akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int k, q;
    cin >> k >> q;
    ll d[k];
    rep(i,k)cin >> d[i];

    rep(loop,q){
        ll n, x, m;
        cin >> n >> x >> m;
        x %= m;
        ll b[k];
        ll sum = 0;
        ll zero = 0;
        rep(i,k){
            b[i] = d[i] % m;
            sum += b[i];
            if(b[i] == 0)zero++;
        }
        ll ans = n - 1;
        ll now = x;
        n--;
        now += n / k * sum;
        ll cnt = 0;
        cnt += n / k * zero;
        n -= n / k * k;
        rep(i,n){
            now += b[i];
            if(b[i] == 0)cnt++;
        }
        ans -= cnt;
        ans -= now / m;
        cout << ans << endl;
    }


    return 0;
}
 
 


Measured memory_bytes: 384
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

from collections import Counter

h,w = na()
c = Counter()

for i in range(h):
    c.update(ns())

c = list(c.values())

for i in range(len(c)):
    c[i] %= 4

v,x,y,z = c.count(0),c.count(1),c.count(2),c.count(3)

if x+z > 1:
    print('No')
else:
    a = y+z
    if h%2 == 1:
        a -= w//2
    if w%2 == 1:
        a -= h//2
    if a <= 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3316
c_table = [list(map(int, input().split())) for _ in range(3)]
a = [0]*3
b = [0]*3

# a1を0と仮定して b1,b2,b3 の値を求める
for i in range(3):
    b[i] = c_table[0][i]
# b1の値から逆算して a1,a2,a3 の値を求める
for i in range(3):
    a[i] = c_table[i][0]-b[0]

for i in range(3):
    for j in range(3):
        # 成立しないケースがある場合
        if a[i]+b[j] != c_table[i][j]:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    long long a[n+1];
    for(int i=1;i<=n;i++)cin>>a[i];
    long long res=0;
    for(int i=1;i<=n;i++)
    {
        res=res^a[i];
    }
    if(res==0)cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin >> n;
   int ichi = n%10;
   if(ichi == 2 || ichi == 4 || ichi == 5 || ichi == 7 || ichi == 9){
       cout << "hon" << endl;
   }else if(ichi == 3){
       cout << "bon" << endl;
   }else{
       cout << "pon" << endl;
   }
 
}


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

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

int main() {
  int a;
  cin>>a;
  vector<string> vec(a);
  vector<int> vecb(a);
  for(int i=0;i<a;i++){
    cin>>vec.at(i)>>vecb.at(i);
  }
  string f;
  cin>>f;
  int h;
  for(int i=0;i<a;i++){
    if(vec.at(i)==f){
      h=i;
    }
  }
  if(h==a-1){
    cout<<0<<endl;
    return 0;
  }
  int sum=0;
  for(int i=h+1;i<a;i++){
    sum+=vecb.at(i);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc065/tasks/arc076_b?fbclid=IwAR0STem5aakN0X9ogLTeeUqSxyYJ0_NVqqNFUqdgG6pbO2akcR7sJ3SojkY
*/
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define ROF(i,a,b) for(int i = a; i >= b; --i)
#define fast_read ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define maxN 2000005
using namespace std;
int a[maxN];
string s;
vector<int> e[maxN];
int ra[maxN];
queue<pair<int,int> > q;
int main () {
    fast_read
    cin>>s;
    int n = (int) s.size() + 1;
    FOR(i,1,n - 1) {
        if(s[i -1] == '>') {
            e[i+1].pb(i);
            ra[i]++;
        }
        else {
            e[i].pb(i+1);
            ra[i+1]++;
        }
    }
    FOR(i,1,n)
        if(!ra[i]) q.push({i,0});
    while(!q.empty()) {
        int u = q.front().fi;
        int cur = q.front().se;
        a[u] = cur;
       // cout<<"u " <<u<<' '<<cur<<endl;

        q.pop();
        for(int v : e[u]) {
            ra[v]--;
            if(ra[v] == 0) {
                q.push({v,cur+1});
            }
        }
    }
    ll ans =0 ;
    FOR(i,1,n) {
       // cout<<a[i]<<' ';
        ans += 1ll*a[i];
    }
    cout<<ans;
}


Measured memory_bytes: 69532
#include <bits/stdc++.h>
using namespace std;
 
#define NDEBUG
#include <cassert>
 
typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;
 
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;
 
#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair
 
 
ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
 
const ll MOD=1000000007LL;
 
ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
 
vector<ll> m(51), n(51);
 
ll sub(int N, ll X) {
    if (N == 0) { return X; }
    ll w = m[N-1];
    if (X <= 1) return 0;
    X -= 1;
    if (X <= w) return sub(N-1, X);
    X -= w;
    if (X <= 1) return n[N-1] + X;
    X -= 1;
    if (X <= w) return n[N-1] + 1 + sub(N-1, X);
    X -= w;
    return n[N];
}
 
ll solve(int N, ll X) {
    return sub(N, X);
}
 
int main() {
    m[0] = n[0] = 1;
    for (int i=1; i<=50; ++i) {
        m[i] = m[i-1]*2 + 3;
        n[i] = n[i-1]*2 + 1;
    }
 
 
    int N; ll X;
    cin >> N >> X;
    cout << solve(N,X) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
ll n,p,pp;
string s;
ll cou[1000000];
vector<ll> sosu;
ll a[1000001];
int main(){
    cin >> n >> p;
    if(n == 1){
           cout << p << endl;
           return 0;
    }
    pp = p;

       for(int i = 0; i < 1000000; i++)   a[i] = 1;

    for(int i = 2; i < 1000000; i++){
           if(a[i] == 1){
              sosu.push_back(i);
              for(int j = 0; i * (j+2) < 1000000; j++){
                     a[i*(j+2)] = 0;
              }
           }
    }
    ll mem;

    for(int i = 0; i < sosu.size(); i++){
           mem = 0;
           if(p > 1){
                  while(true){
                         if(p % sosu[i] != 0)    break;
                         p /= sosu[i];
                         ++cou[i];
                  }
           }
           else{
                  break;
           }
    }
    ll ans = 1;
    for(int i = 0; i < sosu.size(); i++){
           if(cou[i] >= n){
                  for(int j = 0; j < cou[i]/n; j++){
                         ans *= sosu[i];
                  }
           }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11252
# 1 Dimensional World's Tale
n, m, x, y = map(int, input().split())
x_max = max(list(map(int, input().split())))
y_min = min(list(map(int, input().split())))
if x_max < y and x_max < y_min and x < y_min:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;

    s[5] = ' ';
    s[13] = ' ';
    
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int h, w;
		cin>>h>>w;
		if(h==0&&w==0) break;
		REP(i, h) {
			REP(j, w) {
				if(!((i + j) % 2)) cout<<'#';
				else cout<<'.';
			}
			cout<<endl;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cctype>
using namespace std;
int main(){
    int N,T;
    cin >> N >> T;
    int x=1001;
    for(int i = 0;i<N;++i){
        int c,t;cin>>c>>t;
        if(t<=T&&c<x){
            x=c;
        }
    }

    if(x==1001){
        puts("TLE");
    } else {
        cout << x << endl;
    }

}

Measured memory_bytes: 256
n = gets.chomp.to_i
digits = n.to_s.chars.size
if digits == 1
  puts n
elsif digits.even?
  ans = (1..(digits-1)).step(2).inject(0) do |sum, i|
    sum += 9 * (10 ** ( i - 1 ))
  end
  puts ans
else
  ans = (1..(digits-2)).step(2).inject(0) do |sum, i|
    sum += 9 * (10 ** ( i - 1 ))
  end + n - 10**(digits-1) + 1
  puts ans
end


Measured memory_bytes: 1788
// AOJ 2660: Sigma
// 2018.1.25 bal4u

#include <stdio.h>
#include <string.h>

#define INF 0x10101010

int s[302];
int dp[302][302];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int calc(int x, int y)
{
	int xi, yi, c, tm;

	tm = 0, c = 0;
	while (x || y) {
		xi = x % 10, x /= 10;
		yi = y % 10, y /= 10;
		c = (xi + yi + c) >= 10;
		tm += xi * yi + c;
	}
	return tm;
}

int main()
{
	int n, i, j, k, w, x;

	n = in();
	for (i = 0; i < n; i++) s[i+1] = s[i] + in();

	memset(dp, INF, sizeof(dp));
	for (i = 0; i < n; i++) dp[i][i] = 0;

	for (w = 1; w < n ; w++) {
		for (i = 0 ; i < n - w; i++) {
			j = i + w;
			for (k = i; k < j; k++) {
				x = dp[i][k] + calc(s[k+1]-s[i], s[j+1]-s[k+1]) + dp[k+1][j];
				if (x < dp[i][j]) dp[i][j] = x;
			}
		}
	}
	printf("%d\n", dp[0][n-1]);
	return 0;
}



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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(abs(a-b)<=k && abs(a-c)<=k && abs(a-d)<=k && abs(a-e)<=k && abs(b-c)<=k && abs(b-d)<=k && abs(b-e)<=k && abs(c-d)<=k && abs(c-e)<=k && abs(d-e)<=k){
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

string a,b,c;
string s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

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

	cin>>a>>b>>c;
	cout<<s[a[0]-'a']<<s[b[0]-'a']<<s[c[0]-'a']<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(true){
				int n = sc.nextInt(), s = sc.nextInt();
				if(n == 0 && s == 0) break;
				System.out.println(dfs(0, 0, s, n));
			}
		}
	}
	public static int dfs(int total, int addv, int target, int n){
		if(n == 0) return total == target ? 1 : 0;
		else if(addv > 9) return 0;
		else return dfs(total + addv, addv + 1, target, n - 1) + dfs(total, addv + 1, target, n);
	}
}

Measured memory_bytes: 26344
#include<iostream>
#include<vector>
#include<numeric>

int main()
{
	int64_t N;
	std::cin >> N;
	
	size_t i = 2;
	int64_t R = 0;
	while (i <= N)
	{
		int64_t c = 0;
		while(N % i == 0)
		{
			N /= i;
			++c;
		}
		if (c != 0)
		{
			size_t t = 1;
			size_t j = 1;
			while (t <= c) {
				++j;
				t += j;
			}
			R += j - 1;
		}
		else {
			if (i * i > N) {
				++R;
				break;
			}
		}
		++i;
	}
	std::cout << R << std::endl;

	return 0;
}

Measured memory_bytes: 3648
N = int(input())
A = list(map(int, input().split()))

A.insert(0, 0)
A.append(0)

sum_dis = 0
for i in range(len(A)-1):
    sum_dis += abs(A[i] - A[i+1])

for i in range(1, len(A)-1):
    if A[i-1] < A[i] < A[i+1] or A[i+1] < A[i] < A[i-1]:
        print(sum_dis)
    else:
        print(sum_dis - (abs(A[i] - A[i-1]) + abs(A[i] - A[i+1]) - abs(A[i-1] - A[i+1])))


Measured memory_bytes: 14176
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		sort(all(s));
		string tmp=s;
		reverse(all(tmp));
		cout<<atoi(&tmp[0])-atoi(&s[0])<<endl;
	}
}

Measured memory_bytes: 1236
S=list(input())
n = len(S)

for ii in range(1,n+1):
    if ii % 2 != 0 and S[ii-1] == "L":
        print("No")
        break
    elif ii % 2 == 0 and S[ii-1] == "R":
        print("No")
        break
    if ii == n:
        print("Yes")


Measured memory_bytes: 2940
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut pairs = vec![];
    for _ in 0..n {
        let v = read_vec::<i64>();
        pairs.push((v[0], v[1]));
    }

    let mut ans = 0;
    for jjj in 0..2 {
        if jjj == 1 {
            let mut r_pairs = vec![];
            for &(l, r) in pairs.iter() {
                r_pairs.push((-r, -l));
            }
            pairs = r_pairs;
        }
        let mut l = vec![];
        let mut r = vec![];
        for i in 0..n {
            l.push(pairs[i].0);
            r.push(pairs[i].1);
        }
        let mut l_idx = argsort(&l);
        l_idx.reverse();
        let r_idx = argsort(&r);

        let mut used = vec![false; n];

        let mut l_pointer = 0;
        let mut r_pointer = 0;

        let mut used_indexes = vec![];

        while used_indexes.len() < n {
            while used[l_idx[l_pointer]] {
                l_pointer += 1;
            }
            used[l_idx[l_pointer]] = true;
            used_indexes.push(l_idx[l_pointer]);

            if used_indexes.len() == n {
                break;
            }

            while used[r_idx[r_pointer]] {
                r_pointer += 1;
            }
            used[r_idx[r_pointer]] = true;
            used_indexes.push(r_idx[r_pointer]);
        }
        used_indexes.reverse();

        // simulation
        let mut cur = 0;
        let mut temp = 0;
        for (l, r) in used_indexes.iter().map(|&x| pairs[x]) {
            if cur > r {
                temp += cur - r;
                cur = r;
            } else if cur < l {
                temp += l - cur;
                cur = l;
            }
        }
        temp += cur;
        ans = max(ans, temp);
    }
    println!("{}", ans);
}

fn argsort<T: std::cmp::Ord + std::marker::Copy>(v: &Vec<T>) -> Vec<usize> {
    let mut sort_v = Vec::new();
    for i in 0..v.len() {
        sort_v.push((v[i], i));
    }
    sort_v.sort();
    sort_v.iter().map(|x| x.1).collect::<Vec<usize>>()
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 13712
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,d,x; cin >> n >> d >> x;
    VI a(n); VIin(a);
    rep(i,n) {
        int q = 1;
        x++;
        while(q*a[i]+1 <= d) x++,q++;
    }
    OUT(x);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
string s;
int f(int a,int b)
{
	return a>b;
}
int main()
{fast
	int n,k,i;
	cin>>n>>k;
	ll a[200005];
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n,f);
	ll ans=0;
	for(i=k;i<n;i++)
		ans+=a[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn f(u: usize, p: usize, c: u64, edges: &Vec<Vec<(usize, u64)>>, depth: &mut Vec<u64>) {
    depth[u as usize] = c;
    for v in &edges[u] {
        if v.0 == p {
            continue;
        }
        f(v.0, u, c + v.1, edges, depth);
    }
}

fn main() {
    let n: usize = read();
    let abcvec: Vec<Vec<usize>> = read_vec2(n - 1);
    let mut edges: Vec<Vec<(usize, u64)>> = vec![vec![]; n];
    for abc in abcvec {
        let a = abc[0] - 1;
        let b = abc[1] - 1;
        let c = abc[2];
        edges[a as usize].push((b, c as u64));
        edges[b as usize].push((a, c as u64));
    }
    let qk: Vec<usize> = read_vec();
    let q = qk[0];
    let k = qk[1] - 1;

    let mut depth: Vec<u64> = vec![0; n];
    for v in &edges[k] {
        f(v.0, k, v.1, &edges, &mut depth);
    }

    let xyvec: Vec<Vec<usize>> = read_vec2(q);

    for xy in xyvec {
        println!("{}", depth[xy[0] - 1] + depth[xy[1] - 1]);
    }
}


Measured memory_bytes: 30200
#include <iostream>
#include <math.h>
using namespace std;

long long N,ans;

int main(){
    cin >> N;
    long long a = 1, b = N,ab = b + a - 2;
    for (long long i = 1; i * i <= N;i++){
        if(N % i == 0){
            if(ab > i + N/i - 2){
                a = i;
                b = N / i;
                ab = a + b - 2;
            }
        }
    }
    cout << ab << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int flag1 = 1;
  int i,N,temp,c=0;
  int argv[100];

  scanf("%d",&N);

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

  while(flag1){
    flag1 = 0;
    for( i=N-1 ; i>0 ; i-- ){
      if(argv[i] < argv[i-1]){
        temp = argv[i];
        argv[i] = argv[i-1];
        argv[i-1] = temp;
        c++;
        flag1 = 1;
      }
    }
  }

  for( i=0 ; i<N-1 ; i++)
    printf("%d ",argv[i]);

  printf("%d\n",argv[N-1]);
  printf("%d\n",c);

  return 0;
}


Measured memory_bytes: 2128
l=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
n=int(input())
a=1
for x in l:
	a*=sum(n//x**i for i in range(1,2+9*(x<32)))+1
	a%=10**9+7
print(a)

Measured memory_bytes: 3064
import sys
import cmath
input = sys.stdin.buffer.readline
pi = cmath.pi
exp = cmath.exp

""" https://tjkendev.github.io/procon-library/python/fft/fft.html
"""

def make_exp_t(fn, base):
    exp_t = {0: 1}
    temp = fn
    while temp:
        exp_t[temp] = exp(base / temp)
        temp >>= 1
    return exp_t

def fft_dfs(f, s, fn, st, exp_t):
    if fn==2:
        a = f[s]; b = f[s+st]
        return [a+b, a-b]
    fn2 = fn//2; st2 = st*2
    F0 = fft_dfs(f, s   , fn2, st2, exp_t)
    F1 = fft_dfs(f, s+st, fn2, st2, exp_t)
    w = exp_t[fn]; wk = 1.0
    for k in range(fn2):
        U = F0[k]; V = wk * F1[k]
        F0[k] = U + V
        F1[k] = U - V
        wk *= w
    F0.extend(F1)
    return F0

def fft_init(n: int):
    fn = 2**(n-1).bit_length()
    fft_exp_t = make_exp_t(fn, -2j*pi)
    ifft_exp_t = make_exp_t(fn, 2j*pi)

    def fft(f):
        if fn==1: return f
        F = fft_dfs(f, 0, fn, 1, fft_exp_t)
        return F

    def ifft(F):
        if fn==1: return F
        f = fft_dfs(F, 0, fn, 1, ifft_exp_t)
        f = [x/fn for x in f]
        return f

    return fn, fft, ifft

def pad(f, fn):
    return f + [0,]*max(0, fn-len(f))

def roll(f, shift):
    return f[-shift:] + f[:-shift]

def main():
    N, M = map(int, input().split())
    vA = list(map(int, input().split()))
    nH = 10**5 + 1
    vH = [0,]*nH
    for a in vA:
        vH[a] += 1

    fn, fft, ifft = fft_init(nH*2)
    vH = pad(vH, fn)
    #vB = pad(vB, fn)
    #vB = roll(vH, 1)

    fA = fft(vH)
    #fB = fft(vB)
    fC = [a*a for a in fA]
    vC = ifft(fC)
    rC = [int(x.real+.5) for x in vC]
    #print(*rC[50:70], sep=" ", file=sys.stderr)

    res = 0
    i = len(rC)
    for c in rC[::-1]:
        i -= 1
        if M>=c:
            res += i*c
            M -= c
        else:
            res += i*M
            break
    print(res)

if __name__ == "__main__":
    main()


Measured memory_bytes: 131216
#include <stdio.h>

int Prime(int);

int main()
{
    int n,x,i,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(Prime(x)) cnt++;
    }
    printf("%d\n",cnt);
    
    return 0;
}
int Prime(int x)
{
    int i;
    if(x<2) return 0;
    if(x==2) return 1;
    if(x%2==0) return 0;
    for(i=3;i*i<=x;i+=2){
        if(x%i==0) return 0;
    }
    return 1;
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int count = 0;
			int[][] ans = new int[n][n];
			for(int i = 0;i < n;i++) {
				for(int j = 0;j < 2;j++) {
					ans[i][j] = sc.nextInt();
				}
				if(ans[i][0] == ans[i][1]) {
					count++;
					if(count >= 3) {
						break;
					}
				}
				else {
					count = 0;
				}
			}
			if(count >= 3) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
	}

}


Measured memory_bytes: 36072
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1e18;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main() { 
   int a, b, q; cin >> a >> b >> q;
   vector<ll> A(a), B(b);
   rep(i, a) cin >> A[i];
   rep(i, b) cin >> B[i];
   sort(all(A)); sort(all(B));

   vector<ll> ans(q);
   rep(i, q){
       ll x; cin >> x;
       ll lj = -INF, lt = -INF, rj = INF, rt = INF;
       auto jinja = lower_bound(all(A), x);
       auto tera = lower_bound(all(B), x);
       if(jinja != A.end()) rj = *jinja;
       if(jinja != A.begin()){ jinja--; lj = *jinja;}
       if(tera != B.end()) rt = *tera;
       if(tera != B.begin()){tera--; lt = *tera;}

       ll one = max(x-lj, x-lt);
       ll two = max(rj-x, rt-x);
       ll three = x-lj + rt-x + min(x-lj, rt-x);
       ll four = rj-x + x-lt + min(rj-x, x-lt);
       ll res = min(min(one, two), min(three, four));
       ans[i] = res;
   }
   rep(i, q){
       cout << ans[i] << ln;
   }
}

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

int main() {
  string S;
  cin >> S;
  
  int n = 0;
  
  for(int i = 0; i<4; i++){
    if(S.at(i) == '+') {
      n++;
    }
    else if(S.at(i) == '-') {
      n--;
    }
  }
  cout << n << endl;
}

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

int main(void) {

  char a, b;
  cin >> a >> b;

  if(a == 'H' and b == 'H') cout << "H" << endl;
  else if(a == 'H' and b == 'D') cout << "D" << endl;
  else if(a == 'D' and b == 'H') cout << "D" << endl;
  else cout << "H" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod=1e9+7;
int n,m,a[105],d[105],mn[105],mx[105],f[105][105][105];
int add(int &x,int a){x=x+a>=mod?x+a-mod:x+a;}
int main(){
	scanf("%d",&n);
	m=n+n-1;
	for(int i=1;i<=m;i++) scanf("%d",&a[i]);
	sort(a+1,a+m+1);
	f[1][1][1]=1;
	for(int i=2,mid=1+m>>1;i<=n;i++){
		if(a[mid-i+1]!=a[mid-i+2]) ++d[i],mn[i]=1;
		if(a[mid+i-1]!=a[mid+i-2]) ++d[i],mx[i]=1;
	}
	for(int i=1;i<n;i++){
		for(int p=1;p<=m;p++){
			for(int j=1;j<=p;j++)if(f[i][p][j]){
				int tot=p+d[i+1];
				int pos=mn[i+1]?j+1:j;
				for(int l=1;l<pos;l++)
					add(f[i+1][tot-(pos-l-1)][l],f[i][p][j]);
				add(f[i+1][tot][pos],f[i][p][j]);
				for(int l=pos+1;l<=tot;l++)
					add(f[i+1][tot-(l-pos-1)][pos+1],f[i][p][j]);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++){
		for(int p=1;p<=i;p++) add(ans,f[n][i][p]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<map>
#include<cmath>
#include<set>
#define ll long long
#define inf 0x7fffffff;
#define maxn 600005
using namespace std;
ll x,ans;
ll read()
{
    ll l=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
        w=-1;
        else
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        l*=10;
        l+=ch-'0';
        ch=getchar();
    }
    return l*w;
} 
int main()
{
	x=read();
	ll a=100;
	for(;;)
	{
		ans++;
		a=a*0.01+a;
		if(a>=x)
		break;
	} 
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

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

int main() {
    // input
    int H, W, K; cin >> H >> W >> K;
    vector<vector<char>> S(H);
    repp(i,0,H) {
        vector<char> s(W);
        repp(j,0,W) cin >> s[j];
        S[i] = s;
    }

    int res = 10000;
    // 分割可能な箇所は H - 1 個
    repp(bit,0,(1<<(H-1))) {

        int countH = __builtin_popcount(bit) + 1;
        vector<vector<int>> vertically_splited_S(countH);
        repp(i,0,countH) {
            vector<int> v(W,0);
            vertically_splited_S[i] = v;
        }
        int temp_res = countH - 1;

        int k = 0;
        repp(j,0,H) {
            if (bit&(1<<(j-1)) && j > 0) ++k;
            repp(l,0,W) {
                if (S[j][l] == '1') vertically_splited_S[k][l] += 1;
            }
        }

        bool ok = true;
        repp(j,0,countH) {
            repp(k,0,W) {
                ok &= vertically_splited_S[j][k] <= K;
            }
        }
        if (!ok) continue;

        repp(j, 0, W-1) {
            ok = true;
            repp(k, 0, countH) ok &=
                vertically_splited_S[k][j] + vertically_splited_S[k][j+1] <= K;
            if (ok) {
                repp(k,0,countH) {
                    if (ok) vertically_splited_S[k][j+1] += vertically_splited_S[k][j];
                }
            } else ++temp_res;
        }

        res = min(res, temp_res);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long Gcd(long m, long n) {
  long temp = 0;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

long Lcm(long m, long n) {
  return m * n / Gcd(m,n); 
}

int main() {
  long A, B, C, D;
  cin >> A >> B >> C >> D;
  long div_c = B / C;
  long div_c_out = (A-1) / C;
  div_c -= div_c_out;

  long div_d = B / D;
  long div_d_out = (A-1) / D;
  div_d -= div_d_out;

  long lcm = Lcm(C, D);
  long div_cd = B /lcm;
  long div_cd_out = (A - 1) / lcm;
  div_cd -= div_cd_out;
  
  long res = B - A + 1 - (div_c - div_cd + div_d);
  
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	d = readline() |> split |> parseMap
	s = 0
	for i in 1:n-1
		for j in i+1:n
			s += d[i]*d[j]
		end
	end
	println(s)
end

main()

Measured memory_bytes: 168192
n = int(input())
a = list(map(int, input().split()))
l = [False]*8
ov = 0

for i in range(n):
    if a[i] < 3200:
        l[a[i]//400] = True
    else:
        ov += 1

ans = l.count(True)

print(max(ans, 1), ans + ov)

Measured memory_bytes: 3060
import sys, re
import math
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

s = input()

if s[2] == s[3] and s[4] == s[5] :
    print("Yes")
else:
    print("No")


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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000007; //

int A[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  for(int i=0;i<n;i++) cin >> A[i];

  int last = -1;
	long long ans = 1;
	long long ctr = 0;
  for(int i=0;i<n;i++){
  	if(A[i] > last+2) A[i] = last + 2;
  	if(A[i] == last+1) ans = (ans * (ctr+1)) % MODD;
  	else { last = A[i]; ctr++; }
  }

  for(int i=1;i<=ctr;i++) ans = (ans*i) % MODD;

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


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
import numpy as np

INF = 10 ** 9 + 1
NIL = - 1


N = int(input())
H = list(map(int, input().split()))
h_arr = np.array(H).astype(np.int64)
h_a = np.append(0, h_arr)
h_b = np.append(h_arr, 0)

sub = h_a - h_b
sub_arr = sub[1:-1]

max_count = - INF
counter = 0
for num in sub_arr:
    if num >= 0:
        counter += 1
    else:
        max_count = max(max_count, counter)
        counter = 0

print(max(max_count, counter))


Measured memory_bytes: 23444
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ");
        int a1 = Integer.parseInt(line[0]);
        int a2 = Integer.parseInt(line[1]);
        int a3 = Integer.parseInt(line[2]);
        int a4 = Integer.parseInt(line[3]);
        int a5 = Integer.parseInt(line[4]);
        int a6 = Integer.parseInt(line[5]);
 
        int b = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < b; i++) {
            int c = scanner.nextInt();
            int d = scanner.nextInt();
            int result = 0;
            if (c == a1 || c == a6)
                if (d == a2)
                    result = 3;
                else if (d == a3)
                    result = 5;
                else if (d == a4)
                    result = 2;
                else
                    result = 4;
            else if (c == a2 || c == a5)
                if (d == a1)
                    result = 4;
                else if (d == a3)
                    result = 1;
                else if (d == a4)
                    result = 6;
                else
                    result = 3;
            else {
                if (d == a1)
                    result = 2;
                else if (d == a2)
                    result = 6;
                else if (d == a5)
                    result = 1;
                else
                    result = 5;
            }
            if (c == a4 || c == a5 || c == a6)
                result = 7 - result;
            System.out.println(line[result - 1]);
        }
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<tuple<string,int,int>> vec(N);
  int c = 1;
  string s;
  int score;
  for(auto &v : vec){
    cin >> s >> score;
    get<0>(v) = s;
    get<1>(v) = -score;
    get<2>(v) = c;
    c++;
  }
  //名前の順に並べ替える
  sort(vec.begin(),vec.end());
  for(auto &v : vec){
    cout << get<2>(v) << endl;
  }
  
  
  //for(auto &v : vec){
    //cout << v.first << " " << v.second << endl;
  //}
}

Measured memory_bytes: 256
# ABC 121 B

from collections import deque

def resolve():
    n, m, c = map(int, input().split())
    b = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        a = list(map(int, input().split()))
        v = 0
        for j in range(m):
            v += a[j] * b[j]
        v += c
        if v > 0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

ll solve(ll n, ll k){
    return n / k;
}

int main(){
    ll a, b, x; cin >> a >> b >> x;
    ll ans;
    if(a == 0) ans = solve(b, x) + 1;
    else ans = solve(b, x) - solve(a-1, x);
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
using namespace std;
void dice(){
   int d1,d2,d3,d4,d5,d6;
   cin>>d1>>d2>>d3>>d4>>d5>>d6;
  
   char dir;
   int tmp;
   while(true){
       cin>>dir;
       if(cin.eof()) break;
       if(dir=='E'){
           tmp=d1;d1=d4;d4=d6;d6=d3;d3=tmp;
       }else if(dir=='N'){
           tmp=d1;d1=d2;d2=d6;d6=d5;d5=tmp;
       }else if(dir=='S'){
           tmp=d1;d1=d5;d5=d6;d6=d2;d2=tmp;
       }else if(dir=='W'){
           tmp=d1;d1=d3;d3=d6;d6=d4;d4=tmp;
       }
   }
   cout<<d1<<endl;
}
int main(){
   dice();
   return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
int sub(int n){
  if(n < 10){
    return n;
  }
  int a = n / 10;
  return n % 10 + sub(a);
}

int main(){
  int in;
  scanf("%d",&in);
  if(in % sub(in) == 0){
    printf("Yes");
  }else{
    printf("No");
  }
}


Measured memory_bytes: 128
import javax.swing.text.TabableView;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    static int minCost=Integer.MAX_VALUE;
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        InputReader in=new InputReader(System.in);
        int n=in.nextInt();
        long k=in.nextLong()+1;
        int []aim=new int[n];
        for(int i=0;i<n;i++) aim[i]=in.nextInt();
        List<Integer> list=new ArrayList<>();
        int cur=1;
        int len=-1;
        int start=-1;
        list.add(1);
        boolean []visit=new boolean[n+1];
        visit[1]=true;
        while (true){
            int next=aim[cur-1];
            if(!visit[next])
                list.add(next);
            else{
                int i=0;
                for(i=0;i<list.size();i++)
                    if(list.get(i)==next)
                        break;
                len=list.size()-i;
                start=i;
                break;
            }
            visit[next]=true;
            cur=next;
        }
        if(k<list.size())
            out.println(list.get((int)(k-1) ));
        else{
            long  cha = k-list.size();
            int yu= (int) (cha%len);
            if(yu==0) out.println(list.get(list.size()-1));
            else out.println(list.get(start+yu-1));
        }
        out.flush();
    }
    static class InputReader{
        private BufferedReader in;
        private StringTokenizer tokenizer;
        public InputReader(InputStream stream){
            in = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }
        public String next() throws IOException{
            while(tokenizer==null || !tokenizer.hasMoreTokens()){
                tokenizer = new StringTokenizer(in.readLine());
            }
            return tokenizer.nextToken();
        }
        public Long nextLong() throws IOException {
            String next = next();
            return Long.valueOf(next);
        }
        public int nextInt() throws IOException{
            return Integer.valueOf(next());
        }
    }
}

Measured memory_bytes: 54948
#include<bits/stdc++.h>
using namespace std;
double dp[3005][3005];
double p[3005];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>p[i];
	dp[0][1]=p[0];
	dp[0][0]=1-p[0];
	for(int i=1;i<n;i++){
		dp[i][0]=dp[i-1][0]*(1-p[i]);
		for(int j=1;j<=i+1;j++){
			dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
		}
	}
	double res=0;
	for(int i=n/2+1;i<=n;i++){
		res+=dp[n-1][i];
	}
	printf("%.9f",res);
	return 0;
}

Measured memory_bytes: 68992
#include <stdlib.h>
#include <iostream>
using namespace std;

struct node{
	int parent_id;
	int child_num;
	int* children;
};
void print_children(int *children, int size);
int get_depth(node* g, int id);
int main(){
	int n;
	cin >> n;
	node* g = (node*)calloc(n, sizeof(node));
	// initialize
	for(int i = 0; i < n; ++i){
		g[i].parent_id = -1;
	}
	//input data
	for(int i = 0; i < n; ++i){
		int id;
		int child_num;
		cin >> id;
		cin >> child_num;
		g[id].child_num = child_num;
		g[id].children = (int*)malloc(child_num * sizeof(int));
		for(int j = 0; j < child_num; ++j){
			int child_id;
			cin >> child_id;
			g[child_id].parent_id = id;
			g[id].children[j] = child_id;
		}
	}

	for(int i = 0; i < n; ++i){
		cout << "node " << i
		<< ": parent = " << g[i].parent_id
		<< ", depth = ";
		int depth = get_depth(g, i);
		cout << depth;
		if(depth == 0){
			cout << ", root";
		}else{
			if(g[i].child_num == 0){
				cout << ", leaf";
			}else{
				cout << ", internal node";
			}
		}
		cout << ", [";
		print_children(g[i].children, g[i].child_num);
		cout << "]" << endl;
	}
	return 0;
}

void print_children(int *children, int size){
	for(int j = 0; j < size; ++j){
		 	cout << children[j];
		 	if(j != size-1){
		 		cout << ", ";
		 	}
	}

}
int get_depth(node* g, int id){
	int depth = 0;
	int current_id = id;
	while(g[current_id].parent_id != -1){
		++depth;
		current_id = g[current_id].parent_id;
	}
	return depth;
}

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

const int MAX_H = 100;
const int MAX_W = 100;

char Field[MAX_H][MAX_W];

int A, B;

int main()
{
  memset(Field, '.', sizeof(Field));
  cin >> A >> B;

  bool flagA = (A == 1);
  bool flagB = (B == 1);

  int H = MAX_H;
  int W = MAX_W;

  //黒をいい感じにつくる
  for(int x = 0; x < W && B > 1; x += 2) {
    for(int y = 0; y < H && B > 1; y += 2) {
      Field[y][x] = '#';
      B--;
    }
  }

  //白をいい感じに作る
  for(int x = W-2; 0 <= x && A > 1; x -= 2) {
    for(int y = H-1; 0 <= y && A > 1; y -= 2) {
      Field[y][x] = Field[y-1][x] = Field[y-1][x+1] = '#';
      A--;
    }
  }

  if(flagA) {
    Field[H-1][W-1] = '#';
  }

  cout << H << " " << W << endl;
  for(int y = 0; y < H; y++) {
    for(int x = 0; x < W; x++) {
      cout << Field[y][x];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
S = input()
newS = ''
if len(S) == 1:print(0)
else:
    i = pre = 0
    while True:
        if i > len(S) - 1:
            newS = newS + S[pre]
            break
        else:
            if S[pre] != S[i]:
                newS = newS + S[pre]
                pre = i
            else:i += 1
    print(len(newS)-1)

Measured memory_bytes: 3188
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=307;

int n, k;
char wcz[nax];

int dp[nax][nax][nax];

int wyn;

void maxi(int &a, int b)
{
	a=max(a, b);
}

int main()
{
	scanf("%s%d", wcz+1, &k);
	n=strlen(wcz+1);
	for (int i=1; i<=n; i++)
	{
		for (int j=n; j>i; j--)
		{
			for (int l=0; l<=k; l++)
			{
				maxi(dp[i][j][l], dp[i-1][j][l]);
				maxi(dp[i][j][l], dp[i][j+1][l]);
				if (wcz[i]==wcz[j])
					maxi(dp[i][j][l], dp[i-1][j+1][l]+1);
				if (l)
					maxi(dp[i][j][l], dp[i-1][j+1][l-1]+1);
			}
		}
	}
	for (int i=0; i<=n; i++)
		maxi(wyn, dp[i][i+1][k]*2);
	for (int i=0; i<n; i++)
		maxi(wyn, dp[i][i+2][k]*2+1);
	printf("%d\n", wyn);
	return 0;
}


Measured memory_bytes: 110464
# coding: utf-8

# import numpy as np

inf = 10**10
# inf = np.inf

H, N = map(int, input().split())
A = [None] * N
B = [None] * N

for i in range(N):
    A[i], B[i] = map(int, input().split())

nap = [[inf for _ in range(H+max(A)+1)] for _ in range(N)]
# nap[0] = [inf for _ in range(H+1)]
for j in range(1, len(nap[0])):
    if j <= A[0]:
        nap[0][j] = B[0]
    else:
        # nap[0][j] = inf
        nap[0][j] = nap[0][j-A[0]] + B[0]
for i in range(N):
    nap[i][0] = 0
# nap = [[0 for _ in range(H+2)] for _ in range(N+1)]
# nap = [[None for _ in range(H+1)] for _ in range(N)]
# nap[0][0] = 0

# print(np.array(nap))

for i in range(1, N):
    for j in range(len(nap[0])):
        if j - A[i] < 0:
            nap[i][j] = nap[i-1][j]
        else:
            # print(np.array(nap))
            # print(i, j)
            nap[i][j] = min(nap[i-1][j-A[i]] + B[i], nap[i-1][j], nap[i][j-A[i]] + B[i])

# for i in range(N):
#     for j in range(H+1):
#         if i == 0:
#             if j <= A[0]:
#                 nap[i][j] = B[0]
#             else:
#                 nap[i][j] = 0

#         if j - A[i-1] < 0:
#             nap[i][j] = nap[i-1][j]
#         else:
#             nap[i][j] = min(nap[i-1][j-A[i-1] + B[i-1]], nap[i-1][j])

# import numpy as np
# print(np.array(nap))
print(min(nap[-1][H:]))


Measured memory_bytes: 133896