akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


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

const Int MOD = 1000000007;

const int MAXN = 1000000;
Int fact[MAXN], inv[MAXN];

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

void init_fact() {
    fact[0] = 1;
    for(int i=1; i<MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
    for(int i=MAXN - 2; i>=0; i--) {
        inv[i] = (inv[i+1] * (i+1)) % MOD;
    }
}

Int comb(int n, int r) {
    if(r < 0 || n < r) return 0;
    return fact[n] * inv[n-r] % MOD * inv[r] % MOD;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

string s;
stack<int> st;

int main(){
    cin.tie(0);

    int n; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    int ma = 0;
    for (int i = 0; i < n; i++){
        if (ma < p[i]){
            for (int j = 0; j < p[i]-ma; j++){
                s.push_back('(');
            }
            s.push_back(')');
            ma = p[i];
        }else{
            s.push_back(')');
        }
    }
    int op = 1;
    int cl = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == '(') st.push(op++);
        else{
            if (st.empty()){ 
                s = ":(";
                break;
            }else{
                if (p[cl] != st.top()){
                    s = ":(";
                    break;
                }else{
                    cl++;
                    st.pop();
                }
            }
        }
    }

    cout << s << endl;

    

    return 0;

}




Measured memory_bytes: 3740
N = int(input())
restaurants = list()
for i in range(1, N+1) :
    s, p = input().split()
    r = { 'i' : i, 's' : s, 'p' : int(p) }
    restaurants.append(r)

restaurants.sort(key=lambda r : (r['s'], -r['p']))

for r in restaurants :
    print(r['i'])


Measured memory_bytes: 3060
/* コッホ曲線　異なる三点を決めて二つを頂点とする */
#include<math.h>
#include<stdio.h>
struct Point{
double x,y;
};
double theata = M_PI*60.0/180.0;

void koch(int num, struct Point p1, struct Point p2){
    struct Point s,t,u;
    //printf("Debug:%d %f %f ",num,p1.x,p2.x);
    if(num==0){
        return ;
    }

    s.x=(2.0*p1.x+1.0*p2.x)/3.0;
    s.y=(2.0*p1.y+1.0*p2.y)/3.0;
    t.x=(1.0*p1.x+2.0*p2.x)/3.0;
    t.y=(1.0*p1.y+2.0*p2.y)/3.0;
    u.x=(t.x-s.x)*cos(theata)-(t.y-s.y)*sin(theata)+s.x;
    u.y=(t.x-s.x)*sin(theata)+(t.y-s.y)*cos(theata)+s.y;

    /* p1とp2から s,t,u を計算 再帰的に求める*/
    koch(num-1,p1,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(num-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(num-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(num-1,t,p2);
}

int main(){
    struct Point p1,p2;\
    int num;
    p1.x=0;
    p1.y=0;
    p2.x=100;
    p2.y=0;
    scanf("%d",&num);
    //端点
    printf("%.8f %.8f\n",p1.x,p1.y);
    koch(num,p1,p2);
    //端点
    printf("%.8f %.8f\n",p2.x,p2.y);

    return 0;
}


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

int H, W;

void BFS(vector<vector<char>> &S, queue<vector<int>> &q, int *max) {
    // ある地点からスタートして、各マスへは最短ステップで移動している
    // countが最大のものが、最も遠いゴールへのステップ数になる
    int count = q.front()[0];
    int h = q.front()[1];
    int w = q.front()[2];
    *max = count;
    q.pop();
    if (h > 0 && S[h - 1][w] != '#') {
        q.push(vector<int>{ count + 1, h - 1, w });
        S[h - 1][w] = '#';
    }
    if (h < H - 1 && S[h + 1][w] != '#'){
        q.push(vector<int>{ count + 1, h + 1, w });
        S[h + 1][w] = '#';
    }
    if (w > 0 && S[h][w - 1] != '#') {
        q.push(vector<int>{ count + 1, h, w - 1 });
        S[h][w - 1] = '#';
    }
    if (w < W - 1 && S[h][w + 1] != '#') {
        q.push(vector<int>{ count + 1, h, w + 1 });
        S[h][w + 1] = '#';
    }
    if(!q.empty())BFS(S, q, max);
}

int main() {
    cin >> H >> W;
    vector<vector<char>> S(H, vector<char>(W));

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++)cin >> S[i][j];
    }

    vector<vector<char>> s = S;

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] != '#') {
                int max = 0;
                queue<vector<int>> q;
                q.push(vector<int>{0, i, j});
                s[i][j] = '#';
                BFS(s, q, &max);
                if (ans < max)ans = max;
                s = S;
            }
        }
    }
    cout << ans;

}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

import static java.util.stream.Collectors.joining;

// Solution
public class Main {
  private static Scanner in;
  private static PrintWriter out;
  private static final String INPUT = ""; // input file name

  /**
   * Interactive get next command
   */
  static int get(int pos) {
    out.println(pos + 1);
    out.flush();
    return ni();
  }

  static void solve() {
    char[] a = ns().toCharArray();
    char[] b = ns().toCharArray();

    int[][] dp = new int[a.length + 1][b.length + 1];

    for (int i = 1; i <= a.length; i++) {
      for (int j = 1; j <= b.length; j++) {
        if (a[i - 1] == b[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else {
          dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
        }
      }
    }

    int x = a.length, y = b.length;

    StringBuilder sb = new StringBuilder();
    while (x > 0 && y > 0) {
      if (dp[x - 1][y] == dp[x][y -1] && dp[x][y] == dp[x-1][y-1] + 1) {
        sb.append(a[x - 1]); // b[y - 1] also works
        x--;
        y--;
      } else if (dp[x - 1][y] > dp[x][y -1]) {
        x--;
      } else {
        y--;
      }
    }

    out.print(sb.reverse().toString());
  }

  public static void main(String[] args) throws Exception {
    long S = System.currentTimeMillis();
    in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
    out = new PrintWriter(System.out);

    solve();
    out.flush();
    long G = System.currentTimeMillis();
    tr(G - S + "ms");
  }

  private static int gcd(int a, int b) {
    while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }

    return a;
  }

  private static int ni() {
    return Integer.parseInt(in.next());
  }

  private static String ns() {
    return in.nextLine();
  }

  private static long nl() {
    return Long.parseLong(in.next());
  }

  // Math Utils
  private static int pi(int num, int pow) {
    int result = 1;

    while (pow > 0) {
      if (pow % 2 == 1) {
        result *= num;
      }

      num *= num;
      pow /= 2;
    }

    return result;
  }

  private static int pim(int num, int pow, int mod) {
    int result = 1;

    while (pow > 0) {
      if (pow % 2 == 1) {
        // keep collecting `odd` num in result
        result = (result * num) % mod;
      }

      num = (num * num) % mod;
      pow /= 2;
    }

    return result;
  }

  private static long pl(long num, long pow) {
    long result = 1;

    while (pow > 0) {
      if (pow % 2 == 1) {
        result *= num;
      }

      num *= num;
      pow /= 2;
    }

    return result;
  }

  private static long plm(long num, long pow, long mod) {
    long result = 1;

    while (pow > 0) {
      if (pow % 2 == 1) {
        // keep collecting `odd` num in result
        result = (result * num) % mod;
      }

      num = (num * num) % mod;
      pow /= 2;
    }

    return result;
  }

  static void tr(Object... o) {
    if (!INPUT.isEmpty())
      out.println(Arrays.deepToString(o));
  }
}


Measured memory_bytes: 81228
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val M = IntArray(N) { 0 }
    var min = Int.MAX_VALUE
    var ans = 0
    for (i in 0 until N) {
        if (min > A[i]) min = A[i]
        M[i] = min
        if (A[i] == M[i]) ans += 1
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 82936
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x[3],d,e,a,b,c,f=0,g;
    scanf("%d%d%d",&a,&b,&c);
    x[0]=abs(a-b);
    x[1]=abs(b-c);
    x[2]=abs(a-c);
    sort(x,x+3);
    f=x[0]+x[1];
    printf("%d",f);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    
    int key;
    
    Node *next, *prev;
    
};

Node *nil;

Node* listSearch(int key) {
    
    Node *cur = nil -> next;
    
    while (cur != nil && cur -> key != key) {
        
        cur = cur -> next;
        
    }
    
    return cur;
    
}

void init() {
    
    nil = (Node *)malloc(sizeof(Node));
    
    nil -> next = nil;
    
    nil -> prev = nil;
    
}

void printList() {
    
    Node *cur = nil -> next;
    
    int isf = 0;
    
    while (1) {
        
        if (cur == nil) break;
        
        if (isf ++ > 0) {
            
            printf(" ");
            
        }
        
        printf("%d", cur -> key);
        
        cur = cur -> next;
        
    }
    
    printf("\n");
    
}

void deleteNode(Node *t) {
    
    if (t == nil) return;
    
    t -> prev -> next = t -> next;
    
    t -> next -> prev = t -> prev;
    
    free(t);
    
}

void deleteFirst() {
    
    deleteNode(nil -> next);
    
}

void deleteLast() {
    
    deleteNode(nil ->prev);
    
}

void deleteKey(int key) {
    
    deleteNode(listSearch(key));
    
}

void insert(int key) {
    
    Node *x = (Node *)malloc(sizeof(Node));
    
    x -> key = key;
    
    x -> next = nil -> next;
    
    nil -> next -> prev = x;
    
    nil -> next = x;
    
    x -> prev = nil;
    
}

int main() {
    
    int key, n, i;
    
    int size = 0;
    
    char com[20];
    
    int np = 0, nd = 0;
    
    scanf("%d", &n);
    
    init();
    
    for (i = 0; i < n; i ++) {
        
        scanf("%s%d", com, &key);
        
        if (com[0] == 'i') {
            
            insert(key);
            
            np ++;
            
            size ++;
            
        } else if (com[0] == 'd') {
            
            if (strlen(com) > 6) {
                
                if (com[6] == 'F') {
                    
                    deleteFirst();
                    
                } else if (com[6] == 'L') {
                    
                    deleteLast();
                    
                }
                
            } else {
                
                deleteKey(key);
                
                nd ++;
                
            }
            
            size --;
            
        }
        
    }
    
    printList();
    
    return 0;
    
}


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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fir first
#define sec second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 200;
const int MAXM = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EXP = 1e-8;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll mulit(ll a, ll b, ll m)
{
    ll ans = 0;
    while (b)
    {
        if (b & 1)
            ans = (ans + a) % m;
        a = (a << 1) % m;
        b >>= 1;
    }
    return ans;
}
ll quick_mod(ll a, ll b, ll m)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = mulit(ans, a, m);
        a = mulit(a, a, m);
        b >>= 1;
    }
    return ans;
}
ll c(ll a, ll b, ll m)
{
    if (a < b)
        return 0;
    if (a == b)
        return 1;
    if (b > a - b)
        b = a - b;
    ll ans = 1, ca = 1, cb = 1;
    for (int i = 0; i < b; i++)
    {
        ca = ca * (a - i) % m;
        cb = cb * (b - i) % m;
    }
    ans = ca * quick_mod(cb, m - 2, m) % m;
    return ans;
}

ll lucas(ll a, ll b, ll m)
{
    ll ans = 1;
    while (a && b)
    {
        ans = (ans * c(a % m, b % m, m)) % m;
        a /= m;
        b /= m;
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    ll s = quick_mod(2, n, MOD);
    ll ss = (lucas(n, a, MOD) + lucas(n, b, MOD)) % MOD;
    if (s < ss)
        s = s + MOD - ss;
    else
        s -= ss;
    cout << s - 1;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
a = [INT() for _ in range(M)]
b = [0] * (N+1)  # こわれているところに１たてる
for i in a:
	b[i] = 1

dp = [0]*(N+1)
dp[0] = 1
if b[1] == 1:
	dp[1] = 0
else:
	dp[1] = 1

for i in range(2, N+1):
	if b[i] == 1:  # こわれてる
		dp[i] = 0
	else:
		dp[i] = (dp[i-1] + dp[i-2])%MOD

print(dp[N])



Measured memory_bytes: 9336
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;



int main(){
    int count=0;
    int n;
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        a.push_back(--b);
    }
    for(int i=0;i<n-1;i++){
        int t=n-1-i;
        if(a[i]==i){swap(a[i],a[i+1]); count++;}
        if(a[t]==t){swap(a[t],a[t-1]); count++;}
    }
    cout<<count<<endl;
    
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h1,h2,k1,k2,a,b,c,d,suma,sumb;
  cin>>h1>>h2>>k1>>k2>>a>>b>>c>>d;
  suma=h1*a+h1/10*c+h2*b+h2/20*d;
  sumb=k1*a+k1/10*c+k2*b+k2/20*d;
  if(suma>sumb) cout<<"hiroshi"<<endl;
  else if(suma<sumb) cout<<"kenjiro"<<endl;
  else cout<<"even"<<endl;
  return 0;
}



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

int main()
{
  int64_t A, B, ans;
  cin >> A >> B;
  if (A % 2 == 0 && B % 2 == 0)
    ans = (((B - A) / 2) % 2) ^ B;
  else if (A % 2 == 0 && B % 2 == 1)
    ans = ((B - A + 1) / 2) % 2;
  else if (A % 2 == 1 && B % 2 == 0)
    ans = A ^ ((B - A - 1) / 2 % 2) ^ B;
  else
    ans = A ^ ((B - A) / 2 % 2);
  cout << ans << endl;
}


Measured memory_bytes: 256
module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Array
import           Data.Char
import           Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine

main = do
  n <- readInteger
  print $ if n `mod` 2 == 1 then 0 else count n 10 5

count n d m
  | n < d = 0
  | otherwise = n `div` d + count n (d * m) m


Measured memory_bytes: 380
import Control.Applicative
import Control.Monad
import Data.List

f :: (Int, Int) -> (Int, Int) -> (Int, Int)
f (t1, a1) (t2, a2) = head as
  where
    mi = maximum [1, t1 `div` t2, a1 `div` a2]
    as = dropWhile (\(t, a) -> t1 > t || a1 > a)
            [(t2 * i, a2 * i) | i <- [mi .. ]]

main :: IO ()
main = do
    n <- readLn
    tas <- replicateM n $ do
        [t, a] <- fmap read . words <$> getLine :: IO [Int]
        return (t, a)
    let ans = foldl1' f tas
    print $ fst ans + snd ans

Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

	
	public static void main(String[] args) {
		
		
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
		
			
		if(c-a+b>0) {
		    System.out.println(c-a+b);
		}else {
			System.out.println(0);
		}
		
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class SCC{
private:
	vector<vector<int> > gg, rg;
	vector<int> order, comp;
	vector<bool> used;
	vector<vector<int> > ng;
public:
	SCC(int v) : gg(v), rg(v), comp(v, -1), used(v, 0){}

	void add_edge(int x, int y){
		gg[x].push_back(y);
		rg[y].push_back(x);
	}

	int operator[](int k){
		return comp[k];
	}

	void dfs(int v){
		used[v] = true;
		REP(i, gg[v].size()){
			if(!used[gg[v][i]]) dfs(gg[v][i]);
		}
		order.push_back(v);
	}

	void rdfs(int v, int k){
		used[v] = true;
		comp[v] = k;
		REP(i, rg[v].size()){
			if(!used[rg[v][i]]) rdfs(rg[v][i], k);
		}
	}

	int build(){
		REP(i, gg.size()){
			if(!used[i]) dfs(i);
		}
		fill(all(used), 0);
		int k = 0;
		for(int i = order.size()-1;i >= 0;i--){
			if(!used[order[i]]) rdfs(order[i], k++);
		}

		ng.resize(k, vector<int>());

		REP(i, gg.size()){
			REP(j, gg[i].size()){
				if(comp[i] != comp[gg[i][j]])
					ng[comp[i]].push_back(comp[gg[i][j]]);
			}
		}
		REP(i, ng.size()){
			sort(all(ng[i]));
			ng[i].erase(unique(all(ng[i])), ng[i].end());
		}
		return k;
	}
	
	int size(){
		return ng.size();
	}
};

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

	int V, E;
	cin >> V >> E;
	SCC scc(V);

	REP(i, E){
		int s, t;
		cin >> s >> t;
		scc.add_edge(s, t);
	}
	scc.build();

	int Q;
	cin >> Q;
	REP(i, Q){
		int u, v;
		cin >> u >> v;
		cout << (scc[u] == scc[v]) << endl;
	}
}

Measured memory_bytes: 4440
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N, M;
    cin >> N >> M;
    std::vector<std::vector<long>> mat(N, vector<long>());
    long a, b;
    for(size_t i=0;i<M; i++)
    {
        cin >> a >> b;
        a--;b--;
        mat[a].push_back(b);
        mat[b].push_back(a);
    }
    bool ok=false;
    for(size_t i=0;i<mat[N-1].size(); i++)
    {
        long next_point = mat[N-1][i];
        cerr << next_point << endl;
        for(size_t j=0;j<mat[next_point].size(); j++)
        {
            long last_point = mat[next_point][j];
            cerr <<  last_point << endl;
            if(mat[next_point][j]==0) ok =true;
        }
    }
    if(ok) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 15620
N,x = map(int,input().split())
alis = list(map(int,input().split()))

ans = 0
for num in range(N-1):
	if alis[num] + alis[num+1] <= x: continue;
	
	if alis[num] > x:
		ans += alis[num] - x
		alis[num] = x
	if alis[num] + alis[num+1] > x:
		ans += alis[num]+alis[num+1] - x
		alis[num+1] -= alis[num]+alis[num+1] - x
print(ans)


Measured memory_bytes: 14592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

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

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

ll ans(ll h) {
    if (h < 1) return 0;
    if (h == 1) return 1;
    //if (cache.count(h)) return cache[h];
    return 1 + 2 * ans(h / 2);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    ll h;
    cin >> h;
    cout << ans(h);
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting, graph is not a tree/connected
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1000000007;
const long long INF = 1LL << 55;
const double EPS = 1e-10;

int main()
{
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;

    for (size_t i = 0; i < N; i++)
    {
        /* code */
        cout << S.at(i) << T.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    int n;cin>>n;
    vector<int> v(n);
    rep(i,0,n)cin>>v[i];
    sort(all(v));
    int ans=0;
    rep(i,0,n){
        ans+=v[i];
    }
    cout<<ans-(v.back()/2)<<endl;
}

Measured memory_bytes: 256
local read = io.read
local byte = string.byte
local N, L = read("*n", "*n")
read("*l")
local S = {}
for i = 1, N do
	local str = read("*l")
	S[i] = {byte(str, 1, L)}
	setmetatable(S[i], {__call = function() return str end})
end

local function isDict(s1, s2)
	for i = 1, L do
		if s1[i] < s2[i] then
			return true
		elseif s1[i] > s2[i] then
			return false
		end
	end
	return false
end

table.sort(S, isDict)
local out = ""
for i = 1, N do
	out = out..S[i]()
end

print(out)


Measured memory_bytes: 1152
using System;
using System.Linq;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NK[0]; var K = NK[1];
            var p = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Console.WriteLine(p.OrderBy(n => n).Take(K).Sum(n => n));
        }
    }
}


Measured memory_bytes: 28636
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))

D = defaultdict(list)

for i in range(N):
    D[A[i]].append(i)

next = [None for _ in range(N)]
dist = [None for _ in range(N)]

for v in D.values():
    l = len(v)
    for i in range(l):
        next[v[i]] = (v[(i + 1) % l] + 1) % N
        dist[v[i]] = (v[(i + 1) % l] - v[i] + N - 1) % N + 2

period = 0
node = 0

while node or not period:
    period += dist[node]
    node = next[node]

rem = N * K % period
count = 0
node = 0

while count + dist[node] <= rem:
    count += dist[node]
    node = next[node]

s = []
used = [0 for _ in range(10**6)]

for i in range(rem - count):
    j = (node + i) % N
    if not used[A[j] - 1]:
        used[A[j] - 1] = 1
        s.append(A[j])
    else:
        while True:
            p = s.pop()
            used[p - 1] = 0
            if p == A[j]:
                break

print(*s)

Measured memory_bytes: 142928
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    vi b = a;
    sort(all(b));
    int cnt = 0;
    rep(i,n)if(a[i] != b[i])cnt++;
    if(cnt>2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }

}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  string s;
  cin >> s;
  if ((!(s.size() & 1)) ^ (s[0] == s[s.size() - 1])) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }
  return 0;
}


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

int main(){
    for(int r=0; r<3; r++){
    	int bh,bm,bs,eh,em,es;
    	cin >> bh >> bm >> bs >> eh >> em >> es;
    	es -= bs;
    	if(es < 0){
    		es += 60;
    		em--;
    	}
    	em -= bm;
    	if(em < 0){
    		em += 60;
    		eh--;
    	}
    	eh -= bh;
    	cout << eh << " " << em << " " << es << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  const int MAXP = 999983;
  vector<bool> is_prime(MAXP + 1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i = 2; i * i <= MAXP; i++)if(is_prime[i]){
    if((ll)i * i <= MAXP){
      for(int j = i * i; j <= MAXP; j += i){
        is_prime[j] = false;
      }
    }
  }
  vector<int> acc(MAXP + 1, 0);
  for(int i = 1; i <= MAXP; i++){
    acc[i] = acc[i - 1] + (is_prime[i] ? 1 : 0);
  }
  int N;
  while(cin >> N && N != 0){
    int ans = 0;
    REP(i, N){
      int p, m; cin >> p >> m;
      int left = max(p - m, 1);
      int right = min(p + m, MAXP);
      int cnt = acc[right] - acc[left - 1];
      ans += cnt - 1;
    }
    if(ans < 0) ans = 0;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 5164
import java.util.*;

class Main{
    static PriorityQueue<Edge> pq;
    static HashSet<Edge>[] G;
    static boolean[] visited;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        G = new HashSet[N+1];
        visited = new boolean[N+1];
        for(int i=0;i<=N;i++) G[i] = new HashSet<>();
        int[][] IdXY = new int[N][3];
        for(int i=0;i<N;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            IdXY[i] = new int[]{i,x,y};
        }
        // Prim
        pq = new PriorityQueue<>();
        myComparator1 mc1 = new myComparator1();
        Arrays.sort(IdXY,mc1);
        for(int i=0;i<N-1;i++){ // sort by x-axis
            int a = Math.min(IdXY[i][0],IdXY[i+1][0]);
            int b = Math.max(IdXY[i][0],IdXY[i+1][0]);
            G[a].add(new Edge(b,IdXY[i+1][1]-IdXY[i][1]));
            G[b].add(new Edge(a,IdXY[i+1][1]-IdXY[i][1]));

        }
        myComparator2 mc2 = new myComparator2();
        Arrays.sort(IdXY,mc2);
        for(int i=0;i<N-1;i++){ // sort by x-axis
            int a = Math.min(IdXY[i][0],IdXY[i+1][0]);
            int b = Math.max(IdXY[i][0],IdXY[i+1][0]);
            G[a].add(new Edge(b,IdXY[i+1][2]-IdXY[i][2]));
            G[b].add(new Edge(a,IdXY[i+1][2]-IdXY[i][2]));
        }
        long ans = 0;
        visit(0);
        while(pq.size()>0){
            Edge cur = pq.poll();
            if(!visited[cur.to]){
                ans += cur.length;
                visit(cur.to);
            }
        }
        System.out.println(ans);
    }
    static void visit(int i){
        visited[i]=true;
        for(Edge e:G[i]){
            if(!visited[e.to]) pq.add(e);
        }
    }
    static class Edge implements Comparable<Edge>{
        int to;
        int length;
        @Override
        public int compareTo(Edge e){
            return this.length-e.length;
        }
        Edge(int to, int cost){
            this.to=to;
            this.length=cost;
        }
    }
    static class myComparator1 implements Comparator<int[]>{
        public int compare(int[] o1, int[] o2){
            return o1[1]-o2[1];
        }
    }
    static class myComparator2 implements Comparator<int[]>{
        public int compare(int[] o1, int[] o2){
            return o1[2]-o2[2];
        }
    }
}


Measured memory_bytes: 104752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br =	new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int number = Integer.parseInt(line);
		String[] in = br.readLine().split(" ");
		ArrayList<Integer> coordinate = new ArrayList<Integer>();
		int min = 1000;
		int max =0;

		for(int i = 0; i < in.length ;i++){
			coordinate.add(Integer.parseInt(in[i]));
		}

		for(int j =0; j < coordinate.size();j++){
			if(min > coordinate.get(j)){
				min = coordinate.get(j);	//1000からmax値を下げていく
			}
			if(max < coordinate.get(j)){
				max = coordinate.get(j);	//0からmin値を上げていく
			}
		}

		System.out.println(max - min);
	}
}

Measured memory_bytes: 21460
s = gets.chomp
n = s.size - 1
ans = 0
(1 << n).times do |i|
  num = s[0]
  n.times do |j|
    if (i >> j) & 1 == 0
      num << s[j + 1]
    else
      ans += num.to_i
      num = s[j + 1]
    end
  end
  ans += num.to_i
end
puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    int ans = 0;
    rep(i, n) {
        if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) ans += 2;
        else if (a[i] != b[i] || b[i] != c[i] || c[i] != a[i]) ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;

int main() {
  long long int n, k;
  cin >> n >> k;

  long long ans = 0;

  for (long long int i = k; i <= n + 1; i++)
    ans += (i * n - i * (i - 1) + 1) % MOD;

  cout << ans % MOD << endl;
}

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

using namespace std;

int main(){
    int a,b,c;
    cin >> a >>b >>c;
    int counter = 0;
    for(int i = a;i < (b+1);i++){
        if (c%i == 0) counter++;
    }
    cout << counter << "\n";
    return 0;
    
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
string unfair="Unfair";
int main()
{
  long long A,B,C,K;
  cin>>A>>B>>C>>K;
  long long ans=( (K%2==0)? A-B:B-A);
  if(ans>1e18) cout<<unfair;
  else cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int[] result = new int[N];
        for(int i = 1; i <= N; i++){
            for(int j = i + 1; j <= N; j++){
                int min = Integer.MAX_VALUE;
                if(min > Math.abs(j-i)) min = Math.abs(j-i);
                if(min > Math.abs(X-i) + 1 + Math.abs(j-Y)) min = Math.abs(X-i) + 1 + Math.abs(j-Y);
                if(min > Math.abs(Y-i) + 1 + Math.abs(j-X)) min = Math.abs(X-i) + 1 + Math.abs(j-Y);
                result[min]++;
            }
        }
        for(int i = 1; i < N; i++){
            System.out.println(result[i]);
        }
    }
} 

Measured memory_bytes: 23124
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H-h) * (W-w) << endl;
  return 0;
}


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

int m, n;
string s[128];

map<vector<int>,int> memo;

int dfs(vector<int> &idx){
  
  if( idx.size() <= 1 ) return 0;
  
  if( memo.count(idx) ) return memo[idx];
  
  int res = 12;
  
  for(int i=0;i<m;i++){
    
    vector<int> idx0, idx1;

    for(int j : idx){
      if(s[j][i]=='0') idx0.push_back(j);
      else idx1.push_back(j);
    }
    
    if( idx0.size() == 0 || idx1.size() == 0 ) continue;
    
    int A = dfs(idx0);
    int B = dfs(idx1);
    
    res = min( res, max( A , B ) );
    
  }

  return memo[idx] = res + 1;
}

int main(){
  
  while(1){
    
    cin>>m>>n;
    if(!m&&!n) break;
    
    vector<int> idx;
    
    for(int i=0;i<n;i++){
      cin>>s[i];
      idx.push_back(i);
    }
    
    memo.clear();
    
    cout<<dfs(idx)<<endl;
    
  }
  
  return 0;
}



Measured memory_bytes: 5444
// ref: https://img.atcoder.jp/abc125/editorial.pdf

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int64 abs_sum(const vector<int>& v){
    int64 ret=abs(v[0]);
    for(uint i=1; i<v.size(); ++i){ ret+=abs(v[i]); }
    return ret;
}
int64 min(int64 lhs, int64 rhs){ return (lhs<rhs ? lhs:rhs); }
int64 abs_min(const vector<int>& v){
    int64 ret=abs(v[0]);
    for(uint i=1; i<v.size(); ++i){ ret=min(ret, abs(v[i])); }
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N; cin >> N;
    vector<int> vA(N); for(uint i=0; i<N; ++i){ cin >> vA[i]; }
    
    int64 s = abs_sum(vA);
    int64 m = abs_min(vA);
    int64 minusNum = count_if(vA.begin(), vA.end(), [](int x){return x<0;} );
    
    cout << (minusNum&1 ? (s-2*m):s) << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
#define MAXN 200100
#define ll long long
ll n, sum[MAXN], ans, a[MAXN], t, mod=2019, cnt[MAXN], h[MAXN];
char s[MAXN];
int main()
{
	scanf("%s",s+1);
	n = strlen(s+1);
	for(ll i=1;i<=n;i++)
		a[i] = s[i]-'0';
	h[0] = 1;
	for(int i=1;i<=n;i++) h[i] = (h[i-1]*10)%mod;
	for(ll i=1;i<=n;i++)
	{
		t = (t*10%mod+a[i])%mod;
		sum[i] = t;
		sum[i] = (sum[i] * h[n-i]) % mod;
		cnt[sum[i]]++;
//printf("%d\n",sum[i]);
	}
	cnt[0]++;
	for(ll i=0;i<2019;i++)
	{
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 8732
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>

#define MAX_N 40

using namespace std;

int main(void){

	int N;
	char mark[MAX_N],Bmark[MAX_N],Smark[MAX_N];
	int  num[MAX_N], Bnum[MAX_N], Snum[MAX_N] ;
	char stable[20][MAX_N];
	int cnt[20];
	bool flag;
	int min_i;

	cin>>N;

	for(int i=0;i<20;i++){
		for(int j=0;j<MAX_N;j++){
			stable[i][j]='1';
		}
	}

	for(int i=0;i<20;i++) cnt[i]=0;
	for(int i=0;i<N;i++){
		cin>>mark[i]>>num[i];
		Bmark[i]=mark[i],Smark[i]=mark[i];
		Bnum[i]=num[i],Snum[i]=num[i];
		for(int j=0;j<20;j++){
			if(num[i]==j){
				stable[j][cnt[j]]=mark[i];
				cnt[j]++;
				break;
			}
		}
	}

	for(int i=0;i<N-1;i++){
		for(int j=N-1;j>i;j--){
			if(Bnum[j]<Bnum[j-1]){
				swap(Bnum[j],Bnum[j-1]);
				swap(Bmark[j],Bmark[j-1]);
			}
		}
	}

	flag=true;
	for(int i=0;i<20;i++) cnt[i]=0;
	for(int i=0;i<N-1;i++){
		cout<<Bmark[i]<<Bnum[i]<<" ";
		for(int j=0;j<20;j++){
			if(j==Bnum[i]){
				if(stable[j][cnt[j]]!=Bmark[i]){
					flag=false;
				}
				cnt[j]++;
				break;
			}
		}
	}
	cout<<Bmark[N-1]<<Bnum[N-1]<<endl;
	if(flag) cout<<"Stable"<<endl;
	else cout<<"Not stable"<<endl;
	

	for(int i=0;i<N-1;i++){
		min_i=i;
		for(int j=i;j<N;j++){
			if(Snum[j]<Snum[min_i]) min_i=j;
		}
		if(i!=min_i){
			swap(Snum[min_i],Snum[i]);
			swap(Smark[min_i],Smark[i]);
		}
	}

	flag=true;
	for(int i=0;i<20;i++) cnt[i]=0;
	for(int i=0;i<N-1;i++){
		cout<<Smark[i]<<Snum[i]<<" ";
		for(int j=0;j<20;j++){
			if(j==Snum[i]){
				if(stable[j][cnt[j]]!=Smark[i]){
					flag=false;
				}
				cnt[j]++;
				break;
			}
		}
	}
	cout<<Smark[N-1]<<Snum[N-1]<<endl;
	if(flag) cout<<"Stable"<<endl;
	else cout<<"Not stable"<<endl;

	return 0;
}

Measured memory_bytes: 1172
#include <iostream>

using namespace std;

int main(void){
  int A,B,C;
  cin >> A >> B >> C;
  bool found = false;
  for(int i=1; i<=B; i++){
    if(i*A%B == C){
      found = true;
    }
  }
  if(found){
    cout << "YES" << endl;
  } else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

vector<pair<int,int>> edge[100010];
// dp[i]:=白黒
int dp[100010];

void dfs(int from, int color){
    if(dp[from]!=-1) return;
    dp[from]=color;
    for(auto z:edge[from]){
        int to=z.first;
        int cost=z.second;
        if(cost) dfs(to,color^1);
        else dfs(to,color);
    }
}

int main(){
    rep(i,100010) dp[i]=-1;
    int n; cin>>n;
    for(int i=0;i<n-1;i++){
        int u,v,w; cin>>u>>v>>w;
        w%=2;
        edge[u].push_back({v,w});
        edge[v].push_back({u,w});
    }
    dfs(1,0);
    for(int i=1;i<=n;i++){
        cout<<dp[i]<<endl;
    }
    return 0;
}


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

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() {
    let s1: String = read();
    let s2: String = read();

    let s1_list: Vec<char> = s1.chars().collect::<Vec<char>>();
    let s2_list: Vec<char> = s2.chars().collect::<Vec<char>>();

    let mut ans: String = String::new();

    for elem in 0..s1.len() {
        if !(s1_list[elem] == s2_list[elem]) {
            ans.push(s1_list[elem]);
        }
    }

    println!("{}", ans.len());
}

Measured memory_bytes: 4156
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[200010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N, greater<int>());
	ll ans = 0;
	for (int i = 1; i < N; i++) {
		ans += A[i / 2];
	}
	cout << ans << endl;
}


Measured memory_bytes: 4416
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long a=20190430;
		String[] fruit = s.split("/", 0);
		String ans="";
		for(int i = 0; i<3; i++){
			ans+=fruit[i];
		}
		if(a<Long.parseLong(ans)){
			System.out.println("TBD");
		}else{
			System.out.println("Heisei");
		}
	}
}

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

int main(){
    long long a, b, k;
    cin >> a >> b >> k;
    long long res1, res2;
    res1 = a - k;
    if(res1 >= 0) res2 = b;
    else res2 = a + b - k;
    if(res1 < 0) res1 = 0;
    if(res2 < 0) res2 = 0;
    cout << res1 <<" " << res2 << endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}

int main(){
while(1){
ll n,m;
cin>>n>>m;
if(n==0&&m==0)return 0;
vector<ll> a(n+1),b;
for(int i=0;i<n;i++)cin>>a[i];
a.push_back(0);
for(int i=0;i<n+1;i++){
    for(int j=0;j<n+1;j++){
        b.push_back(a[i]+a[j]);
    }
}
ll ans=0;
sort(all(b));
for(int i=0;i<n*n;i++){
     ll tmp=m-b[i];
  // cout<<b[i]<<endl;
     int ite=upper_bound(all(b),tmp)-b.begin();
     if(ite==0||ite==n*n||b[i]+b[ite-1]>m)continue;
  //  cout<< b[i]+b[ite-1]<<endl;
     ans=max(ans,b[i]+b[ite-1]);
}
cout<<ans<<endl;
}
}



Measured memory_bytes: 19040
#include<iostream>

using namespace std;
bool search(int A[],int n,int key){
	int i=0;
	A[n]=key;
	while( A[i]!=key) i++;
	return i<n;
}
int  BinarySearch(int A[],int n,int key){
	int left=0;
	int right=n-1;
	int mid;
	while(left<=right){
		mid=(left+right)/2;
		if(A[mid]==key)return 1;
		if(A[mid]>key) right=mid-1;
		else left=mid+1;
	}
	return 0;
}
int main(){
	int n,m;
	cin>>n;
	int* S=new int[n+1];
	for(int i=0;i<n;++i)cin>>S[i];
	cin>>m;
	int *T=new int[m];
	for(int i=0;i<m;++i)cin>>T[i];
	int sum=0;
    for(int j=0;j<m;++j)
	  if(BinarySearch(S,n,T[j]))sum++;
    cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3672