akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  set<string> gacha; ll n; cin >> n; ll count = 0;
  
  rep(i,n){ string s; cin >> s; gacha.insert(s); }
  
  for(string s : gacha){
    count++;
  }
  
  cout << count << endl;
}
  
  

Measured memory_bytes: 19188
using System;

class Solver {
  public void solve() {
    var buf = Console.ReadLine().Split();
    int n = int.Parse(buf[0]);
    int k = int.Parse(buf[1]);
    int m = k * 2;
    int[,,] a = new int[2, m + 1, m + 1];
    for (int i = 0; i < n; i++) {
      buf = Console.ReadLine().Split();
      int x = int.Parse(buf[0]);
      int y = int.Parse(buf[1]);
      int c = buf[2]=="B" ? 1 : 0;
      x %= m; y %= m;
      a[c,x,y]++;
    }
    for (int c = 0; c < 2; c++) {
      for (int i = 0; i < m; i++) {
        for (int j = 0; j <= m; j++) {
          a[c, i + 1, j] += a[c, i, j];
        }
      }
      for (int i = 0; i <= m; i++) {
        for (int j = 0; j < m; j++) {
          a[c, i, j + 1] += a[c, i, j];
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        for (int c = 0; c < 2; c++) {
          int cur = 0;
          int ti = i + k, tj = j + k;
          for (int nc = 0; nc < 2; nc++) {
            int tmp = 0;
            tmp += a[nc, m, tj] - a[nc, m, j];
            tmp += a[nc, ti, m] - a[nc, i, m];
            tmp -= (a[nc, ti, tj] - a[nc, ti, j] - a[nc, i, tj] + a[nc, i, j]) * 2;
            if (c != nc) tmp = a[nc, m, m] - tmp;
            cur += tmp;
          }
          ans = Math.Max(ans, cur);
        }
      }
    }
    Console.WriteLine(ans);
  }
}

/* Main */
class ReSha {
  static void Main() {
    new Solver().solve();
  }
}

Measured memory_bytes: 44244
using System;
class test{
  static void Main(){
    var line = Console.ReadLine().Split(' ');
    int n = int.Parse(line[0]);
    int r = int.Parse(line[1]);

    if(n >= 10)
    {
      Console.WriteLine(r);
    }else
    {
      Console.WriteLine(r + 100*(10 - n));
    }
  }
}

Measured memory_bytes: 11092
n,k=map(int,input().split())
A=list(map(int,input().split()))
B=[]
B.append(1)
C=[0]*n
C[0]+=1

start=0
finish=0

for i in range(1,n):
	if C[A[B[i-1]-1]-1]!=1:
		B.append(A[B[i-1]-1])
		C[A[B[i-1]-1]-1]+=1
	else:
		start=B.index(A[B[i-1]-1])
		finish=i
		break

roop=finish-start
line=sum(C)-roop

if line+(roop-1)>=k:
	print(B[k])
else:
	print(B[(k-line)%roop+line])

Measured memory_bytes: 32376
N = int(input())
aaa = list(map(int, input().split()))
bbb = [format(a, '061b') for a in aaa]

zero = [0] * 61
one = [0] * 61
for i in range(61):
    s = ''.join(list(b[-(i+1)] for b in bbb))
    zero[i] = s.count('0')
    one[i] = s.count('1')
ans = 0
MOD = 1_000_000_007
for i, o, l in zip(range(61), zero, one):
    ans += 2**i * o * l
    ans %= MOD
print(ans)


Measured memory_bytes: 62556
/*
 * Name        : c
 * Creat       : Thu Jul 11 21:47:30 CST 2019
 * Accept      : Thu Jul 11 22:11:07 CST 2019
 * Author      : landcold7
 * Motivation  : Action speaks louder more than words
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int l, r;
  cin >> l >> r;
  int x = (l - 1) / 2019;
  int y = r / 2019;
  if (y > x) {
    cout << 0 << "\n";
    return;
  }
  int ans = (1 << 30);
  for (int i = l; i <= r; ++i) {
    for (int j = i + 1; j <= r; ++j) {
      int t = (i * 1ll * j) % 2019;
      ans = min(ans, t);
    }
  }
  cout << ans << "\n";
}

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


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

const int MAX =1000000;
int cnt;

void insertionSort(int *a, int n, int g){
        for(int i=g;i<n;i++){
                int v = a[i];
                int j = i-g;
                while(j>=0&&a[j]>v){
                        a[j+g] = a[j];
                        j = j-g;
                        cnt++;
                }
                a[j+g] = v;
        }
}
void shellSort(int *a, int n){
        int m=1;
        int g[MAX];
        int i=1;
        g[0]=1;
        while(1+3*g[i-1]<=n){
                g[i] = 1+3*g[i-1];
                i++;
                m++;
        }
        cnt=0;
        for(int j=m-1;j>=0;j--)
                insertionSort(a,n,g[j]);

        cout<<m<<endl;
        for(int j=m-1;j>=0;j--){
                cout<<g[j];
                if(j>0) cout<<" ";
                else cout<<endl;
        }
        cout<<cnt<<endl;
}

int main(){
        int n;
        int a[MAX];
        cin>>n;
        for(int i=0;i<n;i++) cin>>a[i];
        shellSort(a, n);
        for(int i=0;i<n;i++) cout<<a[i]<<endl;

        return 0;
}


Measured memory_bytes: 7000
#include<stdio.h>
#include<string.h>
int main(void)
{
	char S1[10] = "Sunny";
	char S2[10] = "Cloudy";
	char S3[10] = "Rainy";
	char S4[10];
	scanf("%s", S4);
	if (strcmp(S4, S1) == 0)
		printf("%s", S2);
	else if (strcmp(S4, S2) == 0)
		printf("%s", S3);
	else if (strcmp(S4, S3) == 0)
		printf("%s", S1);
	return 0;
}

Measured memory_bytes: 128
S = input()
s = list(S)
l_s = len(s)
ans = 0
black_index = 0
for i in range(1, l_s)[::-1]:
    if s[i] == 'B':
        black_index += 1
        continue

    if s[i-1] == 'B':
        ans += l_s - i - black_index
        s[i] = 'B'
        s[i-1] = 'W'
        black_index += 1
print(ans)


Measured memory_bytes: 4840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char input[4];
    scanf("%s", input);
    if (input[0] == '7' || input[1] == '7' || input[2] == '7')
    {
        printf("Yes");
        return 0;
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		
		if(s.charAt(0) != s.charAt(1) && s.charAt(0) != s.charAt(2) && s.charAt(1) != s.charAt(2))
			System.out.println("Yes");
		else System.out.println("No");
	}
}

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


int main() {
  int n,m;
  cin >> n>>m;
  vector<tuple<int,int,int>>a;
  
  rep(i,n){
    int s,t,c;
    cin>>s>>t>>c;
    a.push_back(tuple<int,int,int>(s,t,c));
  }
  sort(a.begin(),a.end());
  vector<bool>e(n,true);
  int ans=0;
  int co=0;
  while(co<n){
    ans++;
    int f=0;
    int g=0;
    int h=0;
  rep(i,n){
    if(e.at(i)){
      if((g<get<0>(a[i])&&h!=get<2>(a[i]))||(g<=get<0>(a[i])&&h==get<2>(a[i]))){
        f=get<0>(a[i]);
        g=get<1>(a[i]);
        h=get<2>(a[i]);
        e.at(i)=false;
        co++;
      }
    }
  }
  }
  
  cout<<ans<<endl;
}

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

int main(){
	int a,b,c,d,e,f;
	cin >>a>>b>>c>>d>>e>>f;
	cout << a+b+c+d+e+f -min(min(a,b), min(c,d)) -min(e,f) << endl;
	return 0;
}


Measured memory_bytes: 3080
// g++ -std=gnu++1y -O2 main.cpp

#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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

int main() {
	int N, K;
	cin >> N >> K;

	int cnt = 0;
	while (N != 0)
	{
		N /= K;
		cnt++;
	}
	cout << cnt << endl;

	return 0;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

const long long MOD = (long long)1e9 + 7;

ll f[400001];

long long mod_pow(long long x_, long long y_){
    if(y_ == 0) return 1;
    long long res = mod_pow(x_ * x_ % MOD, y_ / 2);
    if(y_ & 1) res =  x_ * res % MOD;
    return res;
}

long long mod_inv(long long x){
    return mod_pow(x, MOD - 2);
}

ll comb(ll x, ll y){
    return (((f[x] * mod_inv(f[y]) % MOD) * mod_inv(f[x - y])) % MOD);
}

int main(){
    ll n, k, ans = 0;
    cin >> n >> k;
    f[0] = 1;
    for(int i = 1; i <= 400000; i++){
        f[i] = f[i - 1] * i;
        f[i] %= MOD;
    }
    if(n - 1 <= k){
        ans = comb(n + n - 1, n);
    }else{
        for(int i = 0; i <= k; i++){
            ans += comb(n, i) * comb(n - 1, i);
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
import collections

n = int(input())
l = list(map(int, input().split()))
q = int(input())

clist = collections.Counter(l)

ans = sum(l)
for i in range(q):
  b,c = map(int, input().split())
  
  add = (c - b) * clist[b]
  ans += add
  
  clist[c] += clist[b] 
  clist[b] -= clist[b]
  
  print(ans)

Measured memory_bytes: 95104
import sys
sys.setrecursionlimit(100000)
import heapq
input=lambda : sys.stdin.readline().rstrip('\n')

a,b=map(int,input().split())

def f(x):
    ans=[]
    for i in range(1,42):
        if i==1:
            if x%4==1 or x%4==2:
                ans.append('1')
            else:
                ans.append('0')
        else:
            if x%(2**i)>(2**(i-1)-1) and (x%(2**i))%2==0:
                ans.append('1')
            else:
                ans.append('0')
    return ''.join(ans[::-1])


print(int(f(b),2)^int(f(a-1),2))


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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() {
    int N, M;
    cin >> N >> M;

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int  x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1); // xの木とyの木を併合する
    }

    int cnt=0;
    for(int i=0;i<N;i++){
        if(!tree.same(0,i)){
            tree.unite(0, i);
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3804
n = int(input())
A = [ int(input()) for i in range(n) ]
c = 0
temp = 1
s = set()
while temp not in s:
  s.add(temp)
  temp = A[temp-1]
  c += 1
  if temp == 2:
    print(c)
    exit()
print(-1)

Measured memory_bytes: 13220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll L,a,b,mod;
struct Matric
{
    ll a[3][3];
    Matric(){memset(a,0,sizeof(a));}
    Matric operator*(const Matric&o)const
    {
        Matric ans;
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
            ans.a[i][j]=(ans.a[i][j]+a[i][k]*o.a[k][j]%mod)%mod;
        return ans;
    }
};
Matric Mqpow(Matric a,ll n)
{
    Matric ans;
    ans.a[0][0]=ans.a[1][1]=ans.a[2][2]=1;
    while(n)
    {
        if(n&1) ans=ans*a;
        a=a*a;
        n>>=1;
    }
    return ans;
}
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int getlen(ll x)
{
    int ans=0;
    while(x)
    {
        x/=10;
        ans++;
    }
    return ans;
}
ll getpos(int x)
{
    ll l=1,r=L,ans=1;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(getlen(a+(m-1)*b)<=x) ans=m,l=m+1;
        else r=m-1;
    }
    return ans;
}
/*
si=s(i-1)*qpow(10,i)+qi+B;
gi=g(i-1)+B;
|10i 1 1| |si-1|
|0   1 1| |gi-1|
|0   0 1| |B|
*/
int main()
{
    scanf("%lld%lld%lld%lld",&L,&a,&b,&mod);
    ll ans=a%mod,res=a%mod,now=1;
    for(int i=1;i<=18;i++)
    {
        ll p=getpos(i);
        if(p==now) continue;
        {
            Matric A;
            A.a[0][0]=qpow(10,i);A.a[0][1]=1;A.a[0][2]=1;
            A.a[1][1]=1;A.a[1][2]=1;
            A.a[2][2]=1;
            A=Mqpow(A,p-now);
            ans=(A.a[0][0]*ans%mod+A.a[0][1]*res%mod+b%mod*A.a[0][2]%mod)%mod;
            res=(res+b*(p-now))%mod;
            now=p;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

int main() {
ll n;
cin>>n;
double k=2.0/n;

double a[n+1];
double b[n+1];
rep(i, n){
	cin>>a[i]>>b[i];
}

double sum=0.0;
for(int i=1;i<=n-1;i++){
	for(int j=i+1;j<=n;j++){
		double x=a[i];
		double x2=a[j];
		double y2=b[j];
		double y=b[i];
sum+=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
	}
}

sum*=k;

dcout;
cout<<sum<<endl;
return 0;


}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
using namespace std;
#define EPS 1e-10

struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x=_x; y=_y;
    }
    Point operator +(const Point p)const{
        return Point(x+p.x,y+p.y);
    }
    Point operator -(const Point p)const{
        return Point(x-p.x,y-p.y);
    }
	Point operator *(const double d)const{
		return Point(x*d,y*d);
	}
};

struct Line{
    Point a,b;
    Line(){}
    Line(Point _a,Point _b){
        a=_a; b=_b;
    }
};

double dot(Point p,Point q){
    return p.x*q.x+p.y*q.y;
}

double cross(Point p,Point q){
    return p.x*q.y-q.x*p.y;
}

int ccw(Point a,Point b,Point c){
    if(cross(b-a,c-b)>0) return +1;
    if(cross(b-a,c-b)<0) return -1;
    return 0;
}

bool pss(Line l,Line m,Point &p){
	Point a1,a2,b1,b2;
	a1 = l.b-l.a; a2 = m.b-m.a;
	b1 = m.a-l.a; b2 = m.b-l.a;
	double s1,s2;
	s1 = abs(cross(a1,b1)/2); s2 = abs(cross(a1,b2)/2);
	if(s1<EPS && s2<EPS) return false;
	p = Point(m.a.x+a2.x*s1/(s1+s2),m.a.y+a2.y*s1/(s1+s2));
	if(p.x<min(l.a.x,l.b.x) || max(l.a.x,l.b.x)<p.x || p.x<min(m.a.x,m.b.x) || max(m.a.x,m.b.x)<p.x ||
	   p.y<min(l.a.y,l.b.y) || max(l.a.y,l.b.y)<p.y || p.y<min(m.a.y,m.b.y) || max(m.a.y,m.b.y)<p.y)
		return false;
	return true;
}

int main(){
	/*Line l[3];
	while(true){
		for(int i=0;i<3;i++){
			cin>>l[i].a.x>>l[i].a.y>>l[i].b.x>>l[i].b.y;
			if(l[i].a.x==0 && l[i].a.y==0 && l[i].b.x==0 && l[i].b.y==0) return 0;
		}
		Point p[3];
		bool kyo = false;
		for(int i=0;i<3;i++){
			if(pss(l[i],l[(i+1)%3],p[i])==false) kyo = true;
		}
		if(kyo==true){
			puts("kyo"); continue;
		}
		double s = abs(cross(p[1]-p[0],p[2]-p[0])/2);
		//printf("\t%lf\n",s);
		if(s<EPS) puts("kyo");
		else if(s<100000) puts("syo-kichi");
		else if(s<1000000) puts("kichi");
		else if(s<1900000) puts("chu-kichi");
		else puts("dai-kichi");
	}*/
	int Q;
	cin>>Q;
	for(int ds=0;ds<Q;ds++){
		Line l,m;
		cin>>l.a.x>>l.a.y>>l.b.x>>l.b.y;
		cin>>m.a.x>>m.a.y>>m.b.x>>m.b.y;
		Point p;
		pss(l,m,p);
		printf("%.16lf %.16lf\n",p.x,p.y);
	}
    return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, k;
    cin >> n >> k;
    VL a(n);
    REP(i,n) a[i] = in();

    ll ans = 0;
    REP(x,k+1) REP(y,k+1){
        if (x + y > k || x + y > n) continue;
        VL b;
        REP(i,x) b.push_back(a[i]);
        REP(i,y) b.push_back(a[n - 1 - i]);
        sort(ALL(b));
        int m = b.size();
        ll s = 0;
        REP(i,m) s += b[i];
        chmax(ans, s);
        REP(p,m){
            s -= b[p];
            if (x + y + p + 1 <= k) chmax(ans, s);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int min=753;
    for(int i=0;i<s.length()-2;i++){
        string x=s.substr(i,3);
        int a=x[0]-'0';
        int b=x[1]-'0';
        int c=x[2]-'0';
        if(min>abs(753-(a*100+b*10+c))){
            min=abs(753-(a*100+b*10+c));
        }
    }
    cout<<min<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll n, k;
    cin >> n >> k;
    
    vector<vector<int>> next(60, vector<int>(n));
    for(int v = 0; v < n; v++) {
        cin >> next[0][v]; next[0][v]--;
    }

    for(int d = 0; d+1 < 60; d++) {
        for(int v = 0; v < n; v++) {
            next[d+1][v] = next[d][next[d][v]];
        }
    }

    int v = 0;
    for(int d = 0; d < 60; d++) {
        if (k & (1L<<d)) v = next[d][v];
    }

    cout << v+1 << endl;

return 0;
}

Measured memory_bytes: 51040
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()  {
	string s;
	cin>>s;
	s = "#" + s;
	for(int i=1;i<s.size();i+=2) {
		if(s[i]=='L'){
			cout<<"No";
			return 0;
		}
	}
	for(int i=2;i<s.size();i+=2) {
		if(s[i]=='R'){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}

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

const int MAX_N = 2005;

bool visited[MAX_N];
int dist[MAX_N], u[MAX_N], v[MAX_N];
vector<int> g[MAX_N];

void dfs(int node, int curr_dist) {
	dist[node] = curr_dist;
	visited[node] = true;

	for(int nb : g[node]) {
		if(!visited[nb]) {
			dfs(nb, curr_dist + 1);
		}
	}
}

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

	for(int i = 0; i < n - 1; i++) {
		scanf("%d %d", &u[i], &v[i]);
		
		g[u[i]].pb(v[i]);
		g[v[i]].pb(u[i]);
	}
	
	int ans = -1;
	if(k % 2 == 0) {
		for(int i = 1; i <= n; i++) {
			memset(visited, 0, sizeof(visited));
			dfs(i, 0);
	
			int cnt = 0;
			for(int j = 1; j <= n; j++) {
				if(k % 2 == 0) {
					if(dist[j] > k / 2) {
						cnt++;
					}
				}
				else {
					if(dist[j] > (k + 1) / 2) {
						cnt++;
					}
				}
			}
	
			if(ans == -1 || ans > cnt) {
				ans = cnt;
			}
		}
	}
	else {
		for(int i = 0; i < n - 1; i++) {
			memset(visited, 0, sizeof(visited));
			
			visited[u[i]] = true;
			dfs(v[i], 0);
			
			visited[u[i]] = false;
			dfs(u[i], 0);

			int cnt = 0;
			for(int j = 1; j <= n; j++) {
				if(dist[j] > (k - 1) / 2) {
					cnt++;
				}
			}

			if(ans == -1 || ans > cnt) {
				ans = cnt;
			}
		}
	}

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second

int main() {

	ll n,k;
	cin>>n>>k;
	ll a[n];
	rep(i,n){
		cin>>a[i];
	}
	ll dp[n]={0};
	for(ll i=1;i<n;++i){
		ll j=i-1,p=0,mini = INT_MAX;
		while(j>=0 && p<k){
			mini = min(mini, dp[j]+abs(a[j]-a[i]));
			j--;
			++p;
		}
		dp[i] = mini;
	}
	
	cout<<dp[n-1];
}

Measured memory_bytes: 1792
import java.util.Scanner;

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

    String firstLine = scanner.nextLine();
    String[] firstArgs = firstLine.split(" ");
    int N = Integer.parseInt(firstArgs[0]);
    int K = Integer.parseInt(firstArgs[1]);

    String secondLine = scanner.nextLine();
    String[] secondArgs = secondLine.split(" ");
    int[] H = new int[N];
    for (int i = 0; i < N; i++) {
      H[i] = Integer.parseInt(secondArgs[i]);
    }

    int[] minCumulativeCosts = new int[N];
    for (int i = 0; i < N; i++) {
      if (i == 0) {
        minCumulativeCosts[i] = 0;
        continue;
      }

      int minCost = Integer.MAX_VALUE;
      for (int j = Math.max(i - K, 0); j < i; j++) {
        int costBetweenNodes = Math.abs(H[i] - H[j]);
        int cumulativeCost = minCumulativeCosts[j];
        int totalCost = costBetweenNodes + cumulativeCost;
        minCost = Math.min(minCost, totalCost);
      }
      minCumulativeCosts[i] = minCost;
    }

    System.out.println(minCumulativeCosts[N - 1]);
  }
}


Measured memory_bytes: 61808
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
 int main() {
    int n,m;
    cin>>n>>m;
    int r[100]={};
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        r[a]++;
        r[b]++;
    }
    for(int i=1;i<=n;i++){
        cout<<r[i]<<endl;
    }
 }



Measured memory_bytes: 256
n = int(input())
A = input().split()
for i in range(n):
    A[i] = int(A[i])

for i in range(n-1):
    print(A[i],end=" ")
print(A[n-1])


for i in range(1,n):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j = j-1
    A[j+1] = v
    for i in range(n-1):
        print(A[i],end=" ")
    print(A[n-1])


Measured memory_bytes: 5984
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>

using namespace std;

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

    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i < N; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3872
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
Sum = sum(b)
for i in range(len(a)-1):
    if a[i] ==  a[i+1] -1:
        Sum = Sum + c[a[i]-1]
print(Sum)

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
using namespace std;
int main()
{

    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) cin >> a[i];

    long long sum[N]; // 上からi枚目までの和(0-indexed)
    sum[0] = a[0];

    // 累積和を計算しておく
    for (int i = 1; i < N; i++) sum[i] = sum[i - 1] + a[i];

    long long minimum = 1000000000000000000ll;
    for (int i = 0; i < N - 1; i++) {
        long long sum_snuke = 0, sum_kuma = 0;
        // すぬけくんは上からi枚目まで取る(0-indexed)
        sum_snuke = sum[i];
        // 残りをアライグマが取る
        sum_kuma = sum[N - 1] - sum_snuke;
        long long score = abs(sum_snuke - sum_kuma);
        // 2人の手札の差の絶対値が小さければ更新
        if (minimum > score) minimum = score;
    }
    // 最小値を出力
    cout << minimum << endl;

    return 0;
}

Measured memory_bytes: 5968
MOD = 1000000007


S = int(input())

#dp[i]:=i桁の数列で条件を満たすものの数
dp = [0]*(S+1)
dp_sum = [0]*(S+1)

for i in range(3,S+1):
    #dp[i]=sum(dp[0],..,dp[i-3])+1
    
    dp[i] = (dp_sum[i-3]+1)%MOD
    dp_sum[i] = (dp[i]+dp_sum[i-1])%MOD

print(dp[S])

Measured memory_bytes: 8996
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long min = (long) 1e18;
		for(long x = 0; x <= 100; x++){
			
			long tot = 0;
			for(int i=0;i<N;i++){
				tot += (X[i] - x) * (X[i] - x);
			}
			min = Math.Min(min, tot);
		}
		Console.WriteLine(min);
		
		
	}
	int N;
	long[] X;
	public Sol(){
		N = ri();
		X = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;



int main() {
	int  h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}

	bool canPaint = true;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w;j++) {
			if (s[i][j] == '#') {
				bool canPaint_grid = false;
				if (i > 0 && s[i - 1][j] == '#') {
					canPaint_grid = true;
				}
				if (i  < h-1 && s[i + 1][j] == '#') {
					canPaint_grid = true;
				}
				if (j > 0 && s[i][j - 1] == '#') {
					canPaint_grid = true;
				}
				if (j < w -1 && s[i][j + 1] == '#') {
					canPaint_grid = true;
				}

				if (!canPaint_grid) {
					canPaint = false;
					break;
				}
			}

		}
		if (!canPaint) {
			
			break;
		}
	}

	cout << (canPaint ? "Yes" : "No") << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b,c,d,e=0;
	cin>>a>>b>>c>>d;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(500*i+100*j+50*k==d)
					e++;
			}
		}
	}
	cout<<e<<endl;
}

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

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var X = vals[0];
        var N = vals[1];

        if (N == 0)
        {
            Console.WriteLine(X);
            return;
        }

        var p = Console.ReadLine().Split(' ').Select(int.Parse).ToHashSet();

        for (int d = 0; true; d++)
        {
            foreach (var f in new int[] { -1, 1 })
            {
                var x = X + d * f;
                if (!p.Contains(x))
                {
                    Console.WriteLine(x);
                    return;
                }
            }
        }
    }
}

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

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

ll n, w;
ll a[mnx];
ll b[mnx];
ll dp[mnx];

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

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

    for(int i = 1; i <= n; i++){
        for(int j = w; j >= 0; j--) {
            dp[j + a[i]] = max(dp[j] + b[i], dp[j + a[i]]);
        }
    }

    ll ans = 0;

    for (int i = 1; i <= w; i++) {
        ans = max(ans, dp[i]);
    }

    cout << ans << '\n';

    return 0;
}

/*
3
10 40 70
20 50 80
30 60 90

10  40  70
90  120 120
150 180 210
*/


















Measured memory_bytes: 5888
from itertools import product
N,M,X = map(int,input().split())
C = []
A = []
for n in range(N):
    a = list(map(int,input().split()))
    C.append(a[0])
    A.append(a[1:])
INF = 10**9
ans = INF
for p in product([0,1], repeat=N):
    sm = [0] * M
    cost = 0
    for i in range(N):
        if p[i]:
            for m in range(M):
                sm[m] += A[i][m]
            
            cost += C[i] 
    #print (p,sm)
    if min(sm) >= X:
        ans = min(ans,cost)
if ans==INF:
    print (-1)
else:
    print (ans)

Measured memory_bytes: 9236
#include<cstdio>
int main(){
  int r,x,y;
  int w,h;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
  bool in=false;
  if(x-r>=0 && y-r>=0 && x+r<=w && y+r<=h){
      in=true;
  }
  printf("%s\n",in? "Yes":"No");
}

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


int main() {
  int n , k ;
  cin >> n >> k ;
  
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end());
  
  for(int i=k-1;i<n;i++){
    b.at(i)=a.at(i)-a.at(i-k+1);
  }
  
  sort(b.begin(),b.end());
  
  cout << b.at(k-1) <<endl;
  
  
  
}

Measured memory_bytes: 1152
#include <stdio.h>

int main()
{
 long int a,b,c,d,n,n2,flag=0,i,j;
  
  scanf("%ld%ld%ld%ld",&a,&b,&c,&d);
 
 
 
 
 if(a+b==c+d)
 {
     printf("Balanced");
 }else{
     if(a+b>c+d)
     {
         printf("Left");
     }else{
         printf("Right");
     }
 }
    return 0;
}


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

using namespace std;

int Menu[30];
bool PrimeNumber[1000000], DpMoney[1000000];


void findPrimeNumber() {
	int limit;
	bool flag;

	memset(PrimeNumber, false, sizeof(PrimeNumber));
	PrimeNumber[2] = PrimeNumber[3] = true;

	for (int i = 5; i < 1000000; i += 2) {
		flag = true;
		limit = sqrt(i) + 1;
		for (int j = 2; j < limit; ++j) {
			if (i%j == 0) {
				PrimeNumber[i] = false;
				flag = false;
				break;
			}
		}
		if (!flag) {
			continue;
		}
		PrimeNumber[i] = true;
	}
}

void solve(int n, int max) {

	memset(DpMoney, false, sizeof(DpMoney));
	DpMoney[0] = true;

	for (int i = 0; i <= max; ++i) {
		for (int j = 0; j < n; ++j){
			if (DpMoney[i]) {
				if (i + Menu[j] > max) {
					continue;
				}
				DpMoney[i + Menu[j]] = true;
			}
		}
	}

	for (int i = max; i > 1; --i) {
		if (DpMoney[i] && PrimeNumber[i]) {
			cout << i << endl;
			return;
		}
	}
	cout << "NA" << endl;
}

int main() {
	int n, x, i;
	bool flag;

	findPrimeNumber();
	while (cin >> n >> x, n) {
		for (int i = 0; i < n; ++i) {
			cin >> Menu[i];
		}
		solve(n, x);
	}

	return 0;
}


Measured memory_bytes: 4964
#include <stdio.h>

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

void insertionSort(int A[], int N){
  int j, i, v;
  for(i=1; i<N; i++)
    {
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v)
      {
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
  trace(A, N);
  }
}

int main(){
  int N, i, j;
  int A[100];
  
  scanf("%d", &N);
  for(i=0;i<N; i++)
    scanf("%d", &A[i]);
  
  trace(A,N);
  insertionSort(A,N);
  
  return 0;
}


Measured memory_bytes: 2140
function Main(s){
  s = s.split(" ").map(a=>+a);
  var ans = "x";
  if(s[0] + s[1] === 15)ans = "+";
  if(s[0] * s[1] === 15)ans = "*";
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		int h,w;
		Scanner scan = new Scanner(System.in);
		while(true){
			h=scan.nextInt();
			w=scan.nextInt();
			if(h==0&&w==0)
				break;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if((i+j)%2==0)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}		
	}
}


Measured memory_bytes: 34840
#include<stdio.h>
int main(void)
{
	int n,z[1000],c,i,m,b,a,j;
	double t,w,x,max,o,s[1000];
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		scanf("%d",&a);
		for(i=0;i<n;i++){
			scanf("%d %lf %d",&z[i],&x,&c);
			if(c==1){
				s[i]=10000.0+(double)a*x*100;
//				printf("s=%lf\n",s[i]);
			}
			else {
				o=x/100.0;
				t=o+1.0;
				w=t;
				for(j=0;j<a-1;j++){
					t=t*w;
				}
				s[i]=t*10000.0;
//				printf("ss=%lf\n",s[i]);
			}
			
		}
		max=-1;
		for(i=0;i<n;i++){
//			printf("%lf\n",s[i]);
			if(max<s[i])	{
				max=s[i];
				b=z[i];
			}
		}
		printf("%d\n",b);
	}
	return 0;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef debug
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    vector<int> vec;
    for(int i = 0; i< 3; i++){
        int t; cin >> t; vec.pb(t);
    }
    sort(vec.begin(),vec.end());
    cout << vec[vec.size()-1]*10+vec[1]+vec[0] << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	long long int s[88];
	s[0] = 2;
	s[1] = 1;
	for(int i = 2; i < 88; i++){
		s[i] = s[i-1] + s[i-2];
	}
	int n;
	cin >> n;
	cout << s[n] << endl;
	return 0;
}

Measured memory_bytes: 256
N,K,Q=map(int,input().split())
q=[0 for i in range(N)]
for i in range(0,Q):
  n=int(input())
  q[n-1]+=1
  
for i in range(N):
  if K-Q+q[i]>0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 4680
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    ll now=1000;
    for(ll i=0;i<N-1;++i){
        if(A[i]<A[i+1]){
            ll num=now/A[i];
            now-=num*A[i];
            now+=num*A[i+1];
        }
    }
    prt(now);

    return 0;
}



Measured memory_bytes: 3656
var n:longint;
    i:longint;
    v:array[0..100050]of boolean;
    x:longint;
    last:longint;
    ans:int64;
begin
  read(n);
  for i:=1 to n do
  begin
    read(x);
    if i=x then v[i]:=true;
  end;

  for i:=1 to n do
  begin
    if (v[i])and(not v[i-1]) then last:=i-1;
    if (v[i])and(not v[i+1]) then
    begin
      ans:=ans+(i-last)div 2;
      if (i-last) mod 2=1 then inc(ans);
    end;
  end;
  writeln(ans);
end.

Measured memory_bytes: 128
#include <iostream>

using namespace std;
bool kadai[31];
int i,n;
int main(){
	for(int j=1;j<=30;j++){
		kadai[i]=false;
	}
	i=0;
	while(i!=28){
		cin >>n;
		kadai[n]=true;
		i++;
	}
	for(int j=1;j<=30;j++){
		if(!kadai[j])cout << j<<endl;
	}
	return 0;
}

Measured memory_bytes: 3072
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = T1 * (A1 - B1)
d2 = T2 * (A2 - B2)
if d1 > 0 and d1 + d2 > 0:
    print(0)
elif d1 < 0 and d1 + d2 < 0:
    print(0)
elif d1 + d2 == 0:
    print("infinity")
else:
    if d1 < 0:
        d1 = -d1
        d2 = -d2
    ok = 0
    ng = (d1 + d1) // (-d1 - d2) + 1
    x = 0
    while ok + 1 < ng:
        mid = (ok + ng) // 2
        s = mid * (d1 + d2)
        if s + d1 > 0:
            ok = mid
        elif s + d1 == 0:
            ok = mid
            ng = ok + 1
            x = -1
        else:
            ng = mid
    print(ng * 2 - 1 + x)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(void){

	char x[1001];
	int sum;
	int i;

	while(scanf("%s",x)!=EOF){

		if(x[0] == '0' && x[1] == '\0')
			break;

		sum = 0;

		for(i=0;i<strlen(x);i++){
			sum += x[i]%'0';
		}

		printf("%d\n",sum);

	}

	return 0;

}

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


int main()
{
    long long int n;
    long long int a, b;

    cin >> n;
    cin >> a;
    cin >> b;

    long long int div;
    long long int mod;
    long long int ans;

    if(a+b == 0){
        cout << 0;
        return 0;
    }

    div = n / (a + b);
    mod = n % (a + b);

    if(mod > a){
        ans = div * a + a;
    }else{
        ans = div * a + mod;
    }

    cout << ans;

    return 0;

}

Measured memory_bytes: 256
/*
   Push yourself, because no one else is going to do it for you.
*/
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long int
#define PI 2 * acos(0.0)
#define MAX 10000000000000000
#define in(a) scanf("%d",&a);
#define out(a) printf("%d",a);
#define INF 1000000 
#define M 1000000007
using namespace std;
vector<ll> printDivisors(ll n) 
{ 
    vector<ll> v; 
    vector<ll> f;
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
  
            if (n / i == i)  
                f.push_back(i); 
            else { 
                f.push_back(i); 
  
                v.push_back(n / i); 
            } 
        } 
    } 
    for (ll i = v.size() - 1; i >= 0; i--){
       f.push_back(v[i]);
    }
  return f;
} 
int main(){ 
   fast_io
   ll n;
   cin>>n;
   vector<ll> v = printDivisors(n);
   ll dis;
   for(ll i = 0;i<v.size();i++){
      ll y = n / v[i];
      ll h = ( v[i]  - 1 ) + (y - 1);
      dis = min(dis,h);
   }
   cout<<dis<<endl;
   return 0; 
}  

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  int N = s.length();
  int K; cin >> K;
  set<string> mem;
  for(int l = 1; l < 6; l++){
    for(int i = 0; i <= N - l; i++){
      mem.insert(s.substr(i, l));
    }
  }
  int c = 0;
  for(string t : mem){
    c++;
    if(c == K){
      cout << t << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 1664
n,m=map(int,input().split())
if n>=m/2:
  print(m//2)
else:
  x=(m-2*n)//4
  y=x+1
  z1=min(n+x,(m-2*x)//2)
  z2=min(n+y,(m-2*y)//2)
  print(max(z1,z2))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}
int main(){
	ll A,B;
	string s,t;
	cin>>A>>B>>s>>t;
	rep(i,A){
		if(i*B%A!=0) continue;
		ll j = i*B/A;
		if(s[i] != t[j]){
			puts("-1");
			return 0;
		}
	}
	cout<<lcm(A,B)<<endl;
}

Measured memory_bytes: 512
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    }

    let mins = h * 60.0 + m;
    let min_a = std::f64::consts::PI * 2.0 / 60.0 * mins;
    let hour_a = std::f64::consts::PI * 2.0 / 720.0 * mins;
    let angle = (min_a - hour_a).abs();

    let ans = (a * a + b * b - 2.0 * a * b * angle.cos()).sqrt();
    println!("{}", ans);
}


Measured memory_bytes: 3052
n = int(input())

a = list(map(int, input().split()))

ans  = 1
hantei = True
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        hantei = False
        break

if a.count(0) >= 1:
    hantei = True
    ans = 0
print(ans) if hantei else print(-1)

Measured memory_bytes: 21796
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
template<typename T>
int sz(const T &a){return (int)a.size();}
lli fivth(lli a){
    return a*a*a*a*a;
}
lli findfi(lli a){
    for(lli i=0;fivth(i)<=a;i++){
        if(fivth(i)==a)return i;
    }
    return LLONG_MIN;
}
int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    lli x;
    cin>>x;
    for(lli i=0;i<=200;i++){
        lli diff=fivth(i)-x;
        if(diff<0){
            if(findfi(-diff)!=LLONG_MIN){
                printf("%lli %lli\n",i,-findfi(-diff));
                return 0;
            }
        }
        else{
            if(findfi(diff)!=LLONG_MIN){
                printf("%lli %lli\n",i,findfi(diff));
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3772
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <vector>

int main() {
  size_t n;
  intmax_t k;
  scanf("%zu %jd", &n, &k);

  std::vector<size_t> a(n);
  for (auto& ai: a) scanf("%zu", &ai), --ai;

  size_t res = 0;
  for (int j = 0; k >> j; ++j) {
    std::vector<size_t> na(n);
    for (size_t i = 0; i < n; ++i) na[i] = a[a[i]];
    if (k >> j & 1) res = a[res];
    a = std::move(na);
  }

  printf("%zu\n", res+1);
}


Measured memory_bytes: 6248
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main()
{
	int n, p, t, x, o;

	cin >> n >> p;
	priority_queue<int> cpp[n];
	while (p--)
	{
		cin >> o >> t;
		if (o > 0)
		{
			if ((o == 1)&&(!cpp[t].empty()))			
					cout << cpp[t].top() << endl; 

			if (o == 2 && !cpp[t].empty())
					cpp[t].pop(); 				
		}
		else 
		{
			cin >> x;
			cpp[t].push(x);
		}
	}
	return 0;
}


Measured memory_bytes: 4016
using System;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var strArray = str.Split(' ');
            var a = int.Parse(strArray[0]);
            var b = int.Parse(strArray[1]);
            var x = a * b;
            var s = x % 2 == 0 ? "Even" : "Odd";
            Console.WriteLine(s);
        }
    }
}

Measured memory_bytes: 27264