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

const int maxn = 1e3+5, maxs = 2e4+5, inf = 1e9;
int n, h, a[maxn], b[maxn], dp[maxn][maxs];

int main(){
	scanf("%d %d", &h, &n);
	for(int i = 1; i<=n; i++) scanf("%d %d", &a[i], &b[i]);
	fill(dp[0]+1, dp[0]+maxs, inf);
	for(int i = 1; i<=n; i++){
		for(int s = 0; s<maxs; s++){
			dp[i][s] = dp[i-1][s];
			if (s>=a[i]) dp[i][s] = min(dp[i][s], dp[i][s-a[i]]+b[i]);
		}
	}
	printf("%d\n", *min_element(dp[n]+h, dp[n]+maxs));
	return 0;
}

Measured memory_bytes: 82016
import java.util.Scanner;

//Palindrome
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = 0;
		while(sc.hasNext()){
			String s = sc.next();
			if(s.equals((new StringBuffer(s)).reverse().toString()))c++;
		}
		System.out.println(c);
	}
}

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1000000000;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;

int main() {
  int n, h, w;
  cin >> h >> w >> n;
  int m = max(h, w);
  if (n % m == 0)
    cout << n / m << endl;
  else
    cout << n / m + 1 << endl;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

typedef pair<int,int> pii;

int n,m,q,co[300001],ro[300001];
map<pii,int> mp;

void nhap()
{
    scanf("%d %d %d",&n,&m,&q);
    while (q--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        mp[{x,y}]=1;
        ro[x]++;
        co[y]++;
    }
}

void process()
{
    vector<pii> vco,vro;
    for (int i=1;i<=n;++i)
        vro.push_back({ro[i],i});
    for (int i=1;i<=m;++i)
        vco.push_back({co[i],i});
    sort(vco.begin(),vco.end());
    sort(vro.begin(),vro.end());
    int kq=0;
    for (auto i:vco)
        kq=max(kq,vro.back().first+i.first-mp[{vro.back().second,i.second}]);
    for (auto i:vro)
        kq=max(kq,vco.back().first+i.first-mp[{i.second,vco.back().second}]);
    cout<<kq;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 66524
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	int contador5 = 0;
	int contador7 = 0;
	cin >> a >> b >> c;
	if (a==5){
		contador5++;
	}
	if (a==7){
		contador7++;
	}
	if (b==5){
		contador5++;
	}
	if (b==7){
		contador7++;
	}
	if (c==5){
		contador5++;
	}
	if (c==7){
		contador7++;
	}
	if (contador5 == 2 and contador7 == 1){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int s[]=new int[n];
		double g=0;
		for(int i=0;i<n;i++) {
			s[i]=sc.nextInt();
			g+=1/(double)s[i];
		}
		g=1/g;
		System.out.println(g);
	}

}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n;
ll c,a[N],b[N],pre[N],bk[N],pp[N],bb[N];
ll dis(ll x,ll y)
{
    return min(abs(x-y),c-abs(x-y));
}
ll solve()
{
    ll ans=0,pos=0,res=0;
    int l=1,r=n;
    while(l<=r)
    {
        if(b[l]-dis(pos,a[l])>b[r]-dis(pos,a[r]))
        {
            res+=b[l]-dis(pos,a[l]);
            ans=max(ans,res);
            pos=a[l++];
        }
        else
        {
            res+=b[r]-dis(pos,a[r]);
            ans=max(ans,res);
            pos=a[r--];
        }
    }
    return ans;
}
ll solve2()
{
    ll ans=0,pos=0,res=0;
    int l=1,r=n;
    while(l<=r)
    {
        if(dis(pos,a[l])<b[r]-dis(pos,a[r]))
        {
            res+=b[l]-dis(pos,a[l]);
            ans=max(ans,res);
            pos=a[l++];
        }
        else
        {
            res+=b[r]-dis(pos,a[r]);
            ans=max(ans,res);
            pos=a[r--];
        }
    }
    return ans;
}
int main()
{
    scanf("%d%lld",&n,&c);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&a[i],&b[i]);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        pre[i]=pre[i-1]+b[i]-(a[i]-a[i-1]),ans=max(ans,pre[i]);
    }
    a[n+1]=c;
    for(int i=n;i>=1;i--)
        bk[i]=bk[i+1]+b[i]-(a[i+1]-a[i]),ans=max(ans,bk[i]);
    for(int i=n;i>=1;i--)
        bb[i]=max(bk[i],bb[i+1]);
    for(int i=1;i<=n;i++)
        pp[i]=max(pre[i],pp[i-1]);
    for(int i=n;i>=1;i--)
        ans=max(ans,bk[i]-(c-a[i])+pp[i-1]);
    for(int i=1;i<=n;i++)
        ans=max(ans,pre[i]-a[i]+bb[i+1]);
    //ans=max(ans,solve());
    //ans=max(ans,solve2());
    printf("%lld\n",ans);
}


Measured memory_bytes: 4992
import java.util.Scanner;

class Main {
	
	public static void main(String args[]){
		
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int n = s.length();
		int x[] = new int[n];
		for(int i = 0;i < n; i++)
			x[i] = s.charAt(i)-'0';
		
		String X ="";
		
		for(int i = 0; i < Math.pow(2,n-1); i++){
			for(int j = 0; j < n-1; j++){
				
				X += String.valueOf(x[j]);
				if((1 & (i>>j)) == 1){
					X += "X";
				}
			}

			X += String.valueOf(x[n-1]);
			if(i != Math.pow(2,n-1)-1)X += "X";
		}
		String[] sprit = X.split("X", 0);
		long sum = 0;
		for(int i = 0; i < sprit.length; i++)
			sum += Long.valueOf(sprit[i]);
		System.out.println(sum);
	}
}

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

int main()
{
    string s;cin>>s;
    int i;
    int c0,c1;
    c0=0;
    c1=0;
    for(i=0;i<s.length();i++)
    {
        if(s.at(i)=='0')c0++;
        else c1++;
    }
    cout<<min(c0,c1)*2<<endl;
}


Measured memory_bytes: 512
input = [input() for i in range(2)]

N = int(input[0])
b = input[1].split(" ")
b = list(map(int,b))
output = []

# print(N)
# print(b)

for i in range(N,0,-1):
    # print("i = " + str(i))
    for j in range(i-1,-1,-1):
        # print("j = " + str(j))
        if j + 1 == b[j]:
            # print("pop " + str(b[j]))
            output.append(b.pop(j))
            # print(b)
            break

if b == []:
    for i in range(len(output)-1,-1,-1):
        print(output[i])
else:
    print(-1)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def modpow (a, N):
    res = 1
    while (N>0):
        if N & 1:
            res = res * a % MOD
        a = a * a % MOD
        N >>= 1
    return res

def solve(N: int, K: int):
    ans = 0

    x = [1] * (K+1)

    for i in range(K, 0, -1):
        if i * 2 <= K:
            x[i] = modpow(K//i, N)
            j = 2
            while i * j <= K:
                x[i] -= x[i*j]
                j += 1
            ans += x[i] * i % MOD
        else:
            ans += i
    print(ans%MOD)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11292
N = int(input())

edge_num = 0
for i in range(N-1,0,-1):
    edge_num += i

edge_num -= N//2 

"""
Nが偶数の場合、1とNの間にある辺、2とN-1の間にある辺、......を外していく
Nが奇数の場合、1とN-1の間にある辺、2とN-2の間にある辺、......を外していく
"""
print(edge_num)
for i in range(1, N):
    for j in range(i+1,N+1):
        if N % 2 == 0:
            if i + j == N+1:
                continue
        else:
            if i+ j == N:
                continue
        print(i,j)

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

int main(){
  int N; cin >>N;
  int peak,temp,memo;
  peak = 0; temp = 0; memo = 0;
  for(int i=0;i<N;i++){
    int x; cin >>x;
    if(x<=memo){
      temp ++;
      peak = max(temp,peak);
    }else{
      temp = 0;
    }
    memo = x;
  }
  cout << peak << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
print( -(-N//2)/N )

Measured memory_bytes: 5148
#include <cstdio>
using namespace std;
#define MOD 924844033
struct Edge{
	int to, next;
}e[400005];
int head[200007], a[524403], b[524403], w[524403], rev[524403], siz[200007], vis[200007], fac[200007], ifac[200007], en, n;
long long invlen;
long long fastpow(register int x, register int k){
	register long long t, p;
	for (t = 1, p = x; k; k >>= 1, p = p * p % MOD) if (k & 1) t = p * t % MOD;
	return t;
}
void PPPH(register int *A, register int len){
	register int i;
	for (i = 0; i < len; ++i) fprintf(stderr, "%d ", A[i]);
	fprintf(stderr, "\n");
	return ;
}
void Butterfly(register int *A, register int len){
	register int i, tmp;
	for (i = 1; i < len; ++i) {
		if (i < rev[i]) {
			tmp = A[i];
			A[i] = A[rev[i]];
			A[rev[i]] = tmp;
		}
	}
	return ;
}
void DFT(register int *A, register int len){
	Butterfly(A, len);
	register int i, j, k, p2, *B, *C, *O, tmp;
	for (i = 1, p2 = 2; i < len; i <<= 1, p2 <<= 1) {
		for (j = 0; j < len; j += p2) {
			B = A + j, C = A + i + j, O = w + i;
			for (k = 0; k < i; ++k, ++B, ++C, ++O) {
				tmp = 1ll * *O * *C % MOD;
				(*C = *B + MOD - tmp) %= MOD;
				(*B += tmp) %= MOD;
			}
		}
	}
	return ;
}
void IDFT(register int *A, register int len){
	register int *B, *C, tmp;
	for (B = A + 1, C = A + len - 1; B < C; ++B, --C) {
		tmp = *B;
		*B = *C;
		*C = tmp;
	}
	DFT(A, len);
	for (B = A, C = A + len; B != C; ++B) *B = 1ll * *B * invlen % MOD;
	return ;
}
void dfs(register int o){
	register int i, to;
	vis[o] = siz[o] = 1;
	for (i = head[o]; i; i = e[i].next) {
		if (vis[to = e[i].to]) continue;
		dfs(to);
		++a[siz[to]];
		++a[n - siz[to]];
		siz[o] += siz[to];
	}
	return ;
}
int fastin(){
	register int i; register char ch;
	while (ch = getchar(), ch < '0' || ch > '9');
	i = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9') i = i * 10 + ch - '0';
	return i;
}
int main(){
	register int len, k, tmp, i, u, v, nf;
	n = fastin();
	for (en = i = 1; i < n; ++i) {
		u = fastin(), v = fastin();
		e[++en] = (Edge){v, head[u]};
		head[u] = en;
		e[++en] = (Edge){u, head[v]};
		head[v] = en;
	}
	dfs(1);
	for (tmp = n, len = 2, k = 0; tmp; tmp >>= 1, len <<= 1, ++k);
	invlen = fastpow(len, MOD - 2);
	for (i = 1; i < len; ++i) rev[i] = rev[i >> 1] >> 1 | (i & 1) << k;
	w[len >> 1] = 1;
	tmp = w[i = len >> 1 | 1] = fastpow(5, (MOD - 1) / len);
	for (++i; i < len; ++i) w[i] = 1ll * tmp * w[i - 1] % MOD;
	for (i = (len >> 1) - 1; i; --i) w[i] = w[i << 1];
	fac[0] = fac[1] = 1;
	for (i = 2; i <= n; ++i) {
		fac[i] = 1ll * i * fac[i - 1] % MOD;
		a[i] = 1ll * a[i] * fac[i] % MOD;
	}
	nf = 1ll * n * fac[n] % MOD;
	tmp = fastpow(fac[n], MOD - 2);
	for (i = n; i; --i) {
		ifac[i] = b[len - i] = tmp;
		tmp = 1ll * tmp * i % MOD;
	}
	b[0] = ifac[0] = 1;
	DFT(a, len);
	DFT(b, len);
	for (i = 0; i < len; ++i) a[i] = 1ll * a[i] * b[i] % MOD;
	IDFT(a, len);
	for (i = 1; i <= n; ++i) {
		tmp = (1ll * nf * ifac[i] % MOD * ifac[n - i] - 1ll * ifac[i] * a[i]) % MOD;
		printf("%d\n", tmp < 0 ? tmp + MOD : tmp);
	}
	return 0;
}

Measured memory_bytes: 22656
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int N ;
    std::cin >> N ;
    int tmp;
    std::vector<int> d;
    for(int i=0; i<N; ++i){
        std::cin >> tmp ;
        d.push_back(tmp) ;
    }

    std::sort(d.begin(), d.end()) ;
    std::reverse(d.begin(), d.end()) ;
    int max=1000;
    int cnt=0;
    for(auto x: d)
    {
        if(x<max)
            cnt++ ;
        max = x ;
    }
    std::cout << cnt << std::endl ;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
  	ll n,x;cin>>n>>x;
    ll l[n];rep(i,0,n)cin>>l[i];

    ll d = 0, ans = n+1;
    rep(i,0,n){
        d += l[i];
        if(d > x){
            ans = i+1;
            break;
        }
    }
    cout << ans << ednl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n, y;
    cin >> n >> y;
    for (int i = n; i >= 0;i--){
        for (int j = n-i; j>=0;j--){
            int k = n - (i + j);
            int tmp = i * 10000 + j * 5000 + k * 1000;
            if (tmp == y)
            {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
            
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


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

int main() {
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  for(int i = 0; i < n; i++) cin >> x.at(i);
  
  long long dp[55][55][3000];
  dp[0][0][0] = 1;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= i; j++){
      for(int k = 0; k < 3000; k++){
        int now = x.at(i);
        dp[i+1][j+1][k+now] += dp[i][j][k];
        dp[i+1][j][k] += dp[i][j][k];
      }
    }
  }
  
  long long ans = 0;
  for(int i = 1; i <= n; i++){
    int j = i * a;
    ans += dp[n][i][j];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 34864
#include <iostream>
#include <vector>
#include <array>
#include <queue>

using Int = long long int;
using std::array;
using std::vector;

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Graph = vector<vector<Edge<Cost>>>;

constexpr int PNUM = 15;

constexpr array<Int, PNUM> primes{
    1000000007,
    1000000009,
    1000000021,
    1000000033,
    1000000087,
    1000000093,
    1000000097,
    1000000103,
    1000000123,
    1000000181,
    1000000207,
    1000000223,
    1000000241,
    1000000271,
    1000000289,
};

struct ModNum {
    array<Int, PNUM> num;

    ModNum(Int x = 0) {
        for (int i = 0; i < PNUM; ++i) {
            num[i] = x % primes[i];
        }
    }

    ModNum operator*(ModNum x) const {
        for (int i = 0; i < PNUM; ++i) {
            (x.num[i] *= num[i]) %= primes[i];
        }
        return x;
    }

    ModNum inv() const {
        ModNum ret;
        for (int i = 0; i < PNUM; ++i) {
            Int& x = ret.num[i];
            x = 1;
            Int b = num[i];
            Int n = primes[i] - 2;
            while (n > 0) {
                if (n & 1) (x *= b) %= primes[i];
                n >>= 1;
                (b *= b) %= primes[i];
            }
        }
        return ret;
    }

    bool operator==(const ModNum& x) const {
        return num == x.num;
    }
};

int main() {
    int n, m;
    std::cin >> n >> m;
    Graph<ModNum> graph(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        Int x;
        std::cin >> u >> v >> x;
        --u, --v;
        graph[u].emplace_back(u, v, ModNum(x));
        graph[v].emplace_back(v, u, ModNum(x).inv());
    }

    vector<ModNum> dist(n);
    vector<bool> visited(n, false);
    for (int s = 0; s < n; ++s) {
        if (visited[s]) continue;
        visited[s] = true;

        std::queue<int> que;
        que.push(s);
        dist[s] = ModNum(1);

        while (!que.empty()) {
            int v = que.front();
            que.pop();

            for (auto e : graph[v]) {
                ModNum d = dist[e.src] * e.cost;
                if (visited[e.dst]) {
                    if (!(d == dist[e.dst])) {
                        std::cout << "No" << std::endl;
                        return 0;
                    }
                } else {
                    dist[e.dst] = d;
                    visited[e.dst] = true;
                    que.push(e.dst);
                }
            }
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}



Measured memory_bytes: 49868
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  int a;
  cin >> a;
  int ans = a+a*a+a*a*a;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3652
S=input()

dp=[False]* (len(S)+1)

dp[0] = True

for i in range(1, len(dp)):
  for w in [ 'dream', 'dreamer', 'erase', 'eraser']:
    if dp[i-len(w)] and w == S[i-len(w):i]:
      dp[i] = True

if dp[-1]:
  print('YES')
else:
  print('NO')

    


Measured memory_bytes: 9828
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
int z =sc.nextInt();
if(x+y >=z)
System.out.println("Yes");
else
System.out.println("No");
}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  string a,b;cin>>a>>b;
  int an=a.size(),bn=b.size();
  double m[]={1,1e1,1e2,1e3,1e4,1e5};
  int num=0;
  rep(i,0,bn){
    num+=(b[bn-1-i]-'0')*m[i];
  }
  rep(i,0,an){
    num+=(a[an-1-i]-'0')*m[bn+i];
  }

  for(int i=1;i<=10000;i++){
    if(i*i==num){out("Yes");return 0;}
  }
  out("No");


  return 0;
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
y=0
d=0
s=0
t=0
u=0
for i in range(a+1):
    t=0
    u=0
    if s==0: 
        y=500*i
        if x < y:
            s =1
        else:
            for j in range(b+1):
                u=0
                if t==0:
                    y=500*i+100*j
                    if x < y:
                        t=1
                    else:
                        for k in range(c+1):
                            if u==0:
                                y=500*i+100*j+50*k
                                if x==y:
                                    d=d+1
                                    u=1
print(str(d))
                
            


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int x = 0, xMax = 0;
	int n = (int)S.size();
	for (int i = 0; i < n; i++) {
		if (S[i] == 'I') x++;
		if (S[i] == 'D') x--;

		if (xMax < x) xMax = x;
	}
	cout << xMax << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int N = 100005;

int n, m;
vector<int> can[N], lang[N];
bool people[N], langs[N];
queue<int> q;

int main() {
    scanf("%d%d", &n, &m);
    forn(i, n) {
        int cnt;
        scanf("%d", &cnt);
        forn(j, cnt) {
            int x;
            scanf("%d", &x), --x;
            can[i].pb(x);
            lang[x].pb(i);
        }
    }
    memset(people, 0, sizeof people);
    memset(langs, 0, sizeof langs);
    people[0] = true;
    for (int x : can[0]) {
        langs[x] = true;
        q.push(x);
    }
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int person : lang[v]) {
            if (people[person]) {
                continue;
            }
            people[person] = true;
            for (int x : can[person]) {
                if (langs[x]) {
                    continue;
                }
                langs[x] = true;
                q.push(x);
            }
        }
    }
    forn(i, n) {
        if (!people[i]) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 8824
n,t = map(int,input().split())
L = []
m = 0
for _ in range(n):
    a,b = map(int,input().split())
    m = max(b,m)
    L.append((a,b))
L.sort()
dp =[[0]*(t+m+1) for _ in range(n+1)]
for i in range(n):
    for j in range(t+m+1):
        if j-L[i][0]>=0 and t>j-L[i][0]:
            dp[i+1][j] = max(dp[i][j],dp[i][j-L[i][0]]+L[i][1])
        else:
            dp[i+1][j] = max(dp[i+1][j],dp[i][j])
ans = 0
for i in range(n+1):
    ans = max(ans,max(dp[i]))

print(ans)
#     L.append((b/a,a,b))
# L.sort(key = lambda x:(-x[0],x[1]))
# hq = []
# ans = []
# print(L)
# import heapq
# for c,a,b in L:
#     if a>=t:
#         heapq.heappush(hq,(-b,a,c))
#     else:
#         ans.append((b,a,c))
#         t-=a
# heapq.heapify(ans)
# if t ==0 and hq:
#     nb,nc,na = heapq.heappop(hq)
#     bb,bc,ba = heapq.heappop(ans)
#     if nb>bb:
#         heapq.heappush(ans,(-nb,nc,na))
#     else:
#         heapq.heappush(ans,(bb,b,c,ba))
# elif hq:
#     nb,nc,na = heapq.heappop(hq)
#     heapq.heappush(ans,(-nb,nc,na))
# res = 0
# for b,c,a in ans:
#     res += b
# print(ans)




Measured memory_bytes: 215952
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	ll k=n-1;
	cout<<(k*(k+1))/2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,k;
    cin>>a>>b>>k;
    if(a>=k) cout<<a-k<<" "<<b<<endl;
    else if(a<k)
    {
        if(b>=k-a)
        {
            cout<<0<<" "<<b-(k-a)<<endl;
        }
        else cout<<0<<" "<<0<<endl;
    }

    return 0;
}




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

long long int gcd(long long int a,long long int b){
    return b==0 ? a : gcd(b,a%b);
}

long long int lcm(long long int a,long long int b){
    return a*b / gcd(a,b);
}

int main (int argc, char const* argv[])
{
    long long int a,b;
    while(cin >> a >> b){
        cout << gcd(a,b) << " " << lcm(a,b) << endl;
    }
    return 0;
}

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

int f[2005],n,mod=1e9+7;

int main()
{
	cin>>n;
	f[0]=1,f[1]=0,f[2]=0,f[3]=1;
	for(int i=4;i<=n;i++) f[i]=(f[i-1]+f[i-3])%mod;
	cout<<f[n];
	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

struct St {
	int x1;
	int y1;
	int x2;
	int y2;
};

St r[500001];
int imos[5001][5001];
int main()
{
	int n, m;
	vector<int> x, y;
	vector<int> vx, vy;
	cin >> n >> m;
	REP(i, 0, n) {
		int xx, yy;
		cin >> xx >> yy;
		x.push_back(xx);
		y.push_back(yy);
		vx.push_back(xx);
		vy.push_back(yy);
	}
	REP(i, 0, m) {
		cin >> r[i].x1 >> r[i].y1 >> r[i].x2 >> r[i].y2;
	}

	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	y.erase(unique(y.begin(), y.end()), y.end());

	REP(i, 0, n + 1) imos[i][0] = imos[0][i] = 0;
	REP(i, 0, n) {
		int tx = lower_bound(x.begin(), x.end(), vx[i]) - x.begin();
		int ty = lower_bound(y.begin(), y.end(), vy[i]) - y.begin();
		++imos[ty + 1][tx + 1];
	}

	REP(i, 0, y.size()) {
		REP(j, 0, x.size()) {
			imos[i + 1][j + 1] += imos[i + 1][j] + imos[i][j + 1] - imos[i][j];
		}
	}

	REP(i, 0, m) {
		int xx1, yy1, xx2, yy2;
		xx1 = lower_bound(x.begin(), x.end(), r[i].x1) - x.begin();
		yy1 = lower_bound(y.begin(), y.end(), r[i].y1) - y.begin();
		xx2 = lower_bound(x.begin(), x.end(), r[i].x2 + 1) - x.begin();
		yy2 = lower_bound(y.begin(), y.end(), r[i].y2 + 1) - y.begin();

		cout << imos[yy2][xx2] - imos[yy2][xx1] - imos[yy1][xx2] + imos[yy1][xx1] << endl;
	}

	return 0;
}

Measured memory_bytes: 108792
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
using namespace std;
int main()
{
    IOS;
    int t=1;
	//cin>>t;
	while(t--)
	{
		float d,t,s;
		cin>>d>>t>>s;
		if(d/s<=t)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3700
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int N;
    cin >> N;
    vector<long long> a(N);
    vector<long long> b(N);
    rep(i, 0, N) { cin >> a[i]; }
    rep(i, 0, N) { cin >> b[i]; }
    long long kk = 1;
    long long res = 0;
    rep(k, 0, 30) {
        kk *= 2; // kkは2^(k+1)
        vector<long long> ma(N);
        vector<long long> mb(N);
        rep(i, 0, N) {
            ma[i] = a[i] % kk;
            mb[i] = b[i] % kk;
        }
        sort(mb.begin(), mb.end());
        int kosuu = 0;
        rep(i, 0, N) {
            int l1 =
                lower_bound(mb.begin(), mb.end(), kk / 2 - ma[i]) - mb.begin();
            int r1 =
                lower_bound(mb.begin(), mb.end(), kk - ma[i]) - mb.begin() - 1;
            if(l1 != N) {
                kosuu += r1 - l1 + 1;
            }
            int l2 = lower_bound(mb.begin(), mb.end(), kk + kk / 2 - ma[i]) -
                     mb.begin();
            int r2 = lower_bound(mb.begin(), mb.end(), kk * 2 - ma[i]) -
                     mb.begin() - 1;
            if(l1 != N) {
                kosuu += r2 - l2 + 1;
            }
            // if(k < 4) {
            //     cout << "kk:" << kk << " i:" << i << " ma[i]:" << ma[i]
            //          << " l1:" << l1 << " r1:" << r1 << " l2:" << l2
            //          << " r2:" << r2 << endl;
            // }
        }
        // cout << "k:" << k << " kosuu:" << kosuu << endl;
        if(kosuu % 2 != 0) {
            res += kk / 2;
        }
    }
    cout << res << endl;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  vector<LL> v(n);
  REP (i, n) {
    scanf("%lld", &v[i]);
  }

  LL ans = 0;
  int w = 0;
  int e = n - 1;
  bool isW = true;
  while (w < e) {
    if (isW && a * (v[w + 1] - v[w]) <= b) {
      ans += a * (v[w + 1] - v[w]);
      w++;
    } else if (isW) {
      w++;
      isW = false;
      ans += b;
    } else if (a * (v[e] - v[e - 1]) <= b) {
      ans += a * (v[e] - v[e - 1]);
      e--;
    } else {
      e--;
      isW = true;
      ans += b;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);

    cout << (N-2) * 180 << "\n";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=0
y=a[0]
for i in range(n):
  y=min(y,a[i])
  y+=a[i+1]
  x+=min(y,b[i])
  y=max(y-b[i],0)
print(x)

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

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T&a,const T&b){if(b<a){a=b;return true;}return false;}

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)par[i]=i;}
	int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
	void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
	bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

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


Measured memory_bytes: 848
N,M = map(int,input().split()) 
Pref_info = [[] for _ in range(N)] 
for i in range(M):
    P,Y = map(int,input().split())
    Pref_info[P - 1].append([Y,i])
ans = [""]* M 
for i in range(N): 
    Pref_info[i].sort()
    for index, p in enumerate(Pref_info[i]):
        ans[p[1]] = "{0}{1}".format(str(i+1).zfill(6),str(index+1).zfill(6))
for i in ans:
    print(i)

Measured memory_bytes: 39096
import java.util.*;

public class Main {
    private static Scanner scanner;

    public static int[] inputIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = scanner.nextInt();
        }

        return res;
    }

    public static void main(String args[]) {
        scanner = new Scanner(System.in);

            CONTINUE: while(true){
                String str = scanner.nextLine();
                
                if(str.equals("."))
                    break;
                
                
                Stack<String> stack = new Stack<>();
                try{
                for(int i = 0; i < str.length(); ++i) {
                    if(str.charAt(i) == '(') {
                        stack.push("(");
                    } else if(str.charAt(i) == ')') {
                        if(!stack.pop().equals("(")) {
                            System.out.println("no");
                            
                            continue CONTINUE;
                        }
                    } else if(str.charAt(i) == '[') {
                        stack.push("[");
                    }else if(str.charAt(i) == ']') {
                        if(!stack.pop().equals("[")) {
                            System.out.println("no");
                            
                            continue CONTINUE;
                        }
                    }
                }
                }catch(Exception e){
                    System.out.println("no");
                    continue CONTINUE;
                }
                
                System.out.println(stack.empty() ? "yes" : "no");
            }
    }
}


Measured memory_bytes: 44808
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N;
  set<string> v;
  for (int i=0; i<N; i++) {
    cin >> S;
    v.insert(S);
  }
  cout << v.size() << endl;
}

Measured memory_bytes: 19244
#include <bits/stdc++.h>
using namespace std;
int main(){

    int n, aux; cin >> n;
    aux = n;
    int sum = 0;
    while( aux ){
        sum+=( aux%10 );
        aux/=10;
    }
    if( n%sum == 0 ) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 0x3f3f3f3f3f3f3f3f
#define LL long long
#define MX 100005

#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
#include<vector>
#define N 201
vector<int> G[N];
int n,m;
int fat[N];
int low[N],dfn[N];
bool is_cut[N];
int Ddex;

void Init()
{
    Ddex=0;
    for (int i=1;i<=n;i++) G[i].clear();
    memset(dfn,-1,sizeof(dfn));
    memset(fat,-1,sizeof(fat));
    memset(is_cut,0,sizeof(is_cut));
}

void Tarjan(int i,int pre)
{
    fat[i]=pre;/*记录每一个点的父亲*/
    dfn[i]=low[i]=++Ddex;
    for(int j=0;j<G[i].size();++j)
    {
        int k=G[i][j];
        if(dfn[k]==-1)
        {
            Tarjan(k,i);
            low[i]=min(low[i],low[k]);
        }
        else if(k!=pre)/*假如k是i的父亲的话，那么这就是无向边中的重边，有重边那么一定不是桥*/
            low[i]=min(low[i],dfn[k]);
    }
}
void calc()
{
    int rootson=0;
    Tarjan(1,-1);
    for(int i=2;i<=n;++i)
    {
        int v=fat[i];
        if(v==1)
            rootson++;/*统计根节点子树的个数，根节点的子树个数>=2,就是割点*/
        else{
            if(low[i]>=dfn[v])/*割点的条件*/
                is_cut[v]=true;
        }
    }
    if(rootson>1)
        is_cut[1]=true;
        /*
    for(int i=1;i<=n;++i)
        if(is_cut[i])
            printf("%d\n",i);*/
    int ans = 0;
    for(int i=1;i<=n;++i)
    {
        int v=fat[i];
        if(v>0&&low[i]>dfn[v])//桥的条件
            ans++;
    }
    printf("%d\n",ans);
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        Init();
        int a,b;
        for(int i=1;i<=m;++i)
        {
            scanf("%d%d",&a,&b);
            G[a].push_back(b);
            G[b].push_back(a);
        }
        calc();
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N, X, T;
    cin >> N >> X >> T;
    if(N%X==0){
        cout << T*(N/X) << endl;
    }
    else{
        cout << T*(N/X)+T << endl;
    }
}

Measured memory_bytes: 3604
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7

dp = [0] * (1 << n)
dp[0] = 1

bitcount = [0]
for _ in range(n):
    bitcount += [i+1 for i in bitcount]

# 集めるDP
for bit in range(1,1 << n):
    i = bitcount[bit]
    for j in range(n):
        if (bit >> j) & 1 and a[i - 1][j] :
            dp[bit] += dp[bit ^ (1 << j)]
    dp[bit] %= mod
print(dp[(1 << n) - 1])


Measured memory_bytes: 129996
# -*- coding: utf-8 -*-
"""
Created on Fri May  8 15:19:53 2020

@author: shinba
"""
from sys import exit

n,k = map(int,input().split())
h = list(map(int,input().split()))

if k >= len(h):
    print(0)
    exit()
    
h.sort()

while k > 0:
    h.pop()
    k -= 1

print(sum(h))
    





Measured memory_bytes: 26764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int H,W;
string s;
int main(){
	cin>>H>>W;
	int c=0;
	rep(i,H){
		cin>>s;
		rep(j,W) if(s[j]=='#') c++;
	}
	if(c==H+W-1) puts("Possible");
	else puts("Impossible");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 999999999
const int mod = 1000000007;
ll cnt = 0;
 
int main(){
    ll n ;  cin >> n;
    vector<ll> a(n+2);

    for(int i=1;i<=n;i++){
        cin >> a.at(i);
    }
    ll ans = 0;

    for(int i=1;i<=n;i++){
        if(a.at(i) == i){
            cnt++;
        }
        else{
            ans +=(cnt+1)/2;
            cnt = 0;
        }
        if(i == n){
            ans+=(cnt+1)/2;
            cnt = 0;
        }
    }
     
     cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int n;
int pz[8][8];
bool chk[8][8];
int cnt;
ull ans;
vector<ull> v[64];

#define ENC(x,y) (((ull)1) << ((y)*n + (x)))

void check(int x, int y, int sum, ull f){
  chk[y][x] = true;

  if(sum == 0){
    v[cnt].push_back(f);
  }else if(sum < 0){
    REP(i,4){
      int xx = x + _dx[i];
      int yy = y + _dy[i];
      if(ISIN(xx,yy,n,n) && !chk[yy][xx] && pz[yy][xx] >= 0)
        check(xx,yy,sum+pz[yy][xx],(f|ENC(xx,yy)));
    }
  }

  chk[y][x] = false;
}

bool solve(int now, ull f){
  if(now == cnt)
    return f == ans;

  REP(i,v[now].size()){
    if((f & v[now][i]) == 0){
      if(solve(now+1, (f|v[now][i])))
        return true;
    }
  }

  return false;
}

int main(){
  while(scanf("%d",&n),n){
    int sum = 0;
    cnt = 0;

    REP(i,n) REP(j,n) scanf("%d",&pz[i][j]);
    REP(i,n) REP(j,n){
      int t = pz[i][j];
      sum += t;
      if(t < 0){
        v[cnt].clear();

        check(j,i,t,ENC(j,i));
        cnt++;
      }
    }

    if(sum != 0){
      puts("NO");
      continue;
    }

    ans = 0;
    REP(i,n*n){
      ans <<= 1;
      ans |= 1;
    }

    puts(solve(0,0)?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 952
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>


using namespace std;

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

char alfa[] = { 'A','B' ,'C','D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y','Z' };

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

unsigned GetDigit(double num) {
	return log10(num) + 1;
}

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

class Mod {
public:
	static inline ll Add(ll a, ll b) {
		return (a + b) % MOD;
	}

	static inline ll Sub(ll a, ll b) {
		ll ans = (a - b) % MOD;
		return (ans < 0) ? (ans + MOD) : ans;
	}

	static inline ll Mul(ll a, ll b) {
		return (a * b) % MOD;
	}

	static inline ll Div(ll a, ll b) {
		return (a % MOD) * modinv(b, MOD) % MOD;
	}
};



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

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

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

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

int parmitation(ll N) {
	ll ans = 1;
	for (ll i = 1; i <= N; i++) {
		ans *= i;
	}

	return ans;
}

int SemiCommonMultiple(ll A, ll ANum, ll B, ll BNum, ll diff, ll max) {
	ll calc;
	calc = diff + B * BNum - A * ANum;

	if (diff + B * BNum > max) {
		return 0;
	}
	else {
		if (calc < 0) {
			SemiCommonMultiple(A, ANum, B, ++BNum, diff, max);
		}
		else if (calc > 0) {
			SemiCommonMultiple(A, ++ANum, B, BNum, diff, max);
		}
		else {
			return A * (ANum + 0.5);
		}
	}
}

ll  CaracalVsMonstor(ll H, ll sum, ll count) {
	if (H == 0) {
		return sum;
	}


	H = H / 2;
	sum = sum + count;

	count = count * 2;

	return CaracalVsMonstor(H, sum, count);

}

class ibis {
public:
	ll A;
	ll B;
	ld spec;

	bool operator<(const ibis& another) const
	{
		return spec < another.spec;
	};
};

inline void Main() {
	ll X, Y, N, M, K;
	vector<ll> A;
	vector<ll> B;
	vector<ll> C;
	ll M1 = 1, D1 = 0, M2 = 1, D2 = 0;
	ll ans, temp =0;
	ll sum = 0, count = 0, a = 0;
	double avg = 0.0;
	string S;
	string T;
	string Ans = "";
	bool b[8];
	bool flag = false;


	cin >> N;

	for (int i = 1; i <= N; i++) {
		if ((i%3 != 0) && (i%5 != 0)) {
			sum += i;
		}
	}


	cout << sum;
}

Measured memory_bytes: 3676