akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int n,i;
	cin>>n;
	for(i=1;i<=n;i*=2)
		if(i*2>n)
			break;
	printf("%d\n",i);
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a[10], i, j, temp;
	for (i = 0; i < 10; i++)
	{
		scanf("%d", a + i);
	}

	for (i = 0; i < 9; i++)
	{
		for (j = i + 1; j < 10; j++)
		{
			if (a[i] < a[j])
			{
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	for (i = 0; i < 3; i++)
	{
		printf("%d\n", a[i]);
	}
	return 0;
}

Measured memory_bytes: 600
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dist[100010] = {};
vector<ll> tree[100010];

void dfs(ll cur, ll par){
    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs(e, cur);
        dist[cur] ^= dist[e]+1;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    rep(i,0,N-1){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(0,-1);
    if(dist[0] == 0){
        print("Bob");
    }else{
        print("Alice");
    }


    

}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n; cin>>n;
    string ans;
    while(n>0){
        n--;
        ans+='a'+n%26;
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int k,x;
	cin>>k>>x;
	int l=x-k+1,r=x+k-1;
	l=max(l,-1000000);
	r=min(r,1000000);
	for(int i=l;i<=r;i++)
	printf("%d ",i);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	char x[1000][1001] = { "a" };
	int check;
	int a[1000] = {};
	for (int i = 0; i < 1000; i++){
		cin >> x[i];
		if (x[i][0] == '0'){
			break;
		}
		for (int i2 = 0; i2 < 1001; i2++){
			if (x[i][i2] != '\0' && x[i][i2] != 'a'){
				a[i] += x[i][i2] - '0';
			}
		}
		check = i;
	}
	for (int i = 0; i <= check; i++){
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4056
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int A, B, C; cin >> A >> B >> C;
	if (A == 5 && B == 5 && C == 7 ||
		A == 5 && B == 7 && C == 5 ||
		A == 7 && B == 5 && C == 5)
	{
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1e6 + 4;

int isprime[MAX];
   //to store smallest prime factor of number
void sieve()
    {
       for(int i = 1;i < MAX;++i)
           isprime[i] = i;

        for(int i = 2;i < MAX;++i)
        {
            if(i == isprime[i])
            {
                for(int j = 2 * i;j <= MAX;j += i)
                {
                    if(isprime[j] == j)
                    isprime[j] = i;
                }
            }
        }

    }
// A O(log n) function returning primefactorization 
 
vector<int>factorize(int x) 
{ 
    vector<int>res; 
    while (x != 1) 
    { 
        res.push_back(isprime[x]); 
        x = x / isprime[x]; 
    } 
    return res; 
} 




signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    sieve();
    
    int testCases = 1;
  //  cin >> testCases;
    
    while(testCases--)
    {
        int n,i;
        cin >> n;
        
        int a[n];
        
        for(i = 0;i < n;++i)
            cin >> a[i];
        
        
        int GCD = a[0];
        for(i = 1;i < n;++i)
        {
           GCD = __gcd(GCD,a[i]);
            
        }
        map<int,int>mp;
        for(i = 0;i < n;++i)
        {
            vector<int>y = factorize(a[i]);
            set<int>X;
            
            for(int e : y)
                X.insert(e);
            
            for(auto e : X)
                mp[e]++;
            
        }
        bool flg = false;
        for(auto it : mp)
        {
            if(it.second > 1)
            {
                flg = true;
                break;
            }
        }
        
        if(!flg and GCD == 1)
        {
            cout << "pairwise coprime";
        }
        else{
            if(GCD == 1)
                cout << "setwise coprime";
            else
                cout << "not coprime";
        }
       
        cout << '\n';
    }
    
}


Measured memory_bytes: 24052
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define req(x,y) for(ll j=x,k=y;j<k;j++,k--)
#define ss(x) s[x].size()

ll n,c[51],d[51][21][2],v[51][21][2],a=1e18;
string s[51];

ll fnc(ll b,ll p,ll g){
	if(p==ss(b))return 0;
	ll &e=v[b][p][g];
	ll &m=d[b][p][g];
	if(e)return m;
	e=1,m=1e18;
	ll l=1;
	if(!g){
		req(p,ss(b)-1){
			if(s[b][j]!=s[b][k])l=0;
		}
	}
	else{
		req(0,p){
			if(s[b][j]!=s[b][k])l=0;
		}
	}
	if(l)return m=0;
	rep(i,n){
		ll y=1;
		ll j,k;
		if(!g){
			for(j=p,k=ss(i)-1;j<ss(b) && k>=0 && y;j++,k--) {
				if(s[b][j]!=s[i][k])y=0;
			}
			if(y){
				if(k<0)m=min(m,c[i]+fnc(b,j,0));
				else m=min(m,c[i]+fnc(i,k,1));
			}
		}
		else{
			for(j=p,k=0;k<ss(i) && j>=0 && y;j--,k++){
				if(s[b][j]!=s[i][k])y=0;
			}
			if(y){
				if(j<0)m=min(m,c[i]+fnc(i,k,0));
				else m=min(m,c[i]+fnc(b,j,1));
			}
		}
	}
	return m;
}

int main() {
	cin>>n;
	rep(i,n)cin>>s[i]>>c[i];
	rep(i,n)a=min(a,c[i]+fnc(i,0,0));
	cout<<(a==1e18 ? -1 : a)<<endl;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t k;
  cin>>k;
  cout<<50<<endl;
  int64_t r=k/50;
  int64_t m=k-r*50;
  for(int i=0;i<50;i++)
    cout<<(i<m?r+100-m:r+49-m)<<(i+1<50?" ":"");
  cout<<endl;
}

Measured memory_bytes: 256
n,w = list(map(int, input().split()))
wv = [list(map(int, input().split())) for _ in range(n)]

v = sum(list(map(lambda x: x[1], wv)))
dp = [[float("inf")]*(v+1) for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    a = wv[i]
    for j in range(v+1):
        if a[1] <= j:
            dp[i+1][j] = min(dp[i][j], dp[i][j- a[1]] + a[0])
        else:
            dp[i+1][j] = dp[i][j]

dpl = dp[-1]
for i in range(v, -1, -1):
    if dpl[i] <= w:
        print(i)
        break

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

int	main() {
	long N, K;
	cin >>N >>K;
	long S=K;
	if (N>1)
		for (int i=2; i<=N; i++)
			S *=K-1;
	cout <<S <<endl;
	return 0;
};


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b = sc.nextLong

  val firstBit = {
    val nums = b - a + 1
    val evens = if (a % 2 == 1) (nums + 1) / 2 else nums / 2
    evens % 2
  }
  val ans = (1 to 40).foldLeft(firstBit.toLong){(z, s) =>
    val aBits =
      if (((1L << s) & a) == 0) 0
      else (1L << (s + 1)) - (a & (-1L >>> (63 - s)))

    val bBits =
      if (((1L << s) & b) == 0) 0
      else (b & (-1L >>> (64 - s))) + 1

    if ((aBits + bBits) % 2 == 0) z else z + (1L << s)
  }

  println(ans)
}

Measured memory_bytes: 25932
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N;

int main()
{
	in >> N;
	out << N / 3 << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)
typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    if (N == 1 && M == 1)cout << 1 << endl;
    else if (N > 2 && M > 2) cout << (N - 2) * (M - 2) << endl;
    else if (N == 2 || M == 2) cout << 0 << endl;
    else cout << max(N, M) - 2 << endl;
    return 0;
}

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

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

int main(){
    int n,X;
    cin >> n >> X;
    vector<int> x(n);
    rep(i,n) cin >> x[i];

    rep(i,n){
        x[i] = abs(x[i]-X);
    }
    int D = x[0];
    for(int i = 1; i < n; ++i){
        D = gcd(D, x[i]);
    }

    cout << D << endl;
    return 0;
}


Measured memory_bytes: 640
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
s,t = ism()
ans = ''
for i in range(n):
    ans += (s[i]+t[i])
print(ans)

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

using namespace std;

const int maxn = 2*(int)1e5+100;
int n;
char s[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> n;
    int cntw = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> s[i];
        if (s[i] == 'W') ++cntw;
    }
    int ans = 0;
    for (int i = n - cntw + 1; i <= n; ++i) {
        if (s[i] == 'R') ++ans;
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3884
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    int attendance=0;
    int A,B;
    char *state;
    int through=0;
    int foreign_rank=1;

    //printf("Input the number of attendance:");
    scanf("%d",&attendance);
    //printf("Input A:");
    scanf("%d",&A);
    //printf("Input B:");
    scanf("%d",&B);

    state=(char *)malloc(sizeof(char)*attendance);
    //printf("Input string:");
    scanf("%s",state);

    int i;
    for(i=0;i<attendance;i++){
        if(state[i]=='a'){
            if(through<(A+B)){
                printf("Yes\n");
                through++;
            }
            else if(through>=(A+B)){
                printf("No\n");
            }
        }
        else if(state[i]=='b'){
            if(through<(A+B)&&foreign_rank<=B){
                printf("Yes\n");
                through++;
            }
            else{
                printf("No\n");
            }
            foreign_rank++;
        }
        else if(state[i]=='c'){
            printf("No\n");
        }
    }
    return 0;

}

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

#define S second
#define F first
#define all(a) a.begin() , a.end()
#define pb push_back 
#define DBG cout<<"debug\n";

typedef long long ll;

const int N = 2 * 1e5 + 10;
const ll inf = 9e18 + 9; 

ll res;
ll a[N];


void solve(){
    ll m , d,cnt = 0;
    cin>>m>>d;
    for(int i = 1; i <= d ; i++) {
        for(int j = 1; j <= m ; j++) {
            ll x = i ;
            ll one = 0, two = 0;
            one = x%10;
            x = x/10;
            two = x %10;
            if(one * two == j && one >= 2 && two >= 2) {
                //cout<<one<<" "<<two<<"gg\n";
                //cout<<i<<" "<<j<<endl;
                cnt++;
            }
        }
    }

    cout<<cnt<<endl;
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, Z, W;
  cin >> N >> Z >> W;
  vector<ll> a(N);
  for (auto &it : a)
    cin >> it;
  if (N == 1)
    cout << abs(a[0] - W) << endl;
  else
    cout << max(abs(a[N - 1] - W), abs(a[N - 1] - a[N - 2]));
  return 0;
}


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

ll N;
vector<ll> A;
vector<vector<ll>> G;
vector<bool> used;
vector<ll> dist;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

void bfs(vector<vector<ll>> &G) {
  queue<ll> que;
  que.push(0);
  used[0] = true;
  dist[0] = 0;

  while(que.size()) {
    ll node = que.front(); que.pop();
    for(auto next_node: G[node]) {
      if (used[next_node]) continue;
      que.push(next_node);
      dist[next_node] = dist[node]+1;
      used[next_node] = true;
    }
  }
}


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

  cin >> N;
  G.resize(N);
  used.resize(N, false);
  dist.resize(N, -1);
  rep(i, N) {
    int tmp, k;
    cin >> tmp >> k;
    rep(j, k) {
      int node;
      cin >> node;
      G[tmp-1].push_back(node-1);
    }
  }
  bfs(G);
  rep(i, N) cout << i+1 << " " << dist[i] << endl;
  return 0;
}



Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

struct query{
  ll type;//0=empty, 1=add-sum ,2=set-max
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// max-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=max(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return -INF; // max
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return max(lv,rv); // max
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmax(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};

ll med_cnt(vec sum) {
  ll res=0;
  ll n=sum.size();
  segtree cnt(2*n+1);
  cnt.Set(0,2*n+1,0);
  for(ll i=0;i<n;i++) {
    res+=cnt.Getsum(0,sum[i]+n+1);
    cnt.Add(sum[i]+n,sum[i]+n+1,1);
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  ll l=1,r=1e9+10;
  while(l+1<r) {
    ll m=(l+r)>>1;
    vec b(n+1);
    for(ll i=0;i<n;i++) {
      if(a[i]>=m) b[i+1]=1;
      else b[i+1]=-1;
    }
    for(ll i=0;i<n;i++) {
      b[i+1]+=b[i];
    }
    ll k=med_cnt(b);
    if(k>=((n+1)*n/2+1)/2) l=m;
    else r=m;
  }
  cout << l << endl;
}

Measured memory_bytes: 21976
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    int maxLocation = max(a, max(b, max(c, max(d, e))));
    int minLocation = min(a, min(b, min(c, min(d, e))));

    string res = "Yay!";
    if (maxLocation - minLocation > k) res = ":(";

    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x < r || y < r|| x > W - r || y > H - r)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <math.h>
long long int factors (long long int n);
int main()
{
    long long int n,i,y,x;
    double pro;
    scanf("%lld", &n);
    if(factors(n)==0)printf("%lld",n-1);
    else{
            for(i=sqrt(n);i>1;i--){
        pro=n/i;
        if(pro*i==n){
            y=pro;
            x=n/y;
            break;
        }
        else continue;
    }
    printf("%lld",(x+y)-2);
    return 0;
}}
long long int factors (long long int n)
{
    long long int i,u=0;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            u++;
        }
    }
    return u;
}



Measured memory_bytes: 128
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

if A[0] > B[0]:
  result = B[0]
  kurikoshi = 0
else:
  result = A[0]
  kurikoshi = B[0] - A[0]  

for i in range(1, N):
  if A[i] - kurikoshi > 0:
    nokori = A[i] - kurikoshi
    result += kurikoshi
    if nokori > B[i]:
      result += B[i]
      kurikoshi = 0
    else:
      result += nokori
      kurikoshi = B[i] - nokori
  elif A[i] - kurikoshi <= 0:
    result += A[i]
    kurikoshi = B[i]
if A[N] > kurikoshi:
  result += kurikoshi
  print(result)
else:
  result += A[N]
  print(result)
  

Measured memory_bytes: 19004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

ll dp[100005][2];
vector<vector<int> > G(100005);

void dfs(int v, int p) {
  for (int nv : G[v]) {
    if (nv == p) continue;
    dfs(nv, v);
    (dp[v][0] *= dp[nv][0] + dp[nv][1]) %= mod;
    (dp[v][1] *= dp[nv][0]) %= mod;
  }
}


void solve() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].eb(b);
    G[b].eb(a);
  }
  fill_n(*dp, 100005 * 2, 1);
  rep(i, n) if (sz(G[i]) == 1 || sz(G[i]) == 0) {
    dfs(i, -1);
    cout << (dp[i][0] + dp[i][1]) % mod << endl;
    break;
  }
  // rep(i, n) { rep(j, 2) cout << dp[i][j] << " "; cout << endl; }
}


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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

struct Point {
	double x, y;
	Point(){};
	Point(double _x, double _y) : x(_x), y(_y) {};
};

Point operator + (const Point &p, const Point &q){
	return Point(p.x + q.x, p.y + q.y);
}

Point operator - (const Point &p, const Point &q){
	return Point(p.x - q.x, p.y - q.y);
}

double operator * (const Point &p, const Point &q){
	return p.x * q.x + p.y * q.y;
}

double dist(const Point &p, const Point &q){
	return sqrt((q - p) * (q - p));
}

Point operator * (const Point &p, double k){
	return Point(p.x * k, p.y * k);
}

Point projection(const Point &A, const Point &p, const Point &q){
	Point pq = q - p;
	Point pA = A - p;
	
	double K = (pq * pA) / (pq * pq);

	return p + pq * K;
}

Point reflection(const Point &A, const Point &p, const Point &q){
	Point m = projection(A, p, q);
	///2 * m.x = (A.x + B.x)

	return Point(2 * m.x - A.x, 2 * m.y - A.y);
}

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

	cout << setprecision(10) << fixed;

	Point p1, p2;
	cin >> p1.x >> p1.y >> p2.x >> p2.y;

	int q;	cin >> q;
	while(q--){
		Point p;	cin >> p.x >> p.y;
		Point ref = reflection(p, p1, p2);

		cout << ref.x << ' ' << ref.y << '\n';
	}

	return 0;
}


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

typedef long long ll;

ll a[200005];

int main(void)
{
    ll n, k;

    scanf("%lld %lld" ,&n, &k);
    for(ll i=1; i<=n; i++)
        scanf("%lld" ,&a[i]);

    for(int i=k+1; i<=n; i++)
    {
        if(a[i]>a[i-k])
            printf("Yes\n");
        else printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 5168
#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; i--)
#include <bits/stdc++.h>

using namespace std;

int main(void) {
    ll n, ac = 0, wa = 0, tle = 0, re = 0;
    string s;

    cin >> n;
    rep(i, n) {
        cin >> s;
        if(s == "AC") {
            ac++;
        } else if(s == "WA") {
            wa++;
        } else if(s == "TLE") {
            tle++;
        } else {
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}


Measured memory_bytes: 3624
K=int(input())
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd,numbers)
l=[]
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      l.append(gcd(a,b,c))
print(sum(l))


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

int main() {
	int n,k;
	cin>>n>>k;
    long long int a[n];
    for( int i=0; i<n; i++)
    cin>>a[i];
    
    
    long long int dp[n-1],dist=INT_MAX;
    
    for( int i=n-2; i>=0; i--)
    {
        if(i>n-2-k)
        dp[i] = abs(a[n-1] - a[i]);
        
        else
        {   dist=INT_MAX;
            for( int j=1; j<=k; j++)
            { dist= min(dist,abs(a[i]-a[i+j])+dp[i+j]);}
            
            dp[i] = dist;
        }
    }
    cout<<dp[0]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mo 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second

int main()
{
    lol;
    ll n;cin >> n;
    ll d;cin >> d;
    ll cnt =0;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin >> x >> y;
        x = abs(x);
        y = abs(y);
        if(x*x + y*y <=d*d) cnt++;
    }
    cout << cnt << endl;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int count = 0;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      int remain = x - (500 * i + 100 * j);
      if (remain < 0 || remain % 50 != 0) {
        continue;
      }
      int amount = remain / 50;
      if (0 <= amount && amount <= c) {
        count++;
      }
    }
  }
  p(count);
}

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

namespace A {
	class main {
		public main() { }
		public static int Main() {
			new main().run();
			return 0;
		}
		public struct edge {
			public int from,to,cost;
			public edge(int u, int v, int c) {
				from=u;
				to=v;
				cost=c;
			}
		}
		int[] par = new int[10001];
		int[] rank = new int[10001];
		void init(int n) {
			for(int i=0; i<n; i++){
				par[i]=i;
				rank[i]=0;
			}
		}
		int find(int x) {
			if(par[x]==x) {
				return x;
			} else {
				return par [x] = find (par [x]);
			}
		}
		void unite(int x,int y) {
			x=find(x);
			y=find(y);
			if(x==y) return;
			if(rank[x]<rank[y]) {
				par[x]=y;
			} else {
				par[y]=x;
				if (rank [x] == rank [y])
					rank [x]++;
			}
		}
		bool same(int x,int y) {
			return find (x) == find (y);
		}
		int comp(edge e1, edge e2) {
			if (e1.cost < e2.cost) return -1;
			else return 1;
		}
		int V,E;
		int kruskal(edge[] es) {
			Array.Sort (es, comp);
			init (V);
			int res=0;
			for(int i=0; i<E; i++) {
				edge e = es [i];
				if(!same(e.from,e.to)) {
					unite (e.from, e.to);
					res+=e.cost;
				}
			}
			return res;
		}
		void run() {
			Scanner cin = new Scanner();
			V = cin.nextInt ();
			E = cin.nextInt ();
			edge[] es = new edge[E];
			for (int i = 0; i < E; i++) {
				es[i].from = cin.nextInt ();
				es[i].to = cin.nextInt ();
				es[i].cost = cin.nextInt ();
			}
			Console.WriteLine("{0}",kruskal(es)); 
		}
	}

	class Scanner {
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner() {
			s = new string[0];
			i = 0;
		}
		public string next() {
			if (i < s.Length) return s[i++];
			s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 0;
			return s[i++];
		}
		public int nextInt() {
			return int.Parse(next());
		}
		public long nextLong() {
			return long.Parse(next());
		}
		public double nextDouble() {
			return double.Parse(next());
		}
	}
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const double EPS = 1e-9;

bool compare( const Pll& left, const Pll& right ) {
    return (left.first - left.second) > (right.first - right.second);
}

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

    int x,y,z;
    cin >> x >> y >> z;
    int n = x+y+z;
    vector<Pll> ab(n);
    ll csum = 0LL;
    rep(n){
        ll a,b,c;
        cin >> a >> b >> c;
        ab[i].first = a-c;
        ab[i].second = b-c;
        csum += c;
    }
    sort(all(ab), compare);

    // aの最大化
    vector<ll> a(n, 0LL);
    priority_queue<ll, vector<ll>, greater<ll> > que;
    rep(x){
        que.push(ab[i].first);
        a[x] += ab[i].first;
    }
    reppp(k, x+1, x+z+1){
        que.push(ab[k-1].first);
        a[k] = a[k-1] + ab[k-1].first  - que.top();
        que.pop();
    }

    // bの最大化
    vector<ll> b(n, 0LL);
    que = decltype(que)();
    rep(y){
        que.push(ab[n-1-i].second);
        b[x+z] += ab[n-1-i].second;
    }
    for(int k=x+z-1;k>=x;k--){
        que.push(ab[k].second);
        b[k] = b[k+1] + ab[k].second - que.top();
        que.pop();
    }

    ll ans = LLONG_MIN;
    reppp(k, x, x+z+1){
        ans = max(ans, a[k]+b[k]);
    }
    cout << ans+csum << endl;
}


Measured memory_bytes: 4600
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	int n;
	cin >> n;
	map<int, int>mpp;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		mpp[a[i]]++;
	}
	for (int i = 0; i < n; i++)
	{
		mpp[a[i]]--;
		bool ok = 0;
		for (auto x = mpp.rbegin(); x != mpp.rend(); x++)
		{
			if (x->ss > 0) {
				cout << x->ff << endl;
				ok |= 1;
				break;
			}
		}
		mpp[a[i]]++;
		if (!ok)
			cout << a[i] << endl;

	}
	return 0;
}

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

uint64_t calc_l(uint64_t a, uint64_t b) {
  return a+b;  
}

int main() {
  int N;
  cin >> N;
  
  uint64_t l_l = 1;
  uint64_t l_ll = 2;

  for (int i = 0; i < N-1; i++) {
    uint64_t a = calc_l(l_l, l_ll);
    l_ll = l_l;
    l_l = a;
  }

  cout << l_l << endl;

}


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

#define scanll(a) scanf("%lld",&a)
#define printll(a) printf("%lld\n",a)

map<string,ll>ar;
string str;

int main()
{
    ll n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>str;
        sort(str.begin(),str.end());
        if(!ar[str])
            ar[str]++;

        else
        {
            ans+=ar[str];
            ar[str]++;
        }
    }

    cout<<ans<<endl;


}


Measured memory_bytes: 11136
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	int n;
	cin >> n;

	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}
	vector<int> b = a;

	sort(b.begin(), b.end());

	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (a.at(i) != b.at(i))
		{
			cnt++;
		}
	}

	cout << (cnt <= 2 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
N,M,X = map(int,input().split())
A = list(map(int,input().split()))

A.append(X)
A.sort()

A_index = A.index(X)

len_bef = len(A[0:A_index])
len_aft = len(A[A_index+1:])
ans = len_bef

if len_bef > len_aft:
    ans = len_aft

print(ans)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b,w;
	cin>>w>>a>>b;
	if(a+w>=b&&a<=b+w){
		cout<<0<<endl;
	}
	else if(b+w>=a&&b<=a+w){
		cout<<0<<endl;
	}
	else if(a+w<b){
		cout<<b-(a+w)<<endl;
	}
	else if(b+w<a){
		cout<<a-(b+w)<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

	int a,i,t=0,sum=0;

	scanf("%d",&a);

	long int d[100001];

	scanf("%ld",&d[0]);

	for (i = 1;i < a;i++) {
		scanf("%ld", &d[i]);

			if (d[i] <= d[i - 1])
				t++;
			else {
				if (t > sum) { sum = t; }
				t = 0;
			}
	}
	
	
	if (t > sum)sum = t;

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 896
N=int(input())
S=input()

minind={}
maxind={}

for i,c in enumerate(S):
    if c not in minind:
        minind[c]=i
    maxind[c]=i

cnt=[0 for i in range(N+1)]

for c in [chr(i) for i in range(97,97+26)]:
    if c in minind and minind[c]<maxind[c]:
        for j in range(minind[c]+1,maxind[c]+1):
            cnt[j]+=1

print(max(cnt))

Measured memory_bytes: 3064
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b, c] <- getIntList
    print $ max 0 (c - (a - b))

Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  char a, b; cin >> a >> b;
  if (a == b) {
    cout << 'H' << endl;
  } else {
    cout << 'D' << endl;
  }
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 998244353LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace __gnu_pbds;
using namespace std ;

typedef pair<i64, i64> pii;
typedef tree< pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 200005

vector < pair<int,int> > vp ;

int main()
{
    int n ;

    scanf("%d",&n) ;

    int m = (n|1)^1 ;

    for(int i=1 ; i<=m ; i++)
    {
        for(int j=i+1 ; j<=n ; j++)
        {
            if( j!= m-i+1 ) vp.pb( mp( i,j ) ) ;
        }
    }

    printf("%d\n",(int)vp.size()) ;

    for(int i=0 ; i<vp.size() ; i++) printf("%d %d\n",vp[i].xx,vp[i].yy) ;

    return 0 ;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n = in();
  rep(i,n) {
    char s;
    cin >> s;
    if (s == 'Y') {
      puts("Four");
      return 0;
    }
  }
  puts("Three");
  return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int, input().split()))
A.append(0)
L=[0]*N
L[0]=1000

# dpしろ

for i in range(1,N):
    B=[0]*(i+1)
    for j in range(i):
        t=L[j]//A[j]
        B[j]=L[j]%A[j] + t*A[i]
    B[i]=L[i-1]
    L[i]=max(B)
print(L[N-1])

Measured memory_bytes: 67320
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<std::string> s(n);
	for(int i = 0; i < n; i++) cin >> s[i];
	std::vector<std::string> vec = s;
	sort(begin(vec), end(vec)); vec.erase(unique(begin(vec), end(vec)), end(vec));
	
	if(vec.size() < s.size()) {
		cout << "No" << endl;
		return 0;
	}
	
	for(int i = 0; i < n - 1; i++) {
		if(s[i].back() != s[i + 1].front()) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}


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

int main() {
  int N, P, A = 0, B = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> P;
    A += P;
    B = max(B, P);
  }

  cout << A - B / 2 << endl;
}

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

//n
int main() {
    int matrix[3][3];
    map<int,pair<int,int>>map;
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
            cin >> matrix[i][j];
            map[matrix[i][j]] = pair<int,int>(i,j);
        }
    }
    int t;
    cin >> t;
    while (t--){
        int i;
        cin >> i;
        if(map.count(i) != 0){
            auto p = map[i];
            matrix[p.first][p.second] = -1;
        }
    }
    bool find = false;
    for(int i = 0;i < 3;i++){
        if(matrix[i][0] == -1 && matrix[i][1] == -1 && matrix[i][2] == -1)
            find = true;
        if(matrix[0][i] == -1 && matrix[1][i] == -1 && matrix[2][i] == -1)
            find = true;
    }
    if(matrix[0][0] == -1 && matrix[1][1] == -1 && matrix[2][2] == -1)
        find = true;
    if(matrix[0][2] == -1 && matrix[1][1] == -1 && matrix[2][0] == -1)
        find = true;
    if(find)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3608
#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 200001;



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

    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;
    cin >> a >> b;
    if(b >= a){
        cout << "unsafe\n";
    }
    else{
        cout << "safe\n";
    }

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        string s;
        int y, m, d;
        while(cin>>s && s!="#"){
                scanf("%d%d%d", &y, &m, &d);
                if((y==31 && m>=5) || y>31) s="?", y-=30;
                cout << s << " ";
                printf("%d %d %d\n", y, m, d);
        }
}


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

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

int main()
{
	int N;
	cin >> N;
	while(isPrime(N) == false) N++;
	cout << N << endl;
	return 0;
}

Measured memory_bytes: 256
def dfs(A):
    if len(A) == n+1:
        global ans
        total = 0
        for i in range(q):
            if A[b[i]]-A[a[i]] == c[i]:
                total += d[i]
        if total > ans:
            ans = total
        return
    num = A[-1]
    while num <= m:
        dfs(A[:]+[num])
        num += 1
    
                

if __name__ == "__main__":
    n, m, q = map(int, input().split())
    a, b, c, d = [None]*q, [None]*q, [None]*q, [None]*q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
    ans = 0
    dfs([1])
    print(ans)

Measured memory_bytes: 9072
#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top+1];
}

int main() {
	int a, b;
	top = 0;
	char s[100];

	while (cin >> s) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-'){
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}
	cout << pop() << endl;
	return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i > 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  ll s, c, anser = 0;
  cin >> s >> c;
  if (s > c / 2) {
    anser = c / 2;
  } else  {
    anser += s + (c - 2 * s) / 4; 
  }
  cout << anser << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int f(int x){
	int t=0;
	while(x){
		t+=x%10;
		x/=10;
	}
	return t;
}

int n;

int main(){
	cin>>n;
	int res=inf;
	for(int i=1;i<n;i++){
		int A=i,B=n-i;
		res=min(res,f(A)+f(B));
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
    long long a,b,n,x;
    //long long s=100;
    cin>>a>>b>>n;
    x=b-1;
    if(x>n)x=n;
    cout<<floor((x*a)/b);
}


Measured memory_bytes: 3752
import java.util.*;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long ans = 0;
        long c=0;
        long g=0;
        for(int i=1;i<=N;i++){
            if(i%K==0){
                c++;
            }
            if(K%2==0&&i%K==K/2){
                g++;
            }
        }
        System.out.println((long)Math.pow(c,3)+(long)Math.pow(g,3));
    }
}



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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.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 iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

long long dp[200010][3];  // r = 0, s = 1, p = 2

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

    REP(i, N) {
        REP(j, 3) {
            REP(k, 3) {
                if (j == k) continue;
                if (T[i] == 's' && k == 0) {
                    dp[i + K][k] = max(dp[i + K][k], dp[i][j] + R);
                }

                if (T[i] == 'p' && k == 1) {
                    dp[i + K][k] = max(dp[i + K][k], dp[i][j] + S);
                }

                if (T[i] == 'r' && k == 2) {
                    dp[i + K][k] = max(dp[i + K][k], dp[i][j] + P);
                }

                dp[i + K][k] = max(dp[i + K][k], dp[i][j]);
            }
        }
    }
    long long ans = 0;
    for (int i = N; i < N + K; i++) {
        ans += max(max(dp[i][0], dp[i][1]), dp[i][2]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4608