akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  string A,B,C,ans="NO";
  cin>>A>>B>>C;
  if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0])
    ans="YES";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
(L, N) = map(int, input().split())
X = [0 for i in range(N)]
sumld = [0 for i in range(N)]
sumrd = [0 for i in range(N)]
for i in range(N):
    X[i] = int(input())
    sumld[i] = X[i]*2 if i == 0 else sumld[i-1] + X[i]*2
for i in range(N):
    sumrd[N-1-i] = (L-X[N-1-i])*2 if i == 0 else sumrd[N-1-i+1] + (L-X[N-1-i])*2
#print('X: ', X)
#print('sumld: ', sumld)
#print('sumrd: ', sumrd)

ans = 0
if N == 1:
    ans = max(X[0], L-X[0])
else:
    dmax = 0
    for i in range(1, N):
        l = (N-1+i)%N
        r = i
        lnum = l+1
        rnum = N-lnum
        #print('l: ', l)
        #print('r: ', r)
        #print('lnum: ', lnum)
        #print('rnum: ', rnum)

        # start from l
        d = 0
        # end at l
        if lnum > rnum:
            d = sumld[l] + sumrd[r] - X[l]
            if lnum-rnum > 1:
                d -= sumld[l-rnum-1]
        # end at r
        else:
            d = sumld[l] + sumrd[r] - X[l]
            if rnum-lnum > 0:
                d -= sumrd[r+lnum]
        #print('d from l: ', d)
        if d > dmax:
            dmax = d

        # start from r
        d = 0
        # end at l
        if lnum >= rnum:
            d = sumld[l] + sumrd[r] - (L-X[r])
            if lnum-rnum > 0:
                d -= sumld[l-rnum]
        # end at r
        else:
            d = sumld[l] + sumrd[r] - (L-X[r])
            if rnum-lnum > 1:
                d -= sumrd[r+lnum+1]
        #print('d from r: ', d)
        if d > dmax:
            dmax = d
    ans = dmax

print(ans)


Measured memory_bytes: 30052
from collections import deque
import sys

input = sys.stdin.readline

n = int(input())
Qs = deque()

for i in range(n):
    
    OPs = input().split()
    
    op = OPs[0]
    
    if op[0] == 'i':
        Qs.appendleft(OPs[1])
        continue
    if op == 'delete':
        try:
            Qs.remove(OPs[1])
        except ValueError:
            pass
        continue
    if op == 'deleteFirst':
        Qs.popleft()
        continue
    if op == 'deleteLast':
        Qs.pop()
        continue

print(" ".join(map(str, Qs)))


Measured memory_bytes: 69732
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=100005;
int n,m,v,p;
int a[N],ans;
ll b[N];
int main(){
	scanf("%d%d%d%d",&n,&m,&v,&p);
	For(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	For(i,1,n) b[i]=b[i-1]+a[i];
	bool fl=0;
	int sum=0;
	For(i,1,n){
		++sum;
		if (a[i]!=a[i+1]||i==n){
			if (i>n-p){
				ans+=sum;
				sum=0;
				continue;
			}
			int v1=a[i]+m;
			if (a[n-p+1]>v1) fl=0;
			else{
				int pos=n-p+1;
				ll val=1ll*(pos-i)*v1-(b[pos]-b[i]);
				ll v2=1ll*max(0,v-i-p+1)*m;
				fl=(v2<=val);
			}
			if (fl) ans+=sum;
			sum=0;
		}
	}
	printf("%d\n",ans);
}
/*
6 1 5 3
0 1 1 2 2 2
*/

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

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

  int count=0;

  for(int i=0;i<s.length();i++){
    if(s.substr(i,1) == "o"){
        count++;
      }
  }

  cout << 700 + count*100 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

void swap(int x,int y){
    int tmp = x;
    x = y;
    y = tmp;
}

long gcd(int a, int b){
    if(a==b) return a;
    if(a<b) swap(a,b);
    if (b == 0) return a;
    return gcd(b, a%b);
}
long gcd3(int a, int b, int c){
    return gcd(a,gcd(b,c));
}

int main(){
    int K = 0;
    scanf("%d",&K);
    long ans = 0;
    for(int a = 1; a <= K; a++){
        for(int b = 1; b <= K; b++){
            for(int c = 1; c <= K; c++){
                ans+=gcd3(a,b,c);
            }
        }
    }
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 1732
#include <string>
#include <iostream>
using namespace std;
string cf = "CODEFESTIVAL2016";
int main()
{
    string a;
    int cnt = 0;
    cin >> a;
    for(int i = 0;i < 16;i++)
    {
        if(cf[i] != a[i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int N=2e5+10;
ll cnt[N];
ll arr[N];
int main()
{
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        cnt[arr[i]]++;
    }
    for(int i=0;i<N;i++){
        sum+=(cnt[i]*(cnt[i]-1))/2;
    }
    for(int i=1;i<=n;i++)
    {
        ll ans=sum-(cnt[arr[i]]*(cnt[arr[i]]-1))/2;
        ans+=(cnt[arr[i]]-1)*(cnt[arr[i]]-2)/2;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4736
//

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

ll x[1000];
ll y[1000];
ll z[1000];

ll s[8][1000];

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

	for (int i=0; i<N; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}

	// 綺麗さ+ 美味しさ+ 人気度+
	for (int i=0; i<N; i++) {
		s[0][i] = x[i] + y[i] + z[i];
	}

	// 綺麗さ- 美味しさ+ 人気度+
	for (int i=0; i<N; i++) {
		s[1][i] = - x[i] + y[i] + z[i];
	}

	// 綺麗さ+ 美味しさ- 人気度+
	for (int i=0; i<N; i++) {
		s[2][i] = x[i] - y[i] + z[i];
	}

	// 綺麗さ+ 美味しさ+ 人気度-
	for (int i=0; i<N; i++) {
		s[3][i] = x[i] + y[i] - z[i];
	}

	// 綺麗さ- 美味しさ- 人気度+
	for (int i=0; i<N; i++) {
		s[4][i] = - x[i] - y[i] + z[i];
	}

	// 綺麗さ+ 美味しさ- 人気度-
	for (int i=0; i<N; i++) {
		s[5][i] = x[i] - y[i] - z[i];
	}

	// 綺麗さ- 美味しさ+ 人気度-
	for (int i=0; i<N; i++) {
		s[6][i] = - x[i] + y[i] - z[i];
	}

	// 綺麗さ- 美味しさ- 人気度-
	for (int i=0; i<N; i++) {
		s[7][i] = - x[i] - y[i] - z[i];
	}

	ll ans = 0;
	for (int i=0; i<8; i++) {
		ll m = 0;
		sort(s[i], s[i]+N, greater<ll>());

		for (int j=0; j<M; j++) {
			m += s[i][j];
		}

		ans = max(ans, m);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10

vector<vector<int>> g(100010);

ll d[100010][3];


int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v);
	}
	int S, T; cin >> S >> T;

	for (int i = 0; i < 100010; i++) {
		for (int j = 0; j < 3; j++) {
			d[i][j] = INF10;
		}
	}
	d[S][0] = 0;

	queue<P> que;
	que.push(P(S, 0));
	while (que.size()) {
		P p = que.front(); que.pop();
		int current_v = p.first;
		int nxl = (p.second + 1) % 3;
		for (int i = 0; i < g[current_v].size(); i++) {
			int nxt_v = g[current_v][i];
			if (d[nxt_v][nxl] != INF10)continue;
			d[nxt_v][nxl] = d[current_v][p.second] + 1;
			que.push(P(nxt_v, nxl));
		}
	}
	int ans = d[T][0];
	if (ans == INF10)ans = -1;
	else ans /= 3;
	cout << ans << endl;




	return 0;
}


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

void io()

{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}

void dbg(int a)
 {
    cout<<"HELLO"<<a;
    cout<<"\n";
 }

ll sm(vector<ll> v)
 {
     ll sum=0;
     for(int i=0; i<v.size(); i++)
        sum+=v[i];
    return sum;
 }

void print(vector<ll> v)
 {
     for(int i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
 }

 void print(vector<int> v)
 {
     for(int i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
 }

 void print(map<int, int> m)
 {
     for(auto it=m.begin(); it!=m.end(); it++)
          cout<<it->first<<"  "<<it->second<<"\n";

 }


ll srt(ll x)
 {
    ll i=1;
    while(i*i <= x)
       i++;
    i--;
    return i;
 }
vector<vector<ll>> matmul(vector<vector<ll>> a, vector<vector<ll>>b)
{

    int n = a.size();
    int m = a[0].size();
    int p = b[0].size();
    vector<vector<ll>> c(n, vector<ll>(p,0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < p; j++)
        {

            for (int k = 0; k < m; k++)
                c[i][j]+= a[i][k]*b[k][j];
        }
    }
   return c;
}

vector<vector<ll>> matexp(vector<vector<ll>> A , ll n)
{
     if(n==1)
       return A;
    vector<vector<ll>> c = matexp(A,n/2);
    c = matmul(c,c);
    if(n%2==0)
      return c;
    return matmul(A,c);
}

ll binexp(ll A, ll n)
{
   if(n==1)
     return A;
   ll c = binexp(A,n/2);
   if(n%2==0)
     return c*c;
    return A*c*c;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


vector<int> adj[200002];
vector<bool> vis(200002, false);
vector<int> aux;
void dfs(int i)
{
    vis[i]=true;
    aux.push_back(i);
    for(auto p:adj[i])
    {
        if(!vis[p])
           dfs(p);
    }
}


int solve()
{
   io();
  ll n ;
  cin>>n;

  ll ans = 0;
  for(int i=1; i<=n; i++)
  {
      ll y = n/i;
      ans+= (y*(y+1))/2 * i;

  }
  cout<<ans;
   return 0;

}




int main()
{
    solve();
}


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

ll nck(ll n, ll k){
    
    ll p=1000000007;
    ll p2;
    p2=p-2;
    vector <int> r(35);
    vector <ll> r2(36);

    rep(j,35){
        r[j]=(p2>>j)&1;
    }

    ll ans;
    ans=1;

    if (k!=0){
    rep(i,k-1){   
        r2[0]=i+2;
        rep(j,35){
           
            r2[j+1]=(r2[j]*r2[j])%p;
            if(r[j]==1){
            ans*=r2[j];
            ans=ans%p;
            }
        }
    }
    rep(i,k){
        ans*=n-i;
        ans=ans%p;
    }
    }
    return ans;
}


int main(){
    int n,p;
    cin >> n >>p;
    int g,k;
    g=0;
    k=0;
    int a;
    rep(i,n){
        cin >> a;
        if(a%2==0){
            ++g;
        }
        else{
            ++k;
        }
    }

    ll ans=1;
    
        rep(i,n-1){
            ans*=2;
        }

        if(p==1 and k==0){
            ans=0;
        }
        if(p==0 and k==0){
            ans*=2;
        }
        

    cout << ans << endl;




    

    return 0;
}


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

long long int x[100], y[100];
set<pair<long long int, long long int> > S;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        S.emplace(x[i], y[i]);
    }
    int ans = n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            if (i == j)
                continue;
            int dx = x[i] - x[j], dy = y[i] - y[j];
            int tans = n;
            for (int t = 0; t < n; t++)
                if (S.count(make_pair(x[t] + dx, y[t] + dy)) == 1)
                    tans--;
            ans = min(ans, tans);
        }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100005;
int n,a[N],pos[N];
int pre[N],nxt[N];
ll ans;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]),pos[a[i]]=i;
	for (int i=0;i<=n+1;i++)
		pre[i]=max(0,i-1),nxt[i]=min(n+1,i+1);
	ll S=1ll*n*(n-1)/2;
   	for (int i=1;i<=n;i++){
   		ans+=S;
   		int x=pos[i];
   		S-=1ll*(pre[x]-pre[pre[x]])*(nxt[x]-x);
   		S-=1ll*(nxt[nxt[x]]-nxt[x])*(x-pre[x]);
   		pre[nxt[x]]=pre[x];
   		nxt[pre[x]]=nxt[x];
	}
	printf("%lld\n",ans);
}

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

int N,M;
ll ans[200010];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    vector<pair<ll,pair<ll,ll> > > X;
    set<pair<ll,ll> > D;
    REP(i,N){
        int s,t,x;
        cin >> s >> t >> x;
        X.push_back(make_pair(x,make_pair(s-x,t-x)));
    }
    REP(i,M){
        int d;
        cin >> d;
        D.insert(make_pair(d,i));
        ans[i] = -1;
    }

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

    REP(i,X.size()){
        if(D.empty()) break;
        // l <= start time < r の人は、xで止まる。
        ll x = X[i].first;
        ll l = X[i].second.first;
        ll r = X[i].second.second;

        auto itr = D.lower_bound(make_pair(l,-1));
        while(D.size() && itr != D.end() && (*itr).first < r){
            ans[(*itr).second] = x;
            D.erase(itr++);
        }
    }
    REP(i,M) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 21356
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
//#define INF 1e16
typedef long long ll;
typedef pair<int,vector<ll> > P;
typedef pair<P,ll>Q;
 
const int MAX_N = 200005;
const int INF = 1001001001;
vector<int>g[MAX_N];
vector<int>a,ans;
int dp[MAX_N];

void dfs(int v,int p=-1){
    int index = lower_bound(dp,dp+MAX_N,a[v])-dp;
    ll old = dp[index];
    dp[index]=a[v];
    ans[v] = index;
    if(p!=-1)ans[v]=max(ans[v],ans[p]);
    for(int j=0;j<(ll)g[v].size();j++){
        int next = g[v][j];
        if(next == p)continue;
        dfs(next,v);
    }
    dp[index] = old;
    return;
}

int main(void){
    ll n;
  cin>>n;
   a = ans = vector<int>(n);
  for(ll i=0;i<n;i++)cin>>a[i];
  for(ll i=0;i<n-1;i++){
    ll u,v;
    cin>>u>>v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for(ll i=0;i<MAX_N;i++)dp[i]=INF;
  dp[0]=-INF;
  dfs(0);
  for(int i=0;i<n;i++)cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 30816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please



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


	int N, H, W;
	cin >> N >> H >> W;
	int kotae = 0;
	rep(i, N) {
		int A, B;
		cin >> A >> B;
		if (A >= H && B >= W) kotae++;
	}
	co(kotae);
	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();      
		int o=0;
      	int[] a=new int[n];
        PriorityQueue<Integer> num=new PriorityQueue<>();
        for(int i=0;i<n;i++){
        	a[i]=sc.nextInt();
            if(i>0 && a[i]==a[i-1]+1){
            	num.add(a[i-1]-1);
            }
         }
         for(int i=0;i<n;i++){
            int b=sc.nextInt();
        	o+=b;
         }
      //System.out.println(num);
         for(int i=0;i<n-1;i++){
            int c=sc.nextInt();
            
            if(num.peek()!=null && i==num.peek()){
        		o+=c;
                num.poll();
            }
         }
      	System.out.println(o);
    }  
 
}

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

#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;

int s(string x) {
    int summ = 0;
    for (char i : x) {
        int d = (int)i - (int)'0';
        summ += d;
    }
    return summ;
}
int d(string x) {
    int summ = 0;
    for (int i = 0; i < x.size(); i++) {
        int d = (int)x[i] - (int)'0';
        for (int j = 0; j < (x.size() - i - 1); j ++) {
            d *= 10;
        }
        summ += d;
    }
    return summ;
}


int main() {
    string t;
    cin >> t;
    if (d(t) % s(t) == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}



Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
long long a,b,k;
int main(){
    scanf("%lld%lld%lld",&k,&a,&b);
    if(k<=a)cout<<"1"<<endl;
    else if(a<=b)cout<<"-1"<<endl;
    else printf("%lld\n",((k-a)/(a-b)+bool((k-a)%(a-b)))<<1|1);
}

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

if b > a:
    a, b = b, a

if (a - b) % 2 == 0:
    print((a - b) // 2)
else:
    print(min(a - 1, n - b) + 1 + (b - a - 1) // 2)
    

Measured memory_bytes: 3188
// https://atcoder.jp/contests/abc125/tasks/abc125_a

#include <bits/stdc++.h>
using namespace std;
int solve()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, t, n, ans = 0, count = 0;
  string s;
  vector<int> v(n, 0);
  cin >> a >> b >> t;

  ans = t / a;

  cout << ans * b << endl;
  return 0;
}
signed main()
{
  solve();
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, b;
    int i, len=10, count=0;

    scanf("%d", &n);

    b=n;

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

        count = count + (n%len);
        len*10;
        n = n - (n%len);
        n = n /10;
    }
    if(b%count==0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

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

  
int main() {
  int N,L;
  cin >>N>>L;
  vector<string> v(N);
  rep(i,N)cin>>v[i];
  sort(v.begin(),v.end());
  rep(i,N) cout<< v[i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
data = list(map(int, input().split(" ")))

ans = 0
while True:
    for i in range(N):
        # print(data[i])
        if data[i] % 2 == 0:
            data[i] = int(data[i]/2)
        else:
            print(ans)
            exit()
    ans += 1


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
    	cin >> a[i];
    }
    bool niko = true;
    vector<int> v;
    v.pb(a[0]);

    for(int i=1;i<n;i++){
    	if(niko){
    		if(a[i] > v.back()){
    			v.pb(a[i]);
    			niko ^= 1;
    		}else{
    			v.back() = a[i];
    		}
    	}else{
    		if(a[i] < v.back()){
    			v.pb(a[i]);
    			niko ^= 1;
    		}else{
    			v.back() = a[i];
    		}
    	}
    }
    ll ans = 1000, num = 0;
    ll maki = v.size();
    if(maki & 1) maki--;
    for(int i=0;i<maki;i++){
    	if(i&1){
    	    ans += num * v[i];
    	    num = 0;
    	}else{
    		num += ans / v[i];
    		ans %= v[i];
    	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
import math as mt
n,d = map(int,input().split())
x = []
count = 0
for i in range(n):
    x.append(list(map(int,input().split())))

for i in range(n-1):
    for s in range(i+1,n):
        dist = 0
        for j in range(d):
            dist += (x[i][j]-x[s][j])**2
        dist = mt.sqrt(dist)
        if dist.is_integer()==True:
            count += 1
print(count)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if (a<b&&b<c){
printf("%d %d %d\n",a,b,c);
}
else if (a<c&&c<b){
printf("%d %d %d\n",a,c,b);
}
else if (b<a&&a<c){
printf("%d %d %d\n",b,a,c);
}
else if (b<c&&c<a){
printf("%d %d %d\n",b,c,a);
}
else if (c<a&&a<b){
printf("%d %d %d\n",c,a,b);
}
else if (c<b&&b<a){
printf("%d %d %d\n",c,b,a);
}
else if (a==b&&a<c){
printf("%d %d %d\n",a,b,c);
}
else if (a==b&&a>c){
printf("%d %d %d\n",c,a,b);
}
else if (a==c&&a<b){
printf("%d %d %d\n",a,c,b);
}
else if (a==c&&a>b){
printf("%d %d %d\n",b,a,c);
}
else if (b==c&&b<a){
printf("%d %d %d\n",b,c,a);
}
else if (b==c&&b>a){
printf("%d %d %d\n",a,b,c);
}

return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e9;
const int maxN = 100 * 1000 + 9;

int n;
int a[maxN], f[maxN], g[maxN];

void read(){
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> a[i];
}

void solv(){
  for(int i = 0; i < n; i += 2)
    f[a[i]]++;

  for(int i = 0; i < maxN; i++)
    f[i] = (n / 2) - f[i];

  int mn1 = 0, mn2 = 0;
  for(int i = 0; i < maxN; i++){
    if(f[i] < f[mn1]){
      mn2 = mn1;
      mn1 = i;
    } else if(f[i] < f[mn2])
      mn2 = i;
  }

  int ans = INF;
  for(int i = 1; i < n; i += 2)
    g[a[i]]++;

  for(int i = 0; i < maxN; i++){
    g[i] = (n / 2) - g[i];
    if(i == mn1)
      ans = min(ans, f[mn2] + g[i]);
    else
      ans = min(ans, f[mn1] + g[i]);
  }

  cout << ans << '\n';
}

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

  read();
  solv();

  return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#define N_MAX 100000
#define L_MAX 20
void fill(int *a, int l, int r, int x) {
	for(int i = l; i <= r; ++i) {
		a[i] = x;
	}
	return;
}
int find_root(int *a, int x) {
	int s[L_MAX + 1];
	int k = 0;
	while(a[x] >= 1) {
		s[++k] = x;
		x = a[x];
	}
	while(k) {
		a[s[k--]] = x;
	}
	return x;
}
void unite_set(int *a, int x, int y) {
	x = find_root(a, x);
	y = find_root(a, y);
	if(a[x] < a[y]) {
		a[x] += a[y];
		a[y] = x;
	} else {
		a[y] += a[x];
		a[x] = y;
	}
	return;
}
int set_size(int *a, int x) {
	return -a[find_root(a, x)];
}
int main(int argc, char **argv) {
	int n, m, k;
	scanf("%i%i%i", &n, &m, &k);
	int s[N_MAX + 1];
	fill(s, 1, n, -1);
	int rmv[N_MAX + 1];
	fill(rmv, 1, n, 1);
	while(m--) {
		int a, b;
		scanf("%i%i", &a, &b);
		if(find_root(s, a) != find_root(s, b)) {
			unite_set(s, a, b);
		}
		++rmv[a];
		++rmv[b];
	}
	while(k--) {
		int c, d;
		scanf("%i%i", &c, &d);
		if(find_root(s, c) == find_root(s, d)) {
			++rmv[c];
			++rmv[d];
		}
	}
	for(int i = 1; i <= n; ++i) {
		printf("%i%c", set_size(s, i) - rmv[i], i == n ? '\n' : ' ');
	}
	return 0;
}

Measured memory_bytes: 2516
<?php

// x - r > 0
// x + r < W

// y - r > 0
// y + r < H

fscanf(STDIN,"%d %d %d %d %d",$W,$H,$x,$y,$r);

if ($x - $r >= 0 && $x + $r <= $W &&
    $y - $r >= 0 && $y + $r <= $H) {
        echo "Yes".PHP_EOL;
    } else {
        echo "No".PHP_EOL;
    }

?>


Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>
using namespace std;

#define ll long long

int main() {
	int n, a[100010], ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	a[n] = -1;
	for (int i = 0; i < n;) {
		if (a[i + 1] == -1) {
			i++;
			ans++;
		}else if (a[i + 1] - a[i] > 0) {
			while (a[i + 1] - a[i] >= 0) {
				i++;
			}
			ans++;
			i++;
		}
		else if (a[i + 1] - a[i] < 0) {
			while (a[i + 1] - a[i] <= 0) {
				i++;
			}
			ans++;
			i++;
		}else i++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
num = []
for i in sys.stdin:
    H, W = i.split()
    if H == W == '0':
        break
    num.append((int(H), int(W)))

for cnt in range(len(num)):
    for h in range(num[cnt][0]):
        for w in range(num[cnt][1]):
            print('#',end='')
        print()
    print()

Measured memory_bytes: 8984
from collections import deque
from itertools import product


def bfs(x, y):
    dist = [[10 ** 9] * w for _ in range(h)]
    dist[y][x] = 0
    que = deque([(x, y, dist[y][x])])

    while len(que) > 0:
        x, y, d = que.popleft()
        if (x, y) == (Dw - 1, Dh - 1):
            return dist[y][x]

        for i, j in product(range(-2, 3), repeat=2):
            cnt = (abs(i) + abs(j) >= 2)
            i, j = x + i, y + j
            if (0 <= i < w and 0 <= j < h and
                    dist[j][i] > d + cnt and s[j][i] == '.'):
                dist[j][i] = d + cnt
                if cnt == 0:
                    que.appendleft((i, j, d + cnt))
                elif cnt == 1:
                    que.append((i, j, d+cnt))
    return -1


h, w = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
s = [input() for _ in range(h)]

print(bfs(Cw - 1, Ch - 1))


Measured memory_bytes: 125580
#include<stdio.h>
int main()
{
    int a,b,c,d,e,g,f;
    scanf("%d %d",&a,&b);
    c=a+b;
    d=a-b;
    e=a*b;
    {
        if(c>d)
        {
            f=c;
        }
        else f=d;
    }
    {
        if(f>e)
        {
            g=f;
        }
        else g=e;
    }
    printf("%d\n",g);
    return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <map>

const int mod = 1000000007;
//const int mod = 998244353;
int maximum(int a, int b) { return a < b ? b : a; }

long long K3(char* S, int N, int n0) {
	long long res = 0;
	int s = 0;
	for (int i = 0; i < maximum(n0, 3); i++) {
		while (1) {
			if (S[s] == 0)break;
			if (S[s] != '0') {
				int a = S[s] - '0';
				int m = N - s;
				switch (i) {
				case 0:
					res += 9LL * 9 * 9 * (N - 1)*(N - 2)*(N - 3) / 6;
					res += (a - 1) * 9LL * 9 * (N - 1)*(N - 2) / 2;
					if (n0 == 1) {
						//res += 9LL * 9 * (N - 1)*(N - 2) / 2;
					}
					break;
				case 1:
					res += 9 * 9 * (m - 1)*(m - 2) / 2;
					res += (a - 1) * 9 * (m - 1);
					if (n0 == 2) {
						//res += 9 * (m - 1);
					}
					break;
				case 2:
					int k = N - s;
					res += 9 * (k - 1);
					res += a;
					break;
				}
				s++;
				break;
			}
			s++;
		}
	}
	return res;
}

long long K2(char*S, int N, int n0) {
	long long res = 0;
	int s = 0;
	for (int i = 0; i < maximum(n0, 2); i++) {
		while (1) {
			if (S[s] == 0)break;
			if (S[s] != '0') {
				int a = S[s] - '0';
				int m = N - s;
				switch (i) {
				case 0:
					res += 9LL * 9 * (N - 1)*(N - 2) / 2;
					res += (a - 1) * 9LL * (N - 1);
					if (n0 == 1) {
						//res += 9LL * (N - 1);
					}
					break;
				case 1:
					res += 9 * (m - 1);
					res += a;
					break;
				}
				s++;
				break;
			}
			s++;
		}
	}
	return res;
}
int K1(char*S, int N, int n0) {
	int res = 9 * (N - 1);
	res += S[0] - '0';
	return res;
}
int main() {
	char S[101];
	scanf("%s", S);
	int K;
	scanf("%d", &K);
	int n0 = 0;
	int N = 0;
	for (; S[N] != 0; N++) {
		if (S[N] != '0') {
			n0++;
		}
	}
	long long res;
	switch (K)
	{
	case 1:
		res = K1(S, N, n0);
		break;
	case 2:
		res = K2(S, N, n0);
		break;
	case 3:
		res = K3(S, N, n0);
		break;
	}
	printf("%lld", res);
	return 0;
}

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

struct Edge
{
    int a, b;

    Edge(int node1, int node2)
    {
        a = node1;
        b = node2;
    }
};

int main(int argc, char *argv[])
{
    int n, k;
    int count;

    std::vector<Edge> e;

    std::cin >> n >> k;

    e.reserve(10000);

    for (int i = 2; i <= n; i++) {
        e.push_back(Edge(1, i));
    }

    count = (n - 1) * (n - 2) / 2;

    if (count < k) {
        std::cout << -1 << std::endl;
        return 0;
    }

    int i = 2;
    int delta = 1;
    while (k < count) {
        int j = i + delta;
        e.push_back(Edge(i, j));
        count--;

        if (j == n) {
            i = 2;
            delta++;
        } else {
            i++;
        }
    }

    std::cout << e.size() << std::endl;

    const size_t e_size = e.size();
    for (int i = 0; i < e_size; i++) {
        std::cout << e[i].a << " " << e[i].b << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
int main(int argc, char const *argv[])
{
	int n,flag = 0;
	cin>>n;
	for(int i = 0;i < n; ++i)
	{
		int x;
		scanf("%d",&x);
		flag |= (x & 1);
	}
	printf("%s\n",flag ? "first" : "second");
	return 0;
}

Measured memory_bytes: 256
/* Trico */
#include <iostream>
#include <bits/stdc++.h>
#define inf 1e18
#define ll long long
#define x first
#define y second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mll map<ll, ll>
#define mii map<int, int>
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define p push
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, a[100001], dp[2][100001];
    cin>>n;
    for(int i = 0;i<n;i++) cin>>a[i];
    dp[0][n-1] = a[n-1];
    dp[1][n-1] = -a[n-1];
    for(int i = n-2;i>=0;i--){
        dp[0][i] = max(a[i] + dp[0][i+1], dp[1][i+1] - a[i]);
        dp[1][i] = max(dp[0][i+1] - a[i], dp[1][i+1] + a[i]);
        //cout<<dp[0][i]<<' '<<dp[1][i]<<'\n';
    }
    cout<<dp[0][0];
} 

Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
//    int base = 2000000;
//    int lbase = 2000000;
//    int keisu[4000000] = {};

    int N;
    string S;
    int Q;
    vector<int> K;

    void input() {
        cin >> N;
        cin >> S;
        cin >> Q;
        rep(i, 0, Q) {
            int tmp;
            cin >> tmp;
            K.push_back(tmp);
        }
    }

    ll count(int k) {
        int base = 2000000;
        int lbase = 2000000;
//        int keisu[4000000] = {};
        ll ret = 0ll;
        ll keisum = 0ll; //係数の和
        ll add = 0ll;
        ll bairitu = 0ll;

        for (int i = 0; i < S.size(); ++i) {
            if (i - k >= 0) {
                if (S[i - k] == 'D') {
//                    keisu[lbase]--;
                    keisum -= 1ll;
                    add -= bairitu;
//                    add -= keisum;
//                    add -= (lbase - base + 1);
                } else if (S[i - k] == 'M') {
//                    add -= keisum;
                    bairitu--;
                    base++;
                } else if (S[i - k] == 'C') {

                }
            }
            if (S[i] == 'D') {
//                keisu[base]++;
//                add += 1ll;
                keisum += 1ll;
            } else if (S[i] == 'M') {
                add += keisum;
                base--;
                bairitu++;
            } else if (S[i] == 'C') {
                ret += add;
            }
        }

        return ret;
    }

    void solve() {
        input();

        rep(i, 0, Q) {
            ll ans = count(K[i]);
            cout << ans << endl;
        }

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 2544
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

vector<P> Edge;
vector<vector<bool>> E(114,vector<bool>(114));

int main() {
    int N;cin >> N;
    int K;cin >> K;
    if((N-1)*(N-2)/2 - K < 0){
        cout << -1 << endl;
        return 0;
    }

    for(int i = 2;i<=N;i++){
        Edge.push_back(make_pair(1,i));
    }
    int remain = (N-1)*(N-2)/2 - K;
    int plus = remain;
    bool escape = false;
    for(int i = 2;i<=N;i++){
        if(escape) break;
        for(int j = 2;j<=N;j++){
            if(i == j) continue;
            if(remain <= 0){
                escape = true;
                break;
            }
            if(!E.at(i).at(j) && !E.at(j).at(i)){
                E.at(i).at(j) = true;
                E.at(j).at(i) = true;
                Edge.push_back(make_pair(i,j));
                remain--;
            }
        }
    }
    cout << N-1+plus << endl;
    for(P V : Edge){
        int from = V.first;
        int to = V.second;
        cout << from << " " << to << endl;
    }
}

Measured memory_bytes: 384
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strInput = Console.ReadLine().Split(' ');
            int N = int.Parse(strInput[0]);
            int T = int.Parse(strInput[1]);
            int iMinCost = 0;

            for (int i = 0; i < N; i++)
            {
                string[] strInput2 = Console.ReadLine().Split(' ');
                int iCost = int.Parse( strInput2[0]);
                int iTime = int.Parse( strInput2[1]);

                if(iTime <= T )
                {
                    if(iMinCost == 0)
                    {
                        iMinCost = iCost;
                    }
                    else if(iMinCost > iCost)
                    {
                        iMinCost = iCost;
                    }
                }
            }

            if(iMinCost != 0 )
            {
                Console.WriteLine(iMinCost);
            }
            else
            {
                Console.WriteLine("TLE");
            }
        }
    }
}

Measured memory_bytes: 11092
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

ll modpow(ll x, ll a){
    ll ans = 1;
    while(a){
        if(a & 1) ans = ans * x % MOD;
        a >>= 1;
        x = x * x % MOD;
    }
    return ans;
}

ll inv(ll x){
    return modpow(x, MOD - 2);
}


int main(){
    // CFS;
    int n;
    cin >> n;
    vi a(n);
    int b = 20;
    vi dp(1 << b, 0);
    rep(i, n){
        cin >> a[i];
        dp[a[i]]++;
    }
    rep(i, b){
        rep(j, 1 << b){
            if(j & (1 << i)) dp[j ^ (1 << i)] += dp[j];
        }
    }
    ll ans = modpow(2, n) - 1;
    vl mp(n + 1, 1);
    repl(i, 1, n + 1) mp[i] = mp[i - 1] * 2 % MOD;
    repl(i, 1, 1 << b){
        int c = 0;
        rep(j, b) if(i & (1 << j)) c++;
        ans = (ans + (mp[dp[i]] - 1 + MOD) % MOD * (1 - c % 2 * 2) + MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8052
using System;
using System.Collections.Generic;

class Program {
	public static int Main() {
#if DEBUG
		Console.WriteLine("DEBUG Mode");
#endif
		while (true)
		{
			int h, w;
			string[] size = Console.ReadLine().Split(' ');
			h = int.Parse(size[0]);
			w = int.Parse(size[1]);
			if (h == 0 || w == 0)
			{
				break;
			}
			int[,] dp = new int[h + 1,w + 1];
			for (int i = 0; i < h + 1; i++)
			{
				for (int j = 0; j < w + 1; j++)
				{
					dp[i, j] = -1;
				}
			}
			for (int i = 0; i <= h; i++)
			{
				dp[i, 0] = 0;
			}
			for (int i = 0; i <= w; i++)
			{
				dp[0, i] = 0;
			}
			dp[1, 1] = 1;
			int n = int.Parse(Console.ReadLine());
			for (int i = 0; i < n; i++)
			{
				int x, y;
				string[] str = Console.ReadLine().Split(' ');
				x = int.Parse(str[0]);
				y = int.Parse(str[1]);
				dp[x, y] = 0;
			}
			for (int i = 1; i <= h; i++)
			{
				for (int j = 0; j <= w; j++)
				{
					if (dp[i, j] == -1)
					{
						dp[i, j] = dp[i - 1, j] + dp[i, j - 1];
					}
				}
			}
			Console.WriteLine(dp[h, w]);
		}
		return 0;
	}
}

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

#define MOD 1000000007

int n;
int par[100010];
long long memo[100010][2];

vector<int> graph[100010];
vector<int> tree[100010];

bool used[100010] = {};

void makeTree(int i){
  used[i] = true;

  for(int j = 0;j < graph[i].size();j++){
    if(!used[graph[i][j]]){
      tree[i].push_back(graph[i][j]);
      makeTree(graph[i][j]);
    }
  }

  return;
}

void dp(int i){
  for(int j = 0;j < tree[i].size();j++){
    dp(tree[i][j]);
  }

  long long ans = 1;
  for(int j = 0;j < tree[i].size();j++){
    ans = (ans * (memo[tree[i][j]][0] + memo[tree[i][j]][1]) % MOD) % MOD;
  }

  memo[i][0] = ans;

  ans = 1;
  for(int j = 0;j < tree[i].size();j++){
    ans = (ans * memo[tree[i][j]][0]) % MOD;
  }

  memo[i][1] = ans;

  return;
}

int main(){
  cin >> n;

  for(int i = 0;i < n;i++) par[i] = i;
  int a, b;
  for(int i = 0;i < n-1;i++){
    cin >> a >> b;
    a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  makeTree(0);

  dp(0);

  cout << (memo[0][0] + memo[0][1]) % MOD << endl;

  return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n;
    string s;
    cin >> n >> s;
    if(n%(long)2==1){
        cout << "No" << endl;
    }else{
        string s1,s2;
        s1 = "";
        s2 = "";
        for(long i = 0; i < (n/2) ; i++){
            s1+=s[i];
            s2+=s[i+n/2];
        }
        if(s1.compare(s2)==0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            int x = ReadInt();

            int ans = 1;
            for (int i = 2; i * i <= x; i++)
            {
                int value = i;
                while (value <= x)
                {
                    ans = Max(ans, value);
                    value *= i;
                }
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

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

int main(){
  long n,cnt=0;
  cin >> n;
  long a[n+1],b[n];
  for(long i=0;i<=n;i++)
    cin >> a[i];
  for(long i=0;i<n;i++)
    cin >> b[i];
  for(long i=0;i<n;i++){
    if(a[i]+a[i+1]<=b[i]){
      cnt += a[i]+a[i+1];
      a[i+1] = 0;
    }
    if(a[i]<b[i]&&b[i]<a[i]+a[i+1]){
      cnt += b[i];
      a[i+1] -= b[i]-a[i];
    }
     if(b[i]<=a[i]){
      cnt += b[i];
    }
  }
 cout << cnt << endl;
}


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

int main(){
    int n; cin >> n;
    char c[n];
    vector<int> w, r;
    rep(i,n) {
        cin >> c[i];
        if(c[i] == 'W') w.push_back(i);
        if(c[i] == 'R') r.push_back(i);
    }
    int ans = 0;
    if(!r.empty() && !w.empty())
        while(r.back() > w.front()) {
            int k = r.back(); r.pop_back();
            int l = w.front(); w.erase(w.begin());
            w.push_back(k);
            r.insert(r.begin(),l);
            ans++;
        }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4632
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef gp_hash_table < int, int > fast;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test();

int main() {
    fast_io();
    cout << fixed << setprecision(15);
    test();
    return 0;
}

void test() {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (a[i] != b[i]);
    }
    if (ans == 2 or !ans) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}


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

ll solve() {
    ll N, a;
    cin >> N;
    vector<ll> ra(N);
    for ( ll i = 0; i < N; i++ ) {
        cin >> a;
        a--;
        ra[a] = i;
    }
    ll ans = 0;
    set<ll> s;
    for ( ll a = 0; a < N; a++ ) {
        ll i = ra[a];
        s.insert(i);
        auto p = s.find(i);
        ll l = ( p!=s.begin() ? *prev(p) : -1);
        ll r = ( next(p)!=s.end() ? *next(p) : N);
        ans += (i-l)*(r-i)*(a+1);
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 11136