akhauriyash/Code-Regression huggingface dataset:
// ---------- begin ModInt ----------
const MOD: u32 = 1_000_000_007;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 {0} else {MOD - self.0})
    }
}

impl std::fmt::Display for ModInt {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl From<usize> for ModInt {
    fn from(val: usize) -> ModInt {
        ModInt((val % MOD as usize) as u32)
    }
}

impl From<i64> for ModInt {
    fn from(val: i64) -> ModInt {
        let m = MOD as i64;
        ModInt::new((val % m + m) as u32)
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let mut dp = vec![ModInt::zero(); k + 1];
    dp[1] = ModInt::one();
    for _ in 2..(n + 1) {
        let mut next = vec![ModInt::zero(); k + 1];
        for (i, next) in next.iter_mut().enumerate().skip(1) {
            *next = dp[i - 1] + ModInt::from(i) * dp[i];
        }
        dp = next;
    }
    let ans = dp.into_iter().fold(ModInt::zero(), |s, a| s + a);
    println!("{}", ans);
}

fn main() {
    run();
}



Measured memory_bytes: 5028
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    string s, t;
    scan(s, t);
    writeln(t ~ s);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
  int64_t N;
  cin>>N;
  int64_t ai[N];
  int64_t tmp=0;
  int64_t ans=0;
  for(int i=0;i<N;i++){
    cin>>ai[i];
  }
  for(int i=0;i<N;i++){
    tmp=ai[i];
    while(tmp!=0 && tmp%2!=1){
      tmp/=2;
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

typedef long long ll;

main()
{
    double n, a, sum = 0, yen;
    string s;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        cin >> s;
        if(s == "BTC"){
            yen = a *  380000;
            sum = sum + yen;
        }
        else{
            sum = sum + a;
        }
    }
    cout << sum;


}





///promy_pompom
//hello world


Measured memory_bytes: 3780
#include <iostream>
#include <string>
#define FOR(i,k,n) for(int(i)=(k);(i)<(n);(i)++)
using namespace std;

int main()
{
  int K,S;
  cin >> K >> S;

  int ans = 0;
  FOR(X,0,K+1) {
    FOR(Y,0,K+1) {
      int Z;
      Z = S - X - Y;
      if (Z >= 0 && Z <= K) ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
class UnionFind():
  def __init__(self,n):
    self.n = n
    self.parents = [-1] * (n+1)
  
  def find(self, x):
    if self.parents[x] < 0:
      return x
    self.parents[x] = self.find(self.parents[x])
    return self.parents[x]
  
  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.parents[x] > self.parents[y]:
      x,y = y,x
    self.parents[x] += self.parents[y]
    self.parents[y] = x
 
  def size(self, x):
    return -1 * self.parents[x]
  
  def same(self, x, y):
    return self.find(x) == self.find(y)
  
  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]
    
  def roots(self):
    return [i for i,x in enumerate(self.parents) if x < 0]
    
  def group_count(self):
    return len(self.roots()) - 1
  
N,M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
  a,b = map(int, input().split())
  uf.union(a,b)
ans = uf.group_count() - 1
print(ans)


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    ll ok = -1e18 - 1;
    ll ng = 1e18 + 1;

    auto isOK = [&](ll x) {
        ll cnt = 0;
        rep(i, n)
        {
            ll add = 0;
            if (a.at(i) >= 0) {
                ll ng = n, ok = -1;
                while (abs(ok - ng) > 1) {
                    ll mid = (ok + ng) / 2;
                    if (a.at(i) * a.at(mid) < x) {
                        ok = mid;
                    } else {
                        ng = mid;
                    }
                }
                add = ok + 1;
            } else {
                ll ng = -1, ok = n;
                while (abs(ok - ng) > 1) {
                    ll mid = (ok + ng) / 2;
                    if (a.at(i) * a.at(mid) < x) {
                        ok = mid;
                    } else {
                        ng = mid;
                    }
                }
                add = n - ok;
            }
            if (a.at(i) * a.at(i) < x)
                add--;
            cnt += add;
        }
        cnt = cnt / 2;
        return cnt < k;
    };

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isOK(mid))
            ok = mid;
        else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

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

#define LL long long
#define MAXN 10000

int legal(int val, int max){
	if(val<0||val>=max){
		return 0;
	}else{
		return 1;
	}
}

int main(){
	int dh[]={-1,-1,-1,0,0,1,1,1};
	int dw[]={-1,0,1,-1,1,-1,0,1};
	int h,w;
	cin>>h;
	cin>>w;
	vector<string> S;
	for(int i=0;i<h;i++){
		string temp;
		cin>>temp;
		S.push_back(temp);
	}
	vector<string> res(S);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(S[i][j]=='.'){
				int sum=0;
				for(int k=0;k<8;k++){
					int ni,nj;
					ni=i+dh[k];
					nj=j+dw[k];
					int x=legal(ni,h);
					int y=legal(nj,w);
					if(x==1&&y==1){
						if(S[ni][nj]=='#'){
							sum++;
						}
					}
				}
				res[i][j]='0'+sum;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout<<res[i][j];
		}
		cout<<endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
ll a1 =a*c;
ll a2 = a*d;
ll a3 = b*c;
ll a4 = b*d;
 ll ans1 =max(a1,a2);
 ll ans2 = max(a3,a4);
 ll ans = max(ans1,ans2);
 cout<<ans<<endl;
 return 0;
}



Measured memory_bytes: 3608
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pin;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;


#define ff(i, a, b) for ( ll i=a; i<(b); i++)
#define ffd(i, a, b) for ( ll i=a; i<= b; i++)
#define fr(i,a,b) for (int i = (b)-1; i >= a; i--)
#define ffr(i,a) for (int i = (a)-1; i >= 0; i--)
#define endl "\n"
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int maxn = 2e5 + 5 ;
const int mod = 1000000007;
const ll INF = 1e18;
const int MX = 2000000001; //check the limits, dummy

pair < int , string > s[200] ;
int main() {
	ios_base::sync_with_stdio(0) ,cin.tie(0);
  ll t, qr, n, ar, hb, k, l, m, r,  x = 0, y = 0, ans = 0, temp = 0, res = 0 ;
  cin >> n ;
  double pi = 3.14159 ;
  cout << fixed << setprecision(12) << ( 2.0 * pi * n) ;
}
   

Measured memory_bytes: 3824
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while(a >= b){
        b *= 2;
        k--;
        if(k < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    while(b >= c){
        c *= 2;
        k--;
        if(k < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    int p;
    ll s[100000];
    int count[100000] = {0};
    for (int i = 1; i <= n; i++){
        s[i] = k;
    }
    for (int i = 1; i <= q; i++){
        cin >> p;
        count[p]++; 
    }

    for (int i = 1; i <= n; i++){
        s[i] = s[i] - q + count[i];
    }

    for (int i = 1; i <= n; i++){
        if (s[i] <= 0) cout << "No\n";
        else cout << "Yes\n";
    }      

}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main() {
	char s[9000];
	int i ,j;
	for (i = 0; i < 12; i++) {
		scanf("%c", &s[i]);
	}
	printf("%c%c%c", s[0], s[5], s[10]);
	return 0;
}

Measured memory_bytes: 128
x, y = map(int, input().split())
g_1 = (1, 3, 5, 7, 8, 10, 12)
g_2 = (4, 6, 9, 11)
g_3 = (2,)

if (x in g_1 and y in g_1) or (x in g_2 and y in g_2) or (x in g_3 and y in g_3):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
ll factorial[1000001];
const int mod = 1e9+7;
int main(){
    int N;
    cin >> N;
    factorial[0] = 1;
    REP1(i,N){
        factorial[i] =(factorial[i-1]*i)%mod;
    }
    cout << factorial[N] << endl;
    return 0;
}


Measured memory_bytes: 1024
/**
 *    author:  tourist
 *    created: 03.11.2019 18:32:17
 **/
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int min_b = *min_element(b.begin(), b.end());
    int max_a = *max_element(a.begin(), a.end());
    int ans = 0;
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) {
        p[i] = make_pair(min_b - a[i] + 1, b[i] - max_a + 1);
    }
    sort(p.begin(), p.end());
    debug(p);
    int m2 = (int) 1.01e9;
    for (int i = 0; i < n - 1; i++) {
        m2 = min(m2, p[i].second);
        ans = max(ans, p[i + 1].first + m2);
    }
    for (int i = 0; i < n; i++) {
        int cur = b[i] - a[i] + 1;
        cur += max(0, min_b - max_a + 1);
        ans = max(ans, cur);
    }
    cout << ans << '\n';
    return 0;
}

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    string s;
    int cnt;
    cin >> n >> s;
    rep(i, 0, n){
        if(i == n - 2) break;
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
using std::cin;
using std::cout;
int main()
{
	int a,b,c,x,y;
	long int cost=0;
	cin>>a>>b>>c>>x>>y;
	if(c<((a+b)/2.0))
	{
		if(y>x)
		{
			cost+=x*c*2;
			y=y-x;
			if(c<(b/2.0))
				cost+=y*c*2;
			else
				cost+=y*b;
		}
		else
		{
			cost=y*c*2;
			y=x-y;
			if(c<(a/2.0))
				cost+=y*c*2;
			else
				cost+=y*a;
		}
	}
	else 
		cost=x*a+y*b;
	cout<<cost;
			
			
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <ctime>
#include <set>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <climits>

#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define p(a) cout << a << "\n";
#define p1(a) cout << a << " ";

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)

using namespace std;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 

void solve()
{
	int n;
	cin >> n;
	if(n%10 == 9 || (n/10)%10 == 9)
		p("Yes")
	else
		p("No")
}
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
} 

Measured memory_bytes: 256
N = int(input())
As = list(map(int,input().strip().split()))
Bs = list(map(int,input().strip().split()))

diff = []
for i in range(0,N):
    diff.append(As[i] - Bs[i])

minuss = list(filter(lambda x: x < 0, diff))
sorted_diff = sorted(diff,reverse=True)
pla = list(filter(lambda x: x >= 0, sorted_diff))

minus_num = len(minuss)
minus = sum(minuss)
i = 0
while i < len(pla):
    if minus >= 0:
        print(i + minus_num)
        exit()
    minus += pla[i]
    i += 1

if minus >= 0:
    print(i + minus_num)
else:
    print("-1")

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

int n, q;
long long a, b, c, ans;
map<long long, int> mp;


int main() {
    cin >> n;
    while (n --) {
        cin >> a;
        ans += a;
        mp[a] ++;
    }
    cin >> q;
    while (q --) {
        cin >> b >> c;
        int num = mp[b];
        mp[b] = 0;
        mp[c] += num;
        ans += (long long) (c - b) * num;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 9572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	string s,t,u; int a,b;
	cin>>s>>t>>a>>b>>u;
	if(s == u) cout<<a-1<<" "<<b<<endl;
	else cout<<a<<" "<<b-1<<endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
   tmp.sort(function(a,b){
    if( a < b ) return -1;
    if( a > b ) return 1;
    return 0;
	})
   
   result = tmp.toString() == [1,4,7,9] ? 'YES' :'NO';
   console.log(result)

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21956
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;

    return 0;
}

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

/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)

///START
/// Constants
#define MAX     200005
#define MOD     1000000007
#define base    1000000007
#define eps     1e-9
#define INF     1llu<<61    // 2,305,843,009,213,693,952
#define inf     1<<29       // 536,870,912
#define PI      acos(-1.0)  // 3.1415926535897932
// #define      INF 0x3f3f3f3f3f3f3f3f
// #define      inf 0x3f3f3f3f

int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int d,m;
    string str;
    cin>>str;
    d=((str[0]-'0')*10+(str[1]-'0'));
    m=((str[2]-'0')*10+(str[3]-'0'));
    //scanf("%d:%d",&d,&m);
    //cout<<d<<" "<<m<<endl;
    if(1<=d && d<=12){
        if(1<=m && m<=12)pf("AMBIGUOUS\n");
        else cout<<"MMYY"<<endl;
    }
    else{
        if(1<=m && m<=12)pf("YYMM\n");
        else cout<<"NA"<<endl;
    }
    #ifdef VAMP
        printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    string a="abcdefghijklmnopqrstuvwxyz";
    for(int i=0;i<a.size();i++){
        if(s.find(a[i])==string::npos){
            cout << a[i] << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 4
#define N2 16
#define LIMIT 100
 
static const int dy[4] = { 1, 0, -1, 0};
static const int dx[4] = { 0, -1, 0, 1};
static const char dir[4] = { 'r', 'u', 'l', 'd'};
int MDT[N2][N2];
 
typedef struct p{
  int f[N2];
  int space;
  int MD;
} Puzzle;
 
Puzzle state;
int lim;
int path[LIMIT];
 
int getAllMD(Puzzle p){
  int sum=0, i;
  for( i = 0 ; i < N2 ; i++ ){
    if( p.f[i] == N2 ) continue;
    sum += MDT[i][p.f[i]-1];
  }
  return sum;
}
 
int isSolved(){
  int i;
  for( i = 0 ; i < N2 ; i++ ){
    if( state.f[i] != i+1 ) return 0;
  }
  return 1;
}
 
int dfs(int depth, int prev){
  int r;
  Puzzle tmp;
  if( state.MD == 0 ) return 1;
  if( depth + state.MD > lim ) return 0;
 
  int sx = state.space / N;
  int sy = state.space % N;
 
  for( r = 0 ; r < 4 ; r++ ){
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
    if( (fmax( prev, r ) - fmin( prev, r )) == 2 ) continue;
    tmp = state;
    state.MD -= MDT[tx * N + ty][state.f[tx * N + ty]-1];
    state.MD += MDT[sx * N + sy][state.f[tx * N + ty]-1];
    int t;
    t = state.f[tx * N + ty];
    state.f[tx * N + ty] = state.f[sx * N + sy];
    state.f[sx * N + sy] = t;
    state.space = tx * N + ty;
    if( dfs(depth+1,r) == 1 ){
      path[depth] = r;
      return 1;
    }
    state = tmp;
  }
  return 0;
}
 
char ans[1000];
 
int iterative_deepening(Puzzle in){
  int i;
 
  in.MD = getAllMD(in);
 
  for( lim = in.MD ; lim <= LIMIT ; lim++ ){
    state = in;
    if( dfs(0, -100) == 1 ){
      ans[0] = '\0';
      for( i = 0 ; i < lim ; i++ ) ans[i+1] = dir[path[i]];
      return i;
    }
  }
  ans[10] = '\0';
  return 10;
}
 
int main(){
  int i, j, ans;
 
  for( i = 0 ; i < N2 ; i++ ){
    for( j = 0 ; j < N2 ; j++ ){
      MDT[i][j] = fabs( i / N - j / N ) + fabs( i % N - j % N );
    }
  }
  Puzzle in;
  for( i = 0 ; i < N2 ; i++ ){
    scanf("%d",&in.f[i]);
    if( in.f[i] == 0 ){
      in.f[i] = N2;
      in.space = i;
    }
  }
  ans = iterative_deepening(in);
  printf("%d\n",ans);
 
  return 0;
}



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

int main() {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if(0 > x - r || 0 > y - r ||W < x + r ||H < y + r){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3100
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    console.log(1000* (Math.ceil(n/1000)) - n)

}
Main()


Measured memory_bytes: 29696
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,a[100];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    int m=0,sum=0;
    for(int i=0;i<n;i++){
        if(m<=a[i]) sum++;
        m=max(m,a[i]);
    }
    cout<<sum;
}


Measured memory_bytes: 256
import sys
import time
from operator import itemgetter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, readline().split())
    A = list(map(int, readline().split()))
    BC = []
    for _ in range(M):
        B, C = map(int, readline().split())
        BC.append((B,C))
    BC.sort(key=itemgetter(1), reverse=True)
    BC.append((N,-1))
    change = []
    for b,c in BC:
        change += [c]*b
        if len(change) > N:
            break
    A += change
    A.sort()
    answer = sum(A[-N:])
    print(answer)




if __name__ == '__main__':
    main()

Measured memory_bytes: 25988
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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(a > b){a = b; return 1;} return 0;}

bool comp(const Pl &a, const Pl &b){
  if(a.first != b.first)return a.first < b.first;
  else return a.second < b.second;
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<Pll> vec(n);
  rep(i, n)cin >> vec[i].first >> vec[i].second;
  if(n == 1){
    cout << 0 << endl;
    return 0;
  }
  ll ma = -1, mi = linf;
  int mai = 0, mii = 0;
  rep(i, n){
    if(ma < vec[i].first){
      ma = vec[i].first;
      mai = i;
    }
    if(ma < vec[i].second){
      ma = vec[i].second;
      mai = i;
    }
    if(mi > vec[i].first){
      mi = vec[i].first;
      mii = i;
    }
    if(mi > vec[i].second){
      mi = vec[i].second;
      mii = i;
    }
  }
  ll rma = ma, bmi = mi;
  ll rmi = linf, bma = -1;
  if(mai != mii){
    rmi = vec[mii].first + vec[mii].second - mi;
    bma = vec[mai].first + vec[mai].second - ma;
  }
  rep(i, n){
    if(i != mai && i != mii){
      ll fi = vec[i].first, se = vec[i].second;
      if(fi > se)swap(fi, se);
      chmax(bma, fi);
      chmin(rmi, se);
    }
  }
  ll res1 = (rma - rmi) * (bma - bmi);
  if(mai == mii){
    cout << res1 << endl;
    return 0;
  }

  set<Pl> b;
  b.insert(mk(vec[mii].first + vec[mii].second - mi, -1));
  b.insert(mk(vec[mai].first + vec[mai].second - ma, -1));
  rep(i, n){
    if(i != mai && i != mii){
      b.insert(mk(min(vec[i].first, vec[i].second), i));
    }
  }
  while(true){
    Pl mini = *(b.begin());
    Pl maxi = *(b.rbegin());
    if(mini.second < 0)break;
    ll sec = vec[mini.second].first + vec[mini.second].second - mini.first;
    auto itr = b.begin();
    ++itr;
    if(maxi.first >= sec || maxi.first - mini.first >= sec - itr->first){
      b.erase(b.begin());
      b.insert(mk(sec, -1));
    }else{
      break;
    }
  }
  ll res2 = (b.rbegin())->first - (b.begin())->first;
  cout << min(res1, res2 * (ma - mi)) << endl;
	return 0;
}


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

#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5 + 5;

ll N, K, S, A[MAXN];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K >> S;
	if(S == (ll)1e9) {
		for(int i=1; i<=K; i++) A[i] = S;
		for(int i=K+1; i<=N; i++) A[i] = 1;
	}
	else {
		for(int i=1; i<=K; i++) A[i] = S;
		for(int i=K+1; i<=N; i++) A[i] = 1e9;
	}
	for(int i=1; i<=N; i++) cout << A[i] << ' ';
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
/*#define mod 1000000007
//#define int long long int
#define INF 1e9+100
#define pair<int,int> pii
#define ff first
#define ss second
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define fi(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define pb push_back
#define  debug(x)  cout<<#x<<" "<<x<<endl;*/
int main()
{
  int n,i,j,k;
  int t;
  int m;
  cin>>n;
  int a[n+3];
  for(i=0;i<n;i++) cin>>a[i];
  int cnt=0;
  for(i=0;i<n-1;i++)
  {
  	for(j=0;j<n-1-i;j++)
	{
		if(a[j]>a[j+1])
		{
			a[j]+=a[j+1];
			a[j+1]=a[j]-a[j+1];
			a[j]=a[j]-a[j+1];
			cnt++;
		}
	}
  }
  for(i=0;i<n-1;i++) cout<<a[i]<<" ";
  cout<<a[n-1];
  cout<<endl;
  cout<<cnt<<endl;
}



Measured memory_bytes: 3100
#include <stdio.h>
int main(void){
  int x=0,n,ans=0,i;
  char s[101];
  scanf("%d",&n);
  scanf("%s",s);
  for(i=0;i<n;i++){
    if(s[i]=='I')
      x++;
    else
      x--;
    if(x>ans)
      ans=x;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define  N 666666
int a[N];

signed main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0){
			ans+=i;
		}
	}cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, K; long long dp[109][2]; bool vis[109][2];
long long solve(int pos, int col) {
	if (vis[pos][col]) return dp[pos][col];
	long long ret = (col == 1 ? 1 : 0);
	if (pos < N) ret += solve(pos + 1, col ^ 1);
	if (pos <= N - K && col == 0) ret += solve(pos + K, col ^ 1);
	vis[pos][col] = true;
	dp[pos][col] = ret;
	return ret;
}
int main() {
	cin >> N >> K;
	cout << solve(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 3120
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << endl;
}

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

int main(){
  int N;
  cin >> N;
  int Ans=0;
  int Max=0;
  int H;
  for(int i=0; i<N; i++){
    cin >> H;
    if(H>=Max){
      Ans++;
      Max=H;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

def check(l,c):
    if l[c[1]-1] - l[c[0]-1] == c[2]:
        return True
    else:
        return False

n,m,q = LI()
li = LLI(q)
num = [i for i in range(1,m+1)]
a =  list(itertools.combinations_with_replacement(num, n))
ans = 0
ans_li = []
for suuretsu in a:
    ans = 0 #数列を1つ決める
    for ch in li: #チェックしたいやつを決める
        if check(suuretsu,ch):
            ans += ch[3]
    ans_li.append(ans)
print(max(ans_li))


Measured memory_bytes: 26056
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  rep(i, 0, s.size()) {
    if (i == 5 || i == 13)
      cout << " ";
    else
      cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<stack>
#include<math.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vint;
typedef vector<ll> vll;

int main(){
    ll a,b,c,n;
    cin>>n;

    for(a=1; a<3501; a++){
        for(b=1; b<=a; b++){
            if(fmod(a*b*n,4*a*b-b*n-a*n)==0){
                c=(a*b*n)/(4*a*b-b*n-a*n);
                if(c>0){
                    cout<<a<<" "<<b<<" "<<c<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n, q; cin >> n >> q;
  queue<pair<string, int>> que;
  rep(_, n) {
    string s;
    int t;
    cin >> s >> t;
    que.push({s, t});
  }
  int sum = 0;
  vector<pair<string, int>> ans;
  while (!que.empty()) {
    string s;
    int t;
    tie(s, t) = que.front(), que.pop();
    if (t > q) t -= q, sum += q, que.push({s, t});
    else {
      ans.push_back({s, sum + t});
      sum += t;
    }
  }
  rep(i, n) {
    cout << ans[i].first << " " << ans[i].second << '\n';
  }
}



Measured memory_bytes: 7124
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll n,m,x; cin >> n >> m >> x;
    vector<ll> cost(n);
    vector<vector<ll>> a(n,vector<ll>(m,0));
    rep(i,n){
        cin >> cost.at(i);
        rep(j,m){
            cin >> a.at(i).at(j);
        }
    }
    ll mincost = INF;
    for(int i=0;i<(1<<n);i++){
        bitset<12> z(i);
        vector<ll> skill(m,0);
        ll cost_i = 0;
        rep(j,12){ //j番目の参考書
            if(z.test(j)){
                cost_i += cost.at(j);
                rep(k,m){ //k番目のスキルについて
                    skill.at(k) += a.at(j).at(k);
                }
            }
        }
        bool ok = true;
        rep(j,m){
            if(skill.at(j)<x) ok = false;
        }
        if(ok){
            mincost = min(mincost,cost_i);
        }
    }
    if(mincost==INF){
        cout << -1 << endl;
    }else{
        cout << mincost << endl;
    }
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    vector<int> X(3);
    REP(i,3) cin>>X[i];
    sort(ALL(X));
    int biggest = X[2];
    int sum = X[0] + X[1] + X[2];
    int same;
    int ans;
    if (biggest*3 % 2 == sum % 2) {
        ans = (biggest * 3 - sum) / 2;
    }
    else {
        ans = (biggest * 3 + 3 - sum) / 2;
    }
    cout<<ans<<endl;
    return 0;
}

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

const int N = 1e5 + 5;
int n, a[3*N];
long long b[N], c[N];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    for (int i = 1; i <= 3*n; i++){
        cin>>a[i];
    }
    
    
    priority_queue<long long , vector<long long >, greater<long long > > qg;  // 小顶堆，越来越大
    priority_queue<long long , vector<long long>, less<long long> > ql;     // 大顶堆
    
    
    long long  sum = 0;
    
    for (int i = 1; i <= n; i++){
        qg.push(a[i]);
        sum += a[i];
    }
    
    b[0] = sum;
    for (int i = 1; i <= n; i++){
        int base = n;
        if(qg.top() < a[i+base]){
            int popv = qg.top();
            qg.pop();
            qg.push(a[i+base]);
            sum -= popv;
            sum += a[i+base];
        }
        b[i] = sum;
    }
    
    
    sum = 0;
    for (int i = 3*n; i >= 2*n+1; i--){
        ql.push(a[i]);
        sum += a[i];
    }
    
    c[n+1] = sum;
    for (int i = 1; i <= n; i++){
        int base = 2*n+1;
        if(ql.top() > a[base-i]){
            int popv = ql.top();
            ql.pop();
            ql.push(a[base-i]);
            sum -= popv;
            sum += a[base - i];
        }
        c[n+1-i] = sum;
    }
    
    long long maxv = -1e15;
    for (int i = 0; i <= n; i++){
        maxv = max(maxv, b[i] - c[i+1]);
    }
    cout<<maxv<<endl;
    
 
    
    return 0;
}



Measured memory_bytes: 4724
# encoding:utf-8
 
def main():
	n = int(input())
	nums = list(map(int, input().split()))

	ans = 0
	flag = 0
	for i in range(n - 1):

		if flag == 1:
			flag = 0
			continue

		if nums[i + 1] == nums[i]:
			ans += 1
			flag = 1


	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int m = kbd.nextInt();
	    int n = kbd.nextInt();
	    if(m!=0 && n!=0){
		int c;
		int max=0;
		for(int i=0; i<m; i++){
			c=0;
			for(int j=0; j<n; j++){
			    int x =kbd.nextInt();
			    if(x==1) c++;
			}
			if(c>max) max = c;
		}
		System.out.println(max);
	    }
	}
    }
}

Measured memory_bytes: 12000
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();
	String S = sc.next();
	for(int i=0;i<N;i++){
	    if(i!=K-1){
		System.out.print(S.charAt(i));
	    }else{
		char sk = S.charAt(i);
		if(sk=='A') System.out.print('a');
		else if(sk=='B') System.out.print('b');
		else System.out.print('c');
	    }
	}
    }
}


Measured memory_bytes: 21460
H,W=map(int,input().split())
row=[False]*H
col=[False]*W
b=['']*H
for i in range(H):
  a=input()
  b[i]=a
  for j in range(W):
    if a[j]=='#':
      row[i]=True
      col[j]=True
for i in range(H):
  if row[i]:
    for j in range(W):
      if col[j]:
        if row[i] and col[j]:
          print(b[i][j],end='')
    print()

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define rep2(i,a,n) for (int i = a; i < n; i++)
using namespace std;
int main() {
    int N; cin >> N;
    int P[N], Q[N];
    int arr[N];
    rep(i, N) {
        cin >> P[i];
        arr[i] = i + 1;
    }
    rep(i, N) cin >> Q[i];
    int p;
    int q;
    int num = 1;
    do {
        bool p_flag = true;
        rep(i, N) {
            if (P[i] != arr[i]) p_flag = false;
        }
        if (p_flag) p = num;
        bool q_flag = true;
        rep(i, N) {
            if (Q[i] != arr[i]) q_flag = false;
        }
        if (q_flag) q = num;
        num++;

    } while (next_permutation(arr, arr + N));
    printf("%d\n", abs(p - q));


    return 0;
}


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

#define ll long long

using namespace std;

const ll maxn = 2*(ll)1e5+100;
ll n, d;
struct node {
    ll x, y;
}po[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> n >> d;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> po[i].x >> po[i].y;
        if (po[i].x * po[i].x + po[i].y * po[i].y <= d * d) ++ans;
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 6736
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
int arr[] = new int[5];
for(int i=0; i<arr.length; i++){
arr[i] = sc.nextInt();
}
for(int i=0; i<arr.length; i++){
if(arr[i] == 0){
System.out.print(i+1);
}
//System.out.println();
}
}
}

Measured memory_bytes: 35676
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int main()
{
    int n;
    cin >> n;
    ll a[100002];
    P p[100002];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        p[i] = P(a[i], i);
    }
    sort(p, p + n);
    int les = 0;
    for(int i = 0; i < n - 1; i++){
        if(p[i].first * 2 < p[i + 1].first) les = i + 1;
        p[i + 1].first += p[i].first;
    }
    cout << n - les << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
 
int main(void){
   int n,i,t=0;
   scanf("%d",&n);
   int l[n],r[n];
 
   for(i=0;i<n;i++)
      scanf("%d%d",&l[i],&r[i]);
 
   for(i=0;i<n;i++){
      t+=r[i]-l[i]+1;
   }
 
   printf("%d\n",t);
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;

#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define R(i,n) for(int i=0;i<(n);++i)
#define fill(a,b) memset(a,b,sizeof(a))

const int maxn = 1010;
int cnt[4];
char s[maxn];

int main()
{
	//freopen("test.txt","r",stdin);
	scanf("%s",s);
	R(i,strlen(s))
	{
		if(s[i] == 'E') cnt[0]++;
		if(s[i] == 'S') cnt[1]++;
		if(s[i] == 'W') cnt[2]++;
		if(s[i] == 'N') cnt[3]++;
	}
	R(i,2)
	if((!cnt[i] && cnt[i+2]) || (cnt[i] && !cnt[i+2]))
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int solve(int N) {
    vector<string> vs(N);
    char vowel[] = {'a', 'i', 'u', 'e', 'o'};
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        string parsed;
        for (int j = 0; j < s.length(); j++) {
            if (j == 0) {
                parsed.push_back(s[j]);
                continue;
            }
            for (int k = 0; k < 5; k++) {
                if (vowel[k] == s[j-1]) {
                    parsed.push_back(s[j]);
                    break;
                }
            }
        }
        vs[i] = parsed;
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            for (int k = 0; k < vs[i].length() && k < vs[j].length(); k++) {
                ans = max(k+1, ans);
                if (vs[i][k] != vs[j][k]) {
                    break;
                }
                if (k == vs[i].length() - 1 || k == vs[j].length() - 1) {
                    if (vs[i].length() == vs[j].length()) {
                        ans = 100;
                    } else {
                        ans = max(k+2, ans);
                    }
                }
            }   
        }
    }

    if (ans == 100) ans = -1;
    return ans;
}

int main(void) {
    int N;
    vector<int> ans;
    while (1) {
        cin >> N;
        if (!N) break;
        ans.push_back(solve(N));
    }
    for (auto &i : ans) {
        cout << i << endl;
    }
}   


Measured memory_bytes: 3144