akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, K;
  std::cin >> N >> K;

  std::map< ll, ll > ma;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
    ma[va[i]]++;
  }

  std::vector<ll> vv;
  for (auto p : ma) {
    vv.push_back(p.second);
  }

  std::sort(vv.begin(), vv.end());

  ll ans = 0LL;
  for (ll i = 0; i < (ll)vv.size() - K; i++) {
    ans += vv[i];
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 16500
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ll long long
#define N 100050
#define res register int
using namespace std;
int head[N*2],n,m,k,tot;
int a[N],ans;

struct data{
    int to,nxt;
}edge[N*2];

inline void add(int x,int y)
{
    edge[++tot].to=y;
    edge[tot].nxt=head[x];
    head[x]=tot;
}

inline int dfs(int root,int deth)
{
    int p=deth;
    for(res i=head[root];i;i=edge[i].nxt)
    p=max(p,dfs(edge[i].to,deth+1));
    if(a[root]!=1&&p-deth==m-1) return ans++,0;
    else return p;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(res i=1;i<=n;i++)
    scanf("%d",&a[i]);

    if(a[1]!=1)
    {
        a[1]=1;
        ans=1;
    }

    for(res i=2;i<=n;i++)
    add(a[i],i);

     dfs(1,0);
     printf("%d",ans);
}

Measured memory_bytes: 4608
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775808;

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

int main() {
    int N, K;
    cin >> N >> K;
    int a[N];
    int max = intmin;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if(max < a[i]) {
            max = a[i];
        }
    }
    int g = a[0];
    for (int i = 1; i < N; i++) {
        g = gcd(g, a[i]);
    }
    if (K <= max && K % g == 0) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<vector> 
#include<queue>
#include<string.h>
using namespace std;

const int N=100005;
int INF=0x3f3f3f3f;
int n,m;
struct Edge
{
	int from,to,dis;
};

struct node 
{
	int u,d;
	bool operator < (const node &a) const 
	{
	  return d > a.d;
	}
};

vector<Edge>  edge;
vector<int> g[N];
vector<int> gg[N];
int dis[N];
int vis[N];
int pre[N];
int col[N];
void addedge(int u,int d,int dis)
{
   edge.push_back((Edge){u,d,dis});
   int s=edge.size();
   s--;
   g[u].push_back(s);
}

void dij(int s)
{
   priority_queue<node> q;
   memset(dis,INF,sizeof(dis));
   memset(vis,0,sizeof(vis));
   q.push((node){s,0});
   dis[s]=0;
   while(!q.empty())
   {
   	node x=q.top();
   	int u=x.u;
   	q.pop();
   	if(vis[u]==1)continue;
   	vis[u]=1;
   	for(int i=0;i<g[u].size();i++)
   	{
   		Edge e=edge[g[u][i]];
   	    if(dis[e.to]>dis[u]+e.dis)
		   {
		   	dis[e.to]=dis[u]+e.dis;
		   	pre[e.to]=u;
		   	q.push((node){e.to,dis[e.to]});
		}	
	}
   }	
}
int sum;
void dfs(int u,int fa)
{
	int l=gg[u].size();
	if(col[u]==1)return ;
	//printf("u %d\n",u);
	sum++;
	for(int i=0;i<l;i++)
	{
		int v=gg[u][i];
		if(v==fa)continue;
		dfs(v,u);
	}
	return;
}

int main()
{
	while(~scanf("%d",&n))
	{
		edge.clear();
		for(int i=0;i<=n;i++)g[i].clear();
		for(int i=1;i<=n-1;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			addedge(u,v,1);
			addedge(v,u,1);
			gg[u].push_back(v);
			gg[v].push_back(u);
		}
		for(int i=1;i<=n;i++)pre[i]=i;
		dij(1);
		int x=n;
		int dd=dis[n]+1;
		//printf("%d\n",dd);
		memset(col,0,sizeof(col));
		for(int i=1;i<=dd/2;i++)
		{
			//printf("x %d\n",x);
			col[x]=1;
			x=pre[x];
		}
		sum=0;
		dfs(1,-1);
		//printf("%d\n",sum);
		if(sum>n-sum)printf("Fennec\n");
		else printf("Snuke\n");
	}
	return 0;
}

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

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

	int r, c;
	int sum = 0;
	int all = 0;
	cin >> r >> c;
	vector<vector<int>> v(r, vector<int>(c));
	rep(i, r){
		rep(j, c){//column
			cin >> v[i][j];
			sum += v[i][j];
			cout << v[i][j] << ' ';
		}
		cout << sum << '\n';
		all += sum;
		sum = 0;
	}
	rep(i, c){
		rep(j, r){//row
			sum += v[j][i];//sum of row
		}
		cout << sum << ' ';
		sum = 0;
	}
	cout << all << '\n';//migisita

	return 0;
}


Measured memory_bytes: 3156
void main()
{
    long a;
    string b;
    rdVals(a, b);

    long[] list;
    foreach (x; b)
    {
        if (x.isNumber)
        {
            list ~= x - '0';
        }
    }

    long[] num = new long[list.length];
    foreach (i, x; list)
    {
        num[i] = a * x;
    }

    long result;
    foreach (i, x; num)
    {
        result += x * 10L^^(2-i);
    }

    result /= 100;

    result.writeln;
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 2768
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;


int main(){

  int n,m,a[1000],b[1000],c[1000],dist[100][100];
  cin >> n>> m;
  
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
     
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j){
      dist[i][j] = 0;
      }
      else{
        dist[i][j] = 1000000007;
      }
    }
  }
  
  
  for(int i=0;i<m;i++){
    
      dist[a[i]][b[i]] = min(dist[a[i]][b[i]],c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]],c[i]);
    
  }
  
 
  for (int k = 0; k < n; k++){       
    for (int i = 0; i < n; i++) {    
      for (int j = 0; j < n; j++) {  
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans =0;
  for(int i=0;i<m;i++){
    bool ant = false;
    for(int j=0;j<n;j++){
    if(dist[j][a[i]] == dist[j][b[i]]-c[i]){
      ant = true;
    }
    }
      if(ant){
        ans++;
      }
    
  }
  
  cout << m-ans << endl;
}
  
  
  
  
  
  


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a[100][100],b[100],n,m,sum,i,j;

  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++) for(j=0;j<m;j++) scanf("%d",&a[i][j]);

  for(i=0;i<m;i++) scanf("%d",&b[i]);
  for(i=0;i<n;i++){
    for(sum=0,j=0;j<m;j++) sum+=(a[i][j]*b[j]);
    printf("%d\n",sum);
  }

  return 0;
}

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

public class Main {
	
	int count = 0;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt();
		for(int x = 0; x <= N; x++) {
			for(int y = 0; y <= N-x; y++) {
				int z = N - x - y;
				count = x*10000 + 5000*y + 1000*z;
				if(count == Y) {
					System.out.println(x + " " + y + " " + z);
					sc.close();
					return;
				}
			}
		}
		System.out.println("-1 -1 -1");
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23636
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	ll N, D;
	cin >> N >> D;

	int cnt = 0;
	for (int i=0; i<N; i++) {
		ll X, Y;
		cin >> X >> Y;
		if (X*X + Y*Y <= D*D) cnt++;
	}

	ll ans = cnt;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
int main(void) {
	char S[10];
	scanf("%s", S);
	if (strcmp(S, "Sunny") == 0) printf("Cloudy");
	else if (strcmp(S, "Cloudy") == 0) printf("Rainy");
	else if (strcmp(S, "Rainy") == 0) printf("Sunny");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
const int N=200010;
const int mod=1e9+7;

int h,w,a,b;
int fac[N],fnv[N];
ll ans;
ll quickmod(ll x,ll y)
{
    ll ans=1;
    for(;y;y>>=1)
    {
        if(y&1) ans=ans*x%mod;
        x=x*x%mod;
    }
    return ans;
}

void build()
{
    fac[0]=1;
    for(int i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%mod;
    fnv[N-1]=quickmod(fac[N-1],mod-2);
    for(int i=N-2;i>=0;i--) fnv[i]=1ll*fnv[i+1]*(i+1)%mod;
}

ll C(int x,int y)
{
    if(x<y) return 0;
    return 1ll*fac[x]*fnv[y]%mod*fnv[x-y]%mod;
}

int main()
{
    build();
    scanf("%d%d%d%d",&h,&w,&a,&b);
    for(int i=b+1;i<=w;i++)
    {
        ans=(ans+C(h-a-2+i,i-1)*C(a-1+w-i,w-i)%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
using ll = long long;
long long MOD = 1e9 + 7;
constexpr long long INF = numeric_limits<ll>::max();
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<ll, ll> pp;
#define rep(i,n) for(ll i=0;i<n;i++)
inline void YN(bool f) {cout<<(f?"YES":"NO")<<endl;}
inline void yn(bool f) {cout<<(f?"Yes":"No")<<endl;}
int d[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
// 여기까지 template
struct BIT {
	int bit[200100];
	void reset(bool b = 0) {
		rep(i, 200100)bit[i] = (!b?0:INF); 
	}
	void add(ll n, ll p) {
		while (p < 200100) {
			bit[p] += n;
			p += p & -p;
		}
	}
	ll sum(ll p) {
		ll n = 0;
		while (p > 0) {
			n += bit[p];
			p -= p & -p;
		}
		return n;
	}
};
ll n,k,v[2010],sum,sum2;
void solve(){
	BIT b;
	b.reset();
	cin>>n>>k;
	rep(i,n){
		cin>>v[i];
		b.add(1,v[i]);
		sum+=i+1-b.sum(v[i]);
	}
	rep(i,n){
		rep(j,n){
			if(i==j)continue;
			if(v[i]<v[j])++sum2;
		}
	}
	cerr<<sum<<" "<<sum2<<endl;
	cout<<(((sum*k)%MOD)+((sum2*((k*k-k)/2%MOD))%MOD))%MOD<<endl;
}
int main(){
	solve();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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(){
    int N;
    cin >> N;
    bool ans=false;
    for (int i=1;i<10;i++){
        for (int j=1;j<10;j++){
            if (i*j==N){
                ans=true;
            }
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;
//A 65
//a 97


int main(){
  int n,m;cin>>n>>m;
  VD A(n);
  double sum=0;
  REP(i,n){
    cin>>A[i];
    sum+=A[i];
  }
  int count =0;
  REP(i,n){
    if(A[i]>=double(sum/(4*m))){
      count++;
    }
  }
  if(count>=m){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 888
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

void rotation(int *d,int i,int j,int k,int l)
{
	int a = d[i];
	d[i] = d[j];
	d[j] = d[k];
	d[k] = d[l];
	d[l] = a;
}

int main()
{
	int n;
	while (1) {
		cin >> n;
		if (n == 0)break;
		
		int num = 1;
		int dice[6] = { 1,2,3,4,5,6 };
		for (int i = 0; i < n; i++) {
			string str;
			cin >> str;
			if (str == "North") {
				rotation(dice, 0, 1, 5, 4);
			}
			else if (str == "East") {
				rotation(dice, 0, 3, 5, 2);
			}
			else if (str == "West") {
				rotation(dice, 0, 2, 5, 3);
			}
			else if (str == "South") {
				rotation(dice, 0, 4, 5, 1);
			}
			else if (str == "Right") {
				rotation(dice, 1, 2, 4, 3);
			}
			else if (str == "Left") {
				rotation(dice, 1, 3, 4, 2);
			}
			num += dice[0];
		}
		cout << num << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3188
#include <stdio.h>

#define H 2000000

int left(int i) { return i * 2; }
int right(int i) { return i * 2 + 1; }

int n, A[H + 1];

void maxHeapify(int i) {
	int l, r, largest, tmp;

	l = left(i);
	r = right(i);
	if (l <= n && A[l] > A[i]) largest = l;
	else largest = i;
	if (r <= n && A[r] > A[largest]) largest = r;


	if (largest != i) {
		tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;
		maxHeapify(largest);
	}
}

int extract() {
	int max;
	max = A[1];
	A[1] = A[n];
	n--;
	maxHeapify(1);
	return max;
}

void inc(int i, int key) {
	int tmp;
	if (key < A[i]) return;
	A[i] = key;
	while (i > 1 && A[i / 2] < A[i]) {
		tmp = A[i];
		A[i] = A[i / 2];
		A[i / 2] = tmp;
		i = i / 2;
	}
}

void insert(int k) {
	n++;
	A[n] = -100000000;
	inc(n, k);
}

int main() {

	int i=1, j,k;
	char com[10];

	while (1) {
		scanf("%s", com);
		if (com[2] == 'd') break;
		else if (com[0] == 'i') {
			scanf("%d", &k);
			insert(k);
		}
		else {
			printf("%d\n",extract());
			i--;
		}
	
	}
	
	return 0;
}



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

using namespace std;
using ii = pair<int, int>;

vector<int> solve(int N, int Q, const string& S, const vector<ii>& qs)
{
    vector<int> xs(N + 1, 0), ps(N + 1, 0);

    for (int i = 1; i < N; ++i)
        if (S[i - 1] == 'A' and S[i] == 'C')
            xs[i + 1] = 1;

    for (int i = 1; i <= N; ++i)
        ps[i] = ps[i - 1] + xs[i];

#ifdef DEBUG
    cout << "S = " << S << '\n';

    cout << "xs = ";
    for (int i = 1; i <= N; ++i)
        cout << xs[i] << (i == N ? '\n' : ' ');

    cout << "ps = ";
    for (int i = 1; i <= N; ++i)
        cout << ps[i] << (i == N ? '\n' : ' ');
#endif

    vector<int> ans(Q);

    for (int i = 0; i < Q; ++i)
    {
        auto L = qs[i].first;
        auto R = qs[i].second;

        ans[i] = ps[R] - ps[L];
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    vector<ii> qs(Q);

    for (int i = 0; i < Q; ++i)
        cin >> qs[i].first >> qs[i].second;

    auto ans = solve(N, Q, S, qs);

    for (auto x : ans)
        cout << x << '\n';

    return 0;
}


Measured memory_bytes: 2384
x, k, d = map(int, input().split())

r, s = divmod(x, d)
if r < 0:
    r = abs(r)
    if k < r:
        print(abs(x + k * d))
    elif r%2 == k%2:
        print(s)
    elif r%2 != k%2:
        print(abs(s-d))
else:
    if k <= r:
        print(abs(x - k * d))
    elif r%2 == k%2:
        print(s)
    elif r%2 != k%2:
        print(abs(s-d))

Measured memory_bytes: 9168
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
v = [[] for _ in range(N)]
for _ in range(N-1) :
    a, b = map(int, input().split())
    v[a-1].append(b-1)
    v[b-1].append(a-1)
    
pq = [0 for _ in range(N)]
for _ in range(Q) :
    p, q = map(int, input().split())
    pq[p-1] += q
    
visited = [False] * N
visited[0] = True

ret = [0] * N
def bfs(cur, score) :
    ret[cur] = score + pq[cur]
    for nex in v[cur] :
        if not visited[nex] :
            visited[nex] = True
            bfs(nex, ret[cur])

bfs(0, 0)
    
print(*ret)

Measured memory_bytes: 238524
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      ArrayList<String> s = nextCharArray();
      int output = 0;
      for(int i = 0; i < N - 2; i++){
        if(s.get(i).equals("A") && s.get(i + 1).equals("B") && s.get(i + 2).equals("C")){
          output++;
        }
      }
      myout(output);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33188
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};


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

    ll a,b,c,d,n,maxi=0,f=0,mini=INF,sum=0;
    ll h,w;
    ll m;
    cin>>n>>m;
    c=0;
    d=INF;
    rep(i,m){
        cin>>a>>b;
        if(c<a) c=a;
        if(d>b) d=b;
    }
    if(d-c<0) cout<<0<<endl;
    else cout<<d-c+1<<endl;


}


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

const int END = -1;
struct StNod
{
  int m_nDept;
  int m_nHigh;
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
    m_nDept(END), m_nHigh(END), m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

void fnInput(vector<StNod>& rvoNod)
{
  StNod oNod;
  int nMaxSiz;

  cin >> nMaxSiz;
  rvoNod.resize(nMaxSiz, oNod);

  for (int i = 0; i < nMaxSiz; i++)
  {
    int nParnt, nLeft, nRigt;
    cin >> nParnt >> nLeft >> nRigt;

    rvoNod[nParnt].m_nLeft = nLeft;
    rvoNod[nParnt].m_nRigt = nRigt;
    if (nLeft != END)  rvoNod[nLeft].m_nParnt = nParnt;
    if (nRigt != END)  rvoNod[nRigt].m_nParnt = nParnt;
  }
}

void fnSetDepth(vector<StNod>& rvoNod, int nx, int nDept)
{
  rvoNod[nx].m_nDept = nDept;
  
  if (rvoNod[nx].m_nLeft != END)
    fnSetDepth(rvoNod, rvoNod[nx].m_nLeft, nDept + 1);

  if (rvoNod[nx].m_nRigt != END)
    fnSetDepth(rvoNod, rvoNod[nx].m_nRigt, nDept + 1);
}

int fnSetHight(vector<StNod>& rvoNod, int nx)
{
  int nLHigh = 0, nRHigh = 0;

  if (rvoNod[nx].m_nLeft != END)
    nLHigh = fnSetHight(rvoNod, rvoNod[nx].m_nLeft) + 1;
  if (rvoNod[nx].m_nRigt != END)
    nRHigh = fnSetHight(rvoNod, rvoNod[nx].m_nRigt) + 1;
  
  return rvoNod[nx].m_nHigh = max(nLHigh, nRHigh);
}

void fnBinTree(vector<StNod>& rvoNod)
{
  int nx = 0;
  while (rvoNod[nx].m_nParnt != END)
    nx = rvoNod[nx].m_nParnt;

  int nDept = 0;
  fnSetDepth(rvoNod, nx, nDept);
  fnSetHight(rvoNod, nx);
}

void fnResult(const vector<StNod>& cnrvoNod)
{
  for (int i = 0; i < cnrvoNod.size(); i++)
  {
    cout << "node " << i << ": parent = " << cnrvoNod[i].m_nParnt << ", sibling = ";

    if (cnrvoNod[i].m_nParnt == END)  cout << END;
    else
    {
      int nx = cnrvoNod[i].m_nParnt;
      if (i == cnrvoNod[nx].m_nLeft)  cout << cnrvoNod[nx].m_nRigt;
      else                            cout << cnrvoNod[nx].m_nLeft;
    }
    
    cout << ", degree = ";
    int nCCnt = 0;
    if (cnrvoNod[i].m_nLeft != END)  nCCnt++;
    if (cnrvoNod[i].m_nRigt != END)  nCCnt++;
    cout << nCCnt << ", depth = " << cnrvoNod[i].m_nDept << ", height = " << cnrvoNod[i].m_nHigh;

    if (!cnrvoNod[i].m_nDept)       cout << ", root";
    else if (!cnrvoNod[i].m_nHigh)  cout << ", leaf";
    else                            cout << ", internal node";
    cout << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StNod> voNod;

  fnInput(voNod);
  fnBinTree(voNod);
  fnResult(voNod);
  return 0;
}

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

int main() {
    int a, b, k;
    vector<int> ans;
    cin >> a >> b >> k;
    int n = max(a, b);
    rep2(i, n) {
        if (a % i == 0 && b % i == 0) {
            ans.push_back(i);
        }
    }

    cout << ans[ans.size() - k] << endl;
    return 0;
}

Measured memory_bytes: 3640
//Frog 2

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
using ll = long long;
#define range(a) (a).begin(),(a).end()
const int inf = 1000000000;

int main (){
    int N,K,minc;cin >> N >> K;
    vector<int> h(N+K);
    rep(i,K-1,N+K-1)cin >> h[i];
    vector<int> Ans(N+K);
    Ans[K-1]=0;
    rep(i,0,K-1){
        h[i]=inf;
        Ans[i]=inf;
    }
    rep(i,K,N+K-1){
        minc=inf;
        rep(j,i-K,i){
            minc = min(minc,abs(h[j]-h[i])+Ans[j]);
        }
        Ans[i]=minc;
    }
    cout << Ans[N+K-2] << endl;
    return 0;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define   PI    acos(-1)
int fx[]={0,1,0,-1};
int fy[]={-1,0,1,0};

int main()
{
    ll n,i,j,cnt=0,c=0,res,ans,test,ca;
    string s,s1;
    cin>>n>>ca;
    cout<<(abs(n-ca)+1)<<endl;
    return 0;
}



Measured memory_bytes: 256
N=int(input())

mod=10**9+7

FACT=[1]
for i in range(1,10**6+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(10**6,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0

ANS=0
MINUS=0

def k_perm(k):
    return Combi(k-1,N-k-1)*FACT[k]*FACT[N-k-1]%mod

for k in range(N//2,N):
    ANS=(ANS+(k_perm(k)-k_perm(k-1))*k)%mod

print(ANS)

Measured memory_bytes: 82224
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;

ll num(ll a){
    ll ans = 1;
    for(int i = 0; i < a ; i++){
        ans *= 10;
        ans += 1;
    }
    return ans;
}

int main() {
    ll K;
    cin >> K;
    ll ans = 0;
    ll s = 0;
    for(int i = 1; i < 1000000; i++){
        s = (s * 10 + 7);
        s %= K;
        if(s == 0){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define N 21

using namespace std;
int n, A[N][N], F[N][1<<21], d[N][1<<21];

long long Magic(int i, int check)
{
    if(i==n) return 1;
    if(d[i][check]) return F[i][check]; d[i][check]=1;
    long long res = 0;
    for(int j=0; j<n; j++)
    {
        if((check>>j)&1) continue;
        if(A[i][j])
            res = (res+Magic(i+1, check^(1<<j)))%1000000007;
    }
    return F[i][check]=res;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            cin>>A[i][j];
    cout<<Magic(0, 0);
    return 0;
}


Measured memory_bytes: 183680
#include "bits/stdc++.h"

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n,k,ans;
vector<int>v[100010];

void dfs(int now,int cnt){
	if(cnt==k){
		ans++;
		return;
	}
	for(int u:v[now]){
		dfs(u,cnt+1);
	}
	return;
}

void input(){
	cin>>n>>k;
	return;
}

void solve(){
	for(int i=2;i<=n;i++){
		v[i].eb(1);
	}
	for(int i=2;i<=n;i++){
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0){
				v[i].eb(j);
				if(i/j!=j)v[i].eb(i/j);
			}
		}
	}
	for(int i=1;i<=n;i++){
		dfs(i,1);
	}
	cout<<ans<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}


Measured memory_bytes: 13144
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Coer
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[][] v = new int[n + 1][3];
            for (int i = 1; i < n + 1; i++) {
                v[i][0] = in.nextInt();
                v[i][1] = in.nextInt();
                v[i][2] = in.nextInt();
            }
            int[][] dp = new int[n + 1][3];
            for (int i = 0; i < 3; i++) {
                dp[1][i] = v[1][i];
            }
            for (int i = 2; i < n + 1; i++) {
                for (int cur = 0; cur < 3; cur++) {
                    for (int pre = 0; pre < 3; pre++) {
                        if (pre != cur) {
                            dp[i][cur] = Math.max(dp[i][cur], dp[i - 1][pre] + v[i][cur]);
                        }
                    }
                }
            }
            out.println(Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2])));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 49624
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int a, b;
	cin >> a >> b;
	if (a == 1) a = 14;
	if (b == 1) b = 14;
	cout << (a > b ? "Alice" : a < b ? "Bob" : "Draw") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#pragma warning (disable: 4996)

int H1, M1, H2, M2, K;

int main() {
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int S1 = H1 * 60 + M1;
	int S2 = H2 * 60 + M2;
	cout << S2 - S1 - K << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    int p[n]; rep(i,n) cin>>p[i];
    sort(p,p+n);
    int ans=0;
    rep(i,n){
        if(i!=n-1) ans+=p[i];
        else ans+=p[i]/2;
    }
    cout<<ans<<endl;
    return 0;
}


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

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

long long N;
long long a[3], b[3];

long long calc(vector<long long> sei, vector<long long> obj, long long M) {
    if (sei.size() == 0) return M;
    if (sei.size() == 1) {
        long long rem = M;
        long long p = rem / sei[0];
        long long r = rem % sei[0];
        return p * obj[0] + r;
    }
    if (sei.size() == 2) {
        long long res = M;
        for (long long x = 0; x * sei[0] <= M; ++x) {
            long long rem = M - x * sei[0];
            long long p = rem / sei[1];
            long long r = rem % sei[1];
            chmax(res, x * obj[0] + p * obj[1] + r);
        }
        return res;
    }
    if (sei.size() == 3) {
        long long res = M;
        for (long long x = 0; x * sei[0] <= M; ++x) {
            for (long long y = 0; x * sei[0] + y * sei[1] <= M; ++y) {
                long long rem = M - x * sei[0] - y * sei[1];
                long long p = rem / sei[2];
                long long r = rem % sei[2];
                chmax(res, x * obj[0] + y * obj[1] + p * obj[2] + r);
            }
        }
        return res;
    }
    return M;
}

long long solve() {
    // zenhan
    {
        vector<long long> sei, obj;
        for (int i = 0; i < 3; ++i) {
            if (a[i] < b[i]) {
                sei.push_back(a[i]);
                obj.push_back(b[i]);
            }
        }
        N = calc(sei, obj, N);
    }

    // kouhan
    {
        vector<long long> sei, obj;
        for (int i = 0; i < 3; ++i) {
            if (a[i] > b[i]) {
                sei.push_back(b[i]);
                obj.push_back(a[i]);
            }
        }
        N = calc(sei, obj, N);
    }
    return N;
}

int main() {
    while (cin >> N) {
        for (int i = 0; i < 3; ++i) cin >> a[i];
        for (int i = 0; i < 3; ++i) cin >> b[i];
        cout << solve() << endl;
    }
}















Measured memory_bytes: 256
#include <stdio.h>

int min(int *lst, int N) {
  int i = 0;
  int m = 1000000000;
  for(i =0; i < N; i++) {
    if(m > lst[i]) {
      m = lst[i];
    }
  }
  return m;
}

int sum(int *lst, int N) {
  int i = 0;
  int sum = 0;
  for(i =0; i < N;i++) {
    sum += lst[i];
  }
  return sum;
}

int main(void) {
  int i;
  int ans = 0;
  int N,X;
  int m[128];

  scanf("%d %d", &N, &X);

  for(i = 0; i < N; i++) {
    scanf("%d", &m[i]);
  }

  ans = N + ((X-sum(m,N)) / min(m,N));

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
using namespace std;

int main(){
  int n;
  cin >> n;
  string s[n];
  REP(i,n) cin >> s[i];
  sort(s,s+n);
  
  int sum = 1;
  int max_num = 0;
  FOR(i,1,n){
    if(s[i-1] == s[i]) sum++;
    else{
      max_num = max(sum,max_num);
      sum = 1;
    }
  }
  max_num = max(sum,max_num);
  
  sum = 1;
  if(max_num != 1){
    FOR(i,1,n){
      if(s[i-1] == s[i]){
        sum++;
        if(sum == max_num) cout << s[i] << endl;
      }
      else sum = 1;
    }
  }
  else{
    REP(i,n) cout << s[i] << endl;
  }
  
  //cout << max_num;
  return 0;
}

Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
for(char ch='a';ch<='z';ch++)
{
if(s1+ch==s2)
    {cout<<"Yes";
    return 0;
    }
}
cout<<"No\n";
return 0;
}



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

int main(){
    int a,b;
    char op;
    
    while(1){
        cin >> a >> op >> b;
        if ( op == '?') break;
        
        if ( op == '+') cout << a + b << endl;
        else if ( op == '-') cout << a - b << endl;
        else if ( op == '*') cout << a * b << endl;
        else if ( op == '/') cout << a / b << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
package main

import "fmt"

func main() {
	var n, m, c int
	var ans = 0
	fmt.Scan(&n, &m, &c)
	b := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&b[i])
	}
	a := make([]int, m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Scan(&a[j])
		}

		sum := 0
		for k, _ := range a {
			sum += a[k] * b[k]
		}
		if sum+c > 0 {
			ans++
		}

	}
	fmt.Println(ans)
}


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

#define DBG1(a)         cerr<<#a<<":"<<(a)<<'\n'
#define DBG2(a,b)       cerr<<#a<<":"<<(a)<<"  "<<#b<<":"<<(b)<<'\n'
#define DBG3(a,b,c)     cerr<<#a<<":"<<(a)<<"  "<<#b<<":"<<(b)<<"  "<<#c<<":"<<(c)<<'\n'
#define DBG4(a,b,c,d)   cerr<<#a<<":"<<(a)<<"  "<<#b<<":"<<(b)<<"  "<<#c<<":"<<(c)<<"  "<<#d<<":"<<(d)<<'\n'
#define DBGARR(a,n,t)   cerr<<#a<<": "; copy(a,a+n,ostream_iterator<t>(cerr," " )); cerr<<'\n'
#define DBGVEC(a,t)     cerr<<#a<<": "; copy(a.begin(),a.end(),ostream_iterator<t>(cerr," " )); cerr<<'\n'

using namespace std;

const int N = 3e3 + 3, MOD = 1e9 + 7;
int n, dp[N][N];
char s[N];

/**
int mem[N][N];
int solve(int i, int up){
    if(i == n) return mem[i][up] = 1;

    int& ret = mem[i][up];
    if(~ret) return ret;

    ret = 0;
    int down = n - (i + up);
    if(s[i] == '<' && up) for(int l = 1; l <= up; ++l){
        ret += solve(i + 1, up - l);
        if(ret >= MOD) ret -= MOD;
    }
    else if(s[i] == '>' && down) for(int l = 0; l < down; ++l){
        ret += solve(i + 1, up + l);
        if(ret >= MOD) ret -= MOD;
    }
    return ret;
}
**/

int main()
{
    s[0] = '<';
    scanf("%d %s", &n, s + 1);
    dp[n][0] = 1;
    for(int i = n - 1; ~i; --i){
        for(int up = 0; up <= n; ++up){
            int down = n - (up + i);
            if(down < 0) continue;
            if(s[i] == '<' && up){
                dp[i][up] = dp[i + 1][up - 1];
            }
            else if(s[i] == '>' && down){
                dp[i][up] = dp[i + 1][up + down - 1] - (up? dp[i + 1][up - 1] : 0) + MOD;
                if(dp[i][up] >= MOD) dp[i][up] -= MOD;
            }
            if(up){
                dp[i][up] += dp[i][up - 1];
                if(dp[i][up] >= MOD) dp[i][up] -= MOD;
            }
        }
    }
    int ans = dp[0][n] - dp[0][n - 1] + MOD;
    if(ans >= MOD) ans -= MOD;
    printf("%d\n", ans);


//    memset(mem, -1, (n + 3) * sizeof mem[0]);
//    printf("%d\n", solve(0, n));
    return 0;
}


Measured memory_bytes: 35200
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string divide[4] = {"dream", "dreamer", "erase", "eraser"};
int main(){
  string s;
  cin>>s;
  reverse(s.begin(), s.end());
  for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

  for(int i=0;i<s.size();){
    bool can=false;
    for(int k=0;k<4;k++){
      string d=divide[k];
      if(s.substr(i,d.size())==d){
        can=true;
        i+=d.size();
      }
    }
    if(!can){ cout<<"NO"; return 0; }
  }
  cout<<"YES";


}


Measured memory_bytes: 512
INF = 10**10
v, e = map(int, input().split())
dis = [[INF]*v for _ in range(v)]

for i in range(e):
    frm, to, d = map(int, input().split())
    dis[frm][to] = d
  
mem = {}
end = 2**v-1

def minCost(state, pos):
    if state==end:
        return dis[pos][0]
    
    if (state,pos) in mem:
        return mem[(state, pos)]
    
    nxt = 1
    ret = INF
    
    for to in range(v):
        if 1<<to & state:
            continue
        
        ret = min(ret, minCost(state|1<<to, to) + dis[pos][to])
        
    mem[(state, pos)] = ret
    
    return ret

ans = minCost(1, 0)

if ans>=INF:
    print(-1)
else:
    print(ans)


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 200007;

int n;
int a[MAXN];

void init ();
void input ();
void work ();

void no ()
{
	cout << -1 << endl;
	exit ( 0 );
}



int main ()
{
	init ();
	input ();
	work ();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	cin >> n;
	lpi ( i, 1, n ) cin >> a[i];
}

void work ()
{
	// main work

	if ( a[1] ) no ();

	LL ans = 0;
	lpi ( i, 2, n ) {
		if ( a[i] == a[i - 1] + 1 ) ++ans;
		else if ( a[i] <= a[i - 1] ) ans += a[i];
		else no ();
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
n,x = map(int, input().split())
L = list(map(int, input().split()))
l = [0] * (n+1)
for i in range(1,n+1):
    l[i] = l[i-1] + L[i-1]
ans = 0
for a in l:
    if a <= x: ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
  int S,h,m,s;
    cin >> S;
    h=S/3600;
    cout << h;
    cout <<":";
    cin >> m;
    m=(S%3600)/60;
    cout << m;
    cout <<":";
    cin >>s;
    s=S-h*3600-m*60;
    cout << s;
    cout << endl;
    
}



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


int main(){
    char S[4];
    cin >> S;

    int count1 = 0;
    int count2 = 0;

    char A = S[0];
    char B;

    for(int i=1; i<4; i++){
        if(S[i] != A){
            B = S[i];
        }
    }

    for(int j=0; j<4; j++){
        if(S[j] == A){
            count1++;
        }
        else if(S[j] == B){
            count2++;
        }
    }

    if(count1 == 2 && count2 == 2){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
N=int(input())
for i in range(N):
    a,b,c=map(int,input().split())
    if a>b:
        a,b=b,a
    if b>c:
        b,c=c,b
    if a>b:
        a,b=b,a
    if a*a+b*b==c*c:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5604
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int H1 = sc.nextInt();
      int M1 = sc.nextInt();
      int H2 = sc.nextInt();
      int M2 = sc.nextInt();
      int K = sc.nextInt();
      
      // 算出
      int hours = 0;
      int minutes = 0;
      
      if(M1 <= M2){
        minutes = M2 - M1;
        hours = H2 - H1;
      }else{
        minutes = M2 - M1 + 60;
        hours = H2 - H1 - 1;
      }
      
      int result = hours*60 + minutes - K;

      // 出力
      System.out.println(result);
    }
    
}

Measured memory_bytes: 35788
as=3.times.map{gets.split.map(&:to_i)}
N = gets.to_i
N.times do |i|
    b = gets.to_i
    3.times do |j|
        3.times do |k|
            as[j][k] = true if as[j][k] == b
        end
    end
end
f = false
3.times do |i|
    f = true if as[i].all?{|e|e==true}
end
as = as.transpose
3.times do |i|
    f = true if as[i].all?{|e|e==true}
end
f = true if as[0][0]==true && as[1][1]==true && as[2][2]==true 
f = true if as[2][0]==true && as[1][1]==true && as[0][2]==true 
puts f ? "Yes" : "No"

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define INF 1000000100
#define M 1000000007ll
#define INFLL 3000000000000000010ll
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))
#define mid(x,y) (((x)+(y))>>1)
int n;
ll a,b,s[100005];
ll f[100005],g[100005],pf[100005],pg[100005];
int bx[100005],by[100005];
int main() {
	scanf("%d%lld%lld",&n,&a,&b);
	for (int i=1;i<=n;i++) scanf("%lld",&s[i]);
	s[n+1]=INFLL;
	f[0]=1ll;
	g[0]=1ll;
	pf[0]=1ll;
	pg[0]=1ll;
	bx[0]=0;
	by[0]=0;
	s[0]=-INFLL;
	for (int i=1;i<=n;i++) {
		if (s[i]-s[i-1]<a) bx[i]=i-1;
		else bx[i]=bx[i-1];
		if (s[i]-s[i-1]<b) by[i]=i-1;
		else by[i]=by[i-1];
	}
	for (int i=1;i<=n;i++) {
		int jmin=bx[i];
		int jmax=upper_bound(s,s+n+2,s[i+1]-b)-s-1;
		jmax=min(jmax,i-1);
		if (jmin<=jmax) {
			if (jmin) f[i]+=pg[jmax]-pg[jmin-1];
			else f[i]+=pg[jmax];
			f[i]=(f[i]+M)%M;
		}
		pf[i]=(pf[i-1]+f[i])%M;
		
		jmin=by[i];
		jmax=upper_bound(s,s+n+2,s[i+1]-a)-s-1;
		jmax=min(jmax,i-1);
		if (jmin<=jmax) {
			if (jmin) g[i]+=pf[jmax]-pf[jmin-1];
			else g[i]+=pf[jmax];
			g[i]=(g[i]+M)%M;
		}
		pg[i]=(pg[i-1]+g[i])%M;
	}
	printf("%lld\n", (f[n]+g[n])%M);
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            var n = input[0];
            var m = input[1];

            var l = new List<Tuple<int,char>>();
            foreach(var i in Enumerable.Range(0,m)){
                var x = Console.ReadLine().Split().ToArray();
                var s = int.Parse(x[0]);
                var c = Convert.ToChar(x[1]);
                l.Add(Tuple.Create(s,c));
            }

            var notDone = true;
            foreach(var i in Enumerable.Range(0, (int)Math.Pow(10,n))){
                var k = i.ToString().ToCharArray();                
                var flag = true;
                foreach(var x in l){
                    var s = x.Item1;
                    var c = x.Item2;
                    if(k.Length >= s){
                        if(k[s-1] != c){
                            flag = false;
                            break;
                        }
                    }else{
                        flag = false;
                        break;
                    }
                }
                if(flag && k.Length == n){
                    Console.WriteLine(i);
                    notDone = false;
                    break;
                }
            }

            if(notDone){
                Console.WriteLine("-1");
            }
        }
    }
}


Measured memory_bytes: 13524