akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define Icin(s) ll (s);cin>>(s);
#define Scin(s) ll (s);cin>>(s);
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
//ここから
struct BipartiteMatching {
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;

  BipartiteMatching(int n) : graph(n), alive(n, 1), used(n, 0), match(n, -1), timestamp(0) {}

  void add_edge(int u, int v) {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  bool dfs(int idx) {
    used[idx] = timestamp;
    for(auto &to : graph[idx]) {
      int to_match = match[to];
      if(alive[to] == 0) continue;
      if(to_match == -1 || (used[to_match] != timestamp && dfs(to_match))) {
        match[idx] = to;
        match[to] = idx;
        return true;
      }
    }
    return false;
  }

  int bipartite_matching() {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return ret;
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      if(i < match[i]) {
        cout << i << "-" << match[i] << endl;
      }
    }
  }
};
//BipartiteMatching(n)　頂点n個
//add_edge(s,t)
//bipartite_matching()最大マッチング数
int main() {
    int n;cin>>n;
    VP vec1(n);
    rep(i,n){
        int x,y;cin>>x>>y;
        vec1[i]=make_pair(x,y);
    }
    VP vec2(n);
    rep(i,n){
        int x,y;cin>>x>>y;
        vec2[i]=make_pair(x,y);
    }
    BipartiteMatching g(n+n);
    rep(i,n){
        rep(j,n){
            if(vec1[i].F<vec2[j].F&&vec1[i].S<vec2[j].S){
                g.add_edge(i,n+j);
            }
        }
    }
    cout<<g.bipartite_matching()<<endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

pair<int, int> p[100000];

int main() {
    int n = gi();
    int m = gi();
    for (int i = 0; i < n; i++) {
        int a = gi();
        int b = gi();
        p[i] = {a, b};
    }

    sort(p, p+n);
    ll res = 0;
    for (int i = 0; i < n; i++) {
        int b = MIN(m, p[i].second);
        m -= b;
        res += ll(b) * ll(p[i].first);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
/* ( ε:)( ε:)(:ε )(:ε ) */
/* ( ε:)Give me AC(:ε ) */
/* ( ε:)( ε:)(:ε )(:ε ) */
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(count_ver, lower, upper) for (long long count_ver = lower; count_ver < upper; count_ver++)

typedef long long ll;
using namespace std;
const int MOD=10000007;

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}

//--------------------------------

void execute(){
  int n;
  cin>>n;
  int ac=0,wa=0,tle=0,re=0;
  REP(i,0,n){
    string s;
    cin>>s;
    if(s=="AC"){
      ac++;
    }
    if(s=="WA"){
      wa++;
    }
    if(s=="TLE"){
      tle++;
    }
    if(s=="RE"){
      re++;
    }
  }
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
}

//--------------------------------

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  execute();

  return (0);
}


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

const int N = 1e5+3;
int a[N];
int main(){
	int n; cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	int ct = 0;
	for (int i = 1; i <= n; i++){
		if (a[i] == i){
			swap(a[i], a[i+1]);
			ct++;
		}
		else if (a[i] == i && a[i+1] == i+1){
			swap(a[i], a[i+1]);
			ct++;
		}
		else if (a[i+1] == i+1 && i == n -1 ){
			ct++;
			swap(a[i],a[i+1]);
		}
	}
	cout << ct << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,a[200010],b[200010],cnt[200010],L,R,l,r;
inline int read()
{
	int x=0,w=0;char ch=0;
	while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return w?-x:x;
}
int main()
{
	r=L=n=read();
	for(int i=1;i<=n;i++)cnt[a[i]=read()]++;
	for(int i=1;i<=n;i++)cnt[b[n-i+1]=read()]++;
	for(int i=1;i<=n;i++)if(cnt[i]>n){cout<<"No";return 0;}
	cout<<"Yes\n";
	l=R=1;
	for(int i=1;i<=n;i++)
	if(a[i]==b[i]){L=min(L,i);R=max(R,i);}
	for(int i=L;i<=R;i++)
	if(l<L&&b[l]!=b[i]&&b[i]!=a[l])swap(b[i],b[l++]);
	else swap(b[i],b[r--]);
	for(int i=1;i<=n;i++)printf("%d ",b[i]);
}

Measured memory_bytes: 6120
#include <iostream>

int main() {
    int n, a, b;
    std::cin >> n >> a >> b;
    
    if ((b - a) % 2 == 0) {
        std::cout << "Alice" << std::endl;
    } else {
        std::cout << "Borys" << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());

        int num = 0;
        for(int i= 0; i <= n; i++) {
            if (i%2 != 0) {
                num++;
            }
        }
        //double a = (double) num / n;
        double result = (double)num / n;

        System.out.println(result);
    }
}

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

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  
  cout << w * h / 2.0 << endl;
  
  if(x == w / 2.0 && y == h / 2.0) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

void binPrint(int x, int bits){
  for (int i=bits-1; i>=0; i--){
    cout << (x&(1<<i)?1:0);
  }
  cout << endl;
}
int main(void){
  unsigned long long flg=0;
  int q, qtype, i;
  
  cin >> q;
  for (int _i=0; _i<q; _i++){
    cin >> qtype;
    if (qtype<=3) cin >> i;
    switch(qtype){
    case 0: // TST
      cout << (flg&(1ull<<i)?1:0) << endl;
      break;
    case 1: // SET
      flg |= 1ull<<i;
      break;
    case 2: // CLR
      flg &= ~(1ull<<i);
      break;
    case 3: // FLP
      flg ^= (1ull<<i);
      break;
    case 4: // ALL
      cout << (~flg==0?1:0) << endl;
      break;
    case 5: // ANY
      cout << (flg?1:0) << endl;
      break;
    case 6: // NON
      cout << (flg==0?1:0) << endl;
      break;
    case 7: // CNT
      i=0;
      for (unsigned long long tmp=flg; tmp; tmp>>=1){
        i += tmp&1;
      }
      cout << i << endl;
      break;
    case 8: // VAL
      cout << flg << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3136
import collections
def main():

    H, W, K = map(int, input().split())
    A = []
    for i in range(H):
        lv = input()
        A.append(lv)

    # print(A)
    row = []
    for i in range(H):
        temp = []
        for j in range(W):
            if A[i][j] == '#':
                temp.append(j)
        row.append(temp)

    # print(row)
    idx = 0
    ans = []
    ref = []
    for i in range(H):
        temp = []
        if len(row[i]) > 0:
            idx += 1
            prev = 0
            for j in range(len(row[i])):
                if j != len(row[i])-1:
                    temp += [str(idx)] * (row[i][j]-prev+1)
                    idx +=1
                else:
                    temp += [str(idx)] * (W-prev)
                prev = row[i][j]+1
        if ref == []:
            ref = temp
        ans.append(temp)

    for i in range(H):
        if ans[i] == []:
            ans[i] = ref
        ref = ans[i]
        # print(ans[i], len(ans[i]))
        print(" ".join(list(ans[i])))

if __name__ == '__main__':
    main()

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin>>d[i];
    sort(d.begin(),d.end());
    
    if(d[n/2-1]==d[n/2]){
        cout << 0 << endl;
    }else{
        cout << d[n/2]-d[n/2-1] <<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    ll a, b;
    cin >> a >> b;
    int x;
    if (a<0){
        if (b>=0)
            x = 0;
        else if ((b-a)%2)
            x = 1;
        else
            x = -1;
    }
    else if (a==0){
        x = 0;
    }
    else{
        x = 1;
    }

    if (x==0)
        cout << "Zero";
    else if (x==1)
        cout << "Positive";
    else
        cout << "Negative";
    cout << endl;
    return 0;

}


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

int h, w, d[105][105];
char a[105][105];
int main() {
	int i, j, t1, t2;
	cin >> h >> w;
	for(i=1; i<=h; i++) scanf("%s", &a[i][1]);
	for(i=2; i<=h; i++) d[i][0] = 1e9;
	for(j=2; j<=w; j++) d[0][j] = 1e9;
	d[1][1] = (a[1][1]=='#');
	for(i=1; i<=h; i++) for(j=1; j<=w; j++) {
		if(i==1 && j==1) continue;
		t1 = d[i-1][j] + (a[i-1][j]=='.' && a[i][j]=='#');
		t2 = d[i][j-1] + (a[i][j-1]=='.' && a[i][j]=='#');
		d[i][j] = min(t1, t2);
	}
	cout << d[h][w];
	return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define int long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
int a[N],b[N],n,sum,res;
signed main(){
	scanf("%lld",&n);
	fp(i,1,n)scanf("%lld",&a[i]),sum+=a[i];
	if(sum%(n*(n+1)>>1))return puts("NO"),0;
	sum/=(n*(n+1)>>1);
	fp(i,2,n)b[i]=a[i]-a[i-1];b[1]=a[1]-a[n];
	sort(b+1,b+1+n);
	fp(i,1,n-1)if((b[i+1]-b[i])%n)return puts("NO"),0;
	fp(i,1,n-1)res+=(b[n]-b[i])/n;
//	assert(false);
//	printf("%lld %lld\n",sum,res);
	if(sum<res||(sum-res)%n)return puts("NO"),0;
	puts("YES");
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

const int MAXN = 20 + 1;

int a[MAXN], b[MAXN], c[MAXN];

int solve(int n) {
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    res += b[a[i]];
    if (i < n && a[i] + 1 == a[i + 1]) res += c[a[i]];
  }
  return res;
}

int main() {
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  for (int i = 1; i <= n; ++i) std::cin >> b[i];
  for (int i = 1; i < n; ++i) std::cin >> c[i];
  std::cout << solve(n) << std::endl;
  return 0;
}


Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int x; cin >> x;
    cout << 1-x << endl;
}

Measured memory_bytes: 3616
from collections import Counter

N=int(input())

A=[]

for i in range(N):
    a=int(input())
    A.append(a)

C=Counter(A)

D=C.values()

cnt = 0

for x in D:
    if x%2!=0:
        cnt += 1
    else:
        pass
    
print(cnt)

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

int main()
{
  int N, Y;
  int res=0;
  cin >> N >> Y;

  for(int i=0;i<=N;i++){
    for(int j=0;j<=N-i;j++){
      int z = N - (i+j);
      if(10000*i+5000*j+1000*z == Y) {
        cout << i << " " << j << " " << z << endl;
        return 0;
      }
    }
  }
  
  cout << "-1 -1 -1" << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define M 100010


int main(){
    IOS;
 	
	ll a;cin>>a;
	ll x=a+a*a+a*a*a;
	cout<<x;
 	
 	
    return 0;
}


Measured memory_bytes: 3652
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0 for _ in range(N+1)]
b = [0 for _ in range(M+1)]

for i in range(1,N+1):
  a[i] = a[i-1] + A[i-1]
  
for j in range(1,M+1):
  b[j] = b[j-1] + B[j-1]
  
num = M
ans = 0
for k in range(N+1):
  if a[k] > K:
    break
  while b[num] > K - a[k]:
    num -= 1
  ans = max(ans, k+num)
  
print(ans)

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int n, m, q;
string s[2010];
int num[2010][2010];
int sa[2010][2010], sb[2010][2010];

int main() {
	cin >> n >> m >> q;
	rep(i, n) cin >> s[i];

	rep(i, n) {
		rep(j, m) {
			if (s[i][j] == '1') {
				++num[i+1][j+1];
			}
		}
 	}

	rep(i, n) {
		rep(j, m-1) {
			if (s[i][j] == '1' && s[i][j+1] == '1') {
				++sa[i+1][j+2];
			}
		}
	}

	rep(j, m) {
		rep(i, n-1) {
			if (s[i][j] == '1' && s[i+1][j] == '1') {
				++sb[i+2][j+1];
			}
		}
	}

	rep(i, n) {
		rep(j, m) {
			sa[i+1][j+1] += sa[i][j+1] + sa[i+1][j] - sa[i][j];
			sb[i+1][j+1] += sb[i][j+1] + sb[i+1][j] - sb[i][j];			
			num[i+1][j+1] += num[i][j+1] + num[i+1][j] - num[i][j];
		}
	}

	while (q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		--a; --b;
		int t = sa[c][d] - sa[a][d] - sa[c][b+1] + sa[a][b+1];
		int t2 = sb[c][d] - sb[c][b] - sb[a+1][d] + sb[a+1][b];
		int al = num[c][d] - num[a][d] - num[c][b] + num[a][b];
		cout << al - t - t2 << endl;
	}

	return 0;
}

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

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

  map<int, int> m;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    m[a]++;
  }

  int ans = 0;
  for (auto v : m) {
    if (v.second > v.first) {
      ans += v.second-v.first;
    } else if (v.second < v.first) {
      ans += v.second;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4736
#include <iostream>

using namespace std;

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


int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x_diff = x2 - x1;
  int y_diff = y2 - y1;
  cout << x2 - y_diff << ' ' << y2 + x_diff << ' ' << x1 - y_diff << ' ' << y1 + x_diff << endl;
  return 0;
}


Measured memory_bytes: 504
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    string s;
    cin >> s;
    int r = 0;
    for(int i = 0; i < 3; i++){
        if (s[i] - 48 == 1){
            r++;
        }
    }
    cout << r;
    cout << endl;
}


Measured memory_bytes: 256
const main = (input) => {
  const args = input.split('\n')
  const n = Number(args[0])
  const boss = args[1].split(' ').map(v => Number(v))
  let subordinate = Array(n).fill(0)
  boss.forEach(element => {
    subordinate[element - 1] += 1
  })
  subordinate.forEach(element => {
    console.log(element)
  })
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	int n=s.size()-1;
	int64_t ans=0;
	for(int i=0;i<(1<<n);++i){
		int64_t num=s.front()-'0',sum=0;
		for(int j=0;j<n;++j){
			if(i&(1<<j)){
				sum+=num;
				num=0;
			}
			num*=10;
			num+=s.at(j+1)-'0';
		}
		ans+=sum+num;
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3656
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))

d = defaultdict(int)
ans = 0
s = 0
d[0] = 1
for i, a in enumerate(A):
    a %= M
    s += a
    ans += d[s%M]
    d[s % M] += 1

print(ans)

Measured memory_bytes: 14668
import sys
from math import gcd
from collections import defaultdict


def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()
mod = 10**9+7
plus = defaultdict(int)
minus = defaultdict(int)
flag = defaultdict(int)
A_zero,B_zero = 0,0
zero_zero = 0
for i in range(N):
    a,b = MI()
    if a == b == 0:
        zero_zero += 1
    elif a == 0:
        A_zero += 1
    elif b == 0:
        B_zero += 1
    else:
        if a < 0:
            a,b = -a,-b
        a,b = a//gcd(a,b),b//gcd(a,b)
        if b > 0:
            plus[(a,b)] += 1
        else:
            minus[(a,b)] += 1
            flag[(a,b)] = 0

ans = 1

for a,b in plus.keys():
    ans *= pow(2,plus[(a,b)],mod)+pow(2,minus[(b,-a)],mod)-1
    ans %= mod
    flag[(b,-a)] = 1

for key in minus.keys():
    if flag[key] == 0:
        ans *= pow(2,minus[key],mod)
        ans %= mod

ans *= pow(2,A_zero,mod)+pow(2,B_zero,mod)-1
ans %= mod

ans += zero_zero-1
ans %= mod

print(ans)


Measured memory_bytes: 177844
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e5 + 5, mod = (int) 1e9 + 7;
struct mat {
	int a[3][3];
	mat() { memset(a, 0, sizeof a); }
	int *operator [] (int x) { return a[x]; }
} m0, m1;
mat operator * (mat x, mat y) {
	mat z;
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 3; ++k)
				z[i][j] = (z[i][j] + (LL) x[i][k] * y[k][j]) % mod;
	return z;
}
mat fpm(mat a, int b) {
	if (b == 0) {
		mat res;
		res[0][0] = res[1][1] = res[2][2] = 1;
		return res;
	}
	mat res = fpm(a * a, b >> 1);
	if (b & 1)
		res = res * a;
	return res;
}
int a[4], marked[N];
int main() {
	int n, m;
	cin >> n >> m;
	a[2] = 1;
	a[1] = 1;
	a[0] = 1;
	for (int j = 0; j < m; ++j) {
		int x;
		cin >> x;
		marked[j] = --x;
	}
	m0[0][2] = 1;
	m0[0][1] = 1;
	m0[0][0] = 1;
	m0[2][0] = 1;
	m0[2][1] = 1;
	m0[2][2] = 2;
	m0[1][1] = 1;
	m0[1][2] = 2;
	m1 = m0;
	m1[2][0]--;
	m1[2][1]--;
	m1[2][2]--;
	int cur = -1;
	mat res;
	res[0][0] = res[1][1] = res[2][2] = 1;
	for (int j = 0; j < m; ++j) {
		res = res * fpm(m0, marked[j] - cur - 1);
		res = res * m1;
		cur = marked[j];
	}
	res = res * fpm(m0, n - cur - 2);
/*	for (int j = 0; j < n - 1; ++j) {
		int res = (mark[j] ? 0 : a[2]);
		a[2] = a[2] + a[1] * 2 + a[0] + res;
		a[1] = a[1] + a[0] + res;
		a[0] = a[0] + res;
	}
	cout << a[2] << endl; */
	cout << ((LL) res[0][2] + res[1][2] + res[2][2]) % mod << endl;
}




Measured memory_bytes: 640
def main():
    N, M = map(int, input().split())
    S = []
    for _ in range(M):
        S.append(set(list(map(int, input().split()))[1:]))
    P = list(map(int, input().split()))

    ans = 0
    for bit in range(1 << N):
        on_switches = set([])
        for i in range(N):
            if bit & (1 << i):
                on_switches.add(i + 1)

        flag = True
        for s, p in zip(S, P):
            if len(s & on_switches) % 2 != p:
                flag = False
        if flag is True:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n, k;
	cin >> n >> k;
	
	vector<int> cu;
	bool used[10] = {};
	REP(i, k) {
		int a;
		cin >> a;
		used[a] = true;
	}
	REP(i, 10) if (!used[i]) cu.push_back(i);
	
	int keta = log10(n) + 1;
	
	bool f = true;
	REP(i, keta) {
		bool tmp = false;
		REP(j, cu.size()) if (n / (int)pow(10, i) % 10 == cu[j]) tmp = true;
		if (!tmp) f = false;
	}
	if (f) {
		cout << n << endl;
	}
	else {
		int tar = n / (int)pow(10, keta - 1);
		vector<int>::iterator itr;
		if ((itr = upper_bound(cu.begin(), cu.end(), tar)) == cu.end()) {
			if (used[0]) cout << cu[0] << cu[0];
			else cout << cu[1] << cu[0];
		}
		else {
			cout << *itr;
		}
		FOR(i, 1, keta) cout << cu[0];
	}
	return 0;
}

Measured memory_bytes: 256
//by xiqiao
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long ll;
int n;
int l[maxn][30],r[maxn][30];
int a[maxn];
void pre_work(int wh,int v){
	l[0][wh]=0;l[1][wh]=0;
	for(int i=2;i<=n;i++){
		if(a[i-1]-a[i-2]<=v)l[i][wh]=l[i-1][wh];
		else l[i][wh]=i-1;
	}
	r[n][wh]=n;r[n-1][wh]=n;
	for(int i=n-2;i>=0;i--){
		if(a[i+1]-a[i]<=v)r[i][wh]=r[i+1][wh];
		else r[i][wh]=i+1;
	}
}
int f[maxn*3],f2[maxn*3];
int main(){
	//freopen("1.in","r",stdin);
	int V;
	scanf("%d%d",&n,&V);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	int g=0;
	for(int x=V;x;x>>=1){
		pre_work(g++,x);
	}
	pre_work(g++,0);
	for(int i=0;i<(1<<g);i++)f[i]=0;
	for(int i=0;i<(1<<g);i++){
		for(int j=0;j<g;j++){
			if((1<<j)&i)continue;
			f[i|(1<<j)]=max(f[i|(1<<j)],r[f[i]][j]);
		}
	}
	for(int i=0;i<(1<<g);i++)f2[i]=n;
	for(int i=0;i<(1<<g);i++){
		for(int j=0;j<g;j++){
			if((1<<j)&i)continue;
			f2[i|(1<<j)]=min(f2[i|(1<<j)],l[f2[i]][j]);
		}
	}
	if(f[(1<<g)-1]<n){
		for(int i=0;i<n;i++)puts("Impossible");
		return 0;
	}
	int L,R;L=1;
	for(L=0;L<n;L=R){
		bool ok=0;R=r[L][0];
		for(int j=0;j<(1<<g);j++){
			if(j&1)continue;
			if(f[j]>=L && f2[(1<<g)-2-j]<=R){
				ok=1;break;
			}
		}
		for(int j=L;j<R;j++){
			if(!ok)puts("Impossible");
			else puts("Possible");
		}
	}
	return 0;
}

Measured memory_bytes: 54784
#include<stdio.h>
#include<string.h>
int main(){
  int n, l, i, sum = 0, max = 0;
  scanf("%d", &n);
  for(i = 0; i < n; ++i){
    scanf("%d", &l);
    sum += l;
    if(max < l) max = l;
  }
  sum -= max;
  if(max >= sum) puts("No");
  else puts("Yes");
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> vecV(N);
  vector<int> vecC(N);
  
  for(int i=0;i<N;i++){
  	cin>>vecV.at(i);
  }
  for(int i=0;i<N;i++){
  	cin>>vecC.at(i);
  }
  
  int sum=0;
  
  for(int i=0;i<N;i++){
  	if(vecV.at(i)>vecC.at(i))
      sum+=vecV.at(i)-vecC.at(i);
  }
  
  cout<<sum<<endl;
}

Measured memory_bytes: 256
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll l , r , d;
ll solve(ll n){
	return n/d;
}
void solve(){
	cin>>l>> r>> d;
	ll ans=solve(r)-solve(l-1);
	cout<<ans<<endl;
}

int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 3808
x, n = map(int, input().split())
p = list(map(int, input().split()))

a = set()
for i in range(-100, 201):
    a.add(i)
for v in p:
    a.remove(v)
a = list(a)
b = list(map(lambda v: abs(v - x), a))
print(a[b.index(min(b))])


Measured memory_bytes: 61592
import sys
from math import floor

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    A, B, N = map(int, rl().split())
    
    if N < B:
        ans = floor(A * N / B) - A * floor(N / B)
    else:
        ans = floor(A * (B - 1) / B) - A * floor((B - 1) / B)
    print(ans)


if __name__ == '__main__':
    solve()


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

using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvpi = vector<vpi>;
using pl = pair<long long, long long>;
using vl = vector<long long>;
using vpl = vector<pl>;
using vvl = vector<vl>;
using vvpl = vector<vpl>;

void resuelveCaso() {
	int n; cin >> n;
	vi stones(n, 0);
	string s; cin >> s;
	int numW = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'W'){
			numW++;
			stones[n-i-1] = 1; 
		} 
	}
	int moves = 0;
	for(int i = 0; i < numW; i++) {
		if (stones[i] == 0) moves++;
	}
	cout << moves << endl;

}

int main() {
	int T = 1;
	for (int i = 1; i <= T; i++) {
		//cout << "Case #" << i << ": ";
		resuelveCaso();
	}
	return 0;
}




Measured memory_bytes: 4440
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
d = 0
ans = []
ap = 0
for i in range(n):
    if ap == a[i]:
        d += 1
        if d == 2:
            ans.append(a[i])
        elif d == 4:
            ans.append(a[i])
    else:
        d = 1
        ap = a[i]    
    if len(ans)> 1:
      break
ans.append(0)
ans.append(0)
print(ans[0]*ans[1])

Measured memory_bytes: 62704
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        string S = Console.ReadLine();
        Console.WriteLine(700 + 100 * S.Count(c => c == 'o'));
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }

}


Measured memory_bytes: 13268
def d_lucky_pin():
    N = int(input())
    S = input()

    # 暗証番号を全探索
    ans = 0
    for v in range(1000):
        pin = '{0:03}'.format(v)
        current_searching = 0

        for ch in S:
            if ch == pin[current_searching]:
                current_searching += 1
            if current_searching == 3:
                ans += 1
                break
    return ans

print(d_lucky_pin())

Measured memory_bytes: 40684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int n =1;
		int x;
		
		Scanner scan = new Scanner(System.in);
		
		while((x = scan.nextInt()) != 0) {
			
			System.out.println("Case " + n++ + ": " + x);
			
		}
	}

}


Measured memory_bytes: 41352
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a[N];
  int b[8];
  for(int i = 0; i < 8; ++i){
    b[i] = -1;
  }
  int point = 0;
  for(int i = 0; i < N; ++i){
    cin >> a[i];
    if(a[i]>=3200)point += 1;
    else{
      for(int j = 0; j < 8; ++j){
        if(a[i]>=400*j && a[i]<=(400*j+399))b[j]=1;
      }
    }
  }
  int count = 0;
  for(int i = 0; i < 8; ++i){
    if(b[i] > 0)count += 1;
  }
  if(count == 0)cout << 1 << " " << count + point << endl;
  else cout << count << " " << count + point << endl;

  return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 1000005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897L
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"No\n"; return 0;}
#define yup {cout<<"Yes\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}
 
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// Dont paste code two times in the text file.
// ============================================================

int main() {
    
    get(n);
    cout<<(n+1)/2<<endl;
    return 0;  
}   


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
	cin >> h >> w;
	vector<string> s(h);
	rep(snip_i, h) cin >> s.at(snip_i);
	rep(y, h)rep(x, w){
		if(s.at(y).at(x) == '.') continue;
		bool flag = false;
		rep(i, 4){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
			if(s.at(ny).at(nx) == '#')flag = true;
		}
		if(flag == false){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll ans = INF;
	ll X = 0,N,L;
	ll Y;
	ll Z = INF;
	cin >> N >> L;
	FOR(i,1,N+1)X+=(L+i-1);
	Y = X;
	FOR(i,1,N+1){
		Y -= (L+i-1);
		if(abs(Y-X)<=Z){
			ans = Y;
			Z = abs(Y-X);
		}
		Y += (L+i-1);
	}
	cout << ans << endl;
}

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

cnt = 0
flag = False
for i in a:
    if i <= x:
        x -= i
        cnt += 1
        if x == 0:
            break
    else:
        break
else:
    cnt -= 1
print(cnt)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll a,b;
  cin >> a >> b;
  if(a%2==b%2)cout << (a+b)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;


}

Measured memory_bytes: 3604
import java.util.Scanner;

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

		long a = scanner.nextLong();

		long b = scanner.nextLong();

		long x = a*b;

		if(a < b) {
			long temp = a;
			a = b;
			b = temp;

		}

		long r = a%b;

		while(r != 0) {
			a = b;
			b = r;
			r = a%b;
		}

		System.out.println(x/b);		

	}

}

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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    map<int, bool> mp;
    rep(i, 0, n) mp[a[i]] = !mp[a[i]];
    int ans = 0;
    for(auto i : mp) if(i.second) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define pii pair<int, int>
#define forr(i,a,n) for (int i = (a); i < (n); ++i)
#define rforr(i,a,n) for (int i = (a); i > (n); --i)
#define ALL(x) x.begin(),x.end()
#define LEN(X) ((int)(X).size())
#define CASET int _T; cin >> _T; forr(caset,0,_T)
#define int ll

int power(int base, ll exp, int mod=INT_MAX) {
    if (exp == 0) return 1;
    if (exp == 1) return base%mod;
    ll res = (ll) power(base,exp/2,mod); res = res*res%mod;
    return (exp%2==0) ? res : (base*res)%mod;
}

int n; 

signed main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    //freopen("input.txt","w",stdout);
    cin >> n;
    vi subs(n);
    forr(i,0,n-1) {
        int x; cin >> x;
        subs[x-1] += 1;
    }
    for(int i : subs) {
        cout << i << '\n';
    }
    
}


Measured memory_bytes: 4784
def main():
    N = int(input())
    A = list(map(int,input().split()))
    buka_num = [0]*(N+1)

    for i in range(N-1):
        buka_num[A[i]] += 1

    for i in range(1,N+1,1):
        print(buka_num[i])

main()


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

int main ()
{
	int a,b,c,d;

	cin >> a >> b >> c >> d;
	while (a > 0 && c > 0)
	{
		c = c - b;
		if (c <= 0)
		{
			cout << "Yes";
			return 0;
		}
		a = a - d;
	}
	if (a <= 0)
		cout << "No";
	else
		cout << "Yes";
	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
int main() {
	int n, k;
	scanf("%d", &n);
	printf("%d:", n);
	while (n % 2 == 0) {
		printf(" 2");
		n /= 2;
	}
	for (k = 3; n>1; k += 2) {
		if (k*k > n) {
			printf(" %d", n);
			break;
		}
		while (n%k == 0) {
			printf(" %d", k);
			n /= k;
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2760
DEBUG = 0

INF = 10**9
WALK = [[0, 1], [0, -1], [1, 0], [-1, 0]]
WARP = [*[-2, -1, 1, 2].product([-2, -1, 1, 2]), [2, 0], [-2, 0], [0, 2], [0, -2]]

h, w = gets.split.map &:to_i
ch, cw = gets.split.map &:to_i
dh, dw = gets.split.map &:to_i
# 番兵をつけておく
v_margin = [[-1] * (w + 4)] * 2
dists = v_margin + h.times.map { [-1, -1] + gets.chomp.each_char.map { _1 == '.' ? INF : -2 } + [-1, -1] } + v_margin

puts maze if DEBUG >= 1

# 01-BFS
start = [ch - 1 + 2, cw - 1 + 2, 0]
goal_x, goal_y = dh - 1 + 2, dw - 1 + 2
dists[start[0]][start[1]] = 0
queue = [start]
until queue.empty?
  p queue if DEBUG >= 1
  puts maze if DEBUG >= 2
  i, j, cost = *queue.shift
  
  # ゴールなら
  if i == goal_x and j == goal_y
    p cost
    exit
  end

  is_edge = false
  WALK.each do |(di, dj)|
    _i, _j = i + di, j + dj
    if dists[_i][_j] <= cost
      # 枝刈り1用
      is_edge = true if dists[_i][_j] == -2

      next
    end
    dists[_i][_j] = cost
    queue.unshift [_i, _j, cost]
  end

  # 枝刈り1: 徒歩範囲の内部ではワープしない
  if is_edge
    WARP.each do |(di, dj)|
      _i, _j, _cost = i + di, j + dj, cost + 1

      # 枝刈り2: 更新できないときはキューに追加しない
      next if _cost >= dists[_i][_j]

      dists[_i][_j] = _cost
      queue << [_i, _j, _cost]
    end
  end
end

# 到達できない場合
p -1


Measured memory_bytes: 24568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,j,sum=0,sum2=0;
  cin>>n;
  vector<ll> a(n),b(n),c(n);
  for(i=0;i<n;i++){
	cin>>a[i];
    sum+=a[i];
  }
  ll m=n*(n+1)/2,t;
  if(sum%m!=0){
    cout<<"NO"<<endl;
    return 0;
  }else{
	t=sum/m;
  }
  for(i=0;i<n-1;i++){
	b[i]=a[i+1]-a[i];
  }
  b[n-1]=a[0]-a[n-1];
  
  for(i=0;i<n;i++){
	if(t-b[i]<0||(t-b[i])%n!=0){
		cout<<"NO"<<endl;
      	return 0;
    }
  }
	
  cout<<"YES"<<endl;
  
}
  

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

#define y1 dmytxdy
#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,a,k,s;

ll qpow(ll x,ll p,ll cys){
	ll ret=1;
	for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;
	return ret;
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++){
		a=readint(); k=readint();
		while(a%k&&a>2*k){
			ll r=a/k;
			ll tmp=r+1;
			ll num=(a-r*k)/tmp;
			a-=num*tmp;
			if(a%k==0) break;
			a-=a/k+1;
		}
		if(a%k==0) s^=a/k;
		else if(a>k) s^=(a-k)&1?0:1;
	}
	if(s) printf("Takahashi\n");
	else printf("Aoki\n");
	return 0;
}

Measured memory_bytes: 3664
n, q = map(int, input().split())
s = input()
a = [0]
p = ''
for c in s:
    a.append(a[-1] + (1 if p == 'A' and c == 'C' else 0))
    p = c
for _ in range(q):
    l, r = map(int, input().split())
    print(a[r] - a[l])

Measured memory_bytes: 7688
// Hint: Don't look, No need, Let'em Play.

#pragma optimize("O2")
#include <bits/stdc++.h>
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

void solve() {
    int n;
    cin >> n;
    // --n;
    string ans;
    while (n > 0) {
        if (n % 26 == 0) {
            ans += 'z' + 1;
            n /= 26;
            --n;
        }
        else {
            ans += (n % 26) + 'a';
            n /= 26;
        }
    }
    // cout << ans << '\n';
    for (int i = (int)ans.size() - 1; i >= 0; --i) {
        cout << char(ans[i] - 1);
    }


}

signed main() {
    fast;
    int t = 1; // cin >> t;
    while (t--) {
        solve();
    }


  return 0;
}


Measured memory_bytes: 3600
import sys
readline = sys.stdin.buffer.readline

def main():
    N = int(readline())
    S = input()
    ans =0
    x = 0
    for s in S:
        if s == 'I':
            x += 1
            ans = max(ans, x)
        else:
            x -= 1
    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  rep(i, N){
    cin >> vec.at(i);
  }
  int M;
  rep(j, N){
    rep(i, N - 1){
      if(vec.at(i) > vec.at(i + 1)){
        M = vec.at(i);
        vec.at(i) = vec.at(i + 1);
        vec.at(i + 1) = M;
      }
    }
  }
  int A;
  A = 0;
  rep(i, K){
    A = A + vec.at(i);
  }
  cout << A << endl;
}
    
  

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>
//#include "show_vector.hh"

using namespace std;

#define debug false


int magic(int &from, int &to, vector<int> const &x, vector<int> const &y){
  int d_x = abs(x[from] - x[to]);
  int d_y = abs(y[from] - y[to]);
  //printf("from %d to %d\n", from, to);
  //printf("d_x : %d\n", d_x);
  //printf("d_y : %d\n", d_y);
  return d_x + d_y;
}


int main(int argc, char *argv[]){

  int H, W, D;
  cin >> H >> W >> D;
  vector<int> x(H*W+1), y(H*W+1);
  int tmp;
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      cin >> tmp;
      x[tmp] = w;
      y[tmp] = h;
    }
  }
  int Q;
  cin >> Q;
  int L[Q], R[Q];
  for(int i = 0; i < Q; i++){
    cin >> L[i] >> R[i];
  }

  // メモか
  // 0->...
  // 1 -> ...

  vector<int> from_to(W*H+1, 0);
  for(int i = 1; i <= W*H; i++){
    int from = (i-D<=0)?i:i-D;
    int to = i;
    from_to[to] = magic(from, to, x, y);
    //printf("from %d to %d : %d\n", from, to, from_to[to]);
    if(to > D) from_to[to] += from_to[to-D];
  }
  for(int i = 0; i < Q; i++){
    printf("%d\n", from_to[R[i]] - from_to[L[i]] );
  }
  //show_vector(from_to);



  return 0;
}


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

using namespace std;
typedef long long ll;




int main()
{
    ios_base::sync_with_stdio(0);
    ll n,q,b,c,sum = 0; cin >> n;
    ll arr[n];
    map<ll,ll> m;
    for(ll i=0;i<n;i++){
        cin >> arr[i];
        sum += arr[i];
        m[arr[i]]++;
    }
    cin >>q;
    for(int i=0;i<q;i++){
        cin >> b >> c;
        sum += (c-b)*m[b];
        m[c] += m[b];
        m[b] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 10168
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;
    cin >> n;
    set<string> words;
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        words.insert(s);
    }
    cout << words.size() << endl;
    return 0;
}


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

int n,s;
int ans;

void dfs(int x,int now,int co);

int main(){
  while(1){
    cin>>n>>s;
    if(!n && !s)break;
    ans=0;
    dfs(-1,0,0);
    cout<<ans<<endl;
  }
}

void dfs(int x,int now,int co){
  if(co==n && now==s){
    ans++;
    return;
  }
  if(now>s)return;
  for(int i=x+1;i<=9;i++){
    dfs(i,now+i,co+1);
  }
  return;
}
  

Measured memory_bytes: 1160