akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,X;
string S,A;
cin >> N;
X=1;
vector <string> vec ;
for(int i=0;i<N;i++){
    cin >>S;
    vec.push_back(S);
    }
sort (vec.begin(),vec.end());
A=vec.at(0);
for(int j=1;j<vec.size();j++){
    if(A==vec.at(j)){
    
    }
    else{
        A=vec.at(j);
        X++;
    }
}
cout<< X<<endl;

  }

Measured memory_bytes: 11664
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

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

        long n = stdIn.nextLong();
        long k = stdIn.nextLong();

        long a = n % k;
        long b = Math.abs(n % k - k);

        if(a < b){
            System.out.println(a);
        }else{
            System.out.println(b);
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,l[300],ans=0;
  cin >> n;
  rep(i,2*n)cin >> l[i];
  sort(l,l+2*n);
  rep(i,2*n)if(i%2==0)ans+=l[i];
  printf("%lld",ans);
}

Measured memory_bytes: 256
s = input()
res = 0
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        t = s[i:j]
        c = 0
        for sss in 'ATGC':
            c += t.count(sss)
        if c == len(t):
            res = max(res, c)
print(res)


Measured memory_bytes: 2940
X,N = list(map(int,input().split()))
if N == 0:
  print(X)
  exit()
P = sorted(list(map(int,input().split())))
ans1 = P[0] - 1
ans2 = P[-1] + 1
isx = 0
for i in range(1,N):
  if (P[i]-X) > 0:
    if not isx:
      ans1 = X
      break
    else:
      break
  if P[i-1] != (P[i]-1):
    ans1 = P[i] -1
  if P[i] == X:
    isx = 1
    break

for i in range(1,N+1):
  if (P[-i]-X) < 0:
    if not isx:
      ans1 = X
      break
    else:
      break
  if P[-i+1] != (P[-i]+1):
    ans2 = P[-i] + 1
  if P[-i] == X:
    isx = 1
    break

if not isx:
  print(X)
  exit()

aa1 = abs(X-ans1)
aa2 = abs(X-ans2)
if aa1 == aa2:
  print(ans1)
elif aa1 > aa2:
  print(ans2)
else:
  print(ans1)


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

int n, mn = 1e9, mx, cnt, a[100010];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        mn = min(mn, a[i]), mx = max(mx, a[i]);
    }
    for (int i = 1; i <= n; i++) {
        if (a[i] == mn) cnt++;
    }
    if (mx - mn > 1) {
        printf("No\n"), exit(0);
    }
    if (mn == mx) {
        if (mn == n - 1 || mn * 2 <= n) printf("Yes\n");
        else printf("No\n");
        exit(0);
    }
    if (mx - cnt > 0 && n - cnt >= 2 * (mx - cnt)) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

// @@ !! LIM(f:updMaxMin)
// --> f:updMaxMin
// ---- inserted function updMaxMin from util.cc
template<typename T>
bool updMax(T& tmax, const T& x) {
  if (x > tmax) { tmax = x; return true;  }
  else          {           return false; }
}
template<typename T>
bool updMin(T& tmin, const T& x) {
  if (x < tmin) { tmin = x; return true;  }
  else          {           return false; }
}
// ---- end updMaxMin
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  string S; cin >> S;
  ll cmin = 0;
  ll cur = 0;
  for (ll i = 0; i < N; i++) {
    if (S.at(i) == '(') {
      cur++;
    }else {
      cur--;
      updMin(cmin, cur);
    }
  }
  if (cmin < 0) cur -= cmin;
  for (ll i = 0; i < -cmin; i++) cout << '(';
  cout << S;
  for (ll i = cur; i > 0; i--) cout << ')';
  cout << endl;

  return 0;
}



Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n,m,r=na()
rs = na()
for i in range(r):
    rs[i] -= 1

g = [[99999999999]*n for _ in range(n)]
for i in range(n):
    g[i][i] = 0
for i in range(m):
    a, b, c = na()
    a -= 1
    b -= 1
    g[a][b] = g[b][a] = c

from heapq import *
def dijkstra(g, start):
    n = len(g)
    ds = [1e18] * n
    ds[start] = 0
    h = []
    heappush(h, (0, start))
    while len(h) > 0:
        d, cur = heappop(h)
        if d != ds[cur]: continue
        for e, ew in g[cur]:
            if d + ew < ds[e]:
                ds[e] = d + ew
                heappush(h, (ds[e], e))
    return ds

def dijkstra_dense(g, start):
    n = len(g)
    ds = [1e18] * n
    ds[start] = 0

    done = [0] * n
    while True:
        lmin = 1e19
        arg = -1
        for i in range(n):
            if not done[i] and ds[i] < lmin:
                lmin = ds[i]
                arg = i
        if arg == -1: break
        done[arg] = 1
        for i in range(n):
            ds[i] = min(ds[i], lmin + g[arg][i])
    return ds


dss = [None] * n
for r in rs:
    dss[r] = dijkstra_dense(g, r)

from itertools import *

ans = 9999999999999999999
for ord in permutations(rs):
    w = 0
    for i in range(1, len(rs)):
        w += dss[ord[i-1]][ord[i]]
    ans = min(ans, w)
print(ans)


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long h = Long.parseLong(br.readLine());
		long pow2[] = new long[100];
		for(int i = 0 ; i < 100 ; i++) {
			pow2[i] =(long) Math.pow(2, i);
		}
		long result = 0;
		for(int i = 0 ; i < 100; i++) {
			if(h >= pow2[i]) {
				result = pow2[i+1] -1;
			}
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,b) for (ll i=a;i<=ll(b);i++)
using namespace std;
ll ctoi(const char c){if('0'<=c&&c<='9') return (c-'0');return -1;}
#define ALL(x) begin(x),end(x)
  
int main(){
  ll n,m; cin >> n >> m;
  vector<pair<ll,ll>> v;
  rep(i,n){
    ll a,b; cin >> a >> b;
    v.push_back(make_pair(a,b));
  }
  sort(ALL(v));
  
  ll purchaseNum = m;
  ll sum = 0;
  rep(i,n){
    if(purchaseNum>=v[i].second) sum += v[i].first*v[i].second;
    else sum += v[i].first*purchaseNum;
    purchaseNum -= v[i].second;
    if(purchaseNum<=0) break;
  }
  cout << sum << endl;
} 

Measured memory_bytes: 5368
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

const ll MOD = 1000000007;
const int MM = 200000;

ll fac[MM+10];
ll invfac[MM+10];
ll mypow(ll x, ll n) {
  if(n == 0) return 1;
  if(n % 2 == 0) return mypow(x*x%MOD, n/2);
  return mypow(x*x%MOD, n/2) * x % MOD;
}

ll cmb(ll n, ll r) {
  assert(0 <= r && r <= n);
  return fac[n] * invfac[r] % MOD * invfac[n-r] % MOD;
}

int main(void) {
  fac[0] = 1;
  REP(i, MM) {
    fac[i+1] = fac[i] * (i+1) % MOD;
  }
  invfac[MM] = mypow(fac[MM], MOD-2);
  for(int i = MM; i > 0; --i) {
    invfac[i-1] = invfac[i] * i % MOD;
  }
  
  ll n, m;
  cin >> n >> m;
  vector<ll> fs;
  for(ll p = 2; p*p <= m; ++p) {
    ll cur = 0;
    while(m % p == 0) {
      ++cur;
      m /= p;
    }
    if(cur > 0) {
      fs.push_back(cur);
    }
  }
  if(m > 1) {
    fs.push_back(1);
  }
  ll res = 1;
  REP(i, fs.size()) {
    res = res * cmb(n+fs[i]-1, n-1) % MOD;
  }
  cout << res << endl;
  
  return 0;
}



Measured memory_bytes: 3328
x, n = map(int, input().split())
if n:
    p = {int(i) for i in input().split()}
if n == 0:
    print(x)
else:
    if x not in p:
        print(x)
    else:
        flag = True
        abs_diff = 1
        while flag:
            for i in range(1, 3):
                ans = x + (-1)**i * abs_diff
                if ans not in p:
                    flag = False
                    print(ans)
                    break
            abs_diff += 1

Measured memory_bytes: 9084
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

const int MAX=510000;

vll fac(MAX);
vll finv(MAX);
vll inv(MAX);

void combinit(ll m){
    fac[0]=1;fac[1]=1;
    finv[0]=1;finv[1]=1;
    inv[1]=1;
    rep2(i,2,MAX){
        fac[i]=fac[i-1]*i%m;
        inv[i]=m-inv[m%i]*(m/i)%m;
        finv[i]=finv[i-1]*inv[i]%m;
    }
}

ll combi(ll n,ll k,ll m){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%m)%m;
}

ll permutation(ll n,ll k,ll m){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return (combi(n,k,m)*fac[k])%m;
}

int main(){
    ll n,m;cin>>n>>m;
    combinit(inf);
    vll dp(n+1);
    ll tmp;
    rep(i,n+1){
        tmp=permutation(m-i,n-i,inf);
        tmp*=tmp;tmp%=inf;
        tmp*=permutation(m,i,inf);tmp%=inf;
        tmp*=combi(n,i,inf);tmp%=inf;
        dp[i]=tmp;
    }
    ll sum=(permutation(m,n,inf)*permutation(m,n,inf))%inf;
    rep2(i,1,n+1){
        if(i%2){
            sum-=dp[i];
            if(sum<0)sum+=inf;
        }
        else{
            sum+=dp[i];
            sum%=inf;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 18992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int N, X, mm=1000;
    int m[110];

    cin >> N >> X;
    int Y = X;
    for (int i=0; i<N; i++){
        cin >> m[i];
        Y -= m[i];
        mm = min (mm, m[i]);
    }

    int cnt = N + Y / mm;
    cout << cnt << endl;
    
}


Measured memory_bytes: 256
def is_palindrome(s):
    i = 0
    j = len(s)-1
    flag = 1
    while(i<j):
        if s[i] != s[j]:
            flag = 0
            break
        i = i + 1
        j = j - 1
    return(flag)

s = input()
n = len(s)
f1 = int(((n+1)/2) - 1)
f2 = int((n+3)/2 - 1)

if is_palindrome(s) and is_palindrome(s[:f1]) and is_palindrome(s[f2:]):
    print("Yes")
else:
    print("No")

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N,T;
    cin >> N >> T;
    int ans=inf;
    rep(i,0,N){
        int c,t;
        cin >> c >> t;
        if(t<=T) ans=min(ans,c);
    }

    cout << (ans==inf?"TLE":to_string(ans)) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        int count = int.Parse(ReadLine());
        stringData[] stringDatas = new stringData[count];

        for (int i = 0; i < count; i++)
        {
            var input = ReadLine();
            stringDatas[i] = new stringData(input);
        }

        int a_and_b = stringDatas.Count(sd => sd.IsEndWithA && sd.IsStartWithB);
        int a = stringDatas.Count(sd => sd.IsEndWithA) - a_and_b;
        int b = stringDatas.Count(sd => sd.IsStartWithB) - a_and_b;
        int min = new[] { a, b }.Min();
        if (a == 0 && b == 0 && a_and_b != 0)
            min -= 1;

        int Ab = stringDatas.Sum(sd => sd.ABCount);

        WriteLine(Ab + min + a_and_b);


        ReadKey();
    }
}

public struct stringData
{
    public bool IsStartWithB;
    public bool IsEndWithA;
    public int ABCount;

    public stringData(string s)
    {
        ABCount = 0;

        IsStartWithB = s[0] == 'B';
        bool isA = false;

        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'A')
                isA = true;
            else if (s[i] == 'B' && isA)
            {
                ABCount++;
                isA = false;
            }
            else
            {
                isA = false;
            }
        }
        IsEndWithA = s[s.Length - 1] == 'A';
    }
}

static class MyUtil
{
    public static long[] ReadlongArray()
    {
        return ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    }

    /// <summary>
    /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ts"></param>
    public static void WriteToConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        Console.WriteLine(stringBuilder.ToString());
    }
}


Measured memory_bytes: 13476
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <cstring>
#include <cmath>

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()

using namespace std;
const int MOD = 1000000007;

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

long lcm( long m, long n ){
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n);
}


long kake(long x, long y){
	return x * y % MOD;
}

long fact_mod(long x){
	long ans = x;
	x-=1;
	while(x>1){
		ans = ans * x % MOD;
		x-=1;
	}
	return ans;
}

int N,M,cnt;
int adj[8][8];
bool visited[8];


void dfs(int node){
	visited[node] = true;

	int passed = 0;
	for(int i=0; i<N; i++){
		passed += visited[i];
	}

	if(passed == N){
		cnt+=1;
	}

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

		if(adj[node][i]==1 && visited[i]==false){
			dfs(i);
			visited[i] = false;
		}
	}
}

int main(){

	memset(adj, 0, sizeof(adj));
	memset(visited, 0, sizeof(visited));
	cnt = 0;

	cin >> N >> M;

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

	dfs(0);
	cout << cnt << endl;

}

Measured memory_bytes: 256
#include <iostream>

int main()
{
  uint size;
  std::cin >> size;
  int a[size];
  for (int i = 0; i < size; i++) {
    std::cin >> a[i];
  }
  for (int i = size - 1; i >= 0; i--) {
    std::cout << a[i] << (i == 0 ? "\n" : " ");
  }
}



Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		if((b-a-1)%2 == 0) {
			System.out.println("Borys");
		} else {
			System.out.println("Alice");
		}
	}

}


Measured memory_bytes: 22740
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;
const int mx = 3e6 + 9;

inline void normal(ll &a) { if (a >= MOD) a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) {normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) {normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) {normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } //if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll f[mx];

ll nCr(ll n, ll r) {
    return modDiv(f[n], modMul(f[r], f[n - r]));
}

int main() {
    f[0] = 1;
    for (int i = 1; i < mx; i++) f[i] = modMul(i, f[i - 1]);
    int k; string s;
    cin >> k >> s;

    int sz = s.size();
    int n = k + sz;
    int z = 26;

    ll ans = 0;
    for (int m = 0; m < sz; m++) {
        ll temp = nCr(n, m);
        temp = modMul(temp, modPow(z - 1, n - m));
        ans = modAdd(ans, temp);
    }

    ans = modSub(modPow(z, n), ans);
    cout << ans << endl;
}

Measured memory_bytes: 28792
// C++ program to find Excel 
// column name from a given 
// column number 
#include <bits/stdc++.h> 
#define MAX 100 
using namespace std; 

// Function to print Excel column name for a given column number 
void printString(long long int n) 
{ 
	char str[MAX]; // To store result (Excel column name) 
	long long int i = 0; // To store current index in str which is result 

	while (n > 0) { 
		// Find remainder 
		long long int rem = n % 26; 

		// If remainder is 0, then a 'Z' must be there in output 
		if (rem == 0) { 
			str[i++] = 'z'; 
			n = (n / 26) - 1; 
		} 
		else // If remainder is non-zero 
		{ 
			str[i++] = (rem - 1) + 'a'; 
			n = n / 26; 
		} 
	} 
	str[i] = '\0'; 

	// Reverse the string and print result 
	reverse(str, str + strlen(str)); 
	cout << str << endl; 

	return; 
} 

// Driver program to test above function 
int main() 
{ 
	long long a ;
	cin >> a ;
	printString(a) ;
	return 0; 
} 


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int,int> P;
int ans,used[1000010];
vector<P>in[1000010];
int n,m;

void check(int pos){
  if(used[pos])return;
  used[pos]=1;
  for(int i=0;i<in[pos].size();i++){
    int nx=in[pos][i].first,idx=in[pos][i].second;
    if(used[nx])ans=1;
    in[pos].erase(in[pos].begin()+i);
    in[nx].erase(in[nx].begin()+idx);
    check(nx);
    i=-1;
  }
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<=n;i++)in[i].clear(),used[i]=0;

    ans=0;
    for(int i=0,a,b;i<m;i++){
      cin>>a>>b;
      in[a].push_back(P(b,in[b].size()));
      in[b].push_back(P(a,in[a].size()-1));
      if(in[a].size()/3||in[b].size()/3) ans=1;
    }
    
    for(int i=1;i<=n;i++) check(i);
    //    for(int i=1;i<=n;i++) ans+=in[i].size();
    cout <<(ans? "no":"yes")<<endl;
  }
  return 0;
}

Measured memory_bytes: 32840
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


#define N 1300000

int prime[N];

void eratosthenes(){
  rep(i,N) prime[i]=1;
  prime[0]=prime[1]=0;
  rep(i,sqrt(N)){
    if(prime[i]){
      for(int j=i+i;j<N;j+=i) prime[j]=0;
    }
  }
}

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  eratosthenes();
  while(1){
    int n;
    int numu,numd;
    cin>>n;
    if(n==0) break;
    else{
      repi(i,n,1300000){
	if(prime[i]==1){numu=i;break;}
      }
       repn(i,n){
	if(prime[i]==1){numd=i;break;}
      }
    }
    cout<<numu-numd<<endl;
  }
  
    
      

  return 0;
}



Measured memory_bytes: 13284
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

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

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    ll now=100,x;
    cin>>x;
    ll answer=0;
    while(now<x){
        answer+=1;
        now*=1.01;
    }
    cout<<answer;

    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <math.h>

int main(void){
	double x1,y1,x2,y2,d;

	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

	d = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));

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

	return 0;
}

Measured memory_bytes: 652
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;
ll m= 0xffffffffff;
ll N;

ll calc(ll a){
  ll res = 0;
  while(a>0){
    res+= a%10;
    a/=10;
  }
  return res;
}

int main()
{
  cin>>N;
  rep1(i,N-1){
    m = min(m,calc(i)+calc(N-i));
  }
  cout<<m<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(all(v));

	ll ans = 0;
	for (int i = 1; i < N; i++)
		ans += v[N - 1 - i / 2];
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3968
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

ll s[1001];

int main() {
	int n;
	string s;
	cin >> n >> s;
	ll ans = 0;
	FOR(i, 1, n - 1) {
		string a, b;
		a = s.substr(0, i);
		b = s.substr(i, n - i);
		ll tmp = 0;
		REP(i, 26) {
			char cnt = 'a' + i;
			if (a.find(cnt) != a.npos && b.find(cnt) != b.npos)tmp++;
		}
		if (tmp > ans)ans = tmp;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*
import kotlin.*

import java.io.InputStream
import java.lang.NumberFormatException
import java.lang.StringBuilder


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = FastScanner()
        val s = sc.next()
        var ans = 0
        for(i in 0 until 4){
            ans += if(s[i] =='+') 1 else -1

        }

        println(ans)
    }
}


class FastScanner {
    companion object {
        val input: InputStream = System.`in`
        val buffer = ByteArray(1024) { 0 }
        fun isPrintableChar(c: Int): Boolean = c in 33..126
    }

    var ptr = 0
    var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = input.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int = if (hasNextByte()) buffer[ptr++].toInt() else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b)
            b = readByte()
        }
        return sb.toString()
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextDouble(): Double = next().toDouble()
}


Measured memory_bytes: 31388
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

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

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi a(n);
    vi kind(n,0);;
    int max=0;
    rep(i,n){
        cin>>a[i];
        a[i]--;
        kind[a[i]]++;
        chmax(max,kind[a[i]]);
    }
    //引かれない場合．
    ll res=0;
    rep(i,n){
        if(kind[i]>=2)res+=(ll)(kind[i])*(kind[i]-1)/2;
    }
    rep(i,n){
        ll cpres=res;
        if(kind[a[i]]>=2){
            cpres-=(ll)(kind[a[i]])*(kind[a[i]]-1)/2;
            ll tmp=kind[a[i]];
            tmp--;
            cpres+=(tmp)*(tmp-1)/2;
        }
        cout<<cpres<<endl;
    }
    return 0;
}




Measured memory_bytes: 4096
// https://atcoder.jp/contests/abc166/tasks/abc166_d
#include <bits/stdc++.h>

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll inf = LONG_LONG_MAX;
const int nax = 1e5+200;
const double mpi = acos(-1);
const double eps= 1e-10;

int dr[] = {1,-1,0, 0,1,-1,-1, 1}; // trick to explore an implicit 2D grid
int dc[] = {0, 0,1,-1,1, 1,-1,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cout<< setprecision(20)<< fixed;
  ll x;
  cin>> x;
  for(ll a= -500; a<=500; ++a){
    for(ll b= -500; b<=500; ++b){
      if(pow(a,5)- pow(b,5)==x){
        cout<< a<< " "<<b<<el;
        return 0;
      }
    }
  }
}





Measured memory_bytes: 4044
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int SG(int a,int k) {
    int x=a/k,b=a%k;
    return b?SG(a-((b+x)/(x+1))*(x+1),k):x;
}

int main() {
	int n,a,k,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d%d",&a,&k),ans^=SG(a,k);
	return puts(ans?"Takahashi":"Aoki"),0;
}

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

int main(){

   int n;
   cin >> n;
   int *a = new int[n];
   long *num = new long[n];
   long *cor = new long[n];
   int tmp = 0;
   for(int i = 0;i < n;i ++){
   	  cin >> tmp;
	  a[i] = tmp - 1;
	  num[tmp - 1] ++;
   }
   long sum = 0;
   for(int i = 0;i < n;i ++){
   	  cor[i] = num[i] * (num[i] - 1) / 2;
	  sum += cor[i];
   }
   for(int i = 0;i < n;i ++){
   	  tmp = a[i];
	  cout << sum - cor[tmp] + (num[tmp] - 2)* (num[tmp] - 1) / 2 << "\n";
   }
}




Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main(){
  string s;
  cin >> s;
  int odd = s.size() % 2;
  bool same = false;
  if(s[0] == s[s.size()-1]) same = true;
  if(odd && same) cout << "Second" << endl;
  else if(odd && !same) cout << "First" << endl;
  else if(!odd && same) cout << "First" << endl;
  else if(!odd && !same) cout << "Second" << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
import java.util.TreeSet;
import java.util.Iterator;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String atoz = "abcdefghijklmnopqrstuvwxyz";
        for(String str : s.split("")){
            atoz = atoz.replace(str,"");
        }
        if(s.length() != 26){
            System.out.println(s + atoz.charAt(0));
            return;
        }
        int max = -1;
        char maxc = ' ';
        for(int i = 25;i >= 0;i--){
            char tmp = s.charAt(i);
            for(int j = i-1;j >= 0;j--){
                if(s.charAt(j) < tmp){
                    if(max < j){
                        max = j;
                        maxc = tmp;
                    }
                }
            }
        }
        if(max != -1){
            System.out.println(s.substring(0,max) + maxc);
            return;
        }
        System.out.println(-1);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

const int MAX = 200001;

int dp[1 << 26];
int opt[MAX], a[MAX], alp[26];

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

	int n = s.size();
	rep(i,n){
		alp[s[i] - 'a']++;
		
		int bit = 0;
		rep(j,26){
			if(alp[j] % 2){
				bit += 1 << j;
			}
		}
		a[i + 1] = bit;
	}

	rep(i,1 << 26){
		dp[i] = INF;
	}

	rep(i,n + 1) opt[i] = INF;
	opt[0] = 0;
	dp[0] = 0;
	range(i,1,n + 1){
		opt[i] = min(opt[i], dp[a[i]] + 1);
		rep(j,26){
			opt[i] = min(opt[i], dp[a[i] xor (1 << j)] + 1);
		}
		dp[a[i]] = min(dp[a[i]], opt[i]);
	}
	cout << opt[n] << endl;
}


Measured memory_bytes: 264324
void main() {
    int[] tmp = readln.split.to!(int[]);
    int h = tmp[0], w = tmp[1], k = tmp[2];

    int[][] field = new int[][](h, w);
    int cnt;
    int row;
    foreach (i; 0 .. h) {
        string s = readln.chomp;
        if (s.canFind('#')) {
            int col;
            foreach (j, x; s) {
                if (x == '#') {
                    ++cnt;
                    field[i][col..j+1] = cnt;
                    col = j.to!int + 1;
                }

                if (j == w - 1) {
                    if (field[i][col..$].canFind(0)) {
                        field[i][col..$] = cnt;
                    }
                }
            }

            if (row) {
                foreach (r; 1 .. row+1) {
                    foreach (j; 0 .. w) {
                        field[i-r][j] = field[i][j];
                    }
                }
                row = 0;
            }
        } else {
            ++row;

            if (i == h - 1) {
                foreach (r; 0 .. row) {
                    foreach (j; 0 .. w) {
                        field[i-r][j] = field[i-row][j];
                    }
                }
            }
        }
    }

    foreach (x; field) {
        foreach (j, y; x) {
            y.write;
            if (j != w - 1) " ".write;
            else writeln;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 1532
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		char[] str = s.toCharArray();
		int k = sc.nextInt();
		sc.close();

		char ch = str[k - 1];
		for (int i = 0; i < n; i++) {
			if (str[i] != ch) {
				str[i] = '*';
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(str[i]);
		}
		System.out.println();
	}
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    while (1) {
        int n, m;
        cin >> n >> m;
        if (!n) return 0;

        vector<vector<pair<P, int>>> edges(n);
        for (int i = 0; i < m; ++i) {
            int u, v, d, c;
            cin >> u >> v >> d >> c;
            --u;
            --v;
            edges[u].push_back(make_pair(P(d, c), v));
            edges[v].push_back(make_pair(P(d, c), u));
        }
        vector<int> dist(n, M);
        priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>> q;
        q.push(make_pair(P(0, 0), 0));
        int ans = 0;
        while (!q.empty()) {
            auto p = q.top();
            q.pop();
            if (dist[p.second] != M) continue;
            dist[p.second] = p.first.first;
            ans += p.first.second;
            for (auto& e : edges[p.second])
                if (dist[e.second] > p.first.first + e.first.first)
                    q.push(make_pair(P(p.first.first + e.first.first, e.first.second), e.second));
        }
        cout << ans << "\n";
    }
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

class UnionFind{
public:
  vector<int> p;		// 親
  vector<int> rank;	// サイズ・各集合の根のみ有効
  UnionFind(int n){
    p.resize(n, -1);
    rank.resize(n, 1);
  }
  int root(int x){
    if(p[x] == -1)return x;
    else return p[x] = root(p[x]); // 深さを 1 にしている
  }
  void unite(int x, int y){
    x = root(x); y = root(y);
    if(x == y)return;
    if(rank[x] > rank[y]) swap(x, y); // rankの小さいものを下につける
    rank[y] += rank[x];
    p[x] = y;
  }
  //xが属すグループのサイズ
  int size(int x){ return rank[root(x)]; }
  bool same(int x, int y){ return (root(x) == root(y)); }
};

void solve()
{
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> p[i];
    p[i]--;
  }

  UnionFind uf(n);
  ll inx, iny;
  for(int i = 0; i < m; ++i)
  {
    cin >> inx >> iny;
    inx--; iny--;
    uf.unite(inx, iny);
  }

  map<int, vector<int> > mp;
  for(int i = 0; i < n; ++i)
  {
    mp[uf.root(i)].emplace_back(i);
  }

  int ans = 0;
  for(const auto& m : mp)
  {
    vector<int> idxs;
    vector<int> vals;
    for(const auto& v : m.second)
    {
      idxs.emplace_back(v);
      vals.emplace_back(p[v]);
    }
    sort(idxs.begin(), idxs.end());
    sort(vals.begin(), vals.end());
    int ii = 0;
    int iv = 0;
    while(ii < idxs.size() && iv < vals.size())
    {
      if (idxs[ii] == vals[iv])
      {
        ans++;
        ii++;
        iv++;
      }
      else if (idxs[ii] < vals[iv])
      {
        ii++;
      }
      else if (idxs[ii] > vals[iv])
      {
        iv++;
      }
    }
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

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

const int MAXN = 1e5;

int n, m, arr[MAXN+10], red[MAXN+10], emp[MAXN+10];

int main()
{
    int i, j;
    scanf("%d%d", &n, &m);
    red[1]=1;
    for(i=1; i<=n; i++) arr[i]=1;

    for(i=1; i<=m; i++)
    {
        int p, q;
        scanf("%d%d", &p, &q);
        arr[p]--;
        arr[q]++;

        if(red[p]) red[q]=1;
        if(arr[p]==0) emp[p]=1, red[p]=0;
        if(red[q]) emp[q]=0;
    }
    int ans=0;
    for(i=1; i<=n; i++) if(red[i] && !emp[i]) ans++;
    printf("%d", ans);
}


Measured memory_bytes: 1408
fun main(args: Array<String>) {
    val mod = 1000000007
    val (N,M) = readIntList()
    var dp = IntArray(2.pow(N)) { 10000000 }
    dp[0] = 0

    for (m in 0 until M) {
        val dpNext = dp.toList().toIntArray()
        val (a,b) = readIntList()
        val c = readIntList().sumBy { 2.pow(it-1) }

        for (n in 0 until 2.pow(N)) {
            dpNext[n or c] = Math.min(dpNext[n or c], dp[n]+a)
        }
        dp = dpNext
    }

    var ans = dp.last()
    if (ans == 10000000) ans = -1
    println(ans)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun Int.pow(n:Int) = Math.pow(this.toDouble(), n.toDouble()).toInt()

Measured memory_bytes: 67312
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,t;
  cin>>n>>t;
  in mn=1e10;
  in bst=-1;
  in cb=0;
  in a;
  forn(z,n){
    cin>>a;
    if(a-mn>bst){
      bst=a-mn;
      cb=0;
    }
    cb+=(a-mn==bst);
    mn=min(mn,a);
  }
  assert(bst>0);
  cout<<cb<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int n;
    static int q;
    static int[][] g;
    static long[] a;
    static long[] ans;
    static boolean[] used;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        q = sc.nextInt();
        g = buildGraph(sc, n, n-1);
        a = new long[n];
        for (int i = 0; i < q; i++) {
            int p = sc.nextInt()-1;
            a[p] += sc.nextLong();
        }
        ans = new long[n];
        used = new boolean[n];
        dfs(0, 0);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(ans[i] + " ");
        }
        System.out.println(sb.toString());
        sc.close();

    }

    private static void dfs(int i, long j) {
        if(used[i]) return;
        used[i] = true;
        ans[i] += a[i] + j;
        for(int next : g[i]){
            dfs(next, ans[i]);
        }
    }

    public static int[][] buildGraph(Scanner sc, int n, int m) {
        int[][] graph = new int[n][];
        int[][] edges = new int[m][2];
        int[] deg = new int[n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            edges[i][0] = a;
            edges[i][1] = b;
            deg[a]++;
            deg[b]++;
        }
        for (int i = 0; i < n; i++) {
            graph[i] = new int[deg[i]];
        }
        for (int i = 0; i < m; i++) {
            int a = edges[i][0];
            int b = edges[i][1];
            graph[a][--deg[a]] = b;
            graph[b][--deg[b]] = a;
        }

        return graph;
    }

}


Measured memory_bytes: 201748
#include <bits/stdc++.h>
 
using namespace std; 
int main()
{
   int  a,b;
   cin>>a>>b;
   int i;
  vector<long int > v1,v2;
  for(i=0;i<b;++i)
      v1.push_back(a);
  
  for(i=0;i<a;++i)
      v2.push_back(b);
  
  if(v1<v2)
      { for(i=0;i<v1.size();++i) 
         cout<<v1[i];
      }
  
  else if(v2<v1)
     { for(i=0;i<v2.size();++i) 
         cout<<v2[i];
      }
  
  else
     { for(i=0;i<v1.size();++i) 
         cout<<v1[i];
      }
}
  
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main () {
  int N;
  cin >> N;
  vector<LL>A(N);
  vector<LL>a(N);
  vector<LL>b(N);
  LL sum = 0;
  for (int i = 0; i < N; i ++) cin >> a[i];
  for (int i = 0; i < N; i ++) cin >> b[i];
  for (int i = 0; i < N; i ++) {
    A[i] = b[i] - a[i];
    sum += A[i];
  }
  LL sum_ = sum;
  for (int i = 0; i < N; i ++) {
    if (A[i] < 0) {
      if (sum_ < -A[i]) {
        cout << "No" << endl;
        return 0;
      }
      sum_ += A[i];
      A[i] = 0;
    }
  }
  for (int i = 0; i < N; i ++) {
    if (A[i] % 2) {
      if (sum_ == 0ll) {
        cout << "No" << endl;
        return 0;
      }
      sum_ --;
      A[i] ++;
    }
  }
 // cout << sum << endl;
  //for (int i = 0; i < N; i ++) cout << A[i] << endl;
  cout << "Yes" << endl;
}



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


int main() {
    string s;
    while (cin >> s) {
        string f = "F";
        string c = "C";
        if(s.find(f)==string::npos || s.find(c) == string::npos) {
            cout << "No" << endl;
            continue;
        }
        
        
        int ci = s.find(c);
        s = s.substr(ci);
        int fi = s.find(f);

        if(fi!=string::npos) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        
    }

}

Measured memory_bytes: 256
// qdd on Jan 19, 2019

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

long long p[55], sz[55];

long long dfs(long long n, long long x) {
    if (n == 0) return x <= 0 ? 0 : 1;
    if (x <= sz[n - 1] + 1) return dfs(n - 1, x - 1);
    return p[n - 1] + 1 + dfs(n - 1, x - sz[n - 1] - 2);
}

int main() {
    p[0] = 1, sz[0] = 1;
    for (int i = 1; i <= 50; i++) {
        p[i] = 2 * p[i - 1] + 1;
        sz[i] = 2 * sz[i - 1] + 3;
    }
    long long n, x;
    cin >> n >> x;
    cout << dfs(n, x) << endl;
    return 0;
}


Measured memory_bytes: 256