akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

int next(int u){
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if(M[u][v] == 1) return v;
	}
	return -1;
}

void dfs_visit(int r) {
    for(int i = 0; i < n; i++) {
        nt[i] = 0;
	}
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;
	while(!S.empty()) {
		int u = S.top();
		int v = next(u);
		if(v != -1) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v); 	
			}
		} else {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	tt = 0;	
	for(int u = 0; u < n; u++) {
		if(color[u] == WHITE) dfs_visit(u);
	}
	for(int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;	
	}
}

int main() {
	int k , u, v;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
	    u--;
	    for(int i = 0; i < k; i++) {
	        cin >> v;
	        v--;
		   M[u][v] = 1; 
     	}
	} 
	
	dfs();
	
	return 0;
}

Measured memory_bytes: 3116
// combinatorics, overcounting then fixing, modular inverse
// https://atcoder.jp/contests/dp/tasks/dp_y

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ii = pair<int, int>;
#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

const ll mod = 1000000007;
struct Mod {
  ll x;
  Mod(ll xx = 0) : x(xx % mod) {}
  Mod operator+(Mod b) const { return Mod((x + b.x) % mod); }
  Mod operator-(Mod b) const { return Mod((x - b.x + mod) % mod); }
  Mod operator*(Mod b) const { return Mod((x * b.x) % mod); }
  Mod operator/(Mod b) const { return *this * (b ^ (mod - 2)); }
  Mod operator ^ (ll p) const {
    Mod acc{1}, pwr = *this;
    while (p) {
      if (p & 1) acc = acc * pwr;
      pwr = pwr * pwr;
      p /= 2;
    }
    return acc;
  }
};

const int MAXN = 3001;
const int MAXR = 100000;
Mod dp[MAXN + 5];
Mod fac[2 * MAXR + 5];
void precompute(int n) {
  fac[0] = 1;
  rep(i, 1, n + 1) fac[i] = fac[i - 1] * Mod(i);
}
Mod nck(int n, int k) {return fac[n] / (fac[n - k] * fac[k]);}
Mod ways(int dx, int dy){return nck(dx + dy, dy);}

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

  int r, c, n;
  cin >> r >> c >> n;
  precompute(r + c);
  vector<ii> a(n);
  trav(i, a) cin >> i.first >> i.second;
  sort(all(a), [](auto u, auto v){return u.first + u.second < v.first + v.second;});
  a.PB({r, c});
  auto precedes = [&](int i, int j){return a[i].first <= a[j].first and a[i].second <= a[j].second;};
  rep(i, 0, sz(a)) {
    dp[i] = ways(a[i].first - 1, a[i].second - 1);
    auto overcnt = Mod{};
    rep(j, 0, sz(a)) {
      if (!precedes(j, i) or i == j) continue;
      auto ways_ij = ways(a[i].first - a[j].first, a[i].second - a[j].second);
      overcnt = overcnt + dp[j] * ways_ij;
    }
    dp[i] = dp[i] - overcnt;
  }
  cout << dp[n].x << '\n';
}


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

int n[500010],len,s,ans;
char ch[500010];

void work()
{
	scanf("%s",ch),len=strlen(ch);
	for (int i=1; i<=len; i++)  n[i]=(ch[len-i]-'0')*9;
	for (int i=1; i<=len||n[i]; i++)  n[i+1]+=n[i]/10,s+=n[i]%=10;
	while (s>9*ans)
		{
			ans++,s+=9,n[1]+=9;
			for (int i=1; n[i]>9; n[i]-=10,n[++i]++,s-=9);
		}
	printf("%d",ans);
}

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


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 3e3+7;
const int inf = 1e9+9;

ll dp[lim][lim][2];
vector<int> a;

ll solve(int i, int j, int t){

    if(i>j) return 0;

    if(dp[i][j][t]!=-1) return dp[i][j][t];
    if(t){
        dp[i][j][1] = max(a[i]+solve(i+1,j,0), a[j]+solve(i,j-1,0));
    }
    else{
        dp[i][j][0] = min(-a[i]+solve(i+1,j,1), -a[j]+solve(i,j-1,1));
    }
    return dp[i][j][t];
}


void init(){
    for(int i=0;i<lim;i++){
        for(int j=0;j<lim;j++){
            dp[i][j][0]=-1;
            dp[i][j][1]=-1;
        }
    }
}


int main(){
    init();
    int n;
    cin>>n;
    a.resize(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    cout<<solve(0,n-1,1);
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define SUBL freopen("/home/ajinkya/Desktop/input.txt","r",stdin); freopen("/home/ajinkya/Desktop/output.txt","w",stdout); 
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;




int main()
{
    fastio 
    // SUBL
  	int n;
  	cin >> n;
  	int a[n+1];
  	bool is[n+1]={};
  	FI(i,1,n) cin >> a[i];
  	FI(i,1,n) 
  	{
  		if(a[i]==i) continue;
  		if(!is[i] && !is[is[i]])
  		{
  			is[i] = is[is[i]] = true;
  			swap(a[i],a[a[i]]);
  			if(a[i]!=i)
  			{
  				cout << "NO";
  				return 0;
  			}
  		}
  		else 
  		{
  			cout << "NO";
  			return 0;
  		}
  	}
  	// FI(i,0,n-1) 
  	// {
  	// 	if(a[i]!=b[i])
  	// 	{
  	// 		cout << "NO";
  	// 		return 0;
  	// 	}
  	// }
  	cout << "YES";
    return 0;
}         	

Measured memory_bytes: 256
N,K,Q=map(int, input().split())
A=[int(input()) for i in range(Q)]
from collections import Counter
A=Counter(A)
B=list(A.most_common())
#B.sort(key=lambda x:x[0])
C = [0]*N
for i in B:
  C[i[0]-1]=i[1]
for i in range(N):
  if (Q - C[i])< K:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 15820
n, k = map(int, input().split())
a = list(map(int, input().split()))

top = max(a)
bottom = 0

while (top - bottom) > 1:
    mid = (top + bottom) // 2
    div_n = lambda a: (a + mid - 1) // mid - 1
    cnt = sum(map(div_n, a))
    if cnt <= k:
        top = mid
    else:
        bottom = mid

print(top)

Measured memory_bytes: 30844
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    std::ios_base::sync_with_stdio(false); std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(12);
    return true;
}();

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

void solve() {
    cini(n);
    vs ans={ "pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon" };
    n%=10;
    cout<<ans[n]<<endl;
}

signed main() {
    solve();
}

// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3644
// =====================================================================
// macros
// =====================================================================

/// input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            #[allow(unused_mut)]
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/// yet another input macro from https://qiita.com/hatoo@github/items/fa14ad36a1b568d14f3e
#[allow(unused_macros)]
macro_rules! inputln {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

// =====================================================================
// functions
// =====================================================================

fn main() {
    input!{
        n: usize,
        k: usize,
        h: [usize; n]
    }
    h.sort_by(|a,b| b.cmp(a));
    let mut sum:usize= 0;
    for i in k..n{
        if let Some(hi) = h.get(i) {
            sum+=*hi;
        }
    }
    println!("{}",sum.to_string());
}


Measured memory_bytes: 9464
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
VV(pii) vv;
vint v;
int n;
int foo(int a,int b){
	// cout<<a<<" "<<b<<endl;
	if(v[a]>0){
		return b;
	}
	int tmp=0;
	rep(i,vv[a].size()){
		tmp+=foo(vv[a][i].F,vv[a][i].S);
	}
	// cout<<a<<" "<<tmp<<endl;
	tmp=min(tmp,b);
	return tmp;
}
void mainmain(){
	// int n;
	cin>>n;
	vv=VV(pii)(n);
	v=vint(n);
	rep(i,n-1){
		cin>>v[i+1];
	}
	rep(i,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		vv[a].PB(pii(b,c));
	}
	int ans=0;
	rep(i,vv[0].size()){
		ans+=foo(vv[0][i].F,vv[0][i].S);
	}
	cout<<ans<<endl;
}


signed main() {
	ios_base::sync_with_stdio(false);
  	cout<<fixed<<setprecision(0);
    mainmain();
}

Measured memory_bytes: 1248
while True:
    N = int(input())
    if N == 0:
        exit()
    L = [list(map(int,input().replace(':','').split())) for _ in range(N)]
    T = [0]*240002
    for l in L:
        T[l[0]] += 1
        T[l[1]] -= 1
    for i in range(240002):
        if i > 0:
            T[i] += T[i-1]
    print(max(T))


Measured memory_bytes: 20112
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean a = false;
        soto: for(int i = 0; i <= n/4; i++){
            for(int j = 0; j <= n/7; j++){
                int k = 4*i+7*j;
                if (k == n) {
                    a = true;
                    System.out.println("Yes");
                    break soto;
                }
            }
        }
        if (a == false) {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
fun main(args: Array<String>) {
  val MOD = (1e9 + 7).toLong()
  val (n, c) = readLine()!!.split(" ").map { it.toInt() }
  val a = readLine()!!.split(" ").map { it.toInt() }
  val b = readLine()!!.split(" ").map { it.toInt() }
  var h = Array(c + 1) { LongArray(401) { 1L } }
  for (p in 1..c) {
    for (x in 1..400) {
      h[p][x] = h[p - 1][x] * x
      h[p][x] %= MOD
    }
  }
  var g = Array(n) { LongArray(c + 1) { 0L } }
  for (i in 0 until n) {
    for (p in 0..c) {
      for (x in a[i]..b[i]) {
        g[i][p] += h[p][x]
        g[i][p] %= MOD
      }
    }
  }
  var dp = Array(n + 1) { LongArray(c + 1) { 0L } }
  dp[0][0] = 1L
  for (i in 0 until n) {
    for (j in 0..c) {
      for (p in 0..j) {
        dp[i + 1][j] += dp[i][j - p] * g[i][p]
        dp[i + 1][j] %= MOD
      }
    }
  }
  println(dp[n][c])
}


Measured memory_bytes: 41524
# A - 1D Matching
def calculate_cables_length(x: int, y: int, total: int) -> tuple:
    MOD = 10 ** 9 + 7
    if y:
        total = (total * y) % MOD
        y -= 1
    else:
        x += 1
    return x, y, total


def main():
    # sort A, B and the lines between A, B shouldn't cross
    # cross <-> not min distance
    N, *AB = map(int, open(0))
    C = [(i, 1) for i in AB[:N]] + [(i, 0) for i in AB[N:]]
    C.sort()
    ans, a, b = 1, 0, 0
    for i, t in C:
        if t:  # laptop
            a, b, ans = calculate_cables_length(a, b, ans)
        else:  # power sources
            b, a, ans = calculate_cables_length(b, a, ans)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27784
#include <math.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

using ll = long long;

int N, K;
int INF = 1 << 15;

int dfs(int n, int cnt) {
    if (n == N) {
        return cnt;
    }

    int ret = INF;

    ret = min(ret, dfs(n + 1, 2 * cnt));
    ret = min(ret, dfs(n + 1, cnt + K));

    return ret;
}

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

    cout << dfs(0, 1) << endl;

    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, s, k, t, q, ans, sum, last, a[100000], dp[2001][2001];
bool f[101][101];
struct Edge { LL cost,to; };
string str,ss;
LL POw(LL x,LL y) {
	LL AA = 1;
	rep(i, y)AA *= x;
	return AA;
}
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	m = n;
	while (m>0) {
		ans += m % 10;
		m /= 10;
		k++;
	}
	m = POw(10, k);
	m -= 1;
	for (int j = 0; j < 10;j++) {
		rep(i, k) {
			LL BB = m;
			if (BB - POw(10, i)*j < n)
				ans = max(ans, k * 9 - j);
		}
	}
	cout << ans << endl;
	return 0;
}


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

ll A[123456];

int main() {
    ll n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        int a, b;
        cin >> a >> b;
        A[a] += b;
    }

    for(int i = 1; i <= 100000; ++i) A[i] += A[i - 1];
    for(int i = 1; i <= 100000; ++i) if(A[i] >= k) return !printf("%d\n", i);
}

Measured memory_bytes: 1024
import sys
a,b,m = map(int,input().split())
ai = list(map(int,input().split()))
bj = list(map(int,input().split()))
#xyc =[]
#for i in range(m):
#    xyc.append(list(map(int,input().split())))
an = min(ai)+min(bj)
for i in range(m):
    x,y,c = map(int,input().split())
    an = min(an,ai[x-1]+bj[y-1]-c)
print(an)

Measured memory_bytes: 18612
#include "bits/stdc++.h"
#define int long long

using namespace std;

signed main() {
    int A, B;
    cin >> A >> B;
    for(auto i = B * 10; i < (B + 1) * 10; i++) {
        if(i * 8 / 100 == A) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

int main(){
  int n,a;
  cin >> n;
  cin >> a;
  int b;
  b = n % 500;
  if(b <= a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
def sum_digit(num):
    sums = 0
    while num != 0:
        sums += num % 10
        num //= 10
    return sums

n = int(input())
min_ans = 9 * 4
for i in range(1, n):
    ans = sum_digit(i) + sum_digit(n - i)
    if min_ans > ans:
        min_ans = ans
print(min_ans)


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

using namespace std;

int main(void){
  int A,B;
  cin >> A >> B;
  if( A%3==0 || B%3==0 || (A+B)%3==0 ){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}

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

const int Maxn = 2005;

int n, m;
char B[Maxn][Maxn];
int R[Maxn][Maxn], C[Maxn][Maxn];
int my[Maxn][Maxn];
int res;

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%s", B[i]);
        for (int j = 0; j < m; j++)
            if (B[i][j] == '#') R[i][j] = C[i][j] = 0;
            else {
                R[i][j] = 1 + (j > 0? R[i][j - 1]: 0);
                C[i][j] = 1 + (i > 0? C[i - 1][j]: 0);
                my[i][j] = R[i][j] + C[i][j] - 2;
            }
    }
    for (int i = n - 1; i >= 0; i--)
        for (int j = m - 1; j >= 0; j--)
            if (B[i][j] == '#') R[i][j] = C[i][j] = 0;
            else {
                R[i][j] = 1 + (j + 1 < m? R[i][j + 1]: 0);
                C[i][j] = 1 + (i + 1 < n? C[i + 1][j]: 0);
                my[i][j] += R[i][j] + C[i][j] - 1;
                res = max(res, my[i][j]);
            }
    printf("%d\n", res);
    return 0;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int n, ans1 = 0, ans2 = 0;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            ans1++;
            if (a % 3 == 0 || a % 5 == 0)
                ans2++;
        }
    }
    if (ans1 == ans2)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
deque<int>q;
int mn[100100],K;
int bfs(){
	memset(mn,0x3f3f3f3f,sizeof(mn));
	mn[1]=1,q.push_back(1);
	while(true){
		int x=q.front();q.pop_front();
		if(!x)return mn[x];
		if(mn[(x*10)%K]>mn[x])mn[(x*10)%K]=mn[x],q.push_front((x*10)%K);
		if(mn[(x+1)%K]>mn[x]+1)mn[(x+1)%K]=mn[x]+1,q.push_back((x+1)%K);
	}
}
int main(){
	scanf("%d",&K);
	printf("%d\n",bfs());
	return 0;
} 

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

typedef long long ll;
using namespace std;
int main()
{
  ll a,b;
  cin>>a>>b;
  cout<<a*b-(b+a-1)<<endl;
  return 0;
}


Measured memory_bytes: 3580
#include <fstream>
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>

using namespace std;
#define ALL(c) (c).begin(), (c).end()
#define REP(i,n) for(ll i=0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;

struct union_find{
	vl v;
	union_find(ll n) : v(n, -1){}
	ll find(ll x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
	void unite(ll x, ll y){
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y];
		v[y] = x;
	}
	bool same(ll x, ll y){
		return find(x) == find(y);
	}
	ll size(ll x) { return -v[find(x)]; }
};

int main(){
#ifdef _WIN32
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cout << fixed << setprecision(8);

	ll n, m; cin >> n >> m;
	vl a(m), b(m);
	REP(i, m) cin >> a[i] >> b[i];

	union_find uf(n);
	REP(i, m) uf.unite(a[i]-1, b[i]-1);
	
	ll cntm = 0;
	ll cnts = 0;
	REP(i, n){
		if (uf.size(i) == 1){
			cntm++;
		}
		else{
			if (uf.find(i) == i){
				cnts++;
			}
		}
	}

	cout << abs(cntm - cnts) << endl;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 1e5 + 1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL0 {printf("0\n"); return 0;}
#define FAIL1 {printf("-1\n"); return 0;}
#define FAILNO {printf("NO\n"); return 0;}

int N;
char S[MAXN];
char st[MAXN];
int t = -1;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //scanf("%d", &N);
    scanf("%s", S);
    N = strlen(S);
    
    int removed = 0;
    for (int i = 0; i < N; i++) {
        if (t == -1) {
            st[++t] = S[i];
        } else {
            char c = st[t];
            if (c != S[i]) {
                removed += 2;
                t--;
            } else {
                st[++t] = S[i];
            }
        }
    }

    printf("%d", removed);

    printf("\n");
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> cum(n + 1, 0), cumA(n + 1, 0), cumC(n + 1, 0);
    for(int i = 0; i < n; i++) {
        cum[i + 1] = cum[i] + (s[i] == '?');
        cumA[i + 1] = cumA[i] + (s[i] == 'A');
        cumC[i + 1] = cumC[i] + (s[i] == 'C');
    }
    ll ans = 0;
    for(int i = 1; i < n - 1; i++) {
        if(s[i] == 'A' || s[i] == 'C') {
            continue;
        }
        ll tmp = 0;
        ll a = cumA[i];
        ll c = cumC[n] - cumC[i + 1];
        ll l = cum[i];
        ll r = cum[n] - cum[i + 1];
        //(ABC)を作る
        tmp += ((a * c) % MOD) * modpow(3, l + r);
        tmp %= MOD;
        //(AB?)を作る
        tmp += ((a * r) % MOD) * modpow(3, l + r - 1);
        tmp %= MOD;
        //(?BC)を作る
        tmp += ((l * c) % MOD) * modpow(3, l + r - 1);
        tmp %= MOD;
        //(?B?)を作る
        tmp += ((l * r) % MOD) * modpow(3, l + r - 2);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;
}


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

int main(){
	map<char, int> m;
	string s;
	while(cin >> s){
		for(char c:s) m[c]++;
	}
	for(char a = 'a', A = 'A'; a <= 'z'; a++, A++){
		cout << a << " : " << m[a] + m[A] << endl;
	}
}

Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int[] kk = new int[n];
		for(int i=0;i<n;i++) {
			h[i] = sc.nextInt();
			kk[i] = 0;
		}
		boolean f = true;
		for(int i=0;i<n-1;i++) {
			if(h[i+1]-h[i]>0) {
				h[i+1]--;
				kk[i+1]=1;
			}
			if(h[i]>h[i+1]) {
				if(h[i]-h[i+1]==1 && kk[i] ==0) {
					//OK
					kk[i+1]=1;
				}else {
					f=false;
					break;
				}
			}
			if(h[i]==h[i+1]) {
				kk[i+1]=1;
			}
		}
		if(f) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 60264
import math
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]


def explode(x):
    global n
    c=0
    for i in range(n):
        if h[i]-x*b>0:
            c+=math.ceil((h[i]-x*b)/(a-b))
    return c<=x

l,r=1,10**9
while l+1<r:
    k=(l+r)//2
    if explode(k):
        r=k
    else:
        l=k

print(l if explode(l) else r)


Measured memory_bytes: 7088
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MAX_V 10000000
#define INF 100000000

int dp[100000] = {0};

struct edge{
    int to;
    int cost;
};

int solve(vector<vector<edge> >& tree, int from, int count){
    if(dp[from] != 0){
        return dp[from];
    }else if(tree[from].size() == 0){
        return 0;
    }else{
    int res = 0;
    for(int i = 0; i < tree[from].size(); i++){
        res = max(res, solve(tree, tree[from][i].to, count)+1);
    }
    return dp[from] = res;
    }
}


int main(){
    int n, m; cin >> n >> m;
    vector<vector<edge> > tree(n);
    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        edge e = {y-1, 0};
        tree[x-1].push_back(e);
    }
    for(int i = 0; i < n; i++){
        solve(tree, i, 0);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, dp[i]);
    }
    /*for(int i = 0; i < n; i++){
        cout << dp[i] << endl;
    }*/
    cout << ans << endl;
}

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

#define INF (1<<30);

int dp[1000001][2];
// [下から何番目のケタか][いっこ上のケタに1枚払ってもらう？　1:0]

int main(){
	string s;	cin>>s;
	reverse(s.begin(), s.end());

	int n=s.length(), ans=0;

	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++) dp[i][j]=INF;
	}
	dp[0][0]=0;

	for(int i=0;i<n;i++){
		int D=s[i]-'0';
		dp[i+1][0] = D + min(dp[i][0], dp[i][1]+1);

		dp[i+1][1] = (10-D) + min(dp[i][0], dp[i][1]-1);
	}

	
	ans=min(dp[n][0], dp[n][1]+1);
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 9220
#include <stdio.h>

int main() {
  int N, K, Q;
  scanf("%d %d %d",&N,&K,&Q);
  int A[N];
  for (int i = 0; i < N; i++) {
    A[i] = Q;
  }
  for (int i = 0; i < Q; i++) {
    int tmp;
    scanf("%d",&tmp);
    A[tmp-1] -= 1;
  }
  
  for (int i = 0; i < N; i++) {
    int tmp = K - A[i];
    if (tmp > 0) printf("Yes\n");
    else if (tmp <= 0) printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 896
import math
from functools import reduce


n = int(input())
tt = [int(input()) for i in range(n)]

x = 1

def lcm_base(x,y):
  return (x*y) // math.gcd(x,y)
def lcm(*numbers):
  return reduce(lcm_base, numbers, 1)

print(lcm(*tt))

Measured memory_bytes: 9456
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){ int sz = a.size();
for(int i=0;i<a.size();i++)cout << a[i] << (i < sz-1 ? ' ' : '\n'); }
void ioboost(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}
///////////////////////////////////////////////////////////

int main(void){
  ioboost();

  string s;cin >> s;
  char x = s[s.size()-1];
  if(x == '2'||x == '4'||x=='5'||x=='7'||x=='9'||x=='5'){
    cout << "hon" << '\n';
  }else if(x == '3'){
    cout << "bon" << '\n';
  }else cout << "pon" << '\n';
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int p=n%10;
  if(p==2||p==4||p==5||p==7||p==9)
    cout<<"hon"<<endl;
  else if(p==0||p==1||p==6||p==8)
    cout<<"pon"<<endl;
  else
    cout<<"bon"<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  string s;
  cin>>s;
  int start0=0,start1=0;
  rep(i,s.size()){
    if(s[i]=='0') i%2==0 ? start1++ : start0++;
    if(s[i]=='1') i%2==0 ? start0++ : start1++;
  }
  cout<<min(start0,start1)<<endl;
}


Measured memory_bytes: 512
import sys

MOD = 2019

def solve(L, R):
    ans = 2019
    for i in range(L, R+1):
        for j in range(i+1, R+1):
            ij = i*j%MOD
            if ij == 0:
                print(0)
                return
            if ij < ans:
                ans = ij
    print(ans)

def main():
    L, R = map(int, input().split())
    solve(L, R)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        s: chars,
    }
    let mut ans: u64 = 0;
    for bit in 0..1 << (s.len() - 1) {
        let mut tmp = String::new();
        tmp.push(s[0]);
        let mut tmp_num = 0;
        for i in 0..s.len() - 1 {
            if bit & 1 << i != 0 {
                tmp_num += tmp.parse::<u64>().unwrap();
                tmp = String::new();
            }
            tmp.push(s[i + 1]);
        }
        tmp_num += tmp.parse::<u64>().unwrap();
        ans += tmp_num;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int lh=n%100;
    int fh=n/100;
    bool mmyy=false,yymm=false;
    if(fh>=1 && fh<=12)
    mmyy=true;
    if(lh>=1 && lh<=12)
    yymm=true;
    if(mmyy && !yymm){
    	cout<<"MMYY";
	}
	else if(!mmyy && yymm){
		cout<<"YYMM";
	}
	else if(mmyy && yymm){
		cout<<"AMBIGUOUS";
	}
	else if(!mmyy && !yymm){
		cout<<"NA";
	}
	return 0;
}

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

void print(int A[], int n)
{
    for (int i = 0; i != n; ++i)
    {
        if (i > 0)
        {
            cout << " ";
        }

        cout << A[i];
    }

    cout << endl;
}

void insertionSort(int A[], int n)
{
    for (int i = 1; i != n; ++i)
    {
        int v = A[i],
            j = i - 1;

        while (j >= 0 && A[j] > v)
        {
            A[j+1] = A[j];
            --j;
        }

        A[j+1] = v;

        print(A, n);
    }
}

int main()
{
    int A[100], n;

    cin >> n;

    for (int i = 0; i != n; ++i)
    {
        cin >> A[i];
    }

    print(A, n);
    insertionSort(A, n);

    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

const int MAX = 100000;

int main(){
	int N;
	long long K, cnt[MAX+1] = {0};

	cin >> N >> K;

	for(int i = 0; i < N; i++){
		int a, b;
		cin >> a >> b;
		cnt[a] += b;
	}

	for(int i = 1; i <= MAX; i++){
		if(K <= cnt[i]){
			cout << i << endl;
			break;
		}
		K -=cnt[i];
	}

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	ll q,cnt=0;
	string s;
	getline(cin,s);
	vector<char> v;
	for(ll x=0;x<s.size();x++){
	    v.push_back(s[x]);
	}
	cin>>q;
	for(ll i =0;i<q;i++){
	    ll t,f;
	    char c;
	    cin>>t;
	    if(t==1){
	        cnt++;
	    }
	    else if (t==2){
	        cin>>f>>c;
	        if(f==1){
	            if(cnt%2==0)v.insert(v.begin(),c);
	            else v.push_back(c);
	        }
	        else if(f==2){
	            if(cnt%2)v.insert(v.begin(),c);
	            else v.push_back(c);
	        }
	    }
	}
	if(cnt%2==0){
	for(auto it = v.begin();it!=v.end();it++){
	    cout<<*it;
	}}
	else{
	  reverse(v.begin(),v.end());
	  for(auto it = v.begin();it!=v.end();it++){
	    cout<<*it;
	}
	}
	return 0;
}


Measured memory_bytes: 1272
def output(i):
    global outputlist
    global winnerlist
    global reported
    if outputlist[i]:
        return
    else:
        outputlist[i] = 1

    for each in winnerlist[i]:
        output(each)
    print(i+1)
    reported.append(i)


n = int(input())
m = int(input())

winnerlist = [[] for i in range(n+1)]
outputlist = [0]*n
reported = []

for i in range(m):
    winner, loser = map(int, input().split())
    winner -= 1
    loser -= 1
    winnerlist[loser].append(winner)

for i in range(n):
    output(i)

isnotunique = 0

for i in range(n-1):
    if not reported[i] in winnerlist[reported[i+1]]:
        isnotunique = 1
        break

print(isnotunique)

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

#import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
#from collections import deque, defaultdict, Counter
#from heapq import heappush, heappop
#from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
#from operator import itemgetter as ig

#sys.setrecursionlimit(10 ** 7)
#nf = 10 ** 20
#INF = float("INF")
#mod = 10 ** 9 + 7

'''
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]
# 深さ優先探索
def dfs(G, v):
    global time, first_order,seen,last_order
    time += 1
    first_order[v-1] = time   #　行きがけ

    seen[v-1] = True # v を訪問済みにする
    # v から行ける各頂点 next_v について
    for next_v in G[v]:
        if seen[next_v-1]:
            continue
        dfs(G, next_v)

    time += 1
    last_order[v - 1] = time  # 帰りがけ
'''

def main():

    def is_prime(n):
        if n == 1:
            return False
        for i in range(2, int(n**0.5)+1):
            if n % i == 0:
                return False
        return True

    Q = int(input())
    task = []
    m = 10**20
    M = 0
    for i in range(Q):
        task.append(list(map(int, input().split())))
        m = min(task[i][0], m)
        M = max(task[i][1], M)

    A = [0]
    count = 0
    for i in range(m, M+1):
        if i % 2 != 0:
            if is_prime((i+1)/2) == True and is_prime(i) == True:
                count += 1
                A.append(count)
            else:
                A.append(count)
        else:
            A.append(count)


    for i in range(Q):
        ans = A[task[i][1]-m +1] -A[task[i][0]-m]
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 93016
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pdi = pair<double, int>;

int N, K;
vector<int> a;

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

	}
	return 0;
}


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

int main(){
    int num;
    cin >> num;
    int sum = 0, max = 0;
    for (int i = 0; i < num;i++){
        int k;
        cin >> k;
        if (k <= max)
            sum += k;
        else{
            sum += max;
            max = k;
        }
    }
    if (sum > max)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x,y,ans;
int main(){
	scanf("%d%d",&x,&y);
	if(x==y&&x==1){
		printf("1000000");
	}else{
		if(x==1)ans+=300000;
		if(x==2)ans+=200000;
		if(x==3)ans+=100000;
		if(y==1)ans+=300000;
		if(y==2)ans+=200000;
		if(y==3)ans+=100000;
		printf("%d",ans);
	}
}

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

using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int a, b, c;
    ll temp_dp[3];
    ll dp[3];
    cin >> a >> b >> c;
    dp[0] = a;
    dp[1] = b;
    dp[2] = c;
    for (int i = 1; i < N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            temp_dp[j] = dp[j];
        }
        cin >> a >> b >> c;
        dp[0] = max(temp_dp[1], temp_dp[2]) + a;
        dp[1] = max(temp_dp[0], temp_dp[2]) + b;
        dp[2] = max(temp_dp[0], temp_dp[1]) + c;
    }
    cout << max(max(dp[0], dp[1]), dp[2]);
    // system("pause");
}

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

vector<int> to[2000005];
vector<int> ans;
void dfs(int v,int p=-1){
  for(int u : to[v]){
    if(u==p) continue;
    ans.at(u) += ans.at(v);
    dfs(u,v);
  }
}

int main(){
  int n,q;
  cin >> n >> q;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  for(int i=0;i<q;i++){
    int p,x;
    cin >> p >> x;
    p--;
    ans.at(p)+=x;
  }
  dfs(0);
  for(int i=0;i<n;i++){
    cout << ans.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 68736
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;

int div(int x) {
	int cnt = 0;
	for (int i = 1; i <= x;i++) {
		if (x % i == 0)cnt++;
	}
	return cnt;
}
bool prime(long long int x) {
	for (int i = 2; i <= sqrt(x) ;  i++) {
		if (x % i == 0)return 0;
	}
	return 1;

}

long long int divi(long long int n,long long int p) {
	int cn = 0;
	int q = p;
	while (n / q != 0) {
		cn += n / q;
		q = q * p;
	}
	return cn;
}

int main() {
	long long int n;
	int cnt = 0;
	long long int ans = 1;
	cin >> n;
	vector<int> p(n);
	vector<int> a(n);

	for (int i = 2; i <= n; i++) {
		if (prime(i) == 1) {
			p.at(cnt) = i;
			cnt++;
		}
	}
	//for (int i = 0; i < cnt; i++)cout << p.at(i) << endl;

	for (int i = 0; i < cnt; i++) {
		a.at(i) = divi(n, p.at(i));
	}


	for (int i = 0; i < cnt; i++) {
		ans =(ans%MOD) * (a.at(i)+1)%MOD;
	}
	
	cout << ans%MOD << endl;


	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n;
  cin >> n;
  rep(i,n+100){
    int x = double(i) * 1.08;
    if(x == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.to_i
end

N = attrs.shift
A = attrs
m = A.max
mc = A.count(m)
for n in 0..(N - 1) do
  if mc > 1 then
    puts m
  else
    if A[n] == m then
      tmp = (A.clone)
      tmp[n] = -1
      puts tmp.max
    else
      puts m
    end
  end
end

Measured memory_bytes: 7476
h,w=map(int,input().split())
li=[list(input()) for i in range(h)]
yoko=[[1,0],[-1,0],[0,1],[0,-1]]
import itertools
for i in range(h):
  for j in range(w):
    if li[i][j]=="#":
      flag=0
      for za in yoko:
        dx=za[0]
        dy=za[1]
        if h>i+dx>=0 and w>j+dy>=0:
          if li[i+dx][j+dy]=="#":
            flag+=1
      if flag==0:
        print("No")
        exit()
print("Yes")

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

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=1e6+10, maxm=5e4+10, lg=21, mod=1e9+7, inf=1e18;

ll n,fac[maxn],inv[maxn],cc[maxn];
ll pwm(ll a,ll b){if(b==0)return 1;if(b%2)return a*pwm(a,b-1)%mod;ll ret=pwm(a,b/2);return ret*ret%mod;}
ll C(ll n,ll r){return fac[n]*inv[r]%mod*inv[n-r]%mod;}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	fac[0]=inv[0]=1; for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod, inv[i]=pwm(fac[i],mod-2);
	cin>>n;
	ll ans=0;
	for(int k=(n+1)/2;k<n;k++){
		cc[k]=fac[k]*fac[n-1-k]%mod*C(k-1,n-1-k)%mod;
		ans+=k*(cc[k]-cc[k-1]+mod)%mod, ans%=mod;
	}
	cout<<ans;
	
	return 0;
}



 


Measured memory_bytes: 23180
#include <cstdio>
 
int main() {
  int n;
  scanf("%d", &n);
  int s[n];
  for (int i = 0; i < n; ++i)
    scanf("%d", &s[i]);
 
  int q;
  scanf("%d", &q);
  int t[q];
  for (int i = 0; i < q; ++i)
    scanf("%d", &t[i]);
 
  int c = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < q; ++j)
      if (s[i] == t[j]) {
        ++c;
        t[j] = t[q - 1];
        --q;
      }
  }
 
  printf("%d\n", c);
}

Measured memory_bytes: 2756
using System;
using System.Linq;

namespace AtCoderBeginnerContest097
{
    class ABC097B
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            int N = (int)Math.Sqrt(X);
            int max = 1;
            for (int i = 2; i <= N; i++)
            {
                int M = (int)Math.Log((double)X+0.1, (double)i);
                int l = (int)Math.Pow((double)i, (double)M);
                if (max < l) max = l;
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 11476
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int n = scanner.nextInt();
        long result = factorial(n);
        System.out.println(result);
    }
    
    public static long factorial(int n) {
        if (n == 0) {
            return 1;
        } 
        return n * factorial(n-1);
    }
}

Measured memory_bytes: 17176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    int p=max(a,max(b,max(c,max(d,e))));
    int q=min(a,min(b,min(c,min(d,e))));
    int r=p-q;
    if(r<=k)
        cout<<"Yay!"<<endl;
    else
        cout<<":("<<endl;
return 0;
}


Measured memory_bytes: 256