akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  vector<ll> P(N);
  vector<ll> C(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }

  vector<ll> steps(N);
  vector<vector<ll>> scores(N, vector<ll>());
  vector<ll> final(N);
  for (int i = 0; i < N; i++) {
    int j = i;
    ll score = 0;
    ll step = 0;
    while (1) {
      j = P[j] - 1;
      score += C[j];
      step++;
      scores[i].push_back(score);
      if (j == i) {
        steps[i] = step;
        final[i] = score;
        break;
      }
    }
  }

  ll output = -1000000000;
  for (int i = 0; i < N; i++) {
    ll tmp = -1000000000;
    if (K <= steps[i]) {
      for (int j = 0; j < K; j++) {
        if (scores[i][j] > tmp) {
          tmp = scores[i][j];
        }
      }
    } else if (final[i] <= 0) {
      for (int j = 0; j < steps[i]; j++) {
        if (scores[i][j] > tmp) {
          tmp = scores[i][j];
        }
      }
    } else {
      tmp = final[i] * (K / steps[i]);
      ll rest = K % steps[i];
      ll tmpp = 0;
      for (int j = 0; j < rest; j++) {
        if (scores[i][j] > tmpp) {
          tmpp = scores[i][j];
        }
      }
      for (int j = rest; j < steps[i] - rest; j++) {
        if (scores[i][j] - scores[i][steps[i] - 1] > tmpp) {
          tmpp = scores[i][j] - scores[i][steps[i] - 1];
        }
      }
      tmp += tmpp;
    }
    if (tmp > output) {
      output = tmp;
    }
  }

  cout << output << endl;

  return 0;
}

Measured memory_bytes: 218884
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#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 llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

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

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

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};


int main(){
    int N;
    ll M=1;
    ll a[102];
    cin >> N;
    rep(i,N){
        cin >> a[i];
        M = lcm(a[i], M);
    }
    ll mother = 0;
    rep(i,N){
        mother += (M/a[i]);
    }
    ll child = M;
    std::cout << std::fixed << std::setprecision(5) << (float)child / mother << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    int x;cin >> x;
    if(x >= 30) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3600
/*
ID: Aman Raj
LANG: C++
TASK: preface
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

	   //vector<ll > vten(7),vfive(7),vfifty(7),vhundred(7),vfivehundred(7),vthousand(7);

int main()
{
      ifstream fin("preface.in");
      ofstream fout("preface.out");
      ll n,tw;cin>>n>>tw;
        vector<pair<ll,ll> > v(n+1);
         v[0]=make_pair(0,0);
        //v[0].resize(n+1,{0,0});
        for(ll i=1;i<=n;i++)cin>>v[i].first>>v[i].second;
        sort(all(v));
        vector<vector<ll> >  vpw(n+1);
         vpw[0].resize(tw+1);
        ll i=1;

        while(i<=n)
         {   vpw[i].resize(tw+1);
             for(ll w=0;w<=tw;w++)
             {   //if(w==0)vpw[i][w]=0;
                  //if(v[i].first>w)vpw[i][w]=vpw[i-1][w];


                    if(w>=v[i].first)  vpw[i][w]=max(vpw[i-1][w],v[i].second+vpw[i-1][w-v[i].first]);
                    else vpw[i][w]=vpw[i-1][w];


              }
              i++;
         }
        // for(ll i=0;i<=n;i++){for(ll j=0;j<=tw;j++)cout<<vpw[i][j]<<" ";cout<<endl;}
         cout<<vpw[n][tw];




	return 0;
}


Measured memory_bytes: 79488
import sys

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline().rstrip())
n = len(s)

def main():
    res = set()
    for l in range(n):
        for r in range(l, min(l+k, n)):
            res.add(s[l:r+1])

    return sorted(res)[k-1]

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

bool isPrime(long long x) {
    if (x == 1) return true;
    for (long long i = 2; i*i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

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

vector<long long> common_divisors(long long a, long long b) {
    long long n = gcd(a, b);
    vector<long long> ans;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (n / i == i) {
                ans.push_back(i);
            }
            else {
                ans.push_back(n / i);
                ans.push_back(i);
            }
        }
    }
    return ans;
}
vector<int> get_divisors(long long n) {
    vector<int> ans;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (i == n / i) {
                ans.push_back(i);
            }
            else {
                ans.push_back(n / i);
                ans.push_back(i);
            }
        }
    }
    sort(ans.rbegin(), ans.rend());
    return ans;
}

bool is_sorted(vector<int> a) {
    int n = a.size();
    for (int i = 0; i < n - 1; i++) {
        if (a[i + 1] < a[i]) return false;
    }
    return true;
}

int mxN = 1e5;
int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        a[i].first = y;
        a[i].second = x;
    }
    sort(a.begin(), a.end());
    long long sum = 0;
    bool ok = true;
    for (int i = 0; i < n; i++) {
        if (sum + a[i].second <= a[i].first) {
            sum += a[i].second;
        }
        else {
            ok = false;
            break;
        }
    }
    if (ok) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 4852
import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *	
from heapq import *
#from math import *
from itertools import permutations ,product
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
def inc(d,c):
	d[c]=d[c]+1 if c in d else 1
def bo(i):
	return ord(i)-ord('A')	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())			
def gh():
	sys.stdout.flush()
def isvalid(i,j):
	return 0<=i<n and 0<=j<n	
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)


t=1

while t>0:
	t-=1
	n=fi()
	a=li()
	s=sum(a)
	c=0
	mod=10**9+7
	mod2=pow(2,mod-2,mod)
	for i in range(n):	
		c=(c+(s-a[i])*a[i])%mod
	print((c*mod2)%mod)	

	



Measured memory_bytes: 97852
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = sc.nextInt();

		if (n % 500 <= a)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}


Measured memory_bytes: 22868
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int a,b,c;
	for(;cin>>a>>b>>c;){
		int d=20-a-b;
		int e=d;
		if(d>=a)e--;
		if(d>=b)e--;
		if(d>=c)e--;
		cout<<(e>3?"YES":"NO")<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

const int INF = 1 << 30;
const int MAX = 2005;


int main() {
	int N;
	int num[MAX * 2];
	bool col[MAX * 2];
	int posb[MAX];
	int posw[MAX];
	int dpb[MAX][MAX * 2] = { {0} };
	int dpw[MAX][MAX * 2] = { {0} };
	int dp[MAX][MAX];

	for (int i = 0; i < MAX; i++) {
		for (int j = 0; j < MAX; j++)dp[i][j] = INF;
	}
	dp[0][0] = 0;

	cin >> N;
	for (int i = 0; i < N * 2; i++) {
		char c;
		int n;
		cin >> c >> n;
		col[i] = c == 'B';
		num[i] = n;

		if (col[i])posb[n] = i;
		else posw[n] = i;
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N * 2; j++) {
			dpb[i][j + 1] = dpb[i][j] + (col[j] && num[j] > i);
			dpw[i][j + 1] = dpw[i][j] + (!col[j] && num[j] > i); 
		}
	}

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			if (i)dp[i][j] = min(dp[i][j], dp[i - 1][j] + dpb[i][posb[i]] + dpw[j][posb[i]]);
			if (j)dp[i][j] = min(dp[i][j], dp[i][j - 1] + dpw[j][posw[j]] + dpb[i][posw[j]]);
		}
	}


	cout << dp[N][N] << endl;

	return 0;
}


Measured memory_bytes: 78848
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int r,d,x;cin >> r >> d >> x;
    vector<int> ans(11,0);
    ans[0] = x;
    for (int i = 0; i < 10; i++) {
        ans[i+1] = ans[i]*r - d;
    }
    for (int i = 1; i < 11; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

vector<pair<ll,ll>> f(ll n){
    vector<pair<ll,ll>> p;
    for(ll i = 2;i * i<=n;++i){
        if(n%i == 0){
            ll tmp = 0;
            while(n%i == 0){
                n/=i;
                tmp++;
            }
            p.push_back(make_pair(i,tmp));
        }
    }
    if(n != 1) p.push_back(make_pair(n,1));
    return p;
}



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

    vector<vector<int>> c(3,vector<int> (3));
    rep(i,3){
        rep(j,3){
            cin >> c[i][j];
        }
    }
    vector<vector<int>> b(3,vector<int> (2));

    bool ans = false;
    rep(i,3){
        rep(j,2){
            b[i][j] = c[i][j+1] - c[i][j];
        }
    }
    rep(i,2){
        if(b[0][i] != b[1][i]){
            ans = false;
            break;   
        }else if(b[0][i] != b[2][i]){
            ans = false;
            break;
        }else if(b[1][i] != b[2][i]){
            ans = false;
            break;
        }else{
            ans = true;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int calc(vector<int>& v, vector<int>& w) {
	if (v.size() != w.size()) return INT_MAX;
	int res = 0;
	for (int i = 0; i < v.size(); i++)
		res += abs(v[i] - w[i]);
	return res;
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> v;
	for (int i = 0; i < N; i++) {
		int b; cin >> b;
		if (b) v.push_back(i);
	}
	vector<int> w1, w2;
	int i = 0; bool flag = false;
	while (M--) {
		int p; cin >> p;
		while (p--) {
			if (flag) w1.push_back(i);
			else w2.push_back(i);
			i++;
		}
		flag = !flag;
	}
	cout << min(calc(v, w1), calc(v, w2)) << endl;;
} 

Measured memory_bytes: 1216
#include <stdio.h>

int len(char data[]){
	int n=0;
	while(data[n]!='\0'){
		n++;	
	}
	return n;
}

int main(){
	char data[200]={'\0'};
	int i,n,j,c,k=0,l=0;
	scanf("%s",data);
	
	n=len(data);
	j=(n-2)/2;
	l=n;
	for(i=0;i<j;i++){
		l-=2;
		c=0;
		k=0;
		while(k<(l/2)){
			if(data[k]==data[k+l/2]){
				c+=2;
				k++;
				if(c==l){
					printf("%d\n",c);
					return 0;
				}
			}else{
				break;	
			}
		}
	}
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<pii> A(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        A[i] = {a, b};
    }

    sort(all(A), [](pii a, pii b){
        if (a.second == b.second) {
            return a.first < b.first;
        }
        return a.second < b.second;
    });

    int now = 0;
    for(int i = 0; i < N; i++) {
        now += A[i].first;
        if (now > A[i].second) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 1792
import re  # 正規表現, findall('正規表現', 文字列), search('正規表現', 文字列)
import sys # プログラム終了：sys.exit()
# sys.setrecursionlimit(10**6) # 再帰呼び出しの上限を上げる

def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))
# 文字列のまま受け取りたいときはinput()

n = i_input()
D = []

for _ in range(n):
    D.append(i_input())

D_set = set(D)

print(len(D_set))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;cin>>n;
  int v[n],c[n];
  for (int i=0;i<n;i++) cin>>v[i];
  for (int i=0;i<n;i++) cin>>c[i];
  int ans =0;
  for (int i=0;i<n;i++){
    if (v[i] >= c[i]) ans += v[i] - c[i];
  }
  cout << ans << endl; 
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

int pr[] = { 3,5,7,11,13 };

int main() {
	string s;
	ll k;
	cin >> s >> k;
	char ans = '1';
	ll unko = 0;
	REP(i, s.size()) {
		if (s[i] != '1') {
			ans = s[i];
			unko = i + 1;
			break;			
		}
	}
	if (k < unko) {
		cout << s[k - 1] << endl;
		return 0;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}
constexpr int INF = ten(9);

struct edge{int from, to, id, cost=INF;};

class EBichromization {
public:
    int N, M;
    vc<int> D, ans, col;
    vc<pii> V;
    vvc<edge> G;

    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        in>>N>>M;
        V.resize(N);
        G.resize(N);
        D.resize(N);
        col.resize(N, -1);
        ans.resize(M, INF);
        REP(i, N){
            in>>D[i];
            V[i].first = D[i];
            V[i].second = i;
        }
        REP(i, M){
            int u, v;
            in>>u>>v;
            u--, v--;
            G[u].pb({u, v, i});
            G[v].pb({v, u, i});
        }
        sort(ALL(V));
        REP(i, N){
            int u = V[i].second, w = -1, id = -1;
            if(col[u]>-1) continue;
            bool ok = false;
            for(auto& v : G[u]){
                if(col[v.to]>-1){
                    ok = true;
                    col[u] = (col[v.to]+1) % 2;
                    ans[v.id] = V[i].first;
                    break;
                }else if(D[v.to]==V[i].first){
                    w = v.to;
                    id = v.id;
                }
            }
            if(not ok){
                if(w==-1){
                    out<<"-1\n";
                    return;
                }
                col[u] = 0;
                col[w] = 1;
                ans[id] = V[i].first;
            }
        }
        for(auto& c : col){
            if(c) out<<"B";
            else out<<"W";
        }
        out<<'\n';
        for(auto& a : ans) out<<a<<'\n';
    }
};


int main() {
	EBichromization solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 16768
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static int h, w, k;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		k = sc.nextInt();
		int[][] c = new int[h][w];
		for (int i = 0; i < h; i++) {
			char[] line = sc.next().toCharArray();
			for (int j = 0; j < w; j++) {
				c[i][j] = line[j] - '0';
			}
		}
		sc.close();

		int ans = 0;
		for (int x = 0; x < h; x++) {
			for (int y = 0; y < w; y++) {
				int[][] c2 = new int[h][w];
				for (int i = 0; i < h; i++) {
					System.arraycopy(c[i], 0, c2[i], 0, w);
				}
				c2[x][y] = 0;
				drop(c2);
				int val = simulate(c2);
				ans = Math.max(ans, val);
			}
		}
		System.out.println(ans);
	}

	static int simulate(int[][] c) {
		int ret = 0;
		int rensa = 0;
		while (true) {
			boolean[][] used = new boolean[h][w];
			int val = 0;
			for (int i = 0; i < h; i++) {
				int cnt = 0;
				if (c[i][0] != 0) {
					cnt++;
				}
				for (int j = 1; j < w; j++) {
					if (c[i][j] == 0) {
						cnt = 0;
					} else {
						if (c[i][j - 1] == c[i][j]) {
							cnt++;
							if (cnt == k) {
								val += cnt * c[i][j];
								for (int j2 = j - cnt + 1; j2 <= j; j2++) {
									used[i][j2] = true;
								}
							} else if (cnt > k) {
								val += c[i][j];
								used[i][j] = true;
							}
						} else {
							cnt = 1;
						}
					}
				}
			}
			if (val == 0) {
				return ret;
			}
			ret += val * 1 << rensa;
			rensa++;
			drop(c, used);
		}
	}

	static void drop(int[][] c, boolean[][] used) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (used[i][j]) {
					c[i][j] = 0;
				}
			}
		}
		drop(c);
	}

	static void drop(int[][] c) {
		for (int j = 0; j < w; j++) {
			List<Integer> list = new ArrayList<>();
			for (int i = h - 1; i >= 0; i--) {
				if (c[i][j] != 0) {
					list.add(c[i][j]);
					c[i][j] = 0;
				}
			}
			for (int i = 0; i < list.size(); i++) {
				c[h - 1 - i][j] = list.get(i);
			}
		}
	}
}


Measured memory_bytes: 41956
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
    }
    
    //解答処理
    private String solve() {
        String answer = ":(";
        
        if (N%1.08 == 0) {
        	answer = String.valueOf(N);
        } else {
        	for (int i=(int)(N/1.08); i<=N; i++) {
        		if (Math.floor(i*1.08) == N) {
        			answer = String.valueOf(i);
        			break;
        		}
        	}
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35828
from itertools import product
import numpy as np

N, M, X = list(map(int, input().split()))
conditions = product([0, 1], repeat=N)
A = np.array([list(map(int, input().split())) for i in range(N)])
succeed = []
for c in conditions:
    p = A * np.array(c).reshape((N, 1))
    res = p.sum(axis=0)
    if np.all(res[1:] >= X):
        succeed.append(res[0])
print(min(succeed) if len(succeed) > 0 else -1)

Measured memory_bytes: 27432
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  float b = 0.000;
  cin >> N;

  float arr[N];

  for(int j = 0; j < N; j++){
    cin >> arr[j] ;

    b += 1/arr[j];
  }
  cout << 1/b << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

ll ff(ll x1, ll y1, ll x2, ll y2) {
  ll r = 0;
  ll b = 1;
  for (int i = 1; i < 33; i++) {
    if (x1 % 3 == 1 && x2 % 3 == 1 && x1 == x2) {
     // if ((y1 % 3 == 0 && y2 % 3 == 2) || (y1 % 3 == 2 && y2 % 3 == 0)) {
      if (abs(y1 - y2) > 1) {
        r = b;
      }
    }

    x1 /= 3;
    y1 /= 3;
    x2 /= 3;
    y2 /= 3;
    b *= 3;
  }

  return r;
}

ll solve(ll x1, ll y1, ll x2, ll y2) {
  ll big = ff(x1, y1, x2, y2);
  debug("big %lld\n", big);

  ll ans = abs(x2 - x1) + abs(y2 - y1);
  if (big > 0) {
    x1 %= big;
    x2 %= big;
    ans += min(min(x1, x2) * 2 + 2, min(big - x1, big - x2) * 2); 
  }
  return ans;
}

int main() {
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    ll x1, y1, x2, y2;
    scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
    x1--, y1--, x2--, y2--;
    ll r1 = solve(x1, y1, x2, y2);
    ll r2 = solve(y1, x1, y2, x2);
    printf("%lld\n", max(r1, r2));
  }
  return 0;
}


Measured memory_bytes: 384
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String[] list = new String[N];
		for(int i=0;i<N;i++) {
			list[i]=scan.next();
		}
		scan.close();
		
		Set<String> linkedHashSet = new LinkedHashSet<String>();
		
		for(int i = 0; i<list.length;i++) {
			linkedHashSet.add(list[i]);
		}
		Object[] num = linkedHashSet.toArray();
		
		System.out.println(num.length);
		
	}
}

Measured memory_bytes: 74072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b;
string c,d; 
int m,n;
int main()
{
	cin>>a>>b;
	char p=a+48,m=b+48;
	for(int i=0;i<a;i++){
		c=c+m;
	}
	for(int i=0;i<b;i++){
		d=d+p;
	}
	
	if(a==b){
		if(c>d) cout<<c;
		else cout<<d;
	}
	if(a>b) cout<<c;
	if(a<b) cout<<d;
	
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main()
{
	int n,sumv=0;
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=n;i++)
	{
		int pos=0;
		while (a[i]%2==0)
		{
			pos++;
			a[i]/=2;
		}
		sumv+=pos;
	}
	cout<<sumv<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define endl "\n"
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		a--;
		v.pb(a);
	}
	ll ans = 0;
	rep(i,0,n){
		ll a;
		cin>>a;
		ans+=a;
	}
	vector<ll> v1;
	rep(i,0,n-1){
		ll a;
		cin>>a;
		v1.pb(a);
	}
	rep(i,1,v.sz){
		if(v[i]-v[i-1]==1){
			ans += v1[v[i-1]];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main () {

    string S;
    cin >> S;

    int reds = 0, blues = 0;

    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '0') reds++;
        else blues++;
    }

    cout << min(reds, blues) * 2 << endl;

    return 0;
}

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

bool dp[110000];

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    
    for (int i = 1; i <= K; i++) {
        for (int j = 0; j < N; j++) {
            if(i-a[j]>=0){
                dp[i] |= !dp[i - a[j]];
            }
        }
    }
    
    if(dp[K]){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
}

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

int main(){
    int n, q;
    long long k;
    cin >> n >> k >> q;
    vector <int> a(q);
    for (int tsumugi = 0; tsumugi < q; tsumugi++){
        cin >> a[tsumugi];
    }

    //加点式で考え、最後に初期点以上稼いでいない人を
    //リタイアとする
    vector <int> score(n, k - q);
    for (int matsuri = 0; matsuri < q; matsuri++){
        score[a[matsuri] - 1]++;
    }

    for (int kaori = 0; kaori < n; kaori++){
        if (score[kaori] > 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll k, n;
  cin >> k >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll ans = a[n - 1] - a[0];
  rep(i, n - 1) ans = min(ans, k - a[i + 1] + a[i]);
  cout << ans << endl;
}

Measured memory_bytes: 4708
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
 */
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);
        ALucky7 solver = new ALucky7();
        solver.solve(1, in, out);
        out.close();
    }

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

            while (n > 0) {
                if (n % 10 == 7) {
                    out.println("Yes");
                    return;
                }
                n /= 10;
            }
            out.println("No");
        }

    }

    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: 32880
n=int(input())
S=[]
for i in range(n):
    S.append(input())
m=int(input())
T=[]
for i in range(m):
    T.append(input())

d={}
for s in S:
    if s in d:
        d[s]+=1
    else:
        d[s]=1
for t in T:
    if t in d:
        d[t]-=1
ans=0
for i in d.values():
    if i>=0 and i>ans:
        ans=i
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}
#define PD pair<double,double>
#define PDD pair<double,PD>


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  double w;
  cin>>n>>w;
  vector<PDD> v;
  rep(i,n){
    double a,b;
    cin>>a>>b;
    v.PB(PDD(a/b,PD(a,b)));
  }
  sort(all(v));
  reverse(all(v));
  double ans=0;
  rep(i,n){
    double s=min(w,v[i].S.S);
    ans+=v[i].F*s;
    w-=s;
  }

  cout<<ans<<endl;



}


Measured memory_bytes: 6124
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    int N;
    cin >> N;
    string S = to_string(N);
    rep(i, S.size())
    {
        if (S[i] == '9')
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,z,w = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    if n == 1:
        print(abs(w-a[0]))
    else:
        print(max(abs(w-a[-1]),abs(a[-2]-a[-1])))
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 39020
import java.util.Scanner;
public class Main{
	
	
	private static Scanner sc=new Scanner(System.in);
	private static long dp[][];
	
	public static long maxProfit(int weivalue[][],int i,int capacity){
		
		if(capacity<=0)
			return 0;
		if(i>=weivalue.length)
			return 0;
		
		if(dp[i][capacity]!=Integer.MIN_VALUE)
			return dp[i][capacity];
		
		if(capacity>=weivalue[i][0])		
			dp[i][capacity]=Math.max(maxProfit(weivalue,i+1,capacity),
									weivalue[i][1]+maxProfit(weivalue,i+1,capacity-weivalue[i][0]));
		else
			dp[i][capacity]=maxProfit(weivalue,i+1,capacity);
		
		return dp[i][capacity];
		
	}
	
	public static void main(String []args){
		
		int n=sc.nextInt();
		int w=sc.nextInt();
		int weivalue[][]=new int[n][w];
		dp=new long[n+1][w+1];
		for(int i=0;i<n;i++){
			weivalue[i][0]=sc.nextInt();
			weivalue[i][1]=sc.nextInt();
		}
		for(int i=0;i<=n;i++)
			for(int j=0;j<=w;j++)
				dp[i][j]=Integer.MIN_VALUE;
			
		
		System.out.println(maxProfit(weivalue,0,w));
		
	}
}

Measured memory_bytes: 176308
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <cassert>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

int main(){
    int n; cin >> n;
    ll ans = 0;
    rrep(i, n){
        if (i % 3 != 0 and i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}


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

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define EPS 1e-9
#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int a = 0, b = 0;
	for(char c : s) {
		if(c == 'A') ++a;
		else ++b;
	}
	if(a && b) cout << "Yes\n";
	else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
K = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))

index = [i for i in range(1, n+1)]
counter = 0

for i in range(2**n):
  cand_list = []
  flg = True
  
  for j in range(n):
    if i&1<<j:
      cand_list.append(index[j])
  
  for k_i, k in enumerate(K):
    if len(set(cand_list)&set(k))%2!=P[k_i]:
      flg = False
      break
  if flg:
    counter += 1
    
print(counter)

Measured memory_bytes: 9136
#!/usr/bin/env python3

from numba import njit

def main():
    k = int(input())
    print(getresult(k))

@njit
def getresult(k):
    res = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res

@njit("i4(i4, i4)")
def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

if __name__ == "__main__":
    main()


Measured memory_bytes: 109528
//https://caddi2018.contest.atcoder.jp/tasks/caddi2018_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main(){
    int N;
    cin>>N;
    int odd=0;
    for(int i:range(N)){
        int a;
        cin>>a;
        odd+=a%2;
    }
    if(odd)cout<<"first"<<endl;
    else cout<<"second"<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
dinp = [0]*n
edges = [[]for _ in range(n)]
for _ in range(m):
    x, y = list(map(lambda x: int(x)-1, input().split()))
    edges[x].append(y)
    dinp[y] += 1


next_v = deque([])
dist = [-1]*n
for i in range(n):
    if dinp[i] == 0:
        next_v.append(i)
        dist[i] = 0
ans = 0
while next_v:
    v = next_v.popleft()
    for v2 in edges[v]:
        dinp[v2] -= 1
        if dinp[v2] != 0:
            continue
        next_v.append(v2)
        if dist[v]+1 <= dist[v2]:
            continue
        dist[v2] = dist[v]+1
        ans = max(ans, dist[v2])
print(ans)


Measured memory_bytes: 29256
n = gets.to_i
hs = Hash.new
n.times do
  a, b = gets.chomp.split.map(&:to_i)
  hs[b] ||= []
  hs[b] << a
end

k = hs.keys.sort!
t = 0
k.each do |i|
  c = hs[i].inject(:+)
  if i - c < t
    puts "No"
    exit
  end
  t += c
end
puts "Yes"

Measured memory_bytes: 36852
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    t=list(map(int,input().split()))
    s.append(t)

fuman=[0]*26

for i in range(d):
    if i==0:
        p=c.index(max(c))
        print(p+1)
    else:
        p=fuman.index(max(fuman))
        print(p+1)
        
    for j in range(26):
        fuman[j]+=c[j]
    fuman[p]=0

Measured memory_bytes: 9400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int n, m;
	cin >> n >> m;
	priority_queue<P, V<P>, greater<P>> pq;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		pq.push(P(a, b));
	}

	int k = 0;
	ll ans = 0;
	while (k < m) {
		P p = pq.top();pq.pop();
		int cost = p.first;
		int num = p.second;
		ans += (ll)cost * min(num, -k + m);
		k += min(num, -k + m);
	}

	cout << ans << endl;
}

Measured memory_bytes: 4260
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	vector<int > v;
	cin>>a;
	for(int i=0;i<a;i++)
	{
		cin>>c;
		v.push_back(c);
		v.push_back(c-1);
		v.push_back(c+1);
	}
	sort(v.begin(),v.end());
	int asn=0,r=1;
	for(int i=1;i<v.size();i++)
	{
		if(v[i]==v[i-1])
		r++;
		else
		{
			if(r>asn)
			{
				asn=r;
				
			}r=1;
		}
	}
	cout<<asn<<endl;
}


Measured memory_bytes: 2420
N = int(input())
V_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
VC_list = sorted([v-c for v, c in zip(V_list, C_list)], reverse=True)
res = 0
for i in VC_list:
    if i > 0:
        res += i
    else:
        break
print(res)

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

int main()
{
    int a, b;
    cin >> a >> b;
    int d, r;
    double f;

    d = a / b;
    r = a % b;
    f = ((double)a) / b;
    printf("%d %d %.5lf\n", d, r, f);
}


Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int count = 0;
		for(int i = 0; i < C; i++) {
			if(A <= B) {
				B -= A;
				count++;
			} else {
				break;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e6+10;
const int N = 1e5+10;
const int E = 1e6+10; 
ll n,k;
string s;
ll f[maxn][2];

int main(){
	cin>>s;
	n = s.size();
	f[0][0] = s[0]-'0';
	f[0][1] = (10-s[0]+'0')+1;
	F(i,1,n-1){
		f[i][0] = min(f[i-1][0]+s[i]-'0',f[i-1][1]+s[i]-'0');
		f[i][1] = min(f[i-1][0]+(10-s[i]+'0')+1,f[i-1][1]+(10-s[i]+'0')-1); 
	}
	ll ans = min(f[n-1][0],f[n-1][1]);
	cout<<ans<<endl;
}

Measured memory_bytes: 17028
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FASTIO \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr);

ll dp[100001];

ll min_cost_bu(ll h[], int n, int k) {
    
    dp[0] = 0;
    // dp[1] = abs(h[1]-h[0]);
    for (int i = 1; i < n; i++) {
        ll cost = INT_MAX;
        for (int j = 1; j <= k; j++) {
            if(i-j>=0)
                cost = min(cost, abs(h[i] - h[i-j]) + dp[i-j]);
        }

        dp[i] = cost;
    }

    // for (int i = 0; i < n; i++) {
    //     cout<<dp[i]<<" ";
    // }
    return dp[n-1];
}

void solve() {
    ll n, k;
    cin>>n>>k;
    
    ll h[n];
    for (int i = 0; i < n; i++) {
        cin>>h[i];
    }

    // dp = {0};
    memset(dp, 0, sizeof(dp[0])*100001);

    cout<<min_cost_bu(h, n, k)<<"\n";
    
}

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

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

using namespace std;

#define mp make_pair
#define pb push_back
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double EPS=1e-10;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return f?-sum:sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return f?-sum:sum;}

int a[100005];

int main(){//ios_base::sync_with_stdio(0);cin.tie(0);
    int n=readint();
    for(int i=1;i<=n;i++) a[i]=readint();
    int ans=0;
    for(int i=1;i<n;i++){
        if(a[i]==i){
            swap(a[i],a[i+1]);
            ans++;
        }
    }
    if(a[n]==n) ans++;
    printf("%d\n",ans);
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 640