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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


// Xor Sum 2
int N, a[223456], sum[223456], xo[223456];

signed main(){

	cin >> N;
	rep(i,N){
		 cin >> a[i];
		sum[i+1] = sum[i] + a[i];
		xo[i+1] = xo[i] ^ a[i];
	}
	
	int ans=0;
	int le=0, ri=0;
	for(le=0; le<N; le++){
		//ri = le;
		while(ri<N && (sum[ri+1]-sum[le] == (xo[ri+1]^xo[le]))){
		//	cerr << le << " " << ri << endl;
		//	cerr << "  " << sum[ri+1]-sum[le] << " " << (xo[ri+1]^xo[le]) << endl;
			ri++;
		}
		ans += ri - le;
	}
	

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5120
#include "iostream"
#include "cstdio"
#include "cstring"
#include "cmath"
#include "cstdlib"
#include "cctype"
#include "iomanip"
#include "algorithm"
#include "ctime"
#include "set"
#include "queue"
#include "map"
#include "stack"
#include "vector"
#include "deque"
#define lxl long long
#define R register
#define INF 0x3f3f3f3f
#define debug(x) printf("debug:%lld\n",x)
#define debugf(x) printf("debug:%llf\n",x)
const lxl maxn=2010;
lxl n,EdgeSize,ans=INF;
lxl head[maxn],a[maxn],dis[maxn],f[maxn],size[maxn];
struct _Edge
{
	lxl next,v;
}e[maxn<<1];
inline lxl read()
{
	char c=getchar();
	lxl f=1,x=0;
	for(;!isdigit(c);c=getchar())(c=='-')&&(f=-1);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return f*x;
}
inline void EdgeAdd(lxl u,lxl v)
{
	e[EdgeSize].v=v,e[EdgeSize].next=head[u];
	head[u]=EdgeSize++;
	e[EdgeSize].v=u,e[EdgeSize].next=head[v];
	head[v]=EdgeSize++;
	return void(0);
}
inline void init()
{
	memset(f,0,sizeof f),memset(size,0,sizeof size),memset(dis,0,sizeof dis);
}
void dfs(lxl u,lxl fa)
{
	lxl MaxP=0;
	size[u]=a[u];
	for(R int i(head[u]);~i;i=e[i].next)
	{
		lxl v=e[i].v;
		if(v==fa)continue;
		dfs(v,u);
		size[u]+=size[v],dis[v]+=size[v],dis[u]+=dis[v];
		MaxP=dis[v]>dis[MaxP]?v:MaxP;
	}
	if(!MaxP)return void(f[u]=0);
	if(dis[u]-dis[MaxP]>=dis[MaxP])f[u]=dis[u]/2;
	else f[u]=dis[u]-dis[MaxP]+std::min(f[MaxP],(dis[MaxP]+dis[MaxP]-dis[u])/2);
}
int main(void)
{
	memset(head,-1,sizeof head);
	n=read();
	for(R int i(1);i<=n;++i)scanf("%1lld",a+i);
	for(R int i(1);i<n;EdgeAdd(read(),read()),++i);
	for(R int i(1);i<=n;init(),++i)
	{
		dfs(i,0);
		if(dis[i]&1)continue;
		if(f[i]<<1>=dis[i])ans=std::min(ans,dis[i]/2);
	}
	if(ans<INF)printf("%lld\n",ans);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sa=0,sb=0,sc=0,a,b,n,i,t;
	scanf("%d\n%d %d",&n,&a,&b);
	for(i=0;i<n;i++)
	{
		scanf("%d",&t);
		if(t<=a)
			sa++;
		else if(t>a&&t<=b)
			sb++;
		else
			sc++;
	}
	printf("%d",min(sa,min(sb,sc)));
	return 0;
}

Measured memory_bytes: 256
from math import gcd
N = int(input())
A = list(map(int,input().split()))

g = 0
for a in A:
    g = gcd(g,a)
if g > 1:
    print('not coprime')
    exit()

MAXA = 10**6
B = [0] * (MAXA+1)
for a in A:
    if a==1: continue
    if B[a]:
        print('setwise coprime')
        exit()
    B[a] = 1

for n in range(2,MAXA+1):
    c = 0
    for m in range(n,MAXA+1,n):
        c += B[m]
        if c > 1:
            print('setwise coprime')
            exit()

print('pairwise coprime')

Measured memory_bytes: 188940
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int V, E; //グラフ読み込み
    cin >> V >> E; //num of 
    vector<int> dist(V + 1, -1); //最短経路距離、＆未訪問か堂か判定。
    vector<int> ans(V + 1, -1);
    queue<int> q;  //候補たち 
    vector<vector<int>> graph(V + 1);
    for(int i = 0; i < E; i++){
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    q.push(1);
    dist[1] = 0;
    while(!q.empty()){
        int look = q.front();  //最初から一つだけ取り出す。
        q.pop();
        for(auto next: graph[look]){
            if(dist[next] != -1) continue;
            q.push(next);
            dist[next] = dist[look] + 1;
            ans[next] = look;
        }
    }
    // for(int i = 1; i < V + 1; i++){
    //     cout << i<< ": " << dist[i] << endl;
    // }
    cout << "Yes" << endl;
    for(int i = 2; i < V + 1; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 10728
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string s;
	cin >> s;
	int l = 0, r = s.length() - 1;
	while (s[l] != 'A') ++l;
	while (s[r] != 'Z') --r;
	cout << (r - l + 1) << endl;
	return 0;
}


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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

template<class T, class F>
struct SegmentTree {
    F f;
    T ti;
    vector<T> dat;
    int sz;

    SegmentTree(const F &f, const T &ti) : f(f), ti(ti) {}

    void build(const vector<T> &v) {
        assert(v.size());
        sz = 1;
        while (sz < v.size())sz <<= 1;
        dat.resize(sz << 1, ti);
        for (int i = 0; i < v.size(); i++)dat[sz - 1 + i] = v[i];
        for (int i = sz - 2; i >= 0; i--)dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
    }

    inline void update(int k, T x) {
        k += sz - 1;
        dat[k] = x;
        while (k) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    inline void add(int k, int x) {
        k += sz - 1;
        dat[k] = f(dat[k], x);
        while (k) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    inline T query(int a, int b) {
        return query(a, b, 0, 0, sz);
    }

    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)return ti;
        if (a <= l && r <= b)return dat[k];
        return f(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
    }
};

ll min_r(vector<ll> &slimes, int i, int k, int n, SegmentTree<ll, function<ll(ll, ll)>> &segmentTree) {
    int r = i + n;
    int l = i - k + n;
    return segmentTree.query(l, r + 1);
}

ll check(int k, int n, vector<ll> &slimes, SegmentTree<ll, function<ll(ll, ll)>> &segmentTree) {
    ll ans = 0;
    rep(i, n) {
        ll mi = min_r(slimes, i, k, n, segmentTree);
        ans += mi;
    }
    return ans;
}

int main() {
    int n;
    ll x;
    cin >> n >> x;

    vector<ll> slimes(n);
    rep(i, n) cin >> slimes[i];


    function<ll(ll, ll)> f = [](ll i, ll j) { return min(i, j); };
    SegmentTree<ll, decltype(f)> segmentTree(f, INF);
    vector<ll> slimes2;
    for (ll l : slimes)slimes2.push_back(l);
    for (ll l : slimes)slimes2.push_back(l);

    segmentTree.build(slimes2);


    ll ans = INF;
    rep(k, n) {
        ll now = check(k, n, slimes, segmentTree);
        cmin(ans, now + (x * k));
    }
    cout << ans << endl;

}

Measured memory_bytes: 384
#include <iostream>

# define REP(i,n) for(int i=0; i<n;i++)

using namespace std;

int main(){
	int n;
	cin >> n;
	int ans=0;
	REP(i,n){
		int l,r;
		cin >> l >> r;
		ans += r-l+1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import collections 

def is_loop(int_list):
    counter = collections.Counter(input_list)

    unique_list = list(counter.keys())
    counts = list(counter.values())

    if (all(num == 0 for num in unique_list)):
        return True
    else:
        if n % 3 == 0:
            zero_count = counter[0] 
            if zero_count == n / 3 and len(unique_list) == 2:
                return True
            else: 
                if len(unique_list) != 3:
                    return False
                if (unique_list[0] ^ unique_list[1] == unique_list[2]):
                    if (all(counts[0] == num for num in counts)):
                        return True
    return False

n = int(input())
input_list = [int(i) for i in input().split(' ')]
if is_loop(input_list):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14468
import bisect
N = int(input())
A = sorted([int(_) for _ in input().split()])
B = [int(_) for _ in input().split()]
C = sorted([int(_) for _ in input().split()])

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
print(ans)


Measured memory_bytes: 23616
#include <stdio.h>

int main(){

	int a=0, b=0;
	int A[1000] = {};
	int vote[1000] = {};
	int z=0;
	int i=0,k=0;
	int j = 0, ans = 0;

	scanf("%d%d", &a, &b);

	for (i = 0; i < a; i++){
		scanf("%d",&A[i]);
	}

	for (i = 0; i < b; i++){

		scanf("%d",&z);

		for (k = 0; k<b;k++){
			if (z >= A[k]){
				vote[k]++;

				if (j < vote[k])
				{
					ans=k;
					j = vote[k];
				}
				break;
			}
		}
	}

	printf("%d\n", ans + 1);
	return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    ll ans = 0, sum = 0;
    vc<ll> cand;
    repe(i,1,N+1){
        sum += i;
        cand.eb(i);
        if(sum>=N){
            if (sum - N > 0) cand.erase(lower_bound(all(cand), sum - N));
            break;
        }
    }
    repa(x, cand) cout << x << '\n';
}

Measured memory_bytes: 384
from collections import deque
import sys
input = sys.stdin.readline


def main():
    H, W, K = map(int, input().split())
    sx, sy, gx, gy = map(int, input().split())
    S = [[False]*W for _ in range(H)]
    for i in range(H):
        s = input()
        for j in range(W):
            if s[j] == ".":
                S[i][j] = True

    cost = [[-1]*W for _ in range(H)]

    # 深さ優先探索
    def bfs(x, y, gx, gy):
        stack = deque([[x, y]])
        cost[x][y] = 0
        while stack:
            x, y = stack[0]
            if x == gx and y == gy:
                return
            point = cost[x][y] + 1
            # up
            for i in range(1, K+1):
                if x-i >= 0:
                    if not S[x-i][y]:
                        break
                    elif cost[x-i][y] == -1:
                        cost[x-i][y] = point
                        stack.append([x-i, y])
                    elif cost[x-i][y] < point:
                        break
                else:
                    break
            # down
            for i in range(1, K+1):
                if x+i < H:
                    if not S[x+i][y]:
                        break
                    elif cost[x+i][y] == -1:
                        cost[x+i][y] = point
                        stack.append([x+i, y])
                    elif cost[x+i][y] < point:
                        break
                else:
                    break
            # left
            for i in range(1, K+1):
                if y-i >= 0:
                    if not S[x][y-i]:
                        break
                    elif cost[x][y-i] == -1:
                        cost[x][y-i] = point
                        stack.append([x, y-i])
                    elif cost[x][y-i] < point:
                        break
                else:
                    break
            # right
            for i in range(1, K+1):
                if y+i < W:
                    if not S[x][y+i]:
                        break
                    elif cost[x][y+i] == -1:
                        cost[x][y+i] = point
                        stack.append([x, y+i])
                    elif cost[x][y+i] < point:
                        break
                else:
                    break

            stack.popleft()        

    bfs(sx-1, sy-1, gx-1, gy-1)
    print(cost[gx-1][gy-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 125312
package main

import (
	"fmt"
)

func main() {
	var s string
	var q int
	fmt.Scanf("%s", &s)
	fmt.Scanf("%d", &q)

	prefix := []string{}
	postfix := []string{}
	rev := false
	for i := 0; i < q; i++ {
		var t, f, c string
		fmt.Scanf("%s", &t)
		if t == "1" {
			rev = !rev
		} else {
			fmt.Scanf("%s %s", &f, &c)
			if f == "1" == !rev {
				prefix = append(prefix, c)
			} else {
				postfix = append(postfix, c)
			}
		}
	}

	if !rev {
		for i, _ := range prefix {
			fmt.Print(prefix[len(prefix)-i-1])
		}
		fmt.Print(s)
		for _, c := range postfix {
			fmt.Print(c)
		}
	} else {
		for i, _ := range postfix {
			fmt.Print(postfix[len(postfix)-i-1])
		}
		r := []rune(s)
		for i, _ := range r {
			fmt.Print(string(r[len(r)-i-1]))
		}
		for _, c := range prefix {
			fmt.Print(c)
		}

	}
	fmt.Print("\n")
}


Measured memory_bytes: 13952
# ABC093B
a,b,k = map(int,input().split())
xx =[]
for x in range(a,a+k):
    if x>b:
        break
    xx.append(x)
for x in range(b+1-k,b+1):
    if x<a:
        break
    xx.append(x)
for x in sorted(list(set(xx))):
    print(x)

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static final int INF = Integer.MAX_VALUE / 2 - 1;
	public static final int MAX = 1001; 
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[][] monstars_x = new int[5][MAX];
		int[][] monstars_y = new int[5][MAX];
		int[] monstars_count = new int[5];
		int[][] monstars_dp = new int[4][MAX];
		
		while(true){
			final int w = sc.nextInt();
			final int h = sc.nextInt();
			
			if(w == 0 && h == 0){
				break;
			}
			
			int s_x = -1, s_y = -1, g_x = -1, g_y = -1;
			
			Arrays.fill(monstars_count, 0);
			for(int i = 0; i < h; i++){
				char[] input = sc.next().toCharArray();
				
				for(int j = 0; j < w; j++){
					if('0' <= input[j] && input[j] <= '9'){
						final int type = (int)(input[j] - '0') - 1;
						monstars_x[type][monstars_count[type]] = j;
						monstars_y[type][monstars_count[type]] = i;
						monstars_count[type]++;
					}else if('S' == input[j]){
						s_x = j;
						s_y = i;
					}else if('G' == input[j]){
						g_x = j;
						g_y = i;
					}
				}
			}
			
			int min_count = INF;
			int min_hand = INF;
			
			for(int start = 0; start < 5; start++){
				for(int count = 0; count < 4; count++){
					Arrays.fill(monstars_dp[count], INF);
				}
				
				for(int dp = 0; dp < 4; dp++){
					final int cur_type = (start + dp + 1) % 5;
					final int prev_type = (start + dp) % 5;
					
					//System.out.println(cur_type);
					
					for(int cur = 0; cur < monstars_count[cur_type]; cur++){
						if(dp == 0){
							monstars_dp[dp][cur] = Math.abs(s_x - monstars_x[cur_type][cur]) + Math.abs(s_y - monstars_y[cur_type][cur]);
						}else{
							for(int prev = 0; prev < monstars_count[prev_type]; prev++){
								monstars_dp[dp][cur] = Math.min(
										monstars_dp[dp][cur],
										monstars_dp[dp-1][prev] + 
										Math.abs(monstars_x[cur_type][cur] - monstars_x[prev_type][prev]) +
										Math.abs(monstars_y[cur_type][cur] - monstars_y[prev_type][prev])); 
										
							}
						}
					}
				}
				/*
				for(int i = 0; i < 4; i++){
					System.out.println(Arrays.toString(monstars_dp[i]));
				}
				*/
				final int last = (start + 4) % 5;
				for(int result = 0; result < monstars_count[last]; result++){
					final int cost = monstars_dp[3][result] + Math.abs(g_x - monstars_x[last][result]) + Math.abs(g_y - monstars_y[last][result]);
					
					//System.out.print(cost + ", ");
					
					if(cost < min_count){
						min_count = cost;
						min_hand = start + 1;
					}
				}
				
				//System.out.println();
				//System.out.println("----------------------------------------------------");
			}
			
			if(min_count >= INF){
				System.out.println("NA");
			}else{
				System.out.println(min_hand + " " + min_count);
			}
		}
	}
}

Measured memory_bytes: 72128
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	int a = 0;//分子の数値
	if (n % 2 == 1)a = n / 2 + 1;
	else a = n / 2;
	cout << (double)a / n << endl;
	return 0;
}

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

int main () {
  int n = in();

  function<int(int)> s = [&] (int x) {
    if (x < 10) return x;
    return x%10 + s(x/10);
  };

  if (n%s(n) == 0) yn;
  return 0;
}

Measured memory_bytes: 256
def LI():return map(int,input().split())
def I(): return input().split()

while(True):
    a,b=LI()
    if a==b==0:
        break
    else:
        lst = []
        for i in range(a):
            lst_a=[]
            if i==0 or i==a-1:
                for j in range(b):
                    lst_a.append("#")
                lst.append(lst_a)
            else:
                for j in range(b):
                    if j==0 or j==b-1:
                        lst_a.append("#")
                    else:
                        lst_a.append ( "." )
                lst.append(lst_a)

    for i in range(a):
        for j in range(b):
            print(lst[i][j],end="")
        print()
    print()



Measured memory_bytes: 7180
import collections
import numpy as np
import sys
import copy

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
    A[i]-=1
B=[0]
visited=[0]*N
visited[0]=1
Flag=True
for i in range(0,N*2):
    next=A[B[i]]
    if visited[next]==0:
        B.append(next)
        visited[next]=1
    else:
        C=B[B.index(next):]
        num=B.index(next)
        break
#print(C)
if K>num:
    Ans=(K-num)%len(C)
    print(C[Ans]+1)
else:
    print(B[K]+1)

Measured memory_bytes: 50788
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include <bits/stdc++.h>

#define MOD 1000000007
#define MAX 10e5
#define fs first
#define sc second
#define pb push_back
#define ll long long
using namespace std;
/////////////////////
int a[3][100009],n;
int dp[3][100009];
int dp2[3][100009];
 int sol(int n){
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            dp[j][i]=max(dp[(j+1)%3][i-1],dp[(j+2)%3][i-1])+a[j][i];

        }
    }
    return max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
 }
int sol2(int i,int j){
    if(i==0)return a[j][0];
    if(dp2[j][i]!=-1)return dp2[j][i];
    return dp2[j][i]=max(sol2(i-1,(j+1)%3),sol2(i-1,(j+2)%3))+a[j][i];
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(false);
    cout.tie(false);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[0][i]>>a[1][i]>>a[2][i];
            };
            memset(dp2,-1,sizeof dp2);
            dp[0][0]=a[0][0];
            dp[1][0]=a[1][0];
            dp[2][0]=a[2][0];
                cout<<sol(n);
                //cout<<max(sol2(n-1,0),max(sol2(n-1,1),sol2(n-1,2)));

    return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

ll dp[100010][2];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    sort(ALL(a));
    FOR(i, 1, n) a[i] += a[i-1];
    ll ret = a[n-1];
    for(ll i=1; i<n; i+=2) chmax(ret, a[n-1]-a[i]*2);
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>


using namespace std;
using ll = long long;
const ll INF = 1e18;

int main() {
    string s;
    cin >> s;

    cout << (s[0] == '9' || s[1] == '9' ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define min(a,b) a<b ? a:b
// #define max(a, b) a < b ? b : a
#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)

#define pb push_back
#define pi 3.14159265358979323846

// int explore(vector<vector<int>> &adj,int x,int y,vector<int> &visited)
// {
//     if(x==y)
//     return 1;
//     visited[x]=1;
//     for(int i=0;i<adj[x].size();i++)
//     {
//         if(!visited[adj[x][i]])
//         {
//             if(explore(adj,adj[x][i],y,visited))
//             return 1;
//         }
//     }
//     return 0;
// }
bool valley(int p[], int k)
{
    if (p[k] < p[k - 1] && p[k] < p[k + 1])
        return true;
    return false;
}
bool peak(int p[], int k)
{
    if (p[k] > p[k - 1] && p[k] > p[k + 1])
        return true;
    return false;
}

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

int32_t main()
{
    IOS;
    // int t;
    // cin>>t;
    // while(t--)
    // {
        int n;
        int x=1000000007;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        cin>>a[i];
        vector<int> v;
        int sum=0,z=0;
        int ctr=0;
        for(int i=1;i<n;i++)
        {
            sum+=a[i-1];
            ctr+=(sum%x*a[i]%x)%x;
        }
        cout<<ctr%x;
        
    // }
    

}


Measured memory_bytes: 5220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};

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

    int n, m;
    cin >> n >> m;

    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        uf.unite(a, b);
    }

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        b[uf.root(i)] = 1;
    }

    int r = 0;
    for (int i = 0; i < n; i++) {
        r += b[i];
    }

    cout << r - 1 << endl;

    return 0;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T> T count_bit(T p){
  if(typeid(p)==typeid(int))return __builtin_popcount(p);
  else if(typeid(p)==typeid(long))return __builtin_popcountl(p);
  else return __builtin_popcountll(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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  int A,B;
  in(A,B);
  out((int)ceil((double)(B-1)/(A-1)));
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
int findRank(string str) 
{ 
    // store original string 
    string orgStr = str; 
  
    // Sort the string in lexicographically 
    // ascending order 
    sort(str.begin(), str.end()); 
   
    // Keep iterating until 
    // we reach equality condition 
    long int i = 1; 
    do { 
        // check for nth iteration 
        if (str == orgStr) 
            break; 
   
        i++; 
    } while (next_permutation(str.begin(), str.end())); 
   
    // return iterator value 
    return i; 
} 

int main()
{
 
        FastIO
        ll n,i,j,suma=1,sumb=1,c=0;
        cin>>n;
       
       vi p(n),q(n);
       string str1="",str2="";
       for(i=0;i<n;i++)
       {
       	cin>>p[i];
       	

       	str1+=char('0'+(p[i]));
       	
       }
       for(i=0;i<n;i++)
       {
       	cin>>q[i];
       	

       	str2+=char('0'+q[i]);
       	
       }


       cout<<abs(findRank(str1)-findRank(str2));
       return 0;
   }







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  double a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << fixed << setprecision(8) << sqrt(pow(a - c, 2) + pow(b - d, 2)) << endl;

  return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  ll X;
  cin >> X;
  int year = 0;
  ll val = 100;
  while (val < X) {
    val = ll(floor(1.01 * val));
    ++year;
  }
  cout << year << endl;
  return 0;
}


Measured memory_bytes: 3256
#!usr/bin/env python3
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
mod = 1000000007

#A
"""
a,b,c = LI()
s = a+b+c
s /= 2
ans = (s*(s-a)*(s-b)*(s-c))**(1/2)
print(int(ans))
"""

#B
"""
s = int(input())
m = 1
lis = [True for i in range(1000001)]

while lis[s]:
    lis[s] = False
    if s % 2 == 1:
        s = 3*s+1
    else:
        s //= 2
    m += 1
print(m)
"""

#C
n = II()
h = LI()
ans = 0
while sum(h) != 0:
    l = 0
    while h[l] == 0: l += 1
    r = l
    while r < n:
        if h[r] == 0: break
        h[r] -= 1
        r += 1
    ans += 1
print(ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 40816
#include<iostream>
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll packet_size, min_size = INF, min_pos = -1;
    for (int i = 0; i < 5; i++) {
        cin >> packet_size;
        if (packet_size < min_size) {
            min_size = packet_size;
            min_pos = i;
        }
    }
    cout << min_pos + (N + min_size - 1) / min_size + 5 - min_pos - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<vector<Int>> a(N, vector<Int>(N));
	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < N; j++) {
			cin >> a[i][j];
		}
	}

	vector<vector<mint>> dp(N+1, vector<mint>(1LL<<(N)));//dp[i+1][bit]: i番目までの男でbitが立っている女とマッチが整理している通り数
	dp[0][0] = 1;

	//配るDP
	for (Int i = 0; i < N; i++) {
		for (Int bit = 0; bit < (1LL<<(N)); bit++) {
			if (dp[i][bit]==0) {
				continue;
			}

			//各女性を見る
			for (Int k = 0; k < N; k++) {
				if (!(bit & (1LL <<k)) ) {//k番の女性にbitが立っていない場合
					if (a[i][k]) {//iの男とkの女の相性がいい場合
						dp[i + 1][bit + (1LL << k)] += dp[i][bit];
					}
				}
			}
		}
	}

	cout << dp[N][(1LL<<(N))-1] << "\n";

}


Measured memory_bytes: 377216
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    string S;

    void input() {
        cin >> N >> S;
    }

    void solve() {
        input();
        vector<int> ruiW(N), ruiE(N);
        for (int i = 0; i < N; ++i) {
            if (S[i] == 'E') ruiE[i] = 1;
            else ruiW[i] = 1;
        }
        for (int i = 1; i < N; ++i) {
            ruiW[i] += ruiW[i - 1];
        }
        for (int i = N - 2; i >= 0; --i) {
            ruiE[i] += ruiE[i + 1];
        }

        int ans = min(ruiE[1], ruiW[N - 2]);
        for (int i = 1; i < N - 1; ++i) {
            int tmp = ruiE[i + 1] + ruiW[i - 1];
            chmin(ans, tmp);
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 2964
#include<stdio.h>
#include<string.h>

#define MAX 100000

int char_swich_search(char *a, int len,int index);
// array and length, current_index. output is swiching index.


int main()
{
  int N,K;
  char S[MAX+1];


  scanf("%d %d", &N,&K);
  scanf("%s",S);
  
  int len=strlen(S), flag=S[0]-'0',
    index_array[MAX+1], i=0, r;
  
  index_array[0]=0;
  for(r=1; ;r++)
    {
      i=char_swich_search(S,len,i);
      index_array[r]=i;
      if(i==len)break;
    }
  
  int index_len=r,ini,last,temp,max;
  
  
  if(flag)
    {
      if(index_len/2<=K)
	{
	  printf("%d\n",len);
	  return 0;
	}
      last=2*K+1; ini=0; max=0;
      while(last<=index_len)
	{
	  temp=index_array[last]-index_array[ini];
	  if(max<temp) max=temp;
	  ini+=2; last+=2;
	}
    }
  else
    {
      if((index_len+1)/2<=K)
	{
	  printf("%d\n",len);
	  return 0;
	}
      last=2*K; max=index_array[last];
      ini=1; last+=2;
      while(last<=index_len)
	{
	  temp=index_array[last]-index_array[ini];
	  if(max<temp) max=temp;
	  ini+=2; last+=2;
	}
      
    }
      
  last--;
  temp=index_array[last]-index_array[ini];
  if(max<temp) max=temp;
  
  //  for(i=0;i<=index_len;i++)
  //    printf("i_%d=%d ",i,index_array[i]);
  printf("%d\n",max);
  
  return 0;
}

int char_swich_search(char *a, int len,int index)
{
  int i;
  for(i=index;i<=len;i++)
    {
      if(a[i]!=a[index])break;
    }
  return i;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<int> l(N), r(N);
    rep(i, N) cin >> l[i] >> r[i];
    sort(all(l)), sort(all(r));

    int R, L;
    if (N % 2 == 1) {
        R = r[N / 2];
        L = l[N / 2];
    } else {
        R = r[(N - 1) / 2] + r[N / 2];
        L = l[(N - 1) / 2] + l[N / 2];
    }
    cout << R - L + 1 << endl;
}


Measured memory_bytes: 4824
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>


using namespace std;


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define rep(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)

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

int main() {

	int N, x; cin >> N >> x;

	if (x == 1 || x == (2 * N - 1)) {
		cout << "No" << endl;
		return 0;
	}
	else if (N == 2) {
		cout << "Yes" << endl;
		cout << 1 << endl;
		cout << 2 << endl;
		cout << 3 << endl;
		return 0;
	}

	
	cout << "Yes" << endl;

	vector<bool> used(2 * N - 1,false);

	used[x - 1] = true;
	used[x] = true;
	used[x - 2] = true;

	int i = 0;
	int ex = 0;
	while (i < 2*N - 1) {
		
		
		if (i == N - 2) {
			cout << x - 1 << endl;
		}
		else if (i == N - 1) {
			cout << x << endl;
		}
		else if (i == N) {
			cout << x + 1 << endl;
		}else {

			while (used[ex] == true) {
				ex++;
			}

			cout << ex++ + 1 << endl;
		}

		i++;
	}
	
	return 0;
}

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

struct Point {
    int x, y;

    Point() = default;
    Point(int x, int y) : x(x), y(y) {}

    Point operator+(const Point &rhs) const {
        return Point(x + rhs.x, y + rhs.y);
    }
    Point operator-(const Point &rhs) const {
        return Point(x - rhs.x, y - rhs.y);
    }
    long long operator*(const Point &rhs) const {
        return 1ll * x * rhs.x + 1ll * y * rhs.y;
    }
    long long operator%(const Point &rhs) const {
        return x * rhs.y - y * rhs.x;
    }
};

int main() {
    Point p1, p2;
    cin >> p1.x >> p1.y;
    cin >> p2.x >> p2.y;
    int q; cin >> q;

    Point d = p2 - p1;
    double l = sqrt(d * d);
    double dx = d.x / l;
    double dy = d.y / l;

    while (q--) {
        Point p; cin >> p.x >> p.y;
        long long dot = (p - p1) * (p2 - p1);
        double dist = dot / l;
        double fx = p1.x + dx * dist;
        double fy = p1.y + dy * dist;
        cout << fixed << setprecision(20) << fx << ' ' << fy << endl;
    }
}



Measured memory_bytes: 3276
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import sys
inf = 10**9+7
mod = 10**9+7
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b.sort()
c.sort()
b_len = len(b)
c_len = len(c)
count = 0
b_list = [0 for i in range(b_len)]

for i,num in enumerate(b):
    ind_c = bisect.bisect_left(c, num)
    if c_len == ind_c:
        continue
    else:
        if c[ind_c] == num:
            ind_c = bisect.bisect_left(c, num+1)
            if c_len == ind_c:
                continue
            else:
                b_list[i] = c_len - ind_c
        else:
            b_list[i] = c_len-ind_c

# 累積和
a2 = [0]
for i in b_list:a2.append(a2[-1]+i)
def SumArea(l, r):
    return a2[r]-a2[l]


for num in a:
    ind_b = bisect.bisect_left(b, num)
    if b_len == ind_b:
        continue
    else:
        if b[ind_b] == num:
            ind_b = bisect.bisect_left(b, num+1)
            if b_len == ind_b:
                continue
            else:
                count += SumArea(ind_b, b_len)
        else:
            count += SumArea(ind_b, b_len)
print(count)


Measured memory_bytes: 111588
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next();
        String b = in.next();
        for (int i = 0; i < a.length(); i++) {
            if(a.charAt(i)!=b.charAt(i)){
                System.out.println("No");return;
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 26964