akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"strconv"
	"strings"
)

var a []string

func init() {
	for _, suit := range []string{"S", "H", "C", "D"} {
		for i := range make([]int, 13) {
			a = append(a, fmt.Sprintf("%s %s", suit, strconv.Itoa(i+1)))
		}
	}
}

func remove(strings []string, search string) []string {
	var result []string
	for _, v := range strings {
		if v != search {
			result = append(result, v)
		}
	}
	return result
}

func main() {
	var n int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		var suit, rank string
		fmt.Scan(&suit, &rank)

		a = remove(a, fmt.Sprintf("%s %s", suit, rank))
	}
	if len(a) > 0 {
		fmt.Println(strings.Join(a, "\n"))
	}
}



Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

const vector<int> dx4 = {-1,  0,  1,  0};
const vector<int> dy4 = { 0,  1,  0, -1};
const vector<int> dx8 = {-1, -1, -1,  0,  1,  1,  1,  0};
const vector<int> dy8 = {-1,  0,  1,  1,  1,  0, -1, -1};

int main(){
    int a, b, c, d;
    vector<int> t(105, 0);

    cin >> a >> b >> c >> d;

    for(int i = a; i < b; i++) t[i]++;
    for(int i = c; i < d; i++) t[i]++;

    int nCount = 0;

    for(int i = 0; i < t.size(); i++){
        if(t[i] == 2) nCount++;
    }

    cout << nCount << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);

    String str3 = br.readLine();
    String[] str4 = str3.split(" ");

    int max = Integer.MIN_VALUE;
    int min = Integer.MAX_VALUE;
    long total = 0L;

    for (int i = 0; i < n; i++){
      int b = Integer.parseInt(str4[i]);
      if (max < b)
        max = b;
      if (min > b)
        min = b;

      total += b;
    }
    System.out.println(min + " " + max + " " + total);
  }
}

Measured memory_bytes: 28480
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

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

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int k, n; cin >> k >> n;
  if(k * 500 >= n) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 892
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int cnt = 0;
vector<int> g;

void insertionSort(vector<int> &a, int g)
{
	for (int i = g; i < a.size(); i++)
	{
		int v = a[i];
		int j = i - g;
		for (; j >= 0 && a[j] > v;)
		{
			a[j + g] = a[j];
			j -= g;
			cnt++;
		}
		a[j + g] = v;
	}
}

void shellSort(vector<int> &a)
{
	for (int i = 1; i <= a.size(); i = 3 * i + 1)
	{
		g.push_back(i);
	}

	for (int i = g.size() - 1; i >= 0; i--)
	{
		insertionSort(a, g.at(i));
	}
}

int main()
{
	int n;
	vector<int> a;
	for (cin >> n; n--;)
	{
		int x;
		cin >> x;

		a.push_back(x);
	}

	shellSort(a);

	cout << g.size() << endl;
	for (int i = g.size() - 1; i >= 0; i--)
	{
		cout << g.at(i) << (i == 0 ? "" : " ");
	}

	cout << endl;
	cout << cnt << endl;

	for (int i = 0; i < a.size(); i++)
	{
		cout << a.at(i) << endl;
	}
}


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

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

const int MAXN = 1 << 19;
const int MOD = 1e9 + 7;

int n, h, ofs, sol;
int p[MAXN], uk[MAXN];
int t[MAXN * 4], val[MAXN * 4], inv[MAXN * 4];

int add (int x, int y) {x += y; if (x >= MOD) return x - MOD; return x;}
int sub (int x, int y) {x -= y; if (x < 0) return x + MOD; return x;}
int mul (int x, int y) {return (llint) x * y % MOD;}

int pot (int x, int e) {
    if (e == 0) return 1;
    int t = pot(x, e / 2);
    t = mul(t, t);
    if (e & 1) t = mul(t, x);
    return t;
}

void upd (int pos, int val) {
    pos += ofs;
    t[pos] = val;
    pos /= 2;
    while (pos > 0) {
        t[pos] = add(t[pos * 2], t[pos * 2 + 1]);
        pos /= 2;
    }
}

void dfs (int x, int curr) {
    inv[x] = pot(curr, MOD - 2);
    curr = mul(curr, x);
    inv[x] = mul(inv[x], pot(curr, MOD - 2));
    val[x] = curr;
    if (x < ofs) {
        dfs(2 * x, curr);
        dfs(2 * x + 1, curr);
    }
}

int calc (int x, int lo, int hi, int pos) {
    int mid = (lo + hi) / 2;
    if (lo == hi) return 0;
    if (pos <= mid) return add(calc(2 * x, lo, mid, pos), mul(t[2 * x + 1], inv[x]));
    return add(calc(2 * x + 1, mid + 1, hi, pos), mul(t[2 * x], inv[x]));
}

void solve (int x, int lo, int hi) {
    if (lo >= hi) return;
    int mid = (lo + hi) / 2;
    for (int i = mid + 1; i <= hi; i++) upd(p[i], uk[i]);
    for (int i = lo; i <= mid; i++) sol = add(sol, mul(calc(1, 0, ofs - 1, p[i]), mul(uk[i], inv[x])));
    for (int i = mid + 1; i <= hi; i++) upd(p[i], 0);
    solve(2 * x, lo, mid);
    solve(2 * x + 1, mid + 1, hi);
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> h;
    n = (1 << h), ofs = n / 2;
    dfs(1, 1);
    for (int i = 0; i < ofs; i++) {
        cin >> p[i];
        p[i]--;
        uk[i] = mul(val[i + ofs], val[p[i] + ofs]);
    }
    solve(1, 0, ofs - 1);
    cout << sol;
    return 0;
}


Measured memory_bytes: 7788
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - String Palindrome
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 99;

/* typedef */

/* global variables */

char s[MAX_N + 4];

/* subroutines */

bool palindrome(char s[], int i, int j) {
  while (i < j) {
    if (s[i] != s[j]) return false;
    i++, j--;
  }
  return true;
}

/* main */

int main() {
  scanf("%s", s);
  int n = strlen(s);

  if (palindrome(s, 0, n - 1) &&
      palindrome(s, 0, n / 2 - 1) &&
      palindrome(s, n / 2 + 1, n - 1))
    puts("Yes");
  else
    puts("No");
  
  return 0;
}


Measured memory_bytes: 256
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
    ans = 0
    a = [int(i) for i in ipt().split()]
    pl = [-1]*(n+1)
    for i,ai in enumerate(a):
        pl[ai] = i+1

    #Bit_Indexed_Tree
    #A1 ... AnのBIT(1-indexed)
    BIT = [0]*(n+1)

    #A1 ~ Aiまでの和 O(logN)
    def BIT_query(idx):
        res_sum = 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def BIT_update(idx,x):
        while idx <= n:
            BIT[idx] += x
            idx += idx&(-idx)
        return

    for i in range(1,n+1):
        pi = pl[i]
        ll = 0
        lr = pi
        bi = BIT_query(pl[i])
        while ll != lr:
            mid = ll+(lr-ll)//2
            if BIT_query(mid) == bi:
                lr = mid
            else:
                ll = mid+1
        rl = pi
        rr = n
        while rl != rr:
            mid = rl+(rr-rl+1)//2
            if BIT_query(mid) == bi:
                rl = mid
            else:
                rr = mid-1
#        print("a",rl,lr)
        ans += (pi-lr)*(rl-pi+1)*i
        BIT_update(pi,1)

    print(ans)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 117884
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
 
        int n = stdIn.nextInt();
        int p[] = new int[n];
        int q[] = new int[n];
        int a = 0;
        int b = 0;
        //int c = stdIn.nextInt();
        //int x = stdIn.nextInt();
        //int num[] = new int[];
        //String s = stdIn.next();
        //int sum = 0;
        //boolean flag = true;
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        }
        
        for(int i = 0; i < n; i++){
            q[i] = stdIn.nextInt();
        }
        
        int used[] = {1, 1, 1, 1, 1, 1, 1, 1};
        
        int nokori = n - 1;
        
        int sum = 0;
        for(int i = 0; i < n; i++){
            int num = p[i];
            int count = 0;
            used[p[i] - 1] = 0;
            int junretsu = 1;
            for(int j = 0; j < num - 1; j++){
                if(used[j] == 1){
                    count++;
                }
            }
            
            for(int j = nokori; j > 0; j--){
                junretsu *= j;
            }
            
            sum += junretsu * count;
            nokori--;

        }
        
        
        a = sum;
        
        int used2[] = {1, 1, 1, 1, 1, 1, 1, 1};
        
        nokori = n - 1;
        sum = 0;
        for(int i = 0; i < n; i++){
            int num = q[i];
            int count = 0;
            used2[q[i] - 1] = 0;
            int junretsu = 1;
            for(int j = 0; j < num - 1; j++){
                if(used2[j] == 1){
                    count++;
                }
            }
            
            for(int j = nokori; j > 0; j--){
                junretsu *= j;
            }
            
            sum += junretsu * count;
            nokori--;
        }
        
        b = sum;
        
        System.out.println(Math.abs(a - b));
 
        //System.out.println();
        //System.out.print();
 
        stdIn.close();
    }
}

Measured memory_bytes: 22612
#include<stdio.h>
int main(void){

  int hs1, s12, s23, s3h, x, y, sum;
 
  scanf("%d", &hs1);
  scanf("%d", &s12);
  scanf("%d", &s23);
  scanf("%d", &s3h);
  
  //
  sum=hs1+s12+s23+s3h;
  x=sum/60;
  y=sum-60*x;

  printf("%d\n%d\n", x, y);


  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int i,ii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	int k;
	cin>>k;
	for(i=0;i<k;i++){
		a[2]*=2;
	}
	int count=a[1]+a[0]+a[2];
	
	
	cout<<count;
	
	
	return 0;
}

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

int main()
{
    int n;
    scanf("%d", &n);
    int x[n];
    rep(i, n)
    {
        scanf("%d", &x[i]);
    }

    int ans = 100100100;
    int cur;
    rep(i, 101)
    {
        cur = 0;
        rep(j, n)
        {
            cur += pow(i - x[j], 2);
        }
        if (cur < ans)
        {
            ans = cur;
        }
    }
    printf("%d\n", ans);
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
#print(make_divisors(n))
li = make_divisors(n)
ans = 0
for l in li:
    if l == 1:
        continue
    t = l - 1
    if n % t == n//t:
        ans += t
print(ans)

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

#define X first
#define Y second
#define mp make_pair
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

/*#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
                         tree_order_statistics_node_update>;*/

void slow(int n) {
	for (int k = 2; k <= n; ++k) {
		int i = n;
		while (i > 1) {
			if (i % k == 0) {
				i /= k;
			} else {
				i -= k;
			}
		}
		if (i == 1) {
			cerr << k << " ";
		}
	}
	cerr << "\n";
}

void solve() {
	ll n;
	cin >> n;
	// slow(n);
	set<ll> ans;
	ans.emplace(2);
	for (ll d = 2; d * d <= (n - 1); ++d) {
		if ((n - 1) % d == 0) {
			ans.emplace(d);
		}
		if ((n - 1) % ((n - 1) / d) == 0) {
			ans.emplace((n - 1) / d);
		}
	}
	ans.emplace(n - 1);
	ans.emplace(n);
	for (ll d = 2; d * d <= n; ++d) {
		ll n1 = n;
		while (n1 % d == 0) {
			n1 /= d;
		}
		if (n1 % d == 1) {
			ans.emplace(d);
		}
	}
	while (!ans.empty() && *ans.begin() < 2) {
		ans.erase(ans.begin());
	}
	cout << sz(ans) << "\n";
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int tt = 1;
	// cin >> tt;
	while (tt--) solve();
	return 0;
}


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

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		int Y, M, D;
		cin >> Y >> M >> D;

		int offset = (10 - M + 1) * 20 - (D - 1);
		if (Y % 3 != 0){
			offset -= (12 - M) / 2;
		}

		Y++;
		int uruutime = (1002 - Y) / 3;
		int ans = offset + 195 * (1000 - Y) + uruutime * 5;
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int a,b,c;
int main()
{
    cin>>a>>b>>c;
    for(int i=a;i<=1000;i+=a)
        for(int j=a;j<=1000;j+=a)
            if((i + j) % b == c){
                cout<<"YES";
                return 0;
            }
    cout<<"NO";
}


Measured memory_bytes: 256
S = input()
n = len(S)
ans = True
if S!=S[::-1]:
    ans = False
s = S[:(n-1)//2]
if s!=s[::-1]:
    ans = False
s = S[::-1][(n-1)//2]
if s!=s[::-1]:
    ans = False
if ans:
    print('Yes')
else:
    print('No')

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

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if(d <= s*t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3644
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int i,j,t,b;(t=s.nextInt())>0;System.out.println(b))for(b=i=0;i++<t;)for(j=1;j++<t-i;)b+=j*(2*i+j-1)==t*2?1:0;}}

Measured memory_bytes: 12000
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
const long long inf=1e9+7;
const long long mod=1e9+7;
const int64_t CYCLES_PER_SEC=2800000000;
//
inline uint32_t Xor128(){
	static uint32_t x=123456789;
	static uint32_t y=362436069;
	static uint32_t z=521288629;
	static uint32_t w=88675123;
	uint32_t t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct Timer{
	int64_t start;
	Timer(){reset();}
	void reset(){start=getcycle();}
	void plus(double a){start-=(a*CYCLES_PER_SEC);}
	inline double get(){return (double)(getcycle()-start)/CYCLES_PER_SEC;}
	inline int64_t getcycle(){
		uint32_t low,high;
		__asm__ volatile ("rdtsc":"=a"(low),"=d"(high));
		return ((int64_t)low)|((int64_t)high<<32);
	}
};
int c[2000];
int main(){
	int n,x,y;
	cin>>n>>x>>y;
	x--;y--;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(j<=x||y<=i){
				c[j-i]++;
			}else if(i<=x&&y<=j){
				c[(x-i)+1+(j-y)]++;
			}else if(x<=i&&j<=y){
				c[min(j-i,(y-j)+(i-x)+1)]++;
			}else if(i<=x&&x<=j){
				c[min(j-i,(y-j)+1+(x-i))]++;
			}else{
				c[min(j-i,(i-x)+1+(j-y))]++;
			}
		}
	}
	for(int i=1;i<n;i++){
		cout<<c[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<LL> h(n);
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	bool ans = true;
	for (int i = n - 2; i >= 0; --i) {
		if (h[i] > h[i + 1]) {
			--h[i];
		}
		if (h[i] > h[i + 1]) {
			ans = false;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long ll;
#define print(x) cout<<(x)<<endl


#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


// DONT USE "int", USE "ll" !!!!!!!!!!!!
int main() {
	int N;
	cin >> N;

	int fx = 0;

	int tmp = N;
	while (tmp > 0) {
		fx += tmp % 10;
		tmp /= 10;
	}
	if (N%fx == 0)print("Yes");
	else print("No");








	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
const int N=2e5+5;
const int p=1e9+7;
#define PI acos(-1)
ll qpow(ll a,ll n){ll res=1;while(n){if(n&1)res=res*a%p;a=a*a%p;n>>=1;}return res;}
int a[N];
void work()
{
    int n,k;
    scanf("%d%d",&n,&k);
    ll ans=0;
    for(int i=k;i<=n+1;i++){
        ans=(ans+1ll*(n+n-i+1)*i/2-1ll*i*(i-1)/2+1)%p;
    }
    printf("%lld\n",ans);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T=1;
    //scanf("%d",&T);
    //cin>>T;
    while(T--){
        work();
    }
}

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

int main()
{
    long long N;
    cin >> N;
    if (N == 0)
    {
        cout << "0" << endl;
        return 0;
    }

    int count = 0;
    queue<int> fact;
    bool is_positive = (N > 0);
    while (N != 0)
    {
        if (N % 2 != 0)
        {
            fact.push(count);
            if (N > 0)
            {
                N--;
            }
            else
            {
                N++;
            }
        }
        N /= 2;
        count++;
    }

    int a[32] = {};
    for (int i = 0; i < 32; i++)
    {
        if (i == fact.front())
        {
            a[i]++;
            if (is_positive)
            {
                if (i % 2 != 0)
                {
                    a[i + 1]++;
                }
            }
            else
            {
                if (i % 2 == 0)
                {
                    a[i + 1]++;
                }
            }
            fact.pop();
        }
        while (a[i] > 1)
        {
            a[i + 1]++;
            a[i + 2]++;
            a[i] -= 2;
        }
    }

    queue<int> printqueue;
    string ans;
    for (int i = 0; i < 32; i++)
    {
        printqueue.push(a[i]);
        if (a[i] == 1)
        {
            while (printqueue.size() > 0)
            {
                ans += to_string(printqueue.front());
                printqueue.pop();
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 256
import { readFileSync } from 'fs'

function main(input: string) {
  let [x, k, d] = input.split(' ').map(Number)
  x = Math.abs(x)

  const count = Math.min(k, Math.floor(x / d))
  const pos = x - count * d

  const result = (k - count) % 2 === 0 ? pos : d - pos

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 29600
#include <iostream>
#include <algorithm>
using namespace std;
int a[10];
int main(int argc, char *argv[]) {
	int cnt=0;
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	while (a[0]!=a[2]){
		cnt++;
		if (a[1]==a[2] || a[2]-a[0]>1)
			a[0]+=2;
		else {
			a[0]++;
			a[1]++;
		}
		sort(a,a+3);
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
def f():
 N=int(input())
 s=[0]*N
 for _ in[0]*(N*~-N//2):
  a,b,c,d=map(int,input().split())
  s[a-1]+=3*(c>d)+(c==d)
  s[b-1]+=3*(d>c)+(d==c)
 b=[[]for _ in[0]*N*3]
 for i in range(N):b[s[i]]+=[i]
 r=1
 for x in b[::-1]:
  for y in x:s[y]=r
  if x:r+=len(x)
 print(*s,sep='\n')
f()


Measured memory_bytes: 5660
n = int(input())
a = list(map(int, input().split()))
nums = [0 for i in range(n)]
sum = 0
for i in range(n):
    nums[a[i]-1] += 1
for i in range(n):
    t = nums[i]
    sum += t*(t-1)//2
for i in range(n):
    t = nums[a[i]-1]
    print(sum - t*(t-1)//2 + (t-1)*(t-2)//2)

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Long> rts = new ArrayList<>();
        sc.nextLine();
        while(sc.hasNext()) {
            rts.add(Long.parseLong(sc.nextLine()));
        }
        long maxv = (long)Math.pow(10, 9) * -1;
        long minv = rts.get(0);
        for (int i = 1; i < rts.size(); i++) {
            long rji = rts.get(i) - minv;
            if (rji > maxv) {
                maxv = rji;
            }
            if (rts.get(i) < minv) {
                minv = rts.get(i);
            }
        }
//        for (int i = 0; i < rts.size(); i++) {
//            for (int j = 1; j < rts.size(); j++) {
//                if (i >= j) {
//                    continue;
//                }
//                long v = rts.get(j) - rts.get(i);
//                if (v > maxv) {
//                    maxv = v;
//                }
//            }
//        }
        System.out.println(maxv);
    }
}




Measured memory_bytes: 180936
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let a: Vec<_> = (0..n)
		.map(|_| {
			let x: i64 = s.next().unwrap().parse().unwrap();
			let y: i64 = s.next().unwrap().parse().unwrap();
			let z: i64 = s.next().unwrap().parse().unwrap();
			(x, y, z)
		})
		.collect();
	let calc = |sx: i64, sy: i64, sz: i64| -> i64 {
		let mut b: Vec<_> = a.iter().map(|a| a.0 * sx + a.1 * sy + a.2 * sz).collect();
		b.sort();
		b.iter().rev().take(m).sum::<i64>()
	};

	let mut ans = std::i64::MIN;
	for i in 0..8 {
		let sx = (i & 1) * 2 - 1;
		let sy = (i & 2) - 1;
		let sz = (i & 4) / 2 - 1;
		let r = calc(sx, sy, sz);
		if ans < r {
			ans = r;
		}
	}
	println!("{}", ans);
}


Measured memory_bytes: 2172
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
    int x;

    cin >> x;

    if (x == 1) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }
 
    return 0;
}



Measured memory_bytes: 3616
import java.io.*;
import java.util.*;
class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        char s[]=bu.readLine().toCharArray();
        int i,c=0;
        for(i=0;i<3;i++)
        if(s[i]=='R') c++;
        if(c!=2) sb.append(c);
        else
        {
            if(s[0]=='R' && s[2]=='R') c--;
            sb.append(c);
        }
        System.out.print(sb);
    }
}

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

vector<int> tree[200000+5];
int vcount[200000+5];

void counter(int n, int x, int p) {
  vcount[n] += x;
  for (auto v : tree[n]) {
    if (v == p) continue; 
    counter(v, vcount[n], n);
  }
}

int main() {
  int N,Q;
  cin >> N >> Q;
  for (int i=0; i<N-1; ++i) {
    int a,b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  for(int i=0; i<Q; ++i) {
    int p,x;
    cin >> p >> x;
    vcount[p] += x;
  }

  counter(1, 0, -1);

  for (int i=1; i<=N; ++i) {
    if (i!=1) cout << " ";
    cout << vcount[i];
  }
  cout << "\n";

  return 0;
}


Measured memory_bytes: 23424
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();

		if (X<A) {
			System.out.println(0);
		} else if(X>=A){
			System.out.println(10);
		}
	}
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	int N; cin >> N;
	vl a(N); FOR(i, 0, N) cin >> a[i];

	ll sum = 0, cnt = 0;

	// (i) + - + - ...
	FOR(i, 0, N) {
		sum += a[i];
		if (i % 2 == 0 && sum <= 0) {
			cnt += abs(sum) + 1;
			sum = 1;
		}
		else if (i % 2 == 1 && sum >= 0) {
			cnt += abs(sum) + 1;
			sum = -1;
		}
	}

	ll ans = cnt;
	sum = cnt = 0;

	// (ii) - + - + ...
	FOR(i, 0, N) {
		sum += a[i];
		if (i % 2 == 0 && sum >= 0) {
			cnt += abs(sum) + 1;
			sum = -1;
		}
		else if (i % 2 == 1 && sum <= 0) {
			cnt += abs(sum) + 1;
			sum = 1;
		}
	}

	ans = min(ans, cnt);

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


Measured memory_bytes: 1024
#include<cstdio>

int main(){
    int count[749];
    char ch;
    while(scanf("%c",&ch) != EOF){
        if(ch >= 'a' && ch <= 'z'){
            count[ch - 'a']++;
        }
        else if(ch >= 'A' && ch <= 'Z'){
            count[ch - 'A']++;
        }
    }
    for(int j = 0;j < 26; j++){
        printf("%c : %d\n",j + 'a',count[j]);
    }
    return 0;
}


Measured memory_bytes: 2712
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
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;}
ll INF = 1e+18;
int iINF = 1e9;

void
Warshall_Floyd(int V, vector<vector<int>> &G)
{
  rep(i, 0, V){
    rep(k, 0, V){
      rep(l, 0, V){
        chmin(G[k][l], G[k][i] + G[i][l]);
      }
    }
  }
}

int main()
{
  int N, M, R; cin >> N >> M >> R;
  vector<int> des(R);
  rep(i, 0, R){
    int tmp; cin >> tmp;
    --tmp;
    des[i] = tmp;
  }
  sort(des.begin(), des.end());
  vector<vector<int>> G(N, vector<int>(N, iINF));
  rep(i, 0, N) G[i][i] = 0;
  rep(i, 0, M){
    int a, b, c; cin >> a >> b >> c;
    --a, --b;
    G[a][b] = c;
    G[b][a] = c;
  }

  Warshall_Floyd(N, G);

  int ans = iINF;
  do{
    int comp = 0;
    int pre = des[0];
    rep(i, 1, R){
      comp += G[pre][des[i]];
      pre = des[i];
    }
    chmin(ans, comp);
  } while(next_permutation(des.begin(), des.end()));

  cout << ans << endl;
}

Measured memory_bytes: 3800
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>

using namespace std;

int prev_pos[200001] = {};
int dist[200001] = {};

int find(int x) {
    if (prev_pos[x] == 0) return x;

    int prev = prev_pos[x];
    prev_pos[x] = find(prev);
    dist[x] += dist[prev];
    return prev_pos[x];
}

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

    bool flag = true;
    for (int i = 0; i < M; i++) {
        int L, R, D;
        cin >> L >> R >> D;
        int L_first = find(L);
        int R_first = find(R);

        if (L_first == R_first) {
            if (dist[R] - dist[L] != D) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            prev_pos[R_first] = L_first;
            dist[R_first] = dist[L] - dist[R] + D;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 200010
ll dp[N],dq[N];
ll n,m,a[N];
ll res[N];
int main(){
  for(int i=0;i<N;i++)dp[i]=dq[i]=0;
  cin>>n>>m;
  ll sum=0;
  for(int i=0;i<n;i++){
      cin>>a[i]; a[i]--;
      if(i){
          ll b=a[i]; if(b<a[i-1])b+=m;
          sum+=b-a[i-1];
          dp[a[i-1]]++;
          dp[b]--;
          dq[a[i-1]]-=a[i-1]+1;
          dq[b]+=a[i-1]+1;
      }
  }
  for(int i=0;i<m;i++)res[i]=0;
  ll p=0,q=0;
  for(ll i=0;i<N;i++){
      res[i%m]+=p*i+q;
      p+=dp[i],q+=dq[i];
  }
  ll ans=0;
  for(int i=0;i<m;i++)chmax(ans,res[i]);
  cout<<sum-ans<<endl;
  return 0;
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    ll cnt=0;
    ll tot=a[0];
    if(tot==0){
      tot=1;
      cnt++;
    }
    for(int i=1;i<n;i++){
        ll k=tot+a[i];
        if(k*tot>0){
            if(tot==abs(tot)) tot=-1;
            else tot=1;
            cnt+=abs(k)+1;
        }
        else if(k==0){
            if(tot==abs(tot))tot=-1;
            else tot=1;
            cnt++;
        }
        else tot=k;
    }
    if(a[0]==abs(a[0]))tot=-1;
    else tot=1;
    ll cc=abs(a[0])+1;
    for(int i=1;i<n;i++){
        ll k=tot+a[i];
        if(k*tot>0){
            if(tot==abs(tot)) tot=-1;
            else tot=1;
            cc+=abs(k)+1;
        }
        else if(k==0){
            if(tot==abs(tot))tot=-1;
            else tot=1;
            cc++;
        }
        else tot=k;
    }
    cout<<min(cnt,cc)<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>

using namespace std;

int main() {
	string ans = "Yes";
	int c[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 0; i < 3; i++) {
		if (c[i][1] - c[i][0] != c[(i+1)%3][1] - c[(i+1)%3][0])
			ans = "No";
		if (c[i][2] - c[i][0] != c[(i + 1) % 3][2] - c[(i + 1) % 3][0])
			ans = "No";
	} 
	for (int j = 0; j < 3; j++) {
		if (c[1][j] - c[0][j] != c[1][(j+1)%3] - c[0][(j+1)%3])
			ans = "No";
		if (c[2][j] - c[0][j] != c[2][(j + 1) % 3] - c[0][(j + 1) % 3])
			ans = "No";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define M 1000000007
#define N 100005
using namespace std;
typedef long long ll;
ll n,r,s,t,d[N],A[N];
int bit[N];

int sum(int i){
  int s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}

void add(int i,int x){
  while(i<=n){
    bit[i]+=x;
    i+=i&-i;
  }
}

int main(){
  A[0]=A[1]=1;
  for(int i=2;i<N;i++)
    A[i]=(A[i-1]*i)%M;
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++)d[i]=i+1;
    cin>>r;
    for(int i=0;i<r;i++){
      cin>>s>>t;
      swap(d[s-1],d[t-1]);
    }
    memset(bit,0,sizeof(bit));
    ll ans=0;
    for(int i=0;i<n-1;i++){
      ans=(ans+((d[i]-sum(d[i])-1)*A[n-i-1])%M)%M;
      add(d[i],1);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5048
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
int x[200010],y[200010],f[19][19];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	rep(i,19)rep(j,19)f[i][j]=0;
	int n;
	cin>>n;
	ll ans=0;
	rep(i,n){
		string s;
		cin>>s;
		bool th=0;
		rep(j,s.size())th|=(s[j]=='.');
		if(!th)s+='.';
		ll A=0;
		rep(j,s.size()){
			if(s[j]=='.'){
				while(s.size()<j+10)s+='0';
			}
			else{
				A*=10;
				A+=s[j]-'0';
			}
		}
		x[i]=0;
		while(A%2==0){
			A/=2;
			x[i]++;
		}
		y[i]=0;
		while(A%5==0){
			A/=5;
			y[i]++;
		}
		chmin(x[i],18);
		chmin(y[i],18);
		for(int p=18-x[i];p<19;p++){
			for(int q=18-y[i];q<19;q++){
				ans+=f[p][q];
			}
		}
		f[x[i]][y[i]]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5184
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      _a: [[u8; n]; n]
   }
   let mut a = vec![vec![true; n]; n];
   for i in 0..n {
      for j in 0..n {
         if _a[i][j] == 0 {
            a[i][j] = false;
         }
      }
   }
   let mut dp = vec![-1_i64; 1 << n];
   dp[0] = 1;
   println!("{}", rec((1 << n) - 1, 0, &a, &mut dp));
}

const MOD: i64 = 1000000007;

fn rec(state: usize, c: usize, a: &Vec<Vec<bool>>, dp: &mut Vec<i64>) -> i64 {
   if dp[state] != -1 {
      dp[state]
   } else {
      let mut r = 0;
      for (i, &b) in a[c].iter().enumerate() {
         if b && (state >> i) & 1 == 1 {
            r += rec(state ^ (1 << i), c + 1, a, dp);
         }
      }
      dp[state] = r % MOD;
      dp[state]
   }
}


Measured memory_bytes: 20732
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}
vector<int> ans(100000, 0);
vector<bool> v(100000,false);
map<int, vector<pair<int, int>>> m;

void solve(int now,int rest){
	if(v[now]){
		return;
	}
	v[now]=true;
	if(rest==0){
		ans[now]=1;
	}
	for(auto& i:m[now]){
		if(rest==i.second){
			solve(i.first,0);
		}
		else{
			solve(i.first,1);
		}
	}
	return;
}
int main(){
	int n;
	cin >> n;
	REP(i,n-1){
		ll u,v,w;
		cin >> u >> v >> w;
		m[u-1].push_back(make_pair(v-1,w%2));
		m[v-1].push_back(make_pair(u-1,w%2));
	}
	solve(0,0);
	REP(i,n){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 13312
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            Map<String, String> m = new HashMap<>();
            while (n-- > 0) {
                m.put(sc.next(),sc.next());
            }
            n = sc.nextInt();
            StringBuffer sb=new StringBuffer();
            while(n-->0) {
                String s=sc.next();
                if(m.containsKey(s)) {
                    sb.append(m.get(s));
                }else {
                    sb.append(s);
                }
            }
            System.out.println(sb);
        }
    }
}



Measured memory_bytes: 68432
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
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; }
ll t;
bool func(ll a,ll b,ll g,ll d){
    //cout<<g<<"\n";
    ll x=a%g+((b-a%g+g)/g)*g;
    //cout<<x<<"\n";
    if(x<d)return false;
    else return true;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> t;
    while(t--){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a<b){
            no;continue;
        }
        if(b>d){
            no;continue;
        }
        ll kouyaku=gcd(b,d);
        if(func(a,c,kouyaku,b))yes;
        else no;
    }
    //https://scrapbox.io/ganariya/AtCoderGrandContest026_B問題600点「rng_10s」_(copy)
}


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;


int N, A[4000], T[4000];
int dp[2001][2001];
int rev[2][2002];
int add[2][2002][2001];

int rec(int latte, int malta) {
  if(latte == N / 2 && malta == N / 2) return 0;
  if(~dp[latte][malta]) return dp[latte][malta];
  int ret = INF;
  if(latte < N / 2) {
    int x = 0;
    for(int j = 0; j < N; j++) {
      if(T[j] == 0 && A[j] == latte) break;
      if(T[j] == 0 && A[j] < latte) continue;
      if(T[j] == 1 && A[j] < malta) continue;
      ++x;
    }
    ret = min(ret, rec(latte + 1, malta) + add[0][latte][malta]);
  }
  if(malta < N / 2) {

    /*
    int x = 0;
    for(int j = 0; j < N; j++) {
      if(T[j] == 1 && A[j] == malta) break;
      if(T[j] == 0 && A[j] < latte) continue;
      if(T[j] == 1 && A[j] < malta) continue;
      ++x;
    }
     */

    ret = min(ret, rec(latte, malta + 1) + add[1][latte][malta]);

  }

  return dp[latte][malta] = ret;
}

int main() {

  cin >> N;
  N *= 2;
  for(int i = 0; i < N; i++) {
    char x;
    cin >> x >> A[i];
    --A[i];
    T[i] = x == 'W';
    rev[T[i]][A[i]] = i;
  }

  for(int i = 0; i < N / 2; i++) {

    int beet = 0;
    for(int j = 0; j < N; j++) {
      if(T[j] == 1) continue;
      if(A[j] == i) break;
      if(A[j] < i) continue;
      ++beet;
    }
    vector< int > vec(N / 2 + 1);
    for(int k = 0; k < rev[0][i]; k++) {
      if(T[k] == 0) continue;
      ++vec[A[k]];
    }
    for(int k = N / 2 - 1; k >= 0; k--) {
      vec[k] += vec[k + 1];
    }
    for(int j = 0; j <= N / 2; j++) {
      add[0][i][j] = beet + vec[j];
    }


    beet = 0;
    for(int j = 0; j < N; j++) {
      if(T[j] == 0) continue;
      if(A[j] == i) break;
      if(A[j] < i) continue;
      ++beet;
    }
    vec.assign(N / 2 + 1, 0);
    for(int k = 0; k < rev[1][i]; k++) {
      if(T[k] == 1) continue;
      ++vec[A[k]];
    }
    for(int k = N / 2 - 1; k >= 0; k--) {
      vec[k] += vec[k + 1];
    }
    for(int j = 0; j <= N / 2; j++) {
      add[1][j][i] = beet + vec[j];
    }


  }


  memset(dp, -1, sizeof(dp));
  cout << rec(0, 0) << endl;
}


Measured memory_bytes: 47488
# 2020/04/12
# AtCoder Beginner Contest 162 - C

# 最大公約数 fractions.gcdバージョン メモ化
# Greatest Common Divisor(GCD)  
import fractions
dp = [[0] * 201 for i in range(201)]
def gcd_fgf(a, b):
    if dp[a][b] == 0:
        if dp[b][a] == 0:
            dp[a][b] = fractions.gcd(a, b)
            return dp[a][b]
        else:
            return dp[b][a]
    else:
        return dp[a][b]

# Input
n = int(input())

# Calc
ans = 0
for a in range(1, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            wkgcd = gcd_fgf(a, b)
            ans = ans + gcd_fgf(wkgcd, c)

# Output
print(ans)


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;
//map< int64_t, int > prime_factor(int64_t n);

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}


class mm{
    // アクセシビリティ
    // public 以下は全部公開される
public:
    char c;
    int count;
     mm(char cc,int ccount)
    {
       c = cc;
       count = ccount;
    }
};

int main(int argc, const char * argv[]) {
    
    // source code
  string s;
  cin >> s;
  ll k;
  cin >> k;
  vector<mm> mmvec;
  char nowc = 'A';
  ll sseq = 0;
  ll seseq = 0;
  rep(i,s.length())
  {
    if(nowc != s[i])
    { 
      mmvec.push_back(mm(s[i],1));
      nowc = s[i];
    }
    else
    {
      mmvec.back().count++;
    }
  }
  rep(i,mmvec.size())
  {
    sseq+=mmvec[i].count/2;
  }
  if(mmvec.size() == 1)
  {
    cout << s.length() * k/2;
    return 0;
  }
  if(mmvec[0].c == mmvec.back().c)
  {
    seseq = (mmvec[0].count + mmvec.back().count) / 2;
    seseq -= mmvec[0].count/2;
    seseq -= mmvec.back().count / 2;
  }
  ll ans;
  ans = sseq * k;
  ans += seseq * (k - 1);
  cout << ans;
  return 0;
}

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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 1e9 + 7;
const ll linf  = 1ll * inf * inf;
const int N = 4000 + 7;
const int M = 1000000 + 3;
const int multipleTest = 0;
const double pi = acos(-1);

int n;
int f[2][N];
int g[2][N][N];

class FenWickTree{
public:
	static const int MAXN = 2000 + 7;
	int L[MAXN];
	
	void update(int x, int val) {
//		for (int t = x; t < MAXN; t += t & -t) L[t] += val;
		for (int t = x; t > 0; t -= t & -t) L[t] += val;
	}
	
	int get(int x) {
		int res = 0;
//		for (int t = x; t > 0; t -= t & -t) {
//			res += L[t];
//		}
		for (int t = x; t < MAXN; t += t & -t) res += L[t];
		return res;
	}
} fenwickTree[2];

ll dp[N][N];

void solve() {
	cin >> n;
	rep(i, 1, 2 * n + 1) {
		string s; cin >> s;
		int c = (s[0] == 'B'), a = 0;
		scanf("%d", &a);
		
		f[c][a] = fenwickTree[c].get(a);
		for (int j = 0; j <= n; ++j)
			g[c][a][j] = fenwickTree[1 - c].get(j + 1) + f[c][a];
		fenwickTree[c].update(a, 1);
	}
	
	rep(i, 0, n + 1) rep(j, 0, n + 1) dp[i][j] = linf;
	dp[0][0] = 0;
	
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (i == 0 && j == 0) dp[i][j] = 0;
			else {
				if (i == 0) {
					dp[i][j] = dp[i][j - 1] + g[1][j][0];
				} else if (j == 0) {
					dp[i][j] = dp[i - 1][j] + g[0][i][0];
				} else {
					dp[i][j] = min(dp[i - 1][j] + g[0][i][j], dp[i][j - 1] + g[1][j][i]);
				}
			}
		}
	}
	
	cout << dp[n][n] << '\n';
}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//    freopen("out.txt", "w", stdout);
#endif
	int Test = 1;
	if (multipleTest) {
		cin >> Test;
	}
	for(int i = 0; i < Test; ++i) {
		//		printf("Case #%d: ", i + 1);
		solve();
	}
#ifdef _LOCAL_
	cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}



Measured memory_bytes: 130688
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

int n,tn;
int a[2007],p[2007];
int dep[2007],vis[2007];
int red[2007],ed[2007];
vector<int> que,adj[2007],ans;
bool cmp(int x,int y){if(red[x]^red[y]) return red[x]>red[y];return dep[x]>dep[y];}

void rot(int x)
{
	ans.push_back(x);
	while(x!=1) swap(a[1],a[x]),x=p[x]; 
}

int main()
{
	scanf("%d",&n);
	rep(i,n-1){scanf("%d",&p[i+2]);dep[i+2]=dep[++p[i+2]]+1;adj[p[i+2]].pb(i+2);}
	REP(i,n){scanf("%d",&a[i]);a[i]++;}
	
	tn=n;
	while(tn)
	{
		que.clear();
		for(int i=n;i;i--)
		{
			if(vis[i]) continue;que.pb(i);
			int cson=0,son=0;rep(j,adj[i].size()) if(!vis[adj[i][j]]) cson++,son=adj[i][j];
			if(cson>1)red[i]=0;else red[i]=(cson?red[son]:i);
			if(red[i]==i) ed[i]=i;if(red[i]) tn--;
		}
		
		sort(que.begin(),que.end(),cmp);
		int pos=0;
		while(pos<que.size())
		{
			if(red[a[1]])
			{
				int x=a[1],y=red[x];
				while(vis[y]&&a[y]>x)y=p[y];
				rot(y);vis[ed[red[x]]]=1;ed[red[x]]=p[ed[red[x]]];
			}
			else rot(que[pos++]);
			while(pos<que.size()&&vis[que[pos]]) pos++;
		}
	}
	
//	REP(i,n) printf("%d ",a[i]);puts("");
	printf("%d\n",ans.size());
	rep(i,ans.size()) printf("%d\n",ans[i]-1);
	return 0;
}

Measured memory_bytes: 584