akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

using bellman_cost = int; //辺や頂点に持たせたいコストの型

template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	// from, to, cost
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};

template<class T>
struct Vertex
{
	T cost;
	bool valid = false; // 到達不能または無限にコストが減るときfalse
	Vertex(T v1) : cost(v1) {}
	Vertex() {}
};
using vertex = Vertex<bellman_cost>;

template<class T>
struct Edge
{
	int to;
	T cost;
	Edge(int t, T c) : to(t), cost(c) {}
	Edge() {}
};
using edge = Edge<bellman_cost>;
using graph = Graph<vertex, edge>;

template<class T, class V, class E>
void Bellmanford(Graph<V, E>& G, int s, T INF_COST)
{
	auto &v = G.v;
	auto &e = G.e;
	for (auto& vv : v) vv.cost = INF_COST, vv.valid = false;
	v[s].cost = 0, v[s].valid = true;
	for (int i = 0; i + 1 < (int) v.size(); i++) {
		for (int j = 0; j < (int) v.size(); j++) {
			for (auto& x: e[j]) {
				if (v[j].cost == INF_COST) continue;
				v[x.to].cost = min(v[x.to].cost, v[j].cost + x.cost);
				v[x.to].valid = true;
			}
		}
	}
	auto valid_check = [&](auto f, int pos) {
		if (!v[pos].valid) return;
		v[pos].valid = false;
		for (auto& y: e[pos]) {
			f(f, y.to);
		}
	};
	for (int i = 0; i < (int) v.size(); i++) {
		for (auto& x: e[i]) {
			if (v[i].cost == INF_COST) continue;
			if (v[x.to].cost > v[i].cost + x.cost) {
				valid_check(valid_check, x.to);
			}
		}
	}
}

void solve(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C) {
	graph g(N);
	for (int i = 0; i < M; i++) {
		g.add_edge(A[i]-1, B[i]-1, -(C[i]-P));
	}
	Bellmanford(g, 0, INT_MAX);
	if (!g.v[N-1].valid) cout << -1 << endl;
	else cout << max(-g.v[N-1].cost, 0) << endl;
}

signed main() {
	long long N;
	scanf("%lld",&N);
	long long M;
	scanf("%lld",&M);
	long long P;
	scanf("%lld",&P);
	std::vector<long long> A(M);
	std::vector<long long> B(M);
	std::vector<long long> C(M);
	for(int i = 0 ; i < M ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
		scanf("%lld",&C[i]);
	}
	solve(N, M, P, std::move(A), std::move(B), std::move(C));
	return 0;
}


Measured memory_bytes: 512
b1,b2,b3 = (int(x) for x in input().split())
if b1 == 1 and b2 == 0 and b3 == 0:
    print("Close")
elif b1 == 0 and b2 == 1 and b3 == 0:
    print("Close")
elif b1 == 1 and b2 == 1 and b3 == 0:
    print("Open")
elif b1 == 0 and b2 == 0 and b3 == 1:
    print("Open")
elif b1 == 0 and b2 == 0 and b3 == 0:
    print("Close")


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

int main(){
    string str;
    map<char, int> m;
    int Max = 0;
    int Min = 999999;
    int cnt = 0;
    cin >> str;
    
    m['a'] = 0;
    m['b'] = 0;
    m['c'] = 0;

    for (int i = 0; i < str.size(); i++)
    {
        m[str.at(i)]++;
    }

    for(auto itr: m){
        Max = max(Max, itr.second);
        Min = min(Min, itr.second);
    }

    if (Max - Min <= 1) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 512
#include <cstdio>
#include <cmath>

#define MAX_N 10


/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;
int x[MAX_N], y[MAX_N];


int main () {

	double ave = 0.0;

	// 個数と長さの読込み
	scanf("%d", &N);

	for(int i = 0; i < N; i++) 
		scanf("%d %d", x + i, y + i);

	for(int i = 0; i < N; i++) 
		for(int j = i; j < N; j++) 
			ave += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
	ave *= 2;
	ave /= N;
						
	printf("%.10lf\n", ave);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main()
{
  int x,y,w,h,r;
  std::cin >> w >> h >> x >> y >> r;
  if(w < (x+r) || h < (y+r) || (x-r) < 0 || (y-r) < 0 || (x<0) || (y<0)) std::cout << "No" << std::endl;
  else std::cout << "Yes" << std::endl;
  return 0;
}



Measured memory_bytes: 3132
#include<stdio.h>

int main(){
  int num1, num2;
  while(1) {
    scanf("%d%d", &num1,&num2);
    if(num1==0 && num2==0){
      break;
    }
    int max,min;
    if(num1 > num2){
      max = num1; 
      min = num2;
    }else{ 
      max = num2; 
      min = num1;
    }
    printf("%d %d\n",min,max);
  }
  return 0;
}

Measured memory_bytes: 600
def read():
    N, R = list(map(int, input().strip().split()))
    return N, R

def solve(N, R):
    inner_rating = 0
    if N >= 10:
        inner_rating = R
    else:
        inner_rating = R + 100 * (10 - N)
    return inner_rating

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


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

int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}

int main() {
  int k;
  cin >> k;
  int sum = 0;
  for (int a = 1; a <= k; ++a) {
    for (int b = 1; b <= k; ++b) {
      for (int c = 1; c <= k; ++c) {
        sum += gcd(a, gcd(b, c));
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100010;

int a[N];
int n;
int cnt1,cnt2;

int main(){
	n=get();
	int mx=0,mi=1e+9;
	fo(i,1,n){
		a[i]=get();
		mx=max(mx,a[i]);
		mi=min(mi,a[i]);
	}
	bool ans=1;
	if (mx-mi>1)ans=0;
	fo(i,1,n){
		if (a[i]==mi)cnt1++;
		else cnt2++;
	}
	if (cnt2==0){
		if (!((mi>=1&&mi<=n/2)||mi==n-1))ans=0;
	}
	else{
		if (cnt2==1)ans=0;
		if (!(mi<=cnt1-1+cnt2/2&&mi>=cnt1))ans=0;
		if (cnt2>=2&&!(mx>=cnt1+1&&mx<=cnt1+cnt2/2))ans=0;
	}
	if (ans)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[100];
	for (int i = 0; i < n; i++){
		cin >> a[i];
		if (i == n - 1){
			cout << a[i];
			for (i=n-2; i >= 0; i--){
				cout << " " << a[i];
			}
			cout << endl;
			break;
		}
	}
	return 0;
	}


Measured memory_bytes: 3072
import std.stdio, std.conv, std.string, std.algorithm, std.array;

int calc_point(int[] arr) {
  int i = 0;
  int[11] point;
  int strike = 0;
  int game = 1;
  while(game <= 10) {
    if (arr[i] == 10) {
      point[game] += 10 + arr[i + 1] + arr[i + 2];
      i += 1;
    }
    else {
      if (strike > 0) {
        int p = (arr[i] + arr[i + 1]);
        point[game - 1] += p;
        strike = 0;
      }
      
      if ((arr[i] + arr[i + 1]) == 10) {
        point[game] += 10 + arr[i + 2];
      }
      else {
        point[game] += (arr[i] + arr[i + 1]);
      }
      i += 2;
    }
    game += 1;
  }
  return point.reduce!("a + b");
}

void main() {
  for(int t; readf("%d\n", &t), t != 0;) {
    int[][int] people;
    foreach(i; 0..t) {
      int[] line = readln.chomp.split(" ").map!(to!(int)).array;
      people[line[1..$].calc_point] ~= line[0];
    }
    int[] keys = sort!("a > b")(people.keys).array;
    foreach(point; keys) {
      int[] ordered = sort!("a < b")(people[point]).array;
      foreach(id; ordered) {
        writeln(id, " ", point);
      }
    }    
  }
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <stdlib.h>
int main(void) {
	int N,A[100010] = {},i,j;
	int sum = 0;
	
	scanf("%d",&N);
	for (i = 1;i <= N;i++)
		scanf("%d",&A[i]);
	for (i = 1;i <= N+1;i++)
		sum += abs(A[i] - A[i-1]);
	for (i = 1;i <= N;i++) {
		int ans;
		ans = sum - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1]);
		printf("%d\n",ans);
	}
}


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

using namespace std;

const int N=55,M=105,P=1e9+7;
long long f[N][M][M],ans;
int n,a[M],m;

int main(){
	scanf("%d",&n);
	m=2*n-1;
	for(int i=1;i<=m;i++)scanf("%d",&a[i]);
	sort(a+1,a+m+1);
	f[1][1][1]=1;
	for(int i=1;i<n;i++){
		int l=a[n-i]!=a[n-i+1];
		int r=a[n+i]!=a[n+i-1];
		for(int j=1;j<=m;j++)for(int k=1;k<=m;k++)if(f[i][j][k]){
			long long s=f[i][j][k]%P;
			int dj=j+l+r,dk=k+l;
			for(int t=1;t<dk;t++)f[i+1][dj-(dk-t-1)][t]+=s;
			f[i+1][dj][dk]+=s;
			for(int t=dk+1;t<=dj;t++)f[i+1][dj-(t-dk-1)][dk+1]+=s;
		}
	}
	for(int i=1;i<=m;i++)for(int j=1;j<=m;j++)ans+=f[n][i][j];
	printf("%d\n",ans%P);
	return 0;
}

Measured memory_bytes: 3072
var n,i,a,b,c,j,k,l,o:longint;   x,y:ansistring;
begin
readln(x);
readln(y);
for i:=1 to length(x)+length(y)do
  if i mod 2=1 then write(x[i div 2+1])
  else write(y[i div 2]);writeln;
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
int main()
{
    int d;
    cin>>d;
    cout<<d*d<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;
int main()
{
    int n,k,A[1001],c=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    sort(A,A+n);
    for(int i=0;i<k;i++)c+=A[i];
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

int main() {
	int n;
	cin >> n;
	int p = 0;
	vector<int> data(n);
	ff(i, 0, n) {
		cin >> data.at(i);
	}
	sort(data);
	ff(i, 1, n) {
		if (data.at(i - 1) == data.at(i))p++;
	}
	int ans = n;
	while (p>0) {
		ans -= 2;
		p -= 2;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	long n, m;
	scanf("%ld%ld", &n, &m);
	long ans = 0;
	long s = m / 2;
	if(n <= s) {
		ans += n;
		m -= 2 * n;
	}else{
		ans += s;
		m -= 2 * s;
	}
	ans += m / 4;
	printf("%ld\n", ans);
}


Measured memory_bytes: 256
import math
for i in range(input()):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split(" "))
    if y2==y1 or y3==y1:
        if y2==y1:
            a2=-(x3-x1)/(y3-y1)
            b2=((y3+y1)-a2*(x1+x3))/2.0
            a,b,c,d,e,f=1.0,0.0,(x1+x2)/2.0,-a2,1.0,b2
        else:
            a1=-(x2-x1)/(y2-y1)
            b1=((y2+y1)-a1*(x1+x2))/2.0
            a,b,c,d,e,f=-a1,1.0,b1,1.0,0.0,(x1+x3)/2.0
    else:
        a1=-(x2-x1)/(y2-y1)
        a2=-(x3-x1)/(y3-y1)
        b1=((y2+y1)-a1*(x1+x2))/2.0
        b2=((y3+y1)-a2*(x1+x3))/2.0
        a,b,c,d,e,f=-a1,1.0,b1,-a2,1.0,b2
    py=(a*f-c*d)/(a*e-b*d)
    px=(c*e-f*b)/(a*e-b*d)
    r=math.sqrt((px-x1)**2 + (py-y1)**2)
    print "{0:.3f} {1:.3f} {2:.3f}".format(px,py,r)

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

using LL = long long;

const int max_N = 110;

int l, k;

LL f[max_N][2], ans;

int main() {
    scanf("%d%d", &l, &k);
    f[0][0] = 1;
    for (int i = 1; i <= l; ++i) {
        f[i][0] = f[i - 1][1];
        f[i][1] = f[i - 1][0];
        if (i >= k) f[i][1] += f[i - k][0];
        ans += f[i][1];
        //printf("f[%d][%d] = %lld\n", i, 0, f[i][0]);
        //printf("f[%d][%d] = %lld\n", i, 1, f[i][1]);
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 3216
N = int(input())

x = 0

#考え方: c[i][j] := N以下の先頭がiで末尾がjとなる整数の数
#組み合わせの数はc[i][j]*c[j][i]の総和で求まる

c = [[0]*10 for _ in range(10)]

for num in range(N+1):
    i = int(str(num)[0])
    j = int(str(num)[-1])
    c[i][j] += 1

for i in range(1,10):
    for j in range(1,10):
        x += c[i][j]*c[j][i]

print(x)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    int n, a;
    int count = 0;
    
    cin >> n;
    
    for(int i=0; i<n; i++){
        cin >> a;
        
        if(a%2==1){
            count++;
        }
    }
    
    if(count%2==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair


int main()
{
    int n;
    cin>>n;
    ll times=0;

    if(n%1000==0)cout<<0<<endl;
    else{
    times=(n/1000)+1;
    ll ans =  (times*1000)-n;
    cout<<ans<<endl;
    }


}



Measured memory_bytes: 3628
iscoprime(P, i) = !any(x -> i % x == 0, P)

function sieve(n)
    p = trues(n)
    p[1] = false
    for i in 2:Int(ceil(sqrt(n)))
        if p[i]
            j = 0
            while i*(j+2) <= n
                p[i*(j+2)] = false
                j += 1
            end
        end
    end
    findall(x->x, p)
end

function factor(n)
    i = 1
    m = Int(ceil(sqrt(n)))
    res = Tuple{Int, Int}[]
    sizehint!(res, m)
    for a in 2:m
        n%a != 0 && continue
        ex = 0
        while n%a == 0
            ex += 1
            n /= a
        end

        push!(res, (a, ex))
    end
    n != 1 && push!(res, (n, 1))
    
    return res
end

function main()
    n = parse(Int, readline())
    

    fc = factor(n)
    ans = 0
    for (p, c) in fc
        cnt = c
        x = 1
        while x <= cnt
            cnt -= x
            x += 1
            ans += 1
        end
    end

    println(ans)
end

main()


Measured memory_bytes: 164732
#include <iostream>
using namespace std;
  
typedef long long ll;
ll m, n;
  
#define MOD 1000000007
  
ll mod_power(ll x, ll n, ll mod) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
  
int main() {
  cin >> m >> n;
  cout << mod_power(m, n, MOD) << endl;
  return 0;
}

Measured memory_bytes: 3072
import collections
s = input()
a = []
for i in range(26):
    cnt = collections.Counter(s)[chr(i+97)]
    if cnt == 0:
        a.append(len(s))
        continue
    num = 0
    ma = 0
    for j in s:
        if j == chr(i+97):
            ans = num
            ma = max(ma, ans)
            num = 0
        else:
            num += 1
        ans = num
        ma = max(ma, ans)
    a.append(ma)
print(min(a))

Measured memory_bytes: 9404
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int i, pos;
	string s;
	cin >> s;
	if (s[0] == 'A') {
		// 大文字'C'が3文字目と末尾から2文字目の間にちょうど1個含まれるか
		pos = (int)s.find('C');
		if (pos != string::npos && pos == s.rfind('C') && (pos >= 2 && pos <= s.size() - 2)) {
			for (i = 1; i < s.size(); i++) {
				// pos番目以外で大文字が出たらNG
				if (i != pos && s[i] >= 'A' && s[i] <= 'Z') {
					cout << "WA" << endl;
					return 0;
				}
			}
			cout << "AC" << endl;
			return 0;
		}
	}
	cout << "WA" << endl;
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <string>
using namespace std;
struct Tree
{
	int val;
	Tree *left,*right;
};
void Insert(Tree *&root,Tree *x)
{
	if(root == NULL)
	{
		root = x;
		return;
	}
	if(root->val > x->val)
	{
		if(root->left == NULL) root->left = x;
		else Insert(root->left,x); 
	}
	else
	{
		if(root->right == NULL) root->right = x;
		else Insert(root->right,x);
	}
}
void Pre_Print(Tree *root)
{
	if(root != NULL) cout<<" "<<root->val;
	if(root->left != NULL)Pre_Print(root->left);
	if(root->right != NULL)Pre_Print(root->right);
}
void In_Order(Tree *root)
{
	if(root->left != NULL) In_Order(root->left);
	if(root != NULL) cout<<" "<<root->val;
	if(root->right != NULL) In_Order(root->right);
	
}
int main(void)
{
	int n,k; string m;
	Tree *root,*x;
	root = NULL;
	cin>>n;
	while(n--)
	{
		cin>>m;
		if(m == "insert")
		{
			cin>>k;
			x = new Tree; x->val = k;
			x->left = NULL; x->right = NULL;
			Insert(root,x);
		}
		else
		{
			In_Order(root); cout<<endl;
			Pre_Print(root); cout<<endl;
		}
	}
	return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    int maxv = max(a, b);
    maxv = max(maxv, c);

    int sum = a + b + c;

    int count = 0;

    while(1){
        if(sum % 3 == 0 and sum/3 >= maxv){
            break;
        }
        sum += 2;
        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author amotoma3
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long s = in.nextLong();

            if (n < s) {
                out.println(-1);
                return;
            }

            if (n == s) {
                out.println(n + 1);
                return;
            }

            for (long i = 2; i <= 1000000; i++) {
                long tmp = n;
                long sum = 0;
                while (tmp > 0) {
                    sum += tmp % i;
                    tmp /= i;
                }
                if (sum == s) {
                    out.println(i);
                    return;
                }
            }

            long sqrt = (long) Math.sqrt(n);
            if (sqrt * sqrt >= n) sqrt--;
            for (long i = sqrt; i > 0; i--) {
                long b = (n - s) / i + 1;
                if (n / b + n % b == s) {
                    out.println(b);
                    return;
                }
            }

            out.println(-1);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 25044
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'a','b','c','d','e','f','g','h','i','j','k','l',
                 'm','n','o','p','q','r','s','t','u','v','w','x',
                 'y','z'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v;

int main(){
  ll n, m;
  cin >> n >> m;
  
  priority_queue<ll> que;
  for (int i=0;i<n;i++){
    ll tmp;
    cin >> tmp;
    que.push(tmp);
  }
  
  for (int i=0;i<m;i++){
    ll num = que.top(); que.pop();
    que.push(num/2);
  }
  
  ll ans = 0;
  while (!que.empty()){
    ll num2 = que.top(); que.pop();
    ans += num2;
    //cout << ans << endl;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    sort(all(vec));
    vector<pair<ll,ll> > count(0);
    count.push_back(pair<ll,ll> (vec[0],1));
    rep(i,N - 1){
        if (vec[i] == vec[i + 1]){
            int len_count = count.size();
            count[len_count - 1].second++;
        }
        else{
            count.push_back(pair<ll,ll> (vec[i + 1],1));
        }
    }
    int len_count = count.size();
    ll c1 = 0;
    ll c2 = 0;
    rep(i,len_count){
        if (count[i].second >= 4){
            c1 = count[i].first;
            c2 = count[i].first;
        }
        else if (count[i].second >= 2){
            c2 = c1;
            c1 = count[i].first;
        }
    }
    cout << c1 * c2 << endl;
}


Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
	int a,b,c,d,i;

	scanf("%d %d %d",&a,&b,&c);
	for(i=1;i<c+1;i++){
		if(c%i==0){
			if(a<=i && i<=b){
				d=d+1;
			}
		}
	}

	printf("%d\n",d);

	return 0;

}

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

int main() {
  int n, k;
  cin >> n >> k;
  char s[n+1];
  for ( int i = 0; i < n; i++ ) {
    cin >> s[i];
  }
  s[n] = '\0';

  s[k-1] = tolower(s[k-1]);

  cout << s << endl;

  return 0;
}

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

ll merge_cnt(vector<ll> &a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin()+n/2);
    vector<ll> c(a.begin()+n/2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    // merge の処理
    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

ll n,k,num;
vector<ll> a;
map<ll,int> mp;
int main(){
    cin>>n>>k;
    a.resize(n+1);
    mp[0]=1;
    FOR(i,1,n+1){
        cin>>a[i];
        a[i]-=k;
        a[i]*=-1;
        a[i]+=a[i-1];
        num+=mp[a[i]];
        mp[a[i]]++;
    }
    cout<<merge_cnt(a)+num<<endl;
}

Measured memory_bytes: 17496
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int x,n;
    while(cin>>x>>n){
        if(2*n>=x)cout<<"0"<<endl;
        else cout<<(x-2*n)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a)+1)
    for i,num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ca = cumsum(a)
cb = cumsum(b)

def sub(x):
    res = float("inf")
    for i in range(x+1):
        if i>n or (x-i)>m:
            continue
        res = min(res, ca[i] + cb[x-i])
    return res<=k
l = 0
r = n+m+1
while l+1<r:
    mm = (l+r)//2
    if sub(mm):
        l = mm
    else:
        r = mm
print(l)

Measured memory_bytes: 118040
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
/* -- template -- */

const int MAX = 1000100;
ll 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;//拡張euclid互除法
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll 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();
    ll X, Y;
    cin >> X >> Y;
    ll p = (2 * Y - X) / 3, q = (2 * X - Y) / 3;
    if((2 * Y - X) % 3 == 0 && (2 * X - Y) % 3 == 0)
        cout << COM(p + q, p) << endl;
    else
        cout << 0 << endl;
}


Measured memory_bytes: 23680
import java.io.BufferedReader
import java.util.*

fun main() = abc175b()

@OptIn(ExperimentalStdlibApi::class)
fun abc175b() = SimpleFastIOWithToken_abc175b().exec {
    val n = readInt()
    val lList = LongArray(n) { readLong() }

    var answer = 0L

    for (i in 0 until n) for (j in i + 1 until n) for (k in j + 1 until n) {
        val a = lList[i]
        val b = lList[j]
        val c = lList[k]
        if (a + b > c && b + c > a && c + a > b &&
            a != b && a != c && b != c
        )
            answer++
    }

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc175b(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc175b.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;

struct Sieve{
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n),f(n+1){
     f[0]=f[1]=-1;
     for(ll i=2;i<=n;i++){
       if(f[i]){
         continue;
       }
       primes.push_back(i);
       f[i]=i;
       for(ll j=i*i;j<=n;j+=i){
         if(!f[j]) f[j]=i;
       }
     }
  }
  bool isPrime(int x){
    return f[x]==x;
  }
  
  vector<int> factorlist(int x){
    vector<int> res;
    while(x!=1){
      res.push_back(f[x]);
      x/=f[x];
    }
    return res;
  }
  
  vector<P> factor(int x){
    vector<int> fl= factorlist(x);
    if(fl.size()==0){
      return {};
    }
    vector<P> res(1,P(fl[0],0));
    for(int p : fl){
      if(res.back().first==p){
        res.back().second++;
      }
      else{
        res.emplace_back(p,1);
      }
    }
    return res;
  }
};

int main(){
  int a;cin>>a;
  
  Sieve sieve(1000000);
  while(!sieve.isPrime(a)){
    a++;
  }
  
  cout<<a<<endl;
}


Measured memory_bytes: 4732
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;++i)
#define reh(i,a,b) for(int i=b;i>=a;--i)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
using namespace std;
typedef long long ll;
const int mx=1e5+10;
ll ans;
int  c1,c2;
int main(){
	string s1,s2;
	cin>>s1;
	s2=s1;
	int len=s1.length();
	reg (i,1,len-1) {
		if (s1[i]==s1[i-1]) {
		    ++c1;
			s1[i]=((s1[i]-'0')^1+'0');
		}

	}
	++c2;
	s2[0]=((s2[0]-'0')^1+'0');
	reg (i,1,len-1) {
	   if (s2[i]==s2[i-1]) {
		    ++c2;
			s2[i]=((s2[i]-'0')^1+'0');
		}
	}
	printf("%d\n",min(c1,c2));



	return 0;
}




Measured memory_bytes: 512
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
#ifndef ONLINE_JUDGE
    scanf("%lld", &a);
#else
    scanf("%I64d", &a);
#endif
    return a;
}

char a[1004];

int main() {
    scanf("%s", a);
    int n = gi();
    int l = strlen(a);
    for (int i = 0; i < l; i+=n)
        printf("%c", a[i]);
    printf("\n");

    return 0;
}


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

int main(){
    int n;
    std::cin >> n;
    
    std::map<long long, long long> seq;
    for(int i = 0; i < n; ++i){
        int val;
        std::cin >> val;

        auto itr = seq.find(val);
        if(seq.end() != itr){
            ++itr->second;
        }else{
            seq.insert(std::make_pair(val, 1));
        }
    }

    long long ans = 0;
    for(auto itr = seq.begin(); itr != seq.end(); ++itr){
        if(itr->second < itr->first){
            ans += itr->second;
        }else{
            ans += itr->second - itr->first;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 6272
n=int(input())
p=list(map(int,input().split()))
cnt=0

for i in range(n-2):
    #print(p[i])
    if(((p[i]<p[i+1]) and (p[i+1]<p[i+2]))or
    ((p[i]>p[i+1]) and (p[i+1]>p[i+2]))):
        cnt+=1

print(cnt)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			int A = scn.nextInt();
			int B = scn.nextInt();
			int C = scn.nextInt();
			int D = scn.nextInt();

			int result = 0;
			while(true) {
				C = C - B;
				if(C < 1) {
					result = 0;
					break;
				}
				A = A - D;
				if(A < 1) {
					result = 1;
					break;
				}
			}

			if(result == 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 27032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class73
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NM[0], M = NM[1];
            char[] S = new char[NM[0]];
            for (int i = 0; i < S.Length; i++) S[i] = 'x';
            bool imp = false;
            for (int i = 0; i < M; i++)
            {
                var sc = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int s = sc[0] - 1, c = sc[1];
                if (s < N)
                {

                    if (S[s] == 'x' || S[s] == c.ToString()[0])
                    {
                        S[s] = c.ToString()[0];
                    }
                    else imp = true;
                }
            }
            if (N == 1 && (S[0] == 'x' || S[0] == '0')) { Console.WriteLine("0");return; }
            if (S[0] == '0') imp = true;
            if (S[0] == 'x') S[0] = '1';
            for (int i = 1; i < N; i++)
            {
                if (S[i] == 'x') S[i] = '0';
            }
            Console.WriteLine(imp ? "-1" : $"{string.Join("", S)}");
        }
    }
}


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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = INF + 7;

/////////////////////////////////////////////////////////////////////

const int N = 1e5 + 10;

int main() {

   	sync;

	int n, k, ans = 0; cin >> n >> k;
	char last; cin >> last;
	bool flag = 1;
	for(int i = 1; i < n; i++) {
		char c; cin >> c;
		if (flag) {
			if (c != last && k > 0) ans++, k--, flag = 0;
		} else {
			if (c != last) ans++, flag = 1;
		}
		if (last == c) ans++;
		last = c;
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  
  /*
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  */
  
  cout << 6 -a -b << "\n";

}


Measured memory_bytes: 256
def main():
    N = int(input())
    S = sorted([int(input()) for _ in range(N)])
    ans = sum(S)
    if ans % 10 != 0:
        print(ans)
    else:
        for s in S:
            if (ans - s) % 10 != 0:
                print(max(ans - s, s))
                return
        print(0)


main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

constexpr int Y = 2019;
using lint = long long;

void solve() {
    int y = 0;
    std::vector<lint> cnt(Y, 0);
    cnt[y] = 1;

    std::string s;
    std::cin >> s;
    std::reverse(s.begin(), s.end());

    int ten = 1;
    for (char c : s) {
        (y += (c - '0') * ten % Y) %= Y;
        ++cnt[y];

        (ten *= 10) %= Y;
    }

    lint ans = 0;
    for (auto c : cnt) ans += c * (c - 1) / 2;

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    Int n, m;
    Int a[1001], b[1001], c[1001][20];
    cin >> n >> m;
    for(Int i=1; i<=m; i++){
        cin >> a[i] >> b[i];
        for(Int j=1; j<=b[i]; j++){
            cin >> c[i][j];
        }
    }

    const int INF = 1e9;
    vector<Int> dp(10001, INF);
    dp[0] = 0;

    for(Int i=1; i<=m; i++){
        Int now = 0;
        for(Int j=1; j<=b[i]; j++){
            now |= (1 << c[i][j] - 1);
        }
        for(Int bit=0; bit < (1<<n); bit++){
            if(dp[bit | now] > dp[bit]+a[i]){
                dp[bit | now] = dp[bit] + a[i];
            }
        }
    }

    if(dp[(1<<n)-1] == INF){
        cout << -1 << endl;
        return 0;
    }
    cout << dp[(1<<n)-1] << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k; cin>>n>>k; int a[n],dp[n];
    for(int i=0;i<n;i++)
    {cin>>a[i];dp[i]=INT_MAX;}
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i-1;j>=max(0,i-k);j--)
        dp[i]=min(dp[i],(dp[j]+abs(a[i]-a[j])));
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {

	var N, M int
	fmt.Scan(&N, &M)
	homeworks := 0
	for i := 0; i < M; i++ {
		var homework int
		fmt.Scan(&homework)
		homeworks += homework
	}

	restDay := N - homeworks
	if restDay >= 0 {
		fmt.Println(restDay)
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 2528
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.split(" ");
	//input = input.split("\n");
	input = input.split(" ").map((a)=>Number(a));
	//input = input.split("\n").map((a)=>Number(a));
  var K = input[0];
  var S = input[1];
  var output = 0;
  for(var i = 0; i <= K; i++){
    for(var j = 0; j <= K; j++){
      var Z = S - (i + j);
      if(Z >= 0 && Z <= K){
         output++;
         }
    }
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

using namespace std;
typedef long long int ll;
int main() {
    
    ll n, k, p[10001], i, dap=0;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    cin>>p[i];
    sort(p+1, p+(n+1));
    for(i=1;i<=k;i++)
    dap+=p[i];
    cout<<dap;
    
    
    return 0;
}

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  if ((B - A) % 2 == 0){
    cout << (B - A) / 2 << endl;
  }
  else {
    cout << min(N - B + 1 + (B - A - 1) / 2, A + (B - A - 1) / 2) << endl;
  }
}

Measured memory_bytes: 3600
var
  n:string;
  a:array['a'..'z'] of 0..1;
  s,i:longint;
  ch:char;
begin
  readln(n);
  for i:=1 to length(n) do a[n[i]]:=1;
  for ch:='a' to 'z' do s:=s+a[ch];
  if s=26 then begin writeln('None');exit;end;
  for ch:='a' to 'z' do if a[ch]=0 then begin writeln(ch);exit;end;
end.

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

int main() {
    int h, w;
    cin >> h >> w;
    int a[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];

    int ans = 0;
    vector<int> v;

    rep(i, h) rep(j, w) {
        if (a[i][j] % 2 == 1) {
            if (j == w - 1 && i == h - 1) continue;

            v.push_back(i + 1);
            v.push_back(j + 1);
            if (j < w - 1 && a[i][j + 1] % 2 == 1) {
                v.push_back(i + 1);
                v.push_back(j + 2);
                a[i][j]--, a[i][j + 1]++;
            } else if (i < h - 1 && a[i + 1][j] % 2 == 1) {
                v.push_back(i + 2);
                v.push_back(j + 1);
                a[i][j]--, a[i + 1][j]++;
            } else if (j < w - 1) {
                v.push_back(i + 1);
                v.push_back(j + 2);
                a[i][j]--, a[i][j + 1]++;
            } else if (i < h - 1) {
                v.push_back(i + 2);
                v.push_back(j + 1);
                a[i][j]--, a[i + 1][j]++;
            }
            ans++;
        }
    }

    cout << ans << endl;
    for (int i = 1; i <= v.size(); i++) {
        cout << v[i - 1];
        if (i != 1 && i % 4 == 0)
            cout << endl;
        else
            cout << ' ';
    }
    return 0;
}


Measured memory_bytes: 5104
n = int(input())
check = [[0] * 9 for i in range(9)]

for i in range(1,n+1):
    s=str(i)
    s1 = int(s[0]) - 1
    s2 = int(s[-1]) - 1
    if s2 == -1 : continue
    check[s1][s2] += 1

cnt = 0
for i in range(9):
    for j in range(9):
        cnt += check[i][j] * check[j][i]
print(cnt)


Measured memory_bytes: 3060
using System;

namespace codespace
{
    class Program
    {
        static void Main(string[] args)
        {
            int AC = 0, WA = 0, TLE = 0, RE = 0;
            int N = int.Parse(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                switch (Console.ReadLine())
                {
                    case "AC":
                        AC++;
                        break;
                    case "WA":
                        WA++;
                        break;
                    case "TLE":
                        TLE++;
                        break;
                    case "RE":
                        RE++;
                        break;
                }
            }
            Console.WriteLine("AC x " + AC);
            Console.WriteLine("WA x " + WA);
            Console.WriteLine("TLE x " + TLE);
            Console.WriteLine("RE x " + RE);
        }
    }
}


Measured memory_bytes: 30696
import fractions as fr
a,b,c,d = input().split()
a = int(a)
b= int(b)
c = int(c)
d = int(d)
s = b-a+1

cd = c*d // fr.gcd(c,d)
a_ = ((a-1)//c + (a-1)//d) - ((a-1)//cd)
b_ = (b//c + b//d) - (b//cd)
s_ = b_- a_
print(s-s_)

Measured memory_bytes: 5048
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        // long startTime = System.currentTimeMillis();

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        long a[] = new long[N];
        List<Long> evenList = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextLong();
            if (a[i] % 2 == 0) {
                evenList.add(a[i]);
            }
        }

        scanner.close();

        // 2で割れる回数の合計
        long count = evenList.stream().mapToLong(value -> {
            long cnt = 0L;
            while ((value % 2) == 0) {
                value = value / 2;
                cnt++;
            }
            return cnt;
        }).sum();

        System.out.println(count);

        // System.out.println(System.currentTimeMillis() - startTime);
    }
}


Measured memory_bytes: 40584
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
c = gets.chomp.split(" ").map(&:to_i)
arr = []
count = 0
while true
    point = a.shift
    count += b[point - 1]
    if arr[-1] == point - 1
        count += c[point - 2]
    end
    arr << point
    if a == []
        break
    end
end
puts count

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

int main() {
 
  int R,G,B,N ;
  cin >>R>>G>>B>>N ;
 int count = 0;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= N; j++){
      int k = N - R*i - G*j;
      if( 0 <= k && k <= N && k%B == 0){
	count++;	
      }
    }
  }
  cout << count<< endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int Amin(int *p,int size){
   int _min = inf;
   for(int i = 0;i < size;i++)
      if(p[i] < _min)_min = p[i];
   return _min;
}
int main(){
   int a[3];scanf("%d%d%d",&a[0],&a[1],&a[2]);
   int ans[3]={a[0]+a[1],a[1]+a[2],a[2]+a[0]};
   printf("%d",Amin(ans,3));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  ll a,b,c;
  cin>>a>>b>>c;
  ll x,y;
  cin>>x>>y;
  ll s = min(x,y);
  ll p = s*min(a+b,2*c);
  x-=s;
  y-=s;
  ll pm = x*min(a,2*c) + y*min(b,2*c);
  cout<<p+pm<<endl;


} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    char a[3], b[3];
    REP(i, 3) cin >> a[i];
    REP(i, 3) cin >> b[i];

    int res = 0;
    REP(i, 3) if(a[i] == b[i]) res++;
    cout << res << endl; 
}

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

signed main(){
    int x; cin>>x;
    int sum=0,i=0;
    while(sum<x){
        i++;
        sum+=i;
    }
    cout<<i<<endl;
}

Measured memory_bytes: 256