akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	int n,sum=0;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;++i){
		cin>>v[i];
		sum+=v[i];
	}
	sum/=n;
	int ans=0;
	for(int i=0;i<n;++i){
		ans+=(v[i]-sum)*(v[i]-sum);
	}
	int sol=0;
	++sum;
	for(int i=0;i<n;++i){
		sol+=(v[i]-sum)*(v[i]-sum);
	}
	cout<<min(ans,sol)<<"\n";
	return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] nums = sc.nextLine().split(" ");
        int ans = Integer.parseInt(nums[0]) * Integer.parseInt(nums[1]);
        if(ans%2==0){
            System.out.println("Even");
        }else{
            System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y))
#define PI 3.14159265358979


int main()
{
	int l,d;
	int deg = 90;
	double x = 0;
	double y = 0;
	while(scanf("%d,%d",&l,&d),l)
	{
		x += cos((double)deg*PI/180.0)*l;
		y += sin((double)deg*PI/180.0)*l;
		deg -= d;
	}
	printf("%d\n%d\n",(int)x,(int)y);
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    cin >> N;
    vector<ll> A;
    for (int i = 0; i < N; i++) {
        ll a; cin >> a;
        A.pb(a);
    }
    ll maxv = A[0];
    ll cnt = 0;
    for (int i = 1; i < N; i++) {
        if(maxv > A[i]){
            cnt += maxv - A[i];
        } else {
            maxv = max(maxv,A[i]);
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 5360
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    map<int,int> m;
    REP(i,50000){
        if(m.find((int)(i*1.08))==m.end())m.emplace(make_pair((int)(i*1.08),i));
    }
    int n;
    scanf("%d",&n);
    if(m.find(n)==m.end())printf(":(\n");
    else{
        printf("%d\n",m.at(n));
    }
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}

int main() {
  int n;
  cin >> n;
  int ans = INF;
  int w[n];
  rep (i, n) {
    cin >> w[i];
  }
  for (int t = 1; t < n; t++) {
    int s1 = 0;
    int s2 = 0;
    rep (i, n) {
      if (t >= i) s1 += w[i];
      else s2 += w[i];
    }
    ans = min(ans, abs(s1 - s2));
  }
  P(ans);

  return 0;

}

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

int main(){
    int n; cin >> n;
    int a = n % 1000;
    int b;
    if(a == 0) b = 0;
    else b = 1000 - a;
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
template <typename T, typename U>
using P = pair<T,U>;
template <typename T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

int main(){
  string s;
  cin >> s;
  map<char,int> alp;
  int max_alp = 0, size = s.size();
  rep(i,size){
    char a = s[i];
    alp[a]++;
    if(max_alp < alp[a]){
      max_alp = alp.at(a);
    }
  }
  
  if(alp.size()==1)
    cout << 0 << endl;
  else if(max_alp == 1)
    cout << size/2 << endl;
  else{
    int ans = size/2;
    for(auto x : alp){
      char c = x.first;
      int tmp_ans = 0, tmp_c=-1;
      rep(i,size){
        if(s[i]==c){
          tmp_ans = max(tmp_ans, i-tmp_c-1);
          tmp_c = i;
        }
        else if(i == size - 1)
          tmp_ans = max(tmp_ans, i-tmp_c);
      }
      ans = min(ans,tmp_ans);
    }
    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  uint64_t H, W;
  
  cin >> H >> W;
  
  if (W == 1 || H == 1) {
    cout << 1 << endl;
  } else {
    cout << (H % 2 == 0 || W % 2 == 0 ? H * W / 2 : (H * W - 1) / 2 + 1) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3548
// 解き直し.
// https://img.atcoder.jp/data/arc/060/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL dp[55][55][3030];
int x[55];

int main(){
    
    // 1. 入力情報.
    int N, A;
    scanf("%d %d", &N, &A);
    rep(i, N) scanf("%d", &x[i]);
    
    // 2. dp更新.
    rep(j, N + 1){
        rep(k, N + 1){
            rep(s, N * A + 1){
                if(!j && !k && !s) dp[j][k][s] = 1;
                if(j){
                    if(s < x[j - 1])       dp[j][k][s] = dp[j - 1][k][s];
                    if(k && s >= x[j - 1]) dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]];
                }
            }
        }
    }
    
    // 3. 集計.
    LL ans = 0;
    repx(k, 1, N + 1) ans += dp[N][k][k * A];
    
    // 4. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 62748
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n";
#define nec cout<<"\n";continue; 
#define test int t;cin>>t;while(t--)
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1000000007; 

int main()
{
    io();
	li n;
	cin>>n;
	string s;
	cin>>s;
	li c=0,i;
	for(i=0;i<n;i++)
	if(s[i]=='W')c++;
	li ans=0;
	for(i=n-1;i>=n-c;i--)
	if(s[i]!='W')ans++;
	cout<<ans;
}

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

const int maxn=3e5+6;
int cnt[maxn],a,n,tot;
int d[maxn],sum[maxn],sumd[maxn];
long long f[maxn];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		scanf("%d",&a);
		cnt[a]++;
	}
	for(int i=1;i<=n;++i) d[cnt[i]]++;
	sumd[0]=d[0];
	for(int i=1;i<=n;++i) {
		sum[i]=sum[i-1]+i*d[i];
		sumd[i]=sumd[i-1]+d[i];
	}
	for(int i=1;i<=n;++i) {
		f[i]=(1ll*sum[i]+1ll*i*(sumd[n]-sumd[i]))/i;
	}
	int las=n;
	for(int i=1;i<=n;++i) {
		while(f[las]<i&&las!=0) las--;
		printf("%d\n",las);
	}
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N,K;
    cin >> N >> K;
 
    vector<int> x(N),y(N),xs(N),ys(N);
    rep(i,0,N){
        cin >> x[i] >> y[i];
        xs.push_back(x[i]);
        ys.push_back(y[i]);
    }
 
    sort(begin(xs),end(xs));
    sort(begin(ys),end(ys));
 
    i64 ans=inf64;
    rep(i,0,xs.size()) rep(j,i+1,xs.size()) rep(k,0,ys.size()) rep(l,k+1,ys.size()){
        int x1=xs[i],y1=ys[k],x2=xs[j],y2=ys[l];
        i64 s=i64(x2-x1)*i64(y2-y1);
        if(s>=ans) continue;
        
        int cnt=0;
        rep(i,0,N) if(x1<=x[i] and x[i]<=x2 and y1<=y[i] and y[i]<=y2) ++cnt;
        
        if(cnt>=K) ans=s;
    }
 
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
 
int main() {
  // input
    int n,m;cin >> n >> m;
    //string str = "000000";
    vector<int> str(n + 1);
    vector<int> s(m + 1);
    vector<int> c(m + 1);
 
    for(int i = 1; i < n + 1; i++) str[i] = 0;
  	if(n > 1){
        str[1] = 1;
    }
  
    if(m > 0){
        for(int i = 1; i < m + 1; i++) cin >> s[i] >> c[i];
    }else{
        for(int i = 1; i < n + 1; i++) cout << str[i]; 
        cout << endl;
        return 0;
    }
 
  // compute
    set<int> st1,st2,st3;
    
    for(int i = 1; i < m + 1; i++){
        if(s[i] > n){
        }else{
            switch(s[i]){
                case 1:
                    st1.insert(c[i]);
                    break;
                case 2:
                    st2.insert(c[i]);
                    break;                
                case 3:
                    st3.insert(c[i]);
                    break;
            }
        }
        } 
    if(st1.size() > 1 || st2.size() > 1 || st3.size() > 1){
        cout << -1 << endl;
        return 0;
    }else{
      for(int i = 1; i < m + 1; i++) str[s[i]] = c[i];
    }        
 
  // output  
    if(str[1] == 0 && n != 1){
            cout << -1 << endl;
        }else{
             for(int i = 1; i < n + 1; i++) cout << str[i]; 
      		 cout << endl;
        }
}

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

const ll MOD = 1e9+7;

ll a = 0,b = 0,c = 0,ab = 0,abc = 0;

ll p3(ll x){
  // 3^x mod MODを返したい
 
  if( x == 0){ return 1LL;}
  
  if( x%2 == 0){ 
    ll res = p3(x/2);
    res = (res*res)%MOD;
    return res;
  }
  else{
    ll res = p3((x-1)/2)%MOD;
    res = (res*res)%MOD;
    return (res*3)%MOD;
  }
}

int main(){
  
  string S; cin >> S; int n = (int)S.size();
  
  ll q = 0;

  for(int i = 0; i < n; i++){ 
    
    if(S[i] == 'A'){ 
      a = a+p3(q);
      a %= MOD;
    }
    if(S[i] == 'B'){ 
      ab = ab+a;
      b = b+p3(q);
      ab %= MOD;
      b %= MOD;
    }
    if(S[i] == 'C'){
      abc = abc+ab;
      c = c+p3(q);
      abc %= MOD;
      c %= MOD;
    }
    if(S[i] == '?'){ 
      abc = 3*abc+ab;
      ab = 3*ab+a;
      a = 3*a+p3(q);
      b = 3*b+p3(q);
      c = 3*c+p3(q);
      q++;
      
      abc %= MOD;
      ab %= MOD;
      a %= MOD;
      b %= MOD;
      c %= MOD;
      
    }
   
  }
  
  cout << abc << endl;
  
  return 0;
}
    

Measured memory_bytes: 512
#include <stdio.h>


int main(){
	int h, n, cont=0, eq=0;
	scanf("%d %d", &h, &n);
	int vet[n];
	for(int i=0; i<n; ++i){
		scanf("%d", &vet[i]);
		eq+=vet[i];
	}
	if(eq>=h)
		printf("Yes\n");
	else if(eq<h)
		printf("No\n");
	return 0;
	
}

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

int main(){
  string S;
  
  cin>>S;
  
  int K;
  
  if(S.size()%2==0){
    K=S.size()/2;
  }
  else if(S.size()%2!=0){
    K=S.size()/2+1;
  }
  
  vector<char> ans(K);
  
  int sum=0;

  
  for(int i=0;i<S.size();i++){
if((i+1)%2!=0){
  ans.at(sum)=S.at(i);
  sum++;
}
  }
  
  for(int i=0;i<K;i++){
cout<<ans.at(i);
  }
}

  

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

string win = "Alice";
string lose = "Brown";

long long X, Y;

int issente[210][210];
int naive(int a, int b) {
    if (a <= 1 && b <= 1) return issente[a][b] = 0;
    if (issente[a][b] != -1) return issente[a][b];
    issente[a][b] = 0;
    for (int sa = 1; sa * 2 <= a; ++sa) {
        if (naive(a - sa*2, b + sa) == 0) issente[a][b] = 1;
    }
    for (int sb = 1; sb * 2 <= b; ++sb) {
        if (naive(a + sb, b - sb*2) == 0) issente[a][b] = 1;
    }
    return issente[a][b];
}

string solve() {
    if (X <= 1 && Y <= 1) return lose;
    if (abs(X - Y ) <= 1) return lose;
    return win;
}

int main() {
    /*
    memset(issente, -1, sizeof(issente));
    for (int a = 0; a < 100; ++a) {
        for (int b = 0; b < 100; ++b) {
            if (naive(a, b) == 0) cout << a << ", " << b << endl;
        }
    }
     */
    
    while (cin >> X >> Y) {
        cout << solve() << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

LL a[200020];
LL visit[200020];
vector<LL> v;
int main(){
	LL n,k;
	cin>>n>>k;
	for(LL i=0;i<n;i++)cin>>a[i],a[i]--;
	fill(visit,visit+200020,-1);
	visit[0]=0;
	v.push_back(0);
	
	LL ima=0;
	LL first,second;
	for(LL i=1;i<=n+n/2;i++)
	{
		ima=a[ima];
		if(visit[ima]!=-1)
		{
			first=visit[ima];
			second=i;
			break;
		}	
		else
		{
			visit[ima]=i;
			v.push_back(ima);
		}
	}
	
	if(k<second)cout<<v[k]+1<<"\n";
	else
	{
		LL sa=second-first;
		for(LL i=first;i<=second;i++)
		{
			if(k%sa==i%sa)
			{
				cout<<v[i]+1<<"\n";
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 8408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
int main(void){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,b*d,a*d,b*c})<<endl;
    
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int k,c,sum,cou=0,ans[100];
    while(cin>>k&&k!=0){
        sum=0;
        for(int i=0;i<k*(k-1)/2;i++){
            cin>>c;
            sum+=c;
        }
        ans[cou]=sum/(k-1);
        cou++;
    }
    for(int i=0;i<cou;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define MOD 998244353
typedef pair<li, li> PI;
 
#define INF bit(60)
 
li n, k;
 
li comb[5050][5050]; // comb[n][r] = nCr % MOD
li b[5050]; // b[n] = 2^n % MOD
 
inline void prepare() {
    b[0]=1;
    repp(i,1,5050){
        b[i]=(b[i-1]*2)%MOD;
    }
    rep(i, 5050) {
        comb[i][0] = 1;
    }
    repp(i, 1, 5050) {
        repp(j, 1, i + 1) {
            comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
        }
    }
}
 
inline li solve(li x) {
    li res = 0;
    li pair_num = 0;
    repp(i, 1, k + 1) {
        if (i < (x - i) && x - i <= k) {
            ++pair_num;
        }
    }
    if (x % 2 == 1) {
        // odd
        li r = max(k - pair_num * 2, 0ll);
        rep(q, pair_num + 1) {
            if (q > n) {
                continue;
            }
            li conbi_num = (comb[pair_num][q] * b[q]) % MOD;
            li bunkatsu_num = comb[(n - q) + (q + r) - 1][n - q];
            res = (res + (conbi_num * bunkatsu_num % MOD)) % MOD;
        }
    } else {
        // even
        li r = max(k - pair_num * 2 - 1, 0ll);
        rep(q, pair_num + 1) {
            if (q > n) {
                continue;
            }
            // not use x/2
            li conbi_num = (comb[pair_num][q] * b[q]) % MOD;
            li bunkatsu_num = comb[(n - q) + (q + r) - 1][n - q];
            res = (res + (conbi_num * bunkatsu_num % MOD)) % MOD;
 
            if (q > n - 1) {
                continue;
            }
            // use x/2 once
            li bunkatsu_num2 = comb[(n - 1 - q) + (q + r) - 1][n - 1 - q];
            res = (res + (conbi_num * bunkatsu_num2 % MOD)) % MOD;
        }
    }
    return res;
}
 
int main() {
    prepare();
    cin >> k >> n;
 
    repp(i, 2, k * 2 + 1) {
        cout << solve(i) << endl;
    }
 
    return 0;
}

Measured memory_bytes: 197760
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main()
{
   static long i,j,k,l;
   long n;
   long cnt = 0;
   long left,right,mid;
   long ans = 0;
   int a,b;
   static int H[10000];
   static int W[10000];


   for(i = 0;; i++) {
      scanf("%d %d",&H[i],&W[i]);
      if(H[i] == 0)
         break;
   }
   for(j = 0; j < i; j++) {
      for(k = 0; k < H[j]; k++) {
         for(l = 0; l < W[j]; l++) {
            putchar('#');
         }
         putchar('\n');
      }
      putchar('\n');
   }

   return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

using namespace std;

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,j,k) for(int i=j;i<(k);i++)
#define foreach(T,c,i) for(T::iterator i=c.begin();i!=c.end();i++)
typedef vector<int> Array;
typedef vector<Array> Mat;
const int INF = 99999999;
int N,W,a,b,ans_num=0;
const int MAX_N = 1000;
const int MAX_W = 1000;
int dp[MAX_N+1][MAX_W+1];
Array v,w;

void solve()
{
	rep(i,N) rep(j,W+1){
		if(j<w[i]){
			dp[i+1][j] = dp[i][j];
		}else{
			dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
		}
	}
	cout << dp[N][W] << endl;
	int MIN = INF;
	rep(i,N+1)rep(j,W+1){
		if(dp[i][j]==dp[N][W]) MIN = min(MIN,j);
	}
	cout << MIN << endl;
	
}
		
int main(){
	while(1){
		cin >> W >> N;
		if(W==0) return 0;
		ans_num++;
		memset(dp,0,sizeof(dp));
		v.clear();
		w.clear();
		rep(i,N){
			scanf("%d,%d",&a,&b);
			v.pb(a);
			w.pb(b);
		}
		cout << "Case " << ans_num << ":" << endl;
		solve();
	}	
	return 0;	
}

Measured memory_bytes: 0
#include <iostream>

#include <map>
#include <string>

#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cinttypes>


using namespace std;

int main()
{

	string s, t;
	cin >> s >> t;

	int a, b;
	cin >> a >> b;

	string u;
	cin >> u;

	if (s == u) --a;
	else --b;

	cout << a << " " << b << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){   
   int a,count;
   cin>>a;
   string s;
   cin>>s;
   count=0;
   for (int i = 0; i <a-2; i++)
   {
      if(s[i]=='A'){
         if(s[i+1]=='B'){
            if(s[i+2]=='C'){
               count++;
            }
         }
      }
   }
   cout<<count<<endl;
   
   

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, k;
    cin>>a>>b>>k;
    if(a >= k){
        a -= k;
        cout<<a<<" "<<b<<endl;
        return 0;
    } else {
        k = k-a;
        a = 0;
        if(b >= k){
            b -= k;
            cout<<a<<' '<<b<<endl;
            return 0;
        } else {
            b = 0;
            cout<<a<<' '<<b<<endl;
        }
    }
    return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String ans[] = {"Christmas", "Christmas Eve", "Christmas Eve Eve", "Christmas Eve Eve Eve"};
		
		int d;
		d = sc.nextInt();
		
		sc.close();
		
		System.out.println(ans[25-d]);
	}

}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define all(x) x.begin(), x.end()
#define ll long long
#define INF 2e9
using namespace std;

void Main() {
    int n, m;
    cin >> n;
    int t[100], p[100], x[100];

    int t_sum = 0;
    rep(i, 0, n) {
        cin >> t[i];
        t_sum += t[i];
    }

    cin >> m;
    string ans;
    rep(i, 0, m) {
        int p, x;
        cin >> p >> x;
        ans += to_string(t_sum - t[p - 1] + x) + " ";
    }
    cout << ans << endl;
    // rep(i, 0, m) { cout << t_sum - t[p[i] - 1] + x[i] << endl; }
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15) << endl;
    Main();
    return 0;
}

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

using namespace std;

string s,t,r;
int dp[3001][3001];

int init(int i,int j){
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(s[i]=='\0' || t[j]=='\0'){
        return 0;
    }
    if(s[i]==t[j]){
        return dp[i][j]=1+init(i+1,j+1);
    }
    return dp[i][j]=max(init(i+1,j),init(i,j+1));
}

void print(int i,int j){
    if(s[i]=='\0' || t[j]=='\0'){
        cout<<r<<"\n";
        return;
    }
    if(s[i]==t[j]){
        r.push_back(s[i]);
        print(i+1,j+1);
    }
    else{
        if(dp[i+1][j]>dp[i][j+1]){
            print(i+1,j);
        }
        else{
            print(i,j+1);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>s>>t;
    memset(dp,-1,sizeof(dp));
    init(0,0);
    print(0,0);
    return 0;
}

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

int main(){
	int sosu[40000] = {},count = 0, n, f;
	for(int i = 2; i <= 300000; i++){
		f = 0;
		if((i%7 != 1) && (i%7 != 6)) continue;
		for(int j = 2; j * j <= i ;j++){
			if(i%j == 0){
				if(j%7 == 1 || j%7 == 6){
					f = 1;
					break;
				}
				if((i/j)%7 == 1 || (i/j)%7 == 6){
					f = 1;
					break;
				}
			}
		}
		if(f == 0) sosu[count++] = i;
	}
	
	while(1){
		int i = 0;
		cin>>n;
		if(1 == n) break;
		
		cout<<n<<":";
		while(i < count){
			f = 0;
			if(n%sosu[i] == 0)cout<<" "<<sosu[i];
			i++;
		}
		
		cout<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3244
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
 
        // tenka1_2018_a
        if (s.length() == 2) {
        	System.out.println(s);
        } else {
        	StringBuilder sb = new StringBuilder(s);
        	System.out.println(sb.reverse());
        }
 
	}
}

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

int main() {
  int N, A, B, Ans=0;
  cin >> N >> A >> B;
  for(int i=1; i<=N; i++){
    int tmp=i, sum=0;
    while(tmp > 0){
      sum += tmp % 10;
      tmp /= 10; 
    }
    if (A<=sum && sum<=B) Ans+=i;
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	n := scanInt()
	works := make(works, n)
	for i := 0; i < n; i++ {
		w := work{time: scanInt(), deadline: scanInt()}
		works[i] = w
	}

	// sort.Slice(works, func(i, j int) bool {
	// 	return works[i].deadline < works[j].deadline
	// })
	sort.Sort(works)

	elapsed := 0
	for _, v := range works {
		elapsed += v.time
		if elapsed > v.deadline {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}

type work struct {
	time     int
	deadline int
}

type works []work

func (w works) Len() int {
	return len(w)
}

func (w works) Swap(i, j int) {
	w[i], w[j] = w[j], w[i]
}

func (w works) Less(i, j int) bool {
	return w[i].deadline < w[j].deadline
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {

	if a < b {
		a, b = b, a
	}

	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;
vector<int> check;
int main() {
    int n,mx = INT_MAX,cnt = 0;
    cin >> n;
    vector<int> p(n);
    int rui[n+1];
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        mx = min(mx,p[i]);
        rui[i+1] = mx;
    }

    for (int i = 0; i < n; ++i) {
        if(p[i] <= rui[i+1]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1920
N = int(input())
a = [[ int(y) for y in input().split(' ')] for x in range(N)]

h = [[0 for y in range(3)] for x in range(N)]

def max_h(i, j):
    n = [0, 0, 0]
    for k in range(3):
        if k != j:
            n[k] = h[i][k]
    return max(n)

for i in range(N):
    for j in range(3):
        if i == 0:
            h[i][j] = a[i][j]
        else:
            h[i][j] = max_h(i-1, j) + a[i][j]

print(max(h[N-1]))


Measured memory_bytes: 45676
#include <bits/stdc++.h>
using namespace std;
struct Item {
  int value;
  int weight;
  char type;
  long long date;
  string name;
  bool operator<(const Item& other) const {
    if (value != other.value) return value < other.value;
    if (weight != other.weight) return weight < other.weight;
    if (type != other.type) return type < other.type;
    if (date != other.date) return date < other.date;
    if (name != other.name) return name < other.name;
    return false;
  }
};
int main() {
  int n;
  cin >> n;
  vector<Item> v(n);
  for (auto& p : v) cin >> p.value >> p.weight >> p.type >> p.date >> p.name;
  sort(v.begin(), v.end());
  for (auto p : v)
    cout << p.value << " " << p.weight << " " << p.type << " " << p.date << " "
         << p.name << endl;
  return 0;
}


Measured memory_bytes: 12160
using System;
class Program{
  static void Main(){
    int[] ps = {2,11,31,41,61,71,101,131,151,181,191,211,241,271,281,311,331,401,431,461,491,521,541,571,601,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381,1451,1801,1811,2711,3001};
int n = int.Parse(Console.ReadLine());
for (int i=0;i<n-1;i++)
    Console.Write("{0} ",ps[i]);
Console.WriteLine(ps[n-1]);
  }
}

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

int main()
{
ll n , sum=0 ;
cin >> n ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
  sum+=a[i];
}
bitset<4000001> b;
b[0]=1;
rep(i,n){
  b|=(b<<a[i]);
}
ll r=(sum+1)/2;
while(1){
  if(b[r]){
    cout << r << endl;
    break;
  }
  r++;
}
return 0;
}

Measured memory_bytes: 1792
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;
using ll = long long;
using ld = long double;

#define REPi(i, s, e) for(int i = (s); i < (e); ++i)
#define REPll(i, s, e) for(ll i = (s); i < (e); ++i)

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

int main()
{
	cin.tie(0);

	int N; cin >> N;
	vec<int> A(N);
	int first = 0, second = 0;
	REPi(i, 0, N)
	{
		cin >> A[i];
		if (A[i] > first)
		{
			second = first;
			first = A[i];
		}
		else if (A[i] > second)
		{
			second = A[i];
		}
	}
	
	REPi(i, 0, N)
	{
		if (A[i] != first) cout << first << endl;
		else cout << second << endl;
	}


	return 0;
}

Measured memory_bytes: 2432
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	string ans = "";
	for (int i = 0; i < n; i++) {
		ans += string(1, s[i]) + string(1, t[i]);
	}
	cout << ans << "\n";
}



Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ans = "None";
		Map<Character,Integer> check = new TreeMap<Character,Integer>();
		for(char c = 'a' ; c <='z';c++) {
			check.put(c, 0);
		}
		for(int i = 0; i <s.length(); i++) {
			int temp = check.get(s.charAt(i))+1;
			check.put(s.charAt(i),temp);
		}
		for(char i = 'a'; i <='z'; i++) {
			if(check.get(i) == 0) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 28080
import sys
import numpy as np
import numba
from numba import njit
from numba.types import Omitted
i4 = numba.int32
i8 = numba.int64

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

Bsize = 700

@njit((i8[:, :], ), cache=True)
def Mo_argsort(LR):
    L = LR[:, 0]
    R = LR[:, 1]
    key1 = L // Bsize
    key2 = np.where(key1 & 1, -R, R)
    key = (key1 << 32) + key2
    return np.argsort(key)

@njit((i8[:], i8[:, :]), cache=True)
def main(A, LR):
    N = len(A)
    Q = len(LR)
    ind = Mo_argsort(LR)
    count = np.zeros(N + 1, np.int64)
    ans = 0
    

    def add(x):
        nonlocal ans
        if not count[x]:
            ans += 1
        count[x] += 1

    def rem(x):
        nonlocal ans
        count[x] -= 1
        if not count[x]:
            ans -= 1

    answers = np.empty(Q, np.int64)
    nl, nr = 0, 0
    for i in ind:
        l, r = LR[i]
        l -= 1
        # 区間 [l, r) に対する計算
        while nl > l:
            nl -= 1
            add(A[nl])
        while nr < r:
            add(A[nr])
            nr += 1
        while nl < l:
            rem(A[nl])
            nl += 1
        while nr > r:
            nr -= 1
            rem(A[nr])
        #  答を求めて ans[i] に格納する
        answers[i] = ans
    return answers

N, Q = map(int, readline().split())
A = np.array(readline().split(), np.int64)
LR = np.array(read().split(), np.int64).reshape(Q,2)

ans = main(A, LR)
print('\n'.join(map(str, ans.tolist())))

Measured memory_bytes: 183060
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int64_t n, k;
int main() {
    DAU
    cin >> n >> k;
    n %= k;
    cout << min(n, k - n);
    PLEC
}

Measured memory_bytes: 256
n,m,l=map(int,input().split())
c1=[list(map(int,list(input().split()))) for i in range(n)]
c2=[list(map(int,list(input().split()))) for i in range(m)]

c3=[[0]*l for i in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            c3[i][j]+=c1[i][k]*c2[k][j]

for i in range(n):
    print(*c3[i])
    


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

int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> vec(M);
  for (int i = 0; i < M; i++) {
    int k; cin >> k;
    vec[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> vec[i][j];
      vec[i][j] -= 1;
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    bool ok = true;
    for (int j = 0; j < M; j++) {
      int c = 0; // 電球jにつながっていて，かつonになっているスイッチの個数
      for (auto id : vec[j]) {
        if ((bit >> id) & 1) {
          c++;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
#include <random>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

class AtcoderContestSchedule {
  public:
    int D;
    std::array<int,26> c;
    std::vector<std::array<int,26>> s;

    explicit AtcoderContestSchedule(void) {
      std::cin >> D;  s.resize(D);
      rep(i,26) std::cin >> c[i];
      rep(i,D) rep(j,26) std::cin >> s[i][j];
    }

    int Score( const std::vector<int> &d ) {
      int S = 0;
      std::vector<int> last(26, 0);
      rep(i, sz(d)) {
        S += s[i][d[i]-1];
        last[d[i]-1] = i+1;
        rep(j,26) S -= c[j] * ( (i+1) - last[j] );
        std::cout << S << std::endl;
      }
      return std::max<int>(1e6+S, 0);
    }

    void Print() {
      std::random_device rnd;
      std::mt19937 mt(rnd());
      std::uniform_int_distribution<int> rand(1, 26);
      rep(i,365) std::cout << rand(mt) << std::endl;
      return;
    }
};

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  AtcoderContestSchedule sub;
  std::vector<int> t(sub.D);
  rep(i,sub.D) std::cin >> t[i];
  sub.Score(t);
  return 0;
}



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

int main()
{
  int x[4],y[4];
  cin >> x[0] >> y[0] >> x[1] >> y[1];
  int dx = x[1] - x[0];
  int dy = y[1] - y[0];
  for(int i = 2;i < 4;i++){
    swap(dx,dy);
    dx = - dx;
    x[i] = x[i-1] + dx;
    y[i] = y[i-1] + dy;
  }
  cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	vector<long long> 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(C.begin(), C.end());
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		auto x = lower_bound(A.begin(),A.end(), B[i]);
		auto y = lower_bound(C.begin(), C.end(), B[i]+1);
		ans += (x - A.begin())*(C.end() - y);
	}
	cout << ans << endl;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll double

ll dp[301][301][301];



double E(int a, int b, int c, int& n){
    if(a < 0 or b < 0 or c < 0) return 0;
    if(a == 0 and b == 0 and c == 0) return 0;
    
    if(dp[a][b][c] > 0) return dp[a][b][c];
    
    int k = a+b+c;
    double sum = n + a*E(a-1,b,c,n)+ b*E(a+1,b-1,c,n) + c*E(a,b+1,c-1,n);
    return dp[a][b][c] = sum/k;
}



int main(){
    //cout << "yes";
    int n; cin >> n;
    int a = 0,b = 0,c = 0;
    
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        if(x == 1) a++;
        else if(x == 2) b++;
        else c++;
    }
    
    
    cout << fixed << setprecision(10) << E(a,b,c,n);
    
   
    return 0;
}

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

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

    int n;
    cin >> n;
    vector<ll> a(n), b;
    ll sum = 0, k;
    cin >> k;
    rep(i, 0, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            b.push_back(i);
            if (i * i != n)
                b.push_back(sum / i);
        }
    }
    sort(b.begin(), b.end(), greater<ll>());

    for (auto x : b) {
        vector<ll> c = a;
        if (a[n - 1] > x) {
            for (auto &y : c)
                y %= x;
            sort(c.begin(), c.end());
        }
        if (k < c[n - 1] && c[n - 1] < x - k)
            continue;
        vector<ll> s(n), t(n);
        rep(i, 0, n) {
            s[i] = c[i];
            t[n - 1 - i] = x - c[n - 1 - i];
            if (i != 0) {
                s[i] += s[i - 1];
                t[n - 1 - i] += t[n - i];
            }
        }
        if (s[n - 1] == 0) {
            cout << x << endl;
            return 0;
        }

        int l = 0, r = n, i;
        while (r - l > 1) {
            i = (l + r) / 2;
            if (s[i] == t[i + 1]) {
                if (k < s[i])
                    break;
                else {
                    cout << x << endl;
                    return 0;
                }
            } else if (s[i] < t[i + 1])
                l = i + 1;
            else
                r = i;
        }
        i = l;
        if (s[i] == t[i + 1]) {
            if (k < s[i])
                i++;
            else {
                cout << x << endl;
                return 0;
            }
        }
    }
    cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define MOD 1000000007
int main()
{
    int M,N,P,_i,_j;

    cin>>M>>N;

    ll Grid[M+1][N+1];

  
    memset(Grid, 0, sizeof(Grid));

   for(int i=1;i<=M;i++){
    for(int j=1;j<=N;j++){
        char c;
        cin>>c;
        if(c=='#')
         Grid[i][j]=-1;
    }
   }

    if(Grid[1][1] == -1)
    {
        printf("0");
        return 0;
    }


    F(i,1,M)
    {
        if(Grid[i][1] == 0) Grid[i][1] = 1LL;
        else break;
    }

    F(i,2,N)
    {
        if(Grid[1][i] == 0) Grid[1][i] = 1LL;
        else break;
    }


    F(i,2,M)
    {
        F(j,2,N)
        {
            if(Grid[i][j] == -1) continue;


            if(Grid[i-1][j] > 0) Grid[i][j] = (Grid[i][j] + Grid[i-1][j] + MOD)%MOD;
            if(Grid[i][j-1] > 0) Grid[i][j] = (Grid[i][j] + Grid[i][j-1] + MOD)%MOD;
        }
    }

    printf("%lld",(Grid[M][N] >= 0 ? Grid[M][N] : 0));
    return 0;
}


Measured memory_bytes: 8064
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    info = dict()
    info[1] = None
    info[2] = None
    info[3] = None
 
    for i in range(M):
        if info[s[i]] == None or info[s[i]] == c[i]:
            if s[i]==1 and c[i]==0 and N != 1:
                print(-1)
                return
            info[s[i]] = c[i]
        else:
            print(-1)
            return

    if (info[1] == 0 or info[1] == None) and N == 1:
        print(0)
        return
    num = ""
    for i in range(1,N+1):
        if info[i] == None:
            if i == 1:
                info[i] = 1
            else:
                info[i] = 0
        num += str(info[i])

    print(int(num))
    
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
def main():
    N, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    cnt = 0
    for a in A:
        if (a[0]**2 + a[1]**2)**0.5 <= D:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 45844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

signed main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif
  int n;
  cin >> n;
  int res = 1e9;
  for (int a = 1; a < n; ++a) {
    int s = 0;
    for (auto ch : to_string(a)) {
      s += ch - '0';
    }
    for (auto ch : to_string(n - a)) {
      s += ch - '0';
    }
    res = min(res, s);
  }
  cout << res << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
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;
}

int main() {
  int R, G;
  cin >> R >> G;
  cout << 2 * G - R << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <climits>

using namespace std;

long long dist(vector<vector<pair<int, int>>>& g, int from, int to){
    vector<long long> d(g.size(), numeric_limits<long long>::max());
    d[from]=0;
    using T=pair<long long, int>;
    priority_queue<T, vector<T>, greater<T>> pq;
    pq.push({d[from], from});
    while(!pq.empty()){
        int u=pq.top().second; pq.pop();
        for(auto& v : g[u]){
            long long dd=d[u]+v.second;
            if(dd>=d[v.first]) continue;
            d[v.first]=dd;
            pq.push({dd, v.first});
        }
    }
    return d[to];
}

int main(){
    int n; cin >> n;
    vector<vector<int>> amat(n, vector<int>(n));
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            cin >> amat[i][j];
        }
    }
    vector<pair<long long, pair<int, int>>> min_ds;
    for(int i=0; i<n; ++i){
        for(int j=0; j<i; ++j){
            min_ds.push_back({amat[i][j], {i, j}});
        }
    }
    sort(min_ds.begin(), min_ds.end());
    vector<vector<pair<int, int>>> g(n);
    long long ans=0;
    for(auto& p : min_ds){
        int d=p.first, from=p.second.first, to=p.second.second;
        auto dd=dist(g, from, to);
        if(dd==d) continue;
        else if(dd==numeric_limits<long long>::max()){
            g[from].push_back({to, d});
            g[to].push_back({from, d});
            ans+=d;
        } else if(dd>p.first){
            g[from].push_back({to, d});
            g[to].push_back({from, d});
            ans+=d;
        } else{
            ans=-1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		int s = sc.nextInt();
		int count = 0;
		for (int a = 0; a <= k; a++) {
			for (int b = 0; b <= k; b++) {
				int c = s - a - b;
				if (0 <= c && c <= k) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 9300
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e9+7,MAX=1e5+1;
int n;
ll s;
set<pair<ll,ll>>adj[MAX];
vector<int>vis(MAX);
priority_queue<pair<ll,pair<ll,ll>>>st;
ll x;
ll dfs(int node){
    vis[node]=1;
    ll ret=0;
    for(auto i:adj[node]){
        if(!vis[i.first]){
            x=dfs(i.F);
            st.push({x*i.S,{i.S,x}});
            ret+=x;
        }
    }
    if(sz(adj[node])==1)
        ret++;
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin>>n;
    map<string,int>mp;
    lp(i,0,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 8284