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

using namespace std;
typedef long long ll;

const int N = 2001000;
const int Mod = 1e9 + 7;

int Inv[N];
int Fact[N];
int iFact[N];

void add_self(int& x, int y)
{
    if((x += y) >= Mod) x -= Mod;
}

void sub_self(int& x, int y)
{
    if((x -= y) < 0)    x += Mod;
}

int mul(int x, int y)
{
    return (ll) x * y % Mod;
}

int C(int n, int k)
{
    if(n < 0 || k < 0 || n < k) return 0;

    return mul(Fact[n], mul(iFact[k], iFact[n - k]));
}

int Sum(int r, int c)
{
    int Res = 0;

    for(int x = 0; x <= r; x++) add_self(Res, C(x + c + 1, x + 1));

    return Res;
}

int main()
{
    Inv[1] = 1;
    for(int i = 2; i < N; i++)  Inv[i] = (Mod - mul(Mod / i, Inv[Mod % i])) % Mod;

    Fact[0] = iFact[0] = 1;
    for(int i = 1; i < N; i++)  Fact[i] = mul(i, Fact[i - 1]);
    for(int i = 1; i < N; i++)  iFact[i] = mul(Inv[i], iFact[i - 1]);

    int r1, c1; cin >> r1 >> c1;
    int r2, c2; cin >> r2 >> c2;

    int Ans = Sum(r2, c2);
    sub_self(Ans, Sum(r2, c1 - 1));
    sub_self(Ans, Sum(r1 - 1, c2));
    add_self(Ans, Sum(r1 - 1, c1 - 1));

    cout << Ans << endl;
}


Measured memory_bytes: 23680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		String ans="AC";
		if(s[0]!='A') ans="WA";
		int count = 0;
		for(int i=1; i<s.length;i++) {
			char c = s[i];
			if(i>1 && i<s.length-1 && c=='C') {
				count++;
				continue;
			}
			if(!Character.isLowerCase(c)) ans="WA";
		}
		if(count!=1)ans="WA";
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
/*

fix the b.
n = pb + r (0 <= r < b)
    a%b : 0,1,...,b-1,0,1,...,b-1(that appears for p times),0,1,...,r
    then , cnt += p*(max(0,b-k)) + max(0,r-k+1)

*/

//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
    ll n,k;scanf("%lld %lld",&n,&k);
    ll ans = 0;
    for(ll b = 1;b <= n;b++){
        ll p = n / b,r = n % b;
        ans += p*max(0LL,b-k) + max(0LL,r-k+1);
    }
    if(k == 0){
        ans -= n;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
N,D = map(int,input().split())
X = [tuple(map(int,input().split())) for i in range(N)]

ans = 0
for i,a in enumerate(X[:-1]):
    for b in X[i+1:]:
        d = 0
        for x,y in zip(a,b):
            d += (x-y)**2
        if d**0.5 - int(d**0.5) < 10e-10:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
int n,m,fa[100005],dis[100005];
bool ok=1;
int find(int x){
    if(fa[x]!=x){
        int nf=fa[x];
        fa[x]=find(fa[x]);
        dis[x]+=dis[nf];
    }
    return fa[x];
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++){
        int l,r,d;
        scanf("%d%d%d",&l,&r,&d);
        int rl=find(l),rr=find(r);
        if(rl==rr&&dis[l]-dis[r]!=d)
            ok=0;
        if(rl!=rr){
            fa[rl]=rr;
            dis[rl]=d+dis[r]-dis[l];
        }
    }
    if(ok)printf("Yes");
    else printf("No");
    return 0;
} 

Measured memory_bytes: 896
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<utility>
#include<functional>
#include<algorithm>
#include<bitset>
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n,a[105];
int ans=1e9;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=1;i<n;i++)
	{
		int s1=0,s2=0;
		for(int j=0;j<n;j++)
			if(j<=i)
				s1+=a[j];
			else
				s2+=a[j];
		ans=min(ans,abs(s1-s2));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>

using namespace std;


int main() {

    long N, Q;
    cin >> N >> Q;

    string s;
    cin >> s;

    vector<int> v;

    v.push_back(0);

    for (int i = 1; i < s.size(); i++) {
        if (s.substr(i - 1, 2) == "AC") {
            v.push_back(1);
        } else {
            v.push_back(0);
        }
    }

    vector<int> as;
    as.push_back(0);
    for (int i = 0; i < s.size(); i++) {
        as.push_back(as[i] + v[i]);
    }

    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;

        cout << as[r] - as[l] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1976
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	bool flag = false;
	for(int i = 0; i < n; i++){
		ll l = i*c-(n-1-i)*d, r = i*d-(n-1-i)*c;
		if(l<= b-a && b-a <= r) flag = true;
	}

	if(flag) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [list(input()) for i in range(n)]

p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
r = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

d = [0] * 5

for i in range(n):
    if s[i][0] == "M":
        d[0] += 1
    elif s[i][0] == "A":
        d[1] += 1
    elif s[i][0] == "R":
        d[2] += 1
    elif s[i][0] == "C":
        d[3] += 1
    elif s[i][0] == "H":
        d[4] += 1
        
ans = 0
for i in range(0,10):
    ans += (d[p[i]] * d[q[i]] * d[r[i]])
print(ans)

Measured memory_bytes: 20300
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

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

	if (A == B) {
		cout << A * 2 << endl;
	} else {
		ull ma = max(A, B);
		cout << ma + ma - 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from functools import reduce
from math import sqrt
def factorint(n):
    d = dict()
    for i in range(2, int(sqrt(n))+1):
        q, r = divmod(n, i)
        if r == 0:
            c = 0
            while r == 0:
                n = q
                c += 1
                q, r = divmod(n, i)
            d[i] = c
    if n != 1:
        d[n] = 1
    return d

n = int(input())
mod = 10**9 + 7
A = defaultdict(lambda:1)
for i in range(1, n+1):
    for k, v in factorint(i).items():
        A[k] += v

print(reduce(lambda x, y: x*y % mod, A.values()) if A else 1)

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

int main(){
  int n;
  cin >> n;
  ll a[3*n];
  rep(i,3*n) cin >> a[i];
  sort(a,a+3*n);
  int r = 3*n-1;
  ll ans = 0;
  rep(i,n){
    ans += a[--r];
    r--; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
s=input()
def check(s):
    if len(s)%2!=0:
        return False
    if s[0:len(s)//2]==s[len(s)//2:len(s)]:
        return True
    else:
        return False
for i in range(len(s)):
    s=s[:-1]
    if check(s):
        print(len(s))
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int N; cin >> N;
VI a(N); rep(i, 0, N) cin >> a[i];

int b = 0;
int num = 1;
bool ok = false;
rep(i, 0, N){
    if (a[i] != num) ++b;
    else {
        ok = true;
        ++num;
    }
}

cout << (ok ? b : -1) << endl;
}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int d, s, t; cin >> d >> s >> t;
    if(d <= s * t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

main()
{
    string s;
    cin>>s;
    ll sum=0;
    lop0(s.size())
    {
        sum+=(s[i]-'0');
    }
    
    if(sum%9) cout<<"No";
    else cout<<"Yes";

}



Measured memory_bytes: 3660
#include "bits/stdc++.h"

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  vvi ans(h, vi(w));
  REP(i, h)REP(j, w) {
    bool f = 0;
    if (i < b)f = !f;
    if (j < a)f = !f;
    ans[i][j] = f;
  }
  REP(i, h) {
    REP(j, w)cout << ans[i][j];
    cout << endl;
  }
  

}


Measured memory_bytes: 5248
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#define F first
#define S second
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
const int INF=2e9;
const db eps=1e-8;
template<typename T>
inline void read(T &x)
{
	x=0; int f=1; char ch=getchar();
	while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
	while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//==========================head template==========================
const int N=110;
int a[N],n;
signed main()
{
	read(n); int ans=0;
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<n;i++) {
		if(a[i]==a[i+1]) {
			++i;
			++ans;
		}
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    char o;
    while (cin >> a >> o >> b, o != '?') {
        if (o == '+') cout << a + b << endl;
        if (o == '-') cout << a - b << endl;
        if (o == '*') cout << a * b << endl;
        if (o == '/') cout << a / b << endl;
    }
}


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

#define MOD (int)1000000007

typedef long long ll;

ll power(ll e, ll x){ //e^x % MOD
    if (x == 0) return 1LL;
    if (x % 2 != 0) return ((power(e, x-1) * e) % MOD);
    ll temp = power(e, x / 2);
    return (temp * temp) % MOD;
}

void solve(void){
    int m, n;
    cin >> m >> n;
    cout << power(m, n) << endl;
}

int main(void){
  solve();
  return 0;
}



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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

int main(void) {
    int a, b, k;
    cin >> a >> b >> k;

    int div=100, cnt=0;
    while(1) {
        if(a%div==0&&b%div==0) cnt++;
        if(cnt==k) {
            cout << div << endl;
            break;
        }
        div--;
    }

    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as U

-- n := V.length v + 1
-- v ! i = 表が i 枚、裏が n - i 枚出る確率
solve :: U.Vector Double -> U.Vector Double
solve ps = U.foldl' step (U.singleton 1) ps
  where
    step !vec !p = U.generate (U.length vec + 1) $ \i ->
      if i == 0
      then (1 - p) * vec U.! i
      else if i == U.length vec
           then p * vec U.! (i - 1)
           else p * vec U.! (i - 1) + (1 - p) * vec U.! i

main = do
  n <- readLn
  -- 1 <= n <= 2999, n is odd
  ps <- U.unfoldrN n (readDoubleBS . BS.dropWhile isSpace) <$> BS.getLine
  let result = solve ps
  -- U.length result == n + 1
  print $ U.sum $ U.drop (n `quot` 2 + 1) result

readDoubleBS :: BS.ByteString -> Maybe (Double, BS.ByteString)
readDoubleBS s = case BS.readInt s of
                   Just (ipart, s') -> case BS.uncons s' of
                                         Just ('.', s'') -> case BS.readInt s'' of
                                                              Just (fpart, s''') ->
                                                                let !l = BS.length s'' - BS.length s'''
                                                                    !x | ipart >= 0 = fromIntegral ipart + fromIntegral fpart / 10^l
                                                                       | otherwise = fromIntegral ipart - fromIntegral fpart / 10^l
                                                                in Just (x, s''')
                                                              Nothing -> Just (fromIntegral ipart, s')
                                         _ -> Just (fromIntegral ipart, s')
                   Nothing -> Nothing


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);


	int k;
	string s;
	cin >> k >> s;

	if(s.size() <= k)
		cout << s << endl;
	else{
		for(int i = 0; i < k; i++)
			cout << s[i];
		cout << "...";
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3496
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n; cin >> n;
	vector<ll> a(n),b(n+1,0);
	rep(i, n) cin >> a[i];
	rep(i, n) b[i + 1] = b[i] + a[i];
	sort(b.begin(), b.end());
	ll cnt = 1,ans=0;
	rep(i, n) {
		if (b[i] == b[i + 1]) cnt++;
		else {
			ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
	}
	ans += cnt * (cnt - 1) / 2;
	cout << ans << endl;
	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a>b) cout << "a > b" << endl;
	else if (a<b) cout << "a < b" << endl;
	else cout << "a == b" << endl;
	return 0;
}


Measured memory_bytes: 3064
import java.util.*;
import java.lang.Math;
import java.math.BigInteger;

class Main {
    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        BigInteger a, b;

        while (true) {
            try {
               a = new BigInteger(sc.next());
               b = new BigInteger(sc.next());
            } catch (NoSuchElementException e) {
               break;
            }

            BigInteger g = a.gcd(b);
           System.out.printf("%d %d\n", g, a.divide(g).multiply(b)); 
        }
    }
}

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

int main(){
  int n,a,b,sum=0;
  cin>>n>>a>>b;
  for(int i=a;i<=n;i++){
    int c=0;
    int j=i;
    while(j>0){
      c+=j%10;
      j/=10;
    }
    if(c>=a && c<=b) sum+=i;
  }
  cout<<sum<<endl;
}


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

#define inf 1000000007

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > v(n,vector<int>(m)),dp(n,vector<int>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> v[i][j];
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(i==0){
                if(v[i][j]==0){
                    dp[i][j] = 1;
                    ans= max(ans,dp[i][j]);
                }else{
                    dp[i][j] = 0;
                }
            }else{
                if(j==0){
                    if(v[i][j]==0){
                        dp[i][j] = 1;
                        ans= max(ans,dp[i][j]);
                    }else{
                        dp[i][j] = 0;
                    }
                }else{
                    if(v[i][j]==0){
                        dp[i][j] = min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]))+1;
                        ans= max(ans,dp[i][j]);
                    }
                }
            }
        }
    }
    cout << ans*ans << endl;
    return 0;
}


Measured memory_bytes: 18200
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}



int main() {
	int a,b;
	cin >> a >> b;
	cout << a*b << " " << 2*(a+b) << endl;
	return 0;

}



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

int main(){
    long long A,B,C,K;
    long long sum = 0;
    cin >> A >> B >> C >> K;
    for (long long i = 0; i < A; i++) {
        if (i < K) {
            sum++;
        }else{
            cout << sum << endl;
            return 0;
        }
    }
    if (A+B < K) {
        for (long long t = A+B; t < K; t++) {
            sum--;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
l = [int(input()) for _ in range(5)]
m = [10 * ((l[i] + 9) // 10) for i in range(5)]
t = 130 * 5
for i in range(5):
    u = sum(m) - m[i] + l[i]
    t = min(t, u)
print(t)

Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>

int main (void) {
    int n;
    int s;
    double sum1, sum2;

    for (;;) {
        scanf ("%d", &n);
        if (n==0) break;
        sum1=0;
        sum2=0;
        for (int i=0; i<n; i++) {
            scanf ("%d", &s);
            sum1 += s;
            sum2 += pow (s, 2);
        }
        printf ("%lf\n", sqrt(sum2/n-pow(sum1/n, 2)));
    }

    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>

using namespace std;

int main(int argc, char const* argv[])
{
	string target;

	getline( cin, target );

	for( int i = 0;i < target.size();i++ ){
		if( target[i] >= 'a' && target[i] <= 'z' ) target[i] += ('A' - 'a' );
	}

	cout << target << endl;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    ll T;
    cin >> N >> T;
    ll t[N];
    rep(i, N) cin >> t[i];
    ll sum = 0;
    rep(i, N-1){
        sum += min(T, t[i+1] - t[i]);
    }
    sum += T;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	rep(i, N) {
		if (4 * i <= N && (N - (4 * i)) % 7 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
	
	int n;
	scanf("%d", &n);
	
	vector<int> a(n);
	map<int,int> m;
	
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i]);
		m[a[i]] = i;
	}
	
	sort(a.begin(), a.end());
	
	int resp = 0;
	
	for(int i = 0; i < n; ++i){
		int pos_ant = m[a[i]];
		int pos_cur = i;
		
		if((pos_ant%2) != (pos_cur%2))resp++;
	}
	
	printf("%d\n", resp/2);
		
}




Measured memory_bytes: 5376
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

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

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

const int N = 11111111;
int prime[N];

void init()
{
}

void solve()
{
	int n;
	cin >> n;

	prime[0] = 0;
	prime[1] = 0;

	ll sum = 0;

	reps(i, 1, n + 1)
	{
		for (int j = i; j < n + 1; j += i)
		{
			prime[j]++;
		}

		sum += (ll)prime[i] * i;
	}

	cout << sum << endl;
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 42244
#include <stdio.h>
#include <iostream>

#include <bits/stdc++.h>


using namespace std;

#define INPUT_INT(valName) int valName; cin >> valName
#define INPUT_LLINT(valName) long long int valName; cin >> valName;
#define INPUT_STR(valName) string valName; cin >> valName;
#define INPUT_LINE(valName) string valName; getline(cin,s);
#define INPUT_VECTOR_INT(valName, N) vector<int> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }
#define INPUT_VECTOR_DOUBLE(valName, N) vector<double> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }

#define OUTPUT(A) cout << (A) << endl;
#define OUTPUT2(A, B) cout << (A) << " " << (B) << endl;
#define OUTPUT3(A, B, C) cout << (A) << " " << (B) << " " << (C) << endl;

#define REP(valName, N) for(int valName = 0; valName < N; ++valName)

vector<string> split(const string& str, char delimiter) {
	vector<string> ret;
	string tmp = "";
	for (auto c : str) {
		if (c != delimiter) {
			tmp.push_back(c);
		} else {
			ret.push_back(tmp);
			tmp = "";
		}
	}
	ret.push_back(tmp);
	return ret;
}

template <typename T> void sortAsc(vector<T>& v) { sort(v.begin(), v.end(), less<T>()); }
template <typename T> void sortDesc(vector<T>& v) { sort(v.begin(), v.end(), greater<T>()); }

template <typename T> void insert(vector<T>& dest, const vector<T>& src) { copy(src.begin(), src.end(), back_inserter(dest)); }

template <long long int MOD> long long int mod_inv(long long int a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}

template <long long int MOD> long long int mod_add(long long int a, long long int b) {
	return (a + b) % MOD;
}

template <long long int MOD> long long int mod_sum(long long int a, long long int b) {
	return (a - b) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b) {
	return (a % MOD) * (b % MOD) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b, long long int c) {
	return mod_mul<MOD>(a, mod_mul<MOD>(b, c));
}

template <long long int MOD> long long int mod_div(long long int a, long long int b) {
	return (a % MOD) * mod_inv<MOD>(b) % MOD;
}


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

int main() {

	INPUT_LLINT(N);

	long long int n = 0;
	for (long long int i = 1; i <= N-1; ++i) {
		n += i;
	}

	OUTPUT(n);

	return 0;
}

Measured memory_bytes: 256
//Crane and Turtle

#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	int n1 = ((x * 4) - y) / 2;
	int n2 = ((n1 * 2) - y) / 4;

	if ((2 * abs(n1)) + (4 * abs(n2)) == y) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	cout << "\n";
	return 0;
}


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

enum Stake{
    none=0,
    B=1,
    W=2,
    black=3,
    white=4,
    eo=5,
};

Stake area[51][51];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int w,h;

void B_DFS(int y, int x){

    if(area[y][x] == none){
        area[y][x] = black;
    }
    else if(area[y][x] == white){
        area[y][x] = eo;
    }

    for(int i=0; i<4; i++){
        if(x + dx[i] >= 0 && x + dx[i] < w && y + dy[i] >= 0 && y + dy[i] < h){
            if(area[y+dy[i]][x+dx[i]] != B && area[y+dy[i]][x+dx[i]] != W && area[y+dy[i]][x+dx[i]] != black && area[y+dy[i]][x+dx[i]] != eo) {
                B_DFS(y + dy[i], x + dx[i]);
            }
        }
    }

}

void W_DFS(int y,int x){

    if(area[y][x] == none){
        area[y][x] = white;
    }
    else if(area[y][x] == black){
        area[y][x] = eo;
    }

    for(int i=0; i<4; i++){
        if(x + dx[i] >= 0 && x + dx[i] < w && y + dy[i] >= 0 && y + dy[i] < h){
            if(area[y+dy[i]][x+dx[i]] != B && area[y+dy[i]][x+dx[i]] != W && area[y+dy[i]][x+dx[i]] != white && area[y+dy[i]][x+dx[i]] != eo) {
                W_DFS(y + dy[i], x + dx[i]);
            }
        }
    }
}

int main() {

    while(true) {

        cin >> w >> h;
        if (w == 0 && h == 0) {
            break;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                char a;
                cin >> a;
                if (a == 'W') {
                    area[i][j] = W;
                } else if (a == 'B') {
                    area[i][j] = B;
                } else if (a == '.') {
                    area[i][j] = none;
                }
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if(area[i][j] == B){
                    B_DFS(i,j);
                }
                else if(area[i][j] == W){
                    W_DFS(i,j);
                }
            }
        }

        int black_count = 0,white_count = 0;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if(area[i][j] == black){
                    black_count++;
                }
                else if(area[i][j] == white){
                    white_count++;
                }
            }
        }

        cout << black_count << " " << white_count << endl;

    }

    return 0;
}


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

int main(){

    string s;
    cin >> s;

    int num = s.size();
    int ans = 0;
    char cbuf, cmem;

    for (int i=0; i<num; i++){

        cbuf = s.at(i);

        if (cbuf == cmem){
            if (i+1<num){
                ans++;
                cmem = ' ';
                i++;
            }
        }
        else {
            cmem = cbuf;
            ans++;
        }
    }

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

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

using namespace std;

#define chmin(a, b) (a=a<b?a:b);

const int inf = 1e9;

int N, M;
int c[16], x[20001];

int dp[20001][256];

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

    while (cin >> N >> M, N) {
        for (int i = 0; i <= 20000; ++i) for (int j = 0; j < 256; ++j) dp[i][j] = inf;

        for (int i = 0; i < M; ++i) cin >> c[i];
        for (int i = 1; i <= N; ++i) cin >> x[i];

        dp[0][128] = 0;

        for (int i = 1; i <= N; ++i) {
            for (int j = 0; j < 256; ++j) {
                if (dp[i - 1][j] != inf) {
                    for (int k = 0; k < M; ++k) {
                        int v = (c[k] < 0 ? max(j + c[k], 0) : min(j + c[k], 255));
                        int w = abs(v - x[i]);
                        chmin(dp[i][v], dp[i - 1][j] + w * w);
                    }
                }
            }
        }

        cout << *min_element(dp[N], dp[N] + 256) << endl;
    }
}

Measured memory_bytes: 21276
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=2e5+5;
int init()
{
	char c=getchar();int t=0,type=1;
	while(c>'9'||c<'0')	type=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9')	t=t*10+c-'0',c=getchar();
	return t*type;
}
int cnt[maxn],a[maxn],num[maxn],n,m,ans;
int main()
{
//	freopen("e.in","r",stdin);
//	freopen("e.out","w",stdout);
	n=init(),m=init();
	for(int i=1;i<=n;i++)	a[i]=init(),cnt[a[i]]++;
	for(int i=1;i<=n;i++)	for(int j=max(1,i-cnt[i]+1);j<=i;j++)	num[j]++;
	for(int i=1;i<=n;i++)	if(!num[i])	ans++;
	while(m--)
	{
		int x=init(),y=init();
		if(a[x]-cnt[a[x]]+1>=1&&--num[a[x]-cnt[a[x]]+1]==0)	ans++;
		cnt[a[x]]--;a[x]=y;
		if(y-cnt[y]>=1&&++num[y-cnt[y]]==1)	ans--;cnt[y]++;
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;

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

	cin >> a >> b >> c >> d;

	int e = 0;

	while(a > 0 && c > 0){
		if(e){
			a -= d;
		}else{
			c -= b;
		}

		e = !e;
	}

	if(a <= 0){
		cout << "No\n";
	}else{
		cout << "Yes\n";
	}

	return 0;
}

Measured memory_bytes: 3524
#pragma GCC optimize("O3")
#pragma GCC target("sse4.1")

#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = ((int)(n) - 1); i >= 0; --i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#endif

int n, k;

bool read ()
{
    if (!(cin >> n >> k))
        return false;

    return true;
}

ll solve ()
{
    ll cnt = n / k;
    ll ans = cnt * cnt * cnt;
    if (k % 2 == 0)
    {
        ll other_cnt = n / k + (n % k >= k / 2 ? 1 : 0);
        ans += other_cnt * other_cnt * other_cnt;
    }

    return ans;
}

int32_t main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
    {
        auto ans = solve();
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

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

  ll N,K;
  cin>>N>>K;

  vector<ll> v(K+1,0);
  for(int i=K;i>=1;i--){
    ll num=K/i;
    ll res=mod_pow(num,N);
    for(ll j=2;i*j<=K;j++) add(res,MOD-v[i*j]);
    v[i]=res;
  }

  ll ans=0;
  for(int i=1;i<=K;i++) add(ans,v[i]*i%MOD);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3992
let h, w = Scanf.scanf "%d %d\n" (fun h w -> (h, w))

let repeat i =
  let rec aux tmp n = if n = 0 then tmp else aux ("#" ^ tmp) (n - 1) in
  aux "" i

let line = repeat (w + 2)

let buf = Buffer.create (h * w)

let rec f n =
  if n = h then ()
  else
    let () =
      Buffer.add_string buf (Printf.sprintf "#%s#\n" (Scanf.scanf "%s\n" (fun s -> s)))
    in
    f (n + 1)


let () =
  Buffer.add_string buf (Printf.sprintf "%s\n" line) ;
  f 0 ;
  Buffer.add_string buf (Printf.sprintf "%s\n" line) ;
  Printf.printf "%s" (Buffer.contents buf)

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

queue<pair<int,int>> q;
vector<vector<char>> table(1010,vector<char>(1010,'#'));
vector<vector<int>> dist(1010,vector<int>(1010,-1));
vector<vector<bool>> seen(1010,vector<bool>(1010,0));

void bfs(int a, int b,int d){
  if(!seen[a][b] && table[a][b] == '.'){
    if(dist[a][b] == -1) dist[a][b] = d+1;
    else dist[a][b] = min(dist[a][b],d+1);
    auto tmp = make_pair(a,b);
    q.push(tmp);
  }
}

int main(){
  int h,w;
  cin >> h >> w;
  rep1(i,h)rep1(j,w){
    cin >> table[i][j];
    if(table[i][j] == '#'){
      auto tmp = make_pair(i,j);
      q.push(tmp);
      dist[i][j] = 0;
    }
  }
  while(!q.empty()){
    int a = q.front().first;
    int b = q.front().second;
    q.pop();
    if(seen[a][b]) continue;
    seen[a][b] = 1;
    if(a<1 || a>h) continue;
    if(b<1 || b>w) continue;
    int d = dist[a][b];
    bfs(a-1,b,d);
    bfs(a+1,b,d);
    bfs(a,b-1,d);
    bfs(a,b+1,d);
  }
  int ans = 0;
  rep1(i,h){
    rep1(j,w) ans = max(ans,dist[i][j]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 13712
#include <iostream>
#include <fstream>
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <cstring>
#include <numeric>
#include <stack>
#include <iomanip>
#include <chrono>
using namespace std;

#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385

#define sd(mark) scanf("%d",&mark)
#define ss(mark) scanf("%s",mark)
#define sl(mark) scanf("%lld",&mark)
#define clr(mark) memset(mark,0,sizeof(mark))
#define setinf(mark) memset(mark,0x3f,sizeof(mark))

#define mp make_pair
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;

#ifndef KaalaNamak
#define endl '\n'
#define trace(...)
#define start_routine() 
#define end_routine()
#endif

signed main() {
    start_routine();
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);
    cout<<fixed<<setprecision(10);
    int t=1;
    // cin>>t;
    #ifdef KaalaNamak
        t=4;
    #endif
    while(t--){
        int n;
        cin>>n;

        if(n<3){
            cout<<"0";
            return 0;
        }
        if(n<6){
            cout<<"1";
            return 0;
        }
        int dp[n+1];
        dp[0]=0;
        dp[1]=0;
        dp[2]=0;
        dp[3]=1;
        dp[4]=1;
        dp[5]=1;
        for(int i=6;i<=n;i++){
            dp[i]=1;
            for(int  j=3;j<=(i-3);j++){
                dp[i]+=dp[j];
                dp[i]%=mod;
            }
        }
        // for(int i=0;i<=n;i++){
        //     cout<<dp[i]<<" ";
        // }
        cout<<dp[n]<<"\n";

    }
    end_routine();

} 

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) v.begin(), v.end()
int garr[100001];
int mat[100001];
int gv;
int whatdo(int n) {
  if (n >= gv)
    return 0;

  if (mat[n] != -1) {
    return mat[n];
  }

  return mat[n] = min(abs(garr[n] - garr[n + 1]) + whatdo(n + 1),
                      abs(garr[n] - garr[n + 2]) + whatdo(n + 2));
}

void solve() {
  //----------------------VARs---------------------------------------------
  char car, car2;
  string s, st;
  long long n = 0, a = 0, b = 0, c = 0, e, d = 0, m = 0, t = 0, q = 0, r = 0,
            l = 0, middle = 0, count = 0, add = 0, k, ans = 300, temp = 0,
            rootsa, save = 0, bigg = 0, save2 = 0, counter = 0, counter2 = 0,
            sum = 0, x, y;
  bool flag = false, flag2;

  //-------- --------------VARs--------------------------------------------
  memset(mat, -1, sizeof(mat));
  int arr[1000] = {};
  vector<int> vec;
  cin >> gv;

  for (int i = 1; i <= gv; i++)
    cin >> garr[i];
  if (gv == 2) {
    cout << abs(garr[gv] - garr[gv - 1]);
  } else

    cout << whatdo(1) << endl;
}
int main() {
#ifndef ONLINE_JUDGE
  system("clear");
  freopen("Test0.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cin.tie(0);

  cout << fixed << setprecision(10);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 6712
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <assert.h>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
int arr[200001];
int main()
{
    int N;
    cin >> N;
    int temp;
    int i;
    int m = 0;
    ll sum = 0;
    for(i = 0; i < N; i++)
    {
        cin >> temp;
        arr[i] = temp;
        m = max(m,arr[i]);
        sum += m-arr[i];
    }
    
    for(i = N-1; i >= 0; i--)
    {
        
    }

    cout << sum;
}

Measured memory_bytes: 4424
#include <stdio.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	int N, M, C,B[30],A[30][30];
	cin >> N >> M >> C;
	for (int i = 0; i < M; i++)cin >> B[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)cin >> A[i][j];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int x = 0;
		for (int j = 0; j < M; j++) {
			x += A[i][j]*B[j];
		}
		x += C;
		if (x > 0)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.math.*

class UnionFind(n: Int) {
    private val parent = IntArray(n, {-1})
    private val rank = IntArray(n, {0})
    private val size = IntArray(n, {1})
    private var numTree = n
    
    fun find(x: Int): Int {
        if (parent[x] == -1) {
            return x
        } else {
            parent[x] = find(parent[x])
            return parent[x]
        }
    }
    
    fun isSame(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }
    
    fun getSize(): Int {
        return numTree
    }
    
    fun sizeOf(x: Int): Int {
        return size[find(x)]
    }
    
    fun rankOf(x: Int): Int {
        return rank[find(x)]
    }
    
    fun unite(x: Int, y: Int) {
        val parentX = find(x)
        val parentY = find(y)
        
        if (parentX == parentY) {
            return
        }
        
        numTree--
        
        if (rank[parentX] < rank[parentY]) {
            parent[parentX] = parentY
            size[parentY] += size[parentX]
        } else {
            parent[parentY] = parentX
            size[parentX] += size[parentY]
            if (rank[parentX] == rank[parentY]) {
                rank[parentX]++
            }
        }
    }
}

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    if (N == 1) {
        println(1)
        return
    }
    
    val list = mutableListOf<Pair<Long, Long>>()
    
    for (i in 1..N) {
        val (x, y) = readInputLine().split(" ").map { it.toLong() }
        list.add(Pair(x, y))
    }
    
    list.sortBy { it.second }
    list.sortBy { it.first }
    
    val arr: Array<Pair<Long, Long>> = list.toTypedArray()
    
    var ans = Int.MAX_VALUE
    
    for (i in 0 until N) {
        for (j in i + 1 until N) {
            val p = arr[j].first - arr[i].first
            val q = arr[j].second - arr[i].second

            val unionFind = UnionFind(N)
            
            for (k in 0 until N) {
                for (l in k + 1 until N) {
                    if (arr[l].first - arr[k].first == p && arr[l].second - arr[k].second == q) {
                        unionFind.unite(k, l)
                    }
                }
            }
            
            ans = Math.min(ans, unionFind.getSize())
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 42568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define ll long long int 
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define P(x) printf("%d\n",(x))
#define Sl(x) scanf("%lld",&(x))
#define Pl(x) printf("%lld\n",(x))
#define pb push_back
#define f first
#define s second

int dp[3003][3003] ;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t ; cin >> s >> t ; 
	s = " " + s ; t = " " + t ; 
	int n = s.length(), m = t.length() ;
	int parent[m] ;
	for(int i = 1; i < n ; i++){
		for(int j = 1; j < m ;j++){

				if(s[i] == t[j]) {
					dp[i][j] = dp[i-1][j-1] + 1 ;
				}
				else{
					if(dp[i-1][j] > dp[i][j-1] ) {
						dp[i][j] = dp[i-1][j] ;
					}
					else{
						dp[i][j] = dp[i][j-1] ;
					}
				}
		}
	}

	int i, j; 
	i = n-1; j = m-1; 
	stack<char> s1;

	while(1) {

		if( i < 1  ||  j < 1)break ;
		if(s[i] == t[j] ){
			s1.push(s[i]) ;
			i=i-1;j=j-1;
			continue ;
		}
		else{
			if(i >= 1 && j >=1){
				if(dp[i-1][j] > dp[i][j-1])i=i-1;
				else j=j-1;
			}
		}
	} 

	while(!s1.empty()){
		cout << s1.top() ;
		s1.pop();
	}

 	return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <string>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[4444][8];

int main(void){
	int n,i,j,k;
	ll ans;
	std::string s;
	std::cin >> n;
	std::cin >> s;
	dp[0][0] = 1ll;
	for(i=0; i<n; ++i){
		switch(s[i]){
			case 'R': k = 1; break;
			case 'G': k = 2; break;
			case 'B': k = 4; break;
		}
		for(j=0; j<8; ++j){
			dp[i+1][j] += dp[i][j];
			if(!(j&k)){
				dp[i+1][j|k] += dp[i][j];
			}
		}
	}
	ans = dp[n][7];
	for(i=0; i<n; ++i){
		for(j=1; j<=n; ++j){
			if(i+j*2>=n){
				break;
			}
			if((s[i]!=s[i+j])&&(s[i+j]!=s[i+j*2])&&(s[i+j*2]!=s[i])){
				--ans;
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3856
#include <stdio.h>

using lli = long long int;

// constexpr version : N が clang++ : 3e5くらいまでok,  g++ : 2e6くらいまでok
template <int N, long long int mod>
struct CombinationMod{
private:
    using lli = long long int;
public:
    lli Power[N+1], Inverse[N+1], powInverse[N+1];
    constexpr CombinationMod():Power(), Inverse(), powInverse(){
        Power[0] = 1; Inverse[0] = 1; powInverse[0] = 1;
        for(int x = 1; x <= N; ++x) Power[x] = (Power[x-1] * x) % mod;
        powInverse[N] = inverse(Power[N]);
        for(int x = N; x > 0; --x) powInverse[x-1] = (powInverse[x] * x) % mod;
        for(int x = 1; x <= N; ++x) Inverse[x] = (Power[x-1] * powInverse[x]) % mod;
    }
    constexpr void swap(lli &a, lli &b) const {
        a ^= b; b ^= a; a ^= b;
    }
    constexpr lli inverse(lli a) const noexcept{
        lli b = mod, u = 1, v = 0;
        while (b != 0) { 
            lli t = a / b; a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= mod; if (u < 0) u += mod;
        return u;
    }
    // nCkを求める関数 : n < k の入力に注意せよ
    inline lli combination(int n, int k) const noexcept{
        if(n < k) return 0;
        return ((Power[n] * powInverse[k] % mod) * powInverse[n-k]) % mod;
    }
};

constexpr int SizeN = 3e5;
constexpr int mod = 1e9 + 7;
constexpr CombinationMod<SizeN, mod> Cmb;


int main(void){
    int n, m, k; scanf("%d%d%d", &n, &m, &k);
    lli T1 = m; (T1 *= m) %= mod; (T1 *= Cmb.combination(n+1, 3)) %= mod;
    lli T2 = n; (T2 *= n) %= mod; (T2 *= Cmb.combination(m+1, 3)) %= mod;
    lli res = T1 + T2;
    (res *= Cmb.combination(n*m-2, k-2)) %= mod;
    printf("%lld\n", res);
    return 0;
}


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

int main() {
int64_t n;
  char ch;
  cin>>n;
  vector<int64_t> vec(n);
  for(int i=0;i<n;i++){
  cin>>ch;
    if(ch=='W'){vec.at(i)=0;}
     if(ch=='R'){vec.at(i)=1;}
  }
 int64_t a,b,ans;
  a=0;
  b=n-1;
  ans=0;
 while(4+2==6){
  while(vec.at(a)==1&&a<n-1){a++;}
   while(vec.at(b)==0&&b>0){b--;}
   if(a>b||a==b){break;}
   else{vec.at(a)=1;
       vec.at(b)=0;}
   ans++;
 }
  cout<<ans<<endl;
}

Measured memory_bytes: 4820
S = str(input())[::-1]
N = len(S)
mod_list = [0]*2020
mod_list[0] = 1

mod = 2019
tmp = 0

for i in range(N):
    tmp = (tmp + int(S[i])*pow(10,i,mod))%mod
    mod_list[tmp] += 1
    
ans = 0
for i in mod_list:
    ans += i*(i-1)//2
        
print(ans)

Measured memory_bytes: 68356