akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<functional>
#include<algorithm>
#define ms0(a) memset(a,0,sizeof(a))
#define ms1(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
using namespace std;
typedef long long  ll;
const double Eps = (double)0.5;
const int M = 1e9 + 7;
const int N = 1e3 + 5;
const double PI = acos(-1.0);

char aa[15];
int a[15];
ll c[15];
int l;
ll asr =0;

void dfs(int i, int j, int k)
{
    if(l - 1 - i + j < k )
        return ;
    if(j == k)
    {
        for(int o = i; o < l; o++)
        {
            c[j-1] = c[j-1] * 10 + a[o];
        }
        for(int o = 0; o< j; o++)
        {
                asr += c[o];
                //cout<<c[o] << " ";
        }
       // cout<<"\n---------\n";
        return ;
    }

    c[j - 1] = 10 * c[j - 1] + a[i];
    c[j] = 0;
    dfs(i+1, j+1, k);
    dfs(i+1, j, k);
}

/*void dfs(int i, int j)
{
    c[j] = 10 * c[j] + a[i];
}*/

int main()
{
    cin>>aa;
    l = strlen(aa);
    for(int i=0; i<l; i++)
        a[i] = aa[i] - '0';
   /* for(int i=0; i<l;i++)
    {
        asr = 10 * asr + a[i] ;
    }*/
    for(int i=0; i<l; i++)
    {
        c[0] = 0;
        dfs(0, 1, i+1);
       //dfs(0,0)
    }
   // cout <<asr <<endl;
   printf("%lld\n",asr);
    return 0;
}


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

int main(){
    int X, Y;
    cin >> X >> Y;
    
    int flag=0;
    for(int i=0; i<=X; i++){
        if((2*i+4*(X-i))==Y){
            flag=1;
        }
    }
    
    if(flag==0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include <map>
#include <string.h>

using namespace std;

struct S
{
    int Map[55][55];
};

int N,M;
int a[55],b[55],Map[55][55];

bool dfs(S s,int l,int r)
{
   // cout<<" -> "<<l<<" "<<r<<endl;
    int falg = false;
    for(int i = 1;i<=N;i++){
        if((l>i&&s.Map[i][l])||(l<i&&s.Map[l][i])){
            if(l>i) s.Map[i][l] = 0;
            else s.Map[l][i] = 0;
            if(i==r)
                return true;
            if(dfs(s,i,r))
                return true;
        }
    }
    return falg;
}

int main()
{
    cin>>N>>M;
    for(int i = 1;i <=M; i++){
        cin>>a[i]>>b[i];
        if(a[i]>b[i])
            Map[b[i]][a[i]] = 1;
        else
            Map[a[i]][b[i]] = 1;
     }

     int sum = 0;
    for(int i = 1;i<=M;i++){
        S s;
        memcpy(s.Map,Map,sizeof(Map));
        if(a[i]>b[i])
            s.Map[b[i]][a[i]] = 0;
        else
            s.Map[a[i]][b[i]] = 0;
        if(!dfs(s,a[i],b[i]))
            sum++;
       // cout<<a[i]<<" "<<b[i]<<" <-> "<<sum<<endl;
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include <math.h>
using namespace std;

typedef  long long ll;

int main(){
	
  	string S;
  	cin >> S;
	int gu=0,ki=0;
  	
  for(int i = 0; i< S.size();i++){
  	if(i%2==0){
    	if(S[i]=='0')gu++;
    }else{
    	if(S[i]=='1')gu++;
    }
  }
  
   for(int i = 0; i< S.size();i++){
  	if(i%2==0){
    	if(S[i]=='1')ki++;
    }else{
    	if(S[i]=='0')ki++;
    }
  }
  

  cout << min(gu,ki) << endl;
  
}

Measured memory_bytes: 512
S = input()

ans = 10e9

prev = '1'
res = 0
for s in S:
    if prev == s:
        res += 1
        prev = '1' if s == '0' else '0'
    else:
        prev = s
ans = min(ans, res)

prev = '0'
res = 0
for s in S:
    if prev == s:
        res += 1
        prev = '1' if s == '0' else '0'
    else:
        prev = s
ans = min(ans, res)

print(ans)


Measured memory_bytes: 39792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll x, y, a, b, c, g;
  in2(x, y);
  in3(a, b, c);
  vector<ll> ap(a), bp(b), cp(c);
  rep(i, a)
    in(ap[i]);
  rep(i, b)
    in(bp[i]);
  rep(i, c)
    in(cp[i]);
  sort(all(ap));
  sort(all(bp));
  sort(all(cp));
  reverse(all(ap));
  reverse(all(bp));
  reverse(all(cp));
  rep(i, a - x)
    ap.pop_back();
  rep(i, b - y)
    bp.pop_back();
  reverse(all(ap));
  reverse(all(bp));
  ap.pb(99999999999999999);
  bp.pb(99999999999999999);
  ll i, j, k, h;
  i = 0;
  j = 0;
  k = 0;
  g = 0;
  h = 0;
  while(true){
    if(k == c)
      break;
    if(ap[i] < bp[j]){
      if(ap[i] > cp[k])
        break;
      else{
        g += ap[i];
        i++;
        h += cp[k];
        k++;
      }
    }
    else{
      if(bp[j] > cp[k])
        break;
      else{
        g += bp[j];
        j++;
        h += cp[k];
        k++;
      }
    }
  }
  rep2(v, i, x)
    h += ap[v];
  rep2(v, j, y)
    h += bp[v];
  out(h);
  memi;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define REP(i, n) for(int i = 0;i < n;i++)
#define RE(i, n) for(int i=1;i<=n;i++)
int main(){
        long N,M,R;
        long d[201][201]={0};
        cin>>N>>M>>R;
        vector<long> r(R);
        REP(i,R)
                cin>>r[i];
        sort(begin(r),end(r));
        RE(i,N){
                RE(j,N){
                        if(i!=j)
                                d[i][j]=INF;
                }
        }
        REP(i,M){
                long a,b,c;
                cin>>a>>b>>c;
                if(d[a][b]==INF)
                        d[a][b]=d[b][a]=c;
        }
        RE(k,N){
                RE(j,N){
                        RE(i,N)
                                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
        }
        unsigned long min=-1;
        do{
                long sum=0;
                REP(i,R-1){
                        //cout<<r[i]<<" "<<r[i+1]<<" "<<d[r[i]][r[i+1]]<<endl;
                        sum+=d[r[i]][r[i+1]];
                }
                if(sum<min)
                        min=sum;
        }while(next_permutation(begin(r),end(r)));
        cout<<min;
}

Measured memory_bytes: 512
#include <set>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstring>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define f first
#define s second
#define mp make_pair


using namespace std;

int h[20];
int w[20];
int n;
char dist[10][10];

int memo[1<<16];
const int bad = 1000000;

int mask[16][8][8];
int smemo[16][8][8][3];

const char *color = "RGB";

int depth = 0;
int ans   = bad;

void genmemo(){
  REP(k,n){
    int hh = h[k];
    int ww = w[k];
    REP(cc, 3){
      char col = color[cc];
      for(int y = -hh + 1; y < 4; y++){
	for(int x = -ww + 1; x < 4; x++){
	  int next = 0;
	  int msk  = 0;
	  REP(i,hh) REP(j,ww){
	    int yy = i + y;
	    int xx = j + x;

	    if(yy < 0) continue;
	    if(xx < 0) continue;
	    if(yy > 3) continue;
	    if(xx > 3) continue;

	    if(dist[yy][xx] == col){
	      next |= (1 << (yy * 4 + xx));
	    }
	    msk |= (1 << (yy * 4 + xx));
	  }

	  mask[k][y+4][x+4] = msk;
	  smemo[k][y+4][x+4][cc] = next;
	}
      }
    }
  }

}

int solve(int now){
  if(now == (1 << 16) - 1)
    return 0;
  if(memo[now]) return memo[now];
  memo[now] = bad;

  int ret = bad;
  // int cnt = __builtin_popcount(now);

  REP(k,n){
    int hh = h[k];
    int ww = w[k];
    REP(cc, 3){
      for(int y = -hh + 1; y < 4; y++){
	for(int x = -ww + 1; x < 4; x++){
	  int next = (now & (~mask[k][y+4][x+4])) | smemo[k][y+4][x+4][cc];
	  if(now != next && smemo[k][y+4][x+4][cc])
	    ret = min(ret, 1 + solve(next));
	}
      }
    }
  }

  return memo[now] = ret;
}

int main(){
  scanf("%d", &n);
  REP(i,n) scanf("%d%d", h+i, w+i);
  REP(i,4) scanf("%s", dist[i]);
  genmemo();

  typedef pair<int,int> data;
  queue<int> q;
  memset(memo, -1, sizeof(memo));

  memo[0] = 0;
  q.push(0);

  while(q.size()){
    int now = q.front();
    int kai = memo[now];
    q.pop();


    if(now == (1 << 16) - 1){
      printf("%d\n", kai);
      break;
    }

    REP(k,n){
      int hh = h[k];
      int ww = w[k];
      REP(cc, 3){
	for(int y = -hh + 1; y < 4; y++){
	  for(int x = -ww + 1; x < 4; x++){
	    int next = (now & (~mask[k][y+4][x+4])) | smemo[k][y+4][x+4][cc];
	    if(now != next && smemo[k][y+4][x+4][cc] && memo[next] == -1){
	      memo[next] = kai + 1;
	      q.push(next);
	    }
	  }
	}
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

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

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

using namespace std;

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

double W, H, x, y;

int main() {
    cin >> W >> H >> x >> y;
    if (H > W) {
        swap(W, H);
        swap(x, y);
    }
    if (x > W / 2) x = W - x;
    if (y > H / 2) y = H - y;

    double S = W * H / 2;
    bool single_sol = x * 2 != W || y * 2 != H;
    cout << S << " " << (!single_sol) << endl;
    return 0;
}

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

int main(){
    string s, t, r;
    cin >> s >> t;
    r = s + t;
    int n = stoi(r);
    for(int i=1; i<=1000; i++){
        if(n == i*i){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N; 
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> mp;
    rep(i,N){
        cin>>A[i];
        mp[A[i]]++;
    }
    map<ll, ll> ans;
    for(auto p:mp){
        ans[p.first] = p.second * (p.second-1) / 2;
    }
    ll res = 0;
    for(auto p:ans){
        res +=p.second;
    }
    rep(i,N){
        ll anss = res - (mp[A[i]] - 1);
        cout << anss << endl;
    }
}

Measured memory_bytes: 19840
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max();

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(q+1,0);
	for(int i=1; i<=q; i++) {
		cin >> a[i];
	}
	vector<int> v(n+1, 0);
	for(int i=1; i<=q; i++) {
		if (a[i] > 1) {
			v[1]--;
			v[a[i]]++;
		}
		if (a[i] < n) {
			v[a[i]+1]--;
		}
	}
	v[0] = k;
	for(int i=1; i<=n; i++) {
		v[i] = v[i-1] + v[i];	
	}
	for(int i=1; i<=n; i++) {
		if (v[i] <= 0) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}


Measured memory_bytes: 1408
def main():
  X, N = map(int, input().split())
  if N == 0:
    return X
  
  P = list(map(int, input().split()))
  
  delta = []
  for n in range(-1, 102):
    if n in P:
      delta.append(float('inf'))
    else:
      delta.append(abs(X - n))
      
  minD = min(delta)
  for i, d in enumerate(delta):
    if d == minD:
      return i - 1


print(main())

Measured memory_bytes: 9184
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint a(n);
    vint b(n);
    vector<pair<int, int> > ba(n);
    vector<pair<int, int> > a2(n);
    REP(i,n) {cin >> a[i];}
    REP(i,n) {cin >> b[i];}
    REP(i,n){
        ba[i] = make_pair(b[i], a[i]);
    }
    sort(ALL(ba));
    REP(i,n){
        a2[i] = make_pair(ba[i].se, i);
    }
    sort(ALL(a));
    sort(ALL(a2));
    sort(ALL(b));
    REP(i,n){
        if((a[i])>b[i]){
            cout << "No\n";
            return 0;
        }
    }
    vint cld(n);
    REP(i,n){
        auto p = a2[i];
        cld[p.se] = i;
    }
    int cnt = 1;
    int now = 0;
    while(cnt <= n){
        int next = cld[now];
        if(next == 0){
            cnt++;
            if(cnt<n){
                cout << "Yes\n";
                return 0;
            }else{
                break;
            }
        }else{
            cnt++;
            now = next;
        }
    }
    REP(i,n-1){
        if(a[i+1]<=b[i]){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 2944
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
  def permi(self, n, k):
    return self.f[n] * self.i[n - k] % mod

f = Factorial(max(N, M), mod)

res = f.permi(M, N) ** 2 % mod
for x in range(1, N + 1):
  t = f.combi(N, x) * f.permi(M - x, N - x) % mod
  if x % 2: res -= t * f.permi(M, N)
  else: res += t * f.permi(M, N)
  res %= mod
print(res)

Measured memory_bytes: 159080
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func ok(n int, s string, t []byte) bool {
	for i := 1; i < n-1; i++ {
		if (t[i] == 'S' && s[i] == 'o') || (t[i] == 'W' && s[i] == 'x') {
			t[i+1] = t[i-1]
		} else {
			if t[i-1] == 'S' {
				t[i+1] = 'W'
			} else {
				t[i+1] = 'S'
			}
		}
	}
	// n-1の両隣
	if (t[n-1] == 'S' && s[n-1] == 'o') || (t[n-1] == 'W' && s[n-1] == 'x') {
		if t[n-2] != t[0] {
			return false
		}
	} else {
		if t[n-2] == t[0] {
			return false
		}
	}
	// 0の両隣
	if (t[0] == 'S' && s[0] == 'o') || (t[0] == 'W' && s[0] == 'x') {
		if t[n-1] != t[1] {
			return false
		}
	} else {
		if t[n-1] == t[1] {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, s := nextInt(), next()

	t := make([]byte, n)
	sw := []byte{'S', 'W'}
	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			t[0], t[1] = sw[i], sw[j]
			if ok(n, s, t) {
				puts(string(t))
				return
			}
		}
	}

	puts(-1)
}


Measured memory_bytes: 1280
MOD=10**9+7
S=input()
N=len(S)
Acum,Ccum,Qcum=[0]*(N+1),[0]*(N+1),[0]*(N+1)

for i in range(N):
    Acum[i+1]=Acum[i]+1 if S[i]=='A' else Acum[i]
    Ccum[i+1]=Ccum[i]+1 if S[i]=='C' else Ccum[i]
    Qcum[i+1]=Qcum[i]+1 if S[i]=='?' else Qcum[i]
ans=0
for i in range(N):
    if S[i]!='B' and S[i]!='?':
        continue
    a,c,l,r=Acum[i],Ccum[N]-Ccum[i+1],Qcum[i],Qcum[N]-Qcum[i+1]
    res=pow(3,l+r-2,MOD)*(3*a+l)%MOD*(3*c+r)%MOD
    ans=(ans+res)%MOD
print(ans)

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n=5;
    VVI a(n);
    REP(i,n){
        int t;cin>>t;
        a[i] = {(t+9)%10,t};
    }
    SORT_DESC(a);

    int result=0;
    REP(i,n-1){
        result+=(a[i][1]+9)/10*10;
    }
    result += a[n-1][1];
    cout<<result<<endl;


    
	return;
}

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

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>
#include <iomanip>

#define BIG 1000000007
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;

int main(){
    long a,b,c,d;
    cin >> a >> b >> c >> d;
    long g;
    long c1 = c,d1 = d;
    while(c1 != d1){
        if(c1 > d1){
            if(c1 % d1 == 0){
                g = d1;
                break;
            }
            else{
                c1 %= d1;
            }
        }
        else{
            if(d1 % c1 == 0){
                g = c1;
                break;
            }
            else{
                d1 %= c1;
            }
        }
    }

    g = c * d / g;



    long cst = (1 + (a - 1) / c) * c;
    long ced = (b / c) * c;

    long dst = (1 + (a - 1) / d) * d;
    long ded = (b / d) * d;

    long gst = (1 + (a - 1) / g) * g;
    long ged = (b / g) * g;


    long cc = (ced - cst) / c + 1;
    long dc = (ded - dst) / d + 1;
    long gc = (ged - gst) / g + 1;


    long ans = (b - a + 1) - cc - dc + gc;
    cout << ans << endl;
}





Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct P{
	int num,sum;
};
bool cmp(const P &s,const P &t){
	return s.sum<t.sum;
}
int main(){
	int n,m,x;
	while(cin>>n>>m,n||m){
		P box[100];
		for(int i=0;i<m;i++){
			box[i].num=i+1;
			box[i].sum=0;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				cin>>x;
				if(x+1==1)
				box[j].sum++;
			}
		}
		stable_sort(box,box+m,cmp);
		cout<<box[0].num;
		for(int i=1;i<m;i++)
		cout<<' '<<box[i].num;
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
s = input()
p = g = win = lose = 0
for x in s:
    if x == 'g':
        if p < g:
            p += 1
            win += 1
        else:
            g += 1
    elif x == 'p':
        if p < g:
            p += 1
        else:
            g += 1
            lose += 1
print(win - lose)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#include<math.h>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	int ans = 0;
	int now = 0;
	rep(i, n) {
		cin >> a[i];
		if (ans < a[i]) {
			ans = a[i];
			now = i;
		}
	}
	sort(a.begin(), a.end());
	rep(i, now) {
		cout << ans << endl;
	}
	cout << a[n - 2] << endl;
	for (int i = now + 1; i < n; i++) {
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 2432
#include<stdio.h>

 int bubble(int A[],int n){
            int i,j,tmp,count=0;
            for(i=0;i<n;i++){
                     for(j=n-1;j>i;j--){
                               if(A[j]<A[j-1]){tmp=A[j-1];A[j-1]=A[j];A[j]=tmp;count++;}
                               }
                     }
            return count;
            }

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

        x=bubble(A,n);
        for(i=0;i<n;i++){printf("%d%c",A[i],(i==n-1)?'\n':' ');}
        printf("%d\n",x);
        return 0;
        }

        


Measured memory_bytes: 2140
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

vector<ll> calc2(vector<ll> v) {
	int n = v.size();
	vector<ll> res;
	if (v[1] == -1)
		res.push_back(v[0] + v[2]);
	else
		res.push_back(v[0] * v[2]);
	for (int i = 3; i < n; i++)
		res.push_back(v[i]);
	return res;
}

vector<ll> calc(vector<ll> v) {
	int n = v.size();
	for (int i = 0; i < n; i++)
		if (v[i] == -2) {
			vector<ll> res;
			for (int j = 0; j < i - 1; j++)
				res.push_back(v[j]);
			res.push_back(v[i - 1] * v[i + 1]);
			for (int j = i + 2; j < n; j++)
				res.push_back(v[j]);
			return res;
		}
	return calc2(v);
}

int main() {
	string s; cin >> s;
	int n = s.length();
	vector<ll> v;
	for (int i = 0; i < n; i++) {
		if (s[i] == '+') v.push_back(-1);
		else if (s[i] == '*') v.push_back(-2);
		else v.push_back(s[i] - '0');
	}
	vector<ll> w = v;
	for (int i = 0; i < n / 2; i++) {
		v = calc(v);
		w = calc2(w);
	}
	int x; cin >> x;
	if (v[0] == x && w[0] == x) cout << 'U' << endl;
	if (v[0] != x && w[0] == x) cout << 'L' << endl;
	if (v[0] == x && w[0] != x) cout << 'M' << endl;
	if (v[0] != x && w[0] != x) cout << 'I' << endl;
} 

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

struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  Int len;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(string S_,ull B_=1000000007LL):
    S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
    hash[0]=0;p[0]=1;
    for(Int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l,r)
  ull find(Int l,Int r){
    return hash[r]-hash[l]*p[r-l];
  }
};


template<Int X>
struct Trie{
  struct Node{
    char c;
    vector<Int> nxt;
    Int idx;
    Node(char c):c(c),nxt(X,-1),idx(-1){}
  };

  using F = function<Int(char)>;
  vector<Node> v;
  F conv;
  
  Trie(F conv,char c='$'):conv(conv){v.emplace_back(c);}

  void add(const string &s,Int x){
    Int pos=0;
    for(Int i=0;i<(Int)s.size();i++){
      Int k=conv(s[i]);
      if(~v[pos].nxt[k]){
	pos=v[pos].nxt[k];
	continue;
      }
      Int npos=v.size();
      v[pos].nxt[k]=npos;
      v.emplace_back(s[i]);
      pos=npos;
    }
    v[pos].idx=x;
  }

  Int find(const string &s){
    Int pos;
    for(Int i=0;i<(Int)s.size();i++){
      Int k=conv(s[i]);
      if(v[pos].nxt[k]<0) return -1;
      pos=v[pos].nxt[k];
    }
    return pos;
  }
  
  Int find(Int pos,char c){
    return v[pos].nxt[conv(c)];
  }

  Int calc(Int pos){
    return (pos<0?pos:v[pos].idx);
  }
  
};


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int n;
  cin>>n;
  vector<string> p(n);
  for(Int i=0;i<n;i++) cin>>p[i];

  Trie<26>::F f=[](char c){return c-'a';};
  Trie<26> G(f);
  for(Int i=0;i<n;i++) G.add(p[i],i);

  const Int LIM = 500;
  vector<string> l;
  for(Int i=0;i<n;i++)
    if((Int)p[i].size()>=LIM) l.emplace_back(p[i]);

  Int INF = s.size()+1;
  RollingHash rh(s);
  vector<RollingHash> rhs;
  for(Int i=0;i<(Int)l.size();i++)
    rhs.emplace_back(l[i]);

  vector<Int> dp(s.size(),INF);
  for(Int i=0;i<(Int)s.size();i++){
    Int pos=0;
    for(Int j=0;j<LIM&&i+j<(Int)s.size();j++){
      pos=G.find(pos,s[i+j]);
      if(pos<0) break;
      Int k=G.calc(pos);
      if(~k){
	chmin(dp[i],i+j);
	break;
      }
    }
    for(Int j=0;j<(Int)l.size();j++){
      if(i+l[j].size()>s.size()) continue;
      if(rh.find(i,i+l[j].size())==rhs[j].find(0,l[j].size()))
	chmin(dp[i],i+(Int)l[j].size());
    }
  }
  Int ans=0,pos=INF;
  for(Int i=0;i<(Int)s.size();i++){
    //cout<<i<<":"<<pos<<" "<<dp[i]<<endl;
    chmin(pos,dp[i]);
    if(pos<=i) ans++,pos=INF;
  }
  if(pos!=INF) ans++;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 26624
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
  }

  return sum;
}

//main.cpp----------------------------


void solve();

string s;

int main() {
  cin >> s;

  solve();

  return 0;
}

void solve() {

  rep(i, 12) {
    if(i==4) cout << " " << s[i];
    else cout << s[i];
  }

  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a, b; cin >> a >> b;
    if (a == '9' || b == '9') cout << "Yes" << endl;
    else cout << "No" << endl;
}
    


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define rall(n) std::rbegin(n), std::rend(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;
using namespace std;


void init() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
}


void calc() {

	Int D; std::cin >> D;
	std::cout << "Christmas ";
	if (D == 24)std::cout << "Eve";
	else if (D == 23)std::cout << "Eve Eve";
	else if (D == 22)std::cout << "Eve Eve Eve";

}


int main() {

	init();
	calc();

	return 0;
}

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

int main(){
  int n,m; cin>>n>>m;
  set<int> a;
  for(int i=0; i<m; ++i){int b; cin>>b; a.insert(b);}

  long long b=1, c=0, d=0;
  if(a.find(1)==a.end())c=1;
  for(int i=2; i<=n; ++i){
    if(a.find(i)!=a.end())d=0;
    else d=(c+b)%(1000000007);

    b=c; c=d;
  }
  cout<<c<<endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <queue>
#include <vector>

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

    std::vector<int> adj[N];

    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        std::cin >> a >> b;
        --a;
        --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    long long cnt[N]{0};

    for (int i = 0; i < Q; ++i) {
        int p, x;
        std::cin >> p >> x;
        --p;
        cnt[p] += x;
    }

    std::queue<int> q;
    q.push(0);
    int visited[N]{0};
    visited[0] = 1;

    while (!q.empty()) {
        int node = q.front();
        q.pop();

        for (int child : adj[node]) {
            if (visited[child]) continue;
            visited[child] = 1;
            cnt[child] += cnt[node];
            q.push(child);
        }
    }

    for (int i = 0; i < N - 1; i++) {
        std::cout << cnt[i] << " ";
    }
    std::cout << cnt[N - 1] << std::endl;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int x=N%10;
  vector<int> v={2,4,5,7,9};
  vector<int> w={0,1,6,8};
  for(auto y:v){
    if(x==y){
      cout << "hon" << endl;
      return 0;
    }
  }
  for(auto y:w){
    if(x==y){
      cout << "pon" << endl;
      return 0;
    }
  }
  cout << "bon" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
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 vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);


int main(){
	string s1,s2;
	while(cin>>s1>>s2,cin){
		int ans=0;
		int j=0;
		REP(i,s1.size()){
			j=max(j,i);
			string ss;
			while(j<s1.size()&&(ss=string(s1.begin()+i,s1.begin()+j+1),s2.find(ss)!=s2.npos)){
				ans=max(ans,j-i+1);
				j++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1224
n = gets.to_i
hash = Hash.new(0)
n.times do
  s = gets.chomp
  if s[0] == 'M'
    hash['M'] += 1
  elsif s[0] == 'A'
    hash['A'] += 1
  elsif s[0] == 'R'
    hash['R'] += 1
  elsif s[0] == 'C'
    hash['C'] += 1
  elsif s[0] == 'H'
    hash['H'] += 1
  end
end
sum = 0
["M","A","R","C","H"].combination(3).each do |x|
  sum += hash[x[0]] * hash[x[1]] * hash[x[2]]
end
puts sum


Measured memory_bytes: 14324
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n,x,cnt0[65],cnt1[65],a[maxn];
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> x;
		a[i] = x;
		for(int i = 0;i <= 60;i++){
			if(x & (1LL << i)) cnt1[i]++;
			else cnt0[i]++;
		}
	}
//	rep(i,0,60){
//		cout << cnt0[i] << " " << cnt1[i] << endl;
//	}
	ll ans = 0;
	rep(i,1,n){
		ll x = a[i];
		rep(j,0,60){
			if(x & (1LL << j)){
				ll t = cnt0[j];
				ans = (ans + t * poww(2,j,mod) % mod) % mod;
				cnt1[j]--;
			}
			else{
				ll t = cnt1[j];
				ans = (ans + t * poww(2,j,mod) % mod) % mod;
				cnt0[j]--;
			}
		}
//		cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void solve(int n, int m, vector<int> d, vector<int> t) {
    sort(d.begin(), d.end());
    sort(t.begin(), t.end());
    int j = 0;
    bool ans = false;
    for (int i = 0; i < d.size(); i++) {
        if (t[j] == d[i]) {
            j++;
            if (j >= t.size()) {
                ans = true;
                break;
            }
            continue;
        } else if(t[j] < d[i]){
            ans = false;
            break;
        }
    }
    if (ans) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}

int main() {
    struct timeval start,end;
    long long span;
    int n, m;

    gettimeofday(&start,NULL);

    std::cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        std::cin >> d[i];
    }
    std::cin >> m;
    vector<int> t(m);
    for (int i = 0; i < m; i++) {
        std::cin >> t[i];
    }
    solve(n, m, d, t);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 3328
ai = lambda: list(map(int, input().split()))

n,l = ai()
a = ai()

f = 0
for i in range(1,n):
    if a[i-1]+a[i] >= l:
        f = 1
        key = i
        break
if f:
    print('Possible')
    b = list(range(n))
    c = b[1:key]
    c += b[-1:key:-1]
    c += [key]
    print(*c, sep='\n')
else:
    print('Impossible')


Measured memory_bytes: 14448
S=input()
T=input()

def main():
    
    if len(S)==len(T)-1 :
        
        for i in range(len(S)):
            if list(S)[i]==list(T)[i]:
                continue
            else:
                print("No")
                return
        print("Yes")
        
    else:
        print("No")

main()

Measured memory_bytes: 9112
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  int x[N],y[M];
  for(int i=0;i<N;i++){
    cin >> x[i];
  }
  for(int i=0;i<M;i++){
    cin >> y[i];
  }
  sort(x,x+N);
  sort(y,y+M);
  if(x[N-1]>=X && y[0]<=Y && y[0]-x[N-1]>=1){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
  return 0;
}


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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000009; //

int A[MAX_N];

int main(){
  //ios_base::sync_with_stdio(false);
  //cin.tie(0);
  
  int N,a,b; cin >> N >> a >> b; a--; b--;
  
  map<int,set<pair<int,int> > > A,B;
  
  pair<int,int> qq,r;
  
  for(int i=0;i<N;i++){
    int x,y;
    cin >> x >> y;
    A[x-y].emplace(x,y);
    B[x+y].emplace(x,y);
    A[x-y].emplace(INT_MAX,-1);
    B[x+y].emplace(INT_MAX,-1);
    
    if(i == a) qq = make_pair(x,y);
    if(i == b) r = make_pair(x,y);
  }
  
  int d = abs(qq.first-r.first) + abs(qq.second-r.second);
  
  map<int,set<pair<int,int> > > C,D;
  int idx = 0;
  for(const auto& x : A)
    for(const auto& y : x.second)
      C[x.first].emplace(y.first,idx++);
  
  for(const auto& x : B)
    for(const auto& y : x.second)
      D[x.first].emplace(y.first,idx++);
  
  queue<pair<int,int> > q;
  q.push(qq);
  //q.push(r);
  
  long long ans = 0;
  
  set<pair<int,int> > done;
  
  while(!q.empty()){
    int x,y; tie(x,y) = q.front(); q.pop();
    
    if(done.count(make_pair(x,y))) continue;
    done.emplace(x,y);
    
    ans += D[x+y+d].lower_bound(make_pair(x+d+1,-1))->second - D[x+y+d].lower_bound(make_pair(x,-1))->second;
    ans += D[x+y-d].lower_bound(make_pair(x+1,-1))->second - D[x+y-d].lower_bound(make_pair(x-d,-1))->second;
    
    ans += C[x-y+d].lower_bound(make_pair(x+d,-1))->second - C[x-y+d].lower_bound(make_pair(x,INT_MAX))->second;
    ans += C[x-y-d].lower_bound(make_pair(x,-1))->second - C[x-y-d].lower_bound(make_pair(x-d,INT_MAX))->second;
    
    auto i1 = B[x+y+d].lower_bound(make_pair(x,-1)),i2 = B[x+y+d].lower_bound(make_pair(x+d+1,-1));
    for(; i1 != i2; ++i1)
      q.emplace(*i1);
  
    i1 = B[x+y-d].lower_bound(make_pair(x-d,-1)),i2 = B[x+y-d].lower_bound(make_pair(x+1,-1));
    for(; i1 != i2; ++i1)
      q.emplace(*i1);
    
    i1 = A[x-y+d].lower_bound(make_pair(x,-1)),i2 = A[x-y+d].lower_bound(make_pair(x+d,-1));
    for(; i1 != i2; ++i1)
      q.emplace(*i1);
    
    i1 = A[x-y-d].lower_bound(make_pair(x-d,-1)),i2 = A[x-y-d].lower_bound(make_pair(x,-1));
    for(; i1 != i2; ++i1)
      q.emplace(*i1);
    
    B[x+y+d].erase(B[x+y+d].lower_bound(make_pair(x,-1)),B[x+y+d].lower_bound(make_pair(x+d+1,-1)));
    B[x+y-d].erase(B[x+y-d].lower_bound(make_pair(x-d,-1)),B[x+y-d].lower_bound(make_pair(x+1,-1)));
    A[x-y+d].erase(A[x-y+d].lower_bound(make_pair(x,-1)),A[x-y+d].lower_bound(make_pair(x+d,INT_MAX)));
    A[x-y-d].erase(A[x-y-d].lower_bound(make_pair(x-d,-1)),A[x-y-d].lower_bound(make_pair(x,INT_MAX)));
  }
  
  assert(ans%2 == 0);
  cout << ans/2 << endl;
  
  return 0;
}


Measured memory_bytes: 105216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a,b;
ll xsum(ll n){
    ll ret=0;
    if(n%4==1||n%4==2) ret=1;
    FOR(i,1,41){
        if((n>>i&1)&&!(n&1)){
            ret|=(1ll<<i);
        }
    }
    return ret;
}
int main(){
    cin>>a>>b;
    a=xsum(a-1);
    b=xsum(b);
    cout<<(b^a)<<endl;
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n;
  cin >> n;

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

  map<ll, ll> m;
  for (ll i = 0; i < n; ++i) {
    m[i-a[i]]++;
  }
  
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    if (m.count(i+a[i])) ans += m[i+a[i]];
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  //駐車時間
  int n;
  //料金
  int a,b;
  
  cin >> n >> a >> b;
  
  int fee1 = a * n;
  int fee2 = b;
  
  int ans = min(fee1,fee2);
  
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n;i++){
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int sum = 0;
  for (int i = 0; i < k;i++){
    sum += p[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3524
mod = (10 ** 9 + 7)

def comb(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p *(n-i)%mod
        q = q *(i+1)%mod
    return p * pow(q, mod-2, mod) % mod


n, a, b = list(map(int, input().split()))
s = pow(2, n, mod) - 1
print((s - comb(n, a) - comb(n, b)) % mod)


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

int main()
{
    int n; cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<int>difs(n);
    int mi=INT_MAX;;
    for(int i=0;i<n;i++)
    {
        mi=min(mi,a[i]);
        difs[i]=mi;
    }
    int cnt=0;
    
    for(int i=0;i<n;i++)
    {
        if(a[i]==difs[i])
        {
            cnt++;
        }
    }
    cout<<cnt;
    
    
    

}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
    
    int n,i,sum,max;
    max = 0;
    sum = 0;
    int l[100];
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
        sum += l[i];
        if(max < l[i]){
            max = l[i];
        }
    }
    
    sum -= max;
    
    if(max<sum){
        printf("Yes");
    }else{
        printf("No");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef double ll;
int main()
{
  int n;
  cin>>n;
  ll p[n];
  for(int i=0;i<n;i++)
    cin>>p[i];
  ll dp[n+1][n+1];
  dp[1][0]=1-p[0];
  dp[1][1]=p[0];
  for(int i=2;i<=n;i++)
    dp[i][0]=dp[i-1][0]*(1-p[i-1]);
  for(int i=2;i<=n;i++)
    for(int j=1;j<=i;j++)
      dp[i][j]=dp[i-1][j-1]*(p[i-1])+dp[i-1][j]*(1-p[i-1]);
  ll sum=0;
  for(int i=(n/2)+(n%2);i<=n;i++)
    sum+=dp[n][i];
  cout<<setprecision(10)<<sum;
  return 0;
}

Measured memory_bytes: 70528
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (a, b): (usize, usize);
    input!(a, b);

    if a <= b {
        println!("{}", a);
    } else {
        println!("{}", a - 1);
    }
}


Measured memory_bytes: 4352
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

bool exist(string s, string t){
	int i = 0, j = 0;
	while(i != (int)s.size() && j != (int)t.size()){
		if(s[i] == t[j]){
			i++;j++;
		}
		else i++;
	}
	return j == (int)t.size();
}

int main(){
	FIO
	
	int n;cin >> n;
	string s;cin >> s;
	int ans = 0;
	for(int i = 0; i <= 999; i++){
		string now = to_string(i);
		//deb(now);
		while(now.size() != 3)now = '0' + now;
		if(exist(s, now))ans++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 384