akhauriyash/Code-Regression huggingface dataset:
n=gets.to_i
a=gets.split.map(&:to_i)
b=[]
if a.length%2==0
(a.length).times  do |i|
    v=a.shift
    if i%2!=0
        b.unshift(v)
    else
        b.push(v)
    end
end
else
    (a.length).times  do |i|
    v=a.shift
    if i%2!=0
        b.push(v)
    else
        b.unshift(v)
    end
    end
   
end
puts  b.join(" ")

Measured memory_bytes: 37320
#include<bits/stdc++.h>
using namespace std;
int n,q;
vector<int> edge[200010];
int f[200010];
bool book[200010];
int ans[200010];
void solve(int x,int tot)
{
	if(book[x]) return;
	book[x]=1;
	tot+=f[x];
	ans[x]=tot;
	for(vector<int>::iterator it=edge[x].begin();it!=edge[x].end();it++)
	solve(*it,tot);
}
int main()
{
	cin>>n>>q;
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	for(int i=1;i<=q;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		f[x]+=y;
	}
	solve(1,0);
	for(int i=1;i<=n;i++)
	printf("%d ",ans[i]);
}

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

int main() {

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

  vector< vector< long long int > > a;

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

    vector< long long int > v;

    for ( long long int j = 0; j < m; j++ ) {

      long long int in;
      cin >> in;
      v.push_back( in );

    }

    a.push_back( v );

  }

  vector< long long int > b;
  for ( long long int i = 0; i < m; i++ ) {
    long long int in;
    cin >> in;
    b.push_back( in );
  }

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

    long long int cnt = 0;
    for ( long long int j = 0; j < m; j++ ) {

      cnt += a[i][j] * b[j];

    }

    cout << cnt << endl;

  }


  return 0;

}

Measured memory_bytes: 1324
N , M = map(int,input().split())
drink = []
for _ in range(N):
    a , b = map(int,input().split())
    drink.append([a,b])
drink.sort()


value = 0
hold = 0
while hold != M:
    if drink[0][1] == 0:
        drink.pop(0)
    value += drink[0][0]
    hold += 1
    drink[0][1] -= 1
print(value)

Measured memory_bytes: 20064
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int a, b;
int main()
{
	while(scanf("%d %d", &a, &b) != EOF)
	{
		if(a == 1 || b == 1)
		{
			if(a == 1 && b != 1) printf("Alice");
			else if(a != 1 && b == 1) printf("Bob\n");
			else if(a == 1 && b == 1) printf("Draw\n");
		}
		else if(a != 1 && b != 1)
		{
			if(a > b) printf("Alice\n");
			else if(a == b) printf("Draw\n");
			else printf("Bob");
		}
	}
}

Measured memory_bytes: 128
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node
{
  int p, l, r;
};

Node T[MAX];

void preParse(int u)
{
  if (u == NIL)
  {
    return;
  }
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u)
{
  if (u == NIL)
  {
    return;
  }
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}

void postParse(int u)
{
  if (u == NIL)
  {
    return;
  }
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

int main()
{
  //freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
  int size;
  scanf("%d", &size);
  for (int i = 0; i < size; i++)
  {
    T[i].p = NIL;
  }
  for (int i = 0; i < size; i++)
  {
    int nd, left_child, right_child;
    scanf("%d%d%d", &nd, &left_child, &right_child);
    T[nd].l = left_child;
    T[nd].r = right_child;
    if (left_child != NIL)
    {
      T[left_child].p = nd;
    }
    if (right_child != NIL)
    {
      T[right_child].p = nd;
    }
  }
  int root;
  for (int i = 0; i < size; i++)
  {
    if (T[i].p == NIL)
    {
      root = i;
    }
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  //fclose(stdout);
  //fclose(stdin);
  return 0;
}



Measured memory_bytes: 2736
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,j,w,tmp;
  int *A;
  int n,count=0;

    scanf("%d",&n);

  
  A = (int *)malloc(n * sizeof(int));
  

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

  for(i=0; i<(n-1) ; i++){
    
    for(j=(n-1); j>i ; j--){
      
      if(A[j-1] > A[j]){
      tmp=A[j-1];
      A[j-1] = A[j];
      A[j] = tmp;
      count++;
    }
  }
}

  
  for(w=0; w<n ; w++){

    if(w==n-1){
      printf("%d\n",A[w]);
      break;
    }
    
      printf("%d ",A[w]);
  
}


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



Measured memory_bytes: 2124
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vvi s(n);
    rep(i,n) {
        int m;
        cin >> m;
        s[i].resize(m);
        cin >> s[i];
        sort(rall(s[i]));
    }
    vi now(n,0);
    ll ans = 0;
    set<P> st;
    rrep(i,n) {
        st.insert({s[i][0],i});
        auto it = st.end();
        it--;
        ans += it->first;
        int ind = it->second;
        st.erase(it);
        now[ind]++;
        if(now[ind] < s[ind].size()) st.insert({s[ind][now[ind]],ind});
    }
    cout << ans << endl;
}



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



int main(){
    ll N;
    cin>>N;
    vector<pair<ll,ll>> tasks;
    bool ok = true;
    for(int i=0;i<N;i++){
        ll a,b;cin>>a>>b;
        tasks.push_back(make_pair(b,a));
    }
    sort(tasks.begin(),tasks.end());
    //for(int i=0;i<N;i++)cout<<tasks[i].first<<endl;
    ll now1 = 0;
    ll now2 = 0;
    for(ll i=0;i<N;i++)
    {
        now1+=tasks[i].second;
        if(tasks[i].first<now1){
            ok=false;break;
        }
        now2+=tasks[i].second;
        if(tasks[i].first<now2){
            ok=false;break;
        }
        now1=min(now1,now2);
        now2=max(now1,now2);
    }
    if(ok) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 7360
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;
        static List<Tuple<int, int>> X;
        
        
        

        public static void Input()
        {
            var cin = new Scanner();
            N = int.Parse(Console.ReadLine());
            X = new List<Tuple<int, int>>(N);
            var input = cin.SplitReader();
            for(var i = 0; i < N; i++)
            {
                X.Add(new Tuple<int, int>(input[i], i));
            }
        }

        static void Main(string[] args)
        {
            Input();

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            X.Sort();
            int[] ans = new int[N];
            for(var i = 0; i < N; i++)
            {
                if (i <= (N / 2) - 1)
                {
                    ans[X[i].Item2] = X[N / 2].Item1;
                }
                else
                {
                    ans[X[i].Item2] = X[(N / 2) - 1].Item1;
                }
            }

            for(var i = 0; i < N; i++)
            {
                Console.WriteLine(ans[i]);
            }

            Console.Out.Flush();

        }





    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



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

int main(){
    int N; cin >> N;
    vector<int> C(N,0),S(N,0),F(N,0);
    for(int i = 0; i < N-1; i++) cin >> C[i] >> S[i] >> F[i];
    for(int i = 0; i < N; i++){
        int t = 0;
        for(int j = i; j < N-1; j++){
            if(t < S[j]) t = S[j];
            else if(t % F[j] == 0);
            else t = t + F[j] - t % F[j];
            t += C[j];
        }
        cout << t << endl;
    }
}




Measured memory_bytes: 3632
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#define repe(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mst(a, b)   memset((a), (b), sizeof(a))
#define gc() gutchar()
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pr;
typedef long long ll;
const double eps = 1e-5;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const ll mod = 1e9+7;
const int N = 1e6+5;

ll p[N], mp[N];

ll power(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mod;
		a = a * a % mod; b >>= 1;
	}
	return res % mod;
}

int main()
{
	ll n, cs = 0; 
	scanf("%lld", &n);
	repe(i, 1, n){
		scanf("%lld", &p[i]);
		cs = max(cs, p[i]);
	}
	for (ll i = 1; i <= n; i++)
	{
		ll x = p[i];
		ll y = sqrt(x);
		for (ll j = 2; j <= y; j++)
		{
			ll cnt = 0;
			while (x % j == 0)
			{
				x /= j;
				cnt++;
			}
			mp[j] = max(mp[j], cnt);
		}
		if (x != 1)	mp[x] = max(mp[x], 1ll);
	}
	ll sum = 1;
	for (ll i = 1; i <= cs; i++)
		sum = (sum % mod * power(i, mp[i]) % mod) % mod;
	ll res = 0;
	for (ll i = 1; i <= n; i++)
		res += sum * power(p[i], mod - 2) % mod;
	cout << res % mod << '\n';
	return 0;
}

Measured memory_bytes: 8832
while True: #永遠にループをする
    a = b = c = 0 #変数の初期化
    i,j = map(int,input().split()) #標準入力
    if i == 0 and j == 0:break #入力値が両方0ならループを終了する
    else: #そうでなければ
        j -= i #差額を計算する
        a = j // 1000 #1000円札の必要枚数を計算する
        b = (j - a * 1000) // 500 #500円の必要枚数を計算する
        c = (j - a * 1000 - b * 500) // 100 #100円の必要枚数を計算する
        print(str(c) + " " + str(b) + " " + str(a)) #出力


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

const int maxN = 55;
const int maxS = maxN*maxN;
int n, a, x[maxN];
long long dp[2][2*maxS];

int main() {
    scanf("%d%d", &n, &a);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &x[i]);
        x[i] -= a;
    }

    dp[0][maxS] = 1;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 2*maxS; ++j) {
            if (dp[0][j] > 0) {
                dp[1][j] += dp[0][j];
                dp[1][j+x[i]] += dp[0][j];
            }
        }
        for(int j = 0; j < 2*maxS; ++j) {
            dp[0][j] = dp[1][j];
            dp[1][j] = 0;
        }
    }

    printf("%lld", dp[0][maxS]-1);

    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s =sc.next();
        long ans = 0;
        for(int i = 0;i < (1<<s.length()-1);i++){
            StringBuilder sb = new StringBuilder();
            sb.append(s.charAt(0));
            for(int j = 0;j < s.length()-1;j++){
                if((1&(i>>j))==1){
                    sb.append("+");
                }
                sb.append(s.charAt(j+1));
            }
            String[] ss=sb.toString().split("\\+");
            for(String a:ss){
                ans+=Long.parseLong(a);
            }
        }
        System.out.println(ans);
    }    
    
}







Measured memory_bytes: 21972
#include <cstdio>
#include <algorithm>

#define INF 100000000000

using namespace std;

int main() {
    int A, B, Q;
    scanf("%d %d %d", &A, &B, &Q);
    long s[A], t[B], x;
    for (int i=0; i<A+B; i++) {
        if (i<A) scanf("%ld", &s[i]);
        else scanf("%ld", &t[i-A]);
    }
    for (int i=0; i<Q; i++) {
        scanf("%ld", &x);
        int is = upper_bound(s, s+A, x) - s, it = upper_bound(t, t+B, x) - t;
        long es = is > 0 ? x - s[is-1] : INF,  ws = is < A ? s[is] - x : INF,
             et = it > 0 ? x - t[it-1] : INF,  wt = it < B ? t[it] - x : INF;
        long best = min(min(max(es,et), max(ws,wt)), min(min(es,wt)+es+wt, min(ws,et)+ws+et));
        printf("%ld\n" ,best);
    }
    return 0;
}

Measured memory_bytes: 2816
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>

using namespace std;

int query(vector<int> indices) {
  printf("?");
  for (auto i : indices) printf(" %d", i + 1);
  printf("\n");
  fflush(stdout);
  char result[20];
  scanf("%s", result);
  if (result[0] == 'R') return 0;
  if (result[0] == 'B') return 1;
  exit(0);
  return -1;
}

int n;
int query_range(int start) {
  vector<int> q;
  for (int i = 0; i < n; i++) q.push_back(start + i);
  return query(q);
}

int main() {
  scanf("%d", &n);
  vector<int> result(2 * n, -1);
  int last = -1;
  vector<int> base;
  vector<int> base2;
  {
    int lcolor = query_range(0), lpos = 0;
    int rcolor = 1 - lcolor, rpos = n;
    int low = 1, high = n - 1;
    while (low <= high) {
      int mid = (low + high) / 2;
      int mcolor = query_range(mid);
      if (mcolor == lcolor) {
        lpos = mid;
        low = mid + 1;
      } else {
        rpos = mid;
        high = mid - 1;
      }
    }

    int L = lpos, R = rpos + n - 1;
    result[L] = lcolor;
    result[R] = rcolor;
    for (int j = 0; j < 2 * n; j++) {
      if (j == L || j == R) continue;
      if (j > L && j < R) base.push_back(j);
      else base2.push_back(j);
    }
  }
  for (int i = 0; i < 2 * n; i++) {
    if (result[i] != -1) continue;
    vector<int> qset;
    if (binary_search(base.begin(), base.end(), i)) {
      qset = base2;
      qset.push_back(i);
      result[i] = query(qset);
    } else {
      qset = base;
      qset.push_back(i);
      result[i] = query(qset);
    }
  }
  string ans = "! ";
  for (int i = 0; i < 2 * n; i++) if (result[i] == 0) ans.push_back('R'); else ans.push_back('B');
  printf("%s\n", ans.c_str());
  return 0;
}


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

using namespace std;

using ll = long long;

const string KEY = "keyence";

const int N = 1e6 + 5;

const ll MOD = 1e9 + 7;

pair<bool, bool> nums[N];
ll mul[N];

ll solve() {
    ll n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        int d;
        scanf("%d", &d);
        if (nums[d].first) {
            return 0;
        }
        nums[d].first = true;
    }
    for (int i = 0; i < m; ++i) {
        int d;
        scanf("%d", &d);
        if (nums[d].second) {
            return 0;
        }
        nums[d].second = true;
    }

    ll vacant = 0;
    ll hor = 0; // first
    ll ver = 0; // second

    ll res = 1;

    for (ll i = n * m; i >= 1; --i) {
        if (nums[i].first && nums[i].second) {
            vacant += hor + ver;
            ++hor;
            ++ver;
        } else if (nums[i].first) {
            if (ver == 0) {
                return 0;
            }
            vacant += ver - 1;
            ++hor;
            res = (res * ver) % MOD;
        } else if (nums[i].second) {
            if (hor == 0) {
                return 0;
            }
            vacant += hor - 1;
            ++ver;
            res = (res * hor) % MOD;
        } else {
            if (vacant == 0) {
                return 0;
            }
            res = (res * vacant) % MOD;
            --vacant;
        }
    }

    return res;
}

int main() {
#ifdef LOCALHOST
    freopen("input", "r", stdin);
#endif
    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 2304
if __name__ == '__main__':
	N, M = map(int, input().split())
	flg = 0
	lst = [-1,-1,-1]
	for i in range(M):
		s, c = map(int, input().split())
		if lst[s-1] != -1:
			if lst[s-1] != c:
				flg = 1
				break
		else:
			lst[s-1] = c

	a = 0

	if lst[0] == 0:
		flg = 1

	for i in range(N):
		if lst[i] != -1:
			a += lst[i] * 10**(N-i-1)

	if len(str(a)) < N:
		a += 10**(N-1)

	if N == 1 and lst[0] == 0:
		print(0)
	elif flg == 1:
		print(-1)
	else:
		print(a)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

string s, t;

int main() {
	fastio; cin >> s >> t;
	if (s == t.substr(0, s.length())) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 3648
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


int X;
vector<pair<int,int>> stack;
signed main(){
    scanf("%lld",&X);
    rep(i,10000){
        if(i*i*i*i*i>LLINF)break;
        stack.pb(mp(i*i*i*i*i,i));
        stack.pb(mp(-i*i*i*i*i,-i));
    }
    sort(stack.begin(),stack.end());
    rep(i,stack.size()){
        int A5=stack[i].first;
        auto B5itr=lower_bound(stack.begin(), stack.end(), mp(A5-X,(int)-LLINF));
        if(B5itr->first==A5-X){
            printf("%lld %lld\n",stack[i].second,B5itr->second);
            return 0;
        }
    }
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int main2() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K % 2 == 1) {
    cout << -A + B << endl;
  } else {
    cout << A - B << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> t(1010), a(1010);
    for(int i = 0; i < n; i++)
    {
        cin >> t[i] >> a[i];
    }
    ll T=t[0], A=a[0];
    // cout << "---------" << endl;
    for(int i = 1; i < n; i++)
    {
        ll num;
        if((T+t[i]-1)/t[i]>(A+a[i]-1)/a[i]) num = (T+t[i]-1)/t[i];
        else num = (A+a[i]-1)/a[i];

        A = a[i]*num;
        T = t[i]*num;
        // cout << T << ' ' << A << endl;
    }
    
    cout << A + T << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;

int main(){
  bool f = true;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x & 1) {
      f = false;
    }
  }
  if (f) {
    puts("second");
  } else {
    puts("first");
  }
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int n;
	cin >> n;
	int p[n+10],q[n+10];
	rep(i,n) cin >> p[i];
	rep(i,n) cin >> q[i];
	int pp = 0,qq = 0,base = 1;
	for(int i = n-1; i >= 0; i--){
		pp += p[i]*base;
		qq += q[i]*base;
		base *= 10;
	}

	if(pp == qq){
		cout << 0 << endl;
		return 0;
	}

	vi a,tmp;
	rep(i,n) tmp.push_back(i+1);
	do{
		int num = 0;
		base = 1;
		for(int i = n-1; i >= 0; i--){
			num += tmp[i]*base;
			base *= 10;
		}
		a.push_back(num);
	}while(next_permutation(all(tmp)));
	sort(all(a));

	base = -1;
	for(int i = 0; i < a.size(); i++){
		if(base == -1){
			if(a[i] == pp || a[i] == qq) base = i;
		}else{
			if(a[i] == pp || a[i] == qq){
				cout << i - base << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	ll A,B,C,K,S;
	cin >> A >> B >> C >> K;
if(K%2 == 0) S=A-B;
else S=-A+B;
	if(abs(S)>1e18) cout <<"Unfair"<<endl;
	else cout << S << endl;
	return 0;
}

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

using namespace std;

struct shirt{
    int l;
    int r;
    int h;
    shirt(int a,int b,int c){
        l=a;
        r=b;
        h=c;
    }
};

int main(){
    int d,n;
    cin>>d>>n;
    vector<int> temp(d);
    for (int i = 0; i < d; ++i) {
        cin>>temp[i];
    }
    vector<shirt> sv;
    for (int i = 0; i < n; ++i) {
        int a,b,c;
        cin>>a>>b>>c;
        sv.emplace_back(a,b,c);
    }
    vector<vector<int>> dp(d,vector<int>(n,-1));
    for (int i = 0; i < n; ++i) {
        if(sv[i].l>temp[0]||sv[i].r<temp[0])dp[0][i]=-1;
        else dp[0][i]=0;
    }
    for (int i = 1; i < d; ++i) {
        for (int j = 0; j < n; ++j) {
            if(sv[j].l>temp[i]||sv[j].r<temp[i]){
                dp[i][j]=-1;
                continue;
            }
            int tans=-1;
            for (int k = 0; k < n; ++k) {
                if(dp[i-1][k]==-1)continue;
                tans=max(tans,dp[i-1][k]+abs(sv[j].h-sv[k].h));
            }
            dp[i][j]=tans;
        }
    }
    int ans=-1;
    for (int i = 0; i < n; ++i) {
        ans=max(ans,dp[d-1][i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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; }
class ModInt {
  static int MOD;
  long long x;

 public:
  static void mod(int m) { MOD = m; }

  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) x += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = (x * r.x) % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(long long n) const {
    if (n < 0) return pow(-n).inverse();

    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }

  long long val() { return x; }
};
int ModInt::MOD = 1000000007;

int main() {
  ModInt::mod(998244353);

  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  enum State {
    PENDING,
    OPEN,
    CLOSED,
  };
  vector<vector<vector<ModInt>>> dp(
      N + 1, vector<vector<ModInt>>(S + 1, vector<ModInt>(3, 0)));
  dp[0][0][PENDING] = 1;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < S + 1; ++j) {
      dp[i + 1][j][CLOSED] += dp[i][j][CLOSED];

      // i not in X
      dp[i + 1][j][OPEN] += dp[i][j][OPEN];
      dp[i + 1][j][CLOSED] += dp[i][j][OPEN];
      // i in X
      if (j - A[i] >= 0) {
        dp[i + 1][j][OPEN] += dp[i][j - A[i]][OPEN];
        dp[i + 1][j][CLOSED] += dp[i][j - A[i]][OPEN];
      }

      // i not in X
      dp[i + 1][j][PENDING] += dp[i][j][PENDING];
      dp[i + 1][j][OPEN] += dp[i][j][PENDING];
      // i in X
      if (j - A[i] >= 0) {
        dp[i + 1][j][OPEN] += dp[i][j - A[i]][PENDING];
        dp[i + 1][j][CLOSED] += dp[i][j - A[i]][PENDING];
      }
    }
  }

  cout << dp[N][S][CLOSED] << endl;
  return 0;
}


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

int main(){
  string s;
  cin>>s;
  ll ans=(s.size()*(s.size()-1))/2+1;
  string t="abcdefghijklmnopqrstuvwxyz";
  ll vec[26]={};
  for(int i=0;i<s.size();i++){
    for(int j=0;j<26;j++){
      if(s[i]==t[j]){
        vec[j]++;
      }
    }
  }
  for(int i=0;i<26;i++){
    ans-=(vec[i]*(vec[i]-1))/2;
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == b + c) || (b == c + a) || (c == a + b)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include<iostream>

int main(){
  while(true){
    int m, f, r;
    std::cin >> m;
    std::cin >> f;
    std::cin >> r;

    if(m == -1 && f == -1 && r == -1){
      break;
    }

    char rank;
    if(m == -1 || f == -1){
      rank = 'F';
    }else if(m + f >= 80){
      rank = 'A';
    }else if(m + f >= 65){
      rank = 'B';
    }else if(m + f >= 50){
      rank = 'C';
    }else if(m + f >= 30){
      if(r >= 50) rank = 'C';
      else rank = 'D';
    }else{
      rank = 'F';
    }
    std::cout << rank << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3088
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    auto ans = new long[](10_000_000);
    foreach (x; 1 .. 500)
        foreach (y; 1 .. 500)
            foreach (z; 1 .. 500)
            {
                long n = x * x + y * y + z * z + x * y + y * z + z * x;
                // dprint(x, y, z, n);
                ans[n]++;
            }
    foreach (i; 1 .. N + 1)
    {
        writeln(ans[i]);
    }
}


Measured memory_bytes: 81780
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, R: int):
    return R + (0 if N >= 10 else 100*(10-N))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    print(f'{solve(N, R)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75216
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		long firstMax = 0;
		long secondMax = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		boolean firstFound = false;
		for (int i = n-2; i >= 0; i--) {
			if (a[i] == a[i+1]) {
				if (firstFound) {
					secondMax = (long)a[i];
					break;
				} else {
					firstFound = true;
					firstMax = (long)a[i];
					a[i] = 0;
				}
			}
		}
		System.out.println(firstMax * secondMax);
	}

}


Measured memory_bytes: 50196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  //if(a == 0)a++;
  //if(b == 0)b++;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if((i < b ^ j < a))cout << 0;
      //else if(h >= 2 && w >= 2 && i >= h - b - 1 && j >= w - a - 1)cout << 0;
      else cout << 1;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    E[][] e=new E[n][];
    for(int i=0;i<n;i++){
      int a=sc.nextInt();
      e[i]=new E[a];
      for(int j=0;j<a;j++){
        e[i][j]=new E(sc.nextInt()-1,sc.nextInt());
      }
    }
    int max=0;
    for(int i=0;i<1<<n;i++){
      boolean katei=true;
      for(int j=0;j<n;j++){
        if((i>>j&1)==1){
          for(int k=0;k<e[j].length;k++){
            if((i>>e[j][k].i&1)!=e[j][k].h){
              katei=false;
              break;
            }
          }
          if(!katei){
            break;
          }
        }
      }
      if(katei){
        int cnt=0;
        for(int j=0;j<n;j++){
          if((i>>j&1)==1){
            cnt++;
          }
        }
        max=Math.max(cnt,max);
      }
    }
    System.out.println(max);
  }
  static class E{
    int i;
    int h;
    E(int i,int h){
      this.i=i;
      this.h=h;
    }
  }
}

Measured memory_bytes: 22484
n = int(input())
v = list(map(int, input().split()))
odd = dict()
even = dict()
odd[-1] = 0
even[-1] = 0

for i in range(n):
    if (i + 1) % 2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1

odd_values = sorted(list(odd.values()), reverse=True)
for key, val in odd.items():
    if val == odd_values[0]:
        odd_1 = key
    elif val == odd_values[1]:
        odd_2 = key

even_values = sorted(list(even.values()), reverse=True)
for key, val in even.items():
    if val == even_values[0]:
        even_1 = key
    elif val == even_values[1]:
        even_2 = key

if odd_1 != even_1:
    res = n - odd_values[0] - even_values[0]
else:
    res = min(n - odd_values[0] - even_values[1], 
              n - odd_values[1] - even_values[0])
print(res)
# print(odd)
# print(even)

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

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

#define X real()
#define Y imag()

typedef int Real;
typedef complex<Real> Point;

double nearestTwoPoints(vector<Point> &vp) {
  random_shuffle(vp.begin(), vp.end());
  double d = sqrt((double)norm(vp[0] - vp[1]));
  unordered_map<int, vector<unsigned short>> mp;
  for (int i : range(2)) mp[(int)floor(vp[i].X / d) * 76647 + (int)floor(vp[i].Y / d)].emplace_back(i);
  for (int i : range(2, vp.size())) {
    double dd = 1e9;
    int x = floor(vp[i].X / d), y = floor(vp[i].Y / d);
    for (int xx : range(x - 1, x + 2)) for (int yy : range(y - 1, y + 2)) {
      for (int j : mp[(int)xx * 76647 + (int)yy]) dd = min(dd, sqrt((double)norm(vp[i] - vp[j])));
    }
    if (dd < d) {
      d = dd;
      mp.clear();
      for (int j : range(i + 1)) mp[(int)floor(vp[j].X / d) * 76647 + (int)floor(vp[j].Y / d)].emplace_back(j);
    } else {
      mp[(int)x * 76647 + (int)y].emplace_back(i);
    }
  }
  return d;
}

int main() {
  int n;
  cin >> n;
  vector<Point> p(n);
  for (int i : range(n)) {
    Real x, y;
    cin >> x >> y;
    p[i] = Point(x, y);
  }
  double res = nearestTwoPoints(p);
  cout << (int)(res * res + 0.5) << endl;
}

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



int main(){
  int64_t N;
  cin>>N;
  
  vector<int64_t> vec(N);
  vector<int64_t> moto(N);
  for(int i=0;i<N;i++){
    int64_t m;
    cin>>m;
    vec.at(i)=m;
    moto.at(i)=m;
  }
  sort(vec.begin(),vec.end());
  int64_t a=vec.at(N/2-1);
  int64_t b=vec.at(N/2);
  for(int i=0;i<N;i++){
    int64_t p=moto.at(i);
    if(p<=a) cout<<b<<endl;
    else if(p>=b) cout<<a<<endl;
    
  }

}

Measured memory_bytes: 6316
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long A,B;
    cin>>A>>B;
    long long suda=0;
    long long manabu=0;
    for(int i=0;i<A;i++){
        long long a;
        cin>>a;
        suda+=a;
    }
    for(int l=0;l<B;l++){
        long long b;
        cin>>b;
        manabu+=b;
    }
    cout<<suda*manabu<<endl;
}


Measured memory_bytes: 3108
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    sort(a.begin(),a.end());
    ll ans = 1333333333333333;

    for(int i = 0; i+k-1 < n; i++){
        ans = min(ans,a[i+k-1]-a[i]);
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define int          long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define repr(i,x,m)  for(int i=x;i>=m;i--)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define pi           pair<int,int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define pqs          priority_queue<int,vi,greater<int> >
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define FIO         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
     int n,k;
     cin>>n>>k;
     int a[n];
     rep(i,0,n)
     {
     	cin>>a[i];
     }
     rep(i,k,n)
     {
     	if(a[i]>a[i-k])
     	{
     		cout<<"Yes\n";
     	}
     	else
     	{
     		cout<<"No\n";
     	}
     }

}

signed main()
{
        FIO
        // #ifndef ONLINE_JUDGE
        //   freopen("input.txt","r",stdin);
        //   freopen("output.txt","w",stdout);
        // #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}

Measured memory_bytes: 5360
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<cstring>
#include<utility>
#include<string>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define int long long
#define pb push_back
#define ppb pop_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define cfM 998244353
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define inf 10000000000000000
#define sp setprecision(9)
float pi=3.14159265;
int max(int b,int a)
{if(b>a)return b;else return a;}
int min(int b,int a)
{if(b<a)return b;else return a;}
int ab(int b)
{if(b<0) return (-1*b);else return(b);}
void print(vector<int>&v)
{
	fr(i,v.size())
	cout<<v[i]<<" ";
	cout<<endl;
}
void print(int arr[],int n)
{
	for(int i=0;i<n;i++)
		cout<<arr[i]<<" ";}
int32_t main()
{
	string arr[3]={"Sunny","Cloudy","Rainy"};
	string s;
	cin>>s;
	if(s==arr[0])
		cout<<arr[1];
	else if(s==arr[2])
		cout<<arr[0];
	else
		cout<<arr[2];
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

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


int main(void) {
    int i,j;
    int n,k,t,u,v,l;
    cin >> n >> k >> t >> u >> v >> l;
    vi a(l,0);
    rep(i,n){
        int d;
        cin >> d;
        a[d]++;
    }
    double ans = 0;
    int cnt = 0;
    int ne = -1;
    rep(i,l){
        if(a[i])cnt++;
        if((cnt && i >= ne) || cnt > k){
            cnt--;
            ne = i + t * v;
        }
        if(i < ne){
            ans += 1.0/v;
        }else{
            ans += 1.0/u;
        }
    }
    cout << shosu(10) << ans << endl;
}



Measured memory_bytes: 3320
n = int(input())
ma = []
for _ in range(n):
    tmp = list(map(int,input().split()))
    ma.append(tmp)
ma.reverse()

count = 0
for m in ma:
    a = m[0]+count
    b = m[1]
    if a == 0:
        #count += b
        continue
    if a%b != 0:
        amari = a%b
        addition = b - amari
        count += addition
print(count)

Measured memory_bytes: 62808
def main():
    a,b,c,d,e,f = map(int,input().split())
    ans = []
    for i in range(f//a//100+1):
        for j in range((f-100*a*i)//b//100+1):
            if a*i*100+b*j*100 < f:
                ans.append([i,j])
    ans = ans[1:]
    D = 0
    A = [0,0]
    for an in ans:
        m = a*100*an[0] + b*100*an[1]
        slv = e*m//100
        M = 0
        for i in range(min(f-m,slv)//c+1):
            for j in range((min(f-m,slv)-c*i)//d+1):
                if i*c+d*j <= min(slv,f-m):
                    if M < i*c+d*j:
                        M = i*c+d*j
        den = M/(m+M)
        if den>=D:
            D = den
            A = [m+M,M]
    print(' '.join([str(a) for a in A]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9212
#%%
N = int(input())
#import time
#s = time.time()

def ternary (n):
    if n == 0:
        return '0'
    nums = []
    while n:
        n, r = divmod(n, 3)
        nums.append(str(r))
    return ''.join(reversed(nums))

l = []

for i in range(3**9):
    tmp = ternary(i)
    tmp_list = list(tmp)
    tmp2 = ''
#    if tmp_list[0] != '0' and len(tmp_list)<9:
#        tmp = '0' + tmp 
    if '0' in tmp_list and '1' in tmp_list and '2' in tmp_list :
        for j in range(len(tmp)):
            if tmp[j] == '0':
                tmp2 += '3'
            elif tmp[j] ==  '1':
                tmp2 += '5'
            elif tmp[j] == '2':
                tmp2 += '7'
        tmp2 = int(tmp2)
        l.append(tmp2)

for i in range(3**9):
    tmp = ternary(i)
    tmp_list = list(tmp)
    tmp2 = ''
#    if tmp_list[0] != '0' and len(tmp_list)<9:
#        tmp = '0' + tmp 
    if '0' in tmp_list and '1' in tmp_list and '2' in tmp_list :
        for j in range(len(tmp)):
            if tmp[j] == '1':
                tmp2 += '3'
            elif tmp[j] ==  '2':
                tmp2 += '5'
            elif tmp[j] == '0':
                tmp2 += '7'
        tmp2 = int(tmp2)
        l.append(tmp2)

ans = 0

l = list(set(l))

#print(len(l))
#print(l[:100])

for i in range(len(l)):
    if l[i] <= N :
        ans += 1

print(ans)

#e = time.time() - s
#print(e)


#%%


Measured memory_bytes: 7100
from collections import deque

def scan(que, ps, way):
    Li = 0
    pp = ps
    while len(que) > 0:
        if way==0:
            p = que.popleft()
        else:
            p = que.pop()
        if p < ps:
            Li += ps - p
        else:
            break
        pp = p
    return Li

if __name__=='__main__':
    D = input()
    que = deque()
    p = 0
    for c in D:
        que.append(p)
        if   c == "\\" : p += -1
        elif c == "/"  : p +=  1
    que.append(p)
    
    Ll = [] 
    Lr = [] 
    ls = que.popleft()
    if len(que) > 0: rs = que.pop()
    while len(que) > 0:
        while len(que) > 0:
            if que[0] < ls:
                break
            else:
                ls = que.popleft()
        while len(que) > 0:
            if que[-1] < rs:
                break
            else:
                rs = que.pop()
        if len(que) > 0:
            if ls < rs: Ll.append(scan(que,ls,0))
            else      : Lr.insert(0,scan(que,rs,1))
    L = Ll + Lr
    if len(L) > 0:
        print(sum(L))
        print(len(L), *L)
    else:
        print(0)
        print(0)

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

int main() {
    int N; long long K;
    cin >> N >> K;
    vector<pair<long long, long long> > v(N);
    for (int i = 0; i < N; ++i) cin >> v[i].first >> v[i].second;

    // ソート
    sort(v.begin(), v.end());
    
    // a_i が小さい順に b_i を合計して K 以上になる瞬間をとらえる
    long long res = 0;
    long long sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += v[i].second;
        if (sum >= K) {
            cout<< v[i].first << endl; // sum >= K になった瞬間の a_i
            return 0;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class DDerangement {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextInt() - 1;
            }

            int answer = 0;
            for (int i = 0; i < n; i++) {
                if (p[i] == i) {
                    answer++;
                    i++;
                }
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 34376
package main

import "fmt"

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func factorial(n int) int {
	v := 1
	for i := 2; i <= n; i++ {
		v *= i
	}
	return v
}

func rank(a []int, n int) int {
	r := 0

	appear := make([]bool, n)

	for i, v := range a[:n-1] {
		appear[v-1] = true

		rem_rank := 0
		for j := 0; j < v-1; j++ {
			if !appear[j] {
				rem_rank++
			}
		}

		r += rem_rank * factorial(n-i-1)
	}
	return r + 1
}

func main() {
	var N int
	fmt.Scan(&N)
	P := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&P[i])
	}
	Q := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&Q[i])
	}
	a := rank(P, N)
	b := rank(Q, N)
	fmt.Println(abs(a - b))
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.nextLine();
		int k = sc.nextInt();


		//赤より緑の方を大きくする
		while(a >= b){
			b *= 2;
			k--;
		}

		//緑より青を大きくする
		while(b >= c){
			c *=2;
			k--;
		}

		if(k>=0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 35676