akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;
  FOR(i, b*10, b*10+10)if(i*8/100==a){
    cout << i << endl;
    return 0;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3576
// arock - 2019-03-09

#include <iostream>
#include <vector>

using i64 = long long;

int main() {
    i64 A, B;
    std::cin >> A >> B;

    std::vector<i64> As = {A - 1, 1, A, 0};
    std::vector<i64> Bs = {B, 1, B + 1, 0};

    i64 L = A == 0? 0 : As[(A - 1) % 4];
    i64 R = Bs[B % 4];

    std::cout << (L ^ R) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  ll N , Y; cin >> N >> Y;

  rep(i,N+1)rep(j,N+1){
    if((i+j) > N) break;
    ll k = N-i-j;

    if((i*10000 + j*5000 + k*1000)==Y){
      cout << i << " " << j << " " << k << endl;
      return 0;
    }
  }

  cout << "-1 -1 -1" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<sstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
#define make_pair mkp;

const int maxn=2e2+10;
int dp[maxn][maxn];
//dfs回溯
int res;
int h,w;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
char grid[maxn][maxn];
// void dfs(int i,int j,int num){
// 	cout<<i<<" "<<j<<" "<<grid[i][j]<<" "<<res<<" "<<num<<endl;
// 	if(num>=res)return;
// 	if(i==h&&j==w){
// 		res=min(res,num);
// 		return;
// 	}
// 	for(int k=0;k<4;k++){
// 		int x=i+dx[k];
// 		int y=j+dy[k];
// 		if(x>=1&&x<=h&&y>=1&&y<=w&&vis[x][y]==0){
// 			if(grid[x][y]=='.'){
// 				vis[x][y]=1;
// 				dfs(x,y,num);
// 				vis[x][y]=0;
// 			}else{
// 				vis[x][y]=1;
// 				dfs(x,y,num+1);
// 				vis[x][y]=0;
// 			}
// 		}
// 	}
// }


// int main(){
	
// 	cin>>h>>w;
// 	for(int i=1;i<=h;i++){
// 		for(int j=1;j<=w;j++){
// 			cin>>grid[i][j];
// 		}
// 	}
// 	res=1e9;
// 	memset(vis,0,sizeof(vis));
// 	//int num;
// 	vis[1][1]=1;
// 	if(grid[1][1]=='#'){
// 		grid[1][1]='.';
// 		dfs(1,1,1);
// 	}else{
// 		dfs(1,1,0);
// 	}
	
// 	cout<<res<<endl;
// 	return 0;
// }
//dfs搜索超时，看来只能dp了


//dp就是求解最小的连续#个数就是我们需要的最终答案了。。。
int main(){
//只能往下面或者往右走
//注意反转的是一个矩形内部的所有元素，而不是一个一个反转之类的。。。
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>grid[i][j];
		}
	}
	memset(dp,0x3f,sizeof(dp));
	dp[1][1]=(grid[1][1]=='#');
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(i>1){
				dp[i][j]=min(dp[i][j],dp[i-1][j]+(grid[i][j]=='#'&&grid[i-1][j]=='.'));
			}
			if(j>1){
				dp[i][j]=min(dp[i][j],dp[i][j-1]+(grid[i][j]=='#'&&grid[i][j-1]=='.'));//只有出现两个字符不一样才需要反转，并且反转字符相反，所以一定要两者字符同时都不一样才进行加一操作，否则不进行加一操作，等到时间允许的情况才进行加一操作。。。
			}
		}
	}
	cout<<dp[h][w]<<endl;

	return 0;
}



Measured memory_bytes: 384
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s, t;
    cin >> s >> t;

    t.erase(t.end()-1);

    if(t == s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int a[5], b[5], i;
	for (i = 1; i <= 3; i++) {
		scanf("%d %d", a+i, b+i);
	}

	int x = a[1] - b[1];
	int y = a[2] - b[2];
	int z = a[3] - b[3];
	if (x < 0)x *= -1;
	if (y < 0)y *= -1;
	if (z < 0)z *= -1;

	if ((x + y + z) == 3)printf("YES");
	else if ((x + y + z) == 5)printf("YES");
	else printf("NO");

	return 0;
}

Measured memory_bytes: 128
import numpy as np

N = int(input())

T, A = map(int, input().split())

H = list(map(int, input().split()))
H = np.array(H)

H = T - H * 0.006
ans = np.abs(A - H)
ans = np.where(ans == ans.min())[0][0] + 1

print(ans)

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

using namespace std;

const int N = 305;

int n, a[N];
bool vis[N][N][N];
long double f[N][N][N];

long double call (int one, int two, int thr) {
  if (one + two + thr == 0) return 0;
  if (vis[one][two][thr]) return f[one][two][thr];
  vis[one][two][thr] = 1, f[one][two][thr] = n;
  long double w = 0, x = 0, y = 0, z = 0;
  if (one) f[one][two][thr] += one * call(one - 1, two, thr);
  if (two) f[one][two][thr] += two * call(one + 1, two - 1, thr);
  if (thr) f[one][two][thr] += thr * call(one, two + 1, thr - 1);
  f[one][two][thr] /= (one + two + thr);
  return f[one][two][thr];
}

int main() {
  cin >> n;
  int one = 0, two = 0, thr = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] == 1) ++one;
    if (a[i] == 2) ++two;
    if (a[i] == 3) ++thr;
  }
  printf("%0.16f\n", (double) call(one, two, thr));
  return 0;
}



Measured memory_bytes: 463232
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] g = new int[n][2];
        Set<Pair> b = new HashSet<>();
        for (int i = 0; i < n; i++) {
            g[i][0] = sc.nextInt();
            g[i][1] = sc.nextInt();
            b.add(new Pair(g[i][0], g[i][1]));
        }
        Arrays.sort(g, (x, y) -> x[1] - y[1]);
        Arrays.sort(g, (x, y) -> x[0] - y[0]);
        Set<Pair> checked = new HashSet<>();
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i == j) continue;
                int p = g[i][0] - g[j][0];
                int q = g[i][1] - g[j][1];
                Pair a = new Pair(p, q);
                if(checked.contains(a)){
                    continue;
                }
                checked.add(a);
                int t = 0;
                for (int k = 0; k < n; k++) {
                    int tx = g[k][0] + p;
                    int ty = g[k][1] + q;
                    Pair c = new Pair(tx, ty);
                    if(b.contains(c)) t++;
                }
                if(max < t) max = t;
            }
        }
        System.out.println(n-max);
        sc.close();

    }

}

class Pair{
    int x;
    int y;

    Pair(int x, int y){
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair) obj;
        if(p.x == this.x && p.y == this.y) return true;
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 31;
        hash += x * 17;
        hash += y * 19;
        return hash;
    }
}


Measured memory_bytes: 28884
#include <algorithm> //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main()
{
  ll D, G;

  cin >> D >> G;
  vector<ll> p(D + 1, 0), c(D + 1, 0);

  G /= 100;
  for (int i = 0; i < D; i++)
  {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }

  ll base = 0;
  ll count_tmp = 0;
  ll count = 0x7FFFFFFFFFFFFFFF;
  for (int i = 0; i < 1 << D; i++)
  {
    base = 0;
    count_tmp = 0;

    for (int j = 0; j < D; j++)
    {
      base += !!(i & (1 << j)) * (p[j] * (j + 1) + c[j]);
      count_tmp += !!(i & (1 << j)) * p[j];
    }

    // for (int j = 0; j < D; j++)
    //   cerr << !!(i & (1 << j));
    // cerr << ":" << base << ":" << count_tmp;

    if (base < G)
    {
      for (int j = D - 1; j >= 0; j--)
      {
        if (i & (1 << j))
          continue;
        if (base + (p[j] - 1) * (j + 1) <= G)
        {
          base += (p[j] - 1) * (j + 1);
          count_tmp += p[j] - 1;
        }
        else
        {
          count_tmp += (G - base) / (j + 1);
          base += (G - base) / (j + 1) * (j + 1);
          if ((G - base) % (j + 1))
          {
            count_tmp++;
            base += j + 1;
          }
          break;
        }
      }
    }

    if (count_tmp < count && base >= G)
      count = count_tmp;

    // cerr << ":" << count << ":" << count_tmp << endl;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int W[100];

int main()
{
	int N, S1 = 0, S2 = 0, ans = 1000000;

	cin >> N;
	rep(i, N) {
		cin >> W[i];
		S2 += W[i];
	}

	rep(i, N - 1) {
		S1 += W[i];
		S2 -= W[i];
		ans = min(ans, abs(S1 - S2));

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        long n = sc.nextLong();
        long x = sc.nextLong();
        int m = sc.nextInt();

        long res = 0;

//        Comb comb = new Comb(n*2, m);

        Set<Long> set = new HashSet<>();
        long[] arr = new long[m*10];

        int left = 0;
        int right = 0;
        for (int i=0; i<m*10; i++) {
            if (set.add(x)) {
                arr[i] = x;
                x *= x;
                x %= m;
            } else {
                int idx = 0;
                for (int j=0; j<arr.length; j++) {
//                    System.out.println(x);
                    if (arr[j] == x) {
                        idx = j;
                        break;
                    }
                }
                left = idx;
                right = i - 1;
                break;
            }
        }

//        System.out.println(left);
//        System.out.println(right);

        long bef = 0;
        long circle = 0;
        long after = 0;

        for (int i=0; i<left; i++) {
            bef += arr[i];
//            bef %= m;
        }

        for (int i=left; i<=right; i++) {
            circle += arr[i];
//            circle %= m;
        }

        n -= left;
        long cnt = n / (right-left+1);
        n %= (right-left+1);

        for (int i=left; i<left+n; i++) {
            after += arr[i];
//            after %= m;
        }

//        System.out.println(bef);
//        System.out.println(circle);
//        System.out.println(after);

        System.out.println((bef+circle*cnt+after));



//        System.out.println(620*620%m);

//        System.out.println(res);

    }

    public class Comb {
        int n;   //　要素数
        int MOD = (int)1e9+7;
        long[] facts;

        public Comb(int n, int MOD){
            this.n = n;
            this.MOD = MOD;
            facts = new long[n+1];
            facts[0] = 1;
            for (int i=1; i<n+1; i++){
                facts[i] = facts[i-1] * i % MOD;
            }
        }

        // O(log(MOD))
        public long modpow(long a, long b){
            if (b==0) return 1;
            else if (b==1) return a;
            long x = modpow(a, b/2);
            return b%2 == 0 ? x * x % MOD : x * (x*a%MOD) % MOD;
        }

        // 逆元。x^(-1)≡x^(p-2) (MOD p) xとpは互いに素。
        public long inv(long n){
            return modpow(n, MOD-2);
        }

        public long nCk1(int n, int k){
            return n < k ? 0: facts[n] * (inv(facts[n-k]) * inv(facts[k]) % MOD) % MOD;
        }

        // O(k)
        public long nCk2(int n, int k) {
            long ret = 1;
            for (int i=0; i<k; i++) {
                ret = ret * (n - i) % MOD * inv(k - i);
                ret %= MOD;
            }
            return ret % MOD;
        }

    }


}



Measured memory_bytes: 48148
import collections
n = int(int(input())/2)
a = list(map(int,input().split()))
o = []
e = []
for i in range(n):
  o.append(a[i*2])
  e.append(a[i*2+1])
o_c = collections.Counter(o)
e_c = collections.Counter(e)
o_most = o_c.most_common()[0][0]
o_num = o_c.most_common()[0][1]
e_most = e_c.most_common()[0][0]
e_num = e_c.most_common()[0][1]
ans = 0
if(o_most == e_most and o_num + e_num == n*2):
  ans = n
elif(o_most != e_most and o_num == n and e_num == n):
  ans = 0
else:
  if(o_most == e_most):
    if(len(o_c.most_common()) == 1):
      e_num = e_c.most_common()[1][1]
    elif(len(e_c.most_common()) == 1):
      o_num = o_c.most_common()[1][1]
    else:
      e_t = e_c.most_common()[1][1]
      o_t = o_c.most_common()[1][1]
      if(o_num - o_t <= e_num - e_t):
        o_num = o_t
      else:
        e_num = e_t
  ans = n*2 - o_num - e_num
print(ans)

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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
#define N 2000093
long long k;
int T,f[N],g[N],u,v,st[N],t,n,a[N],h[N],tt,hh[N];
int main()
{
	n=read(); cin >> k;
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<=n;++i) {
		if(!h[a[i]])h[a[i]]=i;
	}
	for(int i=n;i;--i){
		if(!g[a[i]])f[i]=h[a[i]]; else f[i]=g[a[i]];
		g[a[i]]=i;
	}
	
	T=1,u=1;
	while(1){
		if(f[u]<=u)++T;
		u=f[u]+1;
		if(u==n+1)break;
	}
	
	k=k%T;
	if(!k)return 0;
	
	u=1;
	while(1){
		if(k==1)break;
		if(f[u]<=u)--k;
		u=f[u]%n+1;
	}
	while(u<=n){
		if(f[u]>u)u=f[u]; else printf("%d ",a[u]);
		++u;
	}
}

Measured memory_bytes: 15872
#include<stdio.h>
int main()
{
    int i,n;
    int temp;
    scanf("%d",&n);
    int max=0,min=1005;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&temp);
        if(temp<min)
            min=temp;
        if(temp>max)
            max=temp;
    }
    printf("%d",max-min);
    return 0;
}


Measured memory_bytes: 128
from collections import defaultdict, Counter
n, m = map(int, input().split())

city_to_pref, city_to_birth, pref_to_birth_list = {}, {}, defaultdict(list)
pref_counter = Counter()
city_id = {}
for i in range(m):
    pref, birth = map(int, input().split())
    city_to_pref[i] = pref
    city_to_birth[i] = birth
    pref_to_birth_list[pref].append(birth)


def get_city_index(i, pref):
    birth = city_to_birth[i]
    return pref_birth_to_id[pref][birth]


def give_id(i):
    p = city_to_pref[i]
    x = get_city_index(i, p) + 1
    return '{:0=6}{:0=6}'.format(p, x)


pref_birth_to_id = defaultdict(lambda : defaultdict(int))
for pref, births in pref_to_birth_list.items():
    for i, birth in enumerate(sorted(births)):
        pref_birth_to_id[pref][birth] = i

for i in range(m):
    print(give_id(i))

Measured memory_bytes: 80376
n,k = map(int,input().split())
lst = list(map(int,input().split()))

ans = 0
m = min(n,k)
for a in range(m+1):
    for b in range(m+1-a):
        jewel = lst[:a] + lst[n-b:]
        jewel.sort()
        for c in range(k+1-a-b):
            ans = max(ans, sum(jewel[c:]))
        
print(ans)

Measured memory_bytes: 3060
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int p[30], ans;

inline void sw(int a, int b) {
	swap(p[a - 1], p[b - 1]);
}

void r1() {
	sw(1, 24);
	sw(4, 27);
	sw(7, 30);
	sw(10, 21);
	sw(16, 18);
}

void r2() {
	sw(7, 22);
	sw(8, 23);
	sw(9, 24);
	sw(18, 13);
	sw(10, 12);
}

void r3() {
	sw(3, 22);
	sw(6, 25);
	sw(9, 28);
	sw(12, 19);
	sw(13, 15);
}

void r4() {
	sw(1, 28);
	sw(2, 29);
	sw(3, 30);
	sw(15, 16);
	sw(19, 21);
}

void dfs(int d) {
	int cnt = 0;
	for (int i = 0; i < 9; ++i)
		if (p[0] != p[i])
			cnt++;
	for (int i = 0; i < 4; ++i)
		for (int j = 0; j < 3; ++j)
			if (p[9 + i * 3] != p[9 + i * 3 + j])
				cnt++;
	for (int i = 0; i < 9; ++i)
		if (p[21] != p[21 + i])
			cnt++;

	if (cnt == 0) {
		ans = min(ans, d);
		return;
	}

	if (d == 8)
		return;

	r1();
	dfs(d + 1);
	r1();

	r2();
	dfs(d + 1);
	r2();

	r3();
	dfs(d + 1);
	r3();

	r4();
	dfs(d + 1);
	r4();
}

int main() {
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < 30; ++i)
			cin >> p[i];
		ans = 9;
		dfs(0);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3124
N = int(input())
A = list(map(int, input().split()))

INPUT_L = [0] + A[:]
B = [0] * (N+1)

# 決まるものを入れてしまう
for i in range(N//2+1, N+1):
    B[i] = INPUT_L[i]
    
for i in reversed(range(1, N//2+1)):
    #print('__', i)
    #print(B[i::i])
    sum_b = sum(B[i::i])
    if sum_b % 2 == INPUT_L[i]:
        continue
    else:
        B[i] = 1
    
ans_sum = sum(B)

if ans_sum % 2 != INPUT_L[1]:
    print(-1)
else:
    #print(B)
    ans_list = []
    for i, b in reversed(list(enumerate(B))):
        if b != 0:
            ans_list.append(str(i))

    print(ans_sum)
    print(' '.join(ans_list))





Measured memory_bytes: 84072
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1000000000000000000;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,q;
vi l,r,a;

void f(int& x){
	x=lower_bound(a.begin(),a.end(),x)-a.begin();
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	l=r=vi(n);
	a=vi(n+1);
	for(int i=0;i<n;i++){
		cin>>r[i]>>l[i];
		l[i]=min(l[i],r[i]);
	}
	for(int i=0;i<=n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	vvi g(n+2),G(n+2);
	vi b(n+2,1),c(n+2,-1),d(n+2);
	priority_queue<P> pq;
	int res=0;
	b[n]=-n;c[0]=0;
	for(int i=0;i<n;i++){
		f(l[i]);f(r[i]);
		int L=l[i],R=r[i];
		g[R].push_back(L);
		if(R<=n){
			b[n]++;
			if(R) b[R-1]--;
		}
		c[R]++;
	}
	for(int i=n;i>=0;i--){
		if(i<n) b[i]+=b[i+1];
		for(auto j:g[i+1]) pq.push({-j,i+1});
		while(pq.size()&&b[i]<0){
			P p=pq.top();
			pq.pop();
			int L=-p.first,R=p.second;
			if(i<L) G[L].push_back(R);
			else{
				b[i]++;
				if(L) b[L-1]--;
				c[L]++;c[R]--;
				res++;
			}
		}
		if(b[i]<0) res=inf;
	}
	while(pq.size()){
		P p=pq.top();
		pq.pop();
		int L=-p.first,R=p.second;
		G[L].push_back(R);
	}
	d[0]=res;
	for(int i=0;i<=n;i++){
		if(i) c[i]+=c[i-1];
		for(auto j:G[i]) pq.push({j,-i});
		while(pq.size()&&c[i]<1){
			P p=pq.top();
			pq.pop();
			int L=-p.second,R=p.first;
			if(i<=R){
				c[i]++;c[R]--;
				res++;
			}
		}
		if(c[i]<1) res=inf;
		d[i+1]=res;
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int x,y;
		cin>>x>>y;
		f(x);f(y);
		int t=min(d[x],d[y]+1);
		cout<<(t<inf?n-t+1:-1)<<endl;
	}
}

Measured memory_bytes: 14964
n,m=map(int,input().split())
s1=[]
sn=[]
ans='IMPOSSIBLE'
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    s1.append(b)
  elif b==n:
    sn.append(a)
s=sorted(s1+sn)
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    ans='POSSIBLE'
    break
print(ans)

Measured memory_bytes: 14968
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main()
{
	string s;
	int a = 2000001, z = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			a = min(a, i);
		}
		else if (s[i] == 'Z') {
			z = max(z, i);
		}
	}
	cout << z - a + 1 << endl;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
#define N 10000

struct node{
  int key;
  struct node *p,*l,*r;
};
typedef struct node *Node;
Node root;
void insert(int);
void printa(Node);
void printb(Node);
int main()
{
  int m,i,p;
  char ip[10];

  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",ip);
    if(ip[0] == 'i'){
      scanf("%d",&p);
      insert(p);
    }
    else {
      printa(root);
      printf("\n");
      printb(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int p)
{
  Node x,y,z;
  y = NIL;
  x = root;
  z = malloc(sizeof(struct node));
  z->key = p;
  z->l = NIL;
  z->r = NIL;

  while (x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }
    else x = x->r;
  }
  z->p = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->l = z;
  }
  else y->r = z;
}



void printb(Node j)
{
  if(j == NIL){
    return;
  }
  printf(" %d",j->key);
  printb(j->l);
  printb(j->r);
}

void printa(Node k)
{
  if(k == NIL){
    return;
  }
  printa(k->l);
  printf(" %d",k->key);
  printa(k->r);
}

Measured memory_bytes: 24040
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;

int main(){
	string s;
	int b,c,d;
	stack<int> a;
	
	while(cin>>s){
		
		if(s=="+"){
			c=a.top();
			a.pop();
			d=a.top();
			a.pop();
			a.push(c+d);
		}else if(s=="-"){
			c=a.top();
			a.pop();
			d=a.top();
			a.pop();
			a.push(d-c);
		}else if(s=="*"){
			c=a.top();
			a.pop();
			d=a.top();
			a.pop();
			a.push(c*d);
		}else{
		
		b=stoi(s);
		
		a.push(b);
		
		}
		
	}
	
	cout<<a.top()<<endl;
	
	return 0;
}

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

unsigned int table[2048 * 2048];

void sort(unsigned int* array, int size) {
	unsigned int* tmp;
	int i, j;

	if(size > 1) {
		sort(array, size / 2);
		sort(array + size / 2, size - size / 2);
	}

	tmp = malloc(sizeof(unsigned int) * size);
	for(i = 0, j = 0; i < size / 2 && j < size - size / 2;) {
		if(array[i] > array[size / 2 + j]) {
			tmp[i + j] = array[i];
			i++;
		}

		else {
			tmp[i + j] = array[size / 2 + j];
			j++;
		}
	}

	for(; i < size / 2; i++)
		tmp[i + j] = array[i];
	for(; j < size - size / 2; j++)
		tmp[i + j] = array[size / 2 + j];

	memcpy(array, tmp, sizeof(unsigned int) * size);
	free(tmp);
}

int main(void) {
	int N, M;
	int h[2048], w[2048];
	int count;
	int ans;

	int i, j;

	while(1) {
		ans = 0;
		scanf("%d %d", &N, &M);
		if(N == 0 && M == 0)
			break;
		for(i = 0; i < N; i++)
			scanf("%d", &h[i]);
		for(i = 0; i < M; i++)
			scanf("%d", &w[i]);

		for(i = 0; i < N - 1; i++)
			h[i + 1] += h[i];
		for(j = 0; j < M - 1; j++)
			w[j + 1] += w[j];

		h[N] = w[M] = 0;
		for(i = 0; i < N + 1; i++) {
			for(j = 0; j < M + 1; j++) {
				table[i * (M + 1) + j] = h[i] + w[j];
			}
		}
		sort(table, (N + 1) * (M + 1));

		for(i = 0, count = 0; i < (N + 1) * (M + 1); i++) {
			if(table[i] == table[i + 1])
				count++;
			else {
				ans += count * (count + 1) / 2;
				count = 0;
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

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

int main() {
    using namespace std;
    unsigned long Q, H, S, D;
    cin >> Q >> H >> S >> D;
    H = min(H, Q * 2);
    S = min(S, H * 2);
    D = min(D, S * 2);
    unsigned long N;
    cin >> N;
    cout << (N / 2 * D) + (N & 1) * S << endl;
    return 0;
}

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

public static class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var stones = Console.ReadLine();
        var wCount = stones.Count(c => c == 'W');
        var count = stones.Take(N - wCount).Count(c => c == 'W');
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 28972
import collections

n = int(input())
blue = [input() for _ in range(n)]
m = int(input())
red = [input() for _ in range(m)]

blue_cnter = collections.Counter(blue)
red_cnter = collections.Counter(red)

maxget = 0
for key, count in blue_cnter.items():
    # 青のkey基準で考える
    bluecount = count
    redcount = red_cnter.get(key, 0)
    maxget = max(maxget, bluecount-redcount)
print(maxget)


Measured memory_bytes: 3316
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/09/20 20:59:36
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s; cin>>s;
  struct F {
    bool f;
    int c;
  };
  vector<F> fs;
  char p;
  int cnt = 0;
  for (auto c:s) {
    if (c==p) {
      cnt++;
    } else {
      fs.push_back({p=='R', cnt});
      cnt=1;
    }
    p=c;
  }
  fs.erase(fs.begin());
  fs.push_back({p=='F', cnt});
  for (int i = 0; i < fs.size(); i += 2) {
    for (int j = 0; j < fs[i].c-1; j++)
      cout << 0 << " ";
    cout << (fs[i].c+1)/2+fs[i+1].c/2 << " " << fs[i].c/2+(fs[i+1].c+1)/2 << " ";
    for (int j = 0; j < fs[i+1].c-1; j++)
      cout << 0 << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1480
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P= pair<int,int>;
string alpha="abcdefghijklmnopqrstuvwxyz";
int main() {
    ll N,T;
    cin>>N;
    T=N;
    ll count=0;
    vector<long long> digits;
    string s;
    while(T>0)
    {
        T--;
        s+=T%26+'a';
      	T=T/26;
    }
    //string name="";
    reverse(s.begin(),s.end());
    //reverse(digits.begin(),digits.end());
    //cout<<alpha[10]<<endl;
    cout<<s<<endl;
    //for(int i=0;i<5;i++)//
    //{
      //cout<<n_digits[i]-1;
      //cout<<alpha[digits[i]-1];
    //}
    //for(int i=5;i<10;i++)//
    //{
      //cout<<n_digits[i]-1;
      //cout<<alpha[digits[i]-1];
   // }
    //cout<<name<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <cctype>
using namespace std;

	// int islower(char ch);
	// int isupper(char ch);
	// int tolower(char ch);
	// int toupper(char ch):

int main(){

	int i = 0;
	string str;
	getline(cin, str);

	char c;
	while(str[i]){
		c = str[i];
		if(islower(c)){
			cout << (char)toupper(c);
		}else if(isupper(c)){
			cout << (char)tolower(c);
		}else{
			cout <<c;
		}
		i++;
	}

	cout << endl;


return 0;
}

Measured memory_bytes: 1176
// atcoder/abc091/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

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

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    cout << (c <= (a + b) ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc160/tasks/abc160_d

use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! {
        n: usize,
        x: usize, y: usize,
    }
    let mut vec = vec![0; n];

    for i in 1..=n - 1 {
        for j in i + 1..=n {
            vec[dist(i, j, x, y)] += 1;
        }
    }
    for k in 1..=n - 1 {
        println!("{}", vec[k]);
    }
}

fn dist(i: usize, j: usize, x: usize, y: usize) -> usize {
    (j - i).min(abs_diff(x, i) + 1 + abs_diff(y, j))
}

fn abs_diff(a: usize, b: usize) -> usize {
    if a > b {
        a - b
    } else {
        b - a
    }
}


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

int main() {
  //input
  int N, H;
  cin >> N >> H;

  vector<int> A(N);
  vector<int> B(N);
  
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
    cin >> B.at(i);
  }
  
    sort(A.begin(), A.end()); // {1, 2, 2, 5}
    sort(B.begin(), B.end()); // {1, 2, 2, 5}

  //count
  int count = 0;

  //Attack B
    for (int i = 0; i < N; i++) {
      if(B.at(N-1-i) >= A.at(N-1)){
        H -= B.at(N-1-i);
        count++;
      }
      
      if (H <= 0){
        break;
      }
    }
  
  //Attack A
    while (H > 0){
      H -= A.at(N-1);
      count++;
    }
  
  cout << count << endl;
  
}


Measured memory_bytes: 4036
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long

#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))

#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000
#define MX2     1000000
#define Inf     1000000000000000
#define mod		1000000007
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    opt;
    
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    
    lli N,i;
    cin>>N;
    
    map<lli,lli>M;
    lli L_14=-1,L_24=-1;
    lli L_12=-1,L_22=-1;
    set<lli>s;
    
    rep(i,0,N)
    {
        lli x;
        cin>>x;
        
        M[x]++;
        
        if(M[x]>=4)
        {
            L_14=max(L_14,x);
        }
        
        if(M[x]>=2)
        {
            s.insert(-x);
        }
    }
    
    lli x=0;
    
    if(L_14!=-1)
    {
        x=max(x,L_14*L_14);
    }
    
    lli Sum=1;
    if(s.sz()>=2)
    {
        lli cnt=2;
        while(cnt--)
        {
            Sum=Sum*(*s.begin());
            s.erase(s.begin());
        }
        
        x=max(x,Sum);
    }
    
    
    cout<<x;
    
    




 return 0;
}


Measured memory_bytes: 6528
def furui(a,b):
    l=max(a,b)
    s=min(a,b)
    if l%s==0:
        return s
    else:
        return furui(s,l-s*(l//s))

n=int(input())
a=[int(x) for x in input().split()]
ans=a[0]
for i in range(1,n):
    ans=furui(ans,a[i])
print(ans)

Measured memory_bytes: 14252
#include<stdio.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];

int head=0, tail=0, n;

void enqueue(P);

P dequeue (void);



int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }


  while(n!=c){    
    u = dequeue();
    if(u.t <= 0) continue; 
    if(u.t - q > 0) {
      u.t -= q;
      elaps+=q;
      enqueue(u);
    }
    
    else{
      elaps += u.t;
      u.t -= q;
      printf("%s %d\n",u.name,elaps);
      c++;
    }
  }
  
  
  return 0;
}

void enqueue(P x){
  //isFull
  /*if(head == (tail+1)%n) {
    printf("error\n");
  }
  */
  Q[tail] = x;
  if(tail+1 == n) tail = 0;
  else tail++;
}


P dequeue(){
  P x;
  //isEmpty
  /*if(head == tail) {
     printf("error\n");
      }
  */
  x = Q[head];
  if(head + 1 == n) head = 0;
  else head++;
  return x;
}



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

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        String[] S = new String[100];
        // ["", "","" ,"" ,"", ... ]
        // [0, 0, 0, 0, 0, ... ]
        // "" - String, '' - Char

        int[] iVal = new int[5]; // [0, 0, 0, 0, 0]
        // iVal = [0,1,2,3,4]

        // iVal = [3, 5, 7, 9, 11]

        for(int i = 0; i < 5; i+=1) {

            iVal[i] = in.nextInt();
            if(iVal[i]==0)
            {
                System.out.println(i+1);
            }


        }

        }









    }





Measured memory_bytes: 35644
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.0001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int to_sec(string s) {
	return stoi(s.substr(0, 2)) * 3600 + stoi(s.substr(3, 2)) * 60;
}
string to_smh(int time) {
	string smh = "";
	if(time/3600<10) smh += "0"+to_string(time / 3600) + ":";
	else smh += to_string(time / 3600) + ":";
	time %= 3600;
	if (time / 60 < 10) smh += "0" + to_string(time / 60) + ":";
	else smh += to_string(time / 60) + ":";
	time %= 60;
	if (time < 10) smh += "0" + to_string(time);
	else smh += to_string(time);
	return smh;
}
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	ll n, c1 = 0, c2 = 0;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int sum;
	sum = a[0];
	if (sum < 1) {
		c1 += 1 - sum;
		sum = 1;
	}
	for (int i = 1; i < n; i++) {
		sum += a[i];
		if (i % 2 == 0) {
			if (sum < 1) {
				c1 += 1 - sum;
				sum = 1;
			}
		}
		else {
			if (sum > -1) {
				c1 += sum + 1;
				sum = -1;
			}
		}
	}
	sum = a[0];
	if (sum > -1) {
		c2 += sum + 1;
		sum = -1;
	}
	for (int i = 1; i < n; i++) {
		sum += a[i];
		if (i % 2 == 0) {
			if (sum > -1) {
				c2 += sum + 1;
				sum = -1;
			}
		}
		else {
			if (sum < 1) {
				c2 += 1 - sum;
				sum = 1;
			}
		}
	}
	cout << min(c1, c2) << endl;
	return 0;
}


Measured memory_bytes: 1024
N,S=map(int,input().split())
*a,=map(int,input().split())
mod=998244353

dp=[[0]*(S+1) for _ in range(N+1)]
dp[0][0]=1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j]=2*dp[i][j]

        if j>=a[i]:
            dp[i+1][j]+=dp[i][j-a[i]]
        
        dp[i+1][j]%=mod

print(dp[N][S])

Measured memory_bytes: 135172
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  bool f=1;
  rep(i,n-1) {
    if(a[i]>=a[i+1]) f=0;
  }
  if(f) {
    pr(1);
    return;
  }
  ll l=1,r=MAX;
  while(l+1<r) {
    ll m=(l+r)/2;
    map<ll,ll> ma;
    REP(i,1,n) {
      if(a[i-1]<a[i]) continue;
      else {
        ll x=a[i];
        while(ma[x]+1>=m&&x) x--;
        if(!x) goto end;
        ma[x]++;
        iter(ma) it=ma.end();
        it--;
        while(it->F!=x) {
          ma.erase(it);
          it--;
        }
      }
    }
    r=m;
    continue;
  end:;
    l=m;
  }
  pr(r);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int num, i;
    long long int max=-1000000, min=1000000, fig[10000], sum=0;
    scanf("%d", &num);
    for(i=0; i<num; i++){
        scanf("%lld", &fig[i]); 
    }
    for(i=0; i<num; i++){
        sum += fig[i];
        if(fig[i]>max)
            max = fig[i];
        if(fig[i]<min)
            min = fig[i];
    }
    printf("%lld %lld %lld\n", min, max, sum);
    return 0; 
}

Measured memory_bytes: 1852
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <climits>


using namespace std;


class Node {
    public:
        int location;
        int p, l, r;
        Node() {}
};


class Point {
    public:
        int id, x, y;

        Point() {}
        Point(int id, int x, int y): id(id), x(x), y(y) {}

        bool operator <(const Point &p) const {
            return id < p.id;
        }

        void print() {
            printf("%d\n", id);
        }
};


static const int MAX = 1000000;
static const int NIL = -1;


int N;
Point P[MAX];
Node T[MAX];
int np = 0;


bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }


int makeKDTree(int l, int r, int d)
{
    if (!(l < r))
        return NIL;

    int mid = (l + r) / 2;
    int t = np++;

    if (d % 2 == 0) {
        sort(P + l, P + r, lessX);
    } else {
        sort(P + l, P + r, lessY);
    }

    T[t].location = mid;
    T[t].l = makeKDTree(l, mid, d + 1);
    T[t].r = makeKDTree(mid + 1, r, d + 1);

    return t;
}


void find(int v, int sx, int tx, int sy, int ty, int d, vector<Point> &ans)
{
    Point p = P[T[v].location];
    int x = P[T[v].location].x;
    int y = P[T[v].location].y;

    if (sx <= p.x && p.x <= tx && sy <= p.y && p.y <= ty)
        ans.push_back(p);

    if (d % 2 == 0) {
        if (T[v].l != NIL && sx <= x)
            find(T[v].l, sx, tx, sy, ty, d + 1, ans);
        if (T[v].r != NIL && x <= tx)
            find(T[v].r, sx, tx, sy, ty, d + 1, ans);
    } else {
        if (T[v].l != NIL && sy <= y)
            find(T[v].l, sx, tx, sy, ty, d + 1, ans);
        if (T[v].r != NIL && y <= ty)
            find(T[v].r, sx, tx, sy, ty, d + 1, ans);
    }
}


int main()
{
    int n, x, y;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &x, &y);
        P[i] = Point(i, x, y);
        T[i].l = T[i].r = T[i].p = NIL;
    }

    int root = makeKDTree(0, n, 0);

    int q;
    int sx, sy, tx, ty;
    vector<Point> ans;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        ans.clear();
        find(root, sx, tx, sy, ty, 0, ans);
        sort(ans.begin(), ans.end());
        for (int j = 0; j < ans.size(); j++)
            ans[j].print();
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 16480
n,a=open(0)
n=int(n)
a=sorted(map(int,a.split()))
if a[0]==a[-1]:
  if n-1==a[0]or n//a[0]>=2:
    print('Yes')
  else:
    print('No')
elif a[-1]-1==a[0]:
  x=a.count(a[0])
  if x<a[-1]and(n-x)//(a[-1]-x)>=2:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 52772
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int, vector<int>> a;
    rep(i, n){ int tmp; cin >> tmp; a.push(tmp);}

    rep(i, m){
        int price = a.top();
        a.pop();


        price /= 2;
        a.push(price);
    }
    ll sum = 0;
    while(!a.empty()) {
        sum += a.top();
        a.pop();
    }
    cout << sum << endl;
}



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


int main() {
    int L, R, d;
    cin >> L >> R >> d;

    int sum = 0;
    for (int i = d; i <= 100; i += d) {
        if (i >= L && i <= R) sum++;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3644
def main(argv)
  n = gets.chomp.to_i
  (a, b) = gets.chomp.split(' ').map(&:to_i)
  p = gets.chomp.split(' ').map(&:to_i)

  counter = [0, 0, 0]
  n.times do |i|
    counter[0] += 1 if (p[i] <= a)
    counter[1] += 1 if ((a < p[i]) && (p[i] <= b))
    counter[2] += 1 if (b < p[i])
  end

  puts counter.min.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int main(void){
	ios::sync_with_stdio(false);
	int n, t;
	cin >> n >> t;
	int m = 0;
	int am = 0;
	int mi = 1000000000;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		mi = min(mi, a);
		if(a-mi > m){
			m = a-mi;
			am = 1;
		} else if(a-mi==m) am++;
	}
	cout << am << endl;
}

Measured memory_bytes: 3644
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Pair implements Comparable<Pair> {
    final int key;
    final int cnt;

    public Pair (int key, int cnt) {
        this.key = key;
        this.cnt = cnt;
    }

    @Override
    public int compareTo(Pair other) {
        return Integer.compare(this.cnt, other.cnt);
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];

        int sum = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        PriorityQueue<Pair> pq = new PriorityQueue<Pair>(N, new Comparator<Pair>() {
            public int compare(Pair a, Pair b) {
                return Integer.compare(a.cnt, b.cnt);
            }
        });

        int[] counter = new int[200001];;
        for (int i = 0; i < N; i++) {
            counter[A[i]]++;
        }

        for (int i = 0; i < 200001; i++) {
            if (counter[i] != 0) {
                pq.offer(new Pair(i, counter[i]));
            }
        }

        int cnt = 0;
        while (pq.size() > K) {
            Pair p = pq.poll();
            cnt += p.cnt;
        }
        System.out.println(cnt);
        return;
    }

}

Measured memory_bytes: 82968