akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, less<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
//#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[&](auto f,auto... args){return f(f,args...);};

int main(){
    lint n,m,d;
    cin>>n>>m>>d;
    double ans=(d?2.:1.)*max(0LL,n-d)*(m-1)/n/n;
    cout<<ans<<endl;
}


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

import sys

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, is_debug):
		self.debug = is_debug
	def print(self, *arg):
		if self.debug:
			print("logger:", *arg)
	def plane(self, lst, sep=" ", space=0):
		if self.debug:
			longest = space
			for i in range(len(lst)):
				for j in range(len(lst[i])):
					longest = max(longest, len(str(lst[i][j])))
			for i in range(len(lst)):
				for j in range(len(lst[i])):
					print("logger:", " "*(longest-len(str(lst[i][j])))+str(lst[i][j]), end=sep)
				print()

def main():
	h, w = map(int, sys.stdin.readline().split())
	s = [list(sys.stdin.readline().rstrip())[::-1] for i in [0]*h][::-1]
	cost = [[0]*w for i in [0]*h]
	for y in range(h):
		for x in range(w):
			if y == 0 and x == 0:
				if s[y][x] == "#":
					cost[y][x] = 1
			elif y == 0:
				if s[y][x] == "#" and s[y][x-1] != "#":
					cost[y][x] = cost[y][x-1] + 1
				else:
					cost[y][x] = cost[y][x-1]
			elif x == 0:
				if s[y][x] == "#" and s[y-1][x] != "#":
					cost[y][x] = cost[y-1][x] + 1
				else:
					cost[y][x] = cost[y-1][x]
			else:
				if s[y][x] == "#" and s[y-1][x] != "#":
					cost[y][x] = cost[y-1][x] + 1
				else:
					cost[y][x] = cost[y-1][x]
				if s[y][x] == "#" and s[y][x-1] != "#":
					cost[y][x] = min(cost[y][x], cost[y][x-1] + 1)
				else:
					cost[y][x] = min(cost[y][x], cost[y][x-1])
	logger = Logger(0)
	logger.print(h, w)
	print(cost[h-1][w-1])

main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define int long long
#define mod (int)(1e9+7)
#define all(v) v.begin(),v.end()
using namespace std;

template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

int h,w,n;
int trans(int x,int y){
	if(x==0){
		return y;
	}else if(y==w){
		return w+x;
	}else if(x==h){
		return w+h+w-y;
	}
	return h+w*2+h-x;
}
map<int,int>ans;
signed main() {
	cin>>h>>w>>n;
	vector<P>v;
	rep(i,n){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		if((x1==0||x1==h||y1==0||y1==w)&&(x2==0||x2==h||y2==0||y2==w)){
			int p=trans(x1,y1),q=trans(x2,y2);
			if(p>q)swap(p,q);
			ans[p]=q;
			v.push_back({p,1});
			v.push_back({q,-1});
		}
	}
	sort(all(v));
	int now=-1;
	stack<P>st;
	rep(i,v.size()){
		if(st.empty())st.push(v[i]);
		else if(st.top().second==1&&v[i].second==-1){
			P p=st.top();st.pop();
			if(ans[p.first]!=v[i].first){
				cout<<"NO"<<endl;return 0;
			}
		}else {
			st.push(v[i]);
		}
	}
	cout<<"YES"<<endl;
}


Measured memory_bytes: 10860
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int main()
{
  int N,K;
  cin >> N >> K;
  int A[N];
  // 2進表現で1が32回
  ll MAX_SUM = (1LL<<40)-1;

  REP(i,N){
    cin >> A[i];
  }
  int N_PATTERNS = (N*(N+1))/2;
  ll AA[N_PATTERNS];
  REP(i,N_PATTERNS){
    AA[i] = 0LL;
  }

  // 連続する部分列の和
  int cnt = 0;
  REP(i,N){
    REP(j,N){
      if (i<=j){
        for(int index=i;index<=j;index++){
          AA[cnt] +=A[index]; 
        }
        cnt++;
      }
    }
  }


  // REP(i,N_PATTERNS){
  //   cout << AA[i] << endl;
  // }

  // bool dp[MAX_SUM][N_PATTERNS];

  // REP(i,MAX_SUM){
  //   REP(j,N_PATTERNS){
  //     dp[i][j] = false;
  //   }
  // }

  vector<ll> v;
  int keta;
  for(int i=39;i>=0;i--){
    int cnt_exist = 0;
    v.clear();
    REP(j,N_PATTERNS){
      if (AA[j] & 1LL<<i){
        v.push_back(AA[j]);
        cnt_exist++;
      }
    }
    if (cnt_exist >= K){
      keta = i;
      break;
    }
  }

  // REP(i,SZ(v)){
  //   cout << v[i] << endl;
  // }

  vector<ll> vv;

  for(int i=keta-1;i>=0;i--){
    int cnt_exist = 0;
    vv.clear();
    REP(j,SZ(v)){
      if (v[j] & 1LL<<i){
        cnt_exist++;
        vv.push_back(v[j]);
      }
    }
    if (cnt_exist >= K){
      v = vv;
      // cout << "cnt_exist > K" << endl;
    }
    // cout << "i: " << i << endl;
    // REP(j,SZ(vv)){
    //   cout << vv[j] << endl;
    // }
  }

  // cout << "result " << endl;
  ll result = MAX_SUM;
  REP(j,SZ(v)){
    result &= v[j];
    // cout << v[j] << endl;
  }
  cout << result << endl;




  return 0;
}


Measured memory_bytes: 5748
import java.util.Scanner;

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

        if((a+b) % 2 == 0){
            System.out.println((a+b)/2);
        } else{
            System.out.println("IMPOSSIBLE");
        }
    }
}



Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
 string a,b;
 cin>>a>>b;
  rep(i,b.size()){
 cout<<a[i]<<b[i];
  }
  if(a.size()!=b.size())cout<<a[a.size()-1]<<endl;
  else cout<<endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        k: i32,
        n: usize,
        a: [i32; n],
    }

    let mut long = (&a[0] + k - &a[n - 1]).abs();

    for i in 1..n {
        long = if (&a[i] - &a[i - 1]).abs() > long {(&a[i] - &a[i - 1]).abs()} else {long};
    }

    println!("{}", k - long);
}


Measured memory_bytes: 4020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String[] tmpArray = br.readLine().split(" ");
			int numOfMayor = Integer.parseInt(tmpArray[0]);
			int numOfStone = Integer.parseInt(tmpArray[1]);
			
			if(numOfMayor == 0 && numOfStone == 0){
				break;
			}
			
			int bowlPos = 1;
			int[] stone = new int[numOfMayor];
			stone[0] = 1;
			int stoneInBowl = numOfStone - 1;
			
			int i = 0;
			while(true){
//				System.out.println("current position "+bowlPos + " turn "+i);
				if(stoneInBowl > 0){
					stone[bowlPos]++;
					stoneInBowl--;
					if(stone[bowlPos] == numOfStone){
						System.out.println(bowlPos);
						break;
					}
				}
				else if(stone[bowlPos] > 0){
					stoneInBowl += stone[bowlPos];
					stone[bowlPos] = 0;
				}
				bowlPos++;
				bowlPos %= numOfMayor;
				i++;
			}
		}
	}

}

Measured memory_bytes: 24708
#include<stdio.h>
 
struct Card{
  char suit;
  char value;
};
 
int main(){
  struct Card C1[101], C2[101],CC;
  int n, i,j,mini,flag=0;
  char ch;
 
  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
  }
 
  for(i=0;i<n;i++) C2[i]=C1[i];
 
  //BubbleSort
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(C2[j].value < C2[j-1].value){
    CC=C2[j];
    C2[j]=C2[j-1];
    C2[j-1]=CC;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%c%c",C2[i].suit,C2[i].value);
  }
  printf("\n");
 
  printf("Stable\n");
 
  //SelectionSort
  for(i=0;i<=n-1;i++){
    mini=i;
    for(j=i;j<=n-1;j++){
      if(C1[j].value < C1[mini].value){
    mini=j;
      }
    }
    CC=C1[i];
    C1[i]=C1[mini];
    C1[mini]=CC;
  }
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%c%c",C1[i].suit,C1[i].value);
    if(!(C1[i].suit == C2[i].suit && C1[i].value == C2[i].value)) flag = 1;
  }
  printf("\n");
 
  if(flag == 1) printf("Not stable\n");
  else printf("Stable\n");
 
 
 
  return 0;
}

Measured memory_bytes: 612
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define step(n) rep(_, n)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define Unique(a) a.erase(unique(Range(a)), a.end())
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr Type Square(Type x) { return x * x; }
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
void Print() { cout << endl; }
template <class Head, class... Tail> void Print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << ""; Print(forward<Tail>(tail)...); }
template <class T> void Print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void Print(vector<vector<T>> &df) { for (auto& vec : df) { Print(vec); } }

int main()
{
    int N, M; cin >> N >> M;
    vector<int> H(N); for(auto& it : H) { cin >> it; }

    set<int> s;
    rep (i, M)
    {
        int a, b; cin >> a >> b;
        a--; b--; // 0-index

        if (H[a] <= H[b])
        {
            s.insert(a);
        }
        if (H[b] <= H[a])
        {
            s.insert(b);
        }
    }

    Print(N - s.size());

    return 0;
}



Measured memory_bytes: 6428
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
    
    
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] f = new int[n][5];
		double AM = -1;
		double BM = -1;
		double A = -1;
		double B = -1;
		for(int i = 0; i < n; i++) 
			for(int j = 0; j < 5; j++) 
				f[i][j] = sc.nextInt();
		for(int i = 1; i < n; i++) {
			if(f[i-1][2] != f[i][2] || f[i-1][1] == f[i][1]) continue;
			double d = Math.sqrt(Math.pow(f[i][3] - f[i-1][3], 2) + Math.pow(f[i][4] - f[i-1][4], 2));
			double time = f[i][0] - f[i-1][0];
			if(f[i][2] == 0) {
				if(d > AM || (d == AM && time < A)) {
					AM = d;
					A = time;
				}
			}
			else {
				if(d > BM || (d == BM && time < B)) {
					BM = d;
					B = time;
				}
			}
		}
		if(AM == -1) System.out.println(-1 + " " + -1);
		else System.out.printf("%.9f %.9f\n",AM,A/60.0);
		if(BM == -1) System.out.println(-1 + " " + -1);
		else System.out.printf("%.9f %.9f\n",BM,B/60.0);
	}
}

Measured memory_bytes: 28728
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    if (n > m)
        swap(n, m);
    if (n == 1) {
        if (m == 1)
            cout << 1 << "\n";
        else {
            cout << m - 2 << "\n";
        }
        return 0;
    }
    lint ret = (n - 2) * (m - 2);
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(l[K-1])

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

#define INF (1LL<<60)

int N, M, L;

vector<vector<long long>> warshall_floyd(vector<vector<long long>> adjmatrix) {
  int n = adjmatrix.size();
  vector<vector<long long>> dist(adjmatrix);
  for(int k = 0; k < n; ++k)
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        if(dist[i][k]!=INF && dist[k][j]!=INF)
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  return dist;
}


signed main() {
  cin >> N >> M >> L;
  vector<vector<long long>> G1(N, vector<long long>(N, INF));
  for(int i=0; i<M; i++) {
    int a,b,c; cin >> a >> b >> c;
    a--;b--;
    G1[a][b] = c;
    G1[b][a] = c;
  }
  auto d = warshall_floyd(G1);

  vector<vector<long long>> G2(N, vector<long long>(N, INF));
  for(int i=0; i<N; i++) for(int j=0; j<N; j++) {
    G2[i][j] = d[i][j] <= L ? 1 : INF;
  }
  auto dd = warshall_floyd(G2);

  int Q; cin >> Q;
  for(int i=0; i<Q; i++) {
    int s,t; cin >> s >> t; s--; t--;
    cout << (dd[s][t]==INF ? -1 : dd[s][t]-1) << endl;
  }
}


Measured memory_bytes: 5888
#include <stdio.h>

int N,M,K,A[10101],O[101][101];

int main()
{
	scanf ("%d %d %d",&N,&M,&K);
	for (int i=1;i<=K;i++) scanf ("%d",&A[i]);

	int x = 0, y = 0;
	for (int i=1;i<=K;i++){
		while (A[i]--){
			O[x][y] = i;
			if (x % 2 == 0){
				if (y == M-1) x++;
				else y++;
			}
			else{
				if (y == 0) x++;
				else y--;
			}
		}
	}

	for (int i=0;i<N;i++){
		for (int j=0;j<M;j++) printf ("%d%c",O[i][j],j+1<M?' ':'\n');
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	vector<int> a(26,-1);
	vector<int> b(26,-1);
	rep(i,s.size()){
		int x=s.at(i)-'a';
		int y=t.at(i)-'a';
		if(a[x]!=-1 || b[y]!=-1){
			if(a[x]!=y || b[y]!=x){
				cout << "No" << endl;
				return 0;
			}
		}
		else{
			a[x]=y;
			b[y]=x;
		}
	}
	cout << "Yes" << endl;
}

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

int main()
{
    int n,i,j,k,c=0;cin>>n;
    string s;cin>>s;
    for(i=0;i<n;i++)
    {
        if(i+2<n)
        {
            if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
                c++;
        }
    }
    cout<<c;
}


Measured memory_bytes: 256
program sample
  implicit none

  integer(8) :: a,b,c,d,x(0:9)

  

  ! 整数を読み込む
  read(*,*) a,b,c,d
  x(:)=0
  x(a)=x(a)+1
  x(b)=x(b)+1
  x(c)=x(c)+1
  x(d)=x(d)+1
  if(x(1)==1 .and. x(4)==1 .and. x(7)==1 .and. x(9)==1)then
    write(*,*)'YES'
    else
    write(*,*)'NO'
    end if
  

  stop
end program sample


Measured memory_bytes: 2860
#include<stdio.h>
int main(void)
{
   int n;
   int i;
   int a[10000];
   int max;
   int min;
   long int sum=0;
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
      scanf("%d",&a[i]);
   }
   max=min=a[0];
   for(i=0;i<n;i++)
   {
      if(a[i]>max)
      {
         max=a[i];
      }
      else if(a[i]<min)
      {
         min=a[i];
      }
      sum+=a[i];
   }
   printf("%d %d %ld\n",min,max,sum);
   return 0;
}

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

int a[200010];
int ans[200010];
int main(){
  int n;
  cin >> n;
  for(int i=2;i<=n;i++) cin >> a[i];
  for(int i=2;i<=n;i++) ans[a[i]]++;
  for(int i=1;i<=n;i++) cout << ans[i] << endl;
}

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

constexpr long long MOD = 1e9+7;
constexpr int MAX_N = 500000 + 1;
long long fact[MAX_N];
void init_fact() {
    fact[0] = 1;
    for(auto i = 1; i < MAX_N; ++i)
        fact[i] = fact[i-1] * i % MOD;
}

long long pow_mod(long long x, long long y, long long mod) {
    auto ret=1ll;
    while (y) {
            if (y % 2)
                ret = ret * x % mod;
            x =  x * x % mod;
            y /= 2;
        }
    return ret;
}

long long nCr(int n, int r) {
    return fact[n] * pow_mod(fact[n-r], MOD - 2, MOD) % MOD * pow_mod(fact[r], MOD - 2, MOD) % MOD;
}

void solve(int TestCase) {
    init_fact();
    long long n, m;
    cin >> n >> m;
    auto A = vector<long long>(n+1);
    A[n] = 1;
    for(long long i = n-1, j = 0; i >= 0; --i, ++j) A[i] = A[i+1]  * (m - j) % MOD;
    long long ret = A[0] * A[0] % MOD;
    for(auto i = 1; i <= n; ++i) {
        if(i % 2)
            ret = (ret -(nCr(n, i) * A[0] % MOD * fact[m-i] % MOD * pow_mod(fact[m-n], MOD - 2, MOD) % MOD) + MOD) % MOD;
        else
            ret = (ret + (nCr(n, i) * A[0] % MOD * fact[m-i] % MOD * pow_mod(fact[m-n], MOD - 2, MOD) % MOD)) % MOD;
    }
    cout << ret << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 11116
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i32 = read();
    let b :i32= read();
    let k :usize= read();
    let mut r = 0;
    let mut result: Vec<i32> = vec![];

    while r <= a || r <= b {
        r = r + 1;
        if is_r_seigi(a, b, r) {
            result.push(r);
        }
    }

    println!("{}", result[result.len()-k]);
}

fn is_r_seigi(a:i32, b:i32, r:i32) -> bool {
    a % r == 0 && b % r == 0
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int N, K;

bool check(double x, vector<int> A) {
    // x以下の長さに切ることが可能ならtrueを返す
    int cnt = 0;
    rep(i, N) {
        cnt += int((double) A[i] / x + 0.999999999) - 1;
    }
    return cnt <= K;
}

int main() {
    // 二分探索
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    if (K == 0) {
        int x = 0;
        rep(i, N) x = max(x, A[i]);
        cout << x << '\n';
        return 0;
    }
    double ok = 1e9; double ng = 0;
    while (abs(ng - ok) > 0.01) {
        double mid = (ok + ng) / 2;
        if (check(mid, A)) ok = mid;
        else ng = mid;
    }
    int ans = int(ok + 0.99999999);    
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4716
#include<iostream>
using namespace std;
int main()
{
    long long n,i,j;
    cin>>n;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            if(i*j==n)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;

}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int N;
    cin>>N;
    vector<P> task(N);
    rep(i,N)cin>>task.at(i).second>>task.at(i).first;
    sort(task.rbegin(),task.rend());
    ll dl=task.at(0).first;
    rep(i,N){
        if(task.at(i).first<dl){dl=task.at(i).first;}
        dl-=task.at(i).second;
    }
    if(dl<0)cout<<"No"<<endl;
    else{cout<<"Yes"<<endl;}
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <cmath>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;

unsigned nChoosek( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}

double distance2(int* a, int* b, int d)
{
    double sum = 0;
    rep(i, d)
    {
        sum = sum + (b[i] - a[i]) * (b[i] - a[i]);
    }
    sum = sqrt(sum);
    return sum;
}

int main()
{
    int n, d;
    cin >> n >> d;
    int mat[n][d];
    rep(i, n)
    {
        rep(j, d)
        {
            cin >> mat[i][j];
        }
    }
    int counter = 0;
    rep(i, n)
    {
        rep(j, n)
        {
            if (i != j)
            {   double intpart = 0;
               if( modf(distance2(mat[i], mat[j], d), &intpart) == 0)
                {
                    counter += 1;
                }
               }
        }
    }
    cout << counter / 2;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


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

    vector<vector<ll>> nxt(40, vector<ll>(m, 0));
    vector<vector<ll>> s(40, vector<ll>(m, 0));
    REP(y, m){
        nxt.at(0).at(y) = (y * y) % m;
        s.at(0).at(y) = y;
    }

    for(ll i = 1; i < 40; ++i){
        REP(y, m){
            const ll n1 = nxt.at(i - 1).at(y);
            s.at(i).at(y) = s.at(i - 1).at(n1) + s.at(i - 1).at(y);
            nxt.at(i).at(y) = nxt.at(i - 1).at(n1);
        }
    }

    ll ans = 0;
    for(ll i = 0; i < 40; ++i){
        if((n >> i) & 1){
            ans += s.at(i).at(x);
            x = nxt.at(i).at(x);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 66608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

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

int main() {
    // input
    int n;
    cin >> n;
    // solve
    map<string, int> dic;
    int max_c = 0;
    // set<string> ans;
    rep(i, n) {
        string s;
        cin >> s;
        dic[s]++;
        // if (chmax(max_c, dic[s])) {
        //     ans.clear();
        //     ans.insert(s);
        // } else if (dic[s] == max_c) {
        //     ans.insert(s);
        // }
    }
    // output
    // for (string s : ans) {
    //     cout << s << endl;
    // }
    for (auto x : dic) {
        chmax(max_c, x.second);
    }
    for (auto x : dic) {
        if (x.second == max_c) {
            cout << x.first << endl;
        }
    }
}

Measured memory_bytes: 19228
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 200000;

int main() {
	ll n, k;
	cin >> n >> k;
	ll h[N];
	rep(i, n) cin >> h[i];
	sort(h, h + n, greater<ll>());
	ll ans = 0;
	for(int i = k; i < n; i++) {
		ans += h[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  writeln(readln.chomp.to!int^^3);
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var K=Arr.shift()-0;
   if(K==0)break;
   var arr=Arr.shift().split(" ").map(Number);
   var sum=arr.reduce(function(a,b){return a+b;});
   console.log(sum/(K-1));
}

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

int u[25][10];

int main()
{
	int n,i,j,k,id,left,right,countDegree,parent,countDepth,countHeight,countHeight2;
	string root;

	cin >> n;
	for(i=0;i<n;i++)
	{
		u[i][1] = -1 ;
		u[i][2] = -1 ;
	}

	for(i=0;i<n;i++){
		cin >> id >> left >> right;

		u[id][7] = left;
		u[id][8] = right;



		u[left][1] = id;
		u[right][1] = id;

		u[left][2] = right;
		u[right][2] = left;
		
		countDegree = 0;

		if(left != -1)countDegree++;

		if(right != -1)	countDegree++;
		

		u[id][3] = countDegree;

		

		
	}

	
	for(i=0;i<n;i++)
	{
		countDepth=0;
		parent=i;
		while(u[parent][1]!=-1)
		{
			parent = u[parent][1] ;
			countDepth++;
		}
		u[i][4] = countDepth;

		countHeight = 0;
		if(u[i][1]!=-1)
		{
			parent=i;
			while(u[parent][1]!=-1)
			{
				countHeight++;
				parent = u[parent][1];
				if(countHeight>=u[parent][5]) u[parent][5] = countHeight;
			}

			
		}

	}

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

		if(u[i][1]==-1) root = "root";
		if((u[i][1]!=-1)&&(u[i][7]!=-1||u[i][8]!=-1)) root = "internal node";
		if((u[i][1]!=-1)&&(u[i][7]==-1&&u[i][8]==-1)) root = "leaf";


		cout << "node " << i << ':' << " parent = " << u[i][1] << ", sibling = " << u[i][2] << ", degree = " << u[i][3] << ", depth = " << u[i][4] << ", height = " << u[i][5] <<", " << root << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    h,w=map(int,readline().split())

    if h*w%3==0:
        ans=0
    else:
        ans=float("inf")
        #縦方向に全探索
        s1=w//2*h
        s2=h*w-s1
        for i in range(1,h):
            s3=i*w
            s1-=w//2
            s2-=w-w//2
            ans=min(ans,max(s1,s2,s3)-min(s1,s2,s3))

        for i in range(1,h-1):
            s3=i*w
            s1=(h-i)//2*w
            s2=h*w-s3-s1
            ans=min(ans,max(s1,s2,s3)-min(s1,s2,s3))

        #横方向に全探索
        s1=h//2*w
        s2=h*w-s1
        for j in range(1,w):
            s3=j*h
            s1-=h//2
            s2-=h-h//2
            ans=min(ans,max(s1,s2,s3)-min(s1,s2,s3))
        
        for j in range(1,w-1):
            s3=j*h
            s1=(w-j)//2*h
            s2=h*w-s3-s1
            ans=min(ans,max(s1,s2,s3)-min(s1,s2,s3))

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int len=s.length();
    for(int i=0;i<=len;i++)
    {
        if(s[i]=='C')
        {
            for(int j=i;j<=len;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes"<<endl;
                    return 0; 
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

int main()
{
    string s,t;
    cin>>s>>t;
    long long int i,j;
    long long int n=s.size();
    long long int m=t.size();

    long long int dp[n+1][m+1];
    long long int dir[n+1][m+1];

    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            dp[i][j]=0;
            dir[i][j]=-1;
        }
    }

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
                dir[i][j]=2;
            }
            else
            {
                if(dp[i-1][j]>=dp[i][j-1])
                {
                    dp[i][j]=dp[i-1][j];
                    dir[i][j]=1;
                }
                else
                {
                    dp[i][j]=dp[i][j-1];
                    dir[i][j]=0;
                }
            }
        }
    }

    string ans="";

    i=n;
    j=m;

    while(i>0&&j>0)
    {
        if(dir[i][j]==2)
        {
            ans+=s[i-1];
            i--;
            j--;
        }
        else if(dir[i][j]==1)
            i--;
        else
            j--;
    }

    reverse(ans.begin(),ans.end());
    cout<<ans;
}


Measured memory_bytes: 140928
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int ans=0;
    for(int i=1;i<s.size();i++){
        if(s[i]!=s[i-1])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 300005, MAXM = 2003, Mod = 1000000007 , MAXLog = 20;
vector<int> adj[MAXN];
bool vis[MAXN];


int bfs(int s, int t) {
    queue<int> q;
    q.push(s);
    vis[s] = 1;
    int d = 0;
    while(q.size()) {
        int sz = q.size();
        while (sz--) {
            int u = q.front();
            q.pop();
            if (u == t)
                return d;
            for (int v : adj[u]) {
                if (!vis[v]) {
                    vis[v] = 1;
                    q.push(v);
                }
            }
        }
        ++d;
    }
    return -1;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v + n);
        adj[u + n].push_back(v + 2 * n);
        adj[u + 2 * n].push_back(v);
    }

    int s, t;
    cin >> s >> t;
    int ans = bfs(s, t);
    if (ans == -1) {
        cout << -1 << '\n';
        return 0;
    }
    cout << ans / 3 << '\n';


    return 0;
}

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

string S;
int main(){
	cin >> S;
	int N = S.size();
	if(S=="keyence"){
		cout << "YES" << endl;
		return 0;
	}
	for(int i=0;i<N;i++){
		for(int j=i;j<N;j++){
			string T = "";
			for(int k=0;k<N;k++){
				if(k<i || j<k) T = T + S[k];
			}
			if(T=="keyence"){
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MAXN 2000

int N;
LL dp[MAXN + 3][MAXN + 3];
pair<int, int> A[MAXN + 3];

LL solve(int l, int r) {
    if (l > r)
        return 0;

    if (dp[l][r] != -1)
        return dp[l][r];

    int idx = N - (r - l + 1) + 1;
    LL goLeft = (LL) abs(A[idx].second - l) * A[idx].first + solve(l + 1, r);
    LL goRight = (LL) abs(A[idx].second - r) * A[idx].first + solve(l, r - 1);

    return dp[l][r] = max(goLeft, goRight);
}

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        int a;
        cin >> a;

        A[i] = {a, i};
    }

    sort(A + 1, A + N + 1);
    reverse(A + 1, A + N + 1);

    memset(dp, -1, sizeof(dp));

    cout << solve(1, N) << endl;
}


Measured memory_bytes: 35088
(defparameter *ans* 100000)
(defparameter *left-black* 0)
(defparameter *right-white* 0)

(defun solve (rocks)
  (setf *right-white*
        (loop :for rock :across rocks
              :count (char= rock #\.)))
  (setf *ans* (min *ans* (+ *left-black* *right-white*)))
  (loop :for rock :across rocks
        :do
           (if (char= rock #\#) (setf *left-black* (1+ *left-black*)))
           (if (char= rock #\.) (setf *right-white* (1- *right-white*)))
           (setf *ans* (min *ans* (+ *left-black* *right-white*))))
  *ans*)

(defun main ()
  (read)
  (let ((rocks (read-line)))
    (format t "~A~%" (solve rocks))))

(main)


Measured memory_bytes: 18656
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

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

    int minL = 1e9;
    int S = 0;
    for(int i=1; i<=N; i++){
        int l = L + i - 1;
        if(abs(minL) > abs(l)){
            minL = L + i - 1;
        }
        S += l;
    }
    cout << S - minL << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <cassert>
#include <cmath>
using namespace std; typedef long long ll; ll an=0; const ll INF = 1e18; const ll MOD = 1e9+7;
typedef pair<int,int> P;
vector<int> v[50];

void dfs(int x, int y, int r, int c) {
  if (!v[x][y]) return;
  //cout<<"("<<x<<","<<y<<","<<r<<","<<c<<") ";
  v[x][y] = 0;
  for(int p=-1;p<=1;p++) {
    for(int q=-1;q<=1;q++) {
      int f=x+p, g=y+q;
      if (0 <= f && f < c && 0 <= g && g < r && v[f][g]) {
        dfs(f,g,r,c);
      }
    }
  }
}
int main(){
  while(true) {
    int r,c; cin>>r>>c; if (r==0) return 0;
    for(int i=0;i<c;i++) {v[i].clear(); v[i].resize(r);}
    int an=0;
    for(int i=0;i<c;i++) {
      for(int j=0;j<r;j++) {
        int x; cin>>x; v[i][j]=x;
      }
    }
    for(int i=0;i<c;i++) {
      for(int j=0;j<r;j++) {
        if (v[i][j]) {an++, dfs(i,j,r,c);}
      }
    }
    cout<<an<<endl;
  }
}


Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
long long pow2(long long p){
  int ans = 1;
  rep(i,p) ans*=2;
  return ans;
}
int main() {
  cout << fixed << setprecision(10);
  vector<int> a(3);
  int k;
  rep(i,3) cin >> a.at(i);
  cin >> k;
  sort(ALLR(a));
  cout << a.at(0)*pow2(k)+a.at(1)+a.at(2) << endl;
}


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

int main() {
  char c;
  cin >> c;

  if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b<c){
			printf("Yes\n");
		}
		else if(b>c){
			printf("No\n");
		}
	}	else {
		printf("No\n");
	}
	return 0;
}

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

using namespace std;

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

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

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

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

using ll = long long;

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

int n;
string s;
ll dp[MAXN][MAXN];

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

    return true;
}

void solve() {
    dp[1][1] = 1;

    for (int i = 2; i <= n; ++i)
        for (int k = 1; k <= i; ++k) {
            if (s[i - 2] == '<')
                dp[i][k] = dp[i - 1][k - 1];
            else
                dp[i][k] = (INF + dp[i - 1][i - 1] - dp[i - 1][k - 1]) % INF;

            dp[i][k] += dp[i][k - 1];
            dp[i][k] %= INF;
        }

    cout << dp[n][n] << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 69376
#include <iostream>
#include <string>
using namespace std;
  
long long c = 0;
  
void merge(int A[], int left, int mid, int right) {
  int i,j,k;
  
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1];
  int R[n2];
  
  for (i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  
  for (i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = 1000000001;
  R[n2] = 1000000001;
  
  i = 0;
  j = 0;
  for (k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
      c += n1 - i;
    }
  }
}
  
void mergeSort(int A[], int left, int right) {
  int i = 0;
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
  
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  int A[200000];
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  
  mergeSort(A, 0, n);
  
  cout << c <<endl;
  
  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) cin >> s[i][j];
  }
  vector<vector<int>> ue(h, vector<int>(w, 0));
  for (int i = 1; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      if (s[i - 1][j] == '.') ue[i][j] = ue[i- 1][j] + 1;
      else ue[i][j] = 0;
    }
  }
  vector<vector<int>> sita(h, vector<int>(w, 0));
  for (int i = h - 2; i >= 0; i --) {
    for (int j = 0; j < w; j ++) {
      if (s[i + 1][j] == '.') sita[i][j] = sita[i + 1][j] + 1;
      else sita[i][j] = 0;
    }
  }
  vector<vector<int>> migi(h, vector<int>(w, 0));
  for (int i = 0; i < h; i ++) {
    for (int j = w - 2; j >= 0; j --) {
      if (s[i][j + 1] == '.') migi[i][j] = migi[i][j + 1] + 1;
      else migi[i][j] = 0;
    }
  }
  vector<vector<int>> hidari(h, vector<int>(w, 0));
  for (int i = 0; i < h; i ++) {
    for (int j = 1; j < w; j ++) {
      if (s[i][j - 1] == '.') hidari[i][j] = hidari[i][j - 1] + 1;
      else hidari[i][j] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      if (s[i][j] == '#') continue;
      else {
        ans = max(ans, ue[i][j] + sita[i][j] + migi[i][j] + hidari[i][j] + 1);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 67072
#include<iostream>
using namespace std;
int main()
{
	long long int N,k,i,j,ans=0;
  	cin>>N>>k;
  	long long int start_value=0;
      	long long int end_value=0;
      	for(j=0;j<k;j++)
        {
        	start_value+=j;
          	end_value+=N-j;
          
        }
        ans+=end_value-start_value+1;
        start_value+=k;
        end_value=end_value+N-k;
    	 ans=ans%1000000007;
    	 //cout<<start_value<<endl;
    	 //cout<<end_value<<endl;
  	
  	for(i=k+1;i<=N+1;i++)
    {
        ans+=end_value-start_value+1;
    	 ans=ans%1000000007;
    	start_value=start_value+i;
    	end_value=end_value+N-i;
      	
    	 //cout<<start_value<<endl;
    	 //cout<<end_value<<endl;
    	 //cout<<ans<<endl;
    }
   
  	cout<<ans<<endl;


	return 0;
}


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

  int main(){
    int N,K;
    cin >> N >> K;
    int x,s=0;
    for (int i=0;i<N;i++){
      cin >> x;
      s+=2*min(x,K-x);
    }
    cout << s << endl;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	int n;
	cin>>n;
	string a,b,c;
	cin>>a>>b>>c;
	int cnt = 0;
	FOR0(i,n){
		if (a[i]==b[i] && a[i]==c[i]) continue;
		if (a[i]==b[i]||a[i]==c[i]||b[i]==c[i]) cnt++;
		else cnt+=2;
	}
	cout<<cnt;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = 0;
		for (int i = 0; i < b ;i++) {
			c += s.nextInt();
		}

		if(a < c) {
			System.out.println(-1);
		} else {
			System.out.println(a - c);
		}

	}

}


Measured memory_bytes: 46228
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,k,x,y;
  cin>>n;
  cin>>k;
  cin>>x;
  cin>>y;
  cout<<min(k,n)*x+max(n-k,0)*y<<endl;
  return 0;
}



Measured memory_bytes: 256
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson (curpos<<1)
#define rson (curpos<<1|1)
/* namespace */
using namespace std;
/* header end */

const int maxn = 1e5 + 10;
// const int maxn = 5;
struct Job {
    int earn, wait;
    bool operator<(const Job &rhs)const {
        if (wait != rhs.wait) return wait < rhs.wait;
        else return earn > rhs.earn;
    }
} a[maxn];
int n, m, tot = 0, p = 0;
ll ans = 0;

int main() {
    scanf("%d%d", &n, &m);
    rep1(i, 1, n) {
        int earn, wait; scanf("%d%d", &wait, &earn);
        if (wait > m) continue;
        a[++tot].wait = wait; a[tot].earn = earn;
    }
    int p = 0;
    sort(a + 1, a + 1 + tot);
    priority_queue<int>q;
    while (!q.empty()) q.pop();
    for (int reDay = 1; reDay <= m && p <= tot; reDay++) {
        while (p < tot && a[p + 1].wait <= reDay) {
            p++; q.push(a[p].earn);
        }
        if (!q.empty()) ans += (ll)q.top();
        if (!q.empty()) q.pop();
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000



int main(){
	
	int N;
	cin>>N;
	
	long long T;
	cin>>T;
	
	vector<long long> t(N);
	
	for(int i=0;i<N;i++){
		cin>>t[i];
	}
	t.push_back(Inf);
	
	long long ans = 0;
	
	for(int i=0;i<N;i++){
		ans += min(T,t[i+1]-t[i]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 4480