akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;
	if (N == 3) {
		cout << "2 5 63" << endl;
		return 0;
	}
	if (N == 4) {
		cout << "2 5 20 63" << endl;
		return 0;
	}
	vector<int> res;
	ll sum = 0;
	for (int i = 2; i <= 30000; i++) {
		if (i % 2 == 0 || i % 3 == 0) {
			sum += i;
			res.push_back(i);
			if (res.size() >= N + 2) {
				break;
			}
		}
	}
	if (N == 20000) {
		for (int i = 0; i < N; i++) {
			cout << res[i] << " \n"[i + 1 == N];
		}
		return 0;
	}
	if (N == 19999) {
		auto tmp = res; res.clear();
		for (int i = 0; i < N + 2; i++) {
			if (tmp[i] != 6) {
				res.push_back(tmp[i]);
			}
		}
		for (int i = 0; i < N; i++) {
			cout << res[i] << " \n"[i + 1 == N];
		}
		return 0;
	}
	if (sum % 6 == 1) {
		reverse(res.begin(), res.end());
		res.pop_back();
		res.pop_back();
		res.pop_back();
		res.push_back(2);
		reverse(res.begin(), res.end());
	}
	else if (sum % 6 == 5) {
		reverse(res.begin(), res.end());
		res.pop_back();
		res.pop_back();
		reverse(res.begin(), res.end());
	}
	else if (sum % 6 == 0) {
		reverse(res.begin(), res.end());
		res.pop_back();
		res.pop_back();
		res.pop_back();
		res.push_back(3);
		reverse(res.begin(), res.end());
	}
	else {
		auto tmp = res; res.clear();
		for (int i = 0; i < N + 2; i++) {
			if (tmp[i] != sum % 6 && tmp[i] != 6) {
				res.push_back(tmp[i]);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << res[i] << " \n"[i + 1 == N];
	}
	return 0;
}


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

N,M = list(map(int, input().rstrip().split()))
ab_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

ab_list.sort(key= lambda x: x[1])

prev_tail = -float("inf")
cnt = 0

for left,right in ab_list:
    if prev_tail <= left:
        cnt += 1
        prev_tail = right

print(cnt)


Measured memory_bytes: 29084
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	vector<ll> sum(N);
	sum[0] = A[0];
	for (int i = 1; i < N; i++) sum[i] = sum[i - 1] + A[i];
	ll ans = 1LL << 60;
	for (int i = 1; i < N; i++) {
		ll d = abs(sum[i - 1] - (sum[N - 1] - sum[i - 1]));
		ans = min(ans, d);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
n,k = map(int,input().split())
list1 = []
for i in range(n):
    x = int(input())
    list1.append(x)
y = 10000000000
a = -1
list1.sort()
for i in range(n-k+1):
    z = list1[k+i-1]-list1[0+i]
    if y > z:
        y = z
print(y)

Measured memory_bytes: 7384
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;


int main()
{
	long N, K;
	cin >> N >> K;
	
	long ans = N % K;
	
	
	if(abs(ans - K) < ans) cout << abs(ans - K) << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3564
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m; readV(n, m);

  auto g = new bool[][](n, n);
  foreach (_; 0..m) {
    int a, b; readV(a, b); --a; --b;
    g[a][b] = g[b][a] = true;
  }

  auto ans = 0;
 loop: foreach (r; iota(1, n).permutations) {
    if (!g[0][r[0]]) continue;
    foreach (i; 0..n-2)
      if (!g[r[i]][r[i+1]]) continue loop;
    ++ans;
  }

  writeln(ans);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		g = new ArrayList[n];
		for(int i = 0; i < n; i++) {
			g[i] = new ArrayList<>();
		}
		for(int i = 0; i < m; i++) {
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			g[u].add(v);
		}
		prev = new int[n][n];
		dist = new int[n][n];
		int ucycle = -1; int dmin = n+1;
		for(int i = 0; i < n; i++) {
			Arrays.fill(prev[i], -1);
			Arrays.fill(dist[i], -1);
			int d = bfs(i);
			if(d > 0 && d < dmin) {
				ucycle = i;
				dmin = d;
			}
		}
		if(ucycle == -1) {
			System.out.println(-1);
		}
		else {
			StringBuilder sb = new StringBuilder();
			sb.append(dmin+"\n");
			ArrayList<Integer> vs = new ArrayList<Integer>();
			int i = prev[ucycle][ucycle];
			while(i != ucycle) {
				vs.add(i);
				i = prev[ucycle][i];
			}
			vs.add(ucycle);
			Collections.reverse(vs);
			for(int v: vs) {
				sb.append((v+1)+"\n");
			}
			System.out.print(sb.toString());
		}
	}
	static ArrayList<Integer>[] g;
	static int[][] prev;
	static int[][] dist;
	static int bfs(int i) {
		LinkedList<Integer> q = new LinkedList<>();
		q.add(i);
		dist[i][i] = 0;
		while(!q.isEmpty()) {
			int u = q.poll();
			for(int v: g[u]) {
				if(v == i) {
					prev[i][i] = u;
					return dist[i][u]+1;
				}
				else if(dist[i][v] < 0) {
					dist[i][v] = dist[i][u]+1;
					prev[i][v] = u;
					q.add(v);
				}
			}
		}
		return -1;
	}
}


Measured memory_bytes: 64632
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


s = S()
a = s.count('1')
b = s.count('0')
print(min(a, b) * 2)


Measured memory_bytes: 39536
#include <stdio.h>
#define N 100
int main(){

  int a,b[N],i,d,k,j;

  scanf("%d",&a);
  
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }

  for(j=0;j<a;j++) {
    printf("%d",b[j]);
    if(j<a-1)printf(" ");
  }
  printf("\n"); 
  
for(i=1;i<=a-1;i++){
    d=i;
 
    while(d>0 && b[d]< b[d-1]){
      k=b[d];
      b[d]=b[d-1];
      b[d-1]=k;
      d--;
    }
    for(j=0;j<a;j++) {
      printf("%d",b[j]);
      if(j<a-1)printf(" ");
    }
    printf("\n"); 
  }
 
  
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << (b - a == c - b ? "YES" : "NO") << endl;
}


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

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	class B{
		int[][] a;
		String name;

		B(int[][] a, String name){
			this.a=a;
			this.name=name;
		}
	}

	int[][] A={{1, 1}, {1, 1}};
	int[][] B={{1}, {1}, {1}, {1}};
	int[][] C={{1, 1, 1, 1}};
	int[][] D={{0, 1}, {1, 1}, {1, 0}};
	int[][] E={{1, 1, 0}, {0, 1, 1}};
	int[][] F={{1, 0}, {1, 1}, {0, 1}};
	int[][] G={{0, 1, 1}, {1, 1, 0}};

	int[][] field;

	int n=8;

	void run(){
		LinkedList<B> blocks=new LinkedList<B>();
		blocks.add(new B(A, "A"));
		blocks.add(new B(B, "B"));
		blocks.add(new B(C, "C"));
		blocks.add(new B(D, "D"));
		blocks.add(new B(E, "E"));
		blocks.add(new B(F, "F"));
		blocks.add(new B(G, "G"));

		sc=new Scanner(System.in);
		for(;;){
			field=new int[n][n];
			for(int j=0; j<n; j++){
				String s=sc.nextLine();
				for(int i=0; i<n; i++){
					if(s.charAt(i)=='1')
						field[j][i]=1;
				}
			}
			boolean f=false;
			for(int j=0; j<n; j++){
				for(int i=0; i<n; i++){
					for(B b : blocks){
						if(match(b, i, j)){
							println(b.name);
							f=true;
							break;
						}
					}
					if(f)
						break;
				}
				if(f)
					break;
			}
			if(!sc.hasNextLine())
				break;
			sc.nextLine();
		}
		sc.close();
	}

	boolean match(B b, int x, int y){
		int[][] a=b.a;
		for(int j=0; j<a.length; j++){
			for(int i=0; i<a[0].length; i++){
				int x2=x+i;
				int y2=y+j;
				if(x2<0||x2>=n||y2<0||y2>=n)
					return false;
				if(a[j][i]==1&&field[y2][x2]==0)
					return false;
			}
		}
		return true;
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ans = 0
    for x in range(1, N + 1):
        n = N // x  # Nのうちにxがいくつ含まれるか（等差数列の項数）
        ans += (n * (2 * x + (n - 1) * x)) // 2  # 初項と公差がxでn項の等差数列の和
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 75048
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

const ll inf = 1LL<<60;
int N, M;
vector<vector<pair<ll, ll>>> adj;
vector<ll> dist;

void input(){
    cin >> N >> M;
    adj.resize(N);
    dist.resize(N+5, inf);
    rep(i, N-1) adj[i+1].push_back(make_pair(i, 0));
    rep(i, M){
        int l, r, c; cin >> l >> r >> c;
        --l; --r;
        adj[l].push_back(make_pair(r, c));
    }
}

void Dijkstra(){
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    dist[0] = 0;
    pq.push(make_pair(0, 0));

    while(!pq.empty()){
        auto p = pq.top(); pq.pop();
        ll d = p.first;
        int now = p.second;
        if(dist[now] < d) continue;
        for(auto q : adj[now]){
            int to = q.first;
            if(dist[to] > dist[now]+q.second){
                dist[to] = dist[now] + q.second;
                pq.push(make_pair(dist[to], to));
            }
        }
    }
}

void solve(){
    Dijkstra();
    cout << (dist[N-1]==inf? -1:dist[N-1]) << endl;
}

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

    input();
    solve();
    
    return 0;
}

Measured memory_bytes: 10108
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

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

int main(){
	int n; cin >> n;
	vector<int> teams,res;

	rep(i,n) teams.push_back(0);
	res = teams;
	//cout << endl << teams.size() << "teams" << endl;
	
	rep(i,n*(n-1)/2){
		int a,b,c,d;

		cin >> a >> b;
		cin >> c >> d; 
		
		if(c > d) teams[a%(n+1) - 1] += 3;		
		else if(c < d) teams[b%(n+1) - 1] += 3;
		else{
			teams[a%(n+1) - 1] += 1;
			teams[b%(n+1) - 1] += 1;
		}
	}

	//rep(i,teams.size()) cout << "[" << i + 1 << "] " << teams[i] << "score" <<endl;
	
	rep(i,teams.size()){
		rep(j,teams.size()){
			if(teams[i] < teams[j]) res[i] += 1;
		}
	}	
	
	
	rep(i,n) cout << res[i] + 1 << endl;	

	return 0;
	
}

Measured memory_bytes: 1220
#include <iostream>
using namespace std;
int main(void){
    int n,m1,m2;
    cin >> n;
    m1 = n/100;
    m2 = n%100;
    if(m1>0 and m1<13){
        if(m2>0 and m2<13) cout << "AMBIGUOUS";
        else cout << "MMYY";
    }
    else{
        if(m2>0 and m2<13) cout << "YYMM";
        else cout << "NA";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int N=sc.nextInt();
	long sum=0;
	for(int i=1;i<=N;i++) {
		if(i%3!=0&&i%5!=0) {
			sum+=i;
		}
	}
	System.out.println(sum);
	}
}


Measured memory_bytes: 35852
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
	N := getStdinInt64()
	A := getStdinIntArr64()
	var i int64 = 0
	//var j int64 = 0
	//var cnt int64 = 0
	var max int64 = 0

	// 最大値を求める
	for i = 0; i < N; i++ {
		if A[i] > max {
			max = A[i]
		}
	}

	// 素数を求める
	isPrime := make([]bool, max+1)
	for i := 2; i < len(isPrime); i++ {
		isPrime[i] = true
	}
	isPrime[0] = false
	isPrime[1] = false
	for i := 2; i < len(isPrime); i++ {
		if isPrime[i] {
			for j := i * 2; j < len(isPrime); j += i {
				isPrime[j] = false
			}
		}
	}

	// 個数
	countMap := make(map[int64]int64)
	for _, a := range A {
		countMap[a]++
	}

	// 1が1個、または1が2個以上の場合
	if countMap[1] == 1 {
		// x % 1 == 0のみ
		fmt.Printf("%d\n", 1)
		return
	}
	if countMap[1] >= 2 {
		// 全てが x % 1 == 0 になってしまう
		fmt.Printf("%d\n", 0)
		return
	}

	var ans int64 = 0
	for _, a := range A {
		if countMap[a] >= 2 {
			// x % x == 0 になってしまう
			continue
		}
		if isPrime[a] {
			// 素数なので明らか
			ans++
			continue
		}

		// 約数を求める
		fac := make([]int64, 0)
		for i = 2; i*i <= a; i++ {
			if a%i == 0 {
				fac = append(fac, i) // 因数
				if i*i != a {
					fac = append(fac, a/i) // 因数で割ったもの
				}
			}
		}

		flag := true
		for _, f := range fac {
			if countMap[f] >= 1 {
				flag = false
				break
			}
		}
		if flag {
			ans++
		}
	}

	fmt.Printf("%d\n", ans)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func gcdimpl(n, m int64) int64 {
	var i int64 = 0
	for i = 0; i < 10; i++ {
		var t int64 = n - m
		q := false
		if m > t {
			q = true
		}
		if q {
			n = m
		} else {
			n = t
		}
		if q {
			m = t
		} else {
		}
		if m == 0 {
			return n
		}
	}
	return gcdimpl(m, n%m)
}

func gcd(n, m int64) int64 {
	if n > m {
		return gcdimpl(n, m)
	}
	return gcdimpl(m, n)
}

func reduce(x, N int64) int64 {
	return (x * N) >> 32
}


Measured memory_bytes: 31096
n = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))

b = 2
bg = 1.0 / b

M = [] #t = i秒の最高速度
for i in range(n) :
    for j in range(T[i] * b) :
        M.append(V[i])

R = [0] + T[:]
for i in range(n) :
    R[i+1] += R[i]


for i in range(n) :

    le = R[i] * b
    ri = R[i+1] * b

    
    j = 0
    if i-1 >= 0 and V[i-1] > V[i] :
        while le >= 0 :
            M[le] = min(M[le], V[i] + j*bg)
            #print(M[le])
            j += 1
            le -= 1
    j = 0
    if i+1 < n and V[i+1] > V[i] :
        while ri < len(M) :
            M[ri] = min(M[ri], V[i] + j*bg)
            j += 1
            ri += 1

for i in range(len(M)) :
    M[i] = min(i*bg, (len(M)-i)*bg, M[i])

M += [0]

ans = 0
for i in range(len(M)-1) :
    ans += (M[i] + M[i+1]) * bg * 0.5

print(ans)


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

int N;
ll a[100000],sum,nadd;

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

	cin >> N;
	for (int i=0;i<N;i++) {
		cin >> a[i];
		sum+=a[i];
	}

	ll div =((ll)N*(N+1)/2);
	if (sum%div) {
		cout << "NO\n";
		return 0;
	}
	ll nadd=sum/div;


	ll nfound=0;
	for (int i=0;i<N;i++) {
		ll diff=a[(i+1)%N]-a[i];
		ll t=nadd-diff;
		if (t<0 || t%N) nfound=nadd+1;
		else nfound+=t/N;
	}

	if (nfound==nadd) cout << "YES\n";
	else cout << "NO\n";
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
 
  if((S.at(2) == S.at(3)) && (S.at(4) == S.at(5))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer cout<<endl<<"answer : ";
#define maxn 100005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0;string s;bool flag=false;
        cin>>n>>k; lld a[n]; for(i=0;i<n;i++) cin>>a[i];
        sort(a,a+n);
        for(i=0;i<k;i++)
            cnt+=a[i];
        cout<<cnt<<endl;
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL n,q,a[3010],Q;
LL f[3010][3010];
LL fp(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;b>>=1;
	}
	return ans;
}
const LL inv=fp(2,mod-2);
int main()
{
	scanf("%lld %lld",&n,&q);Q=q;
	for(LL i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(LL i=1;i<=n;i++)
		for(LL j=1;j<=n;j++) f[i][j]=(a[i]<a[j]);
	while(q--)
	{
		LL x,y;scanf("%lld %lld",&x,&y);
		f[x][y]=f[y][x]=(f[x][y]+f[y][x])*inv%mod;
		for(LL i=1;i<=n;i++)
			if(i!=x&&i!=y)
			{
				f[i][x]=f[i][y]=(f[i][x]+f[i][y])*inv%mod;
				f[x][i]=f[y][i]=(f[x][i]+f[y][i])*inv%mod;
			}
	}
	LL ans=0;
	for(LL i=1;i<=n;i++)
		for(LL j=1;j<i;j++) (ans+=f[i][j])%=mod;
	(ans*=fp(2,Q))%=mod;
	printf("%lld",ans);
}

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

ll digit(ll x)
{
  ll dig = 0;
  ll y = x;
  while(y!=0)
  {
    dig++;
    y = y / 10;
  }
  return dig;
}

ll int_pow(ll x, ll a)
{
  if(a==0) return 1;
  ll y = int_pow(x,a/2);
  y = y * y;
  if (a%2==1) y*=x;
  return y;
}


ll mid_cnt(ll a, ll b, ll n)
{
  ll dig = digit(n);
  ll top = n/int_pow(10,dig-1);
  
  ll cnt = 0;
  // count the number which has less digits
  if(dig>2) cnt = (int_pow(10,dig-2))/9;
  // one-digit number iff a==b
  if(a==b) cnt++;


  // count the number which has the same digits
  if(a<top)
  {
    cnt+= int_pow(10,dig-2);
  } else if(a==top)
  {
    ll y = n - top*int_pow(10,dig-1);
    y = y / 10;
    if((n%10)<b) y--;
    cnt += y+1;
  }
  return cnt;
}

int main()
{
  ll n;
  cin >> n;
  ll dig = digit(n);

  if(dig==1)
  {
    cout << n << endl;
    return 0;
  }

  ll cnt = 0;

  
  
  for (ll x = 1; x < 10; x++)
  {
    for (ll y = 1; y < 10; y++)
    {
      cnt += mid_cnt(x,y,n)*mid_cnt(y,x,n);
    }
  }
  

  cout << cnt << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using  namespace std;
int main() {
    int W,a,b,t,x;
    while(cin>>W>>a>>b) {
        if(a>b) {
            t=b;
            b=a;
            a=t;
        }
        t=b-a-W;
        if(t>0)
            x=b-a-W;
        else
            x=0;
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	const ll oo = 1e15;
	
	int q;
	cin >> q;
	
	ll SL = 0, SR = 0, c = 0;
	
	ll median = oo;
	
	multiset<ll> L, R;
	
	while(q--){
		
		int t;
		cin >> t;
		
		if(t == 1){
			ll a, b;
			cin >> a >> b;
			c += b;
			
			if(median == oo)
				median = a;
			else{
				
				if(a > median)
					R.insert(a), SR += a;
				else
					L.insert(a), SL += a;
				
				if((ll)R.size() - (ll)L.size() == 2){
					L.insert(median);
					SL += median;
					median = *(R.begin());
					R.erase(R.find(median));
					SR -= median;
				}
				else if((ll)L.size() - (ll)R.size() == 1){
					R.insert(median);
					SR += median;
					median = *(L.rbegin());
					L.erase(L.find(median));
					SL -= median;
				}
			}
		}
		else
			cout << median << " " << median * (ll)L.size() - SL + SR - median * (ll)R.size() + c << endl;
	}

	return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n,m,x,y;
  cin>>n>>m>>x>>y;

  int xmax=-100,ymin=100,xx,yy;
  for(int i=0;i<n;i++)
  {
    cin>>xx;
    if(xx>xmax) xmax=xx;
  }
  for(int i=0;i<m;i++)
  {
    cin>>yy;
    if(yy<ymin) ymin=yy;
  }

  bool flag=false;
  for(int i=xmax+1;i<=ymin;i++)
  {
    if(i>x && i<y)
    {
      flag=true;
      break;
    }
  }

  if(flag) cout<<"No War"<<endl;
  else cout<<"War"<<endl;
}

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

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

    vector<ll> p(n);
    for (int i=0; i<n; i++) {
        cin >> p.at(i);
    }

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

    int j = 0;

    ll leftan, rightan;

    while (true) {
        vector<ll>::iterator it = find(p.begin(), p.end(), x-j);
        if (it == p.end()) {
            leftan = x-j;
            break;
        }
        j++;
    }

    j = 0;
    
    while (true) {
        vector<ll>::iterator it = find(p.begin(), p.end(), x+j);
        if (it == p.end()) {
            rightan = x+j;
            break;
        }
        j++;
    }

    ll ans = leftan;
    if (rightan - x < x - leftan) {
        ans = rightan;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007ll
using namespace std;
int ara[200005];
ll bigmod(ll b, ll p)
{
    if(!p)return 1ll;
    ll ret= bigmod(b, p>>1);
    ret= (ret*ret)%mod;
    if(p&1ll)ret= (ret*b)%mod;
    return ret;
}
int main()
{
    int n, k, res= 1;
    scanf("%d %d", &n, &k);
    int neg= 0, z= 0;
    for(int i=1; i<=n; i++)
    scanf("%d", &ara[i]), z+= (ara[i]==0), neg+= (ara[i]<0);
    if(k==n || (neg==n && k&1))
    {
        sort(ara+1, ara+1+n, greater<int>());
        for(int i=1; i<=k; i++)
        res= (1LL*res*ara[i])%mod;
        if(res<0)res+= mod;
        printf("%d\n", res);
    }
    else if((n-z)<k || (z && (n-z)==k && (neg&1)) || (z && !(n-z-neg) && (k&1)))puts("0");
    else
    {
        vector<int>vp, vn;
        for(int i=1; i<=n; i++)
        if(ara[i]!=0)
        {
            if(ara[i]>0)vp.push_back(ara[i]);
            else vn.push_back(-ara[i]);
        }
        sort(vp.begin(), vp.end());
        sort(vn.begin(), vn.end());
        int lp= 0, ln= 0, c= 0;
        for(int i=1; i<=k; i++)
        {
            if(!vp.empty() && (vn.empty() || vp.back()>vn.back()))
            lp= vp.back(), vp.pop_back(), res= (1LL*res*lp)%mod;
            else ln= vn.back(), vn.pop_back(), res= (1LL*res*ln)%mod, c++;
        }
        if(c&1)
        {
            if(!vp.empty() && !vn.empty())
            {
                if(!lp)res= ((1LL*res*bigmod(ln, mod-2))%mod * 1LL*vp.back())%mod;
                else if((1LL*ln*vn.back())>(1LL*lp*vp.back()))
                res= ((1LL*res*bigmod(lp, mod-2))%mod * 1LL*vn.back())%mod;
                else res= ((1LL*res*bigmod(ln, mod-2))%mod * 1LL*vp.back())%mod;
            }
            else
            {
                if(vp.empty() && !vn.empty() && lp)res= ((1LL*res*bigmod(lp, mod-2))%mod * 1LL*vn.back())%mod;
                else if(!vp.empty() && ln)res= ((1LL*res*bigmod(ln, mod-2))%mod * 1LL*vp.back())%mod;
            }
//            if(res<0)res+= mod;
        }
        printf("%d\n", res);
    }
    return 0;
}


Measured memory_bytes: 5000
# 057 B
N, M = [int(x) for x in input().split()]
#print(N,M)#
st = []
for i in range(N):
    st.append([int(x) for x in input().split()])
cp = []
for i in range(M):
    cp.append([int(x) for x in input().split()])
#    st[i][0], st[i][1] =  [int(x) for x in input().split()]
#print(st)#
#print(cp)#
for i in range(N):
    mindist = 10**9
    for j in range(M):
        d = abs(cp[j][0]-st[i][0]) + abs(cp[j][1]-st[i][1])
        if d<mindist: 
            mindist = d
            nth = j
    print(nth+1)

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

using namespace std;

int main(){
    string n;
    cin >> n;
    if((n[0]==n[1] && n[1]==n[2]) || (n[1]==n[2] && n[2]==n[3])){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
#include <complex>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
typedef pair<double, int> P;
typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
const int INF = 1 << 29;
const double EPS = 1e-10;

double cross(const xy_t &a, const xy_t &b){
  return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
  return real(conj(a) * b);
}

int ccw(xy_t a, xy_t b, xy_t c){
  b -= a, c -= a;
  if(cross(b, c) > 0) return 1;
  if(cross(b, c) < 0) return -1;
  if(dot(b, c) < 0) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool intersectSS(const line &s, const line &t){
  return ccw(s.first, s.second, t.first) * ccw(s.first, s.second, t.second) <= 0
    && ccw(t.first, t.second, s.first) * ccw(t.first, t.second, s.second) <= 0;
}

bool visit[10010];
 
double calc(int N1, xy_t *P1, xy_t *P2){
  line l(P2[0], P2[1]);
  memset(visit, false, sizeof(visit));
  visit[0] = 0;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, 0));
  while(!que.empty()){
    P p = que.top(); que.pop();
    double cost = p.first;
    int v = p.second;
    if(v == 1) return cost;
    if(visit[v]) continue;
    visit[v] = true;
    rep(i, N1)if(!visit[i]){
      double d = abs(P1[i] - P1[v]);
      if(!intersectSS(l, line(P1[i], P1[v]))){
	que.push(P(cost + d, i));
      }
    }
  }
  return 1e100;
} 

xy_t A[10010];
xy_t B[10010];

int main(){
  int Na, Nb;
  double x, y;
  while(cin >> Na >> Nb){
    double res = 1e100;
    rep(i, Na) {
      cin >> x >> y;
      A[i] = xy_t(x, y);
    }
    rep(i, Nb){
      cin >> x >> y;
      B[i] = xy_t(x, y);
    }
    res = min(abs(A[0] - A[1]) + calc(Nb, B, A),
	      abs(B[0] - B[1]) + calc(Na, A, B));
    if(res > 1e50) cout << -1 << endl;
    else cout << fixed << setprecision(12) << res << endl;
  }
  return 0;
}
 

Measured memory_bytes: 4700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int n;
    cin >> n;
    cout << n + n * n + n * n * n << "\n";
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#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 rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;

int main(){
	ll N;
	scanf("%lld",&N);
	ll F[N][10];
	ll P[N][11];
	rep(i,N){
		rep(j,10){
			scanf("%lld",&F[i][j]);
		}
	}
	rep(i,N){
		rep(j,11){
			scanf("%lld",&P[i][j]);
		}
	}
	ll ans,tmp;
	ll c[N];
	int flag=0;
	for (int i = 1; i < (1<<10); i++) {
		rep(k,N) c[k]=0;
	  for (int j = 0; j < 10; j++) {
	    if ((1 & (i >> j)) == 1) {
	      rep(k,N) c[k]+=F[k][j];
	    }
		}
		tmp = 0;
		rep(k,N) tmp+=P[k][c[k]];
		if(flag==0){
			ans = tmp;
			flag=1;
		}
		else ans = max(tmp,ans);
	}
	printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%d" (fun d ->
    let c = Array.init 26 (fun _ -> Scanf.scanf " %d" (fun c -> c)) in
    let s = Array.init d (fun _ ->
        Array.init 26 (fun _ ->
            Scanf.scanf " %d" (fun s -> s)))
    in
    for i = 0 to d - 1 do
        let rec loop j mi mx =
            if j = 26 then Printf.printf "%d\n" mi else
                if s.(i).(j) > mx then loop (j + 1) (j + 1) s.(i).(j)
                                  else loop (j + 1) mi mx
        in
        loop 0 0 0
    done
)

Measured memory_bytes: 6000
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = readline().rstrip()
T = readline().rstrip()

longest_overlap = 0
for n in range(1,N+1):
    if S[-n:] == T[:n]:
        longest_overlap = n

answer = N + N - longest_overlap
print(answer)

Measured memory_bytes: 3060
<?php
  $rest=trim(fgets(STDIN));
  while($line=fgets(STDIN)){
    $num[]=trim($line);
  }
  foreach($num as $ele2){
    $trinum=explode(" ",$ele2);
    $maxnum=max($trinum);
    $key=array_search($maxnum,$trinum);
    unset($trinum[$key]);
    $sum=0;
    foreach($trinum as $ele){
      $sum+=pow($ele,2);
    }
    /* echo "max:".(int)$maxnum; */
    if($sum==pow((int)$maxnum,2))
      echo "YES\n";
    else
      echo "NO\n";
  }

Measured memory_bytes: 15272
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int mod = 2019;

int main(void){
    int L, R;
    cin >> L >> R;
    
    if(R - L + 1 >= 2019){
        cout << 0 << endl;
        return 0;
    }
    for(int i = L; i <= R; ++i){
        if(i % mod == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    int ans = 2020;
    for(int i = L; i < R; ++i){
        for(int j = i + 1; j <= R; ++j){
            ll temp = ((ll)i * (ll)j) % mod;
            ans = min(ans, (int)temp);
        }
    }
    
    cout << ans << endl;
}


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

int main(){
	int n;
	std::vector<int> a;
	std::cin >> n;
	for(int i = 0; i < n; i++){
		int temp;
		std::cin >> temp;
		a.push_back(temp);
	}
	
	int count = 0;
	for(int i = 0; i < n; i++){
		int mini = i;
		for(int j = i; j < n; j++){
			if(a[j] < a[mini])
				mini = j;
		}
		if(mini != i){
			int temp = a[mini];
			a[mini] = a[i];
			a[i] = temp;
			count++;
		}
	}
	
	for(int i = 0; i < n; i++){
		std::cout << a[i];
		if(i == n - 1)
			std::cout << std::endl;
		else
			std::cout << ' ';
	}
	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 1224
def main():
    sx, sy, tx, ty = list(map(int, input().split()))
    dx = tx - sx
    dy = ty - sy
    ans = []
    ans.append(''.join(['D', 'R' * (dx + 1), 'U' * (dy + 1), 'L']))
    ans.append(''.join(['D' * dy, 'L' * dx]))
    ans.append(''.join(['U', 'R' * (dx - 1), 'U' * (dy - 1), 'R']))
    ans.append(''.join(['U', 'L' * 2, 'D' * (dy - 1), 'L' * (dx - 1), 'D' * 2, 'R']))
    print(''.join(ans))



if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
S = input()

s_len = len(S)

if s_len%2 == 0:
  s1 = S[:s_len//2]
  s2 = S[:s_len//2-1:-1]
else:
  s1 = S[:s_len//2]
  s2 = S[:s_len//2:-1]

count = 0
for i in range(len(s1)):
  if s1[i] != s2[i]:
    count += 1
print(count)

Measured memory_bytes: 38480
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    int a[m],b[m],x,f=0;
    memset(b,0,sizeof(b));
    r(i,m)cin>>a[i];
    r(i,n)r(j,m){
      cin>>x;
      b[j]+=x;
    }
    r(i,m)if(a[i]<b[i]){
      cout<<"No"<<endl;
      f++;
      break;
    }
    if(!f)cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3020
#include <iostream>
using namespace std;
#define LL long long

#include <cmath>
void _140() {
    int n;
    cin >> n;
    int b[100];
    LL sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        cin >> b[i];
        if (i == 0) {
            sum += b[i];
        } else {
            sum += min(b[i - 1], b[i]);
        }
    }
    sum += b[n - 2];

    cout << sum << endl;
}

int main()
{
    _140();

    return 0;
}



Measured memory_bytes: 256
_n = gets.to_i
a = gets.strip.split.map(&:to_i).sort.reverse
i = 0
al = 0
bo = 0
a.each do |num|
  if i % 2 == 0
    al += num 
  else
    bo += num
  end
  i += 1
end
  
puts al - bo

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

int main(){
    int k, a, b;
    scanf("%d", &k);
    scanf("%d %d", &a, &b);
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            puts("OK");
            return 0;
        }
    }
    puts("NG");
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb puah_back

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 dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    ll n, k; cin >> n >> k;
    map<ll, ll> mp;
    n = n % k;
    ll ans = n;
    mp[n]++;
    while(1){
        n = abs(n-k);
        ans = min(n, ans);
        mp[n]++;
        
        if(mp[n] >= 2){
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N = int(input())
    D = [int(c) for c in input().split()]
    sorted_D = sorted(D)
    upper = sorted_D[N//2]
    lower = sorted_D[N//2 - 1]
    print(upper - lower)


if __name__ == '__main__':
    main()

Measured memory_bytes: 25424
#include <iostream>
using namespace std;
int main(void){
    long long N,T,A,i,ans;
    cin >> N >> T >> A;
    double H[N],tem,temA;
    temA=10000000000;
    for(i=0;i<N;i++){
        cin >> H[i];
        tem = double(T) - H[i]*0.006;
        tem = tem-A;
        if(tem<0){
            tem = -tem;
        }
        if(tem<temA){
            temA=tem;
            ans=i;
        }
    }
    cout << ans+1 << endl;
}


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

int main(){
  int n, k; cin >> n >> k;
  string s; cin >> s;

  vector<int> nums;
  int now = 1, cnt = 0;
  for(int i=0; i<n; ++i){
    if(s[i] == (char)('0' + now)) ++cnt;
    else{
      nums.push_back(cnt);
      cnt = 1;
      now = 1-now;
    }
  }
  if(cnt != 0) nums.push_back(cnt);
  if(nums.size() % 2 == 0) nums.push_back(0);

  int left = 0, right = 0;
  int sum = 0, ans = 0;
  for(int i=0; i<nums.size(); i+=2){
    int nextLeft = i;
    int nextRight = min(nextLeft + 2*k + 1, (int)nums.size());

    while(nextLeft > left){
      sum -= nums[left];
      ++left;
    }

    while(nextRight > right){
      sum += nums[right];
      ++right;
    }

    ans = max(ans, sum);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1020
#include <stdio.h>

struct Node{
  int p;
  int l;
  int r;
};
struct Node T[10000];
int n;

void preParse(int u) {
  if(u == -1){
    return;
  }
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u) {
  if(u == -1){
    return;
  }
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u) {
  if(u == -1){
    return;
  }
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main() {

  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p = -1;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != -1){
      T[l].p = v;
    }
    if(r != -1){
      T[r].p = v;
    }
  }

  for(i=0;i<n;i++){
    if(T[i].p == -1){
      root = i;
    }
  }

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 620
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
#define S    1048576
using namespace std;
char I[S+1],*Is=I,*It=I;
//inline char gc(){return Is==It?((It=(Is=I)+fread(I,1,S,stdin))==I?EOF:*Is++):*Is++;}
char gc(){return getchar();}
int gi(){
    char c=gc();
    int x=0;
    while(c<48)c=gc();
    while(c>47)x=x*10+c-48,c=gc();
    return x;
}
int n,tot,b[200005],c[200005],nx[200005],he[100005],s[100005];
ll ans;
void add(int x,int y,int z){
    ++tot;
    b[tot]=y,c[tot]=z;
    nx[tot]=he[x],he[x]=tot;
}
void dfs(int x,int y){
    s[x]=1;
    int ss=0;
    for(int i=he[x];i;i=nx[i]){
        int z=b[i];
        if(y==z) continue;
        dfs(z,x);
        s[x]+=s[z];
        ans+=c[i]*2ll*min(s[z],n-s[z]);
        if(s[z]*2==n)ans-=c[i];
        if(s[z]>ss)ss=s[z];
    }
    if(n-s[x]>ss)ss=n-s[x];
    if(ss*2<n){
        int o=orz;
        for(int i=he[x];i;i=nx[i])if(c[i]<o)o=c[i];
        ans-=o;
    }
}
int main(){
    n=gi();
    for(int i=1;i<n;++i){
        int x,y,z;
        x=gi();y=gi();z=gi();
        add(x,y,z);
        add(y,x,z);
    }
    dfs(1,0);
    printf("%lld\n",ans);
   // system("pause");
    return 0;
}


Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		String s = in.next();
		int c = 1;
		for(int i = 0;i<3-1;i++) {
			char[] ch = s.toCharArray();
			
			 if(ch[i] =='S' && ch[i+1] == 'S') {
				c=0;
			}
			else if((ch[i]=='R' && ch[i+1] == 'R')){
				c++;
			}
			else if((ch[i] == 'S' && ch[i+1] == 'R')) {
				c=1;
			}
			 if(s.charAt(0) == 'R' && s.charAt(1) == 'S' && s.charAt(2)== 'S'){
				c=1;
			}
			
			
			
			
			
		}
		System.out.println(c);

	}

}


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

int main() {
    int N;
    cin >> N;
    vector<int> k({1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51});
    
    
    
    cout << k[N-1] << endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            string s = ReadString();
            bool answer = s.Zip(s.Skip(1), (left, right) => left == right).All(b => !b);
            Console.WriteLine(answer ? "Good" : "Bad");
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//
 
int main() {
	string s;
	cin >> s;
	cout << s.substr(0, s.size() - 8) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c;
	cin >> a >> b >> c;
	if (a==b && a!=c)
	{
		cout << "Yes";
	}
	else if (a==c && a!=b)
	{
		cout << "Yes";
	}
	else if (c==b && c!=a)
	{
		cout << "Yes";
	}
	else
	cout  << "No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	string N;
	cin >> N;
	if(N[0]=='7'||N[1]=='7'||N[2]=='7') cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

int insertionSort(int A[], int n, int g)
{
	int cnt = 0;
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
	return cnt;
}

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

	int cnt = 0;
	int m = 0;
	int nn = n;
	int G[100];

	while (nn > 0){
		m++;
		nn = nn/2;
	}

	for (int i = 0; i < m; i++)
	{
		G[i] = pow(2, m - i - 1);
		cnt += insertionSort(A, n, G[i]);
	}

	cout << m << endl;
	for (int i = 0; i < m; i++)
		cout << G[i] << " ";
	cout << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
		cout << A[i] << endl;

	return 0;
}


Measured memory_bytes: 7120