akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int func(int x)
{
    if(x%2==0)
    {
        return x/2;
    }
    else
    {
        return 3*x+1;
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    int maxL=0;
    int minR=n;
    for(int i=0;i<m;i++)
    {
        int l,r;
        cin>>l>>r;
        maxL = max(maxL,l);
        minR = min(minR,r);
    }
    if(maxL>minR)
    {
        cout<<0<<endl;
        return 0;
    }

    cout<<minR-maxL+1<<endl;;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(b),d(b),e(a,0),f(a,0);
  rep(i,b)
    cin>>c[i]>>d[i];
  rep(i,b){
  if(c[i]==1)
    e[d[i]-1]++;
  }
  rep(i,b){
  if(d[i]==a){
    f[c[i]-1]++;
  }
  }
  int p=0;
  rep(i,a){
  if(f[i]&&e[i])
    p++;
  }
  if(p){
  out("POSSIBLE");
  }
  else
    out("IMPOSSIBLE");
}


Measured memory_bytes: 9568
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int k, x;
    cin >> k >> x;

    if(k*500 >= x){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    
    
    
    return 0;
        
}

Measured memory_bytes: 256
#include <stdio.h>
long long  gcd(long long x,long long y){
	if(y==0) return x;
	else return gcd(y,x%y);
}
int main(){
	int t,i;
	long long m,n,c,sum;
	sum=0;
	while(~scanf("%d",&t)){
	scanf("%lld",&m);
	for(i=1;i<t;i++){
		scanf("%lld",&n);
		c=gcd(m,n);
		m=m/c*n;
		}
	printf("%lld\n",m);
	}
}



Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 301 

int n;
int vis[N][N][N];
ld dp[N][N][N];

ld rec(int cnt1,int cnt2,int cnt3)
{
    if(cnt1 < 0 or cnt2 < 0 or cnt3 < 0)
        return 0;
    if(cnt1 == 0 and cnt2 == 0 and cnt3 == 0)
        return 0;
    if(vis[cnt1][cnt2][cnt3] == 0)
    {
        vis[cnt1][cnt2][cnt3] = 1;
        int f = cnt1 + cnt2 + cnt3;
        dp[cnt1][cnt2][cnt3] = (ld)n/(ld)(cnt1 + cnt2 + cnt3) +  rec(cnt1-1,cnt2,cnt3)*((ld)(cnt1)/(ld)f) + rec(cnt1+1,cnt2-1,cnt3)*((ld)(cnt2)/(ld)f) + rec(cnt1,cnt2+1,cnt3-1)*((ld)(cnt3)/(ld)f);
        //cerr << cnt1 << " " << cnt2 << " " << cnt3 << " " << dp[cnt1][cnt2][cnt3] << endl;
        return dp[cnt1][cnt2][cnt3];
    }
    else
        return dp[cnt1][cnt2][cnt3];        
}

int32_t main()
{
    IOS;
    

    cin >> n;
    int a[4];
    memset(vis,0,sizeof(vis));
    memset(a,0,sizeof(a));
    for(int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        a[b]++;
    }
    cout << fixed << setprecision(12);
    cout << rec(a[1],a[2],a[3]);

}

Measured memory_bytes: 639488
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#define MAXN 100010
#define LL long long
using namespace std;

namespace Seg{
	struct node{
		int lc,rc,max;
	}a[20000010];

	int size;

	int newnode(){
		int x=++size;
		a[x].lc=a[x].rc=a[x].max=0;
		return x;
	}

	void init(){
		size=0;
		newnode();
	}

	void setMax(int x,int cl,int cr,int l,int r,int v){
		if(l<=cl && cr<=r){
			a[x].max=v;
			return;
		}
		int mid=(cl+cr)>>1;
		if(l<=mid){
			if(!a[x].lc) a[x].lc=newnode();
			setMax(a[x].lc,cl,mid,l,r,v);
		}
		if(r>mid){
			if(!a[x].rc) a[x].rc=newnode();
			setMax(a[x].rc,mid+1,cr,l,r,v);
		}
	}

	int getMax(int x,int cl,int cr,int pos){
		if(cl==cr) return a[x].max;
		int mid=(cl+cr)>>1;
		if(pos<=mid && a[x].lc) return max(a[x].max,getMax(a[x].lc,cl,mid,pos));
		if(pos>mid && a[x].rc) return max(a[x].max,getMax(a[x].rc,mid+1,cr,pos));
		return a[x].max;
	}
}

int n;
LL a[MAXN],b[MAXN],k,s[MAXN];
LL f1[MAXN],f2[MAXN];

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	scanf("%d%lld",&n,&k);
	bool flag=1;
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",a+i,b+i);
		if(b[i]==1) flag=0;
		s[i]=s[i-1]+a[i];
	}
	if(flag){
		printf("%lld\n",s[n]*2);
		return 0;
	}
	LL now=0;
	Seg::init();
	for(int i=1;i<=n;i++){
		if(b[i]==1){
			int temp=min(k-1,now+2*a[i]-1);
			if(now+1<=temp) Seg::setMax(1,0,k-1,now+1,temp,i);
			if(now+2*a[i]-1>=k) Seg::setMax(1,0,k-1,0,now+2*a[i]-1-k,i);
		}
		now=(now+2*a[i])%k;
		int temp=Seg::getMax(1,0,k-1,now);
		if(!temp) f1[i]=s[i];
		else if(temp==i){
			puts("-1");
			return 0;
		}else{
			int pre=((now-(s[i]-s[temp])*2)%k+k)%k;
			f1[i]=f1[temp]+s[i]-s[temp]+(pre-now+k)%k;
		}
	}
	Seg::init();
	now=s[n]*2%k;
	for(int i=n;i>=1;i--){
		int temp=n-Seg::getMax(1,0,k-1,now)+1;
		if(temp==n+1) f2[i]=s[n]-s[i];
		else if(temp==i+1){
			puts("-1");
			return 0;
		}else{
			int pre=(now+(s[temp-1]-s[i])*2)%k;
			f2[i]=f2[temp-1]+s[temp-1]-s[i]+(now-pre+k)%k;
		}
		now=((now-2*a[i])%k+k)%k;
		if(b[i]==1){
			int temp=min(k-1,now+2*a[i]-1);
			if(now+1<=temp) Seg::setMax(1,0,k-1,now+1,temp,n-i+1);
			if(now+2*a[i]-1>=k) Seg::setMax(1,0,k-1,0,now+2*a[i]-1-k,n-i+1);
		}
	}
	LL ans=1LL<<62;
	for(int i=1;i<=n;i++)
		if(b[i]==1){
			ans=min(ans,f1[i]+f2[i]+s[n]);
		}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 34944
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ0121();
	}
	
	class AOJ0121{
		AOJ0121(){
			init();
			while(sc.hasNextLine()){
				line = sc.nextLine().replaceAll(" ", "");
				solve();
			}
		}
		
		final int[] vx={0,1,0,-1}, vy={-1,0,1,0};
		String line;
		HashMap<String,Integer> ans;
		
		void solve(){
			System.out.println(ans.get( line ));
		}
		
		void init(){
			ans = new HashMap<String,Integer>();
			ans.put("01234567", 0);
			
			LinkedList<State> open = new LinkedList<State>();
			open.add(new State("01234567", 0, 0, 0));
			
			while(!open.isEmpty()){
				State now = open.poll();
				for(int v=0; v<4; ++v){
					int xx = now.lx+vx[v], yy = now.ly+vy[v];
					if( !(0<=xx && xx<4 && 0<=yy && yy<2))	continue;
					
					StringBuilder tmp = new StringBuilder(now.state);
					char tmp2 = tmp.charAt(xx+yy*4);
					tmp.setCharAt(xx+yy*4, tmp.charAt(now.lx+now.ly*4));
					tmp.setCharAt(now.lx+now.ly*4, tmp2);
					
					if(ans.containsKey(tmp.toString()) )	continue;
					open.add(new State(tmp.toString(), now.step+1, xx, yy));
					ans.put(tmp.toString(), now.step+1);
				}
			}
		}
		class State{
			int lx,ly,step;
			String state;
			State(String state,int step,int lx,int ly){
				this.state=state;
				this.step=step;
				this.lx=lx;
				this.ly=ly;
			}
		}
	}
}

Measured memory_bytes: 16000
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
int main()
{
	cin.tie(0);
   	ios::sync_with_stdio(false);
	double a, b, x, ans;
	cin >> a >> b >> x;
	if(x<=(a*a*b)/2){
		// cout << a << endl;
		ans = 90 - 180*atan((2*x)/(a*b*b))/M_PI;
	}
	else{
		ans = 90 - 180*atan((a*a*a)/(2*(b*a*a-x)))/M_PI;
	}
	cout << setprecision(11) << ans << endl;	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    int D, X; cin >> D >> X;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    int ans = N;
    for(int i=0; i<N; i++){
        int day = 1;
        while(day + a[i] <= D){
            day += a[i];
            ans++;
        }
    }

    cout << ans + X << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main(){
    ll ans=0;
    string s;
    cin>>s;
    ll pos=0;
    rep(i,0,s.length()){
        ll cntb=0,cntw=0,tmp=0;
        if(s[i]=='B'){
            while(s[i]=='B'){tmp++;cntb++;i++;}
            while(s[i]=='W'){cntw++;i++;}
        }
        else continue;
        //cout<<pos<<" "<<cntb<<" "<<cntw<<endl;
        ans+=(cntb+pos)*cntw;
        pos+=tmp;
        i--;
    }
    cout<<ans;
}

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

using namespace std;

int main(void) {
	int n;

	while (cin >> n) {

		bool f1 = false;

		for (int j = n - 1; j > 1; j--) {
			for (int i = 2; i <= sqrt(j); i++) {
				if ((j % i) == 0) {
					f1 = true;
					break;
				}
			}
			if (!f1) {
				cout << j << " ";
				break;
			}
			f1 = false;
		}

		bool f2 = false;

		for (int j = n + 1; true; j++) {
			for (int i = 2; i <= sqrt(j); i++) {
				if ((j % i) == 0) {
					f2 = true;
					break;
				}
			}
			if (!f2) {
				cout << j << endl;
				break;
			}
			f2 = false;
		}
	}
}

Measured memory_bytes: 3088
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
if k>=n:
    ans=max(sum(l),0)
else:
    ans=0
for i in range(n):
    for j in range(n-i):
        if j==0:
            ll=l[:i]
        else:
            ll=l[:i]+l[-j:]
        if(len(ll)>k or len(ll)==0):
            continue
        ll.sort()
        x=sum(ll)
        for jj in range(min(k-len(ll),len(ll))):
            if ll[jj]<0:
                x-=ll[jj]
            else:
                break
        ans=max(ans,x)
print(ans)

Measured memory_bytes: 40176
// AOJ GRL_5_A Diameter of a Tree
// 2018.5.4 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define INF   0x10101010
#define MAX_N 100002

typedef struct { int s, d; } QUE;
QUE que[MAX_N*2]; int top, end;
int n;
int hi[MAX_N], *to[MAX_N], *w[MAX_N];
int dist[MAX_N];

void bfs(int s)
{
	int i, t, d, nd;

	memset(dist, INF, n<<2);
	que[0].s = s, que[0].d = 0, dist[s] = 0, top = 0, end = 1;
	while (top != end) {
		s = que[top].s, d = que[top++].d;
		if (dist[s] < d) continue;
		for (i = 0; i < hi[s]; i++) {
			t = to[s][i];
			if (dist[t] == INF) {
				nd = d+w[s][i];
				dist[t] = nd, que[end].s = t, que[end++].d = nd;
			}
		}
	}
}

int treeDiameter()
{
	int i, ans_n, ans_d;
	
	bfs(0);
	ans_d = 0;
	for (i = 0; i < n; i++) if (dist[i] != INF) {
		if (dist[i] > ans_d) ans_n = i, ans_d = dist[i];
	}

	bfs(ans_n);
	ans_d = 0;
	for (i = 0; i < n; i++) if (dist[i] != INF) {
		if (dist[i] > ans_d) ans_d = dist[i];
	}
	return ans_d;
}

int main()
{
	int s, t, x, i, j, k;
	int *memo;

	n = in();
	memo = malloc(n*12);
	j = 0; for (i = 1; i < n; i++) {
		memo[j++] = s = in();
		memo[j++] = t = in();
		memo[j++] = in();
		hi[s]++, hi[t]++;
	}
	for (i = 0; i < n; i++) if (hi[i]) {
		to[i] = malloc(hi[i]<<2), w[i] = malloc(hi[i]<<2);
	}
	memset(hi, 0, n<<2);
	j = 0; for (i = 1; i < n; i++) {
		s = memo[j++], t = memo[j++], x = memo[j++];
		k = hi[s]++, to[s][k] = t, w[s][k] = x;
		k = hi[t]++, to[t][k] = s, w[t][k] = x;
	}
	free(memo);

	printf("%d\n", treeDiameter());
	return 0;
}



Measured memory_bytes: 11228
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n,m;
int w[maxn];
ll v[maxn];
ll dp[maxn];
int main()
{
    gbtb;
    cin>>n>>m;
    repd(i,1,n)
    {
        cin>>w[i]>>v[i];
    }
    repd(i,1,n)
    {
        for(int j=m;j>=w[i];j--)
        {
            dp[j]=max(dp[j],1ll*dp[j-w[i]]+v[i]);
        }
    }
    cout<<dp[m];
    return 0;
}

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

int main(){
  int p[24];
  double t[24];
  double min1,min2;
  int ansp[8];
  vector<int>losep;
  double anst[8];
  vector<double> loset;

  for(int i=0;i<24;i++)cin >> p[i] >> t[i];

  for(int j=0;j<3;j++){
    min1 = 1e+9;
    min2 = 1e+9;
    for(int i=j*8;i<(j+1)*8;i++){
      if(min1>t[i]){
	min2 = min1;
	min1 = t[i];
      }else if(min2>t[i])min2 = t[i];
    }
    for(int i=j*8;i<(j+1)*8;i++){
      if(min1==t[i]){
	ansp[j*2] = p[i];
	anst[j*2] = t[i];
      }else if(min2==t[i]){
	ansp[j*2+1] = p[i];
	anst[j*2+1] = t[i];
      }else{
	losep.push_back(p[i]);
	loset.push_back(t[i]);
      }
    }
  }
  min1 = 1e+9;
  min2 = 1e+9;
  for(int i=0;i<18;i++){
     if(min1>loset[i]){
	min2 = min1;
	min1 = loset[i];
     }else if(min2>loset[i])min2 = loset[i];
  }
  for(int i=0;i<18;i++){
    if(min1==loset[i]){
      ansp[6] = losep[i];
      anst[6] = loset[i];
    }else if(min2==loset[i]){
      ansp[7] = losep[i];
      anst[7] = loset[i];
    }
  }
  for(int i=0;i<8;i++){
    printf("%d %.2lf\n",ansp[i],anst[i]);
  }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
    int a[5];
    int n;
    int k = 0;
    int s[6] = {500,100,50,10,5,1};
    while(cin >> n){
        if(n == 0)break;
        a[k] = 0;
        int c = 1000 - n;
        for(int i = 0;i < 6;i++){
            if(c >= s[i]){
                int m = c/s[i];
                //cout << m << " ";
                a[k] += m;
                c -= m * s[i];
            }
        }
        k++;
    }
    for(int i = 0;i < k; i++){
        cout << a[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 3096
///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include<bits/stdc++.h>
using namespace std;
#define MAX 35000
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
const int N = 2e5 + 10;
ll aarray[200000+10];
ll magic[101][101];
vector<ll>primes;
bool prime[1000001];
ll cxor(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;

    if(n%4==2)
        return n+1;
    else return 0;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    makefast__
    string str;
    ll a,b,c,d,e,f,x,y,k,t,A=0,mod,B=0,L,j,i,l,r,m,n,C=0,ans,sum=0,sum1=0;
    vector<ll>v,v1;
    queue<ll>qu;
    cin>>n>>m;
    ans=cxor(n-1)^cxor(m);
    cout<<ans<<endl;





    return 0;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define rep(i, n) for (signed i = 0; i < signed(n); i++)
#define REP(i, s, n) for (signed i = signed(s); i < signed(n); i++)
#define rrep(i, n) for (signed i = signed(s) - 1; i >= 0; i--)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

void calc() {
	int n, a, b; cin >> n >> a >> b;
	int lb = a * (n - 1) + b;
	int ub = b * (n - 1) + a;
	cout << max(0ll, ub - lb + 1) << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	calc();
#ifdef _MSC_VER
	system("pause");
#endif
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

typedef long long ll;

using namespace std;

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

	int ret = 0;
	if (a == b && b == c)
		ret = 1;
	else if (a == b || b == c || c == a)
		ret = 2;
	else
		ret = 3;

	cout << ret << endl;
}

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

int main() {

  int N;
  cin >> N;

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

  vector<long long> t(N);
  vector<long long> a(N);

  t[0] = T[0];
  a[0] = A[0];

  for (int i = 1; i < N; i++) {

    long long t_ = t[i - 1] / T[i];
    
    if (t[i - 1] % T[i] != 0) {
      t_++;
    }
    
    long long a_ = a[i - 1] / A[i];
    
    if (a[i - 1] % A[i] != 0) {
      a_++;
    }
    
    long long n = max(t_, a_);
    
    t[i] = n * T[i];
    a[i] = n * A[i];
    
  }

  cout << t[N - 1] + a[N - 1] << endl;
  
  return 0;

}

Measured memory_bytes: 256
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    print(2*N*3.14159265)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10064
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n,x,i,l[150],sum=0,num=1;
    cin>>n>>x;
    for(i=0; i<n; i++)
        cin>>l[i];
    for(i=0; i<n; i++)
    {
        sum+=l[i];
        if(sum<=x)
            num++;
    }
    cout<<num<<endl;
    return 0;
}


Measured memory_bytes: 256
num = gets.to_i
initial = {"M": 0,"A": 0,"R": 0,"C": 0,"H": 0}
while num > 0 do
  num -= 1
  n = gets.to_s[0]
  if (n == "M")||(n == "A")||(n == "R")||(n == "C")||(n == "H")
    initial[n.to_sym] += 1
  end
end

count = 0
"MARCH".split("").combination(3).map do |a,b,c|
  #puts "#{a},#{b},#{c}"
 count = count + (initial[a.to_sym] * initial[b.to_sym] * initial[c.to_sym])
end


puts count


Measured memory_bytes: 1788
import math
n,a=map(int,input().split())
x=list(map(int,input().split()))+[a]
x.sort()
if n==1:
  print(abs(x[0]-x[1]))
  exit()
res=x[1]-x[0]
for i in range(1,n):
  res=math.gcd(res,x[i+1]-x[i])
print(res)

Measured memory_bytes: 20300
import sys
import math
input = sys.stdin.readline


def main():
    a, b, x = map(int, input().split())
    if x >= a*a*b/2:
        tanx = (2/a) * (b - (x/(a**2)))
        print(math.degrees(math.atan(tanx)))
    else:
        tanx = (2*x) / (a*b**2)
        print(90 - math.degrees(math.atan(tanx)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//============================================================================
// Name        : ITP_1_7_D.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

int main() {
	vector<vector<long long>> a, b;
	long long temp;
	int l,m,n;
	cin >> n >> m >> l;
	a.resize(n);
	b.resize(m);
	for(int i=0; i<n; ++i) {
		a[i].reserve(m);
		for(int j=0; j<m; ++j) {
			cin >> temp;
			a[i].push_back(temp);
		}
	}
	for(int i=0; i<m; ++i) {
		b[i].reserve(l);
		for(int j=0; j<l; ++j) {
			cin >> temp;
			b[i].push_back(temp);
		}
	}
	for(int i=0; i<n; ++i) {
		for(int j=0; j<l; ++j) {
			temp=0;
			for(int k=0; k<m; ++k) {
				temp+=a[i][k]*b[k][j];
			}
			cout << temp;
			if(j!=l-1) {
				cout << " ";
			} else {
				cout << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3156
import sys
f = sys.stdin

while True:
    n = int(f.readline())
    if n == 0:
        break
    converter = {}
    for _ in range(n):
        pre, post = f.readline().strip().split()
        converter[pre] = post
    m = int(f.readline())
    for _ in range(m):
        c = f.readline().strip()
        print(converter[c] if c in converter else c, end='')
    print()

Measured memory_bytes: 6808
program atcoder0404_C
  integer(16)::N,M,I,J,K
  read(5,*)N,M
  I=N/M
  J=N-M*I
  K=abs(N-M*(I+1))
  if(J>=K) then
     write(6,*)K
  else
     write(6,*)J
  end if
end program atcoder0404_C

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}


int anss[20000];

int extgcd(int a, int b, int &x, int &y) {
    int g = a;
    x = 1;
    y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

int mod_fact(int n,int p,int& e){
  e = 0;
  if(n==0) return 1;
  int res = mod_fact(n/p,p,e);
  e += n/p;
  if(n/p%2 != 0){
    //n!(mod p)を求める
    int t = 1;
    for(int i=1;i<=n;i++){
      t *= i;
      t %= p;
    }
    //ここまで
    return res*(p-t)%p;
  }
  //n!(mod p)を求める
  int t2=1;
  for(int i=1;i<=n;i++){
    t2 *= i;
    t2 %= p;
  }
  //ここまで
  return res * t2%p;
}

int mod_inverse(int a,int m){
  int x,y;
  extgcd(a,m,x,y);
  return (m+x%m) %m;
}

int mod_comb(int n,int k,int p){
  if(n<0||k<0||n<k) return 0;
  int e1,e2,e3;
  int a1 = mod_fact(n,p,e1),a2 = mod_fact(k,p,e2),a3 = mod_fact(n-k,p,e3);
  if(e1>e2+e3) return 0;
  return a1 * mod_inverse(a2*a3%p,p)%p;
}


signed main(){
    int n,p;
    cin >> n >> p;
    string s;
    cin >> s;
    int ans = 0;
    if(p==2){
        REP(i,s.size()){
            if((s[i]-'0')%2 == 0){
                ans += i+1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    else if(p==5){
        REP(i,s.size()){
            if((s[i]-'0')%5 == 0){
                ans += i+1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    int now = 0;
    int keta = 1;
    REP(i,s.size()){
        now += keta * (int)(s[s.size()-1-i]-'0');
        now %= p;
        anss[now] ++;
        keta *= 10;
        keta %= p;
    }
    
    anss[0] ++;
    REP(i,p){
      //cout << i << " " <<  anss[i] << endl;
        if(anss[i] <= 1) continue;
        ans += anss[i] * (anss[i] -1) /2;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int D,N;
  cin>>D>>N;
  int ans;
  if(N<100){
    ans = N * pow(100,D);
  }
  else{
    ans = (N+1)*pow(100,D);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int res[1000001];
#include<cmath>
#include<algorithm>
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    int flag=0;
    for(int i=0; i<n; i++) {
        int x=ceil(sqrt(arr[i]));
        for(int j=1; j<=x; j++) {
            if(arr[i]%j==0) {
                if(res[j]>0 && j>1 && res[j]!=i+1)
                    flag=1;
                if(res[arr[i]/j]>0 && (arr[i]/j)>1 && res[arr[i]/j]!=i+1)
                    flag=1;
                if(flag)break;
                res[j]=i+1;
                res[arr[i]/j]=i+1;
            }
        }
        if(flag)break;
    }
    if(!flag)
        cout<<"pairwise coprime"<<endl;
    else {
        int gd=0;
        for(int i=0; i<n; i++)
            gd=__gcd(gd,arr[i]);
        if(gd==1)
            cout<<"setwise coprime"<<endl;
        else
            cout<<"not coprime"<<endl;

    }
    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<string>

using namespace std;

int main(){
  int a[26]={0};
  string str;
  cin >> str;

  for(int i = 0;i < str.size();i++){
    a[str[i]%26]++;
  }
  int flag = 0;
  for(int i = 0;i < 26;i++){
    if(a[i] >= 2)
      flag = 1;
  }
  if(flag == 1)
    cout << "no" << endl;
  else{
    cout << "yes" << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n[]={0,1,2,1,3,1,3,1,1,3,1,3,1};
main(){
	string s;
	int a,b,c;
	cin>>s;
	if(s[0]==s[2])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
k = int(input())
ans = 1
for i in range(n):
    if ans+k < ans*2:
        ans = ans+k
    else:
        ans = ans*2
print(ans)


Measured memory_bytes: 60140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] line = br.readLine().split(" ");
    int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);
		double fa = Integer.parseInt(line[0]);
		double fb = Integer.parseInt(line[1]);
		int d = a/b;
		int r = a%b;
		double f = fa/fb;
		System.out.printf(d + " " + r + " " + "%5.5f",f);
	}
}

Measured memory_bytes: 24792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s;

ll res = 0;
void dfs(int i, ll cur) {
	if(i==s.size()) {
		res += cur;
		return;
	}

	ll x = 0;
	for(int j=i;j<s.size();++j) {
		x = x*10 + s[j] - '0';
		dfs(j+1, cur+x);
	}
}

int main() {
	cin>>s;
	dfs(0,0);
	cout<<res<<endl;
	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long A, long long B, long long C, std::vector<std::string> s)
{
    auto game = [](ll& n1, ll& n2, const string& s, const string& next_s) {
        if (n1 == 0 && n2 == 0) {
            cout << NO << endl;
            exit(EXIT_SUCCESS);
        }
        if (n1 == 1 && n2 == 1) {
            if (s == "AB") {
                if (next_s == "AC") {
                    n1++;
                    n2--;
                    return 'A';
                } else if (next_s == "BC") {
                    n1--;
                    n2++;
                    return 'B';
                }
            } else if (s == "BC") {
                if (next_s == "AC") {
                    n1--;
                    n2++;
                    return 'C';
                } else if (next_s == "AB") {
                    n1++;
                    n2--;
                    return 'B';
                }
            } else { // AC
                if (next_s == "AB") {
                    n1++;
                    n2--;
                    return 'A';
                } else if (next_s == "BC") {
                    n1--;
                    n2++;
                    return 'C';
                }
            }
        }
        if (n1 < n2) {
            n1++;
            n2--;
            return s[0];
        } else {
            n1--;
            n2++;
            return s[1];
        }
    };

    vector<char> ans;
    s.push_back("");
    for (ll i = 0; i < N; i++) {
        if (s[i] == "AB") {
            ans.push_back(game(A, B, s[i], s[i + 1]));
        } else if (s[i] == "AC") {
            ans.push_back(game(A, C, s[i], s[i + 1]));
        } else { // BC
            ans.push_back(game(B, C, s[i], s[i + 1]));
        }
    }

    cout << YES << "\n";
    copy(begin(ans), end(ans), ostream_iterator<char>(cout, "\n"));
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    std::vector<std::string> s(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve(N, A, B, C, std::move(s));
    return 0;
}


Measured memory_bytes: 9656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int a,b;
    	a = sc.nextInt();
    	b = sc.nextInt();
    	
    	System.out.println(a*b + " " + (2*(a+b)));
    	
    }
}

Measured memory_bytes: 26064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    //string s ;
    int i, j, k, t, n;
    cin >> n ;
    int a[n][2];
    for(i=0; i<n; i++)
        cin >> a[i][0] >> a[i][1];
    for(i=0; i<(n-2); i++)
    {
        if(a[i][0]==a[i][1])
        {
            if(a[i+1][0]==a[i+1][1])
            {
                if(a[i+2][0]==a[i+2][1])
                {
                    cout << "Yes";
                    return 0;
                }
            }
        }

    }
    cout << "No";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t H,N;
  cin>>H>>N;
  vector<int> A(N);
  for(int64_t i=0;i<N;i++){
    cin>>A.at(i);
  }
  for(int64_t i=0;i<N;i++){
    H -=A.at(i);
  }
  if(H>0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 640
var
s:string;
i,j:integer;
begin
read(s);j:=-1;
for i:=1 to length(s) do
if s[i]='C' then begin j:=i;break;end;
if j=-1 then begin writeln('No');exit;end;
for i:=j to length(s) do
if s[i]='F' then begin writeln('Yes');exit;end;
writeln('No');
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(rall(a));
    ll ans = 0;
    for (int i = 1; i < n; ++i) {
        ans += a[i/2];
    }
    cout << ans << endl;
}


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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0)
{
  if (fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

int main()
{
  ios::sync_with_stdio(false);
  ll a[6];
  ll ans = numeric_limits<ll>::max();
  ll n;
  cin >> n;
  for(int i = 0 ; i < 5; i++)
  {
    cin >> a[i];
    ans = min(ans, a[i]);
  }

  cout << (n + ans - 1) / ans + 4 << endl;   

  
  return 0;

}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

const int maxn = 1e5 + 10, P = 1e9 + 7;
int n;

struct point {
  int op, x;
} a[maxn * 2];

int main() {
  scanf("%d", &n);
  rep(i, 1, n * 2) {
    scanf("%d", &a[i].x);
    a[i].op = i <= n;
  }
  sort(a + 1, a + n * 2 + 1, [] (point a, point b) {
    return a.x < b.x;
  });
  int res = 1;
  int now = 0, sz = 0;
  rep(i, 1, n * 2) {
    if (now == a[i].op) {
      sz++;
    } else {
      if (sz) res = 1ll * res * sz % P;
      if (--sz < 0) now ^= 1, sz = 1;
    }
  }
  printf("%d", res);
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 1e5+5;
const ll MOD = 1e9+7;

#define NIL -1
struct node
{
    int p, l, r;
} t[MAXN];
int n, depth[MAXN];

void get_depth(int p, int d)
{
    depth[p] = d;
    if (t[p].r != NIL)
        get_depth(t[p].r, d);
    if (t[p].l != NIL)
        get_depth(t[p].l, d+1);
    return;
}

void print()
{
    rep(i, 0, n-1){
        printf("node %d: parent = %d, depth = %d, ", i, t[i].p, depth[i]);
        if (t[i].p == NIL)
            printf("root, [");
        else if (t[i].l == NIL)
            printf("leaf, [");
        else
            printf("internal node, [");
        if (t[i].l != NIL){
            int child = t[i].l;
            printf("%d", child);
            while ((child = t[child].r) != NIL)
                printf(", %d", child);
        }
        printf("]\n");
    }
    return;
}

int main()
{
    int root, id, k, child;
    cin >> n;
    rep(i, 0, n-1){
        t[i].p = t[i].l = t[i].r = NIL;
    }
    rep(i, 0, n-1){
        int left;
        cin >> id >> k;
        rep(j, 0, k-1){
            cin >> child;
            if (!j)
                t[id].l = child;
            else
                t[left].r = child;
            t[child].p = id;
            left = child;
        }
    }
    rep(i, 0, n-1){
        if (t[i].p == NIL){
            root = i;
            break;
        }
    }
    get_depth(root, 0);
    print();

    return 0;
}



Measured memory_bytes: 7800
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println(A - (B * 2) > 0 ? A - (B * 2) : 0);
    }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  for(int i = 0; i < M; ++i){
    cin >> P[i] >> Y[i];
    P[i]--;
  } 
  vector< vector<int> > Pre(N);
  for(int i = 0; i < M; ++i){
    Pre[P[i]].push_back(Y[i]);
  }
  for(int i = 0; i < N; ++i){
    sort(Pre[i].begin(), Pre[i].end());
  }
  for(int i = 0; i < M; ++i){
    printf("%012lld\n", (ll)1000000 *( P[i]+1) + lower_bound(Pre[P[i]].begin(), Pre[P[i]].end(), Y[i]) - Pre[P[i]].begin() + 1LL);
  }
}


Measured memory_bytes: 7808
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = INT_MAX/3;

int main(){
    int H, W;
    cin >> H >> W;
    while(H!=0 || W!=0){
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i == 0 || i == H-1 || j == 0 || j == W-1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl ;
        }
        cout << endl;
        cin >> H >> W;
    }
    return 0;
}

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

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

using namespace std;

int main(){
	int n,k; scanf("%d%d",&n,&k);
	int ans=k;
	rep(i,n-1) ans*=k-1;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  i_i a[112345]={};
  in(int,n);
  rep(i,n)
    {
      a[i].F=i+1;
      cin>>a[i].S;
      if(a[i].F<a[i].S)
	swap(a[i].F,a[i].S);
    }
  sort(a,a+n);
  int sum=0;
  rep(i,n)
    if(a[i]==a[i+1])
      sum++,i++;

  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 1152
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = int(input())
    seen = set()
    i = 1
    while True:
        if s in seen:
            print(i)
            return
        seen.add(s)
        if s % 2 == 0:
            s /= 2
        else:
            s = s * 3 + 1
        i += 1


main()


Measured memory_bytes: 64620
// inputに入力データ全体が入る
function Main(input) {
	input = input.split(" ");
	var n = parseInt(input[0]);//作りたい数
	var x = parseInt(input[1]);//一回で作れる最大数
	var t = parseInt(input[2]);//一回にかかる時間
	//出力　作りたい数を作れる時間
	console.log(Math.ceil(n/x)*t);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29524
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 愚直にいくと、3,5,7のみで作れる数を列挙する
# n 桁なら3+3**2+..+3**(n-1)までは確実に作れる
#　最後は3**8 maxまでループ回しても通りそう
s = int(input())
ans = 0
digit = 0
for j in range(10):
    i = j+1
    if s >= 10**i: pass
    else: break
    digit = i+1
if digit == 0: digit += 1
#print(digit)

num = [3,5,7]
flag = [0,0,0]
for dig in range(1,digit+1):
    for i in range(3**dig):
        val = 0
        tmp = i
        for j in range(dig):
            if flag[tmp % 3] == 0: flag[tmp%3] = 1
            val += num[tmp % 3]*(10**j)
            tmp = tmp // 3
        #print(val)
        if val <= s and flag[0]*flag[1]*flag[2] ==1:
            ans += 1
            #print(val)
        flag = [0,0,0]
print(ans)

        

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

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

    int h, m, s;
    h = S / 3600;
    m = S % 3600 / 60;
    s = S % 3600 % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int W,H;
    cin >> W >> H;
    while(W!=0){
        vector<string> G(H);
        for(int i=0; i<H; i++){
            cin >> G[i];
        }
        vector<vector<bool>> dist(H,vector<bool> (W,false));
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(G[i][j] == '@'){
                    int ans = 1;
                    queue<P> que;
                    que.push(P(i,j));
                    dist[i][j] = true;
                    while(que.size()){
                        P v = que.front();
                        que.pop();
                        for(int i=0; i<4; i++){
                            int ny = v.first + dy[i];
                            int nx = v.second + dx[i];
                            if(ny<0 or ny>=H or nx<0 or nx>=W) continue;
                            if(G[ny][nx] == '#') continue;
                            if(dist[ny][nx]) continue;
                            ans++;
                            dist[ny][nx] = true;
                            que.push(P(ny,nx));
                        }
                    }
                    cout << ans << endl;
                }
            }
        }
        cin >> W >> H;
    }
    return 0;
}


Measured memory_bytes: 3272
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N;
  vector<int> ps;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int p;
    scanf("%d", &p);
    ps.push_back(p - 1);  // NOTE : modified input
  }

  // create reverse map from ps[i] -> i
  vector<int> rs(N, 0);
  for (int i = 0; i < N; i++) {
    rs[ps[i]] = i;
  }

  // find longest sub-sequence of the form
  //     b, b + 1, ..., e - 2, e - 1
  vector<int> ls(N, 0);
  int max_l = 1;
  ls[N - 1] = 1;
  for (int i = N - 2; i >= 0; i--) {
    if (rs[i] < rs[i + 1]) {
      ls[i] = ls[i + 1] + 1;
    } else {
      ls[i] = 1;
    }
    max_l = max(max_l, ls[i]);
  }
  printf("%d\n", N - max_l);

  return 0;
}


Measured memory_bytes: 2676
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n, m, x := scanInt(), scanInt(), scanInt()
	c := make([]int, n)
	as := make([][]int, n)
	for i := 0; i < n; i++ {
		c[i], as[i] = scanInt(), scanInts(m)
	}

	INF := 1000000000000000000
	ans := INF

	for i := 0; i < (1 << n); i++ {
		costSum := 0
		smart := make([]int, m)
		for j := 0; j < n; j++ {
			if (i>>j)%2 == 0 {
				continue
			}
			costSum += c[j]
			for k := 0; k < m; k++ {
				smart[k] += as[j][k]
			}
		}
		ok := true

		for j := 0; j < m; j++ {
			if smart[j] < x {
				ok = false
			}
		}
		if ok {
			if costSum < ans {
				ans = costSum
			}
		}
	}
	if ans == INF {
		ans = -1
	}

	fmt.Println(ans)
}


Measured memory_bytes: 2144