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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        boolean overflow = false;
        long value = 1;
        long threshold = 1000000000;
        threshold *= 1000000000;
        for(int i=0; i<n; i++) {
            long a = in.nextLong();
            double logv = Math.log10(value);
            double loga = Math.log10(a);
            double logsum = logv + loga;
            if(logsum > 18.0) {
                overflow = true;
            }
            else if(value * a > threshold) {
                overflow = true;
            }
            if(a == 0) {
                overflow = false;
            }
            value = value * a;
        }
        System.out.println(overflow ? -1 : value);
    }
}


Measured memory_bytes: 59816
//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 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 run() {
    input! {
        h: usize,
        w: usize,
        s: [chars; h],
    }
    let mut dp = vec![vec![h * w; w]; h];
    let mut q = std::collections::VecDeque::new();
    for i in 0..h {
        for j in 0..w {
            if s[i][j] == '#' {
                dp[i][j] = 0;
                q.push_back((i, j));
            }
        }
    }
    while let Some((x, y)) = q.pop_front() {
        const DIR: [i32; 4] = [0, 1, 0, -1];
        for k in 0..4 {
            let i = (DIR[k] + x as i32) as usize;
            let j = (DIR[k ^ 1] + y as i32) as usize;
            if i < h && j < w && dp[i][j] > dp[x][y] + 1 {
                dp[i][j] = dp[x][y] + 1;
                q.push_back((i, j));
            }
        }
    }
    let mut ans = 0;
    for i in 0..h {
        ans = std::cmp::max(ans, *dp[i].iter().max().unwrap());
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 33524
n = int(input())
a = list(int(i) for i in input().split())

ans = "APPROVED"
for i in range(n):
    if ans =="APPROVED":
        if a[i]%2 == 0:
            b = a[i]%3
            c = a[i]%5
            if b == 0 or c == 0:
                ans = "APPROVED"
            else: 
                ans = "DENIED"
    else:
        ans = "DENIED"
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	string S;
	cin >> S;
	
	int cnt[3];
	for(int i=0;i<3;i++) cnt[i] = 0;
	
	for(int i=0;i<S.length();i++) cnt[S[i] - 'a']++;
	
	sort(cnt, cnt + 3);
	
	//cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
	
	if(cnt[0] == cnt[1] && cnt[1] == cnt[2]){
		cout << "YES" << endl;
		return 0;
	}
	if(cnt[0] == cnt[1] && cnt[1] == cnt[2] - 1){
		cout << "YES" << endl;
		return 0;
	}
	if(cnt[0] == cnt[1] - 1 && cnt[1] == cnt[2]){
		cout << "YES" << endl;
		return 0;
	}
	
	cout << "NO" << endl;
	
    return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] d = new int[n];

        for (int i = 0; i < n; i++) {
            d[i] = sc.nextInt();
        }

        long ans = 0;
        for (int i = 0; i < n-1; i++) {
            for (int j = i+1; j < n; j++) {
                ans += d[i] * d[j];
            }
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 21332
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
from collections import deque
import re

S=input()
T = input()

snum = len(S)
tnum = len(T)

m = tnum

for start in range(snum - tnum + 1):
    diff = 0
    for i in range(tnum):
        if S[start+i] != T[i]:
            diff += 1
    m = min(m, diff)

print(m)


Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

#define MAX_V 100010

struct edge { int to; ll cost; };
int V;

vector<edge> tree[MAX_V];
long long d[MAX_V];
int N;

// s: 開始地点の頂点
void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + N, LINF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) { continue; }
        for (int i = 0; i < tree[v].size(); i++) {
            edge e = tree[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}


int main(){
    cin >> N;

    rep(i, N - 1){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back(edge{b, c});
        tree[b].push_back(edge{a, c});
    }

    int Q, K;
    cin >> Q >> K;
    vector<ll> ans;

    dijkstra(K-1);

    rep(i, Q){
        int x, y;
        cin >> x >> y;
        x--, y--;
        ans.push_back(d[x] + d[y]);
    }

    rep(i, Q) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s, t;
  cin >> s >> t;
  if (s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
import itertools
import bisect
from operator import itemgetter
 
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
def combi(n, r):
  r = min(r, n-r)
  numer = denom = 1
  for i in range(1, r+1):
    numer = numer * (n+1-i) %mod
    denom = denom * i %mod
  return numer * pow(denom, mod-2, mod) %mod

N = I()
n = N/3

print(n**3)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 998244353
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 104
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,par[mx];
long long a[mx],g[mx][mx];
bool bfs(){
	bool sudah[104];
	queue<int>q;
	reset(sudah,false);
	reset(par,0);
	q.push(0);
	sudah[0]=true;
	while(!q.empty()){
		int now=q.front();
		q.pop();
	//	cout<<par[now]<<" -> "<<now<<endl;
		for(int i=0;i<=n+1;i++){
			if(!sudah[i] && g[now][i]>0){
				q.push(i);
				par[i]=now;
				sudah[i]=true;
			}
		}
	}
	return sudah[n+1];
}

long long MF(){
	long long ret=0;
	while(bfs()){
		int now=n+1;
		long long BN=1e15;
		while(now!=0){
			BN=min(BN,g[par[now]][now]);
	//		cout<<par[now]<<" -> "<<now<<" "<<g[par[now]][now]<<endl;
			now=par[now];
		}
	//	debug(BN);
		now=n+1;
		while(now!=0){
			g[par[now]][now]-=BN;
			g[now][par[now]]+=BN;
			now=par[now];
		}
		ret+=BN;
	}
	return ret;
}

int main(){
	cin>>n;
	long long jaw=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]>0)g[i][n+1]=a[i],jaw+=a[i];
		if(a[i]<0)g[0][i]=-a[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=i*2;j<=n;j+=i){
			g[i][j]=1e15;
		}
	}
	cout<<jaw-MF()<<endl;
}




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

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 n: u64 = read();
    let m: u64 = read();
    let mut odd_only = 1;
    let mut even_only = 1;
    if n != 1 && n != 0 {
        let mut p1 = 1;
        let mut p2 = 1;
        let mut cn = n;
        while cn > n-2 {
            p1 *= cn;
            cn -= 1;
        }
        even_only = p1 / 2;
    } else {
        even_only = 0;
    }


    if m != 1 && m != 0 {
        let mut p1 = 1;
        let mut cn = m;
        while cn > m-2 {
            p1 *= cn;
            cn -= 1;
        }
        odd_only = p1 / 2;
    } else {
        odd_only = 0;
    }
    println!("{}", even_only+odd_only);
}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int N, K;
    cin >> N >> K;
    vector<bool> have(N, false);
    for(int i = 0; i < K; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int A;
            cin >> A;
            have[A -1] = true;
        }
    }
    int count = 0;
    for(int i = 0; i < N; i++){
        if(!have[i]){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
    int a, b, c;
    char buf[256];
    fgets(buf, 256, stdin);
    buf[255] = '\0';
    sscanf(buf, "%d %d %d", &a, &b, &c);

    a = a - b;
    b = b - c;
    if (!a || !b)
        printf("No\n");
    else
        if ((a & 0x80000000) && (b & 0x80000000))
            printf("Yes\n");
        else
            printf("No\n");
    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ll long long int
#define fin for(i=0;i<n;i++)
#define vec vector<ll>
#define pb push_back
#define vecit vector<ll>::iterator
#define vecp vector<pair<ll,ll> >
#define vecpit vector<pair<ll,ll> >::iterator
#define mapp map<ll,ll>
#define mapr map<ll,pair<ll,ll> >
#define maprit map<ll,pair<ll,ll> >::iterator
#define mapit map<ll,ll>::iterator
#define mod1 1000000007
#define INF 1000000000000
using namespace std;
int main()
{
    ll n;
    cin>>n;
     ll i,k,j,l;
     ll map1[n+1][4];
     map1[0][1]=0;
     map1[0][2]=0;
     map1[0][3]=0;

     for(i=1;i<=n;i++)
     {
         cin>>j>>k>>l;
         map1[i][1]=j+max(map1[i-1][2],map1[i-1][3]);
         map1[i][2]=k+max(map1[i-1][1],map1[i-1][3]);
         map1[i][3]=l+max(map1[i-1][2],map1[i-1][1]);
     }
     cout<<max(max(map1[i-1][1],map1[i-1][2]),map1[i-1][3]);
}



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

X, N = map(int, input().split())
p = list(map(int, input().split()))
st = set(p)
for i in range(X+1):
    if X - i not in st:
        print(X - i)
        break
    if X + i not in st:
        print(X + i)
        break


Measured memory_bytes: 61980
#include<stdio.h>
#include<iostream>
#include<math.h>

using namespace std;


int main(){
	int A,B,H,M;
	cin >>A>>B>>H>>M;
	double t;
	t=2.0*acos(-1.0)*fabs((double)H/12.0-(double)M*11.0/720.0);
	double d =sqrt((double)A*(double)A+(double)B*(double)B-2.0*(double)A*(double)B*cos(t));
	printf("%.10f\n",d);
	return 0;
}

Measured memory_bytes: 4132
#!/usr/bin/env python3
# coding: utf-8
"""
about module
"""


def main():
    n, k = map(int, input().split())
    if n > k:
        n = n % k

    while n * 2 > k:
        n = abs(n - k)
    return n


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 2940
d = int(input())
c = list(map(int,input().split()))
cmax = max(c)
for al in range(26):
  if c[al] == cmax:
    maxc = al
cmax2 = 0
maxc2 = -1
for al in range(26):
  if al == maxc:
    continue
  if c[al] > cmax2:
    cmax2 = c[al]
    maxc2 = al
m = [maxc,maxc2]
up = []
for _ in range(d):
  up.append(list(map(int,input().split())))
ans = [[-1] for _ in range(26)]
for i in range(d):
  ans[m[i%2]].append(i)
task = [m[i%2] for i in range(d)]
#print(m)
#print(ans)
#print(task)
#print(task)
#ans[0].append(0)
#ans[16].append(1)
#ans[12].append(2)
#ans[13].append(3)
#ans[12].append(4)

for al in range(26):
  ans[al].append(d)
#print(ans)
import bisect
from random import random
from random import randrange
import math
scr = 0
for al in range(26):
  now = ans[al]
  l = len(now)
  for j in range(1,l):
    scr -= c[al] * (now[j]-now[j-1]-1) * (now[j]-now[j-1]) // 2
    #print(c[al] * (now[j]-now[j-1]-1) * (now[j]-now[j-1]) // 2)
  for j in range(1,l-1):
    scr += up[now[j]][al]
    #print(up[now[j]][al])
  #print('$')
#print(scr)
est = 20000
for _ in range(222):
  for _ in range(10000):
    day = randrange(d)
    pre = task[day]
    pst = randrange(26)
    if pre == pst:
      continue
    bpre = bisect.bisect_left(ans[pre],day)
    bpst = bisect.bisect_left(ans[pst],day)
    bpre1 = ans[pre][bpre-1]
    bpre2 = ans[pre][bpre+1]
    bpst1 = ans[pst][bpst-1]
    bpst2 = ans[pst][bpst]
    #print(day,ans[pre][bpre],ans[pst][bpst])
    #print(day)
    #print(bpre1,day,bpre2,'#',pre)
    #print(bpst1,day,bpst2,'#',pst)
    tmp = 0
    tmp -= c[pre] * (day-bpre1) * (bpre2-day)
    #print(c[pre] * (day-bpre1) * (bpre2-day))
    tmp += c[pst] * (day-bpst1) * (bpst2-day)
    #print(c[pst] * (day-bpst1) * (bpst2-day))
    tmp -= up[day][pre]
    #print(up[day][pre])
    tmp += up[day][pst]
    #print(up[day][pst])
    #print(tmp)
    r = random()
    if est > 0:
      exp = math.exp(tmp/est)
    else:
      exp = bool(tmp>0)
    if exp > r:
      #print(ans[pre])
      #print(ans[pst])
      ans[pre].remove(day)
      bisect.insort(ans[pst],day)
      #print(ans[pre])
      #print(ans[pst])
      task[day] = pst
      scr += tmp
      #print(scr)
    #print('%')
  est -= 100
#for x in ans:
  #print(x)
for x in task:
  print(x+1)
#print(scr)

Measured memory_bytes: 90812
#include<bits/stdc++.h>
using namespace std;
const int N=5e3+10;
const int mod=1e9+7;
const int inv2=(mod+1)>>1;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,f[N][N],bin[N],ibin[N];

int main() {
	cin>>n>>m;
	bin[0]=1;for(int i=1;i<N;i++) bin[i]=(bin[i-1]<<1)%mod;
	ibin[0]=1;for(int i=1;i<N;i++) ibin[i]=1ll*ibin[i-1]*inv2%mod;
	for(int i=0;i<=n;i++) {
		int sum=0;
		for(int j=0;j<=m;j++) {
			if(i==0||j==0) f[i][j]=1;
			else {
				f[i][j]=(1ll*f[i-1][j]*(j+1)+1ll*bin[j-1]*sum)%mod;
			}
			if(j) sum=(sum+1ll*f[i-1][j]*j%mod*ibin[j])%mod;
		}
	}
	cout<<f[n][m];
	return 0;
}


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

int main() {
  string key = "keyence";
  string str;
  string tmp;
  
  cin >> str;
  
  for(int i = 0; i < 8; i++){
    tmp = str.substr(0,i) + str.substr(str.size() - (7-i), 7-i);

    if(tmp == key){
      cout << "YES";
      return 0;
    }
  }
  
  cout << "NO";
}


Measured memory_bytes: 256
/*
Author : Hocky Yudhiono
Min 26 Jan 2020 07:11:32  WIB

1. You can sort the query if offline!
2. Don't bring the dp remaining state when dfsing on DP on Tree.
3. Try to reverse (Think from the back) if you stuck.
4. Be careful when submitting Div. 2 D-F, dont waste it on stupid WAs.
5. Try to reduce a problem
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
//If the time limit is strict, try not to use long double

#define popf pop_front
#define pf push_front
#define popb pop_back
#define mp make_pair
#define pb push_back
#define remove erase
#define fi first
#define se second

//Remember to undefine if the problem is interactive
#define endl '\n'
#define DEBUG(X) cout << ">>> DEBUG(" << __LINE__ << ") " << #X << " = " << (X) << endl

const double eps = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const LL LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const LL MOD = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1};
const int dy[8] = {0,1,0,-1,1,-1,1,-1};
const double PI = 3.141592653589793;

inline void open(string a){
    freopen((a+".in").c_str(),"r",stdin);
    freopen((a+".out").c_str(),"w",stdout);
}

inline void fasterios(){
    //Do not use if interactive
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

LL h,n;
PLL isi[1005];
LL memo[10005];
int main(){
    fasterios();
    memset(memo,INFMEM,sizeof(memo));
    cin >> h >> n;
    LL ans = LINF;
    memo[0] = 0;
    for(int i = 1;i <= n;i++){
        cin >> isi[i].fi >> isi[i].se;
        for(int j = 0;j < h;j++){
            if(j+isi[i].fi >= h){
                ans = min(ans,memo[j]+isi[i].se);
            }else{
                memo[j+isi[i].fi] = min(memo[j+isi[i].fi],memo[j]+isi[i].se);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    long long N, max = 0;
    cin >> N;

    for (long long i = 1; i < sqrt(N) + 1; i++)
    {
        if (N % i == 0)
        {
            max = i;
        }
    }

    cout << (long long)(max + N / max - 2ll) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll A,B,C,D,E,F;
  
  cin>>A>>B>>C>>D>>E>>F;
  ll water=0;
  ll sugar=0;
  double rate=0;
  for(ll i=0;100*A*i<F;i++){
for(ll j=0;100*B*j<F;j++){
  for(ll k=0;k*C<F;k++){
for(ll l=0;l*D<F;l++){
  if(100*A*i+100*B*j+k*C+l*D<=F&&i+j!=0){
  double date=(k*C+l*D)*100*1.0/(100*A*i+100*B*j+k*C+l*D)*1.0;
  
  if(E*(A*i+B*j)>=(k*C+l*D)){
    if(rate<=date){
      water=(100*A*i+100*B*j+k*C+l*D);
      sugar=(k*C+l*D);
      rate=date;
    }
  }
  }
}
  }
}
  }

  cout<<water<<" "<<sugar<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    long long n,all=0,z;
    cin>>n;
    long long a[n+2];
    a[0]=0;
    a[n+1]=0;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=0;i<=n;i++)
    {
        if (a[i]-a[i+1]>=0) all=all+a[i]-a[i+1];
        else
        {
            all=all+a[i+1]-a[i];
        }
    }
    z=all;
    for (int i=1;i<=n;i++)
    {
        all=z;
        if (a[i]-a[i+1]>=0) all=all-a[i]+a[i+1];
        else
        {
            all=all+a[i]-a[i+1];
        }
        if (a[i]-a[i-1]>=0) all=all-a[i]+a[i-1];
        else
        {
            all=all+a[i]-a[i-1];
        }
        if (a[i-1]>=a[i+1]) all=all+a[i-1]-a[i+1];
        else all=all+a[i+1]-a[i-1];
        cout<<all<<endl;
    }
    system ("pause");
    return 0;
}

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

const ll INF = ll(1e18)+1;

int main(){
	int n;
  	ll k;
  	cin >> n >> k;
  	vector<ll> a(n);
  	rep(i, n) cin >> a[i];
  	sort(a.begin(), a.end());
  	ll l = -INF, r = INF;
  	
  	while(l+1 < r){
    	ll x = (l+r)/2;
      
      	bool ok = [&]{
        	ll tot = 0;
          	rep(i, n){
            	if(a[i] < 0){
                	int l = -1, r = n;
                  	while(l+1 < r){
                    	int c = (l+r)/2;
                      	if(a[c] * a[i] < x) r = c;
                      	else l = c;
                    }
                  	tot += n-r;
                } else {
                	int l = -1, r = n;
                  	while(l+1 < r){
                    	int c = (l+r) /2;
                      	if(a[c] * a[i] < x) l = c;
                      	else r = c;
                    }
                  	tot += r;
                }
              
              	if(a[i] * a[i] < x) tot--;
            }
          	tot /= 2;
          	return tot < k;
        }();
      	
      	if(ok) l = x;
      	else r = x;
    }
  
  	cout << l << endl;
}

Measured memory_bytes: 4816
h, w = [int(i) for i in input().split()]
s = []
flag = True
for hi in range(h):
    s1 = input()
    s.append(s1)

for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == "#":
            if hi != 0 and s[hi-1][wi] == "#":
                pass
            elif hi != h - 1 and s[hi+1][wi] == "#":
                pass
            elif wi != 0 and s[hi][wi-1] == "#":
                pass
            elif wi != w - 1 and s[hi][wi+1] == "#":
                pass
            else:
                flag = False
    if not flag:
        break

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
def main():
    M = 10 ** 6
    _ = int(input())
    A = list(map(int,input().split()))
    erato = [True] * (M+10)
    m = dict()
    for i in A:
        if i in m:
            m[i] += 1
        else:
            m[i] = 1
    one = []
    for k,v in m.items():
        if v == 1:
            one.append(k)
        else:
            for i in range(k,M+1,k):
                erato[i] = False
    one.sort()
    ans = 0 
    for i in one:
        ans += 1 if erato[i] else 0
        for j in range(i,M+1,i):
            erato[j] = False

    print(ans)


if __name__ == '__main__':
    main()

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

#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

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

int main(void)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}

Measured memory_bytes: 256
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n, m, q]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const l = Main.makeList(1, 0, n, m, []);
    const len = l.length;
    let result = [];
    for (let j = 0; j < len; j++) {
      result.push(0);
    }
    for (let i = 0; i < q; i++) {
      const x: number[] = tmp.shift().split(" ").map(int => parseInt(int));
      for (let j = 0; j < len; j++) {
        const list = l[j];
        if (list[x[1] - 1] - list[x[0] - 1] == x[2]) {
          result[j] = result[j] + x[3];
        }
      }
    }
    return `${Math.max.apply(null, result)}`;
  }

  static makeList(i, k, n, m, list) {
    if (k == n) {
      return [list];
    }
    let result = [];
    for (let j = i; j <= m; j++) {
      result = result.concat(Main.makeList(j, k + 1, n, m, list.concat([j])));
    }
    return result;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 75408
import sys
input = sys.stdin.readline
from collections import *

N, A, B, C = map(int, input().split())
l = [input()[:-1] for _ in range(N)]
ans = []

for i in range(N):
    if l[i]=='AB':
        if A==0:
            A += 1
            B -= 1
            ans.append('A')
        elif B==0:
            B += 1
            A -= 1
            ans.append('B')
        else:
            if i<N-1:
                if l[i+1]=='AB':
                    A += 1
                    B -= 1
                    ans.append('A')
                elif l[i+1]=='BC':
                    B += 1
                    A -= 1
                    ans.append('B')
                else:
                    A += 1
                    B -= 1
                    ans.append('A')
            else:
                ans.append('A')
    elif l[i]=='BC':
        if B==0:
            B += 1
            C -= 1
            ans.append('B')
        elif C==0:
            C += 1
            B -= 1
            ans.append('C')
        else:
            if i<N-1:
                if l[i+1]=='AB':
                    B += 1
                    C -= 1
                    ans.append('B')
                elif l[i+1]=='BC':
                    B += 1
                    C -= 1
                    ans.append('B')
                else:
                    C += 1
                    B -= 1
                    ans.append('C')
            else:
                ans.append('B')
    else:
        if A==0:
            A += 1
            C -= 1
            ans.append('A')
        elif C==0:
            C += 1
            A -= 1
            ans.append('C')
        else:
            if i<N-1:
                if l[i+1]=='AB':
                    A += 1
                    C -= 1
                    ans.append('A')
                elif l[i+1]=='BC':
                    C += 1
                    A -= 1
                    ans.append('C')
                else:
                    A += 1
                    C -= 1
                    ans.append('A')
            else:
                ans.append('A')
    
    if A<0 or B<0 or C<0:
        print('No')
        exit()
    
print('Yes')

for ans_i in ans:
    print(ans_i)

Measured memory_bytes: 80540
#include <iostream>
#include <algorithm>

using namespace std;

void printarr(vector<int> arr,int n){
    for(int i=0;i<arr.size()-1;i++){
        cout<<arr[i]<<" ";
    }
    cout<<arr[arr.size()-1]<<endl;
    return;
}


int main() {
    int n;
    vector<int> arr;
    cin>>n;
    for(int i=0,t;i<n;i++){
        cin>>t;
        arr.push_back(t);
    }
    for(int i=0;i<n;i++){
        int temp=arr[i];
        int j=i-1;
        while (j>=0&&arr[j]>temp){
            arr[j+1]=arr[j];
            j--;
        }
        arr[j+1]=temp;

        printarr(arr,n);
    }
    return 0;
}



Measured memory_bytes: 3140
// C - Welcome to AtCoder
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, m, w = 0, ans = 0, count = 0;
  string s, t;
  // vector<pair<lli, pair<string, lli>>> pr;
  cin >> n >> m;
  vlli d(n + 1, 0), e(n + 1, 0);
  rep(i, 0, m)
  {
    cin >> a >> s;
    if (d[a] == 1LL)
    {
      continue;
    }
    if (s == "AC")
    {
      d[a] = 1LL;
      ans++;
      w += e[a];
    }
    else if (s == "WA")
    {
      e[a]++;
    }
    // cout << "e[" << a << "]: " << e[a] << endl;
    // cout << "w: " << w << endl;
  }
  // cout << endl;
  t = to_string(ans) + " " + to_string(w);
  // cout << ans << " ";
  cout << t << endl;
  // cout << e << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int i=a;i<b;i++)

int main()
{
    int x,y,ans;
    cin>>x>>y;
    ans=(x*(x-1))/2+(y*(y-1))/2;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 1e7 + 1;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
int dv[N];
void solve(){
    
    ll ans = 0;
    int n;
    cin >> n;
    for(int i = 1; i < N; ++i)
        for(int j = i; j < N; j += i)
            dv[j] ++;
    
    for(int i = 1; i <= n; ++i)
        ans += 1ll * dv[i] * i;
    cout << ans;
    
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 42708
count = gets.chomp.to_i
numbers = gets.chomp.split(' ')
sum = 0
count.times do |i|
  sum += numbers[i].to_i
end 
numbers = numbers.map(&:to_i)
max = numbers.max
sum -= max.to_i 
if max < sum
  puts 'Yes'
else
  puts 'No'
end 

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


set<int> primes(ll n, bool flog = false) {
	int N = ((int)sqrt(n)) + 1;
	vector<bool> num(N, true);
	set<int> p;
	for (int i = 2; i < N; i++) {
		if (num[i]) {
			p.insert(i);
			if (flog) cout << "primes " << i << endl;
			for (int j = i; j < N; j += i) {
				num[j] = false;
			}
		}
	}
	return p;
}


int main() {
	ll N;
	cin >> N;
	vector<ll> A(N,0);
	for(int i =0; i< N; i++){
		cin >> A[i];
	}

	set<int> P = primes(1000000,false);

	bool pc = true;
	while(!P.empty()){
		int p = *P.begin();
		P.erase(p);
		int score = 0;
		for(int i = 0; i < N; i++){
			if((A[i] % p) == 0){
				A[i] /= p;
				score++;
			}
		}
		if(score == N){
			cout << "not coprime" << endl;
			return(0);
		}
		if(score >= 2){
			pc = false;
		}
	}

	int sss = 0;
	set<ll> SSS;
	for(int i = 0; i < N; i++){
		if(A[i] > 1){
			sss++;
			SSS.insert(A[i]);
		}
	}
	if(sss > SSS.size()){
		pc = false;
	}
	if(SSS.size() == 1 && sss == N){
		cout << "not coprime" << endl;
		return(0);
	}
	if(pc){
		cout << "pairwise coprime" << endl;
	}else{
		cout << "setwise coprime" << endl;

	}
	return(0);
}


Measured memory_bytes: 18824
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n)  for(int i = 0;i<n;++i)
#define fri(i,a,b) for(int i= a;i<=b;++i)
#define fro(i,a,b) for(int i= a;i>=b;--i)
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define fi first
#define se second
#define pb(x) push_back(x)
#define  mp(x,y) make_pair(x,y)
#define endl  "\n"
#define  ii  pair<int,int>
#define  LL  long long
#define  maxm(a,b,c)  max(a,max(b,c))
const int INF = 1e9+7;
int main(){
  int n;
  cin>>n;
  int a[n],b[n],c[n];
  fr(i,n)cin>>a[i]>>b[i]>>c[i];
  int dp[n][3];
  dp[0][0] = a[0],dp[0][1] = b[0],dp[0][2] = c[0];
  fri(i,1,n-1){
  		  dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
  		  dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
  		  dp[i][2] = max(dp[i-1][1],dp[i-1][0])+c[i];
	  }
	  cout<<maxm(dp[n-1][0],dp[n-1][1],dp[n-1][2]);
  }
  


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int n, m, x;
vector<int> c;
vector<vector<int>> a;

bool check(const vector<int>& s) {
	for (int i = 0; i < m; i++) {
		if (s[i] < x) return false;
	}
	return true;
}

void dfs(int i, int v, vector<int> s, int& res) {
	if (i == n) {
		if (check(s)) {
			res = min(res, v);
		}
		return;
	}
	dfs(i + 1, v, s, res);
	for (int j = 0; j < m; j++) {
		s[j] += a[i][j];
	}
	dfs(i + 1, v + c[i], s, res);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> x;
	c = vector<int>(n, 0);
	a = vector<vector<int>>(n, vector<int>(m, 0));

	vector<int> X(m, 0);
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			X[j] += a[i][j];
		}
	}

	for (int i = 0; i < m; i++) {
		if (X[i] < x) {
			cout << -1 << endl;
			return 0;
		}
	}

	vector<int> s(m, 0);
	int res = INT_MAX;
	dfs(0, 0, s, res);
	cout << res << endl;
	return 0;
}



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

#define int long long

using namespace std;

signed main()
{
    int n;
    cin >> n;
    vector<int>v(n);
    for(auto &i : v)
        cin >> i;
    int g = 0;
    for(int i = 0; i < n; ++i)
        g = __gcd(g, v[i]);
    cout << g << endl;
    return 0;
}


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

int main() {

    int N;
    cin >> N;
    
    if (N <= 1000) {
        cout << 1000 - N << endl;
    }
    
    if (1001 <= N && N <= 2000) {
        cout << 2000 - N << endl;
    }
    
    if (2001 <= N && N <= 3000) {
        cout << 3000 - N << endl;
    }
    
    if (3001 <= N && N <= 4000) {
        cout << 4000 - N << endl;
    }
    
    if (4001 <= N && N <= 5000) {
        cout << 5000 - N << endl;
    }
    
    if (5001 <= N && N <= 6000) {
        cout << 6000 - N << endl;
    }
    
    if (6001 <= N && N <= 7000) {
        cout << 7000 - N << endl;
    }
    
    if (7001 <= N && N <= 8000) {
        cout << 8000 - N << endl;
    }
    
    if (8001 <= N && N <= 9000) {
        cout << 9000 - N << endl;
    }
    
    if (9001 <= N && N <= 10000) {
        cout << 10000 - N << endl;
    }
    
}

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

static const int MAX = 200001;

int main(){
    int n, a[MAX];
    cin >> n;
    for(int i=1; i<=n; i++){
        a[i] = 0;
    }

    for(int i=2; i<=n; i++){
        int b;
        cin >> b;
        a[b]++;
    }

    for(int i=1; i<=n; i++){
        cout << a[i] << endl;
    }

}

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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int cnt=0;
  while(a>=b){
    b*=2;
    cnt++;
  }
  while(b>=c){
    c*=2;
    cnt++;
  }
  if(cnt<=k){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3572
S = gets.chomp
T = gets.chomp
 
S_CODES = S.codepoints
T_CODES = T.codepoints
 
S_SIZE = S.size
T_SIZE = T.size
dp = Array.new(S_SIZE + 1) { Array.new(T_SIZE + 1, 0) }
 
S_SIZE.times do |s|
  dp_cur = dp[s]
  dp_next = dp[s+1]
  T_SIZE.times do |t|
    if S_CODES[s] == T_CODES[t]
      dp_next[t+1] = dp_cur[t] + 1
    else
      dp_next[t+1] = dp_cur[t+1]
      dp_next[t+1] = dp_next[t] if dp_next[t+1] < dp_next[t]
    end
  end
end
 
lcs = ''
s = S_SIZE
t = T_SIZE
while s > 0 && t > 0
  if dp[s][t] == dp[s-1][t]
    s -= 1
  elsif dp[s][t] == dp[s][t-1]
    t -= 1
  else
    lcs << S[s-1]
    s -= 1
    t -= 1
  end
end
 
puts lcs.reverse

Measured memory_bytes: 72316
#include<iostream>
using namespace std;
int A[2<<17];
int T,D,L;
main()
{
	while(cin>>T>>D>>L,T)
	{
		for(int i=0;i<2<<17;i++)A[i]=0;
		for(int i=0;i<T;i++)
		{
			int x;cin>>x;
			if(x>=L)
			{
				A[i]++;
				A[i+D]--;
			}
		}
		int ans=0;
		for(int i=1;i<1<<17;i++)A[i]+=A[i-1];
		for(int i=0;i<T-1;i++)ans+=A[i]>0;
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 4036
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int h,w;

int main() {
    cin >> h >> w;
    vector<string> f(h);
    rep(i,h) cin >> f[i];

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

    int ans = 0;
    int d[h][w];

    rep(sh,h) {
        rep(sw,w) {
            if (f[sh][sw]=='#') continue;
            else {
                queue<P> q;
                q.push(P(sh,sw));

                rep(i,h)rep(j,w) d[i][j] = INF;
                d[sh][sw] = 0;
                while(q.size()!=0) {
                    P pos = q.front(); q.pop();

                    rep(i,4) {
                        int nh = pos.fi + dy[i];
                        int nw = pos.se + dx[i];
                        if (nh < 0 || nh >= h || nw < 0 | nw >= w || f[nh][nw] != '.' || d[nh][nw] != INF) continue;
                        d[nh][nw] = d[pos.fi][pos.se] + 1;
                        q.push(P(nh,nw));
                        ans = max(ans, d[nh][nw]);
                    }
    
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}






















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

// --- MOD begin --- cut here ---

ll MOD = 1e9 + 7;
// ll MOD = 998244353;

// g = eGCD(a, b, s, t)  --->  sa + tb = g
constexpr ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u = 0;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}

constexpr ll gcd(ll a, ll b) {
  ll dummy1 = 0;
  ll dummy2 = 0;
  return eGCD(a, b, dummy1, dummy2);
}

struct Fp {
  ll val;

  Fp(ll t = 0) :
    val(t < 0 ? MOD + t % MOD : t >= MOD ? t % MOD : t) {}

  Fp& operator +=(const Fp& t) {
    val += t.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }

  Fp& operator -=(const Fp& t) {
    val -= t.val;
    if (val < 0) val += MOD;
    return *this;
  }

  Fp& operator *=(const Fp& t) {
    val = (val * t.val) % MOD;
    return *this;
  }

  Fp inv() const {
    if (val == 0) {
      cerr << "inv() is called for zero." << endl;
      exit(1);
    }
    ll u = 0;
    ll v = 0;
    eGCD(val, MOD, u, v);
    return Fp(u);
  }

  Fp& operator /=(const Fp& t) {
    return (*this) *= t.inv();
  }

  Fp operator +(const Fp& t) const { return Fp(val) += t; }
  Fp operator -(const Fp& t) const { return Fp(val) -= t; }
  Fp operator *(const Fp& t) const { return Fp(val) *= t; }
  Fp operator /(const Fp& t) const { return Fp(val) /= t; }
  Fp operator -() const { return Fp(-val); }

  bool operator ==(const Fp& t) const { return val == t.val; }
  bool operator !=(const Fp& t) const { return val != t.val; }
  
  operator ll() const { return val; }

};

class Comb {
  int nMax;
  vector<Fp> vFact;
  vector<Fp> vInvFact;
public:
  Comb(int nm) : nMax(nm), vFact(nm+1), vInvFact(nm+1) {
    vFact.at(0) = 1;
    for (int i = 1; i <= nMax; i++) vFact.at(i) = i * vFact.at(i-1);
    vInvFact.at(nMax) = vFact.at(nMax).inv();
    for (int i = nMax; i >= 1; i--) vInvFact.at(i-1) = i * vInvFact.at(i);
  }
  Fp fact(int n) { return vFact.at(n); }
  Fp comb(int n, int r) {
    return vFact.at(n) * vInvFact.at(r) * vInvFact.at(n-r);
  }
  // The number of permutation extracting r from n.
  Fp perm(int n, int r) {
    return vFact.at(n) * vInvFact.at(n-r);
  }
};

/* 
   Power function    power(a, b) == a^b
   Speed is O(log b).
   The same source code can be used for integers by replacing
   Fp with int etc.  Unfortunately, replacing Fp with auto does not
   make the function generic for int and Fp.
 */
Fp power(Fp a, int b) {
  Fp twoPow = a;
  Fp rv = 1;
  while (b > 0) {
    if (b & 1) rv *= twoPow;
    twoPow *= twoPow;
    b >>= 1;
  }
  return rv;
}

// --- MOD end --- cut here ---


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll A, B; cin >> A >> B;
  ll g = gcd(A, B);
  cout << A * B / g << endl;
  

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M = 1e9+7;
#define ll long long 
ll mod(ll x){
        return ((x%M + M)%M);
}
ll add(ll a, ll b){
    return mod(mod(a)+mod(b));
}
ll mul(ll a, ll b){
    return mod(mod(a)*mod(b));
}
ll minu(ll a, ll b){
    return mod(mod(a)-mod(b));
}
ll modPow(ll a,ll b){
    if(b==0)
        return 1LL;
    if(b==1)
        return a%M;
    ll res=1;
    while(b){
        if(b%2==1)
            res=mul(res,a);
        a=mul(a,a);
        b=b/2;
    }
    return res;
}
int main(){
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
    // cout<<fixed;
    // cout<<setprecision(10);
    ll n;
    cin>>n;
    if(n==1){
        cout<<0;
        return 0;
    }
    if(n==2){
        cout<<2;
        return 0;
    }
    ll ans=minu(add(modPow(10LL,n),modPow(8LL,n)),mul(2LL,modPow(9LL,n)));
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3620
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

int main(){
    long long x, y;
    cin >> x >> y;
    long long a = y / x;
    int count = 0;
    while(true){
        a = a/2;
        count++;
        if(a==0) break;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

//Compiler version gcc  6.3.0

int main()
{
  int k,s;
  int ans=9999999;
  scanf("%d",&k);
  int x[k];
  
  for(int i=0;i<k;i++){
    scanf("%d",&x[i]);
    }
    
    int temp=0;
    
    for(int i =1;i<=100;i++){
      temp=0;
      for(int j =0;j<k;j++){
        temp +=(x[j]-i)*(x[j]-i);
      }
      if(ans >temp)ans=temp;
    }
    

  
   printf("%d",ans);
  
  
  
  return 0;
}

Measured memory_bytes: 128
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn main() {
    input! {
    n: usize,
    m: usize,
    ab: [(Usize1, Usize1); m]
    }
    let mut ans = vec![];
    let mut uf = UnionFind::new(n);
    let mut uncomfo = n * (n - 1) / 2;
    for i in (0..m).rev() {
        ans.push(uncomfo);
        let (a, b) = ab[i];
        if !uf.same(a, b) {
            uncomfo -= uf.size(a) * uf.size(b);
            uf.unite(a, b);
        }
    }
    for i in (0..m).rev() {
        println!("{}", ans[i]);
    }
}

#[derive(Default)]
struct UnionFind {
    par: Vec<usize>,
    siz: Vec<usize>,
}

#[allow(dead_code)]
impl UnionFind {
    fn new(n: usize) -> Self {
        Self {
            par: (0..n).collect::<Vec<usize>>(),
            siz: vec![1; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        let ele = self.par[x];
        return if ele == x {
            x
        } else {
            self.par[x] = self.find(ele);
            self.par[x]
        };
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn unite(&mut self, x: usize, y: usize) -> bool {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x == y {
            return false;
        }
        if self.siz[x] < self.siz[y] {
            std::mem::swap(&mut x, &mut y)
        }
        self.siz[x] += self.siz[y];
        self.par[y] = x;
        true
    }

    fn size(&mut self, x: usize) -> usize {
        let root = self.find(x);
        self.siz[root]
    }
}




Measured memory_bytes: 7212
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dist[101010][3];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, S, T;
    cin >> N >> M;
    vector<vector<int>> G(N);
    REP(i,M){
        int u, v;
        cin >> u >> v;
        --u, --v;
        G[u].emplace_back(v);
    }
    REP(i,N) REP(j,3) dist[i][j] = INF;
    cin >> S >> T;
    --S, --T;
    queue<pair<int, int>> q;
    q.emplace(S,0);
    dist[S][0] = 0;
    while(!q.empty()){
        int v, l;
        tie(v, l) = q.front();
        q.pop();
        for(auto nv : G[v]){
            int nl = (l + 1) % 3;
            if(dist[nv][nl] != INF) continue;
            dist[nv][nl] = dist[v][l] + 1;
            q.emplace(nv, nl);
        }
    }
    int ans = dist[T][0];
    if(ans == INF) ans = -1;
    else ans /= 3;
    cout << ans << endl;
}

Measured memory_bytes: 6912
#include<stdio.h>
int main()
{
    int n;
    int a[10000];
    long int min=1000000,max=-1000000,sum=0;
    
    scanf("%d", &n);
    if(n==0){
        printf("%ld %ld %ld\n",0,0,0);
        return 0;
    }
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        if(min>a[i]) min=a[i];
        if(max<a[i]) max=a[i];
        sum+=a[i];
    }
    printf("%ld %ld %ld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2808