akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<ll>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc ll t; cin >> t; while(t--)

using namespace std;
string repeat(string s, ll n) {
    string s1 = "";
    for (ll i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll gcd(ll a, ll b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  ll n;
  cin>>n;
  vector<string> s(n);
  string g;
  rep(i,0,n) {cin>>g; s[i]=g;}
  vector<pii> v1(n,{0,0});
  vector<ll> op,clos;
  vpii op_clos;
  rep(i,0,n){
    stack<ll> st;
    g=s[i];
    rep(j,0,(ll)g.length()){
      if(st.empty()){
        if(g[j]=='(') st.push(1);
        else st.push(-1);
      }
      else{
        if(g[j]=='('){
          if(st.top()<0) st.push(1);
          else{
            ll x=st.top();
            st.pop();
            st.push(x+1);
          }
        }
        else{
          ll x=st.top();
          x--;
          st.pop();
          if(x!=0) st.push(x);
        }
      }

    }
    ll mn=0,mx=0;
    while(!st.empty()){
      if(st.top()<0) mn=st.top();
      if(st.top()>0) mx=st.top();
      st.pop();
    }
    v1[i]={mn,mx};
    if(mn==0 && mx>0){
      op.push_back(i);
    }
    else if(mx==0 && mn<0){
      clos.pb(i);
    }
    else if(mx>0 && mn<0){
      op_clos.pb({mn,mx});
    }
  }

  ll op1=0,flag=0;
  rep(i,0,(ll)op.size()){
    op1+=v1[op[i]].s;
  }
  auto comp=[](pii &x,pii &y){
    return (x.f+x.s)>(y.f+y.s);
  };
  sort(all(op_clos),comp);
  rep(i,0,(ll)op_clos.size()){
    pii x=op_clos[i];
    if(op1<abs(x.f)) {flag=1; break;}
    else{
      op1+=x.f;
      op1+=x.s;
    }
  }
  // cout<<flag<<endl;
  rep(i,0,(ll)clos.size()){
    pii x=v1[clos[i]];
    if(op1<abs(x.f)){flag=1; break;}
    else op1+=x.f;
  }
  // cout<<op1<<endl;
  if(op1!=0) flag=1;
  if(flag) cout<<"No\n";
  else cout<<"Yes\n";
}
int main(){
    optimizeIO();

    solve();

}


Measured memory_bytes: 58184
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	long long n;
	cin >> n;
	for(long long i = 1; i <= n; i ++)
		if(i * (i + 1) / 2 >= n)
			{cout << i; return 0;}
 
	return 0;
}

Measured memory_bytes: 256
// D - Islands War
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int N,M;
map<int,int> V;

int solve(){
	// for(auto m:V){cout<<m.first<<" "<<m.second<<"\n";}///

	int ans = 0;
	int R = 0;
	for(auto m:V){
		int l,r; tie(r,l) = m;
		// cout<<l<<" "<<r<<"\n";
		if(l >= R){ R = r; ans++; }
	}
	return ans;
}

int main(){
	cin>>N>>M;
	// V[0] = 0;
	rp(i, 0, M){
		int a,b; cin>>a>>b;
		V[b] = max(V[b], a);
	}
	cout<< solve() <<endl;
}


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

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

int main() {
	int a,b;

	cin >> a >> b;

	cout << gcd(a,b) << endl;

}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    int av1 = sum / n, av2 = (sum / n) + 1;
    int e1 = 0 , e2 = 0;
    for(int i = 0; i < n ; i++){
        e1 += (av1 - a[i]) * (av1 - a[i]);
        e2 += (av2 - a[i]) * (av2 - a[i]);
    }
    cout<<min(e1 , e2)<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

using namespace std;


int slove(int R,int C){
    int uR[10000]={0},uC[10][10000]={0},kei[10000]={0},in,me,ans=0;
    
    for(int i=0;i<R;i++)
        for(int j=0;j<C;j++){
            scanf("%d",&in);
            uR[j]+=in;
            uC[i][j]+=in;
        }
    
    for(int i=0;i<pow(2,R);i++){
        me=0;
        for(int j=0;j<C;j++){
            kei[j]=uR[j];
        }
        
        for(int j=0;j<R;j++){
            if(i & (1<<j)){
                for(int k=0;k<C;k++){
                    if(uC[j][k]){
                        kei[k]--;
                    }else{
                        kei[k]++;
                    }
                }
            }
        }
        for(int j=0;j<C;j++){
            me+=max(kei[j],R-kei[j]);
        }
        ans=max(ans,me);
    }
    
    printf("%d\n",ans);
    
    return 0;
}


int main(){
    int R,C;
    while(1){
        scanf("%d%d",&R,&C);
        if(!(R+C)) break;
        slove(R,C);
    }
    return 0;
}

Measured memory_bytes: 1704
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        Solver solver = new Solver();
        solver.solve();
        return;
    }
}

class Solver
{
    public Solver()
    {
    }

    public void solve()
    {
        while (input() == 0) ;
    }

    private int input()
    {
        string[] str;
        try
        {
            str = rsa();
        }
        catch (System.IO.IOException)
        {
            return 1;
        }
        catch (System.ArgumentOutOfRangeException)
        {
            return 1;
        }
        catch (System.OutOfMemoryException)
        {
            return 1;
        }
        catch (System.NullReferenceException)
        {
            return 1;
        }

        List<double> sta = new List<double>();

        for (int i = 0; i < str.Length; i++)
        {
            double parsed;
            if (double.TryParse(str[i], out parsed)) {
                sta.Add(parsed);
            }
            else
            {
                int counter = sta.Count;
                double var1 = sta[counter - 2];
                double var2 = sta[counter - 1];
                sta.RemoveAt(counter - 1);
                sta.RemoveAt(counter - 2);
                switch (str[i].ToCharArray()[0])
                {
                    case '+':
                        //Console.WriteLine(var1 + var2);
                        sta.Add(var1 + var2);
                        break;
                    case '-':
                        //Console.WriteLine(var1 - var2);
                        sta.Add(var1 - var2);
                        break;
                    case '*':
                        //Console.WriteLine(var1 * var2);
                        sta.Add(var1 * var2);
                        break;
                    case '/':
                        //Console.WriteLine(var1 / var2);
                        sta.Add(var1 / var2);
                        break;
                    default:
                        break;
                }
            }
        }
        Console.WriteLine(sta[0].ToString("0.000000"));

        return 0;
    }

    static String rs() { return Console.ReadLine(); }
    static int ri() { return int.Parse(Console.ReadLine()); }
    static long rl() { return long.Parse(Console.ReadLine()); }
    static double rd() { return double.Parse(Console.ReadLine()); }
    static String[] rsa() { return Console.ReadLine().Split(' '); }
    static int[] ria() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => int.Parse(e)); }
    static long[] rla() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => long.Parse(e)); }
    static double[] rda() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => double.Parse(e)); }
}

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

int main() {
  int a,b;
  cin >> a >> b;
  string s;
  s += to_string(a);
  s += to_string(b);
  int con = stoi(s);
  
  for(int i=0;i<10000;i++){
    if( con == i*i ){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 3003, MOD = 998244353;
int a, b, c, d, dp[N][N];

void add(int & x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

void sub(int & x, int y) {
	x -= y;
	if (x < 0) x += MOD;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> a >> b >> c >> d;
	dp[a][b] = 1;
	for (int i = a; i <= c; i++) {
		for (int j = b; j <= d; j++) {
			if (i > a) {
				add(dp[i][j], (ll)dp[i - 1][j] * j % MOD);
			}
			if (j > b) {
				add(dp[i][j], (ll)dp[i][j - 1] * i % MOD);
			}
			if (i > a && j > b) {
				sub(dp[i][j], (ll)(i - 1) * (j - 1) * dp[i - 1][j - 1] % MOD);
			}
		}
	}
	cout << dp[c][d];
}


Measured memory_bytes: 38764
X = input()
box = []

for i in range(len(X)):
  if X[i] == "S": box.append(X[i])
  elif X[i] == "T":
    if len(box) == 0 or box[-1] != "S":
      box.append(X[i])
    else: box.pop(-1)
print(len(box))

Measured memory_bytes: 5096
a, b, c, d = list( input())
 
op = ['+','-']
 
for i in op :
  for j  in op :
    for k in op :
      if eval( a+ i + b + j + c + k +d) == 7 :
        print('{}{}{}{}{}{}{}=7'.format( a,i, b,j,c,k,d))
        exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+5;
int n,m,x[maxn],v[maxn],v1[maxn],v2[maxn],tmp1[maxn],tmp2[maxn],ans;
inline int read()
{
	register int f=1,k=0;register char c=getchar();
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
#undef int
int main()
#define int long long
{
	n=read(); m=read();
	for (int i=1;i<=n;i++) x[i]=read(), v[i]=read();
	for (int i=1;i<=n;i++) v1[i]=v1[i-1]+v[i];
	for (int i=n;i>=1;i--) v2[i]=v2[i+1]+v[i];
	for (int i=1;i<=n;i++) ans=max(ans,v1[i]-x[i]);
	for (int i=n;i>=1;i--) ans=max(ans,v2[i]-m+x[i]);
	for (int i=1;i<=n;i++) tmp1[i]=max(tmp1[i-1],v1[i]-x[i]);
	for (int i=n;i>=1;i--) tmp2[i]=max(tmp2[i+1],v2[i]-(m-x[i])*2);
	for (int i=1;i<=n;i++) ans=max(ans,tmp1[i]+tmp2[i+1]);
	//printf("%lld %lld\n",tmp1,tmp2);
	//ans=max(ans,tmp1+tmp2); tmp1=tmp2=0;
	for (int i=1;i<=n;i++) tmp1[i]=max(tmp1[i-1],v1[i]-x[i]*2);
	for (int i=n;i>=1;i--) tmp2[i]=max(tmp2[i+1],v2[i]-(m-x[i]));
	for (int i=1;i<=n;i++) ans=max(ans,tmp1[i]+tmp2[i+1]);
	//printf("%lld %lld\n",tmp1,tmp2);
	//ans=max(ans,tmp1+tmp2);
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  for(int X, Y; cin >> X >> Y && (X|Y);) {
    if(X < Y) swap(X, Y);
    int t = 0;
    for(; Y; ++t) {
      X = X % Y;
      swap(X, Y);
    }
    cout << X << " " << t << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cmath>
#define rep(i,a) for(int i=0;i<(a);++i)

constexpr int MAX_N = 200;

int N;
int nsum;

int grundy( int n, int k )
{
  if( n % k == 0 )
    return n/k;
  
  int d = n/k;

  return grundy( n - ceil(double(n-k*d)/(d+1))*(d+1) , k );
}

int main()
{
  scanf( "%d", &N );
  rep( i, N )
  {
    int A, K;
    scanf( "%d%d", &A, &K );

    nsum ^= grundy( A, K );
  }

  if( nsum != 0 )
    puts( "Takahashi" );
  else
    puts( "Aoki" );
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax=1e5;
int N, M;
int X[Nmax];
int d[Nmax];

int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++) cin >> X[i];
	sort(X, X+M);

	for(int i=0; i<M-1; i++) d[i] = X[i+1]-X[i];

	sort(d, d+M-1);

	ll ans = 0;
	for(int i=0; i<M-N; i++) ans += d[i];

	cout << ans << endl;

	return 0;
}


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

int main(){
    int w,h,t;
    int p,tx,ty,tt;
    int s[50][50];
    int total=0;
    
    for (int i=0;i<50;i++)
        for (int j=0;j<50;j++)
            s[i][j]=0;
    
    cin >> w >> h >> t;
    cin >> p;
    
    for (int i=0; i<p;i++){
        cin >> tx >> ty >> tt;
        s[tx][ty]++;
    }
    
    for (int y=0;y<h;y++){
        for (int x=0;x<w;x++){
            cin >> t;
            if (t) total+=s[x][y];
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 1168
#include <cstdio>
#include <iostream>
using namespace std;
int w,a,b;
int main()
{
    scanf("%d%d%d",&w,&a,&b);
    if(a > b) swap(a,b);
    int x = a + w;
    if(x >= b)
        printf("0\n");
    else
        printf("%d\n",b - x);
    return 0;
}


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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
	char c;
	cin>>c;
	if(c>='A' && c<='Z') cout<<"A";
	else cout<<"a";
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i = 0; i < N; ++i)
    cin >> A[i];
  int ok = 1e9, ng = 0;
  while(ok-ng > 1){
    int m = (ok+ng)/2;
    long long k = 0;
    for(auto a : A){
      k += (a+m-1)/m - 1;
    }
    if(k <= K) ok = m;
    else ng = m;
  }
  cout << ok << endl;
}


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

int vis[12];
int main(){
    int a[4][4];
    for(int i = 1;i <= 3;i++)
    for(int j = 1;j <= 3;j++){
        cin>>a[i][j];
        vis[a[i][j]]=1;
    }
    int n,x;
    cin>>n;
    for(int i = 1;i <= n;i++){
        cin>>x;
        vis[x]=0;
    }
    if(vis[a[1][2]]==0) {
        if(vis[a[1][1]]==0&&vis[a[1][3]]==0){
            cout<<"Yes";return 0;
        }
    }
    if(vis[a[2][1]]==0) {
        if(vis[a[1][1]]==0&&vis[a[3][1]]==0){
            cout<<"Yes";return 0;
        }
    }
    if(vis[a[2][3]]==0) {
        if(vis[a[1][3]]==0&&vis[a[3][3]]==0){
            cout<<"Yes";return 0;
        }
    }
    if(vis[a[3][2]]==0) {
        if(vis[a[3][1]]==0&&vis[a[3][3]]==0){
            cout<<"Yes";return 0;
        }
    }
    if(vis[a[2][2]]==0) {
        if(vis[a[1][1]]==0&&vis[a[3][3]]==0) {
            cout<<"Yes";return 0;
        }
        else if(vis[a[1][3]]==0&&vis[a[3][1]]==0){
            cout<<"Yes";return 0;
        }
        else if(vis[a[1][2]]==0&&vis[a[3][2]]==0){
            cout<<"Yes";return 0;
        }
        else if(vis[a[2][1]]==0&&vis[a[2][3]]==0){
            cout<<"Yes";return 0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    K,S = (int(x) for x in input().split())

    count = 0

    for x in range(K+1):
        for y in range(K+1):
            z = S - (x + y)
            if z >= 0 and z <= K:
                count += 1

    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40940
n,m=map(int,input().split())
l1=[list(input().split()) for i in range(m)]
l2=["WA"]*n
l3=[0]*n
account=0
wacount=0
for i in range(m):
  if l1[i][1]=="WA" and l2[int(l1[i][0])-1]=="WA":
    wacount+=1
    l3[int(l1[i][0])-1]+=1
  if l1[i][1]=="AC":
    l2[int(l1[i][0])-1]="AC"

for i in range(n):
  if l2[i]=="AC":
    account+=1
  else:
    wacount-=l3[i]
print(account,wacount)


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

def main():
    dictionary = {}
    input_num = int(raw_input())
    counter = 0
    while counter < input_num:
        command, key = raw_input().split(' ')
        if command == 'insert':
            dictionary[key] = True
        else:
            if key in dictionary:
                print 'yes'
            else:
              print 'no'

        counter += 1


if __name__ == '__main__':
    main()

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

int main() {
	int N;
  	cin >> N;
  
  	int num1 = N % 10;
  	int num2 = N / 10;
  
  	if(num1 == 9 || num2 == 9) {
    	cout << "Yes" << endl;
    }else {
    	cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
#define mprint(x) printf(FORMATCONVERSION(x),(x))
#define FORMATCONVERSION(x) _Generic((x),\
                                    int:"%d",unsigned int:"%u",\
                                    double:"%lf",long long int:"%lld",\
                                    unsigned long long int:"%llu",\
                                    char :"%c",char*:"%s")

#define mswap(x,y) _Generic((x),int:swap_int,unsigned int:swap_uint,\
                            long long:swap_ll,unsigned long long:swap_ull)(&(x),&(y))

void swap_int(int *a,int *b){int tmp = *a;*a = *b;*b= tmp;return;}
void swap_uint(unsigned int *a,unsigned int *b){unsigned int tmp = *a;*a = *b;*b= tmp;return;}
void swap_ll(long long *a,long long *b){long long tmp = *a;*a = *b;*b= tmp;return;}
void swap_ull(unsigned long long *a,unsigned long long *b){unsigned long long tmp = *a;*a = *b;*b= tmp;return;}

int main(void){
    int n;
    scanf("%d",&n);

    int handtpair[10][10] = {};

    int temp = 0;
    for(int i = 1;i <= n;i++){
        temp = i;
        while(temp >= 10)temp /= 10;
        if(temp != 0 && i % 10 != 0)++handtpair[temp][i % 10];
    }

    long long int ans = 0;
    temp = 0;
    for(int i = 0;i <= n;i++){
        temp = i;
        while(temp >= 10)temp /= 10;
        if(temp != 0 && i % 10 != 0)ans += handtpair[i % 10][temp];
    }
    mprint(ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer price = sc.nextInt();
        sc.close();
        int change = 0;
        for (int i = 1; ; i++) {
            if (i * 1000 - price >= 0) {
                change = i * 1000 - price;
                break;
            }
        }
        System.out.println(change);
    } 
}

Measured memory_bytes: 35496
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2)
        cout << "Odd";
    else
        cout << "Even";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N + 1];
		long[] B = new long[N];
		for(int i = 0; i < N + 1; i++) {
			A[i] = sc.nextLong();
		}
		for(int i = 0; i < N; i++) {
			B[i] = sc.nextLong();
		}
		sc.close();
		long ans = 0L;
		for(int i = 0; i < N; i++) {
			// 勇者B[i]がモンスターA[i]を倒せる数
			long hit = Math.min(A[i], B[i]);
			// モンスターA[i]の残数
			// A[i] -= hit;
			// 勇者B[i]の残機
			B[i] -= hit;
			// 倒した合計の加算
			ans += hit;
			// 勇者B[i]がモンスターA[i + 1]を倒せる数
			hit = Math.min(A[i + 1], B[i]);
			// モンスターA[i + 1]の残数
			A[i + 1] -= hit;
			// 勇者B[i]の残機
			// B[i] -= hit;
			// 倒した合計の加算
			ans += hit;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 88516
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;

template<typename T> void print(T t) { cout << t << endl; }

int main() {
	int N, K;
	cin >> N >> K;
	double ans = 0;
	for (int n = 1; n <= N; n++) {
		double pn = 1.0 / N;
		for (int k = n; k < K; k *= 2) pn /= 2;
		ans += pn;
	}
	cout << fixed << setprecision(15);
	print(ans);
}



Measured memory_bytes: 3752
using System;
class A_Rounding{
	static void Main(string[] args){
		string[] Str = Console.ReadLine().Split(' ');
		int X = int.Parse(Str[0]);
		int A = int.Parse(Str[1]);
		if(X < A)Console.WriteLine("0");
		else Console.WriteLine("10");
		return;
	}
}

Measured memory_bytes: 13140
#include"bits/stdc++.h"

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

int main() {
	int h, m, a, b;
	double hd, hm,rd;
	double s, l;
	cin >> a >> b >> h >> m;
	hd = h * 30 + m * 0.5;
	hm = m * 6;
	if (hd == 0)hd = 360;
	if (hm == 0)hm = 360;
	s = min(a, b);
	l = max(a, b);
	if (hd < hm)rd = hm - hd;
	else rd = hd - hm;
	rd = rd * acos(-1) / 180;
	double ans = sqrt(a * a + b * b - 2 * a * b * cos(rd));
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}


Measured memory_bytes: 4228
#include<bits/stdc++.h>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
using namespace std;
template<typename T>inline void read(T &x)
{
	T s=0,f=1;char k=getchar();
	while(!isdigit(k)&&(k^'-'))k=getchar();
	if(!isdigit(k)){f=-1;k=getchar();}
	while(isdigit(k)){s=s*10+(k^48);k=getchar();}
	x=s*f;
}
void file()
{
	#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	#endif
}
char x;
bool a;
int main()
{
	while(scanf("%c",&x)!=EOF)
	{
		if(isupper(x))x-='A'-'a';
		if(x=='a')a=true;
		else
		{
			if(a&&x=='c')
			{
				printf("Yes\n");
				return 0;
			}
			a=false;
		}
	}
	printf("No\n");
	return 0;
}



Measured memory_bytes: 256
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll.sort(key=lambda x:x[1])

ans = 0
tmp = -10**9

for s, t in ll:
  if s >= tmp:
    ans += 1
    tmp = t

print(ans)

Measured memory_bytes: 21336
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define I_L_T_S ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
const int N = 1e5 + 2;
const int mod = 1e9 + 7;

long long binpow(long long a, long long b) {
    a %= mod;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int32_t main(){
   I_L_T_S;
   int n , k;
   cin >> k >> n;
   set <int> s;
   for(int i = n ; i <= n + k - 1; i++) {
        if(i <= 1e5)
        s.insert(i);
        else break;
    }
    int p = k;
    int t = n;
    while(p--){
        if(t>=-1e5){
        s.insert(t);
        }
        else break;
        t--;
    }   
    for(auto x : s) cout << x << " ";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#pragma 03
using namespace std;
struct pnt{
	double x, y;
};
double dis(pnt a, pnt b){
	double c = abs(a.x - b.x);
	double d = abs(a.y - b.y);
	return sqrt(c*c + d*d);
}
int main(){ 
	cout << fixed << setprecision(10);
	double n;
	cin >> n;
	pnt points[10];
	for (int i = 0; i<n; i++){
		cin >> points[i].x >> points[i].y;
	}
	double sum = 0;
	for (int i = 0; i<n; i++){
		for (int j = i+1; j<n; j++){
			sum += dis(points[i], points[j]);
		}
	}
	sum /= (n * (n-1));
	sum *= 2;
	cout << sum * (n-1) << endl;
    return 0; 
} 

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

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

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

int main ()
{
    long long x,y;
    while(cin>>x>>y){
    cout<<gcd(x,y)<<' '<<lcm(x,y)<<endl;
    }
    return 0;
}

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

int main(void) {
	string s;
	int cont = 0;

	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != s[i + 1]) {
			cont++;
		}
	}
	cout << cont - 1 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;u.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>u;
map<LL,LL>ww,cc;
LL ar[50000001];
LL br[50000001];
LL cr[500][500];
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
LL dxx[]= {-1,0,1,0};
LL dyy[]= {0,1,0,-1};
LL dx[]={2,1,-1,-2,-2,-1,1,2};
LL dy[]={1,2,2,1,-1,-2,-2,-1};
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
        UOSMOY;
        cin>>n;
        k=0;
        for(i=0;i<n;i++)
        {
            cin>>o;
            if(i%2==0 && o%2==1 )
            {
                k++;
            }
        }

        cout<<k<<endl;

    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>
int main(){
	int t[105],n[105],e[105],w[105],p[17],pt[17],i,j,k,l,x,y,b;
	for(i=0;i<100;i++){
		t[i]=i*5;
		n[i]=(i%5==1?5:2);
		e[i]=17*(i%2)+3*(i%3)+19;
		//printf("%d %d %d\n",t[i],n[i],e[i]);
	}
	memset(p,-1,sizeof(p));
	memset(pt,-1,sizeof(pt));
	memset(w,-1,sizeof(w));
	x=y=b=0;
	while(x<100){
		//printf("%3d:",b);
		for(i=0;i<17;i++){
			if(pt[i]==b){
				pt[i]=-1;
				p[i]=-1;
			}
			/*if(pt[i]==b){
				pt[i]=-1;
				p[i]=-1;
			}*/
		}
		if(b==t[y+1])y++;
		for(l=x;l<=y;l++){
			if(l==x){
			for(i=0;i<17;i++){
				for(j=0;j<n[l];j++){
					if(p[i+j]!=-1)break;
					//if(pt[i+j]-1==)
				}
				if(j==n[l]){
					for(k=0;k<n[l];k++){
						p[i+k]=l;
						pt[i+k]=b+e[l];
					}
					w[l]=b-t[l];
					//printf(" w[%d]=%d ",l,b);
					x++;
					break;
				}
			}
			}
		}
		b++;
	}
	while(scanf("%d",&i)!=EOF){
		printf("%d\n",w[i]);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin >> n >> k;
	ll r,s,p;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	ll ans = 0;
	vector <vector<ll>> dp(n,vector<ll>(3,0));
	for (int z=0;z<k;z++){
		int x = z;
		for (;x<n;x+=k){
			if (x-k >= 0){
				dp[x][0] = max(dp[x-k][1],dp[x-k][2]);
				dp[x][1] = max(dp[x-k][0],dp[x-k][2]);
				dp[x][2] = max(dp[x-k][0],dp[x-k][1]);
			}
			if (t[x] == 'r') dp[x][2] += p;
			if (t[x] == 's') dp[x][0] += r;
			if (t[x] == 'p') dp[x][1] += s;
		}
		ans += max({dp[x-k][0],dp[x-k][1],dp[x-k][2]});
	}
	cout << ans << endl;
}

Measured memory_bytes: 5840
#include<bits/stdc++.h>
using namespace std;
#define BeatMeScanf ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define sz 150010
const int mod=1000000007;

int main(){
    BeatMeScanf;
    int n;
    while(cin>>n){
        vector<int>v,ans;
        for(int i=0;i<n;i++){
            int a;
            cin>>a;
            v.push_back(a);
        }
        int x=1;
        for(int i=0;i<n;i++){
            if(v[i]==x){
                ans.push_back(x);
                x++;
            }
        }
        if(ans.size()==0) cout<<-1<<endl;
        else cout<<n-ans.size()<<endl;
    }
    return 0;
}


Measured memory_bytes: 2548
l = input().split()
taka = int(l[0])
aoki = int(l[1])
num = int(l[2])
for i in range(1,num+1):
	if i % 2 == 0:
		if aoki % 2 == 1:
			aoki += -1
		aoki = aoki //2
		taka += aoki
	elif i % 2 ==1:
		if taka % 2 == 1:
			taka += -1
		taka = taka // 2
		aoki += taka
print(taka,aoki)
	

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;




int main(){
    ll A;
    ld B;
    cin >> A >> B;
    ll ib = B*100+0.5;
    A *= ib;
    A /= 100;
    cout << A << endl;
}

Measured memory_bytes: 3700
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>


using namespace std;


int main() {

	long long x, y;
	int cnt = 0;

	cin >> x >> y;
	while (x <= y) {
		x *= 2;
		cnt++;
	}

	cout << cnt << endl;
	return 0;

	

}



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

using namespace std;

typedef complex<double> Point;
const double epx=1e-10;

Point read()
{
    int x,y;
    cin>>x>>y;
    return Point(x,y);
}

int ccw(Point a,Point b,Point c)
{
    b-=a;c-=a;a=c*conj(b);
    if(a.imag()>epx) return 1;
    if(a.imag()<-epx) return -1;
    if(a.real()<-epx) return 2;
    if(abs(b)+epx<abs(c)) return -2;
    return 0;
}

bool isIntersect(Point a,Point b,Point c,Point d)
{
    return (ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0);
}

double dot(Point a,Point b)
{
    return real(b*conj(a));
}

double cross(Point a,Point b)
{
    return imag(b*conj(a));
}

double dist(Point a,Point b,Point c)
{
    if(dot(b-a,c-a)<0) return abs(c-a);
    if(dot(a-b,c-b)<0) return abs(c-b);
    return abs(cross(b-a,c-a))/abs(b-a);
}

double dist(Point a,Point b,Point c,Point d)
{
    if(isIntersect(a,b,c,d)) return 0;
    double ab = min(dist(a,b,c),dist(a,b,d));
    double cd = min(dist(c,d,a),dist(c,d,b));
    return min(ab,cd);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<setprecision(10)<<fixed;
    int t;
    cin>>t;
    while(t--)
    {
        Point a,b,c,d;
        a = read(); b = read(); c = read(); d = read();
        cout<<dist(a,b,c,d)<<endl;
    }

    return 0;
}



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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
int n,m,q;
int a[55] , b[55] , c[55] , d[55];
int ans = 0;

void solve(vector<int> v , int mx = 1) {
   if(sz(v) == n + 1) {
      int cur = 0;
      f(i,0,q) if(v[b[i]] - v[a[i]] == c[i]) cur += d[i];
      ans = max(ans , cur);
      return ;
   }

   for(int i=mx ; i<=m ; i++) {
      v.push_back(i);
      solve(v , i);
      v.pop_back();
   }
}
int32_t main(){
   fast;
   cin >> n >> m >> q;
   f(i,0,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
   vector<int> v = {1};
   solve(v);
   cout << ans;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int A,B,M;
cin >> A >> B >> M;
vi a(A),b(B);
rep(i,A) cin >> a[i];
rep(i,B) cin >> b[i];

vi ans;

rep(i,M) {
    int x,y,c;
    cin >> x >> y >> c;
    x--;y--;
    ans.push_back(a[x]+b[y]-c);
}

sort(all(a));
sort(all(b));
ans.push_back(a[0]+b[0]);
cout << *min_element(all(ans)) << endl;
return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>

int main(void){
	int i,x,n;	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		x=i;
		if(x%3==0){
			printf(" %d",x);
		}else{
		while(x!=0){
			if(x%10==3){
				printf(" %d",i);
				break;
			}
			x/=10;
		}
		}
	}
	printf("\n");
return 0;
}


Measured memory_bytes: 2052
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        int cardCount = (int)inpt[0];

        long xPoint = inpt[1];
        long yPoint = inpt[2];

        inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        long ans = Math.Abs(inpt.Last() - yPoint);
        if(cardCount > 1) {
            ans = Math.Max(ans, Math.Abs(inpt[inpt.Length - 2] - inpt.Last()));
        }
        Console.WriteLine(ans);
    }

    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"




3 100 100
10 1000 100



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13432
x = input()

n = int(x)
cnt = 0
while n>1:
  n = n/10
  cnt+=1

# x[cnt-1]が1桁目
s = int(x[cnt-1])
if s == 3:
  print("bon")
elif s == 0 or s == 1 or s == 6 or s == 8:
  print("pon")
else:
  print("hon")

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

#define fi first
#define se second

#define N 100005

int n, m, D[N], id[N], d[N*2];

int col[N];

using pii = pair <int, int>;

vector <pii> v[N];

bool vis[N];

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i ++) scanf("%d", &D[i]), id[i] = i;
	for (int i = 1, x, y; i <= m; i ++) {
		scanf("%d %d", &x, &y);
		v[x].emplace_back(y, i);
		v[y].emplace_back(x, i);
	}
	sort(id+1, id+n+1, [](int x, int y) {return D[x] < D[y];});
	for (int i = 1; i <= n; i ++) {
		int u = id[i];
		if (vis[u]) continue;
		bool flag = 0;
		for (auto x : v[u]) if (vis[x.fi]) {
			d[x.se] = D[u];
			col[u] = col[x.fi] ^ 1;
			flag = 1;
			vis[u] = 1;
			break;
		}
		if (flag) continue;
		for (auto x : v[u]) if (D[x.fi] == D[u]) {
			d[x.se] = D[u];
			vis[u] = vis[x.fi] = 1;
			col[u] = 1, col[x.fi] = 0;
			flag = 1;
			break;
		}
		if (!flag) {
			puts("-1");
			return 0;
		}
	}
	for (int i = 1; i <= n; i ++) printf("%c", "BW"[col[i]]);
	puts("");
	for (int i = 1; i <= m; i ++) {
		if (d[i] == 0) d[i] = 1e9;
		printf("%d\n", d[i]);
	}
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000;

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

signed main() {
	ll n, m, a[1001], b[1001], c[1001], d[101][101];
  cin >> n >> m;
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
  }
  rep(i, n) {
    rep(j, n) {
      if (i == j) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }
  rep(i, m) {
    d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
    d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
  }
  rep(i, n) {
    rep(j, n) {
      rep(k, n) {
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }

  ll ans = 0;

  rep(i, m) {
    if (d[a[i]][b[i]] < c[i]) ++ans;
  }

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

Measured memory_bytes: 384
#include <iostream>
#include <vector> //動的配列確保//

 using namespace std;

int main()
{
 int i,k,n,max=0;
 cin >> k >> n;
 vector<int> a(n),sa(n);//int型の配列aをつくる//
for(i=0;i<n;i++) cin >> a[i];

for(i=0;i<n-1;i++){
     sa[i]=a[i+1]-a[i];
     if(sa[i]>max)
      max=sa[i];
}

sa[n-1] = k-a[n-1]+a[0];

if(max<sa[n-1]) max=sa[n-1];

cout << k-max << endl;
return 0;
}


Measured memory_bytes: 1792
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
if N < 1000:
    print("ABC")
else:
    print("ABD")


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;

int h,w,k;

ll solve(int x,vvi &v){
    //v中の0を敷き詰める
    for (int i=0;i<w;i++){
        int b1=1;
        while(b1){
            b1=0;
            for (int j=h-1;j>0;j--){
                if (v[j][i]==0 && v[j-1][i]!=0){
                    b1=1;
                    v[j][i]=v[j-1][i];
                    v[j-1][i]=0;
                }
            }
        }
    }
    //敷き詰めた後
    ll res=0;
    int b=0;
    for (int i=0;i<h;i++){
        vector<pair<int,int>> vp;
        int now=-1;
        int index=-1;
        int c=-1;
        for (int j=0;j<w+1;j++){
            if (now==v[i][j]){
                c+=1;
            }
            else{
                if (c>=k){
                    vp.push_back(make_pair(index,j-1));
                    b=1;
                }
                if (v[i][j]==0){
                    c=0;
                    now=-1;
                }
                else{
                    c=1;
                    now=v[i][j];
                    index=j;
                }
            }
        }
        for (auto p:vp){
            int num1=p.first,num2=p.second;
            res+=(1<<x)*(num2-num1+1)*v[i][num1];
            for (int j=num1;j<num2+1;j++){
                v[i][j]=0;
            }
        }
    }
    if (b){
        return res+solve(x+1,v);
    }
    else{
        return res;
    }

}

int main() {
    cin>>h>>w>>k;
    vvi graph(h,vi(w+1,0));
    rep(i,h){
        rep(j,w){
            char s;
            cin>>s;
            graph[i][j]=s-'0';
        }
        graph[i][w]=10000;
    }
    ll ans=0;
    for (int i=1;i<h;i++){
        for (int j=0;j<w;j++){
            auto g1=graph;
            g1[i][j]=0;
            ll ans1=solve(0,g1);
            ans=max(ans,ans1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
A=[]
for i in range(3):
    A.append(list(map(int,input().split())))
b=int(input())
for i in range(b):
    l=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==l:
                A[j][k]=0
a1=sum(A[0])
a2=sum(A[1])
a3=sum(A[2])
a4=A[0][0]+A[1][0]+A[2][0]
a5=A[0][1]+A[1][1]+A[2][1]
a6=A[0][2]+A[1][2]+A[2][2]
a7=A[0][0]+A[1][1]+A[2][2]
a8=A[2][0]+A[1][1]+A[0][2]
count=min(a1,a2,a3,a4,a5,a6,a7,a8)
if count==0:
     print("Yes")
else:
     print("No")

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> x(2,0);
    vector<int> y(N,0);
    for(int i = 0; i < M; ++i) {
        cin >> x.at(0) >> x.at(1);
        ++y.at(x[0]-1);
        ++y[x[1]-1];
    }
    for(int i=0; i<N; ++i) {
        cout << y[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  rep(i, 0, 3) rep(j, 0, 3) cin >> a[i][j];
  int n;
  cin >> n;
  rep(i, 0, n) {
    int b;
    cin >> b;
    rep(j, 0, 3) rep(k, 0, 3) {
      if (b == a[j][k]) a[j][k] = 0;
    }
  }
  bool ans = false;
  rep(i, 0, 3) {
    if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) ans = true;
  }
  rep(i, 0, 3) {
    if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) ans = true;
  }
  if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) ans = true;
  if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) ans = true;
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

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

    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll n = SZ(s);
    vvll dp(n,vll(4,1));
    dp[0][0] = 1;
    dp[0][1] = s[0] - '0';
    dp[0][2] = 0;
    dp[0][3] = 0;
    ll cnt = 2;
    for(ll i=1;i<n;i++){
        char c = s[i];
        for(ll j=1;j<4;j++){
            if(j!=cnt){
                dp[i][j] = 9*dp[i-1][j-1] + dp[i-1][j];
            }
            else{
                dp[i][j] = 9*(dp[i-1][j-1]-1) + dp[i-1][j] + (c-'0');
            }
        }
        if(c!='0'){
            cnt++;
        }
    }
    cout << dp[n-1][k] <<endl;


    
    return 0;
}



Measured memory_bytes: 3596
#                         author:  kagemeka 
#                         created: 2019-11-08 23:31:18(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 

def main():
    n, y = (int(i) for i in sys.stdin.readline().split())
    y //= 1000

    if 10 * n < y or n > y:
        print(-1, -1, -1)
        exit()

    for i in range(y // 10 + 1):
        for j in range((y - i * 10) // 5 + 1):
            k = n - (i + j)
            if 10 * i + 5 * j + k == y:
                print(i, j, k)
                exit()
    
    print(-1, -1, -1)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Measured memory_bytes: 3064
# include "iostream"
# include "cstdio"
# include "algorithm"

using namespace std;

const int maxm=1e5+10;

int ans=0x7fffffff; 
int N,K;
int Stack1[maxm],Top1;
int Stack2[maxm],Top2;
 
int main(){
	register int i;
	int x; 
	scanf("%d%d",&N,&K); 
	for(i=1;i<=N;i++){
		scanf("%d",&x);
		if(x<0){
			Stack1[++Top1]=-x; 
		}else{
			Stack2[++Top2]=x; 
		} 
	}
	sort(Stack1+1,Stack1+1+Top1);
	sort(Stack2+1,Stack2+1+Top2); 
	for(i=0;i<=min(Top1,K);i++){
		if(K-i>Top2 || K-i<0) continue; 
		int a=Stack1[i]+Stack2[K-i]*2,b=Stack1[i]*2+Stack2[K-i];
		ans=min(ans,min(a,b)); 
	}
	printf("%d",ans); 
	return 0;
}

Measured memory_bytes: 640