akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;

int n, ans = INF;
int x, y, z;
vector<int> l;
void dfs(int cur, int A, int B, int C, int a, int b, int c) {
  if(cur==n) {  //l1~lnまで全探索
    if(A>=1&&B>=1&&C>=1) {
      int cos = abs(a-x)+abs(b-y)+abs(c-z)+(A+B+C-3)*10;//最初に使う竹の分はMP10はいらない(-30)
      ans = min(ans,cos);
      return;
    }
    else return;
  }

  dfs(cur+1, A, B, C, a, b, c);//l[cur]を使わない
  dfs(cur+1, A+1, B, C, a+l[cur], b, c);//l[cur]をxで使う。
  dfs(cur+1, A, B+1, C, a, b+l[cur], c);//l[cur]をyで使う。
  dfs(cur+1, A, B, C+1, a, b, c+l[cur]);//l[cur]をzで使う。
}

int main() {
  cin >> n >> x >> y >> z;
  l.resize(n);
  rep(i,n) cin >> l[i];
  dfs(0,0,0,0,0,0,0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
int main()
{
	int lena,lenb;
	char a[12],b[12],c[12];
	scanf("%s %s %s",a,b,c);
	lena = strlen(a);
	lenb = strlen(b);
	if(a[lena - 1] == b[0] && b[lenb - 1] == c[0])
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
N, K, Q = map(int,input().split())
A=[]
P=[]
for i in range(Q):
    A.append(int(input())-1)
for j in range(N):
    P.append(K-Q)
for k in A:
    P[k]+=1
for l in range(N):
    if P[l]>0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 11784
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
int n;
string bfs(int sum,string omori,int now){
    int weight[11] = {1,2,4,8,16,32,64,128,256,512};
    string weight2[11] = {"1","2","4","8","16","32","64","128","256","512"};
    if(sum==n)return omori;
    else if(now==10)return "Not_find";
    else if(sum>n)return "Not_find";
    
    string next = " ";
    if(omori=="")next = "";
    string result1 = bfs(sum+weight[now],omori+next+weight2[now],now+1);
    string result2 = bfs(sum, omori,now+1);
    if(result1!="Not_find")return result1;
    else return result2;
}

int main(){
    while (cin>>n) {
        string result = bfs(0,"",0);
        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
#define out(x) cout<<x<<'\n';
inline char gc(){char op[2];scanf("%s",op);return op[0];}
const int N = 2e5+10;
const double eps = 0.00000001;
const ll mod = 1e9 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
vector<int> G[N];
map<int,int> hap;
bool vis[2005];
struct node{
    int x,val;
    node(){}
    node(int a,int b):x(a),val(b){}
};
void bfs(int u){
    memset(vis,0,sizeof vis);
    queue<node> q;
    q.push({u,0});
    node tmp;
    while(q.size()){
        tmp = q.front();
        int x = tmp.x,val = tmp.val;
        q.pop();
        vis[x] = 1;
        int S =  G[x].size();
        for(int i = 0;i < S;++i){
            int y = G[x][i];
            if(!vis[y]){
                vis[y] = 1;
                hap[val+1]++;
                q.push({y,val+1});
            }
        }
    }
}
int main(){
    int  n = read(), x = read(),y = read();
    rep(i,1,n-1){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[x].push_back(y);
    G[y].push_back(x);
    rep(i,1,n){
        bfs(i);
    }
    rep(i,1,n-1){
        cout<<hap[i]/2<<'\n';
    }
}


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

using namespace std;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) (int)a.size()
#define fi first
#define se second
#define ar array

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int > pii;
const ll MOD =1e9+7;

void solve(){
	int n, x,g; cin>> n >> x;
	vi a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		if(i == 0)
			g = abs(x-a[i]);
		else
			g = __gcd(g,abs(x-a[i]));
	}
	cout << g;
}
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		solve();
		cout <<'\n';
	}
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(){
	char s[4];
	cin>>s;
	if((s[0]==s[1]&&s[1]==s[2]) || (s[1]==s[2]&&s[2]==s[3]))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;	
}

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

using namespace std;

int main()
{
  long long  N, x;
  cin >> N >> x;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  long long ans = 0;
  if (a[0] > x) {
    ans += a[0] - x;
    a[0] = x;
  }

  for (int i = 1; i < N; i++) {
    if (a[i] + a[i - 1] > x) {
      long long tmp = a[i] + a[i - 1] - x;
      ans += tmp;
      a[i] -= tmp;
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
n=int(input())
arr=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(arr[1]-arr[0])
for i in range(2,n):
	dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]))
print(dp[n-1])


Measured memory_bytes: 13980
a = 0
b = 0
o = 0
ab = 0
while 1:
    try:
        num, blood = map(str, input().split(","))
    except:
        break

    if blood == "A":
        a += 1
    elif blood == "B":
        b += 1
    elif blood == "O":
        o += 1
    else:
        ab += 1

print(a)
print(b)
print(ab)
print(o)



Measured memory_bytes: 5560
/*ITS FUCKING O(N) now
GET ACCEPTED FOR FUCK'S SAKE*/


#include <iostream>
# include <bits/stdc++.h>
using namespace std;

long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=0;i<n;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;

#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int main()
{
  string s,s1;
  cin>>s>>s1;
  int flag=1;
  rep(i,0,s.size()-1)
  {
  	if(s[i]!=s1[i])
  	{
  		flag=0;
  		cout<<"No";
  		break;
  	}
  }
  if(flag)
  {
  	if(s1.size()==s.size()+1)
  	{
  	cout<<"Yes";
  	}
  	else
  	{
  		cout<<"No";
  	}
  }

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	string patern[] = {"SS", "SW", "WS" , "WW"};
	for(auto p : patern){
		string a = p;
		range(i,2,n){
			char hint = s[i - 1];
			if(a[i - 1] == 'W') hint = hint == 'o' ? 'x' : 'o';

			if(hint == 'o'){
				a += a[i - 2];
			}else{
				a += a[i - 2] == 'W' ? "S" : "W";
			}
		}

		string c = a.back() + a + a;
		bool f = true;
		rep(i,n){
			char hint = s[i];
			if(a[i] == 'W') hint = hint == 'o' ? 'x' : 'o';

			if(hint == 'o' and c[i] != c[i + 2]) f = false;
			if(hint == 'x' and c[i] == c[i + 2]) f = false;
		}
		if(f){
			cout << a << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 988
#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
#include<vector>
#include<tuple>
using namespace std;
//# Functions for Vector/Matrix
template <typename T>
vector<T> zeros(int length){
    vector<T> vec(length, 0);
    return vec;
}
template <typename T>
vector<vector<T>> zeros(tuple<int, int> dim){
    vector<vector<T>> mat(get<0>(dim), vector<T>(get<1>(dim), 0));
    return mat;
}
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define VARNAME(VariableName) # VariableName
template <typename T>
void show(vector<T> &vec){
    cerr << VARNAME(vec) << ": " << endl;
    for (auto value : vec) {
        cerr << value << " ";
    }
    cerr << endl;
}
template <typename T>
void show(vector<vector<T>> &mat){
    for (auto vec : mat) {
        show(vec);
    }
}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(ALL(a))
#define RSORT(a) sort(RALL(a))
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; }
bool iseven(int x){ return x % 2 == 0; }
bool isodd(int x){ return !iseven(x); }
int dist(int x, int y) { return abs(x - y);}
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main(){
	// cin.tie(0);
   	// ios::sync_with_stdio(false);
    // N: マッチ本数、M: 使える数字のパターン数
    // Ex. 20 4
    int N, M; cin >> N >> M;
    // A: 使える数字の集合
    // Ex. 3 7 8 4
    VI A(M); REP(i, M) cin >> A[i];
    RSORT(A);
    show(A);
    // 各数字を作るのに必要なマッチの本数。0はダミー
    //           1,2,3,4,5,6,7,8,9
    VI cost = {0,2,5,5,4,5,6,3,7,6};
    // ちょうど i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
    VI dp(N+1, (int)-1e9);
    dp[0] = 0;
    FOR(i, 1, N+1){
        for(auto& j: A){
            // i本のマッチで作れる整数の最大桁数は
            // j ∈Aを使ってdp[i - cost[j]]桁から一桁増やした場合
            // をすべてのjについて比較することで得られる
            if(i - cost[j] >= 0) dp[i] = max(dp[i], dp[i - cost[j]]+1);
        }
    }
    // N本のマッチを使って得られる最大の桁数dp[N]に以下に数字を配置していくかを解く
    // 単純に逆順ソートされている数字を上から走査して，使えるものを使えば良い
    int n = N; // 残りマッチ本数
    string ans; // 出力する整数
    while(n > 0){
        // n本のマッチから何本か使って作れる最大の数字を調べる
        int a; // 各桁で使う数字
        for(auto& j: A){
            // 数字jを使って，一桁分の数字を作れるかを判定
            if((n - j >= 0) and (dp[n - cost[j]] == dp[n] - 1)){
                a = j;
                break;
            }
        }
        n -= cost[a];
        ans += '0' + a;
    }
    cout << ans;
    return 0;
}



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

    int main(void){
        int n, x;
        cin >> n;
        int cnt = 0;
        vector<int> d(101,0);
        for (int i = 0; i < n; i++){
            cin >> x;
            if(d.at(x)==0)
                d.at(x) = 1;
            else
                d.at(x) += 1;
        }
        for (int i = 0; i < 101;i++){
            if(d.at(i)!=0)
                cnt++;
        }
        cout << cnt << endl;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 305;
const Int MAX2 = MAX*2;
Int ex[MAX2][MAX2];
Int dp[MAX2+2][MAX2+2];
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(Int i=0;i<h;i++) cin>>s[i];

  using P = pair<int, int>;
  vector<P> vp;
  memset(ex,0,sizeof(ex));
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      if(s[i][j]!='#') continue;
      vp.emplace_back(1+i+j,1+i-j+w);
      ex[1+i+j][1+i-j+w]=1;      
    }
  }
  
  auto ch=
    [&](Int i,Int j)->Int{
      if(i<0||i>=MAX2) return 0;
      if(j<0||j>=MAX2) return 0;
      return ex[i][j];
    };
  
  const int LIM = h+w;
  Int ans=0;
  for(Int k=1;k<=LIM;k++){
    for(Int i=0;i<MAX2;i++)
      for(Int j=1;j<MAX2;j++)
        dp[i][j+1]=dp[i][j]+(ch(i,j)&&ch(i,j-k));

    for(P p:vp){
      int i,j;
      tie(i,j)=p;
      if(i-k>=0)  ans+=dp[i-k][min(MAX2-1,j+k+1)]-dp[i-k][j];
      if(i+k<MAX2) ans+=dp[i+k][min(MAX2-1,j+k+1)]-dp[i+k][j];
    }

    for(Int j=0;j<MAX2;j++)
      for(Int i=0;i<MAX2;i++)
        dp[j][i+1]=dp[j][i]+(ch(i,j)&&ch(i-k,j));
    
    for(P p:vp){
      int i,j;
      tie(i,j)=p;
      if(j-k>=0)  ans+=dp[j-k][min(MAX2-1,i+k+1)]-dp[j-k][i];
      if(j+k<MAX2) ans+=dp[j+k][min(MAX2-1,i+k+1)]-dp[j+k][i];   
    }            
  }

  //cout<<ans<<endl;
  if(1){
    for(Int i=0;i<MAX2;i++){
      for(Int j=0;j<MAX2;j++){
        if(!ex[i][j]) continue;
        for(Int k=1;k<=LIM;k++){
          if(ch(i+k,j)&&ch(i,j+k)) ans--;
          if(ch(i+k,j)&&ch(i,j-k)) ans--;
          if(ch(i-k,j)&&ch(i,j+k)) ans--;
          if(ch(i-k,j)&&ch(i,j-k)) ans--;
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7032
N, M = map(int, input().split())
O = list(map(int, input().split()))
B = [[] for i in range(N)]
 
for j in range(M):
  o_1, o_2 = map(int, input().split())
  B[o_1-1].append(o_2-1)
  B[o_2-1].append(o_1-1)

ans = 0
for node in range(N):
  flag =1
  for l in B[node]:
    if O[node] <= O[l]:
      flag = 0
  if  flag ==1:
    ans += 1
print(ans)
      

Measured memory_bytes: 29344
'use strict';
(function(stdin) {
  //declare function

  //declare variable
  var inputs = stdin.toString().trim().split(' ');
  inputs = inputs.map(Number);
  var a = inputs.shift();
  var b = inputs.shift();
  //main
  if (a < b) {
    console.log('a < b');
  } else if (a > b) {
    console.log('a > b');
  } else if (a == b) {
    console.log('a == b');
  }
  //display
  // console.log(a, b);
})(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 15472
#include<stdio.h>
int main()
{
    long long int N,i,sum;
    sum=0;
    scanf("%lld",&N);
    for(i=1;i<=N;i++)
    {
        if(i%3!=0 && i%5!=0)
        sum=sum+i;
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 1736
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<utility>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;
using ll = long long;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

const long long MOD = 1e9+7;
const long long INF = 1e11;
const long long MAX = 3e5+1;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int N, M, X;
    in(N); in(M); in(X);

    vector<int> C(N, 0);
    vector<vector<int>> A(N, vector<int> (M, 0));
    rep(i, N) {
        in(C[i]);
        rep(j, M) in(A[i][j]);
    }
    int ans = INT_MAX;
    int cost;
    rep(i, (1<<N)) {
        cost = 0;
        vector<int> U(M, 0);

        rep(j, N) {
            if ((i>>j) & 1) {
                cost += C[j];
                rep(k, M)
                    U[k] += A[j][k];
            }
        }
        /*
        rep(j, M) cout << U[j] << '\t';
        cout << endl;
        cout << cost << endl;
        */

        bool flag = true;
        rep(j, M) {
            if (U[j] < X) {
                flag = false;
                break;
            }
        }
        if (!flag) continue;
        ans = min(ans, cost);
    }

    if (ans == INT_MAX) out(-1);
    else out(ans);


    return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

vs M;

int HH, WW;
int N = 0, W = 0, S = 0, E = 0;

void bfs() {
	queue<pii> que;
	que.push(make_pair(0, 0));

	M[0][0] = '.';

	while (!que.empty()) {
		
		const pii now = que.front(); que.pop();
		REP(i, 4) {
			int ny = now.first + dy[i];
			int nx = now.second + dx[i];

			if (nx < 0 || WW <= nx || ny < 0 || HH <= ny) continue;
			if (M[ny][nx] == '.') continue;
			if (M[ny][nx] == 'G') return;

			if (i == 0) {
				E++;
			} else if (i == 1) {
				S++;
			} else if (i == 2) {
				W++;
			} else {
				N++;
			}

			M[ny][nx] = '.';
			que.push(make_pair(ny, nx));

			cout << "----================----" << endl;
			REP(i, HH) {
				cout << M[i] << endl;
			}
		}
	}
}

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

	cin >> HH >> WW;
	M.resize(HH);

	REP(i, HH) {
		cin >> M[i];
	}

//	M[HH - 1][WW - 1] = 'G';
//	bfs();

	FOR(i, 1, HH) {
		FOR(j, 1, WW) {
			if (M[i - 1][j] == '#' && M[i][j - 1] == '#') {
				cout << "Impossible" << endl;
				return 0;
			}
		}
	}
	cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define vec vector<int> 
#define int long long 
#define pii pair<int,int>
string s;
int n;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
	int t=1;
	//cin>>t;
	while(t--){
		//int n;
		cin>>n;
		//int arr[n][n];
		//bool visited[n+1];
		int dp[n+1][n+1];
		memset(dp,0,sizeof(dp));
		cin>>s;
		s=" "+s;
		int pre_sum[n+1]={0};
		pre_sum[0]=0;
		pre_sum[1]=1;
		memset(dp,0,sizeof(dp));
		dp[1][0]=0;
		dp[1][1]=1;
		REP(i,1,n+1){
			pre_sum[i]=pre_sum[i-1]+dp[1][i];
		}
		REP(i,2,n+1){
			REP(j,1,i+1){
				if(s[i-1]=='<'){
					dp[i][j]=(pre_sum[j-1]%mod);
				}
				else{
					dp[i][j]=((pre_sum[i-1]%mod)-(pre_sum[j-1]%mod)+mod)%mod;
				}
				dp[i][j]%=mod;
			}
			dp[i][0]=0;
			REP(j,1,i+1){
				pre_sum[j]=((dp[i][j]%mod)+(pre_sum[j-1]%mod))%mod;
				pre_sum[j]%=mod;
			//	cout<<pre_sum[j]<<" ";
			}
		//	cout<<endl;
		}
		int ans=0;
		
		REP(i,1,n+1){
			ans+=dp[n][i]%mod;
			ans%=mod;
		}
		cout<<ans<<endl;
	}
	//exit();
	return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
static const LL INF = 1<<24;
static const LL LL_INF = 1<<60;
static const int mod = 1e+5;
static const int MAX_N = 200;
int dx[]={0,1};
int dy[]={1,0};
using namespace std;


int w,h;
LL mem[MAX_N][MAX_N][3][3][3][3];
LL cal(int x,int y,int px,int py,int ppx,int ppy){
    LL res=0;
    if(mem[x][y][px][py][ppx][ppy]!=0)return mem[x][y][px][py][ppx][ppy];
    if(x>=w||y>=h)return 0;
    if(x==w-1&&y==h-1)return 1;
    FOR(i,0,1){
        if(x==0&&y==0)res+=cal(x+dx[i],y+dy[i],dx[i],dy[i],px,py);
        else{
            if(px!=ppx&&py!=ppy&&px!=dx[i]&&py!=dy[i])continue;
            res+=cal(x+dx[i],y+dy[i],dx[i],dy[i],px,py)%mod;
        }
    }
    return mem[x][y][px][py][ppx][ppy]=res%mod;
}

int main(){
    while(1){
        memset(mem,0,sizeof(mem));
        cin>>w>>h;
        if(w==0&&h==0)break;
        cout<<cal(0,0,0,0,0,0)<<endl;
    }
    return 0;
}

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

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<String> ans = new ArrayList<String>();

		String line;
		while((line = in.readLine()) != null){
			String[] dst = line.split(" ");
			int x = 0;
			int y = 0;
			int h = Integer.parseInt(dst[0]);
			int w = Integer.parseInt(dst[1]);

			if(w==0 && h==0){
				break;
			}

			String[][] data = new String[h][w];
			for(int j=0; j<h; j++){
				line = in.readLine();
				for(int i=0; i<w; i++){
					data[j][i] = line.substring(i, i+1);
				}
			}

			int step = 0;
			String tile = null;
			while(true){
				tile = data[y][x];

				if(tile.equals(">")){
					x++;
				}
				else if(tile.equals("<")){
					x--;
				}
				else if(tile.equals("v")){
					y++;
				}
				else if(tile.equals("^")){
					y--;
				}
				else if(tile.equals(".")){
					ans.add(Integer.toString(x) + " " + Integer.toString(y));
					break;
				}

				step++;
				if(step > w*h+1){
					//System.out.println(step);
					ans.add("LOOP");
					break;
				}
			}
		}

		for(int i=0; i<ans.size(); i++){
			System.out.println(ans.get(i));
		}
	}
}

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

ll = [[i - j, i, j] for i, j in zip(a, b)]

ll.sort(reverse=True)
start = n -1

if sum(a) < sum(b):
    print(-1)
    exit(0)

for i in range(n):
    while ll[i][0] > 0:
        if ll[start][0] < 0:
            if ll[i][0] + ll[start][0] >= 0:
                ll[i][0] += ll[start][0]
                ll[start][0] = 0
                start -= 1
            elif ll[i][0] + ll[start][0] < 0:
                ll[start][0] += ll[i][0]
                ll[i][0] = 0
                break
        else:
            break

cnt = 0

for l in ll:
    if l[1] - l[2] != l[0]:
        cnt += 1

print(cnt)
"""
方針
- b - aが小さい要素を使って、b - aが大きい要素を埋めていく
- 

"""


Measured memory_bytes: 92976
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 456789;
const int INF = (int)1e9;
vector<int> line[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    vector<pii> V;
    int mx = 0, mn = INF;
    for (int i = 0; i < N; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (x > y) swap(x, y);
        V.push_back(make_pair(x, y));
        mn = min(x, mn);
        mx = max(y, mx);
    }
    sort(V.begin(), V.end());
    int mxL = mx, mnR = mn;
    multiset<int> st;
    for (int i = 0; i < N; i++) {
        mxL = min(mxL, V[i].second);
        mnR = max(mnR, V[i].first);
        st.insert(mnR);
    }
    LL ans = ((LL)mx - mxL) * ((LL)mnR - mn);
    LL len = (mx - mn);
    for (int i = 0; i < N; i++) {
        LL x = V[i].first, y = V[i].second;
        st.erase(st.find(x));
        st.insert(y);
        ans = min(ans, len * (*st.rbegin() - *st.begin()));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 21872
n,m,c=map(int,input().split())
b=[int(i) for i in input().split()]
a=[[int(i) for i in input().split()] for j in range(n)]
x=0
for i in range(n):
    y=0
    for j in range(m):
        y+=a[i][j]*b[j]
    if y+c>0:
        x+=1
print(x)

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

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

    vector<int> a(m, 0);
    int can = 0;
    vector<int> odds;
    vector<int> evens;

    for (int i = 0; i < m; i += 1) {
        cin >> a[i];
        can += a[i] / 2;
        if (a[i] % 2)
            odds.push_back(a[i]);
        else
            evens.push_back(a[i]);
    }

    can += n / 2;

    if (can < n - 1) {
        cout << "Impossible\n";
        return 0;
    }

    vector<int> aa, bb;

    if (m == 1) {
        aa = a;
        if (n > 1)
            bb = {1, n - 1};
        else {
            bb = {1};
        }
    } else {
        auto insertOdd = [&] () {
            if (odds.empty())
                return;
            aa.push_back(odds.back());
            odds.pop_back();
        };

        insertOdd();
        aa.insert(aa.end(), evens.begin(), evens.end());
        insertOdd();
        
        if (aa[0] > 1)
            bb.push_back(aa[0] - 1);
        for (int i = 1; i < m - 1; i += 1)
            bb.push_back(aa[i]);
        bb.push_back(aa.back() + 1);
    }

    for (int val : aa)
        cout << val << " ";
    cout << "\n";

    cout << bb.size() << "\n";

    for (int val : bb)
        cout << val << " ";
    cout << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 200005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m, a, b, fac[maxn], inv[maxn];
il int Sum(int x) {
	return Dec(qpow(2, x), 1);
}
il int C(int x, int y) {
	return Mul(fac[x], Mul(inv[y], inv[x - y]));
}
il int F(int x) {
	int ans1 = 1, ans2 = 1;
	rep(i, 1, x) ans1 = Mul(ans1, i);
	rep(i, n - x + 1, n) ans2 = Mul(ans2, i);
	ans2 = Mul(ans2, qpow(ans1, mod - 2));
	return ans2;
}
int main() {
	n = read(), a = read(), b = read();
	cout << Dec(Sum(n), Inc(F(a), F(b))) << endl;
	return 0;
}

Measured memory_bytes: 256
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f**2 <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
count = 0
N = int(input())

if N <= 1:
  print(0)
  exit()
else:
  c = collections.Counter(prime_factorize(N))

  K = [sum(range(1,i)) for i in range(2,11)]
  # = [1, 3, 6, 10, 15, 21, 28, 36, 45]
 
  for i in c:
    for j in range(1,len(K)):
      if c[i] < K[j]:
        count += j
        break

  print(count)

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

#define ff first
#define ss second
#define ins insert
#define ll long long
#define ld long double
#define vl vector<ll>
#define sz(c) (ll) c.size()
#define all(c) begin(c), end(c)
#define trv(x,c) for(auto &x : c)
#define tc ll t; cin >> t; while(t--)
#define rep(i,a,n) for(ll i = a; i < n; ++i)
#define per(i,a,n) for(ll i = n-1; i >= a; --i)
#define godspeed cin.tie(0) -> sync_with_stdio(0)

int main() {
    godspeed;
    string s; cin >> s;
    if(s == "RRR") cout << 3;
    else if(s == "RRS") cout << 2;
    else if(s == "SRR") cout << 2;
    else if(s == "RSS") cout << 1;
    else if(s == "SRS") cout << 1;
    else if(s == "SSR") cout << 1;
    else if(s == "RSR") cout << 1;
    else if(s == "SSS") cout << 0;
}

Measured memory_bytes: 3656
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

total = sum(B) - sum(A)
Aadd = 0
for i in range(N):
    if A[i] < B[i]:
        if (B[i] - A[i])%2==0:
            Aadd += (B[i]-A[i])//2
        else:
            Aadd += (B[i]-A[i])//2+1
print("Yes" if Aadd <= total else "No")

Measured memory_bytes: 4600
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

bool find(int fixIndex, v fixRef, v targetRef, v target, int limit, int other) {
  for (int i = 0; i < fixRef.size(); i++) {
    if (fixIndex == fixRef[i]) {
      target[targetRef[i]]--;
    }
  }
  int tmp = 0;
  for (int i = 0; i < target.size(); i++) {
    tmp = max(tmp, target[i]);
  }
  return tmp + other == limit;
}

int main()
{
  int h, w, m;
  cin >> h >> w >> m;
  map<p, int> memo;
  v hs(m, 0);
  v ws(m, 0);
  v hcnt(h, 0); v wcnt(w, 0);
  rep(i, m) {
    cin >> hs[i] >> ws[i];
    hcnt[--hs[i]]++;
    wcnt[--ws[i]]++;
    p tmp;
    tmp.first = hs[i];
    tmp.second = ws[i];
    memo[tmp] = 1;
  }

  int hmax = 0; int wmax = 0;
  int hindex = 0; int windex = 0;
  rep(i, h) {
    if (hmax < hcnt[i]) {
      hmax = hcnt[i];
      hindex = i;
    }
  }
  rep(i, w) {
    if (wmax < wcnt[i]) {
      wmax = wcnt[i];
      windex = i;
    }
  }

  if (memo.count({hindex, windex}) == 0) {
    cout << hmax + wmax << endl;
  } else {
    if (find(hindex, hs, ws, wcnt, hmax + wmax, hmax) || find(windex, ws, hs, hcnt, hmax + wmax, wmax)) {
      cout << hmax + wmax << endl;
    } else {
      cout << hmax + wmax - 1 << endl;
    }
  }
}


Measured memory_bytes: 33608
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a, b, c, d;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b >> c >> d;
	while(1){
		c -= b;
		if(c <= 0){
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if(a <= 0){
			cout << "No" << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,h[21],maxx=-1,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>h[i];
	for(int i=1;i<=n;i++)if(h[i]>=maxx)ans++,maxx=h[i];
	cout<<ans<<endl; 
}

Measured memory_bytes: 256
N = int(input())
for i in range(1,3501):
    h = i
    for j in range(1,3501):
        n = j
        wb = (4*h*n-N*n-N*h)
        if wb > 0:
            w = (N*h*n)/wb
            if w.is_integer() is True:
                print(h,n,int(w))
                exit()


Measured memory_bytes: 40796
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A[200000], B[200000];
    cin >> N;
    map<int, int> mii;
    REP(i, N) {
        cin >> A[i];
        mii[A[i]]++;
    }
    REP(i, N) {
        cin >> B[i];
        mii[B[i]]++;
    }
    for (auto p : mii) {
        if (p.second > N) {
            cout << "No" << endl;
            return 0;
        }
    }

    int C[200001] = {}, D[200001] = {};
    REP(i, N) {
        C[A[i]]++;
        D[B[i]]++;
    }
    REP(i, N) {
        C[i + 1] += C[i];
        D[i + 1] += D[i];
    }

    int offset = 0;
    REP(i, N) {
        offset = max(D[i + 1] - C[i], offset);
    }
    cout << "Yes" << endl;
    REP(i, N) {
        cout << B[(i + offset) % N] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 15980
#include<bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
int n;
int a[N],b[N],c[N];
int main()
{
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        int tmp=a[i];
        while(tmp)
        {
            b[i]++;
            tmp>>=1;
        }
        b[i]--;
        if((a[i]&-a[i])!=a[i])c[i]=1;
        ans+=b[i]+c[i];
    }
    int lst=0;
    for(int i=1;i<=n;i++)
    {
        int tmp=min(b[i],lst);
        ans-=tmp;lst-=tmp;
        if(lst>0&&c[i]>0)
        {
            ans--;c[i]--;
        }
        lst=b[i]+c[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main(){
    int a, p;
    cin >> a >> p;
    int pp = 3*a+p;
    
    cout << pp/2 << endl;
    
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;

	int count = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i] && b[i] == c[i]) {

		}
		else if (a[i] == b[i]) {
			count++;
		}
		else if (b[i] == c[i]) {
			count++;
		}
		else if (a[i] == c[i]) {
			count++;
		}
		else {
			count += 2;
		}
	}

	COUT(count);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long

using namespace std;

const ll N = 2e5 + 5, M = N * 2;

vector<int> v;

int main()
{
    int l, r, mn = 1e9;
    scanf("%d%d", &l, &r);
    for(int i = l, j = 0 ; i <= r and j <= 2019 ; i++, j++)
    {
        v.push_back(i % 2019);
    }
    for(int i = 0 ; i < v.size() ; i++)
    {
        for(int j = i + 1 ; j < v.size() ; j++)
        {
            mn = min(mn, (v[i] * v[j]) % 2019);
        }
    }
    printf("%d\n", mn);
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
 
using namespace std;
 
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
 
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
 
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
 
const double EPS = 1e-10;

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

	REP(syzygy, n) {
		int x, y, w, h;
		cin >> x >> y >> w >> h;

		int cn, num = 0;
		cin >> cn;

		REP(i, cn) {
			int cx, cy;
			cin >> cx >> cy;

			if(x <= cx) {
				if(cx <= x+w) {
					if(y <= cy) {
						if(cy <= y+h) {
							num++;
						}
					}
				}
			}
		}

		cout << num << endl;
	}
}

Measured memory_bytes: 0
# 視点を変えてやる全探索 実は条件よりAを全列挙することが可能

# rec, 1からじゃなくて0からにしてたせいか1ケースでWA????

n, m, q = map(int, input().split())
koho = []


def rec(arr):
    if len(arr) == n:
        koho.append(arr)
    else:
        for i in range(arr[-1], m + 1):
            nex_arr = arr[:]
            nex_arr.append(i)
            rec(nex_arr)


# これ 0からにしてたんだけど べつに影響なくないか？？？？？？
for i in range(1, m + 1):
    rec([i])
ans = 0

qs = []
for _ in range(q):
    qs.append(list(map(int, input().split())))

for arr in koho:
    tmp = 0
    for abcd in qs:
        if arr[abcd[1] - 1] - arr[abcd[0] - 1] == abcd[2]:
            tmp += abcd[3]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 99944
import sys


def input():
    return sys.stdin.readline()[:-1]


N, Q = map(int, input().split())

tree = {}
for i in range(1, N + 1):
    tree[i] = []
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a] += [b]

count = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split())
    count[p] += x

stack = [1]
while stack:
    label = stack.pop()
    if tree[label] != []:
        for next_label in tree[label]:
            count[next_label] += count[label]
        stack += tree[label]

ans = count[1:]
print(*ans)


Measured memory_bytes: 66528
s=[int(input()) for i in range(5)]
a=0
b=10
for i in s:
    for j in range(0,140,10):
        if j>=i:
            a+=j
            break
    if i%10>0:
        b=min(b,i%10)

if b==10:
    print(a)
else:
    print(a-10+b)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const ll mod=1e9+7;
ll a[N],sum[N]={0};
int main(){
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum[i]=(a[i]+sum[i-1]);
    }
    ll ans=0;
    for(int i=1;i<=n-1;i++){
        ans=(ans+a[i]*((sum[n]-sum[i])%mod)%mod)%mod;
    }
    cout<<ans;
}




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

int H, W, N;
int sr, sc;
string S, T;

int main() {
    cin >> H >> W >> N;
    cin >> sr >> sc;
    cin >> S;
    cin >> T;
    
    // L
    int left = sc - 1;
    int right = W - sc;
    for (int i=0; i<N; ++i) {
        if (S[i] == 'L') {
            --left;
            ++right;
        }
        if (left < 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'R' && right > 0) {
            --right;
            ++left;
        }
    }
    // R
    left = sc - 1;
    right = W - sc;
    for (int i=0; i<N; ++i) {
        if (S[i] == 'R') {
            ++left;
            --right;
        }
        if (right < 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'L' && left > 0) {
            ++right;
            --left;
        }
    }
    // U
    int up = sr - 1;
    int down = H - sr;
    for (int i=0; i<N; ++i) {
        if (S[i] == 'U') {
            ++down;
            --up;
        }
        if (up < 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'D' && down > 0) {
            ++up;
            --down;
        }
    }
    // D
    up = sr - 1;
    down = H - sr;
    for (int i=0; i<N; ++i) {
        if (S[i] == 'D') {
            --down;
            ++up;
        }
        if (down < 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'U' && up > 0) {
            --up;
            ++down;
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1020
#include <iostream>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    if ((a-b)%2!=0){
        cout<<"IMPOSSIBLE";
    }
    else{
        if (a>b)
            cout<<(a-b)/2+b;
        else if (a<b)
            cout<<(b-a)/2+a;
            
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
ans=0
for i in range(n):
    if al[i]>=bl[i]:
        ans+=bl[i]
    else:
        ans+=al[i]
        t=bl[i]-al[i]
        if al[i+1]>=t:
            ans+=t
            al[i+1]-=t
        else:
            ans+=al[i+1]
            al[i+1]=0
print(ans)

Measured memory_bytes: 19116
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def solve():
    P, R, T = map(int, readline().split())
    *L, = map(int, readline().split())
    RS = [list(map(int, readline().split())) for i in range(P)]
    LG = [list(map(int, input().split())) for i in range(T)]

    prv = -1
    K = [[0]*R for i in range(P)]
    def check(t):
        nonlocal prv
        if prv < t:
            for i in range(prv+1, t+1):
                p, r = LG[i]
                K[p-1][r-1] += 1
                L[r-1] -= 1
        else:
            for i in range(t+1, prv+1):
                p, r = LG[i]
                K[p-1][r-1] -= 1
                L[r-1] += 1
        S = L[:]; U = [0]*P
        updated = 1
        while updated:
            updated = 0
            for i in range(P):
                if U[i]:
                    continue
                for j in range(R):
                    if RS[i][j] - K[i][j] > max(S[j], 0):
                        break
                else:
                    U[i] = 1
                    for j in range(R):
                        S[j] += K[i][j]
                    updated = 1
        prv = t
        return sum(U) == P

    left = 0; right = T
    while left+1 < right:
        mid = (left + right) >> 1
        if check(mid):
            left = mid
        else:
            right = mid
    if right == T:
        write("-1\n")
    else:
        write("%d\n" % (right+1))
solve()


Measured memory_bytes: 31444
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int dis[1000050];
priority_queue <pii, vector<pii>, greater<pii>> Hx;
int main() {
	int N, i;
	scanf("%d", &N);
	
	memset(dis, 0x3f, sizeof(dis));
	for (i = 1; i <= 9; i++) {
		dis[N*i] = 0;
		Hx.emplace(0, N*i);
	}
	while (!Hx.empty()) {
		pii u = Hx.top();
		Hx.pop();
		if (dis[u.second] != u.first) continue;
		for (i = 0; i < 10; i++) {
			int t = N * i + u.second;
			if (dis[t / 10] > u.first + t % 10) {
				dis[t / 10] = u.first + t % 10;
				Hx.emplace(dis[t / 10], t / 10);
			}
		}
	}
	return !printf("%d\n", dis[0]);
}

Measured memory_bytes: 6388
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int a[N];
map<int,int> mp;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[i] = x;
		mp[x]++;
	}

	long long ans = 0;

	for(auto x : mp) {
		ans += (1ll*x.second*(x.second-1))/2;
	}

	for(int i = 0; i < n; i++) {
		cout << ans - mp[a[i]] + 1 << "\n";
	}




	return 0;
}


Measured memory_bytes: 8320
from math import log2, ceil


class SegmentTree:
    def __init__(self, n):
        tn = 2 ** ceil(log2(n))
        self.a = [2 ** 31 - 1] * (tn * 2)
        self.l = tn * 2
        self.tn = tn

    def find(self, c, l, r, s, t):
        if self.a[c] == -1:
            return self.a[c // 2]
        if s <= l and r <= t:
            return self.a[c]
        mid = (l + r) // 2
        if t <= mid:
            return self.find(c * 2, l, mid, s, t)
        elif s > mid:
            return self.find(c * 2 + 1, mid + 1, r, s, t)
        else:
            return min(
                self.find(c * 2, l, mid, s, mid),
                self.find(c * 2 + 1, mid + 1, r, mid + 1, t))

    def update(self, c, l, r, s, t, x, f=None):

        if f is None and self.a[c] == -1:
            f = self.a[c // 2]

        if l == s and r == t:
            return self.set(c, x)

        mid = (l + r) // 2
        if t <= mid:
            rv, f = self.get_child(c, c * 2 + 1, f)
            u = min(self.update(c * 2, l, mid, s, t, x, f), rv)
        elif s > mid:
            lv, f = self.get_child(c, c * 2, f)
            u = min(lv, self.update(c * 2 + 1, mid + 1, r, s, t, x, f))
        else:
            u = min(
                self.update(c * 2, l, mid, s, mid, x, f),
                self.update(c * 2 + 1, mid + 1, r, mid + 1, t, x, f))
            if f is not None:
                u = min(f, u)
        self.a[c] = u

        return u

    def set(self, c, x):
        self.a[c] = x
        if c * 2 < self.l:
            self.a[c * 2] = self.a[c * 2 + 1] = -1
        return x

    def get_child(self, c, child, f):
        if f is not None:
            return self.set(child, f), f
        v = self.a[child]
        if v == -1:
            f = self.a[c]
            v = self.set(child, f)
        return v, f


n, q = map(int, input().split())
st = SegmentTree(n)
buf = []
for _ in range(q):
    query = input().split()
    if query[0] == '0':
        s, t, x = map(int, query[1:])
        st.update(1, 0, st.tn - 1, s, t, x)
    else:
        s, t = map(int, query[1:])
        buf.append(st.find(1, 0, st.tn - 1, s, t))
        # print(_, query, st.a)
print('\n'.join(map(str, buf)))

Measured memory_bytes: 17856