akhauriyash/Code-Regression huggingface dataset:
# Problem:
# Python  Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def initSet():
    result = set()
    for j in range(ord('a'),ord('z')+1):
        result.add(chr(j))
    return result

def solver(inputString,allCharSet):
    result = ''
    inputSet = set(inputString)
    # print("INPUT={}".format(inputSet))
    # print("ALL={}".format(allCharSet))
    diffset = allCharSet - inputSet
    # print("DIFF={}".format(diffset))
    difflist = list(diffset)
    difflist.sort()
    # print("{}".format(difflist))
    if len(difflist) == 0:
        result = "None"
    else:
        result = difflist[0]
    return result

if __name__ == "__main__":
    S = sys.stdin.readline().split('\n')
    allset = initSet()
    print("{}".format(solver(S[0],allset)))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int64_t s=0;
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    s+=a.at(i);
  }
  int64_t s0=0;
  for(int i=1;i<n;i+=2)
    s0+=a.at(i)*2;
  vector<int64_t> w(n);
  w.at(0)=s-s0;
  for(int i=1;i<n;i++){
    w.at(i)=(a.at(i-1)-w.at(i-1)/2)*2;
    cout<<w.at(i-1)<<" ";
  }
  cout<<w.at(n-1)<<endl;
}

Measured memory_bytes: 2432
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    d = [int(readline()) for _ in range(N)]
    print(len(set(d)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62000
from sys import stdin
from collections import deque

V, E, R = [int(x) for x in stdin.readline().split()]
d = {}
tick = False
INF = float('inf')
for i in range(V):
    d[i] = INF
d[R] = 0
weight = {}
st = []
for i in range(1, V+1):
    for j in range(E):
        if i == 1:
            s, t, w = [int(x) for x in stdin.readline().split()]
            weight[(s, t)] = w
            st.append((s, t))
        (s, t) = st[j]
        if d[t] > d[s] + weight[(s, t)]:
            d[t] = d[s] + weight[(s, t)]
            if i == V:
                print('NEGATIVE CYCLE')
                quit()

for k in range(V):
    if d[k] == float('inf'):
        print("INF")
    else:
        print(d[k])

Measured memory_bytes: 8900
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  
  REP(i,n){
    if((i+1) % 3 == 0 || (i+1) % 5 == 0 ){
      continue;
    }
    ans += i+1;
  }
  
  cout << ans << endl;
    

 
  
}

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>p(n);
	for (int i = 0; i < n; i++)cin >> p.at(i);
	sort(p.begin(), p.end());
	ll ans = 0;
	for (int i = 0; i < k; i++)ans += p.at(i);
	cout << ans << endl;
}

Measured memory_bytes: 3628
import copy
N=str(input())
K=int(input())
m=len(N)
def con(n,r):
  if r==0:
    return 1
  else:
    return (n/r)*con(n-1,r-1)
S=0
for i in range(1,m):
  S=S+(9**K)*con(i-1,K-1)
if K==1:
  S=S+int(N[0])
  print(int(S))
if K==2:
  S=S+9*(m-1)*(int(N[0])-1)
  for i in range(1,m):
    for i1 in range(1,10):
      N1=(int(N[0]))*(10**(m-1))+i1*10**(m-i-1)
      if int(N)>=N1:
        S=S+1
  print(int(S))
if K==3:
  S=S+(int(N[0])-1)*(9**2)*con(m-1,K-1)
  for i in range(1,m-1):
    for j in range(i+1,m):
      for i1 in range(1,10):
        for j1 in range(1,10):
          N1=(int(N[0]))*(10**(m-1))+i1*10**(m-i-1)+j1*10**(m-j-1)
          if int(N)>=N1:
            S=S+1
  print(int(S))

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

using ll = long long;

#define vl vector<long long>
using pll = pair<long long, long long>;
#define __ << '\n'
#define _ << ' '
#define all(x) (x).begin(), (x).end()

void error()
{
    cout << "-1";
    exit(0);
}

#define flush fflush(stdout)


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

    ll n;
    cin >> n;
    vector<ll> ot(n);
    for (auto i = 0; i < n; i++)
        cin >> ot[i];

    ll ma = -1;
    ll sum = 0;

    for (auto e : ot)
    {
        sum += e;
        ma = max(ma, e);
    }

    if (ma < sum - ma)
    {
        cout << "Yes";
    } else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;

int main(){
   ll N, C, x[100000], v[100000];
   scanf("%lld%lld", &N, &C);
   for(ll i = 0; i < N; i++) scanf("%lld%lld", &x[i], &v[i]);
   ll smax[2][2][100000];
   for(ll i = 0; i < N; i++) smax[0][0][i]=smax[0][1][i]=smax[1][0][i]=smax[1][1][i]=0;
   ll cal = v[0];
   smax[0][0][0] = max((ll) 0, cal - x[0]);
   smax[0][1][0] = max((ll) 0, cal - 2*x[0]);
   for(ll i = 1; i < N; i++){
      cal += v[i];
      smax[0][0][i] = max(smax[0][0][i-1], cal - x[i]);
      smax[0][1][i] = max(smax[0][1][i-1], cal - 2*x[i]);
   }
   cal = v[N-1];
   smax[1][0][N-1] = max((ll) 0, cal - (C - x[N-1]));
   smax[1][1][N-1] = max((ll) 0, cal - 2 * (C - x[N-1]));
   for(ll i = N-2; i >= 0; i--){
      cal += v[i];
      smax[1][0][i] = max(smax[1][0][i+1], cal - (C - x[i]));
      smax[1][1][i] = max(smax[1][1][i+1], cal - 2 * (C - x[i]));
   }
   ll ans = max(smax[0][0][N-1], smax[1][0][0]);
   for(ll i = 0; i < N-1; i++){
      ans = max(ans, max(smax[0][0][i]+smax[1][1][i+1], smax[0][1][i]+smax[1][0][i+1]));
   }
   printf("%lld\n",ans);
}

Measured memory_bytes: 4864
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i, j, m, n;
		int [] Pasta = new int[3];
		int [] Pasta1 = new int[3];
		int [] Juice = new int[2];
		int [] Juice1 = new int[2];
		for(i = 0; i < 3; i++){
			Pasta[i] = sc.nextInt();
		}
		for(i = 0; i < 2; i++){
			Juice[i] = sc.nextInt();
		}
		for(i = 0; i < 3; i++){
			n = 0;
			for (j = 0; j < 3; j++) {
				if (Pasta[j] < Pasta[i]) {
				n++;
				}
			}
			Pasta1[n] = Pasta[i];
		}
		for(i = 0; i < 2; i++){
			m = 0;
			for (j = 0; j < 2; j++) {
				if (Juice[j] < Juice[i]) {
				m++;
				}
			}
			Juice1[m] = Juice[i];
		}
		System.out.println(Pasta1[0] + Juice1[0] - 50);
	}
}

Measured memory_bytes: 17324
/*/ Author:amar1503/*/
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize ("Ofast")
//common
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,n) for(int i=0;i<n;i++)
#define Afor(i,v) for(auto i:(v))
//#define bfor(i,a,b) for(int i=a;i<b;i++)
//#define rfor(i,n) for(int i=n-1;i>=0;i--)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define vect(v,n) int (n); cin>>(n); vector <int> v(n); for(int i=0;i<(n);i++) cin>>v[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
//containers
#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz(v) (v).size()
//#define sortv(v)  sort((v).begin(),(v).end())
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)   (v).erase(unique(all(v)),(v).end())
//#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
//#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//equal range can also be used

typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;

/*/-----------------------------Code begins----------------------------------/*/
int main(){
    fio;
int n;
cin>>n;
long double x;
string s;
long double sum=0;
For(i,n){
    cin>>x;
    cin>>s;
    if(s=="JPY")
        sum+=x;
    else sum+=(x*(long double)380000.0);
}
cout<<sum;
return 0;}










Measured memory_bytes: 256
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;

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


  int H,W; cin>>H>>W;
  vs S(H); REP(i,H) cin>>S[i];


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

  int ans = 0;
  REP(sx,H) {
    REP(sy,W) {
      if (S[sx][sy] == '#') continue;
      
      vvi dist(H, vi(W, 0));
      vvb vis(H, vb(W, false));
      queue<pii> que;
      dist[sx][sy] = 0;
      que.push(mkpr(sx,sy));
      while(!que.empty()) {
        auto pr = que.front(); que.pop();
        int x = pr.first, y = pr.second;
        vis[x][y] = true;
        REP(i,4) {
          int nx = x + dx[i], ny = y + dy[i];
          if (nx<0 || H<=nx || ny<0 || W<=ny) continue;
          if (S[nx][ny]=='#') continue;
          if (vis[nx][ny]) continue;

          dist[nx][ny] = dist[x][y]+1;
          vis[nx][ny] = true;
          ans = max(ans, dist[nx][ny]);

          que.push(mkpr(nx,ny));
        }
      }

    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, k, P;
    double ans = 0;
    cin >> n >> k;
    vector<double> p(n+1, 0);
    for(int i = 1; i < n+1; i++){
        scanf("%d", &P);
        p[i] = (P * (P + 1)) / 2 / (double)P;
    }
    for(int i = 0; i < n+1; i++){
        p[i] += p[i-1];
    }
    for(int i = 0; i+k < n+1; i++){
        ans = max(ans, p[i+k] - p[i]);
    }
    // cout << ans << endl;
    printf("%.10lf\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int face[7][7][4] = {
{{0},{0},{0},{0},{0},{0},{0}},
{{0},{0},{0,1,2,3},{0,1,3,5},{0,1,4,2},{0,1,5,4},{0}},
{{0},{0,2,1,4},{0},{0,2,3,1},{0,2,4,6},{0},{0,2,6,3}},
{{0},{0,3,1,2},{0,3,2,6},{0},{0},{0,3,5,1},{0,3,6,5}},
{{0},{0,4,1,5},{0,4,2,1},{0},{0},{0,4,5,6},{0,4,6,2}},
{{0},{0,5,1,3},{0},{0,5,3,6},{0,5,4,1},{0},{0,5,6,4}},
{{0},{0},{0,6,2,4},{0,6,3,2},{0,6,4,5},{0,6,5,3},{0}}};
int assign[7];

int main()
{
	int q, i, t, f;

	for (i = 1; i <= 6; i++) scanf("%d", assign+i);
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &t, &f);
		for (i = 1; i <= 6; i++) {
			if (assign[i] == t) t = i;
			if (assign[i] == f) f = i;
		}
		printf("%d\n", assign[face[t][f][3]]);
	}
	return 0;
}





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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define ins insert
#define er erase
#define bg begin()
#define ed end()
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define files(name) fin(name".in"); fout(name".out")
#define enter cout << "\n"
#define space cout << " "
#define endl "\n"
#define fi(st,n) for (int i = (st); i <= (n); ++i)
#define fj(st,n) for (int j = (st); j <= (n); ++j)
#define fk(st,n) for (int k = (st); k <= (n); ++k)
#define fq(st,n) for (int q = (st); q <= (n); ++q)
#define fw(st,n) for (int w = (st); w <= (n); ++w)
#define ff(i, st, n) for (int (i) = (st); (i) <= (n); ++(i))
#define ei(st,n) for (int i = (st); i >= (n); --i)
#define ej(st,n) for (int j = (st); j >= (n); --j)
#define ek(st,n) for (int k = (st); k >= (n); --k)
#define ef(i, st, n) for (int (i) = (st); (i) >= (n); --(i))
#define ri(st,n) for (int i = (st); i < (n); ++i)
#define rj(st,n) for (int j = (st); j < (n); ++j)
#define rk(st,n) for (int k = (st); k < (n); ++k)
#define rq(st,n) for (int q = (st); q < (n); ++q)
#define rf(i, st, n) for (int (i) = (st); (i) < (n); ++(i))
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define y1 dsklmlvmd

typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int inf = (int)1e9;
const dbl eps = (dbl) 1e-8;
const int mod = (int) 1000000007;
const int maxn = (int) 1e5 + 5;
//const dbl M_PI = (dbl)2 * (dbl)acos(0);

//cout<<fixed<<setprecision(10);
//srand(time(0));

int k;
string st;

int main()
{
//    fin("t.in");
    sync;
    cin >> st >> k;
    ri(0, st.size()) {
        if (st[i] == 'a')
            continue;
        if ('z' - st[i] + 1 <= k) {         
            k -= 'z' - st[i] + 1;
            st[i] = 'a';
        }
    }
    k %= 26;
    st[(int)st.size() - 1] = st[(int)st.size() - 1] + k;
//    while (st[(int)st.size() - 1] > 'z') {
//        st[(int)st.size() - 1] -= 26;
//    }
    cout << st << endl;
    return 0;
}




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

XOR_all = a[0]
for i in range(N-1):
    XOR_all = XOR_all ^ a[i+1]


ans = []
for i in range(N):
    p = a[i]
    ans.append(p^XOR_all)

print(*ans)

Measured memory_bytes: 31448
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       
        String s = sc.next();
        StringBuilder sb = new StringBuilder(s);
        String t = "no";

        
        do {            
            sb.reverse();
            sb.deleteCharAt(0);
            sb.reverse();
            if (sb.substring(0, (sb.length() / 2)) .equals(sb.substring(sb.length() / 2, (sb.length())))) {
                
                System.out.println(sb.length());
                t = "yes";
            }
        } while (t == "no");

    }
}


Measured memory_bytes: 22740
#include <stdio.h>
#include <math.h>

int main(void){
    int n, k;
    scanf("%d %d", &n, &k);
    double p=0;
    for(int i=1; i<=n; i++){
        int point=i, cnt=0;
        while(point<k){
            point*=2;
            cnt++;
        }
        p+=(1.0/n)*(1/pow(2, cnt));
    }
    printf("%.12lf\n", p);
    return 0;
}


Measured memory_bytes: 2528
# 絶対値誤差を最小値にする値は中央値である

def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import functools

    n = int(input())
    as_ = list(map(int, input().split()))

    as_minus_i = [a - i for a, i in zip(as_, range(1, n + 1))]
    median = sorted(as_minus_i)[n // 2]
    
    ans = functools.reduce(lambda x, y: x + abs(y - median), as_minus_i, 0)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 27000
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	
	int x;
	cin >> x;
	syc(x,0,9999);
	int b,c;
	b=x/100;
	c=x%100;
	
	if((1<=b && b<=12) && (1<=c && c<=12))cout <<"AMBIGUOUS" << endl;
	else if(1<=b && b<=12)cout <<"MMYY" << endl;
	else if(1<=c && c<=12)cout <<"YYMM" << endl;
	else cout <<"NA" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b!=c){
    cout<<"Yes"<<endl;
  }else if(a!=b&&b==c){
    cout<<"Yes"<<endl;
  }else if(a==c&&c!=b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

answer = ''
for i in range(len(S)-len(T)+1):
    if any([S[i+j] != '?' and S[i+j] != T[j] for j in range(len(T))]):
        continue
    tmp = (S[:i] + T + S[i+len(T):]).replace('?', 'a')
    if answer == '' or tmp < answer:
        answer = tmp 

if answer == '':
    print('UNRESTORABLE')
else:
    print(answer)

Measured memory_bytes: 3064
#include <cstdio>
#define ll long long int
int vis[1000005], prime[1000005], pa;
int N, flag;
ll A[1000010], Gcd;
ll GCD(ll a, ll b)
{
	return (a%b==0) ? b : GCD(b, a%b);
}
void Euler(int n)
{
	for(int i=2;i<=n;i++)
	{
		if(!vis[i])     //是质数 
			prime[pa++] = i;
		for(int j=0;j<pa&&prime[j]*i<=n;j++)
		{
			vis[prime[j]*i] = 1;
			if(i%prime[j]==0)
			    break;
		}
	}
}
void work(ll n)      //对n质因数分解 
{
	for(int i=0;i<pa&&prime[i]*prime[i]<=n;i++)
	{
		if(n%prime[i]==0)
		{
			if(vis[prime[i]]==0)
			    vis[prime[i]] = 1;
			else
			{
				flag = 1;    //此时肯定不是两两互质 
				return;
			}
			while(n%prime[i]==0)
			    n /= prime[i];
		}
	}
	if(n>1)
	{
		if(vis[n]==0)
		    vis[n] = 1;
		else
		{
			flag = 1;
			return;
		}
	}
}
int main()
{
	Euler(1000000);
	scanf("%d", &N);
	for(int i=1;i<=N;i++)
	{
		scanf("%lld", &A[i]);
		if(!flag)
		    work(A[i]);
		if(Gcd==0)
		    Gcd = A[i];
		else Gcd = GCD(Gcd, A[i]);
	}
	if(!flag) 
	    printf("pairwise coprime\n");
	else if(flag&&Gcd==1) 
	    printf("setwise coprime\n");
    else printf("not coprime\n");
	return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

 
int main(void) {
	// your code goes here
	int d[100000];
	int N;
	scanf("%d",&N);
	for(int i = 0; i < N; i++)scanf("%d",&d[i]);
	sort(d, d+N);
	int ln = -1;
	int cout = 0;
	for(int i = 0; i < N; i++){
		if(ln != d[i]){
			cout++;
			ln = d[i];
		}
	}
	if(cout % 2 != 0)printf("%d",cout);
	if(cout % 2 == 0)printf("%d",cout-1);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mmax=1e2+5;
int a[mmax],l,r;
int an[mmax],top,antmp[mmax];
ll maxans,ans;
bool bo[mmax][mmax][mmax];
void dfs(int k)
{
 	if(bo[k][l][r])return;
  	bo[k][l][r]=1;
    //cout<<ans<<" "<<k<<" "<<l<<" "<<r<<endl;
    int ji=0;
    for(int i=0;i<top;i++)
        antmp[i]=an[i];
    sort(antmp,antmp+top);
    for(int i=0;i<k&&i<top;i++)
        if(antmp[i]<0)ji+=antmp[i];
        else break;
    maxans=max(maxans,max(ans,ans-ji));
    //for(int i=0;i<top;i++)
    //    cout<<antmp[i]<<" ";
    //cout<<"!!!"<<endl;
    //cout<<ans<<" "<<maxans<<" "<<ji<<endl;
    if(k==0)return;
    if(k>=0&&r>=l)
    {
        {
            ans+=a[l];
            an[top++]=a[l];
            l++;
            dfs(k-1);
            top--;
            l--;
            ans-=a[l];
        }
        {
            ans+=a[r];
            an[top++]=a[r--];
            dfs(k-1);
            top--;
            r++;
            ans-=a[r];
        }
    }
}

int main()
{
    ans=0;maxans=0;
    int n,m;

    cin>>n>>m;
    l=1,r=n,top=0;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    dfs(m);
    cout<<maxans<<endl;
}


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

int main()
{
  // 入力
  int N;                // 問題案
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++) {
    cin >> D[i];
  }

  int M;        // 問題セット
  cin >> M;
  vector<int> T(M);
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }

  // 並び替え
  sort(D.begin(), D.end());
  sort(T.begin(), T.end());

  int j = 0; // 問題案カウンタ
  int count = 0; // i = Mまでいけば全問ある
  for (int i = 0; i < M; i++) {
    if (D[j] < T[i]) {while (D[j] < T[i] && j < D.size()) j++;}
    if (D[j] == T[i]) {
      count++;
      j++;
    }
    else if (D[j] > T[i]) break;
  }

  if (count == M) cout << "YES" << endl;
  else cout <<  "NO" << endl;

  return 0;
}

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

using namespace std;

int main()
{
    int n, m, X, Y; cin >> n >> m >> X >> Y;
    int maxX = X;
    int minY = Y;

    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        if (maxX < x) maxX = x;
    }
    for (int i = 0; i < m; i++) {
        int y; cin >> y;
        if (minY > y) minY = y;
    }

    cout << (maxX < minY ? "No War" : "War") << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define L 19
#define M 262144
const int mo=998244353;
typedef long long LL;
using namespace std;
int n,m;
int a[M+1],b[M+1];
LL ksm(LL k,LL n)
{
	LL s=1;
	for(;n;n>>=1,k=k*k%mo) if(n&1) s=s*k%mo;
	return s;
}
const LL ny2=499122177;
void FWT(int *a,bool pd)
{
	for(int h=1;h<m;h<<=1)
		for(int j=0;j<M;j+=h*2)
			fo(i,0,h-1)
			{
				int v=a[i+j+h];
				a[i+j+h]=(a[i+j]-v+mo)%mo,a[i+j]=(a[i+j]+v)%mo;
				if(pd) a[i+j]=(LL)a[i+j]*ny2%mo,a[i+j+h]=(LL)a[i+j+h]*ny2%mo;
			}
}
LL pr[M];
int main()
{
	cin>>n;
	m=1<<n;
	LL sum=0;
	fo(i,0,m-1) scanf("%lld",&pr[i]),sum=(sum+pr[i])%mo;
	sum=ksm(sum,mo-2);
	a[0]=m-1;
	fo(i,1,m-1) a[i]=mo-1;
	fo(i,0,m-1) b[i]=pr[i]*sum%mo;
	b[0]=(b[0]-1+mo)%mo;
	FWT(a,0),FWT(b,0);
	int wz=0;
	fo(i,0,m-1)
	{
		if(b[i]!=0) a[i]=(LL)a[i]*ksm(b[i],mo-2)%mo;
		else a[i]=0,wz=i;
	}
	FWT(a,1);
	LL wp=(LL)(mo-a[0])*m%mo;
	FWT(a,0);
	a[wz]=wp;
	FWT(a,1);
	fo(i,0,m-1) printf("%d\n",a[i]);
}

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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define SIN(x) string x; cin>>(x);
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x,v) lower_bound((x).begin(),(x).end(),(v))-(x).begin();
#define uboundv(x,v) upper_bound((x).begin(),(x).end(),(v))-(x).begin();
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;
typedef long double LD;

using namespace std;

string s;
string getsubs(int i, int j) {
    string r = "";
    for(int k=i; k<=j; k++) {
        r.pb(s[k]);
    }
    return r;
}

int main() {
	ios::sync_with_stdio(0);
    cin>>s;
    int k; set<string> st;
    cin>>k;
    F(s.size()) {
        FF(k) {
            if(i+j >= s.size()) break;
            string a = getsubs(i, i+j);
            //cout<<"inserting "<<a<<endl;
            st.insert(a);
        }
    }
    F(k-1) {
        auto it = st.begin();
    //cout<<(*it)<<endl;
        st.erase(it);
    }
    auto it = st.begin();
    cout<<(*it)<<endl;
	return 0;
}


Measured memory_bytes: 1664
/* 
 * Project: M-SOLUTIONS プロコンオープン 2020 C - Marks
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/25
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <vector>
using namespace std;

int n;
int k;
vector<int> a;

void solve() {

    for (int i=k;i<n;i++) {
        if (a[i-k] < a[i])
            printf("Yes\n");
        else
            printf("No\n");
    }
}

int main() {

    scanf("%d", &n);
    scanf("%d", &k);
    for (int i=0;i<n;i++) {
        int tmp;
        scanf("%d", &tmp);
        a.push_back(tmp);
    }

    solve();
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007

int n;
vector<int> g[1111],rg[1111],ng[1111];
vector<int> vs;
bool used[1111];
int cmp[1111];

void dfs(int v){
  used[v]=true;
  for(int nv: g[v]){
    if(!used[nv])dfs(nv);
  }
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int nv: rg[v]){
    if(!used[nv])rdfs(nv,k);
  }
}

int m,k;
ll mem[1111][3];

ll rec(int v,int c){
  if(mem[v][c]!=-1)return mem[v][c];
  ll res=1;
  for(int nv:ng[v]){
    if(c==0){
      res=(res*(rec(nv,0)+rec(nv,1)))%mod;
    }else{
      res=(res*rec(nv,1))%mod;
    }
  }
  return mem[v][c]=res;
}

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>m;
  rep(i,m){
    int s,t;
    cin>>s>>t;
    s--; t--;
    g[t].push_back(s); rg[s].push_back(t);
  }
  memset(used,0,sizeof(used));
  vs.clear();
  rep(i,n){
    if(!used[i])dfs(i);
  }
  memset(used,0,sizeof(used));
  for(int i=vs.size()-1;i>=0;i--){
    if(!used[vs[i]])rdfs(vs[i],k++);
  }
  rep(i,n){
    for(int v: g[i]){
      if(cmp[i]<cmp[v]&&!exist(ng[cmp[i]],cmp[v]))ng[cmp[i]].push_back(cmp[v]);
    }
  }
  ll res=1;
  memset(mem,-1,sizeof(mem));
  rep(i,k){
    if(mem[i][0]==-1){
      res=(res*(rec(i,0)+rec(i,1)))%mod;
    }
    //dbg(rec(i,0)); dbg(rec(i,1));
  }
  cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3352
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    int sn = 0;
    for (int tmpn = n; tmpn != 0; tmpn /= 10) {
        sn += tmpn % 10;
    }
    if (n % sn == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal A = new BigDecimal(sc.next());
		BigDecimal B = new BigDecimal(sc.next());
		sc.close();
		BigDecimal ans = A.multiply(B);
		System.out.println(ans.setScale(0, RoundingMode.DOWN));

	}
}


Measured memory_bytes: 35952
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  int N;
  cin >> N;
  vi a(N);
  ll ans = 0;
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    ans += (ll)a.at(i) - 1LL;
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline().rstrip())
P = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0
ans = 0
for i,j in enumerate(P):
    if i+1 == j:
        cnt += 1
    else:
        ans += ((cnt+1)//2)
        cnt = 0
ans += ((cnt+1)//2)
print(ans)

Measured memory_bytes: 13880
A = int(input())
B = int(input())
C = int(input())
X = int(input())

if A > 40:
	Amax = 40
else:
	Amax = A

ans = 0
for i in range(Amax+1):
	for j in range(B+1):
		for k in range(C+1):
			if 500*i + 100*j + 50*k == X:
				ans += 1

print(ans)

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)	
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7  ;
#define ld long double
#define MAX (int)(pow(10,5)+ 10)




void deal(){
	ll n, m ;
	cin>>n>>m;
	vector<vector<ll> > g(n);
	vector<ll> cixan(n, 0);
	fori(m){
		ll x, y;
		cin>>x>>y;
		--x, --y;
		g[y].pb(x);
		cixan[x]++;
	}
	vector<ll> bfs;
	vector<ll> dp(n,0);
	fori(n)
		if(!cixan[i])
			bfs.pb(i);
	ll mx= 0 ;
	fori(bfs.size()){
		ll hd = bfs[i];
		mx = max(mx, dp[hd]);
		for(auto hr : g[hd]){
			--cixan[hr];
			dp[hr] = max(dp[hr], dp[hd]+1);
			if(!cixan[hr])
				bfs.pb(hr);
		}
	}
	cout<<mx;
}
 
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}
 
/*
 
5 1
1 2 3 4 5


*/

Measured memory_bytes: 8440
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;


#define FOR(i, n) for (int i = 0; i < (n); ++i)


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vec(istream& in, size_t n) {
  vector<T> ret(n);
  for (size_t i = 0; i < n; ++i) {
    ret[i] = next<T>(in);
  }
  return ret;
}


void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto who = next_vec<int>(in, n);
  int res = 0;
  FOR(i, n) {
    --who[i];
  }
  FOR(i, n) {
    if (who[who[i]] == i) {
      ++res;
    }
  }
  res /= 2;
  out << res << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 3700
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int n = as.nextInt();
		for(int i=(int)Math.sqrt(n)/2;i<=n;i++){
			if(n<=(i*(i+1))/2){
				System.out.println(i);
				break;
			}
		}
	}
}

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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    int first = 10 * (s[0]-'0') + (s[1]-'0');
    int second = 10 * (s[2]-'0') + (s[3] - '0');

    if(first >= 1 && first <= 12){
        if(second >= 1 && second <= 12){
            cout << "AMBIGUOUS" << endl;
            return 0;
        }else{
            cout << "MMYY" << endl;
            return 0;
        }
    }else{
        if(second >= 1 && second <= 12){
            cout << "YYMM" << endl;
            return 0;
        }else{
            cout << "NA" << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
s = gets.chomp

(0..s.length-1).each do |i|
  if i % 2 == 0 then
    if s[i] == "L" then
      puts "No"
      exit 0
    end
  else
    if s[i] == "R" then
      puts "No"
      exit 0
    end
  end
end
puts "Yes"


Measured memory_bytes: 1788
N = int(input())
S = input()
ans = 0
r = g = b = rg = rb = gb = 0

for c in S:
    if c=="B":
        ans += rg
        rb += r
        gb += g
        b += 1
    elif c=="G":
        ans += rb
        rg += r
        gb += b
        g += 1
    else:
        ans += gb
        rg += g
        rb += b
        r += 1
for j in range(1, N):
    Sj = S[j]
    for Si, Sk in zip(S[j-1::-1], S[j+1:]):
        if len({Si, Sj, Sk}) == 3:
            ans -= 1
print(ans)


Measured memory_bytes: 68920
#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 mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__",", __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define long long long // for codeforces

int main(){
  int r,c,n;
  cin>>r>>c>>n;
  vector<pair<int,int>> vec;

  auto ins = [&](int x, int y, int i){
    if(x==0) vec.pb(mp(y,i));
    else if(y==c) vec.pb(mp(c+x,i));
    else if(x==r) vec.pb(mp(r+c+c-y,i));
    else if(y==0) vec.pb(mp(r+c+c+r-x, i));
  };

  auto ok = [&](int x, int y){
    return x==0 || y==0 || x==r || y==c;
  };

  rep(i,n){
    int a,b,cc,d;
    cin>>a>>b>>cc>>d;
    if( ok(a,b) && ok(cc,d) ){
      ins(a,b,i);
      ins(cc,d,i);
    }
  }
//dbg(vec);
  sort(all(vec));
  stack<int> st;
  for(auto &p : vec){
    int i = p.se;
    if(!st.empty() && st.top() == i) st.pop();
    else st.push((int)i);
  }

  if(st.size()==0) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int X, Y; cin >> X >> Y;
    //A+B = Xのもと2A+4B=Yとなるか？
    bool ok = false;
    for(int i = 0; i <= X; i++){
        int A = i, B = X-i;
        if(2*A + 4*B == Y) ok = true;
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	string s;
	cin>>n>>s;
	for(int i=0;i+2<n;i++){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
	}
	cout<<ans;
	return 0;
}

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

#define int int_fast64_t

struct exam {
  int l, u, b;
  int cost(int score) const {
    int c = score >= b ? u : l;
    return c*(score - b);
  }
  int gain(int score) const {
    return cost(score) - cost(0);
  }
  int score_for_mingain(int mingain, int x) const {
    assert(gain(0) < mingain && gain(x) >= mingain);
    
    // invariant: gain(l)<mingain, gain(r)>=mingain
    int l=0, r=x;
    while (r-l > 1) {
      int m = (l+r)/2;
      if (gain(m) < mingain)
        l = m;
      else
        r = m;
    }
    assert(gain(l)  < mingain);
    assert(gain(r) >= mingain);
    return r;
  }
};

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

  int n, x; cin >> n >> x;
  vector<exam> exams;
  for (int i = 0; i < n; ++i) {
    exam e;
    cin >> e.b >> e.l >> e.u;
    exams.push_back(e);
  }
  int score=0;
  for (auto& e : exams) score += e.cost(0);

  // maximize gain (more=better)
  auto key = [&](exam const& e) { return e.gain(x); };
  sort(exams.begin(), exams.end(), [&](exam const& a, exam const& b) { return key(a) > key(b); });

  const int INF = numeric_limits<int>::max();
  int best=INF;

  int max_taken = 0;
  for (; score < 0 && max_taken < n; ++max_taken) {
    auto const& e = exams[max_taken];
    assert(score < 0);
    score += e.gain(x);
  }
  assert(score >= 0);
  
  if (score == 0) {
    best = max_taken*x;
  } else {
    assert(max_taken >= 1);
    for (int i = 0; i < n; ++i) {
      auto const& e = exams[i];
    
      int base_score = score - exams[min(i, max_taken-1)].gain(x);
      assert(base_score < 0);
      if (base_score + e.gain(x) < 0)
        continue; // can't take it, not enough gain
      best = min(best, x*(max_taken-1) + e.score_for_mingain(-base_score, x));
    }
  }
  assert(best < INF);
  cout << best << '\n';
}


Measured memory_bytes: 4852
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var M = int.Parse(inputs[1]);
        var A = new long[N];
        inputs = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
        {
            A[i] = long.Parse(inputs[i]);
        }
        var bcList = new List<BC>(M);

        for (int i = 0; i < M; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            var b = int.Parse(inputs[0]);
            var c = long.Parse(inputs[1]);
            var newBc = new BC(b, c);
            bcList.Add(newBc);
        }

        bcList = bcList.OrderByDescending(bcd => bcd.C).ToList();
        A = A.OrderBy(a => a).ToArray();

        int bcIndex = 0;
        var bc = bcList[bcIndex];
        var cCount = 0;
        long sum = 0;
        for (int i = 0; i < N; i++)
        {
            var a = A[i];
            sum += a;
            if (bc.C >= a && cCount < bc.B && bcIndex <= bcList.Count - 1)
            {
                sum -= a;
                sum += bc.C;
                cCount++;
            }
            if (cCount >= bc.B)
            {
                bcIndex++;
                if(bcIndex <= bcList.Count - 1)
                {
                    bc = bcList[bcIndex];
                    cCount = 0;
                }
            }
        }

        Console.WriteLine(sum);
    }

    struct BC
    {
        internal int B;
        internal long C;
        internal BC(int B, long C)
        {
            this.B = B;
            this.C = C;
        }
    }
}



Measured memory_bytes: 36912
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))


int main(){
    int N,P;
    cin >> N >> P;
    vector<int> A(N);

    for(int i = 0;i < N;i++)
        cin >> A.at(i);

    vector<int>kisuu(N),gusuu(N);

    int l = 0,m = 0;
    for(int i = 0;i < N;i++){
        if(A.at(i) % 2 == 0){
            gusuu.at(m) = A.at(i);
            m++;
        }else{
            kisuu.at(l) = A.at(i);
            l++;
        }
        
    }


    if(P == 0){
        ll count = 1;
        for(int i = 1;i < l;i++)
            count *= 2;
        for(int i = 0;i < m;i++)
            count *= 2;

        cout << count << endl;
    }else{
        if(l==0)
            cout << 0 << endl;
        else{
            ll count = 1;
            for(int i = 1;i < l;i++)
                count *= 2;
            for(int i = 0;i < m;i++)
                count *= 2;
            cout << count << endl;
        }
    }

    return 0;

}

Measured memory_bytes: 3604
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    int x1,y1,x2,y2;cin >> x1 >> y1 >> x2 >> y2 ;
    int dx=x2-x1,dy=y2-y1;

    cout << x2 - dy << " " << y2 + dx << " " << x2 - dy - dx << " " << y2 + dx -dy << endl;

} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin >> n;
    int a[n][n-1];
    vector<bool> b(n,true);
    vector<int> c(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int cnt=0,ans=0;
    while(cnt<n*(n-1)/2){
        vector<int> d(n);
        int sum=0;
        for(int i=0;i<n;i++){
            if(!b[i]||c[i]==n-1){
                continue;
            }
            int t=a[i][c[i]];
            if(a[t][c[t]]==i&&!d[i]){
                sum++;
                d[i]=true;
                d[t]=true;
            }
        }
        for(int i=0;i<n;i++){
            b[i]=d[i];
            if(d[i]){
                c[i]++;
            }
        }
        if(sum==0){
            cout << -1 << endl;
            return 0;
        }
        cnt+=sum;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int n, res, a[110];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    res = 1000000000;
    FOR(i,-100,100) {
        int e = 0;
        FOR(j,1,n) e += (a[j]-i)*(a[j]-i);
        res = min(res, e);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [[0, 0, 0]]
S.extend([list(map(int, input().split())) for i in range(N)])

for i in range(N):
    t = abs(S[i][0] - S[i + 1][0])
    d = abs(S[i][1] - S[i + 1][1]) + abs(S[i][2] - S[i + 1][2])
    if t < d:
        print("No")
        exit()
    if t % 2 != d % 2:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 63576
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	a := make([][3]int, N)
	for i := range a {
		fmt.Scan(&a[i][0], &a[i][1], &a[i][2])
	}
	// fmt.Println("N", N, "a", a)
	dp := make([][3]int, N+2) // DPテーブル
	// 0-indexed
	// i-1日目までの最大幸福度をdp[i]としたとき、
	// i日目までの最大幸福度dp[i+1]を求めたい
	// 初期値は0で良い
	// 遷移方向は以下の通り
	// dp[i][0] => dp[i+1][1] or dp[i+1][2]
	// dp[i][1] => dp[i+1][0] or dp[i+1][2]
	// dp[i][2] => dp[i+1][0] or dp[i+1][1]
	for i := 0; i < N; i++ {
		dp[i+1][0] = max(dp[i][1]+a[i][0], dp[i][2]+a[i][0])
		dp[i+1][1] = max(dp[i][0]+a[i][1], dp[i][2]+a[i][1])
		dp[i+1][2] = max(dp[i][1]+a[i][2], dp[i][0]+a[i][2])
	}
	// fmt.Println("dp", dp)
	fmt.Println(max(dp[N][0], max(dp[N][1], dp[N][2])))
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  ll third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}
//降順
bool comp_Th(T& l, T& r){
  return l.third > r.third;
}
int N;
vector<T> v;

int main(void){
  cin >> N;
  v.resize(N);
  int i,j,k;
  ll h,h_;
  bool true_flag;
  REP(i,N)cin >> v[i].first >> v[i].second >> v[i].third;
  sort(v.begin(),v.end(),comp_Th);
  REP(i,101){
    REP(j,101){
      h = v[0].third + abs(v[0].first - i) + abs(v[0].second - j);
      true_flag = true;
      REP(k,N){
        h_ = max(h - abs(v[k].first - i) - abs(v[k].second - j), (ll)0);
        if(h_ != v[k].third){
          true_flag = false;
          break;
        }
      }
      if(true_flag)break;
    }
    if(true_flag) break;
  }

  cout << i << " " << j  << " " << h << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}

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


	public void exec() throws Exception{
		final int a1 = sc.nextInt();
		final int a2 = sc.nextInt();
		final int a3 = sc.nextInt();
		if(a1+a2+a3>=22) {
			out.println("bust");
		}else {
			out.println("win");
		}
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

ll GCD(ll a, ll b) {
	return (b > 0) ? GCD(b, a % b) : a;
}

ll LCM(ll a, ll b) {
	return a / GCD(a, b) * b;
}

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll gcd = a[0];
	for (int i = 0; i < n - 1; i++) {
		gcd = GCD(gcd, a[i + 1]);
	}
	cout << gcd << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<26;i++){
        sum=0;
        for(int j=0;j<s.size();j++){
            if(s[j]!=char(i+'a')){
                sum++;
            }
        }
        if(sum==s.size()){
            cout<<char(i+'a')<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
}

Measured memory_bytes: 512