akhauriyash/Code-Regression huggingface dataset:
n=int(input())
v=[]
f=True
c=res=0

for i in range(n):
    a=int(input())
    xy=tuple(tuple(map(int,input().split())) for _ in range(a))
    v.append(xy)
for i in range(2**n):
    f=True
    for j in range(n):
        if not (i & (1<<j)):
            continue
        for xy in v[j]:
            x=xy[0]-1
            y=xy[1]
            if y==1 and (not(i & (1<<x))):
                f=False
            if y==0 and (i & (1<<x)):
                f=False
        if not f:
            break
    else:
        c=0
        for k in range(n):
            if (i & (1<<k)):
                c+=1
        res=max(res,c)
print(res)

Measured memory_bytes: 41968
#include<stdio.h>

int main(){
  int i, C1, C2, C3, count;
  double under20;

  while(scanf("%d %d %d", &C1, &C2, &C3) != EOF){
    count = 0;
    for(i=1; i<=10; i++){
      if(i != C1 && i != C2 && i != C3){
        if((i+C1+C2) <= 20) count++;
      }
    }

    under20 = (double)count / 7.0;

    if(under20 >= 0.5)
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>

using namespace std;

int main() 
{
    int n, c = 0, cost = 0;
    scanf("%d", &n);
    
    cost = n * 800;
    
    while(n >= 15)
    {
        n-=15;
        c++;    
    }
    
    cost -= c * 200;
    
    printf("%d\n", cost);
    return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    T = input()
    for i in range(len(S) - len(T), -1, -1):
        ok = True
        for j in range(len(T)):
            if S[i+j] != "?" and S[i+j] != T[j]:
                ok = False
                break
        if ok:
            ans = (S[:i] + T + S[i+len(T):]).replace("?", "a")
            print(ans)
            return
    print("UNRESTORABLE")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include <iostream>
using namespace std;

char Division_class(int, int, int);

int main(void)
{
  int pm[10000], pe[10000], pj[10000];
  char s_class[10000];
  int n;
  
  while(1)
    {
      cin >> n;
      if(n == 0) break;
      
      for(int i = 0 ; i < n ; i++)
	{
	  cin >> pm[i] >> pe[i] >> pj[i];
	  s_class[i] = Division_class(pm[i], pe[i], pj[i]); 
	}
      for(int i = 0 ; i < n ; i++)
	{
	  cout << s_class[i] << endl;
	}
    }
  return 0;
}

char Division_class(int math, int english, int japanese)
{
  if(math == 100 || english == 100 || japanese == 100) return 'A';
  if(((math + english) / 2) >= 90) return 'A';
  if(((math + english + japanese) / 3) >= 80) return 'A';
  if(((math + english + japanese) / 3) >= 70) return 'B';
  if(((math + english + japanese) / 3) >= 50 && math >= 80 || english >= 80) return 'B';
  else return 'C';
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<vector>
#define maxn 200000
using namespace std;
 
vector<int> G[maxn];
bool vis[maxn] = {false};
 
int m, n;
 
void dfs(int v)
{
    vis[v] = true;
    for(int i = 0; i < G[v].size(); i++)
    {
        if(vis[G[v][i]] == false)
        {
            dfs(G[v][i]);
        }
    }
}
 
 
int main()
{
    scanf("%d %d",&m, &n);
    for(int i = 0; i < n; i++)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
 
    int block = 0;
    for(int i = 1; i <= m; i++)
    {
        if(vis[i] == false)
        {
            dfs(i);
            block++;
        }
    }
 
    printf("%d", block-1);
 
    return 0;
}

Measured memory_bytes: 12156
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin >> N;
  ll s=0;
  vector<ll> A(100010);
  for(int i=0;i<N;i++){
    int a; cin >> a;
    A[a]++;
    s+=a;  
  }

  int Q;
  cin >> Q;

  for(int i=0;i<Q;i++){
    ll b,c;
    cin >> b >> c;
    s-=b*A[b];
    s+=c*A[b];
    A[c]+=A[b];
    A[b]=0;
    cout << s << endl;
  }


  return 0;
}


Measured memory_bytes: 3976
def inpl(): return list(map(int, input().split()))
N, K = inpl()
R = N-K

MOD = 10**9 + 7
def cmb(n, r, mod=MOD):
    if ( r<0 or r>n ):
        return 0
    
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


size = 10000
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

def calc(i, x):
    if R - (i-1) - x < 0:
        return 0
    else:
        a = R-x-(i-1)
        b = i-1+x-1
        return cmb(K-1, i-1) * cmb(a+b, a)

for i in range(1, K+1):
    b = R - (i - 1)
    print(cmb(K-1, i-1)*cmb(b+i, b)%MOD)


Measured memory_bytes: 42992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll m;
  cin >> m;
  cout << 48-m << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')] * n
dp[0]= 0

for i in range(n):
    for j in range(k+1):
        if i + j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[-1])

Measured memory_bytes: 85888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int number, st, nd, rd, th;

    cin >> number;

    th = number/1000;
    rd = number/100 - 10*th;
    nd = number/10 - 10*rd - 100*th;
    st = number - 10*nd - 100*rd - 1000*th;

    if((st == nd) && (nd == rd)){
        cout << "Yes" << endl;
    }else if((rd == th) && (nd == rd))
    {
        /* code */
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn binary_search<F>(lb: usize, ub: usize, criterion: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut lb = lb;
    let mut ub = ub;
    while ub - lb > 1 {
        let mid = (ub + lb) / 2;
        if criterion(mid) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    lb
}

fn is_ok(x: i64, num_removed: usize, cards: &Vec<i64>) -> bool {
    let n = cards.len();
    if num_removed * 2 > n {
        return false;
    }
    if num_removed == 0 {
        return true;
    }
    let lowest_first = cards[n - num_removed];
    let lowest_second = cards[n - num_removed * 2];
    if (x - lowest_second).abs() > (x - lowest_first).abs() {
        false
    } else {
        true
    }
}

fn main() {
    let v = read_vec::<usize>();
    let (n, q) = (v[0], v[1]);
    let mut a = read_vec::<i64>();
    let mut x = vec![0; q];
    for i in 0..q {
        x[i] = read::<i64>();
    }
    if n == 2 {
        for _ in 0..q {
            println!("{:?}",a[1]);
        }
        return;
    }

    let mut ans = 0;
    ans += a.pop().unwrap();

    let mut accum_a = vec![0i64; a.len()];
    accum_a[0] = a[0];
    for i in 1..a.len() {
        accum_a[i] = accum_a[i - 1] + a[i];
    }
    let mut accum_2 = Vec::new();
    if n % 2 == 1 {
        accum_2.push(a[0])
    } else {
        accum_2.push(a[1]);
    }
    for i in 2..a.len() {
        if i % 2 != n % 2 {
            let last_elem = accum_2[accum_2.len() - 1];
            accum_2.push(a[i] + last_elem);
        }
    }

    for x_num in x {
        let mut ans = ans;
        let seq_num: usize = binary_search(0, n, |i| is_ok(x_num, i, &a));
        ans += accum_a[a.len() - 1] - accum_a[a.len() - 1 - seq_num];
        if 2 * seq_num < a.len() - 1 {
            ans += accum_2[(a.len() - 2 * seq_num - 2) / 2];
        }
        println!("{0}", ans);
    }
}


Measured memory_bytes: 9592
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N  = sc.nextInt();
		int K = sc.nextInt();
		
		boolean judge[] = new boolean[N];
		Arrays.fill(judge, true);
		
		for(int i=0;i<K;i++) {
			int d = sc.nextInt();
			for(int j=0;j<d;j++) {
				int a = sc.nextInt();
				judge[a-1] = false;
			}
			//System.out.println(d);
		}
		int count = 0;
		for(int l=0;l<N;l++) {
			if(judge[l]) {
				count ++;
			}
		}
		
		System.out.println(count);
	}
}


Measured memory_bytes: 46040
import math

a, b = map(int, input().split())

min_a = math.ceil(a/0.08)
max_a = math.floor((a+1)/0.08)
min_b = math.ceil(b/0.1)
max_b = math.floor((b+1)/0.1)

if max_a <= min_b or max_b <= min_a:
  print(-1)
else:
  print(max([min_a, min_b]))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	int count = 0;
	vector<int> height(N);
	for (int i = 0; i < N; i++) {
		cin >> height.at(i);
	}
	

	for (int i = 0; i < N; i++) {
		bool loop = true;
		for (int j = 0; j < i; j++) {
			if (height.at(j) > height.at(i)) {
				loop = false;
			}
		}
		if (loop) {
			count++;
		}
	}
	cout << count << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i=0; i<n; i++)

int d[111111];
int n, k;

int main()
{
  while(cin >> n >> k, n){
    rep(i, k) cin >> d[i];
    sort(d, d + k);

    bool ok = false;
    int p = 0;
    int res = 0;
    if(d[0] == 0) ok = true,  p += 1;
    while(p < k){
      int cnt = 1;
      while(p + 1 < k && d[p + 1] - d[p] == 1) p += 1,  cnt += 1;
      int pp = p + 1;
      if(ok && d[p + 1] - d[p] == 2){
        cnt += 2;
        p += 1;
        while(p + 1 < k && d[p + 1] - d[p] == 1) p += 1,  cnt += 1;
      }
      p = pp;
      res = max(res, cnt);
    }

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1484
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int a,b,c,x;
int main(void){
    cin>>a>>b>>c>>x;
    int ans=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                int sum=500*i+100*j+50*k;
                if(sum==x) ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){

  int N;
  cin >> N;

  double a = (double)N / 1.08;
  double b = (double)(N+1) / 1.08;

  // cout << "a: " << a << endl;
  // cout << "b: " << b << endl;

  // if (a <= floor(b))
  //   cout << floor(b) << endl;
  // else
  //   cout << ":(" << endl;

  int ans = -1;
  for(int i=floor(a);i<=ceil(b);i++){
    if (floor((double)i*1.08) == N)
      ans = i;
  }

  if (ans != -1)
    cout << ans << endl;
  else
    cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <cstdio>
using namespace std;
int t, n, x, y, a, b, v[123][123]; bool s[123][123];
int main() {
	while (~scanf("%d%d", &t, &n)) {
		if (t == 0) break;
		for (int i = 0; i <= 122; i++) {
			for (int j = 0; j <= 122; j++) {
				s[i][j] = false, v[i][j] = -1;
			}
		}
		for (int i = 0; i < n; i++) {
			scanf("%d%d", &x, &y); s[y + 61][x + 61] = true;
		}
		scanf("%d%d", &a, &b);
		queue<pair<int, int> > que; que.push(make_pair(a + 61, b + 61)); v[b + 61][a + 61] = 0;
		while (!que.empty()) {
			int x = que.front().first;
			int y = que.front().second; que.pop();
			if (v[y][x] == t) continue;
			for (int i = -1; i <= 1; i++) {
				for (int j = -1; j <= 1; j++) {
					if (i + j != 0 && v[y + i][x + j] == -1 && !s[y + i][x + j]) {
						v[y + i][x + j] = v[y][x] + 1;
						que.push(make_pair(x + j, y + i));
					}
				}
			}
		}
		int ret = 0;
		for (int i = 0; i <= 122; i++) {
			for (int j = 0; j <= 122; j++) {
				if (v[i][j] != -1) ret++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 2752
#include <iostream>
using namespace std;

int main() {
    int N;
    cin >> N;
    long long sum = 0;
    for(int i= 1;i <= N;i++){
        if(i % 3 == 0 || i % 5 == 0) {
        } else {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

int main(void){
    ll h;
    cin >> h;

    ll n = 0;
    ll one = 1;
    for(ll i = 0;i < 45;++i){
        if(h & (one << i)){
            n = i+1;
        }
    }

    ll ans = (one << n) - 1;

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
    int N;
    cin >> N;    
    vector<string>s(N); 
    vector<int>t(N); 
    string X;
    for(int i=0;i<N;i++) cin >> s[i] >> t[i];
    cin >> X;

    int last_idx;
    for(int i=0;i<N;i++){
        if(s[i]==X){
            last_idx = i;
            break;
        } 
    }

    int sum_time=0;
    for(int i=last_idx+1;i<N;i++){
        sum_time += t[i];
    }
    cout << sum_time << endl;
}

Measured memory_bytes: 256
program rgb_triplets
  implicit none
  integer :: n, i, j, a(4000) = 0, p, q
  integer(8) :: c(3) = 0_8, x = 0_8
  character(4000) :: s
  read(*,*) n
  read(*,*) s
  do i = 1, n
    if (s(i:i) == "R") then
      a(i) = 1
    else if (s(i:i) == "G") then
      a(i) = 2
    else
      a(i) = 3
    end if
    c(a(i)) = c(a(i))+1_8
  end do
  x = c(1)*c(2)*c(3)
  do j = 1, n
    if (2*j+1 > n) exit
    do i = 1, n
      p = i+j
      q = p+j
      if (q > n) exit
      if (a(i) == a(p) .or. a(p) == a(q) .or. a(q) == a(i)) cycle
      x = x-1_8
    end do
  end do
  write(*,'(i0)') x
end program rgb_triplets

Measured memory_bytes: 2932
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

int main(void){
    int n, i, j;
    int M[MAX][MAX];
    int d[MAX];
    int key[MAX];
    int p[MAX];
    int m,u,k,c,v;
    /* your code*/

  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

  /*your code */
    
    
    for(i=0;i<n;i++){
        p[i]=-1;
        key[i]=0;
        d[i]=INFTY;
    }
    
    d[0]=0;
    
    
    while(u!=-1){
        u=-1;
        m=INFTY;
        
        for(i=0;i<n;i++){
            if(m>d[i] && (key[i]==0)){
                u=i;
                m=d[i];
                
            }
        }
        
        //if(u==-1)break;
        key[u]=1;
        
        for(i=0;i<n;i++) {
            if(d[i] >= M[u][i]+d[u] && (key[i] == 0)) {
                p[i] = u;
                d[i] = M[u][i]+d[u];
            }
        }
        
        
        
        
    }

  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  }

  return 0;
}

Measured memory_bytes: 804
#include <stdio.h>

int abs(int a){return (a<0)?-a:a;}
int main(){
        int x1,y1,x2,y2;
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        int a = abs(y2-y1);
        int b = abs(x2-x1);

        if((x2-x1)>=0 &&(y2-y1)>=0){printf("%d %d %d %d\n", x2-a,y2+b,x1-a,y1+b);}
        else if((x2-x1)<0 &&(y2-y1)>=0){ printf("%d %d %d %d\n", x2-a,y2-b,x1-a,y1-b);}
        else if((x2-x1)>=0 &&(y2-y1)<0){ printf("%d %d %d %d\n", x2+a,y2+b,x1+a,y1+b);}
        else if((x2-x1)<0 &&(y2-y1)<0){  printf("%d %d %d %d\n", x2+a,y2-b,x1+a,y1-b);}
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
from bisect import bisect_left
N, Q = map(int, input().split())
W = [tuple(map(int, input().split())) for _ in range(N)]
W.sort(key=lambda x:x[2])
D = [int(input()) for _ in range(Q)]
ans = [-1]*Q
skip = [-1]*Q
for s, t, x in W:
    l = bisect_left(D, s-x)
    r = bisect_left(D, t-x)
    while l < r:
        if skip[l] == -1:
            ans[l] = x
            skip[l] = r
            l += 1
        else:
            l = skip[l]
print(*ans, sep='\n')

Measured memory_bytes: 57056
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    ll n;
    cin >> n;
    vector<ll> vec(n),sum(n);
    rep(i,n) cin >> vec[i];

    sum[0] = vec[0];
    reps(i,1,n){
        sum[i] = sum[i-1] + vec[i];
    }

    ll ans = 2e9+10;
    rep(i,n-1){
        ll x = sum[n-1]-sum[i];
        ll y = sum[i];
        ans = min(ans,abs(x-y));
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6372
H,W=map(int,input().split())

l=[]
for i in range(H):
  x=input()
  # 白いマスのみからなる場合は追加しない
  if x!='.'*W:
    l.append(x)

rm=[]
for i in range(W):
  # フラグ
  f=True
  for j in range(len(l)):
    if l[j][i]=='#':
      f=False

  # 取り除く列の添字を保存しておく
  if f:
    rm.append(i)

a=[]
for x in l:
  for i in rm[::-1]:
    x=x[:i]+x[i+1:]
  a.append(''.join(x))

# 出力
for i in range(len(a)):
  print(''.join(a[i]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i <= n; i++)
using namespace std;

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
  
    int counter = 0;
  	rep(i, a)
    {
      rep(j, b)
      {
        rep(k, c)
        {
          int total = 500 * i + 100 * j + 50 * k;
          if (x == total)
          {
            counter++;
          }
        }
      }
    }
  
    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
        int k, n; cin >> k >> n;
        vector<int> v;
        for (int x = 0; x < n; ++x){
            int q; cin >> q;
            v.push_back(q);
        }
        int mx_seg = v.front() + k - v.back();
        for (int x = 0; x < n-1; ++x){
            mx_seg = max(mx_seg, v[x+1] - v[x]);
        }
        cout << k - mx_seg << endl;
    return 0;
}


Measured memory_bytes: 4256
#include <iostream>

using namespace std;

int
main()
{
    uint64_t n,a,b,c,d;
    cin >> n >> a >> b;

    c = (n / (a + b)) * a;
    d = n % (a + b);

    if(d > a)
        cout << c + a << endl;
    else
        cout << c + d << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
#[derive(Debug)]
struct UnionFind {
    //ノード情報のベクトル。
    //各ノードは親のノードを指す。
    //根なら木のサイズを負にして入れる。
    d: Vec<isize>,
}

impl UnionFind {
    //コンストラクタ dをn個の要素でそれぞれサイズ-1で初期化
    fn new(n: usize) -> UnionFind {
        UnionFind { d: vec![-1; n] }
    }

    //ノード番号を引数にとり
    //属する木のグループ番号を返す
    //グループ番号は属する木の根のノード番号
    fn find(&mut self, x: isize) -> isize {
        let u_x = x as usize;
        //負値であれば、根である
        if self.d[u_x] < 0 {
            x
        } else {
            //再帰的に根を探索し、各ノードの根の番号を張り替える（経路縮約）
            self.d[u_x] = self.find(self.d[u_x]);
            self.d[u_x]
        }
    }

    //木の併合
    //木のサイズが小さい方を大きい方にくっつける
    //長いものにまかれにいく
    //木が深くならなくなる
    fn unite(&mut self, x: isize, y: isize) -> bool {
        //所属するグループの検索
        let mut x = self.find(x);
        let mut y = self.find(y);
        let mut u_x = x as usize;
        let mut u_y = y as usize;
        //すでに所属グループが同じ
        if x == y {
            return false;
        }
        //xを大きいサイズのグループに設定する
        if self.d[u_x] > self.d[u_y] {
            std::mem::swap(&mut x, &mut y);
            std::mem::swap(&mut u_x, &mut u_y);
        }
        //大きいグループxに小さいグループyのサイズを加算する
        self.d[u_x] += self.d[u_y];
        //グループyの親をxにするくっつける
        self.d[u_y] = x;
        return true;
    }

    //ノードxとノードyが同じグループか判定する
    fn same(&mut self, x: isize, y: isize) -> bool {
        self.find(x) == self.find(y)
    }
    //所属するグループのサイズを返す
    fn size(&mut self, x: isize) -> isize {
        let root = self.find(x);
        -self.d[root as usize]
    }
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut tree = UnionFind::new(n);

    for _ in 0..m {
        let a:isize = read();
        let b:isize = read();
        tree.unite(a-1 , b-1);
    }
    let mut set = HashSet::new();
    for i in 0..n{
        set.insert(tree.find(i as isize));
    }
    println!("{}",set.len()-1);
}


Measured memory_bytes: 4464
def main():
    N, M = map(int, input().split())
    wish = []
    for i in range(M):
        wish.append(tuple(map(int, input().split())))
    w = sorted(wish, key=lambda x:x[1])
    
    cnt = 0
    ans = 0
    for i in range(M):
        if(w[i][0] >= cnt):
            ans += 1
            cnt = w[i][1]
    print(ans)
main()

Measured memory_bytes: 19012
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> g;
int n,m;
vector<int> anss;

void bfs(){
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int now = q.front();
    q.pop();
    for(int next:g[now]){
      if(anss[next]!=-1) continue;
      q.push(next);
      anss[next] = now;
    }
  }
}

int main(){
  cin >> n >> m;
  g.assign(n,vector<int>());
  anss.assign(n,-1);
  anss[0] = 0;
  for (int i = 0; i < m; i++)
  {
    int a,b;
    cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  bfs();
  puts("Yes");
  for (int i = 1; i < n; i++)
  {
    cout << anss[i]+1 << endl;
  }
}

Measured memory_bytes: 10144
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"10 2 3
abccabaabb"# => r#"Yes
Yes
No
No
Yes
Yes
Yes
No
No
No"#,

r#"12 5 2
cabbabaacaba"# => r#"No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
No"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize,
        a: usize,
        b: usize,
        s: chars,
    }
    let mut ans = "".to_string();
    let mut cnt = 0;
    let mut b_cnt = 0;

    for i in 0..n {
        if (s[i] == 'a' && cnt < a + b) ||
           (s[i] == 'b' && cnt < a + b && b_cnt < b) {
            ans.push_str("Yes");
            cnt += 1;
            if s[i] == 'b' {
                b_cnt += 1;
            }
        } else {
            ans.push_str("No");
        }
        if i != n - 1 {
            ans.push_str("\n");
        }
    }
    ans.to_string()
}

Measured memory_bytes: 6780
n = int(input())
tot = sum(range(1, n + 1))
n_3 = n // 3
n_5 = n // 5
n_15 = n // 15
print(tot - sum(range(3, int(3 * n_3) + 1, 3)) -
      sum(range(5, int(5 * n_5) + 1, 5)) +
      sum(range(15, int(15 * n_15) + 1, 15)))


Measured memory_bytes: 9184
#include <bits/stdc++.h>

const static double	de_PI	= 3.14159265358979323846;
const static int	de_MOD	= 1000000007;
const static int	de_MAX	= 999999999;
const static int	de_MIN = -999999999;

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());

	int n = 0, ans = 0;
	std::vector<int> A;

	while (std::cin >> n) {
		A.push_back(n);
	}

	for (unsigned int x = 0; x < A.size(); x++) {
		ans = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						if (i + j + k + l == A[x]) {
							ans++;
						}
					}
				}
			}
		}
		std::cout << ans << std::endl;
	}

}

Measured memory_bytes: 3120
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<iomanip>
#include<string>
#include<iomanip>
using namespace std;
int main() {
	int l;
	cin >> l;
	cout <<fixed<<setprecision(10)<< (double)pow((double)(l /3.0),3)<< endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

long long int gcd(long long int a, long long int b) {
	if (a < b)swap(a, b);
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> K;
	long long int ans = 0;
	cin >> M;
	ans = abs(M-K);
	for (int i = 1; i < N; i++) {
		cin >> M;
		ans = gcd(ans, abs(M - K));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
int main()
{
	string S;
	cin >> S;
	int A = stoi(S.substr(0, 2));
	int B = stoi(S.substr(2, 2));
	if(A > 0 && A <= 12)
	{
		if(B > 0 && B <= 12)
		{
			cout << "AMBIGUOUS" << endl;
		}
		else
		{
			cout << "MMYY" << endl;
		}
	}
	else if(B > 0 && B <= 12)
	{
			cout << "YYMM" << endl;
	}
	else
	{
		cout << "NA" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> P;

int N, M, Q;
ll ans;
vector<int> a(50), b(50), c(50), d(50);

void f(vector<int> v) {
  if (v.size() == N) {
    // calc
    ll score = 0;
    FOR(i,0,Q) {
      if(v[b[i]] - v[a[i]] == c[i]) {
        score += d[i];
      }
    }
    ans = max(ans, score);
    return;
  }
  FOR(i, v[v.size()-1], M+1) {
    vector<int> vv = v;
    vv.push_back(i);
    f(vv);
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> Q;
  FOR(i,0,Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;b[i]--;
  }
  ans = 0;
  FOR(i,1,M+1) {
    vector<int> v;
    v.push_back(i);
    f(v);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;

bool Check(int ans, const vector<int> &d) {
    while (ans) {
        int n = ans % 10;
        for (auto dd : d)
            if (dd == n)
                return true;
        ans /= 10;
    }

    return false;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;

    cin >> n >> k;
    vector<int> d(k);
    for (int i = 0; i < k; ++i)
        cin >> d[i];

    int ans = n;
    while (Check(ans, d))
        ++ans;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <sstream>

using namespace std;

const int N_MAX = 1000000;

bool is_reachable(int t, int x, int y){
  if( x + y > t) return false;
  else if(x + y == t) return true;
  else{
    // x + y and t are odd, reachable
    if((x+y-t)%2==0) return true;
    else return false;
    
    // x + y and t are (odd, even) or (even, odd) not reachable
  }
  return true;
}

int main(){
  int N;
  int cur_x = 0; int cur_y = 0; int cur_t = 0;
  bool ans=true;
  cin >> N;

  for(int i=0; i<N; i++){
    int t, x, y;
    cin >> t >> x >> y;
    if(!is_reachable(t-cur_t, x-cur_x, y-cur_y)){
      ans = false;
    }
    cur_x = x; cur_y = y; cur_t = t;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<functional>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<climits>
using namespace std;

typedef long long ll;

int main(){
	ll N;
	cin >> N;
	ll latte = 1, ans = 0;
	while(latte <= N)
	{
		latte *= 2;
		ans++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>

using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  long long count[5] = {0, 0, 0, 0, 0};
  for(int i = 0 ; i < n ; i++){
    cin >> s;
    switch (s[0]) {
      case 'M':
        count[0]++;
        break;
      case 'A':
        count[1]++;
        break;
      case 'R':
        count[2]++;
        break;
      case 'C':
        count[3]++;
        break;
      case 'H':
        count[4]++;
        break;
    }
  }
  long long ans = 0;
  for(int i = 0 ; i < 3; i++){
    for(int j = i + 1; j < 4; j++){
      for(int k = j + 1; k < 5 ; k++){
        ans += count[i] * count[j] * count[k];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    
    int x,prev,ppos,tmpn,count;
    bool found, solvable;
    
    found = false;
    solvable = true;
    count=0;
    tmpn = n;
    
    while(tmpn--){
        
        cin>>x;
        
        if(x!=n-tmpn)
            count++;
        
        if(!found&&count<3){
            if(x!=n-tmpn){
                found = true;
                ppos = n-tmpn;
                //cout<<"problem position = "<<ppos<<endl;
                solvable = false;
            }
        }
        
        else if(count<3){
            if(x!=n-tmpn){
                //cout<<"second problem position = "<<n-tmpn<<endl;
                
                if(x == ppos)
                    solvable = true;
            }
        }
        
        if(count>3){
            //cout<<"count = "<<count<<endl;
            solvable = false;
        }
    
    }
    
    if(solvable)
        cout<<"YES";
    else
        cout<<"NO";

    return 0;
}


Measured memory_bytes: 256
n, k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
h = Hash.new(0)
a.each do |x|
  h[x] += 1
end
nk = h.size
v = h.values.sort
if k - nk < 0
  puts v.shift(nk - k).inject(:+)
else
  puts 0
end

Measured memory_bytes: 34160
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int k = in.nextInt();
        in.nextLine();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        for (int i = 0; i < k; i++) {
            final int[] next = new int[n];
            for (int j = 0; j < n; j++) {
                final int left = Math.max(0, j - arr[j]);
                final int right = Math.min(n - 1, j + arr[j]);
                next[left]++;
                if (right + 1 < n) {
                    next[right + 1]--;
                }
            }
            for (int j = 1; j < n; j++) {
                next[j] += next[j - 1];
            }
            if (Arrays.equals(next, arr)) {
                break;
            }
            arr = next;
        }
        for (int num : arr) {
            System.out.print(num + " ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 63456
import random
import time
import copy
import math
start=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
for i in range(d):
  s.append(list(map(int,input().split())))
last=[0]*26
score=0
solution=[]
for day in range(1,d+1):
  co=[]
  dla=[]
  down=0
  for (i,j) in zip(last,c):
    down+=(day-i)*j
  for (i,j) in zip(last,c):
    dla.append(down-(j*(day-i)))
  for con in range(26):
    co.append(s[day-1][con]-dla[con])
  choice=co.index(max(co))
  score+=co[choice]
  last[choice]=day
  #print(choice+1)
  #print(score)
  solution.append(choice)
#print(score)
stemp=3000
etemp=100
def tem():
  return stemp-((stemp-etemp)*(time.time()-start)/1.9)
while time.time()-start<1.95:
  
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(1)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[day-i][j]
  try:
    prob = math.exp((sc-score)/tem())
  except:
    prob=0
  #print("{} {}".format(sc,prob))
  if prob>random.random():
    solution=copy.deepcopy(sol)
    score=sc
    #print(score)
for i in solution:
  print(i+1)
#print(sco)


Measured memory_bytes: 10444
#include <bits/stdc++.h>
#include <set> 
#include <iterator> 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)


int main()
{
   
    fastio();
    int n;
    cin>>n;
    double p[n];
    for(int i=0;i<n;i++)
        cin>>p[i];
    double dp[n+1][n+1];
    dp[0][0]=0;
    dp[1][0]=1-p[0];
    dp[1][1]=p[0];
    for(int i=2;i<n+1;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0)
                dp[i][j]=(1-p[i-1])*dp[i-1][j];
            else
                dp[i][j]= dp[i-1][j-1]*p[i-1] + dp[i-1][j]*(1-p[i-1]);
        }
        
    }
    double sum=0;
    for(int i=n/2+1;i<=n;i++)
        sum+=dp[n][i];
   
     cout << fixed << setprecision(12) <<sum<<endl;
}


Measured memory_bytes: 70400
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
	string s;
	cin>>s;
	if(s=="SUN") printf("7\n");
	else if(s=="MON") printf("6\n");
	else if(s=="TUE") printf("5\n");
	else if(s=="WED") printf("4\n");
	else if(s=="THU") printf("3\n");
	else if(s=="FRI") printf("2\n");
	else if(s=="SAT") printf("1\n");
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut cnt = vec![0; n * 2 + 10];
    let mut ans: i64 = 0;
    for i in 0..n {
        let j = n - 1 - i;
        let val = a[j] + j as i64;
        if val < cnt.len() as i64 {
            ans += cnt[val as usize];
        }
        let val = (j as i64) - a[j];
        if val < cnt.len() as i64 && val >= 0 {
            cnt[val as usize] += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6760
<?php
$n=trim(fgets(STDIN));
$w=explode(" ",trim(fgets(STDIN)));
$suml=array_sum($w);
$sumr=0;
$i=0;
while($i<$n){
  $suml-=$w[$i];
  $sumr+=$w[$i];
  $ans[]=abs($suml-$sumr);
  ++$i;
}
echo min($ans);

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;
    int ans = A - 2 * B;
    if (ans < 0) ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
v1 = abs((a // 2) * b * c - (a - (a // 2)) * b * c)
v2 = abs((b // 2) * a * c - (b - (b // 2)) * a * c)
v3 = abs((c // 2) * b * a - (c - (c // 2)) * b * a)
ans = min(v1, v2, v3)
print(ans)

Measured memory_bytes: 9112
#include <stdio.h>
     
             
            int main()
            {
             int a,b,c=0,i;
             scanf("%d %d", &a ,&b);
             for(i=0;i<2;i++){
               if(a>=b){
               	c=c+a;
               	a=a-1;}
               else{
               	c=c+b;
               	b=b-1;}
              
             }
             
             printf("%d",c);
             return 0;
            }

Measured memory_bytes: 128
#include<stdio.h>
main(){
	int x,a,b,c,d,count;
	while(scanf("%d",&x)!=EOF){
		count=0;
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if((a+b+c+d)==x)count++;
					}
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 0
from collections import deque
n,m = map(int,input().split())
prefs = [{} for _ in range(n)]
cities = deque()
for i in range(m):
    p, y = map(int,input().split())
    prefs[p-1][y] = -1
    cities.append((p,y))

for p in prefs:
    years = list(p.keys())
    years.sort()
    for y in range(len(years)):
        p[years[y]] = y+1


for _ in range(m):
    p, y = cities.popleft()
    cid = prefs[p-1][y] + p * 1000000
    print("{:0=12}".format(cid))


Measured memory_bytes: 47140
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int A, B;
	cin >> A >> B;
	if (A < 6)
	{
		cout << "0" << endl;
	}
	else if (A > 12)
	{
		cout << B << endl;
	}
	else
	{
		cout << B / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class B
{
	static void Main()
	{
		Console.ReadLine();
		Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Min(Count));
	}

	static int Count(int x)
	{
		var r = 0;
		while (x % 2 == 0)
		{
			x /= 2;
			r++;
		}
		return r;
	}
}


Measured memory_bytes: 11348
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  string s;cin>>s;
  sort(s.begin(),s.end());
  if(s[0] == s[1] && s[2] == s[3] && s[2] != s[1])cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
def solve2():
    n = int(input())
    s = list(input())

    r = s.count('R')
    g = s.count('G')
    b = s.count('B')

    cnt = 0
    for i in range(n):
        for j in range(i+1,n):
            k = j*2-i
            if k >= n:
                break
            elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                cnt +=1
    return r*g*b - cnt

print(solve2())

Measured memory_bytes: 9232
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

string tolower(string str) {
	int len = str.length();
	string res = "";
	for(int i = 0; i < len; i++) if(isalpha(str[i])) res += tolower(str[i]); else res += str[i];
	return res;
}

int main() {
	string word, text;
	cin >> word;
	word = tolower(word);
	int cnt = 0;
	while(cin >> text && text != "END_OF_TEXT") {
		text = tolower(text);
		cnt += text == word;
	}
	cout << cnt << '\n';
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

int n, m;
vi a;
vi b;

void dfs(int num, int p, vector<bool> &v) {
  if(v[p]) return;
  v[p] =true;

  rep(i, 0, m) {
    if(i == num) continue;
    
    if(a[i] == p) dfs(num, b[i], v);
    else if(b[i] == p) dfs(num, a[i], v);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  a.resize(m);
  b.resize(m);
  rep(i, 0, m) cin >> a[i] >> b[i];

  int ans = 0;
  rep(i, 0, m) {
    vector<bool> visited(n + 1, false);
    visited[0] = true;
    dfs(i, 1, visited);
    if(count(all(visited), false)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
A, B = [], []
for _ in range(n):
    A.append(list(map(int, input().split())))
for _ in range(m):
    B.append(int(input()))
for i in A:
    elm = 0
    for j in range(m):
        elm += i[j] * B[j]
    print(elm)


Measured memory_bytes: 6012
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define re register
#define ls rt<<1
#define rs rt<<1|1
#define mid ((l+r)>>1)
#define MAXN 200001
#define ll long long
using namespace std;
int a[1000001];
int n,m,cnt;
int main()
{
	cin>>n;
	for(re int i=1;i<=n;i++)
		cin>>a[i];
	for(re int i=1;i<=n;i++){
		if(a[i]==a[i+1]){
			cnt++;i++;
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <map>
const int MAXN = 2e5+5;
const int MAXQ = 2e5+5;
int pos[MAXQ], R[MAXN];
int S[MAXN], T[MAXN], X[MAXN];  // Roadblocks
std::map<int,int> D;
int N, Q;

// y = x + D[i]
// lower_bound, upper_bound (S-X[i]) (T-X[i])

int main() {
    scanf(" %d%d", &N, &Q);
    for (int i = 0; i < N; ++i) {
        scanf(" %d%d%d", &S[i], &T[i], &X[i]);
        R[i] = i;
    }
    std::sort(R, R+N, [](int l, int r) {
        return X[l] != X[r] ? X[l] < X[r] : S[l] < S[r];
    });
    for (int i = 0; i < Q; ++i) {
        int d;
        scanf("%d", &d);
        D[d] = i;
        pos[i] = -1;
    }
    for (int i = 0; i < N; ++i) {
        auto lo = D.lower_bound(S[R[i]] - X[R[i]]);
        auto hi = D.lower_bound(T[R[i]] - X[R[i]]);
/*
        printf("search: %d, %d\n",
               S[R[i]] - X[R[i]],
               T[R[i]] - X[R[i]]);
*/
        for (auto jtr = lo; jtr != hi;) {
//            printf("   got: %d at %d\n", jtr->first, jtr->second);
            pos[jtr->second] = X[R[i]];
            jtr = D.erase(jtr);
        }
    }
//    puts("===");
    for (int i = 0; i < Q; ++i) {
        printf("%d\n", pos[i]);
    }
    return 0;
}


Measured memory_bytes: 15104
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
static const int N = 50;

int W, H;
bool visited[N][N];
int map[N][N];

const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

void dfs(int h, int w) {
    visited[h][w] = true;

    for (int i = 0; i < 8; ++i) {
        int nh = h + dx[i];
        int nw = w + dy[i];

        if (nh < 0 || nh > H-1 || nw < 0 || nw >W-1) continue;
        if (visited[nh][nw]) continue;
        if (map[nh][nw] == 0) continue;

        dfs(nh, nw);
    }
}

int main() {
    while (true) {
        cin >> W >> H;
        if (W == 0 && H == 0) break;

        for (int h = 0; h < H; ++h) {
            for (int w = 0; w < W; ++w) {
                cin >> map[h][w];
            }
        }

        memset(visited, 0, sizeof(visited));

        int count = 0;
        for (int h = 0; h < H; ++h) {
            for (int w = 0; w < W; ++w) {
                if (visited[h][w] || map[h][w] == 0) continue;
                dfs(h, w);
                ++count;
            }
        }

        cout << count << endl;
    }


    return 0;
}


Measured memory_bytes: 3128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long X,m;
    m=100;
    cin>>X;
    int year=0;
    while(m<X){
        m=floor(m*1.01);
        year++;
    }
    cout<<year<<endl;
}

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  for(int i=0;i<110;i++){
    c-=b;
    if(c<=0){
      cout << "Yes" << endl;
      break;
    }
    a-=d;
    if(a<=0){
      cout << "No" << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        Train[] trains = new Train[N-1];
        for (int i = 0; i < N - 1; i++) {
            int C = scan.nextInt();
            int S = scan.nextInt();
            int F = scan.nextInt();
            Train t = new Train();
            t.C = C;
            t.S = S;
            t.F = F;
            trains[i] = t;
        }
        for (int i = 0; i < N-1; i++) {
            Train t = trains[i];
            long elapsed_time = t.S + t.C;
            for (int j = i + 1; j < N-1; j++) {
                Train n = trains[j];
                if (elapsed_time < n.S) {
                    elapsed_time = n.S;
                }
                if (elapsed_time % n.F == 0) {
                    elapsed_time += n.C;
                } else {
                    elapsed_time = elapsed_time + (n.F - (elapsed_time % n.F)) + n.C;
                }
            }
            System.out.println(elapsed_time);
        }
        System.out.println(0);
    }
    class Train {
        int C;
        int S;
        int F;
    }
}


Measured memory_bytes: 26692