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

int main() {
  int a, c;
  cin >> a;
  int sum = 0;
  c = a;
  for( int i = 0;i < 8;i++){
  if(a > 0) {
    int b;
	b = a % 10;
    a = a / 10;
    sum += b;
  }
  }
  
  if ( c % sum > 0 ) {
    cout << "No" << endl;
  }   else cout << "Yes" << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]

a = sorted(a,key=lambda x:x[0])
ans = 0
for i in range(n):
    ans += a[i][1]
    if ans >= k:
        print(a[i][0])
        exit()

Measured memory_bytes: 29492
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

#define INF 10000000
#define SOUR 200
#define SINK 201

int N,M;
class Node
{
public:
	vector<int> to;

};

class Edge
{
public:
	int s,d;
	double c;
	Edge(int s, int d, double c)
		:s(s),d(d),c(c)
	{}

	bool operator<(const Edge& e) const
	{
		return c<e.c;
	}
};

int flow[202][202], capa[202][202];

int dfs(int p, int T, int mf, vector<Node>& graph, vector<int>& level, vector<bool>& finished)
{
	if(p==T) return mf;
	if(finished[p]) return 0;

	finished[p]=true;

	for(int i=0; i<graph[p].to.size(); i++)
	{
		int next=graph[p].to[i], fw=capa[p][next]-flow[p][next];
		if(level[p] >=level[next]) continue;
		if(fw <=0 ) continue;

		int f=dfs(next, T, min(mf, fw), graph, level, finished);
		if(f>0)
		{
			finished[p]=false;
			flow[p][next]+=f;
			flow[next][p]-=f;
			return f;
		}
	}

	return 0;
}

int dinic(int S, int T, vector<Node>& graph)
{
	bool end=false;
	int total=0;
	while(!end)
	{
		end=true;
		vector<int> level(graph.size(), -1);
		level[S]=0;

		queue<int> q;
		q.push(S);
		
		while(!q.empty())
		{
			int n=q.front(); q.pop();
			for(int i=0; i<graph[n].to.size(); i++)
			{
				int next=graph[n].to[i];
				if(level[next]!=-1) continue;
				if(capa[n][next]-flow[n][next] <=0) continue;
				level[next]=level[n]+1;
				q.push(next);
			}
		}

		if(level[T]==-1) break;

		vector<bool> finished(graph.size());
		while(1)
		{
			int fw=dfs(S, T, INF, graph, level, finished);
			if(fw<=0) break;

			total+=fw;
			end=false;
		}
	}

	return total;
}

bool calc(int& hi, int& lo, vector<Edge>& G, double& ans)
{
	if(hi<lo) return false;
	int mi=(hi+lo)/2;

	memset(flow, 0, sizeof(flow));
	memset(capa, 0, sizeof(capa));

	vector<Node> graph(205);
	for(int i=0; i<=mi; i++)
	{
		graph[G[i].s].to.push_back(G[i].d);
		graph[G[i].d].to.push_back(G[i].s);
		graph[SOUR].to.push_back(G[i].s);
		graph[G[i].d].to.push_back(SINK);

		capa[G[i].s][G[i].d]=1;
		capa[G[i].d][G[i].s]=1;
		flow[G[i].d][G[i].s]=1;

		capa[SOUR][G[i].s]=1;
		capa[G[i].s][SOUR]=1;
		flow[G[i].s][SOUR]=1;

		capa[G[i].d][SINK]=1;
		capa[SINK][G[i].d]=1;
		flow[SINK][G[i].d]=1;
	}
	if(dinic(SOUR, SINK, graph) == M)
	{
		hi=mi-1;
		ans=min(G[mi].c,ans);
	}
	else
	{
		lo=mi+1;
	}

	return true;
}

int main()
{
	while(scanf("%d%d", &N,&M), (N||M))
	{
		double x[100],y[100],v[100];
		for(int i=0; i<N; i++)
			scanf("%lf%lf%lf", &x[i],&y[i],&v[i]);

		vector<Edge> e;
		for(int j=0; j<M; j++)
		{
			double xx, yy;
			scanf("%lf%lf", &xx,&yy);
			for(int i=0; i<N;i++)
			{
				double dist=(x[i]-xx)*(x[i]-xx)+(y[i]-yy)*(y[i]-yy);
				e.push_back(Edge(i,j+100, sqrt(dist)/v[i]));
			}
		}

		sort(e.begin(), e.end());

		int hi=e.size()-1, lo=0;
		double ans=INF;

		while(1)
		{
			if(!calc(hi,lo,e,ans)) break;
		}

		printf("%.20lf\n", ans);
	}
}

Measured memory_bytes: 1648
import bisect
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

# 二分探索 #
def nibutan(list,n):
	left = -1
	right = len(list)
	while left+1 != right:
		middle = (left+right)//2
		if list[middle] < n:
			left = middle
		else:
			right = middle
	return left+1

N = I()
A = sorted(IL())
B = sorted(IL())
C = sorted(IL())

dp = [0]*(N+1)

for i in range(N):
	dp[i] = nibutan(A,B[i])

num = 0
for i in range(N):
	num += dp[i]
	dp[i] = num

ans = 0
for i in range(N):
	ans += dp[nibutan(B,C[i])-1]

print(ans)

Measured memory_bytes: 32940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    ll x = 0, X = 1000;
    x = X/A[0], X -= A[0]*x;
    for (int i = 1; i < N; i++) {
        if (A[i-1] > A[i]) {
            X += A[i-1]*x;
            x = 0;
            
            x = X/A[i];
            X -= A[i]*x;
        }
        else if (A[i-1] < A[i]) {
            ll k = X/A[i-1];
            x += k;
            X -= A[i-1]*k;

            X += A[i]*x;
            x = 0;
        }
        else {
            X += A[i]*x;
            x = 0;
        }
    }
    X += A[N-1]*x;
    x = 0;
    cout << X << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <set>

using namespace std;

int main() {
  int n, k, r;
  int m[50], p[5000], q[5000];
  int bunny[50][50];
  int count = 0;
  set<int> all, selected;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    cin >> m[i];
    for (int j = 0; j < m[i]; ++j) {
      cin >> bunny[i][j];
    }
  }
  cin >> r;
  for (int i = 0; i < r; ++i) {
    cin >> p[i] >> q[i];
  }
  for (int i = 0; i < k; ++i) {
    all.clear();
    selected.clear();
    for (int j = 0; j < m[i]; ++j) {
      all.insert(bunny[i][j]);
    }
    for (int j = 0; j < r; ++j) {
      if (all.count(p[j]) * all.count(q[j]) > 0) {
        selected.insert(p[j]);
        selected.insert(q[j]);
      }
    }
    count += selected.size();
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1224
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)
 
func run() {
	n := nextInt()
	k := nextInt()
	s := next()
	
	v := make([]int, 0)
	
	for i := 0; i < n; i++ {
		if(string(s[i]) == "R"){
			v = append(v, 1)
		}else {
			v = append(v, 0)
		}
	}
	
	count := 0
	count2 := 0
	te := v[0]
	
	for i := 1; i < n; i++ {
		if(te == v[i]){ 
			count ++
		}else{
			count2 ++
			te = v[i]
		}
	} 
	
	if ((count2 + 1) / 2 > k) {
		Println(count + k * 2)
	} else{
		Println(n - 1)
	}
	
}

// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}
 
func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}

Measured memory_bytes: 7296
#include<stdio.h>

int main(){
	int n,i,count[100002]={0},a,ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		count[a]++;
		if(a>0)count[a-1]++;
		if(a<100001)count[a+1]++;
	}
	for(i=0;i<=100000;i++){
		if(ans<count[i])ans=count[i];
	}
	printf("%d\n",ans);
	return 0;
}

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

int n , w , a[100][2] , dp[100][100001];
int f(int i , int v)
{
    int &d = dp[i][v];
    if( v == 0 ) return 0;
    if( i == n || v < 0 ) return 1e9+1;
    if( d != -1 ) return d;
    return d = min( f(i+1,v) , f(i+1,v-a[i][1]) + a[i][0] );
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin >> n >> w;
    for(int i=0;i<n;++i)
        cin >> a[i][0] >> a[i][1];
    for(int i=1e5;i>=0;--i)
    {
        int wi = f(0,i);
        if( wi <= w )
        {
            cout << i; return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 39296
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> a(m);
	rep(i,m) cin >> a[i];
	int l = 0, r = 0;
	rep(i,m){
		if(a[i] < x) l++;
		if(a[i] > x) r++;
	}
	chmin(l, r);
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <vector>
using namespace std;

double p[3010];
int N;
vector< vector<double> > dp (3010, vector<double>(3010, -1));

double q(int n, int k) {
    if (dp[n][k] != -1) return dp[n][k];
    else if (k <= 0) dp[n][k] = 1;
    else if (n < k) dp[n][k] = 0;
    else dp[n][k] = p[n-1] * q(n-1, k-1) + (1.0 - p[n-1]) * q(n-1, k);

    return dp[n][k];
}

int main() {
    int i;

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

    printf("%.10f\n",q(N, (N + 1)/2));
}

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

int main(){
  int turn;
  int stepn = 0;
  int sain = 0;
  vector<int> outp;
  for(turn = 0; ;turn++){
    cin >> stepn;
    cin >> sain;
    if(stepn == 0 && sain == 0){
      break;
    }
    int pos = 0;
    int g = 0;
    vector<int> step(stepn + 6,0);
    vector<int> sai(sain,0);
    sai.resize(sain,0);
    for(int n = 0;n<stepn;n++){
      cin >> step[n];
    }
    for(int n = 0;n<sain;n++){
      cin >> sai[n];
    }
    for(int t = 0;t<sain;t++){
      g += 1;
      pos += sai[t];
      pos += step[pos];
      if(stepn <= pos + 1){
        break;
      }
    }
    outp.push_back(g);
  }
  for(int x = 0;x<turn;x++){
    cout << outp[x] << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>
int main(void)
{
	int i,j,k,n,m,l,s,ss,kk,ll;
	char a[100][100];
	char b[100][100];
	scanf("%d%d",&n,&m);
	getchar();
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%c",&a[i][j]);
		}
		getchar();
	}
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=m;j++)
		{
			scanf("%c",&b[i][j]);
		}
		getchar();
	}
	ss=0;
	for(i=1;i<=n-m+1;i++)
	{
		for(j=1;j<=n-m+1;j++)
		{
			if(a[i][j]==b[1][1])
			{
				s=0;
				for(k=i,kk=1;k<i+m;k++,kk++)
				{
					for(l=j,ll=1;l<j+m;l++,ll++)
					{
						if(a[k][l]!=b[kk][ll])
						{
							s=1;
							break;
						}
					}
					if(s==1)
					break;
				}
				if(s==0)
				{
					ss=1;
					break;
				}
			}
		}
		if(ss==1)
		break;
	}
	if(ss==1)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
s = str(input())
result = ""
res = []

for i in range(len(s)):
    if s[i] == "0":
        res.append("0")
    elif s[i] == "1":
        res.append("1")
    else:
        if len(res) > 1:
            del res[-1]
        elif len(res) == 1:
            res = []

for i in res:
    result += i

print(result)


Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pll  = pair<ll,ll>;
using vll  = vector<pll>;
using vvll = vector<vll>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define dmax(a,b) a=max(a,b)

int n;
vvll dp(1<<18, vll(2));

int main() {
    cin >> n;
    rep(i,1<<n) {
        scanf("%ld", &dp[i][0].first);
        dp[i][0].second = i;
    }
    rep(b,1<<n) {
        rep(i,n) {
            int nb = b | (1<<i);
            if (nb == b) continue;
            if (dp[b][0].first > dp[nb][0].first) {
                if (dp[b][1].first > dp[nb][0].first) {
                    dp[nb][1] = dp[b][1];
                } else {
                    dp[nb][1] = dp[nb][0];
                }
                dp[nb][0] = dp[b][0];
            } else if (
                dp[b][0].first > dp[nb][1].first and
                dp[b][0].second != dp[nb][0].second
            ) {
                dp[nb][1] = dp[b][0];
            }
        }
    }
    ll ans = 0;
    rng(i,1,1<<n) {
        dmax(ans, dp[i][0].first + dp[i][1].first);
        printf("%ld\n", ans);
    }
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int h, w;
    cin >> h >> w;
    int mp[10][10] = {};
    int cnt = 0;
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            char c;
            cin >> c;
            if(c == '#') {
                mp[i][j] = 1;
                ++cnt;

            }

        }
    }

    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            if(i == 1 && j == 1) {
                if(mp[i][j] != 1) {
                    cout << "Impossible" << endl;
                    return 0;

                }
                continue;
            }
            if(mp[i][j] == 1) {
                if(mp[i - 1][j] != 1 && mp[i][j - 1] != 1) {
                    cout << "Impossible" << endl;
                    return 0;

                }
            }
            if(mp[i - 1][j] == 1 && mp[i][j - 1] == 1) {
                cout << "Impossible" << endl;
                return 0;

            }
        }
    }
    if(cnt == h + w - 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main() {

    int n;
    cin>>n;
    ll ans=0;
    rep(i,n){
        int l,r;
        cin>>l>>r;
        ans+=r-l+1;
    }
    fin(ans);
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        a: char,
    }

    if (b'a'..=b'z').contains(&(a as u8)) {
        println!("a");
    } else {
        println!("A");
    }
}


Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void)
{
	int x, y, d, work;
	cin >> x >> y;
	if (x < y) {
		work = x; x = y; y = work;
	}
	d = x % y;
	if (x % y == 0) d = y;
	while(x % y) {
		d = x % y;
		x = y; y = d;
	}
	cout << d << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
int A[N];
int n , m;

void solve()
{
	int a;
	cin >> a;

	cout << a*(1 + a + a*a);
}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  	string B;
  	cin >> B;
  	if (B=="A"){
      cout << "T";
    }
  	if (B=="T"){
      cout << "A";
    }
  	if (B=="G"){
      cout << "C";
    }
  	if (B=="C"){
      cout << "G";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<cctype>
#include <fstream>
#include <time.h>
#include <iterator>





#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define fil(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;

int Rank[100010], numR[100010];
vector<int>G[100010];
void dfs(int n,int r,int pre) {
	Rank[n] = r;
	numR[r]++;
	for (auto x: G[n]) {
		if (x == pre)continue;
		dfs(x, r + 1, n);
	}
}
int ans = 1;
int K;
void dfs2(int n, int pre, int cnt) {
	//print(n);
	if (n == 0) {
		ans *= K; ans %= MOD;
	}
	else if (pre == 0) {
		ans *= (K - cnt-1);
		ans %= MOD;
	}
	else {
		ans *= (K - 2 - cnt);
		ans %= MOD;
	}
	int c = 0;
	for (auto x : G[n]) {
		if (x == pre)continue;
		dfs2(x, n, c);
		c++;
	}
}
bool visited[200020];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	 cin >> K;
	REP(i, N-1) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	dfs2(0, 0, 0);
	//dfs(0, 0, 0);
	////print(1);
	//int ans = 1;
	//REP(i, N) {
	//	if (visited[Rank[i]])continue;
	//	if (Rank[i] == 0) {
	//		ans *= K; ans %= MOD;
	//		visited[0] = 1;
	//		pe(i)print(ans);
	//		continue;
	//	}
	//	else if (Rank[i] == 1) {
	//		int m = numR[1];
	//		if ((m + 1) > K)ans = 0;
	//		int res = 1;
	//		FOR(i, numR[0], m+1) {
	//			res *= (K - i);
	//			res %= MOD;
	//		}
	//		ans *= res;
	//		ans %= MOD;
	//		visited[1] = 1;
	//		pe(i)print(ans);
	//		continue;
	//	}
	//	int m = numR[Rank[i]];
	//	int ran = Rank[i];
	//	if ((m + numR[ran-1]+numR[ran-2]) > K)ans = 0;
	//	int res = 1;
	//	FOR(i, numR[ran - 1] + numR[ran - 2], m + numR[ran - 1] + numR[ran - 2]) {
	//		res *= (K - i);
	//		res %= MOD;
	//	}
	//	ans *= res;
	//	ans %= MOD;
	//	visited[ran] = 1;
	//	pe(i)print(ans);
	//}
	print(ans%MOD);
}

Measured memory_bytes: 10752
#include<stdio.h>

#define true 1
#define false 0

int solve(int,int);

int n , A[20];

int solve(int i,int m)
{
  int res;

  if( m == 0 ) return true;

  if( i >= n ) return false;

  res = solve( i + 1 , m ) || solve( i + 1 , m  - A[i] );

  return res;
}


int main()
{
  int q , j , m;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for( j = 0 ; j < q ; j++) {
    
    scanf("%d",&m);

    if( solve( 0 , m ) == 1 ) printf("yes\n");

    else printf("no\n");
  }

  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,mim=INT_MAX,ans;
int main()
{
	cin>>n;
	while(n--)
	{
		int tmp;
		cin>>tmp;
		mim=min(mim,tmp);
		if(tmp==mim)
		{
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        int ans = A - B * 2;
        if(ans > 0) System.out.println(ans);
        else System.out.println("0");
    }
}

Measured memory_bytes: 21844
///created: 4/Jul/2019 18:18:11

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
const int modulo = 1e9 + 7;

#ifdef LOCAL_DEBUG_NTV1612
template<class __Ty>
string to_string(__Ty a) {
	string res = "[ ";
	bool f = true;
	for (auto &p : a) { res += (f ? string("") : string(", ")) + to_string(p); f = false;	}
	return res + " ]";
}
void _debug() { fprintf(stderr, "\n"); }
template<typename __Ty_head, typename... __Ty_tail>
void _debug(__Ty_head head, __Ty_tail... tail) { fprintf(stderr, "%s ", to_string(head).c_str()); _debug(tail...); }
#define debug(...) fprintf(stderr, "DEBUG [%s]: ", #__VA_ARGS__), _debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif

template<class __Ty> bool mini(__Ty& a, __Ty b) { return a > b ? ((a = b) | 1) : (0); }
template<class __Ty> bool maxi(__Ty& a, __Ty b) { return a < b ? ((a = b) | 1) : (0); }
template<class __Ty> __Ty add(__Ty a, __Ty b) { return (a + b) % (__Ty(modulo)); }
template<class __Ty> __Ty sub(__Ty a, __Ty b) { __Ty m(modulo); return ((a - b) % m + m) % m; }

int a[501][501], h, w, sum = 0;
bool vs[601][601] = {0};

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> h >> w;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			cin >> a[i][j];
	vector<tuple<int, int, int, int> > ans;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j < w; ++j) {
			if (a[i][j] % 2 != 0) {
				ans.push_back(make_tuple(i, j, i, j + 1));
				a[i][j]--;
				a[i][j + 1]++;
			}
		}
		if (i < h && a[i][w] % 2 != 0) {
			a[i][w]--;
			a[i + 1][w]++;
			ans.push_back(make_tuple(i, w, i + 1, w));
		}
	}
	cout << ans.size() << '\n';
	for (int i = 0; i < int(ans.size()); ++i) {
		int x, y, u, v;
		tie(x, y, u, v) = ans[i];
		cout << x << ' ' << y << ' ' << u << ' ' << v << '\n';	
	}
	int cnt = 0;
	for (int i = 1; i <= h; ++i)
		for (int j =1; j <= w; ++j)
			cnt += a[i][j] % 2;
	assert(cnt <= 1);	
	return 0;
}


Measured memory_bytes: 5232
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

ls = inpl()
for i,k in enumerate(ls):
    if k==0:
        print(i+1)


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

using t_r = tuple<string, int, int>;

bool compare(const t_r &l, const t_r &r)
{
  if (get<0>(l) != get<0>(r))
  {
    return get<0>(l) < get<0>(r);
  }
  return get<1>(l) > get<1>(r);
}

int main()
{
  int N;
  cin >> N;
  vector<t_r> restaurants(N);
  for (int i = 0; i < N; i++)
  {
    string s;
    int p;
    cin >> s >> p;
    restaurants.at(i) = make_tuple(s, p, i + 1);
  }
  sort(restaurants.begin(), restaurants.end(), compare);

  for (auto r : restaurants)
  {
    cout << get<2>(r) << endl;
  }
}


Measured memory_bytes: 256
x = int(input())
if 400 <= x < 600:
    print('8')
elif 600 <= x < 800:
    print('7')
elif 800 <= x < 1000:
    print('6')
elif 1000 <= x < 1200:
    print('5')
elif 1200 <= x < 1400:
    print('4')
elif 1400 <= x < 1600:
    print('3')
elif 1600 <= x < 1800:
    print('2')
elif 1800 <= x < 2000:
    print('1')


Measured memory_bytes: 9180
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Input();
            Initialize();

            for (int i = 0; i < Q; i++)
            {
                var x = p[i];
                var y = q[i];
                Console.WriteLine(Count(y, y) - Count(x - 1, y) - Count(y, x - 1) + Count(x - 1, x - 1));
            }
        }

        // L<=x, Q<=y を満たす電車区間の個数
        static int Count(int x, int y)
        {
            if (dp[x, y] != -1) return dp[x, y];
            if (x == 0 || y == 0) return 0;

            dp[x, y] = trains[x, y] + Count(x - 1, y) + Count(x, y - 1) - Count(x - 1, y - 1);
            return dp[x, y];
        }

        static int N;
        static int M;
        static int Q;
        static int[,] trains;
        static int[] p;
        static int[] q;
        static int[,] dp;

        static void Input()
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            N = input[0];
            M = input[1];
            Q = input[2];
            trains = new int[N + 1, N + 1];
            p = new int[Q];
            q = new int[Q];

            for (int i = 0; i < M; i++)
            {
                var inputLR = Console.ReadLine().Split().Select(int.Parse).ToArray();
                trains[inputLR[0], inputLR[1]]++;
            }

            for (int i = 0; i < Q; i++)
            {
                var inputPQ = Console.ReadLine().Split().Select(int.Parse).ToArray();
                p[i] = inputPQ[0];
                q[i] = inputPQ[1];
            }
        }

        static void Initialize()
        {
            dp = new int[N + 1, N + 1];
            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= N; j++)
                {
                    dp[i, j] = -1;
                }
            }
        }
    }
}


Measured memory_bytes: 20840
#include <stdio.h>
#include <iostream>
#include <map>
using namespace std;

#define N_MAX 200010

long long func(long long n){
    if(n == 1)
        return 0;
    return n * (n - 1) / 2;
}

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

    long long A[N_MAX + 1];

    A[0] = 0;
    for(int i = 0; i < N; i++){
        long long A_;
        scanf("%lld", &A_);
        A[i + 1] = A[i] + A_;
    }

    map<long long, int> mapTable;
    for(int i = 0; i <= N; i++){
        auto it = mapTable.find(A[i]);
        if(it == mapTable.end()){
            mapTable[A[i]] = 1;
        }else{
            it->second += 1;
        }
    }

    long long sum = 0;
    for(auto it = mapTable.begin(); it != mapTable.end(); ++it){
        //cout << it->first << ' ' << it->second << endl;
        sum += func(it->second);
    }
    
    printf("%lld\n", sum);
}



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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint lin(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	list<int> staffList;
	map<int, lint> saleResult;
	int n;
	int staffNum;
	lint unitPrice;
	lint quantity;
	while( 1 )
	{
		n = in();
		if( n == 0 )break;

		staffList.clear();
		saleResult.clear();
		loop(i, 0, n)
		{
			staffNum = in();
			unitPrice = lin();
			quantity = lin();
			staffList.push_back(staffNum);
			saleResult[staffNum] += unitPrice * quantity;
		}
		bool flag = false;
		for(list<int>::iterator it = staffList.begin(); it != staffList.end(); it++)
		{
			if( saleResult[*it] >= 1000000 )
			{
				printf("%d\n", *it);
				saleResult[*it] = 0;
				flag = true;
			}
		}
		if( !flag )
		{
			cout << "NA" << endl;
		}
	}
	return (0);
}

Measured memory_bytes: 1320
from itertools import groupby, chain

N, K, Q, *A = map(int, open(0).read().split())

ans = float("inf")
for Y in set(A):
    G = (sorted(v) for k, v in groupby(A, key=lambda a: a >= Y) if k)
    C = list(chain.from_iterable(v[:len(v) - K + 1]for v in G if len(v) >= K))

    if len(C) >= Q:
        C.sort()
        X = C[Q - 1]
        ans = min(ans, X - Y)

print(ans)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ll a;
        cin >> a;
        while(a % 2 == 0){
            ans++;
            a /= 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static bool f = false,t=true;
static void Main(string[] args)
{
int n=int.Parse(Console.ReadLine());
long []a=Read.longs();
long sum=1;    
for(int i=0;i<n;i++){
sum=lcm(sum,a[i]);
}
Console.WriteLine(sum);


}

    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a  / gcd(a, b) * b;
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (long i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
////////////////////////////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
////////////////////////////////////////////////////////////////////

int main(){
    int N,L;
    SCD2(N,L);
    static int a[100002] = {};
    ARSCD1(a,N);

    FORq(i,1,N-1){
        if (a[i] + a[i+1]  >= L){
            printf("Possible\n");
            FORq(j,1,i-1){PRINTD(j);}
            FORqr(j,i+1,N-1){PRINTD(j);}
            PRINTD(i);
            return 0;
        }
    }
    printf("Impossible\n");
}

Measured memory_bytes: 1280
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,a,b,dep,p,q;
int vis[N],path[N];
vector<int>e[N];
int dfs1(int now,int deep){
    vis[now]=1;
    if(now==n){
        dep=deep;
        return 1;
    }
    for(int i=0;i<e[now].size();i++){
        if(vis[e[now][i]])
            continue;
        path[deep]=e[now][i];
        if(dfs1(e[now][i],deep+1))
            return 1;
    }
    return 0;
}
int dfs2(int now){
    vis[now]=1;
    int sum=1;
    for(int i=0;i<e[now].size();i++)
        if(!vis[e[now][i]])
            sum+=dfs2(e[now][i]);
    return sum;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d%d",&a,&b);
        e[a].push_back(b);
        e[b].push_back(a);
    }
    path[0]=1;
    dfs1(1,1);
    memset(vis,0,sizeof(vis));
    p=dfs2(1);
    if(dep%2){
        memset(vis,0,sizeof(vis));
        for(int i=0;i<=dep/2;i++)
            vis[path[i]]=1;
        q=dfs2(path[dep/2+1]);
        if(p-q>q)
            printf("Fennec\n");
        else
            printf("Snuke\n");
    }
    else{
        memset(vis,0,sizeof(vis));
        for(int i=0;i<=dep/2-1;i++)
            vis[path[i]]=1;
        q=dfs2(path[dep/2]);
        if(p-q>q)
            printf("Fennec\n");
        else
            printf("Snuke\n");
    }
    return 0;
}
/*
//2
#pragma GCC optimize("Ofast",3,"inline")
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 10;
int n, l, r, q[maxn], vis[maxn];

vector <int> e[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d %d", &u, &v);
        e[u].push_back(v), e[v].push_back(u);
    }
    l = 1, r = 0;
    vis[1] = 1;
    vis[n] = 2;
    q[++r] = 1;
    q[++r] = n;
    for (; l <= r; ) {
        int u = q[l++];
        for (int v : e[u]) {
            if (!vis[v]) {
                vis[v] = vis[u];
                q[++r] = v;
            }
        }
    }
    int sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++) {
        if (vis[i] == 1) {
            sum1++;
        } else {
            sum2++;
        }
    }
    puts(sum1 > sum2 ? "Fennec" : "Snuke");
    return 0;
}
*/

Measured memory_bytes: 9600
n,x,m=map(int,input().split())
ary=[x]
ans=x
d={x:0}
i=1
while x and i<n and (x**2)%m not in d:
  x=(x**2)%m
  ans+=x
  d[x]=i
  ary.append(x)
  i+=1
if x==0 or i==n:
  print(ans)
  exit()
s=d[(x**2)%m]
l=i-s
suml=sum(ary[s:])
tmp=n-i
ans+=suml*(tmp//l)
ans+=sum(ary[s:s+tmp%l])
print(ans)

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

double T_ave(int T, int H);

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

    int T, A;
    scanf("%d %d", &T, &A);

    int H[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &H[i]);
    }

    double min = fabs(A - T_ave(T, H[0]));
    int min_i = 0;
    for(int i = 0; i < N; i++){
        if(min > fabs(A - T_ave(T, H[i]))){
            min = fabs(A - T_ave(T, H[i]));
            min_i = i;
        }
    }

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

double T_ave(int T, int H){
    return T - H * 0.006;
}

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

int main(){
  int n,k;
  int w,h;

  cin >> n;
  cin >> k;

  for(int i=0;i<k;i++){
    cin >> w >> h;
    w--;
    h--;
    if(w > n/2)w = n - 1 - w;
    if(h > n/2)h = n - 1 - h;

    if(h<=w)cout << h%3+1 << endl;
    else cout << w%3+1 << endl;
  }
}

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

int main() {
    int n,k; cin >> n >> k;
    vector<long long> l(k);
    for(int i = 1; i <= n; i ++) l[i%k] ++;
    long long ans = 0;
    for(int a = 0; a < k; a ++) {
        int b = (k-a)%k;
        int c = (k-a)%k;
        if((b+c)%k != 0) continue;
        ans += l[a] * l[b] * l[c];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define m3(a, b, c) max(c, max(a, b))
#define m4(a, b, c, d) min(d, min(c, min(a, b)))
#define test long long t; cin>>t; while(t--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const ll minn=-1e18;
 ll ans[100005][4];
 
 void solve(ll arr[],ll n,ll q[])
 {
 	for(int i=1;i<=n;i++)
 	for(int j=1;j<=3;j++)
 	{
 		ans[i][j]=max(ans[i-1][j],ans[i][j-1]+arr[i-1]*q[j-1]);
 	}
 }
 
 int main()
 { /*memset(ans,0,sizeof(ans));
  for(int i=1;i<4;i++)
  ans[0][i]=(minn*3)-1;*/
 int x;
 cin>>x;
 cout<<!x;
 
 }

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

int main(void) {
	int n;
	std::cin >> n;

	std::string s, s0;

	std::cin >> s;

	std::map<std::string, int> m;
	m[s] = 1;
	for (size_t i = 0; i < n - 1; i++) {
		s0 = s;
		std::cin >> s;
		if (s0.back() == s[0]) {
			if (m[s] == 0) {
				m[s] = 1;
			}
			else {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
		else {
			std::cout << "No" << std::endl;
			return 0;
		}
	}

	std::cout << "Yes" << std::endl;

	return 0;
}

Measured memory_bytes: 256
import math
def naive_cmb(n, r):
    if r < 0 or r > n:
        return 0
    return (math.factorial(n) // math.factorial(r)) // math.factorial(n-r)

N, P = map(int, input().split())
A = list(map(lambda x: x%2, list(map(int, input().split()))))

ans = 0
a = A.count(1)
b = A.count(0)

if P == 1:
    for i in range(1, a+1, 2):
        ans += naive_cmb(a, i)
    ans *= 2**b
else:
    for i in range(0, a+1, 2):
        ans += naive_cmb(a, i)
    ans *= 2**b

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  int h, w;

  while(1){
    cin >> h >> w;
    if(h == 0 && w == 0){ break; }
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(i==0 || i==h-1 || j==0 || j==w-1){
	  cout << '#';
	}
	else{
	  cout << '.';
	}
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3088
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#endif

#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;

int main(){
	fastIO;
	int n;
	cin >> n;
	map<string, int> mp;
	while (n--)
	{
		string temp;
		cin >> temp;
		mp[temp]++;
	}
	vector<string> cmx;
	int mx = 0;
	for (auto& i : mp) {
		if (i.second > mx) cmx.erase(all(cmx)), mx = i.second, cmx.pb(i.first);
		else if (i.second == mx) cmx.pb(i.first);
	}
	for (const auto& i : cmx)
	{
		cout << i << endl;
	}
	return 0;
}



Measured memory_bytes: 27252
int main(int argc, const char * argv[]) {
    int n,m,i,j,s,k,w;
    scanf("%d %d",&n,&m);
    int a[100][100]={0};
    for (i=0;i<n; i++) {
        for (j=0; j<m; j++) {
            scanf("%d ",&a[i][j]);
        }
    }
    int b[100]={0};
    for (s=0; s<m; s++) {
        scanf("%d", &b[s]);
    }
    int c[100] = {0};
    for (k=0; k<n; k++) {
        for (w=0; w<m; w++) {
            c[k]+=a[k][w]*b[w];
            
        }
        
        printf("%d\n", c[k]);
        
    }
    
    
   
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main(){
    ll h, w;
    cin >> h >> w;
    ll ans = h * w;
    rep(_, 2){
        for(int i = 1; i < h; i++){
            ll s1 = i * w;
            ll s2 = (h - i) / 2 * w;
            ll s3 = h * w - s1 - s2;
            ll smax = max(s1, max(s2, s3));
            ll smin = min(s1, min(s2, s3));
            ans = min(ans, smax - smin);

            s2 = (h - i) * (w / 2);
            s3 = h * w - s1 - s2;
            smax = max(s1, max(s2, s3));
            smin = min(s1, min(s2, s3));
            ans = min(ans, smax - smin);
        }
        swap(h, w);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){

	int a,b;
	cin >> a >> b;
	for(int i = 1;i <= 2000;i++){
		if((i * 8)/100 == a && i / 10 == b){
			cout << i;
			return 0;
		}
	}
	cout << -1;
	return 0;
}


Measured memory_bytes: 384
n = int(input())
a = [int(i) for i in input().split()]
def gcd(p,q):
    if p%q: return gcd(q,p%q)
    else: return q
if n==2: print(max(a))
else:
    num,x,num2 = a[2],[],gcd(a[0],a[1])
    for i in range(3,n): num = gcd(num,a[i])
    ans = max(gcd(num,a[0]),gcd(num,a[1]))
    for i in range(1,int(num2**0.5)+1):
        if num2%i==0:
            x.append(i)
            if i**2!=num2: x.append(num2//i)
    x = sorted(x)[::-1]
    for i in x:
        m = 0
        for j in a[2:]:
            if j%i: m+=1
            if m>1: break
        if m<2: break
    print(max(ans,i))

Measured memory_bytes: 14400
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vb=vector<bool>;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct loop_t
{
	vll c_sum;
	vll c_max;
	vll c_rmax;

void dump(void)
{
	int n=c_sum.size();
	for(int i=0;i<n;i++)
	{
		cout << "(" << c_sum[i] << "," << c_max[i] << "," << c_rmax[i] << ")";
	}
	cout << "\n";
}
};


template <typename X>
struct btmax_t
{
	vector<X> t;
	int base;
	btmax_t(int n)
	{
		for(base=1;base<n;base*=2)
			;
		t.resize(base*2);
	}
	btmax_t(int n, X x)
	{
		for(base=1;base<n;base*=2)
			;
		t.resize(base*2, x);
	}
	void seti(int idx)
	{
		if(idx<=0) return;

		if(t[idx*2]<t[idx*2+1]) t[idx]=t[idx*2+1];
		else t[idx]=t[idx*2];

		seti(idx/2);
	}
	void set(int idx, const X&v)
	{
		int y=idx+base;
		t[y]=v;
		seti(y/2);
	}
	X get(void)
	{
		return t[1];
	}
};


template<typename X>
void dump(vector<X>&v)
{
	for(auto&m:v) cout << m << " ";
	cout << "\n";
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		int n, k;
		cin >> n >> k;
		if(cin.fail()) break;
		vi p(n+1);
		vll c(n+1);
		for(int i=1;i<=n;i++) cin >> p[i];
		for(int i=1;i<=n;i++) cin >> c[i];

		ll ans=c[1];
		vb is_passed(n+1, false);

		for(int i=1;i<=n;i++)
		{
			if(is_passed[i]) continue;
			int cp=i;
			int g_num=1;
			for(int j=0;j<=n;j++)
			{
				if(is_passed[cp])
				{
					g_num=j;
					break;
				}
				is_passed[cp]=true;
				cp=p[cp];
			}

			vll sum={c[cp]};
			ll sum_min=sum.back();
			for(int j=1;j<g_num*3;j++)
			{
				cp=p[cp];
				sum.push_back(sum.back()+c[cp]);
				min_u(sum_min, sum.back());
			}
//dump(sum);
			int loop_num=max(0, (int)k/g_num-1);
			ll ans_add=sum[g_num-1]*loop_num;
			if(ans_add<0) ans_add=0;

			int chk_size=k-loop_num*g_num;
			btmax_t<ll> t(chk_size, sum_min);
			for(int j=0;j<chk_size;j++)
			{
				t.set(j, sum[j]);
			}
			for(int j=0;j<g_num;j++)
			{
				t.set(j%chk_size, sum[chk_size+j]);
				max_u(ans, t.get()-sum[j]+ans_add);
			}
//printf("loop_num=%d  g_num=%d  ans_add=%lld\n", loop_num, g_num, ans_add);
		}

		cout << ans << "\n";
	}
	return 0;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    ll n;
    vector<ll> A(5);
    
    cin >> n;

    for(auto &i: A)
        cin >> i;

    ll mn=*min_element(A.begin(),A.end());

    cout << 5+(n-1)/mn << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
int N, W;
int dp[100010];
int a[100010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> a[i];
    
    for(int i=0; i<N; ++i) dp[i]=1e9;
    
    for(int i=0; i<N; ++i){
        *lower_bound(dp, dp+N, a[i]) = a[i];
    }
    cout << lower_bound(dp, dp+N, 1e9) - dp << endl;
    
	return 0;
}


Measured memory_bytes: 4000
N,M = list(map(int,input().split()))
Map = [[] for i in range(N)]
for i in range(M):
    a,b=list(map(int,input().split()))
    Map[a-1].append(b-1)

b_list = [0 for i in range(N)]
count=0   
for i in range(N):
    if b_list[i]==1:
        b_list=[0 for i in range(N)]
        count+=1
    for j in Map[i]:
        b_list[j]=1

print(count)

Measured memory_bytes: 25916