akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    m = n;
    intl ans = 0;
    while(m){
        ans += (m%10);
        m /= 10;
    }
    fp(!(n%ans));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    ll n; cin >> n;
    ll a[n + 1];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    ll p = 0 , mx = a[0];
    for(ll i = 1; i < n; i++)
    {
        mx = max(mx , a[i]);
        if(a[i] < mx)
        {
            p += (mx - a[i]);

        }


    }
    cout << p;

}


Measured memory_bytes: 5128
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MOD2 100000000
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define all(v) v.begin(),v.end()
ll mod=MOD;
using namespace std;
long long int fast_exp(long long int base,long long int ex) {
    long long int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
long long int gcd(long long int a, long long int b)
{
    if(b==0)return a;
     return gcd(b,a%b);
}
void lcs( string X, string Y, int m, int n )
{
   int L[m+1][n+1];

   /* Following steps build L[m+1][n+1] in bottom up fashion. Note
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++)
   {
     for (int j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
       else if (X[i-1] == Y[j-1])
         L[i][j] = L[i-1][j-1] + 1;
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }

   // Following code is used to print LCS
   int index = L[m][n];

   // Create a character array to store the lcs string
   string  lcs;// Set the terminating character

   // Start from the right-most-bottom-most corner and
   // one by one store characters in lcs[]
   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      // If current character in X[] and Y are same, then
      // current character is part of LCS
      if (X[i-1] == Y[j-1])
      {
          lcs+= X[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }

      // If not same, then find the larger of two and
      // go in the direction of larger value
      else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
   }

   // Print the lcs
   reverse(all(lcs));
   cout << lcs;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string a,b;cin>>a>>b;
    long long int la=a.length(),lb=b.length();
    lcs(a,b,la,lb);
    return 0;
}


Measured memory_bytes: 35456
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node
{
    int key;
    Node *right,*left,*parent;
};

Node *root, *NIL;

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL)
    {
        y = x;
        if(z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }

    z->parent = y;
    if(y == NIL)
    {
        root = z;
    }
    else
    {
        if(z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
    }
}

void inorder(Node *u)
{
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node*u)
{
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);

}

Node *find(Node *u,int k)
{
    while(u != NIL && k != u->key)
    {
        if(k < u->key)u = u->left;
        else u = u->right;
    }

    return u;
}

int main()
{
    int n,x,i;
    string com;
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        cin >> com;
        if(com[0] == 'f')
        {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }
        if(com == "insert")
        {
            scanf("%d",&x);
            insert(x);
        }
        else if(com == "print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
    
}


Measured memory_bytes: 22064
def main():
    mod = 10**9+7
    fact = [1, 1]
    for i in range(2, 300):
        fact.append(fact[-1]*i % mod)

    n, x = map(int, input().split())
    s = sorted(list(map(int, input().split())))[::-1]
    next_dict = {x: fact[n-1]}
    for i in range(n):
        memo = dict()
        inv = pow(n-i-1, mod-2, mod)
        ss = s[i]
        for j, a in next_dict.items():
            memo[j % ss] = (memo.get(j % ss, 0)+a) % mod
        for j, a in memo.items():
            next_dict[j] = (next_dict.get(j, 0)+a*inv) % mod
    ans = 0
    for i, j in memo.items():
        ans = (ans+i*j) % mod
    print(ans)


main()

Measured memory_bytes: 73580
#include <bits/stdc++.h>
using namespace std;
//{
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define all(v) (v).begin(),(v).end()
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)


#define PII pair<int,int>
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
};
//{
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);
//}

map<PII, int> cnt;
char s[100];
vector<lint> p10 = {1};

lint rad() {
	scanf("%s", s);
	int n = strlen(s);
	int ind = -1;
	FOR(i,0,n) if (s[i]=='.') ind = i;
	if (ind == -1) {
		int x;
		sscanf(s, "%d", &x);
		return x*1LL*1e9;
	}
	FOR(i,ind,n) s[i] = s[i+1];
	
	lint ans;
	sscanf(s, "%lld", &ans);
	return ans*1LL*p10[10-(n-ind)];;
}

int main() {
	make(n);
	FOR(i,0,10) p10.pb(p10.back()*10LL);
	lint ans = 0;
	FOR(i,0,n) {
		lint y = rad();
		int p2 = -9; int p5 = -9;
		while (y%2==0) {
			y = y/2; p2++;
		}
		while (y%5==0) {
			y = y/5; p5++;
		}
		FORE(j, cnt) {
			PII x = j->st;
			if (x.st+p2 >= 0 && x.nd +p5>=0) ans+= j->nd;
		}
		if (cnt.find({p2,p5}) != cnt.end()) cnt[{p2,p5}]++;
		else cnt[{p2,p5}] = 1;
	}
	printf("%lld\n", ans);
}



Measured memory_bytes: 3784
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int k, temp;
  int max = 0;
  int count = 0;
  vector<int> mheight;
  cin >> k;
  for(int i=0; i<k; i++){
    cin >> temp;
    mheight.push_back(temp);
  }
  for(int j=0; j<k; j++){
    if(mheight[j] >= max){
      max = mheight[j];
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

#define MAX_N (100000)
#define MAX_M (200000)

using namespace std;

long dfs(const vector<vector<pair<long, long>>> &adj_lists, vector<long> &xs,
         vector<long> &us, long i, long x) {
  long res = 1;
  for (pair<long, long> p : adj_lists[i]) {
    const long j = p.first, d = p.second, y = x + d;
    if (us[j]) {
      // check that there is no mismatch
      if (xs[j] != y) {
        return 0;
      }
    } else {
      // determine the coordinates of node j
      xs[j] = y;
      us[j] = 1;
      if (!dfs(adj_lists, xs, us, j, y)) {
        return 0;
      }
    }
  }
  return 1;
}

int main() {
  // read inputs
  long N, M, ls[MAX_M], rs[MAX_M], ds[MAX_M];
  scanf("%ld %ld", &N, &M);
  for (long i = 0; i < M; i++) {
    scanf("%ld %ld %ld", &ls[i], &rs[i], &ds[i]);
    ls[i]--;  // NOTE : modified input
    rs[i]--;  // NOTE : modified input
  }

  // create graph
  vector<vector<pair<long, long>>> adj_lists(N, vector<pair<long, long>>());
  for (long i = 0; i < M; i++) {
    long l = ls[i], r = rs[i], d = ds[i];
    adj_lists[l].push_back(make_pair(r, d));
    adj_lists[r].push_back(make_pair(l, -d));
  }

  // count number of incoming edges
  vector<long> cnt_edge_ins(N, 0);
  for (long i = 0; i < M; i++) {
    cnt_edge_ins[rs[i]]++;
  }

  // determine the coordinates of each node
  long isPossible = 1;
  vector<long> xs(N, 0), us(N, 0);
  for (long i = 0; i < N; i++) {
    if (!us[i]) {
      // start at node i
      xs[i] = 0;
      us[i] = 1;
      if (!dfs(adj_lists, xs, us, i, 0)) {
        isPossible = 0;
        break;
      }
    }
  }

  if (isPossible) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define fname "E"
#define bug(x) cerr << (#x) << " = " << (x) << endl
#define ll long long
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define ARR0(a, n) {cerr <<(#a)<< ": ["; REP0(i, n) cerr<< ' ' << a[i] <<','; cerr<<']'<<endl;}
#define ARR1(a, n) {cerr <<(#a)<< ": ["; REP1(i, n) cerr<< ' ' << a[i] <<','; cerr<<']'<<endl;}
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define LB lower_bound
#define UB upper_bound
#define X first
#define Y second

using namespace std;
template<typename T, typename V>
inline void bugp(const pair<T, V> &x) {cerr << '{' << x.X << ", " << x.Y << '}' << endl;}
template<typename T, typename U, typename V>
inline void bugpp(const pair<T, pair<U, V> > &x) {cerr << '{' << x.X << ", {" << x.Y.X << ", " << x.Y.Y << "}}" << endl;}
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ll, int> li;
typedef pair<ll, ii> lii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int H = 300003, W = 300003;
ii row[H], col[W];
map<ii, bool> sqr;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	int h, w, m, x, y;
    cin >> h >> w >> m;
    REP1(i, h) row[i].Y = i;
    REP1(j, w) col[j].Y = j;
    REP1(i, m) {
        cin >> x >> y;
        ++row[x].X;
        ++col[y].X;
        sqr[{x, y}] = true;
    }
    sort(row + 1, row + h + 1, greater<ii>());
    sort(col + 1, col + w + 1, greater<ii>());
    int ans = 0, val;
    REP1(j, w) {
        val = row[1].X + col[j].X;
        if(sqr[{row[1].Y, col[j].Y}]) --val;
        ans = max(ans, val);
    }
    REP1(i, h) {
        val = row[i].X + col[1].X;
        if(sqr[{row[i].Y, col[1].Y}]) --val;
        ans = max(ans, val);
    }
    cout << ans;
	return 0;
}


Measured memory_bytes: 64500
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <valarray>

using namespace std;

int main()
{
    int I, O, T, J, L, S, Z;
    scanf("%d %d %d %d %d %d %d\n", &I, &O, &T, &J, &L, &S, &Z);
    long long result = 0;
    result += O; O = 0;
    if (I % 2 + J % 2 + L % 2 >= 2 && I >= 1 && J >= 1 && L >= 1){
        result += 3; --I; --J; --L;
    }
    result += (I / 2) * 2; I %= 2;
    result += (J / 2) * 2; J %= 2;
    result += (L / 2) * 2; L %= 2;
    printf("%lld\n", result);
}


Measured memory_bytes: 128
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

import java.util.Arrays;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();

        final int N = fs.nextInt();

        int[] X = new int[N];

        for (int i = 0; i < N; i++) X[i] = fs.nextInt();

        int[] Y = new int[N];

        System.arraycopy(X, 0, Y, 0, X.length);

        Arrays.sort(Y);

        int left = Y[N / 2 - 1];
        int right = Y[N / 2];

        for (int i = 0; i < N; i++)
            System.out.println(X[i] <= left ? right : left);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 55144
#include<iostream>
#include<math.h>

using namespace std;

int main(void)
{
	for(;;)
	{
		int a;
		cin>>a;
		if(a==0)break;
		int ans=0;
		for(int j=5;j<=a;j+=5)
		{
			for(int k=j;k%5==0;k/=5)
			{
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	cout << (a - 1)*(b - 1) << endl;
	return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=(x);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(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 pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

#define WA printf("WA\n");
int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    if((a <= c && c <= b) || (b <= c && c <= a))puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int n;
vvi s;
void dfs(int i, int j, int ma) {
    if(i == n) return;
    s[j].push_back(0);
    vi a = s[j];
    
    while(true) {
        dfs(i+1, j, max(a[i]++ + 2, ma));
        if(a[i] == n || a[i] == ma) break;
        s.push_back(a);
        j = s.size()-1;
    }
}

int main() {
    cin >> n;
    vi a(1);
    s.push_back(a);
    dfs(1, 0, 2);
    vs xx;
    rep(i, s.size()) {
        if(s[i].size() != n) continue;
        xx.push_back("");
        rep(j, n) {
            xx[xx.size()-1].push_back(s[i][j] + 'a');
        }
    }  

    sort(all(xx));
    rep(i, xx.size()) {
        cout << xx[i] << '\n';
    }
}

Measured memory_bytes: 18480
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n = list(input())

    hon = [2, 4, 5, 7, 9]
    pon = [0, 1, 6, 8]
    # bon = [3]
    if int(n[-1]) in hon:
        print('hon')
    elif int(n[-1]) in pon:
        print('pon')
    else:
        print('bon')


if __name__ == '__main__':
    solve()


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

using namespace std;
using ll = long long;
using ld = long double;

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<int>> dp(n, vector<int>(3));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}


Measured memory_bytes: 6912
S = input()
N = len(S)



a = S[0:(N-1)//2]
b = a[::-1]

c = S[(N+3)//2-1::]
d = c[::-1]

e = S
f = S[::-1]

if a == b and c ==d and e == f:
  print('Yes')
  
else:
  print('No')
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int v,e;
  cin>>v>>e;
  int g[v][v];
  int INF=1LL<<55LL;
  for(int i=0;i<v;i++)
    for(int j=0;j<v;j++)
      g[i][j]=(i!=j)*INF;
  for(int i=0;i<e;i++){
    int s,t,d;
    cin>>s>>t>>d;
    g[s][t]=d;
  }
  for(int k=0;k<v;k++)
    for(int i=0;i<v;i++)
      for(int j=0;j<v;j++)
	g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
  for(int i=0;i<v;i++){
    if(g[i][i]<0){
      cout<<"NEGATIVE CYCLE"<<endl;
      return 0;
    }
  }
  for(int i=0;i<v;i++){
    for(int j=0;j<v;j++){
      if(j) cout<<" ";
      if(g[i][j]>=INF/2) cout<<"INF";
      else cout<<g[i][j];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3176
a_1 = gets.chop.split(' ').map(&:to_i)
a_2 = gets.chop.split(' ').map(&:to_i)
a_3 = gets.chop.split(' ').map(&:to_i)

N = gets.chop

b = readlines.map(&:chomp).map(&:to_i)

container = []

container.push([a_1[0], a_2[0], a_3[0]])
container.push([a_1[1], a_2[1], a_3[1]])
container.push([a_1[2], a_2[2], a_3[2]])
container.push([a_1[0], a_1[1], a_1[2]])
container.push([a_2[0], a_2[1], a_2[2]])
container.push([a_3[0], a_3[1], a_3[2]])
container.push([a_1[0], a_2[1], a_3[2]])
container.push([a_1[2], a_2[1], a_3[0]])

ans = 'No'
container.each do |x|
  flag = true
  x.each do |y|
    unless b.include?(y)
      flag = false
    end
  end

  if flag == true
    ans = 'Yes'
    break
  end
end

puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <ctype.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef  vector< vector<int> > vector2d;

int main (){

  int i,j,n;
  vector<int> prime;
  
  int judge[300000]={};

  for(i=0;i<42857;i++){
    judge[i*7+1] = 1;
    judge[i*7+6] = 1;
  }
  judge[1] = 0;
  
  //素数リスト作成
  for(i=6;i<300000;i++){
    if (judge[i]==1){
      prime.push_back(i);
      //cout << i <<endl;
      for(j=2;j*i<300000;j++){
	judge[j*i]=0;
      }
    }
  }
  prime.push_back(300100);
  
  while(1){
    cin >> n;
    if (n==1)break;
    
    string ans;
    cout << n << ":";
    
    for(i=0;prime[i]<=n;i++){
      if(n%prime[i]==0){
        cout << " " << prime[i];
      }
    }
    
    cout << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 2592
#include<stdio.h>
#include<math.h>

#define N 1000000
#define M 10000

void main(){
  long int a[M], n, m, play_days;
  scanf("%ld %ld",&n, &m);
  for(int i=0; i<m; i++)
    scanf("%ld ",&a[i]);
  
  play_days = n;
  for(int i=0; i<m; i++)
    play_days -= a[i]; 
  
  if(play_days<0)
    printf("-1");
  else
    printf("%ld", play_days);
}

Measured memory_bytes: 1808
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int main() {
	ll n, k;
	P a[100000];
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + n);
	ll j = 0, sum = a[0].second;
	while (sum < k) {
		j++;
		sum += a[j].second;
	}
	cout << a[j].first << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

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

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

  int result = 1;

  for (int b = 2; b <= sqrt(x); b++) {
    for (int p = 2; p <= 10; p++) {
      int v = pow(b, p);
      if (v <= x) {
        result = max(v, result);
      }
    }
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <limits.h>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin>>n;
    vector<int> ans(n);
    
    int k;
    cin>>k;
    
    vector<int> r(n);
    int e;
    cin>>e;
    r[0] = e;
    ans[0]= 0;
    for(int i=1; i<k && i<n; i++){
        cin>>e;
        int add = INT_MAX;
        for(int j=0; j<i; j++){
            if(ans[j]+abs(e-r[j])<add){
                add =ans[j]+abs(e-r[j]);
            }
        }
        r[i]=e;
        ans[i]=add;
    }
    
    for(int i = k; i<n;i++){
        cin>>e;
        r[i]=e;
        int add = INT_MAX;
        for(int j=i-k; j<i; j++){
            if(ans[j]+abs(e-r[j])<add){
                add =ans[j]+abs(e-r[j]);
            }
        }
        ans[i]=add;
    }
    cout<<ans[n-1]<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()
#define out(x) cout << (x) << endl;

int main(){
	int n;
	string s[10005];
	cin >> n;
	int i, j;
	rep(i, n) cin >> s[i];

	int ans = 0;
	int a_count = 0;
	int b_count = 0;
	int a_b_count = 0;

	rep(i, n){
		int l = s[i].size();
		rep(j, l){
			if(s[i].substr(j, 2) == "AB") ++ans;
		}
		if(s[i][0] == 'B' && s[i][l-1] == 'A') ++a_b_count;
		if(s[i][0] != 'B' && s[i][l-1] == 'A') ++a_count;
		if(s[i][0] == 'B' && s[i][l-1] != 'A') ++b_count;
	}	
  
  	if(a_count + b_count == 0 && a_b_count != 0) cout << a_b_count + ans -1 << endl;
	else cout << min(a_count, b_count) + a_b_count + ans << endl;
	
}


Measured memory_bytes: 768
n, m = map(int, input().split())
students = [list(map(int, input().split())) for i in range(n)]
checks = [list(map(int, input().split())) for i in range(m)]

for i in range(n):
    mn = 10**17
    for j in range(m)[::-1]:
        if mn >= abs(students[i][0] - checks[j][0]) + abs(students[i][1] - checks[j][1]):
            mn = abs(students[i][0] - checks[j][0]) + abs(students[i][1] - checks[j][1])
            ans = j + 1
    print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
int n,pos;
vector<int> pre,in,post;

void rec(int l,int r){
	if(l>=r)return ;
	int root=pre[pos++];//preorder??§????¬??????????
	//inorder????????????c?????????
	int m=distance(in.begin(),find(in.begin(),in.end(),root));
	rec(l,m);//?????¨?????¨?????????
	rec(m+1,r);//?????¨?????¨?????????
	post.push_back(root);
}
void solve(){
	pos=0;
	rec(0,pre.size());
	for (int i = 0; i < n; ++i) {
		if(i)cout<<" ";
		cout<<post[i];
	}
	cout<<endl;
}

int main(){
	int k;
	cin>>n;
	for (int i = 0; i < n; ++i) {
		cin>>k;
		pre.push_back(k);
	}
	for (int i = 0; i < n; ++i) {
			cin>>k;
			in.push_back(k);
	}
	solve();
	return 0;
}

Measured memory_bytes: 3148
import itertools
N,M,Q = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(Q)]
com = list(itertools.combinations_with_replacement(range(1,M+1),N))
answer = 0
for i in com:
    ans = 0
    for j in A:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            ans += j[3]
    answer = max(answer,ans)
print(answer)

Measured memory_bytes: 84632
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = int64_t;

ll dp[200005] = {};
ll sum[200005] = {};
const ll M = 998244353;

int main(int, const char**)
{
    int n, k;
    cin >> n >> k;
    struct Range
    {
        int s;
        int e;
    };
    vector<Range> ranges(k);
    rep(i, k)
    {
        cin >> ranges[i].s >> ranges[i].e;
    }

    sum[1] = 1;
    dp[1] = 1;

    rep(i, n - 1)
    {
        auto t = i + 2;
        auto diff = 0;
        rep(j, k)
        {
            auto& r = ranges[j];
            if(t - r.s < 1) continue;
            auto rmin = max(1, t - r.e);
            auto rmax = t - r.s;
            diff = (diff + (sum[rmax] - sum[rmin - 1] + M) % M) % M;
        }
        dp[t] = diff;
        sum[t] = (sum[t - 1] + diff) % M;
    }

    rep(i, n)
    {
//        cout << dp[i] << endl;
    }

    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 6672
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,a,b=i2()
value=min(n*a,b)
print(value)

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

int main() {
  int n; cin >> n;
  vector<int> vec;
  vec = { 1, 2, 4, 8, 16, 32, 64 };
  if (n == 1) {
    cout << 1;
  }
  else if ((2 <= n) && (n < 4)) {
    cout << 2;
  }
  else if ((4 <= n) && (n < 8)) {
    cout << 4;
  }
  else if ((8 <= n) && (n < 16)) {
    cout << 8;
  }
  else if ((16 <= n) && (n < 32)) {
    cout << 16;
  }
  else if ((16 <= n) && (n < 32)) {
    cout << 16;
  }
  else if ((32 <= n) && (n < 64)) {
    cout << 32;
  }
  else if (64 <= n) {
    cout << 64;
  }
  cout << endl;
}




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


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

  vector<vector<int>> adj(N);
  for(int i = 0; i < N - 1; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  vector<int> ans(N);
  for(int i = 0; i < Q; i++){
    int p, x;
    cin >> p >> x;
    ans[p - 1] += x;
  }

  // now, prev, add_val
  stack<tuple<int, int, int>> st;
  st.push(make_tuple(0, -1, 0));
  while(!st.empty()){
    int now, prev, add_val;
    tie(now, prev, add_val) = st.top();
    st.pop();

    ans[now] += add_val;
    for(auto next: adj[now]){
      if(next != prev){
	st.push(make_tuple(next, now, ans[now]));
      }
    }
  }

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


Measured memory_bytes: 17140
/*
	ID: sixathofpain
	TASK: friday
	LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

int32_t main(){
    IOS;

    int x;
    cin>>x;
    int p = 100;
    int ans = 0;
    while(p<x){
    	p = p + p/100;
    	ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(scanner.next());

		int a = Integer.parseInt(scanner.next());

		int b = Integer.parseInt(scanner.next());


		int max = a > b ? b : a;

		int min = a + b - n;
		min = min > 0 ? min : 0;

		System.out.println(max + " " + min);
	}

}


Measured memory_bytes: 22740
#from functools import lru_cache
#memo = lru_cache(None)
#from sys import setrecursionlimit as srl
#srl(2 * 10**5)
import heapq

rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

def solve(R, C, A):
    pq = [(0, 0, 0)]
    dist = {(0,0): 0}
    INF = float('inf')

    def neighbors(r, c):
        for nr, nc in ((r+1, c), (r, c+1)):
            if 0 <= nr < R and 0 <= nc < C:
                if A[nr][nc] == A[r][c]:
                    yield nr, nc, 0
                else:
                    yield nr, nc, 1
    while pq:
        d, r, c = heapq.heappop(pq)
        if d > dist.get((r, c), INF):
            continue
        if r==R-1 and c==C-1:
            if A[0][0]:
                return (d + 1) // 2
            else:
                return d // 2 + 1
            
        for nr, nc, w in neighbors(r, c):
            nd = d + w
            nei = nr, nc
            if nd < dist.get(nei, INF):
                heapq.heappush(pq, (nd, nr, nc))
                dist[nei] = nd
    return 0
        


for _ in xrange(1):
    R, C = rrm()
    A = []
    for _ in xrange(R):
        row = [c=='.' for c in rr()]
        A.append(row)

print solve(R, C, A)


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

template <typename T>
auto make_vector(size_t sz, T t) {
  return std::vector<T>(sz, t);
}
template <size_t N, typename T, typename U, std::enable_if_t<
  N == 1, std::nullptr_t> = nullptr>
auto make_higher_vector(size_t sz, U u) {
  return make_vector(sz, T(u));
}
template <size_t N, typename T, std::enable_if_t<
  N == 1, std::nullptr_t> = nullptr>
auto make_higher_vector(size_t sz) {
  return std::vector<T>(sz);
}
template <size_t N, typename T, typename... Args, std::enable_if_t<
  N != 1, std::nullptr_t> = nullptr>
auto make_higher_vector(size_t a, Args... args) {
  return make_vector(a, make_higher_vector<N - 1, T>(args...));
}
template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {
  return t.at(i);
}
template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {
  return at(t.at(i), args...);
}

auto at(int x, int j) -> bool
{
  return (x >> j) & 1;
}

template<typename T, typename U>
inline auto cmn (T& a, U b) {if (a > b) {a = b; return true;} return false;}
template<typename T, typename U>
inline auto cmx (T& a, U b) {if (a < b) {a = b; return true;} return false;}

int main()
{
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int sz = 3;
  int n, m; std::cin >> n >> m;
  auto x = make_higher_vector<2, long long>(n, sz, 0);
  for (auto& y : x) for (auto& z : y) std::cin >> z;
  auto cal = [&] (int bs) -> long long
  {
    std::vector<long long> v(n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < sz; j++) {
        v.at(i) += x.at(i).at(j) * (2 * at(bs, j) - 1);
      }
    }
    std::sort(v.begin(), v.end(), std::greater<long long>{});
    return std::accumulate(v.begin(), v.begin() + m, 0LL);
  };
  long long ret = 0;
  for (int i = 0; i < 8; i++)
  {
    cmx(ret, cal(i));
  }
  std::cout << ret << std::endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

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

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

int count2(long long x)
{
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		++ret;
	}
	return ret;
}

long long solve(int N, int M, const vector<long long> &a)
{
	int c2 = count2(a[0]);
	for (auto x : a) {
		if (count2(x) != c2) {
			return 0;
		}
	}

	long long m = 1;

	for (auto x : a) {
		m = lcm(m, x);
		if (m > 2LL * M) {
			return 0;
		}
	}
	
	return 1 + (M - m / 2) / m;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<long long> a(N);
	for (auto &x : a) {
		cin >> x;
	}

	cout << solve(N, M, a) << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
int main(){
	int N;long W;cin>>N>>W;
	long w,s;int v;
	vector<int> a[4];
	rep(i,0,4) a[i].push_back(0);
	rep(i,0,N){
		cin>>w>>v;
		if(i == 0) s = w;
		a[w - s].push_back(v);
	}
	rep(i,0,4){
		sort(a[i].begin() + 1 , a[i].end() , greater<int>());
		rep(j,1,a[i].size()) a[i][j] += a[i][j-1];
	}
	int ans = 0;
	rep(i,0,a[0].size())rep(j,0,a[1].size())rep(k,0,a[2].size())rep(l,0,a[3].size()){
		if(i*s + j*(s+1) + k*(s+2) + l*(s+3) <= W){
			ans = max(ans , a[0][i] + a[1][j] + a[2][k] + a[3][l]);
		}
	}cout<<ans<<endl;
}

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

if 0 in A:
  ans = 0
else:
  ans = 1
  max_limit = 10 ** 18
  for i in range(N):
    if ans * A[i] > max_limit:
      ans = -1
      break
    else:
      ans *= A[i]

print(str(ans))

Measured memory_bytes: 21628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
           
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


const int coin[] = { 500, 100, 50, 10, 5, 1 };
int min_coin(int change)
{
    int res = 0;
    rep (i, 6)
    {
	int c = change / coin[i];
	res += c;
	change -= c * coin[i];
    }
    return res;
}
bool operator==(const pint& a, const pint& b)
{
    return a.first == b.first;
}
int main()
{
    int p, n[6];
    while (scanf("%d", &p), p)
    {
	rep (i, 6)
	    scanf("%d", n + i);
	reverse(n, n + 6);

	vector<pint> d[7];
	d[0].push_back(pint(p,0));

	int res = 1 << 25;
	rep (i, 6)
	{
	    rep (j, d[i].size())
	    {
		int left = d[i][j].first;
		int use = d[i][j].second;
		for (int c = min(n[i], max(0, left / coin[i]));
		     c <= n[i] && c * left - c * coin[i] >= -500; ++c)
		{
		    d[i + 1].push_back(pint(left - c * coin[i], use + c));
		}
	    }
	    sort(all(d[i + 1]));
	    d[i + 1].erase(unique(all(d[i + 1])), d[i + 1].end());
	    rep (j, d[i + 1].size())
	    {
		int left = d[i + 1][j].first;
		int use = d[i + 1][j].second;
		if (left <= 0)
		    min_swap(res, use + min_coin(-left));
		// printf("%d, %d\n", left, use);
	    }
	}
	printf("%d\n", res);
    }
}

Measured memory_bytes: 1220
#include<iostream>
#define MAX 200002
using namespace std;
typedef long long LL;
int n;
int nums[MAX];
int L[MAX / 2 + 2];
int R[MAX / 2 + 2];
LL mergeSort(int left,int right) {
	if (left >= right) {
		return 0;
	}
	int middle = (left + right) / 2;
	LL inverNum1 = mergeSort(left, middle);
	LL inverNum2 = mergeSort(middle + 1, right);
	LL rinverNum = inverNum1 + inverNum2;

	int len1 = middle - left + 1;
	int len2 = right - middle;
	int len = right - left + 1;
	//拷贝
	int j = 0;
	for (int i = left; i <= middle; i++,j++) {
		L[j] = nums[i];
	}
	j = 0;
	for (int i = middle+1; i <= right; i++, j++) {
		R[j] = nums[i];
	}

	//归并
	int i = 0,k=left;
	j = 0;
	while (i<len1 && j<len2) {
		if (L[i] <= R[j]) {
			nums[k] = L[i];
			i++;
			k++;
		}
		else if (R[j] < L[i]) {
			nums[k] = R[j];
			rinverNum += len1 - i;
			j++;
			k++;
		}
	}
	if (i < len1) {
		for (i; i < len1; i++, k++) {
			nums[k] = L[i];
		}
	}
	else if (j < len2) {
		for (j; j < len2; j++, k++) {
			nums[k] = R[j];
		}
	}
	return rinverNum;
}
int main() {
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	LL inverNum = mergeSort(0,n-1);
	cout << inverNum << endl;

	/*for (int i = 0; i < n; i++) {
		cout << nums[i] << " ";
	}*/
}


Measured memory_bytes: 4644
#include <cstdio>
#include <cstdlib>
//#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

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

	for (int i = 0; i < n; i++){
		set<string> result;
		result.clear();

		string str;
		cin >> str;


		for (int j = 1; j < str.size(); j++){
			string sub1 = str.substr(0, j);
			string sub2 = str.substr(j, str.size() - j);

			result.insert(sub1 + sub2);
			result.insert(sub2 + sub1);
			reverse(sub1.begin(), sub1.end());
			result.insert(sub1 + sub2);
			result.insert(sub2 + sub1);
			reverse(sub2.begin(), sub2.end());
			result.insert(sub1 + sub2);
			result.insert(sub2 + sub1);
			reverse(sub1.begin(), sub1.end());
			result.insert(sub1 + sub2);
			result.insert(sub2 + sub1);
		}

		cout << result.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1292
H,W,M = map(int,input().split())
h = []
w = []

for i in range(M):
    tmp1,tmp2 = map(int,input().split())
    h.append(tmp1)
    w.append(tmp2)

dic1 = {}
dic2 = {}

for i in h:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1

val1 = max(dic1,key=dic1.get)
ans = 0
ans +=dic1[val1]
for j in range(M):
    if h[j] != val1:
        if w[j] not in dic2:
            dic2[w[j]] = 1
        else:
            dic2[w[j]] +=1
if dic2:
    val2 = max(dic2,key=dic2.get)
    ans +=dic2[val2]


dic1 = {}
dic2 = {}

for i in w:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1
val1 = max(dic1,key=dic1.get)
ans1 = 0
ans1 +=dic1[val1]
for j in range(M):
    if w[j] != val1:
        if h[j] not in dic2:
            dic2[h[j]] = 1
        else:
            dic2[h[j]] +=1
if dic2:
    val2 = max(dic2,key=dic2.get)
    ans1 +=dic2[val2]
print(max(ans,ans1))

Measured memory_bytes: 176424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s = sc.next();
		int k = sc.nextInt();
		Set<String> set = new HashSet<>();
		
		for (int i = 0; i < s.length(); i++) {
			for (int j = 1; j <= Math.min(k, s.length()-i); j++) {
				set.add(s.substring(i, i+j));
			}
		}
		List<String> res = new ArrayList<>(set);
		Collections.sort(res);
		/*for (int i = 0; i < res.size(); i++) {
			System.out.println(res.get(i));
		}*/
		
		System.out.println(res.get(k-1));
	}

    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
const char endk = '\n';
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //const ll mod = 1e9 + 7;
    //const ll mod = 998244353;

	ll h, w, k;
	cin >> h >> w >> k;
	vector<string> c(h);
	for (ll i = 0; i < h; i++) cin >> c[i];

	ll n = (1 << h), m = (1 << w);
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		bitset<6> a = i;
		for (ll j = 0; j < m; j++) {
			bitset<6> b = j;
			ll cnt = 0;
			for (ll l = 0; l < h; l++) {
				for (ll o = 0; o < w; o++) {
					if (!a[l] && !b[o] && c[l][o] == '#') {
						cnt++;
					}
				}
			}
			if (cnt == k) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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

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


int N, M;
vector<int> x;
vector<int> a;

int main () {
  cin >> N >> M;

  Rep(i, M) {
    int tmp;
    cin >> tmp;
    x.push_back(tmp);
  }

  sort(All(x));

  int sum = x[M-1] - x[0];

  Rep(i, M-1) {
    int tmp = x[i+1] - x[i];
    a.push_back(tmp);
  }

  sort(All(a), greater<int>());

  Rep(i, N-1) {
    if (sum > 0) {
      sum -= a[i];
    }
  }

  cout << sum << "\n";
}

Measured memory_bytes: 1400