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


int main() {

  int N, K;
  cin >> N >> K;
  int sr, ss, sp;
  cin >> sr >> ss >> sp;
  string turn;
  cin >> turn;
  int score = 0;
  int cantwin =1;
  int cantr =1;
  int cants =1;
  int cantp =1;
  vector<vector<char>> veca(K);
  
  for(int i=1; i<N+1; i++){
    veca.at(i%K).push_back(turn.at(i-1)); 
  }
  
  for(int i=0;i<K; i++){
    for(int j =0; j<veca.at(i).size(); j++){
      if(veca.at(i).at(j)=='r' && j>0 && veca.at(i).at(j-1)=='r' && cantr==0){
         cantr = 1;
        
      }else if(veca.at(i).at(j)=='r' && cantr==1){
        cantr = 0;
        score += sp;
        cants = 1;
        cantp = 1;
          
    }else if(veca.at(i).at(j)=='s' && j>0 && veca.at(i).at(j-1)=='s'&& cants==0){
      cants=1;
      }else if(veca.at(i).at(j)=='s' && cants==1){
        cantr = 1;
        cants = 0;
        cantp = 1;
        score += sr;
        
      
    }else if(veca.at(i).at(j)=='p' && j>0 && veca.at(i).at(j-1)=='p'&& cantp==0){
     cantp =1; 
    }else if(veca.at(i).at(j)=='p' && cantp==1){
        cantp =0;
        cantr =1;
        cants =1;
        score += ss;
            }else if(veca.at(i).at(j)=='p' && j==0){
        score += ss;
        cantp =0;
        cantr =1;
        cants =1;
        }else if(veca.at(i).at(j)=='r' && j==0){
        score += sp;
        cantp =1;
        cantr =0;
        cants =1;
        }else if(veca.at(i).at(j)=='s' && j==0){
        score += sr;
        cantp =1;
        cantr =1;
        cants =0;
      }
    }
    }
  cout << score;
      for(int i=0; i<veca.at(0).size(); i++){
     //cout << veca[0][i]; 
    }
}


Measured memory_bytes: 5120
def main():
    mod=10**9+7
    s=int(input())
    dp=[0]*(s+1)
    for i in range(3,s+1):
        sm=1
        for j in range(i-3,2,-1):
            sm+=dp[j]
            sm%=mod
        dp[i]=sm
    print(dp[s])

main()

Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)


int main(){
  ll a,b,k;
  cin >> a >> b >> k;
  for(int i=a;i<a+k;i++){
    if(i<=b)cout << i << endl;
  }
  for(int i=b-k+1;i<=b;i++){
    if(i>=a+k)cout << i << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
pair<int,int> Array[55];
bool IsDone[55];

int Find_Ans( int p , int q , int index , int N ){
    int a , b , i , j , Count = 2;
    int Ans = 0;

    while( Count < N ){
        a = Array[index].first - p;
        b = Array[index].second - q;

        for( i = 1 ; i <= N ; ++i ){
            if( IsDone[i] == false && Array[i].first == a && Array[i].second == b ){
                IsDone[i] = true;
                index = i;
                ++Count;
                ++Ans;
                break;
            }
        }

        if( i == N + 1 ){
            for( i = 1 ; i <= N ; ++i ){
                if( IsDone[i] == true ) continue;
                for( j = 1 ; j <= N ; ++j ){
                    if( IsDone[j] == false ){
                        if( (Array[i].first - Array[j].first == p) && (Array[i].second - Array[j].second == q) ){
                            ++Ans;
                            break;
                        }
                    }
                }
            }

            break;
        }
    }

    return Ans;
}

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

    for( i = 1 ; i <= N ; ++i )
        scanf( "%d%d" , &Array[i].first , &Array[i].second );
    
    if( N == 1 ){
        puts( "1" );
        return 0;
    }

    int Ans = 0;
    int p , q;

    for( i = 1 ; i <= N ; ++i ){
        for( j = 1 ; j <= N ; ++j ){
            if( i == j ) continue;
            fill( IsDone , IsDone + N + 1 , false );
            IsDone[i] = IsDone[j] = true;
            p = Array[i].first - Array[j].first;
            q = Array[i].second - Array[j].second;
            Ans = max( Ans , 1 + Find_Ans( p , q , j , N ) );
        }
    }

    printf( "%d\n" , N - Ans );
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 200100

ll L[MAXN],R[MAXN], sum_left[MAXN], sum_right[MAXN];
ll len,N,ans;

int main(){
	cin>>len>>N;
	for (ll i=1;i<=N;++i){
		cin>>L[i];
		R[i] = len-L[i];
		sum_left[i] = sum_left[i-1] + L[i];
	}
	for (ll i=N;i>0;--i){
		sum_right[i] = sum_right[i+1] + R[i];
	}
	for (int k=0;k<2;++k){
		for (ll lend = 1;lend<N;++lend){
			ll lstart = 1;
			ll rstart = lend + 1;
			ll rend = N;
			ll offset = 0;
			ll dif = (rend - rstart) - (lend - lstart) + 1; // -1 if we ending on the right
			if (k)dif -= 2;
			if (dif > 0){
				rend -= dif;
				offset = R[rend+1];
			}else if (dif < 0){
				lstart -= dif;
				offset = L[lstart-1];
			}
			ll tot = 2*(sum_right[rstart]-sum_right[rend+1]+ sum_left[lend]-sum_left[lstart-1]);
			if (k == 0)tot -= L[lend];
			else tot -= R[rstart];
			if (dif > 0 && k == 0)tot = tot + offset*2;
			if (dif < 0 && k == 1)tot = tot + offset*2;

			ans = max(ans,tot);
		}
	}
	ans = max({ans, L[N], R[1]});
	cout<<ans;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      String string = scan.next();
      char[] c = new char[4];
      for(int i=0;i<4;i++){
        c[i] = string.charAt(i);
      }
      if(c[0]==c[3] && c[1]==c[2] && c[0]!=c[1]){
        System.out.println("Yes");
      }else if(c[0]==c[1] && c[2]==c[3] && c[0]!=c[2]){
        System.out.println("Yes");
      }else if(c[0]==c[2] && c[1]==c[3] && c[0]!=c[1]){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
      
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n;cin >> n;
	ll ans = 0;
	for(int i = 0;i <= n;i++){
		if(i % 3 == 0)continue;
		if(i % 5 == 0)continue;
		ans += i;
	}

	cout << ans << endl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  int ans = n * (n + 1) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] arg){
        Scanner sc=new Scanner(System.in);
        int H=sc.nextInt();
        int W=sc.nextInt();
        char[][] map=new char[H][W];
        int[][] result=new int[H][W];

        for(int i=0;i<H;i++){
            map[i]=sc.next().toCharArray();
            for(int j=0;j<W;j++){
                if(map[i][j]=='#'){
                    result[i][j]=0;
                }
                else{
                    result[i][j]=9999;
                }
            }
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(j!=0) {
                    if (result[i][j] > result[i][j - 1] + 1) {
                        result[i][j] = result[i][j - 1] + 1;
                    }
                }
                if(i!=0){
                    if(result[i][j]>result[i-1][j]+1){
                        result[i][j]=result[i-1][j]+1;
                    }
                }
            }
        }
        for(int i=H-1;i>=0;i--){
            for(int j=W-1;j>=0;j--){
                if(j!=W-1) {
                    if (result[i][j] > result[i][j + 1] + 1) {
                        result[i][j] = result[i][j + 1] + 1;
                    }
                }
                if(i!=H-1){
                    if(result[i][j]>result[i+1][j]+1){
                        result[i][j]=result[i+1][j]+1;
                    }
                }
            }
        }
        int result2=0;
        for(int i=0;i<H;i++) {
            for (int j = 0; j < W; j++) {
                if (result[i][j] > result2) {
                    result2=result[i][j];
                }
            }
        }

        System.out.println(result2);
    }
}


Measured memory_bytes: 38712
#include<stdio.h>
#include<math.h>
#include<string.h>
int main ()
{
	int n[60],t,i,j,a,b,c;
	for(i=0;i<3;i++)
		scanf("%d",&n[i]);
	for(i=0;i<3;i++)
		for(j=i+1;j<3;j++)
		{
			t=n[i]+n[j];
			if(n[i]>n[j])
			{
				n[i]=t-n[i];
				n[j]=t-n[i];
			}
		}
	a=n[0];
	b=n[1];
	c=n[2];
	if(b==c-1)
	{
		for(i=1;;i++)
		{
			a+=2;
			if(a>b)
				break;
		}
		if(a-2==b)
			printf("%d",i);
		else
			printf("%d",i+2);
	}
	else
	{
		t=c-b-1;
		a+=t;
		b+=t;
		for(i=1;;i++)
		{
			a+=2;
			if(a>b)
				break;
		}
		if(a-2==b)
			printf("%d",i+t);
		else
			printf("%d",i+2+t);
	}
	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

bool solve(vector<bool> &memo, vector<bool> &visited, ll x) {
    if (x < 0) {
        return false;
    }
    if (visited[x]) {
        return memo[x];
    }

    if (memo[x]) {
        return true;
    } else {
        bool temp = false;
        repd(i, 100, 106) { temp |= solve(memo, visited, x - i); }
        memo[x] = temp;
        visited[x] = true;
        return temp;
    }
}

int main() {
    ll x;
    cin >> x;

    vector<bool> memo(x + 1);
    vector<bool> visited(x + 1);
    visited[0] = true;
    memo[0] = true;

    cout << solve(memo, visited, x) << endl;

    return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (2147483647)
#define mod (1000000007)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)

void solve()
{
    int a;string s;cin>>a>>s;
    cout<<(a>=3200?s:"red")<<endl;
}

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

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    int r, d, x;
    cin >> r >> d >> x;

    int next = x;
    rep(i, 10) {
        next = r * next - d;
        cout << next << endl;
    }
    return 0;
}


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

int main(void){
	int N;
	ll D;
	cin >> N >> D;
	int ans = 0;
	rep(i,N) {
		ll x, y;
		cin >> x >> y;
		if(x*x+y*y<=D*D) ans++;
	}
	cout << ans << endl;
return 0;
}


Measured memory_bytes: 3568
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]

ab.sort()

cnt = 0
ans = 0
for a, b in ab:
    if cnt + b < m:
        cnt += b
        ans += b * a
    else:
        ans += (m - cnt) * a
        break
print(ans)

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 2e5 + 5;

int n;
int a[MAXN], b[MAXN];

ll calc(int x){
    ll ret = 0;
    REP(i, n)
        ret += abs(a[i] - (x + i + 1));
    return ret;
}

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

    cin >> n;
    REP(i, n){
        cin >> a[i];
        b[i] = a[i] - (i + 1);
    }

    sort(b, b + n);

    cout << min(calc(b[n / 2]), calc(b[n / 2 + 1]));
}


Measured memory_bytes: 1792
import math
def sol(inp=input):
    n,k=map(int,inp().split())
    res=0
    for dice_m1 in range(n):
        dice=dice_m1+1
        head=max(0,math.ceil(math.log(k/dice,2)))
        res+=2**-head
    res/=n
    return res
print(sol())


Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(long long i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(long long i = m; i <= n; i++)
#define FORR(i, m, n) for(long long i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


int main(){FIN

    ll n;cin>>n;
    string s;cin>>s;
    ll q;cin>>q;

    vector<set<int>> v(26);
    REP(i,n){
        v[s[i]-'a'].insert(i);
    }

    REP(i,q){
        int command;cin>>command;

        if(command==1){
            int b; char c; cin>>b>>c;
            b--;
            v[s[b]-'a'].erase(b);
            v[c-'a'].insert(b);
            s[b]=c;
        }

        else{
            ll l,r; cin>>l>>r; l--; r--;
            int count = 0;
            REP(j,26){
                auto it = v[j].lower_bound(l);
                if(it != v[j].end()){
                    if(*it<=r) count++;
                }
            }
            cout<<count<<endl;
        }

    }

    return 0;
}

Measured memory_bytes: 24220
d = int(input())
c = [0] + list(map(int, input().split()))
s = [0] + list([0] + list(map(int, input().split())) for _ in range(d))

kaisai = [0]*27

for i in range(1, d+1):
    decrese = 0
    zantei = [0]*27
    for k in range(1, 26):
        zantei[k] = s[i][k] + c[k]*(i - kaisai[k])
    increase = max(zantei)
    index = zantei.index(increase)

    kaisai[index] = i
    print(index)
    

Measured memory_bytes: 9224
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

t = [0]*(n+1)

for _ in range(m):
    a, b = inintm()
    if a == 1:
        if t[b] == 1:
            print("POSSIBLE")
            exit()
        t[b] = 1
    elif b == n:
        if t[a] == 1:
            print("POSSIBLE")
            exit()
        t[a] = 1

print("IMPOSSIBLE")


Measured memory_bytes: 75360
a,b=map(int, input().split())
c=[0]*a
d=[0]*a
e=0
for i in range(b):
    p, s=input().split()
    p=int(p)-1
    if c[p]==0 and s=='AC':
        c[p]=1
        e+=d[p]
    d[p]+=1
print(sum(c),e)

Measured memory_bytes: 51544
from collections import deque
n = int(input())
L = deque()

for i in range(n):
    cmdline = input().split()

    if cmdline[0] == "insert":
        L.appendleft(cmdline[1])
    elif cmdline[0] == "delete":
        try:
            L.remove(cmdline[1])
        except ValueError: pass
    elif cmdline[0] == "deleteFirst":
        L.popleft()
    elif cmdline[0] == "deleteLast":
        L.pop()

print(" ".join(L))

Measured memory_bytes: 71896
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;


int main()
{
	int n,k;
	cin >> n >> k;
	long long ans = 0;

	vector<long long>v;

	for (int i = 0; i < n; i++) {
		long long vi;
		cin >> vi;
		v.push_back(vi);
	}

	for (int i = 0; i <= min(k,n); i++) {
		
		for (int r = 0; r <= i; r++) {
			long long s = 0;
			int l = i - r;
			vector<long long> mean;

			for (int num = 0; num < l; num++) {
				mean.push_back(v[num]);
			}
			for (int num = 0; num < r; num++) {
				mean.push_back(v[n - num -1]);
			}

			sort(mean.begin(), mean.end());
			int count = k - i;
			for (int num = 0; num < i; num++) {
				if (mean[num] < 0 && count> 0) {
					count--;
					
				}
				else {
					s = s + mean[num];
				}
			}
			ans = max(ans, s);

		}

	}


	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
let n = read_int ()
let cs = Array.make n 0
let f n = Printf.printf "%d\n" n; exit 0
let ( * ) a b = a * b mod 1000000007
let rec g b n = if n <= 0 then 1 else let p = g b (n / 2) in p * p * if n mod 2 = 0 then 1 else b
let _ = for _ = 1 to n do Scanf.scanf " %d" @@ fun a -> if n mod 2 = a mod 2 then f 0; cs.(a) <- cs.(a) + 1 done; if cs.(0) <> n mod 2 then f 0; for i = 1 to n / 2 do if cs.(2 * i - (1 - n mod 2)) <> 2 then f 0 done; Printf.printf "%d\n" @@ g 2 (n / 2)

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

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> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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(0);
	ios::sync_with_stdio(false);
    int N, K;
    string S;
    cin >> N >> S >> K;

    char change_char = S[K - 1];
    string rsl = "";
    rep(i, 0, N) {
        if(S[i] != change_char) rsl += '*';
        else rsl += S[i];
    }

    cout << rsl << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>                
using namespace std;
int N, A[2][105];
int i, j, sum, answer = INT_MIN; 

int main(void){
	cin >> N;
	for(i = 0; i < 2; i++){
		for(j = 0; j < N; j++){
			cin >> A[i][j];
		}
	}

  for(i = 0; i < N; i++){
		sum = 0;
		for(j = 0; j < N; j++){
			if(j == i) sum += A[0][j] + A[1][j];
			else if(j >= i) sum += A[1][j]; 
			else sum += A[0][j];
    }
		answer = max(answer, sum);
  }
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,i,p[100010],ans=0;
  cin >> n;
  for (i=0;i<n;i++) cin >> p[i];
  for (i=0;i<n-1;i++) if (p[i]==i+1){
    swap(p[i],p[i+1]);
    ans++;
  }
  if (p[n-1]==n) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
N = int(input())
A = [int(i) for i in input().split()]
counter = 0
for i in range(N):
    minj = i
    for j in range(i+1, N):
        if A[j] < A[minj]:
            minj = j
    if minj != i:
        A[i], A[minj] = A[minj], A[i]
        counter += 1
    
print(' '.join([str(i) for i in A]))
print(counter)


Measured memory_bytes: 5608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int cardCount = sc.nextInt();
        int gateCount = sc.nextInt();
        int min = -1;
        int max = 1000000;
        
        while (gateCount-- > 0) {
            int nowMin = sc.nextInt();
            int nowMax = sc.nextInt();
            min = Math.max(min, nowMin);
            max = Math.min(max, nowMax);
        }
        
        if (min > max) {
            System.out.println(0);
        } else {
            System.out.println(max - min + 1);
        }
        
    }
}


Measured memory_bytes: 64008
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
	int i,k,p[3],j[2];
	for(i = 0;i < 3;i++) scanf("%d",&p[i]);
	for(i = 0;i < 2;i++) scanf("%d",&j[i]);
	sort(p,p + 3);
	sort(j,j + 2);
	printf("%d\n",p[0] + j[0] - 50);
	return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

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

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {

  ll N;
  cin>>N;
  FOR(i,1,3500){
    FOR(j,1,3500){
      if((4*i*j-N*i-N*j)>=1){
        ll bunbo=4*i*j-N*i-N*j;
        ll bunsi=N*i*j;
        if(bunsi%bunbo==0){
          cout<<i<<" "<<j<<" "<<(bunsi/bunbo)<<endl;
          return 0;
        }

      }
    }
  }

  return 0;
}
 


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define MAX 112345
using namespace std;

long long pos[MAX];

int main(){
    long long n, k, a, b, actual = 0;
    cin >> n >> k;
    for(long long i = 0; i < n; i++){
        cin >> a >> b;
        pos[a] += b;
    }

    for(long long i = 1; i <= 100000; i++){
        actual += pos[i];
        if(k <= actual){
            cout << i << endl;
            i = MAX;
        }
    }


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int A,B;
	cin>>A>>B;
	int k=max({A+B,A-B,A*B});
ce(k)

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>

typedef long long ll;

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

int main() {
	int n, m;
	std::string s1, s2;
	std::cin >> n >> m;
	std::cin >> s1 >> s2;
	int gcd = gcd_(n, m);
	ll ans =  1ll * n * m / gcd;
	int adn = n / gcd, adm = m / gcd;
	for(int i = 1, j = 1; i <= n && j <= m; i += adn, j += adm) {
		if(s1[i - 1] != s2[j - 1]) 
			ans = -1;
	}
	std::cout << ans << '\n';
	return 0;
}


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

using namespace std;

int main(void){
	int a,b;
	int num[2][1001];
	memset(num,0,sizeof(num));
	int i=0;
	string str;
	while(getline(cin,str)){
		if(i>=2)break;
		if(str.size()==0){
			i++;
			continue;
		}
		stringstream ss(str);
		ss >> a;
		num[i][a]++;
	}
	for(a=0;a<=1000;a++){
		if(num[0][a]>0 && num[1][a]>0)printf("%d %d\n",a,num[0][a]+num[1][a]);
	}
	return 0;
}

Measured memory_bytes: 1232
using System;
using System.Linq;
 
namespace arc082_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            bool flag = false;
            for (int i = 0; i < n; i++)
            {
                if (x[i] == i + 1)
                {
                    if (!flag)
                    {
                        ret++;
                    }
                    flag = !flag;
                }
                else if (flag) flag = false;
            }
            Console.WriteLine(ret);
        }
    }
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < n; i++)
			list.add(sc.nextInt());
		
		Collections.sort(list);
		
		int res = Integer.MAX_VALUE  - 10000;
		for(int i = 0; i + k - 1 < n; i++) {
			int a = list.get(i);
			int b = list.get(i + k - 1);
			int abs = Math.abs(a - b);
			res = Math.min(res, abs);
		}
		out.println(res);
		
		out.close();
	}
	
static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}




Measured memory_bytes: 26620
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        a: usize,
        b: usize,
    }
 
    let astr: &str = &a.to_string();
    let bstr: &str = &b.to_string();

    let c: &str;
    let len: usize;
    if astr > bstr {  
        c = bstr; 
        len = a;     
    } else  {
        c = astr;
        len = b;
    }

    let mut s = String::from("");
    for _ in 0..len {
        s.push_str(c);
    }

    return s;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)(r); i++)
ll tar = 1e9;

int main(){
    ll x,n; cin >> x >> n;
    set<ll> s; rep(i,0,110) s.insert(i);
    vector<ll> p(n);
    rep(i,0,n) {
        cin >> p[i];
        s.erase(p[i]);
    }
    int ans = 1111;
    for(auto &it: s){
        if(tar > abs(x-it)){
            tar = abs(x-it);
            ans = it;
        }
    }
    cout << ans << endl;
}

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

std::vector<std::list<std::pair<int, int>>> edge;
std::vector<int> color;
std::vector<bool> visited;

void rc(int, int);

int main()
{
	int N;
	scanf("%d", &N);
	edge.resize(N);

	for (int i{}; i < N - 1; i++)
	{
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		u--; v--;
		edge[u].push_back({v, w % 2});
		edge[v].push_back({u, w % 2});
	}

	color.resize(N);
	visited.resize(N);
	rc(0, 0);
	for (auto& e: color) printf("%d\n", e);

	return 0;
}

void rc(int index, int c)
{
	if (visited[index]) return;
	visited[index] = true;
	color[index] = c;
	for (auto& e: edge[index])
		rc(e.first, (e.second + c) % 2);
}

Measured memory_bytes: 9600
fun main(args: Array<String>) {
    // 与えられた入力をスペースで区切った配列にする
    val inputs = readLine()!!.split(" ").map(String::toInt)
    // 1つめを取得
    val H = inputs[0]
    // 2つめを取得
    val A = inputs[1]

    if (H % A == 0) {
        print(H / A)
    } else {
        print((H / A) + 1)
    }
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
vector<int> A,B,C;

int main()
{
	scanf("%d",&N);
	A.assign(N,0);
	B.assign(N,0);
	C.assign(N,0);
	FOR(i,0,N){
		scanf("%d",&A [i]);
	}
	FOR(i,0,N){
		scanf("%d",&B [i]);
	}
	FOR(i,0,N){
		scanf("%d",&C [i]);
	}
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());

	vector<ll> v(N);
	for(int i = N - 1;i >= 0;i--){
		v [i] = C.end() - upper_bound(C.begin(),C.end(),B [i]);
		if(i + 1 < N){
			v [i] += v [i + 1];
		}
	}
	ll ans = 0;
	FOR(i,0,N){
		int idx = upper_bound(B.begin(),B.end(),A [i]) - B.begin();
		ans += v [idx];
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
int main()
{
    int n;
    int i, a, b, c;

    a = b = c = 0;
    for (i = 0; i < 10; i++){
        scanf("%d", &n);
        if (n >= a){c = b; b = a; a = n;}
        else if (n >= b){c = b; b = n;}
        else if (n > c)c = n;
    }
    printf("%d\n%d\n%d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];

    ll lack = 0;
    int lacknum = 0;
    for(int i = 0; i < n; i++){
        if(b[i]-a[i] > 0){
            lack += b[i]-a[i];
            lacknum++;
        }
    }

    vector<int> surplus;
    for(int i = 0; i < n; i++){
        if(a[i]-b[i] > 0) surplus.push_back(a[i]-b[i]);
    }
    sort(surplus.begin(), surplus.end(), greater<int>());

    if(lack == 0){
        cout << 0 << endl;
    }else{
        ll sum = 0;
        int ans = 0;
        for(; ans < surplus.size();){
            sum += surplus[ans++];
            if(sum >= lack) break;
        }

        if(sum >= lack) cout << ans+lacknum << endl;
        else cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  ll n;
  cin>>n;
  vector<ll> d(n);
  for(ll i=0;i<n;i++){
    cin>>d[i];
  }
  sort(d.begin(),d.end());
  ll ans=d[n/2]-d[n/2-1];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
apple_num, taste = map(int, input().split())
total = 0
table = []
total_ans = 0
manual = 100000000
ans = 0
for i in range(apple_num):
    table.append(i+1)

for j in range(apple_num):
    table[j] = taste + j
    total += taste + j

for k in range(apple_num):
    if manual > abs(table[k]):
        manual = abs(table[k])
        ans = k
for l in range(apple_num):
    if l == ans:
        continue
    else:
        total_ans += table[l]
print(total_ans)

Measured memory_bytes: 9124
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <functional>

using namespace std;

#define F first
#define S second
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << ": "; for (auto& xxxx: a) cerr << xxxx << " "; cerr << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))
#define equal equalll
#define less lesss

typedef double dbl;
typedef long long ll;
const int N = -1;
const int INF = 1.01e9;
typedef vector<int> vi;



int main() {
#ifdef HOME 
    assert(freopen("in", "r", stdin));
#endif
    string s;
    cin >> s;
    int n = s.size();
    vector<int> pos;
    for (int shift = 0; shift < 3; shift++) {
        for (int i = 0; shift + i * 3 < n; i++) {
            pos.pb(shift + i * 3);        
        }
    }
    map<char,int> q;
    for (auto ch: s) {
        q[ch]++;
    }
    vector<pair<int,char>> b;
    for (auto x: q) {
        b.pb({x.S, x.F});
    }
    sort(all(b));
    reverse(all(b));

    int cur = 0;
    string answer(n, '0');
    for (auto x: b) {
        for (int i = 0; i < x.F; i++) {
            answer[pos[cur]] = x.S;
            cur++;
        }
    }


    bool ok = 1;

    for (int i = 0; i < n - 1; i++) {
        if (answer[i] == answer[i + 1]) {
            ok = 0;
        }
        if (i + 2 < n && answer[i] == answer[i + 2]) {
            ok = 0;
        }
    }

    if (ok) {
        puts("YES");
    }
    else {
        puts("NO");
    }
        











    
#ifdef HOME 
    epr("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
    return 0;
}


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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    char s ='a' - 'A';
    a[0] -= s;
    b[0] -= s;
    c[0] -= s;


    cout << a[0] << b[0] << c[0] << endl;
    return 0;
}




Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;



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

	cin >> N;
	long long int cnt = 1;
	long long int ans = 0;
	while (1) {
		if (cnt == 10000000)break;
		long long int num = N - cnt;
		if (num <= 0)break;
		if (num%cnt) {
			cnt++;
			continue;
		}
		num /= cnt;
		if(num>cnt){
			ans += num;
		}
		cnt++;
	//	cout << cnt << endl;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n;
  LL k;
  cin >> n >> k;

  vector<int> perm(n + 1);
  for (int i = 1; i < n + 1; i++) {
    cin >> perm[i];
  }

  vector<bool> vis(n + 1);
  vector<int> dist(n + 1);
  LL cycle_size = 1;
  int v = 1;
  LL d = 1;
  vis[1] = true;

  while (!vis[perm[v]]) {
    vis[perm[v]] = true;
    dist[perm[v]] = d;
    v = perm[v];
    d++;
    cycle_size++;
  }

  LL tail = dist[perm[v]];

  cycle_size -= tail;

  if (k > tail) {
    k = tail + (k - tail) % cycle_size;
  }

  v = 1;
  for (int i = 0; i < k; i++) {
    v = perm[v];
  }

  cout << v << "\n";
}

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

bool taro(ll);
bool jiro(ll);

vector<ll> v;
unordered_map<ll,ll> t,j;

bool jiro(ll k){
	if(j.find(k)!=j.end())
		return j[k];
	bool ans=1;
	for(ll d:v){
		if(k-d>=0 && !taro(k-d)){
			ans=0;
			break;
		}
	}
	j[k]=ans;
	return j[k];
}

bool taro(ll k){
	if(t.find(k)!=t.end())
		return t[k];
	bool ans=0;
	for(ll d:v){
		if(k-d>=0 && jiro(k-d)){
			ans=1;
			break;
		}
	}
	t[k]=ans;
	return t[k];
}

int main(){
 ll n,k;
 cin>>n>>k;
 
 for(ll i=0;i<n;i++){
 	ll d;
 	cin>>d;
 	v.push_back(d);
 }
 if(taro(k)){
 	cout<<"First"<<endl;
 }
 else{
 	cout<<"Second"<<endl;
 }
 
 return 0;
}



Measured memory_bytes: 15960
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k==x:
        ans+=1
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


#define ll long long
#define FOR(i,a) for(ll i=0;i<(ll)a.size();i++)
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll inf=1e9;
const ll maxn=405;
const ll maxm=1e5+500;



bitset<maxn> hazf;
ll dp[maxn];
ll s[maxm];
ll t[maxm];
bitset<maxn> res0;
bitset<maxn> im[maxn];

void hesab_hazf(ll n,ll m){
	for(ll i=0;i<n;i++){
		im[i][i]=1;
	}
	for(ll i=m-1;i>=0;i--){
		ll v=s[i];
		ll u=t[i];
		hazf|=(im[u]&im[v]);
		im[u]|=im[v];
		im[v]|=im[u];
	}
}
bitset<maxn> mi[maxn];


int main(){
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<n;i++){
		mi[i][i]=1;
	}
	for(ll i=0;i<m;i++){
		ll v,u;
		cin>>v>>u;
		v--;u--;
		s[i]=v;
		t[i]=u;
		mi[u]|=mi[v];
		mi[v]|=mi[u];
	}
	hesab_hazf(n,m);
	ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			if( !hazf[i] && !hazf[j] && res0==(mi[i]&mi[j])){
				ans++;
			}
		}
	}
	cout<<ans;
}













Measured memory_bytes: 1920
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

    if(s=="Sunny"){
      cout<<"Cloudy"<<endl;
    }else if(s=="Rainy"){
      cout<<"Sunny"<<endl;
    }else{
      cout<<"Rainy"<<endl;
    }
}



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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll x, a, b;
    cin >> x >> a >> b;
    if ((-1)*a + b <= 0) {
        MSG("delicious")
    } else if ((-1)*a + b <= x) {
        MSG("safe")
    } else {
        MSG("dangerous")
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2010;
ll a[N];
ll dp[N];
int main() {
	int n;
	ll x;
	cin >> n >> x;
	for (int i=0;i<n;i++) cin >> a[i];
	ll ans = 0;
	for (int i=0;i<n;i++) {
		ans += a[i];
		dp[i] = a[i];
	}
	for (int i=1;i<n;i++) {
		ll sum = 0;
		for (int j=0;j<n;j++) {
			dp[j] = min(dp[j],a[(j-i+n)%n]);
			sum += dp[j];
		}
		ans = min(sum+x*i,ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
count = 0
soFar = 0
for i in range(1, n):
    first = list(set(s[:i]))
    second = list(set(s[i:]))
    for j in range(len(first)):
        if first[j] in second:
            count += 1
    soFar = max(soFar, count)
    count = 0
print(soFar)


Measured memory_bytes: 3060
#include <iostream>
#include <string>

bool isPalindrome(const std::string &s) {
    std::string rev(s.rbegin(), s.rend());
    return rev == s;
}

int main(int argc, char **argv) {
    int L;
    std::cin >> L;

    double a = L / 3.0;

    printf("%.12f", (a * a * a));
    return 0;
}


Measured memory_bytes: 256