akhauriyash/Code-Regression huggingface dataset:
for i in range(input()):
	balls = map(int, raw_input().split())
	a = [balls.pop(0)]
	b = [0]
	flag = 0
	while len(balls) > 0:
		gapa = balls[0] - a[-1]
		gapb = balls[0] - b[-1]
		if gapa < gapb:
			if gapa > 0:
				a.append(balls.pop(0))
			elif gapb > 0:
				b.append(balls.pop(0))
			else:
				flag = 1
		elif gapb < gapa:
			if gapb > 0:
				b.append(balls.pop(0))
			elif gapa > 0:
				a.append(balls.pop(0))
			else:
				flag = 1
		if flag == 1:
			print "NO"
			break
		if len(balls) == 0: print "YES"

Measured memory_bytes: 4248
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n,a,b,c,d;
const int N=1003;
const int mod=1e9+7;
int f[N],dp[N],C[N][N],power[N],F[N][N];

int mu(int x,int m)
{
    if (m==1) return x;
    int c=mu(x,m/2);
    c=(LL)c*c%mod;
    if (m%2==0) return c;
    return (LL)c*x%mod;
}
int main()
{
   
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>a>>b>>c>>d;
    dp[0]=1;
    for (int i=0;i<=n;i++) C[i][i]=C[i][0]=1;
    for (int i=2;i<=n;i++)
    for (int j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    power[0]=1;
    for (int i=1;i<=n;i++) power[i]=((LL)power[i-1]*i)%mod;
    power[n]=mu(power[n],mod-2);
    for (int i=n-1;i>=0;i--) power[i]=(LL)power[i+1]*(i+1)%mod;
    for (int i=1;i<=n;i++) F[0][i]=1;
    for (int i=1;i<=n;i++)
    for (int j=i;j<=n;j+=i)
         F[j][i]=(LL)F[j-i][i]*C[j][i]%mod;
    for (int i=1;i<=n;i++)
    for (int j=i;j<=n;j+=i)
    {
        F[j][i]=(LL)F[j][i]*power[j/i]%mod;
        //cout<<j<<" "<<i<<" "<<F[j][i]<<"\n";
    }
    dp[0]=1;
    for (int i=a;i<=b;i++)
    {
        for (int h=0;h<=n;h++) f[h]=dp[h];
        for (int j=c;j<=d;j++)
        {
            int k=i*j;
            for (int h=k;h<=n;h++)
            {
                dp[h]=(dp[h]+((LL)f[h-k]*F[k][i]%mod)*C[n-h+k][k]%mod)%mod;
                //cout<<i<<" "<<j<<" "<<h<<" "<<dp[h]<<" "<<f[h-k]<<"\n";
            }
        }
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;

const int P_MAX = 1e6;

int main() {
	vector<bool> isPrime(P_MAX + 1, true);
	vector<int> primes(P_MAX / 2, 0);
	isPrime[0] = isPrime[1] = 0;

	for (int i = 4; i <= P_MAX; i += 2) {
		isPrime[i] = false;
	}
	int limit = sqrt(P_MAX);
	for (int i = 3; i <= limit; i += 2) {
		if (!isPrime[i]) {
			continue;
		}
		for (int j = i * 2; j <= P_MAX; j += i) {
			isPrime[j] = false;
		}
	}

	primes[0] = 2;
	int n_p = 1;
	for (int i = 3; i <= P_MAX; i += 2) {
		if (isPrime[i]) {
			primes[n_p] = i;
			n_p++;
		}
	}

	int n, m;
	scanf("%d", &n);
	int count = 0;

	for (int i = 0; i < n; i++) {
		scanf("%d", &m);
		if (m <= P_MAX) {
			count += isPrime[m] ? 1 : 0;
		} else {
			int limit = sqrt(m);;
			bool ok = true;
			for (int j = 0; j < n_p; j++) {
				if (primes[j] > limit) {
					break;
				}
				if (m % primes[j] == 0) {
					ok = false;
					break;
				}
			}
			if (ok) {
				count++;
			}
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 3108
#include <cstdio>

int main(void) {
	while(true) {
		int n;
		scanf("%d", &n);
		if(n == 0)
			break;

		int ans = 0;
		for(int i = 1; i <= 12; i++) {
			int p, q;
			scanf("%d %d", &p, &q);
			n -= p - q;
			if(ans == 0 && n <= 0)
				ans = i;
		}
		if(ans != 0)
			printf("%d\n", ans);
		else
			printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){

  int n,a,b;
  string str;
  
  cin >> a >> b;
  if(a%3==0 || b%3==0 || (a+b)%3==0) cout <<"Possible\n";
  else cout <<"Impossible\n";
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long N = sc.nextLong();
        Long K = sc.nextLong();
        N = N % K;
        N = Math.min(Math.abs(N-K), N);
        System.out.println(N);
    }
}


Measured memory_bytes: 24148
#include<stdio.h>

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

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>

using namespace std;
typedef pair<double, double> P;

void solve()
{
	P p[4];
	while(cin >> p[0].first >> p[0].second)
	{
		for(int i = 1; i < 4; ++i)
		{
			cin >> p[i].first >> p[i].second;
		}
		if(fabs((p[1].first - p[0].first) * (p[3].first - p[2].first) + (p[1].second - p[0].second) * (p[3].second - p[2].second)) < 1e-12)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

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

Measured memory_bytes: 1216
#define REP(i, n) for (int (i) = 0;(i)<(int)(n);(i)++)
#define REPI(i, a, n) for(int (i)=int(a);(i)<int(b);(i)++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back

typedef long long ll;

#include <bits/stdc++.h>

using namespace std;


int main(){
    std::cin.tie(0);

    int n,m;
    cin >> n >> m;

    vector<ll> v[3];
    REP(i,n){
        REP(j,3){
            ll num;
            cin>>num;
            v[j].PB(num);
        }
    }
    ll ans=0,total;
    REP(bit,(1<<3)){
        vector<ll> x;
        total = 0;
        REP(i,n){
            ll tmp=0;
            REP(j,3){
                if(bit &(1<<j)){
                    tmp += v[j][i];
                }else{
                    tmp -= v[j][i];
                }
            }
            x.PB(tmp);
        }
        sort(ALL(x), greater<ll>());
        REP(j,m){
            total+=x[j];
        }
        ans = max(ans, total);
    }
    cout << ans << endl;
}

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

using namespace std;

const int N = 1e5 + 3;

int p, n;

int main() {
  #ifdef GG
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
  #endif
  scanf("%d", &n); int ans = 0, x = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p);
    if (p == i) {
      ++x;
    } else {
      ans += x / 2 + x % 2;
      x = 0;
    }
  }
  ans += x / 2 + x % 2;
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import itertools

N = int(input())

def primes(n):
    primfac = []
    d = 2
    while d*d <= n:
        while (n % d) == 0:
            primfac.append(d)  # supposing you want multiple factors repeated
            n //= d
        d += 1
    if n > 1:
       primfac.append(n)
    return primfac

def F(a,b):
    return max([len(str(a)), len(str(b))])
    
if N == 1:
    print(1)
    exit()
    
l = primes(N)
l.append(1)
ans = []
for i in range(1,len(l)//2+1):
    comb = itertools.combinations(l, i)
    comb = list(set(list(comb)))
    for comblist in comb:
        # print(tmp)
        tmp = 1
        for x in comblist:
            tmp *= x

        ans.append(F(tmp,N//tmp))

# print(ans)
print(min(ans))


Measured memory_bytes: 52024
inp = [int(input()) for _ in range(5)]
rem = [p % 10 if p % 10 != 0 else 10 for p in inp]
idx = rem.index(min(rem))
min_rem = inp[idx]
res = 0
inp.remove(min_rem)
for a in inp:
    if a % 10 == 0:
        res += a
    else:
        res += a + (10 - a % 10)

print(res + min_rem)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

type combi struct{ yukichi, higuchi, natsume int }

func main() {
	var n, y int
	fmt.Scanf("%d %d", &n, &y)
	y /= 1000
	c := search(n, y)
	fmt.Printf("%d %d %d", c.yukichi, c.higuchi, c.natsume)
	return
}

func search(num, y int) combi {
	state := combi{}
	state.natsume = num

	d := (y - price(state)) / 9
	state.yukichi += d
	state.natsume -= d

	if state.natsume < 0 || state.higuchi < 0 || state.yukichi < 0 {
		return combi{-1, -1, -1}
	}

	d = (y - price(state)) / 4
	state.higuchi += d
	state.natsume -= d

	if state.natsume < 0 || state.higuchi < 0 || state.yukichi < 0 {
		return combi{-1, -1, -1}
	}

	d = (y - price(state)) / 3
	state.yukichi -= d
	state.higuchi += 3 * d
	state.natsume -= 2 * d

	if state.natsume < 0 || state.higuchi < 0 || state.yukichi < 0 {
		return combi{-1, -1, -1}
	}

	d = (y - price(state)) / 2
	state.yukichi -= 2 * d
	state.higuchi += 5 * d
	state.natsume -= 3 * d

	if state.natsume < 0 || state.higuchi < 0 || state.yukichi < 0 {
		return combi{-1, -1, -1}
	}

	d = y - price(state)
	state.yukichi -= 3 * d
	state.higuchi += 7 * d
	state.natsume -= 4 * d

	if state.natsume < 0 || state.higuchi < 0 || state.yukichi < 0 {
		return combi{-1, -1, -1}
	}

	return state
}

func adjust(c combi, y int) combi {
	if p := price(c); p > y {
	} else if p < y {
	} else {
	}
	return combi{-1, -1, -1}
}

func price(c combi) int {
	return c.yukichi*10 + c.higuchi*5 + c.natsume
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    ll n;
    cin >> n;
    // map<ll, ll> cnt;
    vector<ll> cnt(100 * 100 * 100, 0);
    reps(x, 100) {
        reps(y, 100) {
            reps(z, 100) {
                cnt[x * x + y * y + z * z + x * y + y * z + z * x]++;
            }
        }
    }
    reps(i, n) { cout << cnt[i] << endl; }
    return 0;
}

Measured memory_bytes: 10716
N, M = map(int, input().split())
 
a = max(N,M)
b = min(N,M)

if b==1:
  if a==1:
    print(1)
  else:
    print(a-2)

elif b==2:
  print(0)
  
else:
  print((a-2)*(b-2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(val) cerr << "Value " << #val << " : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ld epsilon = 10e-9;
const ll nax = 1e5+5;
ll n, arr[nax], ans=0;

int main(void){
	IOS
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> arr[i];
	}
	for(int i=1;i<=n;i++){
		if(arr[i]==i){
			if(i==n){
				swap(arr[i], arr[i-1]);
			}
			else{
				swap(arr[i], arr[i+1]);
			}
			ans++;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 4376
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string.h>
#include <vector>
#include <cmath>
#include <iostream>
#include <unordered_map>
#include <queue>
using namespace std;
typedef unsigned long long ui64;
typedef long long i64;
void ProgrammingEducation() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << "\n";
		return;
	}
	int a, b;
	cin >> a >> b;
	cout << (a + b) << "\n";

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

Measured memory_bytes: 256
#include<stdio.h>
 
int code(char x){
  if(x=='A')return 0;
  if(x=='B')return 1;
  if(x=='C')return 2;
  return -1;
}
 
int main(void){
  int cup[3];
  char x,y;
  int tmp;
 
  cup[0] = 1;
  cup[1] = 0;
  cup[2] = 0;
 
  while(scanf("%c,%c ",&x,&y)!=EOF){
    tmp = cup[code(x)];
    cup[code(x)] = cup[code(y)];
    cup[code(y)] = tmp;
  }
 
  if(cup[0])printf("A\n");
  if(cup[1])printf("B\n");
  if(cup[2])printf("C\n");
 
  return 0;
}

Measured memory_bytes: 528
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k,a,b;
    int flag = 0;
    cin >> k >> a >> b;
    for(int i=1;i<= 1000;i++){
    int temp = i * k;
    if(temp >= a && temp <= b){
    cout << "OK" << endl;
    flag = 1;
    break;
    }
    }
    if(flag == 0)cout << "NG" << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> w(N); rep(i, 0, N) { cin >> w[i]; }
	int l = 0, r = 10000 * 100000;
	auto f = [&](int P) {
		int j(0);
		rep(i, 0, K) {
			int sum(0);
			while (j < N&&sum + w[j] <= P)sum += w[j++];
			if (j == N)return true;
			dump(j);
		}
		return false;
	};
	while (r - l > 1) {
		dump(l, r);
		int mid = (l + r) / 2;
		if (f(mid))r = mid;
		else l = mid;
	}
	cout << r << endl;

	return 0;
}

Measured memory_bytes: 3352
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <ctype.h>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
// #include <pair> 
       
using namespace std;
       
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
 
// #define MAX 100010
 
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
// long long binpow(long long a,long long b)
// {
//     if (b == 1) return a;
//     long long res = binpow(a, b/2)%MOD;
//     if (b % 2) return (res*((res*a)%MOD))%MOD;
//     else return (res * res)%MOD;
// }
 
// long long int fact(long long int a)
// {
//     if(a==0||a==1)
//         return 1;
//     long long int ans = 1;
//     for(int i=a;i>=1;i--)
//         ans = (ans * i);
//     return ans;
// }
 
// long long int ivmod(long long int a)
// {
//     return binpow(a,MOD-2);
// }
 
// long long int ncr(long long int a,long long int b)
// {
//     long long int pans=1;
//     for(int i =a;i>max(b,a-b);i--)
//         pans=pans*i;
//     long long int div = fact(min(b,a-b));
//     // cout<<ans<<"            "<<div<<endl;
//     pans = pans/div;
//     return pans;
// }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif   
    string a,b,c;
    cin>>a>>b>>c;
    char d,e,f;
    d = a[0];
    e = b[0];
    f = c[0];
    cout<<char(toupper(d))<<char(toupper(e))<<char(toupper(f))<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    K, N = map( int, input().split())
    A = list( map( int, input().split()))
    ans = K - A[0] - (K-A[N-1])
    for i in range(N-1):
        if K - (A[i+1] - A[i]) < ans:
            ans = K - (A[i+1] - A[i])
    print(ans)
if __name__ == '__main__':
    main()


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

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

  int A = S.size();
  
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());

  cout << ((A == S.size()) ? "yes" : "no") << endl;
}

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

int main() {
    int l;
    cin >> l;
    string v = to_string(l*l*l / 27) + to_string((long double)((l*l*l)%27)/27L).substr(1);
    cout << v << endl;
    return 0;
}

Measured memory_bytes: 3760
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    P = [int(input_raw[i]) for i in range(N)]
    P_inv = {}

    A = {}
    B = {}
    A[P[0]] = P[0] * N + 1
    B[P[0]] = P[0] * N + 1
    min_B = B[P[0]]
    min_A = A[P[0]]
    for i in range(1, N):

        if P[i] > P[i - 1]:
            A[P[i]] = A[P[i - 1]]  + N*(P[i] - P[i - 1])
            B[P[i]] = B[P[i - 1]] - N *(P[i] - P[i - 1])
        else:
            A[P[i]] = A[P[i - 1]]  - N *(P[i - 1] - P[i])
            B[P[i]] = B[P[i - 1]] + N *(P[i - 1] - P[i])
        min_A = min(min_A, A[P[i]])
        min_B = min(min_B, B[P[i]])

    for i in range(1, N + 1):
        A[P[i - 1]] += -min_A + 1
        B[P[i - 1]] += -min_B + 1
    for i in range(1, N + 1):
        A[P[i - 1]] += i
    for i in range(1, N + 1):
        print A[i],
    print
    for i in range(1, N + 1):
        print B[i],





if __name__ == '__main__':
    main()


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

int main() {
    int A, B;
    bool tf = 0;
    cin >> A >> B;
    for (int i = 1; i <= 1000; i++)
    {
        if(floor(i*0.08) == A && floor(i*0.1) == B){
            tf = 1;
            cout << i << endl;
            break;
        }
    }
    if(tf==0) cout << "-1" << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;

int main(){
  int n,k; cin>>n>>k;
  int ans=0;
  
REP(i,n){
  int h; cin>>h;
  if(h>=k)ans++;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
# ABC_077_C_Sunuke_Festival.py

from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

# B[j]を固定してA[i]<=B[j]<=C[k]を満たす(i,j)の個数を求める
# ソートして二分探索すれば間に合う
A.sort()
# B.sort()
C.sort()
# print(A)
# print(B)
# print(C)


def bisectsearch_left(L, a):
    i = bisect_left(L, a)
    return(i)


def bisectsearch_right(L, a):
    i = bisect_right(L, a)
    return(i)


ans = 0
for j in range(N):
    b = B[j]
    cti = bisectsearch_left(A, b)
    ctk = N-bisectsearch_right(C, b)
    # print(cti, ctk)
    ans += cti*ctk
print(ans)


Measured memory_bytes: 106420
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
#define MOD 1000000007
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(18);
}
ll pow_kai(ll a, ll n){
  ll x = 1;
  while(n > 0){
    if(n&1){
      x = x*a;
      x %= MOD;
    }
    a = a*a;
    a %= MOD;
    n >>= 1;
  }
  return x;
}

vector<ll> eratos(int max){
  vector<ll> res;
  vector<bool> cp_list(max+1,true);
  cp_list[0]=false;
  cp_list[1]=false;
  for(ll i=2;i<=max;i++){
    if(cp_list[i]){
      res.push_back(i);
      for(ll j=2;j*i<=max;j++){
        cp_list[i*j]=false;
      }
    }
  }
  return res;
}
signed main(){
  init_io();
  ll n,k,ans=0,add=1;
  cin >> n >> k;
  vector<ll> dp(k+1,0);
  for(ll i=0;i<n;i++){
    add *= 2;
    add %= MOD;
  }
  add = (add-2+MOD)%MOD;
  for(ll i=k;i>=1;i--){
    ll tmp = 0,ed,val=1;
    for(ed=1;i*ed<=k;ed++){
      tmp++;
    }
    val = pow_kai(tmp,n);
    for(ll j=2;j<ed;j++){
      val = (val - dp[i*j]+MOD)%MOD;
    }
    dp[i] = val;
    ans += val*i;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int dansuu = 0;
  
  int N;
  cin >> N;
  
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    
    cin >> d.at(i);
    
  }
  
  
    
    
  for (int i = 0; i < N; i++) {
    
    int a = d.at(i);
    
    if (a == 0) {
      
      continue;
      
    } else if (a > 0) {
      
      dansuu++;
      
      for(int i = 0; i < N; i++) {
      
        if (a == d.at(i)) {
        
          d.at(i) = 0;
        
        } else {
        
          continue;
        
        }
      
      }
      
    }
    
    
    
  }
  
  cout << dansuu << endl;
  
}
 
  
  


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

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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll N,M,L; cin >> N >> M >> L;
    ll dist[N][N]; REP(i,N)REP(j,N) dist[i][j] = LL_INF;
    REP(i,M){
        ll a,b,c; cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    REP(k,N)REP(i,N)REP(j,N) chmin(dist[i][j], dist[i][k]+dist[k][j]);

    ll dist2[N][N];
    REP(i,N)REP(j,N){
        if(dist[i][j] <= L) dist2[i][j] = 1;
        else dist2[i][j] = LL_INF;
    }
    REP(k,N)REP(i,N)REP(j,N) chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);

    int Q; cin >> Q;
    REP(i,Q){
        int s,t; cin >> s >> t;
        s--; t--;
        if(dist2[s][t] == LL_INF) cout << -1 << endl;
        else cout << dist2[s][t]-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
import numpy as np
import sys
import math
import itertools
import collections

X , N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
else:
    print(X)
    sys.exit()

s = set(P)

m = 1000
ans = None
for i in range(-1,102):
    if i not in s:
        if m > abs(X-i):
            ans = i
            m = abs(X-i)

print(ans)

Measured memory_bytes: 27168
#include <bits/stdc++.h>
#include <tgmath.h>
using ll = long long;
using namespace std;

struct edge{
    int to;
    int id;
};

vector<vector<edge>> edges;

void solve(long long N, std::vector<long long> a, std::vector<long long> b){
    
    queue<pair<ll,ll>> q;
    q.emplace(0,0);
    map<string,ll > m;
    set<ll> already;
    int msize =0;
    int ans[N-1] = {};
    while(!q.empty()){
        ll node = q.front().first;
        already.insert(node);
        ll pcolor = q.front().second;
        q.pop();
        ll notUsed = edges[node].size();
        msize = max(msize,(int)edges[node].size());
        int target = 1;
        for(int i=0;i<edges[node].size();i++){
            edge e = edges[node][i];
            ll to  = edges[node][i].to;
            ll id = edges[node][i].id;
           
            // cerr << "node =" << node << "to=" << to << endl;
            if(target == pcolor){
                    target++;
            }
            if(already.find(to) != already.end()){
                
                continue;
            }
            // cerr << "from =" << node <<" pcolor = " << pcolor<<" to= " << to << " target = " << target << endl;
            q.emplace(to,target);
            ans[id] = target;
            target++;

        }
    }
    cout << msize << endl;
    for(int i=0;i<N-1;i++){
        cout << ans[i] << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    edges.resize(N);

    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        int c,d;
        cin >> c >> d;
        c--;
        d--;
        a[i] = c;
        b[i] = d;
        edges[c].emplace_back((edge){d,i});
        edges[d].emplace_back((edge){c,i});
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


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

int main(){
  int L, R, d;
  int ans = 0;
  cin >> L >> R >> d;
  
  for (int i = L; i <= R; i++){
    if (i % d == 0){
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i, N) cin >> d.at(i);
    sort_g(d);

    int cnt = 0;
    rep(i, N) {
        if(i == 0) {
            cnt++;
        } else {
            if(d.at(i) < d.at(i - 1)) cnt++;
        }
    }

    cout << cnt << endl;
}

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

int main(){
    int n, a[n], b[n];
    cin >> n;
    for(int i=0; i<n; i++) cin >> a[i] >> b[i];
    string ans = "No";
    for(int i=0; i<n-2; i++){
    if(a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2]) ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;

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

    ll a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    ll ans = a1 + a2 + a3;
    if(ans >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int num,pair,sum;
  while(cin >> num && num != 0){
    sum = 0;
    for(int i=0;i<num*(num-1)/2;i++){

      cin >> pair;
      sum += pair;
    //    cout << hairetsu[i][0] << " " << hairetsu[i][1];
    //    cout << endl;
    }
    sum /= num - 1;
    
    cout << sum << endl;
  }
  
  
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, n;
  string S;
  cin >> A >> B;
  
  for (;A <= B; A++) {
    S = to_string(A);
  
    if (S.at(0) == S.at(4) && S.at(1) == S.at(3)) n++;
  
  }
  cout << n;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>




int main(){
  int n,bus,i,muda,ans=0,sum=0,weight=0,mudajougen;
  int *W;
  scanf("%d %d",&n,&bus);
  W=malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&W[i]);
    sum+=W[i];
    if(ans<W[i]) ans=W[i];
  }
  if(ans< sum/bus) ans=sum/bus;
  while(1){
    muda=0;
    weight=0;
    mudajougen=ans*bus-sum;
    for(i=0;i<n;i++){
      if(weight +W[i] <= ans) weight+=W[i];
      else{
        muda+=ans-weight;
        if(muda>mudajougen) break;
        weight=W[i];
      }
    }
    if(i==n) break;
    ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 988
#include<iostream>
#include<utility>
using namespace std;
 
int main(){
    
    int H, W;
    
    while (1){
        cin >> H >> W;
        if ( (H == 0) && (W == 0) ){
            break;
        }

        for ( int i = 0; i < H; i++ ){
            for ( int j = 0; j < W; j++ ){
                if (i == 0 || i == H-1 || j == 0 || j == W-1) {
                cout << "#";
                } else {
                cout << ".";
                }
            }
        cout << endl;
        }
    cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> init(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second
using P = pair<int, int>;

int n, m;
v2<P> adj;
set<P> seen;

void solve(){
    cin >> n >> m;
    adj = v2<P>(n);
    for(int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }

    for(int s = 0; s < n; ++s){
        vector<int> d(n, 1e9), p(n, -1);
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.push({0, s});
        d[s] = 0;
        while(!pq.empty()){
            int node = pq.top().S;
            pq.pop();
            for(P& a : adj[node]){
                int next = a.F, w = a.S;
                if(d[node] + w < d[next]){
                    d[next] = d[node] + w;
                    pq.push({d[next], next});
                    p[next] = node;
                }
            }
        }

        vector<int> v(n, false);
        for(int i = 0; i < n; ++i){
            int node = i;
            while(p[node] != -1){
                if(v[node]) break;
                v[node] = true;
                int a = min(node, p[node]), b = max(node, p[node]);
                seen.insert({a, b});
                node = p[node];
            }
        }
    }

    cout << m - (int)seen.size() << '\n';
}

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

Measured memory_bytes: 3628
def g(a, b):
    m = a * b
    if a < b:
        a, b = b, a
    while True:
        a, b = b, (a % b)
        if b == 0:
            return m // a    
        
N = int(input())
A = list(map(int,input().split()))
MOD = 10 ** 9 + 7
ans = 0
c = 1
for i in range(N):
    c = g(c, A[i])
for i in range(N):
    ans += c // A[i]
print(ans % MOD)

Measured memory_bytes: 4084
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	bool wa[3001];
	bool sh[3001];
	REP(i,3001){
		wa[i]=false;
		sh[i]=false;
	}
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	a*=100;
	b*=100;
	eREP(i,30){
		eREP(j,30){
			if(i*a+j*b<=f)wa[i*a+j*b]=true;
		}
	}
	eREP(i,3000){
		eREP(j,3000){
			if(i*c+j*d<=f)sh[i*c+j*d]=true;
		}
	}
	int ans=0;
	int A,B;
	eFOR(i,1,f){
		eREP(j,f){
			if(wa[i] && sh[j] && i+j<=f && e*i/100>=j){
				//cout<<" "<<j<<" "<<j+i<<endl;
				if(ans<=1000000*j/(i+j)){
					//cout<<"ll"<<endl;
					ans=1000000*j/(i+j);
					A=i;
					B=j;
				}//cout<<"ll"<<endl;
			}
		}
	}
	cout<<B+A<<" "<<B<<endl;
				
	return 0;
}


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

has_zero = 0 in As
num_of_minus = len(list(filter(lambda x: x<0, As)))

abss = list(map(abs, As))
ans = sum(abss)
if num_of_minus%2 != 0:
    ans -= min(abss) * 2
    
print(ans)


Measured memory_bytes: 14412
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        string s = IO.STRING();
        int t = 0;
        string ans = "No";
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'C')
            {
                t = 1;
            }
            if (t == 1 && s[i] == 'F')
            {
                ans = "Yes";
                break;
            }
        }
        IO.WRITE(ans);
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
        public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}

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

int main() {
  ll n;
  cin >> n;
  
  int num = 1;
  rep(i, 20) {
    if ((n - pow(26, i+1)) >= 1) {
      n -= pow(26, i+1);
      num++;
    }
    else break;
  }
  
  const int dig = num;
  vector<char> alpha;
  for (char moji = 'a'; moji <= 'z'; moji++) alpha.push_back(moji);
  rep(i, dig) {
    int cnt = 0;
    rep(i, 30) {
      if ((n - pow(26, num - 1)) >= 1) {
        n -= pow(26, num - 1);
        cnt++;
      }
      else {
        num--;
        break;
      }         
    }
    cout << alpha[cnt];
  }
  
  return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<int> l(n);
    rep(i, n){
        cin >> l[i];
    }
    SORT(l);

    int ans = IINF;
    do{
        REP(i, 1, n + 1){
            REP(j, i + 1, n + 1){
                REP(k, j + 1, n + 1){
                    int val = (k - 3) * 10;
                    int cnt = 0;
                    rep(m, i){
                        cnt += l[m];
                    }
                    val += abs(cnt - a);
                    cnt = 0;
                    REP(m, i, j){
                        cnt += l[m];
                    }
                    val += abs(cnt - b);
                    cnt = 0;
                    REP(m, j, k){
                        cnt += l[m];
                    }
                    val += abs(cnt - c);
                    ans = min(ans, val);
                }
            }
        }
    }while(next_permutation(l.begin(), l.end()));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> A(N); rep(i,N) std::cin >> A[i];

  ll m = 1000, n = 0;
  for(int i=0; i<N; i++) {
    if ( i != 0 ) {
      m += A[i]*n;
      n = 0;
    }

    if ( i+1 < N ) {
      if ( A[i] < A[i+1] ) {
        n = m/A[i];
        m -= A[i]*n;
      }
    }
  }
  std::cout << m << std::endl;
  return 0;
}



Measured memory_bytes: 3656
import java.util.*;
 
class Main {
        private static int[][] c;
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int[] x = new int[N];
                for (int i = 0; i < N; i++) {
                        x[i] = sc.nextInt();
                }
                c = new int[20][N];
                int L = sc.nextInt(), Q = sc.nextInt();
                int idx = 0;
                while (idx < N && x[idx] - x[0] <= L) {
                        idx++;
                }
                if (idx == N) {
                        for (int i = 0; i < Q; i++) {
                                System.out.println(1);
                        }
                        return;
                }
                c[0][0] = idx - 1;
                for (int i = 1; i < N; i++) {
                        while (idx < N && x[idx] - x[i] <= L) {
                                idx++;
                        }
                        if (idx == N) {
                                while (i < N) {
                                        c[0][i] = N - 1;
                                        i++;
                                }
                        } else {
                                c[0][i] = idx - 1;
                        }
                }
                for (int i = 1; i < 18; i++) {
                        for (int j = 0; j < N; j++) {
                                c[i][j] = c[i-1][c[i-1][j]];
                        }
                }
                for (int i = 0; i < Q; i++) {
                        int A = sc.nextInt() - 1, B = sc.nextInt() - 1;
                        if (A > B) {
                                int C = A;
                                A = B;
                                B = C;
                        }
                        System.out.println(calc(A,B));
                }
        }
        public static int calc(int A, int B) {
                int idx = 0;
                while (c[idx][A] < B) {
                        idx++;
                }
                if (idx == 0) {
                        return 1;
                } else {
                        return (1 << (idx - 1)) + calc(c[idx - 1][A], B);
                }
        }
}

Measured memory_bytes: 40744
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <set>
#include <map>
#include <queue>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, m, fa[N];
map<pair<int, int> , int> h; 
queue<pair<int, int> > q;
set<int> s[N];
pair<int, int> code(int x, int y) { return make_pair(min(x, y), max(x, y)); }
int find(int x) { return fa[x] == x?x:fa[x] = find(fa[x]); }
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) fa[i] = i;
    for(int i = 1; i <= (n-1)<<1; ++i)
    {
        int x = read(), y = read();
        if(++h[code(x, y)] == 2) q.push(code(x, y));
        s[x].insert(y), s[y].insert(x);
    }
    while(q.size())
    {
        int x = q.front().first, y = q.front().second; q.pop();
        x = find(x), y = find(y);
        s[x].erase(y), s[y].erase(x);
        if(s[x].size() > s[y].size()) swap(x, y);
        for(set<int>::iterator it = s[x].begin(); it != s[x].end(); ++it)
        {
            h.erase(code(*it, x)), s[*it].erase(x), s[*it].insert(y), s[y].insert(*it);
            if(++h[code(*it, y)] == 2) q.push(code(*it, y));
        }
        s[x].clear(), fa[x] = y;
    }
    for(int i = 1; i <= n; ++i) m += i == find(i);
    if(m == 1) puts("YES"); else puts("NO");
    return 0;
}

Measured memory_bytes: 38712
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>
#define NIL -1
#define MAX 100005
using namespace std;
struct Node {
    int p, l, r;
};
Node T[MAX];
int n, D[MAX];
void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    if(T[u].p == NIL) {
        cout << "root, ";
    } else if(T[u].l == NIL) {
        cout << "leaf, ";
    } else {
        cout << "internal node, ";
    }
    cout << "[";
    if(T[u].l != NIL) {
        cout << T[u].l;
        Node node = T[T[u].l];
        while(node.r != NIL) {
            cout << ", ";
            cout << node.r;
            node = T[node.r];
        }
    }
    cout << "]\n";
}

void rec(int r, int d) {
    D[r] = d;
    if(T[r].l != NIL) {
        rec(T[r].l, d+1);
    }
    if(T[r].r != NIL) {
        rec(T[r].r, d);
    }
}
int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for(int i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

    for(int i=0; i<n; i++) {
        cin >> v >> d;
        for(j=0; j<d; j++) {
            cin >> c;
            if(j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for(int i=0; i<n; i++) {
        if(T[i].p == NIL) r = i;
    }
    rec(r, 0);

    for(int i=0; i<n; i++) {
        print(i);
    }
}



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

int main()
{
    int n;
    int k;
    cin>>n>>k;
    int M=1;
    for(int i=0;i<9;i++)
    {
        M*=10;
    }
    M+=7;
    long long int c[2][2000];
    long long int d[2][2000];
    for(int i=0;i<=2000;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0||j==i)
            {
                c[i%2][j]=1;
            }
            else
            {
                c[i%2][j]=(c[(i-1)%2][j-1]+c[(i-1)%2][j])%M;
            }
            if(i==k-1)
            {
                d[0][j]=c[i%2][j];
            }
            if(i==n-k+1)
            {
                d[1][j]=c[i%2][j];
            }
        }
        if(i>=k-1&&i>=n-k+1)
        {
            break;
        }
    }
    for(int i=1;i<=k;i++)
    {
        if(k>=i-1&&k<=n-i+1)
        {
            cout<<(d[0][k-i]*d[1][i])%M<<endl;
        }
        else
        {
            cout<<"0"<<endl;
        }
    }
}

Measured memory_bytes: 256