akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

int a[110];
int b[110];
int dp[110][110];
/*
dp[i][j]:行列i~jまでの乗算回数の最小値
dp[i][j]=min(dp[i-1][j]+(a[i-1]*b[i-1]*[b[j]])), dp[i][j+1]+(a[i]*a[j+1]*b[j+1]))
*/

void solve(){

    int n;
    cin >> n;
    rep(i,n){
      cin >> a[i] >> b[i];
    }
    rep(i,110){
      rep(j,110){
          dp[i][j]=0;
      }
    }
    
    for(int i=1; i<n; i++){
        dp[i-1][i]=a[i-1]*b[i-1]*b[i];
    }
    

    for(int i=2; i<n; i++){
        for(int j=0; j<n-i; j++){
            int ans = INF;
            int x = j;
            int y = i+j;
            for(int k=0; k<y-x; k++){
                ans = min(int(ans), int(dp[x][x+k]+dp[x+k+1][y]+a[x]*b[x+k]*b[y]));
            }
            dp[j][i+j]=ans;
        }
    }

    /*
    rep(i,n){
        rep(j,n){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */

    cout << dp[0][n-1] << endl;

}


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



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

int main() {
  int N, M;
  cin >> N >> M;
  int b = 0;
  vector<vector<int>> a(M, vector<int>(2));
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < 2; j++) {
      cin >> a.at(i).at(j);
    }
  }
  for(int k = 1; k <= N; k++) {
    b = 0;
    for(int i = 0; i < M; i++) {
      for(int j = 0; j < 2; j++) {
        if(a.at(i).at(j) == k) {
          b++;
        }
      }
    }
    cout << b << endl;
  }
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    if(0 in A):
        print(0)
        sys.exit()

    sum_l = 1
    for x in A:
        sum_l *= x
        if(sum_l > 10 **18):
            print(-1)
            sys.exit()

    print(sum_l)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main(){
    int n;
    cin >>n;
    int a;
    for(int i=0;i<n;i++){
        cin >> a;
        if(a%2==0){
            if(a%3!=0 && a%5!=0){
                cout << "DENIED"<<endl;
                return 0;
            }
        }
    }
    cout << "APPROVED"<<endl;
    return 0;
}

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

int main() {
  int a, b, c, x, res = 0, i, j, k;
  cin >> a >> b >> c >> x;
  for(i=0;i<=a;i++) for(j=0;j<=b;j++) for(k=0;k<=c;k++) if(500*i+100*j+50*k == x) res++;
  cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())

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

int main() {
	int x;cin>>x;
	cout<<360/__gcd(360,x);
	return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int N,Q;

void solve() {
    cin>>N;
    int a,b,c;
    map<int,int> M;
    int ans = 0;
    REP(i,N) {
        cin>>a;
        M[a]++;
        ans += a;
    }
    cin>>Q;
    while(Q--) {
        cin>>b>>c;
        ans -= b * M[b];
        ans += c * M[b];
        M[c]+=M[b];
        M[b]=0;
        cout << ans << endl;
    }
}



Measured memory_bytes: 9504
#include<bits/stdc++.h>
int a[5][5];
int main(){
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            scanf("%d",&a[i][j]);
        }
    }
    int n;
    scanf("%d",&n);
    int b;
    int vis[5][5];
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            vis[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b);
        for(int j=1;j<=3;j++){
            for(int k=1;k<=3;k++){
                if(a[j][k]==b){
                    vis[j][k]=1;
                }
            }
        }
    }
/*    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            printf("%d ",vis[i][j]);
        }
        printf("\n");
    }
*/    int can=1;
    for(int i=1;i<=3;i++){
        can=1;
        for(int j=1;j<=3;j++){
            if(!vis[i][j]){
                can=0;
            }
        }
        if(can==1){
            printf("Yes");
            return 0;
        }
    }
    for(int i=1;i<=3;i++){
        can=1;
        for(int j=1;j<=3;j++){
            if(!vis[j][i]){
                can=0;
            }
        }
        if(can==1){
            printf("Yes");
            return 0;
        }
    }
    if(vis[1][1]==1&&vis[2][2]==1&&vis[3][3]==1){
        printf("Yes");
        return 0;
    }
    if(vis[1][3]==1&&vis[2][2]==1&&vis[3][1]==1){
        printf("Yes");
        return 0;
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int ans;
int map[100][100];
void dfs(int x,int y,int w,int h);
int dx[8] = {1,1,0,-1,-1,-1,0,1},dy[8] = {0,1,1,1,0,-1,-1,-1};

int main(){
  int w,h;
  while(cin>>w>>h){
    ans=0;
    if(w == 0 && h == 0)break;
    for(int i = 0;i<h;i++)
      for(int j = 0;j<w;j++)
	cin>>map[i][j];
    for(int i = 0;i<h;i++)
      for(int j = 0;j<w;j++){
	if(map[i][j] == 1){
	  map[i][j] = 0;
	  ans++;
	  dfs(j,i,w,h);
	}
      }
    // cout<<"map"<<endl;
    // for(int a=0;a<h;a++){
    //   for(int b=0;b<w;b++) cout<<map[a][b];
    //   cout<<endl;
    // }
    //cout<<endl;
    cout<<ans<<endl;
  }
  return 0;
}

void dfs(int x,int y,int w,int h){
  //cout<<"LK+LKJ"<<endl;
  int nx,ny;
  for(int i = 0;i<8;i++){
    nx = x+dx[i]; ny = y+dy[i];
    if(nx>=0 && nx<w && ny>=0 && ny<h && map[ny][nx] == 1){
      map[ny][nx] = 0;
      dfs(nx,ny,w,h);
    }
  }
}

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

int main()
{
    int m, d;
    cin >> m >> d;
    int result = 0;
    for (int i = 4; i <= m; i++)
    {
        for (int j = 22; j <= d; j++)
        {
            if (j / 10 >= 2 && j % 10 >= 2
            && (j / 10) * (j % 10) == i)
            {
                result++;
            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
import sys

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = sys.stdin.readline()

v_hand = {'r': P, 's': R, 'p': S}

ans = 0

wins = [False] * K

for i in range(N):
    if not wins[i % K] or T[i] != T[i - K]:
        ans += v_hand[T[i]]
        wins[i % K] = True
    else:
        wins[i % K] = False
        
print(ans)

Measured memory_bytes: 3956
import sys
input = sys.stdin.readline

n,m=map(int,input().split())
ans=0
s=[[0,0] for _ in range(n)]
for i in range(n):
        s[i][0],s[i][1]=map(int,input().split())
s.sort()
for i in range(n):
        if m>=s[i][1]:
                ans+=s[i][0]*s[i][1]
                m-=s[i][1]
        else:
                ans+=s[i][0]*m
                break


print(ans)

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

int main(){
    string s;
    cin >> s;
    string ans="No";
    for(int i=0; i<s.size(); i++){
        if(s[i]=='7'){
            ans ="Yes";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>   
using namespace std;
#define N 50   
#define REP(i, n) for(int i=0; i<n; i++)
long n;
long ans=1;
int main(void){
    cin>>n;
    for(long i=1;i<=n;i++){
        ans=(ans*i)%(int(pow(10,9))+7);    
    }
    printf("%ld",ans);
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1000005;
int n,nn,m;
int cnt[3],ord[3];
char s[maxn],ns[maxn];
vector<pii>val[5];
bool del[maxn],mark[maxn];
bool cmp(int a,int b){
	return cnt[a]<cnt[b];
}

int main(){
	scanf("%s",s);n=strlen(s);
	rep(i,n)if(!nn||s[i]!=ns[nn-1])ns[nn++]=s[i];
	n=nn;
	rep(i,n){
		s[i]=ns[i];
		cnt[s[i]-'A']++;
	}
	rep(i,3)ord[i]=i;
	sort(ord,ord+3,cmp);
	int last=-1;
	rep(i,n+1)if(i==n||s[i]-'A'==ord[0]){
		if(last+1<=i-1){
			if(last+1==i-1){
				if(s[i-1]-'A'==ord[1])val[3].pb(mp(last+1,i-1));
				else{
					if(last+1==0||i-1==n-1)val[1].pb(mp(last+1,i-1));
					else val[4].pb(mp(last+1,i-1));
				}
			}
			else{
				if(s[last+1]-'A'==ord[1]&&s[i-1]-'A'==ord[1]){
					if(last+1==0||i-1==n-1)mark[int(val[0].size())]=true;
					val[0].pb(mp(last+1,i-1));
				}
				else if(s[last+1]-'A'==ord[2]&&s[i-1]-'A'==ord[2])val[2].pb(mp(last+1,i-1));
				else val[1].pb(mp(last+1,i-1));
			}
		}
		last=i;
	}
	int tot=2*int(val[2].size())+int(val[1].size());
	int tar=cnt[ord[2]]-cnt[ord[1]];
	if(tot<tar){
		assert(int(val[4].size())>=tar-tot);
		rep(i,tar-tot){
			del[val[4][i].fst]=del[val[4][i].fst+1]=true;
			cnt[ord[0]]--;
			cnt[ord[2]]--;
		}
		tar=tot;
	}
	rep(i,int(val[2].size())){
		int l=val[2][i].fst,r=val[2][i].snd;
		if(tar>=2){
			del[l]=del[r]=true;
			cnt[ord[2]]-=2;
			tar-=2;
			if(l+1<=r-1){
				if(l==0||r==n-1)mark[int(val[0].size())]=true;
				val[0].pb(mp(l+1,r-1));
			}
		}
		else if(tar==1){
			del[l]=true;
			cnt[ord[2]]--;
			tar--;
			if(l+1<=r){
				if(l==0||r==n-1)mark[int(val[0].size())]=true;
				val[0].pb(mp(l+1,r));
			}
		}
		else{
			if(l==0||r==n-1)mark[int(val[0].size())]=true;
			val[0].pb(mp(l,r)); 
		}
	}
	rep(i,int(val[1].size())){
		int l=val[1][i].fst,r=val[1][i].snd;
		if(tar){
			if(s[l]-'A'==ord[2]){
				del[l]=true;
				if(l+1<=r){
					if(l==0||r==n-1)mark[int(val[0].size())]=true;
					val[0].pb(mp(l+1,r));
				}
			}
			else{
				del[r]=true;
				if(l<=r-1){
					if(l==0||r==n-1)mark[int(val[0].size())]=true;
					val[0].pb(mp(l,r-1));
				} 
			}
			cnt[ord[2]]--;
			tar--;
		}
		else{
			if(l==0||r==n-1)mark[int(val[0].size())]=true;
			val[0].pb(mp(l,r)); 
		}
	}
	assert(!tar);
	tar=cnt[ord[1]]-cnt[ord[0]];
	rep(i,int(val[0].size())){
		int l=val[0][i].fst,r=val[0][i].snd;
		int now=min((r-l+mark[i])/2,tar);
		rep(i,now){
			del[l+2*i]=del[l+2*i+1]=true;
			cnt[ord[1]]--;
			cnt[ord[2]]--;
			tar--;
		}
	}
	assert(!tar);
	assert(cnt[ord[0]]==cnt[ord[1]]&&cnt[ord[1]]==cnt[ord[2]]);
	rep(i,n)if(!del[i])putchar(s[i]);
	puts("");
	return 0; 
}

Measured memory_bytes: 12012
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    while (a >= MOD)
        a -= MOD;
    while (a < 0)
        a += MOD;
}

int main() {
    string k; cin >> k;
    int n = k.size();
    int d; cin >> d;

    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>> (d, vector<int> (2, 0)));

    dp[0][0][1] = 1;

    for (int i = 0; i < n; i += 1)
        for (int rem = 0; rem < d; rem += 1) 
            for (int equal = 0; equal < 2; equal += 1) {
                for (int digit = 0; digit < 10; digit += 1) {
                    if (equal and digit > k[i] - '0') 
                        continue;
                    int new_rem = (rem + digit) % d;
                    add(dp[i + 1][new_rem][equal && (digit + '0' == k[i])], dp[i][rem][equal]);
                }
            }

    int ans = (dp[n][0][0] + dp[n][0][1]) % MOD;
    add(ans, -1);
    cout << ans << "\n";
}

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

int main()
{

  int i,j,minj,n,flag=1,cmp,hantei=0;
  char b[36][3],s[36][3],sw[36][3];
  

  /*??\???*/
  scanf("%d",&n);

  for(i=0;i<n;i++){

    scanf("%s",b[i]);

    strcpy(s[i],b[i]);
    
      }
  
  i=0;
  while(flag){
    flag = 0;
for (j = n - 1; j >= i+1; j--) {
      if (b[j - 1][1] > b[j][1]) { 
	strcpy(sw[j],b[j]);        
	strcpy(	b[j],b[j - 1]);
	strcpy(	b[j - 1],sw[j]);
	flag = 1;
      }
 }
    i++;
  }
  

  for(i=0;i<n;i++){

    minj = i;

    for(j=i;j<n;j++){
      if(s[j][1] < s[minj][1]){
	minj = j;
      }
    }
    if(i != minj){
   
    strcpy(sw[i] ,s[i]);
    strcpy(s[i],s[minj]);
    strcpy(s[minj],sw[i]);
    }
  }

  /*BS??????*/
  for(i=0;i<n-1;i++){

    printf("%s ",b[i]);
  }
    printf("%s",b[i]);
  

  printf("\n");
  printf("Stable\n");
  /*SS??????*/
  for(j=0;j<n-1;j++){

    printf("%s ",s[j]);

  }
  printf("%s",s[j]);
  printf("\n");
  flag = 1;
  for(i=0;i<n;i++){


    if(strcmp(&b[i][0],&s[i][0])!=0 && hantei==0){
      printf("Not stable\n");
      flag=0;
      hantei++;
    }
  }
  if(flag==1){
    printf("Stable\n");
  }
 return 0;
}

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

bool check(int M, int* k, bool* St, int* p, vector<vector<int>> s){
    int i, j, flg;
    for(i=0; i<M; i++){
        flg = 0;
        for(j=0; j<k[i]; j++){
            flg += St[s[i][j]];
        }
        if(flg%2!=p[i])return false;
    }
    return true;
}

void func(int n, int N, bool* St, int* count, int M, int* k, int* p, vector<vector<int>> s){
    if(n==N){
        if(check(M, k, St, p, s))*count += 1;
        return;
    }
    St[n] = false;
    func(n+1, N, St, count, M, k, p, s);
    St[n] = true;
    func(n+1, N, St, count, M, k, p, s);
}

int main()
{   
    int i, j, N, M, tmp;
    cin >> N >> M;
    int k[N];
    int p[M];
    vector<vector<int>>s(M);
    for(i=0; i<M; i++){
        cin >> k[i];
        for(j=0; j<k[i]; j++){
            cin >> tmp;
            s[i].push_back(tmp-1);
        }
    }
    for(i=0; i<M; i++){
        cin >> p[i];
    }
    //--全探索
    bool St[N];
    int count = 0;
    func(0, N, St, &count, M, k, p, s);
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse4,sse4.2,popcnt,abm,mmx,avx")
#endif
#include <bits/stdc++.h>
 
using namespace std;
 
#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;
 
template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}
 
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}
 
vector<int> a, b, res;
 
int n;
const int N = 2e5 + 5;
int cnt_a[N], cnt_b[N];
 
const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
 
bool validate() {
  bool valid = true;
  for (int i = 0; i < n; ++i) {
    valid &= (a[i] != res[i]);
  }
  return valid;
}
 
bool solve() {
  res = b;
  for (int t = 0; t < 20; ++t) {
    rotate(begin(res), begin(res) + rng() % n, end(res));
    if (validate()) return true;
  }
  res = b;
  reverse(all(res));
  for (int t = 0; t < 20; ++t) {
    if (validate()) return true;
    shuffle(all(res), rng);
  }
  return false;
}
 
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif
  cin >> n;
  a.resize(n), b.resize(n), res.resize(n);
  cin >> a >> b;
  for (int x : b) ++cnt_b[x];
  for (int x : a) {
    ++cnt_a[x];
    if (cnt_b[x] + cnt_a[x] > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (solve()) {
    cout << "Yes" << endl;
    cout << res << endl;
    return 0;
  }
 
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 7224
// ALDS_1_3_A Stack

#include <iostream>
#include <stack>
#include <string>

bool is_operator(char symbol){
	switch(symbol){
		case '+':
		case '-':
		case '*': return true;
		default : return false;
	}
}

int operation(int x, int y, char ope){
	switch(ope){
		case '+': return x + y;
		case '-': return x - y;
		case '*': return x * y;
		default : return 0;
	}
}


int main(int argc, char *argv[]){
	std::stack<int> operand;
	std::string symbol;

	while(std::cin >> symbol){
		if(is_operator(symbol[0])){
			int y = operand.top();
			operand.pop();
			int x = operand.top();
			operand.pop();
			int ans = operation(x, y, symbol[0]);
			operand.push(ans);
		}
		else{
			operand.push(stoi(symbol)); // C++11
		}
	}

	std::cout << operand.top() << std::endl;

	return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto &&V : v)
#define all(x) (x).begin(), (x).end()
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
using lint = long long;

using namespace std;

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

  int n, q;
  cin >> n >> q;
  struct con {
    int s, t, x;
  };
  vector<con> cons(n);
  rep(i, n) {
    int s, t, x;
    cin >> cons[i].s >> cons[i].t >> cons[i].x;
  }
  map<int, int> pe;
  rep(i, q) {
    int d;
    cin >> d;
    pe[d] = i;
  }
  vector<int> ans(q);
  sort(all(cons), [&](con a, con b) { return a.x < b.x; });
  rep(i, n) {
    int l = cons[i].s - cons[i].x;
    int r = cons[i].t - cons[i].x;
    auto litr = pe.lower_bound(l);
    auto ritr = pe.lower_bound(r);
    for (auto itr = litr; itr != ritr; ++itr) {
      ans[itr->second] = cons[i].x;
    }
    pe.erase(litr, ritr);
  }
  allrep(p, pe) {
    ans[p.second] = -1;
  }
  allrep(a, ans) cout << a << "\n";
  return 0;
}

Measured memory_bytes: 14464
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
int n,x;
int main(){
    cin>>n>>x;
    if(x==1 || x==2*n-1) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        for(int i=x-n+1;i<=x+n-1;i++){
           int cnt=i;
           if(cnt>(2*n-1)) cnt-=2*n-1;
           else if(cnt<=0) cnt+=2*n-1;
            cout<<cnt<<endl;
        }
    }
}

Measured memory_bytes: 1536
#include <stdio.h>

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

    int x,y,e=0,count=0;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0){
            break;
        }
        for(int n=1;n<=x;n++){
            for(int q=n+1;q<=x;q++){
                for(int a=q+1;a<=x;a++){

                    if(a!=q&&a!=n&&n!=q){
                        e=a+q+n;
                    }
                    if(e==y){
                        count++;
                    }
                }
            }

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



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

vector<ll> primes(100020), w(100020);
vector<ll> v;

int main() {
  
  ll count = 0;
  ll j;
  
  for ( ll i = 2; i < 100020; i++ ){
    
    bool ok = true;
    for ( j = 0; primes[j] * primes[j] <= i && j < count; j++) {
      if ( i % primes[j] == 0 ){
        ok = false;
        break;
      }
    }
    
    if ( !ok ) continue;
    primes[count++] = i;
  }
  
  for ( ll i = 1; i < count; i++ ){
    if ( find(primes.begin(), primes.end(), (primes[i] + 1) / 2) != primes.end() )
      v.push_back(primes[i]);
  }
  
  ll pos = 0;
  for ( ll i = 1; i < 100001; i++ ){
    w[i] = w[i-1];
    if ( i == v[pos] ) {
      pos++;
      w[i]++;
    }
  }
  
  ll q;
  cin >> q;
  ll l, r;
  for ( ll i = 0; i < q; i++ ){
    cin >> l >> r;
    cout << w[r] - w[l-1] << endl;
  }
  
}


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

using namespace std;
const int INF=1<<27;

int n,m,R;
int f[205][205];
int r[15];

int main()
{
	cin >> n >> m >> R;
	for(int i=1;i<=R;i++) cin >> r[i];
	
	for(int i=1;i<=200;i++)
		for(int j=1;j<=200;j++)
			f[i][j]=INF;
	
	for(int i=1;i<=m;i++)
	{
		int x,y,z;cin >> x >> y >> z;
		f[x][y]=f[y][x]=z;
	}
	
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(f[i][k]+f[k][j]<f[i][j]) f[i][j]=f[i][k]+f[k][j];
				
	int np[10],ans=INF;
	for(int i=1;i<=R;i++) np[i]=i;
	
	do
	{
		int sum=0;
		for(int i=1;i<=R-1;i++) sum+=f[r[np[i]]][r[np[i+1]]];
		ans=min(ans,sum);
	}
	while(next_permutation(np+1,np+R+1));
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll H, W, ans = 1000000000;
	ll size[3];

	cin >> H >> W;

	if (H % 3 == 0 || W % 3 == 0) ans = 0;
	if (H >= 3) ans = min(ans, W);
	if (W >= 3) ans = min(ans, H);

	repc(i, 1, H - 1) {
		int h = H - i;
		int w = W;

		size[0] = W * i;
		size[1] = h * (W / 2);
		size[2] = h * W - size[1];

		sort(size, size + 3);
		ans = min(ans, size[2] - size[0]);
	}

	repc(i, 1, W - 1) {
		int w = W - i;
		int h = H;

		size[0] = H * i;
		size[1] = w * (H / 2);
		size[2] = w * H - size[1];

		sort(size, size + 3);
		ans = min(ans, size[2] - size[0]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    S = gete()

    p = []
    nl, ng = 0, 0  # <, >

    for i, c in enumerate(S):
        if c == "<":
            nl += 1
        else:
            ng += 1

        if c == "<" and i < len(S) - 1 and S[i + 1] == ">":
            p.append((ng, nl))
            nl, ng = 0, 0

    p.append((ng, nl))

    ans = 0
    for i, q in enumerate(p):

        if i == 0 or p[i - 1][1] < q[0]:
            ans += q[0] * (q[0] + 1) // 2
        else:
            ans += q[0] * (q[0] - 1) // 2

        if i == len(p) - 1 or q[1] >= p[i + 1][0]:
            ans += q[1] * (q[1] + 1) // 2
        else:
            ans += q[1] * (q[1] - 1) // 2


    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 51540
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int R, G, B, N;
  int rbox, gbox, bbox;
  int ans = 0;
  cin >> R >> G >> B >> N;
  for(int i = 0; i < N+1; i++){
  	rbox = i * R;
  	if(rbox > N){
  		break;
  	}else{
  		for(int j = 0; j < N+1 - rbox; j++){
  			gbox = j * G;
  			bbox = N - (rbox + gbox);
  			if(bbox < 0){
  				break;
  			}else{
  				if(bbox % B == 0){
  					ans += 1;
  				}
  			}
  		}
    }
  }

  cout << ans << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int> x;
    int p = 0;
    while (p < n) {
        if (s[p] == t[p]) {
            x.eb(1);
            ++p;
        } else {
            x.eb(2);
            p += 2;
        }
    }
    int sz = x.size();
    ll ans = (x[0] == 1 ? 3 : 6);
    forn(i, 1, sz) {
        if (x[i] == 1) {
            if (x[i - 1] == 1) ans *= 2;
        } else {
            if (x[i - 1] == 1) ans *= 2;
            else ans *= 3;
        }
        ans %= MOD;
    }
    cout << ans << '\n';
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,t;
    cin>>n>>t;
    int arr[n];
    for (int i=0;i<n;i++)cin>>arr[i];
    int p=0;
    int ans=0;
    for (int i=1;i<n;i++){
        if (arr[i]<=arr[i-1]+t){
            continue;
        }else{
            ans+=arr[i-1]-arr[p]+t;
            p=i;
        }
    }ans+=arr[n-1]-arr[p]+t;
    cout<<ans<<endl;
    return 0;
}

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


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

    int S;
    cin >> S;
    vector<long long> dp(S + 1);
    dp[0] = 1;
    for (int from = 0; from <= S - 3; ++from) {
        for (int to = from + 3; to <= S; ++to) {
            dp[to] += dp[from];
            dp[to] %= 1000000007;
        }
    }

    cout << dp[S] << endl;

    return 0;
}


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

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

    for (int i = 1; i <= n; i++) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
        } else {
            while (x > 0) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3124
/// 標準入力マクロ
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        a: i32,
        b: i32,
    }

    let mut ret = 0;
    for i in 1..n + 1 {
        let d = find_sum_of_digits(i);
        //println!("i = {} -> d = {}", i, d);
        if a <= d && d <= b {
            ret = i + ret;
        }
    }

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

fn find_sum_of_digits(n: i32) -> i32 {
    let mut sum = 0;
    let mut n = n;
    while n > 0 {
        // n が 0 になるまで
        sum += n % 10;
        n /= 10;
    }
    sum
}


Measured memory_bytes: 2124
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (a - c) * (b - d) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef unsigned long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const ll base[] = {29, (ll)1e9 + 7};
ll h[2][300001], pw[2][300001];
int n, m;
char in[300001];

int main(){
	scanf("%d%d%s", &n, &m, in);
	rep(k, 2){
		pw[k][0] = 1;
		rep(i, n){
			pw[k][i + 1] = pw[k][i] * base[k];
			h[k][i + 1] = h[k][i] + pw[k][i] * (in[i] - 'a' + 1);
		}
	}
	set<pi> s;
	int l = 0, r = 1;
	rep(i, m){
		char a[4];
		scanf("%s", a);
		if(a[0] == 'L' && a[1] == '+') l++;
		else if(a[0] == 'L' && a[1] == '-') l--;
		else if(a[0] == 'R' && a[1] == '+') r++;
		else r--;
		
		ll ha[2];
		rep(j, 2) ha[j] = (h[j][r] - h[j][l]) * pw[j][n - r];
		s.insert(mp(ha[0], ha[1]));
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 29620
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
#define repr2(i, s, n) for(int i = n-1; i >= s; i--)
using namespace std;

int main(){
  while(1){
    int h;
    cin >> h;
    if(h == 0) break;
    vector<vector<int>> board(h, vector<int>(5));
    rep(i, h)rep(j, 5) cin >> board[i][j];
    int score = 0;
    bool flag;
    while(1){
      flag = true;
      // 消滅させる
      rep(i, h){
        int count;
        int prev = -1;
        int now;
        rep(j, 5){
          now = board[i][j];
          if (now == 0) count = 0;
          else if (now != prev) count = 1;
          else count++;
          if (count == 3){
            flag = false; // 一回でも消滅したらもう一度判定する
            score += now * 3;
            board[i][j] = board[i][j-1] = board[i][j-2] = 0;
          }
          else if (count > 3){
            score += now;
            board[i][j] = 0;
          }
          prev = now;
        }
      }
      // 消滅しなかったら終わり
      if (flag) break;
      
      // 消滅した分、下に下げる
      rep(k, h-1)repr2(i, k+1, h)rep(j, 5){
        if (board[i][j] == 0){
          board[i][j] = board[i-1][j];
          board[i-1][j] = 0;
        }
      }
    }
    cout << score << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3156
import java.util.Scanner;

public class Main {

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

		String ss = s + s;

		if (ss.indexOf(p)!=-1) {
			System.out.println("Yes");

		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 26044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

template<typename T> class BIT {
    int n;
    vector<T> dat;
public:
    void init(ll n_input) {
        n = n_input + 1;
        dat.resize(n + 1);
        for (int i = 0; i <= n; i++) dat[i] = 0;
    }
    ll sum(ll i) {
        ll s = 0;
        while (i >= 0) {
            s += dat[i];
            i = (i & (i + 1)) - 1;
        }
        return s;
    }
    void add(ll i, ll x) {
        while (i <= n) {
            dat[i] += x;
            i |= i + 1;
        }
    }
};

int main() {
    ll n;
    cin >> n;
    VL a(n), sorted(n);
    FOR(i, 0, n) {
        cin >> a[i];
        sorted[i] = a[i];
    }
    sort(sorted.begin(), sorted.end());
    int ok = 0, ng = n;
    BIT<ll> bit;

    ll border = ((n * (n + 1) / 2) + 1) / 2;
    while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        int midnum = sorted[mid];
        bit.init(2 * n + 1);
        int sum = 0;
        bit.add(sum + n, 1);
        ll result = 0;
        FOR(i, 0, n) {
            sum += (a[i] >= midnum ? 1 : -1);
            result += bit.sum(sum + n);
            bit.add(sum + n, 1);
        }
        if (result >= border)ok = mid;
        else ng = mid;
    }
    cout << sorted[ok] << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int H, W;
string field[1005];

int main() {
    //cout.precision(10);
    cin >> H >> W;
    for(int h = 0; h < H; h++) cin >> field[h];
    vector<ll> plus, minus;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            if(field[h][w] == '.') continue;
            plus.push_back(h+w);
            minus.push_back(h-w);
        }
    }
    sort(plus.begin(), plus.end());
    sort(minus.begin(), minus.end());
    cout << max(abs(plus[0] - plus.back()), abs(minus[0] - minus.back())) << endl;
    return 0;
}



Measured memory_bytes: 16540
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n,m;
	cin>>n>>m;
	vector<int>k(m),p(m);
	vector<vector<int>>vec(m);
	for(int i=0;i<m;i++){
		cin>>k[i];
		vec[i].resize(k[i]);
		for(int j=0;j<k[i];j++){
			cin>>vec[i][j];
			vec[i][j]--;
		}
	}
	int ans=0;
	for(int i=0;i<m;i++)cin>>p[i];
	for(int i=0;i<(1<<n);i++){
		bool ok=true;
		for(int j=0;j<m;j++){
			int tmp=0;
			for(auto l:vec[j]){
				if((i>>l)&1)tmp++;
			}
			if(tmp%2!=p[j])ok=false;
		}
		if(ok)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)


int power(ll x, unsigned int y)  
{  
	ll p=mod;
    ll res = 1;      
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  
ll gcdExtended(ll a, ll b, ll *x, ll *y)  
{  
    // Base Case  
    if (a == 0)  
    {  
        *x = 0;  
        *y = 1;  
        return b;  
    }  
  
    ll x1, y1; // To store results of recursive call  
    ll gcd = gcdExtended(b%a, a, &x1, &y1);  
  
    // Update x and y using results of  
    // recursive call  
    *x = y1 - (b/a) * x1;  
    *y = x1;  
  
    return gcd;  
}  
set<ll> fact(ll n){
  set<ll> res;
  for(ll i=2;i*i<=n;++i){
    if(n%i==0){
      res.insert(i);
      while(n%i==0) n /= i;
    }
  }
  if(n>1)res.insert(n);
  return res;
}
int main()
{
	multiset<ll,greater<int>> s;
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		ll t;
		cin>>t;
		s.insert(t);
	}
	//auto it;
	// for(auto it=s.begin();it!=s.end();it++)
	// 	cout<<*it;
	while(m--)
	{
		ll x=*(s.begin());
		
		s.erase(s.begin());
		s.insert(x/2);
		
	}
	ll ans=0;
	 for(auto it=s.begin();it!=s.end();it++)
	 {
	 	ans+=*it;
	 	//cout<<*it<<endl;

	 }
cout<<ans;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  
  int n = s.size();
  t = t + t;
  bool ok;
  rep(i,n){
    ok = true;
    rep(j,n) if(s[j] != t[i+j]) ok = false;
    if(ok) break;
  }
  
  cout << ( ok ? "Yes" : "No" ) << endl;
  
  return 0;
}
                      
                      

Measured memory_bytes: 256
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#include <bits/stdc++.h>
#include <cmath>
#define f first
#define s second
#define ms(a, b) memset(a,b,sizeof(a))
typedef long long ll;

using namespace std;

char _;
int arr[200001];
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);

    int N,tmp;
    scan(N);

    for(int i=1;i<N;i++){
        scan(tmp);
        arr[tmp]=arr[tmp]+1;
    }
    for(int i=1;i<=N;i++){
        cout << arr[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 4412
fun main(args: Array<String>) {
    val (N, L) = readInputLine().split(" ").map { it.toInt() }
    val a = readInputLine().split(" ").map { it.toInt() }.toIntArray()

    val ties = IntArray(N - 1) { a[it] + a[it + 1] }

    if (ties.all { it < L }) {
        println("Impossible")
        return
    } else {
        println("Possible")
    }

    // 最後にほどく結び目
    val lastTies = mutableSetOf<Int>()

    var l = 0
    var r = N - 2

    // まず左から最初に長さ和Lの結び目までほどく
    while (ties[l] < L) {
        println(l + 1)
        l++
    }
    lastTies.add(l)
    l++

    // 次に右から最初に長さ和Lの結び目までほどく
    while (ties[r] < L) {
        println(r + 1)
        r--
    }
    lastTies.add(r)
    r--

    // 左から長さ和がL未満の結び目を貪欲にほどく
    while (l <= r) {
        if (ties[l] < L) {
            println(l + 1)
        } else {
            lastTies.add(l)
        }
        l++
    }

    // 最後にほどく結び目をほどく
    for (t in lastTies) {
        println(t + 1)
    }
}

fun readInputLine(): String {
    return readLine()!!
}


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

  char moji;

  scanf("%c", &moji);

  if((moji>= 'a') && (moji<='z')){
    printf("a\n");
  }
  else if((moji>= 'A') && (moji<='Z')){
    printf("A\n");
  }
 
  return 0;
}


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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	ll N,M,K,count = 0;
  cin >> N >> K >> M;
  N = abs(N);
  count = N / M;
  if(count <= K){
  N -= M * count;
  K -= count;
  }else{
    N -= M * K;
    K = 0;
  }
 
  if(K == 0){
    cout << N << endl;
    return 0;
  }
    if(K % 2 == 0){
      cout << abs(N) << endl;
    }else{
      cout << abs(N - M) << endl;
    }
}

Measured memory_bytes: 3632
from itertools import groupby
s=input()
t=[0]*(len(s)+1)

gr=groupby(s)
now=0

for key,group in gr:
    if key=="<":
        for i in range(now,now+len(list(group))):
            t[i+1]=t[i]+1
            now+=1
    else:
        for i in range(now,now+len(list(group)))[::-1]:
            t[i]=max(t[i+1]+1,t[i])
            now+=1
print(sum(t))

Measured memory_bytes: 25940
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		long sum = 0;
		long min = 1000000;
		long max = -1000000;
		long a = 0;
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		for(int i = 1;i <= n;i++){
			a = scan.nextInt();
			if(a < min){
				min = 	a;
			}
			if(a > max){
				max = a;
			}
			sum += a;
		}
		System.out.println(min + " " + max + " " + sum);
	}

}

Measured memory_bytes: 41752
/* 
 * Project: AtCoder Beginners Contest 085 A - Already 2018
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/3
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

char s[10];

void solve() {

    s[3] += 1;
    printf("%s\n", s);

}

int main() {

    scanf("%s", s);

    solve();

}

Measured memory_bytes: 888
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

#define ll long long
#define ull unsigned long long

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


    int l;
    std::cin >> l;
    std::cout << std::setprecision(10) << std::pow(((double)l / 3.0), 3.0) << std::endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) = yorukatsu9b()

fun yorukatsu9b() {
    val (n, l) = readLine()!!.split(' ').map { it.toInt() }
    val sList = (1..n).map { readLine()!! }

    val answer = sList.sorted().joinToString("")

    println(answer)
}


Measured memory_bytes: 38372
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>

int main() {
	int a, b; std::cin >> a >> b;
	if (a <= 5) {
		std::cout << "0\n";
	}
	else if (a <= 12) {
		std::cout << b / 2 << '\n';
	}
	else {
		std::cout << b << '\n';
	}
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int bingo[3][3];
	int same_number[3][3];
	int n;
	int b[10];
	for (int i = 0; i < 3; i++)
		scanf("%d%d%d", &bingo[i][0], &bingo[i][1], &bingo[i][2]);

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &b[i]);


	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			for (int k = 0; k < n; k++)
				if (bingo[i][j] == b[k])
				{
					same_number[i][j] = 1;
					break;
				}
				else
					same_number[i][j] = 0;

	for (int i = 0; i < 3; i++)
		if (same_number[i][0] && same_number[i][1] && same_number[i][2])
		{
			printf("Yes");
			return 0;
		}
		else if (same_number[0][i] && same_number[1][i] && same_number[2][i])
		{
			printf("Yes");
			return 0;
		}

	if (same_number[0][0] && same_number[1][1] && same_number[2][2])
	{
		printf("Yes");
		return 0;
	}

	if (same_number[2][0] && same_number[1][1] && same_number[0][2])
	{
		printf("Yes");
		return 0;
	}
    printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	ll a[n];
	for(int i = 0; i<n; i++)
		cin>>a[i];
	map<ll,ll> mp,mp2;
	for(ll i = 0,j=1; i<n; i++,j++)
	{
		mp[a[i]+j]++;
		mp2[j-a[i]]++;
	}
	ll ans = 0;
	for(auto it:mp)
		ans += mp2[it.first]*it.second;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 39528
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int main(){
	int a[maxn],dp[maxn],n;
	memset(dp,0x3f3f,sizeof(dp));
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	dp[1] = 0;
	for(int i = 2;i <= n;i++){
		dp[i] = min(dp[i],dp[i - 1] + abs(a[i] - a[i -1]));
		if(i > 2) dp[i] = min(dp[i],dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
n,k = gets.split.map(&:to_i)
h = []
n.times do
  h << gets.to_i
end
h.sort!{| a, b | b <=> a }
ans = 1000000000
(n-k+1).times do |i|
  if (h[i]-h[i+k-1]) < ans
    ans = h[i]-h[i+k-1]
  end
end
puts ans


Measured memory_bytes: 4016
#include <cstdio>
#include <algorithm>

#define maxn 200010
int n, k, hcnt;
long long a[maxn], hash[maxn];
int bit[maxn];
#define lowbit(x) ((x) & -(x))
void add(int x)
{
	for (; x <= hcnt; x += lowbit(x)) ++bit[x];
}
int query(int x)
{
	int ret = 0;
	for (; x; x -= lowbit(x)) ret += bit[x];
	return ret;
}
int main()
{
	int n, k; scanf("%d%d", &n, &k);
	hash[++hcnt] = 0;
	for (int i = 1; i <= n; ++i)
		scanf("%lld", a + i), a[i] = a[i - 1] + a[i] - k, hash[++hcnt] = a[i];
	std::sort(hash + 1, hash + hcnt + 1);
	hcnt = std::unique(hash + 1, hash + hcnt + 1) - hash - 1;
	long long ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		int ai = std::lower_bound(hash + 1, hash + hcnt + 1, a[i]) - hash;
		ans += query(ai);
		add(ai);
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    long long int a[n], b[n];
    long long int a_sum = 0, b_sum = 0; 
    for(int i = 0; i < n; ++i) cin >> a[i], a_sum += a[i];
    for(int i = 0; i < n; ++i) cin >> b[i], b_sum += b[i];

    long long int cnt = b_sum - a_sum;
    if(cnt < 0) {
        cout  << "No" << '\n';
        return 0;
    }
    long long int a_diff = 0, b_diff = 0;
    for(int i = 0; i < n; ++i) {
        if(a[i] > b[i]) a_diff += a[i] - b[i];
        else b_diff += (b[i] - a[i])/2;
    }
    
    if(a_diff <= b_diff) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 384
N,L=input().split()
N=int(N)
L=int(L)
sum=N*L+(1+N)*N/2-N
if L+1-1<=0 and N+L-1>=0:
    print(int(sum))
elif L+1-1<=0 and N+L-1<=0:
    print(int(sum-(L+N-1)))
else:
    print(int(sum-(L+1-1)))


Measured memory_bytes: 3060