akhauriyash/Code-Regression huggingface dataset:
local read = io.read
local min = math.min

local n, m, x = read("n", "n", "n")
local c_t, a_t = {}, {}
for i = 1, n do
	c_t[i] = read("n")
	a_t[i] = {}
	for j = 1, m do
		a_t[i][j] = read("n")
	end
end

local money_min = math.maxinteger
for i = 0, 2^n - 1 do
	local money = 0
	local score_t = {}
	for j = 1, m do
		score_t[j] = 0
	end

	for j = 0, n - 1 do
		local bit = i >> j
		if bit == 0 then
			break
		end
		if bit & 1 == 1 then
			money = money + c_t[j + 1]
			for k = 1, m do
				score_t[k] = score_t[k] + a_t[j + 1][k]
			end
		end
	end

	local score_min = math.maxinteger
	for j = 1, m do
		score_min = min(score_min, score_t[j])
	end
	if score_min >= x then
		money_min = min(money_min, money)
	end
end

print((money_min == math.maxinteger) and -1 or money_min)


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

int dp[100010];

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

    dp[0] = 0;
    
    for(int i = 1; i <= 100000; i++){
        dp[i] = INT_MAX;
        int power = 1;
        while(power <= i){
            dp[i] = min(dp[i] , dp[i - power] + 1);
            power *= 6;
        }
        power = 1;
        while(power <= i){
            dp[i] = min(dp[i], dp[i - power] + 1);
            power *= 9;
        }
    }
    int n;
    cin >> n;
    cout << dp[n] << endl;
}



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

int main()
{
    int N;
    cin>>N;
    int a,b,c,d;
    a = N/1000;
    N -= a*1000;
    b = N/100;
    N -= b*100;
    c = N/10;
    N -= c*10;
    d = N;
    if(a == b && b == c){
        cout<<"Yes"<<endl;
    }else if(b == c && c == d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 2001001;
const ll MOD = 1000000007;
const ll INF = 1001001001;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    COMinit();
    ll ans = 0;
    rep2(i, c1, c2 + 1)
    {
        ans = (ans + COM(1 + i + r2, r2) + MOD - COM(i + r1, r1 - 1)) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 50488
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int
lli to[200005][65] = {};
int a[200005] = {};
signed main() {
  lli N, K;
  cin >> N >> K;

  rep(i, N) {
    cin >> to[i][0];
    to[i][0]--;
  }
  rep(j, 64) rep(i, N) {
    to[i][j + 1] = to[to[i][j]][j];
    //    cout << to[i][j + 1] << endl;
  }
  lli cur = 0;
  rrep(i, 64) {
    if ((K >> i) & 1) {
      cur = to[cur][i];
    }
    //    cout << i << " " << cur << endl;
  }
  cout << cur + 1 << endl;

  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 105216
#include<bits/stdc++.h>
using namespace std;
#define Ri register
template<typename T>inline T read(Ri T&t)
{Ri T f=1;Ri char ch=getchar();t=0;
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9')t=t*10+ch-'0',ch=getchar();t*=f;return t;}
template<typename T,typename...Args>
inline void read(T&t,Args&...args)
{read(t);read(args...);}
const long long p=1e9+7;
inline long long power(Ri long long x,Ri long long k=p-2)
{Ri long long re=1;for(;k;k>>=1,x=x*x%p)if(k&1)re=re*x%p;return re;}
long long fac[2000006],ifac[2000006];
inline long long C(int x,int y)
{if(y<0||x-y<0)return 0;return fac[x]*ifac[y]%p*ifac[x-y]%p;}
int X[10],Y[10];
struct OPT{int x,y,col;}opt[10];
inline long long G(OPT a,OPT b)
{return C(abs(a.x-b.x)+abs(a.y-b.y),abs(a.x-b.x));}
inline long long calc(OPT a,OPT b)
{
	long long ans=0;
	for(int i=X[3];i<=X[4];i++)
	{
		ans=(ans-G(a,(OPT){i,Y[3]-1,0})*G((OPT){i,Y[3],0},b)%p*(i+Y[3])%p+p)%p;//下边界,钦点从下方进入 
		ans=(ans+G(a,(OPT){i,Y[4],0})*G((OPT){i,Y[4]+1,0},b)%p*(i+Y[4]+1)%p)%p;//上边界,钦点从上方离开 
	}
	for(int i=Y[3];i<=Y[4];i++)
	{
		ans=(ans-G(a,(OPT){X[3]-1,i,0})*G((OPT){X[3],i,0},b)%p*(X[3]+i)%p+p)%p;//左边界,钦点从左边进入
		ans=(ans+G(a,(OPT){X[4],i,0})*G((OPT){X[4]+1,i,0},b)%p*(X[4]+i+1)%p)%p;//右边界,钦点从右边离开 
	}
//	printf("ans=%lld\n",ans);
	return (ans*a.col*b.col%p+p)%p;
}
int main()
{
	fac[0]=1;for(int i=1;i<=2000000;i++)fac[i]=fac[i-1]*i%p;
	ifac[2000000]=power(fac[2000000]);
	for(int i=2000000-1;i>=0;i--)ifac[i]=ifac[i+1]*(i+1)%p;
//	for(int i=1;i<=10;i++)printf("%lld",ifac[i]);printf("\n");
	for(int i=1;i<=6;i++)read(X[i]);
	for(int i=1;i<=6;i++)read(Y[i]);
	opt[1]=(OPT){X[1]-1,Y[1]-1,1};//第二个矩阵的关键点在右上方,旋转180
	opt[2]=(OPT){X[2],Y[1]-1,-1};
	opt[3]=(OPT){X[1]-1,Y[2],-1};
	opt[4]=(OPT){X[2],Y[2],1};
	
	opt[5]=(OPT){X[5],Y[5],1};
	opt[6]=(OPT){X[6]+1,Y[5],-1};
	opt[7]=(OPT){X[5],Y[6]+1,-1};
	opt[8]=(OPT){X[6]+1,Y[6]+1,1};
	long long ans=0;
	for(int i=1;i<=4;i++)
		for(int j=5;j<=8;j++)
			ans=(ans+calc(opt[i],opt[j]))%p;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 34996
import java.util.*;
import java.io.*;

public class Main {


    public Main(FastScanner in, PrintWriter out, int test) {
        int N = in.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++)
            A[i] = in.nextInt();
        Arrays.sort(A);

        long res = 0;

        PriorityQueue<int[]> q = new PriorityQueue<>(Comparator.comparingInt((int[] e) -> Math.min(e[0], e[1])).reversed());
        q.add(new int[]{A[N - 1], A[N - 1]});

        for (int i = N - 2; i >= 0; i--) {
            int a = A[i];
            int[] place = q.remove();
            res += Math.min(place[0], place[1]);
            q.add(new int[]{place[0], a});
            q.add(new int[]{a, place[1]});
        }
        out.println(res);
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        // int T = in.nextInt();
        for (int t = 1; t <= 1; t++) {
            Main sol = new Main(in, out, t);
        }

        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream)
    {
        this.stream = stream;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}

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

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        string tmp(s.begin(), s.end() - 1);
        s = *(s.end() - 1) + tmp;
        // printf("%s\n", s.c_str());
        if (s == t) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353LL

ll fac[10000010],ifac[10000010];
int n,a,b;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll pls(const ll &x,const ll &y) { return (x+y<mod)?x+y:x+y-mod; }
inline ll mns(const ll &x,const ll &y) { return (x-y<0)?x-y+mod:x-y; }
inline ll ksm(ll x,ll y) { ll res=1;for (;y;y>>=1,x=x*x%mod) if (y&1) res=res*x%mod;return res; }
inline ll C(const int &x,const int &y) { return (x<0||y<0||x<y)?0:fac[x]*ifac[y]%mod*ifac[x-y]%mod; }

inline void pre_gao()
{
	fac[0]=1;
	for (int i=1;i<=10000000;i++) fac[i]=fac[i-1]*i%mod;
	ifac[10000000]=ksm(fac[10000000],mod-2);
	for (int i=9999999;~i;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}

inline ll calc(int n,int m)
{
	return mns(C(n-1+m,m),C(n-1+m,m-1));
}

inline ll gao(int n,int m) { return (!n)?0:C(m+n-1,n-1); }

int main()
{
	n=rd();a=rd();b=rd();pre_gao();
	if (b==0) { puts("1");return 0; }
	ll ans=0;
	if (a+b==n) ans=calc(b,a);
	for (int k=0;k<=a;k++)
	{
		int hh=n-b-k;
		if (hh<=0) break;
		ans=pls(ans,calc(b,k)*mns(gao(a-k+1,hh),gao(a-k,hh))%mod);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 156544
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
h_list = [int(elem) for elem in fin().split()]
original_h_list = [x for x in h_list]

flag = True
result = 'Yes'
h_list = [-1] + h_list + [10**10]
min_h_list = min(h_list[1:-1])
for i in range(1, len(h_list)-1):
    if h_list[i] - 1 >= h_list[i-1]:
        h_list[i] -= 1

for i in range(1, len(h_list)-1):
    if not (h_list[i-1] <= h_list[i] <= h_list[i+1]):
        result = 'No'

print(result)


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

using namespace std;
using ll=long long;

int main(){
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll> v(n,k-q);
    for(int i=0;i<q;++i){
        int a;
        cin>>a;
        v[a-1]++;
    }
    for(int i=0;i<n;++i){
        if(v[i]>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;


int main(){


	long N,A,B,C,D,E;
	long ans;

	cin >> N >> A >> B >> C >> D >> E;

	vector<long> v;
	v.push_back(A);
	v.push_back(B);
	v.push_back(C);
	v.push_back(D);
	v.push_back(E);
	sort(v.begin(),v.end());
	if (v[0]==1){
		ans = N + 4;
	}else{
		ans = N / v[0] + 5;
	}

	

	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <bitset>
#include <cstring>
using namespace std;
char buf[8001];
bitset<16001> okx, oky;
int main() {
    int x, y;
    scanf("%s %d %d", buf, &x, &y);
    char *s = buf;
    okx[8000] = oky[8000] = true;
    for (int i = 0; *s; i++) {
        char *t = strchr(s, 'T');
        if (!t)
            t = strchr(s, '\0');
        int sh = t - s;
        // printf("%d %d\n", i, sh);
        if (i == 0) {
            okx <<= sh;
        } else if (i % 2) {
            oky = (oky << sh) | (oky >> sh);
        } else {
            okx = (okx << sh) | (okx >> sh);
        }
        if (!*t)
            break;
        s = t + 1;
    }
    printf(okx[x + 8000] && oky[y + 8000] ? "Yes" : "No");
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

int calcNum(int num, int binary, int kind) {
  int ans = 0;
  if (kind == 0) {
    ans += (num/(binary*2)) * binary;
    num -= ans * 2;
    if (num > 0 && num < binary) {
      ans += num;
    } else {
      ans += binary-1;
    }
  } else if (kind == 1) {
    ans += (num/(binary*2)) * binary;
    num -= ans * 2;
    if (num >= binary) {
      ans += num - binary + 1;
    }
  }

  return ans;
}

signed main(void) {
  int A, B;
  cin >> A >> B;

  int start = 1;
  int ans = 0;
  while(start <= B) {
    int num1;
    num1 = calcNum(B, start, 1) - calcNum(A-1, start, 1);
    // cout << num1 << endl;
    if (num1%2 == 1) {
      ans += start;
    }
    start *= 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long d = sc.nextLong();
	    int result = 0;
		for(int i = 0; i < n; i++){
		    long x = sc.nextLong();
		    long y = sc.nextLong();
		    if(x*x + y*y <= d*d) result++;
		}
		
		// 計算
		//String result = "No";
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 45696
import sys
readline = sys.stdin.readline

# 現在のインデックスを持ちながらBFSしてみよう

N = int(readline())
S = readline().rstrip()

from collections import deque
q = deque([])

for i in range(10):
  q.append(["",0,str(i)])
  
ans = 0
while q:
  # 現在の文字列、探し始めるインデックス、探している文字列
  num, ind, target = q.popleft()
  while ind < len(S):
    if S[ind] == target:
      break
    ind += 1
  else:
    continue
  num += target
  if len(num) == 3:
    ans += 1
    continue
  for i in range(10):
    q.append([num, ind + 1, str(i)])

print(ans)

Measured memory_bytes: 70564
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;
 
int main(){
    int R;
    cin >>R;
    if(R<1200)cout<<"ABC"<<endl;
    else if(R<2800)cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    char hw[52][52];
    for(int i=0;i<52;i++){
        for(int j=0;j<52;j++){
            hw[i][j]='.';
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>hw[i][j];
        }
    }
    bool flag=true;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(hw[i][j]=='#'){
                if(hw[i-1][j]=='#'||
                    hw[i+1][j]=='#'||
                    hw[i][j-1]=='#'||
                    hw[i][j+1]=='#');
                else flag=false;
            }
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
const lli N = 2e3 + 10;
bitset < (N * N) / 2 > bs;
void solve() {
	lli n;
	cin >> n;
	lli a;
	lli sum = 0;
	bs[0] = 1;
	for (lli i = 0; i < n; i++) {
		cin >> a;
		sum += a;
		bs |= (bs << a);
	}
	for (lli i = (sum) / 2; i >= 0; i-- ) {
		if (bs[i]) {
			cout << sum - i << endl;
			return;
		}
	}

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

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int>k(M);
    vector<int>p(M);
    vector<vector<int>> s(M, vector<int>());
    for (int i = 0; i < M; ++i) {
        cin >> k[i];
        for (int j = 0; j < k[i]; ++j) {
            int temp;
            cin >> temp;
            s[i].push_back(temp);
        }
    }
    for (int i = 0; i < M; ++i) {
        cin >> p[i];
    }

    // スイッチで全探索
    int ans = 0;
    for (int i = 0; i < pow(2, N); ++i) {
        int flag = 1;
        for (int j = 0; j < M; ++j) {
            int temp = 0;
            for (int x : s[j]) {
                if(i & (1 << x-1)) temp++;
            }
            if(temp % 2 != p[j]) flag = 0;
        }
        ans += flag;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 1001001001
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> a2(n);
    rep(i, n) {
        cin >> a[i];
        a2[i] = a[i];
    }
    sort(a.begin(), a.end());
    
    int max = a[n-1], second = a[n-2];
    
    rep(i,n){
        if(a2[i]!=max) {
            cout << max << endl;
            continue;
        }
        else{
            cout << second << endl;
            continue;
        }
    }

    
    
 

}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int h,w;
char grid[51][51];
int reach[51][51];
bool issearched[51][51];
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

int dfs(int px, int py){
	// cout << "(px,py) = " << "(" << px << "," << py << ") = " << grid[px][py] << "??§???" << endl;
	if(grid[px][py] == 'B') {
		// cout << "unko" << endl; 
		return 2;  //10
	
	}
	if(grid[px][py] == 'W') return 1;  //01
	int res = 0;
	REP(i,4){
		int nx = px + dx[i]; 
		int ny = py + dy[i];
		if(nx < 0 || ny < 0 || nx > h-1 || ny > w-1) continue;
		if(issearched[nx][ny]) continue;
		issearched[nx][ny] = true;
		// cout << "?¬??????¢?´¢??????" << "(" << nx << "," << ny << ")??§???" << endl;
		res |= dfs(nx,ny);	
	}
	return res;
}
int main(){
	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		REP(i,h) REP(j,w) cin >> grid[i][j];
		REP(i,h) REP(j,w) reach[i][j] = 0;
		REP(i,h) REP(j,w) {
			REP(k,h) REP(l,w) issearched[k][l] = false;
			// cout << i << " " << j << "?????????????????¢?´¢???????§?" << endl;
			issearched[i][j] = true;
			if(grid[i][j]=='.') reach[i][j] = dfs(i,j);
		}
		int white = 0; int black = 0;
		REP(i,h) REP(j,w){
			if(reach[i][j] == 1) white++;
			else if(reach[i][j] == 2) black++;
		}
		cout << black << " " << white << endl;
	}
}

Measured memory_bytes: 1292
#!/usr/bin/env python3
h,w = map(int,input().split())
grid = [["."]*(w+2) for _ in range(h+2)]
for i in range(h):
    s = input()
    for j in range(w):
        grid[i+1][j+1] = s[j]
for i in range(h):
    for j in range(w):
        if grid[i+1][j+1] == "#":
            if grid[i][j+1] == "."  and  grid[i+1][j] == "." and grid[i+2][j+1] == "." and grid[i+1][j+2] == ".":
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 39152
#include <cstdio>
#include <utility>
#include <vector>
#include <list>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	vector<list<int>> v(in());
	for (int q = in(); q; q--) {
		int o = in();
		auto &t = v[in()];
		switch(o) {
		case 0:
			t.push_back(in());
			break;
		case 1:
			{
				int  i = 0;
				for (int x: t) {
					if (i++)
						out(" ");
					out(x);
				}
				outl();
				break;
			}
		default:
			{
				auto &i = v[in()];
				i.splice(i.end(), move(t));
			}
		}
	}
}



Measured memory_bytes: 18248
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define line cout<<"----------------------------"<<endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=4009;
string str;
string str1;
ll  dp[mx][5];
ll  call(ll  i, ll  j)
{
    if(j==str1.size()) return 1;
    if(i==str.size()) return 0;
    ll  &ret=dp[i][j];
    if(ret!=-1) return ret;
    ll  a=0,b=0 ;
    if(str[i]==str1[j]) a=call(i+1,j)+call(i+1,j+1);
    else b=call(i+1,j);
    return ret=a+b;
}
int   main()
{
    fast;
    ll  n;
    cin>>n;
    cin>>str;
    ll  ans=0;
    str1="BGR";
    do
    {
        memset(dp,-1,sizeof dp)  ;
        ans+=call(0,0);

    }while(next_permutation(str1.begin(),str1.end()));
    ll  cnt=0;
    for(ll  i=0;i<str.size();i++)
    {
        for(ll  j=1;j<=str.size();j++)
        {
            if(i+2*j>=str.size()) break;
            if(str[i]!=str[i+j] and str[i]!=str[i+2*j] and str[i+j]!=str[i+2*j]) cnt++;
        }
    }
    cout<<ans-cnt<<endl;

}


Measured memory_bytes: 3964
/*****Enigma_27*****/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pll         pair<ll,ll>
#define vll          vector<ll>
#define f           first
#define s           second
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll )x.size()
#define hell        10000000000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define prime       54059
using namespace std;
ll i,j,t=1,k,n,ans=0,w,sum=0,l,r,q,a[100005]={0},y,b[100005];
map<ll,ll> m;
int  main()
{   ios
   cin>>n;
   for(i=1;i<=n;i++)
   {
       cin>>a[i];
       b[i]=a[i];
   }
  for(i=1;i<n;i++)
  {
      if(a[i]==i)
      {
          swap(a[i],a[i+1]);ans++;
      }
  }
  if(a[n]==n) ans++;
   for(i=n;i>1;i--)
  {
      if(b[i]==i)
      {
          swap(b[i],b[i-1]);sum++;
      }
  }
  if(b[1]==1) sum++;
  cout<<min(sum,ans)<<endl;
	return 0;
}


Measured memory_bytes: 1792
N,M=map(int,input().split())
S=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0

for i in range(2**N):
  bulb=[0]*M
  judge=True
  for j in range(N):
    if (i>>j)&1==1:
      for k in range(M):
        if j+1 in S[k]:
          bulb[k]+=1
  for t in range(M):
    if bulb[t]%2!=P[t]:
      judge=False
  if judge:
    ans+=1
            
print(ans)      

Measured memory_bytes: 3064
import itertools as it 

s = input()
k = int(input())

groups = [(k, len(list(g))) for k, g in it.groupby(s)]

# print(groups)

if s[0] != s[-1]:
    answer = sum([x[1] // 2 for x in groups]) * k

elif len(set(s)) == 1:
    answer = (len(s) * k) // 2

elif s[0] == s[-1]:
    answer = sum([x[1] // 2 for x in groups[1:-1]]) * k + groups[0][1] // 2 + groups[-1][1] // 2
    answer += (k - 1) * ((groups[0][1] + groups[-1][1]) // 2)

print(answer)

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

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

  double sum = 0;
  for (int i = 0; i < N; i++) {
    int A = 0;
    scanf("%d", &A);
    sum += 1 / (double)A;
  }

  double ans = 1 / sum;
  printf("%f", ans);
  return 0;
}

Measured memory_bytes: 256
def merge(a, left, mid, right):
    l, r = [], []
    for i in range(left, mid):
        l.append(a[i])
    l.append(float('inf'))
    for i in range(mid, right):
        r.append(a[i])
    r.append(float('inf'))
    i, j = 0, 0
    for k in range(left, right):
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1


def merge_sort(a, left, right):
    res = 0
    if left + 1 < right:
        mid = (left + right) // 2
        res += merge_sort(a, left, mid)
        res += merge_sort(a, mid, right)
        merge(a, left, mid, right)
        res += right - left
    return res

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = merge_sort(a, 0, len(a))
    print(' '.join(map(str, a)))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 66776
# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
K, = [int(s) for s in inputs]

ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g1 = math.gcd(a, b)
        for c in range(1,K+1):
            g2 = math.gcd(g1, c)
            ans += g2
print(ans)


Measured memory_bytes: 9180
from functools import lru_cache
MOD = 1000000007

def valid(s):
    f = 0
    if len(s) == 4:
        f = 1
        if (s[0] == 'A' and s[2:] == 'GC') or (s[0:2] == 'AG' and s[3] == 'C'):
            return 0
    return s[f:] != 'AGC' and s[f:] != 'ACG' and s[f:] != 'GAC'
    

@lru_cache(maxsize=None)
def dfs(n, s):
    if not valid(s):
        return 0

    if n == N:
        return 1

    f = len(s) == 4
    a = dfs(n+1, s[f:] + 'A')
    b = dfs(n+1, s[f:] + 'C')
    c = dfs(n+1, s[f:] + 'G')
    d = dfs(n+1, s[f:] + 'T')
    return (a + b + c + d) % MOD
    

N = int(input())
ans = dfs(0, '')
print(ans)


Measured memory_bytes: 11268
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) cout << c << endl;
	else if (a == c) cout << b << endl;
	else cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
        else:pass
    

while Q:top = Q[0];func(top);del Q[0]

for i in range(N):print(i + 1 ,int(L[i]))



Measured memory_bytes: 5632
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      tm: usize,
      t: [usize; n]
   }

   let mut ans = 0;
   let mut ts = 0;
   let mut te = tm;
   for i in 1..n {
      if t[i] - t[i-1] > tm {
         ans += te - ts;
         ts = t[i];
      }
      te = t[i] + tm;
   }
   ans += te - ts;
   println!("{}", ans);
}


Measured memory_bytes: 6396
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)


template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }
template<class T> inline ll gcd(T a, T b){ if (a % b == 0){ return b; } else{ return gcd(b, a%b); } }
template<class T> inline ll lcm(T a, T b){ return a * b / gcd(a, b); }
template<class T> inline ll fact(T a){ if (a <= 1){ return 1; } else{ return a * fact(a - 1); } }
template<class T> inline ll comb(T a, T b){ return a == 0 ? 0 : fact(a) / fact(b) / fact(a - b); }

int main(){
    ll N;
    vector<ll> A, B;
    cin >> N;
    rep(i, 0, N){
        ll temp;
        cin >> temp;
        A.push_back(temp);
        B.push_back(temp);
    }
    sort(begin(B), end(B), greater<ll>());
    rep(i, 0, N){
        if (A[i] == B[0]){
            cout << B[1] << endl;
        }
        else{
            cout << B[0] << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 4964
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;
const ll inf = 1001001001;

int main() {
    ll n, p;
    cin >> n >> p;
    ll ans = 1;
    if(n == 1){
        cout << p << endl;
        return 0;
    }
    for(ll i=2; i*i<=p; i++){
        if(p%i != 0)continue;
        ll count = 0;
        while(p%i == 0){
            p /= i;
            count++;
        }
        rep(j, 0, count/n){
            ans*= i;
        }
    }  
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
string S, T;
vector<string> answer;

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

void search(){
    for(int i=0; i<S.size(); i++){
        bool judge=true;
        for(int j=0; j<T.size(); j++){
            if (S[i+j]!=T[j] && S[i+j]!='?') {
                judge =false;//SとTを比較して
                break;
            }
        }
        string A=S;
        if (judge) {
            for(int j=0; j<T.size(); j++){
                A[i+j]=T[j];
            }
            for(int j=0; j<A.size(); j++){
                if(A[j]=='?') A[j]='a';
            }
            answer.push_back(A);
        }
    }
    sort(answer.begin(), answer.end());
}

void print(){
    if (answer.size()==0) cout << "UNRESTORABLE" << endl;
    else cout << answer.at(0) << endl;
}

int main(){
    input();
    search();
    print();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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(int argc, char const *argv[]) {
  ll a,b,c;
  cin >> a >> b >> c;
  if(2*sqrtl(a*b)<c-a-b)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
K, N =map(int, input().split())
A = list(map(int, input().split()))

diff = []

for i in range(1, len(A)):
  diff.append(A[i] - A[i-1])
  
diff.append(K + A[0] - A[-1])

diff.remove(max(diff))

print(sum(diff))

Measured memory_bytes: 26060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
vector<bool> visisted;
vector<ll> counter;

void bfs(vector<ll> adj[],ll u){
	queue<ll> q;
	q.push(u);
	visisted[u] = true;
	while(!q.empty()){
		ll front = q.front();
		q.pop();
		fr(i,0,adj[front].size()){
			if(!visisted[adj[front][i]]){
				q.push(adj[front][i]);
				counter[adj[front][i]]+=counter[front];
				visisted[adj[front][i]] = true;
			}
		}
	}
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,q;
    cin>>n>>q;
    visisted.assign(n+1,false);
    counter.assign(n+1,0);
    vector<ll> tree[n+1];
    // vector<ll> counter(n+1);
    fr(i,0,n-1){
    	ll a,b;
    	cin>>a>>b;
    	tree[a].pb(b);
    }
    fr(i,0,q){
    	ll p,x;
    	cin>>p>>x;
    	counter[p]+=x;
    }
    // cout<<"hello"<<endl;
    bfs(tree,1);
    fr(i,1,n+1){
    	cout<<counter[i]<<" ";
    }
    cout<<endl;



    return 0;
}


Measured memory_bytes: 14976
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};



#define int ll
signed main(){
    map<ll,ll> mp;
    mp[0]++;
    int n;cin>>n;
    int a[200010];
    ll s=0;
    
    rep(i,0,n){
        cin>>a[i];
        s+=a[i];
        mp[s]++;
    }
    
    ll ans=0;
    for(auto kv : mp){
        ans+=kv.se*(kv.se-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,p;
	cin>>n>>p;
	string s;
	cin>>s;
	if(p==2 || p==5){
		ll ans=0;
		ll cnt=0;
		rep(i,n){
			 int now=s[i]-'0';
			 if(now%p==0){
				 ans+=(i+1);
			 }
		}
		cout<<ans<<endl;
		return 0;
	}
	ll ans=0;
	ll cnt=0;
	ll pow=1;
	map<ll,ll> mp;
	mp[0]++;
	for(int i=n-1;i>=0;i--){
		int now=s[i]-'0';
		cnt=(pow*now+cnt)%p;
		pow*=10;
		pow%=p;
		ans+=mp[cnt];
		mp[cnt]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1044
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int sz = 1e6 + 1;

int n;
int a[sz];
int s[sz];
int prime[sz];

void sieve() {
	for (int i = 2; i < sz; i++) {
		if (s[i] == 0) {
			for (int j = i; j < sz; j += i)
				s[j] = i;
		}
	}
}

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

void solve() {
	sieve();
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int g = a[0];
	for (int i = 0; i < n; i++) {
		g = gcd(g, a[i]);
		set<int> fact;
		int t = a[i];
		while (t != 1) {
			fact.insert(s[t]);
			t /= s[t];
		}
		for (int p : fact)
			prime[p]++;
	}

	bool ok = 1;
	for (int i = 0; i < sz; i++)
		if (prime[i] > 1)
			ok = 0;
	if (ok)
		cout << "pairwise coprime";
	else if (g == 1)
		cout << "setwise coprime";
	else
		cout << "not coprime";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 15280
N, W = map(int, input().split())
w=[]
v=[]
for i in range(N):
	a, b = map(int, input().split())
	w.append(a)
	v.append(b)
#dp[i+1][j] := i番目までの品物から総和がjとなるように選んだ時の重さの総和の最小値
dp=[[float("inf")]*(max(v)*N+1) for _ in range(N+1)]
#初期条件
dp[0][0]=0
for i in range(N):
	for j in range(max(v)*N+1):
		if v[i]>j:
			dp[i+1][j] = dp[i][j]
		else:
			dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i])

ans=0
for j in range(max(v)*N+1):
	if dp[N][j]<=W:
		ans=j
print(ans)

Measured memory_bytes: 250224
let checkOverFlow (x: int64) (y: int64) = x > 1000000000000000000L / y

let rec fb (x: int64) (xs: int64 list) =
    match xs with
    | y :: ys -> if checkOverFlow x y then -1L else fb (x * y) ys
    | [] -> x


stdin.ReadLine() |> ignore
let b = stdin.ReadLine().Split(' ') |> Array.map int64
if Array.contains 0L b
then printfn "%d" 0
else b |> List.ofArray |> fb 1L |> printfn "%d"


Measured memory_bytes: 46444
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

#define BITS 62
ll maxSubarrayXOR(ll set[], int n)
{
  int index = 0; //ランク

  for (int i = BITS-1; i >= 0; i--){ //bit桁ぶん進めていく
    int maxInd = index;
    ll maxEle = -1;
    for (int j = index; j < n; j++){
      if ( (set[j] & ((ll)1 << i)) != 0 && set[j] > maxEle ){
        maxEle = set[j], maxInd = j;
      }
    }

    if (maxEle == -1) continue;

    swap(set[index], set[maxInd]); //最大のものを上に持ってくる

    maxInd = index;

    rep(j, n){
      if (j != maxInd && (set[j] & ((ll)1 << i)) != 0){
        set[j] = set[j] ^ set[maxInd];
      }
    }

    index++; //ランクを1つ上げる。
  }

  // setは掃き出し済 ランクはindex　Final result is XOR of all elements
  
  ll res = 0;
  rep(i, n) res ^= set[i];
  return res;
}

// Driver program
void Main() {

  int N;
  cin>>N;
  ll set[N];
  ll allxor=0;
  rep(i,N){
    cin>>set[i];
    allxor ^= set[i];
  }
  rep(i,N){
    set[i] &= ~allxor;
  }

  ll x=maxSubarrayXOR(set, N);

  cout<< x*2 + allxor<<"\n";
}


  //-----------------------------------
  int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
  }
  //-----------------------------------


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define pb push_back
#define ld long double
#define mod 1000000007
#define mk make_pair
#define ull unsigned long long
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    ll n;
    cin>>n;
    vector<ll>v;
    ll x,ans=0,y,val,val1;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.pb(x);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            y=v[i]+v[j];
            if(lower_bound(v.begin(),v.end(),y)==v.end())
            {
                val=n-j-1;
                ans+=val;
            }
            else
            {
                x=lower_bound(v.begin(),v.end(),y)-v.begin();
                val=x-j-1;
                ans+=val;
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int h[6],w[6];
  int i,j,tmp;
    
  for(i=0;i<6;i++){
    scanf("%d %d",&h[i],&w[i]);
    if(h[i]>w[i]){
      tmp=h[i];
      h[i]=w[i];
      w[i]=tmp;
    }
  }


  for(i=0;i<6;i++){
    for(j=0;j+1<6;j++){
      if(h[j]>h[j+1] || (h[j]==h[j+1]&&w[j]>w[j+1]) ){
        tmp=h[j];
        h[j]=h[j+1];
        h[j+1]=tmp;
        tmp=w[j];
        w[j]=w[j+1];
        w[j+1]=tmp;
      }
    }
  }
  
  if( h[0]==h[1] && w[0]==w[1] && h[2]==h[3] && w[2]==w[3] && h[4]==h[5] && w[4]==w[5] && h[0]==h[2] && w[0]==h[4] && w[2]==w[4] ){
    printf("yes\n");
  }else{
    printf("no\n");
  }
  
  return 0;
}
                                                                            

Measured memory_bytes: 580
import sys

X, Y = map(int, input().split())

# 直交座標に直す
if X > 2 * Y or Y > 2 * X or \
        (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0:
    print(0)
    sys.exit()
x, y = (2 * X - Y) // 3, (2 * Y - X) // 3


def comb_inv(n, k, mod):
    f = [1 for _ in range(n + 1)]
    inv = [1 for _ in range(n + 1)]
    finv = [1 for _ in range(n + 1)]

    for i in range(2, n + 1):
        f[i] = f[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return f[n] * (finv[k] * finv[n - k] % mod) % mod


print(comb_inv(x + y, x, 10 ** 9 + 7))


Measured memory_bytes: 82200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int r;
    cin>>r;
    cout<<3*r*r;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int num,count;
	int weight[10];
	for(int i=0,j=1;i<10;i++,j*=2){
		weight[i]=j;
	}
	//for(int i=0;i<10;i++){
	//	cout << weight[i] << endl;
	//}
	while(cin >> num){
		count = 0;
		for(int i=0;i<10 && num;i++){
			if(num%2){
				if(count){
					cout << " " << weight[i];
				}
				else{
					cout << weight[i];
					count++;
				}
			}
			num /= 2;
		}
		cout << endl;
	}

}

Measured memory_bytes: 0
import numpy as np
from fractions import gcd
 
 
N, M = list(map(int, input().split()))
S = input()
T = input()

g = gcd(N, M)
l = int(N * M / g)

for i in range(g):
    if S[int(N/g*i)] != T[int(M/g*i)]:
        l = -1
        break

print(l)


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

int main()
{
	string str;
	cin >> str;
	int count = 0;
	for(unsigned i=0;i<str.size()/2;i++){
		if(str[i] == '(' ){
			if(str[str.size()-1-i] != ')'){
				str[str.size()-1-i] = ')';
				count++;
			}
		}
		else if(str[i] == ')' ){
			if(str[str.size()-1-i] != '('){
				str[str.size()-1-i] = '(';
				count++;
			}
		}
		else if(str[i] != str[str.size()-1-i]){
			str[i] = str[str.size()-1-i];
			count++;
		}
	}
	if(str.size()%2 == 1 && ( str[str.size()/2] == '(' || str[str.size()/2] == ')' )){
		str[str.size()/2] = 'i';
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int	main(void)
{
  	int		N;
  	char	*S;
  	char	*sp;
  	int		num;
  	int		count;
  
  	num = scanf("%d", &N);
  	if (num != 1)
      	return (0);
  
  	S = (char *)malloc(sizeof(char) * N);
  
    num = scanf("%s", S);
  	if (num != 1)
      	return (0);
  
  	sp = strstr(S, "ABC");
    if (sp == NULL)
    {
      	printf("0");
      	return (0);
    }
  
  	count = 1;
  	while ((sp = strstr(sp + 1, "ABC")) != NULL)
      	count++;
  
  	printf("%d", count);
  	return (0);
}

Measured memory_bytes: 128