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

const int N=2009;
typedef long long ll;
bitset<N*N> b;
ll n,a[N],sum;

int main()
{
	int n;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		sum+=a[i];
	
	b[0]=1;
	for(int i=1;i<=n;i++)
		b|=b<<a[i];
	for(int i=ceil((double)sum/2.0);i<N*N;i++)
		if(b[i])
			return printf("%d\n",i),0;
	
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>

int data[10001];
int rank[10001];

int find(int x){
  if(data[x] == x){
    return x;
  }else{
    data[x] = find(data[x]);
    return data[x];
  }
}

void Union(int x,int y){
  int a = find(x);
  int b = find(y);
  if(a != b){
    if(rank[a] > rank[b]){
      data[b] = a;
      rank[a]++;
    }else{
      data[a] = b;
      rank[b]++;
    }
  }
}

bool Some(int x,int y){
  return find(x) == find(y);
}

int main(){
  int n, q, com, x, y;
  std::cin >> n >> q;
  for(int i=0;i<=n;i++){
    data[i]=i;
  }
  while(std::cin >> com >> x >> y){
    if(com){
      std::cout<< Some(x,y) << std::endl;
    }else{
      Union(x,y);
    }
  }
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,Y; cin>>N>>Y;
	Y /= 1000;
	int MAX = 20000;
	rpz(y10,N+1){
		rpz(y5,N+1){
			int y1 = max(0, N - y10 - y5);
			if(y10+y5+y1 != N) continue;
			if(y10*10+y5*5+y1 == Y){
				cout<<y10<<" "<<y5<<" "<<y1<<endl;
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
li = [(int(str(x)[0]), int(str(x)[-1])) for x in range(1, n + 1)]

c = dict(Counter(li).items())

cnt = 0
for k, v in c.items():
    a, b = k
    if a == b:
        cnt += v**2
    elif (b, a) in c:
        v2 = c[(b, a)]
        cnt += v * v2

print(cnt)

Measured memory_bytes: 17652
# coding: utf8

def read_int_n():
    return list(map(int, input().split()))

if __name__ == "__main__":
    n = read_int_n()
    ans = 0
    for i in range(3):
        n[i] *= 10
        sum = 0
        for k in n:
            sum += k
        if sum > ans:
            ans = sum
        n[i] /= 10
    print(int(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    if(k==1)
        cout<<0<<endl;
    else if(k==2)
        cout<<n-2<<endl;
    else{
        n = n-1;
        n = n-(k-2);
        cout<<n-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	//sort(a.begin(),a.end());
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int pre = -999;
	rep(i, n) {
		if (pre <= a[i] - 1) {
			pre = a[i] - 1;
		}
		else if (pre <= a[i]) {
			pre = a[i];
		}
		else {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}









Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,x,tuk=1000000,sum=0;
	cin>>n>>x;
	vector<int>m(n);
	rep(i,n){
	    cin>>m[i];
	    tuk=min(tuk,m[i]);
	    sum+=m[i];
	}
	int ans=(x-sum)/tuk+n;
	cout<<ans;
	return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

using Graph = vector<vector<int>>;

int main() {
	// 頂点数と辺数
	int N, M;
	cin >> N >> M;

	// グラフ入力受取 (ここでは無向グラフを想定)
	Graph G(N+1);
	FOR(i,1,M) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vector<int> prev(N+1, -1);
	queue<int> que;
	prev[1] = 0;

	que.push(1); // 0 を橙色頂点にする

	// BFS 開始 (キューが空になるまで探索を行う)
	while (!que.empty()) {
		int v = que.front(); // キューから先頭頂点を取り出す
		que.pop();

		// v から辿れる頂点をすべて調べる
		for (int nv : G[v]) {
			if (prev[nv] != -1) continue; // すでに発見済みの頂点は探索しない

			// 新たな白色頂点 nv について距離情報を更新してキューに追加する
			prev[nv] = v;
			que.push(nv);
		}
	}

	ps(Yes)
	FOR(i, 2, N) {
		pv(prev[i]);
	}
}

Measured memory_bytes: 10120
/* ex 5_4
   Sweet_Sweet_soul */

#include <stdio.h>

int main(void){
    //10文字以下なので最大の要素数は\0を含めて11
    //pointはstrの各要素へのポインタ
    char str[11],*point;
    //countが途中経過、ansが答え
    int count,ans;
    //各種変数の初期化&入力
    point=str;
    count=0;
    ans=0;
    scanf("%s",str);
    //ヌル文字まで全探索
    while(*point){
        //ポイントが指し示すのがACGTの場合countを1増やす
        if(*point=='A' || *point=='C' || *point=='G' || *point=='T'){
            count++;
        }
        //それ以外ならcountの値に応じてansを更新しcountを初期化
        else{
            if(count>ans){
                ans=count;
            }
            count=0;
        }
        point++;
    }
    //最後にもう一度ansの更新を行う
    if(count>ans){
        ans=count;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1716
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))


ans = -1
diff = float('inf')
for i in range(N):
    d = abs(1000*T-6*H[i]-1000*A)

    if d < diff:
        diff = d
        ans = i + 1
print(ans)

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

// DPテーブル
const int MAX_N = 15;
const int MAX_W = 110000;
int dp[MAX_N][MAX_W]; // 12 種類だが余裕をもつ

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

	// 品物を列挙 (価値はすべて 1)
	vector<int> weight;
	for (int i = 1; i <= W; i *= 6) weight.push_back(i);
	for (int i = 9; i <= W; i *= 9) weight.push_back(i); // 1 が重複しないように (しても問題はない)
	int n = (int)weight.size();

	// DP初期条件: dp[i][0] = 0
	for (int i = 0; i < MAX_N; ++i) for (int w = 0; w < MAX_W; ++w) dp[i][w] = 1 << 29; // INF
	for (int i = 0; i <= n; ++i) dp[i][0] = 0;

	// DPループ
	for (int i = 0; i < n; ++i) {
		for (int w = 0; w <= W; ++w) {
			if (w >= weight[i]) dp[i + 1][w] = min(dp[i + 1][w - weight[i]] + 1, dp[i][w]);
			else dp[i + 1][w] = dp[i][w];
		}
	}

	cout << dp[n][W] << endl;
}

Measured memory_bytes: 6656
def main():
    n = int(input())
    r = [list(map(int, input().split())) for _ in range(n)]
    b = [list(map(int, input().split())) for _ in range(n)]

    #左から考える
    b.sort(key=lambda x: x[0])
    ans = 0

    for nb in b:
        #残っている青玉の一番左のものと条件を満たすものをサーチする
        r_sorted = [i for i in r if i[0] < nb[0] and i[1] < nb[1]]
        #もし条件を満たすものがるなら
        if r_sorted:
            #その中で一上のものを取り除く
            r_sorted.sort(key=lambda x: x[1], reverse=True)
            r.remove(r_sorted[0])
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> monster(n + 1), player(n);
  for(int i = 0; i < n + 1; ++i) cin >> monster[i];
  for(int i = 0; i < n; ++i) cin >> player[i];
  long long ans = 0;
  for(int i = 0; i < n; ++i){
    if(player[i] > monster[i]){
      ans += monster[i];
      player[i] -= monster[i];
      if(player[i] > monster[i + 1]){
        ans += monster[i + 1];
        monster[i + 1] = 0;
      }
      else {
        ans += player[i];
        monster[i + 1] -= player[i];
      }
    }
    else {
      ans += player[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
n,s = list(map(int, input().split()))

a = list(map(int, input().split()))

dp = [[0 for i in range(s+1)] for j in range(n+1)]

beki2 = [1]
MOD = 998244353
for i in range(4000):
    beki2.append(beki2[-1]*2%MOD)

for i in range(n):
    ai = a[i]
    if(ai<=s):
        dp[i+1][ai] += beki2[i]
    for j in range(s+1):
        valj = dp[i][j]
        dp[i+1][j] += (valj * 2)
        wa = j + ai
        if(wa <= s):
            dp[i+1][wa] += valj
    for j in range(s+1):
        dp[i+1][j] %= MOD

print(dp[-1][-1])



Measured memory_bytes: 147932
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		doIt();
	}
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n != 0){
			ArrayList<Double> per = new ArrayList<Double>();
			ArrayList<String> names = new ArrayList<String>();
			for(int k = 0; k < n; k++){
				String name = sc.next();
				//System.out.println(k + name);
				//P0 A1 B2 C3 D4 E5 F6 S7 M8
				int[] v = new int[9];
				for(int i = 0; i < 9; i++){
					v[i] = sc.nextInt();
					//System.out.println(i + " " + v[i]);
				}
				//f*s*m - p
				int income = v[6]*v[7]*v[8] - v[0];
				//a + b + c + m*(d+e)
				int time = v[1] + v[2] + v[3] + v[8]*(v[4] + v[5]);
				double p = (double)income / (double)time;
				//System.out.println(name + " = " + p);

				//pの値に応じて入れる
				int size = per.size();
				int j;
				for(j = 0; j < size; j++){
					double tmp = per.get(j);
					if(p > tmp){
						break;
					}
					else if(p == tmp){
						if(name.compareTo(names.get(j)) < 0){
							break;
						}
					}
				}
				per.add(j, p);
				names.add(j, name);
			}
			int len = names.size();
			for(int k = 0; k < len; k++){
				System.out.println(names.get(k));
			}
			System.out.println("#");
			n = sc.nextInt();
		}
	}
}

Measured memory_bytes: 13000
def tpbc_2018_c():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    a.sort()
    low = a[:len(a) // 2]
    high = a[len(a) // 2:]
    if len(a) % 2 == 0:
        return 2 * (sum(high) - sum(low)) + max(low) - min(high)
    else:
        low2 = a[:len(a) // 2 + 1]
        high2 = a[len(a) // 2 + 1:]
        return max(2 * (sum(high) - sum(low)) - high[0]-high[1],2 * (sum(high2) - sum(low2))+low2[-2]+low2[-1])
 
 
print(tpbc_2018_c())

Measured memory_bytes: 8532
import java.util.*;

class Main{
  static public void main(String[] args){
    Scanner sc=new Scanner(System.in);
    List<String> g1=new ArrayList<>();
    List<String> g2=new ArrayList<>();
    List<String> g3=new ArrayList<>();
    g1.add("1");
    g1.add("3");
    g1.add("5");
    g1.add("7");
    g1.add("8");
    g1.add("10"); 
    g1.add("12");
    g2.add("4");
    g2.add("6");
    g2.add("9");
    g2.add("11");
    g3.add("2");
    String str=sc.next(),str2=sc.next();
    if(g1.contains(str)&&g1.contains(str2))System.out.print("Yes");
    else if(g2.contains(str)&&g2.contains(str2))System.out.println("Yes");
    else if(g3.contains(str)&&g3.contains(str2))System.out.println("Yes");
    else System.out.println("No");
    
    sc.close();
  }
}


Measured memory_bytes: 35516
#include <iostream>
#include <algorithm>
#include<vector>
using namespace std;
int main(void){
    int n,s,sum=0;
    cin >> n;
    vector<int> V,v;
    for(int i = 0;i<n;i++){
        cin >> s;
        V.push_back(s);
        sum += s;
    }
    if(sum%10 == 0) {
        for(int i=0;i<n;i++){
            int iv = V[i];
            sum=0;
            if(iv % 10!=0) v.push_back(iv);
            for(int j=0 ;j<n;j++){
                
                if(i != j){
                    sum += V[j];
                    int a = iv + V[j];
                    if(a % 10!=0) v.push_back(a);
                }
                
            }
            if(sum % 10!=0) v.push_back(sum);
        }
        sort(v.begin(),v.end(),greater<int>() );
        if(v.size()!=0) cout<<v[0];
        else cout<<0;
    }
    else cout<<sum;
    
}


Measured memory_bytes: 384
# coding: utf-8
a,b = map(int, input().split())
count=[0]*a
for i in range(b):
    n = int(input())
    num_list = list(map(int, input().split())) 
    for j in num_list:
       count[j-1]+=1
c=0

for i in range(a):
    if count[i]==0:
        c+=1
print(c)

Measured memory_bytes: 9180
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n;

	cin>>n;

	vc s(n);

	vi sum;

	rep(i, n) cin>>s[i];

	int k=0, count=1;
	bool flag;

	if(s[0]=='('){
		flag=true;
	}else{
		flag=false;
	}

	while(k<n-1){
		if(s[k]==s[k+1]){
			count++;
		}else{
			sum.push_back(count);
			count=1; flag=!flag;
		}
		k++;
	}
	sum.push_back(count);

	int size=sum.size(), front=0, back=0, temp=0;

	flag=(s[0]==')')?true:false;

	if(flag){
		front+=sum[0];
	}

	for(int i=(int)flag; i<size-1; i+=2){
		int d=sum[i]-sum[i+1];
		if(temp+d>=0){
			temp+=d;
		}else{
			front+=-(temp+d);
			temp=0;
		}
	}

	if(s[n-1]=='('){
		back+=sum[size-1];
	}
	if(temp<0){
		front-=temp;
	}else{
		back+=temp;
	}

	rep(i, front) cout<<"(";
	rep(i, n) cout<<s[i];
	rep(i, back) cout<<")";
	cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

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

  bool can = false;
  int ans = 0;
  rep(i,50000) {
    if (i * 108 / 100 == N) {
      can = true;
      ans = i;
    }
  }

  if (can) cout << ans << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
use std::io::Read;
use std::collections::BTreeSet;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();

    let mut set = buf.split_whitespace()
        .map(|s| s.parse::<usize>().unwrap())
        .collect::<BTreeSet<usize>>();

    let r = set.clone();
    let max = r.iter().max().unwrap();
    set.remove(max);

    println!("{}", set.iter().product::<usize>() / 2)
}


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


int main()
{
	int N,K,len=0;
	cin >> N >> K;
	int l[55];
	int i = 0;
	while (i < N)
		cin >> l[i++];
	sort(l, l+N, greater<int>());
	i = 0;
	while (i < K)
	{
		len += l[i];
		i++;
	}
	cout << len << endl;
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,p,i,j,k,n=0;
     string s;
     cin>>s;
     for(i=0;i<s.size();i++){
        n=n*10+s[i]-'0';
     }
     a=s.size();
     if(a==6){
        p=9+(999-100+1)+(99999-10000+1);
     }
     else if(a==5){p=9+(999-100+1)+n-10000+1;}
      else if(a==4){p=9+(999-100+1);}
       else if(a==3){p=9+n-100+1;}
        else if(a==2){p=9;}
         else if(a==1){p=n-1+1;}
         cout<<p<<endl;




}



Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        String s = scanner.next();
        if(s.length() <= k){
            System.out.println(s);
        }else{
            System.out.println(s.substring(0,k)+"...");
        }
    }
}



Measured memory_bytes: 38652
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long int ll;

int main(){
  int n;  cin >> n;
  map<string, int> mp;
  int other = 0;
  int minAns, maxAns;
  vector<int> rate(100);
  rep(i, 0, n){
    cin >> rate[i];
    if(1 <= rate[i] and rate[i] <= 399){
      mp["灰色"]++;
    }
    else if(400 <= rate[i] and rate[i] <= 799){
      mp["茶色"]++;
    }
    else if(800 <= rate[i] and rate[i] <= 1199){
      mp["緑色"]++;
    }
    else if(1200 <= rate[i] and rate[i] <= 1599){
      mp["水色"]++;
    }
    else if(1600 <= rate[i] and rate[i] <= 1999){
      mp["青色"]++;
    }
    else if(2000 <= rate[i] and rate[i] <= 2399){
      mp["黄色"]++;
    }
    else if(2400 <= rate[i] and rate[i] <= 2799){
      mp["橙色"]++;
    }
    else if(2800 <= rate[i] and rate[i] <= 3199){
      mp["赤色"]++;
    }
    else{
      other++;
    }
  }
  if(mp.size() == 0) {
    minAns = 1;
    maxAns = other;
  }
  else {
    minAns = mp.size();
    maxAns = minAns + other;
  }

  cout << minAns << " " << maxAns << endl;
  return 0;
}

Measured memory_bytes: 256
Q = int(input())

n = 10 ** 5
is_prime = [True for i in range(n)]
is_prime[0], is_prime[1] = False, False
for i in range(2, n):
    if is_prime[i]:
        j = 2 * i
        while j < n:
            is_prime[j] = False
            j += i

like_num = [0 for i in range(n)]
rec = 0
for i in range(1, n, 2):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        rec += 1
    like_num[i] = rec

for i in range(Q):
    l, r = map(int, input().split())
    if l == 1:
        print(like_num[r])
    else:
        print(like_num[r] - like_num[l - 2])


Measured memory_bytes: 5160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int a = 1;

		while (a != 0) {
			a=0;
			for (int i = 2; i <= X / 2; i++) {
				if (X % i == 0) {
					a++;
				}
			}
			if (a != 0) {
				X++;
			}
		}
		System.out.println(X);
	}
}

Measured memory_bytes: 22100
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim sw As Integer = 0

        For i As Integer = 1 To N
            Dim A As Integer = NextInt() Mod 2
            sw = sw Xor A
        Next

        If sw = 0 Then
            WriteLine("YES")
        Else
            WriteLine("NO")
        End If
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module


Measured memory_bytes: 26676
import sys
import heapq

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

g = [[] for _ in range(N)]
for i in range(M):
  a,b = map(int,input().split())
  a -= 1; b -= 1
  g[a].append(b)
  g[b].append(a)#番号を修正。0スタートに。
#print(g)

INF = float('inf')
reach = [INF for _ in range(N)] #0からの距離を記録。INF未到達。
reach[0] = 0
par = [-1 for _ in range(N)] #親の位置を記録

Q =[]
heapq.heappush(Q, (0,0)) #0からの距離と頂点を入れる。

while Q:
  d,v = heapq.heappop(Q)
  for i in range(len(g[v])): #点vから行ける点をすべて探索
    u = g[v][i] #今探索している点
    #print(v,u)
    if u == 0: #始点の場合はスルー
      continue
    if reach[u] != INF: #到達済みならスキップ
      continue
    reach[u] = d + 1 #探索中の点の到達を記録。
    par[u] = v
    heapq.heappush(Q, (reach[u],u))

#print(reach,par)
if INF not in reach[1:]:
  print("Yes")
  for i in range(1,N):
    ans = par[i]+1
    print(ans)
else:
  print("No")

Measured memory_bytes: 38764
N, X = map(int, input().split())
x = [abs(X - int(i)) for i in input().split()]

def f(a, b):
    if b == 0:
        return a
    return f(b, a % b)

tmp = 1
for i in range(len(x)-1):
    x[i+1] = f(x[i], x[i+1])

print(x[len(x)-1])


Measured memory_bytes: 14212
N, K = map(int, input().split())

upper = (N - 1) * (N - 2) // 2
if K <= upper:
    pair = [(1, i) for i in range(2, N + 1)]
    rest = upper - K

    edge = []
    for i in range(2, N):
        for j in range(i + 1, N + 1):
            edge.append((i, j))
    pair.extend(edge[:rest])

    print(len(pair))
    for p in pair:
        print(*p)
else:
    print(-1)


Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int numberOfPlaces;
    cin >> numberOfPlaces;
    double t0;
    cin >> t0;
    double desire;
    cin >> desire;
    vector<double> temp(numberOfPlaces);
    for (int i = 0; i < numberOfPlaces;++i){
        double h;
        cin >> h;
        temp[i] = t0 - h * 0.006;
    }
    int id=0;
    double diff=abs(temp[0]-desire);
    for (int i = 1; i < numberOfPlaces;++i){
        if(abs(temp[i]-desire)<diff){
            id = i;
            diff = abs(temp[i] - desire);
        }
    }
    cout << id + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    vector<ll> num(4);
    rep(i,4)cin >> num[i];
    sort(all(num));
    if(num[0] == 1 && num[1] == 4 && num[2] == 7 && num[3] == 9)cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[110];
	scanf("%s", s);
	int len = strlen(s);
	int cnt = 0;
	for(int i=0; i<len/2; i++)
	{
		if(s[i]!=s[len-i-1]) cnt++;
	}
	printf("%d\n", cnt);
	return 0;
 } 

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

using namespace std;

long comb(long n, long k) {
  if (n < k) { return 0; }
  long res = 1;
  for (int i = n; i > n - k; i--) { res *= i; }
  for (int i = 1; i <= k; i++) { res /= i; }
  return res;
}

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

  int as[n];
  int cnt[n + 1];
  for (int i = 0; i <= n; i++) { cnt[i] = 0; }
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    cnt[as[i]]++;
  }

  long sum = 0;
  for (int i = 0; i <= n; i++) { sum += comb(cnt[i], 2); }

  for (int i = 0; i < n; i++) { cout << sum - (cnt[as[i]] - 1) << endl; }
}


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

int m,n;

int zanzo[100010];
int magic(int p){
    if (zanzo[p]&1){
        zanzo[p-1]|=2;
        zanzo[p+1]|=2;
    }
}

int main(){
    int i,j,k;
    
    cin >>n>>m;
    
    zanzo[1]=1;
    int p=1;
    int a,b;
    for (i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        magic(p);
        swap(zanzo[a],zanzo[b]);
        if (zanzo[a]&1)
            p=a;
        if (zanzo[b]&1)
            p=b;
        magic(p);
    }
    int count = 0;
    for (i=1;i<=n;i++){
        count+=!!zanzo[i];
    }
    
    //debuga(zanzo,n+1);
    cout << count << endl;
    

    return 0;
}

Measured memory_bytes: 640
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const int N = 1e5 + 10;
string s;
int n;

void solve() {
	int n;
	cin >> n;
	vector <vector <int>> a(3, vector <int> (n));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 3; ++j)
			cin >> a[j][i];
	}
	int dp[3][n];
	memset(dp, 0, sizeof dp);

	dp[0][0] = a[0][0];
	dp[1][0] = a[1][0];
	dp[2][0] = a[2][0];

	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			dp[j][i] = a[j][i] + dp[(j + 1)%3][i - 1];
			dp[j][i] = max (dp[j][i], a[j][i] + dp[(j + 2) % 3][i - 1]);
		}
	}
	int ans = 0;
	for (int i = 0; i < 3; ++i)
		ans = max (ans, dp[i][n - 1]);
	cout << ans;
}
int main () {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                  

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

int main(){
    int A,B,ans;
    cin >> A >> B;
    ans = 0;
    if (A > B) {
        ans += A;
        A--;
    } else {
        ans += B;
        B--;
    }
    if (A > B) {
        ans += A;
        A--;
    } else {
        ans += B;
        B--;
    }
    cout << ans << endl;
}

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

int gcd(int a, int b){
	if(b>0){ 
	    return gcd(b, a%b);
	}else{
        return a;
	}
}

int lcm(int a, int b){
	return (a / gcd(a, b) * b);
}

int main(){
	int a, b;
	while(cin >> a >> b){
		cout << gcd(a,b) << " " << lcm(a,b) << endl;
	}
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vector<ll> ret;
vector<ll> divisor(ll n) {
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return ret;
}

/*証明*/
/*
N=(商)*m+(mで割った余り)
ここで、条件を満たす場合(商)=N%m
また、(mで割った余り)は当然N%m
ゆえに、N=(N%m)*m+(N%m)=(N%m)*(m+1)
N%m=kとおいて
N=k*(m+1)
*/
int main() {
    ll n;
    cin >> n;

    ll ans = 0;
    divisor(n);
    rep(i, ret.size()) {
        if (ret[i] == 1) continue;
        if (n / (ret[i] - 1) == n % (ret[i] - 1)) ans += (ret[i] - 1);
    }
    /*
        ll ans2 = 0;
        rep(i, n) {
            if (i == 0) continue;
            if (n / i == n % i) ans2 += i;
        }
    */
    cout << ans << "\n";
    //    cout << ans2 << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
 int a,b,t;
 cin>>a>>b>>t;
 int ans= 0;
 for(int i=1;a*i < t+1 ; i++){
   ans += b;

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int a = 0;
	int b = 0;
	int sum = 0;
	int ans = 0;
	for(int i = 1; i <= n / 2; i++) {
		a = i;
		b = n - i;
		while(a != 0) {
			sum += a % 10;
			a /= 10;
		}
		
		while(b != 0) {
			sum += b % 10;
			b /= 10;
		}
		
		if(i == 1) {
			ans = sum;
		}
		else if(ans > sum) {
			ans = sum;
		}
		sum = 0;
	}
	
	cout << ans << endl;
	return 0;
}

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

class Guidebook implements Comparable<Guidebook>{
  public String city;
  public int score;
  public int number;
  
  public int compareTo(Guidebook obj){
    if(this.city.equals(obj.city)){
      return obj.score - this.score;
    }else{
      return this.city.compareTo(obj.city);
    }
  }
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static int ans = 0;
  public static int N;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    N = sc.nextInt();
    cal("3"); cal("5"); cal("7");
    out.println(ans);
  }
  
  public static void cal(String S){
    if(Long.parseLong(S) > N) return;
    if(S.contains("3") && S.contains("5") && S.contains("7") ) ans++;
    cal(S + "3");
    cal(S + "5");
    cal(S + "7");
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}



Measured memory_bytes: 36296
import sys

stdin = sys.stdin
na = lambda: map(int, stdin.readline().split())

def main():
  N, Q = na()

  ab = []
  for _ in range(N-1):
    a, b = na()
    ab.append([a, b])
  ab.sort()

  counter = [0] * (N+1)
  for _ in range(Q):
    p, x = na()
    counter[p] += x
  for i in range(N - 1):
    counter[ab[i][1]] += counter[ab[i][0]]
  print(*counter[1:])

if __name__ == "__main__":
  main()

Measured memory_bytes: 51112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==0)cout<<"No";
    else if(b%2!=0)cout<<"No";
    else if(a>(b+1)/2)cout<<"No";
    else if(a<(b+2)/4)cout<<"No";
    else cout<<"Yes";
}

Measured memory_bytes: 3632
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
cur = A[0]
cnt = 0
ans = []
for ai in A:
    if ai==cur: cnt += 1
    else: 
        cur = ai
        cnt = 1
    if cnt==2 or cnt==4:
        ans.append(cur)
    if len(ans)==2:
        print(ans[0]*ans[1])
        break
else:
    print(0)

Measured memory_bytes: 15020
#include<stdio.h>
#include<string.h>
#define M 10000
int N,K,dp[105][3]={0},f[105]={0},i,j,a,b;
int main()
{
	scanf("%d%d",&N,&K);
	for(i=0;i<K;f[a-1]=b,i++)
		scanf("%d%d",&a,&b);
	if(f[0])dp[0][f[0]-1]=1;
	else dp[0][0]=dp[0][1]=dp[0][2]=1;
	for(i=1;i<N;i++)
	{
		if(f[i])
		{
			dp[i][f[i]-1]=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];
			if(i>1&&dp[i-2][f[i]-1]&&dp[i-1][f[i]-1])
				dp[i][f[i]-1]+=(-dp[i-1][f[i]-1]+dp[i-2][0]+dp[i-2][1]+dp[i-2][2]-dp[i-2][f[i]-1]);
			dp[i][f[i]-1]%=M;
		}
		else
			for(j=0;j<3;j++)
			{
				dp[i][j]=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];
				if(i>1&&dp[i-2][j]&&dp[i-1][j])
					dp[i][j]+=(-dp[i-1][j]+dp[i-2][0]+dp[i-2][1]+dp[i-2][2]-dp[i-2][j]);
				dp[i][j]%=M;
			}
	}
	printf("%d\n",(dp[N-1][0]+dp[N-1][1]+dp[N-1][2])%M);
	return 0;
}

Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace CirRec
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split(' ');
            int W = int.Parse(input[0]);
            int H = int.Parse(input[1]); 
            int x = int.Parse(input[2]);
            int y = int.Parse(input[3]);
            int r = int.Parse(input[4]); 
         

            if(0 <= (x - r) && 0 <= ( y - r) && W >= (x + r ) && H >= (y + r )){
                System.Console.WriteLine("Yes");
            }else{
                System.Console.WriteLine("No");
            }
        }
    }
}

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

int main(){
    int n ;
    cin >> n ;
    vector<int> v(n) , c(n) ;
    for(int i=0;i<n;i++){
        cin >> v[i] ;
    }
    for(int i=0;i<n;i++){
        cin >> c[i] ;
    }
    int ans = -1e9 + 5 ;
    for(int i=0;i<(1<<n);i++){
        int x = 0 , y = 0 ;
        for(int j=0;j<n;j++){
            if ( (1<<j) & i ){
                x+=v[j] ;
                y+=c[j] ;
            }
        }
        ans = max(ans,x-y) ;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            for (int i = 0; i < s.Length; i++)
            {
                Console.Write(s[i]);
                if (i == 3) Console.Write(" ");
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 2776
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
const int N = 200200;
vector<int> g[N];
int c[N];
int sz[N];
int res[N];

void dfs(int v,int p=-1){
  sz[v] = 1;
  for(int to : g[v]){
    if(to==p)continue;
    dfs(to,v);
    sz[v]+=sz[to];
  }
}
 int n;
int used[N];
void dfs2(int v,int p=-1){
  int ant = used[c[v]];
  res[c[v]]+=(n-sz[v] - used[c[v]] + 1)*(sz[v]);

  int tot = 0;
  int qua=0;
  for(int to : g[v]){
    if(to==p)continue;
    tot+=sz[to];
    qua+=sz[to]*sz[to];
  }
  res[c[v]]+=(tot*tot - qua)/2;

  for(int to : g[v]){
    if(to==p)continue;
    used[c[v]] = n - sz[to];
    dfs2(to,v);
  }
  used[c[v]] = ant;
  used[c[v]]+=sz[v];
} 

int32_t main(){
	fastio;
 cin>>n;
 for(int i=1;i<=n;i++)cin>>c[i];
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    g[a].pb(b);
    g[b].pb(a);
  }
  dfs(1);
  dfs2(1);
  for(int i=1;i<=n;i++){
    cout<<res[i]<<endl;
  }
}

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
 int maxn = 1e6;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}





int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

    int n,mx=0;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin >> v[i],maxself(mx,v[i]);

    vi cant(mx+1,0);
    vi mul(mx+1,0);
    for(int i=0;i<n;i++)
    {
        if(cant[v[i]] == 0)
        {
            for(int j=v[i];j<=mx;j+=v[i])
                mul[j]++;
        }
        cant[v[i]]++;
    }

    int ans = 0;
    for(int i=0;i<n;i++)
    {
        if(cant[v[i]] == 1 and mul[v[i]] == 1)
            ans++;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 20316
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    deque<int> dq;

    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        if(i % 2 == n % 2) {
            dq.push_back(a);
        }
        else {
            dq.push_front(a);
        }
    }

    for(int i = 0; i < n; i++) {
        cout << dq.front() << " ";
        dq.pop_front();
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;
const ld pi = (acos(-1));


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n; cin >> n;
  vector<int>a(n); 
  rep(i,0,n) cin >> a[i];
  int p=1,ans=0;
  rep(i,0,n) {
    if(a[i]==p){p++;continue;}
    ans++; 
  }
   if(p==1) cout << -1 << endl;
   else cout << ans << endl;
  

 }

Measured memory_bytes: 1024
def main():
    n, adj = getInputs()
    sequence = getTopologicalSort(n, adj)

    distance = [-1] * n
    longest = -1

    for v in sequence:
        if len(adj[v]) == 0:
            distance[v] = 0
        else:
            for dest in adj[v]:
                distance[v] = max(distance[v], 1 + distance[dest])
                longest = max(longest, distance[v])

    print(longest)

def getTopologicalSort(n, adj):
    state = [0] * n
    toVisit = list(range(n))

    topologicalSort = []
    order = []

    while len(toVisit) > 0:
        curr = toVisit.pop()

        if state[curr] == 0:
            order.append(curr)
            state[curr] = 1

            foundNewDest = False
            for dest in adj[curr]:
                if state[dest] == 0:
                    toVisit.append(dest)
                    foundNewDest = True

            if not foundNewDest:
                while True:
                    v = order[-1]

                    allProcessed = True
                    for dest in adj[v]:
                        if state[dest] == 0:
                            allProcessed = False
                            break

                    if allProcessed:
                        state[v] = 2
                        topologicalSort.append(order.pop())

                    if len(order) == 0 or not allProcessed:
                        break

    return topologicalSort

def getInputs():
    n, m = map(lambda x: int(x), input().split())

    adj = []
    for i in range(n):
        adj.append([])

    for i in range(m):
        a, b = map(lambda x: int(x), input().split())
        adj[a - 1].append(b - 1)

    return n, adj

main()


Measured memory_bytes: 97528
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	s := make([]float64, n+1)
	s[0] = 0
	for i := 1; i < n+1; i++ {
		var p int
		fmt.Scan(&p)
		s[i] = s[i-1] + (float64(p)+1)/2.0
	}

	max := 0.0
	for i := k; i < n+1; i++ {
		tmp := s[i] - s[i-k]
		if max < tmp {
			max = tmp
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 5120
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
	int n, a, b;
	cin >> n;
	if (n == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string: split;

void main(){
	int n, sum;
	while (1) {
		readf("%d\n", &n);
		if(n == 0) break;
		int[100][100] table;
		// initialize
		for (int i = 0; i <= n; i++) {
			table[i][n] = table[n][i] = 0;
		}
		// calc
		for (int y = 0; y < n; y++) {
			string[] str = split(readln());
			for (int x = 0; x < n; x++) {
				int num = to!int(str[x]); 
				table[y][x] = num;
				table[n][x] += num;
				table[y][n] += num;
				table[n][n] += num;
			}
		}
		// print
		for (int y = 0; y <= n; y++) {
			for (int x = 0; x <= n; x++) {
				writef("%5d", table[y][x]);
			}
			writeln();
		}

	}
}

Measured memory_bytes: 1048
#include<stdio.h>

int x, y, z;

int main( ) {
  scanf("%d %d %d", &x, &y, &z);
  if(x>=y&&y>=z) {
  		printf("%d %d %d\n", z, y, x);
  } else if(x>=z&&z>=y) {
  		printf("%d %d %d\n", y, z, x);
  } else if(y>=x&&x>=z) {
  		printf("%d %d %d\n", z, x, y);
  } else if(z>=x&&x>=y) {
  		printf("%d %d %d\n", y, x, z);
  } else if(y>=z&&z>=x) {
  		printf("%d %d %d\n", x, z, y);
  } else {
  		printf("%d %d %d\n", x, y, z);  
  }
  return 0;
}   


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

int main()
{
  long long int N, D;

  cin >> N >> D;

  int count = 0;

  for (long long int i = 0; i < N; i++)
  {
    long long int x, y;
    cin >> x >> y;
    if (D >= sqrt(x * x + y * y))
    {
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3672
#include <stdio.h>


int gcd(int x,int y);


int main(void){
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d\n", gcd(x,y));
	
	return 0;
}

int gcd(int x,int y){
	
	
	return (y > 0) ? gcd(y, x%y):x;
}


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




int main(){
	int lnth;
	cin>>lnth;
	int cntlnth=0;
	string bas="abcdefghij";
	string st="aaaaaaaaaa";
	
	//while(cntlnth<lnth){
		for(int a=0;a<=0;a++){
			st[cntlnth]=bas[a];
			if(cntlnth==lnth-1)cout<<st.substr(0,lnth)<<endl;
			for(int b=0;cntlnth+1<lnth&&b<=a+1;b++){
				st[cntlnth+1]=bas[b];
				if(cntlnth+1==lnth-1)cout<<st.substr(0,lnth)<<endl;
				for(int c=0;cntlnth+2<lnth&&c<=b+1;c++){
					st[cntlnth+2]=bas[c];
					if(cntlnth+2==lnth-1)cout<<st.substr(0,lnth)<<endl;
					for(int d=0;cntlnth+3<lnth&&d<=max(c,max(a,b))+1;d++){
						st[cntlnth+3]=bas[d];
						if(cntlnth+3==lnth-1)cout<<st.substr(0,lnth)<<endl;
						for(int e=0;cntlnth+4<lnth&&e<=max(d,max(c,max(a,b)))+1;e++){
							st[cntlnth+4]=bas[e];
							if(cntlnth+4==lnth-1)cout<<st.substr(0,lnth)<<endl;
						for(int f=0;cntlnth+5<lnth&&f<=max(e,max(d,max(c,max(a,b))))+1;f++){
							st[cntlnth+5]=bas[f];
							if(cntlnth+5==lnth-1)cout<<st.substr(0,lnth)<<endl;
						for(int g=0;cntlnth+6<lnth&&g<=max(f,max(e,max(d,max(c,max(a,b)))))+1;g++){
							st[cntlnth+6]=bas[g];
							if(cntlnth+6==lnth-1)cout<<st.substr(0,lnth)<<endl;
			      for(int h=0;cntlnth+7<lnth&&h<=max(g,max(f,max(e,max(d,max(c,max(a,b))))))+1;h++){
							st[cntlnth+7]=bas[h];
							if(cntlnth+7==lnth-1)cout<<st.substr(0,lnth)<<endl;
						for(int i=0;cntlnth+8<lnth&&i<=max(h,max(g,max(f,max(e,max(d,max(c,max(a,b)))))))+1;i++){
							st[cntlnth+8]=bas[i];
							if(cntlnth+8==lnth-1)cout<<st.substr(0,lnth)<<endl;
						for(int j=0;cntlnth+9<lnth&&j<=max(i,max(h,max(g,max(f,max(e,max(d,max(c,max(a,b))))))))+1;j++){
							st[cntlnth+9]=bas[j];
							if(cntlnth+9==lnth-1)cout<<st.substr(0,lnth)<<endl;
		
						}
						}	
						}
						}
						}
						}
					}
				}
			}
		}
		//cntlnth++;		
	//}
	
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  
  if (N < 26) {
    set<char> s;
    for (int i = 0; i < N; i++) s.insert(S[i]);
    for (char ch = 'a'; ch <= 'z'; ch++) {
      if (!s.count(ch)) {
        cout << S << ch << endl;
        return 0;
      }
    }
  }
  
  vector<char> t;
  for (int i = 25; i > 0; i--) {
    t.push_back(S[i]);
    
    if (S[i-1] < S[i]) {
      sort(t.begin(), t.end());
      for (char ch : t) {
        if (ch > S[i-1]) {
          S[i-1] = ch;
          cout << S.substr(0,i) << endl;
          return 0;
        }
      }
    }
    
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256