akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long k = sc.nextLong();
		long d = sc.nextLong();
		x = Math.abs(x);
		long p = x / d;
		if (p >= k) {
			x -= d * k;
			System.out.println(x);
		} else {
			x = x % d;
			if ((k - p) % 2 == 0) {
				System.out.println(x);
			} else {
				System.out.println(Math.abs(x - d));
			}
		}
	}

}

Measured memory_bytes: 35672
#include <iostream>
#include <stack>

using namespace std;

void Solution()
{
    stack <int> car;
    
    int n;
    
    while (cin>>n)
    {
        if(n == 0)
        {
            cout<<car.top()<<endl;
            car.pop(); //Removes the element on top of the stack
        }
        else
        {
            car.push(n);
        }

    }

    return;
}

int main()
{
    Solution();
    return 0;
}

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

using namespace std;

int mod = 1000000007;

ll mulmod(ll a, ll b, ll mod) 
{ 
    ll res = 0; // Initialize result 
    a = a % mod; 
    while (b > 0) 
    { 
        // If b is odd, add 'a' to result 
        if (b % 2 == 1) 
            res = (res + a) % mod; 
  
        // Multiply 'a' with 2 
        a = (a * 2) % mod; 
  
        // Divide b by 2 
        b /= 2; 
    } 
  
    // Return result 
    return res % mod; 
} 

ll fact(ll n){
	ll ans = 1;
	for(ll i=1;i<=n;i++){
		ans = mulmod(ans,i,mod);
	}
	return ans%mod;
}

int main(){
	ll n,a,b;
	cin >> n;
	vector< pair <int,int> > v;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		v.push_back({b,a});
	}
	sort(v.begin(),v.end());
	ll time = 0;
	for(int i=0;i<n;i++){
		time+=v[i].second;
		if(time>v[i].first){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main()
{
	long a,b,c;
	cin>>a>>b>>c;
	if(a < b)
	{
		swap(a,b);
	}
	if(a < c)
	{
		swap(a,c);
	}
	if(b < c)
	{
		swap(b,c);
	}
	cout<<b + c<<endl;
	return 0;
}

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


ll a, b, c, d;

ll divide(ll t)
{
	return b / t - (a - 1) / t;
}

ll gcd(ll a, ll b)
{
	return (b == 0 ? a : gcd(b, a%b));
}

int main()
{
	cin >> a >> b >> c >> d;
	cout << (b - a + 1 - divide(c) - divide(d) + divide(c*d/gcd(c,d)));
}
//
//struct work
//{
//	int t;
//	int e;
//};
//
//bool operator < (work t, work e)
//{
//	return t.e < e.e;
//}
//
//int main()
//{
//	int n;
//	cin >> n;
//	fo
//}

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int k,m;
  k = a.size() , m = b.size();
  if (a.at(k-1) == b.at(0) && b.at(m-1) == c.at(0)){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    ll l, r;
    cin >> l >> r;
    ll jmax = min(l + 2020, r);

    ll ans = 2018;

    for(ll i = l; i <= jmax - 1; i++){
        for(ll j = i + 1; j <= jmax; j++){
            ans = min((i * j) % 2019, ans);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  string a, b;
  int c, d;
  cin >> a >> b;
  cin >> c >> d;
  string str;
  cin >> str;
  if(a == str) cout << c-1 << " " << d << endl;
  else cout << c << " " << d-1 << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
abc = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0, 0, 0] for _ in range(N + 1)]
for i in range(N):
    for a in range(3):
        for b in range(3):
            if a == b:
                continue
            dp[i + 1][b] = max(dp[i + 1][b], dp[i][a] + abc[i][b])
print(max(dp[-1]))


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

int main() {
int n,k;
cin >> n >> k;
vector<int> p(n);
for(int i=0;i<n;i++){
	cin >> p[i];
}
sort(p.begin(),p.end());
int ans=0;
for(int i=0;i<k;i++){
	ans += p[i];
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 3628
from itertools import permutations

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
	A[i], B[i], C[i] = map(int, input().split())

d = [[float("inf") for _ in range(N)] for _ in range(N)]

for i in range(M):
	d[A[i] - 1][B[i] - 1] = C[i]
	d[B[i] - 1][A[i] - 1] = C[i]

for k in range(N):
	for i in range(N):
		for j in range(N):
			if d[i][j] > d[i][k] + d[k][j]:
				d[i][j] = d[i][k] + d[k][j]
				d[j][i] = d[i][k] + d[k][j]

p = permutations(r)
ans = float("inf")
for route in p:
	l = 0
	for i in range(R - 1):
		l += d[route[i] - 1][route[i + 1] - 1]

	if l < ans:
		ans = l

print(ans)

Measured memory_bytes: 53720
use proconio::{input, fastout};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
        t: usize,
        ct: [[usize; 2];n],
    }

    let mut c: Vec<usize> = Vec::new();
    for i in 0..n {
        if ct[i][1] <= t {
            c.push(ct[i][0]);
        }
    }
    c.sort();
    if c.len()==0 {
        println!("TLE");
    } else {
        println!("{}", c[0]);
    }

}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N){
    ll ans = 0;
    return ans;
}

int main(){
    char N; cin >> N;
    print(char(N+1));
    return 0;
}

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

result = []
v = sum(sorted_list)
diff = []
for x in range(len(sorted_list)) :
    result.append(sorted_list.pop(0))
    diff.append(abs(sum(result) - sum(sorted_list)))
print(min(diff))

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll min = INF;
    REP(i, 2 * max(X, Y) + 1)
    {
        //! ABピザをi枚買う
        ll a = i / 2, b = i / 2;
        ll m = C * i + std::max((ll)0, X - a) * A + std::max((ll)0, Y - b) * B;
        min = std::min(min, m);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
	ios::sync_with_stdio(0), cin.tie(0);
  	char c;
  	cin >> c;
  	if (c >= 'A' && c <= 'Z')
  		cout << 'A';
  	else 
  		cout << 'a';
}

Measured memory_bytes: 3528
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    Q = int(input())
    BC = [[int(x) for x in input().split()] for _ in range(Q)]

    ans = sum(A)
    cnt = collections.Counter(A)

    for i in range(Q):
        b, c = BC[i]
        ans -= cnt[b] * b
        ans += c * cnt[b]
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(ans)



    

if __name__ == '__main__':
    main()



Measured memory_bytes: 38704
#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 a,b;cin>>a>>b ; int ans=-1;
   rep(i,0,200000){
       int A=floor(i*0.08);
       int B=floor(i*0.1);
       if(A==a && B==b){
           ans=i;
           break;
       }
   }
   cout<<ans<<endl;

    getchar();getchar();
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto C = new string[](2);
    C[0] = sread();
    C[1] = sread();
    writeln((C[0][0] == C[1][2] && C[0][1] == C[1][1] && C[0][2] == C[1][0]) ? "YES" : "NO");
}


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

int main() {
  int N, Y;
  int x,y,z,total;
  int resx,resy,resz;
  resx = -1;
  resy = -1;
  resz = -1;
  cin >> N >> Y;
  for(x=0; x<=N; x++){
    for(y=0; x+y<=N; y++){
      z = N-x-y;
      total = x*10000 + y*5000 + z*1000;
      if(total == Y){
        resx = x;
        resy = y;
        resz = z;
      }
    }
  }
  cout << resx << " " << resy << " " << resz << endl;
}
  

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;



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


ll m = 1000000007;
const int MAX = 200000;
const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}
long long nCrM(int n, int r) {
	if (n < r)return 0;
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
		ans %= MOD;
	}

	return ans;
}
ll kai[100100];
void kaijo() {
	kai[0] = 1;
	FOR(i,1, 100010) {
		kai[i] = (kai[i-1] * (i%MOD)) % MOD;
	}
}




int main() {
	int N, M;
	cin >> N >> M;
	kaijo();
	ll ans = 0;
	int a = min(N, M); int b = max(N, M);
	if (M - N > 1) {
		cout << 0 << endl;
		return 0;
	}
	else {
		ans += kai[b];
		ans = (ans * ((kai[a]) % MOD)*(a-b+2)) % MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T>> &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int H, W;
int u[2005][2005], b[2005][2005], l[2005][2005], r[2005][2005];

void print_dim2(int a[2005][2005], int n, int m) {
  rep(i, 0, n) {
    rep(j, 0, m) {
      cout << a[i][j] << (j != m-1 ? " " : "\n");
    }
  }
}

signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> H >> W;
  vv<string> s(H);
  rep(i, 0, H) cin >> s[i];
  rep(i, 0, H) {
    int c = 0;
    rep(j, 0, W) {
      c = s[i][j] != '#' ? c + 1 : 0;
      l[i][j] = c;
    }
    c = 0;
    eper(j, W-1, 0) {
      c = s[i][j] != '#' ? c + 1 : 0;
      r[i][j] = c;
    }
  }

  rep(j, 0, W) {
    int c = 0;
    rep(i, 0, H) {
      c = s[i][j] != '#' ? c + 1 : 0;
      u[i][j] = c;
    }
    c = 0;
    eper(i, H-1, 0) {
      c = s[i][j] != '#' ? c + 1 : 0;
      b[i][j] = c;
    }
  }
  
  int ans = 0; 
  rep(i, 0, H) {
    rep(j, 0, W) {
      chmax(ans, l[i][j] + r[i][j] + u[i][j] + b[i][j] - (s[i][j] == '#' ? 0 : 1) * 3);
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 130048
#include <cstdio>
#include <vector>

using namespace std;

int main(){
	int self;
	char str[256];
	char* pt;
	bool flag;
	while(1){
		scanf("%d",&self);
		if(self == 0){break;}
		sprintf(str,"%o",self);
		//printf("%s\n",str);
		//01234567
		//01235789
		for(pt = str;*pt!='\0';pt++){
			if(*pt >= '5'){
				*pt += 2;
			}else if(*pt >= '4'){
				*pt += 1;
			}
		}
		printf("%s\n",str);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[n],b[n],i,c=0,p=0;
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<n;i++)cin>>b[i];
    sort(a,a+n,greater<int>());
    sort(b,b+n,greater<int>());
    for(i=0;i<n&&!p;i++){
      if(a[i]>b[i-c])c++;
      if(c>(i+1)/2)p=i+1;
    }
    if(p>0&&p<n)cout<<p<<endl;
    else cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 3464
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N, Q;
string s;

signed main() {
  cin >> N >> Q >> s;

  int sum[101010];
  sum[0] = 0;
  for (int i = 0; i + 1 < N; i++) {
    sum[i + 1] = sum[i];
    if (s[i] == 'A' && s[i + 1] == 'C') {
      sum[i + 1] += 1;
    }
  }

  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    cout << sum[r] - sum[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  cin.ignore();
  while(n--) {
    string s, t, u;
    getline(cin, s);
    t = "Hoshino";
    u = "Hoshina";
    for(int i = 0; i < s.size(); ++i) {
      if(s.substr(i, t.size()) == t) {
        cout << u;
        i += t.size() - 1;
      } else {
        cout << s[i];
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
N = 2000001
k, x = map(int, input().split())
p = [i for i in range(-1000000, 1000001)]
filt = list(filter(lambda j: j >= x - (k-1) and j <= x + (k-1), p))
ans = ' '.join(list(map(str, filt)))
print(ans)

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

int main(){
  int A = 0, B = 0, C = 0, D = 0;

  cin >> A >> B >> C >> D ;

  while(A > 0 && C > 0){
    C = C - B;
    if(C > 0){
      A = A - D;
      if(A > 0) continue;
      else cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 3636
N, A, B = map(int, input().split())
S = str(input())

AB = A + B

count_all = 0
count_abroad = 0
for i in range(N):
    if S[i] == "a" and count_all < AB:
        count_all += 1
        print("Yes")

    elif S[i] == "b" and count_abroad < B and count_all <AB:
        count_all += 1
        count_abroad += 1
        print("Yes")

    else:
        print("No")

Measured memory_bytes: 9308
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
 
int main() {
	string s,t;
	cin >> s >> t;

	int ans;

	if(s[0] == t[0]){
		ans += 1;
	}

	if(s[1] == t[1]){
		ans += 1;
	}

	if(s[2] == t[2]){
		ans += 1;
	}

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

Measured memory_bytes: 256
import sys

# sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    a, op, b = read_str_list()
    res = 0
    if op == '+':
        res = int(a) + int(b)
    if op == '-':
        res = int(a) - int(b)
    print(res)


main()


Measured memory_bytes: 3060
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()


def main():
    n,k = isRaw()
    if k >= n-1:
        return ncr(2*n-1,n-1)
    conv = CONV_TBL(n+1)
    ans = 0
    for j in range(0,k+1):
        tmp = (conv.ncr(n, j)*conv.ncr(n-1, j)+DIV) % DIV
        ans = (ans+tmp+DIV )% DIV

    return ans


if __name__ == "__main__":
    print(main())


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

long gcd(long a,long b){
  if(min(a,b) == 0) return max(a,b);
  gcd(max(a,b)%min(a,b),min(a,b));
}

int main() {
  long x,y;
  cin >> x >> y;
  cout << gcd(x,y) << endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

bool kaibun(string S)
{
    bool b = true;
    REP(i, S.size())
    {
        if (S[i] != S[S.size() - 1 - i])
            b = false;
    }
    return b;
}
signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    string S;
    cin >> S;
    if (kaibun(S))
    {
        if (kaibun(S.substr(0, (S.size() - 1) / 2)))
        {
            if (kaibun(S.substr((S.size() + 3) / 2 - 1, S.size() - (S.size() + 3) / 2 + 2)))
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,i;cin>>n;
  vector<long long> a(n);
  for(i=0; i<n; ++i) cin>>a[i];
  sort(a.rbegin(),a.rend());
  if(a[a.size()-1]==0){cout<<0<<endl;return 0;}
  long long b=1,c=1e18;
  for(i=0; i<n; ++i){
    b*=a[i];c/=a[i];
    if(c==0){cout<<-1<<endl;return 0;}
  }
  cout<<b<<endl;
  return 0;
}


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

int main()
{
  int a[3][3];
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
    	cin >> a[i][j];
    }
  }
  int n, b[15];
  cin >> n;
  for (int k = 0; k < n; k++)
  {
    cin >> b[k];
  }
  
  int p = 0;
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      for (int k = 0; k < n; k++)
      {
      	if (a[i][j] == b[k])
        {
          a[i][j] = 0;
        }
      }
    }
  }

  int c = 0;
  bool bingo = false;
  for (int i = 0; i < 3; i++)
  {
    c = 0;
    for (int j = 0; j < 3; j++)
    {
    	c += a[i][j];
    }
    if (c == 0)
        {
      		bingo = true;
        }
  }
  for (int j = 0; j < 3; j++)
  {
    c = 0;
    for (int i = 0; i < 3; i++)
    {
    	c += a[i][j];
    }
    if (c == 0)
        {
      		bingo = true;
        }
  }
  c = 0;
  for (int i = 0; i < 3; i++)
  {
    c += a[i][2 - i];
  }
  if (c == 0)
    {
    	bingo = true;
    }
  c = 0;
  for (int i = 0; i < 3; i++)
  {
  	c += a[i][i];
  }
  if (c == 0)
    {
    	bingo = true;
    }
  
  if (bingo)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define pos position<int>
#define at_(p) at(p.x).at(p.y)

#define GCD(v) gcd(ALL(v), 0l)

template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}

template <typename T>
using vec =vector<T>;

template <typename T>
using vvec =vector<vector<T>>;

class v {
public:
  int a;
  int b;
  int c;
  int d;
};


int main(){
  int n,m,q;
  cin>>n>>m>>q;
  vec<v> v(q);
  for (int i = 0; i < q; i++) {
    cin>>v[i].a>>v[i].b>>v[i].c>>v[i].d;
  }
  vvec<int> x;
  for (int l = 0; l < pow(2,n+m-1); l++) {
    vec<int> w(1,0);
    int a=1;
    int k=l;
    for (int i = 0; i < n+m-1; i++) {
      if(k%2){
        a++;
      }else{
        w.push_back(a);
      }
      k/=2;
    }
    if(w.size()==n+1)x.push_back(w);
  }
  int mx=0;
  for(const auto& w: x){
    int dsum=0;
    for (int i = 0; i < q; i++) {
      if(w[v[i].b]-w[v[i].a]==v[i].c)dsum+=v[i].d;
    }
    mx=max(mx,dsum);
  }
  cout<<mx;

}



/* きょむ〜 */


Measured memory_bytes: 11464
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+5;
const LL lim = 1e+15;

int n,a[N];
char op[N];
LL f[N][3];

LL maxll(LL x,LL y){return x>=y?x:y;}

int main(){
	n=get();
	a[1]=get();
	fo(i,2,n){
		char ch;
		while(ch=getchar(),ch!='+'&&ch!='-');
		op[i]=ch;
		a[i]=get();
	}
	fo(i,1,n)fo(j,0,2)f[i][j]=-lim;
	f[1][0]=a[1];
	fo(i,2,n)
	if (op[i]=='+'){
		f[i][0]=maxll(f[i-1][0],f[i-1][1])+a[i];
		f[i][1]=f[i-1][1]-a[i];
		f[i][2]=f[i-1][2]+a[i];
	}
	else{
		f[i][1]=f[i-1][0]-a[i];
		f[i][2]=maxll(f[i-1][1],f[i-1][2])+a[i];
	}
	LL ans=maxll(maxll(f[n][0],f[n][1]),f[n][2]);
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

ll gca(ll a, ll b) {
    int r = a % b;
    while (r) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

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

    ll g = gca(a, b);

    cout << a * b / g << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

bool is_prime(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) return false;
	}
	return n != 1;
}

vector<int> divisor(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

map<int, int> prime_factor(int n) {
	map<int, int> res;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int eratosthenes(int n) {
	bool is_prime[n + 1];
	memset(is_prime, true, sizeof(is_prime));
	// prime[n];

	is_prime[0] = is_prime[1] = false;
	int ans = 0;
	rep(i, 2, n + 1) {
		if(is_prime[i]) {
			// prime[ans++] = i;
			ans++;
			for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return ans;
}

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

	bool is_prime[1000001];
	memset(is_prime, true, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	rep(i, 2, 1000000 + 1) {
		if(is_prime[i]) {
			for(int j = 2 * i; j <= 1000000; j += i) is_prime[j] = false;
		}
	}

	int n;
	while(cin >> n) {
		int rsl = 0;
		rep(i, 0, n + 1) {
			if(is_prime[i]) rsl++;
		}
		cout << rsl << endl;
	}
}



Measured memory_bytes: 4204
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int ans, sum;
void dfs(int i, int s, int n){
	/*cout << "i = " << i;
	cout << " s = " << s;
	cout << " n = " << n << endl;*/
	if(s == sum && n == 0){
		ans++;
		return;
	}
	if(i == 10 || n == 0) return;
	dfs(i+1, s+i, n-1);
	dfs(i+1, s, n);

}
int main(){
	int n;
	while(1){
		cin >> n >> sum;
		if(n == 0 && sum == 0) break;
		ans = 0;
		dfs(0, 0, n);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int a, b, h;
	cin >> a >> b >> h;
	cout << ((a + b) * h / 2) << endl;
	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc107/tasks/abc107_b
# B - Grid Compression

N, M = gets.split(" ").map{|d|d.to_i}
A = (0...N).map{gets.strip.split("")}

ignorex = []
ignorey = []


A.size.times{|y|
	if(A[y].all?{|d|d == "."}  )
		ignorey.push(y)
	end
}

A.transpose.size.times{|x|
	if(A.transpose[x].all?{|d|d == "."}  )
		ignorex.push(x)
	end
}

out = ""
A.size.times{|y|
	A.transpose.size.times{|x|
		if(!ignorey.include?(y) && !ignorex.include?(x))
			out += "#{A[y][x]}"
		end
	}
	if(!ignorey.include?(y))
		out += "\n"
	end
}
puts out


Measured memory_bytes: 34032
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);

    int h,n;
    cin>>h>>n;

    
    vi dp(30000,inf);
    dp[0]=0;

    rep(i,n){
        int a,b;
        cin>>a>>b;
        rep(j,30000){
            if(j+a<30000)
                dp[j+a]=min(dp[j+a],dp[j]+b);
            
        }
    }

    int ans=inf;
    FOR(j,h,30000){
        ans=min(ans,dp[j]);
    }

    cout<<ans<<endl;


}

Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    ll n=in();
    vector<ll>b(n-1);for(ll i=0;i<n-1;++i)b[i]=in();
    vector<ll>a(n);for(ll i=0;i<n;++i)a[i]=i==0?b[0]:i==n-1?b[n-2]:min(b[i-1],b[i]);
    cout<<accumulate(a.begin(),a.end(),0LL)<<endl;
}

Measured memory_bytes: 256
def gcd(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp
    while b != 0:
        a, b = b, a%b
    return a

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

Measured memory_bytes: 14076
program am
    implicit none
    integer::N
    integer::M
    integer,allocatable,dimension(:,:)::ANS
    integer::S

    integer::i,j
    read*,N
    allocate(ANS((N**2-N)/2,2))

    M=0
    S=N+merge(1,0,mod(N,2)==0)
    do i=1,N-1
        do j=i+1,N
            if(i+j/=S)then
                M=M+1
                ANS(M,1)=i
                ANS(M,2)=j
            endif
        end do
    end do
    print"(I0)",M
    do i=1,M
        print"(I0,A,I0)",ANS(i,1)," ",ANS(i,2)
    end do
end program am

Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	ll p[a],q[b],r[c];
	for(ll i=0;i<a;i++) {
		cin>>p[i];
	}
	for(ll i=0;i<b;i++) {
		cin>>q[i];
	}
	for(ll i=0;i<c;i++) {
		cin>>r[i];
	}
	sort(p,p+a,greater<ll>());
	sort(q,q+b,greater<ll>());
	sort(r,r+c,greater<ll>());
	ll ans=0;
	multiset<ll> s;
	for(ll i=0;i<x;i++) s.insert(p[i]);
	for(ll i=0;i<y;i++) s.insert(q[i]);
	for(ll i=0;i<c;i++) s.insert(r[i]);
	
	multiset<ll> ::reverse_iterator it;
	ll count=0;
	for(it=s.rbegin();it!=s.rend();it++){
		if(count==(x+y)) break;
		ans+=*it;
		count++;
	}
	
	cout<<ans;
	
	return 0;
}

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

void course0();

int main()
{
	int c = 0;
	if (c == 0) course0();
	getchar();
	getchar();
    return 0;
}

void course0()
{
  long long N, K;	
  cin >> N >> K;
  vector<int> A(N,0),junban(N,0);
  for (int i = 0; i<N; i++){
    int x=0;
    cin >> x;
    A.at(i) = x-1;
  }
  int jun = 1;
  int i = 0;
  while (K > 0){    
    if (junban.at(i) == 0){
      //cout << K << endl;
      junban.at(i) = jun;
      jun++;
      i = A.at(i);
      K--;
    }else{
      K = K % (jun - junban.at(i));
      break;
    }
  }
  while (K > 0) {
    i = A.at(i);
    K--;
  }
  cout << i+1 << endl;
  
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y << endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
 
using namespace std;
 
bool compare(ll &x, ll &y){
    return x>=y;
}
 
ll mode=pow(10,9)+7;

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

	ll n;
	cin>>n;
	ll a[n];
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	a[0]--;
	bool ans=true;
	for (int i=1;i<n;i++){
		if (a[i]-1>=a[i-1]){
			a[i]--;
		}
	}
	for (int i=1;i<n;i++){
		if (a[i]<a[i-1]){
			ans=false;
			break;
		}
	}
	if (ans){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
    return 0; 
}
	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int n;
    cin >> n;
    ll tmp = 1;
    rep(i, n){
        int a;
        cin >> a;
        if (a%2==0) tmp*=2;
    }
    cout << ll(pow(3,n)) - tmp << endl;

    return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int n, m;
    cin >> n;
    int c4=0, c2=0, co=0; 
    rep(i, n) {
        int a; cin >> a;
        if (a%4==0) c4++;
        else if (a%2==0) c2++;
        else co++;
    } 
    co += c2%2;
    cout << (c4 < co -1 ? "No" : "Yes") << endl;
    return 0;
}

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

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long long ,long long >
#define pi pair<int ,int >
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define ct(i) cout<< i << "\n"
#define sv(v) sort(v.begin(),v.end())
#define mod 1000000007
#define M 100005
#define endl "\n"

vector<int> adj[2*M+1],visited(2*M);
int co=0;

void dfs(int s,int nodes) { 
    visited[s] = true;
    co++;
    for (int i = 0; i < adj[s].size(); i++) { 
        if (visited[adj[s][i]] == 0) { 
            dfs(adj[s][i], nodes); 
        } 
    }
} 


void solve(){
    ll n,x=0,ans=0,y,m;
    //string s,t;
    cin>>n>>m;
    set<pair<int,int>>se;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        if(x>y) swap(x,y);
        se.insert({x,y});
    }
    for(auto i:se){
        x = i.F,y=i.S;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    for (int i = 1; i <= n; i++) { 
        if (visited[i] == false) { 
            dfs(i, n);
            ans = max((ll)co,ans);
            co=0; 
        }       
    } 
    
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int q;
    //cin>>q; while(q--)
        solve();
    return 0;
}


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

int main() {
 UL L,R,D; cin>>L>>R>>D;
 UL ans=0;
 ans+=R/D;
 ans-=(L-1)/D;
 cout<<ans<<endl;
 return 0;
}



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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  ll n,p;
  cin >> n >> p;
  string s;
  cin >> s;
  ll ans = 0;
  if(p==2){
    REP(i,n){
      ll num = s[i] - '0';
      if(num%2==0) ans += i+1;
    }
  }else if(p==5){
    REP(i,n){
      ll num = s[i] - '0';
      if(num%5==0) ans += i+1;
    }
  }else{
    vl modp2count = vl(p,0);
    modp2count[0] = 1;
    ll cur = 0;
    ll t = 1;
    REP(i,n){
      ll num = s[n-1-i] - '0';
      cur = cur + num*t;
      cur %= p;
      t = t*10%p;
      modp2count[cur] += 1;
    }
    REP(i,p){
      //cout << i << ":" << modp2count[i] << endl;
      ll k = modp2count[i];
      ans += k*(k-1)/2;
    }
  }
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int main()
{

  int t;
  t = 1;
  //cin >> t;
  while (t--)
  {
     ll n,i,x,s=0;
     cin>>n;
     ll a[n+3];
     FOR(i,0,n-1)  cin>>a[i];
     for(i=0;i<n-1;i++)
     {
      if(a[i]>a[i+1])
      {
        s+=a[i]-a[i+1];
        a[i+1]=a[i];
      }
     }
     cout<<s<<endl;

  }
}

Measured memory_bytes: 5096
#include<string>
#include<sstream>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<ios>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<type_traits>
#include<random>
#include<vector>
#include<map>

using namespace std;

int main()
{
	int A,B,C;
	cin >> A >> B >> C;
	if(B/A<C)
	{
		cout << B/A << endl;
	}
	else
	{
		cout << C << endl;
	}

}





Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;

using Graph = vector<vector<int>>;

ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
ll mul(ll l, ll r) {
    ll ret =1;
    for(int i=0; i<l-r+1; ++i) {
        ret*=i+r;
        ret%=MOD;
    }
    return ret;
}
ll com(ll n, ll k) {
    ll ret1 = mul(n,n-k+1);
    ll ret2 = mul(k,1);
    ll ret3 = modPow(ret2, MOD-2);
    return ret1*ret3%MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k; cin >> n >> k;
    int idx = 0;
    vi A(n); rep(i,n) {
        cin >> A[i];
    }
    int ans = ((n-1)+(k-1)-1)/(k-1);
    cout << ans << "\n";

}



Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main() {
	string str, m, p, k, k2, k3[1000];
	int a, b, q, z = 0, j, l;
	cin >> str >> q;
	for (int i = 0; i < q; i++) {
		cin >> m >> a >> b;
		if (m == "replace") {
			cin >> p;
			str.replace(a, p.size(), p);
		}
		if (m == "reverse") {
			k = str.substr(a, b - a + 1);
			k2 = k;
			l = 0;
			for (j = k.size() - 1; j >= 0; j--) {
				k2[l] = k[j]; l = l + 1;
			}
			str.replace(a, k2.size(), k2);
		}
		if (m == "print") {
			if (a == 0 && b == str.size() - 1) {
				k3[z] = str;
			}
			else if (a == 0 && b == 0) {
				k3[z] = str[0];
			}
			else {
				k3[z] = str.substr(a, b - a+1);
			}
			z = z + 1;
		}
	}
	for (int w = 0; w < z; w++) {
		cout << k3[w] << endl;
	}
}




Measured memory_bytes: 3228
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    ret = 1.0 - (N // 2) / N
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    string s;
    cin >> s;
    int ct = 1;
    for (int i = 1; i < n; i++){
        if (s[i] != s[i-1]) ct++;
    }
    printf("%d",n-max(1,ct-k*2));
}


Measured memory_bytes: 512