akhauriyash/Code-Regression huggingface dataset:
import fractions as fr
from functools import reduce

def lcm_base(x, y):
  return (x * y) // fr.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

n=int(input())
a=list(map(int,input().split()))
aa=lcm_list(a)
ans=0
for i in a:
  ans+=aa//i
ans=aa/ans
print(ans)

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

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

const int dx[2][4] = {{1, 0, -1, 0}, {1, 0, -1, 0}};
const int dy[2][4] = {{0, 1, 0, -1}, {0, -1, 0, 1}};
const int MAX_W = 55;
const int MAX_H = 55;
char maze[2][MAX_H][MAX_W+1];
int sx[2], sy[2];
int tx[2], ty[2];
int h, w;
bool used[MAX_H][MAX_W][MAX_H][MAX_W];

inline bool check(int hx, int hy){ return 0 <= hx && hx < h && 0 <= hy && hy < w; }

int main()
{
  while(cin >> w >> h, w){
    rep(i, h) rep(j, w) rep(k, h) rep(l, w) used[i][j][k][l] = false;
    rep(i, h){
      rep(j, w) cin >> maze[0][i][j];
      rep(j, w) cin >> maze[1][i][j];
    }

    rep(i, h) rep(j, w) if(maze[0][i][j] == 'L') sx[0] = i,  sy[0] = j;
    rep(i, h) rep(j, w) if(maze[0][i][j] == '%') tx[0] = i,  ty[0] = j;
    rep(i, h) rep(j, w) if(maze[1][i][j] == 'R') sx[1] = i,  sy[1] = j;
    rep(i, h) rep(j, w) if(maze[1][i][j] == '%') tx[1] = i,  ty[1] = j;

    queue<vector<int> > que;
    vector<int> tmp(4);
    tmp[0] = sx[0];
    tmp[1] = sy[0];
    tmp[2] = sx[1];
    tmp[3] = sy[1];
    que.push(tmp);
    //    map<vector<int>, bool> used;
    used[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = true;
    //    used[tmp] = true;
    bool ok = false;
    while(!que.empty()){
      vector<int> h = que.front();  que.pop();
      if(h[0] == tx[0] && h[1] == ty[0] && h[2] == tx[1] && h[3] == ty[1]){
        ok = true;
        break;
      }
      rep(k, 4){
        int nx[2] = {h[0] + dx[0][k], h[2] + dx[1][k]};
        int ny[2] = {h[1] + dy[0][k], h[3] + dy[1][k]};
        if(!check(nx[0], ny[0]) && !check(nx[1], ny[1])) continue;
        if((nx[0] == tx[0] && ny[0] == ty[0]) && (nx[1] != tx[1] || ny[1] != ty[1])) continue;
        if((nx[0] != tx[0] || ny[0] != ty[0]) && (nx[1] == tx[1] && ny[1] == ty[1])) continue;
        if(check(nx[0], ny[0]) && maze[0][nx[0]][ny[0]] != '#'){
          tmp[0] = nx[0];
          tmp[1] = ny[0];
        }
        else{
          tmp[0] = h[0];
          tmp[1] = h[1];
        }
        if(check(nx[1], ny[1]) && maze[1][nx[1]][ny[1]] != '#'){
          tmp[2] = nx[1];
          tmp[3] = ny[1];
        }
        else{
          tmp[2] = h[2];
          tmp[3] = h[3];
        }
        if(h != tmp && !used[tmp[0]][tmp[1]][tmp[2]][tmp[3]]){
          used[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = true;
          //          used[tmp] = true;
          que.push(tmp);
        }
      }
    }

    puts(ok ? "Yes" : "No");
  }

  return 0;
}

Measured memory_bytes: 12148
N = int(input())

if N % 2 == 1:
    print(0)
    exit()

while N % 10 != 0:
    N -= 1

answer = 0

x = 1
while N // (5**x) > 1:
    answer += int((N//(5**x)) // 2)
    x += 1

print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long 
#define print(ds) for(auto i:ds){cout<<i<<" ";} cout<<endl;
#define printpair(pairs) cout<<pairs.first<<" "<<pairs.second<<endl;
#define p2v(v) for(int i=0; i<v.size();i++){ for(int j=0; j<v[i].size();j++){ cout<<v[i][j]<<" ";} cout<<endl;}
#define pp pair <ll, ll>
#define mod 1000000007
#define large 1e6
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int32_t main(){
    fastio;
    int n; cin>>n;
    vector <int> a(1000005,0);
    for(int i=1; i<=1000005; i++){
        for(int j=1; i*j<=1000005; j++){
            a[i*j]++;
        }
    }
    vector <int> prefix(1000006, 0);
    for(int i=0; i<1000005;i++){
        prefix[i+1] = prefix[i]+a[i];
    }
    cout<<prefix[n]<<endl;
}

Measured memory_bytes: 11104
#include <iostream>
#include <string>
#include <utility> // pairとか
#include <vector>
#include <array>
#include <list>
#include <deque>
#include <map>
#include <algorithm> // sortとか findとか
#include <functional> // algorithmに渡せる関数
#include <cmath>
#include <cstdio>
#include <numeric> // gcd,lcmとか
#define rep(iter, beg, end, step) for (long(iter) = (beg); (iter) < (end); (iter) += (step))
using namespace std;
int main() {
	int c[3][3];

	rep(i,0,3,1) {
		rep(j,0,3,1) {
			cin >> c[i][j];
		}
	}


	bool res = true;
	rep(j,0,2,1) { // tate
		int hiki = c[0][j] - c[0][j+1];
		rep(i,1,3,1) {
			if( c[i][j] - c[i][j+1] != hiki ) {
				res = false;
				goto end;
			}
		}
	}

	rep(i,0,2,1) { // tate
		int hiki = c[i][0] - c[i+1][0];
		rep(j,1,3,1) {
			if( c[i][j] - c[i+1][j] != hiki ) {
				res = false;
				goto end;
			}
		}
	}

	end:
	cout << ((res) ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int w[105],v[105];
int w1[105],w2[105],w3[105],w4[105];
int x1,x2,x3,x4;
int cnt1=1,cnt2=1,cnt3=1,cnt4=1;
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int n,W;
	cin>>n>>W;
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&w[i],&v[i]);
		if(w[i]==w[0])  w1[cnt1++]=v[i];
		if(w[i]==w[0]+1)w2[cnt2++]=v[i];
		if(w[i]==w[0]+2)w3[cnt3++]=v[i];
		if(w[i]==w[0]+3)w4[cnt4++]=v[i];
	}
	sort(w1+1,w1+cnt1,cmp);
	sort(w2+1,w2+cnt2,cmp);
	sort(w3+1,w3+cnt3,cmp);
	sort(w4+1,w4+cnt4,cmp);
	for(int i=2;i<cnt1;i++) w1[i]+=w1[i-1];
	for(int i=2;i<cnt2;i++) w2[i]+=w2[i-1];
	for(int i=2;i<cnt3;i++) w3[i]+=w3[i-1];
	for(int i=2;i<cnt4;i++) w4[i]+=w4[i-1];
	x1=w[0],x2=x1+1,x3=x2+1,x4=x3+1;
	int ma=-1;
	for(int i1=0;i1<=cnt1;i1++)
	for(int i2=0;i2<=cnt2;i2++)
	for(int i3=0;i3<=cnt3;i3++)
	for(int i4=0;i4<=cnt4;i4++)
	{
		if(1ll*i1*x1+1ll*i2*x2+1ll*i3*x3+1ll*i4*x4>1ll*W) continue;
		ma=max(w1[i1]+w2[i2]+w3[i3]+w4[i4],ma);
	}
	cout<<ma;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a,long long int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

long long int lcm(long int a,long int b)
{
    return (a * b) / gcd(a, b);
}
int main(void)
{
 long long int a, b;
 cin>>a>>b;
 cout<<lcm(a,b)<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (void) {
	int	a=0;
	int	b=0;
	int	c=0;

	scanf ("%d %d", &a, &b);

	c = a * b;
	
	if (c % 2 == 0) {
		printf ("Even");
	} else {
		printf ("Odd");
	}

	return 0;
}


Measured memory_bytes: 128
<?php
define("MOD", 10**9+7);

$n = int();
$a = ints();
$d = 0;
$p = factorialm($n-1);
$q = 0;
for($i = 1; $i < $n; $i++){
    $q = ($p+$q) % MOD;
    $p = mulm($p, $i);
    $p = divm($p, $i+1);
    $d += (($a[$i] - $a[$i-1])*$q)%MOD;
    $d %= MOD;
}
echo $d;


//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}
//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}
//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}
//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}
//組み合わせ
function nCm($n, $m){
    $m = min($m, $n-$m);
    return divm(nPm($n, $m), factorialm($m));
}

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 35444
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main(){
  int a,b;
  cin >> a >> b;
  int m = max(a,b) - min(a,b);
  int n = 16 - 2 * min(a,b);
  if(m * 2 <= n) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, M, = map(int, input().split())
L = [int(v) % 2 for v in input().split()]
L.sort()

zc = len([v for v in L if v == 0])
oc = len([v for v in L if v == 1])

if oc == 0:
    if M == 0:
        print(2 ** N)
    else:
        print(0)
else:
    print(2 **  (N - 1))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


/*
  UnionFind
*/
struct UnionFind {
vector<int> d;
UnionFind(int n = 0): d(n,-1) {}
int find(int x) {
  if (d[x] < 0) return x;
  return d[x] = find(d[x]);   //経路縮尺(メモ化再帰)
}
bool unite(int x, int y) {  //連結する
  x = find(x); y = find(y);
  if (x == y) return false;
  if (d[x] > d[y]) swap(x,y); //根の高さが小さい方に連結する
  d[x] += d[y];
  d[y] = x;
  return true;
}
bool same(int x, int y) { return find(x) == find(y);} //連結しているかを返す
int size(int x) { return -d[find(x)];}  //連結成分サイズを返す
};

int deg[100005];//直接接続している友人数のリスト
vector<int> to[100005]; //ブロック関係の連結リスト


int main(){
  int n, m;
  cin >> n >> m;
  UnionFind uF(n);

  REP(i,m){
    int a, b;
    cin >> a >> b;
    --a; --b;
    uF.unite(a,b);
  }
 
  int ans = 0;
  REP(i,n-1){
    if(uF.same(i,i+1)) continue;
    ans++;
    uF.unite(i,i+1);
  }

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

Measured memory_bytes: 6056
#include<stdio.h>

int gcd(int x,int y){
	
	int z=-1;
	
	while(z!=0){
		z=x%y;
		x=y;
		y=z;
	}
	
	return x;
}

int main(void){
	
	int x;
	int y;
	
	scanf("%d",&x);
	scanf("%d",&y);
	
	printf("%d\n",gcd(x,y));
	
	return 0;
	
}


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

int main () {
  int A, B, C;
  int K;
  cin >> A >> B >> C;
  cin >> K;
  
  int counter = 0;
  int tmp = 0;
  for (int i = 0; i < A+1; i++) {
    for (int j = 0; j < B+1; j++) {
      for (int k = 0; k < C+1; k++) {
        tmp = 500 * i + 100 * j + 50 * k;
        if (tmp == K) {
          counter++;
        }
      }
    }
  }
  
  cout << counter << endl;
  
}


Measured memory_bytes: 256
def main():
    in_list = list(map(int, input().split()))
    X = abs(in_list[0])
    K = in_list[1]
    D = in_list[2]

    max_move = K*D
    if max_move < X:
        print(X-max_move)
    else:
        iter1 = int(X/D)+1
        iter2 = K - iter1
        ans = X - iter1*D
        if iter2%2 == 0:
            print(abs(ans))
        else:
            print(abs(ans+D))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9136
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
	int a,b,c[100000],x=0,vx=0,z=1000000000;
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		cin >> c[i];
		if (c[i] > 0 && !vx) {
			x = i;
			vx++;
		}
		if (c[i] == 0) {
			b--;
			i--;
			a--;
		}
	}
	if (!vx) x = a;
	for (int i = 0; i < b - 1; i++) {
		if (x - i - 1 >= 0 && x + b - 2 - i < a) z = min(z, abs(c[x - i - 1]) * 2 + c[x + b - 2 - i]);
		if (x + i < a&&x - b + 1 + i >= 0) z = min(z, c[x + i] * 2 + abs(c[x - b + i + 1]));
	}
	if(b<=0) z = 0;
	if (x + b - 1 < a) z = min(z, c[x + b - 1]);
	if (x - b >= 0) z = min(z, abs(c[x - b]));
	cout << z << endl;
	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] Args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final int z[][] = new int[1001][1001];
        for(int i = 0; i<n; i++){
            final String x = br.readLine();
            final int xl = x.length();
            final String y = br.readLine();
            final int yl = y.length();
            for(int j = 0; j<=xl; j++)
                z[xl][0] = 0;
            for(int j = 0; j<=yl; j++)
                z[0][yl] = 0;
            for(int j = 1; j<=xl; j++){
                for(int k = 1; k<=yl; k++){
                    if(x.charAt(j-1)==y.charAt(k-1)) z[j][k] = z[j-1][k-1]+1;
                    else z[j][k] = Math.max(z[j-1][k], z[j][k-1]);
                }
            }
            System.out.println(z[xl][yl]);
        }
    }
}

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

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  const double r = 6378.1;
  double x1,y1,x2,y2;
  double c = M_PI/180.0;
  while(cin >> y1 >> x1 >> y2 >> x2){
    if(y1 == -1 && x1 == -1 && y2 == -1 && x2 == -1) break;
    y1 = y1 * c;
    y2 = y2 * c;
    double d = r * acos(sin(y1) * sin(y2) + cos(y1) * cos(y2) * cos(x1*c - x2*c));
    cout << (int)(d + 0.5) << endl;
  }
  return 0;
}

Measured memory_bytes: 1296
n, q = map(int, input().split())
s = input()
questions = [tuple(map(int,input().split())) for _ in range(q)]

part = [0]*n
al = [0]*n
for i in range(len(s)):
	if i == 0:
		continue
	if s[i-1:i+1]=='AC':
		al[i] = al[i-1]+1
		if i>1:
			part[i-1] = part[i-2] + 1
		else:
			part[i-1] = 1
	else:
		al[i] = al[i-1]
		if i>1:
			part[i-1] = part[i-2]
		else:
			part[i-1] = 0

for question in questions:
	l, r = question
	l -= 1
	r -= 1
	print(al[r]-part[l-1])


Measured memory_bytes: 22248
from math import ceil
r,g,b,n = map(int, input().split())

ans = 0
for i in range(ceil(n/r)+1):
  for j in range(ceil(n/g)+1):
    if n - (r*i + g*j) >= 0 and (n - (r*i + g*j)) % b == 0: ans += 1
print(ans)

Measured memory_bytes: 68668
def main():
    n = int(input())
    vlis = list(map(int, input().split()))
    vlis.sort()
    mae = vlis[0]
    for i in range(1, n):
        ato = vlis[i]
        heikin = (mae + ato) / 2
        mae = heikin
    print(heikin)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 61896
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;

int main() {
	int n, m;
	cin >> n >> m;
	int num = m;
	set<ll> divisors;
	divisors.insert(1);
	for (int i = 2; i*i <=m;i++) {
		
		while (num%i == 0) {
			set<ll> tmp_div;
			for (auto it = divisors.begin();it != divisors.end();it++) {
				tmp_div.insert(*it);
				tmp_div.insert(*it * i);
			}
			divisors = tmp_div;
			num /= i;
		}
		
	}

	if (num > 1) {
		divisors.insert(num);
	}

	int ans = 1;
	int max = m / n;
	for (auto it = divisors.begin();it != divisors.end();it++) {
		//cout << *it << endl;
		if (*it <= max) {
			//cout << *it << endl;
			ans = *it;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

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

	int ans = 0;
	if (a >= k) ans = k;
	else if (a + b >= k) ans = a;
	else ans = a - (k - a - b);

	dunk(ans);
	return 0;
}


Measured memory_bytes: 3632
S = input()
T = input()

S_length = len(S)
T_length = len(T)

if S_length < T_length:
    print("UNRESTORABLE")
    
elif S_length == T_length:
    for i in range(T_length):
        if S[i] != "?" and S[i] != T[i]:
            print("UNRESTORABLE")
            break
    else:
        print(T)
    
else:
    flag = 0
    for i in range(S_length - T_length):
        for j in range(T_length):
            if S[S_length - T_length - i + j] != "?" and S[S_length - T_length - i + j] != T[j]:
                break
        else:
            flag = 1
            S = S[:S_length - T_length - i] + T + S[S_length - i:]
            break
            
    if flag == 1:
        ans = S.replace("?", "a")
        print(ans)
        
    elif flag == 0:
        print("UNRESTORABLE")

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

int main(){ 
    Int N,cnt;
    cin >> N;
    cnt = 0;

    vector<string> S(N+10);
    set<string> T;
    set<string>::iterator ite;;

    rep(i,N) cin >> S[i];

    rep(i,N) T.insert(S[i]);

    for (ite = T.begin(); ite != T.end(); ++ite){
        cnt++;
    }

    cout << cnt << endl;


}

Measured memory_bytes: 24944
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long INF = 1_000_000_000_000_000_000L;
        int N = sc.nextInt();
        int[] a = new int[N];
        long[] ruiseki = new long[N+1];
        for (int i=0;i<N;i++) {
            a[i] = sc.nextInt();
            ruiseki[i+1] = ruiseki[i]+a[i];
        }

        long[][] dp = new long[N+1][N+1];
        for (int w=1;w<=N;w++) {
            for (int l=0;l<N;l++) {
                int r = l+w;
                if (r>N) continue;
                if (r==l+1) {
                    dp[l][r] = 0;
                } else {
                    long tmp = INF;
                    for (int mid=l+1;mid<r;mid++) {
                        tmp = Math.min(tmp, dp[l][mid]+dp[mid][r]+ruiseki[r]-ruiseki[l]);
                    }
                    dp[l][r] = tmp;
                }
            }
        }
        System.out.println(dp[0][N]);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  string s;
  set<string> keys;
  cin>>n;
  rep(i,n){
    cin>>s;
    keys.insert(s);
  }
  cin>>n;
  bool now = true;
  rep(i,n){
    cin>>s;
    //    cout<<keys.find(s)<<endl;
    if(keys.find(s)!=keys.end()){
      if(now){
	cout<<"Opened by ";
      }else{
	cout<<"Closed by ";
      }
      now = !now;
    }else{
      cout<<"Unknown ";
    }
    cout<<s<<endl;
  }


}

Measured memory_bytes: 1232
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m, k;
    cin >> n >> m >> k;
    n = max(n, m);
    cout << (k + n - 1) / n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;
  
int main()
{
	int i;
	int cnt[26] = { 0 };
	char ch;

	while(cin >> ch ){// ????????§ch?????¢??????????????????????????°??????
		if(isalpha(ch)){
			if(isupper(ch))
			ch = tolower(ch);
			cnt[ch-'a']++;
		}
	}
	
	//a : a????????°?????????????????¨???
	for(i = 0; i < 26; i++) {
        cout << (char)('a' + i) << " : " << cnt[i] << endl;
    }
	return 0;
}

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

int main() {

    int x, y;

    for ( ;; ) {

        std::cin >> x >> y;

        if ( x == 0 && y == 0 ) break;

        if ( x > y ) std::swap(x, y);

        std::cout << x << " " << y << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const int N = 2e5 + 5;

ll n, k, a[N];
bool visited[N];

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

    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];

    int ptr = 1, c = 0, period = -1, ptr1;
    vi cycle(n + 1);

    while (true) {
        if (visited[ptr]) {
            period = c - cycle[ptr];
            ptr1 = ptr;
            break;
        }

        cycle[ptr] = c;
        visited[ptr] = true;

        ptr = a[ptr];
        c += 1;
    }

    if (k < c) {
        for (int i = 1; i <= n; i++) {
            if (cycle[i] == k) {
                cout << i << "\n";
                return 0;
            }
        }
    }

    k -= c;
    k %= period;

    ptr = ptr1;
    c = 0;

    while (true) {
        if (c == k) {
            cout << ptr << "\n";
            return 0;
        }
        ptr = a[ptr];
        c += 1;
    }

    return 0;
}

Measured memory_bytes: 5784
#include<iostream>
using namespace std;
typedef long long llong;
llong f(llong x) {
	return x*x;
}
int main() {
	int d;
	while (cin >> d) {
		llong s = 0;
		for (int i = d; i < 600; i += d) {
			s += f(i)*d;
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int m,nmn,nmx;
int gap=0;
int p[10005];
int main(void)
{
  while(cin >> m >> nmn >> nmx && m)
    {
      int ans;
      gap=0;
      for(int i=1;i<=m;i++)
	{
	  cin >> p[i];
	}
      for(int i=nmn;i<=nmx;i++)
	{
	  int tmp;
	  tmp=p[i]-p[i+1];
	  if(tmp>=gap)
	    {
	      gap=tmp;
	      ans=i;
	    }
	}
      cout << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 3072
N,*as=$<.read.split.map(&:to_i)
MOD=10**9+7

def comb2(n)
    n * (n-1) / 2
end

ret = 0

60.times do |i|
    ones = as.count {|a| a[i] == 1 }
    zeros = as.count {|a| a[i] == 0 }
    n = comb2(ones+zeros) - comb2(ones) - comb2(zeros)
    ret += n * 2.pow(i,MOD) % MOD
end

puts ret % MOD



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

ll dp[3001][3001][4]; // dp[i][j][k] := (i,j)で、同じ行でk個以下取った時の最大値
ll item[3001][3001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int R,C,K; cin >> R >> C >> K;
    int r, c; ll v;
    rep(i, K){
        cin >> r >> c >> v;
        --r; --c;
        item[r][c] = v;
    }

    rep(i,3) dp[0][0][i+1] = item[0][0];
    rep(i,R-1){
        dp[i+1][0][0] = dp[i][0][3];
        rep(k, 3) dp[i+1][0][k+1] = dp[i][0][3] + item[i+1][0];
    }
    rep(i,C-1){
        dp[0][i+1][0] = dp[0][i][0];
        rep(k,3) dp[0][i+1][k+1] = max(dp[0][i][k] + item[0][i+1], dp[0][i][k+1]);
    }
    
    rep(i, R-1) rep(j, C-1){
        dp[i+1][j+1][0] = max(dp[i][j+1][3], dp[i+1][j][0]);
        rep(k, 3){ // k(k >= 1)個以下取る場合
            dp[i+1][j+1][k+1] = max({
                dp[i+1][j][k+1], // 左からの遷移、取らない場合
                dp[i+1][j][k] + item[i+1][j+1], // 左からの遷移、取る場合
                dp[i][j+1][3] + item[i+1][j+1] // 上からの遷移、この場合は必ず取ってよい
            });
        }
    }
    cout << dp[R-1][C-1][3] << endl;
}

Measured memory_bytes: 355216
#include <iostream>

using namespace std;

int n, a[100005], f[100005], b[100005], ans;

int gcd(int x, int y)
{
	if (y > x) swap(x, y);
	if (y == 0) return x;
	return gcd(y, x % y);
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	f[1] = a[1];
	b[n] = a[n];
	for (int i = 2; i <= n; i++) f[i] = gcd(a[i], f[i - 1]);
	for (int i = n - 1; i >= 1; i--) b[i] = gcd(a[i], b[i + 1]);
	for (int i = 2; i < n; i++)
	{
		ans = max(ans, gcd(f[i - 1], b[i + 1]));
	}
	ans = max(ans, b[2]);
	ans = max(ans, f[n - 1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
from itertools import combinations as comb
def main():
    N = int(input())
    L = list(map(int, input().split()))
    count = 0
    for a, b, c in comb(L, 3):
        a, b, c = sorted([a, b, c])
        if a == b or b == c or c == a:
            continue
        if c < a + b:
            count += 1
    print(count)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
n,m,x = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]

def dfs(i, ais, cur):
	if i == len(ais): return 0 if all([e<=0 for e in cur]) else +float('inf')
	return min( ais[i][0] + dfs(i+1 , ais, [c - ais[i][j+1] for j,c in enumerate(cur)]), dfs(i+1, ais, cur))

r = dfs(0,ais,[x] * m) 
print r if r < float('inf') else -1

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/


int main(){
    fIO

    int r;
    cin >> r;

    cout << r * r;

}








Measured memory_bytes: 256
from fractions import gcd
def find(a):
    ans = a[0]
    for i in range(1,len(a)):
        ans = ((ans)//(gcd(ans,a[i])) * a[i])
    return ans            
	


n = int(input())
a = list(map(int,input().split()))

lcm = find(a)
ans = 0
mod = pow(10,9)+7
for i in a:
	ans = ans + lcm//i
	
print(ans%mod)	


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

using namespace std;

class Disjoint{
    public:
    
        vector<int> rank, p;
        
        Disjoint(){}
        Disjoint(int size){
            rank.resize(size, 0);
            p.resize(size,0);
            
            for(int i=0; i<size; i++){
                Makeset(i);
            }
        }
        
        void Makeset(int x){
            p[x] = x;
            rank[x] = 0;
        }
        
        bool same(int x, int y){
            return Findset(x) == Findset(y);
        }
        
        void unite(int x, int y){
            link(Findset(x), Findset(y));
        }
        
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] =x;
            }else{
                p[x] = y;
                if(rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }
        
        int Findset(int x){
            if(x != p[x]){
                p[x] = Findset(p[x]);
            }
            return p[x];
        }
};


int main(){
    int n, a, b, q;
    int command;
    
    cin >> n >> q;
    Disjoint DS = Disjoint(n);
    
    
    for(int i=0; i<q; i++){
        cin >> command >> a >> b;
        
        if(command == 0){
            DS.unite(a, b);
        }else if(command == 1){
            if(DS.same(a, b)){
                cout << 1 << endl;
            }else{
                cout << 0 << endl;
            }
            
        }
    }
    
    return 0;
}


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

int main() {
  ll N,x; cin>>N>>x;
  vi a(N); REP(i,N) cin>>a[i];
  vvi dp(N,vi(N));
  REP(i,N) dp[i][0]=a[i];
  FOR(i,1,N) REP(j,N) {
    dp[j][i]=min(a[j],dp[(j-1+N)%N][i-1]);
  }
  ll ans=INF;
  REP(i,N) {
    ll t=0;
    REP(j,N) t+=dp[j][i];
    t+=i*x;
    ans=min(ans,t);
  }
  cout<<ans<<endl;
}


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

int main()
{
	int A[101][101];
	int b[101];
	int n,m;
	int c = 0;
	
	cin >> n >> m;
	
	//??????A???????´?
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			cin >> A[i][j];
		}
	}
	//???????????????b???????´?
	for(int i=1; i<=m; i++){
		cin >> b[i];
	}
	//??????A??¨???????????????b?????????
	for(int i=1; i<=n; i++){
		c = 0;
		for(int j=1; j<=m; j++){
			c += (A[i][j] * b[j]);
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#define DBG 0 //submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif

using namespace std;


int main(){
    int r,g,b;
    bool flag = false;
    cin >> r >> g >> b;
	
    if((g*10+b)%4 == 0) flag=true;
    
    cout << (flag ? "YES" : "NO") << endl;
    //cout << ans << endl;

}


Measured memory_bytes: 256
from sys import stdin
inf = 10**10
n = int(stdin.readline().rstrip())
to = [inf]*26
s = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    li = [0]*26
    p = stdin.readline().rstrip()
    for j in range(len(s)):
        li[j] += p.count(s[j])
    for k in range(26):
        to[k] = min(to[k],li[k])
sn = ""
for i in range(26):
    if to[i] > 0:
        sn += s[i]*to[i]
print(sn)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;

int main(){
  int n; cin >>n;
  int a[10100];
  int ans=0;
  for(int i=0;i<n;i++){
    cin >>a[i];
    while(a[i]%2==0){
      ans++;
      a[i]/=2;
    }
  }
  cout<<ans<<endl;



}


Measured memory_bytes: 256
def main():
    n, a, b, c = map(int, input().split())
    s = [list(input()) for _ in range(n)]
    t = a+b+c
    d = dict(A=a, B=b, C=c)
    ans = []
    if t == 0:
        print("No")
        return
    if t == 1:
        for i in range(n):
            si = s[i]
            if d[si[0]] == 1:
                d[si[0]], d[si[1]] = 0, 1
                ans.append(si[1])
            elif d[si[1]] == 1:
                d[si[0]], d[si[1]] = 1, 0
                ans.append(si[0])
            else:
                print("No")
                return
        print("Yes")
        print("\n".join(ans))
    else:
        for i in range(n-1):
            si = s[i]
            sin = s[i+1]
            if d[si[0]] >= 1 and d[si[1]] >= 1:
                if si[0] in sin:
                    d[si[0]] += 1
                    d[si[1]] -= 1
                    ans.append(si[0])
                else:
                    d[si[0]] -= 1
                    d[si[1]] += 1
                    ans.append(si[1])
            elif d[si[0]] == 0 and d[si[1]] >= 1:
                d[si[0]] += 1
                d[si[1]] -= 1
                ans.append(si[0])
            elif d[si[0]] >= 1 and d[si[1]] == 0:
                d[si[0]] -= 1
                d[si[1]] += 1
                ans.append(si[1])
            else:
                print("No")
                return
        si = s[n-1]
        if d[si[0]] >= 1 and d[si[1]] >= 1:
            ans.append(si[0])
        elif d[si[0]] == 0 and d[si[1]] >= 1:
            ans.append(si[0])
        elif d[si[0]] >= 1 and d[si[1]] == 0:
            ans.append(si[1])
        else:
            print("No")
            return
        print("Yes")
        print("\n".join(ans))
        
        
        

if __name__ == "__main__":
    main()

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

using namespace std;

int n;
int ball[10]; 
vector<int> l;
vector<int> r;

bool solve() {
    bool res = false;
    for (int i = 0; i < 1024; i++) {
        for (int j = 0; j < 10; j++) {
            if (i & (1 << j)) {
                l.push_back(ball[j]);
            }
            else {
                r.push_back(ball[j]);
            }
        }
        int lLen = l.size();
        int rLen = r.size();
        bool lOK = true;
        bool rOK = true;        
        for (int j = 0; j < lLen - 1; j++) {
            if (l.at(j) > l.at(j + 1)) {
                lOK = false;
                break;
            }
        }
        for (int j = 0; j < rLen - 1; j++) {
            if (r.at(j) > r.at(j + 1)) {
                rOK = false;
                break;
            }
        }
        if (lOK && rOK) {
            res = true;
            break;
        }
        l.clear();
        r.clear();        
    }
    return res;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> ball[j];
        }        
        if (solve()) {
            cout << "YES" << endl;
        } 
        else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

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

Measured memory_bytes: 384
SENTINEL = 9999999999999

count = 0

def merge(S, n, left, mid, right):
    global SENTINEL
    global count
    n1 = mid - left
    n2 = right - mid
    L = S[left:mid] + [SENTINEL]
    R = S[mid:right] + [SENTINEL]
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

def mergeSort(S, n, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(S, n, left, mid)
        mergeSort(S, n, mid, right)
        merge(S, n, left, mid, right)

n = int(input())
S = list(map(int, input().split(" ")))

mergeSort(S, n, 0, n)
print(*S)
print(count)


Measured memory_bytes: 61648
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll a[210000];
int main()
{
	ll n;
	cin>>n;
	ll ans=0;
	ll cnt=1;
	for(int i=0;i<n;i++){
		cin>>a[i];  a[i]-=cnt;
		cnt++;
		
	}
	sort(a,a+n);
	if(n%2==0)
	{
		ll t1,t2;
		t1=t2=0;
		for(int i=0;i<n;i++)
			t1+=abs(a[i]-a[n/2]);
		for(int i=0;i<n;i++)
			t2+=abs(a[i]-a[n/2-1]);
		ans=min(t1,t2);	
	}	
	else{
		for(int i=0;i<n;i++)
		   ans+=abs(a[i]-a[n/2]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
import math
N=int(input())
b=list(map(int, input().split()))

if(sum(1 for i in range(1, N+1) if b[i-1] > i)):
    ret = [-1]

else:
    M = max(b)
    ret = []
    while len(b):
        for j in range(min(M, len(b)), 0, -1):

            if j == b[j-1]:
                ret += [b[j-1]]
                del b[j-1]
                break

print("\n".join(map(str,ret[::-1])))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

const ll INF = 1LL << 60;

#define MAX 51
ll com[MAX][MAX];
void calc_com(){
  memset(com, 0, sizeof(com));
  com[0][0] = 1;
  for (int i = 1; i < MAX; i++) {
    com[i][0] = 1;
    for (int j = 1; j < MAX; j++) {
      com[i][j] = com[i-1][j] + com[i-1][j-1];
    }
  }
}

int main(){
  int n,p; cin >> n >> p;
  int even = 0, odd = 0;
  rep(i, n){
    int a; cin >> a;
    if(a%2 == 0) even++;
    else odd++;
  }
  
  calc_com();

  ll ans0 = 0;// P=0 の時の答え。P=1 だったら (1<<n) - ans0 が答え
  for (int i = 0; i <= odd; i += 2) {
    ans0 += com[odd][i]*(1LL << even);
    //printf("ans0:%d\n",ans0 );
  }

  ll ans1 = 0;
  for (int i = 1; i <= odd; i += 2) {
    ans1 += com[odd][i]*(1LL << even);
  }

  std::cout << (p ? ans1 : ans0) << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  string S;
  LINT K;
  cin >> S >> K;

  int sl = S.size();
  int i=0;
  while(i<sl){
    if(S[i] != '1') {
      cout << S[i] << endl;
      break;
    }
    else if(i == K-1) {
      cout << 1 <<endl;
      break;
    }
    else ++i;
  }


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    int f = 0, i,o, j, l, z, q, k[6], s[100][6], n[6], n2[6];
    char c;
    scanf("%d",&q);
    for (z = 0; z < q; z++){
        for (i = 0; i < 6; i++){
            scanf("%d", &s[z][i]);
            n[i] = i;
        }
    }
    for (i = 0; i < q; i++){
        for (z = 0; z < q; z++){
            if (i != z){
                for (j = 0; j < 19; j++){
                    if (j % 5 == 0){
                        n2[0] = n[1]; 
                        n2[1] = n[5]; 
                        n2[3] = n[3]; 
                        n2[4] = n[0]; 
                        n2[2] = n[2]; 
                        n2[5] = n[4];
                    }
                    else {
                        n2[0] = n[3]; 
                        n2[1] = n[1]; 
                        n2[3] = n[5]; 
                        n2[4] = n[4]; 
                        n2[2] = n[0]; 
                        n2[5] = n[2];
                    }
                    for (o = 0; o < 6; o++){
                        n[o] = n2[o];
                    }
                    for (l = 0; l < 6; l++){
                        if (s[i][l] != s[z][n[l]])break;
  
                    }
                    if (l == 6){ 
                        f = 1; 
                        break;
                    }
  
                }
            }
            if (f == 1)break;
        }
        if (f == 1)break;
    }
        if (f == 1)printf("No\n");
        else printf("Yes\n");
    return 0;
}


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

int main() {
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}


Measured memory_bytes: 3588
import sys

n, *lst = map(int, sys.stdin.read().split())
res = 0
tmp = 0
prep = lst[0]
for i in lst[1:]:
  if i > prep:
    res = max(res, tmp)
    tmp = 0
  else:
    tmp += 1
  prep = i
else:
  res = max(res, tmp)
print(res)

Measured memory_bytes: 14092
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

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

    int i = 0;
    while((1 + i) * i / 2 < n){
        i++;
    }

    vector<int> v;
    for(int j = i; i >= 0; i--){
        if(n >= i){
            n-=i;
            v.emplace_back(i);
        }
        if(n == 0) break;
    }

    for(int j = v.size() - 1; j >= 0; j--){
        cout << v[j] << endl;
    }
}


Measured memory_bytes: 384
N,K = map(int, input().split())
#h = list(map(int, input().split()))
h = [int(input()) for _ in range(N)]
h.sort()
min=100000000000000000000
for i in range(0,N-(K-1)):
  if h[i+(K-1)]-h[i]<min:
    min=h[i+(K-1)]-h[i]
print(min)


Measured memory_bytes: 50264
from queue import LifoQueue


def print_sol(c, sol):
    print('Case #{}: {}'.format(c, sol))


def rd_int():
    return int(input())


def rd_str():
    return input()


def rd_str_lst():
    return input().split(' ')


def sp_str_lst():
    return list(input())


def rd_int_lst():
    return [int(i) for i in rd_str_lst()]


def sp_int_lst():
    return [int(i) for i in sp_str_lst()]


def dfs(g, i, v):
    """
    recursive post order dfs
    Args:
        g: array of graph nodes
        i: node to traverse
        v: visited array

    Returns: a post order dfs of graph g
    """
    v[i] = True
    for j in g[i]:
        if not v[j]:
            dfs(g, j, v)

    print(i)


def dfs_iter(g, i, n):
    v = [False] * n
    stack = LifoQueue()
    stack.put(i)
    while stack.not_empty:
        u = stack.get()
        v[u] = True
        print(u)
        for i in g[u]:
            if not v[i]:
                stack.put(i)


def main():
    s = rd_str()
    t = rd_str()

    sol = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            sol += 1

    print(sol)


if __name__ == '__main__':
    main()


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

int main()
{
    const int MAX_N = 2000;
    int n;
    std::cin >> n;
    std::pair<long long, int> a[MAX_N];
    for (int i = 0; i < n; ++i)
    {
        std::cin >> a[i].first;
        a[i].second = i;
    }

    std::sort(a, a + n);
    long long ans[MAX_N][MAX_N];
    for (int j = 0; j < n; ++j)
    {
        ans[0][j] = a[0].first * std::abs(a[0].second - j);
    }

    //a[i]
    for (int i = 1; i < n; ++i)
    {
        //埋まっている先頭の数
        for (int j = 0; i + j < n; ++j)
        {
            long long front = ans[i - 1][j + 1] + a[i].first * std::abs(a[i].second - j);
            long long back = ans[i - 1][j] + a[i].first * std::abs(a[i].second - (j + i));
            ans[i][j] = std::max(front, back);
        }
    }

    std::cout << ans[n - 1][0] << std::endl;
    return 0;
}

Measured memory_bytes: 26344
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	as := make([]int, n+2)
	as[0] = 0
	for i := 1; i < n+1; i++ {
		var s int
		fmt.Scanf("%d", &s)
		as[i] = s
	}
	as[n+1] = 0
	sum := 0
	for i := 0; i < len(as)-1; i++ {
		d := as[i+1] - as[i]
		if d < 0 {
			d = -d
		}
		sum += d
	}
	for i := 1; i < len(as)-1; i++ {
		d1 := as[i+1] - as[i-1]
		if d1 < 0 {
			d1 = -d1
		}
		d2 := as[i] - as[i-1]
		if d2 < 0 {
			d2 = -d2
		}
		d3 := as[i+1] - as[i]
		if d3 < 0 {
			d3 = -d3
		}
		fmt.Printf("%d\n", sum+d1-d2-d3)
	}
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int R,G;
	cin>>R>>G;
	ce(2*G-R)
	
}

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

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
using namespace std;

int main(){
	int n = 5;

	vector<int> aa;

	REP(i, n){
		int a;
		cin >> a;
		aa.push_back(a);
	}

	sort(aa.begin(), aa.end(),greater<int>());

	int i(0);
	for (auto x : aa){
		cout << x;
		if (i != 4){
			cout << " ";
		}
		++i;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1212