akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdint>
 
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
 
using namespace std;
 
 
int inputValue(){
    int a;
    cin >> a;
    return a;
};
 
long long inputValueLongLong(){
    long long a;
    cin >> a;
    return a;
};
 
void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};
 
void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
 
template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
 
int Kaijou(int N){
    if(N>1){
        return Kaijou(N-1)*N;
    }else{
        return 1;
    }
}
 
long long combination(long long n, long long r) {
  if ( r * 2 > n ) r = n - r;
  long long dividend = 1;
  long long divisor  = 1;
  long long res = 1;
  for ( long long i = 1; i <= r; i++ ) {
    // dividend *= (n-i+1);
    // divisor  *= i;
    res = res * (n-i+1) / i;
    res = res % 1000000007;
    cout << res << endl;
  }
  
  return res;
}
 
const int MAX = 1000000;
const int MOD = 1000000007;
 
long long 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(int argc, const char * argv[]) {
    // source code
    long long X,Y;
    X = inputValueLongLong();
    Y = inputValueLongLong();
 
    if((X+Y)%3!=0 || X>2*Y || Y>2*X){
        cout << 0 <<endl;
        return 0;
    }
 
    long long step = (X+Y)/3;
 
    long long i=0;
    long long sX=0,sY=0;
    sX = 2*step;
    sY = step;
    long long r=0;
    for(i=0;i<step+1;i++){
        if(sX == X && sY ==Y){
            r = i;
            break;
        }
        sX -= 1;
        sY += 1;
    }
 
    COMinit();
 
    cout << COM(step,r) << endl; 
    return 0;
}

Measured memory_bytes: 23680
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD (int)1e9+7
int dx4[]={1,0,-1,0};
int dy4[]={0,-1,0,1};
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct pair_{
    int x;
    int y;
}pair_t;

int main(){
    char s[200];scanf("%s",s);
    for(int i=0;i<strlen(s)/2;i++){
        if(s[i]!=s[strlen(s)-1-i]){
            printf("No\n");
            return 0;
        }
    }
    for(int i=0;i<(strlen(s)-1)/4;i++){
        if(s[i]!=s[(strlen(s)-1)/2-1-i]){
            printf("No\n");
            return 0;
        }
    }
    for(int i=(strlen(s)+3)/2-1;i<(strlen(s)-1);i++){
        if(s[i]!=s[(strlen(s)-1)-i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 128
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cmath>
using namespace std;
long long N;
int main() {
	cin>>N;
	for(int i=0;;i++){
		if(i*i>N){
			cout<<(i-1)*(i-1)<<endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
const int INF = 1e9;
int dp[100010];

int main(){
  int n;
  cin >> n;
  rep(i,n+1) dp[i] = INF;
  dp[0] = 0;
  for (int i = 0; i <= n;i++){
    for (int pow6 = 1; pow6 <= i;pow6*=6){
      dp[i] = min(dp[i],dp[i-pow6] + 1);
    }
    for (int pow9 = 1; pow9 <= i;pow9*=9){
      dp[i] = min(dp[i],dp[i-pow9] + 1);
    }
  }
  cout << dp[n] << endl;
  
  

  
  return 0;
  
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  string a;
  cin >>a;
  
  cout << (a=="hi" || a=="hihi" || a=="hihihi" ||
           a=="hihihihi" || a=="hihihihihi"?"Yes":"No") << endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int r[100][100], h, w, n, a;
void paint(int c) {
	for (int i = 0; i < h; i++) {
		if (i % 2) {
			for (int j = w - 1; j >= 0; j--)
				if (!r[i][j]) {
					r[i][j] = c;
					return;
				}
		}
		else {
			for (int j = 0; j < w; j++)
				if (!r[i][j]) {
					r[i][j] = c;
					return;
				}
		}
	}
}
int main(void) {
	scanf("%d%d%d", &h, &w, &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a);
		while (a--)
			paint(i);
	}
	for (int i = 0; i < h; i++) {
		printf("%d", r[i][0]);
		for (int j = 1; j < w; j++)
			printf(" %d", r[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
using namespace std;

static const int inf=1e9;
struct Node
{
    int data;
    Node *l,*r;
};
int m;
int total;

///此处必须定义二级指针 或者指针的引用 或者返回Node *才能返回修改后的p
void add_point(Node *&p,int x)
{
    if(p==NULL)
    {
        p=(Node *)malloc(sizeof(Node));
        p->data=x;
        p->l=NULL;
        p->r=NULL;
        return;
    }
    if(x < p->data)
        add_point(p->l,x);
    else
        add_point(p->r,x);
}

bool find_point(const Node *p,int x)
{
    if(p==NULL)
        return false;
    if(p->data==x)
        return true;
    else if(x<=p->data)
        return find_point(p->l,x);
    else
        return find_point(p->r,x);
}

int delete_assist(Node *&p)
{
    if(p->l!=NULL)
        delete_assist(p->l);
    else
    {
        int ans=p->data;
        p=p->r;
        return ans;
    }
}
bool delete_point(Node *&p,int x)
{
    if(p==NULL)
        return false;
    if(p->data==x)
    {
        if(p->l==NULL)
            p=p->r;
        else
        {
            if(p->r==NULL)
                p=p->l;
            else
                p->data=delete_assist(p->r);
        }
        return true;
    }
    else if(x<=p->data)
        return delete_point(p->l,x);
    else
        return delete_point(p->r,x);
}

void inorder(Node *p)
{
    if(p!=NULL)
    {
        inorder(p->l);
        printf(" %d",p->data);
        inorder(p->r);
    }
}

void preorder(Node *p)
{
    if(p!=NULL)
    {
        printf(" %d",p->data);
        preorder(p->l);
        preorder(p->r);
    }
}

int main()
{
    int i,x;
    char st[20];
    Node *tree=NULL;
    cin>>m;
    for(i=1;i<=m;i++)
    {
        scanf("%s",st);
        switch (st[0])
        {
        case 'i' :
            scanf("%d\n",&x);
            add_point(tree,x);
            break;
        case 'f' :
            scanf("%d\n",&x);
            if(find_point(tree,x))
                cout<<"yes"<<endl;
            else
                cout<<"no"<<endl;
            break;
        case 'd' :
            scanf("%d\n",&x);
            delete_point(tree,x);

            break;
        default:
            inorder(tree);
            cout<<endl;
            preorder(tree);
            cout<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 15740
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

// 検索タグ
int main() {
	// 入力
	ll K;cin>>K;
    
	// 解法
	ll ans = 0;
	REP(i,K){
		REP(j,K){
			REP(k,K){
				ll tmp = GCD(i+1,j+1);
				tmp =GCD(tmp,k+1);
				ans += tmp;
			}
		}
	}

	//出力
	printf("%lld\n", ans);
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
#define int long long

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

  int n,a,b,c; cin >> n >> a >> b >> c;
  vector<int> l(n);
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }

  int ans = 1e9;
  for(int i = 1; i < 1 << n; i++){
    for(int j = 1; j < 1 << n; j++){
      for(int k = 1; k < 1 << n; k++){
        if((i & j) || (j & k) || (k & i)) continue;
        int pp = 0,s1 = 0,s2 = 0,s3 = 0;
        for(int p = 0; p < n; p++){
          if(1 & i >> p) s1 += l[p],pp += 10;
          if(1 & j >> p) s2 += l[p],pp += 10;
          if(1 & k >> p) s3 += l[p],pp += 10;
        }
        ans = min(ans,(pp-30) + abs(a-s1) + abs(b-s2) + abs(c-s3));
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = gets.chomp!.to_i
h_n = gets.chomp!.split(" ").map(&:to_i)

head = 0
tail = n - 1

memo = []
y = h_n.slice_after(&:zero?).to_a
y.each do |sub|
    if sub.last == 0
        sub.delete_at(-1)
    end
    if sub.empty?.!
        memo.push(sub)
    end
end
count = 0

while memo.empty?.!
    arr = memo.shift
    arr.map!{|x| x - 1 }
    count += 1
    x = arr.slice_after(&:zero?).to_a
    x.each do |sub|
        if sub.last == 0
            sub.delete_at(-1)
        end
        if sub.empty?.!
            memo.push(sub)
        end
    end
end

puts count


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

using namespace std;

typedef long long ll;

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<ll> towns;
    towns.push_back(1);
    vector<bool> visited(n + 1);
    visited[1] = true;
    while (1) {
        ll cur = towns[(int)towns.size() - 1];
        ll next = a[cur];
        towns.push_back(next);
        if (visited[next]) {
            break;
        } else {
            visited[next] = true;
        }
    }
    ll size = towns.size();
    ll l = towns[size - 1];
    ll startidx;
    for (int i = 0; i < size; ++i) {
        if (towns[i] == l) {
            startidx = i;
            break;
        }
    }
    startidx++;
    if (startidx > k) {
        cout << towns[k];
    } else {
        cout << towns[startidx + (k - startidx) % (size - startidx)];
    }
    return 0;
}


Measured memory_bytes: 6904
#include<stdio.h>

#define MAX 107

int gragh [MAX][MAX];

int v[MAX];

int main(){
  int n,i,j;
  int vertex,num;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){    
      gragh[i][j] = 0;
    }
  }
  
  for(i=1;i<=n;i++){
    scanf("%d%d",&vertex,&num);
    for(j=1;j<=num;j++){
      scanf("%d",&v[j]);
      gragh[vertex][v[j]] = 1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j != 1) printf(" ");
      printf("%d",gragh[i][j]);
    }
    printf("\n");
  }



  return 0;
}





Measured memory_bytes: 2704
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
long long int arr[500005];
long long int size1[500005];
long long int m = 1000000007;
bool vis[200005] = {0};
vector<pair<ll, ll>> vec[300005];
ll count1 = 0;
vector<pair<ll, pair<ll, ll>>> vec1;
ll count2 = 0;
long long int fin(long long int node)
{
    if (node == arr[node])
        return node;
    node = arr[arr[node]];
}

void union1(long long int x, long long int y)

{
    long long int node1 = fin(x);
    long long int node2 = fin(y);

    if (size1[node1] > size1[node2])
    {
        size1[node1] += size1[node2];
        arr[node2] = node1;
    }
    else
    {
        size1[node2] += size1[node1];
        arr[node1] = node2;
    }
}
long long int fastexpo(long long int a, long long int b)
{
    long long int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        b = b / 2;
        a = (a * a) % m;
    }
    return ans;
}
void dfs(ll node)
{
    vis[node] = 1;
    //  vec1.push_back({count1, {node1, node}});

    size1[node] = count1;
    count1++;
    for (int i = 0; i < vec[node].size(); i++)
    {

        // arr[vec[node][i]] = count1;
        if (!vis[vec[node][i].first])
        {
            dfs(vec[node][i].first);
            arr[node] += arr[vec[node][i].first];
        }
    }
    count1--;
}
void dijkstra(ll s, vector<pair<ll, ll>> vec2[], ll dis5[])
{
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push(make_pair(0, s));
    dis5[s] = 0;
    while (!pq.empty())
    {
        ll u = pq.top().second;
        //  vis[u] = 1;
        pq.pop();
        for (ll i = 0; i < (ll)vec2[u].size(); i++)
        {

            ll q = vec2[u][i].second;
            ll w = vec2[u][i].first;

            if (dis5[u] + w < dis5[q])
            {
                dis5[q] = dis5[u] + w;
                pq.push(make_pair(dis5[q], q));
            }
        }
    }
}
int main()
{
    long double t;
    cin >> t;
    long double p = 2.0 * 3.141592 * t;
    cout << p;

    return 0;
}

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

int dp[3005][3005];

int main(){
  int n,t;
  cin>>n>>t;
  P ba[3005];
  rep(i,n){
    int a,b;
    cin>>a>>b;
    ba[i]={a,b};
  }
  sort(ba,ba+n);
  reverse(ba,ba+n);
  for(int i=n-1;i>=0;i--){
    rep(j,t){
      if(j<ba[i].first){
	dp[i][j]=dp[i+1][j];
      }
      else{
	dp[i][j]=max(dp[i+1][j],dp[i+1][j-ba[i].first]+ba[i].second);
      }
    }
  }
  int ma=0;
  int end[3005];
  rep(i,n-1){
    ma=max(ma,ba[i].second);
    end[i+1]=ma;
  }
  for(int i=1;i<n;i++){
    dp[i][t-1]+=end[i];
  }
  int ans=0;
  rep(i,n){
    ans=max(ans,dp[i][t-1]);
  }
  cout<<max(ans,dp[0][t])<<endl;
  return 0;
}



Measured memory_bytes: 35456
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()

class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n

n,m,k = readInts()

uf = UnionFind(n)
fc = [0]*(n+1) #friend count

for i in range(m):
	a,b = readInts()
	uf.union(a-1,b-1)
	fc[a]+=1
	fc[b]+=1

br = [0]*(n+1)

for i in range(k):
	c,d = readInts()
	if uf.find(c-1)==uf.find(d-1):
		br[c]+=1
		br[d]+=1

for i in range(1,n+1):
	print(uf.size(i-1)-1-fc[i]-br[i],end=" ")
print()

Measured memory_bytes: 10392
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N,K;
int R,S,P;
int dp[2][3];
char buf[100005];

int main(){

	scanf("%d %d",&N,&K);
	scanf("%d %d %d",&R,&S,&P);

	scanf("%s",buf);

	int ans = 0;
	int CURRENT,NEXT;
	int pre_r = 0,pre_s = 1,pre_p = 2;

	for(int i = 0; i < min(N,K); i++){

		CURRENT = 0,NEXT = 1;
		for(int a = 0; a < 2; a++){
			for(int b = 0; b < 3; b++){

				dp[a][b] = 0;
			}
		}

		switch(buf[i]){
		case 'r':
			dp[CURRENT][pre_p] += P;
			break;
		case 's':
			dp[CURRENT][pre_r] += R;
			break;
		case 'p':
			dp[CURRENT][pre_s] += S;
			break;
		}

		for(int a = 1; i+K*a < N; a++){

			for(int now = 0; now < 3; now++){

				dp[NEXT][now] = 0;
			}

			for(int pre = 0; pre < 3; pre++){
				for(int now = 0; now < 3; now++){
					if(now == pre){

						continue;
					}else{

						int tmp = dp[CURRENT][pre];

						switch(buf[i+K*a]){
						case 'r':
							if(now == 2){

								tmp += P;
							}
							break;
						case 's':
							if(now == 0){

								tmp += R;
							}
							break;
						case 'p':
							if(now == 1){

								tmp += S;
							}
							break;
						}

						dp[NEXT][now] = max(dp[NEXT][now],tmp);
					}
				}
			}
			swap(CURRENT,NEXT);
		}
		ans += max(dp[CURRENT][pre_r],max(dp[CURRENT][pre_s],dp[CURRENT][pre_p]));
	}

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

	return 0;
}


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

int main() {
  int n,k,q;cin>>n>>k>>q;
  vector<int> a(q),ans(n,k-q);
  rep(i,q){
    cin>>a[i];
    a[i]--;
    ans[a[i]]++;
  }
  rep(i,n){
    if(ans[i]>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3992
import java.util.*;
class Main
{
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n=s.nextInt();
		int m=s.nextInt();
		int sum=0;
		for(int i=0;i<n;i++)
		{
			sum=sum+i;
		}
		for(int i=0;i<m;i++)
		{
			sum=sum+i;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21972
# coding: utf-8
# hello worldと表示する
N=int(input())
s=list(map(int,input().split()))
def f(N,s,t):
    ss=0
    w=0
    for i in range(N):
        ss+=s[i]
        if t==1:
            if ss<=0:
                w+=1-ss
                ss=1
            t=-1    
        elif t==-1:
            if ss>=0:
                w+=1+ss
                ss=-1
            t=1
    return w
t=1
a=f(N,s,t)
t=-1
b=f(N,s,t)
print(min(a,b))
            
            
    

Measured memory_bytes: 14468
import math

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def factorize(n):
    primes = set()
    for p in Ps:
        if p * p > n:
            break
        while n % p == 0:
            n //= p
            primes.add(p)
    if n > 1:
        primes.add(n)
    return primes

Ps = primes(10 ** 6)
n = int(input())
As = list(map(int, input().split()))

# setwiseFlag
gcd = As[0]
for a in As:
  gcd = math.gcd(gcd, a)
setwiseFlag = (gcd == 1)

# pairwiseFlag
pairwiseFlag = True
table = [0] * (10 ** 6 + 1)
for a in As:
  table[a] += 1
for p in Ps:
  count = 0
  for _p in range(p, 10 ** 6 + 1, p):
    count += table[_p]
  if count > 1:
    pairwiseFlag = False

if pairwiseFlag:
  print('pairwise coprime')
elif setwiseFlag:
  print('setwise coprime')
else:
  print('not coprime')


Measured memory_bytes: 216236
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long int li;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main() {
  int n;
  cin >> n;
  vector<pair<string, int> > pairs(n+1);
  vector<pair<string, int> > pairss(n+1);
  
  for (int i = 1; i < n+1; i++) {
    string s;
    int p;
    cin >> s >> p;
    pairs[i] = make_pair(s, -1*p);
    pairss[i] = make_pair(s, -1*p);
  }
  sort(pairs.begin()+1, pairs.end());
	for(int i=1;i<=n;i++){
    	for(int j=1;j<=n;j++){
    		if(pairs[i]==pairss[j])cout << j << endl;
   		}
    }
    return 0;
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
	int n = in();
	LL x = 1;

	rep(i, n) {
		x = x * 2 + 1;
	}

	cout << x * 2 << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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


void solve(long long N, std::vector<long long> A){
    sort(A.begin(),A.end(),greater<long long>());
    ll ans = 0;
    rep(i,N){
        if(i == 0) continue;
        ll d = i/2;
        ans += A[d];
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4792
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int K = scanner.nextInt();
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    if (A % K == 0 || B % K == 0) {
      System.out.println("OK");
      return;
    }
    if (A / K == B / K) {
      System.out.println("NG");
    } else {
      System.out.println("OK");
    }
  }
}


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

int main()
{
    int n,m,num=0;
    long long k;
    cin>>n>>m>>k;
    long long a[n+1],b[m+1];
    memset(a, 0, (n+1)*sizeof(a[0]));
    memset(b, 0, (m+1)*sizeof(b[0]));
    for(int i=0; i<n; i++)
    {
        cin>>a[i+1];
        a[i+1]+=a[i];
    }
    for(int i=0; i<m; i++)
    {
        cin>>b[i+1];
        b[i+1]+=b[i];
    }
    for(int i=0, j=m; i<=n; ++i)// iterate on all possible values of a & b and we start with zero to consider the case of reading all from b
    {
        if(a[i]>k)// if a alone exceeds the sum then break
            break;
        while(a[i]+b[j]>k)// start with the largest value of b possible and decrease until you reach
            --j;
        num=std::max(i+j, num);//use max to store the max value of all possible combinations
    }
    cout << num;
    return 0;
}

Measured memory_bytes: 6692
/**
 *   author: sahushivam
 *   created: 14 January 2020 (Tuesday)  20:05:21
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

void solve(){
    int h,c,m; cin>>h>>c>>m; cout<<(m-1)/max(h,c)+1;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

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

long long n, m;
vector<vector<int>> g;
vector<int> res;
vector<bool> used;

void solve();

int main() {
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g[--a].push_back(--b);
    g[b].push_back(a);
  }
  solve();
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); ++i) {
    if (i != 0) cout << " ";
    cout << res[i] + 1;
  }
  cout << endl;
  return 0;
}

void solve() {
  int st = 0;
  while (!g[st].size()) ++st;
  used.assign(n, 0);
  used[st] = 1;
  res.push_back(st);
  for (int now = st, bf = -1; now != bf;) {
    bf = now;
    for (auto to : g[now])
      if (!used[to]) {
        used[to] = 1;
        res.push_back(to);
        now = to;
        break;
      }
  }
  reverse(res.begin(), res.end());
  for (int now = st, bf = -1; now != bf;) {
    bf = now;
    for (auto to : g[now])
      if (!used[to]) {
        used[to] = 1;
        res.push_back(to);
        now = to;
        break;
      }
  }
}


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

int main() {
  char a[3];
  for(int i = 0;i < 3;i++){
    cin >> a[i];
    if(a[i] == '1'){
      a[i] = '9';
    }else{
      a[i] = '1';
    }
  }
  cout << a[0] << a[1] << a[2] << endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;

int main() {
		int n;
		int date_x[100];
		int date_y[100];
		double sum = 0;
		double var = 0;
		double D[4] = { 0 };
		string haki;
		cin >> n;
		getline(cin, haki);
		for (int i = 0; i < n; i++) {
			cin >> date_x[i];
		}
		for (int i = 0; i < n; i++) {
			cin >> date_y[i];
		}
		for (int i = 0; i < n; i++) {
			D[0] += abs(date_x[i] - date_y[i]);
			D[1] += pow(abs(date_x[i] - date_y[i]), 2);
			D[2] += pow(abs(date_x[i] - date_y[i]), 3);
			if(D[3] < abs(date_x[i] - date_y[i]))D[3] = abs(date_x[i] - date_y[i]);
		}
		D[1] = pow(D[1], 1.0 / 2.0);
		D[2] = pow(D[2], 1.0 / 3.0);

		for (int i = 0; i < 4; i++) {
			cout << fixed << D[i] << endl;
		}


	return 0;
}


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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;cin>>n;
    vi v;
    f(n){
        int x;
        cin>>x;
        v.pb(x);
    }
    int ans=0;
    bool f=true;
    while(f){
        for(auto &val:v){
            if(val%2==1){
                f=false;
                break;
            }
            val/=2;
        }
        if(f) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	double ans = 0;
	int tmp;
	int n, k;
	double pr;
	cin >> n >> k;
	REP1(i, n){
		tmp = i;
		pr = (double)1 / n;
		while(tmp < k){
			tmp *= 2;
			pr *= 0.5; 
		}
		ans += pr;
	}
	cout << setprecision(15) << fixed << ans << endl;
}

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

int main(){
  string s;
  cin >> s;
  vector<int> v(26, 0);
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < 26; j++){
      if(s[i] == j + 97){
        v[j]++;
        break;
      }
    } 
  }
  bool f = true;
  for(int i = 0; i < 26; i++){
    if(v[i] % 2 == 1){
      cout << "No" << endl;
      f = false;
      break;
    }
  }
  
  if(f){ cout << "Yes" << endl; }
}

Measured memory_bytes: 256
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
///#pragma GCC optimize("unroll-loops")

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

///#include<ext/pb_ds/assoc_container.hpp>
///#include<ext/pb_ds/tree_policy.hpp>
///using namespace __gnu_pbds;
///template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///(X).order_of_key(value) /// return lower_bound(value)
///(*X).find_by_order(index) /// return value (0 index)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// mt19937_64 (long long)

typedef long long ll;
typedef long double ld;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vbb;

const int N = 100001;
const int MOD = 1000000007;
const ll INF = 1e18;

#define fast() ios_base::sync_with_stdio(false),cin.tie(NULL)
#define next(x) next_permutation(all(x))
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rev(a) reverse(all(a))
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'
#define PI acos(-1)
#define Case(x) cout<<"Case "<<x<<": "
#define strtoint(a) atoi(a.c_str())
#define dbg(x) cerr<<#x<<" is "<<x<<'\n';
#define fix(x) cout<<fixed<<setprecision(x)
#define leastonepos(x) __builtin_ffs(x)
#define leadingoff(x) __builtin_clz(x)
#define trailingoff(x) __builtin_ctz(x)
#define numofone(x) __builtin_popcount(x)

#define coutv(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define cinv(v) for(auto &it:v)cin>>it;

///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///



int main()
{
    fast();
    int tc=1,cs=0;
    //cin>>tc;
    while(tc--)
    {
        ll a;
        cin>>a;
        ld b;
        cin>>b;
        ll ans=(ld)a*b;
        cout<<ans<<nl;
    }
}


Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool bubble_sort (vector<string> & a )
{
	vector<string> pre = a;
	int n = a.size();
	rep (i, n ){
		for (int j = n-1; j >= i + 1; j-- ){
			if ((int)(a[j][1] - '0' ) < (int)(a[j-1][1] - '0' ) ){
				swap (a[j], a[j-1] );
			} // end if
		} // end for
	} // end rep


	vector<string> p(10, "" );
	vector<string> q(10, "" );
	rep (i, n ){
		int num1 = (int)(pre[i][1] - '0' );
		p[num1] += pre[i][0];
		int num2 = (int)(a[i][1] - '0' );
		q[num2] += a[i][0];
	} // end rep

	rep (i, 10 )
		if (p[i] != q[i] ) return false;

	return true;
}

bool selection_sort (vector<string> & a )
{
	vector<string> pre = a;
	int n = a.size();

	rep (i, n ){
		int mini = i;
		for (int j = i; j < n; j++ ){
			if ((int)(a[j][1] - '0' ) < (int)(a[mini][1] - '0' ) ){
				mini = j;
			} // end if
		} // end for
		if (i != mini ){
			swap (a[i], a[mini] );
		} // end if
	} // end rep

	vector<string> p(10, "" );
	vector<string> q(10, "" );
	rep (i, n ){
		int num1 = (int)(pre[i][1] - '0' );
		p[num1] += pre[i][0];
		int num2 = (int)(a[i][1] - '0' );
		q[num2] += a[i][0];
	} // end rep

	rep (i, 10 )
		if (p[i] != q[i] ) return false;

	return true;
}
int main()
{
	int n;
	scanf ("%d", &n );
	vector<string> a (n, "" );
	rep (i, n ) cin >> a[i];

	vector<string> ans1 = a, ans2 = a;
	bool res1 = bubble_sort (ans1 );
	bool res2 = selection_sort (ans2 );
	rep (i, n ){
		cout << ans1[i];
		cout << (i != n - 1 ? ' ' : '\n' );
	} // end rep
	res1 ? printf("Stable\n" ) : printf ("Not stable\n" );
  
	rep (i, n ){
		cout << ans2[i];
		cout << (i != n - 1 ? ' ' : '\n' );
	} // end rep
	res2 ? printf("Stable\n" ) : printf ("Not stable\n" );

	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue> 
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
const long long mod=1e9+7;
int a[100001]={0};
int main()
{
	long long n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		long long ai;
		cin>>ai;
		a[ai]++; 
	}
	if (n%2)
	{
		if (a[0]!=1)
		{
			cout<<0<<endl;
			return 0;
		}
		for (int i=2;i<=n;i+=2)
		{
			if (a[i]!=2)
			{
				cout<<0<<endl;
				return 0;
			}
		}
		n/=2;
		long long ans=1;
		for (int i=0;i<n;i++) ans=ans*2%mod;
		cout<<ans<<endl;
		return 0;
	}
	else 
	{
		for (int i=1;i<=n;i+=2)
		{
			if (a[i]!=2)
			{
				cout<<0<<endl;
				return 0;
			}
		}
		n/=2;
		long long ans=1;
		for (int i=0;i<n;i++) ans=ans*2%mod;
		cout<<ans<<endl;
		return 0;
	}
}
 

Measured memory_bytes: 640
#include<iostream>
#include <ctype.h>
#include <string.h>
using namespace std;

int main(){
  string s ;
  cin >> s;
  int len = s.size();
  int f = 1;
  if(s[0]!='A') f = 0;
  else{
	int c = 0;
	for(int i=0;i<len;i++){
	  if(isupper(s[i])){
		c = c+1; 
	  }
	}
	//cout << c << " ";
	if(c!=2) f= 0;
	else{
	  int i = 0;
	  while(s[i]!='C'){
		i++;
	  }
	  if(i<2 || i>len-2) f= 0;
	}
  }

  if(f == 0)
	cout << "WA";
  else
	cout << "AC";
}


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

int main() {
    int N; cin >> N;
    long long int res = 0;
    vector<int> f(N);
    for (int i = 0; i < N; i++) cin >> f[i];
    sort(f.begin(), f.end(), greater<int>());   // descending order.
    priority_queue<int> h;
    h.push(f[0]);
    for (int i = 1; i < N; i++) {
        int temp = h.top();
        h.pop();
        res += temp;
        h.push(f[i]);
        h.push(f[i]);
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 5088
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
vector<int>g[2005];
int n,m,ml,sum;
inline void dfs(int x,int fa,int d)
{
	if(d>m/2)
		sum++;
	for(int i=0;i<g[x].size();i++)
		if(g[x][i]!=fa)
			dfs(g[x][i],x,d+1);
}
inline void dfs1(int x,int fa,int d)
{
	if(d>m/2)
		sum++;
	for(int i=0;i<g[x].size();i++)
		if(g[x][i]!=fa)
			dfs(g[x][i],x,d+1);
	for(int i=0;i<g[fa].size();i++)
		if(g[fa][i]!=x)
			dfs(g[fa][i],fa,d+1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int ans=0x3f3f3f3f;
	if(m%2==0)
	{
		for(int i=1;i<=n;i++)
		{
			sum=0;
			dfs(i,0,0);
			ans=min(sum,ans);
		}
		printf("%d\n",ans);
	}
	else
	{
		for(int i=1;i<=n;i++)
			for(int x=0;x<g[i].size();x++)
			{
				sum=0;
				dfs1(i,g[i][x],0);
				ans=min(sum,ans);
			}
		printf("%d\n",ans);
	}
}////

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  unsigned long long n,a,b;
  cin >> n >> a >> b;
  unsigned long long ans=0;
  unsigned long long s=n/(a+b);
  ans+=a*s;
  unsigned long long t=n%(a+b);
  ans+=min(t, a);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<string,string>P;
map<P,int>mp;
vector<P>vec;
vector<P>ans;

int main(){
  int n,f;
  cin>>n>>f;
  for(int i=0;i<n;i++){
    int m;
    string s[109];
    cin>>m;
    for(int j=0;j<m;j++){
      cin>>s[j];
    }
    for(int j=0;j<m;j++){
      for(int k=j+1;k<m;k++){
	string a=s[j],b=s[k];
	if(a>b)swap(a,b);
	if(mp.count(P(a,b))==0){
	  vec.push_back(P(a,b));
	  mp[P(a,b)]=1;
	}
	else{
	  mp[P(a,b)]++;
	}
      }
    }
  }
  for(int i=0;i<vec.size();i++){
    if(mp[vec[i]]>=f){
      ans.push_back(vec[i]);
    }
  }
  sort(ans.begin(),ans.end());
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++){
    cout<<ans[i].first<<' '<<ans[i].second<<endl;
  }
  return(0);
}



Measured memory_bytes: 3756
#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(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;



int main(){
 ll n; cin>>n;
 vector<ll> a(n); REP(i,n)cin>>a[i];
 sort(ALL(a));
 reverse(ALL(a));
 ll max_a1=0,max_a2=0;

 int i=1;
 while(i<n){
     if(a[i]==a[i-1]){
      if(a[i]>max_a1) max_a1=a[i];
      else if(a[i]>max_a2) max_a2=a[i];
      i++;
    }
    i++;
     }
   cout<<max_a1*max_a2<<endl;
 
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>

using namespace std;

int solve(int a, int year, int t, double r, int q)
{
  int b, x;
  int y = 0;

  if(t == 1){
    for(int i = 0; i < year; i++){
      b = a * r;
      x = a + b - q;
      a = x;
    }
  }

  if(t == 0){
    for(int i = 0; i < year; i++){
      b = a * r;
      x = a - q;
      y += b;
      a = x;
    }
  }

  return x + y;
}

int main()
{
  int m, a, year, n, t, q;
  double r;
  int d[110];
  cin >> m;
  for(int i = 0; i < m; i++){
    cin >> a;
    cin >> year;
    cin >> n;
    for(int i = 0; i < n; i++){
      scanf("%d %lf %d", &t, &r, &q);
      d[i] = solve(a, year, t, r, q);
    }
    int max = 0;
    for(int i = 0; i < n; i++){
      if(max < d[i]) max = d[i];
    }
    cout << max << endl;
  }

  return 0;
}

Measured memory_bytes: 1276
use std::collections::HashMap;

/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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,
        v_a: [u64; n],
    }

    let mut v_o = HashMap::with_capacity(n/2);
    let mut v_e = HashMap::with_capacity(n/2);

    for v_p in v_a.chunks(2) {
        *v_o.entry(v_p[0]).or_insert(0) += 1;
        *v_e.entry(v_p[1]).or_insert(0) += 1;
    }

    let max_o = v_o.iter().max_by_key(|&(_, v)| v).unwrap();
    let max_e = v_e.iter().max_by_key(|&(_, v)| v).unwrap();

    let ans = if max_o.0 != max_e.0 {
        n - max_o.1 - max_e.1
    } else {
        let second_o = match v_o.iter()
            .filter(|&a| a != max_o)
            .max_by_key(|&(_, v)| v) {
                Some((_, second_o)) => *second_o,
                _ => 0,
            };

        let second_e = match v_e.iter()
            .filter(|&a| a != max_e)
            .max_by_key(|&(_, v)| v) {
                Some((_, second_e)) => *second_e,
                _ => 0,
            };

        std::cmp::min(n - second_o - max_e.1, n - max_o.1 - second_e)
    };

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <tuple>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#define REP(i, n) for(int i = 0; i < n; i++)
//using ll = long long;
using namespace std;


int main() {

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

  int n,tmp=0;
  cin >> n;
  int a[n];
  
  REP(i,n){
    a[i]=0;
  }

  REP(i,n-1){
    cin >> tmp;
    a[tmp-1] += 1;
  }

  REP(i,n){
    cout << a[i] << endl;
  }
      
}


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

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Read().Split(' ');
            var a = new string(input[0][0], int.Parse(input[1]));
            var b = new string(input[1][0], int.Parse(input[0]));

            Console.WriteLine(int.Parse(input[0]) < int.Parse(input[1]) ? a : b);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long dp[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	long long ret=0;
	for(int i=b;i>=1;i--){
		dp[i]=pw(b/i,a);
		for(int j=i+i;j<=b;j+=i){
			dp[i]=(dp[i]+mod-dp[j])%mod;
		}
		ret+=dp[i]*i%mod;
	}
	ret%=mod;
	printf("%lld\n",ret);
}

Measured memory_bytes: 2516