akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main{
  public static void main(String[] arcs)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int[] args = new int[4];
    for(int i= 0; i<3; i++){
      args[i] = Integer.parseInt(br.readLine());
    }
    args[3]=Integer.parseInt(br.readLine())/50;
    
    int c2 = 0;
    int c10 = 0;
    int counter = 0;
    
    if(args[0]*10 + args[1]*2 + args[2] >= args[3]){
        for(c10 = 0; c10 <= args[0]; c10++){
            if(c10 * 10 > args[3]){
                break;
            }
            else if(c10*10 + args[1]*2 + args[2]<args[3]){
                //何もしない
            }
            else{
                for(c2 = 0;c2<=args[1];c2++){
                    if(c10*10 + c2*2 > args[3]){
                        break;
                    }
                    else if(c10*10 + c2*2 + args[2] <args[3]){
                        //何もしない
                    }else{
                        counter++;
                    }
                }
            }
        }
    }
    System.out.println(counter);
  }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int h, w;
void init(){
    cin >> h >> w;
}
void solve(){
    if (h == 1 || w == 1) {
        printf("1\n");
        return ;
    }
    if (h % 2 == 0){
        h >>= 1;
        ll ans = 1ll * h * w;
        cout << ans << endl;
    }else {
        int r1 = (w + 1) >> 1;
        h >>= 1;
        ll ans = 1ll * h * w;
        ans += 1ll * r1;
        cout << ans << endl;
    }
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#define ll long long

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> x(N),y(N),h(N);
    for(int i=0;i<N;i++){
        cin >> x[i] >> y[i] >> h[i];
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            int needH=-1;// 必要な高さであるか
            for(int k=0;k<N;k++){
                if(h[k]>0){
                    int tmp=abs(x[k]-i)+abs(y[k]-j)+h[k];
                    if(needH==-1){
                        needH=tmp;
                    }
                    else{
                        if(needH!=tmp){
                            needH=-2;
                            break;
                        }
                    }
                }
            }
            if(needH==-2){
                continue;
            }
            for(int k=0;k<N;k++){
                if(h[k]==0){
                    int dist = abs(x[k]-i)+abs(y[k]-j);
                    if(needH > dist){
                        needH = -2;//????????
                    }
                }
            }
            if(needH==-2){
                continue;
            }
            cout << i << " " << j << " " << needH << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d %d %d", $arr[0], $arr[1], $arr[2]);
  $min = 99999;
  for($i = 0;$i<count($arr);$i++){
    $sum = $arr[$i] + $arr[($i+2)%3];
    if($min>$sum){
      $min = $sum;
    }
  }
  echo $min;
  ?>

Measured memory_bytes: 3828
str = 'abcdefghijklmnop'
def bt(n,m,s):
  if n == 0:
    print(s)
    return
  for c in range(m):
    bt(n-1,m,s+str[c])
  #introduce another character
  bt(n-1,m+1,s+str[m])
n = int(input())
bt(n,0,'')

Measured memory_bytes: 4412
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n = 0;
    cin >> n;
    string in = "";
    cin >> in;
    vector<int> left(n), right(n);
    for (int i=0; i<n; i++) {
        if (i == 0) left.at(i) = 0;
        else left.at(i) = (in.at(i-1) == 'W') ? left.at(i-1)+1 : left.at(i-1); 
    }
    for (int i=n-1; i>=0; i--) {
        if (i == n-1) right.at(i) = 0;
        else right.at(i) = (in.at(i+1) == 'E') ? right.at(i+1)+1 : right.at(i+1);
    }
    int ans = INT_MAX;
    for (int i=0; i<n; i++) {
        if (right.at(i) + left.at(i) < ans) {
            ans = right.at(i) + left.at(i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3076
from bisect import bisect_left, bisect_right
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(3,n + 1) if is_prime[i]]

prime = primes(10**5)
p_set = set(prime)
like = [3]
for i in prime:
    if (i+1)//2 in p_set:
        like.append(i)

Q = int(input())
for _ in range(Q):
    l, r = map(int,input().split())
    print(bisect_right(like, r) - bisect_left(like, l))

Measured memory_bytes: 77056
a, b, k= gets.chomp.split(' ').map(&:to_i)

answer=[]
(1..100).each do |n|
  if a%n ==0 && b%n ==0
    answer << n
  end
end

# answer => [1,2,4]
n = answer.reverse
# answer =>[4, 2, 1]
# indexは0スタートなので -1する
puts n[k -1]

Measured memory_bytes: 1788
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

path = [0,0,0,0]
for i in range(3):
    a,b = getMN()
    path[a-1] += 1
    path[b-1] += 1

if max(path) <= 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll; 

int N;
const int MAX_N = 100;
int h[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> h[i];
    
    int ans = h[N-1];
    for (int i = 0; i < N-1; i++) {
        if (h[i] > h[i+1]) ans += h[i] - h[i+1];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
if (N>=2)&(M>=2):
    ans = N*(N-1)/2 + M*(M-1)/2
elif (N<2)&(M<2):
    ans = 0
elif N<2:
    ans = M*(M-1)/2
elif M<2:
    ans = N*(N-1)/2

print(int(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

void solve(){
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    rep(i,n) rep(j,m){
        if(s[i]==t[j]){
            dp[i+1][j+1] = max(dp[i][j]+1,max(dp[i+1][j],dp[i][j+1]));
        }
        else{
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
        }
    }
    cout << dp[n][m] << endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    rep(_,t) solve();
}


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

using namespace std;

int a[1000];
int main()
{
    int n;
    cin >> n;
    for(int i =0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i =n-1;i>=1;i--){
        printf("%d ",a[i]);
    }
    printf("%d",a[0]);
    printf("\n");
    
    return 0;
}





Measured memory_bytes: 3224
#include <stdio.h>
#include <string.h>
int main()
{
    char s[50];
    scanf("%s",s);
    if (s[0]==s[1] && s[1]==s[2]){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
    return 0;
}

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

int main(int argc, char const *argv[]) {
  int alpha['z' - 'a' + 1] = {};

  string str;

  while (getline(cin, str)) {
    for (auto c : str) {
      if ('a' <= c && c <= 'z') {
        alpha[c - 'a']++;
      } else if ('A' <= c && c <= 'Z') {
        alpha[c - 'A']++;
      }
    }
  }

  int i;
  for (i = 0; i < 26; i++) {
    printf("%c", i + 'a');
    cout << " : " << alpha[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		int[][] count = new int[h][w];
		int[] dx = {0, 0, 1, -1, 1, -1, 1, -1};
		int[] dy = {1, -1, 0, 0, -1, 1, 1, -1};
		String S = "";
		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			S = scan.next();
			for (int j = 0; j < w; j++) {
				a[i][j] = S.charAt(j);
			}
		}
		int ny = 0;
		int nx = 0;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i][j] == '.') {
					for (int k = 0; k < 8; k++) {
						ny = i + dy[k];
						nx = j + dx[k];
						if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
						else {
							if (a[ny][nx] == '#') {
								count[i][j]++;
							}
						}
					}
				}
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i][j] == '.') {
					a[i][j] = encode(count[i][j]);
				}
			}
		}
		String str[] = new String[h];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (j == 0) {
					str[i] = String.valueOf(a[i][j]);
				} else {
					str[i] = str[i] + String.valueOf(a[i][j]);					
				}
			}
		}
		for (int i = 0; i < h; i++) {
			System.out.println(str[i]);
		}
	}

	static private char encode(int num) {
		switch (num) {
		case 1:
			return '1';
		case 2:
			return '2';
		case 3:
			return '3';
		case 4:
			return '4';
		case 5:
			return '5';
		case 6:
			return '6';
		case 7:
			return '7';
		case 8:
			return '8';
		case 0:
		return '0';
		}
		return '0';
	}
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC\n";
  } else if (r < 2800) {
    cout << "ARC\n";
  } else {
    cout << "AGC\n";
  }
}


Measured memory_bytes: 256
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()
val S: String = sc.next()

fun main(args: Array<String>) {
    var ans = 0

    for (i in 0 until N) {
        val x = S.substring(0, i).toSet()
        val y = S.substring(i).toSet()

        ans = Math.max(ans, x.intersect(y).size)
    }
    println(ans)
}


Measured memory_bytes: 31768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    vector<int> a;
    rep(i, 4){
        int p;
        cin >> p;
        a.push_back(p);
    }
    sort(a.begin(), a.end());
    int check[4] = {1, 4, 7, 9};
    bool flag = true;
    rep(i, 4) flag &= (check[i] == a[i]);
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3628
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int x,ans=1,cnt;
  cin >> x;
  for(int i=2; i<=40; i++) {
    cnt=i*i;
    while(cnt<=x) {
      ans=max(ans,cnt);
      cnt*=i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <climits>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

int main()
{
	vector<int> index;
	string ss, t;
	cin >> ss;
	cin >> t;
	rep(i, ss.size()-t.size()+1){
		rep(j, t.size()){
			if(!(ss[i+j] == t[j] || ss[i+j] == '?')){
				break;
			}else if(j==t.size()-1){
				index.push_back(i);
			}
		}
	}

	if(index.size()==0){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}


	string tmp="";

	int& last = index.back();
	rep(i, ss.size()){
	if(i==last){
		tmp = tmp + t;
		i += t.size()-1;
		continue;
	}
	
	if(ss[i]=='?'){
		tmp = tmp + "a";
		continue;
	}

	tmp = tmp + ss[i];

	}	
	cout << tmp << endl;
}



Measured memory_bytes: 256
#!/usr/bin/python3
# coding: utf-8

import sys


def main():
    line = sys.stdin.readline().strip()
    line1 = line.replace('eraser', '').replace(
        'erase', '').replace('dreamer', '').replace('dream', '')
    if line1 == '':
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll X, t;
    cin >> X >> t;
    print(max(X - t, 0LL));

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, m;
    scan(n, m);
    auto a = readln.split.to!(int[]);

    if (n >= m) {
        writeln(0);
        return;
    }

    a.sort();
    auto d = new int[](m - 1);
    foreach (i ; 0 .. m - 1) {
        d[i] = a[i + 1] - a[i];
    }
    d.sort();

    long ans;
    foreach (i ; 0 .. m - n) {
        ans += d[i];
    }
    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#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)            ll x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


ll solve(ll n,vector<ll>v,ll k){
    ll op1,op2;
    vector<ll>dp(n+1);
dp[1]=0;
for(int i=2;i<=n;i++)
{
    dp[i]=INT_MAX;
    for(int j=i-1;j>=1&&(i-j)<=k;j--)
    {
        dp[i]=min(dp[i],abs(v[i]-v[j])+dp[j]);
    }
}

return dp[n];

}

int main()
{
    FIO;
    ll a,b,c,d,e,f=0,sum=0,ans,ck=0,m,n,k,p,q,r,t,add=0,x,y,z;
    string s;

    cin>>n>>k;
    vector<ll>v(n+1);
    for(int i=1;i<=n;i++){cin>>v[i];}
    ans=solve(n,v,k);
    cout<<ans<<endl;



    return 0;
}



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

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);
    int k;
    string s;
    cin >> k >> s;

    if (s.size() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;


int median(int a, int b, int c) {
	static int abc[3];
	abc[0] = a, abc[1] = b, abc[2] = c;
	sort(abc, abc + 3);
	return abc[1];
}


int main() {
	int n; cin >> n;
	int x; cin >> x;
	if (x == 1 || x == 2 * n - 1) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	vector<int> a(2*n - 1);
	deque<int> d, e;
	for (int i = 1; i < x; i++) d.push_back(i);
	for (int i = x + 1; i <= 2 * n - 1; i++) e.push_back(i);
	a[n - 1] = x;
	for (int i = 1; i < n; i++) {
		if (i & 1) {
			if (!e.empty()) { a[n - 1 + i] = e.front(); e.pop_front(); }
			else { a[n - 1 + i] = d.front(); d.pop_front(); }
			if (!d.empty()) { a[n - 1 - i] = d.front(); d.pop_front(); }
			else { a[n - 1 - i] = e.front(); e.pop_front(); }
		}
		else {
			if (!d.empty()) { a[n - 1 + i] = d.front(); d.pop_front(); }
			else { a[n - 1 + i] = e.front(); e.pop_front(); }
			if (!e.empty()) { a[n - 1 - i] = e.front(); e.pop_front(); }
			else { a[n - 1 - i] = d.front(); d.pop_front(); }
		}
	}
	for (int i : a) cout << i << endl;
	return 0;
}

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

typedef pair<int,int> P;

int main(){
    int a,b;
    cin >> a >> b;
    for (int i = 1; i <= 1262; i++){
        int xa = i*0.08;
        int xb = i*0.1;
        if (a == xa && b == xb){
            cout << i << "\n";
            return 0;
        }
    }
    cout << -1 << "\n";
}

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

int main() {
	int M, D; cin >> M >> D;
	int d10, d_1;
	int cnt = 0;
	for (int i = 1; i <= M; ++i) {
    	for (int j = 1; j <= D; ++j) {
        	d10 = j / 10;
        	d_1 = j % 10;
        	if (d_1>=2 && d10>=2 && (d_1*d10==i)) {
            	cnt++;
            }
        }
    }
	cout << cnt << endl;
}

Measured memory_bytes: 256
def best_coins(r, i=3, bc=[0] * 4):
    global coins
    bc[i], r = divmod(r, coins[i])
    if i:
        best_coins(r, i - 1, bc)
    return bc


coins = (10, 50, 100, 500)
output = []

while True:
    price = int(input())
    if not price:
        break
    pocket = tuple(map(int, input().split()))
    remains = best_coins(sum(c * p for c, p in zip(coins, pocket)) - price)
    output.append('\n'.join('{} {}'.format(c, p - r) for c, p, r in zip(coins, pocket, remains) if p - r > 0))

print('\n\n'.join(output))

Measured memory_bytes: 8144
from itertools import permutations
from sys import stdin
N, M, R = [int(_) for _ in stdin.readline().rstrip().split()]
Rs = [int(_) for _ in stdin.readline().rstrip().split()]
D = [[10**9]*N for _ in range(N)]

for i in range(M):
    a, b, c = [int(_) for _ in stdin.readline().rstrip().split()]
    D[a-1][b-1] = c
    D[b-1][a-1] = c
for i in range(N):
    D[i][i] = 0

def warshall_floyd():
    for k in range(N):
        for i in range(N):
            for j in range(N):
                D[i][j] = min(D[i][j], D[i][k] + D[k][j])

warshall_floyd()
p = list(permutations(Rs, R))

ans = 10**9
for i in p:
    tmp = 0
    for j in range(R-1):
        tmp += D[i[j]-1][i[j+1]-1]
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 48476
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, a, b int
	fmt.Scan(&n)
	cards := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(cards)))
	for i := 0; i < n; i += 2 {
		a += cards[i]
		if i+1 < n {
			b += cards[i+1]
		}
	}
	fmt.Println(a - b)
}


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

int main(){
  int n, m, s[3], c[3];
  int ans = -1;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> s[i] >> c[i];
  }
  
  if(n==1){
    for(int i=0;i<10;i++){
      int flag=1;
      for(int j=0;j<m;j++){
        if(s[j]!=1||c[j]!=i)flag=0;
      }
      if(flag==1){
        ans=i;
        break;
      }
    }
  }
  if(n==2){
    for(int i=10;i<100;i++){
      int flag=1;
      int n1, n2;
      n2 = i%10;
      n1 = (i/10)%10;
      for(int j=0;j<m;j++){
        if(s[j]==1&&c[j]!=n1)flag=0;
        if(s[j]==2&&c[j]!=n2)flag=0;
      }
      if(flag==1){
        ans=i;
        break;
      }
    }
  }
  if(n==3){
    for(int i=100;i<1000;i++){
      int flag=1;
      int n1, n2, n3;
      n3 = i%10;
      n2 = (i/10)%10;
      n1 = ((i/10)/10)%10;
      //cout << "[" << n1 << n2 << n3 << "]";
      for(int j=0;j<m;j++){
        if(s[j]==1&&c[j]!=n1)flag=0;
        if(s[j]==2&&c[j]!=n2)flag=0;
        if(s[j]==3&&c[j]!=n3)flag=0;
      }
      if(flag==1){
        ans=i;
        break;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>


#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define CON 1000000000000
#define SIX 1000000
using namespace std;

int n;
int find(long now, bool is_3, bool is_5, bool is_7){
    if(now > n){
        return 0;
    }
    int ans = is_3 && is_5 && is_7;
    ans += find(now * 10 + 3, true, is_5, is_7);
    ans += find(now * 10 + 5, is_3, true, is_7);
    ans += find(now * 10 + 7, is_3, is_5, true);
    return ans;
}

int main(){
    cin >> n;
    cout << find(0, false, false, false) << endl;
}


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

int main(){
	string spell;
	getline(cin, spell);
  	int i = spell.length();
  	if (spell[i-1] == 's'){
    	cout<<spell<<'e'<<'s'<<endl;}
  	else{
  		cout<<spell<<'s'<<endl;}
  	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

bool checkA(char *p){
    int eqCnt=0;
    
    if (*p++!='>') return false;
    if (*p++!='\'') return false;
    if (*p!='=') return false;
    while (*p++=='=') eqCnt++;
    p--;
    if (*p++!='#') return false;
    while (*p++=='=') eqCnt--;
    p--;
    if (eqCnt!=0) return false;
    if (*p++!='~') return false;
    if (*p!='\0') return false;
    
    return true;
}

bool checkB(char *p){
    if (*p++!='>') return false;
    if (*p++!='^') return false;
    if (*p!='Q') return false;
    while (*p++=='Q'){
        if (*p++!='=') return false;
    }
    p--;
    if (*p++!='~' || *p++!='~') return false;
    if (*p!='\0') return false;
    
    return true;
}

int main(void){
    int n;
    char str[256];
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%s", str);
        if (checkA(str)){
            puts("A");
        } else if (checkB(str)){
            puts("B");
        } else {
            puts("NA");
        }
    }
    
    return 0;
}

Measured memory_bytes: 2504
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 123;
#define int long long 
int n, m;
int c;
int x[maxn], sum[maxn], rsum[maxn], v[maxn], rans[maxn];
main () { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    cin >> c;
    int ans = 0;
    for(int i = 1; i <= n; i++){
    	cin >> x[i] >> v[i];
    	sum[i] = sum[i - 1] + v[i];
    	ans = max(ans, sum[i] - x[i]);
	}

	for(int i = n; i >= 1; i--) {
		rsum[i] = rsum[i + 1] + v[i];
		rans[i] = max(rans[i + 1], rsum[i] - (c - x[i]));
		ans = max(ans, rsum[i] - (c - x[i]));
	}
	for(int i = 1; i <= n; i++) {
		ans = max(ans, sum[i] - 2 * x[i] + rans[i + 1]);
	}
	for(int i = 1; i <= n; i++)
		rans[i] = 0;
	for(int i = 1; i <= n; i++)
			rans[i] = max(rans[i - 1], sum[i] - x[i]);
  	for(int i = n; i >= 1; i--)
  			ans = max(ans, rsum[i] - 2 * (c - x[i]) + rans[i - 1]);
  	 cout << ans;
}




Measured memory_bytes: 7548
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<assert.h>
#include<stdlib.h>
#include<stack>
using namespace std;
/*********************Contest Template***********************/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<int,int> Cord;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);
struct S{
    int a,b; S(){}S(int _a,int _b){
        a=_a;
        b=_b;
    }
    const bool operator<(const S &o) const{
        return a<o.a;
    }
};
priority_queue<int,vector<int>,greater<int>> mpq;
#define SPACE 0
#define NL 1
inline void showAll(vector<int> &v,int NL_or_space){ 
    //0 is space, 1 is NL
    for(int &here:v){
        printf("%d",here);
        printf("%c",(NL_or_space)?'\n':' ');
    }
}
/*********************Contest Template***********************/
const int SIZE= 22;

int value[SIZE],cost[SIZE];

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

    for(int i=1 ; i<=n ; i++){
        scanf("%d",&value[i]);
    }	

    for(int i=1 ; i<=n ; i++){
        scanf("%d",&cost[i]);
    }

    int ans=0;
    for(int i=0 ; i< (1<<20) ; i++){
        int v_sum=0,c_sum=0;
        for(int j=0 ; j<n ; j++){
            if((1<<j)&i) {
                v_sum+=value[j+1];
                c_sum+=cost[j+1];
            }
        }
        ans=max(ans,v_sum-c_sum);
    }
    
    printf("%d\n",ans);
	return 0;
}



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

#define sz(a) int(a.size())

bool vis[2510];
vector <int> adj[2510];

void dfs (int u) {
	vis[u] = 1;
	for (int v : adj[u]) {
		if (!vis[v]) dfs(v);
	}
}

int main() {
	int n, m, p;
	cin >> n >> m >> p;

	vector <tuple<int,int,int>> edges;
	for (int i = 0; i < m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		edges.emplace_back(u, v, w);
		adj[v].push_back(u);
	}

	dfs(n-1);

	const int INF = 1e9;
	vector <int> D (n, INF);
	D[0] = 0;

	for (int i = 1; i < n; i++) {
		for (auto t : edges) {
			int u = get<0>(t), v = get<1>(t), w = get<2>(t);
			int cost = D[u] != INF ? D[u]+p-w : INF;
			if (D[v] > cost) D[v] = cost;
		}
	}

	for (auto t : edges) {
		int u = get<0>(t), v = get<1>(t), w = get<2>(t);
		int cost = D[u] != INF ? D[u]+p-w : INF;
		if (vis[v] && D[v] > cost) {
			puts("-1");
			return 0;
		}
		if (D[v] > cost) D[v] = cost;
	}

	cout << max(0, -D[n-1]) << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = (ll)(1e9 + 7);
const int MAX_N = 3010;
ll dp[MAX_N][MAX_N];

int main2() {
  int N; cin >> N;
  string s; cin >> s;

  CLR(dp, 0);
  dp[0][0] = 1;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == '<') {
      ll add = 0;
      for (int k = 0; k <= i+1; k++) {
        (dp[i+1][k] += add) %= MOD;
        (add += dp[i][k]) %= MOD;
      }
    } else if (s[i] == '>') {
      ll add = 0;
      for (int k = i+1; k >= 0; k--) {
        (add += dp[i][k]) %= MOD;
        (dp[i+1][k] += add) %= MOD;
      }
    }
  }
  ll ans = 0;
  for (int j = 0; j < N; j++) {
    ans += dp[N-1][j];
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 71040
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//絶対値
long long int change_plus(long long int a) {
	if (a < 0) { return -a; }
	if (a >= 0) { return a; }
}
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

int main() {
	long long int n, m, k = 0;
	char str[15],str2[15],str3[15];
	scanf("%lld%lld",&n,&m);
	if (n == 1) { n += 13; }
	if (m == 1) { m += 13; }
	if (n > m) { printf("Alice"); }
	else if (n == m) { printf("Draw"); }
	else { printf("Bob"); }
}

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

int main(void) {
    int N;
    bool rule = true;
    cin >> N;
    vector<string> W(N);
    cin >> W[0];
    for(int i=1;i<N;i++) {
        cin >> W[i];
        if(W[i-1][W[i-1].size()-1] != W[i][0]){
//printf("i:%d c:%c\n", i, W[i][0]);
            rule = false;
        }
        for(int j=0;j<i;j++) {
            if(W[j] == W[i]) {
//printf("i:%d bef:%s\n", i, &W[i][0]);
                rule = false;
            }
        }
    }

    if(rule) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


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

int main() {
  int n, x;
  rep(p,1000000){
    cin >> n >> x;
    if(n != 0){
      int ans = 0;
      for(int i = 1; i <= n-2; i++)
        for(int j = i+1; j <= n-1; j++)
          for(int k = j+1; k <= n; k++)
            if(i+j+k == x)
              ans++;
      cout << ans << endl;
    }else return 0;
  }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

// struct path
// {
//     pair<ll, ll> f;
//     pair<ll, ll> t;
// };

// struct cmp
// {
//     bool operator() ( path a, path b ) const
//     { return std::make_pair(a.f,a.t) > std::make_pair(b.f,b.t) ; }
// };

void solve()
{
    ll n, m, x;
    cin >> n >> m >> x;
    ll val[n][m];
    ll c[n];
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            cin >> val[i][j];
        }
    }

    ll ans = -1;
    for (int i = 0; i < (1 << n); i++)
    {
        ll cost = 0;
        vector<ll> alg(m, 0);
        for (int j = 0; j < n; j++)
        {
            if ((i>>j)&1)
            {
                cost += c[j];
                for (int k = 0; k < m; k++)
                {
                    alg[k] += val[j][k];
                }
            }
        }

        bool f = true;
        for (int j = 0; j < m; j++)
        {
            if (alg[j] < x)
            {
                f = false;
                break;
            }
        }

        if (f)
        {
            if (ans == -1 || ans > cost)
            {
                ans = cost;
            }
        }
    }

    cout << ans << endl;
}

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

    // ll t;
    // cin >> t;

    // while (t--)
    // {
    //     solve();
    // }
    solve();
    return 0;
}

Measured memory_bytes: 3660
n,k=map(int,input().split())
p=list(map(int,input().split()))
for i in range(n-k+1):
  if i==0:
    s=sum(p[:k])
    m=s
  else:
    s=s+p[i+k-1]-p[i-1]
    m = max(m,s)
print((m+k)/2)

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

const int M=1e5+5;
char tt[M];
int t[M];
int score[3]; // 0 r, 1 s, 2 p

int tmp[M];

int dp[2][3];

int solve(int n)
{
	for(int i=0;i<3;i++)
		dp[1][i]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
			dp[i&1][j]=0;
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
			{
				if(j==k) continue;
				dp[i&1][j]=max(dp[i&1][j],dp[(i+1)&1][k]+(j==(tmp[i]+2)%3?score[j]:0));
			}
	}
	int ans=0;
	for(int i=0;i<3;i++)
		ans=max(ans,dp[(n+1)&1][i]);
	return ans;
}

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<3;i++)
		scanf("%d",&score[i]);
	scanf("%s",tt);
	for(int i=0;i<n;i++)
	{
		if(tt[i]=='r')
			t[i]=0;
		else if(tt[i]=='s')
			t[i]=1;
		else
			t[i]=2;
	}
	int ans=0;
	for(int i=0;i<k;i++)
	{
		int m=0;
		for(int j=i;j<n;j+=k)
			tmp[m++]=t[j];
		ans+=solve(m);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
// Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

queue <int> deck,temp,tempp;

void shuffle(int x,int c){
    while(x--){
        temp.pp(deck.front());
        deck.pop();
    }
    while(c--){
        tempp.pp(deck.front());
        deck.pop();
    }
    while(temp.size()){
        tempp.pp(temp.front());
        temp.pop();
    }
    while(deck.size()){
        tempp.pp(deck.front());
        deck.pop();
    }
    while(tempp.size()){
        deck.pp(tempp.front());
        tempp.pop();
    }
}

void init(int n){
    while(deck.size()) deck.pop();
    
    for(int i = n ; i >= 1 ; i--) deck.pp(i);
}
main(){
    int n,r;
    int a,b;
    
    while(cin >> n >> r){
        if(n == 0) break;
    
        init(n);
        
        while(r--){
            cin >> a >> b;
            shuffle(a-1,b);
        }
        
        cout << deck.front() << endl;
    }
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>> 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("explicit.in","r",stdin);freopen("explicit.out","w",stdout)
#define mp make_pair
#define pll pair <lli,lli>
#define vll vector <lli>
#define pq2 priority_queue<pair<lli,lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define ld long double 
const long double pi = 3.1415926535898;
#define dec greater<lli>()
//const lli mod=1000000007;
const lli mod=100000000;
using namespace std;

int main()
{
    fio;
    lli n;
    cin>>n;
    lli a[n+5];
    for (int i=1;i<=n;i++)
    cin>>a[i];
    lli dp[n+5][n+5];
    memset(dp,0,sizeof(dp));
    for (int i=n;i>=1;i--)
    {
        for (int j=i;j<=n;j++)
        {
            dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
        }
    }
    cout<<dp[1][n];
    return 0;
}


Measured memory_bytes: 74160
#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 1003;
const int INF = 0x7FFFFFFF;
char S[MAXN];
char T[MAXN];

int strcmpLen(char *s1,char *s2,int Len)
{
    int c = Len;
    for(int i=0;i<Len && s1[i] && s2[i];i++)
    {
        if(s1[i]==s2[i])
            c--;
    }
    return c;
}

int main(void)
{

    scanf("%s",S);
    scanf("%s",T);
    int sLen = strlen(S);
    int tLen = strlen(T);

    int minVal = INF;

    for(int i=0;i<=sLen-tLen;i++)
    {
        minVal = std::min(minVal,strcmpLen(S+i,T,tLen));
    }
    printf("%d\n",minVal);
    return 0;
}


Measured memory_bytes: 1736
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

struct Eratosthenes{
  vector<ll> sieve;// sieve[i]: 数字iがエラトステネスで篩落とされた時の素数

  Eratosthenes(ll n): sieve(n+1){
    for(int i=0; i<=n; i++) sieve[i] = i;
    for(ll i=2; i*i<=n; i++){
      if(sieve[i] < i) continue;
      for(ll j=i*i; j<=n; j+=i) sieve[j] = min(sieve[j], i);
    } 
  }

  vector<ll> prime_divisors(ll x, bool tmp=false){
    vector<ll> res(1,1);//back()のところで ひっかかるので1を入れとかないとダメ
    while(x > 1){
      if(res.back() != sieve[x]) res.push_back(sieve[x]);
      x /= sieve[x];
    }
    return res;
  }

  map<ll, int> prime_divisors(ll x, int tmp=0){
    map<ll, int> mp;
    while(x > 1){
      mp[sieve[x]]++;
      x /= sieve[x];
    }
    return mp;
  }
};

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

  sort(A.begin(), A.end());//82行目のbreakを入れないとTLEになるらしく，それならsortしないといけない
  // const int INF  =1e6+1;// sortじゃなくてこっちがTLEの原因?
  const int INF = A.back()+1;
  vector<int> vec(INF, 0);
  for(int i=0; i<N; i++){
    if(vec[A[i]] >= 2) continue;// 84行目の代わり
    for(int j=1; j*A[i]<=INF; j++){
      vec[A[i]*j]++;
      // if(vec[A[i]*j] >= 2) break;// これいれたらWA?
    }
  }
  int ans = 0;
  for(ll i=0; i<N; i++){
    if(vec[A[i]] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 1e5+10;
int N;
string s[MAX_N];

void solve()
{
	int ac=0,wa=0,tle=0,re=0;
	for(int i=0;i<N;++i){
		string& ss = s[i];
		if(ss[0]=='A') ac++;
		if(ss[0]=='W') wa++;
		if(ss[0]=='T') tle++;
		if(ss[0]=='R') re++;
	}
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
}

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


Measured memory_bytes: 6872
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N, Q;
vector<ll> A;
ll sum[100005];
ll sumE[100005];
ll sumO[100005];

bool check(int turn, ll X){
  int aok = turn/2;
  int tak = turn - turn/2;

  int a = N - tak;
  int b = a - aok;
  if(b < 0) return false;
  return abs(A[b]-X) <= abs(A[a]-X);
}

ll solve(ll X){
  int lb = 0, ub = N+1;
  while(ub-lb>1){
    int t = (lb+ub)/2;
    if(check(t, X)) lb = t;
    else ub = t;
  }

  int aok = lb/2;
  int tak = lb - lb/2;

  ll ret = sum[N-1] - ((N-tak-1>=0)?sum[N-tak-1]:0);
  if(lb != N){
    int pos = N - lb - 1;
    if(lb%2==0){
      if(pos%2==0) ret += sumE[pos];
      else ret += sumO[pos];
    }else{
      pos--;
      if(pos >= 0){
        if(pos%2==0) ret += sumE[pos];
        else ret += sumO[pos];
      }
    }
  }

  return ret;
}

int main(){
  cin >> N >> Q;
  rep(i,N){
    ll a;
    cin >> a;
    A.push_back(a);
  }

  rep(i,N){
    sum[i] = A[i] + ((i-1>=0)?sum[i-1]:0);
    if(i%2==0) sumE[i] = A[i] + ((i-2>=0)?sumE[i-2]:0);
    else sumO[i] = A[i] + ((i-2>=0)?sumO[i-2]:0);
  }

  rep(i,Q){
    ll X;
    cin >> X;
    cout << solve(X) << endl;
  }
  
  return 0;
}


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

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



int main(){
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   cout<<c-d+b<<" "<<d+c-a<<" "<<a-d+b<<" "<<b+c-a<<endl;


   return 0;
}



Measured memory_bytes: 256
#include <iostream>
    #include <vector>
    #include <map>
     
    using namespace std;
     
    int main() {
        int h, w;
        vector< pair<int, int> > m8 = {{-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
        cin >> h >> w;
        vector< vector<char> > s(h + 2, vector<char>(w + 2, '.'));
        for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) cin >> s.at(i).at(j);
        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {
                if (s.at(i).at(j) - '.') cout << '#';
                else {
                    int n = 0;
                    for (int k = 0; k < 8; ++k) if (s.at(i + m8.at(k).first).at(j + m8.at(k).second) - '.') ++n;
                    cout << n;
                }
            }
            cout << endl;
        }
        return 0;
    }

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
/*#define fast ios_base::sync_with_stdio(0); cin.tie(0)*/
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const double pi = acos(-1);
typedef long long ll;
int main()
{
	//fast;
	
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	a+=b;
	c+=d;
	if(a>c)cout<<"Left";
	else if(c>a)cout<<"Right";
	else cout<<"Balanced";
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
using namespace std;
int a[1003];
int main() {
    long long n;
    scanf("%lld", &n);
    if (n == 0) {
        puts("0");
        return 0;
    }
    long long tmp = 0, cj = 0;
    for (int i = 1; ; ++i) {
        if (i & 1) {
            tmp += (1ll << (long long)(i - 1));
            a[i] = 1;
        }
        cj += (1ll << (long long)(i - 1));
        if (tmp >= n && tmp - cj <= n) {
            cj = i;
            for (int j = i; j >= 1; --j) {
                if (tmp - (1ll << (long long)(j - 1)) >= n) {
                    a[j] ^= 1;
                    tmp -= 1ll << (long long)(j - 1);
                }
            }
            break;
        }
    }
    int hs1 = 0;
    for (int i = cj; i >= 1; --i) {
        hs1 |= a[i];
        if (hs1)
            printf("%d", a[i]);
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll(x);cin >> (x);
#define stin(x) str(x);cin >> (x);
#define vllin(x,n) vll(x)(n);FOR(i,0,n-1){cin >> (x)[i];}
#define vllin2(a,b,n) vll(a)(n);vll(b)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vllin3(a,b,c,n) vll(a)(n);vll(b)(n);vll(c)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >> (x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vpl4in(x,n) vpl4(x)((n),mp(0,0));FOR(i,0,n-1){cin >> x[i].fi >> x[i].se;}
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define rFOR(i,b,a) for(ll i=a;i>=b;i--)
#define SORT(x) sort(x.be,x.en)
#define rSORT(x) sort(x.rbegin(),x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll MOD = 1000000007;

signed main()
{
    llin(h);
    llin(w);
    vvvll d(h,vvll(w,vll(4,1000000)));
    vector<str> a(h);
    FOR(i,0,h-1){
        cin >>a[i];
    }
    ll tj[]={-1,-1,1,1};
    ll ti[]={-1,1,-1,1};
    ll i,j;
    FOR(k,0,3){
    FOR(ii,0,w-1){
        i=ii;
        if(ti[k]==1) i=w-1-ii; 
        FOR(jj,0,h-1){
            j=jj;
            if(tj[k]==1) j=h-1-jj;
            if(a[j][i]=='#'){
                d[j][i][k]=0;
            }else{
                if(jj!=0) d[j][i][k]=d[j+tj[k]][i][k]+1;
                if(ii!=0) d[j][i][k]=min(d[j][i][k],d[j][i+ti[k]][k]+1);
            }
        }
    }
    }
    ll dd=0;
    ll s=0;
    FOR(ii,0,w-1){
        FOR(jj,0,h-1){
            dd=1000000;
            FOR(k,0,3){
                dd=min(d[jj][ii][k],dd);
            }
            s=max(s,dd);
        }
    }
    sal(s)
}

Measured memory_bytes: 71680