akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> people(Q);
  for(int i = 0; i < Q; i++){
      cin >> people[i];
  }
  vector<int> ans(N,0);
  int content;
  for(int i = 0; i < Q; i++){
    content = people[i];
    ans[content - 1] = ans[content - 1] + 1;
  }
  for(int i = 0; i < N; i++){
      if(ans[i] + K > Q)
      cout << "Yes" << endl;
      if(ans[i] + K <= Q)
      cout << "No" << endl;
  }
}

Measured memory_bytes: 1408
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val len1 = StdIn.readInt
    val arrayA = StdIn.readLine().split(" ").map(_.toInt)
    val len2 = StdIn.readInt
    val arrayB = StdIn.readLine().split(" ").map(_.toInt)

    var count = 0
    for (value <- arrayB) count += binarySearch(value, arrayA)
    println(count)
  }

  def binarySearch(value: Int, array: Array[Int]): Int = {
    var left = 0
    var right = array.length
    while (left < right) {
      val mid = (left + right) / 2
      if (array(mid) == value) {
        return 1
      } else if (value < array(mid)) {
        right = mid
      } else {
        left = mid + 1
      }
    }
    return 0
  }
}

Measured memory_bytes: 71324
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,K = inpl()
ans = 0
while K**ans <= N:
    ans += 1

print(ans)


Measured memory_bytes: 4080
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
    
using namespace std;

typedef long long ll;

int main() {
    ll n,m;
    map<ll,ll> mp;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        ll a;
        ll b;
        cin>>a>>b;
        if (mp.count(a)) {
            mp.at(a)+=b;
        }
        else mp.insert(make_pair(a,b));
    }
    
    ll l=0,ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        if(l+itr->second>=m){
            ans+=(m-l)*itr->first;
            break;
        } else {
            l+=itr->second;
            ans+=itr->first*itr->second;
        }
    }
    
    cout<<ans<<endl;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	string w;
	cin >> w;
	vector<int> cnt(26,0);
	FOR(i,0,(int)w.size())
		cnt[w[i] - 'a']++;
	bool ans = true;
	FOR(i,0,26){
		if(cnt[i] % 2 == 1){
			ans = false;
			break;
		}
	}
	Yes(ans);
	return 0;
}


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

int main(){
    int N;
    int a[210];
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> a[i];
    }
    bool check  = false;
    int count = 0;
    while(true){
        for(int i = 0;i < N;i++){
            if(a[i] % 2 != 0) check = true;
        }
        if(check) break;
        for(int i = 0;i < N;i++) {
            a[i] /= 2;
        }
        count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  string s;
  ll k;
  cin >> s >> k;
  char ans = ' ';
  rep(i,k){
    if(s[i] == '1'){
      ans ='1';
      continue;
    }
    else{
      ans = s[i];
      break;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Prime p = new Prime();
		int n;
		Scanner sc = new Scanner(System.in);
		
		while(true){
			n = sc.nextInt();
			if(n == 0){
				break;
			}
			System.out.println(p.searchMaxQuadruplet(n));
		}
	}
}

class Prime {
	
	private final int size = 664579;
	private int[] prime;
	
	public Prime(){
		prime = new int[size];
		setPrime();
	}
	
    public void setPrime() {
        int counter = 0;
        int ptr = 0;
        

        prime[ptr++] = 2;
        prime[ptr++] = 3;

        for (int n = 5; n <= 10000000; n += 2) {
            boolean flag = false;
            for (int i = 1; prime[i] * prime[i] <= n; i++) {
                counter +=2;
                if (0 == n % prime[i]) {
                    flag = true;
                    break;
                }
            }
            
            if (!flag) {
                prime[ptr++] = n;
                counter++;
            }
        }
    }
    
    private int getIndex(int n){
    	for(int i=0; i<size; i++){
    		if(prime[i] > n){
    			return i-1;
    		}else if(prime[i] == n){
    			return i;
    		}
    	}
    	
    	return size-1;
    }
    
    public int searchMaxQuadruplet(int n){
    	int idx = getIndex(n);
    	
    	while(true){
    		if(prime[idx]-prime[idx-1] == 2){
    			if(prime[idx]-prime[idx-2] == 6){
    				if(prime[idx]-prime[idx-3] == 8){
    	    			return prime[idx];
    	    		}
        		}
    		}
    		idx --;
    	}
    	
    }
}

Measured memory_bytes: 25808
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600
#define MAX 1000000

int  dp[MAX+1];
int dp2[MAX+1];

int main(){
  vector<int> nums,odds;

  int tmp=0, n=1;
  while(tmp<=MAX){
    tmp+=n*(n+1)/2;
    nums.pb(tmp);
    if(tmp%2==1) odds.pb(tmp);
    n++;
  }

  fill(dp, dp+MAX+1, INF);
  fill(dp2, dp2+MAX+1, INF);
  dp[0]=0; dp2[0]=0;

  repl(i,1,MAX+1){
    for(int nxt : nums){
        if(i<nxt) continue;
        dp[i] = min(dp[i], dp[i-nxt]+1);
    }
    for(int nxt : odds){
        if(i<nxt) continue;
        dp2[i] = min(dp2[i], dp2[i-nxt]+1);
    }
  }

  while(scanf("%d", &n), n){
    printf("%d %d\n", dp[n], dp2[n]);
  }

  return 0;
}

Measured memory_bytes: 10996
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;
long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	ll i, ans = 0, j;
	ll N, AB = 0, tail_A = 0, head_B = 0, B_A = 0,k;
	string S;
	vector<int> A(100000), L(100000);
	cin >> N >> k >> S;
	S[k-1] = S[k-1] + 32;
	cout << S << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  int W=X*Y*Z;
  vector<ll> A(X),B(Y),C(Z),sum();
  for(int i=0;i<X;i++){
          cin>>A.at(i);
  }
  for(int i=0;i<Y;i++){
      cin>>B.at(i);
  }
  for(int i=0;i<Z;i++){
      cin>>C.at(i);
  }
 vector<ll> AB,ABC;
for(int i=0;i<X;i++){
    for(int j=0;j<Y;j++){
    AB.push_back(A.at(i)+B.at(j));
    }
}
sort(AB.begin(),AB.end(),greater<ll>());
AB.resize(K);
for(int i=0;i<K;i++){
    for(int j=0;j<Z;j++){
    ABC.push_back(AB.at(i)+C.at(j));
    }
}
 sort(ABC.begin(),ABC.end(),greater<ll>());
    ABC.resize(K);
    for(int i=0;i<K;i++){
        cout<<ABC.at(i)<<endl;
    }
}


Measured memory_bytes: 42984
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String ans = "APPROVED";
    
    for(int i = 0; i < N; i++){
      int A = sc.nextInt();
      if(A%2 == 0 && !(A%3 == 0 || A%5 == 0)){
        ans = "DENIED";
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 25044
#!ruby -pal
i=j=d=0
t,a,b=$F
s=""
while a[i]&&b[j]
if a[i]==b[j] 
[s+=a[i],i+=1,j+=1]
else
c,k,p=a[i]==?(?[a,i,0]:[b,j,1]
d=1
t>?i&&s+=c[k]
k+=1
while d>0
c[k]==?(&&d+=1
c[k]==?)&&d-=1
t>?i&&s+=c[k]
k+=1
end
p==0?(i=k):j=k
end
end
$_=s

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

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  for (int i=0; i<N; i++) {
    int v=A[i];
    int j=i-1;
    while (j>=0 && A[j]>v) {
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    for (int i=0; i<N; i++) {
      printf("%s%d",(i==0?"":" "),A[i]);
    }
    printf("\n");
  } 
  return 0;
}

Measured memory_bytes: 3200
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for key in A:
    d[key] += 1
    #print(d)

Sum = 0
for i in d:
    n = d[i]
    Sum += (n * (n - 1)) // 2
    #print((n * (n - 1)) // 2)
    #print(d[A[i]],i)
    #print(d)

#print(Sum)

for i in range(N):
    n = d[A[i]]
    hoge = Sum - (n*(n-1))//2
    n -= 1
    hoge += (n*(n-1))//2
    print(hoge)

Measured memory_bytes: 110152
#include<iostream>

using namespace std;

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

long long int h,w,n;
int ans = 0;
for(int i=1;i<=3500&&ans==0;i++){
    for(int j=1;j<=3500&&ans==0;j++){
        if(4*i*j-N*(i+j)>0&&N*i*j%(4*i*j-N*(i+j))==0){
            cout<<i<<" "<<j<<" "<<N*i*j/(4*i*j-N*(i+j))<<"\n";
       
        ans++;
        }
    }

}

return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include<math.h>
#include<stdio.h>


int main()
{
	std::string a;
	std::cin >> a;
	if (a[2] == a[3] && a[4] == a[5]) {
		std::cout << "Yes" << std::endl;
	}
	else
	{
		std::cout << "No" << std::endl;
	}
	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;

int main(){
    int prev,a,cnt;
    set<int> set;
    cin>>prev;
    set.insert(prev);
    cnt=2;
    while(1){
        if(prev%2==0){
            a=prev/2;
        }else{
            a=3*prev+1;
        }
        if(set.find(a)!=set.end()){
            cout<<cnt<<endl;
            return 0;
        }
        set.insert(a);
        prev=a;
        cnt++;
    }
}


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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define all(a) (a).begin(), (a).end()

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int a,b,c;cin>>a>>b>>c;
  cout<<a*b/2<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000
#define INF 9223372036854775807
#define EPS 1e-9
#define DEBUG 0
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

vector< vector<ll> > input(100000, vector<ll>(3));
  vector<ll> d;
  ll V, E;
  priority_queue<Pll, vector<Pll>, greater<Pll> > que;
  vector<Pll> edges[MAX];
  
  void dijkstra(ll start){
    rep(E){
        edges[input[i][0]].push_back(Pll(input[i][1], input[i][2]));
        edges[input[i][1]].push_back(Pll(input[i][0], input[i][2]));
    }

    d.clear();
    rep(V){
        d.push_back(INF);
    }
    d[start] = 0;
    que.push(Pll(0, start));
    
    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d[v.second] < v.first) continue; //?
        rep(edges[v.second].size()){
          Pll e = edges[v.second][i];
          if(d[e.first] > d[v.second] + e.second){
              d[e.first] = d[v.second] + e.second;
              que.push(Pll(d[e.first], e.first));
          }
        }
    }
  }
  
  signed main(){
    cin >> V;
    E = V-1;
    rep(E){
        ll a, b, c;
        cin >> a >> b >> c;
        input[i][0] = a-1;
        input[i][1] = b-1;
        input[i][2] = c;
    }

    int Q, K;
    cin >> Q >> K;
    K--;
    dijkstra(K);
    rep(Q){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << d[x] + d[y] << endl;
    }
  }

Measured memory_bytes: 39280
N = int(input())
h = list(map(int, input().split()))
dp = [float('inf')]*len(h)
dp[0] = 0
for i in range(N-1):
    if i<N-2:
        dp[i+2] = min(dp[i]+abs(h[i]-h[i+2]), dp[i+2])
    dp[i+1] = min(dp[i]+abs(h[i]-h[i+1]), dp[i+1])
print(dp[-1])

Measured memory_bytes: 13980
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans, arr[2003];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>arr[i];
	}
	sort(arr + 1, arr + n + 1);
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			int l = j, r = n, cur = 0;
			while(r >= l){
				int mid = ((l + r) >> 1);
				if(arr[mid] >= arr[i] + arr[j])r = mid - 1;
				else{
					cur = mid;
					l = mid + 1;
				}
			}
			ans += cur - j;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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 ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int gcd(int a,int b){
    return (b?gcd(b,a%b):a);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    int ans;
    for(int i=0;i<n;i++){
        int a;cin >> a;
        if(!i){
            ans=a;
        }
        else{
            ans=gcd(ans,a);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

int a[10],n;

bool cmp(int a,int b){
	return a > b;
}

int main()
{	
	for(int i=0;i<10;i++){
		cin >> a[i];
	}
	sort(a,a+10);
	for(int i=9;i>=7;i--) {
		cout << a[i] << endl;
	}
	return 0;	
}

Measured memory_bytes: 1176
N = int(input())
dp = [0] * (10 ** 5 + 10)
dp[0] = 0
for i in range(1, (10 ** 5) + 10):
    dp[i] = 10 ** 5 + 1
    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i - p] + 1)
        p *= 6

    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i - p] + 1)
        p *= 9

print(dp[N])

Measured memory_bytes: 3828
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    ins(s);
    // vl A(n); in1(A); 
    if(s[2]==s[3]&&s[4]==s[5]){
        out("Yes");
    }else{
        out("No");
    }
    // out();
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
	using namespace std;

	int main() {
		int N;
        cin >> N;
      
      	cout << N*N*N << endl;

	}


Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>

#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)

using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
int N[222222][26];
char S[222222];
int L[26];
int dp[222222];
int opt[222222];
int calc(int p) {
	if(p == n)
		return 0;
	int& ans = dp[p];
	if(ans == -1) {
		ans = n+10;
		for(int l = 0; l < 26; l++) {
			int nxt = N[p][l];
			if(nxt == -1) {
				opt[p] = l;
				ans = 1;
			//	printf("p==%d, l==%d\n", p, l);
				return ans;
			} else if(calc(N[p][l])+1 < ans) {
				ans = calc(N[p][l])+1;
				opt[p] = l;
			}
		}
		return ans;
	}
	return ans;

}
int main() {
	scanf("%s", S+1);
	S[0] = 'a';
	n = strlen(S);
	memset(dp, -1, sizeof(dp));
	memset(N, -1, sizeof(N));
	memset(L, -1, sizeof(L));
	for(int i = n; i >= 0; i--) {
		REP(j, 26) N[i][j] = L[j];
		L[S[i]-'a'] = i;
	}
	int LL = calc(0);
	int j = 0;
	REP(i, LL) {
		printf("%c", opt[j]+'a');
		j = N[j][opt[j]];
	}
	printf("\n");

	
	
	return 0;
}


Measured memory_bytes: 24960
import numpy as np
n,s,*a=map(int,open(0).read().split())
mod=998244353
d=np.zeros(s+1,dtype=np.int64)
d[0]=1
for x in a:
	p=d*2
	if x<=s:
		p[x:]+=d[:s-x+1]
	p%=mod
	d=p
print(d[-1])

Measured memory_bytes: 27344
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int distance[]={6,7,5,5,20,15},money[6][6]={{300,500,600,700,1350,1650},{350,450,600,1150,1500},{250,400,1000,1350},{250,850,1300},{600,1150},{500}};
	int start,finish;
	while(cin>>start,start){
		int time[2][2];
		for(int i=0;i<2;i++)cin>>time[0][i];
		cin>>finish;
		for(int i=0;i<2;i++)cin>>time[1][i];
		int num=0;
		for(int i=start;i<finish;i++)num+=distance[i-1];
		bool kawa=0;
		for(int i=0;i<2&&!kawa&&num<41;i++)if(time[i][0]==18||time[i][0]==17&&time[i][1]>29||time[i][0]==19&&time[i][1]<31)kawa=1;
		num=money[start-1][finish-start-1];
		if(kawa){
			num/=2;
			if(num%50!=0)num+=25;
		}
		cout<<num<<endl;
	}
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt() % 10;
		String ans;
		if (n == 3) {
		    ans = "bon";
		} else if (n == 0 || n == 1 || n == 6 || n == 8) {
		    ans = "pon";
		} else {
		    ans = "hon";
		}
		System.out.println(ans);
	}
}
 

Measured memory_bytes: 35728
#pragma GCC optimize("-O3")
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#define LL long long
#define ui unsigned int
#define ull unsigned long long
using namespace std;
  
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void Out(int x){
    if(x>9) Out(x/10);
    putchar('0'+x%10);
}
LL gcd(LL x,LL y){
    if(!y) return x;
    return gcd(y,x%y);
}
LL qpow(LL x,LL y,LL P){
    LL re=1;
    while(y){
        if(y&1) re=re*x%P;
        x=x*x%P;y>>=1;
    }
    return re;
}
const double eps=1e-6;
const LL P=1e9+7;
const int N=500050;
int n,m;
int a[100000+10];
int tp=0;
int b[100000+10];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i) scanf("%d",&a[i]);
    for(int i=1;i<=m;++i){
    	if(a[i]%2==0) continue;
    	if(i==1||i==m) continue;
    	if(a[1]%2==0){
    		swap(a[1],a[i]);
    		continue;
		}
		if(a[m]%2==0){
			swap(a[m],a[i]);
			continue;
		}
		puts("Impossible");return 0;
	}
	if(m==1){
		b[++tp]=1;
		if(a[1]>1)b[++tp]=a[1]-1;
	}
	else{
		b[++tp]=a[1]+1;
		for(int i=2;i<m;++i) b[++tp]=a[i];
		if(a[m]>1) b[++tp]=a[m]-1;
	}
	for(int i=1;i<=m;++i) printf("%d ",a[i]);puts("");
	printf("%d\n",tp);
	for(int i=1;i<=tp;++i) printf("%d ",b[i]);
	puts("");
	return 0;
}
/*
5
1 2 2
1 2 2
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include "../cxx-prettyprint/prettyprint.hpp" // vecの内容をきれいに表示

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)

// 今回は関数でdpテーブルをいじるのでグローバル
vector<int> dp(100001,0);
vector<bool> flg(100001, false);
vector< vector<int> > A(100001,vector<int>(0));


int f(int x){
	// すでに探索完了ならその値を返す
	if(flg[x]) return dp[x];
	flg[x] = true;
	// 探索
	int fans = dp[x];
	for(const auto y : A[x]){
		// cout << y;
		fans = max(fans, f(y) + 1);
	}
	// cout << "\n";
	return dp[x] = fans;
}

int main(){
// ここに処理を記述

	int N, M;
	cin >> N >> M;

	int x, y;
	for(int i=0; i<M; i++){
		cin >> x >> y;
		A[x].push_back(y);
	}

	// DAG(閉路なし有向グラフ)はトポロジカルソートでDP可能性あり
	// 今回はそうじゃなくてメモ化再帰で記述
	// f(x) : xを始点とする最長経路
	// f(x) = 0(xの行先なし) or max(f(y)+1|x->yが存在するy)
	// この時答えはmax(f(x))
	int ans = 0;
	FOR(i,1,N+1){
		ans = max(ans,f(i));
	}

	// cout << dp << "\n";

	cout << ans << "\n";

return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const LL INF=1e18;

vector<LL> A, F;
int N;

LL count(LL mid){
	LL res=0;
	rep(i,N){
		LL a=mid/F[i];
		res+=max(0LL,A[i]-a);
	}
	return res;
}

bool exceed(LL mid, LL key){
	LL res=count(mid);
	if(res>key) return true;
	else return false;
}

LL binary_search(LL key){
	LL left=-1, right=INF;
	while(right-left > 1){
		LL mid=left+(right-left)/2;
		if(exceed(mid,key)) left=mid;
		else right=mid;
	}
	return right;
}

int main(){
	cin >> N;
	LL K;
	cin >> K;
	A.resize(N);
	F.resize(N);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> F[i];
	sort(A.begin(),A.end(),greater<LL>());
	sort(F.begin(),F.end());
	LL ans=binary_search(K);
	cout << ans << endl;

	return 0;
}

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

int main()
{
	string str;
	while(cin >> str){
		for(unsigned i=0;i<str.size();i++){
			if(str[i] == '@'){
				stringstream sst;
				sst << str[i+1];
				int n;
				sst >> n;
				for(int j=0;j<n;j++){
					cout << str[i+2];
				}
				i+=2;
			}
			else
				cout << str[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
using namespace std;
const int BUF = 100005;


int nVal;
int val[BUF];
int nEdge;
int edge[BUF][2];

void read() {
    cin >> nVal;
    for (int i = 0; i < nVal; ++i) cin >> val[i];

    cin >> nEdge;
    for (int i = 0; i < nEdge; ++i) {
        cin >> edge[i][0] >> edge[i][1];
    }
}


void work() {
    long long sum = 0;
    int id2cnt[BUF] = {};
    for (int i = 0; i < nVal; ++i) {
        ++id2cnt[val[i]];
        sum += val[i];
    }

    for (int loop = 0; loop < nEdge; ++loop) {
        int src = edge[loop][0];
        int dst = edge[loop][1];
        
        sum -= 1LL * src * id2cnt[src];
        sum += 1LL * dst * id2cnt[src];

        id2cnt[dst] += id2cnt[src];
        id2cnt[src] = 0;

        cout << sum << endl;
    }
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 5108
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e16
#define mod 1000000007
#define en '\n'
#define ld long double
#define ff first
#define ss second
#define ull unsigned long long 
ll pw(ll b, ll r, ll md){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%md;
		b = (b*b)%md;
		r>>=1;
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;cin>>s;
	ll p1 = 0, p2 = s.length()-1;
	ll n = s.length();
	while(p1<p2){
		if(s[p1]==s[p2])p1++,p2--;
		else break;
	}
	if(p1>=p2){
		p1 = 0 , p2 = ((n-1)>>1)-1;
		while(p1<p2)if(s[p1]==s[p2])p1++,p2--;else break;
		if(p1>=p2){
			p1 = ((n+3)>>1)-1;
			p2 = n-1;
			while(p1<p2)if(s[p1]==s[p2])p1++,p2--;else break;
			if(p1>=p2)cout<<"Yes\n";
			else cout<<"No\n";
		} else cout<<"No\n";

	} else cout<<"No\n";
	return 0 ; 
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long
#define ull unsigned long long

using namespace std;

const long long mod = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, t;
    cin >> a >> b >> t;

    cout << (t/a)*b << "\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  int s = a[1] == a[0] ? 0 : (a[1] - a[0]) / abs(a[1] - a[0]);
  int num = 1;

  REP(i, n - 1){
    if(s * (a[i + 1] - a[i]) < 0){
      if(i < n - 2) {
        s = a[i + 2] - a[i + 1] == 0 ? 0 : (a[i + 2] - a[i + 1]) / abs(a[i + 2] - a[i + 1]);
        i++;
      }
      num++;
    }
    if(s == 0 && a[i + 1] - a[i] != 0){
      s = (a[i + 1] - a[i]) / abs(a[i + 1] - a[i]);
    }
  }

  cout << num << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;
  ll n,k,r,s,p,ans;
  string t;
void solve()
{
  bool free = false;
  cin>>n>>k>>r>>s>>p;
  cin>>t;
  for (ll i = 0; i < k; ++i)
  {
    std::vector<ll>dp(3);
    for(ll j =i;j<n;j+=k)
    {
     std::vector<ll> cur(3);
      if(t[j]=='s') cur[0]=r;
      if(t[j]=='p') cur[1]=s;
      if(t[j]=='r') cur[2]=p;
      vector<ll>nxt(3);
      for(ll a=0;a<3;a++)
        for(ll b=0;b<3;b++)
        {
          if(a!=b)
            nxt[a] = max(nxt[a],dp[b]+cur[a]);
        }
        for (int a = 0; a <3 ; ++a)
        {
          dp[a] = nxt[a];
        }
    }
     ans += *max_element(dp.begin(), dp.end());
  }

  
  cout<<ans<<"\n";
}

signed main(){
     
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
int N,K,ans,a;
  cin>>N>>K;
  int NO[N];
  for(int i=0;i<N;i++){NO[i]=1;}
  ans=N;
  for(int i=0;i<K;i++){
    int d;
    cin>>d;
    
  for(int j=0;j<d;j++){
    int a;
    cin>>a;
    if(NO[a-1]!=0){
      ans--;
                NO[a-1]=0;
                }
  
  }
  
  }
    cout<<ans;

}

Measured memory_bytes: 3196
s = input()
def s_count(s):
    m = list(s)
    array = [0. for i in range(len(m))]
    count = 0
    for i in range(len(m)):
        if m[i] == 'R':
            array[i] += 1
            if (i > 0 and m[i] == m[i-1]):
                count += 1
                array[i] += count
            else:
                count = 0
    return max(array)
print(int(s_count(s)))

Measured memory_bytes: 9076
#include<bits/stdc++.h>
#define io std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define M 1000000007
#define int long long
#define pb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define nl "\n"
#define yy "YES\n"
#define nn "NO\n"
using namespace std;
signed main()
{
    io;
    long double a,b;
    cin>>a>>b;
    int res=a*b;
    string s=to_string(res);
    cout<<s;
}



Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
ll f(ll b, ll n)
{
    if (n < b) return n;
    return f(b, n / b) + n % b;
}

void _main()
{
    ll n, s;
    cin >> n >> s;

    if (n < s)
    {
        cout << -1 << endl;
        return;
    }
    else if (n == s)
    {
        cout << n + 1 << endl;
        return;
    }

    for (ll b = 2; b * b <= n; ++b)
    {
        if (f(b, n) == s)
        {
            cout << b << endl;
            return;
        }
    }

    ll p = 0;
    while (p * p < n) ++p;
    --p;

    for (; p > 0; --p)
    {
        ll b = (n - s) / p + 1;
        if (b == 1) continue;
        if (f(b, n) == s)
        {
            cout << b << endl;
            return;
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string s; cin >> s;
    int ans = 0;
    char prev = s[0];
    FOR(i,1,s.size()) {
        if (s[i] != prev) ans++;
        prev = s[i];
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    string s;
    cin >> s;
    int S=0,W=0,N=0,E=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='S'){
            S++;
        }else if(s[i]=='N'){
            N++;
        }else if(s[i]=='W'){
            W++;
        }else{
            E++;
        }
    }
    if((S>0&&N>0&&E==W)||(E>0&&W>0&&N==S)||E*W*S*N!=0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
    }
    let mut cnt: Vec<usize> = vec![0;4];
    for i in 0..n {
        input!{
            s: char,
        }
        match s {
            'G' => cnt[0]+=1,
            'W' => cnt[1]+=1,
            'P' => cnt[2]+=1,
            'Y' => cnt[3]+=1,
            _ => return,
        }
    }
    let mut sum = 0;
    for i in cnt {
        if i!=0 {
            sum += 1;
        } 
    }
    if sum==3 {
        println!("Three");
    } else {
        println!("Four");
    }
}


Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;


template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    long long X, K, D;
    cin >> X >>K >> D;
    X=abs(X);
    D=abs(D);

    long long sho = X/D;
    long long amari = X%D;

    if(sho >= K){
        cout << X- K*D << endl;
    }
    else{
        K-=sho;
        if(K%2 ==0){
            cout << amari << endl;
        }
        else{
            cout << abs(amari-D) << endl;
        }
    }
    
    

    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

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

    vector<int> nums;
    int now = 1; // 今見ている数
    int cnt = 0; // nowがいくつ並んでいるか
    rep(i, N) {
        if (S[i] == (char) ('0' + now)) cnt++;
        else {
            nums.push_back(cnt);
            now = 1 - now; // 0と1を切り替える計算
            cnt = 1; // 新しくカウントする
        }
    }
    if (cnt != 0) nums.push_back(cnt);

    // 1110001100111 のような配列が欲しい
    // 1110001100 のように０で終わっていたら一つ足す
    if (nums.size() % 2 == 0) nums.push_back(0);

    int add = 2 * K + 1;
    int ans = 0;

    // 1110001100111 の1からカウントするので偶数番目から始める
    for (int i = 0; i < nums.size(); i += 2) {
        int tmp = 0;
        int left = i;
        int right = min(i + add, (int) nums.size());
        for (int j = left; j < right; j++) {
            tmp += nums[j];
        }
        ans = max(tmp, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1020
def min2(a, b)
    return a <= b ? a : b
end

n = gets.chomp.to_i
h = gets.chomp.split(" ").map(&:to_i)

# cost[i] : i-1段目到達の最小コスト
cost = Array.new(h.length+1, 0)

(1..(n-1)).each do |i|
    if i == 1
        cost[i] = (h[i]-h[i-1]).abs
        next
    end
    cost[i] = min2(cost[i-1] + (h[i]-h[i-1]).abs,
                    cost[i-2] + (h[i]-h[i-2]).abs)
end

puts cost[n-1]

Measured memory_bytes: 9228
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0,dp[1000000],m ;
bool visit[1000000] ; 
stack <LL> St ; 
vl v[1000000] ; 
void dfs(LL x)
{  visit[x] = 1 ; 
   for(auto i:v[x])  
      if(!visit[i]) dfs(i) ; 
   St.push(x) ; 
}

int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL x,y ;
    cin>>n>>m ; 
    REP(i,m)
    {  cin>>x>>y ; 
       v[x].pb(y) ; 
    }
    for(int i=1;i<=n;i++)
      if(!visit[i]) dfs(i) ;
    for(int i=1;i<=n;i++) dp[i] = (LL)1E9 * -1LL ; 
    // while(!St.empty())
    // {   cout<<St.top()<<endl; 
    //     St.pop() ; 
    // }
    dp[St.top()] = 0 ; 
    while(St.empty()==false)
    {  LL x = St.top() ; 
       St.pop() ; 
       if(dp[x]<0) dp[x] = 0 ;
       for(auto i:v[x]) 
         if(dp[i]<dp[x] + 1) 
            dp[i] = dp[x] + 1 ;   
        
    } 
    cout<<*max_element(dp+1,dp+1+n)<<endl ; 
}
//Check for 0,1 and other corner cases.

Measured memory_bytes: 32896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    vector<ll> X(N), Y(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> X[i] >> Y[i];
    }

    map<pair<ll,ll>, int> d;
    for ( int i = 0; i < N; i++ ) {
        for ( int j = i+1; j < N; j++ ) {
            d[make_pair(X[i]-X[j],Y[i]-Y[j])]++;
            d[make_pair(X[j]-X[i],Y[j]-Y[i])]++;
        }
    }

    pair<ll,ll> p;
    int m = 0;
    for ( auto x : d ) {
        if ( m < x.second ) {
            p = x.first;
            m = x.second;
        }
    }
    ll ans = N - m;
    cout << ans << '\n';
    return 0;
}

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

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

main = do
    [n,a,b] <- getIntList
    hs <- replicateM n getInt
    let f k = sum $ map (g2 . g1) hs
            where g1 h = max 0 $ h - k * b 
                  g2 h | h == 0 = 0
                       | otherwise = (h-1) `div` (a-b) + 1
    let bs l r | r - l == 1 = r
               | f m <= m = bs l m
               | otherwise = bs m r
               where m = l + (r - l) `div` 2
    print $ bs 0 1000000000

Measured memory_bytes: 22992
#include<iostream>
using namespace std;
main(){
int n,m,i,j,k,l,x[9999][2],y[9999][2],x2,y2,c,a;
while(true){
cin>>m;
if(m==0){break;}
for(i=0;i<m;i++){cin>>x[i][0]>>y[i][0];}
cin>>n;
for(i=0;i<n;i++){cin>>x[i][1]>>y[i][1];}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
a=0;x2=x[j][1]-x[i][0];y2=y[j][1]-y[i][0];
for(k=0;k<m;k++){c=0;
for(l=0;l<n;l++){
if(x[k][0]+x2==x[l][1] && y[k][0]+y2==y[l][1]){c++;break;}
}
if(c==0){break;}
a++;
if(a==m){goto z;}
}
}
}
z:;
cout<<x2<<' '<<y2<<endl;
}
}

Measured memory_bytes: 1184
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char* argv[]){
  int a1, a2, a3;
  std::cin >> a1 >> a2 >> a3;
  int t[6];
  t[0] = std::abs(a1 - a2) + std::abs(a2 - a3);
  t[1] = std::abs(a1 - a3) + std::abs(a2 - a3);
  t[2] = std::abs(a2 - a1) + std::abs(a3 - a1);
  t[3] = std::abs(a2 - a3) + std::abs(a3 - a1);
  t[4] = std::abs(a2 - a3) + std::abs(a2 - a1);
  t[5] = std::abs(a1 - a3) + std::abs(a2 - a1);
  int min = 300;
  for (int i = 0; i < 6; i++){
    if(t[i] < min){
      min = t[i];
    }
  }
  std::cout << min << std::endl;
  return 0;  
}




Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }

//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
int main(void){
    int x,a;cin>>x>>a;
    if(x<a) cout<<"0"<<endl;
    else cout<<"10"<<endl;
    return 0;
}
//////////////////
//  B
/*int main(void){

    return 0;
}*/
//////////////////
//  C
/*int main(void){

    return 0;
}*/
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3592
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////


void solve() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	vector<vector<int> >dp(F + 1, vector<int>(F + 1, 0));
	dp[0][0] = 1;
	for (int f = 0; f < F; ++f) {
		for (int mizu = 0; mizu < f; mizu+=100) {
			for (int syu = 0; mizu + syu < f; ++syu) {
				if (dp[mizu][syu] == 0) continue;
				if (mizu + 100 * A <= F) {
					dp[mizu + 100 * A][syu] = 1;
				}
				if (mizu + 100 * B <= F) {
					dp[mizu + 100 * B][syu] = 1;
				}
				if (syu + C <= F) {
					dp[mizu][syu + C] = 1;
				}
				if (syu + D <= F) {
					dp[mizu][syu + D] = 1;
				}
			}
		}
	}

	int ansmizu = 100*A;
	int anssyu = 0;
	LD ansNo = 0;
	for (int f = 0; f <= F; ++f) {
		for (int mizu = 0; mizu <= f; mizu+=100) {
			for (int syu = f-mizu; syu>=0; --syu) {
				if (dp[mizu][syu] == 0) continue;
				if (E * mizu / 100 < syu) continue;//溶けてない
				
				

				LD M = mizu;
				LD S = syu;
				LD res = 100 * S / (M + S);
				if (anssyu*(mizu+syu) < (anssyu+ansmizu)*syu) {
					ansmizu = M;
					anssyu = S;
					ansNo = res;
				}
				break;
			}
		}
	}
	cout <<ansmizu+ anssyu << " " << anssyu << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 32896
import java.util.*;
public class Main {

	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int count =0;
    for(int i =0;i<=A;i++){
    	for(int j=0;j<=B;j++){
    		for(int z=0;z<=C;z++){
    		if(X == 500*i + 100*j + 50*z){
    			count++;
    		}	
    		}
    	}
    }
    System.out.println(count);
	}
}


Measured memory_bytes: 22868
### subroutines

def hm2min(hm)
  hh, mm = hm.split(':').map(&:to_i)
  hh * 60 + mm
end

### main

loop do
  n = gets.to_i
  break if n == 0

  users = []
  maxid = 0
  
  n.times do
    md, hm, io, id = gets.strip.split
    min = hm2min(hm)
    id = id.to_i
    maxid = id if maxid < id
    #p [md, hm, io, id]
    
    users[id] = {} if users[id].nil?
    users[id][md] = [] if users[id][md].nil?
    #p users[id][md]
    
    if io == 'I'
      users[id][md] << [min]
    else
      users[id][md].last << min
    end
  end
  #p users

  sums = (maxid + 1).times.map{0}
  if users[0]
    for md in users[0].keys
      users[0][md].each do |gm0, gm1|
        for id in (1..maxid)
          next if users[id].nil? || users[id][md].nil?
          users[id][md].each do |im0, im1|
            if gm1 >= im0 && im1 >= gm0
              sums[id] += [gm1, im1].min - [gm0, im0].max
            end
          end
        end
      end
    end
  end
  #p sums

  puts sums.max
end

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

int main()
{
	long long h,n,a;

	cin >> h >> n;
	for (long long i=0;i<n;i++){
		cin >> a;
		h-=a;
		if(h<=0) {cout <<"Yes"<<endl;
		            break;
		}
	}
	if(h>0) cout <<"No"<< endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
	int numbers[3];

	for (int i = 0; i < 3; ++i)
	{
		cin >> numbers[i];
	}

	sort(numbers, numbers + 3);

	printf("%d %d %d\n", numbers[0], numbers[1], numbers[2]);

	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            while(true){
                int n = Integer.parseInt(reader.readLine());
                if(n == 0){
                    break;
                }
                int sum = 0;
                int max = 0;
                int min = 1000;
                for(int i = 0; i < n; i++){
                    int a = Integer.parseInt(reader.readLine());
                    sum += a;
                    if(max < a){
                        max = a;
                    }
                    if(min > a){
                        min = a;
                    }
                }
                    int ave = (sum - max - min)/(n - 2);
                    System.out.println(ave);
                
                }
            
        } catch (IOException e) {
            
        }
    }
}


Measured memory_bytes: 24776