Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | tiles = list(map(str, input().split()))
cnt = [0]*3
pos = [[0 for x in range(3)] for y in 'mps']
mps = ['m', 'p', 's']
for i in range(3):
t = tiles[i]
p = int(mps.index(t[1]))
cnt[p] += 1
pos[p][i] = t[0]
if 3 in cnt:
i = cnt.index(3)
tmp = pos[i]
tmp.sort()
if int(tmp[0])+1 == int(tmp[1]) and int(tmp[1]) + 1 == int(tmp[2]):
print(0)
exit()
elif tmp.count(tmp[0]) == len(tmp) and tmp[0] != 0:
print(0)
exit()
k = 0
for tmp in pos:
tmp = list(map(int, tmp))
tmp.sort()
if tmp.count(0) > 1:
continue
k = tmp.count(tmp[0])
if int(tmp.count(tmp[1])) > int(k):
k = tmp.count(tmp[1])
if k == 2:
print(1)
exit()
if tmp[0] == 0 and (int(tmp[2]) - int(tmp[1])) <= 2:
print(1)
exit()
elif (int(tmp[2]) - int(tmp[1])) <= 2:
print(1)
exit()
elif (int(tmp[1]) - int(tmp[0])) <= 2 and tmp[0] != 0:
print(1)
exit()
else:
print(2)
exit()
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def split(s): return [int(s[0]), s[1]]
def check_seq(nums, colors):
for n in nums:
if n not in range(1,10): return False
if len(set(colors)) != 1: return False
nums = set(sorted(nums))
a = sorted(nums)[0]
return {a, a+1, a+2} == nums
def main():
a, b, c = input().split(' ')
if len(set([a,b,c])) == 1:
return 0
a1, a2 = split(a)
b1, b2 = split(b)
c1, c2 = split(c)
domcol = None
if check_seq([a1,b1,c1],[a2,b2,c2]):
return 0
if len(set([a,b,c])) == 2:
return 1
if len(set([a2,b2,c2])) <= 2:
domcol = a2
if a2 != b2:
if a2 != c2:
domcol = c2
ns = set([])
if a2 == domcol: ns = ns | {a1}
if b2 == domcol: ns = ns | {b1}
if c2 == domcol: ns = ns | {c1}
for n in ns:
if len(set([a2,b2,c2])) == 2:
if check_seq(list(ns) + [n-1],[domcol] * 3):
return 1
if check_seq(list(ns) + [n+1], [domcol]*3):
return 1
else: # 1
for d in {-1, 1}:
nns = set(ns) | {n+d}
for x in nns:
ms = nns.difference({x})
if check_seq(list(ms),[domcol] * 3):
return 1
if check_seq(list(ms), [domcol]*3):
return 1
return 2
print(main()) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def check(aa):
a=[i for i in aa]
b = a[:]
b.sort()
ans1 = 100
c = [int(i[0]) for i in a]
for i in range(3):
m = 10 ** 12
for j in range(3):
if c[i]-2+j>=0:
d = []
d.append(str(c[i] - 2 + j) + a[i][1])
d.append(str(c[i] - 1 + j) + a[i][1])
d.append(str(c[i] + j) + a[i][1])
d.sort()
ans = 0
# print(d)
for k in d:
if k not in b:
ans += 1
if int(k[0]) < 1 or int(k[0]) > 9:
ans = 500
ans1 = min(ans, ans1)
# print(ans1)
d1 = [a[0][0] + a[0][1], a[0][0] + a[0][1], a[0][0] + a[0][1]]
d2 = [a[1][0] + a[1][1], a[1][0] + a[1][1], a[1][0] + a[1][1]]
d3 = [a[2][0] + a[2][1], a[2][0] + a[2][1], a[2][0] + a[2][1]]
dd = [d1, d2, d3]
# print(d1,d2,d3)
ddd={}
for i in a:
ddd[i]=ddd.get(i,0) + 1
# print(ddd)
for i in dd:
ans = 0
d4=ddd.copy()
for j in i:
if d4[j]>0:
# ans += 1
d4[j]-=1
else:
ans+=1
# print(ans)
ans1 = min(ans1, ans)
return ans1
a, b, c = map(str, input().split())
print(check([a, b, c])) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author anand.oza
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
BTokitsukazeAndMahjong solver = new BTokitsukazeAndMahjong();
solver.solve(1, in, out);
out.close();
}
static class BTokitsukazeAndMahjong {
static final int THREE = 3;
public void solve(int testNumber, InputReader in, PrintWriter out) {
List<String> tiles = new ArrayList<>();
for (int i = 0; i < THREE; i++) {
tiles.add(in.next());
}
int distinct = countDistinct(tiles);
if (distinct == 1) {
out.println(0);
return;
}
if (distinct == 2) {
out.println(1);
return;
}
int answer = 3;
for (char suit : "mps".toCharArray()) {
List<Integer> suited = new ArrayList<>();
for (String s : tiles) {
if (s.charAt(1) == suit) {
suited.add(s.charAt(0) - '0');
}
}
answer = Math.min(answer, 3 - have(suited));
}
out.println(answer);
}
private int have(List<Integer> suited) {
int have = 0;
for (int first : suited) {
int cand = 1;
if (suited.contains(first + 1)) {
cand++;
}
if (suited.contains(first + 2)) {
cand++;
}
have = Math.max(have, cand);
}
return have;
}
private int countDistinct(Iterable<String> tiles) {
HashSet<String> set = new HashSet<>();
for (String s : tiles)
set.add(s);
return set.size();
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
}
}
| JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def iskoutsu(arr):
return len(set(arr)) == 1
def isshuntsu(arr):
nos = [int(ele[0]) for ele in arr]
nos.sort()
return nos[0]+1 == nos[1] and nos[1]+1 == nos[2] and len(set([ele[1] for ele in arr])) == 1
arr = input().strip().split()
if isshuntsu(arr) or iskoutsu(arr):
exit(print(0))
# to make koutsu
total1 = 0
if len(set(arr)) == 3:
total1 = 2
elif len(set(arr)) == 2:
total1 = 1
# to make shuntsu
total2 = 2
for ele in arr:
no, suite = int(ele[0]), ele[1]
if no+2 <= 9:
required = [str(no+1)+suite, str(no+2)+suite]
curr = int(required[0] not in arr) + (required[1] not in arr)
total2 = min(total2, curr)
if no+1 <= 9 and no-1 >= 0:
required = [str(no-1)+suite, str(no+1)+suite]
curr = int(required[0] not in arr) + (required[1] not in arr)
total2 = min(total2, curr)
if no+2 <= 9:
required = [str(no-1)+suite, str(no-2)+suite]
curr = int(required[0] not in arr) + (required[1] not in arr)
total2 = min(total2, curr)
print(min(total1, total2)) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
struct data {
int v;
char a;
};
bool compare(data c, data d) {
if (c.a > d.a)
return true;
else if (c.a == d.a) {
if (c.v < d.v)
return true;
else
return false;
}
return false;
}
int main() {
int i, j, k, l;
data arr[3];
cin >> arr[0].v;
cin >> arr[0].a;
cin >> arr[1].v;
cin >> arr[1].a;
cin >> arr[2].v;
cin >> arr[2].a;
sort(arr, arr + 3, compare);
if (arr[0].a == arr[1].a && arr[1].a == arr[2].a && arr[0].v == arr[1].v &&
arr[1].v == arr[2].v)
cout << 0 << endl;
else if (arr[0].a == arr[1].a && arr[1].a == arr[2].a &&
arr[0].v == arr[1].v - 1 && arr[1].v == arr[2].v - 1)
cout << 0 << endl;
else if (arr[0].a == arr[1].a && arr[0].v == arr[1].v ||
arr[0].a == arr[2].a && arr[0].v == arr[2].v ||
arr[2].a == arr[1].a && arr[2].v == arr[1].v)
cout << 1;
else if ((arr[0].a == arr[1].a && (abs(arr[0].v - arr[1].v) <= 2)) ||
(arr[0].a == arr[2].a && (abs(arr[0].v - arr[2].v) <= 2)) ||
(arr[2].a == arr[1].a && (abs(arr[2].v - arr[1].v) <= 2)))
cout << 1;
else
cout << 2;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class gym{
public static void main(String[] args) throws IOException{
MScanner sc = new MScanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
HashMap<Character,Character>h=new HashMap<Character,Character>();
char[]nums=new char[3];char []l=new char[3];
String[]s=new String[3];
for(int i=0;i<3;i++) {
String x=sc.next();
s[i]=x;
nums[i]=x.charAt(0);l[i]=x.charAt(1);
h.put(l[i],nums[i]);
}
if(s[0].equals(s[1])&&s[1].equals(s[2])) {
pw.println(0);
}
else {
if(l[0]==l[1] && l[1]==l[2]) {
Arrays.sort(nums);
if((int)(nums[1]-nums[0])==1) {
if((int)(nums[2]-nums[1])==1) {
pw.println(0);
}
else {
pw.println(1);
}
}
else {
if((int)(nums[2]-nums[1])==1) {
pw.println(1);
}
else {
if(nums[2]-nums[0]==1) {
pw.println(1);
}
else {
if(nums[1]-nums[0]==2 || nums[2]-nums[1]==2 || nums[2]-nums[0]==2) {
pw.println(1);
}
else {
if(nums[0]==nums[1] || nums[1]==nums[2]) {
pw.println(1);
}
else
pw.println(2);
}
}
}
}
}
else {
if(l[0]==l[1]) {
if(Math.abs((int)(nums[1]-nums[0]))<=2) {
pw.println(1);
}
else {
pw.println(2);
}
}
else {
if(l[1]==l[2]) {
if(Math.abs((int)(nums[1]-nums[2]))<=2) {
pw.println(1);
}
else {
pw.println(2);
}
}
else {
if(l[0]==l[2] ) {
if(Math.abs((int)(nums[0]-nums[2]))<=2) {
pw.println(1);
}
else {
pw.println(2);
}
}
else
pw.println(2);
}
}
}
}
pw.flush();
}
static class MScanner
{
StringTokenizer st;
BufferedReader br;
public MScanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public boolean ready() throws IOException {return br.ready();}
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | li = list(map(str,input().split()))
lis=[ i[1]+i[0] for i in li]
lis.sort()
ans=[]
ans.append(1)
for i in range(1,len(lis)):
if lis[i]==lis[i-1]:
ans[-1]+=1
else:
ans.append(1)
an=min(max(ans),3)
#print(ans,lis)
if an==3:
print('0')
exit()
ans=[]
ans.append(1)
for i in range(1,len(lis)):
if lis[i]==lis[i-1]:
continue
if int(lis[i][1])==int(lis[i-1][1])+1 and lis[i][0]==lis[i-1][0]:
ans[-1]+=1
elif int(lis[i][1])==int(lis[i-1][1])+2 and lis[i][0]==lis[i-1][0]:
ans.append(2)
ans.append(1)
else:
ans.append(1)
print(3-min(3,max(max(ans),an)))
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import javax.print.DocFlavor;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.CookieHandler;
import java.nio.Buffer;
import java.nio.charset.IllegalCharsetNameException;
import java.sql.BatchUpdateException;
import java.util.*;
import java.util.stream.Stream;
import java.util.Vector;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import static java.lang.Math.*;
import java.util.*;
import java.nio.file.StandardOpenOption;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Iterator;
import java.util.PriorityQueue;
public class icpc
{
public static void main(String[] args) throws IOException
{
// Reader in = new Reader();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s1[] = in.readLine().split(" ");
ArrayList<Integer> m = new ArrayList<>();
ArrayList<Integer> s = new ArrayList<>();
ArrayList<Integer> p = new ArrayList<>();
for(int i=0;i<3;i++)
{
String s2 = s1[i];
if(s2.charAt(1) == 'm')
m.add(Integer.parseInt(s2.substring(0, 1)));
else if(s2.charAt(1) == 's')
s.add(Integer.parseInt(s2.substring(0, 1)));
else if(s2.charAt(1) == 'p')
p.add(Integer.parseInt(s2.substring(0, 1)));
}
Collections.sort(m);
Collections.sort(s);
Collections.sort(p);
if(m.size() == 3 || s.size() == 3 || p.size() == 3)
{
if(m.size() == 3)
{
int diff1 = m.get(1) - m.get(0);
int diff2 = m.get(2) - m.get(1);
if((diff1 == 1 && diff2 == 1) || (diff1 == 0 && diff2 == 0))
{
System.out.println(0);
}
else if((diff1 == 1 && diff2 != 1) || (diff1 != 1 && diff2 == 1) || (diff1 == 2 || diff2 == 2) || (diff1 == 0 || diff2 == 0))
System.out.println(1);
else
System.out.println(2);
}
else if(s.size() == 3)
{
int diff1 = s.get(1) - s.get(0);
int diff2 = s.get(2) - s.get(1);
if((diff1 == 1 && diff2 == 1) || (diff1 == 0 && diff2 == 0))
{
System.out.println(0);
}
else if((diff1 == 1 && diff2 != 1) || (diff1 != 1 && diff2 == 1) || (diff1 == 2 || diff2 == 2) || (diff1 == 0 || diff2 == 0))
System.out.println(1);
else
System.out.println(2);
}
else if(p.size() == 3)
{
int diff1 = p.get(1) - p.get(0);
int diff2 = p.get(2) - p.get(1);
if((diff1 == 1 && diff2 == 1) || (diff1 == 0 && diff2 == 0))
{
System.out.println(0);
}
else if((diff1 == 1 && diff2 != 1) || (diff1 != 1 && diff2 == 1) || (diff1 == 2 || diff2 == 2) || (diff1 == 0 || diff2 == 0))
System.out.println(1);
else
System.out.println(2);
}
}
else if(m.size() == 1 && s.size() == 1 && p.size() == 1)
{
System.out.println(2);
}
else
{
if(m.size() == 2)
{
if((m.get(0) == m.get(1)) || (m.get(0) + 1 == m.get(1)) || (m.get(1) - m.get(0) == 2))
System.out.println(1);
else
System.out.println(2);
}
else if(s.size() == 2)
{
if((s.get(0) == s.get(1)) || (s.get(0) + 1 == s.get(1)) || (s.get(1) - s.get(0) == 2))
System.out.println(1);
else
System.out.println(2);
}
else if(p.size() == 2)
{
if((p.get(0) == p.get(1)) || (p.get(0) + 1 == p.get(1)) || (p.get(1) - p.get(0) == 2))
System.out.println(1);
else
System.out.println(2);
}else
System.out.println(2);
}
}
}
class SuffixArray
{
int ALPHABET_SZ = 256, N;
int[] T, lcp, sa, sa2, rank, tmp, c;
public SuffixArray(String str)
{
this(toIntArray(str));
}
private static int[] toIntArray(String s)
{
int[] text = new int[s.length()];
for (int i = 0; i < s.length(); i++) text[i] = s.charAt(i);
return text;
}
public SuffixArray(int[] text)
{
T = text;
N = text.length;
sa = new int[N];
sa2 = new int[N];
rank = new int[N];
c = new int[Math.max(ALPHABET_SZ, N)];
construct();
kasai();
}
private void construct()
{
int i, p, r;
for (i = 0; i < N; ++i) c[rank[i] = T[i]]++;
for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];
for (i = N - 1; i >= 0; --i) sa[--c[T[i]]] = i;
for (p = 1; p < N; p <<= 1)
{
for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i;
for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p;
Arrays.fill(c, 0, ALPHABET_SZ, 0);
for (i = 0; i < N; ++i) c[rank[i]]++;
for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];
for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i];
for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i)
{
if (!(rank[sa[i - 1]] == rank[sa[i]]
&& sa[i - 1] + p < N
&& sa[i] + p < N
&& rank[sa[i - 1] + p] == rank[sa[i] + p])) r++;
sa2[sa[i]] = r;
}
tmp = rank;
rank = sa2;
sa2 = tmp;
if (r == N - 1) break;
ALPHABET_SZ = r + 1;
}
}
private void kasai()
{
lcp = new int[N];
int[] inv = new int[N];
for (int i = 0; i < N; i++) inv[sa[i]] = i;
for (int i = 0, len = 0; i < N; i++)
{
if (inv[i] > 0)
{
int k = sa[inv[i] - 1];
while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++;
lcp[inv[i] - 1] = len;
if (len > 0) len--;
}
}
}
}
class ZAlgorithm
{
public int[] calculateZ(char input[])
{
int Z[] = new int[input.length];
int left = 0;
int right = 0;
for(int k = 1; k < input.length; k++) {
if(k > right) {
left = right = k;
while(right < input.length && input[right] == input[right - left]) {
right++;
}
Z[k] = right - left;
right--;
} else {
//we are operating inside box
int k1 = k - left;
//if value does not stretches till right bound then just copy it.
if(Z[k1] < right - k + 1) {
Z[k] = Z[k1];
} else { //otherwise try to see if there are more matches.
left = k;
while(right < input.length && input[right] == input[right - left]) {
right++;
}
Z[k] = right - left;
right--;
}
}
}
return Z;
}
public ArrayList<Integer> matchPattern(char text[], char pattern[])
{
char newString[] = new char[text.length + pattern.length + 1];
int i = 0;
for(char ch : pattern) {
newString[i] = ch;
i++;
}
newString[i] = '$';
i++;
for(char ch : text) {
newString[i] = ch;
i++;
}
ArrayList<Integer> result = new ArrayList<>();
int Z[] = calculateZ(newString);
for(i = 0; i < Z.length ; i++) {
if(Z[i] == pattern.length) {
result.add(i - pattern.length - 1);
}
}
return result;
}
}
class KMPAlgorithm
{
public int[] computeTemporalArray(char[] pattern)
{
int[] lps = new int[pattern.length];
int index = 0;
for(int i=1;i<pattern.length;)
{
if(pattern[i] == pattern[index])
{
lps[i] = index + 1;
index++;
i++;
}
else
{
if(index != 0)
{
index = lps[index - 1];
}
else
{
lps[i] = 0;
i++;
}
}
}
return lps;
}
public ArrayList<Integer> KMPMatcher(char[] text, char[] pattern)
{
int[] lps = computeTemporalArray(pattern);
int j = 0;
int i = 0;
int n = text.length;
int m = pattern.length;
ArrayList<Integer> indices = new ArrayList<>();
while(i < n)
{
if(pattern[j] == text[i])
{
i++;
j++;
}
if(j == m)
{
indices.add(i - j);
j = lps[j - 1];
}
else if(i < n && pattern[j] != text[i])
{
if(j != 0)
j = lps[j - 1];
else
i = i + 1;
}
}
return indices;
}
}
class Hashing
{
public long[] computePowers(long p, int n, long m)
{
long[] powers = new long[n];
powers[0] = 1;
for(int i=1;i<n;i++)
{
powers[i] = (powers[i - 1] * p) % m;
}
return powers;
}
public long computeHash(String s)
{
long p = 31;
long m = 1_000_000_009;
long hashValue = 0L;
long[] powers = computePowers(p, s.length(), m);
for(int i=0;i<s.length();i++)
{
char ch = s.charAt(i);
hashValue = (hashValue + (ch - 'a' + 1) * powers[i]) % m;
}
return hashValue;
}
}
class BasicFunctions
{
public long min(long[] A)
{
long min = Long.MAX_VALUE;
for(int i=0;i<A.length;i++)
{
min = Math.min(min, A[i]);
}
return min;
}
public long max(long[] A)
{
long max = Long.MAX_VALUE;
for(int i=0;i<A.length;i++)
{
max = Math.max(max, A[i]);
}
return max;
}
}
class Matrix
{
long a;
long b;
long c;
long d;
public Matrix(long a, long b, long c, long d)
{
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
}
class MergeSortInt
{
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r) {
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int[n1];
int R[] = new int[n2];
/*Copy data to temp arrays*/
for (int i = 0; i < n1; ++i)
L[i] = arr[l + i];
for (int j = 0; j < n2; ++j)
R[j] = arr[m + 1 + j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
void sort(int arr[], int l, int r) {
if (l < r) {
// Find the middle point
int m = (l + r) / 2;
// Sort first and second halves
sort(arr, l, m);
sort(arr, m + 1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
}
class MergeSortLong
{
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(long arr[], int l, int m, int r) {
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
long L[] = new long[n1];
long R[] = new long[n2];
/*Copy data to temp arrays*/
for (int i = 0; i < n1; ++i)
L[i] = arr[l + i];
for (int j = 0; j < n2; ++j)
R[j] = arr[m + 1 + j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
void sort(long arr[], int l, int r) {
if (l < r) {
// Find the middle point
int m = (l + r) / 2;
// Sort first and second halves
sort(arr, l, m);
sort(arr, m + 1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
}
class Node
{
String a;
String b;
Node(String s1,String s2)
{
this.a = s1;
this.b = s2;
}
@Override
public boolean equals(Object ob)
{
if(ob == null)
return false;
if(!(ob instanceof Node))
return false;
if(ob == this)
return true;
Node obj = (Node)ob;
if(this.a.equals(obj.a) && this.b.equals(obj.b))
return true;
return false;
}
@Override
public int hashCode()
{
return (int)this.a.length();
}
}
class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
class FenwickTree
{
public void update(long[] fenwickTree,long delta,int index)
{
index += 1;
while(index < fenwickTree.length)
{
fenwickTree[index] += delta;
index = index + (index & (-index));
}
}
public long prefixSum(long[] fenwickTree,int index)
{
long sum = 0L;
index += 1;
while(index > 0)
{
sum += fenwickTree[index];
index -= (index & (-index));
}
return sum;
}
}
class SegmentTree
{
public int nextPowerOfTwo(int num)
{
if(num == 0)
return 1;
if(num > 0 && (num & (num - 1)) == 0)
return num;
while((num &(num - 1)) > 0)
{
num = num & (num - 1);
}
return num << 1;
}
public int[] createSegmentTree(int[] input)
{
int np2 = nextPowerOfTwo(input.length);
int[] segmentTree = new int[np2 * 2 - 1];
for(int i=0;i<segmentTree.length;i++)
segmentTree[i] = Integer.MIN_VALUE;
constructSegmentTree(segmentTree,input,0,input.length-1,0);
return segmentTree;
}
private void constructSegmentTree(int[] segmentTree,int[] input,int low,int high,int pos)
{
if(low == high)
{
segmentTree[pos] = input[low];
return;
}
int mid = (low + high)/ 2;
constructSegmentTree(segmentTree,input,low,mid,2*pos + 1);
constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2);
segmentTree[pos] = Math.max(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);
}
public int rangeMinimumQuery(int []segmentTree,int qlow,int qhigh,int len)
{
return rangeMinimumQuery(segmentTree,0,len-1,qlow,qhigh,0);
}
private int rangeMinimumQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos)
{
if(qlow <= low && qhigh >= high){
return segmentTree[pos];
}
if(qlow > high || qhigh < low){
return Integer.MIN_VALUE;
}
int mid = (low+high)/2;
return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1),
rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2));
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | # alpha = "abcdefghijklmnopqrstuvwxyz"
# prime = 998244353
# INF = 1000_000_000
# from heapq import heappush, heappop
from collections import defaultdict
# from math import sqrt
# from collections import deque
# from math import gcd
t = 1#int(input())
for test in range(t):
# n = int(input())
# strs = list(map(int, input().split()))
strs = list(input().split())
count = defaultdict(int)
for i in strs:
count[i] +=1
suits = "spm"
ans = 2
for i in suits:
for j in range(1,10):
key = str(j)+str(i)
if count[key]==3:
ans = min(ans,0)
# print("here")
elif count[key] == 2:
ans = min(ans,1)
key2 = str(j+1)+str(i)
key3 = str(j+2)+str(i)
if count[key]>0 and count[key2]>0 and count[key3]>0:
ans = min(ans,0)
elif count[key]>0 and count[key2]>0:
ans = min(ans,1)
elif count[key]>0 and count[key3]>0:
ans = min(ans,1)
print(ans) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | '''
1. Figure out min number to get a kontsu
Get a 'counter', count exact match.
- 3 - find max value
2. Figure out min number to get a mentsu
Sort the cards
Do a while loop
While i is < len(lst)
Count # of consecutive cards
Move j until index of the last consecutive card
'''
def min_mentsu(cards):
return min(min_koutsu(cards), min_shuntsu(cards))
def min_koutsu(cards):
counter = {}
for card in cards:
if card not in counter:
counter[card] = 0
counter[card] += 1
return max(0, 3 - max(counter.values()))
def min_shuntsu(cards):
'''
Cases:
3 same:
2 same: either consecutive
7p 8p or 7p 9p
'''
cards = sorted([(int(card[0]), card[1]) for card in cards], key=lambda x: (x[1], x[0]))
if consecutive(cards, 0) and consecutive(cards, 1):
return 0
if consecutive(cards, 0) or consecutive(cards, 1):
return 1
if jump_consecutive(cards, 0) or jump_consecutive(cards, 1):
return 1
return 2
def consecutive(cards, i):
num, suit = cards[i]
num2, suit2 = cards[i + 1]
return suit == suit2 and num2 - num == 1
def jump_consecutive(cards, i):
num, suit = cards[i]
num2, suit2 = cards[i + 1]
r = (suit == suit2) and (num2 - num == 2)
return r
cards = raw_input().split()
print min_mentsu(cards)
| PYTHON |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
public class q5 {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
PrintWriter out=new PrintWriter(System.out);
// String[] arr=new String[3];
int[][] count=new int[3][10];
int ans=2;
for(int i=0;i<3;i++) {
String s=Reader.next();
if(s.charAt(1)=='m') {
count[0][s.charAt(0)-'0']++;
}
else if(s.charAt(1)=='s') {
count[1][s.charAt(0)-'0']++;
}
else {
count[2][s.charAt(0)-'0']++;
}
}
for(int i=0;i<3;i++) {
for(int j=1;j<=8;j++) {
if(count[i][j]==3) ans=0;
if(count[i][j]==2) {
ans=Math.min(ans, 1);
}
if(j==8) {
}
else {
if(count[i][j]>=1 && count[i][j+1]>=1 && count[i][j+2]>=1) {
ans=0;
}
if(count[i][j]>=1 && count[i][j+2]>=1) {
ans=Math.min(ans, 1);
}
}
if(count[i][j]>=1 && count[i][j+1]>=1 ) {
ans=Math.min(ans, 1);
}
}
if(count[i][9]==3) ans=0;
if(count[i][9]==2 && ans!=0) ans=1;
}
out.println(ans);
out.flush();
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init() throws IOException {
reader = new BufferedReader(
new FileReader("pattern.in") );
tokenizer = new StringTokenizer("");
}
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String nextLine() throws IOException{
return reader.readLine();
}
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static long nextLong() throws IOException {
return Long.parseLong( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | from __future__ import print_function
import sys
def get_seq(line):
a = line.split()
d = {'m': [], 'p': [], 's': []}
for x in a:
n = ord(x[0]) - ord('0')
d[x[1]].append(n)
l = [(len(l), l) for l in d.values()]
l.sort(reverse=True)
return sorted(l[0][1])
def get_best(a):
if len(a) == 1:
return 2
elif len(a) == 2:
if a[1] - a[0] <= 2:
return 1
else:
return 2
elif len(a) == 3:
if a[0] == a[1] and a[1] == a[2]:
return 0
elif a[1] - a[0] == 1 and a[2] - a[1] == 1:
return 0
elif a[1] - a[0] <= 2 or a[2] - a[1] <= 2:
return 1
else:
return 2
seq = get_seq(input())
print(seq, file=sys.stderr)
print(get_best(seq))
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | f = lambda c: 'mps'.index(c)
l = [[], [], []]
for c in input().split():
a, b = c
l[f(b)].append(int(a))
for i in range(3):
l[i].sort()
res = 3
for x in l:
if len(x) == 0: continue
elif len(x) == 1: res = min(res, 2)
elif len(x) == 3:
if len(set(x)) == 1:
res = min(res, 0)
break
if x[0] == x[1] - 1 and x[1] == x[2] - 1:
res = min(res, 0)
break
res = min(res, 2)
for i in range(len(x)):
for j in range(i + 1, len(x)):
if abs(x[i] - x[j]) <= 2:
res = min(res, 1)
print(res) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import collections as cl
v = sorted(input().split())
cnt = cl.Counter(v)
seq = 1
if int(v[0][0]) + 1 == int(v[1][0]) and v[0][1] == v[1][1]:
if int(v[1][0]) + 1 == int(v[2][0]) and v[1][1] == v[2][1]:
seq = 3
else:
seq = 2
elif int(v[0][0]) + 2 == int(v[1][0]) and v[0][1] == v[1][1]:
seq = 2
elif int(v[0][0]) + 1 == int(v[2][0]) and v[0][1] == v[2][1]:
seq = 2
elif int(v[1][0]) + 1 == int(v[2][0]) and v[1][1] == v[2][1]:
seq = 2
elif int(v[0][0]) + 2 == int(v[2][0]) and v[0][1] == v[2][1]:
seq = 2
elif int(v[1][0]) + 2 == int(v[2][0]) and v[1][1] == v[2][1]:
seq = 2
print(3 - max(seq, max(cnt.values())))
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | n=input()
q=n.replace(" ","")
a=list(q)
suit=[]
no=[]
for i in range(6):
if i%2==0:
no.append(a[i])
else:
suit.append(a[i])
noo=[int(i) for i in no]
temp=[0,0,0]
su="a"
for i in suit:
if i=='m':
temp[0]+=1
elif i=='p':
temp[1]+=1
elif i=='s':
temp[2]+=1
tem=tuple(temp)
mx=0
ix=0
for i in range(3):
if tem[i]>mx:
mx=tem[i]
ix=i
if ix==0:
su='m'
elif ix==1:
su='p'
else:
su='s'
if mx==1:
print("2")
else:
for i in range(3):
if suit[i]!=su:
noo.pop(i)
noo.sort()
if mx==2:
wtf=noo[1]-noo[0]
if wtf<=2:
print("1")
else:
print("2")
else:
c1=noo[1]-noo[0]
c2=noo[2]-noo[1]
if c1==1:
if c2==1:
print("0")
else:
print("1")
elif c1==0:
if c2==0:
print("0")
else:
print("1")
elif c1==2:
print("1")
elif c2<=2:
print("1")
else:
print("2")
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.util.*;
import java.lang.*;
import java.io.*;
public class SolutionB {
public void solve(){
Scanner sc = new Scanner(System.in);
String one = sc.next();
String two = sc.next();
String three = sc.next();
if(one.equals(two) && two.equals(three)){
System.out.println(0);
return;
}
if(one.equals(two) || one.equals(three) || two.equals(three)){
System.out.println(1);
return;
}
List<String> in = new ArrayList<>();
in.add(one);
in.add(two);
in.add(three);
List<int[]> tiles = new ArrayList<>();
for(int i = 0; i < 3; i++){
char c = in.get(i).charAt(1);
int a = 0;
if(c == 'm'){
a = 0;
}else if(c == 'p'){
a = 1;
}else{
a = 2;
}
int t = (int)in.get(i).charAt(0) - '0';
tiles.add(new int[]{a, t});
}
Collections.sort(tiles, new Comparator<int[]>(){
@Override
public int compare(int [] a, int [] b){
if(a[0] == b[0]){
return a[1] - b[1];
}
return a[0] - b[0];
}
});
int ans = 2;
for(int i = 0; i + 1 < 3; i++){
int [] cur = tiles.get(i);
int [] next = tiles.get(i + 1);
if(cur[0] == next[0]){
int diff = next[1] - cur[1];
if(diff > 2){
ans = Math.min(ans, 2);
}else if(diff == 2){
ans = Math.min(ans, 1);
}else if(diff == 1){
if(i + 2 < 3){
int [] last = tiles.get(i + 2);
if(last[0] == next[0] && last[1] - next[1] == 1){
ans = 0;
}
}
ans = Math.min(ans, 1);
}
}
}
System.out.println(ans);
}
public static void main (String[] args) {
new SolutionB().solve();
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a=sorted(10*ord(y)+int(x)for x,y in input().split())
s={a[1]-a[0],a[2]-a[1]}
print(2-bool(s&{0,1,2})-(s in({0},{1}))) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | s = input()
st = s.split()
st.sort()
ans=2
if st[0]==st[1] and st[1]==st[2]:
ans=0
if st[0][1]==st[1][1] and st[1][1]==st[2][1]:
if int(st[0][0])+1==int(st[1][0]) and int(st[1][0])+1==int(st[2][0]):
ans=0
if st[0]==st[1] or st[1]==st[2] or st[0]==st[2]:
ans=min(1,ans)
if st[0][1]==st[1][1]:
if int(st[1][0])-int(st[0][0])<=2:
ans = min(1,ans)
if st[0][1]==st[2][1]:
if int(st[2][0])-int(st[0][0])<=2:
ans = min(1,ans)
if st[1][1]==st[2][1]:
if int(st[2][0])-int(st[1][0])<=2:
ans = min(1,ans)
print(str(ans)) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a,b,c=input().split()
def fine(x):
if x[0]==x[1] and x[1]==x[2]:
return True
if x[0][1]==x[1][1] and x[1][1]==x[2][1]:
if (int(x[0][0])+1)==int(x[1][0]) and (int(x[0][0])+2)==int(x[2][0]):
return True
return False
l=[a,b,c]
for i in range(3):
for j in range(3):
for k in range(3):
if i==j or i==k or j==k:
continue
if fine([l[i],l[j],l[k]]):
print(0)
quit()
for ijk in range(1,10):
for x in ['m','p','s']:
s=str(ijk)+x
l=[a,b,c,s]
for i in range(4):
for j in range(4):
for k in range(4):
if i==j or i==k or j==k:
continue
if fine([l[i],l[j],l[k]]):
print(1)
quit()
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a=input().split()
n={}
n['m']=[0 for i in range(9)]
n['s']=[0 for i in range(9)]
n['p']=[0 for i in range(9)]
maxcount=1
for i in a:
t=i[1]
l=int(i[0])
n[t][l-1]+=1
if n[t][l-1]>maxcount:
maxcount=n[t][l-1]
flag=1
if maxcount==2 and flag:
print(1)
flag=0
if maxcount==3 and flag:
print(0)
flag=0
prevcons1=0
prevcons2=0
flag2=0
cons=0
maxcons=0
if flag:
for t in ['m','s','p']:
prevcons1=0
cons=0
for i in range(9):
prevcons2=prevcons1
prevcons1=cons
if n[t][i]:
cons+=1
if cons==prevcons2:
flag2=1
else:
cons=0
if cons>maxcons:
maxcons=cons
if maxcons==3:
print(0)
flag=0
if maxcons==2:
print(1)
flag=0
if maxcons==1 and flag2==0:
print(2)
flag=0
if flag and flag2:
print(1) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Arrays;
public class Test1{
public static void main(String args[])throws IOException{
Scanner sc=new Scanner(System.in);
String s[]=new String[3];
s[0]=sc.next();
s[1]=sc.next();
s[2]=sc.next();
Arrays.sort(s);
char n1=s[0].charAt(0),n2=s[1].charAt(0),n3=s[2].charAt(0);
char c1=s[0].charAt(1),c2=s[1].charAt(1),c3=s[2].charAt(1);
if(c1!=c2 && c2!=c3 && c3!=c1)
System.out.println("2");
else if(n1==n2 && n2==n3 && c1==c2 && c2==c3)
System.out.println("0");
else if(c1==c2 && c2==c3 && n2==(n1+1) && n3==(n2+1))
System.out.println("0");
else if((c1==c2 && n1==n2) || (c2==c3 && n2==n3) || (c1==c3 && n1==n3) || (c1==c2 && n2==n1+1) || (c2==c3 && n3==n2+1) || (c1==c3 && n3==n1+2))
System.out.println("1");
else if((c1==c2 && n2==n1+2) || (c2==c3 && n3==n2+2) || (c1==c3 && n3==n1+1))
System.out.println("1");
else
System.out.println("2");
}
}
// || (c1==c2 && n2==n1+1) || (c2==c3 && n3==n2+1) || (c1==c3 && n3==n1+2) | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.util.*;
public class solver{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s1 = sc.next();
String s2 = sc.next();
String s3 = sc.next();
sc.close();
if(s1.equals(s2) && s2.equals(s3)) {
System.out.println(0);
return;
}
int a = Integer.parseInt(s1.charAt(0) + "");
int b = Integer.parseInt(s2.charAt(0) + "");
int c = Integer.parseInt(s3.charAt(0) + "");
if(s1.equals(s2)) {
System.out.println(1);
return;
}else if(s1.equals(s3)) {
System.out.println(1);
return;
}else if(s2.equals(s3)) {
System.out.println(1);
return;
}else if(s1.charAt(1) == s2.charAt(1) && s2.charAt(1) == s3.charAt(1)) {
int[] tmp = new int[3];
tmp[0] = a; tmp[1] = b; tmp[2] = c;
Arrays.sort(tmp);
int count = 0;
int prev = tmp[0];
for(int i = 1; i < 3; i++) {
if(prev + 1 == tmp[i]) {
count++;
}
prev = tmp[i];
}
if(count == 2) {
System.out.println(0);
return;
} else if(count == 1) {
System.out.println(1);
return;
}else {
if(Math.abs(a - b) == 2 || Math.abs(a - c) == 2 || Math.abs(b - c) == 2) {
System.out.println(1);
return;
} else {
System.out.println(2);
return;
}
}
} else if(s1.charAt(1) == s2.charAt(1)) {
if(a + 1 == b || b + 1 == a || Math.abs(a - b) == 2) {
System.out.println(1);
return;
} else {
System.out.println(2);
return;
}
} else if(s1.charAt(1) == s3.charAt(1)) {
if(a + 1 == c || c + 1 == a || Math.abs(a - c) == 2) {
System.out.println(1);
return;
} else {
System.out.println(2);
return;
}
} else if(s2.charAt(1) == s3.charAt(1)) {
if(b + 1 == c || c + 1 == b || Math.abs(b - c) == 2) {
System.out.println(1);
return;
} else {
System.out.println(2);
return;
}
}else {
System.out.println(2);
return;
}
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
char s[3][10];
int cnt[1000];
int a[10];
set<int> ss;
struct node {
int ch, val;
node(int ch = 0, int val = 0) {
this->ch = ch;
this->val = val;
}
friend bool operator<(const node& mm, const node& gg) {
if (mm.ch != gg.ch)
return mm.ch < gg.ch;
else
return mm.val < gg.val;
}
} mmp[10];
int main() {
cin >> s[0] >> s[1] >> s[2];
if (s[0][1] == s[1][1] && s[0][1] == s[2][1]) {
a[0] = s[0][0] - '0';
a[1] = s[1][0] - '0';
a[2] = s[2][0] - '0';
sort(a, a + 3);
if (a[0] == a[2] || (a[0] + 1 == a[1] && a[1] + 1 == a[2])) {
cout << 0 << endl;
return 0;
}
if (a[0] == a[1] || a[1] == a[2] || a[1] - a[0] == 1 || a[2] - a[1] == 1 ||
a[2] - a[1] == 2 || a[1] - a[0] == 2) {
cout << 1 << endl;
return 0;
}
cout << 2 << endl;
return 0;
}
ss.insert(s[0][1]);
ss.insert(s[1][1]);
ss.insert(s[2][1]);
if (ss.size() == 3)
cout << 2 << endl;
else {
mmp[0] = node(s[0][1], s[0][0] - '0');
mmp[1] = node(s[1][1], s[1][0] - '0');
mmp[2] = node(s[2][1], s[2][0] - '0');
sort(mmp, mmp + 3);
if (mmp[0].ch == mmp[1].ch) {
if (mmp[0].val == mmp[1].val || mmp[1].val - mmp[0].val == 1 ||
mmp[1].val - mmp[0].val == 2)
cout << 1 << endl;
else
cout << 2 << endl;
} else {
if (mmp[1].val == mmp[2].val || mmp[2].val - mmp[1].val == 1 ||
mmp[2].val - mmp[1].val == 2)
cout << 1 << endl;
else
cout << 2 << endl;
}
}
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | h = sorted(list(input().split()))
if len(set(h)) < 3:
print(len(set(h)) - 1)
else:
n = list(map(int, (h[0][0], h[1][0], h[2][0])))
s = [h[0][1], h[1][1], h[2][1]]
if len(set(s)) == 3:
print(2)
elif len(set(s)) == 2:
if h[0][1] == h[1][1] and abs(n[0] - n[1]) < 3 or h[0][1] == h[2][1] and abs(n[0] - n[2]) < 3 or h[2][1] == h[1][1] and abs(n[2] - n[1]) < 3:
print(1)
else:
print(2)
else:
if max(n) - min(n) == 2:
print(0)
elif abs(n[0] - n[1]) < 3 or abs(n[0] - n[2]) < 3 or abs(n[2] - n[1]) < 3:
print(1)
else:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.*;
import java.util.*;
public class cardgame {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
Scanner inputs = new Scanner(System.in);
String[] cards = new String[3];
int[] nums = new int[3];
char[] lets = new char[3];
for(int i=0;i<3;i++) {
cards[i] = inputs.next();
nums[i] = Integer.parseInt(cards[i].substring(0, 1));
lets[i] = cards[i].charAt(1);
}
boolean huh = false;
int numsam = 1;
if(cards[0].equals(cards[1])) {
if(cards[0].equals(cards[2])) {
numsam = 3;
System.out.println(0);
huh = true;
}
else {
numsam = 2;
}
}
else if(cards[0].equals(cards[2]))
numsam = 2;
else if(cards[1].equals(cards[2]))
numsam = 2;
//end of check for 3 of the same
if(!huh) {
if(lets[0]==lets[1]&&lets[1]==lets[2]) {
int[] temp = new int[3];
for(int i=0;i<3;i++) {
temp[i] = nums[i];
}
Arrays.sort(temp);
boolean yee = true;
for(int i=1;i<3;i++) {
if(temp[i]!=temp[i-1]+1) {
yee = false;
break;
}
}
if(yee) {
System.out.println(0);
huh = true;
}
}
//end of case were all 3 are equal
//start of case where first 2 are two of three
if(!huh&&lets[0]==lets[1]){
if(Math.abs(nums[0]-nums[1])==1||Math.abs(nums[0]-nums[1])==2) {
numsam = 2;
}
}
if(!huh&&lets[1]==lets[2]){
if(Math.abs(nums[1]-nums[2])==1||Math.abs(nums[1]-nums[2])==2) {
numsam = 2;
}
}
if(!huh&&lets[0]==lets[2]){
if(Math.abs(nums[0]-nums[2])==1||Math.abs(nums[0]-nums[2])==2) {
numsam = 2;
}
}
//end of checking all pairs of two
}
if(!huh) {
System.out.println(3-numsam);
}
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a, b, c = map(str, input().split())
if a == b == c:
print(0)
exit(0)
p = [int(a[0]), int(b[0]), int(c[0])]
p.sort()
if a[1] == b[1] == c[1] and p[2] - p[1] == p[1] - p[0] == 1:
print(0)
elif a == b:
print(1)
elif b == c:
print(1)
elif a == c:
print(1)
elif a[1] != b[1] and b[1] != c[1] and c[1] != a[1]:
print(2)
elif a[1] == b[1] and b[1] != c[1] and (abs(int(a[0]) - int(b[0])) == 1 or abs(int(a[0]) - int(b[0])) == 2):
print(1)
elif c[1] == b[1] and b[1] != a[1] and (abs(int(c[0]) - int(b[0])) == 1 or abs(int(c[0]) - int(b[0])) == 2):
print(1)
elif a[1] == c[1] and b[1] != c[1] and (abs(int(a[0]) - int(c[0])) == 1 or abs(int(a[0]) - int(c[0])) == 2):
print(1)
elif a[1] == b[1] and b[1] == c[1] and abs(int(a[0]) - int(b[0])) > 2 and abs(int(c[0]) - int(b[0])) > 2 and abs(int(a[0]) - int(c[0])) > 2:
print(2)
elif a[1] == b[1] and (abs(int(a[0]) - int(b[0])) == 1 or abs(int(a[0]) - int(b[0])) == 2):
print(1)
elif c[1] == b[1] and (abs(int(c[0]) - int(b[0])) == 1 or abs(int(c[0]) - int(b[0])) == 2):
print(1)
elif a[1] == c[1] and (abs(int(a[0]) - int(c[0])) == 1 or abs(int(a[0]) - int(c[0])) == 2):
print(1)
elif a[1] == c[1] and abs(int(a[0]) - int(c[0])) == 3:
print(2)
elif a[1] == b[1] and abs(int(a[0]) - int(b[0])) == 3:
print(2)
elif b[1] == c[1] and abs(int(b[0]) - int(c[0])) == 3:
print(2)
elif a[1] == b[1] == c[1] and (abs(int(a[0]) - int(b[0])) == 2 or abs(int(c[0]) - int(b[0])) or abs(int(a[0]) - int(c[0]))):
print(1)
else:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 |
def meth(arr):
for i in range(3):
arr[i]=int(arr[i])
arr.sort()
if arr[0]+1==arr[1] and arr[0]+2==arr[2]:
return 0
if arr[1]-arr[0]>=3 and arr[2]-arr[1]>=3:
return 2
return 1
def meth1(arr):
for i in range(2):
arr[i]=int(arr[i])
arr.sort()
if arr[0]+1==arr[1] or arr[0]+2==arr[1] or arr[0]==arr[1]:
return 1
return 2
a,b,c=input().split()
if a==b==c:
print(0)
exit(0)
if a[1]==b[1]==c[1]:
print(meth([a[0],b[0],c[0]]))
exit(0)
if a[1]==b[1] and b[1]!=c[1]:
print(meth1([a[0],b[0]]))
exit(0)
if c[1]==b[1] and a[1]!=c[1]:
print(meth1([b[0],c[0]]))
exit(0)
if a[1]==c[1] and b[1]!=c[1]:
print(meth1([a[0],c[0]]))
exit(0)
print(2)
exit(0)
"""
from sys import stdin,stdout
n,m,k=list(map(int,stdin.readline().split()))
def m1(x,k):
if x%k==0:
return x//k
return x//k+1
def meth(arr):
if arr==[]:
return []
a=[]
#a=[[] for _ in range(m1(arr[-1],k)) ]
tmp=[]
for x in arr:
if m1(x,k)-1==0:
tmp.append(x)
else:
a.append(x)
a=[tmp]+a
if [] in a:
a.remove([])
return a
a=list(map(int,stdin.readline().split()))
arr=meth(a)
res=0
while len(arr)>1:
#print(arr)
val=arr.pop(0)
if isinstance(val,int):
break
ln=len(val)
newarr=[]
for i in range(len(arr)):
arr[i]-=ln
arr=meth(arr)
res+=1
stdout.write(str(res+1)+"\n")
""" | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | t = sorted(input().split())
ans = 3
l = 0
while l < len(t):
r = l
while r < len(t) and t[r] == t[l]:
r += 1
ans = min(ans, 3 - (r - l))
l = r
t = sorted(list(set(t)), key=lambda e: e[1] + e[0])
l = 0
while l < len(t):
r = l
while r < len(t) and t[r][1] == t[l][1]:
r += 1
for k in range(l, r):
ans = min(ans, 2)
if k + 1 < r:
if int(t[k + 1][0]) == int(t[k][0]) + 1:
ans = min(ans, 1)
if k + 2 < r:
if int(t[k + 2][0]) == int(t[k][0]) + 2:
ans = min(ans, 0)
if int(t[k + 1][0]) == int(t[k][0]) + 2:
ans = min(ans, 1)
l = r
print(ans) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | l=input().split()
l.sort()
if l[0]==l[1]==l[2]:
print(0)
elif l[0][1]==l[1][1]==l[2][1]:
if int(l[0][0])-int(l[1][0])==int(l[1][0])-int(l[2][0])==-1:
print(0)
elif int(l[0][0])-int(l[1][0])>=-2 or int(l[1][0])- int(l[2][0])>=-2 or int(l[0][0])-int(l[2][0])>=-2:
print(1)
else:
print(2)
elif l[0][1]==l[1][1]:
if 0<=int(l[1][0])-int(l[0][0])<=2:
print(1)
else:
print(2)
elif l[2][1]==l[1][1]:
if 0<=int(l[2][0])-int(l[1][0])<=2:
print(1)
else:
print(2)
elif l[2][1]==l[0][1]:
if 0<=int(l[2][0])-int(l[0][0])<=2:
print(1)
else:
print(2)
else:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
lis = [x for x in input().split()]
res = 2
s = set(tuple(lis))
if len(s) == 1:
print(0)
elif len(s) == 2:
print(1)
else:
res = 2
for c in lis:
x = int(c[0]) + 1
ch = str(x) + c[1]
if ch in s:
res -= 1
if res == 2:
for c in lis:
x = int(c[0]) + 2
ch = str(x) + c[1]
if ch in s:
res -= 1
if res == 0:
res = 1
print(res) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a=sorted(10*ord(x[1])+int(x[0])for x in input().split())
s={a[1]-a[0],a[2]-a[1]}
print(2-bool(s&{0,1,2})-(s in({0},{1}))) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int minimum(int x, int y, int z) { return min(x, min(y, z)); }
int main() {
unordered_map<char, vector<int> > m;
unordered_map<char, vector<int> >::iterator itr;
string a, b, c;
cin >> a >> b >> c;
itr = m.find(a[1]);
if (itr == m.end()) {
vector<int> v;
v.push_back(a[0] - '0');
m.insert({a[1], v});
} else
itr->second.push_back(a[0] - '0');
itr = m.find(b[1]);
if (itr == m.end()) {
vector<int> f;
f.push_back(b[0] - '0');
m.insert({b[1], f});
} else
itr->second.push_back(b[0] - '0');
itr = m.find(c[1]);
if (itr == m.end()) {
vector<int> g;
g.push_back(c[0] - '0');
m.insert({c[1], g});
} else
itr->second.push_back(c[0] - '0');
itr = m.find('s');
int x, y, z;
if (itr == m.end())
x = 3;
else if (itr->second.size() == 1)
x = 2;
else if (itr->second.size() == 2) {
if (abs(itr->second[0] - itr->second[1]) == 1 ||
abs(itr->second[0] - itr->second[1]) == 0 ||
abs(itr->second[0] - itr->second[1]) == 2)
x = 1;
else
x = 2;
} else {
sort(itr->second.begin(), itr->second.end());
if (abs(itr->second[0] - itr->second[1]) == 1 &&
abs(itr->second[1] - itr->second[2]) == 1 ||
(itr->second[0] == itr->second[1] && itr->second[1] == itr->second[2]))
x = 0;
else if (abs(itr->second[0] - itr->second[1]) == 1 ||
abs(itr->second[1] - itr->second[2]) == 1 ||
abs(itr->second[1] - itr->second[2]) == 2 ||
abs(itr->second[0] - itr->second[1]) == 2 ||
abs(itr->second[0] - itr->second[1]) == 0 ||
abs(itr->second[1] - itr->second[2]) == 0)
x = 1;
else
x = 2;
}
itr = m.find('m');
if (itr == m.end())
y = 3;
else if (itr->second.size() == 1)
y = 2;
else if (itr->second.size() == 2) {
if (abs(itr->second[0] - itr->second[1]) == 1 ||
abs(itr->second[0] - itr->second[1]) == 0 ||
abs(itr->second[0] - itr->second[1]) == 2)
y = 1;
else
y = 2;
} else {
sort(itr->second.begin(), itr->second.end());
if (abs(itr->second[0] - itr->second[1]) == 1 &&
abs(itr->second[1] - itr->second[2]) == 1 ||
(itr->second[0] == itr->second[1] && itr->second[1] == itr->second[2]))
y = 0;
else if (abs(itr->second[0] - itr->second[1]) == 1 ||
abs(itr->second[1] - itr->second[2]) == 1 ||
abs(itr->second[1] - itr->second[2]) == 2 ||
abs(itr->second[0] - itr->second[1]) == 2 ||
abs(itr->second[0] - itr->second[1]) == 0 ||
abs(itr->second[1] - itr->second[2]) == 0)
y = 1;
else
y = 2;
}
itr = m.find('p');
if (itr == m.end())
z = 3;
else if (itr->second.size() == 1)
z = 2;
else if (itr->second.size() == 2) {
if (abs(itr->second[0] - itr->second[1]) == 1 ||
abs(itr->second[0] - itr->second[1]) == 0 ||
abs(itr->second[0] - itr->second[1]) == 2)
z = 1;
else
z = 2;
} else {
sort(itr->second.begin(), itr->second.end());
if (abs(itr->second[0] - itr->second[1]) == 1 &&
abs(itr->second[1] - itr->second[2]) == 1 ||
(itr->second[0] == itr->second[1] && itr->second[1] == itr->second[2]))
z = 0;
else if (abs(itr->second[0] - itr->second[1]) == 1 ||
abs(itr->second[1] - itr->second[2]) == 1 ||
abs(itr->second[1] - itr->second[2]) == 2 ||
abs(itr->second[0] - itr->second[1]) == 2 ||
abs(itr->second[0] - itr->second[1]) == 0 ||
abs(itr->second[1] - itr->second[2]) == 0)
z = 1;
else
z = 2;
}
cout << minimum(x, y, z);
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def dbl(x, y):
if x[1] != y[1]:
return False
else:
return abs(x[0] - y[0]) < 3
p = sorted(map(lambda x: (int(x[0]), x[1]), input().split()))
k = dbl(p[0], p[1]) + dbl(p[0], p[2]) + dbl(p[1], p[2])
if k == 0:
print(2)
elif k == 3 and 2 * p[1][0] == p[0][0] + p[2][0]:
print(0)
else:
print(1)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def solve(arr):
d = Counter(arr)
mx = 0
for i in d.keys():
mx = max(mx,d[i])
if mx >= 3:
return 0
d1 = {'m':[],'p':[],'s':[]}
for a,v in arr:
d1[v].append(int(a))
count = 0
counttwo = 0
#print(d1)
for key in d1.keys():
if len(d1[key]) > 0:
d1[key].sort()
local = 1
localtwo = 1
for j in range(len(d1[key])-1):
if d1[key][j+1] - d1[key][j]==1:
#print("df",local)
local += 1
#print("fd",local)
else:
count = max(count,local)
local = 1
if d1[key][j+1] - d1[key][j]==2:
localtwo += 1
else:
counttwo = max(counttwo,localtwo)
localtwo = 1
count = max(count,local)
counttwo = max(counttwo,localtwo)
#print("heer",count,counttwo,d1)
if count >= 3:
return 0
if counttwo>1:
return min(3 - max(mx,count),1)
return 3 - max(mx,count)
from collections import Counter
arr = input()
arr = arr.split()
print(solve(arr)) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#n,m = map(int, input().split())
#a = [int(x) for x in input().split()]
inp = input().split()
m = [0]*10
s = [0]*10
p = [0]*10
for st in inp:
if st[1] == 'm':
m[int(st[0])] += 1
if st[1] == 's':
s[int(st[0])] += 1
if st[1] == 'p':
p[int(st[0])] += 1
res = 3
for i in range(1, 10):
res = min(res, 3 - m[i])
res = min(res, 3 - s[i])
res = min(res, 3 - p[i])
for i in range(1, 8):
cnt = sum(map(lambda x: 1 if x == 0 else 0, m[i:i+3]))
res = min(res, cnt)
cnt = sum(map(lambda x: 1 if x == 0 else 0, s[i:i+3]))
res = min(res, cnt)
cnt = sum(map(lambda x: 1 if x == 0 else 0, p[i:i+3]))
res = min(res, cnt)
print(res)
#sys.stdout.write('YES\n')
#sys.stdout.write(f'{res}\n')
#sys.stdout.write(f'{y1} {x1} {y2} {x2}\n')
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 |
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import java.text.*;
public class Rough{
static PrintWriter w=new PrintWriter(System.out);
public static void main(String [] args){
DecimalFormat dm=new DecimalFormat("0.000000");
Scanner sc=new Scanner(System.in);
String arr[]=new String[3];
int m=0,p=0,s=0,ans=-1;
boolean found=false;
int cm[]=new int[10];
int cs[]=new int[10];
int cp[]=new int[10];
for(int i=0;i<3;i++){
arr[i]=sc.next();
if(arr[i].charAt(1)=='m'){
m++;
cm[arr[i].charAt(0)-48]++;
if(cm[arr[i].charAt(0)-48]==3){
ans=0;
found=true;
}
if(cm[arr[i].charAt(0)-48]==2){
ans=1;
found=true;
}
}
else if(arr[i].charAt(1)=='s'){
s++;
cs[arr[i].charAt(0)-48]++;
if(cs[arr[i].charAt(0)-48]==3){
ans=0;
found=true;
}
if(cs[arr[i].charAt(0)-48]==2){
ans=1;
found=true;
}
}
else if(arr[i].charAt(1)=='p'){
p++;
cp[arr[i].charAt(0)-48]++;
if(cp[arr[i].charAt(0)-48]==3){
ans=0;
found=true;
}
if(cp[arr[i].charAt(0)-48]==2){
ans=1;
found=true;
}
}
}
//w.println(arr[0]);
// w.println(ans);
if(!found){
for(int i=1;i<9;i++){
if(cm[i]+cm[i+1]==2||cs[i]+cs[i+1]==2||cp[i]+cp[i+1]==2){
found=true;
ans=1;
}
}
// w.println(found);
for(int i=1;i<8;i++){
if(cm[i]+cm[i+1]+cm[i+2]==3||cs[i]+cs[i+1]+cs[i+2]==3||cp[i]+cp[i+1]+cp[i+2]==3){
found=true;
ans=0;
}
else if(!found&&(cm[i]+cm[i+1]+cm[i+2]==2||cs[i]+cs[i+1]+cs[i+2]==2||cp[i]+cp[i+1]+cp[i+2]==2)){
found=true;
ans=1;
}
}
}
if(!found){
w.println(2);
}
else{
w.println(ans);
}
w.close();
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a=input().split()
for i in range(3):
a[i]=[int(a[i][0]),a[i][1]]
a.sort()
if (a[0][0]+2==a[1][0]+1==a[2][0] and a[0][1]==a[1][1]==a[2][1]) or (a[0]==a[1]==a[2]):
print(0)
elif ((a[0][0]+1==a[1][0] or a[0][0]+2==a[1][0]) and a[0][1]==a[1][1]) or ((a[1][0]+1==a[2][0] or a[1][0]+2==a[2][0]) and a[1][1]==a[2][1]) or (a[0]==a[1]) or (a[1]==a[2]) or ((a[0][0]+2==a[2][0] or a[0][0]+1==a[2][0]) and a[0][1]==a[2][1]) or (a[0]==a[2]):
print(1)
else:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 |
# target Specialist
"""
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
* Readability counts *
// Author : raj1307 - Raj Singh
// Date : 12.07.19
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
def si(): return input()
def mi(): return map(str,input().strip().split(" "))
def li(): return list(mi())
def dmain():
sys.setrecursionlimit(100000000)
threading.stack_size(40960000)
thread = threading.Thread(target=main)
thread.start()
#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import ceil,floor,log,sqrt,factorial,pow,pi
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading
#from itertools import permutations
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod,MOD=1000000007,998244353
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[0]
def sort2(l):return sorted(l, key=getKey)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]
def powerMod(x,y,p):
res = 1
x %= p
while y > 0:
if y&1:
res = (res*x)%p
y = y>>1
x = (x*x)%p1
return res
def gcd(x, y):
while y:
x, y = y, x % y
return x
def isPrime(n) : # Check Prime Number or not
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def main():
#for _ in range(ii()):
a,b,c=mi()
if a==b and b==c:
print(0)
elif (a==b and b!=c) or (a==c and b!=c) or (c==b and a!=c):
print(1)
else:
l=[[int(a[0]),a[1]],[int(b[0]),b[1]],[int(c[0]),c[1]]]
l=sort2(l)
if l[1][0]==l[0][0]+1 and l[2][0]==l[1][0]+1 and a[1]==b[1] and c[1]==b[1]:
print(0)
elif (l[1][0]==l[0][0]+1 and l[1][1]==l[0][1]) or (l[2][0]==l[1][0]+1 and l[2][1]==l[1][1]) or (l[2][0]==l[0][0]+1 and l[2][1]==l[0][1]) or (l[2][0]==l[0][0]+2 and l[2][1]==l[0][1]) or (l[1][0]==l[0][0]+2 and l[1][1]==l[0][1]) or (l[2][0]==l[1][0]+2 and l[2][1]==l[1][1]):
print(1)
else:
print(2)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
#read()
main()
#dmain()
# Comment Read() | PYTHON |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vector<string> ar(3);
for (int i = 0; i < 3; ++i) cin >> ar[i];
sort(ar.begin(), ar.end());
char a = ar[0][0];
char b = ar[1][0];
char c = ar[2][0];
if (a - '0' + 1 == b - '0' && b - '0' + 1 == c - '0' &&
ar[0][1] == ar[1][1] && ar[1][1] == ar[2][1]) {
cout << 0;
} else if (ar[0] == ar[1] && ar[1] == ar[2]) {
cout << 0;
} else if (ar[0] == ar[1] || ar[1] == ar[2] || ar[0] == ar[2]) {
cout << 1;
} else if (b - a <= 2 && ar[1][1] == ar[0][1] ||
c - b <= 2 && ar[2][1] == ar[1][1] ||
c - a <= 2 && ar[2][1] == ar[0][1]) {
cout << 1;
} else {
cout << 2;
}
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
map<char, vector<long long>> mp;
string s[3];
bool flag;
for (long long i = 0; i < 3; i++) {
cin >> s[i];
mp[s[i][1]].push_back(s[i][0] - '0');
}
if (s[0] == s[1] && s[1] == s[2]) {
cout << 0;
return 0;
}
for (auto it : mp) {
sort(it.second.begin(), it.second.end());
flag = ((long long)it.second.size() == 3);
for (long long i = 1; i < (long long)it.second.size(); i++) {
if (it.second[i] - it.second[i - 1] != 1) {
flag = 0;
break;
}
}
if (flag) {
cout << 0;
return 0;
}
}
if (s[0] == s[1] || s[1] == s[2] || s[0] == s[2]) {
cout << 1;
return 0;
}
for (auto it : mp) {
sort(it.second.begin(), it.second.end());
flag = 0;
for (long long i = 1; i < (long long)it.second.size(); i++) {
if (it.second[i] - it.second[i - 1] < 3) {
flag = 1;
break;
}
}
if (flag) {
cout << 1;
return 0;
}
}
cout << 2;
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
String [] s = new String[3];
for(int i=0;i<3;i++){
String ss = in.next();
s[i] = ss.charAt(1)+""+ss.charAt(0);
}
Arrays.sort(s);
int f=1;int se=1;
for(int i=1;i<3;i++){
int n1 = Character.getNumericValue(s[i].charAt(1));
int n2 = Character.getNumericValue(s[i-1].charAt(1));
if(s[i].charAt(0)== s[i-1].charAt(0)){
if(n1-n2==1){
f++;
}
else if(n1==n2){
se++;
}
else if(n1-n2==2){
se=2;
break;
}
}
}
int mx = Math.max(f,se);
System.out.println(3-mx);
}
}
| JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import sys
ss = sys.stdin.readline().replace('\n', '').split()
def brick (sb):
return (int(sb[0]), sb[1])
ss = map(brick, ss)
ss = sorted(ss)
a = ss[0]
b = ss[1]
c = ss[2]
if ss[0] == ss[1] and ss[1] == ss[2]:
print "0"
elif a[1] == b[1] and b[1] == c[1] and a[0] == b[0]-1 and b[0] == c[0]-1:
print "0"
elif a == b or b == c or a == c:
print "1"
elif (a[1] == b[1] and a[0] == b[0]-1) or (b[1] == c[1] and b[0] == c[0]-1) or (a[1] == c[1] and a[0] == c[0]-1) or (a[1] == b[1] and a[0] == b[0]-2) or (b[1] == c[1] and b[0] == c[0]-2) or (a[1] == c[1] and a[0] == c[0]-2):
print "1"
else:
print "2" | PYTHON |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | l = list(input().split())
d = {}
for i in l:
if i[1] not in d:d[i[1]] = [int(i[0])]
else:
d[i[1]].append(int(i[0]))
best = []
for i in d:
if len(d[i]) > len(best):
best = d[i]
best.sort()
if len(best)==1:print(2)
elif len(set(best))==1:print(3-len(best))
else:
if len(best)==3:
if best[0]==best[1]-1 and best[2] == best[1]+1:
print(0)
elif best[0]+1==best[1] or best[1]+1==best[2]:
print(1)
elif best[0]==best[1] or best[1]==best[2]:
print(1)
elif best[0]+2==best[1] or best[1]+2==best[2]:
print(1)
else:
print(2)
elif len(best)==2:
if best[0]==best[1]:print(1)
elif best[0]==best[1]-1:print(1)
elif best[0]+2==best[1]:print(1)
else:print(2)
else:
print(2) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def getN():
return int(input())
def getList():
return list(map(int, input().split()))
import math
def main():
# something
pie = input().split()
man = []
pin = []
soh = []
for p in pie:
if p.endswith("p"):
pin.append(p)
elif p.endswith("s"):
soh.append(p)
else:
man.append(p)
ans = 2
for mark in [man, pin, soh]:
# print(mark)
nums = sorted([int(m[0]) for m in mark])
if len(mark) <= 1:
pass
elif len(mark) == 2:
# print("here")
if mark[0] == mark[1]:
ans = 1
if nums[1] - nums[0] <= 2:
ans = 1
else:
# print("nohre")
# print(mark)
if nums[0] == nums[1] and nums[1] == nums[2]:
ans = 0
break
if nums[1] - nums[0] == 1:
if nums[2] - nums[1] == 1:
ans = 0
else:
ans = 1
break
if nums[2] - nums[1] == 1:
if nums[1] - nums[0] == 1:
ans = 0
else:
ans = 1
break
if nums[1] - nums[0] == 2 or nums[2] - nums[1] == 2:
ans = 1
break
if len(list(set(nums))) == 2:
ans = 1
break
print(ans)
if __name__ == "__main__":
main()
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | tl=list(map(str,input().split()))
n1=tl[0][0]
n2=tl[1][0]
n3=tl[2][0]
s1=tl[0][1]
s2=tl[1][1]
s3=tl[2][1]
nl=[int(n1),int(n2),int(n3)]
sl=[s1,s2,s3]
#print(nl)
#print(sl)
if len(set(sl))==3:
print(2)
elif len(set(sl))==1:
if len(set(nl))==1:
print(0)
elif len(set(nl))==2:
print(1)
else:
tmnl=sorted(nl)
if tmnl[1]==tmnl[0]+1 and tmnl[2]==tmnl[1]+1:
print(0)
elif tmnl[1]==tmnl[0]+1 or tmnl[2]==tmnl[1]+1 :
print(1)
else:
if tmnl[1]==tmnl[0]+2 or tmnl[2]==tmnl[1]+2 or tmnl[2]==tmnl[0]+2:
print(1)
else:
print(2)
else:
if sl[0]==sl[1]:
if nl[0]==nl[1]:
print(1)
elif abs(nl[0]-nl[1])==1 or abs(nl[0]-nl[1])==2:
print(1)
else:
print(2)
elif sl[1]==sl[2]:
if nl[1]==nl[2]:
print(1)
elif abs(nl[1]-nl[2])==1 or abs(nl[1]-nl[2])==2:
print(1)
else:
print(2)
else:
if nl[0]==nl[2]:
print(1)
elif abs(nl[0]-nl[2])==1 or abs(nl[0]-nl[2])==2:
print(1)
else:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
char s[10][4];
int main() {
scanf("%2s %2s %2s", s[0], s[1], s[2]);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3 - i - 1; j++) {
if (strcmp(s[j], s[j + 1]) == 1) {
swap(s[j], s[j + 1]);
}
}
}
int cot = 0;
if (strcmp(s[0], s[1]) == 0 && strcmp(s[0], s[2]) == 0) {
cot = 3;
} else if (strcmp(s[0], s[1]) == 0 || strcmp(s[0], s[2]) == 0 ||
strcmp(s[1], s[2]) == 0) {
cot = 2;
} else {
cot = 1;
}
if ((s[0][1] == s[1][1] && s[0][1] == s[2][1]) &&
((char)s[0][0] + 1 == s[1][0] && (char)s[1][0] + 1 == s[2][0])) {
cot = 3;
} else if ((s[0][1] == s[1][1] && (char)s[0][0] + 1 == s[1][0]) ||
(s[0][1] == s[2][1] && s[0][0] + 1 == s[2][0]) ||
(s[1][1] == s[2][1] && s[1][0] + 1 == s[2][0]) ||
(s[1][1] == s[2][1] && s[1][0] + 2 == s[2][0]) ||
(s[0][1] == s[2][1] && s[0][0] + 2 == s[2][0]) ||
(s[0][1] == s[1][1] && s[0][0] + 2 == s[1][0])) {
cot = max(cot, 2);
} else {
cot = max(cot, 1);
}
printf("%d\n", 3 - cot);
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def f(a, b, c):
if a[0] > b[0]:
a, b = b, a
if abs(int(a[0]) - int(b[0])) == 1 and a[1] == b[1]:
if a[1] == c[1] and abs(int(c[0]) - int(b[0])) == 1 and a != c:
return 0
else:
return 1
if abs(int(a[0]) - int(b[0])) == 2 and a[1] == b[1]:
return 1
return 2
a, b, c = input().split()
s1 = set()
s1.add(a)
s1.add(b)
s1.add(c)
c1 = len(s1) - 1
print(min(c1, f(a, b, c), f(a, c, b), f(b, c, a)))
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | from sys import stdin, stdout, exit
t1, t2, t3 = stdin.readline().split()
if t1 == t2 and t2 == t3:
print(0)
exit()
ts = [(int(t[0]), t[1]) for t in [t1, t2, t3]]
ts.sort()
ns = [t[0] for t in ts]
ss = [t[1] for t in ts]
if ns[0] + 1== ns[1] and ns[0] + 2 == ns[2] and ss[0] == ss[1] and ss[1] == ss[2]:
print(0)
exit()
if ns[0] + 2 >= ns[1] and ss[1] == ss[0]:
print(1)
exit()
if ns[1] + 2 >= ns[2] and ss[1] == ss[2]:
print(1)
exit()
if ns[0] + 2 >= ns[2] and ss[0] == ss[2]:
print(1)
exit()
if ts[0] == ts[1] or ts[1] == ts[2] or ts[2] == ts[0]:
print(1)
exit()
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | from collections import Counter
a=map(str,raw_input().split())
d=Counter(a)
m=100
for i in d:
m=min(m,3-d[i])
dic={}
for i in a:
if(dic.get(i[-1])):
dic[i[-1]].append(int(i[0]))
else:
dic[i[-1]]=[(int(i[0]))]
# print dic
for i in dic:
f=list(set(dic[i]))
# print f
# print f
if(len(f)==1):
m=min(m,2)
elif(len(f)==2):
if(abs(f[0]-f[1]) == 1):
m=min(m,1)
if(abs(f[0]-f[1])==2):
m=min(m,1)
else:
m=min(m,2)
elif(len(f)==3):
ll=f
ll.sort()
c=0
if(abs(ll[2]-ll[1])==1 and abs(ll[1]-ll[0])==1):
m=min(0,m)
elif(abs(ll[2]-ll[1])==1 or abs(ll[1]-ll[0])==1):
m=min(1,m)
elif(abs(ll[2]-ll[1])==2 or abs(ll[1]-ll[0])==2):
m=min(1,m)
else:
m=min(2,m)
print m
| PYTHON |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 |
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m[]=new int[10];
int s[]=new int[10];
int p[]=new int[10];
String st =sc.next();
if(st.charAt(1)=='m'){m[st.charAt(0)-'0']++;}
if(st.charAt(1)=='s'){s[st.charAt(0)-'0']++;}
if(st.charAt(1)=='p'){p[st.charAt(0)-'0']++;}
String st1=sc.next();
if(st1.charAt(1)=='m'){m[st1.charAt(0)-'0']++;}
if(st1.charAt(1)=='s'){s[st1.charAt(0)-'0']++;}
if(st1.charAt(1)=='p'){p[st1.charAt(0)-'0']++;}
String st2=sc.next();
if(st2.charAt(1)=='m'){m[st2.charAt(0)-'0']++;}
if(st2.charAt(1)=='s'){s[st2.charAt(0)-'0']++;}
if(st2.charAt(1)=='p'){p[st2.charAt(0)-'0']++;}
int three=0;
int two=0;
int maxthree=1;
int maxtwo=1;
for(int i=0;i<10;i++){
if(m[i]==2||p[i]==2||s[i]==2){maxthree=2;}
if(m[i]==3||p[i]==3||s[i]==3){three++;break;}
if(i<8){
if((m[i]==1&&m[i+1]==1&&m[i+2]==1)||(p[i]==1&&p[i+1]==1&&p[i+2]==1)||(s[i]==1&&s[i+1]==1&&s[i+2]==1)){two++;break;}
if((m[i]==1&&m[i+2]==1)||(p[i]==1&&p[i+2]==1)||(s[i]==1&&s[i+2]==1)){maxtwo=2;}
}
if(i<9){
if((m[i]==1&&m[i+1]==1)||(p[i]==1&&p[i+1]==1)||(s[i]==1&&s[i+1]==1)){maxtwo=2;}
}
}
if(three>0||two>0){System.out.println("0");}
else{System.out.println(3-Math.max(maxthree, maxtwo));}
}
}
| JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | from __future__ import print_function
le=['m','p','s']
d={str(k)+i:0 for k in range(1,10) for i in le}
for k in raw_input().split():
d[k]+=1
def tr():
for k in d:
if d[k]==3:
return True
for k in range(1,8):
for deb in ['m','p','s']:
if d[str(k)+deb]*d[str(k+1)+deb]*d[str(k+2)+deb]:
return True
return False
def du():
for k in d:
if d[k]==2:
return True
for k in range(1,8):
for deb in ['m','p','s']:
if bool(d[str(k)+deb])+bool(d[str(k+1)+deb])+bool(d[str(k+2)+deb])==2:
return True
return False
if sum(d[k] for k in d)==0:
print(3)
elif tr():
print(0)
elif du():
print(1)
else:
print(2)
| PYTHON |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | from sys import stdin
a = [str(x) for x in stdin.readline().split()]
ans = len(set(a)) - 1
for ch in ['s', 'p', 'm']:
all = [str(i) + ch for i in range(1, 10)]
for i in range(3, 10):
tem = 0
for j in range(i - 1, i - 4, -1):
if all[j] not in a:
tem = 2
break
ans = min(ans, tem)
tem = 1
for j in [i - 1, i - 3]:
if all[j] not in a:
tem = 2
break
ans = min(ans, tem)
for i in range(2, 10):
tem = 1
for j in range(i - 1, i - 3, -1):
if all[j] not in a:
tem = 2
break
ans = min(ans, tem)
print(ans)
| PYTHON |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a,b,c = map(str, raw_input().split())
def f2(a,b,c):
x = [int(a[0]), int(b[0]), int(c[0])]
x.sort()
# print (a,b,c)
if a==b and b==c and c==a:
return 0
elif a[1]==b[1] and b[1]==c[1] and c[1]==a[1] and x[1]-x[0]==1 and x[2]-x[1]==1:
return 0
elif a==b or b==c or c==a:
return 1
elif (a[1]==b[1] and abs(int(a[0])-int(b[0]))<=2) or (b[1]==c[1] and abs(int(c[0])-int(b[0]))<=2) or (c[1]==a[1] and abs(int(a[0])-int(c[0]))<=2):
return 1
return 2
print f2(a,b,c) | PYTHON |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;
import java.io.PrintWriter;
public class Ideone
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static boolean ok(String a, String b)
{
int x = a.charAt(0) - '0';
int y = b.charAt(0) - '0';
return (a.charAt(1) == b.charAt(1) && (Math.abs(x - y) == 1 || Math.abs(x - y) == 2));
}
public static void main(String[] args)
{
FastReader sc=new FastReader();
String a=sc.next();
String b=sc.next();
String c=sc.next();
if (a.equals(b)&& b.equals(c) && a.equals(c))
{
System.out.println("0");
System.exit(0);
}
int arr[]=new int[3];
arr[0] = a.charAt(0) - '0';
arr[1] = b.charAt(0) - '0';
arr[2] = c.charAt(0) - '0';
Arrays.sort(arr);
if(arr[1]!=arr[2] && arr[2]!=arr[0] && arr[0]!=arr[1])
{
if (a.charAt(1) == b.charAt(1) && b.charAt(1) == c.charAt(1) && a.charAt(1) == c.charAt(1) )
{
if (arr[0] - arr[2] == -2)
{
System.out.println("0");
System.exit(0);
}
}
}
if (a.equals(b)|| b.equals(c)|| a.equals(c))
{
System.out.println("1");
System.exit(0);
}
if (ok(a, b) || ok(b, c) || ok(a, c))
{
System.out.println("1");
System.exit(0);
}
System.out.println("2");
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | x,y,z = input().split()
p = []
n1 = int(x[0])
n2 = int(y[0])
n3 = int(z[0])
p.append(int(n1))
p.append(int(n2))
p.append(int(n3))
p.sort()
t1 = x[1]
t2 = y[1]
t3 = z[1]
#Zero cards required
if(((t1 == t2 == t3)and(n1 == n2 == n3)) or ((t1 == t2 == t3) and p[1] == p[0]+1 and p[2] == p[0]+2)):
print(0)
#One card required
elif(((t1 == t2 and n1 == n2)or(t2 == t3 and n2 == n3)or(t1 == t3 and n1 == n3))or((t1 == t2 and (n2 == n1+1 or n2 == n1+2 or n1 == n2+1 or n1 == n2+2))or(t2 == t3 and (n3 == n2+1 or n3 == n2+2 or n2 == n3+1 or n2 == n3+2))or(t1 == t3 and (n3 == n1+1 or n3 == n1+2 or n1 == n3+1 or n1 == n3+2)))):
print(1)
#Two cards needed
#elif((t1 != t2 and t1 != t3 and t2 != t3)or((t1 == t2 == t3)and(p[1] != p[0]+1 and p[2] != p[0]+2))or(t1)):
# print(2)
else:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | # m = k ΠΈΠ»ΠΈ s
# k = ΡΡΠΈ ΠΈΠ΄Π΅Π½ΡΠΈΡΠ½ΡΡ
ΡΠ°ΠΉΠ»Π°
# s = ΡΡΠΈ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΡΡ
ΡΠ°ΠΉΠ»Π°
def check(l, r, d=1):
return l[0] == r[0] - d and l[1] == r[1]
s = [i for i in input().split()]
a = []
for i in s:
a.append([int(i[0]), i[1]])
a.sort()
if s[0] == s[1] == s[2] or check(a[0], a[1]) and check(a[1], a[2]):
print(0)
elif (s[0] == s[1] or s[0] == s[2] or s[1] == s[2]) \
or (check(a[0], a[1], 2) or check(a[0], a[1]) \
or check(a[0], a[2], 2) \
or check(a[0], a[2]) or check(a[1], a[2], 2) or check(a[1], a[2])):
print(1)
else:
print(2) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import random as random
def quicksort(nums):
if len(nums) <= 1:
return nums
else:
q = random.choice(nums)
l_nums = [n for n in nums if n < q]
e_nums = [q] * nums.count(q)
b_nums = [n for n in nums if n > q]
return quicksort(l_nums) + e_nums + quicksort(b_nums)
l = list(input().split(' '))
l = quicksort(l)
Answ = ""
if (l[0] == l[1] == l[2]):
Answ = "0"
elif (l[0][1] == l[1][1] == l[2][1] and (int(l[0][0]) +1 == int(l[1][0]) == int(l[2][0])-1) ):
Answ = "0"
elif (l[0] == l[1] or l[1] == l[2]):
Answ = "1"
elif (l[0][1] == l[1][1] and (int(l[0][0]) +1 == int(l[1][0]))):
Answ = "1"
elif (l[2][1] == l[1][1] and (int(l[1][0]) +1 == int(l[2][0]))):
Answ = "1"
elif (l[2][1] == l[0][1] and (int(l[0][0]) +1 == int(l[2][0]))):
Answ = "1"
elif (l[2][1] == l[0][1] and (int(l[0][0]) +2 == int(l[2][0]))):
Answ = "1"
elif (l[1][1] == l[0][1] and (int(l[0][0]) +2 == int(l[1][0]))):
Answ = "1"
elif (l[2][1] == l[1][1] and (int(l[1][0]) +2 == int(l[2][0]))):
Answ = "1"
else:
Answ = "2"
print(Answ) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | d={"s":100,"p":200,"m":300};z=sorted([int(i[0])+d[i[1]] for i in map(str,input().split())])
if len(set(z))==1 or (z[0]==z[1]-1 and z[1]==z[2]-1):print(0)
elif (z[0]==z[1] or z[1]==z[2]) or (z[1]-z[0] in [1,2] or z[2]-z[1] in [1,2]):print(1)
else:print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
string s[3];
int main() {
while (cin >> s[0] >> s[1] >> s[2]) {
if (s[0] == s[1] && s[1] == s[2]) {
puts("0");
} else if (s[0] == s[1] || s[0] == s[2] || s[1] == s[2]) {
puts("1");
} else {
int cntm = 0, cntp = 0, cnts = 0;
for (int i = 0; i < 3; i++) {
if (s[i][1] == 'm')
cntm++;
else if (s[i][1] == 'p')
cntp++;
else
cnts++;
}
if (cntm == 3 || cntp == 3 || cnts == 3) {
sort(s, s + 3);
int lx = 0;
if (abs(s[0][0] - s[1][0]) == 1) lx++;
if (abs(s[1][0] - s[2][0]) == 1) lx++;
if (lx)
printf("%d\n", 2 - lx);
else {
if (abs(s[0][0] - s[1][0]) == 2) lx++;
if (abs(s[1][0] - s[2][0]) == 2) lx++;
puts(lx ? "1" : "2");
}
} else if (cntm == 1 && cntp == 1 && cnts == 1) {
puts("2");
} else {
char c = 'm';
if (cntp == 2)
c = 'p';
else if (cnts == 2)
c = 's';
vector<string> vs;
for (int i = 0; i < 3; i++) {
if (s[i][1] == c) vs.push_back(s[i]);
}
if (abs(vs[0][0] - vs[1][0]) <= 2) {
puts("1");
} else {
puts("2");
}
}
}
}
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.util.Scanner;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Vector;
public class B{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
StringBuilder str = new StringBuilder().append(in.nextLine());
//System.out.println(str);
String[] hand = str.toString().split(" ");
HashMap<String, Integer> map = new HashMap<>();
for(String el : hand)
if(map.containsKey(el)) map.put(el, map.get(el) + 1);
else map.put(el, 1);
//System.out.println(map);
if(map.size() == 1){
System.out.println(0);
return;
}
if(map.size() == 2){
System.out.println(1);
return;
}
Vector<Vector<Integer>> vec = new Vector<>();
vec.add(new Vector<>());
vec.add(new Vector<>());
vec.add(new Vector<>());
for(String st : hand){
if(st.charAt(1) == 'm') vec.get(0).add(st.charAt(0)-'0');
if(st.charAt(1) == 's') vec.get(1).add(st.charAt(0)-'0');
if(st.charAt(1) == 'p') vec.get(2).add(st.charAt(0)-'0');
}
for(Vector<Integer> v : vec)
v.sort((x,y)->Integer.compare(x,y));
int res = 2;
//System.out.println(vec);
for(int i = 0;i<3;++i){
Vector<Integer> v = vec.get(i);
if(v.size() == 3){
if(v.get(0)+1 == v.get(1) && v.get(1)+1 == v.get(2)){
System.out.println(0);
return;
}
}
for(int j = 1;j<v.size();++j){
if(v.get(j) == v.get(j-1)+1 || v.get(j) == v.get(j-1) + 2) res = 1;
}
}
System.out.println(res);
}
}
| JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include<bits/stdc++.h>
#include<stdio.h> //per fare input output con scanf and printf
#include<stdlib.h> //per fare qsort e bsearch
#include<string.h> // per fare strcpy(sarrivo, spartenza) strcat(str, aggiungo) strcmp(a,b) che da 0 se sono uguali
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#using namespace std;
#define ld long double
#define ll long long int
#define vi vector <ll>
#define pi pair <ll, ll>
#define binary(v, el) binary_search((v).begin(), (v).end(), (el))
#define PB push_back
#define MP make_pair
#define F first
#define S second
x,y,z = list(map(str, input().strip().split()))
def cazzu(a,b,c):
if a==b==c:
return 1
else:
return 0
def shizu(a,b,c):
x = int(a[0])
y = int(b[0])
z = int(c[0])
l = [x,y,z]
l.sort()
if a[1]==b[1]==c[1] and l[1]-l[0] == 1 and l[2]-l[1]==1:
return 1
else:
return 0
if cazzu(x,y,z) or shizu(x,y,z):
print(0)
else:
flag = 0
for i in ['p','m','s']:
for j in ['1','2','3','4','5','6','7','8','9']:
w = j+i
if cazzu(x,y,w) or shizu(x,y,w) or cazzu(x,w,z) or shizu(x,w,z) or cazzu(w,y,z) or shizu(w,y,z):
flag = 1
if flag == 1:
print(1)
else:
print(2) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 |
import java.io.*;
import java.util.*;
public class B {
class Token implements Comparable<Token> {
int n;
char c;
public Token(int n, char c) {
this.n = n;
this.c = c;
}
@Override
public int compareTo(Token o) {
if (c == o.c) {
return n - o.n;
}
return c - o.c;
}
public boolean equals(Token o) {
if (n == o.n && c == o.c) {
return true;
}
return false;
}
}
public void solve() throws IOException {
Token[] t = new Token[3];
for (int i = 0; i < 3; i++) {
String s = nextToken();
t[i] = new Token(s.charAt(0) - '0', s.charAt(1));
}
Arrays.sort(t);
if (t[0].equals(t[2]) || (t[0].c == t[2].c && t[2].n - t[0].n == 2 && !t[0].equals(t[1]) && !t[1].equals(t[2]))) {
out.print(0);
} else if (t[0].equals(t[1]) || t[1].equals(t[2]) || t[0].c == t[1].c && (t[1].n - t[0].n == 2 || t[1].n - t[0].n == 1) || t[1].c == t[2].c && (t[2].n - t[1].n == 2 || t[2].n - t[1].n == 1)) {
out.print(1);
} else {
out.print(2);
}
}
public void run() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
BufferedReader br;
StringTokenizer in;
PrintWriter out;
public String nextToken() throws IOException {
while (in == null || !in.hasMoreTokens()) {
in = new StringTokenizer(br.readLine());
}
return in.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public int[] nextArr(int n) throws IOException {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt();
}
return res;
}
public static void main(String[] args) throws IOException {
Locale.setDefault(Locale.US);
new B().run();
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | l=input().split()
if(len(set(l))==1):
print(0)
else:
d=dict()
#d1=dict('s':0,'m':0;'p':0)
for i in l:
if(i[1] not in d):
d[i[1]]=[int(i[0])]
else:
d[i[1]].append(int(i[0]))
mi=9
for i in d.values():
if(len(i)>0):
i.sort()
if(len(i)==3):
c=[]
for j in range(0,2):
c.append(abs(i[j+1]-i[j]))
#print(c)
x=min(c)
if(x==1 and c.count(1)==2):
mi=0
elif(x==1):
if(mi>1):
mi=1
elif(x==2):
if(mi>1):
mi=1
elif(x==0):
y=c.count(0)
y=2-y
if(y<mi):
mi=y
else:
if(mi>3):
mi=2
elif(len(i)==2):
x=abs(i[1]-i[0])
if(x==0):
if(mi>1):
mi=1
elif(x==1 or x==2):
if(mi>1):
mi=1
else:
if(mi>3):
mi=2
else:
x=2
if(mi>x):
mi=x
else:
if(mi>3):
mi=3
print(mi) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | from sys import *
m=list(input().split())
ans1=ans2=2
d=[]
if m[0][1]==m[1][1]:
if abs(int(m[0][0])-int(m[1][0]))<=2 and abs(int(m[0][0])-int(m[1][0]))!=0:
ans1-=1
d.append(int(m[0][0])-int(m[1][0]))
if abs(int(m[0][0])-int(m[1][0]))==0:
ans2-=1
if m[0][1]==m[2][1]:
if abs(int(m[0][0])-int(m[2][0]))<=2 and abs(int(m[0][0])-int(m[2][0]))!=0:
if len(d)>0:
if abs((int(m[0][0])-int(m[2][0]))-d[0])<=2:
ans1-=1
else:
ans1-=1
if abs(int(m[0][0])-int(m[2][0]))==0:
ans2-=1
ans=min(ans1,ans2)
if ans<=1:
print(ans)
else:
ans1=2
if m[1][1] == m[2][1]:
if abs(int(m[1][0]) - int(m[2][0])) <= 2:
ans1 -= 1
print(min(ans,ans1)) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def check(a, b):
if a[1] == b[1] and 1 <= abs(int(b[0]) - int(a[0])) <= 2:
return True
arr = input().split()
d = {}
for i in arr:
d[i] = d.get(i, 0) + 1
mineq = 3 - max(d.values())
arr.sort(key=lambda x: x[0])
arr.sort(key=lambda x: x[1])
if check(arr[0], arr[1]) or check(arr[1], arr[2]):
mineq = min(mineq, 1)
if arr[0][1] == arr[1][1] == arr[2][1] and int(arr[2][0]) - int(arr[1][0]) == 1 and int(arr[1][0]) - int(arr[0][0]) == 1:
mineq = 0
print(mineq) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def main():
s = input().split()
maxIdent = 0
maxIncr = 0
for el in s:
cnt = s.count(el)
if cnt == 3:
print(0)
return
if cnt > maxIdent:
maxIdent = cnt
cnt2 = 1
item1 = str(int(el[0]) + 1) + el[1]
item2 = str(int(el[0]) + 2) + el[1]
if item1 in s or item2 in s:
cnt2 = 2
if item1 in s and item2 in s:
print(0)
return
if cnt2 > maxIncr:
maxIncr = cnt2
maxIdent = 3 - maxIdent
maxIncr = 3 - maxIncr
print(min([maxIdent, maxIncr]))
main() | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #573_B
st = input().split(" ")
nums = sorted([[int(i[0]), i[1]] for i in st])
if st[0] == st[1] and st[1] == st[2]:
print(0)
elif nums[0][1] == nums[1][1] and nums[1][1] == nums[2][1] and nums[0][0] == nums[1][0] - 1 and nums[1][0] == nums[2][0] - 1:
print(0)
else:
if nums[0][1] == nums[1][1] and nums[1][0] - nums[0][0] < 3:
print(1)
elif nums[1][1] == nums[2][1] and nums[2][0] - nums[1][0] < 3:
print(1)
elif nums[0][1] == nums[2][1] and nums[2][0] - nums[0][0] < 3:
print(1)
else:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | // No sorceries shall previal. //
import java.util.Scanner;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.*;
import java.util.*;
public class InVoker {
public static void main(String args[]) {
Scanner inp = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
String s[]=new String[3];
for(int i=0;i<3;i++)
{
s[i]=inp.next();
}
if(s[0].equals(s[1]) && s[1].equals(s[2]))
out.println('0');
else if(s[0].charAt(1)==s[1].charAt(1) && s[1].charAt(1)==s[2].charAt(1))
{
char x[]= new char[3];
x[0]=s[0].charAt(0);
x[1]=s[1].charAt(0);
x[2]=s[2].charAt(0);
for(int i=0;i<2;i++)
{
for(int j=i+1;j<3;j++)
{
if(x[i]>x[j])
{
char t=x[i];
x[i]=x[j];
x[j]=t;
}
}
}
if(x[0]+1==x[1] && x[1]+1==x[2])
out.println('0');
else if(Math.abs(x[1]-x[0])<3 || Math.abs(x[2]-x[1])<3 || Math.abs(x[2]-x[0])<3)
out.println('1');
else
out.println('2');
}
else if(s[0].charAt(1)==s[1].charAt(1))
{
if(Math.abs(s[0].charAt(0)-s[1].charAt(0))<3)
System.out.println('1');
else
System.out.println('2');
}
else if(s[1].charAt(1)==s[2].charAt(1))
{
if(Math.abs(s[1].charAt(0)-s[2].charAt(0))<3)
System.out.println('1');
else
System.out.println('2');
}
else if(s[0].charAt(1)==s[2].charAt(1))
{
if(Math.abs(s[0].charAt(0)-s[2].charAt(0))<3)
System.out.println('1');
else
System.out.println('2');
}
else
System.out.println('2');
out.close();
}
}
| JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a,b,c=raw_input().split()
d={'p':[],'m':[],'s':[]}
d[a[1]].append((int(a[0])))
d[b[1]].append((int(b[0])))
d[c[1]].append((int(c[0])))
c=100
for k in d.keys():
d[k].sort()
if(len(d[k])==1):
c=min(c,2)
elif(len(d[k])==0):
c=min(3,c)
elif(len(d[k])==2):
if(d[k][0]==d[k][1]-1):c=min(c,1)
if (d[k][0] == d[k][1]):
c = min(c, 1)
if (d[k][0] == d[k][1]-2):
c = min(c, 1)
else :c=min(c,2)
else:
for i in range(len(d[k])-2):
if (d[k][i] == d[k][i + 1] and d[k][i + 1] == d[k][i + 2] ): c = min(0, c)
if (d[k][i] == d[k][i + 1] and d[k][i + 1] != d[k][i + 2] ): c = min(1, c)
if (d[k][i] != d[k][i + 1] and d[k][i + 1] == d[k][i + 2] ): c = min(1, c)
if(d[k][i]==d[k][i+1]-1 and d[k][i+1]==d[k][i+2]-1):c=min(0,c)
if (d[k][i] == d[k][i + 1] - 1 and d[k][i + 1] != d[k][i + 2] - 1):c=min(1,c)
if (d[k][i] != d[k][i + 1] - 1 and d[k][i + 1] != d[k][i + 2] - 1 ): c = min(2, c)
if (d[k][i] != d[k][i + 1] - 1 and d[k][i + 1] == d[k][i + 2] - 1): c = min(1, c)
if ( d[k][i]+2==d[k][i+1]): c = min(1, c)
print c
| PYTHON |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.*;
public class mahjong
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int i,r,t;
r=0;
String s,st;
s=in.readLine();
s+=' ';
int[] a=new int[3];
for(i=0;i<s.length();i++)
{
if(s.charAt(i)==' ')
{
st=s.substring(0,i);
s=s.substring(i+1);
i=-1;
a[r]=Integer.parseInt(st.substring(0,1));
if(st.charAt(1)=='p')
a[r]+=15;
else if(st.charAt(1)=='s')
a[r]+=30;
if(r==1)
{
if(a[1]<a[0])
{
t=a[1];
a[1]=a[0];
a[0]=t;
}
}
else if(r==2)
{
if(a[2]<a[0])
{
t=a[2];
a[2]=a[1];
a[1]=a[0];
a[0]=t;
}
else if(a[2]<a[1])
{
t=a[2];
a[2]=a[1];
a[1]=t;
}
}
r++;
}
}
r=2;
a[0]=a[1]-a[0];
a[1]=a[2]-a[1];
if(a[0]==0)
{
r--;
if(a[1]==0)
r--;
}
else if(a[0]==1)
{
r--;
if(a[1]==1)
r--;
}
else if(a[0]==2 || a[1]==0 || a[1]==1 || a[1]==2)
r--;
System.out.println(r);
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a,b,c = input().split()
if a[1] == b[1] == c[1]:
t = sorted([int(a[0]),int(b[0]),int(c[0])])
if (t[1] == t[0] + 1 == t[2] - 1) or (t[0] == t[2]):print(0)
elif t[0] == t[1] or t[1] == t[2]:print(1)
elif t[0] + 1 == t[1] or t[1] + 1 == t[2] or t[0] + 2 == t[1] or t[1] + 2 == t[2]:print(1)
else:print(2)
elif a[1] == b[1]:
s,t = int(a[0]),int(b[0])
if s == t:print(1)
elif min(s,t) + 1 == max(s,t) or min(s,t) + 2 == max(s,t):print(1)
else:print(2)
elif c[1] == b[1]:
s,t = int(c[0]),int(b[0])
if s == t:print(1)
elif min(s,t) + 1 == max(s,t) or min(s,t) + 2 == max(s,t):print(1)
else:print(2)
elif a[1] == c[1]:
s,t = int(a[0]),int(c[0])
if s == t:print(1)
elif min(s,t) + 1 == max(s,t) or min(s,t) + 2 == max(s,t):print(1)
else:print(2)
else:print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def get_min_draw(d):
symbols = list(d.keys())
min_draw = 3
for key in symbols:
for i in range(1, 8):
curr = 3
if i in d[key]:
curr -= 1
if i + 1 in d[key]:
curr -= 1
if i + 2 in d[key]:
curr -= 1
min_draw = min(min_draw, curr)
return min_draw
arr = [i for i in input().split()]
d = {}
d2 = {}
for [num, symbol] in arr:
num = int(num)
if symbol not in d:
d[symbol] = set()
d[symbol].add(num)
if f"{num}{symbol}" not in d2:
d2[f"{num}{symbol}"] = 0
d2[f"{num}{symbol}"] += 1
d2_val = max(0, 3 - max(d2.values()))
print(min(d2_val, get_min_draw(d)))
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | lis = list(map(str,input().split()))
ans = 2
s = len(set(lis))
if s==1:
ans = 0
elif s==2:
ans = 1
lis.sort()
if int(lis[0][0])+1 == int(lis[1][0]) and lis[0][1] == lis[1][1] and int(lis[1][0])+1 == int(lis[2][0]) and lis[1][1] == lis[2][1]:
ans = min(ans,0)
elif int(lis[0][0])+1 == int(lis[1][0]) and lis[0][1] == lis[1][1]:
ans = min(ans,1)
elif int(lis[1][0])+1 == int(lis[2][0]) and lis[1][1] == lis[2][1]:
ans = min(ans,1)
elif int(lis[0][0])+2 == int(lis[1][0]) and lis[0][1] == lis[1][1]:
ans = min(ans,1)
elif int(lis[1][0])+2 == int(lis[2][0]) and lis[1][1] == lis[2][1]:
ans = min(ans,1)
elif int(lis[0][0])+2 == int(lis[2][0]) and lis[0][1] == lis[2][1]:
ans = min(ans,1)
elif int(lis[0][0])+1 == int(lis[2][0]) and lis[0][1] == lis[2][1]:
ans = min(ans,1)
print(ans) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | def trans(x): return int(x[0])*10+{"m":0,"p":1,"s":2}[x[1]]
def isKoutsu(a,b,c): return a == b and a == c
def isShuntsu(a,b,c):
x, z = max(a,b,c), min(a,b,c)
y = (a + b + c) - (x + z)
return x - y == 10 and y - z == 10
a,b,c = map(trans, input().split(' '))
if isKoutsu(a,b,c) or isShuntsu(a,b,c):
print(0)
exit(0)
for i in range(1,10):
for j in range(0,3):
k = i*10+j
if isKoutsu(a,b,k) or isKoutsu(a,c,k) or isKoutsu(c,b,k) or isShuntsu(a,b,k) or isShuntsu(a,c,k) or isShuntsu(c,b,k):
print(1)
exit(0)
print(2) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
****************************************
*/
import java.util.*;
import java.awt.Point;
import java.lang.Math;
import java.util.Arrays;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.IntStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
FastScanner in=new FastScanner();
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
int a[][] = new int[26][9];
for(int i=0;i<3;i++){
String S = in.n();
a[S.charAt(1)-'a'][S.charAt(0)-'1']++;
}
int max = 0;
for (int c=0; c<26; c++) {
for (int d=0; d<9; d++) {
max = Math.max(max, a[c][d]);
}
}
int minKoutsu = 3-max;
max = 0;
for (int c=0; c<26; c++) {
for (int d=2; d<9; d++) {
int count = 0;
for (int i=-2; i<=0; i++) {
if (a[c][d+i] > 0) {
count++;
}
}
max = Math.max(max, count);
}
}
int minShuntsu = 3-max;
int answer = Math.min(minKoutsu, minShuntsu);
System.out.println(answer);
}
private static int sumOfDigits(int number) {
if (number <= 0) return 0;
int sum = 0;
while (number > 0) {
sum += number%10;
number /= 10;
}
return sum;
}
static void ruffle_sort(int[] a) {
//shandom_ruffle
Random r=new Random();
int n=a.length;
for (int i=0; i<n; i++) {
int oi=r.nextInt(i);
int temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
//sort
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
void print(int a){
System.out.println(a);
}
String n(){
return next();
}
void ps(String a) {
System.out.print(a);
}
void pls(String a) {
System.out.println(a);
}
int[] ria(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=ni();
return a;
}
char[] rca(int n, String S){
char a[] = S. toCharArray();
return a;
}
int [][] rda(int n, int m){
int a[][] = new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
a[i][j]=ni();
}
}
return a;
}
void pa(int [] a) {
for (int i=0; i<a.length; i++)
System.out.print(a[i]+" ");
}
void pla(int [] a) {
for (int i=0; i<a.length; i++)
System.out.println(a[i]);
}
long nl() {
return Long.parseLong(next());
}
}
static int max(){
return Integer.MAX_VALUE;
}
public int factorial(int n) {
int fact = 1;
int i = 1;
while(i <= n) {
fact *= i;
i++;
}
return fact;
}
public static long gcd(long x,long y)
{
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int gcd(int x,int y)
{
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int abs(int a,int b)
{
return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
public static int min(int a,int b)
{
if(a>b)
return b;
else
return a;
}
public static long max(long a,long b)
{
if(a>b)
return a;
else
return b;
}
public static long min(long a,long b)
{
if(a>b)
return b;
else
return a;
}
public static long pow(long n,long p,long m)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
if(result>=m)
result%=m;
p >>=1;
n*=n;
if(n>=m)
n%=m;
}
return result;
}
public static long pow(long n,long p)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
p >>=1;
n*=n;
}
return result;
}
static long sort(int a[]){
int n=a.length;
int b[]=new int[n];
return mergeSort(a,b,0,n-1);
}
static long mergeSort(int a[],int b[],long left,long right){
long c=0;
if(left<right){
long mid=left+(right-left)/2;
c= mergeSort(a,b,left,mid);
c+=mergeSort(a,b,mid+1,right);
c+=merge(a,b,left,mid+1,right);
}
return c;
}
static long merge(int a[],int b[],long left,long mid,long right){
long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right){
if(a[i]<=a[j]){
b[k++]=a[i++];
}
else{
b[k++]=a[j++];c+=mid-i;
}
}
while (i <= (int)mid - 1)
b[k++] = a[i++];
while (j <= (int)right)
b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
a[i] = b[i];
return c;
}
static class InputReader extends BufferedReader {
public InputReader(InputStream st) {
super(new InputStreamReader(st));
}
public String readLine() {
try {
return super.readLine();
} catch (IOException e) {
return null;
}
}
private int readByte() {
try {
return read();
} catch (IOException e) {
throw new RuntimeException();
}
}
public int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | m={"s":[0]*9, "m":[0]*9, "p":[0]*9}
for e in input().split():
m[e[1]][int(e[0])-1]+=1
ret=2
for t in "smp":
l=m[t]
if max(l)>=2:
ret=min(ret, 3-max(l))
else:
for i in range(7):
seq = sum(l[i:i+3])
ret = min(ret, 3-seq)
print(ret) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.util.*;
import java.io.*;
public class B_Tokitsukaze_and_Mahjong {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st=new StringTokenizer(br.readLine());
Tile tiles[]=new Tile[3];
for(int i1=0;i1<3;i1++) {
String c=st.nextToken();
int a=Integer.parseInt(c.substring(0,1));
String b=c.substring(1);
tiles[i1]=new Tile(a,b);
}
Arrays.sort(tiles);
int extra=100;
int extra2=100;
if(tiles[0].a==tiles[1].a && tiles[1].a==tiles[2].a && tiles[0].b.equals(tiles[1].b) && tiles[1].b.equals(tiles[2].b)) {
extra=0;
}
else if(tiles[0].a==tiles[1].a && tiles[0].b.equals(tiles[1].b)) {
extra=1;
}
else if(tiles[0].a==tiles[2].a && tiles[2].b.equals(tiles[0].b)) {
extra=1;
}
else if(tiles[2].a==tiles[1].a && tiles[2].b.equals(tiles[1].b)) {
extra=1;
}
else {
extra=2;
}
if(tiles[2].a-tiles[1].a==1 && tiles[1].a-tiles[0].a==1 && tiles[2].b.equals(tiles[1].b)&& tiles[1].b.equals(tiles[0].b)) {
extra2=0;
}
else if(tiles[2].a-tiles[1].a==1 && tiles[2].b.equals(tiles[1].b)) {
extra2=1;
}
else if(tiles[1].a-tiles[0].a==1 && tiles[1].b.equals(tiles[0].b)) {
extra2=1;
}
else if(tiles[2].a-tiles[0].a==1 && tiles[2].b.equals(tiles[0].b)) {
extra2=1;
}
else if(tiles[2].a-tiles[0].a==2 && tiles[2].b.equals(tiles[0].b)) {
extra2=1;
}
else if(tiles[2].a-tiles[1].a==2 && tiles[2].b.equals(tiles[1].b)) {
extra2=1;
}
else if(tiles[1].a-tiles[0].a==2 && tiles[0].b.equals(tiles[1].b)) {
extra2=1;
}
else {
extra2=2;
}
pw.println(Math.min(extra, extra2));
pw.close();
}
}
class Tile implements Comparable<Tile>{
int a;
String b;
Tile(int x, String y){
a=x;
b=y;
}
@Override
public int compareTo(Tile arg0) {
if(this.a-arg0.a>0) {
return 1;
}
return -1;
}
}
| JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a, b, c = input().split()
if a == b and b == c :
print("0")
else :
ok = False
if a[1] == b[1] and b[1] == c[1] :
aa, bb, cc = int(a[0]), int(b[0]), int(c[0])
l = [aa, bb, cc]
l.sort()
if l[0] == l[1]-1 and l[1] == l[2]-1 :
ok = True
if ok :
print("0")
else :
if a == b or b == c or a==c :
print("1")
else :
if a[1] == b[1] or b[1] == c[1] or a[1] == c[1] :
aa, bb, cc = int(a[0]), int(b[0]), int(c[0])
if ((aa == bb-1 or aa-1 == bb) or (aa == bb-2 or aa-2 == bb)) and a[1] == b[1] :
print("1")
elif ((aa == cc-1 or aa-1 == cc) or (aa == cc-2 or aa-2 == cc)) and a[1] == c[1] :
print("1")
elif ((cc == bb-1 or cc-1 == bb) or (cc == bb-2 or cc-2 == bb)) and b[1] == c[1] :
print("1")
else :
print("2")
else :
print("2")
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | ll= lambda : list(map(int,input().split()))
testcases=1
# testcases=int(input())
for testcase in range(testcases):
s1,s2,s3=input().split()
ss=[s1,s2,s3]
ss.sort()
if(len(set([i[1] for i in ss]))==1):
if(len(set([i[0] for i in ss]))==1 or ((int(ss[0][0])==int(ss[1][0])-1) and (int(ss[0][0])==int(ss[2][0])-2))):
print(0)
elif ((len(set([i[0] for i in ss]))==2) or (int(ss[0][0])==int(ss[1][0])-1) or (int(ss[0][0])==int(ss[1][0])-2) or (int(ss[1][0])==int(ss[2][0])-1)):
print(1)
else:
print(2)
elif(len(set([i[1] for i in ss]))==2):
ans=2
for i in range(0,2):
for j in range(i+1,3):
if ss[i][1]==ss[j][1]:
if(ss[i][0]==ss[j][0] or abs(int(ss[i][0])-int(ss[j][0]))<=2):
# print(i,j)
ans=1
break
if(ans==1):
break
print(ans)
else:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class F {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(reader.readLine());
char[] f = st.nextToken().toCharArray();
char[] s = st.nextToken().toCharArray();
char[] t = st.nextToken().toCharArray();
ArrayList<Integer> fi = new ArrayList<>();
ArrayList<Integer> se = new ArrayList<>();
ArrayList<Integer> th = new ArrayList<>();
if(f[1] == 'm'){
fi.add(Integer.parseInt(f[0] + ""));
}
else if(f[1] == 'p'){
se.add(Integer.parseInt(f[0] + ""));
}
else{
th.add(Integer.parseInt(f[0] + ""));
}
if(s[1] == 'm'){
fi.add(Integer.parseInt(s[0] + ""));
}
else if(s[1] == 'p'){
se.add(Integer.parseInt(s[0] + ""));
}
else{
th.add(Integer.parseInt(s[0] + ""));
}
if(t[1] == 'm'){
fi.add(Integer.parseInt(t[0] + ""));
}
else if(t[1] == 'p'){
se.add(Integer.parseInt(t[0] + ""));
}
else{
th.add(Integer.parseInt(t[0] + ""));
}
if(se.size() == 1 && fi.size() == 1 && th.size() == 1){
System.out.println(2);
}
else if(fi.size() == 2){
if(Math.abs(fi.get(0) - fi.get(1)) <= 2){
System.out.println(1);
}
else{
System.out.println(2);
}
}
else if(se.size() == 2){
if(Math.abs(se.get(0) - se.get(1)) <= 2){
System.out.println(1);
}
else{
System.out.println(2);
}
}
else if(th.size() == 2){
if(Math.abs(th.get(0) - th.get(1)) <= 2){
System.out.println(1);
}
else{
System.out.println(2);
}
}
else if(fi.size() == 3){
Collections.sort(fi);
if(fi.get(0) == fi.get(1) && fi.get(1) == fi.get(2) || fi.get(0) == fi.get(1) - 1 && fi.get(1) == fi.get(2) - 1){
System.out.println(0);
}
else if(fi.get(1) - fi.get(0) <= 2 || fi.get(2) - fi.get(1) <= 2){
System.out.println(1);
}
else{
System.out.println(2);
}
}
else if(se.size() == 3){
Collections.sort(se);
if(se.get(0) == se.get(1) && se.get(1) == se.get(2) || se.get(0) == se.get(1) - 1 && se.get(1) == se.get(2) - 1){
System.out.println(0);
}
else if(se.get(1) - se.get(0) <= 2 || se.get(2) - se.get(1) <= 2){
System.out.println(1);
}
else{
System.out.println(2);
}
}
else if(th.size() == 3){
Collections.sort(th);
if(th.get(0) == th.get(1) && th.get(1) == th.get(2) || th.get(0) == th.get(1) - 1 && th.get(1) == th.get(2) - 1){
System.out.println(0);
}
else if(th.get(1) - th.get(0) <= 2 || th.get(2) - th.get(1) <= 2){
System.out.println(1);
}
else{
System.out.println(2);
}
}
}
} | JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | s1,s2,s3=map(str,input().split())
arr=[]
arr.append(ord(s1[0]))
arr.append(ord(s2[0]))
arr.append(ord(s3[0]))
flag=0
if s1==s2 and s1==s3:
flag=1
print(0)
if s1[1]==s2[1] and s1[1]==s3[1]:
arr.sort()
if arr[1]-arr[0]==1 and arr[2]-arr[1]==1:
if flag==0:
flag=1
print(0)
if (s1==s2 and s2!=s3) or (s2==s3 and s3!=s1) or (s1==s3 and s2!=s1):
if flag==0:
flag=1
print(1)
if (s1[1]==s2[1] and (abs(arr[1]-arr[0])==1 or abs(arr[1]-arr[0])==2)) or (s2[1]==s3[1] and (abs(arr[2]-arr[1])==1 or abs(arr[2]-arr[1])==2)) or (s1[1]==s3[1] and (abs(arr[2]-arr[0])==1 or abs(arr[2]-arr[0])==2)):
if flag==0:
flag=1
print(1)
if flag==0:
print(2)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | a,b,c = input().split()
ans = 2
if a == b == c:
ans = 0
elif a[1] == b[1] == c[1]:
l = sorted([int(a[0]), int(b[0]), int(c[0])])
if l[0] == l[1] - 1 == l[2] - 2:
ans = 0
if ans != 0:
if a == b or b == c or a == c:
ans = 1
else:
if a[1] == b[1] and abs(int(a[0]) - int(b[0])) <= 2:
ans = 1
elif c[1] == b[1] and abs(int(c[0]) - int(b[0])) <= 2:
ans = 1
elif c[1] == a[1] and abs(int(c[0]) - int(a[0])) <= 2:
ans = 1
print(ans) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
bool compare(string a, string b) {
if (a[1] == b[1]) return a[0] < b[0];
return a[1] < b[1];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s[3];
cin >> s[0] >> s[1] >> s[2];
sort(s, s + 3, compare);
if (s[0] == s[1] && s[1] == s[2])
cout << "0\n";
else if (s[0][1] == s[1][1] && s[1][1] == s[2][1] &&
(int)s[1][0] == s[0][0] + 1 && (int)s[2][0] == s[1][0] + 1)
cout << "0\n";
else if ((s[0] == s[1] && s[1] != s[2]) || (s[1] == s[2] && s[0] != s[1]))
cout << "1\n";
else if ((abs(s[0][0] - s[1][0]) <= 2 && s[1][1] == s[0][1]) ||
(abs(s[2][0] - s[1][0]) <= 2) && s[2][1] == s[1][1])
cout << "1\n";
else
cout << "2\n";
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename S37, typename... Args>
void err(istream_iterator<string> it, S37 a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
const long long N = 300100, mod = 1e9 + 7, mod2 = 1e9 + 9, mod3 = 998244353,
sq = 450, base = 37, lg = 25, inf = 1e18 + 10, del = 79589;
long long n, m, X, Y, Z, W, t, k, q, ans, a[N];
string x, y, z;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> x >> y >> z;
if (x > y) swap(x, y);
if (y > z) swap(y, z);
if (y < x) swap(x, y);
if (x[1] == y[1] && y[1] == z[1] && y[0] - x[0] == z[0] - y[0] &&
y[0] - x[0] <= 1)
return cout << 0, 0;
if ((x[1] == y[1] && abs(y[0] - x[0]) <= 2) ||
(x[1] == z[1] && abs(z[0] - x[0]) <= 2) ||
(z[1] == y[1] && abs(y[0] - z[0]) <= 2))
return cout << 1, 0;
cout << 2;
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | s=input().split()
hashi=dict()
for i in s:
if(i in hashi):
hashi[i]+=1
else:
hashi[i]=1
maxa=3
for i in ['s','m','p']:
for j in range(1,10):
z=chr(48+j)+i
if z in hashi:
maxa=min(maxa,3-hashi[z])
for i in ['s','m','p']:
for j in range(1,8):
z1=chr(48+j)+i
z2=chr(49+j)+i
z3=chr(48+2+j)+i
count=0
if(z1 not in hashi):
count+=1
if(z2 not in hashi):
count+=1
if(z3 not in hashi):
count+=1
maxa=min(count,maxa)
print(maxa) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.util.Arrays;
import java.util.Scanner;
public class TokitsukazeMahjong {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s1 = in.next(), s2 = in.next(), s3 = in.next();
in.close();
char c1 = s1.charAt(1), c2 = s2.charAt(1), c3 = s3.charAt(1);
int i1 = Integer.valueOf(s1.substring(0, 1)), i2 = Integer.valueOf(s2.substring(0, 1)),
i3 = Integer.valueOf(s3.substring(0, 1)), a[] = new int[] { i1, i2, i3 };
Arrays.sort(a);
if (s1.equals(s2) && s1.equals(s3) || (a[2] - a[1] == 1 && a[1] - a[0] == 1 && c1 == c2 && c1 == c3)) {
System.out.println(0);
} else if (s1.equals(s2) || s1.equals(s3) || s2.equals(s3) || (c1 == c2 && Math.abs(i1 - i2) < 3)
|| (c1 == c3 && Math.abs(i1 - i3) < 3) || (c2 == c3 && Math.abs(i2 - i3) < 3)) {
System.out.println(1);
} else {
System.out.println(2);
}
}
}
| JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | '''
parse the string so that we have a dictionary of s - [1, 3, 5]
p -[2, 2]
m - [1]
it is 1-9
for each of the color, we check can we form a 3 same number -- this is easy, have a another count
or 3 consercutive number -- this is easy as well, sort the list and traverse over
'''
def parse_string_to_counts(input):
color_digit = {}
for x in input:
digit, color = int(x[0]), x[1]
if color not in color_digit:
color_digit[color] = {}
if digit not in color_digit[color]:
color_digit[color][digit] = 0
color_digit[color][digit] += 1
return color_digit
def smallest_needed(input):
color_digit = parse_string_to_counts(input)
min_number = 3
for values in color_digit.values():
min_same = get_min_same(values)
min_consercutive = get_min_consercutive(values)
min_number = min(min_number, min_same, min_consercutive)
return min_number
def get_min_same(digit_counts):
return max(0, 3 - max(digit_counts.values()))
def get_min_consercutive(digit_counts):
min_count = 3
for key in digit_counts:
if key + 1 in digit_counts and key+2 in digit_counts:
return 0
elif key+1 in digit_counts or key+2 in digit_counts:
min_count = min(min_count, 1)
else:
min_count = min(min_count, 2)
return min_count
input = input().split()
print(smallest_needed(input))
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | q = list(input().split())
s1 = q[0]
s2 = q[1]
s3 = q[2]
#print(1)
l = []
#print(q[:-1])
#print(s1[:-1])
l.append(int(s1[:-1]))
l.append(int(s2[:-1]))
l.append(int(s3[:-1]))
if(s1==s2==s3):
print('0')
exit()
if(s1[-1]==s2[-1] and s2[-1]==s3[-1] and s3[-1]==s1[-1]):
#print(1)
a = sorted(l)
if(a[2]-a[0]==2 and a[1]-a[0]==1):
print('0')
exit()
#else:
if(s1==s2 or s2==s3 or s1==s3):
print('1')
exit()
if(s1[-1]!=s2[-1] and s2[-1]!=s3[-1] and s3[-1]!=s1[-1]):
print(2)
exit()
if(s1[-1]==s2[-1]):
if(abs(int(s1[:-1])-int(s2[:-1]))==2 or abs(int(s1[:-1])-int(s2[:-1]))==1):
print(1)
exit()
if (s1[-1] == s3[-1]):
if (abs(int(s1[:-1])-int(s3[:-1]))==2 or abs(int(s1[:-1])-int(s3[:-1]))==1):
print(1)
exit()
if (s2[-1] == s3[-1]):
if (abs(int(s2[:-1])-int(s3[:-1]))==2 or abs(int(s2[:-1])-int(s3[:-1]))==1):
print(1)
exit()
print(2) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
long long power(long long a, long long b, long long c) {
long long ans = 1;
a = (a % c);
while (b > 0) {
if (b & 1) {
ans = (ans * a) % c;
}
b = b >> 1;
a = (a * a) % c;
}
return ans;
}
using namespace std;
int main() {
vector<string> s;
for (int i = 0; i < 3; i++) {
string a;
cin >> a;
s.push_back(a);
}
vector<int> n;
set<int> ns;
set<char> nc;
vector<char> c;
vector<pair<char, int>> p;
for (int i = 0; i < 3; i++) {
n.push_back(s[i][0] - '0');
c.push_back(s[i][1]);
ns.insert(s[i][0] - '0');
nc.insert(s[i][1]);
p.push_back({s[i][1], s[i][0] - '0'});
}
if (nc.size() == 3)
cout << 2;
else if (nc.size() == 1) {
if (ns.size() == 1)
cout << 0;
else if (ns.size() == 2)
cout << 1;
else {
sort(n.begin(), n.end());
int c = 1;
int g = n[1] - n[0];
int h = n[2] - n[1];
if (g == h && g == 1)
cout << 0;
else if (g == 1 || h == 1)
cout << 1;
else if (g == 2 || h == 2)
cout << 1;
else
cout << 2;
}
} else if (nc.size() == 2) {
if (ns.size() == 1)
cout << 1;
else {
sort(p.begin(), p.end());
if (p[0].first == p[1].first) {
if (abs(p[0].second - p[1].second) < 3)
cout << 1;
else
cout << 2;
} else if (p[1].first == p[2].first) {
if (abs(p[1].second - p[2].second) < 3)
cout << 1;
else
cout << 2;
} else if (p[0].first == p[2].first) {
if (abs(p[0].second - p[2].second) < 3)
cout << 1;
else
cout << 2;
}
}
}
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
long long ans = 3;
set<string> s;
s.insert(s1);
s.insert(s2);
s.insert(s3);
if (s.size() == 1)
ans = 0;
else if (s.size() == 2)
ans = 1;
else
ans = 2;
set<long long> sa, ma, pa;
if (s1[1] == 's')
sa.insert((long long)(s1[0] - '0'));
else if (s1[1] == 'm')
ma.insert((long long)(s1[0] - '0'));
else
pa.insert((long long)(s1[0] - '0'));
if (s2[1] == 's')
sa.insert((long long)(s2[0] - '0'));
else if (s2[1] == 'm')
ma.insert((long long)(s2[0] - '0'));
else
pa.insert((long long)(s2[0] - '0'));
if (s3[1] == 's')
sa.insert((long long)(s3[0] - '0'));
else if (s3[1] == 'm')
ma.insert((long long)(s3[0] - '0'));
else
pa.insert((long long)(s3[0] - '0'));
long long c = 0;
long long prev = -1;
for (auto x : sa) {
if (c == 0)
c++;
else if (x - 1 == prev)
c++;
else if (x - 2 == prev) {
c = 2;
if (3 - c < ans) ans = 3 - c;
c = 1;
} else {
c = 1;
}
prev = x;
if (3 - c < ans) ans = 3 - c;
}
c = 0;
prev = -1;
for (auto x : ma) {
if (c == 0)
c++;
else if (x - 1 == prev)
c++;
else if (x - 2 == prev) {
c = 2;
if (3 - c < ans) ans = 3 - c;
c = 1;
} else {
c = 1;
}
prev = x;
if (3 - c < ans) ans = 3 - c;
}
c = 0;
prev = -1;
for (auto x : pa) {
if (c == 0)
c++;
else if (x - 1 == prev)
c++;
else if (x - 2 == prev) {
c = 2;
if (3 - c < ans) ans = 3 - c;
c = 1;
} else {
c = 1;
}
prev = x;
if (3 - c < ans) ans = 3 - c;
}
cout << ans;
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
int judge(string a1, string a2, string a3) {
int ans1 = 2, ans2 = 2, ans3 = 2, ans4 = 2, ans5 = 2, ans6 = 2, ans7 = 2;
if (a1 == a2) ans1--;
if (a1 == a3) ans1--;
string a4, a5;
a4 += (((a1[0] - '0') + 1) + '0');
a5 += (((a1[0] - '0') - 1) + '0');
a4 += a1[1];
a5 += a1[1];
if (a2 == a4) ans2--;
if (a3 == a5) ans2--;
if (a2 == a5) ans3--;
if (a3 == a4) ans3--;
string a6, a7;
a6 += (((a1[0] - '0') + 2) + '0');
a6 += a1[1];
a7 += (((a1[0] - '0') - 2) + '0');
a7 += a1[1];
if (a2 == a4) ans4--;
if (a3 == a6) ans4--;
if (a2 == a6) ans6--;
if (a3 == a4) ans6--;
if (a2 == a5) ans7--;
if (a3 == a7) ans7--;
if (a3 == a5) ans5--;
if (a2 == a7) ans5--;
return min(ans1, min(ans2, min(ans3, min(ans4, min(ans5, min(ans6, ans7))))));
}
int main() {
string a1, a2, a3;
cin >> a1 >> a2 >> a3;
int re = min(judge(a1, a2, a3),
min(judge(a2, a1, a3),
min(judge(a2, a3, a1),
min(judge(a1, a3, a2),
min(judge(a3, a1, a2), judge(a3, a2, a1))))));
cout << re;
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | from collections import Counter
ts=Counter(''.join(reversed(t)) for t in input().split())
t0 = None
run = 0
ans = 3
for t, c in sorted(ts.items()):
if t0 is None or t[0] != t0[0] or int(t[1]) != int(t0[1])+1:
run = 0
t0 = t
run += 1
ans = min(ans, 3-max(c,run))
for s in 'spm':
for r in range(1, 10):
if s+str(r-1) in ts and s+str(r+1) in ts:
ans = min(ans, 1)
print(ans)
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | import java.util.*;
import java.io.*;
public class Main
{
PrintWriter out;
FastReader sc;
long[] m= {(long)(1e9+7),998244353};
long mod=m[1];
long maxlong=Long.MAX_VALUE;
long minlong=Long.MIN_VALUE;
/******************************************************************************************
*****************************************************************************************/
public void sol(){
String[] s=rl1().trim().split("\\s");
String[] str= {"s","m","p"};
int ans=3;
HashMap<String,Integer> map=new HashMap<>();
for(int i=0;i<s.length;i++) {
map.put(s[i],map.getOrDefault(s[i],0)+1);
}for(int i=1;i<=9;i++) {
for(int j=0;j<3;j++) {
String a=i+str[j];
if(map.get(a)==null)continue;
ans=min(ans,3-map.get(a));
}
}for(int i=1;i<=7;i++) {
for(int j=0;j<3;j++) {
String a=i+str[j],b=(i+1)+str[j],c=(i+2)+str[j];
int p=0;
if(map.get(a)!=null)p++;
if(map.get(b)!=null)p++;
if(map.get(c)!=null)p++;
ans=min(ans,3-p);
}
}pl(ans);
}
public static void main(String[] args)
{
Main g=new Main();
g.out=new PrintWriter(System.out);
g.sc=new FastReader();
int t=1;
// t=g.ni();
while(t-->0)
g.sol();
g.out.flush();
}
/****************************************************************************************
*****************************************************************************************/
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} public int ni(){
return sc.nextInt();
}public long nl(){
return sc.nextLong();
}public double nd(){
return sc.nextDouble();
}public char[] rl(){
return sc.nextLine().toCharArray();
}public String rl1(){
return sc.nextLine();
}
public void pl(Object s){
out.println(s);
}public void ex(){
out.println();
}
public void pr(Object s){
out.print(s);
}public String next(){
return sc.next();
}public long abs(long x){
return Math.abs(x);
}
public int abs(int x){
return Math.abs(x);
}
public double abs(double x){
return Math.abs(x);
}public long min(long x,long y){
return (long)Math.min(x,y);
}
public int min(int x,int y){
return (int)Math.min(x,y);
}
public double min(double x,double y){
return Math.min(x,y);
}public long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}public long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
void sort1(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a) {
l.add(i);
}
Collections.sort(l,Collections.reverseOrder());
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}
void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a) {
l.add(i);
}
Collections.sort(l);
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a) {
l.add(i);
}
Collections.sort(l);
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}void sort1(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a) {
l.add(i);
}
Collections.sort(l,Collections.reverseOrder());
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}
void sort(double[] a) {
ArrayList<Double> l = new ArrayList<>();
for (double i : a) {
l.add(i);
}
Collections.sort(l);
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}long pow(long a,long b){
if(b==0){
return 1;
}long p=pow(a,b/2);
if(b%2==0) return (p*p)%mod;
else return (((p*p)%mod)*a)%mod;
}
int swap(int a,int b){
return a;
}long swap(long a,long b){
return a;
}double swap(double a,double b){
return a;
}
boolean isPowerOfTwo (int x)
{
return x!=0 && ((x&(x-1)) == 0);
}boolean isPowerOfTwo (long x)
{
return x!=0 && ((x&(x-1)) == 0);
}public long max(long x,long y){
return (long)Math.max(x,y);
}
public int max(int x,int y){
return (int)Math.max(x,y);
}
public double max(double x,double y){
return Math.max(x,y);
}long sqrt(long x){
return (long)Math.sqrt(x);
}int sqrt(int x){
return (int)Math.sqrt(x);
}void input(int[] ar,int n){
for(int i=0;i<n;i++)ar[i]=ni();
}void input(long[] ar,int n){
for(int i=0;i<n;i++)ar[i]=nl();
}void fill(int[] ar,int k){
Arrays.fill(ar,k);
}void yes(){
pl("YES");
}void no(){
pl("NO");
}
long[] sieve(int n)
{
long[] k=new long[n+1];
boolean[] pr=new boolean[n+1];
for(int i=1;i<=n;i++){
k[i]=i;
pr[i]=true;
}for(int i=2;i<=n;i++){
if(pr[i]){
for(int j=i+i;j<=n;j+=i){
pr[j]=false;
if(k[j]==j){
k[j]=i;
}
}
}
}return k;
}
int strSmall(int[] arr, int target)
{
int start = 0, end = arr.length-1;
int ans = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (arr[mid] >= target) {
end = mid - 1;
}
else {
ans = mid;
start = mid + 1;
}
}
return ans;
} int strSmall(ArrayList<Integer> arr, int target)
{
int start = 0, end = arr.size()-1;
int ans = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (arr.get(mid) > target) {
start = mid + 1;
ans=start;
}
else {
end = mid - 1;
}
}
return ans;
}long mMultiplication(long a,long b)
{
long res = 0;
a %= mod;
while (b > 0)
{
if ((b & 1) > 0)
{
res = (res + a) % mod;
}
a = (2 * a) % mod;
b >>= 1;
}
return res;
}long nCr(int n, int r ,int p)
{
if (n<r)
return 0;
if (r == 0)
return 1;
long[] fac = new long[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i %p;
return (fac[n] * modInverse(fac[r], p)
% p * modInverse(fac[n - r], p)
% p)
% p;
}long power(long x, long y, long p)
{
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}long modInverse(long n, long p)
{
return power(n, p - 2, p);
}
int[][] floydWarshall(int graph[][],int INF,int V)
{
int dist[][] = new int[V][V];
int i, j, k;
for (i = 0; i < V; i++)
for (j = 0; j < V; j++)
dist[i][j] = graph[i][j];
for (k = 0; k < V; k++)
{
for (i = 0; i < V; i++)
{
for (j = 0; j < V; j++)
{
if (dist[i][k] + dist[k][j] < dist[i][j])
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}return dist;
}
class minque {
Deque<Long> q;
minque(){
q=new ArrayDeque<Long>();
}public void add(long p){
while(!q.isEmpty()&&q.peekLast()>p)q.pollLast();
q.addLast(p);
}public void remove(long p) {
if(!q.isEmpty()&&q.getFirst()==p)q.removeFirst();
}public long min() {
return q.getFirst();
}
}
public static class Pair implements Comparable<Pair> {
long x;
long y;
public Pair(long x, long y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair other) {
if (this.x == other.x) {
return Long.compare(this.y, other.y);
}
return Long.compare(this.x, other.x);
}
}
}
| JAVA |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | """
NTC here
"""
from sys import setcheckinterval, stdin
setcheckinterval(1000)
# print("Case #{}: {} {}".format(i, n + m, n * m))
iin = lambda: int(stdin.readline())
lin = lambda: list(map(int, stdin.readline().split()))
def check1(a):
if not a:
return 3
n=len(a)
ans=1
for i in range(n):
sola={a[i]:1}
if a[i]+1<10:
sola[a[i]+1]=0
if a[i]+2<10:
sola[a[i]+2]=0
if a[i]-1>0:
sola[a[i]-1]=0
if a[i]-2>0:
sola[a[i]-2]=0
j=i+1
while j<n:
try:
sola[a[j]]=1
except:pass
j+=1
if a[i]-1 in sola and a[i]-2 in sola:
ans=max(ans,sola[a[i]]+sola[a[i]-1]+sola[a[i]-2])
if a[i]-1 in sola and a[i]+1 in sola:
ans=max(ans,sola[a[i]]+sola[a[i]-1]+sola[a[i]+1])
if a[i]+1 in sola and a[i]+2 in sola:
ans=max(ans,sola[a[i]]+sola[a[i]+1]+sola[a[i]+2])
return 3-ans
def check2(a):
if not a:return 3
d={}
for i in a:
try:
d[i]+=1
except:
d[i]=1
return 3-max(d.values())
s=input().split()
a1=[];a2=[];a3=[]
for i in s:
if i[1]=='m':
a1.append(int(i[0]))
elif i[1]=='p':
a2.append(int(i[0]))
elif i[1]=='s':
a3.append(int(i[0]))
a1.sort()
a2.sort()
a3.sort()
ans=min(check1(a1),check1(a2),check1(a3),check2(s))
print(ans)
# print(check1(a1),check1(a2),check1(a3),check2(s),a1,a2,a3) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | c1, c2, c3 = input().strip().split()
nums = sorted([int(c1[0]), int(c2[0]), int(c3[0])])
if c1 == c2 == c3:
print(0)
elif (c1[1] == c2[1] == c3[1]) and (nums[0] == nums[1]-1 == nums[2]-2):
print(0)
elif c1 == c2 or c1 == c3 or c2 == c3:
print(1)
elif (c1[1] == c2[1] and abs(int(c1[0])-int(c2[0])) in (1,2)) or (c1[1] == c3[1] and abs(int(c1[0])-int(c3[0])) in (1,2)) or (c2[1] == c3[1] and abs(int(c2[0])-int(c3[0])) in (1,2)):
print(1)
else:
print(2) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
string s[3];
int main() {
cin >> s[0] >> s[1] >> s[2];
int data[3];
for (int i = 0; i < 3; i++) {
if (s[i][1] == 's') {
data[i] = s[i][0] - '0' + 10 * 1;
} else if (s[i][1] == 'm') {
data[i] = s[i][0] - '0' + 10 * 3;
} else if (s[i][1] == 'p') {
data[i] = s[i][0] - '0' + 10 * 5;
}
}
sort(data, data + 3);
if (data[0] == data[2]) {
cout << 0 << endl;
} else if (data[0] + 1 == data[1] && data[1] + 1 == data[2]) {
cout << 0 << endl;
} else if (data[0] == data[1] || data[1] == data[2]) {
cout << 1 << endl;
} else if (data[0] + 1 == data[1] || data[1] + 1 == data[2] ||
data[0] + 2 == data[1] || data[1] + 2 == data[2]) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
return 0;
}
| CPP |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 | st = list(map(str, input().split()))
def is_koutsu(s):
cnt = 0
arr = []
for i in s:
cnt = 0
for j in s:
if i == j:
cnt += 1
arr.append(cnt)
return max(arr)
def is_shuntsu(s):
cnt = 0
arr = []
for i in s:
cnt = 0
for j in s:
for k in s:
if(int(i[0]) + 1 == int(j[0]) and int(i[0]) + 2 == int(k[0]) and i[1] == j[1] and j[1] == k[1]):
cnt += 1
arr.append(cnt)
return max(arr)
def kek(s):
for i in s:
for j in s:
if(int(i[0]) + 1 == int(j[0]) and i[1] == j[1]):
return 2
return 0
def kek_1(s):
for i in s:
for j in s:
if(int(i[0]) + 2 == int(j[0]) and i[1] == j[1]):
return 2
return 0
if(is_shuntsu(st) == 1):
print(0)
exit()
print(min( min(3 - is_koutsu(st), 3 - kek_1(st)) , min(3 - is_shuntsu(st), 3 - kek(st)))) | PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 |
# In[10]:
m = {}
p = {}
s = {}
for i in range(1,10):
p[str(i)+'p'] = i
s[str(i)+'s'] = i
m[str(i)+'m'] = i
card = []
card.append(m)
card.append(p)
card.append(s)
# In[12]:
a = input()
tmp = a.split(' ')
# In[13]:
ma = [[],[],[]]
for obj in tmp:
if obj in card[0]:
ma[0].append(int(obj[0]))
elif obj in card[1]:
ma[1].append(int(obj[0]))
else:
ma[2].append(int(obj[0]))
for i in range(3):
list.sort(ma[i])
# In[15]:
output = 1
save = 0
max_count = 0
three = []
for i in range(3):
for j in range(1,10):
fuck = 0
for k in range(len(ma[i])):
if ma[i][k] == j:
fuck += 1
three.append(fuck)
if max(three) >= 3:
output = 0
elif max(three) == 2:
output = 1
else:
output = 2
index = 2
for i in range(3):
if output == 0:
break
n = len(ma[i])
count = 0
for j in range(n):
if j == 0:
save = ma[i][j]
else:
if save - ma[i][j] == -1:
count += 1
if count == 2:
index = 0
break
elif count == 1:
index = 1
elif save - ma[i][j] == -2:
index = 1
else:
if count == 1:
index = 1
count = 0
save = ma[i][j]
if index == 0:
break
print(min(output,index))
# In[ ]:
| PYTHON3 |
1191_B. Tokitsukaze and Mahjong | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, β¦, 9m, 1p, 2p, β¦, 9p, 1s, 2s, β¦, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game:
* A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
* A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
* A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples:
* [2m, 3p, 2s, 4m, 1s, 2s, 4s] β it contains no koutsu or shuntsu, so it includes no mentsu;
* [4s, 3m, 3p, 4s, 5p, 4s, 5p] β it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
* [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
Input
The only line contains three strings β the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.
Output
Print a single integer β the minimum number of extra suited tiles she needs to draw.
Examples
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]. | 2 | 8 |
t=list(map(str,input().split()))
t.sort(key=lambda x: x[1]+x[0])
s=0
ins=0
ist=0
m=0
inm=0
imt=0
p=0
inp=0
ipt=0
count=1
shout=1
prev=0
last=1
pout=1
one=0
for i in range(1,len(t)):
prev=i-1
if(t[i][1]==t[prev][1]):
if(int(t[i][0])==int(t[prev][0])):
last=last+1
elif((int(t[i][0])==(int(t[prev][0])+1)) ):
count=count+1
else:
if((int(t[i][0])==(int(t[prev][0])+2))):
one=1
else:
shout=max(count,shout)
pout=max(last,pout)
count=1
last=1
if(one==0):
print(min(3-shout,3-count,3-pout,3-last))
else:
print(min(3-shout,3-count,3-pout,3-last,1))
| PYTHON3 |
Subsets and Splits