akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 5000010
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    FASTIO;
    ll n, k;
    cin>>n>>k;
    ll tot = n % k;
    tot = min(tot, k-tot);
    cout<<tot<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,magic[5][5];
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	magic[1][1]=a;
	magic[1][2]=b;
	magic[1][3]=3*c-a-b;
	magic[2][2]=c;
	magic[2][1]=4*c-2*a-b;
	magic[2][3]=2*a+b-2*c;
	magic[3][1]=a+b-c;
	magic[3][2]=2*c-b;
	magic[3][3]=2*c-a;
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		cout<<magic[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 整数の入力
x1, y1, x2, y2 = map(int, input().split())

# 点1から点2への差分を計算
dx = x2 - x1
dy = y2 - y1

# 点3, 点4の座標を計算
x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy

# 出力
print(str(x3) + " "+str(y3)+" "+str(x4)+" " + str(y4))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#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, d, a;
    cin >> n>>d>>a;
    d = 2 * d;

    vector<P> e(n);
    rep( i, n ) {
        cin >> e[i].first >> e[i].second;
    }
    sort(e.begin(),e.end());

    ll ans = 0;
    queue<pair<ll,ll>> f;
    ll damage = 0;
    rep ( i, n ) {
        ll x = e[i].first;
        ll h = e[i].second;

        while ( !f.empty() && f.front().first < x ) {
            damage -= f.front().second;
            f.pop();
        }
        if ( h <= damage ) {
            continue;
        }
        h -= damage;

        ll num = (h + a - 1) / a;
        ans += num;

        f.push(P(x+d, a*num));
        damage += f.back().second;
    }
    cout << ans << endl;
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;
vector<int> B;
vector<vector<int> > g;
vector<vector<int> > idx;
vector<int> V;
vector<int> res;
void dfs(int a) {
	V[a] = 1;
	for (int i = 0; i < g[a].size(); i++) {
		if (V[g[a][i]] == 0) {
			dfs(g[a][i]);
			if (B[g[a][i]] == 1) {
				B[a] ^= 1;
				res.push_back(idx[a][i]);
			}
		}
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<pair<int, int> > A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
	sort(A.begin(), A.end());
	vector<int> X(N);
	B.resize(N + 1, 0);
	for (int i = 0; i < N; i++) {
		X[i] = A[i].first;
	}
	if (A[0].second == 1) {
		B[0] = 1;
	}
	for (int i = 0; i < N - 1; i++) {
		if (A[i].second != A[i + 1].second) {
			B[i + 1] = 1;
		}
	}
	if (A.back().second == 1) {
		B.back() = 1;
	}
	vector<int> L(M);
	vector<int> R(M);
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i];
	}
	g.resize(N + 1);
	idx.resize(N + 1);
	V.resize(N + 1, 0);
	for (int i = 0; i < M; i++) {
		int l = lower_bound(X.begin(), X.end(), L[i]) - X.begin();
		int r = upper_bound(X.begin(), X.end(), R[i]) - X.begin();
		g[l].push_back(r);
		g[r].push_back(l);
		idx[l].push_back(i);
		idx[r].push_back(i);
	}
	for (int i = 0; i < N + 1; i++) {
		if (V[i] == 0) {
			dfs(i);
			if (B[i] == 1) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	sort(res.begin(), res.end());
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); i++) {
		if (i > 0) cout << " ";
		cout << res[i] + 1;
	}
	cout << endl;
}

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

int main(){
	int n,m;cin>>n>>m;
	int a=m/2,b=m-m/2;
	rep(i,a){
		cout<<i+1<<' '<<(2*a+1)-i-1+1<<endl;
	}
	rep(i,b){
		cout<<i+2*a+2<<' '<<2*b-i-1+2*a+2<<endl;
	}
}

Measured memory_bytes: 3588
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		long sum1 = a[n - 1];
		long sum2 = a[0];
		int i = 1;
		while (a[i] <= 0 && i < n - 1) {
			sum1 -= a[i];
			i++;
		}
		while (i < n - 1) {
			sum2 -= a[i];
			i++;
		}
		System.out.println(sum1 - sum2);
		sum1 = a[n - 1];
		sum2 = a[0];
		i = 1;
		while (a[i] <= 0 && i < n - 1) {
			System.out.println(sum1 + " " + a[i]);
			sum1 -= a[i];
			i++;
		}
		while (i < n - 1) {
			System.out.println(sum2 + " " + a[i]);
			sum2 -= a[i];
			i++;
		}
		System.out.println(sum1 + " " + sum2);
	}
}



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

using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N, D;
    cin >> N >> D;
    int X[N][D];
    rep(i, N) {
        rep(j, D) { cin >> X[i][j]; }
    }

    float total = 0;
    int count = 0;
    rep(i, N) {
        REP(j, i + 1, N) {
            total = 0;
            rep(k, D) { total += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]); }
            total = sqrt(total);
            if (ceil(total) == floor(total)) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <math.h>

using namespace std;

int main() {

	long int N;
  	cin >> N;
  	long int A[N];
  	for(long int i=0;i<N;i++){
  	cin >> A[i];
    }
  
  	long int sum=0;
  	for(long int i=0;i<N;i++){
  	sum += A[i];
    }
  	long int poi;
  	long int acc=0;
	for(long int i=0;i<N;i++){
  	acc += A[i];
    if(acc >= sum/2){
      	poi=i;
 //     	acc=A[i];
    	break;
    }
    }
  	long int sumleft=0;
  	for(long int i=0;i<poi;i++)
    {
    	sumleft+=A[i];
    }
    long int sumright=sum-sumleft;
	long int idea1=fabs(sumright-sumleft);
  
sumleft=0;
  	for(long int i=0;i<poi+1;i++)
    {
    	sumleft+=A[i];
    }
sumright=sum-sumleft;
	long int idea2=fabs(sumright-sumleft);
  
  	if(idea1<idea2){
    cout << idea1<<endl;
    }else{
    cout << idea2<<endl;
    }
  /*
  cout << acc << " " << sum << " " << sum/2 <<" "<< sumleft <<" " << sumright <<" "<< poi <<endl; 
  	if(sum%2==0){
    //printf("%10d\n",fabs(sumleft-sum/2)+fabs(sum/2-sumright));
    cout << fabs(sumleft-sum/2)+fabs(sum/2-sumright) <<endl; 
    }else{
    //printf("%10d\n",fabs(sumleft-(sum+1)/2)+fabs((sum+1)/2-sumright));
    cout << fabs(sumleft-(sum)/2)+fabs((sum)/2-(sumright-1))+1 <<endl;
    }
    */
}

Measured memory_bytes: 1792
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
T = [[] for _ in range(N)]
for a, b in AB:
    a -= 1
    b -= 1
    T[a].append(b)
    T[b].append(a)

ans = M
for a, b in AB:
    a -= 1
    b -= 1
    T[a].remove(b)
    T[b].remove(a)
    visited = [False] * N
    def rec(x):
        visited[x] = True
        for y in T[x]:
            if not visited[y]:
                rec(y)
    rec(0)
    ans -= all(visited)
    T[a].append(b)
    T[b].append(a)
print(ans)

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

using namespace std;
using ll = long long;

#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()

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

	int k;
	string s;
	cin >> k >> s;
	if(s.size() > k) {
		for(int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "...";
	} else {
		cout << s;
	}
}			



Measured memory_bytes: 3652
import sys
input = sys.stdin.readline
n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1,n-1):
    tmp=0
    for j in range(i+1,n):
        if l[j] - l[i] >= l[i-1]:
            break
        else:
            for k in range(tmp,i):
                if l[tmp] > l[j]-l[i]:
                    ans += i-tmp
                    break
                elif l[k] > l[j]-l[i]:
                    tmp = k
                    ans += i-tmp
                    break
print(ans)

Measured memory_bytes: 3188
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  ll N, Q; cin >> N >> Q;  

  if (N == 1){
    for (int i = 0; i < Q; i++){
      int V, W; cin >> V >> W;
      cout << V << endl;
    }
    return 0;
  }
  
  vector <ll> ans(Q);
  
  for (int i = 0; i < Q; i++){
    ll V, W; cin >> V >> W;
    vector <ll> v = {V}, w = {W};
    while (V > 1){
      if (V % N <= 1) V = V / N;
      else V = V / N + 1;
      v.push_back(V);
    }
    while (W > 1){  
      if (W % N <= 1) W = W / N;
      else W = W / N + 1;
      w.push_back(W);
    }

    for (int j = 1; j <= v.size(); j++){
      if (v[v.size() - j] == w[w.size() - j]){
        ans[i] = v[v.size() - j];
      }else break;
    }
  }
  
  for (int i = 0; i < Q; i++){
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1280
n,k = map(int, input().split())
a = list(map(int, input().split()))


for _ in range(k):
    b = [0] * n
    for i in range(n):
        l = max(0, i - a[i])
        r = min(n-1, i + a[i])
        b[l] += 1
        if r + 1 < n:
            b[r + 1] -= 1
    ee = True
    a[0] = b[0]
    if a[0] < n:
        ee = False
    for i in range(1, n):
        a[i] = a[i-1] + b[i]
        if a[i] < n:
            ee = False
    if ee == True:
        break

print(*a)

Measured memory_bytes: 151032
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	public void run(){
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int max = 0;
		for(int i = 0; i < m;i++)
		{
			int buf = 0;
			for(int j = 0 ; j < n; j++){
				if(sc.nextInt() == 1) buf++;
			}
			max = Math.max(max, buf);
		}
		System.out.println(max);
	}
	public static void main(String Args[]){
		Main t = new Main();
		t.run();
	}
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n, k;
	cin >> n >> k;
	vl a(n+1);
	a[0] = 1;
	for(int i =1; i<=n; i++){
		ll x;
		cin >> x;
		a[i] = x;
	}
	for(int i = k+1; i <= n; i++){
		if(a[i] > a[i- k]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 4848
import math
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
N,M = map(int,input().split())
if N > 1 and M > 1:
    print((N-2)*(M-2))
elif N==1 and M == 1:
    print(1)
else:
    print(N+M-3)


Measured memory_bytes: 5252
// AGC002_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    ll N, M;
    cin >> N >> M;
    
    // calculation
    ll num = abs(M - N) + 1;
    if (N == 0 || M == 0) {
        cout << "Zero" << "\n";
    } else if (N < 0 && M < 0) {
        // どちらも負
        if (num%2 == 0) {
            cout << "Positive" << "\n";
        } else {
            cout << "Negative" << "\n";
        }
    } else if (N < 0 && 0 < M) {
        // N の数で正負が決まる
        cout << "Zero" << "\n";
    } else if (0 < N && 0 < M) {
        cout << "Positive" << "\n";
    }
    
    return 0;
}


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

class Node<T>
{
    private int Height { get; set; }
    private Node<T> Parent { get; set; }
    private long size;
    public long Size { get { return Find().size; } set { size = value; } }
    public T Item { get; }

    public Node(T item)
    {
        Height = 0;
        Parent = this;
        Item = item;
        Size = 1;
    }

    public Node<T> Find()
    {
        if (Parent == this)
        {
            return this;
        }
        var p = Parent.Find();
        Parent = p;
        return p;
    }

    public static void Unite(Node<T> a, Node<T> b)
    {
        var p = a.Find();
        var q = b.Find();
        if (p.Height < q.Height)
        {
            p.Parent = q;
            q.Height = Math.Max(p.Height + 1, q.Height);
            q.Size += p.Size;
            p.Size = 0;
        }
        else
        {
            q.Parent = p;
            p.Height = Math.Max(q.Height + 1, p.Height);
            p.Size += q.Size;
            q.Size = 0;
        }
    }

    public static bool Same(Node<T> a, Node<T> b)
    {
        return a.Find().Item.Equals(b.Find().Item);
    }
}

class MyClass
{
    public static void Solve()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var N = input[0];
        var Q = input[1];
        var uf = new Node<int>[N];
        for (int i = 0; i < N; i++)
        {
            uf[i] = new Node<int>(i);
        }
        for (int i = 0; i < Q; i++)
        {
            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var com = input[0];
            var x = input[1];
            var y = input[2];
            if (com == 0)
            {
                Node<int>.Unite(uf[x], uf[y]);
            }
            else
            {
                Console.WriteLine(Node<int>.Same(uf[x], uf[y]) ? 1 : 0);
            }
        }
    }

    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}



Measured memory_bytes: 25052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  bool t=false;
  for(int64_t b=-1000;b<1000;b++){
      for(int64_t a=-1000;a<1000;a++){
        if((a-b)*((a-b)*(a-b)*(a-b)*(a-b)+5*a*b*((a-b)*(a-b)+a*b))==x){
          cout << a << " " << b << endl;
          t=true;
          return 0;
        }
      }
  }
}
  


Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int a,b,c;cin>>a>>b>>c;
  bool ans=false;
  if(a+b==c||b+c==a||c+a==b){
    ans=true;
  }
  cout<<yesno(ans)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K;
    string S;
    cin >> N >> S >> K;
    
    int l = S.size();
    // SのK番目の文字
    char rep = S[K-1];
    
    for(int i=0;i<l;i++){
        if(S[i] != rep)
            cout << '*';
        else
            cout << S[i];
        
    }
    cout << endl;
    
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

pii solve(int k, int n)
{
    //cout << "call : " << k << ", " << n << endl;
    if (n == 1L) return {0L, k};

    pii ret;
    if (k + k >= 10L) {
        ret = solve((k + k) / 10L + (k + k) % 10L, n/2L);
        ret.first += n - (n % 2);
    } else {
        ret = solve(k + k, n/2L);
        ret.first += n/2L;
    }
    if (n % 2L) {
        if (ret.second + k >= 10L) {
            ret.first += 2L;
            ret.second = (ret.second + k) / 10L + (ret.second + k) % 10L;
        } else {
            ret.first++;
            ret.second += k;
        }
    }

    //cout << "return : " << ret.fir << " " << ret.sec << endl;

    return ret;
}

int funami(vi &state)
{
    int s = state[0];
    int ans = 0L;
    Rep(i, state.size()) {
        s += state[i];
        ans++;
        if (s >= 10L) {
            ans++;
            s = s / 10L + s % 10L;
        }
    }
    return ans;
}

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

    Int(n);
    vector<pii> data(n);
    rep(i, n) {
        cin >> data[i].fir >> data[i].sec;
    }

    vi state;
    int ans = 0L;
    rep(i, n) {
        pii tmp = solve(data[i].fir, data[i].sec);
        ans += tmp.fir;
        state.pb(tmp.sec);
    }

    cout << ans + funami(state) << endl;

    return 0;
    int my = ans + funami(state);

    // ~~~ test ~~~ 

    int length = 0;
    rep(i, data.size()) length += data[i].sec;
    vi input(length);
    int p = 0;
    rep(i, data.size()) {
        rep(j, data[i].sec) {
            input[p++] = data[i].fir;
        }
    }

    int collect = funami(input);
    if (collect != my) {
        //cout << "EWOEOEEEEEEEEEEWOEOWOEO" << endl;
        cout << n << endl;
        rep(i, n) {
            cout << data[i].fir << " " << data[i].sec << endl;
        }
        cout << my << " " << collect << endl;
        return 0;
    }

    return 0;
}


Measured memory_bytes: 5620
a = int(input())

b = []

p = 0
pp = 0
ppp = 0

for i in range(a):
    b.append(list(map(int,input().split())))
b.sort(key=lambda x:-x[2])
for i in range(0,101):
    for j in range(0,101):
        for k in range(a):
            if k == 0:
                p = abs(b[k][0] - i) + abs(b[k][1]-j)+b[k][2]
            else:
                if max(0,p - abs(b[k][0]-i)- abs(b[k][1]-j)) != b[k][2]:
                    pp = 1
        if pp == 0:
            ppp = 1
            break
        else:
            pp = 0
    if ppp == 1:
        print(i,j,p)
        break


Measured memory_bytes: 3064
def solve(S, T):
    for i in reversed(range(0, len(S) - len(T) + 1)):
        if all(S[j] == "?" or S[j] == T[j - i] for j in range(i, i + len(T))):
            return (S[0:i] + T + S[i + len(T):]).replace("?", "a")
    return "UNRESTORABLE"


if __name__ == "__main__":
    S = input()
    T = input()
    print(solve(S, T))


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
   int n,flag=1;
   long long int ans=0;
   scanf("%d",&n);
   for(int i=1;i<n;i++){
       for(int j=1;flag;j++){
           if(i*j<n)ans++;
           else flag=0;
       }
     flag=1;
   }
  printf("%lld",ans);
   return 0;
}


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

int N, M, p, d[10000], a;
int main(){
	cin >> N >> M >> p;
	for (int i = 0; i < M; i++){
		cin >> d[i];
		d[i] = (d[i] -= p) < 0 ? (N + d[i]) : d[i];
	}
	sort(d, d + M);
	a = min(min(d[M - 1], N - d[0]), d[M - 1]);
	for (int i = 0; i < M + 1; i++){
		a = min(a, N - d[i + 1] + d[i] + min(N - d[i + 1], d[i]));
	}
	cout << a * 100 << endl;
}


Measured memory_bytes: 1216
# Author: cr4zjh0bp
# Created: Tue Mar 17 19:50:06 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

sys.setrecursionlimit(10 ** 6)

n, q = na()
ab = nan(n - 1)
px = nan(q)

tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = ab[i]
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

cnt = [0 for _ in range(n)]
for i in range(q):
    p, x = px[i]
    p -= 1
    cnt[p] += x

def dfs(i, p, s):
    x = s + cnt[i]
    cnt[i] = x
    for j in tree[i]:
        if j == p:
            continue
        dfs(j, i, x)

def bfs():
    q = deque()
    q.append((0, -1, 0))
    while len(q):
        p, b, s = q.popleft()
        x = s + cnt[p]
        cnt[p] = x
        for i in tree[p]:
            if i == b:
                continue
            q.append((i, p, x))

bfs()
print(*cnt)

Measured memory_bytes: 145952
#include<stdio.h>
int main(void){
	int dat0,dat1,dat2, tmp;
	
	scanf("%d %d %d", &dat0, &dat1, &dat2);

	if (dat0 > dat1){
		tmp = dat0;
		dat0 = dat1;
		dat1 = tmp;
	}
	if (dat1 > dat2){
		tmp = dat1;
		dat1 = dat2;
		dat2 = tmp;
	}
	if (dat0 > dat1){
		tmp = dat0;
		dat0 = dat1;
		dat1 = tmp;
	}
	printf("%d %d %d\n", dat0, dat1, dat2);

	return 0;
}

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

int main() {
    int N; cin >> N;
    vector<ll> S(5);
    rep(i, N){
        string s; cin >> s;
        if(s[0] == 'M'){
            S[0]++;
        } else if(s[0] == 'A'){
            S[1]++;
        } else if(s[0] == 'R'){
            S[2]++;
        } else if(s[0] == 'C'){
            S[3]++;
        } else if(s[0] == 'H'){
            S[4]++;
        }
    }

    ll ans = (S[0] * S[1] * (S[2]+S[3]+S[4])) + (S[0] * S[2] * (S[3]+S[4])) + (S[0] * S[3] * S[4]);
    ans += (S[1] * S[2] * (S[3] + S[4])) + (S[1] * S[3] * S[4]) + (S[2] * S[3] * S[4]);

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h> // only for GCC
using namespace std;

int main(){
    int n;
    cin >> n;
    int score[100];
    for(int i=0; i < 100; i++) score[i] = 0;
    for(int i=0; i <n*(n-1)/2; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if(c < d){
            score[a] += 0;
            score[b] += 3;
        }
        else if(c > d){
            score[a] += 3;
            score[b] += 0;
        }
        else {
            score[a] += 1;
            score[b] += 1;
        }
    }
    set<int> s;
    for(int i=1; i <= n; i++){
        s.insert(score[i]);
    }

    int result[100];
    set<int>::reverse_iterator it = s.rbegin();
    int count = 1;
    while( it != s.rend() )
    {
        int term = 0;
        for(int j=1; j <= n; j++){
            if(*it == score[j]){ result[j] = count; term++;}
        }
        it++;
        count+=term;
    }
    for(int i=1; i <= n; i++) cout << result[i] << endl;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int a[27],b[27],c[27];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    for(int i=1;i<=n;++i)
        cin>>b[i];
    for(int i=1;i<n;++i)
        cin>>c[i];
    int sum=0;
    for(int i=1;i<=n;++i){
        sum+=b[a[i]];
        if(a[i-1]==a[i]-1&&i>1)
            sum+=c[a[i-1]];
    }
    cout<<sum;
    return 0;
}
///fdfdfsdfs

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

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

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

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

  if(k >= n) {
    cout << 0 << endl;
    return 0;
  }

  sort(h.begin(), h.end());

  ll ans = 0;
  for(int i = 0; i < n - k; i++) {
    ans += h[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3980
x,y = map(int,input().split())
list1 =[1,3,5,7,8,10,12]
list2 =[4,6,9,11]
if x == 2 or y == 2:
    print("No")
elif x in list1 and y in list1:
    print("Yes")
elif x in list2 and y in list2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LEN 100005
using namespace std;

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enquene(P x){
    Q[tail] = x;
    tail = (tail+1)%LEN;
}

P dequene(){
    P x = Q[head];
    head = (head+1)%LEN;
    return x;
}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    cin >> n >> q;
    for(i = 1; i <= n; i++){
        cin >> Q[i].name;
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n+1;
    while(head != tail){
        u = dequene();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enquene(u);
        else{
            cout << u.name << " " << elaps << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 13396
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(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 ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  ll k;
  vector<ll> lunlun;
  map<int, vector<ll>> lunvec;
  cin >> k;
  k--;
  rep(i, 10)
  {
    if (i == 0)
      continue;
    lunlun.push_back(i);
    lunvec[1].push_back(i);
  }
  ll ans = 0;
  int keta = 1;
  while (1)
  {
    if (k < lunlun.size())
    {
      ans = lunlun[k];
      break;
    }
    if (keta == 1)
    {
      keta++;
      continue;
    }
    vector<ll> old = lunvec[keta - 1];
    rep(i, old.size())
    {
      ll target = old[i];
      int matsubi = target % 10;
      for (int i = -1; i <= 1; i++)
      {
        if (matsubi + i < 0 || 9 < matsubi + i)
          continue;
        lunvec[keta].push_back(10 * target + matsubi + i);
        lunlun.push_back(10 * target + matsubi + i);
      }
    }
    keta++;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4848
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <sstream>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<vector<int>> lists;
    lists.resize(K);
 

    for (size_t i = 0; i < K; i++)
    {
        int d = 0;        
        cin >> d;
        lists[i].resize(d);
        for (int j = 0; j < d; j++)
        {
            cin >> lists[i][j];
        }
    }



    // お菓子をもらっていない人の数を数える

    vector<int> counter(N);

    for (auto it = lists.begin(); it != lists.end(); ++it)
    {
        for (auto _it = it->begin(); _it != it->end(); ++_it)
        {
            counter[(*_it-1)] ++;
        }
    }

    int count = 0;
    for(auto it = counter.begin(); it != counter.end(); ++it)
    {
        if(0 == *it)
        {
            count ++;
        }
    }

    cout << count << endl;

    return 0;    
}

Measured memory_bytes: 3672
S = input()
target_S = "keyence"
flg = 0
 
if S.startswith(target_S) or S.endswith(target_S):
    flg = 1
else:
    for i in range(len(target_S)):
        target_left = target_S[:i]
        target_right = target_S[i:]
        
        if S.startswith(target_left) and S.endswith(target_right):
            flg = 1

print("YES") if flg == 1 else print("NO")

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k,sum=0;
	cin>>n>>k;
	vector<pair<ll,ll>>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i).first>>v.at(i).second;
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		sum+=v.at(i).second;
		if(sum>=k){
			cout<<v.at(i).first<<endl;
			return 0;
		}
	}
	return 0;
}


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, A, B, C, D;
  string S;
  cin >> N >> A >> B >> C >> D;
  cin >> S;

  for (int i = A + 1; i < C; ++i) {
    if ((S[i - 1] == '#') && (S[i] == '#')) {
      cout << "No" << endl;
      return 0;
    }
  }

  for (int i = B + 1; i < D; ++i) {
    if ((S[i - 1] == '#') && (S[i] == '#')) {
      cout << "No" << endl;
      return 0;
    }
  }

  bool swappable = false;
  if (C > D) {
    for (int i = B - 1; i < D; ++i) {
      if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
        swappable = true;
        break;
      }
    }

    if (!swappable) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define endl '\n'
#define inf 9223372036854775807
#define maxn 3000001
#define mod (ll)(1e9+7)
#define int ll
 
using namespace std;
 
void io(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int t,a,b,c,n,d,l,r,k;
int dp[maxn][3];
int ar[maxn][3];

int32_t main(){
io();
IOS;    
		cin>>n;
		for(int i=1;i<=n;i++){
			for(int j=0;j<3;j++)cin>>ar[i][j];
		}
		dp[1][0]=ar[1][0];
		dp[1][1]=ar[1][1];
		dp[1][2]=ar[1][2];
		for(int i=2;i<=n;i++){
			dp[i][0]=max(dp[i-1][1]+ar[i][0],dp[i-1][2]+ar[i][0]);
			dp[i][1]=max(dp[i-1][0]+ar[i][1],dp[i-1][2]+ar[i][1]);
			dp[i][2]=max(dp[i-1][0]+ar[i][2],dp[i-1][1]+ar[i][2]);
		}
       	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;



        

        


        
    
        
        
                


 
        
 
 
 
        
 
 
 
 
        
        
 
        
        
 
    
    
    
    
 
 
       
 
 
 
 
      
   
 
 
 
 
}

Measured memory_bytes: 8348
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
using  ll = long long;
using ld = long double;
using Byte = unsigned char;
using namespace std;

//string ans = "Yes";


int SetAns() {
	string s,t;
	cin >> s >> t;

	int ans = 0;
	rep(i, s.length()) {
		if (s[i] != t[i]) ans++;
	}
	return ans;
}

int main() {
	
	cout << SetAns() << endl;
	return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vi H(N); REP(i, N) cin >> H[i];
    int ans = 0;
    REP(i, N)
    {
        int c = 0;
        while(i < N-1 && H[i] >= H[i+1])
        {
            c++;
            i++;
        }
        ans = max(ans, c);
    }
    cout << ans << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if (a + b < a + c && a + b < b + c) {
		cout << a + b << endl;
	}
	else if (a + c < a + b && a + c < b + c) {
		cout << a + c << endl;
	}
	else {
		cout << b + c << endl;
	}
	return 0;
}
	

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine();
		if(n.EndsWith("s"))
		{
			Console.WriteLine(n+"es");
		}
		else
		
		Console.WriteLine(n+"s");
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


Measured memory_bytes: 26176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	int n, x;

	std::cin >> n >> x;

	std::vector<int> v(n);

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	int d = 0;

	for (size_t i = 0; i < n; i++)
	{
		d += v[i];
		if (d > x) {
			std::cout << i + 1 << std::endl;
			return 0;
		}
	}

	std::cout << n + 1 << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

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

    public static void main(String[] args) {
        String S = ns();
        Set<Character> dir = new HashSet<>();

        for (int i = 0; i < S.length(); i++) {
            dir.add(S.charAt(i));
        }

        int ns = 0;
        if (dir.contains('N')) {
            ns++;
        }

        if (dir.contains('S')) {
            ns++;
        }

        int we = 0;
        if (dir.contains('W')) {
            we++;
        }

        if (dir.contains('E')) {
            we++;
        }

        if (ns % 2 == 0 && we % 2 == 0) {
            out.println("Yes");
        } else {
            out.println("No");
        }

    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

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

int main(){
  string O, E;
  cin >> O >> E;
  int LO=O.size();
  int LE=E.size();
  vector<char> pass(LO+LE);
  for(int i=0; i<LE; i++){
    pass.at(i*2)=O.at(i);
    pass.at(i*2+1)=E.at(i);
  }
  if(LO>LE) pass.at(LO+LE-1)=O.at(LO-1);
  for(int i=0; i<LO+LE; i++){
    cout << pass.at(i);
  }
  cout << ' ' << endl;
}

Measured memory_bytes: 256
use std::collections::{HashMap, HashSet};
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(Debug, Clone)]
struct Restaurant {
    n: u32,
    point: u32,
}

fn main() {
    let n = read::<u32>();
    let mut regions: HashMap<String, Vec<Restaurant>> = HashMap::new();
    let mut orders: Vec<String> = vec![];

    for i in 1..n + 1 {
        let key = read::<String>();
        orders.push(key.clone());
        let restaurant = regions.entry(key).or_insert(vec![]);
        restaurant.push(Restaurant {
            n: i,
            point: read::<u32>(),
        });
    }

    let orders: HashSet<String> = orders.into_iter().collect();
    let mut orders: Vec<String> = orders.into_iter().collect();
    orders.sort();

    for key in &orders {
        let region = regions.get_mut(key).unwrap();
        let len = region.len();
        for i in 0..len {
            for j in i..len {
                if region[i].point < region[j].point {
                    let tmp = region[j].clone();
                    *region.get_mut(j).unwrap() = region[i].clone();
                    *region.get_mut(i).unwrap() = tmp;
                }
            }
        }
    }

    for k in &orders {
        for i in 0..regions[k].len() {
            println!("{}", regions[k][i].n);
        }
    }
}


Measured memory_bytes: 4352
use std::io;
use std::cmp::min;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v: Vec<i32> = procon_read();
	let n = v[0];
	let t = v[1];
	let mut mini:i32 = 1001;
	for i in 0..n {
		let v: Vec<i32> = procon_read();
		if v[1] <= t {
			if min(mini, v[0]) != mini {
				mini = v[0];
			}
		}
	}
	if mini == 1001 {
		println!("TLE");
	}else{
		println!("{}", mini);
	}
}

Measured memory_bytes: 4352
#![allow(unused_imports, unused_macros, non_snake_case)]
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

//{{{ macros missing in 1.15.1
#[macro_use]
mod macros {
    macro_rules! eprint {
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = write!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! eprintln {
        () => { eprintln!(""); };
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = writeln!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! dbg {
        ($val:expr) => {
            match $val {
                tmp => {
                    eprintln!(
                        "[{}:{}] {} = {:#?}",
                        file!(),
                        line!(),
                        stringify!($val),
                        &tmp
                    );
                    tmp
                }
            }
        };
    }
}
//}}}

fn solve() -> bool {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    let n: usize = sc.read();
    let s: Vec<char> = sc.read_chars();
    if n % 2 == 0 {
        for i in 0..n / 2 {
            if s[i] != s[i + n / 2] {
                return false;
            }
        }
        return true;
    } else {
        return false;
    }
}
fn run() {
    println!("{}", if solve() { "Yes" } else { "No" });
}

fn main() {
    std::thread::Builder::new()
        .name("run".to_string())
        .stack_size(1024 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap()
}

//{{{ Scanner
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
//}}}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll a, b;
    cin >> a >> b;
    cout << a * b << " " << 2 * (a + b) << endl;
}


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

int main() {

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

  int n;
  cin >> n;

  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    ans += i;
  }

  cout << ans << '\n';
}

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

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

    int L;
    int l = 0;
    int ans = 1;
    for (int i = 0; i < N; i++)
    {
        cin >> L;
        l += L;
        if (l <= X)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
k,n = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

a_diff = [] 

a.each_with_index do |an, i|
  if i + 1 == a.length
    a_diff.push a[0] + k - a[i]
  else
    a_diff.push a[i+1] - a[i] 
  end
end

puts k - a_diff.max


Measured memory_bytes: 18364