akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        int kotae = 0;

        for (int i = 0; i < 5; i++)
        {
            if (a[i] == 0)
            {
                kotae = i + 1;
                break;
            }
        }
        Console.WriteLine(kotae);
    }
}


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

int main() {
    int N, a;
    cin >> N;
    vector<int> ai;
    for (int i = 0; i < N; ++i) {
        cin >> a;
        ai.push_back(a);
    }
    sort(ai.begin(), ai.end());
    cout << ai.back() - ai.front() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

const int N = 100005;

void output(char f[N][4], int j, int n){
    rep(i,n){
        cout << f[i][j];
    }
    cout << endl;
}

bool check(string s, char f[N][4], int j, int n){
    rep(i,n){
        if(f[i][j] == 'W') s[i] = (s[i] == 'o' ? 'x' : 'o');
    }
    //show(s)
    if(s[0] == 'o' && f[1][j] != f[n - 1][j]) return 0;
    if(s[0] == 'x' && f[1][j] == f[n - 1][j]) return 0;
    if(s[n - 1] == 'o' && f[0][j] != f[n - 2][j]) return 0;
    if(s[n - 1] == 'x' && f[0][j] == f[n - 2][j]) return 0;
    range(i,1,n - 1){
        if(s[i] == 'o' && f[i - 1][j] != f[i + 1][j]) return 0;
        if(s[i] == 'x' && f[i - 1][j] == f[i + 1][j]) return 0;
    }
    return 1;
}

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

    char f[N][4];
    f[0][0] = f[0][1] = 'S';
    f[0][2] = f[0][3] = 'W';
    if(s[0] == 'o'){
        f[1][0] = f[n - 1][0] = 'S';
        f[1][1] = f[n - 1][1] = 'W';
        f[1][2] = 'W'; f[n - 1][2] = 'S';
        f[1][3] = 'S'; f[n - 1][3] = 'W';
    }else{
        f[1][0] = 'W'; f[n - 1][0] = 'S';
        f[1][1] = 'S'; f[n - 1][1] = 'W';
        f[1][2] = f[n - 1][2] = 'S';
        f[1][3] = f[n - 1][3] = 'W';
    }
    rep(j,4){
        range(i,1,n - 2){
            if( (s[i] == 'o' && f[i][j] == 'S') || (s[i] == 'x' && f[i][j] == 'W') ){
                f[i + 1][j] = f[i - 1][j];
            }else{
                f[i + 1][j] = (f[i - 1][j] == 'S' ? 'W' : 'S');
            }
        }
    }
    rep(j,4){
        //output(f,j,n);
        if(check(s,f,j,n)){
            output(f,j,n);
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


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

using namespace std;

typedef long long int 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; }
 
typedef pair<int,int> pair;

int main(){
  string s,t; cin >> s >> t;

  bool ans=true;

  for(int i=0;i<s.length();i++){
    if(s[i]!=t[i]) ans =false;
  }

  if(ans) puts("Yes");
  else puts("No") ;
}

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

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k) cout << s << endl;
  else {
    string ans = s.substr(0,k);
    ans += "...";
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
# coding: utf-8
# hello worldと表示する
import sys
import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lisr=[LI() for i in range(n)]
lisb=[LI() for i in range(n)]
#print(lisr)
#print(lisb)
lisr.sort(key=itemgetter(1))
lisb.sort(key=itemgetter(1))
#print(lisr)
#print(lisb)
count=0
for i in range(n):
    x,y=lisb[i]
    mx=-inf
    for j in range(n):
        a,b=lisr[j]
        if b<y and a<x:
            if a>mx:
                mx=a
                pos=j
    #print(mx,pos)
    if mx>-inf:
        count+=1
        lisr[pos][1]=inf
print(count)
#print(lisr)

        
    

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

int main(){  
  ll a, b, c;
  cin >> a >> b >> c;

  ll d = c - a - b;
  if(4*a*b < d*d && d > 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ull X, Y;
  cin >> X >> Y;
  ll count = 0;
  for (ull x = X; x <= Y; x *= 2) {
    count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())
# あまりの計算
b = a%10
# 出力するテキスト
if b == 2 or b == 4 or b == 5 or b == 7 or b == 9:
  out = 'hon'
elif b == 0 or b == 1 or b == 6 or b == 8:
  out = 'pon'
elif b == 3:
  out = 'bon'
# 出力
print("{}".format(out))

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

using namespace std;

const int N = 1234567;

int n;
vector<pair<int, int>> graph[N];
int from[N];
int size[N];
int weight[N];

long long dfs(int v = 0, int pv = 0) {
  size[v] = 1;
  long long ret = 0;
  for (auto nxt : graph[v]) {
    int to = nxt.first;
    if (to == pv) continue;
    from[to] = v;
    weight[to] = nxt.second;
    ret = max(ret, dfs(to, v));
    size[v] += size[to];
  }
  if (2ll * size[v] == n) ret = weight[v];
  return ret;
}

long long dfs2(int v = 0, int pv = 0) {
  long long ret = 0;
  for (auto nxt : graph[v]) {
    int to = nxt.first;
    if (to == pv) continue;
    long long sz = min(size[to], n - size[to]);
    ret += 2ll * sz * nxt.second; 
    ret += dfs2(to, v);
  }
  return ret;
}

long long go() {
  int cen = 0;
  queue<int> q; q.push(cen);
  int best_size = n;
  while (!q.empty()) {
    int v = q.front(); q.pop();
    int max_size = n - size[v];
    int which = from[v];
    for (auto nxt : graph[v]) {
      int to = nxt.first;
      if (to == from[v]) continue;
      if (size[to] > max_size) {
        max_size = size[to];
      }
      q.push(to);
    }
    if (max_size < best_size) {
      best_size = max_size;
      cen = v;
    }
  }
  int ret = 1 << 30;
  for (auto it : graph[cen]) ret = min(ret, it.second);
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i + 1 < n; i++) {
    int a, b, c; scanf("%d %d %d", &a, &b, &c); a--, b--;
    graph[a].push_back(make_pair(b, c));    
    graph[b].push_back(make_pair(a, c));
  }
  long long edge = dfs();
  long long ans = dfs2();
    if (edge > 0) {
    ans -= edge;
    printf("%lld\n", ans);
  } else {
    long long edge = go();
    ans -= edge;
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 43648
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vector<int>>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define itr(v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fd(i,n)         for(int i=n-1;i>=0;i--)
#define fir(i,a,b)      for(int i=a;i<b;i++)
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);
#define MAXZ            200005
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

bool cmp(int a,int b) {return a>b;}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

int a[200001],b[200001];
void dfs(vii adj,ll vis[],ll curr,stack<ll> &s,vector<ll> &v){
    vis[curr]=-1;
    s.push(curr);
    // cout<<curr+1<<"\n";
    fi(i,adj[curr].size()){
        if(vis[adj[curr][i]]==0){
            dfs(adj,vis,adj[curr][i],s,v);
        }
        else if(vis[adj[curr][i]]==-1){
            // cout<<"cycle is there\n";
            s.push(adj[curr][i]);
            while(!s.empty()){
                v.push_back(s.top());
                s.pop();
            }
            return;
        }
    }
    s.pop();
    vis[curr]=1;
}

int32_t main()
{
    // FIO
    int n,k; cin>>n>>k;
    fi(i,n) {
        cin>>a[i];
        a[i]--;
    }
    mii m;
    vi v;
    int nex=0;
    v.pb(0);
    while(1){
        m[nex]=1;
        nex=a[nex];
        v.pb(nex);
        if(m[nex]) break;
    }
    // itr(v) cout<<it+1<<" "; cout<<"\n";
    if(k<v.size()) {
        cout<<v[k]+1<<"\n";
    }
    else{
        int c=v[v.size()-1];
        int ind=v.size()-1;
        fi(i,v.size()-1){
            if(v[i]==c) {
                ind=i;
                break;
            }
            k--;
        }
        k=k%(v.size()-ind-1);
        // cout<<k<<"\n";
        cout<<v[ind+k]+1<<"\n";

    }
    return 0;

}

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

int main()
{
	ll h, w; cin >> h >> w;

	if ((h == 1) || (w == 1))
	{
		cout << 1 << endl;
	}
	else
	{
		cout << ((((w + 1) / 2) * ((h + 1) / 2)) + ((w / 2) * (h / 2))) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
s=str(input())

cnt=0

num=len(s)//2

a=s[:num]
b=s[num+1:]

num2=len(a)//2
if len(a)%2 ==1:
    c=a[:num2]
    d=a[num2+1:]
else:
    c=a[:num2]
    d=a[num2:]


num3=int((len(s)+3)/2-1)
s1=s[num3:]
num4=len(s1)//2
if len(s1)%2==1:
    e=s1[:num4]
    f=s1[num4+1:]
else:
    e=s1[:num4]
    f=s1[num4:]


if a==b[::-1]:
    cnt +=1

if c==d[::-1]:
    cnt +=1

if e==f[::-1]:
    cnt +=1

if cnt==3:
    print("Yes")
else:
    print("No")

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

int main()
{
	fast;
	int n;
	cin >> n;
	map<string, int> mp;
	vector<string> st = {"AC", "WA", "TLE", "RE"};
	for (string s : st)
		mp[s] = 0;
	forn
	{
		string s;
		cin >> s;
		mp[s]++;
	}
	for (string s : st)
	{
		cout << s << " x " << mp[s] << en;
	}
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; i++)
    cin >> X[i];
  vector<int> Y(N);
  for (int i = 0; i < N; i++)
    Y[i] = X[i];
  sort(X.begin(), X.end());
  int mid = N / 2;
  for (int i = 0; i < N; i++)
  {
    if (Y[i] < X[mid])
      cout << X[mid] << endl;
    else
      cout << X[mid - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>

using namespace std;

int main() {
    int N, L;
    string ans;
    cin >> N >> L;

    vector<string> s(N);

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

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

    for (int i = 0; i < N; i++) {
        ans += s[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a, b = gets.strip.split.map(&:to_i)

result = Array.new(50){ ['#']*100 } + Array.new(50){ ['.']*100 }
a-=1
b-=1

(a/50.0).ceil.times do |i|
  50.times do |j|
    break if a==0
    y = i*2
    x = i.odd? ? j*2+1 : j*2
    result[y][x]='.'
    a-=1
  end
end

(b/50.0).ceil.times do |i|
  50.times do |j|
    break if b==0
    y = (99-i*2)
    x = y.odd? ? j*2+1 : j*2
    result[y][x]='#'
    b-=1
  end
end

puts [result.length, result.first.length]
result.each do |l|
  puts l.join('')
end




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

int main() {
  int n;
  cin >> n;
  int h[n];
  rep(i, n) cin >> h[i];
  
  int score[n] = {0};
  score[1] = abs(h[0] - h[1]);
  
  for (int i=2; i<n; i++) {
    int s = abs(h[i] - h[i-1]) + score[i-1];
    int t = abs(h[i] - h[i-2]) + score[i-2];
    if (s > t) {
      score[i] = t;
    } else {
      score[i] = s;
    }
  }
  cout << score[n-1];
  
  return 0;
}


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

typedef long long ll;
const int p = (int)1e9+7;

double dp[3100][3100];

int main() {
	int N; cin >> N;
	vector<double> p(N);
	for(int i=0; i<N; i++) cin >> p[i];

	dp[0][0] = 1.0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dp[i+1][j+1] += dp[i][j] * p[i];
			dp[i+1][j] += dp[i][j] * (1-p[i]);
		}
	}

	double res=0.0;
	for(int j=(N+1)/2; j<=N; j++) res += dp[N][j];
	cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 74112
#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;

typedef pair<int, int> P;

int data[12][12] = {};
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1 ,0 ,-1};

void dfs(int sx, int sy) {
  queue<P> que;
  data[sx][sy] = 2;
  que.push(P(sx, sy));
  
  while(que.size()) {
    P p = que.front();
    que.pop();
    
    for(int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(0 <= nx && nx < 12 && 0 <= ny && ny < 12 && data[nx][ny] == 1 ){
	que.push(P(nx, ny));
	data[nx][ny] = 2;
      }
    }
  }
}


int main(){
  while(~scanf("%1d", &data[0][0])) {
    int cnt = 0, i, j = 1;
    for(i = 0; i < 12; i++, j=0)
      for(;j < 12; j++) {
	scanf("%1d", &data[i][j]);
      }
    for(i = 0; i < 12; i++)
      for( j = 0; j < 12; j++)
	if(data[i][j] == 1){
	  dfs(i, j);
	  cnt++;
	}
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
import sys, math
input = sys.stdin.readline

def main():
    inpt = input()
    A = int(inpt.split()[0])
    B = inpt.split()[1]

    B = int(B[0] + B[2:4])

    print(math.floor((B * A)//100))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int n,a;
int main()
{
	cin>>n;
	int maxn=0,sum=0;
	for (int i=0;i<n;i++) cin>>a,maxn=max(maxn,a),sum+=a;
	sum-=maxn;
	if (maxn<sum) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import math
from collections import deque
from collections import defaultdict

import itertools as it

#自作関数群
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 combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
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
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

n = readInt()
t,a = readInts()
h = readInts()

ans = 1
ran = float("inf")

for i in range(n):
	x = t-h[i]*0.006
	if ran>abs(x-a):
		ran = abs(x-a)
		ans = i+1

print(ans)

Measured memory_bytes: 3444
// AOJ 0387 Taxi
// 2018.3.20 bal4u

#include <stdio.h>
#include <stdlib.h>

// 高速数値入出力
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()   // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}


// 優先度付きキュー（最大値）
#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)
#define QSIZE 300010
int que[QSIZE + 5];
int qsize;

void max_heapify(int i)
{
	int l, r, max;
	int qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l] > que[i]) max = l; else max = i;
	if (r < qsize && que[r] > que[max]) max = r;
	if (max != i) {
		qt = que[i], que[i] = que[max], que[max] = qt;
		max_heapify(max);
	}
}

void deq()
{
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(int c)
{
	int i, max;
	int qt;

	i = qsize++;
	que[i] = c;
	while (i > 0 && que[max = PARENT(i)] < que[i]) {
		qt = que[i]; que[i] = que[max], que[max] = qt;
		i = max;
	}
}


// 本問題関連
int c[300010];
int top[300010], sz[300010]; int N;

int main()
{
	int i, k, M;
	unsigned ans;

	N = in(), k = 0;
	for (i = 0; i < N; i++) {
		sz[i] = M = in();
		top[i] = k;
		while (M--) c[k++] = in();
	}
	
	// 各列のデータを逆順に優先度付きキューに追加
	ans = 0, qsize = 0;
	for (i = N - 1; i >= 0; i--) {
		M = sz[i], k = top[i];
		while (M--) enq(c[k++]);
		ans += (unsigned)que[0];
		deq();
	}
	printf("%u\n", ans);
	return (0);
}




Measured memory_bytes: 5240
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>



struct Point {
	long long int x, y;
	bool operator<(const Point& other) const {
		if (x == other.x) {
			return y < other.y;
		}
		else {
			return x < other.x;
		}
	}
};
int main() {
	int n; std::cin >> n;
	std::vector<Point> points(n);
	std::set<Point> point_set;
	for (auto& p : points) {
		std::cin >> p.x >> p.y;
		point_set.insert(p);
	}
	if (n != 1) {
		int min = INT_MAX;
		for (auto i = 0; i < n; ++i) {
			for (auto j = 0; j < n; ++j) if (i != j) {
				auto p = points[j].x - points[i].x;
				auto q = points[j].y - points[i].y;
				auto cost = 0;
				for (const auto& point : points) {
					if (point_set.find(Point{ point.x - p, point.y - q }) == point_set.end()) {
						cost++;
					}
				}
				if (min > cost) {
					min = cost;
				}
			}
		}
		std::cout << min << std::endl;
	}
	else {
		std::cout << 1 << std::endl;
	}
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{

  cin >> a;
  if (a < 3)
    pr(0);
  else
    pr((a ) / 3);

  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
class Main {
	public static void main(String args[]){
		int[] student = new int[30];
		int i;
		Main app = new Main();
		
		while(true){
			Scanner scan = new Scanner(System.in);
			if(!scan.hasNext()){
				break;
			}
			for(i=0;i<30;i++){
				student[i] = 0;
			}
			app.submit(student,scan);
			app.who(student);
		}
	}
	
	public void submit(int[] student,Scanner scan){
		for(int i=0;i<28;i++){
			String str = scan.nextLine();
			int num = Integer.parseInt(str);
			student[num-1] = 1;
		}
	}
	
	public void who(int student[]){
		for(int i=0;i<30;i++){
			if(student[i] == 0){
				System.out.println(i+1);
			}
		}
	}
}

Measured memory_bytes: 17164
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll X;
ll eat(int n){
    if(n == 0) {
        X--;
        return 1;
    }

    ll ret = 0;
    X--;
    if(X == 0) return ret;
    else if(X >= (1LL << n+1) - 3){
        X -= (1LL << n+1) - 3;
        ret += (1LL << n) - 1;
    }
    else ret += eat(n-1);

    if(X == 0) return ret;
    X--, ret++;

    if(X == 0) return ret;
    else if(X >= (1LL << n+1) - 3){
        X -= (1LL << n+1) - 3;
        ret += (1LL << n) - 1;
    }
    else ret += eat(n-1);

    if(X == 0) return ret;
    X--;

    return ret;
}

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

    ll ans;
    ans = eat(N);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self,n):
        self.par=[i for i in range(n+1)]
        self.rank=[0]*(n+1)
        self.size=[1]*(n+1)
        
    def findroot(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.findroot(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x=self.findroot(x)
        y=self.findroot(y)
        if self.rank[x]==self.rank[y]:
            self.rank[x]+=1
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
            self.size[y]+=self.size[x]
        else:
            self.par[y]=x
            self.size[x]+=self.size[y]
    
    def issame(self,x,y):
        return self.findroot(x)==self.findroot(y)
    
    def size(self,x):
        x=self.findroot(x)
        return self.size[x]
    
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(M)]
inconvenience=(N*(N-1))//2
Bridge=UnionFind(N)
ans=[]
for i in range(M):
    ans.append(inconvenience)
    a,b=ab[-i-1]
    if UnionFind.issame(Bridge,a,b)==True:
        pass
    else:
        inconvenience-=UnionFind.size(Bridge,a)*UnionFind.size(Bridge,b)
        UnionFind.unite(Bridge,a,b)
for j in range(M):
    print(ans[-j-1])

Measured memory_bytes: 34960
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, P> Pi;
int par[200002];
int rk[200002];

void init(int n){
	for(int i=0; i<n; i++){
		par[i]=i; rk[i]=0;
	}
}

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

void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rk[x]<rk[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rk[x]==rk[y]) rk[x]++;
	}
}

bool same(int x, int y){
	return find(x)==find(y);
}
int n;
ll d;
ll a[200001];
vector<Pi> e;
void solve(int l, int r){
	if(l==r) return;
	int m=(l+r)/2;
	int i1=l; ll mn=a[l]-(ll)l*d;
	for(int i=l+1; i<=m; i++){
		if(mn>a[i]-(ll)i*d) mn=a[i]-(ll)i*d, i1=i;
	}
	for(int i=m+1; i<=r; i++) e.push_back(Pi(a[i]+a[i1]+(ll)(i-i1)*d, P(i1, i)));
	i1=m+1, mn=a[m+1]+(ll)(m+1)*d;
	for(int i=m+2; i<=r; i++){
		if(mn>a[i]+(ll)i*d) mn=a[i]+(ll)i*d, i1=i;
	}
	for(int i=l; i<=m; i++) e.push_back(Pi(a[i]+a[i1]+(ll)(i1-i)*d, P(i1, i)));
	solve(l, m);
	solve(m+1, r);
}
int main()
{
	cin>>n>>d;
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	solve(0, n-1);
	ll ans=0;
	sort(e.begin(), e.end());
	init(n);
	for(int i=0; i<e.size(); i++){
		int x=e[i].second.first, y=e[i].second.second;
		if(!same(x, y)){
			unite(x, y);
			ans+=e[i].first;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 69344
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  map<int, int> cnt;
  vector<int> answer;
  REP(i,n) {
    if((cnt.find(a[i])!=cnt.end()) && cnt[a[i]]==-1) cnt.erase(a[i]);
    else ++cnt[a[i]];
    if((cnt.find(a[n-1-i])!=cnt.end()) && cnt[a[n-1-i]]==1) cnt.erase(a[n-1-i]);
    else --cnt[a[n-1-i]];
    if(cnt.empty()) answer.push_back(i+1);
  }
  REP(i,(int)answer.size()) {
    if(i) cout << ' ';
    cout << answer[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 4076
#include<iostream>
#include<vector>
using namespace std;
string s[1<<17];
vector<string>A;
int cnt[1<<17];
int N;
string f(int id,int L,int R,int d)
{
	A[id]+=':';
	for(int i=L;i<R;i++)
	{
		if(s[i].substr(d,A[id].size())!=A[id])continue;
		if(id+1==A.size())
		{
			string ret=s[i].substr(min(d+A[id].size()+1,s[i].size()));
			if(ret.size()>0)return "string \""+ret+"\"";
			else return "object";
		}
		else
		{
			int l=i+1;
			int r=l;
			while(r<R&&cnt[r]>=cnt[l])r++;
			return f(id+1,l,r,cnt[l]);
		}
	}
	return"no such property";
}
main()
{
	string t;
	getline(cin,t);
	for(int i=0;i<t.size();i++)
	{
		if(t[i]=='.')A.push_back("");
		else A.back().push_back(t[i]);
	}
	while(getline(cin,s[N++]));
	for(int i=0;i<N;i++)
	{
		while(s[i][cnt[i]]==' ')cnt[i]++;
	}
	cout<<f(0,0,N,0)<<endl;
}



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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}




signed main() {
  stack<int> z;
  string s;
  while((cin >> s)) {
    if (isdigit(s[0])) {
      z.push(atoi(s.c_str()));
    } else {
      int a = z.top(); z.pop();
      int b = z.top(); z.pop();

      if (s == "+") z.push(b + a);
      if (s == "-") z.push(b - a);
      if (s == "*") z.push(b * a);
    }
  }

  cout << z.top() << endl;
}


Measured memory_bytes: 3244
# AOJ 0038: Poker Hand
# Python3 2018.6.27 bal4u

def judge(card, cnt):
	nmax = cnt[0][1]
	if nmax == 4: return "four card"
	if nmax == 3: return "full house" if cnt[1][1] == 2 else "three card"
	if nmax == 2: return "two pair" if cnt[1][1] == 2 else "one pair"
	if (card[0] == 1 and list(range(10, 14)) == card[1:]) \
		or list(range(card[0], card[0]+5)) == card: return "straight"
	return "null"

import collections
while True:
	try: card = list(map(int, input().split(',')))
	except: break
	cnt = collections.Counter(card)
	print(judge(sorted(card), sorted(cnt.items(), key=lambda x: -x[1])))


Measured memory_bytes: 5992
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl

int main() {
  string s;
  cin >> s;
  stack<char> st;
  int cnt = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (st.empty()) st.push(s[i]);
    else if (st.top() == 'S' && s[i] == 'T') {
      cnt++;
      st.pop();
    }
    else st.push(s[i]);
  }
  dump((int)st.size());
  return 0;
}


Measured memory_bytes: 644
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = 998244353; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
ll mpow(ll x, ll n) { ll y = 1; for (; n > 0; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }
    
struct Combination {
    vector<ll> fact, ifact;
    Combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1; for (int i = 0; i < n; ++i) fact[i + 1] = fact[i] * (i + 1) % MOD;
        ifact[n] = mpow(fact[n], MOD - 2); for (int i = n; i > 0; --i) ifact[i - 1] = ifact[i] * i % MOD;
    }
    ll operator ()(int n, int k) { return k < 0 || k > n ? 0 : fact[n] * ifact[n - k] % MOD * ifact[k] % MOD; }
} C(4545);

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

    rep(i, 2, 2 * K + 1) {
        // １個だけでi以上の個数 or 片方がその数字だとiに満たない個数
        int n_NotPair = i < K + 1 ? max(0, K - i + 1) : max(0, i - K - 1);

        ll ans = 0;
        if (i % 2) {
            int n_Pair = (K - n_NotPair) / 2;
            // 2つに割ったペアの使用数
            rep(m, 0, min(N, n_Pair) + 1) {
                ll tmp = C((N - m) + (m + n_NotPair) - 1, N - m) * mpow(2, m) % MOD;
                ans = (ans + C(n_Pair, m) * tmp % MOD) % MOD;
            }
        }
        else {
            int n_Pair = (K - n_NotPair - 1) / 2;
            // i/2を使わない
            rep(m, 0, min(N, n_Pair) + 1) {
                ll tmp = C((N - m) + (m + n_NotPair) - 1, N - m) * mpow(2, m) % MOD;
                ans = (ans + C(n_Pair, m) * tmp % MOD) % MOD;
            }

            // i/2を使う i/2は1個まで
            rep(m, 0, min(N - 1, n_Pair) + 1) {
                ll tmp = C((N - m - 1) + (m + n_NotPair) - 1, N - m - 1) * mpow(2, m) % MOD;
                ans = (ans + C(n_Pair, m) * tmp % MOD) % MOD;
            }
        }

        write(ans);
    }
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int divceil(int a, int b) {
  return (a+b-1)/b;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll k, q;
  cin >> k >> q;
  vector<int> d(k);
  rep(i, k) {
    cin >> d[i];
  }
  rep(iq, q) {
    int n, x, m;
    cin >> n >> x >> m;
    ll last = x, eq = 0;
    rep(i, k) {
      // repeated d's length is n-1. calculate the each contribution
      ll num = divceil((n-1)-i, k);
      last += (d[i]%m)*num;
      if ((d[i]%m) == 0) {
        eq += num;
      }
    }
    // last/m - x/m .. the count of (aj mod m) > (aj+1 mod m)
    // eq .. the counf of (aj mod m) == (aj+1 mod m)
    ll ans = (n-1) - (last/m - x/m) - eq;
    cout << ans << endl;
  }
}


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

long long A[5];

int main(){
    int n, m, a, r ,c, h;
    cin >> n;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        if(s[0] == 'M') A[0]++;
        else if(s[0] == 'A') A[1]++;
        else if(s[0] == 'R') A[2]++;
        else if(s[0] == 'C') A[3]++;
        else if(s[0] == 'H') A[4]++;
    }
    long long ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5; j++){
            for(int k = j + 1; k < 5; k++){
                ans += A[i] * A[j] * A[k];                
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for (int i = 0; i <= A; ++i)
    {
        for (int j = 0; j <= B; ++j)
        {
            for (int k = 0; k <= C; ++k)
            {
                if( X == (i*500+j*100+k*50)){
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = na()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

ps = [0] * n
for i in range(q):
    p, x = na()
    p -= 1
    ps[p] += x

stack = [0] * (n+1)
inds = [0] * (n+1)

sp = 0
stack[sp] = 0
sp += 1

while sp > 0:
    cur = stack[sp-1]
    if inds[sp-1] == len(g[cur]):
        sp -= 1
        continue
    if inds[sp-1] == 0 and sp > 1:
        ps[cur] += ps[stack[sp-2]]
    if sp == 1 or stack[sp-2] != g[cur][inds[sp-1]]:
        stack[sp] = g[cur][inds[sp-1]]
        inds[sp] = 0
        inds[sp-1] += 1
        sp += 1
        continue
    inds[sp - 1] += 1

print(" ".join(map(str, ps)))


Measured memory_bytes: 121804
#include <iostream>

int main()
{
    using namespace std;

    int n;
    cin >> n;

    int x;
    int min = 1000000;
    int max = -1000000;
    long long sum = 0;

    for (int i = 0; i < n; i++)
    {
        cin >> x;

        if (x < min)
        {
            min = x;
        }
        if (x > max)
        {
            max = x;
        }
        sum += x;
    }

    printf("%d %d %lld\n", min, max, sum);
}


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

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

  int a, b, c, x;
  cin >> a >> b >> c >> x;
  x /= 50;
  int res = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      int r = x - 10 * i - 2 * j;
      res += (0 <= r && r <= c);
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		boolean[] prime=new boolean[(int)Math.pow(10,8)+1];
		prime[0]=prime[1]=true;
		int limit=(int)Math.pow(10,8);
		int limit2=(int)Math.sqrt(Math.pow(10,8));
		for(int i=2;i<limit2;){
			for(int j=2;i*j<=limit;j++){
				prime[i*j]=true;
			}
			for(int j=i+1;j<=limit;j++){
				if(!prime[j]){
					i=j;
					break;
				}
			}
		}
		int N=scan.nextInt();
		int count=0;
		for(int i=0;i<N;i++){
			if(!prime[scan.nextInt()]) count++;
		}
		System.out.println(count);
		scan.close();
	}
}

Measured memory_bytes: 129880
//Copyright(c)2017 Mstdream
#include<bits/stdc++.h>
using namespace std;

inline void splay(int &v){
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
#define LL long long
char s[500];
int main(){
	//freopen("xxx.in","r",stdin);
	LL l=10000000000ll,r=99999999999ll;
	while(l!=r){
		LL mid=l+r>>1LL;
		cout<<"? "<<mid<<endl;
		fflush(stdout);
		scanf("%s",s+1);
		if(s[1]=='Y')r=mid;
		else l=mid+1;
	}
	if(l!=10000000000ll){
		l--;
		while(1){
			l/=10;
			cout<<"? "<<l<<endl;
			fflush(stdout);
			scanf("%s",s+1);
			if(s[1]=='Y'){
				cout<<"! "<<l+1<<endl;
				fflush(stdout);
				return 0;
			}
		}
	}
	else{
		l=9;LL ans=1;
		while(1){
			cout<<"? "<<l<<endl;
			fflush(stdout);
			scanf("%s",s+1);
			if(s[1]=='Y'){
				cout<<"! "<<ans<<endl;
				fflush(stdout);
				return 0;
			}
			ans*=10,l*=10;
		}
	}
}	
	

Measured memory_bytes: 596
N = int(input())
A, B = map(int, input().split())
Ps = list(map(int, input().split()))

nums = [0] * 3
for P in Ps:
    if P <= A:
        i = 0
    elif P <= B:
        i = 1
    else:
        i = 2
    nums[i] += 1

print(min(nums))


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

int main()
{
    
        ll a, b, c, i, j, k, l, m, n, x, y, z;
        char ch;
        string s;

        cin >> n >> k;
        if(n >= k) x = min(n%k, k - n%k);
        else x = min(n, k-n);

        cout << x << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int sec = scanner.nextInt(),min,hour;
        hour = (min = sec/60)/60;
        sec %= 60;
        min %= 60;
        System.out.println(hour+":"+min+":"+sec);
    }
}


Measured memory_bytes: 26208
N = int(input())
H = list(map(int,input().split()))

A = [[0]*N for _ in range(101)]
#A = [[0 for i in range(N)] for j in range(101)]
for i in range(101):
    for j in range(N):
        if H[j] > 0:
            A[i][j]=1
            H[j]-=1
        else:
            H[j] = 0
ans = 0
for i in range(101):
    flag = False
    for j in range(N):
        if A[i][j] == 1 and flag == False:
            flag = True
        elif A[i][j] == 0 and flag == True:
            ans += 1
            flag = False
    if flag:
        ans+=1
print(ans) 


Measured memory_bytes: 3064
def main():
    n = int(input())
    ss = sorted(int(input()) for _ in range(n))

    res = sum(ss)
    if res % 10 != 0:
        print(res)
        return

    for s in ss:
        if s % 10 != 0:
            print(res - s)
            return

    print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, mini = MOD, coun;
	bool muteki = false;
	ll ans = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
		if (a[i] < 0) coun++;
		if (a[i] == 0) muteki = true;
	}
	if (muteki || coun%2 == 0){
		for (auto x : a){
			ans += abs(x);
		}
	}else{
		for (int i = 0; i < n; i++){
			a[i] = abs(a[i]);
		}
		sort(a.begin(), a.end());
		ans -= a[0];
		for (int i = 1; i < n; i++){
			ans += a[i];
		}
	}
	cout << ans << endl;
 	return 0;
}



Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();

    if let Some(s) = solve(n) {
        writeln!(o, "Yes").unwrap();
        writeln!(o, "{}", s.len()).unwrap();
        for si in s {
            write!(o, "{}", si.len()).unwrap();
            for sij in si {
                write!(o, " {}", sij).unwrap();
            }
            writeln!(o, "").unwrap();
        }
    } else {
        writeln!(o, "No").unwrap();
    }
}
fn solve(n: usize) -> Option<Vec<Vec<usize>>> {
    let mut sum = 0;
    let mut i = 0;

    loop {
        i += 1;
        sum += i;
        if sum > n {
            return None;
        }
        if sum == n {
            return Some(make_result(i));
        }
    }
}
fn make_result(i: usize) -> Vec<Vec<usize>> {
    if i == 1 {
        vec![vec![1]; 2]
    } else {
        let mut rs = make_result(i - 1);
        let j0 = rs.last().unwrap().last().unwrap() + 1;

        let mut r = Vec::new();

        for j in 0..i {
            rs[j].push(j0 + j);
            r.push(j0 + j);
        }
        rs.push(r);
        rs
    }
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 8444
#include <stdio.h>
#include <stdlib.h>

int main(){
	int a,
		b;
	char suuti[2][20],
		 *edp,
		 c;
	long l[2];
	for(a = 0;a < 2;a++){

		for(b = 0; b < 19 && (c = getchar()) != ' ' && c != '\n';b++ ){
			suuti[a][b] = c;
		}suuti[a][b] = 0;

		l[a] = strtol(suuti[a],&edp,10);
		if(*edp != '\0'){
			exit(0);
		}
	}suuti[a][b] = 0;
	
	if(l[0] > l[1]){
		printf("a > b\n");
	}
	if(l[0] < l[1]){
		printf("a < b\n");
	}
	if(l[0] == l[1]){
		printf("a == b\n");
	}
	return 0;	

}

Measured memory_bytes: 524
import scala.io.StdIn.readLine
import scala.collection.immutable.BitSet

object Main {

  def sum(n:Int, s:Int, b:BitSet):Int = {
    if(n==1) {
      if(s >= 0 && s<=9 && (b.isEmpty || s > b.max)) 1 else 0
    } else {
      var j = 0
      for(i <- 0 to 9 ){
        if(s>=i && (b.isEmpty || i > b.max))
          j += sum(n-1,s-i,b+i)
      }
      j
    }
  }

  def getSum(sb:StringBuilder):Unit = {
    val r = readLine.split(" ").map(_.toInt)

    if(r(0)==0 && r(1)==0)  print(sb.result)
    else {
      println(sum(r(0),r(1),BitSet.empty))
      getSum(sb)
    }
  }

  def main(args:Array[String]) = getSum(new StringBuilder)
}

Measured memory_bytes: 59956