akhauriyash/Code-Regression huggingface dataset:
// ABC080B - Harshad Number

#include <bits/stdc++.h>
using namespace std;

int SumOfDigits(int n) {
	int ans = 0;

	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}

	return ans;
}

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

	int fx = SumOfDigits(N);

	if (N % fx == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N = int(input())

ACcount = 0 
WAcount = 0
TLEcount = 0
REcount = 0
for i in range(N):
	S=input()

	if S == "AC":
		ACcount = ACcount + 1
	elif S == "WA":
		WAcount = WAcount + 1
	elif S == "TLE":
		TLEcount = TLEcount + 1
	elif S == "RE":
		REcount = REcount + 1

print("AC x", ACcount)
print("WA x", WAcount)
print("TLE x", TLEcount)
print("RE x", REcount)

Measured memory_bytes: 9180
import java.util.*;
import static java.lang.System.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        String s=sc.next();
        s=s.replace("9","-");
        s=s.replace("1","9");
        s=s.replace("-","1");
        out.println(s);
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll R;
  cin >> R;
  if (2800 <= R) {
    cout << "AGC" << endl;
  } else if (1200 <= R && R < 2800) {
    cout << "ARC" << endl;
  } else if (R < 1200) {
    cout << "ABC" << endl;
  }
  return 0;
}

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


long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  int T,N,k;
  long long int total;
  cin >> T;
  for(int t=0;t<T;t++){
    total=0;
    cin >> N;
    long long int l,r;
    vector<long long int> Ph[N],Pt[N];
    priority_queue<long long int, vector<long long int>, greater<long long int>> H;
    priority_queue<long long int, vector<long long int>, greater<long long int>> T;
    for(int n=0;n<N;n++){
      cin >> k >> l >> r;
      k = k-1;
      if(l>r){
        Ph[k].push_back(l-r);
        total = total +r;
      }else{
        Pt[k].push_back(r-l);
        total = total + l;
      }
    }
    for(int i=0;i<N;i++){
      for(int j:Ph[i]){
        H.push(j);
      }
      while(H.size()>i+1){
        H.pop();
      }
    }
    for(int i=0;i<N;i++){
      for(int j:Pt[N-1-i]){
        T.push(j);
      }
      while(T.size()>i){
        T.pop();
      }
    }
    while(!H.empty()){
      total = total + H.top();
      //cout << H.top() <<endl;
      H.pop();
    }
    while(!T.empty()){
      total = total + T.top();
      //cout << T.top() <<endl;
      T.pop();
    }
    cout << total <<endl;
  }
  
  return 0;
}


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 19720
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w, n, a, b, tmp;
		String[] s;
		int[] table;
		while(sc.hasNext()){
			w = sc.nextInt();
			table = new int[w + 1];
			for(int i = 0; i <= w; i++){
				table[i] = i;
			}
			n = sc.nextInt();
			for(int i = 0; i < n; i++){
				s = sc.next().split(",");
				a = Integer.parseInt(s[0]);
				b = Integer.parseInt(s[1]);
				tmp = table[a];
				table[a] = table[b];
				table[b] = tmp;
			}
			
			for(int i = 1; i <= w; i++){ 
				System.out.println(table[i]);
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}
int main(){
    CIN(N);
    LL ans = 0;
    REP(a,N){
        CIN(b);
        if(is_prime(b))ans++;
    }
    COUT(ans);
    return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
typedef long double ll;
int main(void){
  int n;
  cin >> n;
  int closs = n * (n - 3) / 2;
  int a[n][2];
  for(int i = 0; i < n; i++){
      for(int j = 0; j< 2; j++){
          cin >> a[i][j];
      }
  }
  vector <ll> b(n+closs);
  
  int count = 0;
  for(int i = 0; i< n; i++){
      for(int j = i+1; j < n; j++){
          ll x, y, k;
          x = abs(a[i][0] - a[j][0]) * abs(a[i][0] - a[j][0]);
          y = abs(a[i][1] - a[j][1]) * abs(a[i][1] - a[j][1]);
          
          k = sqrt(x+y);
          b[count] = k;
          count++;
      }
  }
  ll ans = 0;
  for(int i = 0; i < b.size(); i++){
      ans += b[i];
  }
  ll z = b.size();
  ll v = (n-1);
  ans = ans / z * v ;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long x){
    const ll M = 2 * N - 1;
    if(x == 1 || x == M){
        cout << NO << endl;
        return;
    }

    x--;
    vector<ll> ans(M, -1);
    set<ll> rest;
    REP(i, M){ rest.insert(i); }
    ans.at(M / 2) = x;
    rest.erase(x);
    ans.at(M / 2 + 1) = x + 1;
    rest.erase(x + 1);
    ans.at(M / 2 - 1) = x - 1;
    rest.erase(x - 1);
    if(M > 3){
        if(x - 2 >= 0){
            ans.at(M / 2 + 2) = x - 2;
            rest.erase(x - 2);
        }else{
            ans.at(M / 2 - 2) = x + 2;
            rest.erase(x + 2);
        }
    }
    REP(i, M){
        if(ans.at(i) == -1){
            ans.at(i) = *rest.begin();
            rest.erase(rest.begin());
        }
    }

    cout << YES << endl;
    REP(i, M){
        cout << ans.at(i) + 1 << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long x;
    scanf("%lld",&x);
    solve(N, x);
    return 0;
}


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

int main() {
    int N;
    cin >> N;
	vector <int> A(N);
	for (int i=0; i<N; i++) cin >> A[i];
	vector <int> cnt(1000005);
	for (int x:A){
	    if (cnt[x]!=0){
	        cnt[x]=2;
	        continue;
	    }
	    for (int j=x; j<1000005; j+=x){
	        cnt[j]++;
	    }
	}
	int count=0;
	for (int x: A){
	    if (cnt[x]==1){
	        count++;
	    }
	}
	cout << count << endl;
	return 0;
}

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

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

    int count = 0;

    for(int i = 0; i <= 25; i++)
    {
        for(int j = 0; j < 15; j++)
        {
            if(4*i + 7*j == N)count++;
        }
    }

    if(count >= 1)cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

using namespace std;

const int mod = 998244353;

int dp[200000][3][4][2];

int main() {
  string S;
  cin >> S;

  int sum = 0;
  int match = 0;
  for(int i = 1; i < S.size(); i++) {
    if(S[i - 1] == S[i]) ++match;
  }
  for(int i = 0; i < S.size(); i++) {
    sum += (S[i] - 'a') % 3;
  }

  if(match + 1 == S.size()) {
    cout << 1 << endl;
    return 0;
  }

  if(S.size() < 10) {
    queue< string > que;
    set< string > used;
    que.emplace(S);
    used.emplace(S);
    string tmp = "abc";
    while(que.size()) {
      string p = que.front();
      que.pop();
      for(int i = 1; i < p.size(); i++) {
        if(p[i - 1] != p[i]) {
          for(int j = 0; j < 3; j++) {
            if(p[i - 1] == tmp[j]) continue;
            if(p[i] == tmp[j]) continue;
            string q = p;
            q[i - 1] = tmp[j];
            q[i] = tmp[j];
            if(used.count(q)) continue;
            used.emplace(q);
            que.emplace(q);
          }
        }
      }
    }
    cout << used.size() << endl;
    return 0;
  }

  dp[0][0][3][0] = 1;
  for(int i = 0; i < S.size(); i++) {
    for(int j = 0; j < 3; j++) {
      for(int k = 0; k < 4; k++) {
        for(int l = 0; l < 2; l++) {
          if(dp[i][j][k][l] == 0) continue;
          for(int m = 0; m < 3; m++) {
            (dp[i + 1][(j + m) % 3][m][l | (k == m)] += dp[i][j][k][l]) %= mod;
          }
        }
      }
    }
  }
  int ans = 0;
  for(int i = 0; i < 3; i++) {
    (ans += dp[S.size()][sum % 3][i][1]) %= mod;
  }
  if(match == 0) (ans += 1) %= mod;
  cout << ans << endl;
}

Measured memory_bytes: 19332
n,k = [int(x) for x in input().split()]
a = [list(map(int, list(bin(int(x))[2:]))) for x in input().split()]
b = list(map(int, list(bin(k)[2:])))
m = len(b)
for i in a:
    m = max(m,len(i))
for j in range(m-len(b)):
    b.insert(0,0)
s = [n]*m
for i in a:
    k = m-len(i)
    for j in range(len(i)):
        if i[j]:
            s[k+j] -= 1
dp = [[0 for i in range(2)] for k in range(m)]
dp[-1][1] = -float("inf")
f = [1<<(m-i-1) for i in range(m)]
for i in range(m):
    for j in range(2):
        x = 1 if j else b[i]
        for d in range(x+1):
            j_ = j | (d < b[i])
            k = dp[i-1][j]+f[i]*(s[i]*d+(n-s[i])*(1-d))
            if k > dp[i][j_]:
                dp[i][j_] = k
print(max(dp[m-1]))


Measured memory_bytes: 118872
d, n = map(int, raw_input().split())
if d == 0:
	if n == 100:
		print 101
	else:
		print n
elif d == 1:
	if n != 100:
		print n * 100
	else:
		print 10100
else:
	if n != 100:
		print n * 10000
	else:
		print 1010000

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

using namespace std;

const int MAXN = 101;
const int MAXW = 100000 + 1;

int N,W;
long long int memo[MAXN][MAXW];
pair <long long int,long long int> items[MAXN];

long long int dp(int i, int w){
	if(i == N)return 0;
	if(memo[i][w] != -1)return memo[i][w];
	long long int r1 = dp(i + 1,w);
	long long int r2 = 0;
	if(w + items[i].first <= W){
		r2 = dp(i + 1,w + items[i].first) + items[i].second;
	}
	return memo[i][w] = max(r1,r2);
}

int main(){
	#ifdef EVAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	cin >> N >> W;
	for(int i = 0; i < N; i++){
		cin >> items[i].first >> items[i].second;
	}
	memset(memo,-1,sizeof(memo));
	cout << dp(0,0);
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define SZ(a) int((a).size())
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n;
    scanf("%d", &n);
    string t;
    for (int i=0;i<int(s.size());i+=n) t.push_back(s[i]);
    cout << t << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc_058_A
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            Console.WriteLine(a[1]-a[0]==a[2]-a[1]?"YES":"NO");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define PUTS(x) cout << (x) << endl;
#define MOD 1000000007
int main() {
    Int n;
    cin >> n;
    Int v[3] = {0};
    Int ans = 1;
    rep(i, n) {
        Int a;
        cin >> a;
        int c = 0;
        int index = -1;
        rep(j, 3) {
            if (v[j] == a) {
                c++;
                index = j;
            }
        }
        if (c == 0) {
            puts("0");
            return 0;
        }
        ans *= c;
        ans %= MOD;
        v[index]++;
    }
    PUTS(ans)
}


Measured memory_bytes: 256
fn solve(s: &str) -> usize {
    let s = s.chars().collect::<Vec<_>>();

    let mut ans = 0;
    for i in 0..(s.len() / 2) {
        if s[i] != s[s.len() - 1 - i] {
            ans += 1;
        }
    }

    ans
}

#[test]
fn solve_test() {
    assert_eq!(solve("redcoder"), 1);
    assert_eq!(solve("vvvvv"), 0);
    assert_eq!(solve("vvvvvv"), 0);
    assert_eq!(solve("abcabc"), 2);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let s = read_line!();
    println!("{}", solve(&s));
}


Measured memory_bytes: 4352
S = list(input())

length = len(S)

while True:
    length -= 2
    half = length // 2
    if S[0] == S[half]:
        cnt = 0
        for i in range(half):
            if S[i] != S[half + i]:
                break
            cnt += 1
        
        if cnt == half:
            print(length)
            exit()

Measured memory_bytes: 3060
N = int(input())
A = [int(x) for x in input().split()]
minux_count = 0
minimum_abs = 10**9+1
if_zero_exists = False
for a in A:
    if a < 0:
        minux_count += 1
    if a == 0:
        if_zero_exists = True
    if abs(a) < minimum_abs:
        minimum_abs = abs(a)

answer = 0
for a in A:
    answer += abs(a)

if if_zero_exists or minux_count % 2 == 0:
    print(answer)
else:
    print(answer - 2*minimum_abs)


Measured memory_bytes: 14412
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, A, B; 
	cin >> N >> A >> B; 
	string S; 
	cin >> S; 
	int I = 0; int T = 0; 
	for(int i = 0; i < N; i++){
		if(S.at(i) == 'a'){
			if(T < A + B){
				cout << "Yes" << endl; 
				T ++; 
			}	
			else{
				cout << "No" << endl; 
			}
		}
		else if(S.at(i) == 'b'){
			if(T < A + B && I < B){
				cout << "Yes" << endl;
				T ++; I ++; 
			}
			else{
				cout << "No" << endl; 
			}
		}
		else if(S.at(i) == 'c'){
			cout << "No" << endl; 
		}
	}
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans;
    if(a==b){
        ans = c;
    }else if(b==c){
        ans = a;
    }else{
        ans = b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// Your day breaks, your mind aches
// You find that all the words of kindness linger on
// When she no longer needs you
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
#define debug(x) cout << #x << " = " << x << endl
#define For(i,a,b) for (int i = a; i < b; i++)
#define roF(i,a,b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int N = 1e6;
const ll INF = 1e18;
const ld EPS = 10e-9;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll a, ll b) { return uniform_int_distribution<ll> (a, b) (rng); }

int main() {
	fastio;
	ll a, b;
	cin >> a >> b;
	ll ans = a * b / __gcd(a, b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)(r); i++)

int main(){
    ll N; cin >> N;
    ll sum = 0;
    vector<ll> a(N);
    rep(i,0,N){
        cin >> a[i];
        sum ^= a[i];
    }
    rep(i,0,N){
        cout << (sum^a[i]) << " " ;
    }
    cout<< endl;
}


Measured memory_bytes: 4764
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    assert_eq!(!0usize, std::usize::MAX); //🙊
    let mut s = io.chars();

    for i in 0..19 {
        match i {
            5 | 13 => io.write(" "),
            _ => io.write(s[i]),
        }
    }
}

static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


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

using namespace std;

const double eps = 1e-10;

class Point {
    public:
        double x, y;
        Point(double x = 0.0, double y = 0.0): x(x), y(y) {}

        Point operator + (Point p) { return Point(x + p.x, y + p.y); }
        Point operator - (Point p) { return Point(x - p.x, y - p.y); }
        Point operator * (double k) { return Point(x * k, y * k); }
        Point operator / (double k) { return Point(x / k, y / k); }

        double friend norm(Point p) { return p.x * p.x + p.y * p.y; }
        double friend abs(Point p) { return sqrt(norm(p)); }
        double friend dot(Point p1, Point p2) { return p1.x * p2.x + p1.y * p2.y; }
};
typedef Point Vector;
struct Segment {
    Point p1, p2;
};

Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / norm(base);
    return s.p1 + base * r;
}

int main(void) {
    int x, y, q;
    Segment s;
    Point p, ans;

    cin >> x >> y;
    s.p1 = Point(x, y);
    cin >> x >> y;
    s.p2 = Point(x, y);

    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        p = Point(x, y);
        
        ans = project(s, p);
        printf("%.10f %.10f\n", ans.x, ans.y);
    }

    return 0;
}


Measured memory_bytes: 3232
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------

ll N;
ll A[101010];

long long gcd(long long a, long long b) {
  if (b == 0) return a;

  return gcd(b, a % b);
}

long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

ll cgcd[101010], rcgcd[101010];

int main() {
  cin >> N;
  rep(i, 0, N) { cin >> A[i]; }
  cgcd[0] = A[0];
  rep(i, 1, N) { cgcd[i] = gcd(cgcd[i - 1], A[i]); }
  rcgcd[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; --i) {
    rcgcd[i] = gcd(rcgcd[i + 1], A[i]);
  }

  ll ans = max(cgcd[N - 2], rcgcd[1]);
  for (int i = 1; i < N - 1; ++i) {
    chmax(ans, gcd(cgcd[i - 1], rcgcd[i + 1]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
# coding: utf-8
r=list('mcxi')
m=r[::-1]
n=int(input())
for i in range(n):
    a,b=input().split()
    x=int(''.join(['0' if len(a.split(c))==1 else '1' if a.split(c)[0]=='' or a.split(c)[0][-1] in 'mcxi' else a.split(c)[0][-1] for c in r]))
    y=int(''.join(['0' if len(b.split(c))==1 else '1' if b.split(c)[0]=='' or b.split(c)[0][-1] in 'mcxi' else b.split(c)[0][-1] for c in r]))
    ans=str(x+y)[::-1]
    s=''
    for j in range(len(ans)):
        if(ans[j]!='0'):
            s+=m[j]+(ans[j] if ans[j]!='1' else '')
    print(s[::-1])
    


Measured memory_bytes: 5624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long N = sc.nextLong();
		int sqrtn = (int) Math.sqrt(N);
		long a = 0;

		for (long i = 1; i <= sqrtn;) {
			if (N % i == 0) {
				a = i;
			}
			i++;
		}

		long ans = Math.max(a, N / a);
		int len = String.valueOf(ans).length();

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


Measured memory_bytes: 21844
def main():
    n,m = map(int,input().split())
    a_s = list(map(int,input().split()))
    a_s.sort()
    for a in a_s:
        n -= a

    if n < 0:
        print(-1)
    else:
        print(n)

if __name__ == '__main__':
    main()


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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPE(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a > b) a = b; }
template<class T> void chmin(T& a, T b) { if(a < b) b = a; }
typedef long long ll;

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

    for(int i = x; i > 1; i--){
        for(int j = 2; j * j <= i; j++){
            int tmp = i;
            if(tmp % j != 0) continue;
            while(tmp % j == 0){
                tmp /= j;
            }
            if(tmp != 1){
                continue;
            }else{
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}	    
signed main(){
// __builtin_ctz(N);      Nを２で何回割り切れるかを返す
//(n+1)*n/2;              １からNまでの総和を求める式
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d)<<"\n";
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String args[]) {
		FastScanner in=new FastScanner();
		int n=in.nextInt();
		HashMap<Integer, Integer> hmap1=new HashMap<>();
		HashMap<Integer, Integer> hmap2=new HashMap<>();
		boolean chk=false;
		int ctr=0;
		for(int i=0;i<n;i++) {
			int x=in.nextInt();
			int y=in.nextInt();
			if(x==y) {
				ctr++;
			}
			else {
				ctr=0;
			}
			
			if(ctr==3 && !chk) {
				System.out.println("Yes");
				chk=true;
			}
		}
		if(!chk)
		System.out.println("No");
	}

	///////////////////////////
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 32908
N = int(input())

B = [int(a) for a in input().split() ]

result = B[N-2]
old = B[N-2]
for i in range(N-3,-1,-1):
    #print(min(B[i],old))
    result = result + min(B[i],old)
    old  = B[i]


result = result + B[0]

print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
char sre[112212];
int main(){
    scanf("%s",sre);
    if(sre[0]=='Y'&&sre[1]=='A'&&sre[2]=='K'&&sre[3]=='I'){
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int s=0,n,m,i;cin>>n>>m;
for(i=0;i<m;i++)
{
	int a;cin>>a;
	s+=a;
}
if(s<=n) cout<<n-s;
else cout<<-1;


return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,q;
	while(cin >> n >> q,n){
		map<string,pair<int,int> > era;
		REP(i,n){
			string s;
			int x,y;
			cin >> s >> x >> y;
			era[s] = make_pair(x,y);
		}
		REP(i,q){
			int year;
			string ans = "Unknown";
			cin >> year;
			for(auto itr = era.begin(); itr != era.end();++itr){
				if(itr->second.second >= year && itr->second.second - itr->second.first < year){
					ans = itr->first + ' ' + to_string((year - itr->second.second + itr->second.first));
				}
			}
			cout << ans << endl;
		}
	}
  return 0;
}

Measured memory_bytes: 3256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, z = 0;
    string s;
    map<string, int> m;
    cin >> n;
    while (n--) cin >> s, m[s]++;
    for (auto i : m) z = max(z, i.second);
    for (auto i : m) if (i.second == z) cout << i.first << '\n';
}


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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = ((result%MOD) * (x%MOD))%MOD;
        n = n / 2;
        x = ((x%MOD) * (x%MOD))%MOD;
    }
    return result;
}

// Solution Function
void solution()
{
    // cout<<compte<<"\n";
   ll n;
    cin>>n;
    ll x,y;
    vector<ll> v1,v2;
    for(ll i=0;i<n;i++)
    {
        cin>>x>>y;
        v1.pb(x+y);
        v2.pb(x-y);
    }
    sort(all(v1));
    sort(all(v2));
    ll c1=abs(v1[0]-v1[n-1]);
    ll c2=abs(v2[0]-v2[n-1]);
    cout<<max(c1,c2);
    
}

// Driver Function
int main()
{
    //test()
    //{
        solution();
    //}
    return 0;
}


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

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

    // 高さが全部 0 になるまでやる
    int res = 0;
    while (true) {
        // 最高高さが 0 だったらおしまい
        if (*max_element(h.begin(), h.end()) == 0) break;
        
       int i=0;
       while(i<N){
       		if(h[i]==0)++i;
       		else{
       			res++;
       			while(i<N && h[i]>0){
       				h[i]--;
       				i++;
       			}
       		}
       }
    }
    cout << res << endl;
}

Measured memory_bytes: 3584
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

m = sum(a)
s = set()
i = 1
while i * i <= m:
    if m % i == 0:
        s |= set([i, m // i])
    i += 1

ans = 0
for i in s:
    b = [j % i for j in a]
    b.sort()
    c = [0]
    for j in b:
        c.append(c[-1] + j)
    d = [0]
    for j in reversed(b):
        d.append(d[-1] + (i-j))
    d = list(reversed(d))

    for j in range(n+1):
        if (c[j] - d[j]) % i == 0:
            if max(c[j], d[j]) <= k:
                ans = max(ans, i)
print(ans)


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


int N, A;
ll dp[55][55][2505];

void solve() {
    cin >> N >> A;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    dp[0][0][0] = 1;
    rep(i, N){
        Rep1(j, 0, i){
            rep(k, 2505){
                dp[i+1][j][k] += dp[i][j][k];
                if(k - a[i] >= 0){
                    dp[i+1][j+1][k] += dp[i][j][k-a[i]];
                }
            }
        }
    }
    ll res = 0;
    rep1(j, 50){
        rep(k, 2505){
            if(k/j == A && k%j == 0) res += dp[N][j][k];
        }
    }
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 59520
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    char aa[10],bb[10];
    cin>>a>>b;
    for(int i=0;i<a;i++)
        bb[i]='0'+b;
        bb[a]='\0';
    for(int i=0;i<b;i++)
        aa[i]='0'+a;
        aa[b]='\0';
    if(strcmp(aa,bb)>0)
        cout<<bb;
    else
        cout<<aa;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
int n,i,j,x,a[10][10],list[200][3],size;
void push(int x,int y,int s){list[size][0]=i;list[size][1]=j;list[size][2]=s;size++;}

int check(int x,int y,int s){
	int d;
	if(s<3 && (x<1 || x>9 || y<1 || y>9)) return 0;
	if(s==3 && (x<2 || x>8 || y<2 || y>8)) return 0;
	d=a[x][y];
	if(a[x-1][y]<d)d=a[x-1][y];
	if(a[x+1][y]<d)d=a[x+1][y];
	if(a[x][y-1]<d)d=a[x][y-1];
	if(a[x][y+1]<d)d=a[x][y+1];
	if(s==1 || d==0)return d;
	if(a[x-1][y-1]<d)d=a[x-1][y-1];
	if(a[x+1][y+1]<d)d=a[x+1][y+1];
	if(a[x+1][y-1]<d)d=a[x+1][y-1];
	if(a[x-1][y+1]<d)d=a[x-1][y+1];
	if(s==2 || d==0)return d;
	if(a[x-2][y]<d)d=a[x-2][y];
	if(a[x+2][y]<d)d=a[x+2][y];
	if(a[x][y-2]<d)d=a[x][y-2];
	if(a[x][y+2]<d)d=a[x][y+2];
	return d;
}

void draw(int x,int y,int s,int d){
	if(size==3 && (x<2 || x>8 || y<2 || y>8)) return;
	a[x][y]+=d;
	a[x-1][y]+=d;
	a[x+1][y]+=d;
	a[x][y-1]+=d;
	a[x][y+1]+=d;
	if(s==1)return;
	a[x-1][y-1]+=d;
	a[x+1][y+1]+=d;
	a[x+1][y-1]+=d;
	a[x-1][y+1]+=d;
	if(s==2)return;
	a[x-2][y]+=d;
	a[x+2][y]+=d;
	a[x][y-2]+=d;
	a[x][y+2]+=d;
}

int search(int nn,int from){
	int i,x,y,s,t;
	for(i=from;i>=0;i--){
		x=list[i][0];y=list[i][1];s=list[i][2];
		if(x<8){if(s<3 && a[x+2][y]>0)return 0;}
		t=check(x,y,s);
		if(t>0){
			draw(x,y,s,-t);
			for(;t>0;t--){
				if(s==1 && a[x+1][y+1]>0 && check(x-1,y+1,3)==0){draw(x,y,s,+1); if(t>1)continue; else return 0;}
				if(nn-t>0){
					if(search(nn-t,i-1)>0){goto answer;}
				}else{
					int p,q;
					for(p=0;p<10;p++)for(q=0;q<10;q++){{if(a[p][q]!=0)goto miss;}}
					goto answer;
					miss:;
				}
				draw(x,y,s,+1);
			}
		}
	}
	return 0;

	answer:
	for(;t>0;t--)printf("%d %d %d\n",y,x,s);
	return 1;
}

int main(void){
	scanf("%d",&n);size=0;
	for(i=0;i<10;i++){for(j=0;j<10;j++){scanf("%d",&a[i][j]);}}
	for(i=1;i<9;i++){
		for(j=1;j<9;j++){
			x=check(i,j,1); if(x==0)continue; push(i,j,1);
			x=check(i,j,2); if(x==0)continue; push(i,j,2);
			x=check(i,j,3); if(x==0)continue; push(i,j,3);
		}
	}
	search(n,size-1);
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
    int world[26]={};
    int i,flage;
    char c;
    memset(world,0,sizeof(world));
    while (scanf("%c",&c)!=EOF)
    {
        if (c>='a'&&c<='z')
        {
            i=c-'a';
            world[i]++;
        }
        else
        {
            flage=0;
            for (i=0;i<26;i++)
            {
                if (world[i]==0)
                {
                    printf("%c",'a'+i);
                    flage=1;
                    break;
                }
            }
            if (flage==0)
                printf("None");
            printf("\n");
            memset(world,0,sizeof(world));
        }
    }
    return 0;
}

Measured memory_bytes: 256
N,C,K= list(map(int,input().split(" ")))

ans = 1
passed = 0
nums = [ int(input()) for _ in range(N)]
nums.sort()
before = nums[0]
c = 1

for t in nums[1:]:

    c += 1
    passed += t - before
    if passed > K or c > C: #次のバス
        c = 1
        passed = 0
        ans += 1
    before = t
print(ans)




Measured memory_bytes: 7888
#include <stdio.h>
#include <stdlib.h>


typedef struct data_t{
	int num;
	struct data_t *next;
}DATA_T;


int main()
{
	char in_str[256];
	DATA_T *pointer;
	DATA_T *bk_p, *bk_p2;
	DATA_T yamafuda;	// 山札を指す変数
	int n;			// 札の枚数
	int r;			// カット操作回数
	int p, c;		// p枚目の札からc枚を一番上に持ってくる
	int count, i, j;

	while(1){
		// 枚数とカット回数の入力
		fgets(in_str, sizeof(in_str), stdin);
		sscanf(in_str, "%d %d", &n, &r);

		if(n == 0 && r == 0)
			break;

		yamafuda.num = 0;
		yamafuda.next = NULL;
		for(i = 0; i < n; i++){
			if( (pointer = (DATA_T *)malloc(sizeof(DATA_T))) == NULL){
				printf("malloc error\n");
				exit(1);
			}
			pointer->num = i + 1;
			pointer->next = yamafuda.next;
			yamafuda.next = pointer;
		}

		// カット操作
		for(i = 0; i < r; i++){
			fgets(in_str, sizeof(in_str), stdin);
			sscanf(in_str, "%d %d", &p, &c);

			// 先頭を先頭に持ってこようとするとバグる
			if(p == 1)
				continue;

			/* 山札のてっぺんに持ってくる*/
			// 交換し始めの前の場所のポインタを求める
			count = 1;
			for(pointer = &yamafuda; count != p; pointer = pointer->next)
				count++;
			bk_p = pointer;

			// 交換し終わりの場所の次のポインタを求める
			count = 1;
			for(pointer = pointer->next; count != c; pointer = pointer->next)
				count++;
			bk_p2 = pointer->next;

			// 交換
			pointer->next = yamafuda.next;
			yamafuda.next = bk_p->next;
			bk_p->next = bk_p2;
		}

		printf("%d\n", yamafuda.next->num);
	}

	return 0;
}


Measured memory_bytes: 2040
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

int main()
{
    ll m,d,i,j,k=0;
    cin>>m>>d;
    rep(i,1,m)
    {
        rep(j,1,d)
        {
            ll dx[2];
            dx[0]=j%10;
            dx[1]=j/10;
            if(dx[0]>=2 && dx[1]>=2 && (dx[1]*dx[0])==i)
                k++;
        }
    }
    cout<<k;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
struct UnionFind{
    vector<int> par,sizes;
    UnionFind(int n):par(n+1),sizes(n+1,1){
        rep2(i,1,n)par[i]=i;
    }
    int find(int x){
        return (x==par[x]?x:par[x]=find(par[x]));
    }
    bool unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return false;
        if(sizes[x]<sizes[y]){
            swap(x,y);
        }
        par[y]=x;
        sizes[x]+=sizes[y];
        return true;
    }
    bool same(int x,int y) {return (find(x)==find(y));}
    int size(int x) {return sizes[find(x)];}
};
main(){
    int m=in(),k=in();
    int t=1<<m;
    t--;
    vector<int> used(N);
    int f=0;
    vec v1,v2;
    if(m==0){
        if(k==0){
            cout<<0<<" "<<0;
        }
        else cout<<-1;
        return 0;
    }
    if(m==1){
        if(k==0)cout<<"0 0 1 1";
        else cout<<-1;
        return 0;
    }
    if(k==0){
        rep(i,t+1){
            cout<<i<<" "<<i<<" ";
        }
        return 0;
    }
    if(k>t)cout<<-1;
    else{
        rep(i,t+1){
            if(used[i])continue;
            else{
                used[i]=1;
                int j=k^i;
                used[j]=1;
                if(f){
                    v1.pb(i);v1.pb(j);
                    v1.pb(j);v1.pb(i);
                }
                else{
                    v2.pb(i);v2.pb(j);
                    v2.pb(j);v2.pb(i);
                }
                f=1-f;
            }
        }
        rep(i,(t+1)/2){
            cout<<v1[i*2]<<" "<<v1[i*2+1]<<" ";
            cout<<v2[i*2]<<" "<<v2[i*2+1]<<" ";
        }
    }
    
}



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

using namespace std;
using uint = unsigned int;
using int64 = long long;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
#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
#define eb emplace_back
#define all(x) x.begin(),x.end()

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

template<class T, class U> ostream& operator<<(ostream& os, const vector<pair<T, U>> p) {
	os << "P(" << p.first << ", " << p.second << endl;
}

/*
template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << P << " ";
	return os << "}";
}
*/

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Insert from here! */
/* Cut from here! */

void Main() {
	vector<int> ans(4);
	vector<int> table{ 0,6000,4000,3000,2000 };
	rep(i, 4) {
		int t, n; cin >> t >> n;
		ans[i] = table[t] * n;
	}
	rep(i, 4) {
		cout << ans[i]<<endl;
	}
}


Measured memory_bytes: 3224
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    long long ans=0;
    rep(i,n)
    {
        auto itrc=upper_bound(c.begin(),c.end(),b[i]);
        auto itra=lower_bound(a.begin(),a.end(),b[i]);
        ans+=(itra-a.begin())*(c.end()-itrc);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2040
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define int long long int
int function2(int memo[],int turn[],int n,map<int,int> &sticks)
{
	if(n<0)
	{
		return -1000000000;
	}
	if(n==0)
	{
		return 0;
	}
	if(memo[n]!=-1)
	{
		return memo[n];
	}
	else
	{
		map<int,set<int>> mp;
		int here=-1000000000;
		mp[here].insert(-1);
		for(auto &p:sticks)
		{
			int val=1+function2(memo,turn,n-p.second,sticks);
			mp[val].insert(p.first);
		}
		auto it=mp.end();
		it--;
		int answer=*it->second.rbegin();
		turn[n]=answer;
		memo[n]=it->first;
		return it->first;
	}
}
int32_t main()
{
	int answer=0;
	int n;
	cin>>n;
	int j;
	for(j=0;j<n;j++)
	{
		int x;
		cin>>x;
		answer=__gcd(answer,x);
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 3572