akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    vector<ll> C(n);
    rep(i, n) {
        C[A[i]]++;
    }

    if (n % 2 == 0){
        // 0, 2, 0, 2, ..
        rep(i, C.size()) {
            if (i % 2 == 0 && C[i] == 0) {
            }
            else if (i % 2 == 1 && C[i] == 2) {
            }
            else {
                put(0);
                return;
            }
        }
    }
    else {
        // 1, 0, 2, 0, 2, ...
        rep(i, C.size()) {
            if (i == 0 && C[i] == 1) {
            }
            else if (i % 2 == 0 && C[i] == 2) {
            }
            else if (i % 2 == 1 && C[i] == 0) {
            }
            else {
                put(0);
                return;
            }
        }
    }

    ll MOD = 1000000007;
    ll res = 1;      
    rep(i, n/2) res = (res * 2) % MOD;

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 4632
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N, M;
int SUM = 0;
vector<int>A;
int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A.push_back(a);
		SUM += a;
	}
	int count = 0;
	for (int i = 0; i < N; i++) {
		if (SUM <= 4 * M * A[i]) {
			count++;
		}
	}
	if (count >= M) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;

}

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

using namespace std;

string f(int n, int a) {

    n %= 500;

    if (n <= a) {
        return "Yes";
    }

    return "No";
}

int main() {

    int n;
    cin >> n;

    int a;
    cin >> a;

    string result = f(n, a);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
main :: IO ()
main = do
    [n, m] <- map read . words <$> getLine
    print $
        if n == m then (2 * (fact n ^ 2)) `mod` num
        else if n == m + 1 then ((fact m ^ 2) * n) `mod` num
        else if m == n + 1 then ((fact n ^ 2) * m) `mod` num
        else 0

num :: Integer
num = 10 ^ 9 + 7

fact :: Integer -> Integer
fact 0 = 1
fact n = n * fact (n - 1)


Measured memory_bytes: 7224
n=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

plist=[]
nval=0
ncounter=0

for i in range(n):
	if alist[i] > blist[i]:
		plist.append(alist[i]-blist[i])
	elif alist[i] < blist[i]:
		nval += blist[i] - alist[i]
		ncounter += 1

plist.sort(reverse = True)
i=0
maxi=len(plist)
pcounter = 0

while nval != 0 and i < maxi:
	pcounter += 1
	nval = max(0,nval-plist[i])
	i += 1

if nval == 0:
	print(pcounter + ncounter)
else:
	print(-1)


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n);
  unordered_map<ll, ll> mp;
  a[0] = 0, mp[-1]++;
  for (int i = 1; i < n; ++i) cin >> a[i], mp[a[i]]++;

  for (int i = 0; i < n; ++i) cout << mp[i + 1] << endl;
  return 0;
}


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

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

    string s[n];
    long long cou[5];
    char check[5] = {'M', 'A', 'R', 'C', 'H'};
    for(int i = 0; i < 5; i++){
        cou[i] = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> s[i];
        for(int j = 0; j < 5; j++){
            if(s[i][0] == check[j]){
                cou[j]++;
            }
        }
    }

    long long ans = 0;
    int a[10] = {0,0,0,0,0,0,1,1,1,2};
    int b[10] = {1,1,1,2,2,3,2,2,3,3};
    int c[10] = {2,3,4,3,4,4,3,4,4,4};
    for(int i = 0; i < 10; i++){
        ans += cou[a[i]] * cou[b[i]] * cou[c[i]];
    }

    cout << ans << endl;
}

Measured memory_bytes: 6144
#include <stdio.h>
int main(void) {

	char b;
	scanf("%c", &b);

	if (b == 'A') {
		puts("T");
	}
	else if (b == 'C') {
		puts("G");
	}
	else if (b == 'G') {
		puts("C");
	}
	else {
		puts("A");
	}


	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
int minthis(int a, int b){
if(a < b){
return a;
}
return b;
}
int maxthis(int a, int b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return temp * temp;  
    else
    {  
        if(y > 0)  
            return x * temp * temp;  
        else
            return (temp * temp) / x;  
    }  
}  


void solve(){	
	
	int n;
	cin >> n;
	if(n%1000 == 0){
		cout << "0" << "\n";
	}
	else{
		cout << 1000-n%1000 << "\n";
	}
}
  
int main(){ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;    
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  st s;
  cin >> s;
  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
}

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() {
	ll N,K,Q;
	cin >> N >> K >> Q;
	vector<int> ans(Q);
	rep(i,Q){
		cin >> ans.at(i);
	}
    vector<int> kaitouer(N);
    rep(i,N){
        kaitouer.at(i) = K;
        //cout << kaitouer.at(i) << endl;
    }
    if(K > Q){
        rep(i,N){
            cout << "Yes" << endl;
        }
        return 0;
    }
    rep(i,Q){
        kaitouer.at(ans.at(i)-1)++;
        //cout <<kaitouer.at(0)<< endl;
    }
    rep(i,N){
        kaitouer.at(i)-=Q;
    }
    rep(i,N){
        //cout << kaitouer.at(i) << endl;
        if(kaitouer.at(i) <= 0){
            cout << "No" << endl;
        }else if(kaitouer.at(i) > 0){
            cout << "Yes" << endl;
        }
    }
}


Measured memory_bytes: 1408
N,M = map(int,input().split())
M = [0]*M
for i in range(N):
    likes = [int(i) for i in input().split()]
    for i in range(1,len(likes)):
        M[likes[i]-1]+=1
count = 0
for item in M:
    if item == N:
        count += 1
print(count)

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

int main() {

	int A, B, C, K, ans = 0;

	cin >> A >> B >> C >> K;

	for (int i = 0; i < K; i++) {
		if (A > 0) {
			ans += 1;
			A--;
		}
		else if (B > 0) {
			B--;
		}
		else if (C > 0) {
			ans -= 1;
			C--;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
a, b, k = map(int, input().split())

if a >= k:
  ans_a = a - k
  ans_b = b
elif a < k and b + (a - k) >= 0:
  ans_a = 0
  ans_b = b + (a - k)
else:
  ans_a = 0
  ans_b = 0

print(str(ans_a) + ' ' + str(ans_b))

Measured memory_bytes: 3060
import sys
n=list(input())
N=len(n)
k=int(input())
x=int(n[0])
if N<k:
  print(0)
  sys.exit()

def s1(m):
  N=len(m)
  x=int(m[0])
  if N>1 and x==0:
    m2=m[1:N+1]
    return s1(m2)
  elif x==0:
    return 0
  else:
    ans=0
    ans+=(N-1)*9
    ans+=x
    return ans

def s2(m):
  N=len(m)
  x=int(m[0])
  if N>1 and x==0:
    m2=m[1:N+1]
    return s2(m2)
  elif x==0:
    return 0
  else:
    ans=0
    ans+=((N-1)*(N-2))*81//2
    ans+=((x-1)*(N-1))*9
    m2=m[1:N+1]
    ans+=s1(m2)
    return ans
  
def s3(m):
  N=len(m)
  x=int(m[0])
  if N>1 and x==0:
    m2=m[1:N+1]
    return s3(m2)
  elif x==0:
    return 0
  else:
    ans=0
    ans+=((N-1)*(N-2)*(N-3)*729)//6
    ans+=((x-1)*(N-1)*(N-2)*81)//2
    m2=m[1:N+1]
    ans+=s2(m2)
    return ans

if k==1:
  print(s1(n))
  sys.exit()

if k==2:
  print(s2(n))
  sys.exit()

if k==3:
  print(s3(n))
  sys.exit()

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	double a, b, x;
	cin >> a >> b >> x;

	double ans;
	if (x > (a*a*b / 2)) {
		double t = ((x * 2) / (a * a)) - b;
		ans = atan(a / (b - t));
	}
	else {
		double p = (x*2) / (a*b);
		ans = atan(p / b);
	}

	ans = ans / 3.1415926535;
	ans *= 180;
	ans = 90 - ans;

	cout << setprecision(10) << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

class Binomial {
  private:
  const int Mod = 1e9 + 7;
  vector<int> fac, finv, inv;

  public:
  Binomial(int n) : fac(n, 1), finv(n, 1), inv(n, 1) {
    for(int i = 2; i < n; i++) {
      fac[i] = fac[i-1] * i % Mod;
      inv[i] = Mod - inv[Mod%i] * (Mod/i) % Mod;
      finv[i] = finv[i-1] * inv[i] % Mod;
    }
  }
  int C(int n, int r) {
    if(r > n) return 0;
    return (fac[n] * finv[r] % Mod * finv[n - r] ) % Mod;
  }
  int P(int n, int r) {
    return (fac[n] * finv[n - r]) % Mod;
  }
};

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin() , a.rend());
  Binomial Bm(n + 1);
  int ans = 0;
  for(int i = 0; i < n; i++) {
    ans += (a[i] * Bm.C(n - i - 1, k - 1));
    ans = (ans + Mod) % Mod;
    ans -= (a[i] * Bm.C(i, k - 1)) % Mod;
    ans = (ans + Mod) % Mod;
  }
  ans = (ans + Mod) % Mod;
  cout << ans << '\n';

}

Measured memory_bytes: 6292
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
typedef long long ll;
ll a[N];
const ll mod = 1e9 + 7;
ll pre[N];
ll fac[N];
ll qpow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    fac[0] = 1;
    for (int i = 1; i <= n - 1; i++) fac[i] = fac[i - 1] * i % mod;
    for (int i = 1; i <= n - 1; i++) {
        pre[i] = (pre[i - 1] + fac[n - 1] * qpow(i, mod - 2) % mod) % mod;
    }
    ll ans = 0;
    for (int i = 1; i <= n - 1; i++) {
        ans = (ans + pre[i] * (a[i + 1] - a[i] + mod) % mod) % mod;
    }
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long X;
    cin >> X;
    long long ans = (((long long)(sqrt(8 * X + 1) - 1)) >> 1LL);
    cout << ans + (((ans * ans + ans) >> 1LL) < X) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ccomplex>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>


#define SZ(X) ((X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (LL I = 0; I < N; ++I)
#define REPP(I, A, B) for (LL I = (A); I < (B); ++I)
#define RI(X) scanf("%lld", &(X))
#define RII(X, Y) scanf("%lld%lld", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%lld%lld%lld", &(X), &(Y), &(Z))
#define DRI(X) LL (X); scanf("%lld", &X)
#define DRII(X, Y) LL X, Y; scanf("%lld%lld", &X, &Y)
#define DRIII(X, Y, Z) LL X, Y, Z; scanf("%lld%lld%lld", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define IO(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout);
typedef long long LL;
typedef unsigned long long ull;
using namespace std;

LL A[100];
int main(){
    DRI(N);
    LL sum=0;
    
    REP(i,N){RI(A[i]);sum+=A[i];}
    LL ans=sum%10?sum:0;
    REP(i,N)if((sum-A[i])%10)ans=max(sum-A[i],ans);
    printf("%lld\n",ans);
    
}


Measured memory_bytes: 256
#include <iostream>

int main(){

  int n;
  std::cin >> n;

  int cards[4][13] = {{}};

  char mark;
  int num;

  for(int i=0; i<n; i++){
    std::cin >> mark >> num;

    switch(mark){
    case 'S':
      cards[0][num-1] = 1;
      break;
    case 'H':
      cards[1][num-1] = 1;
      break;
    case 'C':
      cards[2][num-1] = 1;
      break;
    case 'D':
      cards[3][num-1] = 1;
      break;
    }
  }

  for(int i=0; i<52; i++){
     switch(i/13){
    case 0:
      if(cards[0][i%13] == 0){ std::cout << "S "  << i+1 << std::endl; }
      break;
    case 1:
      if(cards[1][i%13] == 0){ std::cout << "H "  << i%13+1 << std::endl; }
      break;
    case 2:
      if(cards[2][i%13] == 0){ std::cout << "C "  << i%13+1 << std::endl; }
      break;
    case 3:
      if(cards[3][i%13] == 0){ std::cout << "D "  << i%13+1 << std::endl; }
      break;
    }
  }
  return 0;
}



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

count = 0

for i in range(N):
    minj = i
    for j in range(i, N, 1):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        A[i], A[minj] = A[minj], A[i]
        count += 1

print(" ".join(map(str, A)))
print(count)



Measured memory_bytes: 5600
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	ll N;
	ll A[200001];
	cin >> N;
	for(int i = 1; i <= N; i++){
		cin >> A[i];
	}
	
	static ll CountLeft[200001];
	fill(CountLeft, CountLeft+(N+1), 0);
	static ll CountRight[2000001];
	fill(CountRight, CountRight+(N+1), 0);
	
	for(int i = 1; i <= N; i++){
		ll a1 = i - A[i];
		ll a2 = i + A[i];
		if(a1 >= 1 && a1 <= N){
			CountLeft[a1]++;
		}
		if(a2 >= 1 && a2 <= N){
			CountRight[a2]++;
		}
	}
	
	ll ans = 0;
	for(int i = 1; i <= N; i++){
		if(CountLeft[i] > 0 && CountRight[i] > 0){
			ans += CountLeft[i] * CountRight[i];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 8324
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int D,N;
    long long ans ;

    cin >> D >> N;

    if(D==0){
        if(N==100){
            ans = 101;
        }else{
            ans = N *1;
        }
    }else if(D==1){
        if(N==100){
            ans = 10100;
        }else{
            ans = N * 100;
        }
    }else if(D==2){
        if(N==100){
            ans = 1010000;
        }else {
            ans = N * 100 * 100;
        }
    }

    cout << ans <<endl;

    return 0;
}


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Int32.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(" ").Select(s => Int64.Parse(s)).ToList();

            long mod = 1000000007;

            var a = input;

            long sum = 0;
            long m = 0;
            for (var i = n - 2; i >= 0; i--)
            {
                m += a[i + 1];
                m %= mod;
                sum += a[i] * m;
                sum %= mod;
            }

            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 47772
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

A_cs = A.cumsum()
A_cs = A_cs - A_cs[-1]/2
div = np.abs(A_cs).argmin()

print(abs(A[:div+1].sum() - A[div+1:].sum()))

Measured memory_bytes: 34208
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
LL powMod(LL num, LL n, LL mod = (LL)MOD) {//(num**n)%mod
	num %= mod;//
	if (n == 0) {
		return (LL)1;
	}
	LL mul = num;
	LL ans = (LL)1;
	while (n) {
		if (n & 1) {
			ans = (ans * mul) % mod;
		}
		mul = (mul * mul) % mod;
		n >>= 1;
	}
	return ans;
}
LL mod_inverse(LL num, LL mod = MOD) {
	return powMod(num, MOD - 2, MOD);
}

void solve() {
	int N;
	cin >> N;
	vector<LL> A(N); IN(A);
	vector<int> P(1000001, 0);
	for (int i = 2; i <= 1000000; ++i) {
		if (P[i] == 0) {
			for (int j = i; j <= 1000000; j += i) {
				P[j] = i;
			}
		}
	}
	
	map<int, int> soi;
	
	for (int i = 0; i < N; ++i) {
		int ter = A[i];
		int now = 1;
		int cnt = 0;
		while (P[ter] != 0) {
			if (now != P[ter]) {
				soi[now] = max(soi[now], cnt);
				now = P[ter];
				cnt = 1;
				ter /= P[ter];
			}
			else {
				++cnt;
				ter /= P[ter];
			}
		}
		soi[now] = max(soi[now], cnt);
	}
	
	LL LCM = 1;
	map<int, int>::iterator itr;

	for (itr = soi.begin(); itr != soi.end();itr++) {
		LCM = (LCM * powMod(itr->first, itr->second)) % MOD;
	}
	
	LL ans = 0;
	for (int i = 0; i < N; ++i) {
		LL res = (LCM * mod_inverse(A[i])) % MOD;
		ans += res;
		ans %= MOD;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 4736
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << (abs(n - a) > abs(n - b) ? 'B' : 'A') << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

bool solve(const string& s) {
    vector<char> st;
    rep(i, s.size()) {
        if(s[i]=='(' || s[i]=='[') st.push_back(s[i]);
        if(s[i]==')' || s[i]==']') {
            if(st.empty()) return false;
            if(s[i]==')' && st.back()!='(') return false;
            if(s[i]==']' && st.back()!='[') return false;
            st.pop_back();
        }
    }
    return st.empty();
}

int main() {
    for(;;) {
        string s;
        getline(cin, s);
        if(s==".") return 0;
        puts(solve(s) ? "yes" : "no");
    }
}

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

int main(){
  int N;
  cin >> N;
  int L[N];
  for(int i=0;i<N;i++){
    cin >> L[i];
  }
  sort(L,L+N);
  int count=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
        if(L[k] < L[i]+L[j]){
          count++;
        }else{
          break;
        }
      }
    }
  }
  cout << count;

}


Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
B = []
count = 0  #Aのなかの負の要素の個数
for i in range(N):
	if A[i] != abs(A[i]):
		count += 1
	B.append(abs(A[i]))
if count % 2 == 0:
	print(sum(B))
else:
	print(sum(B) - min(B) * 2)


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

using namespace std;

int main(){
  long long n,k,a[200009];
  cin >> n >> k;
  for(int i=1;i<=n;i++)cin >> a[i];
  long long memo[200009];
  memset(memo, -1, sizeof(memo));
  memo[1]=0;
  int cur=1;
  while(1){
    k--;
    int next = a[cur];
    if(k==0){
      cout << next << endl;
      return 0;
    }
    if(memo[next]!=-1){
      long long loop=memo[cur]-memo[next]+1;
      cur=next;
      k%=loop;
      while(k--){
        cur=a[cur];
      }
      cout << cur << endl;
      return 0;
    }
    memo[next] = memo[cur] + 1;
    cur = next;
  }
}



Measured memory_bytes: 6780
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

bool in[100005];
int cnt[100005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<ll> cnt(n+1, 0);
    rep(i,n) ++cnt[(i+1)%k];
    ll ans = 0;
    for(int a = 1; a <= n; ++a){
        int idx = (k - (a%k)) % k;
        if(idx != a%k) continue;
        ans += cnt[idx] * cnt[idx];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4764
s = input().split()
n = int(s[3])
sum_=0
if int(s[0]) >= n:
    sum_=1*n
elif int(s[0])+int(s[1]) >= n:
    sum_=1*(n-int(s[1]))
elif int(s[0])+int(s[1])+int(s[2]) >= n:
    sum_=1*int(s[0])+(-1*(n-int(s[0])-int(s[1])))

print(sum_)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  int N; cin >> N;
  vector<int> AS(N);
  REP(i, N) cin >> AS[i];
  sort(AS.begin(), AS.end());
  set<int> st;

  int res = 0;
  REP(i, N) {
    if ((i < N) && AS[i+1] == AS[i]) {
      st.insert(AS[i]);
      continue;
    }
    auto ok = true;
    RNG(k, 1, (int)(sqrt((double)AS[i])+1)) if (AS[i]%k == 0 && ((st.find(k) != st.end()) || st.find(AS[i]/k) != st.end())) {
      ok = false;
      break;
    }

    res += ok;
    st.insert(AS[i]);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 13556
#include<bits/stdc++.h>
using namespace std ;
 
int main()
{
  int n ;
  cin >> n ;
  string str ;
  cin >> str ;
  int cnt = 1 ;
  char cmp = str[0] ;
  for(int i = 0 ; i < n ; i++)
  {
    if(str[i] == cmp)
      continue ;
    else
    {
      cnt++ ;
      cmp = str[i] ;
    }
  }
  cout << cnt << endl ;
  return 0 ;
}

Measured memory_bytes: 512
S = input()
children = [0]*len(S)
search_word = 'L'
index = 0
cnt = 0
for i in range(len(S)):
    if search_word == 'L':
        if S[i] != 'L':
            cnt+=1
        else:
            children[i-1] += cnt//2 + cnt%2
            children[i] += cnt//2 + 1
            search_word = 'R'
            cnt = 0
            index = i
    else:
        if S[i] != 'R':
            cnt+=1
        else:
            children[index - 1] += cnt//2 + cnt%2
            children[index] += cnt//2
            search_word = 'L'
            cnt = 1
if cnt != 0:
    children[index - 1] += cnt//2 + cnt%2
    children[index] += cnt//2
print(*children)

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
const int MOD = 1e9 + 7;
int main() {
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    ll p = 1;
    rep(i, 60){
        ll x = 0, y =0;
        rep(j, n){
            if (a[j]%2 == 0) {
                x++;
            }else {
                y++;
            }
            a[j] = a[j] >> 1;
        }
        ans += (x*y)%MOD*p%MOD;
        ans = ans%MOD;
        p *= 2;
        p %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


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

int main() {
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    VI a(n);
    FOR(i,0,n-1) {
        cin >> a[i];
    }
    
    ll sum = 0;
    FOR(i,0,n-1) {
        sum += a[i];
    }
    
    ll eachTime = (ll) n * (n + 1) / 2;
    
    if (sum % eachTime) {
        cout << "NO";
        return 0;
    }
    
    ll steps = sum / eachTime;
    
    FOR(i,0,n-1) {
        int diff = a[(i + 1) % n] - a[i];
        ll val = steps - diff;
        
        if (val < 0 || (val % n)) {
            cout << "NO";
            return 0;
        }
    }
    
    cout << "YES";    

    return 0;
}

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


Measured memory_bytes: 640
import Data.List
import Text.Printf
nextPyramid (x,y) = if y+1<101 then (x,y+1) else if x+1<101 then (x+1,0) else (-1,-1)
listToTuple [x,y,z] = (x,y,z)

check::(Integer,Integer)->[(Integer,Integer,Integer)]->Integer->Integer
check (x,y) (d:ds) h
    | h==0      = check (x,y) ds (abs (a-x) + abs (b-y) + c)
    | c==tmp    = if ds==[] then h else check (x,y) ds h
    | otherwise = -1
    where
        (a,b,c) = d
        tmp     = max (h - abs (a-x) - abs (b-y)) 0

solve (x,y) tbl
    | ans == -1 = solve (nextPyramid (x,y)) tbl
    | otherwise = (x,y,ans)
    where
        ans     = check (x,y) tbl 0

main::IO()
main=do
    getLine
    tbl <- map (listToTuple.map read.words) . lines <$> getContents :: IO [(Integer,Integer,Integer)]
    let (x,y,h) = solve (0,0) (sortBy (\(a0,a1,a2) (b0,b1,b2) -> compare b2 a2) tbl)
    printf "%d %d %d\n" x y h


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    ll D;
    cin >> N >> D;
    D = D * D;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        ll dist = x * x + y * y;
        if (dist <= D) ans++;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3616
N=int(input())
ans=100000000000
for A in range(1,N):
    B=N-A
    sa=0
    sb=0
    for i in range(len(str(A))):
        sa+=A%10
        A=(A-A%10)//10
    for j in range(len(str(B))):
        sb+=B%10
        B=(B-B%10)//10
    if sa+sb<ans:
        ans=sa+sb

print(ans)


Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

//因数分解
map<int,int> prime_factor(int n){
  map<int,int> mp; //{約数,個数}
  for(int i = 2; i*i <= n; i++){
    while(n%i == 0){
      mp[i]++;
      n /= i;
    }
  }
  if(n != 1) mp[n] = 1; //n=素数
  return mp;
}

signed main(){

  int a,b; cin >> a >> b;
  auto r = prime_factor(a);
  auto q = prime_factor(b);

  vector<int> v,v2;
  for(auto p : r){
    v.push_back(p.first);
  }
  for(auto p : q){
    v2.push_back(p.first);
  }

  int ans = 0;
  for(int p : v){
    int res = *lower_bound(v2.begin(),v2.end(),p);
    if(p == res) ans++;
  }
  cout << ans+1 << endl;

  return 0;
}


Measured memory_bytes: 768
import java.util.*;

/**
 * C Main
 *
 * @date 2020.09.19
 * @author 焼き鮭 <yaki-shake@up-tri.me>
 */

public class Main {

  long MOD = 1000000007;

  Scanner sc;

  public static void main(String[] args) {
    new Main().execute();
  }

  public void execute() {
    this.sc = new Scanner(System.in);
    int n = sc.nextInt();
    long ans = ((modpow(10, n, MOD) + modpow(8, n, MOD)) % MOD) - 2 * modpow(9, n, MOD);
    while (ans < 0) {
      ans += MOD;
    }
    System.out.println(ans);
  }

  public long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if ((n & 1) != 0) {
        res = res * a % mod;
      }
      a = a * a % mod;
      n >>= 1;
    }
    return res;
  }
}


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

#define ll long long

int n, x, cnt[4];
double dp[303][303][303];
// x - no of plates with 1 sushi
// y - no of plates with 2 sushi
// z - no of plates with 3 sushi

double solve (int x, int y, int z) {
	if (x < 0 || y < 0 || z < 0) {
		return 0;
	}

	if (x == 0 && y == 0 && z == 0) {
		return 0;
	}

	if (dp[x][y][z] > -0.9) {
		return dp[x][y][z];
	}

	//dp[x][y][z] = 1 + p0*dp[x][y][z] + px*dp[x-1][y][z] + py * dp[x+1][y-1][z] + pz * dp[x][y+1][z-1];
	//p0 = probability of selecting plate with 0 sushi = n - (x + y + z)/  n;
	//p1 = probability of selecting plate with 1 sushi = x/n;
	//p2 = probability of selecting plate with 2 sushi = y/n;
	//p3 = probability of selecting plate with 3 sushi = z/n;

	return dp[x][y][z] = (n + x * solve(x - 1, y, z) + y * solve (x + 1, y - 1, z) + z * solve (x, y + 1, z - 1)) / (x + y + z);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	cnt[1] = cnt[2] = cnt[3] = 0;

	for (int i = 0; i < n; i++) {
		cin >> x;
		cnt[x]++;
	}

	memset(dp, -1, sizeof dp);
	double ans = solve (cnt[1], cnt[2], cnt[3]);
	cout << fixed << setprecision(10) << ans;
	return 0;
}

Measured memory_bytes: 217600
#include<stdio.h>

int main(){
	int arr[3][3];
	int flag [3][3];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			flag [i][j] = 0;
			scanf("%d", &arr[i][j]);
		}
	}
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				if(a == arr[j][k]){
					flag[j][k] = 1;
				}
			}
		}
	}
	int check = 0;
	for(int i = 0; i < 3; i++){
		if(flag [0][i] && flag [1][i] && flag [2][i]){
			check = 1;
		}
	}
	for(int i = 0; i < 3; i++){
		if(flag [i][0] && flag [i][1] && flag [i][2]){
			check = 1;
		}
	}
	if(flag [0][0] && flag [1][1] && flag [2][2]){
		check = 1;
	}
	if(flag [0][2] && flag [1][1] && flag [2][0]){
		check = 1;
	}
	if(check){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1644
import java.util.*;
import java.io.*;

public class Main {	
	
	private static void solve(){
		//Implement solution here.
		int N = ni();
		int K = ni();
		int[] d = new int[K];
		int[][] A = new int[K][N];
		boolean[] ans = new boolean[N];
		for(int i = 0; i < K; i++) {
			d[i] = ni();
			for(int j = 0; j < d[i]; j++) {
				A[i][j] = ni();
				ans[A[i][j] - 1] = true;
			}
		}
		
		int result = 0;
		for(boolean b:ans)result += b ? 0 : 1;
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

int main() {
    int a, b, ans = 0;

    cin >> a >> b;

    if (a > b) {
        ans += a;
        a--;
    } else {
        ans += b;
        b--;
    }
    if (a > b) {ans += a;}
    else {ans += b;}

    cout << ans;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d;
  if(a<b)
    e=a;
  if(a>b)
    e=b;
  if(c<d)
    f=c;
  if(c>d)
    f=d;
  cout<<e+f<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;


int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int a , b;
    cin >> a >> b;
    cout << max({a + b , a + a - 1 , b + b - 1}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main(){

	fastcin
	
	int n, x;
	cin >> n;
	
	int freq[n+1];
	
	memset(freq, 0, sizeof freq);
	
	for(int i=1; i<n; i++){
		cin >> x;
		freq[x]++;
	}
	
	for(int i=1; i<=n; i++) cout << freq[i] << endl;
		
	return 0;
}


Measured memory_bytes: 4436
#X = int(input().strip())

K, N = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
m = 0
ind = 0
ans = 0

for i in range(N-1):
  _m = A[i+1] - A[i]
  if _m > m:
    m = _m
    ind = i+1
    last = i

_m = K + A[0] - A[N-1]
if _m > m:
  m = _m
  ind = 0
  last = N-1

#print(m)
#print(ind)
#print(last)
i = ind
while i != last:
  #print(ans)
  if i < N-1:
    ans += A[i+1] - A[i]
    i += 1
  else:
    ans += K + A[0] - A[i]
    i = 0

print(ans)

Measured memory_bytes: 26444
// Problem : B - Training Camp
// Contest : AtCoder - AtCoder Beginner Contest 055
// URL : https://atcoder.jp/contests/abc055/tasks/abc055_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'
using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	unsigned long long ans = 1;
	unsigned int n; cin >> n;
	for(unsigned long long i = 2; i <=n; i++){
	    ans*= i;
	    ans%=1000000007;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

m4 = sum([1 for i in range(n) if a[i]%4==0])
m2 = sum([1 for i in range(n) if a[i]%2==0])
m2 -= m4
m1 = n-m4-m2

n-=m2-1
if m2>0:
    m1+=1


if m4>=m1-1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 20044
#include<bits/stdc++.h>
#define range(a,l,r) (l<=a && a<=r)
using namespace std;
typedef long long ll;

ll n;
pair<ll,ll> c[100100];
int use[100100];
const ll inf = 1e15;
const long double sq2 = sqrt(2);
const long double PI = acos(-1);
const long double EPS = 1e-8;

int main(){
  scanf("%lld",&n);
  ll maxy = -inf, miny = inf;
  pair<ll,ll> left(inf,inf);

  for(int i=0;i<n;i++){
    scanf("%lld%lld",&c[i].first,&c[i].second);
    complex<long double> p(c[i].first,c[i].second);
    p *= complex<long double>(cos(PI/4),sin(PI/4));
    c[i].first = (ll)(p.real() * sq2 + (p.real()>0?+EPS:-EPS));
    c[i].second = (ll)(p.imag() * sq2) + (p.imag()>0?+EPS:-EPS);
    maxy = max(maxy, c[i].second);
    miny = min(miny, c[i].second);
    left = min(left, c[i]);
  }
  
  ll l=-1,r=1e10;
  while(r-l>1){
    ll mid = (l+r)/2;

    bool ok = false;
    if(maxy <= left.second + mid){
      memset(use,0,sizeof(use));
      for(int i=0;i<n;i++){
	if( range(c[i].first, left.first, left.first+mid)
	    && range(c[i].second, maxy-mid, maxy) )use[i] = 1;
      }

      ll rl = inf, rr = -inf, rd = inf, ru = -inf;
      for(int i=0;i<n;i++){
	if(!use[i]){
	  rl = min(rl, c[i].first); rr = max(rr, c[i].first);
	  rd = min(rd, c[i].second); ru = max(ru, c[i].second);
	}
      }
      if(rr-rl<=mid && ru-rd<=mid)ok = true;
    }

    if(miny >= left.second - mid){
      memset(use,0,sizeof(use));
      for(int i=0;i<n;i++){
	if( range(c[i].first, left.first, left.first+mid)
	    && range(c[i].second, miny, miny+mid) )use[i] = 1;
      }

      ll rl = inf, rr = -inf, rd = inf, ru = -inf;
      for(int i=0;i<n;i++){
	if(!use[i]){
	  rl = min(rl, c[i].first); rr = max(rr, c[i].first);
	  rd = min(rd, c[i].second); ru = max(ru, c[i].second);
	}
      }
      if(rr-rl<=mid && ru-rd<=mid)ok = true;
    }

    if(ok)r = mid;
    else l = mid;
  }

  cout << r << endl;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T,class U> istream& operator >> (istream &is, pair<T,U> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct { template <typename T> operator T() { T x; cin >> x; return x; } } IN;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n=IN;
    vector<int> x(n);
    cin>>x;
    vector<vector<int>> a,b;
    a.reserve(n),b.reserve(n);
    vector<int> ans(n*n,-1);
    REP(i,n) {
        ans[x[i]-1]=i+1;
        a.push_back({x[i]-1,i+1,i});
        b.push_back({x[i]-1,i+1,n-i-1});
    }
    sort(ALL(a));
    sort(RALL(b));
    int idx=0;
    REP(i,n) {
        int x=a[i][0];
        int v=a[i][1];
        int c=a[i][2];
        REP(j,c) {
            while(idx<n*n && ans[idx]!=-1) idx++;
            if(idx>=x) {
                cout<<"No"<<endl;
                return 0;
            }
            ans[idx]=v;
        }
    }
    idx=n*n-1;
    REP(i,n) {
        int x=b[i][0];
        int v=b[i][1];
        int c=b[i][2];
        REP(j,c) {
            while(idx>=0 && ans[idx]!=-1) idx--;
            if(idx<=x) {
                cout<<"No"<<endl;
                return 0;
            }
            ans[idx]=v;
        }
    }
    cout<<"Yes"<<endl;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

vector<vector<ll>> G;
ll N;
ll A,T;
ll par[100000];
ll deep[100000];
ll len[100000];

void bfs(ll n, ll p){
    par[n] = p;
    if(G[n].size() == 1 && G[n][0] == p){
        deep[n] = 0;
        return;
    }
    ll d = 0;
    for(auto &e : G[n]){
        if(e==p) continue;
        len[e] = len[n]+1;
        bfs(e,n);
        d = max(d, deep[e]);
    }
    deep[n] = d + 1;
}

int main(){
    cin >> N >> T >> A;
    T--,A--;
    G.resize(N);
    for(int i=0;i<N-1;i++){
        ll a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    len[A] = 0;
    bfs(A,-1);

    /*
    for(int i=0;i<N;i++) cout << par[i] << " ";
    cout << endl;
    for(int i=0;i<N;i++) cout << deep[i] << " ";
    cout << endl;
    */
   
    ll max_d = (len[T]-1) / 2;

    //cout << max_d << endl;

    ll max_p = T;
    for(int i=0;i<max_d;i++) max_p = par[max_p];

    //cout << max_p << endl;

    ll c =  1 - (len[T] % 2);
    c += max_d + deep[max_p];
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 12032