akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional>
#include <iomanip>

#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define MAX 200000
int main() {
	int x, y;
	cin >> x >> y;
	int dif;
	dif = abs(abs(x) - abs(y));
	if (x == 0 || y == 0) {
		if (y < 0) {
			cout << dif + 1 << endl;
		}
		else {
			if (x > 0) {
				cout << dif + 1 << endl;
			}
			else {
				cout << dif << endl;
			}
		}
	}
	else {
		if (abs(x) > abs(y)) {
			if (x < 0 && y < 0) {
				cout << dif << endl;
			}
			else if (x > 0 && y > 0) {
				cout << dif + 2 << endl;
			}
			else {
				cout << dif + 1 << endl;
			}
		}
		else {
			if (x > 0 && y > 0) {
				cout << dif << endl;
			}
			else if (x < 0 && y < 0) {
				cout << dif + 2 << endl;
			}
			else {
				cout << dif + 1 << endl;
			}

		}
	}
	return 0;
}

Measured memory_bytes: 384
import Data.List (sortBy)

main :: IO ()
main = do
  _ <- read <$> getLine :: IO Int
  (ai:as) <- sortBy (flip compare).map read.words <$> getLine :: IO [Int]
  let md = fromIntegral ai/2 :: Double
      aj = foldr1 (\a b-> if abs(fromIntegral a-md) < abs(fromIntegral b-md) then a else b) as
  putStrLn $ unwords $ map show [ai, aj]


Measured memory_bytes: 49532
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<vector<int>> cnt(60,vector<int>(2,0));
	
	for(int i=0;i<N;i++){
		long long A;
		cin>>A;
		for(int j=0;j<60;j++){
			cnt[j][A%2]++;
			A/=2;
		}
	}
	
	int ans = 0;
	long long now = 1;
	
	for(int i=0;i<60;i++){
		long long a = now;
		a = mod(a * cnt[i][0]);
		a = mod(a * cnt[i][1]);
		ans = mod(ans + a);
		now = mod(now * 2);
	}
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int d[300];
bool ok[300];
bool prob[300];

int main() {
  int ma;
  while(cin>>ma,ma) {
    int n;
    cin >> n;
    REP(i,n) {
      cin >> d[i+1];
    }
    n++;
    memset(ok,0,sizeof(ok));
    memset(prob,0,sizeof(prob));
    prob[0] = 1;
    REP(k,n+1) {
      REP(i,n) {
        for (int x=1; x<=ma; ++x) {
          if (i+x>=n) ok[i] = 1;
          else {
            int D = d[i+x];
            int nxt = i+x;
            if (D > 0) {
              nxt += D;
            } else if (D < 0) {
              nxt += D;
            }
            if (nxt >= n) ok[i] = 1;
            else if (nxt < 0) ok[i] |= ok[0];
            else {
              // cout << i << " : " << nxt << endl;
              ok[i] |= ok[nxt];
              prob[nxt] |= prob[i];
            }
          }
        }
      }
    }
    // REP(i,n) cout << prob[i] << " " << ok[i] << endl;
    bool f = 0;
    REP(i,n) if (prob[i] && !ok[i]) {
      f = 1;
    }
    cout << (f?"NG":"OK") << endl;
  }
}

Measured memory_bytes: 1156
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(s.size()<=k) print(s);
    else {
        rep(i, k){
            cout << s[i];
        }
        cout << "..." << endl;
    }
    return 0;
}


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

int		main(void)
{
	string s;
	cin >> s;
	int a = 0, z = 0;
	while (s[a] != 'A')
		a++;
	for (int i = a; i < s.size(); i++)
		s[i] == 'Z' ? z = i : 0;
	cout << z - a + 1 << endl;
}



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

int main() {
  int n, m, l;
  cin >> n >> m >> l;

  vector<vector<int>> A(n, vector<int>(m, 0)), B(l, vector<int>(m, 0));
  vector<vector<long>> C(n, vector<long>(l, 0L));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A.at(i).at(j);
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B.at(j).at(i);
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      C.at(i).at(j) =
          inner_product(A.at(i).begin(), A.at(i).end(), B.at(j).begin(), 0L);
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j != l - 1) {
        cout << C.at(i).at(j) << ' ';
      } else {
        cout << C.at(i).at(j);
      }
    }
    cout << endl;
  }
}



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

int calc(int v,int x){
  for(int i=v;i>=0;--i) if(i*(100+x)/100==v) return i;
  return 0;
}

int main(){
  int x,y,s;
  while(cin>>x>>y>>s,x||y||s){
    int ans = 0;
    for(int i=1;i<=s-i;++i){
      int a = calc(i,x);
      int b = calc(s-i,x);
      int c = a*(100+y)/100;
      int d = b*(100+y)/100;
      ans = max(ans,c+d);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int a = 1;
    int broken = 0;
    for(int i = 0; i < N; i++){
        if(A[i] == a) a++;
        else broken++;
    }
    if(a == 1) puts("-1");
    else cout << broken << endl;
}

Measured memory_bytes: 1024
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

def f(i):
    xa,ya,xb,yb=i
    return ((xa-xb)**2+(ya-yb)**2)**0.5



def main():
    print(f(list(map(float,input().split()))))
if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

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

    int ans = 700;
    rep(i, 3) if (n[i] == 'o') ans+=100;

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


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

    const string YES = "Yes";
    const string NO  = "No";
    string s;

    cin >> s;

    if (s[0] == s[2]) {
        cout << YES;
    } else {
        cout << NO;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
import copy
N = int(input())
Ts = list(map(int, input().split()))
wa = sum(Ts)
M = int(input())
d_list = []
for i in range(M):
	p, x = list(map(int, input().split()))
	T = copy.deepcopy(Ts)
	T[p-1] = x
	d_list.append(T)

for i in range(M):
	print(sum(d_list[i]))

Measured memory_bytes: 3572
n = int(input())
l = []
temp = []
for i in range(0,2):
    temp = [int(x) for x in input().split()]
    l.append(temp)

cost=[]

for i in range(0,n):  # i = length
    price=0
    for j in range(0,i+1):
        price+=l[0][j]

    for k in range(i,n):
        price+=l[1][k]
    cost.append(price)

print(max(cost))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string s;
int main()
{
 cin>>s; string ss[4]={"dream","dreamer","erase","eraser"};
 for(int i=0;i<4;i++)
 {
   reverse(ss[i].begin(),ss[i].end());
 }
 reverse(s.begin(),s.end());
 bool can=true;
 for(int i=0;i<s.size();)
 {
   bool can2=false;
   for(int j = 0; j < 4; j++)
   {
     string d=ss[j];
     if(s.substr(i,d.size())==d)
     {
       can2=true;
       i+=d.size();
     }
   }
   if(!can2)
   {
     can=false; break;
   }
 }
 if(can)cout<<"YES"<<endl;
 else cout<<"NO"<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int main() {
	while(1){
		int h,m,i,j;
		scanf("%d %d",&h,&m);
		if(h == 0 && m == 0) break;
		for(i=0;i<h;i++){
			if(i == 0 || i == h-1){
				for(j=0;j<m;j++){
					printf("#");
				}
			}
			else{
				for(j=0;j<m;j++){
					if(j == 0 || j == m-1)	printf("#");
					else printf(".");
				}	
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2128
fn main(){
    let mut hs: Vec<i32> = vec![];
    for _i in 0..10{
        let n=readln();
        hs.push(n);
    }
    hs.sort();
    for i in (7..10).rev(){
        println!("{}",hs[i]);
    }
}
    

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
 
pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);



Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  for(int i=0; i<n; i++) cin >> h[i];

  sort(h.begin(), h.end());

  ll ans=INF;
  for(int i=0; i<n-k+1; i++){
    ans=min(ans, h[i+k-1]-h[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
N,K = map(int,input().split())
cc = list(map(int,input().split()))
dice_sum = sum(cc[:K])
max_dice = dice_sum
for i in range(N-K):
  dice_sum = dice_sum + cc[i+K] - cc[i]
  max_dice = max(max_dice,dice_sum)
print((max_dice+K)/2)

Measured memory_bytes: 32236
#include<stdio.h>
int main(void)
{
	int E,Y,a,b;
	scanf("%d %d",&E,&Y);
	if(E==0){
		if(Y>=1868&&Y<=1911){
			a=(Y-1868)+1;
			printf("M%d\n",a);
		}
		if(Y>=1912&&Y<=1925){
			a=(Y-1912)+1;
			printf("T%d\n",a);
		}
		if(Y>=1926&&Y<=1988){
			a=(Y-1926)+1;
			printf("S%d\n",a);
		}
		if(Y>=1989&&Y<=2016){
			a=(Y-1989)+1;
			printf("H%d\n",a);
		}
	}
	if(E>0){
		if(E==1){
			b=1869+Y-2;
		}
		if(E==2){
			b=1912+Y-1;
		}
		if(E==3){
			b=1926+Y-1;
		}
		if(E==4){
			b=1989+Y-1;
		}
		printf("%d\n",b);
	}
	return 0;
}


Measured memory_bytes: 2732
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  rep(x, k) {
    vector<int> im(n+1, 0);
    rep(i, n) {
      im[max(0, i-a[i])]++;
      im[min(i+a[i]+1, n)]--;
    }
    int now = 0;
    int num_less_than_n = 0;
    for (int i = 0; i < n; i++) {
      now += im[i];
      a[i] = now;
      if (a[i] < n) num_less_than_n++;
    }
    if (num_less_than_n == 0) break;
  }

  rep(i, n) printf("%d%c", a[i], i == n-1 ? '\n' : ' ');

  return 0;
}


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


int main() {
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int &x:a)
  {
    cin>>x;
  }
  /*
  vector<bool> dp(k + 1);
  for(int stones = 0; stones <= k; ++stones) 
  {
      for(int x : a)
       {
          if(stones >= x && !dp[stones-x]) 
          {
              dp[stones] = true;
          }
      }
  }

  puts(dp[k] ? "First" : "Second");
*/
  vector<bool> dp(k+1);
  for(int stones = 0;stones <= k;++stones)
  {
    for(int x : a)
    {
      if(stones>=x && !dp[stones-x])
      {
        dp[stones] = true;
      }
    }
  }
 puts(dp[k] ? "First" : "Second");
  /*
  if(helper(a,n,k,0)==0)
  {
    cout<<"first";
  }
  else
  {
    cout<<"second";
  }
*/
  return 0;
}

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

int main(){
  int n, d;
  cin >> n >> d;
  int a_d = (d * 2) + 1;
  
  int num = 1;
  while (a_d < n){
    n -= a_d;
    num += 1;
  }
  
  cout << num << endl;
}

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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define sz(x) ((int)(x).size())
using ll  = long long;
using vi  = vector<int>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
int maxd = 40; // 最大桁数

vi a;
int f(int x){
  int res = 0;
  rep(i,sz(a)) res += x ^ a[i];
  return res;
}  

signed main(){
  int n,k; cin >> n >> k; k++;
  a.resize(n); rep(i,n) cin >> a[i];

  // 最上位の1ビットが下から何桁目か(ただしk==0 <=> x==0)
  int x = 0;
  ROF(i,maxd,0)
    if((k >> i) & 1){
      x = i+1;
      break;
    }

  // 各ビットを何にしたほうが良いか
  vi y(maxd);
  rep(i,n) rep(j,maxd)
    y[j] += (a[i] >> j) & 1;
  rep(j,maxd){
    if(y[j] > n/2) y[j] = 0;
    else y[j] = 1;
  }

  int res = f(0);
  FOR(i,0,x){ // どこを折ってそれ以下を貪欲に取るか全探索
    if(((k >> i) & 1) == 0) continue; // 折れない
    int tmp = k;

    tmp -= (1ll << i);
    rep(j,i)
      tmp = tmp - ((tmp >> j) & 1) * (1ll << j) + y[j] * (1ll << j);
    chmax(res, f(tmp));
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    vector<int> a(3);
    rep(i, 3) cin >> a[i];

    sort(all(a));
    vector<int> b = {5, 5, 7};

    if(a == b){
        cout << "YES" << endl;
        return 0;
    }

    cout << "NO" << endl;

return 0;
}

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


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

struct UFTree {
    static const int MAX_N = 1e6;
    int p[MAX_N], r[MAX_N], s[MAX_N];

    UFTree(int n) : p(), r(), s() {
        for(int i = 0; i < n; ++i) {
            p[i] = i;
            r[i] = 0;
            s[i] = 1;
        }
    }

    int root(int x) {
        return p[x] == x ? x : (p[x] = root(p[x]));
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;

        if(r[x] < r[y]) {
            p[x] = y;
            s[y] = s[x] + s[y];
        } else {
            p[y] = x;
            s[x] = s[x] + s[y];
            if(r[x] == r[y]) r[x]++;
        }
    }

    int size(int x) {
        return s[root(x)];
    }
};

int n, m, k;
// string s;

int main() {
    cin >> n >> m >> k;
    UFTree t = UFTree(n);
    VVi f(n);
    REP(i, m) {
        int x, y; cin >> x >> y;
        x--; y--;
        f[x].push_back(y);
        f[y].push_back(x);
        t.unite(x, y);
    }
    VVi block(n);
    REP(i, k) {
        int x, y; cin >> x >> y;
        x--; y--;
        block[x].push_back(y);
        block[y].push_back(x);
    }

    REP(i, n) {
        int size = t.size(i);
        size -= f[i].size() + 1;
        FOR(j, block[i]) {
            if (t.same(*j, i)) size--;
        }
        std::cout << size;
        if (i != n-1) {
            std::cout << ' ';
        }
    }
    std::cout << '\n';

    return 0;
}


Measured memory_bytes: 23544
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String args[]) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] parts1 = br.readLine().split(" ");
		String[] parts2 = br.readLine().split(" ");
		
		int H = Integer.parseInt(parts1[0]);
		int N = Integer.parseInt(parts1[1]);
		
		int s = 0;
		for (int i = 0; i < parts2.length; i++) {
			s+=Integer.parseInt(parts2[i]);
		}
		
		if(s>=H) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
			
	}

}

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

using namespace std;

int ans = 1e9;

void solve(int x, int cnt){
  if(x < 6){
    ans = min(ans, cnt + x);
    return;
  }
  int tmp = 0;
  for(int i=9; i<=x; i*=9){
    tmp = i;
  }
  if(tmp) solve(x-tmp, cnt+1);
  tmp = 0;
  for(int i=6; i<=x; i*=6){
    tmp = i;
  }
  if(tmp) solve(x-tmp, cnt+1);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  solve(n, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
   
int main() {
	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	vector<string> b(m);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, m) {
		cin >> b[i];
	}
	rep(dx , n - m + 1) {
		rep(dy, n - m + 1) {
			bool is_ok = true;
			rep(x, m) {
				rep(y, m) {
					if (a[y + dy][x + dx] != b[y][x]) {
						is_ok = false;
						y = m;
						x = m;
					}
				}
			}
			if (is_ok) {
				cout << "Yes" << endl;
				return 0;
			}
		}

	}
	cout << "No" << endl;

	return 0;
}


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

int main(){
  ll k,a,b,i;
  string ans;
  ans="NG";
  cin >> k >> a >> b;
  for(i=a;i<=b;i++){
    if(i%k==0){
      ans="OK";
    }
  }
  cout << ans;
}

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

using namespace std;

typedef pair<int,int> pi;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	cout << s[0] << s[1] << s[2] << '\n';
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

long long ans = 0;
long long MOD = 998244353;

long long fact[500000];
long long ufact[500000];

long long inq(long long a, long long b)
{
    if (b == 0) return 1;
    long long l = inq(a, b / 2);
    if (b % 2) return l * l % MOD * a % MOD;
    return l * l % MOD;
}
long long cnk(long long n, long long k)
{
    if (k <= n && k >= 0)
        return (fact[n] * ufact[n - k] % MOD * ufact[k] % MOD);
    return 0;
}
int main()
{
    fact[0] = 1, ufact[0] = 1;
    for (int i = 1; i < 500000; i++) fact[i] = fact[i - 1] * i % MOD, ufact[i] = inq(fact[i], MOD - 2);
    long long n, a, b, k;
    cin >> n >> a >> b >> k;
    for (int i = 0; i <= n; i++)
    {
        long long summ = a * i;
        long long j = (k - summ) / b;
        if (j * b != k - summ) continue;
        ans += cnk(n, i) * cnk(n, j);
        ans %= MOD;
    }
    cout << ans;
}


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

int main(){
	int n,count=0;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	for(int i=1; i<n-1; i++){
            if((a[i]>a[i-1] && a[i]<a[i+1] )|| (a[i]>a[i+1] && a[i]<a[i-1])){
            	count++;
			}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int t[101], b[101];
	for (int i = 0; i < 101; ++i)
	{
		t[i] = 0; b[i] = 0;
	}
	for (int i = 1; i <= n; ++i)
	{
		int a; cin >> a;
		t[i] = a + t[i - 1];
	}
	for (int i = 1; i <= n; ++i)
	{
		int a; cin >> a;
		b[i] = a;
	}
	for (int i = 99; i >= 0; --i)
	{
		b[i] += b[i + 1];
	}
	int max = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (t[i] + b[i] > max)
			max = t[i] + b[i];
	}
	cout << max;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main(void)
{
  int num;
  char s[10];
  vector<string> vec;
  
  if ( scanf("%d", &num ) ) {
    for( int i = 0; i < num; ++i ) {
      if ( scanf("%s", s ) ) {}
      vec.push_back(s);
    }
  }
  
  sort(vec.begin(), vec.end());
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
  
  num = vec.size();
  printf("%d",num);
  
  return 0;
}

Measured memory_bytes: 11648
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
	ll n;scanf("%lld",&n);
	for (int i = 0; i < n; ++i)
	{
		char x;scanf("%c",&x);
		if(x == 'Y'){
			printf("Four\n");return 0;
		}
	}
	printf("Three\n");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int d =  (a / b);
		int r =  (a % b);
		double f = (double)a /(double) b;
		
		System.out.print(d + " " + r + " ");
		System.out.printf("%f", f);
	}

}



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

string S;

int notVal(int x){
    return 2-x;
}

int changeVal(int a,int b,char op){
    if(op=='+') return max(a,b);
    else return min(a,b);
}

bool judge(int a,int b,int c){
    char opt[100];
    vector<int> val[100];
    int no[100]={};

    int dep=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='(') dep++;
        else if(S[i]==')'){
            int va=changeVal(val[dep][0],val[dep][1],opt[dep]);
            val[dep].clear();
            if(no[dep-1]) va=notVal(va);
            no[dep-1]=0;
            dep--;
            val[dep].push_back(va);
        }else if(S[i]=='-'){
            no[dep]=1-no[dep];
        }else if(S[i]=='+'){
            opt[dep]='+';
        }else if(S[i]=='*'){
            opt[dep]='*';
        }else if(S[i]>='0'&&S[i]<='2'){
            int va=S[i]-'0';
            if(no[dep]) va=notVal(va);
            no[dep]=0;
            val[dep].push_back(va);
        }else{
            int va=0;
            if(S[i]=='P') va=a;
            else if(S[i]=='Q') va=b;
            else if(S[i]=='R') va=c;

            if(no[dep]) va=notVal(va);
            no[dep]=0;
            val[dep].push_back(va);
        }
    }

    if(val[0][0]==2) return true;
    else return false;
}

void solve(){
    int ans=0;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(judge(i,j,k)) ans++;
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    while(1){
        cin>>S;
        if(S==".") break;
        solve();
    }

  return 0;
}



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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if(x + r > w || x - r < 0 || y + r > h || y - r < 0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
 
//Made with <3 by MinumCoklatPanas
typedef unsigned long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b,n;
	cin >> a >> b >> n;
	// assert(a != b);
	ll mx = (n / b) * b;
	if (mx == n && n != 1)
		--mx;
	else
		mx = n;
	mx = max(mx,1ull);
	// cout << mx << endbl;
	ll ans = ((mx * a) / b) - (a * (mx / b));
	ll mn = min(n,b - 1);
	ll tmp = ((mn * a) / b) - (a * (mn / b));
	ans = max(ans,tmp);
	cout << max(ans,0ull) << endl;
	return 0;
}

Measured memory_bytes: 3548
import java.util.Scanner;

public class Main{
	public static void main(String[]args){

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		int k=sc.nextInt();
		if(n/k==(double)n/k){
			System.out.println(0);
		}else{
			System.out.println(1);
		}

	}
}

Measured memory_bytes: 23636
#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(){
  ll n;
  cin >> n;
  vi a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll ans = 0;
  rep(i,n-1){
    for (ll j = i + 1; j < n;j++){
      ll b = abs(a[i] - a[j]);
      chmax(ans, b);
    }
  }
  print(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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() {
    int k;
    cin >> k;
    queue<ll>q;
    for(int i = 1;i<=9;i++) q.push(i);
    ll ans = 0;
    rep(i,k) {
        ll cur = q.front();q.pop();
        if(i==k-1) {
            cout << cur << endl;
            return 0;
        }
        int add = cur%10;
        if(add>=1) {
            ll next = cur*10+add-1;
            q.push(next);
        } 
        q.push(cur*10+add);
        if(add<=8) {
            ll next = cur*10+add+1;
            q.push(next);
        }
        
    }
}

Measured memory_bytes: 5068
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
ll read()
{
    ll tmp=0; char c=getchar(),f=1;
    while(c<'0'||'9'<c){if(c=='-')f=-1; c=getchar();}
    while('0'<=c&&c<='9'){tmp=tmp*10+c-'0'; c=getchar();}
    return tmp*f;
}
using namespace std;
int a[10];
int main()
{
	int i,j,n=read();
	for(i=4;i;i--)a[i]=n%10,n/=10;
	for(i=0;i<8;i++){
		int tmp=a[1];
		for(j=0;j<3;j++)if(i&(1<<j))tmp+=a[j+2];else tmp-=a[j+2];
		if(tmp==7){
			printf("%d",a[1]);
			for(j=0;j<3;j++){
				if(i&(1<<j))printf("+");else printf("-");
				printf("%d",a[j+2]);
			}
			printf("=7\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
c=[list(map(int,input().split())) for _ in range(3)]
if c[1][0]-c[0][0]==c[1][1]-c[0][1] and c[1][1]-c[0][1]==c[1][2]-c[0][2] and c[2][0]-c[0][0]==c[2][1]-c[0][1] and c[2][1]-c[0][1]==c[2][2]-c[0][2]: print("Yes")
else: print("No")

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


int main(){
	int n,a,b;
	int aans,bans;
	while(1){
		aans = 0;
		bans = 0;
		cin >> n;
		if(!n)	break;
		
		for(int i=0;i<n;i++){
			cin >> a >> b;
			if(a > b)	aans += (a + b);
			else if(a < b)	bans += (a + b);
			else{
				aans += a;
				bans += b;
			}
		}
		cout << aans << " " << bans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end(), greater<>());

	double m = accumulate(A.begin(), A.end(), 0) / (4.0 * M);
	bool ok = true;
	for (int i = 0; i < M; i++) {
		if (A[i] < m) {
			ok = false;
			break;
		}
	}

	if (ok) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char b;
int main(){
    cin>>b;
    if(b=='A')cout<<"T"<<endl;
    else if(b=='T')cout<<"A"<<endl;
    else if(b=='C')cout<<"G"<<endl;
    else if(b=='G')cout<<"C"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    using ll = long long;
    ll n, h;
    cin >> n >> h;
    using P = pair<ll, ll>;
    vector<P> s(n);
    for(int i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        s[i].first = b;
        s[i].second = a;
    }
    sort(s.begin(), s.end(), greater<P>());
    ll cu = 0;
    for(int i = 0; i < n; i++)
    {
        if(cu <= s[i].second)
        {
            cu = s[i].second;
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(cu <= s[i].first)
        {
            h -= s[i].first;
            ans++;
        }
        else
        {
            break;
        }
        if(h <= 0)
        {
            cout << ans << endl;
            return 0;
        }
    }
    while(true)
    {
        if(h <= cu)
        {
            ans++;
            cout << ans << endl;
            return 0;
        }
        else
        {
            h -= cu;
            ans++;
        }
    }
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,INF=0x3f3f3f3f;
typedef pair<int,int> pii;
int fa[N],vis[N],mi[N],V[N];
vector<pii >Q(N);
int find(int x)
{
    return x==fa[x]?x:(fa[x]=find(fa[x]));
}
int main()
{
    ios::sync_with_stdio(false);
    int n,m,tn=0;
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>Q[i].first,fa[i]=i,mi[i]=INF;
    for(int i=0,u,v; i<m; i++)
    {
        cin>>u>>v,u=find(u),v=find(v);
        if(u!=v)fa[u]=v;
    }
    for(int i=0; i<n; i++)
    {
        find(i);
        if(!vis[fa[i]])V[tn++]=fa[i];
        vis[fa[i]]=1,Q[i].second=fa[i],mi[fa[i]]=min(Q[i].first,mi[fa[i]]);
    }
    if(tn==1)cout<<0;
    else if((tn-1)*2>n)cout<<"Impossible";
    else
    {
        long long s=0;
        for(int i=0; i<tn; i++)s+=mi[V[i]];
        if(tn!=2)sort(Q.begin(),Q.begin()+n);
        for(int i=0; i<n&&tn!=2; i++)
        {
            if(vis[Q[i].second])
            {
                vis[Q[i].second]=0;
                continue;
            }
            s+=Q[i].first,tn--;
        }
        cout<<s;
    }
    return 0;
}


Measured memory_bytes: 2560
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define T3I tuple<int, int, int>
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

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

    int x, y;
    cin >> x >> y;
    int a, b ,c;
    cin >> a >> b >> c;
    vector<int> A(a), B(b), C(c);
    for(int i = 0; i < a; ++i) {
        cin >> A[i];
    }
    for(int i = 0; i < b; ++i) {
        cin >> B[i];
    }
    for(int i = 0; i < c; ++i) {
        cin >> C[i];
    }
    sort(A.begin(), A.end(), greater<int>());
    sort(B.begin(), B.end(), greater<int>());
    sort(C.begin(), C.end(), greater<int>());

    ll ans = 0;
    int cnta = min(a, x), cntb = min(b, y), cntc = 0;
    for(int i = 0; i < cnta; ++i) {
        ans += A[i];
    }
    for(int i = 0; i < cntb; ++i) {
        ans += B[i];
    }
    cntc = x+y-cnta-cntb;
    for(int i = 0; i < cntc; ++i) {
        ans += C[i];
    }

    while(true) {
        int mine = INF, f = -1;
        if(cnta > 0) {
            mine = A[cnta-1];
            f = 1;
        }
        if(cntb > 0) {
            if(mine > B[cntb-1]) {
                mine = B[cntb-1];
                f = 2;
            }
        }
        if(f == -1) break;
        if(cntc == c) break;
        if(mine >= C[cntc]) break;
        if(f == 1) {
            ans -= A[--cnta];
            ans += C[cntc++];
        }else {
            ans -= B[--cntb];
            ans += C[cntc++];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int mod = 1e9 + 7;

int N;
long long A, B, S[100010];

struct ST {
	int t[270000];
	bool tag[270000];
	
	inline void add (int p, int l, int r, int pos, int x) {
		if (l == r) { t[p] = x, tag[p] = false; return; }
		if (tag[p]) t[p << 1] = t[p << 1 | 1] = 0, tag[p << 1] = tag[p << 1 | 1] = true, tag[p] = false;
		int mid = (l + r) >> 1;
		if (pos <= mid) add (p << 1, l, mid, pos, x);
		else add (p << 1 | 1, mid + 1, r, pos, x);
		t[p] = (t[p << 1] + t[p << 1 | 1]) % mod;
	}
	
	inline int query (int p, int l, int r, int ll, int rr) {
		if (l >= ll && r <= rr) return t[p];
		if (tag[p]) t[p << 1] = t[p << 1 | 1] = 0, tag[p << 1] = tag[p << 1 | 1] = true, tag[p] = false;
		int mid = (l + r) >> 1, res = 0;
		if (ll <= mid) res = (res + query (p << 1, l, mid, ll, rr)) % mod;
		if (rr > mid) res = (res + query (p << 1 | 1, mid + 1, r, ll, rr)) % mod;
		return res;
	}
} X, Y;

int main () {
	scanf ("%d%lld%lld", &N, &A, &B);
	for (int i = 1; i <= N; i++) scanf ("%lld", &S[i]);
	
	sort (S + 1, S + N + 1);
	X.add (1, 0, N, 0, 1), Y.add (1, 0, N, 0, 1);
	for (int i = 2; i <= N; i++) {
		int x = X.query (1, 0, N, 0, upper_bound (S + 1, S + i, S[i] - B) - S - 1);
		int y = Y.query (1, 0, N, 0, upper_bound (S + 1, S + i, S[i] - A) - S - 1);
		if (S[i] - S[i - 1] < A) X.t[1] = 0, X.tag[1] = true;
		if (S[i] - S[i - 1] < B) Y.t[1] = 0, Y.tag[1] = true;
		X.add (1, 0, N, i - 1, y), Y.add (1, 0, N, i - 1, x);
	}
	
	printf ("%d\n", (X.t[1] + Y.t[1]) % mod);
	
	return 0;
} 

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    int n = sz(s);
    vi m(n);
    m[n - 1] = (int)(s[n - 1] - '0');
    int d = 10;
    REPR(i, n - 1) {
        m[i] = (m[i + 1] + (int)(s[i] - '0') * d) % 2019;
        d = (d * 10) % 2019;
    }
    // printv(m);
    map<int, int> mp;
    mp[0]++;
    for (auto x : m) mp[x]++;

    ll ans = 0;
    for (auto p : mp) {
        // cout << p.first << ": " << p.second << endl;
        ll c = p.second;
        if (c > 1) ans += c * (c - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4408
def checkRows(grid):
    for row in grid:
        if all([n == True for n in row]):
            return True
    return False


def checkCols(grid):
    for j in range(3):
        if all([n == True for n in [grid[i][j] for i in range(3)]]):
            return True
    return False


def checkDiags(grid):
    return all([n == True for n in [grid[i][i] for i in range(3)]]) or \
           all([n == True for n in [grid[i][2 - i] for i in range(3)]])


if __name__ == '__main__':
    grid = [[0] * 3 for i in range(3)]
    idx = {}

    for i in range(3):
        grid[i] = [int(s) for s in input().strip().split()]
        for j in range(3):
            idx[grid[i][j]] = (i, j)

    n = int(input())
    bs = [-1] * n

    for i in range(n):
        bs[i] = int(input())
        if bs[i] in idx.keys():
            a, b = idx[bs[i]]
            grid[a][b] = True

    if checkRows(grid) or checkCols(grid) or checkDiags(grid):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064
w,h,n = map(int,input().split())
l=0
u=0
for _ in range(n):
  x,y,a = map(int,input().split())
  if a ==1:
    l = max(x,l)
  elif a == 2:
    w = min(x,w)
  elif a == 3:
    u = max(y,u)
  elif a == 4:
    h = min(y,h)
print((w-l)*(h-u) if w-l > 0 and h-u > 0 else 0)

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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  cout <<abs(A.at(N-1) - A.at(0)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int a,b,c;
    cin >> a >> b >> c;
    if(a <= b){
        cout << c << endl;
    }else{
        cout << max( c - ( a - b ), 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  string res;
  cin >> N;

  if(N<1200) res="ABC";
  else res="ARC";

  cout << res << endl;
}


Measured memory_bytes: 256
r,g,b,n = map(int,input().split())
boxes = [r,g,b]
boxes.sort()
ans = 0
for i in range(n//boxes[0] +1):
    for j in range((n-i*boxes[0])//boxes[1] +1):
        if (n-(i*boxes[0]+j*boxes[1]))%boxes[2] == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3060