akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>
#include <thread>
#include <fstream>

using namespace std;

//const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
const int mod = int(1e9) + 7;
//const int inf = 1e7;
//const long long infLL = 1e16;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 100500; //       e6
const int SZ = 122;

long long a[MX];

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n = 50;
    long long k;
    cin >> k;
    long long kk = k / n;
    if(k % n) kk++;
    for(int i = 0; i < n; i++){
        a[i] = n - 1 + kk;
    }
    kk *= n;
    kk -= k;
    while(kk--){
        int pos = 0;
        for(int i = 0; i < n; i++){
            a[i]++;
            if(a[i] > a[pos]) pos = i;
        }
        a[pos] -= n + 1;
    }
    cout << n << endl;
    for(int i = 0; i < n ; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
    return 0;
}


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1e9;
const int MOD = 1000000007;
const int N = 202055;
const int M = 1211;

void solve() {
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;

    for (int i = 0; i < n; i++){
        cout << s[i] << t[i];
    }

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

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

public class Main{
  public static void main(String[] args) {
    try {
      Scanner sc = new Scanner(System.in);
      int a,b;
      a= Integer.parseInt(sc.next());
      b= Integer.parseInt(sc.next());

      if(a<=b){
        System.out.println(a);
      }else{
        System.out.println(a-1);
      }

    }
    catch (Exception e) {

    }
  }
}


Measured memory_bytes: 20948
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        ArrayList<int []> key = new ArrayList<>();
        
        for(int i = 0; i < M; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = 0;
            for(int j = 0; j < b; j++){
                int d = sc.nextInt();
                c |= 1 << d - 1;
            }
            int[] array = {c, a};
            key.add(array);
        }
        
        int[] dp = new int[1 << N];
        for(int i = 0 ; i < 1 << N; i++){
            dp[i] = 2_000_000_000;
        }
        
        dp[0] = 0;
        
        for(int i = 0; i < 1 << N; i++){
            for(int j = 0; j < M; j++){
                int k = i | key.get(j)[0];
                int cost = dp[i] + key.get(j)[1];
                dp[k] = Math.min(dp[k], cost);
            }
        }
        
        System.out.println( dp[(1 << N) - 1] == 2_000_000_000 ? -1 : dp[(1 << N) -1] );
    }
}


Measured memory_bytes: 32336
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    ll n, mi;
    vector<ll> a(5);
    cin >> n;
    rep(i, 5)cin >> a.at(i);
    mi = *min_element(all(a));
    cout  << (n+mi-1)/mi+4;
}

Measured memory_bytes: 256
#include <stdio.h>
#define white 0
#define black 1
int n,m,i,a,b,ans=0;
int col[9]={white};
int r[30][30];
void dfs(int u){
    for(int i=1;i<=n;i++){
        if(col[i]==white)break;
        if(i==n){ans++;
        return ;
        }
    }
    for(int v=1;v<=8;v++){
        if(r[u][v]==1&&col[v]==white){
            col[v]=black;
            dfs(v);
            col[v]=white;
        }
    }
    }
int main(void){
    int i,j,a,b;
    //n頂点、m辺
    scanf("%d %d",&n,&m);
    //m個の辺.頂点a[i]とb[i]をつなぐ
    for(i=1;i<=m;i++){
        scanf("%d %d",&a,&b);
        r[a][b]=1;
        r[b][a]=1;
    }
    col[1]=black;
    dfs(1);
    printf("%d\n",ans);
}


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

int main() {
    int N, D;
    cin >> N >> D;
    int w = 2*D + 1;

    int ans = 0;

    for (int i = 0; ; i++){
        N -= w;
        ans ++;
        if (N <= 0){
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b;
  while(scanf("%d",&a)!=EOF){
    b=0;
    for(int i=0;i<=9;i++){
      for(int j=0;j<=9;j++){
	for(int k=0;k<=9;k++){
	  for(int l=0;l<=9;l++){
	    if(i+j+k+l==a) b++;
	  }
	}
      }
    }
    cout<<b<<"\n";
  }
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
vector<int> nums = {0,2,5,5,4,5,6,3,7,6};
string dp[11000];
void chmax(string &a,string b){
    if(a == "-")a = b;
    else if(a.size() < b.size())a = b;
    else if(a.size() == b.size()){
        if(a < b)a = b;

    }
}
signed main(){
    int n,m;cin >> n >> m;
    char a[m];
    rep(i,m)cin >> a[i];
    rep(i,11000)dp[i] = "-";
    dp[0] = "";
    rep(i,n+1){
        if(dp[i] == "-")continue;
        rep(j,m){
            chmax(dp[i+nums[a[j] - '0']],dp[i] + a[j]);
        }
    }
    cout << dp[n] << endl;
    
    


    
    return 0;
}

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

int main(){
    int a1,a2,a3;
    cin>>a1>>a2>>a3;
    
    if(a1+a2+a3>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    
    return 0;
}

Measured memory_bytes: 3640
import numpy as np

N, D = map(int, input().split())
X = np.zeros([N, D], dtype = int)
for n in range(N):
    X[n] = list(map(int, input().split()))

cnt = 0
for n in range(N - 1):
    for n2 in range(n + 1, N):
        if (((X[n] - X[n2]) ** 2).sum() ** 0.5).is_integer():
            cnt += 1

print (cnt)


Measured memory_bytes: 12396
n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)

Measured memory_bytes: 19428
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  
  vector<int>check(10);
  check[a]++;
  check[b]++;
  check[c]++;
  
  bool ans = false;
  
  for(int i=0;i<9;i++){
    if(check[i] == 2) ans = true;
  }
  
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


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

int main(){
	
	int c[3];
	while(cin>>c[0]){
	for(int i=1;i<3;i++)
		cin>>c[i];
	int s=0;
	double p=0;
		for(int i=1;i<=10;i++){
		if(i!=c[0]||i!=c[1]||i!=c[2]){
			if(i+c[0]+c[1]<=20)
				s++;
		}
		}
		//cout<<s<<endl;
		p=s*100/7;
		//cout<<p<<endl;
		if(p>=50)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	
	}
		
		

}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
int main()
{
    ll m,n,h,w,H,W,ans=0;
    scanf("%lld%lld%lld",&h,&w,&n);
    H=h;
    W=w;
    while(n>0)
    {
        //printf("n=%lld\n",n);
        if(h>w&&H>0)
        {
            if(n<=0)
                break;
            n-=h;
            H--;
            w--;
            ans++;
        }
        if(h<w&&W>0)
        {
            if(n<=0)
                break;
            n-=w;
            W--;
            h--;
            ans++;
        }
        if(w==h&&W>0)
        {
            if(n<=0)
                break;
            n-=w;
            W--;
            h--;
            ans++;
        }
        if(h==w&&H>0)
        {
            if(n<=0)
                break;
            n-=h;
            H--;
            w--;
            ans++;
        }
    }
    printf("%lld\n",ans);

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
 int i,n;
 string s;
 cin >> n;
 cin >> s;
 for(i=0;i<s.length();i++)
 {
  int p=int(s[i]+n);
  if(p>90)
  p-=26;
  s[i]=(char)p;
 }
 cout << s;
 return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){	
	int a,b,c,d,e,f,g,h;
	cin>>a>>b>>c>>d;
	e=c-d+b;
	f=d+c-a;
	g=a-d+b;
	h=b+c-a;
	cout<<e<<' '<<f<<' '<<g<<' '<<h;
}

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

using namespace std;
typedef long long ll;

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

  int r = 0;
  int b = 0;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == 'R')
    {
      r++;
    }
    else
    {
      b++;
    }
  }

  if (r > b)
  {
    cout << "Yes" << endl;
  }
  else
  {
    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++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	SORT(a);
	int index = -1;
	REP(i, n) {
		if (a[i] < 0) {
			index = i;
		}
	}
	if (index == n-1) {
		index = n - 1;
	}
	else if (index == -1) {
		index = 1;
	}
	else {
		index++;
	}
	int t = n-1-index;
	vector<ll> x(n - 1), y(n - 1);
	int temp = a[0];
	REP(i, t) {
		x[i] = temp;
		y[i] = a[n - 1 - i];
		temp = x[i] - y[i];
	}
	x[t] = a[n - 1 - t];
	y[t] = temp;
	temp = x[t] - y[t];
	REP(i, index-1) {
		x[i+t+1] = temp;
		y[i+t+1] = a[i + 1];
		temp = x[i + t + 1] - y[i + t + 1];
	}
	put(temp);
	REP(i, n - 1) {
		cout << x[i] << " " << y[i] << endl;
	}
	/*if (n % 2 == 0) {
		ll m = 0;
		vector<ll> x(n - 1), y(n - 1);
		vector<ll> plus(n / 2), minus(n / 2);
		REP(i, n/2) {
			plus[i] = a[i + n / 2];
			minus[i] = a[i];
		}
		REP(i, n/2) {
			m += plus[i] - minus[i];
		}
		ll temp = minus[0];
		REP(i, n-1) {
			if (i % 2 == 0) {
				x[i] = plus[i/2];
			}
			else {
				x[i] = minus[i/2+1];
			}
			
			y[i] = temp;
			temp = x[i] - y[i];
		}
		put(temp);
		REP(i, n - 1) {
			cout << x[i] << " " << y[i] << endl;
		}
	}
	else {
		ll m=0;
		vector<ll> x(n - 1), y(n - 1);
		vector<ll> plus(n / 2 + 1), minus(n / 2);
		REP(i, n / 2) {
			plus[i] = a[i + n / 2];
			minus[i] = a[i];
		}
		plus[n / 2] = a[n - 1];
		REP(i, n / 2) {
			m += plus[i] - minus[i];
		}
		m += plus[n / 2];
		ll temp = plus[0];
		REP(i, n - 1) {
			if (i % 2 == 1) {
				x[i] = plus[i / 2 + 1];
			}
			else {
				x[i] = minus[i / 2];
			}

			y[i] = temp;
			temp = x[i] - y[i];
		}
		put(temp);
		REP(i, n - 1) {
			cout << x[i] << " " << y[i] << endl;
		}
	}*/
	
	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b){
		cout<<c<<endl;
	}else if(a==c){
		cout<<b<<endl;
	}else{
		cout<<a<<endl;
	}
	return 0;
}


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

ll LCM(ll x, ll y){
  if(x<y){swap(x,y);}
  ll i=1;
  while(true){
    if((x*i)%y==0){
      return x*i;
    }
    i++;
  }
}
int main() {
  int n; cin>>n;
  vector<ll> v(n);
  rep(i,n){
    cin>>v[i];
  }
  ll ans=v[0];
  rep(i,n){ans=LCM(ans,v[i]);}
  cout<<ans;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  cin >>n >> k;
  vector<pll> v(n);
  rep(i,n){
    cin >> v[i].fi >> v[i].se;
  }
  sort(all(v));
  ll c = 0;
  rep(i,n){
    c += v[i].se;
    if(c >= k){
      cout << v[i].fi << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
char a[200001];
int main()
{
	int i,c=1;
	
	scanf("%s",a);
	i=1;
	while(a[i]!='\0')
	{
		if(a[i]==a[i-1])
		{
			i++;
			if(a[i]=='\0')
				break;
			c++;
			i++;
			if(a[i]=='\0')
				break;
			
		}
		i++;
		c++;
	}
	
	printf("%d",c);
	
	return 0;
}


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

int main(){
int a , b , c,numop=0 ,mx,mn,bet;
scanf("%d%d%d",&a,&b,&c) ;

while(true){
  mx=max(max(a,b),c);
  mn=min(min(a,b),c);
  bet=a+b+c-mx-mn ;
  a=mx ;
  b=bet ;
  c=mn ;

   if(a==b && b==c){
     break ;
   }
   if(a>b && a-b>1 ){
       b+=2 ;
       numop++ ;
       continue ;
   }
   else if(a>b && a-b==1){
       b++ ;
       c++ ;
       numop++ ;
       continue ;
   }
  else  if(a>c && a-c >=2){
      c+=2 ;
      numop++ ;
      continue ;
   }
  else if(a>c && a-c==1){
     c+=2 ;
     numop++ ;
     continue ;

   }


}
printf("%d",numop) ;



return 0 ;
}


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

char s[20];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		vector<string>v[31];
		map<string, int>mp;
		rep(i, n) {
			int m; scanf("%s%d", s, &m);
			string t = s;
			mp[t] = 0;
			rep(j, m) {
				int d; scanf("%d", &d);
				v[d].push_back(t);
			}
		}
		rep(i, 31) {
			int p = n + 1 - v[i].size();
			for (string&s : v[i])mp[s] += p;
		}
		vector<pair<int, string>>ans;
		for (auto&p : mp)ans.push_back({ p.second,p.first });
		auto p = *min_element(ans.begin(), ans.end());
		cout << p.first << ' ' << p.second << endl;
	}
}

Measured memory_bytes: 3244
#include <stdio.h>
int main(void)
{
    int n,i,j;
    
    scanf("%d",&n);
    for(i=0;i<20;i++){
        for(j=0;j<20;j++){
            if(n==((4*i)+(7*j))){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

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

using namespace std;

int is_digit(char c) {
  return c == '0' || c == '1';
}

int is_valid(int n) {
  return 0 <= n && n < 1024;
}

int number(string &line, size_t &i) {
  int n = 0;
  while (i < line.size()) {
    if (is_digit(line[i])) {
      n = 2 * n + (line[i] - '0');
      if (!is_valid(n)) {
        i = line.size() + 1;
      }
    } else {
      return n;
    }
    ++i;
  }
  return n;
}

int expr(string &, size_t &);

int fact(string &line, size_t &i) {
  int n;
  if (line[i] == '(') {
    ++i;
    n = expr(line, i);
    ++i;
  } else if (is_digit(line[i])) {
    n = number(line, i);
  } else {
    i = line.size() + 1;
    return -1;
  }
  return n;
}

int term(string &line, size_t &i) {
  int n = fact(line, i);
  int out_num = line.size() + 1;
  while (i < line.size()) {
    if (line[i] == '*') {
      ++i;
      n *= fact(line, i);
      if (!is_valid(n)) {
        i = out_num;
      }
    } else {
      return n;
    }
  }
  return n;
}

int expr(string &line, size_t &i) {
  int m;
  int n = term(line, i);
  int out_num = line.size() + 1;
  while (i < line.size()) {
    if (line[i] == '+' || line[i] == '-') {
      char op = line[i];
      ++i;
      m = term(line, i);
      if (op == '+') {
        n += m;
      } else {
        n -= m;
      }
      if (!is_valid(n)) {
        i = out_num;
      }
    } else if (line[i] == ')') {
      return n;
    } else {
      i = out_num;
    }
  }
  return n;
}

bool is_balanced(const string &line) {
  int depth = 0;
  int count[100];
  for (int i = 0; i < 100; ++i) {
    count[i] = 0;
  }
  for (size_t i = 0; i < line.size(); ++i) {
    if (line[i] == '(') {
      ++depth;
    } else if (line[i] == ')') {
      if (depth == 0 || count[depth] == 0) {
        return false;
      }
      count[depth] = 0;
      --depth;
    } else if (line[i] == '+' || line[i] == '-' || line[i] == '*') {
      ++count[depth];
    }
  }
  return depth == 0;
}

int eval(string &line) {
  if (is_balanced(line)) {
    size_t i = 0;
    int n = expr(line, i);
    if (i == line.size()) {
      return n;
    }
  }
  return -1;
}

int solve(string &line, size_t i = 0) {
  const char *chars = "01+-*()";
  while (i < line.size()) {
    if (line[i] == '.') {
      int retval = -1;
      for (size_t j = 0; chars[j]; ++j) {
        line[i] = chars[j];
        retval = max(retval, solve(line, i + 1));
      }
      line[i] = '.';
      return retval;
    }
    ++i;
  }
  return eval(line);
}

int main() {
  string line;
  cin >> line;
  cout << solve(line) << endl;
  return 0;
}

Measured memory_bytes: 1192
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#define PI 3.14159265358979323846264338327950288
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define testP	 cout << "------------------ test ------------------" << endl;	// 動作確認テスト
#define testX(x) cout << "testout : " << x << endl;	// テストアウト
typedef long long ll;
using namespace std;
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)

// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}

// ------------------ int -> Vector 変換（桁数合わせ_digit） ------------------
vector<int> ItoVec_dig(int x, int digit) {

	vector<int> xVec;
	int X = x;

	while (x > 0) {
		int tmp = x % 10;
		xVec.insert(xVec.begin(), tmp);
		x /= 10;
	}

	if (floor(log10(X)) != digit) {
		int N = abs(digit - floor(log10(X)));
		rep(i, N-1) xVec.insert(xVec.begin(), 0);
	}
	return xVec;

}

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //



int main(void) {

	double A, B, H, M;
	cin >> A >> B >> H >> M;

	double C = abs((H * 30 + M / 2) - (6 * M));
	C = min(C, 360 - C);

	C = C / 180 * PI;
	double ans2 = (A * A) + (B * B) - (2 * A * B * cos(C));
	ans2 = (double)sqrt(ans2);

	cout << setprecision(20) << ans2 << endl;

	return 0;
}


Measured memory_bytes: 4196
s = input()

if len(s) %2 == 0:
  s = s[:-2]
else:
  s = s[:-1]
for i in range(len(s)//2):
  if s[:len(s)//2] == s[len(s)//2:]:
    print(len(s))
    exit()
  s = s[:-2]
    

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

int main() {
  int n, s = 0, m = 0;
  cin >> n;
  vector<int> v(n);
  rep(i, n){
    cin >> v[i];
    m = max(m, v[i]);
  }
  rep(i, m){
    int t = 0;
    bool b = 0;
    rep(j, n){
      if(b && v[j] < i+1) b = 0;
      else if(!b && v[j] > i){
        b = 1;
        ++t;
      }
    }
    s += t;
  }
  cout << s << endl;
  return 0;
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;

    int n , m , X , Y;
    cin>>n>>m>>X>>Y;
    int x[n];
    int y[m];
    for(int i=0; i<n; i++)
        cin>>x[i];
    for(int j=0; j<m; j++)
        cin>>y[j];

    int fl=0;
    sort(x , x+n);
    sort(y , y+m);

    if(y[0]-x[n-1]>0)
    {
        for(int i=x[n-1]+1; i <= y[0]; i++)
        {
            if(i <= Y && i>X) {
                cout<<"No War\n";
                return 0;
            }
        }
        cout<<"War\n";
        return 0;
    }
    cout<<"War\n";
    return 0;


}

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

signed main(void)
{
	long long n, x, cnt, tmpl, tmpr, dec;
	cin >> n >> x;

	vector<long long> a(n);
	rep(i, n) cin >> a[i];
	cnt = 0;
	rep(i, n - 1)
	{
		if (a[i] + a[i + 1] > x)
		{
			dec = (a[i] + a[i + 1]) - x;
			a[i + 1] -= dec;
			cnt += dec;
			if (a[i + 1] < 0)
				a[i + 1] = 0;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1024
num = int(input())
A = list(map(int, input().split(' ')))

def intersection(A,N):

    for i in range(len(A)): #output
        if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ')

    for i in range(1,N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v

        for i in range(len(A)):
            if i == len(A) - 1: #output
                print(A[i])
            else:
                print(A[i], end=' ')

intersection(A,num)

Measured memory_bytes: 8032
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 40)
using namespace std;
typedef long long ll;

struct edge { ll to, cap, rev; };

ll N, A[200];
vector<edge> G[200];
bool used[200];

void add_edge(ll from, ll to, ll cap) {
  G[from].push_back((edge) { to, cap, (ll) G[to].size() });
  G[to].push_back((edge) { from, 0, (ll) G[from].size() - 1 });
}

ll dfs(ll v, ll t, ll f) {
  if(v == t) return f;
  used[v] = true;
  REP(i, 0, G[v].size()) {
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0) {
      ll d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

ll max_flow(ll s, ll t) {
  ll flow = 0;
  while(1) {
    memset(used, 0, sizeof(used));
    ll f = dfs(s, t, INF);
    if(f == 0 || f == INF) break;
    flow += f;
  }
  return flow;
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  ll s = N, t = N + 1;
  REP(i, 0, N) {
    if(A[i] >= 0) {
      add_edge(s, i, A[i]);
      add_edge(i, t, 0);
    } else {
      add_edge(s, i, 0);
      add_edge(i, t, -A[i]);
    }
    REP(j, 0, i) {
      if((i + 1) % (j + 1) == 0) {
        add_edge(i, j, INF);
      }
    }
  }

  ll sum = 0;
  REP(i, 0, N) if(A[i] >= 0) sum += A[i];

  ll flow = max_flow(s, t);

  cout << sum - flow << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int h,w;
bool B[59][59];

int bfs(int i0,int j0){
	int d[30][30];
	rep(i,h) rep(j,w) d[i][j]=INF;
	d[i0][j0]=0;
	pair<int,int> Q[900];
	int head=0,tail=0; Q[tail++]=make_pair(i0,j0);
	while(head<tail){
		int i=Q[head].first,j=Q[head].second; head++;
		rep(k,4){
			int ii=i+dy[k],jj=j+dx[k];
			if(0<=ii && ii<h && 0<=jj && jj<w && B[2*i+dy[k]][2*j+dx[k]]==0
			&& d[ii][jj]>d[i][j]+1){
				d[ii][jj]=d[i][j]+1;
				Q[tail++]=make_pair(ii,jj);
			}
		}
	}
	return d[h-1][w-1];
}

int main(){
	for(;scanf("%d%d",&h,&w),h;){
		rep(i,2*h-1) rep(j,2*w-1) B[i][j]=false;
		rep(i,2*h-1){
			if(i%2==0){
				rep(j,w-1){
					int b; scanf("%d",&b);
					B[i][2*j+1]=b;
				}
			}
			else{
				rep(j,w){
					int b; scanf("%d",&b);
					B[i][2*j]=b;
				}
			}
		}

		// cost[i][j][k] := ( (i,j) から出発して, (i,j) の方向 k にあるドアが使えないときの, ゴールまでの最短距離 )
		int cost[30][30][4];
		rep(i,h) rep(j,w) rep(k,4) {
			int y=2*i+dy[k],x=2*j+dx[k];
			if(0<=y && y<2*h-1 && 0<=x && x<2*w-1){
				int tmp=B[y][x];
				B[y][x]=1;
				cost[i][j][k]=bfs(i,j);
				B[y][x]=tmp;
			}
			else{
				cost[i][j][k]=bfs(i,j);
			}
		}

		int dp[30][30]; // dp[i][j] := ( (i,j) から出発したときの解 )
		rep(i,h) rep(j,w) dp[i][j]=INF;
		dp[h-1][w-1]=0;
		while(1){ // トポロジカル順序がよくわからんので Bellman-Ford っぽく緩和する
			bool changed=false;
			rep(i,h) rep(j,w) {
				int tmp1=0;
				rep(k,4){
					tmp1=max(tmp1,cost[i][j][k]); // (i,j) に隣接するドアが使えなかったとき
				}
				int tmp2=INF;
				rep(k,4){
					int ii=i+dy[k],jj=j+dx[k];
					if(0<=ii && ii<h && 0<=jj && jj<w && B[2*i+dy[k]][2*j+dx[k]]==0){
						tmp2=min(tmp2,dp[ii][jj]+1); // (i,j) と隣接しないどこか他のドアが使えなかったとき
					}
				}
				tmp1=max(tmp1,tmp2);

				if(dp[i][j]>tmp1){
					dp[i][j]=tmp1;
					changed=true;
				}
			}

			if(!changed) break;
		}

		printf("%d\n",dp[0][0]<INF?dp[0][0]:-1);
	}

	return 0;
}

Measured memory_bytes: 1060
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>


using namespace std;


typedef long long ll;
typedef long double ld;


const ll MOD = 1000000007ll;


ll modSum(ll a, ll b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}


ll modProd(ll a, ll b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}


ll getPow(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPow(x, e/2);
    return modProd(tmp, tmp);
  } else {
    ll tmp = getPow(x, e-1);
    return modProd(tmp, x);
  }
}


bool isEven(int x) {
  int tmp = ((x % 2) + 2) % 2;
  return tmp == 0;
}


bool isMultipleOfFour(int x) {
  return isEven(x) && isEven(x / 2);
}







ll N, S;


ll getSumOfDigitsInBase(ll n, ll b) {
  ll ret = 0;
  while (n > 0) {
    ret += n % b;
    n /= b;
  }
  return ret;
}


void input() {
  cin >> N >> S;
}

void preprocess() {
}

ll getAns() {
  if (S == N) {
    return N+1;
  }
  ll till = (ll)(sqrt(N)) + 1;
  for (int i = 2 ; i <= till ; i++) {
    if (getSumOfDigitsInBase(N, i) == S) {
      return i;
    }
  }
  ll target = N-S;
  ll ret = -1;
  for (ll i = 1 ; i*i <= target ; i++) {
    if (target % i == 0) {
      if (getSumOfDigitsInBase(N, (target/i)+1) == S) {
        ret = (target / i) + 1;
      }
    }
  }
  if (ret == -1 && S == 1) {
    return N;
  }
  return ret;
}

void solve() {
  cout << getAns();
}






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

  int T;
//  cin >> T;
  T = 1;

  for (int i = 0 ; i < T ; i++) {
    input();
    preprocess();
    solve();
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;
const int  Inv2 = (MOD+1)/2;

     signed main(){
  int n,k;
  cin>>n>>k;
  cout<<min(n%k,k-n%k)<<endl;
      
      
      }

        


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*void mayank()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}*/
#define ll long long
const int mxN = 1e5;
ll a[mxN + 1], b[mxN + 1];
int main()
{
	//mayank();
	ll n;
	cin >> n;
	map<int, int>m;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		m[x]++;
	}
	ll count = 0;
	for (auto it = m.begin(); it != m.end(); it++) {
		if ((*it).first < (*it).second) {
			count += ((*it).second) - ((*it).first);
		}
		else if ((*it).first > (*it).second) {
			count += (*it).second;

		}
	}
	cout << count << endl;
	return 0;
}


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

class Card{
    public:
        string letter;
        int num;
        int priority;
        Card() {
            letter = "";
            num = 0;
            priority = 0;
        }
};

Card cards[100000];

int partition(Card A[], int start, int end)
{
    int threshold = A[end].num;
    //cout << "threshold:" << threshold << endl;
    int i = start - 1;
    for (int j = start; j < end; ++j) {
        if (A[j].num <= threshold) {
            i++;
            swap(A[i], A[j]);
        }
    }
    i++;
    swap(A[i], A[end]);

    //for (int j = start; j <= end; ++j)
    //    cout << A[j].letter << A[j].num << " ";
    //cout << endl;
    return i;
}

void quickSort(Card A[], int start, int end)
{
    if (start < end) {
        int mid = partition(A, start, end);
        //cout << mid << endl;
        quickSort(A, start, mid - 1);
        quickSort(A, mid + 1, end);
    } else {
        return;
    }
}

int main()
{
    int n;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> cards[i].letter  >> cards[i].num;
        cards[i].priority = i;
    }

    quickSort(cards, 0, n - 1);

    int flag = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (cards[i].num == cards[i+1].num && cards[i].priority > cards[i+1].priority)
            flag = 1;
    }

    if (flag) {
        cout << "Not stable" << endl;
    } else {
        cout << "Stable" << endl;
    }

    for (int i = 0; i < n; ++i)
        cout << cards[i].letter << " " << cards[i].num << endl;

    return 0;
}

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

typedef pair<int, int> P;
typedef long long ll;
const int mod = 1000000007;

bool square(ll a){ll n=(ll)sqrt(a);return a==n*n;}
int digitsum(ll N,int a);//a進数におけるNの各桁の和、計算量はloga(N)
ll mpow(ll x, ll n);
ll inv_mod(ll a){return mpow(a,mod-2);}
int gcd(int x,int y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数
int lcm(int x,int y){return x*y/gcd(x,y);}//xとyの最小公倍数

int main(){
    int P,Q,R;
    cin>>P>>Q>>R;
    cout<<min(P+Q,min(Q+R,R+P))<<endl;
}

int digitsum(ll N,int a){
    if(N==0) return 0;
    int ret=0;
    ret+=digitsum(N/a,a)+N%a;
    return ret;
}
ll mpow(ll x, ll n){ //x^n(mod division) ←普通にpow(x,n)では溢れてしまうため，随時mod計算 2分累乗法だから早い
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
/*
class Fuctorical{//階乗とその逆元を求めて計算に利用するクラス
private:
    vector<ll> fac;
public:
    
    Fuctorical(ll N){
        fac.push_back(1);
        for(int i=0;i<N;i++) fac.push_back(fac[i]*(i+1)%mod);
    }

    ll fact(ll a){return fac[a];}
    ll ifact(ll a){return inv_mod(fac[a]);}

    ll cmb(ll a,ll b){
        if(a==0&&b==0) return 1;
        if(a<b||a<0) return 0;
        ll tmp =ifact(a-b)*ifact(b)%mod;
        return tmp*fac[a]%mod;
    }
};
*/

/*
class UnionFind{//UnionFind木
 private:
    vector<int> Parent;
 public:
    UnionFind(int N){
        for(int i=0;i<N;i++) Parent.push_back(-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};
*/

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b

# ほぼ愚直


N = a_int()
ans = 0
for j in range(1, N + 1):
    for k in range(j, N + 1, j):
        ans += k
print(ans)


Measured memory_bytes: 68708
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
	int Q;
	cin >> Q;

	for (int i = 0; i < Q; i++) {
		long long A, B;
		cin >> A >> B;

		if (A == B || A + 1 == B) {
			cout << 2 * A - 2 << endl;
		} else {
			long long C = sqrt(A * B);
			if (C * C == A * B) C--;

			if (C * (C + 1) >= A * B) cout << 2 * C - 2 << endl;
			else cout << 2 * C - 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#coding: utf-8
N = int(input())
A = list(map(int, input().split()))
pl = {}
mi = {}
for i in range(1, N+1, 1):
    if i+A[i-1] not in pl.keys():
        pl[i+A[i-1]] = 1
    else:
        pl[i+A[i-1]] += 1
    if i-A[i-1] not in mi.keys():
        mi[i-A[i-1]] = 1
    else:
        mi[i-A[i-1]] += 1
ans = 0
for k in pl.keys():
    if k in mi.keys():
        ans += pl[k] * mi[k]
print(ans)

Measured memory_bytes: 56616
#include<stdio.h>
#include<string.h>

int main(void)
{
	int q,a,b,d;
	int i,j,k,l,m;
        char str[1001],p[1001];
	char c[8];
	char s0[1001] = {},s1[] = "print",s2[] = "reverse",s3[] = "replace";

	scanf("%s",str);
	scanf("%d",&q);
	for(i = 0;i < q;i++){
		scanf("%s",c);
		      if(strcmp(c,s1) == 0){
				scanf("%d %d",&a,&b);
				for(j = a;j <= b;j++){
					printf("%c",str[j]);
				}
				printf("\n");
			}
			else if(strcmp(c,s2) == 0){
				scanf("%d %d",&a,&b);
				strcpy(s0,str);
				for(k = a,l = b;k <= l,l >= k;k++,l--){
					s0[k] = str[l];
					str[l] = str[k];
					str[k] = s0[k];
				}
			}
			else if(strcmp(c,s3) == 0){
				scanf("%d %d %s",&a,&b,p);
				d = 0;
				for(m = a;m <= b;m++){
					str[m] = p[d];
					d++;
				}
			}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
ll res=0;
int n,x,dat[MAXN];
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) scanf("%d",&dat[i]);
	if(dat[1]>x) res+=dat[1]-x,dat[1]=x;
	for(int i=2;i<=n-1;i++)
		if(dat[i-1]+dat[i]>x)
			res+=dat[i-1]+dat[i]-x,dat[i]=x-dat[i-1];
	if(dat[n-1]+dat[n]>x) res+=dat[n-1]+dat[n]-x;
	printf("%lld",res);	
	return 0;
}

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

int main(){
	while(1){
		int N;
		cin>>N;
		if(N==0)
			break;
		int player[N+1];
		for(int i=0;i<N+1;i++){
			player[i]=0;
		}
		int all=0;
		int num=1;
		for(int i=1;i<101;i++){
			char x;
			cin>>x;
			if(x=='M'){
				player[num]+=1;
				num++;
				if(num>=N+1){
					num=1;
				}
			}
			if(x=='S'){
				all+=player[num]+1;
				player[num]=0;
				num++;
				if(num>=N+1){
					num=1;
				}
			}
			if(x=='L'){
				player[num]+=1+all;
				all=0;
				num++;
				if(num>=N+1){
					num=1;
				}
			}
		}
		sort(player+1,player+N+1);
		for(int i=1;i<N+1;i++){
			cout<<player[i]<<" ";
		}
		cout<<all<<endl;
	}
	return 0;
}

Measured memory_bytes: 3144
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i,init , n) for (int i = init; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }

//-------------------------------------------------------------------
const ll MOD = pow(10, 9) + 7;
// a+b mod MOD
ll add_mod(ll a, ll b) {return (a % MOD + b % MOD) % MOD;}


// a-b mod MOD
ll sub_mod(ll a, ll b) {
	ll res = add_mod(a, -b);
	if (res < 0) return  res + MOD;
	return res;
}

// a*b mod MOD
ll mul_mod(ll a, ll b) {return ((a % MOD) * (b % MOD)) % MOD;}

// a^n mod MOD
ll pow_mod(ll a, ll n) {
	
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = mul_mod(res, a);
		a = mul_mod(a, a);
		n >>= 1;
	}
	return res;
}

//  a/b mod MOD
ll div_mod(ll a, ll b) { return  a * (pow_mod(b, MOD - 2)); }// a/b(mod MOD)   =  a * b^(MOD-2)   (mod MOD)

//---------------------------------------------------------------------

// nCr mod MOD
ll comb_mod(ll n, ll r) {//nCr =   {n (n-1) (n-2)  ... (n-r+1) }   /   { r (r-1) (r-2) ... (r-r+1)}
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res = mul_mod(res, n - i);
		res = div_mod(res, r - i);
	}
	return res;
}


int main(void) {

	ll n, a, b;
	cin >> n >> a >> b;

	ll ans = pow_mod(2, n) - 1;

	ll nCa = comb_mod(n, a), nCb = comb_mod(n, b);

	//ans = ans - nCa - nCb;
	ans = sub_mod(ans, nCa);
	ans = sub_mod(ans, nCb);
	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  string s;
  cin >> s;
  ll res = 0;
  int cb = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'W') res += cb;
    else ++cb;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 720
n = int(input())
a_lis = list(map(int,input().split()))
b_lis = list(map(int,input().split()))
c_lis = list(map(int,input().split()))
 
s = 0
 
for i in range(n-1):
  if a_lis[i+1] - a_lis[i] == 1:
    s += c_lis[a_lis[i]-1]
print(sum(b_lis)+s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<int> g[100005];
int f[100005],ans;
int DFS(int x){
	if(f[x]!=-1){
		return f[x];
	}
	f[x]=0;
	for(int i=0;i<g[x].size();++i){
		int y=g[x][i];
		f[x]=max(f[x],DFS(y)+1);
	}
	return f[x];
}
int main(){
	memset(f,-1,sizeof(f));
	cin>>n>>m;
	for(int i=0;i<m;++i){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
	}
	for(int i=1;i<=n;++i){
		if(f[i]==-1){
			DFS(i);
		}
		ans=max(ans,f[i]);
	}
	cout<<ans<<'\n';
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll MAX = 10000000;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> ans;
    for(ll i=MAX;i>=1;i--){
        if((i * (i - 1)) / 2 < n){
            ans.push_back(i);
            n -= i;
        }
    }
    for(ll a: ans) cout << a << endl;
}

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

typedef long long ll;

const ll INF = 1e18L + 5;

int main()
{
    ll n, w, sum = 0;
    cin >> n >> w;
    vector<int> wht(n), val(n);
    for(int i = 0; i < n; i++)
    {
        cin >> wht[i] >> val[i];
        sum += val[i];
    }

    vector<ll> dp(sum+1, INF);
    dp[0] = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = sum; j-val[i] >= 0; j--)
        {
                dp[j] = min(dp[j], dp[j-val[i]]+wht[i]);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= sum; i++)
    {
        if(dp[i] <= w)
            ans = max(ans, (ll)i);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define MP make_pair
#define fi first
#define se second

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

const int INF = 1001001001;

void Main()
{
	ll n, m;
  	cin >> n >> m;
  	vector<pii> data;
  	// data[i].fi -> 鍵情報 n bit
    // data[i].se -> コスト
  	rep(i,m){
    	int a, b;
      	cin >> a >> b;
      	int s = 0;
      	rep(j,b){
          	int c;
        	cin >> c;
          	c--;
          	s |= (1<<c); 
        }
      	data.emplace_back(s,a);
    }	
  	//rep(i,m) cout << static_cast<bitset<12>>(data[i].fi) << " " << data[i].se << endl;
	vector<int> dp(1<<n, INF);
  	dp[0] = 0; 
  	rep(s,1<<n){
    	rep(i,m){
        	int t = s | data[i].fi;
          	int cost = dp[s] + data[i].se;
          	dp[t] = min(dp[t], cost);
        }
    }
  	int ans = dp.back();
  	if(ans == INF) cout << -1 << endl;
  	else cout << ans << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

int main()
{
  long X;
  cin >> X;
  long A = 0, B = 0;
  while (true)
  {
    B = 0;
    long A5 = pow(A, 5);
    long A5X = A5-X;
    if (A5X == 0) break;
    else if (A5X < 0)
    {
      A5X *= -1;
      long B5 = 0;
      bool OK = false;
      while (B5 < A5X)
      {
        B++;
        B5 = pow(B, 5);
        if (B5 == A5X)
        {
          OK = true;
          B *= -1;
          break;
        }
      }
      if (OK) break;
    }
    else
    {
      long B5 = 0;
      bool OK = false;
      while (B5 < A5X)
      {
        B++;
        B5 = pow(B, 5);
        if (B5 == A5X)
        {
          OK = true;
          break;
        }
      }
      if (OK) break;
    }
    A++;
  }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 4064
# -*- coding: utf-8 -*-
from collections import defaultdict
K, A, B = map(int, input().split())
ans = 1
if K == 1:
    print(ans+K)
    exit()

if B - A <= 2.0:
    print(ans+K)
    exit()

if K + 1 < A:
    print(ans+K)
    exit()


x = (K - (A - 1))//2

ans += (B - A) * x + (K - 2*x)

print(ans)


Measured memory_bytes: 3316
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    // YYMM
    bool isYYMM = true;
    if (S.substr(0, 2) < "00" || "99" < S.substr(0, 2)) {
        isYYMM = false;
    }
    if (S.substr(2, 2) < "01" || "12" < S.substr(2, 2)) {
        isYYMM = false;
    }


    // MMYY
    bool isMMYY = true;
    if (S.substr(0, 2) < "01" || "12" < S.substr(0, 2)) {
        isMMYY = false;
    }

    if (S.substr(2, 2) < "00" || "99" < S.substr(2, 2)) {
        isMMYY = false;
    }

    if(isYYMM && isMMYY) {
        cout << "AMBIGUOUS" << endl;
    } else if(isYYMM) {
        cout << "YYMM" << endl;
    } else if(isMMYY) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
n = int(input())
S = input()

R = {}
G = {}
B = {}

for i in range(n):
    if S[i] == 'R':
        R[i] = None
    elif S[i] == 'G':
        G[i] = None
    else:
        B[i] = None

#print(R, G, B)

cnt = 0

cnt = len(R) * len(G) * len(B)

for b in B:
    for g in G:
        if (b + g) / 2 in R:
            cnt -= 1

for r in R:
    for b in B:
        if (r + b) / 2 in G:
            cnt -= 1

for r in R:
    for g in G:
        if (r + g) / 2 in B:
            cnt -= 1
            
print(cnt)

Measured memory_bytes: 9308