akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, a[1000];

void push(int x)
{
	top++;
	a[top]=x;
}

int pop()
{
	top--;
	return a[top+1];
}

int main(void)
{
	int x, y;
	top=0;
	char c[100];

	while(scanf("%s", &c) != EOF){
		if(c[0]=='+'){
			x=pop();
			y=pop();
			push(x+y);
		}
		else if(c[0]=='-'){
			x=pop();
			y=pop();
			push(y-x);
		}
		else if(c[0]=='*'){
			x=pop();
			y=pop();
			push(x*y);
		}
		else{
			push(atoi(c));
		}
	}
	printf("%d\n", pop());
	
	return 0;
}
			


Measured memory_bytes: 2092
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

#define MOD 1000000007

ll pow_mod(ll a, ll p){
    if(p == 1) return (ll)a;
    if(p == 0) return (ll)1;
    ll ret = pow_mod(a, p / 2);
    ret = (ret * ret) % MOD;
    if(p % 2 == 1)
        ret = (ret * a) % MOD;
    return ret;
}

ll inverse(ll a){
    return pow_mod(a, MOD - 2);
}

ll comb(ll n, ll m){
    ll ret = 1;
    ll k = min(m, n - m);
    for(ll i = 1; i <= k; ++i){
        ret = (ret * (n - k + i)) % MOD;
        ret = (ret * inverse(i)) % MOD;
    }
    return ret;
}

int main(){
    ll n, m;
    cin >> n >> m;
    list<ll> prime;
    prime.push_back(2);
    for(ll i = 3; i < sqrt(m) + 1; ++i){
        bool isp = true;
        repi(j, prime){
            if(i % *j == 0){
                isp = false;
                break;
            }
        }
        if(isp){
            prime.push_back(i);
        }
    }
    ll ans = 1;
    repi(i, prime){
        if(m <= 1)
            break;
        ll num = 0;
        while(m % *i == 0){
            ++num;
            m /= *i;
        }
        if(num != 0){
            ans = (ans * comb(num + n - 1, num)) % MOD;
        }
    }
    if(m != 1){
        ans = (ans * comb(n, 1)) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		if (sc.nextInt() * sc.nextInt() * sc.nextInt() == 175) {
			System.out.print("YES");
		} else {
			System.out.print("NO");
		}
	}
}


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

using namespace std;

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> s;
    s.push_back(a);
    s.push_back(b);
    s.push_back(c);

    sort(s.begin(), s.end());
    int output = s[0] + s[1];
    cout << output << endl;
}


Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]

D = {}
D['AC'] = 0
D['WA'] = 0
D['TLE'] = 0
D['RE'] = 0

for k in range(N):
  D[S[k]] += 1

print('AC x',D['AC'])
print('WA x',D['WA'])
print('TLE x',D['TLE'])
print('RE x',D['RE'])

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


int main() {
    int n;
    cin >> n;
    vector< int> v(n);

    int s = 0;
    for (int &e : v) {
        cin >> e;
        s += e;
    }
    if (s % 10) return !printf("%d\n", s);

    sort(begin(v), end(v));
    for(int &e: v) {
        if((s - e) % 10) return !printf("%d\n", s - e);
    }

    puts("0");
}

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

int main(void){
  int M,N;
  cin >> N >> M;
  
  int A[100];
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    sum += A[i];
  }
  
  int count=0;
  
  for (int i=0; i<N; i++){
    if (A[i]*4*M >= sum){
      count++;
    }
  }
  
  if (count >= M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) {
        cin >> A.at(i);
    }

    ll res = LLONG_MAX;
    for (int i = 0; i + K - 1 < (ll)A.size(); i++) {
        ll cos = 0;
        ll r = i + K - 1;
        cos = abs(A[i]) + abs(A[r] - A[i]);
        res = min(res, cos);
        cos = abs(A[r]) + abs(A[r] - A[i]); 
        res = min(res, cos);
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
import java.util.*;
import java.util.stream.*;
import java.util.function.*;

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println(new Main().solve());
    }
    
    // パラメタ渡しもちゃんとクラス作るのも面倒なので手抜き
    // 必要な値はここで全部取ってしまう
    Scanner sc = new Scanner(System.in);
    // int n = Integer.parseInt(sc.next());
    // {sc.nextLine();}
    int[] a = IntStream.range(0, 5).map(i -> Integer.parseInt(sc.next())).toArray();
    int k =  Integer.parseInt(sc.next());
    String solve() {
        for(int i : a) {
            for(int j : a) {
                if(i - j > k) {
                    return ":(";
                }
            }
        }
        return "Yay!";
    }
    
}
// public class Main {
//     public static void main(String[] args) throws Exception {
//         Scanner sc = new Scanner(System.in);
//         int a = sc.nextInt();
//         int b = sc.nextInt();
//         int c = sc.nextInt();
//         int d = sc.nextInt();
//         int e = sc.nextInt();
        
//         IntStream.of(a, b, c, d, e).
//         int k = sc.nextInt();
//         System.out.println();
//     }
    
//     // // パラメタ渡しもちゃんとクラス作るのも面倒なので手抜き
//     // // 必要な値はここで全部取ってしまう
//     // Scanner sc = new Scanner(System.in);
//     // int n = Integer.parseInt(sc.next());
//     // {sc.nextLine();}
//     // int[] a = IntStream.range(0, n).map(i -> Integer.parseInt(sc.next())).toArray();
    
//     // String solve() {
//     //     return n + "" + Arrays.toString(a);
//     // }
    
// }


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

void trace(int A[],int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(int A[],int N){
    int j,i,v;
    for(int i=1;i<N;i++){
        v=A[i];
        j=i-1;
        while(j>=0 && A[j]>v){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(){
    int N,i,j;
    int A[100];
    
    cin >> N;
    for(i=0;i<N;i++) cin >> A[i];
    
    trace(A,N);
    insertionSort(A, N);

    
    return 0;
}

Measured memory_bytes: 3108
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		System.out.println(saiki(h));
	}
	public static long saiki(long h){
		if(h==1) return 1;
		else {
			return 2*saiki(h/2)+1;
		}
	}
}


Measured memory_bytes: 22100
#include<iostream>

using namespace std;
char T; int s, n; int chain;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> T >> s;
		if (T == ')') { s = -s; }
		chain += s;
		if (chain < 0) { cout << "NO" << endl; goto E; }
	}
	if (chain != 0) { cout << "NO" << endl; goto E; }
	cout << "YES" << endl;
E:;
	return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
 
#define N 8
  
 void print(void);
 void backtrack(int);
  
 int a[N][N] = {{}};
 int row[N] = {};
 int l[15] = {};
 int r[15] = {};
 int s[N] = {};
  
 void backtrack(int i){
   int j;
  
   if(i == N){
     print();
     return;
   }
  
   for(j = 0;j < N;j++){
     if(s[j] == 1 || l[i + j] == 1 || r[i - j + N - 1] == 1) continue;
  
     row[i] = j;
     l[i + j] = r[i - j + N - 1] = s[j] = 1;
  
     backtrack(i + 1);
  
     row[i] = s[j] = l[i + j] = r[i - j + N - 1] = 0;
  
   }
  
 }

int main(){
 
 
  int i,j,r,c,k;
 
 
  scanf("%d",&k);
 
  for(i = 0;i < k;i++){
    scanf("%d%d",&r,&c);
    a[r][c] = 1;
  }
  backtrack(0);
 
  return 0;
}
 

 
void print(){
 
  int i,j;
 
  for(i = 0;i < N;i++){
    for(j = 0;j < N;j++){
      if(a[i][j] == 1){
        if(row[i] != j) {
          return;
        }
      }
    }
  }
  for(i = 0;i < N;i++){
    for(j = 0;j < N;j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
 
}

Measured memory_bytes: 572
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  string s,t,u;cin>>s>>t;
  int a,b;cin>>a>>b>>u;
  if(s==u)a--;
  else b--;
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
v = RI()

ans1 = 0
ans2 = 0

a = []
b = []
for i in range(n):
    if i%2==0:
        a.append( v[i] )
    else:
        b.append( v[i] )

ac = Counter(a)
bc = Counter(b)

ma = 0
mb = 0

for i in ac:
    if ma<ac[i]:
        ma = ac[i]
        no1 = i
    else:
        pass

for i in bc:
    if mb<bc[i] and i!=no1:
        mb = bc[i]
        no2 = i
    else:
        pass

ans1 += len(a) - ma
ans1 += len(b) - mb

ma = 0
mb = 0

for i in bc:
    if mb<bc[i]:
        mb = bc[i]
        no2 = i
    else:
        pass

for i in ac:
    if ma<ac[i] and i!=no2:
        ma = ac[i]
        no1 = i
    else:
        pass

ans2 += len(a) - ma
ans2 += len(b) - mb

print(min(ans1,ans2))

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

#define ll long long

using namespace std;

int main(){

    int n;
    cin >> n;
    int hairetu[n];
    for(int i=0; i<n; i++){
        cin >> hairetu[i];
    } 
    ll minv = 1000;
    ll maxv = 0;
    for(int i=0; i<n; i++){
        if(hairetu[i] < minv){
            minv = hairetu[i];
        }
        if(hairetu[i] > maxv){
            maxv = hairetu[i];
        }
    }

    cout << maxv - minv << endl;

    return 0;
}


Measured memory_bytes: 256
N=int(input())
if N==1:
    print(1)
    exit()
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

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

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

    return arr
num=0
divs=[0]*(N+1)
for i in range(2,N+1):
    l=factorization(i)
    for t in l:
        divs[t[0]]+=t[1]
p=10**9+7
#print(divs)
ans=1
for a in divs:
    if a>=1:
        ans*=(a+1)
        ans%=p
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
ll power(ll x,ll y,ll p){
ll res = 1;x = x % p;
while (y > 0){
if (y & 1){res = (res*x) % p;}
y = y>>1;
x = (x*x) % p;}
return res;}
ll mcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    else return mcd(b,a%b);
}
ll t,n,m;
bool esprimo(ll n){
ll s=0;
for(ll i=1;i*i<=n;i++){
    if(n%i==0){s++;}}
if(s>=2){return false;}
return true;
}
int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
ll w;
cin>>n>>w;
ll a[n][2];
for(int i=0;i<n;i++){cin>>a[i][0]>>a[i][1];}
ll b[n][w+1];
memset(b,0,sizeof b);
for(int i=0;i<n;i++){
b[i][a[i][0]]=a[i][1];
}
for(int i=0;i<n;i++){
for(int j=0;j<=w;j++){
    if(b[i][j]!=0){
        for(int k=i+1;k<n;k++){
            if(j+a[k][0]<=w){
            b[k][j+a[k][0]]=max(b[k][j+a[k][0]],b[i][j]+a[k][1]);
        }}
    }
}
}
ll s=0;
for(int i=0;i<n;i++){
    for(int j=0;j<=w;j++){
       //cout<<b[i][j]<<" ";
       s=max(s,b[i][j]);
    }
    //cout<<endl;
}
cout<<s<<endl;
}



Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>
#include <random>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-9;

int main() {
	int x, y;
	cin >> x >> y;
	if (x == y) {
		cout << "Yes" << endl;
		return 0;
	}
	set<int> se({1, 3, 5, 7, 8 ,10, 12});
	if (se.count(x) && se.count(y)) {
		cout << "Yes" << endl;
	} else if (x == 2 || y == 2) {
		cout << "No" << endl;
	} else if (se.count(x) || se.count(y)) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int a, b;
	cin >> a >> b;
	if(a < b)
	swap(a, b);
	int ans = a;
	a--;
	ans += max(a, b);
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int S, W;

int main() {

    cin >> S >> W;

    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e18,cnt;
ll flag;

ll b1[3],b2[3],b3[3];
int main(){
	ll c1[3],c2[3],c3[3];
	for(ll i=0; i<3; i++){
		cin>>c1[i];
	}
	
	for(ll i=0; i<3; i++){
		cin>>c2[i];
	}
	
	for(ll i=0; i<3; i++){
		cin>>c3[i];
	}
	
	for(ll j=0; j<=100; j++){
		for(ll i=0; i<=100; i++){
			for(ll k=0; k<=100; k++){
				for(ll r=0; r<3; r++){
					b1[r]=c1[r]-j;
					b2[r]=c2[r]-i;
					b3[r]=c3[r]-k;
				}
				bool ok=true;
				for(ll r=0; r<3; r++){
					if(b1[r]!=b2[r] || b1[r]!=b3[r]){
						ok=false;
					}
				}
				if(ok==true){
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
}



Measured memory_bytes: 256
def main():
  from collections import deque
  import sys
  input = sys.stdin.readline
  from heapq import heapify,heappop,heappush
  T = int(input())
  for _ in range(T):
    N = int(input())
    KLR = [list(map(int,input().split())) for _ in range(N)]
    left = deque([])
    right = deque([])
    ans = 0
    for K,L,R in KLR:
      x = L - R
      if x==0:
        ans += L
      elif x>0:
        left.append([K,L,R])
        ans += R
      else:
        right.append([K+1,L,R])
        ans += L

    left = sorted(left)
    right = sorted(right,reverse=True)
      
    S = []
    heapify(S)
    x = 1
    i = 0
    length = len(left)
    while x<=N:
      while i<length:
        klr = left[i]
        if klr[0]==x:
          heappush(S,klr[1]-klr[2])
          i += 1
          
        else:
          break
      
      y = len(S) - x
      if y<=0:
        x += 1
        continue
      else:
        for _ in range(y):
          heappop(S)
          
    ans += sum(S)
    
    S = []
    heapify(S)
    x = N+1
    i = 0
    length = len(right)
    while x>=0:
      while i<length:
        klr = right[i]
        if klr[0]==x:
          heappush(S,klr[2]-klr[1])
          i += 1
 
        else:
          break
      
      y = len(S) + x - N - 1
      if y<=0:
        x -= 1
        continue
      else:
        for _ in range(y):
          heappop(S)    
    ans += sum(S)
    print(ans)
    
main()

Measured memory_bytes: 129532
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll mod = 1e9+7;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> cnt(n+5, 0);
  rep(i, n){
    int a;
    cin >> a;
    ++cnt[a];
  }
  if(n%2 == 1){
    rep(i, n){
      if(i%2 == 1)   {if(cnt[i] != 0){cout << 0; return 0;}}
      else if(i == 0){if(cnt[i] != 1){cout << 0; return 0;}}
      else           {if(cnt[i] != 2){cout << 0; return 0;}}
    }
  }
  else{
    rep(i, n){
      if(i%2 == 1)   {if(cnt[i] != 2){cout << 0; return 0;}}
      else           {if(cnt[i] != 0){cout << 0; return 0;}}
    }
  }
  auto f = [](int n){
    ll power = 1;
    while(n >= 1){power *= 2; power %= mod; --n;}
    return power;
  };
  cout << f(n/2);
  return 0;
}   

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,t=0;cin>>n>>a>>b;
	if(a+b-1>n||(long long)a*b<n)cout<<-1;
	else{
		for(int i=0;i<a;i++)
		{
			int rem=min((n-t)-(a-i-1),b);
			for (int j=0;j<rem;j++)cout<<t+rem-j<<" ";
			t+=rem;
		}
	}
	return 0;
}

Measured memory_bytes: 3624
// ddcc_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    vector<int> A(N);
    REP(i, N) cin >> A[i];

    ll sm = 0;
    REP(i, N){
        sm += A[i];
    }

    ll tmp = 0;
    ll ans = numeric_limits<ll>::max();
    REP(i, N){
        tmp += A[i];
        ans = min(ans, abs(sm - tmp - tmp));
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1024
//This code was made by Chinese_zjc_
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
inline int rd(int &ddd)
{
	char tmp=getchar();
	int xxx=1;
	ddd=0;
	while(('0'>tmp||tmp>'9')&&tmp!='-'&&tmp!=EOF)
	{
		tmp=getchar();
	}
	if(tmp==EOF)
	{
		return EOF;
	}
	if(tmp=='-')
	{
		xxx=-1;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		ddd=(ddd<<3)+(ddd<<1)+(tmp^48);
		tmp=getchar();
	}
	return ddd*=xxx;
}
inline char rd(char &ddd)
{
	char tmp=getchar();
	while(tmp==' '||tmp=='\n')
	{
		tmp=getchar();
	}
	if(tmp==EOF)
	{
		return EOF;
	}
	return ddd=tmp;
}
inline int max(const int &A,const int &B)
{
	return A<B?B:A;
}
inline int min(const int &A,const int &B)
{
	return A<B?A:B;
}
int a,b;
signed main()
{
	rd(a);
	rd(b);
	printf("%lld",max(a*b,max(a+b,a-b)));
	return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    h = list(map(int, input().split()))
    h += [h[0]] * 2

    dp = [0]*(n+10)
    for i in range(n):
        dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i]))
    print(dp[n-1])


if __name__=="__main__":
    main()

Measured memory_bytes: 52208
#include<stdio.h>
#include<string.h>
int main(){
  int a,b=0,c=0;
  char s[100001];
  scanf("%s",s);
  a=strlen(s);
  for(int i=0; i<a; i++){
    if(s[i]=='0'){
      b++;
    }else{
      c++;
    }
  }
  printf("%d",b<c?b*2:c*2);
  return 0;}

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


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

    long long n, m;

    cin >> n >> m;

    long long ans = m*(m-1) + n*(n-1);

    cout << ans/2;

    return 0;
      

}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    int A[N], B[N];
    map<int, vector<int>> v;
    REP(i, N)
    {
    	int a, b;
    	cin >> a >> b;
    	v[a].push_back(b);
    }
    ll ans = 0;
    priority_queue<int> que;

    // 後ろから考える
    // 今回は後ろから考えると選べるバイトの制約が厳しくなる
    for (int i = 1; i <= M; ++i)
    {
	  	auto itr = v.find(i);      
	    if( itr != v.end() ) 
	    {
	    	for (int j = 0; j < v[i].size(); ++j)
			{
				que.push(v[i][j]);
			}
	    } 
	    else 
	    {
	    	// 何もしない
		}

    	if (que.size() != 0)
    	{
    		ans += que.top();
    		que.pop();
    	}
    }

    cout << ans << endl;
}


Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2005;
int vis[N],rd[N],a[N],n;
bitset<N> ycl[N];
vector<int> v[N];
void dfs(int p){
	vis[p]=1;
	for(int i=1;i<=n;i++)if(!vis[i]&&ycl[p][i]){v[p].push_back(i); rd[i]++; dfs(i);}
}
priority_queue<int> q;
signed main(){
	n=read(); 
	for(int i=1;i<=n;i++)a[i]=read();
	sort(&a[1],&a[n+1]);
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)ycl[i][j]=ycl[j][i]=__gcd(a[i],a[j])>1;
	for(int i=1;i<=n;i++)if(!vis[i]){
		dfs(i);
	}
	for(int i=1;i<=n;i++)if(rd[i]==0)q.push(i);
	while(q.size()){
		int t=q.top(); q.pop(); write(a[t]); putchar(' ');
		for(auto i:v[t])if(--rd[i]==0)q.push(i);
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  string s;cin>>s;
  for(int i=0;i<s.size();i++){
    if(i&1){
      if(s[i]=='R')fin("No");
    }
    else if(s[i]=='L')fin("No");
  }
  fin("Yes");
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[1003];
    scanf("%s", s);
    int i, w, n;
    scanf("%d", &w);
    n = strlen(s);
    i = 0;
    while (i < n)
    {
        printf("%c", s[i]);
        i += w;
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
A,B,C,D = map(int,input().split())
if C<=A:
    if D>=B:
        print(B-A)
    elif A<=D:
        print(D-A)
    else:
        print(0)
elif C<=B:
    if D<=B:
        print(D-C)
    else:
        print(B-C)
else:
    print(0)

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

int main () {
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        if (p[i - 1] < p[i] && p[i] < p[i + 1]) ans++;
        else if (p[i - 1] > p[i] && p[i] > p[i + 1]) ans++;
    }
    cout << ans << endl;
}

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

int main(){
    int N, L; cin >> N >> L;
    int m = abs(L + N - 1), sum = 0, min_i = 0;
    for(int i = 0; i < N; i++){
        if(abs(L + i) <= m){
            m = abs(L + i);
            min_i = i;
        }
        sum += L + i;
    }
    cout << sum - (L + min_i) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (i < b) sb.append(j < a ? 0 : 1);
					else if (i >= b) sb.append(j < a ? 1 : 0);
				}
				sb.append("\n");
			}
			System.out.println(sb);
		}
	}
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<char>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli h,w;
mat m,t,o;
map<string,lli> mp;
map<string,lli> tp;
lli c;

bool special_check(){
  if(mp.size() == 1 && tp.size() == 1){
    for(auto x : mp){
      for(auto y : tp){
        if(x.first == y.first){
          for(lli i = 0;i < h;i++){
            for(lli j = 0;j < w;j++){
              // cout << i << " " << j << " " << h-i-1 << " " << w-j-1 <<  " " << m[i][j] << " " << m[h-i-1][w-j-1] << endl;
              if(o[i][j] != o[h-i-1][w-j-1]) return false;
            }
          }
        }
      }
    }
  }
  return true;

}


int main(){
  cin >> h >> w;
  o = m = mat(h,vector<char>(w));
  t = mat(w,vector<char>(h));
  for(lli i = 0;i < h;i++){
    string s;
    cin >> s;
    for(lli j = 0;j < w;j++){
      o[i][j] = m[i][j] = s[j];
      t[j][i] = s[j];
    }
  }




   c = 0;
   for(lli i = 0;i < h;i++){
     sort(m[i].begin(),m[i].end());
     mp[string(m[i].begin(),m[i].end())]++;
   }
   for(auto x : mp){
     if(x.second%2 == 1) c++;
   }
   if(c > 1){
     cout << "NO" << endl;
     return 0;
   }


   c = 0;
   for(lli j = 0;j < w;j++){
     sort(t[j].begin(),t[j].end());
     tp[string(t[j].begin(),t[j].end())]++;
   }
   for(auto x : tp){
     if(x.second%2 == 1) c++;
   }
   if(c > 1){
     cout << "NO" << endl;
     return 0;
   }

  if(special_check() == false){
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;
    
    for(int i=0;i<5;i++)
        cout << S[i];
    cout << ' ';
    for(int i=6;i<13;i++)
        cout << S[i];
    cout << ' ';
    for(int i=14;i<19;i++)
        cout << S[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define int long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1*1e5+5;


int32_t main() {

	FAST;
	int n;
	cin >> n;
	vector<int> slimes(n);
	
	for(int &i : slimes)
		cin >> i;
	
	auto sum = [&](int L, int R) {
		int kappa = 0;
		for(int i = L; i <= R; i++)
			kappa += slimes[i];
		return kappa;
	};
	
	int dp[n][n];
	
	for(int L = n-1; L >= 0; L--)
		for(int R = L; R < n; R++) {
			if(L == R) dp[L][R] = 0;
			else {
				dp[L][R] = LINF;
				for(int i = L; i <= R-1; i++)
					dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + sum(L, R));
			}
		}
	cout << dp[0][n-1] << endl;
}


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

int main() {
    int n;
    ll ans = 0;
    cin >> n;
    map<int, int> mp;
    set<int> st = {-1, n};
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        mp[p] = i;
    }
    for (int i = n; i >= 1; i--) {
        int x = mp[i];
        auto iter = st.upper_bound(x), itel = iter;
        itel--;
        ll l = *itel, r = *iter, l1, r1;
        if (*itel == -1) {
            l1 = -1;
        } else {
            itel--;
            l1 = *itel;
        }
        if (*iter == n) {
            r1 = n;
        } else {
            iter++;
            r1 = *iter;
        }
        ll C = (l - l1) * (r - x) + (x - l) * (r1 - r);
        ans += i * C;
        st.insert(x);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int K,A,B;
  cin >> K >> A >> B;

  if(A%K == 0 || B%K == 0){
    cout << "OK" << endl;
    return 0;
  }
  int a,b;
  a = A/K;
  b = B/K;

  if(a==b){
    cout << "NG" << endl;
  }
  else{
    cout << "OK" << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define nrep(i,a,b) for(ll i=a;i>=b;i--)

	using namespace std;
	int main()
	{
	
	priority_queue<ll> pq;
	ll n, m;
	cin >> n >> m;
	rep(i,0,n)
    {
		ll x;
		cin >> x;
		pq.push(x);
	}
	while(m--){
		ll k = pq.top();
		pq.pop();
		pq.push(k/2);
	}
	ll sum = 0;
	rep(i,0,n)
    {
		sum += pq.top();
		pq.pop();
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 1400
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node  *right,*left,*parent;
};

Node *root,*NIL;


void insert(int k){
  Node *y =NIL;
  Node *x =root;
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL)return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  string com;
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    cin>>com;
    if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n" );
    }
  }
  return 0;
}



Measured memory_bytes: 26624
import itertools
import bisect
N=int(input())
S=input()
ans=0
L=dict()
R=dict()
for seq in itertools.product([0,1],repeat=N):
    T0=""
    T1=""
    T2=""
    T3=""
    for i in range(N):
        if seq[i]==0:
            T0+=S[i]
            T2+=S[-i-1]
        else:
            T1+=S[i]
            T3+=S[-i-1]
    a0=len(T0)
    a1=len(T1)
    a2=len(T2)
    a3=len(T3)
    if (T0,T1) in L:
        L[(T0,T1)]+=1
    else:
        L[(T0,T1)]=1
    if (T2,T3) in R:
        R[(T2,T3)]+=1
    else:
        R[(T2,T3)]=1
for tup in L:
    if tup in R:
        ans+=L[tup]*R[tup]
print(ans)


Measured memory_bytes: 127512
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		String a=scanner.next();
		String b=scanner.next() ;
		int length = Math.min(a.length(), b.length());
	    int pos = 0;
	    while (pos < length) {
	        if (0 != (a.charAt(pos) ^ b.charAt(pos))) {
	            break;
	        }
	        pos++;
	    }
	   // System.out.println(a.substring(pos));
	    //System.out.println(b.substring(pos));

	    	if(a.substring(pos).length()==0) {
	    		System.out.println("Yes");
	    	}
	    	else {
	    		System.out.println("No");
	    	}


		}


}


Measured memory_bytes: 35420
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
        ll n;
        ll a[200010];
        vector<ll>v;
        vector<ll>w;
        cin>>n;
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        ll sum=0;
        for(ll i=0;i<n;i++){
            sum+=a[i];
            v.push_back(sum);
        }
        for(ll i=0;i<n-1;i++){
            w.push_back(abs(v[i]-(v[n-1]-v[i])));
            //cout<<w[i]<<endl;
        }
        sort(w.begin(),w.end());
        cout<<w[0]<<endl;
        



    return 0;
}

Measured memory_bytes: 6384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cstring>
#include<cmath>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define MOD 1000000007

typedef  long long ll;

using namespace std;


void solve() {
    ll n;
    cin >> n;
    ll d[n+1];
    ll ans = 0LL;
    ll a = 998244353LL;
    bool flag = false;

    for(ll i = 1;i< n+1;i++){
        cin >> d[i];
    }
    ////////
    if(d[1] != 0){
        cout << ans << endl;
        return;
    }

    sort(d+1,d+n+1);
    
    for(ll i = 1;i < n;i++){
        if(d[i+1]-d[i] > 1){
            flag = true;
        }
        if(d[1] == 0 && d[2] == 0){
            flag = true;
            break;
        }
    }
////////
    if(flag) {
        cout << ans << endl;
        return;
    }

    ll cur = 1LL;
    ll prev = 1LL;
    ll t[n];
    ll size = 0;
    ll aflag = false;
    for(int i = 2;i < n;i++){
 
        if(d[i] == d[i+1] /*&& i < n-1*/){
            cur++;
            if(i == n-1){
                aflag = true;
            }
        }else{
            ll tmp = 1LL;
            for(ll j = 0;j < cur;j++){
                tmp *= prev;
                tmp %= a;
            }
            t[size] = tmp;
            size++;
            prev = cur;
            cur = 1LL;
            if(i == n-1){
                t[size] = prev;
            }
        }

        if(aflag){
            ll tmp = 1LL;
            for(ll j = 0;j < cur;j++){
                tmp *= prev;
                tmp %= a;
            }
            t[size] = tmp;
        }
    }
    
    ans = 1LL;
    for(ll i = 0;i < size+1;i++){
        ans *= t[i];
        ans %= a;
       // cout << t[i] << endl;
    }
    cout << ans << endl;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}



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

int main() {
  int a;
  cin >> a;
  int sum=0,num[a],ans=0;
  for(int i = 0;i<a;i++){
    cin >> num[i];
    sum += num[i];
  }
  for(int i = 0;i<a;i++){
    sum -= num[i];
    ans += sum*num[i];
  }
  cout << ans;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

ll n;

int cal(ll x){
	int res = 0;
	while(x){
		res++;
		x /= 10;
	}
	return res;
}

int main(){
	cin >> n;
	int ans = INF;
	for(int i=1; i<=sqrt(n*1.0); i++){
		if(n%i == 0){
			int a=i,b=n/i;
			int t = max(cal(a),cal(b));
			if(t < ans) {
				ans = t;
			}
		}
	}
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
string a,b,c;
cin >> a>> b>> c;
a[0]-=32;
b[0]-=32;
c[0]-=32;
cout << a[0] << b[0] << c[0] <<endl;
return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var deposit float64 = 100
	x := nextInt()

	for i := 1; i <= int(math.Pow10(18)); i++ {
		deposit = math.Trunc(deposit * 1.01)
		if x <= int(deposit) {
			fmt.Println(i)
			return
		}
	}
}


Measured memory_bytes: 1756
# @uthor : Kaleab Asfaw
import sys

input = sys.stdin.readline

def main(n, lst):
    peaks = []
    minn = float("inf")
    maxx = float("-inf")
    money = 1000
    for i in lst:
        if i > maxx:
            if maxx != float("-inf"):
                times, rem = divmod(money, maxx)
                money = i * times + rem
                maxx = i
            else:
                maxx = i
        else:
            maxx = i
    return money
            
n = int(input())
lst = list(map(int, input().split()))
print(main(n, lst))




Measured memory_bytes: 9112
import sys
sys.setrecursionlimit(1000000)

h, w = map(int, input().split())
s = [input() for _ in range(h)]
t = [[None]*w for _ in range(h)]

def dfs(i,j,color): # i,jの色がcolorと同じなら0, colorと異なるなら連結成分でまだカウントされていない要素を数えてその白黒の数を返す
    if not(0<=i<h and 0<=j<w): return 0,0 # i,jが意味をなさないとき
    if s[i][j]==color: return 0,0 # i,jの色がcolorと同じとき
    if t[i][j]: return 0,0 # すでにカウントしたi,jであったとき
    
    t[i][j]=True
    c = s[i][j]
    wh, bl=0,0
    if c=='#':
        bl+=1
    else:
        wh+=1
    

    tmp1,tmp2=dfs(i+1,j,c)
    wh,bl=wh+tmp1,bl+tmp2

    tmp1,tmp2=dfs(i-1,j,c)
    wh,bl=wh+tmp1,bl+tmp2
            
    tmp1,tmp2=dfs(i,j-1,c)
    wh,bl=wh+tmp1,bl+tmp2

    tmp1,tmp2=dfs(i,j+1,c)
    wh,bl=wh+tmp1,bl+tmp2

    return wh,bl

    # tmp1, tmp2 = dfs(i-1,j,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # tmp1, tmp2 = dfs(i+1,j,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # tmp1, tmp2 = dfs(i,j-1,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp1

    # tmp1, tmp2 = dfs(i,j+1,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # return bl,wh

ans = 0
for i in range(h):
    for j in range(w):
        a,b = dfs(i,j,'!')
        ans += a*b
print(ans)
    

Measured memory_bytes: 138724
#include <stdio.h>

int main() {
	int a[5], b, c, d, e;
	char s[100];
	scanf("%d%d", &b, &c);
	for (int i = 0; i <= b; i++) {
		if (i * 2+(b-i) * 4 == c  ) {
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
ostream& operator << (ostream &s, vector<string> P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s; }



int D;
long long G;
vector<long long> p, c;

int main() {
  while (cin >> D >> G) {
	p.resize(D); c.resize(D);
	for (int i = 0; i < D; ++i) cin >> p[i] >> c[i];

	
	long long res = 1<<29;
	for (int bit = 0; bit < (1<<D); ++bit) {
	  long long sum = 0;
	  long long num = 0;
	  for (int i = 0; i < D; ++i) {
		if (bit & (1<<i)) sum += c[i] + p[i] * 100 * (i+1), num += p[i];
	  }
	  if (sum >= G) res = min(res, num);
	  else {
		for (int i = D-1; i >= 0; --i) {
		  if (bit & (1<<i)) continue;
		  for (int j = 0; j < p[i]; ++j) {
			if (sum >= G) break;
			sum += 100 * (i+1);
			++num;
		  }
		}

		res = min(res, num);
	  }
	}

	cout << res << endl;
  }
}





















Measured memory_bytes: 256