akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
const ll LINF = 1e18;

int main(){
  int N; cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 高さが全部 0 になるまでやる
    int res = 0;
    while (true) {
        // 最高高さが 0 だったらおしまい
        if (*max_element(h.begin(), h.end()) == 0) break;
        
        // 区間分割する
        int i = 0;
        while (i < N) {
            if (h[i] == 0) ++i; // 0 なら何もせずに次に進む
            else {
                ++res; // 区間の始まり
                while (i < N && h[i] > 0) {
                    --h[i]; // ついでに引いとく
                    ++i; // 区間の終わりまで一気に
                }
            }
        }
    }
    cout << res << endl;
}

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

#define INF 2000000001

int main() {
  int n; cin >> n;
  // ???i/2??????2??i???2??i+1
  vector<int> heaps(n+1);
  for(int i=1;i<n+1;i++) {
    cin >> heaps[i];
  }
  for(int i=1;i<n+1;i++) {
    // node i: key = k, parent key = pk, left key = lk, right key = rk,
    // pk = ???i/2???, lk = 2??i, rk = 2??i+1
    int k = heaps[i];
    int pk = INF;
    if(i != 1) pk = heaps[i / 2];
    int lk = INF;
    if(2*i <= n) lk = heaps[2 * i];
    int rk = INF;
    if(2*i+1 <= n) rk = heaps[2 * i + 1];

    cout << "node " << i << ": key = " << k << ", ";
    if(pk != INF) cout << "parent key = " << pk << ", ";
    if(lk != INF) cout << "left key = " << lk << ", ";
    if(rk != INF) cout << "right key = " << rk << ", ";
    cout << endl;
  }
}

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

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

    vector<int> ans(n);
    vector<bool> visited(n, false);
    bool flag = true;
    bool zero = false;
    for(int i=0; i<m; i++){
        int s, c;
        cin >> s >> c;

        s -= 1;
        if(visited[s] == false) ans[s] = c;
        if(visited[s] == true && ans[s] != c) flag = false;
        if(s == 0 && c == 0) zero = true;

        visited[s] = true;
    }

    if(flag == false){
        cout << -1 << endl;
        return 0;
    }

    if(zero == true){
        if(n == 1) cout << 0 << endl;
        if(n != 1) cout << -1 << endl;
        return 0;
    }

    if(n == 1 && m == 0){
        cout << 0 << endl;
        return 0;
    }
    if(ans[0] == 0) ans[0] = 1;
    for(int i=0; i<n; i++){
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations
I=lambda:list(map(int,input().split()))
n,m,x=I()
rec=[]
for i in range(n):
  rec.append(I())
best=10**9
for i in range(1,n+1):
  l=list(combinations(rec,i))
  #print(l)
  for j in range(len(l)):
    loc_best=0
    algos=[0 for _ in range(m+1)]
    for k in range(len(l[j])):
      loc_best+=l[j][k][0]
      for p in range(1,m+1):
        algos[p]+=l[j][k][p]
    #print(loc_best,algos)
    st=False
    for p in range(1,m+1):
      if(algos[p]<x):
        st=True
        break
    if(st==False):
      best=min(loc_best,best)
if(best==10**9):
  print(-1)
else:
  print(best)
        
                   


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

#define INF 1<<60

typedef pair<long long int, long long int> PII;
typedef vector<PII> VPII;

int main() {
	long long int N;
	while( cin >> N, N ) {
		map<long long int, VPII> M;
		priority_queue<PII, VPII, greater<PII>>que;
		que.push( make_pair( 0, 1LL << INF ) );
		for( size_t i = 0; i < N; i++ ) {
			char c;
			cin >> c;
			if( c == 'W' ) {
				int a, b;
				cin >> a >> b;
				while( b ) {
					PII now = que.top(); que.pop();
					if( b < now.second - now.first ) {
						que.push( make_pair( now.first + b, now.second ) );
						M[a].push_back( make_pair( now.first, now.first + b - 1 ) );
						b = 0;
					} else if( b == now.second - now.first ) {
						M[a].push_back( make_pair( now.first, now.second ) );
						b = 0;
					} else {
						M[a].push_back( make_pair( now.first, now.second ) );
						b -= now.second - now.first + 1;
					}
				}
			} else if( c == 'D' ) {
				int a;
				cin >> a;
				for( auto x : M[a] ) {
					que.push( x );
				}
				M[a].clear();
			} else {
				int a;
				cin >> a;
				bool f = 0;
				for( auto x : M ) {
					for( auto y : x.second ) {
						if( y.first <= a &&a <= y.second ) {
							cout << x.first << endl;
							f = 1;
							break;
						}
					}
					if( f ) {
						break;
					}
				}
				if( !f ) {
					cout << -1 << endl;
				}
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 41640
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        String S = sc.next();

        if(S.charAt(2)==S.charAt(3) && S.charAt(4)==S.charAt(5)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24276
N=int(input())
V=[]
C=[]
dif=[]
sum=0
V=list(input().split())
C=list(input().split())
for i in range(N):
    dif.append(int(V[i])-int(C[i]))
for i in range(N):
    if dif[i]>=0:
        sum+=dif[i]
print(sum)


Measured memory_bytes: 3060
let a,b,c,d = Scanf.scanf "%d %d %d %d\n" @@ fun a b c d -> a, b, c, d
let rec f a b c d t =
  if a <= 0 then false else if c <= 0 then true
  else if t then f a b (c-b) d false else f (a-d) b c d true
let ans = if (f a b c d true) then "Yes" else "No"
let () = print_endline ans

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define pb push_back
using ll = long long;
using ld = long double;
constexpr ll mod = 1000000007LL;

ll comb[1010][1010];
ll factinv[1010];

void comb_init() {
	for(ll i = 1; i < 1010; i++) {
	for(ll j = 0; j < 1010; j++) {
		if(j > i) {
			comb[i][j] = 0;
			continue;
		}
		if(j == 0 || j == i) {
			comb[i][j] = 1;
			continue;
		}
		comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;
	}}
	return;
}

ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	if(n % 2) {
		return (a * mod_pow((a * a) % mod, n / 2)) % mod;
	} else {
		return mod_pow((a * a) % mod, n / 2) % mod;
	}
}

void factinv_init() {
	ll buf = 1;
	for(ll i = 1; i < 1010; i++) {
		buf *= i;
		buf %= mod;
		factinv[i] = mod_pow(buf, mod - 2);
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	comb_init();
	factinv_init();
	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	vector<ll> cnt(n + 1, 0);
	cnt[0] = 1;
	for(ll i = a; i <= b; i++) {
		vector<ll> ncnt(n + 1, 0);
		for(ll j = 0; j <= n; j++) {
			ncnt[j] += cnt[j];
			ncnt[j] %= mod;
			ll buf = 1;
			for(ll k = 1; k <= d; k++) {
				if(i * k > n - j) break;
				buf *= comb[n - (j + (k - 1) * i)][i];
				buf %= mod;
				if(k < c) continue;
				ncnt[j + i * k] += (((buf * cnt[j]) % mod) * factinv[k]) % mod;
				ncnt[j + i * k] %= mod;
			}
		}
		cnt = ncnt;
	}
	cout << cnt[n] << endl;
	return 0;
}

Measured memory_bytes: 8192
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










template <typename T>
class LazySegmentTree {
private:
    int n;      // 配列の要素数
    T init;     // 遅延伝搬用の配列の初期の値
    vector<T> node, lazy;   // セグメントツリーを持つ配列
    
    // 二項演算
    T f(T a, T b){
        // return min(a, b); // RMQ;
        return a + b; // RSQ;
    };
    
    // 区間に対しての操作
    void g(T &a, T b, ll r = 1){
        // a = b; // range update
        a += b * r; // range add
    }
    
    // 子ノードへ伝搬するときの演算
    void h(T &a, T b){
        // a = b; // range update
        a += b / 2; // range add
    }
    
    void eval(int k, int l, int r){
        if(lazy[k] != init){            
            g(node[k], lazy[k]);
            
            if(r - l > 1){
                h(lazy[k * 2 + 1], lazy[k]);
                h(lazy[k * 2 + 2], lazy[k]);
            }
            
            lazy[k] = init;
        }
    }
    
public:
    LazySegmentTree(vector<T> v, T init = 0) : n(1), init(init) {
        int sz = v.size();
        while(n < sz) n *= 2;
        node.resize(2 * n - 1);
        lazy.assign(2 * n - 1, init);
        
        for(int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--) node[i] = f(node[i * 2 + 1], node[i * 2 + 2]);
    }
    
    LazySegmentTree(ll n, T init = 0) : LazySegmentTree(vector<T>(n, init), init) {}
    
    // [a, b) を x で更新
    void update(int a, int b, T x, int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        
        eval(k, l, r);
        
        if(b <= l || r <= a) return;
        
        if(a <= l && r <= b){
            g(lazy[k], x, (r - l));
            eval(k, l, r);
        }
        else{
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = f(node[2 * k + 1], node[2 * k + 2]);
        }
    }
    
    // [a, b) の値を求める
    T query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        
        eval(k, l, r);
        
        if(b <= l || r <= a) return init;
        if(a <= l && r <= b) return node[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
};



int main(){
    ll n, q;
    cin >> n >> q;
    LazySegmentTree<ll> tree(n, 0);
    REP(i, q){
        ll query;
        cin >> query;
        if(query == 0){
            ll s, t, x;
            cin >> s >> t >> x;
            tree.update(s - 1, t, x);
        }
        else{
            ll s, t;
            cin >> s >> t;
            cout << tree.query(s - 1, t) << endl;
        }
    }
}


Measured memory_bytes: 7564
# coding: utf-8
# Your code here!
n=int(input())
ans=0

for i in range(n,n+1000):
    
    a=str(i)
    flag=1

    for j in range(len(a)):
        if(a[0]!=a[j]):
            flag=0
    if(flag==1):
        ans=a
        break
        
print(ans)

Measured memory_bytes: 3060
from collections import Counter
N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
data = [K-Q]*N
C = Counter(A)
for i,j in C.items():
  data[i-1] += j
for i in range(N):
  if data[i] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 13816
#include<stdio.h>	
int a[300000],b[300000];
int main()
{
	int i,f,a1,b1,n,k;
	f=0;
	scanf("%d%d",&k,&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&a1,&b1);
		if(a1==1)
			a[b1]=1;
		if(b1==k)
			b[a1]=1;

	}
	for(i=1;i<=n;i++)
		if(a[i]&&b[i])
			f=1;
	if(f==1) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 1792
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: i64 = 1 << 60;
const MAX: usize = 255;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    loop {
        let N: usize = sc.get();
        let M: usize = sc.get();
        let C: Vec<i64> = sc.vec(M);
        let x: Vec<i64> = sc.vec(N);
        if N == 0 && M == 0 {
            break;
        }
        let mut dp = vec![vec![INF; MAX+1]; N+1];
        dp[0][128] = 0;
        for i in 0..N {
            for y in 0..MAX+1 {
                for j in 0..M {
                    let mut ny = y as i64 + C[j] as i64;
                    ny = max(0, min(255, ny));
                    dp[i+1][ny as usize] = min(dp[i+1][ny as usize], dp[i][y] + (x[i] - ny) * (x[i] - ny));
                }
            }
        }
        let mut ans = INF;
        for y in 0..MAX+1 {
            ans = min(ans, dp[N][y]);
        }
        println!("{}", ans);
    }
}



Measured memory_bytes: 45992
s_ary = gets.chomp.split("")
odd = s_ary.select.with_index { |_, i| i.even? }
even = s_ary.select.with_index { |_, i| i.odd? }

collect_odd_include_ary = ['R', 'U', 'D']
collect_even_include_ary = ['L', 'U', 'D']

is_odd = odd.all? { |s| collect_odd_include_ary.include?(s) }
is_even = even.all? { |s| collect_even_include_ary.include?(s) }

puts (is_odd && is_even) ? 'Yes' : 'No'

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
int k[2020],f[2000005],a[2000005],g[2000005];
int main()
{
	string s;
	cin>>s;
	int n=s.size(),i;
	for(i=0; i<n; i++)
		a[i+1]=s[i]-'0';
	int l=1;
	for(i=n; i>=1; i--)
	{
		g[i]=l;
		l*=10;
		l%=2019;
	}
	for(i=n; i>=1; i--)
	{
		f[i]=(f[i+1]+a[i]*g[i])%2019;
		k[f[i]]++;
	}
	int sum=k[0];
	for(i=0; i<=2018; i++)
		sum+=(k[i]*(k[i]-1)/2);
	cout<<sum;
	return 0;
}

Measured memory_bytes: 6096
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String x="";
		String y="";
		
		for(int i=0; i<n;i++){
			x = x + "" + m;
			}
		for(int o=0; o<m;o++){
			y = y + "" + n;
			}
		if(x.compareTo(y) < 0){
			System.out.println(x);
			}else if(y.compareTo(x) < 0){
				System.out.println(y);
			}else if(y.compareTo(x) == 0){
				System.out.println(y);
			}
		
		
	}
}

Measured memory_bytes: 23764
#include <iostream>
using namespace std;
int n,m,p;
int X[105];
int main() {
    while(cin >> n >> m >> p, !(n==0 && m==0 && p==0)){
        for(int i=0; i<n; i++){
            int x;
            cin >> x;
            X[i] = x;
        }
        int sum=0;
        for(int i=0; i<n; i++){
            sum += X[i];
        }
        int ans;
        if(X[m-1] == 0) ans=0;
        else ans = sum*(100-p)/X[m-1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
S = ["?"] + list(input())[: -1]
e = dd(set)
a = [0] * (N + 1)
b = [0] * (N + 1)
for _ in range(M):
  u, v = map(int, input().split())
  e[u].add(v)
  e[v].add(u)

s = []
for x in range(1, N + 1):
  for y in e[x]:
    if S[y] == "A": a[x] += 1
    if S[y] == "B": b[x] += 1
  if a[x] == 0 or (b[x] == 0): s.append(x)

vis = [0] * (N + 1)
while len(s):
  x = s.pop()
  if vis[x]: continue
  vis[x] = 1
  for y in e[x]:
    if x == y: continue
    if S[x] == "A": a[y] -= 1
    if S[x] == "B": b[y] -= 1
    if a[y] == 0 or (b[y] == 0): s.append(y)
 
if sum(vis) < N: print("Yes")
else: print("No")

Measured memory_bytes: 119636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
#define int long long
using namespace std;
int kai(int n) {
  int a = 1;
  for (int i = 2; i <= n; i++)
    a = a * i % 1000000007;
  return a;
}
signed main() {
  int N, M;
  cin >> N >> M;
  if (abs(N - M) >= 2)
    cout << 0 << endl;
  else if (abs(N - M) == 1)
    cout << kai(N) * kai(M) % 1000000007 << endl;
  else
    cout << kai(N) * kai(M) % 1000000007 * 2 % 1000000007 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k,sum;
  cin >> n >> k;
  for (int i = 0; i < n; i++){
    int x;
    cin >> x;
    if ((k - x) < x){
      sum += (k - x);
    }
    else{
      sum += x;
    }
  }
  cout << sum * 2 << endl;
}

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

#define ll  long long


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0;i<3;i++){
        if(s[i]-'A'==0){
            ++a;
        }else if(s[i]-'B'==0){
            ++b;
        }
    }

    if(a==0||b==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
        
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int S[10000],T[500];
  int i,j,n,q,s,count=0;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j = 0 ; j < q ; j++){
    scanf("%d",&T[j]);
  }
  
  for(j = 0 ; j < q ; j++){
    for(i = 0 ; i < n ; i++){
      if(S[i] == T[j]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	m, _ := strconv.Atoi(stringLineScan())
	a := map[int]int{}
	for i := 0; i < n; i++ {
		t, _ := strconv.Atoi(stringLineScan())
		a[t] += 1
	}
	bc := make([][]int, m)
	for i := 0; i < m; i++ {
		d := make([]int, 2)
		d[0], _ = strconv.Atoi(stringLineScan())
		d[1], _ = strconv.Atoi(stringLineScan())
		bc[i] = d
		if _, ok := a[d[1]]; ok == false {
			a[d[1]] = 0
		}
	}
	l := make([]int, len(a))
	t := 0
	for i, _ := range a {
		l[t] = i
		t++
	}
	sort.Ints(l)
	t = 0
	for _, d := range bc {
		b, c := d[0], d[1]
		for j := t; j < len(l); j++ {
			if c <= l[j] {
				break
			} else if b == a[l[j]] {
				a[l[j]] = 0
				a[c] += b
				t++
				break
			} else if b < a[l[j]] {
				a[l[j]] -= b
				a[c] += b
				break
			} else if b > a[l[j]] {
				a[c] += a[l[j]]
				b -= a[l[j]]
				a[l[j]] = 0
				t++
			}
		}
	}
	ans := 0
	for k, v := range a {
		ans += k * v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a+b+c-max({a,b,c})<<endl;
}

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

swap_bin = {'0':'1', '1':'0'}

M = N
for i in range(20):
  M += 2**(2*i+1)
  
binary = str(bin(M)[2:])
#print(binary)

solver = []
for i in range(1,len(binary)+1):
  if i % 2 == 0:
    solver.append(swap_bin[binary[-i]])
  else:
    solver.append(binary[-i])
    
solver = solver[::-1]
ans = ''.join(solver)
print(int(ans))

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

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

    int n;
    cin >> n;
    vector<int> as(n), ans(n);
    for (int i = 0; i < n; i++) cin >> as[i];
    long long sum = 0;
    long long hoge = 0;
    for (int i = 0; i < n; i++) {
        sum += as[i];
        if (i % 2 == 0 && i != n - 1) hoge += as[i];
    }
    sum /= 2;
    ans.back() = sum - hoge;
    for (int i = -1; i < n - 1; i++) {
        int idx = i;
        if (idx < 0) idx += n;
        int A = as[idx] - ans[idx];
        ans[i + 1] = A;
    }
    for (int i = 0; i < n; i++) {
        cout << 2 * ans[i] << ' ';
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n,m,x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll> > a(n,vector<ll>(m));
    rep0(i, n){
        cin >> c[i];
        rep0(j, m)cin >> a[i][j];
    }
    
    ll ans = INF;
    rep0(i, (1 << n)){
        vector<ll> cnt(n,0);
        ll s = 0;
        rep0(j, n){
            if(i & (1 << j)){
                rep0(k, m)cnt[k] += a[j][k];
                s += c[j];
            }
        }
        bool f = true;
        rep0(i, m)if(cnt[i] < x)f = false;
        if(f)ans = min(ans,s);
    }
    pf(ans == INF? -1:ans);
    return 0;
}


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

int main(){
    int N; cin >> N;
    int ans = 0;
    int count = 0;
    int prev; cin >> prev;

    for (int i = 1; i < N; i++)
    {
        int H; cin >> H;
        if(H<=prev){
            count++;
            ans = max(ans, count);
        } else {
            count = 0;
        }
        prev=H;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,answer=1,dp[100020];
  cin>>N;
  vector<ll> vec(N+1);
  vector<ll> sum(N+1);
  for(ll i=0;i<=N;i++){cin>>vec.at(i);}
  dp[0]=1;
  sum.at(N)=vec.at(N);
  for(ll i=N-1;i>=0;i--){
    sum.at(i)=sum.at(i+1)+vec.at(i);
  }
  for(ll i=1;i<=N;i++){
    dp[i]=min(2*(dp[i-1]-vec.at(i-1)),sum.at(i));
    if(dp[i]<=0){cout<<-1<<endl;return 0;}
    answer+=dp[i];
  }
  if(dp[N]!=vec.at(N)){cout<<-1<<endl;}
  else{cout<<answer<<endl;}
}

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

#define LL long long

const int N = 200200;
const long long mod = 998244353;

using namespace std;

int n;
int a[N],b[N];

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    cin>>n;
    for( int i=1; i<=n; i++ ){
        cin>>a[i];
        b[i] = a[i];
    }
    sort( a + 1, a + n + 1 );
    int x = a[n];
    int y = a[n-1];
    for( int i=1; i<=n; i++ ){
        if( b[i] == x ){
            cout<<y<<endl;
        }
        else{
            cout<<x<<endl;
        }
    }
}


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

int main(){
  int a;
  bool able=false;
  cin >> a;
  for(int i=1; i<10; i++){
    if(a%i==0 && a/i<10) able = true;
  }
  if(able) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		int nedan = int.Parse(Console.ReadLine());
		int satu=0;

		bool bl = true;

		while(bl)
		{
			if (satu>=nedan)
			{
				bl = false;
				break;
			}
			
			satu += 1000;
			
		}
		satu -= nedan;
		//出力
		Console.WriteLine(satu);
	}
}

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

int main(){
	int h,w;
	cin >> h >> w;
	vector<string> field(h);
	for(int i=0; i<h; i++) cin >> field[i];

	vector<vector<int>> L(h,vector<int>(w,0));
	vector<vector<int>> R(h,vector<int>(w,0));
	vector<vector<int>> D(h,vector<int>(w,0));
	vector<vector<int>> U(h,vector<int>(w,0));

	for (int i=0; i<h; i++){
		int cnt = 1;
		for (int j=0; j<w; j++){
			if (field[i][j]=='#') cnt = 0;
			L[i][j] = cnt;
			cnt++;
		}
	}

	for (int i=0; i<h; i++){
                int cnt = 1;
                for (int j=w-1; 0<=j; j--){
			if (field[i][j]=='#') cnt = 0;
                        R[i][j] = cnt;
                        cnt++;
		}
        }

	for (int j=0; j<w; j++){
                int cnt = 1;
                for (int i=0; i<h; i++){
                        if (field[i][j]=='#') cnt = 0;
                        U[i][j] = cnt;
                        cnt++;
                }
        }

	for (int j=0; j<w; j++){
                int cnt = 1;
                for (int i=h-1; 0<=i; i--){
                        if (field[i][j]=='#') cnt = 0;
                        D[i][j] = cnt;
                        cnt++;
                }
        }
	
	int ans = 0;
	for (int i=0; i<h; i++){
		for (int j=0; j<w; j++){
			if (field[i][j] == '#') continue;
			int res = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3;
			ans = max(ans,res);
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int a, b; cin >> a >> b;
  int ans = -1;
  rep(i,1000) {
    if (((i+1)*8)/100 == a && ((i+1)*10)/100 == b) {
      ans = i+1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
n=int(input())
h_l=list(map(int,input().split()))

ans=0
ans_tmp=0

for i in range(1,n):
    if h_l[i]<=h_l[i-1]:
        ans_tmp+=1
    else:
        ans=max(ans,ans_tmp)
        ans_tmp=0
ans=max(ans,ans_tmp)
print(ans)

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int q; cin >> q;
  vector<int> a;
  for(int i=0;i<q;++i) {
    int t; cin >> t;
    if(t == 0) {
      int x; cin >> x;
      a.push_back(x);
    } else if(t == 1) {
      int p; cin >> p;
      cout << a[p] << endl;
    } else {
      a.pop_back();
    }
  }
}



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

int main(){
    int N;
    int T,A;
    int H[N];
    cin>>N>>T>>A;
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    double dif = 10000;
    int number;
    for(int i=0;i<N;i++){
        double Ti = T - H[i] * 0.006;
        double res = abs(Ti-A);
        if(res<dif){
            dif = res;
            number = i;
        }
    }
    cout<<number+1<<endl;
}

Measured memory_bytes: 3640
<?php

$A = fgets(STDIN); //500
$B = fgets(STDIN); //100
$C = fgets(STDIN); //50
$X = fgets(STDIN); //合計

$cnt = 0;

$i = 0;
$j = 0;
$k = 0;
while($i <= $A){
  $en = 500 * $i;
  if ($en == $X) $cnt++;

  if ($en >= $X) {
    break;
  } else {

    while($j <= $B){
      $en = 500 * $i + 100 * $j;
      if ($en == $X) $cnt++;
      if ($en >= $X) {
        break;
      } else {


        while($k <= $C){
          $en = 500 * $i + 100 * $j + 50 * $k;
          if ($en == $X) $cnt++;

          if ($en >= $X) {
            break;
          }
          $k++;
        }
      }

      $k = 0;
      $j++;
    }

    $j = 0;
    $i++;
  }
}

echo $cnt;

?>


Measured memory_bytes: 3828
package main
import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
func main() {
	var x int
	fmt.Fscan(r, &x)
         // ↓ここを変える
	 x2 := x * x * x
	fmt.Println(x2)
}


Measured memory_bytes: 1136
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  string a,b;cin>>a>>b;
  ll c=0;
  rep(i,a.size()){
    if(a[i]!=b[i])c++;
  }
  cout<<c;
}


Measured memory_bytes: 27228
n, m, k = map(int, input().split())
s = set()
for i in range(n + 1):
    s.add(i * m)
for i in range(m + 1):
    s.add(i * n)
for i in range(1, n):
    for j in range(1, m):
        s.add(i * j + (n - i) * (m - j))
if k in s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 26044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            var nmk = RL2IE().ToList();
            var N = nmk[0];
            var M = nmk[1];
            Int64 K = (Int64)nmk[2];
            var Alst = RL2IE().ToList();
            var Blst = RL2IE().ToList();

            var Asumlst = new List<Int64>();
            var Bsumlst = new List<Int64>();
            Int64 cnt = 0;
            var len = Alst.Count();
            Asumlst.Add(0);
            for (int i = 0; i < len; i++)
            {
                cnt+=Alst[i];
                Asumlst.Add(cnt);
            }
            cnt = 0; len = Blst.Count(); Bsumlst.Add(0);
            for (int i = 0; i < len; i++)
            {
                cnt += Blst[i];
                Bsumlst.Add(cnt);
            }
            long ret = 0; len++;
            var seek = Asumlst.Count()-1;
            for (int i = 0; i < len; i++)
            {
                var num = Bsumlst[i];
                //var Bindex = 0;
                for (int j = seek; j >= 0; j--)
                {
                    if (Asumlst[j] + num <= K)
                    {
                        ret = ret < j + i ? j + i : ret;
                        seek = j;
                        break;
                    }
                }
                /*
                if (num + Asumlst.First() < K)
                {
                    Bindex = Asumlst.FindLastIndex(x =>( (K - num - x) >= 0));
                }
                if (ret < i+ Bindex&&K>=num+Asumlst[Bindex]) ret =i + Bindex;
                 * */
            }
    
            Console.WriteLine(ret);
            Console.ReadLine();

        }

        static IEnumerable<Int64> RL2IE() { return spr(RL()).Select(x => (Int64)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


Measured memory_bytes: 77460
#include <iostream>
#include <bits/stdc++.h>
#define MAX_NUM 10001
#define MAX_SIZE 2000010
using namespace std;



void countingSort(unsigned short A[], unsigned short B[], int n, int k) {
    int C[k];
    for (int i=0; i < k; i++) C[i] = 0;
    for (int j=0; j < n; j++) C[A[j]]++;
    for (int i=1; i < k; i++) C[i] += C[i - 1];
    for (int j=n-1; j >= 0; j--) {
        B[C[A[j]] - 1] = A[j];
        C[A[j]]--;
    }
}

int main(){
    int n;
    unsigned short *A, *B;
    cin >> n;
    A = (unsigned short *) malloc(sizeof(short) * n + 1);
    B = (unsigned short *) malloc(sizeof(short) * n + 1);
    for (int i=0; i < n; i++) cin >> A[i];
    countingSort(A, B, n, MAX_NUM);
    for (int i=0; i < n-1; i++) cout << B[i] << " ";
    cout << B[n -1] << endl;
    return 0;
} 


Measured memory_bytes: 10952
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mag (ll)1e6

ll col[mag],size[mag];

int main(){
    ll n,m;cin>>n>>m;
    ll i;
    for(i=1;i<=n;i++){
        size[i]=1;
        col[i]=0;}
    col[1]=1;
    while(m--){
        ll x,y;cin>>x>>y;
        size[x]--;
        size[y]++;
         if(col[x]==1)
            col[y]=1; 
        if(size[x]==0)
            col[x]=0;
          }
ll sum=0;
for(i=1;i<=n;i++)
if(col[i] && size[i])
    sum++;
cout<<sum;
}

Measured memory_bytes: 1792
use std::cmp::min;

// wall.rs --- Wall
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        h: usize,
        w: usize,
        cs: [[usize; 10]; 10],
        xs: [i32; h * w]
    }

    let mut wf = cs;
    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])
            }
        }
    }

    let ans = xs
        .into_iter()
        .filter(|&x| 0 <= x)
        .map(|x| wf[x as usize][1])
        .sum::<usize>();
    println!("{}", ans);
}


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

int main(){
  ll i,N,sx,tx,sy,ty;
  cin>>sx>>sy>>tx>>ty;
  rep(i,tx-sx)cout<<"R";
  rep(i,ty-sy)cout<<"U";
  rep(i,tx-sx)cout<<"L";
  rep(i,ty-sy)cout<<"D";
  cout<<"D";
  rep(i,tx-sx+1)cout<<"R";
  rep(i,ty-sy+1)cout<<"U";
  cout<<"LU";
  rep(i,tx-sx+1)cout<<"L";
  rep(i,ty-sy+1)cout<<"D";
  cout<<"R"<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
jisho = {}
s = list(input())
for w in s:
    if w in jisho:
        jisho[w] += 1
    else:
        jisho[w] = 1

for _ in range(n - 1):
    s = list(input())
    temp = {}
    for w in s:
        if w in temp:
            temp[w] += 1
        else:
            temp[w] = 1
    for key, val in jisho.items():
        if key in temp:
            jisho[key] = min(jisho[key], temp[key])
        else:
            jisho[key] = 0
kouho = []
start = ord("a")
for i in range(start, start + 26):
    w = chr(i)
    if w in jisho:
        kouho += str(w) * jisho[w]
    else:
        continue
print(*kouho, sep="")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define _READ freopen("input.txt", "r", stdin);
#define _FAST                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
const int mod = 1e9 + 7;
void max_self(int &a,int b)
{
    a=max(a,b);
}
int32_t main()
{
    int n;
    cin>>n;
    map<string,int> mp;
    mp["AC"]=0;
    mp["TLE"]=0;
    mp["WA"]=0;
    mp["RE"]=0;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<"\n";
    cout<<"WA x "<<mp["WA"]<<"\n";
    cout<<"TLE x "<<mp["TLE"]<<"\n";
    cout<<"RE x "<<mp["RE"]<<"\n";
    return 0;
}

Measured memory_bytes: 3632
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=0
for i in range(b[0]):
    d=list(map(int,input().split()))
    y=0
    for j in range(b[1]):
        y+=c[j]*d[j]
    if y+b[2]>0:
        x+=1
print(x)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
long n,k,a,now,id;
map<long,long>m,mm;
vector<long>v;
vector<bool>used;
inline void solve(void){
  in(n,k);
  used.resize(n);
  rep(i,n){
    in(a);
    a--;
    m[i]=a;
  }
  v.pb(0);
  used[now]=true;
  mm[now]=id++;
  while(1){
    now=m[now];
    if(used[now]){
      break;
    }else{
      used[now]=true;
      v.pb(now);
      mm[now]=id++;
    }
  }
  if(k<=mm[now])out(v[k]+1);
  else{
    k-=mm[now];
    out(v[mm[now]+k%(v.size()-mm[now])]+1);
  }
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 29520
integer N
integer,allocatable,dimension(:)::b
integer,allocatable,dimension(:)::ans
read*,N
allocate(b(N),ans(N))
read*,b
do i=N,1,-1
  do j=i,0,-1
    if(j==0)then
      print"(i0)",-1
      stop
    endif
    if(b(j)==j)then
      ans(i)=j
      b=[b(:j-1),b(j+1:)]
      exit
    endif
  end do
end do

print"(i0)",ans

end

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int k;
  cin >> k;
  int ans = 0;
  int nana = 7;
  bool flag = false;
  for(int i=1;i<=k;i++){
    nana %= k;
    if(nana == 0){
      flag = true;
      ans = i;
      break;
    }
    nana = nana * 10 + 7;
  }
  if(flag)cout << ans << endl;
  else cout << -1 << endl;
}

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

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

    int N;
    cin >> N;

    map<ll, ll> a;

    for(int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        a[A]++;
    }

    vector<ll> x;

    for(auto i = begin(a); i != a.end(); i++) {
        for(int j = i -> second; j > 1; j -= 2) {
            x.push_back(i -> first);
        }
    }

    sort(x.begin(), x.end(), greater<ll>());

    if(x.size() < 2) cout << 0 << endl;
    else cout << x[0] * x[1] << endl;
}

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

#define ll long long

//#define mod 10000000007

int main()
{
     ll a,b,mod;

     mod=1000000007;

     cin>>a>>b;

    

          if(b==1){
            cout<<0<<endl;

          }else{

          ll x=a%b;

          x=b-x;

          cout<<min(x,a%b)<<endl;
          }

    return 0;
}






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

int main(){
	while(true){
		int n;
		int dp[35] = {0};
		dp[1] = 1;
		dp[2] = 1;
		dp[3] = 1;

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

		for(int i = 1; i <= n; i++){
			dp[i + 1] += dp[i];
			dp[i + 2] += dp[i];
			dp[i + 3] += dp[i];
		}

		dp[n] /= 10;
		dp[n] /= 365;
		dp[n]++;

		cout << dp[n] << endl;

	}
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m;
char s1[2100],s2[2100],s3[2100];
int main()
{
	//scanf("%d%d",&n,&m);
	//printf("%d.",n/m);
	scanf("%s%s%s",s1,s2,s3);
	printf("%c%c%c",s1[0],s2[0],s3[0]);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  long long int a[n], arr[n] = {0};
  for(int i=0; i<n; i++){
    cin >> a[i];
    a[i]--;
    arr[a[i]] += 1;
  }
  long long int ans = 0;
  for(int i=0; i<n; i++){
    if(arr[i]!=0){
      ans += (arr[i]*(arr[i]-1))/2;
    }
  }
  for(int i=0; i<n; i++){
    cout << ans-(arr[a[i]]-1) << endl;
  }
  return 0;
}


Measured memory_bytes: 5760
import scala.math.{min,max}

object Main {
    def main(args: Array[String]) {
        var input = io.Source.stdin.getLines().mkString("\n");
        var ss = input.split('\n').toList;
        val xs = to_array_int(ss(0));
        val p = xs(0);
        val q = xs(1);
        val r = xs(2);
        val res = p + q + r - max(max(p,q),r);
        println(res);
    }
    def to_array_int(s: String): Array[Int] = {
        return s.split(' ').map(_.toInt).toArray;
    }
}


Measured memory_bytes: 25404
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
ll gcd(ll a, ll b){
	while (b) b ^= a ^= b ^= a %= b;
	return a;
}
int main(){
	ll n, ans = 0;
	scanf("%lld", &n);
	ll c[n + 1];
	fill(c, c + n + 1, 0);
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			c[gcd(i, j)]++;
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			ans += gcd(i, j) * c[j];
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    ll T;
    cin >> N >> T;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    a.push_back(2 * (1e+9));
    vector<ll> diff(N);
    for (int i = 0; i < N; i++) diff[i] = a[i+1] - a[i];
    ll ans = 0;
    for (int i = 0; i < N; i++) ans += min(diff[i], T);
    cout << ans << '\n';
}


Measured memory_bytes: 4708
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long seven = 7;
		long count = 0;
		long mod = 0;
		boolean able = false;
		for(int i = 0; i < k; i++) {
			mod=(mod*10+7)%k;
			count++;
			if(mod == 0) {
				able = true;
				break;
			}
		}
		System.out.println(able? count : -1);
    }
}

Measured memory_bytes: 35708
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>

using namespace std;

int main(){
  int n,a,b;
  int x[100000];
  
  cin>>n>>a>>b;
  for(int i = 0;i<n;i++){
    cin>>x[i];
  }
  long long ans = 0;
  for(int i = 1;i<n;i++){
    ans += (b > (long long)(x[i] - x[i-1])*a) ? (long long)(x[i] - x[i-1]) * a:b;
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 768