akhauriyash/Code-Regression huggingface dataset:
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            ulong L = Convert.ToUInt64(input[0]);
            ulong R = Convert.ToUInt64(input[1]);

            if ((R - L) >= 2019)
            {
                Console.WriteLine(0);
                return;
            }

            ulong min = ulong.MaxValue;
            for (ulong i = L; i < R; i++)
            {
                ulong mod = (i * (i + 1)) % 2019;
                min = (min < mod) ? min : mod;
                for (ulong j = i + 2; j <= R; j++)
                {
                    mod = (i * j) % 2019;
                    min = (min < mod) ? min : mod;
                    if (min == 0)
                        break;
                }
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>

using namespace std; using ll=long long; const int INF=1e9;
typedef pair<int,int> P;

int main() {
  ll x; cin>>x;
  ll y = 100; int an=0;
  while(y < x) {
    y = (ll)(y * 1.01); an++;
  }
  cout<<an<<endl;
}

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

int main() {
    int x;
    cin >> x;
    int a = x / 500;
    int b = (x-a*500) / 5;
    cout << a*1000+b*5 << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for i in a:
    d[i] += 1

ans = 0
for v, c in d.items():
    if v > c:
        ans += c
    elif v < c:
        ans += c - v

print(ans)

Measured memory_bytes: 18668
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll M =1e9+7;
const int N = 1e5+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

vector<int> adj[N];
bool vis[N]={0};

void dfs(int x)
{
    vis[x]=1;
        
    for(auto it:adj[x])   
    if(!vis[it])
    dfs(it);
        
}


int main()
{
    int a,b,c,d;
    scf(a),scf(b),scf(c),scf(d);

    if(abs(a-c)<=d||((abs(a-b)<=d&&abs(c-b)<=d)))
        cout<<"Yes\n";

    else
 cout<<"No\n";        
    
 

    
}

Measured memory_bytes: 6088
use std::cmp;

macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let _ = scan!(i64);
    let k = scan!(i64);
    let xs = scan!(i64;;);

    println!(
        "{}",
        xs.iter().map(|x| cmp::min(2 * x, 2 * (k - x))).sum::<i64>()
    )
}


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

public class Main
{

	static int[] a,b,c;
	static int n,k;

		
	public static void main(String[] args)throws IOException{

			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String[] s;
			n=Integer.parseInt(br.readLine());
			a=new int[n];b=new int[n];c=new int[n];

			int[][] dp=new int[n][3];
			

			for(int i=0;i<n;i++)
			{
				s=br.readLine().split(" ");
				a[i]=Integer.parseInt(s[0]);
				b[i]=Integer.parseInt(s[1]);
				c[i]=Integer.parseInt(s[2]);
			}

			dp[0][0]=a[0];
			dp[0][1]=b[0];
			dp[0][2]=c[0];

			for(int i=1;i<n;i++)
			{
				dp[i][0]=a[i]+Math.max(dp[i-1][1],dp[i-1][2]);
				dp[i][1]=b[i]+Math.max(dp[i-1][2],dp[i-1][0]);
				dp[i][2]=c[i]+Math.max(dp[i-1][1],dp[i-1][0]);
			}
			System.out.println(Math.max(Math.max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]));
			

	}
	
}







Measured memory_bytes: 49224
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
d = [0] * (2 * n - 1)
for i in range(n - 1):
    c[i] = b[i] ^ b[i + 1]
    d[i] = a[i] ^ a[i + 1]
c[n - 1] = b[0] ^ b[-1]
d[n - 1] = a[0] ^ a[-1]
for i in range(n - 1):
    d[n + i] = d[i]
t = [0] * (n + 1)
t[0] = -1
j = -1
for i in range(n):
    while j >= 0 and c[i] != c[j]:
        j = t[j]
    j += 1
    t[i + 1] = j
m = 0
i = 0
ans = []
while m < n:
    if c[i] == d[m + i]:
        i += 1
        if i == n:
            ans.append(m)
            m += i - t[i]
            i = t[i]
    else:
        m += i - t[i]
        if i > 0:
            i = t[i]
for k in ans:
    print(k, a[k] ^ b[0])


Measured memory_bytes: 128080
fun main(array: Array<String>) {
    val n = readLine()!!.toInt()
    val list = readLine()!!.split(" ").map { it.toInt() }
    var max = 0
    for(i in list.indices) {
        if(list[i] <= max - 2) {
            print("No")
            return
        }
        else {
            if(list[i] > max) {
                max = list[i]
            }
        }
    }
    print("Yes")
}

Measured memory_bytes: 57812
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;



int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	bool flag = false;
	if (abs(a - c) <= d) {
		flag = true;
	}
	if (abs(a - b) <= d && abs(b-c)<=d) {
		flag = true;
	}

	cout << ((flag) ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int r1 = Math.abs(a-x);
		int r2 = Math.abs(b-x);
		if (r1 >= r2) {
			System.out.println("B");
		} else {
			System.out.println("A");
		}
	}
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    string s;
    cin>>s;
    ll n = s.size();
    s = "."+s;
    if(s[1]!='1'){
        cout<<-1<<endl;
        return  0;

    }
    if(s[n]!='0'){
        cout<<-1<<endl;
        return  0;

    }
    REP(i,1,n){
        if(s[i]!=s[n-i]){
            cout<<-1<<endl;
            return  0;
        }
    }
    s[n]='1';
    queue<int> q;
    REP(i,1,n+1){
        if(s[i]=='1'){
            q.push(i);
        }
    }
    REP(i,1,n){
        if(i==q.front()){
            q.pop();
        }
        cout<<i<<" "<<q.front()<<endl;
    }

    return  0;
}


Measured memory_bytes: 1900
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
81 58
)");
#define cin input
#endif

int main()
{
	int x, y;
	cin >> x >> y;

	cout << (x + y / 2) << endl;

	return 0;
}


Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int n; cin >> n;
	vector<ll> a(n);
	cin >> a;
	ll now = a[0];
	REP1(i, n - 1){
		if(now > a[i]){
			ans += now - a[i];
		}
		else now = a[i];
	}	
	cout << ans << endl;
}

Measured memory_bytes: 4832
#include<stdio.h>
#include<string.h>
#define MAX 300

int main(){
	int i,j,n;
	int dp[MAX];
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	for(i=1;i*i<MAX;i++){
		for(j=i*i;j<MAX;j++){
			dp[j] += dp[j-i*i];
		}
	}
	while(scanf("%d",&n)==1&&n){
		printf("%d\n",dp[n]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D){
  int TC = myCeil(C, B);
  int AC = myCeil(A, D);
  cout << (TC <= AC ? YES : NO) << endl;
}

signed main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  long long D;
  scanf("%lld",&D);
  solve(A, B, C, D);
}


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

int main(){
  int n,m;
  cin >> n >> m;
  cin.ignore();
  int mat[n][m];
  int vec[m];
  int s = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> mat[i][j];
    }
    cin.ignore();
  }
  for(int j=0;j<m;j++){
    cin >> vec[j];
    cin.ignore();
  }
  for(int i=0;i<n;i++){
    s = 0;
    for(int j=0;j<m;j++){
      s += mat[i][j]*vec[j];
    }
    cout << s << endl;
  }
  return 0;
}



Measured memory_bytes: 3108
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int n[]=new int[101];
        while(s.hasNext())n[s.nextInt()]++;
        int best=0;
        for(int e: n)if(e>best)best=e;
        for(int i=1; i<=100; i++)if(n[i]==best)System.out.println(i);
    }
}
//by Tuvhsee 12.05.2012
//Mod Value

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int a,b,c,k;
	int ans=0;
	cin >>a>>b>>c>>k;
	while(a >=b){
		b*=2;
		k--;
	}
	clog<<k<<endl;
	while(b >=c){
		c*=2;
		k--;
	}
	cout<<solve(k>=0)<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=2e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
}
int n;
struct node
{
	int x,v,id;
}e[N];
void input()
{
	n=read<int>();
	For(i,1,n)e[i].x=read<int>(),e[i].v=read<int>();
}
struct seg
{
	int l,r;
}a[N];
const int mo=1e9+7;
void add(int &a,int b){a+=b;a-=(a>=mo?mo:0);}
int Mod(int x){return x>=mo?x-mo:x;}
void init()
{
	sort(e+1,e+n+1,[&](node a,node b){return a.v<b.v;});	
	For(i,1,n)e[i].id=i;
	sort(e+1,e+n+1,[&](node a,node b){return a.x<b.x;});
	For(i,1,n)a[i].r=max(a[i-1].r,e[i].id);
	a[n+1].l=n+1;
	Fordown(i,n,1)a[i].l=min(a[i+1].l,e[i].id);
	sort(a+1,a+n+1,[&](seg a,seg b){return a.r==b.r?a.l<b.l:a.r<b.r;});
}
int sum[N<<2];
#define mid ((l+r)>>1)
#define lson h<<1,l,mid
#define rson h<<1|1,mid+1,r
void update(int h,int l,int r,int pos,int v)
{
	if(l==r)add(sum[h],v);
	else
	{
		pos<=mid?update(lson,pos,v):update(rson,pos,v);
		sum[h]=Mod(sum[h<<1]+sum[h<<1|1]);
	}
}
int query(int h,int l,int r,int s,int t)
{
	if(s<=l&&r<=t)return sum[h];	
	int res=0;
	if(s<=mid)res=query(lson,s,t);
	if(mid<t)add(res,query(rson,s,t));
	return res;
}
void work()
{
	int ans=0;
	update(1,0,n,0,1);
	For(i,1,n)
	{
		//cerr<<a[i].l<<' '<<a[i].r<<endl;
		int res=query(1,0,n,a[i].l-1,a[i].r);
		if(a[i].r==n)add(ans,res);
		update(1,0,n,a[i].r,res);
	}
	write(ans,'\n');
}
int main()
{
	input();
	init();
	work();
	return 0;
}



Measured memory_bytes: 7296
import fractions
n = int(input())
a = list(map(int,input().split()))
l = [0 for i in range(n)]
l[0] = a[0]
for i in range(1,n):
    l[i] = fractions.gcd(l[i-1],a[i])
r = [0 for i in range(n)]
r[n-1] = a[n-1]
for i in reversed(range(0,n-1)):
    r[i] = fractions.gcd(r[i+1],a[i])
ans = max(l[n-2],r[1])
for i in range(n-2):
    ans = max(ans,fractions.gcd(l[i],r[i+2]))
print(ans)
    

Measured memory_bytes: 16152
import java.util.*;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
 
public class Main {
	
	static int N;
	static int M;
	static int R;
	static int[] r;
	static int[] A;
	static int[] B;
	static int[] C;
	static int[][] d;
	static int INF = 2 << 28;
	
	static int dfs(int now, boolean[] visit, int cost) {
		boolean ok = true;
		for(int i = 0; i < visit.length; i++) {
			if(!visit[i]) ok = false;
		}
		if(ok) {
			return cost;
		}
		int ret = INF;
		for(int i = 0; i < visit.length; i++) {
			if(!visit[i]) {
				visit[i] = true;
				ret = Math.min(ret, dfs(r[i],visit,cost + d[now][r[i]]));
				visit[i] = false;
			}
		}
		return ret;
	}
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		N = sc.nextInt();
		M = sc.nextInt();
		R = sc.nextInt();
		r = new int[R];
		for(int i = 0; i < R; i++) {
			r[i] = sc.nextInt()-1;
		}
		A = new int[M];
		B = new int[M];
		C = new int[M];
		d = new int[N][N];
		
		for(int i = 0; i < M; i++) {
			A[i] = sc.nextInt()-1;
			B[i] = sc.nextInt()-1;
			C[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				d[i][j] = INF;
			}
		}
		for(int i = 0; i < M; i++) {
			d[A[i]][B[i]] = C[i];
			d[B[i]][A[i]] = C[i];
		}
		for(int k = 0; k < N; k++) {
			for(int i = 0; i < N; i++) {
				for(int j  = 0; j < N; j++) {
					d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		
		int ans = INF;
		
		for(int i = 0; i < R; i++) {
			boolean[] a = new boolean[R];
			a[i] = true;
			ans = Math.min(dfs(r[i],a,0),ans);
		}
		
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 47312
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> HW(H);
    rep(i, H) cin >> HW[i];

    vector<vector<int>> R(H + 1, vector<int>(W + 1, 0));
    vector<vector<int>> C(H + 1, vector<int>(W + 1, 0));

    repd(i, 1, H + 1) {
        repd(j, 1, W + 1) {
            if (HW[i - 1][j - 1] == '.') {
                R[i][j] += R[i][j - 1] + 1;
            }
        }
    }

    repd(j, 1, W + 1) {
        repd(i, 1, H + 1) {
            if (HW[i - 1][j - 1] == '.') {
                C[i][j] += C[i - 1][j] + 1;
            }
        }
    }

    repd(i, 1, H + 1) {
        int ct = R[i][W];
        for (int j = W; j > 0; j--) {
            if (R[i][j] == 0) ct = R[i][j - 1];
            else R[i][j] = ct;
        }
    }

    repd(j, 1, W + 1) {
        int ct = C[H][j];
        for (int i = H; i > 0; i--) {
            if (C[i][j] == 0) ct = C[i - 1][j];
            else C[i][j] = ct;
        }
    }
/*
    repd(i, 1, H + 1) {
        repd(j, 1, W + 1) {
            cout << R[i][j] << " ";
        }
        cout << endl;
    }
*/
    int ans = 0;
    repd(i, 1, H + 1) {
        repd(j, 1, W + 1) {
            chmax(ans, R[i][j] + C[i][j]);
        }
    }

    cout << max(0, ans - 1) << endl;
    return 0;
}

Measured memory_bytes: 42292
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int i,a,b,c,count=0;
      cin>>a>>b>>c;
      if(a!=b)
      	count++;
      if(b!=c)
      	count++;
      if(c!=a)
      	count++;
      if(a==b && b==c)
      	count++;
      cout<<count<<endl;
      return 0;
    }


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

int main() {
    int64_t N;
    cin >> N;

    vector<int64_t> num(N + 1, 0);
    for (int64_t x = 1; x * x <= N; x++) {
        for (int64_t y = 1; y * y <= N; y++) {
            for (int64_t z = 1; z * z <= N; z++) {
                int64_t v = x * x + y * y + z * z + x * y + y * z + z * x;
                if (v > N) {
                    break;
                }
                num[v]++;
            }
        }
    }

    for (int64_t i = 1; i <= N; i++) {
        cout << num[i] << endl;
    }
}

Measured memory_bytes: 3568
// This CODE is supported by PEPECHAN (knzk_ate)
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

ll dp[100100][4] ;
int main()
{
	string s;
	cin >> s;
	ll n = s.size() ;
	rep(i,100100){
		rep(j,4){
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1 ;
	rep(i,n){
		ll num = s[i] - 'A'+1;
		//状態numを更新する。
		rep(j,4) dp[i+1][j] = dp[i][j];

		if(s[i]=='?'){
			rep(j,4){
				dp[i+1][j] *= 3;
				dp[i+1][j] %= mod;
			}
			for(ll j = 1 ; j <= 3 ; j++){
				 dp[i+1][j] += (dp[i][j-1]);
				 dp[i+1][j] %= mod;
			}
		} else {
			dp[i+1][num] += dp[i][num-1] ;
			dp[i+1][num]%= mod;
		}
	} 
	cout << dp[n][3] << endl;
}


Measured memory_bytes: 3584
S=(input())
Q=int(input())
cnt_re=0
s=''
for i in range(Q):
    q=list(input().split())
    if q[0]=='1':
        cnt_re+=1
    else:
        if (int(q[1])+cnt_re)%2==1:
            s=s+q[2]
        else:
            S=S+q[2]
if cnt_re%2==1:
    print(S[::-1]+s)
else:
    print(s[::-1]+S)

Measured memory_bytes: 4480
#include <stdio.h>

void sort(int *num){
	int flag,i,tmp;

	do{
		flag = 0;
		for(i = 0;i < 4;i++){
			if(num[i] < num[i+1]){
				tmp = num[i+1];
				num[i+1] = num[i];
				num[i] = tmp;
				flag = 1;
			}
		}
	}while(flag);
}

int main(){
	int i;
	int num[5];

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

	sort(num);

	for(i = 0;i < 5;i++){
		printf("%d%c",num[i],i == 4 ? '\n' : ' ');
	}

	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll dp[61][2][2]; // 何ケタ目か,L=x or L<x,R=y or y<R
int main() {
	ll L, R;
	cin >> L >> R;
	ll ans = 0;
	for (int n = 0; n <= 60; n++) {
		ll p = 1LL << n;
		ll mask = ~(p - 1);
		if ((L&mask) > p || p > (R&mask)) continue;
		memset(dp, 0, sizeof(dp));
		dp[n][(L&mask) < p][p < (R&mask)] = 1;
		for (int i = n - 1; i >= 0; i--) {
			for (int j = 0; j < 2; j++) {
				for (int k = 0; k < 2; k++) {
					// 0 0
					if (j || ((L >> i) & 1) == 0) {
						(dp[i][j][k | (((R >> i) & 1) == 1)] += dp[i + 1][j][k]) %= MOD;
					}
					// 1 0
					if ((j || ((L >> i) & 1) == 0) && (k || ((R >> i) & 1) == 1)) {
						(dp[i][j][k] += dp[i + 1][j][k]) %= MOD;
					}
					// 1 1
					if (k || ((R >> i) & 1) == 1) {
						(dp[i][j | (((L >> i) & 1) == 0)][k] += dp[i + 1][j][k]) %= MOD;
					}
				}
			}
		}
		for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) (ans += dp[0][i][j]) %= MOD;
	}
	cout << ans << endl;
}

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

const int MAX_NUM = 10000;
bool prime[MAX_NUM + 1];
int N;

void make_prime_table(void) {
	int sqrt_max;

	fill(&prime[0], &prime[MAX_NUM], true);
	prime[0] = prime[1] = false;
	for (int i = 4; i <= MAX_NUM; i += 2) prime[i] = false;
	sqrt_max = (int)sqrt((double)MAX_NUM);
	for (int i = 2; i <= sqrt_max; i++) {
		if (prime[i]) {
			for (int j = i * i; j <= MAX_NUM; j += i)
				prime[j] = false;
		}
	}
}

int main(void) {
	make_prime_table();
	cin >> N;

	int cnt = 0;
	int p = 8;
	while (true) {
		if (prime[p] && (p % 5 == 1)) {
			cout << p;
			++cnt;
			if (cnt == N) {
				cout << '\n';
				break;
			}
			else
				cout << ' ';
		}
		++p;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int bucket[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        bucket[x]++;
    }

    int type=0;
    for(int i=1;i<=N;i++)
        if(bucket[i]!=0)
            type++;

    int res;
    if(type%2)
        res=type;
    else
        res=type-1;

    printf("%d\n",res);
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int lis(vector<int> &v){
    int n = v.size();
    vector<int> ans(n, INF);
    REP(i, n) *lower_bound(ALL(ans), v[i]) = v[i];
    return lower_bound(ALL(ans), INF) - ans.begin();
}

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

    int now = 0;
    REP(i, N){
        if(a[i] == now+1){
            now++;
        }
    }
    if(now) pr(N-now);
    else pr(-1);
}

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

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

    int digit_100 = n/100;
    int digit_10 = (n-(digit_100*100)) / 10;
    int digit_1 = (n-(digit_100*100)-(digit_10*10));

    if((digit_100 == 7) || (digit_10 == 7) || (digit_1 == 7)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second


typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

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

	int n, w; cin >> n >> w;
	vi wei(n), val(n); 
	int sum = 0;
	FOR(i, n) {cin >> wei[i] >> val[i]; sum+=val[i];}  
	vector<vector<int>> dp(n, vector<int>(sum+1, INF));

	for(int i = 0; i <= sum; i++)
		if(i <= val[0]) dp[0][i] = wei[0];
		else dp[0][i] = INF;

	for(int i = 1; i < n; i++){
		for(int j = 0; j <= sum; j++){
			if(j <= val[i])
				dp[i][j] = min(dp[i-1][j], wei[i]);
			else
				dp[i][j] = min(dp[i-1][j],
						   dp[i-1][j-val[i]] + wei[i]);
		}
	}

	int i;
	for(i = 0; i <= sum && dp[n-1][i] <= w; i++);

	cout << i-1 << '\n';

	return 0;
}

Measured memory_bytes: 39808
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
mod = 1_000_000_007
d = {}
for i in range(2,n+1):
    l = factorization(i)
    for item in l:
        d[item[0]] = d.get(item[0],0)+item[1]
ans = 1
for j in d.values():
    ans *= j+1
    ans %= mod
print(ans)

Measured memory_bytes: 9348
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans=1;
int k,n;
int a[111111];
int cnt[111111];

long long mod_pow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

signed main(){
	cin>>n;
	int lim=0;
	rep(i,n){
		cin>>a[i];
		cnt[a[i]]++;
		lim=max(a[i],lim);
	}
	if(lim==0 && cnt[0]!=1)ans=0;
	if(cnt[0]>1 || a[0]!=0)ans=0;
	for(int i=1;i<=lim;i++){
		if(cnt[i]==0 || cnt[0]==0)ans=0;
		ans*=mod_pow(cnt[i-1],cnt[i],998244353);
		ans%=998244353;
	}
	cout<<ans<<endl;
}


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

int main(int argc, char *argv[]){
	string s;
    while(getline(cin,s)){

		while(s.find("that") ==string::npos 
			  && s.find("the") ==string::npos
			  && s.find("this") ==string::npos){
			for (int i = 0; i < s.length(); ++i){
				if(s[i]<'z' && s[i] >='a') s[i]++;
				else if(s[i]=='z') s[i]='a';
			}
		    
			
		}
		cout<<s<<endl;
	}
    return 0;
}

Measured memory_bytes: 1176
#include<stdio.h>
int main(void){
    int A,B;
    scanf("%d %d", &A,&B);
    if(A <= 5){
        printf("0\n");
    }else if(A <= 12){
        printf("%d\n",B/2);
    }else{
        printf("%d\n",B);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

    c = s[0];
    for(int i =1; i < 4; i++){
        if(s[i] == c) {
            cout << "Bad" << endl;
            return 0;
        }
        else c = s[i];
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#過去にACを出したコードでのテスト
N=int(input())
a=[-1]+[int(i) for i in input().split()]
b=[0 for i in range(N+1)]
for i in range(1,N+1)[::-1]:
    tmp=0
    for j in range(2*i,N+1,i):
        tmp+=b[j]
    if tmp%2!=a[i]:
        b[i]=1
ans=[]
for i in range(N+1):
    if b[i]==1:
        ans.append(str(i))
print(len(ans))
print(" ".join(ans))

Measured memory_bytes: 72328
#include<stdio.h>

int main(void)
{
  long int N,i,j,k,C,A;
  long int L[2000];
  scanf("%ld\n",&N);
  for(i=0;i<=N-1;i++){
    scanf("%ld",&L[i]);
  }
  i=0;
  
  while(i<=N-2){
    if(L[i]>L[i+1]){
      C=L[i+1];
      L[i+1]=L[i];
      L[i]=C;
      
      if(i!=0){
        i=i-1;
      }else{
        i++;
      }
    }else{
      i++;
    }
  }
  
  A=0;
  
  for(i=0;i<=N-3;i++){
    for(j=i+2;j<=N-1;j++){
      if(L[j]<L[i]*2){
        A=A+j-i-1;
      }else{
        k=i+1;
        while(L[k]<=L[j]-L[i]){
          k++;
        }
        A=A+j-k;
      }
    }
  }
  
  printf("%ld",A);
  
  return 0;
}

Measured memory_bytes: 128
N = gets.to_i

uf = Array.new(N,&:itself)
class << uf
  def _root(i)
    self[i] = (self[i] == i ? i : _root(self[i]))
  end
  def same?(i,j)
    _root(i) == _root(j)
  end
  def union(i,j)
    self[_root(j)] = _root(i)
  end
end


XY = Array.new(2){ Hash.new(-1) }

N.times.map do |u|
  gets.split.map(&:to_i).each_with_index do |k, axis|
    if XY[axis][k] >= 0
      uf.union(XY[axis][k], u) 
    else
      XY[axis][k] = u
    end
  end
end

E = 2.times.with_object([]) do |axis, o|
  XY[axis].keys.sort.each_cons(2) do |a,b|
    o << [b - a, XY[axis][a], XY[axis][b]]
  end
end
E.sort_by!(&:first)

ans = E.inject(0) do |total, (cost, u, v)|
  unless uf.same?(u,v)
    uf.union(u, v)
    total + cost
  else
    total
  end
end
puts ans




Measured memory_bytes: 39912
#include "bits/stdc++.h"
using namespace std;

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

	for(int i=0;i<s.size();i++) {
		if(s.at(i) == '1') s.at(i) = '9';
		else if(s.at(i) == '9') s.at(i) = '1';
	}

	cout << s << endl;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		String s = sc.nextLine();
		sc.close();
		Set<Character> list = new HashSet<>();
		for(int i = 0; i < s.length(); i++){
			list.add(s.charAt(i));
		  }
		for (char i='a';i<='z';i++) {
			if(!list.contains(i)) {
				System.out.println(i);
				return;
			}
		}
		System.out.println("None");
		
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
}

Measured memory_bytes: 25660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e11
const long long MOD = 1000000007;
typedef long long ll;

int main(){
	ll N, K;
	cin >> N >> K;
	vector<pair<ll, ll>> A(N);
	rep(i, N)cin >> A[i].first >> A[i].second;
	SORT(A);
	ll cnt = 0;
	ll ans;
	for(ll i = 0; i < N; i++){
		if(cnt + A[i].second < K)cnt += A[i].second;
		else{
			ans = A[i].first;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 9e18;
typedef std::pair<int,int> P;
//struct edge {int to,cost;};
#define VMAX 100000+10
    ll X,Y;
    ll ans;
    ll Z,W,N,A[3000];
int main(){
    //std::ios_base::sync_with_stdio(false);
    cin>>N>>Z>>W;
    ans=0;
    REP(i,N){cin>>A[i];}
    if(N==1)ans=abs(A[N-1]-W);
    else ans=max(abs(A[N-1]-W),abs(A[N-2]-A[N-1]));
    cout<<ans<<endl;
    return 0;
}

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

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buf = new byte[1024];
    private int p = 0;
    private int len = 0;
    private boolean hasNextByte() {
        if (p >= len) {
            p = 0;
            try {
                len = in.read(buf);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return len >= 1;
    }
    private int readByte() {
        if (hasNextByte()) {
            return buf[p++];
        }
        else {
            return -1;
        }
    }
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buf[p])) p++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b;
        while (isPrintableChar(b = readByte())) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }
}

public class Main {
    public static void main(String[] args){
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        Integer[][] a = new Integer[62][n + 1];
        int t = 1;
        for (int i = 1; i <= n; i++) a[0][i] = Integer.parseInt(sc.next());
        for (int i = 0; i < 61; i++) {
            for (int j = 1; j <= n; j++) {
                a[i + 1][j] = a[i][a[i][j]];
            }
            if ((k >> i & 1) == 1) t = a[i][t];
        }
        out.println(t);
        out.flush();
    }
}

Measured memory_bytes: 104740
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>

using namespace std;
using ll = long long;

struct Block {
    ll w;
    ll s;
    ll v;
};

const int NNODES = 1009;
const int NWEIGHTS = 2e4 + 7;
Block b[NNODES];
ll dp[NWEIGHTS];
ll t[NWEIGHTS];

bool cmp(Block a, Block b) {
    return (a.s + a.w) < (b.s + b.w);
}

ll solve(int n) {
    ll maxV = 0;
    dp[b[0].w] = b[0].v;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= b[i].s+b[i].w; j++) {
            if (j-b[i].w > 0 && dp[j-b[i].w] > 0) {
                t[j] = max(t[j], dp[j-b[i].w] + b[i].v);
            }
        }
        t[b[i].w] = max(t[b[i].w], b[i].v);

        for (int j = 1; j <= b[i].s+b[i].w; j++) {
            dp[j] = max(dp[j], t[j]);
            t[j] = 0;
        }
    }
    
    for (int j = 0; j <= NWEIGHTS; j++) {
        maxV = max(maxV, dp[j]);
    }
    return maxV;
}
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll tw, ts, tv;
        cin >> tw >> ts >> tv;
        b[i] = Block{tw, ts, tv};
    }
    sort(b, b+n, cmp);
    // for (int i = 0; i < n; i++) {
    //     printf("%lld %lld %lld\n", b[i].w, b[i].s, b[i].v);
    // }
    printf("%lld\n", solve(n));
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	map<vector<llong>, llong> m;

	cin >> N;
	for(int i = 0; i < N; i++){
		vector<llong> p(3);
		cin >> p[0] >> p[1] >> p[2];
		sort(ALL(p));
		m[p]++;
	}

	llong ans = 0;
	for(auto x : m)
		ans += x.second - 1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3268
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,k,ans=0;
  string s;
  cin>>n>>k>>s;
  for(ll i=1;i<n;i++){
    if(s[i]==s[i-1])ans++;
  }
  cout<<min(ans+2*k,n-1)<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 2e5+3;
ll n,p[N],v[N],f[N],num[2][N],ans;
ll find(int x){return x==f[x]?x:f[x]=find(f[x]);}
struct cmp{
    bool operator()(const ll& a,const ll& b){
        return num[0][a]*num[1][b] == num[1][a]*num[0][b] ? a>b : num[0][a]*num[1][b] > num[1][a]*num[0][b];
    }
};
multiset<ll,cmp> st;

int main(){
    scanf("%lld",&n);
    rep(i,2,n) scanf("%lld",&p[i]);
    rep(i,1,n) scanf("%lld",&v[i]);
    rep(i,1,n) num[v[i]][i]=1;
    rep(i,1,n) f[i]=i;
    rep(i,2,n) st.insert(i);
    rep(i,1,n-1){
        ll x=*st.begin();
        ll fz=find(p[x]);
        st.erase(x); st.erase(fz);
        ans+=num[1][fz]*num[0][x];
        //printf("%lld %lld %lld\n",x,fz,ans);;
        num[0][fz]+=num[0][x]; num[1][fz]+=num[1][x];
        f[x]=fz;
        if(fz!=1) st.insert(fz);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 17536
#include<stdio.h>
#define MAX 102

int m[MAX][MAX],p[MAX],n;

int min(int x,int y)
{
  if( x <= y )
    return x;
  else
    return y;
}

void matrixChainOrder(){
  int i,j,k,l,q;
  for( i = 1 ; i <= n ; i++ ) m[i][i] = 0;
  for( l = 2 ; l <= n ; l++ ){
    for( i = 1 ; i <= n-l+1 ; i++ ){
      j = i + l - 1;
      m[i][j] = 100000000;
      for( k = i ; k <= j-1 ; k++ ){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j],q);
      }
    }
  }

}

int main(){
  int i;
  scanf("%d",&n);

  for( i = 1  ; i <= n ; i++ ){
    scanf("%d%d",&p[i-1],&p[i]);
  }    

  matrixChainOrder();

  printf("%d\n",m[1][n]);
  
  return 0;
}

Measured memory_bytes: 636
#include <cstdio>

using namespace std;

int main(void){
  int mtrx[3][3];
  
  for (int i=0; i<9; i++){
    int t;
    scanf("%d", &t);
    mtrx[i%3][i/3] = t;
  }
  
  for (int i=0; i<3; i++){
    while (mtrx[i][0] && mtrx[i][1] && mtrx[i][2]){
      mtrx[i][0]--; mtrx[i][1]--; mtrx[i][2]--;
    }
  }
  
  if ((mtrx[0][0]==mtrx[1][0] && mtrx[1][0]==mtrx[2][0]) &&
      (mtrx[0][1]==mtrx[1][1] && mtrx[1][1]==mtrx[2][1]) &&
      (mtrx[0][2]==mtrx[1][2] && mtrx[1][2]==mtrx[2][2])){
    puts("Yes");
  } else {
    puts("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  if (n > 1) {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  } else {
    cout << "Hello World" << endl;
  }
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    ll tot = 0;
    rep(i,0,n){
        cin >> a[i];
        tot += a[i];
    }
    ll now = 0;
    ll ans = 0;
    if((n != 0 && a[0] > 0) || (n == 0 && a[0] != 1)){
        puts("-1");
        return 0;
    }
    if(n == 0 && a[0] == 1){
        puts("1");
        return 0;
    }
    ans++;
    now = 1;
    rep(i,1, n){
        now = min(tot, (now-a[i-1])*2);
        if(now<1){
            puts("-1");
            return 0;
        }
        if(now<a[i]){
            puts("-1");
            return 0;
        }

        // cout << now << endl;
        tot -= a[i];
        ans += now;
    }


    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3768
/* code by AbhiTaker
         ____
        /    \
       /  __  \              _______      __       _   _    _____    _____
      /  /  \  \            |__   __|    /  \     | | / /  |  ___|  |  _  \
     /  /____\  \     ___      | |      / /\ \    | |/ /   | |__    | |_)  )
    /  /______\  \   |___|     | |     / /__\ \   |   /    |  __|   |    _/
   /  /        \  \            | |    / /----\ \  | |\ \   | |___   | |\ \
  /__/          \__\           |_|   /_/      \_\ |_| \_\  |_____|  |_| \_\
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 6001016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x,a,b;
    cin>>x>>a>>b;
     x -= a;
     
     cout<<x%b<<"\n";
    
    

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

typedef long long ll;

int N;
ll A[100000 - 1], ans[100000 - 1];

int main() {
	cin >> N;
	ll sum = 0;
	for (int i = 0; i < N; i++)cin >> A[i], A[i] *= 2, sum += A[i];
	sum /= 2;
	for (int i = 0; i < N - 1; i += 2) {
		sum -= (A[i]);
	}
	ans[N - 1] = sum;
	for (int i = N - 2; i >= 0; i--) {
		ans[i] = A[i] - ans[i + 1];
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2816