akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int a,b,c; cin>>a>>b>>c;
    if(a+b==c||b+c==a||c+a==b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int N;
bool adj[201][201];
int depths[201];

int dfs_depth(int start) {
    for(int i = 1; i <= N; i++)
        depths[i] = 0;

    queue<int> Q;
    Q.push(start);
    depths[start] = 1;
    int max_depth = 0;
    while(!Q.empty()) {
        int x = Q.front();
        //cout << "queue element: " << x << "\n";
        max_depth = max(max_depth, depths[x]);
        Q.pop();
        for(int i = 1; i <= N; i++) {
            //cout << adj[x][i] << " " << depths[i] << "\n";
            if(adj[x][i] and depths[i] == 0) {
                depths[i] = depths[x] + 1;
                Q.push(i);
            }
        }
    }

    for(int i = 1; i <= N; i++) {
        for(int j = i + 1; j <= N; j++) {
            if(adj[i][j] and depths[i] == depths[j]) {
                return -1;
            }
        }
    }
    return max_depth;
}

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            char c;
            cin >> c;
            adj[i][j] = (c == '1');
        }
    }
    
    int ans = -1;
    for(int i = 1; i <= N; i++)
        ans = max(ans, dfs_depth(i));
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> vec(H+2,vector<char>(W+2));
  
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      vec.at(i).at(j)='#';
    }
  }

  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin >> vec.at(i).at(j);
    }
  }

  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout << vec.at(i).at(j);
    }
    cout << endl;
  }
      
      
                  

}

Measured memory_bytes: 256
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    s = input()
    if s[0] == "S":
        if s[1] == "U":
            print(7)
            return
        print(1)
        return
    elif s[0] == "F":
        print(2)
        return
    elif s[0] == "W":
        print(4)
        return
    elif s[0] == "M":
        print(6)
        return
    elif s[1] == "H":
        print(3)
        return
    print(5)
    
    
    
main()

Measured memory_bytes: 5844
#include <iostream>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main()
{
    int n,q,left,right,mid,key,counter = 0;
    cin >> n;
    int S[n];
    REP(i,n)cin >> S[i];    
    cin >> q;

    REP(i,q) {
        cin >> key;
        left = 0;
        right = n;
        while( left < right ) {
            mid = (left + right) / 2;
            if (S[mid] == key) {
                counter++;
                break;
            } else if (key < S[mid]) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 3424
#include <stdio.h>
int main()
{
    int h, n, i, err;
    scanf("%d %d", &h, &n);
    int a[n];
    if (h>=1 && h<=1000000000 && n>=1 && n<=100000)
    {
        for (i=0; i<n; i++)
        {
            scanf("%d", &a[i]);
        }
        for (i=0; i<n; i++)
        {
            if (a[i]<1 || a[i]>10000)
            {
                goto skip;
            }
        }
        for (i=0; i<n; i++)
        {
            h=h-a[i];
        }
        if (h<=0)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    else
    {
skip:
        printf("Error\n");
    }

    return 0;
}


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

int m,n; char s[509][509];
int main(){
	scanf("%d%d",&m,&n);
	int i,j;
	for (i=1; i<=m; i++) scanf("%s",s[i]+1);
	for (i=1; i<=m; i++){
		for (j=1; j<=n; j++)
			putchar(((i&1) || j==1 || s[i][j]=='#') && j<n?'#':'.');
		puts("");
	}
	puts("");
	for (i=1; i<=m; i++){
		for (j=1; j<=n; j++)
			putchar(((i&1^1) || j==n || s[i][j]=='#') && j>1?'#':'.');
		puts("");
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int x, a, b;
    cin >> x >> a >> b;
    int y = b - a;
    if(y <= 0) { printf("delicious\n"); }
    else if(y <= x) { printf("safe\n"); }
    else { printf("dangerous\n"); }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x;cin >> n >> m >> x;
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> c(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }
    int ans=inf;
    for(int i=0;i<(1<<n);i++){
        int res=0;
        vector<int> b(m);
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                res+=c[j];
                for(int k=0;k<m;k++){
                    b[k]+=a[j][k];
                }
            }
        }
        bool f=true;
        for(int j=0;j<m;j++){
            if(b[j]<x){
                f=false;
            }
        }
        if(f){
            chmin(ans,res);
        }
    }
    if(ans==inf){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 3660
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    string s = sread();
    long[2] cnt;
    foreach (c; s)
    {
        cnt[c / '1']++;
    }
    writeln(min(cnt[0], cnt[1]) * 2);
}


Measured memory_bytes: 508
a,b = gets.chomp.split.map(&:to_i)
require 'prime'
primes_a = Prime.prime_division(a)
primes_b = Prime.prime_division(b)

cnt = 0
primes_b = primes_b.map do |prime_b|
    prime_b[0]    
end
for prime_a in primes_a do
    if primes_b.include?(prime_a[0])
        cnt += 1
    end
end
p cnt+1

Measured memory_bytes: 2300
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define all(x) (x).begin(),(x).end()

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int MOD = 1e9+7;

int main()
{
	int r;
	cin >> r;
	cout << 3*r*r << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	ll n[3];
	rep(i, 3) cin >> n[i];
	ll k;
	cin >> k;
	ll c[3][1000];
	rep(i, 3) {
		rep(j, n[i]) cin >> c[i][j];
		sort(c[i], c[i] + n[i], greater<ll>());
	}

	priority_queue<ll> queue;
	int idx[] = {0, 0, 0};
	queue.push(c[0][0] + c[1][0] + c[2][0]);
	ll remain = k;
	vector<ll> ans;
	while(remain > 0) {
		if(queue.empty()) {
			rep(i, 3) if(idx[i] + 1 < n[i]) {
				rep(j, idx[(i + 1) % 3] + 1) rep(l, idx[(i + 2) % 3] + 1) {
					queue.push(c[i][idx[i] + 1] + c[(i + 1) % 3][j] + c[(i + 2) % 3][l]);
				}
				idx[i]++;
			}
		}
		else {
			ll sum_max = queue.top();
			queue.pop();
			bool queue_updated = false;
			rep(i, 3) if(idx[i] + 1 < n[i]) {
				ll sum_add =  c[i][idx[i] + 1] + c[(i + 1) % 3][0] + c[(i + 2) % 3][0];
				if (sum_add > sum_max) {
					rep(j, idx[(i + 1) % 3] + 1) rep(l, idx[(i + 2) % 3] + 1) {
						queue.push(c[i][idx[i] + 1] + c[(i + 1) % 3][j] + c[(i + 2) % 3][l]);
					}
					queue_updated = true;
					queue.push(sum_max);
					idx[i]++;
					break;
				}
			}
			if(!queue_updated) {
				ans.push_back(sum_max);
				remain--;
			}
		}
	}
	rep(i, k) cout << ans[i] << endl;
}


Measured memory_bytes: 640
n = int(input())
h = list(map(int, input().split()))

for i in range(n-1):
    if h[i] - h[i+1] < 0:
        h[i+1] -= 1
    if h[i] - h[i+1] > 0:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14396
const teststr = 
"""
6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6
"""

function lines()
  Channel{String}(32) do ch
    lines = true ? readlines() : split(teststr, "\n")
    for s in lines
      put!(ch, s)
    end
  end
end

function main()
  ch = lines()
  N, M = parse.(Int, split(take!(ch)))
  H = parse.(Int, split(take!(ch)))
  @assert length(H) == N
  goods = [true for n in 1:N]
  for m in 1:M
	a, b = parse.(Int, split(take!(ch)))
    if H[a] >= H[b]
      goods[b] = false
    end
    if H[a] <= H[b]
      goods[a] = false
    end
  end
  println(count(goods))
end

main()

Measured memory_bytes: 225824
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if(abs(c-a) <= d)
    cout << "Yes" << endl;
  else if(abs(b-a)<=d && abs(c-b)<=d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

using namespace std;

#define ll long long int

int main(){

    ll n,k;
    cin >> n >> k;

    vector<ll> a;
    ll a1,i;

    for(i=0;i<n;i++){
        cin >> a1;
        a.push_back(a1);
    }

    sort(a.begin(),a.end());

    ll sum = 0;

    for(i=0;i<n-k;i++){
        sum = sum + a[i];
    }

    cout << sum;
}


Measured memory_bytes: 2548
def solve() :
    n = int(input()) 
    a = list(map(int, input().split()))

    total = 1

    if 0 in a :
        print(0)
        return

    for i in a :
        total *= i

        if total > 10 ** 18 :
            print(-1)
            return

    print(total)

if __name__ == "__main__" :
    solve()

Measured memory_bytes: 84888
// C - Takahashi's Information
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	vvi C(3,vi(3)); rpz(i,3) rpz(j,3) cin>>C[i][j];
	vi A(3,INT_MAX), B(3,INT_MAX);
	A[0] = 0;
	rpz(j,3) B[j] = C[0][j] - A[0];
	rpz(i,3) A[i] = C[i][0] - B[0];
	string ans = "Yes";
	rpz(i,3) rpz(j,3) if(C[i][j] != A[i]+B[j]) ans = "No";
	cout<< ans <<endl;
}

Measured memory_bytes: 256
fac=[1]*505050
inv=[1]*505050
finv=[1]*505050
mod=1000000007
for i in range(2,500010):
  fac[i]=fac[i-1]*i%mod
  inv[i]=-inv[mod%i]*(mod//i)%mod
  finv[i]=finv[i-1]*inv[i]%mod

def C(n,r):
  if n<0 or r<0 or n<r: return 0
  return fac[n]*finv[n-r]%mod*finv[r]%mod

N,M=map(int,input().split())
ans=0
for i in range(N+1):
  ans+=C(N,i)*fac[M]%mod*finv[M-i]%mod*((fac[M-i]*finv[M-N]%mod)**2%mod)*(1 if i%2==0 else -1)%mod
  if ans<0: ans+=mod
  if ans>=mod: ans-=mod
print(ans)


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

int main()
{
  int n, d;
  cin >> n >> d;

  int count = 0;
  for (int i = 0; i < n; i++)
  {
    double x, y;
    cin >> x >> y;

    if (sqrt(pow(x, 2) + pow(y, 2)) <= d)
    {
      count++;
    }
  }
  cout << count << "\n";

  return 0;
}

Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = 3.14159265358979323846;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second




int main() {
	int a, b, n, s, t, time[1010] = {0};
	cin >> a >> b >> n;
	for (int i = a;i < b;i++)time[i]++;
	for (int i = 0;i < n;i++) {
		cin >> s >> t;
		for (int j = s;j < t;j++) {
			if (time[j]) {
				cout << 1 << endl;
				return 0;
			}
		}
	}
	cout << 0 << endl;
	return 0;
}



Measured memory_bytes: 3120
N = int(input())
L = list(map(int,input().split()))
L.sort()
a = 0
for i in range(0, N):
  for j in range(i + 1, N):
    for k in range(j + 1, N):
      if L[i] < L[j] and L[j] < L[k] and L[i] + L[j] > L[k]:
        a += 1
print(a)

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  LL n,t;
  cin >> n >> t;
  vector<LL> x(n);
  rep(i,n){
    cin >> x[i];
  }
  sort(all(x));
  LL ans=1;
  rep(i,n){
    LL idx = lower_bound(all(x),x[i]-t)-x.begin();
    ans=ans*(i-idx+1)%MOD;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3616
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 文字列の入力
        String origin = sc.next();
        String[] s = origin.split("");
        int ans = 0;
        for(int i = 0; i < s.length - 1; i++) {
          String target = s[i];
          child:for (int index = i + 1; index < s.length - 1; index++) {
            int length = index - i;
            if (length + index > s.length - 1) {
              break child;
            }
            if (target.equals(s[index])) {
              if (origin.substring(i, length + i).equals(origin.substring(index, length + index))) {
                if (ans < length) {
                  ans = length * 2;
                }
              }
            }
          }
        }

		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 24020
N = int(input())
An = list(map(int,input().split(' ')))

An_half_sum = sum(An)/2
i = 0
sum_count =0
for i in range(N):
    sum_count += An[i]
    if An_half_sum <= sum_count:
        break
min_num = min(sum_count - An_half_sum, An_half_sum - sum_count + An[i])
print(int(min_num*2))
#print(sum_count - An_half_sum)
#print(An_half_sum - sum_count + An[i])

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

double EPS = 1e-10;
double add(double a, double b){
  if(abs(a+b) < EPS* (abs(a) + abs(b))) return 0;
  return a+b;
}

struct P{
  double x,y;
  P(){}
  P(double _x,double _y):x(_x),y(_y){}
  P operator + (P p){
    return P(add(x,p.x) ,add(y,p.y));
  }
  P operator - (P p){
    return P(add(x,-p.x) ,add(y,-p.y));
  }
  P operator * (double d){
    return P(x * d,y * d);
  }
  friend ostream& operator<<(ostream& os,const P& p){
    os << "("<<p.x <<","<<p.y<<")";
    return os;
  }
  double dot(P p){
    return add(x * p.x,y*p.y);
  }
  double det(P p){
    return add(x*p.y,-y*p.x);
  }
  double dist2(P p){
    return ((*this-p).x * (*this-p).x) + ((*this-p).y * (*this-p).y);
  }
  double GetSlope(P &p){
    P tmp = *this - p;
    return tmp.y/tmp.x;
  }
};
//???????????????????????¨?????????
bool on_seg(P p1,P p2,P q){
  return (p1-q).det(p2-q) == 0 && (p1-q).dot(p2-q) <= 0;
}
//???????°????
P intersection(P p1, P p2, P q1,P q2){
  return p1 + (p2-p1) * ((q2 - q1).det(q1-p1) / (q2 - q1).det(p2-p1)) ;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double xa,ya,xb,yb,cx,cy,dx,dy;
  while(cin >> xa>>ya >> xb >> yb >> cx >> cy >> dx >> dy){
    P ab = P(xa-xb,ya-yb),cd = P(cx-dx,cy-dy);
    Ans(abs(ab.dot(cd)) < EPS );
  }
  return 0;
}

Measured memory_bytes: 3196
#include <algorithm>
#include <climits>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

long Sum(vector<pair<int, int>>& collection, int min_index, int max_index)
{
	long sum = 0;
	for (int i = min_index; i < max_index; i++)
		sum += get<0>(collection[i]);
	return sum;
}

int main()
{
	int n; cin >> n;
	vector<int> odd_collection(n / 2, 0), even_collection(n / 2, 0);

	loop(i, n / 2)
	{	// 偶数番目と奇数番目の入力を保存
		cin >> odd_collection[i];
		cin >> even_collection[i];
	}

	vector<pair<int, int>> count_odd_collection;
	count_odd_collection.resize(100000);
	for (const auto& e : odd_collection)
	{	// 偶数数列の同じ要素をカウントする
		get<0>(count_odd_collection[e % 100000])++;
		get<1>(count_odd_collection[e % 100000]) = e % 10000;
	}
	sort(count_odd_collection.begin(), count_odd_collection.end(), greater<pair<int, int>>());

	vector<pair<int, int>> count_even_collection;
	count_even_collection.resize(100000);
	for (const auto& e : even_collection)
	{	// 奇数数列の同じ要素をカウントする
		get<0>(count_even_collection[e % 100000])++;
		get<1>(count_even_collection[e % 100000]) = e % 10000;
	}
	sort(count_even_collection.begin(), count_even_collection.end(), greater<pair<int, int>>());

	long min = 0;
	if (get<1>(count_odd_collection[0]) == get<1>(count_even_collection[0]))
	{	// 例外処理その１「偶数数列と奇数数列で出現頻度が最も高い数字が同じ時」
		if (get<0>(count_odd_collection[1]) < get<0>(count_even_collection[1]))
		{
			min += Sum(count_odd_collection, 1, count_odd_collection.size());
			min += get<0>(count_even_collection[0]);
			min += Sum(count_even_collection, 2, count_even_collection.size());
		}
		else
		{
			min += get<0>(count_odd_collection[0]);
			min += Sum(count_odd_collection, 2, count_odd_collection.size());
			min += Sum(count_even_collection, 1, count_even_collection.size());

		}
	}
	else
	{	// 通常処理　出現頻度が最も高い数字に置き換えれば答えになる
		min += Sum(count_odd_collection, 1, count_odd_collection.size());
		min += Sum(count_even_collection, 1, count_even_collection.size());
	}

	// 例外処理その２「偶数数列と奇数数列が全て同じ数字のとき」
	// 数列を個別に見れば置き換え回数はゼロだが、実際は片方の数列を全て置き換える必要がある
	if (min == 0 && odd_collection[0] == even_collection[0])
		min = n / 2;

	cout << min;

	return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		if(S == U) score[0]--;
		else score[1]--;
		Console.WriteLine(String.Join(" ",score));
	}
	String S,T;
	int[] score;
	String U;
	public Sol(){
		var ss = rsa();
		S = ss[0]; T = ss[1];
		score = ria();
		U = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    int n,k;
    cin >> n >> k;
    int ans = 0;
    rep(i,n){
        int x ; cin >> x;
        ans += min(abs(k-x),x);
    }
    cout << ans * 2 << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
  priority_queue<int> mlist;
  int i;
  for(i=0;i<10;i++){
    int dt;
    cin>>dt;
    mlist.push(dt);
  }
  for(i=0;i<3;i++){
    cout <<mlist.top()<<endl;
    mlist.pop();
  }

  return 0;
}

Measured memory_bytes: 3140
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <numeric>
using namespace std;

int main() {
	string s;
	cin >> s;
	const string ss = "keyence";
	bool flag;
	flag = false;
	if (s.length() < ss.length()) {
		cout << "NO" << endl;
		return 0;
	}
	for (int i = 0; i < ss.length(); ++i) {
		string ss1 = ss.substr(0, i);
		string ss2 = ss.substr(i);
		string s1 = s.substr(0, ss1.length());
		string s2 = s.substr(s.length() - ss2.length());
		if (ss1 == s1 && ss2 == s2) {
			flag = true;
		}
	}
	if (flag) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && a == c && b == c){
        cout << 1 << endl;
    }else if(a != b && a != c && b != c){
        cout << 3 << endl;
    }else{
        cout << 2 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iterator>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(v) begin(v), end(v)
#define rreps(i, a, n) for (ll i = (a); i <= (ll)(n); ++i)
#define rrep(i, n) rreps(i, 0, n)
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define each(i, n) for (auto&& i : n)
#define fill(x, y) memset(x,y,sizeof(x))
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <typename T> inline void print(const T& x) {cout << x << '\n';}

signed main()
{ 
  int n; cin>>n;
  vi a(n);
  each(v,a) cin>>v;
  ll cnt=0;
  for(int l=0, r=0, bit=0; l<n; ++l)
  {
    while(r<n&&(bit&a[r])==0) bit|=a[r++];
    cnt+=r-l;
    bit^=a[l];
  }

  print(cnt);

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<int> A(N);
    map<int, int> mp;
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    vec<int> F((int)1e6+100,0);
    sort(all(A));

    int ans= 0;
    rep(i,N){
        int now = A[i];
        if(F[now] >= 1){
            F[now]++;
            continue;
        }
        if(F[now] == 0 && mp[now] == 1) ++ans;
        for(int j=now;j<=(int)1e6+1;j+=now){
            F[j]+=1;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 17092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int bit_full_search(int n, string s)
{

    int a;
    
    for (int bit = 0; bit < (1<<n); ++bit) {
        int ans = s[0] - '0';
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                //cout << " " << i << " ";
                ans -= s[i+1]-'0';
            }else{
                ans += s[i+1]-'0';
            }
        }
        if(ans == 7){
            a = bit;
            break;
        }
    }

    return a;
    
}

int main() {
    string s;
    cin >> s;
    vector<string> vec{"+","+","+"};

    int result;
    result = bit_full_search(s.size()-1, s);

    for (int i = 0; i < s.size()-1; ++i) {
        if (result & (1<<i)) {
            vec[i] = "-";
        }
    }

    cout << s[0] << vec[0] << s[1] << vec[1] << s[2] << vec[2] << s[3] << "=7" << endl;

}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int h,r;
	scanf("%d",&h);
	scanf("%d",&r);
	if(h==-r){
		printf("0\n");
	}
	else if(h+r<0){
		printf("-1\n");
	}
	else{
		printf("1\n");
	}
	
	return 0;
}



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

int main() {
  string N;
  cin >> N;
  
  if(N=="SUN")
    cout << 7 << endl;
  
  if(N=="MON")
    cout << 6 << endl;
  
  if(N=="TUE")
    cout << 5 << endl;
  
  if(N=="WED")
    cout << 4 << endl;
  
  if(N=="THU")
    cout << 3 << endl;
  
  if(N=="FRI")
    cout << 2 << endl;
  
  if(N=="SAT")
    cout << 1 << endl;
  
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
k=1
lst=[]
for i in range(1,n):
    if a[i]==a[i-1]:
        k+=1
    else:
        lst.append(k)
        k=1
lst.append(k)
m=len(lst)
count=0
for i in range(m):
    if lst[i]%2==0:
        lst[i]=2
        count+=1
    else:
        lst[i]=1
if count%2==0:
    print(m)
else:
    print(m-1)

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 2 == 1)
            cnt++;
    }
    cout << fixed << setprecision(15);
    cout << (double)cnt / n << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>


using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int sum = a1 + a2 + a3;
    if (sum >= 22) {
        cout << "bust\n";
    } else {
        cout << "win\n";
    }
    
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n;
  scanf("%d", &n);

  vector<int> v(n);
  REP (i, n) scanf("%d", &v[i]);

  sort(v.begin(), v.end());

  int ans = 0;
  auto itr = v.begin();
  while (itr < v.end()) {
    auto next = lower_bound(itr, v.end(), *itr + 1);
    int num = next - itr;
    if (num > *itr) ans += num - *itr;
    else if (num < *itr) ans += num;
    
    itr = next;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 640
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

for x in b:
    for i,a in enumerate(A):
        if x in a:
            A[i][a.index(x)] = 0
for i in range(3):
    if A[i][0]+A[i][1]+A[i][2] == 0 or A[0][i]+A[1][i]+A[2][i] == 0:
        print("Yes")
        exit()

if A[0][0]+A[1][1]+A[2][2] == 0 or A[0][2]+A[1][1]+A[2][0] == 0:
    print("Yes")
    exit()
    
print("No")


Measured memory_bytes: 3188
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    int a[5],b[5],ans=0;
    pair<int,int>p[5];
    for(int i=0;i<5;++i){
        cin>>a[i];
        b[i]=a[i]%10;
        if(b[i]!=0)b[i]=10-b[i];
        p[i].first=b[i],p[i].second=a[i];   
    }
    sort(p,p+5);
    for(int i=0;i<4;++i)
        p[i].second+=p[i].first;
    for(int i=0;i<5;++i)
        ans+=p[i].second;
    
    cout<<ans<<endl;
    return 0;
        
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string vect = "aiueo";
    char c;
    cin >> c;
    if (count(ALL(vect), c) > 0) {
        cout << "vowel" << endl;
        return 0;
    } else {
        cout << "consonant" << endl;
        return 0;
    } 
}

Measured memory_bytes: 256
N = gets.to_i
S = N.times.map{gets.chomp.bytes.sort}.sort

last = nil
a = []
idx = 0
S.each do |line|
  if last.nil?
    last = line
    a[idx] = 1
  elsif last != line
    last = line
    idx += 1
    a[idx] = 1
  elsif last == line
    a[idx] += 1
  end
end
b = a.find_all { |i| i >= 2 }
c = b.map { |i| (i-1)*(i)/2 }
if c.empty?
  puts "0"
else
  puts c.inject(:+)
end



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


void solve(long long A, long long B, long long T){
    int ans = 0;
    int time = A;
    while(time <= T){
        ans += B;
        time += A;
    }
    cout << ans << endl;

}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long T;
    scanf("%lld",&T);
    solve(A, B, T);
    return 0;
}


Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

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

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << 1 << endl;
  } else if (a != b && b != c && c != a) {
    cout << 3 << endl;
  } else {
    cout << 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

from math import gcd

def solve():
    N = II()
    A = LI()
    
    mx = 1000003
    D = [1] * mx
    for i in range(2, len(D)):
        if D[i] != 1:
            continue
        for j in range(i, len(D), i):
            if D[j] == 1:
                D[j] = i

    # def fast_make_divisor(x):
    #     d = D[x]
    #     divisors = [d]
    #     while x != d:
    #         x = x // d
    #         d = D[x]
    #         divisors.append(d)
    # # print(divisors)
    #     return divisors

    g = A[0]
    dct = defaultdict(int)
    flag = True
    for a in A:
        g = gcd(g, a)
        # print(a, D[a])
        # if D[a] != 1:
        #     if dct[D[a]] > 0:
        #         flag = False
        #     dct[D[a]] += 1
        # print(a, fast_make_divisor(a))
        d = D[a]
        p = a
        # 最小の素数を求める
        while p != d:
            p = p // d
            d = D[p]

        if p != 1:
            dct[p] += 1
            if dct[p] > 1:
                flag = False

    if g == 1:
        if flag:
            print('pairwise coprime')
        else:
            print('setwise coprime')
    else:
        print('not coprime')


if __name__ == '__main__':
    solve()



Measured memory_bytes: 127868
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-10;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int n;
  cin >> n;
  vector<ll> a(n + 1);
  rep(i, n + 1) cin >> a[i];
  if (a[0] > 0)
  {
    if (n == 0 && a[0] == 1)
      cout << 1 << "\n";
    else
      cout << -1 << "\n";
    return;
  }
  vector<ll> csum(n + 2);
  csum[n + 1] = 0;
  for (int i = n + 1; i > 0; i--)
    csum[i - 1] = a[i - 1] + csum[i];
  ll ans = 1;
  ll v = 1;
  REP(i, 1, n + 1)
  {
    v = min(2 * v - a[i], csum[i + 1]);
    if (v < 0)
    {
      cout << -1 << "\n";
      return;
    }
    ans += v + a[i];
  }
  cout << ans << "\n";
}

int main()
{
  init_main();

  solve();

  return 0;
}

Measured memory_bytes: 4768
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  s <- getLine
  let isTrue = and $ map ($s) [check1,check2,check3]
  putStrLn $ if isTrue then "AC" else "WA"

check1 s = head s=='A'
check2 s = elem 'C' $ drop 2 $ init s
check3 s = and $ elemList (s\\"AC") ['a'..'z']

elemList [] _ = []
elemList (x:xs) list  = elem x list : elemList xs list

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A ;
  cin >> A ;
  int iti ;
  int jyu ;
  int hya ;
  hya = A / 100 ;
  jyu = ( A - 100 * hya ) / 10 ;
  iti = A - 100 * hya - 10 * jyu ;
  cout << iti + jyu + hya << endl ;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int a,b,c;cin>>a>>b>>c;
    long long k;cin>>k;
    if(k%2==0)cout<<a-b<<endl;
    else cout<<b-a<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

def main():
  input = sys.stdin.readline
  n,k = map(int,input().split())
  sl = [0]*(n+1)
  tree = [[] for i in range(n+1)]
  mod = 10**9+7
  ans = k

  for i in range(n-1):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)
    
  lent = len(tree[1])
  if lent > 0:
    q = deque(tree[1])
    for x in range(k-1, k-1-lent, -1):
      ans = ans * x % mod
    sl[1] = 1
  else:
    print(k)
    exit()
  
  qpop = q.popleft
  qappend = q.append
  
  while q:
    pos = qpop()
    sl[pos] = 1
    lent = len(tree[pos]) - 1
    if lent > 0:
      for x in range(k-2, k-2-lent, -1):
        ans = ans * x % mod
    for i in tree[pos]:
      if sl[i] == 0:
        qappend(i)
  print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 23896
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 1000000000;

main(){
  int a, b;
  while(cin >> a >> b && (a|b)){
    int ans = INF;
    for(int i=1;i<=a;i++){
      if(a%i != 0) continue;
      for(int j=1;j<=b;j++){
        if(b%j != 0) continue;
        int tmp[4] = {i, a/i, j, b/j};
        sort(tmp, tmp+4);
        int sum = 0;
        for(int i=1;i<4;i++){
          sum += (tmp[i] - tmp[i-1]) * (tmp[i] - tmp[i-1]);
        }
        ans = min(ans, sum);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define         sf       scanf
#define         pf       printf
#define         sz       30

using namespace std;

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

struct nd
{
	int x, y;
};

char a[sz][sz];
bool vis[sz][sz];
int dis[sz][sz], r, c, l1, l2, ans;

int bfs(int i, int j)
{
	nd g;
	queue<nd> q;

	g.x = i;
	g.y = j;

	vis[i][j] = true;
	dis[i][j] = 0;
	ans = max(ans, dis[i][j]);
	q.push(g);

	while(!q.empty())
	{
		nd gr = q.front();
		l1 = gr.x;
		l2 = gr.y;
		q.pop();

		for(int k = 0; k < 4; k++)
		{
			int xx = gr.x + dx[k];
			int yy = gr.y + dy[k];

			if(xx>=0 and xx<r and yy>=0 and yy<c and vis[xx][yy]==false and a[xx][yy]=='.')
			{
			    nd temp;
			    temp.x = xx;
			    temp.y = yy;

				vis[xx][yy] = true;

				q.push(temp);

				dis[xx][yy] = dis[gr.x][gr.y] + 1;
				ans = max(ans, dis[xx][yy]);
			}
		}
	}
}

int main()
{
	cin >> r >> c;

	for(int i = 0; i < r; i++)
	{
		for(int j = 0; j < c; j++)
		{
			cin >> a[i][j];
		}
	}

	for(int i = 0; i < r; i++)
	{
		for(int j = 0; j < c; j++)
		{
			if(vis[i][j]==false and a[i][j]=='.')
			{
				bfs(i, j);
				memset(vis, false, sizeof(vis));

				bfs(l1, l2);
				memset(vis, false, sizeof(vis));
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int64 gcd(int64 a, int64 b) { return b? gcd(b,a%b):a; };
int64 lcm(int64 a, int64 b) { return a/gcd(a,b)*b; };

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> ans(n+2, 0);
    for (int i=0; i<m; i++) {
        int l,r;
        cin >> l >> r;
        ans[l] += 1;
        ans[r+1] -= 1;
    }

    for (int i=0; i<n; i++)
        ans[i+1] += ans[i];

    int pans = 0;
    for (int i=1; i<=n; i++)
        if (ans[i] >= m) pans++;

    cout << pans << endl;
}


Measured memory_bytes: 640
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    while(true){
      val line = StdIn.readLine()
      if(line == "0"){return}
      println(line.toCharArray.map(_.toString.toInt).sum)
    }
  }
}

Measured memory_bytes: 44192
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int cnt[N] = {};
    int tmp;
    int cnt2 = 0;
    rep(i, N) {
        cin >> tmp;
        tmp--;
        cnt[tmp]++;
    }
    rep(i, N) if (cnt[i] > 0) cnt2++;

    //dump(cnt2);
    if (cnt2 <= K) {
        cout << "0" << endl;
        return 0;
    }
    sort(cnt, cnt + N);
    int ans = 0;
    rep(i, N) {
        if (cnt[i] == 0) continue;
        ans += cnt[i];
        //dump(cnt[i]);
        cnt2--;
        if (cnt2 <= K) {
            cout << ans << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1152