akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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


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

	printf("%d\n",(A-1)*(B-1));
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	string t; cin >> t;
	int m=t.size();
	vector<string> s(n);
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		bool ok=true;
		for(int j=0;j<s[i].size();j++){
			for(int k=j+m-1;k<s[i].size();k++){
				if((k-j)%(m-1)!=0)continue;
				int l=(k-j)/(m-1);
				ok=true;
				for(int p=0;p<m;p++){
					if(s[i][j+p*l]!=t[p]){
						ok=false;
						break;
					}
				}
				if(ok){
					break;
				}
			}
			if(ok)break;
		}
		if(ok)ans++;
	}
	cout << ans << endl;
}


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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

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

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

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

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, p;
  cin >> n >> p;
  string s;
  cin >> s;

  if (p != 2 && p != 5)
  {
    reverse(all(s));
    ll csum[200010];
    csum[0] = 0;
    ll pow10 = 1;
    rep(i, n)
    {
      csum[i + 1] = (csum[i] + pow10 * (ll)(s[i] - '0')) % p;
      pow10 = pow10 * 10 % p;
    }

    ll cnt[10010] = {};
    rep(i, n + 1)
    {
      cnt[csum[i]]++;
    }
    ll ans = 0;
    rep(i, 10010)
    {
      ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans << endl;
  }
  else if (p == 2)
  {
    ll ans = 0;
    rep(i, n)
    {
      ll t = s[i] - '0';
      if (t % 2 == 0)
        ans += i + 1;
    }
    cout << ans << endl;
  }
  else
  {
    ll ans = 0;
    rep(i, n)
    {
      ll t = s[i] - '0';
      if (t % 5 == 0)
        ans += i + 1;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
typedef pair<int, int> ii;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e5 + 5;
int n, dp[50][N];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	//dp(i, j): Min sum of digits with i non - zero digits, mod j.
	memset(dp, 63, sizeof dp);
	dp[0][0] = 0;
	fw (i, 0, 45) {
		priority_queue<ii, vector<ii>, greater<ii>> pq;
		fw (j, 0, n + 1) if (dp[i][j] != inf) pq.push(ii(dp[i][j], j));
		while (!pq.empty()) {
			ii tmp = pq.top(); pq.pop();
			if (tmp.fi != dp[i][tmp.se]) continue;
			int nxtJ = tmp.se * 10 % n;
			if (dp[i][tmp.se] < dp[i][nxtJ]) {
				dp[i][nxtJ] = dp[i][tmp.se];
				pq.push(ii(dp[i][nxtJ], nxtJ));
			}
		}
		fw (j, 0, n + 1) {
			fw (nxtDigit, 1, 10) {
				int nxtJ = (j * 10 + nxtDigit) % n;
				dp[i + 1][nxtJ] = min(dp[i + 1][nxtJ], dp[i][j] + nxtDigit);
			}
		}
	}
	int ans = inf;
	fw (i, 1, 46) ans = min(ans, dp[i][0]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 21664
#include <cstdio>
#include <cstring>
#include <vector>
#include <tuple>

using namespace std;

int f1(int a) {
	if(a<2) {
		return 2-a;
	}
	return a & 1;
}
int f2(int a) {
	return (a ^ 1) & 1;
}

int main() {
	int N;
	scanf("%d", &N);
	long long st0 = 0;
	long long st1 = 0;
	long long st2 = 0;
	long long st3 = 0;
	long long st4 = 0;
	for(int n=0; n<N; ++n) {
		int a;
		scanf("%d", &a);
		long long bSt0 = st0;
		long long bSt1 = st1;
		long long bSt2 = st2;
		long long bSt3 = st3;
		long long bSt4 = st4;
		st0 = bSt0 + a;
		st1 = min(bSt0, bSt1) + f1(a);
		st2 = min(min(bSt0, bSt1), bSt2) + f2(a);
		st3 = min(min(bSt0, bSt1), min(bSt2, bSt3)) + f1(a);
		st4 = min(min(min(bSt0, bSt1), min(bSt2, bSt3)), bSt4) + a;
	}
	long long ret = min(min(min(st0, st1), min(st2, st3)), st4);
	printf("%lld\n", ret);

	return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int ls[20][100010];
int rs[20][100010];

int solve(int a, int b){
  int res = 0;
  for(int t=20-1;t>=0;--t){
	if(a < b){
	  if(rs[t][a] < b){
		res += 1<<t;
		a = rs[t][a];
	  }
	}
	else{
	  if(b < ls[t][a]){
		res += 1<<t;
		a = ls[t][a];
	  }
	}
  }

  return res+1;
}

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

  int N;
  cin >> N;
  VL xs(N);
  REP(i,N) cin >> xs[i];
  VL ds(N-1);
  REP(i,N-1) ds[i] = xs[i+1] - xs[i];
  LL L;
  cin >> L;

  VL acc(N);
  REP(i,N-1) acc[i+1] = acc[i] + ds[i];
  REP(i,N){
	rs[0][i] = upper_bound(ALL(acc), acc[i]+L) - begin(acc) - 1;
	ls[0][i] = max(0, (int)(lower_bound(ALL(acc), acc[i]-L) - begin(acc)));
  }

  REP(t,20-1){
	REP(i,N){
	  rs[t+1][i] = rs[t][rs[t][i]];
	  ls[t+1][i] = ls[t][ls[t][i]];
	}
  }

  int Q;
  cin >> Q;
  while(Q--){
	int a, b;
	cin >> a >> b;
	--a;
	--b;
	cout << solve(a, b) << endl;
  }

  return 0;
}


Measured memory_bytes: 18816
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef unsigned long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

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

int n;
string p="";
string q="";
int no =0;
int pno;
int qno;

void func(string s, int keta, vector<bool> use)
{
	if (keta == n)
	{
        no ++;
        if(s==p) pno=no;
		if(s==q) qno=no;
		return;
	}
 
	else
	{
		for (int i = 1; i <= n; i++)
		{
			if (!use[i])
			{
				vector<bool> use2 = use;
				use2[i] = true;
				
				
				func(s+to_string(i), keta + 1,use2);
 
 
			}
		}
	}
}
 

int main(void)
{


cin>>n;

rep(i,n)
{
int a;
cin>>a;
p+=to_string(a);
}

rep(i,n)
{
    int b;
    cin>>b;
    q+=to_string(b);
}

string s ="";

vector<bool> use(10);
func(s,0,use);

cout<<abs(pno-qno)<<endl;

}












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

#define PB push_back
#define all(a) (a.begin(), a.end())
#define REP(type,i, a, n) for ( type i = a; i < n; i++)

#define vi vector<int>
#define vii vector<pair<int, int> >
#define vl vector<long long>
#define vvi vector< vector<int> >

typedef long long ll;

// for debugging output uncomment below line 
// #define DBG
//NOTE : COMMNET ABOVE LINE BEFORE SUBMITTING

#ifdef DBG
	#define dout if(true) cout
	#define dfor if(true) REP
#else
	#define dout if(false) cout
	#define dfor if(false) REP
#endif


using namespace std;

void optimizeIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

//==================================================================================///////////////////
///                  CLASHER
//////////////==========================================================//////////////////////////////

int main() {
    optimizeIO();
    ll a,b;
    cin >> a >> b;
    double x = (a+b)/2.0;
    ll val = x;
    if(val == x){
        cout << val;
    }else{
        cout << "IMPOSSIBLE" ;
    }
    return 0;

}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main (String[] args)  {

		Scanner sc = new Scanner(System.in);
		long t1 = sc.nextLong();
		long t2 = sc.nextLong();
		long a1 = sc.nextLong();
		long a2 = sc.nextLong();
		long b1 = sc.nextLong();
		long b2 = sc.nextLong();
		
		long c1 = a1-b1;
		long c2 = a2-b2;

		long total = c1*t1+c2*t2;
		long mid = c1*t1;
		if (total==0) {
			System.out.println("infinity");

		} else if ((total>0 && mid>0) || (total<0 && mid<0)){
			System.out.println(0);

		} else if (mid%total==0){
			System.out.println(-mid/total*2);
		} else {
			System.out.println(-mid/total*2+1);
		}
	}

}




Measured memory_bytes: 24916
#include <stdio.h>

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


Measured memory_bytes: 2112
N = int(input().strip())
X = sorted([int(v) for v in input().strip().split()])

c = 100000000000000000
for p in range(X[0], X[-1] + 1):
    P = sum([pow(x - p, 2) for x in X])
    if P >= c:
        break
    c = P
print(c)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
	int a, b;
	char op;
	//scanf("%d %c %d", &a, &op, &b);
	//printf("%d %c %d", a, op, b);
	while(1){
	    scanf("%d %c %d", &a, &op, &b);
		if(op=='?'){
			break;
		}
		switch(op){
			case '+':
				printf("%d\n", a+b);
				break;
			case '-':
				printf("%d\n",a-b);
				break;
			case '*':
				printf("%d\n", a*b);
				break;
			case '/':
				printf("%d\n", a/b);
				break;
		}
	}
	return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=1;i<=n;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,c) for(__typeof(c.begin())i=c.begin();i!=(c).end();i++)
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
using namespace std;
int n;
vector<int> gr[100010];
int cnt[100010];
int frst;
vector<int> Root;
void dfs(int x,int y){
	cnt[x]=1;
	Root.push_back(x);
	if(x==n){
		frst=Root[(Root.size()+1)/2];
	}
	REP(i,gr[x].size()){
		if(gr[x][i]==y)continue;
		dfs(gr[x][i],x);
		cnt[x]+=cnt[gr[x][i]];
	}
	Root.erase(Root.begin()+Root.size()-1);
}
int main(){
	cin>>n;
	REP(i,n-1){
		int a,b;
		cin>>a>>b;
		gr[a].push_back(b);
		gr[b].push_back(a);
	}
	frst=-1;
	dfs(1,1);
	if(cnt[frst]*2<n){
		cout<<"Fennec"<<endl;
	}
	else{
		cout<<"Snuke"<<endl;
	}
	return 0;
}

Measured memory_bytes: 11256
#pragma region 宣言部分
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;

#pragma endregion



int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    ll a[n] = {};
    ll b[m] = {};
    REP(i,n){
        ll x;
        cin >> x;
        if(i == 0)
            a[i] = x;
        else{
            a[i] = a[i-1] + x;
        }
    }
    REP(i,m){
        ll x;
        cin >> x;
        if(i == 0)
            b[i] = x;
        else{
            b[i] = b[i-1] + x;
        }
    }
    ll res = 0;
    REP(i,n){
        if(a[i] > k){
            continue;
        }
        ll key = k - a[i];
        ll itr = lower_bound(b, b + m, key) - b;   
        //cout << itr << endl;
        if(b[itr] == key){
            res = max(res, i+1 + itr+1);
        }else{
            res = max(res, i+1 + itr);
        }
    }
    REP(i,m){
        if(b[i] > k){
            continue;
        }
        ll key = k - b[i];
        ll itr = lower_bound(a, a + n, key) - a;   
        //cout << itr << endl;
        if(a[itr] == key){
            res = max(res, i+1 + itr+1);
        }else{
            res = max(res, i+1 + itr);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6712
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Q = sc.nextInt();
        long[] A = new long[Q+1];
        long[] B = new long[Q+1];
        for(int i=1;i<=Q;i++){
            long num1 = sc.nextLong();
            long num2 = sc.nextLong();
            A[i] = Math.min(num1,num2);
            B[i] = Math.max(num1,num2);
        }
        for(int i=1;i<=Q;i++){
            if(A[i]==B[i]){
                System.out.println(2*(A[i]-1));
                continue;
            }
            long ans1 = (A[i]-1)*2;
            long ans2 = 0;
            if(B[i]-A[i]<2) System.out.println(ans1);
            else{
                long upper = A[i]*B[i];
                long mid = (long) Math.floor(Math.sqrt(upper));
                while(mid*mid>=upper) mid--;
                if(mid==A[i]) ans2 = 1;
                else{
                    ans2 += 2*(mid-A[i]+1)-1;
                    if(mid*(mid+1)>=upper) ans2--;

                }
                System.out.println(ans2+ans1);
            }
        }
    }
}




Measured memory_bytes: 20948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long X = sc.nextLong();
		long T = sc.nextLong();
		sc.close();

		long temp = (N / X);
		temp = N % X == 0 ? temp : temp + 1;
		System.out.println(temp * T);

	}

}


Measured memory_bytes: 35684
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b,ans=0;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      ans=1;
      break;
    }
  }
  if(ans==1) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}

Measured memory_bytes: 3636
n = int(input())
a = [list(input()) for i in range(n)]
cntr, cntc = [i.count(".") for i in a], [i.count(".") for i in zip(*a)]
if sum(cntr) == 0:
    exit(print(0))
if sum(cntr) == n * n:
    exit(print(-1))
if any(i == 0 for i in cntr):
    cnt = 0
    for i in cntc:
        cnt += 1 if i > 0 else 0
    exit(print(cnt))
cnt2 = 0
ans = float("inf")
for i in cntc:
    cnt2 += 1 if i > 0 else 0
for i in range(n):
    ans = min(ans, cntr[i] + cnt2 + 1) if cntc[i] == n else min(ans, cntr[i] + cnt2)
print(ans)

Measured memory_bytes: 11200
fun main() {
    val N = readLine()!!.toInt()
    val AN = mutableMapOf<Int, Long>()

    readLine()!!.split(" ").map(String::toInt).forEach {
        AN.compute(it) { k, v -> (v ?: 0) + 1 }
    }
    val Q = readLine()!!.toInt()
    val BCN: Array<Pair<Int, Int>> = Array(Q) { readLine()!!.split(" ").map(String::toInt).let { it[0] to it[1] } }


    var sum = 0L
    AN.toList().forEach { (k, v) -> sum += k * v }
    for ((B, C) in BCN) {
        val CC = AN.getOrElse(C, { 0 })
        val BC = AN.getOrElse(B, { 0 })
        AN.remove(B)
        AN.put(C, CC + BC)
        sum = sum - (BC * B) + (BC * C)
        println(sum)
    }

}

Measured memory_bytes: 76196
##### ABC 160
K,N = map(int, input().split())
A = list(map(int,input().split()))


dist = []
for i in range(N-1):
    dist.append(A[i+1]-A[i])
    
dist.append(K-A[-1]+A[0])

dist.sort()

ans = 0
for i in range(N-1):
    ans += dist[i]
    
print(ans)

Measured memory_bytes: 102428
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

ll f(ll num,ll m){
  ll a=num/m*m;
  ll b=a+m;
  if(num-a<b-num)return -(num-a);
  else return b-num;
}

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

void solve(){
  ll n,k;cin>>n>>k;
  vector<pair<ll,ll>>v(n);
  rep(i,n){
    cin>>v[i].second;
  }
  ll ans=0;
  ll sum=0;
  rep(i,n)sum+=v[i].second;
  auto d=divisor(sum);
  for(auto&&num:d){
    //cout<<num<<endl;
    rep(i,n){
      v[i].first=abs(v[i].second%num);
    }
    sort(all(v));

    vector<ll>a(n);
    rep(i,n){
      a[i]=v[i].first;
    }
    vector<ll>p(n+1,0);
    vector<ll>q(n+1,0);
    rep(i,n)p[i+1]=p[i]+a[i];
    reverse(all(a));
    rep(i,n)q[i+1]=q[i]+(num-a[i]);
    ll count=INF;
    rep(i,n+1)count=min(count,max(p[i],q[n-i]));
    //cout<<"num="<<num<<" "<<count<<endl;
    if(count<=k)ans=max(ans,num);    
  }
  cout<<ans<<endl;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);cout<<fixed;
  cout<<setprecision(30);
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100010];
int main(){
	char ch;
    int i=0,ans=0,l=0;
    while((ch=getchar())!='\n'){
        a[i++]=ch;
        l++;
    }
    a[i]='\0';
    for(int j=0;j<l-1;j++){
    	if(a[j]!=a[j+1])ans++;
	}
	cout<<ans;
	return 0;
}

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

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h,w;
    map<ll,ll>x,y;
    cin>>h>>w;
    char l1[h+1][w+1];
    for(int i=1;i<=h;i++){ll a=0,b=0;
        for(int j=1;j<=w;j++){
            cin>>l1[i][j];
            if(l1[i][j]=='.')x[i]++,y[j]++;
        }
    }
    for(int i=1;i<=h;i++){ll a=0,b=0;
        for(int j=1;j<=w;j++){
            if(x[i]==w)break;
            if(y[j]!=h)cout<<l1[i][j];
        }if(x[i]!=w)cout<<endl;
    }
}


Measured memory_bytes: 3644
from heapq import heappush, heappop
def dijkstra(n, graph, s):
    dist = [float('inf')] * n
    from_v = [-1] * n
    hq = [(0, s)]
    dist[s] = 0
    while hq:
        c, v = heappop(hq)
        if dist[v] < c:
            continue
        for t, cost in graph[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                from_v[t] = v
                heappush(hq, (dist[t], t))
    return dist, from_v

def main():
    import sys
    input = sys.stdin.readline
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append((b,1))
        graph[b].append((a,1))
    dist, from_v = dijkstra(N, graph, 0)
    if float("inf") in dist:
        print("No")
        sys.exit()
    else:
        print("Yes")
        for ans in from_v[1:]:
            print(ans+1)

if __name__ == '__main__':
    main()

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

int main() {
  int64_t Q=1000000007,A=1,N,Z=0;
  cin>>N;
  vector<int64_t> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  for(int j=0;j<70;j++){
    int64_t M=0;
    for(int i=0;i<N;i++){
      if(p[i]%2==0){
        M++;
      }
      p[i]/=2;
    }
    Z=(Z+((M*(N-M))%Q)*A)%Q;
    A=(A*2)%Q;
  }
  cout<<Z<<endl;
}



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll arr[61];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        arr[a]+=1;
        arr[b]+=1;
    }
    for(ll i=1;i<=n;i++){
        cout<<arr[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int gcd(int A, int B) {
	if (A % B == 0) return B;
	return gcd(B, A % B);
}

int main() {
	int N = getint();
	int A[100000];
	rep(i, N) A[i] = getint();

	int B[100000];
	B[0] = A[0];
	rep1(i, N - 2) B[i] = gcd(A[i], B[i - 1]);

	int kotae = B[N - 2];
	int C = A[N - 1];
	rep1(i, N - 2) {
		kotae = max(kotae, gcd(C, B[N - 2 - i]));
		C = gcd(A[N - i - 1], C);
	}
	kotae = max(C, kotae);

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i=0; i<n1; i++) L[i] = A[left + i];
	for(int i=0; i<n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		cnt++;
		
		if(L[i] <= R[j]){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[], int n, int left, int right){
	if(left+1 < right){
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int main(){
	int A[MAX], n, i;
	cnt = 0;
	
	cin >> n;
	for(i=0; i<n; i++)cin >> A[i];
	
	mergeSort(A, n, 0, n);
	
	for(i=0; i<n; i++){
		if( i )cout << " ";
		cout << A[i];
	}
	cout << endl;
	
	cout << cnt << endl;
	
	return 0;
}



Measured memory_bytes: 6900
c=[list(map(int,input().split())) for j in range(3)]
if c[0][0]+c[1][1]+c[2][2]==c[0][1]+c[1][2]+c[2][0] and c[0][0]+c[1][1]+c[2][2]==c[0][2]+c[1][0]+c[2][1] and c[0][0]+c[1][1]+c[2][2]==c[0][2]+c[1][1]+c[2][0]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9212
lst = [int(i) for i in input().split()]
ball = lst[0]
blue = lst[1]
red = lst[2]

red_blue = int(ball / (red + blue))
shokichi = red_blue * blue
amari = ball - (red_blue * (red + blue))

if amari < blue:
    nokori = amari
elif amari > blue:
    nokori = blue
else:
    nokori = 0

if blue == 0:
    print(0)
else:
    print(shokichi + nokori)

Measured memory_bytes: 3064
#include<stdio.h>
#define k 10000

int main()
{
  int C[k+1];
  int i,j,n;

  scanf("%d",&n);

  int A[n+1];
  int B[n+1];


  for(i=0; i<=k; i++){
    C[i] = 0;
  }
  
  for(i=0; i<n; i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }
  
  for(i=1; i<=k; i++){
    C[i] = C[i] + C[i-1];
  }
  
  for(j=n; j>0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for(i=1; i<=n-1; i++){
    printf("%d ",B[i]);
  }
  
  printf("%d\n",B[i]);
  
  return 0;
}




Measured memory_bytes: 18280
using System;
using System.Linq;
using System.Collections.Generic;
class AC
{
    static void Main(string[] args)
    {
        var N = Cin.Int();
        const int mod = 1000000007;
        var dp = new long[N + 1, 2, 2];//dp[i,j,k]:=i 番目の値まで決めて、0を含むかどうか(j)、9を含むかどうか(k)
        dp[0, 0, 0] = 1;
        for(var i = 0; i < N; i++)
        {
            for(var j = 0; j < 2; j++)
            {
                for(var k = 0; k < 2; k++)
                {
                    dp[i + 1, j, k] = (dp[i + 1, j, k] + dp[i, j, k] * 8) % mod;
                    dp[i + 1, 1, k] = (dp[i + 1, 1, k] + dp[i, j, k]) % mod;
                    dp[i + 1, j, 1] = (dp[i + 1, j, 1] + dp[i, j, k]) % mod;
                }
            }
        }
        Console.WriteLine(dp[N, 1, 1]);
    }
}
static class Cin
{
    public static string Str() => Console.ReadLine();
    public static int Int() => int.Parse(Cin.Str());
    public static long Long() => long.Parse(Cin.Str());
    public static double Double() => double.Parse(Cin.Str());

    private static T Conv<T>(string value) => (T)Convert.ChangeType(value, typeof(T));
    public static (T, U) ReadTuple<T, U>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]));
    public static (T, U, V) ReadTuple<T, U, V>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]));
    public static (T, U, V, W) ReadTuple<T, U, V, W>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]), Conv<W>(input[3]));
    public static (T, U, V, W, X) ReadTuple<T, U, V, W, X>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]), Conv<W>(input[3]), Conv<X>(input[4]));

    public static (T, U) Input<T, U>() => ReadTuple<T, U>(ReadSplit());
    public static (T, U, V) Input<T, U, V>() => ReadTuple<T, U, V>(ReadSplit());
    public static (T, U, V, W) Input<T, U, V, W>() => ReadTuple<T, U, V, W>(ReadSplit());
    public static (T, U, V, W, X) Input<T, U, V, W, X>() => ReadTuple<T, U, V, W, X>(ReadSplit());

    public static string[] ReadSplit() => Console.ReadLine().Split();
    public static string[] ReadSplit(char separator) => Console.ReadLine().Split(separator);
    public static int[] ReadSplitInt() => Array.ConvertAll(ReadSplit(), int.Parse);
    public static long[] ReadSplitLong() => Array.ConvertAll(ReadSplit(), long.Parse);
    public static double[] ReadSplit_Double() => Array.ConvertAll(ReadSplit(), double.Parse);
}


Measured memory_bytes: 58760
#include <stdio.h>
int main(void){
    // Here your code !
    int i,j;
    for(i=1;i<=9;i++){
        for(j=1;j<=9;j++){
            printf("%dx%d=%d\n",i,j,i*j);
            
        }
    }
    return 0;
}

Measured memory_bytes: 1760
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int main() {

	int N;

	scanf("%d", &N);

	int l = 0, m, r = N;
	const int Male = 0, Female = 1;
	int ls, ms, rs;
	char str[16];

	cout << 0 << endl;
	scanf("%s", str);
	if (str[0] == 'V') return 0;
	if (str[0] == 'M') {
		ls = Male;
		rs = Male;
	}
	else {
		ls = Female;
		rs = Female;
	}

	for (;;) {
		m = (l + r) / 2;
		cout << m << endl;
		scanf("%s", str);
		if (str[0] == 'V') return 0;
		if (str[0] == 'M') {
			ms = Male;
		}
		else {
			ms = Female;
		}

		if (((m - l) % 2 && ms^ls) || (!((m - l) % 2) && ms == ls)) {
			l = m;
			ls = ms;
		}
		else {
			r = m;
			rs = ms;
		}
	}

	return 0;
}


Measured memory_bytes: 852
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

string s;

int main(){
    cin >> s;
    if (s[0] == 'S')
        printf("Cloudy\n");
    else if (s[0] == 'C')
        printf("Rainy\n");
    else if (s[0] == 'R')
        printf("Sunny\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
 
#define rep(i, n) for(i = 0;i < n;++i)
 
int main(void){
  int i, j;
  int n, sum = 0;
  string s;
  bool fl = true;
  cin >> n;
 
  rep(i, n){
    cin >> s;
    if(s == "A")sum++;
    else --sum;
    if(sum < 0){ fl = false; break; }
  }
  if(sum > 0)fl = false;
 
  puts(fl ? "YES" : "NO");
 
  return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	vector<int> list(N);
	for (int i = 0; i < N; i++)
	{
		int v;
		cin >> v;

		list[i] = v;
	}

	for (int i = 0; i < N; i++)
	{
		int c;
		cin >> c;

		list[i] -= c;
	}

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

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (list[i] > 0)
		{
			ans += list[i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3

import sys


def main():
    while True:
        m, f, r = [int(score) for score in sys.stdin.readline().split()]

        if m == f == r == -1:
            break
        if m == -1 or f == -1 or m+f < 30:
            print('F')
        elif m+f >= 80:
            print('A')
        elif 80 > m+f >= 65:
            print('B')
        elif 65 > m+f >= 50:
            print('C')
        elif 50 > m+f >= 30:
            if r >= 50:
                print('C')
            else:
                print('D')


if __name__ == '__main__':
    main()

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


int main(){

    int N;
    cin >> N;
    if(N==1){
        cout << 1 << endl;
    }else if(N%2==0){
        cout << (double)0.5 << endl;
    }else{
        cout << (double)(N+1)/2/N << endl;
    }
    return 0;
}

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


int main(){
  long long int mod = 1000000007;
  long long int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(auto& a : A){
    cin >> a;
  }

  long long int ans_0 = 0;
  for(int ii=0; ii<N; ii++){
    for(int jj=ii+1; jj<N; jj++){
      if(A[ii] > A[jj]){
        ans_0++;
        ans_0 %= mod;
      }
    }
  }

  long long int ans_1 = 0;
  for(int ii=0; ii<N; ii++){
    for(int jj=0; jj<N; jj++){
      if(A[ii] > A[jj]){
        ans_1++;
        ans_1 %= mod;
      }
    }
  }

  long long int ans = (ans_0 * K % mod + K * (K-1)/2 % mod * ans_1 % mod) % mod;;

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


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vector<int>>;
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"YES",0;
#define retn return cout<<"NO",0;
#define fl fflush(stdout)   
#define hell 1000000007  
#define hell2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=b*d;
    ans=max({ans,c*a,c*b,d*a,d*b});
    if((a<=0&&b>=0)||(c<=0&&d>=0))ans=max(ans,0LL);
    cout<<ans;
    return 0;
}

signed main(){
    auto start = high_resolution_clock::now();
    IOS;
    int t=1;

    while(t--){
        solve();
        cout<<"\n";
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr<<"Time taken:"<<duration.count()/1000000.0<<"seconds"<<"\n";
    return 0;
} 

Measured memory_bytes: 3796
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
int main()
{
    char a;
    scanf("%c",&a);
    int b=a;
    b=b+1;
    printf("%c\n",b);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = 0;
        if(n % 2 == 0) {
            a = n / 2;
        } else {
            a = n / 2 +1;
        }
        double ans =  (double)a / (double)n;
        System.out.println(ans);
    }
}

Measured memory_bytes: 36060
#include <iostream>
#include <map>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int a[60], b[60];
  for(int i = 0; i < M; i++){
    cin >> a[i] >> b[i];
  }
  map<int,int> ans;
  for(int i = 0; i < M; i++){
    ans[a[i]-1] = ans[a[i]-1] + 1;
    ans[b[i]-1] = ans[b[i]-1] + 1;
  }

  for(int i = 0; i < N; i++){
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# N, M = map(int, input().split())
# A = []
# for i in range(N):
#     a = list(map(int, input().split()))
#     A.append(a)
# A = sorted(A)
#
# count = 0
# cost = 0
#
# i = 0
# while count < M:
#     cost += A[i][0] * min(A[i][0], M-count)     # 買う予定の本数に満たしたかどうかをmin()で判断
#     count += min(A[i][0], M-count)              # 上と同じくmin()で判断
#     i += 1
#
# print(cost)

N, M = map(int, input().split())

A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)

A = sorted(A)

count = 1
b = 0
cost = 0
for i in range(M):
    if i == M:
        break

    cost += A[b][0]

    if count == A[b][1]:
        count = 1
        b += 1
    else:
        count += 1


print(cost)




Measured memory_bytes: 28656
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc075/tasks/abc075_c

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline



def solve(es, degrees, N, M):
    bridge = 0
    Q = []

    for i in range(1, N+1):
        if degrees[i] == 1:
            Q.append(i)

    while Q:
        u = Q.pop()
        bridge += 1
        for e in es[u]:
            degrees[e] -= 1
            if degrees[e] == 1:
                Q.append(e)

    return bridge



def main(args):
    N, M = map(int, input().split())

    degrees = [0] * (N + 1)
    es = [[] for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        es[a].append(b)
        es[b].append(a)
        degrees[a] += 1
        degrees[b] += 1

    result = solve(es, degrees, N, M)
    print(min(result, M))



if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define all(e) e.begin(), e.end()
#define vi vector<int>
#define vd vector<double>
#define ret return 0;

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

typedef long long ll;
typedef unsigned long long ull;

const int INF = ~(1 << 31);

using namespace std;

int a = 100001;

int num[100001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;

    if(n == 1){
        if(m == 1){
            cout << 1 << endl;
            ret;
        }else{
            cout << m - 2 << endl;
            ret;
        }
    }
    if(m == 1){
        if(n == 1){
            cout << 1 << endl;
            ret;
        }else{
            cout << n - 2 << endl;
            ret;
        }
    }

    cout << (n - 2) * (m - 2) << endl;

    return 0;
}

Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            int[] A = new int[n];
            string[] numbers = Console.ReadLine().Split(' ');
            int[] N_O_N = new int[n];
            for (int c = 0; c < n; c++)
            {
                A[c] = Int32.Parse(numbers[c]);
            }

            Array.Sort(A);
            int first = A[0];
            int prev = A[0];
            int counter2 = 0;
            for (int c = 0; c < n; c++)
            {
                if (A[c] != prev)
                {
                    counter2++;
                }
                N_O_N[counter2]++;
                prev = A[c];
                /*いっことってきて
                 * まえのとちがったら
                 * ひとつNONのなかのカウンタをすすめて
                 * else
                 * ふやす
                 * prevにいれる
                 * */

            }
            /*このネーミングセンス、とてもプログラマーっぽくない*/
            //counter2+1種類のカードが山札に有るよ
            int two_counter = 0 ;
            for (int c = 0; c < counter2 + 1; c++)
            {
                //3を1に、4を2にするので、%2で1,0、1引いて0,-1、ABSとって0,1、1を足すと
                if (N_O_N[c] >= 3) N_O_N[c] = Math.Abs((N_O_N[c] % 2 - 1))+1;
                if (N_O_N[c] == 2) two_counter++;

            }
            Console.WriteLine(counter2 + 1 - two_counter%2);

            
        }
    }
}


Measured memory_bytes: 10200
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[100005] = {0},n,m;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> m;
        a[m]++;
    }
    int ans = 0,b;
    for(int i = 0; i < 100000; i++){
        b = a[i] + a[i+1] + a[i+2];
        if(ans < b){
            ans = b;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int mod = 1000000007;

int64_t gcd(int64_t p, int64_t q)
{
    if (p < q)
        swap(p, q);

    if (p % q == 0)
        return q;
    else
        return gcd(q, p % q);
}

int main()
{
    int64_t A, B;
    cin >> A >> B;
    cout << A * B / gcd(A, B);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    sort(all(v));
    double ans = v[0];
    rep(i, n-1){
        ans = (ans+v[i+1])/2.;

    }
    cout << decimal << ans << endl;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
  long long int h, w;
  cin >> h >> w;
  long long int ans;
  if (h%3==0 || w%3==0) ans = 0;
  else {
    ans = (w-(w/3)*2)*h - h*(w/3);
    for (long long int i = 1; i < w-1; i++) {
      long long int s[3] = {h*i, h*((w-i)/2), h*(w-i-(w-i)/2)};
      sort(s,s+3);
      if (s[2]-s[0]<ans) ans = s[2]-s[0];
    }
    for (long long int i = 1; i < h-1; i++) {
      long long int s[3] = {w*i, w*((h-i)/2), w*(h-i-(h-i)/2)};
      sort(s,s+3);
      if (s[2]-s[0]<ans) ans = s[2]-s[0];
    }
    for (long long int i = 1; i < w; i++) {
      long long int s[3];
      s[0] = i*h, s[1]=(w-i)*(h/2), s[2]=(w-i)*(h-(h/2));
      sort(s,s+3);
      if (s[2]-s[0]<ans) ans = s[2]-s[0];
    }
    for (long long int i = 1; i < h; i++) {
      long long int s[3];
      s[0] = i*w, s[1]=(h-i)*(w/2), s[2]=(h-i)*(w-(w/2));
      sort(s,s+3);
      if (s[2]-s[0]<ans) ans = s[2]-s[0];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{


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

		
		System.out.println(24+(24-N));


	}
}
class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n;
  int a[200000], inv[200000];
  std::set<int> s;
  long long ans = 0;
  std::cin >> n;
  for (int ni = 0; ni < n; ++ni) {
    std::cin >> a[ni];
    inv[a[ni] - 1] = ni;
  }
  for (int ni = 0; ni < n; ++ni) {
    auto pos = s.insert(inv[ni]).first;
    long long begin, end;
    if (pos == s.begin()) {
      begin = 0;
    } else {
      begin = *std::prev(pos) + 1;
    }
    if (std::next(pos) == s.end()) {
      end = n;
    } else {
      end = *std::next(pos);
    }
    ans += ((end - begin) * (end - begin + 1)
            - (inv[ni] - begin) * (inv[ni] - begin + 1)
            - (end - inv[ni] - 1) * (end - inv[ni])) / 2 * (ni + 1);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 11768
import java.util.*;

public class Main {
    public static long[] buildValues(int d) {
        long[] res = new long[d/2];
        long high = (long) Math.pow(10, d - 1);
        long low = 1L;
        for (int i = 0; i < d / 2; i++) {
            res[i] = high - low;
            high /= 10;
            low *= 10;
        }

        return res;
    }

    public static long calc(long[] vs, long D) {
        long res = 1;
        long ten = 10;
        for (int i = 0; i < vs.length; i++) {
            long now = 0;
            while (D % ten != 0 && now < 9) {
                D -= vs[i];
                now++;
            }
            D = Math.abs(D);
            ten *= 10;
            res *= (i == 0) ? (9 - now) : (10 - now);
        }
        return D == 0 ? res : 0;
    }

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

        long res = 0;
        for (int d = 1; d <= 20; d++) {
            long[] vs = buildValues(d);
            long next = calc(vs, D);
            if (d % 2 == 1) next *= 10;
            res += next;
        }
        System.out.println(res);
    }
    /*
    a = 10x + y
    b = 10y + x
    a - b = 9x - 9y = 9(x - y)

    a = 100x + 10y + z
    b = 100z + 10y + x
    a - b = 99x - 99z = 99(x - z) + 0y

    a = 1000x + 100y + 10z + w
    b = 1000w + 100z + 10y + x
    a - b = 999x - 999w + 90y - 90z = 999(x - w) + 90(y - z)

    a = 10000x + 1000y + 100z + 10w + v
    b = 10000v + 1000w + 100z + 10y + x
    a - b = 9999(x - v) + 990(y - w) + 0z

    a = 100000x + 10000y + 1000z + 100w + 10v + u
    b = 100000u + 10000v + 1000w + 100z + 10y + x
    a - b = 99999(x - u) + 9990(y - v) + 900(z - w)
    */
    static int rev(int x) {
        String s = "0";
        while (x > 0) {
            s += x % 10 + "";
            x /= 10;
        }
        return Integer.valueOf(s);
    }
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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 NM = 1e5+10;
map<pair<ll, ll>, ll> dist;
vector<ll> tree[NM];

bool isexist(ll a, ll b){
    if(a>b) swap(a,b);
    if(dist[make_pair(a,b)] != 0) return true;
    else return false;
}

ll get_dist(ll a, ll b){
    if(a>b) swap(a,b);
    return dist[make_pair(a,b)];
}

void reg(int a, int b, int d){
    if(a>b) swap(a,b);
    dist[make_pair(a,b)] = d;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    for(ll i=1; i<=n-1; i++){
        ll a,b,c;cin>>a>>b>>c;
        tree[a].push_back(b);
        tree[b].push_back(a);
        reg(a,b,c);
    }
    ll q, k; cin>>q>>k;
    vector<P> query(q);
    for(ll i=0; i<q; i++){
        cin>>query[i].first>>query[i].second;
    }
    // 幅優先探索
    queue<P> qu;
    qu.push(make_pair(k, 0));
    ll ad[NM] = {-1};
    for(ll i=0; i<NM; i++){
        ad[i] = -1;
    }
    ad[k] = 0;
    while(!qu.empty()){
        ll top = qu.front().first; 
        ll now = qu.front().second;
        qu.pop();
        for(ll t : tree[top]){
            if(ad[t] != -1) continue;
            ad[t] = now+get_dist(top, t);
            qu.push(make_pair(t, ad[t]));
        }
    }
    for(auto t : query){
        cout<< (ll)ad[t.first] + (ll)ad[t.second] <<'\n';
    }

}


Measured memory_bytes: 17780