akhauriyash/Code-Regression huggingface dataset:
# ABC099C - Strange Bank
# DP ver.
def powers_of_x(x: int, N: int) -> set:
    # return set of x^1, x^2, x^3, ..., x^p ≤ N
    from itertools import count, takewhile

    if x == 1:
        return set()
    ret = set(x ** p for p in takewhile(lambda p: x ** p <= N, count(1)))
    return ret


def main():
    n = int(input())
    dp = [i for i in range(n + 1)]  # initialize with using only ¥1
    cand = powers_of_x(6, n) | powers_of_x(9, n)
    for i in range(n + 1):
        for j in cand:
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + 1)
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 7064
{-# LANGUAGE OverloadedStrings #-}

import           Control.Arrow  ((&&&))
import           Data.Either    (rights)
import           Data.List      (group, sort)
import qualified Data.Text      as T
import qualified Data.Text.IO   as T
import qualified Data.Text.Read as T

frequency :: Ord a => [a] -> [(Int, a)]
frequency = map (length &&& head) . group . sort

judge :: [Int] -> T.Text
judge = judge' . sort . frequency
    where
        judge' [(1, _), (4, _)] = "four card"
        judge' [(2, _), (3, _)] = "full house"
        judge' [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5)] = "straight"
        judge' [(1, 1), (1, 10), (1, 11), (1, 12), (1, 13)] = "straight"
        judge' [(1, c1), (1, c2), (1, c3), (1, c4), (1, c5)]
            | [c1, c2, c3, c4, c5] == [c1 .. c5] = "straight"
            | otherwise                          = "null"
        judge' [(1, _), (1, _), (3, _)] = "three card"
        judge' [(1, _), (2, _), (2, _)] = "two pair"
        judge' [(1, _), (1, _), (1, _), (2, _)] = "one pair"
        judge' _ = "null"

main :: IO ()
main = T.interact $ T.unlines . map judge . map (map fst) .
    map rights . map (map T.decimal) . map (T.splitOn ",") . T.lines

Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1e9+7;
const int INF=1001001001;

int main() {
  double W,H,x,y;
  cin>>W>>H>>x>>y;
  int a=0;
  if(x==W/2&&y==H/2){a=1;}
  cout<<W*H/2<<" "<<a<<endl;
  return 0;  
}

Measured memory_bytes: 3764
def getlist():
	return list(map(int, input().split()))

N = int(input())
A = getlist()

M = [0]
v = 0
for i in range(N):
	x = 2 * (A[i] - int((v // 2)))
	M.append(x)
	v = x
n = int(M[N] // 2)
ans = []
for i in range(1, N + 1):
	if i % 2 == 0:
		ans.append(M[i] + n)
	else:
		ans.append((M[i] - n))

ans2 = []
for i in range(N):
	ans2.append(str(ans[(N - 1 + i) % N]))
print(*ans2)

Measured memory_bytes: 76900
#include <iostream>
#include <queue>
#include <cassert>
#include <map>
using namespace std;

class state{
public:
  int* num;
  int time;
  int space;

  state(){
    num = new int[9];
  }

  state(int time){
    num = new int[9];
    this->time = time;
  }

  state(const state &st){
    num = new int[9];
    for(int i=0; i<9; i++) num[i]=st.num[i];
    time = st.time;
    space = st.space;
  }

  ~state(){
    delete[] num;
  }

  bool operator < (const state&a) const{
    for(int i=0; i<9; i++){
      if(num[i]==a.num[i]) continue;
      return num[i] < a.num[i];
    }
    return false;
  }

  bool check_ans(){
    bool flag=true;
    for(int i=0; i<9; i++){
      if(num[i]!=i+1) flag=false;
    }
    return flag;
  }

  //コード1~4を指定して、パズルを移動させる
  state operate(int i){
    int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};//移動方向
    int nx = space%3+dx[i], ny = space/3+dy[i];
    state ns=*this;
    ns.swap(ny*3+nx, space);

    ns.time=time+1;
    ns.space=ny*3+nx;

    return ns;
  }

  bool direction_check(int i){
    int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};//移動方向
    int nx = space%3+dx[i], ny = space/3+dy[i];
    if(nx<0 || 2<nx || ny<0 || 2<ny) return false;
    return true;
  }
private:
  //numのn1番目の要素とn2番目の要素を入れ替える
  void swap(int n1, int n2){
    int temp=num[n1];
    num[n1]=num[n2];
    num[n2]=temp;
  }
};
int main(){
  state start(0);//初期状態の生成
  for(int i=0; i<9; i++) {
    cin >> start.num[i];
    if(start.num[i]==0){
      start.num[i]=9;
      start.space=i;
    }
  }

  //重複を避けるためのmap
  map<state, bool> mp;
  mp[start]=true;

  //bfs用のqueue生成
  queue<state> q; q.push(start);

  //queueが空になるまで
  while(!q.empty()){
    state now=q.front(); q.pop();

    //もし取り出した状態が所望の状態なら、かかった回数を表示して終了
    if(now.check_ans()){
      cout << now.time << endl;
      break;
    }

    for(int i=0; i<4; i++){
      if(!now.direction_check(i)) continue;
      state ns=now.operate(i);
      if(!mp[ns]){
        mp[ns]=true;
        q.push(ns);
      }
    }

  }

  return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int nx = y1- y2;
  int ny = x2 - x1;
  int x3, y3, x4, y4;
  x3 = x2 + nx;
  y3 = y2 + ny;
  x4 = x1 + nx;
  y4 = y1 + ny;
  cout << x3 << ' ' << y3  << ' ' << x4  << ' ' << y4 << endl;
  return 0;
}



Measured memory_bytes: 3536
def main():

    H,W = map(int, input().split())

    total = H * W

    if H == 1 or W == 1:
        print(1)

    else:
        if total % 2 == 0:
            print(int(total/2))

        else:
            print(int((total+1)/2))

    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, Q, t[1000000], w[1000000], x; string s; vector<int> leader, ls;
int query(int x1, int x2) {
	return lower_bound(w, w + N, x2) - lower_bound(w, w + N, x1);
}
int check(int v) {
	int ret = 0;
	for (int i = 1; i < ls.size(); i++) ret += query(max(ls[i - 1] + 1, ls[i] - v), ls[i] + 1);
	return ret + (ls.size() ? query(ls[0] - v, ls[0] + 1) : 0);
}
int main() {
	scanf("%d%d", &N, &Q);
	for (int i = 0; i < N; i++) scanf("%d", &t[i]), w[i] = t[i];
	sort(w, w + N);
	for (int i = 0; i < Q; i++) {
		cin >> s >> x;
		if (s == "ADD") leader.push_back(x - 1);
		if (s == "REMOVE") {
			for (int j = 0; j < leader.size(); j++) {
				if (leader[j] == x - 1) leader.erase(leader.begin() + j);
			}
		}
		if (s == "CHECK") {
			int l = -1, r = 1000000001; ls.clear();
			for (int j = 0; j < leader.size(); j++) ls.push_back(t[leader[j]]);
			sort(ls.begin(), ls.end());
			while (r - l > 1) {
				int m = (r + l) / 2, u = check(m);
				if (u >= N - x) r = m;
				else l = m;
			}
			if (r == 1000000001) printf("NA\n");
			else printf("%d\n", r);
		}
	}
	return 0;
}

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

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


Measured memory_bytes: 764
import itertools
N=int(input())
p=tuple(map(str,input().split()))
q=tuple(map(str,input().split()))

test=[]
for i in range(1,N+1):
    test.append(str(i))
tables=list(itertools.permutations(test))

print(abs(tables.index(p)-tables.index(q)))

Measured memory_bytes: 13980
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define hi(x) ((x)>>16)
#define lo(x) ((x)&0xffff)

struct comp{
    bool operator()(const unsigned a, const unsigned b){return hi(a)*lo(a) < hi(b)*lo(b);}
};

int main(){
	int n,w,d;
	for(;scanf("%d%d%d",&n,&w,&d);){
		if(!n&&!w&&!d)return 0;
		
{
	vector<unsigned> v;
	v.push_back((w<<16)+d);
	while(n--){
		int p, s, state=0;
		scanf("%d%d", &p, &s);
		p--;
		s%=hi(v[p])+lo(v[p]);
		
		unsigned x=hi(v[p]), y=lo(v[p]), _x=0, _y=0;
		while(s--){
			switch(state){
				case 0:{
					_x++;
					if(_x==x)state=1;
					break;
				}
				case 1:{
					_y++;
					break;
				}
			}
		}
		unsigned x1, x2, y1, y2;
		switch(state){
			case 0:{
				x1=_x;x2=x-_x;
				y1=y2=y;
				break;
			}
			case 1:{
				x1=x2=x;
				y1=_y;y2=y-_y;
				break;
			}
		}
		
		v.erase(v.begin()+p);
		if(x1*y1>x2*y2){
			v.push_back((x2<<16)+y2);
			v.push_back((x1<<16)+y1);
		}else{
			v.push_back((x1<<16)+y1);
			v.push_back((x2<<16)+y2);
		}
	}
	
	sort(v.begin(), v.end(), comp());
	while(v.size()){
		printf("%d", hi(v[0])*lo(v[0]));
		v.erase(v.begin());
		if(v.size())printf(" ");
	}
	printf("\n");
}
	}
}

Measured memory_bytes: 0
# AOJ 0066 Tic Tac Toe

while line = gets
  r1, r2, r3 = line[0..2], line[3..5], line[6..8]
  c1 = line[0] + line[3] + line[6]
  c2 = line[1] + line[4] + line[7]
  c3 = line[2] + line[5] + line[8]
  d1 = line[0] + line[4] + line[8]
  d2 = line[2] + line[4] + line[6]

  result = "d"
  [r1, r2, r3, c1, c2, c3, d1, d2].each do |l|
    if l == "ooo"
      result = "o"
      break
    elsif l == "xxx"
      result = "x"
      break
    end
  end

  puts result
end

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

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

const int INF=1e9;
const int MOD=1e9+7;

int main(){
    int H,W,M; cin >> H >> W >> M;
    vector<ll> maxh(H,0);
    vector<ll> maxw(W,0);
    ll h[M],w[M];
    ll max_cnth=0;
    ll max_cntw=0;
    for(int i=0;i<M;i++){
        cin >> h[i] >> w[i]; h[i]--; w[i]--;
        maxh[h[i]]++;
        maxw[w[i]]++;
        max_cnth=max(max_cnth,maxh[h[i]]);
        max_cntw=max(max_cntw,maxw[w[i]]);
    }
    map<int,ll> ish;
    map<int,ll> isw;
    ll cnth=0; ll cntw=0;
    for(int i=0;i<H;i++){
        if(maxh[i]==max_cnth){
            ish[i]++; cnth++;
        }
    }
    for(int i=0;i<W;i++){
        if(maxw[i]==max_cntw){
            isw[i]++; cntw++;
        }
    }
    ll cnt=0;
    for(int i=0;i<M;i++){
        if(ish[h[i]]&&isw[w[i]]) cnt++;
    }
    ll sum=cnth*cntw;
    if(sum>cnt){
        cout << max_cnth+max_cntw << endl;
    }else{
        cout << max_cnth+max_cntw-1 << endl;
    }
}

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

int main() {
  int A, B;
  cin >> A >> B;
  string S;
  cin >> S;
  bool flag = true;
  for(int i = 0; i < A + B + 1; i++) {
    if(i == A && S[i] == '-') continue;
    else if(i == A && S[i] != '-') { flag = false; break; }
    else if(S[i] >= '0' && S[i] <= '9') continue;
    else { flag = false; break; }
  }

  if(flag) cout << "Yes";
  else cout << "No";


  return 0;
}

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

int main()
{
	int N, L;
	cin >> N;
	cin >> L;
	int d = 1000;
	int d_i = 0;
	int taste_sum = 0;
	for (int i = 1; i <= N; i++)
	{
		int taste = L + i - 1;
		if (abs(taste)< d)
		{
			d = abs(taste);
			d_i = i;
		}
		taste_sum += taste;
	}
	cout << taste_sum - (L + d_i - 1) << endl;

	return 0;
}

Measured memory_bytes: 384
H,W,D=map(int,input().split())

board_dic={}
for i in range(H):
  array=list(map(int,input().split()))
  for j in range(W):
    num=array[j]
    board_dic[num]=(i+1,j+1)
#print(board_dic)  
  
dslist=[]
for i in range(1,D+1):
  dl=[0]
  for j in range(1,10**9):
    if i+j*D>H*W:
      break
    x1,y1=board_dic[i+(j-1)*D]
    x2,y2=board_dic[i+j*D]
    dist=abs(x2-x1)+abs(y2-y1)
    dl.append(dl[-1]+dist)
  dslist.append(dl)
#print(dslist)    

Q=int(input())
for i in range(Q):
  l,r=map(int,input().split())
  mod=(l-1)%D
  print(dslist[mod][(r-mod-1)//D]-dslist[mod][(l-mod-1)//D])

Measured memory_bytes: 28376
#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>;
const ll INF = 1e10;

int N;
vector<vector<ll>> dp;

void warshallFloyd() {
  rep(k, N) {
    rep(i, N) {
      rep(j, N) {
        dp.at(i).at(j) = min(dp.at(i).at(j), dp.at(i).at(k) + dp.at(k).at(j));
      }
    }
  }
}

int main() {
  int M, R;
  cin >> N >> M >> R;
  dp.resize(N, vector<ll>(N, INF));

  vector<int> r(R);
  rep(i, R) {
    int x;
    cin >> x;
    x--;
    r.at(i) = x;
  }

  rep(i, M) {
    int A, B, C;
    cin >> A >> B >> C;
    A--; B--;

    dp.at(A).at(B) = C;
    dp.at(B).at(A) = C;
  }
  rep(i, N) dp.at(i).at(i) = 0;

  warshallFloyd();

  ll ans = INF;
  sort(r.begin(), r.end());
  do {
    ll tmp = 0;
    rep(i, (int)r.size() - 1) tmp += dp.at(r.at(i)).at(r.at(i + 1));
    ans = min(ans, tmp);
  } while (next_permutation(r.begin(), r.end()));

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> TP;
typedef pair<string, string> PS;

int main() {
  ll n;
  cin >> n;
  vector<ll> v;
  REP(i, n) {
    ll a;
    cin >> a;
    v.pb(a);
  }
  sort(v.begin(), v.end());
  ll sum = 0;
  REP(i, v.size() - 1) { sum += v[i]; }
  if (sum > v.back()) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
        int n, count;
        while(std::cin >> n)
        {
                count = 0;
                for(int a = 0; a < 10; ++a)
                        for(int b = 0; b < 10; ++b)
                                for(int c = 0; c < 10; ++c)
                                        for(int d = 0; d < 10; ++d)
                                                if(a + b + c + d == n)
                                                        count++;
                std::cout << count << std::endl;
        }
        return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,k;
string s;

signed main() {
    cin >> n >> k >> s;
    rep(i,n) {
        if (i == k-1) cout << (char)(s[i]+'a'-'A');
        else cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
// #include "knapsack_1.h"
#include <algorithm>
#include <iostream>

#include <vector>

struct Item {
    int weight;
    int value;

    Item(int w, int v)
        : weight{w}
        , value{v}
    {
    }
};

long long max_value(const std::vector<Item>& items, int capacity)
{
    std::vector<long long> dp(capacity + 1);

    for (const auto& item : items) {
        for (int weight = capacity; weight >= item.weight; --weight) {
            dp[weight] = std::max(dp[weight], item.value + dp[weight - item.weight]);
            // auto& current = dp[weight + item.weight];
            // current = std::max(current, item.value + dp[weight]);
        }
    }

    return dp.back();
}

int main(int argc, char *argv[])
{
    int n, capacity;
    std::cin >> n >> capacity;
    std::vector<Item> items;
    items.reserve(n);

    for (int i = 0; i < n; ++i) {
        int weight, value;
        std::cin >> weight >> value;
        items.emplace_back(weight, value);
    }
    std::cout << max_value(items, capacity) << std::endl;
    return 0;
}


Measured memory_bytes: 1024
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    for (i, line) in stdin.lock().lines().enumerate() {
        let x = line.unwrap().trim().parse::<u16>().unwrap();
        match x {
            0 => return,
            _ => println!("Case {}: {}", i+1, x),
        }
    }
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(3*n);
    REP(i, 3*n) cin >> a[i];
    sort(ALL(a));
    reverse(ALL(a));

    REP(i, n) {
        ans += a[2*i + 1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

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

    rep(i,n){
        if(a[i]%2==0 && a[i]%3!=0 && a[i]%5!=0){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 3576
#include<iostream>
using namespace std;
 
int main() {
    int a, b;
    char op;
    while (1) {
        cin >> a >> op >> b;
        if (op == '?') return 0;
        else if (op == '+') cout << a + b << endl;
        else if (op == '-') cout << a - b << endl;
        else if (op == '*') cout << a * b << endl;
        else if (op == '/') cout << a / b << endl;
    }
}

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

using namespace std;

void insertion_sort(vector<int> &vec);
void print_vector(vector<int> vec);

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

    vector<int> vec(n);
    for (int i = 0; i < n; ++i)
        cin >> vec[i];

    print_vector(vec);
    insertion_sort(vec);
}

void insertion_sort(vector<int> &vec)
{
    for (int i = 1; i < vec.size(); ++i) {
        int tmp = vec[i];

        int j = i - 1;
        while (j >= 0 && vec[j] > tmp) {
            vec[j + 1] = vec[j];
            --j;
        }
        vec[j + 1] = tmp;

        print_vector(vec);
    }
}

void print_vector(vector<int> vec)
{
    cout << vec[0];
    for (int i = 1; i < vec.size(); ++i)
        cout << ' ' << vec[i];
    cout << '\n';
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define MOD 1000000007
#define INF 1000000000000000000
#define endll "\n"
#define pb push_back
#define forn(i,n) for(i=0;i<n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() 
{
	fast_io;
	ll n,W,i,j,sum=0;
	cin>>n>>W;
	ll w[n],v[n];
	forn(i,n)cin>>w[i]>>v[i],sum+=v[i];
	ll dp[sum+1];
	forn(i,sum+1)dp[i]=INF;
	dp[0]=0;
	forn(i,n)
	{
	    for(j=sum-v[i];j>=0;j--)
	    {
	        dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
	    }
	}
	ll ans;
	forn(i,sum+1)if(dp[i]<=W)ans=i;
	cout<<ans<<endll;
	return 0;
} 

Measured memory_bytes: 1024
import java.util.*;
public class Main{
static int N= 0;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		N =sc.nextInt();
		int data[] =new int[N];
		int max=0;
		for(int i=0;i<N;i++) {
			data[i] = sc.nextInt();
			if(data[i]> max) max=data[i];
			if(i!=0&& data[i]<max-1) {
				System.out.print("No");
				break;
			}
			if(i==N-1)System.out.print("Yes");

		}
		
		
}
}

Measured memory_bytes: 50168
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
#include <time.h>
#define int long long
using namespace std;
int a,b,c,d;
signed main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	printf("%d\n",(a-c)*(b-d));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
 
int main()
{
    string s;
    cin >> s;

    map<unsigned long long, unsigned long long> mod;
    for(unsigned long long i = 0; i < 2019; i++)
    {
        mod[i] = 0;
    }

    unsigned long long cur = 0;
    unsigned long long tenFactor = 1;
    for(unsigned long long i = 0; i < s.size(); i++)
    {
        cur = (cur + (s[s.size() - i - 1] - '0') * tenFactor) % 2019;
        tenFactor = (tenFactor * 10) % 2019;
        mod[cur]++;
    }

    unsigned long long count = 0;
    for(unsigned long long i = 0; i < 2019; i++)
    {
        count += mod[i] * (mod[i] - 1) / 2;
    }

    cout << count + mod[0];
 
    return 0;
}

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

using namespace std;
string s[101];
int n, l;
int main()
{
    cin >> n >> l;
    for(int i = 0; i < n; i++)
        cin >> s[i];
    sort(s, s+n);
    for(int i = 0; i < n; i++) cout << s[i];
    cout << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int a;
    cin >> a;
    cout << 3*a*a << endl;		
		
	
}

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

int A, B;
int main()
{
	cin >> A >> B;
	if (A == B)
	{
		cout << "Draw" << endl;
	} else
	{
		if (A == 1 || B == 1)
		{
			if (A == 1)
			{
				cout << "Alice" << endl;
			} else
			{
				cout << "Bob" << endl;
			}
		} else
		{
			if (A > B)
			{
				cout << "Alice" << endl;
			} else
			{
				cout << "Bob" << endl;
			}
		}
	}

	cin.get();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll fac[200005];
ll qpow(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1)
			ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
ll inv(ll a){//mod为素数
	return qpow(a,mod-2);
}
ll C(ll n,ll m){
	return fac[n]*inv(fac[m])%mod*inv(fac[n-m])%mod;
}
int main(){
	ll n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	fac[0]=1;
	for(ll i=1;i<2*n;i++)
		fac[i]=(fac[i-1]*i)%mod;
	ll tmpa,tmpb,tmpc;
	tmpa=a*inv(a+b)%mod;
	tmpb=b*inv(a+b)%mod;
	tmpc=100*inv(100-c)%mod;	
	ll ans=0;
	for(ll i=n;i<2*n;i++){
		ll y=tmpc*i%mod*C(i-1,n-1)%mod;
		ll p=(qpow(tmpa,n)*qpow(tmpb,i-n)%mod+qpow(tmpa,i-n)*qpow(tmpb,n)%mod)%mod;
		ans=ans+p*y%mod;
		ans%=mod;
	}	
	printf("%lld",ans);	
} 

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
	int n;
	cin>>n;
	vi vs(n);
	unordered_map<int,ll> mp,inc,ninc;
	for(int &x:vs){
		cin>>x;
		mp[x]++;
	}
	ll s=0;
	for(auto &x:mp){
		inc[x.ff] = (x.ss*(x.ss-1LL))/2LL;
		s+=inc[x.ff];
		if(x.ss > 1LL)
			ninc[x.ff] = ((x.ss-1LL)*(x.ss-2LL))/2LL;
		else
			ninc[x.ff]=0LL;
	}
	for(int i=0;i<n;++i){
		cout << s - inc[vs[i]] + ninc[vs[i]] << endl;
	}
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

string a[] = {"erase","dream","eraser","dreamer"};

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

    for(int i = s.length()-1; i > 0;){
        if(s.substr(i-4,5) == a[0]) i -= 5;
        else if(s.substr(i-4,5) == a[1]) i -= 5;
        else if(s.substr(i-5,6) == a[2]) i -= 6;
        else if(s.substr(i-6,7) == a[3]) i -= 7;
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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


fn abc(a: Vec<i32>) -> i32 {
    let a_: i32 = a.iter().map(|x| x-1).sum();
    return a_;
}

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

fn main() {
    /*
    assert_eq!(abc(), "Yes");
    assert_eq!(abc(101), "No");
    assert_eq!(abc(999999999), "Yes");
    */
    let n: i32 = read();
    let mut a: Vec<i32> = (0..n).map(|_| read()).collect();
    
    let result = abc(a);
    
    println!("{}", result);
}




Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

vector<long long> dp;

long long f(int i, const vector<long long> &h) {
  if (i == 0) {
    return 0;
  }

  if (i == 1) {
    return abs (h[i] - h[0]);
  }

  if (dp[i] == -1) {
    long long a = abs(h[i] - h[i - 1]) + f(i - 1, h);
    long long b = abs(h[i] - h[i - 2]) + f(i - 2, h);
    dp[i] = min(a, b);
  }

  return dp[i];
}

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

  vector<long long> h(n);
  for (auto &hi : h) cin >> hi;

  dp.resize(n);
  fill(dp.begin(), dp.end(), -1);

  long long ans = f(n - 1, h);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6528
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	hh := make([]int, n)
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		hh[i] = getNextInt(scanner)
	}

	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}

	seg := Segment{}

	seg.init(n + 1)

	for i := 0; i < n; i++ {
		mx := seg.max(0, hh[i])
		seg.maximize(hh[i], mx+aa[i])
	}

	fmt.Fprintln(writer, seg.bucket[seg.h-1][0])
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int64
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int64, 1)
	seg.bucket[0] = make([]int64, n)

	chunk := 8
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int64, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}

func (seg *Segment) maximize(index int, value int64) {
	seg.bucket[0][index] = value
	for seg.i = 0; seg.i < seg.h-1; seg.i++ {
		parent := index / seg.chunk
		if seg.bucket[seg.i+1][parent] < value {
			seg.bucket[seg.i+1][parent] = value
		}
		index /= seg.chunk
	}
}

func (seg *Segment) max(l, r int) int64 {
	var max int64
	if seg.n < r {
		r = seg.n
	}
	for index := l; index < r; index += seg.unit[seg.i] {
		for seg.i = 0; seg.i < seg.h-1 && index%seg.unit[seg.i+1] == 0; seg.i++ {
			if index+seg.unit[seg.i+1] >= r {
				break
			}
		}
		if max < seg.bucket[seg.i][index/seg.unit[seg.i]] {
			max = seg.bucket[seg.i][index/seg.unit[seg.i]]
		}
	}

	return max
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
	cin.tie(0);	ios::sync_with_stdio(false);

  int i,j;
  int N; cin >> N;
  ll A[N]; rep(i,N){cin >> A[i];}
  int ans = 0;
  for(;;){
      bool isOK = true;
      rep(i,N){
          if(A[i]%2!=0){isOK=false;break;}
          else{A[i]/=2;}
      }
      if(isOK==false){break;}
      ans++;
  } 
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3616
def judge_place_term(a_cities, b_cities, z):
    for city_x in a_cities:
        if z <= city_x:
            return False
    for city_y in b_cities:
        if z > city_y:
            return False

    return True

def judge_war(a_cities, b_cities, x, y):
    for z in range(x + 1, y + 1, 1):
        if judge_place_term(a_cities, b_cities, z):
            return False
    
    return True

stats = input().split(" ")

n = int(stats[0])
m = int(stats[1])
x = int(stats[2])
y = int(stats[3])

a_cities = [int(city) for city in input().split(" ")]
b_cities = [int(city) for city in input().split(" ")]

if judge_war(a_cities, b_cities, x, y):
    print("War")
else:
    print("No War")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	ll ans = 0;
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			int x = r * i + g * j;
			if (n - x < 0) continue;
			if ((n - x) % b == 0) ans++;
		}
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using V = vector<T>;
using P = pair<int, int>;

/*
 *  */

signed main() {
  int n;
  cin >> n;
  V<int> a(n);
  rep(i, 0, n) cin >> a[i];

  bool ok = true;
  rep(i, 0, n) if(a[i]%2 == 0){
    if(a[i]%3 != 0 and a[i]%5 != 0) ok = false;
  }

  cout << (ok ? "APPROVED" : "DENIED") << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  vector<int> ans(3);
  for(int i = 0; i < 3; i++){
    ans[i] = 0;
  }
  int A, B;
  cin >> A >> B;
  A--;
  B--;
  ans[A] = 1;
  ans[B] = 1;
  for(int i = 0; i < 3; i++){
    if(ans[i] == 0){
      cout << i+1 << endl;
    }
  }



  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#define INF 2100000000
#define INVALID -1
using namespace std;
int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
int absint(int a)
{
	return max(a , - a);
}
int main()
{
	int a, b, c, d;
	bool n1=false, n9=false, n7=false, n4=false;
	cin >> a >> b >> c >> d;
	switch (a)
	{
	case 1:n1++; break;
	case 9:n9++; break;
	case 7:n7++; break;
	case 4:n4++; break;
	}
	switch (b)
	{
	case 1:n1++; break;
	case 9:n9++; break;
	case 7:n7++; break;
	case 4:n4++; break;
	}
	switch (c)
	{
	case 1:n1++; break;
	case 9:n9++; break;
	case 7:n7++; break;
	case 4:n4++; break;
	}
	switch (d)
	{
	case 1:n1++; break;
	case 9:n9++; break;
	case 7:n7++; break;
	case 4:n4++; break;
	}
	if (n1&&n9&&n7&&n4) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<queue>
#define sqr(x) (x)*(x)
#define mk(x,y,z) make_pair(x,make_pair(y,z))
using namespace std;
int n,m,i,j,mi[1000005][2],num[1000005],re[1000005],x,y,l,r;
priority_queue<pair<int,pair<int,int>/**/>,vector<pair<int,pair<int,int>/**/>/**/>,greater<pair<int,pair<int,int>/**/>/**/>/**/> pq;
void build(int id,int l,int r)
{
	if (l==r)
	{
		mi[id][l&1]=num[l];
		mi[id][(l&1)^1]=n+1;
		return;
	}
	build(id*2,l,(l+r)/2);
	build(id*2+1,(l+r)/2+1,r);
	mi[id][0]=min(mi[id*2][0],mi[id*2+1][0]);
	mi[id][1]=min(mi[id*2][1],mi[id*2+1][1]);
}
int query(int id,int l,int r,int ql,int qr,int t)
{
	if (ql<=l&&r<=qr) return mi[id][t];
	int ans=n+1;
	if (ql<=(l+r)/2) ans=min(ans,query(id*2,l,(l+r)/2,ql,qr,t));
	if (qr>(l+r)/2) ans=min(ans,query(id*2+1,(l+r)/2+1,r,ql,qr,t));
	return ans;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>num[i];
		re[num[i]]=i;
	}
	build(1,1,n);
	pq.push(mk(query(1,1,n,1,n,1),1,n));
	for (i=1;i<=n/2;i++)
	{
		x=pq.top().first;
		y=query(1,1,n,re[x]+1,pq.top().second.second,(re[x]+1)&1);
		cout<<x<<' '<<y<<' ';
		x=re[x];
		y=re[y];
		l=pq.top().second.first;
		r=pq.top().second.second;
		pq.pop();
		if (l<x-1) 
		{
			pq.push(mk(query(1,1,n,l,x-1,l&1),l,x-1));
		}
		if (x+1<y-1)
		{
			pq.push(mk(query(1,1,n,x+1,y-1,(x+1)&1),x+1,y-1));
		}
		if (y+1<r)
		{
			pq.push(mk(query(1,1,n,y+1,r,(y+1)&1),y+1,r));
		}
	}
	return 0;
} 

Measured memory_bytes: 13176
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    char a, b;
    cin >> a >> b;
    cout << (a == 'H'^b == 'H' ? "D" : "H") << endl;
    return 0;
}

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

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

bool ans = {};

void solve(){
  // main algorithm
  ans = (S.substr(0,4) == (string)("YAKI"));
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  if(ans) {
    cout << "Yes\n";
  }
  else {
    cout << "No\n";
  }
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> S;
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function(line) {
  lines.push(line);
});

reader.on('close', function() {
  const N = Number.parseInt(lines[0]);

  var array = new Array(N);
  for (var i = 0; i < N; i++) array[i] = Number.parseInt(lines[1].split(' ')[i]);
  
  insertionSort(array, N);
});

function insertionSort(A, N) {
  console.log(A.join(' '));
  for (var i = 1; i < N; i++) {
    var v = A[i];
    var j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    console.log(A.join(' '));
  }
}


Measured memory_bytes: 18196
#include <iostream>

using namespace std;

int main() {
  char c;
  cin >> c;

  if (c == 'A') cout << 'T';
  if (c == 'T') cout << 'A';
  if (c == 'G') cout << 'C';
  if (c == 'C') cout << 'G';

  cout << endl;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())

ans = "No"
cnt = 0
while cnt < K:
    if A >= B:
        B *= 2
    elif B >= C:
        C *= 2

    if A < B and B < C:
        ans = "Yes"
        break
    cnt += 1

print(ans)


Measured memory_bytes: 9164
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=2e5+11;
const ll INF=1e18;
ll a[N],sum[N],ans=INF;
int n;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();
	for(int i=1;i<=n;++i) a[i]=(ll)read();
	for(int i=1;i<=n;++i) sum[i]=sum[i-1]+a[i];
	for(int i=1;i<n;++i) ans=min(ans,abs(sum[i]-(sum[n]-sum[i])));
	printf("%lld",ans);
}

Measured memory_bytes: 3328
import heapq
 
N,M,S,T = map(int,input().split())
S,T = S-1,T-1
src = [tuple(map(int,input().split())) for i in range(M)]
 
es = [[] for i in range(N)]
for u,v,a,b in src:
    u,v = u-1,v-1
    es[u].append((v,a,b))
    es[v].append((u,a,b))
 
INF = float('inf')
cy = [INF] * N
cy[S] = 0
hq = [(0,S)]
heapq.heapify(hq)
while hq:
    cost,v = heapq.heappop(hq)
    for to,a,b in es[v]:
        if cost + a >= cy[to]: continue
        cy[to] = cost + a
        heapq.heappush(hq, (cy[to],to))
 
cs = [INF] * N
cs[T] = 0
hq = [(0,T)]
heapq.heapify(hq)
while hq:
    cost,v = heapq.heappop(hq)
    for to,a,b in es[v]:
        if cost + b >= cs[to]: continue
        cs[to] = cost + b
        heapq.heappush(hq, (cs[to],to))
 
ans = [INF]
for i in reversed(range(N)):
    tmp = cs[i] + cy[i]
    ans.append(min(ans[-1],tmp))
 
for a in reversed(ans[1:]):
    print(10**15 - a)

Measured memory_bytes: 73720
#include<iostream>

using namespace std;

int main(){
    long long N,M;
    long long ans=0;

    cin>>N>>M;

    if(N>M/2){
        cout<<M/2<<endl;
        return 0;
    }else{
        ans+=N;
        ans+=(M-2*N)/4;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
def resolve():
    N, M = map(int, input().split())

    if M == 1:
        print(1, 2)
        return

    i1 = 1
    i2 = M+2
    for diff in range(M, 0, -1):
        print(i1, i1+diff)
        i1 += 1
        i1, i2 = i2, i1

if __name__ == "__main__":
    resolve()

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    char c;
    cin>>c;

    if((int)(c-'A')<=25){
        cout<<"A"<<endl;
        return;
    }else{
        cout<<"a"<<endl;
        return;
    }
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3592
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		HashMap<String, Integer> map = new HashMap<String, Integer>();

		int d[] = {1, -1};
		for(int k = 0; k < 2; k++){
			int n = sc.nextInt();

			for(int i = 0; i < n; i++){
				String tmp = sc.next();

				if(!map.containsKey(tmp)){
					map.put(tmp, d[k]);
				}
				else {
					map.put(tmp, map.get(tmp) + d[k]);
				}
			}
		}

		int sum = 0;
		Iterator<String> it = map.keySet().iterator();

		while(it.hasNext()){
			sum = Math.max(sum, map.get(it.next()));
		}

		System.out.println(sum);

	}
}


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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define tc ll t;cin >> t;while(t--)

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	set <string> s;
	string t;
	for0(i,n){
		cin >> t;
		s.insert(t);
	}
	cout << s.size()<< endl;
	return 0;
}


Measured memory_bytes: 19196
N,M=map(int,input().split())
mod=10**9+7

def nCmMOD(A,B,Mod):
    num,den=1,1
    for i in range(B):
        num*=(A-i)
        den*=(i+1)
        num%=Mod
        den%=Mod
    return (num*pow(den,Mod-2,Mod))%Mod

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

ans=1
F=factorization(M)
for i in range(len(F)):
    f=F[i][1]
    ans*=nCmMOD(f+N-1,f,mod)
    ans%=mod

if M==1:
    print(1)
else:
    print(ans)

Measured memory_bytes: 9512