akhauriyash/Code-Regression huggingface dataset:
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  string s, t, u;
  cin >> s >> t >> u;
  cout << "A" << t[0] << "C";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a, b, c, k, d;
  scanf("%d %d %d %d", &a, &b, &c, &k);
d = 2*a+b-k;
  if(k<a){
    printf("%d", k);
  }else if(k<a+b){
    printf("%d", a);
  }else{
    printf("%d", d);
  }
}

Measured memory_bytes: 1724
#include <iostream>
#include <array>
#include <algorithm>

int main() {
    using namespace std;


    long long X;
    cin >> X;

    if (X <= 6)
    {
        cout << 1 << endl;
    }
    else
    {
        long long numTimes = X / 11;
        long long Check = X - numTimes * 11;
        if (Check == 0)
        {
            //exactly by 11
            numTimes = numTimes*2;
        } else if (Check <= 6)
        {
            //needs one more 6
            numTimes = numTimes*2 + 1;
        } else
        {
            //we need another 11
            numTimes = numTimes*2 + 2;
        }
        cout << numTimes << endl;
    }

    return 0;
}

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

const int N = 100 + 5;

char a[N][N]; 
int H, W, b[N][N];
bool hh[N], ww[N];

int cnt = 0;

int main(void) {
	memset(hh, true, sizeof(hh));
	memset(ww, true, sizeof(ww));
	scanf("%d%d", &H, &W);
	for (int i = 1; i <= H; ++ i) {
		scanf("%s", a[i] + 1);
		for (int j = 1; j <= W; ++ j) 
		if (a[i][j] == '.') b[i][j] = 0; else b[i][j] = 1;
		int sum = 0;
		for (int j = 1; j <= W; ++ j) sum += b[i][j];
		if (sum == 0) hh[i] = false;		
	}
	
	for (int i = 1; i <= W; ++ i) {
		int sum = 0;
		for (int j = 1; j <= H; ++ j) sum += b[j][i];
		if (sum == 0) ww[i] = false;
	}
	
	for (int i = 1; i <= H; ++ i) {
		bool ok = true;
		for (int j = 1; j <= W; ++ j) {
			if (!ww[j] || ! hh[i]) continue;
			cout << a[i][j]; ok = false;
		}
		if (! ok) cout << endl;
	}
	
	return 0;
}

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

int main(int argc, char **argv)
{
    std::vector<int> nums;

    int size;
    std::cin >> size;
    nums.resize(size);

    for (size_t i = 0; i < size; i++)
    {
        std::cin >> nums[i];
    }

    auto maxNumItr = std::max_element(nums.begin(), nums.end());
    size_t maxNumIndex = std::distance(nums.begin(), maxNumItr);
    int maxNum = *maxNumItr;
    nums.erase(maxNumItr);
    auto secondMax = std::max_element(nums.begin(), nums.end());

    for (size_t i = 0; i < size; i++)
    {
        if (i == maxNumIndex)
        {
            std::cout << *secondMax << std::endl;
            continue;
        }
        std::cout << maxNum << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int N;
    cin >> N;
    if (N % 2 == 0)
        cout << N << endl;
    else
        cout << N*2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

int D, L, L_D, ans;
LL pw[20];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	pw[0] = 1;
	for (int i = 1; i <= 18; i ++)
		pw[i] = pw[i - 1] * 10;
	int t = D = Read();
	if (D % 9)
		return puts("0"), 0;
	while (t)
		t /= 10, L_D ++;
	for (L = L_D; L <= L_D << 1; L ++)
	{
		int n = (L >> 1) - 1, ret = L & 1 ? 10 : 1;
		LL cur = D, tmp;
		for (int i = 0, f = 1; i <= n; i ++)
		{
			tmp = pw[L - 1 - i] - pw[i];
			if (cur >= 0)
				f = 1;
			else
				f = -1, cur = -cur;
			LL d = cur / tmp, c = cur - d * tmp, v = c % pw[i + 1];
			if (v)
			{
				if (v ^ 9 * pw[i])
					goto GG;
				d ++, c -= tmp;
			}
			if (d >= 10)
				goto GG;
			cur = c * f;
			ret *= 10 - (!i && (!d || f > 0)) - d;
		}
		if (!cur)
			ans += ret;
		GG:;
	}
	return printf("%d\n", ans), 0;
}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
double ave = 0;
vector<ll> a;

int main(){
  cin >> n;
  REP(i,n){
    ll x;
    cin >> x;
    a.push_back(x);
    ave += x;
  }
  ave /= n;
  ave = round(ave);
  ll ans = 0;
  REP(i,n){
    ans += (ave-a[i])*(ave-a[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<int>> bingo(3,vector<int> (3));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin>>bingo.at(i).at(j);
    }
  }
  int n;
  cin>>n;
  vector<int> b(n);
  for(int i=0; i<n; i++){
    cin>>b.at(i);
  }
  vector<vector<bool>> ans(3,vector<bool> (3,false));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      for(int k=0; k<n; k++){
        if(bingo.at(i).at(j)==b.at(k)){
          ans.at(i).at(j)=true;
        }
      }
    }
  }
  string s="No";
  for(int i=0; i<3; i++){
    if(ans.at(0).at(i)&&ans.at(1).at(i)&&ans.at(2).at(i)) s="Yes";
    else if(ans.at(i).at(0)&&ans.at(i).at(1)&&ans.at(i).at(2)) s="Yes";
  }
  if(ans.at(0).at(0)&&ans.at(1).at(1)&&ans.at(2).at(2)) s="Yes";
  if(ans.at(0).at(2)&&ans.at(1).at(1)&&ans.at(2).at(0)) s="Yes";
  cout<<s<<endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int q,k,z,r;
    for(int i=1;i<N+1;i++){
        q=i;
        while(1){
          z=q/10;
          k=q-z*10;
          if(k==3){r=1;break;}
          q=z;
          if(q==0){break;}
        }
        if(i%3==0||r==1) cout<<" "<<i;
        r=0;
    }cout<<endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a, b, p, x, y, z;

signed main() {
	cin >> n >> a >> b;
	rep(i,n) {
		cin >> p;
		if (p<=a) x++;
		else if (p<=b) y++;
		else z++;
	}
	cout << min(x, min(y, z)) << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main () {
  int a, b, c;
  std::cin >> a >> b >> c;
  if((a + b == c)||(b + c == a)||(c + a == b)) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

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

int main() {
    int n,a;
    cin>>n>>a;
    int b[n];
    for (int i=0;i<n;i++)
        cin>>b[i];
    ll dp[n+1][20000]{};
    dp[0][10000]=1;
    for (int i=0;i<n;i++) {
        int d=b[i]-a;
        for (int j=0;j<20000;j++) {
            dp[i+1][j]=dp[i][j];
            if (0<=j-d&&j-d<20000)
                dp[i+1][j]+=dp[i][j-d];
        }
    }
    cout<<dp[n][10000]-1<<endl;
    return 0;
}

Measured memory_bytes: 8192
#include<iostream>
using namespace std;
int n,m,a,h,p,q,i;
main(){
  cin.sync_with_stdio(0);
  while(cin>>n>>m>>a,n){
    int x[1001][101]={};
    while(cin>>h>>p>>q,x[h][p]=q,x[h][q]=p,--m);
    for(i=1000;i--;)x[i][a]&&(a=x[i][a]);
    cout<<a<<endl;
  }
}

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

int main(){
    int N,M,x,i,j;
    scanf("%d%d%d",&N,&M,&x);

    int n[N+1] = {0};
    int m[M] = {0};
    for(i=0; i<M; i++){
        scanf("%d",&m[i]);
    }

    for(i=0; i<M; i++){
        if(0 < m[i]){
            n[m[i]]++;
        }
    }

    int a=0;
    int b=0;

    for(i=x;i>0;i--){
        if(n[i]>0){
            a++;
        }
    }
    for(j=x;j<N+1;j++){
        if(n[j]>0){
            b++;
        }
    }
    
    if(a < b){
        printf("%d",a);
    }else{
        printf("%d",b);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=100005;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n,m;
      cin>>n>>m;
      int a[n+2]={0};
      for(int i=0;i<m;i++)
      {
            int x,y;
            cin>>x>>y;
            a[x]++;
            a[y+1]--;
      }
      int s=0;
      int ans=0;
      for(int i=1;i<=n;i++)
      {
            s+=a[i];
            ans+=(s==m);
      }
      cout<<ans;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<queue>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

struct Hop{
    int N,M;
    vvii G;
    vector<vector<int> >  done;
    int S,T;
    queue<P> que;
    Hop(){
        cin>>N>>M;
        G.resize(N);
        done.resize(3,vector<int>(N,-1));
        REP(i,M){
            int u,v; cin>>u>>v;
            u--; v--;
            G[u].push_back(v);
        }
        cin>>S>>T;
        S--; 
        T--;
    }


    int bfs(){
        que.push(P(0,S));
        while(!que.empty()){
            P now = que.front(); que.pop();
            bfs3(now.first, now.second);
        }
        return done[0][T];
    }

    void bfs3(int turn, int s){
        queue<P> que3;
        que3.push(P(0,s));
        while(!que3.empty()){
            P nownow = que3.front(); que3.pop();
            int ken = nownow.first; //何歩めか
            int v = nownow.second; //どの街か
            if(ken == 3){
                if(done[0][v] == -1){
                //done[0][v] = turn+1;
                Hop::que.push(P(turn+1, v));
                //return;
                }
            }

            else if(done[ken][v] == -1){
                done[ken][v] = turn;
                REP(k,G[v].size()){
                    int next = G[v][k];
                    que3.push(P(ken+1,next));
                }
            }

        }
    }
};

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    Hop hop;
    int ans = hop.bfs();
    cout << ans << endl;
}

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

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long ans = 0;
        int nEndA = 0;
        int nStartB = 0;
        int nSame = 0;
        int n = sc.nextInt();
        for(int i=0; i<n; i++){
            String s = sc.next();
            for(int j=0; j<s.length()-1; j++){
                if(s.charAt(j)=='A' && s.charAt(j+1) == 'B') ans++;
            }
            if(s.charAt(0) == 'B') nStartB++;
            if(s.charAt(s.length()-1) == 'A') nEndA++;
            if(s.charAt(0) == 'B' && s.charAt(s.length()-1) == 'A') nSame++;
        }

        ans += Math.min(nEndA, nStartB);
        if(nEndA == nSame && nStartB == nSame && nSame != 0) ans--;
        System.out.println(ans);
    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 26340
N = int(input())
P = list(map(int, input().split()))

cnt = 0
for n in range(1, N-1):
    if ((P[n-1] < P[n] and P[n] < P[n+1]) or (P[n+1] < P[n] and P[n] < P[n-1])):
        cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a <= b && b <= c && c <= d) cout << '0';
    else if (a <= c && c <= b && b <= d) cout << b - c;
    else if (a <= c && c <= d && d <= b) cout << d - c;
    else if (c <= a && a <= b && b <= d) cout << b - a;
    else if (c <= a && a <= d && d <= b) cout << d - a;
    else if (c <= d && d <= a && a <= b) cout << '0';
}


Measured memory_bytes: 3632
// template
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N);
    REP(i, N) cin >> H[i];
    int ans = -1;
    double mval = 1000.0;
    REP(i, N)
    {
        double diff = abs(A - (T - H[i] * 0.006));
        if (mval > diff)
        {
            ans = i + 1;
            mval = diff;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
# coding: utf-8

n = input()
A = []
for i in xrange(n):
    A.append( map(int, raw_input().split()) )

Max = -1
Maxidx = -1
for i in xrange(n):
    if Max < A[i][1]:
        Max = A[i][1]
        Maxidx = i
    elif Max == A[i][1] and A[Maxidx][0] > A[i][0]:
        Maxidx = i

print A[Maxidx][0], A[Maxidx][1]

Measured memory_bytes: 4248
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
if N == 1:
    print(1)
else:
    d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
    items = list(set(d_list))
    s = 1
    for item in items:
        c = d_list.count(item)
        if c > s:
            s = c
    print(N - s)

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

using namespace std;

const int INF = 1 << 30;

int N, K, A[100000];
int succ[36][101010];
vector< pair< int, int > > d;
vector< int > g[100000];


bool end()
{
  for(int i = 0; i < 35; i++) {
    for(int j = 0; j < N; j++) {
      succ[i + 1][j] = succ[i][succ[i][j]];
    }
  }
  for(int i = 0; i < N; i++) {
    int v = i;
    for(int j = 0; j < 35; j++) {
      if(K & 1LL << j) v = succ[j][v];
    }
    if(v != 0) return (false);
  }
  return (true);
}

int dist[100000];

void dfs(int idx)
{
  for(int to : g[idx]) {
    d[to] = {d[idx].first + 1, to};
    dfs(to);
  }
}

bool cut(int idx)
{
  int now = idx;

  if(dist[now] != -1) return (false);
  for(int i = 0; i < K - 1; i++) now = A[now];

  queue< int > que;
  dist[now] = 0;
  que.emplace(now);
  while(!que.empty()) {
    int p = que.front();
    que.pop();
    for(int to : g[p]) {
      if(dist[to] == -1) {
        dist[to] = dist[p] + 1;
        if(dist[to] < K - 1) que.push(to);
      }
    }
  }
  return (true);
}

void Calculation()
{
  cin >> N >> K;

  for(int i = 0; i < N; i++) {
    cin >> A[i];
    --A[i];
    succ[0][i] = A[i];
  }

  if(end()) {
    cout << 0 << endl;
    return;
  }

  int ret = 0;
  if(A[0] != 0) {
    ++ret;
    succ[0][0] = A[0] = 0;
    if(end()) {
      cout << 1 << endl;
      return;
    }
  }

  d.assign(N, {0, 0});
  for(int i = 1; i < N; i++) g[A[i]].push_back(i);
  dfs(0);
  sort(begin(d), end(d));
  reverse(begin(d), end(d));
  memset(dist, -1, sizeof(dist));
  for(int i = 0; i < N; i++) {
    if(d[i].first <= K) break;
    ret += cut(d[i].second);
  }
  cout << ret << endl;
}

int main()
{
  Calculation();
}

Measured memory_bytes: 24576
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n)]
arm = [list(map(int, input().split())) for _ in range(n)]

ans = -(10 ** 9)
# bin(100) '0b1100100'
# ビットで組み合わせを考えてる
for item in range(1, 1024):
    fund = 0
    for i in range(n):
        cou = 0
        for x in range(10):
            if (item >> x) % 2 == 1 and arr[i][x] == 1:
                cou += 1
        fund += arm[i][cou]
    ans = max(ans, fund)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

//階乗,二項係数
//*
ll fact[100010];
ll invfact[100010];
void makefact(int n,ll m){
	fact[0]=1;
	rep(i,0,n)fact[i+1]=fact[i]*(i+1)%m;
	invfact[n]=invp(fact[n],m);
	for(int i=n;i>0;i--)invfact[i-1]=invfact[i]*i%m;
}
ll choose(int n,int r,int m){return n<0||r<0||n-r<0?0:fact[n]*invfact[r]%m*invfact[n-r]%m;}
//*/

int main(){
	makefact(2000,MOD);
	int n,m;
	scanf("%d%d",&n,&m);
	ll s=0;
	rep(i,0,m+1)s=(s+choose(m,i,MOD)*pom(i,n,MOD)*((m-i)%2==0?1:-1))%MOD;
	printf("%lld\n",(s+MOD)%MOD);
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> iii;
typedef vector<iii> viii;

#define umap unordered_map
#define uset unordered_set
#define pb push_back
#define LSOne(x) (x & (-x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

const int iinf = 1e9+7;
const ll inf = 1e18+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,W; cin >> n >> W;
    vll dp(W+1,0);
    for (int i = 0; i < n; ++i) {
        ll w,v; cin >> w >> v;
        for (int i = W-w; i >= 0; --i) dp[i+w] = max(dp[i+w], dp[i]+v);
    }
    cout << dp[W] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int W,H,N;

  cin >> W >> H >> N;

  vector<int> x(N),y(N),a(N);

  for(int i=0;i<N;i++){
    cin >> x.at(i) >> y.at(i) >> a.at(i);
  }  

  int xr=0,xl=W,yu=0,yo=H;

  for(int i=0;i<N;i++){
    switch (a.at(i)) {
      case 1 : if(xr<x.at(i)) xr=x.at(i); break;
      case 2 : if(xl>x.at(i)) xl=x.at(i); break;
      case 3 : if(yu<y.at(i)) yu=y.at(i); break;
      case 4 : if(yo>y.at(i)) yo=y.at(i); break;

    }
  }

  if(xl<=xr||yo<=yu) cout << 0 << endl;
  
  else cout << (xl-xr)*(yo-yu) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int N;
    int a[110];
    cin >> N;
    for (int i=0; i<N;i++) cin >> a[i];

    sort(a, a+N, greater<int>());
    int Alice = 0;
    int Bob = 0;
    for (int i=0; i<N; i++) {
        if (i%2 == 0) Alice += a[i];
        else Bob += a[i];
    }
    cout << Alice - Bob << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
 
//#include<iostream>
using namespace std;
 
int main(){
    int w, n, a, b, i, t, ar[31];
	for(i=0; i<31; ++i) ar[i]=i;

	scanf("%d %d", &w, &n);
    for(i=0; i<n; ++i){
		scanf("%d,%d", &a, &b);
		t=ar[a]; ar[a]=ar[b]; ar[b]=t;
	}
	for(i=1; i<w+1; ++i)	printf("%d\n", ar[i]);

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}
 
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
 
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
 
 
using pll = pair<long long, long long>;
bool cmp(pll a, pll b) {
    return a.second < b.second;
}
 
 
int N;
vector<pll> v;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    while (cin >> N) {
        v.resize(N);
        for (int i = 0; i < N; ++i) cin >> v[i].first >> v[i].second;
        sort(v.begin(), v.end(), cmp);
 
        bool ok = true;
        long long sum = 0;
        for (int i = 0; i < N; ++i) {
            sum += v[i].first;
            if (sum > v[i].second) ok = false;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define s second
#define f first
long long const mod = 1000000007;
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}
#define MAX 100001

ll dp[101][101][2];
ll func(ll i,ll j,ll h,ll w,ll last,string s[])
{
    if(i==h-1 && j==w)
        return 0;
    if(i==h && j==w-1)
        return 0;
    if(i==h || j==w)
        return inf;
    
    if(dp[i][j][last]!=-1)
        return dp[i][j][last];
    ll ans=0;
    if(s[i][j]=='.')
    {
        ans=func(i+1,j,h,w,0,s);
        ans=min(ans,func(i,j+1,h,w,0,s));
    }
    else
    {
        if(last==1)
        {
            ans=func(i+1,j,h,w,1,s);
            ans=min(ans,func(i,j+1,h,w,1,s));
        }
        else
        {
            ans=func(i+1,j,h,w,1,s)+1;
            ans=min(ans,func(i,j+1,h,w,1,s)+1);
        }
        
    }
    dp[i][j][last]=ans;
    return ans;
}


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

    ll h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++)
        cin>>s[i];
    memset(dp,-1,sizeof(dp));
    cout<<func(0,0,h,w,0,s)<<endl;

    return 0;
}


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

typedef long long ll;

string t;
int win[4], val[4], dp[200100][4];

int go(int pos, int prev) {
	if(pos == t.size()) {
		return 0;
	}

	if(dp[pos][prev] != -1) return dp[pos][prev];

	if(t[pos] == '*') return dp[pos][prev] = go(pos + 1, 0);

	int ans = 0;

	for(int i = 1; i <= 3; i++) {
		if(i == prev) continue;

		int add = 0;
		if(i == win[t[pos] - '0']) add = val[i];

		ans = max(ans, add + go(pos + 1, i));
	}

	return dp[pos][prev] = ans;
}

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

	int n, k, r, s, p;
	cin >> n >> k >> r >> s >> p >> t;

	for(int i = 0; i < n; i++) {
		if(t[i] == 'r') t[i] = '1';
		if(t[i] == 's') t[i] = '2';
		if(t[i] == 'p') t[i] = '3';
	}

	win[1] = 3;
	win[2] = 1;
	win[3] = 2;

	val[1] = r;
	val[2] = s;
	val[3] = p;

	vector<string> w(k, "");

	for(int i = 0; i < n; i++) {
		w[i % k] += t[i];
	}

	t = "";

	for(int i = 0; i < k; i++) {
		if(i) t += "*";
		t += w[i];
	}

	memset(dp, -1, sizeof dp);

	cout << go(0, 0) << endl;
}

Measured memory_bytes: 23120
#include <bits/stdc++.h>
using namespace std;
int n;
int dp[100010][5];
int mapp[100010][5];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d%d%d",&mapp[i][1],&mapp[i][2],&mapp[i][3]);
		dp[i][1]=mapp[i][1]+max(dp[i-1][2],dp[i-1][3]);
		dp[i][2]=mapp[i][2]+max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=mapp[i][3]+max(dp[i-1][1],dp[i-1][2]);
	}
	printf("%d",max(max(dp[n][1],dp[n][2]),dp[n][3]));
	return 0;
} 

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
const double pi = 3.14159265358979323846;



void solve()
{
	int i=0,j=0,k=0,n=0,m=0;
    float x,y;
    cin>>x>>y;
    if(floor((y-2*x)/2)==(y-2*x)/2 and y-2*x>=0 and floor((4*x-y)/2)==(4*x-y)/2 and 4*x-y>=0)
    cout<<"Yes";
    else cout<<"No";
    
}
int main() {
    fast
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 3732
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;

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

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;
int N;

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

  std::cin >> S;

  N = S.size();

  int res = 0;

  for(int i=0;i<N/2;++i){
      if(S[i] != S[N-1-i]){
          res += 1;
      }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }

int main() {
  string s;
  while (cin >> s) {
    YesNo(equal(ALL(s), s.rbegin()));
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
   lint dp[1005][1005];
  int main(){      
       lint h,w;
       cin>>h>>w;
       char x[h][w];
       rep(i,h){
           rep(j,w){
               cin>>x[i][j];
           }
       }
       dp[1][1]=1;
       rep(i,h){
           rep(j,w){
               if(x[i][j]=='#')continue;
               dp[i+1][j+1]+=dp[i][j+1]+dp[i+1][j];
               dp[i+1][j+1]%=MOD;
           }
       }
  
              cout<<dp[h][w];
      }
  
     


Measured memory_bytes: 9344
n = int(input())
A = list(map(int, input().split()))
dp = [0] * 9
for i in A:
    s = i // 400
    if s >= 8:
        dp[-1] += 1
    else:
        dp[s] = 1
 
ans = 0
for j in range(len(dp) - 1):
    ans += dp[j]
    
if ans == 0:
    print(1, dp[-1])
else:    
    print(ans, sum(dp))

Measured memory_bytes: 3064
#include <string>
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;
int main() {
    int H, W;
    cin >> H >> W;

    vector<vector<char> > v;
    for (int i = 0; i < H; i++) {
        string temp;
        cin >> temp;
        vector<char> a;
        v.push_back(a);
        for (auto&& s : temp) {
            v[i].push_back(s);
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (v[i][j] != '#'){
                int cnt = 0;

                // 左上
                if (i > 0 && j > 0 && v[i-1][j-1] == '#') {
                    cnt++;
                }

                // 上
                if (i > 0 && v[i-1][j] == '#') {
                    cnt++;
                }

                // 右上
                if (i > 0 && j < W-1 && v[i-1][j+1] == '#') {
                    cnt++;
                }

                // 左
                if (j > 0 && v[i][j-1] == '#') {
                    cnt++;
                }

                // 右
                if (j < W-1 && v[i][j+1] == '#') {
                    cnt++;
                }

                // 左下
                if (i < H-1 && j > 0 && v[i+1][j-1] == '#') {
                    cnt++;
                }

                // 下
                if (i < H-1 && v[i+1][j] == '#') {
                    cnt++;
                }

                // 右下
                if (i < H-1 && j < W-1 && v[i+1][j+1] == '#') {
                    cnt++;
                }

                // v[i][j] = (char)cnt;
                printf("%d", cnt);
            } else {
                printf("#");
            }
        }
        printf("\n");
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#include<vector>
#include<algorithm>
#include<string>
using ll=long long;
using P =pair<int,int>;


int main(){
  int K;
  cin >> K;
  vector<ll>a;
  rep(i,9)a.push_back(i+1);
  ll x=0;
  while(1){
    if(K<=a.size()){
      cout << a[K-1];
      break;
    }
    if(a[x]%10==0){rep(i,2)a.push_back(a[x]*10+i);}
    else if(a[x]%10==9){rep(i,2)a.push_back(a[x]*10+8+i);}
    else {rep(i,3)a.push_back(a[x]*10+a[x]%10+i-1);}
    x++;

  }
  return 0;
}






Measured memory_bytes: 1400
import java.util.*;
import java.io.*;
import java.lang.*;

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

        if (b>=a)
            System.out.println(a);
        else
            System.out.println(a-1);
    }
}


Measured memory_bytes: 35664
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,k;
    cin>>a>>b>>k;
    set<ll>s;
    for(ll i=a;i<=min(b,a+k-1);i++){
        s.insert(i);
    }
    for(ll i=b;i>=max(a,b-k+1);i--){
        s.insert(i);
    }
    for(auto x:s){
        cout<<x<<"\n";
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;
#define MAXN 505
int a[MAXN][MAXN];
int h,w;
struct node{
	int x1,y1,x2,y2;
};
vector<node> ans;
int main()
{
    scanf("%d %d",&h,&w);
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            scanf("%d",&a[i][j]);
    for(int i=1;i<=h;i++)
        for(int j=1;j<w;j++)
            if(a[i][j]%2)
            {
				a[i][j]--,a[i][j+1]++;
				node t;
				t.x1=i,t.y1=j,t.x2=i,t.y2=j+1;
				ans.push_back(t);
			}
    for(int i=1;i<h;i++)
        if(a[i][w]%2)
		{
			a[i][w]--,a[i+1][w]++;
			node t;
			t.x1=i,t.y1=w,t.x2=i+1,t.y2=w;
			ans.push_back(t);
		}
	int siz=ans.size();
	printf("%d\n",siz);
	for(int i=0;i<siz;i++)
		printf("%d %d %d %d\n",ans[i].x1,ans[i].y1,ans[i].x2,ans[i].y2);
    return 0;
}

Measured memory_bytes: 5104
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

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

  unordered_map<int64_t, int64_t> map;
  int32_t N;
  cin >> N;
  int64_t sum = 0;
  for (int i = 0; i < N; i++) {
    int64_t A;
    cin >> A;
    map[A]++;
    sum += A;
  }
  int32_t Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int64_t b, c;
    cin >> b >> c;
    int64_t bcnt = map[b];
    sum -= bcnt * b;
    map[b] = 0;
    sum += bcnt * c;
    map[c] += bcnt;
    cout << sum << endl;
  }


  return 0;
}


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

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

    int coin = 0;
    int days = 0;
    
    while(coin < c){
        days++;
        coin += a;
        if(days % 7 == 0){
            coin += b;
        }
    }

    cout << days << endl;
}



Measured memory_bytes: 3124
import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int,input().split()))
cnt = []
A = np.array(A)
for _ in range(60):
    ad = A % 2
    cnt.append(int(np.sum(ad)))
    A = A // 2
ans = 0
for i in range(60):
    num0 = N - cnt[i]
    num1 = cnt[i]
    ans += ((num0 * num1) * (2 ** i)) % MOD
    ans %= MOD
print(ans)

Measured memory_bytes: 48828
#include<bits/stdc++.h>
using namespace std;
int flag[200005];
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        flag[a[i]]++;
    }
    sort(flag,flag+200005,greater<int>());
    int c=0;
    for(int i=k;i<=n;i++)
    {
        c+=flag[i];
    }
    cout<<c<<endl;

}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        StringBuffer s = new StringBuffer(sc.next());
        int q = sc.nextInt();
        int pn = 0;
        StringBuffer plus = new StringBuffer();
        StringBuffer minus = new StringBuffer();
        for (int i=0;i<q;i++){
            if (sc.nextInt()==1){
                pn++;
            }else {
                if ((sc.nextInt()-1+pn)%2==0){
                    plus.append(sc.next());
                }else {
                    minus.append(sc.next());
                }
            }
        }
        if (pn%2==1){
            plus.reverse();
            s.append(minus);
            s.insert(0,plus);
        }else {
            s.reverse();
            minus.reverse();
            s.append(plus);
            s.insert(0,minus);
        }
        s.reverse();
        System.out.println(s);
    }
}


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

int main()
{
    int N;
    string ans = "No";
    cin >> N;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0;  j < 10;  j++)
        {
            if (i * j == N)
                ans = "Yes";
        }
        }

    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	a := intSliceScanner(n)
	ans := 0
	x := -1
	for i := 0; i < n; i++ {
		if ans == -1 {
			break
		}
		if a[i] == x+1 && a[i] <= i {
			x += 1
		} else if a[i] <= x && a[i] <= i {
			ans += x
			x = a[i]
		} else {
			ans = -1
		}
	}
	if ans >= 0 {
		ans += x
	}
	fmt.Println(ans)
}


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

int main() {
  string str;
  cin >> str;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string cmd;
    cin >> cmd;
    if (cmd == "print") {
      int a, b;
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    } else if (cmd == "reverse") {
      int a, b;
      cin >> a >> b;
      string tmp = str.substr(a, b - a + 1);
      reverse(tmp.begin(), tmp.end());
      str.replace(a, b - a + 1, tmp);
    } else if (cmd == "replace") {
      int a, b;
      cin >> a >> b;
      string p;
      cin >> p;
      str.replace(a, b - a + 1, p);
    }
  }
}


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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,ans=0;
    cin >> n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ans+=gcd(i,gcd(j,k));
            }
        }
    }
    cout << ans << endl;

    return 0;
}











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

int main() {
	int h, n, a, sum = 0;
	cin >> h >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a;
		sum += a;
	}
	if(sum >= h)
	cout << "Yes" << endl;
	else
	 cout << "No" << endl;
	return 0;
}

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

using int64 = long long;

int64 A[200000];
int64 cumA[200000];

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

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

        cumA[i] += A[i];
        if (i > 0) cumA[i] += cumA[i - 1];
    }

    int64 ans = 0;
    map<int64, int64> counter;
    for (int i = N - 1; i >= 0; i--) {
        counter[cumA[i]]++;

        int64 x = (i > 0) ? cumA[i - 1] : 0;
        ans += counter[x];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int n,h[20];

int main() {
    cin >> n;
    rep(i,n)cin>>h[i];
    int ans = 1;
    int mx = h[0];
    reps(i, n-1){
        if(h[i] >= mx){
            ans++;
            mx = h[i];
        }
    }
    cout << ans << endl; 
}



Measured memory_bytes: 256