akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int N;
int A[210]; // 最大 200 個なので余裕を持って 210 に --- 200 以上ならなんでもよいです

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;

    // 操作が行える限り操作を繰り返す
    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  // 奇数があったらフラグを立てる
        }

        if (exist_odd) break;  // 奇数があったら break

        // 操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;  // 操作回数をインクリメント
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    int N, M; readf("%s %s\n", &N, &M);
    auto G = new int[][N];
    foreach (i; 0 .. M) {
        int a, b; readf("%d %d\n", &a, &b);
        a--; b--;
        G[a] ~= b;
        G[b] ~= a;
    }
    int Q; readf("%s\n", &Q);
    auto V = new int[Q];
    auto D = new int[Q];
    auto C = new int[Q];
    foreach (q; 0 .. Q) {
        readf("%s %s %s\n", &V[q], &D[q], &C[q]);
        V[q]--;
    }
    reverse(V); reverse(D); reverse(C);

    auto color = new int[N]; color[] = -1;
    auto max_d = new int[N]; max_d[] = -1;
    void f(int v, int d, int c) {
        if (color[v] < 0) {
            color[v] = c;
        }
        if (max_d[v] >= d) {
            return;
        }
        max_d[v] = d;
        if (d == 0) return;
        foreach (u; G[v]) {
            f(u, d - 1, c);
        }
    }
    foreach (q; 0 .. Q) {
        f(V[q], D[q], C[q]);
    }

    foreach (v; 0 .. N) {
        writeln(max(0, color[v]));
    }
}


Measured memory_bytes: 8060
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
    int flag=0;
    for(long long i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            flag=1;
            break;
        }
    }
    if(n==1)
	   return false;
    else if(flag==0 || n==2 ||n==3)
    {
        return true;
    }
    else
    {
        return false;
    }

}

int binaryExponentiation(int x,int n)//function to calculate x raise to power n
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(0);
   #ifndef ONLINE_JUDGE
    if(fopen("input.txt","r"))
    {
    freopen ("input.txt" , "r" , stdin);
    freopen ("output.txt" , "w" , stdout);
    }
   #endif
    //_______________________________-code starts-______________________________________________________________________________

string s;
cin>>s;

	if(s[2]==s[3]&&s[4]==s[5])

	{
		cout<<"Yes"<<en;
	}
  else
  {
  	cout<<"No"<<en;
  }


  return 0;
}


Measured memory_bytes: 256
from sys import exit
# a = [int(input()) for _ in range(N)]
S = str(input())
L = len(S)
# T = str(input())
# exit()
st0 = 0
st1 = 0
pari = True
for i in range(L):
    if(S[i] == "0" and i%2 == 0):#1,3,5
        st1+=1
    elif(S[i] == "1" and i%2 == 0):
        st0+=1
    elif(S[i] == "0" and i%2 == 1):#0,2,4
        st0+=1
    elif(S[i] == "1" and i%2 == 1):
        st1+=1
# print(st0,st1)
print(min(st0,st1))


Measured memory_bytes: 3188
s = input()

n = len(s)
ans = [1]*len(s)

for i in range(n-1):
    if s[i] == 'R' and s[i+1] == 'R':
        ans[i+2] += ans[i]
        ans[i] = 0

for i in range(n-1, 0, -1):
    if s[i] == 'L' and s[i-1] == 'L':
        ans[i-2] += ans[i]
        ans[i] = 0
        
L=[str(a) for a in ans]
L=" ".join(L)
print(L)

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

typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<": ";REP(i,v.size())cout<<" "<<v[i];cout<<endl

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

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))


//===


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

	int nr = 0, nb = 0;
	for (const auto& c : S) {
		if (c == 'R') ++nr;
		else ++nb;
	}

	cout << (nr > nb ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pblist[10001]={0};
void makeList(int x)
{
	for(int i=2;i<x;i++)
	{
		int j=i;
		while((j*=i)<=x)
		  pblist[j]=1; 
	}
} 

int main()
{
	int a;
	cin>>a;
	makeList(a);
	bool flag=false;
	for(int i=a;i>=1;i--)
	{
		if(pblist[i])
		{
			cout<<i<<endl;
			flag=true;
			break;
	    }
	}
	if(!flag)
	  cout<<1<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();

		if (c * 2 < a + b) {
			int z = Math.min(x, y);
			if (x == y) {
				System.out.println(c * 2 * z);
			} else if (x > y) {
				if (c * 2 < a) {
					z = x;
					System.out.println(c * 2 * z);
				} else {
					System.out.println(c * 2 * z + a * (x - z));
				}
			} else {
				if (c * 2 < b) {
					z = y;
					System.out.println(c * 2 * z);
				} else {
					System.out.println(c * 2 * z + b * (y - z));
				}
			}
		} else {
			System.out.println(a * x + b * y);
		}
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int a;
	double x;
	cin >> a >> x;
	int b = round(100.0 * x);
	int ans = a * b;
	ans /= 100;
	cout << ans;

	return 0;
}

Measured memory_bytes: 3796
#include <iostream>

int main(void)
{
    int N;
    std::cin >> N;

    switch(N%10)
    {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            std::cout << "hon" << std::endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            std::cout << "pon" << std::endl;
            break;
        case 3:
            std::cout << "bon" << std::endl;
            break;
        default:
            break;
    }

    return 0;
}

Measured memory_bytes: 3592
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/26/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N,K; cin>>N>>K;
  vector<int> H(N); for (auto&h : H) cin>>h;
  sort(H.begin(), H.end());
  int ans = H[K-1]-H[0];
  for (int i = 1; i+K-1 < N; i++) {
    int d = H[i+K-1]-H[i];
    ans = min(ans, d);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
long long cost[200000];
long long memo[200000];
int initMemo(){
    for(int i = 0; i < 200000; i++){
        memo[i] = -1;
    }
    memo[0] = 0;
    memo[1] = abs(cost[1] - cost[0]);
    return 0;
}
long long getCost(int id,int K){
    if(memo[id] != -1){
        return memo[id];
    }
    int m = max(id - K,0);
    long long tmp = getCost(m, K) + abs(cost[m] - cost[id]);
    for(int i = m; i < id; i++){
        tmp = min(tmp,getCost(i, K) + abs(cost[i] - cost[id]));
    }
    memo[id] = tmp;
    return tmp;
}
int main() {
    int N, K;
    cin >> N >> K;

    for(int i = 0; i < N; i++){
        cin >> cost[i];
    }
    initMemo();
    cout << getCost(N - 1, K) << endl;

    return 0;
}


Measured memory_bytes: 8832
from collections import deque

d = deque()
n = list(map(int, input().split()))
time = 0

for i in range(int(n[0])):
    p = input().split()
    p[1] = int(p[1])
    if p[1] <= n[1]:
        time += p[1]
        print(p[0], end=" ")
        print(time)
    else:
        p[1] -= n[1]
        time += n[1]
        d.append(p)

while len(d) != 0:
    pnew = d.popleft()
    if pnew[1] <= n[1]:
        time += pnew[1]
        print(pnew[0], end=" ")
        print(time)

    else:
        pnew[1] -= n[1]
        time += n[1]
        d.append(pnew)



Measured memory_bytes: 9944
from collections import deque



def main():
    n, m = map(int, input().split())
    graph = [[] for i in range(n)]
    for _ in range(m):
        l, r, d = map(int, input().split())
        graph[l - 1] += [(r - 1, d)]
        graph[r - 1] += [(l - 1, -d)]


    que = deque()
    lines = [None] * n


    for i in range(n):
        if lines[i] is not None:
            continue
        lines[i] = 0
        que.append(i)
        while que:
            cur = que.popleft()
            for nxt, cost in graph[cur]:
                if lines[nxt] is None:
                    lines[nxt] = lines[cur] + cost
                    que.append(nxt)
                else:
                    if lines[nxt] != lines[cur] + cost:
                        return 'No'
    return 'Yes'



print(main())

Measured memory_bytes: 83744
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        char[][] a = new char[h][w];
        for (int i = 0; i < h; i++) {
            a[i] = sc.next().toCharArray();
        }
        sc.close();

        // 主処理
        int[][] count = new int[h][w];

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (i == 0 && j == 0) {
                    count[i][j] = a[i][j] == '#' ? 1 : 0;
                } else if (i == 0) {
                    int left = (a[i][j] == '.' || a[i][j] == '#' && a[i][j - 1] == '#') ? count[i][j - 1]
                            : count[i][j - 1] + 1;
                    count[i][j] = left;
                } else if (j == 0) {
                    int up = (a[i][j] == '.' || a[i][j] == '#' && a[i - 1][j] == '#') ? count[i - 1][j]
                            : count[i - 1][j] + 1;
                    count[i][j] = up;
                } else {
                    int left = (a[i][j] == '.' || a[i][j] == '#' && a[i][j - 1] == '#') ? count[i][j - 1]
                            : count[i][j - 1] + 1;
                    int up = (a[i][j] == '.' || a[i][j] == '#' && a[i - 1][j] == '#') ? count[i - 1][j]
                            : count[i - 1][j] + 1;
                    count[i][j] += Math.min(up, left);
                }
            }
        }
        int result = count[h - 1][w - 1];

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 37372
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

vector<ll> s, t;
int A, B, Q;
ll INF = 100000000000;
ll ans = INF;

int main() {
    cin >> A >> B >> Q;
    s.push_back(-INF);
    rep(i, A) {
        ll input;
        scanf("%lld", &input);
        s.push_back(input);
    }
    s.push_back(INF);

    t.push_back(-INF);
    rep(i, B) {
        ll input;
        scanf("%lld", &input);
        t.push_back(input);
    }
    t.push_back(INF);

    rep(i, Q) {
        ll x;
        scanf("%lld", &x);
        int b = upper_bound(s.begin(), s.end(), x) - s.begin();
        int d = upper_bound(t.begin(), t.end(), x) - t.begin();
        for (int i = b-1; i <= b; i++)
            for (int j = d-1; j <= d; j++)
                ans = min(ans, min(abs(s[i] - x), abs(t[j] - x)) + abs(s[i] - t[j]));
        cout << ans << endl;
        ans = INF;
    }
}

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
long long int map[1010][1010] = {0};
long long int maps[1010][1010] = {0};
long long int num[1010][1010] = {0};
long long int cnt[1010][1010] = {0};
bool flag[1100010] = {};
int main() {

  vector< long long int > sosu;
  for ( long long int i = 2; i <= 1100000; i++ ) {
    if ( flag[i] == false ) {
      sosu.push_back( i );
      for ( long long int j = 1; j * i <= 1100000; j++ ) {
	flag[j*i] = true;
      }
    }
  }

  vector< long long int > mx, my;
  mx.push_back( 0 );
  my.push_back( 0 );
  long long int x = 505;
  long long int y = 505;
  long long int lm = 1;
  long long int l = lm;
  bool lf = false;
  long long int d = 0;
  int dx[4] = {  1,  0, -1,  0 };
  int dy[4] = {  0, -1,  0,  1 };
  long long int s = 0;
  for ( long long int i = 1; i <= 1000000; i++ ) {
    if ( i == sosu[s] ) {
      maps[x][y] = 1;
      s++;
    }
    map[x][y] = i;
    mx.push_back( x );
    my.push_back( y );
    x += dx[d];
    y += dy[d];
    l--;
    if ( l == 0 ) {
      if ( lf == false ) {
	lf = true;
      }else {
	lf = false;
	lm++;
      }
      l = lm;
      d = ( d + 1 ) % 4;
    }
  }

  long long int m, n;
  while( true ) {

    cin >> m >> n;
    if ( m == 0 ) break;

    x = 0;
    y = 1008;
    while( true ) {
      cnt[x][y] = 0;
      num[x][y] = 0;
      if ( map[x][y] > 0 && map[x][y] <= m ) {
	if ( maps[x][y] == 1 ) {
	  cnt[x][y]++;
	  num[x][y] = map[x][y];
	}
	d = -1;
	if ( cnt[x-1][y+1] < cnt[x][y+1] ) d = 0;
	if ( cnt[x-1][y+1] == cnt[x][y+1] && num[x-1][y+1] < num[x][y+1] ) d = 0;
	if ( cnt[x+d][y+1] < cnt[x+1][y+1] ) d = 1;
	if ( cnt[x+d][y+1] == cnt[x+1][y+1] && num[x+d][y+1] < num[x+1][y+1] ) d = 1;
	if ( cnt[x+d][y+1] > 0 ) {
	  cnt[x][y] += cnt[x+d][y+1];
	  num[x][y] = num[x+d][y+1];
	}
      }
      x++;
      if ( x == 1010 ) {
	x = 0;
	y--;
	if ( y == 0 ) break;
      }
    }
    cout << cnt[mx[n]][my[n]] << " " << num[mx[n]][my[n]] << endl;

  }

  return 0;

}

Measured memory_bytes: 50480
#include <stdio.h>
int main()
{
  int N, M;
  int H[100000];
  int buk[100000];
  int i;
  int counter = 0;
  int a, b;
  for(i = 0; i < 100000; ++i)
    buk[i] = 0;
  scanf("%d %d", &N, &M);
  for(i = 0; i < N; ++i)
    scanf("%d", &H[i]);
  
  for(i = 0; i < M; ++i){
    scanf("%d %d", &a, &b);
    if(H[a-1] > H[b-1])
      ++buk[b-1];
    else if(H[a-1] < H[b-1])
      ++buk[a-1];
    else{
      ++buk[a-1];
      ++buk[b-1];
    }
  }
  for(i = 0; i < N; ++i){
    if(buk[i] == 0)
      ++counter;
  }
  printf("%d\n", counter);
  return 0;
}

Measured memory_bytes: 2516
#include<iostream>
#include<queue>
using namespace std;
int main() {
    int n, q;
    cin >> n >> q;
    queue<int> Q[n];
    for (int i = 0; i < q; i++) {
        int num, t; //manipulate Qt
        cin >> num >> t;
        if (num == 0) { //enqueue
            int x;
            cin >> x;
            Q[t].push(x);
        } else if (num == 1) { //front
            if (!Q[t].empty()) {
                cout << Q[t].front() << endl;
            }
        } else if (num == 2) { //dequeue
            if (!Q[t].empty()) {
                Q[t].pop();
            }
        }
    }
}



Measured memory_bytes: 4380
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    int k, a, b;
    cin >> k >> a >> b;
    int t = 0;
    bool flag = false;
    while (t <= b)
    {
        t += k;
        if (t >= a && t <= b)
        {
            flag = true;
            break;
        }
    }
    if (flag)
        cout << "OK\n";
    else
        cout << "NG\n";
    return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, h, w; cin >> n >> h >> w;
  V<> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += a[i] >= h and b[i] >= w;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n,i;
int main()
{
	fast;
	cin>>n>>i;
	cout<<n+1-i<<endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> vp(n);
  rep(i, n) cin >> vp[i].first >> vp[i].second;
  sort(vp.begin(), vp.end());

  int honsu = 0;
  ll okane = 0;

  for (int i = 0; i < n && honsu < m; ++i) {
    for (int j = vp[i].second; j > 0 && honsu < m; --j) {
      vp[i].second--;
      honsu++;
      okane += vp[i].first;
    }
  }

  cout << okane << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[M];
        int[] B = new int[M];
        for (int i = 0; i < M; ++i) {
            A[i] = sc.nextInt() - 1;
            B[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(N, A, B));

        sc.close();
    }

    static String solve(int N, int[] A, int[] B) {
        int[] parents = new int[N];
        Arrays.fill(parents, -1);

        int[] sizes = new int[N];
        Arrays.fill(sizes, 1);

        long[] result = new long[A.length];
        long pairNum = N * (N - 1L) / 2;
        for (int i = result.length - 1; i >= 0; --i) {
            result[i] = pairNum;

            int rootA = findRoot(parents, A[i]);
            int rootB = findRoot(parents, B[i]);
            if (rootA != rootB) {
                pairNum -= (long) sizes[rootA] * sizes[rootB];

                parents[rootB] = rootA;
                sizes[rootA] += sizes[rootB];
            }
        }

        return Arrays.stream(result).mapToObj(String::valueOf).collect(Collectors.joining("\n"));
    }

    static int findRoot(int[] parents, int node) {
        int root = node;
        while (parents[root] != -1) {
            root = parents[root];
        }

        int p = node;
        while (p != root) {
            int next = parents[p];
            parents[p] = root;

            p = next;
        }

        return root;
    }
}

Measured memory_bytes: 65208
n = []
x = []
while(True):
    N,X = map(int,input().split())
    if N ==0 and X == 0:
        break
    else:
        n.append(N)
        x.append(X)
for l in range(len(n)):
    sum = []
    for i in range(1,n[l]+1):
        for j in range(1,n[l]+1):
            for k in range(1,n[l]+1):
                if i==j or j==k or i==k:break
                sum.append(i+j+k)
    print(int(sum.count(x[l])/2))


Measured memory_bytes: 8352
#include<iostream>
#include<vector>
#include<algorithm>
#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

using namespace std;

struct Item{
    int value, weight;
};

int N, W;
Item items[NMAX + 1];
int C[NMAX + 1][WMAX + 1], G[NMAX + 1][WMAX +1];

void compute(int &maxValue, vector<int> &selection){
    for(int w=0; w<=W; w++){
        C[0][w] = 0;
        G[0][w] = DIAGONAL;
    }

    for(int i=1; i<=N; i++) C[i][0] = 0;

    for(int i=1; i<=N; i++){
        for(int w=1; w<=W; w++){
            C[i][w] = C[i-1][w];
            G[i][w] = TOP;
            if(items[i].weight > w) continue;
            if(items[i].value + C[i-1][w-items[i].weight] > C[i-1][w]){
                C[i][w] = items[i].value + C[i-1][w-items[i].weight];
                G[i][w] = DIAGONAL;
            }
        }
    }

    maxValue = C[N][W];
    selection.clear();
    for(int i=N, w=W; i>=1; i--){
        if(G[i][w] == DIAGONAL){
            selection.push_back(i);
            w -= items[i].weight;
        }
    }

    reverse(selection.begin(), selection.end());
}

void input(){
    cin >> N >> W;
    for(int i=1; i<=N; i++){
        cin >> items[i].value >> items[i].weight;
    }
}

int main(){
    int maxValue;
    vector<int> selection;
    input();
    compute(maxValue, selection);

    cout << maxValue << endl;

    return 0;
}


Measured memory_bytes: 11068
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,q;
  cin >> n;
  map<int, int> cnt;
  ll tot = 0;
  rep(i, n){
    int a;
    cin >> a;
    cnt[a]++;
    tot += a;
  }
  cin >> q;
  rep(i, q){
    int a,b;
    cin >> a >> b;
    int num = cnt[a];
    cnt[a] = 0; cnt[b] += num;
    tot += b * num - a * num;
    cout << tot << endl;
  }
}

Measured memory_bytes: 7928
# あ
read_line = input().split()
route_count = int(read_line[0])
permit_time = int(read_line[1])

route_info = {}
min_cost = 9999
for i in range(route_count) :
	read_line = input().split()
	cost = int(read_line[0])
	time = int(read_line[1])
	if (time > permit_time) :
		continue
		
	if (min_cost > cost) :
		min_cost = cost

if (min_cost != 9999) :
	print(min_cost)
else :
	print("TLE")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll PS(ll n,ll d) {
  
  if(n==-1) {
    return 0;
  }
  else {
    return n/d+1;
  }
}
  
  
  
int main() {
  ll a;
  ll b;
  ll x;
  cin >>a>>b>>x;
  
  cout<<PS(b,x)-PS(a-1,x)<<endl;
}
 
  


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

using namespace std;

#define INF 1e9
typedef long long ll;
typedef vector<ll> Vec;
 
struct State{
  Vec v;
  int sp,cost;
  State(Vec v,int sp,int cost)
    : v(v),sp(sp),cost(cost) {}
  bool operator < (const State &s)const{
    return cost > s.cost;
  }
};

int ch,cv;
const int d[4] = {-1,1,-3,3};

ll getVal(Vec &v){
  ll res = 0LL;
  for(auto &x : v){
    res *= 9;
    res += x;
  }
  return res;
}

int dijkstra(Vec &st,ll target,int sp){
  priority_queue<State> Q;
  Q.push(State(st,sp,0));
  unordered_map<ll,int> mp;
  mp[getVal(st)] = 0;

  while(!Q.empty()){
    State s = Q.top(); Q.pop();
    ll val = getVal(s.v);
    if(mp.find(val) != mp.end() && mp[val] < s.cost){
      continue;
    }
    if(val == target){ return mp[val]; }
    for(int i = 0 ; i < 4 ; i++){
      int nsp = (s.sp + d[i] + 9) % 9;
      int cost = (i < 2 ? ch : cv);
      swap(s.v[nsp],s.v[s.sp]);
      ll nval = getVal(s.v);
      if(mp.find(nval) == mp.end() ||
         mp[val] + cost < mp[nval]){
        mp[nval] = mp[val] + cost;
        Q.push(State(s.v,nsp,mp[nval]));
      }
      swap(s.v[nsp],s.v[s.sp]);
    }
  }
  return INF;
}

int main(){
  while(cin >> ch >> cv, (ch|cv)){
    int sp;
    Vec s(9),t(9);
    for(int i = 0 ; i < 9 ; i++){
      cin >> s[i];
      if(s[i] == 0){ sp = i; }
    }
    for(int i = 0 ; i < 9 ; i++){
      cin >> t[i];
    }
    cout << dijkstra(s,getVal(t),sp) << endl;
  }
  return 0;
}

Measured memory_bytes: 33420
N, K = map(int,input().split())
H = list(map(int,input().split()))

#DP[i] i番目までの足場を見たときの足場iにたどり着く最小値

DP = [10**12 for _ in range(N + 1)] 
DP[0] = 0
for i in range(N):
    for k in range(1,K + 1):
        if 0 <= i - k and i - k < N:
            cost_min = 10**12
            cost_min = min(cost_min, DP[i - k] +  abs(H[i] - H[i - k]))
            DP[i] = min(DP[i],cost_min)
print(DP[N - 1])



Measured memory_bytes: 56032
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

typedef pair<int,int> pii;

const pii inf=make_pair(-1e7,1e7);
const pii fail=make_pair(1e7,-1e7);

vector<pii> range;
vector<int> edge[100000];
bool visited[100000];

pii dfs(int v){
	if(visited[v])	return inf;
	visited[v]=true;
	for(int i=0;i<edge[v].size();i++){
		int to=edge[v][i];
		pii result=dfs(edge[v][i]);
		if(result==make_pair(inf.first-1,inf.second+1))	result=inf;
		if(result==fail)	return fail;
		else if(range[v]==inf)	range[v]=result;
		else if(result==inf)	continue;
		else if(range[v].first%2!=result.first%2)	return fail;
		else if(range[v].second<result.first)	return fail;
		else if(result.second<range[v].first)	return fail;
		else{
			range[v].second=min(range[v].second,result.second);
			range[v].first=max(range[v].first,result.first);
		}
	}
	if(range[v].second<range[v].first)	return fail;
	return make_pair(range[v].first-1,range[v].second+1);
}

void decide(int v){
	if(visited[v])	return;
	visited[v]=true;
	range[v]=make_pair(range[v].first,range[v].first);
	for(int i=0;i<edge[v].size();i++){
		int to=edge[v][i];
		if(visited[to])	continue;
		range[to]=make_pair(max(range[to].first,range[v].first-1),
							min(range[to].second,range[v].second+1));
		decide(to);
	}
	return;
}
	
int main(){
	int n;	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;	cin>>a>>b;	a--;	b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	for(int i=0;i<n;i++)	visited[i]=false;
	range=vector<pii>(n,inf);
	int k;	cin>>k;
	for(int i=0;i<k;i++){
		int v,p;	cin>>v>>p;	v--;
		range[v]=make_pair(p,p);
	}
	pii ret=dfs(0);
	if(ret==fail){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<n;i++)	visited[i]=false;
	decide(0);
	for(int i=0;i<n;i++)	cout<<range[i].first<<endl;
	return 0;
}
	


Measured memory_bytes: 13568
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int V1, V2;
int size[1002];
int to[1002][1002];
int dist[1002];
int match[1002];
const int NIL = 1001;
bool BFS(){
  queue<int> que;
  REP(v, V1){
    if(match[v] == NIL){
      dist[v] = 0;
      que.push(v);
    }else{
      dist[v] = INF;
    }
  }
  dist[NIL] = INF;
  while(!que.empty()){
    int v = que.front(); que.pop();
    if(dist[v] < dist[NIL]){
      for(int i = 0; i < size[v]; i++){
        int u = to[v][i];
        if(dist[match[u]] == INF){
          dist[match[u]] = dist[v] + 1;
          que.push(match[u]);
        }
      }
    }
  }
  return dist[NIL] != INF;
}

bool DFS(int v){
  if(v != NIL){
    for(int i = 0; i < size[v]; i++){
      int u = to[v][i];
      if(dist[match[u]] == dist[v] + 1 && DFS(match[u])){
        match[u] = v;
        match[v] = u;
        return true;
      }
    }
    dist[v] = INF;
    return false;
  }
  return true;
}

int Hopcroft_Karp(){
  REP(v, V1 + V2) match[v] = NIL;
  int matching = 0;
  while(BFS()){
    REP(v, V1){
      if(match[v] == NIL && DFS(v)){
        matching ++;
      }
    }
  }
  return matching;
}
int gcd(int x, int y){
  int r = x % y;
  if(r == 0) return y;
  return gcd(y, r);
}
int main(){
  while(scanf("%d %d", &V1, &V2) && (V1 != 0 || V2 != 0)){
    REP(i, V1) size[i] = 0;
    static int blue[500];
    static int red[500];
    REP(i, V1) scanf("%d", blue + i);
    REP(i, V2) scanf("%d", red + i);
    REP(u, V1) REP(v, V2){
      if(gcd(blue[u], red[v]) != 1) {
        to[u][size[u]++] = V1 + v;
        //G[u].push_back(V1 + v);
        //G[V1 + v].push_back(u);
      }
    }
    printf("%d\n", Hopcroft_Karp());
  }
  return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    char s[4];
    char t[4];
    scanf("%s%s", s, t);
    
    int cnt = 0;
    if (s[0] == t[0]) {
        cnt += 1;
    }
    if (s[1] == t[1]) {
        cnt += 1;
    }
    if (s[2] == t[2]) {
        cnt += 1;
    }

    printf("%d", cnt);

    return 0;


}


Measured memory_bytes: 128
<?php
fscanf(STDIN, "%d %d", $a, $b);

function euclid($x, $y) {
  if ($x == $y) {
    $result = $x;
  } else {
    $c = abs($x - $y);
    if ($x > $y) {
      $result = euclid($y, $c);
    } elseif ($y > $x) {
      $result = euclid($x, $c);
    }
  }
  return $result;
}

echo $a*$b/euclid($a, $b);

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

using namespace std;
#define REP(i, n) for(int i=0; i < (int)(n); ++i)
#define REPR(i, n) for(int i=n; i>= 0; --i)
#define FOR(i, m, n) for(int i=m; i<(n); ++i)

using ll = long long;

int main(){
    string S, T;
    cin >> S >> T;
    int ans = 0;
    REP(i, 3){
        if(S[i] == T[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll N, K, Q;
    ll A[100000];
    cin >> N >> K >> Q;
    for(int i = 0; i < Q; i++) cin >> A[i];
    vector<ll> point(N);
    for(int i = 0; i < N; i++) point[i] = 0;
    for(int i = 0; i < Q; i++) point[A[i] - 1]++;
    for(int i = 0; i < N; i++) {
        if(Q - point[i] < K) {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <unordered_map>

using namespace std;

int main(){
    int N;
    int p[20];
    cin >> N;
    for(int i=0; i<N; i++){
        cin>>p[i];
    }
    int answer=0;
    for(int i=1; i<N-1; i++){
        if((p[i]>=p[i-1] and p[i]<=p[i+1]) or (p[i]<=p[i-1] and p[i]>=p[i+1]))
            answer++;
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = true;

int main(){

    ll n, m, d;
    cin >> n >> m >> d;

    long double ans = 1.0;
    //dの値により場合分け
    if(d == 0){
        ans = 1.0 * (m-1) * (1.0 / n) ;
    }
    else{
        ans = 1.0 * ( 1.0 * (n - d) / n ) * (1.0 / n) * 2 * (m-1);
    }

    cout << setprecision(10) << ans << endl;
}

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

using namespace std;

typedef long long ll;

template<class V, int NV> struct SegTree {
	V comp(V& l, V& r) { return max(l, r); }

	vector<V> val;
	SegTree() {
		val = vector<V>(NV * 2, 0);
	}
	V get(int x, int y, int l = 0, int r = NV, int k = 1) {
		if (r <= x || y <= l) {
			return 0;
		}
		if (x <= l && r <= y) {
			return val[k];
		}
		auto a = get(x, y, l, (l + r) / 2, k * 2);
		auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
		return comp(a, b); 
	}

	void update(int i, V v) {
		i += NV;
		val[i] = v;
		while (i > 1) {
			i >>= 1;
			val[i] = comp(val[i * 2], val[i * 2 + 1]);
		}
	}
	void add(int i, V v) {
		update(i, val[i + NV] + v);
	}
	V operator[](int x) {
		return get(x, x + 1);
	}
};

SegTree<ll, 1 << 18> dp;
int main(int argc, char *argv[])
{
	int N;
	int a[200005], h[200005];

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

	for (int i = 0; i < N; i++) {
		ll opt = dp.get(0, h[i]) + a[i];
		dp.update(h[i], max(dp[h[i]], opt));
	}

	cout << dp.get(0, 1 << 18) << endl;

	return 0;
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#define endl '\n'
using namespace std;
int main()
{
    int a,b,cnt=0;
    cin >> a >> b;
    while(a<=b)
    {
        if(to_string(a).at(0)==to_string(a).at(4))
            if(to_string(a).at(1)==to_string(a).at(3))cnt++;
        a++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>
#include<float.h>

int main(void){
  int k,n;
  double xa,ya,ra,xb,yb,rb;
  double d[4];
  scanf("%d",&n);
  int ans[n];

  for(k=1;k<=n;k++){
    scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
    d[0] = sqrt(pow(xb-xa,2.0) + pow(yb-ya,2.0));
    d[1] = ra + rb;
    d[2] = ra - rb; //B???A???????????????
    d[3] = rb - ra; //A???B???????????????

    if(d[0] > d[1]){
      ans[k-1] = 0;
    }else if(d[2]>d[0]){
      ans[k-1] = 2;
    }else if(d[3]>d[0]){
      ans[k-1] = -2;
    }else{
      ans[k-1] = 1;
    }
  }
  for(k=1;k<=n;k++){
    printf("%d\n",ans[k-1]);
  }
  return 0;
}

Measured memory_bytes: 640
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let ans = sc.chars();
    let len = ans.len();
    println!("{}{}{}", ans[0], len-2, ans[len-1]);
}

// Thanks, kenkoooo(https://kenkoooo.hatenablog.com/entry/2019/05/07/101033)
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <queue>
#include <cmath>
#include <unordered_map>

using namespace std;

#define endl '\n'

int main() {	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;

	int ans = n;
	if (n % 2) {
		ans *= 2;
	}
	cout << ans;
}

Measured memory_bytes: 256
import sys
from typing import List, Optional

sys.setrecursionlimit(1000000)

N, M = map(int, input().split())

g = [[] for _ in range(N)]

for i in range(M):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    g[l].append((r, d))
    g[r].append((l, -d))


def ok(cur: int, ds: int, dists: List[Optional[int]]) -> bool:
    dists[cur] = ds

    flag = True
    for nx, d in g[cur]:
        if dists[nx] != None:
            flag &= dists[nx] - dists[cur] == d
        elif flag:
            flag &= ok(nx, ds + d, dists)

    return flag


dists = [None] * N
ans = True
for i in range(N):
    if ans and dists[i] == None:
        ans &= ok(i, 0, dists)

print("Yes" if ans else "No")


Measured memory_bytes: 135132
#include<stdio.h>
#define N 10000
#define M -1

struct Node {int i,j,k;};
struct Node T[N];
int a;

void sum(int b)
{
    if(b==M)return;
    printf(" %d",b);
    sum(T[b].j);
    sum(T[b].k);
}
void num(int c)
{
    if(c==M)return;
    num(T[c].j);
    printf(" %d",c);
    num(T[c].k);
}

void tum(int d)
{
    if(d==M)return;
    tum(T[d].j);
    tum(T[d].k);
    printf(" %d",d);
}

int main()
{
    int i,v,l,r,xu;
    scanf("%d",&a);
    for(i=0;i<a;i++)
    {
        T[i].i=M;
        
    }
    for(i=0;i<a;i++)
    {
        scanf("%d %d %d",&v,&l,&r);
        T[v].j=l;
        T[v].k=r;
        if(l!=M)T[l].i=v;
        if(r!=M)T[r].i=v;
    }
    for(i=0;i<a;i++)if(T[i].i==M)xu=i;
    
    printf("Preorder\n");
    sum(xu);
    printf("\n");
    printf("Inorder\n");
    num(xu);
    printf("\n");
    printf("Postorder\n");
    tum(xu);
    printf("\n");
    
    return 0;
}



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

#include <iostream>


#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;
auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};

int main()
{
	f();
	int n,m;cin>>n>>m;
	vector<int> arr(n+1,0);
	int s=0;
	while(s<m)
	{
		int b,e;cin>>b>>e;
		arr[b-1]+=1;
		arr[e]-=1;
		++s;
	}
	
	int ans=0;
	if(arr[0]==m)ans++;
	for(size_t i=1;i<=n;++i){
		arr[i]+=arr[i-1];
		if(arr[i]==m)ans++;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

struct Node {
	int left;
	int right;
};

Node T[100];
int PreOrder[100], InOrder[100];
int NumOfNode;



void printPost(int node) {
	if (node == -1) {
		;
	}
	else {
		printPost(T[node].left);
		printPost(T[node].right);
		if (NumOfNode-- != 1) {
			printf("%d ", node);
		}
		else {
			printf("%d\n", node);
		}
	}
}



void makeTree(int PreBegin, int PreEnd, int InBegin, int InEnd) {
	int root = PreOrder[PreBegin];
	int PreLeftSubtreeBegin, PreLeftSubtreeEnd, PreRightSubtreeBegin, PreRightSubtreeEnd, InLeftSubtreeBegin, InLeftSubtreeEnd, InRightSubtreeBegin, InRightSubtreeEnd;
	for (int i = InBegin; i <= InEnd; ++i) {
		if (InOrder[i] == root) {
			PreLeftSubtreeBegin = PreBegin + 1;
			PreLeftSubtreeEnd = PreBegin + i - InBegin;
			PreRightSubtreeBegin = PreLeftSubtreeEnd + 1;
			PreRightSubtreeEnd = PreEnd;
			InLeftSubtreeBegin = InBegin;
			InLeftSubtreeEnd = i - 1;
			InRightSubtreeBegin = i + 1;
			InRightSubtreeEnd = InEnd;
			break;
		}
	}
	if (PreLeftSubtreeBegin > PreLeftSubtreeEnd) {
		//the left subtree is empty
		T[root].left = -1;
	}
	else {
		//the left subtree is not empty
		T[root].left = PreOrder[PreLeftSubtreeBegin];
		makeTree(PreLeftSubtreeBegin, PreLeftSubtreeEnd, InLeftSubtreeBegin, InLeftSubtreeEnd);
	}

	if (PreRightSubtreeBegin > PreRightSubtreeEnd) {
		//the right subtree is empty
		T[root].right = -1;
	}
	else {
		//the right subtree is not empty
		T[root].right = PreOrder[PreRightSubtreeBegin];
		makeTree(PreRightSubtreeBegin, PreRightSubtreeEnd, InRightSubtreeBegin, InRightSubtreeEnd);
	}
}

int main() {
	int n;
	scanf("%d", &n);
	NumOfNode = n;

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

	makeTree(0, n - 1, 0, n - 1);
	printPost(PreOrder[0]);

	return 0;
}

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

string S;
string s;
map<string, int> mp;
string buff;
int cnt;

void rec(int index)
{
    // 最後まで走査したら
    if (index >= S.length())
    {
        return;
    }

    s += S[index];

    if (mp[s] == 0)
    {
        mp[s]++;
        cnt++;
        if (buff == "") { buff = s; }
        else
        {
            mp[buff] = 0;
            buff = s;
        }
        s = "";
    }

    rec(index + 1);
}


int main()
{
    buff = "";
    cnt = 0;
    cin >> S;

    rec(0);

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, a, b)    for(int i = (a); i <= (int)(b); ++i)
#define per(i, a, b)    for(int i = (a); i >= (int)(b); --i)
#define debug(x)    cerr << #x << ' ' << x << endl;
using namespace std;
 
typedef long long ll;
const int MAXN = 2e5 + 7;

int main() {
    int k, x;
    cin >> k >> x;
    rep(i, x-k+1, k+x-1){
        cout << i << ' ';
    }
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    int h,w;
    cin >> h >> w;

    int cnt = 0;

    while(n--)
    {
        int x,y;
        cin >> x >> y;

        if(x >= h && y >= w)
            cnt++;
    }

    cout << cnt << endl;

}

Measured memory_bytes: 256
v, e = map(int,input().split())
par = [i for i in range(v+1)]

def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y

for i in range(e):
  a, b = map(int, input().split())
  unite(a, b)
  
cnt = 0
for i in range(v+1):
  if i == par[i]:
    cnt += 1

print(cnt-2)

Measured memory_bytes: 13004
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int W,H;
    cin>>W>>H;
  	if(W==1||H==1)cout<<1<<endl;
  else{
    if(W*H%2==0) cout<<W*H/2<<endl;
    else cout<<W*H/2+1<<endl;
  }
}


Measured memory_bytes: 256
s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
d = 1
r = 0
for i in reversed(range(0, N)):
    r = ( r + int( s[i] ) * d ) % 2019
    d = d * 10 % 2019
    array[r] += 1
for i in array:
    count += i*(i-1)/2
print(int(count))


Measured memory_bytes: 9304
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long ll;

#define N 100010
#define M 200010
#define INF 1000000000
#define LLINF 2000000000000000000LL

struct UF{
  vector<int> data;
  vector<int> child[N];
  vector<int> used;
  vector<int> size;

  UF(int n){
    data.assign(n+1,-1);
    size.assign(n+1,1);
    used.assign(n+1,0);
    used[0] = true;
  }

  void set(int x,int y){
    if(used[y]) return;
    // x -> y
    child[x].push_back(y);

    if(used[x]){
      used[y] = true;
      size[0]++;
      for(int i=0;i<child[y].size();i++){
	set(0,child[y][i]);
      }
    }
  }
};

int n,m,q;
int u[M],v[M],r[M];
int ans;

vector<pair<int,int> > way[N];
int dist[N];

bool used[M] = {};
int need[M] = {};
bool connect[N] = {};

int main(){
  
  scanf("%d%d%d",&n,&m,&q);

  for(int i=0;i<m;i++){
    scanf("%d%d",u+i,v+i);
    u[i]--;
    v[i]--;

    way[v[i]].push_back({u[i],i});
    way[u[i]].push_back({v[i],i});
  }

  for(int i=0;i<q;i++){
    scanf("%d",r+i);
    r[i]--;

    used[r[i]] = true;
  }

  //dijkstra
  queue<pair<int,int> > q1;

  for(int i=0;i<n;i++) dist[i] = INF;
  q1.push({0,-1});

  for(int i=0;q1.size();i++){
    queue<pair<int,int> > q2;

    while(q1.size()){
      int now = q1.front().first;
      int id = q1.front().second;
      q1.pop();
      
      if(dist[now]>=i && dist[now]!=-1){
	if(u[id]==now) need[id] = 1;
	else need[id] = 2;
      }

      if(dist[now]<=i) continue;
      dist[now] = i;

      for(int j=0;j<way[now].size();j++){
	q2.push({way[now][j].first,way[now][j].second});
      }
    }
    q1 = q2;
  }

  UF uf(n);

  for(int i=0;i<m;i++){
    if(used[i]==false && need[i]){
      if(need[i]==1){
	uf.set(v[i],u[i]);
      }
      if(need[i]==2) uf.set(u[i],v[i]);
    }
  }

  int vec[M] = {};

  for(int i=q-1;i>=0;i--){
    vec[i] = n - uf.size[0];
    
    if(need[r[i]]==1){
      uf.set(v[r[i]],u[r[i]]);
    }
    if(need[r[i]]==2){
      uf.set(u[r[i]],v[r[i]]);
    }
  }

  for(int i=0;i<q;i++){
    printf("%d\n",vec[i]);
  }

  return 0;
}

Measured memory_bytes: 22056
N=int(input())
L=list(map(int, input().split()))
L=sorted(L)
import bisect

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        a=L[i]
        b=L[j]
        upper = bisect.bisect_left(L,a+b)
        lower=max(j+1, bisect.bisect_right(L, a-b), bisect.bisect_right(L, b-a))
        #print(upper, lower)
        ans+=max(0, upper-lower)


print(ans)

Measured memory_bytes: 75512
from networkx import *

n,m = map(int, input().split())
G = Graph()

for i in range(m):
    a,b = map(int, input().split())
    G.add_edges_from([(a, b)])

m3 = list(connected_components(G))

count = 0

if len(max(connected_components(G), key=len)) == n:
    print(0)
    exit()
else:
    for i in m3:
        count += len(i)

sub = n - count

if sub != 0:
    print((len(m3)-1)+sub)

else:
    print(len(m3)+sub-1)




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

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

    int even,odd;
    for (int i = 1; i <= k; i++) {
        if (i % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }
    cout << even * odd << endl;
}


Measured memory_bytes: 256