akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;
const int INFi = 2e9 + 1;
const lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto &(i) : (vec))


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(void){
  lli n, m; cin >> n >> m;
  vector<pll> data(n);
  REP(i, n){
    lli a, b; cin >> a >> b;
    data.at(i) = make_pair(a, b);
  }
  sort(data.begin(), data.end());
  lli res = 0, number = 0;
  REP(i, n){
    if(number + data[i].second < m){
      res += data[i].second * data[i].first;
      number += data[i].second;
    }
    else{
      res += data[i].first * (m - number);
      break;
    }
  }
  cout << res << '\n';
  return 0;
}

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

int main(){
  int64_t N,M;
  cin>>N>>M;
  int64_t sum=0;
  map<int64_t,int64_t> m;
  for(int i=0;i<N;++i){
    int64_t A;
    cin>>A;
    sum += A;
    sum %= M;
    ++m[sum];
  }
  ++m[0];
  
  sum=0;
  for(auto p:m) sum += ((p.second-1)*p.second)/2;
  cout<<sum<<endl;
}


Measured memory_bytes: 4224
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if ((a * b) % 2 == 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import queue


class Process:
    def __init__(self, name, value):
        super().__init__()
        self.name = name
        self.value = value

    def __repr__(self):
        return '{} {}'.format(self.name, self.value)


Q = queue.Queue()

n, q = map(int, input().split())
for _ in range(n):
    name, value = input().split()
    Q.put(Process(name, int(value)))

t = 0
while not Q.empty():
    process = Q.get()
    if process.value > q:
        process.value -= q
        Q.put(process)
        t += q
    else:
        t += process.value
        print('{} {}'.format(process.name, t))



Measured memory_bytes: 18628
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int func(ll n, int a) {
    int res = 0;
    while (n > 0) {
        res += n%a;
        n /= a;
    }
    return res;
}
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll n;cin>>n;
  if(n%func(n,10)==0){
    P("Yes");
  }else{
    P("No");
  }
  return 0;
}


Measured memory_bytes: 256
import itertools
from collections import Counter

N = int(input())
point = [tuple(map(int, input().split())) for _ in range(N)]

ans = Counter()
if N == 1:
    print(1)
    exit()

for first, second in list(itertools.permutations(point, 2)):
    fx, fy = first
    sx, sy = second
    ans[(sx-fx, sy-fy)] += 1

print(max(1, N - ans.most_common()[0][1]))


Measured memory_bytes: 40560
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

bool f[256];

int main(){
	string s;
	cin>>s;
	rep(i, s.size()){
		f[s[i]] = true;
	}
	bool ans = true;
	if(f['S'] || f['N']){
		if(f['S'] && f['N']);
		else ans = false;
	}
	if(f['W'] || f['E']){
		if(f['E'] && f['W']);
		else ans = false;
	}
	cout<<(ans?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 
end

N = gets.to_i
A = $<.read.split($/).map(&:to_i)

include Memoizable

def f(turn, i, j)
	if turn
		if i == j
			0
		elsif A[i] > A[j]
			f(false, (i - 1) % N, j)
		else
			f(false, i, (j + 1) % N)
		end
	else
		if i == j
			A[i]
		else
			[
			A[i] + f(true, (i - 1) % N, j),
			A[j] + f(true, i, (j + 1) % N)
			].max
		end
	end
end

memoize(:f)

p (0..N-1).map{|i|
	A[i] + f(true, (i - 1) % N, (i + 1) % N)
}.max

Measured memory_bytes: 423324
#include <iostream>
#include <string>
#include <map>
int main(int argc, char const *argv[]) {
    int n;std::cin >> n;
    std::string S;
    std::map<char, int> outer_counter,inner_counter;

    std::string alphabet="abcdefghijklmnopqrstuvwxyz";

    for (size_t i = 0; i < alphabet.size(); i++) {
        inner_counter[alphabet[i]]=0;
        outer_counter[alphabet[i]]=10000;
    }
    for (size_t i = 0; i < n; i++) {
        std::cin >> S;
        for (size_t i = 0; i < S.size(); i++) {
            inner_counter[S[i]]+=1;
        }
        for (size_t i = 0; i < alphabet.size(); i++) {
            outer_counter[alphabet[i]]=std::min(outer_counter[alphabet[i]],inner_counter[alphabet[i]]);
            inner_counter[alphabet[i]]=0;
        }
    }

    for (size_t i = 0; i < alphabet.size(); i++) {
        if (outer_counter[alphabet[i]]!=0) {
            for (size_t j = 0; j < outer_counter[alphabet[i]]; j++) {
                std::cout << alphabet[i];
            }
        }
    }
    std::cout << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int partition(int *, int, int);

int A[100000];

int main(){
  
  int i,a,n;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  a=partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i==a) printf("[");
    printf("%d",A[i]);
    if(i==a) printf("]");
    if(i<n-1) printf(" ");
  }
  printf("\n");
  
  return 0;
  
}

int partition(int A[], int p, int r){

  int tmp,x,j,i;
  
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
  return i+1;

}

Measured memory_bytes: 992
#include <stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
int A[100][100];

void dijkstra(){
  int i;
  int minv;
  int d[100],color[100];
  int u,v;
  int count;

  for( i = 0; i < n; i++){
    d[i] = 1000000;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = 1000000;
    u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if( u == -1) break;
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if( color[v] != BLACK && A[u][v] != 1000000){
	if( d[v] > d[u] + A[u][v]){
	  d[v] = d[u] + A[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%d %d\n",i,(d[i] == 100000 ? -1 : d[i]));
  }
}

int main(){
  int i,j;
  int u,k,v,c;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      A[i][j] = 1000000;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d%d",&v,&c);
      A[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <array>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
#define out(s) cout << (s) << endl;

int main()
{
	string S;
	cin >> S;
	int cnt = 0;
	char item = S[0];
	for (auto c : S) {
		if (item != c) cnt++; item = c;
	}
	out(cnt);
	return 0;
}

Measured memory_bytes: 512
import sys

def solve():
    input = sys.stdin.readline
    H, W, M = map(int, input().split())
    Bomb = dict()
    Hc = [0] * H
    Wc = [0] * W
    for _ in range(M):
        h, w = map(int, input().split())
        Bomb[(h-1, w-1)] = 0
        Hc[h-1] += 1
        Wc[w-1] += 1
    maxH, maxW = max(Hc), max(Wc)
    maxHs = []
    for i, h in enumerate(Hc):
        if h == maxH: maxHs.append(i)
    maxWs = []
    for i, w in enumerate(Wc):
        if w == maxW: maxWs.append(i)
    
    ans = maxH + maxW - 1
    for h in maxHs:
        for w in maxWs:
            if (h, w) not in Bomb:
                ans += 1
                break
        if ans == maxH + maxW:
            break
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 182964
#include<iostream>
#include<algorithm>

using namespace std;

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

struct S{
	string name;
	double ratio;
	bool operator<(const S &r)const{
		if(ratio==r.ratio)return name<r.name;
		return ratio>r.ratio;
	}
};

int main(){
	int n;
	while(cin>>n,n)
	{
		S corp[50];
		rep(i,n)
		{
			int p,a,b,c,d,e,f,s,m,gain=0,time=0;
			cin>>corp[i].name>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			gain=s*m*f-p;
			time=(a+b+c)+(d+e)*m;
			corp[i].ratio=double(gain)/time;
		}
		sort(corp,corp+n);
		rep(i,n)cout<<corp[i].name<<endl;
		cout<<"#"<<endl;
	}
	return 0;
}

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

vector<vector<int>> e[53];
int c[53], d[53];
LL ans[53]{0, 1};

int main()
{
	int n, m;
	cin >> n >> m;
	if(n & 1) {
		for(int i = 1; i <= m; ++i) cout << i << ' ' << n-i << endl;
	}
	else {
		for(int i = 1; i <= (m+1)/2; ++i) cout << i << ' ' << n+1-i << endl;
		for(int i = (m+3)/2; i <= m; ++i) cout << i << ' ' << n-i << endl;
	}
	return 0;
}


Measured memory_bytes: 3648
/*
    http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B
    ????§£???????????????
*/

#include <iostream>
using namespace std;
int main() {
    int n,x;
    int ans;
    while(cin >> n >> x,(n!=0)||(x!=0)){
        ans = 0;
        for(int a = 1;a <= n;a++){ //a = a+1
            for(int b = a+1;b <= n;b++){
                for(int c = b+1; c <= n;c++){
                    if(a+b+c==x)ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
/*
for(???????????????;?¶????????????¶;????????????????????£???????????????)
 */

Measured memory_bytes: 1160
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{

    std::string s;
    std::cin >> s;

    lint bc_count = 0;
    lint a_count = 0;

    lint ans = 0;

    for (lint i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A' && bc_count == 0)
        {
            a_count++;
        }
        else if (s[i] == 'A' && bc_count == 1)
        {
            a_count = 1;
            bc_count = 0;
        }
        else if (s[i] == 'B' && bc_count == 0)
        {
            bc_count = 1;
        }
        else if (s[i] == 'B' && bc_count == 1)
        {
            a_count = 0;
        }
        else if (s[i] == 'C' && bc_count == 1)
        {
            ans += a_count;
            bc_count = 0;
        }
        else
        {
            bc_count = 0;
            a_count = 0;
        }
    }

    printf("%lld", ans);

    return 0;
}


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

using namespace std;

#define mod 1000000007LL


template<typename T>
class UF {
public:
	UF() {
		size = 0;
	}

	//???????????\??????
	void push( T a ) {
		M[a] = size;
		V.push_back( size );
		rank.push_back( 0 );
		C.push_back( 1 );
		size++;
	}

	//????????°??????????????????
	void unite( T a, T b ) {
		long long int x = find( M[a] );
		long long int y = find( M[b] );
		if( x == y )return;
		if( rank[x] < rank[y] ) {
			V[x] = y;
			C[y] += C[x];
		} else {
			V[y] = x;
			C[x] += C[y];
			if( rank[x] == rank[y] )rank[x]++;
		}
	}

	void merge( T a, T b ) {
		unite( a, b );
	}

	//????????°??????????????????????????????????????????
	bool same( T a, T b ) {
		return find( M[a] ) == find( M[b] );
	}

	//????????°????????????????????°?????????
	long long int group() {
		set<long long int>S;
		for( long long int i = 0; i < V.size(); i++ ) {
			S.insert( find( V[i] ) );
		}
		return S.size();
	}

	//??°?????????????±???????????????°?????????
	long long int count( T a ) {
		return C[find( M[a] )];
	}

	//????±???????????????°????????????ID?????????
	long long int groupID( T a ) {
		return find( M[a] );
	}

	//????????°?????????????????????????????????
	vector<T>friendList( T a ) {
		long long int inputID = find( M[a] );
		vector<T>ret;
		for( auto now : M ) {
			if( find( now.second ) == inputID ) {
				ret.emplace_back( now.first );
			}
		}
		return ret;
	}

private:
	vector<long long int>C, V, rank;
	map < T, long long int>M;
	long long int size;

	//?\?????????§?????????
	long long int find( long long int x ) {
		if( V[x] == x )return x;
		else return V[x] = find( V[x] );
	}
};



int main() {
	long long int N, M;
	cin >> N >> M;
	UF<long long int>uf;
	for( size_t i = 0; i < N; i++ ) {
		uf.push( i );
	}
	vector<vector<long long int>>D( N );
	vector<vector<long long int>>F( N );
	for( size_t i = 0; i < M; i++ ) {
		long long int x, y;
		cin >> x >> y;
		x--; y--;
		D[x].push_back( y );
		F[y].push_back( x );
		uf.merge( x, y );
	}

	function<long long int( long long int )> f = [&]( long long int idx )->long long int {
		long long int ret = 1;
		for( auto x : F[idx] ) {
			ret *= f( x );
			ret %= mod;
		}
		return ret + 1;
	};
	long long int ans = 1;
	set<long long int>checked;
	vector<bool>checkbool( N );
	for( size_t i = 0; i < N; i++ ) {
		if( !checked.count( uf.groupID( i ) ) ) {
			checked.insert( uf.groupID( i ) );
			auto group = uf.friendList( i );

			long long int now = i;
			while( !checkbool[now] && D[now].size() ) {
				checkbool[now] = true;
				now = D[now][0];
			}

			if( D[now].size() ) {
				auto now_ = D[now][0];
				set<long long int>SLL;
				SLL.insert( now );
				long long int prev;
				while( now_ != now ) {
					SLL.insert( now_ );
					prev = now_;
					for( auto x : F[now_] ) {
						if( x != prev ) {
							F[now].push_back( x );
						}
					}
					now_ = D[now_][0];
				}
				F[now].erase( remove_if( F[now].begin(), F[now].end(), [&]( auto i ) { return SLL.count( i ); } ), F[now].end() );
				now_ = D[now][0];

			}
			ans *= f( now );
			ans %= mod;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3352
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()

    m = {}
    def f(i,t):
        k = (i,t)
        if k in m:
            return m[k]

        r = 0
        if i == 1:
            if t == -1:
                r = 9
            elif t == 0 or t == 9:
                r = 2
            else:
                r = 3
        else:
            if t == -1:
                r += f(i-1, -1)
                for nt in range(1, 10):
                    r += f(i-1, nt)
            else:
                for nt in range(max(0,t-1), min(10, t+2)):
                    r += f(i-1, nt)
        m[k] = r
        return r

    def g(i, t, k):
        if i == 1:
            if t == -1:
                return k
            if t == 0:
                return k - 1
            return t + k - 2

        if t == -1:
            f1 = f(i-1, -1)
            if f1 >= k:
                return g(i-1, -1, k)
            k -= f1
            for j in range(1, 10):
                fj = f(i-1, j)
                if fj >= k:
                    r = g(i-1, j, k)
                    return r + j * 10**(i-1)
                k -= fj
        else:
            for j in range(max(0, t-1), min(10, t+2)):
                fj = f(i-1, j)
                if fj >= k:
                    r = g(i-1, j, k)
                    return r + j * 10**(i-1)
                k -= fj

    r = g(11, -1, k)
    return r

print(main())





Measured memory_bytes: 6352
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        mut n: i64
    }
    let mut ans = Vec::new();
    while n > 0 {
        n -= 1;
        ans.push((n % 26) as u8 + b'a');
        n /= 26;
    }
    ans.reverse();
    for b in ans {
        print!("{}", b as char);
    }
}


Measured memory_bytes: 2136
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int A;
    string S;
    
    bool operator<( const Data& right ) const {
        return A == right.A ? S < right.S : A < right.A;
        //return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    bool A[1000001] = {};
    int s;
    
    cin >> s;
    
    A[s] = 1;
    int now = s;
    int i = 2;
    while (true) {
        if(now%2==0) now = now/2;
        else now = 3*now+1;
        
        if(A[now]==1) {
            cout << i << endl;
            break;
        }
        A[now] = 1;
        i++;
    }
    
    
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------


//--MAIN-----------------------------------
void Main() {
    ll L; cin>>L;
    ll nokori=L;
    ll N=1;
    while(pow(2,N)<=L) ++N;
    vector<ll> s,t,cost;
    rep(i,N-1){
        s.emplace_back(1+i);
        t.emplace_back(2+i);
        cost.emplace_back(0);

        s.emplace_back(1+i);
        t.emplace_back(2+i);
        cost.emplace_back(pow(2,(N-2-i)));
    }
    ll saisyo=pow(2,N-1);
    nokori-=pow(2,N-1);
    rep(i,N-1){
        if(nokori>>i&1){
            s.emplace_back(1);
            t.emplace_back(N-i);
            cost.emplace_back(saisyo);
            saisyo+=1<<i;
        }
    }
    cout<< N<<" "<<s.size()<<"\n";
    rep(i,s.size()){
        cout<< s[i]<<" "<< t[i] <<" "<< cost[i] <<"\n";
    }
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

	int i, n, max,min;

	cin >> n;

	int a[n];

	cin >> a[0];
	min = a[0];

	cin >> a[1];

	max = a[1] - min;

	if (min > a[1])
		min = a[1];

	for (i =2; i < n; i++) {
		cin >> a[i];


		if (max < a[i] - min)
			max = a[i] - min;
		
		if (min > a[i])
			min = a[i];

	}

	cout << max << endl;


	return 0;
}


Measured memory_bytes: 3864
import sys
input = sys.stdin.readline

import numpy as np

N = int(input())
V = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

benefit = V - C
sum_b = 0
for item in benefit:
    if item > 0:
        sum_b += item

print(sum_b)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> A(n), B(n);
    rep(i, n) cin >> A[i] >> B[i];
    ll ans = 0;
    rrep(i, n) {
        ll a = (A[i]+ans) % B[i];
        if (a == 0) continue;
        ans += B[i] - a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
<?php
// Here your code !
$x = trim(fgets(STDIN));
//echo $x."\n";
$y = trim(fgets(STDIN));
// echo $y;
$ret = explode(" ",$y);
echo $ret[$x - 1];
$i = 2;
while($x>1){
    echo " ";
    echo $ret[$x - $i];
    $x--;
}
?>

Measured memory_bytes: 15324
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, k, num = 111, cnt = 0, ind = 0;
bool ch = 1;
vector<pair<int, int>> v;

void solve();

int main() {
  cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v.push_back(make_pair(a, i));
  }

  solve();
  return 0;
}

void solve() {
  int now = 0, bf = -1;
  vector<int> ans;
  for(int i = 0; i <= k; ++i) {
    sort(v.begin(), v.end());
    if(bf == v[0].se)
      now = 1;
    else
      now = 0;
    for(int j = 0; j < n; ++j)
      if(j != bf && j != v[now].se) ans.push_back(j);
    ans.push_back(v[now].se);
    bf = v[now].se;
    if(i != k) ++v[now].fi;
  }
  sort(v.begin(), v.end());
  if(v[0].fi <= k) {
    cout << -1 << endl;
    return;
  }
  else {
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); ++i) {
      if(i != 0) cout << " ";
      cout << ans[i] + 1;
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
 
l = [0] * N
r = [0] * N
 
for i in range(N):
  if i == 0:
    r[i] = W[0]
    l[i] = W[N-1]
  else:
    r[i] = r[i-1] + W[i]
    l[i] = l[i-1] + W[N-i-1]
 
ans = 100000
for i in range(N-1):
  ans = min([abs(r[i] - l[N-i-2]), ans])
print(ans)

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

int a, b, c, d, e, k;
int main(){
    cin >> a >> b >> c >> d >> e >> k;
    if (e- a > k){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
    return 0;
}

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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

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

    cout << max(sum(next<vector<int>>(4)), sum(next<vector<int>>(4))) ln;

    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#define MAX 100001
using namespace std;

void Partition(int A[], int n, int& l) // l is the last index of smaller part
{
    int x = A[n-1];
    for (int i = 0; i < n-1; ++i) 
    {
        if (A[i] <= x) 
        {
            swap(A[i], A[l+1]);
            l++;
        }
    }
    l++;
    swap(A[l], A[n-1]);
}

int main() 
{
    int n, A[MAX];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
    int l = -1;
    Partition(A, n, l);

    for (int i = 0; i < n; ++i) 
    {
        if (i == l) printf("[%d]", A[i]);
        else printf("%d", A[i]);
        if (i != n-1) printf(" ");
        else printf("\n");
    }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    int a[n];
    forn(i, n) {
        cin >> a[i];
    }
    sort(a, a + n);
    cout << a[n - 1] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define il inline
#define ri register
#define ll long long
#define Size 300050
using namespace std;
int p[Size],p1[Size],p2[Size];
il void read(int&);
il ll mergesort(int,int,int*);
int main(){
	//freopen("in","r",stdin);
	int n;read(n);
	for(int i(1);i<=n;++i)read(p[i]);
	for(int i(1);i<=n;++i)
		if(i&1){p1[i+1>>1]=p[i];
			if(~p[i]&1)return puts("No"),0;
		}else{p2[i>>1]=p[i];
			if(p[i]&1)return puts("No"),0;
		}puts((mergesort(1,n+1>>1,p1)+
			   mergesort(1,n>>1,p2))*3^mergesort(1,n,p)
			  ?"No":"Yes");
	return 0;
}
il ll mergesort(int l,int r,int*a){
	if(l==r)return 0;static int a1[Size];
	int mid(l+r>>1),i(l),j(mid+1),k(l);
	ll ans(mergesort(l,mid,a)+mergesort(mid+1,r,a));
	while(i<=mid&&j<=r)
		a1[k++]=a[i]<a[j]?a[i++]:(ans+=mid-i+1,a[j++]);
	while(i<=mid)a1[k++]=a[i++];while(j<=r)a1[k++]=a[j++];
	for(i=l;i<=r;++i)a[i]=a1[i];return ans;
}
il void read(int&x){
	x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> Point;
typedef pair<int,Point> Edge;
#define x first
#define y second

const int N = 100010;
int n;
Point a[N];

int dist(Point a, Point b) {
	return min(abs(a.x - b.x), abs(a.y - b.y));
}

bool cmp_x(Point a, Point b) {
	return a.x < b.x || (a.x == b.x && a.y < b.y);
}
bool cmpx(Edge a, Edge b) {
	bool ok = cmp_x(a.second, b.second);
	if (ok) return true;
	else if (a.second == b.second && a.first < b.first);
	return false;
}

bool cmp_y(Point a, Point b) {
	return a.y < b.y || (a.y == b.y && a.x < b.x);
}
bool cmpy(Edge a, Edge b) {
	bool ok = cmp_y(a.second, b.second);
	if (ok) return true;
	else if (a.second == b.second && a.first < b.first);
	return false;
}

int par[N];
int anc(int p) { return p == par[p] ? p : par[p] = anc(par[p]); }
void join(int p, int q) { par[anc(p)] = anc(q); }

vector <Edge> e, A;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i].x >> a[i].y;
	for (int i = 1; i <= n; ++i) A.push_back(make_pair(i, a[i]));
	sort(A.begin(), A.end(), cmpx);
	for (int i = 0; i < n - 1; ++i) {
		int d = dist(A[i].second, A[i + 1].second);
		e.push_back(Edge(d, make_pair(A[i].first, A[i + 1].first)));
	}
	sort(A.begin(), A.end(), cmpy);
	for (int i = 0; i < n - 1; ++i) {
		int d = dist(A[i].second, A[i + 1].second);
		e.push_back(Edge(d, make_pair(A[i].first, A[i + 1].first)));
	}

	for (int i = 1; i <= n; ++i) par[i] = i;
	sort(e.begin(), e.end());
	long long ans = 0;
	for (auto edge: e) {
		int u = edge.second.first, v = edge.second.second;
		u = anc(u), v = anc(v);
		if (u != v) {
			join(u,v);
			ans += edge.first;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6900
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] nums = s.nextLine().split(" ");
        int n=Integer.parseInt(nums[0]);
        int a=Integer.parseInt(nums[1]);
        int b=Integer.parseInt(nums[2]);
        if(n*a > b){
            System.out.println(b);
        }else{
            System.out.println(n*a);
        }
    }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	long double l;
	cin>>l;
	l/=3;
	l*=l*l;
	printf("%.9Lf",l);
	// your code goes here
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> dp(n, 0);
    vector<int> h(n);
    for (int i=0; i<n; i++) cin >> h[i];

    dp[1] = abs(h[1]-h[0]);
    for (int i=2; i<n; i++)
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));

    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int N, K;

  cin >> N >> K;

  vector<int> a(N);
  rep(i, N) cin >> a[i];
  int ans = 1;
  N = N - K;
  ans += (N + K - 2) / (K - 1);

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

Measured memory_bytes: 640
#include <string>
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm> 
#include <bits/stdc++.h>

#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
using namespace std;
typedef unsigned long long int ull;



int main() {
	int n;
	cin>>n;
	int* a = new int[n];
	REP(i,0,n-1)
		cin>>*(a+i);
	std::sort(a,a+n);
	cout<<a[n/2]-a[(n/2)-1];
	
	
	return 0;
}

Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d %d", $n, $x);
$ans = $n;
$y = 0;
$z = 0;
$y = $n - $x;
if ($x == $y) {
  $ans += $y;
} else {
  if (($n - $y) / $n >= 1) {
    if (($n - $y) % $n == 0) {
      $ans += (($n - $y) / $y) * $y * 2 - $y;
      echo $ans."\n";
      exit;
    }
    $ans += (floor($n / $y)- 1 ) * $y * 2;
    $z = $n - (floor($n / $y) * $y);
  } else {
    $z = $n - $y;
  }
  while ($y % $z != 0) {
    $ans += floor($y / $z)  * $z * 2;
    $a = $z;
    $z = $y % $z;
    $y = $a;
  }
    $ans += ($y / $z - 1) * $z * 2 + $z;
}
echo $ans."\n";


Measured memory_bytes: 3704
#include <iostream>
#include <algorithm>
#include <vector>

#include <stack>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
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; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif


int main() {
  string s, t; cin >> s >> t;
  int N = s.size(), M = t.size();

  int dp[N+1][M+1];
  rep(i, N+1) rep(j, M+1) dp[i][j] = 0;

  rep(i, N) rep(j, M) {
    if (s[i] == t[j])
      dp[i+1][j+1] = 1 + dp[i][j];
    else
      dp[i+1][j+1] = max(dp[i][j+1], max(dp[i+1][j], dp[i][j]));
  }

  stack<char> st;
  int lcs = dp[N][M];
  int m = M;
  rrep(i, N) {
    if (dp[i][m] == lcs - 1) {
      st.push(s[i]);
      while (m >= 0 && dp[i][m] == lcs-1) --m;
      ++m;
      --lcs;
    }
  }
  while (!st.empty()) {
    cout << st.top();
    st.pop();
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 35456
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;

#define forsn(i,s,n) for(int i=(s); i<(int)(n); i++)
#define forn(i,n) forsn(i,0,n)

typedef long long int tint;

int a[100000];
int b[100000];
int c[100000];

int main() {
	int n; cin >> n;
	forn(i,n) cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);

	int pos = 0;
	for (int i = 1;i < n;i += 2) b[i] = a[pos++];
	
	b[0] = a[pos++];
	if (n % 2) b[n - 1] = a[pos++];
	
	for (int i = 2;i < n - (n % 2);i += 2) b[i] = a[pos++];
	
	tint res = 0;
	forn(i, n - 1) res += abs(b[i] - b[i + 1]);
	
	pos = 0;
	for (int i = 2;i < n;i += 2) c[i] = a[pos++];
	c[0] = a[pos++];
	for (int i = n - 1 - (n % 2);i >= 0;i -= 2) c[i] = a[pos++];
	
	tint res2 = 0;
	forn(i, n - 1) res2 += abs(c[i] - c[i + 1]);
	
	
	cout << max(res, res2) << endl;
}


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

int main() {
  int N;
  cin >> N;
  int A=0,B=0;
  vector<int> C(N);
  for (int i=0; i<N; i++){
    cin >> C.at(i);
  }
  sort(C.begin(),C.end());
  reverse(C.begin(),C.end());
  
  //cout << C.at(0) << endl;
  int T=0;
  while(1){
    if(T!=N){
      A+=C.at(T);
      T++;
    }else{
      break;
    }
    if(T!=N){
      B+=C.at(T);
      T++;
    }else{
      break;
    }
  }
  int ans = A-B;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

int n, res, f;
string s[55], h;
int t[55];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> s[i] >> t[i];
	cin >> h;

	for (int i = 0; i < n; i++) {
		if (f) res += t[i];
		f |= s[i] == h;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
def f(d,x,y):
    t = x % y
    x = y
    y = t
    if y != 0:
        return f(d+1,x,y)
    else:
        return (x,d+1)

while 1:
    y,x = sorted(list(map(int, input().split())))
    if x == 0: break
    ans = f(0,x,y)
    print(ans[0],ans[1])




Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
bool collected[21][21];
int main(){
  while(true){
    int N;
    cin >> N;
    if(N == 0){
      break;
    }

    for(int i = 0; i <= 20; i++){
      for(int j = 0; j <= 20; j++){
        collected[i][j] = true;
      }
    }

    for(int i = 0; i < N; i++){
      int x;
      int y;
      cin >> x >> y;
      collected[x][y] = false;
    }


    int cur_x = 10;
    int cur_y = 10;
    collected[cur_x][cur_y] = true;

    int M;
    cin >> M;
    for(int i = 0; i < M; i++){
      char dir;
      int dst;
      cin >> dir >> dst;
      if(dir == 'N'){
        for(int j = 0; j < dst; j++){
          cur_y ++;
          collected[cur_x][cur_y] = true;
        }
      } else if(dir == 'E'){
        for(int j = 0; j < dst; j++){
          cur_x ++;
          collected[cur_x][cur_y] = true;
        }
      } else if(dir == 'S'){
        for(int j = 0; j < dst; j++){
          cur_y --;
          collected[cur_x][cur_y] = true;
        }
      } else {
        for(int j = 0; j < dst; j++){
          cur_x --;
          collected[cur_x][cur_y] = true;
        }
      }
    }

    bool all_collected = true;
    for(int i = 0; i <= 20; i++){
      for(int j = 0; j <= 20; j++){
        if(!collected[i][j]){
          all_collected = false;
        }
      }
    }

    if(all_collected){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3100
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline

N, u, v = map(int, input().split())
u -= 1
v -= 1
Tree = [[] for _ in range(N)]

for _ in range(N-1):
  A, B = map(lambda x:int(x)-1, input().split())
  Tree[A].append(B)
  Tree[B].append(A)

#u-v間の単純pathを用意する
path = []
def connected(v, tv, p=-1):
  if v == tv:
    return True
  for w in Tree[v]:
    if w == p:
      continue
    elif connected(w, tv, v):
      path.append(w)
      return True
  return False

connected(v, u)
path.append(v)

#u-v間の点からvとは逆方向にdfs
#u-vの中点から調べれば十分(中点よりvに寄ると、青木君は捕まってしまう)

def dfs(v, p):
  d = -1
  for w in Tree[v]:
    if w == p:
      continue
    else:
      d = max(d, dfs(w, v))
  return d + 1

dist = len(path)
mid = path[dist//2 - 1]
par = path[dist//2]
ans = dfs(mid, par)

print(ans + (dist-1)//2)

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < n; i++)
#define REP(n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using INT64 = long long;
using UINT64 = unsigned long long;

int main(void)
{
    IOS
    int h,w;
    cin >> h >>w;
    vector<string> ss(h);
    REP(h) cin >> ss[i];

    vector<vector<int>> v(h,vector<int>(w,0));
    vector<int> lh(w,0); // ライト縦方向
    int lw; // ライト横方向
    FOR(i, 0 ,h) {
        lw = 0;
        FOR(j,0,w) {
            if (ss[i][j] == '#') {
                int i2 = i-1;
                while(i2 >= 0 && ss[i2][j] == '.'){
                    v[i2][j] += lh[j];
                    i2--;
                }
                int j2 = j-1;
                while(j2 >= 0 && ss[i][j2] == '.'){
                    v[i][j2] += lw;
                    j2--;
                }
                lh[j] = 0;
                lw = 0;
                continue;
            }

            lh[j]++;
            lw++;

            if (j == w-1) {
                int j2 = j;
                while(j2 >= 0 && ss[i][j2] == '.'){
                    v[i][j2] += lw;
                    j2--;
                }

            }
            if (i == h-1) {
                //cerr << lh[j];
                int i2 = i;
                while(i2 >= 0 && ss[i2][j] == '.'){
                    v[i2][j] += lh[j];
                    i2--;
                }
            }
        }
        //REP(h) cerr << lh[i];
        //cerr << endl;
    }

    REP(h) {
        //FOR(j,0,w) cerr << v[i][j] << " ";
        //cerr << endl;
        sort(RALL(v[i]));
    }

    int ans = 0;
    REP(h) {
        //FOR(j,0,w) cerr << v[i][j];
        //cerr << endl;
        if (ans < v[i][0]) ans = v[i][0];
    }

    cout << ans-1 << endl;



    return 0;
}


Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;
int g[100010];
int R[100010],L[100010];
int main(){
    string s;
    cin>>s;
    int cnt_r=0;
    int cnt_l=0;
    for (int i = s.size()-1; i >=0; i--)
    {
        if(s[i]=='R') cnt_r++;
        else cnt_r=0;
        R[i]=cnt_r;
    }
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]=='L') cnt_l++;
        else cnt_l=0;
        L[i]=cnt_l;
    }
    

    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]=='R' && R[i]%2==1)    {
            g[i+R[i]-1]++;
        }

        if(s[i]=='R' && R[i]%2==0)    {
            g[i+R[i]-1+1]++;
        }
        
        if(s[i]=='L' && L[i]%2==1)    {
            g[i-L[i]+1]++;
        }
        if(s[i]=='L' && L[i]%2==0)    {
            g[i-L[i]+1-1]++;
        }
        
        
    }
    for (int i = 0; i < s.size(); i++)
    {
        cout<<g[i]<<" ";
    }
    cout<<endl;
    
    



    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s; cin >> s;
	ll k; cin >> k;
	ll n = sz(s);
	FOR(i,0,n) {
		if (s[i] == 'a') continue;
		ll todo = 26 - (s[i]-'a');
		if (todo <= k) s[i] = 'a', k -= todo;
	}
	s[n-1] = 'a' + (s[n-1] - 'a' + k) % 26;
	cout << s << endl;
}



Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    long N;
    cin >> N;
    string res="";
    while(N){
        --N;
        res+=(char)('a'+(N%26));
        N/=26;
    }
    reverse(res.begin(),res.end());
    cout<<res;
}

Measured memory_bytes: 3620