akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    T=LI()
    A=LI()
    inf=10**9+1
    M1=[inf]*N
    M2=[inf]*N
    m1=[1]*N
    m2=[1]*N
    
    now=1
    for i in range(N):
        t=T[i]
        if t>now:
            m1[i]=t
            M1[i]=t
            now=t
        else:
            M1[i]=now
            
    now=1
    for i in range(N-1,-1,-1):
        t=A[i]
        if t>now:
            m2[i]=t
            M2[i]=t
            now=t
        else:
            M2[i]=now
            
    ans=1
    for i in range(N):
        M=min(M1[i],M2[i])
        m=max(m1[i],m2[i])
        if m>M:
            ans=0
            break
        else:
            ans=(ans*(M-m+1))%mod
            
    print(ans)
        
    
main()


Measured memory_bytes: 96692
N = int(input())
D,X = map(int,input().split())
L = []
for i in range(N):
    a = int(input())
    L.append(a)
ans = N + X
for i in L:
    cnt = 1
    while(True):
        A = cnt * i + 1
        if(A <= D):
            ans += 1
        else :
            break
        cnt += 1
print(ans)

Measured memory_bytes: 38512
#include <iostream>
#include <vector>
                                                                                                                             
int main(){

   const int r = -2; 
   int N;
   std::vector<int> S;
   std::cin >> N;

   if(N==0){
      std::cout << 0 << std::endl;
      return 0;
   }   

   long long n = -1; 
   for(int i=0; abs(N)>0; ++i){
      S.push_back(abs(N)%2);
      if(abs(N)%2==0) N /= 2;
      else if(i%2==0) N = (N-1)/2;
      else N = (N+1)/2;
   }   

   for(int i=S.size()-1; i>=0; --i)
      std::cout << S[i];
   std::cout << std::endl;

   return 0;
}

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

const int maxN = 1e3; int n;
int matchId[maxN][maxN], a[maxN][maxN], t, indegree[maxN*maxN];
vector<int> graph[maxN*maxN];

int main()
{
  memset(matchId, -1, sizeof(matchId));
  scanf("%d", &n);
  for (int u = 0; u < n; u ++)
    for (int i = 0; i < n - 1; i ++)
    {
      int v; scanf("%d", &v); v --;
      a[u][i] = v;
      if (matchId[min(u, v)][max(u, v)] == -1)
        matchId[min(u, v)][max(u, v)] = t ++;
    }

  for (int u = 0; u < n; u ++)
    for (int i = 1; i < n - 1; i ++)
    {
      graph[matchId[min(u, a[u][i - 1])][max(u, a[u][i - 1])]].push_back(matchId[min(u, a[u][i])][max(u, a[u][i])]);
      indegree[matchId[min(u, a[u][i])][max(u, a[u][i])]] ++;
    }

  int ans = 0;
  queue<pair<int, int>> q;
  for (int i = 0; i < t; i ++)
    if (indegree[i] == 0)
      q.push({i, 1});
  int matches = t;
  while (!q.empty())
  {
    int u = q.front().first, d = q.front().second; q.pop();
    ans = max(ans, d); matches --;
    // printf("%d %d | %d\n", u, d, matches);
    for (int v: graph[u])
    {
      // printf("\t%d\n", v);
      if (-- indegree[v] == 0)
        q.push({v, d + 1});
    }
  }
  printf("%d\n", !matches ? ans : -1);

  return(0);
}

Measured memory_bytes: 51072
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    int tmp;
    cin>>tmp;
    if(tmp%2==0){
      if(tmp%3!=0&&tmp%5!=0){
        cout<<"DENIED"<<endl;
        return 0;
      }
    }
  }
  cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()

using namespace std;

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


template<typename T>
void dump(T *arr, int h, int w){
	rep(i,h){
		rep(j,w) cout << arr[i][j] << "\t";
		cout << "\n";
	}
}

template<typename T>
void dump(T *arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

template<typename T>
void dump(vector<T> arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

const int INF = 1e9;
const int MOD = 1e9+7;

bool compare(P a, P b){
	if(a.second != b.second) return a.second > b.second;
	else	return a.first > b.first;
}


int digits(ll num){
	ll d=0;
	while(num >= 1){
		num/= 10;
		d++;
	}
	return d;
}

ll pow_kai(ll a, int n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
    }
    a = a*a;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}


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

	int h, w;
	cin >> h >> w;

	char s[h][w];
	rep(i, h) rep(j, w) cin >> s[i][j];

	int ans=0;
	queue<tuple<int, int, int>> q;
	int hh, ww, d;
	rep(i, h) rep(j, w){
		if(s[i][j] == '#') continue;
		q.push(make_tuple(i, j, 0));
		bool visited[h][w] = {};
		int most_distant = 0;
		while(!q.empty()){
			tie(hh, ww, d) = q.front();
			q.pop();
			if(visited[hh][ww]) continue;
			//auto t = q.front();
			//int hh = get<0>(t), ww=get<1>(t), d=get<2>(t);
			most_distant = max(most_distant, d);
			visited[hh][ww] = true;
			if(hh != 0 && (!visited[hh-1][ww]) && s[hh-1][ww] == '.') q.push(make_tuple(hh-1, ww, d+1));
			if(hh != h-1 && (!visited[hh+1][ww]) && s[hh+1][ww] == '.') q.push(make_tuple(hh+1, ww, d+1));
			if(ww != 0 && (!visited[hh][ww-1]) && s[hh][ww-1] == '.')q.push(make_tuple(hh, ww-1, d+1));
			if(ww != w-1 && (!visited[hh][ww+1]) && s[hh][ww+1] == '.') q.push(make_tuple(hh, ww+1, d+1));
		}
		ans = max(ans, most_distant);
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int d[10010],t=0,n,i,j;
int main(){
	cin>>n;
	while(t<n)d[t]=114514810,t++;d[0]=0;
	for(i=1;i<n;i++){cin>>t;for(j=0;j<=i/2;j++)d[j]=min(d[j],d[i-j]+t),d[i-j]=min(d[i-j],d[j]+t);}
	cout<<d[n/2]<<endl;
	return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  long long int ans=0;
  cin >> n;
  if(n<=2){
  	cout << 0;
    return 0;
  }
  
  string s;
  cin >> s;
  long long int r=0,g=0,b=0;
  for(int i=0;i<n;i++){
    if(s[i]=='R') r++;
    else if(s[i]=='G') g++;
    else b++;
  }
  ans = r*g*b;
  //cout << ans;
  for(int i=0;i<n;i++){
    for(int j=i+1,k=1;j<n;j++,k++){
      if(s[i] == s[j]) continue;
      if(j-i+j < n && s[i]!=s[j-i+j] && s[j]!=s[j-i+j]){
        ans--;
      }
    }
  }
  cout<<ans;
  return 0;
}

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

#define MAXN 100005
#define P 1000000007
#define IEF(i, s, t)    for(int i=s; i<t; i++)
#define NEF(i, s, t)    for(int i=s; i>=t; i--)
#define ll long long int

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << n / 3;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		String s=sc.next();
		if(s.contains("9"))
			pw.println("Yes");
		else
			pw.println("No");
		
		pw.flush();
		pw.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}

Measured memory_bytes: 21332
import kotlin.math.max

fun main(){
    val (n, m, q) = readLine()!!.split(" ").map{ it.toInt() }
    val list = mutableListOf<Data>()
    for(i in 0 until q){
        val tmp = readLine()!!.split(" ").map{ it.toInt() }

        list.add(Data(tmp[0] - 1, tmp[1] - 1, tmp[2], tmp[3]))
    }

    val seq = mutableListOf<Int>()
    println(search(seq, list, m, n))
}

fun search(seq: List<Int>, data: List<Data>, maxNumber: Int, maxLength: Int): Int {
    if(seq.size == maxLength){
        var ans = 0
        data.forEach { if(seq[it.b] - seq[it.a] == it.c) ans += it.d }
        return ans
    }else{
        var ans = 0
        val k = if(seq.isEmpty()) 1 else seq.last()
        for(i in k until maxNumber + 1){
            ans = max(ans, search(seq.toMutableList().apply { add(i) }, data, maxNumber, maxLength))
        }
        return ans
    }
}

data class Data(
    val a: Int,
    val b: Int,
    val c: Int,
    val d: Int
)

Measured memory_bytes: 57188
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int K = sc.nextInt();

		char t = S.charAt(K - 1);
		StringBuilder sb = new StringBuilder();
		for (char c : S.toCharArray()) {
			if (c != t) {
				sb.append('*');
			} else {
				sb.append(c);
			}
		}

		System.out.println(sb.toString());
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Pair {
		private int A;
		private int B;

		public Pair(int a, int b) {
			super();
			A = a;
			B = b;
		}

		public int getA() {
			return A;
		}

		public int getB() {
			return B;
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main()
{
	ll n,a=0,w=0,t=0,r=0;
	cin>>n;
	string s;
	for(ll i=0;i<n;i++)
    {
		cin>>s;
		a+=s=="AC";
		w+=s=="WA";
		t+=s=="TLE";
		r+=s=="RE";
    }
	cout<<"AC x "<<a<<"\n";
	cout<<"WA x "<<w<<"\n";
	cout<<"TLE x "<<t<<"\n";
	cout<<"RE x "<<r<<"\n";
 	return 0;
}

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

using namespace std;


int isp(int x) {
    for (int i = 2; i * i < x; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    while(!isp(n))n++;
    cout << n << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
from collections import deque, defaultdict
import bisect
from math import factorial

def main():
    N, M = map(int, input().split())
    sc_list = []
    for _ in range(M):
        s, c = map(int, input().split())
        sc_list.append((s, c))

    for i in range(1000):
        st = str(i)
        st = " " * (N - len(st)) + st
        if all([st[s-1] == str(c) for s, c in sc_list]):
            if len(st.strip()) == N:
                print(int(i))
                return
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39888
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////

ll f(const vi &P, const vi &C, int K, int i)
{
    ll sum = 0, max_sum = LLONG_MIN;
    int k = 0, j = i;
    
    do
    {
        k++;
        j = P[j];

        sum += C[j];
        max_sum = max(max_sum, sum);
    }
    while (k < K && i != j);

    if (k == K || sum < 0) return max_sum;
    
    //io << sum << " " << k << BR; 
    sum *= (K - 1) / k;
    K = (K - 1) % k + 1;

    for (int i = 0; i < K; i++)
    {
        j = P[j];
        sum += C[j];
        max_sum = max(max_sum, sum);        
    }

    return max_sum;
}

int main()
{
    int N, K;
    io >> N >> K;

    vi P(N), C(N);
    for (int i = 0; i < N; i++)
    {
        int p;
        io >> p;
        P[i] = p - 1;
    }
    for (int i = 0; i < N; i++)
    {
        io >> C[i];
    }

    ll ans = LLONG_MIN;
    for (int i = 0; i < N; i++)
    {
        ans = max(ans, f(P, C, K, i));
    }
    
    io << ans << BR;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

bool DEBUG=0;
const int MAXN = 100005;

int n,Q;
map<ll,ll> cnt;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n;ll sum=0;
	forn(i,0,n){
		int x; cin>>x;
		cnt[x]++;
		sum+=x;
	}
	cin>>Q;
	forn(z,0,Q){
		ll b,c; cin>>b>>c;
		if(cnt.find(b)==cnt.end()){
			cout<<sum<<'\n'; 
			continue;
		}	
		sum-=cnt[b]*(b-c);
		cnt[c]+=cnt[b];
		cnt.erase(b);
		cout<<sum<<'\n';
	}
	
	return 0;
}


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

int main(void) {
	string w;
	cin >> w;
	int c[26] = {0};
	for (int i = 0; i < w.length(); i++) {
		c[w[i] - 'a']++;
	}
	string ans = "Yes";
	for (int i = 0; i < 26; i++) {
		if (c[i] % 2 != 0) ans = "No";
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3592
#include <cstdio>

using namespace std;

int n, m;
int a[111];

int main(void) {
  scanf("%d%d", &n, &m);
  int s = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", a+i);
    s += a[i];
  }
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] * 4 * m >= s) {
      c += 1;
    }
  }
  puts(c >= m ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 128
#len(s)//2-s.count("p")
iG = 0
iR = 0
for g in [int(_) for _ in list(input().rstrip().replace("g","1").replace("p","0"))]:
    if g :
        if 0 < iG:
            iR += 1
            iG -= 1
        else:
            iG += 1
    else:
        if 0 < iG:
            iG -= 1
        else:
            iR -= 1
            iG += 1
print(iR)


Measured memory_bytes: 4652
#include <stdio.h>
int main(void){
    int s,cnt=1;
    scanf("%d",&s);
    while(s!=1 && s!=2 && s!=4){
        if(s%2==0) s/=2;
        else s=s*3+1;
        cnt++;
    }
    printf("%d",cnt+3);
}

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

bool check(int a, int b, int c) {
  if (a == b || b == c || a == c) return false;
  return ((a + b > c) && (b + c > a) && (a + c > b));
}

int main(void) {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];
  int cnt = 0;
  for (int i = 0; i + 2 < N; i++) {
    for (int j = i + 1; j + 1 < N; j++) {
      for (int k = j + 1; k < N; k++) {
        if (check(L[i], L[j], L[k])) cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3596
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e3 + 5, M = 1e5 + 5;


int main(){
    int a;
    cin >> a;
    string s;
    cin >> s;
    if(a >= 3200)cout << s << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	long long a, l;
	while (cin >> a >> l&&a != 0 || l != 0) {
		long long b[100];
		b[0] = a;
		int i = 1;
		while (true) {
			long long c, d;
			vector<int>e;
			string f = to_string(a);
			for (int j = 0; j < f.size(); j++) 
				e.push_back((int)f[j] - '0');
			for (int j = e.size(); j < l; j++) 
				e.push_back(0);
			sort(e.begin(), e.end());
			f = "";
			for (int j = 0; j < e.size(); j++)
				f += (char)e[j] + '0';
			c = stoll(f);
			reverse(e.begin(), e.end());
			f = "";
			for (int j = 0; j < e.size(); j++)
				f += (char)e[j] + '0';
			d = stoll(f);
			b[i] = d - c;
			a = d - c;
			for (int j = 0; j < i; j++) {
				if (b[j] == b[i]) {
					cout << j << " " << b[j] << " " << i - j << endl;
					goto stop;
				}
			}
			i++;
		}
	stop:;
	}
}

Measured memory_bytes: 3252
#include<iostream>
#define DIM 200005
using namespace std;
int n, k, i, ok, sol, p, u, nr;
int v[DIM], d[DIM], vf[DIM];
int main(){
    cin>> n >> k;
    for(i = 1; i <= n; i++){
        cin>> v[i];
    }
    for(i = 2; i <= k; i++){
        if(v[i] < v[i - 1]){
            ok = 1;
        }
    }
    sol = ok;
    p = 1;
    for(i = 1; i <= k; i++){
        while(p <= u && v[ d[u] ] < v[i]){
            u--;
        }
        d[++u] = i;
    }
    for(i = k + 1; i <= n; i++){
        while(p <= u && v[ d[u] ] < v[i]){
            u--;
        }
        d[++u] = i;
        if(d[p] == i - k){
            p++;
        }
        if(d[p] != i){
            vf[i] = 1;
        }
    }
    p = 1;
    u = 0;
    for(i = 1; i <= k; i++){
        while(p <= u && v[ d[u] ] > v[i]){
            u--;
        }
        d[++u] = i;
    }
    for(i = k + 1; i <= n; i++){
        while(p <= u && v[ d[u] ] > v[i]){
            u--;
        }
        d[++u] = i;
        if(d[p] == i - k){
            p++;
        }
        else{
            vf[i] = 1;
        }
    }
    nr = 1;
    ok = 0;
    for(i = 2; i <= n; i++){
        if(v[i] > v[i - 1]){
            nr++;
        }
        else{
            nr = 1;
        }
        if(nr >= k){
            ok = 1;
            vf[i] = 0;
        }
    }
    sol += ok;
    for(i = k + 1; i <= n; i++){
        sol += vf[i];
    }
    cout<< sol;
}


Measured memory_bytes: 2560
n,m = map(int,input().split())
s = []
for i in range(n):
  s.append(list(map(int,input().split())))
s.sort()
total,count = 0,0
for j in range(n):
  for k in range(s[j][1]):
    total += s[j][0]
    count += 1
    if count == m:
      break
  if count == m:
    break

print(total)    

Measured memory_bytes: 27760
def check_even(i):
  counter = 0
  while i % 2 == 0:
    i /= 2
    counter += 1
  return counter

if __name__ == '__main__':
  N = int(input())
  A = map(int, input().split())

  ans = min(map(check_even, A))
  print(ans)

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

template <typename T>
struct UnionFind
{
    vector<T> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool connected(T x, T y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return true;
        else
            return false;
    }

    bool unite(T x, T y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(T k)
    {
        if (data[k] < 0)
            return k;
        return (data[k] = find(data[k]));
    }

    T size(T k)
    {
        return (-data[find(k)]);
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    vector<ll> res(m + 1);
    res[m] = n * (n - 1) / 2;
    UnionFind<ll> uf(n);
    for (int i = m - 1; i >= 0; i--)
    {
        if (uf.connected(a[i], b[i]))
            res[i] = res[i + 1];
        else
        {
            res[i] = res[i + 1] - uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
    }
    for (int i = 1; i <= m; i++)
    {
        cout << res[i] << endl;
    }
}


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

using namespace std;
using ll = long long;

ll a, b;
//bool judge[1000000000005];
ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}
int main(){
  cin >> a >> b;
  //cout << ans(a, b) << endl;
  ll c = gcd(a, b);
  ll ans=1;
  for(ll i=2;i*i<=c;i++){
    if(c%i==0){
      ans++;
      while(c%i==0){c/=i;}
    }
  }
  if(c!=1){ans++;}
  cout<<ans<<endl;
}

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

#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int l;
    cin >> l;
    double x = (double) l / 3;
    double xx = pow(x, 3);
    cout << setprecision(20) << xx;

    return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans;
    if(s == "SUN"){
        ans = 7;
    }else if(s == "MON"){
        ans = 6;
    }else if(s == "TUE"){
        ans = 5;
    }else if(s == "WED"){
        ans = 4;
    }else if(s == "THU"){
        ans = 3;
    }else if(s == "FRI"){
        ans = 2;
    }else{
        ans = 1;
    }

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


Measured memory_bytes: 256
// 2011/11/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int W[10];
	for(int i=0; i<10; i++)
		cin >> W[i];

	int K[10];
	for(int i=0; i<10; i++)
		cin >> K[i];

	for(int i=0; i<9; i++)
		for(int j=i+1; j<10; j++)
			if(W[i]<W[j]){
				int tmp = W[i];
				W[i] = W[j];
				W[j] = tmp;
			}

	for(int i=0; i<9; i++)
		for(int j=i+1; j<10; j++)
			if(K[i]<K[j]){
				int tmp = K[i];
				K[i] = K[j];
				K[j] = tmp;
			}

	cout << W[0]+W[1]+W[2] << ' ' << K[0]+K[1]+K[2] << endl;

	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n+1); a.front()=0;
	for(int i=1;i<=n;++i)cin>>a[i];
	a.emplace_back(0);
	int sum=0;
	for(int i=1;i<n+2;++i)sum+=abs(a[i]-a[i-1]);
	for(int i=1;i<n+1;++i){
		int ans=sum;
		if(!(a[i-1]<=a[i]&&a[i]<=a[i+1])&&!(a[i+1]<=a[i]&&a[i]<=a[i-1])){
			ans-=min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i]))*2;
		}
		cout<<ans<<"\n"s;
	}
}


Measured memory_bytes: 3960
fun main(args: Array<String>) {
    val (n, cNum) = readLine()!!.split(" ").map(String::toInt)
    val table = Array(100000, { Array(cNum, {0}) })
    for (i in 0 until n) {
        val (s, t, c) = readLine()!!.split(" ").map(String::toInt)
        for (k in s -1 until t) {
            table[k][c - 1] = 1
        }
    }
    val ans = table.map { it.sum() }.max()
    println(ans)
}

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

using namespace std;

const long long P = (long long) 1e10 + 19;

long long count_lattice_points(long long p, long long z) {
  long long q = P - p;
  long long ans = 0;
  if (p < q) {
    for (int y = 0; y * q <= z; ++y) {
      ans += (z - y * q) / p + 1;
    }
  } else {
    for (int x = 0; x * p <= z; ++x) {
      ans += (z - x * p) / q + 1;
    }
  }
  return ans;
}

pair<long long, long long> sum_lattice_points(long long p, long long z, int remain) {
  long long q = P - p;
  long long sum_x = 0;
  long long sum_y = 0;
  if (p < q) {
    for (int y = 0; y * q <= z; ++y) {
      long long max_x = (z - y * q) / p;
      sum_x += max_x * (max_x + 1) / 2;
      sum_y += y * (max_x + 1);
      if (remain && (z + 1 - y * q) % p == 0) {
        --remain;
        sum_x += (z + 1 - y * q) / p;
        sum_y += y;
      }
    }
  } else {
    for (int x = 0; x * p <= z; ++x) {
      long long max_y = (z - x * p) / q;
      sum_x += x * (max_y + 1);
      sum_y += max_y * (max_y + 1) / 2;
      if (remain && (z + 1 - x * p) % q == 0) {
        --remain;
        sum_x += x;
        sum_y += (z + 1 - x * p) / q;
      }
    }
  }
  return make_pair(sum_x, sum_y);
}

long long binary_search_z(long long p, int k) {
  long long l = 0, r = P * 2000;
  while (l < r) {
    long long z = (l + r + 1) >> 1;
    if (count_lattice_points(p, z) <= k) {
      l = z;
    } else {
      r = z - 1;
    }
  }
  return l;
}

bool check(int x, int y, int k) {
  long long l = 0, r = P;
  while (r - l > 1) {
    long long p = (l + r) >> 1;
    long long z = binary_search_z(p, k);
    pair<long long, long long> s = sum_lattice_points(p, z, k - count_lattice_points(p, z));
    if (s.first <= x) {
      if (s.second <= y) {
        return true;
      } else {
        r = p;
      }
    } else {
      if (s.second <= y) {
        l = p;
      } else {
        return false;
      }
    }
  }
  long long zl = binary_search_z(l, k);
  long long zr = binary_search_z(r, k);
  pair<long long, long long> sl = sum_lattice_points(l, zl, k - count_lattice_points(l, zl));
  pair<long long, long long> sr = sum_lattice_points(r, zr, k - count_lattice_points(r, zr));
  return (sr.first - sl.first) * (y - sl.second) <= (sr.second - sl.second) * (x - sl.first);
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int x, y;
  cin >> x >> y;
  int l = 1, r = (int) 4e6;
  while (l < r) {
    int k = (l + r + 1) >> 1;
    if (check(x, y, k)) {
      l = k;
    } else {
      r = k - 1;
    }
  }
  cout << l - 1 << "\n";
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

long n, q;
long S[100001], T[50001];
long c;
    
int bs(long k)
{
    long l=0, u=n;
    while ((u-l) > 1)
    {
        long x = (l+u)/2;
        if (S[x] >= k)
        {
            u = x;
        }
        else l = x;
        //printf("k:%ld u:%ld l:%ld\n", k, u, l);
    }
    if (S[l] == k || S[u] == k) return 1;
    else return 0;

}

int main()
{
    scanf("%ld", &n);
    for (long i=0; i<n; i++)
    {
        scanf("%ld", S+i);
    }
    
    scanf("%ld", &q);
    for (long i=0; i<q; i++)
    {
        scanf("%ld", T+i);
    }

    for (long i=0; i<q; i++)
    {
        c += bs(T[i]);
        //printf("c:%d\n", c);
    }
    printf("%ld\n", c);
    return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int M,D;
  cin >> M >> D;
  
  int ans=0;
  rep2(i,1,D+1) {
    int a=i/10,b=i%10;
    if(a>=2&&b>=2&&a*b<=M) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var dist1 = Math.Abs(str[1] - str[0]);
            var dist2 = Math.Abs(str[2] - str[1]);
            var dist3 = Math.Abs(str[2] - str[0]);

            if(dist1 <= str[3] && dist2 <= str[3] || dist3 <= str[3] )
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

const int N=3005,zqm=1e9+7;
int f[N],pre[N],suf[N];
char str[N];

int main() {
	//freopen("1.in","r",stdin);
	//freopen("1.ans","w",stdout);
	
	int n; scanf("%d",&n);
	scanf("%s",str+2);
	suf[1]=1; fill(pre+1,pre+n+1,1);
	for(int i=2;i<=n;++i) {
		if(str[i]=='<')
			for(int j=1;j<=i;++j) (f[j]+=pre[j-1])%=zqm;
		else
			for(int j=1;j<=i;++j) (f[j]+=suf[j])%=zqm;
		for(int j=1;j<=n;++j) pre[j]=(pre[j-1]+f[j])%zqm;
		for(int j=n;j>=1;--j) suf[j]=(suf[j+1]+f[j])%zqm;
		memset(f,0,sizeof(int)*(n+5));
	}
	printf("%d\n",pre[n]);
	
	return 0;
}


Measured memory_bytes: 256
module Main where
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS
import Data.Maybe(fromJust)

main = do
  s <- getLine
  k <- read<$> getLine :: IO Int
  putStrLn $ solve s k

solve :: String -> Int -> String
solve s k = map (toEnum . (+a)) . rotate k . map (subtract a . fromEnum) $ s
  where
    a = fromEnum 'a'
    z = fromEnum 'z'
    rotate n [x] = [(x + n) `mod` 26]
    rotate n (x:xs)
      | x == 0     = x:rotate n xs
      | 26 - x <= n = 0:rotate (n - (26 - x)) xs
      | otherwise  = x:rotate n xs


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

using namespace std;

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int arr[] = {a, b, c};
    sort(arr, arr+3);
    printf("%d %d %d\n", arr[0], arr[1], arr[2]);
    return 0;
}



Measured memory_bytes: 2804
/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
template<typename T> using v = vector<T>;
#define int long long
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0  //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt"  : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
void read() {}     template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg)     ;read(args...) ;}
void print(){}     template<typename Arg,typename... Args> void print(Arg  arg,Args...  args){put (arg)<<" ";print(args...);}
void debug(){eol;} template<typename Arg,typename... Args> void debug(Arg  arg,Args...  args){put (arg)<<" ";debug(args...);}
int getInt(){int a; get a; return a;}
//code goes here

void run() {
    int n;
    get n;
    int a[n];
    rep(i, 0, n)
        get a[i];
    int d = 1e5;
    int ans = 0;
    rep(i, 1, n) {
        if (a[i] == a[i - 1]) {
            a[i] = d++;
            ans++;
        }
    }
    put ans;
}

int32_t main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); put fixed; put setprecision(15); run(); return 0;}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
using namespace std;

int main() {
    int n, m;
    scan2Int(n, m);
    printInt(n*(n-1)/2 + m*(m-1)/2);
    return 0;
}


Measured memory_bytes: 3816
map = new Int32Array(26);
charA = 65, charZ = 90, chara = 97, charz = 122;

//str = require('fs').readFileSync('tmp', 'ascii'); // win
str = require('fs').readFileSync('/dev/stdin', 'ascii'); // linux

for (i in str) {
	c = str[i].charCodeAt();
	idx = (c <= charZ) ? (c - charA) : (c - chara);
	if (idx >= 0 && idx < 26) map[idx]++;
}

for (i = 0; i < 26; i++) {
	console.log("%s : %d", String.fromCharCode(chara + i), map[i]);
}

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

int main(){
  int64_t A,B,N;
  cin>>A>>B>>N;
  int64_t m=0;
  if(N<B-1){
    m=N;
  }
  else{
    m=B-1;
  }
  cout<<(A*m)/B-(m/B)*A;
}


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

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////


#define LL long long
const int MAXN = 212345;
const int INF  = 0x3f3f3f3f;




int main () {

	ios_base::sync_with_stdio(false);  cin.tie(NULL); 

	int a, b;
	cin >> a >> b;

	if (a > 8 || b > 8)
		cout << ":(" << '\n';
	else cout << "Yay!" << '\n';
 


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}

int main()
{
  int d[1000001] = {};
  int n,q; cin >> n >> q;
  priority_queue<Pii> pq;
  REP(i,q)
  {
    int a,v; cin >> a >> v;
    d[a] += v;
    pq.push(Pii(d[a],-a));
    while(!pq.empty())
    {
      Pii p = pq.top();
      if(p.first == d[-p.second])
      {
        cout << -p.second << " " << p.first << endl;
        break;
      }
      pq.pop();
    }
  }
  return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#include <unordered_set>

#define _USE_MATH_DEFINES
#include <math.h>


#include <vector>
#include <list>

#include <set>
#include <map>

#include <unordered_map>

#include <queue>

#include <string>

#include <vector>

#define sqr(x) (x) * (x)

#include <algorithm>
#include <functional>

#include <bitset>

#include <functional>

#include <chrono>

typedef unsigned int u32;
typedef int i32;

typedef unsigned long long int u64;
typedef long long int i64;

typedef uint16_t u16;
typedef int16_t i16;

typedef uint8_t u8;
typedef int8_t i8;


using namespace std;
using namespace std::chrono;

struct less_key
{
    bool operator() (pair<i64, i64> p1, pair<i64, i64> p2)
    {
        return p1.first < p2.first || (p1.first == p2.first && p1.second < p2.second);
    }
};

struct pair_hash {
public:
    std::size_t operator()(const std::pair<u64, u64> &x) const
    {
        return std::hash<u64>()(x.first) ^ std::hash<u64>()(x.second);
    }
};
#include <random>

const i64 mod = 1000000007ll;
const i64 smod = 999983;
const i64 inf = mod;

const double eps = 1e-10;

// del

string s;

string gen(i64 k) {
    stringstream ss;
    for (i64 i = 0; i < s.size(); i++) {
        ss << k;
        k = (k + 1) % 2;
    }

    return ss.str();
}

i64 diff(string s, string t) {
    i64 R = 0;
    for (i64 i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            R += 1;
        }
    }

    return R;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> s;

    string v1 = gen(0);
    string v2 = gen(1);

    cout << min(diff(s, v1), diff(s, v2)) << endl;

    return 0;
}


Measured memory_bytes: 968
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<queue>
#include<vector>
#include<iomanip>
#include<memory.h>
using namespace std;
struct node{
	int pos,ind;
	friend bool operator < (node a,node b)
	{
		return a.ind>b.ind;
	}
};
priority_queue<node> q;
int n,m;
vector<int> edge[10010];
bool visited[10010];
int indgree[10010];
vector<int> ans;
void init()
{
	for(int i=0;i<n;i++) visited[i]=false;
	for(int i=0;i<n;i++)
	q.push({i,indgree[i]});
	ans.clear();
}
void topological_sort()
{
	init();
	while(!q.empty())
	{
		int x=q.top().pos,y=q.top().ind;
		if(visited[x])
		{
			q.pop();
			continue;
		}
		visited[x]=true;q.pop();ans.push_back(x);
		for(int i=0;i<edge[x].size();i++)
		{
			indgree[edge[x][i]]--;
			if(!visited[edge[x][i]]) q.push({edge[x][i],indgree[edge[x][i]]});
		}
	}
}
int main()
{
	cin>>n>>m;
	memset(indgree,0,sizeof(indgree));
	int x,y; 
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		edge[x].push_back(y);
		indgree[y]++;
	}
	topological_sort();
	for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";cout<<endl;
	return 0;
}


Measured memory_bytes: 4232
#include<iostream>
#include<math.h>

int main()
{
  int S;
  std::cin >> S;
  int h=0,m=0,s=0;

  h = S/(60*60);
  m = (S-h*60*60)/60;
  s = (S-(h*60*60))%60;

  std::cout << h << ':' << m << ':' << s << std::endl;
  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// 約数の列挙O(sqrt(n))
vll divisor(ll n){
    vll res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i * i != n) res.push_back(n / i);
        }
    }
    sort(ALL(res));
    return res;
}

// 素因数分解O(sqrt(n))
map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}



int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a, b;
    cin >> a >> b;
    vll di = divisor(GCD(a, b));
    map<ll, ll> pf = prime_factor(GCD(a, b));
    cout << SZ(pf)+1 << endl;
    return 0;
}

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

using namespace std;

// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);

bool tryCut(vector<int>& vec, long long maxHeight, long long maxCuts)
{
    long long cuts = 0;
    for(auto tree : vec)
        cuts += (tree-1)/maxHeight;
    return cuts <= maxCuts;
}

void solve()
{
    int n, k;
    cin >> n >> k;

    vector<int> v(n);
    int highest = -1;
    for(auto& tree : v)
    {
        cin >> tree;
        if (tree > highest)
            highest = tree;
    }
    // cout << "highest " << highest << '\n';

    int startHeight = 1;
    int endHeight = highest;
    bool start = tryCut(v, startHeight, k);
    bool end = false;

    if (start)
    {
        cout << 1 << "\n";
        return;
    }

    while(endHeight - startHeight > 1)
    {
        int middleHeight = (endHeight + startHeight) / 2;
        // cout << "Trying " << middleHeight << "...\n";
        bool middle = tryCut(v, middleHeight, k);
        if (middle)
            endHeight = middleHeight;
        else
            startHeight = middleHeight;
        // cout << "final start(" << startHeight << ") - end(" << endHeight << ")\n";
    }
    cout << endHeight << '\n';
}

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

    int nCases = 1;
    // cin >> nCases;

    while(nCases--)
        solve();

    return 0;
}


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

using namespace std;

const int N = 1e5 + 5;
const long long mod = 2e9 + 89;
const long long inf = 1e18;

/****** Tarjan’s SCC *******/
vector< int > num, low, S, vis, comp, adj[N];
int cntr, numCC;

void tarjanSCC(int v, int bef = -1) {
	low[v] = num[v] = ++cntr;
	vis[v] = 1;
	S.push_back(v);
	for(auto u : adj[v]) {
		if (u == bef) continue;
		if(num[u] == -1)
			tarjanSCC(u, v);
		if(vis[u])
			low[v] = min(low[v], low[u]);
	}
	if(low[v] == num[v]) {
		numCC++;
		while(1) {
			int u = S.back(); S.pop_back(); vis[u] = 0;
			comp[u] = numCC;
			if(u == v)
				break;
		}
	}
}

void dijkstra(int start, long long* d, vector<tuple<int, int, int>> edge[N]) {
	fill(d, d + N, inf);
	d[start] = 0;
	priority_queue<pair<long long, int>> pq;
	pq.emplace(-d[start], start);
	while (!pq.empty()) {
		long long cost;
		int now;
		tie(cost, now) = pq.top();
		pq.pop();
		cost = -cost;
		if (d[now] != cost) continue;
		for (auto it : edge[now]) {
			long long add; int near;
			tie(near, add, ignore) = it;
			long long ncos = cost + add;
			if (ncos < d[near]) {
				d[near] = ncos;
				pq.emplace(-d[near], near);
			}
		}
	}
}

long long d[N], drev[N];
int u[N], v[N], w[N];
vector<tuple<int, int, int>> edge[N];           // node - cost - id
vector<tuple<int, int, int>> rev[N];            // node - cost - id
bool good[N], done[N];

void dfs(int now) {
	if (done[now]) return;
	done[now] = 1;
	for (auto it : rev[now]) {
		int to, cost, id;
		tie(to, cost, id) = it;
		if (d[to] + cost == d[now]) {
			good[id] = 1;
			dfs(to);
		}
	}
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d", u + i, v + i, w + i);
		edge[u[i]].emplace_back(v[i], w[i], i);
		rev[v[i]].emplace_back(u[i], w[i], i);
	}
	dijkstra(1, d, edge);
	dijkstra(2, drev, rev);

	dfs(2);
	for (int i = 0; i < m; i++) {
		if (good[i]) {
			adj[u[i]].push_back(v[i]);
			adj[v[i]].push_back(u[i]);
		}
	}
	num.assign(n + 1, -1);
	low.assign(n + 1, 0);
	vis.assign(n + 1, 0);
	comp.assign(n + 1, -1);
	cntr = numCC = 0;
	for(int i = 1; i <= n; i++)
		if(num[i] == -1)
			tarjanSCC(i);

	/*
		 puts("d");
		 for (int i = 1; i <= n; i++) printf("%lld ", d[i]); printf("\n");
		 puts("good");
		 for (int i = 0; i < m; i++) printf("%d ", good[i]); printf("\n");
		 puts("comp");
		 for (int i = 1; i <= n; i++) printf("%d ", comp[i]); printf("\n");
		 */

	for (int i = 0; i < m; i++) {
		if (d[v[i]] + drev[u[i]] + w[i] < d[2]) {
			puts("HAPPY");
		} else if (good[i] && comp[u[i]] != comp[v[i]]) {
			puts("SAD");
		} else {
			puts("SOSO");
		}
	}


	return 0;
}



Measured memory_bytes: 30496