akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文
int main() {
	int n;
	cin >> n;
	bool ans = false;
	if (n % 10 == 9) ans = true;
	if (n / 10 == 9) ans = true;
	ansYes(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,k; cin >> n >> k;
    vector<ll> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];

    ll ans = 1e9;
    for(int i = 0; i < n-k+1; i++){
        if(ans > x[i+k-1] - x[i] + min(abs(x[i]),abs(x[i+k-1]))){
            ans = x[i+k-1] - x[i] + min(abs(x[i]),abs(x[i+k-1]));
        }
    }
    cout << ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

const ll N_MAX = 3030;
struct RAQSB{
	ll N;
	ll sN;
	ll data[N_MAX];
	ll bucket[N_MAX];

	RAQSB(ll n){
		sN = (ll)sqrt(n) + 1;
		N = sN * sN;
		REP(i, N_MAX){
			data[i] = 0;
			bucket[i] = 0;
		}
	}

	void add(ll s, ll t, ll x){
		// add x to range [s, t)
		ll ss = s/sN;
		ll tt = t/sN;
		if(ss==tt){
			for(int i=s;i<t;i++){
				data[i] += x;
				data[i] %= mod;
			}
		}else{
			for(int i=s;i<(ss+1)*sN;i++){
				data[i] += x;
				data[i] %= mod;
			}
			for(int i=tt*sN;i<t;i++){
				data[i] += x;
				data[i] %= mod;
			}
			for(int i=ss+1;i<tt;i++){
				bucket[i] += x;
				bucket[i] += mod;
			}
		}
	}

	ll get_val(ll i){
		return (data[i] + bucket[i/sN])%mod;
	}
};

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

	ll ma = 3030;
	ll DP[ma][ma];
	REP(i, ma)REP(j, ma) DP[i][j] = 0;
	REP(j, N) DP[0][j] = 1;
	REP(i, N-1){
		RAQSB raqsb(N+10);
		if(S[i]=='<'){
			REP(j, N){
				raqsb.add(0, j, DP[i][j]);
				/*
				REP(k, j){
					DP[i+1][k] += DP[i][j];
					DP[i+1][k] %= mod;
				}
				*/
			}
		}else{
			REP(j, N){
				raqsb.add(j, N-i-1, DP[i][j]);
				/*
				for(int k=j;k<=N-i-2;k++){
					DP[i+1][k] += DP[i][j];
					DP[i+1][k] %= mod;
				}
				*/
			}
		}
		REP(j, N) DP[i+1][j] = raqsb.get_val(j);
	} 
	cout << DP[N-1][0] << endl;
	/*
	REP(i, N){
		REP(j, N){
			cout << DP[i][j] << " ";
		}
		cout << endl;
	}
	*/
    return 0;
}

Measured memory_bytes: 72064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)

void recursive_debug(string) { cerr << endl; }

template<class H,class... T>
void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}

template<class T,class U>
ostream& operator<<(ostream& ost, const pair<T,U> &p) {
    ost << "(" << p.first << ", " << p.second << ")";
    return ost;
}

template<class T>
ostream& operator<<(ostream &ost, const vector<T> &v) {
    ost << "[";
    for(T t : v) ost << t << ",";
    ost << "]";
    return ost;
}

struct State {
    ll score;
    vector<int> last;
    vector<int> types;
    bool operator<(const State& rhs) const {
        return (score < rhs.score);
    }
    bool operator>(const State& rhs) const {
        return (score > rhs.score);
    }
};


int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int D, M = 26;
    cin >> D;
    vector<ll> c(M);
    rep(m,M) cin >> c[m];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(d,D) rep(m,M) cin >> s[d][m];

    set<State> cur_states = {{0, vector<int>(M, -1), {}}};
    size_t SIZE = 700;

    rep(d,D) {
        set<State> nxt_states;
        for (auto &cur_itr : cur_states) {
            State state = cur_itr;
            rep(m,M) {
                State nxt_state;
                nxt_state.score = state.score + s[d][m];
                nxt_state.last = state.last;
                nxt_state.last[m] = d;
                nxt_state.types = state.types;
                nxt_state.types.push_back(m);

                rep(i,M) {
                    nxt_state.score -= c[i] * (d - nxt_state.last[i]);
                }
                nxt_states.insert(nxt_state);
                if (nxt_states.size() > SIZE) {
                    nxt_states.erase(nxt_states.begin());
                }
            }
        }

        cur_states = std::move(nxt_states);
    }

    for (int t : cur_states.begin()->types) {
        cout << t+1 << endl;
    }
    // debug(cur_states[0].score);

    return 0;
}


Measured memory_bytes: 6468
s=input()
if s[0]==s[1] and s[2]==s[3] and s[0]!=s[2]:
    print("Yes")
elif s[0]==s[2] and s[1]==s[3] and s[0]!=s[1]:
    print("Yes")
elif s[0]==s[3] and s[1]==s[2] and s[1]!=s[0]:
    print("Yes")
else:
    print("No")


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

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

  vector<string> s(n);
  vector<int> t(n);

  for (int i = 0; i < n; ++i)
    cin >> s[i] >> t[i];

  string x;
  cin >> x;

  int ans = 0;
  bool found = false;
  for (int i = 0; i < n; ++i) {
    if (!found && s[i] == x) {
      found = true;
      continue;
    }
    if (found)
      ans += t[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
def multiple_factors(i, N):
  factors = []
  for index in range(0, N//i):
    factors.append(int((index+1)*i))
  return factors
  
def assign_ball(factors, blist, ai, b_add_index):
  sum_b = 0
  for index in range(len(factors)-1, 0, -1):
    sum_b += blist[factors[index]-1]
  
  if ai != sum_b%2:
    blist[factors[0]-1] = 1
    b_add_index.append(str(factors[0]))
  return blist, b_add_index

      
N = int(input())
alist = list(map(int, input().split()))
blist = [0 for i in range(N)]
b_add_index = []
for i in range(N-1,-1, -1):
  factors = multiple_factors(i+1, N)
  blist, b_add_index = assign_ball(factors, blist, alist[i], b_add_index)

if sum(blist)%2 != alist[0]:
  print(-1)
else:
  print(len(b_add_index))
  print(" ".join(b_add_index))

Measured memory_bytes: 26420
#include<stdio.h>
int N,A,B,i,t,C[105][2];
char S[105],s;
void mv(char *c,int m)
{
	int i;
	for(i=0;i<m;i++)
	{
		if(*c=='z')*c='a';
		else (*c)++;
	}
}
int main()
{
	for(;scanf("%d\n",&N),N;)
	{
		gets(S);
		for(i=N-1;i>=0;i--)
		{
			scanf("%d%d",&A,&B);
			A--;B--;
			C[i][0]=A;
			C[i][1]=B;
		}

		for(i=0;i<N;i++)
		{
			A=C[i][0];
			B=C[i][1];
			t=A>B?A-B:B-A;
			mv(&S[A],t);
			mv(&S[B],t);
			s=S[A];
			S[A]=S[B];
			S[B]=s;
		}
		puts(S);
	}
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    string ans="Impossible";
    if(a%3==0 || b%3==0 || (a+b)%3==0) ans="Possible";
    cout<<ans<<endl;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

long long INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int a,b,c; cin >> a >> b >> c;
	if((a==b&&a!=c)||(a==c&&a!=b)||(a!=b&&b==c))cout << "Yes" << endl;
	else cout << "No" << endl;
}	


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

arr=[list(mii()) for _ in range(n)]

chk={}

for i in arr:
    for j in arr:
        if i!=j:
            p=i[0]-j[0]
            q=i[1]-j[1]

            if str(p)+","+str(q) in chk:
                chk[str(p)+","+str(q)]+=1
            else:
                chk[str(p)+","+str(q)]=1

places="w"
num=0

for i,j in chk.items():
    if j>num:
        num=j
        places=i

print(n-num)

Measured memory_bytes: 5460
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int

const int mod = (int)1e9 + 7;
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;cin >> n;
    vector<int> in(n), pre;
    int tot;
    FOR(i, n)cin >> in[i];
    tot = 0;
    FOR(i, n)tot ^= in[i], pre.pb(tot);
    vector<int> ans(pre.size());
    unordered_map<int, int> zero;
    unordered_map<int, int> cum;
    vi prev(n), zCum(n);
    unordered_map<int, int> last;
    unordered_map<int, bool> found;
    for(int i = pre.size() - 1; i >= 0; i--){
        if(found[pre[i]]){
            prev[i] = last[pre[i]];
        }
        found[pre[i]] =true;
        last[pre[i]] = i;
    }
    int pp = 0;
    FOR(i, n)pp += (pre[i] == 0), zCum[i] = pp;
    
    FOR(i, n){
        if(prev[i])prev[i] = zCum[prev[i]] - zCum[i];
 //       cout << prev[i] << " ";
    }
  //  cout <<endl;
    
    bool first = false;
    FOR(i, pre.size()){
//        cout << pre[i] << " ";
        if(pre[i]){ // xor != 0
            ans[i] = cum[pre[i]] + 1; 
            ans[i] %= mod;
            zero[pre[i]] += ans[i];
            zero[pre[i]] %= mod;
            cum[pre[i]] += zero[pre[i]] * prev[i]; 
            cum[pre[i]] %= mod;
           //we need to consider all the beginnings behind zero
           //add 1 to make this the initial interval 
        }else{ // xor is 0
            if(!first)zero[0] = 1;
            else zero[0] *= 2;
            zero[0] %= mod;
            int j = i -1;
           /* while(j != prev){
                zero[pre[j]] += ans[j];
                zero[pre[j]] %= mod;
                j--;
            }
            for(pii x: zero){
                cum[x.first] += x.second;
                cum[x.first] %= mod;
            }*/
            first = true;
        } 
    }
  //  cout <<endl;
    if(tot)cout << ans[n-1];
    else{
        int sum = 0;
        for(pii x: zero)sum += x.second, sum %= mod;
        cout << sum;
    }
}




Measured memory_bytes: 74092
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 = new int[N];
		for (int i = 0; i < N; ++i) {
			a[i] = sc.nextInt();
		}
		
		int sum = 0;
		for (int i = 0; i < N; ++i) {
			int count = 0;
			
			while(a[i] % 2 == 0) {
				count++;
				a[i] /= 2;
			}
			
			sum += count;
		}
		
		System.out.println(sum);
	}
}

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

int main(void){
int p,q,r;
int min;
scanf("%d %d %d",&p,&q,&r);
min=mini(p+q,p+r,q+r);
printf("%d",min);
return 0;
}

int mini(a,b,c){
    if(a<=b&&a<=c){return a;}
    else if(b<=c&&b<=a){return b;}
    else {return c;}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int n,m; cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
}













Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
 
dp = [0]*N
dp[1] = abs(H[0] - H[1])
for i in range(2,N):
    dp[i] = min(dp[i-2] + abs(H[i-2]-H[i]), dp[i-1] + abs(H[i-1]-H[i]))
print(dp[-1])

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

int n;
unsigned long long cnt;

int main()
{
	int i, j, k;
	cin >> n;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
			for (k = 1; k <= n; k++)
				cnt += __gcd(i, __gcd(j, k));
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3636
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
ts=time.time()
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
show_flg=True

n,k,q=MI()
a=[]
p=[k-q]*n
for i in range(q):
    a.append(I())
    
while a:
    x=a.pop()
    p[x-1]+=1

for i in range(n):
    if p[i]>0:
        an=0
    else:
        an=1
        
    print(YN[an])


Measured memory_bytes: 50648
n = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
  if x < y: x, y = y, x
  if y == 0: return x
  return gcd(x % y, y)

L = [A[0]]
for i in range(1, n):
  L.append(gcd(L[-1], A[i]))

R = [A[-1]]
for i in range(n-2, -1, -1):
  R.append(gcd(R[-1], A[i]))
R = list(reversed(R))

ans = 1
for i in range(n):
  if i == 0: g = R[i+1]
  elif i == n-1: g = L[i-1]
  else: g = gcd(L[i-1], R[i+1])
  ans = max(ans, g)

print(ans)

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

int main(){
  int h,a,cnt=0;
  cin >> h >> a;
  if(h%a == 0){
    for(int i=0;i<h/a;i++){
      cnt++;
    }
    cout << cnt << endl;
  }else{
    for(int i=0;i<h/a+1;i++){
      cnt++;
    }
    cout << cnt << endl;
  }
}
      

Measured memory_bytes: 256
N = int(input())
a = [0]
for _ in range(N):
    a.append(int(input()))
x = 1
visited = set([1])
answer = 0

while True:
    x = a[x]
    if x in visited:
        answer = -1
        break
    visited.add(x)
    answer += 1
    if x == 2:
        break

print(answer)

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#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)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

bool solve(char c1,char c2, char c3){
  if(c1 == c2 && c2 == c3 && c1 != 's'){
    cout << c1 << endl;
    return true;
  }
  return false;
}
int a[] = {0,3,6};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(cin >> s){
    bool f = false;
    rep(i,3){
      if(solve(s[a[i]],s[a[i]+1],s[a[i]+2])){
        f = true;
        break;
      }
    }
    if(!f){
      rep(i,3){
        if(solve(s[i],s[i+3],s[i + 6])){
          f = true;
          break;
        }
      }
    }
    if(!f){
      if(!solve(s[0],s[4],s[8])){
        if(solve(s[2],s[4],s[6])){
          f = true;
        }
      }
      else f = true;
    }
    if(!f){
      cout << "d"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3084
import java.util.Scanner;


public class Main {

	private static String alpha = "abcdefghijklmnopqrstuvwxyz";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		char [] alphaArray = alpha.toCharArray();
		int alphaLen = alphaArray.length;
		int [] counter = new int[alphaLen];
		char[] inArray = in.toCharArray();
		int inSize = inArray.length;
		for (int i = 0; i < inSize;i++) {
			for (int j = 0; j < alphaLen;j++) {
				if (inArray[i] == alphaArray[j]) {
					counter[j]++;
					break;
				}
			}
		}
		boolean hit = false;
		for (int i = 0; i < alphaLen; i++) {
			if (counter[i] == 0) {
				System.out.println(alphaArray[i]);
				hit = true;
				break;
			}
		}
		if (!hit){
			System.out.println("None");
		}

	}


}

Measured memory_bytes: 27284
import java.awt.geom.Point2D;
import java.util.*;
public class Main {

	private double getS(double x1, double y1, double x2, double y2){
		double s = x1 * y2 - y1 * x2;
		s = s / 2;
		return s;
	}

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("[, \\r\\n]+");

		ArrayList<Point2D> list = new ArrayList<Point2D>();
		Point2D.Double start = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
		while(sc.hasNext()){
			double x = sc.nextDouble() - start.getX();
			double y = sc.nextDouble() - start.getY();
			list.add(new Point2D.Double(x, y));
		}
		list.add(new Point2D.Double(0, 0));
		double sum =0;
		int len = list.size();
		for(int i=0; i < len-1; i++ ){
			double result = getS(list.get(i).getX(), list.get(i).getY(), list.get(i+1).getX(), list.get(i+1).getY());
			sum += Math.abs(result);
		}
		System.out.printf("%1.6f\n",sum);
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a != b && b != c && c != a) {
			pr.println(3);
		} else if (a == b && b == c) {
			pr.println(1);
		} else {
			pr.println(2);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 9684
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    cin >> n;
    vector<long long> b;
    b.push_back(-1);
    int blen = 1;
    int kind = 0;
    int zero = 0;
    vector<long long> a(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> a.at(i);
        if(a.at(i) == 0) {
            zero++;
        }
        if(kind <= 3) {
            bool dub = false;
            for(int j = 0; j < blen; ++j) {
                if(b.at(j) == a.at(i)) {
                    dub = true;
                }
            }
            if(!dub) {
                kind++;
                b.push_back(a.at(i));
                blen++;
            }
        }
    }

    if(kind == 1) {
        if(zero == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }else if(kind == 2) {
        if(n % 3 == 0) {
            if(n / 3 == zero) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }else if(kind == 3) {
        if(n % 3 == 0) {
            int fuck = b.at(1) ^ b.at(2);
            fuck ^= b.at(3);
            if((b.at(1)^b.at(2)^b.at(3)) == 0) {
                int fst = 0;
                int snd = 0;
                int thd = 0;
                for(int i = 0; i < n; ++i) {
                    if(a.at(i) == b.at(1)) {
                        fst++;
                    }else if(a.at(i) == b.at(2)) {
                        snd++;
                    }else {
                        thd++;
                    }
                }
                if(fst == snd) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	a, b, _, k := readInt(), readInt(), readInt(), readInt()

	ans := 0
	if a <= k {
		ans += a
		k -= a
		if b <= k {
			ans -= k - b
		}
	} else {
		ans += k
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

using namespace std;

const int INF = 1001001001;

struct Edge {
	int to, cost, cost2;
	Edge(int to, int cost, int cost2 = 0) : to(to), cost(cost), cost2(cost2){}
	Edge(){}
	bool operator > (const Edge &a) const {
		return (cost > a.cost);
	}
};

int main()
{
	int n, m, c;

	while (scanf("%d %d %d", &n, &m, &c) && n){
		vector<Edge> G[128];

		for (int i = 0; i < m; i++){
			int f, t, cst;
			scanf("%d %d %d", &f, &t, &cst);
			G[f - 1].push_back(Edge(t - 1, cst));
		}

		bool vis[128][128];
		memset(vis, 0, sizeof(vis));

		priority_queue< Edge, vector<Edge>, greater<Edge> > pq;
		pq.push(Edge(0, 0));

		int ans = n;
		while (pq.size()){
			Edge e = pq.top(); pq.pop();
			if (vis[e.to][e.cost2]) continue;
			vis[e.to][e.cost2] = true;

			if (e.to == n - 1){
				ans = min(ans, e.cost2);
				continue;
			}

			for (int i = 0; i < G[e.to].size(); i++){
				Edge nxt = G[e.to][i];
				if (e.cost + nxt.cost <= c && !vis[nxt.to][e.cost2]) pq.push(Edge(nxt.to, e.cost + nxt.cost, e.cost2));
				if (e.cost2 < n && !vis[nxt.to][e.cost2 + 1]) pq.push(Edge(nxt.to, e.cost, e.cost2 + 1));
			}
		}

		printf("%d\n", ans);
	}

	return (0);
}

Measured memory_bytes: 2392
n = int(input())
A = list(map(int, input().split()))
prev = -1
count = 0
total = 0
for i in range(n):
    if prev == A[i]:
        count += 1
    else:
        total += (count + 1) // 2
        count = 0
    prev = A[i]
total += (count + 1) // 2
print(total)

Measured memory_bytes: 3064
import java.util.Scanner;


public class Main {
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int i = 1;
		while(true) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			}
			else {
				while(true) {
					if(x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					x /= 10;
					if(x == 0) {
						break;
					}
				}
			}
			
			if(++i <= n) {
				continue;
			}
			else {
				break;
			}
		}
		System.out.println();
		
		
		
	}

}

Measured memory_bytes: 24300
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    from math import sqrt, ceil
    N,K = LMIIS()
    A = LMIIS()
    suma = sum(A)
    dL = [0] * N
    dU = [0] * N
    ds = []
    for x in range(1,ceil(sqrt(suma))+1):
        
        if suma % x != 0:
            continue

        d = suma // x 
        ds.append(x)
        for i in range(N):
            dL[i] = A[i] % d
        dL.sort()
        for i in range(N):
            dU[i] = d - dL[i]

        c = 0
        l = 0
        r = N-1
        while l < r:
            #print(l,r)
            if dL[l] == dU[r]:
                c += dL[l]
                if c > K:
                    break
                l += 1
                r -= 1
                if l >= N or r < 0:
                    break
            elif dL[l] < dU[r]:
                c += dL[l]
                if c > K:
                    break
                dU[r] -= dL[l]
                l += 1
                if l >= N:
                    break
            else:
                c += dU[r]
                if c > K:
                    break
                dL[l] -= dU[r]
                r -= 1
                if r < 0:
                    break
            
            
        if l >= r:
            print(d)
            return

    for i  in range(len(ds)-1,-1,-1):
        d = ds[i]
        for i in range(N):
            dL[i] = A[i] % d
        dL.sort()
        for i in range(N):
            dU[i] = d - dL[i]

        c = 0
        l = 0
        r = N-1
        while l < r:
            #print(l,r)
            if dL[l] == dU[r]:
                c += dL[l]
                if c > K:
                    break
                l += 1
                r -= 1
                if l >= N or r < 0:
                    break
            elif dL[l] < dU[r]:
                c += dL[l]
                if c > K:
                    break
                dU[r] -= dL[l]
                l += 1
                if l >= N:
                    break
            else:
                c += dU[r]
                if c > K:
                    break
                dL[l] -= dU[r]
                r -= 1
                if r < 0:
                    break
            
            
        if l >= r:
            print(d)
            return


if __name__ == '__main__':
    main()

Measured memory_bytes: 42480
use std::io::*;

struct Dice;

impl Dice {
  fn right_of(top: usize, front: usize) -> usize {
    let (a, b) = (top > 2, front > 2);

    let t = if a { 5 - top } else { top };
    let f = if b { 5 - front } else { front };

    let right = match (t, f) {
      (0, 1) => 2,
      (1, 2) => 0,
      (2, 0) => 1,
      (1, 0) => 3,
      (2, 1) => 5,
      (0, 2) => 4,
      _ => unreachable!()
    };

    if a ^ b { 5 - right } else { right }
  }
}

fn main() {
  let stdin = stdin();
  let mut lines = stdin.lock().lines();

  let line = lines.next().unwrap().unwrap();
  let labels = line.split_whitespace().collect::<Vec<_>>();
  let q = lines.next().unwrap().unwrap().parse::<usize>().unwrap();

  for _ in 0..q {
    let line = lines.next().unwrap().unwrap();
    let mut args = line.split_whitespace();

    let top = args.next().unwrap();
    let front = args.next().unwrap();

    let top = labels.iter().position(|&x| x == top).unwrap();
    let front = labels.iter().position(|&x| x == front).unwrap();

    let right = Dice::right_of(top, front);

    println!("{}", labels[right]);
  }
}



Measured memory_bytes: 5028
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int,int> > S2;
  char ch;
  int sum=0;
  for (int i=0; cin>>ch; i++) {
    if (ch=='\\') {
      S1.push(i);
    } else if (ch=='/' && !S1.empty()) {
      int j=S1.top();
      S1.pop();
      sum+=i-j;
      int a=i-j;
      while (!S2.empty() && S2.top().first>j) {
        a+=S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }
  vector<int> ans;
  while (!S2.empty()) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(),ans.end());
  cout<<sum<<endl;
  cout<<ans.size()<<flush;
  for (int i=0; i<ans.size(); i++) {
    cout<<" "<<ans[i]<<flush;
  }
  cout<<endl;
  return 0;
}



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

int main(){
	string a;
	while(cin>>a){
		if(a[0]=='#')break;
		int b,c,d;
		cin>>b>>c>>d;
		if(b<31)cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		else if(b==31 &&  c<5)cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		else{
		b-=30;
		a = "?";
		cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		}

	}
	return 0;
}



Measured memory_bytes: 3152
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let r = get_line().parse::<f64>().unwrap();

    println!("{}", 2. * r * std::f64::consts::PI);
}


Measured memory_bytes: 2188
#include<bits/stdc++.h>
using namespace std;
const int nn=3e5,mm=1e5+1;
int n,m,dep,c[mm];
struct sou{int l,r,di;}ran[nn];
bool cmp(sou a,sou b){return a.di<b.di;}
int lowbit(int p){return p&(-p);}
int prefix(int i){
	int p=0;
	for(;i;i-=lowbit(i))p+=c[i];
	return p;
}void add(int i,int v){for(;i<=m;i+=lowbit(i))c[i]+=v;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d%d",&ran[i].l,&ran[i].r);
		ran[i].di=ran[i].r-ran[i].l;
	}sort(ran,ran+n,cmp);
	for(int i=1,ans;i<=m;i++){
		for(;dep<n&&ran[dep].di<i;dep++)add(ran[dep].l,1),add(ran[dep].r+1,-1);
		ans=n-dep;
		for(int j=i;j<=m;j+=i)ans+=prefix(j);
		printf("%d\n",ans);
	}return 0;
}

Measured memory_bytes: 7628
#include <set>
#include <iostream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int main(){
  string str; cin >> str;
  int n = str.size();
  int ans = 0;

  char m[256];
  m['i'] = 'i';
  m['w'] = 'w';
  m['('] = ')';
  m[')'] = '(';

  REP(i,n/2 + n % 2){
    char c1 = str[i];
    char c2 = str[n-i-1];

    if(m[c1] != c2) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 0
/*
g++ -std=c++11 -o2 -Wall ABC105C.cpp -o ./out/ABC105C.out
./out/ABC105C.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll a[66000];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  if (n == 0) {
    cout << n << "\n";
    return 0;
  }
  for (ll i = 0; i < (1 << 16); ++i) {
    ll temp = 0;
    ll x = 1;
    for (int j = 0; j < 16; ++j) {
      if ((i >> j) & 1) temp += x;
      x *= 4;
    }
    a[i] = temp;
  }
  for (ll i = 0; i < (1 << 16); ++i) {
    ll temp = n;
    ll x = 2;
    for (int j = 0; j < 16; ++j) {
      if ((i >> j) & 1) temp += x;
      x *= 4;
    }
    int idx = lower_bound(a, a+66000, temp) - begin(a);
    if (idx < 66000 && a[idx] == temp) {
      bool flag = false;
      for (int k = 31; k >= 0; --k) {
        if (k%2==0) {
          int t = (idx >> (k/2))&1;
          if (t) {
            flag = true;
            cout << "1";
          } else if (flag) cout << "0";
        } else {
          int t = (i >> (k/2))&1;
          if (t) {
            flag = true;
            cout << "1";
          } else if (flag) cout << "0";
        }
      }
      cout << "\n";
      return 0;
    }
  }
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
typedef long long ll;

const int N=5005,P=998244353;
int n,k,C[N][N];

inline int Cs(int n,int m){return n<0||m<0||n<m?0:C[n][m];}

int main()
{
	scanf("%d%d",&k,&n);
	for(int i=C[0][0]=1;i<=5001;++i)
		for(int j=C[i][0]=1;j<=i;++j)
			if((C[i][j]=C[i-1][j]+C[i-1][j-1])>=P)
				C[i][j]-=P;
	for(int i=2,j,u,v,s;i<=k<<1;printf("%d\n",s),++i)
		for(u=std::min(k,i>>1),v=std::max(1,i-k),s=j=0;j<=u-v+1;++j)
			s=(s+(ll)Cs(u-v+1,j)*Cs(n+k-j-j-1,n-j-j)%P*(j&1?P-1:1))%P;
	return 0;
}


Measured memory_bytes: 96512
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=300+3;
const int p=1e9+7;

int dp[N][N][N];
int n,m,l,r,x,res;
vector<pii> V[N];

void Upd(int n,int x,int y,int val){
	for (pii A:V[n]){
		if (1+(A.fi<=x)+(A.fi<=y)!=A.se) return;
	}
	dp[n][x][y]=(dp[n][x][y]+val)%p;
}

int main(){
	n=IN(),m=IN();
	For(i,1,m+1){
		l=IN(),r=IN(),x=IN();
		V[r].pb(mp(l,x));
	}
	dp[0][0][0]=1;
	For(i,0,n) For(j,0,i+1) For(k,0,j+1)
		if (dp[i][j][k]){
			Upd(i+1,j,k,dp[i][j][k]);
			if (i) Upd(i+1,i,k,dp[i][j][k]);
			if (j) Upd(i+1,i,j,dp[i][j][k]);
		}
	For(i,0,n+1) For(j,0,i+1)
		if (dp[n][i][j]){
			int tmp=1+(i!=0)+(j!=0),coef;
			coef=(tmp==1?3:6);
			res=(res+1ll*coef*dp[n][i][j])%p;
		}
	printf("%d\n",res);
}

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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        long M;
        M = sc.nextLong();
        long[] a = new long[(int)(A)];
        for(int i = 0 ; i < A ; i++){
                a[i] = sc.nextLong();
        }
        long[] b = new long[(int)(B)];
        for(int i = 0 ; i < B ; i++){
                b[i] = sc.nextLong();
        }
        long[] x = new long[(int)(M)];
        long[] y = new long[(int)(M)];
        long[] c = new long[(int)(M)];
        for(int i = 0 ; i < M ; i++){
                x[i] = sc.nextLong();
                y[i] = sc.nextLong();
                c[i] = sc.nextLong();
        }

        final Solver solver = new Solver();
        solver.solve(A, B, M, a, b, x, y, c);
    }
}

class Solver {
    public void solve(long A, long B, long M, long[] a, long[] b, long[] x, long[] y, long[] c) {
        int minA = Integer.MAX_VALUE;
        for (int i = 0; i < A; i++) {
            minA = (int) Math.min(minA, a[i]);
        }

        int minB = Integer.MAX_VALUE;
        for (int i = 0; i < B; i++) {
            minB = (int) Math.min(minB, b[i]);
        }

        int minTotal = minA + minB;
        for (int i = 0; i < M; i++) {
            minTotal = (int) Math.min(minTotal, (a[(int) (x[i] - 1)] + b[(int) (y[i] - 1)]) - c[i]);
        }
        System.out.println(minTotal);
    }
}



Measured memory_bytes: 138136
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

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

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

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

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

const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const long double PI = 3.14159265358979323846;







// ****************************************CODE***************************************//




int x[11][11];



int main(){
    _upgrade;

    vector<int> check(1100);
    for(int i = 1; i <= 1000; i++){
        check[i] = i*i;
    }


    int n,d;
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }

    int ans = 0;

    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            int cnt = 0;
            for(int k = 0; k < d; k++){
                int tmp = x[i][k] - x[j][k];
                cnt += tmp * tmp;
            }
            for(int k = 0; k <= 1000; k++){
                if(cnt == check[k]){
                    ans++;
                }
            }
        }
    }


    cout << ans << endl;

















}











Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000;
int A[MAX];
int B[MAX];
int main()
{
	string str;
	cin >> str;
	string aws = "Yes";
	sort(str.begin(),str.end());
	char flag = str[0];
	int c = 1;
	for (int i = 1; i < str.size(); i++)
	{
		if (str[i] == flag)
			c++;
		else
		{
			if (c % 2 != 0)
				aws = "No";
			c = 1;
			flag= str[i];
		}
	}
	if (c % 2 != 0)
		aws = "No";
	cout << aws << endl;
 	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 50

int main(){

    int N,C[MAX],V[MAX];
    int i,sum;

    scanf("%d",&N);

    for(i=0;i<N;i++){
        scanf("%d",&C[i]);
    }

    for(i=0;i<N;i++){
        scanf("%d",&V[i]);
    }

    for(i=0;i<N;i++){
        if((C[i]-V[i])>0){
            sum=sum+C[i]-V[i];
        }
    }

    printf("%d\n",sum);

}

Measured memory_bytes: 128
my $s = <STDIN>;
my @s = split(/ /,$s);
 
@soinsu1;
@soinsu2;
 
$a = $s[0];
for($i=2;$i<10000;$i++){
  if(($a % $i) == 0 ){
    $a = $a / $i ;
    $soinsu1[$i] = $soinsu1[$i] + 1;
    $i--; 
  }
}
 
$b = $s[1];
for($i=2;$i<10000;$i++){
  if(($b % $i) == 0 ){
    $b = $b / $i ;
    $soinsu2[$i] = $soinsu2[$i] + 1;
    $i--; 
  }
}
#print "ab $a $b\n";
$ans = $a * $b ;
for($i=2;$i<10000;$i++){
   if($soinsu1[$i] < $soinsu2[$i]){
      $soinsu1[$i] = $soinsu2[$i];
   }
   if($soinsu1[$i] == 0){next;};
   $ans = $ans * ( $i ** $soinsu1[$i] );
}
print "$ans";

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

int d[100][100]; //d[u][v]は辺e=(u,v)のコスト（存在しない場合はINF、ただしd[i][i]=0とする）
int V = 10; //頂点数

void warshall_floyd() {
	for(int k = 0;k < V;k++) {
		for(int i = 0;i < V;i++) {
			for(int j = 0;j < V;j++) {
				d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
			}
		}
	}
}

signed main() {
	int H,W;
	cin >> H >> W;
	for(int i = 0;i < 10;i++) {
		for(int j = 0;j < 10;j++) {
			int A;
			cin >> A;
            d[i][j] = A;
		}
	}
	warshall_floyd();
	int ret = 0;
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			int A;
			cin >> A;
			if(A != -1) {
				ret += d[A][1];
			}
		}
	}
	cout << ret << endl;
}

Measured memory_bytes: 256
/*
      author : nishi5451
      created: 12.08.2020 17:34:59
*/

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


int main(){
    int w,h,n;
    cin >> w >> h >> n;
    vector<vector<bool>> b(h+1,vector<bool>(w+1,true));
    rep(i,n){
        int x,y,a;
        cin >> x >> y >> a;
        if(a==1)
            for(int j=1; j<=h; j++)
                for(int k=1; k<=x; k++)
                    b[j][k] = false;
        else if(a==2)
            for(int j=1; j<=h; j++)
                for(int k=x+1; k<=w; k++)
                    b[j][k] = false;
        else if(a==3)
            for(int j=1; j<=y; j++)
                for(int k=1; k<=w; k++)
                    b[j][k] = false;
        else if(a==4)
            for(int j=y+1; j<=h; j++)
                for(int k=1; k<=w; k++)
                    b[j][k] = false;
    }
    int ans = 0;
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
            if(b[i][j]==true) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int answer=0;
  for(int i=0;i<3;i++){
    if(s.at(i)==t.at(i)){
      answer++;
    }
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n,a,min = 1000000,max=-1000000;
    long sum = 0;
    cin >>n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a < min)min = a;
        if (a > max)max = a;
        sum += a;
    }
        cout << min << " " <<max <<" "<< sum << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const long long MOD = 1e9;

int main() {
  vector<int> num(10, 0);
  for (int i = 0; i < 4; ++i) {
    int a;
    cin >> a;
    num[a]++;
  }
  if (num[1] == 1 && num[9] == 1 && num[7] == 1 && num[4] == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date: 7th May 2020
'''

n,k=map(int,input().split())
a=list(map(int,input().split()))
a=[0]+a
vis=[-1]*(n+5)


turn=k
now=1
c=0
while vis[now]==-1:

    if turn<=0:
        print(now)
        exit()
    vis[now]=c
    c+=1
    now=a[now]
    turn=turn-1

diff =c-vis[now]

lo=1
hi=10**25
cost=vis[now]
while lo<=hi:

    mid=(lo+hi)//2
    t=mid*diff
    if t+cost<=k:
       lo=mid+1
    else:
        hi=mid-1

t=hi*diff+cost


rem=k-t

while rem>0:
    now=a[now]
    rem-=1

print(now)

Measured memory_bytes: 31020