akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i

edges = []
g = Array.new(n){ [] }
(n-1).times do |i|
  a,b = gets.split.map(&:to_i).map{|k|k-=1}
  a, b = b, a if a > b # 辺は頂点 i < j の形で入れる。
  g[a] << b # 隣接リストに
  g[b] << a # 反対向きにも隣接リストに.無向グラフなので
  edges << [a,b] # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [0] # 頂点0から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while !que.empty? do
  v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    next if used[w] == true # 探索済みの頂点なら見ない。
    k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    # next if colors[[i,j]] != nil # nilでなければi-jの辺に色がついてて頂点jは探索済みで,次に。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

Measured memory_bytes: 58620
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int nr=gi();

	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    System.out.print(nr*2*Math.PI);


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35728
//created by missever

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;

int add(int x, int y) {
    x += y;
    if(x >= mod) x -= mod;
    return x;
}

int mul(int x, int y) {
    LL z = 1LL * x * y;
    return z - z / mod * mod;
}

char s[maxn];
vector<int> f;
int d[maxn],n;
int w[maxn];

bool check(int x) {
    int l, r;
    l = r = 1;
    w[0] = 0;
    for(auto e:f) {
        if(e >= x) return true;
        w[r] = w[r - 1] + e;
        d[r++] = e;
        while(r - l > 2) {
            if(w[r - 2] >= x && n - w[r - 3] >= x) {
                w[r - 3] = w[r - 1];
                d[r - 3] = d[r - 1] + d[r - 2] + d[r - 3];
                r -= 2;
                if(d[r - 1] >= x) return true;
            } else break;
        }
    }
    return false;
}

int main() {
#ifdef CX_TEST
    freopen("E:\\program--GG\\test_in.txt", "r", stdin);
#endif
    int i, j;
    scanf("%s", s);
    n = strlen(s);
    i = j = 0;
    while(i < n) {
        while(j < n && s[j] == s[i]) j++;
        f.push_back(j - i);
        i = j;
    }
    int l, r;
    l = 1;
    r = n;
    while(l < r) {
        //cout<<l<<" "<<r<<endl;
        int mid = (l + r + 1) >> 1;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }
    printf("%d\n", l);
    return 0;
}


Measured memory_bytes: 1020
s = input()
q = int(input())
cnt = 0
left = ''
right = ''
for i in range(q):
    query = list(input().split())
    if int(query[0])==1:
        cnt += 1
    elif int(query[0])==2:
        if int(query[1])==1:
            if cnt%2==0:
                left = query[2] + left
            else:
                right = right + query[2]
        elif int(query[1])==2:
            if cnt%2==0:
                right = right + query[2]
            else:
                left = query[2] + left

if cnt%2==0:
    print(left+s+right)
else:
    s=left+s+right
    s=s[::-1]
    print(s)


Measured memory_bytes: 4444
dice1 = input().split()
dice2 = input().split()

def rotate(faces, move):
    for i in range(len(move)):
        m = move[i]
        
        if m == "N":
            # N
            tmp = faces[4]
            faces[4] = faces[0]
            faces[0] = faces[1]
            faces[1] = faces[5]
            faces[5] = tmp
            
        elif m == "S":
            # S
            tmp = faces[1]
            faces[1] = faces[0]
            faces[0] = faces[4]
            faces[4] = faces[5]
            faces[5] = tmp
            
        elif m == "E":
            # E
            tmp = faces[2]
            faces[2] = faces[0]
            faces[0] = faces[3]
            faces[3] = faces[5]
            faces[5] = tmp
            
        elif m == "W":
            # W
            tmp = faces[3]
            faces[3] = faces[0]
            faces[0] = faces[2]
            faces[2] = faces[5]
            faces[5] = tmp

# for k, v in enumerate(dice1):
#     print(k, v)
#     if v in dice2:
#         index1 = dice2.index(v)
#         print(index1)

# if dice1[2] in dice2:
#     index1 = dice2.index(dice1[2])
#     if index1 == 0:
#         rotate(dice1, "W")
#     elif index1 == 1:
#         rotate(dice1, "WS")
#     elif index1 == 2:
#         pass
#     elif index1 == 3:
#         rotate(dice1, "WW")
#     elif index1 == 4:
#         rotate(dice1, "WN")
#     elif index1 == 5:
#         rotate(dice1, "E")
        
def equals(a, b):
    for (a, b) in zip(dice1, dice2):
        if a != b:
            return False
            
    return True

isMatch = equals(dice1, dice2)

copy_list = dice1.copy()

looping = True
for j in range(4):
    #print(dice1)
    if isMatch:
        break
    for i in range(4):
        # print(dice1)
        rotate(dice1, "N")
        if equals(dice1, dice2):
            isMatch = True
            break
    #print('----')
    #print(dice1)
    rotate(dice1, "W")
    #print(dice1)

# print('---- ---- ----')
#print(copy_list)
# print('---- ---- ----')

rotate(dice1, "NW")

for j in range(4):
    #print(dice1)
    if isMatch:
        break
    for i in range(4):
        #print(dice1)
        rotate(dice1, "N")
        if equals(dice1, dice2):
            isMatch = True
            break
    #print('----')
    #print(dice1)
    rotate(dice1, "W")
    #print(dice1)


if isMatch:
    print('Yes')
else:
    print('No')



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

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0; i<n; i++){
        cin >> vec.at(i);
    }
    vec.push_back(0);
    int color = 0, cnt = 0, ans = 0;
    for(int i=0; i<=n; i++){
        if(vec.at(i) == color){
            cnt++;
        }else{
            ans += cnt/2;
            color = vec.at(i);
            cnt = 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int A, B, C;
  int X;
  int i, j, k;
  int count = 0;

  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  scanf("%d", &X);

  for(i = 0; i <= A; i++){
    for(j = 0; j <= B; j++){
      if((X/50 - 10*i - 2*j) <= C && (X/50 - 10*i - 2*j) >= 0){
        k = X/50 - 10*i - 2*j;
        if(i != 0 || j != 0 || k != 0){
          count++;
        }
      }
    }
  }

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


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

using namespace std;

typedef long long ll;

ll a[100005],b[100005];
int q[100005];

int main() {
  int n,s;
  scanf("%d%d",&n,&s);
  int id=0;
  for(int i=1;i<=n;i++) {
  	scanf("%lld%lld",&a[i],&b[i]);
  	if (a[i]<s) id=i;
  }
  int cnt=0,l=1,r=n;
  while ((l<=id)^(r<=id))
    if (b[l]>=b[r]) {
    	q[++cnt]=a[r];
    	b[l]+=b[r];
    	r--;
	}
	else {
		q[++cnt]=a[l];
		b[r]+=b[l];
		l++;
	}
  if (r<=id) {
  	for(int i=l;i<=r;i++) q[++cnt]=a[i];
  }
  else {
  	for(int i=r;i>=l;i--) q[++cnt]=a[i];
  }
  q[cnt+1]=s;
  ll ans=0;
  for(int i=1;i<=cnt;i++) ans+=abs(q[i]-q[i+1]);
  printf("%lld\n",ans);
  return 0;
}


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

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define INF 1000000009
#define mod 1000000007
using namespace std;
typedef long long ll;

int n;
ll k;
struct matris{
	ll mat[51][51];
};

void prtmat(matris* mat1){
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			cout << mat1 -> mat[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}

void matcarp(matris* a, matris* b){
	//cout << "matcarp" << endl;
	matris* ans = (matris *)malloc(sizeof(matris));
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			ll zx = 0;
			for (int k = 0; k < n; k++){
				zx += (a->mat[i][k]*b->mat[k][j])%mod;
				zx %= mod;
			}
			//cout << "ans(" << i << ", " << j << ") = " << zx << endl; 
			ans->mat[i][j] = zx;
			//cout << "ans(" << i << ", " << j << ") = " << ans->mat[i][j] << endl; 
		}
	}
	//cout << "ans: " << endl;
	//prtmat(ans);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			a -> mat[i][j] = ans -> mat[i][j];
		}
	}
	//cout << "a: " << endl;
	//prtmat(a);
	free(ans);
}



void matus(matris* mat1, ll o){
	//cout << "matus" << endl;
	matris* ans = (matris *)malloc(sizeof(matris));
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			ans->mat[i][j] = (i==j);
		}
	}
	//cout << "ans: " << endl;
	//prtmat(ans);
	
	while (o){
		if (o & 1){
			matcarp(ans, mat1);
			//cout << "us ans: " << endl;
			//prtmat(ans);
		}
		matcarp(mat1, mat1);
		//cout << "mat1: " << endl;
		//prtmat(mat1);
		o >>= 1;
	}
	
	//cout << "en son ans: " << endl;
	//prtmat(ans);
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			mat1->mat[i][j] = ans->mat[i][j];
		}
	}
	free(ans);
}

int main(){
	//freopen("stl.gir", "r", stdin);
	
	cin >> n >> k;
	matris *ben = (matris *)malloc(sizeof(matris));
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			cin >> ben -> mat[j][i];
		}
	}
	
	/*for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			cout << ben->mat[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;*/
	
	//cout << "ben: " << endl;
	//prtmat(ben);
	
	matus(ben, k);
	
	//cout << "ben: " << endl;
	//prtmat(ben);
	
	ll ans = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			ans += ben->mat[i][j];
			ans %= mod;
		}
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=1e5+5,OO=1e18;
void no(){cout<<"0\n";exit(0);}
int a[N],b[N],c[N],u[N];
vector<int> g[N];
int go(int v,int i){return a[i]^b[i]^v;}
int uc[N][2],co[N][2];
void f(int v,int k,int b){
    if(uc[v][k]&&co[v][k]!=b)no();
    uc[v][k]=1;co[v][k]=b;
}
void dfs(int v){
    u[v]=1;
    for(int i:g[v]){
        int to=go(v,i);
        forn(j,2)if(uc[v][j])f(to,j^1,c[i]-co[v][j]);
        if(!u[to])dfs(to);
    }
}
int32_t main(){
    int n,m;
    cin>>n>>m;
    forn(i,m){
        cin>>a[i]>>b[i]>>c[i];
        g[a[i]].pb(i);
        g[b[i]].pb(i);
    }
    uc[1][1]=1;
    dfs(1);
    int z=-1;
    for(int i=1;i<=n;++i){
        if(uc[i][0]&&uc[i][1]){
            int sum=co[i][0]-co[i][1];
            if(sum&1)no();
            z=sum/2;
            break;
        }
    }
    if(z!=-1){
        for(int i=1;i<=n;++i){
            vector<int> vs;
            if(uc[i][0])vs.pb(-z+co[i][0]);
            if(uc[i][1])vs.pb(+z+co[i][1]);
            for(int j:vs)if(j<=0)no();
            if(sz(vs)>1&&vs[0]!=vs[1])no();
        }
        cout<<"1\n";
    }else{
        int l=1,r=OO;
        for(int i=1;i<=n;++i){
            if(uc[i][0])upn(r,co[i][0]-1);
            else upx(l,-co[i][1]+1);
        }
        cout<<max(0ll,r-l+1)<<'\n';
    }
    return 0;
}



Measured memory_bytes: 23116
h,w=map(int,input().split())
def solve(h,w):
    ans=h*w
    for i in range(1,h):
        #h-i height left 
        a=(h-i)*(w//2)
        b=(h-i)*w-a
        ans=min(ans,max(i*w,a,b)-min(i*w,a,b))
        a=((h-i)//2)*(w)
        b=(h-i)*w-a
        ans=min(ans,max(i*w,a,b)-min(i*w,a,b))
    return ans
print(min(solve(h,w),solve(w,h)))


Measured memory_bytes: 3064
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
	const int INF=1<<29;
	for(int n;scanf("%d",&n),n;){
		vector<pair<int,int> >v(n+1);
		vector<vector<int> >m(n+1);
		for(int i=0;i<=n;i++){
			if(i)scanf("%d%d",&v[i].first,&v[i].second);
			m[i].resize(4),fill(m[i].begin(),m[i].end(),INF);
		}
		m[0][0]=0;
		int i=0,r=INF;
		for(;i<n;i++){
			bool x=false;
			for(int j=0;j<4;j++)if(m[i][j]<INF){
				int dist=abs(v[i+1].first-v[i].first),dt=v[i+1].second-v[i].second;
				bool f,g;
				if(f = j<3&&dist*(j+1)<=dt)m[i+1][j+1]=min(m[i+1][j+1],m[i][j]+dist);
				if(g = v[i+1].first+v[i].first*(j+1)<=dt)m[i+1][1]=min(m[i+1][1],m[i][j]+v[i+1].first+v[i].first);
				x=x||f||g;
			}
			if(!x){
				printf("NG %d\n",i+1);
				break;
			}
		}
		if(i==n){
			int r=INF;
			for(int i=0;i<4;i++)r=min(r,m[n][i]+v[n].first);
			printf("OK %d\n",r);
		}
	}
}

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

#define fi first
#define se second
#define pb push_back

typedef long long LL;
typedef long double LD;

const LL INF = (1LL << 60);

typedef vector<LL> VLL;
LL knapsack_01(VLL& v, VLL& w, int n, LL W);

int main() {

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

  int n; LL W;
  cin >> n >> W;

  VLL v, w;
  v.assign(n + 1, 0);
  w.assign(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> v[i] >> w[i];
  }

  LL ans = knapsack_01(v, w, n, W);

  cout << ans << endl;

  return 0;
}

/**
 *
 * tested on http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B
 */
LL dp[105][100005];
LL solve(VLL& v, VLL& w, int n, LL W) {
  if (W < 0) {
    return -INF;
  } else if (n == 0 || W == 0) {
    return 0;
  } else if (dp[n][W] != -1) {
    return dp[n][W];
  } else {
    return dp[n][W] = max(solve(v, w, n - 1, W),
                          solve(v, w, n - 1, W - w[n]) + v[n]);
  }
}

LL knapsack_01(VLL& v, VLL& w, int n, LL W) {
  memset(dp, -1, sizeof(dp));
  return solve(v, w, n, W);
}


Measured memory_bytes: 85236
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

template <typename T>
T gcd(T a, T b){ return b%a==0 ? a : gcd(b%a, a); }

template <typename T>
T lcm(T a, T b){ return a*b / gcd(a, b); }

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    i64 sum = 0;
    rep(i,n) sum += a[i] - 1;
    cout << sum << endl;
    return 0;
}

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

//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n){
    //rep(j,m) cin >> a[i][j]; 
  //}
 
int main() {
  int r, D, X;
  cin >> r >> D >> X;
  vector<int> x(11);
  x[0]=X;
  rep(i,10){
    x[i+1]=r*x[i] - D;
    cout << x[i+1] << endl;
  }
} 

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

using namespace std;

using u32 = uint32_t;
using u64 = uint64_t;
using ll = long long;

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

  ll n, k;
  cin >> n >> k;

  ll md = LLONG_MAX;

  ll remainder = n % k;
  ll nMin = min(n, remainder);
  nMin = min(nMin, k - remainder);

  cout << nMin;
}


Measured memory_bytes: 256
#include<stdio.h>
int yaku(int,int);
int bai(int,int,int);

main(){
  int a,b,y;
  while(scanf("%d%d",&a,&b)!=EOF){
    y=yaku(a,b);
    printf("%d %d\n",y,bai(a,b,y));
}

}

int yaku(int a,int b){
  int x,y,r;
  if(a>=b){
    x=a;
    y=b;
  }
  else{
    x=b;
    y=a;
  }
  
  while(1){
    x%=y;
    r=x;
    x=y;
    y=r;
    
    if(y==0){break;}
  }  
  return x;
}


int bai(int a,int b,int g){
  return a/g*b;
}

Measured memory_bytes: 0
while True:
    x = [int(z) for z in input().split(" ")]
    if x[0] == 0 and x[1] == 0: break
    for h in range(0,x[0]):
        dot = h % 2
        for w in range(0,x[1]):
            if (dot == 0 and w % 2 == 0) or (dot == 1 and w % 2 == 1):
                print("#", end="")
            else:
                print(".", end="")
        print("\n", end="")
    print("")

Measured memory_bytes: 9064
#include<bits/stdc++.h>
#define ll long long int
#define fin for(i=0;i<n;i++)
#define vec vector<ll>
#define pb push_back
#define vecit vector<ll>::iterator
#define vecp vector<pair<ll,ll> >
#define vecpit vector<pair<ll,ll> >::iterator
#define mapp map<ll,ll>
#define mapr map<ll,pair<ll,ll> >
#define maprit map<ll,pair<ll,ll> >::iterator
#define mapit map<ll,ll>::iterator
#define mod1 1000000007
#define INF 10000000000
using namespace std;
int main()
{
    string x;
    string y;
    cin>>x>>y;
    ll i,j,k,l;
    ll a[x.size()+1][y.size()+1];
    ll n,m;
    n=x.size();
    m=y.size();
    for(i=0;i<=n;i++)
     {
         for(j=0;j<=m;j++)
            a[i][j]=0;
     }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(x[i-1]==y[j-1])
            {
                a[i][j]=1+a[i-1][j-1];
            }
            else
                a[i][j]=max(a[i-1][j],a[i][j-1]);
        }
    }
    //cout<<a[n][m];
    i=n;
    j=m;
    vector<char>v;
    while(a[i][j]>0)
    {
        if(x[i-1]==y[j-1])
        {
            v.pb(x[i-1]);
            i--;
            j--;
        }
        else
        {
            if(a[i][j-1]>a[i-1][j])
            {
                j--;
            }
            else
                i--;
        }

    }

       for(i=0;i<v.size();i++)
    {
        cout<<v[v.size()-1-i];

    }





}


Measured memory_bytes: 73964
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define T pair<int, int>
#define ordered_set tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
signed main(){
    fast();
    int p, n;
    cin >> p >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++)  cin >> a[i];
    int big = INT_MIN;
    int start;
    if(p+a[0]-a[n-1] > big){
        big = p+a[0]-a[n-1];
        start = 0;
    }
    for(int i=1; i<n; i++){
        if(a[i]-a[i-1] > big){
            big = a[i]-a[i-1];
            start = i;
        }
    }
    int ans = 0;
    for(int i=start+1; i<start+n; i++){
        if(i%n != 0)    ans += abs(a[i%n]-a[(i-1)%n]);
        else ans += (p+a[0]-a[n-1]);
    }
    // cerr << ans2 << endl;
    cout << ans << endl;
}


Measured memory_bytes: 1792
ans = [None, None]
red = 0
blue = 0

ans[0] = int(input())
ans[1] = input()

for j in range(ans[0]):
   if ans[1][j] == 'R':
      red +=1
   else:
      blue += 1 
if red <= blue:
   print('No')
else:
   print('Yes')


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using P = pair<int, int>;

vector<P> runLength(const vector<int>& s) {
    vector<P> res;
    int now = s[0];
    int cnt = 1;
    rep(i, 1, s.size()) {
        if (now == s[i]) {
            ++cnt;
        }
        else {
            res.emplace_back(now, cnt);
            now = s[i];
            cnt = 1;
        }
    }
    res.emplace_back(now, cnt);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> S(1 << N);
    for (auto& s : S) {
        cin >> s;
    }
    sort(all(S));
    reverse(all(S));
    vector<P> v = runLength(S);
    int idx = 0;
    priority_queue<int> que;
    que.push(N);
    while (!que.empty()) {
        if (v[idx].second > (int)que.size()) {
            cout << "No" << endl;
            return 0;
        }
        vector<int> hv;
        rep(i, 0, v[idx].second) {
            int h = que.top();
            que.pop();
            rep(hh, 0, h) {
                hv.push_back(hh);
            }
        }
        for (auto& h : hv) {
            que.push(h);
        }
        ++idx;
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int a, b, c, d, e, f, g;

void fu(bool &can, int &need, int cnt) {
    if (cnt == 0) {
        can = false;
    }
    if (cnt % 2 == 0) {
        need += 4;
    }
}

int main() {
    cin >> a >> b >> c >> d >> e >> f >> g;
    LL ans = 0;
    ans += 2ll * b;
    ans += 4ll * (a / 2);
    ans += 4ll * (d / 2);
    ans += 4ll * (e / 2);
    bool can = true;
    int need = 0;
    fu(can, need, a);
    fu(can, need, d);
    fu(can, need, e);
    if (can && need < 6) {
        ans += 6 - need;
    }
    cout << ans / 2 << endl;
    return 0;
}


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

#define ll long long
#define endl "\n"

int main(){
	ios_base::sync_with_stdio(false);

	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	ll last=a[1];
	for(ll i=3;i<n;i+=2){
		ll now=a[i]^a[i-1];
		last=last^now;
	}
	ll ans[n+1];
	ans[n]=last;
	for(ll i=n-1;i>0;i--){
		ll now=a[i+1]^a[i];
		now=now^ans[i+1];
		ans[i]=now;
	}
	for(ll i=1;i<=n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 6668
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        deque<char> Q;
        Q.emplace_back(s[0]);
        int cur = 0;
        for (int i = 3; i < s.size(); i += 3) {
            if(s[i-2] == '-'){
                cur++;
                if(Q.size() <= cur) Q.emplace_back(s[i]);
            }else {
                cur--;
                if(cur < 0) Q.emplace_front(s[i]), cur++;
            }
        }
        for (auto &&i : Q) cout << i;
        puts("");
    }
    return 0;
}


Measured memory_bytes: 3212
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int V = scanner.nextInt();
        int E = scanner.nextInt();
        int R = scanner.nextInt();
        scanner.nextLine();

        BellmanFord bellmanFord = new BellmanFord(V);
        for (int i = 0; i < E; i++) {
            int[] e = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            bellmanFord.addEdge(e[0], e[1], e[2]);
        }

        bellmanFord.run(R);
        for (int i = 0; i < V; i++) {
            if (bellmanFord.dist[i] == Long.MIN_VALUE) {
                System.out.println("NEGATIVE CYCLE");
                return;
            }
        }
        for (int i = 0; i < V; i++) {
            if (bellmanFord.dist[i] == Long.MAX_VALUE / 2)
                System.out.println("INF");
            else
                System.out.println(bellmanFord.dist[i]);
        }
    }
}

class BellmanFord {

    private int size;
    public long[] dist;
    public long[] from;
    public List<Edge> edges;

    public BellmanFord(int size) {
        this.size = size;
        dist = new long[size];
        Arrays.fill(dist, Long.MAX_VALUE / 2);
        from = new long[size];
        Arrays.fill(from, -1);
        edges = new ArrayList<>();
    }

    public void addEdge(int from, int to, int cost) {
        edges.add(new Edge(from, to, cost));
    }

    public void run(int start) {
        dist[start] = 0;
        for (int i = 0; i < size; i++) {
            boolean updated = false;
            for (Edge e : edges) {
                if (dist[e.from] != Long.MAX_VALUE / 2
                        && dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to] = dist[e.from] + e.cost;
                    from[e.to] = e.from;
                    updated = true;
                }
            }
            // found loops. update all nodes in loops with Long.MIN_VALUE
            if (i == size - 1 && updated) {
                for (int j = 0; j < size; j++) {
                    for (Edge e : edges) {
                        if (dist[e.from] == Long.MIN_VALUE || dist[e.to] > dist[e.from] + e.cost) {
                            dist[e.to] = Long.MIN_VALUE;
                        }
                    }
                }
            }
        }
    }
}


class Edge {
    public final int from;
    public final int to;
    public final int cost;

    public Edge(int from, int to, int cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Edge edge = (Edge) o;
        return from == edge.from &&
                to == edge.to &&
                cost == edge.cost;
    }

    @Override
    public int hashCode() {
        return Objects.hash(from, to, cost);
    }
}



Measured memory_bytes: 40560
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;

void solve(int test)
{
  cin >> n >> m;
  for (int i = max(-1'000'000, m - n + 1); i < min(1'000'000, m + n); ++i) {
    cout << i << ' ';
  }
  cout << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
ru(i,j) = \sum^i x^j
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

ll n,c,a[100010],b[100010];
mint ru[410][410],dp[410][410];

void init(){
	cin>>n>>c;
	reg(i,1,n)cin>>a[i];
	reg(i,1,n)cin>>b[i];
	dp[0][0]=1;
	reg(i,1,400){
		mint i_pow_j=1;
		reg(j,0,400){
			ru[i][j]=ru[i-1][j]+i_pow_j;
			i_pow_j*=i;
		}
	}
	// reg(i,1,10){
	// 	reg(j,1,10)cerr<<ru[i][j].get()<<" ";
	// 	cerr<<endl;
	// }
}

int main(void){
	init();
	reg(i,1,n){
		reg(j,0,c){
			reg(k,0,j)dp[i][j]+=dp[i-1][j-k]*(ru[b[i]][k]-ru[a[i]-1][k]);
		}
	}
	// reg(i,1,n){
	// 	cerr<<i<<": ";
	// 	reg(j,1,c)cerr<<dp[i][j].get()<<"\t";
	// 	cerr<<endl;
	// }
	cout<<dp[n][c].get()<<endl;
	return 0;
}

Measured memory_bytes: 1664
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,k,cnt=0; cin>>n>>k;
    vector<pair<ll,ll>> ar(n);
    rep(i,n){
        ll a,b; cin>>a>>b;
        ar[i]=mk(a,b);
    }
    sort(al(ar));
    rep(i,n){
        cnt+=ar[i].second;
        if(k<=cnt){
            cout<<ar[i].first<<endl;
            break;
        }
    }
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;

#define MAX 1000000000000



int main(void) {
	ll n, k; cin >> n >> k;
	ll ans = 0;
	for (ll i = k; i <= n;i++) {
		ll min, max;
		min = ((i - 1)*i) / 2;
		max = (i*(2 * n - i + 1)) / 2;
		ans = (ans+ max - min + 1)%MOD;
	}
	cout << (ans+1) % MOD << endl;
	return 0;
}


Measured memory_bytes: 3628
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;


int main() {
	string s, t;
	cin >> s >> t;
	vector<string> ans;

	int l = s.size() - t.size() + 1;

	for (int i = 0; i < max(0, l); ++i) {
		string tmp = s;
		for (int j = 0; j < t.length(); ++j) {
			if (i + j > s.size() - 1) break;
			if (tmp[i + j] == '?' || tmp[i + j] == t[j]) tmp[i + j] = t[j];
			else break;
			if (j == t.length() - 1) {
				for (int k = 0; k < tmp.length(); ++k) {
					if (tmp[k] == '?')tmp[k] = 'a';
				}
				ans.push_back(tmp);
			}
		}
	}
	
	sort(ans.begin(), ans.end());
	if (ans.size() > 0) cout << ans[0] << endl;
	else cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> t(n);
    for(int i=0;i<n;i++)cin>>t[i];
    int m;
    cin>>m;
    vector<int> p(m),x(m);
    for(int i=0;i<m;i++)cin>>p[i]>>x[i];
    for(int i=0;i<m;i++){
        int ans=0;
        for(int j=0;j<n;j++){
            if(j==p[i]-1)ans+=x[i];
            else ans+=t[j];
        }
        cout<<ans<<endl;
    }
}

   


Measured memory_bytes: 256
use std::cmp;

const INF: u64 = 1e9 as u64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let h: usize = sc.read();
    let w: usize = sc.read();
    let c: Vec<Vec<char>> = (0..h).map(|_| sc.chars()).collect();
    let mut d = vec![vec![' '; h]; w];
    for i in 0..h {
        for j in 0..w {
            d[j][i] = c[i][j];
        }
    }

    let mut ans = 0;
    for i in 1..w {
        ans += solve(&d[i - 1], &d[i]);
    }
    println!("{}", ans);
}

fn solve(a: &[char], b: &[char]) -> u64 {
    let h = a.len();
    let mut cost = vec![vec![0; h + 1]; h + 1];
    for i in 0..(h + 1) {
        cost[0][i] = 0;
        for j in 0..h {
            if i + j < h && a[i + j] == b[j] {
                cost[0][i] += 1;
            }
        }

        cost[i][0] = 0;
        for j in 0..h {
            if i + j < h && a[j] == b[i + j] {
                cost[i][0] += 1;
            }
        }
    }

    for i in 0..h {
        for j in 0..h {
            if i + j < h {
                cost[j + 1][i + j + 1] = cost[j][i + j]
                    - if a[h - 1 - j] == b[h - 1 - (i + j)] {
                        1
                    } else {
                        0
                    };
                cost[i + j + 1][j + 1] = cost[i + j][j]
                    - if a[h - 1 - (i + j)] == b[h - 1 - j] {
                        1
                    } else {
                        0
                    };
            }
        }
    }

    let mut dp = vec![vec![INF; h + 1]; h + 1];
    dp[0][0] = 0;
    for i in 0..(h + 1) {
        for j in 0..(h + 1) {
            if i + 1 <= h {
                dp[i + 1][j] = cmp::min(dp[i + 1][j], dp[i][j] + cost[i][j]);
            }
            if j + 1 <= h {
                dp[i][j + 1] = cmp::min(dp[i][j + 1], dp[i][j] + cost[i][j]);
            }
        }
    }
    dp[h][h]
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;

  cin >> a >> b;
 
  if (0 == a * b % 2) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import collections

MOD = (10 ** 9 + 7)

n = int(input())
p = [True for i in range(n+1)]
p[0] = False
p[1] = False
pf = collections.defaultdict(int)
for i in range(2, n+1):
    if not p[i]:
        continue
    j = i * i
    while j <= n:
        p[j] = False
        j += i
    cnt = 1
    v = i
    while v <= n:
        cnt += n//v
        v *= i
    pf[i] = cnt
total = 1
for v in pf.values():
    total = (total * v) % MOD

print(total)

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

void allpat(long long *max, int k, int N, int M, int Q, vector<int> &A, vector<long long> a, vector<long long> b, vector<long long> c, vector<long long> d){
    
    if(k==N){
        //if(A[] > M) return;
        
        // check
        long long sum = 0;
       
        for(int i=0; i<Q; i++){

           if((A[b[i]-1] - A[a[i]-1]) == c[i]){
               sum += d[i];
               //j ++;
           }
        }
        //std::cout << *max << " j:" << j << " sum:" << sum << std::endl;
        if(*max < sum){
            *max = sum;   
        }
       
    }else{
        int start = 1;
        if(k>0){
            start = A[k-1];
        }
        // true
        for(int i=start; i<=M; i++){
            A[k] = i;
            allpat(max, k+1, N,  M, Q, A, a, b, c, d);
        }
    }
    
}
    
    
int main()
{   
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<long long> a(Q, 0), b(Q, 0), c(Q, 0), d(Q, 0);
    for(int i=0; i<Q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    
    vector<int> A(N, 0);
    long long max;
    max = 0;
    bool flg[M];
    
    allpat(&max, 0, N, M, Q, A, a, b, c, d);
   
    std::cout << max << std::endl;
  
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll A;
	float B;
	cin >> A >> B;
	ll B_ = (B + 0.000001) * 100;
	ll ans = (A * B_) / 100;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 998244353;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}


int main()
{
    int r;
    cin >> r;
    cout << r * r << endl;
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >>n, n)
	{
		int index = 999999999;
		double bmi = 999999999;
		while(n--)
		{
			int i, h, w;
			cin >> i >> h >> w;
			double data = (double)w * 100 * 100 / h / h;
			if(fabs(22 - data) == bmi && index > i)
			{
				index = i;
			}
			else if(fabs(22 - data) < bmi)
			{
				bmi = fabs(22 - data);
				index = i;
			}
		}
		cout << index << endl;
	}
}

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

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

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

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

    // 累積 GCD (左と右両方)
    vector<int> left(N+1, 0), right(N+1, 0);
    for (int i = 0; i < N; ++i) left[i+1] = GCD(left[i], a[i]);
    for (int i = N-1; i >= 0; --i) right[i] = GCD(right[i+1], a[i]);
    
    // 集計
    int res = 0;
    for (int i = 0; i < N; ++i) {
        // 左側
        int l = left[i];

        // 右側
        int r = right[i+1];

        // 更新
        chmax(res, GCD(l, r));
    }
    cout << res << endl;
}

Measured memory_bytes: 1408
// 2015/06/02 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

class Stack{
private:
	int sp;			// スタックポインタ
	int S[100];		// スタックの配列
public:
	Stack()			{  sp = 0;  }
	bool isFull() const	{  return (sp==100);  }
	bool isEmpty() const	{  return (sp==0);  }
	void push(int d);
	int top();
	void pop();
};

void Stack::push(int d)
{
	if(isFull())
		return;		// 満杯

	S[sp++] = d;		// スタックにデータを追加する
}

int Stack::top()
{
	if(isEmpty())
		return -1;	// 異常終了（空）

	return S[sp-1];		// 頂上のデータ
}

void Stack::pop()
{
	if(isEmpty())
		return;		// 空

	sp--;			// スタックからデータを取り出す
}


int main()
{
	Stack s;

	string ex;
	getline(cin, ex);	// 1行読み込み

	istringstream is(ex);	// 入力ストリーム

	while(!is.eof()){
		string op;
		is >> op;

		int tmp1, tmp2;

		switch(op[0]){
		case '+':
			tmp1 = s.top();  s.pop();
			tmp2 = s.top();  s.pop();
			s.push(tmp2+tmp1);
			break;
		case '-':
			tmp1 = s.top();  s.pop();
			tmp2 = s.top();  s.pop();
			s.push(tmp2-tmp1);
			break;
		case '*':
			tmp1 = s.top();  s.pop();
			tmp2 = s.top();  s.pop();
			s.push(tmp2*tmp1);
			break;
		default:
			istringstream is2(op);
			is2 >> tmp1;
			s.push(tmp1);
			break;
		}
	}

	cout << s.top() << endl;

	return 0;
}

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

long long a, b, c, x, y, tmp, res;
int main() {
    cin >> a >> b >> c >> x >> y;
    if (a + b < c + c) res = (a + b) * min(x, y);
    else res = 2 * c * min(x, y);
    tmp = min(x, y);
    x -= tmp; y -= tmp;
    if (x > 0) {
        if (a < 2*c) res += x * a;
        else res += x * 2 * c;
    } else if (y > 0) {
        if (b < 2*c) res += y * b;
        else res += y * 2 * c;
    }
    cout << res;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()

ans_str = ''
for i in range(n):
    if t[i] == 'r':
        ans_str += 'p'
    elif t[i] == 's':
        ans_str += 'r'
    else:
        ans_str += 's'

ans_str = list(ans_str)
for i in range(k, n):
    if ans_str[i] == ans_str[i-k]:
        ans_str[i] = 'z'

pnt = 0
for i in range(n):
    if ans_str[i] == 'r':
        pnt += R
    elif ans_str[i] == 's':
        pnt += S
    elif ans_str[i] == 'p':
        pnt += P

print(pnt)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    for (int i=0;i<n;i++){
        int input;
        cin >> input;
        mp[input] = i+1;
    }
    for (auto i:mp){
        cout << i.second << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5888
#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;
    string s,d,f;
cin>>s>>d>>f;
if(s[s.size()-1]==d[0]&&d[d.size()-1]==f[0])cout << "YES";
    else cout<< "NO";
}



Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

point = 0
for i in range(n):
    if k > i:
        point += a[i]
        continue
    now = point
    now -= a[i - k]
    now += a[i]
    if now > point:
        print('Yes')
    else:
        print('No')
    point = now


Measured memory_bytes: 31500
#include <stdio.h>

int main(void) {
  int x1, x2, x3, x4, x5;
  scanf("%d", &x1);
  scanf("%d", &x2);
  scanf("%d", &x3);
  scanf("%d", &x4);
  scanf("%d", &x5);

  if(x1 == 0)
  puts("1");
  else if(x2 == 0)
  puts("2");
  else if(x3 == 0)
  puts("3");
  else if(x4 == 0)
  puts("4");
  else if(x5 == 0)
  puts("5");


}


Measured memory_bytes: 1660
n=int(input())
a=list(map(int,input().split()))

d=dict()

for i in range(n):
    if a[i] in d:
        d[a[i]]=d[a[i]]+1
    else:
        d[a[i]]=1
        
xsum=0
for x in d.keys():
    if d[x]<x:
        xsum=xsum+d[x]
    elif d[x]>x:
        xsum=xsum+d[x]-x
        
print(xsum)

Measured memory_bytes: 18164
#import<iostream>
#import<atcoder/all>
int N,Q,i,a;main(){std::cin>>N>>Q;atcoder::fenwick_tree<long>b(N);for(;i++<N;b.add(i-1,a))std::cin>>a;for(;std::cin>>i>>a>>N;Q--){if(i)std::cout<<b.sum(a,N)<<'\n';else b.add(a,N);}}

Measured memory_bytes: 8220