akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

ll n;
int a, b, c, d;
unordered_map<ll, ll> mp;

ll rec(ll i)
{
  ll& m = mp[i];
  if (i == 0 || m != 0)
    return m;
  ll ret;
  if (c / d < i - i / 5 - i % 5)
    ret = i % 5 * d + c + rec(i / 5);
  else
    ret = d * (i - i / 5) + rec(i / 5);
  if (b / d < i - i / 3 - i % 3)
    ret = min(ret, i % 3 * d + b + rec(i / 3));
  else
    ret = min(ret, d * (i - i / 3) + rec(i / 3));
  if (a / d < i - i / 2 - i % 2)
    ret = min(ret, i % 2 * d + a + rec(i / 2));
  else
    ret = min(ret, d * (i - i / 2) + rec(i / 2));
  if (i % 5 != 0)
  {
    if (c / d < i - (i + 4) / 5 - 5 + i % 5)
      ret = min(ret, (5 - i % 5) * d + c + rec((i + 4) / 5));
    else
      ret = min(ret, d * (i - (i + 4) / 5) + rec((i + 4) / 5));
  }
  if (i % 3 != 0)
  {
    if (b / d < i - (i + 2) / 3 - 3 + i % 3)
      ret = min(ret, (3 - i % 3) * d + b + rec((i + 2) / 3));
    else
      ret = min(ret, d * (i - (i + 2) / 3) + rec((i + 2) / 3));
  }
  if (i % 2 != 0)
  {
    if (a / d < i - (i + 1) / 2 - 2 + i % 2)
      ret = min(ret, (2 - i % 2) * d + a + rec((i + 1) / 2));
    else
      ret = min(ret, d * (i - (i + 1) / 2) + rec((i + 1) / 2));
  }
  m = ret;
  return ret;
}


int main()
{
  int t;
  cin >> t;
  rep(i, t)
  {
    cin >> n >> a >> b >> c >> d;
    mp.clear();
    mp[1] = d;
    cout << rec(n) << endl;
  }
  return 0;
}

Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define inf 2e18
#define pi acos(-1)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>p;
int main()
{
    //freopen("in.txt", "r", stdin);
    double a, b, x;
    cin >> a >> b >> x;
    double s = x / a;
    double rad;
    if(s >= a*b / 2)
    {
        double h = (a*b-s) *2/a;
        rad = atan2(h, a);
    }
    else
    {
        double w = s*2/b;
        rad = atan2(b, w);
    }
    double pk=(rad*360)/(pi*2);
    printf("%.10f",pk);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define var auto
using namespace std;
using ll = long long;
using P = pair<int, int>;
#ifdef DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; cout << a << endl; return 1; } cout << a << endl; return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; cout << a << endl; return 1; } cout << a << endl; return 0; }
#else
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; }
#endif
const ll INF = 1LL << 60;
const int MAX_VALUE = 10e4+10; // 10^5
const int MAX_ITEM = 10e1+10; // 10^2

ll dp[MAX_ITEM][MAX_VALUE] = {0}; // 重さ

int main() {
  int n;
  ll w;
  cin >> n >> w;
  ll weight[n], value[n];
  rep(i,n) cin >> weight[i] >> value[i];

  // 最小化問題なのでINF埋め
  rep(i,MAX_ITEM) {
    rep(j,MAX_VALUE) {
      if (j == 0) continue;
      dp[i][j] = INF;
    }
  }

  rep(i,n) {
    rep(j,MAX_VALUE) {
      // 選ばない
      chmin(dp[i+1][j], dp[i][j]);

      // 選びたい
      if (j - value[i] >= 0) {
        chmin(dp[i+1][j], weight[i] + dp[i][j - value[i]]);
      }
    }
  }

  // 
  int res = 0;
  rep(i, MAX_VALUE) {
    if (dp[n][i] > w) continue;
    res = i;
  }

  cout << res << endl;
}


Measured memory_bytes: 86144
// extern crate rand;
// use rand::prelude::*;
use std::cmp;
fn main() {
    // test();
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let a: Vec<i64> = (0..n).map(|_| sc.read()).collect();
    println!("{}", solve(&a));
}

fn test() {
    // let mut rng = thread_rng();
    // let n = 10;
    // let t = 4;
    // let mut x = vec![0; n];
    // for _ in 0..t {
    //     let i = rng.gen_range(0, n - 1);
    //     x[i + 1] = x[i] + 1;
    // }
    // if solve(&x) > t {
    //     println!("{:?}", x);
    //     println!("{}", solve(&x));
    // }
}

fn solve(a: &Vec<i64>) -> i64 {
    let n = a.len();

    if a[0] != 0 {
        return -1;
    }

    for i in 1..n {
        if a[i] > a[i - 1] + 1 {
            return -1;
        }
    }

    let mut ans = 0;
    let mut cur = 0;
    for i in (0..n).rev() {
        if cur < a[i] {
            ans += a[i];
        }
        cur = cmp::max(a[i] - 1, 0);
    }

    return ans;
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 6524
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);


    string S;
    cin >> S;

    string nota = "KIHBR";
    int npos = 0;

    bool ok = true;
    REP(i, S.size()) {
        char c = S[i];
        if (c == 'A') {
            if (i == 0 || i == S.size() - 1) continue;
            if (S[i + 1] == 'B') continue;
            if (S[i + 1] == 'R') continue;
            ok = false;
            break;
        } else {
            if (npos >= nota.size() || c != nota[npos]) {
                ok = false;
                break;
            }
            npos++;
        }
    }
    if (npos != nota.size()) {
        ok = false;
    }
    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 24 14:53:50 2018
ITP22B
@author: maezawa
"""

from collections import deque

n, q = list(map(int, input().split()))
d = [deque() for _ in range(n)]


for i in range(q):
    c = list(map(int, input().split()))
    if c[0] == 0:
        d[c[1]].append(c[2])
    elif c[0] == 1:
        if d[c[1]]:
            print(d[c[1]][0])
    else:
        if d[c[1]]:
            d[c[1]].popleft()





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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y;
    cin >> x >> y ;
    if(x<y)printf("%s\n","a < b");
    else if(x>y)printf("%s\n","a > b");
    else printf("%s\n","a == b");
    }


Measured memory_bytes: 3052
a=int(input())
p=0
x=0
y=0
z=0
for i in range(0,a+1):
	if i ==0:
		x=2
		z=2
	elif i ==1:
		y=1
		z=1
	else:
		z=x+y
		x=y
		y=z
print(z)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define print(x) cout << (x) << endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n; cin >> n;
	string s[n]; for(ll i = 0; i < n; i++)cin >> s[i];
	
	vector<P> p, m;
	for(auto si : s){
		ll mn = 0;
		ll cnt = 0;
		
		for(auto c : si){
			if(c == '('){
				cnt++;
			}
			else{
				cnt--;
			}
			mn = min(mn, cnt);
		}
		
		if(cnt >= 0){
			p.push_back(P(mn, cnt));
		}
		else{
			m.push_back(P(mn-cnt, cnt));
		}
	}
	sort(p.begin(), p.end(), greater<>());
	sort(m.begin(), m.end());
	
	bool ans = true;
	ll res = 0;
	for(auto x : p){
		if(res + x.first < 0)ans = false;
		res += x.second;
	}
	
	for(auto x : m){
		if(res + x.first + x.second < 0)ans = false;
		res += x.second;
	}
	
	if(res != 0)ans = false;
	print(ans? "Yes" : "No")
	
	return 0;
}

Measured memory_bytes: 50248
#include<bits/stdc++.h>
using namespace std;
typedef uint64_t  ut;
/*条件によって味指標の最小値がなんであるのかが変わる*/

ut gcd(ut a, ut b){
  if(a == 0 || b == 0)
    return -1;
  else if(a > b){
    if(a % b == 0)
      return b;
    else
      return gcd(a%b, b);
  }else if(b >= a){
      if(b % a == 0)
        return a;
      else
        return gcd(b%a, a);
  }

}

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

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

  ut surA = A/C + A/D - A/lcm(C, D);      //1からAまで CまたはDで割り切れる整数の数
  ut surB = B/C + B/D - B/lcm(C, D);      //1からBまでCまたはDで割り切れる整数の数
  ut nsurA = A - surA;                                    
  ut nsurB = B - surB;
  ut nsur = nsurB - nsurA;                            // A < c <= Bかつ当該問題の条件を満たす整数の数

  /*nsurはAより大きくB以下の数が対象   よってAがCとDで割り切れるかで判別*/

  if(A % C != 0 && A % D != 0)                                
    cout << nsur + 1 << endl;
  else
    cout << nsur << endl;

  return 0;
}

Measured memory_bytes: 256
m, d = map(int, input().split())
cnt = 0
for i in range(1, m + 1):
    for j in range(22, d + 1):
        s = str(j)
        if int(s[0]) >= 2 and int(s[1]) >= 2 and i == int(s[0]) * int(s[1]):
            cnt += 1
print(cnt)

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    vs s(3);
    rep(i,3)cin >> s[i];
    cout << s[0][0] << s[1][0] << s[2][0] << endl;
    return 0;
}

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

int main() {
  int N;
  double a, ans=0;
  cin >> N;
  string str;
  vector<double> item(N);

  cout << fixed;
  
  for (int i = 0; i < N; i++) {
    cin >> a >> str;
    if (str == "JPY") item.at(i) = a;
    else item.at(i) = a * 380000;
  }
  
  sort(item.begin(), item.end());
  for (int j = 0; j < N; j++) ans = ans + item.at(j);

  cout << ans << endl;
}

Measured memory_bytes: 3744
an,bn,m = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x,y,c = [],[],[]
for i in range(m):
  xt,yt,ct = map(int,input().split())
  x.append(xt)
  y.append(yt)
  c.append(ct)
#
'''
print('{} {} {}'.format(an,bn,m))
print(a)
print(b)
print(x)
print(y)
print(c)
'''
#

ans = min(a)+min(b)
for i in range(m):
  ans = min(ans,a[x[i]-1]+b[y[i]-1]-c[i],)
#
print(ans)


Measured memory_bytes: 24620
using System;
class Multiplication3
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
            ulong a = ulong.Parse(input[0]);
            decimal b = decimal.Parse(input[1]);

            ulong ab = (ulong)(a * b);
            Console.WriteLine(ab);
        }
    }

Measured memory_bytes: 27576
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

struct UnionFind {
    typedef vector<int> vi;
    int n;
    vi par, rank, cnt;

    UnionFind(int n)
        : n(n), par(n), rank(n, 0), cnt(n, 1) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int find(int a) {
        if (par[a] == a) return a;
        return par[a] = find(par[a]);
    }

    void unite(int a, int b) {
        a = find(a);
        b = find(b);

        if (a == b) return;
        if (rank[a] < rank[b]) {
            par[a] = b;
            cnt[b] += cnt[a];
        } else {
            par[b] = a;
            cnt[a] += cnt[b];
            if (rank[a] == rank[b]) rank[a]++;
        }
    }

    int count(int a) { return cnt[find(a)]; }

    bool same(int a, int b) { return find(a) == find(b); }
};


int main() {
    fastio();

    int n, k, l;
    cin >> n >> k >> l;

    UnionFind uf1(n), uf2(n);

    forn(i, k) {
        int p, q;
        cin >> p >> q;
        p--, q--;
        uf1.unite(p, q);
    }

    forn(i, l) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        uf2.unite(s, t);
    }

    map<pii, int> cnt;

    forn(i, n) {
        cnt[mp(uf1.find(i), uf2.find(i))]++;
    }

    forn(i, n) {
        cout << cnt[mp(uf1.find(i), uf2.find(i))] << ' ';
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 16640
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

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

using namespace std;

const char *W[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat","All"};
const char *D[]={"Day","Night","All"};

int week,daynight; // 突然変異する曜日, 時間帯

bool isOK(int w,int h){
	return (week==7 || week==w) && (daynight==2 || (daynight==0)==(6<=h && h<18));
}

// jikan wo t dake susumeru
void go(int &w,int &h,int &m,int t){
	w+=t/1440;
	t%=1440;
	h+=t/60;
	t%=60;
	m+=t;
	if(m>=60) m-=60, h++;
	if(h>=24) h-=24, w++;
	w%=7;
}

int main(){
	int born,n,end,stage;
	double p;
	char str1[8],str2[8];
	while(~scanf("%d%d%d%s%s%lf%d",&born,&n,&end,str1,str2,&p,&stage)&&born!=0){
		rep(i,8) if(strcmp(str1,W[i])==0) { week=i; break; }
		rep(i,3) if(strcmp(str2,D[i])==0) { daynight=i; break; }
		p=1-pow(1-1/p,n);

		double ans=0;
		rep(w0,7) rep(h0,24) rep(m0,60) { // initial condition
			double tmp=0;
			int w=w0,h=h0,m=m0;

			double q=p; // 今のステージで突然変異する確率
			rep(i,stage){
				bool ok1=isOK(w,h);
				go(w,h,m,born);
				bool ok2=isOK(w,h);
				go(w,h,m,end-born);
				if(ok1 && ok2) tmp+=q, q*=1-p;
			}
			ans=max(ans,tmp);
		}

		printf("%.9f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1096
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut spans = vec![];
    for i in 0..n {
        let v = read_vec::<usize>();
        let (l, r) = (v[0], v[1]);
        spans.push((r + 1 - l, l, r));
    }
    spans.sort();
    // spans.reverse();

    let mut answers = vec![0; m + 1];
    let mut spans_pointer = 0;
    let mut seg = LazySegmentTree::new(m + 1);
    for mi in 1..m + 1 {
        while spans_pointer < spans.len() && spans[spans_pointer].0 < mi {
            let (_, l, r) = spans[spans_pointer];
            seg.add(l, r + 1, 1, 0, 0, m + 1);
            spans_pointer += 1;
        }
        answers[mi] = spans.len() - spans_pointer;
        let mut cur_pos = mi;
        while cur_pos <= m {
            answers[mi] += seg.getsum(cur_pos, cur_pos + 1, 0, 0, m + 1) as usize;
            cur_pos += mi;
        }
    }
    for &ans in &answers[1..m + 1] {
        println!("{}", ans);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[derive(Debug)]
struct LazySegmentTree {
    n: usize,
    data: Vec<i64>,
    datb: Vec<i64>,
}

impl LazySegmentTree {
    fn new(sz: usize) -> LazySegmentTree {
        let mut n = 1;
        while n < sz {
            n *= 2;
        }
        LazySegmentTree {
            n: n,
            data: vec![0i64; 2 * n - 1],
            datb: vec![0i64; 2 * n - 1],
        }
    }

    fn add(&mut self, a: usize, b: usize, x: i64, k: usize, l: usize, r: usize) {
        if a <= l && r <= b {
            self.data[k] += x;
        } else if l < b && a < r {
            self.datb[k] += (min(b, r) - max(a, l)) as i64 * x;
            self.add(a, b, x, k * 2 + 1, l, (l + r) / 2);
            self.add(a, b, x, k * 2 + 2, (l + r) / 2, r);
        }
    }

    fn getsum(&mut self, a: usize, b: usize, k: usize, l: usize, r: usize) -> i64 {
        if b <= l || r <= a {
            return 0;
        }
        if a <= l && r <= b {
            return self.data[k] * (r - l) as i64 + self.datb[k];
        } else {
            let mut res = (min(b, r) - max(a, l)) as i64 * self.data[k];
            res += self.getsum(a, b, k * 2 + 1, l, (l + r) / 2);
            res += self.getsum(a, b, k * 2 + 2, (l + r) / 2, r);
            return res;
        }
    }
}


Measured memory_bytes: 17396
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int a,b,c,x,h=0;
    cin >> a>>b;

    c=b-a;

    for(int i=1;i<=c;i++){
        h+=i;
    }
    
    x=h-b;

    cout << x << endl;

    return 0;
}

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

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

  string s;
  cin >> s;

  if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") cout << "Yes\n";
  else cout << "No\n";

  return (0);
}


Measured memory_bytes: 3604
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll m,d,ans=0;
  cin>>m>>d;
  for(ll i=1;i<=m;i++){
    for(ll j=1;j<=d;j++){
      if(j/10>1&&j%10>1&&(j/10)*(j%10)==i){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		int sn = Integer.parseInt(br.readLine());
		List<Integer> slist = Arrays.stream(br.readLine().split(" "))
				.map(Integer::parseInt)
				.collect(Collectors.toList());
		int qn = Integer.parseInt(br.readLine());
		List<Integer> qlist = Arrays.stream(br.readLine().split(" "))
				.map(Integer::parseInt)
				.collect(Collectors.toList());
		
		int count = 0;
		for(int q: qlist){
			for(int s: slist){
				if(q == s){
					count++;
					break;
				}
			}
		}
		
		System.out.println(count);
		
	}
}



Measured memory_bytes: 32956
#include<stdio.h>
#define NIL -1 /*??????????????????????????????????????????????????\?????????????????????*/
struct Node{

  int left;
  int right;
  int parent;

};

void prewalk(int);
void inorderwalk(int);
void postorderwalk(int);

struct Node inputNodedata[10000];

int main(){

  int sumNode,Nodeid,i,j,root,leftdata,rightdata,roott;

  scanf("%d",&sumNode);
  for(i = 0; i < sumNode; i++){

    inputNodedata[i].left = NIL;
    inputNodedata[i].right = NIL;
    inputNodedata[i].parent = NIL;
  }
 

  for(i = 0; i < sumNode; i++){

    scanf("%d",&Nodeid);
    scanf("%d",&leftdata);
    scanf("%d",&rightdata);

    inputNodedata[Nodeid].left = leftdata; /*????????????????±????????????????????????§??\?????????leftdata??¨rightdata????????¨???Nodeid?????????????????¨??????????????¨???????????¨??????*/
    inputNodedata[Nodeid].right = rightdata;

    if(leftdata != NIL) {

      inputNodedata[leftdata].parent = Nodeid;

    }

    if(rightdata != NIL){

      inputNodedata[rightdata].parent = Nodeid;

    }

    /*    if(inputNodedata[i].parent == NIL){*/ /*?????????root??????????????¢??????????????????????????\????????¨????????????????????\????????????????????????parent??????????????¨????????¨?????£???????????????

      roott = i;

      } */  
  }


  for(i = 0; i < sumNode; i++){

    if(inputNodedata[i].parent == NIL){

      root = i;

    }
  }

 
  printf("Preorder\n");
  prewalk(root);
  printf("\n");
  printf("Inorder\n");
  inorderwalk(root);
  printf("\n");
  printf("Postorder\n");
  postorderwalk(root);
  printf("\n");

  /*  for(i = 0; i < sumNode; i++){

    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,inputNodedata[i].parent,sibling(i),children(i),depth(i),height(i));
     judge(i);

     }*/



  return 0;

}

void prewalk(int Nodeid){


  if(Nodeid != NIL){

    printf(" %d",Nodeid);
    prewalk(inputNodedata[Nodeid].left);
    prewalk(inputNodedata[Nodeid].right);
  }  

}

void inorderwalk(int Nodeid){

  if(Nodeid != NIL){

    inorderwalk(inputNodedata[Nodeid].left);
    printf(" %d",Nodeid);
    inorderwalk(inputNodedata[Nodeid].right);

  }
}

void postorderwalk(int Nodeid){

  if(Nodeid != NIL){

    postorderwalk(inputNodedata[Nodeid].left);
    postorderwalk(inputNodedata[Nodeid].right);
    printf(" %d",Nodeid);
  }

}

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);

    for (int i = 0; i < N; i++) {
        cin >> d.at(i);
    }

    int sum = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            sum += d.at(i) * d.at(j);
        }
    }
    cout << sum << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long K, long long X)
{
    if (K * 500 >= X)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long K;
    scanf("%lld", &K);
    long long X;
    scanf("%lld", &X);
    solve(K, X);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 998244353
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = INT_MAX/4;
const int N=2e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int read(){
    int x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}/*
struct Edge{
	int nxt,v;
//	int w;
//	int id;
}e[N<<1];
void add(int u,int v){
	e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;
	e[++tot].v=u,e[tot].nxt=head[v],head[v]=tot;
}*/

struct Segment_Tree{ 
	int flg[N<<2],mn[N<<2],t[N<<2];
	#define ls(x) (x<<1)
	#define rs(x) (x<<1|1)
	void update(int pos,int l,int r){
		mn[pos]=min(mn[ls(pos)],mn[rs(pos)]);	
	}
	void build(int pos,int l,int r){
		flg[pos]=0;
		if(l==r){
			t[pos]=l;
			mn[pos]=0;
			return;
		}
		int mid=l+r>>1; 
		build(ls(pos),l,mid),build(rs(pos),mid+1,r);
		update(pos,l,r);
	}
	void pushdown(int pos,int l,int r){
		if(!flg[pos]) return;
		flg[pos]=0,flg[ls(pos)]=flg[rs(pos)]=1;
		int mid=l+r>>1;
		t[ls(pos)]=t[rs(pos)]=t[pos];
		mn[ls(pos)]=l-t[pos],mn[rs(pos)]=mid+1-t[pos]; 
	}
	int calc(int pos,int l,int r,int nl,int nr){
		if(nl<=l&&r<=nr){
			return mn[pos];
		} 
		pushdown(pos,l,r);
		int mid=l+r>>1;
		if(nl>mid) return calc(rs(pos),mid+1,r,nl,nr);
		if(nr<=mid) return calc(ls(pos),l,mid,nl,nr);
		return min(calc(rs(pos),mid+1,r,nl,nr),calc(ls(pos),l,mid,nl,nr));
	}
	void change(int pos,int l,int r,int nl,int nr,int v){
		if(nl>nr) return;
		if(nl<=l&&r<=nr){
			flg[pos]=1;
			t[pos]=v;
			mn[pos]=l-v;
//			,bug(mn[pos]);
			return;
		} 
		pushdown(pos,l,r);
		int mid=l+r>>1;
		if(nr>mid) change(rs(pos),mid+1,r,nl,nr,v);
		if(nl<=mid) change(ls(pos),l,mid,nl,nr,v);	
		update(pos,l,r);
	} 
	int find(int pos,int l,int r,int v){
		if(l==r){
			return t[pos];
		}
		pushdown(pos,l,r);
		int mid=l+r>>1;
		if(v<=mid) return find(ls(pos),l,mid,v);
		else return find(rs(pos),mid+1,r,v);
		update(pos,l,r);
	}
}sgt;

int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
	int n=read(),m=read();
	sgt.build(1,1,m);
	for(int i=1;i<=n;i++) {
		int l=read(),r=read();
		int x=(l>1)?(sgt.find(1,1,m,l-1)):(-INF);
		
//		cerr<<l<<" "<<r<<" "<<x<<endl;
		sgt.change(1,1,m,l,r,x);
		int ans=sgt.calc(1,1,m,1,m);
		if(ans>=0&&ans<=m)	cout<<i+ans<<endl;
		else cout<<-1<<endl; 
	}
	return 0;
}


Measured memory_bytes: 9764
use std::io;

fn f(mut n:u64, mut m: u64) -> u64 {

    while m > 0 {
        let t = n;
        n = m;
        m = t % m;
    }

    n
}

fn main() {
    let mut s = String::new();
    let stdin = io::stdin();

    let _ = stdin.read_line(&mut s);

    let vec: Vec<&str> = s.split_whitespace().collect();
    let n : u64 = vec[0].parse().unwrap();
    let m : u64 = vec[1].parse().unwrap();

    if m < n {
        println!("{}", f(n, m));
    }
    else {
        println!("{}", f(m, n));
    }
    
}



Measured memory_bytes: 5032
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]


def match2int(x, y):
    x, y = min(x, y), max(x, y)
    return (2 * n - 1 - x) * x // 2 + y - x - 1


match_sm = n * (n - 1) // 2

adj = [[] for _ in range(match_sm)]
in_deg = [0] * match_sm
for i, li in enumerate(a):
    for j, k in zip(li, li[1:]):
        j -= 1
        k -= 1
        match1 = match2int(i, j)
        match2 = match2int(i, k)
        adj[match1].append(match2)
        in_deg[match2] += 1

cnd = [i for i, e in enumerate(in_deg) if e == 0]
day = 0
while cnd:
    nxt_cnd = []
    for u in cnd:
        for v in adj[u]:
            in_deg[v] -= 1
            if in_deg[v] == 0:
                nxt_cnd.append(v)

    cnd = nxt_cnd
    day += 1

if in_deg.count(0) != match_sm:
    day = -1

print(day)


Measured memory_bytes: 117552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
int main(){
  int a,b;
  cin >> a >> b;
  if(a*b%2==0) cout << "Even" << endl;
  else cout << "Odd" << endl;
  return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2100000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;

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;
}

void mod(ll &val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> graph[N];
    int start,last;
    for(int i = 0;i < M;i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        if(i == 0) {
            start = A;
            last = B;
        }
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    vector<bool> used(N);
    deque<int> que;
    que.push_front(start);
    que.push_back(last);
    used.at(start) = true;
    used.at(last) = true;
    while(true) {
        bool ret = false;
        for(auto x:graph[start]) {
            if(!used.at(x)) {
                start = x;
                que.push_front(x);
                used.at(x) = true;
                ret = true;
                break;
            }
        }
        for(auto x:graph[last]) {
            if(!used.at(x)) {
                last = x;
                que.push_back(x);
                used.at(x) = true;
                ret = true;
                break;
            }
        }
        if(ret == false) {
            break;
        }
    }
    cout << que.size() << endl;
    for(auto x:que) {
        cout << x + 1 << " ";
    }
    cout << endl;
}

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

int main() {
	int n;
	string s;
	std::cin >> n >> s;
	
	int ans = 0;
	
	for (int i = 0; i < n-2; i++) {
	    if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C') ans++;
	}
	
	std::cout << ans << std::endl;
	
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n;
    n=s.size();
    vector <int> r(n),l(n);

    int r2,l2,k2,lk;
    r2=0;
    l2=0;
    rep(i,n){
        if(s[i]=='L' and lk!=0){
            ++lk;
            if(lk%2==0){
            ++r[i-lk];
            }
            else{
                ++l[i-lk+1];
            }
        }
        else if(s[i]=='L'){
            l[i]=1+l2;
            r[i-1]=r2;
            r2=0;
            l2=0;
            lk=1;
        }
        else{
            lk=0;
            k2=r2;
            r2=l2;
            l2=k2;
            ++r2;
        }
    }

    rep(i,n){
        cout << max(r[i],l[i]) << endl;
    }
    

    return 0;
}

Measured memory_bytes: 1408
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    A, B, C, X, Y = map(int, input().split())
    money = []
    money.append(X * A + Y * B)
    if X > Y:
        money.append(X * 2 * C)
        money.append(Y * 2 * C + (X - Y) * A)
    elif X == Y:
        money.append(X * 2 * C)
    else:
        money.append(Y * 2 * C)
        money.append(X * 2 * C + (Y - X) * B)
    print(min(money))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <cmath>
#include <string.h>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

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

const int N = 500;

using namespace std;

int cal_min_fight(int s_1, int s_2, int s_3);

int main() {
	int p, q, r;
	
	cin >> p >> q >> r;
	
	cout << cal_min_fight(p + q, p + r, q + r) << endl;
	
    return 0;
}

int cal_min_fight(int s_1, int s_2, int s_3) {
	int min;
	min = (s_1 > s_2) ? s_2 : s_1;
	min = (min > s_3) ? s_3 : min;
	return min;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);

  if(a + b > c + d){
    puts("Left");
  }
  else if(a + b < c + d){
    puts("Right");
  }
  else{
    puts("Balanced");
  }
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <vector>
#include <string>
#include <ctype.h>
#include <set>
#include <map>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<tr1/unordered_set>
#include<tr1/unordered_map>


#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
//#define int long long
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1000000009;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;
const double pi=6.283185307179586232;

using namespace std;

#pragma GCC optimize ("Ofast")
static auto _ = [] { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); return 0; } ();

int main() {
    double i;
    cin>>i;
    cout<<i*pi;
    return 0;
}



Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}

#define ll long long
#define f first
#define s second
#define pb push_back
#define INF 1000000000000000000
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

int main()
{
	ll A, B;
	cin >> A >> B;

	cout << max(2 * A - 1, max(2 * B - 1, A + B)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define ll long long
const int inf = 1e8;
const ll INF = 1e18;
const int MAXN = 3e5 + 200;
const  long double eps = 1e-9;
const long double pi = acos(-1.0);
using namespace std;

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

int n;
int a[MAXN];
void solve() {
    cin >> n;
    int ans = 1e9;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = -200; i <= 200; i++){
        int cost = 0;
        for (int j = 1; j <= n; j++){
            cost += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}



int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(40);
    //freopen("inevit.in", "r", stdin);
    //freopen("inevit.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++)
        solve();


}

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


void preprocessor(int a[][1024],int h,int w){ //1-indexed
	for(int i=0;i<h+1;i++)for(int j=0;j<w;j++)a[i][j+1]+=a[i][j];
	for(int j=0;j<w+1;j++)for(int i=0;i<h;i++)a[i+1][j]+=a[i][j];
}
int calc(int s[][1024],int y1,int x1,int y2,int x2){
	return s[y2][x2]-s[y2][x1-1]-s[y1-1][x2]+s[y1-1][x1-1];
}

int J[1001][1024],O[1001][1024],I[1001][1024];
int n,m,k;

int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char c;
			cin>>c;
			J[i][j]=c=='J';
			O[i][j]=c=='O';
			I[i][j]=c=='I';
		}
	}
	preprocessor(J,n,m);
	preprocessor(O,n,m);
	preprocessor(I,n,m);
	while(k--){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		cout<<calc(J,a,b,c,d)<<' ';
		cout<<calc(O,a,b,c,d)<<' ';
		cout<<calc(I,a,b,c,d)<<endl;
	}
	return 0;
}

Measured memory_bytes: 13132
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    int n; cin >> n;
    ll ans = 0;
    ll ima = 0LL;
    rep(i,n){
        ll a; cin >> a;
        if (ima <= a) ima = a;
        else ans += ima - a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// 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;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

vector<vector<mint>> dp(1000, vector<mint>(1000, 0));

int main(){
  ll H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, H){
    cin >> a.at(i);
  }
  dp.at(0).at(0) = 1;
  rep(i, H){
    rep(j, W){
      if(i == 0 && j == 0){
        continue;
      }
      if(a.at(i).at(j) == '#'){
        continue;
      }
      if(i == 0){
        if(a.at(0).at(j-1) == '.'){
          dp.at(0).at(j) = dp.at(0).at(j-1);
        }
      }
      else if(j == 0){
        if(a.at(i-1).at(0) == '.'){
          dp.at(i).at(0) = dp.at(i-1).at(0);
        }
      }
      else{
        if(a.at(i-1).at(j) == '.'){
          dp.at(i).at(j) += dp.at(i-1).at(j);
        }
        if(a.at(i).at(j-1) == '.'){
          dp.at(i).at(j) += dp.at(i).at(j-1);
        }
      }
    }
  }
  cout << dp.at(H-1).at(W-1).x << endl;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define mp(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define all(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define vec vector
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
	int a, b, c;
	int m[3] = {1,2,3};
	
	cin >> a >> b;
	rep(i,3){
		if(m[i] != a && m[i] != b)	cout <<m[i];
	} 
}




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

int main() {
  int n, q;
  cin >> n;
  vector<int> v(n + 1), w(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v.at(i) >> w.at(i);
  }
  cin >> q;
  vector<int> u(q), l(q);
  for (int i = 0; i < q; i++) {
    cin >> u.at(i) >> l.at(i);
  }
  int d = 11;
  while ((1 << d) > n) d--;
  vector<vector<int>> dp(1 << d, vector<int>(100001));
  for (int i = 1; i < (1 << d); i++) {
    for (int j = 0; j <= 100000; j++) {
      dp.at(i).at(j) = dp.at(i / 2).at(j);
      if (j < w.at(i)) continue;
      dp.at(i).at(j) = max(dp.at(i).at(j), dp.at(i / 2).at(j - w.at(i)) + v.at(i));
    }
    for (int j = 1; j <= 100000; j++) {
      dp.at(i).at(j) = max(dp.at(i).at(j), dp.at(i).at(j - 1));
    }
  }
  for (int i = 0; i < q; i++) {
    if (u.at(i) < (1 << d)) {
      cout << dp.at(u.at(i)).at(l.at(i)) << "\n";
    } else {
      int dq = 0, ans = 0;
      while ((u.at(i) >> dq) >= (1 << d)) dq++;
      for (int j = 0; j < (1 << dq); j++) {
        int sv = 0, sw = 0;
        for (int k = 0; k < dq; k++) {
          if ((j >> k) & 1) continue;
          sv += v.at(u.at(i) >> k);
          sw += w.at(u.at(i) >> k);
        }
        if (sw > l.at(i)) continue;
        ans = max(ans, sv + dp.at(u.at(i) >> dq).at(l.at(i) - sw));
      }
      cout << ans << "\n";
    }
  }
}


Measured memory_bytes: 809248
import java.util.Scanner;

public class Main {

	static int n,m,a;
	static int[][] field;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			n=cin.nextInt();
			m=cin.nextInt();
			a=cin.nextInt();
			if(n+m+a==0){
				break;
			}
			field=new int[n+2][1020];
			int max=0;
			for(int i = 0;i<m;i++){
				int x = cin.nextInt();
				int y = cin.nextInt();
				int z = cin.nextInt();
				field[y][x]=field[z][x]=i+1;
				max=Math.max(x,max);
			}
			
			/*
			for(int i = 1;i<max+2;i++){
				for(int j = 1;j<n+1;j++){
					System.out.print(field[j][i]+  " ");
					
				}
				System.out.println();
			}
			*/
			for(int i = max+1;i>=1;i--){
				if(field[a][i]>0){
					if(field[a-1][i]==field[a][i]){
						a--;
					}
					else{
						a++;
					}
				}
			}
			System.out.println(a);
		}

	}

}

Measured memory_bytes: 16000
using System;
class aoj
{
    static void Main()
    {
        int a = 0;
        for(int i = 0; i < 5; i++)
        {
            int b = int.Parse(Console.ReadLine());
            if (b < 40)
                a += 40;
            else
                a += b;
        }
        Console.WriteLine(a / 5);
    }
}

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
char a[55];
int main(){
	int n;
	cin>>n;
	scanf("%s",a);
	int sum=0;
	for(int i=0;i<n+2;i++)
		if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')
			sum++;
	cout<<sum;
} 

Measured memory_bytes: 256
def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    r, d, x = read_int_array()
    for i in range(1, 11):
        x = r * x - d
        write(x)

main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

struct data {
	int first, second, id;
	data(int _f, int _s, int _id) : first(_f), second(_s), id(_id) {}
};

const int N = (int)1e5+5;
int n, m, len, a[N], dp[18][N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);
	scanf("%d%d", &len, &m);
	for (int i = 0; i < 18; ++i) fill(dp[i] + 1, dp[i] + n + 1, n + 5);
	for (int i = n, j = n; i >= 1; --i) {
		while (j >= 1 && a[j] - a[i] > len) --j;
		dp[0][i] = j;
	}
	for (int i = 1; i <= 17; ++i)
		for (int j = 1; j <= n; ++j)
			dp[i][j] = dp[i - 1][dp[i - 1][j]];
	for (int i = 1, u, v; i <= m; ++i) {
		scanf("%d%d", &u, &v);
		if (u > v) swap(u, v);
		int ans = 1;
		for (int i = 17; i >= 0; --i)
			if (dp[i][u] < v) u = dp[i][u], ans += (1 << i);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 8192