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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N;
V<V<int>> e;

V<bool> vis1;
V<bool> vis2;

int dfs() {
    vis1.resize(N+1,true);
    vis2.resize(N+1,true);

    std::stack<tuple<int,int>> stk1;
    stk1.push(make_tuple(1,0));
    int u = 1, maxd1 = 0, s, d;
    while(!stk1.empty()) {
        std::tie(s,d) = stk1.top();
        stk1.pop();
        REP(i,e[s].size()) if(vis1[e[s][i]]) {
            stk1.push(make_tuple(e[s][i],d+1));
            vis1[e[s][i]] = false;
            if(maxd1 < d+1) u = e[s][i], maxd1 = d+1;
        }
    }

    std::stack<tuple<int,int>> stk2;
    stk2.push(make_tuple(u,0));
    int v = u, maxd2 = 0;
    while(!stk2.empty()) {
        std::tie(s,d) = stk2.top();
        stk2.pop();
        if(e[s].size() > 0) {
            REP(i,e[s].size()) if(vis2[e[s][i]]) {
                stk2.push(make_tuple(e[s][i],d+1));
                vis2[e[s][i]] = false;
                if(maxd2 < d+1) v = e[s][i], maxd2 = d+1;
            }
        }
    }

    return maxd2;
}

int main(){
    INIT;
    cin >> N;
    e.resize(N+1);
    REP(i,N-1) {
        int x,y; cin >> x; cin >> y;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    int dm = dfs();
    cout << (dm%3 != 1 ? "First" : "Second") << "\n";
}

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

int main() {
  int N, D, X, A;
  cin >> N >> D >> X;

  for (int i = 0; i < N; i++) {
    cin >> A;
    (D % A == 0) ? X += D / A : X += D / A + 1;
  }

  cout << X << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fo for(int i=0;i<n;i++)
#define clear cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define loopSolve int t; cin>>t; while(t--){solve();}
//INT_MAX         2,147,483,647                       <10^10
//U_INT_MAX       4,294,967,295                       <10^10
//LONG_LONG_MAX   9,223,372,036,854,775,807           <10^18
//U_LONG_LONG_MAX 18,446,744,073,709,551,615          <10^18
//ll power(int a, int b){
//    return (ll)(pow(a,b)+0.5);
//}

vector<int> gV(int n){
    vector<int> v(n);
    int input;
    fo { cin>>v[i];  }
    return v;
}

int* gA(int n){
    int* arr = new int[n];
    fo cin>>arr[i];
    return arr;
}


void solve(){
    int x,n;
    cin>>x>>n;
    if(n==0){
        cout<<x<<endl;
        return;
    }
    map<int,int> mp;
    int elt;
    fo{
        cin>>elt;
        mp[elt]++;
    }
    int* arr2 = new int[100];
    int* arr3 = new int[100];
    for(int i=0;i<101;i++)
        arr2[i]=i-(100-x);
    for(int i=0;i<101;i++)
        arr3[i]=x+i+1;
    int a1,a2,d1=INT_MAX,d2=INT_MAX;

    for(int i=100;i>=0;i--){
        if(mp[arr2[i]]==0){
            a1=arr2[i];
            d1=abs(x-arr2[i]);
            break;
        }
    }
    for(int i=0;i<101;i++){
        if(mp[arr3[i]]==0){
            a2=arr3[i];
            d2=abs(x-arr3[i]);
            break;
        }
    }
    if(d1>d2){
        cout<<a2<<endl;
    }else if(d1==d2){
        cout<<min(a1,a2)<<endl;
    }else{
        cout<<a1<<endl;
    }

//    for(int i=-94;i<=5;i++){
//        cout<<i<<" ";
//    }



}


int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    //loopSolve;

	return 0;
}


Measured memory_bytes: 3636
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

const INF: usize = std::usize::MAX;

#[fastout]
fn main() {
    input! {
    n: usize,
    p: [usize; n]
    }
    let mut m = INF;
    let mut ans = 0;
    for i in 0..n {
        if m > p[i] {
            ans += 1;
            m = p[i];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4724
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, M = map(int, input().split())
    p = 10**9 + 7
    
    a = [None] * (M+1)
    inva = [None] * (M+1)
    a[0] = 1
    for i in range(1, M+1):
        a[i] = i * a[i-1] % p
    inva[M] = pow(a[M],p-2,p)
    for i in range(M):
        inva[M-i-1] = inva[M-i] * (M-i) % p

    ans = 0
    for k in range(N+1):
        # nCk
        tmp = (a[N] * inva[N-k] % p) * inva[k] % p
        # (-1)**k
        if k % 2 == 1:
            tmp = -tmp % p
        # mPk
        tmp = (tmp * a[M] % p) * inva[M-k] % p

        # m-kPn-k
        tmp *= pow(a[M-k] * inva[M-N] % p, 2, p)
        tmp %= p
        ans += tmp
        ans %= p
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 48700
solve(c,i,j){
  m[i][j]=0;
  if(m[i][j-1]==c)solve(c,i,j-1);
  if(m[i-1][j]==c)solve(c,i-1,j);
  if(m[i+1][j]==c)solve(c,i+1,j);
  if(m[i][j+1]==c)solve(c,i,j+1);
}

main(){
  int w,h,i,j,r;
  for(;scanf("%d%d",&h,&w),h;printf("%d\n",r)){
    memset(m,0,sizeof(m));
    r=0;
    for(i=1;i<=h;i++)
      scanf("%s",m[i]+1);
    for(i=1;i<=h;i++)
      for(j=1;j<=w;j++)
        if(m[i][j])solve(m[i][j],i,j),r++;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define _READ freopen("input.txt", "r", stdin);
#define _FAST                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
void solve()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int flag=0;
    while(a>0 && c>0)
    {
        if(flag==0)
        {
            c-=b;
        }
        else
        {
            a-=d;
        }
        flag=1-flag;
    }
    if(a>0)
        cout<<"Yes";
    else
    {
            cout<<"No";
    }
    
}
int32_t main()
{
    _FAST

    int t;
    t=1;
    while (t--)
    {
        solve();
        //lb:;
    }

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, 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__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;
	vector<string> vec(n);
	unordered_map<string, int> mp;
	for(auto &s : vec){
		cin >> s;
		mp[s]++;
	}
	cout << mp.size() << endl;
	return 0;
}

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

int main()
{
	string a;
	string b;

	cin >> a;

	if (a == "Sunny") {
		b = "Cloudy";
	}
	else if (a == "Cloudy") {
		b = "Rainy";
	}
	else { b = "Sunny"; }

	cout << b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define MN 262144

typedef long long ll;
typedef std::pair<int, int> P;

const int T = 9;

ll f[1 << T][101000];
int n, q, v[MN], w[MN];
std::vector<P> Q[MN];
ll V[MN], W[MN]; int N = 1;
ll Ans[MN];

void dfs(int x, int y)
{
	if(x > n) return;
	if(x >= (1 << T)) 
	{
		for(int i = 1; i <= N; i++)
			W[i + N] = W[i] + w[x], V[i + N] = V[i] + v[x];
		N <<= 1;
		for(int i = 0; i < Q[x].size(); i++)
		{
			int L = Q[x][i].first, id = Q[x][i].second; 
			for(int j = 1; j <= N; j++)
				if(W[j] <= L) Ans[id] = std::max(Ans[id], V[j] + f[y][L - W[j]]);
		}
		dfs(x << 1, y), dfs(x << 1 | 1, y);
		N >>= 1;
	}
	else
	{
		if((x >> (T - 1)) & 1) dfs(x << 1, x), dfs(x << 1 | 1, x);
		else dfs(x << 1, 0), dfs(x << 1 | 1, 0);
	}
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d%d", &v[i], &w[i]);
		if(i < (1 << T))
		{
			for(int j = 0; j <= 100000; j++)
			{
				f[i][j] = f[i >> 1][j];
				if(j >= w[i]) f[i][j] = std::max(f[i][j], f[i >> 1][j - w[i]] + v[i]);
			}
		}
	}	
	scanf("%d", &q);
	for(int i = 1; i <= q; i++)
	{
		int x, l; scanf("%d%d", &x, &l);
		if(x < (1 << T)) Ans[i] = f[x][l];
		else Q[x].push_back(P(l, i));
	}
	dfs(1, 0);
	for(int i = 1; i <= q; i++) printf("%lld\n", Ans[i]);
}

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

int n;
vector<int> naes;

bool isSequense(vector<int> &data)
{
	int sa = data[1] - data[0];
	for (int i = 0; i < n - 2; i++)
	{
		if(data[i + 1] - data[i] != sa)
			return false;
	}
	return true;
}

int solve()
{
	for (int i = 0; i < n; i++)
	{
		vector<int> tmp = naes;
		tmp.erase(tmp.begin() + i);
		if(isSequense(tmp))
			return naes[i];
	}
}

int main()
{
	while(cin >> n && n)
	{
		n++;
		naes.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> naes[i];
		}
		cout << solve() << endl;
	}
	return 0;
}

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

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

int main(){
	int a,b,r;
	cin>>a>>b;
	if(a>b){
		r = gcd(a,b);
	}else{
		r = gcd(b,a);
	}
	cout<<r<<endl;
	return 0;
}



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

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  if(a > k){
    cout << a-k << " " << b;
  }
  else if(a - k + b > 0){
    cout << 0 << " " << a + b - k;
  }
  else{
    cout << 0 << " " << 0;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

cnt = 0

for i in a:
    if i < 0:
        cnt += 1

abs_a = list(map(abs, a))

if cnt % 2 == 0:
    print(sum(abs_a))
else:
    abs_a = list(map(abs, a))
    print(sum(abs_a) - 2 * min(abs_a))

Measured memory_bytes: 14964
require 'prime'

#約数一覧
def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end

D = divisors(gets.to_i)

s = D.size
if s.even? then
  puts [Math.log10(D[s/2] + 1).ceil, Math.log10(D[(s-2)/2] + 1).ceil].max
else
  puts Math.log10(D[s/2] + 1).ceil
end


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

class Main{
  public static void main(String[] args){
    int i,j,n,num=0;
    try{
      BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(buffer.readLine());
      for(i=0;i<n;i++){
        String strx = buffer.readLine();
        String stry = buffer.readLine();
        num = solve(strx,stry);
        System.out.println(num);
      }
    }catch (IOException e) {
      System.out.println("error");
    }
  }
  private static int solve(String x, String y) {
        int[][] dp = new int[x.length()+1][y.length()+1];
        for(int i=1; i<=x.length(); i++) {
            for(int j=1; j<=y.length(); j++) {
                if(x.charAt(i-1) == y.charAt(j-1)) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
                }
            }
        }
        return dp[x.length()][y.length()];
    }
}



Measured memory_bytes: 64324
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main{
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> array = new ArrayList<String>();

		try {
			String str = null;
			while ((str = br.readLine()) != null && !str.equals("0 0")) {
				array.add(str);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		for (int j = 0; j < array.size(); j++) {
			String[] data = array.get(j).split(" ");
			int from = Integer.parseInt(data[0]);
			int to = Integer.parseInt(data[1]);
			ArrayList<Integer> answer = new ArrayList<Integer>();
			for (int i = 0; from + i <= to; i++) {
				if (((from + i) % 400 == 0) || ((from + i) % 4 == 0)
						&& ((from + i) % 100 != 0)) {
					answer.add(from + i);
				}
			}
			if (answer.size() == 0) {
				System.out.println("NA");
			} else {
				for (int i : answer) {
					System.out.println(i);
				}
			}
			if(j + 1 != array.size())
				System.out.println();
		}
	}

}

Measured memory_bytes: 20076
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>

using namespace std;

int main() {
	int n, m;
	vector<long long> a, b, c, d;
	cin >> n >> m;
	//cout << n << ' ' << m << endl;

	for (int i = 0; i < n; i++) {
		long long x, y;
		cin >> x >> y;
		a.push_back(x);
		b.push_back(y);
	}

	for (int j = 0; j < m; j++) {
		long long x, y;
		cin >> x >> y;
		c.push_back(x);
		d.push_back(y);
		
	}

	for (int i = 0; i < n; i++) {
		long long v = 1000000000;
		int res = 51;
		
		for (int j = 0; j < m; j++) {
			long long m = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			//cout << c[j] << ' ' << d[j] << endl;
			//cout << m << endl;
			if (m < v) {
				res = j; v = m;
			}
		}
		cout << res+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] NK = Console.ReadLine().Split();
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            char[] S = Console.ReadLine().ToCharArray();

            S[K - 1] = S[K - 1].ToString().ToLower().ToCharArray()[0];

            Console.WriteLine(S);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

#define INF 1e9

using namespace std;

int main(void){

  map<char, int> hoge;
  hoge['r'] = 0;
  hoge['s'] = 1;
  hoge['p'] = 2;
  int n, k, r, s, p;
  string t;

  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;
  
  vector<vector<int>> dp(n + 1, vector<int>(3, 0));

  int sum = 0;
  for (int i = 0; i < k; i++){
    if (hoge[t[i]] == 0){
      dp[0][0] = 0;
      dp[0][1] = 0;
      dp[0][2] = p;
    }
    if (hoge[t[i]] == 1){
      dp[0][0] = r;
      dp[0][1] = 0;
      dp[0][2] = 0;
    }
    if (hoge[t[i]] == 2){
      dp[0][0] = 0;
      dp[0][1] = s;
      dp[0][2] = 0;
    }
    int a = 0;
    for (int j = 1; j * k + i < n; j++){
      a = j;
      if (hoge[t[j*k + i]] == 0){
        dp[j][0] = max(dp[j-1][1], dp[j-1][2]);
        dp[j][1] = max(dp[j-1][0], dp[j-1][2]);
        dp[j][2] = max(dp[j-1][0], dp[j-1][1]) + p;
      }
      if (hoge[t[j*k + i]] == 1){
        dp[j][0] = max(dp[j-1][1], dp[j-1][2]) + r;
        dp[j][1] = max(dp[j-1][0], dp[j-1][2]);
        dp[j][2] = max(dp[j-1][0], dp[j-1][1]);
      }
      if (hoge[t[j*k + i]] == 2){
        dp[j][0] = max(dp[j-1][1], dp[j-1][2]);
        dp[j][1] = max(dp[j-1][0], dp[j-1][2]) + s;
        dp[j][2] = max(dp[j-1][0], dp[j-1][1]);
      }
    }
    sum += max(dp[a][0], max(dp[a][1], dp[a][2]));
  }

  cout << sum << endl;


  return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <string.h>
#define MOD 1000000007
#define N_MAX 200006

using namespace std;
typedef long long ll;

int main(){
	int N;
  	int C[N_MAX];
  	ll dp[N_MAX];
    int m[N_MAX];
  	C[0] = 200005;
  	cin >> N;
  	for(int i = 1; i <= N; i++){
    	cin >> C[i];
      	m[C[i]] = 0;
    }
  	bool update = false;
  	dp[0] = 1;
  	for(int i = 1; i <= N; i++){
      	dp[i] = dp[i-1];
      	if(C[i-1] != C[i]){
            dp[i] += m[C[i]];
          	dp[i] = dp[i]%MOD;
        }
      	m[C[i]] = dp[i];
    }
  	cout << dp[N] << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	const string t = "CODEFESTIVAL2016";
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < t.size(); i++) {
		if (s[i] != t[i]) {
			ans++;
		}
	}

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


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

R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]

R.sort(reverse=True)

ans  = 0
used = set([-1])

for x, y in R:
    take = -1
    for i, (u, v) in enumerate(B):
        if x < u and y < v and (not i in used):
            if take == -1:
                take = i
            else:
                if v < B[take][1]:
                    take = i
    if not take in used:
        ans += 1
        used.add(take)

print(ans)

Measured memory_bytes: 3188
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
m = [a1,b1,a2,b2,a3,b3]

n={1:0,2:0,3:0,4:0}
for x in m:
    n[x]+=1
    
t=0
for i in range(4):
    i+=1
    if n[i] != 1 and n[i] != 2:
        t=1
        
if t == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

const int mod = 1001;
 
signed main(){
    int d[1010] = {0};
    d[0] = 1; d[1] = 2;
    rep(i, 2, 1001){
        d[i] = (d[i - 1] + d[i - 2]) % mod;
    }
    int n, a;
    while(cin >> n >> a){
        int ans = 1;
        set<int> st;
        vector<int> mp;
        rep(i, 1, n + 1){
            if(!st.count(d[i])){
                st.insert(d[i]);
                mp. push_back(d[i]);
            }
        }
        sort(all(mp));
        rep(i, 1, mp.size()){
            if(abs(mp[i] - mp[i - 1]) >= a) ans ++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1236
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int timePassed= 0;
		int n = in.nextInt();
		int q = in.nextInt();
		Queue<Integer> process = new LinkedList<Integer>();
		Queue<String> name = new LinkedList<String>();
		ArrayList<String> nameRt = new ArrayList<String>();
		ArrayList<Integer> processRt = new ArrayList<Integer>();
		for(int i = 0;i<n;i++) {
			name.add(in.next());
			process.add(in.nextInt());
		}
		while(!process.isEmpty()) {
			int number = process.remove();
			String nme = name.remove();
			if(number-q<=0) {
				processRt.add(number+timePassed);
				nameRt.add(nme);
				timePassed+=number;
			}
			else {
				process.add(number-q);
				name.add(nme);
				timePassed+=q;
			}
			
		}
		for(int i =0; i<n;i++) {
			System.out.println(nameRt.get(i)+" "+processRt.get(i));
		}
		//System.out.println(process.toString());
		//System.out.println(name.toString());
		
		/**
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
		*/
	}

}


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

ll d(ll x) {
    ll res=0;
    while(x) { 
        res+=x%10; 
        x/=10;
    }
    return res;
}

int main() {
    int n,res,ans=10000000;
    cin>>n;
    for (int a=1; a<=n-1; a++) {
        int b=n-a;
        res=d(a)+d(b);
        ans=min(ans,res);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,c;
    cin>>a>>b>>c;
    if(a+b<=a+c&&a+b<=b+c)cout<<a+b<<endl;
    else if(a+c<=a+b&&a+c<=c+b)cout<<a+c<<endl;
    else cout<<b+c<<endl;

    return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef pair<int,int> pai;
queue<pai> que;
char c[60][60];
int cnt;
bool flag[60][60];
int ans[60][60];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main()
{
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='.') cnt++;
		}
	}
	flag[0][0]=true;
	que.push(pai(0,0));
	while(!que.empty())
	{
    pai p=que.front();
    que.pop();
    for(int i=0;i<4;i++)
		{
      int x=p.first+dx[i],y=p.second+dy[i];
      if(0<=x&&x<h&&0<=y&&y<w&&!flag[x][y]&&c[x][y]=='.')
			{
        flag[x][y]=1;
        ans[x][y]=ans[p.first][p.second]+1;
        que.push(pai(x,y));
      }
    }
  }
	cout<<(ans[h-1][w-1]?cnt-ans[h-1][w-1]-1:-1)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int h,w,d,n;
  cin>>h>>w>>d>>n;
  string s[h];
  for(int i=0;i<h;i++) cin>>s[i];
  int r[d];
  for(int i=0;i<d;i++) cin>>r[i];
  //for(int i=0;i<d;i++) cout<<r[i]<<" ";cout<<endl;
  bool ok[h][w];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      ok[i][j]=1;
  for(int k=0;k<n;k++){
    int x,y,t;
    cin>>x>>y>>t;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	//ok[i][j]=1;
	int di=max(abs(y-i),abs(x-j));
	//cout<<k<<" "<<di<<":"<<i<<" "<<j<<" "<<y-i<<" "<<x-j<<endl;
	if(t==0){
	  if(di<=r[0]) continue;
	  ok[i][j]=0;
	}else if(t==d){
	  if(r[d-1]<di) continue;
	  ok[i][j]=0;
	}else{
	  if(r[t-1]<di&&di<=r[t]) continue;
	  ok[i][j]=0;
	}
      }
    }
    /*
      for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
      cout<<ok[i][j];
      }
      cout<<endl;
      }
      cout<<endl;
    */
  }
  int cnt=0,cnt2=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(ok[i][j]&&s[i][j]!='#') cnt++;
 
  if(cnt==0){
    cout<<"Broken"<<endl;
    return 0;
  }
 
  int sy,sx;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(s[i][j]=='D') sy=i,sx=j;
 
  int ax[]={1,-1,0,0};
  int ay[]={0,0,1,-1};
   
  typedef pair<int,int> P;
  queue<P> q;
  int dp[h][w];
  memset(dp,-1,sizeof(dp));
  dp[sy][sx]=0;
  q.push(P(sy,sx));
  while(!q.empty()){
    P p=q.front();q.pop();
    int y=p.first,x=p.second;
    //cout<<y<<" "<<x<<endl;
    if(ok[y][x]) cnt2++;
    for(int k=0;k<4;k++){
      int ny=y+ay[k],nx=x+ax[k];
      if(ny<0||h<=ny||nx<0||w<=nx) continue;
      if(s[ny][nx]=='#') continue;
      //cout<<ny<<"n"<<nx<<endl;
      if(dp[ny][nx]<0){
	dp[ny][nx]=dp[y][x]+1;
	q.push(P(ny,nx));
      }
    }
  }
  //cout<<cnt<<" "<<cnt2<<endl;
  if(cnt==cnt2){
    cout<<"Yes"<<endl;
  }else if(cnt2==0){
    cout<<"No"<<endl;
  }else{
    cout<<"Unknown"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=2*1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	cout<<n*(n-1)/2<<"\n";
}
// I never lose. I either win or I learn

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

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

    N %= K;

    if(abs(N - K) < N) N = abs(N - K);

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Globalization;
using System.Threading;
using System.Collections.Generic;
using System.Linq;

namespace atcoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            long n = long.Parse(input);
            string name = "";

            while(n != 0)
            {
                char alpha;
                var num = n % 26;
                if(num == 0)
                {
                    alpha = (char)(96 + 26);
                }
                else
                {
                    alpha = (char)(96 + num);
                }
                name = alpha + name;
                n--;
                n /= 26;
            }
            Console.WriteLine(name.ToString());
        }
    }
}


Measured memory_bytes: 17632
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#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 FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())



void init() {

}

void input() {

}

void solve() {
  int n;
  int x[110], y[110], h[110];
  cin >> n;
  REP(i, n) cin >> x[i] >> y[i] >> h[i];
  while(1) {
    REP(X, 101) REP(Y, 101) {
      bool ok = true;
      LL H;
      REP(i, n) if (h[i] > 0) H = h[i] + abs(X-x[i]) + abs(Y-y[i]);
      REP(i, n) {
        int tmph = h[i] + abs(X-x[i]) + abs(Y-y[i]);
        if (h[i] == 0) {
          if (H > tmph) ok = false;
        } else {
          if (H != tmph) ok = false;
        }
      }

      if (ok) {
        cout << X <<" " << Y <<" "<< H << endl;
        return;
      }
    }
  }
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int W = stdIn.nextInt();
		int H = stdIn.nextInt();
		int x = stdIn.nextInt();
		int y = stdIn.nextInt();
		int r = stdIn.nextInt();
		if (x<W && y<H && x>0 && y>0) {
			if (x+r<=W && y+r<=H && x-r>=0 && y-r>=0) {
				System.out.println("Yes");
				return;
			}
			System.out.println("No");
			return;
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 17356
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int i,j;
  for(i=0;4*i<=n;i++){
    for(j=0;4*i+7*j<=n;j++){
      if(4*i+7*j==n){
	printf("Yes\n");
	return;
      }
    }
  }
  printf("No\n");
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <stdio.h>
using namespace std;

// Sum of 4 Integers(0008)
int main()
{
	int n;
	while (cin >> n) {
		int ans = 0;

		for (int a = 0; a < 10; ++a) {
			for (int b = 0; b < 10; ++b) {
				for (int c = 0; c < 10; ++c) {
					for (int d = 0; d < 10; ++d) {
						if (a+b+c+d == n)
							++ans;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$A=$key->A[0];
$B=$key->A[1];
$C=$key->A[2];
$D=$key->A[3];
printf("%d\n",max($A*$B,$C*$D));


Measured memory_bytes: 3704
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B1 solver = new B1();
        solver.solve(1, in, out);
        out.close();
    }

    static class B1 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long aim = in.readLong();
            long pv = 100;
            long time = 0;
            while (pv < aim) {
                long fv = (long) (pv * 101.0 / 100);
                pv = fv;
                time++;
            }

            System.out.println(time);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 32276
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll a, b;
  cin >> a >> b;

  ll ans = (a + b + 1) / 2;

  cout << ans << endl;

  return 0;
}


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

int main() {
  string input;
  cin >> input;
  
  if ( input == "Sunny") cout << "Cloudy" << endl;
  if ( input == "Cloudy") cout << "Rainy" << endl;
  if ( input == "Rainy") cout << "Sunny" << endl;
}

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

int a[100000+1],b[100000+1],s[100000+1];

int main()
{
	int i,j;
	
	for(i=2;i<=100000;i++) a[i]=1;
	
	for(i=2;i<=int(sqrt(100000));i++)
	{
		if(a[i]==1)
			for(j=i+i;j<=100000;j+=i) a[j]=0;
	}
	
	b[1]=0;b[2]=0;
	
	for(i=3;i<=100000;i++)
		if(a[i]==1&&a[(i+1)/2]==1) b[i]=1;
	
	s[1]=0;s[2]=0;
	
	for(i=3;i<=100000;i++)
		s[i]=s[i-1]+b[i];
	
	int q,L,r;
	cin>>q;
	
	for(i=1;i<=q;i++)
	{
		cin>>L>>r;
		cout<<s[r]-s[L-1]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"

using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

//2
int main(void) {
	vector<int> cards = vector<int>();
	int num = 0;
	cin >> num;
	rep(0, num) {
		int a = 0;
		cin >> a;
		cards.push_back(a);
	}
	sort(cards.rbegin(), cards.rend());
	int alice = 0;
	int bob = 0;
	while (!cards.empty()) {
		alice += cards[0];
		cards.erase(cards.begin());
		if (cards.empty()) break;
		bob += cards[0];
		cards.erase(cards.begin());
	}
	cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<cstdio>
 
int main(){
 
    int count[26];
    for(int i = 0;i < 26;i++) {
        count[i] = 0;
    }
    char s[1300];
    while(fgets(s,1300,stdin) != NULL) {
        for(int i = 0;s[i] != '\0';i++) {
            if(s[i] >= 'A' && s[i] <= 'Z') {
                count[s[i] - 'A']++;
            }
            if(s[i] >= 'a' && s[i] <= 'z') {
                count[s[i] - 'a']++;
            }
        }
    }
 
    for(int i = 0;i < 26;i++) {
        printf("%c : %d\n",'a' + i,count[i]);
    }
    return 0;
}


Measured memory_bytes: 2604
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	s := getNextString(scanner)
	k := getNextInt64(scanner)

	cc := make([]int, 0)
	n := len(s)
	c := 0
	for i := 1; i <= n; i++ {
		c++
		if i == n || s[i] != s[i-1] {
			cc = append(cc, c)
			c = 0
		}
	}
	if len(cc) == 1 {
		fmt.Println(int64(cc[0]) * k / 2)
		return
	}
	var ans, add int64
	if s[0] == s[n-1] {
		add = int64(cc[0]/2 + cc[len(cc)-1]/2)
		cc[0] += cc[len(cc)-1]
		cc = cc[:len(cc)-1]
		add -= int64(cc[0] / 2)
	}
	for i := 0; i < len(cc); i++ {
		ans += int64(cc[i]/2) * k
	}

	ans += add
	fmt.Println(ans)
	writer.Flush()
}


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

int main() {
  int a, b;
  cin >> a >> b;
  rep(i, 3) {
    int ii = i + 1;
    if (ii != a && ii != b) cout << ii << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl

use utf8;
use strict;

my $n = <STDIN>;
chomp $n;

my $s_ba = "";
my @s_b = {};
my @s_a = {};
my $s_other = ""; 

for (my $i = 0; $i < $n; $i++) {
    my $s = <STDIN>;
    chomp $s;

    if ($s =~ m/^B.*A$/) {
        $s_ba .= $s;
    } elsif ($s =~ m/^B/) {
        push(@s_b, $s);
    } elsif ($s =~ m/A$/) {
        push(@s_a, $s);
    } else {
        $s_other .= $s;
    }
}

my $ans = $s_other;

if ($#s_a >= 0) {
    $ans .= pop(@s_a);
}

$ans .= $s_ba;

while($#s_a >= 0 && $#s_b >= 0) {
    $ans .= pop(@s_b).pop(@s_a);
}

while($#s_b >= 0) {
    $ans .= pop(@s_b);
}

while($#s_a >= 0) {
    $ans .= pop(@s_a);
}

my $cnt = 0;
while($ans =~ m/AB/g) {$cnt++};

print "$cnt\n";

exit;




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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int num ;
  cin >> num ;
  
  double red[num] , blue[num] , undersum , pom;
  
  for(int i=0; i<num; i++){
    cin >> red[i] ;
  }
  
  for(int j=0; j<num; j++){
    blue[j] = 1/red[j] ;
  }
  
  for (int k=0; k<num; k++){
    undersum += blue[k] ;
  }
  
  pom = 1/undersum ;
  
  cout << pom <<endl ;
  
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		long K=sc.nextLong();
		int[] tel= new int[N];
		for(int i=0;i<N;i++) {
			tel[i]= sc.nextInt();
		}
		int ans = 0;
		int cnt= 0;
		int[] pass=new int[N];
		int from=0;
		int[] loop = new int[2];
		
		for(int i=0;i<K;i++) {
			from = tel[from]-1;
			cnt+=1;
			if(cnt==K) {
				ans=from;
			}
			if(pass[from]==0) {
				pass[from]=cnt;
			}else {
				loop[0]=pass[from];
				loop[1]=cnt;
				break;
			}
//			System.out.println(Arrays.toString(pass));
//			System.out.println(from);
		}
//		System.out.println(Arrays.toString(loop));
//		System.out.println(cnt);
		if(cnt<K) {
			long nokori = ((K-(long)cnt)%(loop[1]-loop[0]));
//			System.out.println(nokori);
			for(int i=0;i<nokori;i++) {
				from = tel[from]-1;
			}
			ans=from;
		}
		System.out.println(ans+1);
		
	}

}

Measured memory_bytes: 60140
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

H_temp = [abs(A-(T-0.006*i)) for i in H]

for i in range(len(H_temp)):
    if H_temp[i] == min(H_temp):
        print(i+1)


Measured memory_bytes: 3060
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		String s = sc.next();
		char[] c = s.toCharArray();

		Arrays.sort(c);
		if(c[0]==c[1]&&c[2]==c[3]&&c[1]!=c[2]) out.println("Yes");
		else out.println("No");

		out.flush();
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#define  C       first
#define  D       second
#define  MAXN    1100
using namespace std;
typedef pair<int,int> pii;
pii res[MAXN];
int add[MAXN];
bool cmp (const pii &a,const pii &b) { return a.C<b.C; }
int main(void) {
    int n, m, c,d ;
    while ( scanf("%d%d",&n,&m)==2 ) {
          for (int i=0;i<m;++i) {
              scanf ("%d%d",&c,&d);
              res[i] = make_pair(c,d);
          }
          sort (res,res+m,cmp);      
          memset (add,0,sizeof(add));
          for (int i=0;i<m;++i) {
              add[res[i].C]++;
              add[res[i].D]--;
          }   
          int ans = 0, tmp = 0;
          for (int i=0;i<=n;++i) {
              tmp += add[i];
              ans += (tmp > 0);
          }
          printf ("%d\n",ans*2+n+1);
    }
    return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
int main(void){
	int a[100][100],b[100],i,j,k,m,n,x;

	scanf("%d %d",&n,&m);
	for(i=0;i<n;++i){
		for(j=0;j<m;++j){
			scanf("%*c%d",&a[i][j]);
		}
	}
	for(i=0;i<m;++i)scanf("%*c%d",&b[i]);
	for(i=0;i<n;++i){
		for(j=0,x=0;j<m;++j)x=x+a[i][j]*b[j];
	printf("%d\n",x);
	}


	return 0;
}

Measured memory_bytes: 640
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define F first
#define S second
#define pb push_back
#define bit __builtin_popcount
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mkp make_pair
#define ffs fflush(stdout)

using namespace std;
using namespace __gnu_pbds;

//order_of_key(k) : Number of items strictly smaller than k
//find_by_order(k) : K-th element in a set (counting from 0)

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

typedef long long ll;
typedef long double ld;
typedef vector <int> lnum;
typedef pair <int, int> pii;

const int N = (int)1e6 + 5;
const int MOD = (int)1e9 + 7;
const int inf = (int)1e18;
const int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
const ld eps = 1e9 - 7;
const int pp[] = {29, 31, 53, 67, 71};
const double pi = acos(-1.0);

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

int a[N];
int pref[N];

signed main() {
  ios_base :: sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  for (int i = 1; i <= n; ++i)
    pref[i] = pref[i - 1] + a[i];
  int ret = inf;
  for (int i = 1; i <= n; ++i)
    ret = min(ret, abs(pref[i] - (pref[n] - pref[i])));
  cout << ret;
  return 0;
}


Measured memory_bytes: 5888
# AGC011
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort(reverse=True)
ans = 0
c_cnt = 0
now = T[0]
##print(C, K)
##print(T)

for i in range(N):
    if c_cnt >= C or now > T[i] + K:     # 乗れない時
        ans += 1
        c_cnt = 1
        now = T[i]
    else:
        c_cnt += 1
    if i == N - 1:
        if c_cnt != 0:
            ans += 1
        else:
            pass
    ##print(i, now, c_cnt, ans)
print(ans)

Measured memory_bytes: 7416
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
	lli n,m;
	cin>>n>>m;
	priority_queue<lli> q;
	for(int i=0;i<n;i++)
	{
		lli x;
		cin>>x;
		q.push(x);
	}
	for(int i=0;i<m;i++)
	{
		lli x=q.top();
		q.pop();
		x=x/2;
		q.push(x);
	}
	lli sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=q.top();
		q.pop();
	}
	cout<<sum<<'\n';
	return 0;
}

Measured memory_bytes: 1400
##======================================python3
''' ===========================================
## null
##
##
=========================================== '''
import sys
from sys import stdin #read(), readline()
input = stdin.readline
import heapq #heappush(trgt, val) heappop(trgt) trgt[0] __lt__<
import collections #Counter() .most_common()
sys.setrecursionlimit(10**6)
INF = 1<<50

if __name__ == '__main__':
    n = int(input())
    
    sip = []
    for i in range(n):
        sip.append(input().replace("\n",""))
    cnt = collections.Counter(sip)
    
    num_max = max(cnt.values())
    ans = [i for i, j in cnt.items() if j == num_max]
    ans.sort()
    
    print('\n'.join(ans))
    
    
    

Measured memory_bytes: 35948
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
    int ans = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1)
            ans = ans * a % mod;
    return ans;
}

signed main()
{
    io;
    
    int x;cin>>x;
    cout<<(x/500 * 1000 + (x%500)/5 * 5)<<endl;

    getchar(); //
    getchar();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/************************Contest Template**************************/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);
struct S{
    int a,b; S(){}S(int _a,int _b)
    { a=_a; b=_b; }
    const bool operator<(const S &o) const{
        return a<o.a;}
};
string exm;
inline void exf(void){ cout<<exm<<"\n"; exit(0); }
template <typename T>
inline void showAll(vector<T> &v,string sep=""){
    for(T &here:v) cout<<here<<sep;}
template <typename T>
inline void showAll(T a[],int st,int end,string sep=""){
    for(int i=st ; i<=end ; i++) cout<<a[i]<<sep; }
template <typename T>
inline void showAll(T a[],int x,int y,int z,int w,string p,string q){
    for(int i=x ; i<=y ; i++){for(int j=z ; j<=w ; j++)
        {cout<<a[i][j]<<p;}cout<<q;}}   
template <typename T>
inline vector<int> int_seperation(T N,int d=10){
    vector<int> v; while(N){v.push_back(N%d); N/=d;}
    reverse(v.begin(),v.end()); return v; }
/************************Contest Template**************************/
//const int SIZE=

int main(){
    int n,s;    scanf("%d %d",&n,&s);
    
    ll ans = 0;
    for(int i=0 ; i<=n ; i++){
        for(int j=i ; j<=n ; j++){
            if(i+j+n<s) continue;
            int k = s-i-j;
            if(k<j) continue;
            if(i==j && j==k) ans++;
            else if(i==j || j==k || i==k) ans+=3;
            else ans+=6;
        }
    }
        
    printf("%lld\n",ans);

    return 0;
}
/*

*/






Measured memory_bytes: 3692