akhauriyash/Code-Regression huggingface dataset:
import collections
n = int(input())
v = input().split(" ")
"""
n = 10000
# v = [_i % 10 for _i in range(n)]
v = [_i for _i in range(n)]
n = 10
v = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
"""
if len(set(v)) == 1:
    print(n // 2)
else:
    odds = v[1::2]
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    evens = v[::2]
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    ans1 = 0
    tmp = max(_o.values())
    ans1 += len(odds) - tmp
    key = r_o[str(tmp)]
    if key in _e.keys():
        _e[key] = 0
    ans1 += len(evens) - max(_e.values())

    ans2 = 0
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    tmp = max(_e.values())
    ans2 += len(evens) - tmp
    key = r_e[str(tmp)]
    if key in _o.keys():
        _o[key] = 0
    ans2 += len(evens) - max(_o.values())

    print(min(ans1, ans2))


Measured memory_bytes: 23908
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define ld long double
#define F first
#define S second
#define mem(v) memset(v,0,sizeof(v))
#define all(v) v.begin(), v.end()
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#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 vll vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define hell 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; 
if (m == 1) {return 0;} 
while (a > 1) { ll q = a / m; ll t = m;  m = a % m, a = t; t = y; y = x - q * y; x = t; } 
if (x < 0) {x += m0;} return x; } 
inline ll add(ll a, ll b) { return (((a >= hell) ? a % hell : a) + ((b >= hell) ? b % hell : b) + hell) % hell; }
inline ll subt(ll a, ll b) { return (a - b + hell) % hell; }
inline ll mult(ll a, ll b) { return (1ll * ((a >= hell) ? a % hell : a) * ((b >= hell) ? b % hell : b)) % hell; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll mylog(ll n,ll b)
{ll i = 1;ll ans = 0;
while(1)
{if(i>n/b){break;} i = i*b;ans++;}return ans;
}
bool compare(const pair<ll,ll> &a,const pair<ll,ll> &b){
if (a.first == b.first)
{return a.second<b.second;} 
return a.first<b.first;
}
bool comparerev(const pair<ll,ll> &a,const pair<ll,ll> &b){
if(a.first == b.first)
{return a.second>b.second;}
return a.first>b.first;
}
int main()
{
    fast
    ll t = 1;
 //   cin>>t;
    while(t--){
    ll n;
    cin>>n;
    ll sum = (n*(n+1))/2;
    ll x = n/3;
    ll y = n/5;
    ll xx = 3*((x*(x+1))/2);
    ll yy = 5*((y*(y+1))/2);
    ll z = n/15;
    ll zz = 15*((z*(z+1))/2);
    sum = sum-xx-yy+zz;
    cout<<sum<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;

void dfs(const Graph &G, int v, int &group_num) {
  seen.at(v) = true; // v を訪問済にする
  group_num++;

  // v から行ける各頂点 next_v について
  for (auto next_v : G.at(v)) {
    if (seen.at(next_v)) continue; // next_v が探索済だったらスルー
    dfs(G, next_v, group_num); // 再帰的に探索
  }
}

int main() {
  // 頂点数と辺数
  int N, M;
  cin >> N >> M;

  // グラフ入力受取
  Graph G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--; // 0-indexed

    G.at(a).push_back(b);
    // 無向グラフの場合は以下を追加
    G.at(b).push_back(a);
  }

  // 頂点 0 をスタートとした探索
  seen.assign(N, false); // 全頂点を「未訪問」に初期化

  int ans = 0;
  for (int i = 0; i < N; i++) {
    // 訪問済みの場合はスキップ
    if (seen.at(i)) { continue; }

    int group_num = 0;
    dfs(G, i, group_num);
    ans = max(ans, group_num);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 23376
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;

    vl v(4);
    rep(i, 4) {
        v[i] = s[i] - '0';
    }

    rep(b, 1<<3) {
        ll now = v[0];
        vector<char> op(3);
        rep(i, 3) {
            if(b & 1<<i) {
                now += v[i+1];
                op[i] = '+';
            }
            else {
                now -= v[i+1];
                op[i] = '-';
            }
        }
        if(now == 7) {
            cout << v[0];
            rep(i, 3) {
                cout << op[i] << v[i+1];
            }
            cout << "=7" << endl;
            re0;
        }
    }
    
    re0;
}

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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

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

const int N = (int)2123, mod = (int)1e9 + 7;

int n;
int ans, dp[N+N][N+N], cnt[N+N][N+N], f[10*N];
void add(int &a,int b){
	a+=b;
	if(a >= mod)
		a-=mod;
}
ll binpow(ll x,ll p){
	ll res = 1;
	while(p){
		if(p&1)
			res = res * x % mod;
		x = x * x % mod;
		p/=2;
	}
	return res;
}
ll inv(ll x){
	x%=mod;
	return binpow(x, mod - 2);
}
ll C(int k,int n){
	return 1ll * f[n] * inv( 1ll * f[k] * f[n-k]) %mod;
}
int main(){    
	f[0] = 1;
	for(int i = 1; i < 10*N; i++)
		f[i] = 1ll * f[i - 1] * i % mod;
	
	cin >> n;
    for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		add(ans, C(a+a,a+a+b+b));
		dp[N-a][N-b]++;
		cnt[N+a][N+b]++;
	}
	ans = mod - ans;
	ans%=mod;
	for(int d = 0; d <= 4*N; d++)
		for(int x = 0; x <= d; x++){
			int y = d - x;
			if(x >= N + N || y >= N + N)
				continue;                
			ans = (ans + 1ll * cnt[x][y] * dp[x][y]) % mod;
			if(x + 1 < N + N)
				add(dp[x + 1][y], dp[x][y]);
			if(y + 1 < N + N)
				add(dp[x][y + 1], dp[x][y]);
		}//

	cout << ans * inv(2) % mod;
	return 0;
}


Measured memory_bytes: 106496
#include<iostream>

using namespace std;

int main(){
  char S[3];
  
  cin >> S;
  
  if(S[0] == S[1] && S[1] == S[2]){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  
  return 0;
}

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

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

    reverse(N.begin(), N.end());
    N += '0';
    int n = N.size();

    const int INF = 1001001001;
    int dp[n+1][2];

    for(int i=0; i<n+1; i++){
        for(int j=0; j<2; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<2; j++){
            int x = N.at(i) - '0';
            x += j;
            for(int a=0; a<10; a++){
                int ni = i+1;
                int nj = 0;
                int b = a - x;
                if(b < 0){
                    nj = 1;
                    b += 10;
                }
                dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b);
            }
        }
    }

    cout << dp[n][0] << endl;

    return 0;
}

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=1e5+5;
lli fact[N], M, a[N], pre[N];

lli binpow(lli a,lli b) 
{
    if (b == 0) return 1;
    lli res = binpow(a,b/2);
    res= (res*res)%M;
    
    if(b%2) return (res*a)%M;
    return res;
}
 
lli inv(lli a)
{
    return binpow(a,M-2);
}

lli add(lli a, lli b)
{
	lli res = a + b;
	if(res >= M)
		return res - M;
	return res;
}
 
lli mul(lli a, lli b)
{
	lli  res = a * b;
	if(res >= M)
		return res % M;
	return res;
}
 
lli sub(lli a, lli b)
{
	return (a%M -b%M +M) %M;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    lli n, x;
    cin>>n>>x>>M;
    lli i, tot = 1, cur = x, ans = 0;
    map<lli ,lli> mp;
    
    while(1)
    {
        if(mp.find(cur) != mp.end())
        {
            lli rem = n - tot + 1;
            lli sz = tot - mp[cur];
            
            lli round = rem / sz;
            ans += (round * (pre[tot-1] - pre[mp[cur] - 1]));
            
            rem -= (round * sz);
            
            for(int i=mp[cur];;i++)
            {
                if(rem == 0)
                    return cout<<ans, 0;
                
                ans += a[i];
                rem--;
            }
        }
        
        mp[cur] = tot;
        a[tot] = cur;
        ans += cur;
        pre[tot] += pre[tot-1] + a[tot];
        
        if(tot == n) 
            return cout<<ans, 0;
            
        tot++;
        cur = mul(cur, cur);
    }
    return 0;
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7
//vvll v(n,vll(m)) n行m列
//A.erase(A.begin()+i) 配列Aのi番目を消せる
//std::binary_search(v.bgn,v.en,a);
//abs(a,b)   pow(a,n)  to_string  stoll
//auto Iter=lower_bound(v.bgn,v.en,a);
//lower//upper  co(*Iter)co(Iter-v.bgn);

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
#define comuse Comuse()
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  str s;
  cin>>s;
  ll n=s.sz;
  vll ans(n,0);
  vll c(5,0);
  FOR(i,0,n){
    if(s[i]=='R'){
      if(c[1]%2==0){
        ans[i-c[1]]+=c[1]/2;
        ans[i-c[1]-1]+=c[1]/2;
      }
      else if(c[1]==1){
        ans[i-c[1]]++;
      }
      else{
        ans[i-c[1]]+=c[1]/2+1;
        ans[i-c[1]-1]+=c[1]/2;
      }
      c[1]=0;
      c[0]++;
    }
    if(s[i]=='L'){
      if(c[0]%2==0){
        ans[i-1]+=c[0]/2;
        ans[i]+=c[0]/2;
      }
      else if(c[0]==1){
        ans[i-1]++;
      }
      else{
        ans[i-1]+=c[0]/2+1;
        ans[i]+=c[0]/2;
      }
      c[0]=0;
      c[1]++;
    }
    //co(ans[0]<<ans[1]<<ans[2]<<ans[3]<<ans[4]);
  }
  if(c[1]%2==0){
    ans[n-c[1]]+=c[1]/2;
    ans[n-c[1]-1]+=c[1]/2;
  }
  else if(c[1]==1){
    ans[n-c[1]]++;
  }
  else{
    ans[n-c[1]]+=c[1]/2+1;
    ans[n-c[1]-1]+=c[1]/2;
  }
  FOR(i,0,n){
    co(ans[i]);
  }
}
  


Measured memory_bytes: 1408
#include <iostream>
#include <set>
using namespace std;
 
int main() {
    int n,q,s,t,i,ans=0;
    cin>>n;
    set<int> S = set<int>();
    for (i=0;i<n;i++) {
        cin>>s;
        S.insert(s);
    }
    cin>>q;
    for (i=0;i<q;i++) {
        cin>>t;
        if (S.count(t)>0) {
            ans++;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7716
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
//typedef __int64 LL;
typedef pair<int,int> P;
const int INF=100000000;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<' '<<b<<' '<<c<<endl;
	return 0;
}

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

using namespace std;

struct Card {
    char suit;
    int value;
};

void bubbleSort(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        for (int j = N - 1; j > i; j--){
            if (A[j].value < A[j-1].value) swap(A[j], A[j-1]);
        }
    }
}

void selectionSort(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j].value < A[minj].value) {
                minj = j;
            }
        }
        swap(A[i], A[minj]);
    }
}

void print(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        if ( i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card A[], struct Card B[], int N) {
    for (int i = 0; i < N; i++) {
        if (A[i].suit != B[i].suit) return false;
    }
    return true;
}

int main(void) {
    Card C1[100], C2[100];
    int N;
    char ch;

    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }

    for (int i = 0; i < N; i++) C2[i] = C1[i];

    bubbleSort(C1, N);

    selectionSort(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if ( isStable(C1, C2, N) ) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }

    return 0;
}


Measured memory_bytes: 3076
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char a,b;
    cin>>a>>b;
    if(a>b){
        cout<<">"<<endl;
    }
    else if(a<b){
        cout<<"<"<<endl;
    }
    else{
        cout<<"="<<endl;
    }
    return 0;

}

Measured memory_bytes: 256
n,m = tuple(int(i) for i in input().split())
A = [[int(j) for j in input().split()] for k in range(n)]
b = [int(input()) for p in range(m)]
R = [sum([A[p][q] * b[q] for q in range(m)]) for p in range(n)]

for r in R:
    print(str(r))


Measured memory_bytes: 6020
from itertools import accumulate

def main():
    def index_from_timer(time):
        hour=int(time[:2])
        minute=int(time[3:5])
        second=int(time[6:8])
        return hour*3600+minute*60+second

    while 1:
        n=int(input())
        if n==0:
            break
        timer=[input() for i in range(n)]
        A=[0 for _ in range(86400)]
        for time in timer:
            start=time[:8]
            end=time[9:]
            A[index_from_timer(start)]+=1
            A[index_from_timer(end)]-=1
        print(max(list(accumulate(A))))
main()


Measured memory_bytes: 10456
x,*c=open(0);n,m=map(int,x.split());o=n-m+1;print("YNeos"[all(any(c[p//o+q//m][p%o+q%m]!=c[n+q//m][q%m]for q in range(m*m))for p in range(o*o))::2])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  ll H,W,ans; cin>>H>>W;
  if(H<W){
    swap(H,W);
  }
  if(W==1){
    ans=1;
  }
  else{
    if(H*W%2){
      ans=H*(W+1)/2-H/2;
    }
    else{
      ans=H*W/2;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    P = [float(v) for v in input().split()]

    dp = [0] * (N + 1)
    dp[0] = 1

    for i, p in enumerate(P):
        p2 = 1 - p
        for j in range(i + 1, -1, -1):
            if j >= 0:
                dp[j] = dp[j] * p2 + dp[j - 1] * p
            else:
                dp[j] = dp[j] * p2

    ldp = len(dp)
    s = ldp - len(dp) // 2

    print(sum(dp[s:]))

main()


Measured memory_bytes: 3316
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <bitset>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = Mint(2).pow(n);
  Mint pow(long long n) const {
    if (n==0) return Mint(1);
    Mint y = pow(n>>1); // pow(n/2)を計算する
    y *= y;
    if (n%2==1) y *= *this;
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return a.pow(mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    Mint one = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= (i + one);
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

int main() {
  int D, T, S;
  std::cin >> D >> T >> S;
  printf("%s\n", (T*S>=D)?"Yes":"No");
  return 0;
}


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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 5;
int a[N];
ll cnt[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n;
    cin >> n;
    forn(i, n) {
        cin >> a[i];
        ++cnt[a[i]];
    }
    ll res = 0;
    forab(i, 1, 200000) {
        res += cnt[i] * (cnt[i] - 1)/2;
    }
    forn(i, n) {
        cout << res - (cnt[a[i]] * (cnt[a[i]] - 1)/2) + (cnt[a[i]] - 1) * (cnt[a[i]] - 2)/2 << "\n";
    }
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}



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

int main(){
  int a, b;
  cin >> a >> b;
  rep(i, 1251){
    int a1 = ( i * 0.08) / 1;
    int a2 = ( i * 0.1 ) / 1;
    if(a1 == a && a2 == b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  
}


Measured memory_bytes: 256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  o=chomp(readline())
  e=chomp(readline())
  for i=1:length(e)
    print(o[i])
    print(e[i])
  end
  if length(o)!=length(e)
    println(o[end])
  else
    println()
  end
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 108284
#include<bits/stdc++.h>
    #define int ll
    #define M 1000000007
    #define hell 998244353
    #define big 1e18
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define mem0(a) memset(a,0,sizeof(a))
    #define memf(a) memset(a,false,sizeof(a))
    #define mem1(a) memset(a,1,sizeof(a))
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    #define endl "\n"
    #define gcd __gcd
    using namespace std;
    int power(int x, unsigned int y, unsigned int m) 
	{ 
    	if (y == 0) 
        	return 1; 
    	int p = power(x, y/2, m) % m; 
    	p = (p * p) % m; 
  
 	   return (y%2 == 0)? p : (x * p) % m; 
	} 
	int modInverse(int a, int m) 
	{   
    	return power(a, m-2, m);
	}
    signed main()
    {
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    	ll t=1;
    	// cin >> t;
    	/*SAARE INPUTS LENA*/
    	/*VARIABLES KI RANGE DEKHLENA*/
    	while(t-->0)
    	{
    		string s1,s2;
    		cin>>s1>>s2;
    		if(s2.length()==(s1.length()+1) && s2.substr(0,s1.length())==s1)
    			cout<<"Yes";
    		else
    			cout<<"No";	
    	}
    	return 0;
    }

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

int main() {
  int N, S, t, m;
  cin >> N;
  S = 0;
  m = 1000000;
  vector<int> W(N);
  for(int i = 0; i < N; i++) {
    cin >> W.at(i);
    S += W.at(i);
  }
  for(int T = 1; T < N; T++) {
    int s = 0;
    for(int i = 0; i < T; i++) {
      s += W.at(i);
    }
    t = S - 2 * s;
    if(t < 0) {
      t *= -1;
    }
    m = min(t, m);
  }
  cout << m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
#define erase(s) s.erase(s.end()-1) //文字列sの末尾削除

ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
string RLE(string s){
  ll n=s.size();
  char now='.';
  ll count=1;
  string press;
  loop(i,n){
    if(s[i]!=now){
      if(i){
        press+=now;
        press+=to_string(count);
      }
      now=s[i];
      count=1;
      continue;
    }
    else count++;
  }
  press+=now;
  press+=to_string(count);
  return press;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  string s;
  cin>>n>>s;
  ll ans=0;
  ll dight[1000][3];
  loop(i,1000){
    ll num=i;
    loop(j,3){
      dight[i][j]=num%10;
      num/=10;
    }
    swap(dight[i][0],dight[i][2]);
    bool check1=false,check2=false,check3=false;
    ll next1,next2;
    loop(j,n)if(ctoi(s[j])==dight[i][0]){
      check1=true;
      next1=j;
      break;
    }
    if(check1)Loop(j,next1+1,n)if(ctoi(s[j])==dight[i][1]){
      check2=true;
      next2=j;
      break;
    }
    if(check2)Loop(j,next2+1,n)if(ctoi(s[j])==dight[i][2]){
      check3=true;
    }
    if(check3)ans++;
  }
  putout(ans);
}

Measured memory_bytes: 384
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

int main(){

    int N,W,ans = 0,sum = 0;
    scanf("%d %d",&N,&W);

    int* dp = new int[W+1];
    int* friends = new int[N+1];

    friends[0] = 0;
    for(int i = 1; i <= N; i++){
        scanf("%d",&friends[i]);
        sum += friends[i];
    }

    sort(friends,friends+(N+1));

    if(sum <= W || W < friends[1]){
        printf("1\n");
        return 0;
    }

    sum = 0;
    for(int i = 1; i <= N; i++){
        sum += friends[i-1];
        if(sum > W)break;

        if(i == N){
            ans = (ans + 1)%MOD;
            break;
        }

        for(int a = 0; a <= W; a++)dp[a] = 0;

        dp[0] = 1;

        for(int a = i+1; a <= N; a++){
            for(int b = W-sum; b >= friends[a]; b--){
                dp[b] = (dp[b] + dp[b-friends[a]])%MOD;
            }
        }

        for(int a = 0; a <= W-sum; a++){
            if(W-sum-a < friends[i]){
                ans = (ans + dp[a])%MOD;
            }
        }
    }

    printf("%d\n",ans%MOD);

    return 0;
}

Measured memory_bytes: 2776
// VSCF.cpp : Defines the entry point for the console application.
//
#include <iomanip>
#include <string>
#include <ctime>
#include <random>
#include <functional>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <set>
#include <deque>
#include <map>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

#define MP make_pair
#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) decltype(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define int long long

#undef int 
int main() {
#define int long long
	int n, l;
	cin >> n >> l;
	vector<int> inp(n);
	REP(i, n) {
		cin >> inp[i];
	}
	int seeked = -1;
	REP(i, n - 1) {
		if (inp[i] + inp[i + 1] >= l) {
			seeked = i;
		}
	}
	if (seeked == -1) {
		cout << "Impossible";
	} else {
		cout << "Possible\n";
		REP(i, seeked) {
			cout << i + 1 << "\n";
		}
		FORD(i, n - 1, seeked + 1) {
			cout << i << "\n";
		}
	}
	return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cerr << x << " ";} cerr << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cerr << x << " ";}cerr << endl;}
#define printP(p) cerr << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

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

    int N, M;
    cin >> N >> M;
    vi num(N, 1);
    vector<bool> red(N);
    red[0] = true;
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        num[x]--;
        num[y]++;
        if (red[x]) red[y] = true;
        if (num[x] == 0) red[x] = false;
    }

    int ans = 0;
    rep(i, N) ans += red[i];
    cout << ans << endl;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
L = {0: 0, 1: 0, 2: 0}
for i in range(n):
    for j in range(3):
        if a[i] % 2 == 1:
            L[j] += 1
            break
        a[i] = a[i] // 2
    else:
        L[2] += 1
L[1] = L[1] % 2
if L[2] >= L[0] + L[1] - 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14252
import sys
sys.setrecursionlimit(10**8)
H = int(input())
D = {1: 1}


def dfs(H):
    if H in D:
        return D[H]

    D[H] = dfs(H//2) + dfs(H//2) + 1
    return D[H]


print(dfs(H))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, k;
    cin >> n >> k;
    vint a(n);
    rep(i, n) cin >> a[i];

    vll sum(n+1, 0);
    rep(i, n) sum[i+1] = sum[i] + a[i];

    vll ls;
    rep(i, n) srep(j, i, n) {
        ls.push_back(sum[j+1] - sum[i]);
    }

    ll ans = 0;
    for (int i = 40; i >= 0; --i) {
        vll ls2;
        ll mask = 1ll << i;
        rep(j, ls.size()) {
            if (mask & ls[j]) ls2.push_back(ls[j]);
        }
        if (ls2.size() >= k) {
            ls = ls2;
            ans += mask;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6388
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l,count1=0;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC133();
}

void ABC133(){
    int n,d,sum=0;
    cin>>n>>d;
    int x[n][d];
    for(i=0;i<n;i++){
        for(j=0;j<d;j++){
            cin>>x[i][j];
        }
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            sum=0;
            for(k=0;k<d;k++){
                sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            for(k=1;k<=1000;k++){
                if(sum==k*k)count1++;
            }
        }
    }
    cout<<count1<<endl;
}

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

int main() {
    string s, t;
    while (getline(cin, t)) s += t;
    int cnt[26] = {};
    for (char c: s) {
        if (islower(c)) cnt[c-'a'] ++;
        else if (isupper(c)) cnt[c-'A'] ++;
    }
    for (int i=0; i<26; ++i) {
        cout << char(i+'a') << " : " << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    set<ll> st;
    ll n;cin>>n;
    for(ll i=0,x;i<n;i++)cin>>x,st.insert(x);
    cout<<(st.size()==n?"YES":"NO");
}




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

long long solve(int N, const vector<int> &a) {
    int iter = 1;
    int res = 0;
    for (int i = 0; i < N; ++i) {
        if (a[i] == iter) ++iter;
    }

    if (iter == 1) return -1;
    else return N - iter + 1;
}

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    cout << solve(N, a) << endl;
}


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

const int N = 200005;
typedef long long ll;


int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string s;
	cin>>s;
	deque<char> dq;
	for(int i=0;i<(int)s.size();i++){
		dq.push_back(s[i]);
	}
	bool rev = false;
	
	int q;
	cin>>q;
	while(q--){
		int t;
		cin>>t;
		if(t == 1){
			rev ^= 1;
		}else{
			int f;
			cin>>f;
			char c;
			cin>>c;
			if(f == 1){
				if(rev) dq.push_back(c);
				else dq.push_front(c);
			}else{
				if(rev)dq.push_front(c);
				else dq.push_back(c);
			}
		}
	}
	
	if(!rev){
		while(!dq.empty()){
			cout<<dq.front();
			dq.pop_front();
		}
	}else{
		while(!dq.empty()){
			cout<<dq.back();
			dq.pop_back();
		}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 4064
#include<stdio.h>
int main()
{
    int a,b;
    // 整数の入力
    scanf("%d %d", &a,&b);
    int add,sub,mul,max;
    add = a+b;
    sub = a-b;
    mul = a*b;
    if(b>0){
        if(add>mul){
            max=add;
        }else{
            max=mul;
        }
    }else{
        if(sub>mul){
            max=sub;
        }else{
            max=mul;
        }
    }
    // 出力
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int count = 0;
        if(A+B>2*C){
            if(X>=Y){
                if(A>=2*C){
                    count = 2*C*X;
                }else{
                    count = 2*C*Y + A*(X-Y);
                }
            }else{
                if(B>=2*C){
                    count = 2*C*Y;
                }else{
                    count = 2*C*X + B*(Y-X);
                }
            }
        }else{
            count = A*X+B*Y;
        }
        
          System.out.println(count);
        }
    }


Measured memory_bytes: 35892
#include <stdio.h>
#include <string.h>

int main()
{
	long int a,b,c;
	scanf("%ld",&a);
	int i;
	scanf("%d",&i);
	int j;
	long int  sum =0;
	long int  ar[i];
	for(j=0;j<i;j++)
	{	
		scanf("%ld", &ar[j] );
		sum=sum+ar[j];

	}
	if(sum>=a)
	{
		printf("Yes");
	}
	else
		printf("No");

	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> N >> K;
	for (int b = K + 1; b <= N; b++) {
		int x = (N - K) / b;
		ans += (b - K)*x;
		if ((x+1)*b - 1 <= N)ans += b - K;
		else ans += N - (x*b + K) + 1;
	}
	if (K == 0)ans = N * N;
	cout << ans << endl;
}

Measured memory_bytes: 256
import collections
MOD = 10**9 + 7

N = int(input())
A = input().split(' ')
flag = False
c = collections.Counter(A)


if c.most_common()[0][1] > 2:
    flag = True
if N % 2 == 1:
    if not c.most_common()[-1][0] == '0':
        flag = True
if flag:
    print(0)
    exit()

if N % 2 == 0:
    ans = pow(2, N//2, MOD)
else:
    ans = pow(2, (N-1)//2, MOD)
print(ans)


Measured memory_bytes: 18028
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int n; cin >> n;
    for (int i = 0; i <= n/4; i++) {
        for (int j = 0; j <= n/7; j++) {
            if (4*i + 7*j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

class P
{
    static void Main()
    {
        int[] NL = Console.ReadLine().Split().Select(int.Parse).ToArray();
        string[] S = new string[NL[0]].Select(_ => Console.ReadLine()).OrderBy(x => x).ToArray();
        string res = "";
        foreach (var s in S)
        {
            res += s;
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 11616
#include<bits/stdc++.h>
#define S 2500005
#define N 1005
using namespace std;
typedef pair<int,int> P;
struct d{
  int a,b,c;
  d(){}
  d(int A,int B,int C){
    a=A,b=B,c=C;
  };
  bool operator<(const d&r)const{
    if(a!=r.a)return a<r.a;
    return b<r.b;
  }
};

int n,slen,tlen,r[S];
char s[S],t[N];
d ran[S];
P a[S];

void init(){
  for(int i=0;i<slen;i++)r[i]=s[i];
  int x=1;
  r[slen]=0;
  while(x<slen){
    for(int i=0;i<slen;i++){
      int o=i+x;
      if(o>slen)o=slen;
      ran[i]=d(r[i],r[o],i);
    }
    sort(ran,ran+slen);
    int cnt=1;
    for(int i=0;i<slen;i++){
      r[ran[i].c]=cnt;
      if(ran[i].a==ran[i+1].a&&ran[i].b==ran[i+1].b)
	continue;
      cnt++;
    }
    //    if(x>slen)break;
    x*=2;
  }
  for(int i=0;i<slen;i++)a[i]=P(r[i],i);
  sort(a,a+slen);
}

bool bynary_search(){
  int L=0,R=slen;
  while(L<R){
    int M=(L+R)/2;
    if(strncmp(s+a[M].second,t,tlen)<0)L=M+1;
    else R=M;
  }
  if(!strncmp(s+a[L].second,t,tlen))return true;
  return false;
}

int main(){
  scanf("%s%d",s,&n);
  slen=strlen(s);
  init();  
  while(n--){
    scanf("%s",t);
    tlen=strlen(t);
    if(bynary_search())printf("1\n");
    else printf("0\n");
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

const int MAXN = 16;

int N;
ll a[MAXN][MAXN], group[1 << MAXN], dp[1 << MAXN];

int unpack(int mask, int popcount, int packed) {
    int result = 0;
    for (int i = 0; i < popcount; i++) {
        if (packed & (1 << i))
            result |= 1 << __builtin_ctz(mask);
        mask &= mask - 1;
    }
    return result;
}

ll score(int mask) {
    if (dp[mask] == -1) {
        dp[mask] = group[mask];
        int popcount = __builtin_popcount(mask);
        for (int packed = 1; packed < (1 << popcount); packed++) {
            int submask = unpack(mask, popcount, packed);
            if ((mask | submask) == mask)
                dp[mask] = max(dp[mask], group[submask] + score(mask & ~submask));
        }
    }
    return dp[mask];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            cin >> a[i][j];
    for (int mask = 0; mask < (1 << N); mask++)
        for (int i = 0; i < N; i++)
            for (int j = i + 1; j < N; j++)
                if ((mask & (1 << i)) && (mask & (1 << j)))
                    group[mask] += a[i][j];
    memset(dp, -1, sizeof dp);
    cout << score((1 << N) - 1) << endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int main()
{
    int n,m;
    cin>>n>>m;
    char a[n][m];
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>a[i][j];
    ll dp[n][m];
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) dp[i][j]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(a[i][j]=='.')
            {
                if(i==0&&j==0) dp[0][0]=1;
                else if(i==0)
                {
                    dp[i][j]=dp[i][j-1];
                }
                else if(j==0)
                {
                    dp[i][j]=dp[i-1][j];
                }
                else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
    }
    cout<<dp[n-1][m-1];
    
}

Measured memory_bytes: 9088
/*Author : Prokash
           JU CSE 48
           CF: epiprokash
           UVa: epiprokash
*/

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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,d=1,i=5,cnt=0;
    cin>>a;
    if(a%2==1)
    {
        cout<<0<<endl;
    }
    else
    {
        while(d!=0)
        {
            d=a/(i);
            i*=5;
            cnt+=(d/2);
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 10;
int N, K, last[2], first[2];
LL A[maxn], ans;
bool cmp(const LL &x, const LL &y)
{
    return abs(x) > abs(y);
}
LL qpow(LL a, LL b)
{
    LL res = 1;
    a %= MOD;
    while(b)
    {
        if(b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
int main()
{
    scanf("%d %d", &N, &K);
    bool has_pos = false;
    for(int i = 1; i <= N; i++)
    {
        scanf("%lld", &A[i]);
        if(A[i] > 0)
            has_pos = true;
    }
    sort(A + 1, A + N + 1, cmp);
    if(!has_pos && K % 2 != 0)
    {
        ans = 1;
        for(int i = N; i >= N - K + 1; i--)
            ans = ans * A[i] % MOD;
        printf("%lld\n", (ans % MOD + MOD) % MOD);
        return 0;
    }
    int cnt = 0, flag = 0;
    ans = 1;
    for(int i = 1; i <= K; i++)
    {
        ans = (ans * A[i]) % MOD;
        if(A[i] == 0)
            flag = 1;
        else if(A[i] < 0)
            cnt++;
    }
    while(A[N] == 0 && N > K)
        N--;
    if(flag == 1 || cnt % 2 == 0 || N == K)
    {
        printf("%lld\n", (ans % MOD + MOD) % MOD);
        return 0;
    }
    for(int i = 1; i <= K; i++)
    {
        if(A[i] > 0)
            last[0] = i;
        else
            last[1] = i;
    }
    for(int i = N; i >= K + 1; i--)
    {
        if(A[i] > 0)
            first[0] = i;
        else
            first[1] = i;
    }
    if((last[0] && first[1]) && !first[0])
        ans = ans * qpow(A[last[0]], MOD - 2) % MOD * A[first[1]] % MOD;
    else if(!(last[0] && first[1]) && first[0])
        ans = ans * qpow(A[last[1]], MOD - 2) % MOD * A[first[0]] % MOD;
    else
    {
        if(abs(A[last[0]]) * abs(A[first[0]]) < abs(A[last[1]]) * abs(A[first[1]]))
            ans = ans * qpow(A[last[0]], MOD - 2) % MOD * A[first[1]] % MOD;
        else
            ans = ans * qpow(A[last[1]], MOD - 2) % MOD * A[first[0]] % MOD;
    }
    printf("%lld\n", (ans % MOD + MOD) % MOD);
    return 0;
}


Measured memory_bytes: 5360
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


Int N;
vector<Int> used;
vector<P> A;

Double calc(Int x, Int y, Int a, Int b){
  return sqrt((Double)((x - a) * (x - a) + (y - b) * (y - b)));
}


Double sum;
void dfs(Int x, Int y, Double dis){
  Int f = 1;
  for(Int i=0;i<N;i++){
    if(used[i]) continue;
    f = 0;
    Int nx, ny; tie(nx, ny) = A[i];
    used[i] = 1;
    dfs(nx, ny, dis + calc(x, y, nx, ny));
    used[i] = 0;
  }
  if(f) sum += dis;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>N;
  A.resize(N);
  cin>>A;
  used.resize(N);

  for(Int i=0;i<N;i++){
    Int sx, sy; tie(sx, sy) = A[i];
    used[i] = 1;
    dfs(sx, sy, 0);
    used[i] = 0;
  }

  Double all = 1;
  for(Int i=0;i<N;i++) all *= (i + 1);
  Double ans = sum / all;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n,m=map(int,input().split())
ans=0;wrong=0
d=[0]*n
for i in range(m):
    p,s=input().strip().split()
    p=int(p)-1
    if d[p]!=-1:
        if s=='WA':
            d[p]+=1
        else:
            wrong+=d[p]
            d[p]=-1
            ans+=1
print(ans,wrong)


Measured memory_bytes: 74680