akhauriyash/Code-Regression huggingface dataset:
n = gets.chomp.to_i
arr = Array.new
n.times do
  order = gets.split(" ")
  case order[0]
    when "insert"
      arr.unshift(order[1].to_i)
    when "delete" 
      arr.index(order[1].to_i) == nil ? (next): (arr.delete_at(arr.index(order[1].to_i)))
    when "deleteFirst"
    arr.shift
    when "deleteLast"
    arr.pop
  end
end

(arr.size).times do |num|
  print arr[num]
  num+1 == (arr.size) ? (print "\n") : (print " ")
end


Measured memory_bytes: 21276
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

struct P
{
	double x, y;
	P(double x, double y) :x(x), y(y) {}
	P() :P(0, 0) {}
	P operator+(const P& v)const
	{
		return P(x + v.x, y + v.y);
	}
	P operator-(const P& v)const
	{
		return P(x - v.x, y - v.y);
	}
	P operator*(const double v)const
	{
		return P(x*v, y*v);
	}
	bool operator==(const P& v)const
	{
		return abs(x - v.x) <= 0.0000000000001&&abs(y - v.y) <= 0.00000000000001;
	}
	bool operator!=(const P& v)const
	{
		return abs(x - v.x) > 0.0000000000001 || abs(y - v.y) > 0.00000000000001;
	}

	double dot(const P& v)const
	{
		return x*v.x + y*v.y;
	}
	double cross(const P& v)const
	{
		return x*v.y - y*v.x;
	}
	double length()const
	{
		return sqrt(x*x + y*y);
	}
	double length2()const
	{
		return x*x + y*y;
	}
	
	bool operator<(const P& v)const
	{
		return x<v.x || (x == v.x) && y < v.y;
	}
	bool operator>(const P& v)const
	{
		return x<v.x || (x == v.x) && y < v.y;
	}
};

int ccw(P a, P b, P c) 
{
	b = b - a; c = c - a;
	if (b.cross(c) > 0)   return +1;			// counter clockwise
	if (b.cross(c) < 0)   return -1;			// clockwise
	if (b.dot(c) < 0)     return +2;			// c--a--b on line
	if (b.length2() < c.length2()) return -2;   // a--b--c on line
	return 0;
}

double CalcDiameter(vector<P>& points)
{
	int n = points.size();
	int is = 0, js = 0;
	for (int i = 1; i != n; i++)
	{
		if (points[i].y > points[is].y)
		{
			is = i;
		}
		if (points[i].y < points[js].y)
		{
			js = i;
		}
	}
	double maxd = (points[is] - points[js]).length();

	int i, maxi, j, maxj;
	i = maxi = is;
	j = maxj = js;
	do
	{
		if ((points[(i + 1) % n] - points[i]).cross(points[(j + 1) % n] - points[j]) >= 0)
		{
			j = (j + 1) % n;
		}
		else
		{
			i = (i + 1) % n;
		}
		if (maxd < (points[i] - points[j]).length())
		{
			maxd = (points[i] - points[j]).length();
			maxi = i;
			maxj = j;
		}
	} while (i != is || j != js);
	return maxd;
}

vector<P> points;

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

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		double x, y;
		cin >> x >> y;
		points.push_back(P(x, y));
	}

	printf("%.10lf\n", CalcDiameter(points));
	
	return 0;
}


Measured memory_bytes: 4192
#include<stdio.h>
typedef unsigned u;
u G[9][9],Gi[9],V[9],r,n;
void F(u x,u deep)
{
	if(V[x])return;
	V[x]=1;
	if(deep==n)++r;
	else
	{
		u i;
		for(i=Gi[x];i--;)F(G[x][i],deep+1);
	}
	V[x]=0;
	return;
}
int main()
{
	u q,a,b;
	scanf("%u%u",&n,&q);
	while(q--)
	{
		scanf("%u%u",&a,&b);
		G[a][Gi[a]++]=b;
		G[b][Gi[b]++]=a;
	}
	F(1,1);
	printf("%u\n",r);
	return 0;
}

Measured memory_bytes: 128
function Main (input) {
  input = input.split("\n")[0].split(" ").map(inp => parseInt(inp, 16));
  var A = input[0], B = input[1];
  var ans = "";
  if (A < B) {
    ans = "<";
  }
  else if (A > B) {
    ans = ">";
  }
  else if (A == B) {
    ans = "=";
  }
  console.log(ans);
}

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

Measured memory_bytes: 9420
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

int f(int n){
    int sum = 0;
    while(n>0){
        sum += n%10;
        n/=10;
    }
    return sum;
}

void Main(){
    ll A, B, K;
    cin >> A >> B >> K;
    ll i = A;
    for(int i_len=A+K; i<i_len && i<=B; i++){
        cout << i << el;
    }
    i = max(i, B-K+1);
    for(; i<=B; i++){
        cout << i << el;
    }
}



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

using namespace std;

int main(){
    int k , s ;
    cin >> k >> s ;
    int ans = 0 ;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            int z = s - (x + y) ;
            if ( z >= 0 && z <= k ) ans++ ;
        }
    }
    cout << ans << endl;


    return 0 ;
}


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

typedef long long int ll;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll k = n / (a+b);
    ll ans = k * a;
    n -= k * (a+b);
    ans += min(a, n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
lst = list(map(int, input().split()))

def temp(x):
  return T-x * 0.006

dif = 10 ** 9
for i in range(N):
  if dif > abs(temp(lst[i])-A):
    dif = min(dif, abs(temp(lst[i])-A))
    ans = i

print (ans+1)

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

int main(){
  constexpr int M = 10001;
  vector<bool> P(M,true);
  for(int i = 2; i*i < M; ++i){
    if(not P[i]) continue;
    for(int j = i; i*j < M; ++j){
      P[i*j] = false;
    }
  }
  vector<int> A(M,-1);
  for(int i = 5; i < M; ++i){
    if(not P[i]) A[i] = A[i-1];
    else if(P[i-2]) A[i] = i;
    else A[i] = A[i-1];
  }
  int n;
  while(cin >> n,n){
    cout << A[n]-2 << " " << A[n] << endl;
  }
}



Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <map>
#include <unordered_map>
#include <memory.h>

using namespace std;

int main() {
    int n, w;
    cin >> n >> w;
    long long v[n][2];
    for (int i = 0; i < n; ++i){
        cin >> v[i][0] >> v[i][1];
    }
    map<long long,long long> dp;
    dp[0] = 0;
    for (int i = 0; i < n; ++i)
        for(auto j = dp.rbegin(); j != dp.rend(); ++j){
            if (dp.count(v[i][0] + j->first) == 0 && v[i][0] + j->first <= w)
                dp[v[i][0]+j->first] = j->second + v[i][1];
            else if (v[i][0] + j->first <= w)
                dp[v[i][0]+j->first] = max(j->second + v[i][1],dp[v[i][0]+j->first]);
        }
    long long r = 0;
    for (auto i : dp)
        r = max(r,i.second);
    cout << r << endl;
}

Measured memory_bytes: 384
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
        int int1 = Integer.parseInt(scan.next());
//        int int2 = Integer.parseInt(scan.next());
//        int int3 = Integer.parseInt(scan.next());
//        int int4 = Integer.parseInt(scan.next());
//        double db = Double.parseDouble(scan.next());
        int ans_int = 0;
        String ans = "";
//        String temp_str1 = "";
//        String temp_str2 = "";
        int temp_int1 = 0;
//        String str1 = scan.next();
//        String str2 = scan.next();
//        String str3 = scan.next();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < int1; i++){
            int m = Integer.parseInt(scan.next());
            list.add(m);
        }

        for (int i = 0; i < int1; i++){
            for (int j = int1-1; i < j; j--){
                ans_int += list.get(i)*list.get(j);
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans_int);
        out.flush();
        scan.close();
    }
}


Measured memory_bytes: 20688
n,m = map(int,input().split())
maze = [list(input()) for i in range(n)]

from collections import deque


# 辿り着けないと INF
def bfs(i,k):
    # すべての点を INF で初期化
    d = [[float("inf")] * m for i in range(n)]

    # 移動4方向のベクトル
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

#最短経路を探す再はコメントin
#     for i in range(n):
#         for j in range(m):
#             # スタートとゴールの座標を探す
#             if maze[i][j] == "S":
#                 sx = i
#                 sy = j
#             if maze[i][j] == "G":
#                 gx = i
#                 gy = j

    # スタート地点をキューに入れ、その点の距離を0にする
    que = deque([])
    que.append((i, k))
    d[i][k] = 0

    # キューが空になるまでループ
    ans = 0
    while que:
        # キューの先頭を取り出す
        p = que.popleft()
#         # 取り出してきた状態がゴールなら探索をやめる
#         if p[0] == gx and p[1] == gy:
#             break
        # 移動4方向をループ
        for i in range(4):
            # 移動した後の点を (nx, ny) とする
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            # 移動が可能かの判定とすでに訪れたことがあるかの判定
            # d[nx][ny] != INF なら訪れたことがある
            if 0 <= nx < n and 0 <= ny < m and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                # 移動できるならキューに入れ、その点の距離を p からの距離 +1 で確定する
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
                ans = max(ans, d[p[0]][p[1]] + 1)

    return ans

result = 0
for i, row in enumerate(maze):
    for k, element in enumerate(row):
        if element =='.':
            result = max(result, bfs(i,k))
print(result)

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

using namespace std;

int main(){
    int n,m,l;
    cin >> n >> m >> l;
    int nm[n][m],ml[m][l];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> nm[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin >> ml[i][j];
        }
    }
    long mnl[n][l];
    int cont = 0;
    memset(mnl,0,sizeof(mnl));
    for(int i=0;i<n;i++){
        for(int y=0;y<m;y++){
          for(int j=0;j<l;j++){
              mnl[i][j] += (nm[i][y]*ml[y][j]);
          }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            cout << mnl[i][j];
            if(j+1<l){cout << " ";}
        }
        cout << endl;
    }
    
    return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n;
int a[maxn];

int32_t main()
{
    IOS
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    int cnt=0,ans=0;
    for (int i=n;i>=1;i--)
    {
        if (a[i]>=a[i+1]) cnt++;
        else cnt=1;
        ans=max(ans,cnt);
    }
    cout<<ans-1<<endl;
}



Measured memory_bytes: 640
from fractions import gcd
n = int(input())
A = list(map(int, input().split()))
ans = 0
l = [A[0]]
r = [A[n-1]]
for i in range(1, n):
    l.append(gcd(l[i-1], A[i]))
    r.append(gcd(r[i-1], A[n-i-1]))
r.reverse()
# print(l, r)
for i in range(n):
    if i == 0:
        cost = r[1]
    elif i == n-1:
        cost = l[n-2]
    else:
        cost = gcd(l[i-1], r[i+1])
    if ans < cost:
        ans = cost

print(ans)    


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

using mint = modint998244353;
const mint inv9 = mint(1)/9;

struct S {
    mint x, w;
    S(mint x = 0, mint w = 1): x(x), w(w) {}
};

S op(S a, S b){
    return S(a.x*b.w + b.x, a.w * b.w);
}

S e(){
    return S();
}

S mapping(int f, S a){
    if(f==0) return a;
    else return S(f*(a.w-1)*inv9, a.w);
}

int composition(int f, int g){
    if(f == 0) return g;
    else return f;
}

int id(){
    return 0;
}
int main()
{
    cout << fixed << setprecision(15);
    ll N, Q;
    cin >> N >> Q;

    lazy_segtree<S, op, e, int, mapping, composition, id> seg(N);

    REP(i, N){
        seg.set(i, S(1, 10));
    }

    REP(i, Q){
        ll l, r, d;
        cin >> l >> r >> d;
        l--;

        seg.apply(l, r, d);

        S ans = seg.all_prod();

        cout << ans.x.val() << endl;
    }
    return 0;
}

Measured memory_bytes: 9844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
#define v_inputrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)

int main(){
    string s;
    cin >> s;
    string a[4] = {"maerd", "remaerd", "esare", "resare"};
    string n = "";
    for(int i = s.length() - 1 ; i >= 0 ; i--){
        n = n + s[i];
        rep(j, 4){if(n == a[j])n = "";}
    }
    if(n==""){cout << "YES";}else{cout << "NO";}
}

Measured memory_bytes: 640
//Round One

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

int main ()
{
    int A, B;

    cin >> A >> B;
    int x = 1;
    for (int i = 0; i < 3; i++) {
        x = i + 1;
        if (x == A) {
            continue;
        }
        else if (x == B) {
            continue;
        }
        else {
            break;
        }
    }

    cout << x << endl;


    return 0;
}

Measured memory_bytes: 888
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    c = collections.Counter(a)
    if len(c) > 3:
        return "No"

    k = list(c.keys())
    def f(t):
        for i in range(n-2):
            u = t[i] ^ t[i+1]
            t.append(u)
        if t[0] ^ t[-2] != t[-1] or t[-1] ^ t[1] != t[0]:
            return False
        d = collections.Counter(t)
        if c != d:
            return False
        return True

    for g in k:
        for h in k:
            if f([g,h]):
                return 'Yes'

    return 'No'


print(main())





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

int main() {
	int n;
	cin >> n;
	vector<int> a(55555 + 1, 1);
	a[0] = 0;
	a[1] = 0;
	for (int i = 2; i * i <= 55555; i++) {
		if (a[i] == 1)
			for (int j = i * 2; j <= 55555; j += i)
				a[j] = 0;
	}
	// 1が格納されているaの添え字(>=2)が素数
	vector<int> v;
	for (int i = 0; i <= 55555; i++)
		if (a[i] == 1)
			v.push_back(i);
	// 55555以下の素数
	int count = 0;
	for (int i = 0; i < v.size(); i++) {
		if (v[i] % 5 == 1) {
			cout << v[i] << " ";
			count++;
		}
		if (count == n)
			break;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
def solv(t):
    c = 0
    while t % 100 == 0:
        t /= 100
        c += 1
    return c

D, N = map(int, input().split())
t = 1
c = 0
while c < N:
    n = solv(t)
    if n == D:
        c += 1
    t += 1

print(t -1)

Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if((a<c && c<b) || (b<c && c<a)){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int array[] = new int[n];
        int sum = 0;
        int max = 0;
        for(int i=0; i<n; i++){
            array[i] = sc.nextInt();
            sum += array[i];
            if(max < array[i]){
                max = array[i];
            }
        }
        sum = sum - max/2;
        System.out.println(sum);
    }
}

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

int keta(int N){
  string s;
  s = to_string(N);
  return s.size();
}

int main(){
  int N;
  cin >> N;
  int counter = 0;
  for(int i = 1; i <= N; i++){
    if(keta(i) % 2 == 1) counter++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 2e5+5;



int main() {
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif*/
    run();
    ll n;
    cin>>n;
    cout<<(n+999)/1000*1000-n<<endl;


    return 0;
}

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

int main(){
	while(1){
		int n,w;
		cin >> n >> w;
		if(n==0) break;
		
		vector<int> graph(11,0);
		int vmax=0;
		for(int i=0; i<n; i++){
			int v;
			cin >> v;
			vmax = max(v, vmax);
			graph[v/w]++;
		}
		
		int numbar=vmax/w+1;
		int hmax=0;
		double ans=0.0;
		for(int i=0; i<numbar; i++){
			ans += (double)graph[i]*(numbar-1-i)/(numbar-1);
			hmax = max(graph[i], hmax);
		}
		ans = ans/hmax + 0.01;
		cout << fixed;
		cout << setprecision(6);
		cout << ans << endl;	
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;
 
void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}
 
const int N=2e6+3,M=5e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;
 
int n,m,k,tc,ans,a[N];
 
char s[N];

int main(){
    scanf("%d",&n);
    ll cur = 0;
    for(int i = 1 ; i < N ; i++){
        cur = (cur * 10 + 7) % n;
        if (cur % n == 0)
            return !printf("%d\n",i);
    }
    printf("-1\n");
}


Measured memory_bytes: 3828
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <array>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;



int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    vector<vector<int>> G(N + 1);
    int a, b;
    vector<int> is_used(N + 1, 0);
    vector<pair<int,int>> edge;
    while (cin >> a >> b) {
        G[a].push_back(b);
        G[b].push_back(a);
        edge.emplace_back(a, b);
    }
    queue<int> q;
    q.emplace(1);
    is_used[1] = 1;
    map<pair<int,int>, int> color;
    map<int, int> parent;
    int maxt = 1;
    while (!q.empty()) {
        int f = q.front();q.pop();
        is_used[f] = 1;
        int c = 1;
        maxt = std::max(maxt, (int)G[f].size());
        for (auto e: G[f]) {
            if (is_used[e]) continue;
            if (c == parent[f]) c++;
            pair<int, int> e1(e, f);
            pair<int, int> e2(f, e);
            color[e1] = c;
            color[e2] = c;
            parent[e] = c;
            c++;
            q.emplace(e);
        }
    }
    cout << maxt << "\n";
    for (auto e: edge) {
        cout << color[e] << "\n";

    }
    return 0;
}

Measured memory_bytes: 24436
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			
			int n = sc.nextInt();
			int k = sc.nextInt();
			String s = sc.next();
			String tmp = null;
			
			switch (s.substring(k-1,k)) {
			case "A":
				tmp = "a";
				break;
			case "B":
				tmp = "b";
				break;
			case "C":
				tmp = "c";
				break;
			}
			
			System.out.println(s.substring(0,k-1) + tmp + s.substring(k));	
		}
	}
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <math.h>

int isprime(int);

int main()
{
  int n, i, j, count=0, p[10000];

  scanf("%d",&n);
  for( i=0 ; i<n ; i++ ){
    scanf("%d",&p[i]);
    count += isprime(p[i]);
  }

  printf("%d\n",count);
  return 0;
}

int isprime(int x)
{
  int i;
  if(x==2) return 1;
  if(x<2 || x%2==0) return 0;
  i=3;
  while(i<=sqrt(x)){
    if(x%i==0) return 0;
    i = i+2;
  }
  return 1;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("test.txt","r",stdin);
	ll n,W;
	cin>>n>>W;
	ll w[n+1],v[n+1];
	for(ll i=1;i<=n;i++)
		cin>>w[i]>>v[i];
	ll dp[n+1][W+1];
	for(ll i=0;i<=n;i++)
		dp[i][0]=0;
	for(ll i=0;i<=W;i++)
		dp[0][i]=0;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=W;j++)
		{
			if(w[i]<=j)
				dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][W]<<endl;


}

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

int selection(int *r, int n);
int bubble(int *r, int n);

int bubble(string *r, int n){
    string tmp;
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(r[j][1]-'0'<r[j-1][1]-'0'){
                tmp=r[j-1];
                r[j-1]=r[j];
                r[j]=tmp;
            }
        }
    }
return 0;
}



int selection(string *r, int n){
    int minj;
    string tmp;
    for(int i=0;i<n;i++){
        minj=i;
        for(int j=i;j<n;j++){
            if(r[minj][1]-'0'>r[j][1]-'0'){
                minj=j;  
            }
        }
        tmp=r[i];
        r[i] = r[minj];
        r[minj]=tmp;
    }
    return 0;
}



int main(){
    int n,a,i;
    int flag=0;
    string c;
    string rb[100], rs[100];

    cin>>n;
    for(i=0;i<n;i++){
        cin>>c;
        rb[i]=c;
        rs[i]=c;
    }

    bubble(rb, n);
    selection(rs, n);

    for(i=0;i<n;i++){
        if(i!=n-1) cout<<rb[i]<<' ';
        else cout<<rb[i]<<endl;
    }

    cout<<"Stable"<<endl;

    for(i=0;i<n;i++){
        if(i!=n-1) cout<<rs[i]<<' ';
        else cout<<rs[i]<<endl;
        if(rs[i]!=rb[i]) flag=1;
    }

    if(flag) cout<<"Not stable"<<endl;
    else cout<<"Stable"<<endl;


}


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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)     for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(x);
    int ans=0,cur=0;
    for(int i=1;cur<x;i++){ans++;cur+=i;}
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 200005
int n,t,tp;string a[N],b[N];map<string,int> cnt;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) cin>>a[i],++cnt[a[i]];
	for(int i=1;i<=n;++i) t=max(t,cnt[a[i]]);
	for(int i=1;i<=n;++i) if(t==cnt[a[i]]) b[++tp]=a[i],cnt[a[i]]=0;
	sort(b+1,b+tp+1);for(int i=1;i<=tp;++i) cout<<b[i]<<endl;
	return 0;
}

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

x, y = map(int, input().split())

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]

if x in b and y in b:
    print('Yes')
elif x in a and y in a:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X, T;
    cin >> N >> X >> T;
    int cnt = 0;
    int now = 0;
    while(now < N) {
        now += X;
        cnt++;
    }
    cout << cnt * T << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

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

ll GCD(ll a, ll b){
    ll s = a, t = b;
    while(s%t != 0){
        ll u = s%t;
        s=t; t=u;
    }
    return t;
}

int main(){
    ll n, m; cin >> n >> m;
    ll gcd = 1;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    rep(i,n){
        gcd = gcd / GCD(gcd,a[i]) * a[i];
        if(gcd/2 > m){ cout << 0 << endl; return 0; }
    }
    ll ans = m/gcd;
    if(m - ans*gcd >= gcd/2) ans++;
    bool check = true;
    rep(i,n) if((gcd/a[i])%2 == 0) check = false;
    cout << (check ? ans : 0) << endl;
}

Measured memory_bytes: 4032
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cstdio>
struct String {
	char* str;
	const int length;
	String(const int size) : str{ new char[size + 1] }, length{ size } {};
	~String() { delete[] str; }
	const char operator[](const int index) const {
		return str[index];
	}
};
int scanf(String& str) {
	return std::scanf("%s", str.str);
}
std::istream& operator>>(std::istream& is, String& str) {
	return std::cin >> std::setw(str.length + 1) >> str.str;
}
int main() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	int n, k; std::cin >> n >> k;
	String from(n), to(n); std::cin >> from >> to;
	std::vector<int> left_diff(n, 0);
	for (auto i = 0; i < n; ++i) {
		if (from[i] != to[i]) left_diff[i] = i;
		else if (i > 0) left_diff[i] = left_diff[i - 1];
	}
	std::vector<int> black_segment_count(n, 0), white_segment_count(n, 0);
	if (to[0] == 'B') black_segment_count[0]++;
	else white_segment_count[0]++;
	for (auto i = 1; i < n; ++i) {
		black_segment_count[i] = black_segment_count[i - 1];
		white_segment_count[i] = white_segment_count[i - 1];
		if (to[i] != to[i - 1]) {
			if (to[i] == 'B') black_segment_count[i]++;
			else white_segment_count[i]++;
		}
	}
	
	std::deque<int> black_end, white_end;
	std::vector<int> left_min_cost(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		if (to[i] != from[i]) left_min_cost[i + 1] = left_min_cost[left_diff[i]] + 1;
		else left_min_cost[i + 1] = left_min_cost[left_diff[i] + 1];
		while (!black_end.empty() && black_end.front() <= i - k) black_end.pop_front();
		while (!white_end.empty() && white_end.front() <= i - k) white_end.pop_front();
		if (to[i] == 'B') {
			if (!black_end.empty()) left_min_cost[i + 1] = std::min(left_min_cost[i + 1], left_min_cost[black_end.front()] - black_segment_count[black_end.front()] + black_segment_count[i] + 1);
			while (!black_end.empty() && left_min_cost[black_end.back()] - black_segment_count[black_end.back()] > left_min_cost[i] - black_segment_count[i])
				black_end.pop_back();
			black_end.push_back(i);
		}
		else {
			if (!white_end.empty()) left_min_cost[i + 1] = std::min(left_min_cost[i + 1], left_min_cost[white_end.front()] - white_segment_count[white_end.front()] + white_segment_count[i] + 1);
			while (!white_end.empty() && left_min_cost[white_end.back()] - white_segment_count[white_end.back()] > left_min_cost[i] - white_segment_count[i])
				white_end.pop_back();
			white_end.push_back(i);
		}
	}
	std::cout << left_min_cost.back() << std::endl;
}



Measured memory_bytes: 13724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}



int H,W;
const int MAXW = 2001;
const int MAXH = 2001;
string S[MAXH];
int tate[MAXH][MAXW];
int yoko[MAXH][MAXW];

void showtate(){
    rep(i,H){
        rep(j,W)cout << tate[i][j];
        cout << endl;
    }
    cout << endl;
}
void showyoko(){
    rep(i,H){
        rep(j,W)cout << yoko[i][j];
        cout << endl;
    }
    cout << endl;
}

int main(){

    cin >> H >> W;
    rep(i,H){
        rep(j,W){
            tate[i][j] = 0;
            yoko[i][j] = 0;
        }
        cin >> S[i];
    }

    rep(i,H){
        int counter = 0;
        rep(j,W){
            if(S[i][j]=='.'){
                counter++;
                yoko[i][j]=counter;
            }else {
                counter = 0;
            }
        }
    }
    for(int i=H-1;i>=0;i--){
        for(int j=W-1;j>=1;j--){
            if(yoko[i][j]>=yoko[i][j-1] && S[i][j-1]!='#'){
                yoko[i][j-1] = yoko[i][j];
            }
        }
    }
    // showyoko();
    rep(j,W){
        int counter = 0;
        rep(i,H){
           if(S[i][j]=='.') {
               counter++;
               tate[i][j] = counter;
           }else{
               counter = 0;
           }
        }
    }
    for(int i=W-1;i>=0;i--){
        for(int j=H-1;j>0;j--){
            if(tate[j][i]>=tate[j-1][i] && S[j-1][i] != '#'){
                tate[j-1][i] = tate[j][i];
            }
        }
    }

    int ans = 0;
    

    rep(i,H)rep(j,W){
        int tmp = tate[i][j] + yoko[i][j];
        ans = max(ans, tmp);
    }
    cout << ans-1 << endl;
    

    return 0;
}

Measured memory_bytes: 42464
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=5e5+5;
priority_queue < ll > x,y;
ll xs,ys,vy[N],vx[N],ans, n,a[N];
int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    ans=-1e16+7;
    cin>>n;
    for(int i=0;i<3*n;i++){
        cin>>a[i];
        if(i<n){
            x.push(-a[i]);
            xs+=a[i];
        }
        else
        if(i>=2*n){
            y.push(a[i]);
            ys+=a[i];
        }
    }
    vx[n]=xs;
    for(int i=n;i<2*n;i++){
        if(a[i]>-x.top()){
            xs+=x.top();
            x.pop();
            xs+=a[i];
            x.push(-a[i]);
        }
        vx[i-n]=xs;
    }
    vy[n]=ys;
    for(int i=2*n-1;i>=n;i--){
        if(a[i]<y.top()){
            ys-=y.top();
            y.pop();
            ys+=a[i];
            y.push(a[i]);
        }
        vy[i-n]=ys;
    }
    for(int i=0;i<n;i++)
        ans=max(ans,vx[i]-vy[i+1]);
    ans=max(vx[n]-vy[n],ans);
    ans=max(vx[n]-vy[0],ans);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 12148
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,x,y,ans=0;
  cin >> a >> b >> c >> x >> y;
  //ABピザの無駄な重複をなくす
  ans+=min(x,y)*min(a+b,c*2);
  if(x-min(x,y)>0) {
    ans+=(x-min(x,y))*min(a,c*2);
  }
  else if(y-min(x,y)>0) {
    ans+=(y-min(x,y))*min(b,c*2);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#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(){
  vector<int> x(5);
  rep(i,5) cin >> x[i];
  int ans=0;
  rep(i,5){
    if(x[i]==0) ans=i+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

int main()
{
    int N, X, T;
    cin >> N >> X >> T;

    int q = N / X;
    int r = N - q * X;

    if (r > 0)
    {
        ++q;
    }

    cout << q * T << endl;


    return 0;
}


Measured memory_bytes: 3632
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn dfs(i: usize, j: usize, field: &mut Vec<Vec<char>>, is_checked: &mut Vec<Vec<bool>>) -> u64 {
    let mut stack = std::collections::VecDeque::new();
    stack.push_back((i, j));
    let mut black_count = 0;
    let mut white_count = 0;
    is_checked[i][j] = true;
    while let Some((cur_x, cur_y)) = stack.pop_back() {
        if field[cur_x][cur_y] == '#' {
            black_count += 1;
        } else {
            white_count += 1;
        }
        if cur_x > 0 && field[cur_x - 1][cur_y] != field[cur_x][cur_y] && !is_checked[cur_x - 1][cur_y] {
            is_checked[cur_x - 1][cur_y] = true;
            stack.push_back((cur_x - 1, cur_y));
        }
        if cur_x < field.len() - 1 && field[cur_x + 1][cur_y] != field[cur_x][cur_y] && !is_checked[cur_x + 1][cur_y] {
            is_checked[cur_x + 1][cur_y] = true;
            stack.push_back((cur_x + 1, cur_y));
        }
        if cur_y > 0 && field[cur_x][cur_y - 1] != field[cur_x][cur_y] && !is_checked[cur_x][cur_y - 1] {
            is_checked[cur_x][cur_y - 1] = true;
            stack.push_back((cur_x, cur_y - 1));
        }
        if cur_y < field[0].len() - 1 && field[cur_x][cur_y + 1] != field[cur_x][cur_y] && !is_checked[cur_x][cur_y + 1] {
            is_checked[cur_x][cur_y + 1] = true;
            stack.push_back((cur_x, cur_y + 1));
        }
    }
    // println!("{:?}", (black_count, white_count));
    black_count * white_count
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);

    let mut field = (0..h)
        .map(|_| read::<String>().chars().collect::<Vec<_>>())
        .collect::<Vec<_>>();

    let mut is_checked: Vec<Vec<bool>> = vec![vec![false; w]; h];

    let mut ans = 0u64;
    for i in 0..field.len() {
        for j in 0..field[0].len() {
            if field[i][j] == '#' && !is_checked[i][j] {
                ans += dfs(i, j, &mut field, &mut is_checked);
            }
        }
    }
    println!("{:?}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
 
const int MAXV=(int) 1e5+1;
 
struct edge{
    int to;
    int H;
};
 
vector <edge> G[MAXV];
int color[MAXV];
 
int main(){
    int N,M;
    cin >> N >> M;
    int H[N+1];
    int u, v, w;
    int ans;

    for(int i=0; i<N; i++){
        cin >> H[i+1];
    }
 
    for(int i=1; i<=M; i++){
        cin >> u >> v;
        edge e = { v, H[u]-H[v] };
        G[u].push_back(e);
        e = { u, H[v]-H[u] };
        G[v].push_back(e);
    }

    ans=0;

    for(int i=1; i<=N; i++){
        bool flag = true;
        //cout << "i " << i << endl;
        for(auto x: G[i]){
            //cout << "to  height " << x.to << " " << x.H << endl;
            if(x.H<=0){
                flag = false;
            }
            //cout << "flag " << flag << endl;
        }
        if(flag){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9784
#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
	long long int x=0;
	int f=1;
	char c=getchar();
	while(c>'9'||c<'0')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,i;
int A,B,C[100000];
long long int a,b;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie();
	cout.tie();
	n=read();
	for(i=0;i<n;i++)
	{
		A=read();
		B=read();
		C[i]=A+B;
		b+=B;
	}
	sort(C,C+n,greater<int>());
	for(i=0;i<n;i+=2)
	{
		a+=C[i];
	}
	cout << a-b;
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long n,m,k,ans=0,cnt=0,tmp;
string s,t;
int main(){
  cin >> n >> m;
  if(n%2==0 or m%2==0){
    cout << "No" << endl;
  }else{
  cout << "Yes" << endl;
    
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>



int main ()

{

    int number[10];

    int i, j, a, n;

    n=10;

    for (i = 0; i < n; i++)

    scanf("%d", &number[i]);



    for (i = 0; i < n; i++)

    {

        for (j = i + 1; j < n; j++)

        {

            if (number[i] < number[j])

            {

                a = number[i];

                number[i] = number[j];

                number[j] = a;

            }

        }

    }


    for (i = 0; i < 3; i++)

    {

        printf("%d\n", number[i]);

    }
    return 0;

}

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

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int tmp = Z;
    int cnt;
    while (tmp + Y + Z <= X)
    {
        tmp += Y + Z;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<ll, ll> P;
int main() {
	int N;
	cin >> N;
	vector<P> ball(N);
	ll MAX = 0, MIN = INF;
	for (int i = 0; i < N; i++) {
		cin >> ball[i].first >> ball[i].second;
		if (ball[i].first > ball[i].second) swap(ball[i].first, ball[i].second);
		MAX = max(MAX, ball[i].second);
		MIN = min(MIN, ball[i].first);
	}
	sort(ball.begin(), ball.end());
	ll Rmax = 0, Rmin = INF, Bmax = 0, Bmin = INF;
	for (int i = 0; i < N; i++) {
		Rmax = max(Rmax, ball[i].second);
		Rmin = min(Rmin, ball[i].second);
		Bmax = max(Bmax, ball[i].first);
		Bmin = min(Bmin, ball[i].first);
	}
	ll ans = (Rmax - Rmin)*(Bmax - Bmin);
	Bmax = 0, Bmin = INF;
	ll b = INF;
	for (int i = 0; i + 1 < N; i++) {
		Bmax = max(Bmax, ball[i].second);
		Bmin = min(Bmin, ball[i].second);
		b = min(b, max(Bmax, ball[N - 1].first) - min(Bmin, ball[i + 1].first));
	}
	ans = min(ans, (MAX - MIN)*b);
	cout << ans << endl;
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	int sum = 0;
	int c[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
			sum += c[i][j];
		}
	}
	int a[3];
	int b[3];
	int A1, A2, A3;
	int B1, B2, B3;

	if (sum % 3) {
		cout << "No" << endl;
		return 0;
	}
	else {
		A1 = (c[1][0] + c[1][1] + c[1][2]) - (c[0][0] + c[0][1] + c[0][2]); //3*(a2-a1);
		A2 = (c[2][0] + c[2][1] + c[2][2]) - (c[1][0] + c[1][1] + c[1][2]); //3*(a3-a2);
		A3 = (c[2][0] + c[2][1] + c[2][2]) - (c[0][0] + c[0][1] + c[0][2]); //3*(a3-a1);

		if (A3 - A2 != A1) {
			cout << "No" << endl;
			return 0;
		}

		if (A1%3) {
			cout << "No" << endl;
			return 0;
		}

		B1 = (c[0][1] + c[1][1] + c[2][1]) - (c[0][0] + c[1][0] + c[2][0]); //3*(b2-b1);
		B2 = (c[0][2] + c[1][2] + c[2][2]) - (c[0][1] + c[1][1] + c[2][1]); //3*(b3-b2);
		B3 = (c[0][2] + c[1][2] + c[2][2]) - (c[0][0] + c[1][0] + c[2][0]); //3*(b3-b1);

		if (B3 - B2 != B1) {
			cout << "No" << endl;
			return 0;
		}

		if (B1 % 3) {
			cout << "No" << endl;
			return 0;
		}

		cout << "Yes" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
int dp[41][401][401];
int a[40], b[40], c[40];
int main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	rep(i, N) {
		cin >> a[i] >> b[i] >> c[i];
	}
	fill((int*)dp, (int*)(dp + 41), INF);
	dp[0][0][0] = 0;
	rep(i, N) {
		rep(j, 401) {
			rep(k, 401) {
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				if (j + a[i] <= 400 && k + b[i] <= 400) dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
			}
		}
	}
	int ans = INF;
	for (int i = 1; i <= 400; i++) {
		for (int j = 1; j <= 400; j++) {
			if (i*Mb == j*Ma) ans = min(ans, dp[N][i][j]);
		}
	}
	if (ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}

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

int main(){
    int n;
    int num;
    vector<int> x;
    vector<int> y;
    
    double manh = 0, euclid = 0, mincof = 0, three = 0;
    
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> num;
        x.push_back(num);
    }
    for(int i=0; i<n; i++){
        cin >> num;
        y.push_back(num);
    }
    
    for (int i = 0; i < n; i++){
        manh += abs(x.at(i) - y.at(i));
    }
    
    for (int i = 0; i < n; i++){
        euclid += (x.at(i) - y.at(i)) * (x.at(i) - y.at(i));
    }
    euclid = sqrt(euclid);
    
    for (int i = 0; i < n; i++){
        three += (x.at(i) - y.at(i)) * (x.at(i) - y.at(i)) * abs((x.at(i) - y.at(i)));
    }
    three = pow(three, 0.3333333333);
    
    for (int i = 0; i < n; i++){
        if(abs(x.at(i) - y.at(i)) > mincof){
            mincof = abs(x.at(i) - y.at(i));
        }
    }
    
    cout << fixed << setprecision(8) << manh << endl;
    cout << fixed << setprecision(8) << euclid << endl;
    cout << fixed << setprecision(8) << three << endl;
    cout << fixed << setprecision(8) << mincof << endl;
}



Measured memory_bytes: 3472