akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations

N = int(input())
shogens = []
for _ in range(N):
  a = int(input())
  s = [list(map(int, input().split())) for _ in range(a)]
  shogens.append(s)

ans = 0
i = N
mens = list(range(1, N+1))
while i > 0:
  mujun = True
  for honests_id in combinations(mens, i):
    mujun = False
    for h in honests_id:
      for x, y in shogens[h-1]:
        if y == 1 and not x in honests_id or y == 0 and x in honests_id:
          mujun = True
          break
      if mujun:
        break
    if not mujun: 
      break
  if not mujun:
    break
  i -= 1
print(i)

Measured memory_bytes: 3064
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a >> b;
	cout << (a > b * 2 ? a - b * 2 : 0) << '\n';
   return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
d = defaultdict(int)
for i in range(3):
  a = list(map(int,input().split()))
  for j in range(3):
    d[a[j]] = 3*i+j+1
f = [False for _ in range(10)]

N = int(input())
for _ in range(N):
  b = int(input())
  f[d[b]] = True
  
ans = False

for i in range(3):
  ans = ans or (f[3*i+1] and f[3*i+2] and f[3*i+3])
  ans = ans or (f[i+1] and f[i+4] and f[i+7])
  
ans = ans or (f[1] and f[5] and f[9])
ans = ans or (f[3] and f[5] and f[7])

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

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

using namespace std;
#define REP(i,n) for(int i = 0;i < n ;++i)

int tile[11][5];

int main()
{
  int h;

  while(cin >> h,h){
    REP(i,11)REP(j,5){
      tile[i][j] = -1;
    }
    REP(i,h)REP(j,5){
      cin >> tile[h-1-i][j];
    }
    int ans = 0;
    bool update = false;
    while(true){
      update = false;
      REP(it,11){
        bool t1 = tile[it][0] == tile[it][1] && tile[it][0] != -1; 
        bool t2 = tile[it][1] == tile[it][2] && tile[it][1] != -1; 
        bool t3 = tile[it][2] == tile[it][3] && tile[it][2] != -1; 
        bool t4 = tile[it][3] == tile[it][4] && tile[it][3] != -1; 
        bool y1 = t1 && t2;
        bool y2 = t2 && t3;
        bool y3 = t3 && t4;
        if(y1 && y2 && y3){
          ans += tile[it][0]*5;
          REP(i,5){
            tile[it][i]=-1;
          }
          update = true;
        }
        else if(y1 && y2 || y2 && y3){
          ans += tile[it][y3]*4;
          REP(i,4){
            tile[it][i + y3]=-1;
          }
          update = true;
        }
        else if(y1 || y2 || y3){
          ans += tile[it][2]*3;
          REP(i,3){
            tile[it][i + y2 + ((int)y3)*2] = -1;
          }
          update =true;
        }
      }
      REP(it,10){
        REP(i,5){
          if(tile[it][i] == -1){
            int itt = it;
            while(tile[++itt][i] == -1 && itt != 10);
            swap(tile[it][i],tile[itt][i]);
          }
        }
      }
    if(!update)break;
    }
    cout << ans << endl;
  }
}

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

int main(){
  int a,b;
  int ans;
  cin >> a >> b;
  if((a+b)>(a-b)&&(a+b)>(a*b)){
    ans = a+b;
  }else if((a*b)>(a-b)&&(a*b)>(a+b)){
    ans = a*b;
  }else{
  	ans = a-b;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a = input().split()
ast = int(a[0])
aen = int(a[1])
bst = int(a[2])
ben = int(a[3])
if ast > ben or bst > aen:
    print("0")
elif ast < bst and aen < ben:
    print(aen - bst)
elif ast < bst and aen > ben:
    print(ben - bst)
elif bst < ast and ben < aen:
    print(ben - ast)
elif bst < ast and ben > aen:
    print(aen - ast)
elif ast == bst and aen < ben:
    print(aen - ast)
elif ast == bst and aen > ben:
    print(ben - ast)
elif ast < bst and aen == ben:
    print(ben - bst)
elif ast > bst and aen == ben:
    print(aen - ast)
elif ast == bst and aen == ben:
    print(aen - ast)
else:
    print("0")


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

using namespace std;
#define BUF (1000)
#define ll long long 
#define INF (1000005)

int n;

typedef struct {
	int x;
	int y;	
}P;

P p[105];

#define BIN (500000)
int v[BIN];

int main(void){
	cin >> n;

	for(int i=1;i<=n;i++){
		cin >> p[i].x >> p[i].y;
	}	

	double th = 2*M_PI/BIN;
	double theta = 0;
	for(int i=0;i<BIN;i++){
		theta+=th;	
		double mx=-INF;
		int max_i=-1;
		for(int j=1;j<=n;j++){
			double tmp = p[j].x*cos(theta)+p[j].y*sin(theta) ;
			if(mx < tmp){
				mx = tmp;
				max_i = j;
			}
		}
		v[max_i]++;
	}

	for(int i=1;i<=n;i++){
		cout << (double)v[i]/(double)BIN << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

struct node{
    char val;
    int depth;
    vector<node> next;
};

node* getNode(node &cur, char c){
    for(int i = 0; i < cur.next.size(); i++){
        if(cur.next[i].val == c) return &(cur.next[i]);
    }
}

bool hasChar(node &cur, char c){
    for(int i = 0; i < cur.next.size(); i++){
        if(cur.next[i].val == c) return true;
    }
    return false;
}

int cnt;
vector<node> v;

void addNode(node &cur, char c){
    node n;
    cnt++;
    n.depth = cur.depth+1;
    n.val = c;
    cur.next.push_back(n);
}

ll L;
ll xo;

void dfs(node &cur){
    int s = cur.next.size();
    if(s == 1){
        for(int i = 0; i <= 62; i++){
            if(L-cur.depth & ((ll)1<<i)){
                xo ^= ((ll)1<<i);
                break;
            }
        }
    } 
    for(int i = 0; i < s; i++){
        dfs(cur.next[i]);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N >> L;
    node root;
    root.depth = 0;
    root.val = '0';
    for(int i = 0; i  < N; i++){
        node* cur = &root;
        string s;
        cin >> s;
        for(int j = 0; j < s.size(); j++){
            if(hasChar(*cur, s[j])){
                cur = getNode(*cur, s[j]);
            }else{
                addNode(*cur, s[j]);
                cur = getNode(*cur, s[j]);
            }
        }
    }
    dfs(root);
    if(xo == 0){
        cout << "Bob" << endl;
    }else{
        cout << "Alice" << endl;
    }
}

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

#define MAX 200000000
#define INF (1<<30)

int H,A[MAX];

void swap(int *x,int *y){
  int tmp;
  tmp=*x;
  *x=*y;
  *y=tmp;
}
void maxHeapify(int i){
  int l,r,largest;
  l=i*2;
  r=i*2+1;

  if(l<=H &&A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;

  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxHeapify(largest);
  }
}
int extract(){
  int maxv;
  if(H<1)return -INF;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}



void increaseKey(int i,int key){
  if(key<A[i])return;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i=i/2;

  }

}


void insert(int key){
  H++;
  A[H]=-INF;
  increaseKey(H,key);
}


int main(){
  int key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(com[0]=='e' && com[1]=='n')break;
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }else printf("%d\n",extract());

  }

  return 0;
  
}

Measured memory_bytes: 4692
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    while(true){
        CST(3);
        ll n;cin >> n;
        if(!n)break;
        vector<double> x(n),y(n),z(n),r(n);
        rep(i,n)cin >> x[i] >>y[i]>>z[i]>>r[i];
        vector<tuple<double,ll,ll>> v;
        rep(i,n){
            repl(j,i+1,n){
                double dx=abs(x[i]-x[j]),dy=abs(y[i]-y[j]),dz=abs(z[i]-z[j]);
                double dl=sqrt(dx*dx+dy*dy+dz*dz);
                double cost=max((double)0,dl-r[i]-r[j]);
                v.pb(tie(cost,i,j));
            }
        }
        sort(all(v));
        double ans=0;
        UnionFind uf(n);
        rep(i,v.size()){
            ll a=get<1>(v[i]),b=get<2>(v[i]);
            double cost=get<0>(v[i]);
            if(!uf.same(a,b)){
                ans+=cost;
                uf.merge(a,b);
            }
        }
        cout << ans <<endl;
    }
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define RP(i, f, t) for (int i = f; i < t; i++)
#define PR(i, f, t) for (int i = t - 1; i >= f; i--)
int main()
{
    char a;
    cin >> a;
    cout << char(a + 1) << endl;
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 200500;

int n, m;
vector < int > open[N];
vector < pil > close[N];
ll ans, t[N << 2], k[N << 2], dp[N];

inline void push(int v) {
	t[v << 1] += k[v];
	k[v << 1] += k[v];
	t[v << 1 | 1] += k[v];
	k[v << 1 | 1] += k[v];
	k[v] = 0;
}

void upd(int v, int l, int r, int pos) {
	if (l == r) {
		t[v] = dp[pos];
		return;
	}
	push(v);
	int mid = (l + r) >> 1;
	if (pos <= mid)
		upd(v << 1, l, mid, pos);
	else
		upd(v << 1 | 1, mid + 1, r, pos);
	t[v] = max(t[v << 1], t[v << 1 | 1]);
}

void upd(int v, int l, int r, int lx, int rx, ll val) {
	if (rx < l || r < lx)
		return;
	if (lx <= l && r <= rx) {
		t[v] += val;
		k[v] += val;
		return;
	}
	push(v);
	int mid = (l + r) >> 1;
	upd(v << 1, l, mid, lx, rx, val);
	upd(v << 1 | 1, mid + 1, r, lx, rx, val);
	t[v] = max(t[v << 1], t[v << 1 | 1]);
}

ll get(int v, int l, int r, int lx, int rx) {
	if (rx < l || r < lx)
		return -inf;
	if (lx <= l && r <= rx)
		return t[v];
	push(v);
	int mid = (l + r) >> 1;
	return max(get(v << 1, l, mid, lx, rx), get(v << 1 | 1, mid + 1, r, lx, rx));
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= m; i++) {
		int l, r;
		ll w;
		scanf("%d %d %lld", &l, &r, &w);
		open[l].pb(w);
		close[r].pb({l, w});
	}

	for (int i = 1; i <= n; i++) {
		for (auto j : open[i])
			upd(1, 0, n, 0, i - 1, j);
		dp[i] = get(1, 0, n, 0, i - 1);
		for (auto j : close[i])
			upd(1, 0, n, 0, j.F - 1, -j.S);
		upd(1, 0, n, i);
		ans = max(ans, dp[i]);
	}

	printf("%lld", ans);

	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 36224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int count = 0;
		for(int i = a; i <= b; i++) {
			String str = String.valueOf(i);
			if(str.charAt(0)==str.charAt(4)&&str.charAt(1)==str.charAt(3)) {
				count++;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int n, t;
int a[112345], ma[112345];
int dif[112345];

int main() {
	cin >> n >> t;
	REP(i, n) scanf("%d", a + i);
	
	copy(a, a + n, ma);
	for (int i = n - 1; i >= 0; i--) chmax(ma[i], ma[i + 1]);
	REP(i, n) dif[i] = ma[i] - a[i];
	
	int m = *max_element(dif, dif + n);
	
	cout << count(dif, dif + n, m) << endl;
	
	return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
/*mod逆元*/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;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    auto fn = divisor(n);
    int now = 1 , now2 = 0; //中央2つ
    for(auto x:fn){
        if(now*x==n){now2 = x; break;}
        else if(x*x==n){now = x; now2 = x; break;}
        now = x;
    }
    cout << now+now2-2 << endl;

    return 0;
}

Measured memory_bytes: 384
#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=700000;

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

int main(){
    ll x,y;cin>>x>>y;
    if(2*y-x<0||2*x-y<0||(2*y-x)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    combinit(inf);
    cout<<combi((x+y)/3,(2*y-x)/3,inf)<<endl;
}

Measured memory_bytes: 16768
import java.io.*;
import java.util.*;

public class  Main{
	static int mod=(int)1e9+7;
    public static void main(String[] args) throws Exception{
        //MScanner sc = new MScanner("chess.in");
        MScanner sc = new MScanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        pw.println((3*(sc.nextInt())+sc.nextInt())/2);
        pw.flush();
    }
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21204
// abc045_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  char c = 'a';
  string s1,s2,s3;
  int i1=0,i2=0,i3=0;
  cin>>s1>>s2>>s3;
  while(true) {
    if(s1.size() == i1 && c == 'a') {
      cout << "A" << endl;
      break;
    } else if(s2.size() == i2 && c == 'b') {
      cout << "B" << endl;
      break;
    } else if(s3.size() == i3 && c == 'c'){
      cout << "C" << endl;
      break;
    } else {
      if(c == 'a') {
        c = s1[i1];
        i1++;
      } else if(c == 'b') {
        c = s2[i2];
        i2++;
      } else {
        c = s3[i3];
        i3++;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


string s;
bool j = true;

int main() {
	
	cin >> s;
	rep(i, s.size()) {
		if (i % 2 == 0) {
			if (s[i] == 'L')j = false;
		}
		else {
			if (s[i] == 'R')j = false;
		}
	}
	if (j)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int res = 0;
  rep(i,a+1) {
    rep(j,b+1) {
      rep(k,c+1) {
        if(500*i + 100*j + 50*k == x) {
          res++;
        }
      }
    }
  }
  
  cout << res << endl;

}

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

int main() {
  double a, b, c, C;
  cin >> a >> b >> C;
  c = sqrt(a * a + b * b - 2 * a * b * cos(C * M_PI / 180));
  double S = a * b * sin(C * M_PI / 180) / 2;
  double L = a + b + c;
  double h = b * sin(C * M_PI / 180);
  cout << fixed << setprecision(4);
  cout << S << endl;
  cout << L << endl;
  cout << h << endl;
  return 0;
}



Measured memory_bytes: 3548
#include <string.h>
#include <iostream>
using namespace std;

int main()
{
	int rate[4800] = {0};
	int colorNum , i= 0;
	int varN = 0;
	int min = 0, max = 0, minN = 0;
	bool colorflag[8];
	memset(colorflag, false, 8);
	int countMax;
	cin >> countMax;
	/*while (cin >> rate[i]) {
		i++;
	}*/
	for (i = 0; i != countMax; i++) {
		cin >> rate[i];
	}
	
	for (int ci = 0; ci != countMax; ci++) {
		if (1 <= rate[ci] && rate[ci] <= 399) {
			colorflag[0] = true;
		}
		else if (400 <= rate[ci] && rate[ci] <= 799) {
			colorflag[1] = true;
		}
		else if (800 <= rate[ci] && rate[ci] <= 1199) {
			colorflag[2] = true;
		}
		else if (1200 <= rate[ci] && rate[ci] <= 1599) {
			colorflag[3] = true;
		}
		else if (1600 <= rate[ci] && rate[ci] <= 1999) {
			colorflag[4] = true;
		}
		else if (2000 <= rate[ci] && rate[ci] <= 2399) {
			colorflag[5] = true;
		}
		else if (2400 <= rate[ci] && rate[ci] <= 2799) {
			colorflag[6] = true;
		}
		else if (2800 <= rate[ci] && rate[ci] <= 3199) {
			colorflag[7] = true;
		}
		else if (3200 <= rate[ci] && rate[ci] <= 4800) {
			varN++;
		}
	}
	for (int ci = 0; ci < 8; ci++) {
		if (colorflag[ci] == true) {
			min++;
		}
		else {
			minN++;
		}
	}
	if (minN == 8) {
		min = 1;
		max = varN;
	}
	else {
		max = min + varN;
	}
	//max = (8 < max) ? 8 : max;
	cout << min << " " << max << endl;

    return 0;
}

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

typedef  long long int ll;
typedef  vector<int> vi;
#define  IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  pb push_back
#define  fn for(int i=0;i<n;i++)
#define  all(x) x.begin(), x.end()
#define  endl "\n"


void solve()
{
	// write your code here :
	long long  n,r;
	cin>>n>>r;
	if(n>=10)
		cout<<r;
	else 
		cout<<100*(10-n)+r;
	
}

int main()
{
	// IOS
 //    #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    freopen("output.txt","w",stdout);
 //    #endif
	// int t;
	// cin>>t;
	// while(t--)
	solve();
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int a[105];
    for(int i=0;i<N;i++)
        cin>>a[i];
        int first=1;
        for(int j=0;j<N;j++)
        {
            if(first)
                first=0;
            else
                cout<<" ";
            cout<<a[j];

        }
         cout<<endl;
    for(int i=1;i<N;i++)
    {
        int f=1;

        int v=a[i];
        int j;
        j=i-1;
        while(j>=0&&a[j]>v)
        {
            a[j+1]=a[j];
            j--;
            a[j+1]=v;
        }
        for(int i=0;i<N;i++)
        {
            if(f)
                f=0;
            else
                cout<<" ";
            cout<<a[i];

        }
        cout<<endl;


    }

        return 0;

}

Measured memory_bytes: 3096
s = input()
res = 0
s = s[:-1]
if len(s) % 2 != 0:
    s = s[:-1]


for i in range(len(s) // 2):
    f = True
    for j in range(len(s) // 2):
        if s[j] != s[len(s) // 2 + j]:
            f = False
    if f:
        break

    s = s[:-2]

print(len(s))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    ll x = sx, y = sy;
    for(; y < ty; ++y){
        cout << 'U';
    }
    for(; x < tx; ++x){
        cout << 'R';
    }
    for(; y > sy; --y){
        cout << 'D';
    }
    for(; x > sx; --x){
        cout << 'L';
    }

    cout << 'L';
    x--;
    
    for(; y < ty + 1; ++y){
        cout << 'U';
    }
    for(; x < tx; ++x){
        cout << 'R';
    }
    cout << 'D';
    y--;

    cout << 'R';
    x++;
    for(; y >= sy; --y){
        cout << 'D';
    }
    for(; x > sx; --x){
        cout << 'L';
    }
    cout << 'U';
    y++;

    cout << endl;
    return 0;
}


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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===




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

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

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		if (h[i] >= K) ++ans;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll gcd(ll x,ll y){
  if(x%y==0)return y;
  else return gcd(y,x%y);
}
struct edge{
  int to;
  ll cost;
};
vector<edge>G[100010];
ll dist[100010];
void dfs(int v,int p,ll d){
  dist[v]=d;
  for(auto g:G[v]){
    if(g.to==p)continue;
    dfs(g.to,v,d+g.cost);
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  int n;
  cin >> n;
  rep(i,n-1){
    int a,b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back(edge{b,c});
    G[b].push_back(edge{a,c});
  }
  int q,k;
  cin >> q >> k;
  k--;
  dfs(k,-1,0);
  rep(i,q){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    cout << dist[x]+dist[y] << endl;
  }
    
}


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

typedef long long ll;

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

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];

  int S=0;
  rep(i,n) S += d[i];
  S *= S;
  rep(i,n) S -= d[i]*d[i];
  S /= 2;

  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen

using namespace std;

typedef pair<int, int> P;

struct BUTTON{
	P start, end;
	string link_name;
};	

struct PAGE{
	string name;
	int link_num;
	vector <BUTTON> link;
};		
	

int main()
{
	const string action[] = { "click", "show", "back", "forward" };
//	cut here before submit 
//	freopen ("testcase.distortedlove", "r", stdin );
	int n;

	while (cin >> n && n ){
		int W, H;
		cin >> W >> H;
		vector<PAGE> page(n);

		for (int i = 0; i < n; ++i ){
			int num = 0;
			cin >> page[i].name >> num;
			page[i].link_num = num;
			page[i].link.resize(num );
			for (int j = 0; j < num; ++j ){
				cin >> page[i].link[j].start.first;
				cin >> page[i].link[j].start.second;
				cin >> page[i].link[j].end.first;
				cin >> page[i].link[j].end.second;
				cin >> page[i].link[j].link_name;
			} // end for
		} // end for

		vector <int> buffer (10500, -1 );
		int curr_page = 0;	// ツ個サツ催敖づ個ペツーツジ
		int pointer = 0;
		buffer[pointer] = curr_page;
		int m;
		cin >> m;

		for (int i = 0; i < m; ++i ){
			string com = "";
			cin >> com;
			int cw, ch;
			if (com == action[0] ){	// "click"
				cin >> cw >> ch;
				int curr = buffer[pointer];
				string next_page = "";	
				for (int j = 0; j < page[curr].link_num; ++j ){
					if ( page[curr].link[j].start.first <= cw 
					&&   cw <= page[curr].link[j].end.first
					&&   page[curr].link[j].start.second <= ch 
					&& ch <= page[curr].link[j].end.second ){
						next_page = page[curr].link[j].link_name;
						break;
					} // end if
				} // end for
				if (!next_page.empty() ){
					for (int j = pointer + 1; j < buffer.size(); ++j ){
						buffer[j] = -1;
					} // end for
					for (int j = 0; j < n; ++j ){
						if (next_page == page[j].name ){
							++pointer;
							buffer[pointer] = j;
							break;
						} // end fi
					} // end for
				} // end if
			}else
			if (com == action[1] ){	// "show"
				cout << page[buffer[pointer]].name << endl;
			}else
			if (com == action[2] ){	// "back"
				if (pointer > 0 ){
					--pointer;
				} // end if
			}else{				// "forward"
				if (buffer[pointer+1] != -1 ){
					++pointer;
				} // end if
			} // end if
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use proconio::{fastout, input, marker::Bytes, marker::Chars, marker::Isize1, marker::Usize1};
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

#[fastout]
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let t = sc.read_chars();
    if t.len() == 2 && t[0] == t[1] {
        println!("1 2");
        return;
    }
    for i in 0..26 {
        let c = ('a' as u8 + i) as char;
        let s = t
            .windows(3)
            .enumerate()
            .filter(|&(i, w)| w.iter().filter(|&x| *x == c).count() > 1)
            .collect_vec();
        if s.len() > 0 {
            println!("{} {}", s[0].0 + 1, s[0].0 + 3);
            return;
        }
    }
    println!("-1 -1");
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2712
import java.util.Scanner;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int i = 0;
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double S = r * r * 3.141592653589;
        double l = 2 * r * 3.141592653589;
        System.out.println(String.format("%.6f", S) +" "+ String.format("%.6f", l));
    }
}


Measured memory_bytes: 28192
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstdio>
using namespace std;

/*
 * intput:
5 100
p1 150
p2 80
p3 200
p4 350
p5 20
 * output:
p2 180
p5 400
p1 450
p3 550
p4 800
 */
int main() {
    int ret = 0;
    // queue<pair<char*, int>> q;
    queue<pair<string, int> > q;

    int n, quantum, v;
    string name;
    scanf("%d", &n);
    scanf("%d", &quantum);
    for(int i = 0; i < n; i++) {
        // char name[100];
        cin >> name >> v;
        // scanf("%s", name);
        // scanf("%d", &quantum);
        q.push(make_pair(name, v));
    }

    // printf("\n\n");
    // // pair<char*, int> x;
    // pair<string, int> x;
    // for(int i = 0; i < n; i++) {
    //     x = q.front(); q.pop();
    //     // printf("%s, %d\n", x.first, x.second);
    //     cout << x.first << ", " << x.second << endl;
    // }

    int elaps = 0;
    int t = 0;
    pair<string, int> u;
    while(!q.empty()) {
        u = q.front(); q.pop();
        t = min(u.second, quantum);
        u.second -= t;
        elaps += t;
        if(u.second > 0) {
            q.push(u);
        } else {
            // printf("%s %d\n", u.first, elaps);
            cout << u.first << " " << elaps << endl;
        }
    }

    return ret;
}



Measured memory_bytes: 6372
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
vector<vector<int>> G;
vector<int> vis, S;

void dfs(int cur = 0) {
    for(int v: G[cur]) {
        if(vis[v] == 0){
            vis[v] = 1;
            S[v] = S[cur] ^ 1;
            dfs(v);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, M;
    cin >> N >> M;
    G.resize(N);
    S.resize(N);
    vis.assign(N, 0);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    vis[0] = 1;
    dfs();
    
    bool ok = true;
    rep(i, N){
        for(int v: G[i]){
            if((S[i] ^ S[v]) == 0){
                ok = false;
            }
        }
    }
    
    ll ones = 0, zeros = 0;
    rep(i, N){
        if(S[i] == 0) zeros++;
        else ones++;
    }
    
    if(ok){
        output(ones * zeros - M);
    }
    else {
        output(N * (N - 1) / 2 - M);
    }
    
    
    return 0;
}


Measured memory_bytes: 6784
N = int(input())
INF = 10**9

M = [[-1 for i in range(N)] for j in range(N)]
for i in range(N):
  u, k, *vs = list(map(int, input().split()))
  for j in range(k):
    v, c = vs[2*j], vs[2*j+1]
    M[u][v] = c

d = [INF for i in range(N)]
d[0] = 0
p = [-1 for i in range(N)]
mst = [False for i in range(N)]

while True:
  min_w = INF
  for i in range(N):
    if not mst[i] and d[i] < min_w:
      min_w = d[i]
      u = i
  if min_w == INF:
    break
  mst[u] = True
  for v in range(N):
    if M[u][v] != -1 and M[u][v] + d[u] < d[v]:
      d[v] = M[u][v] + d[u]
      p[v] = u

for i in range(N):
  print(i, d[i])



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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 3000;

void solve() {
  int r, g, b, n; scanf("%d%d%d%d", &r, &g, &b, &n);
  int ans = 0;
  for (int i = 0; i <= N; ++i) {
    if (i*r > n) break;
    for (int j = 0; j <= N; ++j) {
      if (i*r+j*g > n) break;
      if ((n-i*r-j*g)%b) continue;
      ++ans;
    }
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3788
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	static void solver() {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			if (n == 0)
				return;
			String[] s = new String[n];
			for (int i = 0; i < n; i++) {
				s[i] = sc.next();
			}
			int bit = (1 << n) - 1;
			boolean[] unvalid = new boolean[n];
			for (int i = 0; i < n; i++) {
				if (((bit >> i) & 1) == 0)
					continue;
				for (int j = 0; j < n; j++) {
					if (i == j)
						continue;
					if (((bit >> j) & 1) == 0)
						continue;
					out: for (int k = 0; k < s[j].length(); k++) {
						if (s[i].length() > s[j].length())
							continue;
						if (k + s[i].length() > s[j].length())
							continue;
						String sj = s[j].substring(k, k + s[i].length());
						if (sj.equals(s[i])) {
							bit = ~((~(bit)) | (1 << i));
							break out;
						}
					}
				}
			}
			memo = new int[1 << n][n];
			for (int i = 0; i < memo.length; i++) {
				for (int j = 0; j < memo[0].length; j++) {
					memo[i][j] = -1;
				}
			}
			int min = Integer.MAX_VALUE/4;
			for (int i = 0; i < n; i++) {
				if (((bit >> i) & 1) == 1) {
					int d = ~((~bit) | (1 << i));
					min = Math.min(min, dp(d, i, n, unvalid, s));
				}
			}
			System.out.println(min);
		}
	}

	static int[][] memo;

	// state:0 indexed num is used
	// 1 indexed num is unused
	// state + tail ??? ????°????
	static int dp(int state, int tail, int n, boolean[] unvalid, String[] s) {
		if (Integer.bitCount(state) == 0)
			return s[tail].length();
		if (memo[state][tail] != -1) {
			return memo[state][tail];
		}
		int min = Integer.MAX_VALUE/4;
		for (int i = 0; i < n; i++) {
			if ((((state >> i) & 1) == 1) && (!unvalid[i])) {
				int bit = ~((~state) | (1 << i));
				min = Math.min(min, dp(bit, i, n, unvalid, s) - same_length(s[i], s[tail]) + s[tail].length());
			}
		}
		memo[state][tail] = min;
		return min;
	}

	static int same_length(String bottom, String tail) {
		int max = 0;
		for (int i = 0; i < bottom.length(); i++) {
			int add = 0;
			while (bottom.charAt(i + add) == tail.charAt(add)) {
				if (i + add == bottom.length() - 1) {
					max = Math.max(add + 1, max);
					break;
				} else if (add == tail.length() - 1) {
					break;
				} else {
					add++;
				}
			}
		}
		return max;
	}

	static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 69064
#include<iostream>
#include<climits>
int check(int*,int);
int n, k;
int main(){
  std::cin >> n >> k;
  int W[n];
  for(int i=0; i<n; i++) std::cin >> W[i];
  int l=0, r=INT_MAX, m;     // solve
  while(r-l>1){              // *
    m = (r + l) / 2;         // *
    int v = check(W, m);     // *
    v >= n ? r = m : l = m;  // *
  }                          // end
  std::cout << r << std::endl;
  return 0;
}
int check(int *W,int p){
  int i=0;
  for(int j=0; j<k; j++){
    int s=0;
    while(s+W[i] <= p){
      s += W[i];
      i++;
      if(i == n) return n;
    }
  }
  return i;
}

Measured memory_bytes: 3476
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

const int N = 10;

int n, m, k, u, ans = 0, p[N];
vector<int> ve[N];

bool check(int msk)
{
    for (int i = 0; i < n; i++)
    {
        int cur = 0;
        for (int &v : ve[i])
            cur ^= (msk >> v & 1);
        if (cur != p[i])
            return false;
    }
    return true;
}

int main()
{
    cin >> m >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> k;
        while (k--)
        {
            cin >> u;
            ve[i].push_back(u - 1);
        }
    }
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int msk = 0; msk < (1 << m); msk++)
        if (check(msk))
            ans++;
    cout << ans;
}


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

B = []

def createList(B,k):
    tmpB = []
    if k == 0:
        tmpB.append([A[k]-1])
        tmpB.append([A[k]])
        tmpB.append([A[k]+1])
    else:
        for b in B:
            b.append(A[k]-1)
            tmpB.append(b.copy())
            b.pop()
            b.append(A[k])
            tmpB.append(b.copy())
            b.pop()
            b.append(A[k]+1)
            tmpB.append(b.copy())
            b.pop()
    return tmpB

for n in range(N):
    B = createList(B,n)

count = 0
for b in B:
    for _ in b:
        if _ % 2 == 0:
            count += 1
            break

print(count)


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


using namespace std;


using ll = long long;


vector<bool> is_prime;


void eratos(ll n) {
    is_prime.resize(n, true);

    is_prime[0] = is_prime[1] = false;
    for (ll i = 2; i * i < n; i++) {
        if (is_prime[i]) {
            ll j = i + i;
            while (j <= n) {
                is_prime[j] = false;
                j += i;
            }
        }
    }
}


void prime_factorization(vector<pair<ll, ll>> &res, ll x) {
    for (ll p = 2; p * p <= x; p++) {
        if (x % p != 0) {
            continue;
        }

        ll num = 0;
        while (x % p == 0) {
            ++num;
            x /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (x != 1) {
        res.push_back(make_pair(x, 1));
    }
}


int main() {
    ll A, B;
    cin >> A >> B;

    // eratos(min(A, B));
    // is_prime[1] = true;

    vector<pair<ll, ll>> pfA, pfB;
    prime_factorization(pfA, A);
    prime_factorization(pfB, B);

    ll ans = 0;
    sort(pfB.begin(), pfB.end(), [](auto &l, auto &r) { return l.first < r.first; });
    for (auto p : pfA) {
        // cout << p.first << endl;
        if (binary_search(pfB.begin(), pfB.end(), p, [](auto l, auto r) { return l.first < r.first; }))
            ans++;
    }
    cout << ++ans << endl;
}


Measured memory_bytes: 764
let readInt () = stdin.ReadLine() |> int
let choice ok ng bool = if bool then ok else ng

()
|> readInt
|> fun x ->
    x
    |> string
    |> (fun f -> f.ToCharArray())
    |> Array.map string
    |> Array.sumBy int
    |> (%) x
    |> (=) 0
|> choice "Yes" "No"
|> printfn "%s"


Measured memory_bytes: 29732
P = 10 ** 9 + 7
N, K = map(int, input().split())

L = N + 1  # 数列の長さ 

count = 0
table = [i for i in range(N + 1)]  # 0 ~ Nまでの数列

cusum = [0] * (L + 1)

for i in range(L):
  cusum[i + 1] = cusum[i] + table[i]

while K <= L:
  # K個選んだときの最大値 - 最小値 + 1
  count += (cusum[L] - cusum[L - K]) - cusum[K] + 1
  count %= P
  K += 1

print(count)


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


int N;
int C;

int A[404];
int B[404];
int X[400];

ll MOD = 1000000007;

// (i, j) => pow(i, j) or i ^ j 
ll ppow[404][404];

// (i, 0) => 0
// (i, j) => i^0 + i^1 + ... + i^(j-1)
ll ppows[404][404];

ll ans;

// (N, C)
ll dp[404][404];


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

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

    ppow[0][0] = 1;

    for (int i = 1; i <= 400; i++) {
        ppow[i][0] = 1;
        for (int j = 0; j < 400; ++j) {
            (ppow[i][j+1] = ppow[i][j] * i) %= MOD;
        }
    }

    for (int i = 0; i < 401; ++i) {
        for (int j = 0; j < 401; ++j) {
            (ppows[i+1][j] = ppows[i][j] + ppow[i][j]) %= MOD;
        }
    }
 
    dp[0][0] = 1;

    for (int i = 0; i < N; ++i) {
        for (int x = 0; x < C+1; ++x) {
            for (int y = 0; x+y <= C; y++) {
                ll p = (ppows[B[i]+1][y] - ppows[A[i]][y]) % MOD;

                if (p < 0) {
                    p += MOD;
                }

                (dp[i+1][x+y] += dp[i][x] * p) %= MOD;
            }
        }
    }
    cout << dp[N][C] << endl;

    //for (int i = 0; i < 5; ++i) {
    //    for (int j = 0; j < 7; ++j) {
    //        cout << ppow[i][j] << " ";
    //    }
    //    cout << endl;
    //}
    //cout << endl;

    //for (int i = 0; i < 5; ++i) {
    //    for (int j = 0; j < 7; ++j) {
    //        cout << ppows[i][j] << " ";
    //    }
    //    cout << endl;
    //}

    //for (int i = 0; i < N+1; ++i) {
    //    for (int x = 0; x < C+1; ++x) {
    //        cout << dp[i][x] << " ";
    //    }
    //    cout << endl;
    //}

    return 0;
}


Measured memory_bytes: 4096