akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  ll h, w, x, y;
  cin >> w >> h >> x >> y;
  double d = (double)h*w / 2;
  cout.precision(9);
  cout << fixed << (double)h*w / 2;
  if (w % 2 == 0 && h % 2 == 0 && x == w / 2 && y == h / 2) ans = 1;
  cout << " " << ans << endl;



  

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char s[12];
  scanf("%s",s);
  for (int i=0;i<4;i++){
    printf("%c",s[i]);
  }
  printf(" ");
  for (int i=4;i<12;i++){
    printf("%c",s[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())
A = []
B = []
for line in range(n):
    A.append(list(map(int, input().split())))
for line in range(m):
    B.append(int(input()))
#print(A,B)

ret = []
for i in range(n):
    ret.append(sum(A[i][j] * B[j] for j in range(m)))
print('\n'.join(map(str, ret)))

Measured memory_bytes: 8024
n = int(input())
INF = 114514191981036436433-4
xy = []
for i in range(n):
    x,y = map(int,input().split())
    xy.append((x,y))
    
a = n
for i in range(n):
    for j in range(n):
        if i == j:
            continue
            
        p,q = xy[i][0] - xy[j][0] , xy[i][1] - xy[j][1]
        ans = n
        
        for k in range(n):
            for l in range(n):
                xx,yy = xy[k][0] - xy[l][0] , xy[k][1] - xy[l][1]
                if xx == p and yy == q:
                    ans -= 1
                    
        a = min(a,ans)
        
print(a)

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

int n;
int mp[2077],nxt[2077];
char s[200005];
int a[200005];
long long ans;

int main(){

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

    cin>>s+1;
    n=strlen(s+1);
    mp[0]=1;
    for(int i=1;i<=n;i++){
        a[i]=(a[i-1]*10+s[i]-'0')%2019;
        memset(nxt,0,sizeof(nxt));
        for(int i=0;i<2019;i++){
            nxt[i*10%2019]+=mp[i];
        }
        memcpy(mp,nxt,sizeof(mp));
        if(s[i]!='0')ans+=mp[a[i]];
        mp[a[i]]++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();
        
        if(a<k){
            k -= a;
            a = 0;
            b -= k;
        }
        else{
            a -= k;
        }
        
        System.out.println(a + " " + Math.max(b,0));
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#define ll long long
using namespace std;
int gcd(int n, int m){
    if(m==0){
        return n;
    }
    else{
        return gcd(m, n%m);
    }
}

int main(){
    int z;
    ll x, y;
    string a, b, c;
    cin >> x >> y;
    cin >> a >> b;
    bool same=true;
    z=gcd(x, y);
    for(int i=0; i<a.size(); i+=(x/z)){
        c+=a[i];
    }
    for(int i=0; i<b.size(); i+=(y/z)){
        if(b[i]!=c[i/(y/z)]){
            same=false;
        }
    }
    if(same){
        cout << x*y/z << endl;
    }
    else{
        z=-1;
        cout << z << endl;
    }
}

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

int main() {
  int N, A, B, Plan1;

  cin >> N >> A >> B;

  Plan1 = N * A;

  if (Plan1 <= B) {
    cout << Plan1 << endl;
  } else {
    cout << B << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

Measured memory_bytes: 9044
import math

N = int(input())
ans = 0
ms = set()
sqi = math.sqrt(N)
for i in range(1, int(sqi)+1):
    if N % i == 0:
        ms.add(i-1)
        ms.add(N//i-1)
for m in ms:
    if m <= 0:
        continue
    if N//m == N%m:
        ans += m
print(ans)

Measured memory_bytes: 3828
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a, b, c;
	a = n / 100;
	b = (n - a * 100) / 10;
	c = n - 100 * a - 10 * b;
	if (a == 1)
		a = 9;
	else if (a == 9)
		a = 1;
	if (b == 1)
		b = 9;
	else if (b == 9)
		b = 1;
	if (c == 1)
		c = 9;
	else if (c == 9)
		c = 1;
	cout << 100 * a + 10 * b + c << endl;
}

Measured memory_bytes: 256
package main
import (
	"fmt"
)
func main(){
	var n, k, q, i, temp int
	fmt.Scan(&n, &k, &q)
	b:=make([]int, n)
	for i=0;i<q;i++{
		fmt.Scan(&temp)
		b[temp-1]++
	}
	for i=0;i<n;i++{
		b[i]+=k-q
		if b[i]>0{
			fmt.Println("Yes")
		}else{
			fmt.Println("No")
		}
	}
}


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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)

using namespace std;

template <class String>
std::vector<size_t> knuth_morris_pratt(const String &text, const String &pattern) {

    const size_t N = text.size();
    const size_t M = pattern.size();

    if (M == 0) {
        std::vector<size_t> result(N + 1);
        for (size_t i = 0; i <= N; ++i) {
            result[i] = i;
        }
        return result;
    }

    int i, j;

    // lps[i] is the length of the longest proper prefix and suffix of pattern[:i + 1].
    std::vector<size_t> lps(M);
    lps[0] = 0;
    i = 1;
    j = 0;
    while (i < M) {
        if (pattern[i] == pattern[j]) {
            lps[i++] = ++j;
        } else if (j > 0) {
            j = lps[j - 1];
        } else {
            lps[i++] = 0;
        }
    }

    std::vector<size_t> result;
    i = 0;
    j = 0;
    while (i < N) {
        if (text[i] == pattern[j]) {
            ++i;
            if (j < M - 1) {
                ++j;
            } else {
                result.push_back(i - M);
                j = lps[M - 1];
            }
        } else if (j > 0) {
            j = lps[j - 1];
        } else {
            ++i;
        }
    }

    return result;
}

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

    int N;
    cin >> N;
    vector<int> a(N), b(N);
    REP(i, N) cin >> a[i];
    REP(i, N) cin >> b[i];

    if (N == 1) {
        cout << 0 << ' ' << (a[0] ^ b[0]) << endl;
        return 0;
    }

    vector<int> a_diff(2 * (N - 1)), b_diff(N - 1);
    REP(i, N - 1) {
        a_diff[i] = a[i + 1] ^ a[i];
        b_diff[i] = b[i + 1] ^ b[i];
    }
    a_diff[N - 1] = a[0] ^ a[N - 1];
    FOR(i, N, a_diff.size()) {
        a_diff[i] = a_diff[i - N];
    }

    vector<size_t> ks = knuth_morris_pratt(a_diff, b_diff);
    for (int k: ks) {
        int x = a[k] ^ b[0];
        cout << k << ' ' << x << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 9044
n = int(input())
h = list(map(int, input().split()))

def mizuyari(l):
    if l == 0 or l == []:
        return 0
    nin = min(l)
    for i in range(len(l)):
        l[i] -= nin
    index = l.index(0)
    return nin + mizuyari(l[:index]) + mizuyari(l[index+1:])


print(mizuyari(h))

Measured memory_bytes: 9108
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

/*

行列累乗 有向パス 数え上げ

----------------------------------------

a -> b と、b -> c をつなげると a -> c のパスになる

「aからbへの長さiのパスの総数」をx[i][a][b]とすると、x[i + j][a][c] = sum(b)(x[i][a][b] + x[j][b][c])

これを使って、K を、K/2 と K/2 に分けていけば、log K のオーダーでできるはず

----------------------------------------

上記を整理して、以下のようにすればよい

xs[l][i][j] は、i から j への長さ (1<<i) のパスの個数

xs[1] は与えられる a[i][j]に他ならない

xs[l][i][j] = sum(t)(xs[l - 1][i][t] * xs[l - 1][t][j])


これを表すために、
(long[][], long[][]) => long[][] の演算 a ** b を

(a ** b)[i][j] = sum(t)(a[i][t] * b[t][j]) 

で定義する

xs[1] = a
xs[l] = xs[l - 1] ** xs[l - 1]


そして求めるものは

ans = xs[l1] ** xs[l2] ** xs[l3] ** ... 
ただし、l1 などは (1<<l) & k > 0 であるような l

のすべての項の和

----------------------------------------

*/

const mod = 1_000_000_007;

void main(){
	int n = read.to!int;
	long k = read.to!long;
	
	long[][] as;
	foreach(i; 0 .. n){
		as ~= [[]];
		foreach(j; 0 .. n){
			as[i] ~= read.to!long;
		}
	}
	
	long[][][] xs = [as];
	for(int l = 1; (1L<<l) <= k; l ++) xs ~= prod(xs[l - 1], xs[l - 1]);
	debug writeln("xs: ", xs);
	
	long[][] p;
	foreach(l, q; xs){
		if((1L<<l) & k){
			if(p.length) p = prod(p, q);
			else p = q;
		}
	}
	
	long ans;
	foreach(i; 0 .. n) foreach(j; 0 .. n) ans += p[i][j], ans %= mod;
	ans.writeln;
}

long[][] prod(long[][] a, long[][] b){
	long[][] res;
	foreach(i; 0 .. a.length){
		res ~= [[]];
		foreach(j; 0 .. a.length){
			long x = 0;
			foreach(t; 0 .. a.length) x += a[i][t] * b[t][j], x %= mod;
			res[i] ~= x;
		}
	}
	return res;
}


Measured memory_bytes: 5500
#include<iostream>
#include<cstdio>
#include<list>
#include<string>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	int n,i,x;
	string s;
	list<int> intlist;
	cin >> n;
	
	
	for(i=0;i<=n-1;i++){
		cin >> s;
		if (s=="insert"){
			cin >> x;
			intlist.push_front(x);
		}else if(s=="delete"){
			cin >> x;
			list<int>::iterator it =intlist.begin();
			while (1){
				if (*it == x ){
					it=intlist.erase(it);
					break;
				}else if(it == intlist.end()){
					break;
				}
				it++;
			}
		}else if(s=="deleteFirst"){
			intlist.pop_front();
		}else if(s=="deleteLast"){
			intlist.pop_back();
		}
	}
	
	list<int>::iterator it =intlist.begin();
	cout << *it;
	it++;
	while(1){
		if (it == intlist.end()){
			cout << "\n";
			break;
		}
		cout << " " << *it;
		it++;
	}
	
	return 0;
}

Measured memory_bytes: 32476
W,H,N = (int(T) for T in input().split())
XYA = [[0],[W],[0],[H]]
for TN in range(0,N):
    X,Y,A = (int(T) for T in input().split())
    if A in [1,2]:
        XYA[A-1].append(X)
    else:
        XYA[A-1].append(Y)
CW = min(XYA[1])-max(XYA[0])
CH = min(XYA[3])-max(XYA[2])
if CW>=0 and CH>=0:
    print(CW*CH)
else:
    print(0)

Measured memory_bytes: 9124
import numpy as np

n,k=map(int,input().split())
A=np.array(input().split(),np.int64)
A.sort()

zero=A[A==0]
neg=A[A<0]
pos=A[A>0]

def f(x): # count pairs x or less
    cnt=0
    #zero
    if x>=0:
        cnt += len(zero)*n
    #pos
    cnt += A.searchsorted(x//pos,side="right").sum()
    #neg
    cnt += (n-A.searchsorted(-(-x//neg),side="left")).sum()
    #except a*a
    cnt-=np.count_nonzero(A*A<=x)
    return cnt//2

l=-10**18
r=10**18

while l<r:
    pov=(l+r)//2
    if f(pov)>=k:
        r=pov
    else:
        l=pov+1
print(l)


Measured memory_bytes: 50200
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] A = new int[N];
	  for(int i = 0; i < A.length; i++)
		  A[i] = Integer.parseInt(sc.next());
	  
	  int[] B = new int[N];
	  for(int i = 0; i < B.length; i++)
		  B[i] = Integer.parseInt(sc.next());
	  
	  int[] C = new int[N-1];
	  for(int i = 0; i < C.length; i++)
		  C[i] = Integer.parseInt(sc.next());
 	  
	  int temp = 0;
	  for(int i = 0; i < A.length; i++) {
		  temp += B[A[i] -1];
		  if(i > 0 && A[i] == A[i-1] +1) {
			  temp += C[A[i-1] -1];
		  }
	  }
	  
	  System.out.println(temp);
	  
	  sc.close();
	  
  }
}


Measured memory_bytes: 23380
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int x = 1;
    for (int i = 1 ; i <= m ; i++) x *= 2;
    cout << x * (1900 * m + 100 * (n - m));
}

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

char grid[1010][1010];
bool seen[1010][1010];
int di[]={0,1,0,-1};
int dj[]={1,0,-1,0};

int main(){
  int h,w;
  cin>>h>>w;
  queue<P> q;
  rep(i,h)rep(j,w){
    cin>>grid[i][j];
    seen[i][j]=0;
    if(grid[i][j]=='#'){
      seen[i][j]=1;
      q.push(make_pair(i,j));
    }
  }
  int ans=0;
  while(true){
    bool ok=1;
    rep(i,h)rep(j,w){
      if(!seen[i][j]){
        ok=0; break;
      }
    }
    if(ok) break;
    queue<P> r;
    ans++;
    while(!q.empty()){
      int pi,pj;
      tie(pi,pj)=q.front(); q.pop();
      rep(i,4){
        int ni=pi+di[i],nj=pj+dj[i];
        if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
        if(seen[ni][nj]) continue;
        seen[ni][nj]=1;
        r.push(make_pair(ni,nj));
      }
    }
    q=r;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 21904
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


int cnt[104];
vector<ii> added;
set<int> allowed;

const string IMPOSSIBLE = "Impossible";
const string POSSIBLE = "Possible";


int main(){

    ios_base::sync_with_stdio(0);

    int n, diameter = 0;
    cin>>n;
    while(n--){
        int a;
        cin>>a;
        diameter = max(diameter, a);
        cnt[a]++;
    }

    if(cnt[diameter] < 2){
        cout<<IMPOSSIBLE;
        return 0;
    }

    cnt[diameter] -= 2;
    for(int i=1;i<=diameter-1;i++){
        int temp = max(i, diameter-i);
        allowed.insert(temp);
        if(cnt[temp] == 0){
            cout<<IMPOSSIBLE;
            return 0;
        }
        cnt[temp]--;
    }

    if(cnt[1] != 0){
        cout<<IMPOSSIBLE;
        return 0;
    }

    for(int i=2;i<=diameter;i++){
        while(cnt[i]--){
            bool found = false;
            for(auto x : allowed){
                if(i > x){
                    added.pb({i-x, x});
                    found = true;
                    break;
                }
            }
            if(!found){
                cout<<IMPOSSIBLE;
                return 0;
            }
        }
    }

    for(int i=0;i<(int)added.size();i++)
        for(int j=i;j<(int)added.size();j++)
            if(added[i].ff + abs(added[i].ss-added[j].ss) + added[j].ff > diameter){
                cout<<IMPOSSIBLE;
                return 0;
            }

    cout<<POSSIBLE;
    return 0;
}






Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
	int a[3],b,c,ans;
	while(scanf("%d%d%d",&a[0],&a[1],&a[2])!=EOF)
	{
		sort(a,a+3);
		b=a[2]-a[0];
		c=a[2]-a[1];
		if(b%2==c%2)
		{
			if(b%2==0)
			ans=b/2+c/2;
			else
			ans=(b+c)/2;
		}
		else
		{
			ans=(b+c)/2+2;
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
  int n,su=0; cin>>n;
  int ar[n];
  for(int i=0;i<n;i++) cin>>ar[i];
  for(int i=0;i<n;i++)
    for(int j=i;j<n;j++)
      if(i!=j)
        su+=ar[i]*ar[j];
  cout<<su;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
辞書
"""

d = {}
N = int(input())
for i in range(N):
    com, s = input().split()
    if com == 'insert':
        d[s] = True
    elif com == 'find':
        if d.get(s):
            print('yes')
        else:
            print('no')



Measured memory_bytes: 33120
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;
const int NIL = -1;
const int MAX = 100000;
vector<vector<int>> G(MAX);
vector<int> color(MAX,NIL);
int n;

// start:r , color:c
void dfs(int r, int c){
    stack<int> S;
    S.push(r);
    color[r]=c;
    while(!S.empty()){
        int u = S.top();S.pop();
        rep(i,G[u].size()){
            int v = G[u][i];
            if(color[v]==NIL){
                color[v]=c;
                S.push(v);
            }
        }
    }
}

void assign_color(){
    int id = 1;
    rep(i,n){
        if(color[i]==NIL){
            dfs(i,id++);
        }
    }
}


int main(){
    int m;
    cin >> n >> m;
    rep(i,m){
        int v,u;
        cin >> v >> u;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int q;
    cin >> q;
    assign_color();
    rep(i,q){
        int u,v;
        cin >> u>>v;
        if(color[u]==color[v])cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;

}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    vector<P> p(N);
    rep(i, N) {
        p[i].first = a[i];
        p[i].second = i;
    }

    sort(p.begin(), p.end());
    vector<int> minus_idx;
    vector<int> plus_idx;
    rep(i, p.size()) {
        int val = p[i].first;
        int idx = p[i].second;
        if (i == 0) {
            minus_idx.push_back(idx);
        } else if (i == N - 1) {
            plus_idx.push_back(idx);
        } else if (val >= 0) {
            plus_idx.push_back(idx);
        } else {
            minus_idx.push_back(idx);
        }
    }

    ll s = 0;
    rep(i, minus_idx.size()) s -= a[minus_idx[i]];
    rep(i, plus_idx.size()) s += a[plus_idx[i]];

    vector<P> op;
    int tmp = a[minus_idx[0]];
    for (int i = 1; i < plus_idx.size(); i++) {
        op.push_back(P{tmp, a[plus_idx[i]]});
        tmp -= a[plus_idx[i]];
    }
    int tmp2 = a[plus_idx[0]];
    for (int i = 1; i < minus_idx.size(); i++) {
        op.push_back(P{tmp2, a[minus_idx[i]]});
        tmp2 -= a[minus_idx[i]];
    }
    op.push_back(P{tmp2, tmp});

    cout << s << endl;
    rep(i, op.size()) cout << op[i].first << " " << op[i].second << endl;
}


Measured memory_bytes: 4596
import java.util.*;

class Main {

  static int LENGTH = 100000;
  static int [] queue = new int[LENGTH];
  static String [] name = new String[LENGTH];
  static int tail = 0;
  static int head = 0;
  public static void main(String args[]){
    //宣言
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = sc.nextInt();
    int out;
    int count=0;
    //input
    for(int i = 0; i<n; i++){
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    }
    //loop
    while(isEmpty() != true){
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    }
  }
  //enqueue
  static void enqueue(int num){
    queue[tail] = num;
    if(head != 0){
    name[tail] = name[head-1];//
  }else{
    name[tail] = name[LENGTH-1];
  }
    if(tail == LENGTH-1){
      tail=0;
    }else{
      tail++;
    }
  }
  //dequeue
  static int dequeue(){
    if(head == LENGTH-1){
      head = 0;
      return queue[LENGTH-1];
    }
    return queue[head++];
  }
  //キューの中身がなくなったかどうかの判定
  static boolean isEmpty(){
    return head == tail;
  }

}


Measured memory_bytes: 78620
#include <bits/stdc++.h>
#define LL long long 
using namespace std;
int N, M, A, B;
int main()
{
	scanf("%d%d%d%d", &N, &M, &A, &B);
	if (!(N % A) && !(M % B))
		puts("No");
	else 
	{
		puts("Yes");
		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < M; ++j)
			{
				if (i % A || j % B)
					printf("%d ", -1000);
				else printf("%d ", 1000 * (A * B - 1) - 1);
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


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

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n;
  while(cin >> n, n){
    vector<int> a(n);
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> a[i], sum += a[i];
    }
    double ave = (double)sum / n;
    int cnt = 0;
    for(int i = 0; i < n; i++){
      cnt += (a[i] <= ave);
    }
    cout << cnt << endl;
  }
  return 0;
}


Measured memory_bytes: 3000
#include <stdio.h>

int main() {
  long long a, b, x;
  scanf("%lld%lld%lld", &a, &b, &x);
  if (a > 0) {
    printf("%lld\n", b / x - (a - 1) / x);
  } else {
    printf("%lld\n", b / x + 1);
  }
  return 0;
}


Measured memory_bytes: 128
#include "iostream"
#include "math.h"
#include <algorithm>
using namespace std;

#define SUQARE_SIZE  100000

int block[SUQARE_SIZE];          // decomposed array
int blockSize;

// Time Complexity : O(1)
void updateTable(int arr[],int index,int val)
{
    // 更新
    arr[index] = val;
    // block内の最小値を更新する
    int blockNumber = index / blockSize;
    int startIndex = blockNumber * blockSize;
    int minValue = arr[startIndex];
    // blockを最小のものに更新し直す
    for (int i = startIndex + 1;i < startIndex + blockSize;++i) {
        minValue = min(minValue,arr[i]);
    }
    block[blockNumber] = minValue;
}

// Time Complexity : O(sqrt(n))
int query(int arr[],int l, int r)
{
    int minValue = __INT32_MAX__;
    // 左端
    while (l < r && l % blockSize != 0 && l != 0)
    {
        // traversing first block in range
        minValue = min(minValue,arr[l]);
        l++;
    }
    // blockに当てはまる部分
    while ((l + blockSize) <= r)
    {
        // traversing completely overlapped blocks in range
        minValue = min(minValue,block[l / blockSize]);
        l += blockSize;
    }
    // 右端
    while (l <= r)
    {
        // traversing last block in range
        minValue = min(minValue,arr[l]);
        l++;
    }
    return minValue;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q,x,y,c;
    cin >> n >> q;
    int nums[n];
    for(int i = 0;i < n;++i){
        nums[i] = __INT_MAX__;
        block[i] = __INT_MAX__;
    }
    // block size
    blockSize = sqrt(n);
    
    for(int i = 0;i < q;++i){
        cin >> c >> x >> y;
        switch(c){
                // update
            case 0:
                updateTable(nums,x,y);
                break;
                // find
            case 1:
                cout << query(nums,x,y) << endl;
                break;
        }
    }
}



Measured memory_bytes: 3936
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  int N;
  cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  std::vector<int> dp(N*2,1e9);
  dp[0]=0;
  for(int i=0;i<N;i++){
    dp[i+1]=min(dp[i+1],dp[i]+abs(v[i+1]-v[i]));
    dp[i+2]=min(dp[i+2],dp[i]+abs(v[i+2]-v[i]));
  }
  cout<<dp[N-1]<<endl;
}


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

int main() {
	int n, x;
	cin >> n >> x;
	int a[110];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		x -= a[i];
		if (x < 0) {
			cout << i << endl;
			return 0;
		}
		else if (x == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	if (x > 0) {
		cout << n - 1 << endl;
		return 0;
	}
}

Measured memory_bytes: 256
import itertools
N, M, Q = map(int,input().split())
L = []
for _ in range(Q):
    L.append(list(map(int,input().split())))

A = itertools.combinations_with_replacement([i for i in range(1,M+1)], N)
count = []
for a in A:
    temp = 0
    for l in L:
        if a[l[1]-1] - a[l[0]-1] == l[2]:
            temp += l[3]
    count.append(temp)
print(max(count))

Measured memory_bytes: 12524
#include <stdio.h>

int main() 
{
    int n;
    scanf("%d",&n);
    int f=0;
    for(int i=1;i<=n;i++)
    {
        int count=0,j=i;
        while(j!=0)
        {
            j=j/10;
            count++;
        }
        if(count%2!=0)
        {
            f++;
        }
    }
    printf("%d",f);
    return 0;
}

Measured memory_bytes: 128
import Data.Functor ((<$>))

main :: IO ()
main = do
  [h, w] <- map (read :: String -> Int) . words <$> getLine
  if h == 0 && w == 0
    then return ()
    else do
      putStrLn . unlines $ do
        i <- [1..h]
        return $ do
          j <- [1..w]
          if i >= 2 && i <= h-1 && j >= 2 && j <= w-1
            then return '.'
            else return '#'
      main



Measured memory_bytes: 3980
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(){
  int n,datacase = 1;
	while(true){
		cin>>n;
		if(!n)break;
		double area = 0,sx,sy,x1,y1,x2,y2;
		cin>>x1>>y1;
		sx = x1,sy = y1;
		for(int i=0;i<n-1;i++){
			cin>>x2>>y2;
			area+=(y2+y1)*(x2-x1)/2;
			x1 = x2;
			y1 = y2;
		}
		x2 = sx;
		y2 = sy;
		area+=(y2+y1)*(x2-x1)/2;
		printf("%d %.1f\n",datacase,abs(area));
		datacase++;
	}
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 2050;
 ll mod = 1e9+7;

double solve(vector<double> &vec){
    double sol = 0;
    for(auto v:vec){
        sol+=(1/v);
    }
    return sol;
}

int main(){
    int n;
    cin >> n;
    vector<double> vec(n);
    rep(i,n) cin >> vec[i];
    double ans = solve(vec);
    printf("%.12lf\n",(double)1/ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(3 * N);
    rep(0, i, 3 * N)
    {
        cin >> a.at(i);
    }
    sort(all(a));
    reverse(all(a));
    ll ans = 0;
    rep(0, i, N)
    {
        ans += a.at(2 * i + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <sstream>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;

int stoi(char c){
  int ret = c - 48;
  return ret;
}

int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  string s;
  cin >> s;
  int sum = 0;
  int n = s.length();
  rep(i, n){
    sum += stoi(s[i]);	
  }
  if(sum % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using namespace std;

int dp1[100005];
int least[100005];
int n,k;

int dp(int m){
    if (m <= k)return abs(least[m] - least[0]);
    if (dp1[m] > -1) return dp1[m];
    int minn = 2e9;
        for (int i = 1 ; i <= k ; i++){
            minn = min(minn,abs(least[m]-least[m-i])+dp(m-i));
        }
    return dp1[m] = minn;
}


int main()
{

    cin >> n >> k;
    for (int i = 0 ; i < n ; i++){
            scanf("%d", &least[i]);
            dp1[i] = -1;
    }

    cout<<dp(n-1)<<endl;


    return 0;
}


Measured memory_bytes: 5760
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n;
int a[100011], f[22];
vector<int> v;
int dp[(1 << 16) + 123];
int ans = 0;
int xr[(1 << 16) + 123], sum[(1 << 16) + 123];
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n;
	for(int i = 1; i < n; i ++){
		int x, y, c;
		cin >> x >> y >> c;
		x ++;
		y ++;
		a[x] ^= c;
		a[y] ^= c;
	}
	for(int i = 1; i <= n; i ++){
		f[a[i]] ++;
	}
	for(int i = 1; i <= 15; i ++){
		ans += f[i] / 2;
		if(f[i] % 2){
			v.pb(i);
		}
	}
	int sz = v.sz();   /*
	for(int i = 0; i < v.sz(); i ++){
		cout << v[i] << " ";
	}
	cout << endl;    */
	for(int mask = 1; mask < (1 << sz); mask ++){
		for(int i = 0; i < sz; i ++){
			if(((1 << i) & mask) == 0)
				continue;
			xr[mask] = xr[mask] ^ v[i];
			sum[mask] ++;
		}
	//	cout << mask << " " << xr[mask] << " " << sum[mask] << endl;
		sum[mask] --;
	}                                                
	dp[0] = 0;
	for(int mask = 1; mask < (1 << sz); mask ++){
		dp[mask] = inf;
		for(int s = mask; s > 0; s = ((s - 1) & mask)){
			if(xr[s] > 0)
				continue;
			dp[mask] = min(dp[mask], dp[mask ^ s] + sum[s]);
		}
	}
	cout << dp[(1 << sz) - 1] + ans; 
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int t[100010],x[100010],y[100010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    }
    bool flag=true;
    for(int i =0;i<n;i++)
    {
        if(t[i]<x[i]+y[i])
        {
            flag=false;
            break;
        }
        if((t[i]-x[i]-y[i])%2)
        {
            flag=false;
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int pos = -1;
    for(int i = 1; i < n; ++i){
        if(a[i-1] + a[i] >=l){
            pos = i;
            break;
        }
    }
    if(pos == -1){
        cout << "Impossible\n";
        return 0;
    }
    vector<int> res;
    for(int i = 1; i < pos; ++i){
        res.push_back(i);
    }
    for(int i = n-1; i > pos; --i){
        res.push_back(i);
    }
    res.push_back(pos);
    cout << "Possible\n";
    for(int i = 0; i < res.size(); ++i){
        cout << res[i] << "\n";
    }
}

Measured memory_bytes: 4256
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d%d",&A,&B);
    if(A>=13)
    { C=B;
      printf("%d",B);
    }
    else if(A>=6 && A<=12 )
    {   C=(int)(0.5*B);
        printf("%d",C);
    }
    else
        printf("0");
    return 0;


}


Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<stack>
using namespace std;


int main() {
	int X, Y;
	scanf("%X", &X);
	scanf("%X", &Y);

	if (X > Y) {
		printf(">");
	}
	else if (X == Y) {
		printf("=");
	}
	else {
		printf("<");
	}
}


Measured memory_bytes: 256
def examC():
    N, M = LI()
    cur = int(0)
    remain = M - N*2
    if remain>=0:
        cur += N
        cur += remain//4
    else:
        cur += M//2
    print(cur)

import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

using namespace std;

int exist[100000];

int main(){
	
	while(true){
		
		int m;
		cin >> m;
		if(m == 0){
			break;
		}
		
		for(int i = 0; i < 10000; i++){
			exist[i] = 0;
		}
		
		exist[0] = 1;
		
		int a, b;
		
		for(int loop = 0; loop < m; loop++){
			cin >> a >> b;
			for(int i = 9999; i >= 0; i--){
				if(exist[i] > 0){
					for(int j = 1; j <= b; j++){
						exist[i + a * j] += exist[i];
					}
				}
			}
		}
		
		int g;
		
		cin >> g;
		
		for(int loop = 0; loop < g; loop++){
			int n;
			cin >> n;
			cout << exist[n] << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3112
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto S = 'a' ~ readln.chomp ~ 'a';
    auto N = readln.chomp.to!int;
    auto A = iota(N).map!(_ => readln.split.map!(to!int).array).array;

    auto M = S.length.to!int;
    auto B = (M-1).iota.map!(i => ((S[i].to!int - S[i+1].to!int) % 26 + 26) % 26).array;

    auto uf = new UnionFind(M-1);

    foreach (i; 0..(M-1)/2) {
        uf.unite(i, M-i-2);
    }

    foreach (a; A) {
        uf.unite(a[0]-1, a[1]);
    }

    foreach (i; 0..M-1) if (uf.table[i] < 0) {
        if (uf.group[i].map!(j => B[j]).sum % 26 != 0) {
            writeln("NO");
            return;
        }
    }

    writeln("YES");
}


class UnionFind {
    int N;
    int[] table;
    int[][] group;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        group = N.iota.map!(i => [i]).array;
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        group[x] ~= group[y];
        group[y] = [];
        table[x] += table[y];
        table[y] = x;
    }
}



Measured memory_bytes: 16664
n=int(input())
end=int(n**0.5)+1
cnt=0
l=[0 for i in range(6*end*end)]
for i in range(1,end):
  for j in range(1,end):
    for k in range(1,end):
      now=i*i+j*j+k*k+i*j+i*k+j*k
      l[now-1]+=1
for i in range(n):
  print(l[i])


Measured memory_bytes: 9776
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){r(1)(r(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,t,r){"use strict";e.exports=function(e){for(var t=Number(e[0]),r=0,n=1;n<=t;n++)n%2==1&&r++;console.log(r/t)}},function(e,t){e.exports=require("fs")}]);

Measured memory_bytes: 21956
import math

def main():
    N,D = (int(x) for x in input().split())
    # N,D = map(int, input().split())
    cnt = 0
    for i in range(N):
        x,y = (int(x) for x in input().split())
        dis = math.sqrt(x**2 + y**2)
        if dis <= D:
            cnt +=1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define aio()                         \
    do {                              \
        std::ios::sync_with_stdio(0); \
        std::cin.tie(0);              \
    } while (0)
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
    aio();

    int n, x, t;
    cin >> n >> x >> t;
    cout << (int)(ceil((double)n / x)) * t;
}


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

int main()
{
  int h, n; cin>>h>>n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i, n) {
    cin >> a[i] >> b[i];
  }

  vector<int> dp(h+1, 1001001001);
  dp[0] = 0;
  for (int i=0; i<n; i++) {
    for (int j=0; j<h+1; j++) {
      if (j < a[i]) dp[j] = min(dp[j], b[i]);
      else dp[j] = min(dp[j], dp[j-a[i]] + b[i]);
    }
  }
  cout << dp[h] << endl;

  return 0;
}


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

public class Main 
{
	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) 
	{
		int n = scan.nextInt();
		
		for(int i = 0; i < n; i++)
		{
			new DataSet();
		}
	}
	
	static class DataSet
	{
		String original = "";
		String train1;
		String train2;
		List<String> traindex = new ArrayList<String>();
		
		
		public DataSet()
		{
			original = scan.next();
			
			for(int i = 1; i < original.length(); i++)
			{
				train1 = original.substring(0, i);
				train2 = original.substring(i);
				
				String rev1 = reverseStr(train1);
				String rev2 = reverseStr(train2);
//				System.out.println("Trains [" + train1 + "] and [" + train2 + "]");
				
				checkTrain(train1 + train2);
				checkTrain(rev1 + train2);
				checkTrain(train1 + rev2);
				checkTrain(rev1 + rev2);
				
				checkTrain(train2 + train1);
				checkTrain(rev2 + train1);
				checkTrain(train2 + rev1);
				checkTrain(rev2 + rev1);
			}
			
			System.out.println(traindex.size());
			//12.345
			//12.34
		}
		
		public String reverseStr(String str)
		{
			String ret = "";
			
			for(int i = str.length()-1; i >= 0; i--)
			{
				ret += str.substring(i, i+1);
			}
			
//			System.out.println("Reversing " + str + " into " + ret);
			return ret;
		}
		
		void checkTrain(String train)
		{
//			System.out.println("Checking " + train);
			if(!traindex.contains(train))
			{
//				System.out.println(">>> Added " + train);
				traindex.add(train);
			}
		}
	}

}



Measured memory_bytes: 96180
import java.util.Scanner;
import java.util.InputMismatchException;


public class Main {

    public static void main(String[] args) {

    try {
      Scanner scanner = new Scanner(System.in);
 
      int x = scanner.nextInt();
      int y = scanner.nextInt();
      int h = scanner.nextInt();
 
      System.out.println( (x + y) * h / 2 );
      scanner.close();
    } catch (InputMismatchException e) { 
      System.out.println("整数を入力してください。");
    }
  }
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> p(n), a(n, 0);
    rep(i, n) cin >> p[i];
    double ans = 0.0;
    int idx = 0;

    rep(i, k) a[0] += p[i];

    for(int i=1; i<=n-k; i++) { 
        a[i] = a[i-1] - p[i-1] + p[i+k-1];
        if (a[idx] < a[i]) idx = i;
    }

    rep(i, k) {
        ans += 1.0 + double(p[idx+i]-1)*0.5;
    }
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
import collections
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))
dcounter = collections.Counter(d)
tcounter = collections.Counter(t)
check = True
for i in tcounter.items():
	if dcounter[i[0]] < i[1]:
		check = False
if check:
	print('YES')
else:
	print('NO')

Measured memory_bytes: 57056
#include <iostream>
using namespace std;
int main(void){
int R,G,B,N,count;
count = 0;

cin >> R >> G >> B >> N;

for (int r=0;r*R<=N;r=r+1) {
    for (int g=0;r*R+g*G<=N;g=g+1) {

            if (((N-(r*R+g*G))%B)==0 && ((N-(r*R+g*G))%B)>=0) {
            count= count+1;
            }
            
        
        
    }
   
    
}

cout << count << endl;
   
   
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var V = ReadArrayInt();
            var odd = new Dictionary<int, int>();
            var even = new Dictionary<int, int>();
            for (int i = 0; i < N; i++)
            {
                if (i % 2 == 0)
                {
                    if (odd.ContainsKey(V[i])) odd[V[i]]++;
                    else odd.Add(V[i], 1);
                }
                else
                {
                    if (even.ContainsKey(V[i])) even[V[i]]++;
                    else even.Add(V[i], 1);
                }
            }
            var sortedO = odd.OrderByDescending(i => i.Value).ThenBy(i => i.Key).ToArray();
            var sortedE = even.OrderByDescending(i => i.Value).ThenBy(i => i.Key).ToArray();
            var ans = 0;

            if (sortedO.Length == 1 && sortedE.Length == 1)
            {
                if (sortedO[0].Key == sortedE[0].Key) ans = N / 2;
                else ans = 0;
            }
            else if (sortedO.Length == 1)
            {
                int patA = 0, patB = 0;
                patA = ConvNum(sortedO[0], sortedE[0], N);
                patB = ConvNum(sortedO[0], sortedE[1], N);
                ans = Math.Min(patA, patB);
            }
            else if (sortedE.Length == 1)
            {
                int patA = 0, patB = 0;
                patA = ConvNum(sortedO[0], sortedE[0], N);
                patB = ConvNum(sortedO[1], sortedE[0], N);
                ans = Math.Min(patA, patB);
            }
            else
            {
                int patA = 0, patB = 0, patC = 0;
                patA = ConvNum(sortedO[0], sortedE[0], N);
                patB = ConvNum(sortedO[0], sortedE[1], N);
                patC = ConvNum(sortedO[1], sortedE[0], N);
                ans = Math.Min(patA, Math.Min(patB, patC));
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static int ConvNum(KeyValuePair<int, int> A, KeyValuePair<int, int> B, int N)
        {
            var ret = 0;
            var n = N / 2;
            if (A.Key == B.Key) {
                if (A.Value >= B.Value) ret += 2 * n - A.Value;
                else ret += 2 * n - B.Value;
            } 
            else
            {
                ret += 2 * n - A.Value - B.Value;
            }

            return ret;
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

const int MAXN = 205;
int q;
int n, m;	
int t[27];
char ch[MAXN];

void init() {
	for(int i = 0; i <= 26; ++ i)
		t[i] = 0;
}

void work1() {
	bool flag = false;
	for(int i = 0; i <= 26; ++ i) 
		if((t[i] & 1) || ((t[i] >> 1) & 1)) {
			flag = true;
			break;
		}
	printf("%s\n", flag ? "No" : "Yes");
}

void work2() {
	int cnt = 0, tot = 0;
	for(int i = 0; i <=26; ++ i) {
		if(t[i] & 1) 
			cnt ++ ;
		if((t[i] >> 1) & 1)
			tot ++ ;
	}
	int Max = (n & 1) ? (m >> 1) : (n >> 1);
	printf("%s\n", (cnt || tot > Max) ? "No" : "Yes"); 
}

void work3() {
	int cnt = 0, tot = 0;
	for(int i = 0; i <=26; ++ i) {
		if(t[i] & 1) 
			cnt ++ ;
		if((t[i] >> 1) & 1)
			tot ++ ;
	}
	int Max = ((n - 1) >> 1) + ((m - 1) >> 1);
	printf("%s\n", (cnt > 1 || tot > Max) ? "No" : "Yes");
}

int main() {
//	freopen("quilt.in", "r", stdin);
//	freopen("quilt.out", "w", stdout);
	init();
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++ i) {
		scanf("%s", ch + 1);
		for(int j = 1; j <= m; ++ j)
			t[ch[j] - 'a'] ++ ;
	}
	if( ! (n & 1) && ! (m & 1)) { // both ou
		work1();
	} else if((n & 1) && ! (m & 1) || ! (n & 1) && (m & 1)) { // one ou one ji 
		work2();
	} else { // both ji
		work3();
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int main() {
    int n;
    cin>>n;
    rep(i,0,n){
    double x,y,r,xx,yy,rr;
    cin>>x>>y>>r>>xx>>yy>>rr;
    double diff=sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y));
     if(diff>r+rr)cout<<0<<endl;
     else if(diff<rr-r)cout<<-2<<endl;
     else if(diff<r-rr)cout<<2<<endl;
     else cout<<1<<endl;
    
    }
    
  
    return 0;
}



Measured memory_bytes: 3068