akhauriyash/Code-Regression huggingface dataset:
def f(n, x, a, p):
    if n == 0:
        return 1 if x == 1 else 0

    elif x <= 1:
        return 0

    elif 1 < x <= 1 + a[n - 1]:
        return f(n - 1, x - 1, a, p)

    elif x == 2 + a[n - 1]:
        return p[n - 1] + 1

    elif 2 + a[n - 1] < x <= 2 + 2 * a[n - 1]:
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1], a, p)

    else:
        return 1 + 2 * p[n - 1]


n, x = map(int, input().split())

a = [1] * (n + 1)
p = [1] * (n + 1)

for i in range(1, n + 1):
    a[i] = 3 + 2 * a[i - 1]
    p[i] = 1 + 2 * p[i - 1]

print(f(n, x, a, p))



Measured memory_bytes: 61868
import sys
sys.setrecursionlimit(10 ** 6)
import sys
def input():
    return sys.stdin.readline()[:-1]
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
#print(graph)
for _ in range(Q):
    a , b = map(int,input().split())
    a = a - 1
    point[a] += b

# dfsを用いて累積和を計算する
# 初期状態だと前の値がないためデフォルト引数に-1を代入
def dfs(now , prev = -1):
    for next in graph[now]:
        # 次のノードが前に参照した値の時はcontinue
        if next == prev:
            continue

        # 現在の値を次のポイントに加算することで累積和をとる
        point[next] += point[now]

        # 次のノードと現在のノードを引数にdfsを継続する
        dfs(next , now)

dfs(0)
print(*point)

Measured memory_bytes: 268464
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.NoSuchElementException;

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

	void run() {
		FastScanner sc=new FastScanner();
		long A=sc.nextLong();
		long B=Math.round(sc.nextDouble()*100);
		System.out.println(BigInteger.valueOf(A).multiply(BigInteger.valueOf(B)).divide(BigInteger.valueOf(100)));
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 33320
//k_k_dubey_
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
#define non __builtin_popcount
#define ml map<ll, ll> 
#define ms map<string , ll> 
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	
	ll n, m, i, j, a[mx], dp[mx];
	dp[0]= 1, dp[1]= 1;
	cin>>n>>m;
	for(i=2; i<n+1; i++)
	dp[i]= -1;
	
	for(i=0; i< m; i++)
	{
	    cin>>a[i];
	    dp[a[i]]= 0;
	}
	for(i=2; i<n+1; i++){
	    
	    if(dp[i])
	    dp[i]= (dp[i-1] + dp[i-2]) %mod;
	    
	}
	
	dp[n]%= mod;
	cout<<dp[n];
    return 0;
}























Measured memory_bytes: 2688
#include<stdio.h>
int main()
{
    int n,a,b,s;
    scanf("%d",&n);
    if(n==1)
    {
        printf("Hello World");
    }
    else if(n==2)
    {
        scanf("%d" ,&a);
        scanf("%d",&b);
        s=a+b;
        printf("%d",s);

    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
int N, P;
vector<int> A;
unordered_map<int, int64_t> memo;

int64_t dfs(int idx, int par) {
  int key = idx * 2 + par;
  if (memo.count(key)) return memo[key];
  if (idx == N) {
    return (par == P) ? 1 : 0;
  }
  int64_t ret = dfs(idx + 1, par) + dfs(idx + 1, (par + A[idx]) % 2);
  return memo[key] = ret;
}

int main(void) {
  cin >> N >> P;
  A.resize(N);
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A[i] = a % 2;
  }
  cout << dfs(0, 0) << endl;
  return 0;
}

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

using namespace std;

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


	long long sum = 0;
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		int a;
		scanf("%d", &a);
		if(a == 0){
			ans += sum / 2;
			sum = 0;
		}
		else{
			sum += a;
		}
	}
	ans += sum / 2;
	sum = 0;
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(1){
    c-=b;
    if(c<=0){
      cout << "Yes" << endl;
      return 0;
    }
    a-=d;
    if(a<=0){
      cout << "No" << endl;
      return 0;
    }
  }
  
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
int min(int a,int b){
	return (a>b?b:a);
}

int go(int *a,int n){
    int f=0;
    if(n==1) return f;
    int s=abs(a[0]-a[1]);
    if(n==2) return s;
    int c=INT_MAX;
    for(int i=2;i<n;i++){
        c=min(s+abs(a[i]-a[i-1]),f+abs(a[i]-a[i-2]));
        f=s;
        s=c;
    }
    return c;
}
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  cout<<go(a,n)<<endl;
 return 0; 
}



Measured memory_bytes: 3924
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(18);
}

signed main(){
  init_io();
  ll n,sum=0;
  cin >> n;
  ll c[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> c[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      sum += min(c[i][j],c[j][i]);
    }
  }
  cout << sum << endl;
}



Measured memory_bytes: 3260
import os
import sys
from io import BytesIO, IOBase


def main():
    n = int(input())
    arr = list(map(int, input().split()))
    arr.sort()
    ans = 0
    k=max(arr)
    d = [0]*(k+1)
    for i in range(n):
        d[arr[i]]+=1
    for i in range(n):
        x=arr[i]
        if d[x]==1:
            ans+=1
        for j in range(x,k+1,x):
            d[j]+=1
    print(ans)


# fast-io region

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def input():
    return sys.stdin.readline().rstrip("\r\n")


def write(*args, end="\n"):
    for x in args[:-1]:
        sys.stdout.write(str(x) + " ")
    sys.stdout.write(str(args[-1]))
    sys.stdout.write(end)


def r_array():
    return [int(x) for x in input().split()]


def r_int():
    return int(input())


if __name__ == "__main__":
    main()


Measured memory_bytes: 34036
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;

int main(){
    int n;
    std::cin >> n;
    std::vector<ll> a(n);
    rep(i,n){
        std::cin >> a[i];
        a[i]-=i;
    }
    sort(all(a));
    ll aaa=0ll,aa=0ll;
    if(n==1){
        std::cout << 0 << std::endl;
        exit(0);
    }
    else{
        ll ab=a[n/2-1];
        //ll aa=0ll;
        rep(i,n){
            aa+=abs(a[i]-ab);
        }
        ll aab=a[n/2];
       
        rep(i,n){
            aaa+=abs(a[i]-aab);
        }
    }
    std::cout << min(aaa,aa) << std::endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,k;cin>>n>>k;
    vint h(n);
    rep(i, n)cin>>h[i];
    sort(all(h));
    int a = 1000000000;
    rep(i, n-k+1){
        chmin(a, h[i+k-1]-h[i]);
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int n; cin >> n;
	if(n < 1000) cout << "ABC" << endl;
	else cout << "ABD" << endl;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)
func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var a, b, c, d int
  fmt.Scan(&a, &b, &c, &d)
  fmt.Println(maxInt(a*b, c*d))
}

Measured memory_bytes: 512
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, ans = 0, be, n;
  scanf("%lld", &n);
  ll a[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  be = a[0] > 0 ? a[0] : 1;
  if(a[0] <= 0) ans = 1 - a[0];
  for(i = 1; i < n; ++i) {
    if(be > 0 && -1 < be + a[i]) ans += be + a[i] + 1, be = -1;
    else if(be < 0 && 1 > be + a[i]) ans += 1 -be - a[i], be = 1;
    else be += a[i]; 
  }
  ll tmp = ans;
  ans = 0;
  be = a[0] < 0 ? a[0] : -1;
  if(a[0] >= 0) ans = a[0] + 1;
  for(i = 1; i < n; ++i) {
    if(be > 0 && -1 < be + a[i]) ans += be + a[i] + 1, be = -1;
    else if(be < 0 && 1 > be + a[i]) ans += 1 -be - a[i], be = 1;
    else be += a[i]; 
  }
  printf("%lld", (ans > tmp ? tmp : ans));
  return 0;
}

Measured memory_bytes: 896
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 3000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int n, m, k;
int fa[N], size[N], del[N];
inline int find(int x) {
    return x == fa[x] ? fa[x] : fa[x] = find(fa[x]);
}

inline void merge(int x, int y) {
    int fx = find(x), fy = find(y);
    if (fx == fy) return;
    fa[fx] = fy;
    size[fy] += size[fx];
}

int main() {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) fa[i] = i, size[i] = 1;
    for (int i = 1; i <= m; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        merge(u, v);
        del[u]++;
        del[v]++;
    }
    for (int i = 1; i <= k; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        if (find(u) == find(v)) {
            del[u]++;
            del[v]++;
        }
    }
    for (int i = 1; i <= n; i++) {
        printf("%d ", size[find(i)] - del[i] - 1);
    }
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<string,string> Pss;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int f[MAX_N]={};
int b[MAX_N]={};
bool dp[MAX_N]={};
vector<Pss> Vs,Vs2;

int main() {
	int n,f;
	cin>>n>>f;
	rep(i,n){
		vector<string> Vstr;
		int m;
		cin>>m;
		rep(j,m){
			string str;
			cin>>str;
			Vstr.push_back(str);
		}
		sort(Vstr.begin(),Vstr.end());
		rep(j,m){
			for(int k=j+1;k<m;++k){
				Vs.push_back(Pss(Vstr[j],Vstr[k]));
			}
		}
	}
	sort(Vs.begin(),Vs.end());
	Pss ps=Pss("","");
	int total=0;
	rep(i,Vs.size()){
		if(Vs[i]==ps){
			total++;
		}else{
			if(total>=f)Vs2.push_back(ps);
			total=1;
			ps=Vs[i];
		}
	}
	if(total>=f)Vs2.push_back(ps);
	sort(Vs2.begin(),Vs2.end());

	cout<<Vs2.size()<<endl;
	rep(i,Vs2.size()){
		cout<<Vs2[i].first<<" "<<Vs2[i].second<<endl;
	}

	return 0;
}



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

int main(){
    string s;
    cin >> s;
    //cout << s << endl;
    int num=s.size();
    //cout << num << endl;
    ll sum=0;
    rep(i,1<<(num-1)){
	ll temp=0;
	ll part=0;
	//cout << bitset<8>(i) << endl;
	rep(j,num){	
		part=part*10+ll(s[j]-'0');	
		//cout << j <<":" <<part << endl;		
		if((i>>j)&1){
			temp+=part;
			part=0;
		}
		else{
			if(j==num-1) {
			temp+=part;
			part=0;
			}	
		}		
		}
        //cout << temp << endl;
	sum+=temp;
	}
	
	cout << sum << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353//1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

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

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

inline int func(int a, int b)
{
	if (a > b)
		return a - b;
	else
		return b - a;
}

int main()
{
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
		printf("Yes");
	else
		printf("No");

	return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int cv(int t){
	return t/100*60+t%100;
}
int main(){
	int n,p,q,k,a,b,m,c,i;
	while(cin>>n>>p>>q,n){
		int v[1440]={};
		for(i=0;i<n;++i){
			cin>>k;
			while(k--){
				cin>>a>>b;
				++v[cv(a)]; --v[cv(b)];
			}
		}
		for(i=1;i<1440;++i) v[i]+=v[i-1];
		m=0,c=0;
		for(i=cv(p);i<cv(q);++i){
			m=max(m,c=v[i]<n?c+1:0);
		}
		cout<<m<<endl;
	}
}

Measured memory_bytes: 1164
n,x,y = map(int, input().split())
LIST = [0] * (n - 1)
for i in range(1, n):
    for j in range(i+1, n+1):
        path = min(j - i, abs(x-i) + 1 + abs(y-j))
        LIST[path-1] += 1
for i in range(n-1):
    print(LIST[i])

Measured memory_bytes: 3444
N,M = list(map(int,input().split()))
L = 1
R = N+1
ans = N*2

for i in range(M):
    tL,tR = list(map(int,input().split()))
    if tR < L or R < tL:
        ans = 0
        break
    if tL > L:
        L = tL
    if tR < R:
        R = tR

print(min(ans,R-L+1))

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)
vector<vector<pair<int, int>>> g;
vector<int> color;
vector<int> visited;

void dfs(int v, int from) {
	auto c = color[v];
	for (const auto e : g[v]) {
		if(e.first != from)
		if (color[e.first] == 0) {
			color[e.first] = (e.second % 2 == 0 ? c : -c);
			dfs(e.first, v);
		}
	}
}

int main(void)
{
	ll n;
	cin >> n;
	g.resize(n);
	color.resize(n, 0);
	visited.resize(n, 0);
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	color[0] = 1;
	dfs(0, 0);
	rep(i, n) {
		cout << max(0, color[i]) << endl;
	}
	return 0;
}

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

int main()
{
    std::string s;
    std::cin >> s;
    int res = 0;
    for(int i = 1; i < (int)s.size(); i++){
        if(s[i] != s[i - 1])res++;
    }
    std::cout << res << std::endl;
}

Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#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 chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int N;
	cin >> N;


	int A[200000];
	int B[200010] = {};
	ll kotae = 0;
	rep(i, N) {
		cin >> A[i];
		kotae += B[A[i]]++;
	}

	rep(i, N) {
		co(kotae - B[A[i]] + 1);
	}



	Would you please return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
 
using namespace std;
int main(){
    long n;std::cin >> n;
  	long a[5];
  	for(int i=0;i<5;i++)std::cin>>a[i];
  	long k=a[0];
  	for(int i=1;i<5;i++)k=min(k,a[i]);
  	long tim=n/k;
  	if(n%k==0)tim=n/k-1;
  	cout<<tim+5<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws ClassNotFoundException, IOException {
		FastScanner sc = new FastScanner();
		String S = sc.next();
		String[] sArray = S.split("");
		String pre = sArray[0];
		boolean flag = false;

		for(int i = 1; i < 4; i++) {
			if(pre.equals(sArray[i])) {
				flag = true;
				break;
			}
			pre = sArray[i];
		}
		if(flag) {
			System.out.println("Bad");
		}else {
			System.out.println("Good");
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

int main()
{
  int h, w;
  std::vector<std::pair<int, int>> list;
  for (;;)
  {
    std::cin >> h >> w;
    if(h==0 && w==0) break;
    list.push_back(std::make_pair(h,w));
  }
  for(auto e : list)
  {
    for (int i = 0; i < e.first;i++)
    {
      for (int j = 0; j < e.second;j++)
      {
        std::cout << "#";
      }
      std::cout << "\n";
    }
    std::cout << "\n";
  }
  return 0;
}



Measured memory_bytes: 3092
if __name__ == "__main__":
    H, W = map(int, input().split())
    a = list()
    for i in range(H):
        a.append(input())
    
    # 黒がある場所のリスト化
    col_list = list()
    row_list = list()

    for i in range(H):
        for j in range(W):
            if a[i][j] == '#':
                if (i in row_list) is False:
                    row_list.append(i)
                if (j in col_list) is False:
                    col_list.append(j)
    
    for i in range(H):
        ans = ''
        for j in range(W):
            if (j in col_list) and (i in row_list):
                ans += a[i][j]
        if len(ans) > 0:
            print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

int N,M;
ll cumSum[2][1001000];
ll si[100001];
ll ti[100001];
ll pi[100001];

int main(){

    cin>>N>>M;
    for(int i=0;i<N;i++)cin>>si[i]>>ti[i];
    for(int i=1;i<=M;i++)cin>>pi[i];
    sort(pi+1,pi+M+1);
    pi[0]=0;
    pi[M+1]=1000000010;
    // æÔÌÝÏaðßÄ¨­
    for(int i=0;i<=M;i++){
        for(int j=0;j<2;j++){
            cumSum[j][i+1]=cumSum[j][i];
        }
        cumSum[(i%2)][i+1]+=pi[i+1]-pi[i];
    }
    M++;
    ll sum=0;
    // ¶ÌÓÆEÌÓªÇÌÍÍÉ ½é©ñªTõÅT·
    for(int i=0;i<N;i++){
        int leftIdx=upper_bound(pi,pi+M+1,si[i])-pi;
        int rightIdx=upper_bound(pi,pi+M+1,ti[i])-pi;
        // ¯¶ÓÉ éêÍAS·
        if(leftIdx==rightIdx)
            sum+=abs(ti[i]-si[i]);
        else{
            int oldl=leftIdx;
            int oldr=rightIdx;
            if(leftIdx>rightIdx)leftIdx--;
            else rightIdx--;
            int ang=0;
            int kind=0;
            // î_ªÇ±É é©
            if(leftIdx<rightIdx){
                if(leftIdx%2==0)ang=1;
            }
            else{
                if(leftIdx%2==1)ang=1;
            }
            ll a=0;
            ll b=0;
            if(oldl>oldr){
                a=si[i]-pi[leftIdx];
                b=pi[rightIdx]-ti[i];
            }
            else {
                a=pi[leftIdx]-si[i];
                b=ti[i]-pi[rightIdx];
            }
            // ^ñÌaðvZ
            if(leftIdx>rightIdx)swap(leftIdx,rightIdx);
            ll cent=cumSum[ang][rightIdx]-cumSum[ang][leftIdx];
            sum+=cent+a;
            if(rightIdx%2!=leftIdx%2)sum+=b;
        }
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 21+1;
const int MSK = (1<<22)+7;

int n;
bool a[N][N];
ll dp[N][MSK];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);


    cin >> n;
    REP(i,0,n-1) REP(j,0,n-1) cin >> a[i][j];

    // dp[i][msk] = number of ways to choose pairs from first i men while msk women are choosen

    REP(msk,0,(1<<n)-1)
    {
        if (__builtin_popcount(msk) != 1) continue;
        REP(j,0,n-1)
        {
            if ((msk&(1<<j)) && a[0][j]) dp[0][msk] = 1;
        }
    }

    REP(i,1,n-1)
    {
        REP(msk,0,(1<<n)-1)
        {
            if (__builtin_popcount(msk) != i+1) continue;
            REP(j,0,n-1)
            {
                if ((msk&(1<<j)) && a[i][j]) dp[i][msk] = (dp[i][msk]+dp[i-1][msk^(1<<j)])%MOD;
            }
        }
    }
    cout << dp[n-1][(1<<n)-1] << endl;
    return 0;
}


Measured memory_bytes: 321792
def main():
    W, a, b = map(int, input().split())

    if (a + a + W)//2 < b:
        if b > a + W:
            print(b - (a + W))
        else:
            print(0)
    elif(a + a + W)//2 > (b + W):
        if a > (b + W):
            print(a - (b + W))
        else:
            print(0)
    else:
        print(0)
main()

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
int a[100000];
int b[100000];
int c[100000];
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100];
int main() {
  cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

void solve(long long N, std::string S){
    // それぞれのこすう
    ll Nred = count(S.begin(), S.end(), 'R');
    ll Ngreen = count(S.begin(), S.end(), 'G');
    ll Nblue = count(S.begin(), S.end(), 'B');
    // 全部で色のことなるもの
    ll total = Nred*Ngreen*Nblue;
    // あいだがひとしいもの
    ll Nsym = 0;
    for(int i=0; i < S.size(); i++){
        for(int j=i+1; j < S.size(); j++){
            if((i+j) % 2 != 0){
                // 中点がとれない
                continue;
            }
            int k = (i+j)/2;
            if(S.at(i) != S.at(j) && S.at(j) != S.at(k) && S.at(k) != S.at(i)){
                Nsym++;
            }
        }
    }

    cout << total - Nsym << endl;
}

// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3708
def decode():
    [n, k] = [int(x) for x in input().split(" ")]
    ws = []
    for _ in range(n):
        ws.append(int(input()))

    return n, k, ws


def check(k, ws, p):
    sum_w = ws[0]
    tr = 1

    for w in ws[1:]:
        if sum_w + w <= p:
            sum_w += w
        else:
            sum_w = w
            tr += 1

            if tr > k:
                return False

    return True


if __name__ == '__main__':
    n, k, ws = decode()

    lo = max(ws)
    hi = sum(ws)

    while lo <= hi:
        p = (lo + hi) // 2

        if check(k, ws, p):
            hi = p - 1
            ans = p
        else:
            lo = p + 1

    print(ans)


Measured memory_bytes: 10356
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,r;
    cin>>n>>r;
    if(n>=10)
    {
        cout<<r<<endl;
    }
    else
    {
        cout<<r+100*(10-n)<<endl;
    }
    return 0;
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;
template <typename Int, Int MOD, int N>
struct comb_util {
	std::array<Int, N + 1> fc, ifc;

	comb_util() {
		fc[0] = 1;
		for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
		ifc[N] = inv(fc[N]);
		for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
	}

	Int fact(Int n) { return fc[n]; }

	Int inv_fact(Int n) { return ifc[n]; }

	Int inv(Int n) { return pow(n, MOD - 2); }

	Int pow(Int n, Int a) {
		Int res = 1, exp = n;
		for (; a; a /= 2) {
			if (a & 1) res = res * exp % MOD;
			exp = exp * exp % MOD;
		}
		return res;
	}

	Int perm(Int n, Int r) {
		if (r < 0 || n < r)
			return 0;
		else
			return fc[n] * ifc[n - r] % MOD;
	}

	Int binom(Int n, Int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
	}

	Int homo(Int n, Int r) {
		if (n < 0 || r < 0) return 0;
		return r == 0 ? 1 : binom(n + r - 1, r);
	}
};

using comb = comb_util<long long, 1000000007, 3000000>;
comb cb;
vector<vector<int> > g;
int res = 0;
int N;
int dfs(int a, int p) {
	int sz = 1;
	int ans = cb.pow(2, N - 1);
	vector<int> X;
	for (int i : g[a]) {
		if (i != p) {
			int t = dfs(i, a);
			X.push_back(t);
			sz += t;
		}
	}
	X.push_back(N - sz);
	for (int i : X) {
		ans -= cb.pow(2, i) - 1;
	}
	ans--;
	ans %= MOD;
	ans += MOD;
	ans %= MOD;
	res = (res + ans) % MOD;
	return sz;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	g.resize(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, -1);
	res = (res * cb.pow(cb.inv(2), N)) %MOD;
	cout << res << endl;
}

Measured memory_bytes: 74112
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;
using ll = long long;

template <typename T>
class Queue {
private:
    vector<T> pulled, pushed;

public:
    void push(T a) {
        pushed.push_back(a);
    }

    T pop() {
        if (pulled.empty()) {
            reverse(pushed.begin(), pushed.end());
            pulled = pushed;
            pushed.clear();
        }
        T top = pulled.back();
        pulled.pop_back();
        return top;
    }

    T front() {
        return pulled.front();
    }

    int size() {
        return pulled.size() + pushed.size();
    }

    bool empty() {
        return size() == 0;
    }
};


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

    vector<pair<int, ll>> path[N + 1];
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        path[a].push_back(make_pair(b, c));
        path[b].push_back(make_pair(a, c));
    }

    int Q, K;
    cin >> Q >> K;

    ll d[N + 1];
    fill(d, d + N + 1, -1);
    d[K] = 0;

    Queue<int> que;
    que.push(K);

    while (!que.empty()) {
        int v = que.pop();
        for (auto p : path[v]) {
            int sv;
            ll c;
            tie(sv, c) = p;

            if (d[sv] < 0) {
                d[sv] = d[v] + c;
                que.push(sv);
            }
        }
    }

    for (int q = 0; q < Q; ++q) {
        int x, y;
        cin >> x >> y;
        cout << d[x] + d[y] << endl;
    }
    return 0;
}


Measured memory_bytes: 10096
#include <cstdio>           // printf(), scanf()
#include <cmath>            // fabs(), sqrt()
#include <algorithm>        // swap()

using namespace std;
static const double EPS = 1e-10;

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
};

typedef Point Vector;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
abs(Vector a)
{
	return sqrt(norm(a));
}

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}


double
cross(Vector a, Vector b)
{
	return a.x * b.y - a.y * b.x;
}

Point g[3];
Point p;

bool
solve()
{
	bool f = false;
	for (int i = 0; i < 3; ++i)
	{
		Point a = g[i] - p, b = g[(i + 1) % 3] - p;
		if (abs(cross(a, b)) < EPS && dot(a, b) < EPS)
			return false;

		if (a.y > b.y)
			swap(a, b);

		if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
			f = !f;
	}

	return f;
}

int
main(int argc, char** argv)
{
	while (true)
	{
		int i;

		for (i = 0; i < 3; ++i)
		{
			if (scanf("%lf %lf", &g[i].x, &g[i].y) == EOF)
				break;
		}

		if (i < 3 || scanf("%lf %lf", &p.x, &p.y) == EOF)
			break;


		printf("%s\n", solve() ? "YES" : "NO");
	}

	return 0;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define emp emplace

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 21;

int pd[N+1][1 << N];
int a[N+1][N+1];

vector<int> m[N+1];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}

	for (int mask = 0; mask < (1 << n); mask++)
		m[__builtin_popcount(mask)].pb(mask);

	pd[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int mask : m[i])
		{
			for (int b = 0; b < n; b++)
			{
				if (a[i][b+1] and ((mask >> b)&1) == 1)
				{
					pd[i][mask] += pd[i-1][mask^(1 << b)];
					pd[i][mask] %= MOD;
				}
			}
		}
	}
	printf("%d\n", pd[n][(1 << n)-1]);
	return 0;
}



Measured memory_bytes: 171452
#include <iostream>
using namespace std;
 
int main() {
  unsigned long H, W;
  cin >> H >> W;
  if(H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }
  cout << (H * W / 2) + ((H * W) % 2) << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool flag=true;


int main() {
ll A,B;
  cin >> A;


 if(A==999){
     A=111;
  cout<<A<<endl;
  return 0;
}
 if(A==991){
     A=119;
  cout<<A<<endl;
  return 0;
}
 if(A==919){
     A=191;
  cout<<A<<endl;
  return 0;
}
 if(A==911){
     A=199;
  cout<<A<<endl;
  return 0;
}
 if(A==199){
     A=911;
  cout<<A<<endl;
  return 0;
}
 if(A==191){
     A=919;
  cout<<A<<endl;
  return 0;
}
 if(A==119){
     A=991;
  cout<<A<<endl;
  return 0;
}
 if(A==111){
     A=999;
  cout<<A<<endl;
  return 0;
}

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		StringBuilder sb = new StringBuilder();
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int a[][] = new int[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int hh = 0, ww = 0, cnt = 0;
		boolean b = false;
		for (int i = 0; i < h; i++) {
			if (i % 2 == 0) {
				for (int j = 0; j < w; j++) {
					if (b) {
						a[i][j]++;
						sb.append(hh + " " + ww + " " + (i + 1) + " " + (j + 1) + "\n");
						b = false;
						cnt++;
					}
					if (a[i][j] % 2 != 0) {
						hh = i + 1;
						ww = j + 1;
						b = true;
					} else {

					}
				}
			} else {
				for (int j = w - 1; j >= 0; j--) {
					if (b) {
						a[i][j]++;
						sb.append(hh + " " + ww + " " + (i + 1) + " " + (j + 1) + "\n");
						b = false;
						cnt++;
					}
					if (a[i][j] % 2 != 0) {
						hh = i + 1;
						ww = j + 1;
						b = true;
					} else {

					}
				}
			}
		}

		System.out.println(cnt);
		System.out.print(sb);
	}
}


Measured memory_bytes: 94132
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI = atan(1.0)*4.0;

int main(void){
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double thetaH = (double)H/12.0 + (double)M/720.0;
    thetaH *= PI * 2.0;
    double thetaM = (double)M/60.0;
    thetaM *= PI * 2.0;
    double HX = sin(thetaH) * (double)A;
    double HY = cos(thetaH) * (double)A;
    double MX = sin(thetaM) * (double)B;
    double MY = cos(thetaM) * (double)B;
    cout << setprecision(12) << sqrt((HX-MX)*(HX-MX)+(HY-MY)*(HY-MY)) << endl;
    return 0;
}

Measured memory_bytes: 4124
#include<stdio.h>
#include<math.h>

int main() {

	double r, S, L,pai;

	scanf("%lf", &r);

	pai = acos(-1);

	S = pai * r * r;

	L = 2 * pai * r;

	printf("%f %f\n",S,L);

	return 0;


}


Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
char a[52],b[52];

int main(){
    cin>>a;
    cin>>b;
    int la=strlen(a),lb=strlen(b);
    int l=min(la,lb),ll=max(la,lb);
    for(int i=0;i<=l-1;i++)
        cout<<a[i]<<b[i];
    if(la>lb)
        for(int i=l;i<=ll-1;i++)
            cout<<a[i];
    else for(int i=l;i<=ll-1;i++)
            cout<<b[i];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
 
int n, mn, x, v[30], d[200005], ju[200005], u[200005];
string a, ans;
int main()
{
	int i, j, t;
	cin >> a;
	n = a.size();
	a = '.' + a;
	for (i = 0; i < 26; i++) v[i] = n + 1;
	for (i = n; i >= 0; i--) {
		mn = 2e9;
		for (j = 0; j < 26; j++) {
//			if (a[i] - 'a' == j) t = d[v[j]] + 1;
			t = d[v[j]];
			if (t < mn) {
				mn = t;
				x = j;
			}
		}
		ju[i] = v[x];
		d[i] = mn + 1;
		if (i > 0) v[a[i] - 'a'] = i;
		u[i] = x;
	}
	i = 0;
	do {
		ans += (char)(u[i] + 'a');
		i = ju[i];
	} while (i <= n);
	cout << ans;
    return 0;
}

Measured memory_bytes: 2880
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5, mod = 998244353;
int n, k, fac[maxn + 10], ifac[maxn + 10], inv[maxn + 10];
int ans;

void init() {
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= maxn; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % mod;
		inv[i] = i == 1 ? 1 : mod - 1ll * (mod / i) * inv[mod % i] % mod;
		ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
	}
}

int comb(int x, int y) {
	if (y < 0 || y > x) return 0;
	return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}

void work(int x, int y, int l) {
	(ans += comb(x + y, x)) %= mod;
	(ans += mod - comb(x + y, x + l)) %= mod;
}

int main() {
	init();
	scanf("%d%d", &n, &k);
	for (int i = 0; i <= k; ++i) {
		int r = i, b = k - i;
		if (r < max(n, b)) continue;
		else if (r == b)
			work(r, b - 1, r - n + 1);
		else 
			work(r, b, r - n + 1);
	}
	printf("%d", ans);
}


Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

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

void solve()
{
	long long int a, b;
	cin >> a >> b;
	if (a > 0 && b > 0)
	{
		cout << "Positive" << endl;
	}
	else if (a == 0 || b == 0)
	{
		cout << "Zero" << endl;
	}
	else if (a < 0 && b > 0)
	{
		cout << "Zero" << endl;
	}
	else
	{
		if ((b - a) % 2 == 0)
		{
			cout << "Negative" << endl;
		}
		else
		{
			cout << "Positive" << endl;
		}
	}
}

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

Measured memory_bytes: 256