akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

rl = lambda: list(map(int, input().split()))

x, y, a, b, c = rl()
p = rl()
q = rl()
r = rl()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
res = sum(sorted(p[:x] + q[:y] + r, reverse=True)[:x+y])
print(res)


Measured memory_bytes: 23312
#include <iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
LL add(LL s,LL e, LL n)//zhe'li
{
    return (s+e)*n/2;
}
int main()
{
    int n,k;
    cin>>n>>k;
    LL ans = 1;
    for(int i=k;i<=n;i++)
    {
       ans = (ans + add(n-i+1,n,i) - add(0,i-1,i) +1)%mod;

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


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

int main(){
  string s; cin>>s;
  int size=s.size();
  int MIN=0,MAX=size;
  for(int i=0;i<size;i++){
    if(s[i]=='A'){
      MIN=i;
      break;
    }
  }
  for(int i=size-1;0<=i;i--){
    if(s[i]=='Z'){
      MAX=i+1;
      break;
    }
  }
  cout<<MAX-MIN<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stack>
#include<queue>
#include<string>
#include<deque>
#include<set>
#define ll long long
using namespace std;


int main() 
{
	string ss;
	while(getline(cin,ss))
	{
		while(ss.find("the")==-1&&ss.find("this")==-1&&ss.find("that")==-1)
		{
			int i;
			for( i=0;i<ss.size();i++)
			{
				if('a'<=ss[i]&&ss[i]<'z')
				ss[i]++;
				else if(ss[i]=='z')
				ss[i]='a';
				
			}
		}
		cout<< ss <<endl;  
	}
	return 0;
	
}


Measured memory_bytes: 3076
def fina(n, fina_list):

    if n <= 1:
        fina_list[n] = 1
        return fina_list[n]
    elif fina_list[n]:
        return fina_list[n]
    else:
        fina_list[n] = fina(n-1, fina_list) + fina(n-2, fina_list)
        return fina_list[n]


n = int(input())
fina_list = [None]*(n + 1)
print(fina(n, fina_list))



Measured memory_bytes: 5600
#line 2 "solve.cpp"
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
#define int long long
const int INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
void check_input(){
    assert(cin.eof() == 0);
    int tmp; cin >> tmp; 
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H *//*}}}*/

signed main() {
    //input
    int n;cin>>n;
    vector<string> s(n);
    set<string> st;
    rep(i, n) {
        cin>>s[i];
        st.insert(s[i]);
    }
    dump(s);
    check_input();

    //solve
    cout << sz(st) << endl;

    return 0; 
}


Measured memory_bytes: 25112
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;

  cout << (x/100==x%10 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;



int main(void){

    

    long n,m;
    cin >>n>>m;
    string ans;

    int *h = new int[n];

    for(int i = 0; i < n; i++) {
        cin>>h[i];
    }

    int *a = new int[n];

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

    int d,t;
    for(int i = 0; i < m; i++) {
        cin>>d>>t;
        if(h[d-1]>h[t-1]) a[t-1]=0;
        else if(h[d-1]<h[t-1]) a[d-1] = 0;
        else {
            a[t-1]=0;
            a[d-1] = 0;
        }
    }
    int sum = 0;
    for(int i = 0 ; i < n; i++) {
        sum+=a[i];
    }


    cout<< sum;


    return 0;
}

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

bool isOver(int max, vector<int> powor){
  for(int i=0; i<powor.size(); i++){
    if(powor.at(i) < max){
      return false;
    }
  }
  return true;
}

int getMin(vector<int> vals){
  if(vals.size() == 1){
    return vals.at(0);
  }
  int result = vals.at(0);
  for(int i=1; i<vals.size(); i++){
    if(result > vals.at(i)){
      result = vals.at(i);
    }
  }
  return result;
}

void getPrice(bool isBuy, int price, int index, int max, vector<int> powor, vector<int> &prices, vector<int> &result, vector<vector<int>> &data){
  if(isBuy){
    for(int i=0; i<powor.size(); i++){
      powor.at(i) += data.at(index).at(i);
    }
    price += prices.at(index);
    if(isOver(max, powor)){
      result.push_back(price);
      return;
    }
  }
  if(index + 1 != prices.size()){
    getPrice(true, price, index + 1, max, powor, prices, result, data);
    getPrice(false, price, index + 1, max, powor, prices, result, data);
  }
}

int main(){
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> data(n, vector<int>(m, 0));
  vector<int> price(n);
  
  for(int i=0; i<n; i++){
    cin >> price.at(i);
    for(int j=0; j<m; j++){
      cin >> data.at(i).at(j);
    }
  }
  
  vector<int> powor(m, 0);
  vector<int> result(0);
  getPrice(true, 0, 0, x, powor, price, result, data);
  getPrice(false, 0, 0, x, powor, price, result, data);
  if(result.size() == 0){
    cout << "-1" << endl;
  }else{
    cout << getMin(result) << endl;
  }
}



Measured memory_bytes: 3640
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();
		if (A>=13) {
			System.out.println(B);
		}else if(A>=6 && A<=12) {
			System.out.println(B/2);
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21844
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, m = ril()
ls = ril()
acc = [0]
counter = collections.Counter()
res = 0
for x in ls:
    counter[acc[-1]] += 1
    acc.append((acc[-1] + x) % m)
    res += counter[acc[-1]]
print(res)

Measured memory_bytes: 14968
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

const ll Mod = 1e9 + 7;
// const ll Mod = 998244353;
const ll MAXN = 1e6;

void solve(){
    ll a,b,h,m;cin>>a>>b>>h>>m;
    ld x1=a*sin((h+m/60.0)*M_PI*2.0/12), y1=a*cos((h+m/60.0)*M_PI*2.0/12);
    ld x2=b*sin(m*M_PI*2.0/60), y2=b*cos(m*M_PI*2.0/60);
    // trace(x1,y1,x2,y2);
    cout<<sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))<<"\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);

    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4116
#python3
def main():
    a = []
    for _ in range(3):
        x, y, z = map(int, input().split())
        a.append((x, y, z))
    n = int(input())
    b = [int(input()) for _ in range(n)]
    g =[[0 for _ in range(3)] for _ in range(3)]
    for i in range(3):
        for j in range(3):
            for k in range(n):
                if b[k] == a[i][j]:
                    g[i][j] = 1

    bingo = False
    #縦
    for i in range(3):
        s = 0
        for j in range(3):
            s += g[j][i]
        if s == 3:
            bingo = True
    #横
    for i in range(3):
        s = 0
        for j in range(3):
            s += g[i][j]
        if s == 3:
            bingo = True
    #斜め
    
    s1 = 0
    for i in range(3):
        s1 += g[i][i]
    if s1 == 3:
        bingo = True
    
    s2 = 0
    for i in range(3):
        s2 += g[i][2-i]
    if s2 == 3:
        bingo = True 
    
    if bingo:
        print('Yes')
    else:
        print('No')
main()


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 1001001001;

int main(){
	int n, k; cin >> n >> k;
	double cnt = 0;
	for(int i = 1; i<=n; i++){
		if(i>=k) cnt += (double)1 / n;
		else{
			int den = 2;
			while(1){
				if (k <= den*i){
					cnt += (double)1 / (den * n);
					break;
				}

				den *= 2;
			}
		}
	}
	printf("%.15f", cnt);
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n; R(n);
    W(n*n*n);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
using namespace std;

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

typedef long long lint;
typedef pair<int,int> P;

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main()
{

    int N,K;
    cin >> N >> K;

    lint ans;

    if(K%2==0){
    	ans = pow((N+K/2)/K,3) + pow(N/K,3);
    }else{
    	ans = pow(N/K,3);
    }

    cout << ans << endl;

}


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

int main() {
    stack<int> S;
    string s;
    int a, b;
    while( cin >> s ) {
        if (s[0] == '+') {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a + b);
        } else if (s[0] == '-') {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(b - a);
        } else if (s[0] == '*') {
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a*b);
        } else {
            S.push(atoi(s.c_str()));
        }
    }

    cout << S.top() << endl;

    return 0;
}



Measured memory_bytes: 3184
<?php
fscanf(STDIN, "%d%d", $N, $M);
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
sort($A);

//累積和を作る
$AS[-1] = 0;
foreach($A as $i => $a){
    $AS[$i] = ($AS[$i-1] ?? 0) + $a;
}

//満足度がi以上の握手のパターン表を作っておく
for($i = 0; $i < 10**5*2+1; $i++){
    $lbmemo[$i] = lower_bound($A, $i);
}

//めぐる式二分探索 -- $k以上の値の個数がMを超えるなかで最大のkを求める
$ok = 0; 
$ng = 10**5*2+1;
while(abs($ok - $ng) > 1){
    $mid = intdiv($ok+$ng, 2);
    $sum = 0;
    $count = 0;
    if(isOK($mid)){
        $ok = $mid;
    }else{
        $ng = $mid;
    }
}
echo $sum - $ok * ($count - $M);
function isOK($bound){
    global $M, $A, $AS, $N, $sum, $count, $lbmemo;
    foreach($A as $a){
        $i = $lbmemo[$bound - $a] ?? 0;
        $c = $N - $i;
        $count += $c;
        $sum += $AS[$N - 1] - $AS[$i - 1] + $a * $c;
    }
    return $count >= $M;
}
function lower_bound($array, $key){
    $min = -1;
    $max = count($array);
    while($max - $min > 1){
        $c = intdiv($min + $max, 2);
        if($array[$c] >= $key){
            $max = $c;
        }else{
            $min = $c;
        }
    }
    return $max;
}


Measured memory_bytes: 27120
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
struct edge { int to, cost; };
bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int N, M, C, b1, b2, e1, e2, e3, e4;
int main() {
	while (cin >> N >> M >> C >> b1 >> b2, b1--, b2--, N) {
		vector<vector<vector<edge> > > G1(C, vector<vector<edge> >(N));
		for (int i = 0; i < M; i++) {
			cin >> e1 >> e2 >> e3 >> e4; e1--, e2--, e4--;
			G1[e4][e1].push_back(edge{ e2, e3 });
			G1[e4][e2].push_back(edge{ e1, e3 });
		}
		vector<vector<vector<int> > > dist(C, vector<vector<int> >(N, vector<int>(N, 999999999)));
		for (int i = 0; i < C; i++) {
			for (int j = 0; j < N; j++) {
				dist[i][j][j] = 0;
				priority_queue<edge> que1; que1.push(edge{ j, 0 });
				while (!que1.empty()) {
					edge u = que1.top(); que1.pop();
					for (edge e : G1[i][u.to]) {
						if (dist[i][j][e.to] > -u.cost + e.cost) {
							dist[i][j][e.to] = -u.cost + e.cost;
							que1.push(edge{ e.to, -dist[i][j][e.to] });
						}
					}
				}
			}
		}
		vector<int> P(C);
		for (int i = 0; i < C; i++) cin >> P[i];
		vector<vector<int> > costs(C, vector<int>(20000));
		for (int i = 0; i < C; i++) {
			vector<int> Q(P[i] + 1), R(P[i]); Q[0] = 0, Q[P[i]] = 19999;
			for (int j = 1; j < P[i]; j++) cin >> Q[j];
			for (int j = 0; j < P[i]; j++) cin >> R[j];
			for (int j = 0; j < P[i]; j++) {
				for (int k = Q[j] + 1; k <= Q[j + 1]; k++) {
					costs[i][k] = costs[i][k - 1] + R[j];
				}
			}
		}
		vector<vector<int> > G2(N, vector<int>(N, 999999999));
		for (int i = 0; i < C; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					if (j == k) continue;
					if (dist[i][j][k] == 999999999) continue;
					G2[j][k] = min(G2[j][k], costs[i][dist[i][j][k]]);
				}
			}
		}
		vector<vector<edge> > G3(N);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (G2[i][j] != 999999999) G3[i].push_back(edge{ j, G2[i][j] });
			}
		}
		vector<int> dist2(N, 999999999); dist2[b1] = 0;
		priority_queue<edge> que2; que2.push(edge{ b1, 0 });
		while (!que2.empty()) {
			edge u = que2.top(); que2.pop();
			for (edge e : G3[u.to]) {
				if (dist2[e.to] > -u.cost + e.cost) {
					dist2[e.to] = -u.cost + e.cost;
					que2.push(edge{ e.to, -dist2[e.to] });
				}
			}
		}
		cout << (dist2[b2] != 999999999 ? dist2[b2] : -1) << endl;
	}
	return 0;
}

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

int main(){
int n;
cin >> n;
int v[22],c[22];
rep(i,n) cin >> v[i];
rep(i,n) cin >> c[i];
int total=0;
rep(i,n){
    if(v[i]-c[i]>0) total+=v[i]-c[i];
}
cout << total << endl;
}

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

// clang-format off
#define rep(i, n) for(int i=0; i< (n); i++)
#define reps(i, a, n) for(int i=a; i < (n); i++)

const int INF{1001001001};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

int main(){
    int D,N;
    cin >> D >> N;
    
    int ans;
    if(N != 100){
        ans = pow(100,D) * N;
    }else{
        ans = pow(100,D) * (N + 1);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


ll h,w;
vector<string> v(50);

bool check(ll x, ll y){
    if(x < 0 || x >= h) return false;
    if(y < 0 || y >= w) return false;
    if(v[x][y] == '#')  return false;
    return true;
};


int main(){

    cin >> h >> w;
    ll ans = h*w;
    vector<vector<int>> d(h,vector<int>(w,-1));

    rep(i,h){
        cin >> v[i];
    }
    rep(i,h){
        rep(j,w){
            if(v[i][j] == '#') ans --;
        }
    }

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

    d[0][0] = 0;
    pair<ll,ll> pos = make_pair(0,0);
    queue<pair<ll,ll>> q;

    q.push(pos);

    while(!q.empty()){
        pos = q.front();
        q.pop();

        rep(i,4){
            if(check(pos.first+dx[i],pos.second+dy[i]) && d[pos.first+dx[i]][pos.second+dy[i]] == -1){
                q.push(make_pair(pos.first+dx[i],pos.second+dy[i]));
                d[pos.first+dx[i]][pos.second+dy[i]] = d[pos.first][pos.second] + 1;
            }
        }
    }
    

    if(d[h-1][w-1] == -1) cout << -1;
    else cout << ans - d[h-1][w-1] -1;


}

Measured memory_bytes: 3652
#include <stdio.h>

int A[1000000];



int main(){
  
  
  int i,q,n,key1;
  int count = 0;
  
  scanf("%d", &n);
  
  for(i = 0;i < n;i ++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  
  for(i = 0;i < q;i ++)
    {
      scanf("%d", &key1);
      if(biNsearch(key1,n))count ++;
    }

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

  return 0;
}

int biNsearch(int key2,int n){

  int left = 0,right = n;
  int mid;
  
  
  while(left < right) {
    
    mid = (left + right) / 2;
    
    if (key2 == A[mid]) {
      return 1;
    }
    
    if(key2 > A[mid]){
      left = mid + 1; 
    }
    else if(key2 < A[mid])
      {
      right = mid; 
      }
  }  
    return 0;
  
}

Measured memory_bytes: 988
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    N = int(sys.stdin.readline())
    N1 = N - 1

    ans = 0
    for i in range(1, N):
        ans += N1//i
    print(ans)
if __name__ == "__main__":
    resolve()


Measured memory_bytes: 62604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
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;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, k; cin >> n >> k;
	vi a(n);
	rep(i, n) cin >> a[i];
	
	auto can = [&](int d){
		vi m;
		int sum = 0;
		rep(i, n){
			sum += a[i] % d;
			m.pb(a[i] % d);
		}
		sort(all(m));
		int cnt = 0;
		rep(i, n){
			cnt += m[i];
			if((n - i - 1ll) * d == sum) return cnt <= k;
		}
		return false;
	};
	
	int sum = accumulate(all(a), 0);
	vi div;
	for(int i = 1; i * i <= sum; i++) if(sum % i == 0){
		div.pb(i);
		if(i * i != sum) div.pb(sum / i);
	}
	sort(all(div));
	reverse(all(div));
	for(int i : div){
		if(can(i)){
			cout << i << endl;
			return 0;
		}
	}
	assert(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

// stringの要素を検索
bool string_exist(string s, char c) {
  auto itr = find(s.begin(), s.end(), c);
  size_t index = distance(s.begin(), itr);
  if (index!=s.size()) {
    return true;
  }
  else {
    return false;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<char> D(K);
  for (int i=0; i<K; i++) cin >> D[i];
  int num = N;
  while (true) {
    string s = to_string(num);
    bool exist = false;
    for (int i=0; i<K; i++) {
      if (string_exist(s, D[i])) {
        exist = true;
        break;
      }
    }
    if (exist) num++;
    else {
      cout << s << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
     ordered_set s;
     s.insert(1);
     cout<<*s.find_by_order(1); //print kth smallest element
     cout<<s.order_of_key(3);  //print number of strictly smaller element of 3;
*/
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define pi acos(-1)
#define bp __builtin_popcount
#define ll long long int
#define ld long double
#define endl '\n'
#define pii pair<ll , ll>
#define tii tuple<ll,ll,ll>
//aaaccess element of tuple ex. 3rd element(index 2) cout<< get<2>(tuppleName);

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<pii,vector<pii>,greater<pii> >
#define minq priority_queue <int, vector<int>, greater<int> >
#define maxQueue priority_queue<ll>
#define pb push_back
#define mx3(a,b,c) max(a,max(b,c))
#define pf push_front
#define ff first
#define ss second
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
const ll N = 1000005;
const ll M = 1e6 + 10;
const ll mod = 998244353;

ll power(ll x, ll y, ll p)
{
	ll res = 1;
	x = x % p;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}
ll modinv(ll n, ll p)
{
	return power(n, p - 2, p);
}
ll ncr(ll n, ll r, ll p)
{
	if (r == 0)
		return 1;
	int n1 = n;
	ll fac[n1 + 1];
	fac[0] = 1;
	for (int i = 1 ; i <= n; i++)
		fac[i] = fac[i - 1] * i % p;

	return (fac[n] * modinv(fac[r], p) % p *
	        modinv(fac[n - r], p) % p) % p;
}
/*vector<bool> prime(N, true);
void sieve()
{
	for (int i = 2; i <= sqrt(N); ++i) {
		if (prime[i]) {
			for (int j = i * i; j <= N; j += i) {
				prime[j] = false;
			}
		}
	}
}/*

/*int Prime[M];
void MinPrimeFactor()
{
	for (ll i = 1; i < M; i++) Prime[i] = i;
	for (int p = 2; p * p <= M; p++)
	{
		if (Prime[p] == p)
		{
			for (int i = 2 * p; i <= M; i += p)
			{
				Prime[i] = min(p, Prime[i]);
			}
		}
	}
}*/

/*vector<int> getFactorization(int x)
{
	vector<int> ret;
	while (x != 1)
	{
		ret.push_back(Prime[x]);
		x = x / Prime[x];
	}
	return ret;
}


ll find(vector<ll> &parent,ll i)
{
    while(parent[i] != i)
    {
        //parent[i]=parent[parent[i]];
        i=parent[i];
    }
    return parent[i];


}

void Union(vector<ll> &parent,ll i, ll j)
{
    ll x=find(parent,i);
    ll y=find(parent,j);

    parent[x]=y;
}
*/
bool isPowerOfTwo(int x)
{
	return (x && !(x & (x - 1)));
}



int main()
{
	FAST;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int x = 0, a, b, c, k;
	cin >> a >> b >> c >> k;
	while (b <= a)
	{
		b = b * 2;
		x++;
	}
	while (c <= b)
	{
		c = c * 2;
		x++;
	}
	//cout << x << endl;
	if (x <= k)
		return cout << "Yes", 0;
	return cout << "No", 0;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n;
  while(cin >> n && n) {
    vector<P> v;
    int a1,a2;
    rep(i,n) {
      int x,y;
      cin >> x >> y;
      if(i==0) {
	a1=x;
	a2=y;
      }
      int s=x-a1,t=y-a2;
      v.pb(P(s,t));
    }
    int m;
    cin >> m;
    P a[m];
    map<P,bool> b;
    rep(i,m) {
      int x,y;
      cin >> x >> y;
      a[i]=P(x,y);
      b[P(x,y)]=true;
    }
    int ansx,ansy;
    rep(i,m) {
      bool ck=true;
      rep(j,n) {
	int x=a[i].F+v[j].F,y=a[i].S+v[j].S;
	if(b[P(x,y)]==false) {
	  ck=false;
	  break;
	}
      }
      if(ck) {
	ansx=a[i].F-a1;
	ansy=a[i].S-a2;
	break;
      }
    }
    cout << ansx << " " << ansy << endl;
  }
  return 0;
}


Measured memory_bytes: 1308
n,m=map(int, input().split())
a=[0 for i in range(n)]
b = [True for i in range(n)]
for i in range(m):
    b[int(input()) - 1] = False
for i in range(n):
    if b[i]==False:
        continue
    if i == 0:
        a[i] = 1
    elif i == 1:
        a[i] = 1 + a[i - 1]
    else:
        a[i] = a[i - 1] + a[i - 2]

print(a[-1]%int(1e9+7))

Measured memory_bytes: 460824
N = int(input())
X = list(map(int, input().split()))
L = []
for i in range(N):
  L.append([X[i], i])
L.sort()
for i in range(N):
  if i < N // 2:
    L[i].append(L[N // 2][0])
  else:
    L[i].append(L[N // 2 - 1][0])
for i in range(N):
  L[i][0], L[i][1] = L[i][1], L[i][0]
L.sort()
for i in range(N):
  print(L[i][2])

Measured memory_bytes: 47552
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,su;
    cin>>n;
    int a[10005]={};
    for(int i=1;i<105;i++){
        for(int j=1;j<105;j++){
            for(int k=1;k<105;k++){
                su=i*i+j*j+k*k+i*j+j*k+k*i;
                if(su<=10005)
                a[su]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    cout<<a[i]<<"\n";
}

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

#define Int register int
#define MAXN 105

template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}

char str[MAXN];
short f[MAXN][MAXN][MAXN][MAXN];
int n,m,sx,sy,a[MAXN][MAXN],b[MAXN][MAXN];

signed main(){
	read (n,m);
	for (Int i = 1;i <= n;++ i){
		scanf ("%s",str + 1);
		for (Int j = 1;j <= m;++ j) a[i][j] = a[i][j - 1] + (str[j] == 'o'),b[i][j] = b[i - 1][j] + (str[j] == 'o'),(str[j] == 'E') && (sx = i,sy = j);
	}
	int ans = 0;
	for (Int i = sx;i;-- i)
		for (Int j = sy;j;-- j)
			for (Int k = sx;k <= n;++ k)
				for (Int l = sy;l <= m;++ l){
					if (i > 1 && i - 1 > k - sx) f[i - 1][j][k][l] = max ((int)f[i - 1][j][k][l],f[i][j][k][l] + a[i - 1][min (l,m - (sy - j))] - a[i - 1][max (j - 1,l - sy)]);
					if (k < n && n - k > sx - i) f[i][j][k + 1][l] = max ((int)f[i][j][k + 1][l],f[i][j][k][l] + a[k + 1][min (l,m - (sy - j))] - a[k + 1][max (j - 1,l - sy)]);
					if (j > 1 && j - 1 > l - sy) f[i][j - 1][k][l] = max ((int)f[i][j - 1][k][l],f[i][j][k][l] + b[min (k,n - (sx - i))][j - 1] - b[max (i - 1,k - sx)][j - 1]);
					if (l < m && m - l > sy - j) f[i][j][k][l + 1] = max ((int)f[i][j][k][l + 1],f[i][j][k][l] + b[min (k,n - (sx - i))][l + 1] - b[max (i - 1,k - sx)][l + 1]);
					ans = max (ans,(int)f[i][j][k][l]);
				}
	write (ans),putchar ('\n');
	return 0;
} 

Measured memory_bytes: 52992
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {
  case class Edge(x: Int, y: Int, z: Long)
  
  def read() = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()
    //0-index化
    val edges = IndexedSeq.fill(m)(Edge(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt()))

    (n, m, edges)
  }


  def solve2(n: Int, m: Int, edges: IndexedSeq[Edge]): Int = {
    var cnt = 0 // 連結成分数

    val nextList = IndexedSeq.fill(n)(ArrayBuffer.empty[Edge])
    for (edge <- edges) {
      val from = edge.x
      val to = edge.y
      nextList(from).append(edge)
      nextList(to).append(Edge(to, from, edge.z))
    }

    val visited = Array.fill(n)(false)
    for (i <- 0 until n) {
      if (!visited(i)) {
        visited(i) = true
        cnt += 1
        //BFS
        val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()
        open.add(i)
        while (!open.isEmpty) {
          val current = open.remove()
          for (edge <- nextList(current)) {
            val next = edge.y
            if(!visited(next)) {
              open.add(next)
              visited(next) = true
            }
          }
        }

      }
    }
    cnt
  }

  def main(args: Array[String]): Unit = {
    val (n, m, edges) = read()
    println(solve2(n, m, edges))
  }
}


Measured memory_bytes: 117904
a,b,k = map(int,input().split())

t_zan = a - k
if t_zan < 0:
  aoki_zan = b + t_zan
  t_zan = 0
else:
  aoki_zan = b

if aoki_zan < 0:
  aoki_zan = 0

print(str(t_zan) + ' ' + str(aoki_zan))

Measured memory_bytes: 38384
import kotlin.*
import kotlin.math.*

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val dir = "URDL"

        val p = Array(n) { Triple(sc.nextLong(), sc.nextLong(), dir.indexOf(sc.nextChar())) }

        // あのバカ来やがった
        fun ud(): Long {
            // u 0
            // d 2
            var result = Long.MAX_VALUE
            val map = mutableMapOf<Long, Long>()
            p.forEach {
                if (it.third == 0) map[it.first] = it.second
                else if (it.third == 2 && map.containsKey(it.first)) result = min(result, (it.second - map[it.first]!!) * 5)
            }
            return result
        }

        // もう助からないゾ☆
        fun ur(): Long {
            // u = 0
            // r = 1
            var result = Long.MAX_VALUE
            val map = mutableMapOf<Long, Long>()
            p.forEach {
                if (it.third == 0) map[it.first + it.second] = it.second
                else if (it.third == 1 && map.containsKey(it.first + it.second)) result = min(result, (it.second - map[it.first + it.second]!!) * 10)
            }
            return result
        }

        var ans = Long.MAX_VALUE
        for (t in 1..4) {
            for (i in 0 until n) {
                p[i] = Triple(p[i].second, -p[i].first, (p[i].third + 1) % 4)
            }
            p.sortBy { it.second }
            if (t <= 2) ans = min(ans, ud())
            ans = min(ans, ur())
        }

        println(if (ans == Long.MAX_VALUE) "SAFE" else ans.toString())
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 112828
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

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

long long lcm(long long a,long long b){
	long long g=gcd(a,b);
	return a/g*b;
}


int main(){
	int n,x,a[101010]={};
	cin>>n>>x;
	FOR(i,0,n){
		cin>>a[i];
		a[i]-=x;
		if(a[i]<0)a[i]=-a[i];
	}
	int ans=a[0];
	FOR(i,0,n){
		ans=gcd(ans,a[i]);
	}
	cout<<ans;
    return 0;
}


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

int f(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main () {
    int N;
    scanf("%d", &N);
    int *A = malloc((1 + N) * sizeof(int));
    int *copied = malloc((1 + N) * sizeof(int));
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        copied[i] = A[i];
    }
    qsort(A, N, sizeof(int), f);
    int first = A[0];
    int second = A[1];

    for (int i = 0; i < N; i++) {
        if (copied[i] == first)
            printf("%d\n", second);
        else
            printf("%d\n", first);
    }

    return 0;
}


Measured memory_bytes: 3120
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k = LI()
    if n % k:
        print(1)
    else:
        print(0)
    return

#B
def B():
    n = II()
    dp = [0] * (100 + 1)
    dp[4] = 1
    dp[7] = 1
    for i in range(8,n + 1):
        if dp[i - 4] or dp[i - 7]:
            dp[i] = 1
    print(["No", "Yes"][dp[n]])
    return

#C
def C():
    n = II()
    ans = []
    if n == 0:
        print(0)
    while n:
        ans.append("{}".format(n % 2))
        n = (n-1) // -2
    print("".join(ans[::-1]))
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll n,k;
	cin >> n >> k;
	vector<ll> p(n),c(n);
	vector<bool> visited(n,false);
	REP(i,n){
		cin >> p[i];
		p[i]--;
	}
	REP(i,n) cin >> c[i];
	
	vector<vector<ll>> way;
	vector<ll> score,w;
	ll now = 0;
	ll s = 0;
	bool loop = true;
	while(loop){
		visited[now] = true;
		w.push_back(now);
		
		if(!visited[p[now]]){
			s += c[p[now]];
			now = p[now];
		}else{
			s += c[p[now]];
			way.push_back(w);
			w.clear();
			score.push_back(s);
			s = 0;
			REP(i,n){
				if(!visited[i]){
					now = i;
					break;
				}
				if(i==n-1) loop = false;
			}
		}
	}
	
	vector<ll> rscore((int)way.size());
	REP(i,way.size()){
		chmax(score[i], (ll)0);
		rscore[i] = score[i]*(k/way[i].size());
	}
	
	ll ans = -1*(ll)1e13;
	REP(i,way.size()){
		ll sz = way[i].size();
		ll t = k%sz;
		ll smax = -1*(ll)1e13;
		REP(j,sz){
			ll sum = 0;
			REP(l,sz){
				sum += c[way[i][(j+l)%sz]];
				if(l < t){
					chmax(smax, rscore[i]+sum);
				}else{
					chmax(smax, rscore[i]-score[i]+sum);
				}
			}
		}
		chmax(ans, smax);
		
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3780
#include <stdio.h>

int main(void) {
	int n;
	int i;
	int a[1000];
	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for(i = n - 1; i >= 0; i--) {
		if(i == 0) printf("%d", a[i]);
		else printf("%d ", a[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2100
#include <stdio.h>

int main()
{

 int a, b, c, x;
 scanf("%d %d %d\n", &a, &b, &c);
 if(a > b)
 {
     x = a;
     a = b;
     b = x;
 }
 if(b > c)
 {
     x = b;
     b = c;
     c = x;
 }
 if(a > b)
 {
     x = a;
     a = b;
     b = x;
 }
 printf("%d %d %d\n", a, b, c);
 return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 
int mod = 1e9+7;
int main() {

  int n,m; cin >> n>>m;
  vector<ll> dp(n+1);
  vector<ll> a(n); rep(i,m){
    cin >> a[i];
  }
  dp[0]=1;
  int foo=0;
  for(int i=1; i<=n; i++) {
    if(foo < m && a[foo] == i) {
      dp[i] = 0;
      foo++;
    }
    else {
      if (i<2) dp[i] = 1;
      else dp[i] = (dp[i-1] % mod +dp[i-2] % mod)%mod;
    }
  }
  cout << dp[n] << endl; 
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using vi   = vector<int>;
using vll  = vector<long long>;
using vvi  = vector<vi>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;

int main() {
    string S; cin >> S;
    int ans = 0, tmp = 0;
    set<char> key;
    key.insert('A');
    key.insert('C');
    key.insert('G');
    key.insert('T');
    for(int i = 0; i < S.length(); i++) {
        if(key.count(S.at(i))){
            tmp++;
        } else {
            if (ans < tmp) ans = tmp;
            tmp = 0;
        }
    }
    if (ans < tmp) ans = tmp;
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int a[60]; for (int i = 0; i < n; i++)cin >> a[i];
		if (n == 1)cout << a[0];
		else for (int i = 0; i < n; i++) {
			if (!i) {
				cout << a[i];
				if (a[i + 1] == a[i] + 1)cout << '-';
				else cout << ' ';
			}
			else if (i == n - 1)cout << a[i];
			else {
				if (a[i + 1] != a[i] + 1)cout << a[i] << ' ';
				else if (a[i - 1] != a[i] - 1)cout << a[i] << '-';
				else;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 3008
#bubble
N=int(input())
A=[int(i) for i in input().split()]
fl=1
C=0
while fl==1:
    fl=0
    for j in range(N-1):
        if A[N-1-j]<A[N-2-j]:
            t=A[N-1-j]
            A[N-1-j]=A[N-2-j]
            A[N-2-j]=t
            C+=1
            fl=1
for j in range(N):
    A[j]=str(A[j])
print(" ".join(A))
print(C)

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) V vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define Vec vector
#define P pair
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline 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;
  cin>>n;
  Vec< tuple<string,int,int> > a;
  rep(i,n){
    str s;int p;
    cin>>s>>p;
    a.pb( m_t(s,-p,i+1) );
  }
  sort(all(a));
  for(auto&ans:a){
    str s;
    int p,n;
    tie(s,p,n)=ans;
    cout<<n<<endl;
  }
  
  
  
  
  return 0;
}



Measured memory_bytes: 256
let partition (a : int array) p r =
  let x = a.(r) in
  let swap i j = let t = a.(i) in a.(i) <- a.(j); a.(j) <- t
  in
  let rec doit i j =
    if j = r then (swap (i + 1) r; i + 1)
    else if a.(j) <= x then (swap (i + 1) j; doit (i + 1) (j + 1))
    else doit i (j + 1)
  in doit (p - 1) p

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let k = partition a 0 (n - 1) in
  Array.iteri (fun i e -> Printf.printf (if i = 0 then "%d" else if i = k then " [%d]" else " %d") e) a;
  print_newline ()

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

int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	set <long long int> S;
	// 1.2.3.4.5.6.7.8.9.19.29.39..........

	int k;
	vector <long long int> res;
	vector <pair<long long int,long long int>> v;

	cin >> k;

	long long int base = 0;
	long long int l = 1;
	while(1)
	{
		if(l + base >= 1e15)
		{
			break;
		}
		for(long long int j=1;j<110;j++)
		{
			long long int temp = l*j + base;
			if(temp>=1e15)
			{
				break;
			}
			if(S.find(temp)!=S.end())
			{
				continue;
			}
			long long int sum = 0;
			while(temp>0)
			{
				sum += (temp%10);
				temp/=10;
			}
			temp = l*j + base;
			S.insert(temp);
			v.push_back(make_pair(temp,sum));
		}
		l*=10;
		base = 10*base + 9;
	}

	for(int i=0;i<v.size();i++)
	{
		//cout << v[i].first << ' ' << v[i].second << ' ' << v[i].first*(v[i].second*1.0) << '\n';
		bool ok = true;
		for(int j=i+1;j<v.size();j++)
		{
			if(v[i].first*(v[j].second*1.0) > v[j].first*(v[i].second*1.0) && v[i].first < v[j].first)
			{
				ok = false;
				break;
			}
		}
		if(ok)
		{
			res.push_back(v[i].first);
			if(res.size()==k)
			{
				break;
			}
		}
	}

	
	for(int i=0;i<res.size();i++)
	{
		cout << res[i] << '\n';
	}
	//cout << res.size() << '\n';

	return 0;	
}

Measured memory_bytes: 384