akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

int arr[103];

int main()
{
	//ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	int n; scanf("%d", &n);
	int res = 0;
	for(int i = 1; i <= n; i++) scanf("%d", &arr[i]);
	for(int i = 2; i <= n; i++)
	{
		if(arr[i] == arr[i-1])
		{
			res++;
			arr[i] = (arr[i]+1)%10000;
			if(arr[i] == 0) arr[i] = 10000;
			if(arr[i] == arr[i+1])
			{
				arr[i] = (arr[i]+1)%10000;
				if(arr[i] == 0) arr[i] = 10000;
			}
		}
	}
	printf("%d\n", res);
}












Measured memory_bytes: 256
#include<iostream>

int main(){
    int H,W;

    std::cin >> H >> W;

    while( !( (H==0) && (W==0) ) ){
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                std::cout << "#";
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
        std::cin >> H >> W;
    }
}


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

int main(){
  int n,x;
  cin >> n >> x;
  if(x<2 || x>2*n-2){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  vector<int> v;
  rep(i,2*n-1){
    if(i+1!=x)v.push_back(i+1);
  }
  rep(i,n-1){
    cout << v[n-2-i] << ' ';
  }
  cout << x << ' ';
  rep(i,n-1){
    cout << v[2*n-3-i] << ' ';
  }
  cout << endl;
return 0;}

Measured memory_bytes: 2420
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	if(n>2)cout << n / 3 << endl;
	else puts("0");


	return(0);
}

Measured memory_bytes: 256
n = int(input())
ss = input()
li = []
li1 = []
li2 = []
ans = 0
for i in range(n-2):
    f = ss[i]
    if f in li:
        continue
    li.append(f)
    for j in range(i+1,n-1):
        s = ss[j]
        if f+s in li1:
            continue
        li1.append(f+s)
        li2 = []
        for k in range(j+1,n):
            if len(li2) == 10:
                break
            t = ss[k]
            if t in li2:
                continue
            ans += 1
            li2.append(t)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  int K, N, prev, next, tmp1, tmp2;
  bool c1, c2;
  cin >> K >> N;
  vector<int> A(N), B(N);
  REP(i, N) {
    cin >> A[i];
  }
  REP(i, N) {
    c1 = false, c2 = false;
    if (i == 0) {
      prev = N-1, next = 1;
    } else if (i == N-1) {
      prev = N-2, next = 0;
    } else {
      prev = i-1, next = i+1;
    }
    if (A[i] < A[prev]) c1 = true;
    if (A[i] < A[next]) c2 = true;
    if (c1 == true) {
      tmp1 = A[prev] - A[i];
    } else {
      tmp1 = A[prev] + K - A[i];
    }
    if (c2 == true) {
      tmp2 = A[next] + K - A[i];
    } else {
      tmp2 = A[i] -  A[next];
    }
    if (tmp1 < tmp2) {
      B[i] = tmp1;
    } else {
      B[i] = tmp2;
    }
  }
  sort(ALL(B));
  cout << B[0] << endl;
  return 0;
}

Measured memory_bytes: 1792
s = input()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
m = 0
decimal = 1
for j in range(1, len(s)+1):
  m += int(s[-j]) * decimal
  m %= 2019
  dic[m] += 1
  decimal *= 10
  decimal %= 2019

ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)


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

int main() {
	string s;
	int ans = 0;
	cin >> s;
	if (s[0] == '1') ans++;
	if (s[1] == '1') ans++;
	if (s[2] == '1') ans++;
	 
	cout << ans << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	double res = 0;
	REP(i, N){
		double x;
		string u;
		cin >> x >> u;
		if(u=="JPY"){
			res += x;
		}else{
			res += 380000.0 * x;
		}
	}
	printf("%.10f\n", res);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define F first
#define S second
#define ld long double
int const M=2e5+10,inf=1e9+10,mod=1e9+7;
int a[M],n;
map<int,int>cnt;
int32_t main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	int now=0,ans=0;
	cnt[now]++;
	for(int i=1;i<=n;i++)
	{
		now+=a[i];
	//	cout<<now<<endl;
		ans+=cnt[now];
		cnt[now]++;
	}
	cout<<ans;
}

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

int d,mod=1e9+7;
long long dp[10000][101][2];

long long addself(long long a,long long b)
{
    if(a+b >= mod)
        return a+b-mod;
    return a+b;
}

long long multipleofD(int index,int sum,int tight,const vector<int> &a)
{

    if(index==a.size())
        return sum==0;

    if(dp[index][sum][tight]!=-1)
        return dp[index][sum][tight];
        
    int m=tight? a[index] : 9;

    long long ans=0;
    for(int i=0;i<=m;i++)
    {
        int newtight= tight? (i==a[index]): 0;
        ans = addself(ans,multipleofD(index+1,(sum+i)%d,newtight,a));
    }
    return dp[index][sum][tight]=ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    memset(dp,-1,sizeof(dp));

    string k;
    int i,j;
    cin>>k>>d;
    vector<int> a(k.length());
    for(i=0;i<k.length();i++)
        a[i]=k[i]-'0';
    
    long long res = multipleofD(0,0,1,a);
    
    res-=1;
    if(res<0)
        res+=mod;
    cout<<res<<endl;
}

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

void rec(int n, int min_n, std::vector<int> v){
	if(n == 0){
		std::cout << v[0];
		for(int i=1;i<v.size();i++){
			std::cout << " " << v[i];
		}
		std::cout <<  std::endl;
	}

	int max_n = std::min(n, min_n);
	for(int i=max_n;i;i--){
		v.push_back(i);
		rec(n-i, i, v);
		v.erase(v.end() - 1);
	}
}

int main(){
	int n;
	while(std::cin >> n, n){
		for(int i=n;i;i--){
			rec(n-i, i, {i});
		}
	}
}

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

int main() {
	string buf;
	while (getline(cin, buf)) {
		stack<double>st;
		stringstream ss(buf);
		string c;
		while (ss >> c) {
			if (c == "+" || c == "-" || c == "*" || c == "/") {
				double a = st.top(); st.pop();
				double b = st.top(); st.pop();
				if (c == "+")st.push(b + a);
				else if (c[0] == '-')st.push(b - a);
				else if (c[0] == '*')st.push(b*a);
				else st.push(b / a);
			}
			else st.push(stod(c));
		}
		printf("%.6lf\n", st.top());
	}
}

Measured memory_bytes: 3288
#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
const int N=1000005;
int a[N],n,d,p[N],cnt;
bool isp[N];
il void gcd(ct a,ct b){return !b?d=a,void():gcd(b,a%b);}
il bool ck(ct x,ct P){
	it i,now=0;
	for(i=n;~i;--i)
		now=((0ll+now)*x%P+a[i]%P+P)%P;
	return !now;
}
il bool work(ct x){
	if(a[0]%x) return 0;
	it i;
	for(i=1;i<=8;++i) if(!ck(p[i],x)) return 0;
	for(i=1;i<=8;++i) if(!ck(rand()%1000000,x)) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);it i,j,x;
	srand(998244353);
	for(i=n;~i;--i) scanf("%d",&a[i]),gcd(a[i],d);
	d=d<0?-d:d;
	for(i=2;i<=n;++i){
		if(!isp[i]) p[++cnt]=i;
		for(j=1;(x=i*p[j])<=n&&j<=cnt;++j){
			isp[x]=1;
			if(!(i%p[j])) break;
		}
	}
	for(i=2;i*i<=d;++i)
		if(!(d%i)){
			while(!(d%i)) d/=i;
			p[++cnt]=i;
		}
	if(d>1) p[++cnt]=d;
	std::sort(p+1,p+1+cnt),cnt=std::unique(p+1,p+1+cnt)-p-1;
	for(i=1;i<=cnt;++i) if(work(p[i])) printf("%d\n",p[i]);
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b; i++)
#define MAX 1000000010
using namespace std;
typedef long long int ll;
int dp[100010];
bool visit[100010];
vector<int> adj[100010];
void dfs(int x){
	visit[x]=true;
	for(int i=0;i<adj[x].size();i++){
		int v=adj[x][i];
		if(!visit[v]){
			dfs(v);
		}
		dp[x]=max(dp[x],dp[v]+1);
	}
}
int main(){
	int n,m,a,b,x,ans=0;
	cin>>n>>m;
	f(i,0,m){
		cin>>a>>b;
		adj[a].push_back(b);
	}
	f(i,1,n+1) if(!visit[i]) dfs(i);
	f(i,1,n+1) ans=max(ans,dp[i]);
	cout<<ans;
}

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


int main(){

    int N,l,r,count = 0;;
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> l >> r;
        count += (r-l+1);

    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 1145141919;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator > (const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

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

vector<P> search(char c)
{
	vector<P> v;
	int mx = 1;
	REP(i, 8)REP(j, 8)
	{
		if (fld[i][j] != '.') continue;
		int cnt = 0;
		REP(k, 8)
		{
			int tmp = 0;
			int nx = i; int ny = j;
			while (1)
			{
				nx = nx + dx[k]; ny = ny + dy[k];
				if (nx<0 || ny<0 || nx>7 || ny>7 ||fld[nx][ny]=='.') break;
				else if (fld[nx][ny] != c)
				{
					tmp++; continue;
				}
				else
				{
					cnt += tmp;
					break;
				}
			}
		}
		if (cnt > mx)
		{
			v.clear();
			v.push_back(P(i, j));
			mx = cnt;
		}
		else if (cnt == mx)
		{
			v.push_back(P(i, j));
		}
	}
	return v;
}

bool endf()
{
	vector<P> a, b;
	a = search('x'); b = search('o');
	if (a.size() == 0 && b.size() == 0) return false;
	else return true;
}

void majo()
{
	vector<P> v = search('x');
	int x, y;
	if (v.size() > 0)
	{
		x = v.back().first; y = v.back().second;
		fld[x][y] = 'x';
		REP(k, 8)
		{
			vector<P> w;
			int nx = x; int ny = y;
			while (1)
			{
				nx = nx + dx[k]; ny = ny + dy[k];
				if (nx<0 || ny<0 || nx>7 || ny>7 || fld[nx][ny] == '.') break;
				else if (fld[nx][ny] == 'o')
				{
					w.push_back(P(nx, ny)); continue;
				}
				else
				{
					REP(i, w.size())
					{
						fld[w[i].first][w[i].second] = 'x';
					}
					break;
				}
			}
		}
	}

}

void mami()
{
	vector<P> v = search('o');
	int x, y;
	if (v.size() > 0)
	{
		x = v[0].first; y = v[0].second;
		fld[x][y] = 'o';
		REP(k, 8)
		{
			vector<P> w;
			int nx = x; int ny = y;
			while (1)
			{
				nx = nx + dx[k]; ny = ny + dy[k];
				if (nx<0 || ny<0 || nx>7 || ny>7 || fld[nx][ny] == '.') break;
				else if (fld[nx][ny] == 'x')
				{
					w.push_back(P(nx, ny)); continue;
				}
				else
				{
					REP(i, w.size())
					{
						fld[w[i].first][w[i].second] = 'o';
					}
					break;
				}
			}
		}
	}

}

int main()
{
	REP(i, 8) cin >> fld[i];
	for (int i = 0; endf(); i++)
	{
		if (i % 2) majo();
		else mami();
	}
	REP(i, 8) cout << fld[i] << endl;
	return 0;
}

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

int main() {
  int N, X = 0;
  cin >> N;
  rep(i, N) {
    int l, r;
    cin >> l >> r;
    rep(i, r-l+1){
      X+=1;
    }
  }
  cout << X << endl;
}


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

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

    int x, a, b;
    cin >> x >> a >> b;
    //a >=b
    // a < b <=a+x
    // b > a + x
    
    
    if (a >= b)
        cout << "delicious";
    else if (a+x >=b)
        cout << "safe";
    else
        cout << "dangerous";
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
class Dice{
private:
	int dice[6];
/*	int direction[4][6]={
		{3,1,0,5,4,2},
		{1,5,2,3,0,4},
		{4,0,2,3,5,1},
		{2,1,5,0,4,3}};
*/
	int direction[4][6];
public:
	Dice(int dice[6]);
	void rotate(string cmd);
	void rotate(char cmd);
	int getTop();
};

Dice::Dice(int dice[6]){
	for(int i=0;i<6;i++){
		this->dice[i]=dice[i];
	}
	int tmp[4][6]={
		{3,1,0,5,4,2},
		{1,5,2,3,0,4},
		{4,0,2,3,5,1},
		{2,1,5,0,4,3}};
	for(int i=0;i<4;i++){
		for(int j=0;j<6;j++){
			direction[i][j]=tmp[i][j];
		}
	}
}

void Dice::rotate(string cmd){
	int length=cmd.length();
	for(int i=0;i<length;i++){
		rotate(cmd[i]);
	}
}

void Dice::rotate(char cmd){
	int tmp[6];
	int index;
	switch(cmd){
		case 'E':index=0;break;
		case 'N':index=1;break;
		case 'S':index=2;break;
		case 'W':index=3;break;
		default:return;
	}
	for(int i=0;i<6;i++){
		tmp[i]=dice[i];
	}
	for(int i=0;i<6;i++){
		dice[i]=tmp[direction[index][i]];
	}
}

int Dice::getTop(){
	return dice[0];
}

int main(){
	int tmp[6];
	for(int i=0;i<6;i++){
		cin>>tmp[i];
	}
	Dice dice(tmp);
	string cmd;
	cin>>cmd;
	dice.rotate(cmd);
	cout<<dice.getTop()<<endl;
	return 0;
}

Measured memory_bytes: 1212
# 石の番号は0-initial
N=int(input())
S=input()
# 0~iまでの石を白'.'，i+1~N-1までの石を黒'#'にする必要がある
L=[0] # iより左の黒石の個数
for i in range(N):
    L.append(L[-1]+int(S[i]=='#'))
R=[0] # i-1より右（i以右）の白石の個数（右から数えて後で反転させる）
for i in range(N-1,-1,-1):
    R.append(R[-1]+int(S[i]=='.'))
R=R[::-1]

ans=min([L[i]+R[i] for i in range(N+1)])

print(ans)

Measured memory_bytes: 61588
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N, K; cin >> N >> K;
	if (N % 2 != 0) N = N + 1;

	if (N / 2 >= K)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 8064
L = t = int(input())
X = []
B = 4
while L:
    X.append(L%B)
    L//=B

E = []
N = len(X)*2
for i, x in enumerate(X[:-1]):
    r = B**i
    t -= r*x
    for k in range(0, x):
        E.append((2*i+1, 2*i+2, r*k))

    E.append((2*i+2, 2*i+3, 0))

    for k in range(x, B):
        E.append((2*i+1, 2*i+3, r*k))

    E.append((2*i+2, N, t))

for k in range(0, X[-1]):
    E.append((N-1, N, B**(len(X)-1)*k))

print(N, len(E))
for e in E:
    print(*e)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

int a, b;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() { 

  cin >> a >> b;
  int g = gcd(a, b);

  long long ans = 1ll * a * b / g;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import itertools
n, m, x = list(map(int, input().split()))
books=[]
results=[]
for i in range(n):
    books.append(list(map(int, input().split())))
# 全ての本を買ってもXwo満たせないアルゴリズムがあるか検査
for i in range(m):
    skill=0
    for j in books:
        skill+=j[i+1]
    if skill<x:
        print(-1)
        exit()

# 本の組み合わせをためす
index=[]
for i in range(n):
    index.append(i)
patarns=[]
for i in range(1,n+1):
    patarns.append(itertools.combinations(index,i))
    #print(list(a))

# 全パターン検査
for patarn in patarns:
    #flg=True
    # ある本の組み合わせの時検査
    for bk_indexies in patarn:
        # すべてのアルゴリズム
        flg=True
        for arg in range(m):
            point=0
            money=0
            for bk_index in bk_indexies:
                # アルゴリズムargの合計得点
                point+=books[bk_index][arg+1]
                money+=books[bk_index][0]
            #print(arg,money,point)
            if point<x:
                flg=False
        if flg:
            #print(money,list(patarn))
            results.append(money)
#print(results)
print(min(results))


Measured memory_bytes: 9264
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int j = n-1; j >= 0; j--){
        if(j == n-1){
            cout << a[j];
        }else{
            cout << " " << a[j];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
	IOS;
	int n,m;
	cin>>n>>m;
	if(n==m){
		cout<<"Yes";
	}
	else cout<<"No";
}


Measured memory_bytes: 256
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;

int main(){
    //std::stack<int> stack;
    int n;
    cin >> n;
    double ans = n*6.28;
    cout << ans << endl;
    return 0;
}





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

int main()
{
    int N;
    cin >> N;
    pair<pair<string, int>, int> p[N];

    string s; int t;
    rep(i, N) {
        cin >> s >> t;
        p[i] = make_pair(make_pair(s, -t), i+1);
    }

    sort(p, p+N);

    rep(i, N) {
        cout << p[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
S=input()
A=[]
flag=0
cnt=0
for i in range(n):
    if S[i]=="A":
        flag=1
    elif S[i]=="C":
        if flag==1:
            cnt+=1
        flag=0
    else:
        flag=0
    A.append(cnt)
    
for i in range(q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    print(A[r]-A[l])

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

int main() {
  int N, A, B, k, x;
  cin >> N >> A >> B;
  
  k = A*N;
  
  if (k >= B) {
    x = B;
  }
  else {
    x = k;
  }
  cout << x << endl;
}

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

int main(){
  long long int n;
  cin >>n;
  long long int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  deque<long long int>b;
  for(int i=0;i<n;i++){
    if(i%2==n%2)b.push_back(a[i]);
    else b.push_front(a[i]);
  }
  for(int i=0;i<n;i++)
    cout << b[i] <<" ";
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

string s,t = "Yes";
ll n,m,a,b;
char c;

int main () {
  cin >> n >> m;
  if(n != m) t = "No";
  cout << t << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int main() {
  // 入力
  std::string s;
  std::cin >> s;

  // 処理
  std::string ans;
  int w = std::count(s.begin(), s.end(), 'o');
  int l = std::count(s.begin(), s.end(), 'x');
  int nokori = 15 - w -l;

  if (w + nokori >= 8) {
    ans = "YES";
  } else {
    ans = "NO";
  }
  // 出力
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
const int mod = 998244353;
 
LL n, a, b, k;
LL ans, tot;
LL f[300000 + 47], g[300000 + 47];
 
LL qpw(LL a, LL b) {
	LL res = 1;
	while(b) {
		if(b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
 
int main() {
	scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
	f[1] = 1;
	for(LL i = 2; i <= n; i++) f[i] = f[i - 1] * i % mod;
	g[n] = qpw(f[n], mod - 2);
	for(LL i = n - 1; i >= 1; i--) g[i] = g[i + 1] * (i + 1) % mod;
	g[0] = 1;
	for(LL i = 0; i <= n && i * a <= k; i++) {
		LL num = k - i * a;
		if(num % b == 0 && num / b <= n) ans = (ans + f[n] * g[i] % mod * g[n - i] % mod * f[n] % mod * g[num / b] % mod * g[n - num / b] % mod) % mod;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N >> M;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
void solve() {
  int K=M;
  vb.resize(N + 1);
  vb[0] = 0;
  rep(i, 0, N - 1) { vb[i + 1] = vb[i] + va[i]; }
  priority_queue<int> pq;

  vi wa;
  rep(i, 0, N - 1) {
    // vb[i] ~ vb[i+K]

    if (i + K  <=  N) {
      pq.push(vb[i+K] - vb[i]);
    }
  }
  int ansp = pq.top();
  double ans = (ansp + K)/(2.0);
  printf("%lf\n",ans);

}
signed main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 5492
import java.util.*;

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

    long ans = 0;

    ans += x/11 * 2;
    x %= 11;

    ans += x/6;
    x %= 6;
    
    ans += x/5;
    if (x%5 != 0) {
      ans++;
    }
    
    System.out.println(ans);
  }
}

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

namespace CSharpSample01
{


    class Program
    {
        
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

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

                int t = i;                
                int cc = 0;
                while (t > 0)
                {
                    cc += t % 6;
                    t = t / 6;
                }               
                
                t = N - i;               
                while (t > 0)
                {
                    cc += t % 9;
                    t = t / 9;
                }

                if (ans > cc) ans = cc;
            }

            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 11092
import sys
a,b,c = map(int,input().split())
if a == b == c and a%2 == b%2 == c%2== 0:
    print(-1)
    sys.exit()
count = 0
while a%2 == 0 and b%2 == 0 and c%2 == 0:
    x = (b+c)//2
    y = (a+c)//2
    z = (a+b)//2
    a,b,c = x,y,z
    count+=1
    #print(a,b,c)
print(count)

Measured memory_bytes: 3064
N = int(input())
S = input()
ans = [S[1:].count("E")]
for i in range(1, N):
	tmp = ans[i - 1]
	if S[i - 1] == "W":
		tmp += 1
	if S[i] == "E":
		tmp -= 1
	ans.append(tmp)
print(min(ans))


Measured memory_bytes: 15564
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let s = it.next().unwrap().chars();
    let t = it.next().unwrap().chars();
    println!(
        "{}",
        s.zip(t)
            .map(|(x, y)| if x != y { 1 } else { 0 })
            .sum::<usize>()
    );
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2492
#include <stdio.h>

/*上に進んできて曲がれない*/
#define UP_NOC 0
/*上に進んできて曲がれる*/
#define UP_OKC 1
/*右に進んできて曲がれない*/
#define RIGHT_NOC 2
/*右に進んできて曲がれる*/
#define RIGHT_OKC 3

int main(void) {
	int data[100][100][4];
	int nanboku,touzai;
	int x,y;
	while(1) {
		scanf("%d %d",&nanboku,&touzai);
		if(nanboku==0 && touzai==0)break;
		/*初期化*/
		for(x=0;x<nanboku;x++) {
			for(y=0;y<touzai;y++) {
				data[x][y][UP_NOC]=0;
				data[x][y][UP_OKC]=0;
				data[x][y][RIGHT_NOC]=0;
				data[x][y][RIGHT_OKC]=0;
			}
		}
		data[0][1][UP_OKC]=1;
		data[1][0][RIGHT_OKC]=1;
		/*計算*/
		for(x=0;x<nanboku;x++) {/*左から右へ順に計算する*/
			for(y=0;y<touzai;y++) {/*上下逆転しても数は変わらないだろう*/
				/*オーバーフロー防止*/
				data[x][y][UP_NOC]=data[x][y][UP_NOC]%100000;
				data[x][y][UP_OKC]=data[x][y][UP_OKC]%100000;
				data[x][y][RIGHT_NOC]=data[x][y][RIGHT_NOC]%100000;
				data[x][y][RIGHT_OKC]=data[x][y][RIGHT_OKC]%100000;
				/*右端でなければ*/
				if(x<nanboku-1) {
					/*右に曲がらずに進む（次に曲がれる）*/
					data[x+1][y][RIGHT_OKC]+=data[x][y][RIGHT_NOC];
					data[x+1][y][RIGHT_OKC]+=data[x][y][RIGHT_OKC];
					/*右に曲がって進む（次に曲がれない）*/
					data[x+1][y][RIGHT_NOC]+=data[x][y][UP_OKC];
				}
				/*一番下（本来の一番上）でなければ*/
				if(y<touzai-1) {
					/*上に曲がらずに進む（次に曲がれる）*/
					data[x][y+1][UP_OKC]+=data[x][y][UP_NOC];
					data[x][y+1][UP_OKC]+=data[x][y][UP_OKC];
					/*上に曲がって進む（次に曲がれない）*/
					data[x][y+1][UP_NOC]+=data[x][y][RIGHT_OKC];
				}
			}
		}
		printf("%d\n",(data[nanboku-1][touzai-1][UP_NOC]+
			data[nanboku-1][touzai-1][UP_OKC]+
			data[nanboku-1][touzai-1][RIGHT_NOC]+
			data[nanboku-1][touzai-1][RIGHT_OKC])%100000);
	}
	return 0;
}

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

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int a = stdin.nextInt();
    int b = stdin.nextInt();
    int c = stdin.nextInt();
    int[] arr = { a, b, c };

    Arrays.sort(arr);
    System.out.println(arr[0] + " " + arr[1] + " " + arr[2]);
  }

}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 100;
int n;
tuple<string,int,int> a[MAX_N];

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n) {
    string x; int y;
    cin >> x >> y;
    a[i] = make_tuple(x,-y,i+1);
  }

  sort(a,a+n);

  forn(i,n)
    cout << get<2>(a[i]) << endl;


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int x,y,z,i,j,k;
    scanf("%d%d%d",&x,&y,&z);
    i=max(x,y);
    i=max(i,z);
    j=min(x,y);
    j=min(j,z);
    printf("%d\n",i*10+x+y+z-i-j+j);
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int tmp = 1;

  for (int i=0; i<N; i++){
    if (tmp <= K) tmp*=2;
    else tmp += K;
  }
  cout << tmp << endl;

}


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

using i64 = int64_t;

int main(){
    string s;
    cin >> s;
    stack<char> st;
    for(auto c: s){
        if(c == '(')st.push(c);
        else if(c == ')')st.pop();
        else if(c == '*'){
            cout << st.size() << endl;
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 3208
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    t = 1
    if N%2 == 0:
        t = 2
    AB = [ tuple( map( lambda x: int(x)*t, input().split())) for _ in range(N)]
    A = [ab[0] for ab in AB]
    B = [ab[1] for ab in AB]
    A.sort()
    B.sort()
    if t == 1:
        m = A[N//2]
        M = B[N//2]
    else:
        m = (A[N//2-1]+A[N//2])//2
        M = (B[N//2-1]+B[N//2])//2
    print(M-m+1)
if __name__ == '__main__':
    main()


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

int di[2] = {1, 0};
int dj[2] = {0, 1};

int main(){
    int h, w, n;
    while(cin >> h >> w >> n, h+w+n){
        int mat[h][w], dp[h+1][w+1];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> mat[i][j];
                dp[i][j] = 0;
            }
        }
        dp[0][0] = n-1;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(dp[i][j] == 0)   continue;
                int tmp = mat[i][j];
                mat[i][j] = (mat[i][j]+dp[i][j])%2;
                int ni = i+di[tmp], nj = j+dj[tmp];
                dp[ni][nj] += (dp[i][j]+1)/2;
                ni = i+di[1-tmp], nj = j+dj[1-tmp];
                dp[ni][nj] += dp[i][j]/2;
            }
        }
        int ansi = 0, ansj = 0;
        while(ansi != h && ansj != w){
            if(mat[ansi][ansj] == 0)    ansi++;
            else                        ansj++;
        }
        cout << ansi+1 << " " << ansj+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 10924
#include <iostream>

using namespace std;

int main()
{
	int N, count = 0;
	double ans;
	
	cin >> N;
	
	for (int i = 1; i <= N; ++i) {
		if (i % 2 != 0) {
			count++;
		}
	}
	
	ans = (double)count / N;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int factorize(long long n, long long p[], int m[])
{
	int k;
	long long i;
	for (i = 2, k = 0; i * i <= n; i++) {
		if (n % i != 0) continue;
		p[k] = i;
		for (m[k] = 0; n % p[k] == 0; m[k]++, n /= p[k]);
		k++;
	}
	if (n > 1) {
		p[k] = n;
		m[k++] = 1;
	}
	return k;
}

// Find an integer x such that ax + by = c with some integer y
long long solve(long long a, long long b, long long c)
{
	if (b % a == 0) return c / a;
	else return (c - solve(b % a, a, c % a) * b) / a;
}

int main()
{
	long long N;
	scanf("%lld", &N);
	if (N == 1) {
		printf("1\n");
		fflush(stdout);
		return 0;
	}

	long long p[101];
	int m[101], k = factorize(N * 2, p, m);
	
	int i, j, l[101] = {};
	long long x = 1, y, ans = N * 2;
	__int128 tmp;
	m[k] = 1;
	while (l[k] == 0) {
		y = N * 2 / x;
		tmp = solve(x, y, 1);
		if (tmp < 0) tmp = (tmp % (N * 2) + N * 2) % (N * 2);
		tmp = (x * tmp + N * 2 - 1) % (N * 2);
		if (tmp > 0 && ans > tmp) ans = tmp;
		
		for (i = 0; i < k && l[i] == m[i]; i++);
		for (j = 0; j < m[i]; j++) x *= p[i];
		for (l[i] = m[i], i--; i >= 0; l[i--] = 0) {
			for (j = 0; j < m[i]; j++) x /= p[i];
		}
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1712
#include <stdio.h>
#include <string.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a,b,i;
	scanf("%d",&a);
	if(a/100<13){
		if(a/100==0){
			if(a%100==0){
				b=3;
			}else if(a%100<13){
				b=1;
			}else{
				b=3;
			}
		}else{
			if(a%100==0){
				b=2;
			}else if(a%100<13){
				b=4;
			}else{
				b=2;
			}
		}
	}else{
		if(a%100==0){
			b=3;
		}else if(a%100<13){
			b=1;
		}else{
			b=3;
		}
	}
	if(b==1){
		printf("YYMM");
	}else if(b==2){
		printf("MMYY");
	}else if(b==3){
		printf("NA");
	}else{
		printf("AMBIGUOUS");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s,int v,vector<int>&d,whei(edge)&G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size();i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int n;
	cin >> n;
	hei(llint) a(n+1);
	map<llint, llint> S;
	S[0] = 1;
	rep(i, 0, n) {
		llint z;
		cin >> z;
		a[i + 1] = a[i] + z;
		S[a[i + 1]]++;
	}
	llint ans = 0;
	rep(i, 0, n+1) {
		ans += (S[a[i]]-1);
	}
	ans /= 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14336
r=lambda x:x if u[x]<0else r(u[x])
n,m,*e=map(int,open(0).read().split())
u=[-1]*-~n
t=n*~-n//2
a=[t]
for x,y in zip(e[-2:1:-2],e[:1:-2]):
 x,y=sorted((r(x),r(y)))
 if x!=y:t-=u[x]*u[y];u[x]+=u[y];u[y]=x
 a+=t,
print(*a[::-1],sep='\n')

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

int main() {
    int n, m;
    vector<string> s, t;

    cin >> n;
    s = vector<string>(n);
    for (int i = 0; i < n; i++) {
        cin >> s.at(i);
    }

    cin >> m;
    t = vector<string>(m);
    for (int i = 0; i < m; i++) {
        cin >> t.at(i);
    }

    /*
    for (int i = 0; i < n-1; i++) {
        cout << s.at(i) << " ";
    }
    cout << s.at(n-1) << endl;

    for (int i = 0; i < m-1; i++) {
        cout << t.at(i) << " ";
    }
    cout << t.at(m-1) << endl;
    */

    int max_score, score;
    string w;
    max_score = 0;
    for (int i = 0; i < n; i++) {
        score = 0;
        w = s.at(i);
        for (int j = 0; j < n; j++) {
            if (w == s.at(j)) score += 1;
        }
        for (int j = 0; j < m; j++) {
            if (w == t.at(j)) score -= 1;
        }
        if (score > max_score) max_score = score;
    }
    cout << max_score << endl;
}


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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < 111; i++) {
      
    if (N % 10 == (N % 100)/10 && N % 10 == N/100) {
      cout << N << endl;
      break;
    }
    N++;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)))
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int n;
int a[200005];
int ans;
map<int,int> mp;
/*---main code---*/

void sol(int x)
{
//	cout<<1<<'\n';
	if(mp[x]==0)
	{
		return ;
	}
	mp[x]--;
	int p=1;
	while(p<=x)
	{
		p<<=1;
	}
	if(mp[p-x])
	{
		ans++;
		mp[p-x]--;
	}
	return ;
}

int main()
{
	FIO;
//	cout<<1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
//	cout<<1;
	sort(a,a+n);
//	cout<<1;
	for(int i=n-1;i>=0;i--)
	{
		sol(a[i]);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 19840
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=100005;
const LL mod=1000000007;
int a[N][2],cnt[N];
LL jc[N],njc[N];
LL sqrr(LL x){return x*x%mod;}
LL ksm(LL x,LL y){
    if (y==0) return 1;if (y==1) return x;
    if (y%2==0) return sqrr(ksm(x,y/2));return sqrr(ksm(x,y/2))*x%mod;
}
LL ny(LL x){return ksm(x,mod-2);}
LL C(int n,int m){
    if (n<m) return 0;if (n==m) return 1;
    return jc[n]*njc[m]%mod*njc[n-m]%mod;
}
int main(){
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,n,tt,m;
    scanf("%d",&n);
    jc[0]=njc[0]=1;
    for (i=1;i<=n+1;i++) {jc[i]=jc[i-1]*((LL)i)%mod;njc[i]=ny(jc[i]);}
    for (i=1;i<=n+1;i++){
        int x;scanf("%d",&x);
        a[x][cnt[x]++]=i;
        if (cnt[x]==2) tt=x;
    }
    m=n-(a[tt][1]-a[tt][0]);
    for (i=1;i<=n+1;i++) printf("%d\n",(C(n+1,i)-C(m,i-1)+mod)%mod);
    
  //  system("pause");
    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    char n[3];
    cin >> n;
    for (int i = 0; i < 3; i++)
    {
        if (n[i] == '1')
        {
            n[i] = '9';
        }
        else if (n[i] == '9')
        {
            n[i] = '1';
        }
    }
    cout << n << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    from collections import defaultdict
    from heapq import heappop, heappush

    def greedy(L):
        ret = 0
        q = []
        for k, gain in L:
            for g in gain:
                ret += g
                heappush(q, g)
            while len(q) > k:
                g = heappop(q)
                ret -= g
        return ret

    for _ in [0]*int(input()):
        N = int(input())

        ans = 0
        pos = defaultdict(list)
        neg = defaultdict(list)
        for _ in range(N):
            K, L, R = map(int, input().split())
            if L > R:
                ans += R
                pos[K].append(L-R)
            elif L < R:
                ans += L
                neg[N-K].append(R-L)
            else:
                ans += L

        pos = sorted(pos.items())
        neg = sorted(neg.items())
        ans += greedy(pos)
        ans += greedy(neg)

        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 125724
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<cstring>
using namespace std;
#define N 100010
int head[N];
struct aa{int to,next;
}a[N*2];
int num,i,n,x,y;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
    {
        if (ch=='-') f=-1;
        ch=getchar();
    }
    while (ch<='9'&&ch>='0')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void write(int x)
{
    if (x<0) putchar('-'),x=-x;
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
inline void add(int x,int y)
{
				num++;
				a[num].next=head[x];
				a[num].to=y;
				head[x]=num;
}
inline int sg(int x,int fa)
{
				int now=0,i,y;
				for (i=head[x];i;i=a[i].next)
				{
								y=a[i].to;
								if (y==fa) continue;
								now^=(sg(y,x)+1);
				}
				return now;
}
int main()
{
				n=read();
				for (i=1;i<n;i++)
				{
								x=read();
								y=read();
								add(x,y);
								add(y,x);
				}
				if (sg(1,1)) puts("Alice");
				else puts("Bob");
}
/*

*/


Measured memory_bytes: 4224
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#define ll long long
#define gt getchar()
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline int in()
{
    int k=0;char ch=gt;
    while(ch<'-')ch=gt;
    while(ch>'-')k=k*10+ch-'0',ch=gt;
    return k;
}
const int YL=1e9+7,M=2e7+5,N=2e5+5;
inline int MO(const int &a){return a>=YL?a-YL:a;}
int ksm(int a,int k){int r=1;while(k){if(k&1)r=1ll*r*a%YL;a=1ll*a*a%YL,k>>=1;}return r;}
int fac[M],fnv[M],n,f[M],a[N],b[N];
inline int C(int x,int y){return y>x?0:1ll*fac[x]*fnv[y]%YL*fnv[x-y]%YL;}
int dp[4005][4005];
const int B=2001,inv=YL+1>>1;
int main()
{
	n=in();
	int T=16000;fac[0]=fnv[0]=1;
    for(int i=1;i<=T;++i)fac[i]=1ll*fac[i-1]*i%YL;fnv[T]=ksm(fac[T],YL-2);
    for(int i=T;i>=1;--i)fnv[i-1]=1ll*fnv[i]*i%YL;
	for(int i=1;i<=n;++i)
	{
	    a[i]=in(),b[i]=in();
	    ++dp[B-a[i]][B-b[i]];
	}
	for(int i=1;i<=B<<1;++i)
	    for(int j=1;j<=B<<1;++j)
	        dp[i][j]=MO(dp[i][j]+MO(dp[i-1][j]+dp[i][j-1]));
	int ans=0;
	for(int i=1;i<=n;++i)
	    ans=MO(MO(ans+dp[B+a[i]][B+b[i]]-C(a[i]+b[i]<<1,a[i]<<1))+YL);
	printf("%d\n",1ll*inv*ans%YL);
	return 0;
}


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

using namespace std;

bool isPrime(int x)
{
	if (x == 1) { return false; }
	if (x == 2) { return true; }
	if (x % 2 == 0) { return false; }

	for (int i = 3; i * i <= x; i +=2) {
		if (x % i == 0) {
			return false;
		}
	}

	return true;
}

int main()
{
	while (1) {
		int a, d, n;
		cin >> a >> d >> n;

		if (a == 0 && d == 0 && n == 0) {
			break;
		}

		int count = 0;
		for (int i = a; count < n; i += d) {
			if (isPrime(i)) {
				++count;
				if (count == n) {
					cout << i << endl;
					break;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int n,a[100];
  cin>>n;
  for (int i(0);i<n;i++) cin>>a[i];
  sort(a,a+n,greater<int>());
  int b(0),c(0);
  for (int i(0);i<n;i++){
    if (i%2==0) b+=a[i];
    else c+=a[i];
  }
  cout << b - c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  ll n;
  ll ans;
  cin>>n;
  ans=(n)*(n-1)/2;
  if(n==2)ans=1;
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int N; cin >> N;
    int a, cnt = 0;
    for(int i=0;i<N;i++){
        cin >> a;
        if(a%2 == 0) cnt++;
    }
    int ans = pow(3,N) - (1<<cnt);
    cout << ans << endl;

    return 0;

}

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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

int n;
int a[10005], b[10005];
ll suma, sumb, sumd;

int main()
{
	scanf("%d", &n);
	for(int i=0; i<n; i++) {
		scanf("%d", &a[i]);
		suma+=a[i];
	}
	for(int i=0; i<n; i++) {
		scanf("%d", &b[i]);
		sumb+=b[i];
	}
	for(int i=0; i<n; i++) {
		if(b[i]>=a[i]) {
			sumd+=(b[i]-a[i])/2+(b[i]-a[i])%2;
		}
	}
	if(sumb-suma>=sumd) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 384