akhauriyash/Code-Regression huggingface dataset:
from collections import deque
n,u,v = map(int,input().split())
branch = [list(map(int,input().split())) for _ in range(n-1)]
link = [[] for _ in range(n)]
for i in branch:
    link[i[0]-1].append(i[1]-1)
    link[i[1]-1].append(i[0]-1)

q_a = deque([u-1])
q_b = deque([v-1])
dist_a = [-1 for _ in range(n)]
dist_b = [-1 for _ in range(n)]
dist_a[u-1] = 0
dist_b[v-1] = 0
while q_a:
    check = q_a.popleft()
    for j in link[check]:
        if dist_a[j] == -1:
            dist_a[j] = dist_a[check]+1
            q_a.append(j)
while q_b:
    check = q_b.popleft()
    for m in link[check]:
        if dist_b[m] == -1:
            dist_b[m] = dist_b[check]+1
            q_b.append(m)

ans = 0
for k in range(n):
    compare = 0
    if dist_b[k]>dist_a[k]:
        compare = dist_b[k]-1

    if compare > ans:
        ans = compare

print(ans)

Measured memory_bytes: 114800
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

#define P 1000000007

using namespace std;


int n;
vector<vector<int>> v;
vector<vector<long long>> c;
vector<long long> w;

void dfs(int now, long long d) {
  if(w[now] >= 0) return;
  w[now] = d;
  for(int i = 0; i < v[now].size(); i++) {
    if(w[v[now][i]] >= 0) continue;
    dfs(v[now][i], d + c[now][i]);
  }
}

int main() {
  cin >> n;
  v.resize(n);
  c.resize(n);
  for(int i = 0; i < n - 1; i++) {
    int a, b;
    long long d;
    cin >> a >> b >> d;
    a--; b--;
    v[a].push_back(b);
    v[b].push_back(a);
    c[a].push_back(d);
    c[b].push_back(d);
  }
  w.resize(n);
  for(int i = 0; i < n; i++) w[i] = -1;
  int q, k;
  cin >> q >> k;
  dfs(k - 1, 0);
  for(int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << w[x] + w[y] << endl;
  }

  return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}


struct Die{
  int s[6];
  int &top()   {return s[0];}
  int &south() {return s[1];}
  int &east()  {return s[2];}
  int &west()  {return s[3];}
  int &north() {return s[4];}
  int &bottom(){return s[5];}
  void roll(char c){
    //the view from above
    // N
    //W E
    // S
    string b("EWNSRL");
    int v[6][4]={{0,3,5,2},
                 {0,2,5,3},
                 {0,1,5,4},
                 {0,4,5,1},
                 {1,2,4,3},
                 {1,3,4,2}};
    for(int k=0;k<6;k++){
      if(b[k]!=c) continue;
      int t=s[v[k][0]];
      s[v[k][0]]=s[v[k][1]];
      s[v[k][1]]=s[v[k][2]];
      s[v[k][2]]=s[v[k][3]];
      s[v[k][3]]=t;
    }
  }
  using ll = long long;
  ll hash(){
    ll res=0;
    for(int i=0;i<6;i++) res=res*256+s[i];
    return res;
  }
  bool operator==(const Die &d) const{
    for(int i=0;i<6;i++) if(s[i]!=d.s[i]) return 0;
    return 1;
  }
};

vector<Die> makeDice(Die d){
  vector<Die> res;
  for(int i=0;i<6;i++){
    Die t(d);
    if(i==1) t.roll('N');
    if(i==2) t.roll('S');
    if(i==3) t.roll('S'),t.roll('S');
    if(i==4) t.roll('L');
    if(i==5) t.roll('R');
    for(int k=0;k<4;k++){
      res.push_back(t);
      t.roll('E');
    }
  }
  return res;
}

//INSERT ABOVE HERE
signed main(){
  int n;
  while(cin>>n,n){
    vector<int> xs(n),ys(n);
    vector<Die> ds(n);
    vector<string> rs(n);

    for(int i=0;i<n;i++){
      cin>>xs[i]>>ys[i];
      cin>>ds[i].west();
      cin>>ds[i].east();
      cin>>ds[i].south();
      cin>>ds[i].north();
      cin>>ds[i].bottom();
      cin>>ds[i].top();
      cin>>rs[i];
    }

    using P = pair<int, int>;
    vector< set<P> > sp(n);
    vector< map<P, int> > mp(n);
    for(int i=0;i<n;i++){
      int x=xs[i],y=ys[i];
      Die d=ds[i];
      sp[i].emplace(x,y);
      mp[i][P(x,y)]=d.bottom();
      for(char c:rs[i]){
        if(c=='L') x--,d.roll('W');
        if(c=='R') x++,d.roll('E');
        if(c=='F') y--,d.roll('S');
        if(c=='B') y++,d.roll('N');
        sp[i].emplace(x,y);
        mp[i][P(x,y)]=d.bottom();
      }
    }

    int sz=1<<n;
    const int INF = 1e9;
    vector<int> dp(sz,-INF);
    vector<set<P>> us(sz);
    dp[0]=0;

    for(int bit=0;bit<sz;bit++){
      set<P> &used=us[bit];
      for(int i=0;i<n;i++){
        if((~bit>>i)&1) continue;
        int old=bit^(1<<i);
        used=us[old];
        for(auto p:sp[i])
          used.emplace(p);
        break;
      }

      for(int i=0;i<n;i++){
        if((bit>>i)&1) continue;
        int nbit=bit|(1<<i);
        int res=0;
        for(auto p:sp[i])
          if(!used.count(p))
            res+=mp[i][p];
        chmax(dp[nbit],dp[bit]+res);
      }
    }
    cout<<dp[sz-1]<<endl;
  }
  return 0;
}



Measured memory_bytes: 235084
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
struct UF{
	int par[2000005],ran[2000005];
	void init(){ for(int i=0;i<2000005;i++) par[i] = i, ran[i] = 0; }
	int find(int x){ if(x == par[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(ran[x] < ran[y]) par[x] = y;
		else{
			par[y] = x;
			if(ran[x] == ran[y]) ran[x]++;
		}
	}
	bool same(int x,int y){ return find(x)==find(y); }
}uf;


ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[2000005],R[2000005];
void make(){
	F[0] = 1;
	for(int i=1;i<2000005;i++) F[i] = F[i-1]*i%mod;
	R[2000004] = modpow(F[2000004], mod-2);
	for(int i=2000003;i>=0;i--) R[i] = R[i+1] * (i+1) % mod;
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
void solve(){
	int n; string s;
	map<char, int>M;
	cin >> n;
	rep(i, n){
		cin >> s;
		M[s[0]] ++;
	}
	cout << "AC x " << M['A'] << endl;
	cout << "WA x " << M['W'] << endl;
	cout << "TLE x " << M['T'] << endl;
	cout << "RE x " << M['R'] << endl;
}




int main(){
	uf.init();
	make();
	solve();
}

Measured memory_bytes: 50476
import sys
sys.setrecursionlimit(10**7)

N = int(input())
A = [list(map(int,input().split())) for i in range(N)]

T = [0] * (1<<N)
for b in range(1<<N):
    if bin(b).count('1') <= 1: continue
    msb = len(bin(b)) - 3
    T[b] = T[b^(1<<msb)]
    for k in range(msb):
        if b&(1<<k):
            T[b] += A[k][msb]

dp = [None] * (1<<N)
def rec(b):
    if dp[b] is not None: return dp[b]
    if bin(b).count('1') <= 1: return 0
    ret = max(0,T[b])
    c = (b-1)&b
    while c > 0:
        ret = max(ret, rec(c) + rec(b^c))
        c = (c-1)&b
    dp[b] = ret
    return(ret)

print(rec(2**N-1))

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

typedef complex<double> P;

string l(string s){
	if( s[0] <= 'Z' ) s[0] = s[0] - 'Z' + 'z';
	return s;
}

int main(){
	map<string,int> d;
	string s;
	int mx = 0;
	string v = "";
	while( cin >> s ){
		mx = max(mx,++d[l(s)]);
		if( v.size() < s.size() ) 
			v = l(s);
	}
	for( auto i : d)
		if( mx == i.second) cout << i.first << " ";
	cout << v << endl;
		
	
			
			
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;
typedef long long ll;

using namespace std;

void solve() {
    const int M = 100001;
    ll N, K;
    cin >> N >> K;
    ll d[M];
    REP(i, M) d[i] = 0;
    REP(i, N) {
        ll a, b;
        cin >> a >> b;
        d[a] += b;
    }
    ll cnt = 0;
    ll ans;
    REP(i, M) {
        cnt += d[i];
        if (cnt >= K) {
            ans = i;
            break;
        }
    }
    print(ans);
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;

class Program{
  static void Main(){
    
    Console.ReadLine();
    string input = Console.ReadLine();
    int ans = 0;
    
    for(int i = 0; i < input.Length; i++){
      ans = Math.Max(ans, input.Substring(0,i).Intersect(input.Substring(i)).Count());
    }
    
    Console.WriteLine(ans);
    
  }
}

Measured memory_bytes: 11220
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 

int main(){
	//問題文は理解できないが，
	//fは　Sが何個の木で構成されてるかっぽい
	// ⇒ f = (Sの頂点数) - (Sの辺の数) (∵ 木は閉路がない) 
	//そのため，求める答えΣΣfは
	//   ΣΣf = ΣΣ(Sの頂点数) - ΣΣ(Sの辺の数)  かな

	ll N;// Nを計算に使うんでllにしときます
	cin >> N;
	//vec[i]: 頂点iの辺の先のの頂点の列(頂点iとくっついている頂点達)
	//今回はiより小さい頂点は格納しないことにする
	vector<vector<int>> vec(N, vector<int>());
	for(int i=0; i<N-1; i++){
		int u, v;
		cin >> u >> v;
		u--; v--;
		// vec[u].push_back(v);
		// vec[v].push_back(u);
		if(u<v) vec[u].push_back(v);
		else vec[v].push_back(u);
	}
	// vertex: 頂点, edge: 辺
	// num_vertex: ΣΣ(Sの頂点数), num_edge: ΣΣ(Sの辺の数)
	ll num_vertex = 0, num_edge = 0;
	for(int i=1; i<=N; i++){
		num_vertex += i*(N-i+1);
		//例 N=3のとき　 num_vertex = 1*3 + 2*2 + 3*1
		//N=4のとき num_vertex = 1*4 + 2*3 + 3*2 + 4*1
	}

	for(int i=0; i<N; i++){
		for(int j=0; j<vec[i].size(); j++){
			num_edge += (i+1) * (N-1 - vec[i][j] +1);
		// LとRを ΣΣで　0~N-1までずらしていくとき 
		//　頂点iと頂点vec[i][j]を結ぶ辺が何回使われるかを数える
		// 例: 頂点2と頂点5を結ぶ辺の場合 
		//     Lの候補は0,1,2 Rの候補は5,6,...,N-1
		// Lの候補とRの候補はそれぞれ独立しているので 
		//  (2+1)  *  {(N-1)-5 + 1} 
		}
	}
	//cout << " num_vertex: " << num_vertex << " num_edge: " << num_edge << endl; 
	ll ans = num_vertex - num_edge;
	cout << ans << endl;

}


Measured memory_bytes: 13948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n),b(n);
	vector<P> g(n),g2(n);
	rep(i,n){
		cin>>a[i]>>b[i];
		g[i].fi=a[i],g[i].se=b[i];
		g2[i]=g[i];
	}
	sort(begin(g),end(g));
	sort(begin(g2),end(g2),[&](const P &a,const P &b){
		return a.se<b.se;
	});
	ll ans=0;
	vector<P> cnt(n);
	rep(i,n){
		cnt[i]=P(g[i].fi,g2[i].se);
	}
	if(n%2){
		cout<<cnt[n/2].se-cnt[n/2].fi+1<<endl;
	}else{
		ll l1=cnt[n/2-1].fi,l2=cnt[n/2].fi;
		ll r1=cnt[n/2-1].se,r2=cnt[n/2].se;
		//chmin(r1,l2);
		ll ans=(r2-l2+1)+(r1-l1);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 15868
import java.util.*;

 class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
 int c=0;
      for(;;){  
        int s=sc.nextInt();
        if(s==0)break;
        if(c!=0)System.out.println();
   
   String tn[] =new String[s];
    int tp[]=new int[s]; 
    int tpc[]=new int[s];
    for(int i=0;i<s;i++){ 
    	tn[i]=sc.next();
    	tp[i]=(sc.nextInt()*3+sc.nextInt()*0+sc.nextInt());
        tpc[i]=tp[i];
    }
    Arrays.sort(tpc);
    for(int i=tpc[s-1];i>-1;i--){ 
    	for(int j=0;j<s;j++) if(i==tp[j])
    	System.out.println(tn[j]+","+tp[j]);
    }
    c++;
      }
    }
}

Measured memory_bytes: 20552
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
		
	string S;
	cin>>S;
	string ans1="";
	string ans2="";
	fx(S.size()){
		if(x%2==0){
			ans1+="1";
			ans2+="0";
		}else{
			ans2+="1";
			ans1+="0";
		}
	}
	int min1=0;
	int min2=0;
	fx(S.size()){
		if(S.at(x)!=ans1.at(x)){
			min1++;
		}
		if(S.at(x)!=ans2.at(x)){
			min2++;
		}
	}
	ce(min(min1,min2))
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)


int main() {
    ll K;
    cin >> K;

    ll tmp = 7;
    if (tmp % K == 0) {
        cout << 1 << endl;
        return 0;
    }

    for (int i = 2; i <= K + 10; ++i) {
        tmp = (tmp * 10) % K;
        tmp = (tmp + 7) % K;
        if (tmp == 0) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);


int main() {
	ll s, x, y, p = 1e9;
	cin >> s;

	x = (p - s % p) % p;
	y = (s + x) / p;

	cout << "0 0 1000000000 1 " << x << " " << y ;

	return 0;
}

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

Measured memory_bytes: 3640
import Control.Monad

readIntLine :: IO ([Int])
readIntLine = do
    x <- getLine
    return $ map (read :: String -> Int) $ words x

main :: IO ()
main = do
    [r,g,b,n] <- readIntLine
    putStrLn $ show $ solve [r,g,b] n

solve (x:[]) n
    | mod n x == 0 = 1
    | otherwise    = 0

solve (x:xs) n =
    let mx = div n x
      in sum $ map (solve xs) $ map ((n-) . (x*)) [0..mx]


Measured memory_bytes: 892
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = map(int, input().split())

ans = 0
for a in As:
    while a % 2 == 0:
        a //= 2
        ans += 1
print(ans)



Measured memory_bytes: 8520
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    bool f=1;
    int n=s.length();
    for(int i=1;i<=n;i+=2)
    {
        if(s[i-1]=='L')
        {
            f=0;
            break;
        }
    }

    for(int i=2;i<=n;i+=2)
    {
        if(s[i-1]=='R')
        {
            f=0;
            break;
        }
    }

    if(f)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    
    
    return 0;   
}


 
 


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, M, X;
lint C[12];
lint arr[12][12];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> M >> X;
	REP(i, N) {
		cin >> C[i];
		REP(j, M) {
			cin >> arr[i][j];
		}
	}

	lint minv = INF;
	REP(i, 1 << N) {
		lint score[12];
		lint cost = 0;
		REP(j, M) score[j] = 0;
		REP(j, N) {
			if ((i >> j) % 2 == 1) {
				REP(k, M) {
					score[k] += arr[j][k];
				}
				cost += C[j];
			}
		}

		bool flag = true;
		REP(j, M) {
			flag &= (score[j] >= X);
		}
		if (flag) chmin(minv, cost);
	}
	if (minv == INF) cout << -1 << endl;
	else cout << minv << endl;
}


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

long long depth[500];
long long w[500][2];
long long x[500][2];
long long n, root, v[500], a, A, B, C;
pair<long long, long long>DEPTH[500];
long long mobile[500][2];

long long gcd(long long p, long long q) {
	long long P = p, Q = q;
	while (true) {
		if (P%Q == 0) { return Q; }
		if (Q%P == 0) { return P; }
		if (P > Q) { P = P%Q; }
		else { Q = Q%P; }
	}
}

int main() {
	while (true) {
		memset(depth, 0, sizeof(depth));
		memset(w, 0, sizeof(w));
		memset(x, 0, sizeof(x));
		memset(v, 0, sizeof(v));
		memset(DEPTH, 0, sizeof(DEPTH));
		memset(mobile, 0, sizeof(mobile));
		root = 0; n = 0; A = 0; B = 0; C = 0; a = 0;
		cin >> n;
		if (n == 0) { break; }
		for (int i = 1; i <= n; i++) {
			v[i] = 0;
		}
		for (int i = 1; i <= n; i++) {
			cin >> w[i][0] >> w[i][1] >> x[i][0] >> x[i][1];
			v[x[i][0]] = 1; v[x[i][1]] = 1;
			a = gcd(w[i][0], w[i][1]);
			w[i][0] /= a; w[i][1] /= a;
		}
		for (int i = 1; i <= n; i++) {
			if (v[i] == 0) {
				root = i;
			}
		}
		//depth.
		for (int i = 1; i <= n; i++) {
			depth[i] = 1000;
		}
		depth[root] = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (depth[j] != 1000) {
					depth[x[j][0]] = min(depth[x[j][0]], depth[j] + 1);
					depth[x[j][1]] = min(depth[x[j][1]], depth[j] + 1);
				}
			}
		}
		for (int i = 1; i <= n; i++) {
			DEPTH[i - 1].first = depth[i];
			DEPTH[i - 1].second = i;
		}
		sort(DEPTH, DEPTH + n);
		for (int i = n - 1; i >= 0; i--) {
			A = DEPTH[i].first;
			B = DEPTH[i].second;
			if (x[B][0] == 0 && x[B][1] == 0) {
				mobile[B][0] = w[B][1];
				mobile[B][1] = w[B][0];
			}
			if (x[B][0] == 0 && x[B][1] >= 1) {
				mobile[B][1] = mobile[x[B][1]][0] + mobile[x[B][1]][1];
				mobile[B][1] = mobile[B][1] * w[B][0] / gcd(mobile[B][1], w[B][0]);
				mobile[B][0] = mobile[B][1] * w[B][1] / w[B][0];
			}
			if (x[B][0] >= 1 && x[B][1] == 0) {
				mobile[B][0] = mobile[x[B][0]][0] + mobile[x[B][0]][1];
				mobile[B][0] = mobile[B][0] * w[B][1] / gcd(mobile[B][0], w[B][1]);
				mobile[B][1] = mobile[B][0] * w[B][0] / w[B][1];
			}
			if (x[B][0] >= 1 && x[B][1] >= 1) {
				mobile[B][0] = mobile[x[B][0]][0] + mobile[x[B][0]][1];
				mobile[B][1] = mobile[x[B][1]][0] + mobile[x[B][1]][1];
				C = mobile[B][0] * w[B][0] * mobile[B][1] * w[B][1] / gcd(mobile[B][0] * w[B][0], mobile[B][1] * w[B][1]);
				mobile[B][0] = C / w[B][0];
				mobile[B][1] = C / w[B][1];
			}
		}
		cout << mobile[root][0] + mobile[root][1] << endl;
	}
	return 0;
}

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

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    a %= b;
    int flag=0;
    for(int i=1;i<=b;i++){
        if((a*i)%b == c) flag=1;
    }
    cout<<(flag==1?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,x;
    int count = 0;
    while(1){
        cin>>n>>x;
        if(n==0&&x==0) break;
    for(int i=1;i<=n-2;i++){
        for(int j=i+1;j<=n-1;j++){
            for(int k=j+1;k<=n;k++){
                if(i+j+k==x){
                        count++;
                }
            }
        }
    }cout<<count<<endl;
    count=0;
    }
}


Measured memory_bytes: 3096
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		int a = in.nextInt();
		
		if (a%2 == 0) System.out.println(0.5);
		else {
			double b = a/2 + 1;
			double c = a;
			System.out.println(String.format("%.6f", b/c));
		}
		
	}

	public static PrintWriter out = new PrintWriter(System.out);
	public static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_143
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] ls = ReadInts();
            Dictionary<int, long> sames = new Dictionary<int, long>();
            long[] cnts = new long[2000 + 1];
            for (int i = 0; i < n; i++)
            {
                cnts[ls[i]]++;
                if (!sames.ContainsKey(ls[i]))
                {
                    sames.Add(ls[i], 0);
                }
                sames[ls[i]]++;
            }
            for(int i = 1; i <= 2000; i++)
            {
                cnts[i] += cnts[i - 1];
            }
            Array.Sort(ls);
            long res = 0;
            for (int i = 0; i < n; i++)
            {
                for(int j = i + 1; j < n; j++)
                {
                    res += cnts[ls[i] + ls[j] - 1] - cnts[ls[j]];

                }
            }
            foreach (int key in sames.Keys)
            {
                if (sames[key] >= 2)
                {
                    res += sames[key] * (sames[key] - 1) / 2 * cnts[key - 1];
                }
                if (sames[key] >= 3)
                {
                    res += sames[key] * (sames[key] - 1) * (sames[key] - 2) / 6;
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13408
#include <iostream>
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
vector<vector<vector<vector<ll>>>> dp;
ll def;
ll solve(int n,int mod,int ch,int same){
	if(n==1){
		if(same==1){
			return 0;
		}
		if(mod==ch){
			return 1;
		}
		return 0;
	}
	ll &ans=dp[n][mod][ch][same];
	if(~ans)return ans;
	ans=0;
	mod+=3-ch;
	mod%=3;
	if(same){
		for(int i=0;i<3;i++){
			ans+=solve(n-1,mod,i,1);
		}
		ans+=solve(n-1,mod,ch,0);
	}else{
		for(int i=0;i<3;i++){
			if(i!=ch){
			ans+=solve(n-1,mod,i,0);
			}
		}
	}
	ans%=def;
	return ans;
}

int main() {
	 def=998244353;
	string s;cin>>s;
	for(int i=1;i<s.size();i++){
		if(s[i]!=s[i-1])break;
		if(i==s.size()-1){
			cout<<1<<endl;
			return 0;
		}
	}
	if(s.size()==2){
		if(s[0]==s[1]){
			cout<<1<<endl;
			return 0;
		}else{
			cout<<2<<endl;
			return 0;
		}
	}else if(s.size()==3){
		int ans;
		if(s[0]==s[1]){
			if(s[1]==s[2]){
				ans=1;
			}else{
				ans=6;
			}
		}else{
			if(s[1]==s[2]){
				ans=6;
			}else{
				if(s[0]==s[2]){
					ans=7;
				}else{
					ans=3;
				}
			}
		}

		cout<<ans<<endl;
		return 0;

	}
//	memset(dp,-1,sizeof(dp));
	dp=vector<vector<vector<vector<ll>>>>(200001,vector<vector<vector<ll>>>(3,vector<vector<ll>>(3,vector<ll>(2,-1))));
	ll ans=0;
	ll rem=0;
	ll flag=1;
	for(int i=0;i<s.size();i++){
		rem+=int(s[i]-'a');
	}
	rem%=3;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1])flag=0;
	}

		ans+=solve(s.size(),rem,0,1);
		ans+=solve(s.size(),rem,1,1);
		ans+=solve(s.size(),rem,2,1);
		ans+=flag;

	cout<<ans%def<<endl;
	return 0;
}

Measured memory_bytes: 133508
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long int lli;
const lli mx = 1299711;

int main()
{
  lli n, s, t;
  bool a[mx];
  fill(a, a+mx, true);
  a[0] = a[1] = false;

  for(lli i = 2; i < mx; i++){
    if(a[i]){
      for(lli j = i+i; j < mx; j += i){
	a[j] = false;
      }
    }
  }

  while(cin>>n && n){
    for(lli i = n; i >= 2; i--){
      if(a[i]){
	s = i;
	break;
      }
    }
    for(lli i = n; i < mx; i++){
      if(a[i]){
	t = i;
	break;
      }
    }

    cout << (t-s) << endl;
  }

  return 0;
}

Measured memory_bytes: 0
n = int(input())
s = [sorted(input()) for i in range(n)]
s = sorted(s) + ["a"]

cnt = 1
ans = 0
for i in range(n):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        ans += (cnt * (cnt - 1)) // 2
        cnt = 1
print(ans)

Measured memory_bytes: 101976
#include<cstdio>
using namespace std;
int A,B,C;
int X;
int solve(){
      int ans=0;
      for(int i=0;i<=A;++i){
            for(int j=0;j<=B;++j){
                  for(int k=0;k<=C;++k){
                        int tmp=i*500+j*100+k*50;
                        if(tmp==X)ans++;
                  }
             }
       }
       return ans;
}
int main(){
      scanf("%d%d%d%d",&A,&B,&C,&X);
       int ans=solve();
       printf("%d\n",ans);
       return 0;
}

Measured memory_bytes: 128
def main():
    MOD = 10**9 + 7

    while 1:
        N, D, X = map(int, input().split())
        if N == D == X == 0:
            break
        dp = [[0]*(N+1) for i in range(N+1)]
        dp[0][0] = 1
        for i in range(N):
            s = 0
            dpi = dp[i]
            dpj = dp[i+1]
            for j in range(N):
                s += dpi[j]
                if X-1 <= j:
                    s -= dpi[j-X+1]
                dpj[j+1] = s = s % MOD
        ans = 0
        v = 1
        d = D % MOD
        for k in range(1, min(D, N)+1):
            v = v * (d-k+1) * pow(k, MOD-2, MOD) % MOD
            ans += v * dp[k][N] % MOD
        print(ans % MOD)
main()


Measured memory_bytes: 131924
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX_N=100000;

int N;
int A[MAX_N];

long long sum[MAX_N*2];

int main(){
	scanf("%d",&N);
	int i;
	for (i=0;i<N;i++){
		scanf("%d",A+i);
	}
	sum[0]=A[0];
	for (i=1;i<N;i++){
		sum[i]=sum[i-1]+A[i];
	}
	for (i=N;i<2*N;i++){
		sum[i]=sum[i-1]+A[i-N];
	}
	long long ans=1;
	int s,t;
	s=0;
	t=1;
	long long a=A[0],b,c;	//s-t間のバームクーヘン
	while (s<N){
		long long *p;
		do{
			while (a<=ans){
				t++;
				a+=A[(t-1)%N];
			}
			//aがansを更新できるか
			p=lower_bound(sum+t,sum+s+N,a+sum[t-1]);
			if (p!=sum+s+N){
				//見つかった
				b=*p-sum[t-1];
				c=sum[N-1]-b-a;
				if (c>=a){
					//aが最小値
					ans=a;
				}
				else{
					break;
				}
			}
		}while (p!=sum+s+N);
		s++;
		a=sum[t-1]-sum[s-1];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4652
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}

void chmin(int &a, int &b){if (a>b){a = b; return;}return;}
void chmax(int &a, int &b){if (a<b){a = b; return;}return;}


const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  int k,x; cin >>k >>x;
  string ans = "Yes";
  if (500*k < x) ans = "No";
  cout <<ans <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 1000000000000
#define int long long int
#define hell (int)(1e9+7)

using namespace std;

void solve(){
    int n,m,x;
    cin>>n>>m>>x;
    vector <int> cost(n);
    int a[n][m];
    for(int i=0;i<n;i++){
        cin>>cost[i];
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    int ans=inf;
    for(int i=0;i<1<<n;i++){
        bitset <15> b(i);
        vector < int > v(m,0);
        int cc=0;
        for(int k=0;k<m;k++){
            for(int j=0;j<n;j++){
                if(b[j]==1){
                    v[k]+=a[j][k];
                }
            }
        }
        for(int j=0;j<n;j++){
            if(b[j])
                cc+=cost[j];
        }
        bool f=true;
        for(int j=0;j<m;j++){
            if(v[j]<x)
                f=false;
        }
        if(f)
            ans=min(ans,cc);
    }
    if(ans==inf)
        ans=-1;
    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}


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

const int MAGIC = 35000;

int n;
int res;

int grundy(int n, int k) {
	// if n % k == 0 -> grundy(n) = n / k
	// else -> grundy(n) = grundy(n - ceil(n / k))

	if (k < MAGIC) {
		while(n % k != 0) {
			n -= n / k + 1;
		}
		return n / k;
	} else {
		int val = n / k + 1;

		while(val > 0 && n % k != 0) {
			int low = 0, high = 1e9;
			while(low < high) {
				int mid = ((low + high) >> 1);
				if (n - 1LL * mid * val <= 1LL * (val - 1) * k) high = mid;
				else low = mid + 1;
			}
			n -= 1LL * low * val;
			--val;
		}

		return n / k; 
	}
}

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

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int a, k; cin >> a >> k;
		res ^= grundy(a, k);
	}

	if (res > 0) cout << "Takahashi\n";
	else cout << "Aoki\n";
}

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

int main() {
    int m,f,r,Z;
    for(int i = 0;i < 50;i++){
        cin >> m >> f >> r;
        Z = m + f;
        if(m == -1 && f == -1 && r == -1)break;
        if(m == -1 || f == -1){
            cout << "F" << endl;
            continue;
        }
        if(Z >= 80)cout << "A" << endl;
        if(Z < 80 && Z >= 65)cout << "B" << endl;
        if(Z < 65 && Z >= 50)cout << "C" << endl;
        if(Z < 50 && Z >= 30){
            if(r >= 50){
                cout << "C" << endl;
                continue;
            }
            cout << "D" << endl;
        }
        if(Z < 30)cout << "F" << endl;
    }
}


Measured memory_bytes: 3044
Scanf.scanf "%d" (fun n ->
    let module M = Map.Make (struct type t = string let compare = compare end) in
    let atgc k = "ACGT".[k] in
    let rec loopi i map =
        if i = 64 then map else
            let key = Printf.sprintf "%c%c%c" (atgc (i mod 4)) (atgc (i / 16)) (atgc ((i / 4) mod 4)) in
            let map = if key = "AGC" || key = "ACG" || key = "GAC" then map else M.add key 1 map in
            loopi (i + 1) map
    in
    let check k t =
        let nk = k ^ t in
        let ch s p a =
            let ss = String.init 4 (fun i ->
                if i = p then s.[i + 1] else
                if i = p + 1 then s.[i - 1] else s.[i]) 
            in
            String.sub ss a 3
        in
        ch nk 0 1 <> "AGC" && ch nk 1 1 <> "AGC" && ch nk 2 1 <> "AGC" && ch nk 4 1 <> "AGC" && ch nk 2 0 <> "AGC"
    in
    let (+@) a b = (a + b) mod 1_000_000_007 in
    let add k t v map =
        let nk = String.sub (k ^ t) 1 3 in
        M.add nk (v +@ try M.find nk map with _ -> 0) map
    in
    let rec loop i map =
        if i = n then map else
            let newmap = M.fold (fun k v newmap ->
                List.fold_left (fun acc t ->
                    if check k t then add k t v acc else acc) newmap [ "A"; "C"; "G"; "T" ]
            ) map M.empty
            in
            loop (i + 1) newmap
    in
    let map = loop 3 (loopi 0 M.empty) in
    M.fold (fun _ v acc -> acc +@ v) map 0 |> Printf.printf "%d\n"
)

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

#ifdef LOCAL 
string to_string(char a) { return string(1,a); }
string to_string(bool a) { return a ? "1" : "0"; }
string to_string(const char* a) { return (string)a; }
string to_string(string a) { return a; }
string to_string(vector<bool> v) {
	string s = "["; for(unsigned i=0;i<v.size();i++){ s += ((i>0)?" ":"");
    s += char('0'+v[i]); } 	s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) {
	bool b = 1; string s = "["; for (const auto& x: v) {
		if (!b) {s += ", ";} b = 0; s += to_string(x); } s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void dbgf() { cerr << endl; }
template<class H, class... T> void dbgf(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	dbgf(t...); }
#define dbg(...) cerr << #__VA_ARGS__ << " = ", dbgf(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
#define boolout(x) cout<<(x?"YES":"NO")<<endl;
typedef long long ll;

const ll inf = 1e18 + 5;


void solve()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> pref(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (i>0) {
            pref[i] = pref[i-1] + a[i];
        } else {
            pref[i] = a[i];
        }
    }
    dbg(pref);

    vector<vector<ll>> dp(n, vector<ll>(n, inf));

    for (int l = n-1; l >= 0; --l) {
        for (int r = l; r < n; ++r) {
            if (l==r) {
                dp[l][r] = 0;
            } else {
                for (int k = l; k < r; ++k) {
                    dp[l][r] = min(dp[l][r], dp[l][k] + dp[k+1][r] + pref[r] - (l==0?0:pref[l-1]));
                }
            }
        }
    }

    dbg(dp);
    cout << dp[0][n-1] << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t; // read t. cin knows that t is an int, so it reads it as such.
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 1536
import numpy as np

if __name__ == "__main__":
  _n = int(input())
  _l = [int(i) for i in input().split()]

  check = set()
  for i in _l:
    if i in check:
      print("NO")
      exit(0)
    else:
      check.add(i)
  print("YES")


Measured memory_bytes: 34448
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
pi ar[200005];

template<lint mod>
struct Int_{
  unsigned x;
  unsigned mpow(Int_ a,unsigned k){
    Int_ res=1;
    while(k){
      if(k&1) res=res*a;
      a=a*a;
      k>>=1;
    }
    return res.x;
  }
  unsigned inverse(Int_ a){
    return mpow(a,mod-2);
  }
  Int_(): x(0) { }
  Int_(long long sig) {
    int sigt=sig%mod;
    if(sigt<0) sigt+=mod;
    x=sigt;
  }
  unsigned get() const { return (unsigned)x; }
  
  Int_ &operator+=(Int_ that) { if((x += that.x) >= mod) x -= mod; return *this; }
  Int_ &operator-=(Int_ that) { if((x += mod - that.x) >= mod) x -= mod; return *this; }
  Int_ &operator*=(Int_ that) { x = (unsigned long long)x * that.x % mod; return *this; }
  Int_ &operator=(Int_ that) { x=that.x; return *this;}
  Int_ &operator/=(Int_ that) { x=(unsigned long long) x * inverse(that.x)%mod; return *this;}
  bool operator==(Int_ that) const { return x==that.x; }
  bool operator!=(Int_ that) const { return x!=that.x; }

  Int_ operator-() const { return Int_(0)-Int_(*this);}
  Int_ operator+(Int_ that) const { return Int_(*this) += that; }
  Int_ operator-(Int_ that) const { return Int_(*this) -= that; }
  Int_ operator*(Int_ that) const { return Int_(*this) *= that; }
  Int_ operator/(Int_ that) const { return Int_(*this) /= that; }

};

namespace std{
  template<lint mod>
  ostream &operator <<(ostream& out,const Int_<mod>& a){
    out<<a.get();
    return out;
  }
  template<lint mod>
  istream &operator >>(istream& in,Int_<mod>& a){
    in>>a.x;
    return in;
  }
};

typedef Int_<1000000007> Int;
int main(){
  cin>>n;
  REP(i,n) cin>>ar[i].fr,ar[i].sc=0;
  REP(i,n) cin>>ar[i+n].fr,ar[i+n].sc=1;
  sort(ar,ar+n*2);

  int sum[2]={0};
  Int res=1;
  REP(i,n*2){
    if(sum[ar[i].sc^1]==0) ++sum[ar[i].sc];
    else{
      res*=sum[ar[i].sc^1];
      --sum[ar[i].sc^1];
    }
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 1792
from itertools import permutations
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    A = tuple(map(int, input().split()))

    cost = float('inf')
    for i, j, k in permutations(A, 3):
        n = abs(i - j)
        n += abs(j - k)
        cost = min(cost, n)
    print(cost)

main()


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<ll> AB(N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    AB[i] = a + b;
    ans -= b;
  }
  sort(AB.begin(), AB.end(), greater<ll>());
  for (int i = 0; i < N; i++)
    if (i % 2 == 0) ans += AB[i];
  cout << ans << '\n';
  return 0;
}


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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

int main() {
  cout << setprecision(18);
  string S;
  cin >> S;
  u64 res = stoull(S);
  for (u32 i = 1; i < (0x01 << (S.size() - 1)); ++i) {
    u32 start = 0;
    for (u32 b = 0; b < 9; ++b) {
      if ((i >> b) & 0x01) {
        res += stoull(S.substr(start, b + 1 - start));
        start = b + 1;
      }
    }
    res += stoull(S.substr(start));
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
# ABC 062
def getIntList(): return [int(x) for x in input().split()]

A = {1, 3, 5, 7, 8, 10, 12}
B = {4, 6, 9, 11}
C = {2}
x,y = getIntList()
res = 'No'
if (x in A and y in A) or (x in B and y in B) or (x in C and y in C): res = 'Yes'
print(res)

Measured memory_bytes: 3064
A, B, K = list(map(int, input().strip().split(' ')))
for j in range(A,min(A+K,B+1)):
    if not(j >= A+K and j <= B-K):
        print(j)
for i in range(max(B-K,j+1),B+1):
    if not(i >= A+K and i <= B-K):
        print(i)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int m, n;
	while (cin >> m >> n, m || n) {
		int cnt = 0;
		vector<bool> v(7368800, true);

		REP(i, m, 7368800) {
			if (v[i]) {
				if (cnt >= n) {
					cout << i << endl;
					break;
				}
				for (int j = 2 * i; j < 7368800; j += i) v[j] = false;
				cnt++;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3872
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int main(){
    int n=0,i;
    char str[10];
    cin>>str;
    //cout<<str;
    for(i=0;i<3;i++){
        if(str[i]=='o')
            n++;
    }
    cout<<700+100*n<<"\n";
}





Measured memory_bytes: 256
import math

# 標準偏差を求める
def standard_deviation():
    average = sum(s) / n  # 平均値を求める
    total_deviation = 0
    for element in s:
        total_deviation += (element - average)**2 # 偏差の合計を求める

    return math.sqrt(total_deviation / n) # 標準偏差を求める


while True:
    n = int(input())
    if n == 0: break
    s = [int(s) for s in input().split()]
    print('{0:.5f}'.format(standard_deviation()))


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1<<29;
/****** define constant end ********/


/****** define variable start ******/
ll n, a, b;
/******* define variable end *******/
ll solve() {
    cin >> n >> a >> b;
    ll wari = n / (a+b);
    ll ans  = a * wari;
    ans += min(n - wari * (a+b), a);
    cout << ans << endl;
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    
    return (int)end_solve;
}


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

int main() {
	string a;
	int w = 0;
	cin >> a;
	for (int i = 0; i < 3;i++) {
		if (a[i] == a[i + 1]) w++;
		
		}
	if (w >= 1) {
		cout<<"Bad"<<endl;
	}
	else {
		cout << "Good" << endl;
	}
	
}

Measured memory_bytes: 256
// oj d https://atcoder.jp/contests/abc161/tasks/abc161_b
// g++ B.cpp && oj t
// oj s https://atcoder.jp/contests/abc161/tasks/abc161_b B.cpp

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

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

int main() {
  int N, M, S = 0;
  cin >> N >> M;
  vector<int> A(N);
  REP(i, N) {
    cin >> A[i];
    S += A[i];
  }
  int c = 0;
  REP(i, N) {
    if (A[i] * (4 * M) >= S) {
      c++;
    }
  }
  if (c >= M) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next();
			for(int i = 0; i < s.length(); i++){
				String temp = s.substring(i);
				if(temp.equals("FESTIVAL")){
					System.out.println(s.substring(0, i));
					break;
				}
			}
		}
	}



	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 21844