akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, a[200009], b[200009], ans = 0; vector<int>p[30];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < N; i++) scanf("%d", &b[i]);
	for (int i = 0; i <= 29; i++) {
		p[i].resize(N);
		for (int j = 0; j < N; j++) { p[i][j] = b[j] % (1 << i); }
		sort(p[i].begin(), p[i].end());
	}
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for (int j = 0; j <= 28; j++) {
			sum = (a[i] & ((2 << j) - 1));
			int LL = (3 << j) - sum; LL %= (2 << j);
			int RR = LL + (1 << j); RR %= (2 << j);
			if (LL < RR) {
				int pos1 = lower_bound(p[j + 1].begin(), p[j + 1].end(), LL) - p[j + 1].begin();
				int pos2 = lower_bound(p[j + 1].begin(), p[j + 1].end(), RR) - p[j + 1].begin();
				if ((pos2 - pos1) % 2 == 1) {
					ans ^= (1 << j);
				}
			}
			else {
				int pos1 = lower_bound(p[j + 1].begin(), p[j + 1].end(), RR) - p[j + 1].begin();
				int pos2 = lower_bound(p[j + 1].begin(), p[j + 1].end(), LL) - p[j + 1].begin();
				if ((N - (pos2 - pos1)) % 2 == 1) {
					ans ^= (1 << j);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long int;

const ll MAX = (ll)(1e9 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

/////////////////////////////////////////////////////////////
class BinaryIndexedTree {
public:
  static const int MAX_N_LIB = (int)(2e5 + 100);

  ll bit_arr[MAX_N_LIB];
  int bit_n;

  BinaryIndexedTree(int n) {
    bit_n = n;
    init();
  }

  void init() {
    for (int i = 0; i < bit_n; ++i) bit_arr[i] = 0LL;
  }

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

  void add(int i, ll x) {
    while (i <= bit_n) {
      bit_arr[i] += x;
      i += i & -i;
    }
  }
};
/////////////////////////////////////////////////////////////

int n;
ll a[MAX_N];
ll b[MAX_N];

int s[MAX_N];

BinaryIndexedTree bit(MAX_N * 2);

bool check(ll x) {
  ll num = 0;

  for (int i = 1; i <= n; ++i) s[i] = (a[i] >= x) ? 1 : -1;
  for (int i = 1; i <= n; ++i) s[i] += s[i - 1];

  bit.init();

  for (int i = 0; i <= n; ++i) {
    num += bit.sum(s[i] + MAX_N);
    bit.add(s[i] + MAX_N, 1);
  }

  ll whole = (1LL * (n + 1) * n) / 2;
  ll target =  (whole - 1) / 2 + 1;

  return (num >= target);
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &(a[i]));
    b[i] = a[i];
  }

  sort(b + 1, b + n + 1);

  b[n + 1] = b[n] + 1; // guard

  int ok = 1;
  int ng = n + 1;

  while (abs(ok - ng) > 1) {
    int next = (ok + ng) / 2;

    if (check(b[next])) {
      ok = next;
    }
    else {
      ng = next;
    }
  }

  printf("%lld\n", b[ok]);

  return 0;
}


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


int main() {
    string sA, sB, sC;
    cin >> sA >> sB >> sC;
    map<char, string> mp;
    mp['a'] = sA;
    mp['b'] = sB;
    mp['c'] = sC;

    char now = 'a';
    while (mp[now].size()) {
        char flont_char = mp[now].front();
        mp[now].erase(mp[now].begin());
        now = flont_char;
    }
    
    if (now == 'a') cout << 'A' << endl;
    else if (now == 'b') cout << 'B' << endl;
    else cout << 'C' << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
d=[[10**18]*n for i in range(n)]
e=[]
for _ in range(m):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c
    e.append([a-1,b-1,c])
for i in range(n):
    d[i][i]=0
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
print(sum(c>d[a][b]for a,b,c in e))

Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {

	int n;
	int o[50010];
	int e[50010];
	int oc = 0;
	int om = 0;
	int om2 = 0;
	int om_you = 0;
	int om2_you = 0;

	int ec = 0;
	int em = 0;
	int em2 = 0;
	int em_you = 0;
	int em2_you = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		if (i == 0)
			cin >> o[0];
		else if (i == 1)
			cin >> e[0];
		else if (i % 2 == 1)
			cin >> e[(i - 1) / 2];
		else if (i % 2 == 0)
			cin >> o[i / 2];
	}
	n = n / 2;
	sort(o, o + n);
	sort(e, e + n);
	for (int i = 0; i < n - 1; i++) {
		if (e[i] != e[i + 1]) {
			ec++;
			if (em < ec) {
				if (em2 < em)
					em2 = em;
				em = ec;
				em_you = e[i];
			}
			else if (em2 < ec) {
				em2 = ec;
				em2_you = e[i];
			}
			ec = 0;
		}
		else
			ec++;

		if (o[i] != o[i + 1]) {
			oc++;
			if (om < oc) {
				if (om2 < om)
					om2 = om;
				om = oc;
				om_you = o[i];
			}
			else if (om2 < oc) {
				om2 = oc;
				om2_you = o[i];
			}
			oc = 0;
		}
		else
			oc++;
	}
	ec++;
	oc++;
	if (em < ec) {
		if (em2 < em)
			em2 = em;
		em = ec;
		em_you = e[n-1];
	}
	else if (em2 < ec) {
		em2 = ec;
		em2_you = e[n-1];
	}
	if (om < oc) {
		if (om2 < om)
			om2 = om;
		om = oc;
		om_you = o[n-1];
	}
	else if (om2 < oc) {
		om2 = oc;
		om2_you = o[n-1];
	}
	if(em_you!=om_you)
		cout << n * 2 - om - em << endl;

	else {
		if (om2 + em > om + em2)
			cout << n * 2 - om2 - em << endl;
		else
			cout << n * 2 - om - em2 << endl;
	}

	return 0;
}

Measured memory_bytes: 640
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (H, W, K) = rd.readIntArray()

    for (a in 0 .. H) {
        for (b in 0 .. W) {
            if (W*a + H*b - a*b*2 == K) {
                println("Yes")
                return
            }
        }
    }

    println("No")
}


//val rd = debug.Reader("etc", "code-festival-2017-quala", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 36780
n, q = map(int, input().split())
s = str(input())
lr = []
for i in range(q):
    lr.append(list(input().split()))

n = len(s)
ary = [0 for i in range(len(s)+1)]

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        ary[i+1] = ary[i] + 1
    else:
        ary[i+1] = ary[i]

for i in range(q):
    ans = ary[int(lr[i][1])] - ary[int(lr[i][0])]
    print(ans)


Measured memory_bytes: 29280
#include <iostream>
using namespace std;
int main(void){
    int c[9];
    for(int i=0;i<9;i++){
        cin>>c[i];
    }
    int A,B,C,D,E,F,G,H,I,J,K,L;
    A=c[1]-c[0];
    B=c[2]-c[1];
    C=c[4]-c[3];
    D=c[5]-c[4];
    E=c[7]-c[6];
    F=c[8]-c[7];
    G=c[3]-c[0];
    H=c[6]-c[3];
    I=c[4]-c[1];
    J=c[7]-c[4];
    K=c[5]-c[2];
    L=c[8]-c[5];
    if(A==C&&C==E&&B==D&&D==F&&G==I&&I==K&&H==J&&J==L){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
const int max_n = 10000;
ll a[max_n];
int main(){
  cin >> n;
  ll sum = 0;
  for(int i=0 ; i<n ; i++){
    cin >> a[i];
    sum += a[i] -1;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int A[3], cost;

    for (int i = 0; i < 3; i++) cin >> A[i];
    sort(A, A+3);
    for (int i = 0; i < 2; i++) cost += abs(A[i+1] - A[i]);

    cout << cost << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
btree = []
root = None


class Node():
    def __init__(self, key, parent, left, right):
        self.key = key
        self.parent = parent
        self.left = left
        self.right = right


def showInorder(node):
    if node.left is not None:
        showInorder(node.left)
    print(" {0}".format(str(node.key)), end="")
    if node.right is not None:
        showInorder(node.right)


def showPreorder(node):
    print(" {0}".format(node.key), end="")
    if node.left is not None:
        showPreorder(node.left)
    if node.right is not None:
        showPreorder(node.right)


def insert(key):
    global root
    z = Node(key, None, None, None)
    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left  # 左の子へ移動
        else:
            x = x.right  # 右の子へ移動

    z.parent = y

    if y is None:
        root = z
    elif z.key < y.key:
        y.left = z  # zをyの左の子にする
    else:
        y.right = z  # zをyの右の子にする


def showtree(root):
    showInorder(root)
    print()
    showPreorder(root)
    print()


def main():
    m = int(input())
    global root
    for i in range(m):

        operation = input().split()

        # print(operation)

        if operation[0] == 'insert':
            # print("insert!")
            insert(int(operation[1]))
        else:
            # print("show tree!")
            # print("root.key:{0} root.left:{1} root.right:{2}".format(root.key, root.left, root.right))
            showtree(root)


if __name__ == '__main__':
    main()



Measured memory_bytes: 105164
from collections import deque

n,q = map(int,input().split())
Q = deque()

for _ in range(n):
    p = [x for x in input().split()]
    Q.append(p)

account = 0
i = 0
while len(Q)!=0:
    if int(Q[i][1]) > q:
        Q[i][1] = int(Q[i][1])-q
        Q.append(Q[i])
        Q.popleft()
        account += q
    else:
        account += int(Q[i][1])
        print(Q[0][0],account)
        Q.popleft()


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


int main(){
    int a, b;
    cin >> a >> b;
    cout << a * b - a - b + 1 << endl;
    
    return 0;
}


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int top, S[1000];
 
void push(int x){
    S[++top] = x;
}
 
int pop(void){
    return S[top--];
}
 
int main(){
    int a, b;
    top = 0;
    char s[100];
    while (scanf("%s", s) != EOF){
        if (s[0] == '+'){
            a = pop();
            b = pop();
            push(a + b);
        }else if (s[0] == '-'){
            b= pop();
            a = pop();
            push(a - b);
        }else if (s[0] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        }else{
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
    return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  queue<int> m;
  ll H;cin>>H;
  m.push(H);

  ll ans = 0;
  ll bi = 1;
  while(H>0){
    H = H >> 1;
    ans += bi;
    bi = bi << 1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sum_of_digit(int num) {
    int sum = 0;
    while (num > 0) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        int tmp = sum_of_digit(i);
        if (tmp >= a && tmp <= b)
            sum += i;
    }
    cout << sum << '\n';
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        long sum = 0;
        for(int i = 0; i < n; i++){
            sum += arr[i];
        }
        long MOD = 1000000007;
        long ans = 0;
        for(int i = 0; i < n; i++){
            ans += (arr[i] * ((sum - arr[i])%MOD))%MOD;
            ans %= MOD;
            sum -= arr[i];
        }
        sb.append(ans);
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 55108
#include<stdio.h>
main()
{
	double a,b,x,y;
	double j,l;
	while(~scanf("%lf %lf %lf %lf",&a,&b,&x,&y))
	{
	if(a/2==x&&b/2==y)
		printf("%lf 1\n",a*b/2);
		else
		printf("%lf 0\n",a*b/2);
	}
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 105;
int a[maxn];

int main() {
    #ifdef LOCAL
    assert(freopen("c.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    forn (i, n)
        cin >> a[i];
    ll best = infl;
    for (int X = -100; X <= 100; ++X) {
        ll sum = 0;
        forn (i, n)
            sum += (X - a[i]) * (X - a[i]);
        best = min(best, sum);
    }
    cout << best << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);
    int m = 0;
    int s = 0;
    for (int i = 0; i < N; i++) {
        int L;
        scanf("%d", &L);
        if (m < L) m = L;
        s += L;
    }
    puts(s > 2 * m ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int a;
	int n;
	int i;
	int s,f;
	int sum = 0;
	int t;
	while(scanf("%d",&a)){
		if(a == 0){
			break;
		}
		scanf("%d",&n);
		for(i = 0;i < n;i++){
			scanf("%d %d",&s,&t);
			sum = sum + t - s;
		}
		if(sum >= a){
			printf("OK\n");
		}
		else{
			printf("%d\n",a - sum);
		}
		sum = 0;
	}
	return 0;
}

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

using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int> spots(N+2);
  vector<int> costs(N+1);
  vector<int> rm_costs(N);
  int all_cost = 0;
  spots[0] = 0;
  spots[N+1] = 0;

  for(int i = 1; i < N + 2; i++) {
    if(i < N + 1)
      cin >> spots[i];

    costs[i-1] = abs(spots[i] - spots[i - 1]);
    all_cost += costs[i - 1];

    if(i > 1) {
      rm_costs[i - 2] = abs(spots[i] - spots[i - 2]);
    }
  }

  for(int i = 0; i < N; i++) {
    int out = all_cost;
    out -= costs[i] + costs[i + 1];
    out += rm_costs[i];
    cout << out << endl;
  }
  return 0;
}


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

typedef long long ll;

#define MAX 25
#define NIL -1

struct Node{
    int p,l,r;
};

int n;
Node tree[MAX];

void init(){
    for(int i=0;i<MAX;i++){
        tree[i].p = tree[i].r = tree[i].l = NIL;
    }
}

void print_pre(int r){
    if(r==NIL) return;
    else {
        cout << " " << r;
        print_pre(tree[r].l);
        print_pre(tree[r].r);
    }
}

void print_in(int r){
    if(r==NIL)return;
    else {
        print_in(tree[r].l);
        cout << " " << r;
        print_in(tree[r].r);
    }
}

void print_post(int r){
    if(r==NIL)return;
    else{
        print_post(tree[r].l);
        print_post(tree[r].r);
        cout << " " << r;
    }
}

void print(){
    int root;
    for(int i=0;i<n;i++)if(tree[i].p==NIL)root=i;
    cout << "Preorder\n";
    print_pre(root);
    cout << "\n";
    cout << "Inorder\n";
    print_in(root);
    cout << "\n";
    cout << "Postorder\n";
    print_post(root);
    cout << "\n";

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    init();
    cin >> n;
    int id,lft,rgt;

    for(int i=0;i<n;i++){
        cin >> id >> lft >> rgt;
        tree[id].l=lft;
        tree[id].r=rgt;
        tree[lft].p = tree[rgt].p = id;
    }

    print();
}



Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1e9+7
#define MOD 1e9+7
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

struct UnionFind{
	int par[201000];
	int rank[201000];

	void init(int n){
		for (int i = 0; i < 201000; i++){
			par[i] = i;
			rank[i] = 1;
		}
	}

	int find(int x){
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]){
			par[x] = y;
		}
		else{
			par[y] = x;
			if (rank[y] == rank[x])rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int n, k, l;
UnionFind buf[10];

map<pair<int, int>, int> mpi;

int main(){
	cin >> n >> k >> l;
	REP(i, 10)buf[i].init(n + 1);
	int p, q;
	REP(i, k){
		cin >> p >> q;
		buf[0].unite(p, q);
	}
	REP(i, l){
		cin >> p >> q;
		buf[1].unite(p, q);
	}
	FOR(i, 1, n + 1){
		mpi[{buf[0].find(i), buf[1].find(i)}]++;
	}
	FOR(i, 1, n + 1){
		cout << mpi[{buf[0].find(i), buf[1].find(i)}] << endl;
	}
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL<<60);

int main(){

    ll a, b, k; cin >> a >> b >> k;

    ll ans1, ans2;
    ans1 = a-k;
    if(ans1<0){
        ans1 = 0;
        ans2 = a+b-k;
        if(ans2<0) ans2 = 0;
    }
    else{
        ans2 = b;
    }

    cout << ans1 << " " << ans2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vc= vector<char>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()

int main(){
  int n;
  cin >> n;
  vi a(n);
  vi ans(n);
  rep(i,n) cin >> a[i];

  rep(i,n){
    ans[a[i]-1]= i+1;
  }
  rep(i,n){
    cout << ans[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int a[1009];
main(){
    int n;
    cin >> n;
    int cnt = 0,ans=0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i && a[i] != a[i-1]) {
            ans += cnt/2;
            cnt = 0;
        }
        cnt++;
    }
    ans += cnt/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
L,r=map(int, input().split())

R=min(L+2019,r)

amari=[]
for i in range(L,R+1):
	amari+=[i%2019]

#print(amari)

ans=2019
for i in range(len(amari)):
	for j in range(i+1,len(amari)):
		ans=min(ans,(amari[i]*amari[j])%2019)


print(ans)



Measured memory_bytes: 3060
#include <cstring>
#include <cstdio>
using namespace std;
char ch[15];
int len,base;
long long ans,sum,cnt;
int main(){
	scanf("%s",ch);
	len=strlen(ch);
	base=1<<(len-1);
	for(int i=0;i<base;++i){
		int t=i<<1;
		sum=0;
		cnt=0;
		for(int j=0;j<len;++j){
			if(t&1){
				sum+=cnt;
				cnt=ch[j]-'0';
			}else{
				cnt=cnt*10+ch[j]-'0';
			}
			t/=2;
		}
		sum+=cnt;
		ans+=sum;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1732
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-7;

vector <int> G[MAXN];
bool bip, used[MAXN];
int col[MAXN];

void dfs(int v)
{
	used[v] = true;
	REP(i, SZ(G[v]))
	{
		int to = G[v][i];
		if (!used[to])
		{
			col[to] = 3 - col[v];
			dfs(to);
		}
		if (col[to] != 3 - col[v])
			bip = false;
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n, m;	
	cin >> n >> m;
	REP(i, m)
	{
		int u, v;
		cin >> u >> v;
		--u; --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	LL b = 0, c = 0, c1 = 0;
	REP(i, n)
	{
		if (SZ(G[i]) == 0)
		{
			++c1;
			continue;
		}
		if (!used[i])
		{
			bip = true;
			col[i] = 1;
			dfs(i);
			if (bip)
				++b;
			++c;
		}
	}
	cout << c * c + b * b + c1 * (2 * n - c1);
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 11904
#include<iostream>
#include <utility>
#include<bits/stdc++.h>
#define ull unsigned long long int
#define ll int
#define ld long double
// #define loop(i,a,b) for(ll i=a;i<b;i++)
// #define inll(n) ll n;cin>>n;
// #define instr(s)  string s;cin>>s;
// #define inarr(a,n)  ll*a = new ll[n];loop(i,0,n)cin>>a[i]; 
// #define invec(v,n)  vector<ll> v(n);loop(i,0,n)inll(v[i])
// #define arr(a,n) ll*a = new ll[n];
// #define outarr(a,n) loop(i,0,n)cout<<a[i]<<" ";cout<<endl;
#define pb push_back
#define mp make_pair
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector <int>
#define vb vector <bool>
#define vll vector <ll>
#define vc vector <char>
#define clr(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define infd 1e+18
#define inf 101901199101
#define mod 1000000007

inline ll min(ll a,ll b)
{
    return (a<b?a:b);
}
inline ll max(ll a,ll b)
{
    return (a<b?b:a);
}

using namespace std;
int main()
{fastio
    ll n;cin>>n;
    ll a[n];
    ll c =0;
    for(ll i =0;i<n;i++)
    {
        cin>>a[i];
    }
        ll j =1;
    for(ll i =0;i<n;i++)
    {
        if(a[i]!=j)c++;
        else
        {
            j++;
        }
    }

    if(c==n)cout<<-1<<endl;
    else cout<<c<<endl;
}

Measured memory_bytes: 1024
def sigma(N):
    return N*(N+1)//2


def find_max(N):
    for i in range(N):
        if sigma(i) > N:
            return i
    return N


def solve(N):
    Y = find_max(N)
    rem = sigma(Y)-N
    for i in range(1, Y+1):
        if i != rem:
            print(i)


N = int(input())
solve(N)


Measured memory_bytes: 3408
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
4
631 577 243 199
)");
#define cin input
#endif

int main()
{
	int n;
	cin >> n;

	int a;
	int count = 0;

	for (int i=0; i<n; i++)
	{
		cin >> a;

		while (a%2 == 0)
		{
			a /= 2;
			count++;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
n = int(input())
s = list(map(int,input().split()))
ans = {}
#各番号がいくつずつあるのかを整理
#keyに番号、valueにその番号が書かれてあるボールの数
for i in range(n):
    if not s[i] in ans.keys():
        ans[s[i]] = 1
    else:
        ans[s[i]] += 1
#iC2の総和
answer = 0
for i,j in ans.items():
    answer += j*(j-1)//2
#answer-nC2+(n-1)C2 = answer-n+1
#nはans[s[i]],よって以下の出力で求められる
for i in range(n):
    print(answer-ans[s[i]]+1)


Measured memory_bytes: 24996
#include<string>
#include<iostream>

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

using namespace std;

string LCS(const string &s,const string &t){
	const int LMAX=300;
	static int dp[LMAX+1][LMAX+1],from[LMAX+1][LMAX+1];
	int slen=s.length(),tlen=t.length();

	rep(i,slen+1)	dp[i][0]=0,from[i][0]=-1;
	rep(j,tlen+1)	dp[0][j]=0,from[0][j]=-1;

	for(int i=1;i<=slen;i++)for(int j=1;j<=tlen;j++){
		dp[i][j]=0;
		int a[]={dp[i][j-1],dp[i-1][j],dp[i-1][j-1]+(s[i-1]==t[j-1])};
		rep(k,3)if(dp[i][j]<a[k]){ dp[i][j]=a[k]; from[i][j]=k; }
	}

	int l=dp[slen][tlen];
	string ans(l,'@');
	for(int x=tlen,y=slen;~from[y][x];){
		switch(from[y][x]){
			case 0: x--; break;
			case 1: y--; break;
			case 2: x--; y--; ans[--l]=s[y]; break;
		}
	}

	return ans;
}

int main(){
	for(string s;cin>>s,s!="#END";){
		int len=s.length();
		string ans;
		for(int i=1;i<len;i++){
			if(min(i,len-i)<=ans.length())	break;
			string tmp=LCS(s.substr(0,i),s.substr(i));
			if(ans.length()<tmp.length())	ans=tmp;
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 2344
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>

typedef long long ll;

using namespace std;

int main() {
    int a, b, c, ans;

    cin >> a >> b >> c;

    a -= b;

    ans = c - a;

    if(0 > ans) {
        ans = 0;
    }

    cout << ans << endl;

    return 0;

}

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

int main(){
    int H, W, i, j;


for(;;){
    cin >> H >> W;


    if(H==0&&W==0) break;

    for(i=0; i<H; i++){
        if(i%2==0){
            for(j=0; j<W ; j++){
                if(j%2==0) {cout <<"#";
                }else{
                cout << ".";
                }
            }
            cout << endl;
        }else{
            for(j=0; j<W ; j++){
                if(j%2==0) {cout <<".";
                }else{
                cout << "#";
                }
            }
            cout << endl;
        }
    }
    cout << endl;
}
}



Measured memory_bytes: 3088
/*************************************************************************
  >         File: A.cc
  >       Author: Riho.Yoshioka
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sun 31 Jul 2016 08:00:23 PM CST
*************************************************************************/
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  int a, b;
  cin >> a >> b;
  int has = 0;
  if (a <= 0 && b >= 0) has = 1;
  if (has) {
    cout << "Zero" << endl;
  }
  else {
    if (a > 0) {
      cout << "Positive" << endl;
    }
    else {
      int cnt = 0;
      if (b < 0) {
        cnt = (b - a + 1);
      }
      else {
        cnt = -a;
      }
      cout << ((cnt & 1) ? "Negative" : "Positive") << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
/*  
     author : masaow    
     g++ : 17.3.20  
*/        
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+7;  
/*  
    time : 10 : 14    
    date : 24.02.2020
*/   
// int L,R,mid,target,idx ;
int tests() 
{

    int n ;
    cin >> n ;
    int c = 0 ; 
    vector <int> v(n) ;
    for(auto &x: v)
        cin >> x ; 
    for(int i = 1 ; i < n-1 ; i++ )
        if((v[i] < v[i+1] && v[i-1] < v[i]) || (v[i-1] > v[i] && v[i] > v[i+1])) 
            c++;
        cout << c << '\n' ; 
        return 0; 
}
int main(){
    I__O ;  
    int cases = 1 ; 
    //cin >> cases;  
    while(cases--)
      tests(); 
  return 0 ; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cstring>
using namespace std;
#define INF 1000000000
int main(){
	int n,k;
	while(scanf("%d%d",&n,&k),(n|k)){
		int a;
		int d[128][128];
		for(int i = 0; i < 101; i++){
			for(int j = 0; j < 101; j++){
				d[i][j] = i == j?0:INF;
			}
		}
		for(int l = 0; l < k; l++){
			scanf("%d",&a);
			if(a == 1){
				int f,t,c;
				scanf("%d%d%d",&f,&t,&c);
				f--;
				t--;
				if(d[f][t] > c){
					d[f][t] = d[t][f] = c;
					for(int i = 0; i < n; i++){
						for(int j = 0; j < n; j++){
							d[i][j] = min(d[i][j],d[i][f] + d[f][t] + d[t][j]);
							d[i][j] = min(d[i][j],d[i][t] + d[t][f] + d[f][j]);
							d[j][i] = d[i][j];
						}
					}
				}
			}
			else{
				int f,t;
				scanf("%d%d",&f,&t);
				f--;
				t--;
				if(d[f][t] == INF)puts("-1");
				else printf("%d\n",d[f][t]);
			}
		}
	}
	return 0;
}

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

int main() {
    int X, A, B; cin >> X >> A >> B;
    if (B - A <= 0) {
        cout << "delicious" << endl;
    } else if (B - A <= X) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
from itertools import accumulate
def sieve_of_eratosthenes_2017(N):
    numbers = [n & 1 for n in range(N + 1)]
    numbers[1] = 0
    numbers[2] = 1
    like2017 = [0] * (N + 1)
    p = 1
    while True:
        while not numbers[p]:
            p += 2
        if p * p > N:
            for i in range(p, N + 1, 2):
                if numbers[i] & numbers[(i + 1) >> 1]:
                    like2017[i] = 1
            return like2017
        if numbers[(p + 1) >> 1]:
            like2017[p] = 1
        for i in range(p * 2, N + 1, p):
            numbers[i] = 0
        p += 2

like2017 = sieve_of_eratosthenes_2017(10 ** 5)
like2017_sum = list(accumulate(like2017))
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(like2017_sum[r] - like2017_sum[l] + like2017[l])

Measured memory_bytes: 7840
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int n,l;
string a[101];
int main()
{
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		cout<<a[i];
	}
	return 0;
}


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

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const vector<long long> &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:] and S[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }

    // get lcp of S[a:] and T[b:]
    inline int getLCP(const RollingHash &T, int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != T.get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};


int N;
vector<long long> a, b;

void solve() {
    vector<long long> da(N*2), db(N*2);
    for (int i = 0; i < N*2; ++i) {
        int j = i % N;
        int k = (i + 1) % N;
        da[i] = a[j] ^ a[k];
        db[i] = b[j] ^ b[k];
    }

    RollingHash A(da), B(db);
    for (int k = 0; k < N; ++k) {
        int len = A.getLCP(B, k, 0);
        if (len >= N) {
            cout << k << " " << (a[k] ^ b[0]) << endl;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N) {
        a.resize(N); b.resize(N);
        for (int i = 0; i < N; ++i) cin >> a[i];
        for (int i = 0; i < N; ++i) cin >> b[i];
        solve();
    }
}


















Measured memory_bytes: 37888
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define Max(a,b) a=max(a,b);
typedef long long ll;

using namespace std;
#define N 200010
ll n,m,a[N],cnt[N],sum[N];
int main(){
    cin>>n>>m;
    lol(i,N)cnt[i]=0,sum[i]=0;
    lol(i,n){
	scanf("%lld",&a[i]);
	if(a[i]<N)cnt[a[i]]++;
    }
    lol(i,N){
	for(ll j=i-cnt[i]+1;j<=i;j++)sum[j]++;
    }
    ll ans=0;
    for(int i=1;i<=n;i++)ans+=sum[i]==0;
    lol(i,m){
	ll x,y; scanf("%lld%lld",&x,&y);  x--;
	if(a[x]<=n){
	    ll p=a[x]-cnt[a[x]]+1;
	    if(p>=1){
		sum[p]--;
		if(sum[p]==0)ans++;
	    }
	    cnt[a[x]]--;
	}
	a[x]=y;
	if(a[x]<=n){
	    ll p=a[x]-cnt[a[x]];
	    if(p>=1){
		if(sum[p]==0)ans--;
		sum[p]++;
	    }
	    cnt[a[x]]++;
	}
	printf("%lld\n",ans);
    }
    return 0;
}


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

struct restaurant {
	string city;
	int score;
	int idx;
} r[1004];

bool cmp(restaurant a, restaurant b){
	if(a.city<b.city)	return true;
	if(a.city == b.city)	return a.score>b.score;
	return false;
}
int main() {
	int n;
	cin>>n;
	for(int i = 0;i<n;i++){	
		cin>>r[i].city>>r[i].score;
		r[i].idx = i+1;
	}
	sort(r, r+n, cmp);
	for(int i = 0;i<n;i++)	cout<<r[i].idx<<endl;
	return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> P(m);
  vector<string> S(m);
  vector<int> A(n);
  vector<int> W(n);
  rep(i, m) cin >> P[i] >> S[i];
  int wa=0, ac=0;
  rep(i, m){
    if(A[P[i]-1]==1) ac = ac;
    else if(S[i] == "AC"){
      wa += W[P[i]-1];
      ac++;
      A[P[i]-1] = 1;
    }
    else W[P[i]-1]++;
  }
  cout << ac << " " << wa << endl;
}

Measured memory_bytes: 6912
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    string s;
    cin>>s;
    if(s[1] == 'B') {
        s[1] = 'R';
    }
    else {
        s[1] = 'B';
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <map>
using ll = long long;
using namespace std;

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

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

    vector<ll> A(N);

    rep(i, N) cin >> A[i];

    map<ll,ll> B;

    rep(i, N) ++B[A[i]];

    ll sum = 0;

    for (auto x : B) {
        ll y = x.second;
        ll z = y * (y - 1) / 2;
        sum += z;
    }

    rep(i, N) cout << sum - B[A[i]] + 1 << endl;

}

Measured memory_bytes: 11008
machi_number = input()
road_number = input()
mapp = [[10000 for j in range(machi_number)] for i in range(machi_number)]


for i in range(road_number):
	a,b,c,d =map(int, raw_input().split(","))
	aa = a-1
	bb = b-1
	mapp[aa][bb] = c
	mapp[bb][aa] = d
for i in range(machi_number):
	mapp[i][i] = 0

for k in range(machi_number):
	for i in range(machi_number):
		for j in range(machi_number):
			if mapp[i][j] > (mapp[i][k] + mapp[k][j]):
				mapp[i][j] = mapp[i][k] + mapp[k][j]

x1,x2,y1,y2 = map(int, raw_input().split(","))
print y1 - y2 - mapp[x1-1][x2-1] - mapp[x2-1][x1-1]

Measured memory_bytes: 4284
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	string S = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	int k[100];
	for (int n; cin >> n&&n;) {
		for (int i = 0; i < n; i++) {
			cin >> k[i];
		}
		string s; cin >> s;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] >= 'a') {
				int d = s[i] - 'a' + 26;
				cout << S[(d - k[i%n] + 52) % 52];
			}
			else {
				int d = s[i] - 'A';
				cout << S[(d - k[i%n] + 52) % 52];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

/// Lib
///

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    const string yes = "Yes";
    const string no = "No";

    string s; cin >> s;
    int n = s.size();

    vector<int> tmpr(n+1);
    for(int i = 0; i < n; ++i){
        if(s[i] == 'R'){
            tmpr[i + 1] = tmpr[i] + 1;
        }
    }
    vector<int> sumr(n);
    for(int i = 0; i < n; ++i){
        if(tmpr[i] > 0 && tmpr[i + 1] == 0){
            sumr[i] = tmpr[i];
        }
    }

    vector<int> tmpl(n+1);
    for(int i = n - 1; i >= 0; --i){
        if(s[i] == 'L'){
            tmpl[i] = tmpl[i + 1] + 1;
        }
    }
    vector<int> suml(n);
    for(int i = n - 1; i >= 0; --i){
        if(tmpl[i] > 0 && tmpl[i - 1] == 0){
            suml[i-1] = tmpl[i];
        }
    }


    for(int i = 0; i < n; ++i){
        int tmp = sumr[i] / 2 + sumr[i] % 2;
        sumr[i] -= tmp;
        sumr[i-1] += tmp;
    }

    for(int i = n-1; i >= 0; --i){
            int tmp = suml[i] / 2 + suml[i] % 2;
            suml[i] -= tmp;
            suml[i+1] += tmp;
    }

    vector<int> ans(n);
    for(int i = 0; i < n; ++i){
        ans[i] = sumr[i] + suml[i];
    }
    
    for(int i = 0; i < n-1; ++i){
        cout << ans[i] << " ";
    }
    cout << ans[n - 1] << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S; cin >> S;
    int K = 0;
    string a = "", b = "";
    for (auto c : S) {
        b += c;
        if (a != b) a = b, b = "", ++K;
    }
    cout << K << '\n';
}



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

#define endl '\n'
#define x first
#define y second
#define ii pair<int, int>
#define mp make_pair
#define pb push_back
#define vii vector<ii>
#define vi vector<int>
#define vvi vector<vi>
#define INF int(1e9)
#define TAM int(2e5)
#define LL long long int 

using namespace std;

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

int main () {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    LL ans = 0;

    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            for(int k=1; k<=n; k++)
                ans+=gcd(i, gcd(j, k));

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

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
 
std::vector<std::pair<std::pair<int,int>,long long> > v;
std::map<int,std::vector<int> > xis,yis;
std::vector<int> used;
 
std::map<int,long long> xAxis,yAxis;
 
bool traverse(int i,int x,int y,long long a,int dx,int dy){
  if(used[i])return true;
  auto itx = xAxis.find(x), ity = yAxis.find(y);
  if(itx==xAxis.end())xAxis[x] = dx;
  else if(itx->second!=dx)return false;
  if(ity==yAxis.end())yAxis[y] = dy;
  else if(ity->second!=dy)return false;
  used[i] = 1;
  for(const int &p : xis[x]){
    if(p!=i){
      long long a2 = v[p].second;
      bool r = traverse(p,v[p].first.first,v[p].first.second,a2,dx,dy+a2-a);
      if(!r)return false;
    }
  }
  for(const int &p : yis[y]){
    if(p!=i){
      long long a2 = v[p].second;
      bool r = traverse(p,v[p].first.first,v[p].first.second,a2,dx+a2-a,dy);
      if(!r)return false;
    }
  }
  return true;
}
 
struct C{
  bool operator()(const std::pair<int,long long>& l, const std::pair<int,long long>& r){
    return l.second < r.second;
  }
};
 
int main(){
  int r,c,n;
  std::cin >> r >> c >> n;
  for(int i=0;i<n;i++){
    int x,y,a;
    std::cin >> x >> y >> a;
    v.push_back(std::make_pair(std::make_pair(x,y),a));
    xis[x].push_back(i);
    yis[y].push_back(i);
    used.push_back(0);
  }
  for(int i=0;i<n;i++){
    if(!used[i]){
      xAxis.clear();
      yAxis.clear();
      bool b = traverse(i,v[i].first.first,v[i].first.second,v[i].second,0,v[i].second);
      if(!b){
        std::cout << "No" << std::endl;
        return 0;
      }
      long long xMin = std::min_element(xAxis.begin(),xAxis.end(),C()) -> second;
      long long yMin = std::min_element(yAxis.begin(),yAxis.end(),C()) -> second;
      if(xMin + yMin < 0){
        std::cout << "No" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}

Measured memory_bytes: 27248
#include<stdio.h>

typedef long long ll;

int main(void){
    ll A, B, K;

    scanf("%lld %lld %lld", &A, &B, &K);

    ll i=0;

    if(A<=K && B <= (K-A)){
        A=0;
        B=0;
        printf("0 0");
        return 0;
    }else if(A<=K && B>(K-A)){
        B=B-(K-A);
        A=0;
    }else{
        A=A-K;
    }

    printf("%lld %lld", A, B);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 998244353;
const int INF = 9e18;

signed main() {
    string S;
    cin >> S;
    bool check = true;
    for (int i = 0; i < S.length(); i++) {
        auto temp = S.substr(i, 2);
        if (temp == "hi") i++;
        else check = false;
    }
    cout << (check ? "Yes" : "No") << endl;
}


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

int main(){
  int n,d; cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < i; j++){
      int sq = 0;
      for(int k = 0; k < d; k++){
        int s = x[i][k]-x[j][k];
        sq += s*s;
      }
      int temp = sqrt(sq)+0.5;
      if(temp*temp == sq) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N,X = list(map(int, input().split()))
L = list(map(int, input().split()))
d = []
d.append(0)
count = 1
for i in range(1,N+1):
    d.append(d[i-1]+L[i-1])
    if d[i] <= X:
        count += 1
    else:
        break
print(count)


Measured memory_bytes: 2940
-- リストの最小の値でその他の値を割ってそのあまりに書き換える　のを繰り返す

import Control.Applicative
import Data.List

main :: IO ()
main = do
  _ <- getLine
  ss <- map read . words <$> getLine
  putStrLn $ show (solve ss)

solve :: [Int] -> Int
solve ss = solve' (sort ss) where
  solve' :: [Int] -> Int
  solve' [x] = x
  solve' (x:xs) = solve' $ sort $ filter (/= 0) ([x] ++ map (\p -> p `mod` x) xs)



Measured memory_bytes: 39804
# vim: set fileencoding=utf-8 :
x, y = map(int, raw_input().split())

if x % y == 0:
    print(-1)
    exit()

n = 1
top = pow(10, 18)

while True:
    t = n * x
    if t >= top:
        print(-1)
        break

    if t % y != 0:
        print(t)
        break

    n += 1


Measured memory_bytes: 2568