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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define MOD 1000000007
#define IINF INT_MAX
#define INF 1LL << 30

ll modPow(ll x, ll a){
    if(a == 1) return x;
    if(a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return (t * t) % MOD;
}

ll modInv(ll x){
    return modPow(x, MOD - 2);
}

ll modPerm(ll n, ll k){
    ll ret = 1;
    for(int i = 0; i < k; i++){
        ret = (ret * (n - i)) % MOD;
    }
    return ret;
}

ll modComb(ll n, ll k){
    ll a, b;
    a = modPerm(n, k);
    b = modPerm(k, k);
    return (a * modInv(b)) % MOD;
}

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

    for(int i = 1; i <= k; i++){
        cout << modComb(n - k + 1, i) * modComb(k - 1, i - 1) % MOD << endl;
    }

    return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int dp[2005][2005];    // dp[i][j]: 白をi個、黒をj個、一番左に持ってくる操作の最小回数
int aa[2005][2005];    // aa[i][j]: i番目(0-indexed)の白より左側に0-j番目の黒が何個あるか
int bb[2005][2005];    // bb[i][j]: i番目(0-indexed)の黒より左側に0-j番目の白が何個あるか

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> a(n), b(n), pa(n), pb(n);
    vector<int> aposi(n), bposi(n);
    int i, j;
    int cnta=0, cntb=0;
    for(i=0; i<n*2; i++) {
        char str[3]={0};
        scanf("%s", str);
        int tmp;
        scanf("%d", &tmp);
        if(str[0]=='W') {
            a[cnta]=tmp-1;
            pa[tmp-1]=cnta;
            aposi[cnta]=i;
            cnta++;
        }
        else {
            b[cntb]=tmp-1;
            pb[tmp-1]=cntb;
            bposi[cntb]=i;
            cntb++;
        }
    }
    assert(cnta==n);
    assert(cntb==n);

    {
        set<int> za;
        for(i=0; i<=n; i++) {
            vector<int> va;
            copy( za.begin(), za.end(), back_inserter( va ));

            for(j=0; j<n; j++) {
                bb[j][i] = lower_bound( va.begin(), va.end(), bposi[pb[j]] ) - va.begin();
            }
            if(i<n) {
                za.insert(aposi[pa[i]]);
            }
        }
    }

    {
        set<int> zb;
        for(i=0; i<=n; i++) {
            vector<int> vb;
            copy( zb.begin(), zb.end(), back_inserter( vb ));

            for(j=0; j<n; j++) {
                aa[j][i] = lower_bound( vb.begin(), vb.end(), aposi[pa[j]] ) - vb.begin();
            }
            if(i<n) {
                zb.insert(bposi[pb[i]]);
            }
        }
    }

    for(i=0; i<=n; i++) {
        for(j=0; j<=n; j++) {
            if(i==0 && j==0) {
                dp[i][j]=0;
            }
            else {
                dp[i][j]=INF;
                if(i>0) {
                    dp[i][j]=MIN(dp[i][j], dp[i-1][j] + aposi[pa[i-1]] - aa[i-1][j] - pa[i-1]);
                }
                if(j>0) {
                    dp[i][j]=MIN(dp[i][j], dp[i][j-1] + bposi[pb[j-1]] - bb[j-1][i] - pb[j-1]);
                }
            }
        }
    }

    int tentou=0;
    for(i=0; i<n; i++) {
        for(j=i+1; j<n; j++) {
            if(a[i]>a[j]) tentou++;
            if(b[i]>b[j]) tentou++;
        }
    }
    printf("%d\n", dp[n][n]+tentou);

    return 0;
}



Measured memory_bytes: 47488
s =str(input())
z = int(s[-1])
if z == 2 or z == 4 or z == 5 or z == 7 or z == 9:
	print("hon")
elif z == 0 or z == 1 or z == 6 or z == 8:
    print("pon")
else:
	print("bon")

Measured memory_bytes: 9104
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int debt = 100000;
	for (int i = 0; i < n; i++) {
		debt = debt * 1.05;
		if (debt % 1000)
			debt += 1000;
		debt -= debt % 1000;
	}
	cout << debt << endl;

	return 0;
}

Measured memory_bytes: 3000
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;




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

	int N, M;
	cin >> N >> M;
	cout << M * (M - 1) / 2 + N * (N - 1) / 2 << 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;

int main(void){
    int n;
    cin >> n;
    vector<int> cnt(4);
    string ja[4] = {"AC", "WA", "TLE", "RE"};
    rep(i, n){
        string s;
        cin >> s;
        rep(j, 4)
            if(s == ja[j]) ++cnt[j];
    }
    rep(i, 4) cout << ja[i] << " x " << cnt[i] << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

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

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,k;
int a[500005],ans[500005];
pii val[1100000],pl[500005];
priority_queue<int> q;

void build(int id,int l,int r){
	if(l==r) return (void)(val[id]=mp(a[l],l));
	int mid=(l+r)/2;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	val[id]=max(val[id<<1],val[id<<1|1]);
}

void change(int id,int l,int r,int x,int c){
	if(l==r) return (void)(val[id]=mp(c,l));
	int mid=(l+r)/2;
	if(x<=mid) change(id<<1,l,mid,x,c);
	else change(id<<1|1,mid+1,r,x,c);
	val[id]=max(val[id<<1],val[id<<1|1]);
}

pii query(int id,int l,int r,int ql,int qr){
	if(l==ql&&r==qr) return val[id];
	int mid=(l+r)/2;
	if(qr<=mid) return query(id<<1,l,mid,ql,qr);
	else if(ql>mid) return query(id<<1|1,mid+1,r,ql,qr);
	else return max(query(id<<1,l,mid,ql,mid),query(id<<1|1,mid+1,r,mid+1,qr));
}

void update(int x){
	pl[x]=query(1,1,n,(x-1)*k+1,min(n,x*k));
	if(pl[x].fi>0&&query(1,1,n,max(1,pl[x].se-k+1),min(n,pl[x].se+k-1))==pl[x]) q.push(pl[x].se);
//	cout<<"update "<<x<<' '<<pl[x].fi<<' '<<pl[x].se<<endl;
}

int main(){
	n=readint(); k=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	build(1,1,n);
	for(int i=1;i<=n;i+=k) update((i-1)/k+1);
	for(int i=n;i>=1;i--){
		while(q.top()!=pl[(q.top()-1)/k+1].se||pl[(q.top()-1)/k+1].fi==0) q.pop();
//		cout<<"getans "<<i<<' '<<q.top()<<endl;
		ans[q.top()]=i;
		change(1,1,n,q.top(),0);
		int bl=(q.top()-1)/k+1;
		q.pop();
		update(bl);
		if(bl>1) update(bl-1);
		if(bl<(n-1)/k+1) update(bl+1);
	}
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 22000
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p = Mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[200000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += mod_pow(i, Mod - 2, Mod);
		sum %= Mod;
	}
	int fac = 1;
	for (int i = 1; i <= n; i++) {
		fac *= i;
		fac %= Mod;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += a[i] * fac%Mod*sum%Mod;
		ans %= Mod;
		sum -= mod_pow(n - i, Mod - 2);
		sum %= Mod;
		sum += Mod;
		sum %= Mod;
		sum += mod_pow(i + 2, Mod - 2);
		sum %= Mod;
	}
	cout << (ans + Mod) % Mod << endl;
}

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

int main(void)
{
    string s;
    cin >> s;
    const int fav_num = 753;
    int ans = 1000;
    rep(i, s.size() - 2)
    {
        int x = 0;
        rep(j, 3)
        {
            x = 10*x + (s[i + j] - '0');
        }
        ans = min(ans, abs(fav_num - x));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;

public class Main{
	double EPS = 1.0e-08;

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [][] data = new int[2][2];
			for(int i = 0; i < 2; i++){
				for(int j = 0; j < 2; j++){
					data[i][j] = sc.nextInt()-1;
				}
			}
			int min = 1 << 24;
			for(int i = 1; i <= n; i++){
				
				int sum = 0;
				for(int j = 0; j < 2; j++){
					int pos1 = data[j][0];
					int x1 = pos1 % i;
					int y1 = pos1 / i;
					int pos2 = data[j][1];
					int x2 = pos2 % i;
					int y2 = pos2 / i;
					sum += Math.abs(x1 - x2) + Math.abs(y1 - y2);
				}
				min = Math.min(min, sum);
			}
			System.out.println(min);
		}
	}
	
	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 17360
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

ll dp[220][120000];
int s[120000];
int main(){
	int n,x;scanf("%d%d",&n,&x);
	rep(i,n){
		scanf("%d",&s[i]);
	}
	sort(s,s+n,greater<>());
	dp[0][x]=1;
	rep(i,n)rep(j,120000){
		if(dp[i][j]==0)continue;
		(dp[i+1][j%s[i]]+=dp[i][j])%=MOD;
		(dp[i+1][j]+=dp[i][j]*(n-i-1)%MOD)%=MOD;
	}
	ll ans=0;
	rep(i,120000){
		(ans+=i*dp[n][i]%MOD)%=MOD;
	}
	cout<<ans<<endl;
}

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

int main(){
  int N, y;
  int all;
  string X;
  vector<string> name;
  vector<int> time;
  
  cin >> N;
  
  for(int i=0; i < N; i++)
  {
    cin >> X >> y;
  	name.push_back(X);
  	time.push_back(y);
  }
  
  cin >> X;
  
  auto iter = find(name.begin(), name.end(), X);
  auto index = distance(name.begin(), iter);
  
  int  sum = accumulate(time.begin() + index + 1, time.end(), 0);
  
  cout << sum << endl;
   
}

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

b_p = [2**(i+2)-3 for i in range(N+1)]
p = [2**(i+1)-1 for i in range(N+1)]


def cal_paty(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= b_p[N-1] + 1:
        p_num = cal_paty(N-1, X-1)
        return p_num
    else:
        p_num = p[N-1] + 1
        p_num += cal_paty(N-1, X-(2 + b_p[N-1]))
        return p_num

print(cal_paty(N, X))


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int xdif = abs(x1 - x2), ydif = abs(y1 - y2);
  if(x1 >= x2 && y1 >= y2){
    cout << x2 + ydif << " " << y2 - xdif  << " " << x1 + ydif << " " << y1 - xdif <<endl;
  } else if(x1 >= x2 && y1 <= y2){
    cout << x2 - ydif << " " << y2 - xdif << " " << x1 - ydif  << " " << y1 - xdif <<endl;
  } else if(x1 <= x2 && y1 >= y2){
    cout << x2 + ydif << " " << y2 + xdif << " " << x1 + ydif << " " << y1 + xdif <<endl;
  } else if(x1 <= x2 && y1 <= y2 ){
    cout << x2 - ydif << " " << y2 + xdif << " " << x1 - ydif << " " << y1 + xdif <<endl;
  }
}

Measured memory_bytes: 3636
N = int(input())
X = list(map(int, input().split()))
X.append(0)
load = 0
now = 0
for i in range(N + 1):
  load += abs(X[i] - now)
  now = X[i]
  
#print(load)  

now = 0
for i in range(N):
  if now <= X[i] <= X[i + 1]:
    print(load)
  elif X[i + 1] <= X[i] <= now:
    print(load)
  else:
    ll = 2 * min(abs(X[i] - now), abs(X[i] - X[i + 1]))
    print(load - ll)
  now = X[i]   
    
    
    
    
    








Measured memory_bytes: 20424
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    ll n, m;
    std::cin >> n >> m;

    if(n >= 2 && m >= 2){
        std::cout << (n - 2) * (m - 2) << std::endl;
        return 0;
    }

    if(n == 1 && m == 1){
        std::cout << 1 << std::endl;
        return 0;
    }

    if(n == 1 && m >= 2){
        std::cout << m - 2 << std::endl;
        return 0;
    }

    if(n >= 2 && m == 1){
        std::cout << n - 2 << std::endl;
        return 0;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll k,a,b;cin>>k>>a>>b;
  bool ok=false;
  rep(i,a,b+1){
    if(i%k==0){ok=true;}
  }
  if(ok){cout<<"OK"<<endl;}
  else{cout<<"NG"<<endl;}
}




Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string S;
    ll N;
    cin >>S;
    N=S.size();
    ll ans = INF;
    rep(i,N-2){
        ll s = stol(S.substr(i,3));
        chmin(ans,abs(753-s));

    }

    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3612
a,b,c=(int(x) for x in input().split())
if a<=b<=c:
    print(a,b,c)
elif a<=c<=b:
    print(a,c,b)
elif b<=a<=c:
    print(b,a,c)
elif b<=c<=a:
    print(b,c,a)
elif c<=a<=b:
    print(c,a,b)
else:
    print(c,b,a)



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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    string s; cin >> s;
    int lens = s.length();
    int l = 0, r = lens-1;
    int cnt = 0;
    while(l < r){
        int x_left = 0;
        int x_right = 0;
        while(s[l] == 'x'){
            x_left++;
            l++;
        }
        while(s[r] == 'x'){
            x_right++;
            r--;
        }
        if(l > r) break;
        cnt += abs(x_left - x_right);
        if(s[l] != s[r]){
            cout << -1 << endl;
            return 0;
        }
        l++; r--;
    }
    cout << cnt << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 512
n = int(input())
c = list(map(int, input().split()))

mod = 10**9 + 7
c.sort()
ans = 0
# python3.4.3では, powは、modを指定した場合、第二引数が負だとエラーを返す。3.8.0では問題なかった
for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2+n, mod) * (n-i-1) + pow(2, n-i-1+n, mod)) % mod
    ans %= mod

print(ans)


Measured memory_bytes: 26800
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	int i, j;
	char K[20], S[20];
	scanf("%s", &S);

	j = 0;
	for (i=0;i<20;i++) K[i] = '\0';
	for (i=0;i<strlen(S);i++) {
		if (S[i] == '0') K[j++] = '0';
		else if (S[i] == '1') K[j++] = '1';
		else if (S[i] == 'B') {
			if (K[0] == '\0') continue;
			else K[--j] = '\0';
		}
		if (j<0) j = 0;
	}
	printf("%s\n", K);
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll f(ll x){
	if(x%4==1)return 1;
	if(x%4==2)return x+1;
	if(x%4==3)return 0;
	return x;
}

int main(){
	ll a,b;
	cin>>a>>b;
	cout << (f(b)^f(max(0LL,a-1))) << endl;
	return 0;	
}

Measured memory_bytes: 256
/*
  --- 
  title : -1266.comp.cpp
  date : 2015-10-30
  status : NULL
  ---
  
 */

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cassert>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()


double dist(double x,double y,double z){
    return sqrt(x*x+ y*y + z*z);
}

double my_cos(double a,double b,double c){
    return (b*b+c*c-a*a)/(2*b*c);
}

bool solve(){
    int n;
    cin>>n;
    if(n==0)return false;
    vector<double> sx(n),sy(n),sz(n);
    rep(i,n){
        cin>>sx[i]>>sy[i]>>sz[i];
    }
    int m;
    cin>>m;
    vector<double> tx(m),ty(m),tz(m),phi(m);
    rep(i,m){
        cin>>tx[i]>>ty[i]>>tz[i]>>phi[i];
    }

    vector<bool> flg(n,false);
    
    rep(t_i,m){
        double dt = dist(tx[t_i],ty[t_i],tz[t_i]);
        rep(s_i,n){
            double ds = dist(sx[s_i],sy[s_i],sz[s_i]);
            double dts = dist(sx[s_i]-tx[t_i],sy[s_i]-ty[t_i],sz[s_i]-tz[t_i]);
            double cos_theta = my_cos(dts, ds, dt);
            double cos_phi = cos(phi[t_i]);
            //double sin_phi = sin(phi[t_i]);
            
            if(cos_theta > abs(cos_phi)){
                flg[s_i]=true;
                //cout << "tele "<<t_i<<" s "<<s_i<<endl;
            }
            
        }
    }
    
    int ans =0;
    rep(i,n){
        if(flg[i])ans++;
    }
    cout <<ans<<endl;
    
    return true;
}

int main()
{
    while(solve());
    return 0;
}

Measured memory_bytes: 1276
# coding: utf-8
# Your code here!

import copy
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
d = deque()
c = 0
count = 2
ans = 0

if N == 2:
    print(A[0])
elif N == 3:
    print(A[0] + A[1])
else:
    ans = A[0] + A[1]
    for i in range(3, N-1):
        if c == 0:
            ans += A[count]
            c += 1
        elif c == 1:
            ans += A[count]
            count += 1
            c = 0
        
    ans += A[1]
    print(ans)

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

typedef long long ll;

#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back

const int N=2e5+5,D=1e9+7;
ll mi(ll x,int y=D-2)
{
	ll ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}
vector<int>lk[N];
bool vis[N];
ll jie[N];

int du[N],fa[N],sz[N];
int q[N],tail,nq[N];
inline bool link_fa(int x)
{
	return x<fa[fa[x]];
}
ll solve(int rt)
{
	tail=1;
	q[1]=rt;
	vis[rt]=1;
	rep(head,1,tail)
	{
		int x=q[head];
		du[x]=0;sz[x]=1;fa[x]=0;
		for(auto y:lk[x])
		if(!vis[y])
		{
			q[++tail]=y;
			vis[y]=1;
		}
	}
	int ecnt=0;
	rep(head,1,tail)
	{
		int x=q[head];
		for(auto y:lk[x])
		{
			++du[y];
			++ecnt;
		}
	}
	ecnt/=2;
	if(ecnt!=tail)return 0;
	int nq_tail=0;
	rep(head,1,tail)
	{
		int x=q[head];
		if(du[x]==1)nq[++nq_tail]=x;
	}
	rep(head,1,nq_tail)
	{
		int x=nq[head];
		for(auto y:lk[x])
		if(--du[y]>0)
		{
			fa[x]=y;
			if(du[y]==1)nq[++nq_tail]=y;
		}
	}
	rep(head,1,tail)
	{
		int x=q[head];
		if(du[x]>1)
		{
			rt=x;
			break;
		}
	}
	for(int x=rt;;)
	{
		for(auto y:lk[x])
		if(du[y]>1&&fa[y]!=x)
		{
			fa[x]=y;
			x=y;
			break;
		}
		if(x==rt)break;
	}
//	cerr<<tail<<" "<<nq_tail<<endl;
//	rep(i,1,8)cerr<<fa[i]<<" ";cerr<<endl;
	ll ans=1;
	rep(head,1,nq_tail)
	{
		int x=nq[head];
		if(!link_fa(x))(ans*=mi(sz[x]))%=D; 
		else 
		{
			(ans*=mi(sz[x]))%=D;
			sz[fa[x]]+=sz[x];
		}
	}
	for(int x=rt;;)
	{
		if(!link_fa(x))
		{
			rt=fa[x];
			break;
		}
		x=fa[x];
		if(x==rt)return 0;
	}
	for(int x=rt;;)
	{
		if(!link_fa(x))(ans*=mi(sz[x]))%=D; 
		else 
		{
			(ans*=mi(sz[x]))%=D;
			sz[fa[x]]+=sz[x];
		}
		x=fa[x];
		if(x==rt)break;
	}
	return ans;
}

int main()
{
	int n;
	cin>>n;
	rep(i,1,n*2)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		y+=n;
		lk[x].pb(y);lk[y].pb(x);
	}
	jie[0]=1;
	rep(i,1,n*2)jie[i]=jie[i-1]*i%D;
	
	ll ans=jie[n*2];
	rep(x,1,n*2)
	if(!vis[x])
	{
		ll s=solve(x);
		rep(head,1,tail)
		{
			int x=q[head];
			vis[x]=0;
			reverse(lk[x].begin(),lk[x].end());
		}
		(ans*=s+solve(x))%=D;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, W;
  cin >> N >> W;
  vector<long> a, b, c, d;
  long base, w, v;
  for(long i = 0; i < N; i++){
    cin >> w >> v;
    if(i == 0){
      a.push_back(v);
      base = w;
    } else {
      if((w - base) == 0)a.push_back(v);
      else if((w - base) == 1)b.push_back(v);
      else if((w - base) == 2)c.push_back(v);
      else if((w - base) == 3)d.push_back(v);
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  sort(d.begin(), d.end());
  a.push_back(0);
  b.push_back(0);
  c.push_back(0);
  d.push_back(0);
  long sum = 0;
  for(int i = a.size() - 1; i >= 0; i--){
    a.at(i) += sum;
    sum = a.at(i);
  }
  sum = 0;
  for(int i = b.size() - 1; i >= 0; i--){
    b.at(i) += sum;
    sum = b.at(i);
  }
  sum = 0;
  for(int i = c.size() - 1; i >= 0; i--){
    c.at(i) += sum;
    sum = c.at(i);
  }
  sum = 0;
  for(int i = d.size() - 1; i >= 0; i--){
    d.at(i) += sum;
    sum = d.at(i);
  }
  long wei, ans = 0, val;
  for(long i = 0; i < a.size(); i++){
    for(long j = 0; j < b.size(); j++){
      for(long k = 0; k < c.size(); k++){
    	for(long l = 0; l < d.size(); l++){
          wei = base * i + (base + 1) * j + (base + 2) * k + (base + 3) * l;
          val = a.at(a.size() - 1 - i) + b.at(b.size() - 1 - j) + c.at(c.size() - 1 - k) +d.at(d.size() - 1 - l);
          if(W >= wei)ans = max(ans, val);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

ll inf = 1000000000;

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

  string s,t;cin>>s>>t;
  int len = s.size();
  int tlen = t.size();
  string ans = "UNRESTORABLE";
  for(int i=0;i<len;i++){
    bool f = true;
    string ts = s;
    for(int j=0;j<tlen;j++){
       if(i+j==len){f = false;break;}
      if(ts[i + j]=='?' || ts[i + j] == t[j]){
        ts[i + j] = t[j];
      }else{
        f = false;
      }
    }
    // cout<<f<<':'<<s<<':'<<ts<<endl;
    if(f){
      for(int i=0;i<len;i++)if(ts[i]=='?')ts[i]='a';
      ans = ts;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
int n,m,k,a,b,c,d;
string s,w;

int main(){
	cin >> s;
	RREP(i,s.size()-1,0) if(s.substr(i,8)=="FESTIVAL"){cout << s.substr(0,i) << endl; return 0;}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int i;
  int sum=0;
  cin>>N;
  char p[N];
  for(i=0;i<N;i++){
    cin>>p[i];
    if(p[i-1]==p[i]){
      sum=sum;
    }
    else{
      sum++;
    }
  }
  cout<<sum<<endl;
}
  

Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

//typedef uint64_t hash_t;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int HASH_COUNT = 2;
//const hash_t HASH_P = (uint32_t)-13337;
//uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);
//const hash_t HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)};

int inp[10];

int main(){
  for(int i = 1; i <= 5; i++){
    fastScan(inp[i]);
  }
  for(int i = 1; i <= 5; i++){
    if(inp[i] == 0){
      printf("%d\n", i);
      return 0;
    }
  }
}


Measured memory_bytes: 3752
n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
mod=10**9+7
vx,vy=0,0
for i in range(n-1):
  vx+=(x[i+1]-x[i])*(i+1)*(n-i-1)
  vx%=mod
for i in range(m-1):
  vy+=(y[i+1]-y[i])*(i+1)*(m-i-1)
  vy%=mod
print((vx*vy)%mod)


Measured memory_bytes: 18556
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> c(n);
  rep(i, n) cin >> c[i];

  vector<ll> dp(n + 1, 0);
  dp[0] = 1;
  map<ll, ll> m;
  rep(i, n) {
    dp[i + 1] = dp[i];
    if (m[c[i]] && m[c[i]] != i) {
      dp[i + 1] = (dp[i + 1] + dp[m[c[i]]]) % mod;
    }
    m[c[i]] = i + 1;
  }
  cout << dp[n] << '\n';




  
  return 0;
}

Measured memory_bytes: 15872
#include<cstdio>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);

    if (n % 2 == 0) printf("%f\n", ((double)n / 2) / (double)n);
    else printf("%f\n", (((double)n + 1) / 2 ) / (double)n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int MAXN=1e5+10;
vector<int> v[MAXN];
vector<int> st1, st2;
bool flag=false;
int vis[MAXN];
 
void dfs(int point){
    if(flag){
        return;
    }
    for(int i=0; i<v[point].size(); i++){
        int cnt=v[point][i];
        if(vis[point]==vis[cnt]){
            flag=true;
            return;
        }else if(!vis[cnt]){
            if(vis[point]==1){
                vis[cnt]=2;
                st2.push_back(cnt);
                dfs(cnt);
            }else if(vis[point]==2){
                vis[cnt]=1;
                st1.push_back(cnt);
                dfs(cnt);
            }
        }
    }
}
 
int main(void){
    int n, m, x, y;
    scanf("%d %d",&n,&m);
    for(int i = 0; i < m; i++){
        scanf("%d %d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1; i<=n; i++){
        if(v[i].size()==0){
            continue;
        }else if(!vis[i]){
            vis[i]=1;
            st1.push_back(i);
            dfs(i);
        }
    }
    ll cnt;
    if(flag) cnt = (ll)n * (n - 1) / 2 - m;
    else cnt = (ll)st1.size() * st2.size() - m;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

const int inf = 1e9;
int n, m, x, ans = inf;
vl c;
vvl a;

void dfs(int dep, int sum, vl unds) {
    bool finish = true;
    rep(i,m) if (unds[i] < x) finish = false;
    if (finish) {
        ans = min(ans, sum);
        return;
    }
    if (dep >= n) return;

    dfs(dep+1, sum, unds);
    rep(i,m) unds[i] += a[dep][i];
    dfs(dep+1, sum+c[dep], unds);
}

int main() {
    cin >> n >> m >> x;
    c.resize(n);
    a.assign(n, vl(m));
    rep(i,n) {
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    vl unds(m,0);
    dfs(0, 0, unds);
    if (ans == inf) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> p(n), q(n), s(n);
	rep(i, n)
	{
		cin >> p[i];
		s[i] = i + 1;
	}
	rep(i, n)cin >> q[i];
	int a, b;
	int cnt = 0;
	do
	{
		if (s == p)a = cnt;
		if (s == q)b = cnt;
		++cnt;
	} while (next_permutation(all(s)));
	cout << abs(a - b) << endl;
}

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

int n, m, x, cost[12], a[12][12], ans = 120000000;

int main()
{
    cin >> n >> m >> x;
    for (int in = 0; in < n; in++)
    {
        cin >> cost[in];
        for (int in2 = 0; in2 < m; in2++)
        {
            cin >> a[in][in2];
        }
    }

    for (int i = 0; i < (1 << n); i++)
    {
        int c = 0, lvl[m] = {0};
        for (int j = 0; j < n; j++)
        {
            if ((i >> j) & 1)
            {
                c += cost[j];
                for (int k = 0; k < m; k++)
                {
                    lvl[k] += a[j][k];
                }
            }
        }

        int jj;
        for (jj = 0; jj < m; jj++)
        {
            if (lvl[jj] < x) break;
        }
        if (jj == m) ans = min(ans, c);
    }

    if (ans == 120000000) cout << -1 << endl;
    else cout << ans << endl;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    char ch[h+3][w+3];

    for (int y = 1; y <= h; y++) {
        for (int x = 1; x <= w; x++) {
            cin >> ch[y][x];
        }
    }

    for (int y = 1; y <= h; y++) {
        for (int x = 1; x <= w; x++) {
            if (ch[y][x] == '.') continue;

            if (ch[y - 1][x] == '.' && ch[y + 1][x] == '.' && ch[y][x - 1] == '.' && ch[y][x + 1] == '.') {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
/// Kazuki Hoshino
/// Lost July

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

ll n, a[202020], sum=0, s[202020], ans=inf;

int ser(int l, int r){
    ll temp = s[r]-s[l-1];
    temp/=2;
    int m = upper_bound( s+1, s+n+1, s[l-1]+temp) - s;
    return m;
}

ll val(int x, int y, int z){

    if(x-0==0 || y-z==0 || z-y==0 || n-z==0)return inf;

    ll temp = s[x];
    ll t = s[y] - s[x];
    ll t2 = s[z] - s[y];
    ll t3 = s[n]- s[z];

    ll mn = min(temp, t);
    mn = min(mn, t2);
    mn = min(mn, t3);
    ll mx = max(temp, t);
    mx = max(mx, t2);
    mx = max(mx, t3);

    return mx - mn;

}

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

cin >> n;

rep(i, 1, n){
cin >> a[i];
sum+=a[i];
s[i]+=s[i-1]+a[i];
//cout << s[i] << endl;
}

sum/=4;

rep(i, 3, n){

int mid = ser(1,i-1);
int m = ser(i, n);

ans = min(ans, val( mid,i-1,m) );
ans = min(ans, val(mid-1, i-1, m ));
ans = min(ans, val(mid-1, i-1, m-1));
ans = min(ans, val(mid, i-1, m-1));

//cout << ans << " " << mid << " " << i-1 << " " << m << endl;

}

cout << ans << endl;

return 0;}


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

int main(){
    int n, d;
    cin >> n >> d;
    int a = (d*2)+1;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if ( a*i >= n ) {
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  int n,a,b,c;
  string s;
  cin >> n;
  cout << (n-2)*180 << endl;
}

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

using namespace std;

long n, a[100002], t = 0;

int main() {
  scanf("%ld", &n);
  for (long i = 1; i <= n; i++)
    scanf("%ld", &a[i]), t += abs(a[i] - a[i - 1]);
  t += abs(a[n]);
  for (long i = 1; i <= n; i++)
    printf("%ld\n", t - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]));
}


Measured memory_bytes: 2048
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

char s[100];
int main(int argc, char const *argv[]) {
    // code
    scanf("%s", s);
    if (s[2] == s[3] && s[4] == s[5])
        puts("Yes");
    else
        puts("No");
    return 0;
}


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

int main(){
    ll n;
    cin >> n;
    ll a[5];
    for (int i = 0; i < 5; i++) {
       cin >> a[i];
    }
    ll mi = a[0];
    for (int i = 1; i < 5; i++) {
        if (a[i]  < mi) {
            mi = a[i];
        }
    }
    ll ans;
    if (n % mi == 0) {
        ans = n / mi - 1;
    }
    else {
        ans = n / mi;
    }
    cout << ans  + 5<< '\n';

}


Measured memory_bytes: 256
#include <stdio.h>

	int n;
	int a[15];
	int x[14][15];
	int y[14][15];

int numofbits(long bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

//整合性チェック 0=正しい/1=矛盾した
int checkCorrectness(int b)
{
	for ( int i = 0 ; i < n ; i++ ) {
		int bb;
		if ( b & ( 1<<i ) ) {
			bb = 0;	//他の人が自分を不親切な人としていないかチェック
		} else {
			bb = 1;	//他の人が自分を正直な人としていないかチェック
		}
		for ( int j = 0 ; j < n ; j++ ) {
			if ( i != j ) {
				if ( b & ( 1<<j ) ) {
					for ( int k = 0 ; k < a[j] ; k++ ) {
						if ( ( x[k][j] == i ) && ( y[k][j] == bb ) ) {
							return 1;
						}
					}
				}
			}
		}
	}
	return 0;
}

int main()
{

	scanf( "%u", &n );
	for ( int i = 0 ; i < n ; i++ ) {
		scanf( "%u", &(a[i]) );
		for ( int j = 0 ; j < a[i] ; j++ ) {
			scanf( "%u", &(x[j][i]) );	// 1～
			x[j][i]--;					// 0～
			scanf( "%u", &(y[j][i]) );
		}
	}

	int err = 1;
	int imax = 1 << n;
	for ( int c = n ; c > 0 ; c-- ) {	//正直な人の数が多い順
		for ( int b = 1 ; b < imax ; b++ ) {
			if ( numofbits(b) == c ) {	//正直な人の数
			err = checkCorrectness(b);	//整合性チェック 0=正しい/1=矛盾した
				if (!err) {
					printf("%i",c);
		break;
				}
			}
		}
		if (!err) break;
	}
	if (err) {
		printf("%i",0);
	}

}


Measured memory_bytes: 128
import sys
def main():
  input=sys.stdin.readline
  N, K = map(int, input().split())
  wd = [tuple(map(int, input().split())) for i in range(N)]
  d = 0
  dp = [0]*N
  l = 0
  r = wd[0][0] + wd[0][1]*K
  while(r - l > 1):
    tmp = (l+r)//2
    num = 0
    for w, d in wd:
      if w <= tmp:
          num += ((tmp - w) // d) + 1
    if num >= K:
      r = tmp
    else:
      l = tmp
  print(r)
main()


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

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (size_t i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	bool debug = false;
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

class Point {
public:
	double x, y;
	Point(double x, double y) {
		this->x = x;
		this->y = y;
	}
	Point() {
		x = 0.0;
		y = 0.0;
	}
};

double distance(Point p1, Point p2) {
	return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
}

int kaijo(int n) {
	int ans = 1;
	for (int i = 2; i <= n; ++i) {
		ans *= i;
	}
	return ans;
}

inline void Main(){
	int N;
	cin >> N;
	vector<Point> points;
	vector<int> mati(N);
	for (int i = 0; i < N; ++i) {
		mati[i] = i;
		double x, y;
		cin >> x >> y;
		points.emplace_back(Point(x, y));
	}
	vector<vector<int>> p;
	do {
		p.push_back(mati);
	} while (std::next_permutation(mati.begin(), mati.end()));

	double all_all_distance = 0;
	for (size_t i = 0; i < p.size(); ++i) {
		double all_distance = 0;
		for (size_t j = 0; j < p[i].size() - 1; ++j) {
			all_distance += distance(points[p[i][j]], points[p[i][j + 1]]);
		}
		all_all_distance += all_distance;
	}
	cout << all_all_distance / kaijo(N) << endl;
}

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

int maxtime(int time){
    return (time + 9) / 10 * 10;
}

int losstime(int time){
    return maxtime(time) - time;
}

int main(){
    int a, b, c, d, e;
    int sum, maxtimes;

    cin >> a >> b >> c >> d >> e;

    sum = maxtime(a) + maxtime(b) + maxtime(c) + maxtime(d) + maxtime(e);
    maxtimes = sum - max({losstime(a), losstime(b), losstime(c), losstime(d), losstime(e)});

    cout << maxtimes << endl;
}

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

using ll = long long;

const int max_N = 1e5 + 21;

int n,A[max_N];

ll ans;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",A+i);
	for(int i=1,j;i<=n;++i){
		if(A[i]&1){
			for(j=i+1;j<=n&&A[j]>=2&&(~A[j]&1);++j);
			if(A[j]&1){
				ll tmp=0;
				for(int k=i;k<=j;++k)tmp+=A[k];
				ans+=(tmp>>1);
				i=j;
			}
			else ans+=(A[i]>>1);
		}
		else ans+=(A[i]>>1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define gc getchar
#define int long long
const int MAXN=1e6+5;
char s[MAXN];
int n,m,ans,b[MAXN];

inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	m=read();
	if(n==1)
	{
		cout<<m/2;
		return 0;
	}
	for(int i=2;i<=n;i++)
		if(s[i]==s[i-1]&&!b[i-1])
		{
			ans++;
			b[i]=1;
		}
	ans=ans*m;
	if(s[1]==s[n]&&!b[n])
	{
		if(s[1]!=s[2])ans=ans+m-1;
		else{
			ans=ans/m;
			memset(b,0,sizeof(b));
			b[1]=1;
			int res=1;
			for(int i=2;i<=n;i++)
				if(s[i]==s[i-1]&&!b[i-1])
				{
					res++;
					b[i]=1;
				}
			if(!b[n])ans+=res*(m-1);
			else{
				if(res<ans)swap(res,ans);
				cout<<res*(m/2)+ans*(m/2+m%2)<<endl;
				return 0;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 8448
import java.lang.reflect.Array;
import java.util.Scanner;

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

        for(int i=0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }

        if (a[0] == a[1] && a[0] == a[2]) {
            System.out.println("No");
        }
        else if (a[0] != a[1] && a[1] != a[2] && a[0] != a[2]) {
            System.out.println("No");
        }
        else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
long long ans=0,prep[20];
const long long mod=1e9+7;
map < pair <long long,long long> , int > cnt;
void bt(int l,int r){
	int sz=r-l+1;
	for(int mask=0;mask<(1<<sz);mask++){
		long long prd1=0,prd2=0;
		if(l==0){
			for(int i=0;i<sz;i++){
				if(mask&(1<<i)){
					prd2*=30LL;
					prd2=(prd2+1LL*(s[l+i]-'a'+1))%mod;
				}
				else{
					prd1*=30LL;
					prd1=(prd1+1LL*(s[l+i]-'a'+1))%mod;
				}
			}
			cnt[make_pair(prd1,prd2)]++;
		}
		else{
			for(int i=sz-1;i>=0;i--){
				if(!(mask&(1<<i))){
					prd2*=30LL;
					prd2=(prd2+1LL*(s[l+i]-'a'+1))%mod;
				}
				else{
					prd1*=30LL;
					prd1=(prd1+1LL*(s[l+i]-'a'+1))%mod;
				}
			}
			ans+=cnt[make_pair(prd1,prd2)];
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	cin>>s;
	prep[0]=1;
	for(int i=1;i<=19;i++){
		prep[i]=(prep[i-1]*30LL)%mod;
	}
	bt(0,n-1);
	bt(n,n*2-1);
	cout<<ans;
}


Measured memory_bytes: 33024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
  int key;
  struct node *prev, *next;
}Node;

void init();
void insert(int key);
Node * listSearch(int key);
void deleteNode(Node *t);
void deleteFirst();
void deleteLast();
void deletekey(int key);

Node *nil;

void init()
{
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert(int key)
{
  Node *x =(Node *)malloc(sizeof(Node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}


Node* listSearch(int key)
{
  Node *cur = nil->next;
  while( cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void deleteNode(Node *t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deletekey(int key){
  deleteNode(listSearch(key));
}


int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np=0, nd=0;

  scanf("%d", &n);

  init();

  for(i=0; i<n; i++){
    scanf("%s", com);
    if(strcmp(com, "insert") == 0){
      scanf("%d", &key);
      //printf("key=%d\n", key);
      insert(key);
      np++;
      size++;
    }

    else if(strcmp(com, "delete") == 0){
      scanf("%d", &key);
      // printf("key=%d\n", key);
      deletekey(key);
      nd++;
      size--;
    }

    else if(strcmp(com, "deleteFirst") == 0){
      deleteFirst();
      size--;
    }
    
    else{
      deleteLast();
      size--;
    }
    //printf("i=%d\n", i);
  }

  Node *cur = nil->next;
  int isf = 0;
  while(1){
    if(cur == nil){
      break;
    }
    if(isf++ > 0){
      printf(" ");
    }

    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 31788
import sys

def solve():
    S = input()
    count = 0
    leftMostW = 0
    for i in range(len(S)):
        if S[i] == "W":
            count += i - leftMostW
            leftMostW += 1
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3500
#include<bits/stdc++.h>
#define ll 	long long
#define pb push_back
#define mp make_pair
using namespace std;


int main() {

ll n;
ll d; cin>>n>>d;
ll cnt=0;
ll gg=n;
	ll ff= d*d;
while(n--)
{

	ll e, f;
	cin>>e>>f;
		
		ll hh= (abs(e)*abs(e)) + (abs(f)*abs(f));
		
	
		
		if(hh>ff)
		cnt++;
}

cout<<gg-cnt<<endl;

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define aaa cout<<233<<endl;
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// mt19937 rnd(TM(0));
const int inf = 0x3f3f3f3f;//1061109567 > 1e9
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const double pi = 3.14159265358979;
const int maxn = 1e3 + 5;
const int maxm = 5e5 + 233;
const int mod = 1e9 + 7;


int main()
{
    // double pp = clock();
    // freopen("233.in", "r", stdin);
    // freopen("233.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    int a, b;
    cin >> a >> b;
    cout << ((a - b * 2 > 0) ? (a - b * 2) : 0) << endl;
    
    // cout << endl << (clock() - pp) / CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 892