akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n,m,x,i,t;
  cin >> n >> m >> x; 
  int ans1=0,ans2=0;
  for(i=0; i<m; i++){
    cin >> t;
    if(t<x){
      ans1++;
    }else{
      ans2++;
    }
  }
  cout << min(ans1,ans2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

int main(){
	string s; cin >> s;
	ll ans = 0;
	REP(i,s.size()){
		if (s[i]=='+') ans++;
		else ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    data = input().split()
    S = float(data[0]) * float(data[1]) / 2
    center = [float(data[0]) / 2, float(data[1]) / 2]
    plot = [float(data[2]), float(data[3])]
    if plot == center:
        print(S, 1)
    else:
        print(S, 0)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int q = scan.nextInt();
        int[] out = new int[n];
        Arrays.fill(out, k);
        for(int i = 0; i < q; i++){
            out[scan.nextInt() - 1]++;
        }
        for(var i : out){
            if(i - q > 0) System.out.println("Yes");
            else System.out.println("No");
        }
    }

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


Measured memory_bytes: 59812
N, M = map(int, input().split())

def factorized(M):
    d = 2
    f = []
    while d <= M:
        count = 0
        while M % d == 0:
            M //= d
            count += 1
        if count > 0:
            f.append(count)
        d += 1
        if d < M and d * d > M:
            d = M
    return f

def tetra(n, m):
    x = 1
    for y in range(1, n):
        x = x * (m + y - 1) // y
    return x

x = 1
for f in factorized(M):
    x *= tetra(N, f + 1)
    x %= 10 ** 9 + 7

print(x)


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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

ll pows(int a , int b)
{
	ll res=1;
	for(int i=0; i<b; ++i)
	{
		res*=a;
	}
	return res;
}

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int k,x;cin>>k>>x;
    for(int i=x-(k-1); i<=x+(k-1); ++i)
    {
    	cout<<i<<" ";
    }


}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    int ans = 0;
    rep(i,k){
        ans += p[i];
    }
    cout << ans << endl;

}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  vi v;
  int tmp;

  rep (i, 5) {
    cin >> tmp;
    v.pb(tmp);
  }
  sort(rall(v));

  tr (v, i) {
    cout << *i;
    if (i+1!=v.end())
      cout << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll MOD=1000000007;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n,q;cin >> n >> q;
    auto ft = fenwick_tree<ll> (n);
    for (int i = 0; i < n; i++) {
        int a;cin >> a;
        ft.add(i, a);
    }

    while(q--){
        int t,a,b;cin >> t >> a >> b;
        if(t == 0){
            ft.add(a, b);
        }
        else{
            cout << ft.sum(a, b) << endl;
        }
    }
    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  CIN(int, H, A);
  COUT((H+A-1)/A);
}


Measured memory_bytes: 256
# ABC138D - Ki
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def dfs(v: int, p: int, G: "List[List[int]]", cnt: "List[int]"):
    for u in G[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += cnt[v]  # cumulative sum
            dfs(u, v, G, cnt)
            
def main():
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    G = [[] for _ in range(N + 1)]  # graph, N+1: 1-idx -> 0-idx
    for a, b in E:
        G[a] += [b]
        G[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1, G, cnt)
    print(*cnt[1:])
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 265728
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    int h, w;
    cin>>h>>w;
    
    vector<vector<char>> v(h+2, vector<char>(w+2, '#'));
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>v[i+1][j+1];
        }
    }
    
    for(int i=0; i<h+2; i++){
        for(int j=0; j<w+2; j++){
            cout<<v[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    if n%10==2 or n%10==4 or n%10==5 or n%10==7 or n%10==9:
        print("hon")
    elif n%10==0 or n%10==1 or n%10==6 or n%10==8:
        print("pon")
    else:
        print("bon")
if __name__=='__main__':
    main()

Measured memory_bytes: 9184
#include <iostream>
using namespace std;
int a[25];
int main()
{
	int n,m=0;
	cin>>n;
	for (int i = 0;i < n;i++)
	{
		cin >> a[i];
	}
	for (int i = 0;i < n-2;i++)
	{
		if ((a[i] < a[i + 1] && a[i + 1] < a[i + 2])||(a[i]>a[i+1]&&a[i+1]>a[i+2])) m++;
	}
	cout << m << '\n';
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,k,r,s,p,ans=0;cin>>n>>k;cin>>r>>s>>p;
  string t;cin>>t;
  vector<ll> didget(n,0);
  for (ll i = 0; i < n; ++i) {
    if (i < k) {
      if(t[i]=='r') ans += p; if(t[i]=='p') ans += s; if (t[i]=='s') ans += r;
      didget[i] = 1;
    }
    else {
      ll posk = i - k;
      if(t[i]=='r') { 
        if (t[posk] != 'r') {ans += p;didget[i] = 1;}
        else { if (didget[posk] == 0) {ans+=p;didget[i] = 1;}}
      }
      if(t[i]=='p') { 
        if (t[posk] != 'p') {ans += s;didget[i] = 1;}
        else { if (didget[posk] == 0) {ans+=s;didget[i] = 1;}}
      }
      if(t[i]=='s') { 
        if (t[posk] != 's') {ans += r;didget[i] = 1;}
        else { if (didget[posk]==0) {ans += r;didget[i] = 1;}}
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1232
n = gets.chomp.to_i
varr = gets.chomp.split.map(&:to_i)
carr = gets.chomp.split.map(&:to_i)
cnt = 0
n.times do |i|
	if varr[i] > carr[i]
		cnt += varr[i] - carr[i]
	end
end
puts cnt




Measured memory_bytes: 14272
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 100

int compare(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}

int main()
{
    int i, n;
    int turn = 1, score = 0;
    int a[N];
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    qsort(a, n, sizeof(int), compare);
    for (i = 0; i < n; i++)
    {
        score += turn * a[i];
        turn = -turn;
    }
    printf("%d\n", score);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  string s;
  int ans = 0;
  cin >> s;

  for(int i = 0; i < 4; i++){
    if(s[i] == '+'){
      ans++;
    }else if(s[i] == '-'){
      ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define INF 210000000
#define int long long

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i=n;i>=1;i--){
        double tmp;
        tmp = pow(i,0.5);
        if(floor(tmp) == ceil(tmp)){
            ans = i;
            break;
        }
    }
    cout << ans;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#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++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

ll gcd(ll x,ll y){
  if(x>y)swap(x,y);
  if(y%x==0)return x;
  return gcd(y-x*(y/x),x);
}

int main(){
  char c;
  cin >> c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o')cout << "vowel";
  else cout << "consonant";
  cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

double a,b;

int main(void){
	scanf("%lf%lf",&a,&b);
	if(b<a)swap(a,b);
	if(b-a<=180.0)printf("%.9f\n",(a+b)/2.0);
	else{
		b-=360.0;
		double c=(a+b)/2.0;
		printf("%.9f\n",c>0?c:360.0+c);
	}
	return 0;
}

Measured memory_bytes: 3168
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

antenna = [a, b, c, d, e]
is_ok = True
for i in range(len(antenna)):
    for j in range(i+1, len(antenna)):
        if antenna[j] - antenna[i] > k:
            is_ok = False

if is_ok:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {
	int N, count = 0;

	cin >> N;

	if (N >= 195) {
		count = 5;
	}
	else if (N >= 189) {
		count = 4;
	}
	else if (N >= 165) {
		count = 3;
	}
	else if (N >= 135) {
		count = 2;
	}
	else if (N >= 105) {
		count = 1;
	}

	cout << count << endl;
}

Measured memory_bytes: 256
N,M = gets.split.map &:to_i
AB = M.times.map{ gets.split.map &:to_i}

Map = Array.new(N+1).map{[]}
AB.each do |a,b|
    Map[a] << b
    Map[b] << a
end

ans = [nil]*(N+1)
qry = Map[1].map{|i| [i,1]}
while q = qry.shift
    to,from = q
    next if ans[to]
    ans[to] = from
    Map[to].each{|i| qry << [i,to]}
end

if ans[2..-1].compact.size == N-1 then
    puts "Yes"
    puts ans[2..-1]
else
    puts "No"
end

Measured memory_bytes: 74416
from math import sqrt

x = int(input())
n = (sqrt(8*x+1) - 1) / 2
if int(n) == n:
  n = int(n)
  a = [[1], [1]]
  for i in range(2, n+1):
    ti = i*(i+1)//2
    b = list(range(ti+1-i,ti+1))
    for j, v in enumerate(b):
      a[j].append(v)
    a.append(b)
  print("Yes")
  print(len(a))
  for b in a:
    print(len(b), *b)
else:
  print("No")



Measured memory_bytes: 9480
import collections

h, w = map(int, input().split())

ss = [input() for _ in range(h)]
start = [0,0]
goal = [w-1,h-1]
wall_count = 0
for s in ss:
    wall_count += s.count("#")

dx = [1,-1,0,0]
dy = [0,0,1,-1]

stack = collections.deque([start])
visited = [[-1 for _ in range(h)] for _ in range(w)]
visited[start[0]][start[1]] = 1

while len(stack) > 0:
    pos = stack.pop()
    if pos == goal:
        break
    
    for x,y in zip(dx, dy):
        next_pos = [pos[0]+x, pos[1]+y]
        
        if next_pos[0]<0 or (w-1)<next_pos[0] or next_pos[1]<0 or (h-1)<next_pos[1]:
            continue
        if ss[next_pos[1]][next_pos[0]] == "#":
            continue
        if visited[next_pos[0]][next_pos[1]] != -1:
            continue
        stack.appendleft(next_pos)
        visited[next_pos[0]][next_pos[1]] = visited[pos[0]][pos[1]] + 1

if visited[w-1][h-1] == -1:
    print("-1")
else:
    score = (h*w) - wall_count - visited[w-1][h-1]
    print(score)

Measured memory_bytes: 42224
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n; 
    for (int x=1;x<=3500;x++){
        for (int y=1;y<=3500;y++){
            int z = (n*x*y)/max(1LL,((4*x*y)-(n*y)-n*x));
            if (z>0 and (x*y*z*4 == n*((x*y)+(y*z)+(z*x)))){
                cout << x << " " << y << " " << z << endl; 
                return;
            }
        }
    }
    
}

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


Measured memory_bytes: 3596
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let X: i64 = read();
    let K: i64 = read();
    let D: i64 = read();
    
    let chk_sub = K.checked_mul(D);
    if chk_sub != None{
        if X.abs() >= K * D {
            println!("{}",X.abs() - K * D);
        }else{
            let m = X.abs() % D;
            if (K - (X.abs() / D)) % 2 == 0{
                println!("{}",m);
            }else{
                println!("{}",D - m);
            }
        }
    }else{
        let m = X.abs() % D;
        if (K - (X.abs() / D)) % 2 == 0{
            println!("{}",m);
        }else{
            println!("{}",D - m);
        }
    }
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;

int main() {
  ll n, q;
  cin >> n >> q;
  vector<ll> upGet(n - 2, n - 2);
  vector<ll> leftGet(n - 2, n - 2);
  ll h = n - 2;
  ll w = n - 2;
  ll prevx = n - 2;
  ll prevy = n - 2;
  ll ans = (n - 2) * (n - 2);
  rep(i, q) {
    // cout << "i:" << i << " ans:" << ans << endl;
    ll t, x;
    cin >> t >> x;
    x -= 2;
    if (t == 1) {
      if (x < w) {
        w = x;
        ans -= h;
        for (ll i = w; i < prevx; i++) {
          upGet[i] = h;
        }
        prevx = w;
      } else {
        ans -= upGet[x];
      }
    } else {
      if (x < h) {
        h = x;
        ans -= w;
        for (ll i = h; i < prevy; i++) {
          leftGet[i] = w;
        }
        prevy = h;
      } else {
        ans -= leftGet[x];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(int argc, char* argv[])
{
    int N, K; cin >> N >> K;

    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    sort(L.begin(), L.end(), greater<int>());

    int total = 0;
    for (int i = 0; i < K; i++) {
        total += L[i];
    }

    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int quiz=4,choices[4];
    int wrong;
    for (int i=0;i<quiz;i++){
        choices[i]=i;
    }
    for(int i=0;i<2;i++){
        cin>>wrong;
        for(int j : choices){
            if (choices[j]==wrong) choices[j]=0;
        }
    }
    for(int i : choices){
        if(choices[i]!=0) cout<<choices[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        long x = Math.min(N, B-1);

        long score = A*x/B;

        System.out.println(score);

        sc.close();
    }
}

Measured memory_bytes: 35692
s = list(input())

k = int(input())

cnt = 0

if len(s) == 1:
    print(s[0])
else:
    if s[0] == "1":
        
        while s[0] == "1":
            cnt += 1
            del s[0]
            if cnt>=k:
                print(1)
                break
            
        if cnt<k:
            print(s[0])
            
    else:
        print(s[0])

Measured memory_bytes: 3060
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF =1e9;
const ll LINF=1e18;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a / gcd(a, b)*b;}
int n, k;
vector<double> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>k;
    vector<ll> suma;
    ll sum=0; 
    for(ll i=1;i<=200000;i++){
        sum+=i;
        suma.push_back(sum);
    }
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        double temp1=double(suma[temp-1])/temp;
        //cout<<temp1<<"\n";
        a.push_back(temp1);
    }
    vector<double> anss;
    anss.push_back(0);
    double sumb=0;
    for(int i=0;i<n;i++){
        sumb+=a[i];
        anss.push_back(sumb);
    }
    double ans=0;
    for(int i=0;i<=n-k;i++){
        //cout<<anss[i+k]-anss[i]<<"\n";
        chmax(ans,anss[i+k]-anss[i]);
    }
    cout<<setprecision(15)<<ans<<"\n";
}



Measured memory_bytes: 6512
#include <iostream>

using namespace std;

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

int main() {
  int n;
  cin >> n;
  int k = 0;
  rep(i,n) {
    int a;
    cin >> a;
    if(a == k+1) k++;
  }
  cout << (k == 0 ? -1 : n - k) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std; 

int
main(int argc, char const *argv[])
{
    string s;
    cin >> s;

    bool t = true;
    uint64_t a = 0, b = 0;
    for (auto c = s.begin(); c != s.end(); ++c) {
	if (t) {
	    if (*c == '0') {
		++a;
	    } else {
		++b;
	    }
	} else {
	    if (*c == '1') {
		++a;
	    } else {
		++b;
	    }

	}
	t = !t;
    }

    if (a < b)
	cout << a << endl;
    else
	cout << b << endl;

    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){

  ll n, a;
  cin>>n>>a;
  if(n%500 <= a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
  
}

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

int main() {
  long int n;

  long int i, tmp, x, max_odd, max_odd_i, sec_odd, max_even, max_even_i,
      sec_even, y, z;
  long int odd[MAX] = {0}, even[MAX] = {0};

  scanf("%ld", &n);

  for (i = 0; i < n; i++) {
    scanf("%ld", &tmp);
    if (i % 2 == 0) {
      even[tmp - 1]++;
    } else {
      odd[tmp - 1]++;
    }
  }

  max_odd = 0;
  max_odd_i = 0;
  sec_odd = 0;
  for (i = 0; i < MAX; i++) {
    if (odd[i] >= max_odd) {
      sec_odd = max_odd;
      max_odd = odd[i];
      max_odd_i = i;
    } else if (odd[i] > sec_odd) {
      sec_odd = odd[i];
    }
  }
  max_even = 0;
  max_even_i = 0;
  sec_even = 0;
  for (i = 0; i < MAX; i++) {
    if (even[i] >= max_even) {
      sec_even = max_even;
      max_even = even[i];
      max_even_i = i;
    } else if (even[i] > sec_even) {
      sec_even = even[i];
    }
  }

  if (max_odd_i != max_even_i) {
    x = n - max_odd - max_even;
  } else {
    // max_oddにする
    y = n - max_odd - sec_even;
    // max_evenにする
    z = n - sec_odd - max_even;
    x = y < z ? y : z;
  }
  printf("%ld\n", x);
  return 0;
}


Measured memory_bytes: 1664
N = int(input())

L0 = 2
L1 = 1

if N == 0:
  ans = L0
elif N == 1:
  ans = L1
else:
  prepre = L0
  pre = L1
  ans=0
  for n in range(2,N+1):
    ans = prepre + pre
    prepre = pre
    pre = ans

print(ans)

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

using namespace std;

#define int unsigned long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

signed main()
{
    double a;
    string b;
    cin >> a >> b;

    int b100 = (b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] - '0');

    print((int)a * (b100) / 100);
}


Measured memory_bytes: 3736
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int result = (int) Math.ceil((double) (n - k) / (k - 1)) + 1;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 50208
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedLists #-}

import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    as <- V.fromList . B.words <$> B.getLine
    let printn i = do
        B.putStr $ as V.! i
        B.putStr " "
    V.mapM_ printn [(n - 1), (n - 3) .. 0]
    V.mapM_ printn $ if odd n then [1, 3 .. (n - 1)] else [0, 2 .. (n - 1)]


Measured memory_bytes: 24956
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// 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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
  int x;
  cin >> x;
  if(x==7||x==5||x==3)cout<<"YES"<<endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define pln(x) cout << (x) << endl
#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N,K,Q;
  while(cin >> N >> K >> Q){
    vector<int> A(N); cin >> A;

    int ans = 1e9;

    REP(i,N){
      int m = A[i];

      vector<vector<int>> t;
      REP(j,N){
	if(A[j] < m){
	  t.push_back(vector<int>());
	}else{
	  if(t.empty()) t.push_back(vector<int>());
	  t.back().push_back(A[j]);
	}
      }

      vector<int> s;

      for(auto &x : t){
	sort(ALL(x));
	REP(j,(int)x.size()-K+1) s.push_back(x[j]);
      }

      sort(ALL(s));

      //dump(s);
      if(s.size() >= Q){
	chmin(ans, s[Q-1] - s[0]);
      }
    }

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


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }


int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N, X; cin >> N >> X;
    int d = 0;
    int ret = 1;
    vector<int> L;
    for(int i = 0; i < N; i++)
    {
        int t; cin >> t; L.push_back(t);
    }
    
    for(int i = 0; i < L.size(); i++)
    {
        d += L[i];
        if(d <= X)
            ret += 1;
    }
  
    cout << ret << endl;
    return 0;
}








Measured memory_bytes: 256
n=input()
a=input()
b=input()
c=input()
tim = 0
for i in range(int(n)):
    if a[i] == b[i] and b[i] != c[i]:
        tim+=1
    elif b[i] == c[i] and c[i] != a[i]:
        tim+=1
    elif c[i] == a[i] and a[i] != b[i]:
        tim+=1
    elif c[i] == a[i] and a[i] == b[i]:
        tim+=0
    else:
        tim+=2
print(str(tim))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
   ll h;
   cin >> h;
   int count = 0;
   while(h != 1) {
       count++;
       h /= 2;
   }
   count++;
   cout << setprecision(13) << pow(2, count) - 1 << endl;
   return 0;
}

Measured memory_bytes: 256
//                                                  '-.-'
   //                                         ()      __.'.__
   //                                      .-:--:-.  |_______|
   //                               ()      \____/    \=====/
   //                               /\      {====}     )___(
   //                    (\=,      //\\      )__(     /_____\
   //    __    |'-'-'|  //  .\    (    )    /____\     |   |
   //   /  \   |_____| (( \_  \    )__(      |  |      |   |
   //   \__/    |===|   ))  `\_)  /____\     |  |      |   |
   //  /____\   |   |  (/     \    |  |      |  |      |   |
   //   |  |    |   |   | _.-'|    |  |      |  |      |   |
   //   |__|    )___(    )___(    /____\    /____\    /_____\
   //  (====)  (=====)  (=====)  (======)  (======)  (=======)
   //  }===={  }====={  }====={  }======{  }======{  }======={
   // (______)(_______)(_______)(________)(________)(_________)
   //
   // Credits :- Joan G. Stark
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
   //|                      AUTHOR - KASPAROVIAN                                     |
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define frr(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fr first
#define sc second
#define mk make_pair
#define endl '\n'
#define MOD 1000000007
#define in insert
#define sz(x) (ll)(x).size()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef pair<int,pi> ppi;
typedef vector<vi> graph;
template<class T> void mxi(T & a, const T & b) { a = max(a, b); }
template<class T> void mni(T & a, const T & b) { a = min(a, b); }
ld EPS=1e-9;
void solve()
{
  int n;
  cin>>n;
  if(n<30)
  	cout<<"No\n";
  else
  	cout<<"Yes\n";

}
signed main()
{
  fast;
  int t,tab;
  t=1;
  tab=t;
  while(t--)
  {
    //cout<<"Case #"<<(tab-t)<<": ";
    solve();
  }
}
//APPROACHING A QUESTION
//+ Think of binary search (max of min etc also if n<=2*10^5)
//+ Think of common dp states (Even if it appears as maths but constraints are small)
//+ Check constraints
//+ Keep calm and enjoy the question
//+ Be sure to remove MOD from binpow (if needed)
//+ Try bidirectional analysis for constructive questions
//+ If given some sequence try thinking of prefix sums
//+ If constraints are too large maybe its simple maths
//+ In questions with binary operations think of bits independently and also the change pattern
//+ If two or more binary operations are given mostly there is a relation between them and an arithmatic operator

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y)
{
    if (y < 0) {
        return dceil(-x, -y);
    }
    if (x < 0) {
        return -dfloor(-x, y);
    }
    return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y)
{
    if (y < 0) {
        return dfloor(-x, -y);
    }
    if (x < 0) {
        return -dceil(-x, y);
    }
    return x / y;
}

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

    vector<int> c(n), s(n), f(n);
    rep(i, n - 1)
    {
        cin >> c[i] >> s[i] >> f[i];
    }

    rep(i, n - 1)
    {
        int result = 0;
        for (int j = i; j < n - 1; j++) {
            result = max((int64_t)s[j], f[j] * dceil(result, f[j])) + c[j];
        }

        cout << result << endl;
    }
    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a_max = int(math.sqrt(n))
    min_v = 10 ** 12
    for a in range(1, a_max+1):
        if n % a == 0:
            min_v = min(min_v, a + (n//a) - 2)
    print(min_v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    long long i,j,e=1,n,m,x,c=0,d=0;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            c++;
            if(a[i]%3==0||a[i]%5==0)
            {
                d++;
            }
        }
    }
    if(c==d)
    {
        cout<<"APPROVED";
    }
    else
        cout<<"DENIED";
}


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

static const int INF = 1000000;

typedef long long ll;

char s[55][55];
int H, W, ans;
int white;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int d[55][55];

struct Grid {
  int y, x, d;
  bool operator> (const Grid &g) const {
      return d > g.d;
  }
};

void dijkstra() {
    priority_queue<Grid, vector<Grid>, greater<Grid> > PQ;

    for (int i = 0; i < 55; i++) {
        for (int j = 0; j < 55; j++) {
            d[i][j] = INF;
        }
    }

    Grid g = {0, 0, 1};
    PQ.push(g);
    d[0][0] = 1;
    while (!PQ.empty()) {
        Grid g = PQ.top(); PQ.pop();
        int sx = g.x, sy = g.y;

        if (d[sy][sx] < g.d) continue;
        for (int i = 0; i < 4; i++) {
            int tx = sx + dx[i];
            int ty = sy + dy[i];

            if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue;
            int cost = d[sy][sx] + 1;

            if (cost < d[ty][tx] && s[ty][tx] != '#') {
                d[ty][tx] = cost;
                Grid g2 = {ty, tx, cost};
                PQ.push(g2);
            }
        }
    }

}

int main(void) {
    scanf("%d %d", &H, &W);
    rep(i, 0, H) scanf("%s", &s[i]);
    
    rep(i, 0, H){
      rep(j, 0, W){
        if (s[i][j] == '.') white++;
      }
    }
    
    dijkstra();

    if (d[H-1][W-1] == INF) puts("-1");
    else printf("%d\n", white - d[H-1][W-1]);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli                             long long int
#define ull                             unsigned long long int
#define D                               double
#define Input(n)                        for(int i = 0; i < n; i++) cin >> a[i];                          
#define sqr(x)                          ((x)*(x))
#define ff                              first
#define sz                              size()
#define PB                              push_back
#define MP                              make_pair
#define CHR                             getchar()
#define NL                              printf("\n")
#define PI                              2.0*acos(0.0)
#define MEM(a,val)                      memset(a,val,sizeof(a))
#define timesave                        ios_base::sync_with_stdio(0); cin.tie(0)
#define debug                           printf("***** here here here here *****\n");
#define file_input                      freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
using namespace std;

template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}


long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }

const int M = 1e5 + 5;

 
                      ///*********************** Let`s start ***************************//

int main()
{
	timesave;
	
	
	lli k, l, r, x, y;
	
	cin >> k;
	
	lli a[k+5];
	
	for(int i = 0; i < k; i++){
		cin >> a[i];
	}
	if(a[k-1] != 2){
		cout << -1 << endl;
		return 0;
	}
	l = 2; r = 3;
	
	for(int i = k-2; i >= 0; i--){
		x = (l-1)/a[i]+1; y = r/a[i];
		//cout << x << " " << y << endl;
		
		if(x > y){
			cout << -1 << endl;
			return 0;
		}
		
		l = x*a[i]; r = (y*a[i])+a[i]-1;
	}
	
	cout << l << " " << r << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>
#include <iomanip>

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(int argc, const char *argv[]){
    int n;
    cin >> n;
    vector<double> a(n);
    double sum = 0;
    rep(i,n){
        cin >> a[i];
        sum+=1/a[i];
    }
    cout << fixed;
    cout << setprecision(10) << 1/sum << endl;
    return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n,k;
const int P = 1e9 + 7;
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}
int pot(int a,int w){
  int r = 1;
  while(w){
    if(w & 1){
      r = r * a % P;
    }
    w/=2;
    a = a * a % P;
  }
  return r;
}
const int MAX = 101;
int dp[MAX][MAX*MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> k;
  int lim = (n + 1) * n / 2 + 2;
  debug(lim);
  dp[n][0] = 1;
  for(int gd = n - 1; gd >= 0; gd--){
    R(i,lim)if(dp[gd+1][i])R(j,k + 1){
//       debug(j);
      if(j <= gd + 1){
        add(dp[gd][i + (i + j) / (gd + 1)], dp[gd + 1][i]);
      }else{
        add(dp[gd][i], dp[gd + 1][i]);
      }
    }
//     debug(gd);
//     R(i,lim)
//       cerr << dp[gd][i] << "\n";
//     cerr << "\n";
//     debug("-----");
  }
  int res = 0;
  R(i,lim){
    add(res, dp[0][i] * i % P);
  }
  debug(res);
  cout << ((k + 1) * k / 2 * pot(k+1, n-1) % P * n % P - res + P) % P << "\n";
}


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

#define fs first
#define sc second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair

const int N = 2e5+10;
const ll MAX = ll(1e18) + 111;
const ll MOD = 1e9+7;

int a[N], n, m;

vector<int> g[N];

int ans[N];
int dist[N];

void dfs0(int v, int d = 0, int p = -1){
    dist[v] = d;
    for(int i = 0; i < g[v].size(); i++){
        int to = g[v][i];
        if(to == p) continue;

        dfs0(to, d+1, v);
    }
}

void dfs(int v, int p = -1){

    int children = 0;
    int tans = 0;

    for(int i = 0; i < g[v].size(); i++){
        int to = g[v][i];
        if(to == p) continue;

        dfs(to, v);

        if(!ans[to])
            children += 1;

        tans += ans[to];
    }

    if(children)
        tans += children-1;
    cerr << v << ' ' << tans << ' ' << children << endl;
    ans[v] = tans;
}

int main()
{
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int s = 0;
    dfs0(0);

    for(int i = 0; i < n; i++){
        if(dist[i] > dist[s]) s = i;
    }

    dfs(s);

    for(int i = 0; i < n; i++)
        cerr << ans[i] << ' ';
    cerr << endl;

    cout << ans[s]+1;
	return 0;
}


Measured memory_bytes: 18688