akhauriyash/Code-Regression huggingface dataset:
s=input()
ans=0
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    ans+=1
    if s[i]=='0':
      s=s[:i]+'1'+s[i+1:]
    else:
      s=s[:i]+'0'+s[i+1:]
print(ans)

Measured memory_bytes: 3436
#include <iostream>
#include <vector>
#include <algorithm>

int T,N,K,pos[100000],diff[100000];

int main(){
  std::cin>>T;
  for(int t=0;t<T;++t){
    std::cin>>N>>K;
    for(int i=0;i<N;++i)
      std::cin>>pos[i];
    for(int i=0;i+1<N;++i)
      diff[i] = pos[i+1]-pos[i];
    std::sort(diff,diff+N-1);
    int len = 0;
    for(int i=0;i<N-1-(K-1);++i)
      len += diff[i];
    
    std::cout<<len<<std::endl;
  }

  return 0;
}   

Measured memory_bytes: 3824
a=int(input())
b=int(input())
if a==1 and b==2:
    print('3')
elif a==1 and b==3:
    print('2')
elif a==2 and b==1:
    print('3')
elif a==2 and b==3:
    print('1')
elif a==3 and b==1:
    print('2')
else:
    print('1')

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

int main(){
	int N;
  	int a[110];
  	cin >> N;
  	for(int i = 0; i<N;i++) cin >> a[i];
  	
  	sort(a,a+N,greater<int>());
  	
  	int Alice = 0;
  	int Bob = 0;
  	for(int i = 0; i< N;i++){
    	if(i % 2 == 0){
        	Alice += a[i];
        }else{
        	Bob += a[i];
        }
    
    }

	cout << Alice - Bob << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 5e-7
using namespace std;
int n,k;
double x[62],y[62],c[62];
queue<tuple<double,double,double> > q;
double xp,yp,ap,lb;
double opt(double xx,double yy,double aa){
	vector<double> aux;
	for(int i=1;i<=n;i++){
		aux.push_back(c[i]*hypot(max(abs(xx-x[i])-aa,0.00),max(abs(yy-y[i])-aa,0.00)));
	}
	nth_element(aux.begin(),aux.begin()+k-1,aux.end());
	return aux[k-1];
}
double rel(double xx,double yy){
	vector<double> aux;
	for(int i=1;i<=n;i++){
		aux.push_back(c[i]*hypot(xx-x[i],yy-y[i]));
	}
	nth_element(aux.begin(),aux.begin()+k-1,aux.end());
	return aux[k-1];
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>y[i]>>c[i];
	q.emplace(0.0,0.0,1000.0);
	double res=1e9;
	while(q.size()){
		tie(xp,yp,ap)=q.front();
		q.pop();
		lb=opt(xp,yp,ap);
		if((res-lb)<=(eps*max(1.0,lb)))
			continue;
		res=min(res,rel(xp,yp));
		for(double dx:{-0.5,0.5}){
			for(double dy:{-0.5,0.5}){
				q.emplace(xp+dx*ap,yp+dy*ap,ap/2.00);
			}
		}
	}
	cout<<fixed<<setprecision(15)<<res<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<cstdlib>

using namespace std;

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

   int ans = 0;

   for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
         if (abs(a[i] - a[j]) > ans) ans = abs(a[i] - a[j]);         
      }
   }

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


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

int main(){

    int n;
    cin >> n;

    vector<int> l(n);
    int su=0;

    rep(i,n){
        cin >> l[i];
        su+=l[i];
    }

    auto lng=max_element(l.begin(),l.end());

    if(su-*lng>*lng){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(int argc, char const *argv[]) {
  int A;
  cin >> A;
  if (A == 3 || A == 5 || A == 7) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int l;
vector<E>e;
int a[200];
signed main() {
	cin >> l;
	int n = 1, m = 0, sum = 0;
	while (2 * sum + 1 < l) {
		e.push_back(E{ n,n + 1,0 });
		e.push_back(E{ n,n + 1,sum + 1 });
		n++;
		sum = 2 * sum + 1;
		a[n] = sum;
	}
	while (sum < l - 1) {
		int k = sum + 1, i = 0;
		while (a[i + 1] + k < l) {
			i++;
		}
		e.push_back(E{ i,n, k });
		sum = a[i] + k;
	}
	cout << n << " " << e.size() << endl;
	for (int i = 0; i < e.size(); i++) {
		cout << e[i].from << " " << e[i].to << " " << e[i].cost << endl;
	}
}

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


int N,M,a,b;
vector<bool> visited(8,false);
long long res=0;
vector<vector<int>> v(8,vector<int> (8,0));


void dfs(int i){
    
    bool f = true;
    visited[i] = true;
    for (int j=0;j<N;j++){
        if (visited[j]==false && v[i][j]==1) {
            dfs(j);
            visited[j]=false;
        }
    }
    for (int k=0;k<N;k++){
        if (visited[k] ==false) f = false; 
    }
    if(f) res += 1;
    
}

int main(){
    cin >> N >> M;
    
    for (int i=0;i<M;i++){
        cin >> a >> b;
        v[a-1][b-1] = v[b-1][a-1] = 1;
        }

    dfs(0);


    cout << res << endl;
    }

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int kaibun(char s[], int n)
{
  int i;
  for (i = 0; i < n/2; i++)
    if (s[i] != s[n-i-1])
      return 0;
  return 1;
}
  

int main()
{
  char s[100];
  int n, i;
  
  scanf("%s", s);
  
  n = strlen(s);
  
  if (kaibun(s,n)+kaibun(s,n/2)+kaibun(s+n/2+1,n/2) == 3)
    puts("Yes");
  else
    puts("No");
  
  return 0;
}

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

typedef long long ll;
const ll INF = 1e18L;
const int MOD = 1e9 + 7;
int a[21][21];

int main() {
    int n;
    cin >> n;
    vector<int> dp (1 << n);
    for (int i = 0; i < n; i++) 
        for (int j = 0; j < n; j++) 
            cin >> a[i][j];

    dp[0] = 1;
    for (int i = 1; i < (1 << n); i++) {
        int c = __builtin_popcount(i) - 1; // count the number of 1's in mask i.
        for (int j = 0; j < n; j++) {
            if (a[c][j] && (i & (1 << j)))
                dp[i] = (dp[i] + dp[i ^ (1 << j)]) % MOD; // i ^ (1 << j) flips the bit at j.
        }
    }
    cout << dp[(1 << n) - 1];
}


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

int main() {
  string S; cin >> S; //Sを入力
  int N; N = S.size(); 
  
  vector<string> color(N); //Sを一文字ずつ配列colorに入れる
  for( int i = 0; i < N; i++ ) {
    color.at(i) = S.at(i);
  }
  
  vector<string> sample(N); //比べる配列sample 010101…　を作る
  for( int i = 0; i < N; i++ ) {
    if( i % 2 == 0 )
      sample.at(i) = "0";
    else
      sample.at(i) = "1";
  }
  
  int correct = 0;
  int answer = 0;
  for( int i = 0; i < N; i++ ) { //colorとsampleの一致する要素の個数がcorrect
    if( color.at(i) == sample.at(i) )
      correct++;
  }
  
  if( correct <= N / 2 ) //correctが半分以下だとそれを変換
    answer = correct;
  else                   //correctが半分より多いと間違ってる方を変換
    answer = N - correct;
  cout << answer << endl;
}

Measured memory_bytes: 11264
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=100000+10,maxtot=maxn*25;
ll ans[maxn],cnt[maxn],a[maxn],b[maxn],tree[maxtot],p[maxn][70][2];
int root[maxn],left[maxtot],right[maxtot],rk[maxn];
int len[maxn];
int i,j,k,l,t,n,m,tot,top,num;
int newnode(int x){
	tree[++tot]=tree[x];
	left[tot]=left[x];
	right[tot]=right[x];
	return tot;
}
void insert(int &x,int l,int r,int a,int b){
	x=newnode(x);
	tree[x]=b;
	if (l==r) return;
	int mid=(l+r)/2;
	if (a<=mid) insert(left[x],l,mid,a,b);else insert(right[x],mid+1,r,a,b);
}
int query(int x,int l,int r,int a,int b){
	if (!x||a>b) return 0;
	if (l==a&&r==b) return tree[x];
	int mid=(l+r)/2;
	if (b<=mid) return query(left[x],l,mid,a,b);
	else if (a>mid) return query(right[x],mid+1,r,a,b);
	else return max(query(left[x],l,mid,a,mid),query(right[x],mid+1,r,mid+1,b));
}
void solve(int x,ll l){
	int t=upper_bound(b+1,b+num+1,l)-b-1;
	int y=query(root[x-1],1,num,1,t);
	if (!y){
		if (l>=n){
			p[i][++top][0]=0;
			p[i][top][1]=l/n;
			l%=n;
		}
		p[i][++top][0]=l;
		return;
	}
	p[i][++top][0]=y;
	p[i][top][1]=l/a[y];
	solve(y,l%a[y]);
}
int main(){
	scanf("%d%d",&n,&m);
	a[0]=n;
	fo(i,1,m) scanf("%lld",&a[i]),b[i]=a[i];
	//b[++m]=n;
	sort(b+1,b+m+1);
	num=unique(b+1,b+m+1)-b-1;
	b[++num]=2000000000000000000;
	fo(i,1,m) rk[i]=lower_bound(b+1,b+num+1,a[i])-b;
	fo(i,1,m){
		root[i]=root[i-1];
		insert(root[i],1,num,rk[i],i);
	}
	fo(i,1,m){
		top=0;
		solve(i,a[i]);
		len[i]=top;
	}
	cnt[m]=1;
	fd(i,m,1){
		fo(j,1,len[i]-1)
			cnt[p[i][j][0]]+=cnt[i]*p[i][j][1];
		ans[p[i][len[i]][0]]+=cnt[i];
	}
	ans[n]+=cnt[0];
	fd(i,n,1) ans[i]+=ans[i+1];
	fo(i,1,n) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 148224
package main

import (
	"fmt"
)

func main() {
	var a, b, c, k int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &k)
	if k <= a {
		fmt.Printf("%d\n", k)
	} else if k <= a+b {
		fmt.Printf("%d\n", a)
	} else {
		fmt.Printf("%d\n", a-(k-a-b))
	}
}


Measured memory_bytes: 1816
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i=0; i<3; i++){
            a[i] = sc.nextInt();
        }
        int cost = 10000;
        int pcost = 0;
        
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(i != j){
                    for(int k=0; k<3; k++){
                        if(k != i && k != j){
                            pcost = Math.abs(a[j]-a[i]) + Math.abs(a[k]-a[j]);
                            if(pcost < cost){
                                cost = pcost;
                            }
                        }
                    }
                }
            }
        }
        System.out.println(cost);
    }
}

Measured memory_bytes: 22868
#include<stdio.h>
#include<math.h>

int isPrime(int);

int main()
{
  int a[10000];
  int n=0,i,j,x;

  scanf("%d",&x);
  for(i = 0;i < x;i++){
    scanf("%d",&a[i]);
  }

  for(i = 0;i < x;i++){
    if(isPrime(a[i]) == 1) n++;
  }

  printf("%d\n",n);

  return 0;
}

int isPrime(int x)
{
  int count=0,i=3;
  if(x == 2) return 1;
  else if(x < 2 || x % 2 == 0) return 0;
  
  else{ 
    while(i <= sqrt(x)){
      if(x % i == 0) return 0;
      i = i+2;
    }
  }
  return 1;
}

Measured memory_bytes: 632
#include <stdio.h>

int main() {
  int N,X;
  int mg[101];
  int i,count = 0;
  int min_d, cal = 0;

  scanf("%d %d", &N, &X);

  for(i = 0; i < N; i++){
    scanf("%d", &mg[i]);
    // printf("%d\n", mg[i]);
  }

  min_d = mg[0];

  for(i = 1; i < N; i++){
    if(min_d > mg[i]){
      min_d = mg[i];
    }
  }

  for(i = 0; i < N; i++){
    cal += mg[i];
    count++;
  }

  while(1){
    cal += min_d;
    if(cal <= X){
      count++;
    } else {
      break;
    }
  }

  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 128
import itertools

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

L = [i for i in range(1, N+1)]
a = 0
b = 0

#順列作成
L_list = list(itertools.permutations(L))

for i in range(len(L_list)):
  if list(L_list[i]) == P:
    a = i+1

for i in range(len(L_list)):
  if list(L_list[i]) == Q:
    b = i+1
#  else:
#    continue

print(abs(a-b))

Measured memory_bytes: 8052
import sys
def input():
	return sys.stdin.readline()[:-1]
d = int(input())
c = list(map(int, input().split()))
C = sum(c)
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

def score(t):
	res = 0
	minus = 0
	last = [0 for _ in range(26)]
	for i, x in enumerate(t):
		minus += C - c[x-1] * (i - last[x-1] + 1)
		res -= minus
		res += s[i][x-1]
		last[x-1] = i+1
		print(res)
	return

score(t)

Measured memory_bytes: 68048
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std; 
int main()
{
string s;
cin>>s;
if(s[0]==s[1] && s[1]==s[2])
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }
// const ll sz = 2e6 + 5;
// vector<ll> fac(sz, 1);

// * ALways PASS arrays, strings etc to functions BY REFERENCE

int main() {
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    int t = 1;
    // cin >> t;
    
    while(t--) {
        string s;
        cin >> s;
        
        if (s == "RRR")
            cout << 3 << endl;
        else if (s == "RRS" || s == "SRR")
            cout << 2 << endl;
        else if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR")
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
    
	return 0;
}


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

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    
    if(A<B&&C<B&&A<C)
        cout<<"Yes"<<endl;
    else if(B<A&&C<A&&B<C)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    ll now = 1;
    ll ans = 0;
    rep(i,n){
        ll a;
        cin >> a;
        if(now == a){
            ++ans;
            ++now;
        }
    }
    if(!ans) cout << -1 << endl;
    else cout << n - ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
struct RollingHash{
    
    vector <int> hash, base_pow;
    int base = 1009, mod = 1e+7;
    
    RollingHash(string S = "",/*vector <int> S*/ int basetmp = -1, int modtmp = -1){
        if(modtmp != -1) mod = modtmp;
        if(basetmp != -1) base = basetmp;
        //cout<<mod<<' '<<base<<endl;
        //////
        int n = S.size();
        vector <int> z(n);
        rep(i,n) z[i] = S[i];
        hash.resize(n+1); base_pow.resize(n+1);
        hash[0] = 0, base_pow[0] = 1;
        for(int i=1;i<=z.size();i++){
            hash[i] = (hash[i-1] * base + z[i-1]) % mod;
            
            base_pow[i] = base_pow[i-1] * base % mod;
        }
        
    }
    int between(int a, int b){
        return (mod + hash[b] - hash[a] * base_pow[b-a] % mod) % mod;
    }
};

signed main(void){
    int n,m; cin>>n>>m;
    string s; cin>>s;
    RollingHash roli1(s), roli2(s, 1007, 1000000009), roli3(s, 1011, 1000000181);
    int l=0, r = 0;
    map <tuple <int,int,int> ,int> ma;
    int ans = 0;
    rep(i,m){
        string tmp; cin>>tmp;
        if(tmp == "R++") r++;
        if(tmp == "L++") l++;
        if(tmp == "R--") r--;
        if(tmp == "L--") l--;
        ma[make_tuple(roli1.between(l, r+1),roli2.between(l, r+1), roli3.between(l, r+1))]++;

    }
    cout<<ma.size()<<endl;
}



Measured memory_bytes: 40592
N = int(input())
S = input()

al = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
Slist = list(S)

i = 0
j = 0

while i < len(Slist):
    while j < len(al):
        if Slist[i] == al[j]:
            if j+N > len(al)-1:
                Slist[i] = al[j+N-26]
                break
            Slist[i] = al[j+N]
            break
        j += 1
    i += 1
    j = 0

Sprint = ''.join(Slist)

print(Sprint)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2];
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
const int N = 1000000 + 10;
const int mod = 1e9 + 7;
using namespace std;

ll f[N], s[N];
int n;
int main()
{
  scanf("%d",&n);
  f[1]=n; f[2]=1ll*n*n%mod; 
  s[1]=f[1]; s[2]=(f[1]+f[2])%mod;
  for(int i=3; i<=n; ++i)
  {
    f[i] = f[i-1];
	f[i] += s[i-3];
	f[i] %= mod;
	f[i] += 1ll*(n-1)*(n-1)%mod;
	f[i] += n-i+2;
	f[i] %= mod;
	s[i] = s[i-1]+f[i];
    s[i] %= mod;
  }
  printf("%lld\n",f[n]);




}


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

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

using namespace std;

#define AND 0
#define OR  1

pair<bool,vector<vector<int>>> solve(int n,vector<int> s,vector<int> t,vector<int> u,vector<int> v){
	vector<vector<int>> res(n,vector<int>(n,-1));

	vector<int> R,C;
	int s0=0,s1=0,t0=0,t1=0;
	rep(i,n){
		if(s[i]==AND && u[i]==1){
			rep(j,n) res[i][j]=1;
			s1++;
		}
		else if(s[i]==OR && u[i]==0){
			rep(j,n) res[i][j]=0;
			s0++;
		}
		else R.emplace_back(i);
	}
	rep(j,n){
		if(t[j]==AND && v[j]==1){
			rep(i,n) res[i][j]=1;
			t1++;
		}
		else if(t[j]==OR && v[j]==0){
			rep(i,n) res[i][j]=0;
			t0++;
		}
		else C.emplace_back(j);
	}

	if(R.size()==1){
		int x=u[R[0]];
		rep(j,C.size()){
			if((v[C[j]]==0 && s0>0) || (v[C[j]]==1 && s1>0)) res[R[0]][C[j]]=x;
			else                                             res[R[0]][C[j]]=v[C[j]];
		}
	}
	else if(C.size()==1){
		int x=v[C[0]];
		rep(i,R.size()){
			if((u[R[i]]==0 && t0>0) || (u[R[i]]==1 && t1>0)) res[R[i]][C[0]]=x;
			else                                             res[R[i]][C[0]]=u[R[i]];
		}
	}
	else if(R.size()>=2 && C.size()>=2){
		rep(i,R.size()) rep(j,C.size()) res[R[i]][C[j]]=(i+j)%2;
	}

	// check
	rep(i,n){
		int z;
		if(s[i]==AND){
			z=1;
			rep(j,n) z&=res[i][j];
		}
		else{
			z=0;
			rep(j,n) z|=res[i][j];
		}
		if(z!=u[i]) return {false,{}};
	}
	rep(j,n){
		int z;
		if(t[j]==AND){
			z=1;
			rep(i,n) z&=res[i][j];
		}
		else{
			z=0;
			rep(i,n) z|=res[i][j];
		}
		if(z!=v[j]) return {false,{}};
	}
	return {true,res};
}

int main(){
	int n; scanf("%d",&n);
	vector<int> s(n),t(n);
	vector<unsigned long long> u(n),v(n);
	rep(i,n) scanf("%d",&s[i]);
	rep(j,n) scanf("%d",&t[j]);
	rep(i,n) scanf("%llu",&u[i]);
	rep(j,n) scanf("%llu",&v[j]);

	unsigned long long ans[500][500]={};
	rep(b,64){
		vector<int> u2(n),v2(n);
		rep(i,n){
			u2[i]=u[i]>>b&1;
			v2[i]=v[i]>>b&1;
		}
		auto tmp=solve(n,s,t,u2,v2);
		if(!tmp.first) return puts("-1"),0;
		rep(i,n) rep(j,n) if(tmp.second[i][j]==1) ans[i][j]+=1ULL<<b;
	}
	rep(i,n) rep(j,n) printf("%llu%c",ans[i][j],j<n-1?' ':'\n');

	return 0;
}


Measured memory_bytes: 8644
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int W = sc.nextInt();
    long[] w = new long[n+1];
    int[] v = new int[n+1];
    int maxV = 0;
    long INF = (long)Math.pow(10,15);
    int sum = 0;
    for(int i=1;i<=n;i++){
      w[i]=sc.nextLong();
      v[i]=sc.nextInt();
      maxV = Math.max(maxV,v[i]);
      sum += v[i];
    }
    long[] dp = new long[n*maxV+1];
    for(int i = 0;i <= n*maxV;i++)dp[i]=INF;
    dp[0]=0;
    for(int i=0;i<=n;i++){
      for(int j=sum;j>=v[i];j--){
        dp[j]=Math.min(dp[j],dp[j-v[i]]+w[i]);
      }
    }
    int num = 0;
    for(int i=1;i<=n*maxV;i++){
      if(dp[i]<=W)num=i;
    }
    System.out.println(num);
  }
}

Measured memory_bytes: 22484
#include <iostream>
#define inf 1000000000

using namespace std;

const int W = 15, H = 20;
char map[W][H];
int sx, sy;
const int vx[] = {1, 1, 0, -1, -1, -1, 0, 1}, vy[] = {0, -1, -1, -1, 0, 1, 1, 1};

int dfs(int x, int y)
{
	int nx, ny;
	int ret = inf;
	if(y >= H-2) return 0;
	
	for(int d = 0; d < 8; d++){
		nx = x + vx[d], ny = y + vy[d];
		if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
		if(map[nx][ny] == '.') continue;
		while(1){
			nx += vx[d], ny += vy[d];
			if(ny >= H-1){ ret = 0; break;}
			if(nx < 0 || nx >= W || ny < 0) break;
			if(map[nx][ny] == '.'){
				for(int k = 1; x + k*vx[d] != nx || y + k*vy[d] != ny; k++) map[x + k*vx[d]][y + k*vy[d]] = '.';
				ret = min(ret, dfs(nx, ny));
				for(int k = 1; x + k*vx[d] != nx || y + k*vy[d] != ny; k++) map[x + k*vx[d]][y + k*vy[d]] = 'X';
				break;
			}
		}
	}
	return ret + 1;
}

int main(void)
{
	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			cin >> map[x][y];
			if(map[x][y] == 'O'){
				sx = x, sy = y;
				map[x][y] = '.';
			}
		}
	}
	for(int x = 0; x < W; x++) map[x][H-1] = '.';
	
	int ans = dfs(sx, sy);
	if(ans >= inf) ans = -1;
	cout << ans << endl;
	
	return 0;
}

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

int main(){
    int N;
    cin >> N;

    int A[N+1];
    int B[N];

    for (int i = 0; i < N+1; i++){
        cin >> A[i];
    }
    for (int j = 0; j < N; j++){
        cin >> B[j];
    }

    long long Bt = 0;
    int H = 0;

    for (int k = 0; k < N; k++){
        if (A[k] > H){
            Bt += H;
            A[k] -= H;
        } else {
            Bt += A[k];
            A[k] = 0;
        }
        if (B[k] > A[k]){
            H = B[k] - A[k];
            Bt += A[k];
            if (k == N-1){
                if (A[k+1] > H){
                    Bt += H;
                } else {
                    Bt += A[k+1];
                }
            }
        } else {
            H = 0;
            Bt += B[k];
        }
    }

    cout << Bt << endl;

    return 0;
}

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

vector<int>E[2000];
vector<P>v;
int d[2000];

void bfs(int v) {
	queue<P>que;
	d[v] = 0; que.push(P(0, v));
	while (!que.empty()) {
		P p = que.front(); que.pop();
		for (int u : E[p.second]) {
			if (d[u] > p.first + 1) {
				d[u] = p.first + 1;
				que.push(P(d[u], u));
			}
		}
	}
}
int main() {
	int n, k; scanf("%d%d", &n, &k);
	rep(i, n - 1) {
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		E[a].push_back(b); E[b].push_back(a);
		v.push_back(P(a, b));
	}
	int Min = INT_MAX;
	if (k & 1) {
		rep(i, n - 1) {
			memset(d, 0x3f, sizeof(d));
			bfs(v[i].first); bfs(v[i].second);
			int cnt = 0;
			rep(i, n) {
				if (d[i] > (k - 1) / 2)cnt++;
			}
			Min = min(Min, cnt);
		}
	}
	else {
		rep(i, n) {
			memset(d, 0x3f, sizeof(d));
			bfs(i);
			int cnt = 0;
			rep(i, n) {
				if (d[i] > k / 2)cnt++;
			}
			Min = min(Min, cnt);
		}
	}
	printf("%d\n", Min);
}

Measured memory_bytes: 384
n,m = map(int,(input().split()))
a = []
s = []
for i in range(m):
    s.append(0)

for i in range(n):
    k = [int(i) for i in input().split()]
    k.append(sum(k))
    a.append(k)
    for j in range(m):
        s[j] += k[j]

s.append(sum(s))
a.append(s)

for j in a:
    print(' '.join(map(str, j)))

Measured memory_bytes: 7728
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
template<class T,class C> T max(T a,C b){ return ((a)>(T)(b) ? (a) : (T)(b)); }
template<class T,class C> T min(T a,C b){ return ((a)<(T)(b) ? (a) : (T)(b)); }
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0,x,tmp=0;
  int a[200010]={0};
  string s;
  
  cin >> n >> x;
  result=1;
  rep(i,n){
    cin >> a[i];
    tmp += a[i];
    if(tmp<=x) result++;
  }
  
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 4392
l = list(map(int, input().split()))
n5 = 0
n7 = 0
for i in range(3):
  if l[i] == 5:
    n5 += 1
  elif l[i] == 7:
    n7 += 1
print('YES' if n5 == 2 and n7 == 1 else 'NO')


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

int main(){
    int n;
    cin >> n;
    vector<int> num(n+1),a(n+1);
    rep(i,n) cin >> a[i+1];
    for(int i = n;i>=1;i--){
        int number = 0;
        for(int j = 2*i;j<=n;j+=i){
            number += num[j];
        }
        if(number%2 != a[i]) num[i] = 1;
    }
    int total = 0;
    for(int i = 1;i<=n;i++) total += num[i];
    cout << total << endl;
    for(int i = 1;i<=n;i++){
        if(num[i] == 1) cout << i << endl;
    }

}


Measured memory_bytes: 4716
from collections import deque

n, q = map(int, input().split())
alist = deque([])
endlist = []

for process in range(n):
    name, time = input().split()
    time = int(time)
    alist.append([name, time])

total = 0
while alist:
    curr = iter(alist)
    ob = next(curr)
    res = int(ob[1]) - q
    if res > 0:
        total += q
        ob[1] = res
        alist.append(ob)
        alist.popleft()
    else:
        total += q + res
        ob[1] = total
        endlist.append(ob)
        alist.popleft()

for x in endlist:
    print('{} {}'.format(x[0], x[1]))




Measured memory_bytes: 15104
# -*- coding: utf-8 -*-

import itertools

A, B, C, D = map(str, list(input()))

# 重複順列でオペランド組み合わせの全パターンを出す
op_list = list(itertools.product(["+", "-"], repeat=3))

for op in op_list:
    # evalで文字列を式にできる(これが出なかった…)
    if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
        print(A + op[0] + B + op[1] + C + op[2] + D + "=7")
        exit()

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int A,B;
    cin >> A >> B;

    cout << ((A <= 8 && B <= 8) ? "Yay!" : ":(");
    
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  cin>>s;
  if(sz(s)%2==1){
    COUT("No");
    return 0;
  }
  rep(i,sz(s)-1){
    if(s[i]=='h'&&s[i+1]=='i'){
      i++;
      continue;
    }
    COUT("No");
    return 0;
  }
  COUT("Yes");
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int,input().split()))

A = []
for i in range(1,N+1):
  if(B == []):
    break
  for b in B:
    if(1 <= b <= i):
      A.insert(b-1, b)
      B.remove(b)
    break

if(B == []):
  for a in A:
    print(a)
  exit()
print(-1)

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    if(a+c==2*b) cout<<"YES";
    else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
  
int const MAXN = 100;
int const MAXK = 100000;

int N, K;
int a[MAXN];
int dp[MAXK+1];

int main() {
  std::cin >> N >> K;
  for(int i = 0; i < N; ++i) std::cin >> a[i];

  for(int i = 0; i < a[0]; ++i) dp[i] = 0;
  for(int i = a[0]; i <= K; ++i) {
    dp[i] = 0;
    for(int j = 0; j < N && a[j] <= i; ++j) if(dp[i-a[j]]==0) {
      dp[i] = 1;
      break;
    }
  }
  if(dp[K] > 0) std::cout << "First" << std::endl;
  else std::cout << "Second" << std::endl;
  return 0;
}


Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	if a > b {
		a, b = b, a
	}
	if b > c {
		b, c = c, b
	}
	if a > b {
		a, b = b, a
	}
	fmt.Printf("%d %d %d\n", a, b, c)
	return
}




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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/
//累積和配列を作る( vi a(n) 及び vi s(n+1,0) はmain内で宣言、作成)
int n;
void ruisekiwa(vi &s, vi &a){
    for(int i = 0; i < n; i++){
        s[i+1] = s[i] + a[i];
    }
}
//a[L]からa[R-1]までの総和を返す
int sumLtoR(vi &s, int L, int R){
    return s[R] - s[L];
}
/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    cin >> n;
    vi a1(n); rep(i,n) cin >> a1[i];
    vi a2(n); rep(i,n) cin >> a2[i];
    vi s1(n+1, 0), s2(n+1,0);
    ruisekiwa(s1,a1);
    ruisekiwa(s2,a2);
    int ans = 0;
    rep(i,n){
        ans = max(ans,(sumLtoR(s1,0,i+1) + sumLtoR(s2,i,n)));
    }
    cout << ans << '\n';
}

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

struct S {
    int w, h, diag;
    S(int w, int h):w(w),h(h) {
        diag = h*h + w*w;
    }
    bool operator < (const S &s) const {
        if(diag < s.diag) return true;
        if(diag > s.diag) return false;
        return h < s.h;
    }
};

std::vector<S> vs;
int main() {
    vs.reserve(10005);
    int i, j;
    for(i = 1; i <= 200; ++i) for(j = i + 1; j <= 200; ++j) {
        vs.push_back(S(j, i));
    }
    std::sort(vs.begin(), vs.end());

    int h, w;
    while(std::cin >> h >> w, h != 0 && w != 0) {
        auto it = std::lower_bound(vs.begin(), vs.end(), S(w, h));
        std::cout << (*(it+1)).h << " " << (*(it + 1)).w << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3136
import sys


def solve(n):
    sum = n
    current_value = n
    for i in range(2, 11):
        if i%2 == 0:
            next_value = current_value * 2.0
        else:
            next_value = current_value / 3.0
        sum += next_value
        current_value = next_value
    return sum


if __name__ == '__main__':
    # ??????????????\?????¨???????????????
    for line in sys.stdin:
        n = float(line.strip())
        result = solve(n)
        print('{:.8f}'.format(result))

Measured memory_bytes: 7412
#include <iostream>
#include <queue>
#include <map>

using namespace std;

int solve(string s)
{
    map<string, bool> mem;
    queue<pair<string, int> > q;

    q.push(pair<string, int>(s, 0));
    mem[s] = true;

    while (!q.empty()) {
        pair<string, int> tmp;
        bool flag = true;

        tmp = q.front();
        q.pop();

        // Check
        for (int i = 1; i < tmp.first.size(); i++)
            if (tmp.first[0] != tmp.first[i]) {
                flag = false;
                break;
            }
        if (flag) 
            return tmp.second;

        for (int i = 0; i < tmp.first.size() - 1; i++) {
            if (tmp.first[i] != tmp.first[i + 1]) {
                string str = tmp.first;
                int num = (int)(tmp.first[i] + tmp.first[i + 1]);

                if (num == 217) 
                    str[i] = str[i + 1] = 'b';
                else if (num == 212) 
                    str[i] = str[i + 1] = 'g';
                else if (num == 201) 
                    str[i] = str[i + 1] = 'r';

                if (mem.count(str) == 0) {
                    q.push(pair<string, int>(str, tmp.second + 1));
                    mem[str] = true;
                }
            }
        }
    }
    return -1;
}

int main()
{
    string inp;

    while (cin >> inp, inp != "0") {
        int num = solve(inp);

        if (num >= 0)
            cout << num << endl;
        else 
            cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 2916
N,K,*A = map(int, open(0).read().split())
m = sum(A[:K])
n = sum(c if c>0 else 0 for c in A[K:])
ans = max(m+n,n)
for i in range(N-K):
  m -= A[i]
  m += A[i+K]
  if A[i]>0:
    n += A[i]
  if A[i+K]>0:
    n -= A[i+K]
  ans = max(ans,n+m,n)
print(ans)

Measured memory_bytes: 14092
// 2020-07-04 16:37:06
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  vector<int> a(n), dpl(n+1), dpr(n+1);
  rep(i, n) cin >> a[i];
  dpl[1] = a[0];
  dpr[n-1] = a[n-1];
  REP(i, 1, n) {
    dpl[i+1] = __gcd(dpl[i], a[i]);
    dpr[n-i-1] = __gcd(dpr[n-i], a[n-i-1]);
  }
  int ans = 0;
  chmax(ans, dpr[1]);
  chmax(ans, dpl[n-1]);
  REP(i, 1, n-1) {
    chmax(ans, __gcd(dpl[i], dpr[i+1]));
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4464
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define mp           make_pair
#define int          long long
#define uint         unsigned long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define repr(i,x,m)  for(int i=x;i>=m;i--)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define vs           vector<string>
#define pi           pair<int,int>
#define di           deque<int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define pqs          priority_queue<int,vi,greater<int> >
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define noob         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,0,n)
    cin>>a[i];
    sort(a,a+n);
   int sum=0;
   rep(i,0,k)
   sum+=a[i];
   cout<<sum;
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>
#include <complex>

using namespace std;


template<typename T>
void fillall(T& arr, const T& v) {
	arr = v;
}
template<typename T, size_t N, class U>
void fillall(T(& arr)[N], const U& v) {
	for (auto& r: arr)fillall(r, v);
}

char A[55];
char B[55];
char C[55];
const int64_t MOD = 1000000007;
int64_t func(int i, int p);
int64_t check(int i, char a, char b, char c, int p)
{
	if ((a + b) == c + p * 10) {
		return func(i, 0);
	}
	if ((a + b + 1) == c + p * 10) {
		return func(i, 1);
	}
	return 0;
}
int64_t dp[55][2];
int64_t func(int i, int p)
{
	auto& memo = dp[i][p];
	if (A[i] == '\0') {
		if (p == 0) {
			return 1;
		}
		return 0;
	}
	if (memo != -1) {
		return memo;
	}

	memo = 0;
	for (int a = 0; a < 10; ++a)
	{
		if (i == 0 && a == 0) { continue; }
		if (!(A[i] == '?' || A[i] == a+ '0')) { continue; }
		for (int b = 0; b < 10; ++b)
		{
			if (i == 0 && b == 0) { continue; }
			if (!(B[i] == '?' || B[i] == b + '0')) { continue; }
			for (int c = 0; c < 10; ++c)
			{
				if (i == 0 && c == 0) { continue; }
				if (!(C[i] == '?' || C[i] == c + '0')) { continue; }


				memo += check(i+1, a, b, c, p);
				memo %= MOD;
			}
		}
	}
	return memo;
}



int main()
{
	for (;;)
	{
		fillall(dp, (int64_t )-1);
		cin >> A;
		if (A[0] == '0') { break; }
		cin >> B >> C;
		//for (size_t i = 0; A[i] != '\0'; i++)
		//{
		//	if (A[i] != '?') { A[i] -= '0'; }
		//	if (B[i] != '?') { B[i] -= '0'; }
		//	if (C[i] != '?') { C[i] -= '0'; }
		//}

		cout << (func(0, 0)) % MOD << endl;
	}

}



Measured memory_bytes: 3068
n = int(input())
S = [item for item in input().split()]
q = int(input())
T = [item for item in input().split()]

c = 0
addedOnce = False
for t in T:
    addedOnce = False
    for s in S:
        if t == s and not addedOnce:
            c += 1
            addedOnce = True
print(c)


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
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;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  int t = in();
  vector<P> v(n);
  REP(i,n) {
    int cost = in();
    int time_cost = in();
    v[i] = P(cost, time_cost);
  }
  SORT(v);
  REP(i,n) {
    if(v[i].second <= t) {
      cout << v[i].first << endl;
      return 0;
    }
  }
  cout << "TLE";
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
import itertools
N, M, Q = map(int, input().split(" "))
abcd = []
for i in range(Q):
    abcd.append(list(map(int, input().split(" "))))
A = list(itertools.combinations_with_replacement(range(1, M + 1), N))
#print(A)
ans = 0            
for a in A:
    score = 0
    for i in abcd:
        if a[i[1] - 1] == a[i[0] - 1] + i[2]:
            score += i[3]
    ans = max(ans, score)
print(ans)


Measured memory_bytes: 21432
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    long long n, ans;
    std::cin >> n;
    std::vector<std::vector<std::vector<long long>>> f(n, std::vector<std::vector<long long>>(5, std::vector<long long>(2)));
    std::vector<std::vector<long long>> p(n, std::vector<long long>(11));
    for (auto i = 0; i < n; i++) {
        std::cin >> f[i][0][0] >> f[i][0][1] >> f[i][1][0] >> f[i][1][1] >> f[i][2][0] >> f[i][2][1] >> f[i][3][0] >> f[i][3][1] >> f[i][4][0] >> f[i][4][1];
    }
    for (auto i = 0; i < n; i++) {
        for (auto j = 0; j < 11; j++) std::cin >> p[i][j];
    }

    for (auto pat = 1; pat < 1024; pat++) {
        auto ret = 0ll;

        for (auto s = 0ll; s < n; s++) {
            auto count = 0ll;
            for (auto j = 0; j < 5; j++) {
                for (auto k = 0; k < 2; k++) {
                    count += ((pat >> (2*j + k)) & f[s][j][k]);
                }
            }
            ret += p[s][count];
        }

        if (pat == 1) ans = ret;
        else if (ret >= ans) ans = ret;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i)
#define FORD(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i)
#define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

#define TWO(X) (1LL<<(X))
#define CONTAIN(S,X) ((S) & TWO(X))

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

int segment_union(vector< pair<int, int> > segs) {
    int n = SZ(segs);
    vector< pair<int, bool> > x(n*2);
    REP(i,n) {
        x[i*2] = make_pair(segs[i].first, false);
        x[i*2+1] = make_pair(segs[i].second, true);
    }
    sort(x.begin(), x.end());

    int res = 0;
    int c = 0;
    REP(i,n*2) {
        if (c && i) res += x[i].first - x[i-1].first;
        if (x[i].second) ++c;
        else --c;
    }
    return res;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9) << boolalpha;
    int n, l;
    while (cin >> n >> l) {
        vector< pair<int,int> > segs;
        REP(i,n) {
            int t; cin >> t;
            segs.emplace_back(t, t + l);
        }
        cout << segment_union(segs) << endl;
    }
    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<vector<int>> F(N, vector<int>(10));
  vector<vector<int>> P(N, vector<int>(11));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) cin >> F[i][j];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) cin >> P[i][j];
  }
  
  int ans = -1000000000;
  for (int tmp = 1; tmp < (1 << 10); tmp++) {
    bitset<10> s(tmp);  
    int sum = 0;
    for (int i = 0; i < N; i++) {
      int count = 0;
      for (int j = 0; j < 10; j++) {
        if (s.test(j) && F[i][j] == 1) count++;
      }
      sum += P[i][count];
    }
    ans = max(ans,sum);
  }
  
  cout << ans << endl;
}

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

using namespace std;

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

    for (int yy=0; yy<=100; yy++) {
        for (int xx=0; xx<=100; xx++) {
            int ch = -1;
            for (int i=0; i<n; i++) {
                if (h[i] > 0) {
                    if (ch == -1)
                        ch = h[i] + abs(x[i]-xx) + abs(y[i]-yy);
                    else if (ch != h[i] + abs(x[i]-xx) + abs(y[i]-yy)) {
                        ch = -2;
                        break;
                    }
                }
            }
            if (ch != -2) {
                for (int i=0; i<n; i++) {
                    if (h[i] == 0) {
                        if (ch-abs(x[i]-xx)-abs(y[i]-yy) > 0) {
                            ch = -2;
                            break;
                        }
                    }
                }
                if (ch == -2) continue;
                cout << xx << " " << yy << " " << ch << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a,int b) {
    return b == 0? a : gcd(b,a%b);
}

int main() {
    int a,b; cin >> a >> b;
    if(a < b) swap(a,b);
    cout << gcd(a,b) << endl;
    return 0;
}



Measured memory_bytes: 3092