akhauriyash/Code-Regression huggingface dataset:
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
static int n, a, b, c, i, l[10],use[10],answer=2100000000;
vector<int> ua, ub, uc;
int intabs(int a) { return a > 0 ? a : -a; }
int calc(int now, int s)
{
	switch (s)
	{
	case 1:
	{
		//ua.push_back(l[now]);
		use[now] = 1;
		break;
	}
	case 2:
	{
		//ub.push_back(l[now]);
		use[now] = 2;
		break;
	}
	case 3:
	{
		//uc.push_back(l[now]);
		use[now] = 3;
		break;
	}
	default:use[now] = 0;
	}
	now++;
	if (now == n+1)
	{

		int ans = 0;
		int na = 0, nb = 0, nc = 0, ca = 0,cb=0,cc=0;
		//kakunin
		//for (i = 1; i <= n; i++) printf(",%d", use[i]);
		for (i = 1; i <= n; i++)
		{
			if (use[i] == 1) na += l[i],ca++,ans+=10;
			if (use[i] == 2) nb += l[i],cb++, ans += 10;
			if (use[i] == 3) nc += l[i],cc++, ans += 10;
		}
		/*
		for (i = 0; i < ua.size(); i++) { printf("a%d", ua[i]); }
		for (i = 0; i < ub.size(); i++) { printf("b%d", ub[i]); }
		for (i = 0; i < uc.size(); i++) { printf("c%d", uc[i]); }
		*/
		ans = ans + intabs(a - na) + intabs(b - nb) + intabs(c - nc);
		if (ca&&cb&&cc) ans -= 30;
		else return 0;
		ua.clear();
		ub.clear();
		uc.clear();
		//printf(":%d,na%dnb%dnc%d\n",ans,na,nb,nc);
		answer = min(answer, ans);
		/*
		if (ans == 120)
		{
			int ans = 0;
			int na = 0, nb = 0, nc = 0;
			//kakunin
			for (i = 1; i <= n; i++) printf(",%d", use[i]);
			for (i = 1; i <= n; i++)
			{
				if (use[i] == 1) na += l[i], ans += 10;
				if (use[i] == 2) nb += l[i], ans += 10;
				if (use[i] == 3) nc += l[i], ans += 10;
			}
			ans = ans - 30 + intabs(a - na) + intabs(b - nb) + intabs(c - nc);
			ua.clear();
			ub.clear();
			uc.clear();
			printf(":%d,na%dnb%dnc%d\n",ans,na,nb,nc);
		}
		*/
		return ans;
	}
	calc(now, 1);
	calc(now, 2);
	calc(now, 3);
	calc(now, 0);
}
int main()
{
	cin >> n >> a >> b >> c;
	for (i = 1; i <= n; i++)
	{
		cin >> l[i];
	}
	calc(1, 1);
	calc(1, 2);
	calc(1, 3);
	calc(1, 0);
	cout << answer << endl;
}


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 = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    string s;
    cin >> s;
    if ((s[0]==s[1]&&s[1]==s[2]) || (s[1]==s[2]&&s[2]==s[3])) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
int main() {
	int i, j, n;
	int pn[1000000];
	for (i = 0; i < 1000000; i++) {
		pn[i] = 1;
	}
	pn[0] = 0;
	pn[1] = 0;
	for (i = 2; i*i < 1000000; i++) {
		if (pn[i] == 1) {
			for (j = i*i; j < 1000000; j += i) {
				pn[j] = 0;
			}
		}
	}
	for (i = 1; i < 1000000-1; i++) {
		pn[i+1] += pn[i];
	}
	while (scanf("%d", &n) != EOF) {
		printf("%d\n", pn[n]);
	}
	return 0;
}

Measured memory_bytes: 4500
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	l := intScanner() + intScanner()
	r := intScanner() + intScanner()
	if l < r {
		fmt.Println("Right")
	} else if l == r {
		fmt.Println("Balanced")
	} else {
		fmt.Println("Left")
	}
}


Measured memory_bytes: 1772
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    bool flag = true;
    int cnt=0;
    while(flag == true){
        for (int i = 0; i < N; i++)
        {
            if(A[i]/2 == 0 || A[i]%2 != 0) flag = false;
        }
        if(flag == true){
            for (int i = 0; i < N; i++)
            {
                A[i] = A[i] / 2;
//                cout << A[i] << endl;
            }
            cnt++;
        }
    }

    cout << cnt << endl;
    
}

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

#define mod 1'000'000'007
typedef long long ll;

template<typename T>
void deb(initializer_list<T> l)
{
	for (auto &e : l)
		cout << e << ' ';
	cout << endl;
}

int n, m, k;

vector<pair<int, int>> dir{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool ok(int i, int j)
{
	return i >= 0 && j >= 0 && i < n && j < m;
}

void solve()
{
	cin >> n >> m >> k;
	k = min(k, max(n - 1, m - 1));
	vector<vector<bool>> a(n, vector<bool>(m));
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	--x1;
	--y1;
	--x2;
	--y2;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			char c;
			cin >> c;
			a[i][j] = c == '.';
		}
	}

	vector<vector<int>> dist(n, vector<int>(m, -1));
	vector<vector<bool>> vis(n, vector<bool>(m, false));
	vis[x1][y1] = true;
	dist[x1][y1] = 0;
	queue<pair<int, int>> q;
	q.push({x1, y1});

	while (!q.empty())
	{
		auto [i, j] = q.front();
		q.pop();
		// deb({i, j, dist[i][j]});

		for (auto& [di, dj] : dir)
		{
			int x = i;
			int y = j;
			for (int o = 1; o <= k; ++o)
			{
				x += di;
				y += dj;
				if (!ok(x, y))
					break;
				if (!a[x][y])
					break;
				if (vis[x][y] && dist[x][y] <= dist[i][j])
					break;
				if (vis[x][y])
					continue;

				vis[x][y] = true;
				dist[x][y] = dist[i][j] + 1;
				q.push({x, y});
			}
		}
	}

	// vector<pair<int, int>> x{{2, 1}, {2, 0}, {1, }}
	cout << dist[x2][y2] << '\n';
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;



int main() {
    int n; cin >> n;
    ll ans = 1;
    for(int i = 1;i <= n;i++){
        ans = ans * i % MOD;
    }
    cout << ans;
}




Measured memory_bytes: 3604
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
s = Counter(s)
s = s.most_common()

# ansの初期化
ans = []
ans.append(s[0][0])
cnt = s[0][1]

if (len(s) != 1):
  for i in range(1, n):
    if (s[i][1] < cnt):
      break
    else:
      ans.append(s[i][0])

for s in sorted(ans):
  print(s)

Measured memory_bytes: 119956
#include<stdio.h>

int main(void)
{
   int a,n[20],m,i,j;

   scanf("%d",&a);

   for(i=0;i<a;i++){
      scanf("%d",&n[i]);
   }
   m=1;
   for(i=1;i<a;i++){
      if(n[i-1]<=n[i])
      m=m+1;
      else if(n[i-1]>n[i])
      n[i]=n[i-1];
   }

   printf("%d\n",m);

   return 0;
}

Measured memory_bytes: 128
h,w = map(int, input().split())
n = int(input())
a = [int(i) for i in input().split()]
con = 1
d = []

for i in a:
    for j in range(i):
        d.append(con)
    con += 1

whi = 0
for i in range(h):
    if whi == 0:
        a = d[i*w:w+w*i]
        L=[str(j) for j in a]
        L=' '.join(L)
        print(L)
        whi = 1
    else:
        a = d[i*w:w+w*i]
        a.reverse()
        L=[str(j) for j in a]
        L=' '.join(L)
        print(L)
        whi = 0

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int a[30];
bool rec(int d,int t){
  if(t==0) return true;
  if(d==n||t<0) return false;
  return rec(d+1,t)||rec(d+1,t-a[d]);
}
signed main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  int q;
  cin>>q;
  int m[q];
  for(int i=0;i<q;i++) cin>>m[i];
  for(int i=0;i<q;i++) cout<<(rec(0,m[i])?"yes":"no")<<endl;
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  cout << (n == m ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
//Longest Common Prefix(s,s.substr(i)) O(|s|)
#include<vector>
#include<string>
vector<int>Zalgo(const string&s)
{
	vector<int>ret(s.size());
	if(s.empty())return ret;
	ret[0]=s.size();
	int i=1,j=0;
	while(i<s.size())
	{
		while(i+j<s.size()&&s[j]==s[i+j])j++;
		ret[i]=j;
		if(j==0)
		{
			i++;
			continue;
		}
		int k=1;
		while(i+k<s.size()&&k+ret[k]<j)ret[i+k]=ret[k],k++;
		i+=k;j-=k;
	}
	return ret;
}
string s,t;
main()
{
	cin>>s>>t;
	vector<int>l=Zalgo(t+s);
	vector<int>L(l.begin()+t.size(),l.end());
	reverse(s.begin(),s.end());
	reverse(t.begin(),t.end());
	vector<int>r=Zalgo(t+s);
	vector<int>R(r.begin()+t.size(),r.end());
	reverse(R.begin(),R.end());
	int cnt=0;
	for(int i=0;i+t.size()<=s.size();i++)
	{
		if(L[i]+R[i+t.size()-1]==t.size()-1)cnt++;
	}
	cout<<cnt<<endl;
}



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

int main(){
    int N,U, count1, count2,count3,count4, ans, a,b,c,d;
    map<int,int> p,q,r,s;
    cin >> N;
    U = N / 2;
    vector<int> u1(U);
    vector<int> u2(U);
    count1 = 0;
    count2 = 0;
    count3 = 0;
    count4 = 0;
    a = 0;
    b = 0;
    c = 0;
    d = 0;
    for(int i = 0; i < U; i++){
        cin >> u1.at(i);
        cin >> u2.at(i);
    }
    for(int x : u1){
        if(p.count(x)){
            p.at(x)++;
        }else{
            p[x] = 1;
        }
    }
    for(int x : u1){
        if(p.at(x) > count1){
            count1 = p.at(x);
            a = x;
        }
    }
    
    for(int x : u1){
        
        if(q.count(x)){
            q.at(x)++;
        }else{
            if(a != x){
                q[x] = 1;
            }
        }
    }
    for(int x : u1){
        if(a == x){
            continue;
        }
        if(q.at(x) > count2){
            count2 = q.at(x);
            b = x;
        }
    }
    
    for(int x : u2){
        if(r.count(x)){
            r.at(x)++;
        }else{
            r[x] = 1;
        }
    }
    for(int x : u2){
        if(r.at(x) > count3){
            count3 = r.at(x);
            c = x;
        }
    }
    
    for(int x : u2){
        
        if(s.count(x)){
            s.at(x)++;
        }else{
            if(a != x){
                s[x] = 1;
            }
        }
    }
    for(int x : u2){
        if(a == x){
            continue;
        }
        if(s.at(x) > count4){
            count4 = s.at(x);
            d = x;
        }
    }
    
    if(a != c){
        ans = (u1.size() - count1) + (u2.size() - count3);
    }else{
        if((u1.size() - count1) + (u2.size() - count4)
           <= (u1.size() - count2) + (u2.size() - count3)){
               ans = (u1.size() - count1) + (u2.size() - count4);
           }else{
               ans = (u1.size() - count2) + (u2.size() - count3);
           }
    }
    cout << ans << endl;
}

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

using namespace std;

const int max_n = 100111, inf = 1000111222;

int n, m, k, a[max_n], b[max_n];
int ans = inf;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d", &b[i]);
    }
    ans = *min_element(a, a + n) + *min_element(b, b + m);
    while (k--) {
        int x, y, c;
        scanf("%d%d%d", &x, &y, &c);
        --x;
        --y;
        ans = min(ans, a[x] + b[y] - c);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int n,m;
int f[N],d[N];
int find(int x)
{
	if(x==f[x])return x;
	int nf=find(f[x]);
	d[x]+=d[f[x]];
	return f[x]=nf;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)f[i]=i;
	int t1,t2,t3;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&t1,&t2,&t3);
		int aa=find(t1),bb=find(t2);
		if(aa!=bb)
		{
			f[aa]=bb;
			d[aa]=d[t2]-d[t1]-t3;
		}
		else
		{
			if(d[t2]-d[t1]!=t3)return puts("No"),0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1024
//AtCoder ABC121 A - White Cells
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll H,W; cin>>H>>W;
    ll h,w; cin>>h>>w;
    ll ans=H*W - h*W - w*H +h*w;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,int> li;
const int N = 100005;
const ll INF = 1e18;
const int mod = 1e9+7;
ll cs[N],ct[N],ds[N],dt[N];
vector<ii> adjlist[N];
int n,m,s,t;
int main(){
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for (int i = 0; i < m; i++){
        int u,v,d;
        scanf("%d%d%d",&u,&v,&d);
        adjlist[u].push_back(ii(v,d));
        adjlist[v].push_back(ii(u,d));
    }
    priority_queue<li,vector<li> ,greater<li> > pq;
    fill (ds,ds+n+1,INF);
    pq.push(li(0,s));
    ds[s] = 0;
    cs[s] = 1;
    while (pq.size()){
        li cur = pq.top();pq.pop();
        ll d = cur.first;
        int u = cur.second;
        if (ds[u] < d) continue;
        for (auto v : adjlist[u]){
            if (ds[v.first] > ds[u] + v.second){
                ds[v.first] = ds[u] + v.second;
                cs[v.first] = cs[u];
                pq.push(li(ds[v.first],v.first));
            }
            else if (ds[v.first] == ds[u]+v.second){
                cs[v.first] += cs[u];
                cs[v.first] %= mod;
            }
        }
    }
    fill (dt,dt+n+1,INF);
    pq.push(li(0ll,t));
    dt[t] = 0;
    ct[t] = 1;
    while (pq.size()){
        li cur = pq.top(); pq.pop();
        ll d = cur.first;
        int u =cur.second;
        if (dt[u] < d) continue;
        for (auto v : adjlist[u]){
            if (dt[v.first] > dt[u] + v.second){
                dt[v.first] = dt[u] + v.second;
                ct[v.first] = ct[u];
                pq.push(li(dt[v.first],v.first));
            }
            else if (dt[v.first] == dt[u]+v.second){
                ct[v.first] += ct[u];
                ct[v.first] %= mod;
            }
        }
    }
    ll ans = (cs[t] * ct[s]) % mod;
    ll total = ds[t];
    //printf("total ways: %lld^2, total distance %lld",cs[t],ds[t]);
    for (int i = 1; i <= n; i++){
        //printf("Vertex %d %lld %lld\n",i,cs[i],ct[i]);
        if (2*ds[i] == total && 2*dt[i] == total){
            //printf("Vertex %d cannot: %lld\n",i,cs[i]);
            ll num = (cs[i]*ct[i])%mod;
            num *= num; num %= mod;
            ans += mod-num; ans %= mod;
        }
        if (2*ds[i] < total){
            for (auto v : adjlist[i]){
                if (2*dt[v.first] < total && dt[v.first]+ds[i]+v.second == ds[t]){
                    //printf("Edge %d %d cannot (%lld -> %lld): %lld %lld\n",i,v.first,ds[i],dt[v.first],cs[i],ct[v.first]);
                    ll num = (cs[i]*ct[v.first])%mod;
                    num *= num; num %= mod;
                    ans += mod-num; ans %= mod;
                }
            }
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 13168
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;

//queue push pair<int,int> practice
int main(){
    int h,w; cin >> h >> w;
    queue<P> q;
    int map[h][w];
    int cou[h][w];
    
    //pair in queue BFS
    int res = 0;
    rep(i,h){
        rep(j,w){
            cou[i][j]=0;
            char c; cin >> c;
            if(c=='#'){
                map[i][j]=1;
                q.push(P(i,j));
            }
            else map[i][j]=0;
        }
    }
    while(!q.empty()){
        P d = q.front();
        q.pop();
        int a = d.fi,b = d.se;
        if(a>0 && map[a-1][b]==0){
            cou[a-1][b]=max(cou[a-1][b],cou[a][b]+1);
            map[a-1][b]=1;
            q.push(P(a-1,b));
        }
        if(b>0 && map[a][b-1]==0){
            cou[a][b-1]=max(cou[a][b-1],cou[a][b]+1);
            map[a][b-1]=1;
            q.push(P(a,b-1));
        }
        if(a+1<h && map[a+1][b]==0){
            cou[a+1][b]=max(cou[a+1][b],cou[a][b]+1);
            map[a+1][b]=1;
            q.push(P(a+1,b));
        }
        if(b+1<w && map[a][b+1]==0){
            cou[a][b+1]=max(cou[a][b+1],cou[a][b]+1);
            map[a][b+1]=1;
            q.push(P(a,b+1));
        }
    }
    int ans = 0;
    rep(i,h){
        rep(j,w){
            ans = max(ans,cou[i][j]);
        }
    }
    cout << ans << endl;
        
}


Measured memory_bytes: 16272
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =100001;
ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    }
    return res;
}

int main()
{
  IOS
  ll n,m;
  cin>>n>>m;
  ll p[m+1],a[n+1]={0},b[n+1]={0};
  ll ans=0,ans1=0;
  string s[m+1];
  for(ll i=1;i<=m;i++)
  {
    cin>>p[i]>>s[i];
    if(s[i]=="AC")
    {
      if(a[p[i]]==0)
      {
        a[p[i]]=1;
        ans1++;
      }
    }
    else
    {
      if(a[p[i]]==0)
        b[p[i]]++;
    }
    
  }
  for(ll i=1;i<=n;i++){
    if(a[i])
      ans+=b[i];
  }
  cout<<ans1<<" "<<ans<<endl;
  
  
  
}

Measured memory_bytes: 8064
Public Class Compiler
    Shared Sub Main()
        Dim input As String() = Console.ReadLine().Split(" ")
        Dim n As Integer = Integer.Parse(input(0))
        Dim d As Integer = Integer.Parse(input(1))
        Dim xs(0 To n - 1)() As Integer
        For i As Integer = 0 To n - 1
            xs(i) = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
        Next
        Dim output As Integer = 0
        For i As Integer = 0 To n - 2
            For j As Integer = i + 1 To n - 1
                Dim yz As Integer = 0
                For k As Integer = 0 To d - 1
                    yz += Math.Pow(xs(i)(k) - xs(j)(k), 2)
                Next
                Dim sqyz As Double = Math.Sqrt(yz)
                If sqyz = CType(sqyz, Integer) Then output += 1
            Next
        Next
        Console.WriteLine(output)
    End Sub
End Class

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
typedef long long  ll;
//typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set
// this for long double
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<-1; return 0;}
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int N = 1010;
const int INF = 1e8;
const ll MOD1=1073741824;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
string bin_rep(int n)
{
          string s="";
      for(int i=31;i>=0;i--)
   {
           if(n&(1<<i)) s+='1';
           else s+='0';
   }
   return s;
}
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 string s;
 cin>>s;
 int n=s.size();
 int a=s[n-1]-'0';
 if(a==2 || a==7 || a==4 || a==5 || a==9) cout<<"hon";
 else if (a==3) cout<<"bon";
 else cout<<"pon";
 
 
 
 
 
    
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

Measured memory_bytes: 3588
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
n=l()[0]
A=l()
x=A[0]
for i in range(1,n):
    x=x^A[i]
B=[x^A[i] for i in range(n)]
print(*B)



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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  vector<char> jd(n);
  int flag=0;
  
  for(int i=0; i<n; i++) jd[i] = s.at(i);
  
  for(int i=0; i<n; i++){
    if(jd[i] != jd[n-1-i]) flag++;
  }
  for(int i=0; i<(n-1)/2;i++){
    if(jd[i] != jd[(n-3)/2-i]) flag++;
  }
  for(int i=0; i<(n-1)/2;i++){
    if(jd[(n+3)/2-1+i] != jd[n-1-i]) flag++;
  }
  
  if(flag==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s == "SUN")
    {
        cout << "7";
    }
    else if(s == "MON")
    {
        cout << "6";
    }
    else if(s == "TUE")
    {
        cout << "5";
    }
    else if(s == "WED")
    {
        cout << "4";
    }
    else if(s == "THU")
    {
        cout << "3";
    }
    else if(s == "FRI")
    {
        cout << "2";
    }
    else
    {
        cout << "1";
    }
    
    return 0;
}

Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n,x;
  cin >> n >> x;
  vector<int> l(n);
  int ans = 1;
  int d = 0;
  for(int i = 0; i < n; i++) {
    cin >> l[i];
    d += l[i];
    if(d > x) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
mySet = set()
for i in A:
  if (i % 2)==0:
    mySet.add(i)   
count = 0
for j in mySet:
  if (j%3)==0 or (j%5)==0:
    count = count + 1
if count == len(mySet):
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,q,ans=0,v[100010],t[100010];
    cin>>n;
    rep(i,n){
        cin>>v[i];
    }
    cin>>q;
    rep(i,q){
        ll a,res=0;
        cin>>a;
        ll right=n-1,left=0,middle;
        while(right!=left){
            middle=(right+left)/2;
            if(v[middle]>= a){
                right = middle;
            } else{
                left = middle+1;
            }
        }
        if(v[right]==a) ans++; 
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3836
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

void solve(const int n, const string &s, const int k) {
  ll d = 0, m = 0, dm = 0, ans = 0;
  vl rd(n, 0), rm(n, 0);
  REP(i, n) {
    if (rd[i] < 0) {
      d -= 1;
      dm -= m;
    }
    if (rm[i] < 0) {
      m -= 1;
    }

    if (s[i] == 'D') {
      d++;
      if (i + k < n)
        rd[i + k]--;
    }
    if (s[i] == 'M') {
      m++;
      dm += d;
      if (i + k < n)
        rm[i + k]--;
    }
    if (s[i] == 'C') {
      ans += dm;
    }
  }
  cout << ans << endl;
}

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  REP(i, q) {
    int k;
    cin >> k;
    solve(n, s, k);
  }
  return 0;
}


Measured memory_bytes: 18868
#include<bits/stdc++.h>
using namespace std;
const int maxn=3006;
const int inf=1e9+7; 
typedef long long ll;
int dir[][2]={1,0,-1,0,0,1,0,-1};
int a[maxn],b[maxn],c[maxn],D[maxn],e[maxn],f[maxn];
int u[maxn][maxn],d[maxn][maxn],l[maxn][maxn],r[maxn][maxn],vis[maxn][maxn];
vector<int>xx({-inf,inf}),yy({-inf,inf});
void bfs(int x,int y){
	vis[x][y]=1;
	queue<pair<int,int>>q;
	q.push({x,y});
	while(!q.empty()){
		x=q.front().first,y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++){
			if(i==0&&r[x][y]) continue;
			if(i==1&&l[x][y]) continue;
			if(i==2&&u[x][y]) continue;
			if(i==3&&d[x][y]) continue;
			int nx=x+dir[i][0];
			int ny=y+dir[i][1];
			if(nx<0||ny<0) continue;
			if(nx>=xx.size()-1||ny>=yy.size()-1) continue;
			if(vis[nx][ny]) continue;
			vis[nx][ny]=1;
			q.push({nx,ny});
		}
	}
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		scanf("%d",&b[i]);
		scanf("%d",&c[i]);
		xx.push_back(a[i]);
		xx.push_back(b[i]);
		yy.push_back(c[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%d",&D[i]);
		scanf("%d",&e[i]);
		scanf("%d",&f[i]);
		xx.push_back(D[i]);
		yy.push_back(e[i]);
		yy.push_back(f[i]);
	}
	sort(xx.begin(),xx.end());
	sort(yy.begin(),yy.end());
	xx.resize(unique(xx.begin(),xx.end())-xx.begin());
	yy.resize(unique(yy.begin(),yy.end())-yy.begin());
	for(int i=0;i<n;i++){
		int aa=lower_bound(xx.begin(),xx.end(),a[i])-xx.begin();
		int bb=lower_bound(xx.begin(),xx.end(),b[i])-xx.begin();
		int cc=lower_bound(yy.begin(),yy.end(),c[i])-yy.begin();
		for(int x=aa;x<bb;x++){
			u[x][cc-1]=1;
			d[x][cc]=1;
		}
	}
	for(int i=0;i<m;i++){
		int dd=lower_bound(xx.begin(),xx.end(),D[i])-xx.begin();
		int ee=lower_bound(yy.begin(),yy.end(),e[i])-yy.begin();
		int ff=lower_bound(yy.begin(),yy.end(),f[i])-yy.begin();
		for(int y=ee;y<ff;y++){
			l[dd][y]=1;
			r[dd-1][y]=1;
		}
	}
	int x=lower_bound(xx.begin(),xx.end(),0)-xx.begin()-1;
	int y=lower_bound(yy.begin(),yy.end(),0)-yy.begin()-1;
	bfs(x,y);
	if(vis[0][0]||vis[xx.size()-1][yy.size()-1]){
		printf("INF\n");return 0;
	}
	ll ans=0;
	for(int i=0;i<xx.size()-1;i++){
		for(int j=0;j<yy.size()-1;j++){
			if(vis[i][j]) ans+=(ll)(xx[i+1]-xx[i])*(yy[j+1]-yy[j]);
		}
	}
	printf("%lld\n",ans);
}

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

using namespace std;

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

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(a, b) << ' '  << max(0, a + b - n ) << '\n';

    return 0;
}


Measured memory_bytes: 256
import copy
import math
import time

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()

    n = get_int()
    s_list = get_string_char_list()
    s_list = [int(x) for x in s_list]

    #n = 30000
    #s_list = [1] * 30000

    #ans_set = set([])

    #for i in range(0,n):
    #    for ii in range(i+1, n):
    #        for iii in range(ii+1, n):
    #            ans_set.add(int(s_list[i]) * 100 + int(s_list[ii]) * 10 + int(s_list[iii]) * 1)

    #print(len(ans_set))

    ans = 0

    for i in range(0, 1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10

        find_a = False
        find_b = False
        for ii in s_list:

            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):

                ans += 1
                break
    print(ans)

    #print(time.time() - start)

if __name__ == '__main__':
    main()




Measured memory_bytes: 9924
def ispal(s):
  l = len(s)
  for i in range(l):
    if s[i] != s[l-i-1]:
      return False
  
  return True

def solve(S):
  n = len(S)
  if n%2:
    l = (n-1)//2
    if ispal(S) and ispal(S[:l]) and ispal(S[l+1:]):
      return 'Yes'
  	
    return 'No'
  else:
    return "No"
S = input()
print(solve(S))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int n, dp[18][301];
int rec( int idx, int mul){
  if(mul < 0) return 0;
  if(idx > 17) return mul == 0;
  if(dp[idx][mul]) return dp[idx][mul];
  return dp[idx][mul] = rec( idx + 1, mul) + rec( idx, mul - idx * idx);
}
int main(){
  while(cin >> n, n){
    cout << rec(1,n) << endl;
  }
}

Measured memory_bytes: 1184
import java.util.*;

public class Main {
  public static void main(String args[]) {
	Scanner sc = new Scanner(System.in);
    
    String S = sc.next();
    String T = sc.next();
    int A = sc.nextInt();
    int B = sc.nextInt();
    String U = sc.next();
    sc.close();
    
    if (S.equals(U)) {
      System.out.printf("%d %d", A-1, B);
    } else {
      System.out.printf("%d %d", A, B-1);
    }
  }
}

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

using namespace std;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}



int main(){

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

    int n, t;
    cin >> n >> t;
    vector<ll> a(n);

    ll mn = INT_MAX;
    ll prof[n];
    ll mx = 0;
    rep(i, n) {
        cin >> a[i];
        mn = min(mn, a[i]);
        prof[i] = a[i]-mn;
        mx = max(mx, a[i]-mn);
    }


    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(prof[i] == mx) ++cnt;
    }
    ppp(cnt);




    return 0;
}


Measured memory_bytes: 1792
/*input
5
0.42 0.01 0.42 0.99 0.42
*/

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define db long double
const int N=3010;
db dp[N][N], arr[N];

db calc(int n) {

	// dp[i][j] denotes total probability of i tails for j coins
	dp[0][1] = arr[0];
	dp[1][1] = 1-arr[0];
	for (int i=1; i<=n-2; i+=2) {
		
		vector <db> temp(3);
		temp[0] = arr[i]*arr[i+1];
		temp[1] = arr[i]*(1-arr[i+1]) + arr[i+1]*(1-arr[i]);
		temp[2] = (1-arr[i]) * (1-arr[i+1]);
		int t=0;
		for (int j=0; j<=i; j++) {
			for (int k=0; k<3; k++) { // k denotes no. of tails
				// if ( (i+2)/2 + 1 >  j+k ) {
					// cout<<i<<" "<<j<<" "<<k<<"\n";

					dp[j+k][i+2] += dp[j][i] * temp[k];
				// }
			} 
		}
	}
	// for (int i=0; i<=n; i++) {
	// 	for (int j=0;j<=n;j++) cout<<dp[i][j]<<" ";
	// 	cout<<"\n";
	// }
	db ans=0;
	for (int i=0;i<=n/2;i++)ans+=dp[i][n];
	return ans;
}
int main () {
	int n;
	cin>>n;
	for (int i=0; i<n;i++)cin>>arr[i];
	cout<<setprecision(10);
	cout<<calc(n)<<"\n";

	return 0;
}

Measured memory_bytes: 141568
#include<bits/stdc++.h>
using namespace std;
 
int dy[]={-1,-1,0,1,1,1,0,-1};
int dx[]={0,1,1,1,0,-1,-1,-1};
 
string s;
int t[21][17];
int py[20],px[20];
int m=0,sy,sx;
 
struct state{
  int y,x,S,cost;
};
 
 
state calc(int dir,state s){
  int T=0;
 
  int ny=s.y+dy[dir],nx=s.x+dx[dir];
 
  while(1){
    if(t[ny][nx]==-1)break;
    T|=(1<<t[ny][nx]);
    ny+=dy[dir];
    nx+=dx[dir];
  }
 
  if(T==0)s.cost=-2;
  s.y=ny;
  s.x=nx;
  s.cost++;
  s.S-=T;
  return s;
}
 
int solve(){
 
  queue< state > Q;
  Q.push((state){sy,sx,(1<<m)-1,0});
 
  while(!Q.empty()){
    state s=Q.front();Q.pop();
    int S=s.S;
 
    for(int i=0;i<m;i++)
      if(S>>i&1)
    t[py[i]][px[i]]=i;
 
    for(int i=0;i<8;i++){
      state next=calc(i,s);
      if(next.cost==-1)continue;
      if(next.y<1)continue;
      if(next.y>19){
    return s.cost+1;
      }
      if(next.y==19){
    if(1<=next.x&&next.x<=15)return s.cost+1;
    else continue;
      }
      if(next.x<1)continue;
      if(next.x>15)continue;
      Q.push(next);
    }
    for(int i=0;i<m;i++)
      if(S>>i&1)
    t[py[i]][px[i]]=-1;
  }
  return -1;
}
 
int main(){
  for(int i=0;i<21;i++)
    for(int j=0;j<17;j++)
      t[i][j]=-1;
 
  for(int i=0;i<19;i++){
    cin>>s;
    for(int j=0;j<15;j++){
      if(s[j]=='O'){
    sy=i+1,sx=j+1;
      }else if(s[j]=='X'){
    py[m]=i+1;
    px[m]=j+1;
    m++;
      }
    }
  }
  cout<<solve()<<endl;
  return 0;
}

Measured memory_bytes: 21604
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<queue>
#include<set>
typedef long long ll;
using namespace std;


int main(){
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>

using namespace std;

long long gcd( long long m, long long n )
{
  long long a=m, b=n, tmp, r;
  /* 自然数 a > b を確認・入替 */
if(a<b){
  tmp = a;
  a = b;
  b = tmp;
}

/* ユークリッドの互除法 */
r = a % b;
while(r!=0){
  a = b;
  b = r;
  r = a % b;
}
  return b;

}//gcd

int main() {
  int t;
  scanf("%d", &t);
  long long A[t], B[t], C[t], D[t];
  for (int i = 0; i < t; i++) {
    scanf("%lld %lld %lld %lld", &A[i], &B[i], &C[i], &D[i]);
  }

  for (int i = 0; i < t; i++) {
    long long d = gcd(B[i], D[i]);
    long long cri;
    if ((C[i]-A[i])%d == 0) {
      cri = (C[i]-A[i])/d+1;
    } else {
      cri = (C[i]-A[i])/d;
    }
    if (cri > 0) cri++;

    if (A[i]<B[i] || D[i]<B[i]) {
      printf("No\n");
    } else if (C[i]-A[i] < cri*d && cri*d < B[i]-A[i]) {
      printf("No\n");
    } else {
      printf("Yes\n");
    }
  }

  return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010, mod = 1e9 + 7;

int n, a[N];

int qp(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1) res = (LL)res * a % mod;
        a = (LL)a * a % mod;
        b >>= 1;
    }
    return res;
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a[x]++;
    }

    bool flag = true;
    if(n & 1)
    {
        if(a[0] != 1) flag = false;
        for(int i = 2; i < n; i += 2)
            if(a[i] != 2)
            {
                flag = false;
                break;
            }
    }
    else
    {
        for(int i = 1; i < n; i += 2)
            if(a[i] != 2)
            {
                flag = false;
                break;
            }
    }

    if(!flag) puts("0");
    else cout << qp(2, n / 2) << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

ll C[52][52];

void comb(ll N) {
    memset(C, 0, sizeof(C));
    REP(i, N+1) REP(j, i+1) {
        if (j == 0 or j == i) C[i][j] = 1;
        else C[i][j] = C[i-1][j-1] + C[i-1][j];
    }
}

int main() {
    ll N, P; cin >> N >> P;
    comb(N);
    
    ll even = 0;
    ll odd = 0;
    REP(i, N) {
        ll A; cin >> A;
        if (A % 2 == 1) odd++;
        else even++;
    }
    
    ll ans = pow(2, even);
    if (P % 2 == 1) {
        if (odd == 0) {
            cout << 0 << endl;
            return 0;
        }
        
        ll sum = 0;
        REP(i, odd + 1) {
            if (i % 2 == 1) sum += C[odd][i];
        }
        ans *= sum;
    } else {
        ll sum = 0;
        REP(i, odd + 1) {
            if (i % 2 == 0) sum += C[odd][i];
        }
        ans *= sum;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    char b;
    cin >> b;
    if(b=='A') out('T');
    else if(b=='G') out('C');
    else if(b=='C') out('G');
    else out('A');
}

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

const long long int MOD = 1e9+7;
#define pb push_back
typedef long long ll;
const long long int N = 1e5;



int main(){
    int n,k;
    cin>>n>>k;
    vector<vector<ll>> dp(n+5,vector<ll>(k+5,0));
    vector<vector<ll>> pref(n+5,vector<ll>(k+5,0));

    ll a[n+5];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        dp[i][0]=1;
        pref[i][0]=1;
    }
    for(int i=0;i<=k;i++)  pref[0][i]=1;
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<=k;j++){
            if(a[i]<=j-1)
                dp[i][j]=(pref[i-1][j]-pref[i-1][j-a[i]-1]+MOD)%MOD;
            else
                dp[i][j]=pref[i-1][j];
            if(j>0)
            pref[i][j]=(pref[i][j-1]+dp[i][j])%MOD;
        }
    }
    cout<<dp[n][k];
    return 0;
}

Measured memory_bytes: 168292
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

pub fn gcd<T: PrimInt>(a: T, b: T) -> T {
    if b == zero()  {
        a
    } else {
        gcd(b, a % b)
    }
}

pub fn gcd_list<T: PrimInt>(vec: Vec<T>) -> T {
    assert!(vec.len() > 1);
    vec.iter().fold(vec[0], |acc, x| gcd(*x, acc))
}

fn main() {
    input!{ k: usize }

    let mut ans = 0;
    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                ans += gcd_list(vec![a, b, c])
            }
        }
    }

    println!("{}", ans)
}


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

int main(){
    int n;
    cin>>n;
    vector <int> x(101,0);
    int ave=0;
    rep(i,n) {
        cin>>x[i];
        ave+=x[i];
    }
    ave/=n;
    int lans,rans =0;
    rep(i,n){
        lans+=pow(x[i]-ave,2);
        rans+=pow(x[i]-ave-1,2);
    }
    cout<<min(lans,rans)<<endl;

}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

vector<vector<int> > v1;
vector<vector<int> > v2;
int H, W, K;

void dfs1(int n, vector<int> s) {
  if (n == H) {
    v1.pb(s);
  }
  else {
    dfs1(n+1, s);
    s.pb(n);
    dfs1(n+1, s);
    s.pop_back();
  }
}

void dfs2(int n, vector<int> s) {
  if (n == W) {
    v2.pb(s);
  }
  else {
    dfs2(n+1, s);
    s.pb(n);
    dfs2(n+1, s);
    s.pop_back();
  }
}

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

  cin >> H >> W >> K;
  vector<string> c(H);
  rep(i, H) {
    cin >> c[i];
  }
  int ans = 0;
  rep(i, H) {
    rep(j, W) {
      if (c[i][j] == '#')
        ans++;
    }
  }
  int sum = 0;
  vector<int> s1;
  vector<int> s2;
  dfs1(0, s1);
  dfs2(0, s2);
  // cout << v1.size() << endl;
  // rep (i, v1.size()) {
  //   rep (j, v1[i].size()) {
  //     cout << v1[i][j] << ' ';
  //   }
  //   cout << endl;
  // }
  rep (i, v1.size()) {
    rep (j, v2.size()) {
      int cnt = 0;
      rep (k, v1[i].size()) {
        rep (l, v2[j].size()) {
          if (c[v1[i][k]][v2[j][l]] == '#')
            cnt++;
        }
      }
      // cout << cnt << endl;
      // rep (l, v1[i].size()) {
      //   cout << v1[i][l] << ' ';
      // }
      // cout << endl;
      // rep (l, v2[j].size()) {
      //   cout << v2[j][l] << ' ';
      // }
      // cout << endl;
      if (cnt == K)
        sum++;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
int main() {
	scanf("%d",&n);
	int v1=1e9,v2=-1e9,c1=0,c2=0;
	for (int i=1;i<=n;++i) {
		scanf("%d",a+i);
		v1=min(v1,a[i]);
		v2=max(v2,a[i]);
	}
	if (v2-v1>1) return puts("No"),0;
	if (v1==v2) {
		puts(v1<=n/2||v1==n-1?"Yes":"No");
	}
	else {
		for (int i=1;i<=n;++i) {
			a[i]==v1?++c1:++c2;
		}
		puts(c2>1&&c1+1<=v2&&v2<=c1+c2/2?"Yes":"No");
	}
}

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

#define MAX 100000
#define ll long long

ll arr[MAX+5];
int n;
ll dp[MAX+5];

void initialize()
{
    for(int i=0;i<=MAX+5;i++) dp[i] = -1;
}

ll frog(int pos)
{
    if(pos<=1) return 0;
    if(pos==2) return abs(arr[2]- arr[1]);

    if(dp[pos]!=-1) return dp[pos];

    ll p1 = frog(pos-1)+abs(arr[pos] - arr[pos-1]);
    ll p2 = frog(pos-2)+abs(arr[pos] - arr[pos-2]);

    dp[pos] = min(p1, p2);

    return min(p1, p2);
}

int main()
{
    initialize();
    cin>>n;
    for(int i=1;i<=n;i++) cin>>arr[i];

    ll cost = frog(n);

    cout<<cost<<endl;
    return 0;
}


Measured memory_bytes: 9848
#include <iostream>
#include <cstring>
#include <climits>

using namespace std;

int N, M;
int C[20];
int X[20020];

int INF = 1300500001;
int dp[20020][300];

void solve() {
	for (int i=0; i<20020; i++) fill(dp[i], dp[i]+300, INF);
	
	dp[0][128] = 0;
	for (int i=0; i<N; i++) {
		
		for (int j=0; j<=255; j++) {
		
			for (int k=0; k<M; k++) {
				int jck = j+C[k];
				if (jck < 0) jck = 0;
				if (jck > 255) jck = 255;
				if (dp[i][j] == INF) continue;
				dp[i+1][jck] = min(dp[i+1][jck], dp[i][j] + (jck-X[i])*(jck-X[i]) );
			}
			
		}
	}
	
	int ans = INF;
	for (int i=0; i<=255; i++) ans = min(ans, dp[N][i]);
	cout << ans << endl;	
}

int main() {

	while(1) {
		cin >> N >> M; if (N==0 && M==0) break;
		for (int i=0; i<M; i++) cin >> C[i];
		for (int i=0; i<N; i++) cin >> X[i];
		
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 24700
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N;
  long long int sum=0;
  cin>>N;
  long long int L[2*N];
 if(N>=1&&N<=100){
  for(int i=0;i<2*N;i++){
      cin>>L[i];
  }
  int S = sizeof(L)/sizeof(L[0]); 
  sort(L, L+S, greater<int>()); 
 
  for(int i=0;i<2*N;i++){
      if(i%2==0){
          sum+=min(L[i],L[i+1]);
      }
  }
  cout<<sum;
 }
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
  int a,b,ans;cin >> a >> b;
  ans = a-b;
  if(ans<0){
    ans = 0;
  }
  cout << ans << endl;
}
  

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

int main() {
	int n;
	cin >> n;
	int a[n * 3];
	for (int i = 0; i < n * 3; i++) {
		cin >> a[i];
	}
	sort(a, a + n * 3, greater<int>());
	long ans = 0;
	for (int i = 1, cnt = 0; cnt < n; i += 2, cnt++) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408