akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int ans=0;
    rep(i,n){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3800
N = int(input())
T = input()
S = list(T)
G = True
while G:
    G = False
    for i in range(1, len(S)):
        if S[i - 1] == '(' and S[i] == ')':
            S.pop(i)
            S.pop(i - 1)
            G = True
            break
for s in S:
    if s == '(':
        T = T + ')'
    else:
        T = '(' + T
print(T)

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

using namespace std;

template<typename TypeInt>
string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    reverse(ret.begin(), ret.end());

    return ret;
}

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

	string s;
	s = Itoa(n,k);
	cout << s.size() << endl;
	return 0;
}


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

signed main(){
  int N,K;
  cin >> N >> K;
  int ans = 0;
  int nowmax = 0, nowmin = 0;
  for(int i = 1;i <= N+1;i++){
    nowmin += i-1;nowmax += N+1-i;
    if(i >= K)ans += nowmax - nowmin + 1;
  }
  cout << ans % 1000000007;
}



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


int main() {
	int N, M; cin >> N >> M;
	vector<pair<int,int>> Ans(M);
	for (int i = 0; i < M; i++)
	{
		Ans[i].first = i + 1;
	}
	for (int i = 0; i < N; i++)
	{
		int K; cin >> K;
		for (int j = 0; j < K; j++)
		{
			int A; cin >> A;
			for (int k = 0; k < M; k++)
			{
				if (Ans[k].first == A) {
					Ans[k].second++;
					break;
				}
			}
		}
	}
	int cnt=0;
	for (int i = 0; i < M; i++)
	{
		if (Ans[i].second == N)cnt++;
	}
	cout << cnt << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <vector>
#include <map>

using namespace std;
//map<char,bool> assign;
int assign;
bool formula(string &arg, int &pos){
    if('a' <= arg[pos] && arg[pos] <= 'k'){
        return assign & (1 << (arg[pos++]-'a'));
    }else if(arg[pos] == '-'){
        return !formula(arg, ++pos);
    }else if(arg[pos] == 'T'){
        pos++;
        return true;
    }else if(arg[pos] == 'F'){
        pos++;
        return false;
    }else{
        assert(arg[pos] == '(');
        bool f,b;
        char op;
        f = formula(arg, ++pos);
        op = arg[pos];
        assert(op == '*' || op == '+' || op == '-');
        if(op == '-') pos++;
        b = formula(arg, ++pos);
        assert(arg[pos] == ')');
        pos++;
        if(op == '*'){
            if(f&&b) return true;
            return false;
        }else if(op == '+'){
            if(!f&&!b) return false;
            return true;
        }else{
            if(f && !b) return false;
            return true;
        }
    }
}

bool parse(string &arg, int pos){
    bool f,b;

    f = formula(arg, pos);
    assert(arg[pos] == '=');
    b = formula(arg, ++pos);
    return f == b;
}


int main(){
    string str;
    while(cin >> str){
        if(str == "#") break;
        vector<char> vars;
        bool res = true;

        for(int i=0;i<(int)str.size();i++){
            if('a' <= str[i] && str[i] <= 'k'){
                vars.push_back(str[i]);
            }
        }

        for(int i=0;i<(1 << 10);i++){
            assign = i;
            res = parse(str, 0);
            if(!res) break;
        }
        if(res){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int ans;
	if(b<=c or d<=a) {
		ans = 0;
	}else {
		ans = min(b,d) - max(a,c);
	}
	cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  ll n, x;
  cin >> n >> x;
  vector<ll> vec(n);
  for (auto &v : vec)
    cin >> v;

  ll ans = 0;
  for (ll i = 1; i< n; ++i) {
    ll vsum = vec[i] + vec[i-1];
    if (vsum <= x)
      continue;
    else if (vsum - x <= vec[i])
      vec[i] -= vsum - x;
    else
      vec[i] = 0;
    ans += vsum - x;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4064
N, M = map( int, input().split() )
A = list( map( int, input().split() ) )


for i in range(N-1): A[i+1] += A[i]
for i in range(N): A[i] %= M

import collections
num_appeared = collections.Counter(A)

ans = 0
for key, value in num_appeared.items():
    if key == 0: ans += value
    ans += value*(value-1) // 2
print(ans)

Measured memory_bytes: 14252
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let n: i32 = lines.next().unwrap().unwrap().parse().unwrap();
    let p = lines.next().unwrap().unwrap();
    let p: Vec<i32> = p.split_whitespace().map(|s| s.parse().unwrap()).collect();
    let q = lines.next().unwrap().unwrap();
    let q: Vec<i32> = q.split_whitespace().map(|s| s.parse().unwrap()).collect();

    fn permutation(v: Vec<i32>) -> Vec<Vec<i32>> {
        if v.len() == 1 {
            return vec![v];
        }
        let mut result = Vec::new();
        for i in 0..v.len() {
            let mut new_v = v.clone();
            let first = new_v.remove(i);
            for mut p in permutation(new_v) {
                p.insert(0, first);
                result.push(p);
            }
        }
        result
    }

    let perm = permutation((1..n + 1).collect());

    let a = perm.iter().position(|v| *v == p).unwrap();
    let b = perm.iter().position(|v| *v == q).unwrap();

    let ans = (a as i32 - b as i32).abs();
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char m[7]={'I','V','X','L','C','D','M'};
int n[7]={1,5,10,50,100,500,1000};
int d[110];
int main(){
	string s;
	while(cin>>s){
		for(int i=0;i<s.size();i++){
			for(int j=0;j<7;j++){
				if(m[j]==s[i])d[i]=n[j];
			}
		}
		int ans=0;
		for(int i=0;i<s.size();i++){
			bool t=false;
			for(int j=i+1;j<s.size();j++){
				if(d[j]>d[i])t=true;
			}
			if(t)ans-=d[i];
			else ans+=d[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

#define REP(i,n) for(ll i=0; i < (n); ++i)
#define REPR(i,n) for(ll i=(n); i >= 0; --i)
#define FOR(i, m, n) for(ll i = (m); i < (n); ++i)

#define INF 1e9

int A, B, C, D, E, F;

int main(){
  cin >> A >> B >> C >> D >> E >> F;
  pair<int, int> ans = {A*100, 0};
  double maxm = -1;
  for(int i = 0; A*i*100 < F; i++){
    for(int j = 0; (A*i+B*j)*100 < F; j++){
      if(i==0 && j ==0) continue;
      int water = (A*i+B*j)*100;
      for(int k = 0; water+k*C <= F && k*C <= E*water/100; k++){
        for(int l = 0; (water+k*C+l*D <= F) && ((k*C+l*D) <= E*water/100); l++){
          int suger = C*k+D*l;
          if(suger > E*water/100) continue;
          if(ans.second * water < suger * ans.first){
            ans.first = water;
            ans.second = suger;
            //maxm = (double)100*suger/(suger+water);
          }
        }
      }
    }
  }
  cout << ans.first+ans.second  << " " << ans.second << endl;

  return 0;
}


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

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

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

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];
  ll ans = 0;
  while (1) {
    ll cnt = 0;
    REP(i,n) {
      cnt += a[i]/n;
    }
    if (cnt == 0) break;
    REP(i,n) {
      ll k = a[i]/n;
      a[i] %= n;
      a[i] += cnt - k;
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int people, snack, num, no, count = 0;
	cin >> people >> snack;
	int arr[people];
	for(int i = 0; i < people; ++i){
		arr[i] = 0;
	}
	for(int i = 0; i < snack; ++i){
		cin >> num;
		for(int j = 0; j < num; ++j){
			cin >> no;
			arr[no - 1]++;
		}
	}
	for(int i = 0; i < people; ++i){
		if(arr[i] == 0){
			count++;
		}
	}
	cout << count;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> oder(n), sat(n), adsat(n - 1);
	int result = 0;
	for (int i = 0; i < n; i++) {
		cin >> oder.at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> sat.at(i);
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> adsat.at(i);
	}
	
	for (int i = 0; i < n; i++) {
		result += sat.at(oder.at(i) - 1);
		if (i != 0 && oder.at(i) - oder.at(i - 1) == 1) {
			result += adsat.at(oder.at(i -1) - 1);
		}
	}

	cout << result << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
  
    public static void main(String [] args){
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        int q=sc.nextInt();
        boolean rev=false;
        Deque<Character> deque=new LinkedList<>();
        for(int i=0;i<s.length();i++){
            deque.addLast(s.charAt(i));
        }
        
        for(int i=0;i<q;i++){

            int num=sc.nextInt();

            if(num==1){
                rev=!rev;
            }


            else{

                int p=sc.nextInt();
                char ch=sc.next().charAt(0);
                
                if(p==1){//add at beginning

                    if(!rev){
                        // s=ch+s;
                        deque.addFirst(ch);
                    }
                    else{
                        deque.addLast(ch);
                        // s=s+ch;
                    }
            }

                   else{//add at last
                       
                    if(!rev){
                        // s=s+ch;
                        deque.addLast(ch);
                    }
                    else{
                        deque.addFirst(ch);
                        // s=ch+s;
                    }
                   }
                }
            }
            StringBuilder bs=new StringBuilder("");
            Iterator iterator=deque.iterator();
            while(iterator.hasNext()){
                bs.append(iterator.next());
            }
        if(!rev){
            System.out.println(bs.toString());
        }else{
            System.out.println(bs.reverse().toString());
        }


    }
}

Measured memory_bytes: 161988
object Main extends App {

  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt 
  val a = Array.fill(n)(sc.nextInt) 
  val q = sc.nextInt 
  val m = Array.fill(q)(sc.nextInt)
  
  def solve(i: Int, m: Int): Boolean = if(m == 0) true
    else if(i >= n) false
    else solve(i+1, m) || solve(i+1, m - a(i))
  
  val result = m.map(p => if(solve(0, p)) "yes" else "no")

  print(result.mkString(f"%n") + f"%n")

}



Measured memory_bytes: 45540
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def add_mod(a,b): return (a+b) % MOD

N = iin()
abc = [iln() for _ in range(N)]

dp = [[0 for _ in range(3)] for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k: continue
            dp[i+1][j] = max(dp[i+1][j], dp[i][k]+abc[i][j])
print(max(dp[N]))

Measured memory_bytes: 100180
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    n = 0
    for i in range(N):
        m = min(A[i], B[i])
        n += m
        A[i] -= m
        B[i] -= m
        m = min(A[i+1], B[i])
        n += m
        A[i+1] -= m
        B[i] -= m

    print(n)

main()


Measured memory_bytes: 19376
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  int A;cin>>A;
  cout << N*N-A<<endl;
  return 0;
}


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

int main(){
    map<string, vector<int>> m;
    int q, op, x;
    string s;
    
    cin >> q;
    while(q-- > 0){
        cin >> op;
        if(op == 0){
            cin >> s >> x;
            m[s].push_back(x);
        }else if(op == 1){
            cin >> s;
            if(m.count(s)){
                for(int x : m[s])   cout << x << "\n";
            }
        }else if(op == 2){
            cin >> s;
            m[s].clear();
        }else if(op == 3){
            string l, r;
            cin >> l >> r;
            auto x = m.lower_bound(l);
            auto y = m.upper_bound(r);
            for(;x != y; x++){
                string key = (*x).first;
                for(int z : m[key])   cout << key << " " << z << "\n";
            }
        }
    }

    return 0;
}


Measured memory_bytes: 24412
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 200010;
int n,k;
int pier[MAX];
int nast[MAX];
int t[MAX];
int kiedy[MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> k;
  R(i,n){
    cin >> t[i];
    kiedy[i] = -1;
  }
  R(i,MAX)pier[i] = -1;
  for(int i = n - 1; i >= 0; i--){
    nast[i] = pier[t[i]];
    pier[t[i]] = i;
  }
  int i = 0;
  int ak = 0;
  while(ak != k){
    debug(i,ak);
    if(kiedy[i] != -1){
      int krok = kiedy[i] - ak;
      int pom = (k - ak - 1) / krok;
      ak += pom * krok;
    }
    kiedy[i] = ak;
    int val = t[i];
    if(nast[i] != -1){
      i = nast[i];
    }else{
      if(ak < k - 1){
        ak++;
        i = pier[val];
      }else{
        cout << val << " ";
      }
    }
    i++;
    if(i == n){
      ak++;
      i = 0;
    }
  }
  cout << "\n";
}


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

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

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

struct UF {
  public:
    vector<int> p;
    UF(int n) {
        p = vi(n);
        iota(all(p), 0);
    }

    void unite(int i, int j) {
        p[root(j)] = root(i);
    }

    bool same(int i, int j) {
        return root(i) == root(j);
    }

    int root(int i) {
        if (p[i] == i) {
            return i;
        } else {
            return p[i] = root(p[i]);
        }
    }

    // int count_trees() {
    //     set<int> s;
    //     for (auto e : p) {
    //         debug(root(e));
    //         s.insert(root(e));
    //     }
    //     return s.size();
    // }

    map<int, int> hoge(const vi &a) {
        map<int, int> mp;
        rep(e, p.size()) {
            // debug(root(e));
            if (mp[root(e)] == 0) {
                mp[root(e)] = a[e];
            } else {
                chmin(mp[root(e)], a[e]);
            }
        }
        return mp;
    }
};

const string NO = "Impossible";
void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> x, std::vector<long long> y) {
    UF uf(a.size());
    rep(i, M) {
        uf.unite(x[i], y[i]);
    }

    auto mp = uf.hoge(a);
    int cnt = mp.size();
    if ((cnt - 1) * 2 > a.size()) {
        cout << NO << endl;
        return;
    } else if (cnt == 1) {
        cout << 0 << endl;
        return;
    }

    int ans = 0;
    multiset<int> s;
    rep(i, a.size()) s.insert(a[i]);
    for (auto p : mp) {
        auto it = s.find(p.second);
        s.erase(it);
        ans += p.second;
    }
    sort(all(a));
    rep(i, cnt - 2) {
        auto it = s.begin();
        ans += *it;
        s.erase(it);
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> a(N - 1 - 0 + 1);
    for (int i = 0; i < N - 1 - 0 + 1; i++) {
        scanf("%lld", &a[i]);
    }
    std::vector<long long> x(M);
    std::vector<long long> y(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
    }
    solve(N, M, std::move(a), std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 10368
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
    a_i,b_i=map(int,input().split())
    a.append(a_i)
    b.append(b_i)
for i in range(m):
    c_i,d_i=map(int,input().split())
    c.append(c_i)
    d.append(d_i)
for i in range(n):
    a_i=a[i]
    b_i=b[i]
    dis=-1
    for j in range(m):
        buf=abs(a_i-c[j])+abs(b_i-d[j])
        if dis<0 or buf<dis:
            dis=buf
            ans=j+1
    print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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 main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int A,B; cin >> A >> B;
    cout << 6-A-B << endl;
}

Measured memory_bytes: 256
# coding: utf-8
X,N=map(int,input().split())
P=[]
if N!=0:
    P=list(map(int,input().split()))
K=[]
for i in range(102):
    if not(i in P):
        K.append(i)

ans=[]

for i in range(len(K)):
    ans.append([abs(X-K[i]),K[i]])

ans.sort()

A=[]

for i in range(len(ans)):
    if ans[i][0]==ans[0][0]:
        A.append(ans[i][1])

print(min(A))

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

int main() {
    string s, t;
    int q;
    cin >> s >> t >> q;
    int sp[s.size() + 1], tp[t.size() + 1];
    sp[0] = 0;
    for (int i = 1; i <= s.size(); i++) {
        if (s[i - 1] == 'A') {
            sp[i] = sp[i - 1] + 1;
        } else {
            sp[i] = sp[i - 1] + 2;
        }
    }
    tp[0] = 0;
    for (int i = 1; i <= t.size(); i++) {
        if (t[i - 1] == 'A') {
            tp[i] = tp[i - 1] + 1;
        } else {
            tp[i] = tp[i - 1] + 2;
        }
    }
    for (int a, b, c, d; cin >> a >> b >> c >> d; ) {
        int left = sp[b] - sp[a - 1], right = tp[d] - tp[c - 1];
        if (left % 3 == right % 3) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] Table = new int[r][c];
        for(int i=0; i<r; i++){
            for(int j=0; j<c; j++){
                Table[i][j] = sc.nextInt();
            }
        }
        int[] gyouTotal = new int[r];
        int[] retsuTotal = new int[c];
        int total = 0;
        for(int i=0; i<r; i++){
            for(int j=0; j<c; j++){
                gyouTotal[i] += Table[i][j];
            }
        }
        for(int i=0; i<c; i++){
            for(int j=0; j<r; j++){
                retsuTotal[i] += Table[j][i];
            }
        }
        for(int i=0; i<c; i++){
            total += retsuTotal[i];
        }
        for(int i=0; i<r; i++){
            for(int j=0; j<c; j++){
                System.out.print(Table[i][j] + " ");
            }
            System.out.println(gyouTotal[i]);
        }
        for(int i=0; i<c; i++){
            System.out.print(retsuTotal[i] + " ");
        }
        System.out.println(total);

    }
}


Measured memory_bytes: 42232
from collections import deque
h, w = map(int, input().split())
cnt_b = 0
s = []
for i in range(h):
    si = input()
    cnt_b += si.count('#')
    s.append(si)

def bfs(i0, j0):
    INF = 1000
    search = deque([(i0, j0)])
    d = [[INF] * w for i in range(h)]
    d[i0][j0] = 1
    while search:
        i, j = search.popleft()
        if (i, j) == (h - 1, w - 1):
            break
        for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            ni, nj = i + di, j + dj
            if 0 <= ni < h and 0 <= nj < w and s[ni][nj] == '.' and d[ni][nj] == INF:
                search.append((ni, nj))
                d[ni][nj] = d[i][j] + 1
    return d[i][j] if d[h - 1][w - 1] != INF else 0 
solvable = bfs(0, 0)
print(h*w - cnt_b - solvable if solvable else -1)

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

template <typename T> inline void read (T &x) {bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');
if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x<<3) + (x<<1) + c - 48; if (b)x=-x;}
template <typename T> inline void wrip(T x) {if (x > 9) wrip(x / 10); putchar(x%10 + 48); }

template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar(' ');}
template <typename T> inline void writeln(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar('\n');}
inline char readch() {char c; do c = getchar(); while (c == '\n' || c == ' '); return c;}
inline void reads(string &s) {char c; while((c=getchar())==' '||c =='\n'); s=c; while((c=getchar())!=' '&&c!='\n') s+=c;}
inline void getlines(string &s) {char c; while((c=getchar())=='\n'); s=c; while((c=getchar())!='\n') s+=c;}
typedef const int csint;

#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;

const ld pi = acos(-1);
const int inf = 1e9;
const int N = 1e5 + 11;

int n, m, q, a[N], b[N];
int main() {
    #ifdef makacha
        freopen("m.inp", "r", stdin);
        freopen("m.out", "w", stdout);
    #endif // makacha
    read(n);
    read(m);
    read(q);
    int mina = inf, minb = inf;
    for (int i = 1; i <= n; i++) {
        read(a[i]);
        mina = min(mina, a[i]);
    }
    for (int i = 1; i <= m; i++) {
        read(b[i]);
        minb = min(minb, b[i]);
    }
    int res = mina + minb;
    for (int i = 1, c, x, y; i <= q; i++) {
        read(x);
        read(y);
        read(c);
        res = min(res, a[x] + b[y] - c);
    }
    cout << res;
}


Measured memory_bytes: 1024
a,b,c,d = map(int, input().split())
i = 0
while True:
  if i % 2 == 0:
    c -= b
    if c <= 0:
      print('Yes')
      exit()
  else:
    a -= d
    if a <= 0:
      print('No')
      exit()
  i += 1
    

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int s;
  cin>>s;
  vector<int> a(1000001);
  a[1]=s;
  for(int i=2;i<1000001;i++){
    if(a[i-1]%2==0){
      a[i]=a[i-1]/2;
    }
    if(a[i-1]%2==1){
      a[i]=a[i-1]*3+1;
    }
  }
  for(int i=2;i<1000001;i++){
    for(int j=0;j<i;j++){
      if(a[i]==a[j]){
        cout<<i<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 7228
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func binarySearch(a []int, key int) int {
	l, r := -1, len(a)-1
	for r-l > 1 {
		mid := (l + r) / 2
		if a[mid] < key {
			r = mid
		} else {
			l = mid
		}
	}
	return r
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	colors := make([]int, n)
	for i := range colors {
		colors[i] = -1
	}
	for i := range a {
		x := binarySearch(colors, a[i])
		colors[x] = a[i]
	}

	ans := 0
	for i := range colors {
		if colors[i] < 0 {
			break
		}
		ans++
	}

	puts(ans)
}


Measured memory_bytes: 3968
#include <stdio.h>

int main (){
	float a,b,c,d,e,f,x,y,t;
	while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f)!=EOF){
		t=d/a;
		e=e-b*t;
		f=f-c*t;
		y=f/e;
		x=(c-b*y)/a;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> h(n+1);
    rep1(i,n) cin >> h[i];
    int sum = 0;
    rep(i,n) sum += max(h[i+1]-h[i],0);
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	while(n){
		n /= k;
		ans++;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long k,a,b;
int main() {
	ios::sync_with_stdio(false);
	cin >> k >> a >> b;
	if(k <= a)
		cout << "1\n";
	else if(a <= b)
		cout << "-1\n";
	else
		cout << (k - b - 1) / (a - b) * 2 + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
  
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
  
const int MAX_V=100010; //????????????
  
struct edge {
    int to, cap, rev;
};
  
vector<edge> G[MAX_V];
bool used[MAX_V];
  
void add_edge(int from, int to, int cap)
{
    G[from].pb((edge){to, cap, (int)G[to].size()});
    G[to].pb((edge){from, 0, (int)G[from].size()-1});
}
  
int dfs(int s, int t, int f)
{
    if(s==t) return f;
    used[s]=true;
    rep(i, G[s].size())
    {
        edge &e=G[s][i];
        if(!used[e.to] && e.cap>0)
        {
            int d=dfs(e.to, t, min(f, e.cap));
            if(d>0)
            {
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
  
int max_flow(int s, int t)
{
    int flow=0;
    while(1)
    {
        memset(used, 0, sizeof(used));
        int f=dfs(s, t, INF);
        if(f==0) return flow;
        flow+=f;
    }
}
  
int main()
{
    int v, e;
    cin >> v >> e;
    int a, b, c;
    rep(i, e)
    {
        cin >> a >> b >> c;
        add_edge(a, b, c);
    }
    cout << max_flow(0, v-1) << endl;
    return 0;
}

Measured memory_bytes: 5624
#include<stdio.h>
int main(void){
int x,i,y;
for (i=0;i<3000;i++){
    scanf("%d %d",&x,&y);
    if (x==0&&y==0){ break;}
    else if (x>y){
    printf("%d %d\n",y,x);}
    else{
        printf("%d %d\n",x,y);
    }
}
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
using namespace std;
 
int main ()
{
  char c;cin >> c;
  if(c == 'A')
      cout << "T";
  else if(c == 'C')
      cout << 'G';
  else if(c == 'T')
      cout << 'A';
  else if (c =='G')
  cout << 'C';
    return 0;
}
// ans = 1 + 1 + - 1 + 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
int n,k;
int a[N];
int main() {
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    int ans=2e9+7;
    for (int i=1;i<=n-k+1;i++) {
        int j=i+k-1;
        if (a[i]>0) ans=min(ans,a[j]);
        else if (a[j]<0) ans=min(ans,abs(a[i]));
             else ans=min(ans,min(abs(a[i])*2+a[j],a[j]*2+abs(a[i])));
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    X,A=mi()
    print(0 if X<A else 10)





if __name__ == "__main__":
    main()

Measured memory_bytes: 61832
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string a;
	while(cin>>a){
	
		int cnt=0;
		int cnt1=0;
		
		for(int i=0;i<a.size();i++){
			if(a[i]=='J'&&a[i+1]=='O'&&a[i+2]=='I'){
				cnt++;
			}
			if(a[i]=='I'&&a[i+1]=='O'&&a[i+2]=='I'){
				cnt1++;
			}
		}
		cout<<cnt<<endl;
		cout<<cnt1<<endl;
	}
	return 0;
}
		


Measured memory_bytes: 3076
n = int(input())
lst = []
for i in range(n):
    x, l = map(int, input().split())
    lst.append((x + l, x - l))

sorted_lst = sorted(lst)
num = 0
ans = n
while True:
    tmp = sorted_lst[num][0]
    for i in range(num + 1, n):
        if tmp > sorted_lst[i][1]:
            ans -= 1
        else:
            num = i
            break
        if i == n - 1:
            num = i
            break
    if num == n - 1:
        break

print(ans)

Measured memory_bytes: 56032
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }

  getChildrenNumber() {return Number(this.left !== null) + Number(this.right !== null);}

  isLeftChild() {
    if (this.parent === null) return null;
    return this.parent.left === this;
  }

  getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

  getSuccessor() {
    let n;
    if (this.right !== null) {
      n = this.right;
      while (n.left !== null) n = n.left;
    } else {
      n = this.parent;
      while (!n.isLeftChild && n.parent != null) n = n.parent;
    }
    return n;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key, n = this.root) {
    if (n === null || n.key === key) return n;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  delete(key) {
    const n = this.find(key);
    const leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      const skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



Measured memory_bytes: 204176
//
//  main.c
//  Hello_world
//
//  Created by 関根　歩 on 2014/06/16.
//  Copyright (c) 2014年 Ayumu Sekine. All rights reserved.
//
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a > b){
        printf("a > b\n");
    }else if(a == b){
        printf("a == b\n");
    }else{
        printf("a < b\n");
    };
    return 0;
}

Measured memory_bytes: 580
/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

ll MOD = 1e9 + 7;

int main()
{



  ll n;
  cin >> n;
  ll arr[n];
  for (int i = 0; i < n; i++)cin >> arr[i];

  vector<ll>pref(n + 1);
  pref[0] = 0;
  for (int i = 1; i <= n; i++)
  {
    pref[i] = (pref[i - 1] + arr[i - 1]);
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++)
  {
    ll yy = pref[n] - pref[i + 1];
    ll xx = ((yy % MOD) * arr[i]) % MOD;
    ans = (ans + xx) % MOD;
  }
  cout << ans << endl;


}







Measured memory_bytes: 6380
using System;

namespace tst
{
    class Program
    {
        public static void Main()
        {
            string[] In1 = Console.ReadLine().Split(' ');
            int k = int.Parse(In1[0]);
            int n = int.Parse(In1[1]);
            string[] In2 = Console.ReadLine().Split(' ');
            int[] A=new int[n];
            int max = 0;
            for(int i=0; i<n; i++)
            {
                A[i] = int.Parse(In2[i]);
            }
            //家と家の距離
            int[] D = new int[n];
            for(int i=0; i<n; i++)
            {
                if (i == n - 1) D[i] = k-A[i]+A[0];
                else D[i] = A[i + 1] - A[i];
                if (D[i] > max) max = D[i];
            }
            Console.WriteLine(k - max);
        }
    }
}

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

#define ll long long
#define ar array

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

	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if(s[0]==s[2])
		cout << "No";
	else
		cout << "Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[400001],b[400001],ta[400001],tb[400001],l=1,r=1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),ta[a[i]]++;
	for(int i=1;i<=n;i++)scanf("%d",&b[i]),tb[b[i]]++;
	for(int i=1;i<=n;i++)if(ta[i]+tb[i]>n)puts("No"),exit(0);
	memset(b,0,sizeof(b));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=tb[i];j++)
		{
			while(b[l])++l;
			while(a[r]<=a[l]&&r<=n)++r;
			while(b[r])++r;
			if(a[l]!=i)b[l++]=i;
			else b[r++]=i;
		}
	}
	l=1;
	for(int i=n+1;b[i];i++)
	{
		while(b[l])++l;
		if(a[l]!=b[i])a[l]=b[i];
		else 
		{
			while(a[r=(rand()%n+1)]==b[i]||b[r]==a[l]);
			b[l]=b[r],b[r]=b[i];
		}
	}
	puts("Yes");
	for(int i=1;i<=n;i++)printf("%d ",b[i]);
	return 0;
}


Measured memory_bytes: 7716
#include<iostream>

using namespace std;

int main() {
  int n;
  int a[10000];
  int b[10000];
  
  while(cin >> n) {
    if(n == 0) {
      break;
    }

    for(int i = 0; i < n; i++ ){
      cin >> a[i] >> b[i];
    }

    int ans_a = 0;
    int ans_b = 0;
    for(int i = 0; i < n; i++) {
      if(a[i] < b[i]) {
        ans_b += a[i] + b[i];
      }else if(a[i] > b[i]) {
        ans_a += a[i] + b[i];
      }else {
        ans_a += a[i];
        ans_b += b[i];
      }
    }

    cout << ans_a << " " << ans_b << endl;
  }

  return 0;
}

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

int d[101]={0};

int main(void){

	while (true){
		int n;
		cin>>n;
		if (cin.eof()) break;
		d[n]++;
	}
	int tmp=d[0];
	for (int i=0; i<101; i++) if (d[i]>tmp) tmp=d[i];
	for (int i=0; i<101; i++) if (d[i]==tmp) cout<<i<<endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n;
    cin>>n;
    vi a(n);
    int sum=0;
    REP(i,n){
        int buf;
        cin>>buf;
        sum+=buf;
        a[i]=sum;
    }
    sum=0;
    ll ans1=0,ans2=0;
    int ofs;
    REP(i,n){
        if(i%2){
            if((a[i]+sum)>=0){
                ofs=abs(a[i]+sum)+1;
                ans1+=ofs;
                sum-=ofs;
            }
        }else{
            if((a[i]+sum)<=0){
                ofs=abs(a[i]+sum)+1;
                ans1+=ofs;
                sum+=ofs;
            }
        }
        //cout<<a[i]+sum<<" ";
    }

    sum=0;
    REP(i,n){
        if(!(i%2)){
            if((a[i]+sum)>=0){
                ofs=abs(a[i]+sum)+1;
                ans2+=ofs;
                sum-=ofs;
            }
        }else{
            if((a[i]+sum)<=0){
                ofs=abs(a[i]+sum)+1;
                ans2+=ofs;
                sum+=ofs;
            }
        }
        //cout<<a[i]+sum<<" ";
    }

    //cerr<<ans1<<" "<<ans2<<endl;
    cout<<min(ans1,ans2)<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    vector<ll> a(n+1); rep(i,n+1) a[i] = 0;

    rep(i,m){
        ll b;
        cin >> b;
        a[b] = 1;
    }

    ll dp[100100]; rep(i,100100) dp[i] = 0;
    dp[0] = 1;
    if(a[1] == 0) dp[1] = 1;

   for (int i = 2; i <= n; ++i) {
        if (a[i-1] == 0) dp[i] += dp[i-1];
        if (a[i-2] == 0) dp[i] += dp[i-2];
        dp[i] %= 1000000007; 
    }

    dunk(dp[n]);
}



Measured memory_bytes: 1792
n,h = map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
b = sorted(b, reverse=True)
a_max = max(a)
for i in b:
    if h>0:
        if i>a_max:
            h-=i
            ans+=1
    else:
        print(ans)
        exit()
if h<0:
    print(ans)
else:
    ans += -(-h//max(a))
    print(ans)

Measured memory_bytes: 62296
/*ex3_2
    takafumi_ueki*/
#include <stdio.h>
int main(void){
    int x;
    scanf("%d",&x);
    //Aを10割った余り、つまり1の位が何かによって条件分岐
    //”||”は、またはという意味
        if((x%10 == 2)||(x%10 == 4)||(x%10 == 5)||(x%10 == 7)||(x%10 == 9)){
        printf("hon\n");
    }
    if((x%10 == 0)||(x%10 == 1)||(x%10 == 6)||(x%10 == 8)){
        printf("pon\n");
    }
    if(x%10 == 3){
        printf("bon\n");
    }
    return 0;
}


Measured memory_bytes: 1624
#include <bits/stdc++.h>
#define MAX (ll)(3e5 + 7)
#define INF (ll)(1e5 + 7)
#define MOD (ll)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;

int main () {
	double n;
	cin >> n;
	double x = n / 3;
	double ans = x * x * x;
	cout << setprecision (10) << ans << "\n";
}


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 154 B - I miss you...
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/30
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

char s[100];

void solve() {

    char *ptr;
    ptr = &s[0];

    while (*ptr ^ '\0') {
        printf("x");
        ptr++;
    }
    printf("\n");
}

int main() {

    scanf("%s", s);

    solve();

}

Measured memory_bytes: 3128
h, w = list(map(int, input().split()))

zero1 = "0" * (w + 2)
zero2 = "0" * (w + 2)

table = [zero1]
for _ in range(h):
    table.append("0" + str(input()) + "0")

table.append(zero2)

new_table = [[0 for _ in range(w)] for _ in range(h)]

outputs = []
for r in range(1, h+1):
    output = ""
    for c in range(1, w+1):
        if table[r][c] == ".":

            ll = table[r-1][c-1:c+2] + table[r][c-1:c+2] + table[r+1][c-1:c+2]
            count = 0
            for e in ll:
                if e == "#":
                    count += 1

        else:
            count = "#"

        output = output + str(count)

    outputs.append(output)

for op in outputs:
    print(op)


Measured memory_bytes: 3192