akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
 
const int N = 1e6 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

inline int mul(int a, int b){
    return ((ll)a * b) % mod;
}

inline int add(int a, int b){
    int ans = a + b;
    if(ans >= mod) ans -= mod;
    return ans; 
}

// credits : codeforces :https://codeforces.com/blog/entry/54396
bool isprime(ll n){
    if(n<2) return false;
    for(ll i=2;i*i*i<=n;++i) if(n%i==0) return false;
    for(int it=0;it<1e2;++it){
        ll i = rand()%(n-1)+1;
        if(__gcd(i,n)!=1) return false;
        // if(mpow(i,n-1,n)!=1) return false;
    }
    return true;
}

vector<ll> dp(1 << 16, -1);

ll foo(int mask, const int n, vector<ll>& subset_score){
    if(mask == ((1 << n) - 1)) return 0;
    ll &ans = dp[mask];
    if(ans == -1){
        int can = ((1 << n) - 1) ^ mask;
        ans = 0;
        // iterate over submask for the current group
        for(int j = can; j > 0; j = (j-1)&can)
            ans = max(ans, subset_score[j]+foo(mask^j, n, subset_score));
    }
    return ans;
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector< vector<ll> > score(n, vector<ll>(n));
    for(int j = 0; j < n; j++){
        for(int k = 0; k < n; k++) cin >> score[j][k];
    }
    
    vector<ll> subset_score((1 << n), 0);
    for(int j = 0; j < (1 << n); j++){
        vector<int> taken;
        ll &cur = subset_score[j];
        for(int k = 0; k < n; k++)
            if(j&(1 << k)){
                for(auto i : taken) cur += score[i][k];
                taken.pb(k);
            }
    }
    cout << foo(0, n, subset_score);
    
    return 0;
}


Measured memory_bytes: 1280
n,y = map(int, input().split())
can = [10000, 5000, 1000]
cnd = range(0, n+1)
result = [(i, j, n-i-j) for i in cnd for j in cnd if n-i-j in cnd and i*10000+j*5000+(n-i-j)*1000 == y]
result = [[-1,-1,-1]] if len(result) == 0 else result
print(" ".join([str(i) for i in result[0]]))

Measured memory_bytes: 3064
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

if all(x % 2 == 0 for x in A):
    print("Yes")
else:
    cnt4 = 0
    cnt2 = 0
    for a in A:
        if a % 4 == 0:
            cnt4 += 1
        elif a % 2 == 0:
            cnt2 += 1
    cntOdd = N - cnt4 - cnt2
    if cntOdd <= cnt4 or (abs(cntOdd - cnt4) <= 1 and cnt2 == 0):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 14252
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int M;
	cin >> M;
	long long int ans = -1, S = 0;
	for(int i = 0; i < M; i++){
		long long int d, c;
		cin >> d >> c;
		ans += c;
		S += d * c;
	}
	long long int cnt = 0;
	for(int i = 0; i < 100000; i++){
		cnt = (S + cnt) / 10;
	}
	cout << ans + cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long int o, a, total = 0, i, u, b = -10000000, c = 10000000000, n;
	scanf("%lld", &n);
	for (o = 0; o < n; o++) {
		scanf("%lld", &a);
		total += a;
		if (b < a) {
			b = a;
		}
		if (c > a) {
			c = a;
		}
	}
	printf("%lld %lld %lld\n", c,b, total);
	return 0;
}

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

int main(void) {
    string O,E;

    cin >> O >> E;
    for(int i=0;O[i];i++) {
        if(O[i]) cout << O[i];
        if(E[i]) cout << E[i];
    }

    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;

struct UnionFind{
	vector<int> parent;
	int N;
	UnionFind(int n) : parent(n), N(n){ //メンバイニシャライザを実行している
		for(int i=0; i<n; i++){
			parent[i] = i;
		}
	}
	int getParent(int x){
		return parent[x];
	}

	int root(int x){
		if(parent[x]==x){
			return x;
		}else{
			parent[x] = root(parent[x]); //親の付け替え(ならし)
			return parent[x];
		}
	}
	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if(rx!=ry){
			parent[ry] = rx;
		}
	}
	bool same(int x, int y){
		int rx = root(x);
		int ry = root(y);
		return rx==ry;
	}
};

int main(int argc, char* argv[]){
	int N,M;
	scanf("%d %d", &N, &M);
	vector<int>A(M);
	vector<int>B(M);
	UnionFind tree(N);
	for(int i=0; i<M; i++){
		scanf("%d %d", &A[i], &B[i]);
		if(A[i]>B[i]){
			int tmp;
			tmp =  B[i];
			B[i] = A[i];
			A[i] = tmp;
		}
		tree.unite(A[i]-1, B[i]-1);
	}
	int count = 0;
	for(int i=0; i<N; i++){
		if(tree.getParent(i)==i){
			count++;
		}
	}
	printf("%d\n", count-1);

}



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

const int maxn = 1e5 + 5, P = 1e9 + 7;
int n;
int x[maxn], inv[maxn];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
    }
    inv[1] = 1;
    for (int i = 2; i <= n; ++i) {
        inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
    }
    for (int i = 2; i <= n; ++i) {
        inv[i] = (inv[i] + inv[i - 1]) % P;
    }

    int ans = 0;
    for (int i = 1; i < n; ++i) {
        ans = (ans + 1ll * inv[i] % P *(x[i + 1] - x[i]) % P) % P;
    }
    for (int i = 1; i < n; ++i) {
        ans = 1ll * ans * i % P;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define pai 3.1415926535

int main(void) {
	int N;
	scanf("%d", &N);
	char S[11];
	scanf("%s", S);
	int K;
	scanf("%d", &K);

	for (int i = 0; i < N; i++) {
		if (S[i] != S[K - 1]) {
			S[i] = '*';
		}
	}
	printf("%s\n", S);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;

    int len = s.length();
    string a[len / 2];
    string b[len / 2];
    len = len / 2;

    for(int i = 0; i < len; ++i) {
        a[i] = s[i];
    }

    std::reverse(s.begin(), s.end());

    for(int i = 0; i < len; ++i) {
        b[i] = s[i];
    }

    int count = 0;
    for(int i = 0; i < len; ++i) {
        if(a[i] != b[i]) {

            count++;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

// 2018-08-01T22:01:05+0800
// 2018-08-01T22:11:37+0800
// Giving up and looking for help
// 2018-08-01T22:13:57+0800
// 2018-08-01T22:17:29+0800
// 2018-08-01T22:35:08+0800
func main() {
	var N int
	fmt.Scanf("%d", &N)
	a := make([]int, N)
	max := math.MinInt32
	maxi := 0
	min := math.MaxInt32
	mini := 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a[i])
		if a[i] > max {
			max = a[i]
			maxi = i
		}
		if a[i] < min {
			min = a[i]
			mini = i
		}
	}
	if min > 0 {
		fmt.Println(N - 1)
		for i := 0; i < N-1; i++ {
			fmt.Println(i+1, i+2)
		}
	} else if max < 0 {
		fmt.Println(N - 1)
		for i := N - 2; i >= 0; i-- {
			fmt.Println(i+2, i+1)
		}
	} else {
		if max > -min {
			// Set all to non-negative numbers.
			fmt.Println(2*N - 1)
			for i := 0; i < N; i++ {
				fmt.Println(maxi+1, i+1)
			}
			for i := 0; i < N-1; i++ {
				fmt.Println(i+1, i+2)
			}
		} else {
			fmt.Println(2*N - 1)
			for i := 0; i < N; i++ {
				fmt.Println(mini+1, i+1)
			}
			for i := N - 2; i >= 0; i-- {
				fmt.Println(i+2, i+1)
			}
		}
	}
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
  static class Data {
    public final long price;
    public final long count;

    public Data(long price, long count) {
      this.price = price;
      this.count = count;
    }
  }

  public static void main(String... args) {

    try (Scanner sc = new Scanner(System.in)) {
      long N = sc.nextLong();
      long M = sc.nextLong();
      List<Data> list = new ArrayList<>();
      for (int i = 0; i < N; ++i) {
        list.add(new Data(sc.nextLong(), sc.nextLong()));
      }
      list.sort(Comparator.comparingLong(o -> o.price));

      long total = 0;
      for (Data d : list) {
        if (d.count < M) {
          total += d.price * d.count;
          M -= d.count;
        } else {
          total += d.price * M;
          break;
        }
      }
      System.out.println(total);
    }
  }

}

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

int h, w, n;
int field[1001][1001];
pair<int, bool> dp[1002][1002];
int main()
{
  while(cin >> h >> w >> n && (h || w || n)){

    //part1
    for(int i = 1; i <= h + 1; i++)
      for(int j = 1; j <= w + 1; j++)
	dp[i][j] = make_pair(0, false);
    
    for(int i = 1; i <= h; i++)
      for(int j = 1; j <= w; j++)
	cin >> field[i][j];

    //part2
    dp[1][1] = make_pair(n, true);
    for(int i = 1; i <= h; i++){
      for(int j = 1; j <= w; j++){

	//part2-1
	if(dp[i][j].first % 2){
	  if(field[i][j]){
	    dp[i][j + 1].first += dp[i][j].first / 2 + 1;
	    dp[i + 1][j].first += dp[i][j].first / 2;
	  }
	  else{
	    dp[i][j + 1].first += dp[i][j].first / 2;
	    dp[i + 1][j].first += dp[i][j].first / 2 + 1;
	  }
	}
	else{
	  dp[i][j + 1].first += dp[i][j].first / 2;
	  dp[i + 1][j].first += dp[i][j].first / 2;
	}

	//part2-2
	if(dp[i][j].second){
	  if(dp[i][j].first % 2){
	    if(field[i][j])
	      dp[i][j + 1].second = true;
	    else
	      dp[i + 1][j].second = true;
	  }
	  else{
	    if(field[i][j])
	      dp[i + 1][j].second = true;
	    else
	      dp[i][j + 1].second = true;
	  }
	}
      }
    }

    //part3
    pair<int, int> ans;
    for(int i = 1; i <= h; i++)
      if(dp[i][w + 1].second)
	ans = make_pair(i, w + 1);

    for(int i = 1; i <= w; i++)
      if(dp[h + 1][i].second)
	ans = make_pair(h + 1, i);

    cout << ans.first << " " << ans.second << endl;
  }
  return 0;
}

Measured memory_bytes: 12916
h,w=map(int,input().split())
l=[input().split() for i in range(h)]
a=[chr(i) for i in range(65,65+26)]
for i in range(h):
  for j in range(w):
    if l[i][j]=='snuke':
      x=i
      y=j
      break
print(a[y]+str(x+1))

Measured memory_bytes: 3060
import math
import numpy as np


#a, b, c, x = map(int, [input() for i in range(4)])
#z = list(map(int, input().split()))
#n, a, b = map(int, input().split())

#print(len(z))
#for i in z:
#    print(i)

#a = sorted(a,reverse = True)
#print(sum(a[::2]) - sum(a[1::2]))

n = input()
z = map(int, [input() for i in range(int(n))])
z = set(z)
print(len(z))


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

int main() {
  string s;
  cin >> s;
  for (char c = 97; c <= 122; c++) {
    if (count(s.begin(), s.end(), c) % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 3628
val INF = 1001001001
fun main(arg: Array<String>) {
    var (N, X, Y) = listOfInt()
    X -= 1; Y -= 1
    val ans = IntArray(N)
    for (st in 0 until N) {
        val V = IntArray(N) { INF }
        val Q = Queue<Int>()
        fun push(v: Int, d: Int) {
            if (v !in 0 until N) return
            if (V[v] != INF) return
            V[v] = d
            Q.enqueue(v)
        }
        push(st, 0)
        while (!Q.isEmpty()) {
            val v = Q.dequeue()!!
            val d = V[v]
            push(v - 1, d + 1)
            push(v + 1, d + 1)
            if (v == X) push(Y, d + 1)
            if (v == Y) push(X, d + 1)
        }
        for (n in 0 until N) ans[V[n]] += 1
    }
    println(ans.drop(1).map { it / 2 }.joinToString("\n"))
}
class Queue<T> {
    val elements = mutableListOf<T>()
    fun isEmpty() = elements.isEmpty()
    fun enqueue(item: T) = elements.add(item)
    fun dequeue() = if (!isEmpty()) elements.removeAt(0) else null
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
fun listOfDouble(delta: Double = 0.0) = listOfString().map { java.lang.Double.parseDouble(it) + delta }
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map(String::toDouble)


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

int main() {
    auto is_palindrome = [] (string s) -> bool {
        int l = 0, r = s.size()-1;
        while(l < r)
            if (s[l++] != s[r--])
                return false;
        return true;
    };
    string s;
    cin >> s;
    string s1 = s.substr(0, (s.size()-1)/2);
    string s2 = s.substr((s.size()+3)/2-1);
    if (is_palindrome(s) && is_palindrome(s1) && is_palindrome(s2))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

int main() {
  srand(0);

  // input
  constexpr int n = 26;
  int d;
  cin >> d;
  vector<int> c(n);
  for (auto &e : c) cin >> e;
  vector<vector<int>> s(d, vector<int>(n));
  for (auto &se : s) {
    for (auto &e : se) cin >> e;
  }

  // solve
  int satisfaction = 0;
  vector<set<int>> v(n);
  for (auto &e : v) e.insert(-1);
  vector<int> t(d);
  for (int i = 0; i < d; i++) {
    t[i] = max_element(s[i].begin(), s[i].end()) - s[i].begin();
    satisfaction += s[i][t[i]];
    v[t[i]].insert(i);

    for (int j = 0; j < n; j++) {
      int last_i = *v[j].rbegin();
      satisfaction -= c[j] * (i - last_i);
    }
  }

  auto calculate_decline = [](int c, int d) { return -c * ((d - 1) * d / 2); };

  auto calculate_difference = [&](int i, int j) {
    int difference = 0;
    difference -= s[i][t[i]];
    difference += s[i][j];

    auto it1_to = v[t[i]].upper_bound(i);
    auto it1_from = it1_to;
    it1_from--;
    it1_from--;
    int i1_to = it1_to == v[t[i]].end() ? d : *it1_to, i1_from = *it1_from;

    auto it2_to = v[j].upper_bound(i);
    auto it2_from = it2_to;
    it2_from--;
    int i2_to = it2_to == v[j].end() ? d : *it2_to, i2_from = *it2_from;

    difference -= calculate_decline(c[t[i]], i - i1_from) + calculate_decline(c[t[i]], i1_to - i);
    difference += calculate_decline(c[t[i]], i1_to - i1_from);

    difference -= calculate_decline(c[j], i2_to - i2_from);
    difference += calculate_decline(c[j], i - i2_from) + calculate_decline(c[j], i2_to - i);

    return difference;
  };

  for (int iteration = 0; iteration < (int)1e7; iteration++) {
    if (rand() % 2) {
      int i = rand() % d, j = rand() % n;
      if (t[i] == j) continue;

      int difference = 0;
      difference += calculate_difference(i, j);

      if (difference > 0) {
        satisfaction += difference;
        v[t[i]].erase(i);
        v[j].insert(i);
        t[i] = j;
      }
    } else {
      int i = rand() % (d - 1);
      if (t[i] == t[i + 1]) continue;

      int difference = 0;
      difference += calculate_difference(i, t[i + 1]);
      difference += calculate_difference(i + 1, t[i]);

      if (difference > 0) {
        satisfaction += difference;
        v[t[i]].erase(i);
        v[t[i]].insert(i + 1);
        v[t[i + 1]].erase(i + 1);
        v[t[i + 1]].insert(i);
        swap(t[i], t[i + 1]);
      }
    }
  }

  // output
  cerr << "satisfaction: " << satisfaction << endl;
  cerr << "score: " << max((int)1e6 + satisfaction, 0) << endl;

  for (auto e : t) cout << e + 1 << endl;
}


Measured memory_bytes: 3640
//未

#include <iostream>
#include <limits>

using namespace std;

int N;
int *a;
long long **DP;

long long calc(int i, int j) {
	if (i == N - 1 - j) {
		//残り１つはどちらが取るか
		if (N % 2 == 0) return -a[i]; //次郎
		else return a[i];//太郎
	}
	else if (DP[i][j] != numeric_limits<long long>::max()) return DP[i][j];
	else {
		if ((i + j) % 2 == 0) { //太郎
			long long  max = a[i] + calc(i + 1, j);
			if (max < a[N - 1 - j] + calc(i, j + 1)) max = a[N - 1 - j] + calc(i, j + 1);
			return DP[i][j] = max;
		}
		else {
			long long min = -a[i] + calc(i + 1, j);
			if (min > -a[N - 1 - j] + calc(i, j + 1)) min = -a[N - 1 - j] + calc(i, j + 1);
			return DP[i][j] = min;
		}
	}
}

int main() {
	int i, j;

	cin >> N;

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

	DP = new long long*[N];
	for (i = 0; i < N; i++)
		DP[i] = new long long[N];

	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++)
			DP[i][j] = numeric_limits<long long>::max();
	}

	cout << calc(0, 0) << endl;

	for (i = 0; i < N; i++)
		delete[] DP[i];
	delete[] DP;
	delete[] a;


	return 0;
}

Measured memory_bytes: 70912
#include <iostream>
using namespace std;
int main(void){
    long long int ans, out = 0;
    long long int N, K;
    cin >> N >> K;
    
    ans = N;
    while(true){
        ans = ans / K;
        out++;
        if(ans / K <= 0)
            break;
    }
    if(N < 10) out = 0;
    cout << out + 1 << endl;
}


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

int main() {
  ll takahashi, aoki, k;
  cin >> takahashi >> aoki >> k;
  aoki = max(aoki - max(k - takahashi, 0ll), 0ll);
  takahashi = max(takahashi - k, 0ll);
  cout << takahashi << " " << aoki << endl;
}


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

const int MOD = 1e9 + 7;

int main() {
    int N; cin >> N;
    map<int, int> M;
    rep(i, 0, N) {
        int a; cin >> a;
        M[a]++;
    }
    int ans = 1;
    for (int i = N - 1; i >= 0; i -= 2) {
        ans = (ans * M[i]) % MOD;
    }
    for (int i = N - 1; i >= 2; i -= 2) {
        ans = (ans * (M[i] - 1)) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4096
#!/usr/bin/env python3
from collections import deque

h, w = list(map(int, input().split()))
s = [list(str(input())) for i in range(h)]

map_ = [[10**9]*w for i in range(h)]
# map_[0][0] = 10*

num_black = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            num_black += 1


dq = deque([[0, 0, 1]])


ans = 0
while(len(dq) > 0):
    y, x, dis = dq.popleft()

    if map_[y][x] > dis:
        map_[y][x] = dis
    else:
        continue

    for i, j in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        if y+i < 0 or y+i >= h:
            continue
        if x+j < 0 or x+j >= w:
            continue
        if map_[y+i][x+j] <= dis:
            continue
        if s[y+i][x+j] == "#":
            continue
        else:
            dq.appendleft([y+i, x+j, dis+1])

ans = map_[-1][-1]
# print(map_)

if ans == 10**9:
    print(-1)
else:
    print(w*h-ans-num_black)


Measured memory_bytes: 75052
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    LL ans = 1;
    string str;cin >> str;
    string s;cin >> s;
    I vec;
    char ins = str.front();
    int count = 0;
    REP(a,N){
        if(str.at(a)==ins){
            count++;
        }else{
            vec.pb(count);
            ins = str.at(a);
            count = 1;
        }
    }
    vec.pb(count);
    if(vec.front()==1){
        ans *= 3;
    }else{
        ans *= 6;
    }
    REP(a,vec.size()-1){
        if(vec.at(a)==2&&vec.at(a+1)==1){
            ans *= 1;
            ans %= MOD;
        }else if(vec.at(a)==2&&vec.at(a+1)==2){
            ans *= 3;
            ans %=MOD;
        }else{
            ans *= 2;
            ans %= MOD;
        }
    }
    COUT(ans);
    return 0;
}


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

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

  int N, Y; cin >> N >> Y;
  Y /= 1000;
  
  for (int x = 0; x <= N; x++) {
    int p = Y - N - 9 * x;
    if (p < 0 || p % 4)  continue;
    int y = p / 4;
    if (x + y > N) continue;
    int z = N - x - y;
    cout << x << " " << y << " " << z << "\n";
    return 0;
  }
  cout << -1 << " " << -1 << " " << -1 << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int H, N;
	cin >> H >> N;

	int accum = 0;

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

		accum += a;
	}

	if (accum >= H)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;
}


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

#define ll long long

int m2019of_ten(int n, vector<int> ten_chart) {
  if (ten_chart[n] != 2) {
    return ten_chart[n];
  } else {
    return m2019of_ten(n-1, ten_chart);
  }
}


int main(){
  string s;
  cin >> s;
  
  int N = s.size();
  
  
  vector<int> left(N+1, 0), right(N+2, 0);
  vector<int> ten_chart(N+2, 2);
  
  ten_chart[0] = 1;
  
  for (int i = 0; i < N; i++)
    ten_chart[i+1] = (ten_chart[i] * 10) % 2019;
  
  
  map<int, int> nums;

  
  for (int i = 0; i < N; i++) {
    left[i+1] = (left[i] + int(s[i]-'0') * ten_chart[N-i-1]) % 2019;
  }
  
  for (int i = 0; i < N+1; i++) {
    nums[left[i]]++;
  }
  
  
  ll ans = 0;
  for (auto it : nums) {
    ll num = it.second;
    ans += num * (num -1) / 2;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 6028
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N;
  cin >> N;
  vector<long long> M(5, 0);
  long long ans = 0;

  vector<int> P = {0,0,0,0,0,0,1,1,1,2};
  vector<int> Q = {1,1,1,2,2,3,2,2,3,3};
  vector<int> R = {2,3,4,3,4,4,3,4,4,4};
  string S;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S.at(0) == 'M') M.at(0)++;
    if (S.at(0) == 'A') M.at(1)++;
    if (S.at(0) == 'R') M.at(2)++;
    if (S.at(0) == 'C') M.at(3)++;
    if (S.at(0) == 'H') M.at(4)++;
  }
  for (int i = 0; i < 10; i++) {
    ans += M.at(P.at(i)) * M.at(Q.at(i)) * M.at(R.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# encoding: utf-8
import sys
# input = sys.stdin.readline
inf = 10 ** 18

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

from collections import deque

field = [[None] * W for _ in range(H)]
q = deque([])
cnt = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            field[i][j] = 0
            q.append((i, j, 0))
            cnt += 1

tblr = ((-1, 0), (1, 0), (0, -1), (0, 1))
while cnt < H * W:
    y, x, d = q.popleft()
    for dy, dx in tblr:
        if y + dy < 0: continue
        if x + dx < 0: continue
        if y + dy >= H: continue
        if x + dx >= W: continue
        if field[y + dy][x + dx] != None: continue
        #
        field[y + dy][x + dx] = d + 1
        q.append((y + dy, x + dx, d + 1))
        cnt += 1

print(max([max(field[i]) for i in range(H)]))


Measured memory_bytes: 176780
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long aDup = 0, ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') aDup > 0 && s[i - 1] == 'B' ? aDup = 1 : aDup++;
    else if (s[i] == 'C') aDup > 0 && s[i - 1] == 'B' ? ans += aDup : aDup = 0;
    else if (aDup > 0 && s[i - 1] == 'B') aDup = 0;
  }
  cout << ans << endl;
  return 0;
}

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

    	
    	
#define ll long long
#define pb push_back
#define mp make_pair

ll power(ll x,ll b)
{
    ll res=1;
    if(b==0)
    return 1;
    while(b>0)
    {
      if(b%2!=0)
      res=(res*x);
      b=b/2;
      x=(x*x);
      
    }
    return res;
}
 
 
       


  



      
   
    	
using namespace std;

 
vector<ll> primes;
void SieveOfEratosthenes(int n) 
{ 
    
    vector<ll>prime(200001,0);
  
    for (int p=2; p*p<=n;p++) 
    { 
       
        if (prime[p] == 0) 
        { 
           
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 1; 
        } 
    } 
    
  
    // Print all prime numbers 
    for (int p=1; p<=n; p++) 
       if (prime[p]==0) 
        {
            primes.pb(p);
        }
} 












int main()
{
   
    ll n;
    cin>>n;
    ll arr[n+1];
    for(ll i=0;i<n;i++)
    cin>>arr[i+1];
  
    ll dp[n+1],i;
    dp[2]=abs(arr[2]-arr[1]);
    dp[3]=abs(arr[3]-arr[1]);
    
    if(n>3)
    {
        for(i=4;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
        
    }
    cout<<dp[n]<<endl;
    }
    else
    {
        if(n==2)
        cout<<dp[2];
        else
        cout<<min(dp[2],dp[3]);
    }
  
      
       
    

   







}



Measured memory_bytes: 5144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String odd = sc.next();
		String even = sc.next();
		sc.close();

		int maxLength = Math.max(odd.length(), even.length());

		StringBuffer password = new StringBuffer();
		for(int i = 0; i < maxLength; i++) {
			if(odd.length() != even.length() && i == maxLength - 1) {
				password.append(odd.charAt(i));
			}else {
				password.append(odd.charAt(i));
				password.append(even.charAt(i));
			}
		}
		System.out.println(password.toString());
	}

}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

string YES = "Yes";
string NO = "No";

ll a, b, c, d;

void print(string s) {
	printf("%s\n", s.c_str());	
}

ll gcd(ll a, ll b) {
	if (!a) return b;
	return gcd(b % a, a);
}

void solve() {
	if (b > a) {
		print(NO);
		return;
	}
	if (d < b) {
		print(NO);
		return;
	}
	ll g = gcd(d, b);
	ll rem = a - max(0LL, a - c - 1) / b * b;
	if (rem < b) {
		print(NO);
		return;
	}

	ll best = c + g;

	err("rem = %lld\n", rem);
	err("best = %lld\n", best);
	
	if (best < b) {
		print(NO);
		return;
	}
	print(YES);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  int t;
  scanf("%d", &t);
  while (t--) {
  	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
		solve();		
	}

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
typedef long long ll;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N)cin >> A[i];
    while(K--){
        vec<l_l> v;
        rep(i,N){
            ll l = max(0LL, i - A[i]);
            ll r = min(N-1, i + A[i]);
            v.emplace_back(l,r);
        }
        vec<ll> I(N+1, 0);
        rep(i,N){
            I[v[i].first]++;
            I[v[i].second+1]--;
        }
        rep(i,N){
            I[i+1]+=I[i];
        }
        I.pop_back();
        bool fin = true;
        rep(i,N){
            if(I[i] != N)fin = false;
        }
        if(fin){
            rep(i,N){
                cout << I[i] << " ";
            }
            cout << endl;
            return 0;
        }
        swap(A, I);
    }
    rep(i,N){
        cout << A[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 12960
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int y=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    y+=a[i];
  }
  int mi=10000000;
  int h=0;
  for(int i=0;i<n;i++){
    h+=a[i];
    mi=min(mi,abs(h-(y-h)));
  }
  cout<<mi<<endl;
}
      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define LD long double

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

    LL n;
    cin>>n;
    LL a[n];
    map<LL,LL> cnt;
    for(LL i=0;i<n;i++){
        cin>>a[i];
        cnt[a[i]]++;
    }
    LL sum=0;
    for(auto i:cnt){
        LL x=i.second;
        sum+=(x*(x-1))/2;
    }
    for(LL k=0;k<n;k++){
        LL ans=0;
        LL x=a[k];
        LL y=cnt[x];
        ans=sum;
        ans-=(y*(y-1))/2;
        y--;
        ans+=(y*(y-1))/2;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 11136
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,ans;
vector<ll> v;
map<ll,ll> mp;
ll f(ll n){
    ll m=1;
    while(m<=n)m*=2;
    return m-n;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        mp[a]++;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=0;i<n;i++){
        if(mp[v[i]]>0)mp[v[i]]--;
        else continue;
        if(mp[f(v[i])]>0){
            mp[f(v[i])]--;
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 26864
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Knight solver = new Knight();
        solver.solve(1, in, out);
        out.close();
    }

    static class Knight {
        public static int MOD = 1000000007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();

            if ((x + y) % 3 != 0) {
                out.println(0);
                return;
            }

            int n = (2 * y - x) / 3;
            int m = (2 * x - y) / 3;

            if (n < 0 || m < 0) {
                out.println(0);
                return;
            }

            out.println(combination(n + m, n, MOD));

        }

        static long modPow(long x, long n, long mod) {
            if (n == 0) {
                return 1;
            }
            long result = modPow(x, n / 2, mod);

            if (n % 2 == 0) {
                return (result * result) % mod;
            }
            return (((result * result) % mod) * x) % mod;
        }

        static long modInv(long a, long mod) {
            return modPow(a, mod - 2, mod);
        }

        static long modDiv(long a, long b, long mod) {
            return a * modInv(b, mod) % mod;
        }

        static long combination(long n, long k, long mod) {

            long a = 1, b = 1;
            for (int i = 0; i < k; i++) {
                a = a * (n - i) % mod;
                b = b * (i + 1) % mod;
            }
            return modDiv(a, b, mod);
        }

    }
}



Measured memory_bytes: 35964
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

bool is_prime(ll n){
  for(ll i = 2; i * i<=n; i++){
    if(n%i==0) return false;
  }
  return n!=1;
}

int main(){
  ll n;
  cin >> n;
  map<ll,ll> res;
  for(ll j = 1; j<= n; j++){
    ll s = j;
    for(ll i = 2; i*i <= n; i++){
      while(s%i==0){
        ++res[i];
        s/=i;
      }
    }
    if(s!=1) res[s]++;
  }
  ll ans = 1;
  for(ll j = 1; j <= n; j++){
    ans = ans * (res[j]+1) % 1000000007;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;


using namespace std;



void solve()
{
	int n, r;
	scanf("%d%d", &n, &r);
	if (n < 10) {
		r = r + (100 * (10 - n));
	}
	printf("%d\n", r);
    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


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

int main(){
    
    string S;
    cin >> S;
    string T = "keyence";
    string R = S;
    string Q;
    for(int i = 0; i <S.size();i++){
        for(int j = i; j < S.size();j++){
            R = S;
            Q = R.erase(i,j-i);
            //cout << Q <<endl;
            if(Q == T){
                cout <<"YES"<<endl;
                return 0;
            }
        }
    }
    cout <<"NO"<<endl;
    return 0;
    
}       
    
    



Measured memory_bytes: 256
import math
a, b, x = map(int, input().split())
if x <= a * a * b / 2:
    t = 2 * x / a / b
    theta = math.atan2(b, t) / math.pi * 180
else:
    y = a * a * b - x
    t = 2 * y / a / a
    theta = math.atan2(t, a) / math.pi * 180
print(theta)

Measured memory_bytes: 62548
N = int(input())
h = [int(x) for x in input().split()]
dp = [0] * N
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[N - 1])


Measured memory_bytes: 13980
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] d1 = new int[100010];
    int[] d2 = new int[100010];
    int n = sc.nextInt();
    
    int res = 0;
    if( n>2 ){
      for(int i=0;i<n;i++){
        int v = sc.nextInt();
        if( ( i & ((int)1)) == 0 ){
          d1[v] ++;
        } else {
          d2[v] ++;
        }
      }
      int m11=0,m12=0,m21=0,m22=0;
      for(int i=1;i<=100000;i++){
        if( d1[i]>d1[m11] ){
          m12 = m11;
          m11 = i;
        } else if( d1[i]>d1[m12] ){
          m12 = i;
        }
        if( d2[i]>d2[m21] ){
          m22 = m21;
          m21 = i;
        } else if( d2[i]>d2[m22] ){
          m22 = i;
        }
      }
      if( m11 != m21 ){
        res = n - d1[m11] - d2[m21];
      } else {
        res = Math.min( n - d1[m12] - d2[m21] , n - d1[m11] - d2[m22] );
      }
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 58272
n, m = map(int, raw_input().split())
a, b = [], []
c = [0 for _ in range (n)]
for _ in range(n):
	a.append(map(int, raw_input().split()))
for _ in range(m):
	b.append(int(raw_input()))
for i in range(n):
	for j in range(m):
		c[i] += a[i][j]*b[j]
	print c[i]

Measured memory_bytes: 4820
N,K,Q = (int(i) for i in input().split())

points = [K-Q for i in range(N)]
for i in range(Q):
  A = int(input()) - 1
  points[A] += 1

for i in range(N):
  if points[i] <= 0:
    print("No")
  else:
    print("Yes")


Measured memory_bytes: 7884
// Beginner161.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <bits/stdc++.h>
using namespace std;

int main()
{
    //A
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << ' ' << a << ' ' << b << '\n';
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    for(int i = 0; i < n; i++){
        auto p = lower_bound(a.begin(),a.end(),b[i]);
        auto q = upper_bound(c.begin(),c.end(),b[i]);
        ans += ((ll)(p - a.begin()) * (ll)(c.end() - q));
    }
    cout << ans;
}

Measured memory_bytes: 1408
n,m = map(int,input().split())
peer = [[] for _ in range(n)]
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[b].append(a)
  if i == 0:
    dot0 = [a]
    dot1 = [b]
seen = [0 for _ in range(n)]
seen[dot0[0]] = 1
seen[dot1[0]] = 1
now0 = peer[dot0[0]]
while now0:
  x = now0.pop()
  if seen[x] == 0:
    seen[x] = 1
    dot0.append(x)
    now0 = peer[x]
now1 = peer[dot1[0]]
while now1:
  x = now1.pop()
  if seen[x] == 0:
    seen[x] = 1
    dot1.append(x)
    now1 = peer[x]
dot0.reverse()
dot = dot0 + dot1
#print(dot0)
#print(dot1)
print(len(dot))
print(' '.join(map(lambda x: str(x+1), dot)))

Measured memory_bytes: 74400
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
    unordered_map<string, int> m;
    int n;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<"AC"<<" x "<<m["AC"]<<endl;
    cout<<"WA"<<" x "<<m["WA"]<<endl;
    cout<<"TLE"<<" x "<<m["TLE"]<<endl;
    cout<<"RE"<<" x "<<m["RE"]<<endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())

typedef	long long ll;

const int MAXN = 2e5+1;

vector<int> G[MAXN];
vector<int> side[2];
vector<int> colors[3];
int choice[MAXN];

void dfs(int u, int p, int s)
{
	side[s].push_back(u);
	for (auto v : G[u])
		if (v != p)
			dfs(v,u,!s);
}

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

	int N;
	cin >> N;
	for (int i(1); i < N; ++i)
	{
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	dfs(1,1,0);
	for (int i(1); i <= N; ++i)
		colors[i%3].push_back(i);
	if (SZ(side[0]) > SZ(side[1]))
		swap(side[0], side[1]);

	if (SZ(side[0]) <= SZ(colors[0]))
	{
		while (SZ(side[0]) > 0)
		{
			choice[side[0].back()] = colors[0].back();
			colors[0].pop_back();
			side[0].pop_back();
		}
		for (int c(0); c < 3; ++c)
			while (SZ(colors[c]) > 0)
			{
				choice[side[1].back()] = colors[c].back();
				side[1].pop_back();
				colors[c].pop_back();
			}
	}
	else
	{
		while (SZ(colors[1]) > 0)
		{
			choice[side[1].back()] = colors[1].back();
			side[1].pop_back();
			colors[1].pop_back();
		}
		while (SZ(side[1]) > 0)
		{
			choice[side[1].back()] = colors[0].back();
			side[1].pop_back();
			colors[0].pop_back();
		}
		for (int c : {0, 2})
			while (SZ(colors[c]) > 0)
			{
				choice[side[0].back()] = colors[c].back();
				side[0].pop_back();
				colors[c].pop_back();
			}
	}

	for (int i(1); i <= N; ++i)
		cout << choice[i] << ' ';
	cout << endl;
}



Measured memory_bytes: 22388
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    string s;
    cin >> s;

    ll scnt = 0;
    ll tcnt = 0;
    ll res = 0;
    char cur = 'S';
    REP(i,s.size())
    {
        if(s[i] == cur)
        {
            if(cur == 'S')
            {
                ++scnt;
            }
            else
            {
                ++tcnt;
            }
        }
        else
        {
            if(cur == 'S')
            {
                cur = 'T';
                tcnt = 1;
            }
            else
            {
                res += max(tcnt - scnt, (ll)0);
                cur = 'S';
                scnt = max((ll)0, scnt - tcnt) + 1;
                tcnt = 0;
            }
        }
    }

    res += abs(tcnt - scnt);


    cout << res << endl;

    return 0;
}



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

int main(){
  	int i;
	int n;
  	cin >> n;
  	int a[n];
  	for(i=0;i<n;i++){
    	cin>>a[i];
    }
  	for(i=0;i<n;i++){
      if(a[i]%2==0)
    	if(a[i]%3!=0&&a[i]%5!=0){
          	break;
        }
    }
  
  	if(i==n){
  		cout<<"APPROVED"<<endl;
    }else {
        cout<<"DENIED"<<endl;
    }
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
    int AC = 0;
    int WA = 0;
    int TLE = 0;
    int RE = 0;
  cin >> n;
  vector<string> result(n);
  for (int i = 0; i < n; i++){
    cin >> result.at(i);
  }
   for (int i = 0; i < n; i++){
 	if(result.at(i) == "AC")AC++;
	if(result.at(i) == "WA")WA++;
    if(result.at(i) == "TLE")TLE++;
    if(result.at(i) == "RE")RE++;
   }
  cout << "AC x " << AC <<endl;
  cout << "WA x "<< WA <<endl;
  cout << "TLE x "<< TLE <<endl;
  cout << "RE x "<< RE <<endl;
}

Measured memory_bytes: 6424
n=int(input())
v=list(map(int,input().split()))
import collections as col
o=col.Counter(v[0:n:2])
e=col.Counter(v[1:n:2])
ook=o.most_common()
eok=e.most_common()
ok=ook[0][1]+eok[0][1]
if ook[0][0]==eok[0][0]:
    if len(ook)<2 and len(eok)<2:
        print(n//2)
        exit()
    elif len(ook)<2:
        ok=ook[0][1]+eok[1][1]
    elif len(eok)<2:
        ok=ook[1][1]+eok[0][1]
    else:
        ok=max(ook[0][1]+eok[1][1],ook[1][1]+eok[0][1])
print(n-ok)

Measured memory_bytes: 25532
using System;

namespace _046_Differential
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			decimal max = decimal.MinValue;
			decimal min = decimal.MaxValue;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				decimal height = decimal.Parse (inputStr);

				max = Math.Max (max, height);
				min = Math.Min (min, height);
			}

			Console.WriteLine (max - min);
		}
	}
}

Measured memory_bytes: 9184
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    
    
    public static void main(String[] args){
        
        Scanner in = new Scanner(System.in);
        
        int x = in.nextInt();
        
        int y = in.nextInt();
        
        int z = in.nextInt();
        
        int k = in.nextInt();
        
        int x1=x;
        
        int y1=y;
        
        
        int res[]=new int[3];
        
        for(int i=0;i<3;i++){
            
            for(int j=0;j<k;j++){
                
                if(i==0){
                   
                    x=x*2;
                    res[0]=x+y+z;
                   
                }
                
                if(i==1){
                    
                    x=x1;
                    y=y*2;
                    res[1]=x+y+z; 
                }
                
                if(i==2){
                   
                    y=y1;
                    z =z*2;
                    res[2]=x+y+z; 
                    
                }
            }
            
        }
        
        Arrays.sort(res);
        
        System.out.println(res[res.length-1]);
       
       
    }
    
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,ara[201],i,j,mn=656565656;
  cin>>n;
  for(int i=0;i<n;i++)cin>>ara[i];
  for(int i=-100;i<=100;i++)
  {
      int cost=0;
      for(int j=0;j<n;j++)
      {
          cost+=(ara[j]-i)*(ara[j]-i);
      }
      mn=min(mn,cost);
  }
  cout<<mn<<endl;


}


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

using namespace std;

const int N = 2020;
const int mod = 1000000007;
using Arr = array<array<int, 5>, N>;

void add(int &x, int y) {
   x += y;
   if (x >= mod) x -= mod;
}

int mul(int x, int y) {
   return (long long) x * y % mod;
}

vector<int> g[N];
int sz[N];
Arr f[N];

Arr mrg(Arr x, Arr y, int sx, int sy) {
   Arr z = {};
   for (int ny = 1; ny <= sy; ++ny) {
      array<int, 2> cnt = {};
      for (int i = 0; i < 5; ++i) {
         add(cnt[i > 2], y[ny][i]);
      }
      for (int nx = 1; nx <= sx; ++nx) {
         for (int i = 0; i < 3; ++i) {
            add(z[nx + ny][i], mul(x[nx][i], cnt[0]));
            if (i < 2) {
               add(z[nx + ny - 1][i + 1], mul(x[nx][i], cnt[1]));
            }
         }
         for (int i = 3; i < 5; ++i) {
            add(z[nx + ny][i], mul(x[nx][i], cnt[0]));
            if (i < 4) {
               add(z[nx + ny - 1][i + 1], mul(x[nx][i], cnt[1]));
            }
         }
      }
   }
   return z;
}

void dfs(int u) {
   f[u][1][3] = mod - 1;
   f[u][1][0] = 1;
   sz[u] = 1;
   for (int v : g[u]) {
      dfs(v);
      f[u] = mrg(f[u], f[v], sz[u], sz[v]);
      sz[u] += sz[v];
   }
   for (int nu = 1; nu <= sz[u]; ++nu) {
      for (int i = 1; i < 3; ++i) {
         f[u][nu][i] = mul(f[u][nu][i], 2);
      }
   }
}

int main() {
   ios_base::sync_with_stdio(false);
   int n;
   cin >> n;
   for (int i = 2; i <= n; ++i) {
      int p;
      cin >> p;
      g[p].push_back(i);
   }
   dfs(1);
   int ans = 0;
   int fact = 1;
   for (int i = 1; i <= n; ++i) {
      fact = mul(fact, i);
      int ways = 0;
      for (int j = 0; j < 3; ++j) {
         add(ways, f[1][i][j]);
      }
      add(ans, mul(fact, ways));
   }
   cout << ans << "\n";
}


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

int main() {
    int h,w;cin>>h>>w;
    int a[h][w];
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
            cin>>a[i][j];
    vector<string> ans;
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
            if (a[i][j]%2) {
                stringstream ss;
                if (j==w-1) {
                    if (i!=h-1) {
                        ss<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
                        ans.push_back(ss.str());
                        a[i][j]--;
                        a[i+1][j]++;
                    }
                } else {
                    ss<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
                    ans.push_back(ss.str());
                    a[i][j]--;
                    a[i][j+1]++;
                }
            }
    cout<<ans.size()<<endl;
    for (string s:ans)
        cout<<s;
    return 0;
}

Measured memory_bytes: 11252