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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    System.out.println( (a + b) * c / 2 );
  }
}

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

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

def main():
    mod=10**9+7
    N=I()
    h=LI()
    ans=0
    now=0
    for i in range(N):
        nxt=h[i]
        ans+=max(nxt-now,0)
        now=nxt

    print(ans)
    

main()


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

int main()
{
int n,t;
cin>>n>>t;
int a; cin>>a; int s = 0; n--;
while(n--)
{
int b; cin>>b;
if (b-a < t) s+=b-a; else s+=t;
a = b;
}
s+=t;
cout<<s;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, ans=0, tmp=0;
  std::cin >> N;
  std::vector<int> card(N, 0);
  for(int i=0;i<N;i++) std::cin >> card[i];
  for(int i=0;i<N;i++){
    tmp += card[i];
    if(card[i]==0 || i==N-1) ans += tmp/2, tmp=0;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1272
#include <iostream>
using namespace std;
int main(void){
    int h,w;
    int dy[8]={-1, 0, 1, 1, 1, 0, -1, -1}, dx[8]={-1, -1, -1, 0, 1, 1, 1, 0};
    string s[50];
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='.'){
                int c=0;
                for(int k=0;k<8;k++){
                    int y=i+dy[k], x=j+dx[k];
                    if(x>=0&&x<w&&y>=0&&y<h){
                        if(s[y][x]=='#')c++;
                    }
                }
                s[i][j]='0'+c;
            }
        }
    }
    for(int i=0;i<h;i++){
        cout<<s[i]<<endl;
    }
}


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

#define ALL(x) x.begin(),x.end()
#define RS(T) sort(T.rbegin(),T.rend())
#define BS(T, x) binary_search (T.begin(), T.end(), x)
#define U unsigned
#define ll long long
using namespace std;

bool diverse(string s) {
    for (int i = 0; i < s.length(); i++) {
        for (int j = i + 1; j < s.length(); j++)
            if (s[i] == s[j]) return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    if (s.length() < 26) {
        char c = 'A';
        vector<int> t(26, 0);
        for (int i = 0; i < s.length(); i++) {
            t[(int) s[i] - 97]++;
        }
        int i;
        for (i = 0; i < 26; i++) {
            if (t[i] == 0)
                break;
        }
        c = (char) (i + 97);
        s += c;
        cout << s;
        return 0;
    }
    string s2 = "zyxwvutsrqponmlkjihgfedcba";
    if (s == s2) {
        cout << -1 << endl;
        return 0;
    }
    string s3 = s;
    for (int i = (s.length() - 1); i >= 0; i--) {
        while (s[i] != 'z') {
            s[i] = (char) ((int) s[i] + 1);
            if (diverse(s)) {
                cout << s;
                return 0;
            }
        }
        s.pop_back();
    }
    return 0;
}

Measured memory_bytes: 256
mod = int(1e9) + 7
n = int(input())
a = list(map(int, input().split()))
lis = [0] * n
for i in a:
    lis[i] += 1
for i in range(1,n):
    if lis[i] % 2 == 1:
        print(0)
        exit()

print(pow(2, n//2, mod)) 


Measured memory_bytes: 13880
<?php
list($n, $k) = ints();
$A = ints();
for($i = 0; $i < $n; $i++){
  $sum = 0;
  for($j = $i; $j < $n; $j++){
    $sum+=$A[$j];
    $array[] = $sum;
  }
}
$v = 0;
for($m = 40; $m >= 0; $m--){
  $c = 0;
  $tmp = $v | 1<<$m;
  foreach($array as $a){
    if(($tmp & $a) == $tmp){
      $c++;
    }
  }
  if($c >= $k)$v = $tmp;
}
printf("%d", $v);

function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}


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

t = 0
max_run_length = 0
for _ in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        t += 1
    else:
        t = 0
    max_run_length = max(max_run_length, t)

if max_run_length >= 3:
    print('Yes')
else:
    print('No')


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

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

    cout << max(0, b+c-a) << endl;
    return 0;
}


Measured memory_bytes: 256
fibo = [0] * 45
N = int(input())
fibo[0] = 1
fibo[1] = 1

for i in range(2,N+1):
    fibo[i] = fibo[i-1]+fibo[i-2]

print(fibo[N])
# N = int(input())　再帰のみ
# def fibo(n):
#     if n == 0 or n == 1:
#         return 1
#     return fibo(n-1)+fibo(n-2)
# print(fibo(N))
# N = int(input()) メモ化再帰　5596KB 635B
# def fibo(n):
#     return fib2(1,1,n-1)
# def fib2(a,b,c):
#     if c < 1:
#         return a
#     return fib2(a+b,a,c-1)
# print(fibo(N))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int n;
vector<vector<int>> g;
vector<int> d, ans;

void dfs(int v, int p, int dep) {
    d[v] = dep;
    for(const auto &u : g[v]) {
        if(u != p) {
            dfs(u, v, dep + 1);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n), d.resize(n), ans.resize(n, -1);
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    dfs(0, -1, 0);
    // 0:青 1:赤
    vector<int> red, blue;
    for(int i = 0; i < n; i++) {
        (d[i] % 2 ? red : blue).emplace_back(i);
    }
    if(red.size() > (n / 3) && blue.size() > (n / 3)) {
        int now = 1;
        for(int i = 0; i < red.size() && now <= n; i++, now += 3) {
            ans[red[i]] = now;
        }
        now = 2;
        for(int i = 0; i < blue.size() && now <= n; i++, now += 3) {
            ans[blue[i]] = now;
        }
        now = 3;
        for(int i = 0; i < n; i++) {
            if(ans[i] == -1) {
                ans[i] = now;
                now += 3;
            }
        }
    } else if(red.size() <= (n / 3)) {
        int now = 3;
        for(int i = 0; i < red.size() && now <= n; i++, now += 3) {
            ans[red[i]] = now;
        }
        for(int i = 0; i < blue.size() && now <= n; i++, now += 3) {
            ans[blue[i]] = now;
        }
        now = 1;
        for(int i = 0; i < n; i++) {
            if(ans[i] == -1) {
                ans[i] = now;
                now++;
                if(now % 3 == 0) {
                    now++;
                }
            }
        }
    } else if(blue.size() <= (n / 3)) {
        int now = 3;
        for(int i = 0; i < blue.size() && now <= n; i++, now += 3) {
            ans[blue[i]] = now;
        }
        for(int i = 0; i < red.size() && now <= n; i++, now += 3) {
            ans[red[i]] = now;
        }
        now = 1;
        for(int i = 0; i < n; i++) {
            if(ans[i] == -1) {
                ans[i] = now;
                now++;
                if(now % 3 == 0) {
                    now++;
                }
            }
        }
    }

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

Measured memory_bytes: 18804
n, x = map(int, input().split())

def count_p(n, x):
  if x == 0:
    return 0
  elif n == 0:
    return 1
  elif x > 2**(n+1)-2:
    return 2**(n)-1 + 1 + count_p(n-1, min(x-(2**(n+1)-1), 2**(n+1)-3))
  else:
    return count_p(n-1, x-1)
  
print(count_p(n,x))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long

int main(){

    int N;
    cin>>N;
    vector<int>lst(20, 0);
    ll ans = 0;
    int lm = 1;
    for(int i=1;i<=N;i++){
        int a;
        cin>>a;
        for(int j = 0, b = 1;j<20;j++,b=b+b){
            if(b & a){
                lm = max(lm, lst[j] + 1);
                lst[j] = i;
            }
        }
        //cout<<lm<<endl;
        ans += i - lm + 1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
main :: IO ()
main = do
  n <- getLine
  wn <- map (read :: String -> Int) . words <$> getLine
  print $ ans wn

ans :: [Int] -> Int
ans wn = snd $ foldl func (allW,allW) wn where
  func (a,m) w = (a-2*w,min m $ abs (a-2*w))
  allW = sum wn

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

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (auto &e: l) cin >> e;
    
    sort(l.begin(), l.end());
    
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int d = l[j]-l[i]+1, u = l[i]+l[j];
            auto lo = lower_bound(l.begin(), l.end(), d);
            auto hi = lower_bound(l.begin(), l.end(), u);
            ans += hi - lo;
            if (d <= l[i] && l[i] < u) ans--;
            if (d <= l[j] && l[j] < u) ans--;
            //cout << ans << " " << l[i] << " " << l[j] << endl;
        }
    }
    
    cout << ans/3 << endl;
    
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);

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

  int ans = 0;
  int active = 0;
  for (int i = 0; i < n; i++) {
    if (active >= h[i]) {
      active = h[i];
    } else {
      ans += h[i] - active;
      active = h[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
ll bpow(ll b, ll p, ll m) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3648
while True:
    a,b = map(int,input().split())
    if a ==0 and b==0:
        break
    for i in range(a):
        if i%2==0:
            if b%2==0:
                print('#.'*(b//2))
            else:
                print('#.'*(b//2) + '#')
        else:
            if b%2==0:
                print('.#'*(b//2))
            else:
                print('.#'*(b//2) + '.')
    print()


Measured memory_bytes: 5616
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);

        String s = stdin.nextLine();
        int count = 0;

        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == '1')
                count++;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 23892
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int max = Math.max(a,b);
        max = Math.max(a+b, max+max-1);
        System.out.println(max);
    }
}

Measured memory_bytes: 23252
n, m = map(int, input().split())

root = [[] for i in range(n + 1)]
for i in range(m):
  a, b = map(int, input().split())
  root[a].append(b)
  root[b].append(a)

ans = 'IMPOSSIBLE'
for x in root[n]:
  if 1 in root[x]:
    ans = 'POSSIBLE'
    break

print(ans)

Measured memory_bytes: 38320
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    ll m;
    int v,p;
    cin >> n >> m >> v >> p;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    if(p >= v){
        reverse(a, a + n);
        REP(i,n){
            if(a[i] + m >= a[p - 1]) ans++;
        }
        cout << ans << endl;
    }else{
        vector<ll> t;
        REP(i,n - (p - 1)){
            t.emplace_back(a[i]);
        }
        int k = t.size();
        ll sum[k + 1] = {};
        REP(i,k){
            sum[i + 1] = sum[i] + t[i];
        }
        int mx = t[k - 1];
        REP(i,k){
            if(t[i] + m < mx) continue;
            if(((t[i] + m) * (k - i - 1) - (sum[k] - sum[i + 1])) / m >= v - (p - 1) - i - 1){
                cout << n - i << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 2676
import java.util.*;
import static java.lang.System.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        long[] a=new long[n];
        long[] b=new long[n];
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextLong();
            b[i]=sc.nextLong();
        }
        long ans=0;
        for (int i = n-1; i > -1; i--) {
            a[i]+=ans;
            if(a[i]%b[i]!=0) {
                long t = b[i] - a[i] % b[i];
                ans+=t;
            }
        }
        out.println(ans);
    }
}

Measured memory_bytes: 89360
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    ll ans = 0;
    cin >> n;
    if (n % 2 == 0)
    {
        ll i = 10;
        while(n / i != 0)
        {
            ans += n / i;
            i *= 5;
        }
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    string S;
    cin >> S;

    set<char> se{};
    for (int i = 0; i < S.size(); i++) {
        se.insert(S[i]);
    }

    int mi = 1e9;
    for (const auto c : se) {
        d(c);

        bool ok = true;
        for (int i = 0; i < S.size(); i++) {
            if (S[i] != c) { ok = false; }
        }
        if (ok) {
            mi = min(mi, 0);
            continue;
        }

        string prev = S;
        for (int t = 0; t < S.size() - 1; t++) {
            string next = prev;
            for (int i = 0; i < prev.size(); i++) {
                if (prev[i] == c) { next[i] = next[max(0, i - 1)] = c; }
            }
            next = next.substr(0, next.size() - 1);

            bool ok = true;
            for (int i = 0; i < next.size(); i++) {
                if (next[i] != c) { ok = false; }
            }

            if (ok) {
                mi = min(mi, t + 1);
                break;
            }

            prev = next;
        }
    }

    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=100005;
vector<int >vvi[N];
vector<int>ans(N,0);
vector<bool>visited(N,false);
int n,m;
int find(int src)
{
	if(ans[src]!=0)
	return ans[src];
	int res=0;
	for(int i=0;i<vvi[src].size();i++)
	{
		if(visited[vvi[src][i]]==false)
		{
			res=max(res,1+find(vvi[src][i]));
		}
	}
	return ans[src]=res;
}
int main()
{
	cin>>n>>m;
	int src,dest;
	for(int i=0;i<m;i++)
	{
		cin>>src>>dest;
		vvi[src].push_back(dest);
	}
	for(int i=1;i<=n;i++)
	{
		if(visited[i]==false)
		{
			ans[i]=find(i);
		}
	}
	int res=0;
	for(int i=1;i<=n;i++)
	{
		res=max(res,ans[i]);
	}
	cout<<res;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int S; cin>>S;
    ll dp[2001];
    rep(i,3)dp[i]=0;
    rep(i,3)dp[i+3]=1;
    dp[0]=1;
    for(int i=6; i<2001; i++)dp[i]=0;
    ll MOD=1e9+7;
    for(int i=6; i<2001; i++){
        for(int j=3; j<i+1; j++){
            dp[i]+=dp[i-j];
            dp[i]%=MOD;
        }
        dp[i]%=MOD;
    }
    cout<<dp[S]<<endl;
    return 0;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 9;
int a[N];
int n;

vector<pii> eli;
int cnt;

void add(int pos, int x){
  while(!eli.empty() && eli.back().fi >= pos){
    eli.pop_back();
  }
  eli.push_back(mp(pos, x));
  if(pos < cnt)
    eli.push_back(mp(pos + 1, 1));
}

bool solve(int k){
  eli.clear();
  eli.push_back(mp(1, 1));
  int idx;
  int ps;
  for(int i = 2; i <= n; i ++ ){
    cnt = a[i];
    while(eli.back().fi > a[i])
      eli.pop_back();
    if(a[i] > a[i - 1]){
      if(eli.back().se != 1){
        eli.push_back(mp(a[i - 1] + 1, 1));
      }
      continue;
    }
    else{
      idx = eli.size() - 1;
      ps = cnt;
      while(idx >= 0){
        if(eli[idx].se < k) break;
        ps = eli[idx].fi - 1;
        --idx;
      }
      if(idx == -1){
        return false;
      }
      add(ps, eli[idx].se + 1);
    }
  }
  return true;
}

int main(){
  fastIO;
  cin >> n;
  for(int i = 1; i <= n; i ++ ){
    cin >> a[i];
  }
  int l=1, r=n;
  int m;
  while(l < r){
    m = (l + r) / 2;
    if(!solve(m))
      l = m + 1;
    else
      r = m;
  }
  cout << r << "\n";
  return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
absa = list(map(abs,a))
in0 = True if 0 in a else False
if in0:
    ans = sum(absa)
else:
    mc = 0
    for i in a:
        if i < 0:
            mc += 1
    if mc % 2 == 0:
        ans = sum(absa)
    else:
        ans = sum(absa)-2*min(absa)
print(ans)

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

struct edge {
    int from, to;
    long long cost;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<edge> E;
    vector<bool> visited(N, false);
    vector<long long> d(N);
    for(int i=0; i<M; i++) {
        int from, to;
        long long cost;
        cin >> from >> to >> cost;
        from--; to--;
        E.push_back((edge){from, to, cost});
    }
    d[0] = 0;
    visited[0] = true;
    int cnt = M;
    bool update;
    while(cnt-- > 0) {
        update = false;
        for(int i=0; i<M; i++) {
            if(visited[E[i].from] && (!visited[E[i].to] || d[E[i].to] < d[E[i].from] + E[i].cost)) {
                d[E[i].to] = d[E[i].from] + E[i].cost;
                visited[E[i].to] = true;
                update = true;
            }
        }
        if(!update) break;
    }
    cnt = M;
    vector<bool> loop(N, false);
    while(cnt-- > 0) {
        for(int i=0; i<M; i++) {
            if(visited[E[i].from] && d[E[i].to] < d[E[i].from] + E[i].cost) {
                d[E[i].to] = d[E[i].from] + E[i].cost;
                visited[E[i].to] = true;
                loop[E[i].to] = true;
            }
            if(loop[E[i].from]) loop[E[i].to] = true;
        }
    }
    if(loop[N-1]) {
        cout << "inf" << endl;
    } else {
        cout << d[N-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define line cout<<"here - "<<__LINE__<<"\n";
#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
#define infi INT_MAX
#define rinfi INT_MIN
#define inf LLONG_MAX
#define rinf LLONG_MIN
#define ff first
#define ss second
using namespace std;
main()
{
    fast
    int tc=1,i,j,k;
//    cin>>tc;
    while(tc--)
    {
       int a;
       cin>>a;
       int aa[a];
       map<int,int>mp;
       for(i=0;i<a;i++)
        cin>>aa[i],mp[aa[i]]++;
        sort(aa,aa+a);
        vector<int>tmp;
        for(i=a-1;i>=0;i--)
        {
            while(mp[aa[i]]>=2)
            {
                tmp.push_back(aa[i]);
                mp[aa[i]]-=2;
            }
        }
        if(tmp.size()<2)
            cout<<0<<endl;
        else cout<<tmp[0]*tmp[1]<<endl;

    }

}




Measured memory_bytes: 10588
S = input()

A = ["","k","ke","key","keye","keyen","keyenc","keyence"]
B = ["keyence","eyence","yence","ence","nce","ce","e",""]
ans = "NO"
for i in range(len(A)) :
    if S[:len(A[i])] + S[-len(B[i]):] == "keyence" :
        ans = "YES"

print(ans)


Measured memory_bytes: 3060
n,k=map(int,input().split())
snuke=[0]*n
for _ in range(k):
    d=int(input())
    a=list(map(int,input().split()))
    for i in a:
        i-=1
        snuke[i]+=1
ans=0
for i in snuke:
    if i==0:
        ans+=1
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  string s;
  cin>>s;

  if(s.find("AC") != string::npos) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  char s[11], t[11], u[11];
  int a, b;
  scanf("%s %s %d %d %s", s, t, &a, &b, u);

  if (strcmp(s, u) == 0) a--;
  else b--;
  printf("%d %d\n", a, b);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";

int D, G;
vector<int> p(10);
vector<int> c(10);

int problemsCount(int state) {

    vector<int> problems(D, 0);

    for (int i = 0; i < D; i++) {
        problems[i] = state % 2;
        state /= 2;
    }

    int score = 0, count = 0;
    for (int i = 0; i < D; i++) {
        if ( problems[i] ) {
            score += (i+1) * p[i] + c[i];
            count += p[i];
        }
    }

    if ( score >= G ) {
        return count;
    }

    for (int i = D-1; i >= 0; i--) {
        if ( problems[i] == 0 ) {
            if ( G > score + (i+1) * p[i] + c[i] ) {
                score += (i + 1) * p[i] + c[i];
                count += p[i];
            } else {
                count += (G-score+i)/(i+1);
                break;
            }
        }
    }
    return count;
}

int main() {

    cin >> D >> G;
    G /= 100;

    for (int i = 0; i < D; i++) {
        int pi, ci;
        cin >> pi >> ci;
        p[i] = pi;
        c[i] = ci / 100;
    }

    int ans = 1e9;
    for (int d = 0; d <= pow(2, D); d++) {
        ans = min(ans, problemsCount(d));
    }

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

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int x = c%b;
  int y = a%d;
  if(x != 0)
    x = 1;
  else
    x = 0;
  if(y != 0)
    y = 1;
  else
    y = 0;
  if(c/b + x <= a/d + y)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



Measured memory_bytes: 3524
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll X, K, D;
    cin >> X >> K >> D;
    if (X < 0)
        X *= -1;
    ll mv = X / D;
    if (mv >= K)
        cout << X - (K * D) << endl;
    else
    {
        X %= D;
        K -= mv;
        if (K % 2 == 1)
        {
            cout << -(X - D) << endl;
        }
        else
        {
            cout << X << endl;
        }
    }
}


Measured memory_bytes: 3636
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
aa = inpl()
aa.append(-1)
tmp = 1
ans = 0
for i in range(1,N+1):
    if aa[i] == aa[i-1]:
        tmp += 1
    else:
        ans += tmp//2
        tmp = 1

print(ans)


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

namespace atcoder
{

    namespace atcoder
    {
        class Program
        {
            static void Main(string[] args)
            {
                string[] input = Console.ReadLine().Split(' ');
                int A = int.Parse(input[0]);
                int B = int.Parse(input[1]);
                int ans = B / 2;
                if (A <= 5){
                  Console.WriteLine(0);
                }else if (6 <= A && A <= 12)
                {   
                    Console.WriteLine(ans);
                }else{
                    Console.WriteLine(B);
                }
            }
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll n;
    cin>>n;
    ll nn=n;
    vector<ll>v;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll c=0;
            while(nn%i==0)
            {
                c++;
                nn/=i;
            }
            v.push_back(c);
        }
    }
    if(nn!=1)
        v.push_back(1);
    ll ans=0;
    for(auto u:v)
    {
        ll now=u;
        int p=1;
        while(now>=p)
        {
            ans++;
            now-=p;
            p++;
        }
    }
    cout<<ans;

}



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

int main(){
    int t;
    t=1;
    while(t--){
        int n,x,t;
        cin >> n>>x>>t;
        int ans = n/x;
        if(n%x!=0)ans++;
        cout << ans*t<<endl;
    }
}

Measured memory_bytes: 3624
import sys
import heapq
def dijkstra(s,es):
    INF=sys.maxsize
    cs=[INF]*len(es)
    cs[s],hq=0,[]
    heapq.heapify(hq)
    heapq.heappush(hq,(cs[s],s))
    while hq:
        d,v=heapq.heappop(hq)
        if cs[v]<d:continue
        for t,b in es[v]:
            if cs[t]>cs[v]+b:
                cs[t]=cs[v]+b
                heapq.heappush(hq,(cs[t],t))
    return cs
def nwc(n,c):
    MAX_COINS=2500
    return (MAX_COINS+1)*n+c
def main():
    MAX_COINS=2500
    N,M,S=tuple(map(int,sys.stdin.readline().split()))
    S=S if S<MAX_COINS else MAX_COINS
    es=[[] for _ in range(N*(MAX_COINS+1))]
    for _ in range(M):
        u,v,a,b=tuple(map(int,sys.stdin.readline().split()))
        u,v=u-1,v-1
        for c in range(a,MAX_COINS+1):
            es[nwc(u,c)].append((nwc(v,c-a),b))
            es[nwc(v,c)].append((nwc(u,c-a),b))
    for n in range(N):
        c,d=tuple(map(int,sys.stdin.readline().split()))
        c=c if c<MAX_COINS else MAX_COINS
        for i in range(0,MAX_COINS-c+1):es[nwc(n,i)].append((nwc(n,i+c),d))
    cs=dijkstra(nwc(0,S),es)
    for n in range(1,N):print(min(cs[n*(MAX_COINS+1):(n+1)*(MAX_COINS+1)]))
if __name__=='__main__':main()

Measured memory_bytes: 95192
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));


signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s; cin >> s;
    int n=(int)s.size();
    ll res=0;
    rep(i,n){
        int x=s[i]-'0';
        res+=x;
    }
    if(res%9==0)cout<<"Yes"<<endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3776
import itertools
N,M=map(int,input().split())
L=[list(map(int,input().split()))[1:] for i in range(M)]
P=list(map(int,input().split()))

A=list(itertools.product([0,1],repeat=N))

ans=2**N
for i in range(2**N):
  for j in range(M):
    cnt=0
    for k in L[j]:
      cnt+=A[i][k-1]
    if P[j]!=(cnt%2):
      ans-=1
      break
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,m;
  cin>>n>>m;
  vector<vi> g1(n,vi(n,inf)),g2(n,vi(n,inf));

  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    g1[a][b]=c;
    g2[a][b]=c;
    g1[b][a]=c;
    g2[b][a]=c;
  }

  rep(k,n){
    rep(i,n){
      rep(j,n){
        if(i==j||j==k||k==i) continue;
        
        g1[i][j]=min(g1[i][j],g1[i][k]+g1[k][j]);
        
      }
    }
  }

  int ans=0;
  rep(i,n){
    rep(j,n){
      if(g2[i][j]!=inf&&g1[i][j]<g2[i][j]) ans++;
    }
  }

  cout<<ans/2<<endl;


}

Measured memory_bytes: 384
### constant

INF = 1 << 30

### subroutines

def count_rec(bits, mask)
  return $cache[bits][mask] if $cache[bits][mask]

  c = 0
  for obj in $objs
    c += 1 if (obj & mask) == bits
  end
  return ($cache[bits][mask] = 0) if c <= 1

  minc = INF

  for i in (0...$m)
    b = 1 << i
    mask0 = mask | b
    if mask != mask0
      c0 = count_rec(bits, mask0) + 1
      c1 = count_rec(bits | b, mask0) + 1
      c = (c0 > c1) ? c0 : c1
      minc = c if minc > c
    end
  end

  $cache[bits][mask] = minc
end

### main

loop do
  $m, $n = gets.split.map(&:to_i)
  break if ($m | $n) == 0

  $objs = $n.times.map{gets.strip.to_i(2)}
  #p $objs.map{|o| o.to_s(2)}

  $cache = (1 << $m).times.map{{}}

  minc = count_rec(0, 0)
  puts minc
end

Measured memory_bytes: 16040
n = int(input())
seat = [0] * 10 ** 6
for i in range(n):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        seat[j - 1] = 1

res = 0
for i in range(10 ** 6):
    if seat[i] == 1:
        res += 1
print(res)


Measured memory_bytes: 16772
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,k,ans,a[N],b[N];
char s[N];
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	n=read();int X=read(),Y=read();
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int x=j-i;
			int y=abs(i-X)+1+abs(j-Y);
			a[min(x,y)]++;
		}
	for(int i=1;i<n;i++)printf("%lld\n",a[i]);
	return 0;
}

Measured memory_bytes: 2432
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
    int n;
    string s;
    cin >> n >> s;
    if (s.size() % 2 == 1) {
        cout << "No" << endl;
    }
    else {
        if (string(s.begin(), s.begin() + n / 2) == string(s.begin() + n / 2, s.end())) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n;
    cin>>n;
    ld sum=0;
    rep(i,n){
        ld a;
        cin>>a;
        sum+=(ld)1/a;
    }
    out((ld)1/sum);
}

Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s;cin>>s;
	for(int i = 0; i < s.size(); ++i){
	    if(i%2==0 && s[i]=='L'){
	        cout<<"No"<<endl;
	        return 0;
	    }
	    if(i%2==1 && s[i]=='R'){
	        cout<<"No"<<endl;
	        return 0;
	    }
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 504
#pragma GCC optimize(2)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
#include <sstream>
#include <ctime>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mes(a, b) memset((a), (b), sizeof (a))
#define IosF ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;

struct Point{
    double x, y;
    Point(double a = 0, double b = 0) : x(a), y(b) {};
};

typedef Point Vector;
inline Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y + B.y);}
inline Vector operator - (Vector A, Vector B) {return Vector(A.x - B.x, A.y - B.y);}
inline Vector operator * (Vector A, double x) {return Vector(A.x * x, A.y * x);}
inline Vector operator / (Vector A, double x) {return Vector(A.x / x, A.y / x);}
inline double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //向量点乘
inline double Len(Vector A) {return sqrt(Dot(A, A));}
inline double Ang(Vector A, Vector B) {return acos(Dot(A, B) / Len(A) / Len(B));} //向量夹角
inline double Cro(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //向量叉乘
inline double Area(Vector A, Vector B) {return Cro(A, B) * 0.5;} //组成三角形面积
inline Vector Rotate(Vector A, double rad) {return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));} //向量逆时针旋转角度rad
inline Vector Normal(Vector A) {double len = Len(A); return Vector(-A.y / len, A.x / len);}//求向量A的单位法线

typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 10;
const int M = 0x3f3f3f3f;
const int inf = 0x7fffffff;
const int mod = 9901;
const double PI = acos(-1);

map<string, int> mp;
inline void Solve() {
    int n;
    cin >> n;
    string str;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;

    for ( int i = 0; i < n; i ++ ) {
        cin >> str;
        mp[str] ++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

int main() {
    IosF;
    Solve();
    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ar              array
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int32_t main()
{
	k_007();
	int n, m;
	cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
}


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

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

#define is_uruu leapyear
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,a) for(int i=0;i<(a);++i)

int n, C[2000000]={0};

void countSort(int A[], int B[], int k){
	
	FOR(i, 0, n){
		C[A[i]]++;
	}
	FOR(i, 1, k+1){
		C[i] += C[i-1];
	}
	ROF(i, n-1, -1){
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}
}
	
int main(){
	
	int A[2000000], B[2000000];
	cin >> n;
	FOR(i, 0, n){
		cin >> A[i];
	}
	
	countSort(A, B, 10000);
	
	FOR(i, 1, n) cout << B[i] << " ";
	cout << B[n] << endl;
	
	return 0;
}


Measured memory_bytes: 18736
from collections import defaultdict
from heapq import heappop, heappush
import sys
input=sys.stdin.readline

class Graph():

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra():

    def __init__(self, graph, start):
        self.g = graph.graph

        self.dist = defaultdict(lambda: float("inf"))
        self.dist[start] = 0

        self.prev = defaultdict(lambda: None)

        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            dist_u, u = heappop(self.Q)

            if self.dist[u] < dist_u:
                continue

            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):

        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal

        while node is not None:
            path.append(node)
            node = self.prev[node]

        return path[::-1]

ga=Graph()
gb=Graph()
n,m,s,t=map(int,input().split())
for _ in range(m):
    u,v,a,b=map(int,input().split())
    ga.add_edge(u,v,a)
    ga.add_edge(v,u,a)
    gb.add_edge(u,v,b)
    gb.add_edge(v,u,b)

da = Dijkstra(ga,s)
db = Dijkstra(gb,t)
x=[]
for i in range(1,n+1):
    x.append(da.shortest_distance(i)+db.shortest_distance(i))
for i in range(n-2,-1,-1):
    x[i]=min(x[i],x[i+1])
for i in range(n):
    print(10**15-x[i])


Measured memory_bytes: 143604
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string a, b;
	cin >> a >> b;
	int r(string x);
	int s=r(a+b);
	if (int(sqrt(s))==sqrt(s)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
int r(string x)
{
	int t=0, j;
	for (j=0; j<x.size(); j++) t=t*10+(x[j]-'0');
	return t;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int n = get<int>();
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for (int i = 0; i < n; i++)
        a[i] = get<int>();
    int m = 0;
    for (int i = 0; i < n; i++) {
        m = max(a[i], m);
        b[i] = m;
    }
    m = 0;
    for (int i = n-1; i >= 0; i--) {
        m = max(a[i], m);
        c[i] = m;
    }
    for (int i = 0; i < n; i++) {
        int ans;
        if (i == 0) {
            ans = c[i+1];
        } else if (i == n-1) {
            ans = b[i-1];
        } else {
            ans = max(b[i-1], c[i+1]);
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3968
import fractions
a,b,c,d = map(int,input().split())
cd = (c*d)//fractions.gcd(c,d)
whole = b - a + 1
tmp1 = b//c - (a-1)//c
tmp2 = b//d - (a-1)//d
tmp3 = b//cd - (a-1)//cd
print(whole-tmp1-tmp2+tmp3)

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

int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    if ((A+B) > (C+D)) {
        cout << "Left" << endl;
    } else if ((A+B) == (C+D)) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256