akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:       
            s += self.tree[i] 
            i -= i & -i       
        return s                            
                                            
    def add(self, i, x):                  
        while i <= self.size:
            self.tree[i] += x  
            i += i & -i
x = "abcdefghijklmnopqrstuvwxyz"
N, = map(int, input().split())
d = dict()
for c in x:
    d[c] = Bit(N+1)

S = list(input().strip())
for i, c in enumerate(S):
    d[c].add(i+1, 1)

Q = int(input())
for _ in range(Q):
    t, a, b = input().split()
    if t == '1':
        i, c = int(a), b
        b = S[i-1]
        S[i-1] = c
        d[b].add(i, -1)
        d[c].add(i, 1)
    else:
        l, r = int(a), int(b)
        rr = 0
        for c in x:
            if d[c].sum(r) - d[c].sum(l-1) > 0:
                rr += 1
        print(rr)


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

int Balls[10];


bool not_dfs(int balls[]){
  int b = 0, c = 0;
  for (int i = 0; i < 10; i++) {
    if (b < balls[i]){b = balls[i]; continue;}
    if (c < balls[i]){c = balls[i]; continue;}
    return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> Balls[j];
    }
    if(not_dfs(Balls)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3068
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, x: "List[int]", y: "List[int]"):
    tmp = []
    for i in range(N):
        tmp.append([i, x[i], y[i]])
    tmp.sort(key=lambda x: x[1])
    dis = []
    for i in range(N - 1):
        dis.append([abs(tmp[i + 1][1] - tmp[i][1]), tmp[i][0], tmp[i + 1][0]])

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

    par = list(range(N))
    def find_root(x):
        if par[x] != x:
            par[x] = find_root(par[x])
        return par[x]
    def union(a, b):
        a_root = find_root(a)
        b_root = find_root(b)
        par[a_root] = b_root
        return

    dis.sort(key=lambda x: x[0])
    ret = 0
    for d in dis:
        a = d[1]
        b = d[2]
        if find_root(a) != find_root(b):
            ret += d[0]
            union(a, b)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 156688
import java.util.Scanner;

public class Main {
  public enum Turn {
      A, B, C;
  }
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String Sa = scanner.nextLine().toUpperCase();
    String Sb = scanner.nextLine().toUpperCase();
    String Sc = scanner.nextLine().toUpperCase();
    
    Turn turn = Turn.A;
    
loop:
    while(true) {
        String nextTurn;
        switch(turn) {
            case A:
               if(Sa.length() == 0) break loop;
               nextTurn = Sa.substring(0, 1);
               Sa = Sa.substring(1);
               break;
            case B:
               if(Sb.length() == 0) break loop;
               nextTurn = Sb.substring(0, 1);
               Sb = Sb.substring(1);
               break;
            case C:
               if(Sc.length() == 0) break loop;
               nextTurn = Sc.substring(0, 1);
               Sc = Sc.substring(1);
               break;
            default:
                throw new RuntimeException();
        }
        turn = Turn.valueOf(nextTurn);
    }
    
    System.out.println(turn.toString());
  }
}

Measured memory_bytes: 9556
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N, K, Q;
  cin >> N >> K >> Q;
  vector <int> point(N, K - Q);
  rep(i,Q){
    int a;
    cin >> a;
    a --;  //0-indexedに直す
    point[a] ++;
  }
  rep(i,N){
    if (point[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3756
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    long long N, x;
    cin >> N >> x;

    vector<long long> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    long long ans = 0;
    if (a[0] >= x) {
        ans += a[0] - x;
        a[0] = x;
    }

    for (int i = 1; i < N; i++) {
        if (a[i - 1] + a[i] >= x) {
            long long sum = a[i - 1] + a[i];
            ans += sum - x;
            a[i] -= sum - x;
        }
    }

    cout << ans << endl;

    return 0;
}











































































Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
#define MAXN 55
#define oo ((ll)(1e18))

vector<pip> g[MAXN];
ll d[MAXN][MAXN*MAXN],ci[MAXN],di[MAXN],res[MAXN];
bool mk[MAXN][MAXN*MAXN];

void dijkstra(ll start,ll s)
{
    for(int i=0;i<MAXN;i++)
    {
        res[i]=oo;
        for(int j=0;j<MAXN*MAXN;j++)
            d[i][j]=oo;
    }
    s=min(s,MAXN*MAXN-1ll);
    d[start][s]=0;
    priority_queue<pip,vector<pip>,greater<pip> > pq;
    pq.push(pip(0,pii(start,s)));
    while(!pq.empty())
    {
        ll w0=pq.top().first;
        ll u=pq.top().second.first;
        ll silver=pq.top().second.second;
        pq.pop();

        if(mk[u][silver])
            continue;
        mk[u][silver]=1;
        res[u]=min(res[u],w0);
        d[u][silver]=w0;
        ll ss=silver;
        while(silver!=MAXN*MAXN-1)
        {
            silver=min(silver+ci[u],MAXN*MAXN-1ll);
            w0+=di[u];
            if(w0<d[u][silver])
            {
                d[u][silver]=w0;
                pq.push(pip(w0,pii(u,silver)));
            }
            else
                break;
        }

        silver=ss;
        for(auto y : g[u])
        {
            ll v=y.first;
            ll a=y.second.first;
            ll b=y.second.second;
            if(silver>=a && !mk[v][silver-a] && d[v][silver-a]>d[u][silver]+b)
            {
                d[v][silver-a]=d[u][silver]+b;
                pq.push(pip(d[u][silver]+b,pii(v,silver-a)));
            }
        }
    }
}

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

    ll n,m,s,u,v,a,b;
    cin >> n >> m >> s;
    for(int i=0;i<m;i++)
    {
        cin >> u >> v >> a >> b;
        u--,v--;
        g[u].push_back(pip(v,pii(a,b)));
        g[v].push_back(pip(u,pii(a,b)));
    }

    for(int i=0;i<n;i++)
        cin >> ci[i] >> di[i];

    dijkstra(0,s);

    for(int i=1;i<n;i++)
        db(res[i])

    return 0;
}
/**
3 2 1
1 2 1 2
1 3 2 4
1 11
1 2
2 5

6 5 1
1 2 1 1
1 3 2 1
2 4 5 1
3 5 11 1
1 6 50 1
1 10000
1 3000
1 700
1 100
1 1
100 1

4 6 10000000
1 2 50 1
1 3 50 5
1 4 50 7
2 3 50 2
2 4 50 4
3 4 50 3
10 2
4 4
5 5
7 7
**/


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

int main()
{
    int x, y;
    
    while (1) {
        cin >> x >> y;
        if (x == 0 && y == 0)
            break;
        else if (x > y)
            cout << y << ' ' << x << endl;
        else
            cout << x << ' ' << y << endl;
    }
}


Measured memory_bytes: 3060
#include <cstdio>
using namespace std;
int a,b,c;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	if (a==b){
		if (c!=a){
			puts("Yes");
		}
		else{
			puts("No");
		}
	}
	else if (a==c){
		if (b!=a){
			puts("Yes");
		}
		else{
			puts("No");
		}
	}
	else if (b==c){
		if (a!=b){
			puts("Yes");
		}
		else{
			puts("No");
		}
	}
	else{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e9;

int main(){
    ll N,M;
    cin >> N;
    ll a;
    map<ll,ll> mp;
    for(ll i=0;i<N;i++){
        cin >> a;
        mp[a]++;
    }
    cin >> M;
    for(ll i=0;i<M;i++){
        cin >> a;
        if(mp[a]){
            mp[a]--;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <vector>

int main()
{
        int N, M, X, Y;
        std::vector<int> x, y;
        std::cin >> N >> M >> X >> Y;
        x.resize(N+1);
        for (int i = 0; i < N; ++i)
                std::cin >> x[i];
        x[N] = X;
        y.resize(M+1);
        for (int i = 0; i < M; ++i)
                std::cin >> y[i];
        y[M] = Y;
        std::sort(x.begin(), x.end());
        std::sort(y.begin(), y.end());

        if (x[N] < y[0])
                std::cout << "No War\n";
        else
                std::cout << "War\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  map<int,int>k;
  for(int i=2;i<=N;i++){
    int cur=i;
    for(int j=2;j*j<=cur;j++){
      while(cur%j==0){k[j]++;cur/=j;}
    }
    if(cur!=1){k[cur]++;}
  }
  map<int,int>num;
  for(int i=1;i<=75;i++){
    for(auto c:k){
      if(c.second>=i-1){num[i]++;}
    }
  }
  cout<<num[75]+num[25]*(num[3]-1)+(num[5]-1)*num[15]+num[5]*(num[5]-1)*(num[3]-2)/2<<endl;
  return 0;  //かぶる部分をなくすために-1。num[5]が二つで数なので/2
}

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

#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long

using namespace std;

const int N = 1e6 + 7;
const int mod = 1e9 + 7;

void solve()
{
    ll n,a,b;
    cin >> n >> a >> b;
    if( (b - a) % 2 == 0 )cout << (b - a) / 2;
    else{
        ll bb = n - b + 1;
        ll z = a + n - b + 1;
        ll f = n;
        ll ans = min({ b - 1 , n - a , bb + (f - z) / 2 });
        bb = a;
        f = 1;
        z = b - a;
        ans = min( ans , bb + (z - f) / 2 );
        cout << ans;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );
    //freopen( "cardgame.in" , "r" , stdin );
    //freopen( "cardgame.out" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n,m;
    cin>>n>>m;
    int num[10]={1000,2,5,5,4,5,6,3,7,6};
    vector<pair<int,int>> v;
    rep(i,m){
        int tmp;
        cin>>tmp;
        v.push_back(make_pair(tmp,num[tmp]));
    }
    sort(ALL(v));
    //dp[マッチの本数]=何桁いけるか
    vector<ll> dp(1000000,-LINF);
    dp[0]=0ll;
    int k=0;
    //配るDP
    while(k<n){
        if(dp[k]>=0){
            for(int i=0;i<v.size();i++){
                if(dp[k+v[i].second]<=dp[k]+1){
                    dp[k+v[i].second]=dp[k]+1;
                }
            }
        }
        k++;
    }
    cout<<endl;
    int kk=n;
    string ans="";
    while(kk>0){
        for(int i=v.size()-1;i>=0;i--){
            if(kk-v[i].second<0) continue;
            if(dp[kk-v[i].second]==dp[kk]-1){
                ans+=to_string(v[i].first);
                kk-=v[i].second;
                break;
            }
        }
    }
    sort(ALL(ans));
    reverse(ALL(ans));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8064
#include <iostream> 
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
using namespace std;

int main()
{
	int n,c,k,ans=0,i,tmp;
	int num[100000];
	scanf("%d%d%d",&n,&c,&k);
	for(i=0;i<n;i++) scanf("%d",&num[i]);
	sort(num,num+n);
	i=0;
	while(i<n)
	{
		//printf("%d ",i);
		tmp=i;
		while(tmp<n && tmp-i<c && num[tmp]-num[i]<=k) tmp++;
		ans++,i=tmp; 
		//printf("%d\n",i);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
       if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
    int f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
inline ll readll() {
    ll f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
void fl(string name){
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
          dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
#define MAXN 500010
ll a[MAXN],tree[MAXN],f[MAXN],n,q,ans[MAXN];
struct node{
    ll l,r,id;
}x[MAXN];
bool cmp1(node a,node b){
    return a.r<b.r;
}
void add(ll x,ll num){
    while(x<=n){
        tree[x]+=num;
        x+=lowbit(x);
    }
}
ll sum(ll x){
    ll ans=0;
    while(x>0){
        ans+=tree[x];
        x-=lowbit(x);
    }
    return ans;
}
int main(){
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=q;i++){
        cin>>x[i].l>>x[i].r;
        x[i].id=i;
    }
    sort(x+1,x+q+1,cmp1);
    ll pre=1;
    for(int i=1;i<=q;i++){
        for(int j=pre;j<=x[i].r;j++){
            if(f[a[j]])add(f[a[j]],-1);
            add(j,1);
            f[a[j]]=j;
        }
        pre=x[i].r+1;
        ans[x[i].id]=sum(x[i].r)-sum(x[i].l-1);
    }
    for(int i=1;i<=q;i++)cout<<ans[i]<<endl;
    return 0;
}
/* stuff to remember
    * int overflow, array bounds
    * special cases (n=1? n=0?)
    * do something instead of nothing and stay organized
    * USE STATIC ARRAYS
    * DEFINING ARRAYS BEFORE main()
    * DO NOT DEFINE ARRAYS IN main()
    * USE INT INSTEAD OF LL,NOTICE THE MLE
*/

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

int main() {
	string S;
    cin >> S;
    if (S=="SUN") {
    	cout << 7 << endl;
    }
    else if (S=="MON") {
    	cout << 6 << endl;
    }
    else if (S=="TUE") {
    	cout << 5 << endl;
    }
    else if (S=="WED") {
    	cout << 4 << endl;
    }
    else if (S=="THU") {
    	cout << 3 << endl;
    }
    else if (S=="FRI") {
    	cout << 2 << endl;
    }
    else {
    	cout << 1 << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  if (a + b == c) {
    puts("Yes");
  } else if (b + c == a) {
    puts("Yes");
  } else if (c + a == b) {
    puts("Yes");
  } else {
    puts("No");
  }
}

Measured memory_bytes: 128
n,m=map(int,input().split())
a=[0]*m
b=[list(map(int,input().split())) for _ in range(n) ]
      
for i in range(n):
  c=b[i][0]
  for j in range(1,c+1):
    a[b[i][j]-1]+=1

print(a.count(n))

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    double a, b;
    while(cin >> a >> b) {
        if(a < 35.5 && b < 71) puts("AAA");
        else if(a < 37.5 && b < 77) puts("AA");
        else if(a < 40 && b < 83) puts("A");
        else if(a < 43 && b < 89) puts("B");
        else if(a < 50 && b < 105) puts("C");
        else if(a < 55 && b < 116) puts("D");
        else if(a < 70 && b < 148) puts("E");
        else puts("NA");
    }
    return 0;
}


Measured memory_bytes: 3052
import java.util.*;
import java.io.*;
  
class Main{
    public static void main(String args[])throws IOException{
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       String s;
       while((s=br.readLine())!=null){
           String[] str = s.split(" ");
           int n = Integer.parseInt(str[0]);
           int x = Integer.parseInt(str[1]);
           if(n==0 && x==0) break;
           int count=0;
           for(int i=1; i<n; ++i){
               for(int j=i; j<n; ++j){
                   if(i==j) continue;
                   int num = x - (i+j);
                   if(num<1) break;
                   if(num<j) break;
                   if(i != num && j != num && num <= n) count++;
                   num = 0;
               }
           }     
       System.out.println(count);
       }
    }
}

Measured memory_bytes: 24204
//#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n;
  cin>>n;
  vector<pair<ll,ll>> active_pos;
  for (ll i = 0; i < n; ++i)
  {
    ll tmp;
    cin>>tmp;
    active_pos.push_back(make_pair(tmp,i));
  }
  sort(active_pos.begin(), active_pos.end());
  reverse(active_pos.begin(), active_pos.end());
  ll ans=0;
  vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
  for (ll l = 0; l < n; ++l)
  {
    for (int r = 0; r < n; ++r)
    {
      if(l+r==n)
      {
        ans=max(ans,dp[l][r]);
        break;
      }
      ll activeness=active_pos[l+r].first;
      ll pos=active_pos[l+r].second;
      dp[l+1][r]=max(dp[l][r]+abs(l-pos)*activeness,dp[l+1][r]);
      dp[l][r+1]=max(dp[l][r]+abs(n-r-1-pos)*activeness,dp[l][r+1]);
    }
  }
  cout<<ans<<endl;

}

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

int main(){
    int n;
    cin>>n;
    
    map<int,int> a;
    int c;
    rep(i,n){
        cin>>c;
        a[c]++;
    }
    
    int amax = a.rbegin()->first;
    
    vector<bool> sieve(amax+1,0);
    
    if(a.count(1)){
        if(a[1]==1)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return 0;
    }
    
    int ans = 0;
    
    for(auto p: a){
        int x = p.first;
        if(sieve[x])continue;
        int count = p.second;
        if(count==1)ans++;
        
        sieve[x] = 1;
        for(int i=2*x; i<=amax; i += x){
            sieve[i] = 1;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 13032
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
char S[1007],T[1007];
int main(){
	scanf("%s%s",S+1,T+1);
	int x1=strlen(S+1),x2=strlen(T+1);
	int ans=inf;
	for(int i=1;i<=x1-x2+1;i++){
		int sum=0;
		for(int j=1;j<=x2;j++){
			if(S[i+j-1]!=T[j]) sum++;
		}
		ans=min(ans,sum);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 1736
import re

s = input()

s = s[::-1]

while s:
    if re.match("resare",s):
        s = s[6:]
    elif re.match("esare",s):
        s = s[5:]
    elif re.match("remaerd",s):
        s = s[7:]
    elif re.match("maerd",s):
        s = s[5:]
    else:
        break
    
if len(s) == 0:
    print("YES")
else:
    print("NO")

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define REREP(i,n) for(int i=int(n-1); i>=0; i--)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define REFOR(i,m,n) for(int i=int(n-1); i>=int(m); i--)
#define ALL(obj) (obj).begin(),(obj).end()
 
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>
 
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>
 
#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0LL)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

#define PB push_back
#define Cout(str) cout << str << endl

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const ll EPS = (ll)1e-8;

int main(){
	int n,m;
	int a,b,c,d;
	int sum;
	string str;
	string s,t;
	char ch;
	VI vi;
	vector<char> vc;
	VS vs;
	int reserve_vi = 100;
	map<int, int> table; 
	string str2, str3;
	map<char, string> vowel;
	vector<char> vowel_vec = {'a', 'e', 'i', 'o', 'u'};

	//cin >> n >> m;
	cin >> a >> b;
	//cin >> a >> b >> c;
	//cin >> a >> b >> c >> d;
	//cin >> str;
	//cin >> str >> str2 >> str3;
	//cin >> n;
	
	//cin >> s >> t;
	//cin >> ch;
	//cin >> a >> ch >> b;
	
	a += 11;
	b += 11;
	a %= 13;
	b %= 13;
	if(a < b) cout << "Bob" << endl;
	else if(a == b) cout << "Draw" << endl;
	else cout << "Alice" << endl;
	//cout << accumulate(vi.begin(), vi.begin()+n, 0) << endl;
	//replace(ALL(str), ',', ' ');

	//swap(a, b);
	//vi.resize(N);
	//fill(vi.begin(), vi.end(), 1);
	//vi.reserve(reserve_vi);
	//vi.PB(n);

	//vc.resize(5);
	//vc[i] = (str[i]);

	//sort(vc.begin(), vc.end(), greater<char>());
	//sort(vc.begin(), vc.end());

	//for(auto itr = table.begin(); itr != table.end(); ++itr) {
	return 0;
}



Measured memory_bytes: 256
/**Bismillahir Rahmanir Raheem
    Author:Refat(BSMRSTU)**/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const int M = 1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}
int main() {
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    ///scanf("%d",&test);
    for(int cs=1; cs<=test; cs++) {
        string s;
        cin>>s;
        for(int i=0;i<(int)s.length();i++){
            if(s[i]=='7'){
                printf("Yes\n");
                return 0;
            }
        }
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REV(c) reverse((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) {
    cout << c << endl;
  } else if (b == c) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main(){

  string s;
  cin >> s;
  rep(i, 4){
    if(s[i] == s[i + 1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;

}


Measured memory_bytes: 256
/*~~~~~~~~~~~~~~~~~ K++ code ~~~~~~~~~~~~~~~~~~~
in(n)
if(n==1) out("Hello World")
else {
    in(a, b)
    out(a+b)
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

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

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

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion

#pragma region GCD
int gcd(ll a, ll b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
int lcm(ll a, ll b)
{
	return (a*b) / gcd(a, b);
}
#pragma endregion

int main()
{
	int n; cin >> n;
	ll m; cin >> m;
	vector<ll> a(n); rep(i, n)cin >> a[i];
	ll tmp = a[0];
	int cnt = 0;
	while (tmp % 2 == 0)
	{
		++cnt;
		tmp /= 2;
	}
	rep(i, n)
	{
		tmp = a[i];
		int cnt2 = 0;
		while (tmp % 2 == 0)
		{
			++cnt2;
			tmp /= 2;
		}
		if (cnt != cnt2)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	tmp = a[0];
	rep(i, n)
	{
		tmp = lcm(tmp, a[i]);
		if (tmp / 2 > m)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (m + tmp / 2) / tmp << endl;
}

Measured memory_bytes: 1024
$mod=1_000_000_007
$m=10**5+1
$fact=Array.new($m+1)
$inv=Array.new($m+1)
def pow(x, n)
  ret = 1
  while n>0
    ret = ret*x%$mod if n.odd?
    x=x*x%$mod
    n>>=1
  end
  ret
end
def inverse(x)
  return $inv[x] if $inv[x]
  pow(fact(x),$mod-2)
end
def fact(n)
  $fact[n]
end
def init(n)
  (1..n).inject(1){|s,i|$fact[i]= s*i%$mod}
  $inv[n]=inverse(n)%$mod
  n.downto(1) do |i|
    $inv[i-1]=($inv[i]*(i))%$mod
  end
end

def comb(n, k)
  return 0 if k > n
  return 1 if k.zero? || k == n
  fact(n)*inverse(k)*inverse(n-k) % $mod
end
init($m)
io = STDIN
$n=io.gets.to_i
$a=io.gets.split.map(&:to_i)
#重複項をal  ar   (l<r)
# 1個     :al or ar
# k-1個   :al arで囲まれてない項から選ぶ
# al～arの範囲外の数：n-(r-l+1)
# n+1Ck - (n-(r-l+1))Ck-1
# 参照：https://www.slideshare.net/chokudai/abc021

dup=$a.sort.each_cons(2).select{|a,b|a==b}.flatten[0]
l,r=$a.index(dup),$a.rindex(dup)
(1..($n+1)).each do |k|
  puts (comb($n+1,k)-comb($n+1-(r-l+1),k-1)) % $mod
end

Measured memory_bytes: 13944
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
#print(T)
L=[[]for i in range(K)]
for i in range(N):
    L[i%K].append(T[i])
#print(L)
ans=0
for i in range(K):
    dp=[[0,0,0]for a in range(len(L[i])+1)]
    for x in range(1,len(dp)):
        dp[x][0]=max(dp[x-1][1],dp[x-1][2])
        dp[x][1]=max(dp[x-1][0],dp[x-1][2])
        dp[x][2]=max(dp[x-1][0],dp[x-1][1])
        if L[i][x-1]=="r":
            dp[x][2]+=P
        elif L[i][x-1]=="s":
            dp[x][0]+=R
        else:
            dp[x][1]+=S
    #print(dp)
    ans+=max(dp[-1])
print(ans)

Measured memory_bytes: 67724
using System;
using System.Collections.Generic;
using CompLib.Util;

public class Program
{
    private long N;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextLong();
        // K = N
        int ans = 0;
        for (long i = 1; i * i <= N; i++)
        {
            if (N % i == 0)
            {
                long j = N / i;
                if (F(N, i)) ans++;
                if (i != j && F(N, j)) ans++;
            }

            if ((N - 1) % i == 0)
            {
                long j = (N - 1) / i;
                if (F(N, i)) ans++;
                if (i != j && F(N, j)) ans++;
            }
        }

        Console.WriteLine(ans);
    }

    bool F(long n, long k)
    {
        if (k == 1) return false;
        if (n % k == 0) return F(n / k, k);
        return n % k == 1;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27212
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

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

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i, n) cin >> a[i];
    int f_cnt = 0;
    int t_cnt = 0;
    rep(i, n) {
        if(a[i] % 4 == 0) f_cnt += 1;
        else if(a[i]% 2 == 0) t_cnt += 1;
    }

    if(f_cnt >= n / 2) {
        cout << "Yes" << endl;
    } else {
        int d = n - (f_cnt * 2 + 1);
        //cout << d << " " << t_cnt << endl;
        if(t_cnt > d) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dis[11],arr[11][11];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
			scanf("%d",&arr[i][j]);
	for(int i=0;i<10;i++)
		dis[i]=INF;
	queue<int>q;dis[1]=0;
	q.push(1);		
	while(!q.empty()){
		int nd=q.front();
		q.pop();
		for(int i=0;i<10;i++)
			if(umin(dis[i],dis[nd]+arr[i][nd]))
				q.push(i);		
	}int ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++){
			int x;
			scanf("%d",&x);
			if(~x)	
				ans+=dis[x];
		}
	printf("%d\n",ans);	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pci pair<char, int>
#define pic pair<int, char>
#define plvl pair<long long, vector<long long> >
#define pcvc pair<char, vector<char> >


using namespace std;

const int mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	if(b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

template <typename T>
void show1(vector<T> dp) {
	for(auto d : dp) {
		cout << d << " ";
	}
	cout << "\n";
}

template <typename T>
void show2(vector<vector<T> > dp) {
	for(auto d : dp) {
		for(auto dd : d) {
			cout << dd << " ";
		}
		cout << "\n";
	}
}

void executeCode() {
	ll n;
	cin >> n;
	cout << ((n % 1000 != 0) ? (1000 - (n % 1000)) : 0) << "\n";
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int tt = 1;
	// cin >> tt;
	while(tt--) {
		executeCode();	
	}
	return 0;
}

Measured memory_bytes: 3652
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,M; cin>>N>>M;
  vector<vector<ll>> shimekiri(M,vector<ll>(0));
  rep(i,N){
    ll A,B; cin>>A>>B;
    if(M-A>=0) shimekiri[M-A].push_back(B);
  }
  
  map<ll,ll> mp;
  ll ans=0;
  for(int i=M-1;i>=0;i--){
    //cout<<1<<endl;
    for(auto b:shimekiri.at(i)) mp[b]++;
    //cout<<2<<endl;
    ll b=0;
    if(!mp.empty()) b=(*rbegin(mp)).first;
    //cout<<3<<endl;
    ans+=b;
    mp[b]--; if(mp[b]==0) mp.erase(b);
    //cout<<4<<endl;
  }
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 11644
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
using namespace std;

struct SCC{
    vector<vector<int> > g,rg;
    vector<int> vs,cmp,used;
    SCC(int v):g(v),rg(v),cmp(v,-1),used(v,0){}
    
    void add_edge(int src,int dst){
        g[src].pb(dst);
        rg[dst].pb(src);
    }
    void dfs(int v){
        used[v]=true;
        rep(i,g[v].size()){
            if(!used[g[v][i]]) dfs(g[v][i]);
        }
        vs.pb(v);
    }
    void rdfs(int v,int k){
        used[v]=true;
        cmp[v]=k;
        rep(i,rg[v].size()){
            if(!used[rg[v][i]]) rdfs(rg[v][i],k);
        }
    }
    int scc(){
        fill(used.begin(),used.end(),0);
        vs.clear();
        rep(i,used.size()){
            if(!used[i]) dfs(i);
        }
        fill(used.begin(),used.end(),0);
        int k=0;
        for(int i=vs.size()-1;i>=0;--i){
            if(!used[vs[i]]) rdfs(vs[i],k++);
        }
        return k;
    }
};

int main(){
    int v,e;
    cin>>v>>e;
    SCC scc(v);
    int s,t;
    rep(i,e){
        cin>>s>>t;
        scc.add_edge(s,t);
    }
    int k=scc.scc();
    vector<int> ans(v);
    if(v==k){
        rep(i,v) ans[scc.cmp[i]]=i;
        rep(i,v) cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4380
//Using FeatherPad
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#define problem_solving ios::sync_with_stdio(0);cin.tie(0);
#define oo (int)1e9 + 10
#define all(x) x.begin(), x.end()
using namespace std;

void solve(int case_number) {
	int n, m;
	cin >> n >> m;
	vector<int> ss(m);
	for(int i = 0; i < m; i++)
		cin >> ss[i];
	long long sum = 0;
	for(int i = 0; i < m; i++) {
		sum += ss[i];
		if(sum > n) {
			cout << -1 << endl;
			return;
		}
	}
	cout << n - sum  << endl;
}


int main() {
	problem_solving
	int cases = 1;
	//cin >> cases;
	for(int i=0;i<cases;i++)
		solve(i + 1);
	return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x[4][4],all;
int main()
{
	ios::sync_with_stdio(false);
	cin>>a>>b>>c;
	x[1][1]=a;
	x[1][2]=b;
	x[2][2]=c;
	all=3*x[2][2];
	x[3][3]=all-x[2][2]-x[1][1];
	x[1][3]=all-x[1][1]-x[1][2];
	x[2][3]=all-x[1][3]-x[3][3];
	x[2][1]=all-x[2][3]-x[2][2];
	x[3][1]=all-x[1][1]-x[2][1];
	x[3][2]=all-x[3][1]-x[3][3];
	cout<<x[1][1]<<" "<<x[1][2]<<" "<<x[1][3]<<" "<<endl;
	cout<<x[2][1]<<" "<<x[2][2]<<" "<<x[2][3]<<" "<<endl;
	cout<<x[3][1]<<" "<<x[3][2]<<" "<<x[3][3]<<" "<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N  =1010;

int n , m;
int a,b,c;
bool vis[N][N];
ll mem[N][N];
ll x[N],y[N],z[N];

ll dp(int i,int j){
if( j == m )return 0ll;
if( i == n )return -(1ll<<50);

if( vis[i][j] )return mem[i][j];
vis[i][j]=1;
mem[i][j]=dp(i+1,j);

if( j < m )
    mem[i][j]=max( mem[i][j] , dp(i+1,j+1)+a*x[i]+b*y[i]+c*z[i] );
return mem[i][j];
}

int main(){

scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)scanf("%lld %lld %lld",x+i,y+i,z+i);
ll ans =0;

for(a=-1;a<2;a+=2)
for(b=-1;b<2;b+=2)
for(c=-1;c<2;c+=2){
    memset(vis,0,sizeof vis);
    ans=max(ans,dp(0,0));
}
printf("%lld\n",ans);
return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int count=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        {
            count++;
        }
    }
    cout<<count<<endl;


    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {

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

	sort(a, a + 4);

	COUT((a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9 ? "YES" : "NO"));




	return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    c = 0
    for i in range(1, N-1):
        if A[i-1] < A[i] and A[i] < A[i+1] or A[i-1] > A[i] and A[i] > A[i+1]:
            c += 1
    return c

print(solve())

Measured memory_bytes: 3060
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
class dijkstra{
  constructor(n){
    this.graph = Array(n).fill().map(a=>[]);
  }
  add(u,v,cost){
    this.graph[u].push(v,cost);
  }
  add2(u,v,cost){
    this.graph[u].push(v,cost);
    this.graph[v].push(u,cost);
  }
  solve(start){
    const INF = 1e18;
    const g = this.graph;
    var pq = new priorityQueue();
    pq.push(0,start);
    var dp = Array(g.length).fill(INF);
    dp[start] = 0;
    while(pq.size){
      var [t,v] = pq.pop();
      if(dp[v] < t)continue;
      for(var i = 0; i < g[v].length; i+=2){
        var V = g[v][i], c = g[v][i+1] + t;
        if(dp[V] <= c)continue;
        dp[V] = c;
        pq.push(c,V);
      }
    }
    return dp;
  }
}

class priorityQueue{
  constructor(){
    this.a=[];
  }
  push(num,inc){
    const a = this.a;
    for(var i = a.length, j; i; i = j){
      j = i - 1 >> 1;
      if(a[j][0] <= num)break;
      a[i] = a[j];
    }
    a[i] = [num,inc];
  }
  pop(){
    const a = this.a, r = a[0], x = a.pop(), k = a.length >> 1;
    for(var i = 0, j; i < k; i = j){
      j = (i << 1) + 1;
      if(a[j+1] && a[j+1][0] < a[j][0])j++;
      if(x[0] <= a[j][0])break;
      a[i] = a[j];
    }
    if(a.length)a[i] = x;
    return r;
  }
  get size(){
    return this.a.length;
  }
  get top(){
    return this.a[0];
  }
}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [n,m] = nexts(2);
  var dij = new dijkstra(n);
  for(var i = 0; i < m; i++){
    var [a,b] = nexts(2);
    a--,b--;
    dij.add2(a,b,1);
  }
  var d = dij.solve(0);
  var ans = ["Yes"];
  for(var i = 1; i < n; i++){
    for(var j = 0; j < dij.graph[i].length; j++){
      var v = dij.graph[i][j];
      if(d[i]-1 === d[v]){
        ans.push(v+1);
        break;
      }
    }
  }
  return ans.join("\n");
}

Measured memory_bytes: 129144
N, M = tuple(map(int, input().split()))
A, B = [], []
for _ in range(M):
    a, b = tuple(map(int, input().split()))
    A.append(a)
    B.append(b)
path1 = set()
path2 = set()
for a, b in zip(A, B):
    if a == 1:
        path1.add(b)
    if b == N:
        path2.add(a)
if len(path1.intersection(path2)) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 26152
import sys
import itertools
import math
input = sys.stdin.readline
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
jisyo=[]
for i in range(1,N+1):
    jisyo.append(i)
ans =[]
for v in itertools.permutations(jisyo, N):
    ans.append(list(v))
print(abs(ans.index(P)-ans.index(Q)))

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

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

    int a[4];
    rep(i, 4) a[i] = s[i] - '0';

    for (int i = 0; i < (1 << 3); i++) {
        char op[3];
        int ans = a[0];
        rep(j, 3) {
            if (i & (1 << j)) {
                ans += a[j + 1];
                op[j] = '+';
            } else {
                ans -= a[j + 1];
                op[j] = '-';
            }
        }
        if (ans == 7) {
            cout << a[0];
            rep(i, 3) { cout << op[i] << a[i + 1]; }
            cout << "=7" << endl;
            return 0;
        }
    }
}


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


int main()
{
    int N, K,a;
    cin >> N >> K;
    vector<int> c(N + 1);
    for (int i = 1; i <= N; i++){
        cin >> a;
        c[a]++;
    }
    sort(c.begin(),c.end());
    int ans=0;
    for(int i=0;i<=N-K;i++){
        ans+=c[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	int n = readln.chomp.to!int;
	string s = readln.chomp;
	
	ulong mod = 1_000_000_007;
	
	ulong[][] dp; // dp[j][i] := # of ways to make (any) string of length i by pressing j times
	foreach(j; 0 .. n + 2){
		dp ~= [0];
		dp[j].length = n + 2;
		foreach(i; 0 .. n + 2){
			if(j == 0){
				if(i == 0) dp[j][i] = 1;
				else dp[j][i] = 0;
				}
			else{
				if(i == 0) dp[j][i] = dp[j - 1][i] + dp[j - 1][i + 1];
				else if(i < n - 1)
						dp[j][i] = dp[j - 1][i - 1] * 2 + dp[j - 1][i + 1];
				else
						dp[j][i] = dp[j - 1][i - 1] * 2;
				}
			dp[j][i] %= mod;
			}
		}
	
	ulong ans = dp[n][s.length];
	foreach(k; s){
		if(ans % 2 == 0) ans /= 2;
		else ans = (ans + mod) / 2;
		}
	
	ans.writeln;
	
	}



Measured memory_bytes: 200828
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] d = new int[n];
        int[] c = new int[n];

        for(int i=0; i<n; i++) {
            d[i] = sc.nextInt();
            c[d[i]]++;
        }

        if(c[0] != 1 || d[0] != 0) {
            System.out.println(0);
            return;
        }

        long res = 1;
        long mod = 998244353;

        int sum = 1;
        for(int i=1; i<n; i++) {
            long a = 1;
            for(int j=0; j<c[i]; j++) {
                res *= c[i-1];
                res %= mod;
            }
        }

        System.out.println(res);

    }


}


Measured memory_bytes: 61280
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int N, M, P, X[102];

int solve() {
  if (X[M] == 0) return 0;
  double sum = accumulate(X, X+N, 0);
  sum *= (100 - P);
  return static_cast<int>(sum / X[M]);
}

int main() {
  while (scanf("%d%d%d", &N, &M, &P), N) {
    --M;
    rep(i,N) scanf("%d", X+i);
    printf("%d\n", solve());
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
	int a, b, c;
	int ans = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (int i = 0; i < b; i++)
	{
		if (a * i % b == c)
		{
			ans = 1;
			break;
		}
	}
	if (ans == 1)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128