akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
#include <math.h>

using namespace std;
typedef long long ll;
///定義場所///
int i, j, k, l, m, n;
int N, M, K, H, W;
ll MOD = 1000000007;
int ans = 0;
//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<int ,int> firstElof, pair<int,int> secondElof)
{
	return firstElof.second > secondElof.second;
}
int Keta(ll F) {
	int keta = 1;
	while (F/10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
//////////////

int main()
{
	cin >> N >> K;
	if (K == 1) {
		cout << 0;
	}
	else {
		cout << (N - K + 1) - 1;
	}
}

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

terms = [@a[0]]

(1...(@a.length)).each do |i|
  terms << @a[i] - @a[i-1]
end

terms = terms + [@k - @a[-1] + @a[0]]
#pp terms

#terms = terms + [@k - @a[-1] ] + terms[1,terms.length-1] * 10
#
#n = @n-1
#dl = terms[1, n].reduce(0, :+)
#min = dl
#(1...(@a.length)).each do |i|
#  dl = dl - terms[i] + terms[i + n]
#  min = dl if dl < min
#end
#
#puts min
#
puts @k - terms.max


Measured memory_bytes: 18564
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

c = [0] * 8
w = 0

n.times do |i|
  if a[i] >= 3200 then
    w += 1
  else
    c[ a[i] / 400 ] += 1
  end
end

d = 0
8.times do |i|
  if c[i] > 0 then
    d += 1
  end
end

puts [[d, 1].max, d + w].map(&:to_s).join(' ')

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

int main(){
    int ans=0;
    string S;
    cin>>S;
    for (int i=0;i<S.size();i++){
        if (S.at(i)!=S.at(S.size()-i-1)){
            S.at(i)=S.at(S.size()-i-1);
            ++ans;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val s  = sc.next

  val alphabet = "abcdefghijklmnopqrstuvwxyz"
  val nextAlphabet = "bcdefghijklmnopqrstuvwxyza"

  val res = nextAlphabet.charAt(alphabet.indexOf(s))

  println(res)


}

Measured memory_bytes: 25800
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n;
        cin >> n;

        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            cnt += n / i;
            if (n % i == 0)
                cnt--;
        }
        cout << cnt << '\n';
    }
    
    return 0;
}



Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define uint unsigned int
#define FOR(a,b,i) for(register int i=a;i<b;++i)

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x;
    y = (x / 100) * 111;
    if (y < x) y += 111;
    cout << y;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        ll n,a1=0,t1=0;
        cin>>n;
        vector<ll> a(n),t(n);
        for(int i=0;i<n;i++)
        cin>>t[i]>>a[i];
        t1=t[0],a1=a[0];
        for(int i=1;i<n;i++)
        {
            if(a[i]>a1&&t[i]>t1)
            {
                a1=a[i];
                t1=t[i];
            }
            else if(a[i]>a1)
            {
                if(t1%t[i])
                {
                    a1=a[i]*(t1/t[i])+a[i];
                    t1=t[i]*(t1/t[i])+t[i];
                }
                else
                {
                    a1=a[i]*(t1/t[i]);
                    t1=t[i]*(t1/t[i]);
                }
            }
            else if(t[i]>t1)
            {
                if(a1%a[i])
                {
                    t1=t[i]*(a1/a[i])+t[i];
                    a1=a[i]*(a1/a[i])+a[i];
                }
                else
                {
                    t1=t[i]*(a1/a[i]);
                    a1=a[i]*(a1/a[i]);
                }
            }
            else
            {
                ll x=0;
                if(a1%a[i])
                x=max(x,a1/a[i]+1LL);
                else
                x=max(x,a1/a[i]);
                if(t1%t[i])
                x=max(x,t1/t[i]+1LL);
                else
                x=max(x,t1/t[i]);
                t1=x*t[i];
                a1=x*a[i];
            }
        }
        cout<<t1+a1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(A: int, B: int, C: int, D: int):
    print(max(0, min(B,D)-max(A,C)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int k,x;
  cin>>k>>x;
  for(int i=x-k+1;i<=x+k-1;i++){
    cout<<i<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;

/*----------macros----------*/

//input, output================
#define fastio                          \
std::ios::sync_with_stdio(false);       \
std::cin.tie(nullptr);                  \
std::cout.tie(nullptr)

#define endl '\n'
#define fcout(a)                        \
cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef vector<int>     Vi;
typedef vector<ll>      Vl;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF    = (ll)1e9 + 1;
constexpr ll INFll  = (ll)1e18 + 1;
constexpr ll MOD1   = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define psb push_back
#define epb emplace_back
#define psf push_front
#define mkp make_pair
#define fst first
#define snd second

//others================
#define sz(x)                           \
(int) x.size()

#define all(x)                          \
(x).begin(), (x).end()

#define rall(x)                         \
(x).rbegin(), (x).rend()

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

#define reps(i, n)                      \
for(int i = 1; (i) <= (n); ++(i))

#define rrep(i, n)                      \
for(int i = n - 1; (i) >= 0 ; --(i))

#define repbit(bit, n)                  \
for(int bit = 0; (bit) < (1 << (n)); ++(bit))

#define ifbit(bit, i)                   \
if((bit) & (1 << (i)))

#define CtoI(c)                         \
int((c)) - int('0')

#define ItoC(c)                         \
char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b)
{ return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b)
{ return a > b && (a = b, true); }

// Vi  dx = {1, 0, -1, 0},
//     dy = {0, 1, 0, -1};

// Vi  dx2 = { 1,1,0,-1,-1,-1,0,1 },
//     dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
fastio;

    int a, b; cin >> a >> b;
    --a; --b;
    cout << a * b << endl;

return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

ifstream fin;
ofstream fout;

int main(){
	fin.open("input.txt");
	fout.open("output.txt");

	bool left = false, right = false;//false??§???,true??§????????°

	int n;//input
	int count = 0;
	bool moveflag;
	bool pre,now;//true??§???,false??§???
	bool up, down;//true??§???,false??§???

	string s;
	string gomi;

	while (true){
		//?????????
	pre = false;
		left = right = false;
		count = 0;

		cin >> n;
		if (n == 0)break;
		getline(cin, gomi);//??????
		getline(cin,s);

		for (int i = 0; i < n; i++){//?¶????????????????
			now = false;
			moveflag = false;

			if (s[i * 3] == 'l' && s[i * 3 + 1] == 'u' && left == false)left = true; moveflag = true;
			if (s[i * 3] == 'l' && s[i * 3 + 1] == 'd' && left == true)left = false; moveflag = true; 
			if (s[i * 3] == 'r' && s[i * 3 + 1] == 'u' && right == false)right = true; moveflag = true;
			if (s[i * 3] == 'r' && s[i * 3 + 1] == 'd' && right == true)right = false; moveflag = true;


			if (left == right){
				//now = left == true ? true : false;

				if (left == true)now = true;
				else now = false;

				if (moveflag == true && pre == !now){
					pre = now;
					count++;
				}
			}
		}
		//fout << count;
		cout << count << endl;

	}

	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
struct node {
	int y,c,d;
};
vector<node>T[100001],Q[100001];
int H[100001],F[100001][18],D[100001],C[100001],CD[100001],An[100001];
void dfs(int x,int la,int d) {
	H[x]=H[la]+1,D[x]=d,F[x][0]=la;
	for(int i=0; i<T[x].size(); i++) {
		node nw=T[x][i];
		if(nw.y!=la)dfs(nw.y,x,d+nw.d);
	}
}
void dfs1(int x,int la){
	for(int i=0;i<Q[x].size();i++){
		node nw=Q[x][i];
		if(nw.y>0)An[nw.y]+=D[x]+C[nw.c]*nw.d-CD[nw.c];
		else An[-nw.y]-=2*(D[x]+C[nw.c]*nw.d-CD[nw.c]);
	}
	for(int i=0;i<T[x].size();i++){
		node nw=T[x][i];
		if(nw.y!=la)C[nw.c]++,CD[nw.c]+=nw.d,dfs1(nw.y,x),C[nw.c]--,CD[nw.c]-=nw.d;
	}
}
int LCA(int x,int y) {
	if(H[x]>H[y])swap(x,y);
	int s=H[y]-H[x];
	for(int i=0; i<=17; i++)if(s&(1<<i))y=F[y][i];
	if(x==y)return x;
	for(int i=17; i>=0; i--)if(F[x][i]!=F[y][i])x=F[x][i],y=F[y][i];
	return F[x][0];
}
int main() {
	int a,b,i,j,x,y,c,d;
	cin>>a>>b;
	for(i=1; i<a; i++)scanf("%d%d%d%d",&x,&y,&c,&d),T[x].push_back({y,c,d}),T[y].push_back({x,c,d});
	dfs(1,0,0);
	for(i=1; i<=17; i++)for(j=1; j<=a; j++)F[j][i]=F[F[j][i-1]][i-1];
	for(i=1; i<=b; i++)scanf("%d%d%d%d",&c,&d,&x,&y),Q[x].push_back({i,c,d}),Q[y].push_back({i,c,d}),Q[LCA(x,y)].push_back({-i,c,d});
	dfs1(1,0);
	for(i=1;i<=b;i++)printf("%d\n",An[i]);
}

Measured memory_bytes: 28856
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>;
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }

bool visited[100002];
unordered_set<int> to[100002];
int h[100002];
void dfs(int v, int q=-1) {
    visited[v] = true;
    for(int u: to[v]) {
        if(u==q) continue;
        dfs(u, v);
    }
}
signed main() {
    int n,m;
    cin>>n>>m;
    rep(i,n) cin>>h[i];
    rep(i,m) {
        int a,b;
        cin>>a>>b;
        a--; b--;
        to[a].insert(b);
        to[b].insert(a);
    }
    int ans = 0;
    rep(i,n) {
        bool good = true;
        for(int v : to[i]) {
            if(h[v]>=h[i]) {
                good = false;
                break;
            }
        }
        if(good)
            ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 18920
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import random
def resolve():
    
    S=input()
    A="dream dreamer erase eraser".split()
    #print(A)
    que=[S]
    while(que!=[]):
        t=len(que)
        #print(t)
        vS=que.pop(random.randint(0,t-1))
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])
        #print(que,"k")    

    print("NO")
#%%submit!
resolve()

Measured memory_bytes: 4580
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func bsearch(a []int, t int) int {
	ret := -1
	l, r := 0, len(a)-1
	for l <= r {
		mid := (r + l) / 2
		if a[mid] == t {
			return mid
		} else if a[mid] < t {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return ret
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	S := make([]int, n)
	for i := range S {
		S[i] = nextInt(sc)
	}
	q := nextInt(sc)
	var ans int
	for i := 0; i < q; i++ {
		v := nextInt(sc)
		if bsearch(S, v) >= 0 {
			ans++
		}
	}
	fmt.Println(ans)
}
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}



Measured memory_bytes: 2708
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


int main()
{
    int n;
    cin >> n;
    vector<P>x(n+1);
    rep(i,n){
        int a;
        cin >> x[i+1].first;
        x[i+1].second =i+1;
        
    }
    vector<P> a=x;
    sort(x.begin(),x.end());
    int mid = n/2;
    rep(i,n)
    {
        if(a[i+1].first<=x[mid].first)cout<<x[mid+1].first<<endl;
        else cout<<x[mid].first<<endl;
    }
    return 0;
}

Measured memory_bytes: 8448
import numpy as np

N,M,V,P = map(int,input().split())
A = np.sort(list(map(int,input().split())))[::-1]

Ap = A[P-1]
iOK = P-1
iNG = N
while iOK+1 < iNG:
    x = (iOK+iNG)//2
    if x <= P-1:
        iOK = x
    elif Ap - A[x] > M:
        iNG = x
    elif (P-1)+(N-x) >= V:
        iOK = x
    elif (A[x]+M)*(x-P+1)-np.sum(A[P-1:x]) >= M*(V-P+1-N+x):
        iOK = x
    else:
        iNG = x

ans = iOK + 1
print(ans)

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

const int INF = 100010;

int main() {
    int N;
    cin >> N;
    int B[N+1];
    B[0] = INF;
    B[N] = INF;
    for (int i = 1; i < N; i++) {
        cin >> B[i];
    }

    int res = 0;
    rep(i, N) {
        res += min(B[i], B[i+1]);
    }

    cout << res << endl;

    return 0;
}

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

class Main{
	public static void main(String[] args){
		int i;
		int j;
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String[] C1 = new String[n];
		String[] C2 = new String[n];
		String c;

		for(i=0 ; i<n ; i++){
			c = scan.next();
			C1[i] = c;
			C2[i] = c;
		}

		BubbleSort(C1, n);
		SelectionSort(C2, n);

		StringBuffer sb = new StringBuffer();
		StringBuffer sb2 = new StringBuffer();
		for(i=0 ; i<C1.length-1 ; i++){
			sb.append(C1[i]+" ");
			sb2.append(C2[i]+" ");
		}
		sb.append(C1[i]);
		System.out.println(sb);
		System.out.println("Stable");
		sb2.append(C2[i]);
		System.out.println(sb2);
		if((CheckC(C1, C2)) == true)System.out.println("Stable");
		else System.out.println("Not stable");

	}

 static void BubbleSort(String[] C, int n){
	 int i;
	 int j;
	 String v;

		for(i=0 ; i<n ; i++){
			for(j=n-1 ; j>i ; j--){
				if(C[j].charAt(1) < C[j-1].charAt(1)){
					v = C[j];
					C[j] = C[j-1];
					C[j-1] = v;
				}
			}
		}
}

static void SelectionSort(String[] C, int n){
	int i;
	int j;
	String v;
	int minj;

		for(i =0; i<n; i++){
			minj = i;
			for(j = i; j<n;j++){
				if(C[minj].charAt(1)>C[j].charAt(1))minj =j;
			}
			v = C[minj];
			C[minj] = C[i];
			C[i] = v;
		}
}



static boolean CheckC(String[] C1, String[] C2){
	for(int i=0 ; i<C1.length ; i++){
		if(C2[i] != C1[i])return false;
	}
	return true;
}


}



Measured memory_bytes: 26300
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		(new Solver()).Solve();
	}
}


public class Solver
{
	private int N;
	private long[,] A;

	public Solver()
	{
		N = GetInt();
		A = new long[N, N];
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N; j++)
				A[i, j] = GetLong();
	}

	public void Solve()
	{
		for(int i = 0; i < N; i++)
		{
			for(int j = i + 1; j < N; j++)
			{
				for(int k = 0; k < N; k++)
				{
					if(k == i || k == j)
						continue;
					
					if(A[i, j] > A[i, k] + A[k, j])
					{
						Console.WriteLine(-1);
						return;
					}
				}
			}
		}

		long[,] d = new long[N, N];
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N; j++)
				d[i, j] = A[i, j];

		warshall_floyd(ref d);

		long ans = 0;
		for(int i = 0; i < N; i++)
		{
			for(int j = i + 1; j < N; j++)
			{
				bool flag = true;
				for(int k = 0; k < N; k++)
				{
					if(k == i || k == j)
						continue;
					
					if(d[i, j] == d[i, k] + d[k, j])
					{
						flag = false;
						break;
					}
				}
				if(flag)
					ans += A[i, j];
			}
		}

		Console.WriteLine(ans);
	}

	private static void warshall_floyd(ref long[,] d)
	{
		int V = d.GetLength(0);
		for(int k = 0; k < V; k++)
			for(int i = 0; i < V; i++)
				for(int j = 0; j < V; j++)
					d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 20184
#include "bits/stdc++.h"

using namespace std;
// jebote stupidast
int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    if(a >= n)cout << n;
    else if(a == 0)cout << 0;
    else{
        if(n % (a + b) <= a)
            cout << (n / (a + b)) * a + n % (a + b);
        else cout << (n / (a + b)) * a + a;
    }


	return 0;

}


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

const int maxx=10010;
int n,a[maxx],b[maxx],c[maxx],ans;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	for(int i=1;i<n;i++) scanf("%d",&c[i]);
	for(int i=1;i<=n;i++){
		ans+=b[i];
		if(a[i]==1+a[i-1]) ans+=c[a[i-1]];
	}
	printf("%d",ans);
	return 0;
} 

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

namespace AtCoder
{
    public class ABC_051_B
    {
        public static void Main()
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line, int.Parse);
            var k = a[0];
            var s = a[1];
            var z = 0;
            
            var result = 0;

            for (int i = 0; i <= k; i++)
            {
                for (int j = 0; j <= k; j++)
                {
                    z = s - i  - j ;
                    if (z >= 0 && z <= k)
                    {
                        result++;
                    }

                }
            }
            Console.WriteLine(result);
            Console.Read();
        }

    }
}

Measured memory_bytes: 11220
//#include<bits/stdc++.h> using namespace std;
#include<iostream>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue> //priority_queue inside queue
#include<deque>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
#define f(i,start,end) for(i=start;i<=end;i++)
#define min_heap priority_queue<int, vector<int>, greater<int> >
#define max_heap priority_queue<int>

bool isPrime(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        if(n%i==0) return false;
    }
    return true;
} //returns true if prime!


int main()
{
    fast;
//int t=0,tc=0; cin >> tc; f(t,1,tc) //testcases
    {
        int n; cin >> n;
        int a,b; cin >> a >> b;
        for(int i=a; i<=b; i++)
        {
            if(i%n==0){ cout << "OK"; return 0; }
        }
        cout << "NG";
    }
    return 0;
}
    

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b > c+d) {
    cout << "Left";
  }
  else if (a+b < c+d) {
    cout << "Right";
  }
  else{
    cout << "Balanced";
  }
}

Measured memory_bytes: 256
// サイコロを指示に従って転がし、終了時のtopの数字を出力
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n != 0) solve(n);
	}
    }

    static void solve(int n){
	DiceR dice = new DiceR();
	while(n>0){
	    String order = kbd.next();
	    dice.rollO(order);
	    n--;
	}
	System.out.println(dice.getTop());
    }
}

class DiceR{
    int[] dice;
    public DiceR(){
	dice = new int[]{1, 2, 3, 6, 5, 4};
	// top, north, west, bottom, south, east
	//  0     1     2      3       4     5
    }

    public void rollO(String order){
	if(order.equals("north")){
	    roll(dice, 1, 0, 4, 3);
	}
	else if(order.equals("south")){
	    roll(dice, 4, 0, 1, 3);
	}
	else if(order.equals("east")){
	    roll(dice, 5, 0, 2, 3);
	}
	else if(order.equals("west")){
	    roll(dice, 2, 0, 5, 3);
	}
    }

    private void roll(int[] dice, int a, int b, int c, int d){
	// 引数を左に一つずらす。
	int p = dice[a];
	dice[a] = dice[b];
	dice[b] = dice[c];
	dice[c] = dice[d];
	dice[d] = p;
    }

    public int getTop(){ return dice[0]; }
}

Measured memory_bytes: 19356
n = int(input())
s = input()

rc = s.count('R')
gc = s.count('G')
bc = s.count('B')

ans = rc*gc*bc

for i in range(n):
    if s[i] == 'R':
        for j in range(1,min(n-i-1, i)+1):
            if s[i-j] != s[i+j] and s[i-j] != 'R' and s[i+j] != 'R':
                ans -= 1
        for j in range(1,int((n-i-1)/2)+1):
            if s[i+2*j] != s[i+j] and s[i+2*j] != 'R' and s[i+j] != 'R':
                ans -= 1
        for j in range(1,int(i/2)+1):
            if s[i-j] != s[i-2*j] and s[i-j] != 'R' and s[i-2*j] != 'R':
                ans -= 1

print(ans)

Measured memory_bytes: 9248
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s, t;
    cin >> s >> t;
    ll a, b;
    cin >> a >> b;
    string u;
    cin >> u;

    if(s == u) {
        a--;
    }
    else if(t == u) {
        b--;
    }
    
    cout << a << " " << b << endl;
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)

signed main(){
    int s, w;
    cin >> s >> w;
    if(s>w) cout << "safe" << endl;
    else cout << "unsafe" << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main (void)
{
  int a,aa,aaa,b,bb,bbb,T,TT,TTT;
  for (int i = 0; i < 3; i++)
     {
	  cin >> a >> aa >> aaa >> b >> bb >> bbb;
	  if (aaa > bbb)
	  {
		  if (aa < bb)
		  {
		    bb--;
		    bbb += 60;

	      }
		  else if (aa >= bb)
		  {
			  bb--;
			  bbb += 60;
			  b--;
			  bb += 60;
		  }
	  }
	  else if (aaa <= bbb)
	  {
		  if (aa <= bb)
		  {
		  }
		  else if (aa > bb)
		  {
			  b--;
			  bb += 60;
		  }
	  }

		  T = b - a;
		  TT = bb - aa;
		  TTT = bbb - aaa;
		  cout << T << " " << TT << " " << TTT << endl;
	  }
}

Measured memory_bytes: 3096
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
int main(void){
	while(1){
		bool flag=false;
		int d,w;
		int outline=INF;
		int maxi=0;
		int tmp=0;
		int e[11][11];

		cin>>d>>w;
		if(d==0&&w==0){
			break;
		}
		FOR(i,1,d){
			FOR(j,1,w){
				cin>>e[i][j];
			}
		}

		FOR(xf,1,w-2){
			FOR(yf,1,d-2){
				FOR(xe,xf+2,w){
					FOR(ye,yf+2,d){
						outline=INF;
						FOR(x,xf,xe){
							outline=min(outline,min(e[yf][x],e[ye][x]));
						}
						FOR(y,yf,ye){
							outline=min(outline,min(e[y][xf],e[y][xe]));
						}

						tmp=0;
						flag=false;
						FOR(x,xf+1,xe-1){
							FOR(y,yf+1,ye-1){
								if(e[y][x]<outline){
									tmp+=(outline-e[y][x]);
								}else{
									tmp=0;
									flag=true;
									break;
								}
							}
							if(flag){
								break;
							}
						}

						//cout<<xf<<" "<<xe<<" "<<yf<<" "<<ye<<" "<<tmp<<endl;

						maxi=max(maxi,tmp);

					}
				}
			}
		}

		cout<<maxi<<endl;

	}

}


Measured memory_bytes: 3108
#include<cstdio>
#include<algorithm> 
#include<set>
typedef long long ll;
const int N=500,vx[4]={-1,0,0,1},vy[4]={0,-1,1,0};
int X=14414400;//245044800;
ll a[510][510];
std::set<ll>S;
int d[510],dc,p[510];
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
	for(int i=1;dc<500;i++)if(X%i==0)d[dc++]=i;
	int pl=0,pr=249;
	for(int i=17,ty=0,cnt=0;cnt<250;i+=2){
		if(i%2!=0&&i%3!=0&&i%5!=0&&i%7!=0&&i%11!=0&&i%13!=0&&i%17!=0)cnt++%2?p[pr]=i,pr-=2:(p[pl]=i,pl+=2);
	}
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++){
			if((i+j)%2==0)S.insert(a[i][j]=1ll*d[j]*p[i/2]);
		}
		ll mx=0;
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++){
			if((i+j)%2==1){
				ll L=1;
				for(int d=0,dx,dy;d<4;d++)if((dx=i+vx[d])>=0&&dx<N&&(dy=j+vy[d])>=0&&dy<N)L=lcm(L,a[dx][dy]);
				for(a[i][j]=L+1;S.find(a[i][j])!=S.end();a[i][j]+=L);
				S.insert(a[i][j]);
				if(a[i][j]>mx)mx=a[i][j];
			}
		}
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)printf("%lld%c",a[i][j]," \n"[j==n-1]);
}

Measured memory_bytes: 16640
import math

n = int(input())
dL = [list(map(int, input().split(" "))) for _ in range(n)]

cnt = 0
for d in dL:
    if d[0] == d[1]:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 62644
using System;
using static System.Console;
using System.Collections.Generic;

namespace abc179
{
    class Program
    {
        static void Main()
        {
            var nq = ReadNumList();
            var n = nq[0];
            var q = nq[1];
            var queries = new int[q][];
            for (var i = 0; i < q; ++i)
            {
                queries[i] = ReadNumList();
            }
            WriteLine(SR(n, queries));
        }
        static long SR(int n, int[][] queries)
        {
            var black = (long)(n - 2) * (n - 2);
            var vertMemo = new SortedList<int, int>();
            var horiMemo = new SortedList<int, int>();
            vertMemo.Add(0, n - 2);
            horiMemo.Add(0, n - 2);
            var minVert = n;
            var minHori = n;
            foreach (var query in queries)
            {
                query[1] -= 2;
                if (query[0] == 1)
                {
                    var reverses = vertMemo[0];
                    if (query[1] > 0)
                    {
                        vertMemo.Add(query[1], 0);
                        var currentPos = vertMemo.IndexOfKey(query[1]);
                        reverses = vertMemo.Values[currentPos - 1];
                        vertMemo[query[1]] = reverses;
                    }
                    if (minVert > query[1] && reverses > 0)
                    {
                        horiMemo[0] = query[1];
                        minVert = query[1];
                    }
                    black -= reverses;
                }
                else
                {
                    var reverses = horiMemo[0];
                    if (query[1] > 0)
                    {
                        horiMemo.Add(query[1], 0);
                        var currentPos = horiMemo.IndexOfKey(query[1]);
                        reverses = horiMemo.Values[currentPos - 1];
                        horiMemo[query[1]] = reverses;
                    }
                    if (minHori > query[1] && reverses > 0)
                    {
                        vertMemo[0] = query[1];
                        minHori = query[1];
                    }
                    black -= reverses;
                }
            }
            return black;
        }
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
    }
}


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

#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define vll vector<ll>
#define pll pair<ll , ll>
#define vpll vector<pair<ll, ll> >
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define N 100001
#define HOLE 1000000007

ll fn(ll x,ll rn[])
{
    if(rn[x]==x) return x;
    else return rn[x]=fn(rn[x],rn);
}

void un(ll x,ll y,ll rn[],ll sz[])
{
    x=fn(x,rn);
    y=fn(y,rn);
    if(x==y) return;
    if(sz[x]<sz[y]) swap(x,y);
    sz[x]+=sz[y];
    rn[y]=x;
    return;
}

ll power(ll x,ll y)
{
    ll res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x)%HOLE;

        // n must be even now
        y = y >> 1; // y = y/2
        x = (x * x)%HOLE; // Change x to x^2
    }
    return res;
}

vector <ll> adjl[N];
ll marked[N]={0};
vector <ll> order;

void dfs (ll x){

    if(marked[x])
        return;
    marked[x]=1;

    REP(i,0,adjl[x].size()){

    }

    return;
}

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

    ll q=1;
    //cin>>q;
    while(q--){

        double n;
        cin>>n;

        double volume=(n/3)*(n/3)*(n/3);

        cout<<fixed<<setprecision(7)<<volume<<endl;


    }

return 0;
}


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

using pii = pair<int,int> ;
using pll = pair<long,long> ;
using umpii = unordered_map<int,int> ;
using mpii = map<int,int> ;

#define f first
#define s second

int32_t main(){
	string s ;
	cin >> s ;
	set<char> se; 
	for(auto i : s) se.insert(i) ;
	if(se.size() == 2){
		int x = 0 ; 
		for(auto i : s) x^= i ;
		if(x == 0) cout << "Yes" ;
		else cout<< "No" ;
	}else{
		cout << "No" ;
	}
	return 0 ;
}



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

#define INF ((unsigned long long)200000*200000)
unsigned long long A[200000] = {0};
unsigned long long dp[200001][5];


unsigned long long cost(int i, int k) {
	if (k==0 || k==4) return A[i];
	if (k==1 || k==3) {
		if (A[i]==0) return 2;
		if ((A[i]&0x1)==0) return 0;
		return 1;
	}
	if ((A[i]&0x1)==1) return 0;
	return 1;
}

int main(void) {
	int L;
	cin >> L;
	for (int i = 0; i < L; i++) cin >> A[i];

	for (int i = 0; i <= L; i++) {
		for (int j = 0; j < 5; j++) {
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	for (int i = 0; i < L; i++) {
		for (int j = 0; j < 5; j++) {
			for (int k = j; k < 5; k++) {
				dp[i+1][k] = min(dp[i+1][k], dp[i][j] + cost(i, k));
			}
		}
	}

	unsigned long long ans = INF;
	for (int i = 0; i < 5; i++) {
		ans = min(ans, dp[L][i]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9600
mod=10**9+7

N=int(input())
S1=input()
S2=input()

if S1[0]==S2[0]:
    ans=3
    i=1
else:
    ans=6
    i=2

while i<N:
    if S1[i]!=S2[i]:
        if S1[i-1]!=S2[i-1]:
            ans=ans*3%mod
        else:
            ans=ans*2%mod
        i+=2
    elif S1[i]==S2[i]:
        if S1[i-1]==S2[i-1]:
            ans=ans*2%mod
        i+=1

print(ans)

Measured memory_bytes: 38256
#include<iostream>
#define ll long long int
#define ld long double
#define pi acos(-1)
#define pb push_back
using namespace std;

int main()
{
    ll i,j,a,k,b,c,n,t,m,p,q,d,e,f,y,g,z,h,r,l,x,o;
    ld aa,bb,cc,ee,dd,ff,kk,gg;
//    vector<ll > v,s;
//    map<ll,vector<ll> > me;
//    map<ll,ll > sa,ta,pa,ma;
//    priority_queue<ll, vector<ll>, greater<ll> > aq,tq,pq;
//    string st,et,ft,pt,ct;
//    deque<ll> de,pe,ne;
    ios_base::sync_with_stdio(false);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    cin>>d>>t>>a;
    f = t*a;
    if(f>=d)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int main() {
    llong n, x;
    scanf("%lld%lld", &n, &x);
    llong ans = n;
    n -= x;
    if (n < x) swap(n, x);
    while (x) {
        llong d = n / x * x;
        ans += d << 1;
        d = n - d;
        n = x;
        x = d;
    }
    ans -= n;
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
s = list(input())
q = int(input())

revs = 0
front = []
rear = []

for i in range(q):
    ins = input().split()
    if(ins[0] == "1"):
        revs += 1
    else:
        if (ins[1] == "1" and revs%2 == 0 or ins[1] =="2" and revs%2 == 1):
            front.extend(ins[2])
        else:
            rear.extend(ins[2])

if (revs % 2 == 0):
    for j in reversed(front):
        print(j, end="")
    for j in s:
        print(j, end="")
    for j in rear:
        print(j, end="")
else:
    for j in reversed(rear):
        print(j, end="")
    for j in reversed(s):
        print(j, end="")
    for j in front:
        print(j, end="")
print()


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

int main() {
	// your code goes here
   int n;
   cin>>n;
   int count=0,f=0;
   int a,b;
   for(int i=0;i<n;i++)
   {
       cin>>a>>b;
       if(a==b)
       count++;
       else count=0;
       if(count>=3)
       {
           f=1; break;
       }
       
   }
   if(f) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3560
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int house[4][3][10];
  for(int i=0;i<4;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<10;k++)
        house[i][j][k]=0;

  int b,f,r,v;
  for(int i=0;i<n;i++)
  {
    cin>>b>>f>>r>>v;
    house[b-1][f-1][r-1]+=v;
  }

 for(int i=0;i<4;i++)
 {
   for(int j=0;j<3;j++)
   {
     for(int k=0;k<10;k++)
     {
       cout<<' '<<house[i][j][k];
     }
     cout<<endl;
   }
   if(i!=3)
     cout<<"####################"<<endl;
 }
}

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

int main()
{
  int n,m;
  cin >> n >> m;
  
  ll a[n+1],b[n+1];
  for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  
  ll c[m+1],d[m+1];
  for(int i = 1; i <= m; i++) cin >> c[i] >> d[i];
  
  ll ans[n+1] = {0};
  ll dis = 0, mindis = 1e9;
  int check = 0;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if(dis < mindis){
        mindis = dis;
        check = j;
      }//if
    }//for
    ans[i] = check;
    mindis = 1e9;
  }
  
  for(int i = 1; i <= n; i++) cout << ans[i] << endl;;
  
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  vector<int> cnt(n, 0);
  rep(i, m) {
    cnt[a[i]]++;
    cnt[b[i]]++;
  }
  rep(i, n) {
    cout << cnt[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,a[200002];
struct seg{
	Pi tree[524288];

	void upd(int node, int S, int E, int k, int dif)
	{
		if (S == E)
		{
			tree[node]=mp(dif,S);
			return;
		}
		if (k <= (S + E) / 2)upd(node * 2, S, (S + E) / 2, k, dif);
		else upd(node * 2 + 1, (S + E) / 2 + 1, E, k, dif);
		tree[node]=min(tree[node*2],tree[node*2+1]);
	}

	Pi find(int node, int S, int E, int i, int j)
	{
		if (i > E || j < S)return mp(INF,INF);
		if (i <= S && j >= E)return tree[node];
		return min(find(node * 2, S, (S + E) / 2, i, j), find(node * 2 + 1, (S + E) / 2 + 1, E, i, j));
	}
}t[2];
struct data {
	int l,r,p1,p2;
	bool operator < (const data &O) const{
		if(p1==O.p1)return a[p2]>a[O.p2];
		return a[p1]>a[O.p1];
	}
};
Pi get(int l,int r)
{
	if(l>r)return mp(INF,INF);
	Pi p1=t[l&1].find(1,1,n,l,r);
	Pi p2=t[(p1.Y+1)&1].find(1,1,n,p1.Y+1,r);
	return mp(p1.Y,p2.Y);
}
int main(){
	scanf("%d",&n);
	fup(i,1,n,1)
	{
		scanf("%d",a+i);
		t[i&1].upd(1,1,n,i,a[i]);
		t[(i&1)^1].upd(1,1,n,i,INF);
	}
	priority_queue<data> q;
	Pi p=get(1, n);
	q.push({1,n,p.X,p.Y});
	while(!q.empty())
	{
		data x=q.top();
		q.pop();
		printf("%d %d ",a[x.p1],a[x.p2]);
		
		Pi t1 = get(x.l,x.p1-1);
		Pi t2 = get(x.p1+1,x.p2-1);
		Pi t3 = get(x.p2+1,x.r);
		if(t1.X!=INF)q.push({x.l,x.p1-1,t1.X,t1.Y});
		if(t2.X!=INF)q.push({x.p1+1,x.p2-1,t2.X,t2.Y});
		if(t3.X!=INF)q.push({x.p2+1,x.r,t3.X,t3.Y});
	}
}

Measured memory_bytes: 11252
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll x = (n + 1000 - 1) / 1000;
    cout << x * 1000 - n << "\n";
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  string* cand = new string[6];
  for(int i=0;i<6;i++) cand[i] = "zzzzzz";
  for(int i=0;i<s.length();i++){
    for(int j=0;j<k;j++){
      if(i+j>=s.length()) break;
      string cs = s.substr(i,j+1);
      bool exi = false;
      for(int a=0;a<6;a++){
        exi |= cs==cand[a];
      }
      if(exi) continue;
      cand[5] = cs;
      sort(cand,cand+6);
    }
  }
  cout << cand[k-1] << endl;
  return 0;
}


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

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>p(n);
	for (auto& i : p)
	{
		cin >> i;
	}
	sort(p.begin(), p.end());
	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += p[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define int long long
#define inf 1000000000000000000
#define mod 1000000007
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); //freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
using namespace std;

int k;
vector <int> v;

vector <int> rec(vector<int> t){
	if(t.size() >= 100000) return t;
	vector <int> temp;
	for(int i = 0; i < (int)t.size(); i++){
		int d = t[i]%10;
		temp.push_back(t[i]*10 + d);
		if(d)
			temp.push_back(t[i]*10 + d - 1);
		if(d < 9)
			temp.push_back(t[i]*10 + d + 1);
	}

	temp = rec(temp);
	for(auto x: temp){
		if(x)
		t.push_back(x);
	}
	return t;
}

signed main()
{
    FLASH
	cin>>k;

	v = rec({1, 2, 3, 4, 5, 6, 7, 8, 9});
	sort(v.begin(), v.end());
	cout<<v[k - 1]<<'\n';
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

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

Measured memory_bytes: 2560
from collections import Counter
n = int(input())
a = sorted(map(int, input().split()))
c = Counter(a)
s = set()
for i in range(n):
    if a[i] in s:
        continue
    elif c[a[i]] >= 2:
        s.add(a[i])
    for j in range(2,10**6//a[i]+1):
        s.add(a[i]*j)
print(sum([not (ai in s) for ai in a]))


Measured memory_bytes: 103500
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include <deque>

using namespace std;
typedef long long ll;

ll N, A[100000] = {}, x[100000] = {};

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++)cin >> A[i];
	for (int i = 1; i <= N; i++)x[1] += A[i] * pow(-1, i + 1);
	cout << x[1];
	for (int i = 2; i <= N; i++) {
		x[i] = 2 * A[i - 1] - x[i - 1];
		cout << " " << x[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] check = { "this", "that", "the" };
        while (sc.hasNext()) {
            String str = sc.nextLine();
            String newText = str;
            end: for (int i = 0; i < 26; i++) {
                for (int j = 0; j < check.length; j++) {
                    if (newText.contains(check[j])) {
                        System.out.println(newText);
                        break end;
                    }
                }
                newText = newLine(newText);
            }
        }
    }

    static String newLine(String text) {
        String temp = "";
        for (int i = 0; i < text.length(); i++) {
            if (text.charAt(i) > 96 && text.charAt(i) < 123)
                temp += (char) ((text.charAt(i) + 8) % 26 + 97);
            else
                temp += text.charAt(i);
        }
        return temp;
    }
}


Measured memory_bytes: 26484