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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl;
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    int n;
    cin >> n;
    vi a(n), x(n);
    ll sum = 0, ps = 0;
    REP(i, n) {
        cin >> a[i];
        sum += a[i];
        if(i % 2 == 1) ps += a[i];
    }
    sum /= 2;
    x[0] = sum - ps;
    FOR(i, 1, n) {
        x[i] = a[i - 1] - x[i - 1];
        cout << 2 * x[i - 1] << " ";
    }
    cout << 2 * x[n - 1] << "\n";

    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 200100

string A;
// A2 の位置 i から右のアルファベット j がある位置
// ない場合は -1
int next_pos[MAX_N][26];
int dp[MAX_N] = {};  // i 番目の文字以降でできる文字列の部分文字列でないもので、最短のもの

signed main()
{
    cin >> A;
    A = 'x' + A;   // てきとうな文字

    // next_pos の作成
    int tail = A.size()-1;
    int find_alph = A[tail] - 'a';
    REP(i, 26) {
        next_pos[tail][i] = -1;
    }
    for(int i = A.size()-2; i >= 0; --i) {
        REP(j, 26) { next_pos[i][j] = next_pos[i+1][j]; }
        next_pos[i][find_alph] = i+1;
        find_alph = A[i] - 'a';
    }

    // dp の作成
    dp[A.size()-1] = 1;
    for(int i = A.size()-2; i >= 0; --i) {
        dp[i] = INF;
        for(int j = 0; j < 26; ++j) {
            int next_ind = next_pos[i][j];
            if(next_ind < 0) {
                dp[i] = 1;
                break;
            } else {
                dp[i] = min(dp[i], dp[next_ind] + 1);
            }
        }
    }

    string ans = "";

    // 前方から貪欲にたどっていく
    {
        int i = 0;
        while(i < A.size()) {
            vector<char> cand;  // 最短の文字列の i 文字目の候補
            REP(j, 26) {
                int next_ind = next_pos[i][j];
                if(next_ind < 0) {
                    assert(dp[i] == 1);
                    cand.push_back(static_cast<char>(j + 'a'));
                } else {
                    if(dp[next_ind] == dp[i] - 1) {
                        cand.push_back(static_cast<char>(j + 'a'));
                    }
                }
            }
            // 候補の中で辞書順最小を採用
            SORT(cand);
            assert(cand.size() > 0);
            ans += cand[0];
            {
                int next_ind = next_pos[i][cand[0] - 'a'];
                if(next_ind < 0) { break; }
                i = next_ind;
            }
        }
    }
    printf("%s\n", ans.c_str());

    return 0;
}


Measured memory_bytes: 42816
//package AtCoder.Panasonic2020;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        long a = in.NL(), b = in.NL(), c = in.NL();
        if (c-a-b<=0) {
            out.println("No");
        } else {
            if (4*a*b < (c-a-b)*(c-a-b)) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }
        out.close();
    }

    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);

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

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

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

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

        public long NL() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 23252
<?php
fscanf(STDIN, '%d', $n);
$in = explode(' ', fgets(STDIN));
foreach($in as $v) {
    if($v % 2 == 0) {
        if($v % 3 != 0 && $v % 5 != 0) {
            echo 'DENIED', PHP_EOL;
            exit;
        }
    }
}
echo 'APPROVED', PHP_EOL;

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

int main()
{
  
  ll n,i;
  ll ans=0;
  cin>>n;
  ll arr[n+1];
  for(i=1; i<=n; i++)
  {
    cin>>arr[i];
    if(i%2!=0 && arr[i]%2!=0)
      ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef __int128_t i128;
typedef long long i64;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
#define Sz(a) ((int)(a).size())
const int maxn = 200009;
const int MOD = 1e9 + 7;
int a[maxn];
int main(){
  FPEN;
  ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
  int n;cin>>n;
  i64 tot=0,ans=0,cur=1;
  for(int i=0;i<=n;++i)cin>>a[i],tot+=a[i];
  for(int i=0;i<=n;++i){
    if(cur<a[i]){
      cout<<-1<<'\n';return 0;
    }
    ans+=cur;
    cur-=a[i];
    tot-=a[i];
    if(cur*2<=tot)cur*=2;
    else cur=tot;
  }
  cout<<ans<<'\n';
  return 0;
}
//2020.05.30 20:15:09


Measured memory_bytes: 4044
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int R = sc.nextInt();
			
			if(R < 1200) {
				System.out.println("ABC");
			}else if(R < 2800) {
				System.out.println("ARC");
			}else {
				System.out.println("AGC");
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21332
n=int(input(""))
k=1
# li=list(map(int,input("").split(" ")))
li=input().split(" ")
if '0' in li:
    print("0")
else:
    for i in li:
        k*=int(i)
        if k>1000000000000000000:
            print("-1")
            break
    else:
        print(k)


Measured memory_bytes: 19416
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
typedef long long llong;

static const int MAX = 101;
main(){
  int n; 
  llong T[MAX], dp[21][MAX];
  cin >> n;

  rep(i, n) cin >> T[i];
  rep(i, 21) rep(j, n) dp[i][j] = 0;

  if ( 0 <= T[0] && T[0] <= 20 ) dp[T[0]][0] = 1;

  int p1, p2;
  for ( int j = 1; j < n-1; j++ ){
    for ( int i = 0; i <= 20; i++ ){      
      p1 = i + T[j];
      if ( p1 <= 20 ) dp[p1][j] += dp[i][j-1];
      p2 = i - T[j];
      if ( p2 >= 0 ) dp[p2][j] += dp[i][j-1];
    }
  }
  cout << dp[T[n-1]][n-2] << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
const ll inf = 1e18;
const int nax = 2e6 + 7;

using namespace std;
string s;
int fl1 , fl2;
int main(int argc,char ** argv){
	dhoom;
	cin >> s;
	if(s[0] == 'A' || s[1] == 'A' || s[2] == 'A')
		fl1 = 1;
	if(s[0] == 'B' || s[1] == 'B' || s[2] == 'B')
		fl2 = 1;
	if(fl1 && fl2)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   int x[100];
   rep(i,100){
      x[i]=0;
   }

   for(int i=a;i<b;i++){
      x[i]++;
   }   
   for(int i=c;i<d;i++){
      x[i]++;
   }
   int count=0;
   rep(i,100){
      if(x[i]==2) count++;
   }
   cout<<count;
   return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int INF=123456789;

int n;
string a[10],b[10];
string s,g;

map<string,int> dp;
int dfs(string now)
{
    if(now.size()>g.size()) return INF;
    if(now.size()==g.size())
    {
        if(now==g) return 0;
        else return INF;
    }

    if(dp.find(now)!=dp.end()) return dp[now];

    int ret=INF;

    int N=now.size();
    rep(i,n)
    {
        int A=a[i].size();

        string nx="";
        int idx=0;
        while(idx<N)
        {
            if(idx+A<=N && now.substr(idx,A)==a[i])
            {
                nx+=b[i];
                idx+=A;
            }
            else nx+=now[idx++];
        }

        if(now==nx) continue;
        // cout <<"now= "<<now<<" ,nx= "<<nx<<endl;
        ret=min(ret,dfs(nx)+1);
    }

    return dp[now]=ret;
}

int main()
{
    while(cin >>n,n)
    {
        rep(i,n) cin >>a[i] >>b[i];
        cin >>s >>g;

        dp.clear();

        int ans=dfs(s);
        if(ans==INF) ans=-1;
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  int h, w, k;
  string s[11];
  cin >> h >> w >> k;
  for(int i=0;i<h;i++)cin >> s[i];
  int top=0;
  int mn=100000;
  for(int i=0;i<(1<<h);i+=2){
    int cnt=0;
    int have[10];
    bool ok=true;
    memset(have, 0, sizeof(have));
    for(int l=0;l<h;){
      int top=l;
      while(l<h&&((i>>top)&1)^((i>>l)&1)==0)l++;
      if(l!=h)cnt++;
    }
    for(int j=0;j<w;j++){
      int add[10];
      memset(add, 0, sizeof(add));
      for(int l=0;l<h;){
        int a=0, top=l;
        while(l<h&&((i>>top)&1)^((i>>l)&1)==0){
          if(s[l][j]=='1')a++;
          l++;
        }
        if(a>k){
          ok=false;
          break;
        }
        add[top]=a;
      }
      if(!ok)break;
      for(int l=0;l<h;l++){
        if(have[l]+add[l]>k){
          cnt++;
          for(int r=0;r<h;r++){
            have[r]=add[r];
          }
          break;
        }
        else{
          have[l]+=add[l];
        }
      }
    }
    if(!ok)continue;
    if(mn > cnt){
      mn = cnt;
    }
  }
  cout << mn << endl;
}


Measured memory_bytes: 3656
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
    ($line:expr,$name:ident,$t:tt) => {
        let $name=value!($line,$t);
    };
    }

    macro_rules! values_def {
    ($lines:expr,$n:expr,$name:ident,$t:tt) => {
        let $name={
        let mut vec=Vec::new();
        for i in 0..$n{
            let mut next=$lines.next().unwrap().split_whitespace();
            vec.push(value!(next,$t));
        }
        vec
        };
    };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(a:i64 b:i64 c:i64 x:i64 y:i64));
    if a + b < 2 * c {
        //ABのほうが高い
        a * x + b * y
    } else {
        //Aが多い
        if x > y {
            if a < 2 * c {
                (y * c) * 2 + (x - y) * a
            } else {
                2 * x * c
            }
        } else {
            if b < 2 * c {
                (x * c) * 2 + (y - x) * b
            } else {
                2 * y * c
            }
        }
    }.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "1500 2000 1600 3 2" => "7900",
    test2: "1500 2000 1900 3 2" => "8500",
    test3: "1500 2000 500 90000 100000" => "100000000",
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
//const int INF = 1 << 30;//10^9
const ll INF = INFL;
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

//デバッグ
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll get_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

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

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

//素因数列挙
vector<ll> MakePrimeList(ll x) {
    vector<ll> res;
    for(ll k=2; k*k<=x; k++) {
        if(x % k == 0) {
            res.pb(k);
            while(x % k == 0) x /= k;
        }
    }
    if(x > 1) res.push_back(x);
    return res;
}


//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

int main(){
  string S;
  cin >> S;
  cout << S.substr(0, S.size() - 8) << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int sum = 0;
  
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  
  int ans = sum;
  int v = 0;
  for (int i = 0; i < N-1; i++) {
    cin >> a[i];
    v += a[i];
    ans = min(ans, abs(v - (sum - v)));
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 200000
#define MAX_A 200000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, A[MAX_N];
llong K;

int next_pos[MAX_N];    //A[j] = A[i]となる最小のj > i
vector<int> numpos[MAX_A + 1];

int get_period() {
    int cur = 0;
    int k = 0;
    for(;;) {
        int next = (next_pos[cur] + 1) % N;

        if(next_pos[cur] <= cur) k++;
        cur = next_pos[cur];
        if(next <= cur) k++;
        cur = next;
        if(next == 0) return k;
    }
}

int get_pos(int K) {
    if(K == 0) return N;
    int cur = 0;
    int k = 0;
    for(;;) {
        int next = (next_pos[cur] + 1) % N;
        if(next_pos[cur] <= cur || next <= cur) {
            k++;
            if(k == K) {
                return cur;
            }
        }
        cur = next;
    }
}

int res[MAX_N];
int simulate(int cur) {
    int pos = cur;
    for(int i = cur; i < N; ++i) {
        if(next_pos[i] > i)
            i = next_pos[i];
        else
            res[pos++] = A[i];
    }
    return pos;
}

int main(int argc, char **argv) {
    cin >> N >> K;
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
        numpos[A[i]].push_back(i);
    }

    for(int i = 1; i <= MAX_A; ++i)
        for(int j = 0; j < numpos[i].size(); ++j)
            next_pos[numpos[i][j]] = numpos[i][(j + 1) % numpos[i].size()];

    int period = get_period();
    K %= period;
    int cur = get_pos(K);
    int bound = simulate(cur);

    for(int i = cur; i < bound; ++i) {
        if(i != cur) cout << " ";
        cout << res[i];
    }
    cout << endl;

}

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

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

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int g[] = {-1, 1, 3, 1, 2, 1, 2, 1, 1, 2,1,2,1};
  int x, y;
  cin >> x >> y;

  cout << (g[x]==g[y] ? "Yes" : "No") << endl;

}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
A=tuple(map(int,input().split()))
B=tuple(map(int,input().split()))

def exchange(n,A,B):
    R=[]
    for a,b in zip(A,B):
        if a<b:
            R.append((a,b))
    if len(R)==0:
        return n
    if len(R)==1:
        a,b=R[0]
        return n+n//a*(b-a)
    if len(R)==2:
        a0,b0=R[0]; a1,b1=R[1]
        ans=n
        s=n//a0
        for i in range(s+1):
            p=b0*i
            q=n-a0*i
            r=q//a1
            ans=max(ans,p+q+r*(b1-a1))
        return ans
    a0,b0=R[0]; a1,b1=R[1]; a2,b2=R[2]
    ans=n
    s=n//a0
    for i in range(s+1):
        p=n-a0*i
        t=p//a1
        for j in range(t+1):
            q=p-a1*j
            ans=max(ans,b0*i+b1*j+q+q//a2*(b2-a2))
    return ans

tmp=exchange(n,A,B)
print(exchange(tmp,B,A))

Measured memory_bytes: 39664
from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))

def lcm(a, b):
    return a*b // gcd(a, b)
"""
akが偶数だから、bk=2akとして、
bk × (2p + 1)を満たすpが存在すれば良い
2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない
akに含まれる最大の2^kを探す。
"""
if len(a) == 1: lcm_all = a[0]//2
else: lcm_all = lcm(a[0]//2, a[1]//2)
amax = 0
for i in range(1, n):
    lcm_all = lcm(lcm_all, a[i]//2)
    amax = max(amax, a[i]//2)

f = True
if lcm_all > m:
    f = False
for i in range(n):
    if n == 1: break
    if (lcm_all//(a[i]//2))%2 == 0:
        # akの2の約数の数がそろわないので、どんな奇数を掛けても共通のXを作れない
        f = False
if f:
    # amaxの奇数倍でmを超えないもの
    ans = (m // lcm_all + 1)//2
    print(ans)
else:
    print(0)

Measured memory_bytes: 16320
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
  int a,b,t;
  cin >> a >> b>> t;
  cout << t/a*b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
const double pi = 3.1415926535;
int main(){
	
	int a,b,h,m; cin>>a>>b>>h>>m;
	h *= 5;
	double h0 = h + 5.0*m/60;
	cout << fixed << setprecision(10);
	double c = abs(h0-m);
	//if(c>30) c = 60 - c;  
	cout << sqrt(a*a+b*b-2*a*b*cos(c*6/180*pi)) << endl;
	
}



Measured memory_bytes: 4144
#
# abcxxx a
#
import unittest
from io import StringIO
import sys


def input():
    return sys.stdin.readline().rstrip()


def resolve():
    a, b = map(int, input().split())
    print(-(-(a+b) // 2))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1 3"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7 4"""
        output = """6"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5 5"""
        output = """5"""
        self.assertIO(input, output)


if __name__ == "__main__":
    #unittest.main()
    resolve()


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int 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);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;


void print_v(vector<int> &v) {
    for (int i : v) cout << i;
    cout << ' ';
}


vector<int> sub(vector<int> &v) {
    if(v.size() == 1) return v;
    vector<int> v2(v.size() - 1);
    rep(i, v.size() - 1) {
        v2[i] = abs(v[i] - v[i + 1]);
    }
    return v2;
}

int check2(vector<int> v) {
    while (v.size() != 1) {
        if (v.size() % 2 == 0) {
            vector<int> next;
            for (int i = 0; i < v.size(); i += 2) {
                int a = abs(v[i] - v[i + 1]);
                next.push_back(a);
            }
            v = next;
        } else {
            v = sub(v);
        }
    }
    return v.front();
}


bool is_end(vector<int> &v) {
    for (int i : v) if (i != 3) return false;
    return true;
}


void digit(vector<int> &v) {
    for (int i = 0; i < v.size(); i++) {
        if (v[i] == 4) {
            v[i] = 1;
            v[i + 1]++;
        }
    }
}

int check(vector<int> v) {

    while (v.size() != 1) {
        vector<int> next;
        for (int i = 1; i < v.size(); i++) {
            int a = abs(v[i - 1] - v[i]);
            next.push_back(a);
        }
        v = next;
    }
    return v.front();
}


int main() {


    int n;
    cin >> n;
    vector<int> digits(n);
    rep(i, n) {
        char c;
        cin >> c;
        int a = c - '0';
        digits[i] = a;
    }

    vector<int> digits2 = sub(digits);
    digits2 = sub(digits2);
    digits2 = sub(digits2);
    digits2 = sub(digits2);
    cout << check2(digits2) << endl;


}





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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (auto i = 0; i < n; i++)cin >> x.at(i);

    long long ans = 1 << 18;
    
    for (auto i = 1; i <= 100; i++) {
        auto tmp = 0;
        for (auto j = 0; j < n; j++) {

            tmp += pow((x.at(j) - i), 2);
        }

        ans = min(ans, (long long)tmp);
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static int color[];
	static List<Integer>[] g;
	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), m = in.nextInt();
			g = new ArrayList[n];
			g = Stream.generate(ArrayList::new).limit(n).toArray(List[]::new);

			for (int i = 0; i < m; i++) {
				int a = in.nextInt()-1, b = in.nextInt()-1;
				g[a].add(b);
				g[b].add(a);
			}

			color = new int[n];

			boolean isBipartite = true;
			for (int i = 0; i < n; i++) {
				if (color[i] == 0) {
					if(!isBipartite(i, 1)) {
						isBipartite = false;
					}
				}
			}

			long ans = 0;

			if (isBipartite) {
				long a = 0, b = 0;
				for (int i = 0; i < n; i++) {
					if(color[i] == 1) {
						a++;
					} else {
						b++;
					}
				}
				ans = a * b - m;
			} else {
				ans = (long)n*(n-1)/2 - m;
			}

			out.println(ans);
		}

		static boolean isBipartite(int v, int c) {
			color[v] = c;
			for (int t : g[v]) {
				if (color[t] == c) {
					return false;
				}
				if (color[t] == 0 && !isBipartite(t, -c)) {
					return false;
				}
			}
			return true;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

using namespace std;

typedef long long ll;

vector<vector<ll>> graph;
vector<ll> U;
vector<ll> V;

void dfsU(ll v,ll t){
    U[v] = t, t++;
    for(auto next : graph[v]){
        if(U[next] != -1)
            continue;
        dfsU(next, t);
    }
}

void dfsV(ll v, ll t)
{
    V[v] = t, t++;
    for (auto next : graph[v])
    {
        if (V[next] != -1)
            continue;
        dfsV(next, t);
    }
}

int main(){
    ll N, u, v;
    cin >> N >> u >> v;
    u--, v--;
    graph.resize(N);
    U.resize(N,-1);
    V.resize(N,-1);

    if(N < 2){
        cout << 0 << endl;
        return 0;
    }

    for (int i = 1; i < N;i++){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    dfsU(u, 0);
    dfsV(v, 0);

    ll ans = 0;
    for (int i = 0; i < N;i++){
        if(ans < V[i] && U[i] < V[i]){
            ans = V[i];
        }
    }

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

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

int main() {
	string S, T;
	cin >> S >> T;
	vector<string> a(26), b(26);
	for (int i = 0; i < S.size() && i < T.size(); i++) {
		a[S[i] - 'a'] += T[i];
		b[T[i] - 'a'] += S[i];
	}
	bool ans = true;
	for (int i = 0; i < 26; i++) {
		if (!a[i].empty()) {
			a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end());
			if (a[i].size() != 1) {
				ans = false;
				break;
			}
		}
		if (!b[i].empty()) {
			b[i].erase(unique(b[i].begin(), b[i].end()), b[i].end());
			if (b[i].size() != 1) {
				ans = false;
				break;
			}
		}
	}
	if (ans) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 1288
#include <iostream>

using namespace std;
int sol;
char s[4], x;

int main()
{
    for(int i =0;i<3;i++){
        cin >> x;
        s[i] = x;
    }
    for(int i = 0;i<3;i++){
        cin >> x;
        if(x==s[i]){
            sol++;
        }
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  vector<int> cnt(N, 0);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    A[i]--;
    cnt[A[i]]++;
  }
  sort(cnt.begin(), cnt.end());
  reverse(cnt.begin(), cnt.end());
  int ans = 0;
  for (int i = K; i < N; i++){
    ans += cnt[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    multiset<int> ms, check;
    for (int i = 0; i < (1 << n); ++ i) {
        int a;
        cin >> a;
        ms.insert(a);
        check.insert(a);
    }
    multiset<int> make;
    make.insert(*(-- ms.end()));
    ms.erase(-- ms.end());
    while (make.size() != (1 << n)) {
        vector<int> tmp;
        for (auto it = make.rbegin(); it != make.rend(); ++ it) {
            auto x = ms.lower_bound(*it);
            if (x == ms.begin()) {
                cout << "No";
                return 0;
            }
            x --;
            tmp.emplace_back(*x);
            ms.erase(x);
        }
        for (auto& x : tmp) make.insert(x);
    }
    if (check == make) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 25592
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline, 3);

preorder = line[1].split(' ');
inorder = line[2].split(' ');

tree = {};

function decode(preorder, inorder) {
  var id, idx_in, in_left, in_right, pre_left, pre_right, left, right;
  id = preorder[0];
  idx_in = inorder.indexOf(id);
  in_left = inorder.slice(0, idx_in + 1);
  in_right = inorder.slice(idx_in + 1);
  pre_left = preorder.slice(1, idx_in + 1);
  pre_right = preorder.slice(idx_in + 1);
  if (pre_left.length === 0) left = null;
  else left = decode(pre_left, in_left);
  if (pre_right.length === 0) right = null;
  else right = decode(pre_right, in_right);
  tree[id] = {'left': left, 'right': right};
  return id;
}

decode(preorder, inorder);
root_id = preorder[0];

function postorder(id) {
  var node = tree[id], res = [];
  if (node.left !== null) res = res.concat(postorder(node.left));
  if (node.right !== null) res = res.concat(postorder(node.right));
  res.push(id);
  return res;
}

console.log(postorder(root_id).join(' '));

Measured memory_bytes: 15604
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100205;
const int mod = 1000000007;

bool f[maxn];
int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  f[0] = 1;
  for(int i=0;i<n;i++){
    if(!f[i])continue;
    for(int j=100;j<106;j++)f[j+i]=1;
  }
  cout<<f[n]<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N, Y;
    cin >> N >> Y;
    int a1 = -1, a2 = -1, a3 = -1;
    for (int i = 0; i <= N; ++i) 
    {  
        for (int j = 0; j + i <= N; ++j)
        {  
            int k = N - i - j;  
            if (Y == 10000 * i + 5000 * j + 1000 * k) 
            {  
                a1 = i;
                a2 = j;
                a3 = k;
            }
        }
    }

    cout << a1 << " " << a2 << " " << a3 << endl;
}

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

 int main(){
  	ios::sync_with_stdio(false);
    	cin.tie(0);  
	int A,B,C,X,Y;
	cin>>A>>B>>C>>X>>Y; 
        int ta=A; 
	int tb=B; 
	int tx=X; 
	int ty=Y; 
	if(X>Y){
		B=ta; 
		A=tb; 
		X=ty; 
		Y=tx; 
	}	
	if ((2*C)>(A+B)){
		cout<<A*X+B*Y; 
	}
	else if(2*C>B){ 
	       cout<<B*Y+(2*C-B)*X; 
	}else{ 
 		cout<<2*C*Y; 
	} 		

    
    return 0; 
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn xor_next_1000000(x: u64) -> u64 {
    if (x & 1) == 0 {
        x + 1000000
    } else {
        x
    }
}
fn solve(a: u64, b: u64) -> u64 {
    let mut ans = a;
    let mut curr = a + 1;
    while curr < b {
        if b - curr < 1000000 {
            ans ^= curr;
            curr += 1;
        } else {
            ans = xor_next_1000000(ans);
            curr += 1000000;
        }
    }
    ans
}
fn main() {
    input! {
        a: u64,
        b: u64,
    }
    println!("{}", solve(a, b + 1));
}

fn naive(a: u64, b: u64) -> u64 {
    let mut ans = 0;
    for i in a..b {
        ans ^= i;
    }
    ans
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    int A, B, cnt = 0;
    string s, r;
    cin >> A >> B;
    for (int i = A; i <= B; i++) {
        s = r = to_string(i);
        reverse(r.begin(), r.end());
        if (s == r) cnt++;
    }
    cout << cnt << endl;
}

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

int main(int argc, char const* argv[])
{
    string s0 = "CODEFESTIVAL2016";
    string s;

    cin >> s;

    int ans = 0;
    for (int i = 0; i < s0.length(); i++) {
        s0[i] == s[i] ? ans : ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, A, B, h[100000];

int search(void){
	int Min = -1, Max = 1000000000;
	while(Max > Min+1){
		ll m = (Min + Max)/2, flag = 0, cnt = 0;
		for(int i=0; i<N; i++){
			ll t = (h[i] - m*B + A - B - 1)/(A-B);
		    t = (t>0?t:0);
            cnt += t;
        }
		if(cnt <= m) Max = m;
		else Min = m;
	}
	return Max;
}

int main(){
	cin >> N >> A >> B;
	for(int i=0; i<N; i++) cin >> h[i];
	int ans = search();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
N = int(input())

S = []
cnt = 0
c = {}

for i in range(N):
    s = "".join(sorted(list(input())))
    if s not in c.keys():
        c[s] = 1
    else:
        c[s] += 1
        cnt += c[s]-1
        
    S.append(s)

print(cnt)

Measured memory_bytes: 18488
import heapq

n, m = map(int, input().split())
x = [[] for _ in range(m + 1)]
y = []
heapq.heapify(y)
for i in range(1, m + 1):
    heapq.heapify(x[i])
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        heapq.heappush(x[a], -b)
ans = 0
for i in range(1, m + 1):
    if x[i]:
        s = heapq.heappop(x[i])
        heapq.heappush(y, [s, i])
    if y:
        s, t = heapq.heappop(y)
        ans -= s
        if x[t]:
            s = heapq.heappop(x[t])
            heapq.heappush(y, [s, t])
print(ans)

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

    return 0;
}


Measured memory_bytes: 3624
from collections import defaultdict, deque
n,m = map(int,input().split())
es = [[int(x) for x in input().split()] for _ in range(n+m-1)]
ins = defaultdict(int)
outs = defaultdict(list)
for v1,v2 in es:
    outs[v1].append(v2)
    ins[v2] += 1
que = deque(v1 for v1 in range(n) if ins[v1]==0)
res = []
par = [0]*(n+1)
while que:
    v1 = que.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2]==0:
            que.append(v2)
            par[v2] = v1
for p in par[1:]:
  print(p)

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

class C {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[] A = new int[N];
        Arrays.setAll(A, i -> sc.nextInt());
        final int[] B = new int[N];
        Arrays.setAll(B, i -> sc.nextInt());
        for (int i = 0; i < N; i++)
            A[i] -= B[i];
        Arrays.sort(A);
        long minus = 0;
        int ans = 0;
        for (int i = 0; i < N && A[i] < 0; i++, ans++)
            minus += A[i];
        for (int i = N - 1; i >= 0 && A[i] > 0 && minus < 0; i--, ans++)
            minus += A[i];
        System.out.println(minus < 0 ? -1 : ans);
    }
}
public class Main {
    public static void main(String... args) {
        C.main();
    }
}


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

int check[10][2000];
int sum[10][2000] = {0};
int num[10];

int search(int a, int b) {

	if(a == 0) return 0;
	if(b == 0) return sum[b][a];
	if(check[b][a] != -1) return check[b][a]; 
	
	int ret = 0;
	for(int i = min(a, num[b]); i >= 0; i--) {
		ret = max(ret, search(a-i, b-1) + sum[b][i] );
	}

	check[b][a] = ret;
	return ret;
	
}


int main() {

	int N, K;
	int genre, price;
	
	vector< vector<int> > C;
	C.resize(10);
	
	
	cin >> N >> K;
	
	for(int i = 0; i < N; i++) {
		cin >> price >> genre;
		C[genre-1].push_back(price);
	}
	
	for(int i = 0; i < 10; i++) {
		sort(C[i].begin(), C[i].end(), greater<int>() );
		num[i] = C[i].size();
	}
	
	for(int i = 0; i < 10; i++) {
		for(int j = 1; j <= num[i]; j++) {
			sum[i][j] = sum[i][j-1] + C[i][j-1] + (2 * (j-1));
		}
	}
	
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 2000; j++) {
			check[i][j] = -1;
		}
	}
	
	cout << search(K, 9) << endl;

	return 0;

}

Measured memory_bytes: 1356
H, W = list(map(int, input().split()))
S = [input() for i in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            count = 0
            for y in range(-1, 2):
                for x in range(-1, 2):
                     if 0 <= h+y and h+y < H and 0 <= w+x and w+x < W:
                         if S[h+y][w+x] == '#':
                             count += 1
        else:
            count = '#'
        print(count, end='')
    print()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  bool z = true;
  char x = a[0];
  a.erase(0, 1);
  while (z){
    if(x=='a'){
      if(sz(a)==0){
      print('A');
      break;
    }
      x = a[0];
      a.erase(0, 1);
    }
    else if(x=='b'){
      if(sz(b)==0){
      print('B');
      break;
    }
      x = b[0];
      b.erase(0, 1);
    }
    else if(x=='c'){
      if(sz(c)==0){
      print('C');
      break;
    }
      x = c[0];
      c.erase(0, 1);
    }
  }
}

Measured memory_bytes: 256