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

int main()
{
	int n;
	double h;
	string cnt[6];

	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> h;
		if (h < 165.0){
			cnt[0] += '*';
		}
		else if (h < 170.0){
			cnt[1] += '*';
		}
		else if (h < 175.0){
			cnt[2] += '*';
		}
		else if (h < 180.0){
			cnt[3] += '*';
		}
		else if (h < 185.0){
			cnt[4] += '*';
		}
		else {
			cnt[5] += '*';
		}
	}

	for (int i = 0; i < 6; i++){
		cout << i + 1 << ":" << cnt[i] << endl;
	}

	return (0);
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int max = 0;
    int max2 = 0;
    for(int i = 0; i < N; ++i) {
        cin >> A.at(i);
        if(max <= A.at(i))  {
            max2 = max;
            max = A.at(i);
        }else {
            if(max2 <= A.at(i)) {
                max2 = A.at(i);
            }
        }
    }

    for(int i = 0; i < N; ++i) {
        if(max == A.at(i)) {
            cout << max2 << endl;
        }else {
            cout << max << endl;
        }
    }
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> road(n,0);
  for (int i = 0; i < m; i++) {
    int a,b;
    cin >> a >> b;
    road.at(a - 1) += 1;
    road.at(b - 1) += 1;
  }
  for (int i = 0; i < n; i++) {
    cout << road.at(i) << endl;
  }
}

Measured memory_bytes: 3612
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

    int a, b, c;
    a = 0;
    b = n/2;
    c = n;
    vector<char> st;
    printf("%d\n", 0);
    fflush(stdout);
    string S;
    cin >> S;
    if(S[0] == 'V') return 0;
    st.push_back(S[0]);

    printf("%d\n", b);
    fflush(stdout);
    cin >> S;
    if(S[0] == 'V') return 0;
    st.push_back(S[0]);

    rep(i, 18) {
        if((((b-a)&1) && st[0] != st[1]) || (!((b-a)&1) && st[0] == st[1])) {
            a = b;
            b = (c+b)/2;
            st[0] = st[1];
        } else {
            c = b;
            b = (c+a)/2;
        }
        printf("%d\n", b);
        fflush(stdout);
        cin >> S;
        if(S[0] == 'V') return 0;
        st[1] = S[0];
    }

}

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

int main()
{
      
      int n,k;    
        scanf("%d%d",&n,&k);
        if(k==1)
        {
            printf("0");
            return 0;
        }

        int sum = n, c=1;
        while(sum < k)
        {
            sum += n-1;
            c++;
        }
        printf("%d",c);
    return 0;
}


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

using namespace std;

int a, b, c, k;

int main()
{

    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> a >> b >> c >> k;
    cout << (k <= a ? k : 2 * a + b - k);

    return 0;
}


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

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;

    string S[H];
    for(int i=0; i<H; i++){
        cin >> S[i];
    }

    vector<int> row[H+2];
    vector<int> col[W+2];
    for(int i=0; i<W+2; i++){
        row[0].push_back(i);
    }
    for(int i=0; i<H+2; i++){
        col[0].push_back(i);
    }

    for(int i=1; i<=H; i++){
        row[i].push_back(0);
    }

    for(int i=1; i<=W; i++){
        col[i].push_back(0);
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') {
                row[i+1].push_back(j+1);
                col[j+1].push_back(i+1);
            }
        }
    }


    for(int i=0; i<W+2; i++){
        row[H+1].push_back(i);
    }
    for(int i=0; i<H+2; i++){
        col[W+1].push_back(i);
    }    
    
    for(int i=1; i<=H; i++){
        row[i].push_back(W+1);
    }

    for(int i=1; i<=W; i++){
        col[i].push_back(H+1);
    }

    int m = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') continue;
            auto tate = lower_bound(col[j+1].begin(), col[j+1].end(), i+1);
            auto yoko = lower_bound(row[i+1].begin(), row[i+1].end(), j+1);

            int num = *tate - *(tate-1) + *yoko - *(yoko-1) -2 -1;
            if(num > m) m = num;
        }
    }

    cout << m;
    return 0;

}

Measured memory_bytes: 38656
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int N;
  int sum[200000];

  scanf("%d", &N);

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

  for (int i = 0; i < N - 1; i++)
  {
    int boss;
    scanf("%d", &boss);
    sum[boss - 1]++;
  }

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

  return 0;
}


Measured memory_bytes: 2460
import java.io.*
import java.util.*

fun solve(A: Int, B: Int){
    var ret = 1
    var ans = 0
    while(ret < B){
        ret += A - 1
        ans++
    }
    println(ans)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toInt()
    val B = sc.next().toInt()
    solve(A, B)
}



Measured memory_bytes: 31520
#include <iostream>
using namespace std;
int main()
{
  int N, X;
  cin >> N >> X;
  int pos = 0;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    int L;
    cin >> L;
    pos += L;
    if (pos <= X) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using ll = long long;
using p = pair<ll, ll>;
constexpr ll INF = 1LL << 62;

bool is_prime(ll n) {
  if (n == 1) {
    return false;
  }

  for (ll i = 2; i * i<= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main(void) {
  ll N;
  cin >> N;

  ll ans = 0;
  ll n = N;
  map<ll, ll> counts;

  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      counts[i]++;
      n /= i;
    }
  }

  if (is_prime(n)) {
    counts[n]++;
  }

  for (auto count : counts) {
    ll c = count.second;
    for (ll i = 1; i <= c ; i++) {
      c -= i;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

template<class T> class BIT {
    
public:
    vector<T> bit;
    int SIZE;
    
    void init(int N, T a) {
        SIZE = N + 1;
        bit.resize(SIZE);
        for (int i = 0; i < SIZE; i++) {
            bit[i] = a;
        }
    }
    // 1-indexed
    void add(int a, T w) {
        for (int x = a; x <= SIZE; x += x & -x) bit[x] += w;
    }
    
    // [1, a], 1-indexed
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret += bit[x];
        return ret;
    }
    
    // [a, b), 1-indexed
    T sum(int a, int b) {
        return sum(b) - sum(a - 1);
    }
    
    // get k-th number with binary search, k: 0-indexed
    int getk(T k) {
        k++;
        T ret = 0;
        int N = 1;
        while (N < SIZE) N *= 2;
        for (int i = N / 2; i > 0; i /= 2) {
            if (ret + i < SIZE && bit[ret + i] < k) {
                k = k - bit[ret + i];
                ret = ret + i;
            }
        }
        return ret + 1;
    }
};

const int NMAX = 100000;
int main() {
   int N, Q;
   cin >> N >> Q;
   BIT<int> bit;
   bit.init(NMAX, 0);
   for (int q = 0; q < Q; q++) {
      int c, x, y;
      cin >> c >> x >> y;
      if (c == 0) {
         bit.add(x, y);
      }
      else {
         int ans = bit.sum(x, y);
         cout << ans << endl;
      }
   }
   return 0;
}



Measured memory_bytes: 3116
n, m = map(int, input().split())
List = [list(map(int, input().split())) for i in range(n)]

ans = 0
count = 1
for j in range(1, len(List[0])):
    for i in range(1, n):
        if List[0][j] in List[i][1:]:
            count += 1
            if count == n:
                ans += 1
    count = 1
if n == 1:
    print(List[0][0])
else:
    print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	vector<int> l(n);
	for(int i=0;i<n;i++) cin>>l[i];
	sort(all(l));
	int sum=0;
	for(int i=0;i+1<n;i++) sum+=l[i];
	cout<<(l[n-1]<sum?"Yes":"No");
	re 0;
}

Measured memory_bytes: 3652
from collections import Counter

n = int(input())
l = []
for i in range(n):
    l.append(dict(Counter(input())))

l.sort(key=len)

ans = []
for ki, vi in l[0].items():
    tmp = vi
    for j in range(1, n):
        if ki in l[j]:
            tmp = min(tmp, l[j][ki])
        else:
            break
    else:
        ans.append(ki * tmp)
ans.sort()
print(*ans, sep="")

Measured memory_bytes: 9388
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  ll n, x; cin >> n >> x;

  ll dp[n][n];

  rep(i, n) {
    cin >> dp[0][i];
  }
  
  for(int k=1; k<n; k++) {
    rep(i, n) {
      dp[k][(i+k)%n] = min(dp[k-1][(i+k)%n], dp[0][i]);
    }
  }

  ll ans = LONG_MAX;
  rep(k, n) {
    ll now = 0;
    rep(i, n) {
      now += dp[k][i];
      //debug(dp[k][i]);
    }
    //cout << endl;
    now += (ll)x*k;
    ans = min(now, ans);
  }
  cout << ans << endl;
}

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

const long N = 100;
const long WHITE = 0;
const long GRAY = 1;
const long BLACK = 2;

long n, M[N + 1][N + 1];
long color[N + 1], d[N + 1], f[N + 1], tt;

void dfs_visit(long u){
	long v;
	color[u] = GRAY;
	d[u] = ++tt;
	for (long v = 1; v <= n; v++){
		if (M[u][v] == 0) continue;
		if (color[v] == WHITE){
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs(){
	for (long u = 1; u <= n; u++) color[u] = WHITE;
	tt = 0;

	for (long u = 1; u <= n; u++){
		if (color[u] == WHITE) dfs_visit(u);
	}
	for (long u = 1; u <= n; u++){
		cout << u << " " << d[u] << " " << f[u] << endl;
	}
}

int main(){
	long u, v, k;

	cin >> n;
	for (long i = 1; i <= n; i++){
		for (long j = 1; j <= n; j++){
			M[i][j] = 0;
		}
	}

	for (long i = 1; i <= n; i++){
		cin >> u >> k;
		for (long j = 1; j <= k; j++){
			cin >> v;
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}

Measured memory_bytes: 1240
#include<iostream>
using namespace std;
int main()
{
    int N, A_i;
    cin >> N;
    int A[N] = {0};
    while(cin>>A_i){
        A[A_i-1]++;
    }
    for (int i=0; i < N ; i++){
        cout << A[i] << endl;
    }
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a(k);
	for(int i = 0; i < k; i++) {
		cin >> a[i];
	}
	while (1) {
		bool ok = true;
		string s = to_string(n);
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < a.size(); j++) {
				if (s[i] == a[j] + '0') ok = false;
			}
		}
		if (ok) break;
		else n++;
	}
	cout << n << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
vector<pair<ll,ll>> vec[100000];
int main(){
  ll n;
  cin >> n;
  ll a[n+1];
  ll b[n+1];
  rep(i,n){
    cin >> a[i+1];
  }
  ll tmp;
  for(int i=n;i>0;i--){
    tmp=0;
    for(int j=2*i;j<=n;j+=i){
      tmp += b[j];
    }
    b[i] = (tmp+a[i])%2;
    //cout << tmp << " " << a[i] << endl;
  }
  ll sum=0;
  rep(i,n){
    sum += b[i+1];
  }
  cout << sum << endl;
  rep(i,n){
    if(b[i+1]){
      cout << i+1 << " ";
    }
    //cout << a[i+1] << " ";
  }
}


Measured memory_bytes: 6272
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int eu(int a, int b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	eu(a%b, b);
}

int main() {
	int n, k;
	cin >> n >> k;
	int maxl = 0, gcd = 1;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (i == 0)gcd = a;
		maxl = max(maxl, a);
		gcd = eu(gcd, a);
	}
	if (k <= maxl&&k%gcd == 0)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

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

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

bool c[10000000];
int main(){
    int s; cin >> s;
    rep(i,10000000) c[i] = false;
  int ans = 0;
  	while(1){
      ans++;
      if(c[s]){ break;}
      
      c[s] = true;
      if(s % 2) s = 3*s+1;
      else s = s / 2 ;
    }
  cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10616
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n=0,m=0;
int arr[100000];
int suf[100010];

int get(int l, int r)
{
	int res = suf[l];	
	res-=suf[r+1];
	return res;
}

bool check(int mm)
{
	int res=0;
	for (int i=0; i<n; i++)
	{
		auto it = lower_bound(arr, arr+n, mm-arr[i]);
		res+=(arr+n)-it;
	}
	return (res>=m);
}

void print(int mm)
{
	int res=0, Min=INT_MAX,sum=0;
	for (int i=0; i<n; i++)
	{
		auto it = lower_bound(arr, arr+n, mm-arr[i]);
		if (it!=arr+n)
		Min = min(Min, (*it)+arr[i]);
		res+=(arr+n)-it;
		sum+=suf[it-arr];
		sum+=((arr+n)-it)*arr[i];
	}
	sum-=(res-m)*Min;
	cout << sum << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i=0; i<n; i++)
	{
		cin >> arr[i];		
	}
	sort(arr, arr+n);
	int sm=0;
	for (int i=n-1; i>=0; i--)
	{
		sm+=arr[i];
		suf[i] = sm;
	}
	int ll = arr[0]*2, rr = arr[n-1]*2;
	while (ll<rr-1)
	{
		int mm = (ll+rr)/2;
		if (check(mm))
		{
			ll = mm;		
		}
		else
			rr = mm;
	}
	if (check(rr))
	{
		print(rr);
	}
	else
		print(ll);
	return 0;
}


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


int main()
{
	int c;
	string s = "No";
	cin >> c;
	if (c > 81)
	{
		cout << s << endl;
		return 0;
	}
	for (int i = 1; i <= 9; i++)
	{
		if (c % i == 0 && c / i <= 9)
		{
			s = "Yes";
			break;
		}
	}
	cout << s << endl;


}

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

#define ll long long

ll zbr_value, zbr_weight, W, N, w[111], v[111];
map <ll, ll> m;
vector <ll> lista;

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

    cin >> N >> W;
    for (int i = 0; i < N; i++)
    {
        cin >> w[i] >> v[i];
        zbr_value += v[i];
        zbr_weight += w[i];
    }

    m[zbr_weight] = zbr_value;

    for (int i = 0; i < N; i++)
    {
        lista.clear();
        for (map <ll, ll> :: iterator it = m.begin(); it != m.end(); it++)
        {
            bool b = 1;
            for (int j = 0; j < lista.size(); j++)
            {
                if (it -> first - w[i] == lista[j]) b = 0;
            }
            if (b)
            {
                if (m[it -> first - w[i]] == 0)
                {
                    m[it -> first - w[i]] = m[it -> first] - v[i];
                    lista.push_back(it -> first - w[i]);
                }
                else
                {
                    m[it -> first - w[i]] = max(m[it -> first - w[i]], m[it -> first] - v[i]);
                }
            }
        }
    }

    ll najveci = 0;

    for (map <ll, ll> :: iterator it = m.begin(); it != m.end(); it++)
    {
        if (it -> first <= W)
        {
            najveci = max(najveci, it -> second);
        }
    }

    cout << najveci;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}
//////////////

void solve() {
	int N;
	cin >> N;
	if (N == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int A, B;
		cin >> A >> B;
		cout << A + B << endl;
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


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

typedef long long i64;
typedef pair<i64,i64> P;

int main()
{
	int n;
	int a;

	cin >> n >> a;


	n = n % 500;
	
	if(n <= a)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 256
// 26/01/20 // 10:06 AM //

#include <bits/stdc++.h>

using namespace std;

const int MAXN = (int)(1e2) + 10;
const int MAXK = (int)(1e5) + 10;

int n, k;
int a[MAXN], memo[2][MAXK];

int solve(int p, int h){ // player, height

    //printf("solve(%d, %d) = %d\n", p, h, memo[p][h]);

    if(memo[p][h]!=-1) return memo[p][h];

    memo[p][h] = !p;

    for(int i=0; i<n; i++)
        if(h-a[i]>=0){
            if(p==0)
                memo[p][h] = min(memo[p][h], solve(1, h-a[i]));
            else
                memo[p][h] = max(memo[p][h], solve(0, h-a[i]));
        }

    return memo[p][h];
}

int solve_bottom_up(){

    for(int p=0; p<2; p++){
        for(int h=0; h<=k; h++){
            memo[p][h] = !p;

            for(int i=0; i<n; i++)
                if(h-a[i]>=0){
                    if(p==0)
                        memo[p][h] = min(memo[p][h], solve(1, h-a[i]));
                    else
                        memo[p][h] = max(memo[p][h], solve(0, h-a[i]));
                }
        }
    }

    return memo[0][k];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    memset(memo, -1, sizeof(memo));

    cin >> n >> k;
    for(int i=0; i<n; i++) cin >> a[i];
    //sort(a, a+n);

    cout << (solve_bottom_up()?"Second":"First") << endl;

    return 0;
}


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

bool isValid(int foot[2]) {
  const static int px[10] = {0,-1,0,1,-1,0,1,-1,0,1};
  return px[foot[1]] - px[foot[0]] >= 0;
}

const int INF = 1<<24;
string line;
int T[100001][2][2][10];

int solve() {
  if(line.size() <= 2) return 0;
  fill(T[0][0][0], T[100001][0][0], INF);
  int foot[2];
  foot[0] = line[0] - '0';
  foot[1] = line[1] - '0';
  if(isValid(foot)) T[2][1][0][foot[0]] = 0;
  foot[1] = line[0] - '0';
  foot[0] = line[1] - '0';
  if(isValid(foot)) T[2][0][0][foot[1]] = 0;

  for(int i = 3; i <= line.size(); ++i) {
    for(int j = 0; j < 2; ++j) {
      for(int k = 0; k < 2; ++k) {
	for(int l = 1; l <= 9; ++l) {
	  if(l == 5) continue;
	  foot[j] = line[i-1] - '0';
	  if(k == 0) {
	    foot[1-j] = line[i-2] - '0';
	    if(isValid(foot)) {
	      T[i][j][k][foot[1-j]] = min(T[i][j][k][foot[1-j]], T[i-1][1-j][0][l]);
	      T[i][j][k][foot[1-j]] = min(T[i][j][k][foot[1-j]], T[i-1][1-j][1][l]);
	    }
	  } else {
	    foot[1-j] = l;
	    if(isValid(foot)) {
	      T[i][j][k][l] = min(T[i][j][k][l], T[i-1][j][0][l]+1);
	      T[i][j][k][l] = min(T[i][j][k][l], T[i-1][j][1][l]+1);
	    }
	  }
	}
      }
    }
  }
  int res = INF;
  for(int i = 0; i < 2; ++i) {
    for(int j = 0; j < 2; ++j) {
      for(int l = 1; l <= 9; ++l) {
	if(l == 5) continue;
	res = min(res, T[line.size()][i][j][l]);
      }
    }
  }
  return res;
}

int main() {
  while(getline(cin, line) && line != "#") {
    cout << solve() << endl;
  }
}

Measured memory_bytes: 16000
N = int(input())

ret = [0] * (N + 1)

for x in range(1, N + 1) :
  if x * x > N : break
  for y in range(x, N + 1) :
    if x * x + y * y + x * y > N : break
    for z in range(y, N + 1) :
      if x * x + y * y + z * z + x * y + y * z + z * x > N : break
      n = x * x + y * y + z * z + x * y + y * z + z * x
      k = len(set([x, y, z]))
      if k == 1 :
        ret[n] += 1
      elif k == 2 :
        ret[n] += 3
      elif k == 3 :
        ret[n] += 6
        
for i in range(1, N + 1) :
  print(ret[i])

Measured memory_bytes: 68816
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std ;

#define MAXN 207

int n ;
string a[ MAXN ] ;

int f[ MAXN ][ MAXN ] ;

int used[ MAXN ] ;

bool dfs ( int vertex , int cl ) {
    used[ vertex ] = cl ;
    for ( int i = 0 ; i < n ; ++ i ) {
        if ( a[ vertex ][ i ] == '1' && used[ i ] == used[ vertex ] ) { return false ; }
        if ( a[ vertex ][ i ] == '1' && used[ i ] == 0 ) {
            bool ret = dfs ( i , 3 - cl ) ;
            if ( ret == false ) { return false ; }
        }
    }
    return true ;
}

void input ( ) {
    cin >> n ;
    for ( int i = 0 ; i < n ; ++ i ) {
        cin >> a[ i ] ;
    }
}

void solve ( ) {
    bool ret = dfs ( 0 , 1 ) ;
    if ( ret == false ) { cout << "-1\n" ; return ; }
    for ( int i = 0 ; i < n ; ++ i ) {
        for ( int j = 0 ; j < n ; ++ j ) {
            f[ i ][ j ] = 10000000 ;
        }
    }
    for ( int i = 0 ; i < n ; ++ i ) {
        f[ i ][ i ] = 0 ;
    }
    for ( int i = 0 ; i < n ; ++ i ) {
        for ( int j = 0 ; j < n ; ++ j ) {
            if ( a[ i ][ j ] == '1' ) { f[ i ][ j ] = 1 ; }
        }
    }
    for ( int k = 0 ; k < n ; ++ k ) {
        for ( int i = 0 ; i < n ; ++ i ) {
            for ( int j = 0 ; j < n ; ++ j ) {
                if ( f[ i ][ k ] + f[ k ][ j ] < f[ i ][ j ] ) {
                    f[ i ][ j ] = f[ i ][ k ] + f[ k ][ j ] ;
                }
            }
        }
    }
    int ans = 0 ;
    for ( int i = 0 ; i < n ; ++ i ) {
        for ( int j = 0 ; j < n ; ++ j ) {
            ans = max ( ans , f[ i ][ j ] ) ;
        }
    }
    cout << ans + 1 << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  
  if (a >= b){
    for (int i = 0;i < a;i++){
      cout << b;
    }
  }
  else{
    for (int i = 0;i < b;i++){
      cout << a;
    }
  }
  cout << endl;
}

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

int main(){
  int n,k;
  cin>>n>>k;
  int dislike[10] = {0};
  for(int i=0;i<k;i++){
    int x;
    cin>>x;
    dislike[x] = 1;
  }
  while(true){ 
    int temp = n;
    int flag = 0;
    while(temp != 0){
      int dig = temp%10;
      if(dislike[dig] == 1){
        flag = 1;
        break;
      }
      temp = temp/10;
    }
    if(flag == 0){
      cout<<n;
      break;
    }
    n++;
  }
  return 0;
}

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

const ll MOD = 1000000007;

ll fmemo[100002];
ll imemo[100002];
ll ifmemo[100002];

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

ll fact(ll n){
    if(n == 0) return 1;
    if(fmemo[n]) return fmemo[n];
    return fmemo[n] = n * fact(n - 1) % MOD;
}

ll ifact(ll n){
    if(n == 0) return 1;
    if(ifmemo[n]) return ifmemo[n];
    return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
}

ll com(ll n, ll k){
    if(k > n) return 0;
    if(k == n || k == 0) return 1;
    return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    for(ll i = 1; i <= 10000; i++){
        imemo[i] = modpow(i, MOD - 2);
    }
    for(int i = 1; i <= k; i++){
        cout << com(k - 1, i - 1) * com(n - k + 1, i) % MOD << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	int N;
	cin >> N;
	int M;
	cin >> M;

	vector<int> A(M);
	for (int i = 0; i < M; i++)
	{
		/* code */
		cin >> A[i];
		N -= A[i];
	}

	if (N < 0)
	{
		/* code */
		cout << "-1" << endl;
	}else{
		cout << N << endl;
	}
}

Measured memory_bytes: 3632
object Main {
        def main(args: Array[String]): Unit = {
            val sc = new java.util.Scanner(System.in)
            
            val n, c, k = sc.nextInt
            val ts = Array.fill(n)(sc.nextInt).sorted
            
            var start = 0
            var bus_count = 0
            for (i <- 0 until ts.size) {
                if (ts(i) - ts(start) > k) {
                    start = i
                    bus_count += 1
                } else if (i - start + 1 == c) {
                    start = i + 1
                    bus_count += 1
                }
            }
            if (start < ts.size) {
                bus_count += 1
            }
            
            println(bus_count)
        }
    }

Measured memory_bytes: 54696
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderBeginnerContest148
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = long.Parse(Console.ReadLine());
			if (input % 2 == 1)
			{
				Console.WriteLine("0");
				return;
			}

			long result = 0;
			var index = 1;
			while (input > 0)
			{
				result += (long)(input / 10);
				index++;
				input /= 5;
			}

			Console.WriteLine(result);
		}
	}
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String s;

			int input = Integer.parseInt(br.readLine());
			List<String> rightAngleList = new ArrayList<String>();

			for (int i = 1; i <= input; i++) {
				s = br.readLine();
				String[] num = s.split(" ");

				Integer[] side = convertArray(num);

				if (1 <= side[0] && side[0] <= 1000 && 1 <= side[1]
						&& side[1] <= 1000 && 1 <= side[2] && side[2] <= 1000) {

					Arrays.sort(side);

					if (side[2] * side[2] == side[1] * side[1] + side[0]
							* side[0]) {

						rightAngleList.add("YES");

					} else {
						rightAngleList.add("NO");
					}

				} else {
					break;
				}
			}

			String[] rightAngles = rightAngleList.toArray(new String[0]);

			for(String rightAngle : rightAngles){
				System.out.println(rightAngle);
			}


		} finally {
			br.close();
		}

	}

	public static Integer[] convertArray(String[] str) {

		List<Integer> list = new ArrayList<Integer>();

		for (String num : str) {

			list.add(Integer.parseInt(num));

		}

		return list.toArray(new Integer[0]);

	}

}

Measured memory_bytes: 22368
import { print } from 'util';

namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const [N, Q]: number[] = (await sc.getLine()).split(' ').map((x) => +x);
    const S = await sc.getLine();
    const l: number[] = [];
    const r: number[] = [];
    for (let i = 0; i < Q; i += 1) {
      const [t1, t2] = (await sc.getLine()).split(' ').map((x) => +x);
      l.push(t1);
      r.push(t2);
    }
    const t: number[] = Array(N + 1).fill(0);
    for (let i = 0; i < N; i += 1) {
      let c = 0;
      if (S.substr(i, 2) === 'AC') {
        c = 1;
      }
      t[i + 1] = t[i] + c;
    }

    for (let i = 0; i < Q; i += 1) {
      console.log(t[r[i] - 1] - t[l[i] - 1]);
    }

    sc.close();
  }

  solve();
}


Measured memory_bytes: 49568
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())

using namespace std;
typedef long long ll;


void solve(long long N, long long A, long long B){
  printf("%lld\n", min(N * A, B));
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(N, A, B);
  return 0;
}


Measured memory_bytes: 256
def nCr(n, r):
    import math
    # nCrのr>nは組み合わせが存在しないので0を返す
    # raiseすべきのこともあるかも
    if r > n:
        return 0
    return math.factorial(n) // ((math.factorial(n - r) * math.factorial(r)))

n = int(input())
s = input()
tr, tg, tb = 0,0,0
for i in range(n):
    if s[i] == "R":
        tr  += 1
    if s[i] == "G":
        tg  += 1
    if s[i] == "B":
        tb  += 1

total = tr*tg*tb
# same color
#total -= nCr(tr, 3)
#total -= nCr(tg, 3)
#total -= nCr(tb, 3)
#print(nCr(n, 3), nCr(tr, 3), nCr(tg, 3), nCr(tb, 3))
#print(total)
# cond 2
for i in range(1, n):
    for j in range(1, min(i, n-i-1) + 1):
        a,b,c = s[i-j], s[i], s[i+j]
        if a != b and b != c and a != c:
            total -= 1
print(total)

Measured memory_bytes: 73664
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

void solve() {
    int n;
    cin>>n;
    vector<vector<int>> dp(n+1,vector<int>(3));
    int a[3];
    REP(i,1,n) {
        cin>>a[0]>>a[1]>>a[2];
        REP(j,0,2) {
            REP(k,0,2) {
                if(j!=k) {
                    dp[i][j] = max(dp[i][j],a[j]+dp[i-1][k]);
                }
            }
        }
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]});
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define debug(V) rep(i, V.size()) cout << V[i] << " ";
const ll INF = 1LL << 60;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, m, n, t, r, k, w, l, ans, i, j;
string S, T;
vl A, B;
void solve() {
    B.pb(1);
    rep(i, n + 1) {
        if(B.back() == INF)
            B.pb(INF);
        else if(B.back() == -INF) {
            B.pb(-INF);
        } else {
            a = (B.back() - A[i]) * 2;
            if(a > 0)
                B.pb(min(INF, a));
            else
                B.pb(max(-INF, a));
        }
    }

    if(B.back() < 0) {
        cout << -1 << endl;
        return;
    }

    vl D, E(n + 3);

    E[n + 1] = 0;
    rrep(i, n + 1) { E[i] = A[i] + E[i + 1]; }

    rep(i, n + 1) { ans += min(E[i], B[i]); }

    /*debug(D);
    cout << endl;
    debug(E);
    cout << endl;*/

    cout << ans << endl;
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n + 1) {
        cin >> x;
        A.pb(x);
    }
    solve();
}

Measured memory_bytes: 5828
class SegmentTree():
    def __init__(self, size):
        self.size = 2**((size-1).bit_length())
        self.val = [0]*(self.size*2)
    
    def update(self, i, x):
        i += self.size
        self.val[i] = x
        
        while i > 0:
            i = i >> 1
            self.val[i] = self.val[2*i] + self.val[2*i+1]
    
    def query(self, l, r):
        l += self.size
        r += self.size

        l_sum = 0
        r_sum = 0

        while l < r:
            if l & 1:
                l_sum += self.val[l]
                l += 1
            l = l >> 1

            if r & 1:
                r -= 1
                r_sum += self.val[r]
            r = r >> 1

        return l_sum + r_sum

def convertAlphabetToNumber(s):
    return ord(s) - ord('a')

N = int(input())
S = input()
Q = int(input())
query = [input().split() for i in range(Q)]

for i in range(Q):
    query[i][0] = int(query[i][0])
    query[i][1] = int(query[i][1]) - 1
    if query[i][0] == 2:
        query[i][2] = int(query[i][2]) - 1

alphabet_position = [SegmentTree(N) for i in range(28)]

for i in range(N):
    num = convertAlphabetToNumber(S[i])
    alphabet_position[num].update(i, 1)

for i in range(Q):
    if query[i][0] == 1:
        for j in range(28):
            if j == convertAlphabetToNumber(query[i][2]):
                alphabet_position[j].update(query[i][1], 1)
            else:
                alphabet_position[j].update(query[i][1], 0)
    else:
        cnt = 0
        for j in range(28):
            if alphabet_position[j].query(query[i][1], query[i][2] + 1) > 0:
                cnt += 1
        print(cnt)

Measured memory_bytes: 313152
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn combo(n: i64, r: i64) -> i64 {
    let mut x = 1_i64;
    for i in 0..r {
        x *= n - i;
        x %= P;
        x *= pow(r - i, P - 2);
        x %= P;
    }
    x
}

fn main() {
    let (n, a, b) = read!(i64, i64, i64);

    let mut x = pow(2, n);
    let mut y = combo(n, a);
    y += combo(n, b);
    y += 1;
    y %= P;
    x += P - y;
    x %= P;

    println!("{}", x)
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	class data {
		String key;
		LinkedList<String> C = new LinkedList<String>();

		boolean equals(data t) {
			return t.key.equals(key);
		}
	}

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			LinkedList<String> used = new LinkedList<String>();

			data d[] = new data[n];
			for (int i = 0; i < n; i++) {
				String buffer = sc.next();
				buffer = buffer.replace(':', ' ').replace(',', ' ').replace(
						'.', ' ');
				Scanner bin = new Scanner(buffer);

				String k = bin.next();
				d[i] = new data();
				d[i].key = k;

				for (; bin.hasNext();) {
					String a = bin.next();
					d[i].C.add(a);
				}
			}

			for (int i = 0; i < d[0].C.size(); i++) {
				String are = d[0].C.get(i);

				int index = -1;

				for (int j = 0; j < n; j++) {
					if (d[j].key.equals(are)) {
						index = j;
						break;
					}
				}

				if (index == -1) {
					if(!used.contains(are)){
						used.add(are);
					}
				} else {
					for (String k : d[index].C) {
						if (!d[0].C.contains(k)) {
							d[0].C.add(k);
						}
					}
				}

			}
			System.out.println(used.size());
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B, C = mapint()
Ls = [int(input()) for _ in range(N)]
ans = 10**18
def dfs(a, b, c, idx, magic):
    global ans
    if idx==N:
        if a==0 or b==0 or c==0:
            return
        magic -= 30
        magic += abs(A-a)
        magic += abs(B-b)
        magic += abs(C-c)
        ans = min(ans, magic)
        return
    nx = Ls[idx]
    dfs(a+nx, b, c, idx+1, magic+10)
    dfs(a, b+nx, c, idx+1, magic+10)
    dfs(a, b, c+nx, idx+1, magic+10)
    dfs(a, b, c, idx+1, magic)

dfs(0, 0, 0, 0, 0)
print(ans)


Measured memory_bytes: 73612
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define INF (10000000000000)

struct edge {
	int from, to;
	ll cost;
} es[2000];

ll n, m;

ll res[1000];

int main(int argc, char **argv) {
	cin >> n >> m;
	REP(i, m) {
		cin >> es[i].from >> es[i].to >> es[i].cost;
		--es[i].from; --es[i].to;
	}
	REP(i, n) res[i] = INF;
	res[0] = 0;
	REP(i, n * 2) {
		bool f = false, fg = false;
		REP(j, m) {
			auto &e = es[j];
			ll c2 = res[e.from] - e.cost;
			if (res[e.to] > c2) {
				res[e.to] = c2;
				f = true;
				fg |= (e.to == n - 1);
			}
		}
		if (!f) break;
		if (i >= n - 1 && fg) {
			cout << "inf" << endl;
			return 0;
		}
	}
	cout << (-res[n - 1]) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e8
#define MOD 1000000007
typedef long long ll;

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

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

      vector<int> s;//訪れた頂点をメモ
      vector<int> ord(n+1,-1);
      int c = 1, l = 0;
      {
          int v = 1;
          while(ord[v] == -1){
              ord[v] = s.size();
              s.push_back(v);
              v = a[v-1];
          }
          c = s.size() - ord[v];
          l = ord[v];
      }
      if(k < l) cout << s[k] << endl;
      else{
          k -= l;
          k %= c;
          cout << s[l+k] << endl;
      }
      return 0; 
}


Measured memory_bytes: 5852
# -*- coding: utf-8 -*-

n,k,q = map(int, input().split())
l = []
for i in range(n):
    l.append(0)

for i in range(q):
    a = int(input())
    l[a-1] += 1


for i in l:
    if i + k - q <= 0:
        print('No')
    else:
        print('Yes')

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;

int main()
{
  int N, T; scanf("%d %d", &N, &T);
  vector<ll> BEG(N), END(N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &BEG[i]);
    END[i] = BEG[i] + T;
  }
  ll b = BEG[0], e = END[0];
  ll ans = 0;
  for (int i = 1; i < N; ++i) {
    if (b <= END[i] and e >= BEG[i]) {
      e = END[i];
    }
    else {
      ans += (e - b);
      b = BEG[i];
      e = END[i];
    }
  }
  ans += (e - b);
  printf("%lld\n", ans);
  return 0;
}


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

using ll =long long;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,m,ans=0; cin >> n;
    //ans = n-1;
    for (ll i=1; i*i<n; i++)
    {   
        if ((n-i)%i==0 && i < (n-i)/i) ans+=(n-i)/i;
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int main(){

    ll n; cin >> n;
    ll arr[n][3] = {0};
    for(ll i = 0; i < n; ++i){
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    }
    ll dp[n + 24][3] = {0};
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    for(ll i = 1; i < n; ++i){
        dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = arr[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] });
    return 0;
}


Measured memory_bytes: 8232
def main():
	N, K = map(int, input().split())
	xi = list(map(int, input().split()))
	ans = 10**9
	for l in range(len(xi)-K+1):
		r = l + K - 1
		lr_distance = abs(xi[r]-xi[l])
		this_ans = min(abs(xi[l]), abs(xi[r])) + lr_distance
		ans = min(ans, this_ans)
	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 62576