akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

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

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	S := sc.nextStr()
	X, Y := sc.nextInt(), sc.nextInt()
	Ax := []int{}
	Ay := []int{}
	startX, startY := 0, 0
	count := 0
	isX := true
	isFirst := true
	for _, r := range S {
		if r == 'F' {
			count++
		} else {
			if count > 0 {
				if isX {
					if isFirst {
						startX += count
					} else {
						Ax = append(Ax, count)
					}
				} else {
					Ay = append(Ay, count)
				}
			}
			count = 0
			isX = !isX
			isFirst = false
		}
	}
	if count > 0 {
		if isX {
			if isFirst {
				startX += count
			} else {
				Ax = append(Ax, count)
			}
		} else {
			Ay = append(Ay, count)
		}
	}

	if f(X+8000, Ax, startX) && f(Y+8000, Ay, startY) {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
}

func f(target int, A []int, start int) bool {
	// 0: -8000, 8000: 0, 16000: 8000
	dp := make([][16001]bool, len(A)+1)
	dp[0][8000+start] = true
	for i := 1; i <= len(A); i++ {
		for j := 0; j <= 16000; j++ {
			if dp[i-1][j] {
				dp[i][j+A[i-1]] = true
				dp[i][j-A[i-1]] = true
			}
		}
	}
	return dp[len(A)][target]
}


Measured memory_bytes: 63232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const ll MAX = 200000;
ll inv[MAX], fac[MAX], finv[MAX];

void settable() {
   fac[0] = fac[1] = 1	;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX ; i++){
       fac[i] = fac[i - 1] * i % MOD;
       inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
   }
}
ll choose(ll n, ll k){
   if (n < k) return 0;
   if (n < 0 || k < 0) return 0;
   return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    settable();
    int n;
    cin >> n;
    vector<int> a(n+1);
    map<int, int> mp;
    for(int i = 0; i < n+1; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    int p[2];
    for(auto w : mp) {
        if(w.second == 2) {
            int f = 0;
            for(int i = 0; i < n+1; i++) {
                if(w.first == a[i]) p[f] = i, f++;
                if(f == 2) break;
            }
        } 
    }

    for(int i = 1; i <= n+1; i++) {
        ll ans = choose(n+1, i);
        if(p[0]+n-p[1] >= i-1) ans -= choose(p[0]+n-p[1], i-1);
      	ans += MOD;
      	ans %= MOD;
        cout << ans << endl;
    }
}

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

using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=2e3+10;

int n, m;
ll a[N], b[N], dp[N][N], sum[N][N];

int main() {
	cin>>n>>m;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=m; i++) cin>>b[i];
	a[0]=123456;
	b[0]=-123456;
	for(int i=0; i<=n; i++) {
		for(int j=0; j<=m; j++) {
			if (a[i]==b[j]) {
				dp[i][j]=1;
				if (i&&j) dp[i][j]+=sum[i-1][j-1];
				dp[i][j]%=mod;
			}
			else dp[i][j]=0;
			sum[i][j]=dp[i][j];
			if (i) sum[i][j]+=sum[i-1][j];
			if (j) sum[i][j]+=sum[i][j-1];
			if (i&&j) sum[i][j]-=sum[i-1][j-1];
			sum[i][j]=(sum[i][j]+mod)%mod;
		}
	}
	/*
	for(int i=0; i<=n; i++) {
		for(int j=0; j<=m; j++) {
			cout<<dp[i][j]<<' ';
		}
		cout<<endl;
	}
	*/
	cout<<sum[n][m]+1<<endl;
	return 0;
}


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

int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;

    int ans = 0;
    rep (i, n - 1)
        if (s[i] == s[i + 1])
            ans++;

    cout << min(ans + 2 * k, n - 1) << endl;
    return 0;
}

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

const ll INF = 1LL << 60;

string S;

int main() {
    cin >> S;

    // R, L, R, L

    // R: 0
    // L: 1 とする
    int current = 0;
    int cnt = 0;

    vector<ll> nums;

    for (int i = 0; i < S.size(); i++) {
        int judge = 0;
        if (S[i] == 'L') judge = 1; 

        if (judge == current) {
            cnt++;
        } else {
            nums.push_back(cnt);

            current = 1 - current; 
            cnt = 1;
        }
    }
    if (cnt != 0) nums.push_back(cnt);

    // for (int i = 0; i < nums.size(); i++) {
    //     cout << nums[i] << " ";
    // }
    // cout << endl;

    vector<ll> v(S.size(), 0);
    
    // idx: 0, 2, 4... -> R
    // idx: 1, 3, 5... -> L
    int start_pos = 0;

    // RL の組みづつ計算
    for (int i = 0; i < nums.size(); i += 2) {
        // R の奇数
        int r_odd = (nums[i] + 1) / 2;
        // L の偶数
        int l_even = nums[i + 1] / 2;

        // R の偶数
        int r_even = nums[i] / 2;
        // L の奇数
        int l_odd = (nums[i + 1] + 1) / 2;

        int left = r_odd + l_even;
        int right = r_even + l_odd;

        // cout << left << " " << right << endl;
        start_pos += nums[i] - 1;

        // v に代入
        v[start_pos] = left;
        v[start_pos + 1] = right;

        start_pos += nums[i + 1] + 1;
    } 

    rep(i, v.size()) {
        cout << v[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4912
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
from collections import defaultdict
# from collections import Counter
from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n,k=map(int,input().split())
	A=list(map(int,input().split()))
	S=[0]+list(accumulate(A))
	for i in range(n+1):
		S[i]-=i
		S[i]%=k
	
	dct=defaultdict(int)
	
	ans=0
	for j in range(n+1):
		dct[S[j]]+=1
		if j>=k:
			dct[S[j-k]]-=1
		ans+=dct[S[j]]-1
	print(ans)
	
if __name__ == "__main__":
		main()


Measured memory_bytes: 89624
#include <stdio.h>

#define SIZE 400
#define NUM 501

int main()
{
	int i, N, p[200001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &(p[i]));
	
	int j, k = (N + SIZE - 1) / SIZE, min[2][NUM], argmin[2][NUM];
	for (i = 0; i < k; i++) {
		min[0][i] = p[i*SIZE];
		min[1][i] = p[i*SIZE+1];
		argmin[0][i] = i * SIZE;
		argmin[1][i] = i * SIZE + 1;
		for (j = i * SIZE + 2; j < N && j % SIZE != 0; j++) {
			if (p[j] < min[j%2][i]) {
				min[j%2][i] = p[j];
				argmin[j%2][i] = j;
			}
		}
	}
	
	int l, r, n, tmp, parity[NUM] = {}, flag[NUM] = {}, stop[200001] = {}, ans[200001];
	for (n = 0; n < N; n += 2) {
		for (i = 0, ans[n] = N + 1; i < k; i++) {
			if (min[0][i] < ans[n]) {
				ans[n] = min[0][i];
				l = argmin[0][i];
			}
		}
		for (j = l + 1, ans[n+1] = N + 1; j < N && j / SIZE == l / SIZE && stop[j-1] + stop[j] == 0; j += 2) {
			if (p[j] < ans[n+1]) {
				ans[n+1] = p[j];
				r = j;
			}
		}
		if (j < N && stop[j-1] + stop[j] == 0) {
			for (i = j / SIZE; i < k && flag[i] == 0; i++) {
				if (min[1][i] < ans[n+1]) {
					ans[n+1] = min[1][i];
					r = argmin[1][i];
				}
			}
			if (i < k) {
				for (j = i * SIZE + (l + 1) % 2; j < N && stop[j-1] + stop[j] == 0; j += 2) {
					if (p[j] < ans[n+1]) {
						ans[n+1] = p[j];
						r = j;
					}
				}
			}
		}
		
		stop[l] = 1;
		stop[r] = 1;
		i = l / SIZE;
		flag[i] = 1;
		for (j = i * SIZE, tmp = parity[i], min[0][i] = N + 1, min[1][i] = N + 1; j < N && j < (i + 1) * SIZE; j++) {
			if (stop[j] == 1) continue;
			if (p[j] < min[tmp][i]) {
				min[tmp][i] = p[j];
				argmin[tmp][i] = j;
			}
			tmp ^= 1;
		}
		if (r / SIZE > i) {
			for (i++; i < r / SIZE; i++) {
				parity[i] ^= 1;
				min[0][i] += min[1][i];
				min[1][i] = min[0][i] - min[1][i];
				min[0][i] -= min[1][i];
				argmin[0][i] += argmin[1][i];
				argmin[1][i] = argmin[0][i] - argmin[1][i];
				argmin[0][i] -= argmin[1][i];
			}
			flag[i] = 1;
			for (j = i * SIZE, parity[i] ^= 1, tmp = parity[i], min[0][i] = N + 1, min[1][i] = N + 1; j < N && j < (i + 1) * SIZE; j++) {
				if (stop[j] == 1) continue;
				if (p[j] < min[tmp][i]) {
					min[tmp][i] = p[j];
					argmin[tmp][i] = j;
				}
				tmp ^= 1;
			}
		}
	}
	
	for (i = 0; i < N - 1; i++) printf("%d ", ans[i]);
	printf("%d\n", ans[N-1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

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

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

template<typename T>
string join(const vector<T>& vec, string sep = " "){
    stringstream ss;
    for(int i = 0; i < vec.size(); i++){
        ss << vec[i] << (i + 1 == vec.size() ? "" : sep);
    }
    return ss.str();
}

bool solve(const string& ds){
    int n = stoi(ds);
    int s = 0;
    for(const auto& d : ds){
        s += d - '0';
    }
    return n % s == 0;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string ds;
    cin >> ds;

    cout << (solve(ds) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b;
    cin >> a >> b;

    if (1 <= a && a <= 9 && 1 <= b && b <= 9)
        print(a * b);
    else
        print(-1);

    return 0;
}



Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}

void Yn(bool f)
{
  cout << (f ? "Yes" : "No") << endl;
}

void yn(bool f)
{
  cout << (f ? "yes" : "no") << endl;
}

void YN(bool f)
{
  cout << (f ? "YES" : "NO") << endl;
}

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

  return gcd(b, a % b);
}

int n, a[100000];
int l[100000], r[100000];

int main()
{
  cin >> n;
  REP(i, n){
    cin >> a[i];
  }

  REP(i, n){
    if(i==0)
      l[i] = a[0];
    else
    {
      l[i] = gcd(l[i - 1], a[i]);
    }
  }

  for (int i = n-1; i >= 0; i--)
  {
    if(i==n-1)
      r[i] = a[n - 1];
    else
    {
      r[i] = gcd(r[i + 1], a[i]);
    }
  }

  int ans = 0;
  REP(i, n)
  {
    int s;
    if(i==0)
      s = r[i + 1];
    else if(i==n-1)
      s = l[i-1];
    else
    {
      s = gcd(l[i - 1], r[i + 1]);
    }

    ans = max(ans, s);
  }

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


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


struct UnionFind {
    vector<int> data; int group;
    UnionFind(int N) : data(N, -1), group(N) {}
    void init(int N) {
        data.assign(N, -1);
        group = N;
    }
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(data[x] < data[y])  swap(x, y);        
        if(x != y){
            data[x] += data[y];
            data[y] = x;
            --group;
        }
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]);}
    bool same(int a, int b) { return root(a) == root(b);}
};

class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

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

    int n, q;
    cin >> n >> q;
    UnionFind uf(n);

    for(int _ : in(q)) {
        int k, u, v;
        cin >> k >> u >> v;
        if(k)
            cout << uf.same(u, v) << '\n';
        else
            uf.unite(u, v);
    }
    return 0;
}

Measured memory_bytes: 3204
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer a[] = new Integer[N];
        for (int i=0; i<N; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());

        int Alice = 0;
        int Bob   = 0;
        for (int i=0; i<N; i+=2) {
            Alice += a[i];
        }
        for (int i=1; i<N; i+=2) {
            Bob += a[i];
        }
        System.out.println(Alice - Bob);
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int gcd(int x,int y){
    return y ? gcd(y,x%y) : x;
}

ll GetDigit(ll num){
    return std::to_string(num).length();
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    //cout<<n/2<<endl;
    if(n%2!=0)cout<<"No"<<endl;
    else{
        string a,b;
        rep(i,0,n/2)a+=s[i];
        rep(i,n/2,n)b+=s[i];
        if(a==b)cout<<"Yes";
        else cout<<"No"<<endl;
        //cout<<a<<endl<<b<<endl;
    }
}
//単調増加の時、二分探索を使うO(log n)

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000
#define PI 3.14159265359

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> x(M), y(M), now(N, 1);
    vector<bool> reach(N, false);
    reach[0] = true;
    rep(i, M) {
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
    }

    int cnt = 0;
    rep(i, M) {
        if (reach[x[i]]) {
            reach[y[i]] = true;
            if (now[x[i]] == 1)
                reach[x[i]] = false;
        }
        now[x[i]]--;
        now[y[i]]++;
    }

    rep(i, N) {
        if (now[i] >= 1 && reach[i])
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
 
int main() {
	int h, w;
	string s[105];
	int i, j;
	cin >> h >> w;

	for (i = 0; i < h; i++)
	{
		cin >> s[i];
	}
	for (i = -1; i <= w; i++)
	{
		cout << '#';
	}
	cout << endl;
	for (i = 0; i < h; i++)
	{
		cout << '#' << s[i] << '#'<<endl;
	}
	for (i = -1; i <= w; i++)
	{
		cout << '#';
	}
	cout << endl;
}


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

int m,n,k,rs=1e9;

int main() {
	ios_base::sync_with_stdio(false);
	cin>>m>>n>>k;
	for(int i=1;i<=m;i++)
		if(i*n>=k)
			rs=min(rs,i);
	for(int i=1;i<=n;i++)
		if(i*m>=k)
			rs=min(rs,i);
	cout<<rs;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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



	int dp0 = 0;
	int dp1 = 1e9;

	char c;
	while ((c = getchar_unlocked()) >= '0') {
		int s = c - '0';

		int tmp0 = min(dp0, dp1 + 1) + s;
		dp1 = min(dp1, dp0 + 1) + 9 - s;
		dp0 = tmp0;
	}

	printf("%d\n", min(dp0, dp1 + 1));

	Would you please return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main() {
	long long int n;
	cin >> n;
	long long int ans = Inf;
	for (ll i = 1; i * i <= n; i++)
	{
		if(n%i==0){
			ans = min(ans, (i - 1) + (n / i) - 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  string w;
  cin >> w;
  map<char, int> m;
  REP(i,w.size()){
    m[w[i]] ++;
  }
  REPvec(itr,m){
    if(itr->second %2 != 0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
} 


Measured memory_bytes: 256
A, B, C, D = (int(x) for x in input())

class Op(int):
  def __str__(self):
     return '-' if self < 0 else '+'
    
pm = (Op(1), Op(-1))    

def solve():
  for op1 in pm:
    for op2 in pm:
      for op3 in pm:
        if A + op1 * B + op2 * C + op3 * D == 7:
          print(''.join(str(x) for x in [A, op1, B, op2, C, op3, D]) + '=7')
          return

solve()        

Measured memory_bytes: 3064
X = int(input())
dp = [False for _ in range(100001)]
dp[0] = True
for i in range(100,106):
    dp[i] = True
for i in range(107, X + 1):
    if dp[i - 100] == True or dp[i - 101] == True or dp[i - 102] == True\
        or dp[i - 103] == True or dp[i - 104] == True or dp[i - 105] == True:
        dp[i] = True

if dp[X] == True:
    print(1)
else:
    print(0)

Measured memory_bytes: 44784
K = gets.chomp
D = gets.to_i
KL = K.length
dp = [0]*D
MOD = 10 ** 9 + 7
K[0].to_i.times do |k|
	dp[k%D] += 1
end
tm = K[0].to_i % D
1.upto(KL-1) do |i|
	dg = K[i].to_i
	prev = dp.dup
	dp = [0]*D
	D.times do |j|
		10.times do |k|
			dp[j] += prev[(j-k)%D]
		end
	  dp[j] %= MOD
	end
	dg.times do |k|
		dp[(tm+k)%D] += 1
	end
	tm = (tm+dg) % D
end
dp[tm] += 1
p (dp[0]-1) % MOD

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

typedef pair<int, int> Pi;
#define fi first
#define se second

signed main()
{
  bool prime[1000005];

  fill_n(prime, 1000005, true);

  for(int i = 2; i * i <= 1000005; i++) {
    if(prime[i]) {
      for(int j = i * i; j <= 1000005; j += i) prime[j] = false;
    }
  }

  int N;
  while(cin >> N, N) {
    int ans = 0;
    for(int i = N + 1; i <= 2 * N; i++) {
      ans += prime[i];
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 4024
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    W, a, b = il()
    print(max(0, b - (a + W), a - (b + W)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4020
import heapq
n,m=list(map(int,input().split()))
tmp=[[] for _ in range(m)]
for i in range(n):
  a,b=list(map(int,input().split()))
  if a<=m:
    tmp[a-1].append(-b)
ans=0
heap=[]
for i in range(m):
  for b in tmp[i]:
    heapq.heappush(heap,b)
  if len(heap)>0:
    ans-=heapq.heappop(heap)
print(ans)

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

int dp[10005][5]; //0 ???????????? 1 ???????????? 2 ?????????????????? 3 ???????????? 4 ?????????????????????

int main() {

    int h,n;

    cin >> h >> n;

    int x,y;

    for(int i=0;i<n;i++) {
        cin >> x >> y;
        if(x==0){
            dp[h-y][0] = dp[h-y-1][0] = dp[h-y][1] = dp[h-y-1][1] = -1;
        }
        else if(x==1){
            dp[h-y][0] = dp[h-y-1][0] = dp[h-y][1] = dp[h-y-1][1] = dp[h-y][2] = dp[h-y-1][2] = -1;
        }
        else if(x==2){
            dp[h-y][0] = dp[h-y-1][0] = dp[h-y][2] = dp[h-y-1][2] = dp[h-y][3] = dp[h-y-1][3] = -1;
        }
        else if(x==3){
            dp[h-y][0] = dp[h-y-1][0] = dp[h-y][3] = dp[h-y-1][3] = -1;
        }
    }
    
    for(int i=1;i<h;i++){
        if(dp[i][0] != -1) {
            dp[i][0] = dp[i - 1][4] + 2;
        }
        if(dp[i][1] != -1) {
            dp[i][1] = max(dp[i - 1][3] + 1, dp[i - 1][4] + 1);
        }
        if(dp[i][2] != -1) {
            dp[i][2] = dp[i - 1][4] + 1;
        }
        if(dp[i][3] != -1) {
            dp[i][3] = max(dp[i - 1][1] + 1, dp[i - 1][4] + 1);
        }
        dp[i][4] = max(max(dp[i - 1][0], dp[i - 1][1]), max(dp[i - 1][2], max(dp[i - 1][3], dp[i - 1][4])));
    }

    cout << max(max(dp[h-1][0],dp[h-1][1]),max(dp[h-1][2],max(dp[h-1][3],dp[h-1][4]))) << endl;
    



    return 0;
}

Measured memory_bytes: 3276
import math

N, K = list(map(int, input().split()))
MOD = 10**9+7
i = 1
ans = math.factorial(N-K+1) // (math.factorial(N-K-i+1) * math.factorial(i)) * math.factorial(K-1) // (math.factorial(K-i) * math.factorial(i-1)) % MOD

for i in range(1,K+1):
    if i <= N-K+1:
        ans = math.factorial(N-K+1) // (math.factorial(N-K-i+1) * math.factorial(i)) * math.factorial(K-1) // (math.factorial(K-i) * math.factorial(i-1)) % MOD
    else:
        ans = 0
    print(ans)


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

int main(){
  ll n, l, m, r, s, c, d = 0;
  cin >> n;
  ll a[n], b[n];
  priority_queue<P> que;
  rep(i,n) cin >> a[i];
  rep(i,n) {
    cin >> b[i];
    que.push(P(b[i],i));
  }
  while(!que.empty()) {
    P p = que.top(); que.pop();
    m = p.second;  l = (m-1+n) % n, r = (m+1) % n;
    s = b[l] + b[r]; c = min(b[m]/s,(b[m]-a[m])/s);
    if(c > 0) {
      b[m] -= s*c; que.push(P(b[m],m)); d += c;
    } 
  }
  rep(i,n) {
    if(a[i] != b[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << d << endl;
  return 0;
}

Measured memory_bytes: 9200
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i, n) for (int i =  0; i < (int)(n); i++)

int n, m, a[10], f[10], u[10];

int rec(int k, int t) {
    if (k == m) return t == 0 ? 1 : 0;
    int mx = 0, mn = 0;
    for (int i = k; i < m; i++) {
        if (a[i]>0) mx += a[i]*9; else mn += a[i]*9;
    }
    if (t+mx < 0 || t+mn > 0) return 0;
    int ans = 0;
    rep (i, 10) if (u[i] == 0) {
        if (i == 0 && f[k]) continue;
        u[i] = 1;
        ans += rec(k+1, t+a[k]*i);
        u[i] = 0;
    }
    return ans;
}

int main() {
    for (;;) {
        cin >> n;
        if (n == 0) return 0;
        memset(a, 0, sizeof(a));
        memset(f, 0, sizeof(f));
        map<char, int> of;
        m = 0;
        rep (k, n) {
            string s;
            cin >> s;
            int t = 1;
            for (int i = s.size()-1; i >= 0; i--) {
                if (of.count(s[i]) == 0) of[s[i]] = m++;
                a[of[s[i]]] += k<n-1 ? t : -t;
                if (s.size() > 1 && i == 0) f[of[s[i]]] = 1;
                t *= 10;
            }
        }
        printf("%d\n", rec(0, 0));
    }
}

Measured memory_bytes: 940
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();  
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        int[] A = r.ii();
        int[] count = new int[200001];
        for(int a : A)
            count[a]++;
        Arrays.sort(count);
        int ans = 0;
        for(int i = 200001-N; i < 200001-K; i++){
            ans += count[i];
        }
        println(ans);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 48084
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int num[] = {0,2,5,5,4,5,6,3,7,6};
int dp[10010];
int main(){
    int n;
    int m;
    cin >> n >> m;
    set<int>st;
    rep(i,m){
        int x;
        cin >> x;
        st.insert(x);
    }
    if(st.count(9)){
        st.erase(6);
    }
    if(st.count(5)){
        st.erase(2);
        st.erase(3);
    }else{
        if(st.count(3)){
            st.erase(2);
        }
    }
    int keta = 0;
    vector<int>a;
    vector<int>b;
    for(int x:st){
        a.push_back(num[x]);
        b.push_back(x);
    }
    memset(dp,-1,sizeof(dp));
    dp[0] = 0;
    rep(i,n+1){
        rep(j,a.size()){
            dp[i+a[j]] = max(dp[i+a[j]], dp[i] + 1);
        }
    }
//    rep(i,n+1)show(dp[i]);
//    cerr << dp[n] << endl;
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    while(n){
//        show(n);
        rep(j,a.size()){
//            show(a[j]);
//            cerr << dp[n] << " " << dp[n-a[j]] << endl;
            if(n-a[j] >= 0 and dp[n] == dp[n-a[j]] + 1){
                cout <<b[j];
                n-=a[j];
                break;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){
string ws;
map<char,string> aa;
map<string,char> bb;
 
	aa[' ']  = "101";
	aa['\''] = "000000";
	aa[',']  = "000011";
	aa['-']  = "10010001";
	aa['.']  = "010001";
	aa['?']  = "000001";
	aa['A']  = "100101";
	aa['B']  = "10011010";
	aa['C']  = "0101";
	aa['D']  = "0001";
	aa['E']  = "110";
	aa['F']  = "01001";
	aa['G']  = "10011011";
	aa['H']  = "010000";
	aa['I']  = "0111";
	aa['J']  = "10011000";
	aa['K']  = "0110";
	aa['L']  = "00100";
	aa['M']  = "10011001";
	aa['N']  = "10011110";
	aa['O']  = "00101";
	aa['P']  = "111";
	aa['Q']  = "10011111";
	aa['R']  = "1000";
	aa['S']  = "00110";
	aa['T']  = "00111";
	aa['U']  = "10011100";
	aa['V']  = "10011101";
	aa['W']  = "000010";
	aa['X']  = "10010010";
	aa['Y']  = "10010011";
	aa['Z']  = "10010000";
 
	bb["00000"]  = 'A';
	bb["00001"]  = 'B';
	bb["00010"]  = 'C';
	bb["00011"]  = 'D';
	bb["00100"]  = 'E';
	bb["00101"]  = 'F';
	bb["00110"]  = 'G';
	bb["00111"]  = 'H';
	bb["01000"]  = 'I';
	bb["01001"]  = 'J';
	bb["01010"]  = 'K';
	bb["01011"]  = 'L';
	bb["01100"]  = 'M';
	bb["01101"]  = 'N';
	bb["01110"]  = 'O';
	bb["01111"]  = 'P';
	bb["10000"]  = 'Q';
	bb["10001"]  = 'R';
	bb["10010"]  = 'S';
	bb["10011"]  = 'T';
	bb["10100"]  = 'U';
	bb["10101"]  = 'V';
	bb["10110"]  = 'W';
	bb["10111"]  = 'X';
	bb["11000"]  = 'Y';
	bb["11001"]  = 'Z';
	bb["11010"]  = ' ';
	bb["11011"]  = '.';
	bb["11100"]  = ',';
	bb["11101"]  = '-';
	bb["11110"]  = '\'';
	bb["11111"]  = '?';
	
	while(getline(cin,ws)){

		string wws="", ans="";
		rep(i, ws.size()) wws += aa[ws[i]];
		while(wws.size() % 5 !=0) wws += '0';
//		cout << wws <<endl;
		for(int i=0;i<wws.size() ;i+=5){
			string mws = wws.substr(i,5);
			ans += bb[mws];
		}
		if(cin.eof()) break;
		cout << ans  <<endl;
	}

	return 0;
	
}

Measured memory_bytes: 1208
K = gets.to_i

list = [1,2,3,4,5,6,7,8,9]

count = 0
k = 0

while count != K do
    k = list.shift
    list.push k * 10 + k % 10 -1 unless k % 10 == 0 
    list.push k * 10 + k % 10
    list.push k * 10 + k % 10 + 1 unless k % 10 == 9 
    count += 1
end

puts k

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

int main() {
  int total = 0, N;

  cin >> N;
  
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    total += b - a + 1;
  }

  cout << total << endl;
  
  return 0;
}


Measured memory_bytes: 256
fn main() {
    proconio::input! { // コピペ用: proconio::marker::Usize1
        x: u64,
    }
    let mut cur = 100;
    let mut count = 0;
    while cur < x {
        cur = cur + cur/100;
        count += 1;
    }
    println!("{}", count);
}


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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    // 前処理
    COMinit();
    int n,k;
    cin >> n>>k;
    vector<long long>a;
    long long bef;
    long long ans=0;
    
    for(int i=0;i<n;i++){
        cin>>bef;
        a.push_back(bef);
    }
    sort(a.begin(),a.end());
    //cout<<a[0]<<"   ";
    //cout<<a[n-1]<<"   ";
    for(int i=n;i>=0;i--){
        if(i-1 <k-1){
            break;
            }
        ans=ans+a[i-1]*COM(i-1,k-1);
       //        cout<<a[i-1]<<"  "<<i-1<<"  "<<k-1<<endl;
        ans%=MOD;
    }
   // cout<<endl;
   
    for(int i=1;i<=n;i++){
        if(n-i <k-1){
            break;
            }
        ans=ans-a[i-1]*COM(n-i,k-1);
       //          cout << a[i -1] << "  " <<  n  - i << "  " << k - 1 << endl;
        ans%=MOD;
    }
    
    ans%=MOD;
    if(ans <0){
        ans+=MOD;
    }
    
    cout << ans;
}


Measured memory_bytes: 13304
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n,x,t;
  cin >> n >> x >> t;
  int k = (n+x-1)/x;
  cout << t * k << "\n";
  

  return 0;
}

Measured memory_bytes: 3592
numbers=gets.split(" ").map{|a| a.to_i}
N=numbers[0]
K=numbers[1]

number_list=gets.split(" ")[0...N].map{|a| a.to_i}
number_histogram = Hash.new

number_list.each{|a|
  if nil == number_histogram[a] 
    number_histogram[a] = 1
  else
    number_histogram[a] += 1
  end
}
if number_histogram.size <= K
  print 0
  exit
end
number_histogram = number_histogram.to_a
number_histogram.sort_by!{|a| -a[1]}
print number_histogram[K...N].inject(0){|amount, a| amount += a[1]}

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

using namespace std;

struct edge{
  int to,cap,cost,rev;
};

int V;
vector<edge> G[202];
int dist[202];
int prevv[202],preve[202];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back({to,cap,cost,(int)G[to].size()});
  G[to].push_back({from,0,-cost,(int)G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  const int INF=1<<29;
  int res=0;
  while(f>0){
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update=true;
    while(update){
      update=false;
      for(int v=0;v<V;v++){
	if(dist[v]==INF)continue;
	for(int i=0;i<G[v].size();i++){
	  edge &e=G[v][i];
	  if(e.cap>0&&dist[e.to]>dist[v]+e.cost){
	    dist[e.to]=dist[v]+e.cost;
	    prevv[e.to]=v;
	    preve[e.to]=i;
	    update=true;
	  }
	}
      }
    }
    f--;
    res+=dist[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap--;
      G[v][e.rev].cap++;
    }
  }
  return res;
}
    

int main(){
  int n;
  cin>>n;
  int W[100][100],E[100][100];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>W[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>E[i][j];
    }
  }
  char F[100][101];
  int ec=0;
  for(int i=0;i<n;i++){
    cin>>F[i];
    for(int j=0;j<n;j++){
      if(F[i][j]=='o'){
	ec+=E[i][j];
      }
      add_edge(i,n+j,1,(F[i][j]=='o')?-E[i][j]:W[i][j]);
    }
    add_edge(2*n,i,1,0);
    add_edge(n+i,2*n+1,1,0);
  }
  V=n*2+2;
  ec+=min_cost_flow(n*2,n*2+1,n);
  vector<int> w,e;
  for(int i=0;i<n;i++){
    for(auto f:G[i]){
      int t=f.to-n;
      if(0<=t&&t<n){
	if(F[i][t]=='o'^f.cap==0){
	  if(F[i][t]=='o'){
	    e.push_back(i*n+t);
	  }else{
	    w.push_back(i*n+t);
	  }
	}
      }
    }
  }
  cout<<ec<<endl;
  cout<<e.size()+w.size()<<endl;
  for(auto f:e){
    cout<<f/n+1<<' '<<f%n+1<<' '<<"erase"<<endl;
  }
  for(auto f:w){
    cout<<f/n+1<<' '<<f%n+1<<' '<<"write"<<endl;
  }
}

Measured memory_bytes: 1760
#include <iostream>

int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;
	
	if (a<=b && a<=c) {
		if (b<=c) std::cout << a << " " << c << std::endl;
		else std::cout << a << " " << b << std::endl;
	} else if (b<a && b<c) {
		if (a<=c) std::cout << b << " " << c << std::endl;
		else std::cout << b << " " << a << std::endl;
	} else {
		if (a<=b) std::cout << c << " " << b << std::endl;
		else std::cout << c << " " << a << std::endl;
	}
	
	return 0;
}
		



Measured memory_bytes: 3104
#include<stdio.h>                                                    
int main(void)
{
   int  a,b,c;
   scanf("%d%d",&a,&b); 
   int i;
   c=0;  
   for(i=0;i<2;i++){
   if(a>b){
         c+=a;
         a--;
   }   
   else{
         c+=b;
         b--;
   }   
   }   
   printf("%d\n",c);
   return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main(void){
  int N, A, B;
  cin >> N >> A >> B;
  if((A - B) % 2 == 0){cout << "Alice" << endl;}
  else{cout << "Borys" << endl; }
  return 0;
}


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

int main() {
	int N,M;
	cin>>N>>M;
	vector<int> x(M);
	for(int i=0;i<M;i++){
		cin >>x.at(i);
	}
	sort(x.begin(),x.end());
	vector<int> dis(M-1);
	for(int i=0;i<M-1;i++){
		dis.at(i)=x.at(i+1)-x.at(i);
	}
	sort(dis.begin(),dis.end());
	int count =0;
	if(M-N<=0){
		cout<<0<<endl;
	}
	else{
		for(int i=0;i<M-N;i++){
			count+=dis.at(i);
		}
		cout<<count<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

//Lost in Space
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		double RATIO = 1e-4;
//		double EPS = 1e-8;
		while(t--!=0){
			double qr = sc.nextDouble(), rp = sc.nextDouble(), pq = sc.nextDouble();
			double r1 = qr/rp, r2 = rp/pq, r3 = pq/qr;
			int n = sc.nextInt();
			double[] x = new double[n+1], y = new double[n+1], z = new double[n+1];
			for(int i=1;i<=n;i++){
				x[i] = sc.nextDouble()*9.461; y[i] = sc.nextDouble()*9.461; z[i] = sc.nextDouble()*9.461;
			}
			for(int p=1;p<=n;p++)for(int q=1;q<=n;q++)for(int r=1;r<=n;r++){
				if(p==q||q==r||r==p)continue;
				double QR = Math.sqrt(Math.pow(x[q]-x[r], 2)+Math.pow(y[q]-y[r], 2)+Math.pow(z[q]-z[r], 2));
				double RP = Math.sqrt(Math.pow(x[p]-x[r], 2)+Math.pow(y[p]-y[r], 2)+Math.pow(z[p]-z[r], 2));
				double PQ = Math.sqrt(Math.pow(x[q]-x[p], 2)+Math.pow(y[q]-y[p], 2)+Math.pow(z[q]-z[p], 2));
				double R1 = QR/RP, R2 = RP/PQ, R3 = PQ/QR;
				double d1 = Math.abs((r1-R1)/r1), d2 = Math.abs((r2-R2)/r2), d3 = Math.abs((r3-R3)/r3);
				if(d1<RATIO && d2<RATIO && d3<RATIO){
					System.out.println(p+" "+q+" "+r);break;
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <cstdio>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>

using namespace std;

int main()
{
    int t;
    cin >> t;
    const int n = t;
    int trmp[4][13] = {};
    char s;
    int num;
    for(int i = 0; i < n; i++){
        cin >> s >> num;
        if(s == 'S'){
            trmp[0][num-1] = 1;
        }else if(s == 'H'){
            trmp[1][num-1] = 1;
        }else if(s == 'C'){
            trmp[2][num-1] = 1;
        }else if(s == 'D'){
            trmp[3][num-1] = 1;
        }
    }

    //cout << endl << "============" << endl;
    for(int i = 0; i < 13; i++){
        if(trmp[0][i] == 0){
            cout << "S " << i+1 << endl;
        }
    }
    for(int i = 0; i < 13; i++){
        if(trmp[1][i] == 0){
            cout << "H " << i+1 << endl;
        }
    }
    for(int i = 0; i < 13; i++){
        if(trmp[2][i] == 0){
            cout << "C " << i+1 << endl;
        }
    }
    for(int i = 0; i < 13; i++){
        if(trmp[3][i] == 0){
            cout << "D " << i+1 << endl;
        }
    }
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

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




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    REP(i, min(a, b), max(a, b) + 1){
        if(abs(a - i) == abs(b - i)){
            print(i);
            return 0;
        }
    }
    print("IMPOSSIBLE");

}


Measured memory_bytes: 384