akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  ll n, s; cin >> n >> s;
  for(int i=2; i<=1000000; i++){
    ll K = n, keta = 0;
    while(K>0){
      keta+=K%i; K/=i;
    }
    if(keta==s){
      cout << i << endl; return 0;
    }
  }
  for(ll i = min(s, (ll)1000000); i>0; i--){
    ll A = i; ll B = s-i; ll ans;
    if((n-B)%A==0){
      ans = (n-B)/A;
    }
    if(ans>B){
      cout << ans << endl; 
      //cout << A << " " << B << endl;
      return 0;
    }
  }
  if(n==s){
    cout << n+1 << endl; return 0;
  }
  cout << -1 << endl; return 0;
}
  

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

int main()
{
  long x;
  cin >> x;
  long u = 0;
  while(x>=500){
    x -= 500;
    u += 1000;
  }
  //cout << u << endl;
  while(x>=5){
    x -= 5;
    u += 5;
  }
  cout << u << endl;
  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);
        while (true) {
            int h = sc.nextInt(), w = sc.nextInt();
            if (h == 0 && w == 0) break;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
                        System.out.print("#");
                    else
                        System.out.print(".");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    vector<bool> nashi(h, false);
    REP(i, h) {
        cin >> s[i];
        REP(j, w) {
            if(s[i][j] == '#') nashi[i] = true;
        }
    }
    int kosu = 0;
    int ans[h][w];

    REP(i, h) {
        if(!nashi[i]) continue;

        bool sentou = true;
        kosu++;
        REP(j, s[i].size()) {
            if(s[i][j] == '.') {
                ans[i][j] = kosu;
            } else {
                if(sentou) {
                    sentou = false;
                } else {
                    kosu++;
                }
                ans[i][j] = kosu;;
            }
        }
    }

    REP(i, h) {
        if(!nashi[i]) {
            if(i == h-1) {
                REP(j, w) ans[i][j] = ans[i-1][j];
            } else if(i==0) {
                /* 下に探す */
                REPN(k, 1, h) if(nashi[k]) {
                    REP(j, w) ans[i][j] = ans[k][j];
                    nashi[i] = true;
                    break;
                }
            } else {
                /* 上に探す */
                REPN_REV(k, 0, i) if(nashi[k]) {
                    REP(j, w) ans[i][j] = ans[k][j];
                    nashi[i] = true;
                    break;
                }
            }
        }
    }
    
    REP(i, h) {
        REP(j, w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var ans = "";
            for(int i = 0; i < 3; i++)
            {
                ans += input[i][0];
            }
            Console.WriteLine(ans.ToUpper());
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int a[101];
int main(){
  int n;cin>>n;
  double sum=0;
  for(int i=1;i<=n;++i){cin>>a[i];sum+=1.0*a[i];}
  sum/=(1.0*n);
  double gap=109.0;
  //cout<<sum<<" sum \n";
  for(int i=1;i<=n;++i)gap=min(gap,abs(1.0*a[i]-sum));
  //cout<<gap<<" gap   \n";

  for(int i=1;i<=n;++i){
    if(gap==abs(1.0*a[i]-sum)){cout<<i-1<<"\n";return 0;}
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int fun (int i, int k, vector<int>&a, vector<int>&dp)
{
    
    if(dp[i]!=-1)
        return dp[i];
    else
    {
        int m=1000000005;
        for(int j=i-1;j>=max(1,i-k);j--)
        m=min(fun(j,k,a,dp)+abs(a[j]-a[i]),m);
        return dp[i]=m;
    }

}

int main()
{
    #ifndef ONLINE_JUDGE 
    freopen ("input1.txt", "r", stdin); 
   freopen ("output1.txt", "w", stdout); 
    #endif
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

   int n,k;
   cin>>n>>k;
   vector<int> dp(n+1,-1),a(n+1,0);
   for(int i=0;i<n;i++)
    cin>>a[i+1];
  // dp[0]=100005;
   dp[1]=0;
 int ans=fun(n,k,a,dp);
 cout<<ans<<"\n";
    return 0; 

} 

  
        
    

    

    

        

    

  
        
    

    

    

        

    

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

int main() {
  int H,W,h,w;
  cin >> H>>W>>h>>w;
    
    cout << (H-h)*(W-w) << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	rep(i,n) {
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll max_num = 1000000000000000000;
	ll ans = 1;
	bool ex = false;
	rep(i,n) {
		if (ans>max_num/a[i]) {
			ex = true;
			break;
		}
		else {
			ans *= a[i];
		}
	}
	if (ex) {
		cout << -1 << endl;
	}
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4052
#include<iostream>
using namespace std;
int main(){

  int tate, yoko;

  int n, m;

  while(1){
    cin >> tate >> yoko;
     if(tate == 0 && yoko == 0){
      break;
    }

    else{
      for(m = 1;m <= tate;m++){
 
      if(m%2 == 1){
	
        for(n = 1;n <= yoko;n++){
	  
          if(n%2 == 0){
	    cout << ".";
	  }
	  
	      else{
	   cout << "#";
	    }
	}
      }

        else{
      	for(n = 1;n <= yoko;n++){
      	  if(n%2 == 1){
      cout << ".";
      	  }
      	  else{
      	    cout << "#";
	    	  }
      	}
         }
      
       cout << "\n";
      
      }
    }
     cout << "\n";
  }
}

Measured memory_bytes: 1120
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string a,b;
    cin >> a >> b;
    a += b;
    int n = atoi(a.c_str());
    if(sqrt(n) == int(sqrt(n)))
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
T,A = map(int, input().split())
list_h = []
list_h = list(map(int, input().split()))

list_judge = []

for i in list_h:
    aaa= T-(i*0.006)
    bbb = abs(A - aaa)
    list_judge.append(bbb)

min = list_judge.index(min(list_judge))+1
print(min)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char> >s(h+2,vector<char>(w+2,'#'));
  int i,j;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      cin >> s[i][j];
    }
  }
  queue<pair<int,int> >que;
  vector<vector<int> >dist(h+2,vector<int>(w+2,-1));
  que.push(make_pair(1,1));
  dist[1][1]=1;

  bool chk = true;
  while(chk){
    if(que.empty()){
      chk = false;
      break;
    }
    int x = que.front().first;
    int y = que.front().second;
    int distance = dist[y][x];
    que.pop();
    if(x==w && y == h){
      break;
    }
    if(s[y][x+1]!='#'){
      if(dist[y][x+1]==-1){
        que.push(make_pair(x+1,y));
        dist[y][x+1]=distance+1;
      }
    }
    if(s[y][x-1]!='#'){
      if(dist[y][x-1]==-1){
        que.push(make_pair(x-1,y));
        dist[y][x-1]=distance+1;
      }
    }
    if(s[y+1][x]!='#'){
      if(dist[y+1][x]==-1){
        que.push(make_pair(x,y+1));
        dist[y+1][x]=distance+1;
      }
    }
    if(s[y-1][x]!='#'){
      if(dist[y-1][x]==-1){
        que.push(make_pair(x,y-1));
        dist[y-1][x]=distance+1;
      }
    }

  }
  if(chk){
    int ans = h*w;
    for(i=1;i<=h;i++){
        for(j=1;j<=w;j++){
          if(s[i][j]=='#')ans--;
        }
    }
    cout << ans-dist[h][w] << endl;
  }else cout << -1 << endl;

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll a,b,t;

int main(){
    cin >> a >> b >> t;
    cout << (t/a)*b << endl;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, m;
int deg[100005];
int a[100005], b[100005];
int par[100005];

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

int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; i++){
		scanf("%d %d", &a[i], &b[i]);
		deg[a[i]]++;
		deg[b[i]]++;
	}
	for(int i = 1; i <= n; i++){
		if(deg[i] & 1){
			printf("No\n");
			return 0;
		}
	}
	
	int extra = 0;
	int four = 0;
	for(int i = 1; i <= n; i++){
		extra += (deg[i] / 2) - 1;
		four += deg[i] == 4;
	}
	
	if(extra >= 2){
		if(extra == 2 && four == 2){
			// need further check
			int del = 0;
			for(int i = 1; i <= n; i++){
				if(deg[i] == 4){
					// remove this, see if anything disconnects
					del = i;
					break;
				}
			}
			for(int i = 1; i <= n; i++){
				par[i] = i;
			}
			for(int i = 1; i <= m; i++){
				if(a[i] == del || b[i] == del){
					continue;
				}
				int pa = f(a[i]), pb = f(b[i]);
				if(pa != pb){
					par[pa] = pb;
				}
			}
			int conn_comp = 0;
			for(int i = 1; i <= n; i++){
				if(i != del){
					if(f(i) == i){
						conn_comp++;
					}
				}
			}
			if(conn_comp == 1){
				printf("No\n");
			}else{
				printf("Yes\n");
			}
		}else{
			printf("Yes\n");
		}
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};

int N,M;
vector<ll> X,Y,Z;

void vecOperate(vector<ll> &a, int p){
  // pの1の位が1なら全て-1倍する
  p %= 2;
  if (p == 1){
    rep(i, a.size()) a[i] *= -1;
  }
}

ll dping(vector<ll> &X, vector<ll> &Y, vector<ll> &Z, int p){
  vecOperate(X, p>>2);
  vecOperate(Y, p>>1);
  vecOperate(Z, p);
  vector<vector<ll>> dp(N+1, vector<ll>(M+1, -1001001001001001));
  dp[0][0] = 0;
  // dp[i][j] := i個からj個を選んだときのうれしさの最大値
  // ここでは各々の値の和の最大値として考え、その最大値を返す
  for (int i=0; i<N; i++){
    for (int j=0; j<=M; j++){
      chmax(dp[i+1][j], dp[i][j]);
      if (j < M) chmax(dp[i+1][j+1], dp[i][j] + X[i] + Y[i] + Z[i]);
    }
  }
  ll res = dp[N][M];
  vecOperate(X, p>>2);
  vecOperate(Y, p>>1);
  vecOperate(Z, p);
  return res;
}

int main() {
  cin >>N >>M;
  X.assign(N, 0); Y.assign(N, 0); Z.assign(N, 0);
  rep(i, N) cin >>X[i] >>Y[i] >>Z[i];
  ll res = 0;
  rep(i, 8) chmax(res, dping(X, Y, Z, i));
  cout <<res <<endl;
}


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

//var 
int n,m,x, c[13], a[13][13], co = 0, v[13], ans = INT_MAX; //cost, skill;
bool g = 1;

int main(){
	cin >> n >> m >> x;
	for(int i = 1; i<=n; i++){
		cin >> c[i];
		for(int j = 1; j<=m; j++)cin >> a[i][j];
	}
	
	for(int i = 1; i<=pow(2,n); i++){
		co = 0;
		for(int j = 1; j<=m; j++)v[j] = 0;
		for(int j = 1; j<=n; j++){
			if((i&(1<<(j-1))) == 0)continue;
			//cout << j << " ";
			for(int z = 1; z<=m; z++)v[z] += a[j][z];
			co += c[j];
		}g = 1; 
		for(int j = 1; j<=m; j++)g&=(v[j]>=x);
		if(g)ans = min(ans,co);
	}

	cout << (ans==INT_MAX?-1:ans) << endl;
	
	
}

Measured memory_bytes: 4100
import java.io.*;
import java.util.StringTokenizer;

public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		int D = Integer.parseInt(st.nextToken());
		int T = Integer.parseInt(st.nextToken());
		int S = Integer.parseInt(st.nextToken());
		
		if(T*S < D)
			System.out.println("No");
		else
			System.out.println("Yes");
						
	}
}

Measured memory_bytes: 25400
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

string S;
int now,st=0;
char n='R';

int main(){
    cin>>S;
    int ans[S.size()];
    rep(i,S.size())ans[i]=0;
    rep(i,S.size()){
        if(S[i]==n&&i<S.size()){
            now++;
        }
        else{
            if(n=='R'){
                ans[i]+=now/2;
                ans[i-1]+=(now+1)/2;
            }
            else{
                ans[st]+=(now+1)/2;
                ans[st-1]+=now/2;
            }
            now=1;
            st=i;
            n=S[i];
        }
    }
    ans[st]+=(now+1)/2;
    ans[st-1]+=now/2;
    rep(i,S.size()){
        cout<<ans[i]<<" ";
    }
    out("");

    

}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define reps(i,j,n) for(int i = j ; i < n ; ++i)
#define rep(i,n) reps(i,0,n)
vector<int> book[10];
int dp[11][2001],n,k;
/*Segmentation fault
int solve(int ct,int ja){
  if(ct >= k || ja > 10) return 0;
  if(dp[ct][ja]!=-1) return dp[ct][ja];
  int res = solve(ct,ja+1),sum = 0;
  rep(i,min(k-ct,(int)book[ja].size())){
    sum += book[ja][i];
    res = max(res,solve(ct+i+1,ja+1) + sum + i*(i+1));
  }
  return dp[ct][ja] = res;
}
*/
int main(){
  cin >> n >> k;
  rep(i,n){
    int c,g;
    cin >> c >> g;
    book[g-1].push_back(c);
  }
  rep(i,10) sort(book[i].rbegin(),book[i].rend());
  rep(i,10) rep(j,k+1){
    int res = 0;
    dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
    rep(k,book[i].size()){
      res += book[i][k];
      dp[i+1][j+k+1] = max(dp[i+1][j+k+1],dp[i][j] + res + k*(k+1));
    }
  }
  cout << dp[10][k] << endl;
}

Measured memory_bytes: 1316
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int sum = 0;
    for(int i = 1; i - 1 < n; i++) {
      sum += i;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 22356
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		Demand[] demands = new Demand[m];
		for(int i = 0; i < m; i++){
			demands[i] = new Demand(sc.nextInt(), sc.nextInt());
		}

		Arrays.sort(demands);
		int result = 1;
		//ここは絶対落とす
		int bridgeID = demands[0].end - 1;
		
		for(int i = 1; i < m; i++){
			//既に区間が破壊されていなかった場合
			if(!demands[i].hasBridge(bridgeID)){
				result++;
				bridgeID = demands[i].end - 1;
			}
		}
		
		System.out.println(result);
	}
}

class Demand implements Comparable<Demand>{
	int begin;
	int end;
	
	Demand(int a, int b){
		this.begin = a;
		this.end = b;
	}

	@Override
	public int compareTo(Demand d) {
//		return (this.end - this.begin) - (d.end - d.begin);
		return this.end - d.end;
	}
	
	public boolean hasBridge(int bid){
		return begin <= bid && end > bid;
	}
}


Measured memory_bytes: 91956
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let mut ret = 0.0;
    for i in 1..n + 1 {
        let mut tmp = 1.0 / n as f64;
        let mut now = i;
        while now < k {
            now = now * 2;
            tmp = tmp / 2.0;
        }
        ret += tmp;
    }
    println!("{:.12}", ret);
}


Measured memory_bytes: 2172
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
 
using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

ll gcd(ll a, ll b) { 
	if (b==0)
		return a;
	return gcd(b,a%b);
}
ll lcm(ll a, ll b) { 
	return a/gcd(a,b)*b;
}

 
int main () {
	int N, M;
    cin >> N >> M;
	vector<int> A(N);
	vector<int> B(N);
	rep(i,N) {
		cin >> A[i];
		B[i] = A[i]/2;
	}
	ll l = 1;
	for (int i = 0; i < N; i++) {
		l = lcm(l,B[i]);
	}
	for (int i = 0; i < N; i++) {
		if ((l/B[i])%2==0) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll ans = M / l;
	ans = (ans + 1)/2;
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

int const MaxSize = 1e5 + 5;

string s;
int ans;

void calc(int si, int ei) {
	if (si >= ei) {
		return;
	}

	//cout << si << " " << ei << endl;
	if (s[si] == s[ei]) {
		calc(si + 1, ei - 1);
	} else if (s[si] == 'x') {
		ans++;
		calc(si + 1, ei);
	} else if (s[ei] == 'x') {
		ans++;
		calc(si, ei-1);
	} else {
		ans = -1;
		return;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);
	cin >> s;

	calc(0, s.size() - 1);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = readInt >>= print . ( 1110 - )

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

int main(){
    int h,m,s;
    cin >> s;
    
    h=s/3600;
    s %= 3600;
    m=s/60;
    s%=60;
    
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>

using namespace std;

int main() {
	double A, B;

	cin >> A >> B;

	if (A > B) {
		cout << "GREATER" << endl;
	}

	else if (A < B) {
		cout << "LESS" << endl;
	}

	else if (A == B) {
		cout << "EQUAL" << endl;
	}

	return 0;
}

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

int main()
{
    ll n, j = 0, ma = 0;
    ll k = 0;
    cin >> n;
    vector<string> s(n), s1(n);
    vector<ll> a(n, 0);
    for (ll i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    s1[0] = s[0];
    for (ll i = 0; i < n; i++)
    {
        if (s1[j] != s[i])
        {
            s1[++j] = s[i];
        }
    }

    for (ll i = 1; i < n; i++)
    {
        if (s[i] == s1[k])
        {
            a[k]++;
        }
        else
        {
            k++;
        }
    }
    for (ll i = 0; i <= j; i++)
    {
        if (ma <= a[i])
        {
            ma = a[i];
        }
    }
    for (ll i = 0; i <= j; i++)
    {
        if (ma == a[i])
        {
            cout << s1[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 17408
loop do
	h, w = gets.chomp.split.map(&:to_i)
	break if h == 0 && w == 0
	h.times do |i|
		if i == 0 || i == h-1
			puts "#"*w
		else
			puts "#" + "."*(w-2) + "#"
		end
	end
	puts
end

Measured memory_bytes: 8832
#include<stdio.h>
#include<iostream>
using namespace std;

int n, A[50];

int solve(int i, int m) {
	if (m == 0) return 1;
	else if (i >= n) return 0;

	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}

int main()
{
	int q,M,i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &M);
		if (solve(0, M)) cout << "yes\n";
		else cout << "no\n";
	}
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
using namespace std;

#define NONE 0
#define TREE 1
#define JUMP 2

int dp[17][17];
int area_state[17][17];
int h,w;

int solve(int y, int x){

	if (dp[y][x] != -1)
		return dp[y][x];
	if (x == 0 || x == w+1){
		dp[y][x] = 0;
		return 0;
	}	
	if (y == h || y == h+1){
		dp[y][x] = 1;
		return 1;
	}

	if (area_state[y][x] == TREE){
		return 0;

	}else if (area_state[y][x] == JUMP){
		dp[y][x] = (solve(y+2, x));
		return dp[y][x];

	}else if (area_state[y][x] == NONE){
		if(y == h-1){
			dp[y][x] = 1;
			return 1;
		}
		int left = 0;
		int right = 0;

		if(area_state[y+1][x-1] != JUMP){
			left = solve(y+1,x-1);
		}
		if(area_state[y+1][x+1] != JUMP){
			right =  solve(y+1,x+1);
		}
		dp[y][x] =  left + solve(y+1,x) + right;
		return dp[y][x];
	}
}


int main() {
	while (cin >> w >> h && w&&h ){ 
		fill( dp[0], dp[17], -1);
		fill( area_state[0], area_state[17], 0);

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				int zone;
				cin >> zone;
				area_state[i][j+1] = zone;
			}
		}

		int ans = 0;
		for(int i = 1; i < w+1; i++){
			ans += solve(0,i);
		}

		// cout << endl;

		// for(int i = 0; i < h+2; i++){
		// 	for(int j = 0; j < w+2; j++){
		// 		printf("%4d",area_state[i][j]);
		// 	}
		// 	cout << endl;
		// }
		// cout << endl;

		// for(int i = 0; i < h+2; i++){
		// 	for(int j = 0; j < w+2; j++){
		// 		printf("%4d",dp[i][j]);
		// 	}
		// 	cout << endl;
		// }
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := new(big.Int)
	b := new(big.Int)
	c := new(big.Int)
	fmt.Sscan(getNextString(scanner), a)
	fmt.Sscan(getNextString(scanner), b)
	bl := a.Sign() != b.Sign()
	if a.Sign() == -1 {
		a.Neg(a)
	}
	if b.Sign() == -1 {
		b.Neg(b)
	}
	c.Div(a, b)
	if bl {
		c.Neg(c)
	}
	fmt.Fprintln(writer, c)
}



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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long w = sc.nextLong();
		long[] area = new long[4];
		Arrays.fill(area, Long.MAX_VALUE);
		// 縦に3分割
		for(int i = 1 ; i < w ; i++) {
			long[] inner = new long[3];
			inner[0] = i * h;
			inner[1] = w / 3 * h;
			inner[2] = (w + 2) / 3 * h;
			long max = Math.max(inner[0], Math.max(inner[1], inner[2]));
			long min = Math.min(inner[0], Math.min(inner[1], inner[2]));
			if(area[0] > max - min) {
				area[0] = max - min;
			}
		}
		// 横に3分割
		for(int i = 1 ; i < h ; i++) {
			long[] inner = new long[3];
			inner[0] = i * w;
			inner[1] = h / 3 * w;
			inner[2] = (h + 2) / 3 * w;
			long max = Math.max(inner[0], Math.max(inner[1], inner[2]));
			long min = Math.min(inner[0], Math.min(inner[1], inner[2]));
			if(area[1] > max - min) {
				area[1] = max - min;
			}
		}
		// 縦半分に分割=>横半分に分割
		for(int i = 1 ; i < w ; i++) {
			long rest = w - i;
			long[] inner = new long[3];
			inner[0] = i * h;
			inner[1] = h / 2 * rest;
			inner[2] = (h + 1) / 2 * rest;
			long max = Math.max(inner[0], Math.max(inner[1], inner[2]));
			long min = Math.min(inner[0], Math.min(inner[1], inner[2]));
			if(area[2] > max - min) {
				area[2] = max - min;
			}
		}
		// 横半分に分割=>縦半分に分割
		for(int i = 1 ; i < h ; i++) {
			long rest = h - i;
			long[] inner = new long[3];
			inner[0] = i * w;
			inner[1] = w / 2 * rest;
			inner[2] = (w + 1) / 2 * rest;
			long max = Math.max(inner[0], Math.max(inner[1], inner[2]));
			long min = Math.min(inner[0], Math.min(inner[1], inner[2]));
			if(area[3] > max - min) {
				area[3] = max - min;
			}
		}
		Arrays.sort(area);
		System.out.println(area[0]);
	}
}


Measured memory_bytes: 36692
#define inf 9223372036854775807
#define ll long long
#define pii pair<ll,ll>
#define m_p  make_pair
#define ull unsigned long long
#define spd  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ll n,i,sum=0;

    cin>>n;
    vector<ll>v(n);

    for(i=0;i<n;i++)
    {
      cin>>v[i];
    }

    for(i=0;i<n-1;i++)
    {
        if(v[i]>v[i+1])
        {
            sum+=(v[i]-v[i+1]);
            v[i+1] = v[i];
        }
    }

    cout<<sum<<endl;
}


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

ll l;

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cnt, dist;
        bool operator>(const state s) const { return ((cnt > s.cnt) || (cnt==s.cnt && dist>s.dist)); }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<pair<ll,ll>> shortest_path(long long S) {
        vector<pair<ll,ll>> dp(E.size(), pair<ll,ll>(INF,INF));
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0,0 });
        while(!q.empty()) {
            long long v = q.top().v, cnt = q.top().cnt,dist = q.top().dist;
            q.pop();
            if(dp[v].first < cnt || (dp[v].first==cnt && dp[v].second <= dist)) continue;
            dp[v] = make_pair(cnt,dist);
            for(int i=0;i < E[v].size() ; i++) {
                long long nv = E[v][i].v, ncnt = cnt;
                ll nd = dist+E[v][i].dist;
                if(nd>l){
                    nd = E[v][i].dist;
                    ncnt++;
                }
                if(dp[nv].first > ncnt || (dp[nv].first==ncnt && dp[nv].second > nd)) q.push((state) { nv, ncnt, nd });
            }
        }
        return dp;
    }
};




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
   
    ll n,m;
    cin>>n>>m>>l;
    Dijkstra d(n);
    for(int i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        if(c>l) continue;
        d.add_undirected_edge(a,b,c);
    }
    vector<vector<pair<ll,ll>>> v(n);
    for(int i=0;i<n;i++){
        v[i] = d.shortest_path(i);
    }
    int q;
    cin>>q;
    while(q--){
        int s,t;
        cin>>s>>t;
        s--,t--;
        if(v[s][t].first>=n+1){
            cout << -1 << "\n";
            continue;
        }
        cout << v[s][t].first << "\n";

    }
}


Measured memory_bytes: 6748
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    private static int fact(int n) { int ans=1; for(int i=2;i<=n;i++) ans*=i; return ans; }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int x=0,cnt=0;
        int mx=-1;
        for(int i=0;i<n;i++){
            x = in.nextInt();
            if(x>=mx) cnt++;
            mx = Math.max(x,mx);
        }
        out.println(cnt);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 20564
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int a, b;
  cin >> a >> b;
  cout << max(0, a - b*2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, m, cnt, tr[N], f[N], a[N], b[N], S[N], top, tot, ans;
pair<int, int> p[N];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
bool cmp(pair<int, int> a, pair<int, int> b) {return a.first == b.first ? a.second > b.second : a.first < b.first;}
int lowbit(int x) {return x & (- x);}
void add(int x, int y) {while(x <= cnt) tr[x] = (tr[x] + y) % mod, x += lowbit(x);}
int query(int x) {int res = 0; while(x) res = (res + tr[x]) % mod, x -= lowbit(x); return res;}
signed main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); m = read();
	for(int i = 1; i <= n; i ++) a[i] = read();
	for(int i = 1; i <= m; i ++) b[i] = read();
	for(int i = 1; i <= n; i ++)
	{
		if(a[i] <= b[1] || a[i] >= b[m]) continue;
		int x = lower_bound(b + 1, b + m + 1, a[i]) - b;
		p[++ cnt] = make_pair(a[i] - b[x - 1], b[x] - a[i]);
		S[++ top] = b[x] - a[i];
	}
	sort(S + 1, S + top + 1); tot = unique(S + 1, S + top + 1) - S - 1;
	for(int i = 1; i <= cnt; i ++) p[i].second = lower_bound(S + 1, S + tot + 1, p[i].second) - S;
	sort(p + 1, p + cnt + 1, cmp); cnt = unique(p + 1, p + cnt + 1) - p - 1;
	f[0] = 1;
	for(int i = 1; i <= cnt; i ++) f[i] = query(p[i].second - 1) + 1, add(p[i].second, f[i]);
	for(int i = 0; i <= cnt; i ++) ans = (ans + f[i]) % mod;
	printf("%lld\n", ans);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 5760
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(true){
            int n = scan.nextInt();
            int x = scan.nextInt();
            if(n == 0 && x == 0)break;
            int ans = 0;
            for(int i = 1; i <= n; i++){
                for(int j = i + 1; j <= n; j++){
                    for(int k = j + 1; k <= n; k++){
                        if(i + j + k == x)ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }
}



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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;

const int inf =1 << 18;

const int cmax=250010;
int w,h;
ll d[cmax];
ll e[cmax];

struct state{
	int d,e;
	bool operator<(const state &arg)const{
		return (d-e) >  (arg.d-arg.e);
	}
};

string table[510];

int n=0;
state ex[cmax];

void dijkstra(char s,char o,ll* dist){
	rep(i,cmax) dist[i]=inf;
	queue<pii> q;
	rep(i,h)rep(j,w){
		if(table[i][j]==s){
			int idx=w*i+j;
			dist[idx]=0;
			pii in=mp(idx,0);
			q.push(in);
		}
	}
	while(!q.empty()){
		pii cur=q.front();q.pop();
		if(dist[cur.first]<cur.second)
			continue;
		int dir[4]={-w,-1,1,w};
		rep(i,4){
			pii next=cur;
			next.first+=dir[i];
			next.second++;
			int cw=next.first%w;
			int ch=next.first/w;
			if(table[ch][cw]=='#'||table[ch][cw]==o)
				continue;
			if(dist[next.first]>next.second){
				dist[next.first]=next.second;
				q.push(next);
			}
		}
	}
	return;
}

int main(void){
	cin >> w >> h;
	rep(i,h) cin >> table[i];
	dijkstra('g','*',d);
	dijkstra('*','#',e);

	int sidx;
	ll dsum=0;
	ll esum=0;
	rep(i,h)rep(j,w) {
		int idx=i*w+j;
		if(table[i][j]=='.'||table[i][j]=='s'){
			if(d[idx]!=inf){
				ex[n].d=d[idx];
				ex[n++].e=e[idx];
			}else
				esum+=e[idx];
		}
		if(table[i][j]=='s')
			sidx=idx;
	}
	sort(ex,ex+n);
	rep(i,n) dsum+=ex[i].d;
	double ans=(1.0*(dsum+esum)/n+e[sidx]);
	for(int i=n;i>=1;--i){
		ans=min(ans,1.0*(dsum+esum)/i+e[sidx]);
		int cur=n-i;
		dsum-=ex[cur].d;
		dsum+=ex[cur].e;
	}
	if(d[sidx]!=inf)
		ans=min(ans,1.0*d[sidx]);
	cout.precision(16);
	cout << fixed << ans << endl;
	return 0;
}

Measured memory_bytes: 7412
#include <stdio.h>

int main(void)
{
	int N,sum,max,i,num;
	scanf("%d",&N);
	max=0;
	sum=0;
	for(i=0;i<N;i++){
		
		scanf("%d",&num);
		if(max<num){
			max=num;
		}
		sum+=num;
	}
	sum=sum-max/2;
	printf("%d\n",(int)sum);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define MAX 100005
#define NULL -1
typedef struct
{
	int p,l,r;	//???????????????????????? 
}Node;
Node T[MAX];
int depth;
void Depth(int i)
{
	if(T[i].p!=-1)
	{
		depth++;
		Depth(T[i].p);
	}	
}

void typenode(int i)
{
	if(T[i].p==-1)
	printf("root, [");
	else if(T[i].l==-1)	
	printf("leaf, [");
	else
	printf("internal node, [");
}

void printchildren(int i)
{
	if(i==-1)
	printf("]\n");
	else if(T[i].r==-1)
	printf("%d]\n",i);
	else if(T[i].r!=-1)
	{
		printf("%d, ",i);
		printchildren(T[i].r);
	}
}
int main(int argc, char *argv[])
{
	int n,i,j,node,children,sibling,count;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	T[i].p=T[i].l=T[i].r=NULL;
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&node,&count);
		for(j=0;j<count;j++)	
		{
			scanf("%d",&children);
			if(j==0)
			{
				T[node].l=children;
				T[children].p=node;
			}
			else
			{
				T[sibling].r=children;
				T[children].p=node;
			}
			sibling=children;			
		}		
	}
	for(i=0;i<n;i++)
	{
		depth=0;
		Depth(i);
		printf("node %d: parent = %d, depth = %d, ",i,T[i].p,depth);
		typenode(i);
		printchildren(T[i].l);	
	}
	return 0;
}

Measured memory_bytes: 2908
def check(x, y)
  2.times do |z|
    4.times do
      return true if x == y
      a, b, c, d, e, f = x
      x = z.zero? ? [e, a, c, d, f, b] : [d, b, a, f, e, c]
      g = x
      4.times do
        i, j, k, l, m, n = g
        g = [i, k, m, j, l, n]
        return true if g == y
      end
    end
  end
  false
end

h = $<.map{|i| i.chomp.split}.drop(1)
h.size.times do |j|
  (j+1).upto(h.size - 1) do |k|
    (puts 'No')^exit if check(h[j], h[k])
  end
end
puts 'Yes'



Measured memory_bytes: 7716
using System;
using System.Collections.Generic;

namespace ABC060B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c = int.Parse(input[2]);
            var memo = new HashSet<int>();

            for (var i = 0; ; i++)
            {
                var modA = (b * i + c) % a;
                if (modA == 0)
                {
                    Console.WriteLine("YES");
                    return;
                }
                if (memo.Contains(modA))
                {
                    Console.WriteLine("NO");
                    break;
                }
                memo.Add(modA);
            }
        }
    }
}


Measured memory_bytes: 27820
import java.lang.*;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
        
        String[] nk = br.readLine().split(" ");
        int n = Integer.parseInt(nk[0]);
        long k = Long.parseLong(nk[1]);
        long[] arr = new long[100001];
        
        for(int i = 0; i < n; i++){
            String[] vq = br.readLine().split(" ");
            int v = Integer.parseInt(vq[0]);
            int q = Integer.parseInt(vq[1]);
            arr[v] += q;
        }
        
        long sum = 0;
        
        for(int i = 1; i < 100001; i++){
            sum += arr[i];
            if(sum >= k){
                System.out.println(i);
                break;
            }
        }

    }
}


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

using namespace std;


int main(void) {
	string S, C, prefix = "", sufix = "";;
	long long Q, F, T;
	bool isReverse = false;

	cin >> S >> Q;

	for (long long i = 0; i < Q; i++) {
		cin >> T;
		if (T == 1) {
			isReverse = !isReverse;
		}
		else if (T == 2) {
			cin >> F >> C;
			if (F == 1) {
				if (!isReverse) {
					prefix = C + prefix;
				}
				else {
					sufix = sufix + C;
				}
			}
			else if (F == 2) {
				if (!isReverse) {
					sufix = sufix + C;
				}
				else {
					prefix = C + prefix;
				}
			}
		}
	}

	S = prefix + S + sufix;
	if (isReverse) {
		reverse(S.begin(), S.end());

	}

	cout << S << endl;




	return 0;
}


Measured memory_bytes: 1464
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 13

N = int(readline())
temp = INF
a = 0
b = 0
for i in range(1, int(N**.5)+1):
    if N % i == 0:
        if temp >= abs(i - N // i):
            temp = abs(i - N // i)
            a = i
            b = N // i
print(a+b-2)





Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  struct itr {
    int64_t i;
    constexpr itr(int64_t i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int64_t operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int64_t l_, int64_t r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

struct revrange {
  struct itr {
    int64_t i;
    constexpr itr(int64_t i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int64_t operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int64_t l_, int64_t r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  size_t N;
  std::cin >> N;
  std::vector<u32> A(N), B(N);
  for (auto i: range(0, N)) {
    std::cin >> A[i] >> B[i];
  }
  auto calc = [](std::vector<u32> &vec) {
    size_t size = vec.size();
    std::sort(vec.begin(), vec.end());
    if (size % 2 == 0) {
      return vec[size / 2 - 1] + vec[size / 2];
    }
    else {
      return vec[(size - 1) / 2];
    }
  };
  std::cout << calc(B) - calc(A) + 1 << '\n';
  return 0;
}


Measured memory_bytes: 4844
n=int(input())
a=list(map(int,input().split()))

# dp には 足場(i)へ至る最小コストが入る。
dp=[float("inf")]*(n)
dp[0]=0
for i in range(n-1):
  dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]))
  if i+2 < n:
    dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]))
    
print(dp[-1])
    



Measured memory_bytes: 20596
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

int n;
int cst[2][3];
//ll dp[2][5000 * 5000 + 1];
ll dp[5000 * 5000 + 1];

//ll solve(ll n, int p) {
//	if (!n) return 0;
//	if (vis[p][n]) return dp[p][n];
//	vis[p][n] = 1;
//	eprintf("solve %lld %d\n", n, p);
//	ll res = n;
//	rep(i, 3) if (n >= cst[p][i]) res = max(res, solve(n - cst[p][i], p) + cst[p ^ 1][i]);
//	return dp[p][n] = res;
//}

int main() {
	n = read();
	rep(i, 2) rep(j, 3) cst[i][j] = read();
	rep(p, 2) {
		rep(i, n + 1) dp[i] = i;
		rep(i, n + 1) {
			rep(j, 3) {
				if (i >= cst[p][j]) dp[i] = max(dp[i], dp[i - cst[p][j]] + cst[p ^ 1][j]);
			}
		}
		n = dp[n];
	}
	printf("%lld\n", n);
//	ll m = solve(n, 0);
//	eprintf("%lld\n", m);
//	printf("%lld\n", solve(m, 1));
	return 0;
}

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

signed main(){
  int N;cin>>N;
  int res;
  for(int i=1;i*i<=N;i++){
    if(N%i==0)res=i;
  }
  int res2=N/res;
  int ans=0;
  while(res2!=0){
   res2/=10;
   ans++;
 }
 cout<<ans<<endl;
}


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

Measured memory_bytes: 3064