akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long n = sc.nextLong();
        long min = Long.MAX_VALUE;
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                long x = i;
                long y = n / x;
                min = Math.min(min, x - 1 + y - 1);
            }
        }
        System.out.println(min);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 23252
package main

import "fmt"

func main() {
	var S string
	// odd w/ 'L'
	// even w/ 'R'
	fmt.Scanf("%s", &S)
	for i := 0; i < len(S); i++ {
		if i%2 == 1 {
			if S[i] == 'R' {
				fmt.Println("No")
				return
			}
		} else {
			if S[i] == 'L' {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#N,Kを取得する。
n,k = map(int,input().split())

#確率を保存する配列を用意
v = 0.0

for i in range(1,n+1):  #出目が1～Nまであるので、そのすべてについて調べる。
    #ちょっとiの値を保存する
    t = i
    #何回表を出し続ければいいか？をカウントする変数を用意
    x = 0
    while(t < k):   #得点がK以上になるまで
        t *= 2  #表を出したことにして得点を2倍にする
        x += 1
    
    #一回目にiを出す確率は1/N
    #それからx回表を出し続ける確率は(1/2)^x=0.5^x
    #あとはその積を加算していく。 
    v += 1.0 / n * 0.5**x
print(v)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int ms = 3e3+9;
int dp[ms][ms], n;
string a, b;

int solve(int i, int j){
  if(i >= a.size() or j >= b.size()) return 0;

  int &ans = dp[i][j];
  if(~ans) return ans;

  int are_char_equal  = (a[i] == b[j]);

  ans = are_char_equal + solve(i+1, j+1);

  ans = max(ans,  max(solve(i+1, j), solve(i, j+1)));

  return ans;
}


void recovery_string(int i, int j){
  if(i >= a.size() or j >= b.size()) return ;

  int &ans = dp[i][j];

  int are_char_equal  = (a[i] == b[j]);


  if(are_char_equal and ans == are_char_equal + solve(i+1, j+1) ){
    cout<<a[i];
    recovery_string(i+1, j+1);
  } else if(ans == solve(i+1, j)) {
    recovery_string(i+1, j);
  } else {
    recovery_string(i, j+1);
  }

}


int main(){
  cin >> a >> b;
  memset(dp, -1, sizeof dp);

  int val = solve(0, 0);

  // cout<<val<<endl;
  if(val)
    recovery_string(0, 0);
  else cout<<""<<endl;

}

Measured memory_bytes: 36096
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 1e6 + 5, M = 1e9 + 7;
ll l[N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    ll n, c = 0;
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> l[i];
    sort(l, l + n);
    for (ll i = 0; i < n - 2; i++)
        for (ll j = i + 1, k = i + 2; j < n; j++)
        {
            while (k < n && l[i] + l[j] > l[k])
                k++;
            if (k > j)
                c += k - j - 1;
        }
    cout << c;
}

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

int main() {
  int n; cin >>n;
  ll k; cin >>k;
  vector<ll> c(100001);
  ll bufa, bufb;
  for (int i=0; i<n; i++){
    cin >>bufa >>bufb;
    c.at(bufa) += bufb;
  }
  
  int ans;
  ll buf = 0;
  for (int i=0; i<100001; i++){
    buf += c.at(i);
    if (buf >= k){
      ans = i; break;
    }
  }
  
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 1024
using System;

class Problem
{
    public static void Main()
    {
        string s = Console.ReadLine();
        int ans=0, num=0, count =0;
        char[] c = { 'A', 'T', 'C', 'G' };
        
        for(int i=0; i<s.Length; i++)
        {
            for(int j=0; j<4; j++)
            {
                if (c[j] == s[i])
                {
                    num= 1;
                }
            }
            if (num == 1)
            {
                count += 1;
            }
            else
            {
                count = 0;
            }
            ans = Math.Max(count, ans);
            num = 0;
        }
        Console.WriteLine(ans);
    }
    
}

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

int n, mx;
string s;
map<string, int> m;

int main()
{
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> s;
		m[s]++;
	}

	for (auto i : m)
		mx = max(mx, i.second);

	for (auto i : m)
		if (i.second == mx)
			cout << i.first << '\n';

	return 0;
}


Measured memory_bytes: 25216
use std::io::stdin;

fn read() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

use std::cmp::Ordering::{Equal, Greater, Less};
fn main() {
    let mut s: Vec<char> = read().chars().collect();
    let mut t: Vec<char> = read().chars().collect();
    s.sort();
    t.sort_by(|l, r| r.cmp(&l));
    let ans = s
        .iter()
        .zip(t.iter())
        .fold(Equal, |ans, (s, t)| match (ans, s.cmp(&t)) {
            (Equal, Equal) => Equal,
            (Equal, Less) | (Less, _) => Less,
            _ => Greater,
        });
    println!(
        "{}",
        match ans {
            Equal if s.len() < t.len() => "Yes",
            Less => "Yes",
            _ => "No",
        }
    );
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
 
int mincos(int n ,vector<int>&height)
{
     vector<int>dp(n,0);
     for(int i =1;i<n;i++)
     {    if(i==1)dp[i] = dp[i-1]+abs(height[i]-height[i-1]);
       else
       dp[i] = min(dp[i-1]+abs(height[i]-height[i-1]),dp[i-2]+abs(height[i]-height[i-2]));
     }
    return dp[n-1];
}
int main(){
    int n ;
  cin>>n;
  vector<int>height(n);
  for(int i=0;i<n;i++)
  {  cin>>height[i];
  }
  cout<<mincos(n,height)<<endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define N 100

int main(){
  int a,b,i,j,c,v,minj;
  int A[N];

	scanf("%d",&b);
	for(i=0;i<b;i++){
		scanf("%d",&A[i]);
		v=A[i];}
	for(i=0;i<b-1;i++){
	  minj = i;
	  for(j=i;j<b;j++){
	    if(A[j] < A[minj])
	      minj = j;
	  }
	      v=A[i];
	      A[i]=A[minj];
	      A[minj]=v;
	      if(i != minj)c++;
	}
	for(j=0;j<b;j++){
	  printf("%d",A[j]);
	  if(j<b-1) printf(" ");
	}
	printf("\n");
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 2108
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int sum_l = 0;
		int sum_r = 0;
		for(int i = 0; i < M; i++){
			int A = sc.nextInt();
			if(A < X) sum_l++;
			else sum_r++;
		}
		System.out.println(Math.min(sum_l, sum_r));
	}
}

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

int main(){
    int r,c;
    cin >> r >> c;
    int A[r+1][c+1] = {};
    
    for (int i=0; i<r; i+=1){
        for (int j=0; j<c; j+=1){
            cin >> A[i][j];
            A[i][c] += A[i][j];
            A[r][j] += A[i][j];
        }
        A[r][c] += A[i][c];
    }
    
    for (int k=0; k<r+1; k+=1){
        for (int l=0; l<c+1; l+=1){
            if (l==c) cout << A[k][l] << "\n";
            else cout << A[k][l] << " ";
        }
    }
    
    return 0;
}



Measured memory_bytes: 3100
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

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

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int maisuu(int sum) {
	int n = 0;

	n += sum/500;
	sum %= 500;
	n += sum/100;
	sum %= 100;
	n += sum/50;
	sum %= 50;
	n += sum/10;

	return n;
}


int main() {
	int sum;
	bool first = true;

	while(cin >> sum, sum) {
		if(first) {
			first = false;
		} else {
			cout << endl;
		}

		int ju, goju, hyaku, gohyaku;
		cin >> ju >> goju >> hyaku >> gohyaku;
		
		int m_mae = (ju + goju + hyaku + gohyaku);

		int shiharai;

		int m_ju = 0, m_goju = 0, m_hyaku = 0, m_gohyaku = 0;
		int m_shiharai, m_oturi;
		int m_min = 100;

		REP(a, gohyaku+1) {
			REP(b, hyaku+1) {
				REP(c, goju+1) {
					REP(d, ju+1) {
						shiharai = a*500 + b*100 + c*50 + d*10;
						m_shiharai = a + b + c + d;

						if(shiharai >= sum) {
							m_oturi = maisuu(shiharai - sum);

							if(m_min > (m_mae-m_shiharai+m_oturi)) {
								m_min =	m_mae-m_shiharai+m_oturi;
								m_gohyaku = a;
								m_hyaku = b;
								m_goju = c;
								m_ju = d;
							}
						}
					}
				}
			}
		}

		if(m_ju) {
			cout << 10 << " " << m_ju << endl;
		}
		if(m_goju) {
			cout << 50 << " " << m_goju << endl;
		}
		if(m_hyaku) {
			cout << 100 << " " << m_hyaku << endl;
		}
		if(m_gohyaku) {
			cout << 500 << " " << m_gohyaku << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 868
import math
def p(d): print(d)
def i(): return input()

def LI():  # Line Integer
    # 1行 1つの数字
    return int(input())
def LIS():  # Line IntegerS
    # 1行 mつの数字
    return [int(x) for x in input().split()]
def MLIS(n):  # Multi Line IntegerS
    # n行 mつの数字
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  # Line Character
    # 1行 1つの文字
    return input()
def LCS(): # Line CharacterS
    # 1行 nつの文字
    return [x for x in input().split()]
def MLCS(n): # Multi Line CharacterS
    # n行 mつの数字
    return [[x for x in input().split()] for y in range(n)]

def alp2int(alphabet):
    # アルファベットの番号を返す
    return ord(alphabet) - ord('a')
def int2alp(num):
    # 番号からアルファベットを返す
    return chr(num + ord('a'))
def cnt2dic(lst, dic={}):
    # 同じものをカウントして辞書型にする
    for x in lst:
        key = str(x)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1
    return dic
def dic2lst(dic, key=lambda x:x[1]):
    # 辞書をタプルの配列にする
    return sorted(list(dic.items()), key=key);

def A():
    a = LC()
    if a[0] == a[2]:
        print('Yes')
    else:
        print('No')

def B():
    a, b, c, d = LIS()
    s = max(a, c)
    e = min(b, d)
    if s < e:
        p(e-s)
    else:
        p(0)

def C():
    pass

def D():
    pass

def E():
    pass

def F():
    pass

def G():
    pass

def H():
    pass

B()


Measured memory_bytes: 3064
use std::io;
use std::process;

macro_rules! parse_line {
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

fn possible() {
    println!("POSSIBLE");
    process::exit(0);
}

fn main() {
    let size = 200000;
    let (N, M) = parse_line!(i32, i32);
    let mut linked_list: Vec<Vec<i32>> = Vec::with_capacity(size);

    for _ in 0..size + 1 {
        linked_list.push(Vec::new());
    }

    for _ in 0..M {
        let (a, b) = parse_line!(i32, i32);
        linked_list.get_mut(a as usize).unwrap().push(b);
        linked_list.get_mut(b as usize).unwrap().push(a);
    }

    for first in &linked_list[1] {
        if *first == N {
            possible();
        }

        for second in &linked_list[*first as usize] {
            if *second == N {
                possible();
            }
        }
    }
    println!("IMPOSSIBLE");
}

Measured memory_bytes: 16636
#include <iostream>

long long abs(long long n) { return (n > 0)?n:-n; }

int main() {
    long long a, b;
    std::cin >> a >> b;
    if (b > a) {
        if (a >= 0 || 0 >= b) std::cout << b - a << std::endl;
        else std::cout << abs(abs(a) - abs(b)) + 1 << std::endl;
    } else {
        if (b > 0 || 0 > a) std::cout << a - b + 2 << std::endl;
        else if (b == 0 || a == 0) std::cout << a - b + 1 << std::endl;
        else std::cout << abs(abs(a) - abs(b)) + 1 << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){

  int i;
  char s[1002]={'\0'};

  scanf("%s",s);

  for(i=0;i<strlen(s);i++){
    if(s[i]>=65 && s[i]<=67){
      s[i]+='Z'-'C';
    }
    else {
    s[i]-=3;
  }
  }

  printf("%s\n",s);

  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  string c1, c2, c3;
  cin >> c1 >> c2 >> c3;
  cout << c1[0] << c2[1] << c3[2] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int used[100];

int main(){
	int n;
	cin >> n;
	vector<pair<int, int> > red(n), blue(n);
	for (int i = 0; i < n; i++){
		cin >> red[i].first >> red[i].second;
	}
	for (int i = 0; i < n; i++){
		cin >> blue[i].second >> blue[i].first;
	}
	sort(red.begin(), red.end(), greater<pair<int, int> >());
	sort(blue.begin(), blue.end());

	int ans = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (red[j].first < blue[i].second && red[j].second < blue[i].first && !used[j]){
				used[j] = true;
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3612
K, N = map(int,input().split())
A=list(map(int,input().split()))

c=[0]*N
for i in range(N-1):
    c[i] = A[i+1]-A[i]
c.append(K-A[N-1]+A[0])
    
c.sort(reverse=True)

print(sum(c[1:]))

Measured memory_bytes: 25840
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100000;
constexpr ll A_I_MAX = 1000000000;

ll N;
vector<ll> a;

void input() {
	scanf("%lld", &N);
	a.assign(N,0);
	rep(i, N) scanf("%lld", &a[i]);
}

void solve() {
	ll ans = 0;
	sort(all(a));
	if(N%2==0){
		vector<ll> v(N,0);
		for(ll i=0;i<N;i+=2){
			v[i]=a[N/2-1-i/2];
		}
		debug(v);
		for(ll i=N-1;0<i;i-=2){
			debug(N-(i+1)/2);
			v[i]=a[N-(i+1)/2];
		}
		debug(v);
		rep(i,N-1){
			ans+=abs(v[i]-v[i+1]);
		}
	}else{
		ll t=0,t2=0;
		vector<ll> v(N,0),v2(N,0);
		v[0]=v2[0]=a[(N-1)/2];
		for(ll i=1;i<N;i+=2){
			v[i]=a[N-(i+1)/2];
		}
		for(ll i=2;i<N;i+=2){
			v[i]=a[i/2-1];
		}

		for(ll i=2;i<N;i+=2){
			v2[i]=a[N-i/2];
		}
		for(ll i=1;i<N;i+=2){
			v2[i]=a[(i+1)/2-1];
		}


		rep(i,N-1){
			t+=abs(v[i]-v[i+1]);
		}
		rep(i,N-1){
			t2+=abs(v2[i]-v2[i+1]);
		}
		ans=max(t,t2);
	}	

	printf("%lld\n", ans);
}

signed main() {
	input();
	solve();
	return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> indexA(N + 1);
    REP(i, N)
    {
        ll a;
        cin >> a;
        indexA[a] = i;
    }

    ll ans = 0;
    set<ll> s;
    for (ll i = 1; i <= N; ++i)
    {
        ll l, r;
        s.insert(indexA[i]);
        auto it = s.find(indexA[i]);
        if (it != s.begin())
        {
            it--;
            l = *(it);
            l++;
        }
        else
        {
            l = 0;
        }
        it = s.find(indexA[i]);
        it++;
        if (it != s.end())
        {
            r = *it;
            r--;
        }
        else
        {
            r = N - 1;
        }
        ans += i * (indexA[i] - l + 1) * (r - indexA[i] + 1);
    }

    cout << ans << endl;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int n,m,deg[100005],visit[100005],maxn=INT_MIN;
vector <int> ke[100005];
void dfs(int u)
{
    visit[u]=1;
    for ( int i=0;i<ke[u].size();i++ )
    {
        int t=ke[u][i];
        if ( !visit[t] )
            dfs(t);
        deg[u]=max(deg[u],deg[t]+1);
    }
    if ( ke[u].empty() ) deg[u]=1;
}
int main()
{
    cin >> n >> m;
    for ( int i=1;i<=m;i++ )
    {
        int u,v;
        cin >> u >> v;
        ke[u].push_back(v);
    }
    for ( int i=1;i<=n;i++ )
        if ( !visit[i] ) dfs(i);
    for ( int i=1;i<=n;i++ )
        maxn=max(maxn,deg[i]);
    cout << maxn-1;
}

Measured memory_bytes: 8576
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <utility>

using namespace std;
typedef long long ll;

#define ALL(c) begin((c)), end((c))
#define REP(i,n) for(ll i=0;i<(ll)n;++i)

inline int getInt() { int s; scanf("%d", &s); return s; }

#define SIZE 10
typedef array<array<int, SIZE>, SIZE> Table;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int g_c;

void fillColor(Table &state, int from, int to) {
	if (from==to) return;
	vector<pair<int,int>> stack;
	stack.emplace_back(1,1);
	while (!stack.empty()) {
		int x,y; tie(x, y) = stack.back();
		stack.pop_back();
		REP(i, 4) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (state[ny][nx] == from) {
				stack.emplace_back(nx,ny);
				state[ny][nx] = to;
			}
		}
	}
}

int countColor(Table & state) {
	vector<pair<int, int>> stack;
	stack.emplace_back(1, 1);
	int cnt = 0;
	while (!stack.empty()) {
		int x,y; tie(x, y) = stack.back();
		stack.pop_back();

		REP(i, 4) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (state[ny][nx] == g_c) {
				stack.emplace_back(nx, ny);
				cnt++;
				state[ny][nx] = -1;
			}
		}
	}
	return cnt;
}

int recursion(int depth, Table state) {
	if (depth > 5) return countColor(state);
	
	int cnt = 1;
	REP(i, 6) {
		if(depth==5 && i != g_c) continue;
		Table ntable = state;
		ntable[1][1] = i;
		fillColor(ntable, state[1][1], i);
		cnt = max(recursion(depth+1, ntable),cnt);
	}
	return cnt;
}

int main() {
	while (true) {
		ll h,w;
		cin >> h >> w;
		if (h == 0) break;
		
		g_c = getInt() - 1;
		Table table;
		REP(y, SIZE) REP(x, SIZE) table[y][x] = -1;
		REP(y, h) REP(x, w) table[y + 1][x + 1] = getInt()-1;
		cout << recursion(1, table) << endl;
	}
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
    // int tests = 1;
    // cin >> tests;
    // for(int test = 1; test <= tests; ++test) {
        
    // }
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
	int sum = 0;
	for(int i = 0; i < k; ++i) sum += a[i];
	cout << sum;
    return 0;
}

Measured memory_bytes: 3652
I,O,T,J,L,S,Z=gets.split.map &:to_i
a = O+2*(I/2+L/2+J/2)+(I.odd? && J.odd? && L.odd? ? 3 : 0)
b = 0
b = O+2*((I-1)/2+(L-1)/2+(J-1)/2)+3 if 0<I && 0<L && 0<J
p [a,b].max


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		sc.close();

		int mod = 2019;
		if (l / mod < r / mod) {
			System.out.println(0);
		} else {
			int ml = l % mod;
			int mr = r % mod;
			int ans = mod;
			for (int i = ml; i < mr; i++) {
				for (int j = i + 1; j <= mr; j++) {
					ans = Math.min(ans, i * j % mod);
				}
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 35640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for(int i=0; i<5; i++) {
            int x = sc.nextInt();
            if(x == 0) {
                System.out.println(i + 1);
                return;
            }
        }
    }
}

Measured memory_bytes: 35636
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	int[] par;
	int count;

	void union(int x, int y) {
		x = root(x);
		y = root(y);
		par[x] = y;
	}

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

	int root(int x) {
		if (par[x] == x) return x;
		return root(par[x]);
	}

	class Data implements Comparable<Data>{
		int t, u, v;

		Data(int t, int u, int v) {
			this.t = t;
			this.u = u;
			this.v = v;
		}

		@Override
		public int compareTo(Data o) {
			return this.t - o.t;
		}
	}

	void run() {
		MyScanner sc = new MyScanner();

		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if ((n | m) == 0) {
				break;
			}
			Data[] d = new Data[m];
			for (int i = 0; i < m; i++) {
				d[i] = new Data(sc.nextInt(), sc.nextInt() - 1, sc.nextInt() - 1);
			}
			Arrays.sort(d);
			par = new int[n];
			for (int i = 0; i < n; i++) {
				par[i] = i;
			}

			count = 1;
			for (int i = 0; i < m; i++) {
				int u = d[i].u;
				int v = d[i].v;

				if (find(0, u) && !find(u, v)) {
					union(u, v);
					count++;
				}
			}

			System.out.println(count);
		}
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

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

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}

}

Measured memory_bytes: 69628
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc =  new Scanner(System.in);
		int  count =  sc.nextInt();
		for(int  i = 0; i<count;i++){
			boolean d = true;
			int  a = 0;
			int  b = 0;
			for(int c = 0;c<10;c++){
				int p = sc.nextInt();
				if(a < p ){
					a = p;
				}else if(b < p){
					b = p;
				} else {
					d = false;
					//System.out.println(d);
				}
			}
			//System.out.println(d);
			if(d == true){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
		
	}
}

Measured memory_bytes: 26124
package main

import (
	"fmt"
	"sort"
)

func main() {
	// Code for C - Remainder Minimization 2019
	var L, R int
	fmt.Scan(&L, &R)

	var ans int
	var min int = 1000000000
	if R-L+1 < 2019 {
		temp := make([]int, 0)
		for i := L; i <= R; i++ {
			temp = append(temp, i%2019)
		}
		sort.Sort(sort.IntSlice(temp))
		if temp[0] == 0 {
			fmt.Println("0")
		} else {
			for i := 0; i < len(temp); i++ {
				for k := 0; k < len(temp); k++ {
					if i == k {
						continue
					} else {
						ans = (temp[i] * temp[k]) % 2019
					}

					if min > ans {
						min = ans
					}
				}
			}
			fmt.Println(min)
		}

	} else {
		fmt.Println("0")
	}
}


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

N, K = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
ab.sort(key=lambda t: t[0])
cnt = 0

for a, b in ab:
    cnt += b
    
    if cnt>=K:
        print(a)
        exit()

Measured memory_bytes: 56924
/**
*    author:  yuya1234
*    created: 24.06.2020 15:15:47
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n, ans=1;
    cin>>n;

    REP(i,n)
    {
        ans*=i+1;
        ans%=1000000000+7;
    }

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

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

using namespace std;

class StudentInfo {
public:
	int id, score;

	StudentInfo():score(0) {
	}
};

StudentInfo StuData[40];
int ScoreOfSet[21];

int calculation(int n) {
	int i, sum, cnt;

	i = sum = cnt = 0;
	while (cnt!=10)
	{
		//cout << "start:" << i;
		if (ScoreOfSet[i] == 10) {
			sum += 10 + ScoreOfSet[i + 1] + ScoreOfSet[i + 2];
			i++;
		}
		else if (ScoreOfSet[i] + ScoreOfSet[i+1] == 10) {
			sum += 10 + ScoreOfSet[i + 2];
			i += 2;
		}
		else {
			sum += ScoreOfSet[i] + ScoreOfSet[i + 1];
			i += 2;
		}
		//cout <<"   sum=" << sum << endl;
		cnt++;
	}
	return sum;
}



bool cmp(const StudentInfo &stu1, const StudentInfo &stu2) {
	if (stu1.score == stu2.score) {
		return stu1.id < stu2.id;
	}
	return stu1.score > stu2.score;
}

int main() {
	int n,j;
	string str;
	stringstream ss;

	while (cin >> n, n) {
		getchar();
		memset(ScoreOfSet, 0, sizeof(ScoreOfSet));
	
		for (int i = 0; i < n; i++) {
			j = 0;
			getline(cin, str);
			ss << str;
			ss >> StuData[i].id;
			while (ss) {
				ss >> ScoreOfSet[j++];
			}
			j--;
			StuData[i].score = calculation(j);
			ss.clear();
			str = "";
		}
		sort(StuData, StuData + n, cmp);
		
		for (int i = 0; i < n; i++) {
			cout << StuData[i].id << " " << StuData[i].score << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3216
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int[] x={scan.nextInt(),scan.nextInt()};
        
        while(x[0]!=0||x[1]!=0){
        if(x[0]>x[1]){
            x[0]^=x[1];
            x[1]^=x[0];
            x[0]^=x[1];
        }
        System.out.println(x[0]+" "+x[1]);
        x[0]=scan.nextInt();
        x[1]=scan.nextInt();
        }
    }
}


Measured memory_bytes: 36064
k = int(input())

a = (1+k)*k/2

dic = {}
for i in range(1, k+1):
  for j in range(i+1, k+1):
    m = min(i, j-i)
    while m != 0:
      if i%m == 0 and j%m == 0:
        break
      m -= 1
    dic[(i, j)] = m
    a += m * 6

for i in range(1, k+1):
  for j in range(i+1, k+1):
    for l in range(j+1, k+1):
      m1 = dic[(i, j)]
      m2 = dic[(j, l)]
      m = min(m1, m2, abs(m1 - m2)) if m1 != m2 else m1
      while m != 0:
        if m1%m == 0 and m2%m == 0:
          break
        m -= 1
      a += m * 6

print(int(a))

      
  

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

int main() {
    long long W,H,x,y;
    cin >> W >> H >> x >> y;
    cout << float(W * H) / (float)2 << " ";
    if(W % 2 == 0 && H % 2 == 0 && (W) / (2) == (x) && (H) / (2) == (y)){
        cout << "1" << endl;
    }else{
        cout << "0" << endl;
    }
}

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



int main(void){
	int N, A[200000];
	int num, i, max = 0, count = 0, maxcount, max2 = 0;
	
	cin >> N;
	for (i = 0; i < N; i++){
		cin >> A[i];
	}

	
	for (i = 0; i < N; i++){
		if (max < A[i]){
			max = A[i];
			maxcount = i;
		}
		
	}

	for (i = 0; i < N; i++){
		if (A[i] == max) count++;
	}

	for (i = 0; i < N; i++){
		if (i != maxcount){
			cout << max << endl;
		}
		else if (i == maxcount&&count >= 2){
			cout << max << endl;
		}
		else if (i == maxcount&&count == 1){
			for (int j = 0; j < N; j++){
				if (A[j] == max){
					A[j] = 0;
				}
				if (max2 < A[j]) max2 = A[j];
			}
			cout << max2 << endl;
		}
	}
	

	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	string s;
	while(getline(cin, s)){
		rep(i, 26){
			rep(i, s.size()){
				if('a' <= s[i] && s[i] < 'z') s[i]++;
				else if(s[i] == 'z') s[i] = 'a';
			}
			
			if(s.find("the") != string::npos || s.find("this") != string::npos || s.find("that") != string::npos){
				cout << s << endl;
				break;
			}
		}
	}
	
	return 0;
}

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

inline int max(int a, int b)
{
  if(a > b)
    return a;
  else
    return b;
}

int main(int argc, char const *argv[]) {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A*B != C*D)
    cout << max(A*B, C*D);
  else
    cout << A*B;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void) {
  int a, i, j;
  scanf("%d",&a);
  for(i = 0;i < 2;i++) {
    for(j = 9;j > 0;j--){
    	if (a % j == 0) {
      	a = a / j;
      	break;
        }
    }
  }
  if(a == 1) {
    printf("Yes");
  }else {
    printf("No");
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    int H;
    int N;
    cin >> H >> N;
    ve<ll> A(N),B(N);
    rep(i,N) cin >> A[i] >> B[i];
    ve<ve<ll>> dp(N+1,vl(H+30000,1e18));
    dp[0][0] = 0;
    
    rep(i,N) rep(j,H+30000){
        
        if(A[i] <= j){
            dp[i+1][j] = min(dp[i][j],dp[i+1][j-A[i]]+B[i]);
        }else{
            dp[i+1][j] = dp[i][j];
        }
    }

    ll ans = 1e18;
    reps(i,H,H+30000) ans = min(ans,dp[N][i]);

    
    out(ans);
    
    /*
    rep(j,H+1000){
        cout << dp[N][j] << " ";
    }
    cout << endl;
    */
    

    return 0;
}


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

int main() {

	int N, M, L, R,l,r;
	cin >> N >> M >> l >> r;
	for (int i = 0; i < M-1; i++) {
		cin >> L >> R;
		if (l <= L) {
			l = L;
		}
		if (r >= R) {
			r = R;
		} 

		
	}

	if (r - l < 0) {
		cout << 0;
	}
	else {
		cout << r - l + 1;
	}

	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000007

int main(){

    ll x;
    cin >> x;

    ll ans = x*2/11;
    
    int mod = x%11;

    if((x*2%11 != 0) && mod != 6){
        ans+=1;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring> 
using namespace std;
char a[100005];
int ans;
int main()
{
	cin>>a;
	int len=strlen(a);
	for(int i=0;i<=len-1;i++)
	{
		int find=0;
		for(int j=1;j<=len-2;j++)
		{
			if(a[j]!='.')
			{
				int k=j-1;
				while(a[k]=='.'&&k>0)
					k--;
				int k2=j+1;
				while(a[k2]=='.'&&k2<len-1)
					k2++;
				if(a[k]!=a[k2])
				{
					ans++;
					find=1;
					a[j]='.';
				}
			}
		}
		if(find==0)
		{
			if(ans%2==0)
			{
				cout<<"Second";
				return 0;
			 } 
			 else 
			 {
			 	cout<<"First";
			 	return 0;
			 }
		}
	}
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

		public static void main(String[] args) throws java.lang.Exception {
		      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		      String s = br.readLine();
		      int a = 0, b = 0;
		      for(char c : s.toCharArray()) {
		    	  if(c == 'A')
		    		  a++;
		    	  if(c == 'B')
		    		  b++;
		      }
		      if(a == 0 || b == 0)
		    	  System.out.println("No");
		      else
		    	  System.out.println("Yes");
		}
}


Measured memory_bytes: 21332
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  int ans = 0;
  for(int i = 0; i < N - 1; i++){
    if(s[i] == s[i+1]) ans++;
  }

  cout << min(N - 1, ans + 2 * K) << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> iii;
typedef vector<iii> viii;

#define umap unordered_map
#define uset unordered_set
#define pb push_back
#define LSOne(x) (x & (-x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

const int iinf = 1e9+7;
const ll inf = 1e18+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    vi v(n);
    for (auto& i : v) cin >> i;
    vi dp(n,iinf);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j <= i+2; ++j) {
            if (j < n) dp[j] = min(dp[i]+abs(v[i]-v[j]),dp[j]);
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int N, M, ans;
		boolean loop;
		while ((N = scn.nextInt()) != 0) {
			M = scn.nextInt();
			int[] tile = new int[N * M];
			boolean[] through = new boolean[N * M];
			String buf = scn.nextLine();
			for (int i = 0; i < N * M; i++) {
				
				if (i % M == 0) {
					buf = scn.nextLine();
				}
				switch (buf.charAt(i % M)) {
				case '.':
					break;
				case '>':
					tile[i] = 1;
					break;
				case '<':
					tile[i] = -1;
					break;
				case 'v':
					tile[i] = M;
					break;
				case '^':
					tile[i] = -M;
					break;
				default:
					break;
				}
			}
			ans = 0;
			loop = false;
			while (tile[ans] != 0) {
				if (through[ans]) {
					loop = true;
					break;
				}
				through[ans] = true;
				ans += tile[ans];
			}
			System.out.println(loop ? "LOOP" : ans % M + " " + ans / M);
		}
		scn.close();
	}
}



Measured memory_bytes: 28548
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<long long> w(n), d(n);
    for(int i=0; i<n; ++i)
        cin >> w[i] >> d[i];

    long long left = 1;
    long long right = 3000000000000000000LL;
    while(left < right){
        long long mid = (left + right) / 2;
        long long cnt = 0;
        for(int i=0; i<n; ++i){
            if(w[i] <= mid)
                cnt += (mid - w[i]) / d[i] + 1;
        }
        if(cnt < k)
            left = mid + 1;
        else
            right = mid;
    }
    cout << left << endl;

    return 0;
}


Measured memory_bytes: 1792
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

map< int, int > prime_factor(int n) {
  map< int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int n,p;

signed main(){

    in(n,p);
    map<int,int> res=prime_factor(p);
    int ans=1;
    for(auto e:res){    
        ans*=pow(e.fs,e.sc/n);
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 256
###### Importing Libraries ######
import math
import operator as op
from functools import reduce
from fractions import Fraction as frac
#################################
##### User defined function #####

############ NCR ###############
def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
    
############ READ ###############
def rd(p):
    if(p==0):
        return input()
    if(p==1):
        return int(input())
    if(p==2):
        return map(int,input().split())
    if(p==3):
        return list(map(int,input().split()))


############ DSU ###############
global par
par=[-1 for i in range(100001)]
# t=rd(1)
def find(u):
    if(par[u]<0):
        return u
    else:
        return find(par[u])
def uni(x,y):
    u=find(x)
    v=find(y)
    if u==v:
        return
    if(par[u]<par[v]):
        par[u]+=par[v]
        par[v]=u
    else:    
        par[v]+=par[u]
        par[u]=v
################################        
        

t=1
for term in range(1,t+1):
    n=rd(1)
    div=10
    tot=0
    if n%2==1:
        print(0)
    else:    
        while(n>=div):
            # print(n//div)
            tot+=(n//div)
            div*=5
        print(tot)
    
        
    
    

Measured memory_bytes: 6336
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int a,b,num;
		boolean ab,bb;
		String str;
		Scanner sc = new Scanner(System.in);
		num = sc.nextInt();
		a = num/100;
		b = num - a*100;
		if(a>0&&a<13) {
			ab = true;
		}else {
			ab = false;
		}
		if(b>0&&b<13) {
			bb = true;
		}else {
			bb = false;
		}
		if(ab&&bb) {
			str = "AMBIGUOUS";
		}else if(ab==true) {
			str = "MMYY";
		}else if(bb==true) {
			str = "YYMM";
		}else {
			str = "NA";
		}

		System.out.println(str);
	}
}


Measured memory_bytes: 21972
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
std::vector<pair<ll,ll>> v;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    for (int i = 0; i < n; ++i)
    {
    	ll a;
    	cin>>a;
    	v.push_back(mp(a,1));
    }
    for (int i = 0; i < m; ++i)
    {
    	ll a,b;
    	cin>>a>>b;
    	v.push_back(mp(b,a));
    }
    sort(v.begin(),v.end(),greater<pair<ll,ll>>());
    ll ans=0;
    for (int i = 0; i < v.size(); ++i)
    {
    	pair<ll,ll> x=v[i];
    	if(x.second<=n)
    	{
    		n-=x.second;
    		ans+=x.first*x.second;
    	}
    	else
    	{
    		ans+=x.first*n;
    		break;
    	}
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 6512
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Integer[] a = Arrays.stream(in.readLine().split(" ")).map(Integer::parseInt).toArray(Integer[]::new);
    Arrays.sort(a);
    System.out.println(a[0]+a[1]);
  }
}


Measured memory_bytes: 26836
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    a=list(map(int,sys.stdin.readline().split(' ')))
    ans=[0 for i in range(n)]
    for k in a:
        ans[k-1]+=1
    for k in ans:
        print(k)
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;

  vector<int> ans;
  for (int i = 1; i <= min(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      ans.push_back(i);
    }
  }

  reverse(ans.begin(), ans.end());
  cout << ans[k-1] << endl;
}


Measured memory_bytes: 256