akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include<math.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,x;
    cin >> a >> b >> x;
    bool ans=true;
    if(a>x)
    {
        cout <<"NO";
        return 0;
    }
    if(x-a<b) ans=true;
    else ans=false;
    if(ans) cout << "YES";
    else cout << "NO";
    return 0;
}




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

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

	cin >> A >> B >> C >> D;

	if (A + B == C + D)cout << "Balanced";
	else if (A + B > C + D)cout << "Left";
	else cout << "Right";
	
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int a, b;
	cin >> a >> b;

	if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  int n;
  cin >> n;
  set<string> st;
  string pre = "";
  for (int i = 0; i < n; i++) {
    string now;
    cin >> now;
    if (i != 0) {
      if (st.count(now) || pre.back() != now.front()) {
        cout << "No" << endl;
        return 0;
      }
    }
    pre = now;
    st.insert(now);
  }
  cout << "Yes" << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,A[100001],o=0,b=0;
  cin >> N;
  REP(i,N)cin >> A[i];
  set<ll> sets,f;
  sort(A,A+N);
  vector<ll> v(0);
  for(int i=N-1;i>=0;i--){
      sets.insert(A[i]);
  }
  for(auto itr=sets.begin();itr !=sets.end();itr++){
    if((b = (upper_bound(A,A+N,*itr) - lower_bound(A,A+N,*itr))) >= 2){
      for(int i=0;i<min((int)b/2,2);i++){
        v.push_back(*itr);
      }
    }
  }
  if(v.size() < 2){
    cout << 0 << endl;
  }else{
    sort(v.begin(),v.end());
    cout << (v[v.size()-2]*v[v.size()-1]) << endl;
  }
  
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 5760
import numpy as np
import collections

A,B,M = map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))


answer=0
x=[]
y=[]
c=[]

answer = min(a)+min(b)

for i in range(M):
    x1,y1,c1 = map(int,input().split())
    if a[x1-1]+b[y1-1]-c1 < answer:
        answer = a[x1-1]+b[y1-1]-c1

#for x in c.values():
#    answer +=x*(x-1) // 2

print(answer)



Measured memory_bytes: 27504
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(void)
{
	double max,min;

	max = 0;
	min = 999999999;

	double data;
	while( cin >> data ){
		if( data > max ) max = data;
		if( data < min ) min = data;
	}

	printf("%.1f\n",max - min );

	return 0;
}

Measured memory_bytes: 0
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll x;cin>>x;
	ll ans=(x/500)*1000;
	x%=500;
	ans+=(x/5)*5;
	cout<<ans<<"\n";

	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 256
N, K = map(int, input().split(' '))
ans = (N-K)*(N-K+1)//2
if K==0:
    print(N**2)
    exit()
for n, i in enumerate(list(range(K+1,N+1))):
    ans += (n+1)*((N-i+1)//i)+max(0,(N-i+1)%i-K)
print(ans)

Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

ll dp[20][10010][2][2];
int main(void) {
    string s;
    cin >> s;
    const ll n = s.size();

    dp[0][0][0][0] = 1;
    REP(i, n) REP(j, 10000) REP(k, 2) REP(l, 2) {
        ll lim = k==0 ? s[i]-'0' : 9;
        REP(d, lim+1) {
            ll nj = (j*10 + d) % 10000, nk = k || d<lim, nl = l;
            if(nj/100 == 51 && nj%10 == 3) nl |= 1;
            dp[i+1][nj][nk][nl] += dp[i][j][k][l];
        }
    }

    ll ret = 0;
    REP(i, 10000) REP(j, 2) ret += dp[n][i][j][1];
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 8856
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define vec vector

using namespace std;

const int INF = 1e18;
const int MOD = 1e9+7;
const int MAX_N = 1e3+1;

int frac[MAX_N];
void init_frac(int N) {
  frac[0] = 1;
  for (int i = 1; i <= N; i++) {
    frac[i] = mod(frac[i-1] * i);
  }
}

int powM(int x, int n) {
  int res = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      res = mod(res * x);
    }
    x = mod(x * x);
    n >>= 1;
  }
  return res;
}

int inverse(int x) {
  return powM(x, MOD-2);
}

int perm(int n, int r) {
  if (n < 0 || n-r < 0) {
    return 0;
  }
  return mod(frac[n] * inverse(frac[n-r]));
}


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

  init_frac(n);
  int dp[MAX_N][MAX_N];
  rep(i, 0, n+1) {
    fill(dp[i], dp[i] + b+1, 0);
  }
  dp[0][a] = 1;
  for (int i = c; i*a <= n && i <= d; i++) {
    dp[i*a][a] = mod(perm(n,i*a) * inverse(powM(frac[a],i) * frac[i]));
  }

  rep(i, 0, n+1) {
    rep(j, a+1, b+1) {
      int s = 0;
      for (int k = c; j*k <= i && k <= d; k++) {
        s = mod(s + mod(dp[i - j*k][j-1] * mod(perm(n-(i-j*k), j*k) * inverse(mod(powM(frac[j],k)*frac[k])))));
      }
      s = mod(s + dp[i][j-1]);

      dp[i][j] = s;
    }
  }

  cout << dp[n][b] << endl;

  return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define ll long long int
#define vi vector <int>
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FORr(i,a,b) for(int i=b; i>=a; i--)
using namespace std;
int k,n,a[200005],b[1000000],c[1000000],cntb,cntc;
void init(){
    cin>>k>>n;
    FOR(i,1,n) cin>>a[i];
    cntb=0,cntc=0;
    FOR(i,1,2*n-1){
        if (i>n) b[++cntb]=a[i%n]; else
        b[++cntb]=a[i];
    }
    //FOR(i,1,cntb) cout<<b[i]<<" "; cout<<"\n";
    c[++cntc]=a[1]; c[++cntc]=a[n];
    FORr(i,2,n-1) c[++cntc]=a[i];
    FOR(i,1,n-1) c[++cntc]=c[cntc%n];

   // FOR(i,1,cntc) cout<<c[i]<<" ";
}
long long minn(long long a, long long b){
    if (a<b) return a; else return b;
}
void tuong_cs(){
    long long tmpb,tmpc;
    int an=a[n],a1=a[1];
    tmpb=0;
    FOR(i,1,n-1) tmpb+=(long long)sqrt(pow(b[i]-b[i+1],2));
    long long minb=tmpb;
    FOR(i,2,n){
        tmpb-=sqrt(pow(b[i-1]-b[i],2));
        int x=b[i+n-2],y=b[i+n-1];
        if (x==an && y==a1) tmpb+=k-an+a1; else
        tmpb+=sqrt(pow(x-y,2));
        minb=minn(minb,tmpb);
    }
    //cout<<tmpb<<" ";
    //FOR(i,1,cntc) cout<<c[i]<<" ";
    tmpc=0;
    tmpc+=(int)k-an+a1;
    FOR(i,2,n-1)  tmpc+=(long long)sqrt(pow(c[i]-c[i+1],2));
    long long minc=tmpc;
    FOR(i,2,n){
        if (i==2) tmpc-=(k-an+a1);
        else tmpc-=sqrt(pow(c[i-1]-c[i],2));
        int x=c[i+n-2],y=c[i+n-1];
        if (x==a1 && y==an) tmpc+=k-an+a1; else
        tmpc+=sqrt(pow(x-y,2));
        minc=minn(minc,tmpc);
    }
    //cout<<tmpc;
    cout<<minn(minb,minc);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   
    init();
    tuong_cs();
}



Measured memory_bytes: 8320
import java.util.Scanner;

public class Main {

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

			boolean[] color = new boolean[8];
			for (boolean b : color) {
				b = false;
			}

			int highRate = 0;

			for (int i = 0; i < N; i++) {
				int tmp = sc.nextInt();
				if (tmp < 400) {
					color[0] = true;
				} else if (tmp < 800) {
					color[1] = true;
				} else if (tmp < 1200) {
					color[2] = true;
				} else if (tmp < 1600) {
					color[3] = true;
				} else if (tmp < 2000) {
					color[4] = true;
				} else if (tmp < 2400) {
					color[5] = true;
				} else if (tmp < 2800) {
					color[6] = true;
				} else if (tmp < 3200) {
					color[7] = true;
				} else {
					highRate++;
				}
			}

			int min = 0;
			for (boolean b : color) {
				if (b) {
					min++;
				}
			}
			int max = min + highRate;
			if (min < 1) min = 1;
			System.out.println(min + " " + max);
		}
	}
}

Measured memory_bytes: 21972
import java.util.Scanner;
    import java.util.Arrays;
     
    public class Main
    {
     
    	public static void main(String[] args)
    	{	Scanner s = new Scanner(System.in);
                    int l = s.nextInt();
                    int i=0,k=0;
                    if(l%2==0){
                      k = l/2;
                       System.out.print(k*k);
                    }else{
                      k = l/2;
                      i = k*l - k*k;
                       System.out.print(i);
                    }
                    
                         
                    
    	}
    }

Measured memory_bytes: 23124
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
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; }

int main() {
  int n; cin >> n;
  vector<int> v(n + 1, 0);

  reps(i, 100){
    reps(j, 100){
      reps(k, 100){
        int s = i*i + j*j + k*k + i*j + j*k + k*i - 1;
        if(s + 1 > n) continue;
        v[s]++;
      }
    }
  }

  rep(i, n){
    cout << v[i] << endl;
  }
}


Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt(), m = in.nextInt();
        int [] roads_for_cities = new int[n];
        Arrays.fill(roads_for_cities, 0);
        for (int i = 0; i < m; i++){
            int a = in.nextInt();
            roads_for_cities[a-1]++;
            int b = in.nextInt();
            roads_for_cities[b-1]++;
        }
        for (int i = 0; i < n; i++) System.out.println(roads_for_cities[i]);
    }
    
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

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

    int num;
    map<ll, ll> mapping;
    for (int i = 0; i < N; i++)
    {
        cin >> num;
        mapping[num]++;
    }
    // debug
    // for (auto itr = box.begin(); itr != box.end(); itr++)
    // {
    //     cout << itr->first <s< ":" << itr->second << endl;
    //
    ll first = 0;
    ll second = 0;
    for (auto itr = mapping.begin(); itr != mapping.end(); itr++)
    {
        num = itr->second;
        if (num >= 2)
        {
            second = first;
            first = itr->first;
        }
        if (num >= 4)
        {
            second = first;
        }
    }
    ll ans = first * second;
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 9712
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	long long a[50];
	cin>>n;
	a[0]=2;
	for (int i=1;i<=n;i++)
	{
		a[i]=2*a[i-1]+2;
	}
	cout<<a[n];
	return 0;
}

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



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

  vector<string> S(0);
  
  for(int i = 0;i < N;i++) {
      vector<char> vec(10);
      string s;

      for(int j = 0;j < 10;j++) {
          cin >> vec.at(j);
      }

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

      for(int j = 0;j < 10;j++) {
          s.push_back(vec.at(j));
      }
    //   cout << s << endl;
      S.push_back(s);
      
  }

  long long ans = 0,count = 1;
  
  sort(S.begin(),S.end());
    // for(int i = 0;i < N;i++) {
    //      cout << S.at(i) << endl;
    //  }

  for(int i = 0;i < N - 1;i++) {
      
      if(S.at(i) == S.at(i + 1) && i != N - 2) {
          count++;
      }else if(S.at(i) != S.at(i + 1) || i == N - 2) {
            
            if(i == N - 2 && S.at(i) == S.at(i + 1)) count++;
            if(count % 2 != 0) {
                ans += (count - 1) / 2 * count;
            }else {
                ans += count / 2 * (count - 1);
            }

            count = 1;
      }

    //  cout << i << " ";
    //  cout << count;
    //  cout << " " << ans << endl;
  }

    //  for(int i = 0;i < N;i++) {
    //      cout << S.at(i) << endl;
    //  }
    cout << ans << endl;
  }




Measured memory_bytes: 7284
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    long long n,a[200010];
    long long b;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]=a[i]-i-1;
    }
    sort(a,a+n);
    b=a[n/2];
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=abs(a[i]-b);
    }
    cout<<ans<<endl;
    return 0;
}




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

int main() {
    ll d,s,t;
    cin >> d >> s >> t;
    if (d <= s*t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
 char a,c,d,e;
  cin>>a>>c;
     if(a<c){
    cout<<"<"<<endl;
     }
  else if(a==c){
 cout<<"="<<endl;
  }
  else{
    cout<<">"<<endl;
    }
     
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
str N;
int main(){
  cin>>N;
  int ns=N.size();
  bool f=true;
  rep1(i,ns-1){
    if(N[i]!='9'){
      f=false;
      break;
    }
  }
  int x=N[0]-'0';
  if(f) prin(x+(ns-1)*9);
  else prin(x-1+(ns-1)*9);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()

# R, G, Bの順
# [n + 10][2][2][2]
dp = [[[[0 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(n+10)]

dp[0][0][0][0] = 1
for i in range(n):
    ch = s[i]
    
    for p in range(2):
        for q in range(2):
            for r in range(2):
                dp[i+1][p][q][r] = dp[i][p][q][r]

    if ch == 'R':
        dp[i+1][1][0][0] += dp[i][0][0][0]
        dp[i+1][1][1][0] += dp[i][0][1][0]
        dp[i+1][1][0][1] += dp[i][0][0][1]
        dp[i+1][1][1][1] += dp[i][0][1][1]
    elif ch == 'G':
        dp[i+1][0][1][0] += dp[i][0][0][0]
        dp[i+1][0][1][1] += dp[i][0][0][1]
        dp[i+1][1][1][0] += dp[i][1][0][0]
        dp[i+1][1][1][1] += dp[i][1][0][1]
    else:
        dp[i+1][0][0][1] += dp[i][0][0][0]
        dp[i+1][1][0][1] += dp[i][1][0][0]
        dp[i+1][0][1][1] += dp[i][0][1][0]
        dp[i+1][1][1][1] += dp[i][1][1][0]

ans = dp[n][1][1][1]

# ans = s.count('R') * s.count('G') * s.count('B')

# print(ans)

for i in range(n-2):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k >= n:
            break
        if s[i] != s[j] != s[k] != s[i]:
            ans -= 1
            # print(i,j,k)


print(ans)


Measured memory_bytes: 11972
#include <stdio.h>
#include <string.h>
int main(void)
{
	int n,l,i,j;
	char s[101][101],tmp[101];
	scanf("%d%d",&n,&l);
	for(i=0; i<n; i++){
		scanf("%s",s[i]);
	}
	for(i=0; i<n; i++){
		for(j=i+1; j<n; j++){
			if(strcmp(s[i],s[j])>0){
				strcpy(tmp,s[i]);
				strcpy(s[i],s[j]);
				strcpy(s[j],tmp);
			}
		}
	}
	for(i=0; i<n; i++){
		printf("%s",s[i]);
	}
	puts("");
	return 0;
}

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

# define fori(i,n)          for(int i=0;i<n;i++)
# define forl(i,n)          for (ll i=0;i<n;i++)
# define pb                 push_back
# define mp                 make_pair
# define X                  first
# define Y                  second
# define all(v)             v.begin(),v.end()
# define in_ar_int(arr,n)   int arr[n]; fori(i,n) cin >> arr[i];
# define in_ar_ll(arr,n)    ll arr[n]; fori(i,n) cin >> arr[i];
# define endl               "\n"
# define R0                 return 0
# define mod                1000000007
# define pi                 3.1415926536


typedef long long ll;
typedef string str;

 
ll power (ll a, ll b){
    ll ans=1;
    while(b){
		if (b & 1) ans*=a;
		a*=a;
		b/=2;
    }
    return ans;
}

bool isprime(int n) { 
    if (n <= 1) return false; 
    if (n <= 3) return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6){
		if (n%i == 0 || n%(i+2) == 0) 
		return false; 
	}
    return true; 
} 

long long nCr(int n,int r){
    if(n==r) return 1;
    else if (r==0) return 1;
    else return nCr(n-1,r-1)+nCr(n-1,r);
}

int sdigit(int x){
    int ans=0;
    while(x){
		ans+=x%10;
		x/=10;
    }
    return ans;
}

int bs(int a[],int b,int l,int r){
    int mid=l + (r-l)/2;
    if(l>r) return -1;
    if(a[mid]==b||l==r)	return mid;
    if(a[mid]>b)	return bs(a,b,l,mid-1);
    else return bs(a,b,mid+1,r);
}

long long  gcd(int a,int b){
    if (b==0) return a;
    return gcd(b,a%b);
}


void solve(){
    int n;
    cin >> n;
    n=n%1000;
    if (n!=0) n=1000-n;
    cout << n;
}           


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int chill=1;
    // cin >> chill;
    while(chill--){
	solve();
    }
}



Measured memory_bytes: 3648
fun main(args:Array<String>):Unit {
    var n = readLine()!!.toInt()
    while (n != 0){
        val nums = readLine()!!.split(' ').map(String::toInt)
        var max = 0
        var count = 0
        nums.forEach {
            if (it != max){
                if (count == 0) {
                    max = it
                    ++count
                }else --count
            }else ++count
        }
        if (nums.count{it == max} * 2 > n){
            println(max)
        }else{
            println("NO COLOR")
        }
        n = readLine()!!.toInt()
    }
}


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

#define pb push_back
#define PI acos(-1.00)
#define mem(t, v) memset ((t), v, sizeof(t))
#define mk make_pair
#define ll long long int



int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << max(max(a+b, a-b), a*b);

    return 0;
}

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

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    LL ans = 0;
    int cnt = 0;
    REP(i,0,n) {
        if (s[i] == 'A') {
            if (i > 0 && s[i-1] != 'A') cnt = 0;
            ++cnt;
        }
        else if (s[i] == 'C') {
            if (i < 2) continue;
            if (s[i-2] != 'A' || s[i-1] != 'B') {
                cnt = 0;
                continue;
            }
            ans += cnt;
            //cnt = 1;
            s[i] = 'A';
        } 
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 640
#include <stdio.h>
int main()
{
  int X,k,cnt = 0;
  
  scanf("%d",&X);
 
  for(int i=1;i<=X;i++){
    scanf("%d" ,&k);
    if( k != i )
      cnt++;
  }
 
  if( cnt == 0 || cnt == 2)
    printf("YES\n");
  else
    printf("NO\n");
  
  return 0;
}

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

#define ALL(v) v.begin(), v.end()
typedef long long ll;



using namespace std;
int main() {
	int n;
	cin >> n;

	map<int, int> cnt;

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		cnt[a]++;
		cnt[a + 1]++;
		cnt[a - 1]++;

	}
	
	int maxx = 0;
	for (auto& x :cnt)
	{
		maxx = max(maxx, x.second);
	}
	
	
	cout << maxx << endl;


}

Measured memory_bytes: 4736
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author emli
 */


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


class B1 {
public:
    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);

        long long s = 100;

        long long k;

        cin >> k;

        int ans = 0;
        while(s < k){
            s += (s / 100);
            ans++;
        }

        cout << ans << endl;
	}
};


int main() {
	B1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int n, a, b, c, l[30];
int ret = INF;

int solve(int a, vector<int> v) {
    int sum = 0;
    int ret0 = 0;
    if (v.size() == 0) {
        return INF;
    }
    rep(i, v.size()) {
        ret0 += 10;
        sum += v[i];
    }
    ret0 -= 10;
    ret0 += abs(sum - a);
    return ret0;
}

void dfs(int i, int use[20]) {
    if (i == n) {
        vector<int> vs[4];
        rep(j, n) {
            if (use[j] == 0) {
                vs[0].pb(l[j]);
            } else if (use[j] == 1) {
                vs[1].pb(l[j]);
            } else if (use[j] == 2) {
                vs[2].pb(l[j]);
            } else if (use[j] == 3) {
                vs[3].pb(l[j]);
            }
        }
        int sum0 = 0;
        sum0 += solve(a, vs[1]);
        sum0 += solve(b, vs[2]);
        sum0 += solve(c, vs[3]);
        ret = min(sum0, ret);
        return;
    }

    use[i] = 0;
    dfs(i + 1, use);
    use[i] = 1;
    dfs(i + 1, use);
    use[i] = 2;
    dfs(i + 1, use);
    use[i] = 3;
    dfs(i + 1, use);

    return;
}

int main() {
    cin >> n >> a >> b >> c;
    rep(i, n) cin >> l[i];
    int u[20];
    dfs(0, u);

    cout << ret;

    /* ====================================== */
    cout << endl;
    return 0;
}

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

const int N = 123456;
bool b[2*N+1];

int main() {
    int i, j, n, res;
    memset(b, true, sizeof(b));
    b[0] = b[1] = false;
    for (i=0; i*i<=2*N; i++) {
        if (b[i]) {
            for (j=i+i; j<=2*N; j+=i) {
                b[j] = false;
            }
        }
    }

    while (cin >> n) {
        if (n == 0) {
            break;
        }
        res = 0;
        for (i=n+1; i<=2*n; i++) {
            if (b[i]) {
                res++;
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    int ans=0;
    rep(i,n){
        if(i%2==0 && p[i]%2==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//

const string agct = "AGCT";

int n;
vector<map<string, int>> memo;

int dfs(string s, int idx) {
  if (idx == n) return 1;
  if (memo[idx].count(s)) return memo[idx][s];

  int ret = 0;
  for (auto c : agct) {
    string next = s + c;
    bool ok = true;
    rep(i, 4) {
      string t = next;
      if (i > 0) swap(t[i], t[i - 1]);
      if (t.find("AGC") != string::npos) ok = false;
    }
    if (ok) ret = (ret + dfs(s.substr(1) + c, idx + 1)) % mod;
    
  }
  return memo[idx][s] = ret;
}

int main() {
  cin >> n;
  memo.resize(n);
  cout << dfs("TTT", 0) << endl;
}

Measured memory_bytes: 4088
#include<stdio.h>

int main(void)


{


int W,H,x,y,r;


scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);


if(W<x+r||x-r<0||H<y+r||y-r<0){


printf("No\n");


}else{


printf("Yes\n");


}


return 0;


}

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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) {
        cin >> a[i];
        a[i]--;
    }

    set<int> visited;
    vector<int> path;
    int now = 0;
    while (visited.count(now) == 0) {
        path.push_back(now);
        visited.insert(now);
        now = a[now];
    }

    int s = find(path.begin(), path.end(), now) - path.begin();
    int loop = (int)path.size() - s;
    if (k < s) {
        cout << path[k] + 1 << endl;
    } else {
        cout << path[(k - s) % loop + s] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 13896
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 13976
#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__) << "] "

using ll = long long;

int main() {
    int a;
    cin>>a;
    for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==a){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
    cout<<"No"<<endl;
}


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

int main(){
  int r, d, x;
  cin >> r >> d >> x;
  rep(i,10) {
    x = r*x - d;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct Edge {
  int to, w;
};

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vec<Edge, 2> G(N);
    for (int i = 0; i < N - 1; i++) {
      int u, v, w;
      cin >> u >> v >> w;
      --u;
      --v;
      w %= 2;
      G[u].push_back({v, w});
      G[v].push_back({u, w});
    }
    vector<int> res(N);
    function<void(int, int, int)> dfs = [&](int v, int p, int c) {
      res[v] = c;
      for (auto& e : G[v]) {
        if (e.to == p) continue;
        dfs(e.to, v, (c + e.w) % 2);
      }
    };
    dfs(0, -1, 0);
    for (int v = 0; v < N; v++) cout << res[v] << endl;
  }
  return 0;
}


Measured memory_bytes: 9728
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def lcm(x, y):
    return x//gcd(x, y)*y


n = int(input())
ans = 1
for i in range(n):
    t = int(input())
    ans = lcm(ans, t)

print(ans)

Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	double a, b, h, m; cin >> a >> b >> h >> m;
	//角度をラジアンで求める必要がある。
	//(h/12)*2pi,(m/60)*2pi

	double ang1 = ((double)(h*60.0+m) / (double)720) * (double)2 * (double)PI;
	double ang2 = ((double)m / (double)60) * (double)2 * (double)PI;

	double ang = ang1 - ang2;

	double base = a * a + b * b - (double)2 * a*b*cos(ang);

	double ans = sqrt(base);

	cout << fixed << setprecision(10) << ans << endl;

	return 0;

}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

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

  int p[n];
  REP(i, n) {
    cin >> p[i];
  }

  int ct = 0;
  REP(i, n) {
    if (p[i] == i + 1) {
      if (i + 1 == n) {
        swap(p[i], p[i - 1]);
      } else {
        swap(p[i], p[i + 1]);
      }
      ct++;
    }
  }
  cout << ct << endl;
}

Measured memory_bytes: 640
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	A=list(map(int,input().split()))

	ans=10**18
	cnt=0

	Asum=sum(A)
	for i in range(n):
		cnt+=A[i]
		ans=min(ans,abs(Asum-2*cnt))
	print(ans)









if __name__ == "__main__":
	main()


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

int main(void){
    int n, k, w[100000];
    cin >> n >> k;
    for(int i = 0; i < n; ++i) cin >> w[i];

    long long left = 0, right = 100000 * 10000, mid;
    while(left < right){
        mid = (left + right) / 2;
        int count = 0;
        bool can = false;
        for(int i = 0; i < k; ++i){
            long long t = 0;
            while(t + w[count] <= mid){
                t += w[count++];
                if(count == n) can = true;
            }
            if(can) break;
        }
        if(count >= n) right = mid;
        else left = mid + 1; 
    }
    cout << left << endl;
    return 0;
}


Measured memory_bytes: 3480
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int N = sc.nextInt();
      int count = 0;

      String S = sc.next();
      char[] s = new char[N];
      for (int i = 0; i < s.length; i++) {
         s[i] = S.charAt(i);
      }

      for (int i = 0; i < s.length-2; i++) {
         if (s[i]=='A') {
            if(s[i+1]=='B'){
               if(s[i+2]=='C'){
                  count = count + 1;
               }
            }
         }
      }

      System.out.println(count);
   }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main (){
  ll n,res=0;cin>>n;
  for(ll i=1;i<=1000000;i++){

      ll j = n/i;

      if(j==0)continue;
      if(i*j<n)res+=j;
      if(i*j==n)res+=(j-1);
  }
  cout<<res<<endl;
  //main();
  return 0;
}


Measured memory_bytes: 3640
N = input()
pt,px,py = 0,0,0
for _ in range(N):
  t,x,y = map(int, raw_input().split())
  if abs(px-x)+abs(py-y)<=t-pt and (abs(px-x)+abs(py-y))%2==abs(t-pt)%2:
    pass
  else:
    print "No"
    exit(0)
  pt,px,py = t,x,y
print "Yes"


Measured memory_bytes: 5764
#include <bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0 && m==0)break;
		
		double sei[101][101];//n^n
		double dp[101][101]={};//m*n
		double ans=0.0;
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>sei[i][j];
			}
		}
		
		/*for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<sei[i][j]<<" ";
			}
			cout<<endl;
		}*/
		
		
		for(int i=0;i<n;i++)
			dp[1][i]=1.0;
		for(int i=1;i<=m;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					//cout<<i<<" "<<j<<" "<<k<<endl;
					if(dp[i][j]*sei[j][k]>=dp[i+1][k])
					dp[i+1][k]=dp[i][j]*sei[j][k];
				}
			}
		}
		for(int i=0;i<n;i++)
			ans=max(dp[m][i],ans);
		/*for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				cout<<dp[i][j]<<" ";
			}
			cout<<endl;
		}*/
		printf("%.2f\n",ans);
		//cout<<ans<<endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';

int main (){
    vector<vector<int>>vec(3,vector<int>(3));
    for(int i=0;i<3;i++){
        for(int j=0; j<3;j++){
            cin >> vec[i][j];
        }
    }
    int a2,b2,b3,a3;
    for(int i=-10000;i<10000;i++){
        for(int j=-10000;j<10000;j++){

            b2=vec[0][1]-i;
            b3=vec[0][2]-i;
            a2=vec[1][0]-j;
            a3=vec[2][0]-j;
            if(i+j==vec[0][0] && a2+b2==vec[1][1] && a3+b3==vec[2][2] && a2+b3==vec[1][2] && a3+b2==vec[2][1]){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}

signed main(){
  int n; cin>>n;
	VI p(n); rep(i,n) cin>>p[i];
	int cnt = 0; bool flg = false;
	rep(i,n){
		if(i+1==p[i]){
			if(!flg){
				cnt++; flg=true;
			}else{
				flg=false;
			}
		}else{
			flg = false;
		}
	}
	cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(int, input().split())
s = 1
e = N
for i in range(M):
	if s < L[i]:
		s = L[i]
	if e > R[i]:
		e = R[i]
if s > e:
	print(0)
else:
	print(e-s+1)

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;

  vector<ll> a(N); rep(i, N) cin >> a[i];
  ll a_max = a[0];
  ll a_min = a[0];
  ll ans = 0;
  rep(i, N) {
    chmax(a_max, a[i]);
    chmin(a_min, a[i]);
  }
  ans = a_max - a_min ;
  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    vector<char> rank(n);
    rep(i, n){
        cin >> rank.at(i);
    }
    int rank_a = 0;
    int rank_b = 0;
    rep(i, n){
        char r = rank.at(i);
        
        if (r == 'c') cout << "No" << endl;
        
        else if (r == 'a'){
            if (rank_a + rank_b < a+b){
                rank_a ++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        else{
            
            if (rank_a + rank_b < a+b){
                if (rank_b < b){
                    rank_b ++;
                    cout << "Yes" << endl;
                }
                else cout << "No" << endl;
            }
            else cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 768