akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    ll n, m;
    cin >> n >> m;
    ll ans = 1;
    if (abs(n - m) > 1) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, n) {
        ans *= (i + 1);
        if (ans > 1000000007) {
            ans %= 1000000007;
        }
    }
    rep(i, m) {
        ans *= (i + 1);
        if (ans > 1000000007) {
            ans %= 1000000007;
        }
    }
    if (abs(n - m) % 2 == 0) {
        ans *= 2;
    }
    if (ans > 1000000007) {
        ans %= 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#define ll long long 
using namespace std;

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	if (n <= k) {
		cout << n*x << endl;
	} else {
		cout << k*x + (n - k)*y << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import math

i = 0
j = 0
k = 0
n = []
s = []
while True:
    n.append(int(input()))
    if n[i] == 0:
        break

    s.append(list(map(int, input().split())))
    i += 1

a = [] * (len(n) - 1)

while True:
    if j == len(n) - 1:
        break

    sumsum = 0
    avr = sum(s[j]) / n[j]
    for k in range(n[j]):
        sumsum += (s[j][k] - avr) ** 2
    
    print(math.sqrt(sumsum / n[j]))

    j += 1
        


Measured memory_bytes: 5704
#include <iostream>

int main()
{
	char* s[] {"a == b", "a > b", "a < b"};
	int a, b, n;
	std::cin >> a >> b;
	n = a==b ? 0 : a>b ? 1 : 2; 
	std::cout << s[n] << '\n';
}

Measured memory_bytes: 3072
S = [int(c) for c in input()]
ans = 0

for i in range(1 << (len(S) - 1)):
    c, s = 0, 0
    for c2, d in enumerate(S):
        if (i << 1) & (1 << c2):
            s += c
            c = 0
        c = 10 * c + d
    s += c
    ans += s

print(ans)


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

int main()
{
    int n;
    cin >> n;
    long long prev, now, ans;
    prev = -1;
    now = 2;
    for(int i = 0; i < n; i++){
        ans = prev + now;
        prev = now;
        now = ans;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())

if k == 0:
    print(n*n)
    exit()

ans = 0
for b in range(k+1,n+1):
    ans += (b-k) * (n//b)
    if b*(n//b)+k<=n:
        ans += n-(b*(n//b)+k-1)

print(ans)


Measured memory_bytes: 39536
#include<stdio.h>

// define
#define MAX_INPUT 1000

// function
void inputArray(int a[], int *num);
void insertionSort(int a[], int num);
void outputArray(int a[], int num);

int main(void)
{
  int size;
  int input[MAX_INPUT];
  
  inputArray(input, &size);
  insertionSort(input, size);
  
  return 0;
}

void inputArray(int a[], int *num)
{
  //  printf("input array size =\n");
  scanf("%d", num);

  //  printf("input array = \n");
  for ( int i = 0; i < *num; i++ ) {
    scanf("%d", &a[i]);
  }
  outputArray(a, *num);
}

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

void outputArray(int a[], int num)
{
  for (int i=0; i < num-1; i++) {
    printf("%d ", a[i]);
  }
  printf("%d\n", a[num-1]);
}

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

def main():
    N = int(input())
    H = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        h = H[i]
        if h == 0:
            continue
        for j in range(h):
            for k in range(i, N):
                if H[k] >= 1:
                    H[k] -= 1
                else:
                    break
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()


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

typedef pair<int, int> PII;

int N;
int W;
vector<int> vv;
vector<int> vw;

PII solve() {
  vector<vector<int> > dp(N+1, vector<int> (W+1, 0));

  for (int i = N - 1; i >= 0; i--) {
    for (int w = 0; w <= W; w++) {
      if (w < vw[i])
	dp[i][w] = dp[i + 1][w];
      else
	dp[i][w] = max(dp[i + 1][w],
		       dp[i + 1][w - vw[i]] + vv[i]);
    }
  }

  auto v_max = dp[0][W];
  auto w_min = W;
  for (int i = 0; i < W; i++) {
    if (dp[0][i] == v_max) {
      w_min = i;
      break;
    }
  }
  
  return make_pair(v_max, w_min);
}

int main() {
  int c = 1;
  while (true) {
    cin >> W;
    if (W == 0) break;
    
    vv.clear();
    vw.clear();
    cin >> N;
    vv.resize(N);
    vw.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("\n%d,%d", &vv[i], &vw[i]);
    }

    cout << "Case " << c++ << ":" << endl;
    auto result = solve();
    cout << result.first << endl << result.second << endl;
  }
}


Measured memory_bytes: 6872
#include<iostream>
#include<queue>
#include<sstream>
#include<algorithm>

using namespace std;

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

struct S {
  int pos, bit;
  vector<string> ans;
};

bool used[15][1 << 15];

int main() {
  while (true) {
    int n, m, s, t, bit = 0;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    vector<vector<int> > e(n), sw(n);
    rep (i, m) {
      cin >> s >> t;
      --s, --t;
      e[s].push_back(t);
      e[t].push_back(s);
    }
    rep (i, n) {
      cin >> s;
      bit |= s << i;
    }
    rep (i, n) {
      cin >> s;
      rep (j, s) {
	cin >> t;
	if (i + 1 != t) sw[i].push_back(t - 1);
      }
      sort(sw[i].begin(), sw[i].end());
    }
    queue<S> que;
    S ss;
    ss.pos = 0;
    ss.bit = bit;
    que.push(ss);
    rep (i, n) rep (j, 1 << n) used[i][j] = false;
    bool f1 = false, f2 = false;
    while (!que.empty()) {
      S now = que.front();
      que.pop();
      if (used[now.pos][now.bit]) continue;
      used[now.pos][now.bit] = true;
      if (now.pos == n - 1) {
	f1 = true;
	if (now.bit == (1 << (n - 1))) {
	  f2 = true;
	  stringstream ss;
	  ss << now.ans.size();
	  string str;
	  ss >> str;
	  cout << "You can go home in " + str + " steps." << endl;
	  rep (i, now.ans.size()) cout << now.ans[i] << endl;
	  break;
	}
      }
      rep (i, e[now.pos].size()) {
	if (!(now.bit & 1 << e[now.pos][i])) continue;
	S next = now;
	next.pos = e[now.pos][i];
	stringstream ss;
	ss << next.pos + 1;
	string str;
	ss >> str;
	next.ans.push_back("Move to room " + str + ".");
	que.push(next);
      }
      rep (i, sw[now.pos].size()) {
	S next = now;
	next.bit = now.bit ^ 1 << sw[now.pos][i];
	stringstream ss;
	ss << sw[now.pos][i] + 1;
	string str;
	ss >> str;
	if (next.bit & 1 << sw[now.pos][i]) {
	  next.ans.push_back("Switch on room " + str + ".");
	} else {
	  next.ans.push_back("Switch off room " + str + ".");
	}
	que.push(next);
      }
    }
    if (!f1) {
      cout << "Help me!" << endl;
    } else if (!f2) {
      cout << "You can not switch off all lights." << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 16156
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to
import std.math;
import std.algorithm;
void main()
{
    string a = chomp(readln());
    string b = chomp(readln());
    int N = to!int(a); // 第0要素を整数に変換
    int K = to!int(b); // 第1要素を整数に変換
    int ans = 1;
    for(int i=0;i<N;i++){
        if(ans < K)
            ans*=2;
        else
            ans+=K;
    }
    writeln(ans);
}

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

int main()
{
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    // 0:R, 1:S, 2:P
    int t[N];
    int v[3] = {R, S, P};
    for (int i = 0; i < N; i++) {
        if (T[i] == 'r') t[i] = 2;
        if (T[i] == 's') t[i] = 0;
        if (T[i] == 'p') t[i] = 1;
    }

    int dp[N][3] = {};

    for (int i = 0; i < K; i++) {
        dp[i][t[i]] = v[t[i]];
        for (int j = i + K; j < N; j += K) {
            for (int k = 0; k < 3; k++) {
                if (t[j] == k) {
                    dp[j][k] = max(dp[j - K][(k + 1) % 3], dp[j - K][(k + 2) % 3]) + v[k];
                }
                else {
                    dp[j][k] = max(dp[j - K][(k + 1) % 3], dp[j - K][(k + 2) % 3]);
                }
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= K; i++) {
        ans += max(dp[N - i][0], max(dp[N - i][1], dp[N - i][2]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long ans = 0;
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<int>());
    ans += A[0];
    int count = 2;
    int consume = 1;
    while (count < N) {
        ans += A[consume];
        count ++;
        if (count < N ) {
            ans += A[consume];
            count ++;
            consume ++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;


int main(){
    ll N, M, Q; cin >> N >> M >> Q;
    vector<vector<ll>> D(N+1, vector<ll>(N+1));
    for(int i = 0; i < M; i++){
        ll l, r; cin >> l >> r; D[l][r]++;
    }
    for(int i = 0; i < N+1; i++){
        for(int j = 0; j < N; j++) D[i][j+1] += D[i][j];
    }

    while(Q--){
        ll p, q; cin >> p >> q;
        ll cnt = 0;
        for(;p <= q; p++){
            cnt += D[p][q];
        }
        cout << cnt << endl;
    }

}


Measured memory_bytes: 5564
n, m, limit = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

x = 0
y = 0
t = 0
while x < n and t + A[x] <= limit:
    t += A[x]
    x += 1
while y < m and t + B[y] <= limit:
    t += B[y]
    y += 1

max_x = x + y

while x > 0:
    x -= 1
    t -= A[x]
    while y < m and t + B[y] <= limit:
        t += B[y]
        y += 1
    if x + y > max_x:
        max_x = x + y

print(max_x)


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

using namespace std;

int main()
{
  char s[6];
  for(int i=0; i<6; i++)
  {
    cin>>s[i];
  }
  if(s[2] == s[3] && s[4] == s[5])
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;


int main(){
    ll n;cin>>n;
    ll a[200020];
    rep(i,0,n)cin>>a[i];
    ll r=0,sum=0,xsum=0,an=0;
    rep(l,0,n){
        while(r<n&&((xsum^a[r])==sum+a[r])){
            sum+=a[r];
            xsum=xsum^a[r];
            r++;
        }
        an+=r-l;
        if(r==l)r++;
        else{
            xsum=xsum^a[l];
            sum-=a[l];
        }
    }
    cout<<an<<endl;
}

    









Measured memory_bytes: 1792
import sys
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
a = A[0]
b = A[-1]
if N == 2:
    print(A[1]-A[0])
    print(A[1],A[0])
    sys.exit()
ans = []
for x in A[1:-1]:
    if x <= 0:
        ans.append([b, x])
        b = b - x
    else:
        ans.append([a, x])
        a = a - x
ans.append([b,a])
M = b-a
print(M)
for x in ans:
    print(x[0], x[1])

Measured memory_bytes: 23880
N, W = map(int, input().split())
# dp[i][w] : i個目の時の重さwの最大値
dp = [[0] * 100010 for _ in range(N+1)]
for i in range(N):
    w_i, v_i = map(int, input().split())
    for w in range(W+1):
        if w >= w_i:
            dp[i+1][w] = max(dp[i][w-w_i]+v_i, dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])


Measured memory_bytes: 120300
<?php
  
fscanf(STDIN, "%s", $s);
$sn = str_split($s);
$n = strlen($s);
$cn = array_fill(0, $n, 0);

fputs(STDERR, implode(' ', $sn) . "\n");

$chr = 'R';
$offset = 0;

while ($offset < $n) {
    if ($offset === $n - 1) {
        $cn[$offset] += 1; // L
		break;
	}
	$needle = ($chr === 'R') ? 'L' : 'R';
	$pos = strpos($s, $needle, $offset);
    fputs(STDERR, "$chr:$pos\n");
	if ($pos === false) {
        $num = $n - $offset;
        $cn[$offset] += 1 + floor(($num - 1) / 2); // L
        $cn[$offset - 1] += floor(($num) / 2); // R
		break;
	}
    $num = $pos - $offset;
    if ($chr === 'R') {
    	$cn[$pos - 1] += 1 + floor(($num - 1) / 2); // R
        $cn[$pos] += floor($num / 2); // L
	} else {
    	$cn[$offset] += 1 + floor(($num - 1) / 2); // L
        $cn[$offset - 1] += floor($num / 2); // R
	}
	$chr = $needle;
    $offset = $pos;
}

echo implode(' ', $cn);

Measured memory_bytes: 35972
#include<bits/stdc++.h>
using namespace std;
#define RI register int
const int N=105;
int n;char S[N],T[N];
int check(int l) {
	for(RI i=n-l+1;i<=n;++i)
		if(S[i]!=T[i-n+l]) return 0;
	return 1;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",S+1),scanf("%s",T+1);
	for(RI i=n;i>=0;--i)
		if(check(i)) {printf("%d\n",2*n-i);break;}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[list(map(int,input().split(" "))) for i in range(2)]
b=sum(a[0][1:])
for i in range(n-1):
    c=sum(a[0][i+2:])+sum(a[1][:i+1])
    b=c if c<b else b
print(sum(a[0])+sum(a[1])-b)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int digits(ll a){
    int ans = 1;
    while(a > 9){
        a = a / 10;
        ans++;
    }
    return ans;
}

int main() {
    ll n;
    cin >> n;
    int ans = 100;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            int f;
            f = max(digits(i), digits(n / i));
            ans = min(ans, f);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const int init = INT32_MAX;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

void out(bool f, vi v = {})
{
	if (!f) cout << "No" << endl;
	else cout << "Yes" << endl;
	for (auto i : v) cout << i << endl;
	exit(0);
}

vector<vi> tree;
vi dep;
vector<pii> range;

pii dfs(int v)
{
	pii res;
	if (range[v].first != init) res = range[v];
	else res = pii(-INF, INF);
	for (auto i : tree[v])
	{
		pii tmp = dfs(i);
		chmax(res.first, tmp.first - 1);
		chmin(res.second, tmp.second + 1);
	}
	if (res.first > res.second) out(false);
	return range[v] = res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vector<vi> t(n);
	REP(i, n - 1)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		t[a].push_back(b);
		t[b].push_back(a);
	}
	tree.resize(n);
	queue<int> que;
	que.push(0);
	vector<bool> vis(n);
	dep.resize(n);
	vis[0] = true;
	while (!que.empty())
	{
		int a = que.front(); que.pop();
		for (auto i : t[a])
		{
			if(vis[i]) continue;
			vis[i] = true;
			que.push(i);
			tree[a].push_back(i);
			dep[i] = dep[a] + 1;
		}
	}
	range.resize(n, pii(init, init));
	int k; cin >> k;
	int check;
	bool f = true;
	REP(i, k)
	{
		int v, p; cin >> v >> p;
		v--;
		range[v] = pii(p, p);
		if(i == 0) check = (dep[v] + p) % 2;
		else
		{
			if (check != (dep[v] + p) % 2) f = false;
		}
	}
	if (!f) out(f);
	dfs(0);
	while (!que.empty()) que.pop();
	que.push(0);
	vi ans(n);
	ans[0] = range[0].first;
	while (!que.empty())
	{
		int v = que.front();
		que.pop();
		int tmp = ans[v];
		for (auto i : tree[v])
		{
			if (tmp + 1 >= range[i].first && tmp + 1 <= range[i].second)
			{
				ans[i] = tmp + 1;
			}
			else if (tmp - 1 >= range[i].first && tmp - 1 <= range[i].second)
			{
				ans[i] = tmp - 1;
			}
			else assert(false);
			que.push(i);
		}
	}
	out(true, ans);
	return 0;
}

Measured memory_bytes: 21632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    if(n>=2&&m>=2)
    {
        cout<<n*(n-1)/2+m*(m-1)/2;
    }
    else if(n<=1&&m>=2)
    {
        cout<<m*(m-1)/2;
    }
    else if(n>=2&&m<=1)
    {
        cout<<n*(n-1)/2;
    }
    else
    {
        cout<<"0";
    }
    return 0;
}



Measured memory_bytes: 256
from collections import defaultdict


def main():
    A, B = map(int, input().split())

    if A == 1:
        A += 100
    if B == 1:
        B += 100

    if A == B:
        print("Draw")
    elif A > B:
        print("Alice")
    else:
        print("Bob")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
input += chunk;
});
process.stdin.on('end', function() {
var lines = input.split('\n').map(Number);
for (var i = 0; i < lines.length && lines[i] != 0; i++) {
console.log('Case %d: %d', i + 1, lines[i]);
}
});

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

using namespace ::std;

typedef long long ll;
typedef unsigned long long ull;


int px[] = {0, 1, 0, -1, 1, -1, -1, 1};
int py[] = {1, 0, -1, 0, 1, 1, -1, -1};

int main()
{
    int test, n, m, a, b;

    //scanf("%d", &test);


    scanf("%d", &n);

    int in[n + 7];
    int mark[1000007]{};

    for(int i = 0; i<n; ++i) scanf("%d", &in[i]), mark[in[i]]++;

    bool flag[1000007]{};

    sort(in, in + n), b = 0;

    for(int i = 0; i<n; ++i)
    {
        if(flag[in[i]]) continue;

        bool decide = 1;
        for(int j = in[i]; j<=1000007; j += in[i])
        {
            if(mark[in[i]] > 1) decide = 0;

            //if(mark[j]) decide = 0;
            flag[j] = 1;
        }

        if(decide) ++b;
    }

    cout << b << endl;
}

Measured memory_bytes: 9344
include Math

while gets
	l, w, h = $_.chomp.split.map(&:to_i)
	break if [l,w,h].all?(&:zero?)
	cheese_size = [l,w,h].combination(2).map{ |x,y| sqrt(x**2 + y**2) }.min
	n = gets.to_i
	cheese_ok = Array.new(n,0)
	n.times do |i|
		r = gets.to_i
		entrance_limit = 2*r
		cheese_ok[i] = (cheese_size < entrance_limit ? "OK" : "NA")
	end
	puts cheese_ok
end

Measured memory_bytes: 6136
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    vi a(m);
    cin >> a;
    int res = n - accumulate(all(a), 0LL);
    if (res < 0)
        res = -1;
    cout << res << endl;
    GAME_OVER;
}

Measured memory_bytes: 3720
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int d = scanner.nextInt() - 1;
        int x = scanner.nextInt() + n;
        for (int i = 0; i < n; i++) {
            x += d / scanner.nextInt();
        }
        System.out.println(x);
    }
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){

    int n,l;
    cin>>n>>l;
    multiset<string>tree;
    rep(i,n){
        string s;
        cin>>s;
        tree.emplace(s);
    }
    auto it=tree.begin();
    while(it!=tree.end()){
        cout<<*it;
        it++;
    }
    cout<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=rdsp;foreach(ref j;v.tupleof)pick(r,j);}}

void main()
{
  int n; readV(n);
  struct P { int x, y, h; }
  P[] p; readS(n, p);

  auto pf = p.find!(pi => pi.h > 0);
  if (pf.empty) {
    foreach (x; 0..101)
      foreach (y; 0..101)
        if (p.all!(pi => pi.x != x && pi.y != y)) {
          writeln(x, " ", y, " ", 1);
          return;
        }
  } else {
    auto pt = pf[0];
    foreach (x; 0..101)
      foreach (y; 0..101) {
        auto h = pt.h + (x-pt.x).abs + (y-pt.y).abs;
        if (p.all!(pi => max(h - (x-pi.x).abs - (y-pi.y).abs, 0) == pi.h)) {
          writeln(x, " ", y, " ", h);
          return;
        }
      }
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            long ans = 0;
            if (2 == N || 2 == M)
            {
                ans = 0;
            }
            else
            {
                ans = Math.BigMul(Math.Max(1, N - 2), Math.Max(1, M - 2));
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    string s[n];
    rep(i, 0, n) cin >> s[i];

    string ans;
    rep(i, 0, 26) {
        int mn = 100;
        rep(j, 0, n) {
            int cnt = 0;
            rep(k, 0, (int)s[j].size()) {
                if (s[j][k] == (char)(i + 'a')) {
                    cnt++;
                }
            }
            mn = min(mn, cnt);
        }
        rep(k, 0, mn) ans += (char)(i + 'a');
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import fractions
n1, n2, n3, n4 = [int(i) for i in input().split()]

n5 = (n3 * n4) // fractions.gcd(n3, n4)

n6 = (n2 // n3) - ((n1 - 1) // n3)
n7 = (n2 // n4) - ((n1 - 1) // n4)
n8 = (n2 // n5) - ((n1 - 1) // n5)

r1 = (n2 - n1  + 1)- n6 - n7 + n8 

print(r1)

Measured memory_bytes: 6012
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo for(int i=0;i<n;i++)
#define clear cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define loopSolve int t; cin>>t; while(t--){solve();}
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//INT_MAX         2,147,483,647                       <10^10
//U_INT_MAX       4,294,967,295                       <10^10
//LONG_LONG_MAX   9,223,372,036,854,775,807           <10^18
//U_LONG_LONG_MAX 18,446,744,073,709,551,615          <10^18
//ll power(int a, int b){
//    return (ll)(pow(a,b)+0.5);
//}

vector<int> gV(int n){
    vector<int> v(n);
    fo { cin>>v[i];  }
    return v;
}

int* gA(int n){
    int* arr = new int[n];
    fo cin>>arr[i];
    return arr;
}


void solve(){
    int n,d;
    cin>>n>>d;
    int count=0;
    fo{
        ll one,two;
        cin>>one>>two;
        if(sqrt(one*one + two*two )<=d)
            count++;
    }
    cout<<count<<endl;
}


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

    solve();
    //loopSolve;

	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> left;
  vector<int> right;
  rep(i, N)
  {
    int x;
    cin >> x;
    if (x < 0)
      left.emplace_back(x);
    else if (x == 0)
      K--;
    else
      right.emplace_back(x);
  }

  std::reverse(left.begin(), left.end());

  long long mn = -1;
  int L = std::min(K, (int)left.size());

  if (K == 0)
  {
    cout << 0 << endl;
    return 0;
  }
  for (int l = 0; l <= L; l++)
  {
    if (K - l > right.size())
      continue;

    long long sum = 0;
    if (l == 0)
    {
      sum = right[K - 1];
    }
    else if (l == K)
    {
      sum = -left[K - 1];
    }
    else
    {
      sum = -left[l - 1] + right[K - l - 1];
      sum += std::min(-left[l - 1], right[K - l - 1]);
    }

    if (mn == -1 || mn > sum)
      mn = sum;
  }

  cout << mn << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

ll solve(vector<ll>& A, ll M) {
  unordered_map<ll, ll> mod_map;

  ll mod_sum = 0;
  for (auto&& x : A) {
    mod_sum += x;
    mod_sum %= M;

    mod_map[mod_sum]++;
  }

  ll retv = 0;
  for (auto &&p : mod_map) {
    auto i = p.first;
    auto x = p.second;
    if (i == 0) {
      retv += x;
    }
      retv += x * (x - 1) / 2;
  }

  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, M;
  cin >> N >> M;

  vector<ll> A(N);
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }

  // main procedure
  ll ans = solve(A, M);

  // output
  cout << ans << endl;

  return 0;
}

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

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

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

int main()
{
    int n,k;
    cin>>n>>k;
    int A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    int dp[n];
    for(int i=0;i<n;i++){
        dp[i] = INT_MAX;
	}
    dp[0] = 0;
    for(int i=0;i<n;i++){
        int val = i+k;
        for(int j=i+1;j<=min(n-1,val);j++){
            dp[j] = min(dp[j],dp[i]+abs(A[i]-A[j]));
        }
    }
        cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
 
signed main(){
    int n;
    cin>>n;
    int mark=1;
    for(int i=0;i<n;i++){
        int t;cin>>t;
        if(mark==t){
            mark++;
        }
    }

    if(mark>1)cout<<n-mark+1<<endl;
    else cout<<-1<<endl;
 
}

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

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

int main(){
  int n;
  cin>>n;
  if(n<1000)
    cout<<"ABC"<<endl;
  else
    cout<<"ABD"<<endl;



  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
        }

        if (N%2==0) {
            // long tmp_1 = 0L;
            // long tmp_2 = 0L;
            // for (int i=0;i<N;i++) {
            //     if (i%2==0) tmp_1+=A[i];
            //     else tmp_2+=A[i];
            // }
            // System.out.println(Math.max(tmp_1, tmp_2));

            long[][] dp = new long[N][2];
            long INF = 2_000_000_000_000_000_000L;
            for (int i=0;i<N;i++) {
                for (int j=0;j<2;j++) {
                    dp[i][j] = -INF;
                }
            }
            dp[0][0] = A[0];
            dp[0][1] = 0L;
            dp[1][1] = A[1];
            for (int i=1;i<N;i++) {
                dp[i][1] = Math.max(dp[i][1], dp[i-1][0]);
                if (i-2>=0) {
                    dp[i][0] = Math.max(dp[i][0], dp[i-2][0]+A[i]);
                    dp[i][1] = Math.max(dp[i][1], dp[i-2][1]+A[i]);
                }
            }
            long ans = dp[N-1][0];
            ans = Math.max(ans, dp[N-1][1]);
            System.out.println(ans);
        } else {
            long[][] dp = new long[N][3];
            long INF = 2_000_000_000_000_000_000L;
            for (int i=0;i<N;i++) {
                for (int j=0;j<3;j++) {
                    dp[i][j] = -INF;
                }
            }
            dp[0][0] = A[0];
            dp[0][1] = 0L;
            dp[0][2] = 0L;
            dp[1][1] = A[1];
            for (int i=1;i<N;i++) {
                dp[i][1] = Math.max(dp[i][1], dp[i-1][0]);
                dp[i][2] = Math.max(dp[i][2], dp[i-1][1]);
                if (i-2>=0) {
                    dp[i][0] = Math.max(dp[i][0], dp[i-2][0]+A[i]);
                    dp[i][1] = Math.max(dp[i][1], dp[i-2][1]+A[i]);
                    dp[i][2] = Math.max(dp[i][2], dp[i-2][2]+A[i]);
                }
            }
            long ans = dp[N-1][0];
            ans = Math.max(ans, dp[N-1][1]);
            ans = Math.max(ans, dp[N-1][2]);
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 63324
#include <stdio.h>

int main(void) {
	int a,b;
	
	scanf("%d %d",&a,&b);
    
    if(a>b){
    	printf("a > b\n");
    }
    if(a<b){
    	printf("a < b\n");
    }
    if(a==b){
    	printf("a == b\n");
    }
	return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s; cin>>s;
  set<char> st;
  st.insert(s[0]); st.insert(s[1]);
  st.insert(s[2]);
  if (st.size() == 2) out("Yes");
  out("No");
  
  

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256
import java.util.Scanner

import scala.util.control.Breaks

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)

    val k = sc.nextInt()
    var x = 7%k

    val b = new Breaks
    b.breakable {
      for(i <- 1 to k){
        if(x == 0){
          println(i)
          b.break()
        }
        x = (x*10+7)%k
      }
      println(-1)
    }

  }
}


Measured memory_bytes: 55424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}
	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	UnionFind clus(n);
	vector<pair<int,int>>ab;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		ab.push_back({ a, b });
		clus.unite(a, b);
	}
	map<int, int>cm;
	for (int i = 0; i < n; i++) {
		clus.par.at(i) = clus.root(i);
		if (cm.count(clus.par.at(i))) cm.at(clus.par.at(i))++;
		else cm[clus.par.at(i)] = 1;
	}
	vector<int>ans(n,0);
	for (int i = 0; i < n; i++)ans.at(i) = cm.at(clus.par.at(i)) - 1;
	for (int i = 0; i < k; i++) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		if (clus.par.at(c) == clus.par.at(d)) {
			ans.at(c)--;
			ans.at(d)--;
		}
	}
	for (int i = 0; i < m; i++) {
		ans.at(ab.at(i).first)--;
		ans.at(ab.at(i).second)--;
	}
	for (int i = 0; i < n; i++) {
		if (i == 0)cout << ans.at(i);
		else {
			cout << " " << ans.at(i);
		}
	}
}

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

int main() {
    int n, m, a[10005], ans=0;
    cin >> n >> m;
    for(int i=0; i<m; i++) {
        cin >> a[i];
        ans+=a[i];
    }
    if(ans>n) cout << -1;
    else cout << n-ans;
}

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

using namespace std;

void divMTwo(vector<int> *s, int n) {
    if(n == 0) return;
    else if(n != 0) {
        if(abs(n) % 2 == 1) {
            (*s).push_back(1);
            if(n < 0) n--;
        }
        else {
            (*s).push_back(0);
        }

        divMTwo(s, n / (-2));
    }
} 

int main() {
    int n;
    vector<int> a(1, 0);

    scanf("%d", &n);

    divMTwo(&a, n);

    if(n == 0) {
        printf("%d\n", n);
    }
    else {
        for(int i = a.size() - 1; i > 0; i--) {
            printf("%d", a[i]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int series_sum(long long int);

int main(){
    long long int ans,a,b,c,d;
    cin>>a>>b>>c>>d;
    ans=b-a+1;
    long long int e=0;
    e+=(b/c)-(a/c);
    if(a%c==0)e++;
    e+=(b/d)-(a/d);
    if(a%d==0)e++;
    long long int f=c*d/__gcd(c,d);
    e-=(b/f)-(a/f);
    if(a%(f)==0)e--;
    cout<<ans-e<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

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

void output(int p, int q, int r, int s) {
  if (p > r || (p == r && q >= s)) cout << p << " " << q << " " << r << " " << s << endl;
  else cout << r << " " << s << " " << p << " " << q << endl;
}

int main() {
  while (true) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0) break;
    rep (i, a + 1) if (i > 0 && a % i == 0) for (int j = -abs(c); j <= abs(c); ++j) if (j != 0 && c % j == 0) {
	  int ii = a / i;
	  int jj = c / j;
	  if (i * jj + ii * j != b) continue;
	  output(i, j, ii, jj);
	  goto next;
	}
    if (c == 0) {
      output(a, b, 1, 0);
      goto next;
    }
    cout << "Impossible" << endl;
  next:;
  }
}

Measured memory_bytes: 1164
#include<stdio.h>
int main(void)
{
	int n[13],a[101],i,j,flg,cnt;
	for(i=1;i<=100;i++) a[i]=0;
	for(i=1;i<=12;i++) scanf("%d",&n[i]);
	cnt=0;
	for(i=1;i<=100;i++){
		for(j=1;j<=12;j++){
			if(i==n[j]) cnt++;
		}
		a[i]=cnt;
	}
	flg=0;
	for(i=1;i<=100;i++){
		if(a[i]%2!=0) flg=1;
	}
	if(flg!=0) printf("no\n");
	else printf("yes\n");
	return 0;
}	

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

using namespace std;

typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;


void solve()
{
	ll x,y,z;
	cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	cout<<x<<" "<<y<<" "<<z<<endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}

Measured memory_bytes: 256
/*3.3 hightierra*/
#include <stdio.h>
#include <math.h>

int main(void){
  int N,K; //変数の定義
  scanf("%d %d",&N,&K); //入力
  
  int i = 1; //カウンターを定義
  
  /*K^(i-1)<=N<K^iのとき、NはK進法でi桁*/
  while(pow((double)K,(double)i)<=N){
    i++;
  }
  printf("%d\n",i);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q, W, H, L, R, C, A, B;
string S;

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

    cout << min(A * N, B);

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
ll k,a[575];
bool used[575];
vector<P> v;

bool comp(P a, P b){
	return (abs(a.second)<abs(b.second));
}

bool check(ll g){
	int i,p;
	ll x=0ll,y=0ll,q;
	for(i=0; i<n; ++i){
		used[i] = false;
		v.push_back(P(i,a[i]%g));
		v.push_back(P(i,a[i]%g-g));
	}
	sort(v.begin(),v.end(),comp);
	for(i=0; i<n*2; ++i){
		p = v[i].first;
		q = v[i].second;
		if(used[p]){
			if(q > 0){
				if(max(x+q,y-(g-q))<max(x,y)){
					x += q;
					y -= (g-q);
				}
			}else if(q < 0){
				if(max(x-(g+q),y-q)<max(x,y)){
					x -= (g+q);
					y -= q;
				}
			}
		}else{
			used[p] = true;
			if(q > 0){
				x += q;
			}else if(q < 0){
				y -= q;
			}
		}
	}
	v.clear();
	// cout << g << " " << x << " " << y << endl;
	return max(x,y)<=k;
}

int main(void){
	int i;
	ll s=0ll,p,q,ans=0ll;
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> a[i];
		s += a[i];
	}
	for(p=1ll; p*p<=s; ++p){
		if(s%p){
			continue;
		}
		q = s/p;
		if(check(p)){
			ans = max(ans,p);
		}
		if(check(q)){
			ans = max(ans,q);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 1e5 + 5;

int n, m, k;
vector<int> g[N];
int par[N], comp[N], deg[N];

int fs(int x) {
  return par[x] == x ? x : par[x] = fs(par[x]);
}

int main()
{
  cin >> n >> m >> k;
  for(int i = 0 ; i < n ; i++)
    par[i] = i, comp[i] = 1;
  for(int i = 0 ; i < m ; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    ++deg[a], ++deg[b];
    a = fs(a);
    b = fs(b);
    if(a != b) {
      par[a] = b;
      comp[b] += comp[a];
    }
  }
  for(int i = 0 ; i < k ; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].pb(b);
    swap(a, b);
    g[a].pb(b);
  }
  for(int i = 0 ; i < n ; i++) {
    int ans = comp[fs(i)] - 1 - deg[i];
    for(int j : g[i])
      if(fs(i) == fs(j))
        ans--;
    cout << ans << " ";
  }
  return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define ms(a,b)         memset(a, b, sizeof(a))
#define pb(a)           push_back(a)
#define db              double
#define ll              long long
#define loop(i,e,n)      for(int i=e;i<=n;i++)
#define TEST_CASE(t)    for(int z=1;z<=t;z++)
ll PowFun(ll base, ll power){ll ans = 1;for(int i = 1; i <= power; i++){ans *= base;}return ans;}
double phi = acos(-1);
using namespace std;

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

        int n; cin>>n;
        vector<int>vct;
        loop(i,1,n)
        {
            int x; cin>>x;
            vct.push_back(x);
        }

        sort(vct.rbegin(),vct.rend());
        ll counter = 0;
        loop(i,1,n-1) counter += vct[i/2];
        cout<<counter<<endl;
    }



Measured memory_bytes: 4284
import java.util.Scanner;

public class Main {

    private static int stamina(int x, int p) {
        return (x - p) * (x - p);
    }

    private static int minStamina(int[] xs) {
        int minP = 0;
        int maxP = 100;
        int min = Integer.MAX_VALUE;

        for (int p = minP; p <= maxP; p++) {
            int totalStamina = 0;

            for (int x : xs) {
                totalStamina += stamina(x, p);
            }

            min = Math.min(totalStamina, min);
        }

        return min;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] xs = new int[n];

        for (int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
        }

        System.out.println(minStamina(xs));
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> d(n);
   rep(i, 0, n) cin >> d[i];
   sort(all(d));
   int ans = d[n / 2] - d[n / 2 - 1];
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 640
//?????????????§£??????????????§IDA*?????????
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

typedef vector<int> Board;

const int INF=INT_MAX/3;
int dist[16][16];
Board goal(16);

int heuristic(Board &b){
	int S=0;
	for(int i=0;i<16;i++){
		if(b[i]!=0){
			S=S+dist[i][b[i]-1];
		}
	}
	return S;
}

void Adj(Board &u, vector<Board> &adj){
	int zero;
	for(int i=0;i<16;i++){
		if(u[i]==0){zero=i;}
	}

	if(zero<12){
		Board v(16);
		v=u;
		swap(v[zero],v[zero+4]);
		adj.push_back(v);
	}
	if(zero>3){
		Board v(16);
		v=u;
		swap(v[zero],v[zero-4]);
		adj.push_back(v);
	}
	if(zero%4 == 0 || zero%4 == 1 || zero%4 == 2){
		Board  v(16);
		v=u;
		swap(v[zero],v[zero+1]);
		adj.push_back(v);
	}
	if(zero%4 == 1 || zero%4 == 2 ||zero%4 == 3){
		Board v(16);
		v=u;
		swap(v[zero],v[zero-1]);
		adj.push_back(v);
	}
}

bool DLS(Board &b,Board &prev, int limit,int depth){
	if(b == goal){
		return true;
	}
	if(depth+heuristic(b)<=limit){
		vector<Board> adj;
		Adj(b,adj);
		for(int i=0;i<adj.size();i++){
			if(prev==adj[i]) continue;
			if(DLS(adj[i], b, limit, depth+1)==true){
				return true;
			}
		}
	}
	return false;
}

int IDDFS(Board &init){
	for (int limit=0; ; limit++){
		bool found = DLS(init,init, limit,0);
		if(found){
			return limit;
		}
	}
}

int main(){
	Board init(16);

	for(int i=0;i<16;i++){
		cin >> init[i] ;
	}

	/*
	int x[16]={1,6,7,2,5,10,12,3,0,14,13,8,9,15,11,4};
	for(int i=0;i<16;i++){
		init[i]=x[i]; 
	} 
	*/

	for(int i=0;i<15;i++){
		goal[i]=i+1; 
	}
	goal[15]=0;

	for(int i=0;i<16;i++){
		for (int j=0;j<16;j++){
			dist[i][j]=abs((i/4)-(j/4))+abs((i%4)-(j%4));
		}
	}

	cout << IDDFS(init) << endl;
	return 0;
}

Measured memory_bytes: 1244
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	string s;
	cin >> s;
	int min=1000;
	for(int i=2; i<s.size(); i++){
		string num="abc";
		num[0]=s[i-2];
		num[1]=s[i-1];
		num[2]=s[i];
		int n = stoi(num);
		if(abs(n-753)<min)
			min = abs(n-753);
	}
	cout << min << endl;
	return 0;
}

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

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

Measured memory_bytes: 256
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
signed main()
{
    fast;
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    a[1]--;
    for(int i=2;i<=n;i++)
    {
        if(a[i]-a[i-1]<0)
        {
            cout<<"No";
            return 0;
        }
        a[i] = max(a[i-1],a[i]-1);
    }
    cout<<"Yes";
}

Measured memory_bytes: 1024