akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
void dumparr(vector<int>s){
  rep(i,s.size()){
    cout << s[i];
    if(s.size()-1 != i)cout << " ";
  }
  cout << endl;
}
int main(){
  int n,q; cin >> n >> q;
  vector<int> arr[n+1];
  rep(i,q){
    int quen,t;cin>>quen>>t;
    if(quen == 0){
      int x;cin>>x;
      arr[t].push_back(x);
    }else if(quen == 1){
      dumparr(arr[t]);
    }else{
      arr[t].clear();
    }
  }
  return 0;
}


Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x,y,z,k;cin >>x>>y>>z>>k;
  vector<long long> a(x),b(y),c(z),ab,abc;
  for (int i=0;i<x;i++) cin >> a[i];
  for (int i=0;i<y;i++) cin >> b[i];
  for (int i=0;i<z;i++) cin >> c[i];
  for (int i=0;i<x;i++) {
    for (int j=0;j<y;j++) {
	  ab.push_back(a[i]+b[j]);
	}
  }
  sort(ab.begin(),ab.end());
  reverse(ab.begin(),ab.end());
  for (int i=0;i<min(x*y,k);i++) {
    for (int j=0;j<z;j++) {
	  abc.push_back(ab[i]+c[j]);
	}
  }
  sort(abc.begin(),abc.end());
  reverse(abc.begin(),abc.end());
  for (int i=0;i<k;i++) cout << abc[i] << endl;
}

Measured memory_bytes: 43368
///God is great

#include <bits/stdc++.h>
using namespace std;

/************************** definations *******************************/
#define pi              2*acos(0.0)
#define ll              long long int
#define llu             unsigned long long int
#define sc(a)           scanf("%d",&a)
#define scc(a,b)        scanf("%d %d",&a,&b)
#define sccc(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sc1(a)          scanf("%lld",&a)
#define sc2(a,b)        scanf("%lld %lld",&a,&b)
#define sc3(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define sc4(a,b,c,d)    scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define pf1(a)          printf("%lld\n",a)
#define pf2(a,b)        printf("%lld %lld\n",a,b)
#define Case(a)         printf("Case %d: ",a)
#define Casel(a)        printf("Case %lld: ",a)
#define mem(a,x)        memset(a,x,sizeof(a))
#define INF             1<<29
#define Inf             10000
#define inf             INT_MAX
#define INFL            1e18
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair
#define NL              cout << endl;
#define DONE            cerr << "Done" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << endl
#define READ            freopen("input.txt", "r", stdin)
#define WRITE           freopen("output.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pii             pair<int,int>
#define ii              pair<ll,int>
#define M               10000007
#define mod             100000007
#define Mod             1000000007
#define MAX             1001
#define qk              5000000
#define REP(i,x,m)      for(i=x;i<m;i++)
#define vi              vector<int>
/************************** definations *******************************/
int main()
{
    /*#ifndef ONLINE_JUDGE
    READ;
    WRITE;
    #endif*/
    int i,n,m,a[111],k=0;
    double sum=0;
    scc(n,m);
    REP(i,0,n){
        sc(a[i]);
        sum+=a[i];
    }
    //sort(a,a+111);
    double as = (double)(sum/(4*m));
    REP(i,0,n) 
        if(a[i]>=as) k++;
    //cout << sum << " " << as << " " << k << " ";
    if(k>=m) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
void fnc(ll n,bool (&x)[50]){
    if(n%4==1||n%4==2)x[0]=1;
    else x[0]=0;
    n/=2;
    for(int i=1;n>0;i++){
        x[i]=n%2;
        n/=2;
    }
}
int main(){
    ll a,b;cin>>a>>b;

    bool a_[50],b_[50];
    rep(i,50)a_[i]=b_[i]=0;
    if(a==0){
        fnc(b,b_);
        ll ans=0;
        rep(i,50){
            if(b_[i])ans+=pow(2,i);
        }
        cout<<ans<<endl;
            return 0;
    }

    a--;
    fnc(a,a_);
    fnc(b,b_);
    rep(i,49){
        if(a_[i+1])a_[i+1]=(a+1)%2;
        if(b_[i+1])b_[i+1]=(b+1)%2;
    }
    ll ans=0;
    rep(i,50){
        if((a_[i]==0&&b_[i]==1)||(a_[i]==1&&b_[i]==0))ans+=pow(2,i);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)
#define debug(x) cerr << #x << ": " << x << "\n";

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

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

  bool tl;
  while(1){
    C -= B;
    if(C<=0){
      tl = true;
      break;
    }
    A -= D;
    if(A<=0){
      tl = false;
      break;
    }
  }
  if(tl) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, A;
    cin >> N >> A;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    
    vector<vector<ll>> dp(51, vector<ll>(2501, 0));
    dp[0][0] = 1;
    for(int x: X){
        for(int i = 49; i >= 0; i--){
            rep(j, 2501){
                if(j + x < 2501) dp[i + 1][j + x] += dp[i][j];
            }
        }
    }
    
    ll ret = 0;
    repd(i, 1, 51){
        ret += dp[i][i * A];
    }
    
    output(ret, 0);
    return 0;
}

Measured memory_bytes: 1280
K, A, B = map(int, input().split())

need_turns = A + 1 + 1  # 交換に必要なターン
first_need_turns = need_turns - 1

if A + 2 > B or K < first_need_turns:  # 交換せずにビスケットを叩き続ける方が得
    print(1 + K)
    exit()

ans = B  # 一度交換した
K -= (need_turns - 1)

# print("{}, {}".format(K, ans))

while K > 0:
    if ans >= A and K >= 2:
        ans += (B - A) * int(K / 2)
        K = K % 2
    else:
        ans += 1
        K -= 1

print(ans)


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	static int max = 1000001;
	static int simentai(int n){
		return n*(n+1)*(n+2)/6;
	}
	public static void main(String[] args) {
		List<Integer> data = new ArrayList<Integer>();
		for(int i=0;simentai(i)<max;i++){
			data.add(simentai(i));
			if(data.get(i)>max)break;
		}
		int num[]=new int[max];
		for(int i=0;i<max;i++)num[i]=i;//初期化(四面体が全て1の場合にしておく)
		for(int i=2;i<data.size();i++){//四面体の数だけ進める。
			for(int s=0;s<max;s++){//0からひとつずつ進める。
				if(s-data.get(i)<0)continue;
				int test=num[s-data.get(i)]+1;//四面体数ぶん前に戻ってその通り方+1(今回の)
				num[s]=Math.min(test,num[s]);
			}
		}
		int kisuu[] = new int[max];
		for(int i=0;i<max;i++)kisuu[i]=i;//初期化
		for(int i=2;i<data.size();i++){
			if(data.get(i)%2==0)continue;//偶数ならはじく
			for(int s=0;s<max;s++){
				if(s-data.get(i)<0)continue;
				int test = kisuu[s-data.get(i)]+1;
				if(s==5)System.out.println(kisuu[s]+" or "+test+" "+i);
				kisuu[s]=Math.min(kisuu[s], test);
			}
		}
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n==0)break;
			System.out.println(num[n]+" "+kisuu[n]);
		}
	}
}

Measured memory_bytes: 30728
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n,m,d;

int main(){
    read3i(n,m,d);
    int c = d ? 2 : 1;
    printf("%.9f", (m - 1.0) * (c * (n - d)) / (1ll * n * n));
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    if(n%10==3)
    {
        cout << "bon" << endl;
    }           
    else if(n%10==0 || n%10==1 || n%10==6 || n%10==8)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
    
}

Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;


int main(){
   string S;
   cin >> S;
   stack<int> st;
   int n=S.size();
   int ans = 0;
   for(int i=0;i<n; i++){
      int a = S[i]-'0';
      if(!st.empty() && st.top() != a){
         ans+=2;
         st.pop();
      }
      else{
         st.push(a);
      }
   }
   cout << ans << endl;
   
   return 0;
}


Measured memory_bytes: 768
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq.map(_.split(' ').map(_.toInt)).head
  val A = in(0)
  val B = in(1)
  val C = in(2)
  //println(A, B, C)
  val c = Math.min(A+B+1, C)
  val b = B//Math.max(B, C)
  println(b+c)
}

Measured memory_bytes: 25516
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

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

const int INF = 2 * 1e9;
int n, k;
int h[100009], dp[100109];

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

    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
        dp[i] = INF;
    }

    dp[1] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            if (i + j > n) break;
            dp[i + j] = min(dp[i + j], abs(h[i] - h[i + j]) + dp[i]);
        }
    }

    cout << dp[n] << "\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll gcd0(ll a,ll b){
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
int main(void){
    ll n;
    cin>>n;
    ll a[n];
    rep(0,i,n)cin>>a[i];
    ll l[n+2],r[n+2];
    l[0]=0,r[n+1]=0;
    rep(0,i,n){
        l[i+1]=gcd0(l[i],a[i]);
        r[n-i]=gcd0(r[n+1-i],a[n-1-i]);
    }
    ll ans=0;
    rep(0,i,n){
        ans=max(gcd0(l[i],r[i+2]),ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
import javax.xml.crypto.Data;
import java.util.*;
import java.io.*;

public class Main {
    public static int n;
    public static int MAX = 500000;
    public static long a[] = new long[MAX + 1];

    public static void main(String[] args) throws IOException {

        //??\???
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m + 1];
        int[][] dp = new int[m + 1][n + 1];
        for(int i = 1; i <= m; i++) {
            a[i] = sc.nextInt();
        }
        for(int j = 1; j <= n; j++) dp[0][j] = 1000007;
        for(int i = 1; i <= m; i++) {
            for(int j = 1; j <= n; j++) {
                if(j < a[i]) dp[i][j] = dp[i - 1][j];
                else dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - a[i]] + 1);
            }
        }
        System.out.println(dp[m][n]);
        
        //??????
    }

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 33072
n = int(input())
array = []
for i in range(n):
    array.append(int(input()))
next_bottun = array[0]
cnt = 0
found = False
while cnt <= n:
    cnt += 1
    if next_bottun == 2:
        found=True
        break
    next_bottun = array[next_bottun-1]
if found:
    print(cnt)
else:
    print(-1)

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n,m,x,y;
int a[5];

int32_t main()
{
    IOS
    cin>>n>>m;
    a[0]=a[1]=a[2]=-1;
    for (int i=1;i<=m;i++)
    {
        cin>>x>>y;
        x--;
        if (a[x]!=-1&&a[x]!=y) return cout<<"-1"<<endl,0;
        if (n>1&&x==0&&y==0) return cout<<"-1"<<endl,0;
        a[x]=y;
    }
    if (n==1)
    {
        if (a[0]==-1) a[0]=0;
    }
    else
    {
        if (a[0]==-1) a[0]=1;
        for (int i=1;i<n;i++) if (a[i]==-1) a[i]=0;
    }
    for (int i=0;i<n;i++) cout<<a[i];
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
  ll n;
  long double x,ans=0;
  cin>>n;
  string s;
  for (int i = 0; i < n; ++i)
  {
    /* code */
    cin>>x>>s;
    if(s=="JPY")
    {
      ans+=x;
    }
    else
    {
      ans+= ( 380000.0)*x;
    }
  }
  cout<<setprecision(10)<<fixed<<ans;

}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      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 a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a == 7 && b == 5 && c == 5) {
            System.out.println("YES");
        } else if (a == 5 && b == 7 && c == 5) {
            System.out.println("YES");
        } else if (a == 5 && b == 5 && c == 7) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21588
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int n, m, k;

bool solve() {
  for (int i = 0; i <= n; ++i) {
    for (int l = 0; l <= m; ++l) {
      if (i * (m - l) + (n - i) * l == k) {
        return true;
      }
    }
  }
  return false;
}

int main() {
  cin >> n >> m >> k;
  if (solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
'''
ITP-1_4-D
 ????°????????????§??????????¨????
n????????´??° ai(i=1,2,...n)ai(i=1,2,...n)?????\?????????????????????????°????????????§??????????¨????????±???????????????°????????????????????????????????????
???Input
??????????????´??°?????° nn ???????????????????????????????????? nn ????????´??° aiai ????????????????????§?????????????????????
???Output
????°????????????§??????????¨????????????????????????§????????????????????????????????????
'''
# import
import sys

# ?????°??????????????????
n = int(input())
inputData = map(int, input().split())
maxData = -1000000
minData = 1000000
totalData = 0

for inputVal in inputData:

    # max value check
    if inputVal > maxData:
        maxData = inputVal

    # minimum value check
    if inputVal < minData:
        minData = inputVal

    # total value add
    totalData += inputVal

# ????????????
print(minData, maxData, totalData)

Measured memory_bytes: 8336
N, M, X, Y = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.sort()
y.sort()

if x[-1] < y[0] and y[0] <= Y and y[0] > X:
    ans = 'No War'
else:
    ans = 'War'

print(ans)

Measured memory_bytes: 3060
//c
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int> pii;

int N;

int solve(vector<pii> v){
	
	sort(v.begin(), v.end());
	
	int rl, rs = 0, ws = 0;
	bool dp[1010][1010] = {0};
	
	rl = v[N-1].first;
	
	for(int i=0; i<N; ++i){
		rs += v[i].first;
		ws += v[i].second;
	}
	
	rs -= rl;
	
	if(rs >= rl){
		return rs + rl + ws;
	}
	
	
	dp[0][0] = true;
	
	for(int i = 0; i < N; ++i){
		for(int j = 0; j <= rl - rs; ++j){
			
			if(dp[i][j]){
			
				if( j + v[i].second <= rl - rs )
					dp[i+1][j + v[i].second] = dp[i+1][j] =true;
				else
					dp[i+1][j] = true;
			}
			
		}
	}
	
	int maxwrite = 0;
	
	for(int i = 0; i <= rl - rs; ++i){
	
		if(dp[N-1][i])
			maxwrite = i;
	}
	
	return 2*rl + ws - maxwrite;
}

int main(){
	
	while(cin>>N, N){
		
		vector<pii> v;
		int r, w;
		
		for(int i=0; i<N; ++i){
			
			cin >> r >> w;
			v.push_back(make_pair(r, w));
		}
		
		cout << solve(v) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2220
import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str

isdelim(x::UInt8, xs::Set{UInt8}) = x in xs

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        if !isdelim(c, delims)
            break
        end
    end
    push!(out, c)
    if eof(s)
        return out
    end
    while !eof(s)
        c = read(s, UInt8)
        if isdelim(c, delims)
            break
        end
        push!(out, c)
    end
    return out
end

delimset = Set([0x0a, 0x20])

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

readvec(tys::Tuple , len::Signed)::Vector{Tuple{tys...}} = @inbounds Tuple{tys...}[reads(tys...) for i in 1:len]

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i = 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

function main()
    N = pread(Int)
    a = readvec(Int, N)
    if count(x -> x == 0, a) > 0
        println(0)
        return
    end

    ans = 1
    befans = 1
    for i in a
        befans = ans
        ans *= i
        if ans > 10^18 || befans > ans
            println(-1)
            return
        end
    end
    println(ans)
end

main()


Measured memory_bytes: 207956
N = int(input())
P = list(map(int, input().split()))

MAX = [P[-1]] * (N+1)
MIN = 0
J = True

for i in range(N):
  MAX[N-1-i] = MAX[N-i] + P[N-1-i]

follow = 1
hikaku = True
ans = 0
for i in range(N+1): 
  p = follow + P[i]
  if follow < 0:
    J = False
  if hikaku:
    if p >= MAX[i]:
      hikaku = False
      ans += MAX[i]
    else:
      ans += p
      follow *= 2
      if i != N:
        follow -= P[i + 1]
      else:
        follow += P[-1]
  else:
    ans += MAX[i]
  
  
if P[0] != 0:
  J = False
  
if N == 0 and P[0] == 1:
  J = True
  
if J:
  print(ans)  
else:
  print(-1)

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

int main(){
  long long N;
  cin >> N;
  
  long long B,tmp;
  int cnt;
  int ans = 100;
  for(long long A=1;A<=sqrt(N);A++){
    if(N%A==0){
      B = N/A;
    }
    tmp = max(A,B);
    cnt = 0;
    while(tmp>0){
      cnt++;
      tmp /= 10;
    }
    ans = min(ans,cnt);
  }
  cout << ans << "\n";
}

  

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const long long INF = 1LL<<40;

void minDist(const vector<string>& plane, char start, vector<vector<long long> >& dist)
{
    int dy[] = {0, 0, -1, 1};
    int dx[] = {-1, 1, 0, 0};

    int h = plane.size();
    int w = plane[0].size();
    dist.assign(h, vector<long long>(w, INF));

    queue<pair<int, int> > q;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(plane[i][j] == start)
                q.push(make_pair(i, j));
        }
    }
    int n = 1;
    while(!q.empty()){
        queue<pair<int, int> > q1;
        while(!q.empty()){
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            for(int i=0; i<4; ++i){
                int y1 = y + dy[i];
                int x1 = x + dx[i];
                if(0 <= y1 && y1 < h && 0 <= x1 && x1 < w && plane[y1][x1] == '.' && dist[y1][x1] == INF){
                    q1.push(make_pair(y1, x1));
                    dist[y1][x1] = n;
                }
            }
        }
        ++ n;
        q = q1;
    }
}

int main()
{
    int w, h;
    cin >> w >> h;

    vector<string> c(h);
    vector<vector<bool> > floor(h, vector<bool>(w, false));
    int n = 0;  // 床の数
    int sy, sx; // スタート位置
    for(int i=0; i<h; ++i){
        cin >> c[i];
        for(int j=0; j<w; ++j){
            if(c[i][j] == 's'){
                sy = i;
                sx = j;
                c[i][j] = '.';
            }
            if(c[i][j] == '.'){
                floor[i][j] = true;
                ++ n;
            }
        }
    }

    vector<vector<long long> > a, b; // ゴールまでの距離、バネまでの距離
    minDist(c, 'g', a);
    minDist(c, '*', b);

    multiset<long long> diff;
    long long sum = 0;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(!floor[i][j])
                continue;

            sum += b[i][j];
            diff.insert(a[i][j] - b[i][j]);
        }
    }

    double ret = a[sy][sx];
    for(int i=0; i<n; ++i){
        sum += *diff.begin();
        diff.erase(diff.begin());
        ret = min(ret, b[sy][sx] + sum / (i + 1.0));
    }
    printf("%.10f\n", ret);

    return 0;
}

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

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

    int count = 0;

    if (N[0] == '7') {
        count = count + 1;
    }
    if (N[1] == '7') {
        count = count + 1;
    }
    if (N[2] == '7') {
        count = count + 1;
    }
    if (count > 0) {
        cout << "Yes" << endl;

    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
x=list(input())

a=0
b=0
c=0
d=0

for i in x:
    if i == 'K':
        a+=1
    if i == 'U':
        b+=1
    if i == 'P':
        c+=1
    if i == 'C':
        d+=1
        
y=min(a,b,c,d)

print(y)


Measured memory_bytes: 5556
import itertools
import math
import fractions
import functools
a, b = map(int, input().split())

x_s = math.ceil(a /0.08)
y_s = math.ceil(b/0.10)
x = x_s
y = y_s
while math.floor(x*0.08) <= a:
    x+=1

while math.floor(y*0.10) <= b:
    y+=1


for i in range(x_s,x):
    for j in range(y_s,y):
        if i == j:
            print(i)
            quit()

print(-1)

Measured memory_bytes: 63980
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader stdReader = new BufferedReader(new InputStreamReader(
				System.in));
		String line = stdReader.readLine();

		int x = Integer.parseInt(line);
		System.out.println(x * x * x);
	}
}


Measured memory_bytes: 16860
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

long long rui(int n){
    int ans = 1;
    for(int i=1;i<=n;i++){
        ans *= i;
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    double d[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i == j){
                d[i][j] = 0;
            }
            else{
                d[i][j] = sqrt((a[i] - a[j])*(a[i] - a[j]) + (b[i] - b[j])*(b[i]-b[j])  ); 
            }
        }
    }
    vector<int> v;
    for(int i=0;i<n;i++){
        v.push_back(i);
    }
    double sum = 0;
    do{
        for(int i=0;i<v.size()-1;i++){
            sum += (double)d[v[i]][v[i+1]];
          //  cout << v[i] << " " << v[i+1];
            //cout << sum << endl;
        }
    }while(next_permutation(v.begin(),v.end()));
    //cout << d[1][2] << endl;
    //cout << sum << endl;
    //cout << rui(n) << endl;
    double ans = (double)sum/(double)rui(n);
    cout << setprecision(20) << ans << endl;
    return 0;
}

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

int main(){
    int m,n;
    long long ans1=1,ans2=1,ans=1;
    int div=1000000007;
    while(cin >> m >> n){
    for(int i=0;i<50;i++){
        ans1 *= m;
        if(ans1>div) ans1 = ans1%div;
    }
    for(int j=0;j<n%50;j++){
        ans2 *= m;
        if(ans2>div) ans2 = ans2%div;
    }
    for(int k=0;k<n/50;k++){
        ans *= ans1;
        if(ans>div) ans = ans%div;
    }
    ans *= ans2;
    ans = ans%div;
    cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }






int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    
    /*
     int n;
     cin >> n;
     vector<int> a(n);
     rep(i, n) cin >> a[i];
     */
    int n;
    cin >> n;
    rep(i, 100000) {
        if (i * 108 / 100 == n) { cout << i << endl; return 0; }
    }
    
    cout << ":(" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  int A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  if( V <= W ) cout << "NO" << endl;
  else if( (V-W)*T >= abs(A-B) ) cout << "YES" << endl;
  else cout <<"NO" << endl;

}


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

class Tree {
public:
  Tree(Tree *parent) {
    num = -1;
    this->parent = parent;
    child[0] = child[1] = NULL;
    cnt = 0;
  }

  ~Tree() {
    for (int i = 0; i < cnt; i++) {
      delete child[i];
    }
  }
  
  // debug
  void print() {
    if (num != -1) {
      if (cnt >= 1) {
	cout << '(';
	child[0]->print();
	cout << ')';
      }
      cout << '[' << num << ']';
      if (cnt >= 2) {
	cout << '(';
	child[1]->print();
	cout << ')';
      }
    }
  }

  void merge(Tree *t) {
    num += t->num;
    for (int i = 0; i < cnt; i++) {
      if (child[i]->num != -1 && t->child[i]->num != -1) {
	child[i]->merge(t->child[i]);
      } else {
	child[i]->num = -1;
      }
    }
  }
  
  int num;
  Tree *parent;
  Tree *child[2];
  int cnt;
};

Tree *readTree() {
  char c = '\0';

  Tree *root = new Tree(NULL);
  for (Tree *t = root; c != ')' || t != root || root->cnt != 2;) {
    cin >> c;
    if (c == '(') {
      t->child[t->cnt] = new Tree(t);
      t->cnt++;
      t = t->child[t->cnt - 1];
    }
    if (c == ')') {
      t = t->parent;
    }
    if (c == '[') {
      int num;
      cin >> num;
      t->num = num;
      cin >> c;
    }
  }

  return root;
}

int main() {
  Tree *t1 = readTree();
  Tree *t2 = readTree();
  t1->merge(t2);
  t1->print();
  cout << endl;

  delete t1, t2;
  
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	ll sum = 0;
	
	rep(i,n){
		if((i+1)%3 == 0){
		}else if((i+1)%5==0){
		}else{
			sum += (i+1);
		}
	}	
	cout << sum << endl;
	
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static final long INF = Long.MAX_VALUE / 4;

    public static void main(String[] args) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        SegTree st = new SegTree(N);
        Edge[] edges = new Edge[M];
        for (int i = 0; i < M; i++) {
            int L = sc.nextInt() - 1;
            int R = sc.nextInt() - 1;
            int C = sc.nextInt();
            edges[i] = new Edge(L, R, C);
        }
        Arrays.sort(edges);
        for (int i = 0; i < M; i++) {
            Edge e = edges[i];
            long s = st.get(e.l);
            if (s == INF) {
                System.out.println(-1);
                return;
            }
            st.add(e.l + 1, e.r + 1, s + e.c);
        }
        long ans = st.get(N - 1);
        System.out.println(ans == INF ? -1 : ans);
    }

    static class Edge implements Comparable<Edge> {
        int l, r, c;

        public Edge(int l, int r, int c) {
            this.l = l;
            this.r = r;
            this.c = c;
        }

        @Override
        public int compareTo(Edge o) {
            return Integer.compare(this.l, o.l);
        }
    }

    static class SegTree {

        int size;
        long[] tree;

        SegTree(int size) {
            this.size = size;
            int l = 1;
            while (l < size * 2) {
                l *= 2;
            }
            tree = new long[l];
            Arrays.fill(tree, INF);
            add(0, 1, 0);
        }

        void add(int lo, int hi, long v) {
//            System.err.println("add:" + lo + " " + hi + " " + v);
            add(0, 0, size, lo, hi, v);
        }

        private void add(int idx, int left, int right, int lo, int hi, long v) {
            if (lo <= left && right <= hi) {
                tree[idx] = Math.min(tree[idx], v);
                return;
            }
            int mid = (left + right) / 2;
            if (lo < mid) add(idx * 2 + 1, left, mid, lo, hi, v);
            if (mid < hi) add(idx * 2 + 2, mid, right, lo, hi, v);
        }

        long get(int pos) {
            return get(0, 0, size, pos);
        }

        private long get(int idx, int left, int right, int pos) {
//            System.err.println("get:" + idx + " " + left + " " + right + " " + pos);
            if (pos < left || right <= pos) return Long.MAX_VALUE;
            long ret = tree[idx];
            if (right - left == 1) return ret;
            int mid = (left + right) / 2;
            if (pos < mid) ret = Math.min(ret, get(idx * 2 + 1, left, mid, pos));
            if (mid <= pos) ret = Math.min(ret, get(idx * 2 + 2, mid, right, pos));
            return ret;
        }
    }
}


Measured memory_bytes: 100316
#include<stdio.h>
int main(void)
{
	int N = 0, i = 0, j = 0, sum = 0;
	char S[100000];
	scanf("%d",&N);
	scanf("%s",S);
	sum = N;
	for (i = 0; i < N-1;i++)
	{
		//for (j = i + 1; j < N ; j++)
		//{
			if(S[i] == S[i+1])
			{
				sum -= 1;
			}
			
		//}
	}
	printf("%d", sum);
	return 0;
}

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


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, x;
    cin >> n;
    int a[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int cur[2] = {0};
    for(int i = n; i >= 1; i--){
        cur[i & 1] += a[i];
    }
    cout << cur[n & 1] - cur[(n - 1) & 1];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
typedef long long ll;
const int N=1e5+10;
int n,a,b,c;
string s;
vector<int>v;
ll dp[N][3];

int main(){
	scanf("%d",&n);
	cin >> a >> b >> c;
	dp[0][0]=a;
	dp[0][1]=b;
	dp[0][2]=c;
	for(int i =1;i<n;i++){
		cin >> a >> b >> c;
		dp[i][0]=1ll*a+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=1ll*b+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=1ll*c+max(dp[i-1][1],dp[i-1][0]);
	}
	printf("%I64d\n",max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) );

	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>

int main(){
  std::string S;
  std::cin >> S;
  
  if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
    std::cout << "Bad" << std::endl;
  }
  else{
    std::cout << "Good" << std::endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;

public class Main {
    class Node {
        int id;
        int left = -1, right = -1;
        String nodeType = null;
        Node(int id, int left, int right) {
            this.id = id;
            this.left = left;
            this.right = right;
        }
        void print() {
            System.out.println(id + ", " + left + ", " + right);
        }
    }
    int[] result;
    int resultIndex;
    void postorder(Node[] nodes, int x) {
        if (nodes[x].left != -1)
            postorder(nodes, nodes[x].left);
        if (nodes[x].right != -1)
            postorder(nodes, nodes[x].right);
        result[resultIndex++] = x;
    }

    Node[] nodes;
    int[] pre;
    int[] in;
    int ap = 0;
int search(int b1p, int b2p) {
        boolean debug = false;
        int center = -1;
        if (ap >= pre.length) {
            return -1;
        }
        int top = pre[ap];
        //if (top == 1) debug = true;
        if (b1p + 1 == b2p) {
            ap++;
            nodes[top] = new Node(top, -1, -1);
            return top;
        } else if (b1p >= b2p) {
            return -1;
        }
        for (int i = b1p; i < b2p; i++) {
            if (top == in[i]) {
                center = i;
                break;
            }
        }
        if (debug) {
            System.out.println("top: " + top);
            System.out.println("ap:  " + ap);
            System.out.println("b1p: " + b1p);
            System.out.println("cen: " + center + ", " + in[center]);
            System.out.println("b2p: " + b2p);
        }
        ap++;
        int left = search(b1p, center);
        //if (left != -1) ap++;
        if (debug) {
            System.out.println("ap r:" + ap + ", " + pre[ap]);
        }
        int right = search(center+1, b2p);
        nodes[top] = new Node(top, left, right);
        return top;
    }
void printArray(int[] ary) {
        System.out.print(ary[0]);
        for (int i = 1; i < ary.length; i++) {
            System.out.print(" " + ary[i]);
        }
        System.out.println();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        nodes = new Node[n+1];
        pre = new int[n];
        in  = new int[n];
        int root = 0;
        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            if (i == 0) root = id;
            pre[i] = id;
        }
        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            in[i] = id;
        }
        search(0, nodes.length);
        result = new int[n];
        resultIndex = 0;
        postorder(nodes, root);
        System.out.print(result[0]);
        for (int i = 1; i < result.length; i++) {
            System.out.print(" " + result[i]);
        }
        System.out.println();
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 26316
class Queue:
    class Node:
        def __init__(self, item):
            self.item=item
            self.next=None
    def __init__(self):
        self.head=None
        self.tail=None
    def enqueue(self, item):
        node=Queue.Node(item)
        if self.head:
            assert self.tail is not None
            self.tail.next=node
            self.tail=node
        else:
            assert self.tail is None
            self.head=node
            self.tail=node
    def dequeue(self):
        assert self.head is not None
        node=self.head
        if self.head==self.tail:
            self.head=None
            self.tail=None
        else:
            self.head=node.next
        return node.item
    def empty(self):
        if self.head: return False
        else: return True

h, w=[int(word) for word in input().split()]
map=[["#" for hi in range(h+2)] for wi in range(w+2)]
visited=[[False for hi in range(h+2)] for wi in range(w+2)]
num_white=0
for hi in range(1, h+1):
    l=input()
    for wi in range(1, w+1):
        map[wi][hi]=l[wi-1]
        if l[wi-1]==".": num_white+=1
queue=Queue()
queue.enqueue((1, 1, 0))
length=None
while not queue.empty():
    wi, hi, l=queue.dequeue()
    if wi==w and hi==h:
        length=l
        break
    if visited[wi][hi]: continue
    if map[wi][hi]==".":
        visited[wi][hi]=True
        queue.enqueue((wi-1, hi, l+1))
        queue.enqueue((wi+1, hi, l+1))
        queue.enqueue((wi, hi-1, l+1))
        queue.enqueue((wi, hi+1, l+1))
if length is not None:
    print(num_white-length-1)
else:
    print(-1)


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

int main() {
    int N;
    cin >> N;
    int mx = 0, mn = 1e9+1;
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        mx = max(mx, a);
        mn = min(mn, a);
    }

    cout << abs(mx-mn) << endl;

    return 0;
}

Measured memory_bytes: 256
using System;


namespace ConsoleApplication19
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string[] b = Console.ReadLine().Split(' ');
            int c = int.Parse(a);
            for (int i = (c - 1); i >= 0; i-- )
            {
                if ( i > 0)
                {
                    int e = int.Parse(b[i]);
                    Console.Write(e + " ");
                }
                else if (i == 0)
                {
                    int e = int.Parse(b[i]);
                    Console.WriteLine(e);
                }
            }


        }
    }
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            if(A[0]+A[1]+A[2] >= 22)
            {
                Console.WriteLine("bust");
            }
            else
            {
                Console.WriteLine("win");
            }
        }

    }

}


Measured memory_bytes: 13140
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = IO().exec {
    val n = int()
    val k = long()
    val a = LongArray(n){long()}
    var ret = 0L
    for (d in divisors(a.sum())) {
        val m = LongArray(n){a[it] % d}
        m.sort()
        val sum = m.sum()
        val l = n - (sum / d).toInt()
        var need = 0L
        for (i in 0 until l) need += m[i]
        if (need <= k) ret = Math.max(ret, d)
    }
    println(ret)
}

fun divisors(n: Long): MutableList<Long> {
    val ret = mutableListOf<Long>()
    var i = 1L
    while (i * i <= n) {
        if (n % i == 0L) {
            ret.add(i)
            if (i != n / i) {
                ret.add(n / i)
            }
        }
        i++
    }
    return ret
}

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Measured memory_bytes: 42292