akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

map<ll, ll> mp;

ll m = 1e9 + 7;

void trial_division(ll n)
{
    vector<ll> factorization;
    while (n % 2 == 0)
    {
        mp[2]++ % m;
        n /= 2;
    }
    for (ll d = 3; d * d <= n; d += 2)
    {
        while (n % d == 0)
        {
            mp[d]++ % m;
            n /= d;
        }
    }
    if (n > 1)
        mp[n]++ % m;
}

int main()
{
    ll n;
    cin >> n;
    rep(i, 1, n + 1)
        trial_division(i);
    ll ans = 1;
    for(auto x:mp)
    {
        // cout << x.first << x.second << endl;
        ans = ans * (x.second + 1) % m; 
    }
    cout << ans % m;   
    return 0;
}

Measured memory_bytes: 256
/* AtCoder Beginner Contest abc130
 * Problem C
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main(void) {
	int W, H, x, y;
	cin >> W >> H >> x >> y;
	cout << ((double) W * H / 2) << " " << (2 * x == W && 2 * y == H) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


ll RepeatSquaring(ll base, ll sisuu) {
	if (sisuu == 0) return 1;
	if (sisuu % 2 == 0) {
		ll t = RepeatSquaring(base, sisuu / 2) % 998244353;
		return (t * t) % 998244353;
	}
	return base * RepeatSquaring(base, sisuu - 1) % 998244353;
}


int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================
	
	ll N;
	cin >> N;

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

	if (D[0] != 0)
	{
		cout << 0 << endl;
		return 0;
	}


	vll dis(N);
	for (int i = 0; i < N; i++)
	{
		dis[i] = 0;
	}
	for (int i = 0; i < N; i++)
	{
		dis[D[i]] ++;
	}

	int last = 0;
	for (int i = 0; i < N; i++)
	{
		if (dis[i] != 0)
		{
			last = i;
		}
	}

	for (int i = 0; i < last; i++)
	{
		if (dis[i] == 0)
		{
			cout << 0;
			return 0;
		}
	}


	if (dis[0] == 1)
	{
		ll ans = 1;
		for (int i = 1; i < N; i++)
		{
			ans *= RepeatSquaring(dis[i - 1], dis[i]); 
			ans %= 998244353;
		}

		cout << ans;
	}
	else
	{
		cout << 0;
	}


}





Measured memory_bytes: 1792
S = input()[::-1]
T = ""

cand = ["dream", "dreamer", "erase", "eraser"]
cand = [c[::-1] for c in cand]

while S:
    for c in cand:
        if S.startswith(c):
            S = S[len(c):]
            break
    else:
        break

print("YES") if S == "" else print("NO")

Measured memory_bytes: 3188
n=int(input())
if n==0:
  print(2)
  exit()
if n==1:
  print(1)
  exit()
l=[0]*87
l[0]=2
l[1]=1
for i in range(2,n+1):
  l[i]=l[i-1]+l[i-2]
print(l[n])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9
// fflush(stdout);
//lower_bound,upper_bound,equal_range
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	ll n,W;
	cin>>n>>W;
	ll i,j;
	vector<ll>v(n),w(n);
	vector<pair<ll,ll>>q;
	rep(i,n)
	{
		cin>>w[i]>>v[i];
		q.push_back(mp(w[i],v[i]));
	}
	sort(q.begin(),q.end());
	rep(i,n)
	{
		w[i]=q[i].first;
		v[i]=q[i].second;
	}
	vector<vector<ll>>dp(n,vector<ll>(W+1,0));
	REP(i,1,W+1)
	{
		if(i>=w[0])dp[0][i]=v[0];
	}
	REP(i,1,n)
	{
		REP(j,1,W+1)
		{
			if(j>=w[i])dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			else
			{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[n-1][W];
	return 0;
}

Measured memory_bytes: 82308
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <utility>

using namespace std;

const int INF = 1000000007;
const double PI = acos(-1.0);
typedef long long llong;
int money[6] = { 1, 5, 10, 50, 100, 500 };


int main()
{	
	int sum = 0;

	vector<int> vec(6);
	for (int i = 0; i < 6; i++)
		cin >> vec[i];

	for (int i = 0; i < 6; i++)
	{
		sum += vec[i] * money[i];
		if (sum >= 1000)
		{
			cout << 1 << endl;
			return 0;
		}
	}

	cout << 0 << endl;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll S;
  cin>>S;
  const ll MAX = 1e9;
  if(S==1e18){
    cout<<0<<" "<<0<<" "<<MAX<<" "<<0<<" "<<0<<" "<<MAX;
    return 0;
  }
  ll X1,X2,X3,Y1,Y2,Y3;

  X1=0;
  Y1=0;
  X2=MAX;
  Y2=1;
  X3=MAX-S%MAX;
  Y3=S/MAX+1;
  cout<<X1<<" "<<Y1<<" "<<X2<<" "<<Y2<<" "<<X3<<" "<<Y3;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int m,n;
  
  scanf("%d %d",&n,&m);
  int a[n];
  int i;
  int sum = 0;
  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  int cnt=0;
  for(i=0;i < n;i++){
    if(sum <= (4*m*a[i])){
      cnt++;
    }
  }
  if(cnt >= m){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}
  


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

int main(){
	/*入力*/
	int n;
	cin >> n;
	int* v = new int [n];
	int* c = new int [n]; 
	for(int i = 0;i < n;i++){
		cin >> v[i];
	} 
	for(int i = 0;i < n;i++){
		cin >> c[i];
	}

	/*計算*/
	int* v_c=new int [n];	//価値ーコストの一覧
	for(int i = 0; i < n; i++){
		v_c[i] = v[i] - c[i];
	}
	int o = 0;				//出力値
	for(int i = 0; i < n; i++){
		if(v_c[i] > 0){
			o+=v_c[i];
		}
	}

	/*出力*/
	cout << o << endl;
	

	delete[] v;
	delete[] c;
	delete[] v_c;
}


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

int main(){

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int k,i;
	cin>>k;
	string s;
	cin>>s;

	if(s.length() <= k)
	cout<<s;
	
	else{
		for(i=0;i<k;i++)
		cout<<s[i];
		cout<<"...";
	}
	
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <numeric>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <tuple>

using namespace std;

//#define int long long

#define rep(i,n) for(int i = 0; i<n ; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)
#define REPSTR(i,s) for(int i=0; (s)[i]; i++)
#define REPITR(i,s) for(auto i=(s).begin(); i!=(s).end();i++)

#define RANGE(a,i,b) ((a)<=(i)&&(i)<=(b))

#define pb push_back
#define mp make_pair

#define ALL(a) begin(a), end(a)

#define EXIST(s,x) ((s).find(x)!=(s).end())

#define SET(a,c) memset(a,c,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))

#ifdef _DEBUG
#define DEBUG(x) cerr<<#x<<":"<<x<<endl
#else
#define DEBUG(x)
#endif

#define PRINTJOIN(x,n) rep(i,n){if(i)cout<<" ";cout<<x[i];}cout<<endl 
#ifdef int
#define INF 1001001001001001001LL
#else
#define INF 1001001001
#endif

typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef stringstream SS;

#define PQ priority_queue

#define FST first
#define SEC second

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

struct Point {
    double x;
    double y;
    Point(){}
    Point(double x, double y): x(x), y(y){}
    double operator ^ (Point const& p) {
        return this->x*p.y-this->y*p.x; 
    }
    Point operator + (Point const& p) {
        return Point(this->x+p.x, this->y+p.y);
    }
    Point operator - (Point const& p) {
        return Point(this->x-p.x, this->y-p.y);
    }
};

signed main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
    //int n; cin>>n;
    Point p1, p2, p3;
    scanf("%lf,%lf", &p1.x, &p1.y);
    scanf("%lf,%lf", &p2.x, &p2.y);
    double ans = 0;
    //cerr<<p1.x<<" "<<p1.y<<" "<<p2.x<<" "<<p2.y<<endl;
    while(~scanf("%lf,%lf", &p3.x, &p3.y)) {
        ans += (p3-p1)^(p2-p1);
        swap(p2,p3);
    }
    cout << abs(ans)/2 << endl;

	return 0;
}


Measured memory_bytes: 3296
from collections import deque
def bfs(S,H,W):
    que = deque([(0,0)])
    dist = [[2**60]*W for _ in range(H)]
    dist[0][0] = 0
    while que:
        u = que.popleft()
        d = [-1,1]
        y,x = u
        for i in range(2):
            s = x+d[i]
            t = y+d[i]
            if 0 <= s < W:
                if S[y][s] == '.':
                    if dist[y][s] == 2**60:
                        que.append((y,s))
                    dist[y][s] = min(dist[y][s],dist[y][x]+1)
            if 0 <= t < H:
                if S[t][x] == '.':
                    if dist[t][x] == 2**60:
                        que.append((t,x))
                    dist[t][x] = min(dist[t][x],dist[y][x]+1)
    return dist[-1][-1]

def main():
    H,W = map(int,input().split(" "))
    S = []
    total = -1
    for _ in range(H):
        s = input()
        total += s.count('.')
        S.append(s)
    num = bfs(S,H,W)
    if num == 2**60:
        ans = -1
    else:
        ans = total-num
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include<stdio.h>
#include<math.h>
int n,i,j;
double P[3][2],a,b,c,A,B,C,R[2],r,x;
double d(double p[2],double q[2])
{
	double e=p[0]-q[0],f=p[1]-q[1];
	double r=sqrt(e*e+f*f);
	return r;
}
int main()
{
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<3;j++)scanf("%lf%lf",&P[j][0],&P[j][1]);
		a=d(P[1],P[2]);
		b=d(P[0],P[2]);
		c=d(P[0],P[1]);
		x=(a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c);
		r=a*b*c/sqrt(x);
		a*=a;b*=b;c*=c;
		A=a*(b+c-a);
		B=b*(c+a-b);
		C=c*(a+b-c);
		R[0]=(A*P[0][0]+B*P[1][0]+C*P[2][0])/(A+B+C);
		R[1]=(A*P[0][1]+B*P[1][1]+C*P[2][1])/(A+B+C);
		printf("%.3f %.3f %.3f\n",R[0],R[1],r);
	}
	return 0;
}

Measured memory_bytes: 664
#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 pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
ll fact[2000000+1];
int fact_tbl(int n){
    if(fact[0]==0){
        fact[0]=1;
        FOR(i,1,n+1) fact[i]=fact[i-1]*i%mod;
    }
    return 0;
}
int exgcd(int a,int b,int& x,int& y){
    int d=a;
    if(b!=0){
        d=exgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else{
        x=1;y=0;
    }
    return d;
}
int mod_inverse(int a,int m){
    int x,y;
    exgcd(a,m,x,y);
    return (m+x%m)%m;
}
int mod_fact(int n,int p,ll& e){
    e=0;
    if(n==0) return 1;
    ll res=mod_fact(n/p,p,e);
    e+=n/p;
    if(n/p%2!=0) return res*(p-fact[n%p])%p;
    return res*fact[n%p]%p;
}
ll mod_comb(int n,int k,int p){
    if(n<0||k<0||n<k) return 0;
    ll e1,e2,e3;
    ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
    if(e1>e2+e3)return 0;
    return a1*mod_inverse(a2*a3%p,p)%p;
}


int main(){
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    ll ans=0,fd,bk;
    fact_tbl(h+w);
    FOR(i,b,w){
        fd=mod_comb(i+h-a-1,i,mod);
        bk=mod_comb(w-i-1+a-1,a-1,mod);
        ans+=fd*bk%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

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

const int MAXN = 3005, mod = 1e9+7;

int n, m;

long long dp[MAXN][MAXN][2];
int power[MAXN];

int main()
{
	cin >> n >> m;
	power[0] = 1;
	for (int i = 1; i <= m; i++) power[i] = power[i-1]*4ll%mod;
	dp[0][0][0] = 1;
	for (int i = 0; i < m; i++) 
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k < 2; k++) { 
				if (j != n) (dp[i+1][j+1][k||(j+1==n)] += dp[i][j][k]) %= mod;
				if (j) (dp[i+1][j-1][k] += dp[i][j][k]) %= mod;
				if (k == 1 || j == n) 
					(dp[i+1][j][1] += dp[i][j][k]*((j!=0)+(j!=n))) %= mod;
				else if (j == n-1) {
					(dp[i+1][j][1] += dp[i][j][k]) %= mod;
					(dp[i+1][j][0] += dp[i][j][k]*(j!=0)) %= mod;
				} else (dp[i+1][j][k] += dp[i][j][k]*((j!=0)+(j!=n))) %= mod;
			}
		}
	int cur = power[m];
	for (int i = 1; i < m; i++) {
		for (int j = 0; j <= n; j++)
			cur = ((cur-4ll*dp[i][j][1]*power[m-i-1])%mod+mod)%mod;
	}
	cout << cur << endl;
	return 0;
}


Measured memory_bytes: 141184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		
		int h = Integer.parseInt(tmpArray[0]);
		int n = Integer.parseInt(tmpArray[1]);

		int damage[] = new int[n];
		int cost[] = new int[n];
		
		int dp[] = new int[10000 + 1];
		
		for(int i = 0; i < n; i++) {
			tmpArray = br.readLine().split(" ");
			
			damage[i] = Integer.parseInt(tmpArray[0]);
			cost[i] = Integer.parseInt(tmpArray[1]);
		}
		
//		int minCost[] = new int[10000 + 1];
//		Arrays.fill(minCost, Integer.MAX_VALUE);
//		minCost[0] = 0;
		/*
		for(int i = 0; i < n; i++) {
			for(int j = 1; j <= 10000 ; j++) {
				int tmpCost = (j + damage[i] - 1)/damage[i]*cost[i];
				if(tmpCost < minCost[j]) {
					minCost[j] = tmpCost;
				}
			}
		}*/
		
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 1; i <= 10000; i++) {
			for(int j = 0; j < n; j++) {
				dp[i] = Math.min(dp[i], dp[i - Math.min(i, damage[j])] + cost[j]);
			}
		}
		
		//debug 
//		for(int i = 0; i < 20; i++) {
//			System.out.print(dp[i]+" ");
//		}
//		System.out.println();
		
		System.out.println(dp[h]);
	}

}


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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

ll calc(ll x) {
	return x / 2;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	string s; int k;
	read(s, k);
	int n = sz(s);
	vector<pair<char, int>> v;
	
	int prev = 0;
	for (int i = 1; i < sz(s); i++) {
		if (s[i] != s[prev]) {
			v.push_back({s[prev], i - prev});
			prev = i;
		}
	}
	v.push_back({s[prev], n - prev});
	
	if (v.size() == 1) {
		write(calc(1ll * n * k));
	} else {
		ll ans = 0;
		ans += calc(v[0].second);
		ans += calc(v[sz(v) - 1].second);
		rep(i, 1, sz(v) - 1)
			ans += 1ll * calc(v[i].second) * k;
		if (v[0].first == v[sz(v) - 1].first)
			ans += calc(v[0].second + v[sz(v) - 1].second) * (k - 1);
		else
			ans += (calc(v[0].second) + calc(v[sz(v) - 1].second)) * (k - 1);
		write(ans);
	}
}


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

#define int long long
#define max(a,b) max((signed)a,(signed)b)
#define mn(a,b) min((signed)a,(signed)b)

using namespace std;

signed main(){
	int n;
	cin>>n;
	string ans="";
	while(n!=0){
		n--;
		ans = (char)('a'+ (n%26))+ans;
		n = n/26;
	}
	cout<<ans;
}


Measured memory_bytes: 3644
#include <stdio.h>
int main(){
  
  int A, B, C, a;
  
  scanf("%d%d%d", &A, &B, &C);
  
  a = B / A;
  
  if(a > C){
    printf("%d\n", C);
  } else {
    printf("%d\n", a);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll n,ans;
ll say[15];
ll ch[15][15];
void cal(){
	bool ch2=true;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			ll now=ch[i][j];
			if(now==-1){
				continue;
			}
			if(say[i]==1){
				if(now!=say[j]){
					ch2=false;
				}
			}
		//	else{
		//		if(now==say[j]){
		//			ch2=false;
		//		}
		//	}
		}
	}
	ll sum=0;
	if(ch2){
		for(ll i=0;i<n;i++){
			//cout << "K";
			if(say[i]==1){
				sum++;
			}
		}
		ans=max(ans,sum);
	}
}
void dep(ll now){
	if(now==n){
		//cout << "k";
		cal();
		return ;
	}
	say[now]=0;dep(now+1);
	say[now]=1;dep(now+1);
	return ;
}
int main() {
	cin>>n;
	for(ll i=0;i<15;i++){
		for(ll j=0;j<15;j++){
			ch[i][j]=-1;
		}
	}
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		for(ll j=0;j<now;j++){
			ll x,y;
			cin>>x>>y;
			x--;
			ch[i][x]=y;
		}
	}
	dep(0);
	cout << ans;
	// your code goes here
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	fmt.Println(max(0, c-(a-b)))
}


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

typedef long long ll;

const int Maxn = 500005;

int n;
char str[Maxn];
int L[Maxn], R[Maxn];
ll res;

int main()
{
    scanf("%s", str + 1);
    n = strlen(str + 1);
    str[0] = '>';
    str[n + 1] = '<';
    for (int i = 1; i <= n; i++)
        if (str[i] == '<') L[i] = L[i - 1] + 1;
        else L[i] = 0;
    for (int i = n; i > 0; i--)
        if (str[i] == '>') R[i] = R[i + 1] + 1;
        else R[i] = 0;
    for (int i = 0; i <= n; i++)
        res += max(L[i], R[i + 1]);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4608
import java.util.*;



public class Main {
    public static int[] ints;
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        final int N=scanner.nextInt();
        ints=new int[N];
        UnionFind unionFind=new UnionFind(N);
        for(int i=0;i<N;i++){
            ints[i]=scanner.nextInt();
            if(!unionFind.isActive(ints[i]-2)){
                unionFind.doActive(ints[i]-1);
                continue;
            }else{
                unionFind.union(ints[i]-1,ints[i]-2);
                unionFind.doActive(ints[i]-1);
            }
        }
        System.out.println(N-unionFind.maxLength());
    }

}
class UnionFind{
    int[] parents;
    boolean[] actives;
    int[] lengths;
    public UnionFind(int n){
        parents=new int[n];
        for(int i=0;i<n;i++){
            parents[i]=i;
        }
        actives=new boolean[n];
        lengths=new int[n];
        for(int i=0;i<n;i++){
            lengths[i]=1;
        }
    }
    int parent(int x){
        if(parents[x]==x){
            return x;
        }else{
            return parent(parents[parents[x]]);
        }
    }
    void doActive(int x){
        actives[x]=true;
    }
    boolean isActive(int x){
        if(x==-1) return false;
        return actives[x];
    }
    void union(int x,int y){
        parents[x]=y;
        lengths[x]=lengths[y]+1;
    }
    int length(int x){
        int result=1;
        while(parents[x]!=x){
            result++;
            x=parents[x];
        }
        return result;
    }
    int maxLength(){
        int max=Integer.MIN_VALUE;
        for(int i=0;i<parents.length;i++){
            int len=lengths[i];
            if(max<len) max=len;
        }
        return max;
    }
}

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

int main() {
  string N;
  cin >> N;
  bool B = false;
  for (int i = 0; i < (int)(N.length()); i++){
    if (N.at(i) == '7')
      B = true;
  }
       if (B)
       cout << "Yes";
       else 
       cout << "No";
  cout << endl;
  
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(c-b<=1||a-b<=0){
  cout<<1+a;
  }
    else{
      if((a-b)%2==0){
      int k=(a-b+1)/2;
        cout<<b+k*(c-b)+1;
      }
        else{
        int k=(a-b+1)/2;
          cout<<b+k*(c-b);
        }
    
    }
}

Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  long long A;
  int B, B1;
  char c;
  cin >> A >> B >> c >> B1;
  cout << A * B + (A * B1 / 100) << endl;
  return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

int N, x;
int ans[200005];

void solve() {
	if (x < 2 || 2 * N - 2 < x) {
		cout << "No" << endl;
		return;
	}
	if (x == N) {
		for (int i = 0; i < 2 * N - 1; i++) {
			ans[i] = i + 1;
		}
	} else if (x < N) {
		int j = 0;
		for (int i = 0; i < 2 * N - 1; i++) {
			ans[(N - x + i) % (2 * N - 1)] = i + 1;
		}
	} else {
		// x > N
		for (int i = 0; i < N - 1; i++) {
			ans[i] = i + 1;
		}
		ans[N - 1] = x;
		for (int i = N, j = 2 * N - 1; i < 2 * N - 1; i++) {
			if (j == x) j--;
			ans[i] = j--;
		}
	}
	cout << "Yes" << endl;
	for (int i = 0; i < 2 * N -1; i++) {
		cout << ans[i] << endl;
	}
}

int main() {
	cin >> N >> x;
	solve();
	return 0;
}




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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;


int N, K;
vector<P> dt;

ll calc(int x)
{
    ll point = (ll)x * x;
    int cnt = 0;
    set<int> us;
    vector<bool> ate(N, false);
    for (int i = 0; i < N; i++) {
        int d = dt[i].first, t = dt[i].second;
        if (us.find(t) == end(us)) {
            point += d;
            cnt++;
            us.insert(t);
            ate[i] = true;
            if (cnt == x)
                break;
        }
    }
    if (cnt == K)
        return point;
    for (int i = 0; i < N; i++) {
        if (!ate[i]) {
            point += dt[i].first;
            cnt++;
            if (cnt == K)
                return point;
        }
    }
}

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

    cin >> N >> K;
    dt = vector<P>(N);
    set<int> us;
    for (int i = 0; i < N; i++) {
        int t, d;
        cin >> t >> d;
        dt.push_back(P(d, t));
        us.insert(t);
    }
    sort(begin(dt), end(dt), greater<>());

    int lx = 1, rx = min(K, (int)us.size());
    while (rx - lx > 3) {
        int d = (rx - lx) / 3;
        int ax = lx + d, bx = rx - d;
        ll ap = calc(ax), bp = calc(bx);
        if (ap <= bp)
            lx = ax;
        else
            rx = bx;
    }

    ll ma = 0;
    for (int x = lx; x <= rx; x++) {
        ma = max(ma, calc(x));
    }

    cout << ma << endl;

    return 0;
}



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

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

    int m = n*100/108;
    string ans = ":(";
    for(int i=m-100; i<m+101; i++)
    {
        if((int)((double)i*1.08) == n)
        {
            ans = to_string(i);
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    a, b = mi()
    print(100, 100)
    ans = [[] for i in range(100)]
    for i in range(50):
        for j in range(100):
            ans[i].append('#')
    for i in range(50, 100):
        for j in range(100):
            ans[i].append('.')

    for i in range(a - 1):
        ans[2 * (i // 50)][2 * (i % 50)] = '.'
    for i in range(b - 1):
        ans[99 - 2 * (i // 50)][2 * (i % 50)] = '#'

    for i in range(100):
        print(''.join(ans[i]))


main()


Measured memory_bytes: 10076
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        ArrayList<Integer> as = new ArrayList(3);
        as.add(scanner.nextInt());
        as.add(scanner.nextInt());
        as.add(scanner.nextInt());
        Collections.sort(as, Collections.reverseOrder());
        int count = 0;
        while(as.get(0) != as.get(1)) {
            as.set(1, as.get(1) + 1);
            as.set(2, as.get(2) + 1);
            count++;
        }
        count += (as.get(0) - as.get(2)) / 2 + (as.get(0) - as.get(2)) % 2 * 2;
        System.out.println(count);
    }
}

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

int main(){
    int l, r, m;
    cin >> l >> r; m = 2019;
    if (r - l + 1 >= m){
        cout << 0 << endl;
        return 0;
    }
    int ans = 1000000000;
    for (int i = l; i <= r; i++){
        for (int j = i + 1; j <= r; j++){
            long long t = (long long)i * j;
            t %= m;
            ans = min(ans, (int)t);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
a = [0] * n
for i in range(n-1):
  a[i+1] = a[i]
  if s[i:i+2] == 'AC':
    a[i+1] += 1
for i in range(q):
  l, r = map(int, input().split())
  print(a[r-1]-a[l-1])

Measured memory_bytes: 6260
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    tmp = A & 1
    A >>= 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans = (ans + pow(2, i, mod) * x) % mod
print(ans)

Measured memory_bytes: 49952
import  java.io.*;
import  java.math.*;
import  java.util.*;
 
 
public class Main {
    public static void main(String[] args) {
    	Scanner cin = new Scanner(System.in);
    	String s = cin.next();
    	int flag = 0;
    	if(s.charAt(0) == '7' || s.charAt(1) == '7' || s.charAt(2) == '7') flag = 1;
        if(flag == 0) System.out.print("No");
        else System.out.println("Yes");
    }
}

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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1), acc(N+1);
    rep(i, 0, N+1){
        cin >> A[i];
        if(i == 0) acc[i] = A[i];
        else acc[i] = acc[i-1] + A[i];
    }
    ll ans = 0, par = 0;
    rep(i, 0, N+1){
        ll upper;
        if(i == 0) upper = min(1LL, acc[N]);
        else upper = min(2 * par, acc[N] - acc[i-1]);
        if(upper < A[i]){
            cout << -1 << endl;
            return 0;
        }
        ans += upper;
        par = upper - A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4792
h,w,k=map(int,input().split())
mod=10**9+7
fib=[1,1]
for i in range(6):
  fib.append(fib[-2]+fib[-1])
dp=[[0]*w for i in range(h+1)]
dp[0][0]=1
for i in range(h):
  for j in range(w):
    if w==1:
      dp[i+1][j]=dp[i][j]
    elif j==0:
      dp[i+1][j]=(dp[i][j]*fib[j]*fib[w-j-1]+dp[i][j+1]*fib[j]*fib[w-j-2])%(mod)
    elif j==w-1:
      dp[i+1][j]=(dp[i][j-1]*fib[j-1]*fib[w-j-1]+dp[i][j]*fib[j]*fib[w-j-1])%(mod)
    else:
      dp[i+1][j]=(dp[i][j-1]*fib[j-1]*fib[w-j-1]+dp[i][j]*fib[j]*fib[w-j-1]+dp[i][j+1]*fib[j]*fib[w-j-2])%(mod)
print(dp[h][k-1])

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

class WeightedUnionFind{
public:
	vector<int> Parent;
	vector<int> Size;
	vector<long long> Weight;
	WeightedUnionFind(int n){
		++n;
		Parent.resize(n, -1);
		Size.resize(n, 0);
		Weight.resize(n, 0);
	}

	int find(int x){
		if(Parent[x] == -1) return x;
		int pastparent = Parent[x];
		Parent[x] = find(Parent[x]);
		Weight[x] += Weight[pastparent];
		return Parent[x];
	}

	bool unite(int x, int y, long long z){ // a[y] - a[x] == z
		int sx = x, sy = y;
		x = find(x);
		y = find(y);
		if(x == y) return false;
		if(Size[x] < Size[y]){
			Parent[x] = y;
			Size[y] += Size[x];
			Weight[x] = z + Weight[sy] - Weight[sx];
		}else{
			Parent[y] = x;
			Size[x] += Size[y];
			Weight[y] = - z - Weight[sy] + Weight[sx];
		}
		return true;
	}

	bool united(int x, int y){
		return find(x) == find(y);
	}

	long long cost(int x, int y){
		assert(united(x, y));
		return Weight[x] - Weight[y];
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	WeightedUnionFind wuf(n);
	while(q--){
		int t;
		cin >> t;
		if(t == 0){
			int x, y, z;
			cin >> x >> y >> z;
			wuf.unite(x, y, z);
		}else{
			int x, y;
			cin >> x >> y;
			if(!wuf.united(x, y)){
				cout << "?\n";
			}else{
				cout << wuf.cost(x, y) << "\n";
			}
		}
	}
}


Measured memory_bytes: 4392
#include<iostream>
using namespace std;
#include<map>
#define int long long int
int memo[3001][3001];
int function(int arr[][2],int initial,int final,int t)
{
	if(initial>final)
	  return 0;
	if(t<=0)
	  return 0;
	if(memo[initial][t]!=-1)
	  return memo[initial][t];
	else
	{
		int val1=0,val2=0;
		val1=arr[initial][1]+function(arr,initial+1,final,t-arr[initial][0]);
		val2=function(arr,initial+1,final,t);
		memo[initial][t]=max(val1,val2);
		return memo[initial][t];
	}
}
int32_t main()
{
	int n,t;
	cin>>n>>t;
	int i,j;
	for(i=0;i<=3000;i++)
	{
		for(j=0;j<=3000;j++)
		{
			memo[i][j]=-1;
		}
	}
	multimap<int,int> mp;
	int arr[n][2];
	for(j=0;j<n;j++)
	{
		cin>>arr[j][0]>>arr[j][1];
		mp.insert({arr[j][0],arr[j][1]});
	}
	int ptr=0;
	for(auto p:mp)
	{
		arr[ptr][0]=p.first;
		arr[ptr][1]=p.second;
		ptr++;
	}
    int answer=function(arr,0,n-1,t);
    cout<<answer<<endl;
}


Measured memory_bytes: 71040
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors


def resolve():
    n = int(input())
    l = make_divisors(n)
    print(min([x + (n // x) for x in l]) - 2)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,a,b;
    map<string,long int>mp;
    string str;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&a);
        cin>>str;
        if(a==0)
        {
            scanf("%d",&b);
            mp[str]=b;
        }
        else if(a==2) mp.erase(str);
        else cout<<mp[str]<<endl;
    }
    return 0;
}





Measured memory_bytes: 27856
n,m=map(int,input().split())
div=10**9+7
if abs(n-m)>1:
  print(0)
else:
  ans=1
  for i in range(1,n+1):
    ans=ans*i%div
  for i in range(1,m+1):
    ans=ans*i%div
  if n==m:
    ans*=2
  print(ans%div)

Measured memory_bytes: 3060
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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

int main() {
	llong N,L;
    cin >>N >> L ;
    int ix,minx=10000;
    llong ans=0;
    FOR(i,L,L+N){
        if(minx>abs(i)){
            minx=abs(i);
            ix=i;
        }
        ans+=i;
    }
    ans-=ix;
    cout << ans << endl;



    return 0;
    




}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
MODN = int(1e9+7)

# A[i][j] i=Hまでで、j=Kにいける通り数（MOD）
A = [[0] * (W+2) for i in range(H+1)]

A[0][1] = 1

# N本の縦棒にひとつの高さで引ける組み合わせ数
def multip(N):
  tempa = [1,1,1,2,3,5,8,13,21,34,55]
  return(tempa[N+1])
  
for i in range(1,H+1):
  for j in range(1,W+2):
    if j < 1 or j > W:
      A[i][j] = 0
    else:
      A[i][j] = (A[i-1][j-1]*(multip(j-2) * multip(W-j)) + A[i-1][j]*(multip(j-1) * multip(W-j))+ A[i-1][j+1]*(multip(j-1) * multip(W-j-1))) % MODN
      
print(A[H][K])

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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { 
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); // i の各桁の和
    if (sum >= A && sum <= B) { //  i の各桁の和が A 以上 B 以下かどうか
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

H, W = map(int, input().split())
S = []
for i in [0]*H:
    l = input()
    S.append([1 if x == "#" else -1 for x in l])

bk = 0
wh = 0
def check(S, x, y):
    global bk, wh
    n = S[y][x]
    if n == 0:
        return 
    elif n == 1:
        bk += 1
    elif n == -1:
        wh += 1
    S[y][x] = 0
    if 0 < y and S[y-1][x] == -n:
        check(S, x, y-1)
    if 0 < x and S[y][x-1] == -n:
        check(S, x-1, y)
    if y < H-1 and S[y+1][x] == -n:
        check(S, x, y+1)
    if x < W-1 and S[y][x+1] == -n:
        check(S, x+1, y)
    return 

cnt = 0
for y in range(H):
    for x in range(W):
        if S[y][x] == 1:
            check(S, x, y)
            cnt += wh*bk
            wh = 0
            bk = 0
            
print(cnt)

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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,ans; string str;

int gcd(int a, int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
vi v;
int prime[1000005];
void seive(){
    for(int i=1;i<1000005;i++){
        prime[i]=1;
    }
    prime[1]=0;
    for(int i=2;i<1000005;i++){
        if(prime[i]){
            v.pb(i);
            for(int j=i*i;j<1000005;j+=i){
                prime[j]=0;
            }
        }
    }
}
int solve(){
    int a,b; cin>>a>>b;
    ans=1;
    int t=gcd(a,b);
    seive();
    rep(i,0,v.size()-1){
        if(t%v[i]==0) ans++;
        while(t%v[i]==0) t/=v[i];
    }
    if(t!=1) ans++;
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 9208
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        
        int S = sc.nextInt();
        
        System.out.print(S/3600+":"+(S%3600)/60+":"+(S%3600)%60);
        System.out.println();
        }
}


Measured memory_bytes: 26136
#!/usr/bin/env python3

import sys
import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, k = mi()
    p = 0
    for point in range(1, n+1):
        if point <= k-1:
            p += 1 / (n * pow(2, math.ceil(math.log(k / point, 2))))
        else:
            p += 1 / n
    print(p)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
int main(){
	int N;
	scan(N);
	int table[26][26];
	rep(i,26){
		rep(j,26){
			table[i][j]=4*i+7*j;
		}
	}
	int flag=0;
	rep(i,26){
		rep(j,26){
			if(table[i][j]==N){
				flag=1;
				break;
			}
		}
	}
	if(flag) prin("Yes");
	else prin("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int> flag(1000100, -1);
  int ans = 0;
  rep(i, n){
    if(flag[a[i]] == 1) continue;
    if(flag[a[i]] == 0){
      ans--;
      flag[a[i]] = 1;
      continue;
    }
    ans++;
    int x = a[i];
    flag[x] = 0;
    x += a[i];
    while(x <= 1000010){
      flag[x] = 1;
      x += a[i];
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 8008
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
//inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));

int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int& x : a)
        cin >> x;

    sort(begin(a), end(a));

    cout << a[n / 2] - a[n / 2 - 1] << endl;
}


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

int main(){
  std::vector<int> a(9,0);

  int n;
  rep(i,9)std::cin >> a[i];

  std::cin >> n;
  rep(i,n){
    int temp;
    std::cin >> temp;
    rep(i,9)if(a[i]==temp){a[i]=-1;break;}
  }

  bool flag=false;
  if(a[0]==a[1] && a[1]==a[2])flag=true;
  if(a[3]==a[4] && a[4]==a[5])flag=true;
  if(a[6]==a[7] && a[7]==a[8])flag=true;

  if(a[0]==a[3] && a[3]==a[6])flag=true;
  if(a[1]==a[4] && a[4]==a[7])flag=true;
  if(a[2]==a[5] && a[5]==a[8])flag=true;

  if(a[0]==a[4] && a[4]==a[8])flag=true;
  if(a[2]==a[4] && a[4]==a[6])flag=true;

  if(flag)std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';





  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n = sc.nextInt()
    val ws = Vector.fill(n)(sc.nextInt())
    val wss = ws.scan(0)(_ + _).tail.init
    val sum = ws.sum

    val ans = wss.map(i => math.abs(sum - i - i)).min

    println(ans)

  }

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }

  def printExecTime(process: => Unit): Unit = {
    val start = System.currentTimeMillis
    process
    debug("処理時間： " + (System.currentTimeMillis - start) + " ミリ秒")
  }

  def bitSearch[T](n: Int, choice: Vector[T]): Vector[Vector[T]] = {
    @tailrec
    def bitSearchLogic(n: Int,
                       choice: Vector[T],
                       acc: Vector[Vector[T]]): Vector[Vector[T]] = {
      if (n == 0) acc
      else {
        val newAcc =
          acc.flatMap(vec => {
            choice.map(c => vec :+ c)
          })
        bitSearchLogic(n - 1, choice, newAcc)
      }
    }

    val firstAcc = choice.map(i => Vector(i))
    bitSearchLogic(n - 1, choice, firstAcc)
  }
}


Measured memory_bytes: 27216
/************************************************
 * Au: Hany01
 * Prob: agc001a
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

template <typename T> inline T read() {
	static T _, __; static char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


int main()
{
#ifdef hany01
	freopen("agc001a.in", "r", stdin);
	freopen("agc001a.out", "w", stdout);
#endif

	int a = read<int>(), b = read<int>();
	if (a > b) swap(a, b);
	if (a <= 0 && b >= 0) puts("Zero");
	else if (b < 0) puts(((b - a + 1) & 1) ? "Negative" : "Positive");
	else puts("Positive");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

const int N= 200001;
int freq[N];

void solve() {
        int n; cin >> n;
        vector<int> v(n);
        for (auto& i: v) {
                cin >> i;
                freq[i]++;
        }

        int an= 0;
        for (int i= 0; i<= n; i++) {
                an+= freq[i]* (freq[i]- 1)/ 2;
        }

        int cur= 0;
        for (int i= 0; i< n; i++) {
                cur= an;
                int nm= v[i];

                cur-= freq[nm]* (freq[nm]- 1)/ 2;
                cur+= (freq[nm]- 1)* (freq[nm]- 2)/ 2;
                cout << cur<< "\n";
        }
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int T= 1;
        //cin >> T;
        while ( T-- ) solve();
return 0;
}


Measured memory_bytes: 6256
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr            first
#define sc            second
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
using namespace std;
int main()
{
     ll a,b,v,w,t,dis,pos,con;
     cin>>a>>v>>b>>w>>t;
     dis=abs(a-b);
     pos=v*t;
     con=dis+w*t;
     if(pos>=con)
          cout << "YES\n";
     else cout << "NO\n";
}



Measured memory_bytes: 3616