akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);

    int k;
    cin>>k;
    queue<int> q;
    rep(i,9){
        q.push(i+1);
    }

    int cnt=0;
    int x=-1;
    while(cnt<k){
        cnt++;
        x=q.front(); q.pop();
        if(x%10) q.push(10*x+x%10-1);
        q.push(10*x+x%10);
        if(x%10!=9) q.push(10*x+x%10+1);
    }

    cout<<x<<endl;


}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstring>
#define SIZE 1000

using namespace std;

int m, n, b[501], r[501];
int match[SIZE];
bool used[SIZE];
vector<int> G[SIZE];

bool dfs(int v){
	used[v]=1;
	for(int i=0; i<G[v].size(); i++){
		int u=G[v][i], w=match[u];
		if(w<0||!used[w]&&dfs(w)){
			match[v]=u, match[u]=v;
			return 1;
		}
	}
	return 0;
}

void solve(){
	int res=0;
	memset(match, -1, sizeof(match));
	for(int v=0; v<m+n; v++){
		if(match[v]<0){
			memset(used, 0, sizeof(used));
			if(dfs(v)) res++;
		}
	}
	cout<<res<<endl;
}

int main(){
	while(1){
		cin >> n >> m;
		if(!n && !m) break;
		for(int i=0; i<n; i++){
			cin >> b[i];
		}
		for(int i=0; i<m; i++){
			cin >> r[i];
		}
		for(int i=0; i<SIZE; i++) G[i].clear();
		for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				int a=b[i], c=r[j];
				while(c){
					a%=c;
					swap(a, c);
				}
				if(a!=1)G[i].push_back(j+n), G[n+j].push_back(i);
			}
		}
		solve();
	}
}


Measured memory_bytes: 4912
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int dp[110][4][2];

int main(){
	string s;
	int K;
	cin >> s >> K;
	int N = s.size();
	dp[0][0][0] = 1;
	rep(i,N){
		rep(j,4){
			rep(k,2){
				int nd = s[i]-'0';
				rep(d,10){
					int ni = i+1, nj = j, nk = k;
					if(d != 0) ++nj;
					if(nj > K)continue;
					if(k == 0){
						if(d > nd)continue;
						if(d < nd)nk = 1;
					}
					dp[ni][nj][nk] += dp[i][j][k];
				}
			}
		}
	}
	cout << dp[N][K][0] + dp[N][K][1] << endl;
}

//ll big = 0, small = 0;
//ll lt = 0, mid = 0;
//void dfs(string now, string to, int m_len){
//	if(now.size() == m_len){
//		if(now <= to){
//			++small;
//		}else{
//			if(now.substr(0,now.size()-1) == to.substr(0, to.size()-1)){
//				++lt;		
//			}else{
//				if(to.size() == 3){
//					if(now[0] == to[0]){
//						mid ++;
//						return;
//					}
//				}
//					++big;
//			}
//		}
//	}else{
//		REP(i,9){
//			string n = now +  (char)('0' + i);
//			dfs(n, to, m_len);
//		}
//	}
//}
//
//ll comb_modM(ll n, ll r, ll M = MOD){
//	if(n == 0)return 0;
//	if(r < 0)return 0;
//  ll ans = 1; rep(i,r){ans *= (n-i); }
//  ll divisor = 1; rep(i,r){divisor *= (i+1);}
//	ans /= divisor;
//  return ans;
//}
//
//int main(){
//	string s;
//	int K;
//	cin >> s	>> K;
//	int N = s.size();
//	string t;
//	if(N >= K){
//		t = s.substr(0,K);
//	}else{
//		t = s;
//	}
//	dfs("", t, K);
//	ll ans = 0;
//	printf("[big, mid, lt, small]->[%lld, %lld, %lld, %lld]\n", big, mid, lt, small);
//	{
//		if(N-K >= 1){
//			ll kake = comb_modM(N,K);
//			ans += kake*small;
//			ans += (kake-1)*lt;
//			ans += (kake-K-1)*mid;
//		}else if(N-K == 0){
//			ans += small;
//		}
//	}
//	{
//		if(N-K-1 >= 1){
//			ans += comb_modM(N-1,K)*big;
//		}else if(N-K-1 == 0){
//			ans += big;
//		}
//	}
//	cout << ans << endl;
//	return 0;
//}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();

        int N = sc.nextInt();
        int p[] = sc.nextIntArray(N);
        int ans = 0;

        for (int i=0;i<N-2;i++) {
            if (p[i] > p[i+1] && p[i+1] > p[i+2]) ans++;
            if (p[i] < p[i+1] && p[i+1] < p[i+2]) ans++;
        }

        out.println(ans);
        out.flush();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        int[] nextIntArray(int N) {
            int a[] = new int[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextInt();
            }

            return a;
        }

        long[] nextLongArray(int N) {
            long a[] = new long[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextLong();
            }

            return a;
        }

        double[] nextDoubleArray(int N) {
            double a[] = new double[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextDouble();
            }

            return a;
        }

        String[] nextTokenArray(int N) {
            String a[] = new String[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextToken();
            }

            return a;
        }
    }
}

Measured memory_bytes: 21204
#include <iostream>

using namespace std;

int main() {
    int m, f, r;

    cin >> m >> f >> r;
    while (true) {
        if (m == -1 && f == -1 && r == -1)
            break;
        if (m == -1 || f == -1)
            cout << 'F' << endl;
        else if (m + f >= 80)
            cout << 'A' << endl;
        else if (m + f >= 65)
            cout << 'B' << endl;
        else if (m + f >= 50)
            cout << 'C' << endl;
        else if (m + f >= 30) {
            if (r >= 50)
                cout << 'C' << endl;
            else
                cout << 'D' << endl;
        }
        else
            cout << 'F' << endl;
        
        cin >> m >> f >> r;
    }

    return 0;
}



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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<int> l;
bool is_DAG = true;

void tpsort(vector<vector<int>>& edges, vector<int>& used, int i) {
    if (used[i] == 0) {
        is_DAG = false;
        return;
    } else if (used[i] < 0) {
        used[i] = 0;
        for (int& j : edges[i]) tpsort(edges,used,j);
        used[i] = 1;
        l.push_back(i);
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(n*1001);
    vector<int> used(n*1001,-1);
    vector<int> a(n-1);
    for (int i = 0;i < n;++i) {
        for (int j = 0;j < n-1;++j) cin >> a[j],a[j]--;
        for (int j = 0;j < n-2;++j) {
            int x = min(i,a[j]),y = min(i,a[j+1]);
            edges[x*1001+i+a[j]-x].push_back(y*1001+i+a[j+1]-y);
        }
    }
    for (int i = 0;i < n*1001;++i) if (used[i] < 0) tpsort(edges,used,i);
    if (!is_DAG) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> dp(n*1001,1);
    reverse(l.begin(),l.end());
    for (int i : l) {
        for (int& j : edges[i]) dp[j] = max(dp[j],dp[i]+1);
    }
    cout << *max_element(dp.begin(),dp.end()) << endl;
    return 0;
}

Measured memory_bytes: 51312
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.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,M,K;
    int count;
    scanf("%d %d",&N,&K);
    int A[N+1];
    for(int i = 0; i <= N; ++i){
        A[i] = 0;
    }

    for(int i = 0; i < K; ++i){
        int d;
        scanf("%d",&d);
        for(int j = 0; j < d; ++j){
            scanf("%d",&count);
            A[count] = 1;
        }
    }
    int ans = 0;
    for(int i = 1; i <= N; ++i){
        if(A[i] == 0){
            ans++;
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
unsigned short F[200000][2019]; 
int main(){
  string S; cin >> S; int i, r, N=S.size();
  for(i=0; i<N; i++){ F[i][S[i]-'0']=1; }  
  for(i=0; i<N-1; i++){ for(r=0; r<2019; r++){ 
    F[i+1][(10*r+(S[i+1]-'0'))%2019]+=F[i][r];
  } }
  long ans=0;
  for(i=0; i<N; i++){ ans+=F[i][0]; }
  cout << ans << "\n";
}

Measured memory_bytes: 792372
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define P pair<int,int>
#define enld endl


int main() {
	lint N, M;
	cin >> N >> M;
	lint sum = 0;
	lint tmp;
	rep(i, M) {
		cin >> tmp;
		sum += tmp;
	}
	cout << max(lint(-1), N - sum) << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(void){

int n;
int a,b;

while(scanf("%d %d",&a,&b) != EOF){
n = a + b;
int dig = 0;
while(n!=0){
n=n/10;
dig++;
}

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

return 0;
}



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

int main(){
    int A, B;
    
    cin >> A >> B;
    
    int ans = 0;
    for(int i = A; i <= B; i++){
        if(to_string(i).at(0) == to_string(i).at(4) && to_string(i).at(1) == to_string(i).at(3)){
            ans++;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{	ios_base::sync_with_stdio(false);    cin.tie(NULL);
	string s1,s2;
	cin>>s1 >> s2;
	int count =0 ;
	for(int i=0; i<s1.length(); i++)
		if(s1[i] != s2[i])
			count++;
	cout<<count<<"\n";
	return 0;

}

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

using namespace std;

struct CWW{CWW(){ios::sync_with_stdio(false);cin.tie(0);}}cww;
typedef long long LL;
const LL INF=1e16;
typedef vector<LL> V;
typedef vector<V> VV;
int main(){
    for(int N,M;cin>>N>>M,N+M;){
	VV riku(N,V(N,INF)),umi(N,V(N,INF));
	for(int i=0;i<N;i++)riku[i][i]=umi[i][i]=0;
	while(M--){
	    int a,b;LL t;string s;
	    cin>>a>>b>>t>>s;
	    a--;b--;
	    if(s=="L")riku[a][b]=riku[b][a]=t;
	    else umi[a][b]=umi[b][a]=t;
	}
	for(int k=0;k<N;k++)
	    for(int i=0;i<N;i++)
		for(int j=0;j<N;j++){
		    riku[i][j]=min(riku[i][j],riku[i][k]+riku[k][j]);	    
		    umi[i][j]=min(umi[i][j],umi[i][k]+umi[k][j]);
		}
	int R;
	cin>>R;
	vector<int> z(R);
	for(auto &it:z){
	    cin>>it;it--;
	}
	VV dp(R,V(N,INF));
	dp[0][z[0]]=0;
	for(int i=1;i<R;i++){
	    for(int j=0;j<N;j++){
		dp[i][j]=dp[i-1][j]+riku[z[i-1]][z[i]];
		for(int k=0;k<N;k++)
		    dp[i][j]=min(dp[i][j],dp[i-1][k]+riku[z[i-1]][k]+umi[k][j]+riku[j][z[i]]);
	    }
	}
	LL res=INF;
	for(auto &it:dp.back())res=min(res,it);
	cout<<res<<endl;
    }
    
    return 0;
}

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

int n,m,a[105],ans;

template<class T>inline void read(T &res)
{
	T flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<1)+(res<<3)+c-'0';res*=flag;
}

int main()
{
	read(n);
	for(register int i=1;i<=n;++i) read(a[i]),ans+=a[i];
	read(m);
	int x,y;
	while(m--)
	{
		read(x);read(y);
		printf("%d\n",ans-a[x]+y);
	}
	return 0;
}


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

int main() {
  char c;
  cin >> c;

  if (c == 'a'
    || c == 'i'
    || c == 'u'
    || c == 'e'
    || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	int n, b, f, r, v;
	int bld[4][3][10] = {};

	
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		bld[b-1][f-1][r-1] += v;
	}



	for (int b = 0; b < 4; b++) {
		for (int f = 0; f < 3; f++) {
			for (int r = 0; r < 10; r++) {
				printf(" %d", bld[b][f][r]);
			}
			printf("\n");
		}
		if(b!=3)
			printf("####################\n");
	}

	return 0;
}


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 200005
#define f first
#define s second
using namespace std;

int main()
{
    FLASH
    ll n,ans = 0;
    cin >> n;
    for(int i = 2; i <= 1000010; ++i)
    {
        ll cnt = 0;
        while(n % i == 0)
        {
            n /= i;
            cnt++;
        }
        for(int j = 1; j < 10000; j++)
        {
            if(cnt < j)
                break;
            cnt -= j;
            ans++;

        }
    }
    if(n > 1){
        ans++;
    }
    cout << ans ;
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<limits.h>
using namespace std;

int main(){
  double B;
  long long int A,a, ans;
  cin >> A >> B;
  a=A/100;
  
  ans = a*((long long int)(B*100))+(long long int)((A%100)*B);
  cout << ans << endl;
  

}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[200],t[200];
  cin >> s >> t;
  if(strlen(s)<strlen(t))cout << "LESS";
  else if(strlen(s)>strlen(t))cout << "GREATER";
  else if(strcmp(s,t)<0)cout << "LESS";
  else if(strcmp(t,s)<0)cout << "GREATER";
  else cout << "EQUAL";}
     /*#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int k;
  cin >> k;
  if(a>=b&&a>=c)a=a*pow(2,k);
  if(b>=a&&b>=c)b=b*pow(2,k);
  if(c>=b&&c>=a)c=c*pow(2*k);
  cout << a+b+c;
}

}
*/

Measured memory_bytes: 256
n,m = map(int,input().split())
da = [list(map(str,input().split())) for i in range(m)]
penalty = [0 for i in range(n)]
accepted = [False for i in range(n)]
for i in range(m):
  now = int(da[i][0]) - 1
  if da[i][1] == 'AC':
    accepted[now] = True
  elif not accepted[now]:
    penalty[now] += 1
AC,WA = 0,0
for i in range(n):
  if accepted[i]:
    AC += 1
    WA += penalty[i]
print(AC,WA)

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

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
   string S;
   cin >> S;
   string x = S, y = S;
   int xa = 0, ya = 0;
   if(x[0] == '0'){

   }else{
      x[0] = '0';
      xa++;
   }
   if(y[0] == '1'){

   }else{
      y[0] = '1';
      ya++;
   }
   for(int i = 1; i < S.size(); i++){
      if(x[i] == x[i-1]){
         if(x[i - 1] == '0'){
            x[i] = '1';
         }else{
            x[i] = '0';
         }
         xa++;
      }else{
         
      }
   }
   for(int i = 1; i < S.size(); i++){
      if(y[i] == y[i-1]){
         if(y[i - 1] == '0'){
            y[i] = '1';
         }else{
            y[i] = '0';
         }
         ya++;
      }else{
         
      }
   }
   cout << min(xa, ya) << endl;
return 0;}

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

int main()
{
  int a = 0;
  int b = 0;
  int c = 0;
  int cnt = 0;
  
  cin >> a >> b >> c;
  
  while (a <= b)
  {
    if((c % a) == 0)
    {
      cnt++;
    }
    a++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3112
N, M = map(int, input().split())

S = []
for i in range(M):
    s = list(map(int, input().split()))[1:]
    S.append(s)

P = list(map(int, input().split()))

ans = 0
for i in range(pow(2, N)):
    e = '{:010b}'.format(i)[::-1]
    go = True
    for j in range(M):
        if go==False:
            break
        cnt = 0
        for d in S[j]: # d桁目が立っているか確認
            if e[d-1]=="1":
                cnt += 1
        if cnt%2 == P[j]:
            go = True
        else:
            go = False
    if go:
        ans += 1

print(ans)


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}


/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
//constexpr int inf = 1<<30;

signed main(){
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;

  cout << (m1 != m2) << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;
#define inf 1000000007

int main(void){
    int n;
    cin >> n;
    int a[n];
    int check[200000];
    int ans = 0;
    for(int i = 0; i < 200000; i++)
        check[i] = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        check[a[i]]++;
    }
    for(int i = 1; i < 100000; i++)
        ans = max(ans, check[i-1]+check[i]+check[i+1]);
    cout << ans << endl;
    return 0;
}

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define fo(i, a, b, k) for(int i = a; i <= b; i += k)
#define _fo(i, a, b, k) for(int i = a; i >= b; i -= k)
#define foa(i, a) for (auto &i : a)
#define fod(i, a) for(int i = 1; i*i <= a; i++)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)  
#define log2i(x) (31-__builtin_clz(x))
#define log2ll(x) (63-__builtin_clzll(x)) 
#define msz(x) __builtin_popcount(x) 
#define mszll(x) __builtin_popcountll(x) 
#define fom(i, a, b) for(int i = a; i < (1<<b); i++)
#define ifon(i, mask) if(mask&(1<<i))
#define ss(i, mask) while(i=(i-mask)&mask)
#define ifss(i, mask) if(i > (mask^i)) 

typedef int64_t ll;

const int N = 1e5+5;

ll a[N];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, ans = 0;
	
	cin >> n;
	fo(i, 1, n+1, 1) cin >> a[i];
	fo(i, 1, n, 1) {
		ll val;
		cin >> val;
		ans += min(val, a[i]);
		val = max((ll)0, val-a[i]);		
		ans += min(val, a[i+1]);
		a[i+1] = max((ll)0, a[i+1]-val);
 	}
 	
 	cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	ll x,y;
	cin>>x>>y;
    COMinit();

    // 計算例
//    cout << COM(100000, 50000) << endl;	
//	ll a=0,b=0;
	ll ans=0;
	for(ll i=0;i*2<=x;i++){
		if((x-i*2)*2+i==y){
			ans+=COM(i+x-i*2,i);
			ans%=inf;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

template<class In>
void print_array(In begin, In end) {
  cout << (*begin);
  begin++;
  for (; begin != end; begin++)
  {
    cout << " " << (*begin);
  }
  cout << endl;
}

int main()
{
  string s;
  cin >> s;
  string res = "Good";
  for (auto i = 1; i < s.size(); i++) {
    if (s[i] == s[i-1])
      res = "Bad";
  }

  cout << res << endl;

  return 0;
}


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

int main(){
  string a,un,h;
  int k,ab,han;
  a="A";
  un="Un";
  cin>>ab;
  k=0;
  han=0;
  for(int i=0;i<ab;i++){
    cin>>h;
    if(h==a)k++;
    else if(h==un)k--;
    if(k<0)han++;
  }
  if(han==0&&k==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}

Measured memory_bytes: 3184
#include<iostream>
#include<cctype>
#include<cmath>
using namespace std;

struct point { double x; double y; };


void knch(int n,point a,point b)
{
	if (n == 0)return;
	point s, u, t;
	double th = M_PI * 60.0 / 180.0;

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(8);

	t.x = (1 * a.x + 2 * b.x) / 3.0;
	t.y = (1 * a.y + 2 * b.y) / 3.0;
	s.x = (2 * a.x + 1 * b.x) / 3.0;
	s.y = (2 * a.y + 1 * b.y) / 3.0;
	u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th) + s.x;
	u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th) + s.y;

	knch(n - 1, a, s);
	cout << s.x << " " << s.y << endl;
	knch(n - 1, s, u);
	cout << u.x << " " << u.y << endl;
	knch(n - 1, u, t);
	cout << t.x << " " << t.y << endl;
	knch(n - 1, t, b);
}

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

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(8);

	point a, b;
	a.x = 0; a.y = 0;
	b.x = 100.0; b.y = 0;

	cout << a.x << " " << a.y << endl;
	knch(n, a, b);
	cout << b.x << " " << b.y << endl;

	return 0;
}


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

int main(){
	int a[3];
    int n = 3;
  	
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    cout << a[0] * a[1] / 2;

    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = []

for i in range(N):
    a.append(int(input()))

button = 1
count = 0

aru = False
for i in range(N):
    button = a[button-1]
    count = count + 1
    if button == 2:
        aru = True
        break

if aru:
    print(count)
else:
    print(-1)

Measured memory_bytes: 7084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    vector<int> v;
    for(int i=1; i<=n; i++){
        v.push_back(i);
    }

    vector<int> p(n), q(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    for(int i=0; i<n; i++){
        cin >> q[i];
    }

    int a, b, i = 0;
    do{
        i++;
        if(v == p) a = i;
        if(v == q) b = i;
    }while(next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

long long ru2(int n){
	long long r=1,i;
	for(i=0;i<n;i++)r=r*2;
	return r;
}

int main(){
	long long n,m,i;
	scanf("%lld%lld",&n,&m);
	long long an[50]={0},bn[50]={0};
	if(n==m){
		printf("%lld\n",m);
		return 0;
	}else if(n>=1)n--;
//	an[0]=n;
//	bn[0]=m;
	for(i=1;i<45;i++){
		an[i-1]=(n/ru2(i))*ru2(i-1);
		bn[i-1]=(m/ru2(i))*ru2(i-1);
		if(n>=ru2(i-1))an[i-1]+=(n%ru2(i)>=ru2(i-1)?(n%ru2(i))-ru2(i-1)+1:0);
		if(m>=ru2(i-1))bn[i-1]+=(m%ru2(i)>=ru2(i-1)?(m%ru2(i))-ru2(i-1)+1:0);
	}
	long long ans=0;
	for(i=0;i<45;i++)bn[i]-=an[i];
	for(i=0;i<45;i++){
		if(bn[i]%2==1){
			ans+=ru2(i-0);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll x=in();
    cout<<(10+x/200*200/(-200))<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

	vector<u64> A(N);
	u64 maxA = 0;

	for(u64 i=0; i<N; i++) {
		cin >> A[i];
		maxA = max(maxA, A[i]);
	}

	//sort(A.begin(), A.end(), greater<u64>());

	u64 h = maxA;
	u64 l = 0;
	
	while(l + 1 < h) {
		u64 cnt = 0;
		u64 m = l + (h - l) / 2;

		for(u64 i=0; i<N && cnt<=K; i++) {
			cnt += (A[i] + m - 1) / m - 1;
		}

		if(K < cnt) {
			l = m;
		} else {
			h = m;
		}
	}

	cout << h << endl;
	return 0;
}

Measured memory_bytes: 4808
#include <iostream>
#include <cmath>
typedef long long ll;
using namespace std;

int main(void) {
    int N;cin>>N;
    ll result = 1;
    for (int i = 0; i < N; i++) {
        ll A;cin>>A;
        if (A % 2 == 0) result *= 2;
    }
    cout << pow(3, N) - result << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a, b;
    while( cin >> a >> b )
    {
        if(a==b)
            cout << "Draw" << endl;
        else
        {
            if(a==1)
                cout << "Alice" << endl;
            else if(b==1)
                cout << "Bob" << endl;
            else if(a>b)
                cout << "Alice" << endl;
            else
                cout << "Bob" << endl;
        }
    }
    return 0 ;
}



Measured memory_bytes: 256
import scala.io.Source.stdin

object Main {
  def sieve(n:Int) = {
    val primes = { for(i<-0 to n+1)  yield  i % 2 }.toArray
    primes(1) = 0
    primes(2) = 1

    for( i <- 3 to Math.sqrt(n).toInt by 2 )
    {
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
      primes(i) = primes(i) + primes(i-1)
      primes(i+1) = primes(i+1) + primes(i)
    }

    for(i<-Math.sqrt(n).toInt+1 to n)
      primes(i) = primes(i)+primes(i-1)

    primes
  }

  def main(args:Array[String]) = {
    val p = sieve(1000000)
    println{
       { for(i <- stdin.getLines) yield p(i.toInt) }.mkString("\n")
    }
  }
}

Measured memory_bytes: 69772
N = int(input())
A = list(map(int, input().split()))

cnt1 = {}
cnt2 = {}

for i in range(N):
    tmp1 = A[i] + i + 1
    tmp2 = i + 1 - A[i]
    if tmp1 not in cnt1:
        cnt1[tmp1] = 1
    else:
        cnt1[tmp1] += 1
    if tmp2 not in cnt2:
        cnt2[tmp2] = 1
    else:
        cnt2[tmp2] += 1

diff = set(list(cnt1.keys())) & set(list(cnt2.keys()))

ans = 0
for d in diff:
    ans += cnt1[d] * cnt2[d]
print(ans)

Measured memory_bytes: 73348
#include <stdio.h>
#include <stdlib.h>
#pragma warning (disable:4996)
#define min(a, b) (((a)<(b)) ? (a) : (b))
#define max(a, b) (((a)>(b)) ? (a) : (b))

int main() {
	int n, i;
	scanf("%d", &n);
	int *c;
	c = malloc(sizeof(int)*n);
	int min = 1000001, max = -1000001;
	long long int sum = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		min = min(c[i], min);
		max = max(c[i], max);
		sum += c[i];
	}
	printf("%d %d %lld\n", min, max, sum);
	free(c);
	return 0;
}

Measured memory_bytes: 636
/* ex2_3
   person_A*/
#include<stdio.h>
int main(void){
  	int N,A;
    //入力受け取り
	scanf("%d",&N);
  	scanf("%d",&A);
    //盤面の数N*Nから白マスの数を引いたものを出力
    printf("%d\n",N*N-A);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>

using namespace std;


void exeption_handling()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  vector<int> a_copy(a.size());
  for (int i = 0; i < a.size(); ++i) a_copy[i] = a[i];
  sort(a_copy.begin(), a_copy.end(),greater<int>());
  int v_max = a_copy[0], v_max_second = a_copy[1];

  for (int i = 0; i < n; ++i)
  {
    if (a[i] == v_max) cout << v_max_second << "\n";
    else cout << v_max << "\n";
  }
}


//skip
void city_savers()
{
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n);
  for (int i = 0; i < n + 1; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];


}


void build_stairs()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];

  for (int i = n - 1; i > 0; --i)
  {
    if (h[i - 1] - h[i] > 1)
    {
      cout << "No" << "\n";
      return;
    }
    else if (h[i - 1] - h[i] == 1)
    {
      --h[i - 1];
    }
  }
  cout << "Yes" << "\n";
}


void green_bin()
{
  int n;
  cin >> n;
  map<string, int> S;
  for (int i = 0; i < n; ++i) 
  {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    S[s]++;
  }

  long long int ana_num = 0;
  for (auto value : S)
    for (int cnt = value.second - 1; cnt > 0; --cnt) 
      ana_num += cnt;
 
  cout << ana_num << "\n";
}


void alchemist()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];

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

  double v_sum = v[0];
  for (int i = 1; i < n; ++i) v_sum = (v_sum + v[i]) / 2;

  cout << v_sum << "\n";
}


void lower_atc()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];


  int tmp = 0, v_max = 0;
  for (int i = 0; i < n; ++i)
  {
    if ((i != n - 1) && h[i] >= h[i + 1]) ++tmp;
    else
    {
      v_max = max(v_max, tmp);
      tmp = 0;
    }
  }

  cout << v_max << "\n";
}


void maximal_value()
{
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; ++i) cin >> b[i];

  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    if (i == 0)          a[i] = b[i];
    else if (i == n - 1) a[i] = b[i - 1];
    else                 a[i] = min(b[i - 1], b[i]);
  }

  cout << accumulate(a.begin(), a.end(), 0) << "\n";
}


int main()
{
  exeption_handling();
  //city_savers();
  //build_stairs();
  //green_bin();
  //alchemist();
  //lower_atc();
  //maximal_value();
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	vector<double> a(n+1);
	for(int i=1;i<=n;i++){
		double x;
		scanf("%lf",&x);
		a[i]=(x+1)/2.0 + a[i-1];
	}
	double ret=0;
	for(int i=0;i+k<=n;i++){
		ret=max(ret,a[i+k]-a[i]);
	}
	
	
	printf("%.10lf",ret);
    return 0;
}

Measured memory_bytes: 1792
n, k = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(n)]

td = sorted(td, key=lambda x: - x[1])

dict_td = set()
q = []
ans = 0
for i in range(k):
    if td[i][0] in dict_td:
        q.append(td[i])
    ans += td[i][1]
    dict_td.add(td[i][0])

ans += len(dict_td) ** 2

tmp_ans = ans
for i in range(k, n):
    if len(q) == 0:
        break
    if td[i][0] not in dict_td :
        minus = q.pop()
        tmp_ans += td[i][1] - minus[1]
        dict_len = len(dict_td)
        tmp_ans += (dict_len + 1) ** 2 - dict_len ** 2
        dict_td.add(td[i][0])
    ans = max(tmp_ans, ans)

print(ans)

Measured memory_bytes: 33024
<?php
/*
    Problem URL : http://abc055.contest.atcoder.jp/tasks/abc055_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d ", $N);

echo ($N * 800 - floor($N / 15) * 200) . PHP_EOL;


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

int main(){
	int pay,n,m;
	while(true){
		n=0;
		m=0;
		pay=0;	
		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					if(a[i]+a[j]<=m&&a[i]+a[j]>=pay){
						pay=a[i]+a[j];
					}
				}
		}
		if(pay!=0)
		cout<<pay<<endl;
		else
		cout<<"NONE"<<endl;
	}
	return 0;
	
}

Measured memory_bytes: 3044
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

        if(a<b && b<c) {
            System.out.printf("Yes\n");
        } else {
            System.out.printf("No\n");
        }
    } 
}


Measured memory_bytes: 26128
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>

using namespace std;

// 参考 https://misteer.hatenablog.com/entry/ARC099#C---Minimization-%E6%9C%80%E5%B0%8F%E5%8C%96
int main() {

    //
    int N, K;
    cin >> N >> K;

//    // -2 は両端
//    if ((N - 2) % (K - 1) == 0) {
//        cout << (N - 2) / (K - 1) << endl;
//    } else {
//        cout << (N - 2) / (K - 1) + 1 << endl;
//
//    }
////
    int ans = (N - 2) / (K - 1) + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,a,b;
	int t1,t2;
	scanf("%d %d %d",&n,&a,&b);
	t1 = n * a;
	t2 = b;
	if(t1>=t2)
		printf("%d\n",t2);
	else
		printf("%d\n",t1);
	return 0;
} 

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
q = int(input())
l = [0] * 100000
for i in a:
    l[i-1] += 1
for i in range(q):
    x,y = map(int, input().split())
    hoge = l[x-1]
    s -= hoge*x
    s += hoge*y
    l[y-1] += hoge
    l[x-1] = 0
    print(s)
    


Measured memory_bytes: 20712
fun main(args: Array<String>){
    val N = readLine()!!.toInt()
    val mochi = mutableListOf<Int>()
    val flag = mutableListOf<Boolean>()
    var count = 0
    repeat(N){
        mochi.add(readLine()!!.toInt())
        flag.add(false)
    }
    //println(mochi)

    for(i in 0..N-1){
        if(flag[i] == false){
            for(j in i+1..N-1){
                if(mochi[i] == mochi[j]){
                    count++
                    flag[i] = true
                    flag[j] = true
                }
            }
        }
        //println(flag)
    }

    val ans = N - count

    println(ans)
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int P = sc.nextInt();
		String S = sc.next();
		sc.close();

		if ( P == 2 || P == 5 ) {
			long ans = 0;
			for ( int i = N - 1 ; i >= 0 ; i-- ) {
				int digit = S.charAt(i) - '0';
				if ( digit % P == 0 ) {
					ans += i + 1;
				}
			}
			System.out.println(ans);
		} else {
			int[] mods = new int[P];
			mods[0] = 1;
			int D = 1;
			int last = 0;
			long ans = 0;
			for ( int i = N - 1 ; i >= 0 ; i-- ) {
				int digit = S.charAt(i) - '0';
				last = (D * digit + last) % P;
				ans += mods[last];
				mods[last]++;
				D = (D * 10) % P;
			}
			System.out.println(ans);
		}
	}
}


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

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

    int g;
    cin >> g;
    rep(i, n) {
        int a;
        cin >> a;
        g = __gcd(g, a);
    }

    int ans = 0;
    while (g > 1) ans++, g /= 2;

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


Measured memory_bytes: 256
#include <stdio.h>
int x,y,z;
 
int main(void){
  scanf("%d %d %d",&x,&y,&z);
  if( x <= z && y <= z ) // z => MAX
  {
    printf("%d\n",x+y+10*z);
    return 0;
  }
  
  if( z <= y && x <= y) // y => MAX
  {
    printf("%d\n",x+10*y+z);
    return 0;
  }
  
  // x => MAX
  printf("%d\n",10*x+y+z);
    
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
main(){
  int a,b,c;
  a=1;
  b=1;
  while(a<10){
    while(b<10){
      c=a*b;
      printf("%dx%d=%d\n",a,b,c);
      b++;
    }
    b=1;
    a++;
  }
return 0;
}

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

int main() {
    
    int64_t N;
    cin >> N;
    
    int64_t M = 26;
    int64_t preM = 0;
    int64_t count = 1; //桁数
    while ( M < N ){
        count = count + 1;
        int64_t pow = 1;
        for ( int64_t i = 0; i < count; ++i){
            pow = pow * 26;
        }
        preM = M;
        M = M + pow;
    }
    
    
    N = N - preM;
    
    N = N - 1;
    //cout << count << " " << N << endl;
    int64_t sho,amari;
    sho = N;
    amari = N;
    vector<int64_t> p(count);
    for ( int64_t i = 0; i < count-1; ++i){
        amari = sho % 26;
        sho = sho / 26;
        //cout << amari << endl;
        p[i] = amari;
    }
    //cout << sho << endl;
    p[count-1] = sho;
    
    for ( int64_t i = count - 1; i >= 0; --i){
        int64_t num = p[i];
        cout << (char) ('a' + num ) ;
    }
    
    /*int64_t sho,amari;
    sho = N / 26;
    amari = N % 26;
    cout << (char) ('a' + amari - 1) ;
    while ( sho ) {
        amari = sho%26;
        sho = sho/26;
        cout << (char) ('a' + amari - 1) ;
    }*/
    
    
    return 0;
}


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

int main(){
  int K,N;
  cin>>K>>N;
  vector<int> a(N);
  int maxi=0;
  for(int i=0;i<N;i++){
    int tmp;
    cin>>a.at(i);
    if(i>=1){
	tmp=a.at(i)-a.at(i-1);
    maxi=max(maxi,tmp);
    }
  }
  int mixi=min(K-maxi,a.at(N-1)-a.at(0));
  cout<<mixi<<endl;
}


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

int main(){
  int n,p,w,g,y;
  string c;
  y =0;
  cin >> n;
  for(int i = 0; i<n; i++){
    cin >> c;
    if(c == "Y"){
      y +=1;
    }
  }
  if(y == 0){
    cout << "Three" <<endl;
  }
  else{
    cout << "Four" <<endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    priority_queue<P> pq;
    sort(a.rbegin(), a.rend());
    pq.push(P(a[0], a[0]));
    ll ans = 0;
    for(int i = 1; i < n; ++i){
        P p = pq.top();
        pq.pop();
        ans += p.first;
        pq.push(P(a[i], p.first));
        pq.push(P(a[i], p.second));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8932
program test
integer(8) :: nn,k,aa(100),aaa(100),a(100),b(100),c(10000),i,a_min,atai,sig,last(100),j,count,temp


read(*,*) nn,k
read(*,*) (aa(i),i=1,nn)

a(1:nn) = aa(1:nn)

do i = 1,nn
	b(i) = i
enddo

call heapsort2(nn,a(1:nn),b(1:nn))


count = 1



do i = 1,k
	aaa(1:nn) = aa(1:nn)
	if(last(i-1) > 0 )then
		aaa(last(i-1)) = 999
	endif
	
	minimum = 999999
	do j =1,nn
		if(aaa(j) <= minimum) then
			last(i) = j
			minimum = aaa(j)
		endif
	enddo

	do j=1,nn
		if(i==1) then
			if((j .ne. last(i))) then
				c(count) = j
				aa(j) = aa(j) -1
				count = count + 1
			endif
		else
			if((j .ne. last(i-1)) .and. (j .ne. last(i))) then
				c(count) = j
				aa(j) = aa(j) -1
				count = count + 1
			endif
		endif
	enddo

	do j=1,nn
		if(j == last(i)) then
			c(count) = j
			aa(j) = aa(j) -1
			count = count + 1
		endif
	enddo

enddo

	do j=1,nn
		if(j .ne. last(k)) then
			c(count) = j
			aa(j) = aa(j) -1
			count = count + 1
		endif
	enddo


if( sum(a(1:nn))<nn*(k+1)-k .or. a(1)<1+k/2 ) then
	write(*,*) -1
else
	write(*,*) count-1
	write(*,*) c(1:count-1)
endif









contains
 
subroutine heapsort2(n,y1,y2)
 
	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n
 
	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif
 
		 i = l
		 j = l+l
 
		 do while(j <= k)
				if(j < k) then
					 if(y1(j) < y1(j+1)) j = j+1
				endif
				
				if (t1 < y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return
 
end subroutine heapsort2

end program

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=1e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }


void solve() {
      int a,b,h,m;
      cin>>a>>b>>h>>m;
      
      long double a1=(m*6);
      long double a2=(h+(m/60.0))*30;
      a1=abs(a1-a2);
      a1=a1*PI/180;
      
      long double len=(a*a)+(b*b)-2*a*b*cos(a1);
      len=sqrt(len);
      cout<<setprecision(9)<<fixed<<len<<endl;    
        				   
 }

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

return 0;	   
}


Measured memory_bytes: 4176
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n , t;
	cin>>n>>t;
	vector<int>v;
	priority_queue<int > pq;
	for(int i =0 ,j;i<n; i++)
	{
		cin>>j;
		v.push_back(j);
	}
	vector<int> k;
	pq.push(v[n-1]);
	for(int i = n-2; i>=0 ; i--)
	{
		int h = pq.top();	
		k.push_back(h-v[i]);
		pq.push(v[i]);
	}
	sort(k.begin(),k.end(),greater<int>());
	int ans = 1;
	for(int i =1;i<n-1; i++)
		if(k[i]==k[i-1])
			ans++;
		else
			break;
	cout<<ans<<endl;
	return 0;
}

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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

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

   string C1,C2;
   cin>>C1>>C2;

   bool flg = true;
   for(int i=0;i<3;i++){
      if(C1[i] != C2[2-i])flg = false;
   }
   if(flg)cout<<"YES";
   else cout<<"NO";
   return 0; 
}


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

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

    for(int i = 1;i <= 9;i++){
        for(int j = 1;j <= 9;j++){
            if(i * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())
A = [0] + list(map(int, input().split()))

B = [0]*(N+1)
for i in reversed(range(1,N+1)):
    k = i
    cnt = 0
    while k <= N:
        cnt += B[k]
        k += i
    
    if cnt%2 != A[i]:
        B[i] = 1

print(sum(B))
for i in range(1,N+1):
    if B[i] == 1:
        print(i)

Measured memory_bytes: 7348
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
    int n;
    cin>>n;
    string s;
    map<string,int>m;
    m["AC"]=0;
    m["WA"]=0;
    m["TLE"]=0;
    m["RE"]=0;
    while(n--)
    {
        cin>>s;
        m[s]++;
        
    }
    cout<<"AC"<<" x "<<m["AC"]<<endl;
    cout<<"WA"<<" x "<<m["WA"]<<endl;
    cout<<"TLE"<<" x "<<m["TLE"]<<endl;
    cout<<"RE"<<" x "<<m["RE"]<<endl;
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int a[]=new int[N];
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		int c[]=new int[100001];
		int i=0;int j=0;int k=0;
		while(j<N) {
			while(j<N&&k==a[j]) {
				i++;j++;
			}
			c[k]=i;
			k++;
			i=0;
		}
		int d[]=new int[99999];
		int x=0;
		for(int l=0;l<99999;l++) {
			d[l]=c[l]+c[l+1]+c[l+2];
			if(x<d[l])x=d[l];
		}

		System.out.println(x);
	}
}


Measured memory_bytes: 51800
def main():
    K, A, B = map(int, input().split())
    if K <= A:
        print(1)
        return
    if A <= B:
        print(-1)
        return
    ans = max(0, -(-(K-A)//(A-B))) * 2 + 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<utility>
#include<cstdio>
using namespace std;

int main(){
  int w,n;
  cin >> w >> n;
  int b[w+1];
  for(int i = 1;i < w+1;i++){
    b[i] = i;
  }
  for(int i = 0;i < n;i++){
    int c,d;
    scanf("%d,%d",&c,&d);
    swap(b[c],b[d]);
  }

  for(int i = 1;i < w+1;i++){
    cout << b[i] << endl;
  }
  
}

Measured memory_bytes: 3132
#include <iostream>

using namespace std;

int main (void) {

    int d;
    cin >> d;

    int d1 = d / 100;
    int d2 = d % 100;

    if (d1 == 0) {
        cout << (d2>0&&d2<=12?"YYMM":"NA");
    }
    else if(d2 == 0){
        cout << (d1>0&&d1<=12?"MMYY":"NA");
    }
    else if (d1 <= 12) {
        if(d2 > 12) {
            cout << "MMYY";
        }
        else {
            cout << "AMBIGUOUS";
        }
    }
    else {
        if(d2 <= 12) {
            cout << "YYMM";
        }
        else {
            cout << "NA";
        }
    }

    return 0;
}

Measured memory_bytes: 256