akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
///////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<int> a(n);
    map<int, int> m;
    rep(i,n) cin >> a[i], m[a[i]]++;

    int ans = n;
    int tmp = 0;

    for (auto v : m) {
        if (v.second > 1) {
            if (v.second%2==0) {
                if (tmp) {
                    ans -= v.second-1;
                    tmp--;
                } else {
                    ans -= v.second-1;
                    tmp++;
                }
            } else {
                ans -= v.second-1;
            }
        }
    }

    cout << ans - tmp << endl;

    return 0;
}

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

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> h(n);

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

    int min = h[n-1];
    for(int i = n-2; i >= 0; i--){
        if(h[i] < min) min = h[i];
        else if(h[i] - min >= 2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	if(n >= k * 2 - 1)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int p,q,ans=1,j;

int so(int n){
  for(int i=2;i*i<=n;i++)if(n%i==0)return 1;
  return 0;
}

int main(){
  cin>>p>>q;
  if(so(q)){
    for(int i=2;q>=i;i++){
      for(j=0;q%i==0;j++){
	q/=i;
	if(p%i==0)p/=i,j--;
      }
      if(j==0)continue;
      ans*=i;
    }
    cout<<ans<<endl;
  }else cout<<q<<endl;
  return 0;
}

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

using ll=long long;

int main() {
  ll A,V,B,W,T; cin >>A >>V >>B >>W >>T;
  ll x=abs(A-B);
  ll y=(V-W)*T;
  cout <<(x<=y ? "YES":"NO") <<endl;
  return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
	int i, n;
	long int a, min = 1000000, max = -1000000, sum = 0;

	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		scanf("%ld", &a);
		if (min > a){
			min = a;
		}
		if (max < a){
			max = a;
		}
		sum = sum + a;
	}
	printf("%ld %ld %ld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 1032
import datetime

s = input()
ans = [['NA', 'MMYY'], ['YYMM', 'AMBIGUOUS']]

try:
    datetime.datetime.strptime(s,"%y%m")
    ans1 = 1
except ValueError:
    ans1 = 0

try:
    datetime.datetime.strptime(s,"%m%y")
    ans2 = 1
except ValueError:
    ans2 = 0

print(ans[ans1][ans2])


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

void fnOutput(const vector<int> &argviSort, int argiSortCnt)
{
  for (int i = 0; i < argviSort.size(); i++)
  {
    if (i) cout << " ";
    cout << argviSort[i];
  }
  cout << endl;
  cout << argiSortCnt << endl;
}

void fnSelectionSort(vector<int> &argviSort, int &argiSortCnt)
{
  for (int ixSorting = 0; ixSorting < argviSort.size(); ixSorting++)
  {
    int ixMinimum = ixSorting;
    bool bSorting = false;

    for (int j = ixSorting; j < argviSort.size(); j++)
    {
      if (argviSort[j] < argviSort[ixMinimum])
      {
        ixMinimum = j;
        bSorting = true;
      }
    }
    if (bSorting == true)
    {
      swap(argviSort[ixSorting], argviSort[ixMinimum]);
      argiSortCnt++;
    }
  }
}

int main()
{
  int iSortCnt = 0;
  vector<int> viSort;
  int iMaxSize;
  
  cin >> iMaxSize;
  for (int i = 0; i < iMaxSize; i++)
  {
    int iNum;
    cin >> iNum;
    viSort.push_back(iNum);
  }

  fnSelectionSort(viSort, iSortCnt);
  fnOutput(viSort, iSortCnt);

  return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
#include<algorithm>
using namespace std;
int dat[10000];
int dp[2][2][10001];//[ツづつアツづ慊づ[ツづづつソツづ珪[ツ暗ェツ人ツ姪堋づ個づ卍つ、ツづ個陳キツつウ]
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a-1;i++){
		scanf("%d",dat+i);
	}
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			for(int k=0;k<5001;k++)
				dp[i][j][k]=999999999;
	dp[0][0][1]=0;
	for(int i=1;i<a;i++){
		for(int j=0;j<=a/2;j++){
			dp[i&1][0][j]=dp[i&1][1][j]=999999999;
		}
		for(int j=0;j<=a/2;j++){
			if(j)dp[i&1][0][j]=min(dp[!(i&1)][0][j-1],dp[!(i&1)][1][j-1]+dat[i-1]);
			dp[i&1][1][j]=min(dp[!(i&1)][1][j],dp[!(i&1)][0][j]+dat[i-1]);
		}
	}
	printf("%d\n",min(dp[(a-1)&1][1][a/2],dp[(a-1)&1][0][a/2]));
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	cin>>n>>m;
    	vi h(n);
    	cin>>h;
    	vi v[n+2];
    	for(i=0;i<m;i++)
    	{
    		cin>>l>>k;
    		v[l].pb(k);
    		v[k].pb(l);
    	}
    	ll ans=0;
    	for(i=1;i<=n;i++)
    	{
    		ll t=1;
    		for(auto j:v[i])
    		{
    			if(h[j-1]>=h[i-1])
    				t=0;
    		}
    		if(t) ans++;
    	}
    	cout<<ans;
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    int cnt = 1;
    for(int i = 1; i < n; i++){
        bool flag = true;
        for(int j = 0; j < i; j++){
            if(h[j] > h[i]){
                flag = false;
                break;
            }
        }
        if(flag == true){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    int n,m;
    ArrayList<int[]> list;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            m = sc.nextInt();
            if(n==0 && m==0) break;

            //a, b, w
            list = new ArrayList<int[]>();
            for(int i=0; i<m; i++){
                int a = sc.nextInt(), b = sc.nextInt();
                int w = sc.nextInt();
                int[] tmp = {a-1,b-1,w};
                list.add(tmp);
            }

            Collections.sort(list, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        return a[2] - b[2];
                    }
                });

            int ans = Integer.MAX_VALUE;
            for(int i=0; i<m && m-i>=n-1; i++){
                ans = Math.min(ans, kruskal(i));
            }

            if(ans==Integer.MAX_VALUE) ans = -1;
            System.out.println(ans);
        }
    }

    int kruskal(int idx){
        init();

        int res = 0;
        for(int i=idx;i<m; i++){
            int[] ab = list.get(i);
            if(!same(ab[0],ab[1])){
                unite(ab[0],ab[1]);
                res = ab[2];
            }
        }

        boolean same = true;
        for(int i=1; i<n; i++){
            if(!same(0,i)){
                same = false;
                break;
            }
        }

        if(same) return res-list.get(idx)[2];
        else return Integer.MAX_VALUE;
    }

    int[] par, rank;
    void init(){
        par = new int[n];
        rank = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[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(rank[x]<rank[y]) par[x] = y;
        else{
            par[y] = x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }
    boolean same(int x, int y){
        return find(x)==find(y);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
typedef long long ll;

void solve(){
    int x, a;
    cin >> x >> a;
    if(x < a)
        cout << 0 << endl;
    else 
        cout << 10 << endl;
}

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

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <list>

using namespace std;


int main(int argc, char * argv [] ) {
    string str;
    cin >> str;

    int strSize = str.size();
    for (int i = 0; i < strSize; ++i) {
            cout << str.at(i);
        if (i == 3) {
            cout << " ";
        }
    }
    cout << endl;

	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i,n){
        if (!bool(i & 1) && bool(a[i] & 1)) ans++;
    }
    cout << ans << endl;
}


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

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		//final double PI = 3.14159265;
		NScanner sc = new NScanner(System.in);
		for(;;){
			int H = sc.nextInt();
			int W = sc.nextInt();
			if(H==0 && W==0) break;
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j)
					System.out.print("#");
				System.out.println();
			}
			System.out.println();

		}
		/*int n = sc.nextInt();
		long sum = 0;minv = INF, maxv = -INF;
		for(int i = 0; i < n; ++i){
			int a = sc.nextInt();
			sum += a;
			minv = Math.min(minv, a);
			maxv = Math.max(maxv, a);
		}
		System.out.printf("%d %d %d\n", minv, maxv, sum);*/
	}

}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	private boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


Measured memory_bytes: 33400
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

const int MOD = 1e9+7;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<ll>> dp(n+1, vector<ll>(k+1));
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    vector<ll> sum(k+2);
    rep(j, k+1)
      sum[j+1] = (sum[j]+dp[i-1][j])%MOD;
    rep(j, k+1)
      dp[i][j] = (sum[j+1]-sum[max(0, j-a[i-1])]+MOD)%MOD;
  }
  cout << dp[n][k] << endl;
  return 0;
}

Measured memory_bytes: 80256
#include <stdlib.h> 
#include <stdio.h>
#include <iostream>


using namespace std; 

void swap(int &x, int &y) {
    int aux = x;
    x = y;
    y = aux;
} 

int main()
{
    int x,y,z;

    cin>>x;
  	cin>>y;
  	cin>>z;

    swap(x,y);
    swap(x,z);

    cout<<x<<" "<<y<<" "<<z;
}



Measured memory_bytes: 3636
n = int(input())
r = n // 4
flag = False
for i in range(r+1):
  for j in range(r+1):
    if 4*i + 7*j == n:
      flag = True
      break
  if flag:
    print('Yes')
    break
  elif flag == False and i == r:
    print('No')
    break

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

class Program
{
    //static int[] dp;
    //static decimal[,,] dp;
    //static decimal N;
    static void Main(string[] args)
    {
        // 入力
        int[] input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
        int N = input[0];
        input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
        int[] ret = new int[N + 1];
        
        for(int i=0; i<N; i++)
        {
            ret[input[i]] = (i+1);
        }

        for(int i=1; i<=N; i++)
        {
            Console.Write(ret[i] + " ");
        }
        Console.WriteLine();
    }
}


Measured memory_bytes: 26328
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int sum = 0;
		for (int i = 0; i < m; i++) {
			sum += a[i];
		}
		if (sum > n) {
			System.out.println(-1);
		} else {
			System.out.println(n - sum);
		}
	}
}


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

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  for(int i=0; i < N; i++){
    cin >> A.at(i);
    H -= A.at(i);
  }
  if(H > 0){
    cout << "No" <<endl;
  }else{
    cout << "Yes" <<endl;
  }
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void)
{
          int p , n , i;
          scanf("%d%d", &p , &n) ;
          int a[n] ;
          for ( i = 0 ; i< n ; i++)
          {
                    scanf("%d", &a[i]) ;
          }
          int sum = 0 ;
          for ( i = 0 ; i < n ; i++)
          {
                    sum = sum + a [i] ;
          }
          if (sum >= p) printf("Yes") ;
          else printf("No") ;
}


Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;

namespace ABC107
{
    class C
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long K = input[1];

            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long[] Res = new long[N - K + 1];
            for (long i = 0; i < N - K + 1; i++)
            {
                Res[i] = Math.Min(Math.Abs(x[i]) + Math.Abs(x[i + K - 1] - x[i]), Math.Abs(x[i + K - 1]) + Math.Abs(x[i + K - 1] - x[i]));
            }

            Console.WriteLine(Res.Min());
        }
    }
}


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

public class Main {

	public static void main(String[] args) {
		Main ans = new Main();
		System.out.printf("%.15f\n",ans.solve());
	}
 
	private double solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ones=0,twos=0,threes=0;
		for(int i=1;i<=N;i++) {
			int val = sc.nextInt();
			if(val==1) ones++;
			else if(val==2) twos++;
			else threes++;
		}
		double [][][] dp = new double[301][301][301];
		return solve(ones, twos, threes, dp, N);
	}

	private double solve(int ones, int twos, int threes, double [][][] dp, int N) {

		if (ones <0 || twos<0 || threes<0) return 0;
		if (ones==0 & twos==0 && threes==0) return 0;

		  
		if(dp[ones][twos][threes] > 0.0) return dp[ones][twos][threes];

		double choose_ones = ones * solve(ones-1, twos, threes, dp, N);
		double choose_twos = twos * solve(ones+1, twos-1, threes, dp, N);
		double choose_threes = threes * solve(ones, twos+1, threes-1, dp, N);
		
		double answer = (N + choose_ones + choose_twos + choose_threes)/(ones+twos+threes);
		dp[ones][twos][threes] = answer;
		return answer;
	}
}

Measured memory_bytes: 273816
x,y,z,k = map(int, input().split())
aa = sorted(list(map(int, input().split())))
bb = sorted(list(map(int, input().split())))
cc = sorted(list(map(int, input().split())))

ab = sorted(a+b for a in aa for b in bb)[:-k-1:-1]
abc = sorted(s+c for s in ab[:k] for c in cc)[:-k-1:-1]
print(*abc, sep='\n')


Measured memory_bytes: 160620
#include <stdio.h>
#include <stdlib.h>
 
long compare(const void *a, const void *b)
{
    return *(long*)a - *(long*)b;
}

int main(void){
  int i,j,n;
  long a[200000];
  
  scanf("%d", &n);
  
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  qsort(a, n, sizeof(long), compare);
  
  for(i=0;i<n-1;i++){
      if(a[i]==a[i+1]){
        printf("NO");
        return 0;
    }
  }
  
  printf("YES");
  return 0;
}

Measured memory_bytes: 3324
use std::io;


fn main() {
    let (n, m) = {
        let i = read::<u64>();
        (i[0], i[1])
    };

    let mut ans = 1;
    
    if n == 1 {
    println!("{}", m);
    return;
    }

    for i in 1..(m / n + 1) {
        if m % i == 0 { ans = i; }
    }

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


#[allow(dead_code)]
fn ncr(n: u64, r: u64) -> u64 {
    match (n, r) {
        (0, _) | (_, 0) => 1,
        _ => ((ncr(n, r - 1) * (n - r + 1) / r))
    }
}


#[allow(dead_code)]
fn divide(n: u64) -> Option<u64> {
    for i in 2..(n as f64).sqrt().ceil() as u64 + 2 {
        if n % i == 0 {
            return Some(i);
        }
    } 
    return None;
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(){

	int h,w,n,a[10000],b[100][100];
	cin>>h>>w>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	
	int cnt=0,now;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			now=j;
			if(i%2) now=w-1-j;
			b[i][now]=cnt+1;
			a[cnt]--;
			if(a[cnt]==0) cnt++;
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(j) cout<<" ";
			cout<<b[i][j];
		}
		cout<<endl;
	}
	
	return 0;
}


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

// マクロ
// forループ
#define REP(i,n) for(ll i=0;i<(ll)(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--)
// xにはvectorなどのコンテナ
#define ALL(x) (x)begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
// 出力
#define PRINT(x) cout<<(x)<<endl
#define PRINTA(x,n) REP(i,n)PRINT(x[i])
// 定数
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
// 略記
#define PB push_back
#define MP make_pair

const int MAX_N = 15;

int N, K, a[MAX_N];

int b[MAX_N];

int main() {
    cin >> N >> K;
    REP(i, N) cin >> a[i];

    ll min_cost = INF;
    REP(bit, 1<<N) {
        REP(i, N) {
            b[i] = a[i];
        }

        ll cur_cost = 0;
        int colors = 1;
        int max_h = b[0];

        FOR(i, 1, N-1) {
            if (b[i] > max_h) {
                colors++;
                max_h = b[i];
            }
            else if (bit & 1<<i) {
                cur_cost += max_h + 1 - b[i];
                b[i] = max_h + 1;
                colors++;
                max_h = b[i];
            }
        }
        if (colors >= K) min_cost = min(min_cost, cur_cost);
    }
    PRINT(min_cost);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();//行
      	int w = sc.nextInt();//列
      	int k = sc.nextInt();//条件
      	int count_Bl=0;//黒の数
      	int result=0;//合致するパターン数
      	int[][] board =new int[h][w];
      

      
          
    	for(int i=0;i<h;i++){
          String input=sc.next();
          for(int j=0;j<w;j++){
            if(input.charAt(j)=='#'){
           		board[i][j] = 1;//要素の打ち込み 
            }else{
            	board[i][j] = 0;//要素の打ち込み
            }
            
          }
        }  
      
      	/*for(int i=0;i<h;i++){//打ち込みがうまくいってるかの確認用
          for(int j=0;j<w;j++){
            System.out.print(board[i][j]);
          }
        }*/  
		
      
      	for(int i=0;i<Math.pow(2,h);i++){//塗りつぶしを2進数で表現
          String paH=String.format("%6s",Integer.toBinaryString(i));
          //System.out.println(paH);//二進数への変換の確認用
          for(int j=0;j<Math.pow(2,w);j++){
            String paW=String.format("%6s",Integer.toBinaryString(j));
            
            for(int n=0;n<h;n++){
              for(int m=0;m<w;m++){
                if(paH.charAt(6-h+n)!='1' && paW.charAt(6-w+m)!='1'){
                  if(board[n][m]==1){
                    count_Bl+=1;
                  }
                }
              }   
            }
           
         	if(count_Bl==k){
              result+=1;
              //System.out.println(paH+paW+"!");//何が条件をクリアしたかの確認
          	}
            count_Bl=0;//カウントのリセット
          } 
        }
          
    	System.out.println(result);
    } 
}

















Measured memory_bytes: 46332
#include <iostream>

int day_count(int month, int day) {
    int per_month[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};    
    int total = 0;
    for (int i = 0; i < month - 1; i++) {
        total += per_month[i];
    }
    return total + day;
}

void day_check(int month, int day) {
    int count = day_count(month, day);
    count %= 7;
    std::string day_array[] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};
    std::cout << day_array[count] << std::endl;
    return; 
}

int main(void) {
    int month;
    int day;
    while (1) {
        std::cin >> month >> day;
        if (month == 0) {
            return 0;;
        }
        day_check(month, day);
    }
    return 0;
}

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

int main() {
	int a[40] = {}, p, s, ju = 1, aaa;
	char knm;
	while (cin >> p >> knm >> s) {
		if (p == 0) { break; }
		a[p] = s;
	}
	for (int i = 30; i > -1; i--) {
		aaa = 0;
		for (int j = 0; j < 40;j++){
			if(a[j] == i){
				a[j] = (-1) * ju;
				aaa++;
			}
		}
		if (aaa > 0) { ju++; }
	}
	while (cin >> p){
		cout << a[p] * (-1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,m,i;
  cin>>h>>w>>m;
  vector<vector<int>> b(m,vector<int>(2));
  map<int,int> x,y;
  for(i=0;i<m;i++){
    cin>>b.at(i).at(0)>>b.at(i).at(1);
    if(x.count(b.at(i).at(0))) x.at(b.at(i).at(0))++;
    else x[b.at(i).at(0)]=1;
    if(y.count(b.at(i).at(1))) y.at(b.at(i).at(1))++;
    else y[b.at(i).at(1)]=1;
  }
  int mx=0,my=0;
  set<int> sx,sy;
  for(auto z:x) mx=max(mx,z.second);
  for(auto z:x) if(z.second==mx) sx.insert(z.first);
  for(auto z:y) my=max(my,z.second);
  for(auto z:y) if(z.second==my) sy.insert(z.first);
  int cnt=0;
  for(i=0;i<m;i++) if(sx.count(b.at(i).at(0))&&sy.count(b.at(i).at(1))) cnt++;
  if(cnt<sx.size()*sy.size()) cout<<mx+my<<endl;
  else cout<<mx+my-1<<endl;
}

Measured memory_bytes: 75788
import collections
def main():

    N = int(input())
    city = []
    for i in range(N):
        x, y = map(int, input().split())
        city.append([x, y, i])

    edges = []
    city.sort(key = lambda x: x[0])
    for i in range(N-1):
        edges.append([city[i][2], city[i+1][2], abs(city[i][0]-city[i+1][0])])
    city.sort(key = lambda x: x[1])
    for i in range(N-1):
        edges.append([city[i][2], city[i+1][2], abs(city[i][1]-city[i+1][1])])
    edges.sort(key = lambda x: x[2])

    parent = [a for a in range(N)]
    def find(a):
        if parent[a] != a:
            parent[a] = find(parent[a])
        return parent[a]
    def union(a, b, c):
        pa, pb = find(a), find(b)
        if pa != pb:
            parent[pb] = pa
            return c, 1
        else:
            return 0, 0

    cost = 0
    connected = N
    for a, b, c in edges:
        cst, cmp = union(a, b, c)
        cost += cst
        connected -= cmp
        if connected == 1:
            return cost



if __name__ == '__main__':
    print(main())

Measured memory_bytes: 53928
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define rep2(i,a,n) for (int i = a; i < n; i++)
using namespace std;
int S, W;
int main() {
    cin >> S >> W;
    if(W >= S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3672
#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()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, a, b;
	string s;
	cin >> n >> a >> b >> s;
	int total = a + b;
	rep(i, n)
	{
		if (s.at(i) == 'a')
		{
			if (total)
			{
				cout << "Yes" << endl;
				total--;
			}
			else
				cout << "No" << endl;
		}
		else if (s.at(i) == 'b')
		{
			if (total && b)
			{
				cout << "Yes" << endl;
				total--;
				b--;
			}
			else
				cout << "No" << endl;
		}
		else
			cout << "No" << endl;
	}
}


Measured memory_bytes: 848
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int i,c=0,f=0;
	char a[100];
	scanf("%s",a);
	for(i=0;i<strlen(a);i++)
	{
		if(a[i]=='C')
		{
			c=1;
		}
		if(a[i]=='F'&&c==1)
		{
			printf("Yes");
			f=1;
			break;
		}
	}
	if(c!=1||f!=1)
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int m = saori.saori_hayami();
		char[][] a = new char[n][n];
		char[][] b = new char[m][m];
		boolean ans = false;
		for(int i = 0;i < n;i++){
			String str = saori.nextHayami();
			for(int j = 0;j < n;j++){
				a[i][j] = str.charAt(j);
			}
		} 
		for(int i = 0;i < m;i++){
			String str = saori.nextHayami();
			for(int j = 0;j < m;j++){
				b[i][j] = str.charAt(j);
			}
		}
		boolean flg = true;
		for(int i = 0;i <= n-m;i++){
			for(int j = 0;j <= n-m;j++){
				flg = true;
				for(int x = 0;x < m;x++){
					for(int y = 0;y < m;y++){
						if(a[i+x][j+y] != b[x][y]){
							flg = false;
						}
					}
				}
				if(flg)ans = true;
			}
		}
		if(ans){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
costs = [2, 5, 5, 4, 5, 6, 3, 7, 6]
cs = {m: costs[m - 1] for m in a}
INF = 10 ** 9
dp = [0]

for i in range(1, n + 1):
    dp.append(max(
        [dp[i - c] if i - c >= 0 else -INF for c in cs.values()]
    ) + 1)

digits = list(cs.keys())
digits.sort(reverse=True)
num = n
ans = []
for _ in range(dp[n]):
    for digit in digits:
        if num >= cs[digit] and dp[num - cs[digit]] != -INF and dp[num - cs[digit]] == dp[num] - 1:
            ans.append(str(digit))
            num -= cs[digit]
            break
print("".join(ans))


Measured memory_bytes: 43740
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// B刀がA刀より小さくなるまで投げる
	// その後A刀の最大を振り続ける
	int n, h; cin >> n >> h;
	vector<int>a(n), b(n);
	rep(i, n)cin >> a[i] >> b[i];
	sort(a.rbegin(), a.rend()); sort(ALLR(b));
	int ans = 0;
	int now = 0;
	int ma = a[0];
	rep(i, n) {
		if (b[i] == -1)break;
		if (b[i] >= ma) {
			ans++;
			now += b[i];
			b[i] = -1;
		}
		else {
			break;
		}
		if (now >= h) {
			cout << ans << endl; return 0;
		}
	}
	if (now >= h) {
		cout << ans << endl; return 0;
	}
	h -= now;
	cout << ans + (h + ma - 1) / ma << endl;
	return 0;
}

Measured memory_bytes: 1792
// Written by newbiechd
#include <cstring>
#include <iostream>
#include <string>

const int maxN = 13;
int n;
char col[maxN][maxN];
bool vis[26];
void dfs(int x, int y, char c) {
  if (x > n) {
    int val = 0;
    memset(vis, 0, sizeof(vis));
    for (int j = 1; j <= n; ++j) vis[col[1][j] - 'a'] = 1;
    for (char t = 'a'; t <= c; ++t) val += vis[t - 'a'];
    if (val != 3)
      return ;
    for (int i = 2; i <= n; ++i) {
      memset(vis, 0, sizeof(vis));
      int tmp = 0;
      for (int j = 1; j <= n; ++j) vis[col[i][j] - 'a'] = 1;
      for (char t = 'a'; t <= c; ++t) tmp += vis[t - 'a'];
      if (tmp != val)
        return ;
    }
    for (int j = 1; j <= n; ++j) {
      memset(vis, 0, sizeof(vis));
      int tmp = 0;
      for (int i = 1; i <= n; ++i) vis[col[i][j] - 'a'] = 1;
      for (char t = 'a'; t <= c; ++t) tmp += vis[t - 'a'];
      if (tmp != val)
        return ;
    }
    for (int i = 1; i <= n; ++i)
      printf("%s\n", col[i] + 1);
    putchar('\n'), fflush(stdout);
    return ;
  }
  if (y > n) {
    dfs(x + 1, 1, c);
    return ;
  }
  if (col[x][y - 1] == '.') {
    col[x][y] = col[x][y - 1] = c;
    dfs(x, y + 1, c + 1);
    col[x][y] = col[x][y - 1] = '.';
  }
  if (col[x - 1][y] == '.') {
    col[x][y] = col[x - 1][y] = c;
    dfs(x, y + 1, c + 1);
    col[x][y] = col[x - 1][y] = '.';
  }
  dfs(x, y + 1, c);
}

const std::string ans[][7] = {
  {
    "aabc",
    "ddbc",
    "efgg",
    "efhh"
  },
  {
    "aabbd",
    "ccf.d",
    "eefgg",
    "..hij",
    "..hij"
  },
  {
    "aabbcc",
    "ddeeff",
    "ghi...",
    "ghi...",
    "...jkl",
    "...jkl"
  },
  {
    "aabbcc.",
    "ddee..h",
    "ffgg..h",
    "....ijk",
    "....ijk",
    "....lmn",
    "....lmn"
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  /*
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      col[i][j] = '.';
  dfs(1, 1, 'a');
  */
  
  if (n < 3) {
    printf("-1\n");
    return 0;
  }
  if (n == 3) {
    std::cout << "aa.\n..a\n..a\n";
    return 0;
  }

  int k = (n & 3) + 4;
  for (int i = 0; i < n - k; ++i) {
    std::string str(n, '.');
    str.replace(i / 4 * 4, 4, ans[0][i % 4]);
    std::cout << str << '\n';
  }
  for (int i = n - k; i < n; ++i) {
    std::string str(n, '.');
    str.replace(n - k, k, ans[k - 4][i + k - n]);
    std::cout << str << '\n';
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9 + 9;

int n, p[200000];

struct RMQ {
	int n;
	vector<pair<int, int>> t;
	RMQ(int _n) {
		n = _n;
		t.resize(2 * n, {INF, INF});
	}
	void upd(int v, int a, int b) {
		t[v += n] = {a, b};
		for(v >>= 1; v; v >>= 1)
			t[v] = min(t[v * 2], t[v * 2 + 1]);
	}
	pair<int, int> get(int l, int r) {
		pair<int, int> res = {INF, INF};
		for(l += n, r += n; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
			if(l & 1) res = min(res, t[l]);
			if(!(r & 1)) res = min(res, t[r]);
		}
		return res;
	}
};

RMQ odd(200000), even(200000);

struct seg {
	int l, r;
	int f;
	bool operator < (const seg &x) const {
		return f < x.f;
	}
};

set<seg> setik;

inline void ins(int l, int r) {
	if(l % 2 == 0) setik.insert({l, r, even.get(l, r).first});
	else setik.insert({l, r, odd.get(l, r).first});
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> p[i];
		if(i % 2 == 0) even.upd(i, p[i], i);
		else odd.upd(i, p[i], i);
	}
	setik.insert({0, n - 1, even.get(0, n - 1).first});
	for(int i = 0; i < n / 2; i++) {
		seg cur = *setik.begin();
		setik.erase(setik.begin());
		pair<int, int> f, s;
		if(cur.l % 2 == 0) {
			f = even.get(cur.l, cur.r);
			s = odd.get(f.second + 1, cur.r);
		} else {
			f = odd.get(cur.l, cur.r);
			s = even.get(f.second + 1, cur.r);
		}
		cout << f.first << ' ' << s.first << ' ';
		if(f.second != cur.l) ins(cur.l, f.second - 1);
		if(f.second + 1 != s.second) ins(f.second + 1, s.second - 1);
		if(s.second != cur.r) ins(s.second + 1, cur.r);
	}
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

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

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	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;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
 ios::sync_with_stdio(false);


ll n;
cin>>n;
ll a[n+1];
rep(i,n){
	cin>>a[i];
}

int num[1000005];
rep(i,1000000){
	num[i]=0;
}

rep(i,n){
num[a[i]]++;
}

ll ans=0;
rep(j,n){
	int imp=0;
ll now=a[j];
vector<ll> vec{};
for(ll i=1;i*i<=a[j];i++){
	if(a[j]%i==0){vec.push_back(i); vec.push_back(a[j]/i);}
}
for(int i=0;i<vec.size();i++){
	
if(num[vec[i]]){
	if(vec[i]==a[j]&&num[vec[i]]==1){continue;}
	imp=1;
	break;}
}
if(imp)continue;
ans++;

}

cout<<ans<<endl;



return 0;
}


	

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LI h,w,i,j;cin>>h>>w;
      char a[h][w];
      LI dp[h][w];
      fo(i,0,h) fo(j,0,w) cin>>a[i][j];
      dp[h-1][w-1]=1;
      rfo(i,h-1,-1){
        rfo(j,w-1,-1){
          if(i==h-1&&j==w-1) continue;
          dp[i][j]=0;
          if(a[i][j]=='.'){
            if(i<h-1) dp[i][j]+=dp[i+1][j];
            dp[i][j]%=MOD;
            if(j<w-1) dp[i][j]+=dp[i][j+1];
            dp[i][j]%=MOD;
          }
        }
      }
      cout<<dp[0][0];
    }
    return 0;
}

Measured memory_bytes: 9088
N = int(input())
a = list(map(int, input().split()))

imos = [0] * (10 ** 5 + 10)

for i in range(N):
    l, r, s = a[i] - 1, a[i] + 1, 1
    l += 1
    r += 1
    # print(l, r)
    imos[l] += s
    imos[r + 1] -= s

for i in range(N + 1):
    imos[i + 1] = imos[i] + imos[i + 1]

# print(imos[: max(a) + 3])

print(max(imos[: max(a) + 3]))


Measured memory_bytes: 13964
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//struct Main {}
//impl Main {
//    fn invoke() {}
//}

fn main() {
    let k: i32 = read();
    let n: usize = read();
    let mut a: Vec<i32> = vec![0; n];
    for i in 0..n {
        a[i] = read();
    }
    let mut d = 0;
    for i in 1..n {
        let diff: i32 = a[i] - a[i-1];
//        println!("{}", diff);
        d += diff;
    }
//    println!("{}", d);

    let mut min_d = d.clone();
    let mut new_d = d.clone();
    for i in 0..n-1 {
        let add_diff = if i == 0 {
            let x = a[n-1] - a[i];
            let y = k - a[n-1] + a[i];
            if x < y {
                x
            } else {
                y
            }
        } else {
            a[i] - a[i-1]
        };
        let remove_diff = a[i + 1] - a[i];
//        println!("add_diff {}", add_diff);
//        println!("remove_diff {}", remove_diff);
        new_d += add_diff;
        new_d -= remove_diff;
//        println!("{}", new_d);
        if new_d < min_d {
            min_d = new_d;
        }
    }
    println!("{}", min_d);
}


Measured memory_bytes: 4476
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int N, res;
	cin >> N;
	vector<ll> A;
	res = 0;
	for (int i = 0; i < N; i++) {
		ll Ai;
		cin >> Ai;
		A.push_back(Ai);
	}
	sort(A.begin(), A.end());
	int i = 0;
	while (i < N) {
		ll cc = A[i];
		ll f = 0;
		while (i < N && A[i] == cc) f++, i++;
		res += f % 2;
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;
ll d[200][200];
ll e[200][200];
int main(){
    int n,m;
    while(cin>>n>>m && n){
        rep(i,200)rep(j,200)d[i][j]=1LL<<60;
        rep(i,200)d[i][i]=0;
        rep(i,200)rep(j,200)e[i][j]=1LL<<60;
        rep(i,200)e[i][i]=0;
        rep(i,n){
            ll a,b,c,c2;
            cin>>a>>b>>c>>c2;
            //printf("%lld %lld %lld %lld\n",a,b,c,c2);
            d[a][b]=d[b][a]=c;
            e[a][b]=e[b][a]=c2;
        }
        rep(k,200)rep(i,200)rep(j,200)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        rep(k,200)rep(i,200)rep(j,200)e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
        int k;cin>>k;
        rep(i,k){
            int p,q,r;
            cin>>p>>q>>r;
            auto t = r?e:d;
            cout << t[p][q] << endl;
        }
    }
}

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

int main()
{
    int a, b, c, n;

    cin >> a >> b >>c;

    if(a > b) {n = a; a = b; b = n;}
    if(b > c) {n = b; b = c; c = n;}
    if(a > b) {n = a; a = b; b = n;} 

    cout << a << ' ' << b << ' ' << c << endl; 

    return 0;           
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
void solve(void)
{
    string s;
    cin >> s;
    cout << (count(all(s), 'o') + 7) * 100 << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector <long long> v;
    int n;
    cin>>n;
    for (int i=0;i<n;i++)
    {
        v.push_back(0);
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int desde=0;
    long long sum=v[desde];
    for (int i=1;i<n;i++)
    {
        if (sum*2>=v[i])
        {
            sum+=v[i];
        }else
        {
            desde=i;
            sum+=v[i];
        }
    }
    cout<<v.size()-desde<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<cstring>
using namespace std;
int ans,len;
char st[100010];
int main()
{
	scanf("%s",st+1);
	len=strlen(st+1);
	for (int i=1;i<=len;i++)
	{
		if (i%2==1&&st[i]=='p')
			ans--;
		if (i%2==0&&st[i]=='g')
			ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import sys
import fractions


def lcm(a, b):
    return a * b // fractions.gcd(a, b)


def input():
    return sys.stdin.readline().strip()


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

a_lcm = a[0]
for ai in a:
    a_lcm = lcm(ai, a_lcm)

m = a_lcm - 1
ans = 0

for ai in a:
    ans += m%ai

print(ans)


Measured memory_bytes: 5340
import java.util.*;
public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
  	int N = sc.nextInt();
 	int cnt = 0;	

  	for (int i=N;i>0;i--){
      if(((0<i)&&(i<10))
         ||((99<i)&&(i<1000))
         ||((9999<i)&&(i<100000))){
         cnt++;
      }
    }
 
  	System.out.println(cnt);
  
	}
}

Measured memory_bytes: 21844