akhauriyash/Code-Regression huggingface dataset:
# -*- coding:utf-8 -*-

if __name__ == '__main__':
    A = list(map(int, input().split()))
    min_costs = 99999
    for i in range(len(A)):
        if i+1 >= 3:
            j = abs(3 - (i+1))
        else:
            j = i+1
        if i+2 >= 3:
            k = abs(3 - (i+2))
        else:
            k = i+2
        costs = abs(A[j] - A[i]) + abs(A[k] - A[i])
        if costs < min_costs:
            min_costs = costs
    print(min_costs)


Measured memory_bytes: 3188
/// You just can't beat the person who never gives up
/// ICPC next year

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

long long d ,t ,s ;
bool Never_give_up(){
    cin >> d >> t >> s ;
    puts(s*t>=d ? "Yes" : "No");
    return 0;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" ,"r" ,stdin);
    freopen("output.txt" ,"w" ,stdout);
#endif
    //std::ios::sync_with_stdio(0);
    //cin.tie(0) ,cout.tie(0);
    int t = 1 ;
    //scanf("%d",&t);
    while(t--){
        Never_give_up();
    }
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

#define MAX 100000

int partition(int [MAX],int,int);

int main(){
  int i,n,q,A[MAX];

  scanf("%d",&n);

  for(i=0; i<n; i++)
    scanf("%d",&A[i]);

  q = partition(A,0,n-1);

  for(i=0; i<n; i++)
    if(i < n-1 && i != q) printf("%d ",A[i]);
    else if(i < n-1 && i == q) printf("[%d] ",A[i]);
    else if(i == n-1) printf("%d\n",A[i]);

  return 0;
}

int partition(int A[MAX],int p,int r){
  int i,j,x,tmp,tmp2;
  x = A[r];
  i = p - 1;
  for(j=p; j<r; j++)
    if(A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  tmp2 = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp2;

  return i+1;
}
  



Measured memory_bytes: 2104
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


double d;
ll a,b,c;

int main(){
	while(cin>>a>>b>>c){
		int res=0;
		rep(i,c){
			a=10*(a%b);
			res+=a/b;
			//cout<<i+1<<" "<<a/b<<endl;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#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; // 割り切る整数がない場合、素数である
}

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;
  ll Norg=N;
  ll ans=0;
  ll flag=1;
  if(N<10)ans++;
  if(N<10)flag=0;
  while(N>=10){
    if(N%10!=9)flag=0;
    N=N/10;
    ans=ans+9;
  }
  ans=ans+N-1+flag;


  cout <<ans<<endl;

  return 0;
}
 


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

int main()
{
  int n,alc=0,bob=0;
  cin>>n;
  vector<int> v(n);
  for(int &i:v) cin>>i;
  sort(v.rbegin(),v.rend());
  for(int i=0;i<n;i++)
    if(i%2==0)
      alc+=v[i];
     else
       bob+=v[i];
  cout<<alc-bob<<"\n";
  
  
  
  return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop

INF = float('inf')

"""
class UnWeightedEdge:
    def __init__(self, src, to):
        self.src = src
        self.to = to
"""

class WeightedEdge():
    def __init__(self, src, to, cost):
        self.src = src
        self.to = to
        self.cost = cost

def Dijkstra(G, s):
    dist = [INF] * len(G)
    dist[s] = 0
    pq = []
    heappush(pq, (0, s))
    while len(pq) != 0:
        top = heappop(pq)
        cost = top[0]
        v = top[1]
        if dist[v] < cost:
            continue
        for edge in G[v]:
            next_cost = cost + edge.cost
            if dist[edge.to] <= next_cost:
                continue
            dist[edge.to] = next_cost
            heappush(pq, (next_cost, edge.to))
    return dist

if __name__ == "__main__":
    """
    入力
    V E r (V:=頂点の数, E:=辺の数, r:=始点のインデックス)
    src0 to0 cost0
    src1 to1 cost1
    .
    .
    srcE-1 toE-1 costE-1
    """
    V, E, r = map(int, input().split())
    G = [[] for i in range(V)]
    for i in range(E):
        src, to, cost = map(int, input().split())
        G[src].append(WeightedEdge(src, to, cost))
    dist = Dijkstra(G, r)
    for i in range(V):
        if dist[i] == INF:
            print("INF")
        else:
            print(dist[i])


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

int main() {

  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;  
  
  int dx = 0;
  int dy = 0;

  if (x2 == x1) {
    dx = y2 - y1;
    cout << x2 - dx << " " << y2 << " " << x1 - dx << " " << y1 << endl;
  } else if (y2 == y1) {
    dy = x2 - x1;
    cout << x2 << " " << y2 + dy << " " << x1 << " " << y1 + dy << endl;
  } else {
    dx = y2 - y1;
    dy = x2 - x1;
    cout << x2 - dx << " " << y2 + dy << " " << x1 - dx << " " << y1 + dy << endl;
  }

}

Measured memory_bytes: 256
N,M = list(map(int,input().strip().split()))

K = N//2
ans = []

if N == 3:
    ans = [(1,2)]
elif N == 4:
    ans = [(1,2)]
elif N == 5:
    ans = [(1,2),(3,5)]
else:
    left = 1
    right = K
    while left<right:
        ans += [(left,right)]
        left+=1
        right-=1

    left = K+1
    right = N
    if (right-left)%2 == (K-1)%2:
        right -= 1
    while left<right:
        ans += [(left,right)]
        left += 1
        right -= 1

for i in range(M):
    print(ans[i][0],ans[i][1])


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

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

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

    cin>>a>>b>>c;
    if(b-a==c-b)
        cout<<"YES";
    else
        cout<<"NO";
}




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

int main()
{
    long long N, M, answer;
    cin >> N >> M;
    if(N > M){
        int temp = N;
        N = M;
        M = temp;
    }

    if(N == 1){
        if(M == 1)
            answer = 1;
        else
            answer = M - 2;
    }
    else{
        answer = (N-2) * (M-2);
    }
    cout << answer << endl;
}


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

using namespace std;

int main() {
	string W;
	cin >> W;
	string T;
	int num = 0;
	while(true){
		cin >> T;
		if(T == "END_OF_TEXT") break;
		transform(T.begin(), T.end(), T.begin(), ::tolower);
		if(T == W) ++num;
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>

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


Measured memory_bytes: 1992
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		List<String> s = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			s.add(sc.next());
		}

		sc.close();

		List<String> s2 = new ArrayList<>();
		for (String x : s) {
			char[] c = x.toCharArray();
			Arrays.sort(c);
			s2.add(new String(c));
		}

		s2.sort(Comparator.naturalOrder());

		long ans = 0;
		Map<String, Long> m = s2.stream().collect(Collectors.groupingBy(a -> a, Collectors.counting()));

		for (Long n : m.values()) {
			ans += f(n);
		}

		out.println(ans);

	}

	private long f(long x) {
		long ans = 0;
		for (int i = 0; i <= x - 1; i++) {
			ans += i;
		}
		return ans;
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 64432
#include<bits/stdc++.h>
using namespace std;
int main(){
char ch[3];
cin>>ch;
if(ch[0]=='R'&&ch[1]=='R'&&ch[2]=='R')
    cout<<3;
else if((ch[0]=='R'&&ch[1]=='R')||ch[1]=='R'&&ch[2]=='R')
    cout<<2;
else if(ch[0]=='R'||ch[1]=='R'||ch[2]=='R')
    cout<<1;
else
    cout<<0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  int q; cin >> q;
  int t, ans = 0;
  for (int i = 0; i < q; i++) {
    cin >> t;

    // binary search
    int left = 0, right = n, mid = n/2;
    bool found = false;
    while (left < right) {
      if (S[mid] < t) {
        left = mid+1;
      } else if (t < S[mid]) {
        right = mid;
      } else {
        found = true;
        break;
      }
      mid = (right+left)/2;
    }
    if (found) ans++;
  }
  cout << ans << endl;
}




Measured memory_bytes: 3104
#include <stdio.h>
#define MAX 100000

int p(int A[],int a,int b);


int main(){
  int i,A[MAX],n,m;;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);

  m=p(A,0,n-1);

  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    if(m==i) printf("[");
    printf("%d",A[i]);
    if(m==i) printf("]");
  }
  printf("\n");

  return 0;
}

int p(int A[],int a,int b){
  int x,i,j,t;
  x=A[b];
  i=a-1;
  for(j=a;j<b;j++){
    if(A[j]<=x){
      i=i+1;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[b];
  A[b]=t;
   return i+1;
}
  
      



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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

char bits[111111];
LL primes[10000], n_primes; 

void sieve(){
	int i, j;
	memset(bits, 1, 111111);
	bits[0] = bits[1] = 0;
	for (i = 0; i < 334; i++)
		if (bits[i])
			for (j = i * i; j < 111111; j += i)
				bits[j] = 0;
	for (i = j = 0; i < 111111; i++)	
		if (bits[i]) primes[j++] = i;
	n_primes = j;
}

int main(){
	sieve();
	while(1){
		int n,p;
		cin>>n>>p;
		if(n==-1)return 0;
		int idx=0;
		while(1){
			if(primes[idx]>n)break;
			idx++;
		}
		VI a(2500);
		REP(i,50){
			REP(j,50){
				a[i*50+j]=primes[idx+i]+primes[idx+i+j];
			}
		}
		SORT(a);
		cout << a[p-1] << endl;
	}
}

Measured memory_bytes: 1412
while True:
    a,b = map(int, input().split())
    if(a == 0 and b == 0):
        break
    for i in range(a):
        if (i == 0 or i == a-1):
            print("#"*b)
        else:
            print("#" + "."*(b-2) + "#")
    print()


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  for(int i=1; i<=9; ++i) for(int j=1; j<=9; ++j) if(i*j==n){ cout<<"Yes"; return 0;}
  cout<<"No";
  return 0;
}

Measured memory_bytes: 3640
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-03 18:17:47
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int x1, x2, x3, x4, y1, y2, y3, y4;
    cin >> x1 >> y1 >> x2 >> y2;

    x3 = x2 + (y1 - y2);
    y3 = y2 - (x1 - x2);
    x4 = x1 + (y1 - y2);
    y4 = y1 - (x1 - x2);

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int Nums[3];
  scanf("%d %d %d", &Nums[0], &Nums[1], &Nums[2]);

  for(int i=0;i<3;i++){
      for(int j=0;j<i;j++){
          if(Nums[i]<Nums[j]){
              int temp=Nums[i];
              Nums[i]=Nums[j];
              Nums[j]=temp;
          }
      }
  }

  printf("%d %d %d\n", Nums[0], Nums[1], Nums[2]);

  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=1e5+10;
int a[3],b[3];
int main(){
    ll n;
    ll i,j;
    scanf("%lld",&n);
    scanf("%d%d%d%d%d%d",a+0,a+1,a+2,b+0,b+1,b+2);
    vector<int>d;
    for(i=0;i<3;i++)if(b[i]>a[i])d.push_back(i);
    if(d.size()==1){
        n+=(b[d[0]]-a[d[0]])*(n/a[d[0]]);
    }
    else if(d.size()==2){
        ll bes=0;
        for(i=0;a[d[0]]*i<=n;i++){
            ll l=n-a[d[0]]*i;
            bes=max(bes,(b[d[0]]-a[d[0]])*i+(b[d[1]]-a[d[1]])*(l/a[d[1]]));
        }
        n+=bes;
    }
    else if(d.size()==3){
        ll bes=0;
        for(i=0;a[d[0]]*i<=n;i++){
            for(j=0;a[d[0]]*i+a[d[1]]*j<=n;j++){
                ll l=n-a[d[0]]*i-a[d[1]]*j;
                bes=max(bes,(b[d[0]]-a[d[0]])*i+(b[d[1]]-a[d[1]])*j+(b[d[2]]-a[d[2]])*(l/a[d[2]]));
            }
        }
        n+=bes;
    }
    swap(a,b);
    d.clear();
    for(i=0;i<3;i++)if(b[i]>a[i])d.push_back(i);
    if(d.size()==1){
        n+=(b[d[0]]-a[d[0]])*(n/a[d[0]]);
    }
    else if(d.size()==2){
        ll bes=0;
        for(i=0;a[d[0]]*i<=n;i++){
            ll l=n-a[d[0]]*i;
            bes=max(bes,(b[d[0]]-a[d[0]])*i+(b[d[1]]-a[d[1]])*(l/a[d[1]]));
        }
        n+=bes;
    }
    else if(d.size()==3){
        ll bes=0;
        for(i=0;a[d[0]]*i<=n;i++){
            for(j=0;a[d[0]]*i+a[d[1]]*j<=n;j++){
                ll l=n-a[d[0]]*i-a[d[1]]*j;
                bes=max(bes,(b[d[0]]-a[d[0]])*i+(b[d[1]]-a[d[1]])*j+(b[d[2]]-a[d[2]])*(l/a[d[2]]));
            }
        }
        n+=bes;
    }
    printf("%lld",n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MAX = 1e18;
int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  ll dp[n][n]= {0};
  ll cost[n][n]= {0};
  for(int i=0;i<n;i++) dp[i][i] = a[i];
  for(int i=0;i<n;i++) cost[i][i] = 0;
  for(int j=1;j<n;j++) {
     int k=j;
  	for(int i=0;i<n-j;i++, k++) {
      int x = k-1, y = k;
      dp[i][k] = MAX;
      cost[i][k] = MAX;
      while(y>i) {
          if(cost[i][k]>dp[y][k]+ dp[i][x]+cost[y][k]+ cost[i][x]) {
          dp[i][k] = dp[y][k]+ dp[i][x];
          cost[i][k] = dp[y][k]+ dp[i][x]+ cost[y][k]+ cost[i][x];
          }
        x--;y--;
      }
      
    }
  }
  cout<<cost[0][n-1]<<endl;
}

Measured memory_bytes: 2688
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define rfor(i,a,b)     for(ll i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

void solve()
{
    ll n,k; cin>>n>>k;
    vector<int> a(n+1);
    rep(i,1,n+1)
    {
        cin>>a[i];
    }
    vector<int> store;
    vector<int> vis(n+1,0);
    int town = 1;
    while(true)
    {
        if(vis[town] == 2 or k == 0) break;
        if(vis[town] == 1) store.pb(town);
        vis[town]++;
        k--;
        town = a[town];
    }
    if(store.size() and k)
    {
        k%=(ll)store.size();
        town = store[k];
    }
    cout<<town;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while(sc.hasNext()) {
			String str = sc.nextLine();
			run_length(str);
		}
	}

	private static void run_length(String str) {
		for (int i = 0; i < str.length(); i++) {

			if (str.charAt(i) == '@') {
				for (int j = 0; j < (str.charAt(i + 1) - '0'); j++) {
					System.out.print(str.charAt(i + 2));
				}
				i+= 2;
			} else {
				System.out.print(str.charAt(i));
			}

		}

		System.out.println();

	}

}


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

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

 int main() {
   ll N, A, B, C, D, E, mn;
   cin >> N >> A >> B >> C >> D >> E;
   mn = min(A, min(B, min(C, min(D, E))));
   cout << 4 + (ll)ceil(N * 1.0 / mn) << endl;
 }


Measured memory_bytes: 256
#include <iostream>

int main()
{
    long long n, a, b;
    std::cin >> n >> a >> b;
    long long ab = a + b;
    long long var1 = n / ab * a;
    long long var2 = n % ab;
    if (var2 > a)
    {
        var2 = a;
    }
    std::cout << var1 + var2;
    return 0;
}

Measured memory_bytes: 256
// Aizu Vol-2 0208: Room Numbers of a Hospital
// 2017.8.18
// 8?????°??????????????????01234567???01235789??????????????????

#include <stdio.h>

char buf[30], *p;
char b[8] = { '0', '1', '2', '3', '5', '7', '8', '9' };

int main(void)
{
	int n;

	while (scanf("%d", &n) && n) {
		sprintf(p = buf, "%o", n);
		while (*p) *p = b[*p - '0'], p++;
		puts(buf);
	}
	return 0;
}

Measured memory_bytes: 620
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=a;i<=min(b,a+k-1);i++){
		cout<<i<<endl;
	}
	for(int i=max(b-k+1,a+k);i<=b;i++){
		cout<<i<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
#define debug(x) cerr << #x << ' ' << x << endl;
using namespace std;

typedef long long ll;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);
    if(n&1) {
        printf("%.10lf", 1.0 * (n+1)/2/n);
    } else printf("0.5");
    return 0;
}

Measured memory_bytes: 256
#Problem C
n, m = map(int, input().split())
L = [list(map(int,input().split())) for _ in range(m)] #s_i, c_i

for i in range(10**n): #ぜんぶやる
    st = str(i)
    if len(st) == n and all(st[s-1] == str(c) for s, c in L): #長さ＝桁数がiで、かつ全てにおいて[s=c]すなわち[stのs番目の文字＝c]となるとき
        print(i)
        exit()

print(-1)

Measured memory_bytes: 3060
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	int n, m;
	cin >> n;
	vector<string> a, b;
	REP(i, n) {
		string c;
		cin >> c;
		a.push_back(c);
	}
	cin >> n;
	REP(i, n) {
		string c;
		cin >> c;
		b.push_back(c);
	}
	int ans = 0;
	REP(i, a.size()) {
		int tmp = 0;
		REP(j, a.size()) {
			if (a[i] == a[j])tmp++;
		}
		REP(j, b.size()) {
			if (a[i] == b[j]) tmp--;
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int data[] = {1,2,3,4,5,6};

void init(){
  for(int i = 0; i < 6; i++)
    data[i] = i+1;
}

void N(int n){
  while(n--){
    int tmp = data[5];
    data[5] = data[1];
    data[1] = data[0];
    data[0] = data[4];
    data[4] = tmp;
  }
}

void E(int n){
  while(n--){
    int tmp = data[2];
    data[2] = data[5];
    data[5] = data[3];
    data[3] = data[0];
    data[0] = tmp;
  }
}

int main(){

  int in;
  while(cin >> in && in){
    init();
    for(int i = 0; i < in; i++){
      string s;
      cin >> s;
      if(s == "north") N(1);
      if(s == "south") N(3);
      if(s == "east") E(1);
      if(s == "west") E(3);
    }
    cout << data[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
#define int          long long
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007 
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cout << #x << " is " << x << flush << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
using namespace std;
const int maxn = 100010;
int n,k;
int sw[maxn], bu[maxn], hw[maxn], dp[maxn][3];
void solve(){
	cin>>n;
	rep(i,1,n+1)
	cin>>sw[i]>>bu[i]>>hw[i];

	rep(i,1,n+1)
	{
		dp[i][0] = sw[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = bu[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = hw[i] + max(dp[i-1][0], dp[i-1][1]);
	}
	cout<<max(dp[n][0], max(dp[n][1], dp[n][2]));






}
 
signed main(){
   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
     //cin>>t;
 
    while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll solve(ll n){
    if(n%2){
        if((n+1)%4==0){
            return 0;
        }
        else{
            return 1;
        }
    }
    else{
        if(n%4==0){
            return n;
        }
        else{
            return (n^1);
        }
    }
}
int main(){
    ll a,b;
    cin>>a>>b;
    cout<<((solve(b))^(solve(a-1)))<<endl;
    return 0;
}


Measured memory_bytes: 256
import math

N=int(input())
L=[list(map(int,input().split())) for i in range(N)]

#print(L)
#print(len(L))
count=0
for i in range(len(L)):
  for j in range(i+1,len(L)):
    count += (math.sqrt((L[i][0]-L[j][0])**2 + (L[i][1]-L[j][1])**2))*2*(math.factorial(len(L)-1))
    #print(count)
print (count / math.factorial(len(L)))

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		int i, j, n, q, k, lower_bound;
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			int[] a = new int[n + 1];
			for(i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			q = sc.nextInt();
			for(i = 0; i < q; i++) {
				k = sc.nextInt();
				lower_bound = Arrays.binarySearch(a, k);
				if(Arrays.binarySearch(a, k) < 0) {
					lower_bound = -lower_bound - 1;
					if(lower_bound > n) {
						lower_bound = n;
					}
				}else {
					while(lower_bound >= 1) {
						if(a[lower_bound] != a[lower_bound - 1]) {
							break;
						}
						lower_bound--;
					}
				}
				System.out.println(lower_bound);
			}
		}
	}
}


Measured memory_bytes: 108784
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int FindSumOfDigits(int x){
    int sum = 0;
    sum += x%10;
    while(x!=0){
        x /= 10;
        sum += x%10;
    }
    return sum;
}

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

    if(n%FindSumOfDigits(n)==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

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

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC117_B();
        }

        static void ABC117_B()
        {
            var N = int.Parse(Console.ReadLine());
            var Ln = Console.ReadLine().Split(' ').Select(int.Parse).OrderByDescending(x => x).ToList();
            var max = Ln[0];
            Ln.RemoveAt(0);
            if (max < Ln.Sum())
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13396
d,g = map(int,input().split())
import math
pc = []
for i in range(d):
    pc.append(list(map(int,input().split())))
ans = 10000
for i in range(2**d):
    score = 0
    num = 0
    for j in range(d):
        if i>>j & 1 == 1:
            score += pc[j][0]*(j+1)*100+pc[j][1]
            num += pc[j][0]
    for j in range(d-1,-1,-1):
        if i>>j & 1 == 0:
            if g>score:
                so = math.ceil((g-score)/((j+1)*100))
                if so < pc[j][0]:
                    ans = min(ans,num+so)
            else:
                ans = min(ans,num)
        if g<=score:
            ans = min(ans,num)
print(ans)

Measured memory_bytes: 41584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
ll n,m;
const int SIZE = 1e5+10;
ll p[SIZE],y[SIZE];
pair<ll,pair<ll,ll>> pa[SIZE];
string ans[SIZE];
ll cou[SIZE];
int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> p[i] >> y[i];
        pa[i].first = y[i];
        pa[i].second.first = p[i];
        pa[i].second.second = i;
    }

    sort(pa,pa+m);

    string mem1,mem2;
    ll befor = 0;
    for(int i = 0; i < m; i++){
        ++cou[pa[i].second.first];
        mem1 = to_string(pa[i].second.first);
        mem2 = to_string(cou[pa[i].second.first]);
        for(int j = 0; j < 6-mem1.length(); j++)    ans[pa[i].second.second] += '0';
        ans[pa[i].second.second] += mem1;
        for(int j = 0; j < 6-mem2.length(); j++)    ans[pa[i].second.second] += '0';
        ans[pa[i].second.second] += mem2;
    }

    for(int i = 0; i < m; i++){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 12416
n1=0
n2=0
n3=0
n4=0

for i in range(3):
 nData = []
 nData  = input().rstrip().split(' ')

 nN1 = int(nData[0])
 nN2 = int(nData[1])

 if nN1==1:
  n1+=1
 elif nN1==2:
  n2+=1
 elif nN1==3:
  n3+=1
 elif nN1==4:
  n4+=1

 if nN2==1:
  n1+=1
 elif nN2==2:
  n2+=1
 elif nN2==3:
  n3+=1
 elif nN2==4:
  n4+=1

if n1==3:
 print('NO')
elif n2==3:
 print('NO')
elif n3==3:
 print('NO')
elif n4==3:
 print('NO')
else:
 print('YES')






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


int main(){
    int N=0,A=0,B=0,C=0,D=0;
    string str;
    int count = 0;
    int ans=0;
    bool check=true;


    cin>>N;

    if(N<1200){
        cout<<"ABC"<<endl;
    }else if(N<2800){
        cout<<"ARC"<<endl;

    }else{
        cout<<"AGC"<<endl;

    }








}

Measured memory_bytes: 764
#!/usr/bin/env python3
n, k, s = map(int, input().split())
ans = [0] * n
for i in range(n):
    a = s
    if i >= k:
        a = s + 1 if s + 1 < 10 ** 9 else s - 1
    ans[i] = a
print(*ans, sep=" ")


Measured memory_bytes: 14688
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif


typedef long long lint;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
dy[8] = { 1,1,0,-1,-1,-1,0,1 };

template<class T>inline bool maxi(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }



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

	string s; cin >> s;
	lint l = s.length();
	lint ap = 0, zp = l;
	rep(i, l) {
		if (s[i] == 'A') {
			ap = i;
			break;
		}
	}
	for (int i = l - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			zp = i;
			break;
		}
	}
	co(zp - ap + 1);
	gc();
}

Measured memory_bytes: 720
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin>>n && n){
        int a1 = 1000000000;
        double a2 = 10000000;
        vector<pair<double,int>> v(n);
        rep(i,n){
            int x,h,w;
            cin>>x>>h>>w;
            double bmi = 1. * w/h/h*10000;
            if(abs(a2-22)>abs(bmi-22) || (abs(a2-22)==abs(bmi-22) && a1>x)){
                a1 = x;
                a2 = bmi;
            }
        }
        cout << a1 << endl;
    }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    string s;
    cin >> s;
    bool ans = true;

    rep(i,s.size()){
        if(i % 2 == 0){
            if(s[i] == 'L'){
                ans = false;
                break;
            }
        }else{
            if(s[i] == 'R'){
                ans = false;
                break;
            }
        }
    }

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()
m = max(A)
sieve = [True]*(m+1)
sieve[0] = False
ct = 0
for i in range(N):
    n = A[i]
    if sieve[n] == False:
        continue
    if i < N-1 and n == A[i+1]:
        sieve[n] = False
    if sieve[n] == True:
        ct += 1
    for k in range(n*2, m+1, n):
        sieve[k] = False
print(ct)


Measured memory_bytes: 116568
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main() {
	int x;
	cin >> x;
	long long _500 = x / 500;
	long long _5 = x % 500 / 5;
	long long ans = _500 * 1000 + _5 * 5;

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

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
#define res register int
#define inf 0x3f3f3f3f
#define N 200005
using namespace std;
int n, a[N], ans, f[N];
inline int read(){
    res w = 0, X = 0; register char ch = 0;
    while(!isdigit(ch)){w |= ch == '-'; ch = getchar();}
    while(isdigit(ch)){X = (X << 1) + (X << 3) + (ch ^ 48); ch = getchar();}
    return w ? -X : X;
}
int main(){
	n = read();
	for(res i = 1; i <= n; i++)
	  a[i] = read();
	for(res i = n - 1; i; i--)
	  f[i] = a[i] >= a[i + 1] ? f[i + 1] + 1: 0, ans = max(ans, f[i]);
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 1024
#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"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

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


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

	cin >> N >> K;
	if (2 * K - 1 > N) {
		cout << -1 << endl;
		return 0;
	}
	int box = N + 1;
	box /= 2;
	box -= K;
	K = (N + 1) / 2;
	long long int cnt = K + N / 2;
	for (int i = K + 2 * N - 1; i >= K + N; i -= 2) {
		cout << i - box << " " << cnt - box << " " << i + cnt - box << endl;
		cnt++;
	}
	cnt = K;
	for (int i = K + 2 * N - 2; i >= K + N; i -= 2) {
		if (N & 1)cout << i - box << " " << cnt - box << " " << i + cnt - box << endl;
		else cout << i - box << " " << cnt - box << " " << i + cnt - box + 1 << endl;
		cnt++;
	}
	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll A;
    string B;
    cin >> A >> B;
    ll bDigit100 = B[0] - '0';
    ll bDigit10 = B[2] - '0';
    ll bDigit1 = B[3] - '0';
    ll b = 10 * bDigit10 + bDigit1;

    ll ans = 0;
    ans += A * bDigit100;
    ans += (A * b) / 100;
    cout << ans << endl;
}


Measured memory_bytes: 3624
fun main(args: Array<String>) {
    abc127d()
}

private data class Operation(val amount: Int, val value: Long)

fun abc127d() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val numbers = readLine()!!.split(" ").map { it.toLong() }
        .sorted().toMutableList()
    val operations = (1..m).map { readLine()!!.split(" ").map { it.toLong() } }
        .map { Operation(it[0].toInt(), it[1]) }.sortedByDescending { it.value }

    val changeValues = mutableListOf<Long>()
    op@ for (operation in operations) {
        val changeValue = (1..operation.amount).map { operation.value }
        for (cv in changeValue) {
            if (changeValues.size >= n) break@op
            changeValues.add(cv)
        }
    }

    changeValues.forEachIndexed { index, cv ->
        if (cv > numbers[index]) {
            numbers[index] = cv
        } else return@forEachIndexed
    }

    val answer = numbers.sum()

    println(answer)
}


Measured memory_bytes: 103712
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest011-A
#  TODO https://atcoder.jp/contests/agc011/tasks/agc011_a

def solveProblem(personNumber,maxPerson,waitMaxTime,reachTime):
	needBas = 1
	reachTime.sort()
	nowTime = reachTime[0]
	nowPassenger = 0
	for i in  range(0,len(reachTime),+1):
		if nowPassenger < maxPerson and reachTime[i] <= nowTime + waitMaxTime:
			nowPassenger = nowPassenger+1
		else:
			needBas = needBas+1
			nowTime = reachTime[i]
			nowPassenger = 1
	answer = needBas
	return answer


if __name__ == '__main__':
	N,C,K = map(int,input().strip().split(' '))
	dataGetPerson = range(0,N,+1)
	reachTime = []
	for _ in dataGetPerson:
		reachTime.append(int(input()))
	solution = solveProblem(N,C,K,reachTime)
	print("{}".format(solution))


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

const int mxn = 5e5;
const int M = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % M;
		b = (b * b) % M;
		e >>= 1; // e/=2;
	}
	return res;
}

ll iv[mxn + 1], f1[mxn + 1], f2[mxn + 1];
ll nck(int n, int k)
{
	return f1[n] * f2[k] % M * f2[n - k] % M;
}

int main()
{
	fast;
	int n;
	cin >> n;
	cout << (n >= 30 ? "Yes" : "No");
}

Measured memory_bytes: 3648
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

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

    while(1) {
        int b;
        cin >> b;
        if (b == 0) break;
        for (long long w = 100000; w >= 1; --w) {
            long long lh = b - (w * w - w) / 2;
            if (lh > 0 && lh % w == 0) {
                cout << lh / w << " " << w << endl;
                break;
            }
        }
    }
}



Measured memory_bytes: 3108
# https://atcoder.jp/contests/arc080/tasks/arc080_b

h, w = map(int, input().split())
n = int(input())
nums = [int(i) for i in input().split()]

matrix = [[0] * w for _ in range(h)]

i = j = 0
t = 0
flag = True # Trueのとき、右方向
while i < h:
    num = nums[t]
    while num:
        matrix[i][j] = t + 1
        num -= 1
        if flag:
            if j + 1 == w:
                i += 1
                flag = False
            else:
                j += 1
        else:
            if j == 0:
                i += 1
                flag = True
            else:
                j -= 1
    t += 1

for r in matrix:
    print(*r)

Measured memory_bytes: 42608
# -*- coding: utf-8 -*-


def main():
    n, y = map(int, input().split())

    a, b, c = -1, -1, -1
    for ia in range(n + 1):
        for ib in range(n - ia + 1):
            ic = n - ia - ib
            total = ia * 10000 + ib * 5000 + ic * 1000
            if total == y and (ia + ib + ic) == n:
                a = ia
                b = ib
                c = ic
                break

    print(" ".join(map(str, (a, b, c))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n = str(input())

ans = 'Yes'

for i in range(len(n)):
  if i % 2 == 0:
    if n[i] != 'R' and n[i] != 'U' and n[i] != 'D':
      print('No')
      exit()
      
  if i % 2 == 1:
    if n[i] != 'L' and n[i] != 'U' and n[i] != 'D':
      print('No')
      exit()

print('Yes')

Measured memory_bytes: 3060
from itertools import cycle
f=lambda a,b:[chr(i) for i in range(a,b)]
c=(f(97,123)+f(65,91))[::-1]
c*=2
while int(input()):
    l=cycle(map(int,input().split()))
    s=input()
    print("".join([c[c.index(i)+j] for (i,j) in zip(s,l)]))



Measured memory_bytes: 5680
def is_prime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    for i in range(3, n, 2):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return True


x = int(input())
while not is_prime(x):
    x += 1
print(x)


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  int x; cin >> x;

  for (int t = 1; ; t++) {
    if (t * (t + 1) / 2 >= x) {
      cout << t << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
a = [0,300000,200000,100000]
ans = 0
if(n <= 3):
	ans = a[n]
if(m <= 3):
	ans += a[m]
if(ans == 600000): ans += 400000
print(ans)




Measured memory_bytes: 38384