akhauriyash/Code-Regression huggingface dataset:
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	T, A := getInt()*1000, getInt()*1000
	h := getInts(N)
	t := make([]int, N)
	m := 100100100
	pos := -1
	for i := 0; i < N; i++ {
		t[i] = T - h[i]*6
		if abs(t[i]-A) < m {
			m = abs(t[i] - A)
			pos = i
		}
	}
	// out(t, A)
	out(pos + 1)
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
using namespace std;
char a[200050];
int main()
{
    while(~scanf("%s",a))
    {
        int pre=-1;
        int back=-1;
        int n=strlen(a);
        for(int i=0;i<n;i++)
        {
            if(a[i]=='A'&&pre==-1)pre=i;
            if(a[i]=='Z')back=i;
        }
        if(pre==-1||back==-1)
        {
            printf("0\n");
        }
        else printf("%d\n",back-pre+1);
    }
}


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

using namespace std;

typedef long long int lli;
typedef vector< lli > vec1;
typedef vector< vec1 > vec2;

int main() {
    int n, a[300], s = 0;
    const int div = 998244353;

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

    vec2 dp1 = vec2(301, vec1(90001, 0));
    dp1[0][0] = 1;
    for (int i=1; i<=n; i++) {
        for (int j=0; j<=s; j++) {
            dp1[i][j] += dp1[i-1][j] * 2;
            dp1[i][j] += (j-a[i-1] >= 0) ? dp1[i-1][j-a[i-1]] : 0;
            dp1[i][j] %= div;
        }
    }

    vec2 dp2 = vec2(301, vec1(90001, 0));
    dp2[0][0] = 1;
    for (int i=1; i<=n; i++) {
        for (int j=0; j<=s/2; j++) {
            dp2[i][j] += dp2[i-1][j];
            dp2[i][j] += (j-a[i-1] >= 0) ? dp2[i-1][j-a[i-1]] : 0;
            dp2[i][j] %= div;
        }
    }

    /*
    for (int i=0; i<20; i++) {
        cout << dp1[n][i] << " ";
    }
    cout << endl;
    */

    lli sum1 = 0;
    for (int i=s/2+s%2; i<=s; i++) {
        sum1 += dp1[n][i]*3;
        sum1 %= div;
    }
    lli sum2 = (s%2) ? 0 : dp2[n][s/2]*3 % div;

    lli all = 1;
    for (int i=0; i<n; i++) {
        all *= 3;
        all %= div;
    }

    //cout << sum1 << " " << sum2 << " " << all << endl;
    if (all < sum1) all += div;
    cout << (all - sum1 + sum2) % div << endl;

    return 0;
}

Measured memory_bytes: 424512
# 入力
N, M = map(int, input().split())
x, y = zip(*(map(int, input().split()) for _ in range(M)))

# シミュレーションにより、赤いボールが入っている可能性のある箱を列挙
c = [1 for _ in range(N + 1)]
r = [False for _ in range(N + 1)]
r[1] = True
for a, b in zip(x, y):
    c[b] += 1
    r[b] |= r[a]
    c[a] -= 1
    r[a] &= c[a] >= 1
ans = sum(r)

# 出力
print(ans)


Measured memory_bytes: 57468
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
string a[] = {"Christmas","Christmas Eve","Christmas Eve Eve","Christmas Eve Eve Eve"};
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	cout<<a[25 - n]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);

	int a, b;
	cin >> a >> b;
	if(2*b >= a) {
		cout << 0;
	}
	else cout << a - 2*b;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a_input = list(map(int,input().split()))
b_input = list(map(int,input().split()))

ans=0
for i in range(n):
    first_attack=0
    second_attack=0

    first_attack = min(b_input[i],a_input[i])
    a_input[i]-=first_attack
    if first_attack<b_input[i]:
        second_attack = min(a_input[i+1],b_input[i]-first_attack)
        a_input[i+1]-= second_attack
    ans+=first_attack+second_attack

print(ans)


Measured memory_bytes: 18624
#include<stdio.h>
int gcd(int,int);
void swap(int *,int *);

int main(){
  int x,y,g=0;
  scanf("%d%d",&x,&y);
  g=gcd(x,y);
  printf("%d\n",g);
  return 0;
}

int gcd(int a,int b){
  int c;
  if(a<b){
    swap(&a,&b);
  }
    while(b>0){
      c=a%b;
      a=b;
      b=c;
    }   
  return a;
}

  void swap(int *a,int *b){
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
  }



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, a[55], k, s, t;
LL comb[55][55];
LL hv[25];
LL ab[262144], ob[262144];

int main()
{
	scanf("%d%d%d%d", &n, &k, &s, &t);
	rep(i, n) scanf("%d", &a[i]);
	if((s & t) != s) {
		printf("0\n");
		return 0;
	}
	comb[0][0] = 1;
	rep(i, n + 1) rep(j, n + 1) {
		comb[i + 1][j] += comb[i][j];
		comb[i + 1][j + 1] += comb[i][j];
	}
	rep(i, n + 1) {
		comb[i][0] = 0;
		rep1(j, n) comb[i][j] += comb[i][j - 1];
	}
	
	rep(i, n) rep(j, 18) if(a[i] >> j & 1) hv[j] |= 1LL << i;
	rep(i, 262144) {
		ab[i] = (1LL << n) - 1;
		rep(j, 18) if(i >> j & 1) ab[i] &= hv[j];
		ob[i] = (1LL << n) - 1;
		rep(j, 18) if(!(i >> j & 1)) ob[i] &= ~hv[j];
	}
	t ^= s;
	
	LL ans = 0;
	for(int i = t; i != -1; i = i - 1 & t) {
		for(int j = i; j != -1; j = j - 1 & i) {
			if(__builtin_parity(t ^ i ^ j)) ans -= comb[__builtin_popcountll(ab[j | s] & ob[i | s])][k];
			else ans += comb[__builtin_popcountll(ab[j | s] & ob[i | s])][k];
			if(j == 0) break;
		}
		if(i == 0) break;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7904
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int c[26],d[26];
int main(){
	while(true){
	int n,f,a=114514;
	char z;
	cin>>n;
	if(!n)break;
	f=n;
	rep(i,26)c[i]=0;
	while(true){
		n--;
		cin>>z;
		c[z-'A']++;
		rep(i,26)d[i]=c[i];
		sort(d,d+26);
		if(d[25]>n+d[24])a=min(a,f-n);
		if(!n)break;
	}
	n=0;
	rep(i,26){
		if(c[i]==n)f=114514;
		if(c[i]>n)n=c[i],f=i;
	}
	z=f+'A';
	if(f==114514)cout<<"TIE"<<endl;
	else cout<<z<<" "<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 3056
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n,m=MI()
A=sorted(LI())
BC=[LI()for i in range(m)]
BC=sorted(BC,key=itemgetter(1),reverse=True)
#print(BC)
dif=[]
l=0
for i in range(m):
    dif+=[BC[i][1]]*BC[i][0]
    l+=BC[i][0]
    if l>=n:
        break
#print(dif)
for i in range(n):
    dif.append(0)
ans=0
for i in range(n):
    ans+=max(dif[i]-A[i],0)
print(ans+sum(A))

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

int main(){
  string a,b;
  cin>>a>>b;
  int ans=0,n=a.size(),m=b.size();

  for(int i=1;i<=n;i++){
    set<vector<int> > S;
    vector<int> v(26,0);
    for(int j=0;j<n;j++){
      v[a[j]-'a']++;
      if(j>=i) {
	v[a[j-i]-'a']--;
	S.insert(v);
      }
    }
    S.insert(v);
    v=vector<int>(26,0);
    for(int j=0;j<m;j++){
      if(i==j&&S.count(v))ans=i;
      v[b[j]-'a']++;
      if(j>=i){
	v[b[j-i]-'a']--;
	if(S.count(v))ans=i;
      }    
    }
    if(S.count(v))ans=i;
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 3868
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;

const int MOD = 1000000007;

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

struct sousa
{
    //(y1,x1) から (y2,x2) への移動
    int y1;
    int x1;
    int y2;
    int x2;
};

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

    vector <vector <int> >  a(H, vector<int>(W));
    REP(i,H)
    {
        REP(j,W)
        {
            cin >> a.at(i).at(j);
        }
    }
    vector <sousa> s;
    //端から、偶数にしていく
    for(int y = 0; y < H; ++y)
    {
        //選んだことのないマスだけ移動できる 配置-> 右と下だけでよい??
        //以下の場合、奇数を奇数のまま配置しておくのはもったいない
        //偶奇偶
        //奇偶奇
        //偶奇偶
        //奇偶奇
        //右か下に寄せておけばスクエル
        //作戦: とにかく右に寄せる(偶数ならなにもしない)
        //(こうすれば、選んだことのないますについて考えないで済む)
        //右端のマスなら下に落とす

        for(int x = 0; x < W; ++x)
        {
            if(a[y][x] % 2 == 0)continue;

            if(x < W - 1)
            {
                --a[y][x];
                ++a[y][x+1];
                s.emplace_back((sousa){y,x,y,x+1});
            }
            else if(y < H - 1)//下に寄せる
            {
                --a[y][x];
                ++a[y+1][x];
                s.emplace_back((sousa){y,x,y+1,x});
            }
        }
    }

    cout << s.size() << endl;

    REP(i,s.size())
    {
        cout << s[i].y1 + 1 << " ";
        cout << s[i].x1 + 1 << " ";
        cout << s[i].y2 + 1 << " ";
        cout << s[i].x2 + 1 << endl;

    }


    return 0;    
}

Measured memory_bytes: 5232
import math
def solve():
  ans = 0
  ex = 10
  for i in range(5):
    tp = int(input())
    ans += 10*math.ceil(tp/10)
    if tp%10 == 0:
      continue
    else:
      ex = min(tp%10,ex)
  if not ex == 10:
    print(ans-10+ex)
  else:
    print(ans)
solve()

Measured memory_bytes: 3060
#include <stdio.h>

void call(int n) {
int i,d,flag;
//scanf("%d",&n);
for(i=1;i<=n;i++){
 if(i%3==0){
 printf(" %d",i);
}else
{
 d=1;
 flag=0;
 while(flag==0)
 {
  if((i%(10*d)-i%d)/d==3)
  {
    printf(" %d",i);
    flag=1;
  }else{
   d=d*10;
   flag=(i/d==0)?1:0;
  }
 }
}
}
}

int main() {
int n;
scanf("%d",&n);
call(n);
printf("\n");
return 0;
}


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

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    from collections import Counter
    c = Counter(arr)

    cnt = 0
    for X in c.keys():
        cnt = max(cnt, c.get(X - 1, 0) + c.get(X, 0) + c.get(X + 1, 0))

    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14300
from collections import deque, Counter
from itertools import chain, combinations
import json
import numpy as np
import bisect


def main():
    N = int(input())
    X = [int(a) for a in input().split()]

    def f(n):
        return sum((n - x) ** 2 for x in X)

    res = 1
    v = f(1)
    for i in range(1, 99):
        i += 1
        if v > f(i):
            res = i
            v = f(i)
    print(v)

    # A = [int(a) for a in input().split()]
    #
    # A = sorted(A)
    # A = np.array(A)
    #


if __name__ == "__main__":
    main()


Measured memory_bytes: 12404
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
vector<ll> dijkstra(vector<vector<P>> graph, ll s) {
    vector<ll> ans(graph.size(), -1);
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, s});
    while (pq.size() > 0) {
        ll cur1 = 0;
        ll cur2 = 0;
        if (ans[pq.top().second] != -1) {
            pq.pop();
        } else {
            cur1 = pq.top().first;
            cur2 = pq.top().second;
            pq.pop();
            ans[cur2] = cur1;
            for (ll i = 0; i < graph[cur2].size(); i++) {
                pq.push({cur1 + graph[cur2][i].first, graph[cur2][i].second});
            }
        }
    }
    return ans;
}
vector<string> maze;
ll h, w;
bool check(ll y, ll x) {
    if (x < 0 || x >= w || y < 0 || y >= h || maze[y][x] == '#') {
        return false;
    }
    return true;
}
int main() {
    ll n, m;
    cin >> n >> m;
    ll x = (n - m) * 100 + m * 1900;
    cout << x * modpow(2, m, mod) << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    double ans = W * H / 2;
    printf("%09lf ", ans);
    cout << (2*x == W && 2*y == H ? '1' : '0') << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

var ans string
var s string
var q int
var t, f int
var c string

func main() {
	fmt.Scan(&s)
	fmt.Scan(&q)
	fronts := make([]rune, 0, 200000)
	backs := make([]rune, 0, 200000)

	rev := false
	for i := 0; i < q; i++ {
		fmt.Scan(&t)
		switch t {
		case 1:
			rev = !rev
		case 2:
			fmt.Scan(&f, &c)
			head := (f == 1)
			if rev {
				head = !head
			}
			if head {
				fronts = append(fronts, []rune(c)[0])
			} else {
				backs = append(backs, []rune(c)[0])
			}
		default:
			panic("err")
		}
	}

	if rev {
		fronts, backs = backs, fronts
		s = string(reverse([]rune(s)))
	}
	ans = strings.Join([]string{
		string(reverse(fronts)), s, string(backs),
	}, "")

	fmt.Println(ans)
}

func reverse(ss []rune) []rune {
	o := make([]rune, len(ss))
	i := len(ss)
	for _, s := range ss {
		i--
		o[i] = s
	}
	return o
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define lc rt<<1
#define rc (rt<<1)|1
using namespace std;
typedef long long LL;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

template <typename T> inline void read(T &AKNOI)
{
    T x=0, flag=1;
    char ch = getchar();
    while(!isdigit(ch)){
        if(ch == '-') flag = -1;
        ch = getchar();
    }
    while(isdigit(ch)){
        x = (x<<1) + (x<<3) + ch - '0';
        ch = getchar();
    }
    AKNOI = flag*x;
}

int n, m, tr[MAXN];

struct Area
{
	int l, r, len;
	bool operator < (const Area &rhs) const {
		return len < rhs.len;
	}
}a[MAXN*3];

inline int lowbit(int x)
{
	return x & (-x);
}

inline void add(int x, int val)
{
	for(int i=x;i;i-=lowbit(i)){
		tr[i] += val;
	}
}

inline void update(int l, int r)
{
	add(l-1, -1);
	add(r, 1);
}

inline int query(int x)
{
	int ret = 0;
	for(int i=x;i<=m;i+=lowbit(i)){
		ret += tr[i];
	}
	return ret;
}

void init()
{
	read(n); read(m);
	for(int i=1;i<=n;++i){
		read(a[i].l); read(a[i].r);
		a[i].len = a[i].r - a[i].l + 1;
	}
	sort(a+1, a+n+1);
}

void solve()
{
	for(int i=1,j=1;i<=m;++i){
		while(j<=n && a[j].len == i){
			update(a[j].l, a[j].r);
			++j;
		}
		int ans = n-j+1;
		for(int k=i;k<=m;k+=i){
			ans += query(k);
		}
		printf("%d\n", ans);
	}
}

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


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    string s; cin>>s;
    bool ok=true;
    rep(i,s.size()){
        if(i%2==0){
            if(s[i]=='L'){
                ok=false;
                continue;
            }
        }else{
            if(s[i]=='R'){
                ok=false;
                continue;
            }
        }

    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
line = $stdin.read.split("\n")
odd = line[0]
even = line[1]
odd.split("")
even.split("")
length = odd.size + even.size - 1

pass=[]
odcnt = 0
evcnt = 0
for i in 0..length do
	if (i+1) % 2 != 0
		pass[i] = odd[odcnt]
		odcnt += 1
	else
		pass[i] = even[evcnt]
		evcnt += 1
	end
end

puts pass.join


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a,b;
    cin>>n;
    std::deque<long long int> A;
    for (int i=0;i<n;i++) {
        cin>>a;
        A.emplace_back(a);
    }
    std::deque<long long int> B;
    for (int i=0;i<n;i++) {
        cin>>b;
        B.emplace_back(b);
    }
    std::deque<long long int> C;
    long long int tmp=0,count=0;
    int flag=0;
    for (int i=0;i<n;i++) {
        if (A[i]<B[i]) {
            flag=1;
        }
        if (A[i]-B[i]<0) {
            tmp+=A[i]-B[i];
            count++;
        } else if (A[i]-B[i]>0) {
            C.emplace_back(A[i]-B[i]);
        }
    }
    if (flag==0) {
        cout<<0<<endl;
    } else {
        sort(C.begin(),C.end(),greater<long long int>());
        for (int i=0;i<C.size();i++) {
            if (C[i]+tmp>=0) {
                cout<<count+i+1<<endl;
                return 0;
            } else {
                tmp+=C[i];
            }
        }
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 5700
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma region header
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
#pragma endregion
#pragma endregion



int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	lint ans = INF;
	lint l, r; cin >> l >> r;
	for (lint i = l; i <= min(2020ll + l, r); i++) {
		for (lint j = i + 1; j <= min(2020ll + l, r); j++) {
			ans = min(ans, (i * j) % 2019);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl


signed main(void){
    int N,W[100];
    cin >> N;
    REP(i,N){
        cin >> W[i];
    }
    int Ans=INF;
    int num=0;
    REP(i,N+1){
        num=0;
        for(int j=0;j<i;j++){
            num+=W[j];
        }
        for(int j=i;j<N;j++){
            num-=W[j];
        }
        Ans=min(Ans,abs(num));
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 256
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var M = one[1];
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		list[i] = {
			child : [],
			no : null,
			access : false,
			from : null
		};
	}
	for(var i = 0; i < M; i++){
		var tmp = nextIntArray();
		list[tmp[0] - 1].child.push(tmp[1] - 1);
		list[tmp[1] - 1].child.push(tmp[0] - 1);
	}
	
	var queue = [0];
	list[0].access = true;
	list[0].no = 0;
	while(queue.length > 0){
		var tmp = queue.shift();
		var child = list[tmp].child;
		for(var i = 0; i < child.length; i++){
			if(!list[child[i]].access){
				list[child[i]].access = true;
				list[child[i]].no = list[tmp].no + 1;
				list[child[i]].from = tmp;
				queue.push(child[i]);
			}
		}
	}
	var output = new Array(N);
	output[0] = "Yes";
	for(var i = 1; i < N; i++){
		if(list[i].no == null){
			myout("No");
			return;
		}
		output[i] = list[i].from + 1;
	}
	myout(myconv(output,9));
}

Measured memory_bytes: 108076
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <list>

using namespace std;

#define int long long int
#define mod 1000000007
#define p push
#define pb push_back
#define mp make_pair
#define f first
#define s second

map <int, bool> M[200007];

signed main()
	{
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);

		int n, m, i, j, u, v;
		bool ans = 0;

		cin >> n >> m;

		for(i = 0; i < m; i++)
			{
				cin >> u >> v;
				M[u][v] = M[v][u] = 1;
			}

		for(i = 1; i <= n; i++)
			if(M[1][i] && M[i][n])
				ans = 1;

		if(ans) cout << "POSSIBLE\n";
		else cout << "IMPOSSIBLE\n";
		return 0;
	}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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


  int n,k;
  cin >> n >> k;
  //  priority_queue<long double> q;
  vector<long double> p(n);
  vector<long double> ex(n);
  rep(i,n){
    cin >> p[i];
  }
  rep(i,n){
    ex[i] = (1+p[i])/2;
  }
  long double ans =0;
  long double tans =0;
  rep(i,k){
    tans += ex[i];
  }
  ans = tans;
  rep(i,n-k){
    tans += ex[i+k] - ex[i];
    ans = max(ans,tans);
  }
  cout << fixed << setprecision(12) << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 6528
N = int(input())
word = []
S = input()
word.append(S)
flag = 0
for i in range(N-1):
  S = input()
  if S[0] == word[i][-1]:
    if S not in word:
      word.append(S)
    else:
      print("No")
      flag +=1
      break
  else:
    print("No")
    flag += 1
    break
if flag == 0:
  print("Yes")

Measured memory_bytes: 3064
val={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
rom=['I','V','X','L','C','D','M']
while True:
    try:
        s = list(input().strip())
        w = 0
        c = s[0]
        s = s[1:]
        while len(s) > 0:
            if rom.index(s[0]) <= rom.index(c):
                w += val[c]
            else:
                w -= val[c]
            c = s[0]
            s = s[1:]

        w += val[c]
        print(w)

    except EOFError:
        break

Measured memory_bytes: 7392
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll W, a, b;
  cin >> W >> a >> b;
  ll ans = (a < b) ? b - (a + W) : a - (b + W);
  cout << max(ans, 0LL) << endl;
  return 0;
}

Measured memory_bytes: 3596
package main 

import "fmt"

func main() {
  var count [10]int
  var a, b, c int
  fmt.Scan(&a, &b, &c)
  count[a]++
  count[b]++
  count[c]++
  
  if count[5] == 2 && count[7] == 1 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)

int main() {

	ll l, r, a, b, mini = 2019;
	cin >> l >> r;

	const int p = 2019;

	if (r - l >= 2019) cout << 0 << endl;
	else {
		rep(i, l, r) {
			rep(j, l + 1, r + 1) {
				a = i % p;
				b = j % p;
				a *= b;
				mini = min(mini, a % p);
			}
		}
		cout << mini << endl;
	}


	return 0;
}


Measured memory_bytes: 256
//Name: The Sorcerer's Donut
//Level:
//Category:
//Note:

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <array>
#include <map>

using namespace std;

#define TIMES(i,n) for(int i = 0; i < (n); ++i)

const int DR[] = {
    0, -1, -1, -1, 0, 1, 1, 1
};
const int DC[] = {
    1, 1, 0, -1, -1, -1, 0, 1
};

array<array<bool,20>,10> visited;

string search(int r, int c, int dir, const vector<string> &s, map<string,int> &memo) {
    const int H = s.size();
    const int W = s[0].size();
    string res;
    TIMES(i, H) {
        TIMES(j, W) {
            visited[i][j] = false;
        }
    }
    while(!visited[r][c]) {
        visited[r][c] = true;
        res += s[r][c];
        if(res.size() > 1) memo[res]++;
        r = (r+DR[dir]+H) % H;
        c = (c+DC[dir]+W) % W;
    }
    return res;
}

bool solve() {
    int H, W;
    cin >> H >> W;
    if(!H && !W) return false;

    vector<string> s(H);
    TIMES(i, H) {
        cin >> s[i];
    }
    map<string,int> memo;
    for(int r = 0; r < H; ++r) {
        for(int c = 0; c < W; ++c) {
            for(int dir = 0; dir < 8; ++dir) {
                search(r, c, dir, s, memo);
            }
        }
    }
    string ans = "";
    for(const auto &p : memo) {
        if(p.second < 2) continue;
        if(p.first.size() > ans.size() || (p.first.size() == ans.size() && p.first < ans)) {
            ans = p.first;
        }
    }
    if(ans == "") ans = "0";
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 35960
package main

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

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

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()

	c := 0
	ans := 0
	for _, e := range s {
		switch e {
		case 'A':
			c++
		case 'C':
			c++
		case 'G':
			c++
		case 'T':
			c++
		default:
			ans = max(ans, c)
			c = 0
		}
	}
	ans = max(ans, c)
	fmt.Fprintln(wr, ans)
}


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

main() {

	
	char a[16];//array
	int c=0;//count
	int i = 0;

	cin >> a;

	if (a[i] != 'C') {
		c++;
	}
	i++;
	if (a[i] != 'O') {
			c++;
		}
	i++;
	if (a[i] != 'D') {
			c++;
		}
	i++;
	if (a[i] != 'E') {
		c++;
	}
	i++;
	if (a[i] != 'F') {
		c++;
	}
	i++;
	if (a[i] != 'E') {
		c++;
	}
	i++;
	if (a[i] != 'S') {
		c++;
	}
	i++;
	if (a[i] != 'T') {
		c++;
	}
	i++;
	if (a[i] != 'I') {
		c++;
	}
	i++;
	if (a[i] != 'V') {
		c++;
	}
	i++;
	if (a[i] != 'A') {
		c++;
	}
	i++;
	if (a[i] != 'L') {
		c++;
	}
	i++; 
	if (a[i] != '2') {
		c++;
	}
	i++; 
	if (a[i] != '0') {
		c++;
	}
	i++;
	if (a[i] != '1') {
		c++;
	}
	i++;
	if (a[i] != '6') {
		c++;
	}

	cout << c;


	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
N, M = map(int, input().split())
ab = [tuple(map(lambda x: int(x) - 1, readline().split())) for _ in range(M)]
class UnionFind:
    def __init__(self, size):
        self.rank = [-1] * size
        self.number = [1] * size
    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x
    def union(self, s1, s2):
        if s1 == s2:
            return
        if self.rank[s1] == self.rank[s2]:
            self.rank[s1] -= 1
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        elif self.rank[s1] < self.rank[s2]:
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        else:
            self.rank[s1] = s2
            self.number[s2] += self.number[s1]
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in ab[1:][::-1]:
    px = uf.find(x)
    py = uf.find(y)
    if px != py:
        p -= uf.number[px] * uf.number[py]
        uf.union(px, py)
    ans.append(p)
print(*ans[::-1], sep="\n")


Measured memory_bytes: 26048
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef vector<vector<double> > vvd;

int main(){

    vvi  c(3, vi(3, 0));
    vi a(3, 0);
    vi b(3, 0);

    for(int i=0; i<3; ++i){
      for(int j=0; j<3; ++j){
          cin >> c[i][j];
      }
    }

    bool isFound = false;

    for(int i=0; i<=c[0][0]; ++i){
        a[0] = i;
        b[0] = c[0][0]-i;

        a[1] = c[1][0]-b[0];
        a[2] = c[2][0]-b[0];

        b[1] = c[0][1]-a[0];
        b[2] = c[0][2]-a[0];

        if( a[1]<0 or a[2]<0 or b[1]<0 or b[2]<0 or
                c[1][1] != a[1]+b[1] or
                c[1][2] != a[1]+b[2] or
                c[2][1] != a[2]+b[1] or
                c[2][2] != a[2]+b[2] )
            continue;

        isFound = true;
        break;
    }

    if( isFound ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int i,j,limit=1000000,count;
	int prime[1000000];
	for(i=0;i<limit;i++){
		prime[i]=i;
	}
	for(i=2;i*i<limit;i++){
	if(prime[i]){
	    for(j=i*2;j<limit;j+=i){
	    prime[j]=0;
	}}}
	int n;
	while(scanf("%d",&n)!=EOF){
	    count=0;
    	for(i=2;i<=n;i++){
    	    if(prime[i]!=0){
		        count++;
		    }}
	printf("%d\n", count);
	}
	return 0;
}


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

int main(){
  int n,m,sum=0;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a; cin >> a; sum+=a;
  }
  if(sum>n) cout << "-1" << endl;
  else cout << n-sum << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();ite++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define mod(x) ((x)%MOD)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

//---------------------
#define MAXN 100000
ll MOD = 1;
//---------------------

int add(ll a,ll b){
    return (int)((a+b)%MOD);
}

int mult(ll a,ll b){
    return (int)(a*b%MOD);
}

ll mypow(int i){
    ll ret = 1;
    for(int j = 0; j < i;j++){
        ret *= 10;
    }
    return ret;
}

struct mat{
  	ll m[3][3];
  	mat(){
  		memset(m,0,sizeof(m));
  	}
  	mat(	ll a00, ll a01, ll a02,
  			ll a10, ll a11, ll a12,
  			ll a20, ll a21, ll a22){
  				m[0][0]=a00;m[0][1]=a01;m[0][2]=a02;
  				m[1][0]=a10;m[1][1]=a11;m[1][2]=a12;
  				m[2][0]=a20;m[2][1]=a21;m[2][2]=a22;
  			}
}src,ans,unit;

void init() {
    memset(unit.m,0,sizeof(unit.m));
    memset(src.m,0,sizeof(src.m));
    unit.m[0][0]=(unit.m[1][1]=(unit.m[2][2]=1));
}

mat operator*(mat m1,mat m2) {
    mat t;
    ll r;
    for(int i = 0;i < 3;i++) {
        for(int j = 0;j < 3;j++) {
            r = 0;
            for(int k = 0;k < 3;k++) {
                r = add(r,mult(m1.m[i][k],m2.m[k][j]));
            }
            t.m[i][j] = r;
        }
    }
    return t;
}

mat qpow(ll x,mat src) {
    if(x == 0) return unit;
    mat ret = qpow(x/2,src);
    ret = ret*ret;
    if(x & 1) ret = ret * src;
    return ret;
}


ll l,a,b,m,maxelement;
ll numketa[19];

int main(){
    init();
    cin >> l >> a >> b >> m;
    MOD=m;
    numketa[0]=0;
    for(int i = 18;i >= 1;i--){
    	ll maxnum = (mypow(i) - 1);
    	//cout << maxnum << endl;
    	ll minnum = mypow(i-1)-1;
    	if(maxnum - a < 0) break;
    	ll maxsum = min(l,(maxnum-a)/b + 1);
    	ll minsum = (minnum-a)<0?0:min(l,(minnum-a)/b + 1);
    	numketa[i] = maxsum - minsum;
    }

   ll s=a%MOD;

   mat vecm(0,s,1,0,0,0,0,0,0);

 	REP(i,19){
 		if(!numketa[i]) continue;
 		init();
 		src = mat(
 		ll(mypow(i))%MOD,0,0,
 		1,1,0,
 		0,b%MOD,1);
 		mat curm=qpow(numketa[i],src);
 		vecm = vecm*curm;
 	}

 	cout<<vecm.m[0][0]%MOD<<endl;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

std::vector<std::string> split(const std::string &s, const std::string &delim) {
  using string = std::string;
  std::vector<string> v;
  string::size_type pos = 0;
  while (pos != string::npos) {
    string::size_type p = s.find(delim, pos);
    if (p == string::npos) {
      v.push_back(s.substr(pos));
      break;
    }
    v.push_back(s.substr(pos, p - pos));
    pos = p + delim.size();
  }
  return v;
}

template<typename InputIterator> std::string join(InputIterator first, InputIterator last, const std::string &sep) {
  if (first == last) return "";
  std::stringstream ss;
  ss << *(first++);
  for_each(first, last, [&](auto &x) { ss << sep << x; });
  return ss.str();
}

main {
  vi dx = {1, -1, 4, -4};
  map<string, int> m;
  queue<string> q;
  q.emplace("01234567");
  while (q.size()) {
    string s = q.front();
    q.pop();
    int pos = distance(s.begin(), find(all(s), '0'));
    rep(i, 4) {
      if (pos + dx[i] < 0 || pos + dx[i] >= 8 || (i / 2 == 0 && pos / 4 != (pos + dx[i]) / 4)) continue;
      string t = s;
      swap(t[pos], t[pos + dx[i]]);
      if (m.count(t)) continue;
      q.push(t);
      m[t] = m[s] + 1;
    }
  }
  string s;
  while (getline(cin, s)) {
    auto x = split(s, " ");
    cout << m[join(all(x), "")] << endl;
  }
}

Measured memory_bytes: 5280
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int * pParam = NULL;
    int num = 0;
    int i, j;
    int sum = 0;
    
    // スペース区切りの整数の入力
    scanf("%d",&num);
    pParam = malloc( sizeof(int)*num);

    for(i = 0;i < num; ++i){
        scanf("%d", &pParam[i]);
    }
    /*
    for(i = 0;i < num; ++i){
        printf("%d\n", pParam[i]);
    }
     */
    for(i = 0;i < num; ++i){
        for(j = i+1;j < num; ++j){
            sum += pParam[i]*pParam[j];
        }
    }
    
    free(pParam);

    printf("%d",sum);
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
const int N = 101;
int d[N][N];

int solve(int i , int n , int m , int x , vector<int>vec, int ans , vector<int>cost) {


    int ii;
    if(i == n) {
        for(ii=0;ii<m;ii++) if(vec[ii]<x) break;
        if(ii == m) return ans;
        return INT_MAX-5;
    }

    vector<int>temp(m);
    for(ii=0;ii<m;ii++) temp[ii] = vec[ii] + d[i][ii];

    return min(solve(i+1 , n , m , x , vec , ans - cost[i] , cost) , solve(i+1 , n , m , x , temp , ans , cost));
}

int main() {

    int t = 1;
    //cin>>t;

    while(t--) {

        ll n,m,x;
        cin>>n>>m>>x;


        vector<ll>che(m);
        vector<int>cost(n);

        ll temp = 0;

        for(int i=0;i<n;i++) {
            cin>>cost[i];
            for(int j=0;j<m;j++) {
                cin>>d[i][j];
                che[j]+=d[i][j];
            }
            temp+=cost[i];
        }

        for(int i=0;i<m;i++) {

            if(che[i]<x) {
                cout<<"-1\n";
                return 0;
            }
        }

        vector<int>vec(m,0);

        ll ans = solve(0 , n , m , x , vec , temp , cost);
        cout<<ans<<"\n";

    }

}




Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    int prev, cur; cin >> prev;
    for (int i = 1; i < n; i++) {
        int cur; cin >> cur;
        if (prev + cur >= k) {
            cout << "Possible" << endl;
            for (int j = 1; j < i; j++) cout << j << endl;
            for (int j = n-1; j >= i; j--) cout << j << endl;
            return 0;
        }
        prev = cur;
    }
    cout << "Impossible" << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>
using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const int64_t BINF = 10000000000000001;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int sum=0;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        
    }
    SORT(a);
    int cost = INF;
    for (int i = a[0]; i <= a[n - 1]; ++i) {
        sum = 0;
        for (int j = 0; j <n; ++j) {
            sum += (a[j] - i)*(a[j] - i);
        }
        cost = min(sum, cost);
    }
    cout << cost << endl;
    return 0;
}


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

int main(){
  int n;  cin >> n;
  vector<int>P(n);
  vector<int>Q(n);
  for(int i=0;i<n;i++){
    cin >> P.at(i);
  }
  for(int i=0;i<n;i++){
    cin >> Q.at(i);
  }
  vector<int>A(n);
  for(int i=0;i<n;i++){
    A.at(i) = i + 1;
  }

  int pe,qe;
  int jun = 1;
  do{
    int p = 0;
    int q = 0;
    for(int i=0;i<n;i++){
      if(A.at(i) == P.at(i))  p++;
      if(A.at(i) == Q.at(i))  q++;
    }
    if(p == n)  pe = jun;
    if(q == n)  qe = jun;
    jun++;
  }while(next_permutation(A.begin(),A.end()));
  if(pe - qe >= 0) cout << pe - qe << endl;
  else  cout << qe - pe << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = {1, 0, -1, 0}, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};


int main() {
	int h,a;
    cin>>h>>a;
    int cnt = h/a;
    if(h%a!=0) cnt++;
    cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int x1, y1, x2, y2, x, y;
    cin >> x1 >> y1 >> x2 >> y2;
    x = x2 - x1;
    y = y2 - y1;
    cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x;
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc117/tasks/abc117_d
// 問題文
// N 個の非負整数 A1,A2,...,AN および非負整数 K が与えられます。
// 0 以上 K 以下の整数 X に対して、f(X)=(X XOR A1) + (X XOR A2) + ... + (X XOR AN) とします。
// ここで、非負整数 a,b に対して a XOR b は a と b のビットごとの排他的論理和を表します。
// f の最大値を求めてください。
// 制約
// 入力は全て整数である
// 1 ? N ? 10^5
// 0 ? K ? 10^12
// 0 ? Ai ? 10^12
//
// 入力
// 入力は以下の形式で標準入力から与えられる。
// N K
// A1 A2 ... AN
//
// 出力
// f の最大値を出力せよ。
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()


vector< vector<ll> > dp(51, vector<ll>(2,-1));

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  
  REP(i,N) cin >> A[i];

  dp[50][0] = 0;
  dp[50][1] = -1;
  for( int b=50-1; b>=0; --b ) {
    ll mask = 1LL << b;
    ll cnt1 = 0;
    REP(i,N) {
      if ( A[i] & mask ) cnt1++;
    }

    // Xi として 0 or 1 を選んだ時のスコア
    ll score0 = cnt1 * mask;
    ll score1 = (N-cnt1) * mask;
    
    // dp[i][0] : i bit目までの合計値、上位bitはKと一致
    // dp[i][1] : i bit目までの合計値、上位bitはKよりも小さい

    // dp[i+1][0] <= dp[i][0] : Xi == Ki なので、Ki を見てscore0/1を加算
    dp[b][0] = dp[b+1][0] + ((K & mask) ? score1 : score0);
    
    // dp[i+1][1] <= dp[i][0] : これは Ki==1 の場合のみ発生。Xiは自動的に 0 と決まる
    //            <= dp[i][1] : Xi は 0/1 どちらでもいいので、scoreの大きい方
    //  但し、上位Bitがずっと K と一致したものしかなかった場合（KのMSBがずっと0だった場合など）
    //  dp[b+1][1] から加算するという遷移は存在しない
    if ( dp[b+1][1] != -1 )
      dp[b][1] = dp[b+1][1] + max( score0, score1 );
    if ( K & mask )
      dp[b][1] = max( dp[b][1], dp[b+1][0] + score0 );
  }
//  REP(i,N+1)
//    cout << dp[i][0] << " ";
//  cout << endl;
//  REP(i,N+1)
//    cout << dp[i][1] << " ";
//  cout << endl;

  cout << max(dp[0][1], dp[0][0]) << endl;

}



Measured memory_bytes: 1024