akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC021A {
    class Program {
        static void Main(string[] args) {
            long N = long.Parse(Console.ReadLine());
            int j = 0;
            while (Math.Pow(10, j) <= N) {
                j++;
            }
            j--;
            long top = N / (long)Math.Pow(10, j);
            long ans = 0;
            if (N == (top + 1) * Math.Pow(10, j) - 1) {
                ans = top + 9 * j;
            } else {
                ans = top - 1 + 9 * j;
            }
            Console.WriteLine(ans);
        }
    }
}

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

using namespace std;

int main(){
 
  int a,v;
  cin >> a >> v;
  
  int x,y;
   x = max(a,v);
  
  if( x == a ){
    a--;
  }else
    v--;
  
  y = max(a,v);
  
  cout << x+y << endl;
  
  return 0;
}

Measured memory_bytes: 256
// Author : MohamedSameh
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <sstream>
#include <string.h>

typedef long long ll ;
// random in each run --> srand(time(NULL));

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"
void fo (){fflush(stdout);}
using namespace std;

int main ()
{
  string x ;
  cin >> x;
  for (int i =0 ; i + 1 < SZ(x) ;i++)
  {
    if (x[i] == x[i+1])
    {
      printf ("Bad\n");
      return 0 ;
    }
  }
  printf ("Good\n"); 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    int value = r * 100 + g * 10 + b;
    cout << (value >= 4 && value % 4 == 0 ? "YES" : "NO") << endl;
    return 0;
};


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main() {
	int n, m, j, suu;
	while ((cin >> m >> n) && m != 0 || n != 0) {
		int check[1001] = { 0 };
		for (int i = 1; i <= m; i++)check[i] = i;
		j = 1;
		suu = m;
		for (int i = 1; i <= n; i++) {
			string str;

			cin >> str;
			if (suu > 1) {
				if (i % 15 == 0) {
					if (str != "FizzBuzz") {
						check[j] = 0;
						suu--;
					}
				}
				else if (i % 3 == 0) {
					if (str != "Fizz") {
						check[j] = 0;
						suu--;
					}
				}
				else if (i % 5 == 0) {
					if (str != "Buzz") {
						check[j] = 0;
						suu--;
					}
				}
				else {
					char buf[10] = { NULL };
					sprintf(buf, "%d", i);
					if (str != buf) {
						check[j] = 0;
						suu--;
					}
				}
				//j++;
				/*int x;
					for (x = j; check[x] == 0;) {
						x++;
						if (x > m)x = 1;
					}
				j = x;*/
				int j2 = j;
				for (int x = j+1; x <= m; x++) {
					if (check[x] != 0) {
						j2 = x; break;
					}
				}
				if (j == j2)for (int x = 1; x < j; x++) {
					if (check[x] != 0) {
						j2 = x; break;
					}
				}
				j = j2;
			}
		}
		int las;
		for (int i = m; i > 0; i--) if (check[i] != 0) {
			las = i; break;
		}
		for (int i = 1; i <= m; i++)
		{
			if (check[i] != 0)
			{
				cout << i;
				if (i<las)
					cout << " ";
			}
		}
		cout << endl;
	}
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n, d;
  cin >> n >> d;
  int tmp = 0;
  rep(i, 1000000) {
    tmp += d * 2 + 1;
    if (tmp >= n) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
alpha = "abcdefghij"
n = int(input())
def dfs(s,k):
    if len(s) == n:
        print(s)
    else:
        for i in range(k+1):
            if i == k:
                dfs(s+alpha[i],k+1)
            else:
                dfs(s+alpha[i],k)
dfs("",0)

Measured memory_bytes: 9036
#include <iostream>
#include <sstream>

using namespace std;
int NOD(int a,int b){
	if (b==0)
		return a;
	return NOD(b, a % b);
}
int main(){
	int r,i=0;
	int a[2];
	string s;
	getline(cin,s);
	stringstream ss;
	ss<<s;
	while(ss>>r){
      a[i]=r;
      i++;
	}
	int c,d;
	c=a[0];
	d=a[1];
	
	cout<<NOD(c,d)<<endl;
	return 0;
}

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

using namespace std;
const int OO = 0x3f3f3f3f;
//const long long OO = (long long) 5e18+7;
//const unsigned long long UOO = (long long) 10e18+7;
#define lp(i,a,n) for(long long i = a ; i < n ; ++i)
#define lpr(i,a,n) for(long long i = a ; i >= n ; --i)
#define rep(i,vec) for(ll i = 0 ; i < vec.size() ; ++i)
#define reprv(i,vec) for(ll i = vec.size()-1; i >=0 ; --i)
#define eps (1e-5)
#define pb(i) push_back(i)
#define EPS 1e-9
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef vector<int> vi ;
typedef   long long ll;
typedef   unsigned long long ull;
typedef vector<ll> vll ;
typedef pair<int,int> pii ;
typedef vector< pair<int,int> >  vpii;
typedef vector<pair<long long,long long>> vpll;
typedef vector<vector<int> > vvi ;
typedef complex<double> point;
typedef pair<ll,ll> pll;

using namespace std;
ll  inv(ll a, ll b) {return 1 < a ? b - inv(b % a, a) * b / a : 1;}
ll  Pow(ll  B,ll  P){ll  R=1; while(P>0)  {if(P&1) R=(R*B);P/=2;B=(B*B);}return R;} //compute b^p
ll  GCD(ll  a,ll  b){ while(b){b ^= a ^=b ^= a %=b;}  return a;}
ll  LCM(ll  a,ll  b) { return (a / GCD(a,b)*b); }
ll  BigMod(ll  B,ll  P,ll  M){ ll  R=1; while(P>0)  {if(P&1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (ll )R;} //compute b^p%m
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int i=uniform_int_distribution<int>(1,n)(rng);


int N,w;

ll mem[100005];




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
//    cout.tie(0);
//#ifndef ONLINE_JUDGE
//   freopen( "output.txt" , "w" , stdout ) ;
//   freopen( "input.txt" , "r" , stdin ) ;
//#endif


    cin >> N >> w;
    lp(i,0,N){
        ll  weight , value;
        cin >> weight >> value;
        lpr(j,w-weight,0){
            mem[j+weight] = max(mem[j+weight],mem[j]+value);
        }
    }
    
    cout << mem[w];
    return 0;
}


Measured memory_bytes: 4340
let is_acgt = function 'A' | 'C' | 'G' | 'T' -> true | _ -> false
let is_acgt s =
  let l = String.length s in
  let res = ref true in
  for i = 0 to l - 1 do
    if not (is_acgt @@ String.get s i) then res := false
  done; !res

let _ =
  let s = Scanf.scanf "%s\n" (fun s -> s) in
  let l = String.length s in
  let max_n = ref 0 in
  for i = 0 to l - 1 do
    for j = 1 to l - i do
      let s' = String.sub s i j in
      if is_acgt s' then max_n := max !max_n (j)
    done
  done;
  !max_n |> print_int

Measured memory_bytes: 384
import java.util.*;
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);

    int h = sc.nextInt();
    int a = sc.nextInt();
    int count = 0;

    for (int i = 1;h>0 ;i++ ) {
    h-=a;
    count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
int n;
int arr[200006];

short done[1000005];
short sq[1005];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	REP(i, 0, n){
		cin >> arr[i];
	}
	sort(arr, arr + n);
	
	int answer = 0;
	REP(i, 0, n){
		answer++;
		bool deducted = false;
		if (i == 0 && i != n - 1 && arr[i] == arr[i + 1]){
			answer--;
			deducted = true;
		} else if (i != 0 && i != n - 1 && arr[i] != arr[i - 1] && arr[i] == arr[i + 1]){
			answer--;
			deducted = true;
		}
		if (arr[i] <= 1001){
			REP(j, 1, 1002){
				if (sq[j] && arr[i]%j == 0){
					if (deducted) break;
					deducted = true;
					answer--;
					break;
				}
			}
			sq[arr[i]] = true;
		} else {
			if (done[arr[i]]){
				if (!deducted){
					deducted = true;
					answer--;
				} 
			} else {
				REP(j, 1, 1002){
					if (sq[j] && arr[i]%j == 0){
						if (deducted) break;
						deducted = true;
						answer--;
						break;
					}
				}				
			}

			
			REP(j, 1, (1000001/arr[i]) + 1){
				if (j*arr[i] > 1000000) break;
				done[j*arr[i]] = true;
			}
		}
	}
	cout << answer << endl;
}

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


int main(){
    int N;
    int a[110];
    cin>>N;
    for (int i=0; i<N; i++) {
        cin>>a[i];
    }
    sort(a, a+N, greater<int>());
    int Alice = 0;
    int Bob = 0;
    for (int i=0; i<N; i++) {
        if (i%2==0) {
            Alice += a[i];
        }else{
            Bob += a[i];
        }
    }
    cout<<Alice-Bob<<endl;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)

    val A = scanner.nextInt()
    val B = scanner.nextInt()
    val C = scanner.nextInt()

    val list = listOf(A, B, C).sorted()

    var base = list[2]
    var m = list[1]
    var n = list[0]
    
    var count = 0
    while (true) {
        if (m - n >= 2) {
            n += 2
        }
        else if (m - n == 1) {
            base += 1
            n += 1
        }
        else {
            if (base > m) {
                m += 1
                n += 1
            }
            else {
                break
            }
        }
        count += 1
    }

    println(count)
}

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

using namespace std;


int main(){
   int x, a, b, c;

   cin >> a >> b >> c >> x;


   int cnt = 0;
   for(int i = 0; i <= a; i++)
        for(int j = 0; j <= b; j++)
            for(int k = 0; k <= c; k++){

        if(i * 500 + j*100 + k * 50 == x) cnt++;
   }

   cout << cnt << endl;

}


Measured memory_bytes: 256
S = input()
S = S[::-1]
MOD = 10**9 + 7

# dp[i][j]: i桁目までで，余りがjになるものの場合の数 
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
    pow10 = pow(10,i,13)
    if S[i] != '?':
        d = int(S[i])
        for r in range(13):
            dp[i+1][(r + d*pow10) % 13] = dp[i][r]
    else:
        for d in range(10):
            for r in range(13):
                dp[i+1][(r + d*pow10) % 13] += dp[i][r]
                dp[i+1][(r + d*pow10) % 13] %= MOD

print(dp[len(S)][5])

Measured memory_bytes: 95812
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <map>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

signed main(){
  int N,M;
  int K[31];
  bool A[31][31]={};
  int aans=0;
  cin >> N>>M;
  LOOP1(i,N){
    cin >> K[i];
    LOOP1(j,K[i]){
      int s;
      cin >> s;
      A[i][s]=1;
    }
  }
  LOOP1(i,M){
    bool islike = true;
    LOOP1(j,N){
      if(!A[j][i])islike = false;
    }
    // cerr << islike << endl;
    if(islike)aans++;
  }
  cout << aans;
}


Measured memory_bytes: 256
/*alurquiza*/
//S:Digit Sum
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7,SIZE = 1e4 + 1,MAXR = 100,CANTD = 10;
int DP[SIZE][CANTD][MAXR];

void sum(int &a,int b){
    a += b;
    if(a >= MOD)
        a -= MOD;
    if(a < 0)
        a += MOD;
}

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

//    freopen(".in","r",stdin);
//    freopen(".out","w",stdout);

    string K;
    int D;

    cin >> K >> D;

    int N = K.size();

    for(int i = 0;i < 10;i++)
        DP[0][i][0] = 1;

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

        ///DP[i][d][r] -> poniendo el digito d en la posicion i en cuantos numeros la suma de sus digitos es = r;
        for(int d = 0;d < 10;d++){
            for(int r = 0;r < D;r++){
                int newr = (r - (d % D) + D) % D;
                sum(DP[i][d][r],DP[i - 1][9][newr]);
            }
        }

        ///acumular la dinamica para todos los digitos con distancia r
        for(int d = 1;d < 10;d++){
            for(int r = 0;r < D;r++){
                sum(DP[i][d][r],DP[i][d - 1][r]);
            }
        }
    }

    int sol = 0,r = 0;
    for(int i = 0;i < N;i++){
        int pos = N - i;

        int digit = K[i] - '0';

        if(digit){
            sum(sol,DP[pos][digit - 1][r] % MOD);
            r = (r - (digit % D) + D) % D;
        }
    }

    ///A la solucion le quito el numero 0 y le sumo si el numero inicial cumple la condicion
    cout << (sol - 1 + !r + MOD) % MOD << '\n';

    return 0;
}













Measured memory_bytes: 39296
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

string S;
int cnt;

int main(){
	cin >> S;

	for (int i = 0; i < (S.size() / 2); i++){
		if (S[i] != S[S.size() - i - 1]){
			cnt++;
		}

	}
	
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
s = list(input())
odd_s = "".join(s[::2])
even_s = "".join(s[1::2])

odd_c = ["R","U","D"]
even_c = ["L","U","D"]

flag = True

for w in odd_s:
    if w not  in odd_c:
        flag = False
        
for w in even_s:
    if w not  in even_c:
        flag = False
        
if flag :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq

def factrization(N):
    k = 2
    ret = {}
    L = N ** 0.5
    while k < L:
        if N % k == 0:
            ret.setdefault(k, 0)
            ret[k] += 1
            N //= k
        else:
            k += 1
    if N > 1:
        ret.setdefault(N, 0)
        ret[N] += 1
    return ret
#
# print(factrization(64))
# print(factrization(24))
# print(factrization(1000000007))
# print(factrization(997764507000))

def solve(N):
    f = factrization(N)
    ans = 0
    for n in f.values():
        i = 1
        while i <= n:
            n -= i
            i += 1
            ans += 1
    return ans
#
# print(solve(64))
# print(solve(24))
# print(solve(1))
# print(solve(1000000007))
# print(solve(997764507000))

if __name__ == "__main__":
    N = int(input())
    print(solve(N))


Measured memory_bytes: 9736
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/15  Problem: AOJ 2162 / Link: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2162  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----

全周期をみたいけどLCM(1 to 24)は5*10^9overなのできびしい。
3,7だけ見ると愚直をしなくての3maxと7maxをとって足しても答えになる。これは互いに素の時のみできる
つまり2,4は無理
互いに素なものは別でやっていいのでなるべく取り除けばLCMを小さくできる。
今回はmaxが24なので13以上の素数を取り除くと、これらのLDMは 55440でハッピー
こっちは全探索をしてあとは独立にやってもよいから間に合ってくれる。

----解説ここまで---- */

LL N;

LL ans = 0LL;
bool doku(int a) { return (a == 13 || a == 17 || a == 19 || a == 23); }

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	map<int, int>m;
	while (cin >> N, N) {
		VL a(55440 + 1, 0);
		VVL b(24 + 1, VL(24, 0));
		FOR(_, 0, N) {
			int d; cin >> d;
			int t; cin >> t;
			VL in(d);
			FOR(j, 0, d) {
				cin >> in[j];
				b[d][(j - t + d) % d] += in[j];
			}
		}
		ans = 0;
		FOR(i, 1, 24 + 1) {
			if (doku(i)) {
				ans += *max_element(ALL(b[i]));
			}
			else {
				FOR(j, 0, 55440 + 1) {
					a[j] += b[i][j%i];
				}
			}
		}
		ans += *max_element(ALL(a));
		cout << ans << endl;
	}
	return 0;

}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define N 400005
using namespace std;
int n,a[N],b[N],cnt,to[N],nxt[N],fst[N],l,vis[N],Ans,s[N],s1[N];
map<int,int>Map;
void link(int x,int y)
{
	to[++l]=y;nxt[l]=fst[x];fst[x]=l;
	to[++l]=x;nxt[l]=fst[y];fst[y]=l;
}
void dfs(int x)
{
	vis[x]=0;
	for (int i=fst[x];i;i=nxt[i])
		if (vis[to[i]])dfs(to[i]);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]),a[0]^=a[i];
	for (int i=1;i<=n;i++)
		scanf("%d",&b[i]),b[0]^=b[i];
	for (int i=0;i<=n;i++)
	{
		if (!Map[a[i]]) Map[a[i]]=++cnt;
		if (!Map[b[i]]) Map[b[i]]=++cnt;
		a[i]=Map[a[i]];b[i]=Map[b[i]];
		s[a[i]]++;s1[b[i]]++;
	}
	for (int i=1;i<=cnt;i++)
		if (s[i]!=s1[i])
		{
			puts("-1");
			return 0;
		}
	for (int i=1;i<=n;i++)
		if (a[i]!=b[i])
		{
			vis[a[i]]=vis[b[i]]=1;
			link(a[i],b[i]);
			Ans++;
		}
	if (a[0]!=b[0]||a[0]==b[0]&&s[a[0]]>1) Ans--;
	for (int i=1;i<=cnt;i++)
	if (vis[i])
	{
		dfs(i);
		Ans++;
	}
	printf("%d\n",max(0,Ans));
}

Measured memory_bytes: 17536
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int a,b;
  cin>>a>>b;
  cout<<max(a,b)*2-(a!=b)<<endl;
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
if (n-2)*(n-1) < k*2:
    print(-1)
    exit()

a=(n-2)*(n-1)//2
print(n-1-k+a)
for i in range(1,n):
    print(1,i+1)

A=[]
for i in range(1,n):
    for j in range(1,i):
        A.append([i+1,j+1])
        
for i in range(a-k):
    print(*A[i])


Measured memory_bytes: 74620
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int m1, d1, m2, d2;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 != m2) cout << 1 << E;
    else cout << 0 << E;
    //system("pause");
    return 0;
}

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


def main():
    N, K = map(int, input().split())
    X = [int(c) for c in input().split()]

    def fullsearch():
        for i in range(N-K+1):
            l = X[i]
            r = X[i+K-1]
            distance = abs(r - l)
            yield distance + abs(r)
            yield distance + abs(l)

    print(min(fullsearch()))

main()

Measured memory_bytes: 14168
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int ans;
int n,m;
int a[100006];
int b[100006];
//
#define MAX_N 1000000
int par[MAX_N];
int rrankr[MAX_N];
void init(int n)
{
	rep(i,n)
	{
		par[i]=i;
		rrankr[i]=0;
	}
}
int find(int x)
{
	if(par[x]==x)return x;
	else return par[x]=find(par[x]);
}
void unite(int x,int y)
{
	x=find(x);y=find(y);
	if(x==y) return;
	if(rrankr[x]<rrankr[y])par[x]=y;
	else
	{
		par[y]=x;
		if(rrankr[x]==rrankr[y])rrankr[x]++;
	}
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
int p[100006];
vector<int> q[100006];
vector<int> r[100006];
int main()
{
	cin>>n;
	init(n);
	cin>>m;
	rep(i,n) cin>>p[i];
	rep(i,n)p[i]--;
	rep(i,m)
	{
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		unite(a[i],b[i]);
	}
	rep(x,n)
	{
		par[x]=find(par[x]);
	}
	rep(x,n)
	{
		q[par[x]].push_back(x);
		r[par[x]].push_back(p[x]);
	}
	rep(i,n)
	{
		sort(all(q[i]));
		sort(all(r[i]));
		int s,t;
		s=0;t=0;
		while(1)
		{
			if(s==q[i].size()||t==r[i].size())break;
			if(q[i][s]==r[i][t])
			{
				ans++;
				s++;t++;
			}
			else if(q[i][s]<r[i][t])
			{
				s++;
			}
			else t++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15488
def f(n):
  return (n*(n-1))//2
N=int(input())
A=list(map(int,input().split()))
d=dict()
ans=0
#それぞれが何個あるかを辞書に登録
for i in range(len(A)):
  if A[i] not in d:
    d[A[i]]=0
  d[A[i]]+=1
for i in d:
  ans+=f(d[i])
for i in range(len(A)):
  print(ans-d[A[i]]+1)

Measured memory_bytes: 25716
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int Array[n];
	for(int i=1;i<=n;i++)
		cin>>Array[i];
	int count=0;
	for(int i=2;i<=n;i++)
	{
		if(Array[i]<i&&Array[Array[i]]==i)
		count++;
	}
	cout<<count<<"\n";
}

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

using namespace std;

int a[105];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	int res = 1e9;
	
	for (int i = -100; i <= 100; i++) {
		int sum = 0;
		for (int j = 0; j < n; j++) {
			sum += (a[j] - i) * (a[j] - i);
		}
		
		res = min(res, sum);
	}
	
	printf("%d\n", res);
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC ("avx,avx2,fma")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define pb push_back
#define pp pop_back
#define f first
#define s second
#define endl "\n"
#define ll long long
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pss pair<string, string>
#define pll pair<long long, long long>

//template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void INeedIT() {ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);}

void freopen(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}


int main() {
	INeedIT();
	ll n, a, b, c, d, x;
	cin >> n >> a >> b >> c >> d;
	if (b > a + (n - 1) * d) {
		cout << "NO";
		return 0; 
	}
	for (int i = 1; i <= n; i++) {
		x = n - i - 1;
		if (a + d * i - x * c >= b && a + c * i - x * d <= b) {
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
#define MOD 1000000007;

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

    int X[N][D];

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int cnt = 0, d;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            d = 0;
            for(int k = 0; k < D; k++) d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            int a = (int)sqrt(d);
            if (a * a == d) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

from collections import Counter

s = ns()
c = Counter(s)
ans = 0

for i in c.values():
    if i%2 == 1:
        ans += 1

print(ans//2)


Measured memory_bytes: 5956
#include <bits/stdc++.h>
#define int long long
#define N 17
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
int Max(int &a,int b){return a=max(a,b);}
string Min(string &a,string b){return a=min(a,b);}
int n,K;
string his[N];

string getNx(const string &a, const string &str){
  string res;
  int j = 0,ch[26]={};
  
  for(char s:str)if(s!='?')ch[s-'A']++; 
  for(char s:str){
    if(j<K &&(a[j] == s ||(s == '?' && !ch[a[j]-'A'])))res = a[j++] + res;
    else res += s;
  }
  if(j < K) return "";
  return res;
}

string ans = "zzzzzzzz";
void dfs(int bit,string str,string ord){
  if(bit == (1<<n)-1){ans = min(ans,ord);return;}
  
  for(int i=0;i<n;i++){
    if(bit>>i&1) continue;
    string nstr = getNx(his[i],str);
    int nbit = bit | (1<<i);
    if(nstr == "") continue;
    dfs(nbit,nstr,ord+char('A'+ i));
  }
}

typedef pair<string,string> P;
string DP(){
  map<string,string> dp[1<<N]; // (key = current thread, value = min order)
  dp[0][string(n,'?')] = "";
  
  for(int bit=0;bit<(1<<n);bit++){ //used
    for(int i=0;i<n;i++){ // next use
      if(bit>>i&1)continue;
      for(P p:dp[bit]){
        int nbit = bit | (1<<i);
        string nsta = getNx(his[i],p.first);
        string norder = p.second + char('A'+i);
        if(nsta == "")continue;
        
        if(!dp[nbit].count(nsta)) dp[nbit][nsta] = norder;
        else Min(dp[nbit][nsta],norder);
      }
    }
  }
  string ans(50,'Z');
  for(P p:dp[(1<<n)-1])Min(ans,p.second);
  return ans;
}

signed main(){
  cin>>n>>K;
  for(int i=0;i<n;i++)cin>>his[i];
  //dfs(0,string(n,'?'),"");
  //cout<<ans<<endl;
  cout<<DP()<<endl;
  return 0;
}

Measured memory_bytes: 15884
using System;
using System.Collections.Generic;
using System.Linq;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = ReadString();
            var list = new List<int>();
            int count = 0;
            var acgt = new char[] {'A', 'C', 'G', 'T'};
            foreach (var c in S)
            {
                if (acgt.Contains(c)) count++;
                else
                {
                    list.Add(count);
                    count = 0;
                }
            }

            list.Add(count);

            Out(list.Max());
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }
}

Measured memory_bytes: 13268
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Grand017
{
    public class AGC017B_ModerateDifferences
    {
        public static void Main(string[] args)
        {
            
            // 入力
            int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nums[0];
            int a = nums[1];
            int b = nums[2];
            int c = nums[3];
            int d = nums[4];

            // 右端－左端の数値差
            int diff = Math.Abs(b - a);

            // 値が変化する回数
            int changeCnt = n - 1;
            
            for(int i=0; i <= changeCnt / 2; i++)
            {
                decimal plusCnt = i;
                decimal minusCnt = changeCnt - i;

                decimal minPlusNum = c * plusCnt;
                decimal maxPlusNum = d * plusCnt;
                decimal minMinusNum = c * minusCnt;
                decimal maxMinusNum = d * minusCnt;

                decimal change1 = Math.Abs(minPlusNum - minMinusNum);
                decimal change2 = Math.Abs(minPlusNum - maxMinusNum);
                decimal change3 = Math.Abs(maxPlusNum - minMinusNum);
                decimal change4 = Math.Abs(maxPlusNum - maxMinusNum);

                if( (change1 <= diff || change2 <= diff || change3 <= diff || change4 <= diff) &&
                    (change1 >= diff || change2 >= diff || change3 >= diff || change4 >= diff) )
                {
                    // 結果出力
                    Console.WriteLine("YES");
                    return;
                }

            }
            
            // 結果出力
            Console.WriteLine("NO");
        }
        

    }
}

Measured memory_bytes: 13396
sknList = [300000, 200000, 100000]

x, y = map(int, input().split())

prize = 0

if x == 1 and y == 1 :
    prize += 400000

if x <= 3 :
    prize += sknList[x - 1]

if y <= 3 :
    prize += sknList[y - 1]

print(prize)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc052/tasks/abc052_b

int main() {

    int N; cin >> N;
    string S; cin >> S;

    int count = 0;
    int ans =0;
    REP(i, N) {
        if (S[i] == 'I') {
            count++;
        }
        if (S[i] == 'D') {
            count--;
        }
        ans = max(ans, count);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
n = int(input())
List = list(map(int,input().split()))
counter = 0
min = abs(max(List))
sum = 0
for item in List:
  if item < 0:
    counter += 1
  if abs(item) <= min:
    min = abs(item)
  sum += abs(item)
if counter % 2 == 0:
  Answer = sum
else:
  Answer = sum - min*2
print(Answer)

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

int main () {
	int n;
	cin >> n;
	long long a[100000];
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	sort(a, a+n);
	long long pos[100000];
	for (int i=0; i<100000; i++) pos[i]=1000000;
	for (int i=0; i<n; i++) {
		pos[a[i]] = i;
		while (a[i] == a[i+1]) i++;
	}
	long long ans = 1;
	for (int i=0; i<n; i++) {
		ans= max(ans, max(i - pos[a[i]-1] + 1, i - pos[a[i]-2] + 1));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5144
import java.util.*;
import java.io.*;
import java.math.*;


import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;


public class Main{ 


    static long mod=1000000007;
     static int dx[]={1,-1,0,0};
      static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1}; 

public  static void main(String[] args)   throws Exception, IOException{

    
    Reader sc = new Reader(System.in);
    PrintWriter out=new PrintWriter(System.out);

//  int n=sc.nextInt();  
  // int n=sc.nextInt(), m=sc.nextInt();  
  int n=sc.nextInt();  
  long k=sc.nextLong();  
  long d[]=new long[100010],s=0,ans=0;
  for( int i=0; i<n; i++ ){
    d[sc.nextInt()]+=sc.nextInt();
  }
  for( int i=1; i<d.length; i++ ){
    s+=d[i];
    if(s>=k){
        ans=i;
        break;
    }
  }
    out.println(ans);
    out.flush();
}

static void db(Object... os){

    System.err.println(Arrays.deepToString(os));

}

static boolean validpos(int x,int y,int r, int c){
    
    return x<r && 0<=x && y<c && 0<=y;
    
}
 
static boolean bit(long x,int k){
    // weather k-th bit (from right) be one or zero
    return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
}

}

class XY {
    int x,y,d;
    XY(int x, int y, int d) {
        this.x=x;
        this.y=y;
        this.d=d;
    } 
}

class P implements Comparable<P>{
    int x,y;
    P(int x, int y) {
        this.x=x;
        this.y=y;
    } 
      
    public int compareTo(P p){
        return x - p.x;
    } 
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}



Measured memory_bytes: 44912
fun main(args: Array<String>) {
    val s = readLine()!!.toInt()
    val a = s / 100
    val b = s % 100
    if (a < 13 && a > 0) {
        if (b < 13 && b > 0) {
            println("AMBIGUOUS")
        } else  {
            println("MMYY")
        }
    }
    else {
        if (b < 13 && b > 0) {
            println("YYMM")
        } else {
            println("NA")
        }
    }

}

Measured memory_bytes: 31776
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;

int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
int ans=n%k;
ans=min(ans,k-ans);
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	string s;
	cin>>s;
	cout<<s.substr(0, 3);


    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<iostream>

#define MOD 1000000007

using namespace std;

long long x[100010];
long long y[100010];

	
int main(void) {
	long long  n, m;
	long long sumx = 0;
	long long sumy = 0;
	long long ans = 0;
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
	}

	for (int i = 1; i <= m; i++) {
		cin >> y[i];
	}

	//calculate sum of input x
	for (int i = 1; i <= n; i++) {
		sumx += ( ( (i-1) * x[i] ) % MOD - ( (n-i) * x[i] ) % MOD) ;
		sumx %= MOD;
	}

	for (int i = 1; i <= m; i++) {
		sumy += ( ( (i-1) * y[i] ) % MOD - ( (m-i) * y[i] ) % MOD);
		sumy %= MOD;
	}

	ans = ((sumx * sumy) % MOD + MOD) % MOD;

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

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

// ???????±??????????i?????¶????????????????????????????????????
int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }
int main()
{
	int H[300];
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &H[i]);

	for (int i = 1; i <= n; i++) {
		printf("node %d: key = %d, ", i, H[i]);
		if (parent(i) >= 1)
			printf("parent key = %d, ", H[parent(i)]);
		if (left(i) <= n) 
			printf("left key = %d, ", H[left(i)]);
		if (right(i) <= n)
			printf("right key = %d, ", H[right(i)]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	ll n;
	cin >> n;
	vector<ll>x(n);
	vector<ll>t(n);
	ll tA, tB;

	rep(i, n) {
		cin >> x[i];
		t[i] = x[i];
	}

	sort(allof(t));

	tA = t[n / 2 - 1];
	tB = t[n / 2];

	// x[i]が中央値より小さかったら
	rep(i, n) {
		if (x[i] <= tA) {
			cout << tB << endl;
		}
		else {
			cout << tA << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5376
def main():
	n,q = map(int,input().split())
	que = []
	for _ in range(n):
		name, time = input().split()
		que += [[name, int(time)]]
	anst = 0
	while que != []:
		temp = que.pop(0)
		if temp[1] <= q:
			anst += temp[1]
			print(f"{temp[0]} {anst}")
		else:
			anst += q
			que += [[temp[0], temp[1]-q]]

main()


Measured memory_bytes: 12892
#include<stdio.h>
#include<stdlib.h>
static long long int p = 1;
static long long int b = 2;
long long int pad(int n, long long int x){
  p = (p-1)/2;
  b = (b-3)/2;
  if(n == 0) return 1;
  else if(x == 1)return 0;
  else if(x <= b+1)return pad(n-1, x-1);
  else if(x == b+2)return p+1;
  else if(x <= 2*b+2)return p+1+pad(n-1, x-b-2);
  else return 2*p+1;
}
int main(void){
  int n;
  long long int x, t;
  scanf("%d", &n);
  scanf("%lld", &x);
  for(int i=0;i<n+1;i++){
    p *= 2;
    b *= 2;
  }
  p -= 1;
  b -= 3;
  t = pad(n, x);
  printf("%lld\n", t);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h> 
using namespace std; 
int main()
{
    long long n, i, sq;
    cin>>n;
    for(i=sqrt(n); i>0; i--)
    {
    if(n%i==0){cout<<i-1+(n/i)-1<<endl; break;}
}
return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  while(true){
	int N, R; cin >> N >> R;
	if(N == 0 && R == 0) break;
	VI card(N+1);
	REP(i,N+1)
	  card[i] = N + 1 - i;
	REP(r,R){
	  int p, c; cin >> p >> c;
	  for(int i=0;i<c;++i){
		int tmp = card[p + i];
		for(int j=p;j>=1;--j)
		  card[i+j] = card[i+j-1];
		card[i+1] = tmp;
	  }
	  //	  for(int i=1;i<=N;++i)cout<<card[i]<<endl;cout<<endl;
	}
	cout << card[1] << endl;
  }

  return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ll n,x,pow=1,cumm=-1,siz=0;
    cin>>n;
    string s;
    while(cumm+pow<n){
        cumm+=pow;
        pow*=26;
        siz++;
    }
    n-=cumm;
    n--;
    for (int i=0;i<siz;i++){
        x=n%26;
        s+=x+'a';
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 200000;
const int INF = 1e9 + 5;

int a[MAXN+5];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	
	LL ans = 0;
	int r = 0, mask = 0;
	for (int l = 0; l < N; l++) {
		while (r < N && (mask ^ a[r]) == mask + a[r]) mask ^= a[r++];
		ans += r - l;
//		cout << "For " << l << " -> " << r << "\n";
		mask ^= a[l];
	}
	
	cout << ans << "\n";
	/**** Note MAXN ****/
}


Measured memory_bytes: 1024
dishes = []
for i in range(5):
    dishes.append(int(input()))
time = 0
losstimes = []
for i in dishes:
    if not i%10 == 0:
        loss = 10-i%10
    else:
        loss = 0
    losstimes.append(loss)
losstimes.sort()
losstimes.pop(-1)
for i in range (5):
    if i < 4:
        time += losstimes[i]
    time += dishes[i]
print(time)

Measured memory_bytes: 3064
#ifndef TEMPLATE
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define mp make_pair
#define sz(a) ((int)(a).size())
#define mem(x,v) memset((x),(v),sizeof((x)));
#define A(x) (x).begin(),(x).end()
#define re(i,n) for(int i=0;i<(int)n;i++)
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define erp(i,k,n) for(int i=n;i>=k;i--)
#define input(v,n) re(i,n)cin>>v[i]
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using vvi = vector<vi>;
using tp = tuple<int,int,int>;
using pi = pair<int,int>;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)9e6;
#endif
// ===================== MANASH =================== //

int n;

void test() {

      cin >> n;
      vector<double> pro(n+1);
      re(i,n) cin >> pro[i+1];
      // Are wa Knapsack Dayo !
      vector<vector<double>> dp(n+1,vector<double>(n+1,0.0));
      dp[1][0] = (1.0-pro[1]);
      dp[1][1] = (pro[1]);
      for( int i = 2; i <= n; i++) {
            for( int j = 0; j <= i; j++) {
                  dp[i][j] = dp[i-1][j]*(1.0-pro[i]);
                  if( j > 0 ) dp[i][j] = dp[i-1][j-1]*(pro[i]) + dp[i-1][j]*(1-pro[i]);
            }
      }    
      double s = 0, t = 0;
      for( int i = 0; i <= n; i++) {
            if ( i > n-i) s += dp[n][i];
            t += dp[n][i]; 
      }

      cout << fixed << setprecision(12) << s;
}

signed main() {

      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
      int T = 1;
      //cin >> T;
      for( int tt = 1; tt <= T; tt++) {
            //cout << "Case #" << tt << " ";
            test();
            cout << "\n";
      }
      return 0;

}

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

using namespace std;

const int N = 1e5 + 5;
string s, t;
int ps[N], pt[N], n, m, q;

main() {
	
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s >> t;
	n = s.size(); m = t.size(); 
	s = ' ' + s;
	for(int i = 1; i <= n; ++i) {
		int tmp = 1;
		if(s[i] == 'B') tmp++;
	 	ps[i] = ps[i - 1] + tmp;
	}
	t = ' ' + t;
	for(int i = 1; i <= m; ++i) {
		int tmp = 1;
		if(t[i] == 'B') tmp++;
		pt[i] = pt[i - 1] + tmp;
	}
	cin >> q;
	while(q--) {
		int x, y, u, v;
		cin >> x >> y >> u >> v;
		if((ps[y]-ps[x - 1]) % 3 == (pt[v]-pt[u - 1]) % 3) cout << "YES\n";
		else cout << "NO\n";
	}
}

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

int main() {
    int A, B, X;
    cin >> A >> B >> X;

    string ans;

    if ((X <= A + B) && (A <= X)) {
        ans = "YES";
    } else {
        ans = "NO";
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

unordered_map<string,bool> dp;
bool solve(string s) {
    if(EXIST(dp,s)) return dp[s];
    if(s=="") return dp[s]=true;
    int n=SZ(s);
    if(s[0]!='m'||s[n-1]!='w') return dp[s]=false;
    REP(i,n) {
        if(s[i]=='e') {
            if(solve(s.substr(1,i-1)) and solve(s.substr(i+1,n-i-2))) {
                return dp[s]=true;
            }
        }
    }
    return dp[s]=false;
}
signed main() {
    string s;
    cin>>s;
    cout<<(solve(s)?"Cat":"Rabbit")<<endl;
    return 0;
}

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

char ss[1010];
char tt[1010];
char*s,*t;
int ans[1010];
int tn;

void f(char*s){
	//この位置からtを引く
	for(int i=0;i<tn;i++)s[i]-=t[i]-'0';
	for(int i=tn-1;i>=0;i--)if(s[i]<'0')s[i]+=10,s[i-1]--;
}

int main(){
	scanf("%s %s",ss,tt);
	int sm=(ss[0]=='-'),tm=(tt[0]=='-');
	s=ss+sm,t=tt+tm;
	tn=strlen(t);
	while(1){
		int sn=strlen(s);
		if(sn<tn)break;
		if(sn==tn){
			if(strcmp(s,t)<0)break;
			f(s);
			ans[sn-tn]++;
		}else{
			int flag=strcmp(s,t)<0;
			f(s+flag);
			ans[sn-tn-flag]++;
		}
		while(*s=='0')s++;
	}
	puts(*s?s:"0");
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s; cin>>s;
    int a=0,b=0;
    rep(i,0,3){
        if(s[i]=='A')a=1;
        if(s[i]=='B')b=1;
    }
    if(a==1&&b==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256