akhauriyash/Code-Regression huggingface dataset:
s = list(input())
n = len(s)-1
ans = 0
l = []
for i in range(2**n):
    ss = s.copy()
    for j in range(n):
        bit = (i >> j) & 1
        if bit == 1:
            ss.insert(n - j, '+')

    ans += eval(''.join(ss))      

 
print(ans)

Measured memory_bytes: 9044
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    ll ans = 0;
    int n;
    cin>>n;
    map<int,ll>mp_l;
    map<int,ll>mp_r;
    for (int i = 1; i <= n; ++i) {
        int temp;
        cin>>temp;
        mp_l[i+temp] ++;
        mp_r[i-temp] ++;
    }

    for(auto L :mp_l){
        ans += L.second * mp_r[L.first];
    }

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


Measured memory_bytes: 37756
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;
	cin >> x;
	ll ans = 2 * (x / 11);
	x %= 11;
	bool flag = true;
	while(x > 0)
	{
		if(flag)
		{
			x -= 6;
			flag = false;
		}
		else 
		{
			x -= 6;
			flag = true;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>

int n,money = 100000;

void OneWeek(int &a){
	a += a*0.05;
	if(a%1000 != 0){
		a -= a%1000;
		a += 1000;
	}
}

int main(){
	std::cin >> n;
	for(int i=0; i<n; i++)
		OneWeek(money);
	std::cout << money << std::endl;
	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

DP=[1000]*(N)

for i in range(N):
    DP[i]=max(DP[i-1],DP[i])
    st,rest=divmod(DP[i],A[i])

    #print(st,rest)
    for j in range(i+1,N):
        DP[j]=max(DP[j],st*A[j]+rest)

print(DP[-1])


Measured memory_bytes: 9188
#include<iostream>
#include <algorithm>
#include <cmath>
using namespace std ;

int main()
{
  int N ;
  cin >> N ;
  int H[N+1], minCost[N+1];   
  for (int i = 1; i <= N; ++i)
    cin >> H[i];


  /* 
  1 way of solving : minCost[i,i+1....N] gives the minimum cost to move from i to N.
  minCost[N] = 0 ;
  minCost[N-1] = abs(H[N]-H[N-1]) ;
  for (int i = N-2; i >= 1; --i)
    minCost[i] = min(abs(H[i+1]-H[i])+minCost[i+1], abs(H[i+2]-H[i])+minCost[i+2]) ;
  */

  
  minCost[1] = 0;  // 2nd way: minCost[1,2..i] gives min cost to move from 1 to i.
  minCost[2] = abs(H[2]-H[1]) ;
  for (int i = 3; i <= N; ++i)
    minCost[i] = min(abs(H[i]-H[i-1])+minCost[i-1], abs(H[i]-H[i-2])+minCost[i-2]);

  cout << minCost[N] << endl ;
  
  return 0 ;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
      int n,m,ans=0;
      vector<int>v[100006];
      priority_queue<int>q;
      cin>>n>>m;
      for(int a,b,i=0;i<n;i++){ 
          cin>>a>>b;
          v[a].push_back(b);
      } 
      for(int i=1;i<=m;i++){ 
          
          for(int j=0;j<v[i].size();j++)q.push(v[i][j]);
          if(q.empty()==false){ 
              ans+=q.top();
              q.pop();
          } 
      } 
      cout<<ans<<endl; 
      
          
      
     
        return 0;
    }

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
    a[i] -= (i + 1);
  }

  auto f = [&](ll b)
  {
    ll ret = 0;
    for(int i = 0; i < n; ++i)
    {
      ret += abs(a[i] - b);
    }
    return ret; 
  };

  ll le = -1000200001LL, re = 1000200001LL;
  ll lv = f(le);
  ll rv = f(re);
  while(re - le > 1)
  {
    ll mid = (le + re) / 2LL;
    ll mv = f(mid);
    if (lv < rv)
    {
      re = mid;
      rv = mv;
    }
    else
    {
      le = mid;
      lv = mv;
    }
  }
  cout << min(rv, lv);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4768
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
int main() {
    FIO;
    ll x;
    cin>>x;
    x==0?cout<<1:cout<<0;
	return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

int main() {
    cin >> a >> b >> c >> d;

    x = c * d / __gcd(c, d);
    a--;
    MSG((b - (b / c) - (b / d) + (b / x)) - (a - (a / c) - (a / d) + (a / x)))
}


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

int64_t MOD = 1e9+7;

//---------- べき乗 ----------
int64_t modpower(int64_t a, int64_t n, int64_t mod){
    if(n == 0) return 1;
    
    int64_t res = 1;
    while(n > 0){
        if(n % 2 == 1) res = res * a % mod;
        a = a * a % mod;
        n /= 2;
    }

    return res;
}

//---------- 逆元 ----------
int64_t modinv(int64_t a, int64_t mod){
    return modpower(a, mod-2, mod);
}


//--------- 組み合わせ ---------
int64_t modcombination(int64_t n, int64_t r, int64_t mod){
  int64_t bunbo = 1, bunshi = 1;

  for(int i=0; i<r; i++){
    bunbo = bunbo * (r-i) % mod;
    bunshi = bunshi * (n-i) % mod;
  }

  return bunshi * modinv(bunbo, mod) % mod;
}


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

  int64_t ans = modpower(2, N, MOD) - modcombination(N, A, MOD) - modcombination(N, B, MOD) - 1;
  while(ans < 0) ans += MOD;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N, M, L; cin >> N >> M >> L;
	vector<vector<ll>> d1(N + 1, vector<ll>(N + 1, 1e10)), d2(N + 1, vector<ll>(N + 1, 1e10));
	for (int i = 0; i < M; i++) {
		ll a, b, c; cin >> a >> b >> c;
		d1[a][b] = c, d1[b][a] = c;
	}

	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]);
				//d1[j][i] = min(d1[i][j], d1[i][k] + d1[k][j]);
				if (k == N&&d1[i][j]<=L) {
					d2[i][j] = 1;
				}
			}
		}
	}

	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
			}
		}
	}

	int Q; cin >> Q;
	vector<pair<int, int>> qs(Q);
	for (int i = 0; i < Q; i++) {
		cin >> qs[i].first >> qs[i].second;
	}
	for (int i = 0; i < Q; i++) {
		int s = qs[i].first, t = qs[i].second;
		if (d2[s][t] > 1e9)cout << -1 << endl;
		else cout << d2[s][t] - 1 << endl;
	}

}



Measured memory_bytes: 5352
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    int n,m,a;
    scanf("%d %d", &n,&m);
    
    
    for(int i=0;i<m;i++){
        scanf("%d",&a);
        n-=a;
    }

    printf("%d",(n>=0? n : -1));
    


    return 0;

}

Measured memory_bytes: 1700
import sys
from collections import defaultdict
N = int(input())


sys.setrecursionlimit(1000000)

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

d = defaultdict(lambda: {})
for u, v, w in uvw:
    d[u][v] = w
    d[v][u] = w


dist = {1: 0}


def calc_dist(i, up):
    if not(i in dist):
        dist[i] = dist[up]+d[up][i]
        [calc_dist(k, i) for k in list(d[i].keys())]


[calc_dist(k, 1) for k in list(d[1].keys())]

for i in range(1, N+1):
    if dist[i] % 2 == 0:
        print(0)
    else:
        print(1)


Measured memory_bytes: 196436
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m&&n){
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))cout<<'#';
				else cout<<'.';
			}cout<<endl;
		}cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] arrayTwoDimension = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		}
		sc.close();
		int count = 0;
		for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <map>

using namespace std;

map<long long, long long> memo;
long long A;
long long B;
long long C; 
long long D;

long long rec(long long N){
    long long ans;

    if( memo.count(N) > 0 ){
        return memo[N];
    }

    if(N == 0){
        ans = 0;
        return memo[N] = ans; 
    }

    if(N == 1){
        ans = D;
        return memo[N] = ans; 
    }

    ans = 9e18;
    // all use D
    if( N < ans/D ){
        ans = N * D;
    }

    //2
    ans = min(ans, ( (rec(N/2) + A) + (N%2) * D) );
    if(N %2 != 0){
        ans = min(ans, ( (rec(N/2+1) + A) + ((N/2+1)*2- N)*D ) );
    }
    //3
    ans = min(ans, ( (rec(N/3) + B) + (N%3) * D) );
    if(N%3 != 0){
        ans = min(ans, ( (rec(N/3+1) + B) + ((N/3+1)*3- N)*D ) );
    }
    //5
    ans = min(ans, ( (rec(N/5) + C) + (N%5) * D) );
    if(N%5 != 0){
        ans = min(ans, ( (rec(N/5+1) + C) + ((N/5+1)*5- N)*D ) );
    }

    return memo[N] = ans; 
}


int main(){
    int T;
    cin >> T;
    
    for(int i=0; i<T; ++i){
        memo.clear();
        long long N;
        cin >> N >> A >> B >> C >> D;
        long long ans;
        ans = rec(N);
        cout << ans << endl;
    }
}




Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int count = 0;
  if (a==b || a==c || b==c) {
    count++;
  }
  if (a==b && a==c && b==c) {
    count++;
  }
  cout << 3 - count << endl;
}

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

int main(){
	int count = 0;
	std::string str;
	std::vector<char> v;

	std::cin >> str;

	const char *cstr = str.c_str();

	for(int i=0;i<str.size();i++){
		v.push_back(cstr[i]);
	}

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

	for(int i=0;i<v.size()-1;i++){
		if(v[i]==v[i+1]) count++;
	}

	if(count==0)
		std::cout << "yes" << std::endl;
	else
		std::cout << "no" << std::endl; 

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=998244353;
const ll MAX_N=100010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,h,w,ans=0;
vl v,v1,v2(200001,0),edge[200001],tree[200001],kaijo(200001),beki(200001),used(200001,0),niko(200001,0),dp(200001);
vp p,p1;
string s;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
   cin>>n;
   y=0;
   rep(i,n){
       cin>>a;
       v.push_back(a);
       y+=a;
   }

   ans=INF;
   x=0;
   rep(i,n){
       x+=v[i];
       ans=fminl(ans,abs(y-x*2));
   }

   cout<<ans<<endl;
}

Measured memory_bytes: 19072
def main():
    s = input()
    score = 0
    diff = 0
    for i in range(len(s)):
        if s[i] == "g":
            if diff == 0:
                diff += 1
            else:
                diff -= 1
                score += 1
        else:
            if diff == 0:
                diff = 1
                score -= 1
            else:
                diff -= 1
    print(max(score, 0))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
s = input()
K = int(input())

l = len(s)
substr = []

for i in range(l):
    for k in range(K):
        substr.append(s[i:i+k+1])
        if i+k+1 >= l: break

substr = list(set(substr))
substr.sort()
print(substr[K-1])


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

#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << "\n"
#define _ << " _ " <<
#define ll long long

using namespace std;

int rez[100100];
vector <int> child[100100];
int par[100100];

void dfs(int x) {
  int out = 0;
  REP(i, child[x].size()) {
    int ne = child[x][i];
    if (ne == par[x]) continue;
    par[ne] = x;
    dfs(ne);
    out ^= 1 + rez[ne];
  }
//  if (child[x].size() == 2 && x != 0) out = 1;
  rez[x] = out;
  return;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n - 1) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    child[x].push_back(y);
    child[y].push_back(x);
  }
  par[0] = -1;
  dfs(0);
  if (child[0].size() == 1) {
    cout << "Alice\n";
    return 0;
  }
  if (rez[0] != 0) cout << "Alice\n";
  else             cout << "Bob\n";

  return 0;
}


Measured memory_bytes: 14336
N, A, B = map(int, input().split())
mod = 10 ** 9 + 7

fact = [1]
num = [N]
for i in range(1, B + 1):
    fact.append(fact[-1] * (i + 1) % mod)
    num.append(num[-1] * (N - i) % mod)


def comb(x):
    res = num[x-1] * pow(fact[x-1], mod - 2, mod) % mod
    return res


ans = (pow(2, N, mod) - comb(A) + mod) % mod
ans = (ans - comb(B) + mod) % mod
ans = (ans - 1 + mod) % mod
print(ans)


Measured memory_bytes: 66416
def solve():
    pass
    '''初期値設定'''
    N, M = [int(i) for i in input().split()]
    food = [0 for i in range(M + 1)]
    '''好み調査開始'''
    for i in range(N):
        p = [int(m) for i, m in enumerate(input().split()) if i != 0]
        for f in p:
            food[f] += 1
    '''結果出力'''
    print(food.count(N))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,s,ans=0,d;
	cin>>k>>s;
	for(int a=0;a<=k;a++){
		for(int b=0;b<=k;b++){
			if(s-a-b<=k && s-a-b>=0){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n;
  scanf("%d", &n);
  int i, x, y, z, c[10001] = {0};
  for(x=1; x<=100; x++){
    for(y=1; y<=100; y++){
      for(z=1; z<=100; z++){
        int f = x*x+y*y+z*z+x*y+y*z+z*x;
        if(f < 10001){
          c[f]++;
        }
      }
    }
  }

  for(i=1;i<=n;i++){
    printf("%d\n", c[i]);
  }
  return 0;
}

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

using namespace std;

const int MOD = 1e9 + 7;
const int LOG = 61;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n;
   cin >> n;
   vector<long long> a(n + 1 , 0LL);
   vector<vector<vector<int> > > dp(n + 1 , vector<vector<int> >(LOG , vector<int>(2 , 0)));
   for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 0; j < LOG; j++) {
         long long st = 1LL << j;
         bool bit = a[i] & st;
         dp[i][j][bit]++;
      }
   }
   for (int i = n - 1; i >= 1; i--) {
      for (int j = 0; j < LOG; j++) {
         dp[i][j][0] += dp[i + 1][j][0];
         dp[i][j][1] += dp[i + 1][j][1];
      }
   }
   long long ans = 0;
   for (int i = 1; i < n; i++) {
      for (int j = 0; j < LOG; j++) {
         long long st = 1LL << j;
         bool bit = a[i] & st;
         if (bit == 1) {
            ans += (dp[i + 1][j][0] * (st % MOD)) % MOD;
            ans %= MOD;
         }
         if (bit == 0) {
            ans += (dp[i + 1][j][1] * (st % MOD)) % MOD;
            ans %= MOD;
         }
      }
   }
   cout << ans << '\n';
   return 0;
}


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

typedef long long STATES;

int main( void )
{
	register int i, j;
	int n;
	while ( cin >> n && n )
	{
		STATES goal_state = 0;
		for ( i = 0; i < n; i++ ) goal_state |= 1LL << i;

		vector <STATES> free_days( 30+1, 0 );
		for ( i = 0; i < n; i++ )
		{
			int k; cin >> k;
			for ( j = 0; j < k; j++ )
			{
				int free_day; cin >> free_day;
				free_days[free_day] |= 1LL << i;
			}
		}

		int answer = -1;
		vector <STATES> dp( n, 0 );
		for ( i = 0; i < n; i++ ) dp[i] = 1LL << i;
		for ( i = 1; answer == -1 && i <= 30; i++ )
		{
			register STATES next = 0;
			for ( j = 0; j < n; j++ ) if ( free_days[i] & ( 1LL << j ) ) next |= dp[j];
			for ( j = 0; j < n; j++ ) if ( free_days[i] & ( 1LL << j ) ) dp[j] |= next;
			if ( next == goal_state ) answer = i;
		}

		cout << answer << endl;
	}

	return 0;
}

Measured memory_bytes: 908
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class Solver {
        public void solve(Scanner in, PrintWriter out) {
            int N = in.nextInt();
            boolean approved = true;
            for (int i = 0; i < N; i++) {
                int A = in.nextInt();
                if (A % 2 == 0) {
                    if (!(A % 3 == 0 || A % 5 == 0)) {
                        approved = false;
                    }
                }
            }
            out.println(approved ? "APPROVED" : "DENIED");
        }
    }
}

Measured memory_bytes: 21972
#include <cmath>
#include <vector>
#include <iostream>
#include <limits>
#include <iostream>
#include <vector>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long Long;
typedef pair<int,int> PII;
int main(){
	
	int N, x;
	cin >> N >> x;
	vector<int> U(N), C(N);
	for (int i = 0; i < N; ++i) {
		int n; cin >> n;
		C[i] = n;
	}
	Long c = 1000000000000000000LL, off = 0;
	for(int i = 0; i < N; ++i){
		Long s = 0;
		for(int j = 0; j < N; ++j)
			s += C[j];
		c = min(s + off, c);
		vector<int> CC = C;
		for(int j = 0; j < N; ++j){
			C[(j+1)%N] = min(CC[(j+1)%N], CC[j]);
		}
		off += x;
	}
	cout << c << endl;
	
	
}


/*



 */


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

int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}

int main() {

	char S[5];

	cin >> S;

	int first;
	int second;

	first = ctoi(S[0]) * 10 + ctoi(S[1]);
	second = ctoi(S[2]) * 10 + ctoi(S[3]);

	if (first <= 12 && second <= 12 && first!=0 && second !=0)
		cout << "AMBIGUOUS" << endl;
	else if((first > 12 || first==0)&& second <= 12 && second != 0)
		cout << "YYMM" << endl;
	else if (first <= 12 && (second > 12 || second==0) && first != 0)
		cout << "MMYY" << endl;
	else
		cout << "NA" << endl;

	return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    while (true) {
        Int n, m;
        cin >> n >> m;
        if (n == 0) break;
        vector<Int> a(n), b(m);
        for (Int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (Int i = 0; i < m; i++) {
            cin >> b[i];
        }
        Int sum_a = 0, sum_b = 0;
        for (Int i = 0; i < n; i++) {
            sum_a += a[i];
        }
        for (Int i = 0; i < m; i++) {
            sum_b += b[i];
        }
        bool check = false;
        for (Int i = 0; i < n; i++) {
            for (Int j = 0; j < m; j++) {
                Int sa = sum_a - a[i] + b[j];
                Int sb = sum_b - b[j] + a[i];
                if (sa == sb) {
                    cout << a[i] << " " << b[j] << endl;
                    check = true;
                    i = n;
                    j = m;
                }
            }
        }
        if (check) continue;
        dump(-1);
    }
    return 0;
}



Measured memory_bytes: 3092
N,M=gets.chomp.split(" ").map(&:to_i)
array=gets.chomp.split(" ").map(&:to_i).sort
bcs=[]
M.times do
    b,c=gets.chomp.split(" ").map(&:to_i)
    bcs.push([b,c])
end
bcs=bcs.sort_by{|b,c|c}

ret=0
N.times do
    if bcs.empty?
        ret+=array[-1]
        array.pop
    else
        if array[-1] > bcs[-1][1]
            ret+=array[-1]
            array.pop                
        else
            ret+=bcs[-1][1]
            if bcs[-1][0] == 1
                bcs.pop
            else
                bcs[-1][0]-=1
            end
        end
    end
end
puts ret


Measured memory_bytes: 26492
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include<climits>

#define ll long long
using namespace std;
int main()
{
    ll k;
    string s;
    cin>>k;
    cin>>s;

   if(s.length()<=k)
   {
       cout<<s<<endl;
   }
   else{
    for(int i=0;i<k;i++)
    {
        cout<<s[i];
    }
    cout<<"...";
   }
    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>

using namespace std;

void compute(int S){

  int h = 0;
  int m = 0;
  int s = 0;

  while(1){
    if( S < 3600 )break;
    S -= 3600;
    h++;
  }
  while(1){
    if( S < 60 )break;
      S -= 60;
      m++;
  }
  printf("%02d:%02d:%02d", h, m, S);
  cout << endl;

}


int main(void){

  int h,m,s;
  while( cin >> h >> m >> s ){
    if( h < 0 && m < 0 && s < 0 )break;
    int se;
    se += s;
    se += m * 60;
    se += h * 60 * 60;
    se = 7200 - se;
    int SE = se * 3;
    compute(se);
    compute(SE);
    se = SE = 0;
  }
  return 0;
}

Measured memory_bytes: 1192
using System;
using System.Collections.Generic;
using System.Linq;
class Edge
{
    public int to;
    public int id;
    public Edge(int to, int id)
    {
        this.to = to;
        this.id = id;
    }
}
class Program
{
    static List<Edge>[] g;
    static int[] colors;
    static int max_color;
    static void DFS(int now, int parent_color = -1, int parent = -1)
    {
        int color = 1;
        foreach (Edge to_node in g[now])
        {
            int to = to_node.to;
            int edge_id = to_node.id;
            if (to == parent) continue;
            if (color == parent_color) color++;
            colors[edge_id] = color;
            if (max_color < color) max_color = color;
            color++;
            DFS(to, colors[edge_id], now);
        }
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        g = new List<Edge>[N];
        for (int i = 0; i < N; i++) g[i] = new List<Edge>();
        colors = new int[N - 1];
        max_color = 1;

        for (int i = 0; i < N - 1; i++)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
            int node_a = input[0];
            int node_b = input[1];
            g[node_a].Add(new Edge(node_b, i));
            g[node_b].Add(new Edge(node_a, i));
        }

        //0を親ノードとしてDFS
        DFS(0);

        //表示
        Console.WriteLine(max_color);
        Console.WriteLine(string.Join("\n", colors));
    }
}


Measured memory_bytes: 35040
from collections import deque
inf=float("inf")

def BFS():
    color=[["white" for _ in range(w)] for _ in range(h)]
    D=[[inf for _ in range(w)] for _ in range(h)]
    queue=deque([])

    for i in range(h):
        for j in range(w):
            if A[i][j]=="#":
                queue.append([i,j])
                color[i][j]="black"
                D[i][j]=0

    while len(queue)>0:
        x,y=queue.popleft()
        for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
            X,Y=x+i,y+j
            if 0<=X<h and 0<=Y<w:
                if color[X][Y]=="white":
                    color[X][Y]="gray"
                    D[X][Y]=D[x][y]+1
                    queue.append([X,Y])
        color[x][y]="black"

    return D


h,w=map(int,input().split())
A=[list(input()) for _ in range(h)]
D=BFS()
ans=0
for i in range(h):
    ans=max(ans,max(D[i]))
print(ans)

Measured memory_bytes: 227956
import java.io.*;

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

    while(true){

      String str[] = br.readLine().split(" ",0);
      int x = Integer.parseInt(str[0]);
      int y = Integer.parseInt(str[1]);
      if(x == 0 && y == 0) break;

      if(x > y){
        System.out.println(y + " " + x);
      }else{
        System.out.println(x + " " + y);
      }

    }
  }
}

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

using namespace std;

int main()
{
  int H, W; cin >> H >> W;
  vector<string> s(H);
  for (int i = 0; i < H; ++i) cin >> s[i];

  string ans = "Yes";
  for (int h = 0; h < H; ++h) {
    for (int w = 0; w < W; ++w) {
      if (s[h][w] == '.') continue;

      if ((h-1 >= 0 && s[h-1][w] == '#') ||
          (w-1 >= 0 && s[h][w-1] == '#') ||
          (w+1 < W && s[h][w+1] == '#') ||
          (h+1 < H && s[h+1][w] == '#')) {
        continue;
      }
      else ans = "No";
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x

signed main() {
    int n, r;
    cin >> n >> r;

    if (n < 10) {
        cout << r + (10 - n) * 100;
    } else {
        cout << r;
    }

    return 0;
}


Measured memory_bytes: 3104
#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>

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

int main() {

	long long X, Y;

	scanf("%lld%lld", &X, &Y);

	long long n = X;
	int c = 0;

	while (n <= Y) {
		n *= 2;
		c++;
	}

	printf("%d\n", c);

	return 0;
}


Measured memory_bytes: 128
<?php

[$S] = fscanf(STDIN, "%s");

$list = str_split($S);

$now = 0;
$mode = 0;
$ans = 0;
for($i=0;$i<count($list);$i++){
    if($mode === 0){
        if($list[$i] === "A"){
            $now++;
        }elseif($list[$i] === "B"){
            if($now > 0){
                $mode = 1;
            }
        }else{
            $now = 0;
        }
    }elseif($mode === 1){
        if($list[$i]==="C"){
            $ans += $now;
//            $now = $ans;
            $mode = 0;
        }else{
            $mode = 0;
            $now = 0;
            if($list[$i] === "A"){
                $now++;
            }
        }
    }
}

echo $ans;

Measured memory_bytes: 28468
#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++)
const ll INF = (1LL<<60);

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll res = 0;
    rep(i,n){
        if(i>0){
            if(a[i]<a[i-1]){
                res += a[i-1]-a[i];
                a[i]=a[i-1];
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 4788
main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  ds <- map ('R' ==) . concat . words <$> getContents :: IO [Bool]
  let
    s = length . filter id . (zipWith (==) <$> id <*> tail) $ ds :: Int
  print $ (s + 2 * k) `min` (n - 1)


Measured memory_bytes: 6876
#include<stdio.h>
#include<math.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long

int main(){
	ll n,small =10000000000;
	int ans = 0;

	scanf("%lld",&n);

	FOR(i,1,sqrt(n)+1){
		if(n % i == 0){
			if(small > (i>n/i ? i:n/i)) small = (i>n/i ? i:n/i);
		}
	}

	FOR(i,1,12){
		if(small < pow(10,i)){
			ans = i;
			break;
		}
	}

	printf("%d\n",ans);
}

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

int main() {
    int N, D, X;
    cin >> N >> D >> X;
    int sum = X;
    for (int i = 0; i < N; i++)
    {
        int A;
        cin >> A;
        int j = 0;
        while (1 + j * A <= D)
        {
            sum++;
            j++;
        }
        
    }
    cout << sum << endl;    
    
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,x,y,a,b,n,i,j,k,l,c,f;
	cin>>x>>y>>a>>b>>c;
	vc p(a+1),q(b+1),r(c+1);
	for(i=1;i<=a;i++)cin>>p[i];
	for(i=1;i<=b;i++)cin>>q[i];
	for(i=1;i<=c;i++)cin>>r[i];
	sort(p.begin()+1,p.end(),greater<ll>());
	sort(q.begin()+1,q.end(),greater<ll>());
	sort(r.begin()+1,r.end(),greater<ll>());
	ll ind1=x,ind2=y;
	for(i=1;i<=c;i++)
	{
	    if((ind1>0&&ind2>0)&&(r[i]>p[ind1])&&(r[i]>q[ind2]))
	    {
	        if(p[ind1]>q[ind2])
	            ind2--;
	        else ind1--;
	    }
	    else if((ind1>0)&&r[i]>p[ind1])
	        ind1--;
	    else if((ind2>0)&&r[i]>q[ind2])
	        ind2--;
	   else break;
	}
	ll sum=0;
	for(j=1;j<=ind1;j++)sum+=p[j];
	for(j=1;j<=ind2;j++)sum+=q[j];
	for(j=1;j<i;j++)sum+=r[j];
	cout<<sum;
	return 0;
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

int N;
vector<vector<vector<double>>> dp;

double rec(int i, int j, int k){
    if (dp[i][j][k]>=0) return dp[i][j][k];
    if (i==0&&j==0&&k==0) return 0.0;

    double res = 0.0;
    if (i>0) res += rec(i-1,j,k)*i;
    if (j>0) res += rec(i+1,j-1,k)*j;
    if (k>0) res += rec(i,j+1,k-1)*k;
    res += (double)N;
    res *= 1.0 / (double)(i + j + k);

    return dp[i][j][k] = res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    int one = 0, two = 0, three = 0;
    for (int i=0;i<N;i++){
        int a;
        cin >> a;
        if (a == 1) one++;
        else if (a==2) two++;
        else three++;
    }
    dp = vector<vector<vector<double>>>(N+5,vector<vector<double>>(N+5,vector<double>(N+5,-1)));

    cout << fixed << setprecision(9) << rec(one, two, three) << "\n";
}

Measured memory_bytes: 228640
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# データ構造：ヒープ
import heapq
class heapque:
    def __init__(self, *args):
        self.que = []
        for arg in args:
            self.push(arg)
    def push(self, v):
        heapq.heappush(self.que, v)
    def pop(self):
        return heapq.heappop(self.que)

from collections import Counter

# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    cnt = Counter(A).values()
    # 3以上の奇数を相殺させ1へ
    cnt = [1 if c % 2 else c for c in cnt]
    # 偶数を相殺させ2へ
    cnt = [2 if c % 2 == 0 else c for c in cnt]

    print(len(cnt) - cnt.count(2) % 2)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


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

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

const int N = 1e5;
ll sum[1 + N];
ll l[1 + N + 1];
ll r[1 + N + 1];
int a[1 + N];

int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    for (int i = 1; i <= n; i++)
        l[i] = l[i - 1] + max (0, a[i]);
    for (int i = n; i > 0; i--)
        r[i] = r[i + 1] + max (0, a[i]);
    ll ans = -(1ll << 60);
    for (int i = 1; i + k - 1 <= n; i++) {
        int x = i;
        int y = i + k - 1;
        ans = max (ans, sum[y] - sum[x - 1] + l[x - 1] + r[y + 1]);
        ans = max (ans, l[x - 1] + r[y + 1]);
    }
    cout << ans << "\n";
    return 0;
}


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

int n,m,k;
int s[10][10],t[10][10],ans;

int main()
{
    char c;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<n;++i) for(int j=0;j<m;++j) {
        c=getchar();while(c!='.'&&c!='#') c=getchar();
        s[i][j]=(c=='#');
    }
    for(int i=0;i<1<<n;++i) for(int j=0;j<1<<m;++j) {
        for(int a=0;a<n;++a) for(int b=0;b<m;++b) t[a][b]=s[a][b];
        for(int b=0;b<n;++b) if((i>>b)&1) for(int a=0;a<m;++a) t[b][a]=0;
        for(int b=0;b<m;++b) if((j>>b)&1) for(int a=0;a<n;++a) t[a][b]=0;
        int cnt=0;
        for(int a=0;a<n;++a) for(int b=0;b<m;++b) cnt+=t[a][b];
        if(cnt==k) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3788
import java.util.*;

public class Main {

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

    for (int i = 0; i < n; i++) {
      System.out.print(s.charAt(i));
      System.out.print(t.charAt(i));
    }
  }

}


Measured memory_bytes: 21844
import java.util.*

fun main(args: Array<String>) {
    val s = Scanner(System.`in`)
    val n = s.nextInt()
    val m = s.nextInt()
    val c = s.nextInt()

    val b = IntArray(m) { s.nextInt() }

    val a = Array(n) {
        IntArray(m) { s.nextInt() }
    }

    val ret = a
        .map {
            it
                .zip(b) { a, b -> a * b }
                .sum()
                .let { sum -> if (sum + c > 0) 1 else 0 }
        }
        .sum()

    println(ret)
}

Measured memory_bytes: 29724
N, K = map(int,input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
S2 = [0]*(N+1)
dict = {}#最新K件の度数分布の管理

for i in range(N):
    S[i+1]=S[i]+A[i]
    S2[i+1] =(S[i+1]-i-1)%K

ans =0
for i in range(N+1):
    if dict.get(S2[i],0):
        ans += dict[S2[i]]
    dict[S2[i]]=dict.get(S2[i],0)+1
    if i >=K-1:
        dict[S2[i-(K-1)]]-=1

print(ans)

Measured memory_bytes: 112972
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const int maxn = 3e2 + 5;

int mod, n, k;
LL dp[maxn][maxn][maxn], ans;

int main() {
	scanf("%d%d%d", &n, &k, &mod);
	dp[0][1][0] = 1;
	for(register int i = 0; i <= n; ++i)
		for(register int j = 1; j <= k; ++j)
			for(register int p = i; p >= 0; --p) {
				if(p) (dp[i][j][p - 1] += dp[i][j][p]) %= mod;
				else (dp[i][j + 1][i] += dp[i][j][p]) %= mod;
				(dp[i + 1][j][p] += dp[i][j][p] * (p + 1)) %= mod;
			}
	printf("%lld", dp[n][k + 1][n]);
	return 0;
}

Measured memory_bytes: 221312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define mp make_pair

const int MAX_N = 2e5+10;
int N;
pair<ll,ll> job[MAX_N]; //deadline, takes

void solve()
{
	sort(job, job+N);
	bool ok = true;
	ll curtime = 0;
	for(int i=0;i<N;++i){
		if(curtime+job[i].second > job[i].first){
			ok = false;
			break;
		}
		curtime += job[i].second;
	}
	if(ok) cout << "Yes\n";
	else cout << "No\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i){
		cin >> job[i].second >> job[i].first;
	}
	solve();
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 998244353;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n;
char buf[2521];
int s[2521];
int sum[2521];
ll dp[4252][4252];

int main(){
  scanf("%s",buf);
  n = strlen(buf);
  REP(i,n)s[i] = buf[i]-'0';
  REP(i,n)sum[i+1] = sum[i] + s[i];
  dp[0][0] = 1;
  REP(i,2*n)REP(j,i+1){
    int tot = min(2*n,2*(i+1));
    int blue = sum[min(i+1,n)];
    int red = tot - blue;
    int ub = j;
    int ur = i-j;
    if(ub+1 <= blue){
      (dp[i+1][j+1] += dp[i][j]) %= MOD;
    }
    if(ur+1 <= red){
      (dp[i+1][j] += dp[i][j]) %= MOD;
    }
  }
  printf("%lld\n",dp[2*n][sum[n]]);
  return 0;
}


Measured memory_bytes: 131712
#include <bits/stdc++.h>
using namespace std;
#define int long long

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    // K 回以下の切断で丸太をすべて x 以下の長さに分割できるか
    auto f = [&](int x){
        int ans = 0;
        for(int i=0; i<N; i++){
            ans += (A[i] + x - 1) / x - 1;
        }
        return ans <= K;
    };

    // 解で二分探索
    int l = 0, r = 1e9;
    while(r-l > 1){
        int m = (l+r) / 2;
        if(f(m)){
            r = m;
        }
        else{
            l = m;
        }
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 4884
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n, tmp1=0,tmp2=0,flag=0;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));
	reverse(all(a));
	a.push_back(-1);
	rep(i, n) {
		if (a[i] == a[i + 1] && flag == 0)tmp1 = a[i], i += 1, flag = 1;
		else if (a[i] == a[i + 1]) { tmp2 = a[i]; break; }
		else continue;
	}
	cout << tmp1 * tmp2 << endl;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll int x[50];
ll int y[50];
int n,kk;
ll int ans = -1;
int main(){
	cin >> n >> kk;
	REP(i,n){
		cin >> x[i];
		cin >> y[i];
	}
	REP(i, n){
		for(int k = i; k < n; k++){
			REP(j, n){
				for(int m = j; m < n; m++){
					int num = 0;
					ll int xl = min(x[i], x[k]);
					ll int xr = max(x[i], x[k]);
					ll int yb = max(y[m], y[j]);
					ll int yu = min(y[m], y[j]);
					REP(t, n){
						if(xl <= x[t] && x[t] <= xr && yu <= y[t] && y[t] <= yb){
							num++;
						}
					}
					// cout << i << " " << k << " " << j << " " << m << "num " << num << endl;
					if(num >= kk){
						ll int nowarea = (xr - xl) * (yb - yu);
						if(ans == -1) ans = nowarea;
						else ans = min(ans, nowarea);
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;
typedef long long Long;

int N;
bool Free[31][51];

bool input() {
    cin >> N;
    if (N == 0) return false;
    memset(Free, 0, sizeof(Free));
    for (int i = 0; i < N; i++) {
        int Count; cin >> Count;
        for (int j = 0; j < Count; j++) {
            int F; cin >> F;
            Free[F][i] = true;
        }
    }
    return true;
}

void solve() {
    Long dp[31][N];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < N; i++) dp[0][i] |= (1LL << i);
    for (int i = 1; i <= 30; i++) {
        for (int j = 0; j < N; j++) {
            dp[i][j] = dp[i - 1][j];
        }
        Long bit = 0;
        for (int j = 0; j < N; j++) {
            if (Free[i][j]) bit |= dp[i][j];
        }
        for (int j = 0; j < N; j++) {
            if (Free[i][j]) dp[i][j] |= bit;
            //cout << hex << dp[i][j] << endl;
        }
        if (bit == (1LL << N) - 1) {
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
}

int main() {
    while (input()) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int k;
  string s;
  cin >> k >> s;
  if(s.size() <= k) {
    cout << s << endl;
  }
  else {
    cout << s.substr(0, k) << "..." << endl;
  }
}

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

#define ll long long int

using namespace std;


int main()
{
    int n,k; cin>>n>>k;
    int ans=k;
    for(int i=0;i<n-1;i++) ans*=(k-1);
    cout<<ans;
    return 0;
}


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

int main()
{
  int l, a, b, c, d;

  cin >> l >> a >> b >> c >> d;

  a = (a + c - 1) / c;
  b = (b + d - 1) / d;

  if (a > b){
    cout << l - a << endl;
    return 0;
  }
  cout << l - b << endl;

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,a[5010],dp[5010],ans;

int main(void){
	while(1){
		cin>>n;
		if(n==0)break;
		reg(i,1,n)cin>>a[i];
		dp[0]=0;
		reg(i,1,n)dp[i]=max(dp[i-1]+a[i],a[i]);
		ans=-1e18;
		reg(i,1,n)ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3144
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        String[] words = line.Split(' ');
        int N, M, X, Y;
        int[] x, y;

        N = int.Parse(words[0]);
        M = int.Parse(words[1]);
        X = int.Parse(words[2]);
        Y = int.Parse(words[3]);

        // A帝国（X座標）
        line = Console.ReadLine();
        words = line.Split(' ');
        //ほしいのは最大値だけ
        int MaxX = X;

        for(int i = 0; i < words.Length; i++)
        {
            if (MaxX < int.Parse(words[i]))
            {
                MaxX = int.Parse(words[i]);
            }
        }
        // B帝国（Y座標）
        line = Console.ReadLine();
        words = line.Split(' ');
        //ほしいのは最小値だけ
        int MinY = Y;

        for (int i = 0; i < words.Length; i++)
        {
            if (MinY > int.Parse(words[i]))
            {
                MinY = int.Parse(words[i]);
            }
        }
        if (MaxX >= MinY)
        {
            Console.WriteLine("War");
        }
        else
        {
            Console.WriteLine("No War");
        }
    }
}

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

using i64 = int64_t;

int main(){
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if(x == 3)ans += 100000;
    else if(x == 2)ans += 200000;
    else if(x == 1)ans += 300000;
    if(y == 3)ans += 100000;
    else if(y == 2)ans += 200000;
    else if(y == 1)ans += 300000;
    if(x == 1 && y == 1)ans += 400000;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256