akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+5;
const int mod=998244353;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    if(n%2)
    {
        int i=1,j=n;
        while(m--)
        {
            cout<<i<<" "<<j<<'\n';
            i++;
            j--;
        }
    }
    else
    {
        int i=1,j=n/2;
        while(m)
        {
            cout<<i<<" "<<j<<'\n';
            m--;
            i++;
            j--;
            if(i>=j)
                break;
        }
        i=n/2+2,j=n;
        while(m--)
        {
            cout<<i<<" "<<j<<'\n';
            i++;
            j--;
        }
    }


}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int w=2e5+5;
int main()
{
    int i,j;
    ll x,n;
    cin>>x>>n;
    ll ans=0;
    while(n--)
    {
        ll x;
        scanf("%lld",&x);
        ans+=x;
    }
    if(ans>=x)
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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(){
ll n;
cin >> n;
vector<double> p(n);
for (ll i = 0; i < n; i++) cin >> p[i];
double dp[n + 2][n + 2];//dp[i][j]:=i枚目まで見て、j枚表の確率
for (ll i = 0; i < n + 2;i++){
    for (ll j = 0; j < n + 2;j++){
        dp[i][j] = 0.0;
    }
}
dp[0][0] = 1;
for (ll i = 1; i < n+1;i++){
    for (ll j = 0; j < n + 1;j++){
        if (j > 0) dp[i][j] = dp[i - 1][j - 1] * p[i-1] + dp[i - 1][j] * (1.0 - p[i-1]);
		else
            dp[i][j] = dp[i - 1][j] * (1.0 - p[i-1]);
    }
}
double ans = 0;
for (ll i = (n+1)/2; i < n+1; i++) ans += dp[n][i];
cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 74068
#include <stdio.h>

#define M 500000
#define S 2000000000

int L[M/2+2],R[M/2+2];
int cou=0;

void mer(int *A,int n,int left,int right,int mid){
  int i=0,j=0,k,na,nb;

  na=mid-left;
  nb=right-mid;

  for(i=0;i<na;i++) L[i]=A[left+i];
  for(i=0;i<nb;i++) R[i]=A[mid+i];

  L[na]=R[nb]=S;
  i=j=0;

  for(k=left;k<right;k++){
    cou++;
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }else {
      A[k]=R[j++];
    }
  }
}

void mers(int *A,int n,int left,int right){
  int mid;
  
  if(left+1<right){
    mid=(left+right)/2;
    mers(A,n,left,mid);
    mers(A,n,mid,right);
    mer(A,n,left,right,mid);
  }
}

int main(){
  int i,A[M],n;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mers(A,n,0,n);

  for(i=0;i<n;i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");

  printf("%d\n",cou);

  return 0;
}
    

Measured memory_bytes: 4508
import itertools

X,*list1=open(0).read().split()

X=int(X)

list1=[int(i) for i in list1]

#print(list1)

list2=list(itertools.combinations(list1,2))

#print(list2)

aaa=[]

for i in list2:
    if i[0]>i[1]:
        aaa.append(i[0]-i[1])
    else:
        aaa.append(i[1]-i[0])

#print(aaa)

print(max(aaa))

Measured memory_bytes: 9548
import itertools
D, G = [int(_) for _ in input().split()]
SPC = [[100 * (i + 1)] + [int(_) for _ in input().split()] for i in range(D)]
ans = 10000
for flags in itertools.product([0, 1], repeat = D):
    score = G
    count = 0
    for i in range(D):
        if flags[i]:
            score -= SPC[i][0] * SPC[i][1] + SPC[i][2]
            count += SPC[i][1]
    if score > 0:
        for i in range(D)[::-1]:
            if not flags[i] and SPC[i][0] * (SPC[i][1] - 1) >= score:
                count_res = 1 + (score - 1) // SPC[i][0]
                score -= SPC[i][0] * count_res
                count += count_res
                break
    if score <= 0:
        ans = min(count, ans)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<map>
using namespace std;
const int BUF = 10005;
const int MOD = 1000000007;
const int PRIME = 1000005;

int nPrime;
int prime[PRIME];

void makePrime() {
    bool isPrime[PRIME];
    for (int i = 0; i < PRIME; ++i) isPrime[i] = true;

    for (int i = 2; i * i < PRIME; ++i)
        if (isPrime[i])
            for (int j = i * 2; j < PRIME; j += i)
                isPrime[j] = false;

    nPrime = 0;
    for (int i = 2; i < PRIME; ++i) {
        if (isPrime[i]) {
            prime[nPrime++] = i;
        }
    }
}

int modPow(int p, int n) {
    if (n == 0) return 1;
    int t = modPow(p, n / 2);
    return n % 2 == 0 ? 1LL * t * t % MOD : 1LL * t * t % MOD * p % MOD;
}


int nVal;
int val[BUF];

void read() {
    cin >> nVal;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}


void work() {
    map<int, int> factor2cnt[BUF];

    for (int loop = 0; loop < nVal; ++loop) {
        int v = val[loop];
        for (int i = 0; prime[i] * prime[i] <= v; ++i) {
            if (v % prime[i] == 0) {
                int cnt = 0;
                while (v % prime[i] == 0) {
                    v /= prime[i];
                    ++cnt;
                }
                factor2cnt[loop][prime[i]] = cnt;
            }
        }
        if (v > 1) factor2cnt[loop][v] = 1;
    }

    map<int, int> maxFactor2cnt;
    for (int i = 0; i < nVal; ++i) {
        for (map<int, int>::iterator iter = factor2cnt[i].begin(); iter != factor2cnt[i].end(); ++iter) {
            if (!maxFactor2cnt.count(iter->first)) {
                maxFactor2cnt[iter->first] = 0;
            }
            maxFactor2cnt[iter->first] = max(maxFactor2cnt[iter->first], iter->second);
        }
    }

    int base = 1;
    for (map<int, int>::iterator iter = maxFactor2cnt.begin(); iter != maxFactor2cnt.end(); ++iter) {
        for (int loop = 0; loop < iter->second; ++loop) {
            base = 1LL * base * iter->first % MOD;
        }
    }
    
    int ans = 0;
    for (int i = 0; i < nVal; ++i) {
        int toAdd = base;
        for (map<int, int>::iterator iter = factor2cnt[i].begin(); iter != factor2cnt[i].end(); ++iter) {
            int toRepeat = iter->second;
            int inv = modPow(iter->first, MOD - 2);
            for (int j = 0; j < toRepeat; ++j) {
                toAdd = 1LL * toAdd * inv % MOD;
            }
        }
        ans = (ans + toAdd) % MOD;
    }

    cout << ans << endl;
}


int main() {
    makePrime();
    read();
    work();
    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
/*
 constexpr　がなければTLEになってしまう…
 */
constexpr int MOD = 1000000007;
signed main(){
    string s; cin >> s;
    const int N = s.size();
    auto memo = vectors( N  + 1, 10,13,-1LL);
    /* 桁の重み*/
    vector<int>base( N + 1,0LL);
    base[s.size()] = 1; // 1-index
    for(int i = N - 1; i >= 1; --i)
        base[i] = (9 * base[i + 1] + base[i + 1]) % 13;
    
    
    for(int i = 0; i < 13; ++i)
        for(int j = 0; j < 10; ++j)
            memo[N][j][i] = (i == j ? 1 : 0);
    /*
        digit桁目の数字をnumにしたときに余りがcmodになる場合の数
        関数呼び出し時に次の数字を指定する。
    */
    function<int(int,int,int)>solver = [&](int digit,int num,int cmod){
        if( memo[digit][num][cmod] != -1LL) return memo[digit][num][cmod];
        memo[digit][num][cmod] = 0;
        int temp =  ( base[digit] * num ) % 13;
        int nmod =  (cmod - temp <= 0 ? cmod - temp + 13 : cmod - temp) % 13;
        int nidx = digit;
        //  *****? <- s[idx]
        if(s[nidx] == '?'){
            for(int i = 0; i < 10; ++i){
                memo[digit][num][cmod] += solver(digit + 1, i, nmod);
                memo[digit][num][cmod] %= MOD;
            }
        } else {
            // ******7 <- s[nidx]
            memo[digit][num][cmod] += solver(digit + 1,s[nidx] - '0',nmod);
            memo[digit][num][cmod] %= MOD;
        }
        return memo[digit][num][cmod];
    };
    int ans = 0;
    if(s.front() == '?'){
        for(int i = 0; i < 10; ++i){
            ans += solver(1,i,5);
            ans %= MOD;
        }
    } else {
        ans += solver(1,s.front() - '0',5);
    }
    cout << ans % MOD << endl;
}



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

ll fact[200001], ifact[200001];

ll exp(ll x, ll n)
{
    ll res = 1;
    while(n)
    {
        if(n % 2 == 1)
            res = (res % mod * x % mod) % mod;
        n = n / 2;
        x = (x % mod * x % mod) % mod;
    }
    return res % mod;
}

ll inverse(ll a, ll b)
{
    return (a % mod * (exp(b, mod - 2) % mod));
}

void factorials()
{
    fact[0] = 1;
    for(int i = 1; i <= 200000; ++i)
        fact[i] = (fact[i - 1] % mod * i) % mod;
    ifact[200000] = inverse(1, fact[200000]);
    for(int i = 199999; i >= 0; --i)
        ifact[i] = (ifact[i + 1] % mod * (i + 1)) % mod;
}

ll ways(ll x1, ll y1, ll x2, ll y2)
{
    ll a = abs(x2 - x1);
    ll b = abs(y2 - y1);
    ll res = fact[a + b] % mod;
    res = (res * ifact[a]) % mod;
    res = (res * ifact[b]) % mod;
    return res; 
}

int main()
{
    factorials();
        ll h, w, n;
        cin>>h>>w>>n;
        ll x, y, start = 0;
        pair<ll, ll> arr[3005];
        for(ll i = 0; i < n; ++i)
        {
            cin>>x>>y;
            arr[start++] = make_pair(x, y);
        }
        arr[start++] = make_pair(h, w);
        sort(arr, arr + start);
        ll way[3005];
        for(ll i = 0; i < start; ++i)
            way[i] = ways(1, 1, arr[i].first, arr[i].second) % mod;

        for(ll i = 0; i < start - 1; ++i)
        {
            for(ll j = i + 1; j < start; ++j)
            {
                if(arr[i].first > arr[j].first or arr[i].second > arr[j].second)
                    continue;
                way[j] -= (way[i] % mod * ways(arr[i].first, arr[i].second, arr[j].first, arr[j].second) % mod) % mod;
                while(way[j] < 0)
                    way[j] += mod;
            }
        }
        cout<<way[start - 1] % mod<<"\n";
    return 0;
}

Measured memory_bytes: 3964
#include<iostream>
#include<cmath>
using namespace std;
double a[10005];
int main()
{
    int n;
    double s,t;
    int ans;
    cin>>n>>s>>t;
    double minn=10000.0;
    for(int i=0;i<n;i++)
    {
        int b;
        cin>>b;
        a[i]=s-0.006*b;
        if(abs(a[i]-t)<minn)minn=min(minn,abs(a[i]-t)),ans=i+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
         int t=1;
        // cin>>t;
         while(t--)
         {
            string a;
             cin>>a;
             ll sum=0;
            for(ll i=0;i<a.size();i++)
            {
                sum+=(a[i]-'0');
            }
            if(sum%9==0){cout<<"Yes";}
            else cout<<"No";
         }

}


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

ll INF = 1e15;

int main() {
  ll N;
  cin >> N;
  vector<ll> p(N);
  vector<ll> v(N);

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

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

  ll len = 1, len_tmp = 1, val = v[0];
  for(int i=1;i<N;i++) {
    if(v[i] > val) {
      len_tmp++;
      val = v[i];
    } else {
      len_tmp = 1;
      val = v[i];
    }
    len = max(len, len_tmp);
  }


  cout << N-len << endl;

}



Measured memory_bytes: 3456
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 100005
#define inf (1ll<<60)
#define rep(i,j,k) for (ll i=j;i<=k;++i)
#define per(i,j,k) for (ll i=j;i>=k;--i)
using namespace std;
inline ll read(){
	char ch=getchar(); ll x=0,f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
ll n,ans;
map<ll,bool> mp;
int main(){
	n=read();
	rep(i,1,n){
		ll x=read();
		if (mp[x]){
			--ans; mp[x]=0;
		}else{
			++ans; mp[x]=1;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 6528
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a;
  int maxa;
  ll ans = 0l;
  for(int i=0; i<n; ++i){
    cin >> a;
    if(a < maxa){
      ans += maxa-a;
    }
    else{
      maxa = a;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
const ll INF=1LL<<60;

int main(){
    
    int H,W,K;cin>>H>>W>>K;
    vector<string> S(H);
    vector<vector<int>> ans(H,vector<int>(W,0));
    for(int i=0;i<H;i++) cin>>S[i];
    
    int now=0,last=-1;
    for(int i=0;i<H;i++){
        bool ok=false;
        for(int j=0;j<W;j++){
            if(S[i][j]=='#'){
                ok=true;
                last=i;
                now++;
                for(int k=j;k>=0;k--){
                    if(ans[i][k]!=0) break;
                    ans[i][k]=now;
                }
            }
        }
        
        if(ok){
            for(int j=W-1;j>=0;j--){
                if(ans[i][j]!=0) break;
                ans[i][j]=now;
            }
        }
    }
    
    for(int j=0;j<W;j++){
        for(int i=0;i<H;i++){
            if(ans[i][j]!=0){
                for(int k=i-1;k>=0;k--){
                    if(ans[k][j]!=0) break;
                    ans[k][j]=ans[i][j];
                }
            }
        }
        
        for(int i=last;i<H;i++){
            ans[i][j]=ans[last][j];
        }
        
    }
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(j) cout<<" ";
            cout<<ans[i][j];
        }
        cout<<endl;
    }
    
    
    
}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> pii;
ll mod=998244353;
int main() {
    int x;
    cin>>x;
    ll ans=0;
    ans+=1000*(x/500);
    x-=500*(x/500);
    ans+=5*(x/5);
    cout<<ans;
    
	return 0;
}

Measured memory_bytes: 256
//author: dazhong_feliks

#include <bits/stdc++.h>
using namespace std;

int main() { 
  int N;
  string S;

  cin >> N >> S;
 
 if(N % 2 != 0)
  cout << "No";

 else{
   string ans = "Yes";
   for(int i=0; i<N/2; i++){
     if(S.at(i) != S.at(i + N / 2)){
     ans = "No";
     break;
   }
 }
  cout << ans << endl;
}
}
     


Measured memory_bytes: 256
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef vector<bool> vbool;
typedef priority_queue<p32> pq32;
typedef priority_queue<p32, vector<p32>, greater<p32> > pq32l;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;



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

	int n, k;
	cin >> n >> k;

	ll h[n];
	forn(i,n) cin >> h[i];

	ll dp[n];

	dp[0] = 0;

	forsn(i,1,n) dp[i] = inf;

	forn(i,n){
		for(int j=1; j<=k && (i+j < n); j++){
			dp[i+j] = min(dp[i+j], dp[i]+abs(h[i] - h[i+j]));
		}
	}


	cout << dp[n-1];


}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    vector<int> G[n];
    vector<int> cnt(n,0);
    P pa[n];
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        pa[i]={a,b};
        G[a].pb(b); G[b].pb(a);
        cnt[a]++; cnt[b]++;
    }
    int maa=0,st=0;
    rep(i,n){
        if(maa<cnt[i]){
            st=i; maa=cnt[i];
        }
    }
    cout << maa << endl;
    
    map<P,int> mp;
    int col[n]; col[st]=-1;
    vector<int> vis(n,0);
    queue<int> q;
    q.push(st); vis[st]=1;
    while(!q.empty()){
        int v=q.front(); q.pop();
        int cnt=1;
        for(int u:G[v]){
            if(vis[u]) continue;
            if(col[v]==cnt) cnt++;
            col[u]=cnt;
            mp[{u,v}]=cnt;
            mp[{v,u}]=cnt++;
            q.push(u); vis[u]=1;
        }
    }
    rep(i,n-1) cout << mp[pa[i]] << endl;
}


Measured memory_bytes: 20480
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second

using namespace std;

ll gcd(ll n1,ll n2){
	if(!n1)return n2;
	if(!n2)return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	base%=mod;
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	ans%=mod;
	return ans;
}
int main()
{
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[0]<<c[0]<<endl;
	return 0;
}


Measured memory_bytes: 764
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ a, b ] <- readInts
	print $ fromMaybe (-1) $ listToMaybe $ do
		i <- [ 1 .. 1000 ]
		guard $ i * 8 `div` 100 == a && i * 10 `div` 100 == b
		return i

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

  ll N;
  cin >> N;
  ll K;
  cin >> K;


  ll tmp = N % K;
  ll ans = min(tmp, abs(tmp - K));
  cout << ans << endl;


  return 0;
};


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n,q,s[100000],t[50000],cnt=0,i,j,key;
  int l,m,r;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]);
  scanf("%d",&q);
  for(j=0;j<q;j++) scanf("%d",&t[j]);

  for(i=0;i<q;i++){
    l=0;
    r=n;
    while(l<r){
      key=t[i];
      m=(l+r)/2;
      if(s[m]==key){
	cnt++;
	break;
      }
      else if(key<s[m]) r=m;
      else l=m+1; 
    }
  }
  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 1184
use std::io::*;
use std::str::FromStr;

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();
  let c = read::<i64>();
  let d = read::<i64>();

  if a + b < c + d {
    println!("Right");
  } else if c + d < a + b {
    println!("Left");
  } else {
    println!("Balanced");
  }
}



Measured memory_bytes: 4352
N,M,X,Y = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

l = max(x)
r = min(y)
if l<r and l<Y and X<r:
    print("No War")
else:
    print("War")


Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(10**7)

alphabets = "abcdefghijklmnopqrstuvwxyz"
a = {c:i for i, c in enumerate(alphabets)}
s = list(input())
n = len(s)
k = int(input())

def f(k, i):
    if i == n - 1:
        k_ = k % 26
        c = s[i]
        shifted = (k_ + a[c]) % 26
        return alphabets[shifted]

    c = s[i]
    diff = 26 - a[c]
    if c != "a" and diff <= k:
        return "a" + f(k-diff, i+1)
    else:
        return c + f(k, i+1)
        

print(f(k, 0))

Measured memory_bytes: 92996
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,f=0;
	cin>>n;
	int a;
	for(int i=1;i<=n;i++){
		cin>>a;
		if(a%2==0)
			if(a%3==0||a%5==0);
			else f=1;
	}
	if(f==0)cout<<"APPROVED";
	else cout<<"DENIED";
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
const Int Inf = 1e17;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

  cin>>n>>s; n=s.size(); int ans=0;
  rep(i,n-1)if(s[i]!=s[i+1])ans++;
  ans++;
  END
}

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

int main() {
  int n; cin>>n;
  ll an[n]; rep(i,n) cin >> an[i];
  ll sn[n+1];
  sn[0]=0;rep(i,n)sn[i+1]=sn[i]+an[i];
  sort(sn,sn+n+1);
  ll cnt=0,total=0;
  rep(i,n){
    if (sn[i+1]==sn[i]) {
      cnt++;
      total += cnt;
    } else {
      cnt=0;
    }
  }
  cout<<total;
}


Measured memory_bytes: 3328
//
//AtCoder Grand Contest 039
//A
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    ll len = SIZEL(s);

    if (count(s.cbegin(), s.cend(), s[0]) == len){
        cout << len*k/2 << endl;
        return 0;
    }

    ll fCnt=0;
    ll lCnt=0;
    REP(i,len){
        if (s[0]==s[i]) fCnt++;
        else break;
    }
    REPD(i,len){
        if (s[len-1]==s[i]) lCnt++;
        else break;
    }

    ll dpCnt=0;
    int c=1;
    char now=s[0];
    FOR(i,1, len){
        if (now==s[i]){
            c++;
        }else{
            dpCnt+=c/2;
            now=s[i];
            c=1;
        }
    }
    if (fCnt%2==1 && lCnt%2==1 && k%2==0) {
        cout << ((dpCnt+1)*k)-1 << endl;
    }else{
        cout << dpCnt*k << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = (a); i <= (b); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 200005;
int n, res[MX], cn[3], f = 0, lvl[2];
vi adj[MX];

void dfs (int u, int l, int p = -1) {
	lvl[l]++;
	for (int v : adj[u])
		if (v != p)
			dfs(v, 1 - l, u);
} 

void go (int u, int l, int x, int y, int p = -1) {
	if (cn[1] && l == x) {
		res[u] = 1;
		cn[1]--;
	} else if (cn[2] && l == y) {
		res[u] = 2;
		cn[2]--;
	}

	for (int v : adj[u])
		if (v != p)
			go(v, 1 - l, x, y, u);
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}

	cn[0] = n / 3;
	cn[1] = (n + 2) / 3;
	cn[2] = (n + 1) / 3;
	
	dfs(1, 0);

	if (cn[1] + cn[2] <= lvl[0]) go(1, 0, 0, 0);
	else if (cn[1] + cn[2] <= lvl[1]) go(1, 0, 1, 1);
	else go(1, 0, 0, 1);

	cn[0] = 3;
	cn[1] = 1;
	cn[2] = 2;

	for (int i = 1; i <= n; i++) {
		cout << cn[res[i]] << " ";
		cn[res[i]] += 3;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 23040
import Data.List

winner :: [(Int,Int)] -> (Int,Int)
winner = foldl1' (\w c -> case snd w `compare` snd c of
                             GT -> w
                             LT -> c
                             EQ -> if fst w > fst c then c
                                                    else w)

main = do
    _ <- getLine
    getContents >>= putStrLn . (\(n,f) -> show n ++ " " ++ show f)
        . winner . map ( (\(n:f:_) -> (n,f)) . map read . words) . lines

Measured memory_bytes: 3816
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
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 ll INF=1LL<<60;

ll w,h,x,y;

int main(){
    cin>>w>>h>>x>>y;
    int ans;
    if(w/2.0==x && h/2.0==y) ans=1;
    else ans=0;
    cout<<fixed<<setprecision(12)<<h*w/2.0<<" "<<ans<<"\n";
    return 0;
}


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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

const double EPS = 1e-9;

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b)))
		return 0;
	return a + b;
}

struct P {
	double x, y;
	P() {};
	P(double x_, double y_) : x(x_), y(y_) { }

	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}

	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}

	P operator * (double d) {
		return P(x * d, y * d);
	}

	P operator / (double d) {
		return P(x / d, y / d);
	}

	bool operator < (const P &p) const {
		return x < p.x + EPS;
	}

	// ??????
	double dot(P p) {
		return add(x * p.x, y * p.y);
	}

	// ??????
	double det(P p) {
		return add(x * p.y, -y * p.x);
	}
};

// ??´?????¨??´????????????
P intersection(P p1, P p2, P q1, P q2) {
	return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}

// ???????????????????????????
bool on_seg(P p1, P p2, P q) {
	return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}


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

struct Line {
	P s, t;
	bool owner;
	bool layer;

	bool operator < (const Line &l) const {
		return s < l.s;
	}
};

void solve() {
	// input
	P a, b;
	cin >> a.x >> a.y >> b.x >> b.y;
	
	int n;
	cin >> n;

	vector<Line> lines(n);
	for (auto &l : lines) {
		cin >> l.s.x >> l.s.y >> l.t.x >> l.t.y >> l.owner >> l.layer;
	}

	// ??????????±???????
	vector<pair<P, Line>> ps;
	for (auto &l : lines) {
		P p = intersection(a, b, l.s, l.t);
		if (on_seg(a, b, p) && on_seg(l.s, l.t, p)) {
			ps.EB(p, l);
		}
	}

	sort(ALL(ps));

	// ??´???????????????
	int cnt = 0;

	if (!ps.size()) {
		cout << cnt << endl;
		return;
	}

	bool current = ps[0].snd.layer ? false : true;
	if (ps[0].snd.owner) {
		current = !current;
	}

	for (int i = 1; i < (int)ps.size(); i++) {
		bool expect = ps[i].snd.layer ? false : true;
		if (ps[i].snd.owner) {
			expect = !expect;
		}

		if (expect != current) {
			current = expect;
			cnt++;
		}
	}
	
	// ??????
	cout << cnt << endl;
}

int main(void) {
	int T;
	cin >> T;

	for (int i = 0; i < T; i++) {
		solve();
	}

	return 0;
}

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

int arr[52];
ll dp[maxi][maxi][maxi*maxi];
int N ,a ;
ll mydp(int index , int cnt , int sum ){
    if(index>N){
        if(cnt>0 && sum%cnt==0 && sum/cnt==a){
            return 1;
        }
        else
            return 0;

    }
    if(dp[index][cnt][sum]!=-1){
        return dp[index][cnt][sum];
    }
    else{
       return dp[index][cnt][sum]=mydp(index+1,cnt,sum)+mydp(index+1,cnt+1,sum+arr[index]);

    }



}

int main(){
  cin >> N >> a;
  for(int i=1;i<=N;i++)
    cin >> arr[i];
  memset(dp,-1,sizeof(dp));
  cout << mydp(1,0 , 0) <<endl;
  return 0;
}


Measured memory_bytes: 57344
def sol(s, p):
	n = len(s)
	cnt = 0
	if p == 2 or p == 5:
		for i in range(n):
			if (s[i] % p == 0):
				cnt += i + 1
	else:
		pre = [0] * (n+2)
		pre[n+1] = 0
		b = 1
		for i in range(n, 0, -1):
			pre[i] = (pre[i+1] + s[i-1] * b) % p
			b = (b * 10) % p
		rec = [0] * p
		rec[0] = 1
		for i in range(n, 0, -1):
			cnt += rec[pre[i]]
			rec[pre[i]] += 1
	return cnt

if __name__ == "__main__":
	n, p = map(int, input().split())
	s = input()
	print (sol([int(i) for i in s], p))

Measured memory_bytes: 48144
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#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 REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 4999999999999999999
#define ALL(n) n.begin(),n.end()

int n, s[114514], sum = 0;
int main(){
	cin >> n;
	REPO(i, n) {
		cin >> s[i];
		sum += abs(s[i - 1] - s[i]);
	}
	sum += abs(s[n]);
	REPO(i, n) {
		cout << sum - abs(s[i - 1] - s[i]) - abs(s[i + 1] - s[i]) + abs(s[i - 1] - s[i + 1]) << endl;
	}
}

Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    N=ii()
    ABC = 'abcdefghij'
    def rec(s, cur_max, d):
        if d==0:
            print(s)
            return
        for i in range(cur_max+1+1):
            rec(s + ABC[i], max(cur_max, i), d-1)
    rec('a', 0, N-1)




main()







Measured memory_bytes: 6448
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  else:
    # For Test
    # N = 4
    # A = [2,10,8,40]
    # N = 4
    # A = [5,13,8,1000000000]
    N = 3
    A = [1000000000,1000000000,1000000000]

  while len(A)>1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for row in A:
      wk = row % minA
      if wk > 0:tempA.append(wk)
    A = tempA
  print(A[0])
  
main()

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define MAX 1000001

ll _sieve_size; // ll is defined as: typedef long long ll;
bitset<MAX> bs; // 10^7 should be enough for most cases
bitset<MAX> used;
vi primes; // compact list of primes in form of vector<int>
void sieve(ll upperbound) { // create list of primes in [0..upperbound]
    _sieve_size = upperbound + 1; // add 1 to include upperbound
    bs.set(); // set all bits to 1
    bs[0] = bs[1] = 0; // except index 0 and 1
    for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
        // cross out multiples of i starting from i * i!
        for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
        primes.push_back((int)i); // add this prime to the list of primes
    }
}

bool prime_factors(int n) {
    vi pfs;
    int pf = 0;
    int pfactor = primes[pf];
    while(pfactor * pfactor <= n) {
        if(n % pfactor == 0) {
            pfs.push_back(pfactor);
            if(used[pfactor]) return true;
            used[pfactor] = 1;
        }
        while(n % pfactor == 0) {
            n /= pfactor;
        }
        pfactor = primes[++pf];
    }
    if (n != 1) {
        pfs.push_back(n);
        if(used[n]) return true;
        used[n] = 1;
    }
    return false;
}

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



int main() {
    sieve(MAX);
    int n;
    cin >> n;
    int a[n];
    bool isPairWise = true;
    for(int i = 0; i < n; i++) cin >> a[i];

    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(prime_factors(a[i])) {
            isPairWise = false;
            break;
        }
    }

    int mcd = a[0];
    for(int i = 1; i < n; i++) {
        mcd = gcd(mcd, a[i]);
    }

    if(isPairWise) {
        cout << "pairwise coprime";
    } else if(mcd == 1) {
        cout << "setwise coprime";
    } else {
        cout << "not coprime";
    }
}

Measured memory_bytes: 7872
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring> 
#include <map>
#include <cmath>
#include <cstdio>
#include <sstream>
#include <stack>
#include <ctime>
#include <string.h>
#include <utility>
#include <cstdlib>
#include <functional>
#include <deque>
#include <list>
#define open_in(n) freopen("n","r",stdin)
#define open_out(n) freopen("n","w",stdout)
#define rep(i,n) for (int i=0;i<n;i++)
#define repw(i,w) for(int i=w;i>0;i--)
#define repn(i,m,n) for (int i=n;i<m;i++)
#define for_all(it,n) for(__typeof((n).begin()) it=(n).begin();it!=(n).end();it++)
#define IT iterator
#define Size(n) (int)((n).size()) 
#define pb push_back
#define mpa make_pair
#define pa pair
#define all(n) (n).begin(),(n).end
#define dump(n) cerr<<#n<<"="<<(n)<<endl 
#define _abs(a) ((a)>0?(a):-(a))
#define inf 1<<32
using namespace std;
template <class t>
	t abs2(const t &x){
		return (x<0?-x:x);
	}
template <class t>	
	t max2(const t &x,const t &y){
		return (x>y?x:y);
	}
template <class t>
	t min2(const t &x,const t &y){
		return (x<y?x:y);
	}
template <class t>
    t gcd(const t &x,const t &y){
	    return x ? gcd(y%x,x) : y;
    }
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef long long ll;
typedef map<int,int> mii;
typedef queue<int> qi;
typedef set<int> si;
int x,a,b;
int main(){
	cin>>x>>a>>b;
	if(_abs(x-a)<_abs(x-b)) cout<<"A"<<endl;
	else cout<<"B"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
static  Scanner sc = new Scanner(System.in);


public static void main(String[] args) {

int N=Integer.parseInt(sc.nextLine());

String[] nyu=sc.nextLine().split(" ");
int[] num=new int[nyu.length];

for(int i=0;i<nyu.length;i++){
num[i]=Integer.parseInt(nyu[i]);
}
Arrays.sort(num);
int min=0;
for(int i=0;i<nyu.length-1;i++){
min+=num[i];
}
if(num[num.length-1]<min)
System.out.println("Yes");
else
System.out.println("No");



}

}




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

using namespace std;

int main() {
	string s;
	int x = 0,maxv=-1;
	int n;
	cin >> n >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') {
			x++;
		}else if (s[i] == 'D') {
			x--;
		}

		if (max(maxv, x) == x) {
			maxv = x;
		}
	}
	if (maxv < 0) maxv = 0;
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = null;

		try {
			sc = new Scanner(System.in);
			//?????????????????????
			int leng = Integer.parseInt(sc.nextLine());
			int[] numBox = new int[leng];

			//??°??????????????????
			String line = sc.nextLine();
			String[] list = line.split(" ");
			//???????????????
			for (int i = 0; i < numBox.length; i++) {
				numBox[i] = Integer.parseInt(list[i]);
			}
			//???????????????????????????
			for (int i2 = 0; i2 < numBox.length; i2++) {

				//??????????????´??°?????????
				int work = numBox[i2];
				//while
				int j = i2 -1;
				while (j >= 0 && numBox[j] > work) {
					numBox[j +1] = numBox[j];
					j--;
				}
				//??\?????????
				numBox[j + 1] = work;
				//???????????????
				for (int i = 0; i < numBox.length; i++) {
					System.out.print(numBox[i]);

					//???????????????????????°???????????\??????
					if (i != numBox.length - 1) {
						System.out.print(" ");
					}
				}
				//??????
				System.out.println("");
			}

		}catch (NumberFormatException e) {
			System.out.println(e);
		} finally {
			if (sc != null) {
				sc.close();
			}
		}
	}

}

Measured memory_bytes: 31644
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	Int temp;
	vector<Int> color(9);
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		temp /= 400;
		if (temp <= 7) {
			color[temp]++;
		}
		else {
			color[8]++;
		}
	}

	Int count = 0;
	for (Int i = 0; i < 8; i++) {
		if (color[i])count++;
	}

	if (count == 0) {
		cout << 1 << " " << color[8] << "\n";
		return 0;
	}
	cout << count << " ";
	cout << count + color[8] << "\n";

}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;
const double eps = 1e-8;

using namespace std;

void solve(){
	int a,b,ans=-1;
	cin>>a>>b;
	for(int i=1;i<=1000;++i){
		double x1 = floor(i*0.08);
		double x2 = floor(i*0.1);
		if(x1==a&&x2==b){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;
void merge(int A[],int n,int left,int mid,int right){
 int n1=mid-left;
 int n2=right-mid;
 for(int i=0;i<n1;i++)L[i]=A[left+i];
 for(int i=0;i<n2;i++)R[i]=A[mid+i];
 L[n1]=R[n2]=SENTINEL;
 int i=0,j=0;
 for(int k=left;k<right;k++){
  cnt++;
  if(L[i]<=R[j]) A[k]=L[i++];
  else A[k]=R[j++];
 }
}
void mergeSort(int A[],int n,int left,int right){
 if(left+1<right){
  int mid=(left+right)/2;
  mergeSort(A,n,left,mid);
  mergeSort(A,n,mid,right);
  merge(A,n,left,mid,right);
 }
}
int main(){
 int A[MAX],n,i;
 cnt=0;
 cin>>n;
 for(i=0;i<n;i++)cin>>A[i];
 mergeSort(A,n,0,n);
 for(i=0;i<n;i++){
  if(i)cout<<" ";
  cout<<A[i];
 }
 cout<<endl;
 cout<<cnt<<endl;
 return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

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

  string s;
  cin>>s;
  int N=s.size();
  reverse(rng(s));
  vector<int>n(N);
  for(int i=0;i<N;i++)n[i]=s[i]-'0';
  vector<vector<ll>>dp(N+1,vector<ll>(2,LONG_MAX/2));
  dp[0][0]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<=9;k++){
        if(j){
          if(k-1>=n[i])dp[i+1][0]=min(dp[i+1][0],dp[i][j]+k-1+abs(k-1-n[i]));
          else dp[i+1][1]=min(dp[i+1][1],dp[i][j]+k-1+10-abs(k-1-n[i])+1);
        }
        else{
          if(k>=n[i])dp[i+1][0]=min(dp[i+1][0],dp[i][j]+k+abs(k-n[i]));
          else dp[i+1][1]=min(dp[i+1][1],dp[i][j]+k+10-abs(k-n[i])+1);
        }
      }
    }
  }

  cout<<min(dp[N][0],dp[N][1])<<endl;
  return 0;
}


Measured memory_bytes: 59804
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    map<string, int> mp;
    for (string x : s) mp[x]++;
    long long ans = 0;
    for (auto p : mp) {
        long long c = p.second;
        ans += c * (c-1) /2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18176