akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
    int n, b[512], f[512], r[512], v[512];
    int j[4][3][10] = { 0 };
    int a=0,i,m,k;

    scanf("%d",&n);
    for (i = 0; i < n; i++){
        scanf("%d%d%d%d",&b[i],&f[i],&r[i],&v[i]);
    }
    for (i = 0; i < n; i++){
        j[b[i]-1][f[i]-1][r[i]-1]+=v[i];
    }
    for (i = 0; i < 4; i++){
        if (a)printf("####################\n");
        for (m = 0; m < 3; m++){
            for (k = 0; k < 10; k++){
                printf(" %d",j[i][m][k]);
            }
            printf("\n");
            a = 1;
        }
    }
    return 0;
}

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



const int N = 1e5 + 5;




int n, m, d[N];
vector < int > g[N], order;
bool used[N];


void dfs(int v){
    used[v] = true;
    for(int to : g[v]){
        if(!used[to]){
            dfs(to);
        }
    }
    order.push_back(v);
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    while(m--){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
    }
    for(int i = 1; i <= n; i++){
        if(!used[i]){
            dfs(i);
        }
    }
    reverse(order.begin(), order.end());
    for(auto v : order){
        for(int to : g[v]){
            d[to] = max(d[to], d[v] + 1);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, d[i]);
    }
    cout << ans;
}


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

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define int long long
#define INF 1e+9
#define MAX_V 100008
const int MOD = 1e9 + 7;
const int inf = 1 << 30;


signed main(){
  IOS
  int  N, K;
  cin >> N;
  vector<int> A(N);
  map<int, int> mp;
  rep(i, 0, N){
    int x;
    cin >> x;
    mp[x]++;
  }
  int div;
  long long ans;
  if(mp[0] == 1){
    mp[0]++;
    div = 0;
    ans = 1;
  }else if(mp[0] == 0){
    // continue;
    div = -1;
    ans = 1;
  }else{
    // cout << "a " << endl;
    cout << 0 << endl;
    return 0;
  }

  bool flag = true;
  mp.erase(0);
  for (auto it: mp){
    // cout << it.first << " " << it.second << endl;
    // cout << ans << endl;
    if(it.second != 2 || it.first != div + 2) flag = false;
    div += 2;
    ans *= 2;
    ans %= MOD;
  }

  // if(mp[0] == 2) ans /= 2;
  if (flag){
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 7916
from collections import deque
INF = 1_000_000_000
def main():
    n, m = map(int, input().split(" "))
    to = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(lambda i:int(i)-1, input().split(" "))
        to[a].append(b)
        to[b].append(a)
    que = deque()
    d = {i:INF for i in range(n)}
    prev = {i:-1 for i in range(n)}
    d[0] = 0
    que.append(0)
    while que:
        v = que.popleft()
        for i in to[v]:
            if d[i] != INF: continue
            d[i] = d[v] + 1
            prev[i] = v
            que.append(i)
    print("Yes")
    for i in range(n):
        if i == 0: continue
        print(prev[i]+1)
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 54632
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def li():
    return [int(x) for x in input().split()]


X, K, D = li()

if X < 0:
    X *= -1

ans = 0
if K * D < X:
    #print("A")
    ans = X - K * D
else:
    over_K = X // D + 1
    #print(over_K)
    if (K - over_K) % 2 == 1:
        #print("B")
        ans = X % D
    else:
        #print("C")
        ans = D - (X % D)

print(ans)

Measured memory_bytes: 61740
def main():
    b, w = map(int, input().split())
    mod = 10**9+7
    fact = [1, 1]
    for i in range(2, 2*(10**5)+5):
        fact.append(fact[-1]*i % mod)

    half = pow(2, mod-2, mod)

    def nCr(n, r, mod=10**9+7):
        return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod

    h = 1

    A, B, C = 0, 1, 0
    for i in range(1, b+w+1):
        h = h*half % mod
        ans = B
        A = A*2 % mod
        B = B*2 % mod
        C = C*2 % mod
        if i-1 >= b:
            p = nCr(i-1, b)
            ans = (ans-p) % mod
            C = (C+p) % mod
            B = (B-p) % mod
        if i-w-1 >= 0:
            p = nCr(i-1, i-w-1)
            A = (A+p) % mod
            B = (B-p) % mod
        ans = (ans+A) % mod
        print(ans*h % mod)


main()


Measured memory_bytes: 13044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, s;

ll solve(){
	if(n < s){return -1;}
	if(n == s){return n+1;}
	
	ll b = 2;
	while(b*b <= n){
		ll tmp = n;
		ll f = 0;
		while(tmp){
			f += tmp%b;
			tmp /= b;
		}
		if(f == s){return b;}
		
		b++;
	}
	
	ll x = b; 
	while(x > 0){
		ll y = s-x;
		if((n-y)%x == 0){
			b = (n-y)/x;
			if(x < b && 0 <= y && y < b){
				return b;
			}
		}
		x--;
	}
	return -1;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> s;
	print(solve())
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>

using namespace std;
#define ll long long
#define ve vector
#define umap unordered_map

int main()
{
    int n,k;
    umap<int, bool> d(10);
    cin>>n>>k;
    for(int i=0;i<k;i++) {
        int t; cin>>t;
        d[t]=1;
    }
    for(int i=n;i<1e+5;i++) {
        string s = to_string(i);
        for(int j=0;j<s.size();j++) {
            if(d[s[j] - '0']) goto j;
        }
        cout<<i;
        break;
        j:;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
 
 
int main(){
  int n; cin >> n;
  ll ans = 3e9;
  vector<ll> a(n),s(n);
  rep(i,n) cin >> a[i];
  s[0] = a[0];
  rep(i,n-1) s[i+1] = s[i] + a[i+1];
  rep(i,n-1) ans = min(ans,abs(s[n-1]-2 * s[i]));
  cout << ans << endl;
}


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

int main() {
	int N;
	int a[100001];
	cin >> N;
	int i;
	int sum = 0;
	for (i = 0; i < N; i++) { 
		cin >> a[i]; 
		sum += a[i];
	}
	cout << sum - N << endl;

}

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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll f[110][64];
bool used[256];

void init(){
  for (int mask = 0; mask < 256; ++mask){
    vector<int> col(4); int s = 1;
    for (int j = 0; j < 4; ++j){
      col[j] = (mask / s) % 4;
      s = s * 4;
    }
    for (int j = 0; j < 4; ++j){
      if (j != 3) swap(col[j], col[j + 1]);
      if (col[0] == 1 && col[1] == 2 && col[2] == 0) used[mask] = true;
      if (col[1] == 1 && col[2] == 2 && col[3] == 0) used[mask] = true;
      if (j != 3) swap(col[j], col[j + 1]);
    }
  }
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);
  int n; cin >> n;
  if (n == 3) {
    cout << 61;
    return 0;
  }
  init();
  for (int i = 0; i < 64; ++i) f[3][i] = 1;
  for (int i = 4; i <= n; ++i) {
    for (int mask = 0; mask < 64; ++mask){
      for (int j = 0; j < 4; ++j){
        int n_mask = mask + j * 64;
        if (not used[n_mask]){
          f[i][mask] = f[i][mask] + f[i-1][n_mask / 4];
          f[i][mask] %= mod;
        }
      }
    }
  }
  ll ans = 0;
  for (int mask = 0; mask < 64; ++mask){
    ans = ans + f[n][mask];
    ans %= mod;
  }
  cout << ans;
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

int a,b,c,k;

int main(){
    cin>>a>>b>>c>>k;

    rep(i,0,k){
        if(a>=b) b*=2;
        else c*=2;
    }
    if(a<b && b<c) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    return 0;
}


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


def main():
    s = input().strip()
    ans = 0
    if s == "SUN":
        ans = 7
    elif s == "MON":
        ans = 6
    elif s == "TUE":
        ans = 5
    elif s == "WED":
        ans = 4
    elif s == "THU":
        ans = 3
    elif s == "FRI":
        ans = 2
    elif s == "SAT":
        ans = 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import sys
input=sys.stdin.readline
n,m,p=[int(j) for j in input().split()]

def bellman_ford(v, s, e):
    INF = 10**18
    # コストをINFで初期化
    d = [INF] * v
    # 開始頂点は0
    d[s] = 0
    # 負の閉路が無ければ更新はV-1回までで終わる
    for _ in range(v):
        f = False
        for a, b, c in e:
            # aまでのコスト+辺abのコストがbまでのコストより小さければ更新
            cost = d[a] + c
            if cost < d[b]:
                d[b] = cost
                f = True
        # 更新が無ければbreak
        if not f:
            break
    else:
        # V回目まで更新があったら負の閉路がある
        print(-1)
        exit()
    print(max(-d[-1],0))

def dfs(edge,s):
    use={s}
    q=[s]
    while q:
        v=q.pop()
        for w in edge[v]:
            if w in use:continue
            use.add(w)
            q.append(w)
    return use


l=[[] for i in range(n)]
ll=[[] for i in range(n)]
e=[]
for i in range(m):
    a,b,c=[int(j) for j in input().split()]
    l[a-1].append(b-1)
    ll[b-1].append(a-1)
    e.append((a-1,b-1,p-c))
use=dfs(l,0)&dfs(ll,n-1)
e=[(a,b,c) for a,b,c in e if (a in use and b in use)]


bellman_ford(n, 0, e)

Measured memory_bytes: 46188
#include <bits/stdc++.h>
using namespace std;
#define INT(a) scanf("%d",&a)
#define STR(a) scanf("%s",a)
#define DBL(a) scanf("%lf",&a)
#define LNG(a) scanf("%lld",&a)
#define PI acos(-1)

long long s[100005], t[100005];
int main(){
	int a,b;
	cin>>a>>b;
	int q;
	cin>>q;
	for(int i=0;i<a;i++) cin>>s[i];
	for(int i=0;i<b;i++) cin>>t[i];
	for(int i=0;i<q;i++){
		long long x; cin>>x;
		int sp = lower_bound(s, s+a, x)-s;
		int tp = lower_bound(t, t+b, x)-t;
		if(sp==a) sp--;
		if(tp==b) tp--;
		long long mn=1e18;
		if(s[sp]>=x && t[tp]>=x){
			mn=min(mn, abs(x-max(s[sp], t[tp])));
			if(sp-1>=0) mn=min(mn, min(abs(x-s[sp-1])+abs(s[sp-1]-t[tp]), abs(x-t[tp])+abs(s[sp-1]-t[tp])));
			if(tp-1>=0) mn=min(mn, min(abs(x-t[tp-1])+abs(t[tp-1]-s[sp]), abs(x-s[sp])+abs(t[tp-1]-s[sp])));
			if(sp-1>=0 && tp-1>=0) mn=min(mn, abs(x-min(s[sp-1], t[tp-1])));
		} else if(s[sp]<=x && t[tp]<=x){
			mn=min(mn, abs(x-min(s[sp], t[tp])));
		} else if(s[sp]<=x){
			mn=min(mn, min(abs(x-s[sp])+abs(s[sp]-t[tp]), abs(x-t[tp])+abs(s[sp]-t[tp])));
			if(tp-1>=0) mn=min(mn, abs(x-min(s[sp], t[tp-1])));
		} else if(t[tp]<=x){
			mn=min(mn, min(abs(x-t[tp])+abs(s[sp]-t[tp]), abs(x-s[sp])+abs(s[sp]-t[tp])));
			if(sp-1>=0) mn=min(mn, abs(x-min(s[sp-1], t[tp])));
		}
		cout<<mn<<endl;
	}

	return 0;
}

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

bool solve() {
    int N, a;
    cin >> N;
    map<int,int> A;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        A[a]++;
    }
    if ( A.size() == 1 ) {
        int k = A.begin()->first;
        if ( k == N-1 ) return true;
        if ( 2 * k <= N ) return true;
        return false;
    } else if ( A.size() == 2 ) {
        int k1 = A.begin()->first;
        int k2 = next(A.begin())->first;
        int n1 = A.begin()->second;
        if ( k1 + 1 != k2 ) return false;
        if ( n1 + 1 > k2 ) return false;
        if ( (k2 - n1) * 2 > N - n1 ) return false;
        return true;
    }
    return false;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4992
using static System.Math;
using System;

class Modulo
{
    private const int MOD = 1000000007;
    private readonly int[] m_facs;
    public int Mul(int a, int b) => (int)(BigMul(a, b) % MOD);
    public Modulo(int n)
    {
        m_facs = new int[n + 1];
        m_facs[0] = 1;
        for (int i = 1; i <= n; ++i)
            m_facs[i] = Mul(m_facs[i - 1], i);
    }
    public int Fac(int n) => m_facs[n];
    public int Pow(int a, int m)
    {
        switch (m)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, m / 2);
                int p2 = Mul(p1, p1);
                return ((m % 2) == 0) ? p2 : Mul(p2, a);
        }
    }
    public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2));
    public int Ncr(int n, int r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        int res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        Console.WriteLine(n > k ? 0 : 1);
    }
}



Measured memory_bytes: 17952
// Score: /300

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	uint64_t A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	uint64_t a=0,b=0,c=0;
	uint64_t fee=0;

	c =min(X,Y)*2;
	if(X>Y){
		a = X-Y;
	}else{
		b = Y-X;
	}
	fee = a*A+b*B+c*C;

	a=X;
	b=Y;
	c=0;
	uint64_t n_fee = a*A+b*B+c*C;
	fee = fee > n_fee ? n_fee : fee;

	a=0;
	b=0;
	c =max(X,Y)*2;
	n_fee = a*A+b*B+c*C;
	fee = fee > n_fee ? n_fee : fee;

	cout << fee;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a1 = sum(A)
for i in range(n):
  b = B[i]
  if A[i] >= b:A[i] -= b
  else:
    if A[i+1]+A[i] >= b:
      A[i+1] = A[i+1]+A[i]-b
      A[i] = 0
    else:A[i], A[i+1] = 0, 0
a2 = sum(A)
print(a1-a2)

Measured memory_bytes: 97748
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// # pragma GCC optimize "-O3"
# define int long long
using namespace std;
  
const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int32_t main() {
    speed;
    string s, t;
    cin >> s >> t;
    for ( int i = 0; i < (int)s.size(); i++ ) {
    	if ( s[i] != t[i] ) {
    		cout << "No\n";
    		return 0;
    	}
    }
    cout << "Yes\n";
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S, T;
    cin >> S >> T;
    cout << T + S << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
def f(x, m):
    return (x**2) % m

N, X, M = map(int, input().split())
A = [X]
S = {X}
while True:
    X = f(X, M)
    if X in S:
        break
    else:
        A.append(X)
        S.add(X)


start = A.index(X)
l = len(A) - start
ans = sum(A[:start])
N -= start

ans += sum(A[start:]) * (N//l)
N %= l

ans += sum(A[start:start+N])
print(ans)

Measured memory_bytes: 13164
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = min(a, b); i >= 1; i--) {
    if (a % i == 0 && b % i == 0) {
      k--;
      if (k == 0) {
        cout << i << '\n';
        return;
      }
    }
  }
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3612
N = int(input())
C = [0 for _ in range(4)]
result = ["AC", "WA", "TLE", "RE"]

for _ in range(N):
  S = input()
  for i in range(4):
    if S == result[i]:
      C[i] += 1
      break

for i in range(4):
  print("{} x {}".format(result[i], C[i]))

Measured memory_bytes: 9108
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;

int main() {
    int N;
    map<int, int> mp;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (!mp.count(tmp)) mp[tmp] = 1;
        else mp[tmp]++;
    }
    int MAX1 = 0, MAX2 = 0;
    for (auto i : mp) {
        if (i.second >= 4) {
           MAX2 = MAX1 = i.first;
        } else if (i.second >= 2) {
           MAX2 = MAX1;
           MAX1 = i.first;
        }
    }
    printf("%lld\n", (LL)MAX1 * MAX2);
    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 200000;

int n;
int a[MAXN];
ll asum[MAXN + 1];
ll b[MAXN + 1];

void run() {
	scanf("%d", &n); REP(i, n) scanf("%d", &a[i]);
	asum[0] = 0; REP(i, n) asum[i + 1] = asum[i] + a[i];
	//printf("asum:"); REPE(i, n) printf(" %lld", asum[i]); puts("");
	REPE(i, n) b[i] = asum[i];
	sort(b, b + n + 1);
	ll ret = 0;
	for (int l = 0, r = l; l <= n; l = r) {
		while (r <= n&&b[l] == b[r]) ++r;
		int cnt = r - l;
		ret += (ll)cnt*(cnt - 1) / 2;
	}
	printf("%lld\n", ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 4096
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;
ll int inv[N],comb[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
void calc_comb(ll int n){
    comb[0]=1;
    rep2(i,1,n){
        comb[i]=comb[i-1]*(n+1-i)*inv[i]%MOD;
    }
    return;
}
void calc_product(){
    prd[0]=prd[1]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N){
        prd[i]=i*prd[i-1]%MOD;
        invprd[i]=inv[i]*invprd[i-1]%MOD;
    }
    return ;
}
ll cmb(int a,int b){
    return prd[a]*invprd[b]%MOD*invprd[a-b]%MOD;
}
ll modpow(ll x,ll n){
    if(n==0) return 1;
    ll res=modpow(x*x%MOD,n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
main(){
    calc_inv();
    calc_product();
    int n,m;
    cin>>n>>m;
    int memm=m;
    vector<int> v;
    for(int i=2;i*i<m;i++){
        if(memm%i==0){
            int count=0;
            while(memm%i==0){
                memm/=i;
                count++;
            }
            v.pb(count);
        }
    }
    if(memm!=1)v.pb(1);
    ll ans=1;
    rep(i,v.size()){
        ans=ans*cmb(n+v[i]-1,v[i])%MOD;
    }
    cout<<ans;
}

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

const int ac = 1e6 + 10;
ll A[ac];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string a, b; cin >> a >> b;
	vector<string> V;
	for (int i = 0; i < a.size() - b.size() + 1; i++)
	{
		bool g = 1;
		for (int j = 0; j < b.size(); j++)
		{
			if (a[i + j] == b[j] || a[i + j] == '?');
			else { g = 0; break; }
		}
		if (g)
		{
			string u;
			for (int j = 0; j < i; j++)
			{
				if (a[j] == '?') u += 'a';
				else u += a[j];
			}
			for (int j = i; j < i + b.size(); j++)
			{
				u += b[j - i];
			}
			for (int j = i + b.size(); j < a.size(); j++)
			{
				if (a[j] == '?') u += 'a';
				else u += a[j];
			}
			V.push_back(u);
		}
	}
	if (V.empty()) { cout << "UNRESTORABLE\n"; return 0; }
	sort(V.begin(), V.end());
	cout << V[0] << '\n';
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n+1];
        for(int i = 1; i <= n; i++) {
            h[i] = sc.nextInt();
        }
        int[] dp = new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = 0;
        for(int i = 2; i <= n; i++) {
            for(int j = 1; j <= k && i - j >= 1; j++) {
                dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }
        System.out.println(dp[n]);
    }
}


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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 998244353;
    unsigned long N, S;
    cin >> N >> S;
    unsigned long ans{0};
    vector<unsigned long> dp(S);
    for(unsigned long i{0}, A; i < N; ++i){
        cin >> A;
        if(A < S){
            ans += dp[S - A] * (N - i) % MOD;
            for(unsigned long j{S}; j --> A; )(dp[j] += dp[j - A]) %= MOD;
            (dp[A] += i + 1) %= MOD;
        }else if(A == S)ans += (i + 1) * (N - i) % MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N, A;
    cin >> N >> A;
    cout << (N*N) - A << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
inline ll min(ll x,ll y) {return x<y?x:y;}
inline ll max(ll x,ll y) {return x>y?x:y;}
const int Maxn=2e5+5;
char s[Maxn];
int n,f[Maxn][2];
int main()
{
	cin>>n>>s+1;
	for(int i=1;i<=n;i++)
    {
        f[i][0]=f[i-1][0]+(s[i]!='.');
        f[i][1]=min(f[i-1][0],f[i-1][1])+(s[i]!='#');
    }
    cout<<min(f[n][0],f[n][1])<<endl;
 	return 0;
}


Measured memory_bytes: 2048
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	long n,s,a[10000];
	
	while(1){
		cin >> n  ;
		if(n==0){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> a[i] ;
		}
		for(int i=1;i<n;i++){
			for(int j=0;j<n-i;j++){
				if(a[j]<a[j+1]){
					s=a[j]; a[j]=a[j+1]; a[j+1]=s;
				}
			}
		}
		s=0;
		for(int i=0;i<n;i++){
			s+=a[i]*i;
		}
		cout << s << "\n";
	}
	
	
return 0;
}

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

using namespace std;
int a,b;

int main()
{
	long long ans1,ans2,ans3;
	cin>>a>>b;
	ans1=a+b;
	ans2=a-b;
	ans3=a*b;
	ans1=max(ans1,ans2);
	ans1=max(ans1,ans3);
	cout<<ans1<<endl;
	return 0;
 } 

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

#define ll long long int
#define MP make_pair
#define pb push_back
#define PLL pair<ll,ll>

int main()
{
  ll n;
  cin >> n;
  ll a[n],i,sum=0;

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

  sort(a,a+n);

  ll count=0;
  sum+=a[n-1];
  count++;

  for(i=n-2;i>=0;i--)
  {
    if(count>= n-1)
    break;

    sum+=a[i];
    count++;
    
    if(count>= n-1)
    break;


    sum+=a[i];
    count++;

  }

  cout << sum <<'\n';


}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D ;
  if ( A+B < C+D ) {
    cout << "Right" << endl;
  }
  else if ( A+B > C+D) {
    cout << "Left" << endl;
  }
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
using System;
class ITP1_8_B
{
    static void Main()
    {
        while (true)
        {
            string ipt = Console.ReadLine();
            if (ipt == "0") break;
            int sum = 0;
            for (int i = 0; ipt.Length > i; i++)
                sum += int.Parse(ipt[i].ToString());
            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 9740
import sys
sys.setrecursionlimit(100000)

N=int(input())
edges = [[] for i in range(N)]
colors = [-1]*N
for i in range(N-1):
    u,v,w=[int(a) for a in input().split()]
    edges[u-1].append((v-1,w))
    edges[v-1].append((u-1,w))
 
diff = lambda n: 1 if n==0 else 0
 
def dfs(prev,curr):
    for node,d in edges[curr]:
        if node==prev:
            continue
        colors[node] = colors[curr] if d%2==0 else diff(colors[curr])
        dfs(curr,node)
 
colors[0]=0
dfs(1000000,0)
for i in range(N):
    print(colors[i])


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

using LL = long long;

const LL INF = 1e9+5;

LL N, A, B;
vector<LL> h;

bool f(LL K){
  LL tmp = 0;
  for(int i=0; i<N; i++){
    LL rem = h[i]-B*K;
    if(rem > 0) tmp += (rem+(A-B-1)) / (A-B);
  }
  return (tmp <= K);
 }

 LL binary_search(LL ok, LL ng){
  while (abs(ok - ng) > 1) {
    LL mid = (ok + ng) / 2;
    if(f(mid)) ok = mid;
    else ng = mid;
  }
  return ok;
 }

 int main(){
  cin >> N >> A >> B;
  h = vector<LL>(N); // サ イ ズ Nを確保
  for(int i=0; i<N; i++) cin >> h[i];
  cout << binary_search(INF, 0) << endl;
 }

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

// dp[i][m]:i番目の数まで考えたとき余りがmとなる選び方の数
LLONG dp[51][2];

int main()
{
	int N, P; cin >> N >> P;
	// DPで解く:O(N)
	dp[0][0] = 1;
	REP(i, N) 
	{
		int ai; cin >> ai;
		if (ai % 2 == 0)
		{
			dp[i + 1][0] = dp[i][0] * 2;
			dp[i + 1][1] = dp[i][1] * 2;
		}
		else
		{
			dp[i + 1][0] = dp[i + 1][1] = dp[i][0] + dp[i][1];
		}
	}
	cout << dp[N][P] << endl;
}


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

int main(){
	int N, i, j;
	scanf("%d", &N);
	for(i = 0; i < 100; i++){
		for(j = 0; j < 100; j++){
			if(4 * i + 7 * j == N){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
const ll base = 31;
const ll MOD = 1e9+9;
const ll  maxN = 1e6+9;

using namespace std ;
int main()
{ double  a , n , b , res=0;
  cin >> a>> b;
  for ( int i = 1; i<= 5000000 ; i++)
  { if ( floor(i * 0.08)  == a  && floor(i*0.1)==b) {cout<< i ; return 0;}

  }
 cout<<-1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for(int i = 0; i<n; i++){
        cin >> p[i];
    }
    for(int i = 0; i<n; i++){
        cin >> q[i];
    }
    int a = 1, b = 1;
    while(prev_permutation(p.begin(), p.end())){
        a++;
    }

    while(prev_permutation(q.begin(), q.end())){
        b++;
    }
    
    cout << abs(a-b) << endl;

    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int ans;
	for(int i=0;;i++){
		if(i*i<=n&&(i+1)*(i+1)>n){
			ans=i*i;
			break;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}


int main(){
    ll x,y,n,m,p,h,k,max=-10000000,min=1000000000,ans=0,sum=0;
    string s,t;
    cin >> n;
    //VI a(n)
    
    cout << n*n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  string s;
  cin>>s;
  if(s[0]=='R')
  {
      if(s[1]=='R')
      {
          if(s[2]=='R')
              cout<<"3"<<endl;
          else
              cout<<"2"<<endl;
      }
      else
      {
          cout<<"1"<<endl;
      }
  }
  else
  {
      if(s[1]=='R')
      {
          if(s[2]=='R')
              cout<<"2"<<endl;
          else
              cout<<"1"<<endl;
      }
      else
      {
          if(s[2]=='R')
              cout<<"1"<<endl;
          else
              cout<<"0"<<endl;
      }
  }
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a==b&&b!=c)||(a==c&&a!=b)||(b==c&&a!=b)){
    cout<<"Yes"<<endl;  
  }
  else{
    cout<<"No"<<endl;  
  }
  
  return 0;
}

Measured memory_bytes: 256
N=int(input())
S=[]
for i in range(N):
  S.append(int(input()))
sum=sum(S)

flg=1
if sum % 10 == 0:
  K=sorted(S)
  flg=0
  for i in range(len(S)):
    if K[i] % 10 != 0:
      sum-=K[i]
      flg=1
      break
if flg == 0:
  sum=0
print(sum)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <deque>
#include <vector>

auto main() -> int {
  std::uint64_t N, Q;
  std::cin >> N >> Q;

  std::string S;
  std::cin >> S;

  // v[i]: S_i までの 'AC' の数
  std::vector<std::uint64_t> v(N);
  v[0] = 0;
  for (std::uint64_t i = 1u; i < N; ++i) {
    if (S[i - 1] == 'A' && S[i] == 'C') {
      v[i] = v[i - 1] + 1;
    } else {
      v[i] = v[i - 1];
    }
  }

  for (std::uint64_t i = 0u; i < Q; ++i) {
    std::uint64_t l, r;
    std::cin >> l >> r;
    std::cout << (v[r - 1] - v[l - 1]) << '\n';
  }
}


Measured memory_bytes: 1856
#include<stdio.h>
int main()
{
    int N,x,y,z;
    1<=N<=100;
    scanf("%d",&N);
    y=N%2;
    x=N/2;
    z=x+1;
    if(y==0)
    printf("%d",x);
    else
    printf("%d",z);
    return 0;
}

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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void){

    string str;	cin >> str;
    V vec(str.length());
    for(int i = 0 ; i < str.length() ; i++){

      //交差する点のRの座標を保存
      if(str[i] == 'R' && str[i + 1] == 'L'){
	int j = i;
	while(0 <= j && str[j] == 'R'){
	  //Rから偶数の距離にいるなら
	  if(abs(j - i) % 2 == 0) vec[i] += 1;
	  //奇数の位置にいるなら
	  else	vec[i + 1] += 1;

	  j--;
	}

	//交差する点のLの位置を保存
	j = i + 1;
	while(j < str.length() && str[j] == 'L'){
	  if(abs(j - i) % 2 == 0) vec[i] += 1;
	  else vec[i + 1] += 1;

	  j++;
	}
      }	
    }

	REP(i , str.length())	SCOUT(vec[i]);
    cout << endl;
    return 0;
}


Measured memory_bytes: 1024
import math
n,k = map(int,input().split())
def c(n, r):
    return math.factorial(n) // (math.factorial(abs(n - r)) * math.factorial(r))
for i in range(k):
  if n-k<i:
    print(0)
  else:
    red = c(n-k+1, i+1)
    blue = c(k-1, i)
    ans = (red*blue) % (10**9+7)
    print(ans)

Measured memory_bytes: 3316
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($A,$B) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));

$x = gcd($A,$B);
$a = array_unique(prime_factors($x));

$r=0;
foreach($a as $v) {
  if (is_prime($v)) {
   $r++;
  }
}
printf("%d\n",$r+1);

function gcd($a,$b) {
  if ($b == 0) return $a;
  return gcd($b,$a%$b);
}
function lcm($a,$b) {
  $l = gcd($a,$b);
  return $a / $l * $b;
}

function prime_factors(int $n) {
    $i = 2;
    $factors = [];
    while ($i * $i <= $n) {
        if ($n % $i) $i += 1;
        else {
            $n /= $i;
            $factors[] = $i;
        }
    }
    if ($n > 1) $factors[] = $n;
    return $factors;
}

function is_prime(int $n) : bool {
    $r = true;
    if ($n < 2) $r = false;
    elseif ($n == 2 || $n == 3 || $n == 5) $r = true;
    elseif ($n & 1 == 0) $r = false;
    elseif ($n % 2 == 0 || $n % 3 == 0 || $n % 5 == 0) $r = false;
    else {
        $f = true;
        $v = 7;
        $m = intval($n ** 0.5) + 1;
        while ($v < $m) {
            if ($n % $v == 0) {
                $r = false;
                break;
            }
            $v += $f ? 4 : 2;
            $f = !$f;
        }
    }
    return $r;
}


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>
const int N = 2e5 + 10;

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    int a[n];
    int x[2] = {0, 0};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x[a[i] % 2]++;
    }
    x[0] += x[1] / 2;
    x[1] %= 2;
    if ((x[1] == 1 && x[0] == 0) || (x[1] == 0 && x[0] > 0)) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

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

def main():
    N,M,P = map(int,input().split())
    edges = []


    for _ in range(M):
        A,B,C = map(int,input().split())
        edges.append([A-1,B-1,P-C])

    reachable_from = [False for _ in range(N)]
    reachable_from[0] = True
    reachable_to = [False for _ in range(N)]
    reachable_to[N-1] = True

    for i in range(N-1):
        for edge in edges:
            if reachable_from[edge[0]]:
                reachable_from[edge[1]] = True
            if reachable_to[edge[1]]:
                reachable_to[edge[0]] = True

    edges2 = []
    for edge in edges:
        if reachable_from[edge[0]] and reachable_to[edge[1]]:
            edges2.append(edge)

    inf = 10000*(10**5)
    dist = [inf for _ in range(N)]
    dist[0] = 0

    for i in range(N):
        for edge in edges2:
            if dist[edge[1]] > dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]]+edge[2]
                if i==N-1:
                    print(-1)
                    break
        else:
            continue
        break
    else:
        print(max(0,-1*dist[N-1]))

if __name__ == "__main__":
    main()


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

int main()
{
  int h, w, ans;
  cin >> h >> w;
  
  char c[55][55];
  
  for (int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      cin >> c[i][j];
    }
  }
  
  for (int i=1; i<=h; i++){
    for(int j=1; j<=w; j++) {
      if (c[i][j] == '#' &&
          c[i+1][j] != '#' && c[i][j+1] != '#' &&
          c[i-1][j] != '#' && c[i][j-1] != '#')	ans++;
    }
  }
  if (ans == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N (1<<18)

long long bit[N + 1];

//初期化
void init(void){
	f(i, N + 1)bit[i] = 0;
	return;
}

//加算(k=1-n)
void add(int k, long long x){
	while (k <= N){
		bit[k] += x;
		k += k& -k;
	}
	return;
}
//合計(1<=k<=r)
long long sum(int r){
	long long s = 0;
	while (r > 0){
		s += bit[r];
		r -= r & -r;
	}
	return s;
}



int main(){
	int a[N];
	vector<int>aa;
	vector<int>b[2 * N];
	int c[N];
	int d[N];
	f(i, N){
		a[i] = 0;
		c[i] = 0;
		d[i] = 0;
	}
	int k;
	int n;
	int x, y, z;
	long long s, ans;
	scanf("%d", &n);
	ans = n;
	ans = ans*(ans + 1);
	ans = ans / 2;
	ans += 2;
	ans = ans / 2;
	f(i, n){
		scanf("%d", &a[i]);
		aa.push_back(a[i]);
	}
	sort(aa.begin(), aa.end());

	int l = 0;
	int r = n;
	int  m;
	while (l + 1 < r){
		m = (l + r) / 2;
		c[0] = 0;
		f(i, 2 * n + 1)b[i].clear();
		b[n].push_back(0);
		f(i, n){
			if (a[i] < aa[m])c[i + 1] = c[i] + 1;
			else c[i + 1] = c[i] - 1;
			b[c[i + 1] + n].push_back(i + 1);
		}
		k = 1;
		f(i, 2 * n + 1){
			f(j, b[i].size()){
				d[b[i][b[i].size()-j-1]] = k;
				k++;
			}
		}
		init();
		s = 0;
		f(i, (n + 1)){
			s += sum(d[i]);
			add(d[i], 1);
		}
      
		if (s < ans)l = m;
		else r = m;
	}


	printf("%d\n", aa[l]);


	return 0;
}

Measured memory_bytes: 21880
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

int int_sort(const void*a, const void *b) {
	return *(int*)b - *(int*)a;
}

int even[100001] = {};
int odd[100001] = {};
int main() {
	int a, b;
	int max1 = 1, max2 = 1;
	int max_ev = 0, max_od = 0, sec_ev = 0, sec_od = 0;
	int sum1, sum2, sum3;

	cin >> a;
	for (int i = 1; i<=a; i++) {
		if (i % 2 == 1) {
			cin >> b;
			odd[b] += 1;
		}
		else {
			cin >> b;
			even[b] += 1;
		}
	}
	for (int i = 1; i <=100000 ; i++) {
		if (odd[max1] < odd[i]) max1 = i;
		if (even[max2] < even[i]) max2 = i;
	}
	qsort(even, 100001, sizeof(int), int_sort);
	qsort(odd, 100001, sizeof(int), int_sort);
	max_ev = even[0]; max_od = odd[0];
	sec_ev = even[1]; sec_od = odd[1];

	sum1 = a - (max_ev + sec_od);
	sum2 = a - (sec_ev + max_od);
	sum3 = a - (max_od + max_ev);
	
	if (max1 != max2) {
		printf("%d\n", sum3);
	}
	else if (sum1 <= sum2) {
		printf("%d\n", sum1);
	}
	else {
		printf("%d\n", sum2);
	}
	return 0;
}

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

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  transform(a.begin(), a.end(), a.begin(), ::toupper);
  transform(b.begin(), b.end(), b.begin(), ::toupper);
  transform(c.begin(), c.end(), c.begin(), ::toupper);
  cout << a.front() << b.front() << c.front() << endl;
  return 0;
}

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

def calc(i, level, fs, lim):
    if fs[i][1] not in "+*":
        return i, int(fs[i][1])
    if fs[i][1] == "+":
        tmp = 0
        j = i+1
        while j < lim:
            if fs[j][0] <= level:
                break
            if fs[j][1] in "*+":
                j, tmp2 = calc(j, level+1, fs, lim)
                tmp += tmp2
            else:
                tmp += int(fs[j][1])
            j += 1
        return j-1, tmp
    elif fs[i][1] == "*":
        tmp = 1
        j = i+1
        while j < lim:
            if fs[j][0] <= level:
                break
            if fs[j][1] in "*+":
                j, tmp2 = calc(j, level+1, fs, lim)
                tmp *= tmp2
            else:
                tmp *= int(fs[j][1])
            j += 1
        return j-1, tmp


def main():
    while True:
        n = int(input())
        if n == 0:
            break
        fs = [[0,0] for i in range(n)]

        for i in range(n):
            tmp = input().strip()
            fs[i][0] = tmp.count(".")
            fs[i][1] = tmp.replace(".", "")
        _, ans = calc(0, 0, fs, len(fs))
        print(ans)

if __name__ == "__main__":
    main()



Measured memory_bytes: 5636
#include<stdio.h>

int main() {
	int a, b, valid_flg, i;
	char s[1000];
	scanf("%d%d%s", &a, &b, &s);
	valid_flg = 1;
	for (i = 0; s[i] != '\0'; i++) {
		if (i == a && s[i] != '-') {
			valid_flg = 0;
			break;
		} else if (i != a && s[i] == '-') {
			valid_flg = 0;
			break;
		}
	}
	printf(valid_flg ? "Yes" : "No");
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    vector<int>c;
    int d;vector<vector<int>>s;
    vector<int>last;
    auto calc=[&](int t,int day){
        int k=0;
        k+=s[day][t];
        for (int j = 0; j < 26; ++j){
            if(j==t)continue;
            else  k-=c[j]*(day+1-last[j]);
        }
        return k;
    };
    cin >>d;
    c.resize(26);
    for (int i = 0; i <26; ++i) cin >>c[i];
    s.assign(d,vector<int>(26));
    for (int i = 0; i < d; ++i)for (int j = 0; j < 26; ++j) cin >>s[i][j];
    int score=0;
    last.assign(26,0);
    vector<int>t(d);
    vector<P>p(d);
    for (int day = 0; day < d; ++day) {
        int now=-INF,now2=-INF;int d=INF;
        for (int i = 0; i < 26; ++i) {
//            if(day==4&&i==19){
//                cout <<now<<" "<<calc(i,day)<<" "<<endl;
//            }
           if(now<calc(i,day)){
               now=calc(i,day);
               t[day]=i+1;
               p[day].first=i+1;
           }
           else if(now2<calc(i,day)){
               now2=calc(i,day);
               p[day].second=i+1;
           }
        }
        last[t[day]-1]=day+1;
        score+=now;
//        cout <<score<<endl;
    }
    vector<int>copy(d);
    vector<int>lcopy(d);
    auto ucalc=[&](){
        int kk=0;
        for (int i = 0; i < d; ++i) {
            kk+=s[i][copy[i]];
            lcopy[copy[i]]=i+1;
            for (int j = 0; j < 26; ++j)score-=c[j]*(i+1-lcopy[j]);
            return kk;
        }
    };
    for (int i = 0; i < 1 << 16; ++i) {
        copy=t;lcopy=last;
        for (int j =0; j <16; ++j) {
            int k=d-j-1;
            if((1>>j)&1){
                copy[k]=p[k].second;
            }
        }
        if(score<ucalc()) {
            score = ucalc();
            t = copy;
            lcopy = last;
        }
    }
    for (int i = 0; i < d; ++i) {
        cout<<t[i]<<endl;
    }
//    for (int i = 0; i < 26; ++i) {
//        cout <<last[i]<<endl;
//    }
//    cout <<score<<endl;
    return 0;
}

Measured memory_bytes: 3716
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Vaibhav Pal
 */

#include <bits/stdc++.h>

using namespace std;

struct BYYMMOrMMYY {

    void solve(istream& in, ostream& out) {
        string s;
        in>>s;
        int a=stoi(s.substr(0,2)),b=stoi(s.substr(2));
        bool x=(/*(a==0||a>12) && */(1<=b&&b<=12));//yymm
        bool y=((1<=a&&a<=12) /*&& (b==0||b>12)*/);//mmyy
        if(x&&y)out<<"AMBIGUOUS\n";
        else if(x)out<<"YYMM\n";
        else if(y)out<<"MMYY\n";
        else out<<"NA\n";
    }
};


int main() {
	BYYMMOrMMYY solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int a[5];
  for (int i = 0; i < 5; ++i)
    cin >> a[i];
  int k;
  cin >> k;
  for (int i = 0; i < 5; ++i)
  {
    for (int j = i + 1; j < 5; ++j)
    {
      if (a[j] - a[i] > k)
      {
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;

signed main(){
    
    double a,b,c;
    int x1,x2,x3,y1,y2,y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    a = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
    b = sqrt((x1-x3)*(x1-x3) + (y1-y3)*(y1-y3));
    c = sqrt((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2));
    
    double A,B,C;
    A = ((a*a - b*b - c*c)/(-2*b*c));
    B = ((b*b - c*c - a*a)/(-2*a*c));
    C = ((c*c - a*a - b*b)/(-2*b*a));
    A = sqrt((1-A)/(1+A));
    B = sqrt((1-B)/(1+B));
    C = sqrt((1-C)/(1+C));

    double ans = max({c/(1/A+1/B+2),a/(1/C+1/B+2),b/(1/A+1/C+2)});
    printf("%.12lf\n",ans);


    
    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://cf16-exhibition-final-open.contest.atcoder.jp/tasks/cf16_exhibition_final_a


Measured memory_bytes: 256
N,K,Q = list(map(int,input().split()))
A = [K] * N
C = 0
for i in range(Q):
  B = int(input())
  A[B-1] += 1
  C += 1
for j in range(N):
  if A[j] > C:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 6596
#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  map<string, int> M;
  while (q--) {
    int op;
    cin >> op;
    if (op == 0) {
      string k;
      int x;
      cin >> k >> x;
      M[k] = x;
    } else if (op == 1) {
      string k;
      cin >> k;
      cout << M[k] << endl;
    } else {
      string k;
      cin >> k;
      M[k] = 0;
    }
  }
}


Measured memory_bytes: 27832