akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main() {
    int n; std::cin >> n;
    int t = 0, x = 0, y = 0;
    for (int i = 0; i < n; i++) {
        int tn, xn, yn; std::cin >> tn >> xn >> yn;
        int d = std::abs(xn - x) + std::abs(yn -y);
        int dt = tn - t;
        if (d > dt || (dt % 2 != d %2)) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String A = sc.nextLine();
        String B = sc.nextLine();
        int NA = A.length();
        int NB = B.length();

        int[][] dp = new int[NA+1][NB+1];

        for (int i = 0; i < NA + 1; i++) {
            dp[i][0] = i;
        }

        for (int j = 0; j < NB + 1; j++) {
            dp[0][j] = j;
        }

        for (int i = 0; i < NA; i++) {
            for (int j = 0; j < NB; j++) {
                int a = dp[i+1][j] + 1;
                int b = dp[i][j+1] + 1;
                int c = dp[i][j] + (A.charAt(i) == B.charAt(j) ? 0 : 1);
                dp[i+1][j+1] = Math.min(Math.min(a, b), c);
            }
        }

        System.out.println(dp[NA][NB]);
    }
}


Measured memory_bytes: 30772
open System.Collections.Generic

type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI32()|]

    member public this.IArrayI32(n: int) =
        [|for i in 0 .. n - 1 -> this.NextI32(), i|]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI64()|]

    member public this.IArrayI64(n: int) =
        [|for i in 0 .. n - 1 -> this.NextI64(), i|]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF32()|]

    member public this.IArrayF32(n: int) =
        [|for i in 0 .. n - 1 -> this.NextF32(), i|]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF64()|]

    member public this.IArrayF64(n: int) =
        [|for i in 0 .. n - 1 -> this.NextF64(), i|]

    member public __.Tuple2Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]|]
    
    member public __.Tuple3Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]|]

    member public __.CountDic n (f : unit -> 'a) =
        let seqs = seq {for _ in 0 .. n - 1 -> f()}
        let dic = new Dictionary<'a, int64>();
        for i in seqs do
            if dic.ContainsKey(i)
            then dic.[i] <- dic.[i] + 1L
            else dic.Add(i, 1L)
        dic

end

[<EntryPoint>]
let main _ =
#if DEBUG
    printfn "debuged"
#endif

    let scanner = Scanner()
    let n = scanner.NextI32()
    let m = scanner.NextI32()
    let arr = scanner.ArrayI32(m)
    let flgArr = Array.create (n + 1) false
    arr |> Array.iter (fun x -> flgArr.[x] <- true)

    let f2 a = a % 1000000007L

    let f a b i =
        if flgArr.[i] then
            b, 0L
        else
            b, f2 (a + b)
    
    seq {1..n} |> Seq.fold (fun (a, b) x -> f a b x) (0L, 1L) |> snd
    |> printfn "%i"

    0


Measured memory_bytes: 19024
#include <stdio.h>
#include <string>

int main() {
  std::string S(3, ' '), T(3, ' ');
  scanf("%s", &S[0], S.size());
  scanf("%s", &T[0], T.size());
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (S[i] == T[i]) cnt++;
  }
  printf("%d", cnt);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a, b, k;
  cin >> a >> b >> k;
  if(a+b < k){
    cout << 0  << " " << 0 << endl;
  }
  else if(a < k){
    cout << 0 << " " << b - (k-a) << endl;
  }
  else{
    cout << a-k << " " << b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long int
#define INF 1000000001

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  if(n==1){
    P(1);
    return 0;
  }
  ll v[100000];
  int ans=0;
  REP(i,n){
    cin>>v[i];
  }
  sort(v,v+n);
  int count=0;
  for(int index=0;index<n;index++){
    if(index-1<0)continue;
    if(index==n-1){
      if(v[index-1]==v[index]){
        count++;
        if(count%2==0)ans++;
        break;
      }
      if(v[index-1]<v[index]){
        if(count%2==0){ans++;ans++;}
        break;
      }
    }
    int i=index;
    if(v[i-1]==v[i])count++;
    if(v[i-1]<v[i]){
      if(count%2==0){ans++;}
      count=0;
    }
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
ll ans;

int main()
{
	cin>>n;
	ans+=n-1;
	for(int i=2;i<=n-1;i++)
	{
		ans+=n/i;
		if(n%i==0)   ans--;
	}
	cout<<ans;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>d(n); for(auto&&i:d)cin>>i;
	sort(d.begin(),d.end());
	cout<<(d.at(n/2-1)==d.at(n/2)?0:d.at(n/2)-d.at(n/2-1))<<"\n"s;
}

Measured memory_bytes: 640
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
c_even = sorted(list(Counter(v[::2]).items()) +
                [(-1, 0)], key=lambda x: x[1])[::-1]
c_odd = sorted(list(Counter(v[1::2]).items()) +
               [(-1, 0)], key=lambda x: x[1])[::-1]
if c_even[0][0] == c_odd[0][0]:
    ans = n - max(c_even[0][1]+c_odd[1][1], c_even[1][1]+c_odd[0][1])
else:
    ans = n - (c_even[0][1] + c_odd[0][1])
print(ans)


Measured memory_bytes: 95168
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int a;
  cin >> a;
  string b[a];
  for(int i = 0;i < a;i++){
    cin >> b[i];
  }
  sort(b,b+a);
  int flag = 0;
  for(int i = 0;i < a-1;i++){
    if(b[i] != b[i+1]){
      flag += 1;
    }
  }
  flag += 1;
  cout << flag << endl;
}


Measured memory_bytes: 9856
n, a, b = map(int,input().split())
x = list(map(int,input().split()))

for i in range(n - 1, 0, -1):
    x[i] -= x[i - 1]

x[0] = 0

ans = 0
for i in range(n):
    if a * x[i] > b:
        ans += b
    else:
        ans += (a * x[i])

print(ans)

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//



int main()
{
	fastio;
    // int T;
    // cin >> T;
    // while(T--)
    // {

    // }
    int N, M, K;
    cin >> N >> M >> K;
    vi A(N), B(M);
    fi(N)   cin >> A[i];
    fi(M)   cin >> B[i];
    int cnt = 0;
    ll sum = 0;
    int idxA = 0, idxB = 0;
    while(idxA < N && sum + A[idxA] <= K)
    {
        sum += A[idxA];
        idxA++;
    }
    idxA--;
    cnt = idxA+1;
    while(idxA < N && idxB<M)
    {
        sum += B[idxB];
        if(sum > K)
        {
            while(idxA >= 0)
            {
                sum-=A[idxA--];
                if(sum<=K)break;
            }
            if(sum > K && idxA<0)
            {
                idxB--;
                break;
            }
        }
        cnt = max(idxA+idxB+2,cnt);
        idxB++;
    }
    cout<<cnt<<endl;
    
    
}

Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;

void solve(istream &cin) {
    ll N, Y;
    while (cin >> N >> Y){
        Y /= 1000;
        ll x, y, z;
        x = y = z= -1;
        ll Z = Y - N;
        ll endz = Z/9 + 1;
        for (int zc = 0; zc < endz; ++zc) {
            ll rem = Z - 9*zc;
            if (rem % 4 == 0) {
                z = zc;
                y = rem / 4;
                x = N - z - y;
                if (x < 0) {
                    x = y = z = -1;
                }
                else break;
            }
        }
        cout << z << ' ' << y << ' '<< x << '\n';
    }
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    solve(cin);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <complex>
using namespace std;

typedef complex<int> pint;
typedef const pint &refpint;
typedef pair<double,bool> pdb;


#define INF 1e99

inline int cross(refpint a, refpint b){
	return a.real() * b.imag() - a.imag() * b.real();
}

inline double intersect(refpint a, refpint dif1, refpint f, refpint negdif2){
	int Aint = cross(dif1, negdif2);
	if( Aint == 0 ) return INF;
	double A = Aint;
	
	pint ddif = f - a;
	double t = cross(ddif, negdif2) / A;
	double s = cross(dif1, ddif) / A;
	
	if(t >= 0.0 && t <= 1.0 && s >= 0.0 && s <= 1.0){
		return t;
	}
	return INF;
}


int main(){
	int dataset;
	vector<pdb> ts;
	ts.reserve(100);
	for(scanf("%d", &dataset); dataset--; ){
		ts.clear();
		pint a, from, dif1, negdif2;
		int n, o, l, x1, x2, y1, y2;

		scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n);
		a = pint(x1, y1);
		dif1 = pint(x2, y2) - a;

		ts.reserve(n);

		for(int i = 0; i < n; ++i){
			scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &o, &l);
			from = pint(x1, y1);
			negdif2 = from - pint(x2, y2);

			double t = intersect(a, dif1, from, negdif2);
			if( t != INF ){
				ts.push_back( pdb(t, o != l) );
			}
		}
		
		sort(ts.begin(), ts.end());
		int res = 0;
		for(int i = 1; i < ts.size(); ++i){
			if(ts[i-1].second != ts[i].second){
				++res;
			}
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 1036
s = input()

# x を除いたときに回文になっていなければ達成不可能
if s.replace('x', '') != s.replace('x', '')[::-1]:
    print(-1)
    exit()

ans = 0

l = 0
r = len(s)-1

while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        ans += 1
        l += 1
    elif s[r] == 'x':
        ans += 1
        r -= 1
    else:
        print('error')
        exit()
print(ans)


Measured memory_bytes: 41584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

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

  vector<int> a(3,0);
  rep(i,s.size()) {
    char tmp = s[i];
    switch (tmp) {
      case 'a': {
        a[0] += 1;
        break;
      }
      case 'b': {
        a[1] += 1;
        break;
      }
      case 'c': {
        a[2] += 1;
      }
    }
  }
  ll mi = 1000000, ma = -10000;
  for (int i = 0; i < 3; ++i) {
    mi = min<ll>(mi, a[i]);
    ma = max<ll>(ma, a[i]);
  }

  printf((abs(mi-ma)) <= 1 ? "YES\n" : "NO\n");
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] ins = br.readLine().split(" ");
		int N = Integer.parseInt(ins[0]), m = Integer.parseInt(ins[1]);

		int[] len = new int[N], pCnt = new int[N];
		ArrayList<Integer>[] chldList = new ArrayList[N];
		for ( int i = 0; i < N; i++ ) {
			chldList[i] = new ArrayList<Integer>();
		}

		for ( int i = 0; i < m; i++ ) {
			ins = br.readLine().split(" ");
			int x = Integer.parseInt(ins[0]) - 1, y = Integer.parseInt(ins[1]) - 1;
			chldList[x].add(y);
			pCnt[y]++;
		}

		// 始点サーチ
		ArrayDeque<Integer> toCheck = new ArrayDeque<>();
		for ( int i = 0; i < N; i++ ) {
			if ( pCnt[i] == 0 ) toCheck.add(i);
		}

		// BFSで距離計算開始
		int lenMax = 0;
		while ( toCheck.size() > 0 ) {
			Integer node = toCheck.pollFirst();
			for ( Integer chld : chldList[node] ) {
				pCnt[chld]--;
				len[chld] = Math.max(len[node] + 1, len[chld]);
				lenMax = Math.max(lenMax, len[chld]);				
				if ( pCnt[chld] == 0 ) {
					toCheck.add(chld);
				}
			}
		}
		System.out.println(lenMax);
	}
}



Measured memory_bytes: 51860
N=int(input())
dic= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

N -=1
ans = ''
while N >= 26:
    a = N%26
    N = N//26 -1
    ans = dic[a] + ans
    

ans = dic[N] + ans  
print(ans)

Measured memory_bytes: 9112
<?php
//$K = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($H1,$M1,$H2,$M2,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$h1 = $H1*60 + $M1;
$h2 = $H2*60 + $M2;

printf("%d\n",max($h2 - $h1 - $K,0));


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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) int(pow(x,y))
#define FI first
#define SE second
const long mod = 1000000007;

int main(){
    long int N, M;
    cin >> N;
    vector<long int> D (N);
    for(int i = 0;i < N;i++){
        cin >> D.at(i);
    }
    cin >> M;
    vector<long int> T (M);
    for(int i = 0;i < M;i++){
        cin >> T.at(i);
    }
    SORT(D);
    SORT(T);
    int test = 0;
    for(int i = 0;i < N;i++){
        if(T.at(test) == D.at(i)){
            if(test == M - 1){
                cout << "YES" << endl;
                ED
            }
            test++;
        }
    }
    cout << "NO" << endl;
}

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

typedef long long ll;

const int MOD = (int)1e9 + 7;
int N, M;
vector<int> A, B;

void input_init(void) {
	cin >> N >> M;
	A.resize(N);
	for (int j = 0; j < N; ++j)
		cin >> A[j];
	B.resize(M);
	for (int i = 0; i < M; ++i)
		cin >> B[i];
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	sort(B.begin(), B.end());
	B.erase(unique(B.begin(), B.end()), B.end());
}

int calcu(int n) {
	vector<int>::iterator it_a = lower_bound(A.begin(), A.end(), n);
	vector<int>::iterator it_b = lower_bound(B.begin(), B.end(), n);
	int idx_a = distance(A.begin(), it_a);
	int idx_b = distance(B.begin(), it_b);

	int ret = 0;
	if (*it_a == n && *it_b == n)				// A, B 共に有る
		ret = 1;
	else if (*it_a == n && *it_b != n)			// A のみに有る
		ret = M - idx_b;
	else if (*it_a != n && *it_b == n)			// B のみに有る
		ret = N - idx_a;
	else										// A, B 共に無い
		ret = (M - idx_b) * (N - idx_a) - (N * M - n);

	return ret;
}

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

	input_init();
	ll ans = (ll)0;
	if (A.size() == N && B.size() == M) {
		A.push_back(N * M + 1);
		B.push_back(N * M + 1);
		ans = (ll)1;
		for (int i = 1; i <= N * M; ++i) {
			ans *= (ll)calcu(i);
			ans %= (ll)MOD;
		}
	}

	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc154/tasks/abc154_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  string S;
  cin >> S;

  cout << string(S.size(), 'x') << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    ll aa = a[0];
    ll mid_aa = aa/2;
    ll bb = 1000000010;
    for(ll i=1; i<n; i++){
        if(abs(a[i] - mid_aa) < abs(bb - mid_aa)){
            bb = a[i];
        }
    }
    cout << aa << " " << bb << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    string s; cin >> s;
    int l, r;
    rep(i, SZ(s)) {
        if (s[i] == 'A') {
            l = i;
            break;
        }
    }
    for (int i = SZ(s) - 1; i >= 0; --i) {
        if (s[i] == 'Z') {
            r = i;
            break;
        }
    }
    out(r - l + 1);
}




Measured memory_bytes: 640
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	std::string S;
	std::cin >> N;
	std::cin >> S;
	std::vector<int> R, G;
	std::unordered_set<int> B;

	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == 'R')
			R.push_back(i);
		else if (S[i] == 'G')
			G.push_back(i);
		else
			B.insert(i);
	}

	long result = 0;
	for (auto r : R) {
		for (auto g : G) {
			result += B.size();
			if (B.find(r + (r - g)) != B.end())
				--result;
			if (B.find(g + (g - r)) != B.end())
				--result;
			if ((r - g) % 2 == 0 && B.find((r + g) / 2) != B.end())
				--result;
		}
	}
	std::cout << result << "\n";

}


Measured memory_bytes: 3720
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int N,T;
vector<int> c;
vector<int> t;

void chmin(int &a, int b){
  if (a > b) a = b;
}

int main(){
  cin >> N >> T;
  c.resize(N); t.resize(N);
  
  rep(i,N) cin >> c[i] >> t[i];
  
  int ans = 1001;
  
  rep(i,N){
    if (t[i] <= T){
      chmin(ans, c[i]);
    }
  }
  
  if (ans == 1001){
    cout << "TLE";
  }else{
    cout << ans;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long n,a[200005],b[200005];
int main()
{
    cin>>n;
    for (int i=2;i<=n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    for (int i=1;i<=n;i++)
    cout<<b[i]<<endl;
}


Measured memory_bytes: 6708
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

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

Measured memory_bytes: 3544
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        S: String,
    }
    let ans = match &S[..] {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => panic!("aaa"),
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys
from itertools import accumulate
from bisect import bisect_left,bisect_right,insort
#input = sys.stdin.readline

def main():
    n,k=map(int,input().split())
    s=list(input())
    flg,cnt,chk='1',0,[0]    
    for i in range(n):
        if s[i]==flg:
            chk[cnt]+=1
        else:
            flg=str((int(flg)+1)%2)
            cnt+=1
            chk.append(1)
    if s[-1]=='0':
        chk.append(0)
    lng=len(chk)
    if k*2>lng:
        print(n)
    else:
        ans=0
        acc=[0]+list(accumulate(chk))
        for i in range(0,len(chk)-2*k,2):
            ans=max(ans,acc[i+2*k+1]-acc[i])
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 53384
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <functional>
#define MOD 1000000007

int i,j,k;

struct edge {
    int to;
    int cost;
};

typedef long long ll;
using namespace std;
using P = pair<int, int>;

bool compare_by_b(pair<int,pair<string,int>> a, pair<int,pair<string,int>> b) {
    if(a.second.first != b.second.first){
        return a.second.first < b.second.first;
    }else{
    return a.second.second > b.second.second;
    }
}

int main(void) {
    int n,x;
    vector<int> L;
    int tmp=0;
    cin >> n >> x;
    for(i=0;i<n;i++){
        int l;
        cin >> l;
        L.push_back(l);
    }
    if(x==0){
        cout << 1 << endl;
        return 0;
    }
    for(i=0;i<n;i++){
        tmp += L[i];
        if(x<tmp){
            cout << 1+i << endl;
            return 0;
        }
    }
    cout << n+1 << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
	int a,b,c,d,x=0,y=0,z=0;
	cin>>a>>b>>c>>d;
	x=max(a,c);
	y=min(b,d);
	if (y>=x){
		z=y-x;
	
	}
		cout<<z;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum;
  cin >> N;

  for (int i=0; i<N; i++)
  {
    int a, b;
  	cin >> a >> b;
    sum += b-a+1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_set>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

pii dfs(int v, int c, vector<int> &color, vector<vector<int>> &E) {
  if (color[v] == -1) {
    color[v] = c;
  } else {
    if (color[v] != c) {
      return mp(-1, -1);
    } else {
      return mp(0, 0);
    }
  }

  int N = E.size();
  pii sum;
  if (c == 0) sum.first += 1; else sum.second += 1;
  for(int i = 0; i < N; i++) {
    if (E[v][i]) {
      pii r = dfs(i, 1 - c, color, E);
      if (r.first == -1) return mp(-1, -1);
      sum.first += r.first;
      sum.second += r.second;
    }
  }
  return sum;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N, vector<int>(N, 0));
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    E[a][b] = E[b][a] = 1;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      E[i][j] = 1 - E[i][j];
    }
  }
  vector<int> color(N, -1);
  vector<pii> k;
  for(int i = 0; i < N; i++) {
    if (color[i] == -1) {
      k.push_back(dfs(i, 0, color, E));
    }
  }
  for (int i = 0; i < k.size(); i++) {
    if (k[i].first == -1) {
      cout << -1 << endl;
      return 0;
    }
  }

  // dp[i][j] := i個目まで考えた時、選んだSの大きさがjとなるか
  vector<vector<int>> dp(k.size() + 1, vector<int>(N + 1, 0));

  dp[0][0] = 1;
  for (int i = 0; i < k.size(); i++) {
    for (int j = 0; j < N; j++) {
      if (!dp[i][j]) continue;
      dp[i + 1][j + k[i].first] |= dp[i][j];
      dp[i + 1][j + k[i].second] |= dp[i][j];
    }
  }
  int ans = 1 << 30;
  for (int j = 0; j < N; j++) {
    if (dp[k.size()][j]) {
      int r = j, b = N - r;
      ans = min(ans, r * (r - 1) / 2 + b * (b - 1) / 2);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4096
import java.util.*;

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

        if(lang.equals("a") || lang.equals("i") || lang.equals("u") || lang.equals("e") || lang.equals("o")){
            System.out.println("vowel");
        }else{
            System.out.println("consonant");
        }
    }
}

Measured memory_bytes: 22996
x_1,y_1,x_2,y_2=map(int,input().split())
ans=[]
x=x_2
y=y_2
dx=x_2-x_1
dy=y_2-y_1
for i in range(2):
    dx,dy=dy,dx
    dx=-dx
    x+=dx
    y+=dy
    ans.append(x)
    ans.append(y)
print(*ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    if (N % 1000 == 0)
    {
        cout << 0 << endl;
    }else
    {
        cout << 1000 - N % 1000 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3632
from bisect import bisect_left, bisect
from itertools import accumulate
from math import ceil


def solve(n, h, aa, bb):
    max_a = max(aa)
    bb.sort()
    i = bisect(bb, max_a)
    if i == n:
        return ceil(h / max_a)
    bba = list(accumulate(reversed(bb[i:])))
    remain = h - bba[-1]
    slash_cnt = max(0, ceil(remain / max_a))
    slash_dmg = slash_cnt * max_a
    throw_dmg = h - slash_dmg
    return slash_cnt + bisect_left(bba, throw_dmg) + 1


n, h = map(int, input().split())
aa, bb = [], []
for _ in range(n):
    a, b = map(int, input().split())
    aa.append(a)
    bb.append(b)

print(solve(n, h, aa, bb))


Measured memory_bytes: 15948
#include<bits/stdc++.h>
using namespace std;
#define EPS (1e-10)
using Int = long long;

//BEGIN CUT HERE
typedef vector<double> arr;
typedef vector<arr> mat;

double det(mat A){
  int n=A.size();
  double res=1;
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i+1;j<n;j++)
      if(abs(A[j][i])>abs(A[pivot][i])) pivot=j;
    swap(A[pivot],A[i]);
    res*=A[i][i]*(i!=pivot?-1:1);
    if(abs(A[i][i])<EPS) break;
    for(int j=i+1;j<n;j++)
      for(int k=n-1;k>=i;k--)
	A[j][k]-=A[i][k]*A[j][i]/A[i][i];
  }
  return res;
}

bool isTriangle(double a1,double a2,double a3){
  if(a1+a2<=a3||a2+a3<=a1||a3+a1<=a2) return 0;
  return 1;
}
double tetrahedra(double OA,double OB,double OC,double AB,double AC,double BC){
  if(!isTriangle(OA,OB,AB)) return 0;
  if(!isTriangle(OB,OC,BC)) return 0;
  if(!isTriangle(OC,OA,AC)) return 0;
  if(!isTriangle(AB,AC,BC)) return 0;
  mat A(5,arr(5,0));
  A[0][0]=    0;A[0][1]=AB*AB;A[0][2]=AC*AC;A[0][3]=OA*OA;A[0][4]=1;
  A[1][0]=AB*AB;A[1][1]=    0;A[1][2]=BC*BC;A[1][3]=OB*OB;A[1][4]=1;
  A[2][0]=AC*AC;A[2][1]=BC*BC;A[2][2]=    0;A[2][3]=OC*OC;A[2][4]=1;
  A[3][0]=OA*OA;A[3][1]=OB*OB;A[3][2]=OC*OC;A[3][3]=    0;A[3][4]=1;
  A[4][0]=    1;A[4][1]=    1;A[4][2]=    1;A[4][3]=    1;A[4][4]=0;
  //cout<<"det(A):"<<det(A)<<endl;
  if(det(A)<=0) return 0; 
  return sqrt(det(A)/288.0);
}
//END CUT HERE

signed main(){
  int n;
  while(cin>>n,n){
    double a[n];
    double ans=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	for(int k=j+1;k<n;k++){
	  for(int x=0;x<n;x++){
	    if(i==x||j==x||k==x) continue;
	    for(int y=0;y<n;y++){
	      if(i==y||j==y||k==y||x==y) continue;
	      for(int z=0;z<n;z++){
		if(i==z||j==z||k==z||x==z||y==z) continue;
		ans=max(ans,tetrahedra(a[i],a[j],a[k],a[x],a[y],a[z]));
	      }
	    }
	  }
	}
      }
    }
    printf("%.10f\n",ans);
  }
  return 0;
}


/*
verified on 2017/04/26
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2060
*/

Measured memory_bytes: 3196
#include <stdio.h>

int main(void)
{
    int a, b, c;
    
    scanf("%d%d%d", &a, &b, &c);
    
    if (a > b && a > c){
        printf("A\n");
        return (0);
    }
    
    if (b > c){
        printf("B\n");
        return (0);
    }
    printf("C\n");
    
    return (0);
}

        


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

int n, m, a[100005];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int l, r;
        cin >> l >> r;
        a[l] += 1;
        a[r + 1] += -1;
    }
    for (int i = 1; i <= n; ++i)
        a[i] += a[i - 1];

    int sol = 0;
    for (int i = 1; i <= n; ++i)
        if (a[i] == m)
            sol++;
    cout << sol;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll r,D,x;
    cin >> r >> D >> x;
    ll out = x;
    rep(i,10){
        out = out*r-D;
        cout << out << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
set<int> s;

int32_t main(){_
   
   s.insert(1);
   s.insert(2);
   s.insert(3);

int a, b;
cin >> a;
cin >> b;
s.erase(s.find(a));
s.erase(s.find(b));
   
   cout<<*s.begin();
   

   return 0;
}

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++)

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size(); i++) {
        char before = s[i] - 3;
        if (before < 'A') {
            before += 26;
        }
        s[i] = before;
    }
    cout << s << endl;
}


Measured memory_bytes: 3164
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const ll mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll x, n, s = 0;
vi b, u, l, ord;
ll f(ll i, ll x) {
	if(x>b[i])
	return b[i]*(l[i]-u[i]) + u[i]*x;
	return x*l[i];
}
bool can(ll v) {
	ll ans = 0, sm1 = 0, fl = v/x, p=v%x;
	for(ll i = 0; i < fl && i < n; i++) sm1+=f(ord[i],x);
	ans = sm1;
	for(ll i = fl; i < n; i++) ans = max(ans, sm1+f(ord[i], p));
	if(fl < n) sm1+=f(ord[fl],x);
	for(ll i = 0; i <= fl & i < n; i++) ans = max(ans, sm1-f(ord[i], x)+f(ord[i], p));
	return ans+s>=0;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> x;
	b.resize(n);
	u.resize(n);
	l.resize(n);
	for (int i = 0; i < n; i++)
		cin >> b[i] >> l[i] >> u[i], ord.pb(i), s -= l[i] * b[i];
	sort(all(ord), [&](const int& a, const int &b) {
		return f(a, x) > f(b, x);
	});
	if(s==0) {
		cout << 0;
		return 0;
	}
	ll ans = 0;
	for(ll a = 1ll<<42; a; a>>=1)
		if(!can(ans+a)) ans += a;
	cout << ans+1;
	return 0;
}

Measured memory_bytes: 3832
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int H, W, N;
char c[1001][1001];
int d[1001][1001], dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
vector<pair<int, int>> z;
int ans=0;

int bf() {
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++)d[i][j]=1e5;
	queue<pair<int, int>> que;
	for (int i = 0; i < z.size(); i++) {
		que.push(z[i]);
		d[z[i].first][z[i].second] = 0;
	}
	while (que.size()) {
		pair<int, int> p = que.front(); que.pop();
		for (int j = 0; j < 4; j++) {
			int ny = p.first + dy[j], nx = p.second + dx[j];
			if (ny >= 0 && ny < H&&nx >= 0 && nx < W&&d[ny][nx] == 1e5&&c[ny][nx] != '#') {
				d[ny][nx] = d[p.first][p.second] + 1;
				ans = max(ans, d[ny][nx]);
				que.push(pair<int, int>(ny, nx));
			}
		}
	}
	return ans;
}


int main() {
	cin >> H >> W ;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> c[i][j];
			if (c[i][j] == '#')z.push_back(pair<int, int>(i, j));
		}
	}
	cout << bf() << endl;
}



Measured memory_bytes: 21096
#include <stdio.h>
#define M 100
#define I (1<<21)
int A[M][M],n,d[M];
int queue[M],head=0,tail=0;

int dequeue(){
    int v;
    v=queue[head];
    if(head + 1 == M)head=0;
    else head++;
    return v;
}

void enqueue(int x){
    queue[tail]=x;
    if(tail+1==M)tail=0;
    else tail++;
}

int empty(){
    if(head==tail)return 1;
    else return 0;
}

void bfs(int s){
    int i,j,k;

    enqueue(s);

    for(i=0;i<n;i++){
        d[i]=I;
        }
    d[s]=0;

    while(empty()!=1){
        k=dequeue();
        for(j=0;j<n;j++){
            if(A[k][j] == 0)continue;
            if(d[j]!=I)continue;
            d[j]=d[k]+1;
            enqueue(j);
        }
    }
    for(i=0;i<n;i++){
        printf("%d ",i+1);
        if(d[i]==I){
            printf("-1\n");
        }
	else  printf("%d\n",d[i]);
    }
    }

int main(){
    int i,j,u,k,v;

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

    for(i=0;i<n;i++){
        scanf("%d%d",&u,&k);
        u--;
        for(j=0;j<k;j++){
            scanf("%d",&v);
            v--;
            A[u][v]=1;
        }
    }
    bfs(0);

    return 0;
}



Measured memory_bytes: 2140
K,N = map(int,input().split())
 
A = list(map(int,input().split()))

  
A_m = []
 
for i in range(1,N):
  A_m.append(A[i]-A[i-1])
  
A_m.append(K-A[N-1]+A[0])
  
print(sum(A_m)-max(A_m))

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

int main() {
  vector<int> h(10000), w(10000);
  int idx = 0;
  while(true) {
    cin >> h.at(idx) >> w.at(idx);
    if (h.at(idx) == 0 && w.at(idx) == 0) break;
    idx++;
  }
  idx = 0;
  while(!(h.at(idx) == 0 && w.at(idx) == 0)) {
    for(int i = 0; i < h.at(idx); i++) {
      for(int j = 0; j < w.at(idx); j++) {
        if(i % 2 == 1) {
          if(j % 2 == 1) cout << '#';
          else cout << '.';
        }
        else {
          if(j % 2 == 1) cout << '.';
          else cout << '#';
        }
      }
      cout << endl;
    }
    idx++;
    cout << endl;
  }
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,n; cin>>x;
 map<int,int>mp;
  while(x--)
  {
    cin>>n;
    if(mp.find(n)!=mp.end())
    {
      cout<<"NO";
      return 0;
    }
    else
    {mp[n]=1;}
  }
  cout<<"YES";
}


Measured memory_bytes: 9600
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	
	if (x-r<0 || x+r>W || y-r<0 || y+r>H){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
		
	return 0;
}


Measured memory_bytes: 2096
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int H, W;
char board[60][60];
int dist[60][60];

struct Elem {
    int x, y, cost;
    bool operator<(const Elem &e) const {
        return cost > e.cost;
    }
};
signed main() {
    cin >> H >> W;
    int cnt = 0;
    rep(i,0,H) rep(j,0,W) {
        cin >> board[i][j];
        cnt += (board[i][j] == '.');
    }

    rep(i,0,H) fill(dist[i], dist[i] + W, INF);
    dist[0][0] = 0;
    queue<Elem> que;
    que.push(Elem{0, 0, 0});

    while(que.size()) {
        Elem cur = que.front(); que.pop();
        for(int k=0; k<4; k++) {
            int nx = cur.x + dx[k], ny = cur.y + dy[k];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(board[nx][ny] == '#') continue;
            if(dist[nx][ny] > cur.cost + 1) {
                dist[nx][ny] = cur.cost + 1;
                que.push(Elem{nx, ny, dist[nx][ny]});
            }
        }
    }

    if(dist[H-1][W-1] == INF) cout << -1 << endl;
    else {
        int ans = cnt - dist[H-1][W-1] - 1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
template<class T> inline bool chmax(T& a, T b){if(a<b) {a=b; return 1;} return 0; }
template<class T> inline bool chmin(T& a, T b){if(a>b) {a=b; return 1;} return 0; }
const ll INF = 1LL << 60;
const ll mod = 1000000007;

int main(){
	//入力
	ll A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll K;cin>>K;
	cout<<A[K-1]<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n, m;
	cin>>n>>m;
	vector<int> a(m);
	rep(i, m) cin>>a[i];
	sort(all(a), [](int x, int y){return x%2>y%2;});
	if(m>2) swap(a[1], a[m-1]);
	if(m>2 && a[2]%2==1){
		cout<<"Impossible"<<endl;
		return 0;
	}
	vector<int> b;
	rep(i, m){
		int t = a[i];
		if(i==0) t++;
		if(i==m-1) t--;
		if(t) b.pb(t);
	}
	if(a.size()==1 && a[0]>1){
		b[0]--;
		b.pb(1);
	}
	cout<<a<<endl;
	cout<<b.size()<<endl;
	cout<<b<<endl;

	return 0;
}


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

int main(){
  long long n,k;
  cin>>n>>k;
  long long N=n;
  long long mn=1000000000000000000;
     while(n>=0){
        mn=min(n,mn);
        if(n<k){
            n=k-n;
        }
        else{
            n=n%k;
        }
        if(n==mn){
        mn=min(n,mn);
            break;
        }
     }
     cout<<mn;

   return 0;
       }


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

typedef long long ll;

#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll x; cin >> x;
	ll c = 100;
	ll ans = 0;
	while (c < x) {
		c *= 1.01; ans++;
	}
	cout << ans << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/


Measured memory_bytes: 3668
N,M,X=map(int,input().split())
a=list(input().split())
s=0
for i in range(M-1):
    a[i]=int(a[i])
    if X>a[i]:
        s+=1
    else:
        s+=0
t=M-s
if s>t:
    print(t)
else:
    print(s)

Measured memory_bytes: 3060
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<29)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    int n;
    int ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int t = i;
        int count = 0;
        while (t >= 1) {
            t /= 10;
            count++;
        }
        if (count % 2 == 1)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256