akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int N=1e5+10;

char ch[N];
int a[N<<1],b[N],vis[N];
int f[N<<1][26];

int main() {
	scanf("%s",ch+1);
	int n=strlen(ch+1);
	for(int i=1;i<=n;i++) a[i]=ch[i]-'a';
	for(int i=1;i<=n;i++) a[i+n]=a[i];
	scanf("%s",ch+1);
	int m=strlen(ch+1);
	for(int i=1;i<=m;i++) b[i]=ch[i]-'a';
	for(int i=1;i<=n;i++) vis[a[i]]=1;
	int flag=0;
	for(int i=1;i<=m;i++) if(!vis[b[i]]) flag=1;
	if(flag) {
		puts("-1");
		return 0;
	}
	for(int i=2*n;i;i--) {
		for(int j=0;j<26;j++) f[i][j]=f[i+1][j];
		f[i][a[i]]=i;
	}
	int cnt=0,now=0;
	for(int i=1;i<=m;i++) {
		now++;
		while(now>n) cnt++,now-=n;
		now=f[now][b[i]];
	}
	cout<<1ll*cnt*n+now<<endl;
}

Measured memory_bytes: 22016
#include <iostream>
#include <cmath>

using namespace std;

int n, v[100100], h[100100];

int main()
{
    cin >> n;
    for(int i=1; i<=n; i++) cin >> h[i];
    v[2] = abs(h[2] - h[1]);
    for(int i=3; i<=n; i++) v[i] = min(v[i-1] + abs(h[i] - h[i-1]), v[i-2] + abs(h[i] - h[i-2]));
    cout << v[n] << '\n';
    return 0;
}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    const int n = 50;
    ll k;
    cin >> k;
    vector<ll> a(n);
    rep(i, n) {
        a[i] = k/n;
    }
    k %= n;
    rep(i, n) {
        if(i < k) {
            a[i] += n;
        } else {
            a[i] += n-1-k;
        }
    }

    cout << n << endl;
    rep(i, n) {
        cout << a[i] << (i == n-1?'\n':' ');
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long a, long long b)
{
    ll height = 0;
    for (int i = 0; i < b - a; i++)
    {
        height += i;
    }
    cout << height - a << endl;
}

int main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
n = int(input())
#n, m, k = map(int, sys.stdin.readline().split())
#s = input()
#A = list(map(int, sys.stdin.readline().split()))

l = [0, 0, 0, 0]

for i in range(n):
    s = input()
    if s == "AC":
        l[0] += 1
    elif s == "WA":
        l[1] += 1
    elif s == "TLE":
        l[2] += 1
    else:
        l[3] += 1


print("AC x" ,l[0])
print("WA x" ,l[1])
print("TLE x" ,l[2])
print("RE x" ,l[3])






Measured memory_bytes: 10024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll mod = 1e9 + 7;


int main(){
	int a,b;
	cin>>a>>b;
	if(a > 0 && a < 10 && b < 10 && b > 0){
		cout<<a*b<<endl;
	}else{
		cout<<-1<<endl;
	}



	return 0;
}

//abc




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  sort(vec.begin(),vec.end());
  cout<<vec[n-1]-vec[0]<<endl;
}
  


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int i=0,j=0,count=0;
	char * string[] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
	char str[3];
	char * p = str;
	gets(str);
	for(i=0;i<7;i++)
	{
		if((strcmp(p,string[i])==0))
		{
				count = 6-i;
				if(strcmp(p,string[6])==0)
				{
					count = 7;
				}
		}
	}
	printf("%d",count);
	return 0;
}


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


using pint = std::pair<int, int>;
int N;
std::vector<std::vector<pint> > v;

bool check(int bit){
    for (int i = 0; i < N; ++i) {
        if (!(bit & (1 << i))) continue;

        for (pint xy: v[i]) {
            int x = xy.first;
            int y = xy.second;

            if (y == 1 && !(bit & (1 << x))) return false;
            if (y == 0 && (bit & (1 <<x))) return false;
        }
    }

    return true;
}

int main(){
    std::cin >> N;
    v.resize(N);
    for(int i = 0; i < N; ++i){
        int shougen;
        std::cin >> shougen;
        v[i].resize(shougen);
        for(int j = 0; j < shougen; ++j) {
            std::cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first;
        }
    }

    int honest = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        if (check(bit)) {
            int tmp_honest = 0;
            for (int i = 0; i < N; ++i) if (bit & (1 << i)) ++tmp_honest;
            honest = std::max(honest, tmp_honest);
        }
    }

    std::cout << honest << std::endl;
}


Measured memory_bytes: 256
// PrintAChessboard.c
// 以下のような、たてH cm よこ W cm のチェック柄の長方形を描くプログラムを作成して下さい。
//
//   #.#.#.#.#.
//   .#.#.#.#.#
//   #.#.#.#.#.
//   .#.#.#.#.#
//   #.#.#.#.#.
//   .#.#.#.#.#
// 上図は、たて 6 cm よこ 10 cm の長方形を表しています。
// 長方形の左上が "#" となるように描いて下さい。
// 【入力】
// 入力は複数のデータセットから構成されています。各データセットの形式は以下のとおりです：
//   H W
// H, W がともに 0 のとき、入力の終わりとします。
// 【出力】
// 各データセットについて、たて H cm よこ W cm の枠を出力して下さい。
// 各データセットの後に、１つの空行を入れて下さい。
// 【制約】
// 1 ≤ H, W ≤ 300
// 【例】
// 入力：
// 3 4
// 5 6
// 3 3
// 2 2
// 1 1
// 0 0
// 出力：
// #.#.
// .#.#
// #.#.
//
// #.#.#.
// .#.#.#
// #.#.#.
// .#.#.#
// #.#.#.
// 
// #.#
// .#.
// #.#
// 
// #.
// .#
//
// #
#include<stdio.h>

int main( void) {
  int H, W;

  while ( 1) {
    scanf( "%d %d", &H, &W);

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

    for ( int h = 1; h <= H; h++ ) {
      for ( int w = 1; w <= W; w++ ) {
	if ( (h + w) % 2 == 0) printf( "#");
	else if ( (h + w) % 2 != 0) printf( ".");
      }
      printf( "\n");
    }
    printf( "\n");
  }
  return 0;
}



Measured memory_bytes: 2096
# -*- coding: utf-8 -*-
# C - Lining Up
# 標準入力の取得
N = int(input())
A_list = list(map(int, input().split()))
sorted_A_list = sorted(A_list)

# 期待されるA_listの算出
EXPECTED_LIST = []
is_N_even = (N % 2 == 0)
for n in range(N):
    is_n_even = (n % 2 == 0)
    if is_N_even:
        # Nが偶数の場合、[1, 1, 3, 3, ・・・, N-1, N-1]となる
        if is_n_even:
            EXPECTED_LIST.append(n+1)
        else:
            EXPECTED_LIST.append(n)
    else:
        # Nが奇数の場合、[0, 2, 2, 4, 4, ・・・, N-1, N-1]となる
        if is_n_even:
            EXPECTED_LIST.append(n)
        else:
            EXPECTED_LIST.append(n+1)

# 判定処理
if sorted_A_list == EXPECTED_LIST:
    # 報告が正しかった場合、並び方の総数を10^9+7で割った余りを出力
    print(2**(N//2) % (pow(10, 9)+7))
else:
    # 報告が誤りであった場合、0を出力して、処理を終了する
    print(0)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,s,c;
    cin>>n;
    c=n;
    for(i=0;i<=n;i++)
    {
        j=i;
        k=n-i;
        s=0;
        while(j)
        {
            s+=(j%6);
            j/=6;
        }
        while(k)
        {
            s+=(k%9);
            k/=9;
        }
        c=min(s,c);
    }
    cout<<c<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;

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

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

  int a[n + 1];
  for (int i = 1; i < n + 1; ++i) cin >> a[i];

  vector<int> r;
  vector<int> ord(n + 1, -1);

  int now = 1;
  while (ord[now] == -1) {
    ord[now] = r.size();
    r.push_back(now);
    now = a[now];
  }

  int loop = r.size() - ord[now];
  int line = ord[now];

  if (k < line) {
    cout << r[k] << '\n';
  } else {
    cout << r[line + (k - line) % loop] << '\n';
  }

  return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
using namespace std;
int main() {
int K, A, B, j = 0;
cin >> K >> A >> B;
  int v = 1000 / K;
vector<int> a(v);
  for (int i = 0; i < v; i++) {
    a.at(i) = K * (i + 1);
  }
  for (int i = 0; i < v; i++) {
    if (a.at(i) >= A && a.at(i) <= B) {
      cout << "OK" << endl;
      break;
    }
    j++;
  }
    if (j == v ) {
      cout << "NG" << endl;
    }
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

    char in[120]; //120文字の列
    pair<pair<string,int>,int> p[110];
int main(){
    int a; cin >> a;
    for(int i=0;i<a;i++){
        int t;
        cin >> in >> t;
        p[i] = make_pair(make_pair(in,-t),i); //iはレストラン番号
    }
    std::sort(p,p+a); //sortは昇順だから1,2,3,... -3,-2,-1となるようにする。
    for(int i=0;i<a;i++){
        cout << p[i].second+1 <<endl; //p[i].secondはレストラン番号
    }
    
}   


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];

  ll ans = 0;
  sort(h.rbegin(), h.rend());
  rep(i, n) {
    if (k > 0) {
      k--;
    } else {
      ans += h[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

string S;
int N;

int main(){
	cin >> S;
	cin >> N;
	int res = 0;
	for(int i = 0; i < N; i++){
		string t;
		cin >> t;
		t += t;
		for(int j = 0; j < t.length() - S.length(); j++){
			if(t.substr(j, S.length()) == S){
				res++;
				break;
			}
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> A((n+1)/2);
    long ans = 1;

    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        ++A[a/2];
    }

    if (n % 2 == 1 && A[0] != 1) {
        goto ERROR;
    }
    for (int i = n % 2; i < A.size(); ++i) {
        if (A[i] != 2) {
            goto ERROR;
        }
        ans = (ans * 2) % 1000000007L;
    }
    cout << ans << endl;
    return 0;

ERROR:
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int a[50], b[50], c[50], d[50];

void Search(vector<int>&v) {
	if (v.size() == N) {
		long long int ans = 0;
		for (int i = 0; i < K; i++) {
			if (v[b[i]] - v[a[i]] == c[i])ans += d[i];
		}
		L = max(L, ans);
		return;
	}
	int st = 1;
	if (v.size())st = v.back();
	for (int i = st; i <= M; i++) {
		v.push_back(i);
		Search(v);
		v.pop_back();
	}
}

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

	cin >> N >> M >> K;
	for (int i = 0; i < K; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--, b[i]--;
	}
	vector<int>v;
	Search(v);
	cout << L << endl;
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>
#include<cassert>

using namespace std;

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
////////////////////////////

bool check(string s, char c){
	rep(i, 0, sz(s)) if(s[i] != c) return false;
	return true;
}

void solve(){
	int ans = 1e9 + 41;
	string s;
	cin >> s;
	int n = sz(s);
	rep(c, 'a', 'z' + 1){
		int pans = 0;
		string s1 = s;
		while(sz(s1) > 0 && !check(s1, c)){
			++pans;
			string ns;
			rep(i, 0, sz(s1) - 1){
				if(s1[i] == c || s1[i+1] == c) ns.pb(c);
				else ns.pb(s1[i]);
			}
			s1 = ns;
		}
		if(check(s1, c)) ans = min(ans, pans);
	}
	cout << ans << endl;

}

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

	solve();

	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define MAXN 8
int main(){
    int N;
    cin >> N;
    int x[MAXN],y[MAXN];
    rep(i,N)cin >> x[i] >> y[i];
    double dist = 0;
    int count = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j)continue;
            else{
                double dts = (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
                dist += sqrt(dts);
                count++;
            }
        }
    }
    dist /= N;
    printf("%0.8f\n",(dist));
    return 0;
}

Measured memory_bytes: 256
#include"stdio.h"
#include"string.h"
#include"algorithm"
   using namespace std;
int main()
{
    int a,b,k;
    while(~scanf("%d%d%d",&a,&b,&k))
    {
        int i;
        if(a<b)
        {
            int t=a;a=b;b=t;
        }
        int cnt=0;
        int s=b;

            for( i=b;i>=1;i--)
            {
                if(b%i==0&&a%i==0)
                    cnt++;
                if(cnt==k)
                    break;
            }

        printf("%d\n",i);

    }
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

long long ans[123456];
int N, W;
long long w, v;

int main(int argc, char *argv[])
{
  cin >> N >> W;
  std::fill(ans, ans + W, 0);
  for (int i = 0; i < N; i++) {
    cin >> w >> v;

    for (int j = W; j >= w; j--) {
      ans[j] = max(ans[j-w] + v, ans[j]);
    }
  }
  cout << ans[W] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#define ll long long
using namespace std;

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

  int X[N], maxn = 0, tmp;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    maxn = max(maxn, tmp);
    X[i] = tmp - A;
  }

  ll dp[N + 5][2 * N * maxn + 1];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 2 * N * maxn; j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][N * maxn] = 1;

  for (int i = 0; i < N; i++) {
    for (int k = 0; k <= 2 * N * maxn; k++) {
      dp[i + 1][k] = dp[i][k];
      if (0 <= k - X[i] && k - X[i] <= 2 * N * maxn)
        dp[i + 1][k] += dp[i][k - X[i]];
    }
  }

  cout << dp[N][N * maxn] - 1 << endl;
  return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#define N 100

int main()
{
  int A[N], n, i, j, k, count=0;
  
  scanf("%d",&n);
  
  for (i=0;i<n;i++){
    scanf("%d", &A[i]);
  }

  for (i=0;i<=n-1;i++){
    for (j=n-1;j>=i+1;j--){
      if (A[j]<A[j-1]){
	k=A[j]; 
	A[j]=A[j-1]; 
	A[j-1]=k;
	count++;
      }
    }
  }
  
  for (i=0;i<n;i++){
    if(i>=1) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n", count);
  
  return 0;
}

Measured memory_bytes: 604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.isEmpty()) {
                break;
            }
            int n = Integer.parseInt(line);
            int result = n * (n + 1) / 2 + 1;
            out.println(result);
        }
    }
}

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL << 60;

ll N, A[100010];

int main()
{
  cin >> N;
  for(ll i = 0; i < N; i++) cin >> A[i];
  
  sort(A, A+N);
  ll sum = A[0];
  bool check1 = false;
  bool check2 = false;
  if(sum == 0) check1 = true;
  else
  {
    for(ll i = 1; i < N; i++)
    {
      if(A[i] > 1000000000000000000/sum)
      {
        check2 = true;
        break;
      }
      else sum *= A[i];
    }
  }
  if(check1) cout << "0" << endl;
  else if(check2) cout << "-1" << endl;
  else cout << sum << endl;
}


Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
int main(){
	// #ifndef LOCAL
	// freopen("input.txt","r",stdin);
	// #endif
	ios::sync_with_stdio(false);
	cin.tie(0);


	int n;
	cin>>n;
    int x=n/500;
    int y=(n%500)/5;
    cout<<x*1000+y*5<<endl;

	return 0;
}

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

typedef long long ll;

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

int main() { 
    int K;
    string target = "ACL", ans;
    cin >> K;
    rep(i, K) {
        ans += target;
    }
    cout << ans <<"\n";
    return 0;
}


Measured memory_bytes: 3520
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a[100000],ans,c;
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	ans=a[2]-a[1];
	if((a[1]-a[0])%2==0){
		ans=ans+(a[1]-a[0])/2;
	}else{
		ans=ans+(a[1]-a[0])/2+1+1;
	}
	
	cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define nl cout<<"\n"
#define dbg(x) cout<<x<<" ";
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define UM unordered_map<int,int>
#define ULL unordered_map<ll,int>
void fun(){
    ll a,b,k;   cin>>a>>b>>k;
    fi(a,b+1){
        if(i<a+k||i>b-k)
            cout<<i<<"\n";
        else
            i=b-k;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    fun();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long

int main() {
    
    ll n;
    cin >> n;
    ll a=n/2;
    ll d[n];
    for (ll i=0;i<n;i++) cin >> d[i];
    sort(d,d+n);
    cout << d[a]-d[a-1] << endl;
   
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int n; cin >> n;
	int b1, b2, b4;
	b1 = b2 = b4 = 0;
	for (int i = 0; i < n; ++i) {
		int a; cin  >> a;
		if (a % 4  == 0) {
			b4++;
		} else if(a % 2 == 0) {
			b2++;
		} else {
			b1++;
		}
	}
	if (b2 > 0) {
		if (b1 <= b4) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	} else {
		if (b1 <= (b4 + 1)) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();


		System.out.println("A" + b.charAt(0) + "C");


		sc.close();

	}

}

Measured memory_bytes: 38532
#include<stdio.h>
long long int jou(long long int n);
int main(){
  long long int n;
  scanf("%lld",&n);
  printf("%lld\n",jou(n));
  return 0;
}

long long int jou(long long int n){
  if(n == 1 || n == 0){
    return 1;
  }
  else{
    return(n*jou(n-1));
  }
}
    
  

Measured memory_bytes: 596
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{ int p, l, r, nid;};
struct Node T[MAX];

void maketree(int id, int l, int r){
  if( l != -1 ){
    T[id].l = l;
    T[l].p = id;
  }
  if( r != -1 ){
    T[id].r = r;
    T[r].p = id;
  }
  T[id].nid = id;
}

void pre_search(int i){
  printf(" %d", i);
  if(T[i].l != -1){
    pre_search(T[i].l);
  }
  if(T[i].r != -1){
    pre_search(T[i].r);
  }
}

void in_search(int i){
  if(T[i].l != -1){
    in_search(T[i].l);
  }
  printf(" %d", T[i].nid);
  if(T[i].r != -1){
    in_search(T[i].r);
  }
}

void pos_search(int i){
  if(T[i].l != -1){    
    pos_search(T[i].l);
  }
  if(T[i].r != -1){
    pos_search(T[i].r);
  }
  printf(" %d", T[i].nid);
}

void print(){
  int i = 0;
  while(1){
    if(T[i].p == -1)
      break;
    i++;
  }
  printf("Preorder\n");
  pre_search(i);
  printf("\n");
  printf("Inorder\n");
  in_search(i);
  printf("\n");
  printf("Postorder\n");
  pos_search(i);
  printf("\n");
}

int main(){
  int n, l, r, id;
  int i;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    T[i].r = T[i].l = T[i].p = NIL;
  }
  for(i=0; i<n; i++){
    scanf("%d%d%d", &id, &l, &r);
    maketree(id, l, r);
  }
  print();
  return 0;
}

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

using namespace std;
int main() {
	int n, p[99999], sum=0;
	cin>>n;
	for (int i=0; i<n; i++) cin>>p[i];
	for (int i=0; i<n; i++) {
		if (p[i]==i+1) {
			if (p[i+1]==i+2) {
				swap(p[i], p[i+1]); 
				i++;
				sum++;
			}
			else if (p[i-1]!=i+1) {
				swap(p[i], p[i-1]);
				sum++;
			}
			else {
				swap(p[i], p[i+1]);
				sum++;
			}
		}
	}
	cout << sum;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
int x,y,T,ans;
int solve1(int x,int y){
	while ((x%y) && (x>y))
		x=x-x/y-1;
	return x/y;
} 
int solve2(int x,int y){
	if (x/y>=y) return solve1(x,y); 
	int t;
	do{
		t=x/y;
		if (t>=y) return solve1(x,y);
		x=std::min(x,t*y+(-t*y%(t+1)+x%(t+1)+t+1)%(t+1));
		if (x%y==0) return x/y;
		x=x-t-1;
	}while (t);
	return 0;
}
int main(){
	scanf("%d",&T);
	while (T--){
		scanf("%d%d",&x,&y);
		//printf("%d %d\n",solve1(x,y),solve2(x,y));
		ans^=solve2(x,y);
	}
	puts(ans?"Takahashi":"Aoki");
}

Measured memory_bytes: 3688
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <functional>
#include <iterator>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end())
#define PSort(x) sort(begin(x), end(x), pairCompare)
#define ll long long
#define INF 2000000000
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
using namespace std;

int main(){
	int dp[123456 * 2 + 1] = { 0 };
	dp[1] = 1;
	dp[2] = 1;
	rep(i, 3, 123456 * 2 + 1) {
		bool f = true;
		if (i % 2 == 0)f=false;
		else {
			for (int j = 3; j <= sqrt(i);j+=2) if (i%j == 0)f = false;
		}
		if (f)dp[i] = 1;
	}

	while (1) {
		int x,ans=0;
		cin >> x;
		if (x == 0)break;
		rep(i, x + 1, 2 * x + 1)if (dp[i] == 1)ans++;
		cout << ans << endl;
	}


	

	return 0;
}

Measured memory_bytes: 4036
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
typedef long long ll;

using namespace std;

int main(void)
{
    int a, b;
    cin >> a;
    cin >> b;
    int cnt = 0;

    if ((a+b) == 3) {
        cnt = 3;
    } else if((a+b) == 4) {
        cnt = 2;
    } else if((a+b) == 5) {
        cnt = 1;
    }

    cout << cnt << endl;

    return 0;
}

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


int main()
{
    ll x;
    cin >> x;
    x--;
    bool now = true;
    ll cnt = 0;

    while (now)
    {
     
        now = false;
        x += 1;

        for (int i = 2; i < x; i++)
        {
            if (x % i == 0)
            {
                now = true;
              
            }
        
        }
    
       
    }




    cout <<  x << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(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; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

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


int main() {

	int N, K;
	cin >> N >> K;
	vector<bool> Hu(N,false);

	rep(i, K) {
		int d;
		cin >> d;
		rep(i, d) {
			int A;
			cin >> A;
			Hu[A - 1] = true;
		}
	}

	int ans = 0;
	rep(i, N) {
		if (Hu[i] == false)ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;

int k;
int count = 0;

int main()
{
	cin >> k;
	queue<string> s;
	if (k <= 10) {
		cout << k << endl;
		return 0;
	}

	int i;
	for (i = 1; i <= 9; i++) {
		s.push(to_string(i));
	}
	string now;
	int len;
	char a, b, c;
	for (i = 0; i < k; i++) {
		now = s.front();
//		cout << i << " : " << now << endl;
		s.pop();
		len = now.length();
		b = now[len - 1];
		if (b > '0') {
			a = b - 1;
			s.push(now + a);
		}
		s.push(now + b);
		if (b < '9') {
			c = b + 1;
			s.push(now + c);
		}
	}
	cout << now << endl;
	return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int x, y;
    cin >> x >> y;
    int ans=0;

    rep(i, 0, x+1){
        if(i*2+(x-i)*4==y) ans=1;
    }

    if(ans) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n,m;cin>>n>>m;
    int L=1,R=n;
    rep(i,m){
        int l,r;cin>>l>>r;
        L = max(L,l);
        R = min(R,r);
    }
    if(L>R){
        R = 1;
        L = 2;
    }
    cout << R - L + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>

std::string x;
int main(){
  std::cin>>x;
  
  std::stack<char> data;
  for(size_t i=0,end=x.size();i<end;++i){
    if(x[i]=='S')
      data.push(x[i]);
    else if(data.empty())
      data.push(x[i]);
    else if(x[i]=='T'){
      if(data.top()=='T')
        data.push(x[i]);
      else
        data.pop();
    }
  }
  
  std::cout<<data.size()<<std::endl;
  return 0;
}


Measured memory_bytes: 644
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        System.out.println(z + " " + x + " " + y);
        sc.close();
    }
}

Measured memory_bytes: 22228
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

def bfs(graph:list, node:int, start:int, k:int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF]*node
    
    # 始点ノードの距離を0とし、dfsのためのstackを作成
    dist[start] = 0
    que = deque([(0,start)])
    
    # 未探索のノードをqueueに入れる
    # kより大きいの距離のものを数える
    cnt = 0
    while que:
        cost, cur_node = que.popleft()
        
        if cost > k:
            cnt += 1
        
        
        for nex_cost, nex_node in graph[cur_node]:
            if dist[nex_node] != INF:
                continue
            else:
                dist[nex_node] = dist[cur_node] + nex_cost
                que.append((dist[nex_node], nex_node))
                
    return dist,cnt


# 入力, グラフ作成
n,k = li()
adj_list = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = li_()
    adj_list[a].append((1,b))
    adj_list[b].append((1,a))


# bfs
ans = n
if k%2 == 0:
    for st in range(n):
        _, cnt = bfs(adj_list, n, st, k//2)
        ans = min(ans, cnt)
        
else:
    for st in range(n):
        for cost, to in adj_list[st]:
            if to <= st:
                continue
            
            dist1, _ = bfs(adj_list, n, st, (k-1)//2)
            dist2, _ = bfs(adj_list, n, to, (k-1)//2)
            cnt = 0
            
            for d1, d2 in zip(dist1, dist2):
                if min(d1,d2) > (k-1)//2:
                    cnt += 1
                    
            ans = min(ans, cnt)
        
print(ans)

Measured memory_bytes: 120796
j,a['   '],s;main(i){for(;++i<998;)if(!a[i])for(j=i*i;a[j]=j<1e6;j+=i);for(i=1;++i<1e6||~scanf(s="%d\n",&j)&&printf(s,a[j]);a[i]=s+=!a[i]);}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline

n = int(input())
S = input().rstrip()
b = 0
q = 0

for s in S:
    if s == '(':
        b +=1
    else:
        if b>0:
            b -= 1
        else:
            q += 1
print('('*q+S+')'*b)


Measured memory_bytes: 9196
#include<stdio.h>
int main(){
	int i,n;
	int a[10001],b[10001],c[10001],d[10001],e[10001];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i/10000==3 || i/1000==3 || i/100==3 || i/10==3 || i%10000==3 || i%10000/1000==3 || i%10000%1000/100==3 || i%10000%1000%100/10==3 || i%10000%1000%100%10==3){
			printf(" %d",i);
		}
		else if(i%3==0)printf(" %d",i);
	}
	printf("\n");
	return 0;
}



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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int a, b;
string s;

int main() {
	cin >> a >> b >> s;
	bool ok = 1;

	rep(i, s.size()) {
		if (i == a) {
			if (s[i] != '-') {
				ok = 0;
			}
		} else {
			if (s[i] >= '0' && s[i] <= '9') {

			} else {
				ok = 0;
			}
		}
	}
	puts(ok ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  if(s.size()>=4 && s.at(0)=='Y' && s.at(1)=='A' && s.at(2)=='K' && s.at(3)=='I')
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#define ll long long
#define inf 1e18
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << #y << "=" << y << endl
#define sp(x, y) fixed << setprecision(y) << x;
#define em emplace_back
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define nl '\n'

typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

const int maxn = 1e6;
const int mod = 1e9 + 7;

void solve()
{
    ll n;
    cin >> n;
    string s;
    map<string, int> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << '\n';
    cout << "WA x " << mp["WA"] << '\n';
    cout << "TLE x " << mp["TLE"] << '\n';
    cout << "RE x " << mp["RE"] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll test = 1;
    //cin >> test;
    while (test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

char s[200005];

int main() {
    scanf("%s", s);
    int n = strlen(s);
    int countA = 0;
    ll total = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'A') ++countA;
        else {
            if (s[i] == 'B') {
                if (i + 1 < n && s[i + 1] == 'C') {
                    total += countA;
                    ++i;
                } else {
                    countA = 0;
                }
            } else {
                countA = 0;
            }
        }
    }
    printf("%lld\n", total);
    return 0;
}



Measured memory_bytes: 384
a = list(map(int,input().split()))
d = abs(a[0] - a[2])
d1 = abs(a[0] - a[1])
d2 = abs(a[1] - a[2])

if d <= a[3]:
  print("Yes")
elif d1 <= a[3] and d2 <= a[3]:
  print("Yes")
else: print("No")


Measured memory_bytes: 3060
///
// File:  a.cpp
// Author: ymiyamoto
//
// Created on Sun Dec 10 21:22:14 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string str;
  cin >> str;

  uint32_t num = 0;
  for (auto c : str) {
    if (c == '1') {
      num++;
    }
  }
  cout << num << endl;

  return 0;
}


Measured memory_bytes: 256
/* it was worth becoming a chemist */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "cardgame"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

int n;
ll a[MAXN];

int main() {	
    // #ifndef ONLINE_JUDGE
	//~ freopen(NAME".in", "r", stdin);
    //~ freopen(NAME".out", "w", stdout);
    // #endif

	cin >> n;
	int ct = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] & 1) ct++;
	}
	if (ct & 1) cout << "NO";
	else cout << "YES";
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <math.h>
#define LL long long
using namespace std;
bool judge(int x)
{
    int m=sqrt(x);
    for(int i=2;i<=m;i++)
        if(x%i==0)return false;
    return true;
}
int main()
{
    int n,k=11;
    scanf("%d",&n);
    while(n)
    {
        if(judge(k))
        {
            if(n==1)
                printf("%d\n",k);
            else
                printf("%d ",k);
            n--;
        }
        k+=10;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    ll ans = 0;

    rep(i,n){
        ll tmp = a[i];
        while(tmp %2 == 0){
            tmp /=2;
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n,i,j,k,l;
    cin>>n>>k; ll arr[n];
    for(i=1;i<=n;i++)cin>>arr[i];
    for(i=k+1;i<=n;i++)
     if(arr[i]>arr[i-k])cout<<"Yes\n";
     else cout<<"No\n";
}

Measured memory_bytes: 5216
n,m,x,y=map(int,input().split())
xx=[int(i) for i in input().split()]
yy=[int(i) for i in input().split()]
ok=False
for i in range(x+1,y+1):
    ansx=[0 if j<i else 1 for j in xx]
    ansy=[0 if j>=i else 1 for j in yy]
    if 1 not in ansx and 1 not in ansy:
        ok=True
        break
if ok:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
 
int n;
vector<vi> to;
 
vi state;
vi vs;
bool dfs(int v) {
  if (state[v]) {
    if (state[v] == 1) {
      vs.erase(vs.begin(), find(vs.begin(),vs.end(),v));
      return true;
    }
    return false;
  }
  vs.push_back(v);
  state[v] = 1;
  for (int u : to[v]) {
    if (dfs(u)) return true;
  }
  state[v] = -1;
  vs.pop_back();
  return false;
}
 
void solve() {
  vector<int> nxt(n), visited(n), erased(n,1);
  rep(i,vs.size()) {
    int v = vs[i];
    int u = vs[(i+1)%vs.size()];
    nxt[v] = u;
    erased[v] = 0;
  }
  int v = vs[0];
  while (!visited[v]) {
    for (int u : to[v]) {
      if (erased[u]) continue;
      int nv = v;
      while (nxt[nv] != u) {
        nv = nxt[nv];
        erased[nv] = 1;
      }
      nxt[v] = u;
    }
    visited[v] = 1;
    v = nxt[v];
  }
  vi ans;
  int sv = v;
  while (1) {
    ans.push_back(v);
    v = nxt[v];
    if (v == sv) break;
  }
  cout<<ans.size()<<endl;
  for (int v : ans) cout<<v+1<<endl;
}
 
int main() {
  int m;
  cin>>n>>m;
  to.resize(n);
  rep(i,m) {
    int a, b;
    cin>>a>>b;
    --a; --b;
    to[a].push_back(b);
  }
 
  state = vi(n);
  rep(i,n) if (!state[i]) {
    if (dfs(i)) {
      solve();
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cassert>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
  // Input
  int N;
  std::cin >> N;
  std::vector<std::string> S(N);
  std::vector<int> P(N);
  for (int i = 0; i < N; ++i)
    std::cin >> S[i] >> P[i];

  // Main
  std::vector<int> idx(N);
  std::iota(idx.begin(), idx.end(), 0);
  std::stable_sort(idx.begin(), idx.end(),
                   [&](int k, int l) { return P[k] > P[l]; });
  std::stable_sort(idx.begin(), idx.end(),
                   [&](int k, int l) { return S[k] < S[l]; });

  // Output
  for (int i = 0; i < N; ++i)
    std::cout << idx[i] + 1 << std::endl;

  return 0;
}


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

#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
                                           	
const int N = 5e5 + 123, M = 2e3 + 123, inf = 1e9 + 123, mod = 1e9 + 7;
const ll INF = 1e18;

int dp[N];

int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n, k;
	cin >> n >> k; 
	int a[n + 1];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[0] = 0;
	for (int i = 1; i <= k; i++) {
		bool ok = 0;
		for (int j = 1; j <= n; j++) {
			if (i >= a[j]) {
				if (dp[i - a[j]] == 0) {
					ok = 1;
					break;
				}
			} 
		}
		if (ok) {
			dp[i] = 1;
		} else {
			dp[i] = 0;
		}
	}
	if (dp[k]) {
		cout << "First";
	} else {
		cout << "Second";
	}
	return 0;   	
}                                                         

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

using namespace std;
using namespace atcoder;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	dsu d(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		d.merge(u - 1, v - 1);
	}
	printf("%d\n", (int)d.groups().size() - 1);
	return 0;
}	


Measured memory_bytes: 8996
import bisect
INF = 10 ** 9 + 7
N, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aset = set(a)
bset = set(b)
ablst = [0] * ((N * M) + 1)
a.sort(), b.sort()

if len(aset) != len(a) or len(bset) != len(b):
    print(0)
    exit()

for i in range(N):
    ablst[a[i]] += 1

for j in range(M):
    ablst[b[j]] += 1

ans = 1
for i in range(N * M, 0, -1):
    ac = bisect.bisect_left(a, i)
    bc = bisect.bisect_left(b, i)
    if ablst[i] == 2:
        ans *= 1
    elif ablst[i] == 1 and ac < N and a[ac] == i:
        ans *= (M - bc)
    elif ablst[i] == 1 and bc < M and b[bc] == i:
        ans *= (N - ac)
    else:
        acnt = bisect.bisect_left(a, i)
        bcnt = bisect.bisect_left(b, i)
        ans *= (N - ac) * (M - bc) - (N * M - i)
    ans %= INF
print(ans % INF)

Measured memory_bytes: 51560
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef unsigned long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
bool isPrime(int x) {
	int i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;
	return 1;
}vector<ll> a;
void prime(ll n) {
	ll m = n, sum = 0, k = 0;
	if (n == 1) return;
	if (n % 2 == 0) {
		while (n % 2 == 0) {
			k++;
			n /= 2;
		}
		a.push_back(k);
	}
	for (ll i = 3; i * i <= m; i += 2){
		if (n % i == 0) {
			k = 0;
			while (n % i == 0) {
				k++;
				n /= i;
			}
			a.push_back(k);
		}
	}
	if (n * n >= m) a.push_back(1);
}
int main(void) {
	ll n,sum = 0; cin >> n;
	prime(n);
	for (ll i : a) {
		ll k = 1,cnt = 1;
		for (;;) {
			if (cnt > i) {
				k--;
				break;
			}
			k++; cnt += k;
		}sum += k;
	}cout << sum << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

const ll mod = 1000000007;

template<int MOD> class Fp {
    ll val;
public:
    constexpr Fp(ll v = 0) noexcept : val(v % MOD) {
        if(val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator- () const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+ (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator- (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator* (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/ (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator+= (const Fp& r) noexcept {
        val += r.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator-= (const Fp& r) noexcept {
        val -= r.val;
        if(val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator*= (const Fp& r) noexcept {
        (val *= r.val) %= MOD;
        return *this;
    }
    constexpr Fp& operator/= (const Fp& r) noexcept {
        ll a = r.val, b = MOD, u = 1, v = 0;
        while(b){
            ll t = a/b;
            a -= t*b; swap(a, b);
            u -= t*v; swap(u, v);
        }
        (val *= u) %= MOD;
        if(val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator== (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator!= (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    constexpr bool operator> (const Fp& r) const noexcept {
        return this->val > r.val;
    }
    constexpr bool operator< (const Fp& r) const noexcept {
        return this->val < r.val;
    }
    friend constexpr ostream& operator<< (ostream &os, const Fp<MOD>& x){
        ll tmp = x.val;
        os << tmp;
        return os;
    }
    friend constexpr ostream& operator>> (istream &is, const Fp<MOD>& x){
        ll tmp;
        is >> tmp;
        x = Fp<MOD>(tmp);
        return is;
    }
    constexpr Fp<MOD> modpow(ll n) noexcept {
        if(n == 0) return 1;
        auto t = modpow(n>>1);
        t *= t;
        if(n & 1) t *= *this;
        return t;
    }
};
using mint = Fp<mod>;

int main(){
    ll n, k; cin >> n >> k;
    vector<ll>  a(n);
    vector<vector<ll>> ac(n), acn(n);
    rep(i, n) cin >> a[i];
    rep(i, n){
        for(ll j = i+1; j < n; ++j){
            if(a[i] > a[j]) ac[i].push_back(a[j]);
        }
        rep(j, n){
            if(a[i] > a[j]) acn[i].push_back(a[j]);
        }
    }
    mint s(0), d(0), dk(0);
    rep(i, n){
        s += ac[i].size();
        d += acn[i].size();
    }
    dk += k*(k-1)/2;
    mint ans(0);
    ans += s*k;
    ans += d*dk;
    //cout << s << " " << d << " " << dk << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}
int func(int n)
{
    return (n*(n+1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
  int n;
  cin>>n;
  set<int> s;
  while(n--)
  {
    int h;
    cin>>h;
    s.insert(h);
  }
  cout<<s.size();


 return 0;
}








Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    long long int a, b, c;
    cin >> a >> b >> c;
    cout << min(b % 2 * a * c, min(a % 2 * b * c, c % 2 * a * b)) << endl;
}




Measured memory_bytes: 3608