akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());

			var cities = new List<int[]>();
				
			for(var i = 0; i < n; i++)
			{
				cities.Add(Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray());
			}

			var array = new int[n];
			var factorial = 1L;
			for(var i = 0; i < n; i++)
			{
				array[i] = i;
				factorial *= i + 1;
			}

			var permutations = GetAllPermutation(array);

			var totalDistance = 0d;

			foreach(var permutation in permutations)
			{
				for(var i = 0; i < n - 1; i++)
				{
					var x = cities[permutation[i]][0] - cities[permutation[i + 1]][0];
					var y = cities[permutation[i]][1] - cities[permutation[i + 1]][1];

					totalDistance += Math.Sqrt(x * x + y * y);
				}
			}

			Console.WriteLine(totalDistance / factorial);
		}

		private static List<int[]> GetAllPermutation(int[] array)
		{
			var permutations = new List<int[]>();
			permutations.Add(array);

			while(true)
			{
				int i;
				var list = permutations[permutations.Count - 1].ToList();

				for (i = list.Count - 2; i >= 0; i--)
				{
					if (list[i] < list[i + 1])
					{
						break;
					}
				}

				if (i < 0)
				{
					break;
				}

				for(var j = list.Count - 1; j > i; j--)
				{
					if(list[i] < list[j])
					{
						var tmp = list[i];
						list[i] = list[j];
						list[j] = tmp;

						list.Reverse(i + 1, list.Count - (i + 1));
						permutations.Add(list.ToArray());
						break;
					}
				}
			}

			return permutations;
		}
	}
}


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

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

  std::vector<int> n(4);
  for (int i = 0; i < 4; i++) {
    n[i] = s[i] - '0';
  }

  for (int i = -1; i <= 1; i+=2) {
    for (int j = -1; j <= 1; j+=2) {
      for (int k = -1; k <= 1; k+=2) {
        if (n[0] + i * n[1] + j * n[2] + k * n[3] == 7) {
          std::cout << n[0] << (i == -1 ? '-' : '+') <<
            n[1] << (j == -1 ? '-' : '+') << n[2]
            << (k == -1 ? '-' : '+') << n[3] << "=7" << std::endl;
            return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra() {
	int minv;
	int d[MAX], color[MAX];
	
	for(int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}
	
	d[0] = 0;
	color[0] = GRAY;
	while(1) {
		minv = INFTY;
		int u = -1;
		for(int i = 0; i < n; i++) {
			if(minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		color[u] = BLACK;
		for(int v = 0; v < n; v++) {
			if(color[v] != BLACK && M[u][v] != INFTY) {
				if(d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}
	for(int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			M[i][j] = INFTY;
		}
	}
	
	int k, c, u, v;
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		for(int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	
	dijkstra();
	
	return 0;
}

Measured memory_bytes: 3104
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

#define N 100010

int n,m,x,y,cnt,ans,p[N],mark1[N],mark2[N]; // 1:weizhi 2:shuzi

struct edge{
	int e;
	edge *next;
} *v[N],ed[N<<1];

void add_edge(int s,int e){
	ed[++cnt].next = v[s];
	v[s] = ed+cnt;
	v[s] -> e = e;
}

void dfs(int x,int fa,int k){
	if (mark1[x]) return ;
	mark1[x] = k;
	mark2[p[x]] = k;
	for (edge *e=v[x];e;e=e->next){
		if (e->e == fa) continue;
		dfs(e->e,x,k);
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	cnt = 0;
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		add_edge(x,y);
		add_edge(y,x);
	}
	for (int i=1;i<=n;i++)
		if (!mark1[i]) dfs(i,0,i);
	for (int i=1;i<=n;i++)
		if (mark1[i]==mark2[i]) ans++;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 8320
#include <stdio.h>

int main(void)
{
    int i = 0, N;
    int a, b, c;

    scanf("%d", &N);
    while (i++ < N) {
        scanf("%d %d %d", &a, &b, &c);
        if ((a*a == b*b + c*c) ||
            (b*b == c*c + a*a) ||
            (c*c == a*a + b*b))
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstring>
#include <cmath> 
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;   
int main()  
{ 
    string s[3];
    for(int i=0;i<3;i++)cin>>s[i];
    cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;


    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> void sortTwoVecter(vector<T1> &f, vector<T2> &s, bool isReverse = false){
    vector<pair<T1, T2>> p;
    rep(i, f.size()) p.emplace_back(make_pair(f[i], s[i]));
    if (!isReverse) sort(p.begin(), p.end());
    else sort(p.rbegin(), p.rend());
    rep(i, f.size()) tie(f[i], s[i]) = p[i];
    return;
}

int main(){
    ll N; cin >> N;
    vector<ll> a(N), b(N, 0);
    rep(i, N) cin >> a[i];
    rep(i, N){
        b[a[i]]++;
    }
    // debug(b);
    if (N % 2 == 0){
        rep(i, N){
            if (i % 2 == 0){
                if (b[i] != 0){
                    pt(0);
                    return 0;
                }
            }else{
                if (b[i] != 2){
                    pt(0);
                    return 0;
                }
            }
        }
    }else{
        rep(i, N){
            if (i == 0){
                if (b[i] != 1){
                    pt(0);
                    return 0;
                }
            }else if (i % 2 == 0){
                if (b[i] != 2){
                    pt(0);
                    return 0;
                }
            }else{
                if (b[i] != 0){
                    pt(0);
                    return 0;
                }
            }
        }
    }
    pt(mpow(2, N / 2, MOD));
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){

	int a, b;

	scanf("%d %d", &a, &b);

	if (a > b){
		printf("a > b\n");
	}
	else if (a < b){
		printf("a < b\n");
	}
	else{
		printf("a == b\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  priority_queue<int> que;
  REP(i, N)
  {
    ll A;
    cin >> A;
    que.push(A);
  }
  REP(i, M)
  {
    int X = que.top();
    que.pop();
    X /= 2;
    que.push(X);
  }
  ll ans = 0;
  REP(i, N)
  {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 892
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

string calc(Vec2 p0, Vec2 p1, Vec2 p2) {
    auto p01 = p1 - p0;
    auto p02 = p2 - p0;

    auto d = p01.cross(p02);
    if (d > 0)
        return "COUNTER_CLOCKWISE";
    if (d < 0)
        return "CLOCKWISE";

    // |p01||p02|cos(pi) ??§ cos(pi) = -1 ????????§??????????????????
    if (p01.dot(p02) < 0)
        return "ONLINE_BACK";

    if (p01.magSq() >= p02.magSq())
        return "ON_SEGMENT";
    return "ONLINE_FRONT";
}

void main() {
    auto xs = readints();
    auto p0 = Vec2(xs[0], xs[1]);
    auto p1 = Vec2(xs[2], xs[3]);

    int q = readint();
    for (int i = 0; i < q; i++) {
        auto xy = readints();
        auto p2 = Vec2(xy[0], xy[1]);
        auto ans = calc(p0, p1, p2);
        writeln(ans);
    }
}

struct Vec2 {
    immutable double x;
    immutable double y;

    this(double x, double y) {
        this.x = x;
        this.y = y;
    }

    Vec2 opAdd(Vec2 other) {
        return Vec2(this.x + other.x, this.y + other.y);
    }

    Vec2 opSub(Vec2 other) {
        return Vec2(this.x - other.x, this.y - other.y);
    }

    Vec2 opMul(double d) {
        return Vec2(this.x * d, this.y * d);
    }

    double dot(Vec2 other) {
        return this.x * other.x + this.y * other.y;
    }

    double cross(Vec2 other) {
        return this.x * other.y - other.x * this.y;
    }

    double mag() {
        return sqrt(magSq());
    }

    double magSq() {
        return this.x * this.x + this.y * this.y;
    }

    Vec2 normalize() {
        auto m = mag();
        if (m != 0 && m != 1)
            return Vec2(this.x / m, this.y / m);
        return this;
    }

    static double distance(Vec2 a, Vec2 b) {
        return (a - b).mag();
    }
}

Measured memory_bytes: 2504
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		init(1300000);
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n==0) {
				break;
			}
			if (isPrime(n) || n == 1) {
				System.out.println(0);
			}else{
				int i = n+1;
				while(!isPrime(i)) {
					i++;
				}
				int higherp = i;
				i = n-1;
				while(!isPrime(i)) {
					i--;
				}
				int lowerp = i;
				System.out.println(higherp-lowerp);
			}
		}
	}

	private static long max_number;
	private static int max_number_sieve;
	private static boolean[] is_not_prime;
	private static ArrayList<Integer> prime = new ArrayList<Integer>();
	public static void init(long maxnum) {
		max_number = maxnum;
		max_number_sieve = (int) Math.sqrt(max_number);
		is_not_prime = new boolean[max_number_sieve+1];
		is_not_prime[0] = is_not_prime[1] = true;
		for(int i=2;i*i<=max_number_sieve;i++) {
			if (!is_not_prime[i]) {
				int j = 2;
				while(i*j<=max_number_sieve) {
					is_not_prime[i*j] = true;
					j++;
				}
			}
		}
		for(int i=2;i<=max_number_sieve;i++) {
			if(!is_not_prime[i]) {
				prime.add(i);
			}
		}
	}
	public static boolean isPrime(long n) {
		if (n>max_number) {
			return false;
		}
		if (n<=max_number_sieve) {
			return !is_not_prime[(int) n];
		}else{
			for(int p:prime) {
				if (n%p==0 && n!=p) {
					return false;
				}
			}
			return true;
		}
	}
	public static int countPrime(long first,long last) {
		if (first>last) {
			return 0;
		}
		if (last>max_number) {
			return -1;
		}
		int num = 0;
		for(int i=(int) first;i<=last;i++) {
			if (isPrime(i)) {
				num++;
			}
		}
		return num;
	}
	public static ArrayList<Integer> primeFactor(long n) {
		ArrayList<Integer> factor = new ArrayList<Integer>();
		for(int p:prime) {
			while(n%p==0) {
				n/=p;
				factor.add(p);
			}
		}
		return factor;
	}
	public static ArrayList<Factor> primeFactorExp(long n) {
		ArrayList<Factor> factor = new ArrayList<Factor>();
		if (n==0) {
			return factor;
		}
		for(int p:prime) {
			int q = 0;
			while(n%p==0) {
				n/=p;
				q++;
			}
			if (q>=1) {
				factor.add(new Factor(p,q));
			}
		}
		return factor;
	}
}
class Factor {
	int base;
	int exp;
	public Factor(int base,int exp) {
		this.base = base;
		this.exp = exp;
	}
	public String toString() {
		if (exp==1) {
			return Integer.toString(base);
		}else{
			return base + "^" + exp;
		}
	}
}

Measured memory_bytes: 24408
N=int(input())
D=sorted(map(int,input().split()))[::-1]
M=int(input())
T=sorted(map(int,input().split()))
for t in T:
    d=0
    while D and d!=t:
        d=D.pop()
    if d!=t:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 35428
#!/usr/bin/env python3

S = int(input())

if S == 1 or S == 2 or S == 4:
    print(4)
    exit()

A = [S]
e = S
cnt = 0
while True:
    if e % 2 == 0:
        v = e//2
    else:
        v = 3*e+1
    A.append(v)
    e = v
    cnt += 1
    if v == 4:
        print(cnt+4)
        exit()



Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K, S;
  cin >> N >> K >> S;
  vector<int> vec(N,S-1);
  for(int i=0; i<K; i++){
    vec.at(i) = S;
  }
  if(S == 1){
    for(int i=K; i<N; i++){
      vec.at(i) = 2;
    }
  }
  if(S == 2){
    for(int i=K; i<N; i++){
      vec.at(i) = 3;
    }
  }
  for(int i=0; i<N; i++){
    cout << vec.at(i);
    if(i != N-1){
      cout << " ";
    }
  }
  cout << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int n;
double a[105];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lf",&a[i]);
	}
	sort(a+1,a+n+1);
	for(int i=2;i<=n;++i){
		a[i]=(a[i]+a[i-1])/2;
	}
	printf("%lf",a[n]);
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  int N,M; cin>>N>>M;
  priority_queue<ll> Q;
  rep(i,N){
    ll a; cin>>a;
    Q.push(a);
  }
  while(M){
    ll q = Q.top();
    Q.pop();
    q = q/2;
    Q.push(q);
    M--;
  }
  ll res = 0;
  while(!Q.empty()){
    res += Q.top();
    Q.pop();
  }
  cout<<res<<endl;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
#define MAX 10000
int main(){
int a,b,c;
cin>>a>>b>>c;
bool flag = false;
for(unsigned long long i = 1;i<MAX;i++){
  if((a*i)%b == c){
      flag = true;break;
}
}
if(flag){
 cout<<"YES"<<endl;
}else{
 cout<<"NO"<<endl;
}
return 0;
}

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

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

long lcm(long a, long b){
  //return a*b/gcd(a, b); オーバーフロー
  return a/gcd(a, b)*b;
}

int main() {
  int N;
  cin>>N;
  vector<long> t(N);
  for(int j=0;j<N;j++){
    cin>>t[j];
  }
 long p=t[0];

 for(int i=1;i<N;i++){

   p= lcm(p,t[i]);
  //  cout<<p<<endl;
 }

 cout<<p<<endl;

}


Measured memory_bytes: 256
-- Drawing Lots
import Control.Monad
import Data.List.Split

main :: IO ()
main = do
  w <- readLn
  n <- readLn
  ss <- replicateM n getLine
  putStr $ solve ss w

solve :: [String] -> Int -> String
solve ss = unlines . map show . swapM (map toTuple ss) . amida

swapM :: [(Int, Int)] -> [Int] -> [Int]
swapM ls xs = foldl swap xs ls

swap :: [Int] -> (Int, Int) -> [Int]
swap xs (i,j) = [swap' a b | (a,b) <- zip [1..length xs] xs]
  where
    swap' a b | a == i = xs !! (j - 1)
              | a == j = xs !! (i - 1)
              | otherwise = b

amida :: Int -> [Int]
amida = \w -> [1..w]

toTuple :: String -> (Int, Int)
toTuple xs = (a,b)
  where
    [a,b] = map read . splitOn "," $ xs

Measured memory_bytes: 4104
#include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define LP(i, a, n) for(int i = a; i < n; i++)
#define lpp(i, n) for(int i = 0; i < n; i++)
using namespace std;
int cnt;
void is(int A[], int n, int g) {
  LP(i, g, n) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}
int main() {
  int m = 10;
  int d = 0;
  int G[] = {29524, 9841, 3280, 1093, 364, 121, 40, 13, 4, 1};
  int n;
  cin >> n;
  for(; G[d] > n; d++);
  
  int A[1000000];
  lp(n)
    cin >> A[i];
  lp(m-d) is(A, n, G[i+d]);
  cout << m-d << endl;
  lp(m-d) cout << G[i+d] << ((i == m-d-1)? "\n" : " ");
  cout << cnt << endl;
  lp(n) cout << A[i] << endl;
  return 0;
}



Measured memory_bytes: 6992
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
	int N, M;
	while(scanf("%d %d\n", &N, &M), N || M){
		vector<int> v(N), w(M);
		for(int i = 0; i < N; i++) scanf("%d\n", &v[i]);
		for(int i = 0; i < M; i++) scanf("%d\n", &w[i]);
		for(int i = 0, p = 0; i < M; i++){
			if((p += w[i]) >= N){ printf("%d\n", i + 1); break; }
			p += v[p];
			if(p >= (N - 1)){ printf("%d\n", i + 1); break; }
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
R,C,K = map(int,input().split())
lis = [[0] * (C+1) for i in range(R+1)]
for _ in range(K):
    r,c,v = map(int,input().split())
    lis[r][c] = v

dp = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)]
#print(dp)
for i in range(1,R+1):
    for j in range(1,C+1):
        for k in range(4):
            dp[0][i][j] = max(dp[0][i][j],dp[k][i-1][j])
            dp[1][i][j] = max(dp[1][i][j],dp[k][i-1][j] + lis[i][j])

            dp[k][i][j] = max(dp[k][i][j],dp[k][i][j-1])
            if k > 0:
                dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j])
# print(dp[0])
# print(dp[1])
# print(dp[2])
# print(dp[3])
print(max(dp[0][R][C],dp[1][R][C],dp[2][R][C],dp[3][R][C]))


Measured memory_bytes: 429292
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int n, m;
    cin >> n;
    m = n;
    int x, y;
    cin >> x >> y;
    vector<vector<P>> to(n);
    rep(i,m-1) {
        to[i].emplace_back(1, i+1);
        to[i+1].emplace_back(1, i);
    }
    to[x-1].emplace_back(1,y-1);
    to[y-1].emplace_back(1,x-1);
    
    vector<int> ans(n);
    rep(i,n) {
        // スタート
        int sn = i;
        // スタートからiまでの最小コスト
        vector<int> dp(n, INF);
        dp[sn] = 0;
        // 次に見るノードとこれまでの累計コストを入れる（昇順）
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.emplace(0, sn);
        P c;
        while (!pq.empty()) {
            // 累計コストが最も小さいノードに移動
            c = pq.top();
            pq.pop();
            // もし現在のノードのコストが古いもので
            // すでにほかの経路で更新済みだったら次のノードへ移動
            if (dp[c.second] < c.first) continue;
            // 隣接ノードを見る
            for (auto n: to[c.second]) {
                // 最小コストが更新できるか確認
                if (dp[n.second] > dp[c.second] + n.first) {
                    dp[n.second] = dp[c.second] + n.first;
                    // 更新出来たら次に見るノードの候補に入れる
                    pq.emplace(dp[n.second], n.second);
                }
            }
        }
        rep(i,n) {
            if (sn == i) ans[dp[i]] += 2;
            ans[dp[i]]++;
        }
    }
    rep(i,n-1) cout << (ans[i+1] / 2) << endl;
    
    return 0;
}

Measured memory_bytes: 384
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Pair = Tuple!(long, "number", long, "times");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n, m;
    scan(n, m);
    auto dif = abs(n - m);
    if(dif == 1)
    {
        auto set = product_mod(min(n, m));
        set *= set;
        set %= bignum;
        set *= max(n, m);
        set %= bignum;
        set.writeln();
    }
    else if(dif == 0)
    {
        auto set = product_mod(n);
        set *= set;
        set %= bignum;
        set *= 2;
        set %= bignum;
        set.writeln();
    }
    else
        writeln(0);
}

long product_mod(long n)
{
    if(n == 1)
        return 1;

    return n * product_mod(n - 1) % bignum;
}

Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll n;
	cin>>n;
	vector<vector<ll>> a(n,vector<ll> (n)),cnt(n,vector<ll> (n,0));
	for(ll i=0;i<n;i++)
		for(ll j=0;j<n;j++)
			cin>>a[i][j],cnt[i][j]=0;
	
	for (ll i=0;i<n;i++)
    	for (ll j=0;j<n;j++)
    		for (ll k=0;k<n;k++)
    		{
    			if (i!=j and j!=k and i!=k) 
    			    if(a[i][k]+a[k][j]<a[i][j])
    			    {
    					cout<<-1;
    					return;
    			    }
    		}
    
    for (ll i=0;i<n;i++)
    	for (ll j=0;j<n;j++)
    		for (ll k=0;k<n;k++)
    		{
    			if (i!=j and j!=k and i!=k) 
    			    if(a[i][k]+a[k][j]==a[i][j])
    					cnt[i][j]=1;
    		}
    ll ans=0;
    for (ll i=0;i<n;i++)
    	for (ll j=i+1;j<n;j++)
    		if(cnt[i][j]==0)
    			ans+=a[i][j];
    cout<<ans;
    		
    
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 4768
#include <iostream>
#include<math.h>

using namespace std;

int couent = 0;
int keisann(int a) {
	if (a == 2) { couent++; }
	if (a % 2 == 0) { return 0; }
	int v = sqrt(a);
	for (int i = 3; i <= v; i+=2)
	{
		if (a%i == 0) {
			return 0;
		}
	}
	couent++;
}
int main()
{
	int dataset;
	cin >> dataset;
	for (size_t i = 0; i < dataset; i++)
	{
		int a;
		cin >> a;
		keisann(a);
	}
	cout << couent << endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_((i), __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Wed Mar 11 19:04:22 JST 2020
 **/

signed main() {
    string s;
    cin >> s;
    deque<char> dq;
    for (char c : s) dq.push_back(c);
    Int Q;
    cin >> Q;
    bool rev = false;
    REP(q, Q) {
        Int t;
        cin >> t;
        if (t == 1) {
            rev = !rev;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (!rev && f == 1 || rev && f == 2) {
                dq.push_front(c);
            } else {
                dq.push_back(c);
            }
        }
    }
    if (rev) reverse(dq.begin(), dq.end());
    for (char c : dq) cout << c;
    cout << endl;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e18+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}




int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    vector<ll>v(3);
    for(int i=0;i<3;i++)cin>>v[i];
    sort(v.begin(),v.end());
    if(v[0]==v[1] && v[0]!=v[2])cout<<"Yes"<<endl;
    else if(v[0]!=v[1] && v[1]==v[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
    }


Measured memory_bytes: 256
//AnkitCode99 here....
#include<bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)
using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
	fast;

	string s;
	cin>>s;
	if(s[2]==s[3] and s[4]==s[5])
		cout<<"Yes\n";
	else
		cout<<"No";
}
//Goodbye...

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

public class Main {
	public static void main(String[] args) throws IOException {
		int mod = (int) 1E9 + 7;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();

		// dp[r] = ある文字までを13で割った余りがrであるものの個数
		long dp[] = new long[13];

		// 初期値
		if ( s[0] == '?' ) {
			for ( int n = 0; n < 10; n++ ) {
				dp[n] = 1;
			}
		} else {
			dp[s[0] - '0'] = 1;
		}

		for ( int i = 1; i < s.length; i++ ) {
			
			// 前回の余りrごとに見て今回のtempを埋める
			long[] temp = new long[13];			
			for ( int r = 0; r < 13; r++ ) {
				
				if ( s[i] != '?' ) {
					int now = s[i] - '0';
					temp[(r * 10 + now) % 13] += dp[r];
				}
				else {
					for ( int now = 0; now < 10; now++ ) {
						temp[(r * 10 + now) % 13] += dp[r];
					}
				}
			}
			
			for ( int r = 0; r < 13; r++ ) {
				dp[r] = temp[r] % mod;
			}
		}
		System.out.println(dp[5]);
		br.close();
	}
}


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

int main() {
  int N,R;
  cin >> N>>R;
  int naibu;
 if(N>=10){
   naibu=R;
 }
 else{
   naibu=R+100*(10-N);
 }
  cout << naibu << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }


using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int r, c, k; cin >> r >> c >> k;
    vector<vector<ll>> mo(r,vector<ll>(c,0ll));
    rep(i,k){
        ll a, b, d; cin >> a >> b >> d;
        mo[a-1][b-1] = d;
    }
    vector<vector<vector<ll>>> dp(r,vector<vector<ll>>(c,vector<ll>(4,0ll)));
    if(mo[0][0]) dp[0][0][1] = mo[0][0];
    rep(i,r) rep(j,c){
        if(i) rep(k,4) {
            if(mo[i][j]) chmax(dp[i][j][1], dp[i-1][j][k] + mo[i][j]);
            chmax(dp[i][j][0], dp[i-1][j][k]);
        }
        if(j) rep(k,4) {
            if(mo[i][j]) { if(k < 3) chmax(dp[i][j][k+1], dp[i][j-1][k] + mo[i][j]); }
            chmax(dp[i][j][k], dp[i][j-1][k]);
        }
    }
    ll ans = 0;
    rep(i,4) chmax(ans,dp[r-1][c-1][i]);
    cout << ans << endl;
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
    int n,m; scanf("%d%d",&n,&m);
    string s; cin>>s;
    int idx=n; vector<int> ans;
    while(idx){
        int lb=max(idx-m,0);
        while(s[lb]=='1'){
            lb++;
            if(lb==idx){printf("-1\n"); return 0;}
        }
        ans.push_back(idx-lb); idx=lb;
    }
    reverse(ALL(ans));
    rep(i,0,ans.size())printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 1144
fn main() {
    let _stdin: String = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };
    let n: f32 = _stdin.parse().unwrap();
    if n % 2. == 0.0 {
        println!("{}", 1. - (n / 2. / n));
    } else {
        println!("{}", 1. - ((n - 1.) / 2. / n));
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define check printf("asd\n")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	if( 2*k>=(b-a+1) ) {
		for( int i=a; i<=b; i++ ) {
			pfd(i);
			pfn;
		}
	}else {
		for( int i=0, j=a; i<k; i++, j++ ) {
			pfd(j);
			pfn;
		}
		for( int i=0, j=b-k+1; i<k; i++, j++ ) {
			pfd(j);
			pfn;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		if(!sc.hasNext())return false;
		n = sc.nextInt();
		return true;
	}
	
	static void solve(){
		double v = Math.log(n)/Math.log(2);
		double vv = Math.log(3)/Math.log(2);
		System.out.println((int)Math.ceil(v/vv));
	}

}

Measured memory_bytes: 12000
#if 1

#include <bits/stdc++.h>
using namespace std;
int n,m,cnt,ans,sum;
pair <string,pair <int,int> > a[105];

bool cmp(pair <string,pair <int,int> > x,pair <string,pair <int,int> > y)
{
    if(x.first == y.first) return x.second.first > y.second.first;
    return x.first < y.first;
}

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i].first >> a[i].second.first;
        a[i].second.second = i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i = 1;i <= n;i++)
    {
        cout << a[i].second.second << '\n';
    }
}

#endif // 1++

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

int main (){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a+b==0) printf("0\n");
	else{
		if(((a+b)/2)*2==a+b) printf("%d\n",(a+b)/2);
		else printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	int n, r;

	cin>>n>>r;

	if (n >= 10) {
		cout << r;
	} else {
		cout << r + 100 * (10 - n);
	}
	return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m, q := nextInt(), nextInt(), nextInt()
	rail := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		rail[i] = make([]int, n+1)
	}
	for i := 0; i < m; i++ {
		l, r := nextInt(), nextInt()
		rail[l][r]++
	}
	for i := 1; i <= n; i++ {
		for j := i; j <= n; j++ {
			rail[i][j] += rail[i][j-1]
		}
	}

	for i := 0; i < q; i++ {
		p, q := nextInt(), nextInt()
		ans := 0
		for j := p; j <= q; j++ {
			ans += rail[j][q]
		}
		puts(ans)
	}
}


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

#define rep(i, a, n) for(int i=(a);i<(n);++i)
#define per(i, a, n) for(int i=(a);i>(n);--i)
#define pb emplace_back
#define mp make_pair
#define lowbit(x) (x & -x)

typedef long long LL;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 2e5 + 10;

int n, K, a[N];

bool ok(int x){
	int num = K;
	int r;
	rep(i, 0, n){
		if(a[i] % x == 0){
			r = a[i] / x - 1;
		} else {
			r = a[i] / x;
		}
		if(num < r)	return 0;
		num -= r;
	}
	return 1;
}

int main(){
	scanf("%d %d", &n, &K);
	int low = 1, top = 0;
	rep(i, 0, n){
		scanf("%d", a+i);
		top = max(top, a[i]);
	}
	int mid, ans = top;
	while(low <= top){
		mid = low + top >> 1;
		if(ok(mid)){
			ans = min(ans, mid);
			top = mid - 1;
		} else {
			low = mid + 1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

int main()
{
    long long n,i,a;
    cin>>n;
    pair<int,int>arr[n+10];
    for(i=0; i<n; i++)
    {
        cin>>a;
        arr[i].first=a;
        arr[i].second=i+1;
    }
    sort(arr,arr+n);
    for(i=0; i<n; i++)
    {
        cout<<arr[i].second<<" ";
    }
}


Measured memory_bytes: 1536
N = int(input())
city = [int(x) for x in input().split()]
hero = [int(y) for y in input().split()]
monster = 0  # 倒せるモンスターの数
for i in range(N):
    if hero[i] > city[i]:
        hero[i] -= city[i]
        monster += city[i]
        city[i] = 0
        if hero[i] > city[i + 1]:
            monster += city[i+1]
            city[i + 1] = 0
        else:
            city[i + 1] -= hero[i]
            monster += hero[i]
    else:
        monster += hero[i]


print(monster)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return [f = std::forward<F>(f)](auto&&... args) {
    return f(f, std::forward<decltype(args)>(args)...);
  };
}

int main() {
  const i64 N = [](){ i64 n; cin >> n; return n; }();
  if(__builtin_popcount(N) == 1) {
    cout << "No" << endl;
    return 0;
  }
  
  cout << "Yes" << endl;

  const auto ans = [N](){
    vector<pair<i64, i64>> vec;
    auto dsh = [N](const i64 i) { return i + N; };
    i64 i = 2;
    vec.push_back({1, 2});
    for(;i + 1 <= N;i += 2) {
      vec.push_back({i, i + 1});
      vec.push_back({i + 1, dsh(1)});
      vec.push_back({dsh(1), dsh(i)});
      vec.push_back({dsh(i), dsh(i + 1)});
    }
    if(i == N) {
      const i64 a = i - 2;
      const i64 b = i ^ a ^ 1;
      vec.push_back({i, dsh(a)});
      vec.push_back({dsh(i), b});
    }
    return std::move(vec);
  }();

  for(auto&& p: ans) {
    cout << p.first << " " << p.second << endl;
  }
}


Measured memory_bytes: 6252
#include <bits/stdc++.h>
#define inf 10000000000LL
#define ll long long
#define pr pair<ll,ll>
using namespace std;

ll dp[100005];
ll arr[100005];

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    for(ll x=0; x<n; x++){
        cin>>arr[x];
        dp[x]=inf;
    }
    dp[0]=0;
    for(ll x=0; x<n; x++){
        
        for(ll y=x+1, i=0; i<m && y<n; i++,y++){
            dp[y]=min(abs(arr[y]-arr[x]) + dp[x], dp[y]);
            //cout<<y<<" ";
        }
        //cout<<dp[x]<<endl;
    }
    cout<<dp[n-1];
    return 0;
    
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    long double ans = 0;
    rep(i,n){
        double a;
        string b;
        cin >> a >> b;
        if(b == "JPY")ans += a;
        else ans += a * 380000.0;
    }
    cout << shosu(10) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define All(a) a.begin(), a.end()
int main(){
    int N;
    cin >> N;
    set<long long> s;
    for(int i = 0; i < N; i++){
        long long a;
        cin >> a;
        if(s.count(a)){
            cout << "NO" << endl;
            return 0;
        }
        s.insert(a);
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 9600
/**
 * 0000：QQの解答
 * 
 * @author MS14A
 * @version 2015/06/21
 */
public class Main {

    /**
     * 九九を出力して終了する 但し、×記号の代わりに、小文字の x を使用する
     * 
     * @param args
     */
    public static void main(String[] args) {

        // 段数ごとに九九を出力
        for (int lineNumber = 1; lineNumber <= 9; ++lineNumber) {
            printMultiplicationTable(lineNumber);
        }
    }

    /**
     * 段数を受け取り、その段の九九を出力する。
     * 
     * @param lineNumber
     *            段数
     */
    private static void printMultiplicationTable(int lineNumber) {
        for (int rowNumber = 1; rowNumber <= 9; ++rowNumber) {
            System.out.println(String.valueOf(lineNumber) + "x"
                    + String.valueOf(rowNumber) + "="
                    + lineNumber * rowNumber);
        }
    }

}

Measured memory_bytes: 17056
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  
  string str1, str2;
  int ans = 0;
  cin >> str1 >> str2;
  for(int i=0;i<str1.size();i++){
    if(str1[i]==str2[i]){
      ans++;
    }
  }  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n")
  E = input[0]
  O = input[1]
  var result = ""
  for(var i=0; i < E.length; i++) {
    result += E[i]
    if(i < O.length ) result += O[i]
  }
  console.log(result)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[100005][4];


int main(){
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i, n) {
        if (s[i]=='A') {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1] + dp[i][0];
            dp[i+1][2] = dp[i][2];
            dp[i+1][3] = dp[i][3];
        }
        if (s[i]=='B') {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
            dp[i+1][2] = dp[i][2] + dp[i][1];
            dp[i+1][3] = dp[i][3];
        }
        if (s[i]=='C') {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
            dp[i+1][2] = dp[i][2];
            dp[i+1][3] = dp[i][3] + dp[i][2];
        }
        if (s[i]=='?') {
            dp[i+1][0] = dp[i][0]*3LL;
            dp[i+1][1] = dp[i][1]*3LL + dp[i][0];
            dp[i+1][2] = dp[i][2]*3LL + dp[i][1];
            dp[i+1][3] = dp[i][3]*3LL + dp[i][2];
        }
    }
    mint ans = dp[n][3];
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
//Problem C
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,a[N],mx[2],cnt[2],sec[2],cs[2],ans,c[2][N];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        ++c[i&1][a[i]];
    }
    for(int k=0;k<2;k++)for(int i=1;i<=100000;i++)if(c[k][i]){
        if(c[k][i]>mx[k])sec[k]=mx[k],mx[k]=c[k][i],cnt[k]=i,cs[k]=1;
        else if(c[k][i]==mx[k])++cs[k];
        else if(c[k][i]>sec[k])sec[k]=c[k][i];
    }
    if(cnt[0]==cnt[1]&&cs[0]==1&&cs[1]==1)ans=max(mx[0]+sec[1],mx[1]+sec[0]);else ans=mx[0]+mx[1];
    printf("%d",n-ans);
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*v+(j))

const int m=10000;
int flow(int source,int sink,int *g,int v){
  int used[100];
  int dp[100];
  int i;
  for(i=0;i<v;i++){
    used[i]=0;
    dp[i]=0;
  }
  dp[source]=m;
  int a[100];
  int len=0;
  while(dp[sink]==0){
    int max=0;
    int maxIndex=-1;
    for(i=0;i<v;i++){
      if(!used[i] && dp[i]>max){
	max=dp[i];
	maxIndex=i;
      }
    }
    if(max==0) return 0;
    used[maxIndex]=1;
    a[len++]=maxIndex;
    for(i=0;i<v;i++){
      dp[i]=MAX(dp[i],MIN(dp[maxIndex],g[POS(maxIndex,i)]));
    }
  }
  int f=dp[sink];
  int now=sink;
  for(i=len-1;now!=source;i--){
    int u=a[i];
    if(g[POS(u,now)]>=f){
      g[POS(u,now)]-=f;
      g[POS(now,u)]+=f;
      now=u;
    }
  }
  return f;
}

void run(void){
  int v,e;
  scanf("%d%d",&v,&e);
  int g[10000];
  int i;
  for(i=0;i<v*v;i++) g[i]=0;
  for(i=0;i<e;i++){
    int s,t,c;
    scanf("%d%d%d",&s,&t,&c);
    g[POS(s,t)]=c;
  }

  int sum=0;
  int f;
  while(f=flow(0,v-1,g,v),f>0) sum+=f;
  printf("%d\n",sum);
  return;
}

int main(void){
  run();
  return 0;
}



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

using namespace std;

int main(){
    int N;

    cin >> N;

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

    int f = 0;
    int cnt = 0;
    while(f == 0){
        for(int i = 0; i < N; i++){
            if(a[i]%2 == 0){
                a[i] /= 2;
                f == 0;
            }
            else {
                f = 1;
            }
        }
        if( f == 1 ) break;
        else cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize "trapv"
#warning "Running on trapv"
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int>inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int>inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int>inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int>inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 118;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

struct SG {
	vector<ll> T;
	int n;
	SG(int n) {
		this->n = n;
		T.assign(2*n, 0);
	}

	void update(int p, ll v) {
		for(p += n; p > 0; p>>=1) T[p] = max(T[p], v);
	}

	ll get(int l, int r) {
		ll ret = 0;
		for(l += n, r += n + 1; l < r; l>>=1, r>>=1) {
			if(l & 1) ret = max(ret, T[l++]);
			if(r & 1) ret = max(ret, T[--r]);
		}
		return ret;
	}
};

void solve() {
	int n;
	cin >> n;
	vector<int> A(n), H(n);
    vector<ll> dp(n + 1);
	REP(n) cin >> H[i];
	REP(n) cin >> A[i];
	ll ans = 0;
	SG sg(n + 1);
	for(int i = 1; i <= n; i++) {
		dp[i] = sg.get(1, H[i - 1] - 1) + A[i - 1];
		sg.update(H[i - 1], dp[i]);
		ans = max(ans, dp[i]);
	}
	cout << ans << "\n";
}

signed main() {
	clock_t start = clock();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	cerr << (double)(clock() - start)/CLOCKS_PER_SEC << "\n";
	return 0;
}


Measured memory_bytes: 9608
W, H, N = map(int, input().split())
sx, sy, gx, gy = 0, 0, W, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max(sx, x)
    elif a == 2:
        gx = min(gx, x)
    elif a == 3:
        sy = max(sy, y)
    else:
        gy = min(gy, y)

dx, dy = gx-sx, gy-sy
if dx <= 0 or dy <= 0:
    print(0)
else:
    print(dx*dy)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(" ").map(String::toInt)
    val lines = Array<String>(h) {readLine()!!}
    val result = lines.joinToString(separator = "\n",
            prefix = "#".repeat(w + 2) + "\n",
            postfix = "\n" + "#".repeat(w + 2)) { line -> "#" + line + "#" }

    println(result)
}

Measured memory_bytes: 38028