akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int c[8];
class DICE{
    public:
    void setdice(char a);
};

void DICE::setdice(char a){
    if(a=='S'){
        c[7]=c[1];
        c[1]=c[5];
        c[5]=c[6];
        c[6]=c[2];
        c[2]=c[7];
    }
    else if(a=='W'){
        c[7]=c[1];
        c[1]=c[3];
        c[3]=c[6];
        c[6]=c[4];
        c[4]=c[7];
    }
    else if(a=='N'){
        c[7]=c[1];
        c[1]=c[2];
        c[2]=c[6];
        c[6]=c[5];
        c[5]=c[7];
    }
    else{
        c[7]=c[1];
        c[1]=c[4];
        c[4]=c[6];
        c[6]=c[3];
        c[3]=c[7];
    }
}
int main(void){
    DICE dice;
    int n,a,b;
    for(int i=1;i<=6;i++){
        cin>>c[i];
    }
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(a==c[3] || a==c[4]){
            while(c[1] !=a) dice.setdice('E');
        }
        else{
            while(c[1] !=a) dice.setdice('S');
        }
        dice.setdice('N');
        while(c[1] !=b) dice.setdice('W');
        dice.setdice('S');
        cout<<c[3]<<endl;
    }
}


Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

void a(){
    int A, P; cin >> A >> P;

    int p = A*3 + P;
    cout << p/2;

}

void b(){
    int N; cin >> N;
    vector<pair<string,int>> vec(N);
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        int p; cin >> p;

        vec[i] = make_pair(s,-p);
    }
    vector<int> idx(N);
    for(int i = 0; i < N; i++){
        idx[i] = i;
    }

    sort(idx.begin(),
         idx.end(),
         [&vec](int idx1, int idx2){return (vec[idx1] < vec[idx2]);}
    );


    for(int i = 0; i < N; i++){

        cout << idx[i] + 1 << endl;
    }

}
int main(){
    b();
}

Measured memory_bytes: 888
#pragma region include
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

int main() {
    string s; cin >> s;
    vector<int> ans(s.size(),0);
    REP(i, s.size()) {
        int cnt = 0;
        while (s[i] == 'R') {
            cnt++;

            i++;
        }
        ans[i - 1] += (cnt + 1) / 2;
        ans[i] += cnt / 2;
        cnt = 0;
        int t = i;
        while (s[i] == 'L') {
            if (cnt % 2 == 0) {
                ans[t]++;
            }
            else {
                ans[t - 1]++;
            }
            cnt++;
            i++;
        }
        i--;
    }
    REP(i, ans.size()) {
        cout << ans[i] << endl;
    }
    getchar(); getchar();
}

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

using namespace std;

bool is_square(long long x) {
    return ((long long)sqrt((long double)x)) * ((long long)sqrt((long double)x)) == x;
}

bool calc(long long a, long long b, long long c) {
    if (is_square(a * b)) {
        return a + 2 * (long long)sqrt((long double)a * b) + b < c;
    } else {
        return sqrt((long double)a) + sqrt((long double)b) < sqrt((long double)c);
    }
}

int main() {
    long long a, b, c;
    cin >> a >> b >> c;
    cout << (calc(a, b, c) ? "Yes" : "No") << endl;
    return 0;
}

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


void SelectionSort(vector<string> Array, int N)
{
  	bool isStable=true;
  	for(int i = 0; i< N;i++)
    {
      int min_idx = i;
      bool isSame = false;
      int same_idx;
      for(int j=i+1;j<N;j++)
      {
        if(Array[j][1] - '0' == Array[min_idx][1] - '0') 
        {
          isSame=true;
          same_idx = j;
        }
        if(Array[j][1] - '0' < Array[min_idx][1] - '0')
        {
          min_idx = j;
        }
      }
      if(isSame && same_idx < min_idx) isStable = false;
      string tmp = Array[i];
      Array[i] = Array[min_idx];
      Array[min_idx] = tmp;
    }
	for(int i=0;i<N;i++)
    {
      cout << Array[i] << endl;
    }
  	cout << Array[N-1] << endl;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//long N, K;
	//cin >> N >> K;
  	string S;
  	cin >> S;	
  	/*
    vector<string> Array(N);
  	int idx = 0;
  	while(cin >> Array[idx]) idx++;
    */
  	int x = stoi(S.substr(0,2));
    int y = stoi(S.substr(2,2));
  	cerr << x << " " << y << endl;
  	
  	if(x >= 1 && x <= 12 && y >= 1 && y <= 12)
    {
      cout << "AMBIGUOUS" << endl;
    }
  	else if(x >= 1 && x <= 12)
    {
      cout << "MMYY" << endl;
    }
  	else if(y >= 1 && y <= 12)
    {
      cout << "YYMM" << endl;
    }
  	else
    {
      cout << "NA" << endl;
    }
  	
  	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main ()
{
    int n,a,sum=0;
    scanf("%d %d",&n,&a);
    for (int i=1; i<=a; i++)
    {
        int x;
        scanf("%d",&x);
        sum=sum+x;
    }
    int ans=n-sum;
    if (ans<0)
        printf("-1\n");
    else
        printf("%d\n",ans);

    return 0;

}


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

using namespace std;

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

typedef modint<1000000007> mint;

mint memo1[100010];
mint memo2[100010];

mint comb(int x, int y) {
  mint ans = 1;
  for (int i = 1; i <= y; i++) {
    ans *= x - y + i;
    ans /= i;
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 2);
  for (int i = 1; i <= n + 1; i++) {
    cin >> a[i];
  }
  auto b = a;
  sort(b.begin(), b.end());
  int diff = -1;
  for (int i = 1; i <= n + 1; i++) {
    if (i != b[i]) {
      diff = b[i];
      break;
    }
  }
  int start = -1, end = -1;
  for (int i = 1; i <= n + 1; i++) {
    if (a[i] == diff) {
      if (start == -1) {
        start = i;
      } else {
        end = i;
        break;
      }
    }
  }
  int com = start - 1 + n + 1 - end;
  memo1[1] = n + 1;
  for (int i = 1; i <= n; i++) {
    memo1[i + 1] = memo1[i] * (n + 1 - i) / (i + 1);
  }
  memo2[0] = 1;
  memo2[1] = com;
  for (int i = 1; i < com; i++) {
    memo2[i + 1] = memo2[i] * (com - i) / (i + 1);
  }
  for (int k = 1; k <= n + 1; k++) {
    mint ans = memo1[k];
    if (com >= k - 1) {
      ans -= memo2[k - 1];
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<string>
#define MAX_N 30
using namespace std;

int s_count[MAX_N], t_count[MAX_N];

int main() {
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < 27; i++) {
        s_count[i] = 0;
        t_count[i] = 0;
    }
    for (int i = 0; i < S.length(); i++) {
        s_count[S[i] - 'a']++;
    }
    for (int i = 0; i < T.length(); i++) {
        t_count[T[i] - 'a']++;
    }
    for (int i = 0; i < S.length(); i++) {
        if (s_count[S[i] - 'a'] != t_count[T[i] - 'a']) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll ans = 0;
string s;

bool read() {
    if (!(cin >> s))
        return false;

    return true;
}

void go(int i, ll cur, ll sum) {
    cur = 10ll * cur + s[i] - '0';

    if (i == n - 1) {
        ans += sum + cur;
        return ;
    }

    go(i + 1, cur, sum);
    go(i + 1, 0, sum + cur);
}

void solve() {
    n = sz(s);
    go(0, 0, 0);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



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

int main(){
  int N;
  cin>>N;
  
  vector<int> AllCard(N);
  for(int i=0;i<N;i++){
    cin>>AllCard.at(i);
  }
  
  sort(AllCard.begin(),AllCard.end());
  reverse(AllCard.begin(),AllCard.end());

  int Alice=0,Bob=0;
  for(int j=0;j<N;j+=2){
    Alice+=AllCard.at(j);
    if(N-j>1){
      Bob+=AllCard.at(j+1);
    }
  }
  cout<<Alice-Bob<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,m;
  long long p=1,M=1e9+7,d[100010],a,ans=0,i;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    hin(a);
  }
  for(i=0;i<n;i++)d[i]=N[hout()];
  for(i=0;i<=n-m;i++){
    ans=(ans+(d[m+i-1]*p)%M)%M;
    ans=(ans-(d[n-m-i]*p)%M)%M;
    p=(p*(i+m))%M;
    p=(p*inv(i+1,M))%M;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3296
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<int> visited;
vector<vector<int>> graph;
void dfs(int c){
  for(auto v : graph[c]){
    if(visited[v]) continue;
    visited[v] = true;
    dfs(v);
  }
}

signed main() {
  int N, M; 
  cin >> N >> M;

  graph.resize(N);
  REP(i, M){
    int u, v, z;
    cin >> u >> v >> z;
    u--; v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }

  int ans = 0;
  visited.resize(N, false);
  REP(i, N){
    if(visited[i]) continue;
    visited[i] = true;
    dfs(i);
    ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int n, m;
  cin >> n >> m;
  vi a(m); vi b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  map<int,int> mps;
  map<int,int> mpg;
  rep(i,m) if(a[i]==0) mps[b[i]]++;
  rep(i,m) if(b[i]==n-1) mpg[a[i]]++;
  map<int,int> mp;
  for(auto p : mps) mp[p.first]++;
  for(auto p : mpg) mp[p.first]++;
  for(auto p : mp) {
    if(p.second>=2) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 20608
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

lint mypow(lint a, lint n){
    lint res = 1;
    lint base = a;
    while(n > 0){
        if (n%2) res = res*base;
        base = base*base;
        n = n/2;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(NULL);    cout.tie(NULL);

    lint n; cin>>n;

    vi a(n);
    int tot = 0;
    for (int i=0; i<n; ++i){
        cin>>a[i];
        tot = tot^a[i];
    }

    for (int i=0; i<n; ++i) cout<<(tot^a[i])<<" ";


}


Measured memory_bytes: 3932
#include <iostream>
#include <iomanip>
#include <cstring>

int main() {
  int n; std::cin >> n;
  int cnt[3] = {};
  for (int i = 0; i < n; i++) {
    int a; std::cin >> a;
    cnt[a - 1]++;
  }
  double dp[302][302][302];
  std::memset(dp, 0, sizeof(dp));
  auto func = [&](const auto &self, int a, int b, int c) {
    if (a < 0 || b < 0 || c < 0) return 0.;
    if (a == 0 && b == 0 && c == 0) return 0.;
    if (dp[a][b][c] != 0) return dp[a][b][c];
    double s = a + b + c;
    double ret = 0.;
    ret += a / s * self(self, a - 1, b, c);
    ret += b / s * self(self, a + 1, b - 1, c);
    ret += c / s * self(self, a, b + 1, c - 1);
    ret += n / s;
    return dp[a][b][c] = ret;
  };
  std::cout << std::fixed << std::setprecision(15)
    << func(func, cnt[0], cnt[1], cnt[2]) << std::endl;
  return 0;
}

Measured memory_bytes: 215552
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;;
const int maxn = 2e5 + 5;


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


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

int main(){
   int n;
   cin >> n;
   int A[n];
   for (int i=0; i<n; i++)
      cin >> A[i];
   int max = A[0], min = A[0];
   for ( int i=0; i<n; i++){
      if ( max < A[i] ) max = A[i];
      if ( min > A[i] ) min = A[i];
      }
   cout << max - min << endl;
}


Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    INF = 10**5
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    n,ma,mb = LI()
    med = [LI() for _ in range(n)]
    h1 = [INF] * 10000

    for i in range(1,2 ** (n//2)):
        bit = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n//2):
            if i & bit:
                a,b,c = med[j]
                ta += a
                tb += b
                tc += c
            bit <<= 1
        dif = ta * mb - tb * ma
        if h1[dif] > tc: h1[dif] = tc

    ans = h1[0]

    for i in range(1,2 ** (n - n//2)):
        bit = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n - n//2):
            if i & bit:
                a,b,c = med[j+n//2]
                ta += a
                tb += b
                tc += c
            bit <<= 1
        dif = tb * ma - ta * mb
        if dif == 0:
            ans = min(ans,tc)
        else:
            ans = min(ans,h1[dif]+tc)

    if ans < INF:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 43992
using System;

namespace abc165_b
{
    class Program
    {
        static void Main(string[] args)
        {
            long x = long.Parse(Console.ReadLine());
            long money = 100;
            int year = 0;
            while (money < x)
            {
                money = money + money/100;
                year++;
            }
            Console.WriteLine(year);
        }
    }
}


Measured memory_bytes: 27352
#include <iostream>
#include <map>
#include <algorithm>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
struct numble
{
	int xuhao;
	int shuzhi;
	numble(int a=0,int b=0)
	{
		xuhao=a; shuzhi=b;
	}	
};
numble t[100100];

bool judge(numble a,numble b)
{
	return a.shuzhi<b.shuzhi;
}
int main(int argc, char** argv) {
	int n;
	int tem;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&tem);
		t[i]=numble(i+1,tem);
	}
	sort(t,t+n,judge);
	for(int i=0;i<n;i++)
	{
		printf("%d ",t[i].xuhao);
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    
    cin.ignore();
    char colors[n];
    
    cin.getline(colors,n);
    bool change = false;
    
    for(int i = 0; i < n; i++)
    {
        if(colors[i] == 'Y')
        {
            change = true;
            break;
        }
    }
    
    if(change)
    {
        cout << "Four" << endl;
    }
    else
    {
        cout << "Three" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int x,y;
	char ch;
	cin>>x>>y;
	int a[x+2][y+2];
	int i,j;
	
	for(i=0;i<=x+1;i++)
		for(j=0;j<=y+1;j++)
			a[i][j]=0;
	
	for(i=1;i<=x;i++)
		for(j=1;j<=y;j++)
		{
			cin >> ch;
			if(ch=='#')			a[i][j]=1;
			else if(ch=='.')     a[i][j]=0;
		}
		

		
	for(i=1;i<=x;i++)
	{	
		for(j=1;j<=y;j++)
		{
			if(a[i][j]==0)
			{
				int sum=0;
				sum+=a[i-1][j+1];
				sum+=a[i-1][j-1];
				sum+=a[i-1][j];
				sum+=a[i+1][j+1];
				sum+=a[i+1][j-1];
				sum+=a[i+1][j];
				sum+=a[i][j+1];
				sum+=a[i][j-1];
				cout<<sum;
			}
			else
				cout<<'#';
		}
		cout<<endl;
	}
}

Measured memory_bytes: 256
import math
def main():
    n,p=map(int,input().split())
    if n==1:
        print(p)
    elif n>39:
        print(1)
    else:
        q=math.ceil(p**(1/n))
        ans=1
        for i in range(q,0,-1):
            if p%(i**n)==0:
                ans=i
                break
        print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

const int MAX_N = 2e5 + 10;
ll cnt[MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    for(int i = 1; i < n; i ++) {
        int a;
        cin >> a;
        cnt[a] ++;
    }
    for(int i = 1; i <= n; i ++) {
        cout << cnt[i] << endl;
    }
    return 0;
}




Measured memory_bytes: 5192
S = gets.chomp
K = gets.to_i

def f(s)
  cnt = 0
  chain = 1
  current = s[0]

  s[1..-1].each_char do |c|
    if current == c
      chain += 1
    else
      cnt += chain / 2
      chain = 1
      current = c
    end
  end

  cnt += chain / 2

  cnt
end

if S.chars.uniq.size == 1
  puts S.size * K / 2
else
  puts (f(S * 2) - f(S)) * (K - 1) + f(S)
end


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

int main() {
    // エラトステネスの篩
    int MAX = 100010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for(int i = 2; i < MAX; ++i) {
        if(!is_prime[i]) continue;
        for(int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }
    
    // 2017 に似た数
    vector<int> a(MAX, 0);
    for(int i = 0; i < MAX; ++i) {
        if(i % 2 == 0) continue;
        if(is_prime[i] && is_prime[(i+1) / 2]) a[i] = 1;
    }
    
    // 累積和を前計算
    vector<int> s(MAX+1, 0);
    for(int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];
    
    int Q; cin >> Q;
    for(int q = 0; q < Q; ++q) {
        int l, r; cin >> l >> r;
        ++r;
        
        cout << s[r] - s[l] << endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int x,ans,j;
    int judge=0;
    cin>>x;
    for(j=x;;j++){
        judge=0;
      for(int i=2;i<j;i++){
          if(j==2){
              break;
          }
        if(j%i==0){
            judge=1;
            break;
        }
      }
      if(judge==0){
          ans=j;
          break;
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	// odds... キー:元の数列の奇数番目に現れた数字 値:現れた回数
	odds, evens := make(map[int]int), make(map[int]int)

	for i := 1; i <= n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		if i%2 == 0 {
			evens[tmp]++
		} else {
			odds[tmp]++
		}
	}

	// FirstNumberは最頻値
	// Firstは最頻値の出現回数、Secondは2番目に頻出な数字の出現回数
	oddsFirstNumber, oddsFirst, oddsSecond := check(odds)
	evensFirstNumber, evensFirst, evensSecond := check(evens)

	if oddsFirstNumber == evensFirstNumber {
		fmt.Println(min(n-oddsSecond-evensFirst, n-oddsFirst-evensSecond))
		return
	}
	fmt.Println(n - oddsFirst - evensFirst)
}

func check(m map[int]int) (firstNunber, first, second int) {
	for i, n := range m {
		switch {
		case n > first:
			second = first
			first = n
			firstNunber = i
		case n > second:
			second = n
		}
	}
	return
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 7808
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <time.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const string A="ABC";

string s;

int main(){
	cin>>s;
	int cnt=0;
	while(s!=A){
		int S=s.size();
		vi a(S),b(3,1);
		for(int i=0;i<S;i++){
			if(s.substr(i,3)==A){
				a[i]++;
				i+=2;
			}
			else b[s[i]-'A']=0;
		}
		if(b[0]+b[1]+b[2]!=1||cnt>3000){
			cout<<"No"<<endl;
			return 0;
		}
		char c='A';
		for(int i=0;i<3;i++) if(b[i]) c=c+i;
		string t;
		for(int i=0;i<S;i++){
			if(a[i]){
				t+=c;
				i+=2;
			}
			else t+=s[i];
		}
		cnt++;
		s=t;
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
int GCD(int a,int b);
int LCM(int a,int b);
signed main(){
    int n,a,sum=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        sum=LCM(a,sum);
    }
    cout<<sum<<'\n';
    return(0);
}

int GCD(int a,int b){
while(b !=0){
    int r =a%b;
    a=b;
    b=r;
}
return(a);
}

int LCM(int a,int b){
    return a/GCD(a,b)*b;
}


Measured memory_bytes: 3120
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int n;
int a;
int b;
int main()
{
	scanf("%d %d %d",&n,&a,&b);
	int c=max(a,b)-min(a,b);
	if(c%2==0)
	{
		printf("Alice\n");
	}
	else
	{
		printf("Borys\n");
	}
	return 0;
}

Measured memory_bytes: 128
def dfs(n):
    if n == 0:return 0
    return dfs(n % format(n, "b").count("1")) + 1
n = int(input())
x = input()
c = x.count("1")
a = int(x, 2)
if c == 1:
    for i in range(n):
        if x[i] == "1":
            print(0)
        elif i == n - 1:
            print(2)
        else:
            print(1)
else:
    j, k = a % (c + 1), a % (c - 1)
    for i in range(n):
        if x[i] == "1":print(dfs((k - pow(2, n - i - 1, c - 1)) % (c - 1)) + 1)
        else:print(dfs((j + pow(2, n - i - 1, c + 1)) % (c + 1)) + 1)

Measured memory_bytes: 9560
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10**9+7
N, M = map(int, readline().split())

fact = [1] * (M+1)
fact_inv = [1] * (M+1)
for i in range(1,M+1):
    fact[i] = fact[i-1] * i % mod 
fact_inv[M] = pow(fact[M],mod-2,mod)
for i in range(M,0,-1):
    fact_inv[i-1] = (i * fact_inv[i]) % mod 

def comb(n,r):
  return fact[n] * fact_inv[r] * fact_inv[n-r] % mod
total = 0
for k in range(N+1):
    a = fact[M-k] * fact_inv[M-N] * comb(N,k) % mod
    if k % 2 == 0:
        total += a
    else:
        total -= a
ans = (comb(M,N) * fact[N]) % mod * total 
print(ans%mod)

Measured memory_bytes: 48516
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

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

    priority_queue<double> pque;
    rep(i, n) {
        int a;
        cin >> a;
        pque.push(double(a));
    }
    rep(i, m) {
        double discount = pque.top() / 2.0;
        pque.pop();
        pque.push(discount);
    }
    ll ans = 0;
    while(!pque.empty()) {
        int price = int(pque.top() + 0.000001);
        pque.pop();
        ans += ll(price);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
int M = 1e9 + 7;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a, b, n;
  cin >>  a >> b >> n;
  int x = min(b - 1, n);
  cout << (a * x) / b - a*(x / b);

}

Measured memory_bytes: 3636
use std::io;

// still don't know how to write lambda
fn add (x:i32, y:i32) -> i32{
    x+y
}

fn minus(x:i32, y:i32) -> i32{
    x-y
}

fn to_op(op:&str) -> (fn(i32, i32) -> i32) {
    match op {
        "+" => add,
        "-" => minus,
        _ => panic!()
    }
}

fn read_int(n:&str) -> i32{
    n.parse().unwrap()
}

fn main(){
    let mut input = String::new();
    io::stdin().read_line(&mut input)
        .expect("input err");
    let inputs : Vec<&str> = input.split_whitespace().collect();
    println!("{}",
             to_op(inputs[1])(read_int(inputs[0]), read_int(inputs[2]))
             );
}

Measured memory_bytes: 380
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int a[10],maxn,maxl=0,sum=0,k;
    for(int i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
        if(i==0)
            maxn=a[i];
        if(maxn<a[i])
            maxn=a[i],maxl=i;
    }
    scanf("%d",&k);
    for(int i=0;i<k;i++)
    {
            a[maxl]=2*a[maxl];
    }
    for(int i=0;i<3;i++)
        sum+=a[i];
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

struct job{
    string name;
    int time;
};

int main(){
    int n,q,i;
    int sum = 0;
    job a;
    cin >> n >> q;
    queue<job> p;
    for(i=0;i<n;i++){
        cin >> a.name >> a.time;
        p.push(a);
    }
    while(!p.empty()){
        a = p.front();
        p.pop();
        if(a.time > q){
            a.time -= q;
            p.push(a);
            sum += q;
        }else{
            sum += a.time;
            cout << a.name <<" "<< sum << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> x(n), y(n), p(n), s(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> p[i];
        s[i] = min(abs(x[i]), abs(y[i]));
    }
    vector<ll> ans(n + 1, 1e18);
    vector<int> a(n);
    int z = 1;
    for (int i = 0; i < n; i++) {
        z *= 3;
    }
    vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(1 << n, s));
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                for (int k = 0; k < n; k++) {
                    dp[0][i][k] = min(dp[0][i][k], abs(x[j] - x[k]));
                    dp[1][i][k] = min(dp[1][i][k], abs(y[j] - y[k]));
                }
            }
        }
    }
    for (int loop = 0; loop < z; loop++) {
        int b = 0;
        for (int i = 0; i < n; i++) {
            if (a[i]) {
                b++;
            }
        }
        int c = 0, d = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 1) {
                c += 1 << i;
            } else if (a[i] == 2) {
                d += 1 << i;
            }
        }
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            sum += min(dp[0][c][i], dp[1][d][i]) * p[i];
        }
        ans[b] = min(ans[b], sum);
        for (int i = n - 1; i >= 0; i--) {
            a[i]++;
            if (a[i] == 3) {
                a[i] = 0;
            } else {
                break;
            }
        }
    }
    for (ll i : ans) {
        cout << i << '\n';
    }
    return 0;
}

Measured memory_bytes: 17720
import fractions
a,b,c,d=map(int,input().split())
a=a-1
l=(c*d)//fractions.gcd(c,d)
B=b-((b//c)+(b//d)-(b//l))
A=a-((a//c)+(a//d)-(a//l))
print(int(B-A))

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

int main()
{
  string str;
  cin >> str;
  int len = str.size();
  int i;
  long long temp = 0;
  int numb = 0;
  for(i = 0;i < len;++i){
    if(str.at(i) == 'W'){
      temp += i-numb;
      ++numb;
    }
  }
  cout << temp << endl;
  return 0;
}


Measured memory_bytes: 640
s=input();n=len(s)
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

# @lru_cache(maxsize=10**10)
def qq(i):
    if i==1:
        if s[0]==s[1]: return 1
        return 2
    if i==2:
        if s[0]!=s[1] and s[1]!=s[2]: return 3
        return 2
    if i==0:
        return 1
    if s[i]==s[i-1]:
        return qq(i-3)+2
    else:
        return qq(i-1)+1
print(qq(n-1))

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  ll n, m; std::cin >> n >> m;
  ll sum = 0;
  rep(i, m) {
    ll a; std::cin >> a;
    sum += a;
  }
  std::cout << (sum <= n ? n-sum : -1) << "\n";
}


Measured memory_bytes: 3656
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, W[111], S = 0;

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> W[i];

    S += W[i];
  }

  int s = 0, dm = INF;

  for (int i = 0; i <= N; s += W[i], i ++) {
    int t = S - s, d = std::abs(s - t);
    
    if (d < dm)
      dm = d;
  }

  std::cout << dm << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
   int x,y,temp,sum=0;
   cin>>x>>y;
   int arr[x];
   for(int a=0;a<x;a++){
    cin>>arr[a];
   }

    for(int i=0; i<x; i++)
    {
        for(int j=i+1; j<x; j++)
        {
            if(arr[j] <arr[i])
            {
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }
   for(int l=0;l<y;l++){
    sum+=arr[l];
   }
cout<<sum;


    return 0;
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define repi(i,a,n) for(int (i)=(a);(i)<(n);(i)++)

int main() {
  int a;
  cin>>a;
  cout<<a*a*3;
  return 0;
}


Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int cnt = 0;
  for(int i = 0;i <= 100;i++){
    if(i >= A && i <= B && i >= C && i <= D)cnt++;
  }
  cout << max(cnt-1,0) <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //usefile;
  //test
  {
    int k;
    cin>>k;
    queue<int> q;
    for(int i=1;i<10;i++){
      q.push(i);
    }
    while(k-1)    
    {
      int num=q.front();
      q.pop();
      k--;
      int l=num*10+(num%10-1);
      if(num%10!=0)
        q.push(l);
      q.push(l+1);
      if(num%10!=9)
        q.push(l+2);
    }
    cout<<q.front();
  }
  //time("");
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main()
{
  char a[100];
  scanf("%s", a);
  if(a[0]=='S')
  printf("Cloudy\n");
  else if(a[0]=='C')
    printf("Rainy\n");
  else if(a[0]=='R')
    printf("Sunny\n");
  return 0;
}

Measured memory_bytes: 128
#include<set>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[200000];
ll b[20000];
int main()
{
	set<ll> st;
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	memset(a,0,sizeof(a));
	for(int i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		st.insert(x);
		a[x]++;
	}
	
	int ans;
	if(st.size()<=k)
		ans=0;
	else{
		ans=0;
		set<ll>:: iterator it;
		int x=0;
		for(it=st.begin();it!=st.end();it++){
			b[x]=a[*it];
			x++;
		}
		sort(b,b+x);
		int t=st.size()-k;
	
		for(int i=0;i<t;i++)
			ans+=b[i];
	}	
	cout<<ans<<endl;
	return  0;
}

Measured memory_bytes: 11392
N,M = map(int,input().split())
a = []
for i in range(M):
    a.append(input())
 
b = [0 for i in range(N)]
b[0] = 1
c = [1 for i in range(N)]
for d in a:
    fr,to = map(int,d.split())
    fr -=1
    to -=1
    c[fr ] -= 1
    c[to ] += 1
    if b[fr] > 0:
        b[to] = 1
        b[fr] = 1 if c[fr] > 0 else 0
 
ans = b.count(1)
print(ans)

Measured memory_bytes: 11800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int judge(int n){
  if(n/10000){
    if((n/10000)==(n%10) && ((n/1000)%10) == ((n%100)/10)) return n;
  }else if(n/1000){
    if((n/1000)==(n%10) && ((n/100)%10) == ((n%100)/10)) return n;
  }else if(n/100){
    if((n/100) == (n%10)) return n;
  }else if(n/10){
    if((n/10) == (n%10)) return n;
  }else{
    return n;
  }
  return 0;
}
int main(){
  int n, res, res1, res2;
  scanf("%d", &n);
  rep(i, 10000){
    if(n - i >= 0) res1 = judge(n-i);
    res2 = judge(n+i);
    if(res1){ res = res1; break;}
    else if(res2){ res = res2; break;}
  }
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  int N = s.size();
  bool ok = false;
  pair< int, int > p(-1, -1);
  REP(i, N) {
    if (s[i] == s[i + 1]) {
      p.fst = i + 1;
      p.snd = i + 2;
      ok = true;
      break;
    }
  }
  if (!ok) {
    REP(i, N - 2) {
      if (s[i] == s[i + 2]) {
        p.fst = i + 1;
        p.snd = i + 3;

        ok = true;
        break;
      }
    }
  }
  cout << p.fst << " " << p.snd << "\n";
}

Measured memory_bytes: 512
/*
  AUTHOR:SOURABH
  CREATED:06:05:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,i,curr,k,k1,r;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n>>k;
        vll a(n+1);
        fs(i,1,n+1)
        cin>>a[i];
        vector<bool> vis(n+1);
        curr=1;
        vll v;
        W(!vis[curr])
        {
            vis[curr]=1;
            v.pb(curr);
            curr=a[curr];
        }
        fn(i,v.size())
        {
            if(v[i]==curr)
                break;
        }
        k1=v.size()-i;
        if(k<=v.size()-1)
            cout<<v[k];
        else
        {
            r=(k-i)%k1;
            cout<<v[i+r];
        }
    }
    return 0;
}


















Measured memory_bytes: 6872
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m;
int a[100020];
bool used[100020];
vector<int> G[100020];
int bestvalue;
int bestindex;
LL ans;
void dfs(int x) {
	used[x] = true;
	if (bestvalue > a[x]) {
		bestvalue = a[x];
		bestindex = x;
	}
	for (int i = 0; i < G[x].size();i++) {
		if (!used[G[x][i]]) {
			dfs(G[x][i]);
		}
	}
}

int main() {
	cin >> n >> m;
	REP(i, n)cin >> a[i];
	REP(i,m){
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	int count = 0;
	REP(i,n) {
		if (!used[i]) {
			bestvalue = INF;
			bestindex = -1;
			dfs(i);
			count++;
			ans += bestvalue;
			a[bestindex] = INF;
		}
	}
	sort(a, a + n);
	if (count == 1) {
		cout << 0 << endl;
		return 0;
	}
	REP(i,count-2) {
		if (a[i] == INF) {
			cout << "Impossible" << endl;
			return 0;
		}
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 6272
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n = read1::<usize>();
    let mut ans = 0;
    
    for i in 1..n+1 {
        ans += i;
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
n = int(input())
a = [int(i) for i in input().split()]
mod = 10**9+7
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        if a[j]>>i & 1 == 0: cnt += 1
    ans = (ans+pow(2,i,mod)*cnt%mod*(n-cnt)%mod)%mod
print(ans)

Measured memory_bytes: 122808
#include <iostream>
using namespace std;
int main(){
  int i,N,X,m,M_min=1<<30;
  cin >> N >> X;
  for(i=0;i<N;i++){
    cin>>m;X-=m;
    M_min=min(m,M_min);
  }
  cout <<N+X/M_min << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		long B = sc.nextLong();
		long N = sc.nextLong();
		long let;
		if (B <= N) {
			let = (A * (B - 1)) / B;
		} else {
			let = (A * N) / B;
		}
		System.out.println(let);

	}
}

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

int main(){
    int n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    rep(i,n-1){
        if(s[i]==s[i+1]) continue;
        ans+=1;
    }
    ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
// AtCoder ABC139: A - Tenki
// 2019.9.2 bal4u

#include <stdio.h>

char S[10], T[10];

int main()
{
	int ans, i;
	
	scanf("%s%s", S, T);
	ans = 0; for (i = 0; i < 3; i++) if (S[i] == T[i]) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128