akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, t; cin >> k >> t;
  vector<ll> A(t); rep(i, t) cin >> A[i];
  ll mx = *max_element(all(A));
  ll other = k-mx;
  cout << max(mx-other-1, 0LL) << endk;
  return 0;
}


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

int main(){
    int n,q;cin>>n;
    string com;
    list<int> v;
    for(int i=0;i<n;i++){
        cin>>com;
        if(com[0]=='i'){
            cin>>q;
            v.push_front(q);
        }
        else if(com[6]=='F') v.pop_front();
        else if(com[6]=='L') v.pop_back();
        else{
            cin>>q;
            for(list<int>::iterator itr=v.begin();itr!=v.end();itr++){
                if(*itr==q) {v.erase(itr);
                break;}
            }
        }
    }
    int i=0;
    for(list<int>::iterator itr=v.begin();itr!=v.end();itr++){
        if(i++) cout<<' ';
        cout<< *itr;
    }
    cout<<endl;
}


Measured memory_bytes: 34412
#include<stdio.h>
int main(void)
{
 int a,b,c;
 scanf("%d %d",&a,&b);
 if(a==0){
  if(b>=1868&&b<=1911){
   c=b-1867;
   printf("M%d\n",c);
  }
  else if(b>=1912&&b<=1925){
   c=b-1911;
   printf("T%d\n",c);
  }
  else if(b>=1926&&b<=1988){
   c=b-1925;
   printf("S%d\n",c);
  }
  else{
   c=b-1988;
   printf("H%d\n",c);
  }
 }
 else if(a==1){
  c=b+1867;
 }
 else if(a==2){
  c=b+1911;
 }
 else if(a==3){
  c=b+1925;
 }
 else{
  c=b+1988;
 }
 if(a!=0){
  printf("%d\n",c);
 }
 return(0);
}

Measured memory_bytes: 596
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

*******************************************************************************/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

int main()
{
    fastio;
    int n,k,d,i,a,cnt=0;
    cin>>n>>k;

    int arr[500];
    for(i=0;i<500;i++)
        arr[i]=0;

    while(k--)
    {
        cin>>d;
        for(i=0;i<d;i++)
        {
            cin>>a;
            arr[a]=1;
        }
    }

    for(i=1;i<=n;i++)
    {
        if(arr[i]==0)
            cnt++;
    }

    cout<<cnt;
    //cout<<"\n";
    return 0;   //:D
}




Measured memory_bytes: 3652
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> [Int] -> [(Int,Int)]
solve n as = stage1 ++ stage2 where
  asWidx = zip [1..] as
  amax = maximum as
  amaxarg = theIndex amax
  amin = minimum as
  aminarg = theIndex amin
  theIndex x = fst $ head $ filter ((== x) . snd) asWidx
  stage1
    | amax >= -amin = map ((amaxarg,) . fst) $ filter ((< 0) . snd) asWidx
    | otherwise     = map ((aminarg,) . fst) $ filter ((> 0) . snd) asWidx
  stage2
    | amax >= -amin = zipWith (,) [1..n-1] [2..n]
    | otherwise     = zipWith (,) [n,n-1..2] [n-1,n-2..1]

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> [(Int,Int)]
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      line2:remLines2 = remLines1
      as = map readBInt line2
  in solve n as

conv :: [(Int, Int)] -> String
conv xys 
  = unlines $ show (length xys) : map (\(x,y) -> show x ++ " " ++ show y) xys

main :: IO ()
main = putStr . conv . tmain =<< B.getContents


Measured memory_bytes: 508
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")


int ans[10];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int r, d, x;
	cin >> r >> d >> x;
	for(int i=1;i<=10;i++)
	{
		x = r * x - d;
		cout << x << endl;
	}

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        long[] dp = new long[N+1];
        dp[0] = 1000;
        for (int i = 1; i <= N; i++) {
            dp[i] = dp[i-1];
            for (int j = 1; j < i; j++) {
                dp[i] = Math.max(dp[i], dp[j-1]/A[j-1]*A[i-1]+dp[j-1]%A[j-1]);
            }
        }

        System.out.println(dp[N]);
    }
}


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

#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
#define OMAZINAI cin.tie(0); ios::sync_with_stdio(false);
#define INF (1LL<<61)
typedef long long int ll;

int a[4000];
ll ans;
int main() {
	int N;
	OMAZINAI;
	cin >> N;
	loop(i, N) {
		cin >> a[i];
		ans += a[i];
	}
	ans -= N;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int insertionSort(int A[], int n, int g, int c){
	int i;
	for(i = g; i < n; i++){
		int v = A[i];
		int j = i - g;
		while(j >= 0 && A[j] > v){
			A[j + g] = A[j];
			j = j - g;
			c++;
		}
		A[j + g] = v;
	}
	return c;
}

void shellSort(int A[], int n){
	int i,j,m,c = 0;
	int G[n]; 
	G[0] = 1;
	m = 1;
	for(i = 1; i < n; i++){
		G[i] = G[i - 1] * 3 + 1;
		if(G[i] < n){
			m = i + 1;
		}
		else{
			break;
		}
	}
	printf("%d\n" ,m);
	for(j = m - 1; j >= 0; j--){
		if(j > 0){
			printf("%d " ,G[j]);
			c = insertionSort(A, n, G[j], c);
		}
		else{
			printf("%d\n" ,G[j]);
			c = insertionSort(A, n, G[j], c);
		}
	}
	printf("%d\n",c);
}

int main(void){
	int n,i = 0;
	scanf("%d" ,&n);
	int A[n];
	for(i = 0; i < n; i++){
		scanf("%d" ,&A[i]);
	}
	shellSort(A,n);
	for(i = 0; i < n; i++){
		printf("%d\n" ,A[i]);
	}
	return 0;
}


Measured memory_bytes: 5660
import java.io.*;
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();
		int c=sc.nextInt();
		int d=sc.nextInt();
		System.out.println(Math.min(a,b)+Math.min(c,d));
	}
}

Measured memory_bytes: 22608
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
typedef long long ll;
 
struct UnionFind {
  int N;
  vector<int> par;   // par[i] :iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;  // rank[i]:iの深さ
  vector<int> sizes; // sizes[i]:iが属する連結成分のサイズ
  UnionFind(int n) : N(n), par(n), rank(n), sizes(n) { //最初は全てが根として初期化
    for(int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
      sizes[i] = 1;
    }
  }
 
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
 
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
 
    sizes[rx] = sizes[ry] = (sizes[rx] + sizes[ry]);
    if (rank[rx] < rank[ry]) {
      par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    } else {
      par[ry] = rx;
      if (rank[rx] == rank[ry]) rank[rx]++;
    }
  }
 
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
 
  int size(int x) {
    return sizes[root(x)];
  }
};
 
int main() {
  int N, M;
  cin >> N >> M;
 
  vector<int> A(M), B(M);
  for (int i=0; i<M; ++i) cin >> A[i] >> B[i];
 
  vector<ll> ret(M+1);
  UnionFind tree(N);
  ret[M] = (ll)N*(N-1)/2;
  for (int i=M-1; i>=0; --i) {
    int x = A[i]-1;
    int y = B[i]-1;
    ret[i] = ret[i+1];
    if (!tree.same(x,y)) ret[i] -= tree.size(x)*tree.size(y);
    tree.unite(x,y);
  }
 
  for (int i=1; i<=M; ++i) {
    cout << ret[i] << endl;
  }
}

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

using namespace std;

typedef long long ll;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<int> arr(n);
    
    int sum = 0;

    for(int i =0; i < n;i++) {
        cin >> arr[i];
        sum += arr[i];
    }   

    set<int> s;
    ll val = ceil(sum/(4.0*m));
    for (auto x: arr) {
        if (x >= val)
            s.insert(x);
    }

    if (s.size() >= m) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> V(N);
    vector<ll> C(N);

    REP(i, N){
        cin >> V[i];
    }
    REP(i, N){
        cin >> C[i];
    }

    ll ans = 0;
    REP(i,N){
        if(V[i] > C[i]){
            ans += V[i] - C[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    int tmp=0;
    for (int i=1;i<=n;i++) {
        if (s.substr(n-i,i)==t.substr(0,i)) {
            tmp=max(tmp,i);
        }
    }
    cout<<n*2-tmp<<endl;
}

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

signed main() {
    int i;
    char date[7][4] = {
        "SAT",
        "FRI",
        "THU",
        "WED",
        "TUE",
        "MON",
        "SUN"
    };
    string s;
    
    cin >> s;
    
    i = 0;
    while ( s != date[i] ) {
        i++;
    }
    
    cout << i + 1 << endl;
    return (0);
}

Measured memory_bytes: 3560
S = int(input())
h1 = S // 3600
m1 = (S - 3600*h1) // 60
s1 = (S - 3600*h1 - 60*m1)
h2 = str(h1)
m2 = str(m1)
s2 = str(s1)
print(h2 + ":" + m2 + ":" + s2)


Measured memory_bytes: 5588
#include<stdio.h>
int main()
{
    char a[4],b[4];
    gets(a);
    gets(b);
    int x=0,i;
    for(i=0;i<=2;i++)
    {
        if(a[i]==b[i])
        {
            x++;
        }
    }
    printf("%d",x);
    return 0;
}

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

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


int main(){
  int C[26];
  int S[26][365];
  int T[365];
  int res_do[26];
  int score;
  
  int min_num=100;
  int min_c =0;
  
  
  for(int i=0;i<26;i++){
    cin >> C[i];
    if(min_num>C[i]){
      min_c=i+1;
      min_num=C[i+1];
    }
  }
  
  
  
  int max_num;
  int max_s;
  
  
  for(int j=0;j<26;j++){
    res_do[j]=0;
  }
  
  for(int i=0;i<365;i++){
    max_num = 0;
    max_s = 26;
    for(int j=0;j<26;j++){
      cin >> S[j][i];
      if(max_num<S[j][i]+C[j]*res_do[j]){
        max_num=S[j][i]+C[j]*res_do[j];
        max_s=j;
      }
    }
    //cout << max_s <<":"<<max_num<<endl;
    T[i]=max_s;
    res_do[max_s]=0;
  }
  
  int P[365];
  for(int i=0;i<365;i++){
    P[i]=T[i];
  }
  int pre_score=0;
  
  int ed=0;
  for(int k=0;k<10000;k++){
    ed++;
    score=0;
    for(int j=0;j<26;j++){
      res_do[j]=0;
    }
    for(int i=0;i<365;i++){
      score= score+S[P[i]][i];
      for(int j=0;j<26;j++){
        score =score+(i-res_do[j])*C[j];
      }
      res_do[P[i]]=i;
    }
    if(score>pre_score){
      pre_score=score;
      ed=1;
      for(int i=0;i<365;i++){
        T[i]=P[i];
      }
    }
    for(int i=0;i<365;i++){
      int d = (ed+i)%26;
      P[i]=T[d];
      }
    }
  
  for(int i=0;i<365;i++){
    cout << T[i]+1 <<endl;
  }
  
  return 0;
}


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


Measured memory_bytes: 3680
// This  Program is made by Jan(Codezebra)
#include<bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f
using namespace std;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b, c;
	cin>>a>>b>>c;
	cout<<a+b+c+max(a,max(b,c))*9;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+N)

int main(void)
{
	char a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	if (a == '1')
		ans += 1;
	if (b == '1')
		ans += 1;
	if (c == '1')
		ans += 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();
    int n = str.length();
    char h = str.charAt(0);
    char t = str.charAt(n-1);
    System.out.println(h+""+(n-2)+""+t);
  }
}

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

main()
{
    string s,t; cin>>s>>t;
    int ans=0;
    for(int i=0; i<s.size(); ++i)
    {
        if(s[i]!=t[i]) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3820
//
// author  : Abhishek
//
#include <bits/stdc++.h>

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;

const ll mod = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    }
}

int main() {

//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    cin >> n;

    ll ans = inf;

    for (i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ll n1 = i;
            ll n2 = n/i;
            ans = min(ans, n1+n2-2);
        }
    }

    cout<<ans;

    return 0;
}




Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

ll dp[3001][3001];
ll mod(ll a){
if(a>=0)
    return a;
else return -a;
}


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
ll a[n];
for(int i=0;i<n;i++)
    cin>>a[i];
ll x=0;
ll l[n+1];
l[0]=0;
for(int i=0;i<n;i++){
    l[i+1]=l[i]+a[i];
}
for(int i=1;i<=n;i++){
    dp[i][i]=a[i-1];
}
for(int i=2;i<=n;i++){
    for(int j=1;j+i<=n+1;j++){
            int p=j,q=j+i-1;
        ll x=min(dp[p+1][q],dp[p][q-1]);
      dp[p][q]=l[q]-l[p-1]-x;
    }
}

cout<<(2*dp[1][n]-l[n])<<endl;


}


Measured memory_bytes: 70016
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

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

	vector<pair<ll, ll>> shop;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		shop.emplace_back(a, b);
	}

	sort(begin(shop), end(shop));

	ll ans = 0;
	for (ll cnt = 0, i = 0; cnt < m; i++) {
		if (shop[i].second < m - cnt) {
			ans += shop[i].first * shop[i].second;
			cnt += shop[i].second;
		} else {
			ans += shop[i].first * (m - cnt);
			break;
		}
	}

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


Measured memory_bytes: 2420
import copy

N = int(input())
org_arr = [list(input().split()) for _ in range(N)]
for i in range(len(org_arr)):
    org_arr[i][1]=int(org_arr[i][1])
    org_arr[i].append(i+1)

arr = copy.copy(org_arr)


arr = sorted(arr, reverse=True, key=lambda x: x[1])
arr.sort(key=lambda x:x[0])

for i in range(len(arr)):
    arr[i].append(i+1)

arr.sort(key=lambda x:x[0])
for i in range(len(arr)):
    print(arr[i][2])


Measured memory_bytes: 69244
fun main() {
    val n = nextInt()
    val x = nextInt() - 1
    val y = nextInt() - 1
    val result = IntArray(n)

    for (i in 0 until n-1) {
        for (j in i+1 until n) {
            val d = Math.min(j-i, Math.abs(x - i) + Math.abs(y - j) + 1)
            result[d]++
        }
    }

    for (i in 1 until n) {
        println(result[i])
    }
}

val scanner = java.util.Scanner(System.`in`)
fun next(): String = scanner.next()
fun nextInt() = scanner.nextInt()
fun nextLong() = scanner.nextLong()
fun nextLine() = scanner.nextLine()
fun nextList() = scanner.nextLine().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")

fun main(args: Array<String>) = main()

Measured memory_bytes: 31008
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
using namespace std;
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
#define lli long long int

#define MAX 100000000
//#define DEBUG

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

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
#else
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
#endif
    int A, B, C;
    cin >> A >> B >> C;
    if (min(A, B) < C && C < max(A, B))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}
/* 注意すべき点
グローバル以外の配列は初期化すべし
*/

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

int main(){
    string homu;
    cin >> homu;
    int n=homu.size();
    random_shuffle(homu.begin(), homu.end());
    while(1){
      bool ok=false;
      string ns="";
      for(int i=0;i< (int)homu.size();++i){
        if(i+1<homu.size()&&homu[i]!=homu[i+1]){
          ++i;
          ok=true;
          }
        else ns+=homu[i];
        }
      if(!ok)break;
      //cout<<ns<<endl;
      homu.swap(ns);
      }
    cout<<n-homu.size()<<endl;
        
    return 0;
}


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

typedef long long int ll;

int main()
{
	ll n;
	scanf("%lld",&n);
	ll arr[n];
	for(ll i=0;i<n;i++)
		scanf("%lld",&arr[i]);
	sort(arr,arr+n);
	ll ans=arr[n-1];
	ll j=n-2;
	while(n-2>0)
	{
		if(n-2>1)
		{
			ans+=2*arr[j];
			n-=2;
		}
		else
		{
			ans+=arr[j];
			n-=1;
		}
		j--;
	}
	printf("%lld\n",ans);
}



Measured memory_bytes: 5360
import sys
N = int(input())
d = {}
max = 0

for i in range(N):
    S = input()
    if not(S in d):
        d[S] = 0
        continue
    d[S] = d[S] + 1
    if max<d[S]:
        max = d[S]

A = []

for k in d:
    if d[k]==max:
        A.append(k)

A.sort()

for a in A:
    print(a)

Measured memory_bytes: 32096
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

int main() {
	int ans = INT_MAX;
	makei(n);
	makei(k);
	--k;
	makev(h, n);
	sort(all(h));
	Rep(k, n) {
		mini(ans, h[i] - h[i - k]);
	}
	say(ans);
}

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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

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

	if(y%2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	y = y/2;

	int a, b;
	b = y - x;
	a = x - b;

	if(a >= 0 && b >= 0) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

typedef struct edge{ll s,g,c;}E;
 
ll n;
E e[200010];
ll vjisuu[100010];
ll vnow[100010];
ll epre[200010];
 
ll que[200010];
ll d[100010];
void bfs(int k){
	ll qcnt=1;
	ll tooi;
	que[0]=k;
	d[k]=1;
	rep(i,0,qcnt){
		ll v=que[i];
		for(ll t=vnow[v];t!=-1;t=epre[t])if(!d[e[t].g]){
			que[qcnt++]=e[t].g;
			d[e[t].g]=d[v]+1;
		}
	}
}

ll ans[100010];
int main(){
	scanf("%lld",&n);
	rep(i,0,n)vnow[i]=-1;
	
	rep(i,0,n-1){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		a--;b--;
		e[2*i].s=a;
		e[2*i].g=b;
		epre[2*i]=vnow[a];
		vnow[a]=2*i;
		
		e[2*i+1].s=b;
		e[2*i+1].g=a;
		epre[2*i+1]=vnow[b];
		vnow[b]=2*i+1;
		
		vjisuu[a]++;
		vjisuu[b]++;
	}
	
	bfs(0);
	ll tooi1=0;
	rep(i,0,n)if(d[i]>d[tooi1])tooi1=i;
	rep(i,0,n)d[i]=0;
	
	bfs(tooi1);
	ll tooi2=tooi1;
	rep(i,0,n)if(d[i]>d[tooi2])tooi2=i;
	
	//tooi2からtooi1への経路上にない点の次数が全て1か？
	ll vr=e[vnow[tooi2]].g;
	ll vpre=tooi2;
	ll len=0;
	while(vr!=tooi1){
//		printf("vr:%d %d\n",vr,d[vr]);
		ll vnext;
		ll cnt=0;
		for(ll t=vnow[vr];t!=-1;t=epre[t]){
			ll vtemp=e[t].g;
//			printf("vtemp:%d %d\n",vtemp,d[vtemp]);
			if(d[vtemp]<d[vr]){
				vnext=vtemp;
			}else if(vtemp!=vpre){
				if(vjisuu[vtemp]!=1){
					puts("-1");
					return 0;
				}
				cnt++;
			}
		}
		ans[len++]=cnt;
		vpre=vr;
		vr=vnext;
	}
	
	int flag=0;
	ll left=0,right=len-1;
	while(left<right&&ans[left]==ans[right])left++,right--;
	
	if(ans[left]>ans[right]){
		//リバース
		for(ll l=0,r=len-1;l<r;l++,r--){
			ll t=ans[l];
			ans[l]=ans[r];
			ans[r]=t;
		}
	}
	printf("1 ");
	ll crr=1;
	rep(i,0,len){
		rep(j,0,ans[i])printf("%d ",crr+1+j+1);
		printf("%d ",crr+1);
		crr+=ans[i]+1;
	}
	printf("%d ",crr+1);
	return 0;
}

Measured memory_bytes: 11008
#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////

void solve(){
	string A,B;
	cin >> A >> B >> A;
	cout << "A" << B[0] << "C";
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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


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

	for (int i = 1; i <= sqrt(n); i++)
	{
		if (n % i == 0)
		{
			if (n / i <= 9)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n >> m) {
        vi d(n);
        REP(i, n) {
            cin >> d[i];
        }
        sort(ALL(d));
        int ans = 0;
        REP(i, n) {
            if ((m -= d[i]) >= 0) ans ++;
        }
        cout << ans - (m > 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define ull unsigned long long 

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

  ull sum = 0;
  ull table[N];
  ull n;

  for (int i = 0; i < N; ++i) {
    cin >> n;
    table[i] = n + 1;
  }
  for (int i = 0; i < K; ++i) {
    sum += table[i];
  }

  ull ans = sum;

  for (int i = K; i < N; ++i) {
    sum += table[i];
    sum -= table[i - K];
    ans = max(ans, sum);
  }

  if (ans % 2 == 0) {
    cout << ans / 2 << endl;
  } else {
    cout << ans / 2 << ".5" << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
	int w, h, x, y, r;
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r );
	if((x + r <= w && x-r >= 0) && (y + r <= h && y-r >= 0))
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n;
    scanf("%d%d",&m,&n);
    if(m*10000<n)
    {
        printf("-1 -1 -1");
        return 0;
    }
    if(m*1000>n)
    {
        printf("-1 -1 -1");
        return 0;
    }
    if(n%1000!=0)
    {
        printf("-1 -1 -1");
        return 0;
    }
    for(int i=0;i<=m;i++)
     for(int j=0;j<=m;j++)
      for(int k=0;k<=m,i+j+k<=m;k++)
       {
            if(i+j+k==m && i*1000+j*5000+k*10000==n)
            {
                printf("%d %d %d",k,j,i);
                return 0;   
            }
       }
    printf("-1 -1 -1");
    return 0;
}

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

void print_vector(vector<int> A, int N)
{
    for (int i = 0; i < N; i++)
    {
        cout << A.at(i);
        if (i != N - 1)
            cout << " ";
    }
    cout << endl;
}

int selection_sort(vector<int> &A, int N)
{
    int count = 0;
    for (int i = 0; i < N - 1; i++)
    {
        int minj = i;
        for (int j = i + 1; j < N; j++)
        {
            if (A.at(minj) > A.at(j))
            {
                minj = j;
            }
        }
        if (i != minj)
            count++;
        swap(A.at(i), A.at(minj));
    }
    return count;
}

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

    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A.at(i);

    int count = selection_sort(A, N);

    print_vector(A, N);
    cout << count << endl;
}


Measured memory_bytes: 3148
H = input().split()
W = int(H[1])
H = int(H[0])

M = []
for _ in range(H):
    w = input()
    M.append(w)

ans = True
for h in range(H):
    for w in range(W):
        if M[h][w] == '.':
            continue
        flag = False
        if h > 0 and M[h-1][w] == '#':
            flag = True
        if h < H - 1 and M[h+1][w] == '#':
            flag = True
        if w > 0 and M[h][w-1] == '#':
            flag = True
        if w < W - 1 and M[h][w+1] == '#':
            flag = True
        if not flag:
            ans = False

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
# coding: utf-8

N, M = list(map(int, input().split(' ')))
colors = []
for i in range(N):
    row = list(input())
    row_color = [0, 0, 0]
    for c in row:
        if c == 'W': row_color[0] += 1
        elif c == 'B': row_color[1] += 1
        elif c == 'R': row_color[2] += 1
    colors.append(row_color)

min_diff = float('inf')
for blue_top in range(1, N-1):
    for red_top in range(blue_top+1, N):
        diff = 0
        for i in range(N):
            if i < blue_top:
                diff += colors[i][1] + colors[i][2]
            elif i < red_top:
                diff += colors[i][0] + colors[i][2]
            else:
                diff += colors[i][0] + colors[i][1]
        if diff < min_diff:
            min_diff = diff

print(min_diff)


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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N;
	cin >> N;
	string s;
	cin >> s;
	string ans[4];
	rep(i,2) ans[0].push_back('S');
	rep(i,2) ans[1].push_back('W');
	ans[2].push_back('S');
	ans[2].push_back('W');
	ans[3].push_back('W');
	ans[3].push_back('S');			
	rep(i,4){
		bool flag=true;
		for(int j=2; j<N; j++){
			if(ans[i][j-1]=='S'){
				if(s[j-1]=='o') ans[i].push_back(ans[i][j-2]);
				else if(ans[i][j-2]=='S') ans[i].push_back('W');
				else ans[i].push_back('S');
			}
			if(ans[i][j-1]=='W'){
				if(s[j-1]=='x') ans[i].push_back(ans[i][j-2]);
				else if(ans[i][j-2]=='S') ans[i].push_back('W');
				else ans[i].push_back('S');
			}
		}
		if(ans[i][N-1]=='S'){
			if(s[N-1]=='o' and ans[i][N-2]!=ans[i][0]) flag=false;
			if(s[N-1]=='x' and ans[i][N-2]==ans[i][0]) flag=false;
		}
		if(ans[i][N-1]=='W'){
			if(s[N-1]=='x' and ans[i][N-2]!=ans[i][0]) flag=false;
			if(s[N-1]=='o' and ans[i][N-2]==ans[i][0]) flag=false;
		}
		if(ans[i][0]=='S'){
			if(s[0]=='o' and ans[i][N-1]!=ans[i][1]) flag=false;
			if(s[0]=='x' and ans[i][N-1]==ans[i][1]) flag=false;
		}
		if(ans[i][0]=='W'){
			if(s[0]=='x' and ans[i][N-1]!=ans[i][1]) flag=false;
			if(s[0]=='o' and ans[i][N-1]==ans[i][1]) flag=false;
		}		
		if(flag){
			cout << ans[i] << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 3920
def connect_dfs(N,E,start):
    connect = {start}
    q = [start]
    while q:
        i = q.pop()
        for j in E[i]:
            if j in connect:continue
            connect.add(j)
            q.append(j)
    return connect

def update(dist,N,E,start):
    done = [False]*N
    done[start] = True
    q = [start]
    d = dist[:]
    while q:
        i = q.pop()
        di = d[i]
        for j,c in E[i].items():
            d[j] = min(d[j],d[i]+c)
            if not done[j]:
                q.append(j)
                done[j] = True
    return d

def main():
    N,M = map(int,input().split())
    ABC = [list(map(int,input().split())) for _ in [0]*M]

    E = [{} for _ in [0]*N]
    Eb = [{} for _ in [0]*N]
    for a,b,c in ABC:
        E[a-1][b-1] = -c
        Eb[b-1][a-1] = c
    v = connect_dfs(N,E,0) & connect_dfs(N,Eb,N-1)
    for i in range(N):
        if i in v:continue
        for j in Eb[i]:
            E[j].pop(i)

    INFTY = 10**18
    d = [INFTY]*N
    d[0] = 0

    for _ in range(N-1):
        d = update(d,N,E,0)
    if d!=update(d,N,E,0):
        print("inf")
    else:
        print(-d[-1])

main()

Measured memory_bytes: 4464
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define RREP(i,x,y) for(int i=(int)(x);i>(int)(y);i--)
#define all(x) (x).begin(),(x).end()

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;

using namespace std;

string s;
int K;
vector<string> list;

void solve() {
    REP(i,0,K) {
        REP(j,0,s.length() - i) {
            list.push_back(s.substr(j,i+1));
        }
    }
    sort(all(list));
    unique(all(list));
    cout << list[K-1] << "\n";
    return;
}

int main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> s >> K;
    solve();
    return 0;
}


Measured memory_bytes: 1660
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

manzokudo = B[A[0] - 1]
for n in range(1, N):
  manzokudo += B[A[n] - 1]
  
  if A[n - 1] == A[n] - 1:
    manzokudo += C[A[n - 1] - 1]

print(manzokudo)
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  vi num(n);
  set<ll>se;
  for(int i=0;i<n;i++)cin>>num[i];
  for(int i=1;i<=6;i++){
    for(int j=0;j<=n-i;j++){
      ll kake=1;
      ll sum=0;
      for(int k=j+i-1;k>=j;k--){
	sum += kake*num[k];
	kake*=10;
      }
     
      se.insert(sum);
    }
  }
  ll cnt=0;
  for(auto a:se){
    if(cnt != a){cout<<cnt<<endl;break;}
    cnt++;
  }
  return 0;
}



Measured memory_bytes: 3356
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 998244353;
const int N=2e5+9;
ll cnt[N];
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    ll y[x+1];
    for (int i=1;i<=x;i++){
        cin>>y[i];
        cnt[y[i]]++;
    }
    ll ans=0;
    for (int i=1;i<=x;i++){
        ans+=(cnt[i]*(cnt[i]-1)/2);
    }
    for (int i=1;i<=x;i++){
        cout<<ans-cnt[y[i]]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 4736
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
vector<pint> gr[114514];
int num[114514];
void dfs(int v,int u,int p){
	//cout<<v<<u<<p<<endl;
	if(num[v]>=0) return;
	num[v]=p;
	rep(i,gr[v].size()){
		pint w=gr[v][i];
		if(w.fi==u) continue;
		dfs(w.fi,v,(p+w.se)%2);
	}
}
int main()
{
	int n,u,v,w;
	cin>>n;
	rep(i,n-1){
		cin>>u>>v>>w;
		u--;v--;w%=2;
		gr[u].pb(mp(v,w));
		gr[v].pb(mp(u,w));
	}
	memset(num,-1,sizeof(num));
	dfs(0,-1,0);
	rep(i,n) cout<<num[i]<<endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353 
#define pb push_back
#define mb make_pair
vector<int> inp[11];
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n,m; cin >> n >> m;
    for(int i=0;i<m;i++){
    	int n1; cin >> n1;
    	for(int j=0;j<n1;j++){
    		int x ; cin >> x;
    		inp[i].pb(x);
    	}
    }	
    int p[m];
    for(int i=0;i<m;i++)
    	cin >> p[i];
    int c=0;
    vector<int> v(n);
    for(int i=0;i<=pow(2,n)-1;i++){
    	fill(v.begin(),v.end(),0);
    	
    	int c2=0;
    	int j=i;
    	int x=0;
    	while(j){
    		if(j%2==1)
    			v[x]=1;
    		j/=2;
    		x++;
    	}
    	int c1=0;
    	for(int j=0;j<m;j++){
    		c1=0;
    		for(int k=0;k<inp[j].size();k++){
    			if(v[inp[j][k]-1])
    				c1++;    				
    		}
    		if(c1%2 == p[j])
    			c2++;
    	}
    	if(c2==m){
    		c++;
    	}
    	

    }
    cout <<c;   




    return 0;

}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];
std::vector<array<ll, 2>> v;

void solve(){
    ll n;
    cin >> n;
    ll a, b;
    for (int i = 0; i < n; ++i){
        cin >> a >> b;
        v.push_back({a, b});
    }
    for (int i = 1; i < n - 1; ++i){
        res = 1;
        for (int j = -1; j <= 1; ++j){
            res = res * (v[i + j][0] == v[i + j][1]);
        }
        if(res) break;
    }
    res && cout << "Yes\n" || cout << "No\n";
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// Radhe Radhe

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll K,A,B;
    Scll3(K,A,B);

    ll ans0 = K+1;
    ll ans1 = 0;
    ll k = K-A+1;
    if( k >= 0 ){
    ans1 = (B-A)*(k/2)+A;
    ans1 += k%2;
    }

    printf ("%lld\n", max( ans0, ans1 ) );

    return 0;
}





Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define iter_e(i, x) for (int i = pos[x]; i; i = g[i].frt)

typedef pair<int, int> pii;
#define fi first
#define se second

const int NR = 310;
const int mod = 1e9 + 7;

struct Edge { int y, frt; } g[NR];
int pos[NR], gsz, dfn[NR], low[NR], top, ans, n, m, dsz, bi[NR][NR], K;
pii stk[NR];
bool vs[NR], vis[NR];

void AE(int x, int y) { g[++gsz] = (Edge) { y, pos[x] }, pos[x] = gsz; }

int pr(int a, int z) {
	int s = 1;
	while (z > 0) {
		if (z % 2 == 1) s = 1ll * s * a % mod;
		a = 1ll * a * a % mod;
		z /= 2;
	}
	return s;
}

int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

int calc(int n, int m) {
	//printf("!%d %d\n", n, m);
	if (n > m) return K;
	else if (n < m) return bi[m + K - 1][K - 1];
	else {
		int ans = 0;
		iter(i, n) ans = (ans + pr(K, gcd(i, n))) % mod;
		return 1ll * ans * pr(n, mod - 2) % mod;
	}
}

#define v g[i].y

void dfs(int x) {
	dfn[x] = low[x] = ++dsz;
	iter_e(i, x) if (!vis[i >> 1]) {
		vis[i >> 1] = true;
		stk[++top] = pii(x, v);
		if (!dfn[v]) {
			dfs(v); low[x] = min(low[x], low[v]);
			if (low[v] >= dfn[x]) {
				iter(k, n) vs[k] = false;
				int V = 0, E = 0, a, b;
				do {
					a = stk[top].fi, b = stk[top].se;
					if (!vs[a]) vs[a] = true, ++V;
					if (!vs[b]) vs[b] = true, ++V;
					--top; ++E;
				} while (a != x || b != v);
				ans = 1ll * ans * calc(V, E) % mod;
			}
		} else low[x] = min(low[x], dfn[v]);
	}
}

int main() {
	//freopen("62D.in", "r", stdin);
	scanf("%d%d%d", &n, &m, &K); gsz = 1;
	iter(i, m) {
		int x, y;
		scanf("%d%d", &x, &y);
		AE(x, y); AE(y, x);
	}

	bi[0][0] = 1;
	iter(i, m + K) {
		bi[i][0] = 1;
		iter(j, i) bi[i][j] = (bi[i - 1][j] + bi[i - 1][j - 1]) % mod;
	}

	ans = 1;
	iter(i, n) if (!dfn[i]) dfs(i);
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
const ll N = 123456;

ll a[N];

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

    ll n , z , w;
    cin >> n >> z >> w;

    rep(i , 1 , n) cin >> a[i];

    if(n == 1) {

        cout << abs(a[1] - w) << endl;
        return 0;
    }

    cout << max(abs(a[n - 1] - a[n]) , abs(a[n] - w)) << endl;
    return 0;
}


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

vector<int> input(int N) {
	vector<int> vec(N);
	for (int i = 0; i < N; i++){
		scanf("%d", &vec.at(i));
	}
	return vec;
}

int main(){
    int N;
    cin >> N;
    vector<int> B;
    B = input(N-1);
    B.insert(B.begin(), 100000);
    B.insert(B.begin()+N, 100000);
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans += min(B[i], B[i+1]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
/*
    Problem 15
    https://atcoder.jp/contests/abc145/tasks/abc145_c
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
typedef pair<double, double> pdd;
/* constant */
int INF = 1 << 30;
/* global variables */
/* function */
double length(pdd p1, pdd p2) {
    double dx = p1.first - p2.first;
    double dy = p1.second - p2.second;
    double ret = sqrt(dx*dx + dy*dy);
    return ret;
}
double factrial(int x) {
    double ret = 1;
    for (int i = 1; i <= x; i++) ret *= i;
    return ret;
}
/* main */
int main(){
    int N;
    cin >> N;
    double x, y;
    vector<pdd> P(N);
    for (int i = 0; i < N; i++) {
        cin >> x >> y;
        P[i] = make_pair(x, y);
    }
    double dist = 0.0;
    vector<int> v(N);
    for (int i = 0; i < N; i++) v[i] = i;
    do {
        for (int i = 0; i < N-1; i++) dist += length(P[v[i]], P[v[i+1]]);
    } while(next_permutation(v.begin(), v.end()));

    double pattern = factrial(N);
    double mean = dist / pattern;
    cout << setprecision(8) << mean << '\n';
}

Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {

  val mod = 1000000007L

  val n = in.readInt
  val s = in.readLine

  val table = Array.ofDim[Long]('z' - 'a' + 1)
  for(ch <- s)
    table(ch - 'a') += 1

  val ans = table.filter(i => i > 0)./:(1L) { (acc, i) =>
      acc * (i+1) % mod
    } - 1
  println(ans)
}

Measured memory_bytes: 27264