akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#include<array>
#include<cmath>

using namespace std;

int main(){/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

    string s, k, l = "5";
    cin>>s;
    int q, temp, t1, rev = 0;
    cin>>q;
    while(q--){
        cin>>temp;
        if(temp == 1){
            rev++;
        }
        else{
            cin>>t1>>k;
            if(t1 == 1){
                if(rev % 2){
                    l = l + k;
                }else{
                    l = k + l;
                }
            }
            else{
                if(rev % 2){
                    l = k + l;
                }else{
                    l = l + k;
                }
            }
        }
    }
    if(rev % 2){
        reverse(s.begin(), s.end());
    }
    int occ = l.find("5");
    string s1 = l.substr(0, occ), s2 = l.substr(occ + 1, l.size() - occ);
    if(rev % 2){
        reverse(s2.begin(), s2.end());
        reverse(s1.begin(), s1.end());
        cout<<s2 + s + s1<<endl;
    }
    else{
        cout<<s1 + s + s2<<endl;
    }
    
}

Measured memory_bytes: 1764
n = int(input())
s = input()

def im(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
R = im(s, "R")
G = im(s, "G")
B = im(s, "B")

ext = 0
if n >= 3:
    for i in range((n-3)//2+1):
        for j in range(n-(3+2*i)+1):
            if s[j] != s[j+i+1] and s[j] != s[j+2*(i+1)] and s[j+i+1] != s[j+2*(i+1)]:
                ext += 1

ans = len(R)*len(G)*len(B) - ext
print(ans)


Measured memory_bytes: 9240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS=1e-10;
const ll INF=1000000000;
double add(double a,double b){
    if(abs(a+b)<EPS*(abs(a)+abs(b))){
        return 0;
    }
    return a+b;
}
struct P{
    int idx;
    double x,y;
    P(){}
    P(double x,double y):x(x),y(y){
    }
    P operator+(P p){
        return P(add(x,p.x),add(y,p.y));
    }
    P operator-(P p){
        return P(add(x,-p.x),add(y,-p.y));
    }
    P operator*(double d){
        return P(x*d,y*d);
    }
    double dot(P p){
        return add(x*p.x,y*p.y);
    }
    double det(P p){
        return add(x*p.y,-y*p.x);
    }
};
///////////////////////////////
//凸包
//辞書順比較

bool cmp_x(const P& p,const P& q){
    if(p.x!=q.x){
        return p.x<q.x;
    }
    return p.y<q.y;
}
vector<P> convex_hull(P* ps,int n){
    sort(ps,ps+n,cmp_x);
    int k=0;
    vector<P> qs(n*2);
    //下側凸包
    for(int i=0;i<n;i++){
        while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0){
            k--;
        }
        qs[k++]=ps[i];
    }
    //上側凸包
    for(int i=n-2,t=k;i>=0;i--){
        while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0){
            k--;
        }
        qs[k++]=ps[i];
    }
    qs.resize(k-1);
    return qs;
}
double dist(P p,P q){
    return (p-q).dot(p-q);
}

int main(){
    int n;
    cin>>n;
    P p[110];
    for(int i=0;i<n;i++){
        cin>>p[i].x>>p[i].y;
        p[i].idx=i;
    }
    vector<P> v=convex_hull(p,n);
    int idx=0;
    int s=v.size();
    double ans[110]={};
    for(int i=0;i<s;i++){
        P a;P b;
        a.x=v[(i+1)%s].x-v[i].x;
        b.x=v[(i-1+s)%s].x-v[i].x;
        a.y=v[(i+1)%s].y-v[i].y;
        b.y=v[(i-1+s)%s].y-v[i].y;
        double al=sqrt((a.x*a.x)+(a.y*a.y));
        double bl=sqrt((b.x*b.x)+(b.y*b.y));
        double th=(a.dot(b))/(al*bl);
        th=max(-1.0,min(1.0,th));
        th=acos(th);
        ans[v[i].idx]=(180.0-(th*180.0/M_PI))/360.0;
    }
    for(int i=0;i<n;i++){
        cout<<fixed<<setprecision(10)<<ans[i]<<endl;
    }
    getchar();
    getchar();
    return 0;
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

Int b[101][200001];

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    for (Int i = 0; i < (Int)n; i++) {
        cin >> a[i];
        a[i]--;
    }
    for (Int i = 0; i < (Int)n; i++) {
        b[0][i] = a[i];
    }
    for (Int i = 0; i < (Int)100; i++) {
        for (Int j = 0; j < (Int)n; j++) {
            b[i + 1][j] = b[i][b[i][j]];
        }
    }
    Int cur = 0;
    Int cnt = 0;
    while (k > 0) {
        if (k & 1) {
            cur = b[cnt][cur];
        } 
        cnt++;
        k >>= 1;
    }
    print(cur + 1);
    return 0;
}

Measured memory_bytes: 162696
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    if (N <= 999) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

bool cant[20][20];
long long mp[20][20];
int a,b,ans;

int main()
{
	while(cin >> a >> b,a)
	{
		for(int i = 0;i < 20;i++)for(int j = 0;j < 20;j++)
		{
			mp[i][j] = 0;
			cant[i][j] = false;
		}
		ans = 0;
		
		int n;
		cin >> n;
		
		for(int i = 0;i < n;i++)
		{
			int x,y;
			cin >> x >> y;
			cant[x-1][y-1] = true;
		}
		
		for(int i = 0;i < 20;i++)
		{
			if(cant[i][0])break;
			mp[i][0]=1;		
		}
		for(int i = 0;i < 20;i++)
		{
			if(cant[0][i])break;
			mp[0][i]=1;		
		}
		
		
		for(int i = 1;i < a ;i++)for(int j = 1;j < b;j++)
		{
			int tmp = 0;
			if(i > 0)tmp += mp[i-1][j];
			if(j > 0)tmp += mp[i][j-1];
			if(!cant[i][j])
			{
				mp[i][j] = tmp;
			}
			else
			{
				mp[i][j] = 0;
			}
			
		}

		cout << mp[a-1][b-1] << endl;
	}
	
	return 0;
}	

Measured memory_bytes: 3004
N,M = map(int,input().split())
a = [ list(input()) for i in range(N) ]

t = 0
for i in range(N):
    for j in range(M):
        if a[i][j] == "#":
            if t <= j:
                t = j
            else:
                print("Impossible")
                exit()
print("Possible")


Measured memory_bytes: 38256
using System;

namespace B___Choose_Integers
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var a = int.Parse (input[0]);
            var b = int.Parse (input[1]);
            var c = int.Parse (input[2]);
            for (var i = 1; i <= b; i++)
            {
                if ((a * i) % b == c)
                {
                    Console.WriteLine ("YES");
                    return;
                }
            }
            Console.WriteLine ("NO");
        }
    }
}

Measured memory_bytes: 11092
from math import sqrt
def solve(B):
    ans = 0
    for L in range(1,int(sqrt(1+8*B))+2):
        # print(L)
        a = (2*B+L*L-L)
        b = (2*L)
        if(a%b==0):
            u = a//b
            d = u - L + 1
            if(1<=d<=u):
                # print(":",d,u)
                ans = L
                ans_d = d
            

    print(ans_d,ans)


def main():
    while(True):
        N=int(input())
        if(N):
            solve(N)
        else:
            break
if __name__ == "__main__":
    main()












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

int main(){
    int r, c, hsum, hsum2, vsum, vsum2;
    cin >> r >> c;
    int A[200][200];
    for (int i = 0; i < r; ++i){
        hsum = 0;
        for (int j = 0; j < c; ++j){
            cin >> A[i][j];
            hsum += A[i][j];
        }
        A[i][c] = hsum;
        hsum2 += hsum;
    }
    
    // すでに行の合計は求めている
    for (int j = 0; j <= c; ++j){
        vsum = 0;
        for (int i = 0; i < r; ++i){
            vsum += A[i][j];
        }
        A[r][j] = vsum;
    }
    
    
    for (int i = 0; i <= r; ++i){
        for (int j = 0; j <= c; ++j){
            if (j == 0) cout << A[i][j];
            else cout << " " << A[i][j];
        }
        cout << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

int N;
vector<int> A;
int used[1000000 + 10];
bool isdouble[1000000 + 10];

int main(){
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; i++)cin >> A[i];

    sort(A.begin(), A.end());
    for (int i = 0; i < N - 1; i++) {
        if (A[i] == A[i + 1])isdouble[A[i]] = true;
    }
    A.erase(unique(A.begin(), A.end()), A.end());
    N = A.size();
    bool used[1000000 + 10] = {};
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = A[i] * 2; j <= 1000000; j += A[i]) {
            used[j] = true;
        }
    }
    for (int i = 0; i < N; i++) {
        if (!used[A[i]] && !isdouble[A[i]])ans++;
    }
    cout << ans << endl;

    return 0;
}


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

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

int main()
{
    int a[3];cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[2]*10+a[1]+a[0];
}


Measured memory_bytes: 256
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 100;

int n, h, a[N], sum;

int main() {
	cin >> h >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	cout << (sum >= h? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  int n;
  ll sum = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) sum += i;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3636
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for _ in range(N):
  A = list(map(int, input().split()))
  x = C
  for a, b in zip(A, B):
    x += a*b
  if x > 0:
    ans += 1
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main(){
    ld a,b;cin>>a>>b;
    ld ans=a*b;
    ll res=floor(ans);
    cout<<res<<endl;
}


Measured memory_bytes: 3732
import queue

k = int(input())
q = queue.Queue()
x = -1
for i in range(1,10):
    q.put(i)
for i in range(1,k+1):
    x = q.get()
    if x % 10 != 0:
        q.put(10 * x + (x % 10) - 1)
    q.put(10 * x + (x % 10))
    if x % 10 != 9:
        q.put(10 * x + (x % 10) + 1)
print(x)

Measured memory_bytes: 12452
# coding: utf-8
# Your code here!
import sys
from collections import Counter
import numpy as np
n=int(input())
S=[]
for i in range(n):
    S.append(input())
s=Counter(S)
keys, values = zip(*s.most_common())

values=np.array(values)
index=np.where(values==np.max(values))
answer=[]
for i in index[0]:
    answer.append(keys[i])
answer.sort()
for i in answer:
    print(i)

Measured memory_bytes: 79928
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long double EPS = 1e-9;

ll n, k;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;

    if (k % 2) {
        cout << (ll)(pow((long double)(n / k), 3) + EPS);
    } else {
        ll ans = (ll)(pow((long double)(n / k), 3) + EPS);
        ll hm = n / k;
        if (n % k >= k / 2) hm++;
        ans += (ll)(pow((long double)hm, 3) + EPS); 
        cout << ans;
    }
}


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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

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


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll k;
    cin >> n >> k;
    v<int> a(n), f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];

    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());

    ll l = -1, r = 1e12;
    while(l+1<r) {
        ll mid = (l+r)/2;
        bool ok = [&](){
            ll s = 0;
            rep(i,n) {
                s += max(0ll, a[i] - mid / f[i]);
            }
            return s <= k;
        }();
        if (ok) r = mid;
        else l = mid;
    };
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{ 
        public static void main(String[] args){
            int i=0,j=0,count=0,d,sum=0,s=0;
            String a;
            char c;
            int b[];
            b = new int[100000];
                Scanner n = new Scanner(System.in);
                while(true){
                     a = n.nextLine();
                     sum = 0;
                     for(i=0;i<a.length();i++){
                         c = a.charAt(i);
                         d = Character.getNumericValue(c);
                         if(d==0 && (a.length())==1){
                             s=1;
                             break;
                         }
                         sum = sum + d;
                     }
                     if(s==1){
                         break;
                     }
                     b[j] = sum; 
                     count++;
                     j++;
                }
                i=0;
                while(count>i){
                     System.out.println(b[i]);
                     i++;
                }
        }
    }


Measured memory_bytes: 26956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll x[n+5];
    for(ll i=0;i<n;i++)
    {
        cin>>x[i];
    }
    sort(x,x+n);
    ll sum=0;
    for(ll i=0;i<n-1;i++)
    {
        sum+=x[i];
    }
    if(sum>x[n-1])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
    int n;
    vector<int> prefix;
    vector<int> suffix;
    int lower_sum = 0;
    scanf("%d", &n);
    prefix.assign(n , 0);
    for(int i=0; i<n ; ++i) {
        scanf("%d", &prefix[i]);
        prefix[i] = prefix[i-1]+prefix[i];
    }
    for(int i=0; i<n ;++i) {
       int in;
       scanf("%d", &in);
       suffix.push_back(in);
    }
    for(int i=n-2; i>=0; i--) {
        suffix[i] = suffix[i+1] + suffix[i];
    }
    int max_coll = 0;
    for(int i=0; i<n; ++i) {
        int tot_collected = prefix[i] + suffix[i];
        if(max_coll < tot_collected) {
            max_coll = tot_collected;
        }
    }
    printf("%d\n", max_coll);

}

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

typedef long long ll;

int main() {
    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> a(N + 1, W);
    rep(i, N) cin >> a[i + 1];
    //dpx[i][j]: Xの番で山札上がa[i]でYがa[j]を持ってる時のスコア
    //dpy[i][j]: Yの番で山札上がa[i]でXがa[j]を持ってる時のスコア
    vector<vector<int>> dpx(N + 1, vector<int>(N + 1)), dpy(N + 1, vector<int>(N + 1));
    rep(i, N) {
        dpx[N][i] = abs(a[N] - a[i]);
        dpy[N][i] = abs(a[N] - a[i]);
    }
    for (int i = N - 1; i > 0; i--) {
        rep(j, i) {
            dpx[i][j] = max(dpy[i + 1][i], dpx[i + 1][j]);
            dpy[i][j] = min(dpx[i + 1][i], dpy[i + 1][j]);
        }
    }
    /*
    rep(i, N + 1) {
        rep(j, N + 1) {
            cout << "dpx[" << i << "," << j << "]=" << dpx[i][j];
            cout << " dpy[" << i << "," << j << "]=" << dpx[i][j] << endl;
        }
    }
    */
    cout << dpx[1][0] << endl;
}

Measured memory_bytes: 31744
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll p[mx],a[mx],b[mx];
#define PB push_back
//#define '\n' endl
#define S second
#define F first
int main()
{
    faster();
    char a,b;
    cin>>a>>b;
    int len1,len2;
    len1=a-'0';
    len2=b-'0';
    string s1,s2;
    s1="",s2="";
    for(int i=0; i<len2; i++)
        s1+=a;
    for(int i=0; i<len1; i++)
        s2+=b;
    if(s1>=s2)
        cout<<s2<<endl;
    else
        cout<<s1<<endl;


    return  0;
}


Measured memory_bytes: 3608
import numpy as np

N = 10 ** 6
Nsq = 10 ** 3
mod = 998244353

n, m, k = map(int, input().split())

fac = np.arange(N, dtype=np.int64).reshape(Nsq, Nsq)
fac[0, 0] = 1
for i in range(1, Nsq):
    fac[:, i] *= fac[:, i - 1]; fac[:, i] %= mod
for i in range(1, Nsq):
    fac[i] *= fac[i - 1, -1]; fac[i] %= mod
fac = fac.ravel()

finv = np.arange(1, N+1, dtype=np.int64)[::-1].reshape(Nsq, Nsq)
finv[0, 0] = pow(int(fac[N-1]), mod - 2, mod)
for i in range(1, Nsq):
    finv[:, i] *= finv[:, i - 1]; finv[:, i] %= mod
for i in range(1, Nsq):
    finv[i] *= finv[i - 1, -1]; finv[i] %= mod
finv = finv.ravel()[::-1]


def nCr(a, b):
    comb = fac[a] * finv[b] % mod * finv[a-b] % mod
    return comb


prt = [1] * (n + 1)
for i in range(n):
    prt[i + 1] = prt[i] * (m - 1) % mod

res = 0
for i in range(k + 1):
    res += m * prt[n - i - 1] % mod * nCr(n-1, i)
    res %= mod
print(res)


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

int main() {
  int N; cin >> N;
  vector<vector<int>> imos(1001, vector<int>(1001, 0));
  for (int i = 0; i < N; ++i) {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    ++imos[x1][y1];
    --imos[x2][y1];
    --imos[x1][y2];
    ++imos[x2][y2];
  }

  for (int i = 0; i < 1001; ++i) {
    for (int j = 0; j < 1000; ++j) imos[i][j + 1] += imos[i][j];
  }
  for (int i = 0; i < 1000; ++i) {
    for (int j = 0; j < 1001; ++j) imos[i + 1][j] += imos[i][j];
  }

  int ans = 0;
  for (int i = 0; i < 1000; ++i) {
    for (int j = 0; j < 1000; ++j) ans = max(ans, imos[i][j]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 6840
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll a=in(),b=in();
    for(int i=0;i<2000;++i){
        if(i*8/100==a&&i*10/100==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int A,B,M,priceA,priceB,priceC;
    cin>>A>>B>>M;
    int a[A],b[B],x[M],y[M],c[M];
    for(int i=0;i<A;i++){
        cin>>a[i];
    }
    for(int i=0;i<B;i++){
        cin>>b[i];
    }
    for(int i=0;i<M;i++){
        cin>>x[i]>>y[i]>>c[i];
    }
    for(int i=0;i<A;i++){
        if(i==0){
            priceA=a[0];
        }
        else{
            priceA=min(priceA,a[i]);
        }
    }
    for(int i=0;i<B;i++){
        if(i==0){
            priceB=b[0];
        }
        else{
            priceB=min(priceB,b[i]);
        }
    }
    for(int k=0;k<M;k++){
        if(k==0){
            priceC=a[x[0]-1]+b[y[0]-1]-c[0];
        }
        else{
            priceC=min(priceC,a[x[k]-1]+b[y[k]-1]-c[k]);
        }
    }
    cout<<min(priceA+priceB,priceC)<<endl;
    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#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);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
vector<vector<pair<int,ll>>> G(N);
vector<int> color(N);
void dfs(int x,int p,ll w){
    color[x]=w%2;
    for(auto e:G[x]){
        if(e.first!=p){
            dfs(e.first,x,w+e.second);
        }
    }
}
main(){
    int n=in();
    rep(i,n-1){
        int u=in(),v=in(),w=lin();
        G[u].pb({v,w});
        G[v].pb({u,w});
    }
    dfs(1,0,0ll);
    rep2(i,1,n){
        cout<<color[i]<<endl;
    }
}



Measured memory_bytes: 20736
var
 a,b:array[1..20] of longint;
 s,i,n:longint;
begin
 readln(n);
  for i:=1 to n do read(a[i]);
  for i:=1 to n do read(b[i]);
  s:=0;
  for i:=1 to n do if (a[i]-b[i]>0) then inc(s,a[i]-b[i]);
 writeln(s);
 end.
  

Measured memory_bytes: 128
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1
print(ans)


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
const   int            inf = 0;
const   double         eps = 0;
const   int            ms  = 0;
const   int            md  = 0;


int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[N];
  int temp;
  for (int i = 0; i < N; i++) {
      cin >> temp;
      A[temp - 1] = i + 1;
  }
  for (int j = 0; j < N; j++) {
      if (j == N - 1) {
          cout << A[j];
      }
      else {
          cout << A[j] << " ";
      }
  }
  return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC153A
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var H = NN;
            var A = NN;
            var cnt = 0;
            while (H > 0)
            {
                H -= A;
                ++cnt;
            }
            Console.WriteLine(cnt);
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 14688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    scanf("%d", &n);
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    printf("%lld\n", ans);
    return 0;
}


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

void solve(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << (a > b ? b : a) << " ";
    cout << (n - a - b > 0 ? 0 : a + b - n) << endl;
}
int main(){
    solve();
    return 0;
}

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

int main(int argc, char const *argv[]) {
  int n;  cin >> n;
  vector<vector<int> > a(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      int v;  cin >> v;
      a[u - 1][v - 1] = 1;
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << a[i][j];
      if (j < n - 1) {
        cout << " ";
      }
    }
    cout << '\n';
  }
  return 0;
}



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

int main(){

  char str[2][105]={{0}};
  scanf("%s",str[0]);
  scanf("%s",str[1]);

  int i;int f=0;
  int j;
  int size=0;
  while(str[0][size] !=0){
    size++;
  }
  for(i=0;i<size;++i){
    int j;
    if(memcmp(str[0],str[1],sizeof(str[0]))==0){
      f=1;
      break;
    }else{
      char temp=str[0][size-1];
      for(j=size-1;j>0;j--){
        str[0][j]=str[0][j-1];
      }
      str[0][0]=temp;
    }
  }
  if(f==0)puts("No");
  if(f==1)puts("Yes");
  return 0;
}


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

int main()
{
    int n,q;
    cin >> n >> q;
    queue< pair<string,int> > Q;
    string s;
    int t;
    for(int i=0;i<n;i++){
        cin >> s >> t;
        Q.push(make_pair(s,t));
    }
    int time = 0;
    while(!Q.empty()){
        pair<string,int> a = Q.front();Q.pop();
        int mint = min(a.second,q);
        time += mint;
        a.second -= mint;
        if(a.second > 0)
            Q.push(a);
        else
            cout << a.first << ' ' << time << endl;
    }
}
 


Measured memory_bytes: 6276
A=[list(map(int,input().split())) for i  in range(3)]
if A[0][0]+A[1][1]==A[0][1]+A[1][0] and A[1][1]+A[2][2]==A[1][2]+A[2][1] and A[0][0]+A[2][2]==A[0][2]+A[2][0] :
    print("Yes")
else:
    print("No")

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

struct city {
    int index;
    int p;
    int y;
    char s[13];
};

bool asc_y(const city& left, const city& right) {
    return left.p == right.p ? left.y < right.y : left.p < right.p;
}

bool asc_index(const city& left, const city& right) {
    return left.index < right.index;
}

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

    city c[m];

    for (int i = 0; i < m; i++) {
        c[i].index = i;

        cin >> c[i].p >> c[i].y;
    }

    /*
    for (int i = 0; i < m; i++) {
        cout << c[i].p << "-" <<  c[i].y << endl;
    }
    */

    sort(c, c + m, asc_y);

    int before_p = -1;
    int city_no;

    for (int i = 0; i < m; i++) {
        if (before_p != c[i].p) {
            before_p = c[i].p;
            city_no = 1;
        }
        sprintf(c[i].s, "%06d%06d", c[i].p, city_no++);
    }

    sort(c, c + m, asc_index);

    for (int i = 0; i < m; i++) {
        cout << c[i].s << endl;
    }

    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> A(N),B(N);
    rep(i,0,N)cin >> A[i] >> B[i];
    vector<P>vec(N);
    rep(i,0,N){
        vec[i] = make_pair((A[i] + B[i]), i);
    }
    sort(vec.rbegin(), vec.rend());
    ll ans = 0;
    rep(i,0,N){
        int ind = vec[i].second;
        if(i % 2 == 0)ans += A[ind];
        else ans -= B[ind];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int k; cin >> k;
    if(k <= 9) {
        cout << k << endl;
        return;
    }
    queue<string> que;
    k -= 9;
    que.push("1");
    que.push("2");
    que.push("3");
    que.push("4");
    que.push("5");
    que.push("6");
    que.push("7");
    que.push("8");
    que.push("9");
    while(k > 0) {
        string s = que.front(); que.pop();
        int sz = (int)s.size();
        char c = s[sz - 1];
        char d = c - 1;
        if(d >= '0') {
            string t = s + d;
            que.push(t);
            -- k;
            if(k == 0) {
                cout << t << endl;
                return;
            }
        }
        string u = s + c;
        que.push(u);
        -- k;
        if(k == 0) {
                cout << u << endl;
                return;
        }
        char e = c + 1;
        if(e <= '9') {
            string v = s + e;
            que.push(v);
            --k;
            if(k == 0) {
                cout << v << endl;
                return;
            }
        }
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 4864
#include <functional>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <sstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
using namespace std;
 
#define pii pair<int, int>
#define rank asdf
 
const int mod = (int)1e9 + 7;

string s;

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> s;
    int l = 0, r = (int)s.size() - 1;
    int ans = 0;
    while(r >= l){
        if(s[l] != s[r]) ans++;
        l++, r--;
    }
    cout << ans << endl;
}

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

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    int V[N];
    int C[N];

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

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

    int cost = 0;
    for (int n = 0; n < N; n++)
    {
        if (V[n] > C[n])
        {
            cost += (V[n] - C[n]);
        }
    }

    cout << cost;
    return 0;
}


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

int N , arr[300003] , sum[2];

int main(){
	ios::sync_with_stdio(0); cin >> N;
	for(int i = 1 ; i <= N ; ++i){cin >> arr[i]; sum[i & 1] += arr[i];}
	if(N & 1){
		for(int i = 1 ; i <= N ; ++i) arr[i] = arr[i - 1] + (i & 1 ? arr[i] : -arr[i]);
		int L = -1.5e9 , R = 1.5e9;
		while(L < R){
			int mid = (L + R + 1) >> 1 , pre = 0;
			for(int j = 2 ; j < N && arr[N] - pre < mid ; j += 2)
				if(arr[j - 1] - pre >= mid) pre = min(pre , arr[j]);
			arr[N] - pre >= mid ? L = mid : R = mid - 1;
		}
		printf("%d %d\n" , sum[0] + L , sum[1] - L);
	}
	else printf("%d %d\n" , max(sum[0] , sum[1]) , min(sum[0] , sum[1]));
	return 0;
}

Measured memory_bytes: 1408
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	h := nextInt()
	w := nextInt()
	l := make([]string, h)
	for i := 0; i < h; i++ {
		l[i] = nextStr()
	}

	fmt.Println(strings.Repeat("#", w+2))
	for i := 0; i < h; i++ {
		fmt.Printf("#%s#\n", l[i])
	}
	fmt.Println(strings.Repeat("#", w+2))
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int n, a, b, c;
int l[10];
int ans = 10e7;

void dfs(int x, int y, int z, int d, int i) {
  if(i==n) {
    if(x==0 || y==0 || z==0) return;
    int key = abs(a-x) + abs(b-y) + abs(c-z) + 10*(d-3);
    ans = min(ans, key);
    return;
  }
  dfs(x,y,z,d,i+1);
  dfs(x+l[i],y,z,d+1,i+1);
  dfs(x,y+l[i],z,d+1,i+1);
  dfs(x,y,z+l[i],d+1,i+1);
}

int main() {
  cin >> n >> a >> b >> c;
  rep(i,n) cin >> l[i];
  dfs(0,0,0,0,0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import product
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
mention = []
for _ in range(N):
    A = int(input())
    xy = [list(map(int, input().split())) for _ in range(A)]
    mention.append(xy)

ans = 0
for pair in product(range(2), repeat=N):
    isOK = True
    for i, p in enumerate(pair):
        if not p:
            continue
        for x, y in mention[i]:
            if pair[x - 1] != y:
                isOK = False
    if isOK:
        ans = max(ans, sum(pair))

print(ans)

Measured memory_bytes: 3064
import bisect

n = int(input())
s = list(map(int, input().split(" ")))
# n = 18
# s = list(reversed(range(1, 2 ** n + 1)))

s = sorted(s)
from collections import deque

def solve():
    global s

    parents = [s[-1]]
    s.pop()

    for i in range(n):
        newparents = list(parents)
        k = len(s)
        dropped = set()
        # print(parents)
        for p in parents:
            oldK = k
            k = bisect.bisect(s, p - 1, 0, k) - 1
            # print("Old", oldK, k, s[k], p)
            if k == -1:
                print("No")
                exit(0)

            newparents.append(s[k])
            dropped.add(k)
        s = [x for i, x in enumerate(s) if i not in dropped]
        parents = sorted(newparents, reverse=True)

    # print(parents)
    # print(k)
    if k == len(s):
        print("Yes")
    else:
        print("No")
solve()


Measured memory_bytes: 119004
#include <bits/stdc++.h>
#define pb push_back
#define long long long
#define pll pair < long , long >
#define vll vector < pll >
#define ml map < long , long >
#define mll map < pll , long >
#define x first
#define y second
#define vl vector < long >
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    io
    ml mp;
    set < long > s;
    set < long > ::iterator it;
    long n,i,x,m1=0,m2=0,m3=0;
    cin>>n;
    for(i=0;i<n;++i)
    {
        cin>>x;
        mp[x]++;
        s.insert(x);
        if(mp[x]>=4) m3=max(x,m3);
    }
    it=s.end();
    it--;
    for(;;it--)
    {
        if(mp[*it]>=2)
        {
            if(m1==0) m1=*it;
            else if(m2==0) m2=*it;
            else break;
        }
        if(it==s.begin()) break;
    }
    cout<<max(m3*m3,m1*m2);
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll mod = 1000000007;


int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	map<ll,ll> mp;

	for(ll i = 0; i < n; i++){
		cin >> a[i];
		mp[a[i]]++;
	}

	ll sum = 0;
	for(auto i : mp){
		sum += i.second * (i.second - 1) / 2;
	}

	for(ll i = 0; i < n; i++){
		ll ans = sum - (mp[a[i]] - 1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 12544
n,k = gets.chomp.split.map(&:to_i)
d = gets.chomp.split.map(&:to_i)

n.upto(n*10) do |i|
    nn = []
    tmp = i
    while tmp > 0 do
        nn.unshift(tmp%10)
        tmp /= 10
    end
    if (nn & d).size == 0
        puts i
        exit
    end
end

Measured memory_bytes: 2172
N, M , X, Y = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

min_y = min(y)
max_x = max(x)

count_x = sum(t < min_y for t in x)

re = 'War'
if count_x == N : # and count_y == M:
    if  X < min_y and min_y <= Y:
        re = 'No War'
    elif X < max_x + 1 and max_x + 1 <= Y:
        re = 'No War'
    
print(re)

Measured memory_bytes: 3064
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect

# from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n, m = map(int, input().split())

data = getInputIntList()

total = sum(data)

if n < total:
    print(-1)
else:
    print(n-total)





Measured memory_bytes: 11240
#include<string>
#include<iostream>
using namespace std;
int main(){
  string str;
  while(cin>>str){
    while(str.size()>1){
      int an[str.size()-1]={};
      for(int i=1;i<str.size();i++){
	an[i-1]=((str[i]-'0')+(str[i-1]-'0'))%10;
      }
      string str2="";
      for(int i=0;i<str.size()-1;i++){
	char c=an[i]+'0';
	str2+=c;
      }
      str=str2;
    }
    cout<<str<<endl;
  }
  return 0;
}

Measured memory_bytes: 3196
//#pragma GCC optimize("Ofast")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include<unordered_set>

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MAX = 100010;
int MOD = (ll)1000000000 + 7;
ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;


typedef pair<ll, int>P;//firstは距離、secondは頂点番号
struct Ver { ll dist; unordered_set<int>company; };//頂点に、始点からの距離と最後に使った会社を持たせる
struct edge { int to, cmp; };//辺には行き先の頂点と会社を持たせる
Ver d[100010];
int V;//頂点数
int M;//辺の本数

vector<edge>G[100010];//グラフ
					  //int d[MAX];//始点からの距離
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	set<int>st;//キューに入っている頂点番号
			   //全点への距離をINFで初期化
	for (int i = 0; i < V + 1; ++i) {
		d[i].dist = INF;
	}
	//始点への距離は0
	d[s].dist = 0;
	//始点をキューに入れる
	que.push(P(0, s)); st.insert(s);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		auto c = st.erase(p.second);
		int v = p.second;//今見ている頂点
		if (d[v].dist < p.first)continue;

		//今見ている頂点につながるすべての辺について距離を更新する
		int n = G[v].size();
		for (int i = 0; i < n; ++i) {
			edge e = G[v][i];
			int cost = 1;
			//vに訪れるのに最後に使った会社(複数の場合もある)が今見ている辺の会社と同じならコストを0にする
			if (d[v].company.find(e.cmp) != d[v].company.end())cost = 0;
			//今見ている辺を使うことでe.toへの距離が小さくなるなら、距離を更新し、最後に使った会社をe.cmpとする
			if (d[e.to].dist > d[v].dist + cost) {
				d[e.to] = { d[v].dist + cost,{ e.cmp } };
				que.push(P(d[e.to].dist, e.to)); st.insert(e.to);
			}
			//今見ている辺を使っても距離が変わらない場合、最後に使った会社に(もしe.cmpがなかったら)e.cmpを追加する
			else if (d[e.to].dist == d[v].dist + cost) {
				if (d[e.to].company.find(e.cmp) == d[e.to].company.end()) {
					d[e.to].company.insert(e.cmp);
					if (st.find(e.to) == st.end()) {
						que.push(P(d[e.to].dist, e.to)); st.insert(e.to);
					}
				}

			}
		}
	}
}

int main() {
	cin >> V >> M;
	int p, q, c;
	for (int i = 0; i < M; i++) {
		scanf("%d %d %d", &p, &q, &c);
		G[p].push_back({ q,c });
		G[q].push_back({ p,c });
	}
	dijkstra(1);
	ll ans = d[V].dist;
	if (ans == INF) {
		cout << -1 << endl; return 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 32216
#include<bits/stdc++.h>
using namespace std;
long long p[100000],pcnt[100001],a[100001],b[100001],c[100001];
int main(void){
	long long n,m,i,ima,x,t,tt,sum;
	cin>>n>>m;
	for(i=0;i<m;i++) cin>>p[i];
	ima=p[0];
	for(i=0;i<=m;i++) pcnt[i]=0;
	for(i=1;i<m;i++){
		x=p[i]-ima;
		if(x>=0){
			pcnt[ima]++;
			ima=ima+x;
			pcnt[ima]--;
		}
		else{
			pcnt[ima]--;
			ima=ima+x;
			pcnt[ima]++;
		}
	}
	for(i=1;i<n;i++) pcnt[i]=pcnt[i]+pcnt[i-1];
//	for(i=1;i<n;i++) cout<<pcnt[i]<<' ';
//	cout<<endl;
	sum=0;
	for(i=1;i<n;i++) cin>>a[i]>>b[i]>>c[i];
	for(i=1;i<n;i++){
		t=c[i]+b[i]*pcnt[i]; tt=a[i]*pcnt[i];
		if(t<tt) sum+=t;
		else sum+=tt;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    string s,t;
    cin >> s >> t;
    vector<ll>scnt(26,0);
    vector<ll>tcnt(26,0);
    for(ll i=0;i<s.size();i++){
        scnt[s[i]-'a']++;
        tcnt[t[i]-'a']++;
    }
    sort(scnt.begin(),scnt.end());
    sort(tcnt.begin(),tcnt.end());
    bool judge=true;
    for(ll i=0;i<scnt.size();i++){
        if(scnt[i]!=tcnt[i]){
            judge=false;
        }
    }
    if(judge) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3928