akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  string S;
  cin >> S;
  deque<char> T;
  for(char c: S) T.push_back(c);
  bool dir = true;
  int Q;
  cin >> Q;
  rep(q, Q) {
    int t;
    cin >> t;
    t--;
    if(!t) {
      dir = !dir;
    } else {
      int f;
      char c;
      cin >> f >> c;
      f--;
      if(!f) {
        if(dir) T.push_front(c);
        else T.push_back(c);
      } else {
        if(dir) T.push_back(c);
        else T.push_front(c);
      }
    }
  }
  if(dir) {
    while(!T.empty()) {
      cout << T.front();
      T.pop_front();
    }
  } else {
    while(!T.empty()) {
      cout << T.back();
      T.pop_back();
    }
  }
  cout << endl;
  return 0;
}


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

int main(){
  int x1, x2, x3, x4, y1, y2, y3, y4;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2 - x1;
  int y = y2 - y1;
  x4 = -y + x1;
  y4 = x + y1;
  x3 = x2 + x4 - x1;
  y3 = y2 + y4 - y1;
  cout << x3 << " "<< y3 << " " << x4 << " " << y4 << endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    int count = 0;
    int ans = 0;
    rep(i, n - 1) {
        if(h[i + 1] <= h[i]) count++;
        else {
            ans = max(ans, count);
            count = 0;
        }
    }
  	ans = max(ans, count);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
    char cup1, cup2;
    char ball;

    ball = 'A';
    while(scanf("%c,%c", &cup1, &cup2) != EOF){
        if(cup1 == ball) ball = cup2;
        else if(cup2 == ball) ball = cup1;
    }
    printf("%c\n", ball);
    return 0;
}

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

int main()
{
	int n,m;
	while(cin>>n>>m){
		if(n==0) return 0;
		vector<int> p1,p2;
		int t1=0,t2=0;
		for(int i=0;i<n;i++){
			int t;cin>>t;p1.push_back(t);
			t1+=t;
		}
		for(int i=0;i<m;i++){
			int t;cin>>t;p2.push_back(t);
			t2+=t;
		}

		bool ok=false;
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++){
				if(!ok && t1-p1[i]+p2[j]==t2-p2[j]+p1[i]){
					cout<<p1[i]<<" "<<p2[j]<<endl;
					ok=true;
				}
			}
		if(!ok) cout<<-1<<endl;
	}
}

Measured memory_bytes: 0
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<ll, ll>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n, m;
    cin >> n >> m;
    vector<PII> v(n);
    for(auto &x : v){
        cin >> x.F >> x.S;
    }
    sort(ALL(v), [&](PII p1, PII p2){
        if(p1.F != p2.F){
            return p1.F < p2.F;
        }
        return p1.S > p2.S;
    });
    ll ans = 0;
    for(auto &x : v){
        if(m > 0){
            if(x.S >= m){
                ans += m * x.F;
                m = 0;
            }else{
                ans += x.S * x.F;
                m -= x.S;
            }
        }else{
            break;
        }
    } 
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/


Measured memory_bytes: 1792
<?php

    $N = intval(trim(fgets(STDIN)));
    
    $max=0;
    for($i=1;$i<=sqrt($N);$i++){
        if($N%$i==0){
            $max=$i;
        }
    }
    // echo $max." ".$N/$max;
    
    echo ($max-1)+(($N/$max)-1);
    
?>

Measured memory_bytes: 16060
/*
 * 2305.cc: Beautiful Currency
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20;
const int MAX_A = 100000 * 2;

const double DINF = 1e30;

/* typedef */

/* global variables */

int as[MAX_N];
double dp[MAX_N + 1][MAX_A + 1];

/* subroutines */

inline double cratio(int a, int b) { return (double)abs(a - b) / a; }

/* main */

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

  for (int i = 0; i < n; i++) cin >> as[i];

  for (int j = 1; j <= MAX_A; j++) dp[0][j] = cratio(as[0], j);
  for (int i = 1; i < n; i++)
    for (int j = 1; j <= MAX_A; j++) dp[i][j] = DINF;

  for (int i = 0; i < n - 1; i++)
    for (int j = 1; j <= MAX_A; j++)
      if (dp[i][j] < DINF)
	for (int k = j; k <= MAX_A; k += j) {
	  double dp0 = max(dp[i][j], cratio(as[i + 1], k));
	  if (dp[i + 1][k] > dp0) dp[i + 1][k] = dp0;
	}

  double mindp = DINF;
  for (int j = 1; j <= MAX_A; j++)
    if (mindp > dp[n - 1][j]) mindp = dp[n - 1][j];

  printf("%.12lf\n", mindp);
  return 0;
}

Measured memory_bytes: 33948
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N, X;

    cin >> N >> X;
    int L[N];
    vector<int> V;
    V.push_back(0);
    int now = 0;
    for(int i = 0; i < N; i++) {
        cin >> L[i];
        now += L[i];
        V.push_back(now);   
    }
    
    int cnt = 0;

    for(int i = 0; i < V.size(); i++) {
        if(V[i] <= X) cnt += 1;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
//絶対値
int abs(int x) {
				return max(x,-x);
}

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int cnt=0;
	while(max(abs(a-b),max(abs(b-c),abs(c-a))) >2) {
	  if(a<=b && a<=c) a+=2;
	  else if(b<=a && b<=c) b+=2;
	  else c+=2;
			  cnt++;
	}
	int cntp=0;
	int dif = max(abs(a-b),max(abs(b-c),abs(c-a)));
	int minn = min(a,min(b,c));
	int cntm=0;
	if (a==minn) cntm++;
	if (b==minn) cntm++;
	if (c==minn) cntm++;
	
	
	if (dif==0) cntp=0;
	else if(dif==1) {
	  if (cntm == 1) cntp=2;
	  if (cntm ==2) cntp=1;
			}
	else {
	  if (a!=b&&b!=c&&c!=a) cntp=3;
	  else if (cntm==2) cntp=2;
	  else cntp=1;
  }
  cout <<cnt+cntp;
}

			  

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))

ll ee[800][800];
ll a[800];
ll cnt[800],dpcnt;
ll dp[800];
ll cnta,cntb;
ll n,m;
ll base;

void f(ll i,ll c){
	a[i]=c;
	if(c==1)cnta++;
	else cntb++;
	
	rep(j,0,n)if(!ee[i][j]){
		if(a[j]&&a[j]==c){
			puts("-1");
			exit(0);
		}
		if(!a[j])f(j,-c);
	}
}

int main(){
	scanf("%lld%lld",&n,&m);
	rep(i,0,m){
		ll p,q;
		scanf("%lld%lld",&p,&q);
		ee[p-1][q-1]=ee[q-1][p-1]=1;
	}
	rep(i,0,n)ee[i][i]=1;
	
	rep(i,0,n)if(!a[i]){
		cnta=0;
		cntb=0;
		f(i,1);
		base+=min(cnta,cntb);
		cnt[dpcnt++]=llabs(cnta-cntb);
	}
	
	dp[base]=1;
	rep(i,0,dpcnt)for(ll j=800;j>=cnt[i];j--)dp[j]|=dp[j-cnt[i]];
	dp[0]=1;
	
	
	ll temp,temp2,ans,ans2;
	temp=n/2;
	while(!dp[temp])temp++;
	temp2=n-temp;
	ans=temp*(temp-1)/2+temp2*(temp2-1)/2;

	temp=n/2;
	while(!dp[temp])temp--;
	temp2=n-temp;
	ans2=temp*(temp-1)/2+temp2*(temp2-1)/2;

	printf("%lld\n",min(ans,ans2));
	
	return 0;
}

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

int main()
{
	int n,i,j,a,b,c, answer;
	cin >> n;
	vector<vector<int>> in;
  	vector<vector<int>> ans(n+1, vector<int> (3,0));
	for(i=0;i<n;i++)
    {
		vector<int> v;
		cin >> a >> b >> c;
		v.push_back(a);
      	v.push_back(b);
      	v.push_back(c);
    	in.push_back(v);
    }
    
    /*for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cout << in[i][j] << " ";
        }
        cout << endl;
    }*/
  	
  	for(i=n-1;i>=0;i--)
    {
      	ans[i][0] = in[i][0] + max(ans[i+1][1],ans[i+1][2]);
      	ans[i][1] = in[i][1] + max(ans[i+1][0],ans[i+1][2]);
      	ans[i][2] = in[i][2] + max(ans[i+1][0],ans[i+1][1]);
    }
    
    /*for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }*/
  	
  	answer = max(ans[0][0], max(ans[0][1], ans[0][2]));
  	
  	cout << answer <<  endl;
  	
  	return 0;
}

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

int main(){
	vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << v[k-1] << endl;
}

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

if 1<= n < 10:
    print(n)
elif 10<= n < 100:
    print(9)
elif 100<= n <1000:
    print(9+n-99)
elif 1000<= n < 10000:
    print(909)
elif 10000<= n <100000:
    print(909+n-9999)
else:
    print(90909)



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

int n;

int main()
{
    cin >> n;
    string res = "second";
    rep(i, n)
    {
        int a;
        cin >> a;
        if(a % 2 == 1) res = "first";
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
const int N=2e5+5;
vector<int> g[N];
int n,ab,a[N],ans[N],b[N],c[N],d[N];
void dfs(int x,int y){
	if(ans[ab]<a[x]){
		b[x]=ab+1,c[x]=0;
		ans[++ab]=a[x];
	}
	else{
		b[x]=lower_bound(ans+1,ans+1+ab,a[x])-ans;
		c[x]=ans[b[x]];
		ans[b[x]]=a[x];
	}
	d[x]=ab;
	for(int i=0;i<g[x].size();i++)
		if(g[x][i]!=y)dfs(g[x][i],x);
	if(c[x]==0)ab--;
	else ans[b[x]]=c[x];
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		g[x].push_back(y),g[y].push_back(x);
	}
	dfs(1,-1);
	for(int i=1;i<=n;i++)
		cout << d[i] << endl;
	return 0;
}

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

int main(){
  int h,w;
  string s[110];
  cin>>h>>w;
  for(int i=0;i<h;i++){
    cin>>s[i];
  }

  for(int i=0;i<h;i++){
    if(i==0){
      for(int j=0;j<w+2;j++) cout<<"#";
    }
    cout<<endl;
    cout<<"#"<<s[i]<<"#";
  }
  cout<<endl;
  for(int j=0;j<w+2;j++) cout<<"#";

}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto S = readln.chomp;
    int[] rr;
    int i, j, last;
    foreach_reverse (c; S) {
        if (c == '0') last = i;
        if (i-j == M) {
            if (last == j) {
                writeln(-1);
                return;
            }
            rr ~= (last-j);
            j = last;
        }
        ++i;
    }
    if (j != N) rr ~= (N-j);
    rr.reverse();
    writeln(rr.array().to!(string[]).join(" "));
}

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

UNIA = []
b = ''
for i in range(N):
    if A[i] == b:
        continue
    else:
        UNIA.append(A[i])
        b = A[i]

# print(UNIA)

# if UNIA[0] < UNIA[1]:
#     up = True
# else:
#     up = False

up = None
ans = 1
for i in range(len(UNIA)-1):
    if up is None:
        if UNIA[i] < UNIA[i+1]:
            up = True
        else:
            up = False
    elif up:
        if UNIA[i] < UNIA[i+1]:
            continue
        else:
            up = None
            ans += 1
    else:
        if UNIA[i] < UNIA[i+1]:
            up = None
            ans += 1

print(ans)

Measured memory_bytes: 14436
#include <stdio.h>
#include <math.h>
int main(){
  double xa,ya,ra,xb,yb,rb;
  int n;
  double d;
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
  d=sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));
  
  if(ra<rb && d<rb-ra)printf("-2\n");
  else if(rb<ra && d<ra-rb)printf("2\n");
  else if(ra+rb<d)printf("0\n");
  else if(fabs(ra-rb)<=d && d<=ra+rb)printf("1\n");
  
  
  }
  return 0;
}

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

const int N = 100005;
vector<int> g[N];
bool visited[N];
int dist[N];

void dfs(int v){
    visited[v] = 1;
    dist[v] = 1;
    for(auto to : g[v]){
        if(!visited[to]){dfs(to);}
        dist[v] = max(dist[v], dist[to] + 1);
    }
}

int main() {
    int n, m; cin>>n>>m;
    for(int i = 1; i <= m; i++){
        int v, to; cin>>v>>to;
        g[v].push_back(to);
    }
    for(int i = 1; i <= n; i++){
        if(!visited[i]){dfs(i);}
    }
    int mx = 0;
    for(int i = 1; i <= n; i++){
        mx = max(mx, dist[i]);
    }
    cout<<mx-1;
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
using namespace std;
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;

int N;
long long ma, mb;
vector<long long> a, b, c;

long long dp[51][510][510];

int main() {
    cin >> N >> ma >> mb;
    a.resize(N); b.resize(N); c.resize(N);
    for (int i = 0; i < N; ++i) cin >> a[i] >> b[i] >> c[i];
    
    for (int i = 0; i < 51; ++i) for (int j = 0; j < 510; ++j) for (int k = 0; k < 510; ++k) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int wa = 0; wa < 500; ++wa) {
            for (int wb = 0; wb < 500; ++wb) {
                if (dp[i][wa][wb] >= INF) continue;
                
                // 使わない
                chmin(dp[i+1][wa][wb], dp[i][wa][wb]);

                // 使う
                chmin(dp[i+1][wa+a[i]][wb+b[i]], dp[i][wa][wb] + c[i]);
            }
        }
    }
    long long res = INF;
    for (int wa = 1; wa < 500; ++wa) {
        for (int wb = 1; wb < 500; ++wb) {
            if (wa * mb != wb * ma) continue;
            chmin(res, dp[N][wa][wb]);
        }
    }
    if (res < INF) cout << res << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 103936
#include <stdio.h>

int main(void)
{
    int a[3],tmp,i;

    scanf("%d %d %d",&a[0],&a[1],&a[2]);

    i=0;

    while(i<2){
        tmp=a[i+1]-a[i];

        if(tmp<0){
            tmp=a[i];
            a[i]=a[i+1];
            a[i+1]=tmp;

            if(i>0) i--;
        }else{
            i++;
        }
    }

    printf("%d %d %d\n",a[0],a[1],a[2]);

    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
#define Yes cout<<"Yes"<<endl; 
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl; 
#define NO cout<<"NO"<<endl;
#define yes cout<<"yes"<<endl; 
#define no cout<<"no"<<endl;

// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
  string s,t;cin>>s>>t;
  int cnt=0;
  rep(i,s.size()-t.size()+1){
      int cnt1 = 0;
      rep(j,t.size()){
          if(s[i+j] == t[j])cnt1++;
      }
      cnt = max(cnt,cnt1);
  }
   cout<<t.size() - cnt<<endl;

    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
ll n,m,i,j,k,l,t,arr[sz],brr[sz],crr[sz];
vector<ll>v;
int main()
{
    scanf("%lld",&t);
    if(t>=30)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

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

	string str;
	cin >> str;

	bool fail = false;
	if (str.size() % 2) fail = true;
	else {
		for (int i = 0; i < str.size(); i += 2) {
			if (str[i] != 'h' || str[i+1] != 'i') fail = true;
		}
	}

	if (fail) cout << "No\n";
	else cout << "Yes\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int op(int a,int b){return max(a,b);}
int e(){return -1;}
int target;
bool f(int a){return target>a;}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin>>n>>q;
    vec A(n);
    rep(i,n) cin>>A[i];
    segtree<int,op,e> B(n);
    rep(i,n) B.set(i,A[i]);
    rep(query,q){
        int t,a,b;
        cin>>t>>a>>b;
        if(t==1) B.set(a-1,b);
        if(t==2) cout<<B.prod(a-1,b)<<"\n";
        if(t==3) target=b,cout<<B.max_right<f>(a-1)+1<<"\n";
    }
}

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

int main(){
  int n, m; cin >> n >> m;
  vector<vector<int>> G(n);
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  bool ok = false;
  for(int nv: G.at(0)){
    for(int g: G.at(nv)){
      if(g == n-1) ok = true;
    }
  }
  if(ok) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;


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

  int N; cin >> N;
  int maxv = 1, minv = 1000000000;
  rep(i, N) {
    int A; cin >> A;
    maxv = max(maxv, A);
    minv = min(minv, A);
  }
  cout << maxv-minv << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>//C语言io
#include <cstring>//以下是c语言常用头文件
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cmath>
#include <iostream>//c++IO
#include <sstream>
#include <string>
#include <list>//c++常用容器
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>//c++泛型的一些函数
#include <functional>//用来提供一些模版
#define fo0(i,n) for(int i = 0;i < n; ++i)
#define fo1(i,n) for(int i = 1;i <= n; ++i)
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
//......................................................
//const int maxn =1024+1;
//int ar[maxn+10];
char ar[100][100];
int br[100][100];
int dir[2][8] = {-1,-1,-1,0,0,1,1,1,-1,0,1,-1,1,-1,0,1};
int main()
{
   int a,b;
   cin>>a>>b;
   for(int i = 0;i < a; ++i)
   {
       scanf("%s",ar[i]);
   }
   for(int i = 0;i < a; ++i)
   {
       for(int j = 0;j < b; ++j)
       {
           if(ar[i][j]=='#')
           {
               for(int k = 0;k < 8; ++k)
               {
                   int r = i + dir[0][k];
                   int l = j + dir[1][k];
                   if(r>=0&&r<a&&l>=0&&l<b)
                     br[r][l]++;
               }
           }
       }
   }
   for(int i = 0;i < a; ++i)
   {
       for(int j = 0;j < b; ++j)
       {
           if(ar[i][j]=='#')
           {
               printf("#");
           }
           else
              printf("%d",br[i][j]);
       }
       puts("");
   }


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
    static decimal result;
static Hashtable ht=new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read3();
      if(s[0]>=s[1] && s[0]>=s[2])result=s[1]+s[2];
            if(s[1]>=s[0] && s[1]>=s[2])result=s[0]+s[2];
            if(s[2]>=s[1] && s[2]>=s[0])result=s[0]+s[1];
                    Console.WriteLine(result.ToString());

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {

 
    }


}


Measured memory_bytes: 13268
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  ll A,B,C; scanf("%lld%lld%lld",&A,&B,&C);
  if (C-A+B>0&&4*A*B<(C-A-B)*(C-A-B)) Yes();
  else No();
  return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

unsigned long long S[51] = {0};
unsigned long long p[51] = {0};
int layerstate[51] = {0};

void init(){

    S[0] = 1;
    p[0] = 1;
    for(int i = 1; i < 51; i++)
    {
        S[i] = S[i-1] * 2 + 3;
        p[i] = p[i-1] * 2 + 1;
    }
    
}

int main(){
    int N;
    unsigned long long X;

    init();   
    cin >> N >> X;

    for(int i = N; i >= 0; i--)
    {
        //printf("S[%d]:%lld  X:%lld", i, S[i], X);
        unsigned long long halfthr = (S[i]+ 1) / 2;
        if (X > S[i]) printf("error");
        if (X == S[i]){
            layerstate[i] = 2;
            X -= S[i];
        } else if(X >= halfthr){
            layerstate[i] = 1;
            X -= halfthr;
        } else {
            layerstate[i] = 0;
            X -= 1;
        }
        //printf(" state[%d]: %d\n", i, layerstate[i]);
        if (X == 0){
            break;
        }

    }
    unsigned long long ans = 0;
    for(int i = N; i >= 0; i--){
        if (layerstate[i] >= 1) ans++;
        ans += p[i - 1] * layerstate[i];
    }

    cout << ans;

}

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

int main(){
	while(1){
		int n, m, now=0;
		int f[1000], t[1000];
		bool flag=false;
		
		scanf(" %d %d", &n, &m);
		if(n==0 && m==0) break;
	
		for(int i=0; i<n; ++i) scanf(" %d", &f[i]);
		for(int i=0; i<m; ++i) scanf(" %d", &t[i]);
		
		for(int i=0; i<m; ++i){
			now+=t[i];
			//printf("now:%d\n", now);
			
			if(now>=n-1) {
				printf("%d\n", i+1);
				break;
			}
			now+=f[now];
			
			//printf("now:%d\n", now);
			
			if(now>=n-1) {
				printf("%d\n", i+1);
				break;
			}
		}
		
	}

	return 0;
}

Measured memory_bytes: 1196
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();

    if s[0] != 'A' {
        println!("WA");
        return;
    }

    let res = find_index(&s, 'C');
    if res.0 != 1 {
        println!("WA");
        return;
    }

    if !check_lower_case(&s, res.1) {
        println!("WA");
        return;
    }
    println!("AC");
}

fn check_lower_case(s: &Vec<char>, skip: usize) -> bool {
    for i in 1..s.len() {
        if i == skip {
            continue;
        }
        if !s[i].is_lowercase() {
            return false;
        }
    }
    return true;
}

fn find_index(s: &Vec<char>, t: char) -> (usize, usize) {
    // cnt index
    let mut cnt = 0;
    let mut idx = 0;
    for i in 0..s.len() {
        if i < 2 || i == s.len() - 1 {
            continue;
        }
        if s[i] == t {
            idx = i;
            cnt += 1;
        }
    }

    return (cnt, idx);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  int a[n];
  rep(i,n) R a[i];
  int ans=MAX;
  REP(i,-100,101) {
    int x=0;
    rep(j,n) x+=(a[j]-i)*(a[j]-i);
    ans=min(ans,x);
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  string s;
  cin>>s;
  for (int i=0; i<3; i++) {
    if (s[i]=='1') cout<<'9';
    else if (s[i]=='9') cout<<'1';
    else cout<<s[i];
  }
  cout<<endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main() {
    int x=0,y=0,z=0,w=0,n=0,m=0;
cin>>x>>y>>z;
if(y-x==z-y)cout <<"YES";
else cout << "NO";
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	cnt := make([]int, n)
	for i := 1; i < n; i++ {
		var a int
		fmt.Scan(&a)
		cnt[a - 1]++;
	}

	for i := 0; i < n; i++ {
		fmt.Println(cnt[i])
	}
}


Measured memory_bytes: 6472
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,w,i,j;
    cin>>n>>w;
    vector<ll> v(n+1);
    vector<ll> p(n+1);
    for(i=1;i<=n;i++) cin>>v[i]>>p[i];
    ll dp[n+1][w+1];
    memset(dp,0,sizeof dp);
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j-v[i]>=0) dp[i][j]=max(dp[i][j],p[i]+dp[i-1][j-v[i]]);
        }
    }
    cout<<dp[n][w]<<endl;
    return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	ll n;
	cin>>n;
	cout<<n*(n-1)/2;
}

Measured memory_bytes: 256
def main():
    from collections import defaultdict
    dd = defaultdict(str)

    n, m = map(int, input().split())
    keys = []
    atcoder = [[] for _ in range(n)]
    for i in range(m):
        p, y = map(int, input().split())
        key_p = str(p).zfill(6)
        key_y = str(y).zfill(10)
        keys.append(key_p + key_y)
        p -= 1
        atcoder[p].append(y)
    for i in range(n):
        atcoder[i].sort()
        key_i = str(i + 1).zfill(6)
        for index, j in enumerate(atcoder[i]):
            key_index = str(index + 1).zfill(6)
            key_j = str(j).zfill(10)
            dd[key_i + key_j] = key_i + key_index
    for k in keys:
        print(dd[k])


if __name__ == "__main__":
    main()

Measured memory_bytes: 47256
n = int(input())
if n == 1:
  print(0)
else:
  def factorization(n):
      arr = []
      temp = n
      for i in range(2, int(-(-n**0.5//1))+1):
          if temp%i==0:
              cnt=0
              while temp%i==0:
                  cnt+=1
                  temp //= i
              arr.append([i, cnt])

      if temp!=1:
          arr.append([temp, 1])

      if arr==[]:
          arr.append([n, 1])

      return arr

  arr = factorization(n)
  ans = 0
  for i in range(len(arr)):
    cnt = arr[i][1]
    j = 1
    while cnt >= 0:
      cnt -= j
      j += 1
    ans += (j - 2)
  print(ans)

Measured memory_bytes: 9496
import sys
import math
 
N = int(input())
S = input()
ans = 0
 
for i in range(10):
    a = S.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = S.find(str(j), a+1)
        if b == -1:
            continue
        for k in range(10):
            if S.find(str(k), b+1) != -1:
                ans += 1
 
 
print(ans)

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

int main(void) {
    int N, M, X, C[15], A[15][15];
    int a, n, x, m, b, bit, i, j;
    int S[15];
    scanf("%d%d%d", &N, &M, &X);
    for (i=0; i<N; i++) {
        scanf("%d", &C[i]);
        for (j=0; j<M; j++) scanf("%d", &A[i][j]);
    }
    m=1000000000;
    a=0;
    for (bit=0; bit<(1<<N); bit++) {
        vector<int> s;
        for (i=0; i<N; i++) {
            if (bit & (1<<i)) s.push_back(i);
        }
        n=(int)s.size();
        
        /*
        printf("%d: ", bit);
        for (i=0; i<(int)s.size(); i++) printf("%d ", s[i]);
        printf("[%d]", n);
        printf("\n");
        */
        
        x=0; b=1;
        for (i=0; i<M; i++) S[i]=0;
        for (i=0; i<n; i++) {
            x+=C[s[i]];
            for (j=0; j<M; j++) S[j]+=A[s[i]][j];
        }
        for (i=0; i<M; i++) {
            if (S[i]<X) {
                b=0;
                break;
            }
        }
        if (b) {
            a=1;
            if (x<m) m=x;
        }
    }
    if (a) printf("%d", m);
    else printf("-1");
    return 0;
}


Measured memory_bytes: 3792
#include<cstdio>
using namespace std;
bool mp[100][100];
bool dian[100];
int ans=0;
int m,n;
void dfs(int v,int dep)
{
	if(dep==m)
	{
		ans++;
		return ;
	}
	for(int i=1;i<=m;i++)
	{
		if(mp[i][v]&&dian[i])
		{
			dian[v]=false;
			dfs(i,dep+1);
			dian[v]=true;
		}
	}
}
int main()
{
	scanf("%d%d",&m,&n);
	for(int i=1;i<=m;i++)
	{
		dian[i]=true;
	}
	for(int a,b,i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
		mp[a][b]=true;
		mp[b][a]=true;
	}
	dfs(1,1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

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

    for (int i = 0; i <n; i++) {
        int t; cin >> t;
    }

    int ans = 0;
    if (n == k) { ans = 1; }
    else {
        n -= k;
        if (n % (k-1)) {
            ans = n / (k-1) + 2;
        } else {
            ans = n / (k-1) + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
answer = [[False, 0] for _ in range(n)]
for i in range(m):
    number, result = input().split()
    number = int(number)
    if result == 'AC':
        answer[number-1][0] = True
    elif answer[number-1][0] != True:
        answer[number-1][1] += 1

ret = [ans[1] for ans in answer if ans[0] == True]
print(len(ret), sum(ret))


Measured memory_bytes: 59808
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<queue>
#include<set>
typedef long long ll;
using namespace std;


int main(){
    char n;
    cin>>n;
    n++;
    cout<<(char)n<<endl;
    return 0;
}

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

int main() {
	int n;
	int d[15][15];
	rep(i, 15) rep(j, 15) d[i][j] = -1;

	// Ai番目の人の人が各Aj番目の人の情報(1:正直/0:不親切)を入力.
	cin >> n;
	rep (i, n) {
		int a;
		cin >> a;
		rep(j , a) {
			int x;
			cin >> x;
			cin >> d[i][x-1];
		}
	}

	int ans = 0;
	for (int bit=0; bit<(1<<n); bit++) {
		int false_cnt = 0;
		bool s[15];
		rep (i, 15) s[i] = true;
		/* bit立っているAiの情報を無視する場合. */
		for (int i=0; i<n; i++) {
			if (bit & (1<<i)) {
				s[i] = false;
				false_cnt++;
			}
		}
		bool pat_res = true;
		rep (i, n) {
			if (s[i] == false) continue;
			rep (j, n) {
				if (d[i][j] == -1) {
					/*Ajの評価もってない.*/
					continue;
				} else if ((d[i][j] == 1) && (s[j] == true)) {
					/**/
				} else if ((d[i][j] == 0) && (s[j] == false)) {
					/**/
				} else {
					/* このパターンはだめ. */
					pat_res = false;
				}
			}
		}
		if (pat_res == true) {
//			cout << "true" << endl;
//			cout << "n = " << n << endl;
//			cout << "false_cnt = " << false_cnt << endl;
			ans = max(ans, n-false_cnt);
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i, n) {
    cin >> a.at(i);
    a.at(i)--;
  }
  rep(i, n) cin >> b.at(i);
  rep(i, n) cin >> c.at(i);
  int sum = 0;
  rep(i, n) {
    sum += b.at(a.at(i));
    if(a[i] == a[i-1] + 1 && i > 0) {
      sum += c[a[i-1]];
    }
  }
  cout << sum << endl;
}
    

Measured memory_bytes: 3644
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
template <typename T>
vector<T> divisor(T n) {
    vector<T> res;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i * i != n) {
                res.push_back(n / i);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}
template <typename T>
map<T, int> prime_factor(T n) {
    map<T, int> res;
    for (T i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        res[n]++;
    }
    return res;
}
template <typename T>
T gcd(T a, T b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
int main(){
    ll a;
    cin >> a;
    ll ans = 1;
    while(a>1){
        ans = ans * 2 + 1;
        a /= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()

int main() {
    ll N,M; scanf("%lld%lld",&N,&M);
    ll X[100010];
    rep(i,M) scanf("%lld",&X[i]);
    sort(X,X+M);
    if (M == 1){
        cout << 0 << endl;
    }
    else{
        ll dif[100010];
        rep(i,M-1) dif[i] = X[i+1]-X[i];
        sort(dif,dif+M-1);
        ll ans = 0;
        if (M-N<=0) cout << ans << endl;
        else{
            rep(i,M-N) ans += dif[i];
            cout << ans << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 1792
open Batteries
let t = Scanf.sscanf (read_line()) "%s" (fun t -> t)
(* 文字列をcharのlistにする *)
let explode s = List.init (String.length s) (String.get s)
let rec loop result lst =
  match lst with
  | [] -> result |> List.rev
  | first :: [] -> if first = '?' then loop ('D' :: result) [] else loop (first :: result) []
  | first :: rest ->
    if first = '?' then loop ('D' :: result) (rest) else
    loop (first :: result) (rest)
let r = loop [] @@ explode t |> Array.of_list
(* charのlistをstringに *)
let _ = print_endline @@ String.init (Array.length r) @@ fun a -> r.(a)


Measured memory_bytes: 22600
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>

using namespace std;

typedef pair<int, int> P;

const int N = 201;
const int O = 100;
const int INF = 100000000;

class S{
public:
  int x, y, t, c;
  S(){}
  S(int x, int y, int t, int c) : x(x), y(y), t(t), c(c) {}
  bool operator < (const S& s) const {
    return c > s.c;
  }
};

int dist[N][N][6], n;
P s, g, l;
bool kagu[N][N];
int dx[2][7] = {{0, 1, 1, 0, -1, -1, 0}, {0, 1, 1, 0, -1, -1, 0}};//
int dy[2][7] = {{1, 0, -1, -1, -1, 0, 0}, {1, 1, 0, -1, 0, 1, 0}};

int solve(){
  fill(dist[0][0], dist[N][0], INF);
  S u = S(s.first, s.second, 0, 0), v;
  priority_queue<S> que;
  que.push(u);
  dist[u.x][u.y][u.t] = u.c;
  while(!que.empty()){
    u = que.top();
    que.pop();
    if(u.x == g.first && u.y == g.second) return u.c;
    if(dist[u.x][u.y][u.t] < u.c) continue;
    for(int i=0;i<7;i++){
      int ny = u.y + dy[u.x%2][i];
      int nx = u.x + dx[u.x%2][i];
      if(abs(nx-O) > l.first) continue;
      if(abs(ny-O) > l.second) continue;
      if(kagu[nx][ny]) continue;

      int d = abs((u.x-O) * (u.y-O) * u.t) % 6;
      v = S(nx, ny, (u.t+1)%6, u.c);
      if(i != d) v.c++;
      if(dist[v.x][v.y][v.t] > v.c){
        dist[v.x][v.y][v.t] = v.c;
        que.push(v);
      }
    }
  }
  return -1;
}

main(){
  cin >> s.first >> s.second >> g.first >> g.second;
  s.first += O;
  s.second += O;
  g.first += O;
  g.second += O;
  cin >> n;
  fill(kagu[0], kagu[N], false);
  for(int i=0;i<n;i++){
    P in;
    cin >> in.first >> in.second;
    kagu[in.first+O][in.second+O] = true;
  }
  cin >> l.first >> l.second;
  cout << solve() << endl;
}

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

int a[1010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int q;
	scanf("%d", &q);
	for(int i = 0; i < q; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		rotate(a+x, a+y, a+z);
	}
	for(int i = 0; i < n-1; i++)
		printf("%d ", a[i]);
	printf("%d\n", a[n-1]);
}



Measured memory_bytes: 3248
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

long long minSpanningTree(const vector<vector<Edge> >& edges)
{
    int n = edges.size();
    vector<bool> used(n, false);
    int usedNum = 0;
    vector<int> minCost(n, INT_MAX);
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, 0));

    long long ret = 0;
    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(used[v])
            continue;
        ret += p.first;
        used[v] = true;
        if(++usedNum == n)
            return ret;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(!used[e.to] && e.cost < minCost[e.to]){
                minCost[e.to] = e.cost;
                q.push(make_pair(e.cost, e.to));
            }
        }
    }
    return -1;
}

int main()
{
    for(;;){
        int s, d;
        cin >> s >> d;
        if(s == 0)
            return 0;

        vector<vector<Edge> > edges(s+d);
        for(int i=1; i<s; ++i){
            edges[0].push_back(Edge(i, 0));
            edges[i].push_back(Edge(0, 0));
        }

        for(int i=0; i<s; ++i){
            for(int j=s; j<s+d; ++j){
                int a;
                cin >> a;
                if(a > 0){
                    edges[i].push_back(Edge(j, a));
                    edges[j].push_back(Edge(i, a));
                }
            }
        }

        for(int i=s; i<s+d-1; ++i){
            for(int j=i+1; j<s+d; ++j){
                int a;
                cin >> a;
                if(a > 0){
                    edges[i].push_back(Edge(j, a));
                    edges[j].push_back(Edge(i, a));
                }
            }
        }

        cout << minSpanningTree(edges) << endl;
    }
}

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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eps 1e-9

const int MOD = 1e9+7;

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

ll POWER[65];
ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}
ll inv(ll x) {return power(x,MOD-2);}

void precompute() {
	POWER[0]=1;
	for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL;
}
char str[10005];
int main() {
//	freopen("TASK.in","r",stdin);freopen("TASK.out","w",stdout);
	precompute();
	scanf("%s",str+1);
	int len=strlen(str+1);
	int n=0,w=0,s=0,e=0;
	map<char,int> mapp;
	for(int i=1;i<=len;i++) {
		mapp[str[i]]++;
	}
	n=mapp['N'];
	s=mapp['S'];
	w=mapp['W'];
	e=mapp['E'];
	bool f=true;
	if((n==0 and s!=0) or (w==0 and e!=0) or (n!=0 and s==0) or (w!=0 and e==0)) f=false;
	if(f) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll n,m,k,d,q;

string a[3];

int main()
{
    int n,k;
    a[0]="Sunny";
    a[1]="Cloudy";
    a[2]="Rainy";
    string s;

    cin>>s;
    for(int i=0;i<=2;i++)
    {
        if(s==a[i])
            {cout<<a[(i+1)%3];
            break;}
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n],i,sum=0,sum1=0,min=10000;
  for(i=0;i<n;i++){
     cin>>a[i];
     sum1+=a[i];
  }
  for(i=n-1;i>=0;i--){
    sum1-=a[i];
    sum+=a[i];
    if(abs(sum1-sum)<min){
      min=abs(sum1-sum);
    }
  }
  cout<<min<<endl;
  return 0;
}

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

const int mo=int(1e9)+7;
int X1,X2,X3,X4,X5,X6,Y1,Y2,Y3,Y4,Y5,Y6,fac[2000010],ifac[2000010],ans;

int qpow(int a,int b)
{
	int x=a;  a=1;
	while (b)
		{
			if (b&1)  a=1LL*a*x%mo;
			x=1LL*x*x%mo,b>>=1;
		}
	return a;
}

int f(int x,int y)
{
	return 1LL*fac[x+y]*ifac[x]%mo*ifac[y]%mo;
}

int f(int x1,int y1,int x2,int y2)
{
	return (0LL+f(x2+1,y2+1)+mo-f(x2+1,y1)+mo-f(x1,y2+1)+f(x1,y1))%mo;
}

void work()
{
	scanf("%d %d %d %d %d %d",&X1,&X2,&X3,&X4,&X5,&X6);
	scanf("%d %d %d %d %d %d",&Y1,&Y2,&Y3,&Y4,&Y5,&Y6);
	fac[0]=1;
	for (int i=1; i<=2000000; i++)  fac[i]=1LL*fac[i-1]*i%mo;
	ifac[2000000]=qpow(fac[2000000],mo-2);
	for (int i=2000000; i; i--)  ifac[i-1]=1LL*ifac[i]*i%mo;
	for (int i=X3; i<=X4; i++)
		{
			ans=(ans+mo-1LL*(i+Y3)*f(i-X2,Y3-Y2-1,i-X1,Y3-Y1-1)%mo*f(X5-i,Y5-Y3,X6-i,Y6-Y3)%mo)%mo;
			ans=(ans+1LL*(i+Y4+1)*f(i-X2,Y4-Y2,i-X1,Y4-Y1)%mo*f(X5-i,Y5-Y4-1,X6-i,Y6-Y4-1))%mo;
		}
	for (int i=Y3; i<=Y4; i++)
		{
			ans=(ans+mo-1LL*(i+X3)*f(X3-X2-1,i-Y2,X3-X1-1,i-Y1)%mo*f(X5-X3,Y5-i,X6-X3,Y6-i)%mo)%mo;
			ans=(ans+1LL*(i+X4+1)*f(X4-X2,i-Y2,X4-X1,i-Y1)%mo*f(X5-X4-1,Y5-i,X6-X4-1,Y6-i))%mo;
		}
	printf("%d",ans);
}

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


Measured memory_bytes: 15872