akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,H,W;
  cin >> N >> H >> W;
  int ans = 0;
  rep(i,N) {
    int a,b;
    cin >> a >> b;
    if(a >= H && b >= W) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
    int i,j;
    int l=0;
    double r[1000];
    for( ; ; ){
        int n;
        double s;
        double m=0;
        double t=0;
        scanf("%d", &n);
        if(n==0) break;
        for(i=0; i<n; i++){
            scanf("%lf ",&s);
            m+=s;
            t+=s*s;
        }
        m=m/(double)n;
        m=m*m;
        t=t/(double)n;
        r[l]=t-m;
        l++;
        printf("%f\n", sqrt(r[l-1]));
    }
    return 0;
}

Measured memory_bytes: 2716
#include <iostream>
#include <string>
#include <stack>
#include <cstdio>
#include <vector>
#include <sstream>

using namespace std;

static bool isOperator(const string& st) {
  return st[0] == '+' || st[0] == '-' || st[0] == '*' || st[0] == '/';
}

int main() {
  stack<string> st;
  string  in, op1, op2, op, line, elem;
  int op1_i, op2_i, ans;
  
  // input line.
  getline(cin, line);
  stringstream ss(line);
  
  // sprit.
  while (getline(ss, line, ' ')) {
    st.push(line);
//    printf("pushed = %s!!\n", line.c_str());
    elem = st.top();
//    printf("elem = %s.\n", elem.c_str());
    if (isOperator(elem)) {
      op = st.top();
      st.pop();
      op2 = st.top();
      st.pop();
      op1 = st.top();
      st.pop();
      op1_i = stoi(op1);
      op2_i = stoi(op2);
      
      switch (op[0]) {
      case '+':
         ans = op1_i + op2_i;
         break;
      case '-':
         ans = op1_i - op2_i;
         break;
      case '*':
         ans = op1_i * op2_i;
         break;
      case '/':
         ans = op1_i / op2_i;
         break;
      }
      st.push(to_string(ans));
    }
  }
  cout << st.top() << endl;
  return 0;
}



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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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 T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int dp[11111][11111];
string s, t;

void print() {
   int n = s.size(), m = t.size();
   rep (i, n+1) {
      rep (j, m+1) {
         printf("%2lld ", dp[i][j]);
      }
      puts("");
   }
}

int dist() {
   s = "*" + s;
   t = "*" + t;
   int n = s.size(), m = t.size();
   rep (i, n) { dp[0][i] = i; }
   rep (i, m) { dp[i][0] = i; }

   repp (i, 1, n) {
      repp (j, 1, m) {
         int cost = dp[i-1][j-1] + (s[i] == t[j] ? 0 : 1);
         dp[i][j] = min({dp[i-1][j]+1, dp[i][j-1]+1, cost});
      }
   }

   return dp[n-1][m-1];
}

signed main() {
   cin >> s >> t;
   fill(dp[0], dp[1010], 1 << 28);
   dp[0][0] = 0;
   dp[0][0] = 0;
   int N = s.size(), M = t.size();
   rep (i, N+1) dp[i][0] = i;
   rep (i, M+1) dp[0][i] = i;

   rep (i, N) {
      rep (j, M) {
         dp[i+1][j+1] = min({dp[i][j+1]+1, dp[i+1][j]+1, dp[i][j] + (s[i] != t[j])});
      }
   }

   cout << dp[N][M] << endl;

   return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll n, m, ans = 0, gc = 0;
vector<int> v[1000010];
bool f = false;
map<int, int> k, g;

void solve(int p, int h) {
  if(k[p] && h || g[p] && !h) return;
  if(k[p] && !h || g[p] && h) {
    f = 1;
    return;
  }
  if(h) k[p] = 1;
  else g[p] = 1, gc++;
  rep(i, 0, v[p].size()) {
    solve(v[p][i], !h);
  }
}

int main() {
  cin >> n >> m;
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    v[a].pb(b);
    v[b].pb(a);
  }
  solve(1, 0);
  if(f) {
    ans = (n * (n - 1)) / 2 - m;
  }else {
    rep(i, 1, n + 1) {
      if(g[i]) continue;
      ans += gc - v[i].size();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 36864
#include <stdio.h>

int sumInts(int n,int i);

int main(){
	int n;
	
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",sumInts(n,4));
	}
	
	return 0;
}

int sumInts(int n,int i){
	int j,sum=0;
	if(i==1){
		if(n>9){
			sum=0;
		}else if(n<0){
			fprintf(stderr,"error\n");
		}else{
			sum=1;
		}
	}else{
		for(j=0;j<=9;j++){
			if (n<j) break;
			sum+=sumInts(n-j,i-1);
		}
	}
	
	
	return sum;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}
int k(ll n) {
	int x=0;
	while (n) {
		x+=n % 10;
		n /= 10;
	}
	return x;
}
ll max(ll x, ll y) {
	if (x < y)return y;
	return x;
}


int main() {
	llint n, x;
	cin >> n >> x;
	hei(ll int) a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	whei(hei(llint)) dp(n + 1, whei(llint)(n + 1, hei(llint)(2501, 0)));
	dp[0][0][0] = 1;
	rep(i, 0, n) {
		rep(j, 0,i+1) {
			rep(k, 0, 2501) {
				dp[i + 1][j][k] += dp[i][j][k];
				if (k >= a[i]) {
					dp[i + 1][j + 1][k] += dp[i][j][k-a[i]];
				}
			}
		}
	}
	llint ans = 0;
	rep(i, 1, n + 1)ans += dp[n][i][i * x];
	cout << ans << endl;
	return 0;
}


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

/**
 * 
 * @author glycine
 *
 */
public class Main {
	int N, Q;
	String s;
	char[] t, d;
	Map<Character, List<Integer>> cellTypes;
	int[] positions;

	int result;

	Main() throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		Q = Integer.parseInt(tokens[1]);
		s = in.readLine();
		t = new char[Q];
		d = new char[Q];
		for (int i = 0; i < Q; ++i) {
			tokens = in.readLine().split(" ");
			t[i] = tokens[0].charAt(0);
			d[i] = tokens[1].charAt(0);
		}
		in.close();
	}

	void calc() {
		int left = -1;
		int right = N;
		for (int i = Q - 1; i >= 0; --i) {
			char c = t[i];
			char dir = d[i];
			if (dir == 'L') {
				if (left <= N - 2 && s.charAt(left + 1) == c) {
					++left;
				}
				if (right <= N - 1 && s.charAt(right) == c) {
					right++;
				}
			} else {
				if (right > 0 && s.charAt(right - 1) == c) {
					--right;
				}
				if (left >= 0 && s.charAt(left) == c) {
					left--;
				}
			}
		}
		this.result = N;
		if (left >= 0)

		{
			this.result -= (left + 1);
		}
		if (right <= N - 1) {
			this.result -= (N - right);
		}
		this.result = Math.max(0, this.result);

	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		ins.calc();
		System.out.println(ins.result);

	}

}

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

// why am I so weak

int n, m;
int a[100055];

long long d[100055];
int have[100055];

int main() {
	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	long long sum = 0;

	for (int i = 0; i + 1 < n; i++) {
		if (a[i + 1] > a[i]) {
			have[a[i] + 2]++, have[a[i + 1] + 1]--;
			d[a[i + 1] + 1] -= a[i + 1] - a[i] - 1;

			sum += a[i + 1] - a[i];
		} else {
			have[a[i] + 2]++, have[1]++;
			have[a[i + 1] + 1]--;

			d[a[i + 1] + 1] -= a[i + 1] + m - a[i] - 1;
			d[1] += m - a[i] - 1;

			sum += a[i + 1] + m - a[i];
		}
	}

	for (int i = 1; i <= m; i++) {
		have[i] += have[i - 1];
		d[i] += d[i - 1];
		d[i] += have[i];
	}

	printf("%lld\n", sum - *max_element(d, d + m + 1));

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
long long int a[200007];
int main(){
    long long int n,i,j,k,ans=0,count=0;
    cin>>n;
    for(i=0;i<n;i++)cin>>a[i];
    if(n>=3){
    sort(a,a+n);
    for(i=n-2;i>0;i--){
        ans+=a[i];
        count++;
        if(count==n-2)break;
         ans+=a[i];
        count++;
        if(count==n-2)break;
    }
    cout<<ans+a[n-1]<<"\n";
    }
    else {
        
        sort(a,a+n);
        if(n==1)cout<<0<<"\n";
        else cout<<a[1]<<"\n";
        
    }
}

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

R = 0
G = 0
B = 0
for i in range(N):
    if S[i] == "R":
        R += 1
    elif S[i] == "G":
        G += 1
    else:
        B += 1
ans = R * G * B
for i in range(1, N//2+1):
    for j in range(0, N - (i*2)):
        k = j + i
        l = k + i
        if S[j] != S[k] and S[k] != S[l] and S[l] != S[j]:
            ans -= 1
print(ans)


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

using namespace std; 
 
#define int long long
#define M 1000000007 
 
signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	
//	int t;
//	cin >> t;
//	while(t--){
		int n;
		cin >> n;
		int a[n+1];
		for(int i=0;i<n-1;i++){
			cin >> a[i];
		}
		int lst=a[0];
		int sum=a[0];
		for(int i=1;i<n-1;i++){
			if(a[i]<lst){
				sum+=a[i];
				lst=a[i];
			}
			else{
				sum+=lst;
				lst=a[i];
			}
		}
		sum+=lst;
		cout << sum << endl;
//	}
}
 

Measured memory_bytes: 3648
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long ans = 0;
    if((n % 2) == 0) {
      long t = n / 2;
      for(int i = 1; i < 50; i++) {
        ans += ((long)(t / (long)Math.pow(5, i)));
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
ll n,m,i,j,k,l,o,p,ans,a[10010],dp[10010],mn[4050][4050];
int main()
{
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=n;i++)
	 scanf("%lld",a+i),a[i+n]=a[i],ans+=a[i];
	for (i=1;i<=n;i++)
	 for (j=1;j<=n;j++)
	 {
	 	mn[i][0]=a[i];
	  	mn[i][j]=min(mn[i][j-1],a[n+i-j]);	 	
	 }
	for (k=0;k<=n;k++)
	 {
	 	ll ans1=0;
	 	for (i=1;i<=n;i++)
	 	 ans1+=mn[i][k];
	 	ans=min(ans,ans1+k*m);
	 }
	printf("%lld\n",ans);
}

Measured memory_bytes: 62976
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
    string s; cin>>s;
    int n=s.size(),l=-1,r=-1;
    rep(i,n-1){
        if(s[i]==s[i+1]){
            l=i+1; r=i+2;
        }
    }
    rep(i,n-2){
        if(s[i]==s[i+2]){
            l=i+1; r=i+3;
        }
    }
    cout<<l<<" "<<r<<endl;
}

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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (1e9 + 7)
#define umap unordered_map

struct Node
{
    bool visited = false;
    long c = 0;
    vector<long> buddy, block;
};

long mark(long x, vector<Node> &nodes, long c)
{
    nodes[x].visited = true;
    nodes[x].c = c;
    long total = 1;
    for (auto &y : nodes[x].buddy) {
        if (nodes[y].visited) continue;
        total += mark(y, nodes, c);
    }
    return total;
}

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n, m, k;
        cin >> n >> m >> k;

        vector<Node> nodes(n+1);
        while (m--) {
            long u, v;
            cin >> u >> v;
            nodes[u].buddy.push_back(v);
            nodes[v].buddy.push_back(u);
        }
        while (k--) {
            long u, v;
            cin >> u >> v;
            nodes[u].block.push_back(v);
            nodes[v].block.push_back(u);
        }
        long c = 1;
        vector<long> d(n+1);
        for (long i = 1; i <= n; i++) {
            if (not nodes[i].c) {
                d[c] = mark(i, nodes, c);
                c++;
            }
        }
        for (long i = 1; i <= n; i++) {
            long x = d[nodes[i].c] - 1;
            x -= nodes[i].buddy.size();
            for (auto &j : nodes[i].block) {
                if (nodes[j].c == nodes[i].c) x--;
            }
            printf("%lld ", x);
        }
        puts("");
    }
}


Measured memory_bytes: 18328
DBG = !true
n = gets.to_i
a = []
for i in 0...n
  x,y,h = gets.split.map{|x| x.to_i}
  a << [x,y,h]
end

if DBG
  printf("n:%d\n", n)
  print a, "\n"
end

a.sort_by!{|e| e[2]}.reverse!

for cx in 0..100
  for cy in 0..100
    hhyp = -1
    ok = true
    for k in 0...n
      x,y,h = a[k]
      if hhyp == -1
        if h == 0
          print "err"
          exit
        else
          hhyp = h + (x-cx).abs + (y-cy).abs
          printf("x:%d y:%d h:%d hhyp:%d\n", x, y, h, hhyp) if DBG
        end
      else
        if h == 0
          if hhyp - (x-cx).abs - (y-cy).abs > 0
            ok = false
            print "breaking\n" if DBG
            break
          end
        else
          if hhyp - (x-cx).abs - (y-cy).abs != h
            ok = false
            printf("cx:%d cy:%d x:%d y:%d h:%d hh:%d breaking2\n", cx, cy, x, y, h, hhyp) if DBG
            break
          end
        end
      end
    end

    if ok
      printf("%d %d %d", cx, cy, hhyp)
      exit
    end
  end
end
printf("dead")


Measured memory_bytes: 1788
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    MAX = int(N ** 0.5)

    res = [0] * 10008

    ans = 0
    li = []
    for x in range(1, MAX + 1):
        for y in range(1, MAX + 1):
            for z in range(1, MAX + 1):
                tmp = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
                if tmp <= 10000:
                    res[tmp] += 1

    for i in range(1, N + 1):
        print(res[i])


if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
    long n, a, b, c, d, e;
    scanf("%ld\n%ld\n%ld\n%ld\n%ld\n%ld", &n, &a, &b, &c, &d, &e);
    long slow = min({a, b, c, d, e});
    printf("%ld\n", 5+(n-1)/slow);
    return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
s = 0
t = 0
cur = 0
ans = 0
while s < N:
    while t < N and cur + A[t] == cur ^ A[t]:
        cur += A[t]
        t += 1
    ans += t - s
    cur -= A[s]
    s += 1
print(ans)


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

class Main{
    public static void main(String[] args)throws NumberFormatException, IOException{
        InputStreamReader input = new InputStreamReader (System. in);
        BufferedReader buffer = new BufferedReader(input);

        PriorityQueue<Integer> quere = new PriorityQueue<Integer> (Collections.reverseOrder());
        while(true){
            String[] str = buffer.readLine().split(" ");
            if(str[0].equals("insert")){
                quere.add(Integer.parseInt(str[1]));
            }
            if(str[0].equals("extract")){
                System.out.println(quere.poll());
            }
            if(str[0].equals("end")){
                break;
            }
        }
    }
}



Measured memory_bytes: 231312
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){      
       lint n,t;
       cin>>n>>t;
       t/=2;
       lint a[n];
       rep(i,n)cin>>a[i];
       lint b[n];
       b[n-1]=a[n-1];
       rep(i,n-1){
           b[n-i-2]=max(b[n-i-1],a[n-i-2]);
       }
       lint c[n];
       rep(i,n)c[i]=b[i]-a[i];
       lint mx=*max_element(c,c+n);
       lint count=0;
       rep(i,n){
           if(c[i]==mx)count++;
       }
       cout<<count<<endl;
      }
  
     


Measured memory_bytes: 2560
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();
		CountNumberOfCookies countNumberOfCookies = new CountNumberOfCookies();

		System.out.println(countNumberOfCookies.getCount(A, B, T));
	}
}

class CountNumberOfCookies {
	public int getCount(int A, int B, int T) {
		int cookieCount = 0;		
		BigDecimal repeatCount = new BigDecimal((T+0.5) / A);
		cookieCount = B * repeatCount.setScale(0, BigDecimal.ROUND_DOWN).intValue();
		return cookieCount;
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;


int main(){
	int x,k;

	std::cin >> k >> x;
	printf("%s\n", 500*k >= x ? "Yes" : "No" );
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string s;
    cin >> s;
    int n = s.size();
    
    string ans = "";
    if (n%2==0) {
        if (s[0]==s.back()) {
            ans = "First";
        }
        else {
            ans = "Second";
        }
    }
    else {
        if (s[0]==s.back()) {
            ans = "Second";
        }
        else {
            ans = "First";
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20)
#define int long long
#define double long double
const int INF = 1e18, MOD = 1e9 + 7;

int n, a[222222], res = 0;
bool h[1111111] = {};
int cnt[1111111] = {};

signed main() {
    INCANT;
    cin>>n;
    for (int i = 0; i < n; i++) {
        cin>>a[i];
        cnt[a[i]]++;
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        if (h[a[i]]) continue;
        res += cnt[a[i]] == 1;
        int j = a[i];
        while (j < 1111111) {
            h[j] = true;
            j += a[i];
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 14056
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int d, t, s;
	cin >> d >> t >> s;
	
	if(s * t >= d) cout << "Yes" << endl;
	else cout << "No" << endl;	
}

int main() {
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piiii pair<pii,pii>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
#define logg2 0.30102999566398119521373889472449L
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=2e5;
ll dp[maxn+1][13];
ll p=1;
map<int,int> mp1,mp2;
bool f(int i){
    if(mp1[1] && i!=1) return(false);
    for(int j=2;j*j<=i;j++){
        if(i%j!=0) continue;
        if(mp1[j] || mp1[i/j]) return(false);
    }
    return(true);
}
void solve(){
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mp1[arr[i]]++;
    }
    int cnt=0;
    for(auto pp:mp1){
        if(pp.second!=1) continue;
        if(f(pp.first)) cnt++;

    }
    cout<<cnt;
    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}


Measured memory_bytes: 33272
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d,t,s; cin>>d>>t>>s;
  if(d%s==0){
    if(d/s<=t){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  else{
    if(d/s+1<=t){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    long long N;cin>>N;
    std::vector<long long>A(N+1); // AのサイズをN+1にする
    for(long long i=0;i<N;i++){
        cin>>A[i];
    }
	A[N]=1000000007; // Aの最後に他の要素と一致しない要素(番兵)を入れる
    sort(A.begin(),A.end());
    long long ans=0;
    long long tmp=0;
    for(long long i=1;i<N+1;i++){ // 回す回数を1回増やす
        if(A[i]==A[i-1]){
            tmp++;
        }
        else{
            if(tmp%2==0){
                ans++;
            }
            tmp=0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4044
def solve():
    N = int(input())
    S = input()
    next_end = 1
    max_length = 0
    for start in range(N-1):
        for end in range(next_end, N):
            text = S[start:end]
            if text in S[end:]:
                max_length = max(len(text), max_length)
                continue
            else:
                if start + 1 == end:
                    next_end = end + 1
                else:
                    next_end = end
            break
    
    print(max_length)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
x, t = gets.chomp.split(" ").map(&:to_i)
routes = []
x.times do
  routes << gets.chomp.split(" ").map(&:to_i)
end
routes.sort! {|a, b| a[0] <=> b[0]}
ans = "TLE"
routes.each do |route|
  if route[1] <= t
    ans = route[0]
    break
  end
end
puts ans


Measured memory_bytes: 1788
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         int X = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         int[] cost = new int[N];
         int[][] grid = new int[N][M];
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            cost[i] = Integer.parseInt(st.nextToken());
            for(int a=0; a < M; a++)
               grid[i][a] = Integer.parseInt(st.nextToken());
         }
         long rest = Long.MAX_VALUE;
         for(int mask=0; mask < (1 << N); mask++)
         {
            int[] res = new int[M];
            long temp = 0L;
            for(int b=0; b < N; b++)
               if((mask&(1<<b)) > 0)
               {
                  temp += cost[b];
                  for(int i=0; i < M; i++)
                     res[i] += grid[b][i];
               }
            boolean works = true;
            for(int x: res)
               if(x < X)
                  works = false;
            if(works)
               rest = Math.min(rest, temp);
         }
         if(rest == Long.MAX_VALUE)
            rest = -1;
         System.out.println(rest);
      }
   }

Measured memory_bytes: 34224
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> P;
	std::vector<int> Q;
	std::vector<int> N;
	for (int i = 0; i < n; i++)
	{
		int p;
		std::cin >> p;
		P.push_back(p);
		N.push_back(i + 1);	
	}
	for (int i = 0; i < n; i++)
	{
		int q;
		std::cin >> q;
		Q.push_back(q);
	}

	int a = 0;
	int b = 0;
	int count = 0;
	do
	{
		++count;
		if (N == P)
			a = count;
		if (N == Q)
			b = count;
		if (a != 0 && b!= 0)
			break;
	} while (std::next_permutation(N.begin(), N.end()));

	std::cout << std::abs(a - b) << '\n';

}

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In,' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var X = cin.ReadLong;
          	var A = X;
            var Y = cin.ReadLong;

            var count = 0;
			if (X == 0){
              	A = 1;
          		count++;
            }

          	while(A<=Y){
              A *= 2;
              count++;
            }
          
            WriteLine(count);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream,char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0;i < tmp.Length;i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }

}

Measured memory_bytes: 11220
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int N, u, v;
vector<vector<int>> edge;

int trace[200000 + 100];
int dis[200000 + 100];

vector<int> kerirojou;
bool saitanro[200000 + 100];

void dfs(int pos, int bef) {
	for (int i = 0; i < edge[pos].size(); i++) {
		int nxt = edge[pos][i];
		if (nxt == bef)continue;
		dis[nxt] = dis[pos] + 1;
		trace[nxt] = pos;
		dfs(nxt, pos);
	}
}

int dfs2(int pos, int bef, int d) {
	int ret = 0;
	for (int i = 0; i < edge[pos].size(); i++) {
		int nxt = edge[pos][i];
		if (nxt == bef)continue;
		if (saitanro[nxt])continue;
		ret = max(ret, dfs2(nxt, pos, d + 1));
	}
	if (ret == 0)return d;
	return ret;
}

int main() {
	cin >> N >> u >> v;
	u--, v--;
	edge.resize(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	for (int i = 0; i < N; i++)trace[i] = -1;

	dfs(u, -1);

	int npos = v;
	saitanro[v] = true;
	saitanro[u] = true;
	kerirojou.push_back(u);
	while (true) {
		if (trace[npos] == -1)break;
		npos = trace[npos];
		if (trace[npos] == -1)break;
		saitanro[npos] = true;
		kerirojou.push_back(npos);
	}
	int ans = dis[v] - 1;
	//cout << ans << endl;
	for (int i = 0; i < kerirojou.size(); i++) {
		if (dis[kerirojou[i]] * 2 < dis[v]) {
			//これじゃないと追いつかれれる
			int tmp = dfs2(kerirojou[i], -1, 0);
			ans = max(ans, dis[kerirojou[i]] + tmp + (dis[v] - dis[kerirojou[i]] * 2 - 1));
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

    if(N>=65 && N<=90){
        cout<<1<<endl;
    }else if(N>=97 && N<=122){
        cout<<2<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104
def main():
  N,P = map(int,input().split())
  n0 = 0
  n1 = 0
  for a in map(int,input().split()):
    if a%2 == 0:
      n0 += 1
    else:
      n1 += 1
  if P == 1 and n1 == 0:
    print(0)
    return
  print(2**(n0+max(n1-1,0)))

main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
 int a;
  cin>>a;
  int b=a%10;
  if(b==2||b==4||b==5||b==7||b==9){
  cout<<"hon";
  }
  else if(b==3){
  cout<<"bon";
  }
   else{
  cout<<"pon";
   }
    
}
    

Measured memory_bytes: 3636
n=int(input())
a=list(map(int,input().split()))

l=[-sum(a)]
for i in range(1,n):
    l.append(l[i-1]+a[i-1]*2)
l=l[1:]
for i in range(n-1):
    l[i]=abs(l[i])
print(min(l))

Measured memory_bytes: 24812
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, itemgetter
import numpy as np

sys.setrecursionlimit(10000)

def read_int():
	return int(sys.stdin.readline().strip())

def read_int_n():
	return [int(x) for x in sys.stdin.readline().strip().split()]

def read_float():
	return float(sys.stdin.readline().strip())

def read_float_n():
	return [float(x) for x in sys.stdin.readline().strip().split()]

def read_str():
	return sys.stdin.readline().strip()

def read_str_n():
	return [str(x) for x in sys.stdin.readline().strip().split()]

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(S):
	c = Counter(S)
	ans = c['+'] - c['-']
	return ans

def main():
	S = read_str()
	print(slv(S))

if __name__ == '__main__':
	main()

Measured memory_bytes: 14144
w, h, x, y = input().split()
w = int(w)
h = int(h)
x = int(x)
y = int(y)

s = w * h / 2
if w / 2 == x and h / 2 == y:
    center = True
else:
    center = False

print(str(s) + " " + str(int(center)))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long long  a[3];
	for(int i = 0; i <= 2; i++)
		cin >> a[i];
	sort(a, a+3);
	if(a[2] % 2 == 0 || a[0] %2 ==0 || a[1] %2 == 0)
		printf("0");
	else{
		long long ans = a[0] * a[1];
		printf("%lld", ans);
	}
	
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, sum=0, r, x;
	cin>>n;
	x=n;
	if((n>=100)&&(n<=999)){
	
	while(n){
		r = n % 10;
	    n = n / 10;
		sum = sum * 10 + r;
	
	}
	if(x==sum)
	
	cout<<"Yes";
	else
	cout<<"No";
}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int main(){
  int N; cin>>N;
  int a[2*N];
  rep(i,2*N) cin>>a[i];
  sort(a,a+2*N);
  int ans=0;
  for(int i=0;i<2*N;i+=2) ans+=min(a[i],a[i+1]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
 
H, W = map(int, input().split())
A = [input() for i in range(H)]
q = deque()
c = [[-1] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append((i, j))
            c[i][j] = 0
D = [[0, 1], [1, 0], [0, -1], [-1, 0]]
while q:
    y, x = q.popleft()
    for dy, dx in D:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and c[ny][nx] == -1:
            q.append((ny, nx))
            c[ny][nx] = c[y][x]+1
print(max([max(l) for l in c]))

Measured memory_bytes: 87132
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
N,M = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i],B[i] = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    uf.union(A[i]-1,B[i]-1)
groups = uf.group_count()
print(groups-1)

Measured memory_bytes: 75648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,f,e) for(int (i)=(f); (i)<(e); (i)++)
#define repr(i,e,f) for(int (i)=(e-1); (i)>=(f); (i)--)

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

deque<int> g[100001];
int memo[100001];

int rec(int i){
    if(memo[i]!=-1) return memo[i];
    int ans = 0;
    for(auto j : g[i]){
        ans = max(ans, rec(j) + 1);
    }
    return memo[i] = ans;
}

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

    int x,y;
    rep(i,0,M){
        cin >> x >> y;
        g[x].push_back(y);
    }

    rep(i,1,N+1){
        memo[i] = -1;
    }

    // rep(i,1,N+1){
    //     cout << i << " : ";
    //     for(auto j : g[i]){
    //         cout << j << " ";
    //     }
    //     cout << endl;
    // }

    int ans = 0;
    rep(i,1,N+1){
        // cout << i << " : " << rec(i) << endl;
        ans = max(ans, rec(i));
    }
    cout << ans;
    
}


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

using namespace std;
struct rest{
	int no;
	char city[15];
	int point;
};
bool cmp(rest a,rest b)
{
	if(strcmp(a.city,b.city)>0)//a>b
	{
		return 0;
	}
	else if(strcmp(a.city,b.city)<0)
	{
		return 1;
	}
	else
	{
		return a.point>b.point;
	}
}
int main()
{
	int n;
	cin >> n;
	rest a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin >> a[i].city >> a[i].point; 
		a[i].no=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		cout << a[i].no << endl;
	}
	
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

int N;
int L[5555],R[5555];

int dp[2][5010][2];

signed main(){
    cin>>N;
    vpint ei;
    rep(i,N){
        int l,r;
        cin>>l>>r;
        ei.pb({l+r,l});
    }
    sort(all(ei));reverse(all(ei));
    rep(i,N){
        L[i]=ei[i].se;
        R[i]=ei[i].fi-ei[i].se;
    }

    fill_n(**dp,2*5010*2,INF);
    dp[0][0][0]=0;
    rep(i,N){
        rep(j,i+1){
            rep(k,2){
                if(dp[i&1][j][k]==INF)continue;
                chmin(dp[(i+1)&1][j+1][k],dp[i&1][j][k]+L[i]+(L[i]+R[i])*j);
                chmin(dp[(i+1)&1][j][k],dp[i&1][j][k]+R[i]+(L[i]+R[i])*(i-k-j));
                if(k==0)chmin(dp[(i+1)&1][j][k+1],dp[i&1][j][k]+(L[i]+R[i])*(N/2));
                dp[i&1][j][k]=INF;
            }
        }
    }

    int ans=INF;
    rep(i,N+1)chmin(ans,dp[N&1][i][0]);
    if(N&1){
        chmin(ans,dp[N&1][N/2][1]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=0
for i in range(n-1):
  s+=b[a[i]-1]
  if(a[i+1]-1==a[i]):
    s+=c[a[i]-1]
s+=b[a[n-1]-1]
print(s)
  

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define MAX 510

int H, W, a[MAX][MAX] = {}, temp[MAX][MAX] = {}, counta;
bool flags[MAX][MAX] = {};

signed main(){
	cin>>H>>W;
	
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			cin>>a[i][j];
			temp[i][j] = a[i][j];
		}
	}
	
	
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			if(a[i][j]%2 == 1 && j != W ){ a[i][j+1]++,a[i][j]--;counta++;}
		}
		if(a[i][W]%2 == 1 && i != H ){ a[i+1][W]++,a[i][W]--;counta++;}
	}
	cout<<counta<<endl;;
	
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			if(temp[i][j]%2 == 1 && j != W ){ 
				temp[i][j+1]++,temp[i][j]--;
				cout<<i<<" "<<j<<" "<<i<<" "<<j+1<<endl;
			}
		}
		if(temp[i][W]%2 == 1 && i != H ){
			 temp[i+1][W]++,temp[i][W]--;
			 cout<<i<<" "<<W<<" "<<i+1<<" "<<W<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4096
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input, "index" : 0, "max" : input.length,
  "hasNext" : function(){return (this.index < this.max);},
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  }
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var H = one[0];
  var W = one[1];
  var K = one[2];
  var count = 0;
  var list = new Array(H);
  var nullIndex = new Set();
  for(var i = 0; i < H; i++){
    list[i] = nextCharArray();
    if(list[i].indexOf("#") == -1){
       nullIndex.add(i);
    }
  }
  myerr(nullIndex);
  for(var i = 0; i < H; i++){
    if(!nullIndex.has(i)){
       count++;
       var isFirst = false;
       for(var j = 0; j < W; j++){
         if(list[i][j] == "#"){
            if(!isFirst){
               isFirst = true;
            }else{
              count++;
            }
            list[i][j] = count;
         }else{
            list[i][j] = count;
         }
       }
    }
  }
  
  var nullKeys = Array.from(nullIndex);
  for(var i = 0; i < nullKeys.length; i++){
    var tmp = nullKeys[i];
    for(var j = 1; j < H; j++){
      var U = tmp - j;
      var D = tmp + j;
      if(U >= 0){
         if(!nullIndex.has(U)){
            list[tmp] = list[U];
            nullIndex.delete(tmp);
            break;
         }
      }
      if(D < H){
         if(!nullIndex.has(D)){
            list[tmp] = list[D];
            nullIndex.delete(tmp);
            break;
         }
      }
    }
  }
  
  for(var i = 0; i < H; i++){
    list[i] = myconv(list[i],8);
  }
  myout(myconv(list,9));
}

Measured memory_bytes: 17044