akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np

read = sys.stdin.read

def dubbling(a:np.array, k:int, MAXk=10**12) -> np.array:
    bl = MAXk.bit_length()
    b = np.empty([bl,len(a)+1], dtype=np.int64)
    b[0] = np.append(a, -1)
    for i in range(1,bl):
        x = b[i-1]
        b[i] = x[x]
    X1 = b[np.array(list(format(k,'0'+str(bl)+'b')), dtype=np.int8).astype(np.bool)[::-1]]
    ret = np.append(np.arange(len(a)), -1)
    for i in X1:
        ret = ret[i]
    return ret

n, k = map(int, input().split())
a = np.array(read().split(), dtype=np.int64)
maxk = 10**18

ans = dubbling(a-1, k, MAXk=maxk)[0] + 1
print(ans)

Measured memory_bytes: 185152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i < en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define int long long


int x, y, n; 

int line(int i, int j){
	return min(abs(j - i), min(abs(x-i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)));
}
int32_t main(){ fast;
	cin>>n>>x>>y;
	vector<int> answer(n, 0);
	for(int i = 1; i <n; i++){
		for(int j = i + 1; j <=n; j++){
			answer[line(i, j)]++;
		}
	}
	for(int i =1; i <= n - 1; i++){
		cout<<answer[i]<<endl;
	}	
	
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] num =new int[3];
		int sum = 0;
		for(int i = 0; i < 3; i++) {
			num[i] = sc.nextInt();
			sum += num[i];
		}
		Arrays.sort(num);
		int count = 0;
		if((3*num[2])%2!=(num[0]+num[1]+num[2])%2) {
			num[2]++;
			count++;
		}
		count += ((3*num[2])-(num[0]+num[1]+num[2]))/2;
		System.out.println(count);
	}
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) ans = max(ans, abs(a[i] - a[j]));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int N;
	std::cin >> N;
	std::cout << 180 * (N - 2) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

int N;
int xs[10], ys[10];
int pat[10];
string bins[] = {"1", "2", "4", "8", "16", "32", "64", "128", "256"};
vector<int> lower_bit[10];

string subsolve(int b, int x){
	string ret = bins[b];
	int cnt = 0;
	for(int i=0; i<=b; i++){
		bool on = ((x>>i)&1);
		ret += "&(" + (on?string("x"):string("(~x)")) + "*" + bins[b-i] + "))";
		cnt++;
	}
	return string(cnt,'(') + ret;
}

string solve(){
	string ret = "0";
	int cnt = 0;
	for(int i=0; i<8; i++){
		for(int j=0; j<N; j++)if((ys[j]>>i)&1){
			lower_bit[i].push_back( xs[j]&((1<<(i+1))-1) );
		}
	}
	for(int i=0; i<8; i++){
		for(int j=0; j<(int)lower_bit[i].size(); j++){
			ret += "|" + subsolve(i,lower_bit[i][j]) + ")";
			cnt++;
		}
	}
	return string(cnt,'(') + ret;
}

int main(){
	scanf("%d",&N);
	for(int i=0; i<N; i++){
		scanf("%d%d",xs+i,ys+i);
	}
	puts(solve().c_str());
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i+1;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

int main() {
    int N;
    cin >> N;
    int X[N];
    for(int i=0;i<N;i++){
        cin >> X[i];
    }
    sort(X,X+N);
    ll sum = -114514;
    for(int i=-100;i<=100;i++){
        ll temp = 0;
        for(int j=0;j<N;j++){
            temp+=((X[j]-i)*(X[j]-i));
        }
        if(temp<sum||sum<0){
            sum = temp;
        }

    }
    cout << sum << endl;



}


Measured memory_bytes: 256
import math

X = int(input())
total_500 = 0
total_5 = 0
total_count = 0

if(X >= 500):
    total_500 = math.floor(X/500)
    total_count += total_500 * 1000
    X -= total_500 * 500

if(X >= 5):
    total_5 = math.floor(X/5)
    total_count += total_5 * 5
    X -= total_5 * 5

print(total_count)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int h[] = new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int cost[] = new int[N];
		cost[N-1] = 0;
		cost[N-1-1] = Math.abs(h[N-1] - h[N-1-1]);
		
		for(int i=N-2-1;i>=0;i--) {
			cost[i] = Math.min(cost[i+1]+Math.abs(h[i+1]-h[i]), cost[i+2]+Math.abs(h[i+2]-h[i]));
		}
		
		System.out.println(cost[0]);
	}

}


Measured memory_bytes: 48076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define vec vector<int> 
#define int long long 
#define pii pair<int,int>
int arr[22][22];
int n;
int m[22][(1<<21)+1];
//map<int,bool> mn,wm;
int solve(int i,int mask){
	if(i==n) return 1;
	if(m[i][mask]!=-1){
		return m[i][mask];
	}

	int ans=0;
	rep(j,n){
		if((((1<<j)&mask)==0)&&(arr[i][j]==1)){
			//wm[j]=true;
			ans+=(solve(i+1,mask|(1<<j))%mod);
			//mask-=(1<<j);
			ans%=mod;
			//wm[j]=false;
		}
	}
	//cout<<ans<<endl;
	return (m[i][mask]=ans%mod);
}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
	int t=1;
	//cin>>t;
	while(t--){
		//int n;
		cin>>n;
		//int arr[n][n];
		for(int i=0;i<21;i++) for(int j=0;j<(1<<n);j++) m[i][j]=-1;
		rep(i,n){
			rep(j,n){
				cin>>arr[i][j];
			}
		}
		int mask=0;
		cout<<solve(0,mask);
	}
	//exit();
	return 0;
}


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

class UnionFind{
private:
    using uint = std::uint_fast64_t;
    std::vector<uint> par;
    std::vector<uint> sizes;

    uint find(uint x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }
public:
    UnionFind() = delete;
    UnionFind(uint size) : par(size), sizes(size, 1){
        for(uint i = 0; i < size; ++i) par[i] = i;
    }

    bool unite(uint x, uint y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        
        if(sizes[x] < sizes[y]) std::swap(x, y);
        if(sizes[x] == sizes[y] && x > y) std::swap(x, y);
        sizes[x] += sizes[y];
        sizes[y] = 0;
        par[y] = x;
        return true;
    }
    bool isSame(uint x, uint y ){ return find(par[x]) == find(par[y]);}
    uint getSize(uint x){return find(sizes[par[x]]);}
}; 

vector<vector<int>> dist(201,vector<int>(201,1e9));
void Warshall_floyd(int& V){
    for(int mid=0;mid<V;++mid){
        for(int s=0;s<V;++s){
            for(int e=0;e<V;++e){
                if(dist[s][mid] == 1e9 || dist[mid][e] == 1e9) continue;
                dist[s][e] = min(dist[s][e],dist[s][mid] + dist[mid][e]);
                //cout << s << " " << e << " " << dist[s][e] << endl;
            }
        }
    } 
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    vector<string> E(N);
    bool loop = false;
    for(int i=0;i<N;i++){
        string S;
        cin >> S;
        E[i] = S;
        for(int j=0;j<N;j++){
            int s = S[j] - '0';
            if(s){
                if(i == j) loop = true;
                G[i].emplace_back(j);
                dist[i][j] = 1;
            }
        }
    }

    if(loop){
        cout << -1 << endl;
        return 0;
    }

    Warshall_floyd(N);
    auto bfs = [&](int u){
        int ans = 0;
        UnionFind uf(2*N);
        for(int i=0;i<N;i++){
            uf.unite(dist[u][i], i+N);
            ans = max(ans, dist[u][i]);
        }
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                if(E[i][j] == '1' && uf.isSame(i+N, j+N)){
                    return -1;
                }
            }
        }
        if(N == 2) ans = 1;
        return ans+1;
    };

    int res = -1;
    for(int i=0;i<N;i++){
        res = max(res, bfs(i));
    }
    cout << res << endl;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, m, mid, minv, man;
  cin >> n >> m;
  vecll a(n), b(n), c(m), d(m);
  forll(i, 0, n)
	cin >> a[i] >> b[i];
  forll(i, 0, m)
	cin >> c[i] >> d[i];
  forll(i, 0, n){
	minv = LLONG_MAX;
	forll(j, 0, m){
	  man = abs(a[i] - c[j]) + abs(b[i] - d[j]);
	  if (minv > man){
		minv = man;
		mid = j + 1;
	  }
	}
	cout << mid << endl;
  }
}

Measured memory_bytes: 256
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        a, b = b, a % b
    return a

def gcd_from_list(vals):
    return reduce(gcd, vals)

n, x = map(int, input().split())
c = [abs(x - xn) for xn in map(int, input().split())]
print(gcd_from_list(c))



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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
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 main():
    rr = []

    def f(n,m,c):
        e = collections.defaultdict(list)
        for _ in range(m):
            a,b,d = LI()
            e[a].append((b,d))

        def search(s):
            d = collections.defaultdict(lambda: inf)
            s = (0, s)
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            r = inf
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                v[u] = True
                cc, uu = u
                if uu == n and r > cc:
                    r = cc
                if cc >= r:
                    continue

                for uv, ud in e[uu]:
                    if k + ud <= c:
                        vv = (cc, uv)
                        vd = k + ud
                        if not v[vv] and d[vv] > vd:
                            d[vv] = vd
                            heapq.heappush(q, (vd, vv))
                    if cc < r:
                        vv = (cc+1, uv)
                        vd = k
                        if not v[vv] and d[vv] > vd:
                            d[vv] = vd
                            heapq.heappush(q, (vd, vv))

            return r
        r = search(1)
        return r

    while 1:
        n,m,c = LI()
        if n == 0:
            break
        rr.append(f(n,m,c))

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 10108
#include <stdio.h>
#include <string.h>

int main()
{
    char str[128];
    long long k;
    long long i;

    scanf("%s", str);
    scanf("%lld", &k);

    i = 0;
    while (str[i] == '1' && i < k - 1) i++;

    printf("%c\n" ,str[i]);

    return 0;
}


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

long long gcd(long long a, long long b)
{
	long long tmp;
	while(b!=0)
	{
		tmp=b;
		b=a%b;
		a=tmp;
	}
	return a;
}

int main(void)
{
	long long a, b;
	while(cin >> a >> b)
	{
		long long Gcd=gcd(a,b);
		cout << Gcd << ' ' << a*b/Gcd << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

	int c[2000][2000] = {{0}};
int maximumRectangule(int h, int w, char m[2000][2000]){
	rep(i,w){
		int cnt = 0;
		rep(j,h){
			if(m[j][i] == '.'){
				cnt++;
				c[j][i] = cnt;
			}else{
				cnt = 0;
			}
		}
	}
	rep(i,h) c[i][w] = 0;

	int ans = 0;
	rep(i,h){
		vector<pair<int, int>> v; //height, pos
		rep(j,w + 1){
			if(v.empty()) v.emplace_back(c[i][j],j);
			else{
				if(v.back().first < c[i][j]) v.emplace_back(c[i][j],j);
				else{
					int target = j;
					while(not v.empty() && v.back().first >= c[i][j]){
						ans = max(ans, v.back().first * (j - v.back().second));
						target = v.back().second;
						v.pop_back();
					}
					v.emplace_back(c[i][j],target);
				}
			}
		}
	}
	return ans;
}

int main(){
	int h, w;
	cin >> h >> w;

	char m[2000][2000];
	rep(i,h){
		rep(j,w){
			int a;
			cin >> a;
			if(a) m[i][j] = '#';
			else m[i][j] = '.';
		}
	}
	cout << maximumRectangule(h,w,m) << endl;
}

Measured memory_bytes: 14816
Scanf.scanf "%d" (fun n ->
    let w = Array.init n (fun _ -> Scanf.scanf " %s" (fun w -> w)) in
    let module S = Set.Make (struct type t = string let compare = compare end) in
    let rec loop i prev set =
        if i = n then "Yes" else
            let k = String.length prev in
            if S.mem w.(i) set || prev.[k - 1] <> w.(i).[0] then "No"
            else loop (i + 1) w.(i) (S.add w.(i) set)
    in
    loop 1 w.(0) (S.singleton w.(0)) |> print_endline
)

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
string cnv(int a){
    string str;
    while(a){
        char c=a%10+'0';
        a/=10;
        str=c+str;
    }
    return str;
}
int main(){
    int n;
    string s;
    while(cin>>n,n){
        cin>>s;
        while(n--){
            string t;
            char c=s[0];
            int cnt=1;
            for(int i=1;i<s.length();i++){
                if(s[i]==c)cnt++;
                else{
                    t+=cnv(cnt)+c;
                    cnt=1;
                    c=s[i];
                }
            }
            t+=cnv(cnt)+c;
            s=t;
        }
        cout<<s<<endl;
    }
}

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

vector <int> a, b, c;
long long x, y, n, ans;

int main () {
	cin>>n;
	
	
	for(int i=0; i<n; i++){
		cin>>x;
		a.push_back(x);
	}
	for(int i=0; i<n; i++){
		cin>>x;
		b.push_back(x);
	}
	for(int i=0; i<n; i++){
		cin>>x;
		c.push_back(x);
	}
	sort(a.begin(), a.end());
	sort(c.begin(), c.end());
	
	for(int i=0; i<n; i++){
		x=(lower_bound(a.begin(), a.end(), b[i])-a.begin());
		y=(c.end()-upper_bound(c.begin(), c.end(), b[i]));
		
		ans+=x*y;
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 4704
n = gets.to_i
name = gets.chomp
count = 0
n.times{
	str = gets.chomp
	(0..str.size-name.size).each{|i|
		next if str[i] != name[0]
		ok = false
		k = 1
		loop {
			break if i + k * (name.size-1) >= str.size
			if (1..name.size-1).all?{|j| str[i + k * j] == name[j]}
				ok = true
				break
			end	
			k += 1
		}
		if ok
			count += 1
			break
		end
	}
}
p count

Measured memory_bytes: 6108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 入力
		int k = sc.nextInt();
		String s = sc.next();
		if(k >= s.length()) {
			System.out.println(s);
		}else{
			 String s1 = new String(s);
			String s2  = s1.substring(0,k);
			System.out.println(s2 + "...");
		}
		sc.close();
	}
}


Measured memory_bytes: 38588
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;


int gcd2(int a,int b)
{
    if(a==0)
    return b;
    else
    return gcd2(b%a,a);
}

int gcd(int a,int b,int c)
{
    return gcd2(a,gcd2(b,c));
}

int main() {
	// your code goes here
	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
	    for(int j=1;j<=n;j++)
	    {
	        for(int k=1;k<=n;k++)
	        sum+=gcd(i,j,k);
	    }
	}
	cout<<sum;
	
	
	return 0;
}


Measured memory_bytes: 3596
#Warshall Floyd
N, M = map(int, input().split())
d = [[float('inf')]*N for _ in range(N)]
for i in range(M): #ひとまず枝があるペアは枝の長さをセット
    a,b,t = map(int, input().split())
    d[a][b] = t

for i in range(N):
    d[i][i] = 0 #自身への最短経路は0
#三重ループ
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])
            if i==j and d[i][i]<0:
                print('NEGATIVE CYCLE')
                exit()

for i in range(N):
    ans = []
    for j in range(N):
        if d[i][j]==float('inf'):
            ans.append('INF')
        else:
            ans.append(str(d[i][j]))
    print(' '.join(ans))



Measured memory_bytes: 6012
use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input! {
        n: usize,
        mut stones: String,
    }

    let red_count = stones.chars().filter(|s| *s == 'R').count();

    let mut count = 0;
    let c: Vec<char> = stones.chars().collect();
    for i in 0..red_count {
        if c[i] == 'W' {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 3196
N = int(input())
q = [sorted(list(map(int, input().split()))) for _ in range(N-1)]

ans = 0

# 頂点数
for i in range(1, N+1):
    ans += i * (N - i + 1)

# 辺数
for qi in q:
    u, v = qi[0], qi[1]
    ans -= u * (N - v + 1)

print(ans)


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

#define sc scanf
#define pf printf
#define CIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ull unsigned long long int
#define ll  long long int
#define db double
#define fl float
#define vi vector<int>
#define vl vector<ll>
#define qin queue<int>
#define pb push_back
#define pob pop_back
#define ft front
#define bk back
#define mp make_pair
#define pii pair<int,int>
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define pll __builtin_popcountll
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())


int main()
{
    CIN;

    ll n;
    cin>>n;

    vl v(n+1,0);

    for(ll i=1;i<=n;i++)
    {
        for(ll j=0;j<=n;j+=i)
            v[j]++;
    }

    ll ans=0;

    for(ll i=1;i<=n;i++)
        ans+=(i*v[i]);

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 81296
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),x(n);
    ll total = 0,odd = 0;

    rep(i,n){ 
        cin >> a[i];
        if((i+1) % 2 == 1) odd += a[i];
        total += a[i];
    }

    total /= 2;
    x[0] = (odd - total);
    reps(i,1,n-1){
        x[i] = (a[i-1] - x[i-1]);
        
    }

    x[n-1] = a[n-1] - x[0];

    rep(i,n){
        cout << 2*x[i] << " ";
    }
    cout << endl;

    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s; cin >> s;
	bool res = true;
	FOR(i,0,sz(s)) {
		if (i%2 == 0 && s[i] == 'L') res = false;
		if (i%2 == 1 && s[i] == 'R') res = false;
	}
	cout << (res ? "Yes" : "No") << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 1e6 + 10 , mod = 1e9 + 7;
int fac[maxn] , inv[maxn] , ifac[maxn];
int n;
void init(){
	fac[0] = fac[1] = 1;
	for(int i = 2 ; i <= 1000000 ; ++ i)
		fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[0] = inv[1] = 1;
	for(int i = 2 ; i <= 1000000 ; ++ i)
		inv[i] = mod - 1ll * (mod / i) * inv[mod % i] % mod;
	ifac[0] = 1;
	for(int i = 1 ; i <= 1000000 ; ++ i)
		ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
}
int C(int x , int y){
	if(x < y) return 0;
	return 1ll * fac[x] * ifac[x - y] % mod * ifac[y] % mod;
}
int main(){
	ios::sync_with_stdio(0);
	cin >> n;
	n --;
	init();
	int ans = 0;
	int last = 0;
	for(int i = n - 1 ; i >= 0 ; -- i){
		int cur = 1ll * C(n - i - 1 , i) * fac[i] % mod * fac[n - i] % mod;
		ans = (ans + 1ll * (cur + mod - last) * (n - i) % mod) % mod;
		last = cur;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12032
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Map<Long,Long> map = new TreeMap<>();
        long ans  = 0;

        for(int i = 0;i < n;i++){
            long cost = sc.nextLong();
            long num = sc.nextLong();
            if(map.containsKey(cost)){
                map.put(cost,map.get(cost)+num);
            }else{
                map.put(cost,num);
            }
        }
        for(long i:map.keySet()) {
			if(m<=map.get(i)) {
				ans+=i*m;
				break;
			}else {
				m-=map.get(i);
				ans+=i*map.get(i);
			}
		}
        System.out.println(ans);
    }
}


Measured memory_bytes: 98636
#include <iostream>
#include<vector>
#include<queue>
#include<list>
#include<algorithm>
using namespace std;
static const int MAX=100000;
static const int INFTY=(1<<29);
vector<int>G[MAX];
list<int>out;
bool V[MAX];
int N;
int indeg[MAX];
void bfs(int u)
{
    queue<int>q;
    q.push(u);
    V[u]=true;
    while(!q.empty())
    {
        int v=q.front();
        q.pop();
        out.push_back(v);
        for(int i=0; i<G[v].size(); i++)
        {
            int u=G[v][i];
            indeg[u]--;
            if(indeg[u]==0&&!V[u])
            {
                q.push(u);
                V[u]=true;
            }
        }
    }
}
void tsort()
{
    for(int i=0; i<N; i++)
    {
        V[i]=false;
        indeg[i]=0;
    }
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<G[i].size(); j++)
        {
            int v=G[i][j];
            indeg[v]++;
        }
    }
    for(int u=0; u<N; u++)
        if(indeg[u]==0&&!V[u])bfs(u);
    for(list<int>::iterator it=out.begin(); it!=out.end(); it++)
    {
        cout<<*it<<endl;
    }
}
int main()
{
    int e,v,c;
    cin>>N>>e;
    for(int i=0; i<e; i++)
    {
        cin>>v>>c;
        G[v].push_back(c);
    }
    tsort();
    return 0;

}

Measured memory_bytes: 6224
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n, k,i,tmp,j,sum=0;

        n = sc.nextInt();
        k = sc.nextInt();

        int p[] = new int[n];

        for (i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }

        for (i = 0; i < n - 1; i++) {
            for (j = i + 1; j < n; j++) {
                if (p[i] > p[j]) {
                    tmp = p[i];
                    p[i] = p[j];
                    p[j] = tmp;
                }
            }
        }
        for (i = 0; i < k; i++) {
            sum += p[i];
        }
        System.out.println(sum);
    }

}

Measured memory_bytes: 38920
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
//const int mod = 1000000007;
const int mod = 998244353;
 

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);
 
// M * (M-1)^(N-1-K) * N-1 C K
int main(int argc, const char * argv[]) {
    ll N,M,K; cin >> N >> M >> K;
    
    mint ans = 0;
    mint col = M;
    
    
    
    for(ll x=N-1; x>=0 ; x--){
        if(x<=K){
            ans += col * c(N-1,x);
        }
        col *= (M-1);
    }
    
    cout << ans << endl;
    
    
}



Measured memory_bytes: 6232
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <assert.h>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>                                    
#include <deque>                                    
#include <queue>
#include <iomanip>
#include <ctime>
#include <random>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;

 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

string s;
int sum;
 
inline void boost () {
   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
}

inline void Solve () {
   cin >> s;
   for (int i = 0; i < sz (s); i ++)
      sum += s[i] - '0';
   cout << (sum % 9 == 0 ? "Yes" : "No");
}               
 
signed main () {                                       
  // #ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                 


Measured memory_bytes: 3768
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX_N = 100100;

struct Edge {
    int to; 
    ll cost;
    Edge(int to, ll cost) : to(to), cost(cost) {};
}; 
vector<Edge> G[MAX_N];
vector<int> color(MAX_N, 0); // 初期値: 0, 二色: -1, +1

void dfs(int v, int c) {
    color[v] = c;
    for(int i = 0; i < (int)G[v].size(); ++i) // 頂点vから出る辺を走査
    {
        if(color[G[v][i].to] == 0) 
        {
            if (G[v][i].cost % 2 != 0) 
            {
                dfs(G[v][i].to, -c);
            }
            else
            {
                dfs(G[v][i].to, c);
            }
        }
    }
}

int main() {

    int N; cin >> N; 
    for (int i = 0; i < N-1; ++i) {
        int a,b; cin>>a>>b;
        a--;
        b--;
        ll cost; cin >> cost;
        G[a].push_back(Edge(b,cost));
        G[b].push_back(Edge(a,cost));
    }

    dfs(0, 1);

    for (int i = 0; i < N; i++)
    {
        if (color[i] == 1) 
        {
            cout << 0 << endl;
        }
        else
        {
            cout << 1 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll read() {
	ll x=0, f=1; char ch=' ';
	while(!isdigit(ch)) {ch=getchar(); if(ch=='-') f=-1;}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x*f;
}
int a, b, c;
int main() {
	cin>>a>>b>>c;
	if(b*c>=a) cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; ++1)
using namespace std;
int main(){
int S;
cin >> S;
cout << S/3600 <<":"<< (S%3600)/60<<":" << (S%3600)%60 <<endl;
return 0;
}


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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long N=sc.nextInt();
        long M=sc.nextInt();
        if(N==1){
            N=1;
        }else{
            N=N-2;
        }
        if(M==1){
            M=1;
        }else{
            M=M-2;
        }
        System.out.println(N*M);
    }

}


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

int main()
{
    string s;
    cin >> s;
    int num = 0;
    rep(i, s.size()) {
        if(s[i] == 'o') num++;
    }
    if(num + 15 - s.size() >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
   
    ll n,i;
    cin>>n;
    ll ans =0 ;
    for(i=1;i<=n;i++)
    {
    	if(i%3!=0 and i%5!=0) ans += i;
    }
    cout<<ans;
}

Measured memory_bytes: 3652
/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
void solve() {
    char a;
    cin >> a;
    if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') {
        cout << "vowel" << endl;
    } else cout << "consonant" << endl;
}
int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  int N;
  ins(N);

  vi A(N);
  rep(i, N) {
    cin >> A[i];
  }
  all(sort, A);

  vector<bool> ok(1e6 + 1, true);

  int ans = 0;
  rep(i, N) {
    if (all(upper_bound, A, A[i])-all(lower_bound, A, A[i]) > 1) {
      if (ok[A[i]]) {
        ok[A[i]] = false;
        for (int x = 2*A[i]; x <= 1e6; x += A[i]) {
          ok[x] = false;
        }
      }
      continue;
    }
    if (!ok[A[i]])
      continue;
    ++ans;
    for (int x = 2*A[i]; x <= 1e6; x += A[i]) {
      ok[x] = false;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4048
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root,*NIL;

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL){
    y = x;
    if( z->key < x->key ){
      x = x->left;
    }else {
      x = x->right;
    }
  }

  z->parent = y;
  if( y == NIL ){
    root = z;
  } else {
    if ( z->key < y->key ){
      y->left = z;
    }else{
     y->right = z;
    }
  }
}

void inorder(Node *u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u){
  if ( u == NIL)return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n);

  for( i = 0; i < n; i++){
    cin >> com;
    if(com == "insert"){
      scanf("%d", &x);
      insert(x);
    } else if( com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 26688
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>

using namespace std;

#define mod (1e9 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

typedef long long ll;

void solve1()
{
   string s; cin >> s;
   int ans = 1000000000;
   string n = "753";
   int nn = (n[0] - '0') * 100 + (n[1] - '0') * 10 + (n[2] - '0');
   for(int i = 0; i < s.size() - 2; i++) {
      string m;
      for(int j = 0; j < 3; j++) {
         m.push_back(s[i+j]);
      }

      int mm = (m[0] - '0') * 100 + (m[1] - '0') * 10 + (m[2] - '0');
      ans = min(ans, abs(mm - nn));
   }

   cout << ans << endl;
}

int main()
{
   solve1();
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

int main(){
	int n,d;
	cin >> n >> d;
	int x[10][10];

	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin >> x[i][j];
		}
	}
	int ans = 0;

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int d2 = 0;
			for(int k=0;k<d;k++){
				d2 += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			for(int l=0;l<1000;l++){
				if(d2==l*l) ans++;
			}
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
void slove(int question_num)
{
    while(question_num--)
    {
        int a,b;cin>>a>>b;
        if(a<10&&b<10)
            cout<<a*b<<endl;
        else cout<<-1<<endl;
    }
}
int main()
{
//    int t;cin>>t;
    slove(1);
    return 0;
}


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

void solve() {
    int n;
    std::cin >> n;

    std::vector<std::pair<int, int>> ps(n);
    for (auto& [x, y] : ps) {
        std::cin >> x >> y;
        --x;
        y = n - y;
    }

    std::vector<int> is(n);
    std::iota(is.begin(), is.end(), 0);
    std::sort(is.begin(), is.end(),
              [&](int i, int j) { return ps[i] < ps[j]; });

    int pmax = -1, max = 0, cnt = 0;
    std::vector<int> ans(n);
    for (int l = 0; l < n; ++l) {
        ++cnt;
        max = std::max(max, ps[is[l]].second);
        if (max - pmax == cnt) {
            for (int i = 0; i < cnt; ++i) ans[is[l - i]] = cnt;
            pmax = max;
            max = 0;
            cnt = 0;
        }
    }

    for (auto a : ans) std::cout << a << "\n";
}

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

    solve();

    return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, m;
    cin >> n >> m;

    vector<pair<int, int>> ans;
    int M = (n + 1) / 2 + 1;
    int i = 1;
    while (i < M - i) {
        ans.emplace_back(i, M - i);
        ++i;
    }

    i = 0;
    int E = n & 1 ? n : n - 1;
    while (M + i < E - i) {
        ans.emplace_back(M + i, E - i);
        ++i;
    }
    rep(i, 0, m) { cout << ans[i].first << " " << ans[i].second << endl; }

    return 0;
}

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

using namespace std;

int main(){
  long long n, a[200009];
  cin >> n;
  for(int i=1;i<=n;i++)cin >> a[i];
  map<long long, long long> memo;
  long long cnt=0;
  for(int i=1;i<=n;i++){
    cnt += memo[i-a[i]];
    memo[a[i]+i]++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 27832
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<pair<int64_t,int64_t>>A(N);
  for(int i=0;i<N;i++){
  int64_t x,y;
    cin>>x>>y;
    pair<int64_t,int64_t>p(x,y);
    A.at(i)=p;
  }map<pair<int64_t,int64_t>,int>M;
  for(int i=0;i<N-1;i++){
  for(int j=i+1;j<N;j++){
    int64_t x1,y1,x2,y2;
    x1=A.at(i).first-A.at(j).first;
    x2=A.at(j).first-A.at(i).first;
    y1=A.at(i).second-A.at(j).second;
    y2=A.at(j).second-A.at(i).second;
    pair<int64_t,int64_t>p1(x1,y1);
    pair<int64_t,int64_t>p2(x2,y2);
    if(M.count(p1))
      M.at(p1)++;
    else
      M[p1]=1;
    if(M.count(p2))
      M.at(p2)++;
    else
      M[p2]=1;
    
  }
  }int ans=0;
  for(auto p:M){
  auto k=p.first;
    auto v=p.second;
    if(ans<v)
      ans=v;
  }cout<<N-ans<<endl;
   return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>  // This will work only for g++ compiler.
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define tree_set tree<int, null_type,greater<int>, rb_tree_tag,tree_order_statistics_node_update>
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define FASTIO ios::sync_with_stdio(false); cin.tie(0); //for faster IO

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second


// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin(), (x).rend() //reverse traversal


// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)


// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())


//find version works for all containers. This is present in std namespace
#define cpresent(c,x) (find(all(c),x) != (c).end())


// Avoiding wrap around of size()-1 where size is a unsigned int.
#define size(a) int((a).size())


using namespace std;
using namespace __gnu_pbds;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;


const ll INF = 1e18+7;


const int M = 1e9+7;

ll mod(ll x){
    return ((x%M + M)%M);
}

ll add(ll a, ll b){
    return mod(mod(a)+mod(b));
}

ll mul(ll a, ll b){
    return mod(mod(a)*mod(b));
}

ll minu(ll a, ll b){
    return mod(mod(a)-mod(b));
}

ll modPow(ll a,ll b){
    if(b==0)
        return 1LL;
    if(b==1)
        return a%M;
    ll res=1;
    while(b){
        if(b%2==1)
            res=mul(res,a);
        a=mul(a,a);
        b=b/2;
    }
    return res;
}

void solve(){
    int n;
    cin>>n;
    vi sum(n),diff(n);
    for0(i,n){
        int temp1,temp2;
        cin>>temp1>>temp2;
        sum[i]=temp1+temp2;
        diff[i]=temp1-temp2;
    }
    sort(all(diff));
    sort(all(sum));
    cout<<max(abs(sum[0]-sum[size(sum)-1]),abs(diff[0]-diff[size(diff)-1]))<<"\n";
}


int main() {
    FASTIO
    cout.precision(10);
    cout << fixed;
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 4720
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o C.exe C.cpp 
Execute: ./C
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	int x, y, z, n, f[10001]={0}, w;
	
	cin >> n; 
	for(int x = 1; x <= 100; x++) {
		for(int y = 1; y <= 100; y++) {
			for(int z = 1; z <= 100; z++) {
				w = x*x + y*y + z*z + x*y + y*z + z*x; 
				if(w <= n)
					f[w]++; 
			}
		}
	}
	
	for(int i = 1; i <= n; i++) 
		cout << f[i] << endl; 
	
	return 0; 
} 


Measured memory_bytes: 3624
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    l = [1] * N
    for i in range(M):
        if H[A[i]] >= H[B[i]]:
            l[B[i]] = 0
        if H[A[i]] <= H[B[i]]:
            l[A[i]] = 0
    print(l.count(1))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens)) - 1
        B[i] = int(next(tokens)) - 1
    solve(N, M, H, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81424
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


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

int main()
{
    ll A;
    string B;
    cin >> A >> B;

    int B_x_100 = (B[0]-'0') * 100 + (B[2]-'0') * 10 + (B[3]-'0');
    ll ans = A * B_x_100 / 100;

    cout << ans << endl;
}

Measured memory_bytes: 3596