akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
typedef pair<int, int> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

void buildSA(const string &s, vector<ll> &sa, vector<ll> &rank) {
    int N = s.size();
    vector<int> tmp(N + 1);
    sa.assign(N + 1, 0);
    rank.assign(N + 1, 0);
    for (int i = 0; i < N + 1; ++i) sa[i] = i, rank[i] = (i < N ? s[i] : -1);

    int h;
    auto comp = [&](int x, int y) {
        return rank[x] != rank[y] ? rank[x] < rank[y]
                                  : (x + h <= N ? rank[x + h] : -1) < (y + h <= N ? rank[y + h] : -1);
    };
    for (h = 1; h <= N; h *= 2) {
        sort(sa.begin(), sa.end(), comp);
        tmp[sa[0]] = 0;
        for (int i = 1; i <= N; ++i)
            tmp[sa[i]] = tmp[sa[i - 1]] + (comp(sa[i - 1], sa[i]) ? 1 : 0);
        for (int i = 0; i <= N; ++i)
            rank[i] = tmp[i];
    }
}

int findSA(const string &t, const string &p, const vector<ll> &sa) {
    int a = 0, b = t.size(), m = p.size();
    while (a < b) {
        int c = (a + b) / 2;
        if (strncmp(t.c_str() + sa[c], p.c_str(), m) < 0)
            a = c + 1;
        else
            b = c;
    }
    return strncmp(t.c_str() + sa[a], p.c_str(), m) == 0 ? sa[a] : -1;
}

int main() {


    string text;
    cin >> text;
    vector<ll> sa, rank;
    buildSA(text, sa, rank);

    int l;
    cin >> l;
    rep(i, l) {
        string p;
        cin >> p;
        cout << (findSA(text, p, sa) != -1) << endl;
    }

}


Measured memory_bytes: 23468
#include <iostream>
#include <vector>
long long INF = 1e18;
long long V, E;
std::vector<std::vector<long long>> G;
struct edge{
    int to;
    long long cost;
};
void waflo(){
    long long d[V][V];
    for(int i = 0; i < V; i++){
        for(int j = 0; j < V; j++) d[i][j] = INF;
        d[i][i] = 0;
    }
    for(int i = 0; i < E; i++){
        long long s, t, g;
        std::cin >> s >> t >> g;
        d[s][t] = g;
    }
    for(int k = 0; k < V; k++){
        for(int i = 0; i < V; i++){
            for(int j = 0; j < V; j++){
                if(d[i][j] > d[i][k] + d[k][j] && d[k][j] != INF && d[i][k] != INF){
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
    for(int i = 0; i < V; i++){
        if(d[i][i] < 0) {
            std::cout << "NEGATIVE CYCLE" << std::endl;
            return;
        }
    }
    for(int i = 0; i < V; i++){
        for(int j = 0; j < V; j++){
            if(d[i][j] == INF) std::cout << "INF";
            else std::cout << d[i][j];
            if(j == V -1) std::cout << std::endl;
            else std::cout << ' ';
        }
    }
}
int main(){
    std::cin >> V >> E;
    waflo();
}


Measured memory_bytes: 3160
/*input
10 10
3 1 4 1 5 9 2 6 5 3
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e17;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=3e3+5;
const ll maxlg=__lg(maxn)+5;
ll dp[maxn][maxn];
int main(){
    int n,s;
    cin>>n>>s;
    ll ans=0;
    dp[0][0]=1;
    REP(i,n){
        int x;
        cin>>x;
        REP(j,s+1){
            //cout<<dp[i][j]<<' ';
            dp[i+1][j]=mult(dp[i][j],2);
        }
        REP(j,s-x+1){
            dp[i+1][j+x]+=dp[i][j];
            dp[i+1][j+x]%=MOD;
        }
    }
    cout<<dp[n][s];
}


Measured memory_bytes: 74072
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from itertools import accumulate

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    h = list(map(int, sys.stdin.readline().split()))
    for i in range(n-1):
        if h[i] > h[i+1] or (i>0 and h[i-1]<h[i] and h[i] == h[i+1]):
            h[i] -= 1
    s = sorted(h)

    if s == h:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 16292
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());

int main()
{
    int n;
    cin >> n;
    int ans = INT_MAX;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        rep(j, 32)
        {
            if (temp >> j & 0b1)
            {
                if (j < ans)
                    ans = j;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define mp make_pair

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef list<int> li;
typedef vector<li> vli;
typedef vector<vpi> vvpi;
typedef long long i64;

const int inf = 1e9 + 500500;

int get(vi& dsu, int i) {
  return dsu[i] != i ? dsu[i] = get(dsu, dsu[i]) : i;
}

void solve_e_fast() {
  int n,k,q;
  cin >> n >> k >> q;
  vi a(n);
  vector<multiset<int>> S(n);
  multiset<int> S0, S1;
  vector<int> dsu(n); forn(i, n) dsu[i] = i;
  auto merge = [&] (int i, int j) {
    if ((i = get(dsu, i)) == (j = get(dsu, j))) return ;
    if (S[i].size() < S[j].size()) swap(i, j);
    dsu[j] = i;
    for (int x: S[j]) S[i].insert(x);
    S[j].clear();
  };
  forn(i, n) {
    cin >> a[i];
    S[i].insert(a[i]);
  }
  int ans = inf;
  vi ord(n); forn(i, n) ord[i] = i; sort(all(ord), [&] (int i, int j) { return mp(a[i], i) > mp(a[j], j); });
  vi used(n, 0);
  if (q > 1) for (int i: ord) {
    if (i + 1 < n && used[i + 1]) merge(i, i + 1);
    if (i > 0 && used[i - 1]) merge(i, i - 1);
    used[i] = 1;
    i = get(dsu, i);
    while (S[i].size() > k - 1) {
      S0.insert(*S[i].begin());
      S[i].erase(S[i].begin());
    }
    while (S0.size() >= q) {
      S1.insert(*S0.rbegin());
      S0.erase(prev(S0.end()));
    }
    if (S0.size() == q - 1 && !S1.empty()) {
      uin(ans, *(S1.begin()) - *(S0.begin()));
    }
  } else ans = 0;
  cout << ans << endl;
}

void solve_e() {
  int n,k,q;
  cin >> n >> k >> q;
  vi a(n);
  forn(i, n) cin >> a[i];
  int ans = inf;
  vi b(a); sort(all(b)); b.erase(unique(all(b)), b.end());
  vi t, z;
  for (int L: b) {
    t.clear(); z.clear();
    for (int x: a) {
      if (x < L) {
        if (t.size() >= k) {
          nth_element(t.begin(), t.begin() + t.size() - k, t.end());
          z.insert(z.end(), t.begin(), t.begin() + t.size() - k + 1);
        }
        t.clear();
      } else t.pb(x);
    }
    if (t.size() >= k) {
      nth_element(t.begin(), t.begin() + t.size() - k, t.end());
      z.insert(z.end(), t.begin(), t.begin() + t.size() - k + 1);
    }
    if (z.size() >= q) {
      nth_element(z.begin(), z.begin() + q - 1, z.end());
      if (q > 1) {
        nth_element(z.begin(), z.begin() + 1, z.begin() + q - 1);
      }
      uin(ans, z[q - 1] - z[0]);
    } else break;
  }
  cout << ans << endl;
}

int main() {
#ifdef HOME
  freopen("../input.txt", "rt", stdin);
#endif
  solve_e_fast();
  return 0;
}


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

int main(){
    int r, g, b;/*int型変数r,g,bを定義*/
    cin >> r >> g >> b;/*変数r,g,bに標準入力を格納*/
    int c = 100 * r + 10 * g + b;/*int型変数cを定義し変数r,g,bで3桁の整数を作り変数cに格納*/
    if (c % 4 == 0) cout << "YES" << endl;/*変数cが4の倍数ならYESを出力*/
    else cout << "NO" << endl;/*4の倍数でないならNOを出力*/
}

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

def calcsum(i):
	sum = 0
	while (i>0):
		sum += i%10
		i -= i%10
		i = i/10
	#print(sum)
	return sum

tmparr = input().split()

n = int(tmparr[0])
a = int(tmparr[1])
b = int(tmparr[2])
sum = 0

#print("n:{}".format(n))
#print("a:{}".format(a))
#print("b:{}".format(b))

for i in range(n+1):
	tmp = calcsum(i)
	if(tmp >= a):
		if(tmp <= b):
			sum += i
print(sum)



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

int main(){
  cin.tie(0);
 	ios::sync_with_stdio(false);
  long x;
  cin >> x;
  bitset<32> a(x);
  cout << a << "\n";
  cout << ~a << "\n";
  cout << (a<<1) << "\n";
  cout << (a>>1) << "\n";
  return 0;
}


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

int main(){
    long H,W;
    cin >> H >> W;
    long long board;
    board=H*W;
    if(H==1 || W==1){
        cout << 1 << endl;
    }
    else if(board%2==0){
        cout << board/2 << endl;
    }
    else{
        cout << board/2+1 << endl;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>

using namespace std;
char s[13];

int main() {
	char s1[5];
	char s2[9];
	cin >> s;

	for (int i = 0; i < 4; i++) {
		s1[i] = s[i];
	}
	s1[4] = '\0';
	for (int i = 0; i < 8; i++)
	{
		s2[i] = s[i + 4];
	}
	s2[8] = '\0';
	cout << s1 <<" " << s2 << endl;;

}

Measured memory_bytes: 256
import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []
 
for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
  
countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)
 
leftkeys = [k for k, v in countleft.items() if v == leftmax]
rightkeys = [k for k, v in countright.items() if v == rightmax]
 
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)
#これで左右の最頻回数はOK
#左右の最頻奴も探した
#ここから最頻同志になってるやつを探す
 
for i in range(M):
    goukei = int(countleft.get(c[i][0])) + int(countright.get(c[i][1]))
    if goukei == tempmax:
        cnt += 1
    else:
        pass

if cnt == int(leftkeyN * rightkeyN):
    print(int(tempmax - 1))
else:
    print(int(tempmax))

Measured memory_bytes: 274152
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int N;
    cin >> N;
    ll S;
    cin >> S;
    vector<ll> a(N + 1, 0);
    for (int i = 1; i <= N; i++)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    if (a[N] < S)
    {
        cout << 0 << endl;
        return 0;
    }
    int ret = INF;
    for (int i = 1; i <= N; i++)
    {
        if (a[i] < S)
            continue;
        auto itr = upper_bound(a.begin(), a.end(), a[i] - S);
        itr--;
        int pos = distance(a.begin(), itr);
        ret = min(ret, i - pos);
    }
    cout << ret << endl;
}



Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
    int n,t,cot=0,mn=0,idx;
    scanf("%d %d",&n,&t);
    int ar[n];
    int y[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&ar[i],&y[i]);
        if(y[i]<=t)
            cot++;
    }
    if(cot==0)
    {
        printf("TLE\n");
        return 0;
    }
    int z[cot];
    for(int i=0,j=0;i<n;i++)
    {
        if(y[i]<=t)
            {
                z[j]=ar[i];
                j++;
            }
    }
    for(int i=0;i<cot;i++)
    {
        mn=z[i];
        idx=i;
        for(int j=i+1;j<cot;j++)
        {
            if(z[j]<mn)
            {
                mn=z[j];
                idx=j;
            }
        }
        if(idx!=i)
        {
            int temp;
            temp=z[i];
            z[i]=z[idx];
            z[idx]=temp;
        }
    }
    //sort(z,z+cot);
    printf("%d\n",z[0]);

    return 0;

}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

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

	int n;
	ll k, count[100001] = {};
	cin >> n >> k;
	REP(i, n){
		int x, y;
		cin >> x >> y;
		count[x] += y;
	}
	for (int i = 1; i <= 100000; ++i){
		if (k <= count[i]){
			cout << i << "\n";
			break;
		}
		k -= count[i];
	}
	return 0;
}

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

int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int tree[500001];
int n,q;
void update(int p,int q)
{
   while(p<=n)
   {
    tree[p]+=q;
    p+=p&(-p);
   }
}
int s1(int p)
{
    int sum=0;
    while(p>0)
    {
       sum+=tree[p];
       p-=p&(-p);
    }
    return sum;
}
void solve()
{
     
     cin>>n>>q;
     rep(i,1,n+1)
     {
        int x;
        cin>>x;
        update(i,x);
     }
     while(q--)
     {
        int x,a,b;
        cin>>x>>a>>b;
        a+=1;
       if(x==1)
       {
        b+=1;
        cout<<s1(b-1)-s1(a-1)<<endl;
       }
       else
        update(a,b);
        
     }


}

signed main()
{
        FIO
        
        
        int t=1;
        //cin>>t;
        while(t--)
        solve();
        cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}

Measured memory_bytes: 8264
#!/usr/bin/env python3
def main():
    N = int(input())
    happiness = [list(map(int, input().split())) for _ in range(N)]

    dp = [0, 0, 0]
    for a, b, c in happiness:
        dp = [max(dp[1], dp[2]) + a,
              max(dp[0], dp[2]) + b,
              max(dp[0], dp[1]) + c]
    print(max(dp))


if __name__ == '__main__':
    main()


Measured memory_bytes: 30052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  long long x , ans = 0 , amari = 0 ;
  cin >> x;
  
  ans += 2 * ( x / 11 );
    
  amari = x % 11;
    
  if  ( 0 < amari && amari <= 6)
    ans += 1;
  if (6 < amari)
    ans += 2;
  
  cout << ans << endl;
}

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

int main(){

    int ashiba_num, jump_num;
    int i,j;
    int dP_min,dP_now;

    scanf("%d", &ashiba_num);
    scanf("%d", &jump_num);

    int ashiba_cost[ashiba_num];
    int dP[ashiba_num + 1];

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

    dP[0] = 0;
    dP[1] = abs(ashiba_cost[1] - ashiba_cost[0]);

    for (i = 2 ; i <= ashiba_num - 1 ; i++){
        dP_min = 1e9;

        for (j = 1 ; j <= jump_num ; j++){
            if (i - j >= 0){
                dP_now = dP[i - j] + abs(ashiba_cost[i] - ashiba_cost[i - j]);
            }else{
                dP_now = abs(ashiba_cost[i] - ashiba_cost[0]);
            }

            if ( dP_min >= dP_now || dP_min < 0 ){
                dP_min = dP_now;
            }
        }
        dP[i] = dP_min;
    }
    printf("%d\n", dP[ashiba_num - 1]);
}

Measured memory_bytes: 896
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[100000];
int res[100000];
int main(){
  int i;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
    }
  }
  for(i=(0);i<(N);i++){
    res[A[i]] = i+1;
  }
  {
    int KL2GvlyY;
    if(N==0){
      putchar_unlocked('\n');
    }
    else{
      for(KL2GvlyY=(0);KL2GvlyY<(N-1);KL2GvlyY++){
        wt_L(res[KL2GvlyY]);
        wt_L(' ');
      }
      wt_L(res[KL2GvlyY]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190929-1

// --- original code ---
// int N, A[1d5], res[1d5];
// {
//   rd(N,(A--)(N));
//   rep(i,N) res[A[i]] = i+1;
//   wt(res(N));
// }


Measured memory_bytes: 1536
X, K, D = [int(n) for n in input().split()]
x = abs(X)
d = (x+D-1)//D
r = x % D
ans = 0
if d<=K:
    if X>0:
        X -= d*D
    else:
        X += d*D
    K -= d
    if K%2==0:
        ans = X
    else:
        if X>0:
            ans = X-D
        else:
            ans = X+D
else:
    if X>0:
        ans = X-K*D
    else:
        ans = X+K*D
print(abs(ans))


Measured memory_bytes: 9132
def root(v):
    if par[v] == v:
        return v
    r = root(par[v])
    diff_weight[v] += diff_weight[par[v]]
    par[v] = r
    return r

def weight(v):
    root(v)
    return diff_weight[v]

def diff(u, v):
    return weight(v) - weight(u)

def unite(u, v, w):
    w += diff(v, u)
    u = root(u)
    v = root(v)
    if u == v:
        return
    if rank[u] < rank[v]:
        u, v = v, u
        w = -w
    par[v] = u
    diff_weight[v] = w
    if rank[u] == rank[v]:
        rank[u] += 1

def same(u, v):
    return root(u) == root(v)

N, M = map(int, input().split())
par = list(range(N))
rank = [0] * N
diff_weight = [0] * N
for _ in range(M):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    if same(l, r):
        dist = diff(l, r)
        if dist != d:
            print("No")
            exit()
    else:
        unite(l, r, d)

print("Yes")

Measured memory_bytes: 10708
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main()
{
	ll A[100002] = {};
	ll N, K; cin >> N >> K;
	rep(i, 0, N) {
		ll a, b;
		cin >> a >> b;
		A[a] += b;
	}
	ll p = 0;
	repe(i, 1, 100000) {
		if (A[i] != 0) {
			p += A[i];
			if (p >= K) {
				cout << i << endl;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1024
N,M = map(int, raw_input().split())
C = [0]*N
for _ in range(M):
    a,b = map(int, raw_input().split())
    C[a-1] += 1
    C[b-1] += 1
ok = True
for c in C:
    if c%2!=0:
        ok = False
print "YES" if ok else "NO"


Measured memory_bytes: 8580
n,k=map(int,input().split())
mod=10**9+7
dp=[pow(k//i,n,mod) for i in range(1,k+1)]
exactly=[0]*k
for i in range(k,0,-1):
    f=0
    for j in range(2*i,k+1,i):
        f+=exactly[j-1]
    exactly[i-1]=dp[i-1]-f
    exactly[i-1]%=mod
print(sum(i*exactly[i-1]%mod for i in range(1,k+1))%mod)

Measured memory_bytes: 13564
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	vector< pair<int,int> > p;
	for(int i=0;i<n;i++){
		cin>>a[i];
		p.pb( mp(a[i],0) );
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
		p.pb( mp(b[i],1) );
	}
	sort( p.begin(), p.end() );
	int ac = 0, bc = 0;
	int ans = 1;
	for(int i=0;i<p.size();i++){
		int tp = p[i].second;
		if( tp == 1 ){
			if( bc == 0 ){
				ac++;
			}
			else{
				ans *= bc;
				ans %= inf;
				bc--;
			}
		}
		else{
			if( ac == 0 ){
				bc++;
			}
			else{
				ans *= ac;
				ans %= inf;
				ac--;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 1};
int dx[]={1, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int h, w; cin >> h >> w;
    char board[10][10];
    bool ok[10][10] = {};
    ok[0][0] = true;
    rep(i,0,h) rep(j,0,w) cin >> board[i][j];

    int x = 0, y = 0;
    while(1) {
        if(x == h-1 && y == w-1) break;
        int cnt = 0, dir, xx, yy;
        rep(i,0,2) {
            xx = x + dx[i];
            yy = y + dy[i];
            if(0 <= xx && xx < h && 0 <= yy && yy < w) {
                if(board[xx][yy] == '#') {
                    cnt++;
                    dir = i;
                }
            }
        }
        // cout << cnt << endl;
        if(cnt != 1) {
            cout << "Impossible" << endl;
            return 0;
        }
        else {
            x += dx[dir];
            y += dy[dir];
            ok[x][y] = true;
        }
    }
    rep(i,0,h) rep(j,0,w) {
        if(board[i][j] == '#' && !ok[i][j]) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std ;
int main()
{
	int n;
	cin >> n ;
	int f,s=0;
	for(int i=1;i<=n;i+=2){
		f=0;
		for(int j=1;j<=i;j++)
			if(i%j==0) f++;
		if(f==8) s++;
	}
	cout << s ;
	return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b = 0,c,d, n, k;
string s, t;


int main()
{
	cin >> a >> b ;
	int sa=b-a;
	cout << sa * (sa + 1) / 2 - b << endl;
	return 0;
}


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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(auto &j:a)
        cin>>j;
    ll x=0;
    for(int i=0;i<n;++i)
        x^=a[i];
    if(x==0)
    {
        cout<<0<<'\n';
        return 0;
    }
    if(a[0]==1)
    {
        cout<<-1;
        return 0;
    }
    ll s=a[0]+a[1];
    ll y=x^a[0]^a[1];
    if(y%2!=s%2)
    {
        cout<<-1;
        return 0;
    }
    ll z=(s-y)/2;
    ll a1=0,a2=0;
    bool mark[40];
    memf(mark);
    for(int i=0;i<40;++i)
    {
        if(y&(1LL<<i))
        {
            if(z&(1ll<<i))
            {
                cout<<-1;
                return 0;
            }
            mark[i]=true;

        }
        else
        {
            if(z&(1ll<<i))
                a1+=1LL<<i,a2+=1ll<<i;
        }
    }
    ll ans=INF;
    if(a1<=a[0])
    {
        ll xx=a[0]-a1;
        for(int i=39;i>=0;--i)
            if(mark[i] && (1ll<<i)<=xx)
                xx-=1ll<<i;
        amin(ans,xx);
    }
    if(a2<=a[0])
    {
        ll xx=a[0]-a2;
        for(int i=39;i>=0;--i)
            if(mark[i] && (1ll<<i)<=xx)
                xx-=1ll<<i;
        amin(ans,xx);
    }
    cout<<(ans==INF || ans==a[0]?-1:ans);
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 3644
package main

import (
	"bufio"
	"fmt"
	"os"
)

var stdin = bufio.NewScanner(os.Stdin)
var t string

func main() {
	stdin.Scan()
	t = stdin.Text()
	dfs(1, int(t[0]^'0'), t[0:1])
}

func dfs(i, data int, ans string) bool {
	if i == 4 {
		if data == 7 {
			fmt.Println(ans + "=7")
			return true
		}
		return false
	}
	if !dfs(i+1, data+int(t[i]^'0'), ans+"+"+t[i:i+1]) {
		return dfs(i+1, data-int(t[i]^'0'), ans+"-"+t[i:i+1])
	}
	return true
}

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


int main() {
    int N;
    cin >> N;
  	vector<int> ans(10050);
  	int v;
    rep(x, 105){
        rep(y, 105){
            rep(z, 105){
                v = x*x + y*y + z*z + x*y + y*z + z*x;
                if(v<10050) ans.at(v)++;
                
            }
        }
    }
    
    rep(i, N){
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
using namespace std;
int MX = (1<<15);
int n ,a,x,y,cntr,ans=0;
vector< pair<int , int > >arr[15];
vector<deque<bool> >states;
deque<bool> tmp;
void rec(int i)
{
    if(i== n)
    {
        states.push_back(tmp);
        return;
    }
    tmp.push_back(1);
    rec(i+1);
    tmp.pop_back();
    tmp.push_back(0);
    rec(i+1);
    tmp.pop_back();
}
int main()
{
    cin >> n;
    int a[n];
    for(int i = 0 ; i < n ;i++)
    {
        cin >> a[i] ;
        for(int j = 0  ; j < a[i] ; j++)
        {
            cin >> x >> y;
            arr[i].push_back(make_pair(x,y));
        }
    }
    rec(0);
    bool flag = true;
    for(int i = 0 ; i < states.size() ; i++)
    {
        cntr=0;
        flag=true;
            for(int k = 0 ;  k < n ;k++)
            {
                for(int s = 0 ; s < a[k] ;s++ )
                {
                    if(states[i][arr[k][s].first-1]!=arr[k][s].second&&states[i][k]!=0)
                    {
                        flag=false;
                        break;
                    }
                }
                if(flag!=true)
                {
                    break;
                }
            }
            if(flag)
            {
                for(int f = 0 ; f < states[i].size();f++)
                {
                    if(states[i][f]==1)
                        cntr++;
                }
                ans=max(ans,cntr);
            }
    }
    cout << ans;
}

Measured memory_bytes: 23444
using System;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var ab = Console.ReadLine().Split();
			int a = int.Parse(ab[0]);
			int b = int.Parse(ab[1]);

			if (a >= 10 || b >= 10)
			{
				Console.WriteLine(-1);
			}
			else
			{
				Console.WriteLine(a * b);
			}
		}
	}
}


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

int main() {
	long long n,k,m,a=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>m;
		if(m>=k)
		a++;
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#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 n;
    cin >> n;
    int ans = 1000 - n%1000;
    if(ans ==1000)ans = 0;
    cout << ans << endl;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }

    int ans = -(1 << 29);
    for (int i = 0; i < 1 << N; i++) {
        int X = 0, Y = 0;
        for (int j = 0; j < N; j++) {
            if (i >> j & 1) {
                X += V[j];
                Y += C[j];
            }
        }
        ans = max(ans, X - Y);
    }
    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int X,Y,Z,A,B,C;
        X = input.nextInt();
        Y = input.nextInt();
        Z = input.nextInt();
        A = Z;
        B = X;
        C = Y;
        System.out.println(A+" "+B+" "+C);
    }
    
}


Measured memory_bytes: 27056
#include<iostream>
using namespace std;
int main(void){
  int cnt=0;
  char str[5];
  cin>>str;
  for(int i=0;i<4;i++){
      if(str[i]==str[i+1])
        cnt++;
  }
    if(str[1]==str[2])
    cnt++;
    if(str[1]==str[3])
    cnt++;
    if(str[0]==str[2])
    cnt++;
  if(cnt==2)
      cout<<"Yes";
  else
  cout<<"No";
}

Measured memory_bytes: 256
import math

N = int(input())
V = []
for _ in range(N):
    V.append([ int(n) for n in input().split() ])

R2 = 0
for i in range(100):
    theta = 2*math.pi * i / 100
    a, b = math.cos(theta), math.sin(theta)
    X, Y = 0, 0
    for x, y in V:
        if a*x+b*y > 0:
            X += x
            Y += y
    r2 = X**2+Y**2
    if r2 > R2:
        R2 = r2

print(math.sqrt(R2))

Measured memory_bytes: 3188
N,*M=`dd`.split.map &:to_i;X,Y,*A,_=M.shift N;D=*0..1e6;s=0;A.map{|e|s+=e.times{|j|D.unshift D[j*2+1]}};M.map{|e|p (D[e]||e-s)+X-Y}

Measured memory_bytes: 88580
import java.util.*;
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int min = 0;
		
		while(true){
			if (Math.abs(a-b) <= w){
				System.out.println(min);
				break;
			}else{
				min+=1;
				w++;
			}
		}
	}
}

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

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

    int N;
    cin >> N;
    vector<int> b(N);
    vector<int> ans;
    bool canMake = true;
    for (int i = 0; i < N; i++)
    {
        cin >> b[i];
        if (b[i] > i + 1)
        {
            canMake = false;
        }
    }

    if (!canMake)
    {
        cout << -1 << endl;
        return 0;
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = b.size() - 1; j >= 0; j--)
        {
            if (b[j] == j + 1)
            {
                ans.push_back(b[j]);
                b.erase(b.begin() + j);
                break;
            }
        }
    }

    if (b.size() == 0)
    {
        for (int i = ans.size() - 1; i >= 0; i--)
        {
            cout << ans[i] << endl;
        }
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = input()
s_num = len(n) -1 
all_p_m = []
for i in range(2**s_num):
  p_m_list = [False for i in range(s_num)]
  for j in range(s_num):
    if ((i >>j) & 1):
      p_m_list[j] = True
  all_p_m.append(p_m_list)
  
for p_m in all_p_m:
  result = int(n[0])
  for i in range(len(p_m)):
    if p_m[i] == True:
      result += int(n[i + 1])
    else:
      result -= int(n[i + 1])
  if result == 7:
    ans_p_m = p_m

ans = ["0" for i in range(7)]
for _ in range(7):
  if _ %2 ==0:
    ans[_] = n[_//2]
  else:
    if ans_p_m[_//2] == True:
    	ans[_] = "+"
    else:
      ans[_] = "-"
ans.append("=7")    
print("".join(ans))
      
   
      

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 1; i <= N; i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    int cnt = 0;
    int i = 1;
    while (i != 2)
    {
        i = a[i];
        // cout << i << endl;
        ans++;
        cnt++;
        if (cnt >= N)
        {
            cout << -1 << endl;
            return 0;
        }
    }

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


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

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define NL              pf("\n")
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       (((a)/gcd(a,b))*b)
#define mx              1234567899
#define TC              int t;scin(t);while(t--)
#define PI              2*acos(0.0)
#define rep(i,a,b)      for( i=a; i<=b; i++)
#define rev(i,a,b)      for( i=a; i>=b; i--)
#define file            freopen("E:\\file.txt", "r", stdin);ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x)          x.begin(),x.end()
#define DEBUG(args...)    do {   cerr << #args << ' ' ;  print(args); } while(0); cerr<< endl ;
using namespace std;
int get(int n,int p){int res = 0;while(n>=p) res+=n/p,n/=p;return res;}
template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1); }
void VC(vector<ll> &v){for(int i=0;i<v.size();i++) printf("%lld ", v[i]);printf("\n");}

template< typename T > void print(const T& v) {    cerr << v << ' ' ;}
template< typename T1, typename... T2 >
void print( const T1& first, const T2&... rest ){
    print(first);
    print(rest...) ;
}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

long long BigMod(long long int a, long long int b, int M) { long long remainder, answer = 1;remainder = a%M; while(b!=0){if(b%2==1) answer = (answer*remainder)%M;remainder = (remainder*remainder)%M;b/=2;}return answer;}
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22)pf("bust\n");
        else pf("win\n");
    return 0;
}


Measured memory_bytes: 256
# input
x, y, z, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab = []
ab.extend([i+j for j in b[:k] for i in a[:k]])
ab.sort(reverse=True)

abc = []
abc.extend([i+j for j in ab[:k] for i in c[:k]])
abc.sort(reverse=True)

print('\n'.join(str(i) for i in abc[:k]))


Measured memory_bytes: 236280
import java.util.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main{
	static FastScanner fs=new FastScanner();
	static PrintWriter pw=new PrintWriter(System.out);
	static void Solve(long the){
		int l=fs.nextInt();
		int r=fs.nextInt();
		int d=fs.nextInt();
		int ans=0;
		for(int i=1;i<200;i++){
			if(d*i>=l && d*i<=r)	ans++;
		}
		pw.print(ans);

		
	}
	public static void main(String args[]){
		long t=1;
		// t=fs.nextInt();
		for(long i=1;i<=t;i++){
			Solve(i);
		}
		pw.close();
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next(){
			while((!st.hasMoreTokens()) || (st==null)){
				try{
					st=new StringTokenizer(br.readLine());
				}
				catch(IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		int[] readArray(int n){
			int[] a=new int[n];
			for(int i=0;i<n;i++)	a[i]=nextInt();
			return a;
		}
		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: 32968
r,g,b,n=io.read("*n","*n","*n","*n")

counter=0
for i=0,3000 do
    for j=0,3000 do
        rg=r*i+g*j
        if n>=rg and (n-rg)%b==0 then
            counter=counter+1
        end
    end
end
print(counter)

Measured memory_bytes: 256
import itertools
import math

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

t = 0
c = 0
for v in itertools.permutations(xy, n):
    c+=1
    for i in range(n - 1):
        t+=math.sqrt((v[i][0] - v[i+1][0]) ** 2 + (v[i][1] - v[i+1][1]) ** 2)
        # print(v, t)
print(t/c)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

int n, k;
vi a;

bool core(int key) {
	if (a[key] >= k) return true;
	vector<bool> dp(k, false), dp2(k, false);
	dp[0] = true;
	Loop(i, n) {
		Loop(j, k) {
			if (dp[j]) {
				dp2[j] = true;
				if (i != key && j + a[i] < k) {
					dp2[j + a[i]] = true;
				}
			}
		}
		dp = dp2;
	}
	for (int j = k - a[key];j < k;++j) {
		if (dp[j]) return true;
	}
	return false;
}

int binary_search(int left, int right) {
	if (left + 1 >= right) return left;
	int mid = (left + right) / 2;
	int judge = core(mid);
	if (judge) return binary_search(left, mid);
	else return binary_search(mid, right);
}

int main() {
	cin >> n >> k;
	a.resize(n);
	Loop(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	//[left, right)は、不必要なもののうち最大のものを含む
	bool judge; //必要ならtrue
	int k = binary_search(0, n);
	int ans;
	if (k == 0) {
		if (core(0)) ans = 0;
		else ans = 1;
	}
	else {
		ans = k + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}
inline int inv(int a) {
  a %= md;
  if(a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= a * t; swap(a, b);
    u -= v * t; swap(u, v);
  }
  assert(b == 1);
  if(u < 0) u += md;
  return u;
}
int main() {
  int n, X;
  cin >> n >> X;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  vector<int> dp(X + 1, 0);
  dp[X] = 1;
  for (int i = 0; i < n; i++) {
    for (int x = 0; x <= X; x++) {
      int d = dp[x];
      dp[x] = 0;
      add(dp[x % s[i]], mul(d, inv(n - i)));
      add(dp[x], mul(d, mul(n - i - 1, inv(n - i))));
    }
  }
  int ret = 0;
  for (int x = 0; x <= X; x++) {
    add(ret, mul(x, dp[x]));
  }
  for (int i = 1; i <= n; i++) {
    ret = mul(ret, i);
  }
  cout << ret << '\n';
  return 0;
}

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

int main(){
    char b;
    cin >> b;
    if(b == 'A') cout << "T ";
    else if(b == 'C') cout << "G ";
    else if(b == 'G') cout << "C ";
    else cout << "A ";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main()
{
	long long N;
	std::cin >> N;

	std::vector<long long> v;

	while ( N != 0 )	//	ピッタリ0になるまでループ
	{
		long long p = 0;
		long long tmp = 0;
		long long sum = 0;

		if ( N > 0 )
		{
			// -2^pを計算する（正の数側）
			while ( N > sum )
			{
				tmp = pow( -2, p );
				sum += tmp;	//	足し合わせていく
				p += 2;		//	正の数だけ考えるので、2ずつ
			}
			v.emplace_back( p - 2 );	//	1回余分に回ってるので調整
			N -= tmp;
		}
		else
		{
			// -2^pを計算する（負の数側）
			p = 1;
			while ( N < sum )
			{
				tmp = pow( -2, p );
				sum += tmp;
				p += 2;
			}
			v.emplace_back( p - 2 );
			N -= tmp;	//	sumは負の値なので、減算でOK
		}
	}

	// 見つけた-2^pのpの値を昇順に探す
	std::vector<int> v_res;
	long long findCounter = 0;
	for ( int i = 0; findCounter < v.size(); i++ )
	{
		auto result = std::find( v.begin(), v.end(), i );
		v_res.emplace_back( result != v.end() ? findCounter++, 1 : 0 );
	}
 
	// 下位ビットから格納したので、逆順に出力する
	if ( 0 == findCounter )
	{
		std::cout << "0";	//	0は特別対応
	}
	for ( auto it = v_res.rbegin(); it != v_res.rend(); it++ )
	{
		std::cout << ( *it );
	}
	std::cout << std::endl;

	return ( 0 );
}


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

int main () {
  
  int N, W; 
  cin >> N >> W;
  
  vector<int> w(N);
  vector<long long> v(N);
  for (int i = 0; i < N; i++) cin >> w[i] >> v[i];
  
  vector<vector<long long>> dp(N, vector<long long>(W + 1));
  
  for (int j = 0; j <= W; j++) {
    if (j < w[0]) dp[0][j] = 0;
    else dp[0][j] = v[0];
  }
  
  for (int i = 1; i <= N - 1; i++) {
    for (int j = 0; j <= W; j++) {
      if (w[i] > j) dp[i][j] = dp[i - 1][j];
      else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
    }
  }
  
  cout << dp[N - 1][W] << endl;
  
}

Measured memory_bytes: 79488
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int dp[1001][10001];

const int INF=1e9;

void chmin(int &a,int b){
  if(a>b) a=b;
}

int main(){
  int H,N;
  cin>>H>>N;
  vector<int> A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];

  for(int i=0;i<=N;i++) for(int j=0;j<=H;j++) dp[i][j]=INF;
  dp[0][H]=0;
  for(int i=0;i<N;i++){
    for(int j=H;j>=0;j--){
      //chmin(dp[i+1][max(0,j-A[i])],dp[i][j]+B[i]);
      chmin(dp[i+1][j],dp[i][j]);
    }
    for(int j=H;j>=0;j--){
      chmin(dp[i+1][max(0,j-A[i])],dp[i+1][j]+B[i]);
    }
  }

  cout<<dp[N][0]<<endl;

  return 0;
}


Measured memory_bytes: 39296