akhauriyash/Code-Regression huggingface dataset:
import time

start_time = time.time()

#input
D = int(input())
c_list = list(map(int, input().split()))

s_grid = []
for i in range(D):
    array = list(map(int, input().strip().split(' ')))
    s_grid.append(array)

t_list = [1 for i in range(D)] #task_list

def calculate_score(t_list,score_list,last_grid,change_query_number):
    score_list = score_list[:change_query_number]
    last_grid = last_grid[:change_query_number]

    if len(score_list) > 1:
        score = score_list[change_query_number-1]
        last_list = last_grid[change_query_number-1]
    else:
        score = 0
        last_list = [0 for i in range(26)]

    for d in range(change_query_number,D):
        score += s_grid[d][t_list[d]]
        last_list = [n+1 for n in last_list]
        last_list[t_list[d]] = 0
        for i in range(26):
            score -= c_list[i]*last_list[i]
        score_list.append(score)
        last_grid.append(last_list)
    return score_list, last_grid

#first cal.
previous_s, previous_l = calculate_score(t_list,[],[[0 for i in range(26)]],0)
score = previous_s[-1]

for k in range(D - 1, 0, -1):
    X = -1  # k-日目に変える番号を探す
    t_list_loop = t_list
    for i in range(26):  # 26通り試す
        t_list_loop[k] = i
        score_list_k, last_grid_k = calculate_score(t_list_loop, previous_s, previous_l, k)
        if score_list_k[-1] > score:
            X = i
            score = score_list_k[-1]
            score_list_t = score_list_k
            last_grid_t = last_grid_k

    if X != -1:
        t_list[k] = X
        previous_s = score_list_t
        previous_l = last_grid_t

    # print(k,X,score)

    if time.time() - start_time > 1.9:
        break

#final result
for j in range(len(t_list)):
    print(int(t_list[j]) + 1)

Measured memory_bytes: 9776
use std::io::stdin;

fn read_ints() -> Vec<i32> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map(|token| token.parse().unwrap()).collect()
}

fn main () {
    let values = read_ints();
    let max_value = values.iter().max_by_key(|&x| x).unwrap();
    let min_value = values.iter().min_by_key(|&x| x).unwrap();
    let answer = max_value - min_value;
    println!("{}", answer);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        int n, k;
        cin >> n >> k;
        int a[n], dp[n];
        for(int i=0; i<n; i++){
    		cin >> a[i];
    		dp[i] = INT_MAX;
        }
     
        dp[0] = 0, dp[1] = abs(a[1] - a[0]);
        for(int i=2; i<n; i++){
    		for(int j=1; j<=k; j++){
    			if(i-j >= 0) dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
    		}
        }
     
        cout << dp[n-1];
     
        return 0;
    }

Measured memory_bytes: 4380
import bisect,copy

N=int(input())
A=list(map(int,input().split()))

data=[0 for i in range(0,N+1)]
for i in range(0,N):
    data[A[i]]+=1

X=[]
for i in range(0,N+1):
    if data[i]!=0:
        X.append(data[i])

X.sort()
n=len(X)
Y=copy.copy(X)
for i in range(1,n):
    Y[i]+=Y[i-1]

ans={i:0 for i in range(0,N+1)}
ans[0]=float('inf')
#num以下の整数の和+num*(num+1以上の個数)
for i in range(1,N+1):
    index=bisect.bisect_left(X,i+1)
    if index!=0:
        t=Y[index-1]+(n-index)*i
    else:
        t=(n-index)*i
    ans[i]=t//i


pointer=N
i=1
while N+1>i:
    if ans[pointer]>=i:
        print(pointer)
        i+=1
    else:
        pointer-=1

Measured memory_bytes: 123700
from collections import defaultdict
from copy import deepcopy
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))


def dfs(graph, v, visited):
    visited.add(v)
    for nv in graph[v]:
        if nv not in visited:
            dfs(graph, nv, visited)
    return visited


def is_connected(graph, nodes_cnt):
    visited = dfs(graph, 1, set())
    # 頂点1から一気に全頂点に訪問できているか
    if len(visited) == nodes_cnt:
        return True
    else:
        return False


n, m = LI()
edges = [LI() for _ in range(m)]
g = defaultdict(set)
for u, v in edges:
    g[u].add(v)
    g[v].add(u)

ans = 0
# 辺を一本ずつ除いていく
for u, v in edges:
    H = deepcopy(g)
    H[u] -= {v}
    H[v] -= {u}
    if not is_connected(H, n):
        ans += 1
print(ans)


Measured memory_bytes: 9596
#include <stdio.h>

int main(){
    int n, x;
    int a, b ,c;
    int ans;
    
    while(1){
        scanf("%d %d", &n, &x);
        if(n==0 && x==0) break;
        int max;
        if(x>n) max = n;
        else max = x;
        ans = 0;
        for(a=1; a<=max; a++){
            for(b=a+1; b<=max; b++){
                c = x-a-b;
                if(c>b && c<=n) ans++;
            }
        }
        printf("%d\n", ans);
    }
    
}



Measured memory_bytes: 2016
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N,K;
    cin>>N>>K;
    vector<bool> NOHAND(N);
    rep(i,N) NOHAND.at(i)=true;
    rep(i,K){
        ll d;
        cin>>d;
        rep(j,d){
            ll A;
            cin>>A;
            NOHAND.at(A-1)=false;
        }
    }
    ll ans=0;
    rep(i,N) if(NOHAND.at(i)) ans++;
    cout<<ans<<endl;
    return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, 0, n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for(auto it = mp.begin(); it != mp.end(); it++) {
    if(it->first <= it->second) ans += it->second - it->first;
    else ans += it->second;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4736
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-25 16:54:48
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
#include<set>
#define pii std::pair<int,int>
const int N=200010;
i64 n,pre[N],suf[N],k,a[N],l[N],r[N],ans,s[N],l_[N],r_[N];
std::set<pii> S;
int q[N],m,m_;
int main()
{
	n=read(); k=read();
	fr(i,1,n) a[i]=read();
	fr(i,1,n) if(a[i]!=a[i-1]) S.insert(pii(a[i],i));
	fr(i,2,n){ pre[i]=i-1; suf[i-1]=i; }
	fr(i,1,n) l[i]=r[i]=1;
	while(!S.empty())
	{
		int u=S.begin()->second,v=u,na=a[u]+1; q[m=1]=u; S.erase(S.begin());
		suf[pre[u]]=pre[suf[v]]=0;
		while(a[suf[v]]==a[u]) q[++m]=(v=suf[v]);
		fr(i,1,m){ s[i]=s[i-1]+l[q[i]]; ans+=(l[q[i]]+s[std::max(i-k+1,0ll)])*r[q[i]]; }
//		fr(i,1,m) printf("+ %d %d\n",l[q[i]],r[q[i]]);
//		printf("+%d %d %d\n",int(m),int(na-1),int(ans));
		m_=m/k;
		if(!m_) continue;
		fr(i,1,m) s[i]=s[i-1]+l[q[i]];
		fr(i,1,m_) l_[i]=s[m-(m_-i+1)*k+1];
		fd(i,m_,2) l_[i]-=l_[i-1];
//		fr(i,1,m_) printf("%d%c",s[m-(m_-i+1)*k+1],i==end_i?'\n':' ');
		fr(i,1,m) s[i]=s[i-1]+r[q[i]];
		fr(i,1,m_) r_[i]=s[m]-s[i*k-1];
		fr(i,1,m_-1) r_[i]-=r_[i+1];
//		fr(i,1,m_) printf("- %d %d\n",l_[i],r_[i]);
		fr(i,1,m_){ l[q[i]]=l_[i]; r[q[i]]=r_[i]; a[q[i]]=na; }
		suf[pre[u]]=u; pre[suf[v]]=q[m_]; suf[q[m_]]=suf[v]; m=m_;
		fr(i,1,m){ s[i]=s[i-1]+l[q[i]]; ans-=(l[q[i]]+s[std::max(i-k+1,0ll)])*r[q[i]]; }
		if(a[pre[u]]!=na) S.insert(pii(na,u));
		if(a[suf[v]]==na) S.erase(pii(na,suf[v]));
//		printf("-%d %d %d\n",int(m),int(na-1),int(ans));
	}
	printf("%lld\n",ans);
	return 0;
}

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

void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(0, c-(a-b));
}

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


Measured memory_bytes: 256
import Data.List

main :: IO ()
main = do
    n <- (read :: String -> Int) <$> getLine
    as <- map read . words <$> getLine
    putStrLn . unwords . map show . binominalCoefficients $ as

nearest n = foldr1 near
    where
        near a b
            | abs (n - a) < abs (n - b) = a
            | abs (n - a) > abs (n - b) = b
            | otherwise                 = if a <= b then a else b

binominalCoefficients as =
    if even ai
        then [ai, nearest (ai `div` 2) as]
        else [ai, nearest ((ai + 1) `div` 2) as]
    where
        ai = maximum as

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

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

    int x = 0;

    // 分割する位置に関してループを回す
    for (int i = 1; i < N; i++)
    {
        int xtemp = 0;

        // 文字'a'から'z'までのループ
        // ASCIIコードにおいて、'a', 'b', ... , 'z'は連番になっているので、
        // インクリメントすることで'a'から'z'に関するループを以下のように記述することができる。
        for (char c = 'a'; c <= 'z'; c++)
        {
            bool left = false;
            bool right = false;
            for (int j = 0; j < i; j++)
            {
                if (S[j] == c)
                {
                    left = true;
                }
            }
            for (int k = i; k < N; k++)
            {
                if (S[k] == c)
                {
                    right = true;
                }
            }

            if (left && right)
            {
                xtemp++;
            }
        }

        if (xtemp > x)
        {
            x = xtemp;
        }

    }

    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner
 
object Main {
  def main(args:Array[String]):Unit = {
    val sc:Scanner = new Scanner(System.in)
    val tmp = Array(sc.nextInt(), sc.nextInt(), sc.nextInt())
 
    //if ((a == b && a < c) || (b == c && a > b) || (c == a && a < b)) {
    if (tmp.sorted sameElements Array(5, 5, 7)) {
      print("YES")
    } else {
      print("NO")
    }
  }
}

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

      int N = sc.nextInt();
      int k = sc.nextInt();
      String S = sc.next();
      char[] c = new char[N];

      for(int i = 0;i<N;i++){
        c[i] = S.charAt(i);
      }

      if(c[k-1]=='A'){
        c[k-1]='a';
      }
      if(c[k-1]=='B') {
        c[k-1]='b';
      }
      if(c[k-1]=='C') {
        c[k-1]='c';
      }

      for(int i = 0;i<N;i++){
        System.out.print(c[i]);
      }
      System.out.println();

  }
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 3003;

i64 n, T;

i64 a[MAXN];
i64 b[MAXN];

pair<i64, i64> dp[MAXN][MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> T;

    for (i64 i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }

    for (i64 i = 1; i <= n; i++) {
        for (i64 t = 1; t < T; t++) {
            dp[i][t] = dp[i - 1][t];
        }

        for (i64 t = a[i]; t < T; t++) {
            pair<i64, i64> c = { dp[i - 1][t - a[i]].first + b[i], i };
            if (c.first > dp[i][t].first
                || (c.first == dp[i][t].first && (a[c.second] < a[dp[i][t].second] || !dp[i][t].second))) {
                dp[i][t] = c;
            }
        }
    }


    i64 t = T - 1;
    i64 c = dp[n][t].second;
    map<i64, i64> q;
    for (i64 i = 1; i <= n; i++) {
        q[b[i]]++;
    }
    set<i64> z;

    while (c) {
        q[b[c]]--;
        if (!q[b[c]]) {
            q.erase(b[c]);
        }
        z.insert(c);
        t -= a[c];
        c = dp[c - 1][t].second;
    }

    i64 R = dp[n][T - 1].first + (q.empty() ? 0 : q.rbegin()->first);
    cout << R << endl;

    return 0;
}


Measured memory_bytes: 141312
# scipy使う場合
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n,m,l = map(int,input().split())

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue
def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d

d = make_d_matrix(n,m)
csr_graph = csr_matrix(d)
d1 = floyd_warshall(csr_graph,directed=False)

inf = 10**3
for i in range(n):
    for j in range(n):
        d1[i][j] = 1 if (d1[i][j] <= l) else inf

csr_graph = csr_matrix(d1)
d2 = floyd_warshall(csr_graph,directed=False)

q = int(input())

for _ in range(q):
    s,t = map(int, input().split())
    tmp = d2[s-1][t-1]
    if(tmp >= inf):
        print(-1)
    else:
        print(int(tmp-1))

Measured memory_bytes: 20640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		boolean ans = false;
		if ((a * b) % 2 != 0) {
			ans = true;
		}
		System.out.println(ans ? "Yes" : "No");
	}

}


Measured memory_bytes: 35712
from math import *

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
vv = list(zip(x, y))
da = lambda v, p: pow(sum(map(lambda q: pow(abs(q[0] - q[1]), p), v)), 1 / p)
di = lambda v: max(map(lambda q: abs(q[0] - q[1]), v))
for i in range(3):
    print(da(vv,i+1))
print(di(vv))



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

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

    stack<char> st;
    st.push(s[0]);
    int ans = 0;
    for(int i = 1; i < s.size(); i++){
        if(!st.empty() && st.top() != s[i]){
            st.pop();
            ans += 2;
        } else {
            st.push(s[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, r;
int main() {
	scanf("%d %d", &n, &r);
	if (10 <= n)
		printf("%d\n", r);
	else
		printf("%d\n", r + 100 * (10 - n));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    ll n, T, ans=0;
    cin >> n >> T;
    vector<int> t(n);
    rep(i, n) cin >> t.at(i);
    rep(i, n-1){
        if(t.at(i+1) - t.at(i) < T)ans += t.at(i+1)-t.at(i);
        else ans += T;
    }
    cout << ans + T;
}  

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n; read(n);
  vector <int> a(n);
  for(int i = 0; i < n; i++) {
    read(a[i]);
  }
  int ans = 1e9 + 10;
  for(int i = 1; i <= 100; i++) {
    int cur = 0;
    for(int j = 0; j < n; j++) {
      cur += (a[j] - i) * (a[j] - i);
    }
    ans = min(ans, cur);
  }
  print(ans);
}

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

#define ll long long 
#define all(x) (x).begin(),(x).end()
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define f(i,x,z) for(ll i=x;i<z;i++)
#define debug(x) cout<<'DEBUG------> '<<x<<endl
#define srt(v) sort(v.begin(), v.end())
#define clr(x) memset(x, 0, sizeof(x)) 
#define mi map<int,int>
#define mod 1000000007
//  for (auto &a : A)
//cin >> a;
//for (auto m : map) {

int main()
{
//   freopen('input.txt', 'r', stdin);
//   freopen('output.txt', 'w', stdout);
    ios::sync_with_stdio(0);// Input and output clearance
    cin.tie(0);
   string aa;
   cin>>aa;
   if(aa[aa.length()-1]=='s')
   {
       cout<<aa<<"es";
   }
   else
   {
       cout<<aa<<"s";
   }
   
   return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int T[101];
int M;
int P[101],X[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	int tot=0;
	cin>>N;
	FOR(i,N) cin>>T[i], tot+=T[i];
	cin>>M;
	
	int mi=tot;
	FOR(i,M) {
		cin>>P[i]>>X[i];
		P[i]--;
		cout<<tot-T[P[i]]+X[i]<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
 
using namespace std;

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

// 最小公倍数
long long lcm(long long a, long long b){
    long long g = gcd(a,b);
    return a / g * b;
}
 
int main(){
    long long int N, M;
    string S, T;

    //cin >> N >> M >> S >> T;
    scanf("%d %d", &N, &M);
    cin >> S >> T;

    long long int L = lcm(N, M);

    //cout << L << endl;

    long long int L_N = L / N;
    long long int L_M = L / M;

    //cout << L_N << endl;
    //cout << L_M << endl;

    if(L_N == L_M && S != T){
        cout << "-1" << endl;
        return 0;
    }

    if(S[0] != T[0]){
        cout << "-1" << endl;
        return 0;
    }

    long long int L_NM = lcm(L_N, L_M);
    long long int tmp = L_NM;

    if(L < L_NM+1){
        cout << L << endl;
        return 0;
    }

    while(tmp < L){
        long long int ss = tmp / L_N;
        long long int tt = tmp / L_M;
        if(N <= ss || M <= tt){
            cout << "-1" << endl;
            return 0;
        }
        if(S[ss] != T[tt]){
            cout << "-1" << endl;
            return 0;
        }
        tmp += L_NM;
    }

    cout << L << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string.h>
#define   FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}

template<typename T>
istream& operator >>(istream& is, vector<T>& vec){
    for(T& x: vec) is >>x;
    return is;
}
int main() {
	int a, b;
	cin >> a >> b;
	if (b % a == 0) {
		cout << a + b;
		return 0;

	} else {
		cout << b - a;
		return 0;
	}
}

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

using namespace std;
using ll = long long;


int main()
{
	string s;
	int a[3] = {};
	cin >> s;
	if(s.size() == 1){cout << "YES" << endl; return 0;}
	for(auto i : s)a[i - 'a']++;
	sort(a, a + 3);
	vector<int> ar(s.size());
	ar[0] = 2; a[2]--;
	ar[1] = 1; if(--a[1] < 0) {
		cout << "NO" << endl;
		return 0;
	}
	int n = s.size();

	for(int i = 2; i < n; i++) {

		for(int j = 0; j < 3; j++) {
			if(j != ar[i - 1] && j != ar[i - 2]) {
				//cout << a[j] << endl;
				ar[i] = j;
				if(--a[j] < 0){cout << "NO" << endl;
				return 0;}
			}
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 896
//__professor_
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define pb push_back
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define test ll T;cin>>T;while(T--)
#define inf 1000000000000000001
#define deb(x) cout<<#x<<' '<<x<<endl;
const long long int M=1e9+7;
const double pi=3.141592653589793238463;
typedef tree<int, null_type, less<int>, rb_tree_tag,
	tree_order_statistics_node_update> indexed_set; 

int main()
{
	FAST;
	ll a[5];
	for(ll i=0;i<5;i++)
		cin>>a[i];
	for(ll i=0;i<5;i++){
		if(a[i]==0)
			cout<<i+1;
	}
	return 0;
}




Measured memory_bytes: 3584
// abc124_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int A, B;
    cin >> A >> B;

    int ans;
    if (A > B){
        ans = A + max(A-1,B);
    } else {
        ans = B + max(B-1,A);
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,x,y,z;
    cin>>n;
    x=n/1000;
    n%=1000;
    y=n/100;
    n%=100;
    z=n/10;
    n%=10;
    if((x==y && x==z && y==z && x!=n) || (y==z && z==n && y==n && x!=n) || (x==y && x==z && x==n && y==z && y==n && z==n)) cout<< "Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    if(a<=b && a<=c)
    {
        if(b<=c) cout<<a<<" "<<b<<" "<<c;
        else cout<<a<<" "<<c<<" "<<b;
    }
    else
    if(b<=a && b<=c)
    {
        if(a<=c) cout<<b<<" "<<a<<" "<<c;
        else cout<<b<<" "<<c<<" "<<a;
    }
    else
    if(c<=a && c<=b)
    {
        if(a<=b) cout<<c<<" "<<a<<" "<<b;
        else cout<<c<<" "<<b<<" "<<a;
    }
    cout<<"\n";
    return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  bool ans = true;

  for (int i = 0;i < n/2;i++){
    if (s[i] != s[n/2+i]){
      ans = false;
      break;
    }
  }
  if (n == 1) ans = false;
  if (n % 2 != 0) ans = false;

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

}

Measured memory_bytes: 256
def main():
    N, *LR = map(int, open(0).read().split())
    LR = list(zip(*[iter(LR)] * 2))

    max_l = max(l for l, _ in LR)
    min_r = min(r for _, r in LR)

    ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in LR]
    ab.sort()

    mi = float("inf")
    ma = max(r - l + 1 for l, r in LR) + max(0, min_r - max_l + 1)
    for i in range(N - 1):
        mi = min(mi, -ab[i][1])
        ma = max(ma, mi + ab[i + 1][0])

    print(ma)

main()


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

using namespace std;
#ifdef KENECHI

template<typename L, typename R>
ostream &operator<<(ostream &out, const pair<L, R> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
    static ostream &print(ostream &out, const Tuple &t) {
        return TuplePrinter<Tuple, N - 1>::print(out, t) << ", " << get<N - 1>(t);
    }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
    static ostream &print(ostream &out, const Tuple &t) { return out << get<0>(t); }
};

template<typename... Args>
ostream &print_tuple(ostream &out, const tuple<Args...> &t) {
    return TuplePrinter<decltype(t), sizeof...(Args)>::print(out << "(", t) << ")";
}

template<typename ...Args>
ostream &operator<<(ostream &out, const tuple<Args...> &t) {
    return print_tuple(out, t);
}

template<typename T>
ostream &operator<<(enable_if_t<!is_same<T, string>::value, ostream> &out, const T &arr) {
    out << "{";
    for (auto &x: arr) out << x << ", ";
    return out << (arr.size() ? "\b\b" : "") << "}";
}

template<size_t S>
ostream &operator<<(ostream &out, const bitset<S> &b) {
    for (int i = 0; i < S; ++i) out << b[i];
    return out;
}

void debug_out() { cerr << "\b\b " << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << H << ", ", debug_out(T...); }

void debug2_out() { cerr << "-----DEBUG END-----\n"; }

template<typename Head, typename... Tail>
void debug2_out(Head H, Tail... T) {
    cerr << "\n";
    for (auto x: H) cerr << x << "\n";
    debug2_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#define debug2(...) cerr << "----DEBUG BEGIN----\n[" << #__VA_ARGS__ << "]:", debug2_out(__VA_ARGS__)
#else
#define debug(...) 42
#define debug2(...) 42
#endif

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

void solve() {
    int n, x, m;
    cin >> n >> x >> m;

    map<int, int> mp;
    int ans = 0, cur = x;
    vector<int> val;
    for (int i = 1; i <= n; i++) {
        if (mp.count(cur))break;
        if (cur == 0) {
            cout << accumulate(val.begin(), val.end(), 0ll) << endl;
            return;
        }
        mp[cur] = val.size();
        val.push_back(cur);
        cur = (cur * cur) % m;
    }

    for (int i = 0; i < mp[cur]; i++)ans += val[i], n--;
    int repSum = 0;
    for (int i = mp[cur]; i < val.size(); i++)repSum += val[i];

    int sz = (int) val.size() - mp[cur];
    ans = ans + repSum * (n / sz);
    n = n % sz;
    int id = mp[cur];
    while (n > 0)ans += val[id++], n--;

    cout << ans << endl;
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 6680
#include<iostream>
#include<vector>
 
using namespace std;
 
int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	int count = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int sum = 0;
			for (int k = 0; k < d; k++) {
				int  sq = abs(x[j][k] - x[i][k]);
				sum += sq*sq;
			}
			bool ans = false;
			for (int l = 0; l <= sum; l++) {
				if (sum == l*l) {
					ans = true;
				}
			}
			if (ans)count++;
		}
	}
	cout << count << endl;
 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
long long i, n, m = 0;

int main() {
	cin >> n;
	for (i = sqrt(n); i > 1; i--) {
		if (n % i == 0) {
			m = n / i;
			break;
		}
	}
	if (m == 0) cout << n - 1 << endl;
	else cout << i + m - 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 9;

int _;

//========================================================================
int a[5];
//========================================================================
int main()
{
    for(int i=1;i<=3;i++)
    {
        scanf("%d",&a[i]);
    }
    int k,ans=0;
    scanf("%d",&k);
    if(a[1]>k) ans+=k,k=0;
    else ans+=a[1],k-=a[1];
    if(a[2]>k) k=0;
    else k-=a[2];
    if(a[3]>k) ans-=k,k=0;
    else ans-=a[3],k-=a[3];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3796
#include <stdio.h>

int     main(void)
{
    int a;
    int b;
    
    scanf("%d %d",&a,&b);
    if (-1000 <= a || b <= 1000)
    {
        if(a < b)
        {
            printf("a < b\n");
        }
        if(a > b)
        {
            printf("a > b\n");
        }
        if(a == b)
        {
            printf("a == b\n");
        }
    }
    return(0);
}


Measured memory_bytes: 2064
#include<stdio.h>

 int main(){
   int y, m, d;

   scanf("%d/%d/%d", &y, &m, &d);
   if(y < 2019){
     printf("Heisei\n");
   }
   else if(y == 2019 && m <= 4){
     printf("Heisei\n");
   }
   else{
     printf("TBD\n");
   }
   return 0;
 }
 


Measured memory_bytes: 128
N = gets.to_i
B = gets.split.map(&:to_i)
A = Array.new(N)
A[-1] = B[-1]
A[-2] = B[-1]
[*0..N-3].reverse.each do |i|
    A[i] = B[i]
    if B[i] < A[i+1] then
        A[i+1] = B[i]
    end
end
puts A.inject(:+)

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;
 
template<typename T>
struct is_vector : false_type{};
 
template<typename T>
struct is_vector<vector<T>> : true_type{};
 
template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

void solve() {
  int x, y; cin >> x >> y;
  int ans = 0;
  if (x <= 3) ans += (4-x) * 1e5;
  if (y <= 3) ans += (4-y) * 1e5;
  if (x == 1 && y == 1) ans += 4e5;
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
a=[[] for i in range(n)]
a[0]+=[h[0]]
for i in range(1,n):
  for j in range(len(a[i-1])):
    if h[i]-a[i-1][j]==0:
      if h[i] not in a[i]:
        a[i]+=[h[i]]
    if h[i]-a[i-1][j]>=1:
      if h[i] not in a[i]:
        a[i]+=[h[i]]
      if h[i]-1 not in a[i]:
        a[i]+=[h[i]-1]
if len(a[n-1])>0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 21928
#include <bits/stdc++.h>
#define MAX 3005
using namespace std;

typedef long long ll;

int dp[MAX][MAX], n, m;
string str1, str2;

int solve(int i, int j)
{
    if(i >= n || j >= m)
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
    int ret = 0;
    if(str1[i] == str2[j]){
        ret = 1 + solve(i + 1, j + 1);
    }
    else{
        ret = max(solve(i + 1, j), solve(i, j + 1));
    }
    return dp[i][j] = ret;
}

void printLCS(int i, int j)
{
    if(i >= n || j >= m)
        return;
    if(str1[i] == str2[j]){
        cout<<str1[i];
        printLCS(i + 1, j + 1);
    }
    else{
        if(dp[i+1][j] > dp[i][j+1]){
            printLCS(i + 1, j);
        }
        else{
            printLCS(i, j + 1);
        }
    }
}
int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    cin>>str1>>str2;    
    n = str1.size(), m = str2.size();
    memset(dp, -1, sizeof(dp));
    int res = solve(0, 0);
    //cout<<res<<endl;
    printLCS(0, 0);

    return 0;
}

Measured memory_bytes: 35840
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
using namespace std;

#define rip(i,n) (int i=0;i<(int)(n);i++)

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    vector<pair<int,pair<int,int>>> da(m);
    vector<int> p(m),y(m);
    for rip(i,m){
        scanf("%d%d",&da[i].first,&da[i].second.first);
        da[i].second.second=i;
    }
    sort(da.begin(),da.end());
    vector<pair<int,int>> ans(m);
    int co=1;
    ans[da[0].second.second]=make_pair(da[0].first,1);
    for (int i=1;i<m;i++){
        if(da[i].first==da[i-1].first){
            co++;
        }
        else{
            co=1;
        }
        ans[da[i].second.second]=make_pair(da[i].first,co);
    }
    for rip(i,m){
        printf("%06d%06d\n",ans[i].first,ans[i].second);
    }
}

Measured memory_bytes: 4224
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n wmax ->
  let wvs = Array.init n @@ fun _ ->
    Scanf.scanf "%d %d\n" @@ fun w v -> w, v in
  Array.fold_left (fun m (w, v) ->
    IntMap.fold (fun w' v' m ->
      if wmax < w + w' then m
      else IntMap.add (w + w') (max (v + v') @@
        try IntMap.find (w + w') m with Not_found -> min_int) m) m m) (IntMap.singleton 0 0) wvs
  |> (fun m -> IntMap.fold (fun _ -> max) m min_int)
  |> Printf.printf "%d\n"


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;
  deque<ll> q;
  rep(i, N) {
    ll a;
    cin >> a;
    auto lb = lower_bound(ALL(q), a) - q.begin();
    if (lb == 0) {
      q.push_front(a);
    } else {
      q[lb - 1] = a;
    }
  }
  ll ans = q.size();
  ANS;
  return 0;
}

Measured memory_bytes: 4392
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
# include <set>
# include <iomanip>
# include <functional>
# include <queue>
#include<map>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}


int main() {
	int A[105],B[105],C[105];
	int hida = 0,   sita = 0;
	int tate=0,yoko=0,N = 0;
	cin >>yoko>>tate>> N;
	int migi = yoko;
	int ue = tate;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i] >> C[i];
		if (C[i] == 1) {
			hida = max(hida, A[i]);
		}
		if (C[i] == 2) {
			migi = min(migi, A[i]);
		}
		if (C[i] == 3) {
			
			sita = max(sita, B[i]);
		}
		if (C[i] == 4) {
			ue = min(ue, B[i]);
		}
	}
	//cout << hida << endl << migi << endl << ue << endl << sita << endl;
	if ((migi - hida) <= 0||(ue-sita)<=0) {
		cout << '0' << endl;
		return 0;
	}
	cout << (migi - hida) * (ue - sita) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextLong();
        }
        long max = a[0];
        long ans = 0l;
        for (int i = 1; i < a.length; i++) {
            if(a[i] <= max) {
                ans += max - a[i];
            } else {
                max = a[i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 61048
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>

using namespace std;

char ch[100];
char ch2[100];

string AKIBA = "AKIHABARA$";

void no(){
	printf("NO\n");
	exit(0);
}

int id;
void add(char c){
	if(c == AKIBA[id]){
		id++;
	}else if(AKIBA[id] == 'A'){
		id++;
		add(c);
	}else{
		no();
	}
}

int main(){
	scanf("%s", ch);
	int N = strlen(ch);
	for(int i = 0; i < N; ++i){
		add(ch[i]);
	}
	add('$');
	if(id == AKIBA.size()){
		printf("YES\n");
	}else{
		no();
	}
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math, std.typecons;


void main() {
    auto s = readln.chomp.to!(char[]);

    auto ans = repeat('z', 100).to!(char[]);
    auto ex = new bool[](26);

    if (s[0] < 'z') {
        ans = [(s[0] + 1).to!char];
    }

    foreach (int j, ch ; s) {
        ex[ch - 'a'] = 1;

        char[] tmp;

        if (j < s.length.to!int - 1) {
            foreach (i ; s[j + 1] - 'a' + 1 .. 26) {
                if (!ex[i]) {
                    tmp = s[0 .. j + 1] ~ ('a' + i).to!char;
                    break;
                }
            }
        }
        else {
            foreach (i ; 0 .. 26) {
                if (!ex[i]) {
                    tmp = s[0 .. j + 1] ~ ('a' + i).to!char;
                    break;
                }
            }
        }

        debug {
            writeln(tmp);
        }

        if (tmp && ans > tmp && s < tmp) {
            ans = tmp;
        }
    }

    if (ans.length > 26) {
        writeln(-1);
        return;
    }

    writeln(ans);
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20);
    int n, k; cin >> n >> k;
    vector<ll> a(n);
    for (ll &x : a) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    ll sum = 0;
    for (int i = 0; i < k; i++) {
        sum += a[i];
    }
    cout << sum << "\n";
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>

#define PI 3.141592

using namespace std;

class coodinate
{
public:
	double x;
	double y;
};


void koch_curve(int n, coodinate p, coodinate q)
{
	if (n == 0)
	{
		
		return;
	}

	coodinate left,mid,right;
	double length;

	length = sqrt(pow(q.x - p.x , 2) + pow(q.y - p.y , 2)) / 3;

	//printf("length=%f\n", length);

	left.x = (2 * p.x + q.x) / 3;
	left.y = (2 * p.y + q.y) / 3;

	right.x = (p.x + 2 * q.x) / 3;
	right.y = (p.y + 2 * q.y) / 3;

	mid.x = (right.x - left.x) * cos((60 * PI) / 180) - (right.y - left.y) * sin((60 * PI) / 180) + left.x;
	mid.y = (right.x - left.x) * sin((60 * PI) / 180) + (right.y - left.y) * cos((60 * PI) / 180) + left.y;

	koch_curve(n-1,p,left);
	printf("%f %f\n", left.x, left.y);

	koch_curve(n-1,left,mid);
	printf("%f %f\n", mid.x, mid.y);

	koch_curve(n-1,mid,right);
	printf("%f %f\n", right.x,right.y);

	koch_curve(n-1,right,q);

}

int main()
{
	int n;

	coodinate p1,p2;

	p1.x = 0;
	p1.y = 0;

	p2.x = 100;
	p2.y = 0;

	scanf("%d", &n);

	printf("%f %f\n", p1.x,p1.y);

	koch_curve(n,p1,p2);

	printf("%f %f\n", p2.x,p2.y);

	return 0;
}
	

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int ans = k == 1 ? 0 : n - k;

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


Measured memory_bytes: 256
s=input()
l=len(s)
while s!=0:
    l=len(s)
    if s.rfind("dream")==l-5:
        s=s[:l-5]
    elif s.rfind("dreamer")==l-7:
        s=s[:l-7]
    elif s.rfind("erase")==l-5:
        s=s[:l-5]
    elif s.rfind("eraser")==l-6:
        s=s[:l-6]
    else:
        break
if len(s)==0:
    print("YES")
else:
    print("NO")
    

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

int main(){
	
	int n ;
	int y,m,d ;
	
	int p = 1 ;
	for( int i=1 ; i<1000 ; i++ ){
		if( i%3 == 0 ) p += 10*20 ;
		else p += 5*20 + 5*19 ;
	}
	
	cin >> n ;
	for( int i=0 ; i<n ; i++ ){
		cin >> y >> m >> d ;
		int c = d ;
		for( int j=1 ; j<y ; j++ ){
			if( j%3 == 0 ) c += 10 * 20 ;
			else c += 5*19 + 5*20 ;
		}
		for( int j=1 ; j<m ; j++ ){
			if( y%3 == 0 ) c += 20 ;
			else if( j%2 ) c += 20 ;
			else c += 19 ;
		}
		cout << p-c << endl ;
	}
	
return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    insert(node(x));
  }
  return 0;
}





Measured memory_bytes: 26564
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<long long> count(N+1, 0);
    for(int i = 0; i < N; i++) {
        count[A[i]]++;
    }
    vector<long long> comb(N+1, 0);
    for(int i = 0; i < count.size(); i++) {
        comb[i] = count[i] * (count[i] - 1) / 2;
    }
    long long ans = accumulate(comb.begin(), comb.end(), 0LL);
    for(int i = 0; i < N; i++) {
        long long t = count[A[i]];
        t--;
        long long c = t * (t - 1) / 2;
        long long co = ans - comb[A[i]] + c;
        cout << co << endl;
    }
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>

using namespace std;

using ll = long long;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int xdiff = c - a;
	int ydiff = d - b;

	for (int i = 0; i < ydiff; i++)
	{
		cout << 'U';
	}
	for (int i = 0; i < xdiff; i++)
	{
		cout << 'R';
	}

	for (int i = 0; i < ydiff; i++)
	{
		cout << 'D';
	}
	for (int i = 0; i < xdiff; i++)
	{
		cout << 'L';
	}

	cout << 'L';
	for (int i = 0; i < ydiff + 1; i++)
	{
		cout << 'U';
	}
	for (int i = 0; i < xdiff + 1; i++)
	{
		cout << 'R';
	}
	cout << 'D';

	cout << 'R';
	for (int i = 0; i < ydiff + 1; i++)
	{
		cout << 'D';
	}
	for (int i = 0; i < xdiff + 1; i++)
	{
		cout << 'L';
	}
	cout << 'U';

	cout << endl;
}

Measured memory_bytes: 256
open Printf
open Scanf

let input_string () =
  scanf "%s\n" (fun s -> s)

let f () =
  let s = input_string () in
  let n = String.length s in
  if n = 0 || s.[n-1] <> 's' then
    printf "%ss\n" s
  else
    printf "%ses\n" s

let () = f ()


Measured memory_bytes: 3708
#include<stdio.h>
int main(void){
	int A,B,C,D,P,n;
	scanf("%d%d%d%d%d",&A,&B,&C,&D,&P);
 	if(P<=C){
	n=B;
	}else{
	n=B+D*(P-C);
	}

	if(A*P<=n){
	printf("%d\n",A*P);
	}else{
	printf("%d\n",n);
	}
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

const int MAX_N = 305;

typedef long double real;

int n;
real dp[MAX_N][MAX_N][MAX_N];

int main()
{
	scanf("%d",&n);
	int d[]={0,0,0};
	for (int i=0; i<n; i++)
	{
		int x;
		scanf("%d",&x);
		d[x-1]++;
	}
	int a=d[0],b=d[1],c=d[2];
	for (int k=0; k<=n; k++)
		for (int j=0; j+k<=n; j++)
			for (int i=0; i+j+k<=n; i++)
			{
				if (i+j+k==0)
					continue;
				real &h=dp[i][j][k];
				h=1;
				if (i)
					h+=dp[i-1][j][k]*real(i)/n;
				if (j)
					h+=dp[i+1][j-1][k]*real(j)/n;
				if (k)
					h+=dp[i][j+1][k-1]*real(k)/n;
				h*=n/real(i+j+k);
			}
	printf("%.15Lf\n",dp[a][b][c]);
	return 0;
}


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

typedef long long ll;

int main(void){
    ll n, m;

    scanf("%lld %lld", &n, &m);

    ll p[m+1];
    char s[10];
    ll a[n+1], w[n+1];
    ll adda=0, addw=0;
    char *ac = "AC";
    char *wa = "WA";

    for(int i=0;i<n+1;i++){
        a[i]=0;
        w[i]=0;
    }

    for(int i=0;i<m;i++){
        scanf("%lld %s",&p[i], s);
        if(strcmp(s,ac)==0){
            a[p[i]-1] = 1;
        }else if(a[p[i]-1]==0){
                w[p[i]-1]++;
        }
    }

    for(int i=0;i<n;i++){
        adda += a[i];
        if(a[i]==1){
            addw += w[i];
        }
    }

    printf("%lld %lld", adda, addw);

    return 0;
}

Measured memory_bytes: 2560