akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

int main(){
	int r, g, b, x;
	cin >> r >> g >> b;
	x = r * 100 + g * 10 + b;
	if (x % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
end = [1,1,1,1,1]
while True:
  n = int(input())
  if n == 0:
    break
  mp = [[0] * 5 for _ in range(6000)]
  height = [0] * 5
  cnt = 0
  for i in range(n):
    d, p, q = map(int, input().split())
    q -= 1
    cnt += p
    if d == 1:
      pos = max(height[q:q + p])
      mp[pos][q:q + p] = [1] * p
      if mp[pos] == end:
        cnt -= 5
        mp.pop(pos)
        mp.append([0] * 5)
        for x in range(5):
          for y in range(i * 5 - 1, -1, -1):
            if mp[y][x] == 1:
              height[x] = y + 1
              break
          else:
            height[x] = 0
      else:
        height[q:q + p] = [pos + 1] * p

    if d == 2:
      pop_flag = False
      pos = height[q]
      for y in range(pos, pos + p):
        mp[y][q] = 1
      for y in range(pos + p - 1, pos - 1, -1):
        if mp[y] == end:
          cnt -= 5
          mp.pop(y)
          mp.append([0] * 5)
          pop_flag = True
      
      if pop_flag:
        for x in range(5):
          for y in range(i * 5 - 1, -1, -1):
            if mp[y][x] == 1:
              height[x] = y + 1
              break
          else:
            height[x] = 0
      else:
        height[q] += p
  
  print(cnt)


Measured memory_bytes: 6988
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
MOD = 998244353

S = input()
N = len(S)
B = [0]*(2*N+1)
R = [0]*(2*N+1)

for i in range(N):
    b = int(S[i])
    B[i] = b
    R[i] = 2 - b

DP = defaultdict(int)
DP[(B[0], R[0])] = 1

for i in range(1, 2*N+1):
    DP2 = defaultdict(int)
    b1, r1 = B[i], R[i]
    for (b0, r0), v in DP.items():
        b2, r2 = b0+b1, r0+r1
        if b0:
            DP2[(b2-1, r2)] = (DP2[(b2-1, r2)] + v)%MOD
        if r0:
            DP2[(b2, r2-1)] = (DP2[(b2, r2-1)] + v)%MOD
    DP = DP2

print(sum(DP.values()))


Measured memory_bytes: 84956
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n==25) printf("Christmas\n");
    if(n==24) printf("Christmas Eve\n");
    if(n==23) printf("Christmas Eve Eve\n");
    if(n==22) printf("Christmas Eve Eve Eve\n");
    return 0;
}


Measured memory_bytes: 1604
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
#include <ext/hash_set>
struct Hasher
{int operator()(int x)const{return x^0x45678901;}};
typedef __gnu_cxx::hash_set<int,Hasher> hashset_int;
int n,m,x[SZ],y[SZ];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",x+i);
	for(int i=1;i<=m;i++) scanf("%d",y+i);
	ll ax=0,ay=0,t=0,s=0,MOD=1e9+7;
	for(int i=1;i<=n;i++)
	{
		ax+=t*x[i]-s; ax%=MOD;
		++t; s+=x[i]; s%=MOD;
	}
	t=s=0;
	for(int i=1;i<=m;i++)
	{
		ay+=t*y[i]-s; ay%=MOD;
		++t; s+=y[i]; s%=MOD;
	}
	ax*=ay; ax=(ax%MOD+MOD)%MOD;
	printf("%d\n",ax);
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
char ara[100005];

int main()
{
    int ln,cnt,i;
    scanf("%s",ara);
    ln=strlen(ara);
    cnt=0;
    for(i=1; i<ln; i++)
    {
        if(ara[i]==ara[i-1])
        {
            if(ara[i]=='0')ara[i]='1';
            else ara[i]='0';
            cnt++;
        }
    }
    printf("%d",cnt);

    return 0;
}


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

char que(int x){
    printf("%d\n",x);
    fflush(stdout);
    char c[8];
    scanf("%s", c);
    if(c[0]=='V')exit(0);
    return c[0];
}

int main(){
    int n;
    scanf("%d", &n);
    int l=0,r=n;
    char bl=que(l);
    while(r-l>1){
        int mid=(l+r)/2;
        char br=que(mid);
        if((bl!=br&&(mid-l)%2==0)||(bl==br&&(mid-l)%2==1))r=mid;
        else l=mid,bl=br;
    }
}

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

int N,M;
vector<vector<int>> v(9,vector<int>(9,-1));

bool check(int y){
    int win = 0,nul = 0;
    for(int x=0;x<N;x++){
        if(v[y][x]==1) win++;
        else if(v[y][x]==-1 && y!=x) nul++;
    }
    return win<=(N-1)/2 && (N-1)/2<=win+nul;
}        

int dfs(int now){
    int res = 0;
    int x = now%N,y = now/N;
    if(now==N*N) return 1;
    if(x==y || v[y][x]!=-1){
        if(check(y)) res += dfs(now+1);
        return res;
    }
    v[y][x] = 1; v[x][y] = 0;
    if(check(y)) res += dfs(now+1);
    v[y][x] = 0; v[x][y] = 1;
    if(check(y)) res += dfs(now+1);
    v[y][x] = -1; v[x][y] = -1;
    return res;
}

int main(){
    while(cin >> N >> M && N>0){
        int x,y;
        for(int i=0;i<N;i++) for(int j=0;j<N;j++) v[i][j] = -1;
        for(int i=0;i<M;i++){
            cin >> x >> y;
            x--; y--;
            v[x][y] = 1;
            v[y][x] = 0;
        }
        cout << dfs(0) << endl;
    }
}


Measured memory_bytes: 3148
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

a = readInt()
print(a+a**2+a**3)

Measured memory_bytes: 9340
N = int(raw_input())
F = []
for i in range(N):
    li = map(int,raw_input().split())
    F.append(li)
P = []
for i in range(N):
    li = map(int,raw_input().split())
    P.append(li)
bigest = None
for i in range(1024):
    kasa = []
    for x in range(N):
        kasa.append(0)
    i = i + 1 
    bi = str(bin(i)).split("b")[1]
    bi = (10-len(bi))*"0" + bi
    for i2 in range(10):
        if bi[i2]  == "1":
            for i3 in range(N):
                if F[i3][i2] == 1:
                    kasa[i3] += 1
    me = 0 
    for i2 in range(N):
        me += P[i2][kasa[i2]]
    if bigest < me or bigest == None:
        bigest = me
print bigest

Measured memory_bytes: 2820
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll A,B,K,ans=1;

int main(){
    cin>>K>>A>>B;
    if(A+1<B&&K>=A+1){
        ans=B;
        K-=A+1;
        ans+=(K/2)*(B-A);
        K%=2;
    }
    out(ans+K);
}


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

int main(){
	int age,price;
	cin>>age>>price;
	
	if(age>=13){
		cout<<price;
		
	}
	else if(age>=6 && age<=12){
		cout<<price/2;
	}
	else if(age>=0 && age<=5){
		cout<<0;
	}
  return 0;
}

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

int main() {
	int n;
	cin>>n;
	int arr[n];
	for (int i=0; i<n; i++){
		cin >> arr[i];
	}
	sort (arr, arr+n);
	int x = arr[n-1];
	long long side = 1;
	int cnt = 0;
	for (int i=n-2; i>=0; i--){
		//cout << x << " " <<arr[i] << endl;
		if (arr[i]==x){
			side*=x;
			x = -1;
			cnt++;
			if (cnt==2){
				cout << side<< endl;
				return 0;
			}
		}
		else {
			x = arr[i];
		}
	}
	cout << 0 << endl;
}

//sort 之後取最大最後面的兩個以上的連續數字相乘




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

using namespace std;

int main(){
    string S;
    cin >> S;
    vector<int> a(4,0);
    for(int i=0;i<S.size();i++){
        if(S[i]=='N'){
            a[0]++;
        }else if(S[i]=='W'){
            a[1]++;
        }else if(S[i]=='S'){
            a[2]++;
        }else{
            a[3]++;
        }
    }

    if((0==a[0])==(0==a[2]) && (0==a[1])==(0==a[3])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	 int n,m,q;
	 cin>>n>>m>>q;
	 vector<int>a[505];
	 for(int i=0;i<m;i++)
	 { int t,t1;
	  cin>>t>>t1;
	   a[t].push_back(t1);
	 }
	 
	 for(int i=0;i<n;i++)
	  sort(a[i].begin(),a[i].end());
	  for(int i=0;i<q;i++)
	  {int ans=0;
	  	 int s,e;
	  	 cin>>s>>e;
	  	 for(int j=s;j<=e;j++)
	  	   {
	  	   	 ans+=(upper_bound(a[j].begin(),a[j].end(),e)-a[j].begin());
				  			 }
				  			 printf("%d\n",ans);
				  			 
	  }
	  
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right ){
	int n1 = mid -left;
	int n2 = right - mid;
	for(int i=0; i<n1; i++ ) L[i] = A[left+i];
	for(int i=0; i<n2; i++ ) R[i] = A[mid+i];
	L[n1] = R[n2] = SENTINEL;

	int i=0,j=0;
	for(int k=left; k<right; k++){
		cnt++;
		if( L[i]<=R[j] ){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
		}
	}
}


void mergeSort(int A[], int n, int left, int right ){
	if( left+1 < right ){
		int mid = (left+right)/2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}


int main(){
	int A[MAX],n;
	cnt = 0;

	cin >> n;
	for(int i=0; i<n; i++) cin >> A[i];

	mergeSort(A,n,0,n);

	for(int i=0; i<n; i++){
		if(i) cout << " ";
		cout << A[i];
	}

	cout << "\n";
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 6964
#include<bits/stdc++.h>
using namespace std;
const int maxn=1050302;
bool vis[maxn];
int d[maxn],n,m;
vector <int> h[maxn];
int main(){
    cin >> n >> m;
    //if (m!=n+2) {puts("No");return 0;}
    for (int i=0;i<m;i++){
        int u,v;
        cin >> u >> v;
        d[u]++; d[v]++;
        h[u].push_back(v);
        h[v].push_back(u);
    }
    for (int i=1;i<=n;i++) if (d[i]&1){puts("No");return 0;}
    if (n>=m) {puts("No");return 0;}
    queue <int> q;
    for (int i=1;i<=n;i++) if (d[i]==2) q.push(i);
    while (!q.empty()){
        int u=q.front(); vis[u]=1; q.pop();
        int s=0,t=0;
        for (auto v:h[u]) if (!vis[v]){
            if (!s) s=v; else t=v;
        }
        h[s].push_back(t);
        h[t].push_back(s);
    }
    vector <int> p;
    for (int i=1;i<=n;i++) if (!vis[i]) p.push_back(i);
    if (p.size()>=3) {puts("Yes");return 0;}
    if (p.size()==1){
        int s=p[0];
        if (d[s]<=4) {puts("No");return 0;}
        puts("Yes");return 0;
    }
    int s=p[0],t=p[1];
    bool flag=false;
    if (d[s]==4&&d[t]==4) flag=true;
    for (auto v:h[s]) if (!vis[v]){
        if (v!=t) flag=false;
    }
    if (flag) puts("No"); else puts("Yes");
    return 0;
}



Measured memory_bytes: 31488
#include <bits/stdc++.h>
#include <set>
#include <queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define readVarll(nam) ll nam; cin >> nam
#define INF 99999999999

ll p[5001];
ll c[5001];

ll calc(ll n, ll k)
{
  ll ans = -INF;
  repl(i, n)
  {
    ll tmpans = 0;
    ll sum = 0;
    ll idx = i;
    ll cnt = 0;
    ll locnt = k;

    do
    {
      sum += c[idx];
      idx = p[idx];
      cnt++;
    } while (idx != i);
    if(locnt / cnt >= 1 && sum > 0)
    {
      if(locnt % cnt > 0)
      {

        tmpans += sum * (k / cnt - 1);
        locnt %= cnt;
        locnt += cnt;
      }
      else
      {
        tmpans += sum * (k / cnt - 1);
        locnt = cnt;
      }
    }
    else
    {
      if(locnt % cnt > 0)
      {
        locnt %= cnt;
        if(k > cnt)
        {
          locnt += cnt;
        }
      }
      else
      {
        locnt = cnt;
      }
    }

    ll pt = i;
    ll vmax = -INF;
    ll vtmp = 0;
    repl(x, locnt)
    {
      vtmp += c[p[pt]];
      vmax = max(vtmp, vmax);
      pt = p[pt];
    }
    tmpans += vmax;
    ans = max(ans, tmpans);
  }

  return ans;
}

ll calc2(ll n, ll k)
{
  ll ans = -INF;

  rep(i, n)
  {
    ll tmp = 0;
    ll pt = i;
    rep(j, k)
    {
      tmp += c[p[pt]];
      pt = p[pt];
      ans = max(ans, tmp);
    }
  }
  return ans;
}

int main()
{
  ll n,k;
  cin >> n >> k;

  repl(i, n)
  {
    readVarll(tmp);
    p[i] = tmp - 1;
  }

  repl(i, n)
  {
    readVarll(tmp);
    c[i] = tmp;
  }


  // ここから確認
  // srand(time(NULL));
  // n = 5;
  // rep(i, n)
  // {
  //   p[i] = ((i+1) % n);
  // }

  // rep(x, 100)
  // {
  //   k = rand() % 99 + 1;
  //   rep(i, n)
  //   {
  //     c[i] = rand() % 201 - 100;
  //   }

  //   ll ans1 = calc(n, k);
  //   ll ans2 = calc2(n ,k);

  //   if(ans1 != ans2)
  //   {
  //     cout << "wrong" << endl;
  //     cout << n << " " << k << endl;
  //     rep(i, n) cout << (p[i]+1) << " ";
  //     cout << endl;
  //     rep(i, n) cout << c[i] << " ";
  //     cout << endl;
  //     cout << "ans1=" << ans1 << ",ans2=" << ans2 << endl;
  //   }
  // }
  //ここまで

  ll ans = calc(n, k);

  cout << fixed << ans << endl;

  return 0;
}

Measured memory_bytes: 3716
n = gets.to_i
$c = Array.new(n)
n.times{ |i| $c[i] = gets.split.map(&:to_i)[1..-1] }
$depth = Array.new(n)
$max = (Math.log(n) / Math.log(2)).ceil
$dp = Array.new(n){ Array.new($max) }

def bfs
  arr = []
  arr << [0,-1,0]
  until arr.empty?
    a,pre,dep = arr.shift
    $depth[a] = dep
    $dp[a][0] = pre
    (1...$max).each do |i|
      if $dp[a][i-1] != -1 then $dp[a][i] = $dp[$dp[a][i-1]][i-1]
      else $dp[a][i] = -1
      end
    end
    $c[a].each do |i|
      next if i == pre
      arr << [i, a, dep+1]
    end
  end
end

def lca(a, b)
  a, b = b, a if $depth[a] > $depth[b]
  dh = $depth[b] - $depth[a]
  i = 0
  while (1 << i) <= dh
    b = $dp[b][i] if (dh>>i) % 2 == 1
    i += 1
  end
  return a if a == b
  ret = -1
  ($max-1).downto(0) do |i|
    if $dp[a][i] == $dp[b][i] then ret = $dp[a][i]
    else
      a = $dp[a][i]; b = $dp[b][i]
    end
  end
  ret
end

bfs
gets.to_i.times do
  a, b = gets.split.map(&:to_i)
  p lca a, b
end

Measured memory_bytes: 58100
#include <bits/stdc++.h>
using namespace std;
double PI = 3.14159265359;
int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    double maxdeg = atan(b / a) / (2 * PI) * 360;
    double left = 0;
    double right = 90;
    double mid;
    double err = 1e-7;
    if (a * a * b / 2 > x)
    {
        left = maxdeg;
        while (abs(right - left) > err)
        {
            mid = (left + right) / 2;
            double deg = 2 * PI * (mid / 360.0);
            double mass = 0.5 * (b * b * a) / tan(deg);
            if (mass < x)
            {
                right = mid;
            }
            else
            {
                left = mid;
            }
        }
    }
    else
    {
        right = maxdeg;
        while (abs(right - left) > err)
        {
            mid = (left + right) / 2;
            double deg = 2 * PI * (mid / 360.0);
            double mass = 0.5 * (tan(deg) * a * a * a) + (b - a * tan(deg)) * a * a;
            if (mass < x)
            {
                right = mid;
            }
            else
            {
                left = mid;
            }
        }
    }
    cout << setprecision(10) << fixed << right << endl;
}

Measured memory_bytes: 512
import numpy as np
S = [int(input()) for _ in range(5)]
amari = [10 if s % 10 == 0 else s % 10 for s in S]
t = 0
for i in range(5):
    ind = np.argsort(amari)[::-1][i]
    #print(ind, np.sort(amari)[::-1][i])
    if i == 4 :
        t += S[ind]
    else :
        t += S[ind] + (10 - amari[ind])
print(t)

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

int cal(int x) {
  int a = 0;
  while(x != 0){
    a += x % 10;
    x /= 10;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  
  if(n % cal(n) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n,x;
  cin>>n>>x;
  vll a(n);
  REP(i,n)
    cin>>a[i];
  
  sort(a.begin(), a.end());
  ll cur=n-1;
  ll sum =0;
  REP(i,n){
    sum += a[i];
    if(sum>x){
      cur=i;
      break;
    }
  }
  
  if(sum==x)
  	cur++;
  cout<<cur<<endl;
    
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;


int main() {
	string s;
	cin >> s;
	if (s[0] == s[1] && s[0] == s[2]) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}


	return 0;
}

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


pair<char,int> a[9];


bool f(){
	char c[]="RGB";
	int f[3][12]={};
	for(int i=0;i<9;i++)
		f[find(c,c+3,a[i].first)-c][a[i].second]++;
	for(int i=0;i<3;i++){
		for(int j=1;j<10;j++){
			if(f[i][j]<0)return false;
			f[i][j]%=3;
			for(int k=2;k>=0;k--){
				f[i][j+k]-=f[i][j];
			}
		}
	}
	return f[3]==find_if(f[0],f[3],bind1st(not_equal_to<int>(),0));
}


int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<9;i++){
			cin>>a[i].second;
		}
		for(int i=0;i<9;i++){
			cin>>a[i].first;
		}
		cout<<f()<<endl;
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 7654321
#define IINF 87654321987654321LL
#define MAXV 200500

ll mod = 1e9 + 7;
int N,M;

int main(){
	string s; cin >> s;
	ll ans = 0;
	ll sum = 0;
	rep(i,sz(s)){
		ans = max(ans, sum + s[i]-'0'-1 + 9LL*(sz(s)-i-1));

		sum += s[i]-'0';
	}
	ans = max(ans, sum);
	cout << ans;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from math import factorial

mod = 10**9+7
s = int(input())

keta = s//3
amari = s % 3

ans = 0
for now_keta in reversed(range(1, keta+1)):
    ans_tmp = factorial(
        amari+now_keta-1)//(factorial(now_keta - 1)*factorial(amari)) % mod
    amari += 3
    ans += ans_tmp

    # print(ans_tmp)

print(ans % mod)


Measured memory_bytes: 9168
#include <queue>
#include <set>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef pair<int,int> pii;

/// pair<int,int> hasher
namespace std{
	template<typename I>
	class hash<pair<I,I>>{
		public:
		size_t operator()(const pair<I,I> &p) const {return hash<long long>() (((long long)(p.first))<<32|p.second);}
	};
}

double solve(const vector<pii> &a){
	set<int>ys;
	for(auto &e:a)ys.insert(e.second);
	int n=a.size();
	vector<double>mx,my;
	mx.reserve(n*2);
	my.reserve(n*2);
	for(int i=0;i<n;i++){
		mx.push_back(a[i].first);
		my.push_back(a[i].second);
		if(i==n-1)continue;
		//??????????????§y??§?¨??????????ys?????????????????????
		if(a[i].second<a[i+1].second){ //??????i????°???§??????
			for(auto it=ys.begin();it!=ys.end();++it){
				if(a[i].second<*it && *it<a[i+1].second){
					double dy=a[i+1].second-a[i].second;
					double dx=(a[i+1].first-a[i].first)/dy*(*it-a[i].second);
					mx.push_back(a[i].first+dx);
					my.push_back(*it);
				}
			}
		}else{ //??????i????±±??§??????
			for(auto it=ys.end();it--!=ys.begin();){
				if(a[i+1].second<*it && *it<a[i].second){
					double dy=a[i+1].second-a[i].second;
					double dx=(a[i+1].first-a[i].first)/dy*(*it-a[i].second);
					mx.push_back(a[i].first+dx);
					my.push_back(*it);
				}
			}
		}
	}
	int m=mx.size();
	priority_queue<pair<double,pii>>q;
	unordered_set<pii>se;
	q.push({0,{0,m-1}});
	for(;!q.empty();){
		double c=q.top().first;
		int l=q.top().second.first;
		int r=q.top().second.second;
		q.pop();
		if(se.find({l,r})!=se.end())continue;
		se.insert({l,r});
		if(l==r)return -c;
		for(int i=-1;i<2;i++)for(int j=-1;j<2;j++){
			if((i||j) && 0<=l+i&&l+i<m && 0<=r+j&&r+j<m && fabs(my[l+i]-my[r+j])<1e-9)
				q.push({c-hypot(mx[l]-mx[l+i],my[l]-my[l+i])-hypot(mx[r]-mx[r+j],my[r]-my[r+j]),{l+i,r+j}});
		}
	}
	abort();
}

int main(){
	int N,x,y;
	for(;scanf("%d",&N),N;){
		vector<pii>a(N);
		for(int i=0;i<N;i++)scanf("%d%d",&a[i].first,&a[i].second);
		printf("%f\n",solve(a));
	}
}

Measured memory_bytes: 4444
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed;
// cout << setprecision(10) << val;

int n, k;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n >> k;
  vii v(n);
  cin >> v;
  int ans = 0;
  erep(a, 0, min(n, k)) {
    erep(b, 0, min(n, k) - a) {
      vii t;
      rep(i, 0, a) t.pb(v[i]);
      rep(j, 0, b) t.pb(v[n-1-j]);
      int cnt = k - a - b;
      sort(ALL(t));
      int sum = accumulate(ALL(t), 0);
      rep(i, 0, t.size()) {
        if (i < cnt && t[i] < 0) sum -= t[i];
      }
      chmax(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a[n];
    for (int i=0; i<m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    int cnt[n] = {0};
    for (int i=0; i<n; i++) {
        for (int x: a[i]) cnt[i]++;
    }
    for (int i=0; i<n; i++) cout << cnt[i] << '\n'; 
    
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  for(int i=0;i<n;i++)
    cin >> a[i];
  for(int i=0;i<n;i++)
    cin >> b[i];
  for(int i=0;i<n;i++)
    cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  vector<ll> cnt(n, 0);
  for(int i=0;i<n;i++) {
    ll idx = upper_bound(b.begin(), b.end(), a[i])-b.begin();
    cnt[idx]++;
  }

  for(int i=1;i<n;i++) {
    cnt[i] += cnt[i-1];
  }
  ll ans = 0;
  for(int i=0;i<n;i++) {
    ll pos_bc = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
    ans += cnt[i] * (n - pos_bc);
  }
  cout << ans << endl;
}


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

int main() {
  int n, a;
  cin >> n;
  if(n%1000 == 0) {
    cout << 0 << endl;
  }else{
    a=n/1000;
    cout << (a+1)*1000 - n << endl;
  }
  return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>
int main(void){
    int a,b,c,x;
    scanf("%d",&a);
    while(~scanf("%d%d%d",&a,&b,&c)){
        int&t=(a>b?a:b);
        if(t>c)x=c,c=t,t=x;
        printf(a*a+b*b==c*c?"YES\n":"NO\n");
    }
    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll lcm(ll n, ll m) {
	ll tmp;
	while (n%m != 0) {
		tmp = m;
		m = n % m;
		n = tmp;
	}
	return m;
}

int main(){
	ll n;
	cin >> n;
	vector<ll>t(n);
	for (int i = 0;i < n;i++) {
		cin >> t[i];
	}

	ll ans = 1;
	for (int i = 0;i < n;i++) {
		ans = ans / lcm(ans, t[i])*t[i];
	}
	cout << ans << endl;




	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    cin>> A>>B;
    if (A+B>A-B&&A+B>A*B){

        cout << A+B<<endl;
        
}else if (A*B>A+B&&A*B>A-B){
    cout << A*B<<endl;
        
}else{
    cout << A-B<<endl;
        
}
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int n;cin>>n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	int ans = INF;
	for(int i = 0; i <= 100; i++) {
		int sum = 0;
		for(int j = 0; j < n; j++) {
			sum += (a[j] - i) * (a[j] - i);
		}
		ans = min(ans,sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3556
N, K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
h.sort()
tail = N - 1
minimumAnswer = h[tail]-h[0]
for i in range(N - K+1):
    if minimumAnswer > h[i+K-1]-h[i]:
        minimumAnswer = h[i+K-1]-h[i]
print(minimumAnswer)


Measured memory_bytes: 7444
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A, B, C, D, E;
    A = sc.nextLong();
    B = sc.nextLong();
    C = sc.nextLong();
    D = sc.nextLong();
    E = sc.nextLong();
    long ar[] = { A, B, C, D, E };
    long minMove = solveMin(ar);
    long ans = ((N + minMove - 1) / minMove) + 4;
    System.out.println(ans);
  }

  public static long solveMin(long[] ar) {
    Arrays.sort(ar);
    return ar[0];
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i = a; i < b;i++)
#define pb push_back
typedef long long ll;
ll mod = 1e9 + 7;
int n;
ll k;

ll self_mul(ll a, ll b)
{
    a = a*b;
    if (a > mod) a%= mod;
    return a;
}

void mul(vector<int> a[], vector<int> b[])
{
    ll res[n][n];
    for(int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            res[i][j] = 0;
            for(int k = 0; k < n; k++)
            {
                res[i][j] += self_mul(a[i][k], b[k][j]);
                if(res[i][j] > mod) res[i][j]%= mod;
            }
        }
    }
    fo(i,0,n) fo(j,0,n) a[i][j] = res[i][j];
}

void pow(vector<int> mat[], ll x)
{
    if(x == 1) return;
    vector<int>res[n];
    fo(i,0,n) fo(j,0,n) res[i].pb(mat[i][j]);
    mul(mat,mat);
    pow(mat, x/2);
    if(x&1) mul(mat,res);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    vector<int> arr[n];
    fo(i,0,n)
    {
        fo(j,0,n)
        {
            int xx;
            cin >> xx;
            arr[i].pb(xx);
        }
    }
    pow(arr, k);
    ll res = 0;
    fo(i,0,n) fo(j,0,n) {res+=arr[i][j]; res%=mod;}
    cout << res <<endl;

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main(){

  ll n,k,q;
  cin>>n>>k>>q;
  map<ll,ll> m;
  for(ll i=1;i<=q;i++)
  {
    ll x; cin>>x; m[x]++;
  }
  for(ll i=1;i<=n;i++)
  {
    if(k-q+m[i]>0)
      cout<<"Yes";
    else
      cout<<"No";
      cout<<endl;
  }
   return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long gcd(long long a, long long b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

long long lcm(long long a, long long b)
{
	return a * b / gcd(a, b);
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

int main()
{
	long long x;
	cin >> x;
	long year = 0;
	long long n = 100;
	while (x > n)
	{
		year++;
		n *= 1.01;
	}
	cout << year;
}



Measured memory_bytes: 34220
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; ++i) {
		if (i + 1 == n || a[i + 1] <= i + 1) {
			int up = a[i] - (i + 1);
			int right = 0;
			while (i + right + 1 < n && a[i + right + 1] >= i + 1) ++right;
			int r = !(right & 1);
			int u = !(up & 1);
			int w = !(r & u);
			printf(w ? "First\n" : "Second\n");
			break;
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll MOD=1e9+7;

int main(){
	int N,M;
	cin>>N>>M;
	vector<int> A(N,0);
	rep(i,N)cin>>A[i];
	sort(A.begin(),A.end());
	
	vector<pair<int,int>>D(M);
	
	rep(i,M){
		int b,c;
		cin>>b>>c;
		D[i]=make_pair(c,b);
	}
	sort(D.begin(),D.end(),greater<pair<int,int>>());
	
	vector<int> E(N,0);
	int nE=0;
	int ni=0;
	int np=0;
	while(nE<N && ni<M){
			E[nE]=D[ni].first;
			nE++;
			np++;
		if(np==D[ni].second){
			ni++;
			np=0;
		}
	}
	ll ans=0;
	rep(i,N){
		int z=max(A[i],E[i]);
		ans=ans+(ll)z;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1920
#include <iostream> 
#include <math.h> 
#include <iomanip> 
using namespace std;  
  
int main()  
{  
int input1,input2,sum,i;
cin >> input1 >> input2;
int a=input1;
int b=input2;
int c=0;
for(i=1;i<=1;i++)
{sum=input1+input2;
for(int i=1;sum!=0;i++)
{sum=sum/10;
c=c+1;}
cout << c << endl;
c=0;
}
for(int i=1;i<=1000;i++)
{cin >> input1 >> input2;
if(a==input1 && b==input2)
{break;}
sum=input1+input2;
for(i=1;sum!=0;i++)
{sum=sum/10;
c=c+1;}
cout << c << endl;
a=input1;
b=input2;
c=0;
}
} 


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

int main(){
  string s; cin >> s;
  bool flag = true;
  
  int n = s.size();
  int cp;
  int ccount = 0;

  for(int i = 2; i < n-1; i++){
    if(s[i] == 'C') {
      cp = i;
      ccount++;
    }
  }


  if(ccount != 1) flag = false;
  for(int i = 0; i < n && flag; i++){
    if(i == 0){
      if(s[i] != 'A') flag = false;
    }

    else if(i != cp){
      if(isupper(s[i])) flag = false;
    }
  }

  

  if(flag) cout << "AC" << endl;
  else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int S{};
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        S+=a;
    }
    cout<<S<<endl;
    return 0;
}



Measured memory_bytes: 3100
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)

using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
    Ryuga;
    
    

    ll n,k;
    cin>>n>>k;
    ll ar[n+1];
    memset(ar,0,sizeof ar);
    rep(i,0,k)
    {
        ll d;
        cin>>d;
        rep(i,0,d)
        {
            ll ele;
            cin>>ele;
            ar[ele]++;
        }
    }
    ll c=0;
    rep(i,1,n+1)
    {
        if(ar[i]==0)
            c++;
    }

    cout<<c<<endl;
    
}//Goodbye...

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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO;
	
	ll n, m, k;
	cin >> n >> m >> k;

	vector<ll> d1(n+1), d2(m+1);
	d1[0] = d2[0] = 0;
	for (int i = 1; i <= n; ++i) {
		ll x; cin >> x;
		d1[i] = d1[i-1] + x;
	}
	for (int i = 1; i <= m; ++i) {
		ll x; cin >> x;
		d2[i] = d2[i-1] + x;
	}
	
	ll ans= 0, j = 0;
	
	for (int i = 0; i < n+1; ++i) {
		ll current = k - d1[i];
		j = 0;
		if (current < 0) 
			break;
		ll low = 1, high = m;
		while (low <= high) {
			ll mid = low + (high - low)/2;
			if (d2[mid] <= current) {
				low = mid + 1;
				j = mid;
			}
			else {
				high = mid -1;
			}
		}
		ans = max(ans, i + j);
	}
	cout << ans;		
		
	
}


Measured memory_bytes: 6348
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
ll a[202020];
int main() {
    cin>>n;
    REP(i, 0, n) cin>>a[i];

    ll crash=0, cur=1;
    REP(i, 0, n){
        if(a[i]==cur){
            crash++;
            cur++;
        }
    }
    if(crash==0) cout<<-1<<endl;
    else cout<<n-crash<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n;
    double A[100];
    cin>>n;
    rep(i,n) cin>>A[i];
    double ans=0;
    sort(A,A+n,greater<int>());
    rep(i,n) ans+=1/A[i];
    ans=1/ans;
    cout<<setprecision(9)<<ans;
}

Measured memory_bytes: 256
def insertionSort(A, N):
    for i in range(1, N):
        print(' '.join(map(lambda x: str(x), A)))
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
    return A

N = int(input())
A = list(map(int, input().split()))
A = insertionSort(A, N)

print(' '.join(map(lambda x: str(x), A)))



Measured memory_bytes: 5600
#include <iostream>
#include "cstdio"
#include <string>
#include <vector>

#define NMAX 100
using namespace std;

int main()
{
    int N,K,ans,D[10] = {};
    cin >> N >> K;
    for (int i = 0; i < K; ++i)
    {
        int a;
        cin >> a;
        D[a]++;
    }
    ans = N;
    while(true)
    {
        int s = 1, ss = ans;
        while(ss)
        {
            if(D[ss%10] == 1)
            {
                s = 0;
                break;
            }
            ss /= 10;
        }
        if(s == 1)
        {
            cout << ans <<"\n";
            break;
        }
        ans++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i,b,n) for(ll i=b;i<(ll)n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it,o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;

//ハマったらチェックリスト見ろ!!
//
template<typename Integer>
Integer GCD(Integer a, Integer b){
    if(!b)return a;
    else return GCD(b,a%b);
}

const ll MOD = 1e9+7;

ll modpow(ll x, ll y, ll m){
    if(y==0) return 1;
    ll res = modpow(x,y/2,m);
    return res * res % m * (y&1 ? x : 1) % m;
}

ll modInverse(ll a, ll p) {
    return modpow(a, p-2, p)%MOD;
}

ll prime[100000*2+1];
ll getPrime(ll i){
    if(prime[i])return prime[i];
    if(i == 0)return prime[i] = 1;
    return prime[i] = (i * getPrime(i-1)) %MOD;
}

ll nck_mod(ll n, ll k, ll p) {
    ll numerator = (getPrime(n) * modInverse(getPrime(n-k), MOD))%MOD;
    ll denominator = getPrime(k);
    return ( numerator* modInverse(denominator,p) ) % p;
}


int main(){
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    ll res = 0;
    rep(h, H - A){
        ll n = h + (B-1);
        ll k = h;
        ll tmp = nck_mod(n, k, MOD);
        tmp = (tmp + MOD) %MOD;
        tmp = (tmp * nck_mod(W-B -1 + H - h-1, H-h-1, MOD)) %MOD;
        res += tmp;
        res %=MOD;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll k,a,b;

void input(){
    cin >> k >> a >> b;    
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    ll ans = 1;
    bool flg = false;
    if ((b-a)>=2) flg=true;
    if(flg){
        for(ll i=0;i<k;i++){
            if (ans>=a && (i+2)<=k){
                ans += (b-a);
                i++;
            }
            else ans++;
        }
    }
    else ans+=k;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//115B
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n=0, ans=0;
    cin >> n;
    vector<int>L(n,0);
    rep(i, n) cin >> L[i];
    sort(L.begin(), L.end());
    ans = accumulate(L.begin(), L.end(), -L.back()/2); //第3引数:初期値
    cout << ans << endl;
  
}

Measured memory_bytes: 256
import scala.math.{min,max}

object Main {
  val sc = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    val w, k = (1 to 10).map(_ => sc.nextInt).sorted.reverse.take(3).sum
    println(Seq(w, k).mkString(" ")) 
  }
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

vector<vector<int>>to(200010);
vector<long long> dist(200010,INF);
bool reached[200010]={};
queue<int>q;
void bfs(int now,int before,long long cnt){
    
    return;

}



int main(){

    long long n,m;
    cin>>n>>m;
    
    rep(i,m){
    int a,b;
    cin>>a>>b;
    a--,b--;
    to[a].push_back(b);
    to[b].push_back(a);

    }
    int nums[200010];
    q.push(0);
    dist[0]=0;
    reached[0]=true;
    while(!q.empty()){
        int now=q.front();q.pop();

        for(auto ne:to[now]){
        if(reached[ne])continue;
        dist[ne]=min(dist[now]+1,dist[ne]);
        nums[ne]=now;
        reached[ne]=true;
        q.push(ne);
        }
    }

    rep(i,n){
        if(dist[i]==INF){
            cout<<"No"<<endl;
            return 0;
        }
    }
    
    cout<<"Yes"<<endl;
    rep2(i,n-1){
        cout<<nums[i]+1<<endl;
    }
    
    
    return 0;

}
/*

*/


Measured memory_bytes: 14352
#!/usr/bin/env python3
from itertools import combinations

H, W, K = map(int, input().split())
G_ = []

for i in range(H):
    G_.append(list(input()))

count = 0
g = 0
for cr in range(2**H):
    G = [G_[r][:] for r in range(H)]
    # row
    for r in range(H):
        if cr & (1 << r):
            G[r] = list('R' * W)
    # col
    for cc in range(2**W):
        G0 = [G[r][:] for r in range(H)]
        for c in range(W):
            if cc & (1 << c):
                for r in range(H):
                    G0[r][c] = 'R'
        b = sum(r.count("#") for r in G0)
        if b == K:
            count += 1
        g+=1
print(count)



Measured memory_bytes: 9136
import java.io.*;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data = br.readLine().split(" ");
    BigDecimal a = new BigDecimal(data[0]);
    BigDecimal b = new BigDecimal(data[1]);
    BigDecimal c = new BigDecimal(data[2]);
    
    String result = sqrt(a, 50).add(sqrt(b, 50)).compareTo(sqrt(c, 50))< 0 ? "Yes" : "No";
    
    System.out.println(result);
  }
  
  
  private static long longSqrt (long a) {
    long b = 2*(long)Math.sqrt(a);
    while (true){
      if (b*b >= 4*a && (b-1)*(b-1) >= 4*a){
        b--;
      } else if(b*b <= 4*a && (b+1)*(b+1) <= 4*a){
        b++;
      } else {
        break;
      }
    }
    return b;
  }
  
  public static BigDecimal sqrt(BigDecimal a, int scale){
    BigDecimal x = new BigDecimal(
            Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
    if(scale < 17) return x;
    
    BigDecimal b2 = new BigDecimal(2);
    for(int tempScale = 16; tempScale < scale; tempScale *= 2){
      x = x.subtract(
              x.multiply(x).subtract(a).divide(
                      x.multiply(b2), scale, RoundingMode.HALF_EVEN));
    }
    return x;
  }
}

Measured memory_bytes: 23380