akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main() {
  long long t, a, T{1}, A{1}, k;
  cin >> k;
  while (cin >> t >> a) {
    k = max((A - 1) / a, (T - 1) / t) + 1;
    A = k * a, T = k * t;
  }
  cout << T + A << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=500010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
char c[310][310];
int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	int ans=0;
	for(int k=0;k<n;k++){
		bool f=true;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(c[i][(j+k)%n]!=c[j][(i+k)%n]){
					f=false;
				}
			}
		}
		if(f){
			ans++;
		}
	}
	cout<<ans*n<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
char s[200005];
map <char,long long int> mp;
long long int x,y,z,n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(long long int i=1;i<=n;i++)
	{
		mp[s[i]]++;
	}
	long long int total=n*(n-1)/2;
	long long int temp=0;
	for(long long int i=1;i<=n;i++)
	{
		if(mp[s[i]]>0)
		{
			long long int tmp=mp[s[i]];
			temp+=tmp*(tmp-1)/2;
			mp[s[i]]=0;
		}
	}
	printf("%lld",total-temp+1);
}


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

int main() {
	vector<int> p;
	int n;
	p.push_back(2);
	for(int i=3;i<999999;i++){
		for(int j=0;;j++){
			if(i%p[j]==0)
			break;
			if(i<p[j]*p[j]){
			p.push_back(i);
			break;
			}
		}
	}
	p.push_back(9999999);
	while(cin >> n){
		int i=0;
		while(n>=p[i]){
			i++;
		}
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 1588
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll anum = 0;
    ll bnum = 0;
    ll ans = 0;
    ll num = 0;
    REP(i, 0, N) {
        string s;
        cin >> s;
        ll len = s.size();
        REP(j, 0, len - 1) {
            if (s[j] == 'A' && s[j + 1] == 'B') {
                ans++;
            }
        }
        if (s[0] == 'B') {
            bnum++;
        }
        if (s[len - 1] == 'A') {
            anum++;
        }
        if (s[0] == 'B' && s[len - 1] == 'A') {
            num++;
        }
    }
    ans += min(anum, bnum);
    if (num == anum && anum == bnum && anum > 0) {
        ans--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll mod=1e9+7;
vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}

int main(void){
    ll n,k;
    cin>>n>>k;
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % mod; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, mod-2) % mod; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    rep(1,i,k+1){
        cout<<comb(n-k+1,i)*comb(k-1,i-1)%mod<<endl;
    }
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int n;
cin >> n;
vector<int> vec(n);
for (int i = 0;i < n;i++) cin >> vec.at(i);

int count = 0;
for (int i = 0;i < n-2;i++) {
    if (vec.at(i) < vec.at(i+1) && vec.at(i+1) < vec.at(i+2)) {
        count++;
    } else if (vec.at(i) > vec.at(i+1) && vec.at(i+1) > vec.at(i+2)) {
        count++;
    }
}

cout << count << endl;

return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> matrix(n, vector<int>(m));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
			cin >> matrix.at(i).at(j); 
	}
	vector<int> vec(m);
	for (int i = 0; i < m; i++)
		cin >> vec.at(i);
	for (int i = 0; i < n; i++)
	{
		int sum;
		sum = 0;
		for (int j = 0; j < m; j++)
			sum += matrix.at(i).at(j) * vec.at(j);
		cout << sum << endl;
	}
}



Measured memory_bytes: 3172
from scipy.sparse import*
i=lambda:map(int,input().split())
f=csgraph.floyd_warshall
n,m,l=i()
d=eval('[0]*-~n,'*-~n)
exec('a,b,c=i();d[a][b]=c;'*m)
d=f(f(d,0)<=l)
d[d>9e9]=0
q,=i()
while q:s,t=i();print(int(d[s,t])-1);q-=1

Measured memory_bytes: 352512
#include <stdio.h>
int main() {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b && a<c){
        printf("%d",a);
        if(b>c){
            printf(" %d %d\n",c,b);
        }else{
            printf(" %d %d\n",b,c);
        }
    }else if(b<a && b<c){
        printf("%d",b);
        if(a>c){
            printf(" %d %d\n",c,a);
        }else{
            printf(" %d %d\n",a,c);
        }
    }else{
        printf("%d",c);
        if(a>b){
            printf(" %d %d\n",b,a);
        }else{
            printf(" %d %d\n",a,b);
        }
    }
    return 0;
}

Measured memory_bytes: 1756
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

#define debug(x) cout<<#x<<" : "<<x<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define derep(i,a,b) for(int i=a;i>b;i--)
#define all(x) (x).begin(),(x).end()
#define PB push_back
typedef long long ll;

int main(){
	int n,cnt=0;
	string s;
	cin>>n>>s;

	rep(i,1,n){
		int c=0;
		vector<bool> inc(26,false);
		rep(j,0,i)inc[s[j]-'a']=true;
		rep(j,i,n){
			if(inc[s[j]-'a']){
				c++;
				inc[s[j]-'a']=false;
			}
		}
		cnt=max(c,cnt);
	}
	cout<<cnt<<endl;



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

bool comp(int a, int b) {
	return abs(a)>abs(b);
}
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	//ofstream cout ("fileName.out");
	//ifstream cin ("fileName.in");
	
	int N,K;
	cin>>N>>K;
	vl pos, neg;
	
	for(int i=0; i<N; ++i) {
		ll n;
		cin>>n;
		if(n>=0) pos.pb(n);
		else neg.pb(n);
	}
	
	ll ans=1;
	
	if(K==N) {
		for(auto x: pos) ans=(ans*(x%MOD))%MOD;
		for(auto x: neg) ans=(ans*(x%MOD))%MOD;
		if(ans<0) ans+=MOD;
		cout<<ans<<"\n";
		return 0;
	}
	
	if(neg.size()==N && K%2==1) {
		sort(neg.rbegin(), neg.rend());
		for(int i=0; i<K; ++i) ans=(ans*(neg[i]%MOD))%MOD;
		ans+=MOD;
		cout<<ans<<"\n";
		return 0;
	}
	
	sort(pos.begin(), pos.end());
	sort(neg.rbegin(), neg.rend());
	
	int minus=neg.size()-1, plus=pos.size()-1;
	
	while(K) {
		ll a=-1, b=-1;
		if(K>=2 && minus>=1) a=neg[minus]*neg[minus-1];
		if(plus>=1)	b=pos[plus]*pos[plus-1];
		
		if(a>b && K!=1) {
			K-=2;
			minus-=2;
			ans=(ans*(a%MOD))%MOD;
		}
		
		else {
			--K;
			ans=(ans*(pos[plus]%MOD))%MOD;
			--plus;
		}
	}
	
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5560
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define rad M_PI/3
#define N 2147483647
#define Max 500000
#define NTL -1
#define min(a,b) ((a>b)?b:a)

int main(){
  int i,n,x,y,ans,max=0;
  scanf("%d%d",&n,&ans);
  for(i=0;i<n;i++){
    scanf("%d%d",&x,&y);
    ans+=x-y;
    if(ans<0){
      printf("0\n");
      break;
    }
    if(max<ans){
      max=ans;
    }
  }
if(ans>0){
  printf("%d\n",max);
}
  return 0;
}


Measured memory_bytes: 2096
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int ans=0,n,k;
vector<int>w[MAXN];
bool vis[MAXN];
int dfs(int u,int f)
{
	int re=0;
	for(int i=0;i<int(w[u].size());i++)
	{
		int v=w[u][i];
		if(v!=f)
		{
			re=max(re,dfs(v,u));
		}
	}
	re++;
	if(vis[u]==0&&re>=k)
	{
		if(re>k)
			printf("HJB!");
		re=0;
		ans++;
	}
	return re;
}
int main()
{
	scanf("%d %d",&n,&k);
	int a;
	scanf("%d",&a);
	if(a!=1)
		ans=1;
	for(int i=2;i<=n;i++)
	{
		scanf("%d",&a);
		w[a].push_back(i);
		w[i].push_back(a);
		if(a==1)
			vis[i]=1;
	}
	vis[1]=1;
	dfs(1,0);
	printf("%d\n",ans);
}

Measured memory_bytes: 13568
def q(a,h):
 d[a]=str(h)
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
for _ in[0]*int(input()):
 e=input().split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
for i in sorted(map(int,t)):
 i=str(i)
 f='root'if'-1'==p[i]else'internal node'if t[i]else'leaf'
 print(f'node {i}: parent = {p[i]}, depth = {d[i]}, {f}, {list(map(int,t[i]))}')


Measured memory_bytes: 55916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B =0, C =0;
  
  vector<int> OOT(200);
  cin >> A;
  
  for(int YUNI =0;YUNI < A;YUNI++){
    cin >> OOT.at(YUNI);
  }
  
  for(int YUNI =0;YUNI < A;YUNI++){
    if(C == 0){
      B += *max_element(OOT.begin(), OOT.end());
    }
    else{
      B -= *max_element(OOT.begin(), OOT.end());
    }
    
    vector<int>::iterator E = max_element(OOT.begin(), OOT.end());
    size_t F = distance(OOT.begin(), E);
    OOT.at(F) = 0;
    
    if(C == 0){
      C = 1;
    }
    else{
      C = 0;
    }
  }
  
  cout << B << endl;
}

Measured memory_bytes: 3636
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: i64 = read();
    let mut cnt_map: Vec<Vec<usize>> = vec![vec![0; 10]; 10];
    let mut ans = 0;

    if n == 1 {
        println!("{}", 1);
        return;
    }

    for i in 0..n + 1 {
        let ie = i % 10;
        let mut is = i;
        while is >= 10 {
            is = is / 10
        }
        cnt_map[is as usize][ie as usize] += 1;
    }
    // for i in &cnt_map {
    //     println!("{:?}", i);
    // }

    for i in 1..10 {
        for j in 1..10 {
            ans += &cnt_map[i][j] * &cnt_map[j][i];
        }
        // ans -= cnt_map[i][i] * cnt_map[i][i]
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
# ライブラリのインポート
#import re #正規表現
import sys
#import heapq
#import collections
#import math

def main():
    q = int(input())
    STR = [str.strip("\n") for str in sys.stdin]
    for i in range(q):
        x = STR[2*i]
        y = STR[2*i+1]
        print(lcs(x,y))


def lcs(x, y):
    dp = []
    for y_k in y:
        ps = 0
        for i, pdp in enumerate(dp):
            p = x.find(y_k, ps) + 1 #.find method returns -1 if there is no element
            if not p: break
            dp[i] = min(p,pdp)
            ps = pdp
        else: #else block is executed when for block has done completedly
            p = x.find(y_k, ps) + 1
            if p: dp.append(p)
    return len(dp)


if __name__ == '__main__':
    main()



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

using namespace std;

int main() {
  int N;  
  cin >> N ;
  
  vector<int> vec;
  
  for (int i = 1; i <= 9; i++) {
    for (int j = i; j <= 9; j++){
      vec.push_back(i*j);
    }
  }
  
  sort(vec.begin(), vec.end());
  bool t = binary_search(vec.begin(), vec.end(), N);
  if (t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
cou_4 = 0
cou_2 = 0

for i in range(n):
    a = A[i]
    if a % 4 == 0:
        cou_4 += 1
    elif a % 2 == 0:
        cou_2 += 1
        
if cou_2 == 0 and cou_4 > 0:
    cou_2 += 1
if n <= 2*cou_4 + cou_2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define turn printf("\n");
using namespace std;
const int orzhjw=100010;
int a,b,c,t=0,x=0,y=0,tt,xx,yy;
inline int get(int &x){
    char s=getchar();int f=1,o=0;
    while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
    while(s<='9'&&s>='0'){o=o*10+s-'0';s=getchar();}
    x=o*f;
}
inline int put(int x){
    printf("%d ",x);
}
int main(){
	get(a);
	for(int i=1;i<=a;i++){
		get(tt);get(xx);get(yy);
		int xxx=abs(xx-x),yyy=abs(yy-y);
		if(xxx+yyy>tt-t){
			cout<<"No"<<endl;
			return 0;
		}
		if((tt-t)%2!=(xxx+yyy)%2){
			cout<<"No"<<endl;
			return 0;
		}
		x=xx;y=yy;t=tt;
	}
	cout<<"Yes"<<endl;
}

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

int main(){
	const char MCXI[]={'m','c','x','i'};
	const int num[]={1000,100,10,1};
	int n;
	cin>>n;
	while(n--){
		int sum=0;
		for(int j=0;j<2;++j){
			string s;
			cin>>s;
			for(int k=0,tmp=1;k<s.size();++k){
				if('2'<=s[k]&&s[k]<='9'){
					tmp=s[k]-'0';
				}else{
					for(int l=0;l<4;++l) if(s[k]==MCXI[l]) sum+=tmp*num[l];
					tmp=1;
				}
			}
		}
		stringstream sums;
		for(int j=0;j<4;++j){
		
			if(sum/num[j]==1) sums << MCXI[j];
			else if(sum/num[j]>=2) sums << (sum/num[j]) << MCXI[j];
			sum%=num[j];
		}
		cout<<sums.str()<<"\n";
	}
	return 0;
}

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

bool IsEven(const string& s) {
  int len = s.size();
  if (len % 2) return false;
  string left = s.substr(0, len / 2);
  string right = s.substr(len / 2, len / 2);
  return left == right;
}

int main() {
  string S;
  cin >> S;
  do {
    S = S.substr(0, S.size() - 1);
  } while (!IsEven(S));
  cout << S.size() << endl;
}


Measured memory_bytes: 256
N = gets.to_i
es = (0..N).map{ {} }
F = (0..N).map{ {} }
G = (0..N).map{ {} }
(N-1).times {
  x,y = gets.split.map &:to_i
  es[x][y] = es[y][x] = 1
}
Colors = [nil] + gets.chomp.chars.map{ |c| c == "B" ? 0 : 1 }
#p Colors
def dig1(n, es, root)
  visited = {}
  parent = Array.new(n+1, 0)
  queue1 = [root]
  queue2 = [root]
  while queue1.size > 0 do
    u = queue1.pop
    visited[u] = 1
    es[u].keys.each{ |v| 
      next if visited[v]
      queue1 << v 
      queue2 << v 
      parent[v] = u
    }
  end
  # p parent, queue2
  queue2.reverse_each{ |u|
    next if u == root
    f = g = h = 0
    s = es[u].keys.reject{ |v| v == parent[u] }
    t = s.max_by{ |v| F[u][v] - G[u][v] }
    # p u,s
    s.each{ |v|
      h += 1 if F[u][v] > 0
      f += F[u][v]
      g += F[u][v]
    }
    f += ((h > 0 ? h+1 : Colors[u]) + Colors[u]) % 2
    f += (h + Colors[u]) > 0 ? 2 : 0
    if t
      g -= F[u][t] - G[u][t]
    end
    g += ((h > 0 ? h   : Colors[u]) + Colors[u]) % 2
    g += (h + Colors[u]) > 0 ? 1 : 0
    F[parent[u]][u] = f
    G[parent[u]][u] = g
    #p F,G
  }
end

def dig2(n, es, root)
  visited = {}
  parent = Array.new(n+1, 0)
  queue1 = [root]
  while queue1.size > 0 do
    u = queue1.pop
    visited[u] = 1
    es[u].keys.each{ |v| 
      next if visited[v]
      queue1 << v 
      parent[v] = u
    }
    s = es[u].keys
    t = s.max_by{ |v| F[u][v] - G[u][v] }
    w = s.reject{ |v| v == t }.max_by{ |v| F[u][v] - G[u][v] }
    f0 = g0 = h0 = 0
    # p u,s
    #p u, s
    s.each{ |v|
      h0 += 1 if F[u][v] > 0
      f0 += F[u][v]
      g0 += F[u][v]
    }
    s.each{ |v|
      h = h0 - (F[u][v] > 0 ? 1 : 0)
      f = f0 - F[u][v]
      f += ((h > 0 ? h+1 : Colors[u]) + Colors[u]) % 2
      f += (h + Colors[u]) > 0 ? 2 : 0
      g = g0 - F[u][v]
      if s.size > 1
        x = t == v ? w : t
        g -= F[u][x] - G[u][x]
      end
      g += ((h > 0 ? h   : Colors[u]) + Colors[u]) % 2
      g += (h + Colors[u]) > 0 ? 1 : 0
      F[v][u] = f
      G[v][u] = g
      #p F,G
    }
    h = h0
    f = f0
    f += ((h > 0 ? h+1 : Colors[u]) + Colors[u]) % 2
    f += (h + Colors[u]) > 0 ? 2 : 0
    g = g0
    if t
      g -= F[u][t] - G[u][t]
    end
    g += ((h > 0 ? h   : Colors[u]) + Colors[u]) % 2
    g += (h + Colors[u]) > 0 ? 1 : 0
    F[0][u] = f
    G[0][u] = g
  end
end

dig1(N, es, 1)
dig2(N, es, 1)

#p F, G
p G[0].values.min

Measured memory_bytes: 145980
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int longth[2],n,lim,mem = -1,ud,sum,ans = 0;
    scanf("%d%d",&n,&lim);
    scanf("%d%d",&longth[0],&longth[1]);
    sum = 2 * lim - longth[0] - longth[1];
    if(longth[1] > longth[0])ud = 1;
    else ud = 0;
    mem = ud;
    longth[0] = longth[1];
    for(int i = 2; i < n + 1; i++)
    {
        if(i == n)
        {
            ans = max(ans,sum);
            break;
        }
        scanf("%d",&longth[1]);
        if(longth[1] > longth[0])ud = 1;
        else ud = 0;
        if(mem == ud)sum = sum + lim - longth[1];
        else
        {
            ans = max(ans,sum);
            sum = 2 * lim - longth[1] - longth[0];
            mem = ud;
        }
        longth[0] = longth[1];
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 2712
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from itertools import permutations 
def main():
    n = int(readline())
    p = tuple([int(i) for i in readline().split()])
    q = tuple([int(i) for i in readline().split()])
    num = [i for i in range(1, n+1)]

    c1 = 0
    c2 = 0
    cnt = 0
    for perm in permutations(num):
        cnt += 1
        if perm == p:
            c1 = cnt
        if perm == q:
            c2 = cnt
    print(abs(c1-c2))   
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#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)

int main()
{
  while (1)
  {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<string> v(n);
    rep(i, n) cin >> v[i];
    int cnt = 0;
    for (int i = 0; i + 1 < n; i += 2)
    {
      if (v[i][0] != v[i + 1][0])
        cnt++;
    }
    cout << cnt << "\n";
  }
  return 0;
}


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


int main(){
  int n;
  while(cin>>n, n){
    vector<int> v;

    v.clear();
    for(int i=0;i<n;++i){
      int x;
      cin>>x;
      v.push_back(x);
    }
    int ans=0,cnt=0;

    
    int t=1;
    for(int i=0;i<v.size();++i){
      if(v[i]){
        if(v[i]==t) ++t;
        else break;
      }
    }

    
    if(t-1==v.size()){
      cout<<0<<endl;
      continue;
    }
    
    int flag=1;    
    while(flag){
      cnt=0;
      ans++;
      if(ans>10000){
        ans=-1;
        break;
      }
      
      for(int i=0;i<v.size();++i){
        if(v[i]){
          v[i]--; cnt++;
        }
      }
      v.push_back(cnt);
      int a=1, b=0;

      
      for(int j=0;j<v.size();++j){
        
        if(v[j]){
          if(v[j]==a) ++a;
          else{
            break;
          }
        }
        b=j+1;
      }
      
      if(b==v.size()) break;
    }
    if(flag) cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3192
unittest
{
	assert( [ "25" ].solve == 17 );
	assert( [ "1" ].solve == 1 );
	assert( [ "100" ].solve == 108 );
	assert( [ "2020" ].solve == 40812 );
	assert( [ "200000" ].solve == 400000008 );
}



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

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	// 先頭の桁と末尾の桁ごとに集計
	auto css = new long[][]( 10, 10 );
	foreach( i; 1L .. n + 1 )
	{
		auto j = i % 10;
		while( 10 <= i ) i /= 10;
		css[ i ][ j ]++;
	}
	
	// ペアの数をカウント
	auto ans = 0L;
	foreach( i; 1L .. 10L )
	{
		foreach( j; 1L .. 10L )
		{
			ans += css[ i ][ j ] * css[ j ][ i ];
		}
	}
	return ans;
}


Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, n, a) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;

void solve(){
    ll dp[N];
    int n, k;
    cin >> n >> k;
    int a[N];
    rep(i, n) cin >> a[i];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    Rep(i, 2, n)
    {
        dp[i] = inf;
        Rep(j, (i - k >= 0)? i - k : 0 ,i - 1)
        {
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
        }
    }
    //rep(i, n) cout << dp[i] << endl;
    cout << dp[n - 1];
}

int main()
{
    OP
    solve();
    return 0;
}    
    
    


Measured memory_bytes: 1408
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;

namespace Math {
// Generic modular integer.
    template<int MOD, typename IntType = int>
    struct GModint {
        IntType val;

        GModint() : val(0) {}

        GModint(int v, bool safe = false) { val = safe ? v : ((v % MOD) + MOD) % MOD; }

        GModint(ll v, bool safe = false) { val = safe ? v : ((v % MOD) + MOD) % MOD; }

        explicit operator bool() const { return val != 0; }

        const bool operator==(const GModint &g) const { return val == g.val; }

        const bool operator!=(const GModint &g) const { return val != g.val; }

        const GModint operator+=(const GModint &g) { return *this = *this + g; }

        const GModint operator-=(const GModint &g) { return *this = *this - g; }

        const GModint operator*=(const GModint &g) { return *this = *this * g; }

        const GModint operator/=(const GModint &g) { return *this = *this / g; }

        const GModint operator^=(const GModint &g) { return *this = *this ^ g; }

        const GModint operator-() const { return GModint(val == 0 ? 0 : MOD - val, true); }

        const GModint operator+(const GModint &g) const {
            ll newval = val + g.val;
            if (newval >= MOD)
                newval -= MOD;
            return GModint(newval, true);
        }

        const GModint operator-(const GModint &g) const { return *this + (-g); }

        const GModint operator*(const GModint &g) const { return GModint(1ll * val * g.val); }

        const GModint operator/(const GModint &g) const { return *this * g.inv(); }

        template<class T>
        const GModint operator^(const T t) const { return GModint(modpow(val, t, MOD)); }

        const GModint inv() const { return GModint(modinv(val, MOD)); }
    };

    using Modint = GModint<1000000007>;
}

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

    int n; cin >> n;
    map<string, int> m;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        m[s]++;
    }
    int mxv = 0;
    vector<pair<string, int>> v(m.begin(), m.end());
    sort(v.begin(), v.end());
    for (auto p : v) mxv = max(mxv, p.second);
    for (auto p : v) if (p.second == mxv) {
        cout << p.first << endl;
    }
}


Measured memory_bytes: 27008
#include <stdio.h>
#include <math.h>

int main(void) {
	int N;
	int I[512];
	while(scanf("%d",&N)==1 && N!=0) {
		int i;
		double score=1e300;
		int ansS=0,ansA=0,ansC=0;
		int S,A,C;
		for(i=0;i<N;i++) {
			if(scanf("%d",&I[i])!=1)return 1;
		}
		for(S=0;S<=15;S++) {
			for(A=0;A<=15;A++) {
				for(C=0;C<=15;C++) {
					int Ocnt[256]={0};
					int R=S;
					double cur_score=0;
					for(i=0;i<N;i++) {
						R=(A*R+C)%256;
						Ocnt[(I[i]+R)%256]++;
					}
					for(i=0;i<256;i++) {
						double b=(double)Ocnt[i]/N;
						/* log no tei no sa wa teisuubai */
						if(Ocnt[i]>0)cur_score-=b*log(b);
					}
					if(cur_score+1e-7<score) {
						score=cur_score;
						ansS=S;
						ansA=A;
						ansC=C;
					}
				}
			}
		}
		printf("%d %d %d\n",ansS,ansA,ansC);
	}
	return 0;
}

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

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

	for(int i=0; i<n; i++)
	{
		int out=0,bass=0,point=0;
		string s;

		while(cin>>s)
		{
			if( s=="HIT") bass++;
			else if( s=="OUT" ) out++;
			else {
				point += bass+1;
				bass=0;
			}

			if( bass == 4 ) {
				point++;
				bass=bass-1;
			}
			if( out == 3 ) break; 
		}
		cout<<point<<endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

int main(){
  ll N; cin>>N;
  vector<vector<pii>> left(1001),right(1001);
  REP(i,N) {ll x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; left[x1].PB({y1,y2}); right[x2].PB({y1,y2});}
  ll ans=0;
  REP(y,1001) {
    ll num=0;
    REP(x,1001) {
      for(pii p:right[x]) if(p.first<=y&&y<p.second) num--;
      for(pii p:left[x]) if(p.first<=y&&y<p.second) num++;
      ans=max(ans,num);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8080
#include <iostream>

using namespace std;

#define repeat(i, start, end) for (int(i) = (start); (i) < (end); (i)++)
#define repeatR(i, end, start) for (int(i) = (end); (i) >= (start); i--)
#define times(n) for (int i = 0; i < n; i++)
#define len(ar) (sizeof(ar) / sizeof(ar[0]))

// 10000*d1 + 1000*d2 + 100*d3 + 10*d4 + *d5

int main() {
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  int d[5];

  repeat(i, A, B + 1) {
    int tmp = i;
    int j = 0;
    while (tmp != 0) {
      d[j] = tmp % 10;
      tmp /= 10;
      j++;
    }
    if (d[0] == d[4] && d[1] == d[3]) cnt++;
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)



Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

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

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

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


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

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


int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b and b == c) cout << "Yes" << BR;
  else cout << "No" << BR;
  return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    string s;
    cin >> s;

    int now = n;

    vector<int> ans;
    while (now > 0) {
        bool fl = false;
        for (int i = max(0ll , now - m); i < now; i++) {
            if (s[i] == '0') {
                ans.push_back(now - i);
                now = i;
                fl = true;
                break;
            }
        }
        if (!fl)
            break;
    }
    if (now)
        cout << -1 << endl;
    else
        for(int i = ans.size() - 1; i >= 0; i--)
            cout << ans[i] << " ";
}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
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; }

int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	ll n; cin >> n;
	
	if(n%2==1){
		
		cout << 0 <<endl;
		return 0;
	}
	
	n/=2;
	
	ll c=0;
	
	for(int i=1;i>=1;i++){
		ll q=pow(5,i);
		if(q>n) break;
		c+=n/q;
	}
		
	
	cout << c << "\n";
	
	return 0;
}


Measured memory_bytes: 512
from itertools import combinations_with_replacement

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

mx = 0
for AN in combinations_with_replacement(range(1, M+1), N):
	score = 0
	for a, b, c, d in abcdn:
		score += d if AN[b-1] - AN[a-1] == c else 0
	mx = max(score, mx)
print(mx)

Measured memory_bytes: 9080
#include <stdio.h>

int main(void){
	int x,y;
	
	while(1){
		scanf("%d %d", &x, &y);
		if(x==0 && y==0) break;
		else{
			if(x>=y) printf("%d %d\n", y,x);
			else printf("%d %d\n", x,y);
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n;
	cin >> n;
	cout << (n+1)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int main(){
  int n , K;
  cin >> n >> K;
  ll ans = 0;
  if(K == 0)
    ans += n;
  rep(b,2,n+1) if(b - 1 >= K) {
    ans += n / b * (b - K);
    // 1 2 3 4 5 0
    int remain = n % b;
    if(K == 0)
      ans += remain;
    else
      ans += max(0 , min(b - 1 , remain) - K + 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

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

int main() {
	string s;
	int ans = 700;
	cin >> s;
	rep(i, 3){
		if(s[i] == 'o'){
			ans += 100;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import operator
from bisect import bisect_left
from math import pi
import decimal


def lis(A):
    L = [A[0]]
    for a in A[1:]:
        if a > L[-1]:
            L.append(a)
        else:
            L[bisect_left(L, a)] = a
    return len(L)


def solve():
    x1, y1, x2, y2 = map(int, input().split())
    if x1 > x2:
        x1, y1, x2, y2 = x2, y2, x1, y1
    is_down = y1 > y2
    if is_down:
        y1, y2 = -y1, -y2
    base = decimal.Decimal(100) * (x2 - x1 + y2 - y1)

    n = int(input())
    fountains = []
    for _ in range(n):
        x, y = map(int, input().split())
        if is_down:
            y = -y
        if x < x1 or x2 < x or y < y1 or y2 < y:
            continue
        fountains.append((x, y))

    if not fountains:
        return str(base)

    dpi = decimal.Decimal(pi)

    fountains.sort()
    fountains_y = list(map(operator.itemgetter(1), fountains))
    mc = lis(fountains_y)
    if mc == min(x2 - x1, y2 - y1) + 1:
        dist = base + (dpi * 5 - 20) * (mc - 1) + dpi * 10 - 20
    else:
        dist = base + (dpi * 5 - 20) * mc
    return str(dist)


print(solve())


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

using namespace std;

const int MX = 200, MB = 60;

long long a[MX], base[MB];
char s[MX + 1];

int main() {
	int T;
	ignore = scanf("%d", &T);
	while (T--) {
		int n;
		ignore = scanf("%d", &n);
		for (int i = 0; i < n; i++) ignore = scanf("%lld", a + i);
		ignore = scanf("%s", s);
		
		fill(base, base + MB, 0);
		
		int ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			bool added = false;
			long long val = a[i];
			for (int j = 0; j < MB; j++) {
				if (((val >> j) & 1) == 0) continue;
				
				if (base[j] == 0) {
					base[j] = val;
					added = true;
					break;
				}
				
				val ^= base[j];
			}
			
			if (s[i] == '1' && added) {
				ans = 1;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}


Measured memory_bytes: 3828
#include<stdio.h>

int main(void) {

	int n, i;
	int a[100];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (i = n - 1; i >= 0;i--) {
		printf("%d", a[i]);
		if (i == 0) {
			continue;
		}
		printf(" ");
		
	}

	printf("\n");

	return(0);
}


Measured memory_bytes: 2048
L,R = map(int,input().split())
min = L*(L+1)%2019
a = L
b = L +1
if(R > L + 2019):
    R = L + 2019
for i in range(L,R+1):
    for j in range(i+1,R+1):
        if(i<j):
            if(min > (i*j)%2019):
                min = (i*j)%2019
                a = i
                b = j
        if(min == 0):
            break
    if(min==0):
        break
print(min)

Measured memory_bytes: 3064
S = input()
if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	998244353;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, q, x, K;
string s,t;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	vll cnt(26,0);
	for(auto ch  : s) cnt[ch-'a']++;
	for(ll i=0;i<26;i++) {
		if(cnt[i]==0) {
			cout<<(char)(i+'a');return;
		}
	}
	cout<<"None";
}


int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

typedef struct pyramid {
	int x;
	int y;
	int h;
} P;

int main()
{
	int N;
	cin >> N;
	vector<P> v(N);
	vector<P> can;

	for (int i = 0; i < N; ++i) {
		cin >> v[i].x >> v[i].y >> v[i].h;
	}

	for (int cx = 0; cx < 101; ++cx) {
		for (int cy = 0; cy < 101; ++cy) {
			for (auto it = v.begin(); it != v.end(); ++it) {
				int t = max(abs((*it).x - cx) + abs((*it).y - cy) + (*it).h, 0);
				P c = {c.x = cx, c.y = cy, c.h = t};
				can.push_back(c);
			}
		}
	}

	for (auto it = can.begin(); it != can.end(); ++it) {
		int flag = 0;
		for (auto ite = v.begin(); ite != v.end(); ++ite) {
			int hi = max((*it).h - abs((*ite).x - (*it).x) - abs((*ite).y - (*it).y), 0);
			if (hi != (*ite).h)
				break;
			flag++;
		}
		if (flag == N) {
			cout << (*it).x << " " << (*it).y << " " << (*it).h << endl;
			return 0;
		}
	}

	assert(false);

}



Measured memory_bytes: 14316
#include <iostream>
#include <string>
typedef long double l;
using namespace std;

int main()
{
    int N;
    cin >> N;
    l ans = 0;
    for (int i = 0; i < N; i++)
    {
        l x;
        string y;
        cin >> x >> y;
        if (y == "JPY")
        {
            ans += x;
        }
        else
        {
            ans += x * 380000.0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque


def calc_next_ones_places(last_ones_place):
    """次の Lunlun数 の一の位の数を返す"""
    if last_ones_place == 0:
        return [last_ones_place, last_ones_place+1]
    elif last_ones_place == 9:
        return [last_ones_place-1, last_ones_place]
    else:
        return [last_ones_place-1, last_ones_place, last_ones_place+1]


def calc_k_th_lunlun_num(k):
    """
    Kが10以上の時、K番目のLunlun数を計算する
    """
    lunlun_num_queue = deque()

    for i in range(1, 10):
        lunlun_num_queue.append(i)

    iterate_num = 9
    while True:
        last_lunlun_num = lunlun_num_queue.popleft()
        last_ones_place = str(last_lunlun_num)[-1]
        next_ones_places_list = calc_next_ones_places(int(last_ones_place))
        for next_ones_place in next_ones_places_list:
            lunlun_num = 10*last_lunlun_num + next_ones_place
            lunlun_num_queue.append(lunlun_num)

            iterate_num += 1
            if iterate_num == k:
                return lunlun_num


def main():
    K = int(input())
    if K <= 9:
        print(K)
    else:
        k_th_lunlun_num = calc_k_th_lunlun_num(K)
        print(k_th_lunlun_num)


main()


Measured memory_bytes: 6124
using System;
using System.Linq;

class Problem {
    public static double p1(double[] x, double[] y) {
        var res = 0.0;
        for (var i = 0; i < x.Length; i++) res += Math.Abs(x[i] - y[i]);
        return res;
    }
    public static double p2(double[] x, double[] y) {
        var res = 0.0;
        for (var i = 0; i < x.Length; i++) {
            var tmp = Math.Abs(x[i] - y[i]);
            res += tmp * tmp;
        }
        return Math.Sqrt(res);
    }
    public static double p3(double[] x, double[] y) {
        var res = 0.0;
        for (var i = 0; i < x.Length; i++) {
            var tmp = Math.Abs(x[i] - y[i]);
            res += tmp * tmp * tmp;
        }
        return Math.Pow(res, 1.0 / 3.0);
    }
    public static double pinf(double[] x, double[] y) {
        var tmp = new double[x.Length];
        for (var i = 0; i < tmp.Length; i++) tmp[i] = Math.Abs(x[i] - y[i]);
        return tmp.Max();
    }
    public static void Main() {
        Console.ReadLine();
        var x = Console.ReadLine().Split().Select(double.Parse).ToArray();
        var y = Console.ReadLine().Split().Select(double.Parse).ToArray();
        Console.WriteLine(p1(x, y));
        Console.WriteLine(p2(x, y));
        Console.WriteLine(p3(x, y));
        Console.WriteLine(pinf(x, y));
    }
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

// ???????????±?°??§???????????????????????????
int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

// ?????????????????????????¬¨??°??????????????????????????±??? key ??§???????¬?????????§???
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++){
    sum += p*getChar(str[i]);
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M;}
int h2(int key){ return 1 + (key % (M - 1));}

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
	    strcpy(H[h],str);
	    return 0;
    }
  }
  return 0;
}

int main(){
	int i, n, h;
	char str[L],com[9];
	for(i=0;i<M;i++) H[i][0] = '\0';
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",com,str);

		if(com[0] == 'i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 16968
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007

pair<long, long> calcDigit(int n) {
 
	pair<long, long> num;
	num.first = n % 10;
	while (n / 10) {
		n /= 10;
	}
	num.second = n;
	return num;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long idx=0;
    long N;
    cin >> N;
    long count = 0;
    std::vector<std::vector<int>> mat(15, vector<int>(15, 0));
    // A の末尾の桁が B の先頭の桁に等しく、A の先端の桁が B の末尾の桁に等しい
    // 先端と末尾だけ考えればいい
    for (int i = 1; i <= N; i++)
	{
		int head = 0;
		int tail = 0;
		tie(tail, head) = calcDigit(i);
        mat[head][tail]++;
	}
    
    int ans = 0;
	for (int i = 0; i <= 9; i++)
	{
		for (int j = 0; j <= 9; j++)
		{
			count += mat[i][j] * mat[j][i];
		}
	}
 
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256