akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc149/tasks/abc149_e
//E - Handshake,2回目
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,M;cin>>N>>M;
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }
    sort(an.begin(),an.end());
    //累積和
    vector<ll> sums(N+1);
    FOR(i,0,an.size()){
        sums.at(i+1) = sums.at(i) + an.at(i);
    }

    auto check_func = [&](ll v){
        ll count=0;//回数
        FOR(i,0,an.size()){
            ll x=an.at(i);
            ll y=v-x;
            auto it = lower_bound(an.begin(), an.end(), y);
            count += distance(it, an.end());
        }
        //dump(count);
        return (count>=M);
    };

    ll lb=1,ub=1e+10+7;
    while(ub-lb>1){
        ll mid = (ub+lb)/2;
        auto ck = check_func(mid);
        if (ck){
            lb=mid;
        }else{
            ub=mid;
        }
    }
    dump(lb);

    ll ans=0;
    ll count = 0;
    FOR(i,0,an.size()){
        ll x=an.at(i);
        ll y=lb-x;
        auto it = lower_bound(an.begin(), an.end(), y);
        ll num = distance(it, an.end());
        ans += num * x;
        ans += sums.at(N) - sums.at(N-num);
        count += num;
    }
    if(count>M) ans -= lb*(count-M);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		long ans =N*(N+1)/2;
		System.out.println(ans);

	}

	public static boolean isPalindromicStr(String s) {
		int h = 0;
		int t = s.length() - 1;
		while (h <= t) {
			if (s.charAt(h) != s.charAt(t)) {
				break;
			}
			h++;
			t--;
		}
		if (h > t) {
			return true;
		}
		return false;
	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*
AC
*/

ll a[5],ans=0,t=0;

int main(void){
	rep(i,5)cin>>a[i];
	//10-a[i]%10が最大のものを最後に配置
	rep(i,5){
		t=max(t,a[i]%10==0?0:10-a[i]%10);
		ans+=a[i]%10==0?a[i]:(a[i]/10+1)*10;
	}
	cout<<ans-t<<endl;
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

struct UnionFind{
    vector<int> par;
    UnionFind(int32 n){
        par = vector<int>(n, -1);
    }

    int root(int x){
        if(par[x] < 0)return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y)return;
        par[x] += par[y];
        par[y] = x;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int deg(int x){
        return -par[root(x)];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    vector<int32> ans(n,-1);
    REP(i,m){
        int32 a,b;
        cin >> a >> b;
        a--;b--;
        ans[a]--;
        ans[b]--;
        uf.unite(a,b);
    }
    REP(i,n)ans[i] += uf.deg(i);
    REP(i,k){
        int32 c,d;
        cin >> c >> d;
        c--;d--;
        if(uf.same(c,d)){
            ans[c]--;
            ans[d]--;
        }
    }
    REP(i,n){
        if(i != 0)cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int K = Integer.parseInt(S[1]);
    
    int[] num = new int[N];
    for(int i = 0; i < N; i++){
      num[i] = Integer.parseInt(sc.next());
    }
    Arrays.sort(num);
    
    List<Integer> list = new ArrayList<>();
    int a = num[0];
    int count = 1;
    for(int i = 1; i < N; i++){
      if(num[i] == a){
        count++;
      }else{
        list.add(count);
        a = num[i];
        count = 1;
      }
      
      if(i == N-1){
        list.add(count);
      }
    }
    Collections.sort(list);
    
    int M = list.size() - K;
    if(M < 0){
      M = 0;
    }
    
    int ans = 0;
    for(int i = 0; i < M; i++){
      ans += list.get(i);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 50360
#include <iostream>
#include <vector>

using std::cin;
using std::cout;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  std::vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }

  int max_move = 0;
  for (int i = 0; i < n; ++i) {
    int move = 0;
    for (int j = i + 1; j < n && h[j] <= h[j - 1]; ++j, ++move) {}
    if (move > max_move) {
      max_move = move;
    }
    i += move;
  }
  cout << max_move;

  return 0;
}


Measured memory_bytes: 640
def include?(arr, n)
  if arr.length == 1
    return arr[0] == n
  else
    if arr[arr.length / 2] <= n
      return include?(arr[arr.length / 2..arr.length - 1], n)
    else
      return include?(arr[0...arr.length / 2], n)
    end
  end
end
gets
arr = gets.split(" ").map(&:to_i).sort
gets
count = 0
gets.split(" ").map(&:to_i).each{|item|
  count += 1 if include?(arr, item)
}
puts count

Measured memory_bytes: 6572
#include<bits/stdc++.h>
using namespace std;
long long ans=-1;
int n;
void def(int i, vector<int> v[], vector<int> co[], int K[],int L[],int m,long long fac )
{
   // cout<<m<<" "<<i<<endl;
    int j;
    if(m<0)return;
    if(i==n)
    {   //cout<<fac<<endl;
        if(m>=0)ans = max(ans,fac);
        return;
    }
        def(i+1,v,co,K,L,m,fac+v[i][L[i]]);
        long long cost=0;
    for(j=L[i];j<K[i];j++)
    {   cost+=co[i][j];
        def( i+1, v,co,K,L, m-cost,fac+v[i][j+1]);
    }
}
int main()
{
    //freopen("in3.in","r",stdin);
    //freopen("out.txt","w",stdout);
    int t;cin>>t;
    int cn4=0,cn2=0,cn=0;
    for(int re=1;re<=t;re++)
    {
        int a;
        cin>>a;
        if(a%4==0)cn4++;
        else if(a%2==0)cn2++;
        else cn++;
    }
    
    if(cn-cn4==1 && cn2%2==0)cout<<"Yes"<<endl;
    else if( cn4>=cn && cn2>=0)cout<<"Yes"<<endl;
    else cout<<"No\n";
    return 0;
}


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

std::vector<int> g[100000];
long long dp[2][100000];
long long mo=1000000000+7;

void dfs(int cur,int par){
  dp[0][cur]=1;
  dp[1][cur]=1;
  for(int dst:g[cur]){
    if(dst==par)continue;
    dfs(dst,cur);
    dp[0][cur]=dp[0][cur]*(dp[0][dst]+dp[1][dst])%mo;
    dp[1][cur]=dp[1][cur]*dp[0][dst]%mo;
  }
  return;
}

int main(){
  int N;
  std::cin>>N;
  if(N==1){
    std::cout<<2<<std::endl;
    return 0;
  }
  for(int i=0;i<N-1;++i){
    int x,y;
    std::cin>>x>>y;
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(0,-1);
  std::cout<<(dp[0][0]+dp[1][0])%mo<<std::endl;
  
  return 0;
}



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

int main(){
    int N,A,min=30,C=0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A;
        while(A%2==0){
            C++;
            A /= 2;
        }
        if(min>C) min=C;
        C=0;
        
    }
    cout << min << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
#define PB push_back
#define INF (int)(1e9)
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()

/*--------------------------------------------*/
/*
int dx[4]={-1,0,1,0};//四方に移動
int dy[4]={0,-1,0,1};
*/
/*--------------------------------------------*/
/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}
ll lcm(ll A, ll B) {//最小公倍数
    ll a=A;
    ll b=B;
    if (a==0 || b==0) {return 0;}
    if (a<0) {a=-a;}
    if (b<0) {b=-b;}
    while(b>0) {
        ll c=a%b;
        a=b;
        b=c;
    }
    return A/a*B;
}

ll gcd(ll a,ll b){
    while(b!=0) {
        int t=b;
        b=a%b;
        a=t;
    }
    return a;
}

//入力はすべて正とする
bool is_prime(int n) {//素数判定o(√n)
    for (int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return n!=1;//1の場合は例外
}

vector<ll> divisor(ll n){//約数の列挙o(√n)
    vector<ll> res;
    for(ll i=1;i*i<=n;i++) {
        if(n%i == 0){
        res.push_back(i);
        if(i!=n/i)res.push_back(n/i);
        }
    }
    return res;
}//vector<ll>k=divisor(n);rep(i,k.size())cout<<k[i]<<endl;//のように使う

map<ll,ll> prime_factor(ll n){//素因数分解o(√n)
    map<ll,ll>res;    
    for(ll i=2;i*i<=n;i++) {
        while (n%i==0) { 
            ++res[i];
            n/=i;
        }
    }
    if (n!=1)res[n]=1;
    return res;
}//map<ll,ll> k=prime_factor(n);for(auto i=k.begin();i!=k.end();i++){cout<<i->first<<" "<<i->second<<endl;}//みたいに使う

vector<ll> prime_list(ll n){//n以下の素数を全て見つける
    vector<ll> is_prime(n);//is_prime[i]が1ならiは素数
    for(ll i=2;i<=n;i++)is_prime[i]=1;//最初はみんな素数かも
    for(ll i=2;i*i<=n;i++){//素数の整数倍を消していく(√nまで)
        if(is_prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    is_prime[j]=0;                
                }
            }
        }
    }return is_prime;
}vector<ll>k=prime_list(n);REP(i,n){if(k[i])cout<<i<<endl;}のように使う
*/
/*--------------------------------------------*/


int main(){
    int n;cin>>n;
    V A(n);rep(i,n)cin>>A[i];
   
    //int money=0;
    int now=0;
    int maxx=0;
    rep(i,n){
        maxx+=abs(A[i]-now);
        now=A[i];
    }maxx+=abs(now);
    A.insert(A.begin(),0);
    A.PB(0);
    //for(int i=0;i<=n+1;i++)cout<<A[i]<<endl;
    REP(i,n){
        int ans=maxx;
        //printf("A[i-1]=%d,A[i]=%d,A[i+1]=%d\n",A[i-1],A[i],A[i+1]);
        if((A[i-1]<=A[i]&&A[i]<=A[i+1])||(A[i-1]>=A[i]&&A[i]>=A[i+1])){;}
        else if((A[i]<=A[i-1]&&A[i-1]<=A[i+1])||(A[i+1]<=A[i-1]&&A[i-1]<=A[i])){
            ans-=2*abs(A[i]-A[i-1]);
        }
        else ans-=2*abs(A[i]-A[i+1]);
        cout<<ans<<endl;
    }
    
}




Measured memory_bytes: 1656
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
import math
# from itertools import product, accumulate, combinations, product
#import bisect
# import numpy as np
# from copy import deepcopy
#from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())



def run():
    H, W = mapline()
    ans = INF
    for i in range(2):
        H, W = W, H
        for h in range(1, H):
            _ans = 0
            A = h * W
            # pat1
            B1 = math.ceil(W/2) * (H-h)
            C1 = math.floor(W/2) * (H-h)
            _ans = max([abs(A - B1), abs(B1 - C1), abs(A - C1)])
            ans = min(_ans, ans)
            # pat2
            _ans = 0
            if H*W <= 3 * A:
                w = math.ceil(A // (H-h))
                B2 = (H-h) * w
                C2 = (H-h) * (W-w)
                _ans = max([abs(A - B2), abs(B2 - C2), abs(A - C2)])
                ans = min(_ans, ans)
            # pat3
            _ans = 0
            h2 = math.ceil((H-h) / 2)
            if h + h2 != H:
                C3 = W * (H - h2 - h)
                B3 = W * h2
                _ans = max([abs(A - B3), abs(B3 - C3), abs(A - C3)])
                ans = min(_ans, ans)

    print(ans)


if __name__ == "__main__":
    #print(math.gcd(0, 10))
    run()


Measured memory_bytes: 9372
import java.util.*;
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String X = sc.next();
		String Y = sc.next();
		if (X.compareTo(Y) == 0) {
			System.out.println("=");
		}
		else if (X.compareTo(Y) < 0) {
			System.out.println("<");
		}
		else {
			System.out.println(">");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define LL1D vector<LL>
#define LL2D vector<LL1D>
#define NFRAC 300000
using namespace std;
const long long MOD = 1000000007;

LL fac[NFRAC+1];
LL ifac[NFRAC+1];

LL mpow(LL x, LL n){
    LL ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

LL comb(LL a, LL b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    LL tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

LL perm(LL a, LL b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    return ifac[a-b] * fac[a] % MOD;
}

void init(){
    fac[0] = 1;
    ifac[0] = 1;
    for(LL i = 0; i<NFRAC+1; i++){
        fac[i+1] = fac[i]*(i+1) % MOD;
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD;
    }
}

LL dfs(LL depth, LL prev, LL curr, LL K, LL2D &edges){
    LL m = (depth==0 ? K-1 : K-2);
    LL k = (LL)(depth==0 ? edges[curr].size() : edges[curr].size()-1);
    LL tmp = perm(m, k);
    for(auto c: edges[curr]){
        if(c==prev)continue;
        tmp = (tmp*dfs(depth+1, curr, c, K, edges))%MOD;
    }
    return tmp;
}

void solve(long long N, LL K, std::vector<long long> a, std::vector<long long> b){
    LL2D edges(N);
    rep(i, N-1){
        edges[a[i]-1].emplace_back(b[i]-1);
        edges[b[i]-1].emplace_back(a[i]-1);
    }
    init();
    cout << (K*dfs(0, -1, 0, K, edges))%MOD << endl;
}

int main(){
    long long N,K;
    scanf("%lld",&N);
    scanf("%lld",&K);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, K, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 17792
#include <cstdio>
// A - ∴ (Therefore)

using namespace std;

int main() {
    int N;

    scanf("%d",&N);
    N %= 10;
    if (N == 3)
        printf("bon\n");
    else if (N == 0 || N == 1 || N == 6 || N == 8)
        printf("pon\n");
    else
        printf("hon\n");

    return 0;
}


Measured memory_bytes: 1660
#include<iostream>
using namespace std;
long dp[31];
main()
{
    dp[0]=1;
    for(int i=1;i<=30;i++)
    {
        for(int j=1;j<=3&&i-j>=0;j++)dp[i]+=dp[i-j];
    }
    int n;
    while(cin>>n,n)cout<<(dp[n]-1)/3650+1<<endl;
}


Measured memory_bytes: 3008
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<vector<vector<vector<ll>>>> vvvvl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;

double N;

int main() {
  cin >> N;
  for(int i = 1; i < 50001; i++){
    int x = (int)i*1.08;
    if(x == N){
      cout << i <<endl;
      return 0;
    }
  }
  cout << ":(" <<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ks = []
for i in range(M):
    ks.append(list(map(int, input().split())))
P = list(map(int, input().split()))
count = 0
sw = [0] * N

def depth(index):
    global count
    for j in range(M):
        a = 0
        for k in range(ks[j][0]):
            if sw[ks[j][k + 1] - 1] == 1: a += 1
        if a % 2 == P[j]:
            if j + 1 == M: count += 1
        else: break

    for i in range(index, N):
        sw[i] = 1
        depth(i + 1)
        sw[i] = 0

depth(0)
print(count)


Measured memory_bytes: 3064
import bisect
N = int(input())
C = list(input())

R, W = 0, 0  # 石の個数
red, white = [], []  # 石の位置
for i in range(N):
    if C[i] == 'R':
        red.append(i)
        R += 1
    else:
        white.append(i)
        W += 1

ans = 10**10
for i in range(N+1):  # 並べ終わったとき、0番目からi番目までRが並んでいる
    ans = min(ans, max(bisect.bisect_left(white, i),
                       R-bisect.bisect_left(red, i)))
print(ans)


Measured memory_bytes: 94800
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
K = INT()


for i in range(len(S)):
	if int(S[i]) != 1:
		print(int(S[i]))
		break
	else:
		K -= 1
		if K <= 0:
			print(S[i])
			break


Measured memory_bytes: 5200
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int N,M,X,Y;

	int x[100];
	int y[100];

	cin >> N >> M >> X >> Y;
	for(int i=0;i<N;i++) cin >> x[i];
	for (int i = 0; i < M; i++)	cin >> y[i];

	sort(x, x + N);
	sort(y, y + M);

	for(int Z = -100;Z<=100;Z++){
		if(x[N-1]<Z && Z<=y[0] && X<Z && Z<=Y){
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;
	return 0;
	
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	static final int MOD = (int)1e9+7;

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		
		long a = sc.nextInt();
		long b = sc.nextInt();
		
		long res = 0;

		long[] x = sc.nextLongArray(n);
		
		for(int i = 1; i < n; i++) {
			long d = x[i] - x[i - 1];
			
			res+=Math.min(a*d, b);
		}
		
		out.println(res);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

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

	public static long factorial(int n) {
		long a;

		if(n > 0) {
			a = n * factorial(n - 1);
		}else{
			a = 1;
		}

		return a;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class UnionFind {
	int[] par;

	public UnionFind(int n) {
		par = new int[n];

		Arrays.fill(par, -1);
	}

	int root(int x) {
		if(par[x] < 0) return x;
		return par[x] = root(par[x]);
	}

	boolean unite(int x,int y) {
		x = root(x);
		y = root(y);

		if(x == y) return false;

		if(size(x) < size(y)) {
			int tmp = x;
			x = y;
			y = tmp;
		}

		par[x] += par[y];
		par[y] = x;

		return true;
	}

	boolean same(int x,int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}

	int size(int a) {
		return -par[root(a)];
	}
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
     }

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

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

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

ll mod_mul(ll x, ll n, ll mod){
  x %= mod;
  n %= mod;
  return x*n % mod;
}

bool millrr_rabin(ll n){
  if(n == 2) return true;
  if((n & 1) == 0 || n <= 1) return false;
  int a[] = {2, 3, 5, 7, 11, 13, 17, -1}, r;
  ll s = 0, d, x;
  d = n - 1;
  while((d & 1) == 0){
    s++;
    d = d >> 1;
  }
  
  for(int i = 0 ; a[i] != -1 && a[i] < n ; i++){
    if((x = mod_pow(a[i], d, n)) != 1){
      for(r = 0 ; r < s ; r++){
	if(x == n-1) break;
	x = mod_mul(x, x, n);
      }
      if(r == s) return false;
    }
  }
  return true;
}

int main(){
  int sum[1000010];
  sum[0] = 0;
  
  for(int i = 1 ; i <= 1000000 ; i++){
    sum[i] = sum[i-1];
    if(millrr_rabin(i)) sum[i]++;
  }
  
  int n;
  while(cin >> n){
    cout << sum[n] << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool check(int m, int d1, int d2){
  return d1 >= 2 && d2 >= 2 && d1*d2 == m;
}


int main(){
  int M, D;
  cin >> M >> D;

  int ret = 0;
  for(int m=1; m<=M; m++){
    for(int d=1; d<=D; d++){
      if(check(m, d%10, (d/10)%10)) ret++;
    }
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    ll n;
    cin >> n;
    vll a(n);
    cin >> a;
    /* sort(ALL(a)); */
    vector<int> occ(1000001, 0);
    REP(i, n) {
        occ[a[i]]++;
    }
    vector<bool> prime(1000001, true);
    int maxcnt = 0;
    FOR(i, 2, 1000001) {
        if (prime[i]) {
            int now = i, cnt = 0;
            while (now <= 1000000) {
                prime[now] = false;
                cnt += occ[now];
                now += i;
            }
            maxcnt = max(maxcnt, cnt);
        }
    }
    if (maxcnt == n) {
        cout << "not coprime" << endl;
    } else if (maxcnt > 1) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "pairwise coprime" << endl;
    }
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



Measured memory_bytes: 14980
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  ll ans=0;
 
 if(x<y){
    if((y<0&&x<0))ans=(ll)abs(x)-abs(y);
    else if((x<0&&y>0)&&abs(x)<abs(y))ans=(ll)1+abs(y)-abs(x);
    else if((x<0&&y>0)&&abs(x)>abs(y))ans=(ll)1+abs(x)-abs(y);
    else if((x<0&&y>0)&&abs(x)==abs(y))ans=1;
    else if(x>0&&y>0)ans=(ll)y-x;
    else if(x==0)ans=(ll)y;
    else if(y==0)ans=(ll)abs(x);
  }else{
    if(x<0&&y<0)ans=(ll)abs(y)-abs(x)+2;
    else if(x>0&&y>0)ans=(ll)2+abs(x)-abs(y);
    else if((x>0&&y<0)&&abs(x)<abs(y))ans=(ll)1+abs(y)-abs(x);
    else if((x>0&&y<0)&&abs(y)<abs(x))ans=(ll)1+abs(x)-abs(y);
    else if((x>0&&y<0)&&abs(y)==abs(x))ans=1;
    else if(x==0)ans=(ll)1+abs(y);
    else if(y==0)ans=(ll)1+abs(x);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e6+10, mod=1e9+7;


int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int a,b;
	cin>>a>>b;
	cout<<max(a-b,max(a+b,a*b));
}
// check for any potential overflow before submitting



Measured memory_bytes: 256
/*
貪欲
後ろから見る
DP
順位表をチェック



*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 3e18+7
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,ll>,ll> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);

ll S[210000],sum;

int main(){
    int N;
    cin>>N;
    ll A[210000];
    for(int i=1;i<=N;i++){
        cin>>A[i];
        S[i]=S[i-1]+A[i];
        sum+=A[i];
    }
    ll ans=INF;
    for(int i=0;i<=N;i++){
        ans=min(ans,abs((sum-S[i])-S[i] ));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

void chmax(ll& a, ll b) { a = max(a, b); }
void chmin(ll& a, ll b) { a = min(a, b); }



int main() {
    int s,w; cin >> s >> w;
    if(w >= s) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAtCoderCrackers solver = new AAtCoderCrackers();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAtCoderCrackers {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();

            if (n % k == 0) {
                out.println(0);
            } else {
                out.println(1);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21460
#include <iostream>
using namespace std;
int main(void){
    int W, H;
    while (1) {
        cin >> H >> W;
        if (W == 0 && H == 0) break;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>

using namespace std;

double getSD(vector<int> data);

int main() {
	int n, _s;
	vector<int> s;
	cout << fixed << setprecision(8);

	while(1) {
		cin >> n;
		if(0 == n) { break; }

		for(int i = 0; i < n; ++i){
			int _s;
			cin >> _s;
			s.push_back(_s);
		}
		cout << getSD(s) << endl;
		s.clear();
	}

	return 0;
}

double getSD(vector<int> data){
	int sum = 0;
	double average;
	double variance = 0.0;

	for(const auto& e : data){
		sum += e;
	}
	average = (double)sum / data.size();

	for(const auto& e : data) {
		variance += pow(e - average, 2);
	}
	variance /= data.size();

	return sqrt(variance);
}


Measured memory_bytes: 3280
#include <stdio.h>
long long int partition(long long int a[],long long int l,long long int u)
{
	long long int v,i,j,temp;
	v=a[l];
	i=l;
	j=u+1;
	
	do
	{
		do
			i++;
			
		while(a[i]<v&&i<=u);
		
		do
			j--;
		while(v<a[j]);
		
		if(i<j)
		{
			temp=a[i];
			a[i]=a[j];
			a[j]=temp;
		}
	}while(i<j);
	
	a[l]=a[j];
	a[j]=v;
	
	return(j);
}
 
 
void quick_sort(long long int a[],long long int l,long long int u)
{
	long long int j;
	if(l<u)
	{
		j=partition(a,l,u);
		quick_sort(a,l,j-1);
		quick_sort(a,j+1,u);
	}
}
 

 
 
int main()
{
  long long int n,k,i,j;
   scanf("%lld %lld\n",&n,&k);
 long long int a[n],sum=0;
  for(i=0;i<n;i++)
    scanf("%lld ",&a[i]);
 quick_sort(a,0,n-1);
    for(i=0;i<n-k;i++)
    {
      sum=sum+a[i];
    }
    printf("%lld",sum);
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

unsigned long long comb(long long n, long long r) {
  if (r == 0) return 1;
  else if (r == 1) return n;

  int numerator[r];
  int denominator[r];

  for (int k = 0; k < r; k++)
  {
      numerator[k] = n - r + k + 1;
      denominator[k] = k + 1;
  }

  for (int p = 2; p <= r; p++)
  {
      int pivot = denominator[p - 1];
      if (pivot > 1)
      {
          int offset = (n - r) % p;
          for (int k = p - 1; k < r; k += p)
          {
              numerator[k - offset] /= pivot;
              denominator[k] /= pivot;
          }
      }
  }

  unsigned long long result = 1;
  for (int k = 0; k < r; k++)
  {
      if (numerator[k] > 1) result *= numerator[k];
  }

  return result;
}

int main() {
  int n;
  cin >> n;
  int count = n;
  long long temp,a,b;
  std::vector<long long> v;
  for (size_t i = 0; i < count; i++) {
    cin >> temp;
    v.push_back(temp);
  }
  sort(v.begin(), v.end(), greater<int>());
  for (int i = 1; i < count; i++) {
    if (i == count - 1) {
      a = v[0];
      b = v[i];
    } else if (v[i] <= v[0]/2) {
      a = v[0];
      if (v[0]/2 - v[i] < v[i-1] - v[0]/2) b = v[i];
      else b = v[i-1];
      break;
    } else if (v[i] > v[0]/2) {
      continue;
    }
  }
  cout << a << ' ' << b << endl;
}


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

int main() {
    int x;
    cin >> x;
    int ans = 1;
    for(int b = 2; b<=x; b++) {
        int t = b * b;
        while (t <= x) {
            ans = max(ans, t);
            t *= b;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){

  long long int N,A,B,ans;

  cin>>N>>A>>B;

  if(A>B)
    cout<<"0"<<endl;

  else if(N==1)
    if(A!=B)cout<<"0"<<endl;
    else    cout<<"1"<<endl;

  else{
    ans=(B-A)*(N-2)+1;
    cout<<ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
const int N=100005,mod=1000000007;
int n,m,k,ans=1,pos[N],a[N],b[N],c[N],x[N],y[N],h[N],f[N];
set<int> s;
bool cmp(int a,int b){
	return x[a]==x[b]?y[a]>y[b]:x[a]<x[b];
}
bool comp(int a,int b){
	return x[a]==x[b]&&y[a]==y[b];
}
void add(int i,int v){
	while(i<=h[0]){
		c[i]=(c[i]+v)%mod;
		i+=i&(-i);
	}
}
int sum(int i){
	int res=0;
	while(i){
		res=(res+c[i])%mod;
		i-=i&(-i);
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=m;i++){
		scanf("%d",&b[i]);
		s.insert(b[i]);
	}
	set<int>::iterator it;
	for(int i=1;i<=n;i++){
		if(a[i]>b[1]&&a[i]<b[m]&&!s.count(a[i])){
			it=s.upper_bound(a[i]);
			k++;
			pos[k]=k;
			y[k]=*it-a[i];
			it--;
			x[k]=a[i]-*it;
			h[++h[0]]=y[k];
		}
	}
	sort(pos+1,pos+k+1,cmp);
	k=unique(pos+1,pos+k+1,comp)-pos-1;
	sort(h+1,h+h[0]+1);
	h[0]=unique(h+1,h+h[0]+1)-h-1;
	for(int i,j=1;j<=k;j++){
		i=pos[j];
		y[i]=lower_bound(h+1,h+h[0]+1,y[i])-h;
		f[i]=(sum(y[i]-1)+1)%mod;
		ans=(ans+f[i])%mod;
		add(y[i],f[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int c[5][5];

signed main() {

    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    
    bool f = true;
    int d1 = c[0][0] - c[0][1], d2 = c[0][1] - c[0][2];
    for(int i = 1; i < 3; i++) {
        if(c[i][0] - c[i][1] != d1 or c[i][1] - c[i][2] != d2) f = false;
    }
    d1 = c[0][0] - c[1][0], d2 = c[1][0] - c[2][0];
    for(int i = 1; i < 3; i++) {
        if(c[0][i] - c[1][i] != d1 or c[1][i] - c[2][i] != d2) f = false;
    }

    cout << (f?"Yes\n":"No\n") ;

  
    return 0;
}



Measured memory_bytes: 256
from re import fullmatch
S = input()
_s = "keyence"
flag = False
for i in range(len(_s)):
    tmp = fullmatch("(.*)" + _s[:i] + "(.*)" + _s[i:] + "(.*)", S)
    if tmp and sum([1 for j in range(1, 4) if tmp.group(j)]) <= 1:
        flag = True
print("YES") if flag else print("NO")


Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    VI a(3);
    REP(i,3) cin >> a[i];
    int i = max_element(ALL(a)) - a.begin();
    cout << char('A' + i) << endl;
    return 0;
}


Measured memory_bytes: 3076
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100+10;
int main()
{
	int N;
	int K;
	int a[maxn];
	int sum=0;
	cin>>N;
	cin>>K;
	int i;
	for(i=0;i<N;i++)
		cin>>a[i];
	sort(a,a+N);
	for(i=N-K;i<N;i++)
		sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

const int N=5e5+10;

int n;

int data[N];

void modify(int v)
{
    int l=v*2;
    int r=v*2+1;
    int Max;

    if(l<=n&&data[l]>data[v])
    {
        Max=l;
    }else
    {
        Max=v;
    }

    if(r<=n&&data[r]>data[Max]) Max=r;

    if(Max!=v)
    {
        swap(data[v],data[Max]);
        modify(Max);
    }
}

void build()
{
    for(int i=n/2;i>0;i--) modify(i);
}

int main()
{
    scanf("%d",&n);

    for(int i=1;i<=n;i++) scanf("%d",&data[i]);

    build();

    for(int i=1;i<=n;i++) printf(" %d",data[i]);
    puts("");

    return 0;
}



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

ll a[100000];
ll c[61][2];
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 60; i >= 0; i--) {
    for (int j = 0; j < n; j++)
      c[i][a[j]>>i&1]++;
  }
  ll best = 0;
  ll ans = 0;
  ll x = 0;
  for (int i = 60; i >= 0; i--) {
    if (x+(1ll<<i) > k) {
      ans += (1ll<<i)*c[i][1];
      continue;
    }
    if (c[i][1] < c[i][0]) {
      x += (1ll<<i);
      ll ans2 = ans;
      ans2 += (1ll<<i)*c[i][1];
      for (int j = 0; j < i; j++) {
	ans2 += (1ll<<j)*max(c[j][0],c[j][1]);
      }
      best = max(best, ans2);
    }
    ans += (1ll<<i)*max(c[i][0],c[i][1]);
  }
  best = max(best, ans);
  cout << best << endl;
}


Measured memory_bytes: 1152
/**
 *    Author: Sutlan Ahmed
**/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,s=0,f=0;
    for(int i=0;i<3;i++)
    {
        scanf("%d",&n);
        if(n==5)f++;
        else s++;
    }
    if(f==2&&s==1)printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<6;i++)
		ans+=(s[i]=='1');
	cout<<ans<<endl;	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

bool DEBUG = false;

int main(){
    int n, l;
    cin >>n >>l;
    int bestApple;
    if(l>0){
        bestApple = 1;
    }
    else{
        bestApple = min(n, -1*l + 1);
    }
    if(DEBUG) cout <<"BA=" <<bestApple <<" with flavour=" <<(l+bestApple-1) <<endl;
    int sum = 0;
    for(int i=1; i<=n; i++){
        sum += l+i-1;
    }
    if(DEBUG) cout <<"Sum=" <<sum <<endl;
    cout <<sum - (l+bestApple-1) <<endl;   
}

Measured memory_bytes: 256
n = int(input())
# b棟f階のr番目の部屋にv人が追加で入居した
bfrv = [list(map(int, input().split())) for i in range(n)]
rooms = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
for b,f,r,v in bfrv: rooms[b-1][f-1][r-1] += v
for b in range(4):
  for f in range(3):
    print(" "+" ".join(map(str, rooms[b][f])))
  if b<3: print("#"*20)


Measured memory_bytes: 5604
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); List <Integer> H = new ArrayList <Integer> (); List <Integer> W = new ArrayList <Integer> (); int lastH = 0; int lastW = 0; do { lastH = stdIn.nextInt(); lastW = stdIn.nextInt(); H.add(lastH); W.add(lastW); } while (lastH != 0 || lastW != 0); for(int i = 0; i < H.size()-1; i++) { for(int j = 0; j < H.get(i); j++) { if(j % 2 == 0) { for(int k = 0; k < W.get(i); k++) { if(k % 2 == 0) { System.out.print("#"); } else { System.out.print("."); } } } else { for(int k = 0; k < W.get(i); k++) { if(k % 2 == 0) { System.out.print("."); } else { System.out.print("#"); } } } System.out.println(); } System.out.println(); } } } 


Measured memory_bytes: 34752
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    def sequence(a,t):
        ans = 0
        x = 0
        for e in a:
            x += e
            if t == True and x<1:
                ans += 1-x
                x=1
            elif t== False and x>-1:
                ans += x+1
                x=-1
            t = not t
        return ans
    print(min(sequence(a,True),sequence(a,False)))

Measured memory_bytes: 16372
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var S = N.ToString();

            var allNine = true;
            for (var i = 1; i < S.Length; i++)
            {
                if (S[i] != '9')
                {
                    allNine = false;
                    break;
                }
            }

            var val = 0;
            if (allNine)
                foreach (var c in S) val += int.Parse(c.ToString());
            else
            {
                N -= (long)Math.Pow(10, S.Length - 1);
                val = N.ToString()[0] == '0' || N.ToString().Length == 1 ? 0 : int.Parse(N.ToString()[0].ToString());
                var remin = new string('9', S.Length - 1);

                foreach (var r in remin) val += int.Parse(r.ToString());
            }

            Console.WriteLine($"{val}");
        }
    }
}


Measured memory_bytes: 13140
N = gets.to_i
S = gets.chomp
MOD = 10 ** 9 + 7

counter = Hash.new(0)

ans = 0

S.each_char do |s|
  c = 1

  counter.each do |key, v|
    next if key == s

    t = v + 1

    c = (c * t) % MOD
  end

  ans = (ans + c) % MOD
  counter[s] += 1
end

puts ans


Measured memory_bytes: 1916
def f(a,b):
  p,q=a,b
  while q!=0: p,q=q,p%q
  return a/p*b
  
while 1:
  x=map(int,raw_input().split())
  if any(x)==0: break
  A=[]
  for i in range(0,6,2):
    a,b=x[i:i+2]
    c=1
    for j in range(1,b):
      c*=a; c%=b
      if c==1: break
    A.append(j)
  x=reduce(lambda a,b: f(a,b), A)
  print x

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

int main ()
{
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; s[i]; i++){
        if (s[i] == '1'){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256