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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int A[310];
double dp[310][310][310];

int main(){

    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> A[i];
    for(int tr = 0; tr <= N; tr++){
        for(int tw = 0; tw <= N; tw++){
            for(int on = 0; on <= N; on++){
                double res = 0;
                if(!(tr == 0 && tw == 0 && on == 0)){
                    double do_no = N - (tr + tw + on);
                    res = 1;
                    if(tr - 1 >= 0)
                        res += (1.0*tr / N) * dp[tr - 1][tw + 1][on];
                    if(tw - 1 >= 0)
                        res += (1.0*tw / N) * dp[tr][tw - 1][on + 1];
                    if(on - 1 >= 0)
                        res += (1.0*on / N) * dp[tr][tw][on - 1];
                    res /= (1.0 - (do_no / N));
                }
                dp[tr][tw][on] = res;
            }
        }
    }

    int freq[4] = {};
    for(int i = 0; i < N; i++){
        freq[A[i]]++;
    }

    printf("%.10f\n", dp[freq[3]][freq[2]][freq[1]]);


    return 0;
}


Measured memory_bytes: 227584
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<ll> a(n+1);
    REP(i,n){
        cin>>a[i];
    }
    a[n]=0;
    ll ans=0;
    REP(i,n){
        ans+=a[i]/2;
        a[i]%=2;
        if(a[i]>0&&a[i+1]>0){
            ++ans;
            --a[i];
            --a[i+1];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstring>
#include <cstdio>
int lst[100005], to[200005], pre[200005], tot; 
int dp[100005], del_cnt, ans; 
bool del[100005]; 
char col[100005]; 
inline void add_edge(int u, int v)
{
	to[tot] = v; 
	pre[tot] = lst[u];
	lst[u] = tot++; 
}
void dfs(int u, int fa = -1)
{
	int cnt = 0; 
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (to[i] == fa)
			continue; 
		dfs(to[i], u); 
		cnt += !del[to[i]]; 
	}
	if (!cnt && col[u] == 'B')
	{
		del[u] = true; 
		del_cnt++; 
	}
}
int calc(int u, int fa = -1)
{
	int res = 0, mx = 0, cur = (col[u] == 'W') ^ (fa != -1); 
	for (int i = lst[u]; ~i; i = pre[i])
	{
		int v = to[i]; 
		if (v == fa || del[v])
			continue; 
		cur ^= 1; 
		res = std::max(res, calc(v, u)); 
		mx = std::max(mx, dp[u] + dp[v]); 
		dp[u] = std::max(dp[u], dp[v]); 
	}
	dp[u] += cur; 
	ans += cur; 
	return std::max(res, mx + cur); 
}
int main()
{
	// freopen("ARC097-F.in", "r", stdin); 
	memset(lst, -1, sizeof(lst)); 
	int n, rt = -1; 
	scanf("%d", &n); 
	for (int i = 1; i < n; i++)
	{
		int u, v; 
		scanf("%d%d", &u, &v); 
		add_edge(--u, --v); 
		add_edge(v, u); 
	}
	scanf("%s", col); 
	for (int i = 0; i < n; i++)
	{
		if (col[i] == 'W')
			rt = i; 
	}
	if (rt == -1)
	{
		puts("0"); 
		return 0; 
	}
	dfs(rt); 
	if (del_cnt == n - 1)
	{
		puts("1"); 
		return 0; 
	}
	ans = n - del_cnt - 1 << 1; 
	ans -= calc(rt) << 1; 
	printf("%d\n", ans);
	return 0; 
}


Measured memory_bytes: 10368
from sys import stdin
def LI(): return list(map(int,stdin.readline().rstrip().split()))

tmp = LI()
n,m = [tmp.pop(0) for _ in range(2)]

l = []
r = []

for i in range(m):
    tmp = LI()
    l.append(tmp.pop(0))
    r.append(tmp.pop(0))

ll = l[0]
rr = r[0]
for i in range(2):
    for j in range(m):
        if i == 0:
            if ll < l[j]:
                ll = l[j]
        else:
            if r[j] < rr:
                rr = r[j]

if rr<ll:
    print(0)
else:
    k = rr-ll+1
    if n<k:
        print(n)
    else:
        print(k)

Measured memory_bytes: 11040
#include <iostream>
#include <cmath>
using namespace std;
int a[111111],dp[111111];
int main(){
	int n,k;
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++){
		int m=1e10;
		if(k>=i){
			for(int j=1;j<=i-1;j++){
				m=min((dp[i-j]+abs(a[i]-a[i-j])),m);
			}
		}else{
			for(int j=1;j<=k;j++){
				m=min(dp[i-j]+abs(a[i]-a[i-j]),m);
			}
		}
		dp[i]=m;
	}
	cout << dp[n];
}


Measured memory_bytes: 4452
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  int K;
  cin >> K;

  int a = 7 % K;
  rep(i, K) {
    if (a == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    a = 10 * a + 7;
    a %= K;
  }
  cout << -1 << endl;
  return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

int n , t , x;
int a[MAXX];

int main()
{
    _FastIO;

    cin >> n;
    cin >> t >> x;
    vector<pair<double , int> > v;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        v.push_back({(double(abs((x * 1.0) - (t - a[i] * 6 * 1.0 / 1000)))) , (i)});
    }
    sort(v.begin() , v.end());
    cout << v[0].second << endl;
    return 0;
}


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

int main(){
  unsigned long long a,b;
  char s[4];
  scanf("%llu %s",&a,s);
  b = (s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';
  printf("%llu\n",(a*b)/100);
  return 0;
}
 

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

int main(){
	int N,K,ans=0;
	string S;
	cin >> N >> K >> S;
	vector<int> p;
	int c=1;
	if(S[0]=='0')p.push_back(0);
	for(int i=0;i<N-1;i++){
		if(S[i]!=S[i+1]){
			p.push_back(c);
			c=1;
		}
		else c++;
	}
	p.push_back(c);
	if(S[N-1]=='0')p.push_back(0);
	
	int l=0,r=0,sum=p[0];
	while(1){
		ans=max(ans,sum);
		if(l==p.size()-1 && r==p.size()-1)break;
		if(r<p.size()-1 && r-l<2*K){
			sum+=p[r+1]+p[r+2];
			r+=2;
		}
		else{
			if(l<p.size()-2){
				sum-=p[l]+p[l+1];
				l+=2;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  ll A, B;
  cin >> A >> B;

  if ((A + B) % 2 == 0) {
    cout << (A + B) / 2;
  } else {
    cout << "IMPOSSIBLE";
  }
  return 0;
}

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

using namespace std;

#define FAST_IO ios::sync_with_stdio(false); cout.tie(NULL);


int main()
{
	FAST_IO;

	int n;
	cin >> n;

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

	int maxi = abs(array[0] - array[1]);

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; j++)
		{
			if (i != j)
				maxi = max(maxi, abs(array[i] - array[j]));
		}
	}

	cout << maxi << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int h = s/3600;
        int m = (s-h*3600)/60;
        s = s-(h*3600)-(m*60);
        System.out.println(h+":"+m+":"+s);
    }
}


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

int main(){
	int a,b; cin>>a>>b;
	int ans = a;
	if(a>b) ans--;
	ote(ans);
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	bool h=true;
	string s;
	cin>>s;
	int n=s.size();
	rep(i,s.size())if(s[i]-s[n-1-i])h=false;
	rep(i,s.size()/2)if(s[i]-s[n/2-1-i])h=false;
	rep(i,n/2)if(s[n-1-i]-s[n/2+i+1])h=false;
	if(h)yes;
	else no;
	
}






Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int n, m;
  bool flag=false;
  string a[55];
  string b[55];
  cin >> n >> m;
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int j=0; j<m; j++){
    cin >> b[j];
  }

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(b[0][0]==a[i][j]){flag=true;}
        for(int k=0; k<m && flag; k++){
          for(int l=0; l<m && flag; l++){
            if(b[k][l]!=a[i+k][j+l]){flag=false;}
            if(k==m-1 && l==m-1){cout << "Yes" << endl;return 0;}
          }
        }

    }
  }
  cout << "No" << endl;
  return 0;

}


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//最終奥義 #define int long long
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; }
//lambda: [](int x, int y){return x<y;}

signed main(void){
    int n,r;
    cin>>n>>r;
    if(n>=10){
        cout << r << endl;
    }else{
        cout << r+(100*(10-n)) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;

int a[maxn];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int l, r;
    REP(i, m) {
        scanf("%d%d", &l, &r);
        a[l]++, a[r + 1]--;
    }
    REP(i, n) a[i + 1] += a[i];
    int ans = 0;
    REP(i, n + 1) if (a[i] == m) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
ll A[60][40];
ll B[1000000];
ll N;
ll ans;
ll M = 1000000000;


int main() {
    cin >> N;
    for(int i=0;i<N;i++){
        double a;
        cin >> a;
        ll b = a*M + 0.5;
        P p;
        for(int j=0;j<60;j++){
            ll c = b;
            for(int k=0;k<40;k++){
                p=P(j,k);
                if(c%5!=0){
                    break;
                }
                c /= 5;
            }
            if(b%2!=0){
                break;
            }
            b /= 2;
        }
        A[p.first][p.second] += 1;
    }
        for(int i=0;i<60;i++){
            for(int j=0;j<40;j++){
                for(int k=0;k<60;k++){
                    for(int l=0;l<40;l++){
                        if(i+k>=18&&j+l>=18){
                            if(i==k&&j==l){
                                ans += A[i][j]*(A[i][j]-1);
                            }else{
                                ans+=A[i][j]*A[k][l];
                            }
                        }
                    }
                }
            }
        }
    
        cout << ans/2 << endl;
    
}


Measured memory_bytes: 3716
n=int(input())
h=list(map(int,input().split()))
flag=False
h[0]-=1

for i in range(1,n):
  if h[i-1]<=h[i]-1:
    h[i]-=1
  elif h[i-1]==h[i]:
    pass
  else:
    flag=True
    break
    
if flag:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 84864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n;
    cin >> n;
    int x = 0, y = 1000;
    while(n--){
        int a; cin >> a;
        if(a > x) x = a;
        if(a < y) y = a;
    }
    cout << x - y << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <string>
#define  debug	  0
#define  MAXN  100010
using namespace std;
int count=0;
int hashTable[MAXN]={0};
map<int,int>id;
int getid(int n)
{	extern int count;
	if(id.find(n) == id.end())
	{	id[n]= count++;
	}
	return id[n];
}
int main()
{				
#if debug 
freopen("data.txt","r",stdin);
#endif
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) 
	{	int number,idd;
		scanf("%d",&number);
		idd = getid(number);
		hashTable[idd] = !hashTable[idd];
	}
	int cnt=0;
	extern int count;
	for(int i=0;i<count;i++)
	{
		if(hashTable[i])cnt++;
	}
	printf("%d\n",cnt);
}


Measured memory_bytes: 5376
#include<iostream>
 
using namespace std;
 
int main(){
  int n;
  scanf("%d",&n);
  int s[n];
  for(int i=0;i<n;i++)
  {
    int temp;
    scanf("%d",&temp);
    s[i]= temp;
  }
  int cnt=1;
  if(n==1)
  {
    cout<< cnt;
    return 0;
  }
  int MAx=s[0];
  for(int i= 1;i<n;i++)
  {
    if(s[i]>=MAx)
    {
      MAx=s[i];
      cnt++;
    }
  }
  cout<< cnt<<endl;
  return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

class unionfind {
	vector<int> par, rank;

public:
	void init(int n) {
		par.resize(n);
		rank.resize(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];
		}
	}

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

string s;
int Q;
int L[100010], R[100010];
int N;
int cmp[100010];

int main() {
	cin >> s >> Q;
	N = s.size();
	uf.init(N + 10);

	rep(i, Q) {
		scanf("%d %d", &L[i], &R[i]);
		--L[i]; --R[i];
	}

	vector<pii> vec;

	if (N & 1) {
		int ct = N / 2;
		rep(i, Q) {
			if (L[i] <= ct && ct <= R[i]) {
				if ((ct-L[i])==(R[i]-ct)) {
					continue;
				}
				else if ((ct-L[i])>(R[i]-ct)) {
					R[i] = ct-(R[i]-ct)-1;
					vec.eb(L[i], R[i]);
				} else {
					L[i] = ct+(ct-L[i])+1;
					vec.eb(N-1-R[i],N-1-L[i]);
				}
			} else if (R[i] < ct) {
				vec.eb(L[i], R[i]);
			} else {
				vec.eb(N-1-R[i], N-1-L[i]);
			}
		}
	} else {
		rep(i, Q) {
			if (L[i] <= N/2-1 && N/2 <= R[i]) {
				if ((N/2-1-L[i])==(R[i]-N/2)) {
					continue;
				} else if ((N/2-1-L[i])>(R[i]-N/2)) {
					R[i] = N-2-R[i];
					vec.eb(L[i],R[i]);
				} else {
					L[i] = N-L[i];
					vec.eb(N-1-R[i],N-1-L[i]);
				}
			} else if (R[i]<N/2) {
				vec.eb(L[i],R[i]);
			} else {
				vec.eb(N-1-R[i],N-1-L[i]);
			}
		}
	}

	vi df;

	rep(i, N/2) {
		df.pb(s[i]-s[N-1-i]);
	}

	vi acm;
	acm.pb(df[0]);

	rep(i,(int)df.size()-1) {
		acm.pb(df[i+1]-df[i]);
	}

	acm.pb(-1e9);

	for (auto p:vec) {
		uf.unite(p.fi, p.se + 1);
	}

	rep(i, acm.size()) {
		cmp[uf.find(i)] += acm[i];
	}

	bool ok = 1;
	rep(i, acm.size()) {
		if (uf.same(i, (int)acm.size()-1)) {
			continue;
		} else {
			if (cmp[uf.find(i)] % 26 != 0) {
				ok = 0;
			}
		}
	}

	puts(ok ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 3572
//最少全域木
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int G[103][103];
int V;
int NG[103][103];//新しくできるほう
int used[103];
int main(){
	int ans=0;
	cin>>V;
	for(int i=0;i<V;i++){
		for(int j=0;j<V;j++){
		cin>>G[i][j];
		}
	}
	for(int i=0;i<103;i++)for(int j=0;j<103;j++)NG[i][j]=-1;
	used[0]=1;
	for(int i=0;i<V;i++){
		int u=-1,a,b;
		for(int j=0;j<V;j++){
		if(used[j]==0)u=i;
		}
		if(u==-1)break;
		int now=99999999;
		for(int j=0;j<V;j++){
			for(int k=0;k<V;k++){
			if(now>G[j][k]&&G[j][k]!=-1&&used[j]==1&&used[k]==0){
			now=G[j][k];
			a=j,b=k;
			}
			}
		}
		ans+=G[a][b];
		used[b]=1;
		NG[a][b]=G[a][b];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1244
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

H, W = map(int, input().split())

for _ in range(H):
    l = input()
    print(l)
    print(l)


Measured memory_bytes: 9116
import java.util.Scanner;

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

		while(a != 0){
			System.out.printf("Case %d: %d\n", i, a);
			a = sc.nextInt();
			i++;
		}
		
	}
}


Measured memory_bytes: 65496
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 long long MOD = 1000000007;
typedef long long ll;

int n,k,q,f;
string s,t;
char c; bool r=0;

int main() {
  cin >> s;
  bool ok=true;
  if((int)s.size()%2==1) ok=false;
  int cnt=0;
  rep(i,(int)s.size()-1)if(s.substr(i,2)=="hi") cnt++;
  if(cnt!=(int)s.size()/2) ok=false;
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      x = pow(B, i, M)
      sum_g[m] += x
      sum_g[0] -= x
  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret += (sx*sy*sz) % M
  return ret%M


edge = [read_edge() for i in range(3)]

print(solve(N, edge))

Measured memory_bytes: 73492
n=int(input())
a=list(map(int,input().split()))
ans=0
changeflag=[]
for i in range(n-1):
    if a[i]==a[i+1]:
        if i==0 or changeflag[i-1]==0:
            changeflag.append(1)
        else:
            changeflag.append(0)
    else:
        changeflag.append(0)
print(changeflag.count(1))


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    sort(all(a));

    int ans = 0;
    rep(i, n - 1)
    {
        if (x >= a[i])
        {
            x -= a[i];
            ans++;
        }
        else
        {
            break;
        }
    }

    if (x == a[n - 1])
    {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


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

#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()cout
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)

signed main(){
  int A,B,N,M,O,P,count=0,count2=0,count3=0,stack=0;
  str S,T;
  cin>>A>>B>>N;
  if(A%N==0)cout<<B/N-A/N+1<<endl;
  else cout<<B/N-A/N<<endl;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

int main(){

    ll n, m; cin >> n >> m;
    vll a(n);
    rep(i, n) cin >> a[i];
    vector<P> cb(m);
    ll b, c, cb_size;
    rep(i, m){
        cin >> b >> c;
        cb[i].first  = c;
        cb[i].second = b;
        cb_size += b;
    } 

    sort(all(a));
    sort(all(cb));
    reverse(all(cb));

    ll ans = 0;
    ll j = 0;
    b = 0;
    rep(i, n){
        if(i>=cb_size){
            ans += a[i];
            continue;
        }

        if(b == 0){
            b = cb[j].second;
            c = cb[j].first;
            j++;
        }
        if(a[i]<c){
            ans += c;
        }
        else{
            ans += a[i];
        }
        b--;
    }

    cout << ans << endl;

    return 0;
}

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

class Stack{
private:
  int s;
  int S[100];
public:
  Stack(){
    s=0;
  }
  bool isFull(){
    return (s==100);
  }
  bool isEmpty(){
    return (s==0);
  }
  void push(int d){
    if(isFull()){
      return;
    }
    S[s++] = d;
  }
  void pop(){
    if(isEmpty()){
      return;
    }
    s--;
  }
  int top(){
    if(isEmpty()){
      return -1;
    }
    return S[s-1];
  }
};

int main(){
  Stack p;
  string e;
  getline(cin, e);
  istringstream is(e);
  while(!is.eof()){
    string op;
    is >> op;
    int tmp1,tmp2;
    switch(op[0]){
      case'+':
        tmp1 = p.top();
        p.pop();
        tmp2 = p.top();
        p.pop();
        p.push(tmp2+tmp1);
        break;
      case'-':
        tmp1 = p.top();
        p.pop();
        tmp2 = p.top();
        p.pop();
        p.push(tmp2-tmp1);
        break;
      case'*':
        tmp1 = p.top();
        p.pop();
        tmp2 = p.top();
        p.pop();
        p.push(tmp2*tmp1);
        break;
      default:
        istringstream is2(op);
        is2 >> tmp1;
        p.push(tmp1);
        break;
    }
  }
  cout << p.top() << endl;
  return 0;
}



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

const int INF = 1<<30;
int w[6] = {2, 3, 5, 10, 12, 15};
int v[6] = {380, 550, 850, 1520, 1870, 2244};
int dp[51];

int main(){
    int i,j;
    dp[0] = 0;
    for(i = 1; i <= 51; i++) dp[i] = INF;
    for(i = 0; i < 6; i++){
        for(j = w[i]; j <= 50; j++){
            dp[j] = min(dp[j], dp[ j-w[i] ] + v[i]);
        }
    }
    while(cin>>i,i) cout << dp[i/100] << endl;
    return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
int main(void)
{
  int a[4],b[4],i,j,hit,blow;
  while(scanf("%d %d %d %d %d %d %d %d",
	      &a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3])!=EOF){
    hit=0;blow=0;
    for(i=0;i<4;i++){
      if(a[i]==b[i])hit++;
    }
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
	if(i==j)continue;
	if(a[j]==b[i])blow++;
      }
    }
    printf("%d %d\n",hit,blow);
  }
  return 0;
}

Measured memory_bytes: 596
S = input()
AA = int(S[:2]) 
BB = int(S[2:])
if (1 <= AA <= 12) and (1 <= BB <= 12):
    print('AMBIGUOUS')
elif (13 <= AA or AA == 0) and (1 <= BB <= 12):
    print('YYMM')
elif (1 <= AA <= 12) and (13 <= BB or BB == 0):
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
// 287644PV
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(10)<<(x)

long long game2(int s, int e,bool t ,vector<int>&a, vector<vector<vector<long long>>> &memo){
    if (s == e) return t ? a[s] : - a[s];
    else if(memo[s][e][t] != 1e18)
        return memo[s][e][t];
    else if(t)
    {
        memo[s][e][t] = max(a[s] + game2(s+1,e,!t,a,memo),a[e] + game2(s,e-1,!t,a,memo));
        return memo[s][e][t];
    } else
    {
        memo[s][e][t] = min(-a[s] + game2(s+1,e,!t,a,memo),-a[e] + game2(s,e-1,!t,a,memo));
        return memo[s][e][t];
    }
}



int mod = 1000000000+7;

long long game(long long curr, long long x, long long y, vector<int> &a, bool t, int beg, int end)
{
    if(beg == end)
            return a[beg];
    else if(t) {
        curr += max(a[beg] + game(curr,x, y, a, false, beg + 1, end), a[end] + game(curr,x, y, a, false, beg, end - 1));
        return curr;
    }
    else {
         curr -= max(a[beg] + game(curr,x, y, a, true, beg + 1, end), a[end] + game(curr,x, y, a, true, beg, end - 1));
         return curr;
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<vector<long long>>> memo(n,vector<vector<long long>>(n,vector<long long>(2,1e18)));
    cout << game2(0,a.size()-1,true,a,memo);

}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
  }
  bool ans = true;
  
  for(int i = 0;i < n;i++){
    if (a.at(i) % 2 == 0){
      if (a.at(i) % 3 != 0 && a.at(i) % 5 != 0){
        ans = false;
      }
    }
  }
  
  if (ans){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 3636
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}




const ll N=1e5+5;



int main()
{ 

IOS;

ll n;cin>>n;

vector<char>ans;

while(n){
  ll q=n%26;
  char t='a'+q-1;
  if(!q)t='z';
  ans.pb(t);
  n/=26;
  if(!q)n--;
}

rev(ans);

for(auto d:ans)cout<<d;

//end_routine();

return 0;
 
 }


Measured memory_bytes: 3592
from copy import deepcopy


def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    b = deepcopy(a)
    b.sort()
    for aa in a:
        if aa == b[-1]:
            print(b[-2])
        else:
            print(b[-1])


if __name__ == '__main__':
    main()



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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

double dp[3005][3005];
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    cout << fixed << setprecision(15);

    int n; cin >> n;
    vec<double> p(n); rep(i,n) cin >> p[i];
    dp[0][0] = 1;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= n; ++j) {
            // 使わない
            dp[i+1][j] += dp[i][j]*(1-p[i]);
            // 使う
            dp[i+1][j+1] += dp[i][j]*p[i];
        }
    }

    double ans = 0;
    for(int j = (n+1)/2; j <= n; ++j) {
        ans += dp[n][j];
    }
    cout << ans << '\n';
}

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

int main() {
  int n = 0;
  cin >> n;
  int t[n];
  int x[n];
  int y[n];
  for(int i = 0; i < n; ++i){
    cin >> t[i] >> x[i] >> y[i];
  }

  int px = 0, py = 0, pt = 0;
  for(int i = 0; i < n; ++i){
    int dpos = abs((x[i]+y[i]) - (px+py));
    int dt = t[i] - pt;
    if (dpos > dt) {
      cout << "No" << endl;
      return 0;
    }
    
    if (dpos % 2 == 0) {
      if (dt % 2 != 0) {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (dt % 2 == 0) {
        cout << "No" << endl;
        return 0;
      }
    }

    px = x[i];
    py = y[i];
    pt = t[i];
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    string s; cin>>s;
    int n = s.size();
    s = s + "T";
    int ans = n;
    
    int r= 0;
    rep(i,n){
        if(s[i] == 'S'){
            r = max(i, r);
            while(s[r] != 'T'){
                r++;
            }
            if(r==n) break;
            else {ans-=2; r++;}
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 772
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())


ans = -1
memo = 0
light = 1

for i in range(n):
    if light == 2:
        ans = memo
        break
    light = a[light-1]
    memo += 1


print(ans)

Measured memory_bytes: 12860
#include<iostream>
using namespace std;
int main() {
    int h, w; cin >> h >> w;
    char s[h + 2][w + 2];
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            cin >> s[i][j];
        }
    }
    for (int i = 0; i <= h; ++i) {
        s[i][0] = '0';
        s[i][w + 1] = '0';
    }
    for (int j = 0; j <= w; ++j) {
        s[0][j] = '0';
        s[h + 1][j] = '0';
    }
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            int cnt = 0;
            if (s[i][j] == '.') {
                if (s[i - 1][j] == '#') {
                    cnt++;
                }
                if (s[i + 1][j] == '#') {
                    cnt++;
                }
                if (s[i][j - 1] == '#') {
                    cnt++;
                }
                if (s[i][j + 1] == '#') {
                    cnt++;
                }
                if (s[i - 1][j - 1] == '#') {
                    cnt++;
                }
                if (s[i - 1][j + 1] == '#') {
                    cnt++;
                }
                if (s[i + 1][j + 1] == '#') {
                    cnt++;
                }
                if (s[i + 1][j - 1] == '#') {
                    cnt++;
                }
                s[i][j] = cnt + '0';
            }
        }
    }
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            cout << s[i][j];
            if (j == w) {
                cout << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int count1=0,count2=0,i,j,a,b,c,x,y;
		while(s.hasNext()){
			String[] str=s.next().split(",");
			a=Integer.parseInt(str[0]);
			b=Integer.parseInt(str[1]);
			c=Integer.parseInt(str[2]);
			x=c*c;y=a*a+b*b;
			if(x==y) count1++;
			if(a==b) count2++;
		}
		System.out.println(count1);
		System.out.println(count2);
	}
}

Measured memory_bytes: 0
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

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


	int N = getint();

	int A[1000001] = {};
	rep(i, N) A[getint()]++;

	if (A[1]) {
		if (A[1] == 1) co(1);
		else co(0);
		return 0;
	}
	if (A[2]) {
		int kotae = (A[2] == 1);
		for (int i = 3; i <= 500000; i += 2) {
			if (A[i]) {
				kotae += (A[i] == 1);
				for (int j = i + i; j <= 1000000; j += i) {
					A[j] = 0;
				}
			}
		}
		for (int i = 500001; i <= 1000000; i += 2) kotae += (A[i] == 1);
		co(kotae);
		return 0;
	}

	int kotae = 0;
	for (int i = 2; i <= 500000; i++) {
		if (A[i]) {
			kotae += (A[i] == 1);
			for (int j = i + i; j <= 1000000; j += i) {
				A[j] = 0;
			}
		}
	}
	for (int i = 500001; i <= 1000000; i++) kotae += (A[i] == 1);
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 7652
#include <stdio.h>
#define STACK_SIZE 1000
#define MAX_LEN 1000

int stack[STACK_SIZE];
int stack_size = 0;

// スタックから出す
int pop()
{
	if (stack_size <= 0) return 0;
	return stack[--stack_size];
}

// スタックに積む
int push(int a)
{
	stack[stack_size++] = a;
}

// 要素が数値かどうか判定
int is_digit(char *s)
{
	// 符号つき
	if (*s == '+' || *s =='-') {
		s++;
		if (*s >= '0' && *s <= '9') return 1;
		return 0;
	}
	// 符号なし
	if (*s >= '0' && *s <= '9') return 1;
	return 0;
}

// 文字列から数値を取り出す
int get_number(char *s)
{
	int sign = 0, n = 0;

	// 符号処理
	if (*s == '+') {
		s++;
	} else if (*s == '-') {
		sign = 1;
		s++;
	}
	// char to int
	while (*s >= '0' && *s <= '9') {
		n = n * 10 + (*s - '0');
		s++;
	}
	// 符号を変えて返す
	if (sign) return -n;
	return n;
}

// 逆ポーランド記法の文字列を計算
int calc_rpn(char *s)
{
	int a, b, n;

	// 終端まで繰り返す
	while (*s) {

		// 数値なら取り出してスタックに積む
		if (is_digit(s)) {
			n = get_number(s);
			push(n);
			while (*s == '-' || *s == '+') {
				s++;
			}
			while (n) {
				n /= 10;
				s++;
			}

		// オペランドなら2項を計算する
		} else {
			switch (*s) {
			case '+':
				a = pop();
				b = pop();
				push(b+a);
				break;
			case '-':
				a = pop();
				b = pop();
				push(b-a);
				break;
			case '*':
				a = pop();
				b = pop();
				push(b*a);
				break;
			case '/':
				a = pop();
				b = pop();
				if (a == 0) break;
				push(b/a);
				break;
			case '%':
				a = pop();
				b = pop();
				if (a == 0) break;
				push(b%a);
			}
			s++;
		}
	}
	return pop();
}

int main()
{
	char s[MAX_LEN];
	scanf("%[^\n]*s", s);
	printf("%d\n", calc_rpn(s));
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a[2];
  cin >> a[0] >> a[1];
  string c;
  sort(a, a + 2);
  
  for (int i = 0; i < a[1]; i++) {
    c += to_string(a[0]);
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int t[105];
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		sum = sum + t[i];
	}
	int m;
	cin >> m;
	int p[105], x[105];
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> x[i];
	}
	int ans;
	for (int i = 0; i < m; i++) {
		ans = sum - t[p[i] - 1] + x[i];
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 256
n, k, q = [ int(_) for _ in input().split() ]
a = [ int(input()) for _ in range(q) ]

p = [ k for _ in range(n) ]

p = [ y-q for y in p ]

for x in a:
	p[x-1] += 1

ans = []

for z in p:
	if z > 0:
		ans.append('Yes')
	else:
		ans.append('No')

for blah in ans:
	print(blah)

Measured memory_bytes: 59096
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    x = list(map(int, input().rstrip('\n').split()))
    ma = 10 ** 20
    for i in range(n - k + 1):
        ma1 = abs(x[i])
        ma2 = abs(x[i + k - 1])
        if x[i] * x[i + k - 1] >= 0:
            ma = min(max(ma1, ma2), ma)
        else:
            ma = min(ma1 + ma2 + min(ma1, ma2), ma)
    print(ma)


if __name__ == '__main__':
    slove()


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

int main() {
  int x,num,a=0,b=0;
  cin >> x >> num;
  cout << endl;
  vector<int> n(num);
  for(int i=0; i<num;i++){
  	cin >> n.at(i);
  }
  int l,m,i;
  for(i=x;i<102;i++){
    l=0;
  	for(int j=0;j<num;j++){
    	if(i!=n.at(j)){
        	l++;
        }
    }
    if(l==num){
    	a=i;
      i=102;
    }
  }

  for(i=x;i>-102;i--){
    m=0;
  	for(int j=0;j<num;j++){
    	if(i!=n.at(j)){
        	m++;
        }
    }
    if(m==num){
    	b=i;
      i=-120;
    }
  }
  int u,r;
  u=a-x;
  r=x-b;
  if(num==0){cout << x << endl;}else{
  if(u>r){cout << b << endl;}
  if(r>u){cout << a << endl;}
  if(u==r){cout << b << endl;}
  }
}


Measured memory_bytes: 3580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
const int MAXN = 1e5 + 10;
int nums[MAXN], dp[MAXN], tree[MAXN];
LL n;
int lowbit(int i) {
    return i&(-i);
}
LL query(int i) {
    LL ret = 0;
    while (i > 0) {
        ret += tree[i];
        i -= lowbit(i);
    }
    return ret;
}
void add(int i) {
    while (i <= n+1) {
        tree[i]++;
        i += lowbit(i);
    }
}
LL solve(LL val) {
    for (int i = 1; i <= n; i++) {
        if (nums[i-1] >= val) dp[i] = 1;
        else dp[i] = -1;
    }
    for (int i = 1; i <= n; i++) {
        dp[i] += dp[i-1];
    }
    map<int, int> rank;
    for (int i = 0; i <= n; i++) {
        rank[dp[i]] = 0;
    }
    int cur = 1;
    for (auto& item : rank) {
        item.second = cur++;
    }
    memset(tree, 0, sizeof(tree));
    LL ret = 0;
    for (int i = 0; i <= n; i++) {
        int tmp = rank[dp[i]];
        ret += query(tmp);
        add(tmp);
    }
    return ret;
}



int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL
    freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    if (n == 1) {
        cout << nums[0] << endl;
        return 0;
    }
    LL a = 1, b = 1e9;
    LL tot = n * (n+1) / 2 + 1;

    while (a < b) {
        LL mid = (a+b + 1) >> 1;
        if (solve(mid) >= tot/2) a = mid;
        else b = mid - 1;
    }
    cout << a << endl;


/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
    return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 6144
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
    long long N;
    long long F;
    scanf("%lld",&N);

    for(long long i=1;i<=sqrt(N);i++){
        if(N%i == 0) F = fmax(i,(long long)(N/i));
    }

    int ans = 0;
    for(;F>0;F/=10){
        ans++;
    }
    printf("%d\n",ans);

    return 0;

}


Measured memory_bytes: 128
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

h,w = rm()
for i in range(h):
    a = list(rs())
    for idx, j in enumerate(a):
        if j == 'snuke':
            print(f'{chr(65+idx)}{i+1}')
            exit()














Measured memory_bytes: 27132
n,k=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i).sort

if a.include?(k)
    puts "POSSIBLE"
    exit
end

if a[-1] < k
    puts "IMPOSSIBLE"
    exit
end

def gcd(a,b)
    a,b = b,a if a>b
    if (b%a==0)
        a
    else
        gcd(b%a,a)
    end
end

m=a[0]
a.each do |v|
    m=gcd(m,v)
end

puts k%m==0?"POSSIBLE":"IMPOSSIBLE"


Measured memory_bytes: 11008