akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		long[] a = sc.nextLongArray(n);
		Arrays.sort(a);
		Deque<Long> aDeque = new ArrayDeque<>();
		for(long i : a)
			aDeque.add(i);
		long sum = calc(new ArrayDeque<>(aDeque));
		aDeque = new ArrayDeque<>(aDeque.stream().sorted(Collections.reverseOrder()).collect(Collectors.toList()));
		System.out.println(Math.max(sum, calc(aDeque)));
	}
	
	private static long calc(Deque<Long> aDeque) {
		Deque<Long> deque = new ArrayDeque<>();
		deque.add(aDeque.pollFirst());
		while(!aDeque.isEmpty()) {
			deque.addLast(aDeque.pollLast());
			if(!aDeque.isEmpty())
				deque.addFirst(aDeque.pollLast());
			if(!aDeque.isEmpty())
				deque.addLast(aDeque.pollFirst());
			if(!aDeque.isEmpty())
				deque.addFirst(aDeque.pollFirst());
		}
		long start = deque.poll();
		long sum = 0;
		while(!deque.isEmpty()) {
			long i = deque.poll();
			sum += Math.abs(start - i);
			start = i;
		}
		return sum;
	}
}

class Scanner {
	private static final int SPACE = (int)' ';
	private static final int LINE_END_0 = 13;
	private static final int LINE_END_1 = 10;
	private static final int BEFORE = -1;
	private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public String next(){
		StringBuilder sb = new StringBuilder();
		
		int length = BEFORE;
		readLoop: while(true) {
			try {
				int value = br.read();
				switch(value) {
				case LINE_END_1:
					if(length == BEFORE)
						break;
					
					if((int)sb.charAt(length) == LINE_END_0)
						sb.deleteCharAt(length);
				case SPACE:
					break readLoop;
				}
				sb.append((char)value);
				length++;

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	public String[] nextArray(int length) {
		String[] array = new String[length];
		for(int i = 0; i < length; i++)
			array[i] = next();
		return array;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public double[] nextDoubleArray(int length) {
		double[] array = new double[length];
		for(int i = 0; i < length; i++)
			array[i] = nextDouble();
		return array;
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public int[] nextIntArray(int length) {
		int[] array = new int[length];
		for(int i = 0; i < length; i++)
			array[i] = nextInt();
		return array;
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public long[] nextLongArray(int length) {
		long[] array = new long[length];
		for(int i = 0; i < length; i++)
			array[i] = nextLong();
		return array;
	}
	
	public boolean ready() {
		try {
			return br.ready();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}


Measured memory_bytes: 46488
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int R = sc.nextInt();
        if(N < 10){
          System.out.println(R + 100*(10 - N));        	
        }else{
        	System.out.println(R); 
        }
    }
}

Measured memory_bytes: 20948
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))
#define N 100005

int n, m;
vector<vi> g;
int par[N];


int main(void) {
	scanf("%d%d", &n, &m);
	g.resize(n);
	REP(i, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--, b--;
		g[a].pb(b);
		g[b].pb(a);
	}

	queue<int> q;
	CL(par, -1);

	q.push(0);
	while (sz(q)) {
		int v = q.front();
		q.pop();

		REP(i, sz(g[v])) {
			int u = g[v][i];

			if (par[u] == -1) {
				par[u] = v;
				q.push(u);
			}
		}
	}

	printf("Yes\n");
	FOR(i, 1, n) {
		printf("%d\n", par[i] + 1);
	}


	return 0;
}



Measured memory_bytes: 10172
#include<stdio.h>

int FLAG1 = 0x1;
int FLAG2 = 0x02;
int FLAG3 = 0x04;
int FLAG4 = 0x08;

int main() {
	int N;
	int a, b, c, d;
	scanf("%d", &N);

	a = N / 1000;
	b = (N - 1000 * a) / 100;
	c = (N - 1000 * a - 100 * b) / 10;
	d = N - (1000 * a + 100 * b + 10 * c);

	for (int i = 0; i < 2 ^ 4; i++) {
		int value = 0;
		if (i & FLAG1) value = value + a;
		else continue;

		if (i & FLAG2) value = value + b;
		else value = value - b;

		if (i & FLAG3) value = value + c;
		else value = value - c;

		if (i & FLAG4) value = value + d;
		else value = value - d;

		if (value == 7) {
			printf("%d%s%d%s%d%s%d=7", a, (i & FLAG2) ? "+" : "-", b, (i & FLAG3) ? "+" : "-", c, (i & FLAG4) ? "+" : "-", d);
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>

using namespace std;

struct Trie {
	Trie() : finish(false), code(0) {
		n[1] = n[0] = NULL;
	};
	Trie *n[2];
	bool finish;
	char code;
};

void add(Trie& t, const char *codes, char c){
	Trie *cur;
	cur = &t;
	for (int i = 0; codes[i]; i++){
		int v = codes[i] == '1';
		if (cur->n[v] == NULL){
			cur->n[v] = new Trie();
		}
		cur = cur->n[v];
	}
	cur->finish = true;
	cur->code = c;
}

int main()
{
	char E[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

	Trie R;
	add(R,"101", ' ');
	add(R,"000000", '\'');
	add(R,"000011", ',');
	add(R,"10010001", '-');
	add(R,"010001", '.');
	add(R,"000001", '?');
	add(R,"100101", 'A');
	add(R,"10011010", 'B');
	add(R,"0101", 'C');
	add(R,"0001", 'D');
	add(R,"110", 'E');
	add(R,"01001", 'F');
	add(R,"10011011", 'G');
	add(R,"010000", 'H');
	add(R,"0111", 'I');
	add(R,"10011000", 'J');
	add(R,"0110", 'K');
	add(R,"00100", 'L');
	add(R,"10011001", 'M');
	add(R,"10011110", 'N');
	add(R,"00101", 'O');
	add(R,"111", 'P');
	add(R,"10011111", 'Q');
	add(R,"1000", 'R');
	add(R,"00110", 'S');
	add(R,"00111", 'T');
	add(R,"10011100", 'U');
	add(R,"10011101", 'V');
	add(R,"000010", 'W');
	add(R,"10010010", 'X');
	add(R,"10010011", 'Y');
	add(R,"10010000", 'Z');

	char str[4048];
	while (fgets(str, sizeof(str), stdin)){
		Trie *cur = &R;
		for (int i = 0; str[i] != '\n'; i++){
			int index;
			for (index = 0; E[index] && E[index] != str[i]; index++);
			for (int j = 4; j >= 0; j--){
				cur = cur->n[(index >> j) & 1];
				if (cur->finish){
					cout << cur->code;
					cur = &R;
				}
			}
		}
		cout << endl;
	}
	return (0);
}

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

int n, m;
vector<vector<int> > g(8);
bool visited[8];
int dfs(int cur, bool visited[8]) {
    ll ans = 0;
    bool all_visited = true;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            all_visited = false;
        }
    }

    if (all_visited) {
        return 1;
    }
    for (int i = 0; i < g[cur].size(); i++) {
        int next = g[cur][i];
        if (!visited[next]) {
            visited[next] = true;
            ans += dfs(next, visited);
            visited[next] = false;
        }
    }

    return ans;
}

int main() {
    cin >> n >> m;
    g.resize(n);
    for (int i = 0; i < n; i++) {
        visited[i] = false;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    visited[0] = true;
    ll ans = dfs(0, visited);


    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool j;
int main()
{
    string a;cin>>a;
    for(int i=0;i<a.length();++i)
    {
        if(a[i]=='C')
        {
            j=1;
        }
        if(a[i]=='F'&&j==1)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
    x=0;char ch;bool flag = false;
    while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 2048;
struct Edge{
    int to,next;
}G[maxn<<1];
int head[maxn],cnt;
void add(int u,int v){
    G[++cnt].to = v;
    G[cnt].next = head[u];
    head[u] = cnt;
}
#define v G[i].to
int dep[maxn];
void dfs(int u,int f){
    for(rg i = head[u];i;i=G[i].next){
        if(v == f) continue;
        dep[v] = dep[u] + 1;
        dfs(v,u);
    }
}
#undef v
struct Node{
    int u,v;
}e[maxn];
int main(){
    int n,K;read(n);read(K);
    int u,v;
    rep(i,2,n){
        read(u);read(v);
        e[i].u = u;e[i].v = v;
        add(u,v);add(v,u);
    }
    int ans = 0x3f3f3f3f;
    if((K&1) == 0){
        int res = 0;
        rep(i,1,n){
            res = dep[i] = 0;dfs(i,i);
            rep(j,1,n) if(dep[j] > (K >> 1)) ++ res;
            ans = min(ans,res);
        }
    }else{
        int res = 0;
        rep(i,2,n){
            dep[e[i].u] = dep[e[i].v] = res = 0;
            dfs(e[i].u,e[i].v);dfs(e[i].v,e[i].u);
            rep(j,1,n){
                if(dep[j] > (K >> 1)) ++ res;
            }ans = min(ans,res);
        }
    }printf("%d\n",ans);
    return 0;
}


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

int main(){
    int a, b, d, r;
    scanf("%d %d", &a, &b);
    double f;
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;
    printf("%d %d %.8lf\n", d, r, f);
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 400005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next,val;
}E[MAXN * 10];
int head[MAXN],sumE;
int N,M,Ncnt;
int c[MAXN],dis[MAXN];
vector<int> to[MAXN];
bool vis[MAXN];
priority_queue<pii > Q;
void add(int u,int v,int c) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    E[sumE].val = c;
    head[u] = sumE;
}
void Solve() {
    read(N);read(M);
    int q,p;
    Ncnt = M;
    for(int i = 1 ; i <= M ; ++i) {
	read(q);read(p);read(c[i]);
	to[q].pb(i);to[p].pb(i);
    }
    for(int i = 1 ; i <= N ; ++i) {
	sort(to[i].begin(),to[i].end(),[](int a,int b) {return c[a] < c[b];});
	int nw = ++Ncnt;
	for(int j = 0 ; j < to[i].size() ; ++j) {
	    int p = j;
	    while(p < to[i].size() - 1 && c[to[i][p + 1]] == c[to[i][j]]) ++p;
	    for(int h = j + 1 ; h <= p ; ++h) {
		add(to[i][j],to[i][h],0);
		add(to[i][h],to[i][j],0);
	    }
	    add(to[i][j],nw,0);
	    add(nw,to[i][j],1);
	    j = p;
	}
    }
    for(int i = 1 ; i <= Ncnt ; ++i) dis[i] = 1e9;
    for(auto t : to[1]) {dis[t] = 1;Q.push(mp(-1,t));}
    while(!Q.empty()) {
	pii now = Q.top();Q.pop();
	if(vis[now.se]) continue;
	int u = now.se;vis[u] = 1;
	for(int i = head[u] ; i ; i = E[i].next) {
	    int v = E[i].to;
	    if(dis[v] > dis[u] + E[i].val) {
		dis[v] = dis[u] + E[i].val;
		Q.push(mp(-dis[v],v));
	    }
	}
    }
    int ans = 1e9;
    for(auto t : to[N]) ans = min(ans,dis[t]);
    if(ans >= 1e9) {
	puts("-1");return;
    }
    else {out(ans);enter;}
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

const int MAXN = 4e3 + 10, MOD = 1e9 + 7;
long long fi[MAXN], f[MAXN];
int n, k;
long long ch(int a, int b) {
	if (b < 0 || a - b < 0)
		return 0;
	return f[a] * fi[b] % MOD * fi[a - b] % MOD;
}

int main() {
	f[0] = fi[1] = 1;
	for (int i = 2; i < MAXN; i++)
		fi[i] = -(MOD / i) * fi[MOD % i] % MOD;
	fi[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		f[i] = f[i - 1] * i % MOD;
		fi[i] *= fi[i - 1], fi[i] %= MOD;
	}
	cin >> n >> k;
	for (int i = 1; i <= k; i++) {
		long long res = ch(k - 1, i - 1) * ch(n - k + 1, i) % MOD;
		if (res < 0)
			res += MOD;
		cout << res << '\n';
	}
}

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

namespace ABC082A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b,c;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            c = a + b;

            if (c % 2 == 0)
                Console.WriteLine(c / 2);

            else
                Console.WriteLine(c / 2 + 1);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			System.out.println((0 == (n % f(n)) ? "Yes" : "No"));
		}
	}

	/**
	 * 整数xを十進法で表したときの各桁の数字の和を求める
	 * 
	 * @param x 入力数字
	 * @return 整数xを十進法で表したときの各桁の数字の和
	 */
	private static int f(int x) {
		int result = 0;
		while (x > 0) {
			result += x % 10;
			x /= 10;
		}
		return result;
	}
}


Measured memory_bytes: 35788
H, W = map(int, input().split())
S = [input() for _ in range(H)]
ans = []
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
for x in range(H):
  tmp = ""
  for y in range(W):
    num = 0
    if S[x][y] == "#":
      tmp += "#"
      continue
    for k in range(8):
      cx = x + dx[k]
      cy = y + dy[k]
      if cx < 0 or cx >= H or cy < 0 or cy >= W:
        continue
      if S[cx][cy] == "#":
        num += 1
    tmp += str(num)
  ans.append(tmp)
  
for i in range(H):
	for j in range(W):
		print(ans[i][j],end = "")
	print("")

Measured memory_bytes: 3444
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//[[iwi]]
public class Main{

	class R{
		int l, r;
		List<R> adj;
		public R(int l, int r) {
			this.l = l;
			this.r = r;
			adj = new ArrayList<R>();
		}
		public void f(int depth){
			max = Math.max(max, depth);
			for(R a:adj){
				a.f(depth+1);
			}
		}
	}
	
	int max;
	
	void run(){
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int l, r;
		l = r = -1;
		int n = s.length;
		for(int i=0;i<n;i++){
			if(s[i]=='w'){
				l = i-1;
				r = i+2;
				break;
			}
		}
		List<R> list = new ArrayList<R>();
		for(int i=0;i<l;i++){
			char c1 = s[i];
			for(int j=r;j<n;j++){
				if(c1=='('&&s[j]==')'||
						c1==')'&&s[j]=='('||
						c1=='{'&&s[j]=='}'||
						c1=='}'&&s[j]=='{'||
						c1=='['&&s[j]==']'||
						c1==']'&&s[j]=='[')list.add(new R(i,j));
			}
		}
		for(R a:list){
			for(R b:list){
				if(a.l<b.l&&a.r>b.r)a.adj.add(b);
			}
		}
		max = 0;
		for(R a:list)a.f(1);
		System.out.println(2*max+3);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    dp=[0]*3
    ndp=copy(dp)
    for i in range(N):
        a,b,c=S[i]
        ndp[0]=max(dp[1]+a,dp[2]+a)
        ndp[1]=max(dp[0]+b,dp[2]+b)
        ndp[2]=max(dp[1]+c,dp[0]+c)
        ndp,dp=dp,ndp
    print(max(dp))



if __name__ == "__main__":
    main()

Measured memory_bytes: 21172
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i <= (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll x = n/(a+b)*a, y = min(n%(a+b),a);
    dunk(x+y);
}

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

int main() {

    ll n, k; cin >> n >> k;
	vector<pair<ll, ll>> pa;
	for (int i = 0; i < n; i++) {
		ll a, b; cin >> a >> b;
		pa.push_back({ a,b });
	}
	sort(pa.begin(), pa.end());

	ll sum = 0;
	ll ans;
	for (int i = 0; i < n; i++) {		
		sum += pa[i].second;
		if (k <= sum) {
			ans = pa[i].first;
			break;
		}
	}

	cout << ans << endl;
	return 0;
}

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

using namespace std;

int n, m, p;
int x[500], y[500];
int pegs[10][10][10];
int z_idx[10][10];

int dx[] = {0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1};
int dy[] = {0, -1, -1, -1, -1, -1, -1,  0,  0,  0,  1,  1,  1};
int dz[] = {-1, -1,  0,  1, -1,  0,  1, -1,  0,  1, -1,  0,  1};

bool sequence(int x, int y, int z)
{
  for(int i = 0; i < 13; i++){
    int seq = 1;
    int nx = x, ny = y, nz = z;
    while(1){
      nx += dx[i], ny += dy[i], nz += dz[i];
      if(nx < 0 || n <= nx || ny < 0 || n <= ny || nz < 0 || n <= nz) break;
      if(pegs[nx][ny][nz] != pegs[x][y][z]) break;
      seq++;
    }
    nx = x, ny = y, nz = z;
    while(1){
      nx -= dx[i], ny -= dy[i], nz -= dz[i];
      if(nx < 0 || n <= nx || ny < 0 || n <= ny || nz < 0 || n <= nz) break;
      if(pegs[nx][ny][nz] != pegs[x][y][z]) break;
      seq++;
    }
    if(seq >= m) return true;
  }
  return false;
}

int simulation(int t)
{
  if(t == p) return -1;
  pegs[x[t]][y[t]][z_idx[x[t]][y[t]]] = t % 2;
  if(sequence(x[t], y[t], z_idx[x[t]][y[t]])) return t;
  z_idx[x[t]][y[t]]++;
  simulation(t + 1);
}

int main()
{
  while(cin >> n >> m >> p, n || m || p){
    for(int i = 0; i < p; i++) cin >> x[i] >> y[i], x[i]--, y[i]--;
    memset(pegs, -1, sizeof(pegs));
    memset(z_idx, 0, sizeof(z_idx));
    int ans = simulation(0);
    if(ans == -1) cout << "Draw" << endl;
    if(ans%2 == 0) cout << "Black " << ans+1 << endl;
    if(ans%2 == 1) cout << "White " << ans+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>

int partition(int*,int,int);

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

  scanf("%d",&n);

  int A[n];

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

  x=partition(A,0,n-1);
  for(i=0;i<x;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[i]);
  for(i+=1;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  return 0;
}
  
int partition(int *A,int p,int r){
  int x=0,hako=0;
  int i,j;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      hako=A[i];
      A[i]=A[j];
      A[j]=hako;
    }
  }
  hako=A[i+1];
  A[i+1]=A[r];
  A[r]=hako;

  return i+1;
}



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

int main() {
int W,H,x,y,r;
cin>>W>>H>>x>>y>>r;
if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H){
  cout<<"Yes"<<endl;
}else{
  cout<<"No"<<endl;
}
return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<vector>

using namespace std;

void funcA() {
  string s;
  cin >> s;

  if (s[s.size() - 1] == 's') {
    s += "es";
  }
  else s += 's';

  cout << s;
}

void funcB() {
  int n;
  cin >> n;
  int d1, d2;

  int count = 0;
  for (int i = 0; i < n; ++i) {
    cin >> d1 >> d2;
    if (d1 == d2) ++count;
    else count = 0;

    if (count == 3) {
      cout << "Yes\n";
      return;
    }
  }

  cout << "No\n";


}

void funcC() {
  int n;
  cin >> n;

  int count = 0;
  for (int a = 1; a < n; ++a) {
    int tmp_count = 0;
    
    if (n % a == 0) tmp_count += n / a - 1;
    else tmp_count += n / a;

    count += tmp_count;
  }

  cout << count;
}

void funcD() {

}

int main() {

  //funcA();
  //funcB();
  funcC();

  return 0;
}

Measured memory_bytes: 3620
dishes = [int(input()) for i in range(5)]
dishes.sort(key=lambda x: (x-1)%10, reverse=True)
res = 0

for i in range(len(dishes)):
    if i == len(dishes) - 1:
        res += dishes[i]
    elif dishes[i] % 10 != 0:
        res += (dishes[i] // 10 + 1) * 10
    else:
        res += dishes[i]

print(res)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

int flag[1000005];
int ji[1000005];
int chu[1005][1005];
int pos[1005];
int main()
{
	int n;
	scanf("%d", &n);
	pos[1] = 1;
	for(int i = 2; i <= 1000; i++) pos[i] = 2;
	for(LL i = 1; i <= 100000; i++)
	{
		LL p = i * (i + 1) / 2;
		if(p > 100000) break;
		ji[p] = i;
		flag[p] = 1;
	}
	if(n == 1) {
		printf("Yes\n");
		printf("2\n1 1\n1 1\n");
	}
	else if(n == 2) {
		printf("No\n");
	}
	else if(n == 3) {
		printf("Yes\n");
		printf("3\n2 1 2\n2 3 1\n2 2 3\n");
	}
	else {
		if(flag[n] == 1) {
			printf("Yes\n");
			printf("%d\n", ji[n] + 1);
			int w = ji[n] + 1;
			int q = ji[n];
			int tot = 1;
			int fl = 0;
			for(int i = 1; i <= 2; i++)
			{
				for(int j = 1; j <= q; j++)
				{
					chu[i][j] = tot;
					tot++;
				}
				tot--;
			}
			tot++;
			for(int i = 3; i <= w; i++)
			{
				pos[i] = i;
				for(int j = 1; j <= q; j++)
				{
					if(j < i) {
						chu[i][j] = chu[j][pos[j]];
						pos[j]++;
					}
					else {
						chu[i][j] = tot;
						tot++;
					}
				}
			}
			for(int i = 1; i <= w; i++)
			{
				printf("%d ", q);
				for(int j = 1; j <= q; j++)
				{
					if(j == q) printf("%d\n", chu[i][j]);
					else printf("%d ", chu[i][j]);
				}
			}
		}
		else printf("No\n");
	}
}

Measured memory_bytes: 11264
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <iomanip>
#include <cfloat>
#include <cmath>
#include <math.h>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
vector <double > a;





int main()
{

	cin >> N;

	a.resize(N);
	cin >> a[0];
	FOR(i,1,N){
		cin >> a[i];
		a[i] += a[i-1];
	}
	double ans = DBL_MAX;
	REP(i,N-1){
		ans = min(ans,fabs((double)2*a[i]-a[N-1]));
	}
	cout << fixed << setprecision(0) << ans << endl;


}

Measured memory_bytes: 1792
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
int K;
int A[200000];
int main(){
  long long ok;
  long long mx;
  long long res;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  {
    int e98WHCEY;
    int cTE1_r3A;
    if(N==0){
      cTE1_r3A = 0;
    }
    else{
      cTE1_r3A = A[0];
      for(e98WHCEY=(1);e98WHCEY<(N);e98WHCEY++){
        cTE1_r3A = max_L(cTE1_r3A, A[e98WHCEY]);
      }
    }
    mx =cTE1_r3A;
  }
  long long xr20shxY;
  long long WYIGIcGE;
  long long t_ynMSdg;
  xr20shxY = 1;
  WYIGIcGE = mx;
  while(xr20shxY < WYIGIcGE){
    int i;
    if((xr20shxY + WYIGIcGE)%2==0){
      t_ynMSdg = (xr20shxY + WYIGIcGE) / 2;
    }
    else{
      t_ynMSdg = (xr20shxY + WYIGIcGE - 1) / 2;
    }
    ok = 0;
    for(i=(0);i<(N);i++){
      ok += (A[i]-1) / t_ynMSdg;
    }
    if(ok <= K){
      WYIGIcGE = t_ynMSdg;
    }
    else{
      xr20shxY = t_ynMSdg + 1;
    }
  }
  res =WYIGIcGE;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, K, A[2d5];
// {
//   ll ok, mx;
//   ll res;
//   rd(N,K,A(N));
//   mx = max(A(N));
//   res = bsearch_min[ll,x,1,mx][
//     ok = 0;
//     rep(i,N) ok += (A[i]-1) / x;
//   ](ok <= K);
//   wt(res);
// }


Measured memory_bytes: 5404
#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,k;
    cin >> n >> k;
    double ans=0;
    rep(i,n){
        ll a = i+1;
        if(a>=k){
            ans += (double)1/n;
        }else{
            int cnt=0;
            while(a<k)
            {
                a*=2;
                cnt++;
            }
            ans += ((double)1/pow(2,cnt)) * ((double)1/n);
        }
    }
    cout << fixed << setprecision(9)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,i,max=0;
	int ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		int h;
		scanf("%d",&h);
		if(h>=max){
			max=h;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int cnt=0;
    for(int i=1; i<s.length(); i++) {
        if(s[i]!=s[i-1]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



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


static const double pi = 3.141592653589793;
int main() {
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    
    double ta,tb;
    
    ta = 2 * pi * ( H + M/60.0) / 12.0;
    tb = 2 * pi * M/60.0;
    
    double xa,ya,xb,yb;
    
    xa = A * cos(ta);
    ya = A * sin(ta);
    xb = B * cos(tb);
    yb = B * sin(tb);

    double ans;
    
    ans = sqrt( (xa - xb) * (xa - xb) + (ya - yb) * (ya - yb) );
    
    //cout << ans << endl;
    printf("%10.10f", ans);
    
    return 0;
}


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

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n = line.length;
        int[] arr = new int[n];
        int count = 0;
        int temp;

        int v1;
        int v2;
        Integer ans;
        ArrayDeque<Integer> stk = new ArrayDeque<Integer>();
        for(int i = 0; i < n; i++){
            if(line[i].equals("+")){
                v1 = stk.pop().intValue();
                v2 = stk.pop().intValue();
                ans = Integer.valueOf(v1 + v2);
                stk.push(ans);
            }else if(line[i].equals("-")){
                v1 = stk.pop().intValue();
                v2 = stk.pop().intValue();
                ans = Integer.valueOf(v2 - v1);
                stk.push(ans);
            }else if(line[i].equals("*")){
                v1 = stk.pop().intValue();
                v2 = stk.pop().intValue();
                ans = Integer.valueOf(v1 * v2);
                stk.push(ans);
            }else{
                stk.push(Integer.valueOf(line[i]));
            }
        }
        System.out.println(stk.pop().intValue());
        
        



    }
}

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


int main(){
  ll h,a,b;
  cin >> h;
  while(h > 1){
    h /= 2;
    ++a;
  }
  b = pow(2,a);
  cout << 2 * b - 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int S,h,m,s, T;
  scanf("%d",&S);
   
  h=S/3600;
  T=S%3600;
  m=T/60;
  s=T%60;
 
printf("%d:%d:%d\n",h,m,s);
 
return 0;
}


Measured memory_bytes: 2100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
		int max = Math.max(a,Math.max(b,c));
		int ans = a+b+c-max;
		ans += max*(int)Math.pow(2,sc.nextDouble());
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 22484
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if(a > b){
    swap(a,b);
  }
  for(int i = 0; i < b; i++){
    cout << a;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;

int main(){
    int N;
    cin>>N;
    vector<vector<int>>A(2,vector<int>(N));
    int sum1=0,sum2=0;
    int sum=0;
    int maxi=0;
    rep(i,2){
        rep(j,N){
            cin>>A[i][j];
        }
    }
    
    rep(i,N){
        rep(j,i+1){
            sum+=A[0][j];
        }

        FOR(j,i,N){
            sum+=A[1][j];
        }
        
        maxi=max(maxi,sum);
        sum=0;
    }

    cout<<maxi<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }

    vector<vector<ll>> W(8, vector<ll> (N));
    for (int i = 0; i < 8; i++) {
        if(i & 1){
            for (int j = 0; j < N; j++) {
                W[i][j] = x[j];
            }
        }
        else{
            for (int j = 0; j < N; j++) {
                W[i][j] = -x[j];
            }
        }

        if(i & 2){
            for (int j = 0; j < N; j++) {
                W[i][j] += y[j];
            }
        }
        else{
            for (int j = 0; j < N; j++) {
                W[i][j] -= y[j];
            }
        }

        if(i & 4){
            for (int j = 0; j < N; j++) {
                W[i][j] += z[j];
            }
        }
        else{
            for (int j = 0; j < N; j++) {
                W[i][j] -= z[j];
            }
        }
    }

    for (int i = 0; i < 8; i++) {
        sort(ALL(W[i]), greater<ll> ());
    }

    ll tmp;
    ll ans = 0;
    for (int i = 0; i < 8; i++) {
        tmp = 0;
        for (int j = 0; j < M; j++) {
            tmp += W[i][j];
        }
        ans = max(ans, tmp);
    }
    printf("%lld\n", ans);

}

Measured memory_bytes: 3752
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    S[K-1]=tolower(S[K-1]);

    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

ll power(ll x, ll pw, ll mod) {
    ll res = 1;
    x = x % mod;  // if it x >= p
    while (pw > 0) {
        if (pw & 1)
            res = (res*x) % mod;
        pw /= 2;
        x = (x*x) % mod;
    }
    return res;
}
ll modInverse(ll n, ll p) {
    return power(n, p-2, p) % p; // Fermat's little theorem
}
ll nCr(ll n, ll m, ll mod=1e9+7) {
    m = min(m, n-m);
    if (m == 0) return 1;
    ll num = 1, dem = 1;
    for(ll i = 1; i <= m; i++) {
        num = (num*(n+1-i)) % mod;
        dem = (dem*(i)) % mod;
    }
    return (num * modInverse(dem, mod)) % mod;
}

int main() {
    //
    // freopen("max_03", "r", stdin);
    ll n, k;
    ll mod = 1e9 + 7;
    cin >> n >> k;
    vector<ll> arr(n, 0);
    for(ll& val: arr)
        cin >> val;
    sort(arr.begin(), arr.end());
    ll ans = 0;
    ll NCR = nCr(n-1, k-1);
    for(ll i = n-1; i >= k-1; i--) {
        // nCr(i, k-1)
        ans += (NCR * ((arr[i]-arr[n-1-i]) % mod)) % mod;
        // cout << "NCR = " << NCR << ", nCr(i, k-1) = " << nCr(i, k-1) << endl;
        // ll mul = (n+1-k) * (modInverse(k+1, mod)) % mod;
        // dp: nCr(n, k+1) = (nCr(n, k) * mul) % mod;
        ll mul = (i-(k-1)) * modInverse(i, mod) % mod;
        NCR = (NCR * mul) % mod;
        ans = (ans + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>

#define REP(i, n) for (int i=0;i<(n);i++)
#define FOR(i, a, b) for (int i=(a);i<(b);i++)

using namespace std;

int N;
int A[200001];

int main()
{
    scanf("%d ", &N);
    REP(i, N) {
        scanf("%d ", &A[i]);
    }

    int C[22];
    REP(i, 22)
        C[i] = 0;
    

    //しゃくとり
    long long int ans = 0;
    int tmp = 0;
    int r = 0;
    REP(l, N) {
        bool flag = true;
        while(r<N && flag) {
            int tmp[22];
            REP(i, 22) {
                tmp[i] = A[r]&(1<<i);
                if(C[i]==1 && tmp[i]>0) {
                    flag = false;
                }
            }
            if(flag) {
                r++;
                REP(i, 22)
                    C[i] += tmp[i]/(1<<i);
            }
        }
        ans += r - l;
        REP(i, 22)
            C[i] -= (A[l]&(1<<i))/(1<<i);
    }

    printf("%lld\n", ans);


    return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    long long n,d;
    cin>>n>>d;
    d=d*d;
    //cout<<d;
    int res=0;
    for(int i=0;i<n;i++)
    {
        long long x,y;
        cin>>x>>y;
        if(x*x+y*y<=d)
            res++;
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 3688
#include <stdio.h>
int main(void){
    int h1,m1,h2,m2,k,h1_m,h2_m,d;
    
    scanf("%d %d %d %d %d", &h1,&m1,&h2,&m2,&k);
    
    h1_m=h1*60;
    h2_m=h2*60;
    d=h2_m+m2-(h1_m+m1)-k;
    
    printf("%d\n",d);
    
    return 0;
}


Measured memory_bytes: 1732
#include<cstdio>
#include<iostream>
#define neko 100005
#define heko 405
#define qwq return putchar('Y'),putchar('E'),putchar('S'),0; 
#define orz return putchar('N'),putchar('O'),0; 
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
static int n,H;
typedef int arr[heko];
static arr fa,book,dg,out;
const unsigned int bufsize=1<<16,outsize=1<<16;
static char ch[bufsize],*S=ch,*T=ch;
inline char getc()
{return ((S==T)&&(T=(S=ch)+fread(ch,1,bufsize,stdin),S==T)?0:*S++);}
static char Out[outsize],*nowp=Out;
inline void flush(){fwrite(Out,1,nowp-Out,stdout);nowp=Out;}
	template<typename T>
void read(T &x)
{
	char c=getc();x=0;
	for(;!isdigit(c);c=getc());
	for(;isdigit(c);x=(x<<1)+(x<<3)+(c^'0'),c=getc());
}
inline int find(int x){return fa[x]^x?fa[x]=find(fa[x]):x;}
int main()
{
	int x,y,z,o,X,Y,HH;
	read(n),read(H),HH=H<<1;
	f(i,0,HH)fa[i]=i;
	f(i,1,n)
	{
		read(x),read(y),read(z),read(o);
		X=z?H-z:H+x;
		Y=o?H+o:H-y;
		book[X]=book[Y]=1;
		//++dgi[Y],++dgo[X];
		--dg[Y],++dg[X];
		fa[find(Y)]=find(X);

	}
	f(i,0,H)if(dg[i]>0)orz;
	f(i,H+1,HH)if(dg[i]<0)orz;
	f(i,0,HH)out[fa[i]]|=dg[i];
	f(i,0,HH)if(fa[i]==i&&book[i]&&!out[fa[i]])orz;
	qwq;
}

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


def f(N):
  if N%2==0:
    return N//2
  return 3*N+1

N = s
if N == 1 or N == 2 or N == 4:
    print(4)
else:
    for i in range(1000000):
      N = f(N)
      if N == 4:
        print(i+5)
        break

Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>

struct team{
    char n[21];
    int p;
}t[10];

int compare(const void *a,const void *b){
    return ((struct team *)b) -> p - ((struct team *)a) -> p;
}

int main(void){
    int i,n,w,l,e,f=0;

    while(scanf("%d",&n),n){
if(f)puts("");
f++;
        for(i = 0;i < n;i++){
            scanf("%s%d%d%d",t[i].n,&w,&l,&e);
            t[i].p = 3 * w + e;
        }

        qsort(t,n,sizeof(struct team),compare);
        for(i = 0;i < n;i++)printf("%s,%d\n",t[i].n,t[i].p);
    }
    return 0;
}

Measured memory_bytes: 620
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.HashSet;
import java.util.List;

class Main{
    static double mod = 1e9+7;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Library lib = new Library();
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();
        sc.close();
        int u1 = ty-sy;
        int r1 = tx-sx;
        int u2 = (ty+1)-sy;
        int r2 = (tx+1)-sx;
        for (int i=0;i<u1;i++){
            System.out.print("U");
        }
        for (int i=0;i<r1;i++){
            System.out.print("R");
        }
        for (int i=0;i<u1;i++){
            System.out.print("D");
        }
        for (int i=0;i<r1;i++){
            System.out.print("L");
        }
        System.out.print("L");
        for (int i=0;i<u2;i++){
            System.out.print("U");
        }
        for (int i=0;i<r2;i++){
            System.out.print("R");
        }
        System.out.print("DR");
        for (int i=0;i<u2;i++){
            System.out.print("D");
        }
        for (int i=0;i<r2;i++){
            System.out.print("L");
        }
        System.out.println("U");
    }
}

class Library{
    static long a;
    static long b;

    public static long gcd(long a,long b){
        Library lib = new Library();
        if (a<b){
            lib.swap(a,b);
        }
        if (b==0){
            return a;
        } else {
            return gcd(b,a%b);
        }
    }

    public static void swap(long a,long b){
        long x = a;
        a = b;
        b = x;
        return;
    }
}

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

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n);
map<int,int> num;
ll sum=0;
rep(i,n){
    cin>>a[i];
    num[a[i]]++;
    sum+=a[i];
}
int q;
cin>>q;

rep(i,q){
    int b,c;
    cin>>b>>c;
    ll numb=num[b];
    if(numb>0){
        sum-=numb*b;
        sum+=numb*c;
        num[c]+=numb;
        num[b]=0;
    }
    cout<<sum<<endl;
}

return 0;
}

Measured memory_bytes: 7888
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
//ios::sync_with_stdio(false);
//<< setprecision(5)
const int mod=1000000007;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
vector<vector<pair<int,int>>>ko;
vector<pair<int,int>>oya;//距離,番号
vector<pair<int,int>> zyu;//距離、番号
int main(void){
	int H,W,i,j;
	cin>>H>>W;
	vector<string>ans(H);
	for(i=0;i<H;i++){cin>>ans[i];ans[i].pob();ans[i].erase(ans[i].begin());}
	string full,none;
	for(j=0;j<W-2;j++){full.pub('#');}
	for(j=0;j<W;j++){none.pub('.');}
	cout<<none<<endl;
	for(i=1;i<H-1;i++){
		cout<<'#';
		if(i%2==0){cout<<ans[i];}
		else{cout<<full;}
		cout<<'.'<<endl;
	}
	cout<<none<<endl<<endl<<none<<endl;
	for(i=1;i<H-1;i++){
		cout<<'.';
		if(i%2==1){cout<<ans[i];}
		else{cout<<full;}
		cout<<'#'<<endl;
	}
	cout<<none<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
	int m,n,k;
	scanf("%d%d%d",&m,&n,&k);
	k=m*n-2*k;
	for(int i=-m;i<=m;i+=2){
		for(int j=-n;j<=n;j+=2){
			if(i*j==k){
				cout<<"Yes\n";
				return 0;
			}
		}
	}
	cout<<"No\n";
return 0;
}

Measured memory_bytes: 256
data = input().split()
N = int(data[0])
W = [int(line) for line in input().split()]

total1 = []
total2 = []
for i in range(1, N+1):
    S1 = 0
    for j in range(i):
        S1 += W[j]
    total1.append(S1)
    total2.append(sum(W)-S1)

diff = [abs(total1[i]-total2[i]) for i in range(len(total1))]
diff.sort()
ans = diff[0]
print(ans)

Measured memory_bytes: 38640
#include "bits/stdc++.h"
    #define in std::cin
    #define out std::cout
    #define rep(i,N) for(LL i=0;i<N;++i)
    typedef long long int LL;
     
    int main()
    {
    	LL N;
    	in >> N;
    	std::vector<LL>a(N + 1);
    	rep(i, N) in >> a[i + 1];
     
    	std::vector<LL>ans(N + 1);
    	for (LL i = N; i >= 1; --i)
    	{
    		if (i * 2 > N) ans[i] = a[i];
    		else
    		{
    			LL sum = 0;
    			for (LL j = i * 2; j <= N; j += i) sum += ans[j];
    			sum %= 2;
    			if (sum != a[i]) ans[i] = 1;
    		}
    	}
     
    	std::vector<LL>b;
    	for (LL i = 1; i <= N; ++i)
    	{
    		if (ans[i] == 1) b.push_back(i);
    	}
    	out << b.size() << std::endl;
    	rep(i, b.size()) out << b[i] << std::endl;
    }

Measured memory_bytes: 4980
S = input()
MIN = 10 ** 8
flag = 1
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        flag = 0
        MIN = min(MIN, max(i + 1, len(S) - i - 1))
if flag:
    MIN = len(S)
print(MIN)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
//17:25~

int main() {
  int n;
  cin >> n;
  int p[n];
  int sum=0;
  for(int i=0;i<n;i++)cin >> p[i];
  for(int i=1;i<n-1;i++){
    if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] && p[i]>p[i+1])){
      sum++;
    }
  }
  cout << sum << endl;
}



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

int main () {
  int N;
  cin >> N;
  int a1 = N%10, a2 = N/10%10, a3 = N/100%10, a4 = N/1000%10;
  if (a1 == a2) {
    if (a3 == a2) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else if (a3 == a4) {
    if  (a3 == a2) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import itertools
import math

N = int(input())
arr = [None] * N
for i in range(N):
  x, y = map(int, input().split())
  arr[i] = (x,y)

results = []
for v in itertools.permutations([i for i in range(N)], N):
  way = 0
  for i in range(N-1):
    way += ((arr[v[i+1]][0]-arr[v[i]][0])**2 + (arr[v[i+1]][1]-arr[v[i]][1])**2)**0.5
  results.append(way)
all = math.factorial(N)
print(sum(results)/all)

Measured memory_bytes: 4400