akhauriyash/Code-Regression huggingface dataset:
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
vector<int> adj[N];
int n, sz[N];

void dfs(int u, int par) {
	sz[u] = 1;
	int cnt = 0;
	for (auto v: adj[u])
		if (v ^ par) {
			dfs(v, u);
			sz[u] += sz[v];
			cnt += sz[v] & 1;
		}
	if (cnt > 1) {
		cout << "First\n";
		exit(0);
	}
}

inline void readInput() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;

		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
}

inline void solve() {
	dfs(0, 0);
	cout << (n & 1? "First\n": "Second\n");
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


Measured memory_bytes: 6144
#include<iostream>
using namespace std;
const int maxn=3005;
int dp[maxn][maxn];
int cal[maxn][maxn];
string a,b;

void dfs(int i,int j)
{
	if(i==0||j==0)
	 return ;
	else if(cal[i][j]==1)
	 dfs(i-1,j);
	else if(cal[i][j]==2)
	 dfs(i,j-1);
	else
	{
		dfs(i-1,j-1);
		cout<<a[i-1];
	} 
}
int main()
{
		cin>>a>>b;
		int n=a.length(),m=b.length();
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=m;++j)
			{
				if(a[i-1]==b[j-1])
				{
					dp[i][j]=dp[i-1][j-1]+1;
					cal[i][j]=3;
				}
				else if(dp[i-1][j]>=dp[i][j-1])
				{
					dp[i][j]=dp[i-1][j];
					cal[i][j]=1;
				}
				else
				{
					dp[i][j]=dp[i][j-1];
					cal[i][j]=2;
				}
			}
		}
		dfs(n,m);
		cout<<endl;
		return 0;
}

Measured memory_bytes: 74048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		StringBuilder sb = new StringBuilder(S);
		int[] ans = new int[sb.length()];
		for (int i = 0; i < sb.length();) {
			int index = i;
			int right = 0;
			while (index < sb.length() && sb.charAt(index) == 'R') {
				right++;
				index++;
			}
			int left = 0;
			while (index < sb.length() && sb.charAt(index) == 'L') {
				left++;
				index++;
			}
			ans[i + right - 1] = 1 + (right - 1) / 2 + ((left - 1) / 2 + (left - 1) % 2);
			ans[i + right] = 1 + (left - 1) / 2 + ((right - 1) / 2 + (right - 1) % 2);
			i = index;
		}
		for (int i = 0; i < ans.length; i++) {
			System.out.println(ans[i]);
		}
		in.close();
	}
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    int n ;
    cin >> n ;
    int m = 100000 ;
    vint cnt(m,0) ;
    vint vec ;
    int mine = 0 ;
    REP(i,n){
        int a ;
        cin >> a ;
        cnt[a-1]++ ;
    }
    REP(i,m){
        int k ;
        if(cnt[i]==0){
            k = 0 ;
        }
        else if(cnt[i]%2==0){
            k = 2 ;
            mine++ ;
        }
        else{
            k = 1 ;
        }
        REP(j,k){
            vec.PB(i+1) ;
        }
    }
    /*REP(i,SZ(vec)){
        //cout << vec[i] <<" " ;
    }*/
    if(mine%2==0){
        cout << SZ(vec) - mine <<endl;
    }
    else{
        cout << SZ(vec) - mine - 1 <<endl;
    }





    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 4160
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,m,k;

ll mod_pow(ll x,ll n,ll mod){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}

ll i_l(ll x){
	return mod_pow(x,MOD-2,MOD);
}
int main(){
	cin>>n>>m>>k;
	ll a_r_c=1;
	for(ll i=n*m-k+1;i<=n*m-2;i++){
		a_r_c*=i;
		a_r_c%=MOD;
	}
	for(ll i=1;i<=k-2;i++){
		a_r_c*=i_l(i);
		a_r_c%=MOD;
	}
	ll tans=0;
	for(int d=1;d<m;d++){
		tans+=(((a_r_c*(m-d))%MOD*((n*n)%MOD))%MOD)*d%MOD;
	}
	ll sans=0;
	for(int d=1;d<n;d++){
		tans+=(((a_r_c*(n-d))%MOD*((m*m)%MOD))%MOD)*d%MOD;
	}
	cout<<(tans+sans)%MOD<<endl;
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	priority_queue<double, vector<double>, greater<double>> V;
	rep(i, N){
		int a;
		cin >> a;
		V.push(a);
	}
	rep(i, N - 1){
		double X = V.top();
		V.pop();
		double Y = V.top();
		V.pop();
		X = (X + Y) / 2;
		V.push(X);
	}
	cout << V.top() << endl;
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n, m;
  cin >> n >> m;
  int a[m+1], b[m+1];
  for(int i=1; i<=m; ++i) cin >> a[i] >> b[i];
  
  int num[n+1] = {};
  for(int i=1; i<=m; ++i){
    num[a[i]]++;
    num[b[i]]++;
  }

  for(int i=1; i<=n; ++i) cout << num[i] << endl;
  return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define int long long 
int dx[5]={0,0,-1,1};
int dy[5]={1,-1,0,0};
using namespace std ;
char a[1200][1200];
int b[1200][1200];
int sum=0;
int ans=0;
struct node{
	int x,y;
};
queue<node> p;
int n,m;
void bfs()
{
	while(!p.empty()){
		node q=p.front();
		p.pop();
		//printf("%d\n",p.size());
		for(int i=0;i<4;i++){
			int tx=q.x+dx[i];
			int ty=q.y+dy[i];
			if((tx>=1&&tx<=n)&&(ty>=1&&ty<=m)&&b[tx][ty]==0){
				b[tx][ty]=b[q.x][q.y]+1;
				p.push(node{tx,ty}) ;
				//printf("%lld %lld\n",tx,ty);
				ans=max(ans,b[tx][ty]);
			}
		}
		/*
		cout<<endl;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				printf("%lld ",b[i][j]);
			}
			cout<<endl;
		}
		*/
	}
}
signed main()
{
	
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		scanf("%s",a[i]+1);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='#'){
				p.push(node{i,j});
				b[i][j]++;
				ans=max(b[i][j],ans);
			}
		}
	}
	bfs();
	printf("%lld\n",ans-1);
	return 0;
} 

Measured memory_bytes: 28980
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const int INF = 1e9;
const ll MAXN = 1e9;

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

	int d[31][31] = {0}, c[501][501]= {0};
	for(int i = 1; i <= C; i++){
		for(int j = 1; j <= C; j++){
			cin >> d[i][j];
		}
	}
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= N; j++){
			cin >> c[i][j];
		}
	}

	int color[3][31] = {0};
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= N; j++){
			color[(i+j)%3][c[i][j]]++;
		}
	}

	int ans = INF;
	for(int i = 1; i <= C; i++){
		for(int j = 1; j <= C; j++){
			for(int k = 1; k <= C; k++){
				if(i != j && j != k && k != i){
					int res = 0;
					for(int l = 0; l < 3; l++){
						int m = i;
						if(l == 1) m = j;
						else if(l == 2) m = k;
						for(int p = 1; p < 31; p++){
							res += color[l][p] * d[p][m];
						}
					}
					ans = min(res,ans);
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define pb push_back

int memo[10010];
int cnt(int n){
	vector<int> vec;
	vec.pb(n%10);
	vec.pb((n/10)%10);
	vec.pb((n/100)%10);
	vec.pb(n/1000);
	sort(vec.begin(),vec.end());
	int l = 0 , s = 0;
	for(int i = 0 ; i < 4 ; i ++){
		l *= 10;
		l += vec[vec.size()-1-i];
	}
	for(int i = 0 ; i < 4 ; i ++){
		s *= 10;
		s += vec[i];
	}
	return l-s;
}
int dfs(int n){
	if(memo[n] == -1)return memo[n] = dfs(cnt(n))+1;
	else return memo[n];
}

int main(){
	for(int i = 0 ; i < 10010 ; i ++){
		memo[i] = -1;
	}
	memo[6174] = 0;
	while(1){
		int n;
		scanf("%d",&n);
		if(n == 0)break;
		if(n%1111 == 0){
			puts("NA");
			continue;
		}
		printf("%d\n",dfs(n));
	}
}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<ll, int> P;

string s,t;
vector<char> v;

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

	cin>>s;
	REP(i,s.size()) {
		if(s[i]=='x') continue;
		else {
			v.push_back(s[i]);
		}
	}
	vector<char> vv=v;
	reverse(ALL(vv));
	REP(i,v.size()) {
		if(v[i]!=vv[i]) {
			cout<<"-1"<<endl;
			return 0;
		}
	}
	t=s;
	reverse(ALL(t));
	int i=0,j=s.size()-1,cnt=0;
	while (true) {
		if(s[i]==s[j]) i++,j--;
		else {
			if(s[i]=='x') {
				i++;cnt++;
			}
			else {
				j--;cnt++;
			}
		}
		if(i>=j) break;
	}
	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<algorithm>
#include<string>
#define LL long long
int N;
LL ans;
std::string MARCH = { "MARCH" };
LL march[5];
int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::string s;
		std::cin >> s;
		for (int i = 0; i < 5; i++) {
			if (s[0] == MARCH[i])march[i]++;
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += march[i] * march[j] * march[k];
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

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

namespace Score
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputLine = "";
            int[] totalPoints = new int[2];

            for (int i = 0; i < 2; i++)
            {
                while (true) 
                {
                    inputLine = Console.ReadLine();
                    string[] data = inputLine.Split(' ');

                    if(data.Length == 4)
                    {
                        List<int> points = new List<int>();

                        for (int j = 0; j < data.Length; j++)
                        {   
                            int point = int.Parse(data[j]);

                            if (point <= 100 && point >= 0)
                            {
                                points.Add(point);
                                totalPoints[i] += point;
                            }
                            else
                            {
                                points.Clear();
                                totalPoints[i] = 0;
                                break;
                            }


                        }

                        if (points.Count > 0)
                        {
                            break;
                        }
                    }
                }
            }

            if (totalPoints[0] >= totalPoints[1])
            {
                Console.WriteLine(totalPoints[0]);
            }
            else
            {
                Console.WriteLine(totalPoints[1]);
            }

        }
    }
}



Measured memory_bytes: 15876
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}



fn solve(n : i64, ly : i64) -> (i64, i64, i64) {
    for x in 0..n+1 {
        for y in 0..n-x+1 {
            let z = n - x - y;
            if x * 10000 + y * 5000 + z * 1000 == ly {
                return (x, y, z)
            }
        }
    }
    return (-1, -1, -1)
}



fn main(){
    const MAX_N : usize = 100010;

    let v = read_t_in_line::<i32>();
    let(n, h) = (v[0] as usize, v[1]);
    let mut aa = [0 ; MAX_N];
    let mut bb = [0 ; MAX_N];

    for i in 0..n {
        let v2 = read_t_in_line::<i32>();
        let (a, b) = (v2[0], v2[1]);
        aa[i] = a;
        bb[i] = b;
    }

    const INF : i64 = (1 as i64) << 60; // as i64は必要ないかも？
    
    // aaとbbをそれぞれsort
    // bbを大きい順番に使う, aaは一番大きい値しか利用しない
    let a_slice : &mut [i32] = &mut aa[0..n]; 
    a_slice.sort_by(|x, y| y.cmp(x));
    let b_slice : &mut [i32] = &mut bb[0..n]; 
    b_slice.sort_by(|x, y| y.cmp(x));

    let a_max = a_slice[0];
    let mut min_count = (h + a_max - 1) / a_max;
    let mut b_sum = 0;
    for i in 0..b_slice.len() {
        b_sum += b_slice[i];
        if b_sum >= h {
            min_count = cmp::min(min_count, i as i32 + 1);
            break;
        }
        else{
            min_count = cmp::min(min_count, ((h - b_sum) + a_max - 1) / a_max + i as i32 + 1);
        }
    }

    println!("{}", min_count);


}


Measured memory_bytes: 5116
#include <stdio.h>
#define N_MAX 4

/*                 front  1  2  3  4  5  6 */
char right[7][7] = { { 0, 0, 0, 0, 0, 0, 0 },   /* top */
                     { 0, 0, 3, 5, 2, 4, 0 },   /* 1   */
                     { 0, 4, 0, 1, 6, 0, 3 },   /* 2   */
                     { 0, 2, 6, 0, 0, 1, 5 },   /* 3   */
                     { 0, 5, 1, 0, 0, 6, 2 },   /* 4   */
                     { 0, 3, 0, 6, 1, 0, 4 },   /* 5   */
                     { 0, 0, 4, 2, 5, 3, 0 } }; /* 6   */

#define RIGHT(top, front)  (right[(int)(top)][(int)(front)])
#define BOTTOM(top, front) (7 - top)
#define BACK(top, front)   (7 - front)
#define LEFT(top, front)   (7 - RIGHT(top, front))

/* ------ */

char height_map[N_MAX * 2 + 1][N_MAX * 2 + 1],
    top_map[N_MAX * 2 + 1][N_MAX * 2 + 2];

void init()
{
    int x, y;
    for(y = 0; y < N_MAX * 2 + 1; y++)
        for(x = 0; x < N_MAX * 2 + 1; x++)
            height_map[y][x] = top_map[y][x] = 0;
}

void put(char top, char front)
{
    int x = N_MAX, y = N_MAX, newfront, newtop, newx, newy, max;

    while(1)
    {
        max = 0;

        /* front */
        if(height_map[y - 1][x] < height_map[y][x] && front > 3 && front > max)
            newfront = top, newtop = BACK(top, front),
                newx = x, newy = y - 1, max = front;

        if(height_map[y + 1][x] < height_map[y][x]
           && BACK(top, front) > 3 && BACK(top, front) > max)
            newfront = BOTTOM(top, front), newtop = front,
                newx = x, newy = y + 1, max = BACK(top, front);

        if(height_map[y][x - 1] < height_map[y][x]
           && LEFT(top, front) > 3 && LEFT(top, front) > max)
            newfront = front, newtop = RIGHT(top, front),
                newx = x - 1, newy = y, max = LEFT(top, front);

        if(height_map[y][x + 1] < height_map[y][x]
           && RIGHT(top, front) > 3 && RIGHT(top, front) > max)
            newfront = front, newtop = LEFT(top, front),
                newx = x + 1, newy = y, max = RIGHT(top, front);

        if(!max)
            break;
        else
            front = newfront, top = newtop, x = newx, y = newy;
    }

    height_map[y][x]++, top_map[y][x] = top;
}

void count_and_print()
{
    int x, y, count[7];

    for(x = 1; x <= 6; x++)
        count[x] = 0;

    for(y = 0; y < N_MAX * 2 + 1; y++)
        for(x = 0; x < N_MAX * 2 + 1; x++)
            count[(int)top_map[y][x]]++;

    for(x = 1; x < 6; x++)
        printf("%d ", count[x]);
    printf("%d\n", count[x]);
}

int main(void)
{
    int n;

    while(scanf("%d", &n), n)
    {
        int t, f;

        init();

        while(n--)
        {
            scanf("%d %d", &t, &f);
            put(t, f);
        }

        count_and_print();
    }

    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
typedef unsigned long long ull;

int main() {

	int N,Y;
	cin >> N >> Y;

	for (int i = 0; i <= 2000; i++) {
		for (int j = 0; j <= 2000; j++) {
			if (i + j > N) continue;
			int k = N - i - j;
			int sum = 10000 * i + 5000 * j + 1000 * k;
			if (sum == Y) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}

	cout << -1 << " " << -1 << " " << -1 << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	string s;
	cin>> s;

	if(s[s.size()-1]=='s') cout<< s+"es" << endl;
	else cout<< s+"s" << endl;
 
	return 0;
}

Measured memory_bytes: 3632
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var as = toIntArr(input[1].split(' '));
	as.length = n;
	var ans = -n;
	for(var i = 0; i < n; i++){
		ans += as[i];
	}
	console.log(ans);	
}

Measured memory_bytes: 11596
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators 
//do not forget to change the sizes of arrays and value of contants and other things after debugging  
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)
 
#define SZ(x)  (ll)(x.size())
 
//comment the below if not required
 
/*
 
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/
 
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{

    ll x,k,d,tot,x1,k1;

    cin>>x>>k>>d;

    x = abs(x);

    tot = x/d;

    if(tot>k)
    {
        cout<<(x-d*k);
    }
    else
    {
        k = k-tot;
        x = x-d*tot;
        k1 = k-1;

        x1 = abs(x-d);

        if((k1>=0) && ((k%2) || ((x1<x) && (!(k1%2)))) )
            cout<<x1;
        else
            cout<<x;


    }






    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
int intceil(int a, int b) {
	return (a + (b - 1)) / b;
}
int main() {
	cin >> N >> H;
	vector<int>a(N);
	vector<int>b(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
	}
	int maxa = *max_element(a.begin(), a.end());
	sort(b.begin(), b.end());
	auto ind = upper_bound(b.begin(), b.end(), maxa);
	ll hp = 0;
	for (auto i = b.end()-1; i >= ind; i--) {
		hp += *i;
		ans++;
		if (hp >= H)break;
	}
	if (hp < H)ans += intceil((H - hp), maxa);
	cout << ans << endl;
}

Measured memory_bytes: 1024
turn_n = int(input())

taro_score = 0
hanako_score = 0

for _ in range(turn_n):
    taro_card, hanako_card = input().split()
    
    if taro_card > hanako_card:
        taro_score += 3
    elif taro_card < hanako_card:
        hanako_score += 3
    else:
        taro_score += 1
        hanako_score += 1
print(taro_score, hanako_score)


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit();

    ll N;
    cin >> N;
    string S;
    cin >> S;

    map<char, vector<int> > m;
    m['R'] = vector<int>();
    m['G'] = vector<int>();
    m['B'] = vector<int>();
    for(int i = 0;i < S.size(); i++) {
        m[S[i]].push_back(i);
    }


    ll not_match = 0;
    for(int diff = 1; diff <= (S.size() - 1)/2; diff++) {
        for(int j = 0;; j++) {
            if(j+ 2*diff >= S.size()) break;
            if(S[j] != S[j+diff] && S[j] != S[j+2*diff] && S[j+diff] != S[j+2*diff]) not_match++;
        }
    }

    cout << m['R'].size() * m['G'].size() * m['B'].size()  - not_match << endl;

    return 0;
}

Measured memory_bytes: 15572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    int cnt[26] = {};
    rep(i, 0, 4) {
        cnt[s[i] - 'A']++;
    }
    rep(i, 0, 26) {
        if(cnt[i]) {
            if (cnt[i] != 2) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  string s, t;
  cin >> s >> t;
  for(int i = (int)'a'; i<=(int)'z'; i++) {
    string u = s + (char)i;
    if(t==u) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

import numpy as np

def main():
  n, x = map(int, input().split())
  A = np.array(input().split()[::-1]*2, dtype=np.int64)
  B = A.copy()[:n]
  ans = float("inf")
  for k in range(n):
    t = x*k + B.sum()
    ans = min(ans, t)
    np.minimum(B, A[k+1:k+n+1], out=B)
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 12500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
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; }

int main()
{
    set<int> s;
    int q; cin >> q;
    rep(i, q){
        int c, x, l ,r;
        cin >> c;
        if(c==0){
            cin >> x;
            s.insert(x);
            pr(s.size());
        }else if(c==1){
            cin >> x;
            if(s.find(x)!=s.end()) pr(1);
            else pr(0);
        }else if(c==2){
            cin >> x;
            s.erase(x);
        }else{
            cin >> l >> r;
            if(l<r){
                auto li = s.lower_bound(l);
                auto ri = s.lower_bound(r);
                for(; li!=ri; li++) pr(*li);
                if(*li==r) pr(*li);
            }if(l==r){
                if(s.find(x)!=s.end()) pr(l);
            }
        }
    }
    return 0;}


Measured memory_bytes: 12452
A,B,C = map(int,input().split())
l = sorted([A,B,C])
count = 0
while l[2] - l[1] > 1:
    l[1] += 2
    count += 1
while l[2] - l[0] > 1:
    l[0] += 2
    count += 1
if l[0] == l[1] == l[2]:
    print(count)
elif l[0] == l[1]:
    count += 1
    print(count)
else:
    count += 2
    print(count)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    
    if((a==b && b!=c) || (a==c && a!=b) || (b==c && a!=b)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

int64_t L, R;

int main(){
    cin >> L >> R;

    int64_t ans = 1000000000;
    if(R - L >= 2019){
        cout << 0 << endl;
        return 0;
    } else {
        for(int64_t i=L;i<=R-1;i++){
            for(int64_t j=i+1;j<=R;j++){
                if(i * j % 2019 < ans)  ans = (int64_t)i * j % 2019;
            }
        }
    }

    cout << ans << endl;
}

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

int main(){
    while(1){
        int h,w;
        cin >> h >> w;
        if(h==0) break;

        int diag = h*h + w*w;
        for(int d=diag; d!=-1; d++){
            for(int i=1; 2*i*i<d; i++){
                int rem=d-i*i;
                int sqrem=sqrt(rem);
                if(sqrem*sqrem == rem){
                    if(d==diag && i<=h) continue;
                    cout << i << " " << sqrem << endl;
                    d = -2;
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

const int INF = 1e9+7;

main()
{
    fast;
    int n,k,i,j;
    cin>>n>>k;
    ll h[n],ans[n];
    memset(ans,INF,sizeof(ans));
    ans[0]=0;
    for (i=0;i<n;i++)
    {
        cin>>h[i];
        for (j=i-1;j>=max(i-k,0);j--)
            ans[i]=min(ans[i],ans[j]+abs(h[i]-h[j]));
    }
    cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
int pow(ll x, ll n, ll mod) //x^nをmodで割った余りを求める
{
	ll res = 1;
	while (n > 0)
	{
		if (n & 1) res = res * x % mod;
		x = x*x%mod;
		n >>= 1;
	}
	return res;
}



int main()
{
	int m, n;
	cin >> m >> n;
	cout << pow(m, n, MOD) << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
	int n,m,l,r,ma=-1,mi=100001;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>l;
		ma=max(ma,l);
		cin>>r;
		mi=min(mi,r);
	}
	if(ma>mi){
		cout<<0<<endl;
	}else{
		cout<<mi+1-ma<<endl;
	}

	return 0;

}



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

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long ll;
inline void Fail(){printf("-1");exit(0);}
inline void debug(int x){cerr<<"debug: "<<x<<"\n";}
inline void debug(int n,int x[]){cerr<<"debug "<<"\n";rep(i,n)cerr<<x[i]<<" ";cerr<<"\n";}
inline void debug(string x){cerr<<"debug: "<<x<<"\n";}

const int maxn=100005;
int n;
ll low=2,high=2;
ll a[maxn];

int main(){
	scanf("%d",&n);
	rep(i,n)scanf("%lld",&a[i]);
	for(int i=n-1;i>=0;i--){
		if((low+a[i]-1)/a[i]*a[i]>high)Fail();
		low=(low+a[i]-1)/a[i]*a[i];
		high=high/a[i]*a[i]+a[i]-1;
	}
	printf("%lld %lld",low,high);
	return 0;
}

/*
Input:
15
37 20 13 15 4 12 8 7 11 8 4 2 5 3 2
-----------------
Output:
*/

Measured memory_bytes: 1024
#pragma GCC optimize("O3", "unroll-loops")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

vector<vector<int>> nxt;
vector<ld> E;

signed main() {
	cout << setprecision(15);
	int n, m; cin >> n >> m;
	nxt.resize(n); E.resize(n);
	while (m--) {
		int s, t; cin >> s >> t;
		--s; --t;
		nxt[s].push_back(t);
	}
	E[n - 1] = 0.0L;
	for (int i = n - 2; i >= 0; --i) {
		vector<ld> e;
		for (auto nxti : nxt[i])
			e.push_back(E[nxti]);
		E[i] = accumulate(e.begin(), e.end(), 0.0L) / e.size() + 1.0L;
	}
	for (int i = 0; i < n; ++i)
		sort(
			nxt[i].begin(), nxt[i].end(),
			[](int a, int b) { return E[a] < E[b]; }
	);
	ld ans = E[0];
	for (int i = 0; i < n - 1; ++i) {
		if (nxt[i].size() <= 1) continue;
		vector<ld> E_(n);
		E_[n - 1] = 0.0L;
		for (int j = n - 2; j >= 0; --j) {
			vector<ld> e;
			for (auto nxti : nxt[j])
				e.push_back(E_[nxti]);
			if (i != j)
				E_[j] = accumulate(e.begin(), e.end(), 0.0L) / e.size() + 1.0L;
			else
				E_[j] = accumulate(e.begin(), e.end() - 1, 0.0L) / (e.size() - 1) + 1.0L;
		}
		ans = min(ans, E_[0]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())
graph = [0] + [[] for _ in range(n)]
for _ in range(m):
    n1, n2 = map(int, input().split())
    graph[n1].append(n2)
    graph[n2].append(n1)

from collections import deque

def bfs(graph, queue, dist, prev):
    while queue:
        current = queue.popleft()

        for c in graph[current]:
            if dist[c] != -1:
                continue
            dist[c] = dist[current] + 1
            prev[c] = current
            queue.append(c)

queue = deque([1])
dist = [0] + [-1] * n
dist[1] = 0
prev = [0] + [-1] * n
prev[1] = 0

bfs(graph, queue, dist, prev)
if -1 in prev:
    print('No')
else:
    print('Yes')
    for n in prev[2:]:
        print(n)


Measured memory_bytes: 94384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

string s;

string dfs(int l,int r){
    int cnt = 0;
    int idx = -1;
    int p = 0;
    string ret = "";
    for (int i = l; i < r; i++) {
        if(s[i] == '['){
            if(cnt == 0) idx = i;
            cnt++;
        }
        else if(s[i] == ']'){
            cnt--;
            if(cnt == 0){
                auto r = dfs(idx+1,i);
                reverse(ALL(r));
                ret += r;
            }
        }
        else if(s[i] == '+'){
            if(cnt) continue;
            p = (p + 1)%26;
        }
        else if(s[i] == '-'){
            if(cnt) continue;
            p = (p + 25)%26;
        }
        else{
            if(cnt) continue;
            int t = s[i] - 'A';
            if(0<=t&&t<26){
                t = (t + p)%26;
                ret += (char) (t + 'A');
                p = 0;
            }
            else{
                ret += s[i];
                p = 0;
            }
        }
    }
    return ret;
}


int main(){
    while(cin >> s){
        if(s==".") return 0;
        auto r = dfs(0,s.length());
        for (int i = 0; i < r.length(); i++) {
            if(r[i] == '?') r[i] = 'A';
        }
        cout << r << endl;
    }
    return 0;
}



Measured memory_bytes: 3172
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] field = new char[h][];
		for (int i = 0; i < h; i++) {
			field[i] = sc.next().toCharArray();
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (field[i][j] == '.') {
					continue;
				}
				if ((i > 0 && field[i - 1][j] == '#') || (i < h - 1 && field[i + 1][j] == '#') || (j > 0 && field[i][j - 1] == '#') || (j < w - 1 && field[i][j + 1] == '#')) {
					continue;
				}
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 23636
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
N = INT()
a = LIST()

cnt = 0
ans = [[-1]*W for _ in range(H)]
tmp = a.pop(0)
color = 1
flag = 0
for i in range(H):
	for j in range(W):
		if i % 2 == 1:
			j = W - j - 1
		ans[i][j] = color
		cnt += 1
		if cnt >= tmp:
			if not a:
				flag = 1
				break
			cnt = 0
			tmp = a.pop(0)
			color += 1
	if flag:
		break

# print(ans)
for i in ans:
	print(" ".join([str(x) for x in i]))


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

int main() {
  int k, x;
  cin >> k >> x;
  
  for (int i = 0; i < (2 * k - 2); i++) {
    cout << (x - k + 1 + i) << " ";
  }
  
  cout << (x + k - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<algorithm>
using namespace std;
int main(){
	int n,t[20],d[20][20],temp,num,a,b,c,qq;
	while(cin>>n,n){
		temp=INT_MAX;
		qq=0;
		for(int i=0;i<10;i++)
		for(int j=0;j<10;j++){
			d[i][j]=INT_MAX/2;
			t[j]=0;
		}
		for(int i=0;i<n;i++){
			d[i][i]=0;
			cin>>a>>b>>c;
			if(qq<a)
			qq=a;
			if(qq<b)
			qq=b;
			d[a][b]=c;
			d[b][a]=c;
		}
		qq++;
		
		for(int k=0;k<qq;k++)
		for(int i=0;i<qq;i++)
		for(int j=0;j<qq;j++)
		d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		for(int i=0;i<qq;i++){
			for(int j=0;j<qq;j++){
				t[i]+=d[i][j];
			}
			if(temp>t[i]){
				temp=t[i];
				num=i;
			}
		}
		cout<<num<<' '<<temp<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc081/tasks/arc081_c

1文字がありうるのは、出てない文字があるとき
2文字がありうるのは、全ての文字が1度出たのち、もう一度すべての文字が1度現れてない場合
つまり答えの文字数はこの方法で分かる

では辞書順最小のものは？
k文字であることがわかっていたとする。
この時、どの文字も最低k-1回出現している
最後の文字は、k回出現してない文字の内、辞書順最小の物
最後から1番目は、k-1回目の出現の後、最後の文字が出ていない者
最後から2番目は、

abcの3文字しかないとする
abababababcab

→この時、求めるのは、?cで、?はc最後に出現するcよりも前に存在しないk-1文字の辞書順最小

abcabcab
→??c
→最後の出現するc以前=abcab以前で存在しない2文字
→?cc
→abで存在しない1文字
→ccc

acbaccbac
→結局再帰的に解ける
→出現回数が最小の文字のうち、辞書順最小の物を答えの最後の文字から決めていき、その文字が最後の出現したind
より前に関して、同じ問題を解く

あとはどうやって計算量を削減するか
その時点で、どの文字が何度出たか、最後の出現したindexはどこか、を記録して置いて再帰的に解く

→方針は合ってる？けど実装してるのが違うよ！
保存しておくのは、全ての文字が何回出揃ったか、とその後どの文字が出ているか。
&各文字が最後にどこで出たか。

あれー？
aaaaaabbbbbbc

→問題は、必ずしも後ろから最適なのを選んで行けばいいわけではなかったこと
→これはあくまで、後ろから見て辞書順最小でしかない…あれまさか？
→正解しちゃったー？？？
"""

A = list(input())
A.reverse()

alp = "abcdefghijklmnopqrstuvwxyz"
alpdic = {}
for i in range(26):
    alpdic[alp[i]] = i

allcol = [0] * (len(A)+1)
apnum =  [ [0] * 26 for i in range(len(A)+1) ]
lastap = [ [0] * 26 for i in range(len(A)+1) ]

for i in range(len(A)):

    for j in range(26):
        apnum[i+1][j] = apnum[i][j]
        lastap[i+1][j] = lastap[i][j]
        allcol[i+1] = allcol[i]

    apnum[i+1][alpdic[A[i]]] |= 1
    if 0 not in apnum[i+1]:
        apnum[i+1] = [0] * 26
        allcol[i+1] += 1
    lastap[i+1][alpdic[A[i]]] = i+1

anslen = allcol[-1]+1
ans = []
nind = len(A)

for i in range(anslen):

    #print ("".join(A[:nind]))

    minind = 0
    for j in range(26):
        if apnum[nind][j] == 0:
            minind = j
            break
    ans.append(alp[minind])

    nind = lastap[nind][minind]-1

#ans.reverse()
print ("".join(ans))

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

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

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

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      int str1 = Integer.parseInt(scan.next());
      double str2 = Double.parseDouble(scan.next());
      double str3 = Double.parseDouble(scan.next());
      scan.close();
      
      double result=0;
      if(str3 >= str2-1)
      	System.out.println((int)(str1-str1/str2));
      else
        System.out.println((int)(str1*str3/str2)-str1*(long)(str3/str2));
      
    }
}

Measured memory_bytes: 35784
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a,b,c; cin>>a>>b>>c;
  if(c-b<=0) cout<<"delicious"<<endl;
  else if(c-b<=a) cout<<"safe"<<endl;
  else cout<<"dangerous"<<endl;
}













Measured memory_bytes: 256
# ABC144 C - Walk on Multiplication Table
import math
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
sqrtn = int(math.sqrt(n))
for i in range(sqrtn, 0, -1):
    if n%i == 0:
        j = n // i
        print(i+j-2)
        break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin>>N>>K;
  vector<int> p(N);
for (int i = 0; i < N; i++) {
  cin >> p.at(i);
}
  
  sort(p.begin(), p.end());
  
  int sw=0;
  for(int i=0;i<K;i++){
    sw=sw+p.at(i);
  }
  
  cout<<sw<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    int h,w,d;cin>>h>>w>>d;
    vector<pii>A(h*w+1);
    rep(i,h)rep(j,w){
        int a;cin>>a;
        A[a]=make_pair(i+1,j+1);
    }
    vector<ll>cost(h*w+1);
    REP(i,1,d+1){
        int j=i;
        while(j<=h*w){
            if(j==i){
                j+=d;
                continue;
            }
            cost[j]=cost[j-d]+abs(A[j].first-A[j-d].first)+abs(A[j].second-A[j-d].second);
            j+=d;
        }
    }
    int q;cin>>q;
    rep(i,q){
        int l,r;cin>>l>>r;
        cout<<cost[r]-cost[l]<<endl;
    }
}

Measured memory_bytes: 2560
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        double money = 100;
        for (int i = 0;i < n; i++)
        {
            money = Math.Ceiling(money * 1.05);
        }
        Console.WriteLine(money*1000);
    }
}

Measured memory_bytes: 5568
#include <stdio.h>
int main(){
    int a, b;
    int n = 0;
    char str[3][5] = {" == ", " < ", " > "};
    
    scanf("%d %d", &a, &b);
    
    if(a < b){
        n = 1;
    }else if(a > b){
        n = 2;
    }
    printf("a%sb\n", str[n]);
    return 0;
}


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

typedef long long int ll;
const int N = 1e6+6;

int main()
{
    int n;cin>>n;
    int Arr[n+2];
    for(int i=1;i<=n;i++)cin>>Arr[i];
    int i=1,Res = 0;
    while(i<=n)
    {
        int cnt = 0;
        if( Arr[i]==Arr[i+1]&&i+1<=n )
        {
            cnt++,i++;
        }
        i++;
        Res += (cnt+1)/2;
    }
    cout<<Res<< "\n";


    return 0;
}


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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 

const int upper = 2e5 + 1;
const int M = (int) 1e9 + 7;
const int inf = (int) 1e17;
const double eps =  1e-8;

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	string s;
	cin >> s;

	string target = "keyence";

	if (len(s) < len(target)) {
		cout << "NO";
		return 0;
	}

	int ptr = 0;
	for (int i = 0; i < len(target); i++) {
		if (s[i] == target[i]) ptr += 1;
	}

	int j = len(s) - 1;
	bool flag = true;
	for (int i = len(target) - 1; i >= ptr; i -= 1) {
		if (s[j] != target[i]) {
			flag = false;
			break;
		}
		j -= 1;
	}
	if (flag) cout << "YES";
	else cout << "NO";
 	end_routine();	
}

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

int main() {
  int n; cin >> n;
  vector<int> hight(n);
  rep(i,n) cin >> hight[i];

  int cnt = 1;
  int maxh = hight[0];
  for (int i = 1; i < n; i++) {
    if (maxh <= hight[i]) cnt++;
    maxh = max(maxh, hight[i]);
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3588