akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <math.h>
typedef long long ll;

using namespace std;

int main()
{
	int n;
	int fn=0;
	int k;
	int nn=0;
	
	cin>>n;
	nn=n;
	k=pow(10,(int)log10(n));
	while(n>=10)
	{
		fn += n/k;
		n = n%k;
		k/=10;
	}
	fn += n;
	if(nn%fn==0)
	{
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
import sys

def resolve():
    N, M, X = list(map(int, input().split(" ")))
    A = list(map(int, input().split(" ")))
    pos = X
    costN = 0
    while True:
        if pos == N: 
            break
        pos += 1
        if pos in A:
            costN += 1
    pos = X
    cost0 = 0
    while True:
        if pos == 0: 
            break
        pos -= 1
        if pos in A:
            cost0 += 1
    print(min(cost0, costN))

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38256
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main()
{
	int N, M, count[110] = { 0 };
	int a[100], b[100];
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &a[i], &b[i]);
		count[a[i]]++;
		count[b[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		printf("%d\n", count[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n, t, a; cin >> n >> t >> a;
    int ans;
    double Min = 100000000;
    rep(i,n) {
        double h; cin >> h;
        h = (double) t-h*0.006; // 平均気温
        double Abs = abs(h-a);
        if (Abs < Min)
        {
            Min = Abs;
            ans = i;
        }
    }
    cout << ++ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
n=int(input())
E=[[] for _ in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    E[a].append([b,i])
    E[b].append([a,i])
k=0
for e in E:
    k=max(k,len(e))
ans=[0]*(n-1)
def dsf(v,p,vp_c):
    c=1
    for u,i in E[v]:
        if u!=p:
            if c==vp_c:
                c+=1
            ans[i]=c
            dsf(u,v,c)
            c+=1
dsf(1,0,0)
print(k)
for i in range(n-1):
    print(ans[i])

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

int main(){
int a,b;
cin >> a >> b;
if (a==0 && b<=99)cout << b << endl;
if (a==0 && b==100)cout << 101 << endl;
if (a==1 && b<=99)cout << b*100 << endl;
if (a==1 && b==100)cout << 10100 << endl;
if (a==2 && b<=99)cout << b*10000 << endl;
if (a==2 && b==100)cout << 1010000 << endl;
}


Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-17 19:37:35
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=610,mod=1000000007;
i64 n,k,t[N],f[N][N],g[N][N],ans,s[N];
int main()
{
	n=read()*2; k=read();
	fr(i,1,k){ int a=read(),b=read(); t[a]=b; t[b]=a; }
	s[0]=1;
	fr(i,1,n/2) s[i*2]=s[(i-1)*2]*(i*2-1)%mod;
	fd(i,n,1) fr(j,i+1,n)
	{
		int l=j-i+1;
		fr(k,i,j) if(t[k])
		{
			if(t[k]<i||t[k]>j) l=-1;
			if(l>=0) l--;
		}
		if(l==-1||l%2) continue;
		f[i][j]=s[l]; g[i][j]=l;
		fr(k,i,j-1) f[i][j]=(f[i][j]-f[i][k]*s[g[k+1][j]]%mod+mod)%mod;
	}
//	fr(i,1,n) fr(j,1,n) printf("%d%c",int(f[i][j]),j==n?'\n':' ');
	fr(i,1,n) fr(j,i,n) ans+=f[i][j]*s[n-(j-i+1)-(k-(j-i+1-g[i][j])/2)*2]%mod;
	printf("%d\n",int(ans%mod));
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
const int N = 10000;
bool v[N];
int main() {
    int X;
    cin >> X;
    for(int i = 1; i < 1e5; i++) {
        if(100 * i <= X && X <= 105 * i) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

class Combination:
    """
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv
n,k = inpl()
m = min(n-1,k)
res = 1
if m == 1:
    print((n-1)*n%mod)
    quit()
comb = Combination(n+10)
for i in range(m):
    res += comb(n,i+1) * comb(n-1,n-i-2)
    res %= mod
print(res)

Measured memory_bytes: 94060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const double INF = 1e9;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号


int main(){
	double a,b;
	string rnk[]={"AAA","AA","A","B","C","D","E","NA"};
	double m5[]={35.5,37.5,40.0,43.0,50.0,55.0,70.0,INF};
	double m10[]={71.0,77.0,83.0,89.0,105.0,116.0,148.0,INF};
	vector<string>res;
	while(cin>>a>>b){
		REP(i,8){
			if(a<m5[i]&&b<m10[i]){
				res.PB(rnk[i]);
				break;
			}
		}
	}
	REP(i,SZ(res))cout<<res[i]<<endl;
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
    
typedef long long ll;
typedef unsigned long long ull;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    if(s[1]=='B')
        cout<<"ARC";
    else if(s[1]=='R')
        cout<<"ABC";
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
bool isincluded(char x, string str) {
	bool f = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str.at(i) == x)f = 1;
	}
	return f;
}

int main(void)
{
	int n, a, b; cin >> n >> a >> b;
	cout << min(a * n, b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

int i;
int a,b,c;
int ans=0;

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

for(i=a;i<=b;i++){
if(c%i==0){
ans++;
}
}
printf("%d\n",ans);

return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<iomanip>
#include<cmath>

int const MAXN = 50;

int x[MAXN], y[MAXN], N;

bool check(double x1, double y1, double r) {
  for(int i = 0; i < N; ++i) {
    double xx = x1 - x[i], yy = y1 - y[i];
    if((xx*xx+yy*yy)/(r*r) >= 1+1e-12) return false;
  }
  return true;
}

bool calc_intersect(int i, int j, double r, double& xx, double& yy, double& dx, double& dy) {
  double vx = x[j] - x[i],  vy = y[j] - y[i];
  double h2 = r*r - (vx*vx + vy*vy)*0.25;
  if(h2 < 0.0) return false;
  xx = 0.5*(x[i]+x[j]); yy = 0.5*(y[i]+y[j]);
  double ratio = sqrt(h2/(vx*vx+vy*vy));
  dx =  ratio*vy;
  dy = -ratio*vx;
  return true;
}

bool check(double r) {
  for(int i = 0; i < N-1; ++i) for(int j = i+1; j < N; ++j) {
    double xx, yy, dx, dy;
    if(calc_intersect(i, j, r, xx, yy, dx, dy)) {
      if(check(xx+dx, yy+dy, r)) return true;
      if(check(xx-dx, yy-dy, r)) return true;
    }
  }
  return false;
}

double calc() {
  double dL = 0.0, dH = 750.0; // > 500*sqrt(2)
  while(dH - dL>1e-9 && (1.0 - dL/dH) > 1e-9) {
    double dM = (dL + dH)*0.5;
    if(check(dM)) dH = dM;
    else dL = dM;
  }
  return (dL + dH)*0.5;
}

int main() {
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> x[i] >> y[i];
  double ans;
  if(N == 2) {
    double dx = x[0] - x[1], dy = y[0] - y[1];
    ans = std::sqrt(dx*dx + dy*dy)*0.5;
  } else ans = calc();
  std::cout << std::setprecision(10) << std::fixed << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input()) #入力回数を決める
temp_list = [int(x) for x in input().split()]
temp_list.append(0)

abs_list = []

for i in range(n):
    i += 1
    abs_list.append(abs(sum(temp_list[i:]) - sum(temp_list[:i])))

print(min(abs_list))


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

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

    vector<vector<int> > v(n);
    pair<int, int> p[n - 1];
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(a < b){
            p[i].first = a;
            p[i].second = b;
        }else{
            p[i].first = b;
            p[i].second = a;
        }
        v[p[i].first].push_back(p[i].second);
        v[p[i].second].push_back(p[i].first);
    }

    int max = -1;
    int poj = -1;

    for(int i = 0; i < n; i++){
        int t = v[i].size();
        if(t > max){
            max = t;
            poj = i;
        }
    }

    cout << max << endl;

    queue<int> q;
    q.push(poj);
    map<pair<int, int>, int> m;
    int flag[n], che[n];
    for(int i = 0; i < n; i++){
        flag[i] = 0;
        che[i] = 0;
    }

    che[poj] = 1;

    while(!q.empty()){
        int t = q.front();
        q.pop();
        int cou = 1;
        for(int i = 0; i < v[t].size(); i++){
            if(che[v[t][i]] == 0){
                che[v[t][i]] = 1;
                if(t < v[t][i]){
                    if(flag[t] == 0){
                        m[make_pair(t, v[t][i])] = cou;
                        flag[v[t][i]] = cou;
                    }else{
                        if(cou != flag[t]){
                            m[make_pair(t, v[t][i])] = cou;
                            flag[v[t][i]] = cou;
                        }else{
                            cou++;
                            m[make_pair(t, v[t][i])] = cou;
                            flag[v[t][i]] = cou;
                        }
                    }
                }else{
                    if(flag[t] == 0){
                        m[make_pair(v[t][i], t)] = cou;
                        flag[v[t][i]] = cou;
                    }else{
                        if(cou != flag[t]){
                            m[make_pair(v[t][i], t)] = cou;
                            flag[v[t][i]] = cou;
                        }else{
                            cou++;
                            m[make_pair(v[t][i], t)] = cou;
                            flag[v[t][i]] = cou;
                        }
                    }
                }
                q.push(v[t][i]);
                cou++;
            }
        }
    }

    for(int i = 0; i < n - 1; i++){
        auto itr = m.find(p[i]);
        cout << itr->second << endl;
    }  
}

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

int main() {
    vector<char> c;
    string s;
    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0' || s[i] == '1') {
            c.push_back(s[i]);
        } else if (s[i] == 'B') {
            if (c.empty() != true) c.pop_back();
        }
    }
    for (int i = 0; i < c.size(); i++) {
        cout << c[i];
    }
    cout << endl;
}


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

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

  vector<int> b;

  if (n % 2 == 0) {
    for (int i = n-1; i > 0; i-=2) {
      b.push_back(a[i]);
    }

    for (int i = 0; i < n; i+=2) {
      b.push_back(a[i]);
    }
  } else {
    for (int i = n-1; i >= 0; i-=2) {
      b.push_back(a[i]);
    }

    for (int i = 1; i < n; i+=2) {
      b.push_back(a[i]);
    }
  }

  for (int i = 0; i < n; ++i) {
    printf("%d ", b[i]);
  }
}

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

using namespace std;
const int INF = 1000000000;

int dp[51][51][51];

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n), c(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i] >> b[i] >> c[i];
	}
	for(int i = 0; i < 51; ++i){
		for(int j = 0; j < 51; ++j){
			for(int k = 0; k < 51; ++k){ dp[i][j][k] = -INF; }
		}
	}
	dp[0][0][0] = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j <= m; ++j){
			for(int k = 0; k <= 8; ++k){
				int prev = dp[i][j][k];
				for(int l = 0; l <= 8 && l + j <= m; ++l){
					int add = c[i];
					if(l > 0){
						add = max(add, a[i] * l);
						add = max(add, a[i]);
					}
					if(k > 0){
						add = max(add, b[i] * k);
						add = max(add, b[i]);
					}
					if(l + k > 0){
						add = max(add, a[i] * l + b[i] * min(8 - l, k));
						add = max(add, a[i] * min(8 - k, l) + b[i] * k);
					}
					dp[i + 1][j + l][l] =
						max(dp[i + 1][j + l][l], prev + add);
				}
			}
		}
	}
	int answer = -INF;
	for(int i = 0; i <= m; ++i){
		for(int j = 0; j <= m; ++j){
			answer = max(answer, dp[n][i][j]);
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1716
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);
	ll n,m,k;
	cin>>n>>m>>k;
	ll x,y,z;
	ll arr[n],brr[m];
	vector<ll> v1,v2;
	for(int a=0;a<n;a++)
	cin>>arr[a];
	for(int a=0;a<m;a++)
	cin>>brr[a];
	v1.push_back(arr[0]);
	v2.push_back(brr[0]);
	for(int a=1;a<n;a++)
	v1.push_back(arr[a]+v1.back());
	for(int a=1;a<m;a++)
	v2.push_back(brr[a]+v2.back());
	ll ans=0;
	for(int a=0;a<n;a++)
	{
		if(v1[a]<=k)
		{
			x=a+1;
			y=k-v1[a];
			z=upper_bound(v2.begin(),v2.end(),y)-v2.begin();
			x+=z;
			ans=max(ans,x);	
		}
	}
	for(int a=0;a<m;a++)
	{
		if(v2[a]<=k)
		{
			x=a+1;
			y=k-v2[a];
			z=upper_bound(v1.begin(),v1.end(),y)-v1.begin();
			x+=z;
			ans=max(ans,x);	
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11032
INF = 10 ** 10


def merge(A, left, mid, right):
    count = 0
    L = A[left:mid] + [INF]
    R = A[mid:right] + [INF]

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return count


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        countL = merge_sort(A, left, mid)
        countR = merge_sort(A, mid, right)
        return merge(A, left, mid, right) + countL + countR
    return 0


N = int(input())
A = list(map(int, input().split()))
count = merge_sort(A, 0, N)
A = list(map(str, A))
print(' '.join(A))
print(count)


Measured memory_bytes: 64400
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vll a(n);
    rep(i, n) cin >> a[i];
    vll d(n,0);
    vll d2(n,0);
    vll dco(n,0);
    ll point=1;
    ll count=0;
    while(true){
        ll next=a[point-1];
        if(d[next-1]==1){
            k-=d2[next-1];
            ll p=count-d2[next-1]+1;
            k%=p;
            cout << dco[k+d2[next-1]-1] << endl;
            return 0;
        }else if(count==k){
            cout << point << endl;
            return 0;
        }else{
            count++;
            d2[next-1]=count;
            d[next-1]=1;
            dco[count-1]=next;
            point=next;
        }
    }
}

Measured memory_bytes: 9596
import bisect

N = int(input())
A = sorted([int(i) for i in input().split()])

zp = bisect.bisect_left(A, 0)
ans = []

M = A[0]
for i in range(max(zp, 1), N-1):
    ans.append((M, A[i]))
    M -= A[i]

ans.append((A[N-1], M))
M = A[N-1]-M

for i in range(1, min(zp, N-1)):
    ans.append((M, A[i]))
    M -= A[i]


print(M)
for a, b in ans:
    print(a, b)


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int X = A + B, Y = C + D;

  if (X > Y) cout << "Left" << endl;
  else if (X == Y) cout << "Balanced" << endl;
  else if (X < Y) cout << "Right" << endl;
}
  


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e3+17;
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif
    int n,k;
    cin>>n>>k;
    LL ans = 0;
    if(k==0) return cout<<1LL*n*n<<endl,0;
    for (int i = k+1; i <= n; ++i)
    {
    	int x = n/i;
    	if(i>k) 
    		ans += x*(i-k)+max(n%i-k+1,0);
    	// debug(i);
    	// debug(x);
    	// debug(ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
cin = open(0).read().strip().split('\n')
n,m,x = map(int, cin[0].split(' '))
books = []
for i in cin[1:]:
    books.append(tuple(map(int, i.split(' '))))

money = float('inf')
for i in range(2**n):
    ret = [0] * m
    tmp_money = 0
    for j in range(n):
        if i >> j & 1:
            for mi in range(m):
                ret[mi] += books[j][1+mi]
            tmp_money += books[j][0]
    if min(ret) >= x:
        money = min(money, tmp_money)

if money == float('inf'):
    print(-1)
else:
    print(money)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#include <queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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


int main() {
	int a;
	cin >> a;
	if (a % 1000 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1000 - a % 1000 << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  string s;
  cin >> s;
  bool flag = true;
  rep(i, s.size()) {
    if(i % 2 == 0 && s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D') flag = false;
    else if(i % 2 != 0 && s.at(i) != 'L' && s.at(i) != 'U' && s.at(i) != 'D') flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  

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

int main() {
  long long K, Sum=0;
  cin >> K;
  rep(i,K){
    rep(j,K){
      rep(l,K){
        Sum+=gcd(i+1, gcd(j+1,l+1));
      }
    }
  }
  cout << Sum << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define it vector<int>::iterator
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		vvi in(n,vi(m));
		rep(i,n){
			int co=0;
			rep(j,m){
				char d;
				cin>>d;
				if(d=='.'){
					co++;
					in[i][j]=co;
				}else{
					co=0;
					in[i][j]=0;
				}
			}
		}
		int ma=0;
		rep(i,n)rep(j,m){
			int t=inf;
			loop(k,i,n){
				t=min(t,in[k][j]);
				if(!t)break;
				ma=max(ma,t*(k-i+1));
			}
		}
		cout<<ma<<endl;
	}
}

Measured memory_bytes: 2128
from math import floor

N, K = map(int, input().split())

if K == 0:
    print(N * N)
    exit()

ans = 0
for b in range(1, N + 1):
    # [1, N]をbで割る
    num = N // b
    rem = N % b
    # numの中がK以上である個数
    # あまり: 0, 1, 2, ..., b - 1
    fact = b - 1 - K + 1
    if fact > 0:
        ans += num * fact
    
    # 残った分
    ans += max(0, rem - K + 1)
    # print(b, num, rem, num * fact, rem)
print(ans)

Measured memory_bytes: 40560
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

string S;

signed main(){
	cin>>S;
	REP(i,S.size()-1){
		if(S[i]==S[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
	}
	REP(i,S.size()-2){
		if(S[i]==S[i+2]){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<-1<<" "<<-1<<endl;
	return 0;
}


Measured memory_bytes: 512
use v5.18;
use warnings;
sub read_line { chomp(my $s = <>); $s }
use List::Util qw( sum0 );
sub splited_read_line { split / /, read_line }

my $N = read_line;
say sum0 map {
  my ($x, $u) = splited_read_line;
  $u eq 'BTC' ? $x * 380000 : $x;
} 0 .. $N - 1;


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

INF = 10**9

def solve(N: int, A: int, B: int, C: int, l: "List[int]"):
    def how_much_mp(cur, a, b, c):
        if cur == N: # 竹の材料が無でない
            return abs(A-a) + abs(B-b) + abs(C-c) -30 if min(a, b, c) > 0 else INF
        costs = []
        costs.append(how_much_mp(cur+1, a, b, c))
        costs.append(how_much_mp(cur+1, a+l[cur], b, c) + 10)
        costs.append(how_much_mp(cur+1, a, b+l[cur], c) + 10)
        costs.append(how_much_mp(cur+1, a, b, c+l[cur]) + 10)
        return min(costs)
    print(how_much_mp(0, 0, 0, 0))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    l = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C, l)

if __name__ == '__main__':
    main()


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


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

Measured memory_bytes: 3600
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	int A, B, C;
	string S;
	cin >> A >> S;
	if (A >= 3200) {
		cout << S;
	}
	else cout << "red";
}

Measured memory_bytes: 256
/* "It's okay if you hate me. I hate me too." */

#include <bits/stdc++.h>

using namespace std;

int a[100005];
int n;

long long calc(int MOD) {
	long long sum = 0, res = 0;
	for (int i = 1; i <= n; ++i)  {
		sum += a[i];
		if (i%2 == MOD && sum <= 0) {
			res += (1-sum);
			sum = 1;
		}
		else if (i%2 != MOD && sum >= 0) {
			res += (sum+1);
			sum = -1;
		}
	}
	return res;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) 
		scanf("%d", &a[i]);
	cout << min(calc(0), calc(1));
	return 0;
}

Measured memory_bytes: 640
Q = int(input())
l, r = [], []
for i in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
max_r = max(r)

is_sosu = [1] * (max_r + 1)
is_sosu[0] = is_sosu[1] = 0
for i in range(2, max_r+1):
    if is_sosu[i]:
        for j in range(i*i, max_r+1, i):
            is_sosu[j] = 0

sums = [0] * (max_r + 1)
for i in range(1, max_r+1):
    if is_sosu[i] and is_sosu[(i+1)//2]:
        sums[i] = sums[i-1] + 1
    else:
        sums[i] = sums[i-1]

for i in range(Q):
    print(sums[r[i]] - sums[l[i]-1])


Measured memory_bytes: 13352
#include<cstdio>
int main()
{
	int a[4],c[4][4];
	for(int i=1;i<=3;i++)
	for(int j=1;j<=3;j++) scanf("%d",&c[i][j]);
	for(a[1]=0;a[1]<=100;a[1]++)
	for(a[2]=0;a[2]<=100;a[2]++)
	for(a[3]=0;a[3]<=100;a[3]++)
	{
		int f=1;
		for(int i=1;i<=3;i++)
		{
			int b=c[1][i]-a[1];
			if(b!=c[2][i]-a[2]||b!=c[3][i]-a[3]) f=0;
		}
		if(f) return printf("Yes\n"),0;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;

namespace AtCoder_practice0801
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            Console.WriteLine(CountOf(S, "ABC"));

        }

        public static int CountOf(string target, params string[] strArray)
        {
            int count = 0;

            foreach (string str in strArray)
            {
                int index = target.IndexOf(str, 0);
                while (index != -1)
                {
                    count++;
                    index = target.IndexOf(str, index + str.Length);
                }
            }

            return count;
        }
    }
}


Measured memory_bytes: 27544
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 n;
int A,B,C;
vector<int>l;
const int INF = 1001001001;
int dfs(int i,int a,int b,int c) {
    int res = INF;
    if(i==n) {
        int res = 0;
        if(a && b && c) {
            res += abs(a-A)+abs(b-B)+abs(c-C);
        } else res = INF;
        return res;
    }
    int res1,res2,res3,res4;
    if(a==0) res1 = dfs(i+1,a+l[i],b,c);
    else  res1 = dfs(i+1,a+l[i],b,c) + 10;

    if(b==0) res2 = dfs(i+1,a,b+l[i],c);
    else  res2 = dfs(i+1,a,b+l[i],c) + 10;

    if(c==0) res3 = dfs(i+1,a,b,c+l[i]);
    else  res3 = dfs(i+1,a,b,c+l[i]) + 10;
    res4 = dfs(i+1,a,b,c);
    res = min({res1,res2,res3,res4});
    return res;
}

int main() {
    cin >> n >> A >> B >> C;
    l.resize(n);
    rep(i,n) cin >> l[i];
    int ans = dfs(0,0,0,0);
    cout << ans << endl;
}

Measured memory_bytes: 3588
def p_l_2():
    n = int(input())
    *a, = map(int, input().split())
    # dp[i][j]は区間[i,j]が残っているときの最大化
    dp = [[-1] * n for _ in range(n)]

    for i in range(n):
        for l in range(n - i):
            r = l + i
            if l == r:
                dp[l][r] = a[l]
            else:
                dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1])
    print(dp[0][n - 1])


if __name__ == '__main__':
    p_l_2()


Measured memory_bytes: 114012
// finish date: 2018/03/17

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    vl a(N);
    ll maxVal = -LONG_LONG_MAX;
    int maxIndex;
    rep(i, N) {
        cin >> a[i];
        if (maxVal < a[i]) {
            maxVal = a[i];
            maxIndex = i;
        }
    }
    if (N == 2) {
        cout << max(a[0], a[1]) << endl;
        cout << 1 << endl;
        if (a[0] > a[1]) cout << 2 << endl;
        else cout << 1 << endl;
        return 0;
    }
    if (maxVal <= 0) {
        cout << maxVal << endl;
        cout << N - 1 << endl;
        for (int i = N; i >= maxIndex + 2; i--) {
            cout << i << endl;
        }
        rep(i, maxIndex) {
            cout << 1 << endl;
        }
        return 0;
    }


    ll oddMax = 0;
    ll evenMax = 0;
    rep(i, N) {
        if (i % 2 == 0) oddMax += max(a[i], (ll) 0);
        else evenMax += max(a[i], (ll) 0);
    }
    vi operate;
    int l, r;
    if (oddMax > evenMax) l = 0;
    else {
        operate.emplace_back(0);
        l = 1;
    }
    r = l + 1;

    while (l + 1 < N) {
        if (r + 1 >= N) {
            operate.emplace_back(1);
            break;
        }
        if (a[l] < 0) {
            operate.emplace_back(0);
            operate.emplace_back(0);
            l += 2;
            r = l + 1;
        } else if (a[r + 1] < 0) {
            operate.emplace_back(2);
            if (r + 2 >= N) {
                operate.emplace_back(1);
                break;
            }
            r += 2;

        } else {
            operate.emplace_back(1);
            a[r + 1] += a[l];
            l = r + 1;
            r = l + 1;
        }

    }

    cout << max(evenMax, oddMax) << endl;
    cout << operate.size() << endl;
    rep(i, operate.size()) {
        cout << operate[i] + 1 << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#define rep(i,j,k) for(register int i = j; i <= k; i++) 
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define fi first
#define se second
//#define P pair<ull,ull>
//#define PP pair<int,pair<int,int> >
//#define mp(a,b) make_pair(a,b)
#define ll long long
#define ull unsigned long long
using namespace std;
 
inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 1e5+5, p = 1e9+7;
struct edge{ int to, nxt; } e[N];
int f[N], g[N], deg[N], head[N], cnt = 0; 
inline void add(int x,int y) { 
	deg[x]++;
	e[++cnt].to = y, e[cnt].nxt = head[x], head[x] = cnt; 
}

#define ez(i,j) for(register int i = head[j]; i; i=e[i].nxt)
#define to e[i].to
inline void dfs(int x) { 
	if( !deg[x] ) return;
	int len = 0, y = 0;
	ez(i,x) dfs(to);
	ez(i,x) g[++len] = f[to];
	sort(g+1,g+len+1);
	rep(i,1,len) y = max(y+1,g[i]+1);
	f[x] = y;
}

int main() {
	int n = read();
	rep(i,2,n) add(read(),i);
	dfs(1);
	cout<<f[1]<<endl;
	return 0; 
}

Measured memory_bytes: 4736
N = int(input())
p = list(map(int, input().split()))

count = 0; p_sorted = sorted(p)
for i in range(N):
    if p[i] != p_sorted[i]:
        count += 1
    
if count == 2 or count == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  int n,l[256],x,y,z;
  while(scanf("%d",&n),n){
    rep(i,n)scanf("%d",&l[i]);
    
    double m = 1e9;
    rep(s,16)rep(a,16)rep(c,16){
      int u[256] = {0};
      
      int r = s;
      rep(i,n){
	r = (a*r + c)&255;
	u[(r + l[i])&255]++;
      }
      
      double tmp = 0;
      rep(i,256)if(u[i]){
	tmp -= u[i]*log((double)u[i]/n);
	if(m + 1e-9 < tmp)break;
      }
      if(m > tmp + 1e-9){ m = tmp; x = s; y = a; z = c; }
    }
    printf("%d %d %d\n",x,y,z);
  }
}

Measured memory_bytes: 1068
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    bool st[30];

    for (int i = 0; i < 30; i++) st[i] = false;

    for (int i = 0; i < 28; i++) {
        int n;
        cin >> n;
        st[n-1] = true;
    }

    for (int i = 0; i < 30; i++) {
        if (!st[i]) cout << i+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 0
import java.io.*;

class Main {
    
    public static int num = 0;
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int it = Integer.parseInt(br.readLine());
        String str = br.readLine();
        String[] strarr = str.split(" ", it);
        
        int[] array = new int[it];
        for(int i=0; i<it; i++) {
            array[i] = Integer.parseInt(strarr[i]);
        }
        
        bubbleSort(array, it);
        trace(array, it);
    }
    
    static void trace(int[] A, int N) {
        for(int i=0; i<N-1; i++) {
            System.out.printf("%d ", A[i]);
        }
        System.out.println(A[N-1]);
        System.out.println(num);
    }
    
    static void bubbleSort(int[] A, int N) {
        boolean flag = true;
        while(flag) {
            int j = 0;
            flag = false;
            for(int i=N-1; i>j; i--) {
                int v = A[i];
                if(A[i] < A[i-1]) {
                    A[i] = A[i-1];
                    A[i-1] = v;
                    flag = true;
                    num++;
                }
            }
            j++;
        }
    }
    
}


Measured memory_bytes: 24836
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int main(){
    LL N, x;
    cin >> N >> x;
    vector<LL> a(N+1);
    a[0] = 0;
    LL ans = 0;
    for(int i = 1;i <= N;i++)    cin >> a[i];
    for(int i = 1;i <= N;i++){
        LL sum = a[i-1]+a[i];
        if(sum > x){
            ans += sum-x;
            a[i] -= sum-x;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll par[ll(1e5+5)],Rank[ll(1e5+5)];
ll N;
// 要素Nで初期化
void init(){
  rep(i,N){
    par[i]=i;
    Rank[i]=0;
  }
}
ll root(ll x){
  return par[x]==x ? x : par[x]=root(par[x]);
}
bool same(ll x,ll y){
  return root(x)==root(y);
}
void unite(ll x,ll y){
  x=root(x);y=root(y);
  if(x==y)return;
  if(Rank[x]<Rank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(Rank[x]==Rank[y])Rank[x]++;
  }
}

int main(){
  ll ans=0;
  ll M;cin>>N>>M;
  init();
  vector<ll> p(N);
  rep(i,N){
    cin>>p[i];
  }
  ll x,y;
  rep(i,M){
    cin>>x>>y;
    unite((x-1),(y-1));
  }
  rep(i,N){
    ans+=same(i,p[i]-1);
  }
  cout<<ans<<endl; 
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>

using namespace std;

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  string S[6];
  for(int i=0; i<H; i++) {
    cin >> S[i];
  }

  int ans = 0;

  // Try 2^H times
  for (int a = 0; a < (1 << H); a++) {

    // Try 2^W times
    for (int b = 0; b < (1 << W); b++) {
      int cnt = 0;

      for (int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
          if ( (((a >> i) & 1) == 0 ) && ((( b >> j ) & 1) == 0) && S[i][j] == '#' ) {
            cnt++;
          }
        }
      }

      if (cnt == K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  vector<P> m[n];
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    for(int j=0; j<a; j++){
      int x, y;
      cin >> x >> y;
      x--;
      m[i].push_back(make_pair(x, y));
    }
  }
  int c = 1<<n;
  int ans = 0;
  for(int i=1; i<c; i++){
    int tmp = 0;
    bool ok = true;
    for(int bit=0; bit<n; bit++){
      if(!ok) break;
      if(i&(1<<bit)){
        tmp++;
        if(m[bit].size()==0) continue;
        for(int j=0; j<m[bit].size(); j++){
          P p = m[bit][j];
          if((i>>p.first)&1^p.second){
            ok = false;
            break;
          }
        }
      }
    }
    if(ok){
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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


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

    string s, p; cin >> s >> p;
    s += s;

    if(s.find(p) != string::npos) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3220
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,avx2,tune=native")
//#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/rope>

using namespace __gnu_pbds; 
using namespace __gnu_cxx;
using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("output.txt","w",stderr);
    #endif
}
template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

clock_t time_p=clock();
void printTime(){
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}


const int N = 2e5 + 5;

int main() {
    io();
    ll k;
    cin >> k;
    ll sum = 0;
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= k; j++) {
            for(int l = 1; l <= k; l++) {
                sum += __gcd(l, __gcd(i, j));
            }
        }
    }
    cout << sum;
}




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

string p(int n,int d){
	string r;
	for(int i = 0 ; i < d ; i++){
		r = ( string(1,n % 2 + '0') + r) ; n/=2;
	}
	return r;
}
int main(){
	double r;
	while(cin >> r && r >= 0.0){
		int n = r;
		bool f = true;
		int s = (r-n)*16;
		if((r-n)*16 != s) f = false;
		f &= s < 16;
		f &= n < 256;
		if(f)cout << p(n,8) << "." << p(s,4) << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
k = int(input())
l = reversed(list(map(int, input().split())))
lo,hi = 2,2
for a in l:
  nl = lo + (a - lo%a)%a
  nh = (hi//a)*a + a-1
  if nl > nh: print(-1); exit(0)
  lo,hi = nl,nh
print(lo,hi)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int x,y,m,n,he;
int main()
{
    cin>>x>>y>>m>>n;
    for(int i=0;i<=x;i++)
    {
     	for(int j=0;j<=y;j++)
        {
      		if((n-i*500-j*100>=0)&&(n-i*500-j*100<=m*50)) 
            	{
            		he++;
                }
        }
    }
    cout<<he;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;

template <typename tn> void read (tn & a) {
	tn x = 0, f = 1; char c = getchar();
	while (c < '0' || c > '9'){ if (c == '-') f = -1; c = getchar(); }
	while (c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }
	a = f == 1 ? x : -x;
}

map<string, int> m;

int main() {
	int n, ans = 0;
	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		if (m[s] <= 0) ++ans, ++m[s];
	}
	if (ans == 3) cout << "Three\n"; else cout << "Four\n";
	return 0;
} 


Measured memory_bytes: 256
import math

in1 = list(map(int,input().split()))
Nin = in1[0]
Din = in1[1]

xy = [map(int, input().split()) for _ in range(Nin)]
x, y = [list(i) for i in zip(*xy)]

count=0

for i in range(Nin):
    dist = math.sqrt(x[i]**2 + y[i]**2)
    if dist <= Din:
        count += 1

print(count)


Measured memory_bytes: 150324
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	if(abs(a-b)&1){
		if(a>b)swap(a,b);
		ll ans = (a + b) /2;
		a = n - a + 1;
		b = n - b + 1;
		swap(a,b);
		chmin(ans,(a + b) /2);
		cout << ans << endl;
	}else{
		cout << abs(a-b) / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256