akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N_T 1000001
#define N_P 10001
#define BASE 64

int* kmpSearch(char*, char*);
int* initNext(char*);

int myIndex(char);

int main() {
  char T[N_T];
  char P[N_P];
  int* pos;

  int i;
    
  while (scanf("%s %s", T, P) != EOF) {
    pos = kmpSearch(T, P);

    for (i = 1; i <= pos[0]; ++i) {
      printf("%d\n", pos[i]);
    }
  }

  return 0;
}

int* kmpSearch(char* T, char* P) {
  int i, j;
  int cnt = 0;
  int M   = strlen(P);
  int N   = strlen(T);
  
  int* next;
  int* pos;

  if (N < M) {
    pos    = (int*)malloc(sizeof(int)*1);
    pos[0] = 0;
    return pos;
  } else {
    pos = (int*)malloc(sizeof(int)*(N-M+2));
  }
  
  next = initNext(P);  
  for (i = 0, j = 0; i < N; ++i, ++j) {
    while ((j >= 0) && (T[i] != P[j])){
      j = next[j];
    }

    if (j == M - 1) {
      cnt++;
      pos[cnt] = i - M + 1;

      do {
	j = next[j];
      }	while ((j >= 0) && (T[i] != P[j]));
    }
  }
  pos[0] = cnt;
  
  return pos;
}

int* initNext(char* P){
  int i, j;
  int M = strlen(P);
  int* next = (int*)malloc(sizeof(int)*M);

  next[0] = -1;
  for (i = 0, j = -1; i < M; ++i, ++j, next[i] = j) {
    while ((j >= 0) && (P[i] != P[j])) {
      j = next[j];
    }
  }
  
  return next;
}

Measured memory_bytes: 5468
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;
    
    if (s==u){
        cout << a-1 << " " << b << endl;
    }
    else{
        cout << a << " " << b-1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;


int main()
{
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    bool ok=true;
    for(int i=0;i<s.length()&&i<t.length();i++)
    {
        // cout<<s[i]<<" "<<t[t.length()-i-1]<<endl;
        if(s[i]==t[t.length()-i-1])continue;
        else if(s[i]<t[t.length()-i-1])
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        ok=false;
    }
    if(s.length()<t.length()&&ok)cout << "Yes" <<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pa[133333];
struct R{int v,sek,w;}e[233333];
int kom[133333],cnt;
void Ins(int a,int b,int c){e[++cnt]=(R){b,kom[a],c};kom[a]=cnt;}
int ls[133333],rs[133333],leg[133333];
long long dep[133333];
vector<long long>p[133333],f[133333];
void init(int u)
{
	leg[u]=1;
	for(int i=kom[u];i;i=e[i].sek)
	{
		dep[e[i].v]=dep[u]+e[i].w;
		init(e[i].v);
		leg[u]+=leg[e[i].v];
		leg[e[i].v]>leg[ls[u]]?rs[u]=ls[u],ls[u]=e[i].v:rs[u]=e[i].v;
	}
}
long long p1[2666666],q1[2666666],p2[2666666],q2[2666666];
int cp1,cp2;
inline long long gmin(register long long a,register long long b){return a<b?a:b;}
void DFS(int u,long long mid)
{
	if(!ls[u])
	{
		//printf(">>>>>>%d %lld\n",u,dep[u]);
		p[u].push_back(dep[u]);
		f[u].push_back(dep[u]);
		return;
	}
	DFS(ls[u],mid);
	DFS(rs[u],mid);
	cp1=cp2=0;
	int sl=p[ls[u]].size(),sr=p[rs[u]].size(),pl=0;
	//printf("sol of %d->%d %d %d %d %lld %lld\n",u,ls[u],rs[u],sl,sr,f[rs[u]][sr-1]+p[ls[u]][0]-2*dep[u],f[ls[u]][sl-1]+p[rs[u]][0]-2*dep[u]);
	if(!sl||!sr)return;
	if(f[rs[u]][sr-1]+p[ls[u]][0]-2*dep[u]<=mid)
	for(int i=0;i<sr;i++)
	{
		bool fl=0;
		for(;pl<sl&&f[rs[u]][i]+p[ls[u]][pl]-2*dep[u]<=mid;pl++)fl=1;if(fl)pl--;
		//printf("[%d %d] %lld\n",i,pl,f[rs[u]][i]+p[ls[u]][pl]-2*dep[u]);
		if(f[rs[u]][i]+p[ls[u]][pl]-2*dep[u]<=mid)
		{
			p1[++cp1]=p[rs[u]][i];
			q1[cp1]=f[ls[u]][pl];
		}
	}
	pl=sl-1;
	if(f[ls[u]][sl-1]+p[rs[u]][0]-2*dep[u]<=mid)
	for(int i=sr;i--;)
	{
		bool fl=0;
		for(;~pl&&f[ls[u]][pl]+p[rs[u]][i]-2*dep[u]<=mid;pl--)fl=1;if(fl)pl++;
		if(f[ls[u]][pl]+p[rs[u]][i]-2*dep[u]<=mid)
		{
			p2[++cp2]=p[ls[u]][pl];
			q2[cp2]=f[rs[u]][i];
		}
	}
	reverse(&p1[1],&p1[cp1+1]);
	reverse(&q1[1],&q1[cp1+1]);
	int cc=0;
	for(;cp1||cp2;)
	{
		//printf("> %d %d %lld %lld %lld %lld\n",cp1,cp2,p1[cp1],q1[cp1],p2[cp2],q2[cp2]);
		if(!cp2||cp1&&p1[cp1]<p2[cp2])
		{
			if(!cc||p1[cp1]!=p[u][cc-1])
			{
				if(!cc||q1[cp1]<f[u][cc-1])
				{
					p[u].push_back(p1[cp1]);
					f[u].push_back(q1[cp1]);
					cc++;
				}
			}
			else f[u][cc-1]=gmin(f[u][cc-1],q1[cp1]);
			cp1--;
		}
		else
		{
			if(!cc||p2[cp2]!=p[u][cc-1])
			{
				if(!cc||q2[cp2]<f[u][cc-1])
				{
					p[u].push_back(p2[cp2]);
					f[u].push_back(q2[cp2]);
					cc++;
				}
			}
			else f[u][cc-1]=gmin(f[u][cc-1],q2[cp2]);
			cp2--;
		}
	}
	//for(int i=0;i<p[u].size();i++)printf("%lld %lld\n",p[u][i],f[u][i]);
}
int main()
{
	int n;
	!scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int c;
		!scanf("%d%d",&pa[i+1],&c);
		Ins(pa[i+1],i+1,c);
	}
	init(1);
	long long l,r,mid;
	for(l=0,r=23333333333333333ll;l<r;p[1].size()?r=mid:l=mid+1)
	{
		mid=l+r>>1;
		for(int i=1;i<=n;i++)p[i].clear(),f[i].clear();
		//printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>%lld\n",mid);
		DFS(1,mid);
	}
	printf("%lld",l);
	return 0;
}

Measured memory_bytes: 44272
#include<iostream>
using namespace std;
int main(){
  int K, N;
  unsigned int h[100000]={};
  cin >> N >> K;
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  sort(h, h+N);
  unsigned int ans = 1000000000;  
  for(int i=0; i<=N-K; i++){
    if(h[i+K-1] - h[i] < ans){
      ans = h[i+K-1] - h[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);

		int K = sc.nextInt();

		int ans = -1;
		for (int i=0, v = 7 % K; i < K; i++) {
			if (v == 0) {
				ans = i + 1;
				break;
			}
			v = (v * 10 + 7) % K;
			//System.out.println(v);
		}
		System.out.println(ans);

	}

	private static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}


Measured memory_bytes: 32684
#include <bits/stdc++.h>
using namespace std;
#define mod 924844033
#define maxn 2000000
int n, cnt, G[maxn], a[maxn], b[maxn], lim = 1, len, rev[maxn];
int fac[maxn], inv[maxn], finv[maxn];

int read() {
    int x = 0, k = 1;
    char c; c = getchar();
    while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * k;
}

struct edge {
    int cnp, to[maxn], last[maxn], head[maxn]; 
    edge() { cnp = 2; }
    void add(int u, int v) {
        to[cnp] = v, last[cnp] = head[u], head[u] = cnp ++;
        to[cnp] = u, last[cnp] = head[v], head[v] = cnp ++;
    }
}E1;

int mul(int x, int y) { return 1ll * x * y % mod; }
int Up(int x, int y) { return (x + y) % mod; }
int Down(int x, int y) { x -= y; if(x < 0) x += mod; return x; }
void Pre() {
    fac[0] = 1, finv[0] = inv[0] = inv[1] = 1;
    for(int i = 1; i <= lim; i ++) fac[i] = mul(fac[i - 1], i);
    for(int i = 2; i <= lim; i ++) inv[i] = mul((mod - mod / i), inv[mod % i]);
    for(int i = 1; i <= lim; i ++) finv[i] = mul(finv[i - 1], inv[i]);
}

void init() {
    while(lim <= (n << 1)) lim <<= 1, len ++;
    for(int i = 0; i < lim; i ++) 
        rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << ((len - 1)));
}

int Qpow(int x, int timer) {
	int base = 1;
	for(; timer; timer >>= 1, x = mul(x, x))
		if(timer & 1) base = mul(base, x);
	return base;
}

void NTT(int *A, int opt) {
    int t = opt < 0 ? Qpow(5, mod - 2) : 5;
    for(int i = 0; i < lim; i ++) 
        if(i < rev[i]) swap(A[i], A[rev[i]]);
    
    for(int l = 1; l < lim; l <<= 1) {	
        int g = Qpow(t, (mod - 1) / (l << 1));
        for(int i = 1; i < l; i ++) G[i] = mul(G[i - 1], g); 
        for(int i = 0; i < lim; i += (l << 1))
            for(int j = i; j <= i + l - 1; j ++) {
                int x = A[j], y = mul(G[j - i], A[j + l]);
                A[j] = Up(x, y); A[j + l] = Down(x, y);
            }
    }
}

int dfs(int u, int fa) {
	int ret = 1;
	for(int i = E1.head[u]; i; i = E1.last[i]) {
		int v = E1.to[i]; if(v == fa) continue;
		int t = dfs(v, u);
		a[t] ++, ret += t;
	}
	a[n - ret] ++;
	return ret;
}

int main() {
    n = read(); G[0] = 1;
    for(int i = 1; i < n; i ++) {
        int u = read(), v = read();
        E1.add(u, v);
    }
    dfs(1, 0);
    init(); Pre();
	for(int i = 0; i <= n; i ++) a[i] = mul(a[i], fac[i]); a[0] = 0;
    for(int i = 1; i <= n; i ++) b[lim - i] = finv[i]; b[0] = 1;
     
    NTT(a, 1); NTT(b, 1);
	
    for(int i = 0; i < lim; i ++) a[i] = mul(a[i], b[i]);
    NTT(a, -1);
    int t = Qpow(lim, mod - 2);
    for(int i = 0; i < lim; i ++) a[i] = mul(a[i], t);
    for(int i = 1; i <= n; i ++) {
        int S = mul(fac[n], mul(finv[n - i], finv[i]));
        S = mul(S, n); S = Down(S, mul(a[i], finv[i]));
        printf("%d\n", S);
    }
    return 0;
}

Measured memory_bytes: 46464
#include<iostream>
#include<climits>
#include<numeric>
using namespace std;
typedef long long ll;

int main(){
    int n, x;
    cin >> n >> x;

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

    int b[n];
    for(int i = 0; i < n; i++)    b[i] = a[i];

    ll ret = LLONG_MAX;
    for(int magic = 0; magic < n; magic++){
        ret = min(ret, accumulate(b, b+n, 0ll) + (ll)magic * x);
        for(int i = 0; i < n; i++){
            b[i] = min(b[i], a[(i+n-1-magic)%n]);
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  println(2^floor(Int,log2(pI(readline()))))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 109520
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

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

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s,t;
	cin >> n >> s >> t;
	int maxv = 0;
	reps(i,n){
		string tmp(s,n-i,i);
		string tmp2(t,0,i);
		if(tmp == tmp2) maxv = i;
	}
	cout << n * 2 - maxv << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL<<60;
constexpr auto mod = 1000000007;
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; }

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, ll>>> edge(n);
	FOR(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		edge[--a].push_back({ --b,c });
	}
	vector<ll> ans(n, -LLINF);
	ans[0] = 0;
	FOR(cnt, n) {
		FOR(i,n) {
			for (auto e : edge[i]) {
				if (chmax(ans[e.first], ans[i] + e.second)) {
					if (cnt == n - 1 && e.first == n - 1) {
						cout << "inf" << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << ans[n - 1] << endl;
}


Measured memory_bytes: 384
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative

readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

main = do
  s <- getBSVector
  let ans = map VU.length $ substring s
  print $ if null ans then 0 else maximum ans

substring sVector = do
  let n = VU.length sVector
  i <- [0..n-1]
  j <- [1..n-i]
  let chosen = VU.slice i j sVector

  guard $ VU.foldr ((&&) . (\n -> n == 'A' || n == 'C' || n == 'G' || n == 'T')) True chosen
  return $ VU.slice i j sVector

-- func vec = foldr ((&&) . (\n -> VU.elem n vec)) True (concat [['B','D'..'F'],['H'..'S'],['U'..'Z']])


Measured memory_bytes: 508
n,T=map(int,input().split())
t=list(map(int,input().split()))

ans=0
stop=0
for i in range(n):
    if stop<=t[i]:
        ans+=T
        stop=t[i]+T
    else:
        ans+=T-(stop-t[i])
        stop=t[i]+T
print(ans)

Measured memory_bytes: 85456
#include<stdio.h>

int n, a[50];

//??\?????????M???????????????????´???????????????????????????¢??°
int solve(int i, int m)
{
    if( m == 0 ) return 1;
    if( i >= n ) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - a[i]);
    return res;
}

int main()
{
    int q, M, i;

    scanf("%d", &n);
    for( i = 0; i < n; i++ ) scanf("%d", &a[i]);
    scanf("%d", &q);
    for( i = 0; i < q; i++ ){
        scanf("%d", &M);
        if( solve( 0, M ) ) puts("yes");
        else puts("no");
    }

    return 0;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
#include<stdio.h>
#include <iostream>

using namespace std;

int main()
{
   int a;
   char s[10];
   cin>>a;
   cin>>s;
   if(a<3200)
   cout<<"red";
   else
   cout<<s;
   
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//
int main(){
    int h,w; cin>>h>>w;
    vector<vector<char>> field(1010,vector<char>(1010));
    rep(i,h){
        rep(j,w){
            cin>>field[i][j];
        }
    }

    vector<vector<ll>> dp(1010,vector<ll>(1010,0));
    dp[0][0]=1;
    rep(i,h){
        rep(j,w){
            if(field[i+1][j]!='#') dp[i+1][j]+=dp[i][j]; dp[i+1][j]%=MOD;
            if(field[i][j+1]!='#') dp[i][j+1]+=dp[i][j]; dp[i][j+1]%=MOD;
        }
    }

    cout<<dp[h-1][w-1]%MOD<<endl;
}

Measured memory_bytes: 9344
import java.util.Arrays;
import java.util.Scanner;

class B {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int M = sc.nextInt();
        final int[] a = new int[A];
        final int[] b = new int[B];
        final int[] x = new int[M];
        final int[] y = new int[M];
        final int[] c = new int[M];
        Arrays.setAll(a, i -> sc.nextInt());
        Arrays.setAll(b, i -> sc.nextInt());
        for (int i = 0; i < M; i++) {
            x[i] = sc.nextInt() - 1;
            y[i] = sc.nextInt() - 1;
            c[i] = sc.nextInt();
        }
        int ans = Arrays.stream(a).min().orElse(Integer.MAX_VALUE) + Arrays.stream(b).min().orElse(Integer.MAX_VALUE);
        for (int i = 0; i < M; i++)
            ans = Math.min(ans, a[x[i]] + b[y[i]] - c[i]);
        System.out.println(ans);
    }
}
public class Main {
    public static void main(String... args) {
        B.main();
    }
}


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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  string s[h];
  for (int i = 0; i < h; i++) cin >> s[i];
  pair<int, int> koma(0, 0);
  s[0][0] = '.';
  while (koma.first < h - 1 or koma.second < w - 1) {
    if (koma.first < h - 1 and s[koma.first + 1][koma.second] == '#') {
      koma.first++;
      s[koma.first][koma.second] = '.';
      continue;
    }
    if (koma.second < w - 1 and s[koma.first][koma.second + 1] == '#') {
      koma.second++;
      s[koma.first][koma.second] = '.';
      continue;
    }
    break;
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] != '.') {
        cout << "Impossible" << "\n";
        return 0;
      }
    }
  }
  cout << "Possible" << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

int main()
{
  int N;
  long long d = std::pow(10, 9) + 7;
  std::cin >> N;
  long long ans = 1;
  for ( int i = 1; i <= N; i++ ) {
    ans *= i;
    ans %= d;
  }
  
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
r = []
for i in range(N):
    s, p = input().split(" ")
    r.append((i+1, s, int(p)))


sorted_r = sorted(r, key=lambda x:x[2], reverse=True)
sorted_r = sorted(sorted_r, key=lambda x:x[1])

for i in sorted_r:
    print(i[0])


Measured memory_bytes: 3060
n=gets.to_i
arr=gets.split.map(&:to_i)
puts arr.join(' ')
(1..n-1).each do |i|
  v=arr[i]
  j=i-1
  while(j>=0 && arr[j]>v)
    arr[j+1]=arr[j]
    j-=1
  end
  arr[j+1]=v
  puts arr.join(' ')
end

Measured memory_bytes: 8772
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

A,B,C,D=map(int,input().split())

x=[C,D]

e=C*D//gcd_list(x)

cc=B%C
ccc=A%C
CB=B-cc
if ccc==0:
    key1=((CB-A)//C+1)
else:
    key1=((CB-A)//C+1)
#print(key1)

dd=B%D
ddd=A%D
DB=B-dd
key2=((DB-A)//D+1)
#print(key2)
ee=B%e
eee=A%e
eb=B-ee
key3=((eb-A)//e+1)
#print(key3)
print(B-A+1-(key1+key2-key3))



Measured memory_bytes: 5244
import sys
N, M, P = [int(x) for x in input().split()]
forward = {}
backward = {}
for _ in range(M):
  A, B, C = [int(x) for x in input().split()]
  forward[A] = forward.get(A, {})
  if B in forward[A]:
    forward[A][B] = max(forward[A][B], C-P)
  else:
    forward[A][B] = C-P
  backward[B] = backward.get(B, {})
  if A in backward[B]:
    backward[B][A] = max(backward[B][A], C-P)
  else:
    backward[B][A] = C-P
#print(forward)
#print(backward)
reachable = set([N])
to_track = set([N])
while to_track:
  x = to_track.pop()
  if x not in backward:
    continue
  for y in backward[x]:
    if y not in reachable:
      to_track.add(y)
      reachable.add(y)
#print(reachable)
if 1 not in reachable:
  print(-1)
  sys.exit()

forward = {k: {k2: v2 for k2, v2 in v.items() if k2 in reachable}
           for k, v in forward.items() if k in reachable}
#print(forward)
# backward = {k: {k2: v2 for k2, v2 in v.items() if k2 in reachable}
#            for k, v in backward.items() if k in reachable}
#print(backward)

dist = {k: -float('inf') for k in reachable} 
dist[1] = 0
#print(reachable)
#print(dist)
#print(forward)
for _ in range(len(reachable)):
  renewed = False
  for x, y_dict in forward.items():
    for y in y_dict:
 #     print(x, y, forward[x][y], dist[x], dist[y])
      if dist[y] < dist[x] + forward[x][y]:
        renewed = True
        dist[y] = dist[x] + forward[x][y]
if renewed:
  # print('loop')
  print(-1)
else:
  print(max(0,dist[N]))
  
  


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

int main(){
   ll n,q;
   cin >> n >> q;
   string s;
   cin >> s;
   vector<ll> l(q),r(q),ans(n,0);
   rep(i,q) cin >> l[i] >> r[i];
   rep(i,n-1){
       ans[i+1]=ans[i];
       if(s[i]=='A' && s[i+1]=='C'){
           ans[i+1]++;
       }
   }
   rep(i,q){
       cout << ans[r[i]-1]-ans[l[i]-1] << endl;
   }
}

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

using namespace std;

const int MAXN = 2e5 + 5;

int n ;
string s , t , u;
int a , b ;

int main()
{
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s)a--;
    else b--;
    cout<<a<<" "<<b;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;
ll GCD(ll x, ll y) {if (x % y == 0) return y;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x * y / GCD(x, y);}

int main(){
  ll n,m; cin>>n>>m;
  if(n>=m){
    cout<<0<<endl;
 return 0;
  }
  vector<ll>x(m),l(m-1);
  rep(i,m) cin>>x[i];
  sort(all(x));
  
  rep(i,m-1) l[i]=x[i+1]-x[i];
  sort(all(l));
 ll ans=0;
  for(ll i=m-2;i>=m-n;i--) ans-=l[i];
  cout<<ans+x[m-1]-x[0]<<endl;
 
  return 0;
}

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

#define int long long
#define MAXN 1000005

int n,m,ans;
char s[MAXN];

void rd()
{
	cin >> n;
	scanf("%s",s+1);
}

signed main()
{
	rd();
	for(int i = 1; i <= n; i ++)
	if(i == 1 || s[i] != s[i-1]) ans ++;
	cout<<ans;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define PB push_back;
#define F first;
#define S second;
#define REP(i,a,b) for (int i=a;i<b;i++)
#define all(x) x.begin(), x.end()
#define all_(x) x.rbegin(), x.rend()
#define mp make_pair



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  int answer = n;
  set<string> dict;
  for (int i=0;i<n;i++){
    string input;
    cin>>input;
    if (dict.find(input)!=dict.end()) answer--;
    else dict.insert(input);
  }
  cout<<answer<<'\n';

  return 0;
}


Measured memory_bytes: 19240
function main()
  
  K = parse(Int, readline())
  (A, B) = map(x -> parse(Int, x), split(readline()))
  
  ans = false
  
  for i in A:B
    if i % K == 0
      ans = true
    end
  end
  
  if ans
    println("OK")
  else
    println("NG")
  end
  
end

main()

Measured memory_bytes: 160884
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Console.ReadLine().Split(' ');
            var flag = true;
            var tHP = int.Parse(data[0]);
            var tAP = int.Parse(data[1]);
            var aHP = int.Parse(data[2]);
            var aAP = int.Parse(data[3]);

            while(true)
            {
                aHP -= tAP;
                if (aHP <= 0)
                {
                    break;
                }
                tHP -= aAP;
                if(tHP <= 0)
                {
                    flag = false;
                    break;
                }
            }
            Console.WriteLine(flag ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 27536
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum[3300000], ans, dp[330000];;
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>vec,rvec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	cin >> s >> t;
	ans = n + 1;
	if(n-s+1>=0)
	ans = max(ans, (n - s + 1) / 2 * (t - s) + (n - s+1) % 2 + s);
	cout << ans << endl;
	return 0;
}


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

void solve(){
    int l, r, d;
    cin>>l>>r>>d;
    int ans = 0;
    for(int i=l;i<=r;i++){
        if(i%d==0)ans++;
    }
    cout<<ans<<endl;
    return;
}

signed main()  
{  
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}  


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

using namespace std;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

struct NODE
{
	int c, num;

	NODE (const int &c0 = 0, const int &n0 = 0) : c(c0), num(n0) {}
};

int n;
vector<int> len;
vector<NODE> stk;

bool check(int mid)
{
	stk.clear();
	stk.emplace_back(NODE(1, *len.begin()));
	for(int i=1; i<n; i++)
	{
		if(len[i] > len[i-1]) stk.emplace_back(NODE(1, len[i]-len[i-1]));
		else
		{
			int need = len[i-1]-len[i];
			while(need)
			{
				if(need >= stk.back().num) need -= stk.back().num, stk.pop_back();
				else stk.back().num -= need, need = 0;
			}
			int p = stk.size()-1;
			while(p>=0 && stk[p].c==mid) p--;
			if(p < 0) return false;
			else
			{
				int add = 0;
				while(stk.size() > p+1) add += stk.back().num, stk.pop_back();
				NODE tmp = stk.back();
				stk.pop_back();
				if(tmp.num == 1) stk.emplace_back(NODE(tmp.c+1, 1));
				else stk.emplace_back(NODE(tmp.c, tmp.num-1)), stk.emplace_back(NODE(tmp.c+1, 1));
				if(add) stk.emplace_back(NODE(1, add));
			}
		}
	}
	return true;
}

int main()
{
	read(n);
	for(int i=1; i<=n; i++)
	{
		int x;
		read(x);
		len.emplace_back(x);
	}
	int l = 1, r = n, mid = 1, ans = 1;
	while(l < r)
	{
		mid = (l+r) / 2;
		if(check(mid)) r = ans = mid;
		else l = ans = mid+1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>

int cmp(const char *a, const char *b) { return *a - *b; }
int rcmp(const char *a, const char *b) { return *b - *a; }

int main() {
  char num[9] = {};
  int i, j, n;
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    int j, min, max;
    for (j = 0; j < 8; j++) {
      scanf("%c", num+j);
    }
    scanf("\n");
    num[8] = 0;
    qsort(num, 8, sizeof(char), (int(*)(const void*, const void*))cmp);
    sscanf(num, "%d", &min);
    
    qsort(num, 8, sizeof(char), (int(*)(const void*, const void*))rcmp);
    sscanf(num, "%d", &max);
    
    printf("%d\n", max - min);
  }
  
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}

using namespace std;

int main(){
    int i,loop=0;
    char x;
    string s;
    cin >> s;
    for(i=0;i<(s.length())&&loop==0;i++){
        if(i%2==0){
            if(s[i]=='L') loop++; //odd
        }
        else{
            if(s[i]=='R') loop++;
        }
    }
    cout << (loop==1?"No":"Yes") << endl;
}

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
string s,t,s1;
int main(){
		cin>>s>>t;
		s1+=s;
		s1+=s;
		if(s1.find(t)==s1.npos){
			cout<<"No";
			return 0;
		}
	cout<<"Yes"<<endl;
}

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

using namespace std;

#define fl(x,n) for(x=0;x<n;x++)
#define I(x) cin>>x
#define O(x) cout<<x<<endl
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define St(name) stack<string>name
#define lld long long int
const int INF = 1e9 + 7; 

int main(){
    fast;
    long long int n, w;
    cin>>n>>w;
    long long int arr[n][2];
    for(long long int i = 0; i<n; i++){
    	cin>>arr[i][0]>>arr[i][1];
    }
    long long int dp[n+1][w+1];
    for(long long int i = 0; i<=n; i++){
    	for(long long int j = 0; j<=w; j++){
    		if(i == 0 || j == 0){
    			dp[i][j] = 0;
    		}
    		else if(j>= arr[i-1][0])
    			dp[i][j] = max(dp[i-1][j-arr[i-1][0]] + arr[i-1][1], dp[i-1][j]);
    		else
    			dp[i][j] = dp[i-1][j];
    	}
    }
    cout<<dp[n][w];
    /*for(long long int i = 1; i<=n; i++){
    	for(long long int j = 1; i<=w; i++){
    		cout<<dp[i][j]<<","<<i<<","<<j<<"      ";
    	}
    	cout<<endl;
    }*/
    return 0;
}


Measured memory_bytes: 79232
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		UnionFind uf = new UnionFind(n);
		Map<Integer, Integer> map = new HashMap<>();
		for(int i=0; i<m; i++){
			int a = in.nextInt();
			Integer ai = map.get(a);
			int b = in.nextInt();
			Integer bi = map.get(b);
			map.put(a, ai == null ? 1 : ai + 1);
			map.put(b, bi == null ? 1 : bi + 1);
			uf.unite(a, b);
		}
		for(int i=0; i<k; i++){
			int c = in.nextInt();
			Integer ci = map.get(c);
			int d = in.nextInt();
			Integer di = map.get(d);
			if(uf.same(c, d)) {
				map.put(c, ci == null ? 1 : ci + 1);
				map.put(d, di == null ? 1 : di + 1);
			}
		}

		for(int i=1; i<=n; i++){
			Integer j = map.get(i);
			if (j == null) j = 0;
			System.out.print(uf.size(i) - j -1 +" ");
		}
	}
}

class UnionFind {
	int[] parents;
	int[] size;

	public UnionFind(int n) {
		this.parents = new int[n + 1];
		this.size = new int[n + 1];
		for (int i = 0; i <= n; i++) {
			parents[i] = i;
		}
		Arrays.fill(size, 1);
	}

	public void unite(int x, int y) {
		int rx = find(x);
		int ry = find(y);
		if (rx == ry) {
			return;
		}
		if (size[rx] < size[ry]) {
			size[ry] += size[rx];
			parents[rx] = ry;
		} else {
			size[rx] += size[ry];
			parents[ry] = rx;
		}
	}

	public int find(int x) {
		int root = x;
		while (root != parents[root]) {
			root = parents[root];
		}
		return root;
	}

	public int size(int x) {
		return size[find(x)];
	}

	public boolean same(int x, int y) {
		return find(x) == find(y);
	}
}



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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    string s;
    cin >> s;
    for(int i=1;i<s.size();i++){
        if(s[i-1] == s[i]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);
void prime_map(map<ll, ll> &, ll);

int main() {
    ll mod = pow(10, 9) + 7;
    int n, m;
    cin >> n >> m;
    ll dp[n + 1] = {};
    int a[m];
    rep(i, m) {
        cin >> a[i];
        dp[a[i]] = -1;
    }

    dp[0] = 1;

    repd(i, 1, n + 1) {
        if (dp[i] == -1) {
            continue;
        }
        ll temp = 0;
        if (i - 2 >= 0) {
            if (dp[i - 2] != -1) {
                temp += dp[i - 2];
            }
        }
        if (i - 1 >= 0) {
            if (dp[i - 1] != -1) {
                temp += dp[i - 1];
            }
        }

        temp %= mod;
        dp[i] = temp;
    }

    cout << dp[n] << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


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

int main() {
    long long N; cin >> N;
    long long K = 1;
    bool exist = false;
    for (K = 1; K <= N; K++)
    {
        if(K * (K + 1) / 2 == N){
            exist = true;
            break;
        }
    }

    if(!exist) puts("No");
    else {
        puts("Yes");
        cout << K + 1 << endl;
        vector<vector<long long>> res(K + 1, vector<long long>());
        long long sum = 1;
        for (int k = K; k >= 1; k--)
        {
            for (int i = 0; i < k; i++)
            {
                res[K - k].push_back(sum + i);
                res[K - k + i + 1].push_back(sum + i);
            }
            sum += k;
        }

        for (int i = 0; i < K+1; i++)
        {
            cout << res[i].size();
            for(int j = 0; j < res[i].size(); j++) cout << " " << res[i][j];
            cout << endl;
        }

    }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()

using namespace std;

LL n, ans;

void solve(LL k) {
	if (k <= 1) return;
	LL x = n;
	while (x % k == 0) x /= k;
	if (x % k == 1) ans++;
}

int main() {
	scanf ("%lld", &n);
	for (int i = 1; (LL) i * i <= n; ++i) {
		if (n % i == 0) {
			solve(i);
			if ((LL) i * i != n) solve(n / i);
		}
	}
	LL m = n - 1;
	for (int i = 1; (LL) i * i <= m; ++i) {
		if (m % i == 0) ans += 2;
		if ((LL) i * i == m) ans--;
	}
	printf ("%lld\n", ans - 1);
	
	
    return 0;
}


Measured memory_bytes: 256
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

map<string, int> mpp;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    rep(i, n) {
        string s; cin >> s;
        mpp[s]++;
    }
    int bes = 0;
    for(auto& v:mpp) bes = max(bes, v.se);
    for(auto& v:mpp) {
        if(v.se == bes) cout << v.fi << endl;
    }
}



Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

int main() {
  int N, M, L; cin >> N >> M >> L;
  vector<vector<P>> edge(N);
  rep(i,M) {
    int a, b, c; cin >> a >> b >> c; --a; --b;
    edge[a].push_back(P(c, b));
    edge[b].push_back(P(c, a));
  }

  Graph move(N);
  rep(i,N) {
    priority_queue<P> pq;
    vi fuel(N, -1);
    pq.push(P(L, i));
    fuel[i] = L;

    while (!pq.empty()) {
      auto p = pq.top(); pq.pop();
      int f, v; tie(f, v) = p;
      if (fuel[v] > f) continue;

      for (auto np : edge[v]) {
        int d, nv; tie(d, nv) = np;
        if (f < d) continue;
        if (fuel[nv] >= f-d) continue;
        fuel[nv] = f-d;
        pq.push(P(f-d, nv));
      }
    }

    fuel[i] = -1;
    rep(j,N) {
      if (fuel[j] != -1) move[i].push_back(j);
    }
  }

  Graph query(N, vi(N, -1));
  rep(i,N) {
    queue<int> q;
    q.push(i);
    query[i][i] = 0;

    while (!q.empty()) {
      auto v = q.front(); q.pop();

      for (auto nv : move[v]) {
        if (query[i][nv] != -1) continue;
        query[i][nv] = query[i][v] + 1;
        q.push(nv);
      }
    }
  }

  int Q; cin >> Q;
  rep(i,Q) {
    int s, t; cin >> s >> t; --s; --t;
    if (query[s][t] == -1) cout << -1 << endl;
    else cout << query[s][t] - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 2676
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
const double PI = acos(-1);
typedef long long ll;

int main(void){
    string S;cin>>S;

    if(S=="SUN")cout<<7<<endl;
    else if(S[0]=='S')cout<<1<<endl;
    else if(S[0]=='M')cout<<6<<endl;
    else if(S=="TUE")cout<<5<<endl;
    else if(S[0]=='W')cout<<4<<endl;
    else if(S[0]=='T')cout<<3<<endl;
    else if(S[0]=='F')cout<<2<<endl;
}

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

using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define REP(i, a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i, a) for(ll i=a;i>0;i--)
#define rrep(i, a, b) for(ll i=a-1;i>=b;i--)
#define printall(n, array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
typedef vector<vector<ll>> VVE;
const ll mod = 1e9 + 7; //10^9+7

int main () {
    ll n, m;
    cin >> n >> m;
    priority_queue<Pi, vector<Pi>, greater<Pi> > pq;
    ll a, b;
    REP(i, m){
        cin >> a >> b;
        pq.push(make_pair(b, a));
    }
    ll ans = 0;
    ll prev = -1;
    while(!pq.empty()){
        auto top = pq.top();
        pq.pop();
        ll b = top.first;
        ll a = top.second;
        if(a <= prev)continue;
        prev = b - 1;
        ans++;
    }
    print(ans);
}  

Measured memory_bytes: 2420
import collections, scipy.misc, numpy
n, p = map(int, input().split())
a = numpy.array(list(map(int, input().split())))
a %= 2
c = collections.Counter(a)
ans = 0
for i in range(p, c[1] + 1, 2):
    ans += 2 ** c[0] * scipy.misc.comb(c[1], i, exact=True)
print(ans)

Measured memory_bytes: 14280
#include <stdio.h>
 
int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i, j;
 
  for ( ; ; )
  {
    int h, w;
 
    scanf ( "%d%d", &h, &w );
    if ( h == 0 && w == 0 ) break ;
 
    for ( i = 0; i < h; ++i )
    {
      for ( j = 0; j < w; ++j )
      {
        putchar ( ( i + j ) % 2 ? '.' : '#' );
      }
      puts ( "" );
    }
    puts ( "" );
  }
 
  return ( 0 );
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, M;
  cin >> N >> M;
  vector<int> road(2 * M);
  vector<int> city(N);
  
  for (int i = 0; i < 2 * M; i++) {
    cin >> road.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2 * M ; j++) {
      if (road.at(j) - 1 == i) city.at(i)++;
    }
  cout << city.at(i) << endl;
  }
}

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

using namespace std;

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

int main(){
  int a, b;
  cin >> a >> b;
  cout << (b - 1 + a - 2) / (a - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

char s[200010];
int ans[100000];

int main(){
	LL sum = 1;
	scanf("%s",s + 1);
	int len = strlen(s + 1);
	for(int i = 1;i <= len;i++){
		if(i - 1 - ans[s[i]] > 0){
			sum += (i - 1 - ans[s[i]]);
		}
		ans[s[i]]++;
	}
	printf("%lld",sum);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        
        int keta = 1;
        for (int i=0;;i++) {
            N = N / K;
            if(N == 0) {
                break;
            }
            keta++;
        }
        
        System.out.println(keta);
    }
}


Measured memory_bytes: 21460
#include<iostream>
using namespace std;
int main()
{
    int i,j,k,n;
    cin >>n;
    int l[n];
	long long sum = 0;
    for (i = 0;i<n;i++){
	cin>>l[i];
	sum +=l[i];
    }
    // operation processing
	long long sum0 = 0;
	long long temp =	1000000000000000;
	for(i= 0;i<n-1;i++){
		sum0 +=l[i];
	temp = (std::abs(2*sum0-sum))<temp?(std::abs(2*sum0-sum)):temp;
	}
	cout<<temp<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
public class Main {
static long[][] memo;
static int I,J;
static String h,s;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
	   h=sc.nextLine();
	   s=sc.nextLine();
	   I=h.length();
	   J=s.length();
	   memo=new long[I][J];
	   for(long []a:memo)
		   Arrays.fill(a,-1);
	   dp(0,0);
	   long max=0; int im=0; int jm=0;
	   for(int i=0;i<I;i++) {
		   for(int j=0;j<J;j++)
			   if(memo[i][j]>=max) {
				   max=memo[i][j];
				   im=i;
				   jm=j;
			   }
	   }
	   if(max==0) {
		   System.out.println(" ");
		   return;
	   }
	   trace(0,0);
	}
	static void trace(int i,int j) {
		if(i==I || j==J)
			return;
		if(i==I-1 && j==J-1) {
			if(s.charAt(j)==h.charAt(i))
				System.out.print(s.charAt(j));
			return;
		}
		if(i==I-1) {
			if(s.charAt(j)==h.charAt(i)) {
				System.out.print(s.charAt(j));
			return ;}
			trace(i,j+1); return;
		}
		if(j==J-1) {
			if(s.charAt(j)==h.charAt(i)) {
				System.out.print(s.charAt(j));
			return ;}
			trace(i+1,j); return;
		}
		if(h.charAt(i)==s.charAt(j)) {
			System.out.print(s.charAt(j));
			trace(i+1,j+1);
			return;
		}
		if(dp(i+1,j)>dp(i,j+1))
			trace(i+1,j);
		else
			trace(i,j+1);
	}
	static long dp(int i,int j) {
		if(i==I || j==J)
			return 0;
		if(memo[i][j]!=-1)
			return memo[i][j];
		if(i==I-1 && j==J-1) {
			if(s.charAt(j)==h.charAt(i))
				return memo[i][j]=1;
			return memo[i][j]=0;}
		if(i==I-1) {
			if(s.charAt(j)==h.charAt(i))
				return memo[i][j]=1;
			return memo[i][j]=dp(i,j+1);}
		if(j==J-1) {
			if(s.charAt(j)==h.charAt(i))
				return memo[i][j]=1;
			return memo[i][j]= dp(i+1,j);}
		if(h.charAt(i)==s.charAt(j)) {
			return memo[i][j]=1+dp(i+1,j+1);
		}
		return memo[i][j]=Math.max(dp(i,j+1),dp(i+1,j));
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 134748
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int L;
char s[20];
void Solve() {
    scanf("%s",s + 1);
    L = strlen(s + 1);
    int ans = 15 - L;
    for(int i = 1 ; i <= L ; ++i) {
        if(s[i] == 'o') ++ans;
    }
    if(ans >= 8) puts("YES");
    else puts("NO");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 0])

    return arr
n = int(input())
p = fac(n)
ans = 0
for i in range(len(p)):
    for j in range(1,10001):
        if j*(j-1)/2 <= p[i][1] < j*(j+1)/2:
            ans += j-1
            break
        else:
            continue
print(ans)

Measured memory_bytes: 9492