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

long long f(string t, int k, int r, int s, int p, int i)
{
    char prev = 'z';
    long long ret = 0;
    for (; i < t.size(); i += k)
    {
        switch (t[i])
        {
        case 'r':
            if (prev == 'p')
            {
                prev = 'z';
            }
            else
            {
                prev = 'p';
                ret += p;
            }
            break;
        case 's':
            if (prev == 'r')
            {
                prev = 'z';
            }
            else
            {
                prev = 'r';
                ret += r;
            }
            break;
        case 'p':
            if (prev == 's')
            {
                prev = 'z';
            }
            else
            {
                prev = 's';
                ret += s;
            }
            break;
        default:
            break;
        }
    }
    return ret;
}

int main()
{
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    long long ans = 0;
    for (int i = 0; i < K; i++)
    {
        ans += f(T, K, R, S, P, i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L, ALL_TASTE=0;
  cin >> N >> L;
  vector<int> TASTE(N);
  for (int i=0; i<N; i++){
    TASTE.at(i) = L+i;
    ALL_TASTE += TASTE.at(i);
  }
  
  int diff=100000, BITE_TASTE, tmp, ans;
  for (int i=0; i<N; i++){
    BITE_TASTE = ALL_TASTE - TASTE.at(i);
    tmp = abs(ALL_TASTE - BITE_TASTE);
    if (tmp <= diff){
      diff = tmp;
      ans = BITE_TASTE;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265
#define seive_len 1000001

bool seive[seive_len];
int primeSeive[seive_len];

typedef long long int lli;

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

lli lcm(lli a, lli b) {
  lli gcd_ = gcd(a, b);
  lli lcm_ = (a*b)/gcd_;
  return lcm_;
}

lli fastPower(lli a, lli b) {
  lli res=1;
  while(b > 0) {
    if(b&1)
      res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}

lli fastPowerM(lli a, lli b, lli mod) {
  a %= mod;
  lli res = 1;
  while(b) {
    if(b%2 == 1)
      res = (res*a)%mod;
    a = (a*a)%mod;
    b >>= 1;
  }
  return res;
}

void multiply(lli a[][2], lli b[][2], int mod) {
  int res[2][2];
  memset(res, 0, sizeof(res));
  for(int i=0;i<2;i++) {
    for(int j=0;j<2;j++) {
      for(int k=0;k<2;k++) {
        res[i][j] += a[i][k]*b[k][j]%mod;
      }
    }
  }
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
      a[i][j] = res[i][j];
}

void matrixExpo(lli a[][2], lli n, int mod) {
  if(n == 0 || n == 1)
    return;
  lli b[][2] = {{1,1}, {1,0}};
  matrixExpo(a, n/2, mod);
  multiply(a, a, mod);
  if(n%2)
    multiply(a, b, mod);
}

void makeSeive() {
  for(int i=2;i*i<=seive_len;i++) {
    if(seive[i]) {
      for(int j=i*i;j<=seive_len;j+=i)
        seive[j] = false;
    }
  }
}

void makePrimeSeive() {
  for(int i=1;i<seive_len;i++)
    primeSeive[i] = i;
  for(int i=4;i<seive_len;i+=2)
    primeSeive[i] = 2;
  for(int i=3;i*i<seive_len;i++) {
    if(primeSeive[i] == i) {
      for(int j=i*i;j<seive_len;j+=i) {
        if(primeSeive[j] = j)
          primeSeive[j] = i;
      }
    }
  }
}

bool isPrime(lli n) {
  for(int i=2;i<=sqrt(n);i++) {
    if(n%i == 0)
      return false;
  }
  return true;
}

void getInput(vector<lli>& a, int n) {
  lli x;
  for(int i=0;i<n;i++) {
    cin >> x;
    a.push_back(x);
  }
}

void testCase() {
  lli i, n;
  cin >> n;
  cout << n+n*n+n*n*n;
}

int main() {
	int t=1;
	// cin >> t;
  // makePrimeSeive();
	while(t--) {
		testCase();
    cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

int K, X;

int main() {
    cin >> K;
    cin >> X;
    for( int i = K - 1; i > 0; i--){
        cout << (X - i) << " ";
    }
    for( int i = 0; i < K ; i++){
        cout << (X + i) << " ";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a,b) memset(a,b,sizeof (a))
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll ksm(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

 
int main(){
	int s,w;
	cin>>s>>w;
	if(w>=s)puts("unsafe");
	else puts("safe");
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 200010
vector<int> v[N];
int n,m;string s;
int cnt[N][2];
bool vis[N];
int main(){
    cin>>n>>m>>s;
    lol(i,m){
	int a,b;cin>>a>>b;a--,b--;
	v[a].push_back(b);
	v[b].push_back(a);
    }
    queue<int> Q;
    lol(i,n){
	vis[i]=0;
	lol(j,2)cnt[i][j]=0;
	for(auto x:v[i]){
	    if(s[x]=='A')cnt[i][0]++;
	    if(s[x]=='B')cnt[i][1]++;
	}
	if(cnt[i][0]==0||cnt[i][1]==0){
	    Q.push(i);
	    vis[i]=1;
	}
    }
    while(!Q.empty()){
	int x=Q.front();Q.pop();
	for(auto y:v[x]){
	    if(vis[y]==1)continue;
	    if(s[x]=='A')cnt[y][0]--;
	    if(s[x]=='B')cnt[y][1]--;
	    if(cnt[y][0]<=0||cnt[y][1]<=0){
		Q.push(y);
		vis[y]=1;
	    }
	}
    }
    bool ans=1;
    lol(i,n)ans&=vis[i];
    cout<<(ans?"No":"Yes")<<endl;
    return 0;
}


Measured memory_bytes: 12548
#include <stdio.h>

int main()
{
    int N, K, h[100001], i, count = 0;
    scanf("%d %d", &N, &K);
    for (i = 1; i <= N; i++)
    {
        scanf("%d", &h[i]);
    }
    for (i = 1; i <= N; i++)
    {
        if (h[i] >= K)
        {
            count = count + 1;
        }
    }
    printf("%d", count);
    return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e16;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll n,m,s,t;
	cin>>n>>m>>s>>t;
	s--;t--;
	vector<vector<P>> g_yen(n,vector<P>()),g_snuuk(n,vector<P>());
	rep(i,m){
		ll u,v,a,b;
		cin>>u>>v>>a>>b;
		u--;v--;
		g_yen[u].push_back(P(v,a));
		g_yen[v].push_back(P(u,a));
		g_snuuk[u].push_back(P(v,b));
		g_snuuk[v].push_back(P(u,b));
	}

	vector<ll> dist_yen(n,INF),dist_snuuk(n,INF);
	priority_queue<P,vector<P>,greater<P>> que;
	que.push(P(0,s));
	dist_yen[s] = 0;
	while(!que.empty()){
		P now = que.top();
		que.pop();
		ll node = now.second;
		ll d = now.first;
		for(auto x : g_yen[node]){
			ll next_node = x.first, next_dist = x.second;
			if(d + next_dist < dist_yen[next_node]){
				dist_yen[next_node] = d + next_dist;
				que.push(P(dist_yen[next_node], next_node));
			}
		}
	}

	que.push(P(0,t));
	dist_snuuk[t] = 0;
	while(!que.empty()){
		P now = que.top();
		que.pop();
		ll node = now.second;
		ll d = now.first;
		for(auto x : g_snuuk[node]){
			ll next_node = x.first, next_dist = x.second;
			if(d + next_dist < dist_snuuk[next_node]){
				dist_snuuk[next_node] = d + next_dist;
				que.push(P(dist_snuuk[next_node], next_node));
			}
		}
	}

	vector<ll> dist(n);
	rep(i,n){
		dist[i] = 1e15 - (dist_yen[i] + dist_snuuk[i]);
	}

	set<P> st;
	rep(i,n){
		st.insert(P(-dist[i],i));
	}

	rep(i,n){
		cout<<(*st.begin()).first*(-1)<<endl;
		// cout<<(*st.begin()).second<<endl;
		st.erase(P(-dist[i],i));
	}
	

	return 0;
}

Measured memory_bytes: 25592
#include<bits/stdc++.h>
#define debug(x) cerr<<"\tDEBUG: "<<#x<<" = "<<(x)<<endl
#define debug2(a,x) cerr<<#a<<"\tDEBUG: "<<#x<<" = "<<(x)<<endl
using namespace std;
const int maxn=55,P=1e9+7;
int n,m,K;
int dp[maxn][maxn][maxn*maxn*2];
void add(int &a,int b){
	a+=b;
	if(a>=P)a-=P;
}
int main(){
//	double sz=&cur2-&cur1;
//	cout<<sz/1024/1024<<endl;
	scanf("%d%d",&n,&K);
	m=n*n+1;
	dp[0][0][m]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			for(int k=-n*n;k<=n*n;k++){
				add(dp[i][j][k+2*j+m],1LL*dp[i-1][j][k+m]*(j+j+1)%P);
				add(dp[i][j+1][k+2*j+m],dp[i-1][j][k+m]);
				if(j!=0)add(dp[i][j-1][k+2*j+m],1LL*dp[i-1][j][k+m]*j*j%P);
			}
		}
	}
	cout<<dp[n][0][m+K]<<endl;
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    string s;
    cin>>s;

    int q;
    cin>>q;

    string add[2] = {"",""};
    int turn = 0;
    while(q--)
    {
        int t;
        cin>>t;
        if( t == 1 )
        {
            turn ^= 1;
        }
        else
        {
            int f;
            char c;
            cin>>f>>c;
            if( f == 1 )
                add[turn] += c;
            else
                add[turn^1] += c;
        }
    }
    reverse( add[turn].begin(), add[turn].end() );

    if( turn )
        reverse(s.begin(), s.end());

    string ans = add[turn] + s + add[turn^1];

    cout<<ans,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 1300
#include<stdio.h>
int main(){
  int count[26]={};
  char str[1300];
  char ei;
  int i=0,j;
  while(scanf("%c",&str[i]) != EOF){
    if('A' <= str[i] && str[i] <= 'Z'){
      str[i]=str[i]+32;
    }
    j=0;
    for(ei='a';ei<='z';ei++){
      if(str[i]==ei){
	count[j]++;
      }
      j++;
    }
    i++;
  }
  j=0;
  for(ei='a';ei<='z';ei++){
      printf("%c : %d\n",ei,count[j]);
      j++;
  }
  return 0;
}
	
    



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
void PDF(string A)
{
    if(A=="ABC")
    {
        cout << "ARC" <<endl;
    }
    else
    {
        cout << "ABC" <<endl;
    }
}
int main()
{
    string A;
    cin >> A;
    PDF(A);
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	int a, b, c;
	char buf[100], buf2[100], buf3[100];

	scanf("%s %s %s", buf, buf2, buf3);

	a = atoi(buf);
	b = atoi(buf2);
	c = atoi(buf3);

	printf("%s\n", a < b ? (b < c ? "Yes" : "No") : "No");

	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin() (x).end()
#define rall(x) (x).rbegin() (x).rend()
typedef pair<int,int> pii;
typedef long long ll;

void A(){
	/**int m,p; cin>>m>>p;
	cout<<((m*3)+p)/2<<endl;*/
}

bool cmp(pair<string,pair<int, int>> &a, pair<string,pair<int, int>> &b){
	if(a.first==b.first)return (a.second.first > b.second.first); 
	else return a.first<b.first;
}
int main(){
	int r, score; cin>>r;
	vector<pair<string, pair<int, int>>> v; 
	for(int i=0; i<r; i++){
		string s; cin>>s>>score;
		v.push_back({s, {score, i+1}});
	}
	sort(v.begin(), v.end(), cmp);
	for(auto&x: v){
		cout<<x.second.second<<endl;
	}
	return 0;
}


Measured memory_bytes: 3572
#include<cstdio>
#define MAX 10000
#define NIL -1
struct Node{int p,l,r;};
struct Node T[MAX];
int n;
void preParse(int u){
if(u==NIL)return;
printf(" %d",u);
preParse(T[u].l);
preParse(T[u].r);
}
void inParse(int u){
if(u==NIL)return;
inParse(T[u].l);
printf(" %d",u);
inParse(T[u].r);
}
void postParse(int u){
if(u==NIL)return;
postParse(T[u].l);
postParse(T[u].r);
printf(" %d",u);
}
int main(){
int i,v,l,r,root;
scanf("%d",&n);
for(i=0;i<n;i++){
T[i].p=NIL;
}
for(i=0;i<n;i++){
scanf("%d %d %d",&v,&l,&r);
T[v].l=l;
T[v].r=r;
if(l!=NIL)T[l].p=v;
if(r!=NIL)T[r].p=v;
}
for(i=0;i<n;i++)if(T[i].p==NIL)root=i;
printf("Preorder\n");
preParse(root);
printf("\n");
printf("Inorder\n");
inParse(root);
printf("\n");
printf("Postorder\n");
postParse(root);
printf("\n");
return 0;
}


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

int main() {

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (A > 0 && C > 0) {
		C -= B;
		if (C <= 0) {
			cout << "Yes";
			return 0;
		}
		A -= D;
		
	}
	cout << "No";
}

Measured memory_bytes: 3672
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            string s,t;
            cin>>s>>t;
            int n=s.length(),m=t.length(),i,j;
            int dp[n+1][m+1];
            pii pre[n+1][m+1];
            mem(dp,0);
            mem(pre,-1);
            for(i=1;i<=n;++i)
            {
                for(j=1;j<=m;++j)
                {
                    dp[i][j]=max(dp[i-1][j],max(dp[i][j-1],dp[i-1][j-1]));
                    if(dp[i][j]==dp[i-1][j])
                        pre[i][j]={i-1,j};
                    else if(dp[i][j-1])
                        pre[i][j]={i,j-1};
                    else
                        pre[i][j]={i-1,j-1};
                    if(s[i-1]==t[j-1])
                    {
                        dp[i][j]=max(dp[i][j],1+dp[i-1][j-1]);
                        if(dp[i][j]==1+dp[i-1][j-1])
                            pre[i][j]={i-1,j-1};
                    }
                }
            }
            string ans="";
            int x=n,y=m;
            while(pre[x][y].f>=0 && pre[x][y].s>=0)
            {
                if(dp[x][y]==1+dp[pre[x][y].f][pre[x][y].s])
                {
                    ans=ans+s[x-1];
                }
                i=pre[x][y].f,j=pre[x][y].s;
                x=i,y=j;
            }
            reverse(ans.begin(),ans.end());
            cout<<ans<<endl;
        }
        return 0;
    }


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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; ++i) {
        if (i % d == 0) {
            ++ans;
        }
    }
    cout << ans << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>  
using namespace std;  
typedef long long ll; 
typedef long double ld; 
const int INF = 0x3f3f3f3f;  
const int N = 200000 + 5;
ll a[N],f[N],sum[N];

int main()
{
	ll n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i > 1)
			sum[i] = sum[i-2] + a[i];
		else
			sum[i] = a[i];
	}
	for(int i = 2; i <= n; i++){
		if(i % 2 == 1)
			f[i] = max(f[i-2]+a[i],f[i-1]);
		else
			f[i] = max(f[i-2]+a[i],sum[i-1]);
	}
	cout << f[n] << endl;
    return 0;
}

Measured memory_bytes: 8332
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	int R;
	cin >> R;
	double ans;
	ans = 2 * acos(-1)* R;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3784
//template---{{{
//Header file---{{{
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
//}}}
using namespace std;

//DEFINE---{{{
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b); i > (a); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
//end.DEFINE---}}}

//end.template ---}}}

int main() {
  int N;
  int sumNum = 0;
  int sumDivisor = 0;

  cin >> N;

  for (int i = 1; i <= N; i += 2) {
    sumDivisor = 0;
    for (int j = 1; j <= N; ++j) {
      if (i % j == 0) sumDivisor++;
    }
    if (sumDivisor == 8) sumNum++;
  }

    cout << sumNum << endl;

  return (0);
}


Measured memory_bytes: 256
/*||>>>> Praveen Ojha <<<<>>>> 29 August 2019 <<<<>>>> 13:42:45 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=100005;
int n;
vi adj[N];
pii dfs(int u,int par){
	pii res={1,1};
	for(int v:adj[u]){
		if(v!=par){
			pii t=dfs(v,u);
			res.F=(res.F*((t.F+t.S)%mod))%mod;
			res.S=(res.S*t.F)%mod;
		}
	}
	return res;
}
int32_t main(){__
	cin>>n;
	int x,y;
	for(int i=0;i<n-1;i++){
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	pii ans=dfs(1,0);
	cout<<(ans.F+ans.S)%mod<<"\n";
return 0;
}

Measured memory_bytes: 9600
# abc125_b.py
# https://atcoder.jp/contests/abc125/tasks/abc125_b

# B - Resale /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# N個の宝石があり、i 番目の宝石の価値は Viです。
# あなたはこれらの宝石の中からいくつかを選んで手に入れます。
# このとき、1つも選ばなくとも、全て選んでも構いません。
# ただし、i番目の宝石を手に入れる場合コスト Ciを支払わなければいけません。
# 手に入れた宝石の価値の合計を X、支払ったコストの合計を Yとします。
# X−Yの最大値を求めてください。

# 制約
#     入力は全て整数である。
#     1≤N≤20
#     1≤Ci,Vi≤50

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# V1 V2 ... VN
# C1 C2 ... CN

# 出力
# X−Yの最大値を出力せよ。

# 入力例 1
# 3
# 10 2 5
# 6 3 4

# 出力例 1
# 5

# 1番目の宝石と 3 番目の宝石を選んだとき、X=10+5=15,Y=6+4=10 です。 このとき、X−Y=5となり、これが最大です。

# 入力例 2
# 4
# 13 21 6 19
# 11 30 6 15

# 出力例 2
# 6

# 入力例 3
# 1
# 1
# 50

# 出力例 3
# 0


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # line = lines[0]
    N = int(lines[0])
    # A, B, T = list(map(int, lines[0].split()))
    values_v = list(map(int, lines[1].split()))
    values_c = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(Q):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 0

    for i in range(N):
        dif = values_v[i] - values_c[i]
        if dif > 0:
            result += dif

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '10 2 5', '6 3 4']
        lines_export = [5]
    if pattern == 2:
        lines_input = ['4', '13 21 6 19', '11 30 6 15']
        lines_export = [6]
    if pattern == 3:
        lines_input = ['1', '1', '50']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(3)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

int main() {
  long N;
  cin >> N;

  char alph[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

  string ans;

  while (N != 0) {
    N--;
    ans += alph[N % 26];
    N /= 26;
  }

  reverse(ans.begin(), ans.end());

  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 


ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}


int main(void){

   ll n, m, k;
   cin>>n>>m>>k;
   ll sum = 0;

 // if(n<m){
   for(int i=0;i<=m;i++){
     for(int j=0;j<=n;j++){
       sum = 0;
       sum = n*i - i*j + (m-i)*j;
      // cout<<i<<","<<j<<","<<sum<<endl;
       if(sum == k){
         cout<<"Yes"<<endl;
         return 0;
       }
     }
   }
  // }else{
  //   for(int i=0;i<=m;i++){
  //    for(int j=0;j<=n;j++){
  //      sum = 0;
  //      sum += m*i - i*j + (n-i)*j;
  //      //cout<<i<<","<<j<<","<<sum<<endl;
  //      if(sum == k){
  //        cout<<"Yes"<<endl;
  //        return 0;
  //      }
  //    }
  //  }
  // }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
#define MOD 1000000007
using namespace std;
ll inv(ll a){
  ll t=1;
  while (a>1){
    t=t*(MOD-MOD/a)%MOD;
    a=MOD%a;
  }
  return t;
}
ll comb(ll n,ll k){
  if (k>n-k) k=n-k;
  ll nu=1,de=1;
  rep(i,1,k+1){
    nu=nu*(n+1-i)%MOD;
    de=de*i%MOD;
  }
  return nu*inv(de)%MOD;
}
ll modpow(ll a,ll b) {
    ll res=1;
    for (a%=MOD;b;a=a*a%MOD,b>>=1)
     if (b&1)res=res*a%MOD;
   return res;
}
int main(){
    ll n,a,b,ans=1;
    cin>>n>>a>>b;
    ans=modpow(2,n);
    ll A=comb(n,a),B=comb(n,b);
    ans=(ans-(A+B)-1)%MOD;
    if(ans<0)ans+=MOD;
    cout<<ans<<endl;
}

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


int main(){
	map <string , int > m ;
	m["SUN"] = 7 ;
	m["MON"] = 6 ;
	m["TUE"] = 5 ;
	m["WED"] = 4 ;
	m["THU"] = 3 ;
	m["FRI"] = 2 ;
	m["SAT"] = 1 ;
	string s ;
	cin >> s ;
	cout  << m[s] << endl ;
	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, h1, h2, tmp, ans;
  ans = 0;
  cin >> n;
  h1 = 0;
  for(int i=0;i<n;i++){
    cin >> h2;
    if(h1>h2){
      ans += h1-h2;
    }
    h1 = h2;
  }
  ans += h2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a=new int[3];
            int []b = new int[2];
            for(int h = 0; h < 3; h++) { a[h] = int.Parse(Console.ReadLine()); }
            for(int y = 0; y < 2; y++) { b[y] = int.Parse(Console.ReadLine()); }
            Array.Sort(a);
            Array.Sort(b);
            Console.WriteLine(a[0] + b[0]-50);
        }
    }
}

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,N,A;cin>>H>>N;
  for(int i=0;i<N;i++){
    cin>>A;H-=A;if(H<=0)break;
  }
  if(H>0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> h(n);
  for(int i=0; i<n; i++) cin >> h[i];
  
  vector<int> dp(n, INF);
  dp[0] = 0;
  dp[1] = dp[0] + abs(h[1]-h[0]);
 
  for(int i=2; i<n; i++) 
    dp[i]=min(
      dp[i-2] + abs(h[i] - h[i-2]),
      dp[i-1] + abs(h[i] - h[i-1])
    );
  
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};
char alpha[26]={};
int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        alpha[s[i]-'a']++;
    }
    bool flag=true;
    for(int i=0;i<26;i++){
        if(alpha[i]%2!=0) flag=false;
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding:utf-8

INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


class RollingHash:
    def __init__(self, s, base, mod):
        self.s = s
        self.length = length = len(s)
        self.base = base
        self.mod = mod
        self.h = h = [0] * (length + 1)
        for i in range(length):
            h[i + 1] = (h[i] * base + ord(s[i])) % mod
        self.p = p = [1] * (length + 1)
        for i in range(length):
            p[i + 1] = pow(base, i + 1, mod)

    def get(self, l, r):
        mod = self.mod
        # return (self.h[r] - self.h[l] * pow(self.base, r - l, mod) + mod) % mod
        return ((self.h[r] - self.h[l] * self.p[r - l]) + mod) % mod


def solve():
    N, M = inpl()
    S = input()
    h1 = RollingHash(S, 13, MOD)
    h2 = RollingHash(S, 17, MOD)
    left, right = 0, 1
    vs = set()
    ans = 0
    for i in range(M):
        q = input()
        if q == 'R++':
            right += 1
        elif q == 'R--':
            right -= 1
        elif q == 'L++':
            left += 1
        else:
            left -= 1

        v = (h1.get(left, right), h2.get(left, right))
        if v not in vs:
            ans += 1
            vs.add(v)

    return ans


print(solve())



Measured memory_bytes: 99780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	string s;
	cin>>s;
	if (s=="ABC") cout<<"ARC";
	else cout<<"ABC";
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101;
string s[N];
bool vis[N][N];
int H , W;
int main(){
    cin >> H >> W;
    rep(i,0,H) cin >> s[i];
    int x = 0 , y = 0;
    while(1){
        if(s[x][y] != '#') break;
        vis[x][y] = true;
        if(x != H - 1 && s[x + 1][y] == '#') x++;
        else if(y != W - 1 && s[x][y + 1] == '#') y++;
        else break;
    }
    bool ok = true;
    rep(i,0,H) rep(j,0,W) if(s[i][j] == '#' && !vis[i][j]) ok = false;
    if(!vis[0][0] || !vis[H - 1][W - 1]) ok = false;
    cout << (ok ? "Possible" : "Impossible") << endl;
    return 0;
}


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

int main(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  ll sa,sa1;
  if(k%2==0){
    sa=a-b;
  }else{
    sa=b-a;
  }
  sa1=sa;
  for(int i=1;i<=18;i++){
    sa1/=10;
  }
  if(sa1>0){
    cout<<"Unfair"<<endl;
  }else{
    cout<<sa<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

ll a,b,k;
cin >> a >> b >> k;

if((a-k) >= 0) cout << a-k << ' ' << b << endl;
else if((a+b-k) >= 0) cout << 0 << ' ' << a+b-k << endl;
else cout << 0 << ' ' << 0 << endl;



//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  char s[5];
  int i,sum = 0;

  for(i = 0;i < 5 ;i++){
    scanf("%c",&s[i]);
  }

  for(i = 0;s[i];i++){
    if(s[i] == '+'){
      sum++;
    }
    else if(s[i] == '-'){
      sum--;
    }
  }

  printf("%d",sum);

  return 0;

}

Measured memory_bytes: 128
N = [int(_) for _ in input().split()]
K, N = N[0], N[1]
A = [int(_) for _ in input().split()]

def solve(K, N, A):
    
    hoge = A[0]
    B = []
    for i in range(1, N):
        B.append(A[i] - hoge)
        hoge = A[i]
    
    B.append( K - A[N-1] + A[0])
    return sum(B) - max(B)

print(solve(K, N, A))

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

int main() {
   int y, m, d;
   char s1, s2;
   cin >> y >> s1 >> m >> s2 >> d;

   if (m <= 4) {
       cout << "Heisei" << endl;
   } else {
       cout << "TBD" << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
using namespace std;
int N,A[100005];
bitset<100005> B;
int nr;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)cin>>A[i];
    nr=0;
    int b=1;
    while(b!=2)
    {
        nr++;
        if(B[b]){cout<<-1;return 0;}
        B[b]=1;
        b=A[b];
    }
    cout<<nr;
    return 0;
}


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

int main() {
  int N,l,r,S;
  cin >> N;
  S=0;

  for (int i=0; i<N; i++){
    cin >> l >> r;
    S+=r-l+1;
    if (i==N-1)
      cout << S <<endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{

    public static void Main(string[] args)
    {
        long N = Input.NextLong();
        var ant = new long[5];
        for (int i = 0; i < 5; i++)
            ant[i] = Input.NextLong();

        var min = ant.Min();

        var r = N % min;
        var n = N / min + (r == 0 ? 0 : 1);
        var ans = n + 4;

        Console.WriteLine(ans);
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 13396
// 一番でかいやつを排除したのが合計値になりそう->端っこに入れる
// 合計がsum(arr)-max(arr)を目指すので適当に↑の続きから大きい順に入れていけば、いれたやつが採用されそう
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	T := make([][]int, N)
	for i := 0; i < N; i++ {
		T[i] = []int{}
	}
	for i := 0; i < N-1; i++ {
		var A, B int
		fmt.Scan(&A, &B)
		T[A-1] = append(T[A-1], B-1)
		T[B-1] = append(T[B-1], A-1)
	}
	C := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&C[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(C)))
	start := -1
	for i, t := range T {
		if len(t) == 1 {
			start = i
			break
		}
	}
	ans := 0
	queue := []int{start}
	used := make([]int, N)
	idx := 0
	used[start] = C[idx]
	for len(queue) > 0 {
		cur := queue[len(queue)-1]
		queue = queue[:len(queue)-1]
		for _, t := range T[cur] {
			if used[t] == 0 {
				idx++
				used[t] = C[idx]
				ans += C[idx]
				queue = append(queue, t)
			}
		}
	}
	fmt.Println(ans)
	for _, p := range used {
		fmt.Printf("%d ", p) // atcoderこれでも許された気がする
	}
}


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

int gcd(int x, int y){
int r;
  if(x<y){swap(x,y);}
  
  while(y>0){
   r=x%y;
    x=y;
    y=r;
  }
 
  return x;
}

int main(){// 数値a,bが互いに最小になるまで引き合うと、ユークリッドの互除法と同じ遷移をするため、
int N;     // 最後はa,bの最大公約数が残る(b-aを繰り返すとb%aが残るため)。
  cin>>N; // よって配列Aの最大公約数が答えになる。
  vector<long>A(N);
  for(int i=0; i<N; i++){
   cin>>A[i]; }
  
  int ans=1e9;
  for(int i=0; i<N-1; i++){
    ans=min(ans, gcd(A[i], A[i+1]));
  }
  
 cout<<ans;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

void self_max(ll &a, ll b) {
	a = max(a,b);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl w(n), s(n), v(n);
	FOR(i,0,n) cin >> w[i] >> s[i] >> v[i];

	vl is(n);
	iota(all(is),0);
	sort(all(is),[&](ll i, ll j) {
		return s[i]+w[i] < s[j]+w[j];
	});
	
	ll W = 20005;

	vl dp(W,-1);
	dp[0] = 0;
	for (ll i: is) {
		FORD(j,0,s[i]+1) if (dp[j] != -1) {
			self_max(dp[j+w[i]], dp[j] + v[i]);
		}
	}
	cout << *max_element(all(dp)) << endl;
}



Measured memory_bytes: 512
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
right = 0
left = 0
for i in range(X, N):
    if i in A:
        right += 1
for i in range(0, X+1):
    if i in A:
        left += 1
print(min(right,left))

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

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> s(M),c(M),v(N,-1);
    bool f=true;
    for (int i=0;i<M;i++){
        cin>>s[i]>>c[i];
        if (v[s[i]-1]==-1) v[s[i]-1]=c[i];
        else if (v[s[i]-1]!=c[i])  f=false;
    }
    for (int i=1;i<N;i++){
        if (v[i]==-1) v[i]=0;
    }
    if (N!=1){
        if (v[0]==-1) v[0]=1;
        if (v[0]==0) f=false;
    }
    else if (v[0]==-1) v[0]=0;
    int k=1,ans=0;
    for (int i=0;i<N;i++){
        ans+=v[N-1-i]*k;
        k=k*10;
    }
    if (f) cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 3652
H,W,K=map(int,input().split())
import numpy as np
import copy
c=[]
for i in range(H):
  c.append(list(input().replace('.','0').replace('#','1')))

def count(xdel,ydel,l):
  cnt=0
  for i in range(H):
      for j in range(W):
        if 2**i&ydel!=0 or 2**j&xdel!=0:
          l[i][j]=2
        if l[i][j]=='1':
          cnt+=1
          l[i][j]=1
        
  return cnt

result=0
for i in range(2**H):
  for j in range(2**W):
    l=copy.deepcopy(c)
    if count(j,i,l)==K:
      result+=1
print(result)
    


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

class UnionFindTree
{
private:
	vector<int> rank, parent;

public:
	UnionFindTree(int n)
	{
		rank.resize(n, 0);
		parent.resize(n, 0);
		for (int i = 0; i < n; i++) {
			rank[i] = 0;
			parent[i] = i;
		}
	}

	int GetRoot(int node)
	{
		if (parent[node] != node) parent[node] = GetRoot(parent[node]);
		return parent[node];
	}

	bool Judge(int x, int y)
	{
		return GetRoot(x) == GetRoot(y);
	}

	void Union(int x, int y)
	{
		int setRootX = GetRoot(x);
		int setRootY = GetRoot(y);

		if (rank[setRootY] < rank[setRootX]) parent[setRootY] = setRootX;
		else {
			parent[setRootX] = setRootY;
			if (rank[setRootY] == rank[setRootX]) rank[setRootY]++;
		}
	}
};

int main()
{
	int n, q;
	cin >> n >> q;
	UnionFindTree uft(n);
	for (int i = 0; i < q; i++) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) uft.Union(x, y);
		else {
			if (uft.Judge(x, y)) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
}



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

int main() {
  int N;
  int ac=0;
  int wa=0;
  int tle=0;
  int re=0;
  string s;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> s;
    if(s=="AC")
      ac++;
    if(s=="WA")
      wa++;
    if(s=="TLE")
      tle++;
    if(s=="RE")
      re++;
  }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    ll a, b, c;
    cin >> a >> b >> c;

    if(a + b >= c){
        cout << c + b << endl;
    }else{
        ll ans = b * 2;
        c -= b;
        ans += min(a, c) + 1;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
S = input()

if 1 <= int(S[0:2]) <= 12 and 1 <= int(S[2:4]) <= 12:
  print("AMBIGUOUS")

elif 1 <= int(S[0:2]) <= 12:
  print("MMYY")
elif 1 <= int(S[2:4]) <= 12:
  print("YYMM")
else: print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  string S;
  cin >> S;
  int F = (S[0] - '0') * 10 + S[1] - '0';
  int B = (S[2] - '0') * 10 + S[3] - '0';
  if (1 <= F && F <= 12 && 1 <= B && B <= 12) {
    printf("AMBIGUOUS\n");
  }
  else if ((F == 0 || 12 < F) && 1 <= B && B <= 12) {
    printf("YYMM\n");
  }
  else if (1 <= F && F <= 12 && (B == 0 || 12 < B)) {
    printf("MMYY\n");
  } else {
    printf("NA\n");
  }
  return 0;
}

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

int arr[100000];
int main() {
	int n, k;
	while (scanf("%d%d", &n, &k), n) {
		rep(i, k)
			scanf("%d", &arr[i]);
		bool flag = false;
		if (arr[0])flag = true;
		sort(arr, arr + k);
		int Max = 0, cnt = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = i; j <= n; j++) {
				if (!binary_search(arr, arr + k, j)) {
					if (!flag) { flag = true; cnt++; }
					else {
						Max = max(Max, cnt);
						cnt = 0;
						if (!arr[0])
							flag = false;
						break;
					}
				}
				else cnt++;
			}
		}
		printf("%d\n", Max);
	}
	return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <ctype.h>

int main(){
    char ch;
    while(1){
        scanf("%c", &ch);
        if(ch=='\n'){
            printf("\n");
            break;
        }else if(islower(ch)){
            printf("%c", toupper(ch));
        }else if(isupper(ch)){
            printf("%c", tolower(ch));
        }else{
            printf("%c", ch);
        }
    }

    return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
//#include <bits/stdc++.h>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)
using namespace std;

int main() {
  string s;
  int K;
  cin >> s >> K;
  for(auto& c : s) {
    int dist = 'z' - c + 1;
    if(dist == 26) { continue; }
    else if(K >= dist) {
      K -= dist;
      c = 'a';
    }
  }
  K %= 26;
  int dist = 'z' - s.back() + 1;
  if(K >= dist) {
    s.back() = 'a' + (K - dist);
  }
  else { s.back() += K; }
  cout << s << endl;
  return 0;
}



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  k--;
  rep(i,n){
    if(i == k){
      s[i] = s[i] - ('A' - 'a');
    }
  }
  cout << s << "\n";
  return 0;
}


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

int main() {
	while (1) {
		int m, l, f;
		vector<int> mem;
		cin >> m >> l >> f;
		if (m == 0)break;

		for (int i = 0; i < m; i++) {
			int x;
			cin >> x;
			mem.push_back(x);
		}

		int gap = 0, gapi = 0;
		for (int i = l - 1; i < f; i++) {
			if (mem[i] - mem[i + 1] >= gap) {
				gap = mem[i] - mem[i + 1];
				gapi = i;
			}
		}
		cout << gapi + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		System.out.println(s.charAt(0) == t.charAt(0) && t.replaceFirst(s, "").length() == 1 ? "Yes" : "No");
	}
}


Measured memory_bytes: 35616