akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;

  cout << s[0];
  cout << s.size()-2;
  cout << s[s.size()-1];
  cout << endl;
}


Measured memory_bytes: 256
def solve(a, b, c):
    if any(i % 2 == 1 for i in [a, b, c]):
        return 0
    if a == b == c:
        return -1
    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
    return solve(a, b, c) + 1

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

print(solve(a, b, c))

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

int main(){
	int n,k;

	cin >> n >> k;

	int out = 1;
	for(int i = 0; i < n; ++i){
		if(out > k){
			out += k;
		} else{
			out *= 2;
		}
	}
	cout << out << endl;

	return 0;
}

Measured memory_bytes: 256
factor::Int->[Int]->Int
factor n xs = let idxs = zip [1..] xs in red_sum [ ((i-1)-(n-i))*v |(i,v)<-idxs]
            where red_sum [] = 0
                  red_sum (x:xs) = mod (x+(red_sum xs)) 1000000007

solver::Int -> Int ->[Int]->[Int]->Int
solver n m xs ys = mod ((factor n xs) * (factor m ys)) 1000000007

main::IO()
main=do
  nmc<-getLine
  let n:m:[]=map read (words nmc)
  x<-getLine
  let xs=(map read (words x))
  y<-getLine
  let ys=(map read (words y))
  print (solver n m  xs ys)


Measured memory_bytes: 113532
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A = np.array(A)

    f = 0
    cnt = 0
    for _ in range(10**9):
        f = np.max(np.mod(A, 2))
        if f == 1:
            break
        A[:] = A[:]/2
        cnt += 1

    print(cnt)


main()


Measured memory_bytes: 12504
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<cmath>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;







int main(){
	int N; cin >> N;
	string s; cin >> s;
	vector<int> which(N);
	vector<int> a{1,-1,1,-1};
	vector<int> b{1,1,-1,-1};
	bool isok = false;
	rep(i,4){
		which[0] = a[i];
		which[1] = b[i];
		bool ok = true;
		repr(j,1,N-1){
			if(s[j] == 'o' && which[j] == 1){
				which[j+1] = which[j-1];
			}
			if(s[j] == 'o' && which[j] == -1){
				which[j+1] = -which[j-1];
			}
			if(s[j] == 'x' && which[j] == 1){
				which[j+1] = -which[j-1];
			}
			if(s[j] == 'x' && which[j] == -1){
				which[j+1] = which[j-1];
			}
		}
		if(which[0] == 1 && s[0] == 'o'){
			if(which[1] != which[N-1]) ok = false;
		}
		if(which[0] == 1 && s[0] == 'x'){
			if(which[1] != -which[N-1]) ok = false;
		}
		if(which[0] == -1 && s[0] == 'o'){
			if(which[1] != -which[N-1]) ok = false;
		}
		if(which[0] == -1 && s[0] == 'x'){
			if(which[1] != which[N-1]) ok = false;
		}
		if(which[N-1] == 1 && s[N-1] == 'o'){
			if(which[N-2] != which[0]) ok = false;
		}
		if(which[N-1] == 1 && s[N-1] == 'x'){
			if(which[N-2] != -which[0]) ok = false;
		}
		if(which[N-1] == -1 && s[N-1] == 'o'){
			if(which[N-2] != -which[0]) ok = false;
		}
		if(which[N-1] == -1 && s[N-1] == 'x'){
			if(which[N-2] != which[0]) ok = false;
		}

		if(ok){
			isok = true;
			break;
		}

	}
	if(!isok) cout << -1 << endl;
	else{
		vector<char> ans(N);
		rep(i,N){
			if(which[i] == 1) ans[i] = 'S';
			else ans[i] = 'W';
			cout << ans[i];
		}
		cout << endl;
	}
	
}


Measured memory_bytes: 1024
#include <stdio.h> 
int main(void) {
  int t, n, s, f, time, i;
  scanf("%d",&t);
  while(t) {
    time=0;
    scanf("%d",&n);
    for(i=0;i<n;i++) {
      scanf("%d%d",&s,&f);
      time+= f-s;
    }
    if(time>=t){
      puts("OK");
    }else{
      printf("%d\n",t-time);
    }
    scanf("%d",&t);
  }
  return(0);
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int n;
    cin >> n;

    vector<int> a(n);
    for (auto& x : a) cin >> x;

    sort(a.begin(), a.end());

    int k, t;
    k = t = 0;
    for (int i = 0; i < n - 1; i++) {
        t += a[i];
        if (a[i + 1] > t * 2) k = i + 1;
    }
    cout << n - k << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{
	int box[3];
	for (int i = 0; i < 3; i++) {
		cin >> box[i];
		if (box[i] < 1 || box[i]>10000) {
			cout << "Error! Input the number from 1 to 10000." << endl;
			i--;
		}
		if (i==2 && box[1] < box[0]) {
			cout << "Error! You need that the first inputed number is smaller than the second.";
			i = 0;
		}
	}
	/*
	for (int i = 0; i < 3; i++) {
		cout << box[i]<<endl;
	}
	*/
	int divisor_counter=0;
	for (int i = box[0]; i <= box[1]; i++) {
		if (box[2] % i == 0) {
			divisor_counter++;
		}
	}
	cout << divisor_counter << endl;

	return 0;
}


Measured memory_bytes: 3116
N,K=map(int,input().split())
ans=0
a=1/N
b=1/2
A=[0]*(N)
for i in range(N):
  while (i+1)*2**A[i]<K:
    A[i]+=1
for i in range(N):
  ans+=a*b**A[i]
print(ans)

Measured memory_bytes: 3828
//package beg_164;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		String[] a = s.nextLine().split(" ");
		int b = Integer.parseInt(a[0]);
		int c = Integer.parseInt(a[1]);
		
		if (c>=b) {
			System.out.println("unsafe");
		}
		else {
			System.out.println("safe");
		}
	}

}


Measured memory_bytes: 35804
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a));
const int N = 1e9;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
typedef long long LL;
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=1e5+5;
using namespace std;

int second[maxn];
bool cmp(int a, int b)
{
    return a>b;
}

int gcd(int a, int b)
{
    return (b==0)?a:gcd(b,a%b);
}

#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    //ios::sync_with_stdio(false);
    int N, H, mxn, b, a, ans, temp;
    mxn = temp = 0;
    cin>>N>>H;
    for(int i = 0;i < N;i++){
        cin>>a>>second[i];
        mxn = max(mxn, a);
    }
    sort(second, second+N, cmp);
    for(int i = 0;i < N;i++){
        if(second[i]>mxn){
            H-=second[i];
            temp++;
            if(H<=0) break;
        }
    }
    if(H<=0) ans = temp;
    else{
    ans = temp+H/mxn;
    if(H/mxn*mxn<H) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [0] + list(map(int, sys.stdin.readline().split()))

divs = [[] for _ in range(N + 1)]
for i in range(1, N + 1):
    n = i
    while n + i <= N:
        n += i
        divs[n].append(i)
ans = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
    ans[i] += A[i]
    ans[i] %= 2
    if ans[i]:
        for d in divs[i]:
            ans[d] += 1
            ans[d] %= 2

nums = []
for i, a in enumerate(ans[1:]):
    if a:
        nums.append(i + 1)
print(len(nums))
print(*nums)


Measured memory_bytes: 124236
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define print(n) cout << n << endl
using namespace std;
using ll = long long;
 
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int N;
    cin >> N;

    double sum = 0.0;
    rep(i,N) {
        double x; cin >> x;
        string u; cin >> u;

        if (u == "JPY") sum += x;
        else sum += x * 380000.0;
    }

    cout << setprecision(20) << sum << endl;

    return 0;
}


Measured memory_bytes: 256
def rle(string):
    _rle_str = string[0]
    _rle_cnt = 1
    _ans_l = []
    for _i in range(1, len(string)):
        if _rle_str == string[_i]:
            _rle_cnt += 1
        else:
            _ans_l.append([_rle_str, _rle_cnt])
            _rle_str = string[_i]
            _rle_cnt = 1
    _ans_l.append([_rle_str, _rle_cnt])
    return _ans_l

n,k=map(int, input().split())
s=input()

rs=rle(s)

if rs[0][0]=="0":
    cnt=1
    wa=rs[0][1]
    r=1
    l=0
else:
    cnt=0
    wa=0
    r=0
    l=0

ans=-1

if len(rs)==1:
    print(rs[0][1])
    exit()

while r<len(rs):
    if cnt==k and rs[r][0]=="0":
        if rs[l][0]=="0":
            wa-=rs[l][1]
            cnt-=1
        else:
            wa-=rs[l][1]
        l+=1

    elif cnt<=k:
        if rs[r][0]=="0":
            cnt+=1
            wa+=rs[r][1]
        else:
            wa+=rs[r][1]
        r+=1
        ans=max(ans, wa)

    else:
        if rs[l][0]=="0":
            wa-=rs[l][1]
            cnt-=1
        else:
            wa-=rs[l][1]
        l+=1

print(ans)


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

int imos[20][100010];
int dp[1<<21];
int main(){
    int n, m;
    cin>>n>>m;
    for(int i=0;i<1<<m;i++)dp[i]=n;
    dp[0]=0;
    int sz[20]={};
    for(int i=1;i<=n;i++){
        int tmp;
        cin>>tmp;
        tmp--;
        sz[tmp]++;
        imos[tmp][i] = 1;
        for(int j=0;j<m;j++)imos[j][i] += imos[j][i-1];
    }
    for(int i=0;i<(1<<m);i++){
        int pos=0;
        for(int j=0, b=1;j<m;j++, b<<=1)if(i & b)pos+=sz[j];
        for(int j=0, b=1;j<m;j++, b<<=1){
            if(i&b)continue;
            int next = i + b;
            dp[next] = min(dp[next], dp[i] + sz[j] - ( imos[j][pos+sz[j]] - imos[j][pos] ) );
        }
    }
    cout<<dp[(1<<m)-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 15008
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;
LL mod = 1e9 + 7;

LL pow_L(LL x, LL n) {
	LL x_n = x, res = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			res = (res * x_n) % mod;

		}
		n = n >> 1;
		x_n = x_n * x_n % mod;
	}


	return res;
}

int main() {
	
	LL N;
	cin >> N;
	LL t = pow_L(10, N);
	LL ans = pow_L(10, N) - pow_L(9, N) * 2 + pow_L(8, N);
	while(ans < 0) {
		ans += mod;
	}
	ans = ans % mod;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h> 
int main(){
	int x;
	scanf("%d",&x);
	x=x%10;
	if(x==3){
		printf("bon\n");		
	} else if(x==0 || x==1 ||x==6||x==8){
		printf("pon\n");
	} else{
		printf("hon\n"); 
	} 
	return 0;
}

Measured memory_bytes: 1616
import Control.Monad
import Data.List
import Data.Ord
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main = do
 [_,k] <- map read . words <$> getLine
 ab <- map (map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents
 print (bigArray k (sortBy (comparing head) ab))

bigArray k ([a,b]:ab)
 | k <= b = a
 | otherwise = bigArray (k-b) ab

Measured memory_bytes: 57724
void main()
{
	int n,i;
	int ans[64]={0};
	
	ans[0]=ans[1]=1;
	ans[2]=2;
	
	for(i=3;i<31;i++)
		ans[i]=ans[i-1]+ans[i-2]+ans[i-3];
	
	for(;;)
	{
		scanf("%d",&n);
		if(n==0)
			break;
		printf("%d\n",ans[n]/3650+1);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S, T, ans;
  cin >> N >> S >> T;
  for(int i = 0; i < N; i++){
    ans += S.at(i);
    ans += T.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
n = int(input())
d = list(map(int, input().split()))
l = []
count = 0
for i in range(0, len(d)):
  for j in range(0, len(d)):
    if i != j or d[i] != d[j]:
      a = sorted([d[i], d[j]], reverse=True)
      l.append(a)
for i in range(0, len(l)):
  count += l[i][0]*l[i][1]
print(math.floor(count/2))

Measured memory_bytes: 3316
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2019-12-13 13:15:46
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int a, b;
    cin >> a >> b;

    int ans;
    if (a <= 9 && b <= 9) {
        ans = a * b;
    } else {
        ans = -1;
    }

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


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  for (int i = 0; i < n; i++) {
    long long maxdec = -1LL * (n - 1 - i) * d;
    long long mindec = -1LL * (n - 1 - i) * c;
    long long maxinc = 1LL * i * d;
    long long mininc = 1LL * i * c;
    if (1LL * a + maxinc + mindec >= 1LL * b && 1LL * a + mininc + maxdec <= 1LL * b) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;	
}

Measured memory_bytes: 256
function main(input) {
  input=input.trim();
  const N = parseInt(input.split(" ")[0], 10);
  const arrS = input.split('\n')[1].split(' ').map((n) => (n));
  var ans=0;
  if(arrS.indexOf("P")!=-1){
    ans++
  }
  if(arrS.indexOf("W")!=-1){
    ans++
  }
  if(arrS.indexOf("G")!=-1){
    ans++
  }
  if(arrS.indexOf("Y")!=-1){
    ans++
  }
  if(ans==3){
    console.log("Three");
  }else{
    console.log("Four");
  }

}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int ALP = 26;

const int N = 1010;
int dp[N][1<<12];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int hp_i, hp_m;
    while(cin >>hp_i >>hp_m, hp_i){
        int h,w;
        cin >>h >>w;
        vector<string> s(h);
        rep(i,h) cin >>s[i];

        int T;
        cin >>T;
        vector<int> trap(ALP,0);
        rep(i,T){
            char c;
            int d;
            cin >>c >>d;
            trap[c-'A'] = d;
        }

        int S;
        cin >>S;
        string route = "";
        int px = 0, py = 0;
        rep(i,S){
            char c;
            int d;
            cin >>c >>d;
            while(d--){
                if(c=='U') --py;
                if(c=='D') ++py;
                if(c=='L') --px;
                if(c=='R') ++px;
                route += s[py][px];
            }
        }

        int P;
        cin >>P;
        vector<int> p(P);
        rep(i,P) cin >>p[i];

        int SZ = route.size();
        memset(dp,0,sizeof(dp));
        dp[0][0] = hp_i;
        rep(i,SZ)rep(mask,1<<P)if(dp[i][mask]>0){
            // move
            dp[i+1][mask] = max(dp[i+1][mask], dp[i][mask]-trap[route[i]-'A']);

            // use potion
            rep(j,P)if(!(mask>>j&1)){
                int nmask = mask | (1<<j);
                dp[i][nmask] = max(dp[i][nmask], min(hp_m, dp[i][mask]+p[j]) );
            }
        }

        string ans = "NO";
        if(dp[SZ][(1<<P)-1]>0) ans = "YES";
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 5;

vector < int > f (N);

ll pwr (ll a, ll b, ll mod) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

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

  f[0] = 0;
  f[1] = 1;
  for (int i = 2; i < N; i++) {
    f[i] = f[i % __builtin_popcount (i)] + 1;
  }

  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for (int i = 0; i < n; i++) cnt += (s[i] == '1');

  if (cnt == 0) {
    for (int i = 0; i < n; i++) {
      cout << 1 << '\n';
    }
    return 0;
  }
  if (cnt == 1) {
    int b = 0;

    for (int i = 0; i < n; i++) {
      if (s[i] == '0') continue;
      b += pwr (2, n - i - 1, 2);
      b %= 2;
    }

    for (int i = 0; i < n; i++) {
      int ans;
      if (s[i] == '0') {
        ans = (b + pwr (2, n - i - 1, 2)) % 2;
        cout << f[ans] + 1 << '\n';
      } else {
        cout << 0 << '\n';
      }
    }

    return 0;
  }

  int a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') continue;
    a += pwr (2, n - i - 1, cnt - 1);
    a %= (cnt - 1);
  }

  for (int i = 0; i < n; i++) {
    if (s[i] == '0') continue;
    b += (pwr (2, n - i - 1, cnt + 1));
    b %= (cnt + 1);
  }

  for (int i = 0; i < n; i++) {
    int ans;
    if (s[i] == '0') {
      // use cnt + 1;
      ans = (b + pwr (2, n - i - 1, cnt + 1)) % (cnt + 1);
    } else {
      // use cnt - 1;
      ans = (a - pwr (2, n - i - 1, cnt - 1) + cnt - 1) % (cnt - 1);
    }
    cout << f[ans] + 1 << '\n';
  }
}


Measured memory_bytes: 4408
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	int[] hindo = new int[101];
	while(sc.hasNext()){
	    int num = sc.nextInt();
	    hindo[num]++;
	}

	//ツ出ツ個サツ嘉アツ青板づ個催妥・ツ値ツづーツ仰づ淞づゥ
	int max = 0;
	for(int i=0; i<hindo.length; i++){
	    if(hindo[i]>max){max = hindo[i];}
	}

	for(int i=0; i<hindo.length; i++){
	    if(hindo[i]==max){
		System.out.println(i);
	    }
	}
    }
}

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

int search(int first,int last,int k, int *S){
	if (first==last){
		if (S[first]==k){
			return 1;
		}else{
			return 0;
		}
	}else{
		int m;
		m=(first + last)/2;
		if(S[m]==k){
			return 1;
		}
		else if(S[m]>k){
			return search(first,m,k,S);
		}else{
			return search(m+1,last,k,S);
			}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int i,j,n,q;
	int count=0;
	
	cin >> n;
	int S[n];
	for (i=0;i<n;i++){
		cin >> S[i];
	}
	cin >> q;
	int T[q];
	for (i=0;i<q;i++){
		cin >> T[i];
	}
	
	for (j=0;j<q;j++){
		count+=search(0,n-1,T[j],S);
	}
	
	cout << count << endl;
	
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;


int main(){
  double n; cin >> n;

  rep(i,50000){
    int price = (int)(i*1.08);
    if(price == n){
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<string,pair<int,int>> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct Res {
  string s; int p, num;
};

bool comp(const Res& a, const Res& b) {
  if (a.s != b.s)
    return a.s < b.s; // 高い順に並べたいので演算子を逆に
  if (a.p != b.p)
    return a.p > b.p; // 同様に比較演算子を反転
}


int N,p;
string s;
int main(){
    cin >> N;
    vector<Res> R;
    rep(i,N) cin >> s >> p, R.pb({s,p,i+1});
    sort(ALL(R),comp);
    rep(i,N) print(R[i].num);
}

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

using namespace std;
typedef long long ll;
const int N = 200010;
const ll INFLL = 1e18;
int _w;

int n, a[N];
ll s[N], mx, mn;

ll sum( int L, int R ) {
	return s[R] - s[L-1];
}

ll check( int L, int mid, int R ) {
	if( mid == R ) return INFLL;
	return abs( sum(L, mid) - sum(mid+1, R) );
}

void qwq( int L, int mid, int R ) {
	mn = min( mn, sum(L, mid) );
	mx = max( mx, sum(L, mid) );
	mn = min( mn, sum(mid+1, R) );
	mx = max( mx, sum(mid+1, R) );
}

void solve( int L, int R ) {
	int low = L, high = R-1;
	while( low < high ) {
		int mid = (low + high + 1)/2;
		if( sum(L, mid) <= sum(mid+1, R) )
			low = mid;
		else high = mid-1;
	}
	if( check(L, low, R) < check(L, low+1, R) )
		qwq(L, low, R);
	else qwq(L, low+1, R);
}

int main() {
	_w = scanf( "%d", &n );
	for( int i = 1; i <= n; ++i ) {
		_w = scanf( "%d", a+i );
		s[i] = s[i-1] + a[i];
	}
	ll ans = INFLL;
	for( int i = 2; i <= n-2; ++i ) {
		mx = -INFLL;
		mn = INFLL;
		solve(1, i);
		solve(i+1, n);
		ans = min( ans, mx-mn );
	}
	printf( "%lld\n", ans );
	return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    for(int i = 1; ; i++){
      int x = sc.nextInt();
      if(x==0)
          break;
      System.out.printf("Case %d: %d\n", i, x);
    }
  }
}



Measured memory_bytes: 66100
#include<bits/stdc++.h>
 
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cerr << (#x) << " is " << (x) << endl
#define INF 1e13
#define LL_MAX 1e18
// memset(array, -1, sizeof(array[0][0]) * row * count)
using namespace std;
 
ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 
bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }
bool check(ll i,ll j,ll n){return (i>=0 && i<n && j>=0 &&  j<n);} //matrix boundary checking
 
 
ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
 
// max({a, b, c, d})
// cout << fixed for removing e notation
 
bool comp(pair<ll, ll>a, pair<ll, ll>b)
{
    if(a.se-a.fi < b.se-b.fi) return true;
    else return false;
}
 
void convert(int arr[], int n) 
{ 
    int temp[n+1];
    for(int i=1;i<=n;i++)
        temp[i] = arr[i]; 
    // memcpy(temp, arr, n*sizeof(int)); 
  
    sort(temp+1, temp+n+1);   
    unordered_map<int, int> umap;
    int val = 1; 
    for (int i = 1; i <= n; i++) 
        umap[temp[i]] = val++;
    for (int i = 1; i <= n; i++) 
        arr[i] = umap[arr[i]]; 
}
 
bool prime[10000005];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime)); 
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++) 
    {
        if (prime[p] == true) 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
    }
} 

int main()
{
    string s, t;
    cin >> s >> t;

    cout << t+s << "\n";  
} 
    

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

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

    ll d[n];
    rep(i, n){
        cin >> d[i];
    }

    ll sum = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pl pair<ll,ll>
#define vl(p) vector<p>
#define W while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007


int main() {
	FASTIO;
    ll t=1, i ,j, k, l;
    // cin>>t;
    W(t--) {
        ll n, k;
        cin>>n>>k;
        ll a[n], res[n], temp[k];
        FOR(i,n) cin>>a[i];
      	if(k>=n-1) { pr(a[n-1]-a[0]); continue; }
        Fore(i,1,k) res[i]=abs(a[i]-a[0]);
        For(i,k+1,n) {
            FOR(j,k) temp[j]=abs(a[i]-a[i-j-1])+res[i-j-1];
            res[i]=*min_element(temp,temp+k);
        }
        pr(res[n-1]);
        nl;
    }
	return 0;
}


Measured memory_bytes: 1792
a, b = map(int, input().split())

if a >= 2 and b >=2 :
    ans = ((a * (a + 1))//2 - a) + ((b * (b +1))//2 - b)
    print(ans)

if a < 2 and b < 2:
    print(0)

if a < 2 and b >= 2:
    print((b * (b + 1))//2 -b)

if a >= 2 and b < 2:
    print((a * (a + 1))//2 -a)

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

int main() {
 double d,t,s;
 cin>>d>>t>>s;
 
 if(d/s<=t){
  cout << "Yes";
  }
  else {
   cout << "No";
   }
 }

Measured memory_bytes: 3720
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    vector<long long> h(n);
    for (int i=0; i<n; i++) cin >> h[i];

    int ans = 0;
    int cur = 0;
    
    for (int i=1; i<n; i++) {
        if (h[i-1] >= h[i]) {
            cur++;
        }
        else {
            ans = max(ans, cur);
            cur = 0;
        }
    }

    ans = max(ans, cur);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
using lint = long long;
using vi = vector<int>;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && a != c || a == c && a != b || b == c && a != b) {
		cou("Yes");
	}
	else {
		cou("No");
	}
}

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

using ll=long long;

int main(){

string S;
cin>>S;

int a=S.size();

for(int i=0;i<a;++i){

if(i%2==0){
if(S[i]=='L'){cout<<"No"<<endl; goto xyz;}
} else {
if(S[i]=='R'){cout<<"No"<<endl; goto xyz;}
}

}

cout<< "Yes" << endl;

xyz:;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, a, b;
string s;

void output(bool b) {
    cout << (b?"Yes":"No") << endl;
}

void solve() {
    int dom = 0, ove = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a') {
            if (dom + ove < a + b) {
                output(1);
                dom++;
            } else {
                output(0);
            }
        } else if (s[i] == 'b') {
            if (dom + ove < a + b && ove < b) {
                output(1);
                ove++;
            } else {
                output(0);
            }
        } else {
            output(0);
        }
    }
}

void input() {
    cin >> n >> a >> b >> s;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


Measured memory_bytes: 848
// compile option: g++ -std=c++11
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;
typedef vector<P> VP;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];
  priority_queue<P> que;
  REP(i, n) que.push(P(b[i], i));
  ll ans = 0;
  while (que.size()) {
    P p = que.top();
    que.pop();
    int i = p.second;
    int sum = b[(i - 1 + n) % n] + b[(i + 1) % n];
    if (sum < b[i]) {
      int t = (b[i] - a[i]) / sum;
      if (0 < t) {
        b[i] -= t * sum;
        que.push(P(b[i], i));
        ans += t;
      }
    }
  }
  REP(i, n) {
    if (a[i] != b[i]) ans = -1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3956
#include <stdio.h>

int main(int argc, char **argv)
{
    int a, b;
    scanf("%d %d", &a, &b);

    if (a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) {
        puts("Possible");
    } else {
        puts("Impossible");
    }
    return 0;
}

Measured memory_bytes: 128
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

const int mod = 1e9+7;
enum{N=5003};
il ll qpow(ll a,ll b){
	ll ans= 1;
	for(; b; b>>=1,a=a*a%mod) if( b&1 ){
		ans= ans*a%mod;
	} return ans;
}

ll f[N][2],g[N][2];
ll f2[N][2];
ll w[N];

int main(){
	int n = ci(), a = ci(), b = ci();
	if( a>b ) swap(a,b);
	if( b==1 ){
		printf("%lld\n",qpow(2,n));
		return 0;
	}
	f[0][0] = 1;
	rep(i,1,b-1){
		rep(j,1,i){
			if( j>=a ) f[i][0] = (f[i][0]+f[i-j][1])%mod;
			f[i][1] = (f[i][1]+f[i-j][0])%mod;
		}
	}
	f2[0][1] = 1;
	rep(i,1,b-1){
		rep(j,1,i){
			if( j>=a ) f2[i][0] = (f2[i][0]+f2[i-j][1])%mod;
			f2[i][1] = (f2[i][1]+f2[i-j][0])%mod;
		}
	}
	g[0][1] = g[0][0] = 1;
	ll ans = qpow(2,n);
	rep(i,1,n){
		if( i<b ){
			g[i][1] = (g[i][1]+f2[i][1])%mod;
		}
		rep(j,1,min(i,b-1)){
			if( j<a ) g[i][0] = (g[i][0]+g[i-j][1])%mod;
			g[i][1] = (g[i][1]+g[i-j][0]*f[j][1])%mod;
		}
		if( i!=n && n-i<b ){
			ans = (ans-g[i][0]*f[n-i][0])%mod;
		}
	}
	ans = (ans-g[n][1]-g[n][0])%mod;
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int n;
int ans = 0;

void dfs(string s) {
	if (stoll(s) > n) return;
	set<char> sc(all(s));
	if (sz(sc) == 3) ans++;
	dfs(s + "3");
	dfs(s + "5");
	dfs(s + "7");
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	read(n);

	dfs("3");
	dfs("5");
	dfs("7");
	die(ans);
}


Measured memory_bytes: 256
#pragma GCC optimize (2)
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 300010
using namespace std;
struct tt{int l, r, sum;}t[6000010];
struct aa{int x, y;}a[N];
int n, m, l, root[N], ans, now, l1, x;
inline char gc(){
	static char now[1<<16], *S, *T;
	if(S==T){T=(S=now)+fread(now, 1, 1<<16, stdin); if(S==T)return EOF;}
	return *S++;
}
inline int read(){
	int x=0, f=1; char ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=gc();}
	return x*f;
}
inline bool cmp(aa a, aa b){return a.x<b.x;}
inline void ins(int i, int x, int L, int R){
	t[l]=t[i]; t[l].sum++;
	if(L<R){
		int mid=(L+R)>>1, l1=l;
		if(x<=mid){l++; t[l1].l=l; ins(t[i].l, x, L, mid);}
		else{l++; t[l1].r=l; ins(t[i].r, x, mid+1, R);}
	}
}
inline int csum(int x1, int x2, int a, int b, int L, int R){
	if(a<=L&&R<=b)return t[x1].sum-t[x2].sum;
	int mid=(L+R)>>1, s=0;
	if(a<=mid)s+=csum(t[x1].l, t[x2].l, a, b, L, mid);
	if(mid<b)s+=csum(t[x1].r, t[x2].r, a, b, mid+1, R);
	return s;
}
int main(){
	n=read(); m=read();
	for(int i=1; i<=n; i++){a[i].x=read(); a[i].y=read();}
	sort(a+1, a+1+n, cmp);
	l=root[0]=now=0;
	for(int i=1; i<=m; i++){
		root[i]=root[i-1];
		while(now<n&&a[now+1].x==i){
			now++;
			l++; l1=l; ins(root[i], a[now].y, 1, m); root[i]=l1;
		}
	}
	printf("%d\n", n);
	for(int i=2; i<=m; i++){
		ans=n;
		for(x=i; x<=m; x+=i)ans-=csum(root[x-1], root[x-i], x-i+1, x-1, 1, m);
		x-=i; if(x<m)ans-=csum(root[m], root[x], x+1, m, 1, m);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 67712
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            board = [[None for j in range(21)] for i in range(21)]
            gems = []
            for i in range(n):
                x, y = map(int, raw_input().split())
                board[y][x] = 1
                gems.append((x, y))
            m = input()
            route = [(10, 10)]
            for i in range(m):
                d, l = raw_input().split()
                l = int(l)
                init = route[-1]
                if d == 'N':
                    for j in range(1, l+1):
                        route.append((init[0], init[1] + j))
                elif d == 'E':
                    for j in range(1, l+1):
                        route.append((init[0] + j, init[1]))
                elif d == 'S':
                    for j in range(1, l+1):
                        route.append((init[0], init[1] - j))
                elif d == 'W':
                    for j in range(1, l+1):
                        route.append((init[0] - j, init[1]))
            if set(gems) <= set(route):
                print 'Yes'
            else:
                print 'No'
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 4712
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();

        String S = sc.nextToken();
        boolean is = false;

        int a[] = new int[26];
        int two = 0;
        for (int i=0;i<4;i++) {
            a[S.charAt(i) - 'A']++;
        }
        for (int i: a) {
            if (i == 2) two++;
        }
        is = two == 2;


        out.println(is ? "Yes" : "No");
        out.flush();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        int[] nextIntArray(int N) {
            int a[] = new int[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextInt();
            }

            return a;
        }

        long[] nextLongArray(int N) {
            long a[] = new long[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextLong();
            }

            return a;
        }

        double[] nextDoubleArray(int N) {
            double a[] = new double[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextDouble();
            }

            return a;
        }

        String[] nextTokenArray(int N) {
            String a[] = new String[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextToken();
            }

            return a;
        }
    }
}

Measured memory_bytes: 20564
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <stdio.h>
using namespace std;

int main(){
    int N,temp,i;
    double ans;
    vector<int> v;
    cin>>N;
    for(i=0;i<N;i++){
        cin>>temp;
        v.push_back(temp);
    }
    sort(v.begin(),v.end());
    ans=v.at(0);
    for(i=1;i<N;i++){
        ans=(ans+v.at(i))/2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[]$) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] b = new int[n][n];
        int[] wait = new int[n + 1];
        wait[n] = n;
        Deque<Integer>[] deque = new Deque[n];
        for (int i = 0; i < n; i++) {
            deque[i] = new ArrayDeque<>();
            wait[i] = scanner.nextInt() - 1;
            for (int j = 2; j < n; j++) {
                deque[i].add(scanner.nextInt() - 1);
            }
        }
        int[] lastMatch = new int[n];
        int rem = n;
        while (rem > 0) {
            boolean updated = false;
            for (int i = 0; i < n; i++) {
                if (wait[wait[i]] == i) {
                    lastMatch[wait[i]] = lastMatch[i] = Math.max(lastMatch[wait[i]], lastMatch[i]) + 1;
                    updated = true;
                    if (!deque[wait[i]].isEmpty()) {
                        wait[wait[i]] = deque[wait[i]].poll();
                    } else {
                        wait[wait[i]] = n;
                        rem--;
                    }
                    if (!deque[i].isEmpty()) {
            
                        wait[i] = deque[i].poll();
                    } else {
                        rem--;
                    }
                }
            }
            if (!updated) {
                System.out.println(-1);
                return;
            }
        }
        Arrays.stream(lastMatch).max().ifPresent(System.out::println);
    }
    
}


Measured memory_bytes: 274076
import java.util.*;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        final int N=scanner.nextInt();
        final int C=scanner.nextInt();
        final int[][] D=new int[C][C];
        for(int i=0;i<C;i++){
            for(int j=0;j<C;j++){
                D[i][j]=scanner.nextInt();
            }
        }
        final int[][] mat=new int[N][N];
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                mat[i][j]=scanner.nextInt();
            }
        }
        long min=Long.MAX_VALUE;
        int[][] memo=new int[3][C];
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                memo[(i+j+2)%3][mat[i][j]-1]++;
            }
        }
        int[] c=new int[3];
        for(c[0]=0;c[0]<C;c[0]++){
            for(c[1]=0;c[1]<C;c[1]++){
                for(c[2]=0;c[2]<C;c[2]++){
                    if(c[0]==c[1]||c[1]==c[2]||c[0]==c[2]) continue;
                    long d_min=0;
                    for(int i=0;i<3;i++){
                        for(int j=0;j<C;j++){
                            d_min+=memo[i][j]*D[j][c[i]];
                        }
                    }
                    if(min>d_min){
                        min=d_min;
                    }
                }
            }
        }
        System.out.println(min);

    }
}


Measured memory_bytes: 89916
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i,n) for(int i=n-1;i>=0;i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
 

signed main(){
   
   int n,a[111111],b[111111];
   cin>>n;
   rep(i,n){
       cin>>a[i]>>b[i];
   }
   int co=0;
   repb(i,n){
       if((a[i]+co)%b[i]==0)continue;
       co+=b[i]*((a[i]+co)/b[i]+1)-(a[i]+co);
       DEB(co)END
   }
   cout<<co<<endl;
}


Measured memory_bytes: 1792
# ARC102C - Triangular Relationship (ABC108C)
def main():
    N, K = list(map(int, input().rstrip().split()))
    a = N // K
    if K % 2 != 0:  # K: odd
        print(a ** 3)
    else:  # K: even
        b = (N + K // 2) // K
        print(a ** 3 + b ** 3)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

struct vec
{
    double x, y;
    vec (const double& x0 = 0, const double& y0 = 0) : x(x0), y(y0) {}
    vec operator + (const vec& t) const {return vec(x+t.x, y+t.y);}
    vec operator - (const vec& t) const {return vec(x-t.x, y-t.y);}
    vec operator * (const double& t) const {return vec(x*t, y*t);}
    vec operator / (const double& t) const {return vec(x/t, y/t);}
    const double len2 () const {return x*x + y*y;}
    const double len () const {return sqrt(len2());}
    vec norm() const {return *this/len();}
    vec rotate_90_c () {return vec(y, -x);}
};

double dot(const vec& a, const vec& b) {return a.x*b.x + a.y*b.y;}
double crs(const vec& a, const vec& b) {return a.x*b.y - a.y*b.x;}

vec lin_lin_int(const vec& p0, const vec& v0, const vec& p1, const vec& v1)
{
    double t = crs(p1-p0, v1) / crs(v0, v1);
    return p0 + v0 * t;
}

vec circle(const vec& a, const vec& b, const vec& c)
{
    return lin_lin_int((a+b)/2, (b-a).rotate_90_c(), (a+c)/2, (c-a).rotate_90_c());
}

int n;
vec pot[100005];

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%lf%lf", &pot[i].x, &pot[i].y);
    random_shuffle(pot+1, pot+n+1);
    vec o;
    double r2 = 0;
    for(int i=1; i<=n; i++)
    {
        if((pot[i]-o).len2() > r2)
        {
            o = pot[i], r2 = 0;
            for(int j=1; j<i; j++)
            {
                if((pot[j]-o).len2() > r2)
                {
                    o = (pot[i]+pot[j])/2, r2 = (pot[j]-o).len2();
                    for(int k=1; k<j; k++)
                    {
                        if((pot[k]-o).len2() > r2)
                        {
                            o = circle(pot[i], pot[j], pot[k]), r2 = (pot[k]-o).len2();
                        }
                    }
                }
            }
        }
    }
    printf("%.10lf\n", sqrt(r2));
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
*A, = map(int, input().split())

ans = 0
for i in range(n):
    for j in range(n-1):
        if A[j+1] < A[j]:
            A[j], A[j+1] = A[j+1], A[j]
            ans += 1
print(*A)
print(ans)



Measured memory_bytes: 5608