akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define   ll     long long int

int get(int x)
{
    if (x < 400) {
        return 0;
    }
    if (x < 800) {
        return 1;
    }
    if (x < 1200) {
        return 2;
    }
    if (x < 1600) {
        return 3;
    }
    if (x < 2000) {
        return 4;
    }
    if (x < 2400) {
        return 5;
    }
    if (x < 2800) {
        return 6;
    }
    if (x < 3200) {
        return 7;
    }
}

int main( )
{
    set<int> st;
    int n, i, c = 0;
    cin >> n;
    for (i = 1; i <= n; i++) {
        int j; cin >> j;
        if (j >= 3200) {
            c++;
            continue;
        }
        st.insert(get(j));
    }
    cout << max(1, (int) st.size()) << ' ' << ((int) st.size() + c) << '\n';
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static int[] divisor;
	public static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		divisor = new int[n+1];
		for (int i = 2; i <= n; i++) {
			int k = i;
			for (int j = 2; j <= i; j++) {
				while(k%j==0) {
					divisor[j]++;
					k /= j;
				}
			}
		}
		int ans = 0;
		ans += count(74);
		ans += count(24)*(count(2)-1);
		ans += count(14)*(count(4)-1);
		ans += count(4)*(count(4)-1)/2*(count(2)-2);
		System.out.println(ans);
		sc.close();
	}
	public static int count(int x) {
		int res = 0;
		for (int i = 0; i <= n; i++) {
			if(divisor[i]>=x) res++;
		}
		return res;
	}
}

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

int main(){
  string s; cin >>s; int n=s.length();
  for(int i=0; i<n; i++)
  {
    if(i%2==0 && s[i]=='L'){cout <<"No"; return 0;}
    if(i%2==1 && s[i]=='R'){cout <<"No"; return 0;}
  }
  cout <<"Yes";
return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,m,b_idx;
  string s;
  vector<ll> ans;
  cin >> n >> m >> s;
  for(int i=n;i>0;){
    b_idx = -1;
    for(int j=1;j<=m&&i-j>=0;j++){
      if(s[i-j]=='0') b_idx = i-j;
    }
    if(b_idx==-1){
      cout << -1<<endl;
      return 0;
    }
    ans.push_back(i-b_idx);
    i = b_idx;
  }
  reverse(ans.begin(),ans.end());
  for(auto i:ans){
    cout <<i<<" ";
  }
  cout << endl;
}


Measured memory_bytes: 1480
n,m = map(int,input().split())
#lef[i]:iの左親,ran[i]:iの左親までの距離
lef = list(range(n+1))
ran = [0]*(n+1)

#左親の発見および更新
def f(x):
    if lef[x]==x:
        return x
    #ran[x] = ran[x]+ran[lef[x]]
    lef[x],ran[x]= f(lef[x]),ran[x]+ran[lef[x]]
    
    return lef[x]

for i in range(m):
    l,r,d = map(int,input().split())
    a = f(l)
    b = f(r)
    if a == b and ran[r]-ran[l] != d:
        print("No")
        exit()
    else:
        lef[b] = a
        ran[b] = ran[l]+d-ran[r]

print("Yes")


Measured memory_bytes: 9996
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#define int long long 
#define pb push_back
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

using namespace std;

const int N = 5e5 + 10, mod = 1e9 + 7, inf = 1e18 + 7, logn = 23;
const double pi = acos(-1);


void solve() {
	//soln
	int n;
	cin >> n;
	int q = n % 10;
	if(n % 10 == 3) {
		cout << "bon" << endl;
	} else if(n % 10 == 1 || q == 0 || q == 6 || q == 8) {
		cout << "pon" << endl;
	} else cout << "hon" << endl;
}
main() {
	bst;
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}


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

int main(){
  int N;
  cin >> N;
  
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin >> d.at(i);
  }
  
  sort(d.begin(),d.end());
  cout << d.at(N/2) -d.at((N/2)-1) << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    int x,y;std::cin>>x>>y;
    std::cout<<std::max({x+y,x-y,x*y})<<'\n';
}


Measured memory_bytes: 256
N = int(input())
cnt = 0
if N>2:
    for x in range(2,int(N**0.5)+1):
        if N%x==0:
            y = N//x
            if N//(x-1)==N%(x-1):
                cnt += x-1
            if N//(y-1)==N%(y-1):
                cnt += y-1
    cnt += N-1
print(cnt)

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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, m;
	cin >> n >> m;
	cout << (1900*m + 100*(n-m)) * pow(2, m);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int>vec;
  int n,m,a[222222],x[222222]={0};
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
    x[a[i]]++;
  }
  for(int i=1;i<=n;i++){
    if(x[i]!=0) vec.push_back(x[i]);
  }
  int ans=0,z=vec.size();
  if(z-m<0) ans=0;
  else{ 
    sort(vec.begin(),vec.end());
    for(int i=0;i<z-m;i++) ans+=vec[i];
  }  
  cout<<ans<<endl;
  return(0);
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];
ll B[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, M) {
        cin >> B[i];
    }

    ll x = 0, y = 0;
    REP(i, N - 1) {
        ll d = A[i + 1] - A[i];
        ll p = (i + 1) * (N - (i + 1)) % MOD;
        x += d * p % MOD;
        x %= MOD;
    }
    REP(i, M) {
        ll d = B[i + 1] - B[i];
        ll p = (i + 1) * (M - (i + 1)) % MOD;
        y += d * p % MOD;
        y %= MOD;
    }
    cout << x * y % MOD << endl;
    return 0;
}

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

using namespace std;

const int NMAX = 1000;
const int SIGMA = 26;

string s;
int N, pre[NMAX+2][SIGMA], mx[NMAX+2][SIGMA];
int Ans = NMAX;
int main()
{
    long long A,B;
    cin >> N >> A >> B;
    if( A > B ) {
        cout << "0\n";
        return 0;
    }
    if( A != B && N == 1 ) {
        cout << "0\n";
        return 0;
    }
    cout << B*N - A*N + 1 - 2*(B - A) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <cassert>
#include <functional>

using namespace std;
typedef long long ll;


#define SIZE 101
#define INF 1000000000
#define LLINF 1000000000000000000LL


int main(){
  int n, a[SIZE][SIZE];
  int sum[SIZE][SIZE] = {};

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d",a[i]+j);
      sum[i+1][j+1] = a[i][j] + sum[i+1][j];
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n+1;j++){
      sum[i+1][j] += sum[i][j];
    }
  }

  int ans = -INF;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){

      for(int p=i+1;p<n+1;p++){
        for(int q=j+1;q<n+1;q++){
          ans = max(ans, sum[i][j] + sum[p][q] - sum[i][q] - sum[p][j]);
        }
      }
      
    }
  }

  printf("%d\n",ans);
  
  return 0;
}



Measured memory_bytes: 3280
//a.c A-Eating Symblos Easy
#include<stdio.h>

int main(void){
    char buf[4];
    int sum = 0;
    scanf("%s",buf);
    
    for(int i=0;i<4;++i){
        if(buf[i]=='+'){
            sum++;
        }else{
            sum--;
        }
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
#grind repainting
h,w=map(int,input().split())

maze=[]
maze.append(["#" for i in range(2+w)])

for i in range(h):
    x=list(input())
    x.insert(0,"#")
    x.append("#")
    maze.append(x)
    
maze.append(["#" for i in range(2+w)])
#(1,1)から(h,w)に最短距離でどのくらいでいけるのかどうか調べる
visited=[[False for i in range(w+2)] for j in range(h+2)]
for i in range(h+2):
    for j in range(w+2):
        if (i==0 or i==h+1) or (j==0 or j==w+1):
            visited[i][j]=True
#visited[u][v]=(u,v)にすでに訪れたことがあるのかどうか
from collections import deque
visited[1][1]=True
d=deque()
e=deque()
d.append((1,1))
distance=0

capable=False

while (not capable) and d:
    distance+=1
    while d:
        X=d.popleft()
        x,y=X[0],X[1]
        if visited[x][y+1]==False and maze[x][1+y]==".":
            visited[x][y+1]=True
            e.append((x,1+y))
        if visited[x][y-1]==False and maze[x][y-1]==".":
            visited[x][y-1]=True
            e.append((x,y-1))
        if visited[x-1][y]==False and maze[x-1][y]==".":
            visited[x-1][y]=True
            e.append((x-1,y))
        if visited[x+1][y]==False and maze[x+1][y]==".":
            visited[x+1][y]=True
            e.append((x+1,y))
    if e:
        d=e
        e=deque()
    if visited[h][w]==True:
        capable=True
cnt=0

for i in range(h+2):
    for j in range(w+2):
        if maze[i][j]==".":
            cnt+=1
if capable:
    print(cnt-distance-1)
else:
    print(-1)


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

typedef long long LL;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/02  Problem: Nagoya_univ_contest16_d  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N, Q, K;
typedef pair<long long, long long >PLL;
LL ans = 0LL;
vector<vector<PLL>> G;

#define DijkV 100005
long long dist[DijkV];
void Dijkstra(int s, int t) {
	const long long INIT_NUM = LLONG_MAX / 10;
	FOR(i, 0, DijkV)dist[i] = INIT_NUM;

	dist[s] = 0;
	priority_queue<PLL, vector<PLL>, greater<PLL>> que;
	que.push(PLL(0LL, s));

	while (!que.empty()) {
		PLL p = que.top(); que.pop();
		LL v;  LL d;
		tie(d, v) = p;

		if (d > dist[v]) continue;

		FOR(i, 0, (int)G[v].size()) {
			int nv = G[v][i].first;
			if (dist[nv] > dist[v] + G[v][i].second) {
				dist[nv] = dist[v] + G[v][i].second;
				que.push(PLL(dist[nv], nv));
			}
		}
	}
}

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

	cin >> N;
	G = vector<vector<PLL>>(N+1);
	int a, b, c;

	FOR(i, 0, N - 1) {
		cin >> a >> b >> c;
		G[a].push_back(PLL(b, c));
		G[b].push_back(PLL(a, c));
	}
	cin >> Q >> K;
	Dijkstra(K, 0);

	int x, y;
	FOR(i, 0, Q) {
		cin >> x >> y;
		cout << dist[x] + dist[y] << endl;
	}


	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

using pss = pair<string, string>;

int n;
string s;
map<pss, int> mp;

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

   for (int mask = 0; mask < (1<<n); mask++) {
      string r, b;
      rep (i, n) {
         if (mask & (1<<i)) {
            r.push_back(s[i]);
         } else {
            b.push_back(s[i]);
         }
      }
      mp[{r, b}]++;
   }

   string t = s;
   t = t.substr(n, 2*n);
   ll ans = 0;
   for (int mask = 0; mask < (1<<n); mask++) {
      string r, b;
      rep (i, n) {
         if (mask & (1<<i)) {
            r.push_back(t[i]);
         } else {
            b.push_back(t[i]);
         }
      }
      reverse(all(r));
      reverse(all(b));
      ans += mp[{b, r}];
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 87040
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string s, s2;
string t, t2;
vector<string> vec, vec2;

string calc(string s, vector<string> &vec)
{
  string t, u; bool flag = false;
  vec.clear();
  for(int i = 0; i < s.size(); i++){
    if(flag){
      if(s[i] == '\"'){
        flag = false;
        vec.push_back(u);
      }
      else u += s[i];
    }
    else{
      if(s[i] == '\"'){
        flag = true;
        t += s[i];
        u = "";
      }
      else{
        t += s[i];
      }
    }
  }
  return t;
}

int main(void)
{
  while(1){
    cin >> s >> s2;
    if(s == ".") break;

    t = calc(s, vec);
    t2 = calc(s2, vec2);

    /*cout << t << endl;
    cout << t2 << endl;
    cout << endl;*/

    if(vec.size() != vec2.size() || t != t2){
      cout << "DIFFERENT" << endl;
      continue;
    }
    int cnt = 0;
    for(int i = 0; i < vec.size(); i++){
      if(vec[i] != vec2[i]) cnt++;
    }
    if(cnt == 0) cout << "IDENTICAL" << endl;
    else if(cnt == 1) cout << "CLOSE" << endl;
    else cout << "DIFFERENT" << endl;
  }
  return 0;
}



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

using namespace std;

typedef long long int ll;

int main()
{
	int n;
	cin >> n;
	vector<int> vec(n);

	int count = 0,curr = 0;

	for(int i = 0; i < n; i++){
		cin >> vec[i];
		if(i == 0){
			count++;
			curr = vec[i];
		}
		else if(vec[i] <= curr){
			count++;
			curr = vec[i];
		}
	}

	cout << count << endl;


	return 0;
}


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

int main(){
  int n,y,x = 0,o,z,kai = 0;
  cin >> n >> y;
  
  if(y < n * 1000 || y > n * 10000){
    cout << "-1 -1 -1" << endl;
    kai = 1;
  }
  else{
    
    for(z = n; z >= 0; z--){
      for(o = 0; o <= n - z; o++){
        x = n - o - z;
        if(1000 * x + 5000 * o + 10000 * z == y){
          cout << z << " " << o << " " << x << endl;
          kai = 1;
          break;
        }
      }
      if(kai == 1)break;
    }
    
  }
  if(kai == 0)cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 3608
#include <iostream>

template<int MOD>
class Modint{
public:
	long long val;
	Modint(long long val = 0) : val(val) {}
	Modint &operator+=(const Modint &a){
		val += a.val;
		if(val >= MOD) val -= MOD;
		return *this;
	}
	Modint &operator-=(const Modint &a){
		val -= a.val;
		if(val < 0) val += MOD;
		return *this;
	}
	Modint &operator*=(const Modint &a){
		val = val * a.val % MOD;
		return *this;
	}
	void inverse(){
		long long x[2] = {MOD, val};
		long long a[2] = {0, 1};
		int i;
		for(i = 0; x[!i]; i ^= 1){
			a[i] -= x[i] / x[!i] * a[!i];
			x[i] = x[i] % x[!i];
		}
		if(!i) a[i] += MOD;
		val = a[i];
	}
	Modint &operator/=(Modint a){
		a.inverse();
		return *this *= a;
	}
	friend Modint modpow(Modint a, long long n){
		Modint ret(1);
		while(n){
			if(n & 1) ret *= a;
			a *= a;
			n >>= 1;
		}
		return ret;
	}
	friend Modint operator+(Modint a, const Modint &b){
		return a += b;
	}
	friend Modint operator-(Modint a, const Modint &b){
		return a -= b;
	}
	friend Modint operator*(Modint a, const Modint &b){
		return a *= b;
	}
	friend Modint operator/(Modint a, const Modint &b){
		return a /= b;
	}
	friend std::istream &operator>>(std::istream &is, Modint &a){
		return is >> a.val;
	}
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){
		return os << a.val;
	}
};

using Mint = Modint<1000000007>;
using Int = long long;

int main(){
	Int n, a, b;
	std::cin >> n >> a >> b;
	Mint x = modpow(Mint(2), n);
	Mint y(1), z(1);
	for(int i = 0; i < a; ++i) y *= Mint(n - i);
	for(int i = a; i > 0; --i) y /= Mint(i);
	for(int i = 0; i < b; ++i) z *= Mint(n - i);
	for(int i = b; i > 0; --i) z /= Mint(i);
	std::cout << x - y - z - 1 << std::endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	int a, b;
	scanf("%d %d", &a, &b);
	int ribuan, ratusan, puluhan, satuan;
	int sum = 0;
	for(int i = 1; i <= n; i++){
		int jumlah = 0;
		if(i > 9999){
			sum += i;
		}else if(i > 999){
			ribuan = i / 1000;
			ratusan = (i / 100) - (ribuan * 10);
			puluhan = (i / 10) - ((i / 100) * 10);
			satuan = i % 10;
			jumlah = ribuan + ratusan + puluhan + satuan;
			if(jumlah >= a && jumlah <= b){
				sum += i;
			}
		}else if(i > 99){
			ratusan = i / 100;
			puluhan = (i / 10) - (ratusan * 10);
			satuan = i % 10;
			jumlah = ratusan + puluhan + satuan;
			if(jumlah >= a && jumlah <= b){
				sum += i;
			}
		}
		else if(i > 9){
			puluhan = i / 10;
			satuan = i % 10;
			jumlah = puluhan + satuan;
			if(jumlah >= a && jumlah <= b){
				sum += i;
			}
		}
		else{
			if(i >= a && i <= b){
				sum += i;
			}
		}
//		printf("saat %d sum = %d\n", i, sum);
		if(jumlah != 0){
//			printf("jumlah setelah ditambah oleh %d = %d\n", i, jumlah);
		}
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, k;
    cin >> n >> k;
    
    int ans = 1;
    rep(i, n) {
        ans = min(2*ans, ans+k);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,H,W,a[10001],grid[100][100],n;
  cin >> H >> W;
  cin >> N;
  REP(i,N)cin >> a[i];
  n = 0;
  for(int j=0;j<H;j++){
    if(j % 2 == 0){
      for(int i=0;i<W;i++){
        if(a[n] == 0){
          n++;
        }
        grid[j][i] = n+1;
        a[n]--;
    }
    }else{
      for(int i=W-1;i>=0;i--){
        if(a[n] == 0){
          n++;
        }
        grid[j][i] = n+1;
        a[n]--;
      }
    }
  }
  REP(i,H){
    REP(j,W)
      cout << grid[i][j] << " ";
    cout << endl;
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n[4];
  cin>>n[0]>>n[1]>>n[2]>>n[3];
  bool f[20] = {false};
  rep(i,4) {
    f[n[i]] = true;
  }
  if(f[1] && f[9] && f[7] && f[4]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(z, 1, (n))
#define pb push_back
#define INF 1000000000
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAXN = 2100;
const ll MOD = 1e9+7;

int n, m;
int s[MAXN], t[MAXN];
ll dp[MAXN][MAXN];

int main()
{
    FAST_IO;

    cin >> n >> m;
    FOR(i, 1, n) cin >> s[i];
    FOR(i, 1, m) cin >> t[i];

    FOR(i, 1, n) FOR(j, 1, m) {
        if (s[i]==t[j])
            dp[i][j] = dp[i][j-1]+dp[i-1][j]+1;
        else dp[i][j] = MOD+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
        dp[i][j] %= MOD;
    }

    cout << ((dp[n][m]+1)%MOD) << endl;

    return 0;
}


Measured memory_bytes: 33152
H, W = map(int,input().split())
N = int(input())
al = list(map(int,input().split()))

ans = []
num = 1
for i in range(N):
    for _ in range(al[i]):
        ans.append(i+1)
#print(*ans)

left = 0

for i in range(H):
    if i % 2 == 0:
        row = ans[left:left+W]
    else:
        row = ans[left:left+W][::-1]
    print(*row)
    left += W



Measured memory_bytes: 3956
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007ll
#define rep(i,L,R) for(ll i=L;i<R;i++)
#define f(n) rep(i,0,n)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
#define sq(X) ((X)*(X))
#define PI 3.141592653589
const ll INF = 1e18l+10,N = 2e5+10,MAX = 5000000;

int main()
{
    int s,w;
    cin>>s>>w;
    if(s<=w) cout<<"unsafe\n";
    else cout<<"safe\n";
}

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

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

int main(){
    int H,W,N;
    cin >> H >> W >> N;
    vector<int> A(H * W);
    int k=0;
    int a;
    rep(i,N){
        cin >> a;
        rep(j,a){
            A[k] = i+1;
            k++;
        }
    } 
    int C[H][W] = {};
    k=0;
    bool flag = true;
    for(int i=0;i<H;i++){
        for(int j=(flag?0:W-1);0<=j && j<W;){
            C[i][j] = A[k];
            k++;
            if(flag) j++;
            else j--;
        }
        flag ^= 1;
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << C[i][j] << " ";
        }
            cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		if(a <= 9 && b <= 9) {
			System.out.println(a * b);
		}else {
			System.out.println(-1);
		}
	}
}

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

#define N 36

typedef struct {

	char mark;
	int num;
} Card;

void BubbleSort(Card A[],int n){
	
		Card t;
	for(int i=0;i<n;i++){
		for(int j=n-1;j>=i+1;j--){
			if(A[j].num < A[j-1].num){
					t = A[j]; A[j] = A[j-1]; A[j-1] = t;
			}
		}
	}
	
}

void SelectionSort(Card A[],int n){
	int mini;
	Card t;
	for(int i=0;i<n;i++){
		mini = i;
		for(int j=i;j<n;j++){
			if ( A[j].num < A[mini].num ){ mini = j;}
    	}
		if(i != mini){t = A[i]; A[i] = A[mini]; A[mini] = t;}
	
	
	}
}

void print(Card A[], int n){
  
  		for (int i = 0; i < n-1; i++ ){
  			
    			printf("%c%d ", A[i].mark, A[i].num);
  			

  }
	
	printf("%c%d\n", A[n-1].mark, A[n-1].num);
}

int isStable(Card A[],Card B[],int n){
	
	for(int i=0;i<n;i++){
		
		if(A[i].mark != B[i].mark){	 return 0;}
	}
	
	
	return 1;
}
	
	
	int main(void){
	
	Card A[N],B[N];
	int n;
	
	
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		
		scanf(" %c %d",&A[i].mark,&A[i].num);
		
	}
	
		
	for(int i=0;i<n;i++){B[i] = A[i];}
	

	BubbleSort(A,n);
	SelectionSort(B,n);
	
		print(A,n);
		printf("Stable\n");
  print(B, n);
  if ( isStable(A, B, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }
	
	return 0;
}
	
	


Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define openfile freopen("input.txt", "r" ,stdin); freopen("output.txt", "w", stdout); 
#define FOR(n) for(int i(0);i<n;++i)
#define ASC(i,a,b) for(int i(a); i <=b; ++i)
#define DESC(i,a,b) for(int i(a);i>=b;i--)
#define WL(t) while(t--)
#define SZ(a) int((a).size())
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define BB begin()
#define EE end()
#define all(c) c.BB, c.EE
#define present(container, element) (container.find(element) != container.end())
// ^^for set,map etc
#define cpresent(container, element) (find(all(container), element) != container.end())
// for vector,array etc
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;
const float INF = numeric_limits<float>::infinity();
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
const LL big=998244353;

#ifdef _DEBUG
freopen(input.txt,"r",stdin);
freopen(output.txt,"w",stdout);
#endif

int nC2(int n){
	return (n * (n-1))/2;
}


int main(){
	int n,cnt=0;
	cin >> n;
	int arr[n];
	FOR(n){
		cin >> arr[i];
		if(arr[i]!=(i+1)) cnt++;
	}
	if(cnt<=2){
		cout << "YES";
	}
	else{
		cout << "NO";
	}
	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int A,B;
  cin >> A >> B;
  if (A >= B && A-B >= 2) {
    cout << A + A-1 << endl;
  }
  else if (B >= A && B-A >=2) {
    cout << B+B-1 << endl;
  }
  else if (A == B || A-B ==1 || B-A==1 ) {
    cout << A+B << endl;
  }
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

s = ns()

st = deque()
for i in range(len(s)):
    if s[i] == 'B':
        if len(st) >= 1:
            st.pop()
    else:
        st.append(s[i])

print(*list(st), sep="")

Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

template <typename T> void output(T, int);
template <typename T> T max(T, T);
int gcd(int a, int b);

int main() {
    // source
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    if (a + b >= c) {
        ans = b + c;
    }else{
        ans=b+a+b+1;
    }
    cout << ans << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T max(T a, T b) {

    if (a > b) {
        return a;
    } else {
        return b;
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k, o = 0, t = 1, m = 0;
  cin >> n >> k;
  string s;
  cin >> s;
  for(int i = 1; i < s.length(); i++) {
    if(s[i - 1] != s[i]) {
      o += t - 1;
      m++;
      t = 0;
    }
    t++;
  }
  o += t - 1;
  if(k * 2 >= m)
    cout << n - 1 << '\n';
  else
    cout << o + k * 2 << '\n';
}

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  for h in range(1,3501):
    for n in range(1,3501):
      a=4*h*n-N*n-N*h
      b=N*h*n
      if a<=0:
        continue
      w=b//a

      if b%a==0:
        return str(h)+' '+str(n)+' '+str(w)

# main()
print(main())


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i{}; i < N; ++i) {
    cin >> H[i];
  }
  sort(H.begin(), H.end(), greater<int>());
  long long ans{};
  for (int i{K}; i < N; ++i) {
    ans += H[i];
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
signed main(){
    int a;
    string s;
    cin>>a>>s;
    if(a<3200)cout<<"red"<<endl;
    else cout<<s<<endl;
  	cerr<<1<<endl;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 0){
    cout << "Even" << endl;  
  }
  if (a * b % 2 == 1){
    cout << "Odd" << endl;
  }
}

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

#define mp make_pair
#define f first
#define s second
void boost()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int n,n1;
string s,s1,ans;
int dp[3110][3110];

pair<int,int> fr[3110][3110];

int main(){
	boost();                           
	cin >> s >> s1;
	n = s.size();
	n1 = s1.size();
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n1; j++){
			if(s[i] == s1[j]){
				dp[i + 1][j + 1] = dp[i][j] + 1;
				fr[i + 1][j + 1] = mp(i,j);
			}
			else{                                                        
				if(dp[i][j + 1] <= dp[i + 1][j]){
					dp[i + 1][j + 1] = dp[i + 1][j];
					fr[i + 1][j + 1] = mp(i + 1,j);
			}
				else{
					dp[i + 1][j + 1] = dp[i][j + 1];
					fr[i + 1][j + 1] = mp(i,j + 1); 
				}
			}
		}
	}
	int i = n,j = n1;
	while (i > 0 && j > 0)
	{
		if (s[i - 1] == s1[j - 1])
		{
		 	ans = ans + s[i - 1];
		} 	
		int g = fr[i][j].f,g1 = fr[i][j].s;
		i = g,j = g1;
	}
	reverse(ans.begin(),ans.end());
	cout << ans;                 	
	return 0;
}

Measured memory_bytes: 112896
/*
 * author: calgagi
 *         Calvin Gagliano 
 */
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define ar array
#define f first
#define s second
#define dd long double

ll mpow(ll a) {
    return a*a*a*a*a;
}

int main() {
    ios_base::sync_with_stdio(false);  
    cin.tie(NULL);
    srand(chrono::steady_clock::now().time_since_epoch().count()); 
    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
    
    ll x;
    cin >> x;


    for (ll a = -1000; a <= 1000; a++) {
        for (ll b = -1000; b <= 1000; b++) {
            if (a*a*a*a*a - b*b*b*b*b == x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
 
#define cMOD 1000000007ULL
#define cINF ((1ull<<62)-1)
#define cINFINT ((1<<30)-1)

ll calcFactional( ll size, 
	vector<ll>& fac, vector<ll>& inv, vector<ll>& facInv, ll mod )
{
	for( ll i = 2; i < size; ++i )
	{
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * ( mod / i ) % mod; // 逆元計算
		facInv[i] = facInv[i - 1] * inv[i] % mod;
 	}
}

ll combinationValue( ll n, ll k, ll mod )
{
	vector<ll> fac( n + 1, 1 ), inv( n + 1, 1 ), facInv( n + 1, 1 );
	calcFactional( n + 1, fac, inv, facInv, mod );

	if( n < k  || n < 0 || k < 0) return 0;
	return fac[n] * ( facInv[k] * facInv[n - k] % mod ) % mod;
 }
 
int main()
{
	ll n,m,k;cin>>n>>m>>k;
	ll comb = 0;
	
	REP(i,n) comb = ( comb + (i * (n-i)%cMOD) * (m * m%cMOD) ) % cMOD;
	REP(i,m) comb = ( comb + (i * (m-i)%cMOD) * (n * n%cMOD) ) % cMOD;
	
	comb = comb * combinationValue( n * m - 2, k-2, cMOD ) % cMOD;

	cout << comb << endl;
	
	return 0;
}

Measured memory_bytes: 4992
n, T = map(int, input().split())
t = list(map(int, input().split()))
time = 0
sa = []
for i in range(n - 1):
    sa.append(t[i + 1] - t[i])
ans = 0
for i in range(len(sa)):
    if sa[i] <= T:
        ans += sa[i]
    else:
        ans += T
print(ans+T)


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

int n;
set<string> shiritori;

int main(){
    scanf("%d", &n);
    string s;
    char tmp[15];
    char last;
    bool ok = true;
    scanf("%s", tmp);
    s = tmp;
    shiritori.insert(s);
    last = s.back();
    for(int i = 1; i< n; i++){
        scanf("%s", tmp);
        s = tmp;
        if(s.front() != last || shiritori.count(s)){
            ok = false;
            break;
        }
        shiritori.insert(s);
        last = s.back();
    }
    if(ok) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = -float('inf')
for i in range(n):
    x = i
    tot = 0
    s = []
    while True:
        x = p[x] - 1
        tot += c[x]
        s.append(c[x])
        if x == i:
            break
    t = 0
    l = len(s)
    for i in range(l):
        t += s[i]
        if i+1 > k:
            break
        now = t
        if tot > 0:
            e = (k-i-1)//l
            now += tot*e
        ans = max(ans, now)
print(ans)


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

int main() {
    int r;
    double ans;
    cin >> r;
    ans = 2 * r * M_PI;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3748
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

class item {
public:
  i64 weight, value;
};

namespace std {
  std::istream& operator>>(std::istream& is, item& self) {
    return is >> self.weight >> self.value;
  }
}

int main() {
  i64 N, W;
  std::cin >> N >> W;
  std::vector<item> items;
  tools::read(items, N);

  constexpr i64 INF = std::numeric_limits<i64>::max();
  // dp[i] ... 価値iを達成できる最小の重さ
  std::vector<i64> dp(100001, INF);
  dp[0] = 0;
  for (const item& item : items) {
    for (i64 i = 100000; i >= 0; --i) {
      if (dp[i] != INF && i + item.value <= 100000 && dp[i] + item.weight <= W) {
        dp[i + item.value] = std::min(dp[i + item.value], dp[i] + item.weight);
      }
    }
  }

  std::cout << std::distance(dp.begin(), std::find_if(dp.rbegin(), dp.rend(), [&INF](const i64& dp_i) { return dp_i != INF; }).base()) - 1 << std::endl;
  return 0;
}

Measured memory_bytes: 1152
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

d = defaultdict(int)
n = inp()
a = inpl()
for i in a:
    d[i] += 1
for i in range(n):
    print(d[i+1])

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

int main() {
    int N, A, B;
    cin >> N;
    int sum;
    int min = INFINITY;
    for (int i = 1; i < N; i++) {
        sum = 0;
        A = i;
        while (A > 0) {
            sum += A % 10;
            A /= 10;
        }
        B = N - i;
        while (B > 0) {
            sum += B % 10;
            B /= 10;
        }
        if (sum < min) min = sum;
    }
    cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/extc++.h>
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(a, b) {for(int _i = a;_i > 0;--_i){b;}}
#define multe int _T;for(cin >> _T;_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
template<typename T> void read(int n, T s){while(n--)cin >> *s, ++s;}
template<typename T> void write(int n, T s){while(n--)cout << *s << " \n"[n==0], ++s;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 18;
const int p = 1e9+7;
int n, m;
int lo[maxn];
ll dp[1 << maxn];
ll fa[1 << maxn], inv[1 << maxn], fainv[1 << maxn];
inline void init(){
	inv[1] = fa[1] = fainv[1] = fa[0] = inv[0] = fainv[0] = 1;
	for(int i = 2;i < (1 << maxn);++i){
		fa[i] = fa[i-1] * i % p;
		inv[i] = (p-p/i) * inv[p % i] % p;
		fainv[i] = inv[i] * fainv[i-1] % p;
	}
}
ll per(int a, int b){
	return (a < b ? 0 : fa[a] * fainv[a - b]) % p;
}
int count_bit(int v){
	int res = 0;
	for(;v;v -= (v & -v))res ^= 1;
	return res;
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	init();
	cin >> n >> m;
	read(m, lo+1);
	sort(lo+1, lo+1+m, greater<int>());
	dp[0] = 1;
#define lowbit(i) ((i) & (-i))
	for(int i = 1;i <= m;++i){
		for(int s = 1<<n;s > 0;--s){
			for(int j = s;j;j -= lowbit(j)){
				dp[s] = (dp[s] + (dp[s ^ lowbit(j)] * per((1<<n)-lo[i]-s+lowbit(j), lowbit(j)-1) % p * lowbit(j))) % p;				
			}
		}
	}
	ll res = 0;
	for(int s = 1;s < (1 << n);++s){
		if(count_bit(s))res = (res + p - dp[s] * fa[(1<<n)-1-s]) % p;
		else res = (res + dp[s] * fa[(1<<n)-1-s]) % p;
	}
	cout << (fa[(1<<n)-1] + p + res) * (1 << n) % p;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std; 
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n, ans = INT_MAX;
    cin >> n;
    vector<int> arr(n), dp(n);
    for (auto &i: arr)
        cin >> i ;
    dp[1] = abs(arr[1]-arr[0]);
    for (int i=2; i<n; i++)
        dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    cout << dp.back() << "\n";
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,ans=2;//初始值包括n和n-1两种. 
	cin>>n;
	if(n==2) ans=1;//特判 
	for(ll k=2,i=n;k*k<=n;k++,i=n){ 
		while(i>=k) i%k?i%=k:i/=k;//这里是计算[2,sqrt[n]的情况. 
		if(i==1) ans++;
		if((n-1)%k==0&&k*k!=(n-1)) ans++;//这里是计算 [sqrt(n),n]n-1的因数情况，这里k*k!=(n-1)是去重 
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
int main()
{
    int W, a, b;
    std::cin >> W >> a >> b;
    std::cout << (((a<=b && b<=a+W) || (a<=b+W && b+W<=a+W)) ? 0 : std::min(std::abs(a-(b+W)), std::abs((a+W)-b))) << std::endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

#include <iostream>
#include <functional>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>

using namespace std;

int main(int argc, char** argv) {
  int n;
  string s;
  cin >> n >> s;

  int count = 0;
  for (int i = 0; i < s.size() - 2; ++i) {
	if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      ++count;
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

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

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    h, w = get_int_multi()

    d = [[-1] * (w+2) for _ in range(h+2)]

    shiro = 0
    for i in range(h):
        wk = get_string()
        for ii in range(w):
            if wk[ii] == ".":
                d[i+1][ii+1] = 10**9
                shiro += 1


    d[1][1] = 1
    q = deque([])
    q.append([1,1])

    flg = False
    while q:
        wk = q.popleft()
        i = wk[0]
        ii = wk[1]
        hosuu = d[i][ii]

        if i == h and ii == w:
            flg = True
            print(shiro-hosuu)
            break

        def add_que(i,ii,hosuu):
            if d[i][ii] == 10**9:
                d[i][ii] = hosuu + 1
                q.append([i,ii])

        add_que(i-1,ii, hosuu)
        add_que(i+1,ii, hosuu)
        add_que(i,ii-1, hosuu)
        add_que(i,ii+1, hosuu)

    if not flg:
        print(-1)



if __name__ == '__main__':
    main()




Measured memory_bytes: 11024
import scala.collection.mutable.{Set => MSet, ArrayBuffer}
import scala.io.StdIn._

object Main extends App {
  val n = readInt
  val players = ArrayBuffer.fill(n)(readLine.split(" ").map(_.toInt - 1).toList)
  val validPlayers = MSet((0 until n): _*)

  @scala.annotation.tailrec
  def playDay(days: Int, toCheck: MSet[Int]): Int = {
    val nextCheck = MSet[Int]()
    var noPlay = true
    val played = new Array[Boolean](n)
    toCheck.foreach { p =>
      if (players(p).nonEmpty) {
        val oppo = players(p).head
        def play(i: Int): Unit = {
          players(i) = players(i).tail
          played(i) = true
          nextCheck += i
          if (players(i).isEmpty) validPlayers -= i
        }
        if (players(oppo).head == p && !played(p) && !played(oppo)) {
          play(p)
          play(oppo)
          noPlay = false
        }
      }
    }
    if (noPlay) {
      if (players.exists(_.nonEmpty)) -1 else days
    } else playDay(days + 1, nextCheck)
  }

  println(playDay(0, MSet((0 until n): _*)))
}

Measured memory_bytes: 148892
#include<cstdio>
#include<algorithm>
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define per(i,x,y) for(int i=(x);i>=(y);--i)
typedef long long LL;
const int N=1e5+10;
int n;
LL a[N],s[N];
int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%lld",&a[i]);
	std::sort(a+1,a+1+n);
	rep(i,1,n)s[i]=s[i-1]+a[i];
	per(i,n-1,1){
		if(s[i]*2<a[i+1]){
			printf("%d",n-i);
			return 0;
		}
	}
	printf("%d",n);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vector<long long> h(n);
    for(ll i=0; i<n; i++) cin >> h[i];
    vector<long long> dp(n, INFLL);
    dp[0] = 0;
    for(ll i=0; i<n-1; i++){
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
        if(i < n-1) dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792