akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a,n;
	cin >> a >> n;
	if(a <= 8 && n <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    ab = LIR(n)
    ab = ab[::-1]
    ans = 0
    for a, b in ab:
        ans += (b - (a + ans) % b) % b
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 58076
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;


int n,q;
string s;
char t[200010],d[200010];
int can(int x){
    int now=x;
    rep(i,q){
        if(s[now]==t[i]){
            if(d[i]=='L') now--;
            else now++;
        }
        if(now==-1) return 1;
        else if(now==n) return 2;
    }
    return 0;
}




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>q>>s;
    rep(i,q) cin>>t[i]>>d[i];
    int l=0,r=n+1;
    while(r-1>l){
        int mid=(r+l)/2;
        if(can(mid)==1) l=mid;
        else r=mid;
    }
    int ans=l;
    l=0;r=n+1;
    while(r-1>l){
        int mid=(r+l)/2;
        if(can(mid)==2) r=mid;
        else l=mid;
    }
    ans +=n-r+1;
    if(ans>=n){
        cout<<0<<endl;
    }
    else cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 976
#include<stdio.h>
int main(){
  int h,w,i,j;
  while(scanf("%d %d",&h,&w)){
    if(h==0 && w==0)break;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(i==0 || i==h-1){
	  printf("#");
	}
	else if(j==0 || j==w-1){
	  printf("#");
	}
	else{
	  printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  return(0);
}

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

int main(void){
    int N, Q;
    
    cin >> N >> Q;
    string ans = "kogakubu10gokan";
    int year = 0;
    for(int i=0; i < N; i++){
        int y;
        string name;
        cin >> y >> name;
        if(y >= year && Q >= y){
            y = year;
            ans = name;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1208
a[200],b[200],c[1000],d[1000],n,m,i,j,k,t,w,q;main(){for(;;){scanf("%d",&n);if(!n)break;for(i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);}scanf("%d",&m);for(i=0;i<m;i++){scanf("%d%d",&c[i],&d[i]);}for(i=0;i<m;i++){w=c[i]-a[0];q=d[i]-b[0];for(j=1;j<n;j++){for(k=0;k<m;k++){if(a[j]+w==c[k]){if(b[j]+q==d[k]){t++;break;}}}}if(t==n-1){printf("%d %d\n",w,q);t=0;break;}t=0;}}return 0;} 

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

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    ll x; cin >> x;
    vector<ll> v;

    /*
    for (ll i = 1; i*i*i*i*i <= 1e9; i++) {
        v.push_back(i*i*i*i*i);
    } */
    for (ll i = 0; i <= 1000; i++) {
        if (i*i*i*i*i < 0) break;
        v.push_back(i);
    }

    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v.size(); j++) {
            if (v[i]*v[i]*v[i]*v[i]*v[i] - v[j]*v[j]*v[j]*v[j]*v[j] == x) {
                cout << v[i] << ' ' << v[j] << '\n';
                return 0;
            }
            if (v[i]*v[i]*v[i]*v[i]*v[i] + v[j]*v[j]*v[j]*v[j]*v[j] == x) {
                cout << v[i] << ' ' << -v[j] << '\n';
                return 0;
            }
        }
    }


    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int a; cin >> a;
    cout << a+a*a+a*a*a << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

ll N;
vector<ll> a;

int main() {
    cin >> N;
    a.resize(N * 3);
    rep(i, N * 3) {
        cin >> a[i];
    }

    // 最大化する
    priority_queue<ll, vector<ll>, greater<ll>> pq1;
    ll positive = 0;
    rep(i, N) {
        pq1.push(a[i]);
        positive += a[i];
    }

    // ll d = pq1.top(); pq1.pop();
    // cout << d << endl;

    // 最小化する
    priority_queue<ll> pq2;
    ll negative = 0;
    int cnt = 0;
    for (ll i = 2 * N; i < 3 * N; i++) {
        pq2.push(a[i]);
        negative += a[i];
    }


    vector<ll> d1(N + 1);
    d1[0] = positive;
    ll idx = 1;
    for (ll i = N; i < 2 * N; i++) {
        ll q1 = pq1.top();
        if (a[i] > q1) {
            positive += a[i];
            positive -= q1; 
            pq1.pop();
            pq1.push(a[i]);
        }
        d1[idx] = positive;
        idx++;
    }

    // cout << negative << endl;
    vector<ll> d2(N + 1);
    d2[N] = negative; 
    ll idx2 = N - 1;
    for (ll i = 2 * N - 1; i >= N; i--) {
        ll q2 = pq2.top();
        if (a[i] < q2) {
            negative += a[i];
            negative -= q2; 
            pq2.pop();
            pq2.push(a[i]);
        }
        d2[idx2] = negative;
        idx2--;
    }
    // rep(i, N) {
    //     cout << d2[i] << endl;
    // }
    
    ll ans = -INF;
    rep(i, N + 1) {
        ans = max(ans, d1[i] - d2[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 5876
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define int long long
#define mod 1000000007
#define vi vector<ll>
#define pb push_back
#define mp make_pair
#define sp(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
#define str string
#define all(v) v.begin(),v.end()
void kehsihba() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main(){
	//kehsihba();
	ll n,w;
	cin>>n>>w;
	int a[n];
	int b[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	ll t[n+1][w+1];
	for(int i=0;i<=w;i++){
		t[0][i]=0;
	}
	for(int i=0;i<=n;i++){
		t[i][0]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			if(a[i-1]<=j){
				t[i][j]=max(t[i-1][j],b[i-1]+t[i-1][j-a[i-1]]);
			}
			else{
				t[i][j]=t[i-1][j];
			}
		}
	}
	cout<<t[n][w];
}


Measured memory_bytes: 79104
import itertools
import math
import sys

X = list(range(-200,201))

X_list = list(map(lambda x: x ** 5, X))

# print(X_list)

ans = int(input())

# print(X_list[0])
# print(math.sqrt(X_list[200]))
for x in itertools.combinations(X_list, 2):
  if x[0]-x[1] == ans:
      a =abs(x[0]**(1/5))
      b =abs(x[1]**(1/5))
      if x[0] < 0:
          a = a*(-1)
      if x[1] < 0:
          b = b*(-1)
    #   print(x[0],x[1])
      print(int(a),int(b))
      sys.exit()
  if x[1]-x[0] == ans:
      a = abs(x[1]**(1/5))
      b = abs(x[0]**(1/5))
      if x[1] < 0:
          a = a*(-1)
      if x[0] < 0:
          b = b*(-1)
    #   print(x[1],x[0])
      print(int(a),int(b))
      sys.exit()


Measured memory_bytes: 9392
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int,int>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define M 998244353

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;

    while(t--)
    {
        int N;
        cin>>N;
        string S;
        cin>>S;
        int R=0,G=0,B=0;
        for(int i=0;i<N;i++)
        {
            if(S[i]=='R')
            R++;
            else if(S[i]=='G')
            G++;
            else if(S[i]=='B')
            B++;
        }
      //cout<<R<<G<<B;
        
        int ans=(R*G*B);
       // cout<<ans<<endl;
        for(int i=0;i<N;i++)
        {
            for(int j=i+1;j<N;j++)
            {
                if(S[i]==S[j]) continue;
                
                //int l=j-i;
                int k=j+j-i;
                
                if(k<0 || k>=N)
                continue;
                if(S[i]==S[k] || S[j]==S[k])
                {continue;}
              //  cout<<i<<" "<<j<<" "<<k<<" \n";
                ans--;
            }
        }
        cout<<ans;
        
    }

   return 0;

//    cout<<"Sum of x+y = " << z;
}


Measured memory_bytes: 3620
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <vector>
using namespace std;


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

  vector<int> a(N);
  int x;
  int total = 0;
  for (int i = 0; i < N; i++) {
    cin >> x;
    a[i] = x;
    total ^= x;
    // cout << "x = " << x << ", total = " << total << endl;
  }

  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    int ans = total ^ a[i];
    cout << ans;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3952
#include <stdio.h>

#define Mod 1000000007

int main()
{
	int H, W, K;
	scanf("%d %d %d", &H, &W, &K);

	int i, j, k;
	long long dp[101][9] = {{0, 1}}, comb[8] = {1, 1, 2, 3, 5, 8, 13, 21};
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) dp[i][j] = dp[i-1][j] * comb[j-1] * comb[W-j];
		for (j = 1; j < W; j++) dp[i][j+1] += dp[i-1][j] * comb[j-1] * comb[W-j-1];
		for (j = 2; j <= W; j++) dp[i][j-1] += dp[i-1][j] * comb[j-2] * comb[W-j];
		for (j = 1; j <= W; j++) dp[i][j] %= Mod;
	}
	
	printf("%lld\n", dp[H][K]);
	fflush(stdout);
	return 0;
}

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

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

    std::unordered_map<uint64_t, uint64_t> m;
    int a;
    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        if (m.count(a) == 0) {
            m[a] = 1;
        } else {
            m[a] += 1;
        }
    }

    uint64_t cnt = 0; 
    for (auto const& p : m) {
        if (p.first < p.second) {
            cnt += (p.second - p.first);
        } else if (p.first > p.second) {
            cnt += (p.second);
        }
    }

    std::cout << cnt << std::endl;


    return 0;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
 
#define INF INT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
 
typedef long long ll;
typedef std::pair<int,int> pii;
 
using namespace std;
 
ll max_v = 10000;

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

    ll n,w;
    cin >> n >> w;
    vector<vector<ll>> wv(n,vector<ll>(2,0)),dp(n+1,vector<ll>(max_v*n+1,INF));
    REP(i,n)cin >> wv[i][0] >> wv[i][1];

    dp[0][0] = 0;
    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= n*max_v;j++){
            ll ww = wv[i-1][0], vv = wv[i-1][1];
            if(j - vv < 0 || dp[i-1][j - vv] + ww > w){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = min(dp[i-1][j],dp[i-1][j - vv] + ww);
            }
        }
    }

    ll ans = 0;
    for(int i = n*max_v;i >= 0;i--){
        if(dp[n][i] < INF){
            ans = i;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 797564
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

bool check(string s){
    for(int i = 0; i < s.size()/2; i++){
        if(s[i] != s[s.size()-i-1]) return false;
    }
    return true;
}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    cout << (check(s) && check(s.substr(0, (n-1)/2)) && check(s.substr((n+1)/2, n)) ? "Yes" : "No") << '\n';
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;
ll bit_kosu[61];


int main(){
    ll n;
    cin >> n;
    REP(i, n) {
        ll tmp;
        cin >> tmp;
        REP(j, 60) {
            if((tmp >> j) & 1) {
                bit_kosu[j]++;
            }
        }
    }
    ll ans = 0;
    ll modint = 1000000007;

    REP(j, 60) {
        long long  tmp = (long long)1 << j;
        //printf( "case3: %lld\n", tmp);
        tmp %= modint;
        tmp *= bit_kosu[j];
        tmp %= modint;
        tmp *= (n - bit_kosu[j]);
        tmp %= modint;
        
        ans += tmp;
        ans %= modint;

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int h,w,c;
int p[10][10];
int ans;

struct data{
  int i,j;
  data(int a,int b){i=a;j=b;}
};

bool isVisit[10][10];
int di[]={0,0,1,-1}, dj[]={1,-1,0,0};
int count(int i, int j){
  if( i<0||j<0 ) return 0;
  if( i>=h||j>=w ) return 0;
  if( isVisit[i][j] ) return 0;
  if( p[i][j] != c )return 0;

  int rtn =1;
  isVisit[i][j] = true;
  for( int d=0;d<4;d++ )
    rtn += count(i+di[d], j+dj[d]);

  return rtn;
}

vector<data> haveSameC(int i,int j, int c){
  vector<data> v;
  if( i<0||j<0 ) return v;
  if( i>=h||j>=w ) return v;
  if( isVisit[i][j] ) return v;
  if( p[i][j] != c ) return v;

  isVisit[i][j] = true;
  v.push_back( data(i,j) );
  for( int d=0;d<4;d++ ){
    vector<data> dd = haveSameC(i+di[d], j+dj[d], c);
    for( int k=0;k<(int)dd.size();k++ )
      v.push_back( dd[k] );
  }
  return v;
}

void rec(int n){ // 0<c<=6
  if( n==0 ){
    // count color
    for( int i=0;i<h;i++ )
      for( int j=0;j<w;j++ )
	isVisit[i][j] = false;
    ans = max( ans, count(0,0) );

    return ;
  }
  n--;

  for(int i=0;i<h;i++ )
    for( int j=0;j<w;j++ )
      isVisit[i][j] = false;

  int orgC = p[0][0];
  vector<data> same = haveSameC(0,0, orgC);
  //  cout << n << " :" << same.size() << endl;
  for( int cc=1;cc<=6;cc++ ){
    if( cc == orgC )
      continue;
    for( int i=0;i<(int)same.size();i++ ){
      data &d = same[i];
      p[d.i][d.j] = cc;
    }
    rec(n);
  }
  for( int i=0;i<(int)same.size();i++ ){
    data &d = same[i];
    p[d.i][d.j] = orgC;
  }

}

int main(){
  while(cin>>h>>w>>c,h){
    for( int i=0;i<h;i++ )
      for( int j=0;j<w;j++ )
	cin >> p[i][j];
    ans=0;
    rec(5);
    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
    double t, x;
    cin >> t >> x;

    cout << fixed << setprecision(10) << t / x << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  int n; cin >> n;
  long long sum = 0;
  for(int i=1; i<=n; i++) {
    for(int j=1; j<=n; j++) {
      int p = __gcd(i, j);
      for(int k=1; k<=n; k++) {
        sum += __gcd(p, k);
      }
    }
  }
  cout << sum << endl;

  return 0;
}

// EOF


Measured memory_bytes: 3612
//we'll get thru it believe me 
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
void max_self(int& a, int b){
	a=max(a, b);
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    const int INF=INT_MAX;
    vector<vector<int>>dp(n, vector<int>(3, -INF)), A(n, vector<int>(3));
    for(int i=0; i<n; i++)
		for(int j=0; j<3; j++)cin>>A[i][j];
	for(int i=0; i<3; i++)dp[0][i]=A[0][i];
	for(int i=0; i<n-1; i++){
		for(int j=0; j<3; j++){
			for(int x=0; x<3; x++){
				if(x==j)continue;
				max_self(dp[i+1][x], dp[i][j]+A[i+1][x]);
			}
		}
	}
	cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(1000001, 0), c(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> c[i];
        ++a[c[i]];
    }
    for (int i = 1000000; i >= 1; --i)
        for (int j = 2 * i; j < 1000001; j += i)
            a[j] += a[i];
    int odp = 0;
    for (int i = 0; i < n; ++i)
        if (a[c[i]] == 1)
            ++odp;
    cout << odp;
    return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << std::fixed << std::setprecision(10);

	long long h;
	cin >> h;
	int n = 0;
	while (1){
		n++;
		h = h / 2;
		if (h == 0)break;
	}

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += pow(2, i);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int adj[100][100],i,j,n,u,k,v;

  for(i=0;i<100;i++){
    for(j=0;j<100;j++) adj[i][j]=0;
  }
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      adj[i][v-1]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j==(n-1)) printf("%d",adj[i][j]);
      else printf("%d ",adj[i][j]);
    }
    printf("\n");
  }

  return 0;
}




Measured memory_bytes: 2112
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = rint;

	long inf = 1_000_000_999;

	X[] xs;
	foreach(i; 0 .. n){
		long x = rlong, l = rlong;
		xs ~= X(x - l, x + l);
	}
	xs.sort!"(a.l!=b.l)?(a.l<b.l):(a.r<b.r)"();
	log("xs:", xs);

	int ans = n;
	long r = -inf;
	foreach(x; xs){
		log("x:", x, "r:", r);
		if(r <= x.l) r = x.r;
		else{
			ans -= 1;
			r = min(r, x.r);
		}
		log("r:", r, "ans:", ans);
	}

	ans.writeln;
}

struct X{
	long l, r;
}

Measured memory_bytes: 4476
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>

using namespace std;


int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    if(n%2==0)
        cout<<n;
    else cout<<2*n;    
}


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

using namespace std;

int main(void) {
    string S;
    cin >> S;

    int ans = 0;
    for(int i=1; i<S.size(); i++) {
        if(S[i-1] != S[i]) ++ans;
    }

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


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

int main() {
    long long int X, year;
    long long int m = 100;
    year = 0;
    cin >> X;
    while (1) {
        m += m * 0.01;
        ++year;
        if (m >= X) {
            cout << year << endl;
            break;
        }
    }
}

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

using namespace std;

int main(){
    int n, ans = 0;
    scanf("%d", &n);
    while(n--){
        int a, b;
        scanf("%d %d", &a, &b);
        ans += b-a+1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
dif = B - A
if dif == 0 and N == 1:
    print(1)
    exit()
if dif < 0 or N == 1:
    print(0)
    exit()
ans = (((B * N - dif) - (A * N + dif))  + 1)
print(ans)

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

typedef long long int ll;
#define f(a, b) for(auto i = a;i < b;i++)
#define ent cout << "\n"

bool sortbysec(const pair<ll, ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

void solve()
{
	ll flag = 0, i = 0;
	string str;
	cin >> str;

	while(str[i] != '\0'){
		if(str[i] == '7'){
			flag = 1;
			break;
		}
		i++;
	}
	if(flag)
		cout << "Yes\n";
	else
		cout << "No\n";

	return;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);	
	
	solve();

}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int len[] = {5,7,5,7,7};
int main(){
  string str;
  map<char,int> score;
  score['I'] = 1;
  score['V'] = 5;
  score['X'] = 10;
  score['L'] = 50;
  score['C'] = 100;
  score['D'] = 500;
  score['M'] = 1000;
  while(cin >> str){
    int ans = 0;
    for(int i=0;i<str.size();i++){
      if(i == str.size()-1) ans += score[str[i]];
      else {
	if(score[str[i]] < score[str[i+1]]) ans -= score[str[i]];
	else ans += score[str[i]];
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1184
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    String ans = "Yay!";
    if((a > 8) || (b > 8)) ans = ":(";
    System.out.println(ans);
  }
}

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

int main()
{
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)
			break;

		for (int a = 0; a < W; a++)
			cout << '#';
		cout << '\n';
		for (int i = 0; i < H - 2; i++) {
			cout << '#';
			for (int j = 0; j < W - 2; j++)
				cout << '.';

			cout << '#' << '\n';

		}
		for (int b = 0; b < W; b++)
			cout << '#';
		cout << '\n'<<'\n';
	}
	
	return 0;
}

Measured memory_bytes: 3020
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = b[a[0]-1]
for i in range(1,n):
  ans += b[a[i]-1]
  if a[i] -a[i-1] == 1:
    ans += c[a[i]-2]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>

std::string A_to_a(std::string &);

int main()
{
    std::string sW;
    std::getline(std::cin, sW);
    size_t c = 0;

    std::transform(sW.begin(), sW.end(), sW.begin(), ::tolower);
    std::string strL;
    while (std::getline(std::cin, strL))
    {
        if (strL == "END_OF_TEXT")
        {
            break;
        }

        std::transform(strL.begin(), strL.end(), strL.begin(), ::tolower);
        std::istringstream sstrL(strL);
        while (!sstrL.eof())
        {
            std::string str;
            sstrL >> str;
            if(str == sW)
            {
                c++;
            }
        }
    }
    std::cout << c << "\n";
    return 0;
}


Measured memory_bytes: 3136
from collections import Counter

n = int(input())
a = [int(v) for v in input().split()]

cnt_all = Counter(a)
cnt2 = [k for k, v in cnt_all.items() if v >= 2]
cnt4 = [k for k, v in cnt_all.items() if v >= 4]
cnt2.sort(reverse=True)
cnt4.sort(reverse=True)

if len(cnt2) < 2:
    print(0)
elif len(cnt4) == 0:
    print(cnt2[0] * cnt2[1])
else:
    if cnt4[0] == cnt2[0]:
        print(cnt4[0] * cnt4[0])
    else:
        print(cnt2[0] * cnt2[1])

Measured memory_bytes: 18592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 100005
#define inf 1000000000
using namespace std;
inline int read()
{
    char c=getchar(); int num=0,f=1;
    while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
    while (c<='9'&&c>='0') { num=num*10+c-'0'; c=getchar(); }
    return num*f;
}
struct edge{
    int to,ne;
}e[N<<1];
int n,rt,tot,sub,head[N],col[N],du[N],val[N],f[N][2];
char s[N];
bool mark[N];
void push(int x,int y)
{
    e[++tot].to=y; e[tot].ne=head[x]; head[x]=tot;
    e[++tot].to=x; e[tot].ne=head[y]; head[y]=tot;
}
void dfs(int now,int pre)
{
    mark[now]=col[now];
    for (int i=head[now];i;i=e[i].ne)
    {
        int v=e[i].to; if (v==pre) continue;
        dfs(v,now); mark[now]&=mark[v];
        if (!mark[v]) du[now]++,du[v]++;
    }
}
void dfs2(int now,int pre)
{
    tot+=du[now];
    if ((du[now]+col[now])&1) val[now]=0;
     else val[now]=2,tot++;
    int mx1=0,mx2=0; bool exi;
    for (int i=head[now];i;i=e[i].ne)
    {
        int v=e[i].to; if (v==pre||mark[v]) continue;
        exi=true; dfs2(v,now);
        sub=max(sub,max(f[v][0]+mx2+val[now],
                        f[v][1]+mx1+val[now]));
        mx1=max(mx1,f[v][0]); mx2=max(mx2,f[v][1]);
    }
    f[now][0]=mx1+val[now]; 
    f[now][1]=exi?(mx2+val[now]):-inf;
}
int main()
{
    n=read(); for (int i=1;i<n;i++) push(read(),read());
    scanf("%s",s+1); 
    for (int i=1;i<=n;i++) col[i]=(s[i]=='B');
    for (int i=1;i<=n;i++) if (!col[i]) { rt=i; break; }
    if (!rt) { printf("0"); return 0; }
    dfs(rt,0); tot=0; dfs2(rt,0);
    printf("%d",tot-sub);
    return 0;
}


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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define urng(i, a, b) for(int i = int(b) - 1; i >= int(a); i--)
#define urep(i, b) urng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int n, b, c, ans = 0;
  //string s;
  cin >> n;
  vector<int> a(n);
  rep(i, n){
    cin >> a.at(i);
    if(a.at(i) % 2 == 0 && a.at(i) % 3 != 0 && a.at(i) % 5 != 0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  //((a == b)? "Yes" : "No")
  //for(int i = 0; i < n; i++){}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long mi[233];
long long work(int l,int r,long long dlt)
{
	if ((l>=r)&&(dlt)) return 0;
	if (l==r) return 10-(l==0);
	if (l>r) return 1;
	int t=(10-dlt%10)%10;
	dlt-=t*(mi[r-l]-1);
	return (10-(l==0)-t)*work(l+1,r-1,abs(dlt)/10);
}
int main()
{
	mi[0]=1;for (int i=1;i<=18;i++) mi[i]=mi[i-1]*10;
	int d;scanf("%d",&d);long long ans=0;
	for (int i=0;i<=17;i++) ans+=work(0,i,d);
	cout<<ans+(d==0)<<endl;
}  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

template<typename T>T gcd(T a,T b){
  if(b == 0)
    return a;
  return gcd(b,a%b);
}
template<typename T>T lcm(T a, T b){
  T g = gcd(a,b);
  return a/g*b; 
}
template<typename T>T power(T a,T b){
  T tmp = 1;
  rep(i,b){
    tmp *= a;
  }
  return tmp;
}
int main(){
  int n;cin>>n;
  ll T;cin>>T;
  vector<ll> t(n);rep(i,n)cin>>t[i];
  ll ans = 0;
  rep(i,n){
    if(i == 0)continue;
	ll tmp = t[i] - t[i-1];
    if(tmp < T)
      ans += tmp;
    else
      ans += T;
  }
  ans += T;
  print(ans)
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int s[100000];
 
int main(void)
{
	char A[10];
	cin >> A;
	if (A[2] != A[3] || A[4] != A[5])
		puts("No");
	else
		puts("Yes");
	
	return 0;
}

Measured memory_bytes: 256
while True:
	n,x = map(int,input().split())
	if (n+x == 0):
		break
	sum =0
	for i in range(1,n+1):
		for j in range(i+1,n+1):
			for k in range (j+1,n+1):
				if i+j+k == x:
					sum+=1
	print(sum)




Measured memory_bytes: 5596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		// 行intRと列intCの入力
		int intR = scanner.nextInt();
		int intC = scanner.nextInt();

		int intNum[][] = new int [100 + 1][100 + 1];
		// 要素の入力
		for (int intI = 0; intI < intR; intI++) {
			for (int intJ = 0; intJ < intC; intJ++) {
				intNum[intI][intJ] = scanner.nextInt();
			}
		}

		int intSumR = 0;
		int intSumC = 0;
		int intSumAll = 0;
		for (int intK = 0; intK < intR; intK++) {
			for (int intL = 0; intL <= intC; intL++) {
				intSumR += intNum[intK][intL];
				if (!( intL == intC)) {
					System.out.print(intNum[intK][intL] + " ");
				} else if (intL == intC) {
					System.out.println(intSumR);
					intSumR = 0;
				}
			}
		}

		for (int intO = 0; intO <= intC; intO++) {
			for (int intP = 0; intP <= intR; intP++) {
				intSumC += intNum[intP][intO];
				intSumAll += intNum[intP][intO];
				if (intO == intC && intP == intR) {
				System.out.println(intSumAll);
				} else if (intP == intR - 1 && intO < intC) {
					System.out.print(intSumC + " ");
					intSumC = 0;
				}
			}
		}


	}

}


Measured memory_bytes: 41524
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#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 FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair

int main() {
	ll a, b, c, d ,n;
	cin >> a >> b >> c >> d >> n;
	d = min(min(a * 8, b * 4), min(c * 2, d));
	c = min(min(a * 4, b * 2), c);
	cout << (n / 2) * d + (n % 2) * c << endl;
}

Measured memory_bytes: 256
s=int(input())
if s==10**18:print(0,0,0,10**9,10**9,0)
else:
  if s%10**9==0:
    x,y=s//(10**9),0
  else:
    x=s//(10**9)+1
    y=x*(10**9)-s
  print(0,0,1,10**9,x,y)


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

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  MAX                 1234567899
#define  mod                 1000000007
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  vi                  vector<int>
#define  hi                  pf(" HI \n")
#define  pp                  pair<int,int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  unsigned long long int ulli;
int dx4[] = { 0 , 0 , -1 , 1 } ;
int dy4[] = { -1 , 1 , 0 , 0 } ;
bool valid( int r , int c , int x , int y ){
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ; return 0 ;}

using namespace std;

int main ()
{
    lli n;
    cin >> n ;
    lli p= log2(n);
    p++;
    lli ans=1;
    for(int i=1;i<=p;i++)
        ans*=2;
    cout << ans-1 <<endl;

    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5+5;
int a[maxn], dp[maxn];

int main(){
	int n, k; cin >> n >> k;
	memset(dp, 0x3f, sizeof dp);
	for(int i = 1; i <= n; i++) cin >> a[i];
	dp[1] = 0;
	for(int i = 2; i <= n; i++){
		for(int j = 1; j <= min(i, k); j++){
			dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair

using namespace std;
int const N = 200001;
int a[N], arr[N];


int main()
{
    ll n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        a[arr[i]]++;
    }
    ll ans = 0;
    for (int i = 0; i < N; i++)
        ans += (a[i] * (a[i] - 1ll))/2ll;

    for (int i = 0; i < n; i++) {
        ll temp = ans - (a[arr[i]] * (a[arr[i]] - 1ll)) / 2ll
            + ((a[arr[i]]-1ll) * (a[arr[i]] - 2ll)) / 2ll;
        cout << temp << endl;
    }

}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



int main() {
	int n, m;
	cin >> n >> m;
	vii a(n, vi(m));
	rep(i, n) {
		rep(j, m) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	vii mem(m);
	rep(i, n) {
		mem[a[i][0]].push_back(i);
	}
	vector<bool> used(m, false);
	int ans = n;
	rep(i, m - 1) {
		int ma = 0;
		int idx = -1;
		rep(j, m) {
			if (ma < mem[j].size()) {
				ma = mem[j].size();
				idx = j;
			}
		}
		ans = min(ans, ma);
		used[idx] = true;
		rep(j, mem[idx].size()) {
			int now = mem[idx][j];
			rep(k, m) {
				if (!used[a[now][k]]) {
					mem[a[now][k]].push_back(now);
					break;
				}
			}
		}
		mem[idx].clear();
	}
	cout << ans << endl;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();
        int posi = X -(K-1);
        	for(int i=0;i<(K-1)*2+1;i++) {
        		System.out.print(posi);
        			if(i != ((K-1)*2+1)-1)
        				System.out.print(" ");
        		posi++;
        	}
        sc.close();
    }
}

Measured memory_bytes: 21972
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#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 srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string S;
  cin >> S;
  ll tmp_on{}, tmp_off {};
  int N = S.size();
  {
    rep(i, N) {
      if (i % 2 == 0) {
        if (S[i] == '0') ++tmp_on;
      } else {
        if (S[i] == '1') ++tmp_on;
      }
    }
    rep(i, N) {
      if (i % 2 == 1) {
        if (S[i] == '0') ++tmp_off;
      } else {
        if (S[i] == '1') ++tmp_off;
      }
    }
  }
  cout << min(tmp_on, tmp_off) << '\n';
}


Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)/n
for i in range(n):
    a[i]=max(a[i]-ave,ave-a[i])
min=min(a)
for i in range(n):
    if a[i]==min:
        print(i)
        exit()
 


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {

int main(void) {
  int n;cin>>n;
  int a[n+10];
  vector<ll> Down(n+11,0);
  vector<ll> Up(n+11,0);
  rep(i,0,n-1) {
    cin>>a[i];
    ll d = max((i+1) - a[i],0);
    ll u = min((i+1) + a[i],n);
    Down[d]++;
    Up[u]++;
  }

  ll ans=0;

  rep(i,1,n-1) {
    ans+= Down[i]*Up[i];
  }

  pr(ans);
  return 0;
}


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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input();
		decimal a1 = decimal.Parse(p[0]);
		decimal a2 = decimal.Parse(p[1]);
		Console.WriteLine(decimal.Floor(a1*a2));
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void chmin(ll &a, ll b){
  if(a > b)
    a = b;
}
void chmax(ll &a, ll b){
  if(a < b)
    a = b;
}

int main(){
  int x, n;
  cin >> x >> n;
  map<int, int> p;
  rep(i, 0, n){
    int a;
    cin >> a;
    p[a] = 1;
  }
  
  int ansp = 1000000, ansm = -1000000;
  bool c1 = false, c2 = false;
  
  rep(i, 0, n+1){
    if(!(p.count(x+i))){
      ansp = min(ansp, x+i);
      c1 = true;
    }
    if(!(p.count(x-i))){
      ansm = max(ansm, x-i);
      c2 = true;
    }
    
    if(c1&&c2)
      break;
    
  }
  
  int ans;
  
  if(abs(ansp-x) > abs(ansm-x))
    cout << ansm << endl;
  else if(abs(ansp-x) < abs(ansm-x))
    cout << ansp << endl;
  else
    cout << ansm << endl;
  
  return 0;
  
}

Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn main() {
    let seq = read::<String>()
        .chars()
        .map(|c| (c as u8 - '0' as u8) as usize)
        .collect::<Vec<usize>>();
    let n = seq.len();
    let mut ans = n;
    for offset in 0..2 {
        let mut sum = 0;
        for i in 0..n {
            if seq[i] != (offset + i) % 2 {
                sum += 1;
            }
        }
        ans = std::cmp::min(ans, sum);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;

    int dX=x2-x1,dY=y2-y1,x3,y3,x4,y4;
    y3=y2+dX;x3=x2-dY;
    x4=x3-dX;y4=y3-dY;
    
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;

double cx,cy;
int cangle;
typedef pair<int,int> P;
queue<P> move;

int main()
{
    int dis,ang;
    while(true){
        scanf("%d%*c%d",&dis,&ang);
        if(dis==0 && ang==0)break;
        move.push(P(dis,ang));
    }
    cx = 0.0; cy = 0.0;
    cangle = 90;
    while(!move.empty()){
        P p = move.front();move.pop();
        cx += (double)p.first*cos(cangle*M_PI/180);
        cy += (double)p.first*sin(cangle*M_PI/180);
        cangle -= p.second;
    }

    cout << (int)cx << endl;
    cout << (int)cy << endl;

    return 0;
}

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

const int maxn=200005;
int n,cnt,tot;
int suf[2];
bool bad[maxn];
char s[maxn];
long long ans;

int main(){
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)if(s[i]=='1'||(s[i]=='0'&&(tot&1))){
		bad[i]=true;
		tot++;
		cnt+=(tot&1)&&(s[i]=='1');
		ans+=cnt;
	}
	for(int i=n-1;i>=0;i--){
		suf[i&1]+=(s[i]=='1');
		if(bad[i]){
			cnt-=(tot&1)&&(s[i]=='1');
			tot--;
		}
		else ans+=cnt+suf[(tot+i)&1];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4216
#include <iostream>

int main(){
    int n;
    std::cin>>n;
    int half=(n-1)/2;
    int count=0;
    for(int i=1;i<=half;++i){
        if(i!=n-i){
            ++count;
        }
    }
    std::cout<<count;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
H = [int(x) for x in input().split()]

flag = True
for i in reversed(range(1, n)):
    if H[i-1] <= H[i]:
        continue
    elif H[i-1] - H[i] == 1:
        H[i-1] -= 1
    else:
        flag = False

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14224