akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T = int>
void print(vec<T> v){ for (T item: v) { cout << item << " "; } cout << endl; }

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"Yes":"N1010o"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

void Main() {
    //code here
    int n = gi, y = gi;
    ZeroToN(i1, n) {
        ZeroToN(i2, n-i1) {
            int i3 = (n-i1-i2);
            if (i1 * 10000 + i2 * 5000 + i3 * 1000 == y) {
                print(to_string(i1) + " " + to_string(i2) + " " + to_string(i3));
                return;
            }
        }
    }
    print("-1 -1 -1");
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	char a[N + 1];
	char b[10];
	f(i, N + 1)a[i] = 0;
	b[0] = 'k';
	b[1] = 'e';
	b[2] = 'y';
	b[3] = 'e';
	b[4] = 'n';
	b[5] = 'c';
	b[6] = 'e';
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%s", a);
	n = strlen(a);
	f(i, 8){
		v = true;
		f(j, i)if (a[j] != b[j])v = false;
		f(j, 7 - i)if (a[n - 7 + i + j] != b[i + j])v = false;
		if (v){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n", ans);
	
	return 0;
}

Measured memory_bytes: 384
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def main():
    s = list(input())
    count = Counter(s)

    if max(count['a'], count['b'], count['c']) - min(count['a'], count['b'], count['c']) <= 1:
        print('YES')
    else:
        print('NO')




if __name__ == '__main__':
    main()
    # test()



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

struct euler_tour{
  int r;
  int n;
  vector<vector<int>> adj;
  vector<int> dep;
  vector<int> tour;
  vector<int> Lid,Rid;
  euler_tour(){}
  euler_tour(vector<vector<int>> const& adjacent_list,int root=0){
    init(adjacent_list,root);
  }
  void init(vector<vector<int>> const& adjacent_list,int root=0){
    adj = adjacent_list;
    r = root;
    n = adjacent_list.size();
    dep.reserve(2*n-1);
    tour.reserve(2*n-1);
    Lid.resize(n);
    Rid.resize(n);
    int k = 0;
    dfs(r,-1,0,k);
  }
  void dfs(int cur,int prv,int depth,int& idx){
    Lid[cur] = idx++;
    dep.emplace_back(depth);
    tour.emplace_back(cur);
    for(auto const& nxt:adj[cur]){
      if(nxt==prv)continue;
      dfs(nxt,cur,depth+1,idx);
      dep.emplace_back(depth);
      tour.emplace_back(cur);
    }
    Rid[cur] = idx++;
  }
  void dump(){
    cout<<" Lid : "<<endl;
    for(auto x:Lid){
      cout<<x<<" ";
    }cout<<endl;
    cout<<" Rid : "<<endl;
    for(auto x:Rid){
      cout<<x<<" ";
    }cout<<endl;
    cout<<"tour : "<<endl;
    for(auto x:tour){
      cout<<x<<" ";
    }cout<<endl;
    cout<<" dep : "<<endl;
    for(auto x:dep){
      cout<<x<<" ";
    }cout<<endl;
  }
};

template<class T,class F>
struct segtree{
  int n;
  T e;
  F f;
  std::vector<T> dat;

  segtree(){}
  segtree(int sz,T _e,F _f):e(_e),f(_f){
    n = 1;
    while(n<=sz)n<<=1;
    dat.resize(2*n,e);
  }
  segtree(std::vector<T> const& v,T _e,F _f):e(_e),f(_f){
    build(v);
  }
  void build(std::vector<T> const& v){
    n = 1;
    int sz = v.size();
    while(n<=sz)n<<=1;
    dat.resize(2*n,e);
    for(int i=0;i<sz;++i){
      dat[i+n] = v[i];
    }
    for(int i=n-1;i>0;--i){
      dat[i] = f(dat[i<<1],dat[i<<1|1]);
    }
  }
  void set(int p,T v){
    for(dat[p+=n]=v;p>1;p>>=1){
      dat[p>>1] = f(dat[p],dat[p^1]);
    }
  }
  T query(int l,int r){
    T res = e;
    for(l+=n,r+=n;l<r;l>>=1,r>>=1){
      if(l&1){
        res = f(res,dat[l]);
        l++;
      }
      if(r&1){
        r--;
        res = f(res,dat[r]);
      }
    }
    return res;
  }
  T operator[](int k){
    return query(k,k+1);
  }
};

template<class T,class U>
vector<pair<T,U>> paired(vector<T> const& t,vector<U> const& u){
  size_t n = t.size();
  size_t m = u.size();
  assert(n==m);
  vector<pair<T,U>> res(n);
  for(int i=0;i<n;++i){
    res[i] = {t[i],u[i]};
  }
  return res;
}

signed main(){

  int n;
  cin>>n;
  vector<vector<int>> adj(n);
  for(int i=0;i<n;++i){
    int k;cin>>k;
    adj[i].resize(k);
    for(auto& a:adj[i])cin>>a;
  }
  euler_tour et(adj);
  auto sum = [](int a,int b){return a+b;};
  segtree<int,decltype(sum)> tree(2*n,0,sum);

  int q;
  cin>>q;
  while(q--){
    int c;cin>>c;
    if(c==0){
      int v,w;cin>>v>>w;
      int lv = et.Lid[v];
      int rv = et.Rid[v];
      tree.set(lv,tree[lv]+w);
      tree.set(rv,tree[rv]-w);
    }
    if(c==1){
      int u;cin>>u;
      u = et.Lid[u];
      cout<< tree.query(0,u+1) <<endl;
    }
  }

}


Measured memory_bytes: 21528
from itertools import combinations 

N = int(input())
d = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
ans = 0
for _ in range(N):
    s = input()
    head = s[0]
    if d.get(head) != None:
        d[head] += 1

for chars in combinations("MARCH", 3):
    ans += d[chars[0]] * d[chars[1]] * d[chars[2]]
print(ans)


Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let mut h = read_vec::<i64>();
    if k > n {
        println!("0");
        return;
    }
    h.sort();
    let mut ans = 0;
    for i in 0..n - k {
        ans += h[i];
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 13560
N, K = [int(_) for _ in input().split()]
D = [int(_) for _ in input().split()]
for i in range(N, 100000):
    is_possible = True
    for d in D:
        if str(d) in str(i):
            is_possible = False
            break
    if is_possible:
        print(i)
        exit()


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec pv(N), qv(N);
    rep(i, N) cin >> pv[i];
    rep(i, N) cin >> qv[i];

    vec a = pv;
    sort(all(a));

    int aa=0, bb=0, idx=0;
    do{
        bool af=true, bf=true;
        rep(i, N){
            if(a[i] != pv[i]) af=false;
            if(a[i] != qv[i]) bf=false;
        }
        if(af) aa = idx;
        if(bf) bb = idx;
        idx++;
    }while(next_permutation(all(a)));

    cout << abs(aa-bb) << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

#define MAXN    103
#define MAXL    16

int main()
{
    int n, i, j;
    char s[MAXN][MAXL], last_char;
    scanf("%d", &n);
    for (i = 0; i < n; ++i) {
        scanf("%s", s[i]);
        if (i != 0 && last_char != s[i][0]) {
            puts("No"); return 0;
        }
        for (j = 0; j < i; ++j)
            if (strcmp(s[i], s[j]) == 0) {
                puts("No"); return 0;
            }
        last_char = s[i][strlen(s[i]) - 1];
    }
    puts("Yes"); return 0;
}


Measured memory_bytes: 128
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()


Measured memory_bytes: 7000
import collections

n=int(input())
a=list(map(int, input().split()))

d = collections.Counter(a)
s = sum(a)
n1, n2, n3 = d[1], d[2], d[3]

dp = [[0]*(n2+n3+1) for _ in range(n3+1)]
dp[n3][n2] = 1.0
ans = 0

for i in range(s, 0, -1):
  dp2 = [[0]*(n2+n3+1) for _ in range(n3+1)]
  for i3 in range(n3, -1, -1):
    for i2 in range(min(n2+n3, (i-i3*3)//2), -1, -1):
      i1 = i-i3*3-i2*2
      i0 = n-i1-i2-i3
      if i2 < 0 or i1 < 0 or i0 < 0: continue
      e0 = n/(i1+i2+i3)
      dp2[i3][i2] += dp[i3][i2] * i1/(i1+i2+i3)
      ans += dp[i3][i2] * e0*(i1/(i1+i2+i3))
      if i2 > 0:
        dp2[i3][i2-1] += dp[i3][i2] * i2/(i1+i2+i3)
        ans += dp[i3][i2] * e0*(i2/(i1+i2+i3))
      if i3 > 0 and i2 < n2+n3:
        dp2[i3-1][i2+1] += dp[i3][i2] * i3/(i1+i2+i3)
        ans += dp[i3][i2] * e0*(i3/(i1+i2+i3))
  dp = dp2

print(ans)


Measured memory_bytes: 132488
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif

	int a, b;
	int x, y;

	cin >> a >> b;

	x = 2 * a + 2 * b;
	y = a * b;

	cout << y << " " << x << endl;


	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
string s;
void solve(){
    int n;
     cin>>n;
     int ar[n];
     ll x=0;
     f(i,0,n)cin>>ar[i],x=x^ar[i];
     f(i,0,n){
     	
     	cout<<(x^ar[i])<<" ";
     }
    
  
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();
 
    
}


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

int main(){
  // input
  int N, i, k = 0, n = 2;
  bool div = true;
  cin >> N;
  int A[N];
  for ( i = 0; i < N; i++)
  {
    cin >> A[i];
  }

  //manipulate
  while (div)
  {
    for ( i = 0; i < N; i++)
    {
      if (A[i] % n != 0)
      {
        div = false;
        break;
      }
    }
    if (div)
    {
      k++;
      n *= 2;
    }else
    {
      break;
    }
  }

  cout << k << endl;
}


Measured memory_bytes: 3560
#include"bits/stdc++.h"
using namespace std;

int main(){
	int N;
	cin >> N;
	for (int i = 1;i < 10;++i) {
		if ((i - 1) * 111 < N && N <= i * 111) {
			cout << i << i << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int N, i, recently, ans;
  recently = 0;
  ans = 0;
  scanf("%d", &N);
  int A[N + 1];
  int B[N + 1];
  int C[N];
  for (i = 1; i < N + 1; ++i) {
    scanf("%d", &A[i]);
  }
  for (i = 1; i < N + 1; ++i) {
    scanf("%d", &B[i]);
  }
  for (i = 1; i < N; ++i) {
    scanf("%d", &C[i]);
  }
  ans += B[A[1]];
  recently = A[1];
  for (i = 2; i < N + 1; ++i) {
    ans += B[A[i]];
    if (recently == A[i] - 1) {
      ans += C[A[i]-1];
    }
    recently = A[i];
  }
  printf("%d\n", ans);
  return 0;
}

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

int main()
{
    int n = 0;
  	int j = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
      	j = 0;
        if (i % 3 == 0)
        {
            cout << " " << i;
            continue;
        }
      	j = i;
        while (j != 0)
        {    
            if(j % 10 == 3)
            {
                cout << " " << i;
                break;
            }
          	j = j / 10;
        }
        continue;
    }
    cout << endl;
}


Measured memory_bytes: 3088
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
typedef struct {
	int d0;
	int d1;
	int d2;
	int d3;
	int d4;
	int d5;
}DICE;

int DiceRoll(DICE[], int);
void Dice(char p, DICE[], int);
int Count(DICE[], int);

int main() {
	DICE d[100];
	int i = 0, flg = 0, n;
	char str[2][4] = { "Yes" ,"No" };
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d%d%d%d%d%d", &d[i].d0, &d[i].d1, &d[i].d2, &d[i].d3, &d[i].d4, &d[i].d5);
	for (i = 1; flg == 0&&i < n; i++) flg = DiceRoll(d, i);
	if (flg) { printf("No\n"); return 0; }
	printf("Yes\n");
	return 0;
}

int DiceRoll(DICE d[], int i)
{
	int j, l, iSum, jSum;
	
		for (j = 0; j < i; j++) {
			iSum = d[i].d0 + d[i].d1 + d[i].d2 + d[i].d3 + d[i].d4 + d[i].d5;
			jSum = d[j].d0 + d[j].d1 + d[j].d2 + d[j].d3 + d[j].d4 + d[j].d5;
			if (jSum == iSum) {
			if (d[j].d5 == d[i].d0) Dice('N', d, j), Dice('N', d, j);
			else if (d[j].d1 == d[i].d0) Dice('N', d, j);
			else if (d[j].d4 == d[i].d0) Dice('S', d, j);
			else if (d[j].d2 == d[i].d0) Dice('W', d, j);
			else if (d[j].d3 == d[i].d0) Dice('E', d, j);
			if (d[j].d0 == d[i].d0) {
				for (l = 0; l < 4; l++) {
					if (d[j].d1 == d[i].d1)if (d[i].d2 == d[j].d2&&d[i].d3 == d[j].d3&&d[i].d4&&d[j].d4&&d[i].d5 == d[j].d5)  return 1;
					Dice('L', d, j);
				}
			}
			if (Count(d, i) >= 10 && Count(d, j) >= 10) return 1;
		}
	}
	return 0;
}

void Dice(char p, DICE d[], int n) {
	int tmp;
	if (p == 'S') { tmp = d[n].d0; d[n].d0 = d[n].d4; d[n].d4 = d[n].d5; d[n].d5 = d[n].d1; d[n].d1 = tmp; }
	if (p == 'W') { tmp = d[n].d0; d[n].d0 = d[n].d2; d[n].d2 = d[n].d5; d[n].d5 = d[n].d3; d[n].d3 = tmp; }
	if (p == 'E') { tmp = d[n].d0; d[n].d0 = d[n].d3; d[n].d3 = d[n].d5; d[n].d5 = d[n].d2; d[n].d2 = tmp; }
	if (p == 'N') { tmp = d[n].d0; d[n].d0 = d[n].d1; d[n].d1 = d[n].d5; d[n].d5 = d[n].d4; d[n].d4 = tmp; }
	if (p == 'L') { tmp = d[n].d1; d[n].d1 = d[n].d3; d[n].d3 = d[n].d4; d[n].d4 = d[n].d2; d[n].d2 = tmp; }
}

int Count(DICE d[], int n) {
	int cnt = 0;
	if (d[n].d0 == d[n].d1)++cnt;
	if (d[n].d0 == d[n].d2)++cnt;
	if (d[n].d0 == d[n].d3)++cnt;
	if (d[n].d0 == d[n].d4)++cnt;
	if (d[n].d0 == d[n].d5)++cnt;
	if (d[n].d1 == d[n].d2)++cnt;
	if (d[n].d1 == d[n].d3)++cnt;
	if (d[n].d1 == d[n].d4)++cnt;
	if (d[n].d1 == d[n].d5)++cnt;
	if (d[n].d2 == d[n].d3)++cnt;
	if (d[n].d2 == d[n].d4)++cnt;
	if (d[n].d2 == d[n].d5)++cnt;
	if (d[n].d3 == d[n].d4)++cnt;
	if (d[n].d3 == d[n].d5)++cnt;
	if (d[n].d4 == d[n].d5)++cnt;
	return cnt;
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;
  cin>>n;
  string s[n];
  rep(i,n)cin>>s[i];
  int ans=0;
  rep(i,n){
    bool ok=true;
    rep(j,n)rep(k,n){
      if(s[(i+j)%n][k]!=s[(k+i)%n][j])
        ok=false;
      }
    if(ok)ans+=n;
    }
  cout<<ans<<endl;
  return 0;
  }

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

#define ll long long
#define ar array

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

#define E_ACH2(x, a) for (auto& x: a)
#define E_ACH3(x, y, a) for (auto& [x, y]: a)
#define E_ACH4(x, y, z, a) for (auto& [x, y, z]: a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...) E_ACHC(__VA_ARGS__)(__VA_ARGS__)

const int mxN=2e5;
int n;
vector<int> adj[mxN];
ll ans;

void dfs(int u=0, int p=-1) {
	for(int v : adj[u])
		if(v^p)
			dfs(v, u);
	if(u) {
		if(p<u)
			ans+=(ll)(u-p)*(n-u);
		else
			ans+=(ll)(u+1)*(p-u);
	} else
		ans+=n;
}

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

	cin >> n;
	for(int i=1, u, v; i<n; ++i) {
		cin >> u >> v, --u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs();
	cout << ans;
}

Measured memory_bytes: 23924
n = int(input())
a = [list(map(int, input().split())) for _ in range(n - 1)]

for i in range(n - 1):
    t = a[i][0] + a[i][1]
    for j in range(i + 1, n - 1):
        b = (t - a[j][1]) % a[j][2]
        if(b != 0):
            t += a[j][2] - b
        if(t < a[j][1]):
            t = a[j][1]
        t += a[j][0]
    print(t)
print(0)

Measured memory_bytes: 3188
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
from scipy.sparse.csgraph._shortest_path import dijkstra, floyd_warshall, bellman_ford, johnson, shortest_path
from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,x,y = map(int,input().split())

length = n
d = [1 for _ in range(n)]
i = list(range(0,n-1)) + [x-1]
j = list(range(1,n)) + [y-1]
# print(d,i,j,sep="\n")

graph = csr_matrix((d, (i, j)), shape=(n, n)) # 頂点i,jはゼロスタートである必要ある
# print(type(csr),csr,sep="\n")

#返り値は各頂点間の距離の値を含んだ隣接行列(float64型のnp.array)
dist = dijkstra(graph, directed=False).astype(int)
# dist = shortest_path(graph, directed=False).astype(int)
# print(type(dist),dist,sep="\n")

dist = dist.ravel() #配列の一次元化
# print(type(dist),dist,sep="\n")

ans = np.bincount(dist, minlength=n) // 2  #bincountは[0の個数,1の個数,2の個数…nの個数]を返す
# print(type(ans),ans,sep="\n")

print(*ans[1:], sep='\n')

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

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

  int ans = 700;
  if (S.at(0) == 'o')
    ans += 100;
  if (S.at(1) == 'o')
    ans += 100;
  if (S.at(2) == 'o')
    ans += 100;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

Weight minimum_spanning_tree(const Graph &g, size_t s=0) {
    /* Prim */
    size_t V=g.size();
    Edges T;
    Weight total=0;
    vector<Weight> d(V, INF); d[s]=0;
    vector<bool> visited(V);

    lp_queue<pair<Weight, size_t>> q; q.push(make_pair(0, s));
    while (!q.empty()) {
        pair<Weight, size_t> p=q.top(); q.pop();
        size_t v=p.second;
        if (visited[v]) continue;


        visited[v] = true;
        total += d[v];
        for (const Edge &e: g[v])
            if (d[e.dst] > e.weight) {
                d[e.dst] = e.weight;
                q.push(make_pair(d[e.dst], e.dst));
            }
    }
    return total;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight w;
        scanf("%zu %zu %lld", &s, &t, &w);

        join(g, s, t, w);
    }

    printf("%lld\n", minimum_spanning_tree(g));
    return 0;
}

Measured memory_bytes: 10700
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {

    int k,n;
    cin>>n>>k;
    int arr[n];
    long long ssum=0;
    long long m=0;
    for(int i=0;i<n;++i){
        cin>>arr[i];
        ssum+=arr[i];
        m= max(m,arr[i]);
    }
    sort(arr, arr+n);
    int ans=0;
    if(n<=k){
        cout<<0<<endl;
    }else{
        if(k==0){
            cout<<ssum<<endl;
        }else{
            for(int i=0;i<(n-k);++i){
                ans+=arr[i];
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
        while(sc.hasNext()){
                int r0 = sc.nextInt();
                int w0 = sc.nextInt();
                int c = sc.nextInt();
                int r = sc.nextInt();
                if(r0+w0+c+r == 0)break;
                
                int need = 0;
                for(int i=0;;i++) {
                	if((r0+i*r)/c >= w0) {
                		need = i;
                		break;
                	}
                }
                System.out.println(need);
        }
        }
    }
}



Measured memory_bytes: 26360
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    int X;
    cin >> X;

    int ret = 0;
    while(X>=500) {
        ret += 1000;
        X-=500;
    }
    while(X>=5) {
        ret += 5;
        X-=5;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=20,M=2e6,inf=1e9;
int n,a[N],b[N],mx,f[N][M],bit[M],ans=1e9;
void cmin(int &x,int y){y<x?x=y:0;}
int main(){
	scanf("%d",&n);mx=1<<n;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);
	for(int i=0;i<n;i++)if(i&1)swap(a[i],b[i]);
	for(int i=1;i<mx;i++)bit[i]=bit[i>>1]+(i&1);
	memset(f,0x3f,sizeof(f));
	for(int i=0;i<n;i++)f[i][1<<i]=0;
	for(int i=1;i<mx;i++)
		for(int j=n-1,l=0;~j;j--)
			if(!(i>>j&1)){
				int y=bit[i]&1?b[j]:a[j];
				for(int k=0;k<n;k++)if(i>>k&1){
					int x=bit[i]&1?a[k]:b[k];
					if(x<=y)cmin(f[j][i^1<<j],f[k][i]+l);
				}
			}
			else l++;
	for(int i=0;i<n;i++)cmin(ans,f[i][mx-1]);
	if(ans>n*n)puts("-1");
	else printf("%d\n",ans);
}

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

// macros
#define overload_rep(_1, _2, _3, name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations
typedef long long ll;

void answer(ll a, ll b, ll c){
    cout << a << ' ' << b << ' ' << c << '\n';
}

// solve
int main(){

    ll N, K;
    cin >> N >> K;

    if(N < 2 * K - 1){
        cout << "-1\n";
        return 0;
    }

    ll a = K + (N - 1) / 2, b = K + 2 * N - 1, c = K + 3 * N - 1;
    while(a >= K){
        answer(a, b, c);
        a--; b--; c -= 2;
    }

    a = K + N - 1; b = K + 2 * N - (N - 1) / 2 - 2; c = K + 3 * N - 2;
    while(c >= K + 2 * N){
        answer(a, b, c);
        a--; b--; c -= 2;
    }

}


Measured memory_bytes: 2304
N,K=map(int,input().split())
p=list(map(int,input().split()))
a=0
for j in range(K):
    a+=(1+p[j])/2
Max=a
for i in range(K,N):
    a=a+(p[i]-p[i-K])/2
    if Max<a:
        Max=a
print(Max)

Measured memory_bytes: 24808
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    ll ans=0;
    n--;
    while(n){
        ans++;
        n/=3;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3116
#include<iostream>
using namespace std;
int main ( ){
    long long int n;cin>>n;
    long long int a[n],b[n],k1,k2;
    for (long long int i=0;i<n;i++) cin>>a[i];
    b[0]=0;
    b[1]=abs(a[1]-a[0]);
    for (long long int j=2;j<n;j++) {
        k1=abs(a[j]-a[j-1]);
         k2=abs(a[j]-a[j-2]);
        b[j]=min(b[j-1]+k1,k2+b[j-2]);
        
    }
    cout<<b[n-1]<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] dp = new int[n+1];

        for (int i = 0; i <= n; i++) {
            dp[i] = (int) 1e8;
        }

        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            dp[i] = Math.min(dp[i], dp[i - 1] + 1);
            if (i < 6) { continue; }
            for (int k = 6; k <= n; k *= 6) {
                if (i - k >= 0) {
                    dp[i] = Math.min(dp[i], dp[i - k] + 1);
                }
            }
            for (int l = 9; l <= n; l *= 9) {
                if (i - l >= 0) {
                    dp[i] = Math.min(dp[i], dp[i - l] + 1);
                }
            }
        }
        System.out.println(dp[n]);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
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); }
ll solve(ll n) {
    if (n == 1) {
        return 1;
    } else {
        return 2LL * solve(n / 2LL) + 1LL;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h;
    cin >> h;
    cout << solve(h) << endl;
}


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

int main() {
    int N,  A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;

  return 0;
}


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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define rrep(i,x) for(int i=x-1;i>=0;--i)

int dp[1010][1010];

int main()
{
    int q; cin >> q;

    rep(_, q) {
        string a,b; cin >> a>>b;

        int n = a.size(), m = b.size();

        rep(i, n) {
            rep(j, m) {
                if (a[i] == b[j]) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                } else {
                    dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
                }
            }
        }

        cout << dp[n][m] << endl;
    }
}

Measured memory_bytes: 7032
import collections
n=int(input())
a_list=[int(i) for i in input().split()]
 
node1,node2=0,0
square=0
 
cnt = collections.Counter(a_list)
for k, v in sorted(cnt.items(), key=lambda x: -x[0]):
    if v>=4:
        square=max(square,k**2)
    
    if v>=2:
        if node1==0:
            node1=k
        else:
            node2=k
            break
print(max(node1*node2,square))

Measured memory_bytes: 25500
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long lli;

const lli N = 10000; 

main(){
  lli a, b, d;
  bool used[N+1];
  while(cin >> a >> b >> d && (a|b|d)){
    lli ans[2] = {-1, -1};
    for(int k=-1;k<=1;k++){
      if(k == 0) continue;
      fill(used, used+N+1, false);
      lli t = 0, tmp = d;
      while(!used[tmp%b]){
        used[tmp%b] = true;
        if(tmp % b == 0){
          if(ans[0] == -1){
            ans[0] = t;
            ans[1] = tmp / b;
          }else if(ans[0] + ans[1] > t+ tmp / b){
            ans[0] = t;
            ans[1] = tmp / b;
          }else if(a * ans[0] + b * ans[1] > a * t + tmp){
            ans[0] = t;
            ans[1] = tmp / b;
          }
        }
        tmp += k * a;
        if(tmp < 0) break;
        t++;
      }
      fill(used, used+N+1, false);
      t = 0, tmp = d;
      while(!used[tmp%a]){
        used[tmp%a] = true;
        if(tmp % a == 0){
          if(ans[0] == -1){
            ans[0] = tmp / a;
            ans[1] = t;
          }else if(ans[0] + ans[1] > tmp / a + t){
            ans[0] = tmp / a;
            ans[1] = t;
          }else if(a * ans[0] + b * ans[1] > tmp + b * t){
            ans[0] = tmp / a;
            ans[1] = t;
          }
        }
        tmp += k * b;
        if(tmp < 0) break;
        t++;
      }
    }
    cout << ans[0] << ' ' << ans[1] << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e6+1;
 
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	ll a[n + 1];
	for (int i = 0; i <= n; i++)
		cin >> a[i];
	ll ans = 0, x;
	for (int i = 0, x; i < n; i++)
	{
		cin >> x;
		if (x > a[i])
		{
			ans += a[i], x -= a[i];
			if (x > a[i + 1])
				ans += a[i + 1], x -= a[i + 1], a[i + 1] = 0;
			else
				ans += x, a[i + 1] -= x;
		}
		else
			ans += x, a[i] -= x;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    
    def unite(x,y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True
    
    def size(x):
        return -par[find(x)]
    
    par = [-1]*(2*10**5+2)
    s = set()
    for _ in range(n):
        x, y = map(int, input().split())
        unite(x, 10**5+y)
        s.add(x)
    
    cnt = Counter()
    for x in s:
        cnt[find(x)] += 1

    res = 0
    for k, v in cnt.items():
        res += v * (size(k)-v)

    print(res-n)

if __name__ == '__main__':
    main()

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

int main(){
	double N,M;
	cin >> N >> M;
	int ano = 100*(N-M);
	double pro = 0.5;
	for(int i=1; i<M; i++)pro *= 0.5;

	double ans = 0;
	double p = pro;
	for(int i=1; i<=1000; i++){
		ans += (M*1900+ano)*i*pro;
		pro *= (1-p);
	}

	cout << ans << endl;
}


Measured memory_bytes: 3708
N, Y = map(int, input().split())
a = 0
k = 0
while a <= N:
  j = 0
  while j <= N-a:
    if 10000*a+5000*j+1000*(N-a-j) == Y:
      s = str(a)+' '+str(j)+' '+str(N-a-j)
      print(s)
      k += 1
      break
    elif k == 0:
      j += 1
    else:
      break
  if k == 0:
    a += 1
  else:
    break
if k == 0:
  print('-1 -1 -1')
else:
  pass

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<pair<int, int>> problems(N);
    for (int i = 0; i < N; i++) cin >> problems[i].first >> problems[i].second;
    sort(problems.begin(), problems.end());
    int ans = 0;
    {
        multiset<int> left, right;
        for (int i = 0; i < N; i++) {
            left.insert(problems[i].first);
            right.insert(problems[i].second);
        }
        for (int i = 0; i < N; i++) {
            auto now = problems[i];
            left.erase(left.find(now.first));
            right.erase(right.find(now.second));
            int temp = now.second - now.first + 1;
            pair<int, int> another = {*left.rbegin(), *right.begin()};
            if (another.first <= another.second) temp += another.second - another.first + 1;
            left.insert(now.first);
            right.insert(now.second);
            ans = max(ans, temp);
        }
    }
    multiset<int> upLeft, upRight, downLeft, downRight;
    for (int i = 0; i < N; i++) {
        auto now = problems[i];
        downLeft.insert(now.first);
        downRight.insert(now.second);
    }
    for (int i = 0; i < N - 1; i++) {
        auto now = problems[i];
        upLeft.insert(now.first);
        upRight.insert(now.second);
        downLeft.erase(downLeft.find(now.first));
        downRight.erase(downRight.find(now.second));
        int temp = 0;
        {
            int l = *upLeft.rbegin();
            int r = *upRight.begin();
            if (l <= r) temp += r - l + 1;
        }
        {
            int l = *downLeft.rbegin();
            int r = *downRight.begin();
            if (l <= r) temp += r - l + 1;
        }
        ans = max(ans, temp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 11136
#!/usr/bin/env python3

a,b,c,x,y = list(map(int,input().split()))

if c*2 < a:#cがaよりお得な場合
    if c*2 < b:#cがbよりお得な場合
        ans = c*2*min(x,y) + (max(x,y) - min(x,y))*c*2
    else:#cがaよろお得かつbよりお得でない
        if x >= y:#aのほうが買う量が多い
            ans = c*2*x
        else:#bの方が買う量が多い
            ans = c*2*x + b*(y-x)
elif c*2 < b:#cがbよりお得な場合
    if c*2 > a:#cがaよりお得でない場合
        if x <= y:#bの方が買う量が多い
            ans = c*2*y
        else:#aの方が買う量が多い
            ans = a*(x-y) + c*2*y
else:
    ans1 = a*x + b*y
    if x <= y:
        ans2 = c*2*x + b*(y-x)
    elif y < x:
        ans2 = c*2*y + a*(x-y)
    ans = min(ans1,ans2)

print(ans)


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

int t;
vector<int> d, f;
int n;
vector<vector<int> > G;

void dfs(int v) {
  if ( d[v] ) return;
  d[v] = ++t;  

  for ( int i = 0; i < n; i++ ) {
    if ( G[v][i] ) dfs(i);
  }

  f[v] = ++t;  
}

int main() {
  cin >> n;

  d = vector<int>(n, 0);
  f = vector<int>(n, 0);

  G = vector<vector<int> >(n, vector<int>(n, 0));
  for ( int i = 0; i < n; i++ ) {
    int u, k;
    cin >> u >> k;
    u--;
    for ( int i = 0; i < k; i++ ) {
      int v;
      cin >> v;
      v--;
      G[u][v] = 1;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    if ( !d[i] ) dfs(i);
  }

  for ( int i = 0; i < n; i++ ) {
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <map>

using namespace std;

class State{
public:
  int name;
  int st;
};

main(){
  int N, M, r, q, t, n, m, s;
  
  bool data[721][10000];


  while(1){
    cin >> N >> M;
    map<int,State> in;
    if(N==0 && M==0) break;
    for(int i=0;i<721;i++){
      for(int j=0;j<M;j++){
	data[i][j]=false;
      }
    }

    cin >> r;
    for(int i=0;i<r;i++){
      cin >> t >> n >> m >> s;
      m--;
      if(s==1){
	in[n].name=m;
	in[n].st=t-540;
      }else if(s==0){
	for(int i=in[n].st;i<(t-540);i++){
	  data[i][m]=true;
	}
      }
    }

    cin >> q;
    for(int i=0;i<q;i++){
      int ts, te;
      cin >> ts >> te >> m;
      m--;
      int count=0;
      for(int i=ts-540;i<(te-540);i++){
	if(data[i][m]) count++;
      }
      cout << count << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 7956
#include <iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;

    int element1 = a + b;
    int element2 = a - b;
    int element3 = a * b;


    int arr[] = {element1, element2, element3};
    int ln = sizeof(arr) / sizeof(*arr);


    int maximum = arr[0];

    for (int i = 0; i < ln; i++){
        if (arr[i] > maximum){
            maximum = arr[i];
        }
    }

    cout << maximum;
}

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

using namespace std;

int main(void)
{
    string n;
    cin >> n;
    int mod = 0;
    for(int i = 0; i < n.length(); i++){
        mod = (mod + (int)(n[i]-'0')) % 9;
    }
    if(mod == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3728
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.root = [-1]*(n+1)
		self.rank = [0]*(n+1)

	def find(self, x):
		if self.root[x] < 0:
			return x
		else:
			self.root[x] = self.find(self.root[x])
			return self.root[x]
			
	def unite(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return 0
		elif self.rank[x] > self.rank[y]:
			self.root[x] += self.root[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.root[x] = y
			if self.rank[x] == self.rank[y]:
				self.rank[y] += 1

	def isSame(self, x, y):
		return self.find(x) == self.find(y)

	def size(self, x):
		return -self.root[self.find(x)]
		
n,m,*L=map(int,open(0).read().split())
L=L[:1:-1]
ans=[n*(n-1)//2]
uf=UnionFind(n)
for a,b in zip(*[iter(L)]*2):
	if not uf.isSame(a,b):
		ans.append(ans[-1]-uf.size(a)*uf.size(b))
		uf.unite(a,b)
	else:
		ans.append(ans[-1])
print(*ans[::-1])

Measured memory_bytes: 25260
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> T inf;
template<> constexpr int inf<int> = 1e9;
template<> constexpr ll inf<ll> = 1e18;
template<> constexpr ld inf<ld> = 1e30;
#define DEBUG(X) cerr<<__LINE__<<" "<<#X<<": "<<X<<endl;
#define DUMP(A, n) for (auto x=begin(A); x!=begin(A)+n;x++){cout <<*x<< ' ';} cout<<endl;
#define DUMPP(A, n, m) for (auto x=begin(A); x != begin(A)+n;x++) {for (auto y=begin(*x); y != begin(*x)+m;)cout <<*y++<< ' '; cout<<endl;};
#define DUMPM(M) for (auto itr=mp.begin(); itr!=mp.end(); itr++) {cout<<itr->first<<" -> "<<itr->second<<endl;}
#define all(x) begin(x),end(x)
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
#define scf(x) scanf("%d",&x),x!=0
#define scff(x, y) scanf("%d%d",&x,&y),x!=0&&y!=0
#define scdd(x, y) ld x,y;scanf("%Lf%Lf",&x,&y);
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORR(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define fin(x,y) ld x,y; while(~scanf("%Lf,%Lf",&x,&y))

int main() {
  int ans=0;
  scii(K,S);
  REP(i,K+1) {
    REP(j,K+1) {
      int z = S - i - j;
      if (0 <= z && z <= K) ans++;
    }
  }
  printf("%d\n",ans);
}


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

using namespace std;
using ll=long long int;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> t(n + m);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        t[i].first = a;
        t[i].second = 1;
    }
    for (int i = 0; i < m; ++i) {
        int b, c;
        cin >> b >> c;
        t[i+n].first = c;
        t[i+n].second = b;
    }
    sort(t.begin(), t.end(), greater<pair<int, int>>());

    int rem = n;
    ll ans = 0;
    for (int i = 0; i < n+m && rem > 0; ++i) {
        int take = min(t[i].second, rem);
        ans += (ll)take * t[i].first;
        rem -= take;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
n, a, b, c = list(map(int, input().split()))
l = []
for _ in range(n):
    l.append(int(input()))

def dfs(depth, t, ans):
    if depth == n:
        sum = calc(t)
        if sum < ans:
            return sum
        else:
            return ans

    for j in range(4):
        tt = t.copy()
        tt.append(j)
        ans = dfs(depth + 1, tt, ans)

    return ans

def calc(t):
    ttt = [ [0, 0] ] * 3

    for i, v in enumerate(t):
        if v < 3:
            ttt[v] = [ttt[v][0] + 1, ttt[v][1] + l[i]]

    if ttt[0][0] == 0 or ttt[1][0] == 0 or ttt[2][0] == 0:
        return 1000000000

    sum = 0
    abc = [a, b, c, 0]
    for i, v in enumerate(ttt):
        sum += ((v[0] - 1) * 10) + abs(v[1] - abc[i])

    return sum


ans = dfs(0, [], 1000000000)
print(ans)

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

bitset<1001001001> is_prime(0);
vector<int> prime_numbers;
void sieve_of_eratosthenes(int n=1e7) {
  for (int i = 2; i < n + 1; i++) {is_prime.set(i);}
  for (int i = 2; i < (int)sqrt(n) + 1; i++) {
    if (is_prime[i]) for (int j = i * 2; j < n + 1; j += i) is_prime.reset(j);
  }
  for (int i = 2; i < n + 1; i++) if (is_prime[i]) prime_numbers.push_back(i);
}

unordered_map<int, int> prime_factorize(int n) {
  unordered_map<int, int> res;
  int border = int(sqrt(n));
  for (int &p : prime_numbers) {
    if (p > border) break;
    if (n % p == 0) {
      res[p] = 1; n /= p;
      while (n % p == 0) {res[p]++; n /= p;}
    }
    if (n == 1) return res;
  }
  res[n] = 1; return res;
}

unordered_map<int, int> prime_factorize_factorial(int n) {
  unordered_map<int, int> res;
  for (int i = 2; i < n + 1; i++) {
    for (auto &pc : prime_factorize(i)) {
      if (res.find(pc.first) == res.end()) res[pc.first] = pc.second;
      else res[pc.first] += pc.second;
    }
  }
  return res;
}

int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  sieve_of_eratosthenes(1e3);
  long long res = 1;
  for (auto &pc : prime_factorize_factorial(n)) {
    res *= pc.second + 1; res %= MOD;
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256