akhauriyash/Code-Regression huggingface dataset:
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N, T;
	cin >> N >> T;
	vector<pair<int, int>> p;
	REP(i, N) {
		pair<int, int> a;
		cin >> a.first >> a.second;
		p.emplace_back(a);
	}
	sort(p.begin(), p.end());

	int timeMax = T + 3005;
	vector<vector<ll>> dp(N + 1, vector<ll>(timeMax, -1));
	dp[0][0] = 0;
	REP(i, N) {
		REP(j, timeMax) {
			if (0 <= dp[i][j]) {
				// 時間内なので食べる
				if (j < T) {
					int nextT = j + p[i].first;
					dp[i + 1][nextT] = max(dp[i][nextT], dp[i][j] + p[i].second);
				}
				// 食べない
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			}
		}
	}

	ll ans = 0;
	REP(i, timeMax) ans = max(dp[N][i], ans);
	cout << ans << endl;
	return 0;
}


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

class Program{

}
class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int count = 1,N = in.nextInt();
        Set<Integer> S = new HashSet<Integer>();
        S.add(N);
        while(true){
            if(N%2==0){
                N/=2;
            }
            else{
                N = 3*N+1;
            }
            S.add(N);
            count++;
            if(S.size()<count) {
                System.out.println(count);
                break;
            }
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=1e6+1;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int mod=998244353;
int fac[N],inv[N];
inline int C(int n,int m) { return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod; }
int main()
{
	int n=gi(),m=gi(),i,ans=0;
	for (i=fac[0]=1;i<=n+m;i++) fac[i]=1LL*fac[i-1]*i%mod;
	for (i=2,inv[0]=inv[1]=1;i<=n+m;i++) inv[i]=-1LL*(mod/i)*inv[mod%i]%mod;
	for (i=3;i<=n+m;i++) inv[i]=1LL*inv[i]*inv[i-1]%mod;

	for (i=min(n,m);i;i--)
		ans=(ans+1LL*C(2*i,i)*C(n+m-i*2,n-i))%mod;
	ans=1LL*ans*fac[n]%mod*fac[m]%mod*inv[n+m]%mod;
	cout<<(max(n,m)+1LL*ans*((mod+1)/2)%mod+mod)%mod;
	return 0;
}


Measured memory_bytes: 8064
s = input()
if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)

Measured memory_bytes: 3060
a, b, c, d = gets.split(' ').map(&:to_i)
a_to_b = (a-b).abs
b_to_c = (b-c).abs
a_to_c = (a-c).abs

if a_to_b <= d && b_to_c <= d then
  puts "Yes"
elsif a_to_c <= d then
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
// ************* Bismillahir Rahmanir Rahim **************

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

#define FORI(i, a, n) ;for(int i=a; i<=n; i++)
#define FORD(i, a, n) for(int i=a; i>=n; i--)
#define INFI 1e8
#define INFL 1e18
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define ff first
#define ss second
#define Dtemp int temp; cin>>temp;
#define N 100002

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;

// ******************########****************


int main()
{
    ll dp[N], h[N];
    int n;

    cin>>n;
    FORI(i, 1, n)
        cin>>h[i];

    dp[1] = 0;
    dp[2] = abs(h[1] - h[2]);
    FORI(i, 3, n)
    {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout<<dp[n]<<endl;

    return 0;
}



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

using namespace std;

const int N = 1234567;
const int mod = (int) 1e9 + 7;

int n, m;
int x[N], y[N];

int add(int a, int b) {
  int ret = a + b;
  if (ret >= mod) ret -= mod;
  return ret;
}

int mul(int a, int b) {
  return (long long) a * b % mod;
}

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", x + i);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", y + i);
  }
  int ans = 0;
  int sum_x = 0;
  for (int i = 0; i + 1 < n; i++) {
    int diff = x[i + 1] - x[i];
    int w = n - i - 1;
    sum_x = add(sum_x, mul(mul(w, i + 1), diff));
  }
  int sum_y = 0;
  for (int i = 0; i + 1 < m; i++) {
    int diff = y[i + 1] - y[i];
    int w = m - i - 1;
    sum_y = add(sum_y, mul(mul(w, i + 1), diff));
  }
  ans = mul(sum_x, sum_y);
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<algorithm>
using Int = long long;

int main() {

	Int A, B, C, D, E, F;

	std::cin >> A >> B >> C >> D >> E >> F;

	long double max_density = (long double)(E * 100) / (long double)(100 + E);
	long double ans_density = 0;
	Int ans_sum = 0;
	Int ans_sugar = 0;
	Int number_a = F / 100 / A;
	Int number_b = F / 100 / B;
	Int number_c = F / C;
	Int number_d = F / D;

	for (Int a = 0; a <= number_a; a++) {
		for(Int b=0;b<=number_b;b++){
			if (100 * A * a + 100 * B * b > 0) {
				for (Int c = 0; c <= number_c; c++) {
					for (Int d = 0; d <= number_d; d++) {
						long double sugar = C * c + D * d;
						long double sum = 100 * A * a + 100 * B * b + C * c + D * d;
						long double density = sugar*100 / sum;
						if (density >= ans_density && sum <= F) {
							if (density <= max_density) {
								ans_density = density;
								ans_sum = sum;
								ans_sugar = sugar;
							}
						}
					}
				}
			}
		}
	}

	std::cout << ans_sum <<" "<< ans_sugar << std::endl;

}

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

public class Main {

	public static void main(String[] args) {
		Stack<Integer>stack = new Stack<>();
        Scanner scan = new Scanner(System.in);
 
        String input = scan.nextLine();
        String[] S = input.split(" ");
        scan.close();
 
        for(int i = 0; i < S.length; i++) {
            if (S[i].equals("+")) {
                int x = stack.pop();
                int y = stack.pop();
                stack.push(y + x);
            }
            else if (S[i].equals("-")) {
                int x = stack.pop();
                int y = stack.pop();
                stack.push(y - x);
            }
            else if (S[i].equals("*")) {
                int x = stack.pop();
                int y = stack.pop();
                stack.push(x * y);
            }
            else {
                stack.push(Integer.parseInt(S[i]));
            }
        }
        System.out.println(stack.firstElement());
    }
}


Measured memory_bytes: 26188
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		if (Math.abs(a-x) > Math.abs(b-x)){
			System.out.println("B");
		}else {
			System.out.println("A");
		}
	}
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//~ const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
 
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};



int main(){
	int n, m; cin>> n >> m;
	n -=  1;
	m -= 1;
	cout<< n*(n+1)/2 + m*(m+1)/2;
    return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector<ll> r1, r2;
    if (n % 2 == 0)
    {
        r1.push_back(a[n / 2 - 1]);
        for (int i = 0, j = n - 1; i < n / 2 - 1; ++i, --j)
        {
            r1.push_back(a[j]);
            r1.push_back(a[i]);
        }
        r1.push_back(a[n / 2]);
        r2.push_back(a[n / 2]);
        for (int i = 0, j = n - 1; i < n / 2; ++i, --j)
        {
            r2.push_back(a[i]);
            r2.push_back(a[j]);
        }
        r2.push_back(a[n / 2 - 1]);
    }
    else
    {
        r1.push_back(a[n / 2]);
        for (int i = 0, j = n - 1; i < n / 2; ++i, --j)
        {
            r1.push_back(a[j]);
            r1.push_back(a[i]);
        }
        r2.push_back(a[n / 2]);
        for (int i = 0, j = n - 1; i < n / 2; ++i, --j)
        {
            r2.push_back(a[i]);
            r2.push_back(a[j]);
        }
    }
    ll s1 = 0, s2 = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        s1 += abs(r1[i] - r1[i + 1]);
        s2 += abs(r2[i] - r2[i + 1]);
    }
    cout << max(s1, s2);
    return 0;
}


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  if(k==1||k==2||k==3||k==5||k==7||k==11||k==13||k==15||k==17||k==19||k==23||k==29||k==31)
    cout<<1<<endl;
  else if(k==4||k==6||k==9||k==10||k==14||k==21||k==22||k==25||k==26)
    cout<<2<<endl;
  else if(k==12||k==8||k==18||k==20||k==27)
    cout<<5<<endl;
  else if(k==16)
    cout<<14<<endl;
  else if(k==24)
    cout<<15<<endl;
  else if(k==32)
    cout<<51<<endl;
  else
    cout<<4<<endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
int main() {
	int n;
	assert(scanf("%d", &n)==1);
	if((n&n-1)==0) {
		puts("No");
		return 0;
	}
	printf("Yes\n3 %d\n", n+1);
	for(int i=2; i<n; i+=2) printf("1 %d\n%d %d\n1 %d\n%d %d\n", i, i, i+1, n+i+1, n+i, n+i+1);
	if(n%2==0) printf("%d %d\n%d %d\n", n&-n, n, (n&n-1)+n+1, 2*n);
	return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>
int main(void)
{
	int A = 0, B = 0;
	scanf("%d%d", &A, &B);
	if (A <= 9)
	{
		if (B <= 9)
		{
			printf("%d\n", A*B);
		}
		else {
			printf("-1\n");
		}
	}
	else {
		printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 128
/**
 *    author:  tourist
 *    created: 02.06.2019 15:47:13       
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  const int inf = (int) 1e9;
  int ans = inf;
  for (int st = 0; st < n; st++) {
    vector<int> mn(n);
    vector<int> mx(n);
    vector<int> cnt(n);
    function<void(int, int)> dfs = [&](int v, int pr) {
      cnt[v] = (s[v] == '1');
      int max_min = -1;
      int max_max = -1;
      for (int u : g[v]) {
        if (u == pr) {
          continue;
        }
        dfs(u, v);
        cnt[v] += cnt[u];
        mx[v] += mx[u] + cnt[u];
        if (mn[u] + cnt[u] > max_min) {
          max_min = mn[u] + cnt[u];
          max_max = mx[u] + cnt[u];
        }
      }
      if (max_min > mx[v] - max_max) {
        mn[v] = max_min - (mx[v] - max_max);
      } else {
        mn[v] = mx[v] % 2;
      }
    };
    dfs(st, -1);
    debug(st, mn, mx);
    if (mn[st] == 0) {
      ans = min(ans, mx[st] / 2);
    }
  }
  cout << (ans == inf ? -1 : ans) << '\n';
  return 0;
}


Measured memory_bytes: 640
import math
import numpy as np
x1, y1, x2, y2 = map(int, input().split())
c1 = [x1, y1]
c2 = [x2, y2]
v = [x2-x1, y2-y1]
d = int(math.sqrt(v[0]*v[0] + v[1]*v[1]))
rotate_matrix = ([0, 1], [-1, 0])

v4 = np.dot(v, rotate_matrix)
v3 = [v4[0] + v[0], v4[1] - v[1]]

c4 = c1 + v4
c3 = c2 + v4

print(c3[0],c3[1],c4[0],c4[1])

Measured memory_bytes: 12504
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N;
    cin >> N;
    for (int i = N; i >= 1; i--) {
        if ((double) log2(i) - (int) log2(i) == 0) {
            cout << i << endl;
            return 0;
        }
    }
    cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define to_mod 1000000007
#define MAX_COLOR 200001


int main(){
    int n;
    cin >> n;
    vector<int> each_color[MAX_COLOR];
    int num_each_color[MAX_COLOR];
    int color_coll[n];
    int idx_each_color[n];
    ll comb_points[n];
    comb_points[0] = 1;
    for(int i = 0; i < MAX_COLOR; i++) num_each_color[i] = 0;
    for(int i = 0; i < n; i++){
        int inp_color;
        cin >> inp_color;
        color_coll[i] = inp_color;
        idx_each_color[i] = num_each_color[inp_color];
        num_each_color[inp_color]++;
        each_color[inp_color].push_back(i);
    }
    for(int i = 1; i < n; i++) {
        int lst_color = color_coll[i];
        int idx_in_color = idx_each_color[i];
        if (idx_in_color == 0) comb_points[i] = comb_points[i-1];
        else {
            int prev_idx_in_color = each_color[lst_color][idx_in_color - 1];
            int diff = each_color[lst_color][idx_in_color] - prev_idx_in_color;
            if (diff > 1) comb_points[i] = comb_points[prev_idx_in_color] + 
                comb_points[i-1];
            else comb_points[i] = comb_points[i-1];
        }
        comb_points[i] = (comb_points[i] + to_mod) % to_mod;
    }

    cout << comb_points[n-1] << endl;
    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
    //freopen("d.in","r",stdin);
	int n, cnt = 0;
	string s;
	while(cin >> n >> s) {
		//cout << s << endl;
		string ans, t;
		int len = s.length();
		rep(i,0,len) {
			if(s[i]=='(') {
				cnt++;
			} else {
				cnt--;
			}
			if(cnt < 0) ans = "(" + ans + ")", cnt = 0;
			else {
				t += s[i];
				if(cnt == 0) ans += t, t = "";
			}
			//ans += t;
			//t = "";
		//	cout << ans <<  endl;
		}
		//rep(i,0,cnt) ans += '(';
		ans += t;
		rep(i,0,cnt) ans += ')';
		cout << ans << endl;
	}
    return 0;
}


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

ans = 1
if 0 in A:
    print(0)
else:
    for i in range(n):
        if ans > 10 ** 9:
            if A[i] >= 10 ** 9:
                ans = -1
                break
            else:
                pass
        else:
            pass
        ans *= A[i]
        if ans > 10 ** 18:
            ans = -1
            break
        else:
            pass
    print(ans)

Measured memory_bytes: 21484
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int times = Integer.parseInt(sc.nextLine());
		while (0 < times) {
			int[] side = {1, 2, 3};
			int total = 1;
			for (int i = 0; i < times; i++) {
				char c = sc.nextLine().charAt(0);
				if ('N' == c) {
					int wk = side[0];
					side[0] = side[1];
					side[1] = 7 - wk;
				}
				if ('E' == c) {
					int wk = side[0];
					side[0] = 7 - side[2];
					side[2] = wk;
				}
				if ('W' == c) {
					int wk = side[0];
					side[0] = side[2];
					side[2] = 7 - wk;
				}
				if ('S' == c) {
					int wk = side[0];
					side[0] = 7 - side[1];
					side[1] = wk;
				}
				if ('R' == c) {
					int wk = side[1];
					side[1] = side[2];
					side[2] = 7 - wk;
				}
				if ('L' == c) {
					int wk = side[2];
					side[2] = side[1];
					side[1] = 7 - wk;
				}
				total += side[0];
			}
			System.out.println(total);
			times = Integer.parseInt(sc.nextLine());
		}
	}
}

Measured memory_bytes: 43000
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    long long int x;
    long long int a;
    long long int n;
    cin >> x;
    a = 100;
    n = 0;
    while (a < x)
    {
        n++;
        a = a * 1.01;
    }
    cout << n << endl;
    return 0;
}

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

int main () {
	int n, k;
	int x;
	cin >> n;
	cin >> k;
	int ans=0;
	for (int i=0; i<n; i++) {
		cin >> x;
		ans += min(x-0, k-x)*2;
	}
	cout << ans;
} 

Measured memory_bytes: 3584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class AEatingSymbolsEasy {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int res = 0;
            for (int i = 0; i < s.length(); i++) {
                res += s.charAt(i) == '+' ? 1 : -1;
            }
            out.println(res);
        }

    }
}



Measured memory_bytes: 23124
k, s = map(int, input().split())
ks = [_ for _ in range(k+1)]

count = 0

for ksk1 in ks:
    for ksk2 in ks:
        z = s - ksk1 - ksk2
        if 0 <= z <= k:
            count += 1
            
print(count)

Measured memory_bytes: 3060
import java.util.*

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }


fun main(args: Array<String>) {
    val (A, B,N) = readListLong()

    val x = if (N >= B-1) B-1 else N;

    val ans = A*x/B - A *(x/B)
    println(ans)
}


Measured memory_bytes: 36372
#include <iostream>

using namespace std;
#define MAX 2000000

template<typename T>
class MaxHeap
{
public:
	MaxHeap(int maxSize = MAX)
	{
		m_maxSize = maxSize;
		m_currentSize = 0;
		m_pArray = new T[m_maxSize];
	}

	virtual ~MaxHeap()
	{
		if (m_pArray) delete[] m_pArray;
		m_pArray = 0;
	}

	const T& Top() const
	{
		return m_pArray[0];
	}

	void Push(const T& data)
	{
		if (m_currentSize >= m_maxSize) throw("MaxHeap is full!");

		m_pArray[m_currentSize] = data;
		TrickleUp(m_currentSize++);
	}

	void Pop()
	{
		if (m_currentSize <= 0) return;

		m_pArray[0] = m_pArray[--m_currentSize];
		TrickleDown(0);
	}

private:
	/**
	 * 向上渗透
	 */
	void TrickleUp(int index)
	{
		if (0 == index) return;

		int parent = (index - 1) >> 1;
		if (m_pArray[index] <= m_pArray[parent]) return;
		//当前节点值大于父节点，与父节点交换
		T temp = m_pArray[parent];
		m_pArray[parent] = m_pArray[index];
		m_pArray[index] = temp;
		TrickleUp(parent);
	}

	void TrickleDown(int index)
	{
		if (index >= m_currentSize) return;

		int maxChild = -1;
		int leftChild = (index << 1) + 1;
		int rightChild = leftChild + 1;
		if (rightChild < m_currentSize)//双子节点
		{
			if (m_pArray[leftChild] > m_pArray[rightChild])
				maxChild = leftChild;
			else
				maxChild = rightChild;
		}
		else if (leftChild < m_currentSize)//只有左子节点
			maxChild = leftChild;
		else//无子节点
			return;

		if (m_pArray[index] >= m_pArray[maxChild]) return;
		//当前节点值小于子节点，与子节点交换
		T temp = m_pArray[maxChild];
		m_pArray[maxChild] = m_pArray[index];
		m_pArray[index] = temp;
		TrickleDown(maxChild);
	}

private:
	T* m_pArray;
	int m_maxSize;
	int m_currentSize;
};

int main()
{
	string cmd;
	int key;
	MaxHeap<int> heap;
	while (true)
	{
		cin >> cmd;
		if (0 == cmd.compare("insert"))
		{
			cin >> key;
			heap.Push(key);
		}
		else if (0 == cmd.compare("extract"))
		{
			cout << heap.Top() << endl;
			heap.Pop();
		}
		else if (0 == cmd.compare("end"))
			break;
	}

	return 0;
}


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

	using namespace std;
	inline void FAST_IO(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

	int main(){
		FAST_IO();

		string a;
		cin >> a;

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

		return 0;
	}

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


int main() {
  int N,M;
  cin>>N>>M;
  vector<int> p(N+1);
  for(int i=0;i<M;i++){
    int l,r;
    cin>>l>>r;
    l--;
    p.at(l)++,p.at(r)--;
  }
  int A=0,C=p.at(0);
  
  for(int i=0;i<N;i++){
    if(p.at(i)==M){
      A++;
    }
    p.at(i+1)+=p.at(i);
  }
cout<<A<<endl;
}

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

int main(){
    string s; cin>>s;
    string res;
    rep(i,s.size()){
        if(s[i]=='A'||s[i]=='Z')res.push_back(s[i]);
    }
    string ans,temp;
    rep(i,res.size()){
        temp.clear();
        for(int j=i; j<res.size();j++){
            if(temp.size()==0&&res[j]=='A')temp.push_back(res[j]);
            else{
                if(temp.back()=='A'&&res[j]=='Z')temp.push_back(res[j]);
                else if(temp.back()=='Z'&&res[j]=='A')temp.push_back(res[j]);
            }
        }
        if(temp.back()=='A')temp.pop_back();
        if(ans.size()<temp.size()&&temp.size()>1)ans=temp;
    }
    if(ans.empty())return puts("-1")*0;
    cout<<ans<<endl;
}

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

list_A = list(map(int,input().split()))
list_B = list(map(int,input().split()))
list_C = list(map(int,input().split()))

b_val = 0

for i in range(N):
    aaa = list_A[i]
    b_val += list_B[aaa-1]
    if i ==0:
        continue
    elif aaa == list_A[i-1]+1:
        b_val += list_C[list_A[i-1]-1]
print(b_val)




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

int main(){
  int H, W;
  cin >> H >> W;
  char moji[H][W];  // 入力領域の配列（H行W列)
  char mine[H][W];  // 出力領域の配列（H行W列)

  // 出力領域の配列の初期化
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      mine[i][j] = '0';
    }
  }

  // 文字列入力
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> moji[i][j];
    }
  }

  // 地雷だったら、周囲のマスの地雷の数をインクリメントする
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      // 地雷だったら
      if(moji[i][j] == '#'){
        // 周囲のマスの地雷の数をインクリメントする
        for(int k = i - 1; k <= i + 1; k++){
          if(k >= 0 && k < H){  // y軸が範囲内なら
            for(int l = j - 1; l <= j + 1; l++){
              if(l >= 0 && l < W){   // x軸が範囲内なら
                if(moji[k][l] == '.'){  // 周囲のマスが'.'なら
                  mine[k][l]++;         // mineの地雷の数をインクリメント
                }else{
                   mine[k][l] = '#';    // 周囲のマスが'#'ならmineに'#'を代入
                }
              }
            }
          }
        }
      }
    }
  }

  // 出力 
 for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << mine[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

// const int N = ;
long long n,m,x,j,i,k,ans,nr;
priority_queue<int> p;

int main() {
	ios_base::sync_with_stdio(false);
	cin>>n>>m;
	for (int i = 0; i < n; ++i)
	{
		cin>>x;
		p.push(x);
		ans+=x;
	}
	if(n==1)
	{
		nr=p.top();
		while(m>0 && nr>0)
		{nr/=2; m--;}
		ans=nr;
	}else 
	while(m>0)
	{
		nr=p.top();
		ans-=nr;
		p.pop();
		while(nr>=p.top())
		{
			m--;
			nr/=2;
			if(m==0)
				break;
		}
		p.push(nr);
		ans+=nr;	
	}
	cout<<ans;
}


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



int main() {
 int n; cin >> n;
 vector<int> v(n);
 for(int i =0; i < n; i++){
        cin >> v[i];
 }
 
 vector<int> dp(n);
 dp[0] = 0;
 dp[1] = abs(v[1]-v[0]);
 for(int i =2; i < n; i++){
  dp[i] = min(dp[i-2]+abs(v[i]-v[i-2]), dp[i-1] + abs(v[i]-v[i-1]));
 }
 
 cout <<  dp[n-1];
 
 
 
}








  

Measured memory_bytes: 1024
/*#define _USE_MATH_DEFINES
#include<cmath>*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}	

int main() {

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

	int k; cin >> k;
	int x; cin >> x;
	cout << (500 * k >= x ? "Yes" : "No") << "\n";

	return 0;
}


Measured memory_bytes: 256
def solve(K):
    K_one = K % 10
    cnt = 0

    carry = 0
    carry_one = carry % 10

    while True:
        is_ok = False
        for i in range(0,9+1):
            if (i * K_one + carry_one) % 10 == 7:
                is_ok = True
                cnt += 1
                carry = (K * i + carry) // 10
                carry_one = carry % 10
                break
        
        if not is_ok:
            print(-1)
            return
        
        if carry == 0:
            print(cnt)
            return

        carry_str = str(carry)
        if carry_str.count('7') == len(carry_str):
            print(len(carry_str) + cnt)
            return
    
if __name__ == '__main__':
    K = int(input())
    solve(K)

Measured memory_bytes: 73292
#include<stdio.h>

int main(void)
{
	int a,b,c;
	
	scanf( "%d%d%d",&a,&b,&c );
	int i,res;
	res=0;
	for( i=a; i<=b; i++) {	
		if( 0 == c%i ) {
			res++;
		}
	}
	printf( "%d\n", res);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



int main() {
	string S;
	cin >> S;
	int ans = 0;
	char c;
	// 文字の塊がいくつあるか
	while (!S.empty()) {
		c = S[0];
		S.erase(S.begin());
		while (S[0] == c && S.size() > 0) S.erase(S.begin());
		ans++;
	}
	cout << ans - 1 << endl;


	return 0;
}

Measured memory_bytes: 512
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io

	
	ll n;
	cin>>n;
	ll cnt=0;
	while(n)
	{
		ll z=n%10;
		n/=10;
		if(z==2)
			cnt++;
	}
	cout<<cnt;



}

Measured memory_bytes: 256
N = int(input())
a = [0] * N
b = [0] * N

for i in range(N):
  a[i], b[i] = map(int, input().split())
  
a.sort()
b.sort()

if N % 2 == 1:
  mid = N // 2
  print(b[mid] - a[mid] + 1)
else:
  mid1 = N // 2
  mid2 = mid1 - 1
  print(b[mid1] + b[mid2] - a[mid1] - a[mid2] + 1) 

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;




int main() {
	
	string s;
	cin >> s;
	if (s.size() % 2 == 1) {
		cout << "No" << endl;
	}
	else {

		bool b = true;

		REP(i, s.size()) {
			if (i % 2 == 0) {
				if (s[i] != 'h')b = false;
			}
			else {
				if (s[i] != 'i')b = false;
			}
		}

		if (b)cout << "Yes" << endl;
		else cout << "No" << endl;

	}




}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int r, g, b;
	cin >> r >> g >> b;
	if((r * 100 + g * 10 + b) % 4 == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

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

int main(void){
    string a,b;
    cin >> a >> b;
    if(a[0] == b[2]){
        if(a[1] == b[1]){
            if(a[2] == b[0])cout << "YES" << endl;
            else cout << "NO" << endl;
        } else cout << "NO" << endl;
    } else cout << "NO" << endl;
}

Measured memory_bytes: 256
V,E,r = map(int,input().split())
g=[]
for i in range(E):
    s,t,d= map(int,input().split()) 
    g.append([s,t,d])
inf= 1001001001
dd= [inf]*V

dd[r]=0 
for i in range(V-1):
    update=0 
    for s,t,d in g:
        if dd[t]> dd[s]+d and dd[s]!= inf:
            dd[t]= dd[s]+d
            update+=1
    if update==0: 
        break

update= False
for s,t,d in g:
    if dd[t]> dd[s]+d and dd[s]!=inf:
        update=True
        break

if update:
    print("NEGATIVE CYCLE")
else:
    for i in dd:
        if i==inf:
            print("INF")
        else:
            print(i)


Measured memory_bytes: 6124
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a, b, ans = 0;
    String op;
    for (int i = 0;; i++) {
      a = sc.nextInt();
      op = sc.next();
      b = sc.nextInt();
      if (op.equals("?")) {
        break;
      } else if (op.equals("+")) {
        ans = a + b;
      } else if (op.equals("-")) {
        ans = a - b;
      } else if (op.equals("*")) {
        ans = a * b;
      } else if (op.equals("/")) {
        ans = a / b;
      }
      System.out.printf("%d\n", ans);
    }
    sc.close();
  }
}



Measured memory_bytes: 26492
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

int main() {
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    auto point = [&](char hand) {
        if (hand == 'r') return p;
        if (hand == 's') return r;
        return s;
    };

    vector<bool> win(n);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (i - k >= 0 && t[i - k] == t[i] && win[i - k]) {
            win[i] = false;
        } else {
            ans += point(t[i]);
            win[i] = true;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int pasta[3];
	int juice[2];
	int i, j;
	int min;
	int cost;
	
	for (i = 0; i < 3; i++){
		scanf("%d", &pasta[i]);
	}
	for (i = 0; i < 2; i++){
		scanf("%d", &juice[i]);
	}
	
	min = 4000;
	
	for (i = 0; i < 3; i++){
		for (j = 0; j < 2; j++){
			cost = pasta[i] + juice[j] - 50;
			if (cost < min){
				min = cost;
			}
		}
	}
	
	printf("%d\n", min);

	return (0);
}

	

Measured memory_bytes: 592
N,M=map(int, input().split())
A=list(map(int, input().split()))
inf = float('inf')

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if i - number[j] >= 0:
      if dp[i-number[j]] +1 > dp_new:
        dp[i] = dp[i-number[j]] +1
        dp_new = dp[i]

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if N - number[j] >= 0:
      if dp[N] == dp[N-number[j]] + 1:
        ans += str(j)
        N -= number[j]
        break

print(int(ans))

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

int main() {
  int N,A,B,i,x,y;
  char p;
  cin >> N >> A >> B;
  x = A+B;
  y = B;
  for(i=0;i<N;i++) {
    cin >> p;
    if(p=='a') {
      if(x>=1) {
        cout << "Yes" << endl;
        x = x-1;
      }
      else  cout << "No" << endl;
    }
    if(p=='b') {
      if(x>=1 && y >= 1) {
        cout << "Yes" << endl;
        x = x-1;
        y = y-1;
      }
      else cout << "No" << endl;
    }
    if(p=='c') {
      cout << "No" << endl;
    }
  }
  return 0;
}     

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
long long n,m,tmp,a[100005],sum[100005],ans;
int main(){
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++){
    	scanf("%lld",&a[i]);
    	sum[i]=sum[i-1]+a[i];
    	sum[i]%=m;
	}
	sort(sum+1,sum+n+1);
	for(int i=1;i<=n;i++){
		if(sum[i]!=sum[i-1]){
			if(sum[i-1]==0)ans+=tmp*(tmp+1)/2;
			else ans+=tmp*(tmp-1)/2;
			tmp=1;
		}
		else tmp++;
	}
	if(sum[n]==0)ans+=tmp*(tmp+1)/2;
	else ans+=tmp*(tmp-1)/2;
	cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

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

	//string s; cin >> s;
	string t; cin >> t;

	ll ans = 0;
	rep(i,t.size()) { 
	 if (t[i] == '?') cout << 'D';
	 else cout << t[i];

	}
	cout << endl;
}


Measured memory_bytes: 3748
//shan61916
#include <bits/stdc++.h>
    using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n" 
typedef long long ll;
typedef unsigned long long ull ;
typedef double dll ;

int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b) ;
  return 0;
} //good night.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  int b;
  int h=0,l,t;
  vector<int> a;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>b;
    h=max(h,b);
    a.push_back(b);
  }
  l=0;
  while(h-l>1){
    int m=(h+l)/2;
    int c=0;
    for(int i=0;i<n;i++){
      c+=((a[i]-1)/m);
    }
    if(c<=k) h=m;
    else l=m;
  }
  cout<<h<<"\n";
}


Measured memory_bytes: 5308
import java.util.*;
public class Main{ 	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long res = 0;
		int[] arr = new int[n + 1];
		for(int i = 1; i <= n; i++) {
			arr[i] = sc.nextInt();
		}
		Map<Integer, Integer> map = new HashMap<>();
		map.put(1,0);
		int i = 1;
		int next = arr[1];
		int town = 0;
		while(i <= k) {
			town = next;
			next = arr[next];
			if(map.containsKey(town)) {
				int pre = map.get(town);
				k = (k - pre) % (i - pre);
				i = 1;
				break;
			}
			else {
				map.put(town, i);
				i++;
			}
		}
		while(i <= k) {
			town = next;
			next = arr[next];
			i++;
		}
		System.out.println(town);
    }
}

Measured memory_bytes: 67804
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int K = sc.nextInt();
	int[] x = new int[N];
	int[] tmp = new int[N];
	int sum = 0;

	for(int i=0; i<N; i++) {
		x[i] = sc.nextInt();
		tmp[i] = K - x[i];
		if(x[i] < tmp[i]) {
			tmp[i] = x[i];
		}
		sum += tmp[i];
	}

	System.out.println(2*sum);
	}
}

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

using namespace std;

int main(){
    int n, k, ans=0;
    cin >> n >> k;
    vector<int> vc;
    for(int i=0; i<n; i++){
        int p;
        cin >> p;
        vc.push_back(p);
    }

    sort(vc.begin(), vc.end());
    for(int i=0; i<k; i++){
        ans += vc[i];
    }

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


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,i,j,r,f[5010][5010],g[5010][5010],a[5010],ans;
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	f[0][0]=1;
	for(i=1;i<=n;i++)
	 for(j=0;j<=m;j++){
	  f[i][j]=f[i-1][j];
	  if(j>=a[i])f[i][j]|=f[i-1][j-a[i]];
  }
  g[n+1][0]=1;
  for(i=n;i;i--)
   for(j=0;j<=m;j++){
   	g[i][j]=g[i+1][j];
   	if(j>=a[i])g[i][j]|=g[i+1][j-a[i]];
   }
     for(i=1;i<=n;i++){
     	r=m;
     	for(j=0;j<=m;j++)if(f[i-1][j]){
     		while(!g[i+1][r]||j+r>=m)r--;
     		if(j+r+a[i]>=m){
     			//printf("%d\n",i);
     			ans++;break;
			 }
		 }
	 }
	printf("%d",n-ans);
}
/*
怎么做都可以吧 
*/

Measured memory_bytes: 196224
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define ull unsigned long long
#define ll long long
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}



int N;
string S1,S2;
ll dp[55][2];
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> N;
	cin >> S1;
	cin >> S2;
	S1 = " "+S1;
	S2 = " "+S2;
	for(int i=1;i<=N;++i){
		if(S1[i] != S1[i-1] && S1[i] != S2[i]) {
			dp[i][0] = 0;
			if(i==1){
				dp[i][1] = 6;
			}else{
				dp[i][1] = 2*dp[i-1][0] + 3*dp[i-1][1];
				dp[i][1] %= mod; 
			}
		}else if(S1[i] == S1[i-1] && S1[i]!=S2[i]){
			dp[i][0] = 0;
			dp[i][1] = dp[i-1][1];
		}else if(S1[i-1] != S2[i-1] && S1[i]==S2[i]){
			if(i==1){
				dp[i][0] = 3;
			}else{
				dp[i][0] = dp[i-1][1]%mod;
				dp[i][1] = 0;
			}
		}else{
			if(i==1){
				dp[i][0] = 3;
			}else{
				dp[i][0] = (2*dp[i-1][0])%mod;
				dp[i][1] = 0;
			}			
		}
	}
	cout << (dp[N][0]+dp[N][1])%mod << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

if __name__=='__main__':
  a = int(input())
  b = int(input())
  if a > b:
    a, b = b, a
  di = {(1, 2):3, (2, 3):1, (1, 3): 2}
  print(di[(a, b)])

Measured memory_bytes: 3060
#include<stdio.h>

int main(void){

int a=0;

int W,H,x,y,r=0;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(x-r>=0&&x+r<=W){

if(y-r>=0&&y+r<=H){ a=1; } }

else{ a=0; }

if(a==1){

printf("Yes\n"); }

else if(a==0){

printf("No\n"); }

return 0;

}

Measured memory_bytes: 584
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
using namespace std;
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;
}
int main() {
  int n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  int dp[n+k+1][3]={};
  
  rep(i,0,n){
    if(t[i]=='r'){
      dp[i+k][0]=max(dp[i][1],dp[i][2]);
      dp[i+k][1]=max(dp[i][0],dp[i][2]);
      dp[i+k][2]=max(dp[i][0],dp[i][1])+p;
    }
    if(t[i]=='s'){
      dp[i+k][0]=max(dp[i][1],dp[i][2])+r;
      dp[i+k][1]=max(dp[i][0],dp[i][2]);
      dp[i+k][2]=max(dp[i][0],dp[i][1]);
    }
    if(t[i]=='p'){
      dp[i+k][0]=max(dp[i][1],dp[i][2]);
      dp[i+k][1]=max(dp[i][0],dp[i][2])+s;
      dp[i+k][2]=max(dp[i][0],dp[i][1]);
    }
  }
  int ans = 0;
  for (int i = n; i < n + k; i++) {
    ans += max({dp[i][0],dp[i][1],dp[i][2]});
  }
  cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  if (n >= 2) ans += n * (n - 1) / 2;
  if (m >= 2) ans += m * (m - 1) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(x+r>w || x-r<0 || y+r>h || y-r<0){
		cout<<"No\n";
	}else{
		cout<<"Yes\n";
	}
	return 0;
}


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

using namespace std;

int main(){
    int n;
    int ans=0;
    cin >>n;
    int d[n];
    for(int i=0;i<n;i++){
        
        cin >> d[i];
    }

    for(int j=1;j<n;j++){
        for(int k=j;k<n;k++){
          
            ans = ans+d[j-1]*d[k];
        }
    }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <cstdio>

int d,s;

int main(){
	scanf("%d",&d);
	for(int i = 1; i <= d; i++){
		scanf("%d",&s);
		printf("Case %d:\n",i);
		for(int j = 0; j < 10; j++){
			int nxt = s*s;
			nxt %= 1000000;
			nxt /= 100;
			printf("%d\n",nxt);
			s = nxt;
		}
	}
	return 0;
}

Measured memory_bytes: 2664
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int X = sc.nextInt();
      
      // 計算
      int num500 = X / 500;
      int remain = X - 500 * num500;
      int num5 = remain / 5;
      int happy = num500 * 1000 + num5 * 5;
      
      // 出力
      System.out.println(happy);
    }
    
}

Measured memory_bytes: 21844