akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  vit ball(n + 5, 1);
  bool Red[n + 5] = {false};
  Red[1] = true;
  int x, y;
  rep(i, m){
    cin >> x >> y;
    if(Red[x]){
      Red[y] = true;
    }
    ball[x] --;
    ball[y] ++;
    if(ball[x] == 0){
      Red[x] = false;
    }
  }
  int ans = 0;
  reps(i, n){
    if(Red[i]){
      ans ++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 768
// A - Mahmoud and Ehab and the MEX: http://codeforces.com/contest/862/problem/A
// 0から順に操作が要るかどうかを考える

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define _D(p) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p)<<std::endl;
#define _D2(p,q) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p) << ", " #q " = "<<(q)<<std::endl;
#define _DN(v) std::cout<<"L"<<__LINE__<<" : " #v " = ["; rep(i,(v).size()) {std::cout<<v[i]<<(i==v.size()-1?"":", ");}std::cout<<"]"<<std::endl;
#define _DNN(v) std::cout<<"L"<<__LINE__<<" : " #v " = [" << std::endl; rep(i,(v).size()) {std::cout<<"    [";rep(j,(v)[0].size()){std::cout<<v[i][j]<<(j==v[0].size()-1?"":", ");}std::cout<<"],"<<std::endl;}std::cout<<"]"<<std::endl;
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int mod = 1000000007;


int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    if (s.size() < 4) {
        cout << "No" << endl;
        return 0;
    }
    if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;

ll a[MAX_N];
ll b[MAX_N];

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld %lld", &(a[i]), &(b[i]));
  }

  vector<pair<ll, int>> sum_index;

  for (int i = 0; i < n; ++i) {
    sum_index.emplace_back(a[i] + b[i], i);
  }

  sort(sum_index.begin(), sum_index.end(), greater<pair<ll, int>>());

  ll ans = 0LL;

  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      ans += a[sum_index[i].second];
    } else {
      ans -= b[sum_index[i].second];
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 3956
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Handshake_3
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputArray = Console.ReadLine().Split().Select(x => long.Parse(x)).ToList();
            var _N = inputArray[0];
            var _M = inputArray[1];

            inputArray = Console.ReadLine().Split().Select(x => long.Parse(x)).ToList();
            var powers = inputArray.OrderBy(x => -x).ToList();

            long top1 = powers.First() * 2 + 1;
            long bottom1 = -1;
            var powerIndex = new List<long[]>((int)_N);
            long thresholdPower = 0;
            do
            {
                powerIndex.Clear();
                long count = 0;
                var mid1 = (top1 + bottom1) / 2;
                for (var i = 0; i < _N; i++)
                {
                    long top2 = _N;
                    long bottom2 = -1;
                    do
                    {
                        var mid2 = (top2 + bottom2) / 2;
                        if (powers[i] + powers[(int)mid2] >= mid1)
                        {
                            bottom2 = mid2;
                        }
                        else
                        {
                            top2 = mid2;
                        }
                    } while (top2 - bottom2 > 1);
                    count += top2;
                    powerIndex.Add(new long[2] { powers[i], top2 });
                }

                if(count >= _M)
                {
                    bottom1 = mid1;
                    thresholdPower = mid1;
                }
                else
                {
                    top1 = mid1;
                }
            } while (top1 - bottom1 > 1);

            var accumulation = new long[_N + 1];
            accumulation[0] = 0;
            for (var i = 0; i < _N; i++)
            {
                accumulation[i + 1] = accumulation[i] + powers[i];
            }

            {
                long ans = 0;
                long count = 0;
                foreach (var item in powerIndex)
                {
                    ans += (item[0] * item[1] + accumulation[item[1]]);
                    count += item[1];
                }
                ans -= (count - _M) * thresholdPower;
                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 48736
n,k = map(int,input().split())
ab_list = [list(map(int,input().split())) 
           for nesya in range(n)]
ab_list.sort()
s = k
for ab in ab_list:
  s -= ab[1]
  if s > 0:
    pass
  else:
    print(ab[0])
    break

Measured memory_bytes: 27872
N, M = map(int, input().split())
x_y_z = []
max_total = 0
for i in range(N):
    x_y_z.append(list(map(int, input().split())))
for i, j, k in [[1, 1, 1], [1, 1, -1], [1, -1, 1], [-1, 1, 1], [1, -1, -1], [-1, 1, -1], [-1, -1, 1], [-1, -1, -1]]:
    total_of_xyz = []
    total = 0
    for x, y, z in x_y_z:
        total_of_xyz.append(i * x + j * y + k * z)
    total_of_xyz.sort(reverse=True)
    for i in range(M):
        total += total_of_xyz[i]
    if max_total < total:
        max_total = total
print(max_total)

Measured memory_bytes: 3316
N = int(input())
a = list(map(int, input().split(" ")))

sum_a = sum(a)

minv = abs(2*a[0] - sum_a)
cc = a[0]

for i in range(1, N-1):
    
    cc += a[i]
    minv = min(abs(2*cc - sum_a), minv)
        
print(minv)

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

int main() {
    int t, d, l;
    while (cin >> t >> d >> l, t != 0) {
        int x;
        int ans = 0;
        int D = 0;

        for (int i = 0; i < t; i++) {
            cin >> x;
            if (x >= l) {
                D = d;
            }
            if (D > 0) {
                ans++;
                D--;
            }
        }

        if (ans > 0) ans--;
        cout << ans << endl;
    }
}



Measured memory_bytes: 3104
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
char fi[1005][1005];
P sg[10];
int d[1005][1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int n,k;

signed main(){
    int n;cin>>n;
    int sh[105][10];
    int po[105][10];
    for(int i=0; i<n; i++){
        for(int j=0; j<10;j++){
            cin>>sh[i+1][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<11;j++){
            cin>>po[i+1][j];
        }
    }
    int mo=inf*-1;
    rep(a,2){
        rep(b,2){
            rep(c,2){
                rep(d,2){
                    rep(e,2){
                        rep(f,2){
                            rep(g,2){
                                rep(h,2){
                                    rep(m,2){
                                        rep(j,2){
                                            
                                            if(a+b+c+d+e+f+g+h+m+j!=0){
                                                int ans=0;
                                                for(int i=1;i<=n;i++){
                                                    int key=0;
                                                    if(a==1&&sh[i][0]==1)key++;
                                                    if(b==1&&sh[i][1]==1)key++;
                                                    if(c==1&&sh[i][2]==1)key++;
                                                    if(d==1&&sh[i][3]==1)key++;
                                                    if(e==1&&sh[i][4]==1)key++;
                                                    if(f==1&&sh[i][5]==1)key++;
                                                    if(g==1&&sh[i][6]==1)key++;
                                                    if(h==1&&sh[i][7]==1)key++;
                                                    if(m==1&&sh[i][8]==1){
                                                        key++;
                                                    }
                                                    if(j==1&&sh[i][9]==1){
                                                        key++;
                                                    }
                                                    ans+=po[i][key];
                                                }
                                                mo=max(mo,ans);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<mo<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()

{
    int a , b, c, d  ;

    scanf("%d %d %d", &a, &b, &c) ;

    d=a*b ;

    if(d<c)
    {
        printf("%d\n", d) ;
    }
    else
    {
        printf("%d\n", c);
    }

    return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    long long n,p[110];
    cin>>n;
    for(int i=0;i<n;i++) cin>>p[i];
    sort(p,p +n);
    cout<<abs(p[0]-p[n-1])<<'\n';
    return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
 
int main(){
  long long n, m, xsum = 0, ysum = 0, x1, x2, y1, y2, i;
  scanf("%lld%lld", &n, &m);
  scanf("%lld", &x1);
  for(i = 1; i < n; i++){
    scanf("%lld", &x2);
    xsum = (xsum + (x2 - x1)*i*(n-i))%MOD;
    x1 = x2;
  }
  scanf("%lld", &y1);
  for(i = 1; i < m; i++){
    scanf("%lld", &y2);
    ysum = (ysum + (y2 - y1)*i*(m-i))%MOD;
    y1 = y2;
  }
  printf("%lld\n", xsum*ysum%MOD);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[3005];
int main()
{
	int n,a1,b;
	cin>>n>>a1>>b;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
		{
			int s,s1,s2;
			s=abs(i-j);
			s1=abs(i-a1)+1+abs(j-b);
			s2=abs(i-b)+1+abs(j-a1);
			a[min(s,min(s1,s2))]++; 
		} 
	for(int i=1; i<n; i++)
		cout<<a[i]/2<<endl;
	return 0;
 } 

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

def prime_factorize(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

primes = defaultdict(int)
for a in A:
    for x, p in prime_factorize(a):
        primes[x] = max(primes[x], p)
lcm = 1
for prime, ind in primes.items():
    lcm *= prime ** ind
ans = 0
for i in range(N):
    ans += lcm // A[i]
    if i == N // 2:
        ans %= mod
print(ans % mod)


Measured memory_bytes: 46684
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    map <ll,ll> sum;
    map <ll,bool> ok;
    ll N;
    cin>>N;
    v a(N);
    rep(i,0,N){
        cin>>a[i];
        sum[a[i]]++;
        ok[a[i]] = false;
    }
    ll ans = 0;

    rep(i,0,N){
        if(ok[a[i]] == false){
            if(a[i] > sum[a[i]]){
                ans += sum[a[i]];
            }
            else{
                ans += sum[a[i]]-a[i];
            }
            ok[a[i]] =true;
        }
    }
    cout<<ans;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	FORR(c,S) c-='0';
	if(S[0]+S[1]+S[2]+S[3]==7) return _P("%c+%c+%c+%c=7\n",S[0]+'0',S[1]+'0',S[2]+'0',S[3]+'0');
	if(S[0]+S[1]+S[2]-S[3]==7) return _P("%c+%c+%c-%c=7\n",S[0]+'0',S[1]+'0',S[2]+'0',S[3]+'0');
	if(S[0]+S[1]-S[2]+S[3]==7) return _P("%c+%c-%c+%c=7\n",S[0]+'0',S[1]+'0',S[2]+'0',S[3]+'0');
	if(S[0]+S[1]-S[2]-S[3]==7) return _P("%c+%c-%c-%c=7\n",S[0]+'0',S[1]+'0',S[2]+'0',S[3]+'0');
	if(S[0]-S[1]+S[2]+S[3]==7) return _P("%c-%c+%c+%c=7\n",S[0]+'0',S[1]+'0',S[2]+'0',S[3]+'0');
	if(S[0]-S[1]+S[2]-S[3]==7) return _P("%c-%c+%c-%c=7\n",S[0]+'0',S[1]+'0',S[2]+'0',S[3]+'0');
	if(S[0]-S[1]-S[2]+S[3]==7) return _P("%c-%c-%c+%c=7\n",S[0]+'0',S[1]+'0',S[2]+'0',S[3]+'0');
	if(S[0]-S[1]-S[2]-S[3]==7) return _P("%c-%c-%c-%c=7\n",S[0]+'0',S[1]+'0',S[2]+'0',S[3]+'0');
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

const int INF = 1<<20;
int X,Y,dp[5][1005],ps[5][1005][2],pc[5],S[2],G[2],i,j,fp,rd,rp;char c;
int dis(int a[2],int b[2]){return abs(a[0]-b[0])+abs(a[1]-b[1]);}
int min(int a,int b){return a<b?a:b;}
int main()
{
	for(;scanf("%d%d\n",&X,&Y),X;)
	{
		memset(pc,0,sizeof(pc));
		rd=rp=INF;
		for(i=0;i<Y;i++)
			for(j=0;j<=X;j++)
			{
				c=getchar();
				if(c=='S'){S[0]=i;S[1]=j;}
				else if(c=='G'){G[0]=i;G[1]=j;}
				else if(48<c){c-='1';ps[c][pc[c]][0]=i;ps[c][pc[c]][1]=j;pc[c]++;}
			}
		for(fp=0;fp<5;fp++)
		{
			int np=(fp+1)%5,nnp;
			memset(dp,0x7f,sizeof(dp));
			for(i=0;i<pc[np];i++)dp[np][i]=dis(S,ps[np][i]);//init
			for(nnp=(np+1)%5;nnp!=fp;np=(np+1)%5,nnp=(nnp+1)%5)
				for(i=0;i<pc[np];i++)
					for(j=0;j<pc[nnp];j++)
						dp[nnp][j]=min(dp[nnp][j],dp[np][i]+dis(ps[np][i],ps[nnp][j]));
			for(np=(fp+4)%5,i=0;i<pc[np];i++)
			{
				if(rd>dp[np][i]+dis(ps[np][i],G))
				{
					rd=dp[np][i]+dis(ps[np][i],G);
					rp=fp+1;
				}
			}
		}
		if(rd==INF)puts("NA");
		else printf("%d %d\n",rp,rd);
	}
	return 0;
}

Measured memory_bytes: 672
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll either = 0;
  ll sum = 0;
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
    if (i > 1) {
      either ^= A.at(i);
    }
    else {
      sum += A.at(i);
    }
  }
  ll both = sum - either;
  if (both % 2 == 1 || both > A.at(0) * 2 || (either & (both / 2))) {
    cout << -1 << "\n";
    return 0;
  }
  both /= 2;
  ll ans_small = 0;
  for (ll i = 39; i >= 0; --i) {
    ll temp = pow(2, i);
    if (either & temp) {
      if (ans_small + temp + both <= A.at(0)) {
        ans_small += temp;
      }
    }
  }
  if (both + ans_small == 0) {
    cout << -1 << "\n";
    return 0;
  }
  ll ans = A.at(0) - (both + ans_small);
  cout << ans << "\n";
}


Measured memory_bytes: 4004
s = input()
s_g = list(map(int, (s[0::2])))
s_k = list(map(int, (s[1::2])))
ans = [len(s_g) - sum(s_g) + sum(s_k),len(s_k) - sum(s_k) + sum(s_g)]

print(min(ans))

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  vector<double> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  vector< vector<double> > dp(n + 1, vector<double>(n + 1));
  dp[0][0] = 1.0;

  for (int i = 0; i < n; i++) {
    dp[i + 1][0] = dp[i][0] * (1.0 - p[i]);
    for (int j = 1; j <= n; j++) {
      dp[i + 1][j] = dp[i][j - 1] * p[i] + dp[i][j] * (1.0 - p[i]);
    }
  }

  double res = 0;
  for (int i = 0; i <= n; i++) {
    if (i > n - i) {
      res += dp[n][i];
    }
  }
  cout << fixed << setprecision(10) << res << '\n';
  return 0;
}

Measured memory_bytes: 70784
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    tb=[0]*(10**4+2)
    n=int(readline())
    for x in range(1,10**2+1):
        for y in range(1,10**2+1):
            for z in range(1,10**2+1):
                f=x*x+y*y+z*z+x*y+y*z+z*x
                if f <= 10**4:
                    tb[f]+=1
    for i in range(1,n+1):
        print(tb[i])
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

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

int a[100005];

int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	
	int g=0;
	
	for (int i=1;i<=n;i++){
		scanf("%d",a+i);
		g=__gcd(g,a[i]);	
	}
	
	for (int i=1;i<=n;i++){
		if(a[i]-k>=0){
			if((a[i]-k)%g==0){
				printf("POSSIBLE\n");
				return 0;
			}
		}
	}
	
	printf("IMPOSSIBLE\n");
	
}

Measured memory_bytes: 640
use proconio::input;

fn main() {
  input! {
    s: String,
  }
  let s = s.chars().collect::<Vec<char>>();
  
  let mut b_count = 0;
  let mut c_count = 0;
  
  for (i, c) in s.iter().enumerate() {
    let c = *c;
    if i % 2 == 0 && c == '0' {
      b_count += 1;
    } else if i % 2 == 1 && c == '1' {
      b_count += 1;
    }
  }
  
  for (i, c) in s.iter().enumerate() {
    let c = *c;
    if i % 2 == 0 && c == '1' {
      c_count += 1;
    } else if i % 2 == 1 && c == '0' {
      c_count += 1;
    }
  }
  
  if c_count < b_count {
    println!("{}", c_count);
  } else {
    println!("{}", b_count);
  }
}

Measured memory_bytes: 2640
#include <stdio.h>

int main(void) {
  int i, j, k, n, a;
  scanf("%d", &n);
  int cnt[n];
  for(i = 0; i < n; ++i) cnt[i] = 0;
  for(i = 0; i < n; ++i) scanf("%d", &a), cnt[a]++;
  for(i = 0; i < n; ++i) if(cnt[i]) {
    if(i == n - 1) {
      if(cnt[i] == n) printf("Yes");
      else printf("No");
      return 0;
    } else {
      if(cnt[i] + cnt[i + 1] != n) printf("No");
      else if(cnt[i] == n) {
        if(2 * i <= n) printf("Yes");
        else printf("No");
      }
      else if(cnt[i] >= i + 1) printf("No");
      else if(2 * (i - cnt[i] + 1) <= cnt[i + 1]) printf("Yes");
      else printf("No");
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;


int main() {
	int N;
	cin >> N;
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	string S;
	cin >> S;
	int flag = 0;
	int flag2 = 0;
	if (C < D) {
		if (B < C) {
			for (int i = B-1; i < D-1; i++) {
				if ((S[i] == '#') && (S[i + 1] == '#') )
					flag = 1;
			}
			for (int i = A - 1; i < C - 1; i++) {
				if ((S[i] == '#') && (S[i + 1] == '#'))
					flag = 1;
			}
		}
		else {
			for (int i = A - 1; i < C - 1; i++) {
				if (S[i] == '#' && S[i + 1] == '#')
					flag = 1;
			}
			for (int i = B - 1; i < D - 1; i++) {
				if (S[i] == '#' && S[i + 1] == '#')
					flag = 1;
			}
		}
}
	else {
		flag2 = 1;
		for (int i = B-1; i < D-1; i++) {
			if (S[i] == '#' && S[i + 1] == '#')
				flag = 1;
		}
		for (int i = A - 1; i < C - 1; i++) {
			if (S[i] == '#' && S[i + 1] == '#')
				flag = 1;
		}
		for (int i = B - 1; i < D; i++) {
			if (S[i-1] == '.' && S[i] == '.' && S[i + 1] == '.')
				flag2 = 0;
		}
	}
	if (flag == 0 && flag2 == 0)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}


Measured memory_bytes: 640
import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [n, p] <- getIntList
  s <- BS.getLine

  v <- VM.new p
  VM.set v (0::Int)
  VM.write v 0 1 -- U0 `mod` p == 0                                                                                       
  let solve25 i a | i > n = print a
                  | otherwise = do
                      let c = BS.index s (n-i)
                          di = ord c - ord '0'
                          x = if di `mod` p == 0 then n - i + 1 else 0
                      solve25 (i+1) (a+x)

      solve i a md m10 | i > n = print a
                       | otherwise = do
                           let c = BS.index s (n-i)
                               di = ord c - ord '0'
                               md' = (md + di * m10) `mod` p
                               m10' = (m10 * 10) `mod` p
                           y <- VM.read v md'
                           VM.write v md' (y+1)
                           solve (i+1) (a+y) md' m10'

  if 10 `mod` p == 0
    then solve25 1 0
    else solve 1 0 0 1

Measured memory_bytes: 21884
n = int(input())
a = list(map(int, input().split()))

forward = True
sec, first = [], []
for i in range(n):
    if i%2:
        first.append(a[i])
    else:
        sec.append(a[i])
arr = first[::-1] + sec
if len(first) != len(sec):
    arr = arr[::-1]

for el in arr:
    print(el, end=' ')

Measured memory_bytes: 103768
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int c[3];
int main()
{
    int now=1;
    int n;scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        int x;scanf("%d",&x);
        int tmp=0;
        for (int j=0;j<3;++j)
            if (c[j]==x) ++tmp;
        now=1ll*now*tmp%mod;
        for (int j=0;j<3;++j)
            if (c[j]==x) {
                ++c[j];
                break;
            }
    }
    printf("%d\n",now);
    return 0;
}


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

int main(){
  int n; cin>>n;
  vector<int>a(n,0);
  for(int i=0;i<n;i++)cin>>a[i];
  bool ok=true;
  for(auto&&x:a){
    if(x%2==0)if(x%3!=0&&x%5!=0)ok=false;
  }
  cout<<(ok?"APPROVED":"DENIED")<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
l=[3]+[0]*(10**5)
m=10**9+7
x=1
for i in a:
  if l[i]:
    x=(x*l[i])%m
    l[i]-=1
    l[i+1]+=1
  else:
    x=0
    break
print(x)

Measured memory_bytes: 14396
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input().strip())
an = [int(input().strip()) for i in range(n)]
an.sort()

ans = an[-1] - an[0]
high = an[-1]
low = an[0]
c = n//2

if n % 2:
  for i in range(1,c):
    ans += high - an[i] + an[-i-1] - low
    high = an[-i-1]
    low = an[i]
  ans += max(high-an[c],an[c]-low)
  print(ans)
else:
  for i in range(1,c):
    ans += high - an[i] + an[-i-1] - low
    high = an[-i-1]
    low = an[i]
  print(ans)

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

using namespace std;
#define mod 998244353
#define mx 200005

int fact[mx];

int power(int x, int y) {
    sqrt(x);
    int res = 1;
    while (y) {
        if (y & 1) {
            res = (long long) res * x % mod;
        }
        y /= 2;
        x = (long long) x * x % mod;
    }
    return res;
}

int mod_inv(int x) {
    return power(x, mod - 2);
}

void cal_fac() {
    static bool done = false;
    if (done)
        return;
    done = true;
    fact[0] = 1;
    for (int i = 1; i < mx; i++) {
        fact[i] = (long long) i * fact[i - 1] % mod;
    }
}

int get_fac(int n) {
    cal_fac();
    return fact[n];
}

int comb(int n, int k) {
    cal_fac();
    return (long long) fact[n] * mod_inv(fact[n - k]) % mod * mod_inv(fact[k]) % mod;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, m, k;
    cin >> n >> m >> k;
    long long sol = 0;
    for (int adj = 0; adj <= k; adj++) {
        long long choose_adj = comb(n-1, adj);
        int rem = n - adj;
        long long color = (long long) m * power(m - 1, rem - 1) % mod;
        sol = sol + color * choose_adj % mod;
        sol %= mod;
    }
    cout << sol;

    return 0;
}

Measured memory_bytes: 4476
#![allow(unused_imports)]

use proconio::fastout;
use proconio::input;
use proconio::marker::{Bytes, Chars, Usize1};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; m],
    }
    let s = a.into_iter().sum::<usize>();
    if n >= s {
        println!("{}", n - s);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 2240
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var x int
	fmt.Fscan(read, &x)

	ans := x / 500 * 1000
	x %= 500
	ans += x / 5 * 5
	fmt.Fprintln(write, ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct node {
	node* ch[26];
	int cnt, end;
	node() : cnt(0), end(0) {memset(ch, 0, sizeof(ch));}
};
node *root;
void insert(char *s, int id) {
	int n = (int) strlen(s);
	node *cur = root;
	for (int i = 0; i < n; ++ i) {
		if (!cur -> ch[s[i] - 'a']) cur -> ch[s[i] - 'a'] = new node();
		cur = cur -> ch[s[i] - 'a'];
		cur -> cnt ++;
	}
	cur -> end = id;
}
int pre[N], cnt[N][26][26];
void dfs(node *cur, int up = 0) {
	if (!cur) return;
	if (cur -> end) {
		pre[cur -> end] = up;
		up ++;
	}
	for (auto x : cur -> ch) dfs(x, up);
}
int a, tmp[26];
void dfs2(node *cur) {
	if (!cur) return;
	if (cur -> end) {
		for (int b = 0; b < 26; ++ b) cnt[cur -> end][a][b] = tmp[b];
	}
	int acnt = cur -> ch[a] ? cur -> ch[a] -> cnt : 0;
	for (int i = 0; i < 26; ++ i) {
		if (i != a) tmp[i] += acnt;
		dfs2(cur -> ch[i]);
		if (i != a) tmp[i] -= acnt;
	}
}
char s[4 * N];
int main() {
	root = new node();
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) {
		scanf("%s", s);
		insert(s, i);
	}
	dfs(root);
	for (a = 0; a < 26; ++ a) dfs2(root);
	int m;
	scanf("%d", &m);
	for (int i = 1; i <= m; ++ i) {
		int x;
		scanf("%d%s", &x, s);
		int ans = pre[x];
		for (int i = 0; i < 26; ++ i) {
			for (int j = i + 1; j < 26; ++ j) {
				ans += cnt[x][s[i] - 'a'][s[j] - 'a'];
			}
		}
		printf("%d\n", ans + 1);
	}
}



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

int main()
{
	string str;

	while(cin >> str)
	{
		string ans;
		int JOIcount = 0, IOIcount = 0;

		for(unsigned int i = 0; i < str.size() - 2; i++){
			ans = str.substr(i, 3);
			if(ans == "JOI")
				JOIcount++;
			if(ans == "IOI")
				IOIcount++;
		}

		cout << JOIcount << endl;
		cout << IOIcount << endl;
	}

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int H, W;
vector<string>grid1,grid2;
bool dfs1(int h, int w) {
	grid1[h][w] = '.';
	if (h == H-1 && w == W-1)return false;
	rep(i, 2) {
		rep(j,2){
			if (i == j)continue;

			int dh = h + j, dw = w + i;
			if (dh < 0 || H <= dh || dw < 0 || W <= dw || grid1[dh][dw] == '.')continue;
			if (!dfs1(dh, dw))return false;
		}
	}
	return true;
}

bool dfs2(int h, int w) {
	grid2[h][w] = '.';
	if (h == H - 1 && w == W - 1)return false;
	for (int i = 1; i >= 0;i--) {
		for (int j = 1; j >= 0;j--) {
			if (i == j)continue;

			int dh = h + j, dw = w + i;
			if (dh < 0 || H <= dh || dw < 0 || W <= dw || grid2[dh][dw] == '.')continue;
			if (!dfs2(dh, dw))return false;
		}
	}
	return true;
}

int main() {
	cin >> H >> W;
	grid1.resize(H);
	rep(i, H)cin >> grid1[i];
	grid2 = grid1;
	dfs1(0, 0);
	dfs2(0, 0);
	bool ans = true;
	for (auto s : grid1) {
		for (auto ss : s)if (ss == '#')ans = false;
	}
	for (auto s : grid2) {
		for (auto ss : s)if (ss == '#')ans = false;
	}
	if (ans) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}



Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<set>
#include <utility>
using namespace std;

#define ll long long
#define MOD 1000000007;


int main() {
	ll N;
	string s, t;
	cin >> N >> s >> t;

	ll ans = 1;
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			if (s[i] == t[i])
				ans *= 3;
			else
				ans *= 6, i++;
		}
		else {
			if (s[i - 1] == t[i - 1])
				ans *= 2;
			else if (s[i] != t[i])
				ans *= 3;

			if (s[i] != t[i])
				i++;
		}
		ans %= MOD;
	}

	cout << ans << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod (ll)1000000007
using namespace std;

int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
    return a*a + b*b;
}
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lf%lf", &x[i], &y[i]);
        X += x[i]; Y += y[i];
    }
    X /= n; Y /= n;
    double P = 0.1;
    for (int i = 0; i < 30000; i++) {
        int f = 0;
        d = dist(X - x[0], Y - y[0]);
        for (int j = 1; j < n; j++) {
            e = dist(X - x[j], Y - y[j]);
            if (d < e) { d = e; f = j; }
        }
        X += (x[f] - X)*P;
        Y += (y[f] - Y)*P;
        P *= 0.999;
    }
    printf("%.15lf\n", sqrt(d));
    return 0;
}

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

using namespace std;
const int INF = 2100000000;

class Heap{
  public:
    vector<int> a;
    int N;
    Heap(int n){
      N = n;
      a.resize(N, INF);
    }

    int get_parent(int x){
      return a[(x)/2];
    }

    int get_left(int x){
      if(x*2 < N){
        return a[x*2];
      }
      return INF;
    }

    int get_right(int x){
      if(x*2+1 < N){
        return a[x*2+1];
      }return INF;
    }
};


int main(void){
  int n, a;
  cin >> n;
  n++;
  Heap hp(n);

  for(int i = 1; i < n; i++){
    cin >> a;
    hp.a[i] = a;
  }
  for(int i = 1; i < n; ++i){
    cout << "node " << i << ": key = " << hp.a[i];
    if(hp.get_parent(i) != INF){
      cout << ", parent key = " << hp.get_parent(i);
    }
    if(hp.get_left(i) != INF){
      cout << ", left key = " << hp.get_left(i);
    }
    if(hp.get_right(i) != INF){
      cout << ", right key = " << hp.get_right(i);
    }
    cout << ", " << endl;
  }
}

Measured memory_bytes: 3112
s = list(input())
t = list(input())
cnt = [0] * (len(s) - len(t) + 1)
for i in range(len(s) - len(t) + 1):
    x = s[i : i + len(t)]
    for j in range(len(t)):
        if x[j] == t[j]:
            continue
        else:
            cnt[i] += 1

print(min(cnt))


Measured memory_bytes: 9068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <utility>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,N) for(long long int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

typedef long long ll;

#define PI acos(-1.0);

string s;

int main(){
	while (cin >> s){
		REP(i, s.size()){
			if (s[i] != '@'){
				cout << s[i];
			}
			else{
				int a = s[i + 1] - '0';
				REP(j, a){
					cout << s[i + 2];
				}
				i += 2;
			}
		}
		cout << endl;
	}
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
#define PI 3.1415926536
typedef long long ll;
typedef pair<int, int> P;


vector<vector<int>> c;
int N;
vector<int> num;

int calc(int n) {
	if (c[n].size() == 0) return 0;
	if (num[n] != 0)return num[n];
	priority_queue<int> q;
	rep(i, c[n].size()) {
		q.push(calc(c[n][i]));
	}
	int ans = 0;
	int s = q.size();
	rep(i, s) {
		ans = max(ans, q.top() + i + 1);
		q.pop();
	}
	return num[n] = ans;
}

int main() {
	cin >> N;
	c = vector<vector<int>>(N);
	num = vector<int>(N);
	fill(begin(num), end(num), 0);
	rep(i, N - 1) {
		int a;
		cin >> a;
		c[a - 1].push_back(i + 1);
	}
	cout << calc(0) << endl;

	return 0;
}

Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, m;
int a[N];

int32_t main()
{
	IOS;
	cin >> n >> m;
	int sum = 0;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	int mn = (sum + 4 * m - 1) / (4 * m);
	if(a[m] >= mn)
		cout << "Yes";
	else
		cout << "No";
	return 0;	
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	private void solve() {
		int n = nextInt();
		long[]a = new long [n];
		for(int i=0;i<n;i++)a[i]=nextLong();
		long[] L = new long[n+1];
		long[] R = new long[n+1];
		long[] res = new long[n];

		for (int i=0;i<n;i++)L[i+1]=gcd(L[i],a[i]);
		for (int i=n;i>0;i--)R[i-1]=gcd(R[i],a[i-1]);
		for (int i=0;i<n;i++)res[i]=gcd(L[i],R[i+1]);
		Arrays.sort(res);
		System.out.println(res[n-1]);
	}

	static long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}

	private int nextInt() {
		return Integer.parseInt(sc.next());
	}
	private long nextLong() {
		return Long.parseLong(sc.next());
	}

}


Measured memory_bytes: 49108
count = 0
aco = 0
bco = 0
abco = 0
l = []
n = int(input())
for i in range(n):
    s = input()
    l.append(s)
    count += s.count("AB")
    if s[0] == "B" :
        bco += 1
    if s[-1] == "A" :
        aco += 1
    if s[0] == "B" and s[-1] == "A" :
        abco += 1
if max(aco,bco) == abco and aco == bco and aco != 0:
    print(count+min(aco,bco)-1)
else :
    print(count+min(aco,bco))


Measured memory_bytes: 3700
import sys
sys.setrecursionlimit(10**6)
n,k=map(int,input().split())
a=list(map(int,input().split()))
seen=[False]*n
l=[1]
now=1
while 1:
    now=a[l[-1]-1]
    l.append(now)
    if seen[now-1]:
        break
    seen[now-1]=True
now=l[-1]
until=l.index(now)
if until>k:
    print(l[k])
    sys.exit()
k-=until
loop=len(l[until:-1])
#print(l)
k%=loop
print(l[until+k])
#print(l)
#print(until,now)

Measured memory_bytes: 32300
#include <bits/stdc++.h>
using std::cin;
using std::ifstream;
using std::cout;
using std::vector;
using std::min;
using std::max;
using std::string;
using std::map;
using std::cerr;
using std::endl;
using std::sort;
using std::__gcd;
using std::ios_base;

#define oo(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
unsigned lcm(int a, int b) { return (a / __gcd(a, b) * b); }
#define fri(i,n) 			for(int i = 0 ; i < n;++i) 
#define jri(j,k,n) 		for(int j = k ; j >= n;j--) 
#define swapnumsxor 	a ^= b; b ^= a; a ^= b
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define inp(i) 				cin >> i 
#define inp2(i,j) 		cin >> i >> j  
#define inp3(i,j,k) 	cin >> i >> j >> k
#define oup(i) 				cout << i << "\n"
#define oup2(i,j) 		cout << i << " "<<j<< "\n"
#define oup3(i,j,k) 	cout << i << " "<< j << " "<<k<< "\n"
#define MOD 1000000007
#define rmdup 				std::sort(str.begin(), str.end());str.erase(std::unique(str.begin(), str.end()), str.end());

typedef long long int lli;
typedef unsigned long long int ulli;
#define pb 		emplace_back
#define mp 		make_pair
#define MAXN 	1000000
#define vi vector<int>
#define vlli vector<lli>
#define vulli vector<ulli>
const int INF = 0x3f3f3f3f;

void max_self( lli &a ,lli b ){
  a = max(a,b);

}

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
		// ifstream in("input.txt");
		lli n , W;
    inp2(n,W);
    vlli dp( W+1 );
    fri(item,n){
      lli weight , value;
      inp2(weight , value);
      for(lli w_a = W - weight; w_a >=0  ; w_a--){
        max_self( dp[w_a + weight] , dp[w_a] + value );
      }
    }

      lli ans = 0;
      for(lli i = 0;i <= W ; ++i ){
        max_self(ans, dp[i]);
      }
    oup(ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
using namespace std;
ll a[200005];
ll b[200005]={0};
int main(){
	ll n;
	cin>>n;
	for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[a[i]]++;
	}
	ll sum=0;
	for(int i=0;i<=n;i++){
            //cout<<b[i]<<endl;
        if(b[i]!=0) sum+=b[i]*(b[i]-1)/2;
    //cout<<sum<<endl;
	}
	ll pre=a[1],now;
	for(int i=1;i<=n;i++){
        if(i==1){
            sum=sum-b[pre]*(b[pre]-1)/2+(b[pre]-1)*(b[pre]-2)/2;
        }
        else {
            now=a[i];
            sum=sum+b[pre]*(b[pre]-1)/2-(b[pre]-1)*(b[pre]-2)/2-b[now]*(b[now]-1)/2+(b[now]-1)*(b[now]-2)/2;
            pre=a[i];
        }
        printf("%lld\n",sum);
	}
	return 0;
}


Measured memory_bytes: 4736
def main():
    from itertools import accumulate
    n, *ab = map(int, open(0).read().split())
    c = list(zip(*[iter(ab)] * 2))
    c.sort(key=lambda x: (x[1], x[0]))
    t = 0
    for i, j in c:
        t += i
        if t > j:
            print('No')
            break
    else:
        print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 49308
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iomanip>
using namespace std;
#define SORT(A) std::sort(A.begin(), A.end())
#define RSORT(A) std::sort(A.begin(), A.end(), std::greater<>())
#define FR(A, e) for (auto& e : A)
#define SHOW(A) for (auto& e : A) {cout << e << " ";}; cout << endl;
#define within(x,_left,_right) (_left <= x && x <= _right)
#define ALL(A) A.begin(),A.end()
#define pb push_back
#define sz(x) ((int)x.size())
#define fi first
#define se second
using LL = long long;
using db = double;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VL = vector<LL>;
using VVL = vector<VL>;
const LL MOD = 1e9 + 7;
typedef std::pair<int, int> PII;
typedef std::pair<LL, LL> PLL;
typedef std::pair<int, char> PIC;
using std::cin;
using std::vector;
using std::cout;
using std::endl;
// int dx[4] = {1, -1, 0, 0}; // 冯诺依曼型邻居
// int dy[4] = {0, 0, 1, -1};
// int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; // 摩尔型邻居
// int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// 字符串类:模拟规律 -> Greedy -> dp -> kmp || Automation (注意数据量， 先数学后暴力)
// #include<iomanip> cout << fixed <<  setprecision(k) 输出k位精度
const int N = 2e5 + 5;
LL a[N], even_mx[N / 2];
LL se[N], so[N];
LL MIN = -1e16;
LL get_even(int gt){
    if (even_mx[gt] != 0) return even_mx[gt];
    if (gt == 0) return MIN;
    if (gt == 1) return even_mx[1] = max(a[1], a[2]);
    else return even_mx[gt] = max(get_even(gt - 1) + a[2*gt], so[gt]);
}

LL helper(int len, int gt){
    if (gt == 0) return 0;
    if (len % 2 == 0) return get_even(gt);
    else {
        return max(get_even(gt), helper(len - 2, gt - 1) + a[len]);
    }
}

int main(){
    int n = 0, k = 0;
    cin >> n;
    // memset(even_mx, 0x80, sizeof(even_mx));
    for (int i = 1; i <= n; ++ i) cin >> a[i];
    for (int i = 1; i <= n; ++ i){
        if (i & 1) so[(i + 1) / 2] += (so[(i - 1) / 2] + a[i]);
        else se[i / 2] += (se[i / 2 - 1] + a[i]);
    }
    LL ans = helper(n, floor(n >> 1));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10616
A, B, C, D = list(map(int, input()))
N = 7 - A

if B+C+D == N:
    print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif B+C-D == N:
    print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif B-C+D == N:
    print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif B-C-D == N:
    print('{}+{}-{}-{}=7'.format(A, B, C, D))

elif -B+C+D == N:
    print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif -B+C-D == N:
    print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif -B-C+D == N:
    print('{}-{}-{}+{}=7'.format(A, B, C, D))
else:
    print('{}-{}-{}-{}=7'.format(A, B, C, D))

Measured memory_bytes: 3064
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << '\n';
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  vll a(9);
  rep(i, 9){
    cin >> a[i];
  }
  ll n;
  cin >> n;
  rep(i, n){
    ll b;
    cin >> b;
    rep(j, 9){
      if(a[j] == b){
        a[j] = 0;
      }
    }
  }
  if(!a[0] && !a[1] && !a[2]) Pr(1);
  if(!a[3] && !a[4] && !a[5]) Pr(1);
  if(!a[6] && !a[7] && !a[8]) Pr(1);
  if(!a[0] && !a[3] && !a[6]) Pr(1);
  if(!a[1] && !a[4] && !a[7]) Pr(1);
  if(!a[2] && !a[5] && !a[8]) Pr(1);
  if(!a[0] && !a[4] && !a[8]) Pr(1);
  if(!a[2] && !a[4] && !a[6]) Pr(1);
  Pr(0);
}


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

int compare_string(const void *a, const void *b) {
    return strcmp(*(const char **)a, *(const char **)b);
}

int main()
{
    int n;
    char *s[200000];

    for (int i = 0; i < 200000; i++)
    {
        s[i] = (char *)malloc(sizeof(char) * 11);
    }
    
    scanf("%d",&n);

    for (int i = 0; i < n; i++)
    {
        scanf("%s",s[i]);
    }
    
    qsort(s,n,sizeof(s[0]),compare_string);

    int ans = 1;
    for (int i = 0; i < n - 1; i++)
    {
        if(strcmp(s[i],s[i + 1]) != 0)
        {
            ans++;
        } 
    }
    printf("%d",ans);
}


Measured memory_bytes: 10764
#include<iostream>
using namespace std;
int main(){
  int X;
  cin>>X;
  int count=X%7;
  if(count==0)
    cout<<"thu"<<endl;
  if(count==1)
    cout<<"fri"<<endl;
  if(count==2)
    cout<<"sat"<<endl;
  if(count==3)
    cout<<"sun"<<endl;
  if(count==4)
    cout<<"mon"<<endl;
  if(count==5)
    cout<<"tue"<<endl;
  if(count==6)
    cout<<"wed"<<endl;
  return 0;
}



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

int s[200005],t[200005],T[200005];

int main(){
	int n;
	scanf("%d",&n);
	--n;
	for(register int i=1;i<=n;i++){
		scanf("%d%d%d",&s[i],&t[i],&T[i]);
	}
	for(register int i=1;i<=n;i++){
		long long sum=s[i]+t[i];
		for(register int j=i+1;j<=n;j++){
			if(sum>t[j]){
				if(sum%T[j]!=0){
					sum=(sum/T[j]+1)*T[j];
				}
			}
			else sum=t[j];
			sum+=s[j];
		}
		printf("%lld\n",sum);
	}
	printf("0");
	return 0;
}

Measured memory_bytes: 128