akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
//#define INF 1145141919810893//810114514
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int long long 


signed main(){
    int N;
    int F;
    cin >> N;
    for(int h=1;h<=3500;h++){
        for(int n=1;n<=3500;n++){
            if(4*h*n-N*h-N*n==0)continue;
            F=(N*h*n)/(4*h*n-N*h-N*n);
            if(F<=0)continue;
            if(4*h*n*F == N*(h*n+h*F+n*F) && 1<=F && F<=3500){
                cout << h <<" "<< n <<" "<< F << endl;
                return 0;
            }
        }
    }
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  int i=0, c=0;
  
  while(i<S.size()-1) {
    if(S.at(i)!=S.at(i+1)) {
      c+=2;
      if(i+2<S.size())
        S=S.substr(0,i)+S.substr(i+2);
      else
        S=S.substr(0,i+1);
      if(i!=0 && S.at(i)!=S.at(i-1))
      	i--;
    } else
      i++;
  }
  
  cout << c << endl;
}

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

using namespace std;

#define ll long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int(x.size()))

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;

const long long N = 200001, P = 1e9 + 7, P1 = 1e9 + 13, iINF = 1e9, INF = 2e18, K = 73, K1 = 79;

ll _bp(ll val, ll st, ll p) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2, p);
    temp = temp * temp;
    temp %= p;
    if (st % 2 == 1) {
        temp *= val;
        temp %= p;
    }
    return temp;
}

ll _bp(ll val, ll st) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2);
    temp = temp * temp;
    if (st % 2 == 1) {
        temp *= val;
    }
    return temp;
}

ll fact[1001000];

void buildFacts(ll n, ll p) {
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}

ll C(ll n, ll k, ll p = -1) {
    if (p == -1) {
        ll x = fact[n];
        ll y = (fact[k] * fact[n - k]);
        return (x / y);
    } else {
        ll x = fact[n];
        ll y = (fact[k] * fact[n - k]) % p;
        x = (x * _bp(y, p - 2, p)) % p;
        return x;
    }
}

void solve() {
    ll n;
    cin >> n;
    buildFacts(n + 1, P);
    ll ans = 0;
    for (int i = 2; i <= n; i++) {
        ans += ((((C(n, i, P) * ((_bp(2ll, i, P) - 2 + P) % P)) % P) * _bp(8ll, n - i, P)) % P);
        ans %= P;
    }
    cout << ans << "\n";
}

signed main() {
    int q = 1;
    while (q--) {
        solve();
    }
}


Measured memory_bytes: 11352
#include "bits/stdc++.h"
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 REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

bool comp(P a, P b) {
	return a.second < b.second;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> vp;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		vp.push_back(P(a, b));
	}

	sort(vp.begin(), vp.end(), comp);

	int res = 0;
	int end = 0;
	rep(i, m) {
		if (vp[i].first >= end) {
			end = vp[i].second;
			res++;
		}
	}

	out(res);

	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <limits>
#include <iomanip>
#include <map>

using namespace std;

int main(){
	int k,n,s;
	
	cin >> n >> k >> s;
	
	for(int i=0;i<k;i++){
		cout << s << ' ';
	}
	
	for(int i=0;i<n-k;i++){
		if(s == 1000000000){
			cout << 999999999 << ' ';
		}else cout << 1000000000 << ' ';
	}
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second
#define _GLIBCXX_DEBUG

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cout << v[i] << ' ';
	}
	cout << endl;
}
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }


int main(){
	int n; cin >> n;
	vector<int> zero(60,0);
	vector<int> one(60,0);
	Rep(n){
		ll a; cin >> a;
		rep(i,60){
			if(a >> i & 1) one[i]++;
			else zero[i]++;
		}
	}
	mint tei(1);
	mint ans;
	rep(i,60){
		ans += tei * zero[i] * one[i];
		tei *= 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
def solve():
  ans = 0
  N = int(input())
  A = []
  for i in range(N):
    x,y = map(int, input().split())
    A.append([x+y,x,y])
  A.sort(reverse=True)
  for i in range(N):
    if i%2==0:
      ans += A[i][1]
    else:
      ans -= A[i][2]
  return ans
print(solve())

Measured memory_bytes: 89428
#include<iostream>
using namespace std;
int main()
{
int A,B;
cin>>A>>B;
A=(A+11)%13;
B=(B+11)%13;
if (A>B) cout<<"Alice";
if (A<B) cout<<"Bob";  
if (A==B) cout<<"Draw";
system("pause");
return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int i=1;
    while(1){
        int x=i;
        if(x%3==0){
            cout<<" "<<i;
        }
        else{
            while(1){
                if(x%10==3){
                    cout<<" "<<i;
                    break;
                }
                x/=10;
                if(x==0)break;
            }
        }
        if(++i>n)break;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

using P=complex<double>;
using ld=double;
constexpr double eps=1e-9;
ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }
template <class iter>
std::pair<complex<double>, double> min_ball(iter left, iter right, int seed = 1333) {
    const int n = right - left;

    assert(n >= 1);
    if (n == 1) {
        return {*left, ld(0)};
    }

    std::mt19937 mt(seed);
    std::shuffle(left, right, mt);
    // std::random_shuffle(left, right); // simple but deprecated

    iter ps = left;
    using circle = std::pair<P, ld>;

    auto make_circle_3 = [](const P &a, const P &b, const P &c) -> circle {
        ld A = std::norm(b - c), B = std::norm(c - a), C = std::norm(a - b),
           S = cross(b - a, c - a);
        P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
        ld r2 = std::norm(p - a);
        return {p, r2};
    };

    auto make_circle_2 = [](const P &a, const P &b) -> circle {
        P c = (a + b) / (ld)2;
        ld r2 = std::norm(a - c);
        return {c, r2};
    };

    auto in_circle = [](const P &a, const circle &c) -> bool {
        return std::norm(a - c.first) <= c.second + eps;
    };

    circle c = make_circle_2(ps[0], ps[1]);

    // MiniDisc
    for (int i = 2; i < n; ++i) {
        if (!in_circle(ps[i], c)) {
            // MiniDiscWithPoint
            c = make_circle_2(ps[0], ps[i]);
            for (int j = 1; j < i; ++j) {
                if (!in_circle(ps[j], c)) {
                    // MiniDiscWith2Points
                    c = make_circle_2(ps[i], ps[j]);
                    for (int k = 0; k < j; ++k) {
                        if (!in_circle(ps[k], c)) {
                            c = make_circle_3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

int main(){
    int N;cin>>N;
    vector<complex<double>> pos(N);
    REP(i,N){
        int x,y;
        cin>>x>>y;
        pos[i]=complex<double>(x,y);
    }
    printf("%.16f\n",sqrt(min_ball(All(pos)).second));

}

Measured memory_bytes: 256
h,w=map(int,input().split())
from collections import defaultdict
data=defaultdict(int)
check=[(-1,0),(1,0),(0,-1),(0,1)]
for y in range(h):
    line=input()
    for x in range(w):
        if line[x]=='.':data[(y,x)]=-1
        if line[x]=='#':
            for (i,j) in check:
                if data[(y+i,x+j)]!=-1:
                    data[(y+i,x+j)]+=1
ans=0            
for y in range(h):
    for x in range(w):
        if data[(y,x)]==0:ans+=1
if ans==0:print('Yes')
elif ans>0:print('No')

Measured memory_bytes: 3700
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class a{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        int ans = 9;
        n -= 400;
        while(n >= 0){
            ans--;
            n -= 200;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 17580
#include<stdio.h>
int main(){long long int a,b,c,d,j,g[5],max;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    g[0]=a*c;
    g[1]=a*d;
    g[2]=b*c;
    g[3]=b*d;
    max=g[0];
    for(j=0;j<4;j++)
    {
        if(max<g[j])
        max=g[j];
    }
    printf("%lld",max);
    return 0;
}

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

int a[1000000];
int n,cnt;
vector<int> G;

void insertionsort(int *a,int g){
  for(int i = g; i < n; i++){
    int v = a[i];
    int j = i-g;
    while(j >= 0 && a[j] > v){
      a[j+g] = a[j];
      j -= g;
      cnt++;
    }
    a[j+g] = v;
  }
}

void shellsort(int *a){
  for(int h = 1; ; ){
    if(h > n) break;
    G.push_back(h);
    h = 3*h + 1;
  }

  for(int i = G.size()-1; i >= 0; i--){
    insertionsort(a,G[i]);
  }
}


signed main(){

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

  shellsort(a);
  cout << G.size() << endl;
  for(int i = G.size()-1; i >= 0; i--){
    cout << G[i];
    if(i) cout << " ";
  }
  cout << endl << cnt << endl;
  for(int i = 0; i < n; i++){
    cout << a[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 10980
#numpy使い、ループが2→１にする
import numpy as np
#初期入力
H,W = (int(x) for x in input().split())
map1 =[ list(input()) for i in range(H)]
map_np =(np.array(map1)==".")*1

L =np.zeros((H,W),dtype=int)
R =np.zeros((H,W),dtype=int)
U =np.zeros((H,W),dtype=int)
D =np.zeros((H,W),dtype=int)

L[:,0] =map_np[:,0]
for i in range(1,W): # if map_np[i,j] ==1: ⇒ *map_npで１or０をかけてるから不要
    L[:,i] = (L[:,i-1] +1) *map_np[:,i]

R[:,W-1] =map_np[:,W-1]
for i in range(W-1-1,-1,-1):
    R[:,i] = (R[:,i+1] +1) *map_np[:,i]

U[0,:] =map_np[0,:]
for i in range(1,H):
    U[i,:] = (U[i-1,:] +1) *map_np[i,:]

D[H-1,:] =map_np[H-1,:]
for i in range(H-1-1,-1,-1):
    D[i,:] = (D[i+1,:] +1) *map_np[i,:]
    
ans =L +R +U +D -3
print(np.max(ans))

Measured memory_bytes: 266580
# -*- coding: utf-8 -*-

"""
しゃくとり法
・前にやったのとか参考にして自力実装
"""
 
N = int(input())
aN = list(map(int, input().split()))

l,r,ans = 0,0,0
sm = xor = 0
# 外ループで左を動かす
while l < N:
    # 内ループは条件を満たす限り右を動かす
    while r < N and sm + aN[r] == xor ^ aN[r]:
        sm += aN[r]
        xor ^= aN[r]
        r += 1
    # 左右の差分が、今の左位置からうまくいった合計になる
    ans += r - l
    # 左を動かす分、合計から引く
    sm -= aN[l]
    xor ^= aN[l]
    l += 1
print(ans)


Measured memory_bytes: 23560
import bisect
N,Q = map(int, input().split())
L = [0]*Q
L1 = []
L2 = []
for i in range(Q):
    a,b = map(int, input().split())
    L[i] = (a, b)
    if a == 1:
        L1.append(b)
    else:
        L2.append(b)

L1.sort()
L2.sort()
M1 = len(L1)
M2 = len(L2)
ans = (N-2)**2
up = N
left = N
for l in L:
    a = l[0]
    b = l[1]
    if a == 1:
        if b > left:
            continue
        idx = bisect.bisect_left(L1, b)
        ans -= (M1-idx)*(up-2)
        M1 = idx
        left = b
    else:
        if b > up:
            continue
        idx = bisect.bisect_left(L2, b)
        ans -= (M2-idx)*(left-2)
        M2 = idx
        up = b
print(ans)

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll C[105][105];

int main() {
    ll N, M;
    cin >> N >> M;
    REP(i, N) {
        REP(j, N) {
            C[i][j] = INF;
        }
        C[i][i] = 0;
    }
    REP(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        C[a][b] = c;
    }

    REP(k, N) {
        REP(i, N) {
            REP(j, N) {
                if (C[i][k] == INF || C[k][j] == INF)
                    continue;
                C[i][j] = std::min(C[i][j], C[i][k] + C[k][j]);
            }
        }
    }

    bool cycle = false;
    REP(i, N) {
        if (C[i][i] < 0)
            cycle = true;
    }

    if (cycle)
        cout << "NEGATIVE CYCLE" << endl;
    else {
        REP(i, N) {
            REP(j, N) {
                if (C[i][j] == INF)
                    cout << "INF";
                else
                    cout << C[i][j];

                if (j < N - 1)
                    cout << " ";
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3192
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,ans=1; cin>>n; 
    map <int,int> cnt;
    int r=n/2;
    for (int i=0;i<n;i++){
      int a; cin>>a;
      cnt[a]++;
    }
    int x=1;
    if (n&1) {
        x=2; 
        if (cnt[0]!=1) ans=0;
    }
    for (int i=x;i<=n;i+=2) if (cnt[x] != 2) ans=0;
    for (int i=1;i<=r;i++){
        ans = (ans*2)%1000000007;
    }
    printf("%lld\n",ans);
    return;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 7624
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($i = 0; $i < $H; $i++){
  $str = trim(fgets(STDIN));
  for($j = 0; $j < $W; $j++){
    $map[$i][$j] = $str[$j];
    $p[$i][$j] = 0;
  }
  $map[$i][$W] = "#";
}
for($j = 0; $j < $W; $j++){
  $map[$H][$j] = "#";
}
for($i = 0; $i < $H; $i++){
  $h = 0;
  for($j = 0; $j < $W+1; $j++){
    if($map[$i][$j] == "#"){
      for($k = 0; $k < $h; $k++){
        $p[$i][$j - 1 - $k] = $h;
      }
      $h = 0;
    }else{
      $h++;
    }
  }
}
for($i = 0; $i < $W; $i++){
  $h = 0;
  for($j = 0; $j < $H+1; $j++){
    if($map[$j][$i] == "#"){
      for($k = 0; $k < $h; $k++){
        $p[$j - 1 - $k][$i] += $h;
      }
      $h = 0;
    }else{
      $h++;
    }
  }
}
$max = 0;
for($i = 0; $i < $H; $i++){
  $max = max($max, max($p[$i]));
}
echo $max - 1;


Measured memory_bytes: 401912
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin >> k;
    string s; cin >> s;
    if(k >= s.length()) cout << s;
    else cout << s.substr(0, k) + "...";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3536
/*
 * yaswanth phani kommineni
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';

void solve(){
	int x;
	cin >> x;
	cout << (x^1) << endl;
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int z;
	z = 1;
	//cin >> z;
	for(int z1=1;z1<=z;z1++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3620
import java.io.*;

class Main{
  public static void main(String[] args) throws Exception{
   int x, ans;
   
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   x = Integer.parseInt(br.readLine());

   ans = x*x*x;
   System.out.println(ans);
  }
}

Measured memory_bytes: 24072
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
A=sorted(a)
shokou=[]
kousa=[]
m=10**9+7
for i in range(n):
  ct=0
  for j in range(i+1,n):
    if a[i]>a[j]:ct+=1
  shokou.append(ct)
for i in range(n):
  kousa.append(A.index(a[i]))
ans=0
S=0
for i in range(n):
  S=(k*(2*shokou[i]+(k-1)*kousa[i]))//2
  S%=m
  ans+=S
print(ans%m)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int d;
  cin >> d;
  if(d == 25)
    cout << "Christmas";
  else if(d == 24)
    cout << "Christmas Eve";
  else if(d == 23)
    cout << "Christmas Eve Eve";
  else if(d == 22)
    cout << "Christmas Eve Eve Eve";
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<bool> dp(2 * k, false);  // true: First, false:Second
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j < n; j++) dp[i + a[j]] = dp[i + a[j]] || (!dp[i]);
  }
  cout << (dp[k] ? "First" : "Second");
  return 0;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   int n;
   cin>>n;
   int a[200000];

   int mm[200000]={0};
   ll ans=0;
   rep(i, n){
      int a;
      cin>>a;
      if(i-a>=0){
         ans+=mm[i-a];
      }
      if(i+a<n){
         mm[i+a]++;
      }
   }

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


Measured memory_bytes: 4384
#include <cstdio>
#include <vector>
#define maxn 110
#define INF 1e8
using namespace std;
int n,m,f[maxn][maxn],ans;
struct edge {
    int to,ca;
};
vector<edge> map[maxn];
int main() {
    scanf("%d %d",&n,&m);
    for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			f[i][j]=INF;
    for (int i=1;i<=m;i++) {
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		edge x; x.to=b; x.ca=c;
		map[a].push_back(x);
		x.to=a;
		map[b].push_back(x);
		f[a][b]=c; f[b][a]=c;
    }
    for (int i=1;i<=n;i++)
		f[i][i]=0;
    for (int k=1;k<=n;k++)
		for (int i=1;i<=n;i++)
			for (int j=1;j<=n;j++)
				if (i!=j&&f[i][k]+f[k][j]<f[i][j]) {
					f[i][j]=f[i][k]+f[k][j];
				}
    ans=0;
    for (int i=1;i<=n;i++) {
		for (int j=0;j<map[i].size();j++) {
			bool T=false;
			for (int s=1;s<=n;s++) {
				for (int t=s+1;t<=n;t++)
				if (f[s][t]==f[s][i]+f[map[i][j].to][t]+map[i][j].ca
				||f[s][t]==f[s][map[i][j].to]+f[i][t]+map[i][j].ca) {
					T=true;
					break;
				}
				if (T)
					break;
			}
			if (!T) {
				ans++;
			}
		}
    }
    printf("%d\n",ans/2);
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	long int S;
	scanf("%ld",&S);
	int x_1 = 0;
	int y_1 = 0;
	int x_2 = 1000000000;
	int y_2 = 1;
	int x_3 = (x_2-S%x_2)%x_2;
	int y_3 = (x_3+S)/x_2;
	
	printf("%d %d %d %d %d %d",x_1,y_1,x_2,y_2,x_3,y_3);
	return 0;
}


Measured memory_bytes: 128
read n a b
read -d ""
ans1=`echo "${REPLY}" | sort | awk -v AA=$a '{if($1<AA)print $1}' | grep -v "^$" | wc -l`
ans2=`echo "${REPLY}" | sort | awk -v BB=$b '{if($1>=BB)print $1}' | grep -v "^$" | wc -l`
echo $((ans1 + ans2))


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

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n, s[1100], ans = INF;
int main() {
	cin >> n;
	REP(i, n) {
		cin >> s[i];
	}
	FOR(i,-200, 200) {
		ll now = 0;
		REP(j, n) {
			now += abs(i - s[j]) * abs(i - s[j]);
		}
		ans = min(ans, now);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    map<int, int> mp;
    ll ans = 0;
    rep(i,n){
        int t;cin>>t;
        ans += mp[i+1-t];
        mp[i+1+t]++;
    } 
    cout<<ans<<endl;

}

Measured memory_bytes: 21028
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

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

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 




/*****************************************************************************/

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

	int n;
	cin >> n;
	vvi a(n, vi(3));
	f(i, 0, n) {
		f(j, 0, 3) {
			cin >> a[i][j];
		}
	}
	vvi dp(n + 1, vi(3,0));
	f(i, 0, n) {
		f(j, 0, 3) {
			f(k, 0, 3) {
				if (k == j)continue;
				dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][j]);
			}
		}
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
	return 0;
}

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

int main(){
	int n,k;
	int mini = 1E9;
  	cin >>n>>k;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
  	sort(a.begin(), a.end());
  	for(int i = 0; i <= n-k; i++) {
      	if(a[k-1+i] - a[i] < mini)
          	mini  = a[k-1+i] - a[i];
    }
	cout << mini << endl;
	
}


Measured memory_bytes: 640
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var V = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var C = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Console.WriteLine(V.Zip(C, (v, c) => v - c).Where(s => s > 0).Sum());
        }
    }
}


Measured memory_bytes: 28320
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
vector<int> graph[100001];

int dists[100001];
int distsv[100001];
int deps[100001];
void dfs(int node, int par, int dist){
    dists[node] = dist;
    for (int i : graph[node]){
        if (i == par){
            continue;
        }
        dfs(i, node, dist+1);
    }
}
int dfs2(int node, int par, int dist){
    distsv[node] = dist;
    int maxdep = 0;
    for (int i : graph[node]){
        if (i == par){
            continue;
        }
        maxdep = max(maxdep, dfs2(i, node, dist+1));
    }
    deps[node] = maxdep;
    return maxdep+1;
}
int main ()
{
  prep();
  int n, u, v;
  cin >> n >> u >> v;
  for (int i=0; i<n-1; i++){
      int a, b;
      cin >> a >> b;
      graph[a].push_back(b);
      graph[b].push_back(a);
  }
  // all paths from u to other
  dfs(u, -1, 0);
  // all paths from node to rooted
  dfs2(v, -1, 0);
  int maxest = 0;
  for (int i=1; i<=n; i++){
      if (dists[i] >= distsv[i]){
          continue;
      }
      
      maxest = max(maxest, distsv[i]+deps[i]-1);
  }
  cout << maxest;
  return 0; 
}

Measured memory_bytes: 13312
a = 2, 3, 5

def f(n):
  m = memo.get(n)
  if m is None:
    m = d * n
    for p, c in zip(a, b):
      m = min(m, *(f(k) + abs(p * k - n) * d + c for k in (n // p, -(-n // p))))
    memo[n] = m
  return m

t = int(input())
for _ in range(t):
  n, *b, d = map(int, input().split())
  memo = {0: 0, 1: d}
  print(f(n))


Measured memory_bytes: 10960
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);
	int menu[30] = {0};
	for (int i = 0; i < N; i++) {
		int K;
		scanf("%d", &K);
		for (int i = 0; i < K; i++) {
			int A;
			scanf("%d", &A);
			menu[A - 1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (menu[i] == N) ans++;
	}
	printf("%d\n", ans);

	return 0;
}


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

int main()
{
    int num =1, n,k;
    cin >> n >> k;
    for(int i=0; i<n; i++)
    {
        if(num * 2 < num + k) num *= 2;
        else num += k;
    }
    cout << num << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
H=list(map(int,input().split()))
AB=[set() for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  A-=1
  B-=1
  AB[A].add(B)
  AB[B].add(A)
ans=0
for i in range(N):
  res=True
  for x in AB[i]:
    if H[i]<=H[x]:      
      res=False
      break
  if res:
    ans+=1
print(ans)

Measured memory_bytes: 45200
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**9+5] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, min(i, K)+1):
        dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
print(dp[N-1])

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

int main(){
  int a,b;
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;
  return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A,B;
int main(){
	cin>>A>>B;

	if(A%3==0){
		cout<<"Possible"<<endl;
	}else{
		if(B%3==0){
			cout<<"Possible"<<endl;
		}else{
			if((A+B)%3==0){
				cout<<"Possible"<<endl;
			}else{
				cout<<"Impossible"<<endl;
			}
		}
	}



	return 0;
}



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

int main(){

	char a[200], b[200];
	int aa= 0;
	scanf("%s %s", a, b);

	if (strlen(a) > strlen(b))
		printf("GREATER\n");
	if (strlen(b) > strlen(a))
		printf("LESS\n");
	if (strlen(a) == strlen(b)){
		for (int i = 0; i < strlen(a); ++i){
			if (a[i] > b[i]){
				printf("GREATER\n");
				break;
			}
			if (b[i] > a[i]){
				printf("LESS\n");
				break;
			}
			if (a[i] == b[i])
				aa+=1;

		}
	}
	if (aa == strlen(a)){
		printf("EQUAL\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;



int main(void){
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	while (a > 0 || c > 0) {
		c -= b;
		if (c <= 0) {
			cout << "Yes";
			break;
		}

		a -= d;
		if (a <= 0) {
			cout << "No";
			break;
		}
	}

	cout << endl;
}


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

int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  int a=0,c=0;
  if(A%D>0){
    a++;
  }
  if(C%B>0){
    c++;
  }
  if (A/D+a >= C/B+c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<string> split(const string &s, char c = '\"'){
    vector<string> ret;
    stringstream ss(s);
    string t;
    while(getline(ss, t, c)){
        ret.push_back(t);
    }
    return ret;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s1, s2;
    while(1){
        cin >> s1;
        if(s1 == ".") break;
        cin >> s2;
        vector<string> ss1 = split(s1);
        vector<string> ss2 = split(s2);
        if(ss1.size() != ss2.size()){
            cout << "DIFFERENT" << endl;
            continue;
        }
        int cnt = 0;
        rep(i, 0, ss1.size()){
            if(i % 2 == 0){
                if(ss1[i] != ss2[i]) cnt += 2;
            }else{
                if(ss1[i] != ss2[i]) cnt++;
            }
        }
        if(cnt == 0){
            cout << "IDENTICAL" << endl;
        }else if(cnt == 1){
            cout << "CLOSE" << endl;
        }else{
            cout << "DIFFERENT" << endl;
        }
    }
}


Measured memory_bytes: 3160
#[allow(unused_macros)]
macro_rules! p {
    ($x:expr $(, $tail:expr)*) => {
        let mut s = String::new();
        s.push_str(format!("{:?}", $x).as_str());
        $(
            s.push_str(format!(", {:?}", $tail).as_str());
        )*
        println!("{}", s);
    };
}

#[allow(unused_macros)]
macro_rules! pl {
    ($($x:expr), *) => {
        $(println!("{:?}", $x);)*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input! {
        source = src,
        n: usize, m: usize,
        ab: [(usize, usize); n]
    }
    let mut ab = ab;
    ab.sort_by_key(|&(a,_b)| a);
    let mut num = 0;
    let mut ans = 0;
    'outer: for i in 0..n {
        let (a, b) = ab[i];
        for _ in 0..b {
            num += 1;
            ans += a;
            if num == m {
                break 'outer;
            }
        }
    }
    ans.to_string()
}

// Test Code

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    };
}

test! {
    r"2 5
4 9
2 4
        " => "12",

    r"4 30
6 18
2 5
3 10
7 9
        " => "130",

    r"1 100000
1000000000 100000
        " => "100000000000000",
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define FOR(I,A,B) for(int I=int(A);I<int(B);++I)


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int h,w;
	while(cin>>h>>w,h+w){
		FOR(i,0,h){
			FOR(j,0,w){
				cout << '#';
			}
			cout << '\n';
		}
		cout << '\n';
	}
}



Measured memory_bytes: 3180
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long x[100005];
long long y[100005];
long long n,m;
long long ans;
long long anss;
long long a;
int main()
{
	cin>>n>>m;
	rep(i,n)
	{
		cin>>x[i];
	}
	rep(j,m)cin>>y[j];
	sort(x,x+n);
	sort(y,y+m);
	rep(i,n-1)
	{
		a=(x[i+1]-x[i]);
		a%=1000000007;
		a*=(i+1);
		a%=1000000007;
		a*=(n-1-i);
		a%=1000000007;
		ans+=a;
		ans%=1000000007;
	}
	rep(i,m-1)
	{
		a=(y[i+1]-y[i]);
		a%=1000000007;
		a*=(i+1);
		a%=1000000007;
		a*=(m-1-i);
		a%=1000000007;
		anss+=a;
		anss%=1000000007;
	}
	ans*=anss;
	ans%=1000000007;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cstring>
int main()
{
	char op[5];
	int a,b,ans;
	while(scanf("%d%s%d",&a,op,&b)!=EOF)
	{
		ans=0;
		if(op[0]=='+')
		ans=a+b;
		if(op[0]=='-')
		ans=a-b;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
bool isprime(int x){
	if(x==2)
		return true;
	if(x<2||x%2==0)
		return false;
	
	for(int i=3;i<=sqrt(x);i+=2){
		if(x%i==0)
			return false;
		
	}
	return true;
}
int main(){
	
	int n;
	int x;
	int count=0;
	
	cin>>n;
	
	while(n>0){
		cin>>x;
		
		if(isprime(x))
			count++;
		
		n--;
	}
	
	cout<<count<<endl;
	
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/


const int N = 105;
int a[N], b[N], c[N];

int main(){
    int n;
    cin >> n;

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

    int ans = 0;

    for(int i = 0; i < n; i++){
        if(!i) ans += b[i];
        else if(i == n - 1) ans += b[i - 1];
        else{
            ans += min(b[i], b[i - 1]);
        }
    }
    cout << ans;

}








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

void put_nchar(char c, char d, int n)
{
	if (n % 2 == 0) {
		n /= 2;
		while (n-- > 0)
			cout << c << d;
	} else {
		cout << c;
		n--;
		n /= 2;
		while (n-- > 0)
			cout << d << c;
	}
}

int main()
{
	int H, W;
	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0) 
			break;
		for (int i = 0; i < H; i++) {
			if (i % 2 == 0) 
				put_nchar('#', '.', W);
			else 
				put_nchar('.', '#', W);
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long long,long long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// 入力受け取り
	int n, m; cin >> n >> m;
	vector<vector<int>> jobs(m);
	rep(i, n) {
		int a, b; cin >> a >> b;
		if (a > m)continue;
		jobs[m - a].push_back(b);
	}
	priority_queue<int> q;
	int ans = 0;
	for (int i = m - 1; i >= 0; i--) {
		for (int b : jobs[i]) {
			q.push(b);
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5632
import sys
import bisect
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))
a.sort()
b.sort()
c.sort()
r = 0
for bn in b:
  cn = n - bisect.bisect_right(c, bn)
  an = bisect.bisect_left(a, bn)
  r += an * cn
print(r)

Measured memory_bytes: 22720
def slove():
    import sys
    input = sys.stdin.readline
    n, l = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    for i in range(1, n):
        if a[i] + a[i-1] >= l:
            print("Possible")
            for j in range(n-1, i, -1):
                print(j)
            for j in range(1, i):
                print(j)
            print(i)
            exit()
    print("Impossible")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 63856
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

type card struct {
	Suit string
	Rank int
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	var suitList = []string{"S", "H", "C", "D"}
	n := nextInt()
	cardList := make([]card, n)
	for i := 0; i < n; i++ {
		cardList[i].Suit = next()
		cardList[i].Rank = nextInt()
	}
	for i := 0; i < len(suitList); i++ {
		checkSuit(suitList[i], cardList)
	}
}

func checkSuit(suit string, cardList []card) {
	var suitList []card
	for i := 0; i < len(cardList); i++ {
		if cardList[i].Suit == suit {
			suitList = append(suitList, cardList[i])
		}
	}
	checkNumber(suit, suitList)
}

func checkNumber(suit string, cardList []card) {
	var check bool = false
	for i := 0; i < 13; i++ {
		for j := 0; j < len(cardList); j++ {
			if i+1 == cardList[j].Rank {
				check = true
			}
		}
		if !check {
			fmt.Fprintf(out, "%s %d\n", suit, i+1)
		}
		check = false
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func quickSort(val []card) []card {
	if len(val) < 2 {
		return val
	}

	pivot := val[0]

	left := []card{}
	right := []card{}

	for _, v := range val[1:] {
		if pivot.Rank > v.Rank {
			left = append(left, v)
		} else {
			right = append(right, v)
		}
	}

	left = quickSort(left)
	right = quickSort(right)

	ret := append(left, pivot)
	ret = append(ret, right...)

	return ret
}



Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
int  main(){
int a =0,b=0,c=0;
string s;
cin >> s;
for(int i=0;i<s.size();i++){
    if(s.at(i)=='a')a++;
    if(s.at(i)=='b')b++;
    if(s.at(i)=='c')c++;
}
int che = min({a,b,c});
a-=che;
b-=che;
c-=che;
if(a<=1&&b<=1&&c<=1&&a+b+c<=2)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}







Measured memory_bytes: 512
#include<stdio.h>
#include<ctype.h>

int main (void){
	
	int num,i;
	char ch;
	int counter[26] = {0};
	while(scanf("%c",&ch) != EOF){
		
		if(isupper(ch)){
			num = ch-'A';
		}else if(islower(ch)){
			num = ch-'a';
		}else{
			continue;
		}
		
		counter[num]++;
		
		
	}
	
	for(i=0;i<26;i++){
		printf("%c : %d\n",i+'a',counter[i]);
	}
	return 0;
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define li 100005
//typedef pair<int,int> PII;
typedef long long int lo;
using namespace std;
lo n,m,cev;
vector<lo> v;
int main(){
	scanf("%lld %lld",&n,&m);
	for(int i=1;i*i<=m;i++){
		if(m/i!=i && m%i==0){
			v.pb(i);
			v.pb(m/i);
		}
		else if(m/i==i && m%i==0)
			v.pb(i);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(int i=0;i<(int)v.size();i++){
		//printf("%lld ",v[i]);
		if(v[i]*n<=m){
			printf("%lld",v[i]);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, x, *A = map(int, read().split())
A = sorted(A)
cnt = 0

for a in A[:-1]:
    if x >= a:
        cnt += 1
        x -= a
if x == A[-1]:
    cnt += 1

print(cnt)


Measured memory_bytes: 12468
N, X = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    sub = max(0, A[i] + A[i+1] - X)
    ans += sub
    A[i+1] = max(0, A[i+1] - sub)

print(ans)

Measured memory_bytes: 14052