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

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(27) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion



int main() {
	int n; put n;
	vi t(n); rep(i, n) put t[i];
	vi a(n); rep(i, n) put a[n-1-i];
	ll ans = 1;
	vi mint(n);
	vi maxt(n);
	mint[0] = t[0];
	maxt[0] = t[0];
	vi mina(n);
	vi maxa(n);
	mina[0] = a[0];
	maxa[0] = a[0];

	if (n == 1) {
		if (t[0] == a[0]) {
			putans(1);
		}
		else {
			putans(0);
		}
		goto END;
	}

	rep(i, n-1) {
		if (t[i + 1] != t[i]) {
			mint[i + 1] = t[i + 1];
			maxt[i + 1] = t[i + 1];
		}
		else {
			mint[i + 1] = 1;
			maxt[i + 1] = t[i + 1];
		}
	}
	rep(i, n - 1) {
		if (a[i + 1] != a[i]) {
			mina[i + 1] = a[i + 1];
			maxa[i + 1] = a[i + 1];
		}
		else {
			mina[i + 1] = 1;
			maxa[i + 1] = a[i + 1];
		}
	}
	rep(i, n) {
		ll x = min(maxa[i], maxt[n - 1 - i]);
		ll y = max(mina[i], mint[n - 1 - i]);
		dbg2(x, y);
		if (x < y) {
			putans(0);
			goto END;
		}
		ans = ( ans* ( x - y + 1 )) % MOD;
	} 
	putans(ans);

END: 
	return 0;
}



//
//vi v;
//vi w; ;
//ll nz1() {
//	return 0;
//}
//
//ll nz2() {
//	ll dp[201][1000*200+1];
//
//}
//
//ll nz3() {
//
//}
//	int n, wkazu; put n >> wkazu;
//	v.resize(200); 
//	w.resize(200);
//	rep(i, n) {
//		put v[i] >> w[i];
//	}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  vector<int> b(n);
  REP(i,n+1) cin >> a[i];
  REP(i,n) cin >> b[i];
  b.push_back(0);

  ll sum = 0;

  REP(i,n){

    if(b[i]-a[i] <= 0){
      sum += b[i];
    }
    else if(b[i]-a[i] > 0){
      sum += a[i];
      sum += min(b[i]-a[i],a[i+1]);
      a[i+1] = max(0, a[i+1]-b[i] + a[i]);
    }
    // cout << sum << endl;
  }

  cout << sum << endl;


  return 0;
}


Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e5 + 44;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;

int w[N];

long long v[N];

long long dp[111][N];

int main () {
	boost;
	int n, m;
	cin >> n >> m;
	for (int i = 0 ; i < n ; ++ i) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0 ; i < n ; ++ i) {
		for (int j = 0 ; j <= m ; ++ j) {
			if (i)
				dp[i][j] = dp[i - 1][j];
			if (j >= w[i]) {
				if (i)
					dp[i][j] = max (dp[i][j], dp[i - 1][j - w[i]] + v[i]);
				else
					dp[i][j] = max (dp[i][j], v[i]);
			}
		}
	}
	cout << dp[n - 1][m];
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

#define P2 pair<int,pair<int,int>>
int N,M,L;
 
signed main(){
	IOS();
	vector<int>ans;
	while(cin>>N>>M>>L,N||M||L){
		vector<pair<int,pair<int,int>>>g[N];
		rep(i,0,M){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			a--;b--;
			g[a].push_back({b,{c,d}});
			g[b].push_back({a,{c,d}});
		}
		int kiken[N][L+1];
		rep(i,0,N)rep(j,0,L+1)kiken[i][j] = INF;
		kiken[0][0] = 0;  //dist(now,cost);
		priority_queue<P2,vector<P2>,greater<P2>>que;
		que.push({0,{0,0}});
		while(!que.empty()){
			int now = que.top().se.fi;
			int usedMoney = que.top().se.se;
			int osoware = que.top().fi;
			que.pop();
			if(kiken[now][usedMoney]!=osoware)continue;
			for(auto e:g[now]){
				if(e.se.fi+usedMoney<=L){
					if(osoware<kiken[e.fi][usedMoney+e.se.fi]){
						kiken[e.fi][usedMoney+e.se.fi] = osoware;
						que.push({kiken[e.fi][usedMoney+e.se.fi],{e.fi,usedMoney+e.se.fi}});
					}
				}
				if(osoware+e.se.se<kiken[e.fi][usedMoney]){
					kiken[e.fi][usedMoney] = osoware+e.se.se;
					que.push({kiken[e.fi][usedMoney],{e.fi,usedMoney}});
				}
			}
		}
		int mi = INF;
		rep(i,0,L+1)chmin(mi,kiken[N-1][i]);
		ans.push_back(mi);
	}
		
	for(auto e:ans){
		cout<<e<<endl;
	}
}


Measured memory_bytes: 4516
#include <stdio.h>

int main() {
  int N, i, memo;
  int A, T, min = 100000000;
  int H[1000], temp[1000];
  scanf("%d", &N);
  scanf("%d %d", &T, &A);
  for(i = 0; i < N; i++) {
    scanf("%d", &H[i]);
    temp[i] = 1000 * T - 6 * H[i] - 1000 * A;
    if(temp[i] < 0) {
       temp[i] *= -1;
    }
    if(min > temp[i]) {
      min = temp[i];
      memo = i + 1;
    }
  }
  printf("%d\n", memo);
  return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;
const ll MOD=1000000007LL;
int main(){
  int n;
  cin>>n;
  int fib[100];
  fib[0]=1;
  fib[1]=1;
  for(int i=2;i<50;i++){
    fib[i]=fib[i-1]+fib[i-2];
  }
  cout<<fib[n]<<endl;
}


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

using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int n;
  cin>>n;
  n=n%10;
  if(n==3){
    cout<<"bon"<<endl;
  }
  else if(n<2||n==6||n==8){
    cout<<"pon"<<endl;
  }
  else{
    cout<<"hon"<<endl;
  }

  
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
#define double long double
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
signed main()
{
    int x;
    x=read();
    (x>=30)?puts("Yes"):puts("No");
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define v(type) vector<type>

int main() {
    int x, y;
    cin >> x >> y;
    const long long a = 1000000000000000000;

    if (x % y == 0) {
        cout << -1 << endl;
        return 0;
    }

    for (long long i = x; i <= a; i += x) {
        if (i % y != 0) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3640
package main

import (
	"math/rand"
	"time"
	"os"
	"bufio"
	"fmt"
	"strconv"
)

var(
	inf = 10000000071000000
	stdin = bufio.NewReader(os.Stdin)
	mod = 1000000007
	mod9 = 1000000009
	//////////////////////////////////
	stack []byte
)

func init()  {
	rand.Seed(time.Now().UnixNano())
}

type zahyo struct {
	x int
	y int
}

func main() {
	h,w,n := goint(),goint(),goint()
	check := make(map[zahyo]int)
	for i:=0;i<n;i++{
		a,b := goint(),goint()
		for j:=-2;j<1;j++{
			for k:=-2;k<1;k++{
				if (a + j < 1) || (b + k < 1) || (a + j + 2 > h) || (b + k + 2 > w){
					continue
				}
				s := zahyo{a+j,b+k}
				if _,ok := check[s]; ok{
					check[s] ++
				} else {
					check[s] = 1
				}
			}
		}
	}
	count := make([]int,10)
	c := 0
	for _,value := range check{
		count[value]++
		c ++
	}
	count[0] = (h-2)*(w-2) - c
	for _,v := range count{
		fmt.Println(v)
	}
}


//||||||||||||||||||||||||||入力|||||||||||||||||||||||||||||||||||||||

//次のスペースか改行まで読み込む
func gostring() string {
	byte_ls := make([]byte,0)
	for  {
		b, _ := stdin.ReadByte()
		if b == 32 || b == 10 || b == 0{
			return string(byte_ls)
		} else if b == 13 {
			continue
		} else {
			byte_ls = append(byte_ls,b)
		}
	}
}

//上の関数のintバージョン
func goint() int {
	n,_ := strconv.Atoi(gostring())
	return n
}

//数字一行
func intLine(n ,a int) []int {
	ls := make([]int,n)
	for i,_ := range ls{
		ls[i] = goint() + a
	}
	return ls
}

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

func sum(a ...int) int {
	ans := 0
	for i:=0;i<len(a);i++{
		ans += a[i]
	}
	return ans
}

func min(a ...int) int {
	ans := a[0]
	for i:=1;i<len(a);i++{
		if ans > a[i]{
			ans = a[i]
		}
	}
	return ans
}

func abs(n int) int {
	if n >= 0{
		return n
	} else {
		return -n
	}
}

func max(a ...int) int {
	ans := a[0]
	for i:=1;i<len(a);i++{
		if ans < a[i]{
			ans = a[i]
		}
	}
	return ans
}

func intList(n,k int) []int {
	ls := make([]int,n)
	for i:=0;i<n;i++{
		ls[i] = k
	}
	return ls
}

Measured memory_bytes: 111744
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define unt		unsigned int
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=(int)(a);i<=(int)(b);i++)
#define Rep(i,a,b)	for(int i=(int)(a);i>=(int)(b);i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define pb	push_back
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	200005

int		N, M, Q, D, st[n];

PA		F[15][n];

struct	Lin{
		int v, next;
}E[n << 1];

void	Link(int u, int v)	{
		E[++ D]= (Lin){v, st[u]};	st[u]= D;
		E[++ D]= (Lin){u, st[v]};	st[v]= D;
}

int		main(int argc, char* argv[]){
		N= IN();
		M= IN();
		
		For(i, 1, M)	Link(IN(), IN());
		
		Q= IN();
		For(i, 1, Q)	{
			int v= IN(), d= IN(), c= IN();
			F[d][v]= MK(i, c);
		}
		
		Rep(d, 10, 1)	{
			For(u, 1, N)	if	(F[d][u].fi)	{
				for (int i= st[u]; i; i= E[i].next)	{
					int v= E[i].v;
					F[d-1][v]= max(F[d-1][v], F[d][u]);
				}
				F[d-1][u]= max(F[d-1][u], F[d][u]);
			}
		}
		
		For(i, 1, N)	{
			PA	ret= MK(0, 0);
			For(j, 0, 10)	ret= max(ret, F[j][i]);
			printf("%d\n", ret.se);
		}
		
		return	0;
}

Measured memory_bytes: 23040
def solve():
    N, M = map(int, input().split())
    S = map(int, input().split())
    *T, = map(int, input().split())
    dp = [1]*(M+1)
    for s in S:
        is_s = s.__eq__
        dp_ = dp[:]
        acc = 0
        for i, t in enumerate(T):
            if is_s(t):
                acc += dp_[i]
            dp[i+1] = dp_[i+1] + acc
    res = (dp[-1])%(10**9+7)
    return str(res)
 
if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 4972
#include <cstdio>

int main() {
  int N, K, X, Y;
  scanf("%d %d %d %d", &N, &K, &X, &Y);

  int res = 0;
  for (int i = 0; i < N; ++i)
    res += (i < K)? X:Y;
  printf("%d\n", res);
}

Measured memory_bytes: 128
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

A_count = Counter(A)
combs = {}

ans = 0
for a in A:
    if a not in combs:
        combs[a] = A_count[a]*(A_count[a]-1)//2
        ans += combs[a]
    else:
        pass
for a in A:
    print(ans - combs[a] + combs[a]*(A_count[a]-2)//A_count[a])

Measured memory_bytes: 30776
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const ll MAX = 2100000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	repl(i, 2, MAX) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 or k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	COMinit();
	int s;
	cin >> s;
	ll ans = 0;
	repl(i, 1, 700) {
		s -= 3;
		if (s < 0) break;
		ans += COM(s + i - 1, i - 1);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 52852
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

const int MAX_N = 100010;

int par[MAX_N];
int Rank[MAX_N];
int size;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
    size = n;
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size--;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}
bool same(int x, int y) {
    return find(x) == find(y);
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    init(N);
    rep(i, M) {
        int s, t, k; cin >> s >> t >> k;
        s--; t--;
        unite(s, t);
    }
    cout << size << endl;

    return 0;
}


Measured memory_bytes: 1024
def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

    for i in range(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n + 1):
        j = max(ans - i, 0)
        if j > m or A[i] + B[j] > k: continue
        while j <= m:
            if A[i] + B[j] > k:
                j -= 1
                break
            j += 1
        j = min(m,j)
        ans = max(i + j, ans)
    print(ans)


abc172c_tsundoku()

Measured memory_bytes: 42696
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long lint;

void solve(lint n){
    lint r;
    bool isAns = false;
    for (lint p = n / 4 + 1; p <= 3500; ++p){
        if(isAns){
            break;
        }
        for (lint q = p; q <= 3500; ++q){
            bool b1 = 4 * p * q > n * (p + q);
            if(b1){
                bool b2 = (p * q * n) % (4 * p * q - n * (p + q)) == 0;
                if(b2){
                    r = (p * q * n) / (4 * p * q - n * (p + q));
                    cout << p << " " << q << " " << r << "\n";
                    isAns = true;
                    break;
                }
            }
        }
    }
    return;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n;
    cin >> n;
    solve(n);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		boolean flag=false;
		String ans="";
		
		String S = br.readLine();
		
		if(S.charAt(1) == 'B')
			ans="ARC";
		else
			ans="ABC";
		
		
		out.println(ans);
		
	}
	
	
}




Measured memory_bytes: 32428
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int result = 0;
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            String val = String.valueOf(i);
            int some = 0;
            for (int j = 0; j < val.length(); j++) {
                some = some + Integer.parseInt(String.valueOf(val.charAt(j)));
            }
            if (a <= some && b >= some) {
                result = result + Integer.valueOf(val);
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 24148
from collections import namedtuple

State = namedtuple("State", "queen row col dpos dneg")


def put_queen(s, r, c):
    s.queen[r] = c
    s.row[r] = s.col[c] = s.dpos[r + c] = s.dneg[r - c + 8 - 1] = True


def unput_queen(s, r, c):
    s.queen[r] = None
    s.row[r] = s.col[c] = s.dpos[r + c] = s.dneg[r - c + 8 - 1] = False


def read_board(s):
    k = int(input())
    for _ in range(k):
        r, c = [int(x) for x in input().split()]
        put_queen(s, r, c)
    return s


def print_board(s):
    for r in range(8):
        for c in range(8):
            print("Q" if s.queen[r] == c else ".", end="")
        print()


def eight_queens(s):
    def rec(r, s):
        if r == 8:
            return s
        elif s.queen[r] is not None:
            return rec(r + 1, s)
        else:
            for c in range(8):
                if s.col[c] or s.dpos[r + c] or s.dneg[r - c + 8 - 1]:
                    continue
                new_s = State(
                    s.queen[:], s.row[:], s.col[:], s.dpos[:], s.dneg[:]
                )
                put_queen(new_s, r, c)
                result = rec(r + 1, new_s)
                if result:
                    return result
            return False

    return rec(0, s)


def main():
    s = State(
        [None] * 8,
        [False] * 8,
        [False] * 8,
        [False] * (2 * 8 - 1),
        [False] * (2 * 8 - 1),
    )

    print_board(eight_queens(read_board(s)))


main()



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

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

int main(){
  int n,p,q;
  cin>>n>>p>>q;
  string s;
  cin>>s;
  int c=0,t=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]=='a'&&c< p+q)
    {
      c++;
      cout<<"Yes"<<endl;   
    }
    else if(s[i]=='b'&&c<(p+q)&&t<q)
     {
      t++;
      c++;
      cout<<"Yes"<<endl;  
    }
    else if(s[i]=='c'){
      cout<<"No"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
 }
    return 0;  
} 
   

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    int dp[201010] = {};
    int p[201010] = {};
    for(int i=1; i<=N; ++i) cin >> p[i];

    int maxv = 0;
    for(int i=1; i<=N; ++i){
        int c = p[i];
        dp[c] = dp[c-1]+1;
        chmax(maxv, dp[c]);
    }

    cout << N-maxv << endl;
}

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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
int n, q, k, x[100010], y[100010];
int a[100010], b[100010], c[100010];
struct edge{int to; ll cost;};

vector<edge> g[100001];
ll d[100010];

int main(){
    cin >> n;
    for(int i = 0; i < n-1; i++){
        edge mem_edge;
        cin >> a[i] >> b[i] >> c[i];
        mem_edge.to = b[i];
        mem_edge.cost = c[i];
        g[a[i]].push_back(mem_edge);
        mem_edge.to = a[i];
        g[b[i]].push_back(mem_edge);
    }
    cin >> q >> k;

    for(int i = 0; i < q; i++){
        cin >> x[i] >> y[i];
    }

    priority_queue<P, vector<P>, greater<P>> que;
    for(int i = 0; i < n+1; i++)  d[i] = LL_INF;
    d[k] = 0;
    que.push(P(0, k));

    while(!que.empty()){
        Pl 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 * 1LL){
                d[e.to] = d[v] + e.cost*1LL;
                que.push(P(d[e.to], e.to));
            }
        }
    }

    for(int i = 0; i < q; i++)  cout << d[x[i]]+d[y[i]] << endl;
}

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

void merge(vector<int>& A,int left,int mid,int right,int& counter){
  int n1 = mid - left,n2 = right - mid;
  vector<int> L,R;
  L.resize(n1+1);
  R.resize(n2+1);
  for(int i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(int i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1-1] > R[n2-1] ? L[n1] = R[n2] = L[n1-1]+1 : L[n1] = R[n2] = R[n2-1]+1;
  for(int i=0,j=0,k=left;k<right;k++){
    counter++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
  }
}

void mergeSort(vector<int>& A,int left,int right,int& counter){
  if(left+1<right){
    int mid = (left + right)/2;
    mergeSort(A,left,mid,counter);
    mergeSort(A,mid,right,counter);
    merge(A,left,mid,right,counter);
  }
}

int main(){
  vector<int> A;
  int n,counter=0;

  cin >> n;
  A.resize(n);
  for(int i=0;i<n;i++){
    cin >> A[i];
  }

  mergeSort(A,0,n,counter);
  cout << A[0];
  for(int i=1;i<n;i++){
    cout << " " << A[i];
  }
  cout << endl << counter << endl;
}


Measured memory_bytes: 6772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int G[100001];
vector<int> E[100001];
int dfs(int A) {
	int g = 0;
	G[A] = -1;
	for (auto i : E[A]) {
		if (G[i] != -1) g ^= dfs(i);
	}
	return G[A] = g + 1;
}

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


	int N;
	cin >> N;
	rep(i, N - 1) {
		int x, y;
		cin >> x >> y;
		E[x].pb(y);
		E[y].pb(x);
	}

	dfs(1);

	if (G[1] - 1) co("Alice");
	else co("Bob");

	Would you please return 0;
}

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

int main(){
    while(1){
        int d, w;
        cin >> d >> w;
        if (d == 0) break;
        vector<vector<int>> pond(d, vector<int>(w));
        for (int i = 0; i < d; i++){
            for (int j = 0; j < w; j++){
                cin >> pond[i][j];
            }
        }
        int ans = 0;
        int pond_min, pond_max;
        int tmp;
        for (int i = 3; i <= d; i++){
            for (int j = 3; j <= w; j++){
                for (int s = 0; s <= d - i; s++){
                    for (int t = 0; t <= w - j; t++){
                        tmp = 0;
                        pond_min = 10;
                        pond_max = 0;
                        for (int x = 0; x < i; x++){
                            for (int y = 0; y < j; y++){
                                if (x == 0 || y == 0 || x == i - 1 || y == j - 1) pond_min = min(pond_min, pond[s+x][t+y]);
                                else {
                                    tmp += pond[s+x][t+y];
                                    pond_max = max(pond_max, pond[s+x][t+y]);
                                }
                            }
                        }
                        if (pond_max < pond_min) ans = max(ans, pond_min * (i - 2) * (j - 2) - tmp);
                    }
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3088
n = int( input() )
a = list( map( int, input().split() ) )

money = 1000
kabu = 0

a.append( -1 )
c = [ 0 for _ in range( n + 1 ) ]
for i in range( n ):
    if a[ i ] < a[ i + 1 ]:
        c[ i ] = 1
    elif a[ i ] == a[ i + 1 ]:
        c[ i ] = 0
    else:
        c[ i ] = -1

for i in reversed( range( n ) ):
    if c[ i ] == 0:
        c[ i ] = c[ i + 1 ]

for d in range( n ):
    if c[ d ] > 0:
        kabu += money // a[ d ]
        money = money % a[ d ]
    else:
        money += kabu * a[ d ]
        kabu = 0

print( money )

Measured memory_bytes: 9188
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
long long dp[400000];
int main() {
	int n;
	cin >> n;
	map<int, int> gogo;
	vector<pair<int, int>> inputs;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		inputs.push_back(make_pair(a, b));
		gogo[b] = 1;
	}
	sort(inputs.begin(), inputs.end());
	int now_itr = 0;
	for (auto i = gogo.begin(); i != gogo.end(); ++i) {
		i->second = now_itr;
		now_itr++;
	}
	REP(q, inputs.size()) {
		inputs[q].second = gogo[inputs[q].second];
	}
	vector<pair<long long, long long>> kukan;
	int a = 0;
	REP(q, inputs.size()) {
		a = max(a, inputs[q].second);
		kukan.push_back(make_pair(0, a));
	}
	a = 300000;
	for (int q = inputs.size() - 1; q >= 0; --q) {
		a = min(a, inputs[q].second);
		kukan[q].first = a;
	}
	sort(kukan.begin(), kukan.end());
	long long now = 1;
	dp[1] = MAX_MOD - 1;
	now_itr = 0;
	for (int i = 0; i < kukan.size(); ++i) {
		while (now_itr < kukan[i].first) {
			now_itr++;
			now += dp[now_itr];
			now %= MAX_MOD;
		}
		dp[kukan[i].second + 2] += (MAX_MOD - now) % MAX_MOD;
		dp[kukan[i].second + 2] %= MAX_MOD;
		now *= 2LL;
		now %= MAX_MOD;
	}
	while (now_itr <= kukan[kukan.size()-1].second) {
		now_itr++;
		now += dp[now_itr];
		now %= MAX_MOD;
	}
	cout << now << endl;
}

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

using namespace std;

#define lli long long int

#define ulli unsigned long long int

#define Pi 3.14159265358979323846264338327950288419716939937510

string s;

bool check(int i, int j){
	
	while(i<j){
		
		if(s[i] != s[j]){
			
			return false;
		}
		
		i++,j--;
	}
	
	return true;
}

int main(){
	
    ios :: sync_with_stdio(false);
   
    //ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
    
    cin>>s;
    
    int n = s.length();
    
    s = '*'+s;
    
    if(check(1,n)){
    	
    	if(check(1,(n-1)/2)){
    		
    		if(check((n+3)/2,n)){
    			
    			cout<<"Yes";
    			
    			return 0;
			}
		}
	}
	
	cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	int n,k; cin>>n>>k;
	int a[100],dp[100001]={};
	FOR(i,0,n) cin>>a[i];
	FOR(i,0,k+1){
		FOR(j,0,n){
			if(i+a[j]<=k){
				dp[i+a[j]]|=(!dp[i]);
			}
		}
	}
	cout<<(dp[k]?"First":"Second")<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <math.h>

typedef long long ll;
using namespace std;

int solve_(vector<int>& ptn, vector<int>& p, vector<vector<int> >& s, int n ){
    if(n < 0){
        for(int i=0; i<p.size(); ++i){
            int ons = 0;
            for(int j=0; j<s[i].size(); ++j){
                ons += ptn[s[i][j]-1];
            }
            ons = ons % 2;
            if(ons != p[i]) return 0;
        }
        return 1;
    }
    int tsc = 0;
    ptn[n] = 0;
    tsc += solve_(ptn, p, s, n-1);
    ptn[n] = 1;
    tsc += solve_(ptn, p, s, n-1);
    return tsc;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> k(m);
    vector<vector<int> > s(m);
    for(int i=0; i<m; ++i){
        cin >> k[i];
        vector<int> ts(k[i]);
        for(int& tss : ts){cin >> tss;}
        s[i] = ts;
    }
    vector<int> p(m);
    for(int i=0; i<m; ++i){
        cin >> p[i];
    }
    vector<int> ptn(n, 1);
    cout << solve_(ptn, p, s, n-1) << endl;
    return 0;
}



Measured memory_bytes: 888
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
using namespace std;
#define MAXN 200005
typedef long long LL;
#define int LL
const int mo=1e9+7;
typedef pair<int,int> pii;
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
int n,a[MAXN],ans;
map<int,int> sum;
signed main(){
	read(n);
	for(int i=1;i<=n;i++)read(a[i]);
	for(int i=1;i<=n;i++)sum[i-a[i]]++;
	for(int i=1;i<=n;i++)ans+=sum[i+a[i]];
	printf("%lld\n",ans);
	return 0;
}
/*
i-j=a[i]+a[j]
j+a[j]=i-a[i]
*/

Measured memory_bytes: 27844
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
int main(){

    ll v,n,s=0;
    cin>>v; n=v;
    while(n!=0)
    {
        s=s+n% 10;
        n/=10;
    }

    if(v%s==0) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for (auto p : mp) {
    ans += (ll)p.se*(p.se-1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <iomanip>
using namespace std;

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

    vector<long long> X(N);
    vector<long long> Y(N);
    vector<int> line(N);
    for(int i=0; i<N; i++){
        cin >> X[i] >> Y[i];
        line[i] = i;
    }

    int perm_N=1;
    for(int i=0; i<N; i++){
        perm_N = perm_N*(i+1);
    }

    double val = 0;
    do{
        for(int i=0; i<N-1; i++){
            int index = line[i];
            int next_index = line[i+1];
            val += sqrt((X[next_index]-X[index])*(X[next_index]-X[index]) + (Y[next_index]-Y[index])*(Y[next_index]-Y[index]));
        }
    }while(next_permutation(line.begin(), line.end()));


    val = val / (double)(perm_N);

    cout << fixed << setprecision(8) << val << endl;
    return 0;

}

Measured memory_bytes: 3824
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<deque>
using namespace std;
typedef pair<int, char>pic;
vector<pic>rle(string s)
{
	s.push_back(' ');
	char now = s[0];
	vector<pic>r;
	r.push_back(make_pair(0, s[0]));
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != now)r.push_back(make_pair(i, s[i])), now = s[i];
	}
	return r;
}
int main()
{
	int num;
	scanf("%d", &num);
	string zs, zt;
	cin >> zs >> zt;
	vector<pic>s = rle(zs), t = rle(zt);
	int pt = s.size() - 2;
	vector<int>idx;
	idx.resize(t.size());
	for (int i = t.size() - 2; i >= 0; i--)
	{
		for (;;)
		{
			if (pt < 0)
			{
				printf("-1\n");
				return 0;
			}
			if (t[i].second == s[pt].second&&t[i].first >= s[pt].first&&t[i + 1].first >= s[pt + 1].first)
			{
				idx[i] = pt;
				pt--;
				break;
			}
			pt--;
		}
	}
	deque<int>now;
	int maxi = 0;
	for (int i = 0; i < t.size() - 1; i++)
	{
		//printf("%d %d\n", t[i].first, s[idx[i]].first);
		for (;;)
		{
			if (now.empty())break;
			int z = now[now.size() - 1];
			if (z + now.size() < s[idx[i] + 1].first)now.pop_back();
			else break;
		}
		if (s[idx[i] + 1].first != t[i + 1].first)now.push_front(t[i + 1].first - 1);
		maxi = max(maxi, int(now.size()));
	}
	printf("%d\n", maxi);
}

Measured memory_bytes: 25892
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS (1e-5)

using namespace std;
typedef pair<int, int> ipair;

int ok_digit[3] = {3, 5, 7};
string S;
int num;

int solve(int power, int cur) {
    if(power == -1) {
        char snum[20];
        sprintf(snum, "%d", cur);
        
        bool san = false, go = false, nana = false;
        for(int i = 0; snum[i] != 0; ++i)
            if(snum[i] == '3')
                san = true;
            else if(snum[i] == '5')
                go = true;
            else if(snum[i] == '7')
                nana = true;

        return (san && go && nana) ? 1 : 0;
    }

    int cnt = 0;
    for(int i = 0; i < 3; ++i) {
        int next = cur + ok_digit[i] * (int)(pow(10, power) + EPS);
        if(next > num)
            break;
        
        cnt += solve(power - 1, next);
    }

    if(cur == 0)
        cnt += solve(power - 1, cur);
    
    return cnt;
}

int main(int argc, char **argv) {
    cin >> S;
    num = atoi(S.c_str());

    int power = S.size() - 1;
    int init_digit[4] = {0, 3, 5, 7};

    int res = 0;
    for(int i = 0; i < 4; ++i) {
        int next = init_digit[i] * (int)(pow(10, power) + EPS);
        if(next > num)
            break;
        
        res += solve(power - 1, next);
    }

    cout << res << endl;
}

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

#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double ld;

const ld pi=3.1415926535897932384626433;
const int mod = 1000000007;
const ll inf=3e18;
// 92DTG

int main ()
{
   bolt;
   ll n,m,x;
   cin>>n>>m>>x;
   ll c[n];
   ll a[n][m];
   memset (a,0,sizeof(a));
   for (ll i=0;i<n;i++)
   {
      cin>>c[i];
      for (ll j=0;j<m;j++)
      {
         cin>>a[i][j];
      }
   }
   ll mc=inf;
   ll st=pow(2,n);
   for (ll i=1;i<st;i++)
   {
      ll u=i;
      ll ans=0;
      ll cur[m]={};

      for (ll j=0;j<n;j++)
      {
         if ((u>>j)&1)
         {
            ans+=c[j];
            for (ll k=0;k<m;k++)
            {
               cur[k]+=a[j][k];
            }
         }
      }
      ll cnt=0;
      for (ll j=0;j<m;j++)
      {
         if (cur[j]>=x)
         {
            cnt++;
         }
      }
      if (cnt==m)
      {
         mc=min(mc,ans);
      }
   }
   if (mc==inf)
      cout<<-1<<endl;
   else
      cout<<mc<<endl;
   return 0;

}


Measured memory_bytes: 4120
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> cnt(N,0);
  int i,a;
  for(i=1;i<N;i++) {
    cin >> a;
    cnt[a-1]++;
  }
  for(i=0;i<N;i++)cout << cnt[i] << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define ll long long int 
#define fori(i,n) for(int i=0; i<n; ++i)
#define ford(i,n) for(int i=n-1; i>=0; --i)
#define vi vector<int> 
#define vs vector<string>
#define vll vector<ll>
#define di deque<int>
#define vpii vector<pair<int,int>>
    #define vpll vector<pair<ll,ll>>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define mod1 1000000007
#define mod2 998244353
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gcd __gcd

//Printing template
#define pf2(a,b) cout<<a<<" "<<b<<"\n"
#define pf3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define pf4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"

#define fast_cin() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> i_set;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ll_set; 
/* new_data_set p; */
/* *p.find_by_order(3); The value at third place */
/* p.order_of_key(7); The expected index in the set in sorted order */



int main(int argc, char const *argv[]){
    fast_cin();
    int n,m,i;
    cin>>n>>m;
    vpii vp(n+1);
    int temp1,temp3;
    string temp2;
    fori(i,m){
        cin>>temp1>>temp2;
        if(temp2=="AC") vp[temp1].fi=1;
        else{
            if(vp[temp1].fi!=1){
                vp[temp1].se++;
            }
        }
    }
    temp1=0,temp3=0;
    for(i=1; i<=n; ++i){
        temp1+=vp[i].fi;
        if(vp[i].fi==1) temp3+=vp[i].se;
    }
    cout<<temp1<<" "<<temp3<<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int n, m;
int a[55], b[55];
map<tuple<int, int, int, int, bool, int>, int> dp;

int dfs(int A, int B, int stA, int stB, bool AB, int pass) {
    if(pass == 3) return 0;
    if(dp.count(make_tuple(A, B, stA, stB, AB, pass))) return dp[make_tuple(A, B, stA, stB, AB, pass)];
    // パス
    int ret1 = dfs(A, B, 0, 0, not AB, pass + 1) + (stA - stB);
    // 積む
    int ret2 = ret1;
    if(AB) {
        if(A < n) {
            if(a[A] == -1) ret2 = dfs(A + 1, B, stA, 0, not AB, 0);
            else ret2 = dfs(A + 1, B, stA + a[A], stB, not AB, 0);
        }
    } else {
        if(B < m) {
            if(b[B] == -1) ret2 = dfs(A, B + 1, 0, stB, not AB, 0);
            else ret2 = dfs(A, B + 1, stA, stB + b[B], not AB, 0);
        }
    }
    if(AB) {
        return dp[make_tuple(A, B, stA, stB, AB, pass)] = max(ret1, ret2);
    } else {
        return dp[make_tuple(A, B, stA, stB, AB, pass)] = min(ret1, ret2);
    }
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < m; ++i) cin >> b[i];
    cout << dfs(0, 0, 0, 0, 1, 0) << endl;
    return 0;
}



Measured memory_bytes: 17504
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

struct BIT{
private:
    vector<ll> a;
    int n;
public:
    BIT(int sz){
        n=sz;
        a.resize(sz+1);
    }
    ll sum(int i){
        ll res=0;
        while(i>0){
            res+=a[i];
            i-=i&-i;
        }
        return res;
    }
    ll sum(int i,int j){
        return sum(j)-sum(i-1);
    }
    void add(int i,ll x){
        while(i<=n){
            a[i]+=x;
            i+=i&-i;
        }
    }
};

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> w,b;
    w.reserve(n),b.reserve(n);
    rep(i,n+n){
        char c;
        int a;
        cin>>c>>a;
        if(c=='W')w.push_back({a,i+1});
        else b.push_back({a,i+1});
    }
    sort(begin(w),end(w));
    sort(begin(b),end(b));
    int cntw[n+1][n+1],cntb[n+1][n+1];
    rep(i,n+1){
        BIT bit(n+n);
        rep(j,i){
            bit.add(w[j].second,1);
        }
        rep(j,n+1){
            if(i<n)cntw[i][j]=bit.sum(w[i].second,n+n);
            if(j<n){
                cntb[i][j]=bit.sum(b[j].second,n+n);
                bit.add(b[j].second,1);
            }
        }
    }
    int dp[n+1][n+1];
    fill(dp[0],dp[n+1],inf);
    dp[0][0]=0;
    rep(i,n+1){
        rep(j,n+1){
            if(i<n)dp[i+1][j]=min(dp[i+1][j],dp[i][j]+w[i].second+cntw[i][j]-(i+j+1));
            if(j<n)dp[i][j+1]=min(dp[i][j+1],dp[i][j]+b[j].second+cntb[i][j]-(i+j+1));
        }
    }
    cout<<dp[n][n]<<endl;
}


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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) cerr<<#x<<" = " << (x) << endl
#define pnl(x) cout << x << '\n'
#define pns(x) cout << x << ' '
#define read(x) cin >> x
#define read2(x,y) cin >> x >> y
#define read3(x, y, z) cin >> x >> y >> z
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	vector<int>	vi;
typedef pair<int,int>	ii;
typedef vector<string>	vs;
typedef vector<ii>	vii;
typedef vector<Arrete>	vg;
typedef vector<long long>	vl;
typedef	long long ll;

const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	set<string> ans;
	string s;
	cin >> s;
	int K;
	cin >> K;
	for (int i(0); i < s.size(); ++i)
	{
		string cur = "";
		for (int j(i); j<s.size() and j-i+1<=K; ++j)
		{
			cur += s[j];
			ans.insert(cur);
			if (ans.size() > K)
				ans.erase(--ans.end());
		}
	}
	cout << *ans.rbegin() << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<iomanip>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int w, h, x, y, ans = 0;
    cin >> w >> h >> x >> y;
    bool f = false;
    if(w % 2 == 0 && w / 2 == x && h % 2 == 0 && h / 2 == y) f = true;
    cout << fixed <<  (double)w * h / 2.0 << " " << (f? 1:0)<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
//10^9=10億 intの限界寸前
int main(){
	int n,k;
	cin >> n >> k;
	vector<int> v(n,0);
	for(int i=0;i<k;i++)
	{
		int d;
		cin>>d;
		for(int j=0;j<d;j++)
		{
			int num;
			cin>>num;
			v[num-1]++;
		}		
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(v[i]==0)ans++;
	}
	cout<< ans;
	return 0;
}

Measured memory_bytes: 3164