akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define double long double

using namespace std;

int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

map<int, int>mp;
set<int>st;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	REP(i, N) {
		int x; cin >> x;
		st.insert(x);
		mp[x]++;
	}
	if (st.size() == 1) {
		auto itr = st.begin();
		if (*itr == 0)print("Yes")else print("No");
	}
	else if(st.size() == 2) {
		auto itr = st.begin();
		if (*itr == 0) {
			int cnt = mp[0];
			for (auto x : mp) {
				if (x.first == 0)continue;
				if (x.second != cnt * 2) {
					print("No"); return 0;
				}
			}
			print("Yes");
		}
		else print("No");
	}
	else if (st.size() == 3) {
		int a[3];
		int c = 0;
		for(auto x:st){
			a[c] = x;
			c++;
		}
		bool ok = false;
		if ((a[0] ^ a[2]) == a[1] && (a[1] ^ a[2]) == a[0]) {
			ok = true;
		}
		if (!ok) {
			print("No"); return 0;
		}
		auto itr = st.begin();
		int cnt = mp[*itr];
		for (auto x : mp) {
			if (x.second != cnt) {
				print("No"); return 0;
			}
		}
		print("Yes");
	}
	else {
		print("No");
	}
}


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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,m;
  cin >> n >> m;
  vector< set<int> > fr(n);
  
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;a--;b--;
    fr[a].insert(b);
    fr[b].insert(a);
  }
  
  queue<int> q;
  char flag[n] = {};  
  int maxCount = 0;
  for(int i=0;i<n;i++){
    if(0==flag[i]){
      int count = 0;
      q.push(i);
      flag[i] = 1;
      while(!q.empty()){
        int p = q.front();q.pop();
        count++;
        for(auto x:fr[p]){
          if(0==flag[x]){
            q.push(x);
            flag[x] = 1;
          }
        }
      }
      maxCount = max(maxCount, count);
    }
  }
  cout << maxCount << endl;
  return 0;
}



Measured memory_bytes: 31768
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n; // 1 <= n <= 2*10^5
    cin >> n;

    int res = 0;
    int tmp;
    int mn = 200001;
    REP(i, n) {
        cin >> tmp;
        if (tmp < mn) {
            mn = tmp;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t h,a;
    cin >> h >> a;
    cout << (h+a-1)/a << endl;
}


Measured memory_bytes: 256
require 'pp'
require 'set'

n = gets.chomp!
p_n = gets.chomp!.split(" ").map(&:to_i)

count = 0
p_n.each_cons(3) {|x|
    y = ([x[0], x[2]].min)..([x[0], x[2]].max)
    if y.include?(x[1])
        count += 1
    end
}

puts count


Measured memory_bytes: 2428
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    p = sorted(LI())
    ans = sum(p[:K])
    print(ans)


main()



Measured memory_bytes: 10872
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 0x7FFFFFFF

using namespace std;

int dp[100005][4];

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

Measured memory_bytes: 1792
def main():
    from collections import Counter as ct
    n, k, q = map(int, input().split())
    a = list(map(int, input().split()))
    c = ct(a).keys()
    a += [0]
    ans = []
    for i in c:
        temp = []
        temp2 = []
        for j in a:
            if j >= i:
                temp2.append(j)
            else:
                if temp2:
                    temp2.sort()
                    if len(temp2) >= k:
                        for l in temp2[:len(temp2)-k+1]:
                            temp.append(l)
                    temp2 = []
        if len(temp) >= q:
            temp.sort()
            ans.append(temp[q-1]-i)
    print(min(ans))


main()

Measured memory_bytes: 3752
#include <cstdio>
using namespace std;

typedef struct stick{
 int lren, rren, sl, sr, weight; 
} STICK;

int n, tmp, top;
int depth[101];
STICK st[101];

void init(int k){
 for(int i = 0; i <= k; i++){
  depth[i] = 0;
  st[i].weight = 0;
 }
}

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

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

int solve(int k){
 if(st[k].weight > 0) return st[k].weight;
 if(st[k].sl == 0 && st[k].sr == 0){
  return st[k].weight = st[k].lren + st[k].rren;
 }else if(st[k].sl == 0){
  return st[k].weight = solve(st[k].sr) * (st[k].lren + st[k].rren) / gcd(solve(st[k].sr), st[k].lren);
 }else if(st[k]. sr == 0){
  return st[k].weight = solve(st[k].sl) * (st[k].lren + st[k].rren) / gcd(solve(st[k].sl), st[k].rren);
 }else {
  tmp = lcm(solve(st[k].sl) * st[k].lren, solve(st[k].sr) * st[k].rren);
  return st[k].weight = tmp / st[k].lren + tmp / st[k].rren;
 }
}

int main(){
 while(scanf("%d", &n)){
  if(n == 0) break;
  init(n);
  for(int i = 1; i <= n; i++){
   scanf("%d %d %d %d", &st[i].lren, &st[i].rren, &st[i].sl, &st[i].sr);
   tmp = gcd(st[i].lren, st[i].rren);
   st[i].lren /= tmp;
   st[i].rren /= tmp;
  }
  for(int i = 1; i <= n; i++){
   depth[st[i].sl]++;
   depth[st[i].sr]++;
  }
  for(int i = 1; i<= n; i++){
   if(depth[i] == 0){
    top = i;
    break;
   }
  }
  printf("%d\n", solve(top));
 }
 return 0;
}

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

int main() {
	int h, w, k, ans = 0;
	cin >> h >> w >> k;
	char c[h][w];
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> c[i][j];
		}
	}
	for(int i = 0; i < (1 << h); i++) {
		for(int j = 0; j < (1 << w); j++) {
			int cnt = 0;
			for(int x = 0; x < h; x++) {
				for(int y = 0; y < w; y++) {
					if(((1 << x) & i) == 0 && ((1 << y) & j) == 0 && c[x][y] == '#') {
						cnt++;
					}
				}
			}
			if(cnt == k) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3600
#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 ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int L, R, d;
  cin >> L >> R >> d;
  int ans=0;
  FOR(i,L,R+1)if(i%d==0)ans++;
  PRINT(ans);
}



Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
  
  int n, time = 0;
  cin>>n;
  vector<string> s(n);
  vector<int> t(n);
  rep(i, n) {
    cin >> s.at(i) >> t.at(i);
    time += t.at(i);
  }
  string x;
  cin >> x;
  rep(i, n) {
    time -= t.at(i);
    if(s.at(i) == x) {
      break;
    }
  }
  cout << time << endl;
    
    return 0;
}

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

int main(){
  vector<int64_t> L(100);
  
  L.at(0) = 2;
  L.at(1) = 1;
  
  int N;
  cin >> N;
  
  for(int i = 2; i < N + 1; i++){
    L.at(i) = L.at(i-1) + L.at(i-2);
  }
  cout << L.at(N) << endl;
}


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

int check(string t) {
  for (auto &i : t) {
    if (i != t[0]) return 1;
  }
  return 0;
}

void MAIN() {
  string s;
  cin >> s;
  int ans = 2e9;
  for (char c = 'a'; c <= 'z'; c++) {
    string t = s;
    int cnt = 0;
    while (check(t)) {
      cnt++;
      for (int i = 0; i < t.size() - 1; i++) {
        if (t[i + 1] == c) t[i] = c;
      }
      t.pop_back();
    }
    ans = min(ans, cnt);
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3664
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n:usize,
    }
    let mut out = String::with_capacity(n * 2);
    let mut results = vec![0; n];
    for x in 1..=n {
        let x2 = x.pow(2);
        if x2 < n {
            for y in 1..=n {
                let y2 = y.pow(2);
                let xy = x2 + y2 + x * y;
                if xy < n {
                    for z in 1..=n {
                        let r = xy + z.pow(2) + x * z + y * z;
                        if r > n {
                            break;
                        }
                        results[r - 1] += 1;
                    }
                } else {
                    break;
                }
            }
        } else {
            break;
        }
    }
    for v in results.iter() {
        out.push_str(&format!("{}\n", v));
    }
    out
}

test! {
    "20" => include_str!("c1_out.txt"),
}


Measured memory_bytes: 2256
import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)
s=input()
t=input()
dp=[[0 for i in range(len(t)+1)] for j in range(len(s)+1)]
for i,sele in enumerate(s):
  for j ,tele in enumerate(t):
    if sele==tele:
      dp[i+1][j+1]=dp[i][j] +1
    else :
      dp[i+1][j+1]=dp[i+1][j] if dp[i+1][j]>=dp[i][j+1] else dp[i][j+1]     
res=""
i=len(s)
j=len(t)
#print(dp)
while True:
#for k in range(9):
  #rint(i,j,dp[i][j])
  if i-1>=0:
    if dp[i-1][j]==dp[i][j]:
      i=i-1
      continue
  if j-1>=0:
    if dp[i][j-1]==dp[i][j]:
      j=j-1
      continue
  if i-1>=0 and j-1>=0:
    if dp[i-1][j-1]==dp[i][j]-1:
      j=j-1
      i=i-1
      res=s[i]+res
      #print(i,res)
      if dp[i][j]==0:
        break
      continue
  break
print(res)
    

Measured memory_bytes: 119900
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
LL n, c;
vector<LL> x, rx, v;
vector<LL> ruiseki;
vector<LL> ruiseki1, ruiseki2;
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> c;
    x.resize(n);
    rx.resize(n);
    v.resize(n);
    REP(i, n) cin >> x[i] >> v[i];
    REP(i, n) rx[i] = c-x[i];
    reverse(all(rx));

    ruiseki.resize(n+1);
    ruiseki[0] = 0;
    REP(i, n){
        ruiseki[i+1] = ruiseki[i] + v[i];
    }
    
    vector<LL> ans1(n, 0);
    ans1[0] = max(0LL, ruiseki[1]-x[0]);
    FOR(i, 1, n){
        ans1[i] = max(ans1[i-1], ruiseki[i+1]-x[i]);
    }
    
    vector<LL> ans2(n, 0);
    ans2[n-1] = max(0LL, v[n-1] - rx[0]);
    FOR(i, 1, n){
        ans2[n-i-1] = max(ans2[n-i], ruiseki[n]-ruiseki[n-i-1] - rx[i]);
    }
    
    vector<LL> ans3(n, 0);
    REP(i, n-1){
        //cout << i << ": " << ans1[i] << " " << ans2[i+1] - x[i] << endl;
        ans3[i] = max(ans1[i], ans1[i] + ans2[i+1] - x[i]);
    }
    ans3[n-1] = ans1[n-1];

    vector<LL> ans4(n, 0);
    for(int i = n-1; i > 0; i--){
        //cout << i << ": " << ans2[i] << " " << ans1[i-1] - rx[n-1-i] << endl;
        ans4[n-i-1] = max(ans2[i], ans2[i] + ans1[i-1] - rx[n-i-1]);
    }
    ans4[n-1] = ans2[n-1];

    LL ans = 0;
    REP(i, n) ans = max(ans, max(max(ans1[i], ans2[i]), max(ans3[i], ans4[i])));
    cout << ans << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}



int main(){
fastio();

   ll x,m,d;
   cin>>x>>m>>d;
   ll mn=abs(x);
   if(x>0)
   {
       if(m>= abs(x)/d )
       {
          ll vg=x/d;
          x-= vg*d;
          m-= vg;
          mn=x;
          if(m)
          {
              if(abs(x-d)<=mn)
              {
                  x-=d;
                  mn=abs(x);
                  m--;
              }

              if(m%2)
              {
                  ll t1= abs(x-d);
                  ll t2=abs(x+d);
                  ll t=min(t1,t2);
                  mn=t;
              }

          }
       }
       else
       {
           x-= m*d;
           mn=abs(x);
       }
   }
       else
       {
           if(m>= abs(x)/d )
       {
          ll vg=abs(x)/d;
         // cout<<vg<<" "<<x<<endl;
          x+= vg*d;
          m-= vg;
          mn=abs(x);
        //  cout<<x<<endl;
          if(m)
          {
              if(abs(x+d)<=mn)
              {
                  x+=d;
                  mn=abs(x);
                  m--;
              }

              if(m%2)
              {
                  ll t1= abs(x-d);
                  ll t2=abs(x+d);
                  ll t=min(t1,t2);
                  mn=t;
              }

          }
       }
       else
       {
           x+= m*d;
           mn=abs(x);
       }

       }

       cout<<mn<<endl;











return 0;
}




Measured memory_bytes: 3648
N=int(input())
A=[]
A_before=input().split(' ')
for i in range(len(A_before)):
  A.append(int(A_before[i]))
for i in range(len(A)):
  for j in range(len(A)-1):
    if A[j]<A[j+1]:
      x=A[j]
      A[j]=A[j+1]
      A[j+1]=x
a=0
b=0
for i in range(len(A)):
  if i%2==0:
    a=a+A[i]
  else:
    b=b+A[i]
print(a-b)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
#define SIZE(v) int(v.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	vector<P> p(N);
	REP(i, N) cin >> p[i].second >> p[i].first;
	SORT(p);
	REV(p);
	int B = p[0].first;
	REP(i, N) {
		B = min(B, p[i].first);
		if (B < p[i].second) {
			cout << "No" << endl;
			return 0;
		}
		B -= p[i].second;
	}
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define MAX 1000000
#define mo 1000000007 
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

bool prime[MAX + 1]; 
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
  
    prime[1] = false; 
  
    for (int p = 2; p * p <= MAX; p++) { 
  
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) { 
  
            // Set all multiples of p to non-prime 
            for (int i = p * 2; i <= MAX; i += p) 
                prime[i] = false; 
        } 
    } 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll modexp(ll x, ll y, ll p)
{
ll res = 1;   
x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
} 
// Function to return LCM of two numbers  
  ll lcm(ll a, ll b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
ll mypow(ll b, ll e) {
    ll ans=1; for(;e;b=b*b%mo,e/=2) if(e&1) ans=ans*b%mo; return ans;}
ll power2(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power2(x, y / 2) * power2(x, y / 2); 
    else
        return x * power2(x, y / 2) * power2(x, y / 2); 
} 
ll mod=100000000;
#define MAXN 100001
ll spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}
ll bin(ll n, ll k)  
{  
    // Base Cases  
    if (k == 0 || k == n)  
        return 1;  
  
    // Recur  
    return bin(n - 1, k - 1) +  
                bin(n - 1, k);  
}  
ld dp[3001][3001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ld p[n+1];
	for(ll i=1;i<=n;i++)
	cin>>p[i];
	dp[0][0]=1;
	for(ll i=1;i<=n;i++)
	dp[0][i]=dp[0][i-1]*(1-p[i]);
	for(ll i=1;i<=n;i++)
	dp[i][i]=dp[i-1][i-1]*p[i];
	for(ll i=1;i<=n;i++)
	{
		for(ll j=i;j<=n;j++)
		{
			if(i==j)
			continue;
			dp[i][j]=dp[i-1][j-1]*p[j]+dp[i][j-1]*(1-p[j]);
		}
	}
	ll k=n/2+1;
	ld ans=0;
	for(ll i=k;i<=n;i++)
	ans+=dp[i][n];
 	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 141568
def printDivisors(n) : 
    i = 1
    fact = []
    while i <= n**(0.5): 
        if (n % i == 0) : 
            if (n / i == i) : 
                fact.append(i) 
            else : 
                fact.append(i) 
                fact.append(n//i) 
        i = i + 1
    return fact

n = int(input())
factN = printDivisors(n)[1:]
factN1  = printDivisors(n-1)[1:]
ans = len(factN1)
for fact in factN:
    num = n
    while num>=fact:
        if num%fact == 0:
            num = num//fact
        else:
            num %= fact
            break
    if num == 1:
        ans += 1
print(ans)

Measured memory_bytes: 3316
import sys

(str_n,str_y) = input().split()
n = int(str_n)
y = int(str_y)

if y % 1000 != 0:
    print (-1,-1,-1)
    sys.exit()

i_max = min(n,y//10000)
for i in range(i_max,-1,-1):
    left = y - 10000*i
    
    j_max = min(n-i,left//5000)
    for j in range(j_max,-1,-1):
        left = y - 10000*i - 5000*j
        
        k = left // 1000
        if i+j+k == n:
            print (i,j,k)
            sys.exit()

print (-1,-1,-1)

Measured memory_bytes: 3064
import java.util.Scanner;
class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int tate,yoko;
		int [][] box = new int [4][13];

			for(tate = 0; tate < 4; tate++){
				for(yoko = 0; yoko < 13; yoko++){

				//?????????1??¨?????§?????????
				box[tate][yoko]=0;
				}
			}

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

					String str = scanner.next();
					yoko = scanner.nextInt();
					

					if(str.equals("S")){
					box[0][yoko-1]=1;
					}
					else if(str.equals("H")){
					box[1][yoko-1]=1;
					}
					else if(str.equals("C")){
					box[2][yoko-1]=1;
					}
					else if(str.equals("D")){
					box[3][yoko-1]=1;
					}
			}	

			for(tate = 0; tate < 4; tate++){ 

				for(yoko = 0; yoko < 13; yoko++){

					if(tate  == 0){
							if(box[0][yoko]==0){
							System.out.println("S "+(yoko+1));
						}
					}
					if(tate  == 1){
						if(box[1][yoko]==0){
							System.out.println("H "+(yoko+1));
						}
					}
					if(tate  == 2){
						if(box[2][yoko]==0){
							System.out.println("C "+(yoko+1));
						}
					}
					if(tate  == 3){
						if(box[3][yoko]==0){
							System.out.println("D "+(yoko+1));
						}
					}
					
				}
			}
	}
}

Measured memory_bytes: 26172
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  var S = [0,1];
  for(var i=1;i<N;i++){
    var Ss1=S.map(j => j+"0");
    var Ss2=S.map(j => j+"1");
    var S=[...Ss1,...Ss2];
  }
  var P=input[M+1].split(" ").map(i=>parseInt(i));
  for(var i=0;i<M;i++){
    var tmp=input[i+1].split(" ").map(j => parseInt(j));
    for(var k=S.length-1;k>=0;k--){
      stmp=S[k].split("").map(i => parseInt(i));
      var cnt=0;
    for(var j=tmp[0];j>0;j--){
      if(stmp[tmp[j]-1]==1){
        cnt++;
      }
    }
      if(cnt%2!=P[i]){
        S.splice(k,1);
      }
    }
  }
  var ans=S.length;

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9744
n, a, b = [int(x) for x in input().split()]

M = 10 ** 9 + 7
# return 2 ** n % 10^9 + 7
def pow2(n):
    pow2s = [2]
    i = 1
    while 2 ** i <= n:
        pow2s.append(pow2s[-1] ** 2 % M)
        i += 1
    r = 1
    for i in range(len(pow2s)):
        if n & (1 << i) != 0:
            r = (r * pow2s[i]) % M
    return r

def fact(n):
    r = 1
    for i in range(1, n + 1):
        r = (r * i) % M
    return r

def inv(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return x0

def comb(n, k):
    r1 = 1
    for i in range(k):
        r1 = r1 * (n - i) % M
    r2 = 1
    for i in range(k):
        r2 = r2 * (i + 1) % M
    return r1 * inv(r2, M) % M
r = pow2(n) - 1 - comb(n, a) - comb(n, b)
while r < 0:
    r += M
print(r)

    


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

double calcSnuke(long long n);
long long calcNextNum(long long n);

int main()
{
    long long k = 0;
    long long num = 1;
    cin >> k;
    
    cout << 1 << endl;
    
    for(int i = 1; i < k; i++)
    {
        num = calcNextNum(num + 1);
        cout << num << endl;
    }
    
    return 0;
}

double calcSnuke(long long n)
{
    double x = (double) n;
    double sx = 0;
    while(n > 0){
        sx += n % 10;
        n /= 10;
    }
    return x / sx;
}


long long calcNextNum(long long n)
{
    vector<long long> candidates;
    vector<double> snukes;
    
    candidates.push_back(n);
    snukes.push_back(calcSnuke(n));
    
    for(int i = 0; i < log10(n) + 1; i++)
    {
        long long candidate_tmp = pow(10, i + 1) * (n / pow(10, i + 1) + 1) - 1;
        candidates.push_back(candidate_tmp);
        snukes.push_back(calcSnuke(candidate_tmp));
    }
    
    long long next_num = n;
    double snuke_tmp = snukes[0];
    
    for(int i = 0; i < candidates.size(); i++)
    {
        if(snukes[i] < snuke_tmp)
        {
            snuke_tmp =snukes[i];
            next_num = candidates[i];
        }
    }
    return next_num;
}



Measured memory_bytes: 512
import Control.Monad
import Data.Array
import Data.Array.Unboxed as UA
import Data.Array.ST
import Control.Monad.ST
import qualified Data.ByteString.Char8 as B

main=B.interact $ B.pack.f.take 2.B.lines

f [s,t]=mk "" (ls-1) (lt-1) where
    ls = B.length s
    lt = B.length t
    mk as si ti
        | si<0 || ti<0 = as
        | B.index s si == B.index t ti = mk (B.index s si:as) (si-1) (ti-1)
        | aa  UA.! (si+1,ti)>aa UA.! (si,ti+1) = mk as si (ti-1)
        | otherwise = mk as (si-1) ti
    aa :: UA.UArray (Int,Int) Int
    aa = runST $ do
        dp <- newArray ((0,0),(ls,lt)) 0 :: ST s (STUArray s (Int,Int) Int)
        forM_ [(i,j)|i<-[1..ls], j<-[1..lt]] $ \(i,j)->
            if B.index s (i-1) == B.index t (j-1)
                then writeArray dp (i,j) =<< (+1) <$> readArray dp (i-1,j-1)
                else writeArray dp (i,j) =<< max <$> readArray dp (i-1,j) <*> readArray dp (i,j-1)
        freeze dp

Measured memory_bytes: 141820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll n, m;
 	ld total = 0;
 	vector <ll> vec(n);
 	cin >> n >> m;
 	for (ll i = 0; i < n; i++) {
 		cin >> vec[i];
 		total += vec[i];
 	}   
 	total /= 4;
 	total /= m;
 	ll co = 0;
 	// cout << total << endl;
 	for (ll i = 0; i < n; i++) {
 		if (vec[i] >= total) co++;
 	}
 	if (co >= m) {
 		cout << "Yes" << endl;
 	}
 	else {
 		cout << "No" << endl;
 	}
	return 0;
}

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

using namespace std;
#define ll long long int

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	string s;
	cin>>s;
	n=0;
	//cout<<s.size()<<" "<<s[3]<<" "<<s[5];
	if(s.size()==6){
		if(s[2]==s[3] && s[4]==s[5])
			n=1;
	}
	if(n)
		cout<<"Yes";
	else
		cout<<"No";

	return 0;
}


Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
vector<int>g[200005];
int ans[200005],delta[200005];
int p[200005],mx[200005];
void dfs_init(int x){
	for(auto to:g[x]){
		if(to!=p[x]){
			p[to]=x;mx[to]=max(mx[x],x);
			dfs_init(to);
		}
	}
}
gp_hash_table<int,int>mem[200005];
int get_data(int x,int v){
	if(mem[x].find(v)!=mem[x].end())return mem[x][v];
	int ret=1;
	for(auto to:g[x]){
		if(to!=p[x]&&to<=v){
			ret+=get_data(to,v);
		}
	}
	return mem[x][v]=ret;
}
void dfs_solve(int x){
//	cerr<<x<<" "<<p[x]<<" "<<mx[x]<<" "<<get_data(x,mx[x])<<endl;
	if(x!=1){
		if(x>mx[p[x]])delta[x]=get_data(x,mx[x]);
		else delta[x]=get_data(x,mx[x])-get_data(x,mx[p[x]]);
	}
	for(auto to:g[x]){
		if(to!=p[x]){
			dfs_solve(to);
		}
	}
}
void pushdown(int x){
//	cerr<<x<<" "<<delta[x]<<endl;
	if(x!=1)ans[x]=ans[p[x]]+delta[x];
	for(auto to:g[x]){
		if(to!=p[x]){
			pushdown(to);
		}
	}
}
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs_init(1);
	mx[1]=-inf;
	dfs_solve(1);
	pushdown(1);
	ans[1]=0;
	for(int i=2;i<=n;i++)cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 79744
#n=int(input())
m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

if m1 != m2:
    print(1)
else:
    print(0)





Measured memory_bytes: 9024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int i1 = sc.nextInt();
        int i2 = sc.nextInt();
        int i3 = sc.nextInt();
        int i4 = sc.nextInt();

        int answer = 0;

        for (int i = 0; i <= i1; i++) {
            for (int j = 0; j <= i2; j++) {
                for (int k = 0; k <= i3; k++) {
                    if (i * 500 + j * 100 + k * 50 == i4) {
                        answer++;
                    }
                }
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 25044
// Author : Chi
// created :
//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb          push_back
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         1000000007
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
int n;
long double p[3000];
long double dp[1501][3000];
long double rec(int x,int i){
    if(x==0)
        return 1;
    if(i==0)
        return 0;
    if(dp[x][i] >= -0.9)
        return dp[x][i];
    dp[x][i]= p[i]*rec(x-1,i-1)+(1-p[i])*rec(x,i-1);
    return dp[x][i];
}
void solve(){
    cin>>n;
    memset(dp,-1.0,sizeof dp);
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    cout<<pdp(rec((n+1)/2,n),10);
}

// Driver Code
int main(){
    TEST1
    return 0;
}


Measured memory_bytes: 70912
N = int(input())
Ws = list(map(int,input().split()))

sumS1 = 0
sumTotal = sum(Ws)
minSubTotal = sumTotal
for i in range(N):
	sumS1 += Ws[i]
	sumS2  = sumTotal - sumS1
	#print(Ws[i],sumS1,sumS2,abs(sumS1 - sumS2))
	if abs(sumS1 - sumS2) < minSubTotal:
		minSubTotal = abs(sumS1 - sumS2)
		
print(minSubTotal)

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,a=0,b=0,c=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int z;cin>>z;
		if(z%4==0)c++;
		else if(z%2==0)b++;
		else a++;
	}
	if(c>=a||(b==0&&c+1>=a))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
A=sorted(list(map(int,input().split(' '))))
if N%2==1:
	B=[ ((i+1)//2)*2 for i in range(N) ]
	C=[ 0 if A[i]==B[i] else 1 for i in range(N) ]
	flag=True if sum(C)==0 else False
elif N%2==0:
	B=[ (i//2)*2+1 for i in range(N) ]
	C=[ 0 if A[i]==B[i] else 1 for i in range(N) ]
	flag=True if sum(C)==0 else False
print((2**(N//2))%(10**9+7)) if flag else print(0)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; ++i)

priority_queue <ll> L;
priority_queue <ll, vector<ll>, greater<ll> > R;

int main() {
	ios::sync_with_stdio(0);
	ll q, ans = 0; cin >> q;
	while (q--) {
		ll opt; cin >> opt;
		if (opt == 1) {
			ll a, b; cin >> a >> b; ans += b;
			L.push(a); R.push(a);
			if (L.top() > R.top()) {
				ll l = L.top(); L.pop();
		        ll r = R.top(); R.pop();
		        ans += l - r;
		        L.push(r);
		        R.push(l);
			}
		}
		else {
			cout << L.top() << ' ' << ans << '\n';
		}
	}
	
	return 0;
}


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

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string str;
  cin>>str;
  if(str[0]=='7' || str[1]=='7' ||str[2]=='7')
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3640
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n;
    cin >> n;
    if (n < 600)
        cout << 8;
    else if (n < 800)
        cout << 7;
    else if (n < 1000)
        cout << 6;
    else if (n < 1200)
        cout << 5;
    else if (n < 1400)
        cout << 4;
    else if (n < 1600)
        cout << 3;
    else if (n < 1800)
        cout << 2;
    else
        cout << 1;
}

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

int main()
{
	int N, M;
	int A[10010];

	cin >> N >> M;

	for (int i = 0; i < M; i++)
		cin >> A[i];

	int sum = 0;
	for (int i = 0; i < M; i++)
		sum += A[i];

	if (sum > N)
		cout << "-1" << endl;
	else
		cout << N - sum << endl;

	return 0;
}



Measured memory_bytes: 3644
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};

fn main() {
    let n: usize = read();

    let mut map: Vec<Vec<i64>> = vec![];

    for _ in 0..n {
        let a: i64 = read();
        let mut arr = vec![-1; n as usize];
        for _ in 0..a {
            let x: usize = read();
            let y: i64 = read();
            arr[x - 1] = y
        }
        map.push(arr);
    }

    for i in &map {
        // println!("{:?}", i);
    }

    let tow = 2 as u64;
    let mut tans = 0;

    for i in 0..(tow.pow(n as u32)) {
        let result: String = format!("{:0>keta$b}", i, keta = n as usize);
        // println!("{}", result);

        let result_char: Vec<char> = result.chars().collect();
        let mut ans = vec![-1; n];
        let mut res = true;
        for (idx, c) in result_char.iter().enumerate() {
            let i = c.to_digit(10).unwrap();
            let mut done = false;
            if i == 1 {
                // println!("{:?}", map[idx]);
                for (i2, j) in map[idx].iter().enumerate() {
                    if result_char[i2].to_digit(10).unwrap() != *j as u32 && *j != -1 {
                        done = true;
                        break;
                    }
                    if ans[i2] == -1 {
                        ans[i2] = *j
                    } else if ans[i2] != *j && *j != -1 {
                        done = true;
                        break;
                    }
                }
            }
            if done == true {
                res = false;
                break;
            }
        }
        if res == true {
            tans = max(tans, result_char.iter().filter(|&x| *x == '1').count());
        }
    }
    println!("{}", tans)
}


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

int main(void){
  int x,y;
  while(1){
    cin >> x >> y;
    if(x == 0 && y == 0)break;
    if(x < y)cout << x << ' ' << y << '\n';
    else cout << y << ' ' << x << '\n';
  }
  return 0;
}


Measured memory_bytes: 2996
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B, C, K;
	std::cin >> A >> B >> C >> K;

	int n = K;
	int max = 0;
	if (n > 0) {
		max += std::min(n, A);
		n -= A;
	}
	if (n > 0) {
		n -= B;
	}
	if (n > 0) {
		max -= std::min(n, C);
	}
	
	std::cout << max << "\n";
}


Measured memory_bytes: 3636
N,X=list(map(int, input().split()))
A=[0]*(N+1)
P=[0]*(N+1)
A[0]=1
P[0]=1

for i in range(N):
    A[i+1]=2*A[i]+3
    P[i+1]=2*P[i]+1
# print(A)
# print(P)

def burguer(n,x):
    if x==0:
        return 0
    if x==A[n]:
        return P[n]
    if x<=A[n-1]+1:
        y=burguer(n-1,x-1)
        return y
    else:
        y=burguer(n-1,x-A[n-1]-2)
        return P[n-1]+1+y

print(burguer(N,X))

Measured memory_bytes: 61952
// Amsal Shoma Ro Gaedan Ye Amal Pasandidas !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int x;
	cin >> x;
	cout << 360 / __gcd(x, 360) << '\n';
	return 0;
}


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

int main()
{
    int x;
    cin >> x;
    int y = sqrt(x) + 1;

    int ans;
    bool flag = true;

    //cout << "test y = " << y << endl;

    for (int i = x; i < 100005; i++) {
        flag = true;
        for (int j = 2; j < y; j++) {
            if (i % j == 0)
                flag = false;
        }
        if (flag) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
N = int(input())
JOB=[]
for _ in range(N):
    a, b =map(int, input().split())
    JOB.append([a,b])

JOB.sort(key= lambda x:x[1])

sum_t=0
for i in range(N):
    sum_t+=JOB[i][0]
    if sum_t>JOB[i][1]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 38036
import java.util.Scanner;
import java.util.ArrayDeque;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    String[] s = scanner.next().split("");
    ArrayDeque<String> result = new ArrayDeque<>();
    
    for(String input: s) {
      // "B"なら後ろから一つ捨てる
      if(input.equals("B")) {
        result.pollLast();
      // それ以外なら後ろに追加する
      } else {
    	result.offerLast(input);
      }
    }
    
    for(String r: result) {
      System.out.print(r);
    }
  }
}

Measured memory_bytes: 35280