akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
char s[SIZE];
int w[SIZE],e[SIZE];
int main(){
    int N;
    R(N);
    RS(s);
    REP(i,N){
        if(s[i]=='W')w[i+1]++;
        else e[i+1]++;
    }
    FOR(i,1,N){
        w[i]+=w[i-1];
        e[i]+=e[i-1];
    }
    int an=1e9;
    FOR(i,1,N){
        an=min(an,w[i-1]+e[N]-e[i]);
    }
    W(an);
    return 0;
}


Measured memory_bytes: 7552
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
int n,k,a,b,s,m,tmp;
int t[1001];
cin >> n >> k;

for(int i=0;i<k;i++){
cin >> a  >> b;
s=min(n-b+1,b);
m=min(n-a+1,a);
tmp=min(s,m);
if(tmp%3==1) t[i]=1;
else if(tmp%3==2) t[i]=2;
else t[i]=3;
}
for(int i=0;i<k;i++){
cout << t[i] << endl;
}
return 0;
}




Measured memory_bytes: 3084
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

int min(int a, int b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

int avd_i(int a, int b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

int main() {
	
	int N, M, K, count = 0;
	bool check = false;

	cin >> N >> M >> K;

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

		for (int j = 0; j <= M; j++) {

			if (((M - j)*i + (N - i)*j) == K) {

				check = true;
				goto qwe;

			}

		}

	}
qwe:

	if (check)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
	long long a = -1000000, b = 1000000, c = 0, tmp = 0, tmp2 = 0;
	cin >> tmp2;
	for (int i = 0; i < tmp2; i++){
		cin>>tmp;
		c += tmp;
		a = max(a, tmp);
		b = min(b, tmp);
	}
	cout << b << " " << a << " " << c << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, ans = 0;
  cin >> n;
  vector<int> v(n);
  for(int &x : v) {
    cin >> x;
    x--;
  }
  for(int i = 0; i < (int) v.size(); i++) {
    ans += i == v[v[i]];
  }
  cout << ans / 2 << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    int A,B;
    cin>>A;
    cin>>B;
    int sum,multi,subtract;
    sum=A+B;
    multi=A*B;
    subtract=A-B;
    if(sum>=multi && sum>=subtract){cout<<sum;}
    else if (multi>=sum && multi>=subtract ){cout<<multi;}
    else if(subtract>=multi && subtract>=sum){cout<<subtract;}
    return 0;}


Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	char ch,ans;
	cin>>ch;
	if(ch=='A')ans='T';
	if(ch=='T')ans='A';
	if(ch=='G')ans='C';
	if(ch=='C')ans='G';
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import bisect, collections

def helper(n, d, cur):
    if (n, cur) in d:
        return d[(n, cur)]
    if n == 1:
        return [chr(ord('a')+i) for i in range(0, min(25, cur+1)+1)]
    res = []
    for i in range(0, min(25, cur+1)+1):
        for x in helper(n-1, d, max(cur, i)):
            res.append(chr(ord('a')+i)+x)
    d[(n, cur)] = res
    return res

def solution():
    N = int(input().strip())
    res = []
    d = collections.defaultdict(list)
    for x in helper(N, d, -1):
        print(x)
    


def main():    
    # T = int(input().strip())
    for _ in range(1):
        solution()
    

main()

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

int main(){
  int N;
  int j = 0;
  string S;
  
  cin >> N;
  
  for(int i = 0; i < N; i++){
    
    cin >> S;
    
    if(S == "Y"){
      j = 1;
    }
    else{
    }
  }
  
  if(j == 1){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
int main(){

  bool cup[3]={true,false,false};
  int num[2];
  char n[2];
  char ssss;

  while(cin >> n[0] >> ssss >> n[1]){
    for(int i=0;i<2;i++)
      if(n[i] == 'A')
	num[i] = 0;
      else if(n[i] == 'B')
	num[i] = 1;
      else
	num[i] = 2;

    cup[num[1]] = !cup[num[1]];
    cup[num[0]] = !cup[num[0]];
  }

  for(int i=0;i<3;i++)
    if(cup[i] == true){
      if(i==0)
  	ssss = 'A';
      else if(i==1)
	ssss = 'B';
      else
	ssss = 'C';
      break;
    }

  cout << ssss << endl;

  return 0;
}

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

int main(){
string s;
int a[10],i,j;
while(cin>>s){
for(i=0;i<10;i++)a[i]=s[i]-'0';
for(i=0;i<9;i++){
for(j=0;j<9-i;j++){
a[j]+=a[j+1];
a[j]%=10;
}}
cout<<a[0]<<endl;}}

Measured memory_bytes: 1180
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if e-a>k:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);

        double[] list = new double[5];

        int min = 10;
        int minIndex = -1;

        for(int i = 0; i < 5; i++) {
            int value = sc.nextInt();
            int amari = value % 10;
            if (amari != 0 && amari < min) {
                min = amari;
                minIndex = i;
            }
            list[i] = value;
        }

        int ans = 0;

        for(int i = 0; i < 5; i++) {
            if (i == minIndex) {
                ans += list[i];
            } else {
                ans += (int) Math.ceil(list[i] / 10) * 10;
            }
        }

        // 出力
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
def gcd(a, b):
    """Return greatest common divisor using Euclid's Algorithm."""
    while b:      
        a, b = b, a % b
    return a
def gcmm(*args):
  return reduce(gcd, args)
print(gcmm(*a))

Measured memory_bytes: 14596
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

void chmax(ll& x, ll y) {
    if (x < y) x = y;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    while(1) {
        int n; cin >> n;
        if (n == 0) break;

        vll w(n); REP(i, n) cin >> w[i];

        vector<vll> dp(n + 1, vll(n + 1, 0));

        FOR(l, 2, n + 1) {
            REP(i, n) {
                int j = i + l - 1;
                if (j >= n) break;

                if (dp[i+1][j-1] == l - 2 && abs(w[i] - w[j]) <= 1) {
                    chmax(dp[i][j], l);
                } else {
                    FOR(k, i, j) {
                        chmax(dp[i][j], dp[i][k] + dp[k+1][j]);
                    }
                }
            }
        }

        print(dp[0][n-1]);
    }
}


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

string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename T> string to_string(T v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename T, typename U> string to_string(pair<T, U> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
void print_debug() { cerr << endl; }
template <typename T, typename... U> void print_debug(T t, U... u) { cerr << " " << to_string(t); print_debug(u...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", print_debug(__VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int n, m;
  cin >> n >> m;
  set<pair<int,int>> a;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    a.insert(make_pair(s, c));
  }
  vector<int> s(n);
  if (n > 1) {
    s[0] = 1;
  }
  set<int> used;
  bool ok = true;
  for (auto p : a) {
    if (p == make_pair(1, 0) && n > 1) {
      ok = false;
      break;
    }
    if (!used.count(p.first)) {
      s[p.first - 1] = p.second;
      used.insert(p.first);
    }
    else {
      ok = false;
      break;
    }
  }
  if (ok) {
    for (auto x : s) {
      cout << x;
    }
  }
  else {
    cout << -1;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, t;
  cin >> n >> t;
  vector<pair<int, int>> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end());

  int ans = 0;
  constexpr int T = 6006;
  vector<int> dp(T);
  // dp[i] = maximum deliciousness until the end of time i
  for(auto &tmp : a) {
    int x, y;
    tie(x, y) = tmp;
    for(int j = T - 1 - x; j >= 0; --j) {
      // j is the start time
      if(j < t) dp[j + x] = max(dp[j + x], dp[j] + y);
      if(j < t) ans = max(ans, dp[j + x]);
    }
  } 
  cout << ans << '\n';
}

Measured memory_bytes: 256
N=int(input())
def f(x):
  #正の数xに対して-2進数表現の桁数を出力
  i=0
  counter=0
  while counter<x:
    counter+=2**i
    i+=2
  return i-1

def g(x):
  k=f(x)
  out=[1]
  for i in range(k-1, 1, -1):
    out.append(h(x, i))
  if x%2==0:
    out.append(0)
  else:
    out.append(1)
  return out

def h(x, i):
  j=i//2
  b=sum([2**(2*k) for k in range(j)])
  if ((x-b-1)//(2**(i-1)))%2==0:
    return 1
  else:
    return 0
  
def e(n):
  #nは負
  n_=-n
  i=1
  while n_>2**i:
    i+=2
    
  return 2**i+n

if N>0:
  out=g(N)
  out=map(str, out)
  out="".join(out)
elif N<0:
  N_=-N
  k=N_//2+N_%2
  out=g(k)
  out.append(N_%2)
  out=map(str, out)
  out="".join(out)
else:
  out=0
  
print(out)

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  double r;
  cin >> r;
  cout << setprecision(10) << fixed;
  cout << 2.0 * pi * r << endl;
  return 0;
}



Measured memory_bytes: 3764
/* ex3_2
  terakura */

#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);

//10で割った余りで分類
  if(n % 10 == 3 ){
    printf("bon\n"); //10で割った余りが３の時”bon”

  }else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
    printf("pon\n"); //10で割った余りが0,1,6,8の時”pon”

  }else{
    printf("hon\n"); //10で割った余りが2,4,5,7,9の時”hon”
  }

  return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  string s,t;
  cin>>s>>t;
  int cnt=0;
  for(int i=stoi(s);i<=stoi(t);i++){
    if(s[0]==s[4]&&s[1]==s[3])cnt++;
    int w=stoi(s)+1;
    s=to_string(w);
  }
  cout <<cnt<<endl;
}

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

class SA{
public:
  string S;
  int n;
  vector<int> sa;
  
  SA():n(-1){}
  SA(string S):S(S),n(S.size()),sa(n){  
    vector<int> rnk(n);
    vector<int> tmp(n);
    for(int i=0;i<n;i++) sa[i]=i;
    for(int i=0;i<n;i++) rnk[i] = S[i];
    
    //k文字についてソートされているところから、2k文字でソート
    for(int Len=1;Len<=n;Len*=2){
      
      //(rnk[i],rnk[i+k])と(rnk[j],rnk[j+k])を比較
      auto compare_sa=[&](const int &i,const int &j){
        if(rnk[i]!=rnk[j])return rnk[i]<rnk[j];
        int ri=i+Len<n?rnk[i+Len]:-1;
        int rj=j+Len<n?rnk[j+Len]:-1;
        return ri<rj;
      };
      
      sort(sa.begin(),sa.end(),compare_sa);

      //いったんtmpに次のランクを計算して、rnkに代入
      for(int i=1;i<n;i++)
        tmp[sa[i]] = tmp[sa[i-1]] + compare_sa(sa[i-1],sa[i]);
      rnk = tmp;
    }
  }
  
  int lower_bound(string T){
    assert(n >= 0);
    int L=-1,R=S.length();
    while(L+1<R){
      int M = (L+R)/2;
      S.compare(sa[M],T.size(),T)<0? L = M:R = M;
    }
    return R;
  } 
  
  int upper_bound(string T){return lower_bound(T+char('z'+ 1));} 
  int count(string T){return upper_bound(T) - lower_bound(T);};
  
};

string s;
int k;
set<string> ans;

signed main(){
  
  cin>>s>>k;

  SA sa(s);
  
  for(int i=0;i<sa.n;i++){
    
    int cnt = 0;
    
    for(int j=sa.sa[i];j<s.size();j++){
      
      cnt++;
            
      ans.insert(s.substr(sa.sa[i],cnt));
      
      if( ans.size() == k ) break;
      
    }
    
    if( ans.size() == k ) break;
    
  }
  
  int cnt = 0;

  for(string a : ans ){
    cnt++;
    if( cnt == k ){
      cout<<a<<endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int h1 = sc.nextInt();
        int m1= sc.nextInt();
        int h2 = sc.nextInt();
        int m2 = sc.nextInt();
        int K = sc.nextInt();
        int res;

        res = Math.max((h2-h1)*60+(m2-m1)-K,0);
        
        
        System.out.println(res);
        }
    }

Measured memory_bytes: 35620
import sys

input = sys.stdin.readline

N, H = map(int, input().split())

slash_throw = [[int(x) for x in input().split()] for _ in range(N)]

slashs = []
throws = []

for slash, throw in slash_throw:
    slashs.append(slash)
    throws.append(throw)

max_slash = sorted(slashs)[-1]
throws.sort(reverse=True)
remaining_hp = H
attack_count = 0

for throw in throws:
    if throw > max_slash:
        remaining_hp -= throw
        attack_count += 1
        if remaining_hp <= 0:
            break

if remaining_hp > 0:
    attack_count += -(remaining_hp // -max_slash)

print(attack_count)

Measured memory_bytes: 69340
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,O,P,Q;
    cin >> N;
    int x = N/100;
    if(N < x*100+x*10+x){
    O = x*100+x*10+x;
    cout << O << endl;}
    else if(N > x*100+x*10+x){
    P = (x+1)*100+(x+1)*10+(x+1);
    cout << P << endl;}
    else if(N = x*100+x*10+x)
    cout << N << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    string a, b;

    std::cin >> a >> b;

    if (a != b && b.find(a) == 0 && a.size() == b.size() - 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
class ABC042B{
    static void Main(){
        int N;
        int i;
        string buf;
        List<string> list = new List<string>();
        buf = Console.ReadLine();

        string[] temp_int = buf.Split(' ');

        N = int.Parse(temp_int[0]);

        
        for( i=0;i<N;i++){
            list.Add(Console.ReadLine().Replace("\n","").Replace("\r",""));
        }
        list.Sort();
        for(i=0;i<N;i++){
            Console.Write(list[i]);
        }
        Console.WriteLine("");
    }
}

Measured memory_bytes: 11360
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let mut a = it.next().unwrap();
    if a == 1 {
        a = 14;
    }
    let mut b = it.next().unwrap();
    if b == 1 {
        b = 14;
    }
    if a > b {
        println!("Alice");
    } else if a == b {
        println!("Draw");
    } else {
        println!("Bob");
    }
}


Measured memory_bytes: 4352
#include <iostream>
 using namespace std;
 int main() {
     int a;
     int b;
     int c;
     cin >> a >> b >> c;
     
     if (a+b>=c){
         cout << "Yes" << endl;
    } 
     else {
     cout << "No" << endl;
     } return 0;
 }


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<int> p(n), q(n), s(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];
    for(int i = 0; i < n; i++) s[i] = i + 1;

    int a, b, cnt = 1;
    do{
        vector<int> w(n);
        w = s;
        if(w == p) a = cnt;
        if(w == q) b = cnt;
        cnt++;
    }while(next_permutation(s.begin(), s.end()));

    cout << abs(a-b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	string s[5];
	cin >> s[0] >> s[1] >> s[2];
	cout << 'A'<< s[1][0] << 'C';

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
void heap(int a, int b, string* s);
void swap(int a,int b, string* s);
int main(){
	int n;
	int m = 1;
	string* s;
	cin >> n;
	s = new string[n];
	for(int i=0; i<n; i++){
		cin >> s[i];
	}
	for(int i=(n-2)/2; i>=0; i--){
	 heap(i,n-1,s);
	}
        for(int i=n-1; i>0; i--){
         swap(0,i,s);
         heap(0,i-1,s);
        }
	for(int i=1; i<n; i++){
		if(s[i]!=s[i-1]){
                 m++;
                }
	}
	cout << m;
	return 0;
}

void heap(int a, int b, string* s){
 int c;
 string d;
 d=s[a];
 while(true) {
  c=2*a+1;
  if(c>b)break;
  if(c!=b){
   if(s[c+1]>s[c]){
    c++;
   }
  }
  if(d>=s[c])break;
  s[a]=s[c];
  a=c;
 }
 s[a]=d;
}
void swap(int a,int b, string* s){
 string t = s[a];
 s[a]=s[b];
 s[b]=t;
}


Measured memory_bytes: 9884
#pragma warning(disable  4996)
#define _CRT_SECURE_NO_WARNINGS
//#include<bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include<cstring>
#include<map>
#include<set>
#include<string>
#include <climits>
#include <vector>
#include<stack>
#include<bitset>
#include<unordered_map>
#include<queue>
#include<deque>
#include<iomanip>
#define pb push_back
#define endl '\n';
#define sz(s) int(s.size())
#define Ceil(x,y)  ((x+y-1)/y)
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define I64 int
typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
const ll mod = ll(1e9 + 7);
const double PI = acos(-1.0);
const int N = (int)1e7 + 1;
using namespace std;

void Selim()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int dx[4] = { 0, -1, 0, 1 };
int dy[4] = { -1, 0, 1, 0 };
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll LCM(ll a, ll b) { return a / gcd(a, b)*b; }
//ll fact(long long  n) { return !n ? 1 : n * fact(n - 1); }
//transform(s.begin(), s.end(), s.begin(), ::tolower);
//palindrom if(s==string(s.rbegin(),s.rend()));
//memset(arr,0,sizeof arr)

/*
*********************************************************************************************

If you want something you've never had, you must be willing to do something you've never done

*********************************************************************************************
*/

int main()
{
	Selim();

	int a, b;
	cin >> a >> b;
	cout << a*b << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>

int up(const void *a,const void *b){
  return *(int *)a - *(int *)b;
}

int main(void){
  int n;
  scanf("%d",&n);

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

  qsort(a,n,sizeof(int),up);
  int count = 1 , ans = 0;
  for(int i = 0;i < n-1;i ++){
    if(a[i] == a[i+1]){
      count ++;
    }
    else{
      if(a[i] > count){
        ans += count;
      }
      else{
        ans += count - a[i];
      }
      count = 1;
    }
  }
  if(a[n-1] > count){
    ans += count;
  }
  else{
    ans += count - a[n-1];
  }

  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 2228
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int a = in.nextInt();
        int b = in.nextInt();
        int sum = 0;
      
      for(int i =1; i <b-a ;i++){
		sum += i;
      }
      
      System.out.print(sum-a);
      
	}
}


Measured memory_bytes: 24148
unittest
{
	assert( [ "4 2 2" ].parse.expand.solve == 14 );		// 追加ケース
	
	assert( [ "3 2 1" ].parse.expand.solve == 6 );
	assert( [ "100 100 0" ].parse.expand.solve == 73074801 );
	assert( [ "60522 114575 7559" ].parse.expand.solve == 479519525 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nmk = input.front.split.to!( long[] );
	return tuple( nmk[ 0 ], nmk[ 1 ], nmk[ 2 ] );
}

auto solve( long n, long m, long k )
{
	const M = 998244353L;
	
	auto ans = ModWorld!M( 0L );
	for( auto i = 0L, d = n - 1; i <= k; i++, d-- )
	{
		// 隣と違う色になっているブロックの位置のパターン数を計算
		auto p = ( n - 1 ).combination!M( d );
		
		// パターン数に色数を反映
		p *= m * ( ModWorld!M( m - 1 ) ^^ d );
		
		// パターン数を合計
		ans += p;
	}
	return ans;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	// 演算子オーバーロード
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = this.n * a % M;
			a = a ^^ 2 % M;
		}
	}
	auto opBinary( string OP )( ModWorld r )
	{
		auto t = this;
		t.opOpAssign!OP( r );
		return t;
	}
	
	// long型対応
	void opAssign( long r ){ this.n = r; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	// format用出力
	string toString()
	{
		return this.n.to!string;
	}
}

// 階乗
auto factorial( long M )( long x )
{
	static memo = [ ModWorld!M( 1L ) ];
	if( memo.length <= x )
	{
		auto i = memo.length.signed;
		memo.length = x + 1;
		for( ; i <= x; i++ ) memo[ i ] = memo[ i - 1 ] * i;
	}
	return memo[ x ];
}

// 組み合わせ数
auto combination( long M )( long n, long k )
{
	if( n < k ) return ModWorld!M( 0L );
	else        return n.factorial!M / ( k.factorial!M * ( n - k ).factorial!M );
}


Measured memory_bytes: 4296
<?php
    fscanf(STDIN, "%s", $input);
    $input = str_split($input);
    sort($input);
    array_unique($input);
    $lowercase = str_split('abcdefghijklmnopqrstuvwxyz');
    $not_found = array_diff($lowercase, $input);
    $output = implode($not_found);
    if ($output == '') { echo 'None' . "\n"; }
    else { echo $output[0] . "\n"; }
?>


Measured memory_bytes: 32248
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    ll ans=0,q=INF;
    rep(i,n){
        cin >> a.at(i) >> b.at(i);
        if (a.at(i)>b.at(i)) q=min(q,b.at(i));
        ans+=a.at(i);
    }
    if (q==INF) q=ans;
    cout << ans-q << endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, ans=0;
	string S;

	cin >> N >> S;

	int cnt1[305]={}, cnt2[305]={};
	rep(i,N) cnt1[S[i]]++;
	rep(i,N) cnt2[S[i+N]]++;

	bool f = true;
	rep(i,305) f &= (cnt1[i] == cnt2[i]);
	if( !f ){
		cout << 0 << endl;
		return 0;
	}

	map<string,ll> memo;
	rep(k,1<<N){
		string s, t;
		rep(i,N) if(k & (1<<i))    s += S[i];
		rep(i,N) if(!(k & (1<<i))) t += S[i];
		memo[s + ";" + t]++;
		//cout << s + ";" + t << endl;
	}
	//cout << "--" << endl;
	rep(k,1<<N){
		string s, t;
		rep(i,N) if(k & (1<<i))    s += S[2*N-i-1];
		rep(i,N) if(!(k & (1<<i))) t += S[2*N-i-1];
		//cout << s + ";" + t << endl;
		ans += memo[s + ";" + t];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 66944
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		a[n] = 0;
		Arrays.sort(a);
		int ans = 0;
		for(int i=n; i>0; i--){
			int temp = i;
			while(a[i]==a[temp]){
				temp--;
			}
			if((i-temp)%2==1){
				ans++;
			}
			i = temp + 1;
		}
		System.out.println(ans);
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<vector<int>> data(2,vector<int>(N));
  for(int i=0; i<2; i++){
    for(int j=0; j<N; j++){
      cin >> data.at(i).at(j);
    }
  }
  int sum = 0;
  for(int j=0; j<N; j++){
    if(data.at(0).at(j)-data.at(1).at(j)>=0){
      sum += data.at(0).at(j)-data.at(1).at(j);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  char b;
  cin >> b;
  if(b == 'A')
  {
    cout << 'T' << endl;
  }else if(b == 'T')
  {
    cout << 'A' << endl;
  }
  else if( b == 'G')
  {
    cout << 'C' << endl;
  }
  else if(b == 'C')
  {
    cout << 'G' << endl;
  }
  
}


Measured memory_bytes: 256
// 2020 05 02
// ABC166 D I hate Factoriation
//
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

bool check(ll a, ll b, ll c) {
    if (pow(a, 5) - pow(b, 5) == c){
        return true;
    }
    return false;
}

int main() {
    ll x;
    cin >> x;

    ll ans_a = 0, ans_b = 0;

    const auto &res = enum_divisors(x);
  //  for (int i = 0; i < res.size(); ++i) cout << res[i] << " ";
    //cout << endl;
    bool flag = false;

    ll num = res.size();
    for (ll i = 0; i <= num; i++) {
        ll l = res[i];
        ll r = res[num - 1 - i];
       // cout << "res " << l << " " << r << endl;

        for (ll a = -10000; a < 10000; a++) {
            ll b = a - res[i];
            //cout << a << " " << b << endl;
            flag = check(a, b, x);
           // cout << flag << endl;
            if (flag) {
                ans_a = a;
                ans_b = b;
                break;
            }
        }
        if (flag) break;
    }

    cout << ans_a << " " << ans_b << endl;


    return 0;
}

Measured memory_bytes: 4236
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();

        Map<Anagram, Integer> anagrams = new HashMap<>();

        long ans = 0;
        for (int i=0; i < n; i++) {
            Anagram a = new Anagram(in.next());
            if (anagrams.containsKey(a)) {
                int j = anagrams.get(a);
                ans += j;
                anagrams.put(a, j + 1);
            }
            else
                anagrams.put(a, 1);
        }

        out.println(ans);
    }

    private static String random() {
        StringBuilder s = new StringBuilder();
        Random r = new Random();
        for (int i=0; i < 10; i++) {
            s.append('a' + r.nextInt(26));
        }
        return s.toString();
    }

    private static class Anagram {
        Map<Character, Integer> chars;

        private Anagram(String s) {
            this.chars = new HashMap<>();
            for (char ch : s.toCharArray()) {
                if (!this.chars.containsKey(ch))
                    this.chars.put(ch, 1);
                else
                    this.chars.put(ch, this.chars.get(ch) + 1);
            }
        }

        @Override
        public boolean equals(Object obj) {
            return obj instanceof Anagram && ((Anagram) obj).chars.equals(this.chars);
        }

        @Override
        public int hashCode() {
            int hash = 0;
            List<Map.Entry<Character, Integer>> list = new ArrayList<>(this.chars.entrySet());
            list.sort(((o1, o2) -> o1.getKey() - o2.getKey()));
            for (Map.Entry<Character, Integer> e : list) {
                hash = Objects.hash(hash, e.getKey(), e.getValue());
            }
            return hash;
        }
    }

}


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

#define ll long long int
#define pii pair<int, int>
#define PII pair<ll, ll>
#define llu long long unsigned
#define ld long double

const int Max=1e9+100;
const ll MAX=1e18+100;

const int sz=2e5+100;
int mark[110];
const ll mod=1e9+7;

ll n;
ll dp[2010];

ll cholo(ll id,ll sum)
{
    if(sum==0) return 1;

    ll &ret=dp[sum];
    if(~ret) return ret;

    ll tot=0;
    for(ll i=3;i<=sum;i++){
        if(sum>=i && (sum-i)>=0) tot=(tot + cholo(id+1, sum-i))%mod;
    }

    return (ret=tot);
}


int main()
{
   int m,p,q,x,y,u,i,j,a,b,c;
   int t;
   
   cin>>n;
   memset(dp, -1, sizeof dp);

   ll ans=cholo(0, n);
   cout<<ans<<endl;
   


}

Measured memory_bytes: 3660
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp
//

#include <iostream>
#define rep(i,n) for(int (i) =0;(i) < (n);(i)++)
using namespace std;

void show(int *a,int x){
    for(int i =0;i<x;i++){
        cout << a[i] << endl;
    }
}
int main() {
    int N,R;
    int A[2][55];
    int p,c;
    while(cin >> N >> R && N) {
        for(int i=0; i<N; ++i){
            A[0][i] = N - i;
            
        }
        int now = 0;
        int next = 1;
        rep(i,R){
            cin >> p >> c;
            rep(j,c){
                A[next][j] = A[now][p-1+j];
            
            }
            for(int j=p-1+c; j<N; j++){
                A[next][j] = A[now][j];
            
            }
            for(int j=0; j<p-1; ++j){
                A[next][c+j] = A[now][j];
            }
            int temp = now;
            now = next;
            next = temp;
            
            
        }
        cout << A[now][0] << endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int a,b,c,d,e,f,k,l,m,n,x,y,z;
	int ans;
	String[] S;

	Main(){
		// 整数の入力
		n = sc.nextInt();
		d = sc.nextInt();

		// 出力
		System.out.println(n%(d*2+1)==0?n/(d*2+1):n/(d*2+1)+1);
	}

	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 21844
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

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

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

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

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N, K = il()
    L = sorted(il(), reverse=True)
    print(sum(L[:K]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3932
#include <cstdio>
#include <set>
using namespace std;
class union_find{
	int *parent,n;
public:
	int root(int a){return parent[a]==a?a:(parent[a]=root(parent[a]));}
	union_find(int _n){n=_n;parent=new int[n];for(int i=0;i<n;i++)parent[i]=i;}
	~union_find(){delete []parent;}
	int same(int a,int b){return root(a)==root(b);}
	int unite(int a,int b){
		int x=root(a),y=root(b);
		if(x==y)return 0;
		parent[x]=y;
		return 1;
	}
	int size(){
		set<int>s;
		for(int i=0;i<n;i++)s.insert(root(i));
		return s.size();
	}
};
int main(){
	int n,q,c,x,y;
	scanf("%d%d",&n,&q);
	union_find uf(n);
	for(;q--;c?printf("%d\n",uf.same(x,y)):uf.unite(x,y))scanf("%d%d%d",&c,&x,&y);
}

Measured memory_bytes: 1140
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  char w[9][9],e[5]="URDL";
  int x=0,y=0,h=1,i,g;
  int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
  for (i=0;i<9;i++) gets(w[i]);
  while(true) {
   h=(h+3) % 4;
   for (i=0;i<4;i++) {
	   if (y+dy[h]>=0 && y+dy[h]<=4 && x+dx[h]>=0 && x+dx[h]<=4) {
          if (dx[h]==-1) g=-1; else g=0;
		  if (w[2*y+dy[h]][x+g]=='1') break;
	   }
	   	  h=(h+1) % 4;
   }
   x+=dx[h]; y+=dy[h];
   cout << e[h];
   if (x==0 && y==0) break;
  }
  cout << endl;
  return 0;
}

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

int main() {
  int n, W;
  cin >> n >> W;
  int w, v;
  vector<long> dp(n*1000+1, W+1);
  dp[0] = 0;
  rep(i, n) {
    cin >> w >> v;
    rep (j, n*1000+1) {
      int k = n*1000-j;
      if (k >= v) dp[k] = min(dp[k-v] + w, dp[k]);
    }
  }
  v = 0;
  rep (j, n*1000+1) if (dp[j] <= W) v = j;
  cout << v;

}


Measured memory_bytes: 1024
a,b,c= input().split()
x,y,z=(int(a),int(b),int(c))
ans_list =[]
for i in range(min(x,y)):
    
    if x % (i+1) == 0 and y % (i+1) == 0:
        ans_list.append(i+1)
print(ans_list[len(ans_list)-z])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

template<class D>
vector<D> dijkstra(const vector<vector<pair<int,D>>>& G, int s = 0){	//G:(v,cost)
	using P = pair<D,int>;
	priority_queue<P,vector<P>,greater<P> > que;
	int N = G.size();

	D inf = 1e9;
	vector<D> d(N,inf);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v = p.sc;
		D c = p.fs;
		if(d[v]!=c) continue;
		for(auto p:G[v]){
			int to=p.fs;
			if(d[to]>d[v]+p.sc){
				d[to]=d[v]+p.sc;
				que.push(P(d[to],to));
			}
		}
	}

	return d;
}

int main(){
	int N;
	cin>>N;
	using P = pair<int,int>;
	vector<vector<P>> G(N);
	rep(x,N){
		G[x].pb(P((x+1)%N,1));
		G[x].pb(P((x*10)%N,0));
	}
	vector<int> d = dijkstra(G,1);
	cout<<d[0]+1<<endl;
}


Measured memory_bytes: 6780
package main

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

func main() {
	scanInit()

	n := nextInt()
	m := nextInt()
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, m)
	d := make([]int, m)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		b[i] = nextInt()
	}
	for i := 0; i < m; i++ {
		c[i] = nextInt()
		d[i] = nextInt()
	}

	for i := 0; i < n; i++ {
		x1 := a[i]
		y1 := b[i]
		mdifmin := math.MaxInt64
		mdifminIdx := -1
		for j := 0; j < m; j++ {
			x2 := c[j]
			y2 := d[j]

			mdif := abs(x2-x1) + abs(y2-y1)

			if mdifmin > mdif {
				mdifmin = mdif
				mdifminIdx = j
			}

		}
		fmt.Println(mdifminIdx + 1)
	}

}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
using System;
using System.Collections.Generic;
using System.Text;
public class ABC150C {
    public static void Main() {
        int N, M, correct = 0, penalty = 0;
        List<int> waCounts = new List<int>();
        List<bool> accepteds = new List<bool>();
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        M = int.Parse(str[1]);
        for (int i = 0; i < N; i++) {
            waCounts.Add(0);
            accepteds.Add(false);
        }

        for (int i = 0; i < M; i++) {
            str = Console.ReadLine().Split(' ');
            int p = int.Parse(str[0]) - 1;
            string result = str[1];
            if (result == "AC") {
                accepteds[p] = true;
            } else {
                if (!accepteds[p]) waCounts[p]++;;
            }
        }

        for (int i = 0; i < N; i++) {
            if (accepteds[i]) {
                correct++;
                penalty += waCounts[i];
            }
        }
        Console.WriteLine(correct + " " + penalty);
    }
}


Measured memory_bytes: 16352