akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define debug(x) cout << #x <<" = " << x << endl
void solve()
{
ll int n;
cin>>n;
set<ll int> s;
set<ll> s1;
for (ll int i = 0; i < n; i++)
{
    ll int a,b;
    cin>>a>>b;
    s.insert((a+b));
    s1.insert((a-b));
}
auto it=s.end();
it--;
ll ans=*it-*s.begin();
ans=abs(ans);
it=s1.end();
it--;
ans=max(ans,abs(*it-*s1.begin()));
cout<<ans<<endl;
}
int main()
{
FASTIO
 long long int t=1;
 //cin>>t;
 while(t--)
  solve();
  return 0;
}


Measured memory_bytes: 22360
from collections import deque
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
e = [[] for _ in range(N)]
for a, b in AB:
    e[a-1].append(b-1)
    e[b-1].append(a-1)

ans = [-1 for _ in range(N)]
def bfs(root):
    if root is None:
        return 
    q = deque()
    q.append(e[root])
    q.append(root)
    while q:
        r = q.popleft()
        i = q.popleft()
        for n in r:
            if ans[n] == -1:
                ans[n] = i + 1
                q.append(e[n])
                q.append(n)
bfs(0)
is_exit = True
for i in ans:
    if i == -1:
        is_exit = False
        break
if is_exit:
    print("Yes")
    for i in ans[1:]:
        print(i)
else:
    print("No")

Measured memory_bytes: 73772
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#define ld long double
#define MAX_REPS 40000
using namespace std;

int n, wh;
ld x[1005], y[1005];
ld v1, v2;
ld d, e;
ld p = 0.1;

ld d2(ld a, ld b) {
	return a*a + b*b;
}

int main() {
	cin>>n;
	for (int i = 1; i <= n; i++){
		cin>>x[i]>>y[i];
		v1 += x[i];
        v2 += y[i];
	}
	v1 /= n;
	v2 /= n;
	for (int i = 1; i <= MAX_REPS; i++) {
		wh = 1;
		d = d2(v1 - x[wh], v2 - y[wh]);
		for (int j = 2; j <= n; j++) {
			e = d2(v1 - x[j], v2 - y[j]);
			if (d < e)
				d = e, wh = j;
		}
		v1 += (x[wh] - v1)*p;
		v2 += (y[wh] - v2)*p;
		p *= 0.999;
	}
	cout<<setprecision(15)<<fixed<<sqrt(d)<<'\n';
	return 0;
}


Measured memory_bytes: 384
from collections import deque
H, W = map(int, input().split())
sH, sW = map(int, input().split())
sH, sW = sH - 1, sW - 1
gH, gW = map(int, input().split())
gH, gW = gH - 1, gW - 1
stage = []
scores = []
for _ in range(H):
    stage.append(list(input()))
    scores.append([float('inf')] * W)
scores[sH][sW] = 0
moveA_q = deque()
moveB_q = deque()
moveA_q.append([sW, sH])
moveB_q.append([sW, sH])
dx_list = [0, 1, 0, -1]
dy_list = [1, 0, -1, 0]
while moveA_q:
    if scores[gH][gW] != float('inf'):
        break
    # 移動AでBFS
    x, y = moveA_q.pop()
    moveB_q.append([x, y])
    for dx, dy in zip(dx_list, dy_list):
        nx, ny = x + dx, y + dy
        if nx < 0 or W <= nx or ny < 0 or H <= ny or stage[ny][nx] == '#':
            continue
        if scores[ny][nx] == float('inf'):
        # if scores[ny][nx] > scores[y][x]:
            scores[ny][nx] = scores[y][x]
            moveA_q.append([nx, ny])

    if not moveA_q:
        # 移動bで動けるマスをmodeA_qに格納
        while moveB_q:
            x, y = moveB_q.pop()
            for dx in range(-2, 3):
                for dy in range(-2, 3):
                    nx, ny = x + dx, y + dy
                    if nx < 0 or W <= nx or ny < 0 or H <= ny or stage[ny][nx] == '#':
                        continue
                    if scores[ny][nx] == float('inf'):
                    # if scores[ny][nx] > scores[y][x]:
                        moveA_q.append([nx, ny])
                        scores[ny][nx] = scores[y][x] + 1

# print(*scores,sep='\n')
if scores[gH][gW] == float('inf'):
    print(-1)
else:
    print(scores[gH][gW])




Measured memory_bytes: 155296
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] b = arrayInt(sc, n - 1);
		sc.close();
		int[] a = new int[n];
		int sum = 0;
		a[0] = b[0];
		for (int i = 0; i < n - 1; i++) {
			if (a[i] > b[i]) {
				a[i] = b[i];
			}
			a[i + 1] = b[i];
			sum += a[i];
		}
		sum += a[n - 1];
		System.out.println(sum);
	}

	public static long modFactorial(long n, long mod) {
		long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans *= i;
			ans %= mod;
		}
		return ans;
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}

class Combination {
	static final int MOD = 1000000007;
	long[] fac;
	long[] finv;
	long[] inv;

	public Combination(int size) {
		fac = new long[size];
		finv = new long[size];
		inv = new long[size];
		fac[0] = 1;
		fac[1] = 1;
		finv[0] = 1;
		finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < size; i++) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	public long getComb(int n, int k) {
		if (n < k || n < 0 || k < 0) {
			return 0;
		}
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
}

Measured memory_bytes: 23636
class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときはinf)

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行けそう
        # d[i][i] < 0 なら、グラフは負のサイクルを持つ
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        hasNegativeCycle = False
        for i in range(self.N):
            if self.d[i][i] < 0:
                hasNegativeCycle = True
                break
        for i in range(self.N):
            self.d[i][i] = 0
        return hasNegativeCycle, self.d


V, E = map(int, input().split())
graph = WarshallFloyd(V)
for i in range(E):
    s, t, d = map(int, input().split())
    graph.add(s, t, d, True)

hasNegativecycle, dist = graph.WarshallFloyd_search()

if hasNegativecycle:
    print("NEGATIVE CYCLE")
    quit()
for row in range(V):
    if dist[row][0] == float('inf'):
        print("INF", end="")
    else:
        print("%d" % (dist[row][0]), end="")
    for col in range(1, V):
        if dist[row][col] == float('inf'):
            print(" INF", end="")
        else:
            print(" %d" % (dist[row][col]), end="")
    print()



Measured memory_bytes: 6544
s = input()
s = s[:-1]
while True:
    if len(s) == 0:
        print(0)
        exit()
    if len(s)%2 == 0:
        half = len(s)//2
        if s[:half] == s[half:]:
            print(len(s))
            exit()
        else:
            s = s[:-2]
    else:
        s = s[:-1]

Measured memory_bytes: 38256
class unionFind():
  def __init__(self,n):
    self.size = n
    self.parents = [-1]*n
  def find(self, x):
     if self.parents[x] < 0:
       return x
     else:
       self.parents[x] = self.find(self.parents[x])
       return self.parents[x]
      
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def grpsize(self, x):
    return -self.parents[self.find(x)]
  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]
  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.size) if self.find(i) == root]
  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
import sys
sys.setrecursionlimit(4100000)

line = input().split()
nPerson = int(line[0])
nFriend = int(line[1])
nBlock  = int(line[2])

friends = [[] for i in range(nFriend)]
for i in range(nFriend):
  line = input().split()
  friends[i] =[int(line[0])-1, int(line[1])-1]

nconnected = [0]*nPerson
for i in friends:
    nconnected[i[0]] += 1
    nconnected[i[1]] += 1
  
  
blocks = [[] for i in range(nBlock)]
for i in range(nBlock):
  line = input().split()
  blocks[i] = [int(line[0])-1, int(line[1])-1]

uf = unionFind(nPerson)
for i in friends:
  uf.union(i[0],i[1])

nblocked = [0]*nPerson
for i in blocks:
  if uf.find(i[0]) == uf.find(i[1]):
    nblocked[i[0]] += 1
    nblocked[i[1]] += 1
  
res = ""
for i in range(nPerson):
  res += str(uf.grpsize(i)-nconnected[i] -nblocked[i]-1) + " "

print(res)


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

int main(){
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  string str = "";
  for(int i=0; i<gy-sy; i++) str += "U";
  for(int i=0; i<gx-sx; i++) str += "R";
  for(int i=0; i<gy-sy; i++) str += "D";
  for(int i=0; i<gx-sx+1; i++) str += "L";
  for(int i=0; i<gy-sy+1; i++) str += "U";
  for(int i=0; i<gx-sx+1; i++) str += "R";
  str += "D";
  str += "R";
  for(int i=0; i<gy-sy+1; i++) str += "D";
  for(int i=0; i<gx-sx+1; i++) str += "L";
  str += "U";
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 256
class UnionFind
  def initialize(n)
    @size = Array.new(n + 1, 1)
    @parent = []

    n.times do |i|
      @parent[i] = i
    end
  end

  def find(x)
    if @parent[x] == x
      x
    else
      @parent[x] = find(@parent[x])
    end
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return if x == y

    @parent[y] = x
    @size[x] += @size[y]
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def size(x)
    @size[find(x)]
  end
end

def kruskal(v, edges)
  edges.sort_by! { |from, to, cost| cost }
  uf = UnionFind.new(v)

  total_cost = 0

  edges.each do |from, to, cost|
    unless uf.same?(from, to)
      uf.unite(from, to)
      total_cost += cost
    end
  end

  total_cost
end

V, E = gets.split.map(&:to_i)
edges = E.times.map { gets.split.map(&:to_i) }

puts kruskal(V, edges)



Measured memory_bytes: 16396
n=int(input())
t=[0]
x=[0]
y=[0]
for i in range(n):
    ti,xi,yi=map(int,input().split())
    t.append(ti)
    x.append(xi)
    y.append(yi)

can = True
for i in range(n):
    dt=t[i+1]-t[i]
    dist=(x[i+1]-x[i])+(y[i+1]-y[i])
    if(dt<dist):
        can=False
    if(dist%2 != dt%2):
        can=False
if(can):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11732
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 100001
#define PLUS 0
#define MINUS 1

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int X, Y; cin >> X >> Y;
	cout << X + Y / 2 << endl;


	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;

void In(ll& I)
{
	cin >> I;
}

void In(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void Out(ll& O)
{
	cout << O;
}

void Out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

int main()
{
	ll N;
	In(N);

	vl H(N);
	In(H);

	ll M = 1;

	for (int i = 1; i < N; i++)
	{
		bool See = true;
		for (int j = i - 1; j >= 0; j--)
		{
			if (H[j] > H[i])
				See = false;
		}
		if (See)M++;
	}

	Out(M);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

int main() {
  int a,b,c,d,x,y,tmp;
  cin >> a >> b >> c >> d;
  x = c,y=d;
  rep(i,a){
    cin >> tmp;
    x = max(x,tmp+1);
  }
  rep(i,b){
    cin >> tmp;
    y = min(y,tmp);
  }
  if(x==c) cout << "War";
  else if(y>=x)cout << "No War";
  else cout << "War";
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int a,b,t;
    cin >> a >> b >> t;
    ll ans = 0;
    while(t+0.5>0)
    {
       ans+=b;
       t-=a;
    }
    cout << ans-b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct Edge{int to,weight;};
/*----------------------------------------------*/

signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  map<int,int>check;
  rep(i,n) check[a[i]]++;
  int ans=0;
  /* rep(i,check.size()){
    if(check[i]<i) ans+=check[i];
    if(check[i]>i) ans+=check[i]-i-1;
  }*/
  for(auto p:check){
    int x=p.first,y=p.second;
    if(y<x) ans+=y;
    else ans+=y-x;
  }
  cout<<ans<<endl;
  // rep(i,check.size()) cout<<check[i]<<endl;
  return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
    string S;
    cin >> S;
    int a[2];
    a[0] = a[1] = 0;
    int len = S.length();
    for (int i = 0; i < len; i++) {
        a[S[i] - '0']++;
    }
    cout << min(a[0], a[1]) * 2 << endl;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import numpy as np
from decimal import Decimal

N = int(input())
A = [int(10**9*Decimal(input())) for _ in range(N)]

def count(a):
  n = a
  count2 = count5 = 0
  while n%2 == 0 and count2<18:
    n //= 2
    count2 += 1
  while n%5 == 0 and count5<18:
    n //= 5
    count5 += 1
  return count2,count5

Z = np.zeros((19,19), dtype=np.int64)
answer = 0
for a in A:
  c2,c5 = count(a)
  answer += Z[18-c2,18-c5]
  Z[:c2+1,:c5+1] += 1

print(answer)


Measured memory_bytes: 34972
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef complex<int> Point;

int main()
{
	for(int n;cin>>n,n;){
		vector<vector<Point> > bs(n+1);
		rep(i,n+1){
			int m; cin>>m;
			bs[i].resize(m);
			rep(j,m)
				cin>>real(bs[i][j])>>imag(bs[i][j]);
		}
		repi(i,1,n+1){
			if(bs[i].size()!=bs[0].size())
				continue;
			int m=bs[i].size();
			rep(j,4){
				bool eq1=true,eq2=true;
				Point d1=bs[i][0]-bs[0][0],d2=bs[i][m-1]-bs[0][0];
				rep(k,m){
					eq1&=bs[i][k]==bs[0][k]+d1;
					eq2&=bs[i][m-1-k]==bs[0][k]+d2;
				}
				if(eq1 || eq2){
					cout<<i<<endl;
					break;
				}
				rep(k,bs[i].size())
					bs[i][k]*=Point(0,1);
			}
		}
		cout<<"+++++"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
   int dp[3]={0};
   for(int i=0;i<n;i++){
    int cst[3];
    for(int k=0;k<3;k++){
        cin >> cst[k];
    }
    int dp2[3]={0};
    for(int k=0;k<3;k++){
        for(int j=0;j<3;j++){
            if(j!=k){
                dp2[j]=max(dp2[j],dp[k]+cst[j]);
            }
        }
    }
    for(int j=0;j<3;j++){
        dp[j]=dp2[j];
    }
   }
   cout << max(dp[0],max(dp[1],dp[2])) << endl;
}


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

int main() {
  int n;
  int k;
  cin >> n >> k;
  int h[n];
  int ans=0;

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

  for (int i=0;i<n;i++){
    if(h[i]>=k)ans++;
  }
  cout << ans << endl;

  return 0;
}

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

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

int main(void){
    int n, sum = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> d(n);
    REP(i, n) {
        cin >> d[i];
    }
    REP(i, n) {
        FOR(j, i + 1, n) {
            sum += d[i] * d[j];
        }
    }

    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n;
    cin >> n;
    vector<P> v;
    for(int i=0;i<n*2;i++){
        int a;
        cin >> a;
        v.push_back(P(a, i));
    }
    sort(v.begin(), v.end());
    int lft = 0;
    long long ans = 1, mod = 1e9+7;
    for(int i=0;i<n*2;i++){
        int s = v[i].second;
        if(s < n){
            if(lft <= 0) lft--;
            else ans *= lft--;
        }else{
            if(lft >= 0) lft++;
            else ans *= -lft++;
        }
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2548
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
ll A,B;
string S;
int main(){
	cin>>A>>S>>B;
	if(S=="+")cout<<A+B<<endl;
	if(S=="-")cout<<A-B<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define fir first
#define sec second
int R[200002];
const int INF=1001001001;

vector<pair<int,int> > edge[100002];
int d[100002];
int s[100002];
int sans[200002];
int N,M,Q;
int main(){
	scanf("%d %d %d",&N,&M,&Q);
	rep(i,M){
		R[i]=INF;
		int u,v;
		scanf("%d %d",&u,&v);u--;v--;
		edge[u].pb(make_pair(v,i) );
		edge[v].pb(make_pair(u,i) );		
	}
	rep(i,Q){
			int r;
			scanf("%d",&r);r--;
			R[r]=i;
	}
	
	fill(&d[0],&d[N+1],INF);
	fill(&s[0],&s[N+1],INF);
	//dijkstra
	priority_queue< pair<int,int>, vector<pair<int,int> >, 
	greater<pair<int,int> > > q;
	q.push(make_pair(0,0) );
	while(q.size()){
		pair<int,int> p=q.top();q.pop();
		int n=p.second;int c=p.first;
		if(d[n]<c)continue;
		rep(i,edge[n].size() ){
			int to=edge[n][i].fir;
			int ro=edge[n][i].sec;
			if(c+1==d[to]){
				s[to]=max(s[to], min(s[n],R[ro]) );
				if(s[to]<min(s[n],R[ro]) )q.push( make_pair(c+1,to) );
			}else if(c+1<d[to] ){
				s[to]=min(s[n],R[ro]);
				d[to]=c+1;
				if(s[to]<min(s[n],R[ro]) )q.push( make_pair(c+1,to) );
				q.push( make_pair(c+1,to) );
			}
		}
	}
	rep(i,N){
		if(i!=0&&s[i]<Q)sans[s[i]]++;
	}
	int ans=0;
	rep(i,Q){
		ans+=sans[i];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 13516
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll n;
    cin>>n;

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

    sort(a,a+n);

    ll ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){

               
                if(a[k]<(a[i]+a[j]))
                    ans++;

                else break;
            }
        }
    }

    cout<<ans<<"\n";

}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    string s; cin >> s;
    for(int i = 0; i < (int)s.size(); i++){
        if(s[i] == '?'){
            if(s[i - 1] == 'P'){
                s[i] = 'D';
            }else if(s[i + 1] == 'D' || s[i + 1] == '?'){
                s[i] = 'P';
            }else{
                s[i] = 'D';
            }
        }
    }
    for(int i = 0; i < (int)s.size(); i++){
        if(i != s.size() - 1) cout << s[i];
        else cout << s[i] << endl;
    }

}


Measured memory_bytes: 3728
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n / k;
  ll b = (n + k / 2LL) / k;
  if(k % 2 == 1) {
    cout << a * a * a << endl;
  } else {
    cout << a * a * a + b * b * b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mxn 200005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
#define ld long double
typedef long long int ll;
using  namespace std;
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	int n,x,t;
	cin>>n>>x>>t;
	int k=(n+x-1)/x;
	cout<<k*t;
}


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

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

    int n, l;
    while (1)
    {
        cin >> n >> l;
        if (n == 0)
            break;
        vector<int> d(n);
        int pos[2][110] = {};
        for (int i = 0; i < n; i++)
        {
            char d;
            int p;
            cin >> d >> p;
            if (d == 'R')
                pos[0][p] = i + 1;
            else
                pos[1][p] = i + 1;
        }
        int maxl = 0;
        for (int i = 0; i < l; i++)
        {
            if (pos[0][i] != 0)
                maxl = max(maxl, l - i);
            if (pos[1][i] != 0)
                maxl = max(maxl, i);
        }
        cout << maxl << " ";
        int rest = n, la = 0;
        while (rest > 0)
        {
            int nxt[2][110] = {};
            for (int i = l - 1; i >= 0; i--)
            {
                if (pos[0][i] != 0 && pos[1][i] != 0)
                {
                    nxt[0][i + 1] = pos[1][i];
                    nxt[1][i - 1] = pos[0][i];
                    continue;
                }
                if (pos[0][i] != 0)
                {
                    if (i == l - 1)
                    {
                        rest--;
                        la = pos[0][i];
                    }
                    else
                    {
                        nxt[0][i + 1] = pos[0][i];
                    }
                }
                if (pos[1][i] != 0)
                {
                    if (i == 1)
                    {
                        rest--;
                        la = pos[1][i];
                    }
                    else
                    {
                        nxt[1][i - 1] = pos[1][i];
                    }
                }
            }
            for (int i = 0; i < l; i++)
            {
                pos[0][i] = nxt[0][i];
                pos[1][i] = nxt[1][i];
            }
        }
        cout << la << endl;
    }
}


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

int main() {
  ll n;
  cin >> n;

  int k = 1;
  ll ans = 0;
  while (1) {
    ll m = n / k - 1;
    if (k >= m) break;
    if (n % k == 0) ans += m;
    ++k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	string s;
	while(cin >> s) {
		int a[10];
		rep(i,10) { 
			a[i] = s[i] - '0';
		}
		int cnt = 9;
		while(cnt) {
			rep(i,cnt) {
				a[i] = (a[i+1] + a[i]) % 10;
			}
			cnt--;
		}
		cout << a[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007



int main() {
  
  int K,X;
  cin >> K >> X;


  for(int i = X - K + 1;i <= X + K - 1;i++) {
      cout << i << " ";
  }
  cout << endl;
}



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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

typedef pair<int,int> ii;
string s;
 
int main(){
  getline(cin,s);
  deque<ii> ans;
  deque<int> deq;
  for(int i=0; i<s.size(); i++){
    if( s[i] == '\\' ) deq.push_back(i);
    else if( s[i] == '/' && !deq.empty() ){
      int sp = deq.back(); deq.pop_back();
      int area = i - sp;
      while( !ans.empty() && sp <= ans.back().first ){
    area += ans.back().second;
    ans.pop_back();
      }
      ans.push_back(ii(sp,area));
    }
  }
  int sum = 0;
  for(int i=0; i<ans.size(); i++){
  	sum += ans[i].second;
  } 
  cout << sum << endl << (int)ans.size();
  for(int i=0; i<ans.size(); i++){	
  	cout << " " << ans[i].second; 
  }
  cout << endl;
}

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

int main() {
  int n,l;
  cin >> n >> l;
  int a = 0;
  rep(i,0,n) {
    a += i+l;
  }
  if (l > 0) {
    a -= l;
  } else if (l+n-1 < 0) {
    a -= l+n-1;
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 3616
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] DR = { -1, 0, 1, 0 };
	static int[] DC = { 0, 1, 0, -1 };
	static int H, W;
	static boolean[][] f;
	static int[][][] visit;

	public static void main(String[] args) {
		while (true) {
			H = sc.nextInt();
			W = sc.nextInt();
			long L = sc.nextLong();
			if (H == 0) break;
			f = new boolean[H + 2][W + 2];
			visit = new int[H + 2][W + 2][4];
			int cr = 0;
			int cc = 0;
			int cd = 0;
			Arrays.fill(f[0], true);
			Arrays.fill(f[H + 1], true);
			for (int i = 0; i < H; ++i) {
				f[i + 1][0] = f[i + 1][W + 1] = true;
				char[] row = sc.next().toCharArray();
				for (int j = 0; j < W; ++j) {
					if (row[j] == '#') {
						f[i + 1][j + 1] = true;
					} else if (row[j] == '.') {
						// nop
					} else {
						cr = i + 1;
						cc = j + 1;
						cd = "NESW".indexOf(row[j]);
					}
				}
			}
			int turn = 0;
			do {
				visit[cr][cc][cd] = turn;
				for (int i = 0; i < 4; ++i) {
					int nr = cr + DR[(cd + i) % 4];
					int nc = cc + DC[(cd + i) % 4];
					if (!f[nr][nc]) {
						cd = (cd + i) % 4;
						break;
					}
				}
				cr += DR[cd];
				cc += DC[cd];
				++turn;
			} while (visit[cr][cc][cd] == 0);
			if (visit[cr][cc][cd] <= L) {
				int loop = turn - visit[cr][cc][cd];
				L = visit[cr][cc][cd] + (L - visit[cr][cc][cd]) % loop;
			}
			for (int i = 1; i <= H; ++i) {
				for (int j = 1; j <= W; ++j) {
					for (int k = 0; k < 4; ++k) {
						if (visit[i][j][k] == L) {
							System.out.println(i + " " + j + " " + "NESW".charAt(k));
						}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 34980
import java.util.*;
import java.io.*;

public class Main {
	static int a[], b[];
	
	public static void main(String[] args) throws IOException{
		//Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		a= new int[n];
		b= new int[n];
		
		st = new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++){
			a[i] = Integer.parseInt(st.nextToken());
		}
		st = new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++){
			b[i] = Integer.parseInt(st.nextToken());
		}
		
		int ans = 0;
		for(int i=29;i>=1;i--){
			int cntone = 0;
			int T = 1<<(i-1);
			
			for(int j=0;j<n;j++){
				b[j] = b[j]&(2*T-1);
			}
			for(int j=0;j<n;j++){
				a[j] = a[j]&(2*T-1);
			}
			Arrays.sort(a);
			Arrays.sort(b);
			int p1 = 0,p2=0, p3=0;
			for(int j=n-1;j>=0;j--){
				while(p1<n&& a[j]+b[p1]<T)	p1++;
				while(p2<n&& a[j]+b[p2]<2*T)	p2++;
				while(p3<n&& a[j]+b[p3]<3*T)	p3++;
				
				cntone += (p2-p1) + (n-p3);
				cntone &=1;
			}

			if(cntone %2 == 1)
				ans |= T;
		}
		System.out.println(ans);
	}
}

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

int main() {
    int R,G,B,n;
    cin>>R>>G>>B>>n;
    int r_max=n/R;
    int G_max=n/G;


    int count=0;
    for(int i=0;i<=r_max;i++){
        for(int j=0;j<=G_max;j++){
            if((n-(R*i+G*j))>=0 && (n-(R*i+G*j))%B==0) count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  int n, d;
  cin >> n >> d;

  int result = n/(2*d+1);
  if((2*d+1)*result == n) cout << result << endl;
  else cout << result+1 << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = [0] * 10
for v in C.values():
    D[v] += 1

D[0] = (H - 2) * (W - 2) - len(C)
for d in D:
    print(d)


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

using namespace std;

int main(){
    long long int H,N,sum=0;
    cin >> H >> N;
    vector<long long int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }

    if(H<=sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define NUM 1000000007
#define MAX 100001
#define INF LLONG_MAX
vector<ll> BIT;
void update(ll i, ll val, ll n){
    for(;i<=n;i+=(i&(-i)))
        BIT[i]=max(BIT[i],val);
}
ll query(ll i){
    ll sum = 0;
    for(;i>0;i-=(i&(-i)))
        sum=max(sum,BIT[i]);
    return sum;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,tmp;
    cin>>n;
    vector<ll> h,v;
    for(int i=0;i<n;i++){
        cin>>tmp;
        h.pb(tmp);
    }
    for(int i=0;i<n;i++){
        cin>>tmp;
        v.pb(tmp);
    }
    BIT.assign(n+1,0);
    ll ans = 0;
    for(int i=0;i<n;i++){
        ll tmp = query(h[i]-1);
        ans=max(ans,tmp+v[i]);
        update(h[i],tmp+v[i],n);
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


// 68 11 55

int gcd(int a, int b) {
    while (b != 0) {
        auto na = a % b;
        a = b;
        b = na;
    }
    return a;
}


void oneCase() {
    ull k;
    cin >> k;

    vector<ll> arr(50);
    for (ull i = 0; i < 50; ++i) {
        arr[i] = i;
    }
    for (auto& val : arr) {
        val += k / 50;
    }
    for (int i = 0; i < k % 50; ++i) {
        for (int j = 0; j < 50; ++j) {
            if (j == i) {
                arr[i] += 50;
            } else {
                --arr[j];
            }
        }

    }
    cout << 50 << "\n";
    for (auto val : arr) {
        cout << val << " ";
    }
    cout << "\n";


}


int main() {
    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


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

int main(){
    int flag=1;
    int n,k;
    int ans=0;

    cin >>n>>k;
    if(k==1)ans=0;
    else ans = n-(k-1)-1;
    cout << ans <<endl;
    //cout <<fixed<<setprecision(16)<< ans <<endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
M, K = map(int, input().split())

if M == 0:
  if K == 0:
    print(0, 0)
  else:
    print(-1)
elif M == 1:
  if K == 0:
    print(0, 0, 1, 1)
  else:
    print(-1)
elif K < (1 << M):
  for i in range(1 << M):
    if i != K:
      print(i, end=" ")
  print(K, end=" ")
  for i in range((1 << M) - 1, -1, -1):
    if i != K:
      print(i, end=" ")
  print(K)
else:
  print(-1)

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

// loop macro
#define PER(ITER,TIMES) for(auto ITER = 0; ITER < TIMES; ++ITER)

// helper macro
#define FUCK(IT) #IT": " << IT << ": "
#define ALL(ITER) ITER.begin(), ITER.end()

void solve(void);

/* --- MAIN PART ----------------------------------------------------------- */

#define SOLVE_F
#ifdef SOLVE_E

void solve(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    PER(i, n) {
        cin >> a[i];
    }
    sort(ALL(a), [](const int& a, const int& b){return a > b;});
    int result = a[0];
    PER(i, (a.size() - 2) / 2) {
        result += 2 * a[i + 1];
    }
    if ((a.size() - 2) % 2) {
        result += a[(a.size() - 2 / 2) + 1];
    }
    cout << result;
    return;
}

#endif

#ifdef SOLVE_F

void solve(void) {
    int n, m, sum;
    cin >> n >> m >> sum;
    PER(i, m) {
        cout << sum << " ";
    }
    PER(i, n - m) {
        cout << (sum > 100 ? sum / 2 + 2 : sum + 1) << " ";
    }
    return;
}

#endif

#ifdef SOLVE_B

long long times (const vector<long long>& sorted, long long len) {
    long long result = 1;
    PER (i, len) {
        result *= sorted[i];
    }
    return result;
}

void solve(void){
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n);
    PER(i, n) {
        cin >> a[i];
    }

    vector<long long> up, down;
    PER(i, n) {
        if (a[i] > 0) {
            up.push_back(a[i]);
        } else if (a[i] < 0) {
            down.push_back(a[i] = -a[i]);
        }
    }

    long long result = 0;
    if ((k % 2 == 1 && up.size() == 0) || (down.size() == 1 && up.size() == k - 1)) {
        if (up.size() + down.size() != a.size()) {
            result = 0;
        } else {
            sort(ALL(a));
            for (int i = 0; i < k; ++i) {
                result += -a[i];
            }
            while (result < 0) {
                result += (long long) 1e9 + 7;
            }
        }
    } else {
        sort(ALL(up), [](const long long& a, const long long& b){return a > b;});
        sort(ALL(down), [](const long long& a, const long long& b){return a > b;});

        for(long long i = 0; i <= down.size(); i += 2) {
            long long _ = times(up, k - i) * times(down, i);
            result = (result > _ ? result : _);
            result %= (long long)1e9 + 7;
        }
    }

    cout << result << endl;

    return;
}

#endif // for solve

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

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



Measured memory_bytes: 3660
#include<iostream>
using namespace std;
int h,w,map[20][20];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int f(int i,int j,int cnt)
{
	if(cnt>10)return 11;
	int ans=11;
	for(int r=0;r<4;r++)
	{
		int x=i+dx[r],y=j+dy[r];
		while(x>=0&&y>=0&&x<h&&y<w&&map[x][y]==0)x+=dx[r],y+=dy[r];
		if(x<0||y<0||x>=h||y>=w)continue;
		else if(map[x][y]==3)return cnt+1;
		else
		{
			map[x][y]=0;
			if(x-dx[r]!=i||y-dy[r]!=j)ans=min(ans,f(x-dx[r],y-dy[r],cnt+1));
			map[x][y]=1;
		}
	}
	return ans;
}
main()
{
	while(cin>>w>>h,h)
	{
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>map[i][j];
		int sx,sy;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)
		{
			if(map[i][j]==2)
			{
				sx=i;sy=j;map[i][j]=0;
			}
		}
		int t=f(sx,sy,0);
		cout<<(t>10?-1:t)<<endl;
	}
}



Measured memory_bytes: 3008
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();


    // 宿題をやる総日数
    int n_sum = 0;
    for(int i=0; i<m; ++i) {
      n_sum += sc.nextInt();
    }

    // 遊べる日数
    int asobitai = -1;
    if(n >= n_sum) {
      asobitai = n - n_sum;
    }

    // 出力
    System.out.println(asobitai);
  }
}

Measured memory_bytes: 46504
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h, n = MAP()
a = LIST()
if sum(a) >= h:
    print('Yes')
else:
    print('No')

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int al=0, bo=0;
    for (int i=0; i<n; i+=2){
        al=al+a.at(i);
    }
    for (int i=1; i<n; i+=2){
        bo=bo+a.at(i);
    }
    cout << al-bo<< endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) (c).size()
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)

#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll MAX=30000;
const ll mod=1e9+7;

#pragma GCC Optimize("Ofast")

vector<ll>tw,tr,sx;
ll ptw,ptr,psx;

int main(){
	FOR(i,2,MAX){
		if(i%2==0&&i%3==0)
			sx.PB(i);
		else if(i%2==0)
			tw.PB(i);
		else if(i%3==0)
			tr.PB(i);
	}
	ll n;cin>>n;
	if(n==3){
		cout<<"2 5 63";
		return 0;
	}
	ptw=2;ptr=2;
	if(n%2)
		psx=1;
	n-=ptw+ptr+psx;
	n/=2;
	REP(i,n){
		if(ptw!=(sz(tw)))
			ptw+=2;
		else if(ptr!=(sz(tr)))
			ptr+=2;
		else
			psx+=2;
	}
	REP(i,ptw)
		cout<<tw[i]<<" ";
	REP(i,ptr)
		cout<<tr[i]<<" ";
	REP(i,psx)
		cout<<sx[i]<<" ";
}

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

using namespace std;

int main(void) {
	long long N;
	cin >> N;
	set<long long> A;
	for(int i = 0; i < N; ++i) {
		long long a;
		cin >> a;
		if(A.count(a) == 1) {
			cout << "NO\n";
			return 0;
		}
		A.insert(a);
	}
	cout << "YES\n";
	return 0;
}



Measured memory_bytes: 9600
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
//#define _DEBUG
int main() {
	int n, q, l, r;
	int ac[(int)1e5];
	char s[1 + (int)1e5];
	scanf("%d%d", &n, &q);
#ifdef _DEBUG
	for (int i = 1; i <= n; i++)
		printf("%d", i%10);
	printf("\n");
#endif
	scanf("%s", s);
	ac[0] = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'A'&&s[i + 1] == 'C') {
			ac[i + 2] = ac[i + 1] = ac[i] + 1;
			i++;
		}
		else {
			ac[i + 1] = ac[i];
		}
	}
	
#ifdef _DEBUG
	for (int i = 0; i < n; i++)
		printf("%d", ac[i]);
	printf("\n");
#endif
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &l, &r);
		printf("%d\n", ac[r - 1] - ac[l - 1]);
	}
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int nday = sc.nextInt();
    int m = sc.nextInt();
    for(int i = 0 ; i < m; i++){
      nday -= sc.nextInt();
    }
    System.out.println(Math.max(nday, -1));
  }
}

Measured memory_bytes: 46188
#include<bits/stdc++.h>
using namespace std;
int s[1005],n,k,sum;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",&s[i]);
	sort(s,s+n);
	for(int i=0;i<k;i++)
		sum+=s[i];
	printf("%d",sum);
	return 0;
} 

Measured memory_bytes: 3800
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

double dist(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,j,N,K,cnt=1;
  cin>>N>>K;
  vec dp(N,inf),h(N);
  dp[0]=0;
  rep(i,N){
    cin>>h[i];
  }
  rep(i,N){
    rep1(j,K+1){
      if(i+j<N){
        dp[i+j]=min(dp[i+j],dp[i]+labs(h[i]-h[i+j]));
      }
    }
  }
  cout<<dp[N-1]<<endl;
  return 0;
}

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

typedef long long ll;

int main(){
	cin.tie(0);	
	cout.tie(0);	
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	ll t,a;
	cin >> t >> a;
	--n;
	ll k = 1;
	while(n--){
		ll tao,alpha;
		cin >> tao >> alpha;
		ll mul = max((k * t + tao - 1)/tao, (k*a + alpha - 1)/alpha);
		k = mul;
		t = tao;
		a = alpha;
	}
	cout << k * (t + a) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n;
  cin >> n;
  n %= 10;
  if(n==2||n==4||n==5||n==7||n==9){
    cout<<"hon";
  }else if(n==3){
    cout<<"bon";
  }else{
    cout<<"pon";
  }
}


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

int main(){
  int n;
  int a,b;
  unsigned long long int ans=0;
  cin >> n;
  cin >> a;
  for(int i=0; i<n-1; i++){
    cin >> b;
    if(a-b>=0){
      ans += a-b;
    } else {
      a = b;
    }
  }
  cout << ans << endl;
}


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

namespace Make_Purse_Light
{
    class Program
    {
        static int[] Coins = new int[] { 10, 50, 100, 500 };
        static bool flag = false;

        private static void Main(string[] args)
        {
            while (true)
            {
                // 会計金額
                int bill = int.Parse(Console.ReadLine());
                if (bill == 0) break;

                // 所持金
                int[] ownedCoins = Console.ReadLine().Trim().Split(' ').Select(i => int.Parse(i)).ToArray();
                // 所持枚数
                int ownedMoney = 0;
                for (int i = 0; i < 4; i++) ownedMoney += ownedCoins[i] * Coins[i];

                // お釣り
                int changeMoney = ownedMoney - bill;
                // お釣り枚数
                int[] changeCoins = GetChange(changeMoney);

                // 支払い枚数
                int[] paymentCoins = GetPayment(ownedCoins, changeCoins);

                WriteLines(paymentCoins);
            }
        }

        private static int[] GetChange(int money)
        {
            int[] result = new int[Coins.Count()];
            for (int i = Coins.Count()-1; i >= 0; i--)
            {
                result[i] = money / Coins[i];
                money %= Coins[i];
            }
            return result;
        }

        private static void WriteLines(int[] paymentCoins)
        {
            if (flag) Console.WriteLine(); else flag = true;
            for (int i = 0; i < Coins.Count(); i++)
            {
                if (paymentCoins[i] > 0)
                {
                    Console.WriteLine("{0} {1}", Coins[i], paymentCoins[i]);
                }
            }
        }

        private static int[] GetPayment(int[] l1, int[] l2)
        {
            int[] result = new int[Coins.Count()];
            for (int i = 0; i < l1.Count(); i++)
            {
                result[i] = (l1[i] - l2[i]);
            }
            return result;
        }
    }
}


Measured memory_bytes: 9820