akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
    int n,m;
    cin >> n >> m;
    vector<string>s(n),d(m);
    for(int i=0;i<n;i++){
        cin >> s.at(i);
    }
    for(int i=0;i<m;i++){
        cin >> d.at(i);
    }
    bool ans = false;
    for(int sy=0;sy<n-m+1;sy++){
        for(int sx =0;sx<n-m+1;sx++){
            vector<string>che(m);
            for(int gy=0;gy<m;gy++){
                for(int gx=0;gx<m;gx++){
                    che.at(gy).push_back(s.at(sy+gy).at(sx+gx));
                }
            }
            bool c = true;
            for(int i=0;i<m;i++){
                if(d.at(i)!=che.at(i))c=false;
            }
            if(c){ans=true;}
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
s=input()
a=set(list(s))
for i in range(26):
  if chr(ord("a")+i) not in a:
    print(s+chr(ord("a")+i))
    exit()
ans=s
for i in range(26):
  for m in s[i+1:]:
    if ord(s[i])<ord(m):
      ans=s[:i]+m
if ans==s:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9136
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
  int n;
  cin>>n;
  int l[n];
  int checker = 0;
  int max = 0;
  for(int i = 0; i<n;i++){
      cin>>l[i];
      if(max<l[i]){
          max = l[i];
          checker = i;
      }
  }
if(accumulate(l,l+n,0)-max>max) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
package main
import "fmt"

func main(){
	var a, b uint
	fmt.Scan(&a, &b)
	if b < a {
		if b < a-1 {
			fmt.Println(a+a-1)
		} else if a-1 <= b {
			fmt.Println(a+b)
		}
	} else if a < b {
		if a < b-1 {
			fmt.Println(b+b-1)
		} else if b-1 <= a {
			fmt.Println(a+b)
		}
	} else if a == b {
		fmt.Println(a+b)
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<string> w(N);
  cin >> w.at(0);

  int i,j,e=0;
  for(i=1; i<N; i++){
    cin >> w.at(i);

    string a1=w.at(i-1), a2=w.at(i);
    char b1=a1.at(a1.size()-1), b2=a2.at(0);
    if(b1 != b2){
      e++;    
    }

    for(j=0; j<i; j++){
      if(w.at(j)==w.at(i)){
        e++;
      }
    }

    if(e != 0){
      break;
    }
  }

  if(e == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  } 
}

Measured memory_bytes: 256
import sys
import math
import numpy as np
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
H,W,D = na()
f= [list(map(int,input().split())) for i in range(H)]
#print(f)
f = np.array(f)
Q=int(input())
'''
li = [0]*(H*W+2)
for i in range(1,D+1):
    li[i]=0
    h_=int(np.where(f==i)[0])
    w_=int(np.where(f==i)[1])
    for j in range(i+D,H*W+1,D):
        h_n=int(np.where(f==j)[0])
        w_n=int(np.where(f==j)[1])
        li[j] = li[j-D]+abs(h_ - h_n)+abs(w_ - w_n)
        h_ = h_n
        w_ = w_n
for i in range(Q):
    L,R = na()
    print(li[R]-li[L])
'''

li ={}
for i in range(H):
    for j in range(W):
        li[f[i][j]]=[i+1,j+1]
res=[0]*(H*W+1)
for i in range(1,D+1):
    for j in range(i+D,W*H+1,D):
        #print("j",j)
        #print(li[j][0],li[j][1])
        res[j] = res[j-D] +abs(li[j-D][0]-li[j][0]) + abs(li[j-D][1]-li[j][1])
#print(res)
for i in range(Q):
    L,R = na()
    print(res[R]-res[L])


Measured memory_bytes: 35560
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

typedef signed long long ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) x.begin(),x.end()

#define DEBUG

int main()
{
	int n, s;
	vector<int> d;

	cin >> n;
	rep(i, n)
	{
		cin >> s;
		d.push_back(s);
	}

	int ans = 0;
	rep(i, n)
	{
		rep(j,n)
		{
			if(i != j)
			{
				ans += d[i] * d[j];
			}
		}
	}

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


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

int n;
vector<int> a;

ll p(int b) {
  ll sad = 0;
  for (int i = 0; i < n; i++) {
    sad += abs(a[i] - (b + i+1));
  }
  return sad;
}

int main() {
  cin >> n;
  a.resize(n);
  for (int &i : a) {
    cin >> i;
  }
  ll l = -1e9, r = 1e9;
  while (l < r) {
    ll m = l + r == 0 ? 0 : (l + r) / 2;
    if (p(m) > p(m-1)) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  cout << p(l-1) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,1,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)
#define pb push_back
#define pob pop_back

template<typename T> 
void chmax(T &a,T b){ a = max(a, b);};
template<typename T> 
void chmin(T &a,T b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int d;

void solve(){
	int c=25-d;
	cout<<"Christmas ";
	rep(i,c)
		cout<<"Eve ";
	cout<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>d;
		solve();
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100


int main(){
  int n,A[N+1],k;
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(k=0;k<n;k++){
    if(k>0)printf(" ");
    printf("%d",A[k]);
  }
  printf("\n");

int j,v;
for(i=1;i<n;i++){
  v=A[i];
  j=i-1;
  while(j>=0 && A[j]>v){
    A[j+1]=A[j];
    j--;
    A[j+1]=v;
  }
  for(k=0;k<n;k++){
    if(k>0)printf(" ");
    printf("%d",A[k]);
  }
  printf("\n");
 }
return 0;
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int main(){
    int n;
    scanf("%d",&n);
    int ans[300000];
    MEM(ans);
    int now=1;
    pii p[505];
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        p[i]=mp(x,i);
    }
    sort(p+1,p+n+1);
    for(int i=1;i<=n;i++){
       /* if(ans[p[i].x]!=0){
            printf("No\n");
            return 0;
        }*/
        ans[p[i].x]=p[i].y;
        for(int j=1;j<p[i].y;j++){
            while(ans[now]!=0)now++;
            ans[now]=p[i].y;
        }
        if(now>p[i].x){
            printf("No\n");
            return 0;
        }
    }
    queue<int> q;
    now=1;
    for(int i = 1;i<=n*n;i++){
        if(ans[i]==0){
            if(q.empty()){
                printf("No\n");
                return 0;
            }
           // printf("%d\n",q.front());
            ans[i]=q.front();
            q.pop();
        }
        while(p[now].x<=i&&now!=n+1){
            for(int j=p[now].y+1;j<=n;j++){
                q.push(p[now].y);
                //printf("%d\n",p[now].y);
            }
            now++;
        }
    }
    printf("Yes\n");
    for(int i = 1;i<=n*n;i++)
        printf("%d ",ans[i]);
    printf("\n");
}
/*
1441152
*/

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N, M, R, A[40000], B[40000], r[10];
ll C[40000], dist[201][201];
ll ans = LONG_LONG_MAX / 2;

void floyd(){
    REP(k, N){
        REP(i, N){
            REP(j, N){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

void solve(int depth, int index, int state, ll value){
    if(depth == R){
        ans = min(ans, value);
    }
    REP(i, R){
        if((1 << i) & state) continue;
        solve(depth + 1, r[i], state | (1 << i), value + dist[index][r[i]]);
    }
}

signed main(){
    cin >> N >> M >> R;
    REP(i, R){
        cin >> r[i];
        r[i]--;
    }
    REP(i, N) REP(j, N) dist[i][j] = LONG_LONG_MAX / 2;
    REP(i, M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
        dist[A[i]][B[i]] = dist[B[i]][A[i]] = C[i];
    }
    floyd();
    REP(i, R) solve(1, r[i], 1 << i, 0);
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 896
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

using namespace std;

int main()
{
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> l(n);
    for (auto& i : l)
    {
        cin >> i;
    }
    sort(l.begin(), l.end());
    ans = accumulate(l.end() - k, l.end(), 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  LINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int x,y;
  cin >> x >> y ;
  
  vi a = {0,1,3,1,2,1,2,1,1,2,1,2,1};

  cout << (a[x]==a[y] ? "Yes" : "No") << endl; 
  return 0;
} 

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> A(N);
  vector<long long> B(N-K+1);
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < N-K; i++) {
    if(A.at(i) < A.at(i+K)) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 6388
import java.util.Scanner;

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

		if (500 * a >= b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21588
#include <stdio.h>
#include <string.h>
int main(){
	
	int arr[3][3]={0};
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			scanf("%d", &arr[i][j]);
		}
	}
	int N;
	scanf("%d", &N);
	int numb[N]={0};
	
	for (int k=0;k<N;k++){
		scanf("%d", &numb[k]);
		for(int l=0;l<3;l++){
			for(int m=0;m<3;m++){
				if(numb[k] == arr[l][m]){
					arr[l][m] = 0;
				}
			}
		}
	}
	if(arr[0][0]==0 && arr[0][1]==0 && arr[0][2]==0){
		printf("Yes");
	} else if(arr[1][0]==0 && arr[1][1]==0 && arr[1][2]==0){
		printf("Yes");
	} else if(arr[2][0]==0 && arr[2][1]==0 && arr[2][2]==0){
		printf("Yes");
	} else if(arr[0][0]==0 && arr[1][0]==0 && arr[2][0]==0){
		printf("Yes");
	} else if(arr[0][1]==0 && arr[1][1]==0 && arr[2][1]==0){
		printf("Yes");
	} else if(arr[0][2]==0 && arr[1][2]==0 && arr[2][2]==0){
		printf("Yes");
	} else if(arr[0][0]==0 && arr[1][1]==0 && arr[2][2]==0){
		printf("Yes");
	} else if(arr[0][2]==0 && arr[1][1]==0 && arr[2][0]==0){
		printf("Yes");
	} else {
		printf("No");	
	}
	
	return 0;
}

Measured memory_bytes: 1720
#include<stdio.h>
int main(){
    int A,B,C;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    
    int answer = C - (A-B);
    if(answer <= 0){
        printf("0\n");
    }else{
        printf("%d\n",answer);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	vector <int> height;
	vector <int> gd;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		height.push_back(a);
		gd.push_back(true);
	}
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		if(height[a] > height[b]){
			gd[b] = false;
		}
		if(height[b] > height[a]){
			gd[a] = false;
		}
		if(height[b] == height[a]){
			gd[a] = false;
			gd[b] = false;
		}
	}
	int cnt = 0;
	for(int i = 0; i < n; i++){
		//cout << i << ": " << gd[i] << '\n';
		if(gd[i]){
			cnt++;
		}
	}
	cout << cnt;
}

Measured memory_bytes: 4316
#include<bits/stdc++.h>
using namespace std;
long long a,b,n;
long long ans;
int main(){
	cin>>a>>b>>n;
	if(n<b){
		cout<<max(ans,a*n/b-a*(n/b));
	}
	else{
		if(a*b>n){
			for(long long i=b-1;i<=n;i+=b){
				long long tot=a*i/b-a*(i/b);
				if(tot>ans){
					ans=tot;
				}
			}
		}
		else{
			for(long long i=1;i<=a;i++){
				long long tot=a*(i*b-1)/b-a*(i-1);
				if(tot>ans){
					ans=tot;
				}
			}
		}
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 3588
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}


void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////



ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}


#define N 2000004
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}

void debug(ll n){
    ll a[n-1];rep(i,1,n-1)a[i-1]=i;
    ll ans[n];memset(ans,0,sizeof(ans));
    do{
        bool used[n];memset(used,false,sizeof(used));
        rep(i,1,n-1){
            rep(j,0,n-2){
                if(a[j]==i){
                    used[j]=used[j+1]=true;
                }
            }
            bool f=true;
            rep(j,0,n-1)if(!used[j])f=false;
            if(f){
                ans[i]++;break;
            }
        }
    }while(next_permutation(a,a+n-1));
    rep(i,(n+1)/2,n-1)cout<<i<<":"<<ans[i]<<endl;
}

int main(){fastio
    calc();
    ll n;cin>>n;
    //debug(n);
    ll ans=0;
    ll zen=0;
    rep(k,(n+1)/2,n-1){
        ll sum=comb(k-1,n-1-k);
        sum=mod(sum*kai[k]);
        sum=mod(sum*kai[n-1-k]);
        Add(ans,(sum-zen)*k);
       // cout<<k<<":"<<sum-zen<<endl;
        zen=sum;
    }
    cout<<mod(ans)<<endl;
    
    return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;

using namespace std;
using ll = long long;


class ipy
{
private:
	/* data */
public:
	int i, p, y;
	ipy(int ii, int pp, int yy) {
		i = ii;
		p = pp;
		y = yy;
	}
	~ipy() { }
};

int main() {
	vector<ipy> i_p_y;
	vector<int> p_ord(100001, 1);
	int N, M;
	cin >> N >> M;
	for (int i = 1; i != M + 1; ++i) {
		int p, y;
		cin >> p >> y;
		i_p_y.push_back(ipy(i, p, y));
	}
	vector<pair<int, int> > out(M + 1);
	sort(begin(i_p_y), end(i_p_y), [](ipy l, ipy r){ return l.y < r.y; });
	for (int i = 0; i != M; ++i) {
		out[i_p_y[i].i] = pair<int, int>(i_p_y[i].p, p_ord[i_p_y[i].p]);
		++p_ord[i_p_y[i].p];
	}
	for (int i = 1; i < M + 1; ++i) {
		cout << std::setfill('0') << std::setw(6) << out[i].first;
		cout << std::setfill('0') << std::setw(6) << out[i].second;
		cout << endl;
	}
}



Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}, K{}; std::cin >> N >> K;
  vector<ll> H(N);
  rep(0, H.size()) cin >> H[i];

  vector<ll> dp(N);
  rep(1, dp.size())
  {
    auto inf = i > K ? i - K : 0;
    vector<ll> tmp(i - inf);
    rep_uj(inf, i)
    {
      tmp[j - inf] = dp[j] + std::abs(H[i] - H[j]);
    }
    dp[i] = *boost::min_element(tmp);
  }

  auto ans = dp[dp.size() - 1];
  cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


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

using namespace std;

#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz(a) int((a).size())
#define F first
#define S second

#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 travel(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define INDEX(arr,ind)          (lower_bound(all(arr),ind)-arr.begin())

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;


typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

inline ll powmod(ll x, ll n, ll _mod){ 
  ll res = 1; 
  while (n){
    if (n & 1)res = (res*x) % _mod; 
    x = (x*x) % _mod; 
    n >>= 1;
    }
    return res; 
  }

#define N 200005

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int d,n;
    cin>>d>>n;
    vi v;
    for(int i=1;sz(v)<n;i++){
        int c=0;
        int j=i;
        while(j%100==0 and j>0){
            c++;
            j/=100;
        }
        if(c==d){
            v.pb(i);
            //cout<<i<<" **\n";
        }
        // cout<<i<<" "<<sz(v)<<endl;
        // if(i>500)break;
    }
    cout<<v[v.size()-1]<<'\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int d = s.nextInt();
        // int  a = d % 10;

        // if(a == 3) {
        //     System.out.println("bon");
        // } else if( a== 0 || a == 1 || a == 6 || a == 8) {
        //     System.out.println("pon");
        // } else {
        //     System.out.println("hon");
        // }
        String str = s.next();
        char c[] = str.toCharArray();
        if(c.length>d) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < d; i++) {
                sb.append(c[i]);
            }
            sb.append("...");
            System.out.println(sb.toString());
        } else {
            System.out.println(str);
        }
    }
}

Measured memory_bytes: 35804
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

l_list = [LR[i][0] for i in range(M)]
r_list = [LR[i][1] for i in range(M)]

l = max(l_list)
r = min(r_list)

if r-l < 0:
  print(0)
else:
  print(r-l+1)

Measured memory_bytes: 29024
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int a, b, k, tmp;
    cin >> a >> b >> k;
    for (int i=0; i<k; ++i){
        // takahashi
        if(i % 2 == 0){
            if(a % 2 == 0){
                tmp = a / 2;
                a -= tmp;
                b += tmp;
            }
            else if(a % 2 == 1){
                if(a > 0){
                    a -= 1;
                }
                tmp = a / 2;
                a -= tmp;
                b += tmp;
            }
        }
        // aoki
        else if(i % 2 == 1){
            if(b % 2 == 0){
                tmp = b / 2;
                b -= tmp;
                a += tmp;
            }
            else if(b % 2 == 1){
                if(b > 0){
                    b -= 1;
                }
                tmp = b / 2;
                b -= tmp;
                a += tmp;
            }
        }
    }
    cout << a << " " << b << endl;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 
  if ((A + B) > (C + D)){
    cout << "Left" << endl;
  }
  else if((A + B) == (C + D)){
    cout << "Balanced" << endl;
  }
  else 
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

vector<pair<ll,ll>> prime_factorize(ll n) {
    vector<pair<ll,ll> > res;
    for (ll p = 2;p*p <= n;++p) {
        if (n%p!=0) continue;
        int num = 0;
        while(n%p ==0) {
            ++num;
            n/=p;
        }
        res.push_back(make_pair(p,num));
    }
    if (n!=1) res.push_back(make_pair(n,1));
    return res;
}


int main() {
    ll n; cin >>n;
    auto pf = prime_factorize(n);
    ll res = 0;
    for(auto p:pf) {
        ll t = p.second;
        ll tmp = 0,cur = 1;
        while(t>=cur) t -=cur++,++tmp;

        res += tmp;
    }

        cout << res << endl;
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> tele(N);
  for(ll i = 0LL; i < N; i++) {
    ll A;
    cin>>A;
    tele[i]=A-1LL;
  }
  vector<bool> seen(N,false);
  map<ll,ll> visit;
  seen[0]=true;
  ll t = 0LL;
  ll nt = tele[0];
  ll i = 0LL;
  visit[0]=0;
  ll ans = 0LL;
  while(!seen[nt]){
    i++;
    t=nt;
    if(i==K) {
      ans = t;
      break;
    }
    visit[nt]=i;
    seen[nt]=true;
    nt=tele[t];
  }
  ll l = i + 1LL - visit[nt];
  if(K>i){
    ll t = K-i-1LL;
    ll tt = t%l;
    tt+=visit[nt];
    for(auto x:visit){
      if(x.second==tt) ans=x.first;
    }
  }
  cout<<ans+1LL<<endl;
}

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

int main()
{
   std::string days;
   int month, day;

   std::cin >> days;

   month = (days[5]-'0')*10 + (days[6]-'0');
   day = (days[8]-'0')*10 + (days[9]-'0');

   if(month == 4){
      if(day <= 30){
         std::cout << "Heisei" << std::endl;
      }
   }else if(month < 4){
      std::cout << "Heisei" << std::endl;
   }else{
      std::cout << "TBD" << std::endl;
   }

   return 0;
}


Measured memory_bytes: 256
s = input()

s1 = int(s[:2])
s2 = int(s[2:])

yymm_flag = False
mmyy_flag = False

if 0 < s1 and s1 < 13:
    mmyy_flag = True
if 0 < s2 and s2 < 13:
    yymm_flag = True

if yymm_flag and mmyy_flag:
    print("AMBIGUOUS")
elif yymm_flag:
    print("YYMM")
elif mmyy_flag:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3064
N = int(input())
S1 = list(input())
S2 = list(input())

i = 0
ans = 1
tmp = ''

for _ in range(N):
    if i < N:
        if S1[i] == S2[i]:
            if tmp == '':
                ans *= 3
            elif tmp == 'X':
                ans *= 2
            else:
                ans *= 1   

            tmp = 'X'
            i += 1
      
    if i < N - 1:
        if S1[i] == S1[i+1] and S2[i] == S2[i+1]:
            if tmp == '':
                ans *= 6
            elif tmp == 'X':
                ans *= 2
            else:
                ans *= 3

            tmp = 'Y'
            i += 2
        

        
print(ans%1000000007)

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

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

int main(){
  long int x;
  cin >> x;
  
  long int k = 100;
  int c = 0;
  while(k < x){
    k += k/100;
    c++;
  }
  cout << c << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>

using namespace std;

int main(){
	long long m,n,ans;
	cin >> m >> n;
	
	if(abs(m-n)>=2){
		cout << "0" << endl;
		return 0;
	}
	
	long long ptn_m=1;
	for(long long i=1;i<=m;i++){
		ptn_m*=i;
		ptn_m=ptn_m%1000000007;
	}
	
	long long ptn_n=1;
	for(long long i=1;i<=n;i++){
		ptn_n*=i;
		ptn_n=ptn_n%1000000007;
	}
	
	if(abs(m-n)==1){
		ans=ptn_m*ptn_n;
	}else{
		ans=ptn_m*ptn_n*2;
	}
	ans=ans%1000000007;
	cout << ans << endl;
		
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi 2*acos(0.0)
#define MOD 1000000007
#define N 100001
#define SZ 100000
int fx[5]= {0,0,0,-1,1};
int fy[5]= {0,-1,1,0,0};
int main()
{
    int n=5,x,i,ans;

    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x==0)
            ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3584
from collections import deque


def topological_sort(graph: list) -> list:
    """入力した重みなしDAGに対してトポロジカルソートする
    計算量: O(|V|+|E|)
    入力条件: グラフGはDAGである、グラフGに多重辺はない、グラフGに自己ループはない
    """
    n = len(graph)
    degree = [0] * n
    for g in graph:
        for next_pos in g:
            degree[next_pos] += 1
    
    # 次数が0、つまり入力の無い頂点を初期値状態とする
    ans = [i for i in range(n) if degree[i] == 0]

    q = deque(ans)
    while q:
        pos = q.popleft()
        for next_pos in graph[pos]:
            degree[next_pos] -= 1
            if degree[next_pos] == 0:
                q.append(next_pos)
                ans.append(next_pos)
    return ans

n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n)]
for i in range(m):
    a, b = info[i]
    graph[a].append(b)
ans = topological_sort(graph)
for pos in ans:
    print(pos)


Measured memory_bytes: 15560
#include<bits/stdc++.h>
#define LL long long
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int N=505;
const int p=998244353;
int n;
int a[N][N];
LL w[N][N],vv[N][N];
LL f[N][N];

void read(int &x){ scanf("%d",&x); }
void read(LL &x){ scanf("%lld",&x); }

LL vwv(int a,int b,int c){
	return w[b][c]-w[a-1][c];
}

void chkmin(LL &x,LL y){
	if (y<x) x=y;
}

int main(){
	read(n);
	fr(i,1,n)
	 fr(j,1,n)
	  if (i!=j) read(a[i][j]);
	fr(i,1,n)
	 rf(j,n,i+1){
	 	w[i][j]=w[i][j+1];
	 	fr(k,1,i) w[i][j]+=a[j][k];
	 }
	fr(i,1,n)
	 fr(j,i+1,n+1){
	 	vv[i][j]=vv[i][j-1];
	 	fr(k,i,j-1) vv[i][j]+=a[k][j];
	 }
	memset(f,0x3f,sizeof f);
	f[0][0]=0;
	fr(i,0,n)
	 fr(j,i,n)
	  if (f[i][j]<1e18){
	  	fr(k,j+1,n+1)
	  	 chkmin(f[j][k],f[i][j]+vv[j+1][k]+vwv(i+1,j,k+1));
	  }
	LL ans=1e18;
	fr(i,0,n) chkmin(ans,f[i][n+1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7168
#include <iostream>
using namespace std;
int main (){

  int room[4][3][10]={0},n,b,f,r,v;

  cin >>n;

  for( int i=0 ; n > i ; i++ ){
    
    cin >>b>>f>>r>>v;

    room[b-1][f-1][r-1]=room[b-1][f-1][r-1]+v;

  }

  for( int j=0 ; j < 3 ; j++){
    for( int k=0 ; k < 10 ; k++){
       
      cout <<" "<<room[0][j][k];
    }
    cout <<"\n";
  }

  cout <<"####################\n";

  for( int l=0 ; l < 3 ; l++){
    for( int m=0 ; m < 10 ; m++){

      cout <<" "<<room[1][l][m];
    }
    cout <<"\n";
  }

  cout <<"####################\n";

  for( int n=0 ; n < 3 ; n++){
    for( int o=0 ; o < 10 ; o++){
      
      cout <<" "<<room[2][n][o];
    }
    cout <<"\n";
  }

  cout <<"####################\n";

  for( int p=0 ; p < 3 ; p++){
    for( int r=0 ; r < 10; r++){

      cout <<" "<<room[3][p][r];
    }
    cout <<"\n";
  }

}



  

Measured memory_bytes: 1168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define f first
#define s second

typedef pair<int, int> P;

int main(){
  int n;
  while(cin >> n, n){
    vector<P> book(n);
    rep(i, n) cin >> book[i].f >> book[i].s;
    
    sort(book.rbegin(), book.rend());
    
    int sum_w = 0;
    rep(i, n) sum_w += book[i].s;
    
    int Maxr = book[0].f;
    int Relse = 0;
    for(int i = 1 ; i < n ; i++) Relse += book[i].f;
    
    if(Maxr > Relse){
      bool dp[1010][1010];
      memset(dp, false, sizeof(dp));
      dp[0][0] = true;
      book[0].s = 0;
      for(int i = 0 ; i < n ; i++){
	for(int j = 0 ; j + book[i].s <= Maxr-Relse ; j++){
	  if(!dp[i][j]) continue;
	  dp[i+1][j] = dp[i+1][j+book[i].s] = true;
	}
      }
      int maxWrite = 0;
      for(int i = 0 ; i <= Maxr-Relse ; i++){
	if(dp[n][i]) maxWrite = i;
      }
      int ans = 2* Maxr + sum_w - maxWrite;
      cout << ans << endl;
    }
    
    else{
      int ans = Maxr + Relse + sum_w;
      cout << ans << endl;
    }
  }
  return 0;
}

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

struct PLANT
{
	string L;
	double eff;
	
	bool operator < (const PLANT& t) const {
		if (eff == t.eff){
			return L < t.L;
		}
		return eff > t.eff;
	}
};

PLANT plant[50];

int main()
{
	int n;
	while (cin >> n, n){
		for (int i = 0; i < n; i++){
			cin >> plant[i].L;
			int p, a, b, c, d, e, f, s, m;
			cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			int A = s * f * m - p;
			int B = (a + b + c) + (d + e) * m;
			plant[i].eff = (double)A / B;
		}
		
		sort(plant, plant + n);
		
		for (int i = 0; i < n; i++){
			cout << plant[i].L << endl;
		}
		cout << "#" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
let args = readLine()!.split(separator: " ").map { Int($0)! }

let n = args[0]

var result = ""
switch n % 10 {
case 2, 4, 5, 7, 9:
    result = "hon"

case 0, 1, 6, 8:
    result = "pon"
    
default:
    result = "bon"
}

print(result)

Measured memory_bytes: 8292
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;
 
class Data{
public:
  string lhs;
  string rhs;
  int power;
  Data(string _l,string _r, int _p){
    lhs = _l;
    rhs = _r;
    power = _p;
  }
};
 
map<string,int> gUnit;
int gCount = 0;
 
int dp[101][101];
 
int unit2num(string str){
  if(gUnit.find(str) == gUnit.end()){
    gUnit[str]=gCount++;
  }
 
  return gUnit[str];
}
 
int main(){
  int n;
 
  while(~scanf("%d",&n)){
    if(n==0) break;
    gCount = 0;
    gUnit.clear();
    memset(dp,0x3f,sizeof(dp));
 
    vector<Data> relations;
    for(int i=0;i<n;i++){
      int num;
      string lhs;
      string eq;
      string rhs;
      string tmp;
 
      cin >> num >> lhs >> eq >> tmp >> rhs;
      int base,pow;
      sscanf(tmp.c_str(),"%d^%d",&base,&pow);
      relations.push_back(Data(lhs,rhs,pow));
    }
 
    for(int i=0;i<relations.size();i++){
      dp[unit2num(relations[i].lhs)][unit2num(relations[i].rhs)] = -relations[i].power;
      dp[unit2num(relations[i].rhs)][unit2num(relations[i].lhs)] = relations[i].power;
    }
 
    for(int k=0;k<gCount;k++){
      for(int i=0;i<gCount;i++){
	for(int j=0;j<gCount;j++){
	  dp[i][j] = min(dp[i][k] + dp[k][j],dp[i][j]);
	}
      }
    }
 
    bool isok = true;
    for(int i=0;i<gCount;i++){
      if(dp[i][i] != 0) isok = false;
    }
    printf("%s\n",isok ? "Yes" : "No");
  }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   int n;cin >>n;
   vector<P>pos(n);
    for (int i = 0; i < n; ++i) {
        int x,y;cin >>x>>y;
        pos[i]={x,y};
    }
    ll ans=INF;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ll p,q;
            ll now=0;
            if(i==j)continue;
            p=pos[i].first-pos[j].first;
            q=pos[i].second-pos[j].second;
            for (int k = 0; k < n; ++k) {
                bool flg=false;
                for (int l = 0; l <n; ++l) {
                    if(k==l)continue;
                    ll dx=pos[k].first-pos[l].first;
                    ll dy=pos[k].second-pos[l].second;
                    if(dx==p&&dy==q)flg=true;
                }
                if(!flg)now++;
            }
//            cout <<p<<" "<<q<<" "<<now<<endl;
            ans=min(ans,now);
        }
    }
    if(n==1)cout <<1<<endl;
    else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 3604
s = int(input())

a = [s]

while True:
    if a[-1]%2 ==0:
        a.append(a[-1]//2)
    else:
        a.append(a[-1]*3+1)
    
    for i in range(0,len(a)-1):
        if a[-1] == a[i]:
            break
    else:
        continue
    break
print(len(a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define N 55
#define int long long
using namespace std;
const int s = ('a'-1);
const int mod = (1e9)+7;
int n;
string str[N];

int calc(int y,int x,int ch){
  if(x>=(int)str[y].size() || ch>=27) return 0;
  int k = 0;
  if(str[y][x] != '?') k = 1;
  if(str[y][x] == '?') k = 27 - ch;
  if(k == 0) return 0;
  int res = 1;
  for(++x;x<(int)str[y].size();x++) if(str[y][x]=='?') res = (res*26)%mod;
  return (res*k)%mod;
}


bool check(int u,int d,int x,char ch){
  for(int y=u;y<=d;y++) if(str[y][x] != '?' && str[y][x] != ch) return 0;
  return  1;
}

int mem[N][N][22][30],used[N][N][22][30];
int dfs(int u,int d,int x,int c){
  if(u > d) return 1;
  if(u == d) return calc(u,x,c);
  if(x >= 21) return 0;
  if(c > 26) return 0;
  if(str[u][x] == s) return (c == 1 && str[u+1][x] != s ? dfs(u+1,d,x,c):0);
  if(used[u][d][x][c]++) return mem[u][d][x][c];

  vector<int> mnc(N,30);
  for(int y=d;y>=u;y--)mnc[y] = min(mnc[y+1],str[y][x]=='?'? 30:str[y][x] - s);  
  
  int res = dfs(u,d,x,c+1); 
  //[u,y]?????????????????????????????????????????????
  for(int y=u;y<=d;y++){
    if(mnc[y+1] <= c || !check(u,y,x,c+s)) continue;
    res = (res+(dfs(u,y,x+1,1)*dfs(y+1,d,x,c+1))%mod)%mod;
  }
    return mem[u][d][x][c] = res;
}


signed main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str[i];
    while(str[i].size()<21) str[i]+=s;
  }
  cout<<dfs(0,n-1,0,1)<<endl;
  return 0;
}

Measured memory_bytes: 16212
/*
                            Author: Ankit Kaul
*******Code Belongs to Respective Author Only*************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
/*freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}   
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi
    int n;
    cin>>n;
    string str;
    cin>>str;
    int res=0,ans=0;
    for(int i=0;i<n;i++)
    {   if(str[i]=='R')
        res++;
    }
    for(int i=0;i<res;i++)
    {   if(str[i]=='W')
        ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3780
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int n;
    cin >> n;
	priority_queue<int> que;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		que.push(a);
	}

    int a1, a2;
    a1 = que.top();
    que.pop();



	int buf = 0;
	if (a1 % 2 == 0) {
		buf = a1 / 2;
	}
	else {
		buf = (a1 + 1) / 2;
	}

	int minBuf = buf;
	do {
		int a = que.top();
		que.pop();
		if (abs(buf - a) <= minBuf) {
			minBuf = abs(buf - a);
			a2 = a;
		}
	} while (que.size() != 0);

    cout << a1 << " " << a2 << endl;

	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
#define P pair<int, int>
const int N = 4222;
int f[N][N], cntb[N][N], cntw[N][N];
int col[N], idx[N], x[N];
int n;
char str[233];

inline void U(int &x, int y) {
  x = min(x, y);
}

inline int doit(int now, int B, int W) {
  int i = B + W;
  int pos = idx[now];
  int less = cntb[pos][B] + cntw[pos][W];
  // cout << i << " " << less << " " << pos << "\n";
  return i - less + pos;
}

main(void) {
  read(n);
  for(int i = 1; i <= 2 * n; i ++) {
    scanf("%s", str); read(x[i]);
    if(str[0] == 'B') {
      for(int k = i; k <= 2 * n; k ++)
        cntb[k][x[i]] ++;
    }
    else {
      for(int k = i; k <= 2 * n; k ++)
        cntw[k][x[i]] ++;
    }
    x[i] += (str[0] != 'B') * n;
    idx[x[i]] = i;
  }
  // arr(idx, 2 * n);
  for(int i = 1; i <= 2 * n; i ++)
    for(int j = 1; j <= 2 * n; j ++)
      cntb[i][j] += cntb[i][j - 1], cntw[i][j] += cntw[i][j - 1];
  // out(doit(6, 0, 2));
  // return 0;
  for(int i = 0; i <= 2 * n; i ++)
    for(int has = 0; has <= n; has ++)
      f[i][has] = 1e9;
  f[0][0] = 0;
  for(int i = 0; i < 2 * n; i ++) {
    for(int has = 0; has <= min(i, n); has ++)
      if(f[i][has] != 1e9) {
        int B = has, W = i - has, pos;
        int Bp = B + 1, Wp = W + n + 1;
        // if(Bp > n || Wp > 2 * n) continue;
        // B
        pos = doit(Bp, B, W);
        U(f[i + 1][has + 1], f[i][has] + abs(pos - i - 1));
        // W
        pos = doit(Wp, B, W);         
        // cout << Wp << " " << B << " " << W << " " << pos << "\n";
        U(f[i + 1][has], f[i][has] + abs(pos - i - 1));
      }
  }
  // for(int i = 1; i <= 2 * n; i ++) {
  //   for(int has = 0; has <= min(i, n); has ++)
  //     cout << f[i][has] << " ";
  //   puts("--");
  // }
  cout << f[2 * n][n] << "\n";
}


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

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

    tuple<int, int, int> data[M];
    // (Y_i, P_i, i)の配列

    for (int i = 0; i < M; ++i) {
        int p, y;
        cin >> p >> y;
        data[i] = make_tuple(y, p, i);
    }

    // tupleをソートするときは第一要素がkeyとなる
    // つまりY_iによって昇順にソートされる
    sort(data, data + M);

    int cnt[N + 1];
    fill(cnt, cnt + N + 1, 0);
    // 各県に今属している市の数

    pair<int, int> id[M];
    // 各市の(属する県、県の中で誕生した順番)

    for (int i = 0; i < M; ++i) {
        int y, p, idx;
        tie(y, p, idx) = data[i];
        ++cnt[p];
        id[idx] = make_pair(p, cnt[p]);
    }

    for (int i = 0; i < M; ++i) {
        // setwで文字数、setfillで埋める文字を指定
        // iomanipをincludeする必要があるので注意
        cout << setw(6) << setfill('0') << id[i].first;
        cout << setw(6) << setfill('0') << id[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 3840