akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    ll K, N;
    input(K, N);

    vector<ll> A;
    rep(i, 0, N)
    {
        ll a;
        input(a);
        A.push_back(a);
    }

    vector<ll> dist(N, 0);
    ll mx = -1;
    ll idx = -1;
    rep(i, 0, N)
    {
        dist[i] = i != N - 1 ? abs(A[i] - A[i + 1]) : abs(K - A[i] + A[0]);
        if (mx < dist[i])
        {
            mx = dist[i];
            idx = i;
        }
    }

    ll res = 0;
    rep(i, 0, N)
    {
        if (i != idx)
        {
            res += dist[i];
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3440
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int Q;
  cin >> Q;
  for(int i=0; i<Q; i++){
    ll A, B;
    cin >> A >> B;
    if(A > B){
      ll tmp = A;
      A = B;
      B = tmp;
    }
    ll M = A * B;
    if(M == 1){
      cout << 0 << endl;
    } else {
      // ll C = floor(sqrt(M-1));                                                                               
      ll C = sqrt(M);
      if(C * C == M) C--;
      ll ret = C * 2;
      if(C == (M-1)/C) ret--;
      if(A <= C) ret--;
      cout << ret << endl;
    }
  }
  return 0;
}


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

int main() {
    int n;
    cin>>n;
    vector<char> s(n);
    rep(i,n){
        cin>>s[i];
    }
    if(n%2!=0){
        cout<<"No"<<endl;
        return 0;
    }
    rep(i,n/2){
        char s1=s[i];
        char s2=s[n/2+i];
        if(s1!=s2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
    int a, b;
    int minx, minx2, maxx, maxx2;
    cin >> a >> b;
    minx = ceil(a * ((float)100 / 8));
    maxx = ((a + 1) * ((float)100 / 8));
    minx2 = ceil(b * ((float)100 / 10));
    maxx2 = ((b + 1) * ((float)100 / 10));
    // cout << minx << "    " << maxx << "\n";
    // cout << minx2 << "    " << maxx2 << "\n";
    if ((minx >= maxx2) || (minx2 >= maxx))
    {
        cout << "-1";
        return 0;
    }
    else
    {
        cout << max(minx, minx2);
    }

    return 0;
}

Measured memory_bytes: 256
s=input()
n=int(input())
isreverse=False
top=''

for i in range(n):
    ss=input().split()
    if len(ss)==1:
        isreverse=not isreverse
    else:
        if ss[1]=="1":
            if isreverse: s+=ss[2]
            else: top+=ss[2]
        else:
            if isreverse: top+=ss[2]
            else: s+=ss[2]
if isreverse:
    s=s[::-1]+top
else:
    s=top[::-1]+s


print(s)

Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> point(n, k-q);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    point[a-1]++;
  }
  for (int i = 0; i < n; i++) {
    if (point[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct card {
	char suit;
	int value;
	size_t index;
	card (char suit, int value, size_t index) :
		suit(suit), value(value), index(index) { }
	bool operator< (const card &rhs) const {
		return ((this->value) < (rhs.value));
	}
};

vector<card> bubble_sort (vector<card> c, size_t n) {
	for (size_t i = 0; i < n; i++) {
		for (size_t j = n; j --> i + 1;) {
			if (c[j] < c[j - 1]) swap(c[j], c[j - 1]);
		}
	}
	return c;
}

vector<card> selection_sort (vector<card> c, size_t n) {
	for (size_t i = 0; i < n; i++) {
		size_t min_j = i;
		for (size_t j = i; j < n; j++) {
			if (c[j] < c[min_j]) min_j = j;
		}
		swap(c[i], c[min_j]);
	}
	return c;
}

bool is_stable (const vector<card> &c) {
	bool flag = true;
	for (size_t i = 0; i + 1 < c.size(); i++) {
		if (c[i].value == c[i + 1].value) {
			flag &= (c[i].index < c[i + 1].index);
		}
	}
	return flag;
}

int main() {
	size_t n;
	cin >> n;
	vector<card> c;
	for (size_t i = 0; i < n; i++) {
		string s;
		cin >> s;
		c.emplace_back(s[0], (s[1] - '0'), i);
	}
	
	vector<card> a = bubble_sort(c, n);
	for (size_t i = 0; i < n; i++) {
		cout << a[i].suit << a[i].value << " \n"[i + 1 == n];
	}
	cout << (is_stable(a) ? "Stable" : "Not stable") << '\n';
	
	vector<card> b = selection_sort(c, n);
	for (size_t i = 0; i < n; i++) {
		cout << b[i].suit << b[i].value << " \n"[i + 1 == n];
	}
	cout << (is_stable(b) ? "Stable" : "Not stable") << '\n';
	
	return 0;
}


Measured memory_bytes: 3144
#include<stdio.h>
int main(void){
	int a,b;
	
	scanf("%d %d",&a,&b);
	if(a<=100000&&b<=100000){
	if(a>=b)
	printf("1\n");
	else if(a==1)
	printf("%d\n",b);
	else if(b%a==0)
	printf("%d\n",b/a);
	else
	printf("%d\n",b/a+1);
	}return 0;
	}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  ll n;
  cin >> n;
  string s = "";

  ll a = n;
  while (a > 0) {
    a -= 1;
    char c = 'a' + a%26;
    s = c + s;
    a /= 26;
  }

  cout << s << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }


vector<vector<int>> V =
    {
        {0, 1, 2},
        {3, 4, 5},
        {6, 7, 8},
        {0, 4, 8},
        {2, 4, 6},
        {0, 3, 6},
        {1, 4, 7},
        {2, 5, 8}};

int main()
{
    vector<lint> A(9);
    cin >> A;
    int N;
    cin >> N;
    while (N--) {
        int b;
        cin >> b;
        for (auto &x : A) if (x == b) x = 0;
    }
    for (auto vec : V) {
        bool b = true;
        for (auto x : vec) if (A[x]) b = false;
        if (b) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
}


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

int n;
pair<int, int>p[300000];
bool ok(ll t) {
	priority_queue<int>Q; ll sum = 0;
	rep(i, t - 1) {
		Q.push(p[i].second); sum += p[i].second;
	}
	for (int i = t - 1; i < n; i++) {
		if (p[i].first*t >= sum + p[i].second)return 1;
		if (!Q.empty() && Q.top() > p[i].second) {
			sum -= Q.top() - p[i].second; Q.pop();
			Q.push(p[i].second);
		}
	}
	return 0;
}
int main() {
	scanf("%d", &n);
	rep(i, n) {
		int a, b; scanf("%d%d", &a, &b);
		p[i] = { b,a };
	}
	sort(p, p + n, greater<>());
	int a = 0, b = n;
	while (a != b) {
		int t = (a + b) / 2;
		if (b - a == 1)t = b;
		if (ok(t))a = t;
		else b = t - 1;
	}
	printf("%d\n", a);
}

Measured memory_bytes: 8352
from math import *

def main():
    N, M = map(int, input().split())
    if N==1:
        print(M)
        return
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(M/j for j in divisor_set)
    print(int(max([i for i in divisor_set if special_value >= i])))
    return

main()

Measured memory_bytes: 3060
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let input_vec = read_vec::<i64>();
    let n = input_vec[0];
    let l = input_vec[1];

    let mut sum = 0;
    for i in (l)..(l+n) {
        sum += i;
    }

    if l == 0 {
        println!("{}", sum);
    } else if l < 0 {
        if 0 <= l + n - 1 {
            println!("{}", sum);
        } else {
            println!("{}",sum - l - n + 1);
        }
    } else {
        println!("{}",sum - l);
    }
    
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-1]に格納する
    int* S;
    NEW(S,N);
    for(int i=0;i<N;i++){
        scanf("%d",&S[i]);
    }
    qsort(S,N,sizeof(int),asc);

    int sum=0;
    for(int i=0;i<N;i++) sum+=S[i];

    int ans=0;
    if(sum%10!=0) ans=sum;
    else{
        for(int i=0;i<N;i++){
            if((sum-S[i])%10!=0){
                ans=sum-S[i];
                break;
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    cnt = {}
    for a in A:
        if a not in cnt:
            cnt[a] = 1
        else:
            cnt[a] += 1

    for i in range(1, N + 1):
        if i in cnt:
            print(cnt[i])
        else:
            print(0)


Measured memory_bytes: 113556
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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 input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s; cin>>s;
    if (s=="SUN") cout << 7 << endl;
    else if (s=="MON") cout << 6 << endl;
    else if (s=="TUE") cout << 5 << endl;
    else if (s=="WED") cout << 4 << endl;
    else if (s=="THU") cout << 3 << endl;
    else if (s=="FRI") cout << 2 << endl;
    else if (s=="SAT") cout << 1 << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;

    for(int i=1;i<=9;i++){
        for(int j=i;j<=9;j++){
            if(n==i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    ans += a * (N - c)

print(ans)

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

using namespace std;

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

typedef long long ll;

void solve() {
  int n; cin >> n;
  int prv = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int v; cin >> v;
    if (prv <= v) {
      prv = v; continue;
    }
    ans += prv - v;
  }
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
    solve();
}


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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
    IOS;

    int n;
    cin >> n;
    if(n/100 == n%10) cout << "Yes\n";
    else cout << "No\n";
    return 0;    
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderGrandContest010
{
    class ProgramB
    {
        private const string kYes = "YES";
        private const string kNo = "NO";
        static void Main(string[] args)
        {
            string szTotal = Console.ReadLine();
            int nTotal = int.Parse(szTotal);
            long[] arr = new long[nTotal];

            string szLine = Console.ReadLine();
            string[] szSplittedLine = szLine.Split(' ');

            for (int i = 0; i < szSplittedLine.Length; ++i)
            {
                long a = long.Parse(szSplittedLine[i]);
                arr[i] = a;
            }
            string ret = Solve(arr) ? kYes : kNo;
            Console.WriteLine(ret);
        }

        private static bool Solve(long[] arr)
        {
            long nTotal = arr.Length;
            long nStoneTotal = 0;// 石総数
            for (int i = 0; i < arr.Length; ++i)
            {
                nStoneTotal += arr[i];
            }

            long nSubTotal = (nTotal * (nTotal + 1)) / 2;// 一回の操作で除かれる石

            if (nStoneTotal % nSubTotal != 0) { return false; ; }
            long step = nStoneTotal / nSubTotal;// K回で終わる

            // 配列を変換し、問題をすり替える
            long[] arr_custom = new long[nTotal];
            for (int i = 0; i < arr_custom.Length; ++i)
            {
                long dt = arr[(i + 1) % nTotal] - arr[i];
                arr_custom[i] = dt - step;
            }

            // 各数字は N の倍数か？ K回のNの加算で解決できるぁ？
            long nAddTotal = 0;
            for (int i = 0; i < arr_custom.Length; ++i)
            {
                long dt = arr_custom[i];
                if (dt > 0) { return false; }
                if( dt == 0) { continue; }
                if (Math.Abs(dt) % nTotal != 0) { return false; }
                nAddTotal += Math.Abs( dt) / nTotal;
            }
            if( nAddTotal != step) { return false; }
            return true;
        }
    }
}


Measured memory_bytes: 13400
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))

int main()
{
	fastio;
	ll int a=1,b=1,c=1,i,j,k,n;
	cin>>n;
	ll res=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				res+= __gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<res<<endl;




	return 0;
}

Measured memory_bytes: 3652
-- E - "Common Subsequence"
import Data.Array

modulo = 10^9 + 7

main :: IO()
main = do
  [n, m] <- map read . words <$> getLine
  ns <- map read . words <$> getLine
  ms <- map read . words <$> getLine
  print $ solve n m ns ms

solve :: Int -> Int -> [Int] -> [Int] -> Int
solve n m ns ms = (dp!(n, m) + 1) `mod` modulo
  where
    na = listArray (1, n) ns
    ma = listArray (1, m) ms
    dp = array ((0, 0), (n, m)) $ map (\p->(p, f p)) [(x, y)| x <- [0..n], y <- [0..m]]
    f (x, y)
      | x == 0 || y == 0 = 0
      | na!x == ma!y = (1 + dp!(x-1, y) + dp!(x, y-1)) `mod` modulo
      | otherwise = (dp!(x-1, y) + dp!(x, y-1) - dp!(x-1, y-1)) `mod` modulo

Measured memory_bytes: 499068
def main():
    N,M = map(int,input().split())
    X = list(map(int,input().split()))
    X.sort()
    if N >= M:
        print(0)
        exit()
    L = X[-1]-X[0]
    Y = [X[i+1]-X[i] for i in range(M-1)]
    Y.sort()
    Y.reverse()
    Z = Y[:N-1]
    ans = X[-1]-X[0]
    for z in Z:
        ans -= z
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 13968
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, c, k, fpt = 0, npr = 0, ans = 0;
    cin >> n >> c >> k;
    vector<int> t(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &t[i]);
    }
    sort(t.begin(), t.end());
    for(int i = 0; i < n; i++){
        if(fpt == 0) fpt = t[i];
        if(t[i] - fpt <= k){
            npr++;
            if(npr == c){
                ans++;
                npr = 0;
                fpt = 0;
            }
        } else{
            ans++;
            npr = 1;
            fpt = t[i];
        }
    }
    if(npr != 0) ans++;
    cout << ans << endl;
    return 0;
}

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

int shortestPath01(string arr[], int n, int m, int sx, int sy, int dx, int dy){
    if(arr[sx][sy] == '#')
        return -1;
    typedef pair<int, int> pi;
    deque<pi> dq;
    dq.push_front({sx, sy});
    vector<vector<int>> distance(n, vector<int>(m, INT_MAX));
    distance[sx][sy] = 0;
    int ddx[] = {-1, 0, 1, 0};
    int ddy[] = {0, 1, 0, -1};

    while(!dq.empty()){
        pi curr = dq.front();
        dq.pop_front();
        int x = curr.first, y = curr.second;
        if(x == dx and y == dy)
            return distance[x][y];
//        for(int i=0; i<4; i++){
//            int newX = x+ddx[i], newY = y+ddy[i];
//            if(newX<0 or newY<0 or newX>=n or newY>=m or arr[newX][newY] == '#')
//                continue;
//            if(distance[x][y] < distance[newX][newY]){
//                distance[newX][newY] = distance[x][y];
//                dq.push_front({newX, newY});
//            }
//        }
        for(int i=x+1; i<n; i++){
            if(arr[i][y] == '#')
                break;
            if(distance[x][y] < distance[i][y]){
                distance[i][y] = distance[x][y];
                dq.push_front({i, y});
            }
        }

        for(int i=x-1; i>=0; i--){
            if(arr[i][y] == '#')
                break;
            if(distance[x][y] < distance[i][y]){
                distance[i][y] = distance[x][y];
                dq.push_front({i, y});
            }
        }

        for(int j=y+1; j<m; j++){
            if(arr[x][j] == '#')
                break;
            if(distance[x][y] < distance[x][j]){
                distance[x][j] = distance[x][y];
                dq.push_front({x, j});
            }
        }

        for(int j=y-1; j>=0; j--){
            if(arr[x][j] == '#')
                break;
            if(distance[x][y] < distance[x][j]){
                distance[x][j] = distance[x][y];
                dq.push_front({x, j});
            }
        }

        for(int i=x-2; i<=x+2; i++)
            for(int j=y-2; j<=y+2; j++){
                if(i<0 or j<0 or i>=n or j>=m or arr[i][j] == '#')
                    continue;
                if(distance[x][y]+1 < distance[i][j]){
                    distance[i][j] = distance[x][y]+1;
                    dq.push_back({i, j});
                }
            }

    }
    return -1;
}

int main()
{
 int n, m;
 cin>>n>>m;
 int sx, sy;
 cin>>sx>>sy;
 sx--;
 sy--;
 int dx, dy;
 cin>>dx>>dy;
 dx--;
 dy--;
 string arr[n];
 for(int i=0; i<n; i++)
    cin>>arr[i];
 int ans = shortestPath01(arr, n, m, sx, sy, dx, dy);
 cout<<ans;
 return 0;
}



Measured memory_bytes: 9444
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n;cin >> n;
    vector<int>a(n);
    rep(i,n)cin >>a[i];
    int max=*max_element(a.begin(),a.end());
    int min=*min_element(a.begin(),a.end());
    cout << max-min << endl;
    return 0;
}


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

int h,w,s;
int map[32][32];
int all;
pair<int,int> memo[32][32][33][33];
bool use[32][32][33][33];

pair<int,int> rec(int y1,int x1,int y2,int x2,int sum){
  pair<int,int> res,hoge1,hoge2;
  int a=1,b=0;
  int tmp;
  bool flag = false;

  if(use[y1][x1][y2][x2])return memo[y1][x1][y2][x2];

  tmp = 0;
  for(int i=x1+1;i<x2;i++){

    for(int j=y1;j<y2;j++)tmp += map[j][i-1];

    if( all-tmp <= s && all-(sum-tmp) <= s){
      flag = true;
      hoge1 = rec(y1,x1,y2,i,tmp);
      hoge2 = rec(y1,i,y2,x2,sum-tmp);
      if(hoge1.first+hoge2.first > a){
	a = hoge1.first + hoge2.first;
	b = max(hoge1.second,hoge2.second);
      }else if(hoge1.first + hoge2.first == a && max(hoge1.second,hoge2.second) < b){
	b = max(hoge1.second,hoge2.second);
      }
    }
  }

  tmp = 0;
  for(int i=y1+1;i<y2;i++){

    for(int j=x1;j<x2;j++)tmp += map[i-1][j];

    if( all-tmp <= s && all-(sum-tmp) <= s){
      flag = true;
      hoge1 = rec(y1,x1,i,x2,tmp);
      hoge2 = rec(i,x1,y2,x2,sum-tmp);
      if(hoge1.first+hoge2.first > a){
	a = hoge1.first + hoge2.first;
	b = max(hoge1.second,hoge2.second);
      }else if(hoge1.first + hoge2.first == a && max(hoge1.second,hoge2.second) < b){
	b = max(hoge1.second,hoge2.second);
      }
    }
  }

  if(!flag){
    res.first = 1;
    res.second = all - sum;
  }else{
    res.first = a;
    res.second = b;
  }
  memo[y1][x1][y2][x2] = res;
  use[y1][x1][y2][x2] = true;
  return res;
}


int main(){
  pair<int,int> ans;
  while(1){
    cin >> h >> w >> s;
    if(!h && !w && !s)break;

    all = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> map[i][j];
	all += map[i][j];
      }
    }
 
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int k=0;k<=h;k++){
	  for(int l=0;l<=w;l++){
	    memo[i][j][k][l].first = -1;
	    memo[i][j][k][l].second = -1;
	    use[i][j][k][l] = false;
	  }
	}
      }
    }

    ans = rec(0,0,h,w,all);
    cout << ans.first << " " << s - ans.second << endl;
  }
}

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

int main(){
	int n, a[3]={3600,60,1};
	cin>>n;
	for(int i=0;i<3;i++){
		int t=n/a[i];
		cout<<t;
		n-=t*a[i];
		if(i<2) cout<<':';
	}
	cout<<endl;
} 


Measured memory_bytes: 3096
#include <stdio.h> 
long long int gcd(long long int a, long long int b) 
{ 
	if (a == 0) 
	return b; 
	if (b == 0) 
	return a; 
	if (a == b) 
		return a; 
	if (a > b) 
		return gcd(a-b, b); 
	return gcd(a, b-a); 
} 
int main() 
{ 
	long long int a,b,c;
	scanf("%lld%lld",&a,&b);
	c=gcd(a, b);
	c=(a*b)/c;
	printf("%lld\n",c);
	return 0; 
} 



Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#define NMAX 10000
#define NMIN 1
#define MAX 100000000
#define MIN 2
int main(){
  int i,n,j,num[NMAX],count=0;
  scanf("%d",&n);
  if(n>NMAX||n<NMIN) exit(1);
  for(i=n;i>0;i--){
    scanf("%d",&num[i]);
    if(num[i]>=MIN&&num[i]<=MAX){
      if(num[i]!=2&&num[i]%2==0) count++;
      else{
	for(j=3;j<=sqrt(num[i]);j+=2){
	  if(num[i]%j==0){
	    count++;
	    break;
	  }
	}
      }
    }
    else break;
  }
  printf("%d\n",n-count);
  return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF INT_MAX
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll
#define P pair<int,int>

signed main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a, a+3);
  cout<<a[2]*10+a[0]+a[1]<<en;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int d,r;
  double a,b,f;
  scanf("%lf %lf",&a,&b);
  d = a / b;
  r = (int)a % (int)b;
  f = a / b;
  printf("%d %d %f\n",d,r,f);
  return 0;
}

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

int gcd(int a,int b)
{
    if(b==0)
        return a;

    return gcd(b,a%b);
}

void solve()
{

   ll k,x,g=0;
   cin>>k;

   for(int i=1;i<=k;i++)
   {
       for(int j=1;j<=k;j++)
       {
           for(int h=1;h<=k;h++)
           {
               x=gcd(j,h);
               g+=gcd(i,x);
           }
       }
   }
   cout<<g<<endl;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    solve();
    return 0;
}


Measured memory_bytes: 3652
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            Integer v[] = new Integer[n];
            for (int i = 0; i < n; i++) {
                v[i] = Integer.parseInt(in.next());
            }

            Arrays.sort(v);
            double ans = v[0];

            for (int i = 1; i < n; i++) {
                ans = (ans + v[i]) / 2.0;
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,ans=0,x=0;
    cin>>N;
    string s;
    cin>>s;
    REP(i,N){
        if(s[i]=='I'){
            x++;
            ans=max(ans,x);
        } else {
            x--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
abc = []
for _ in range(m):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  c *= -1
  abc += [[a,b,c]]

def bellman_ford(s):
  # std = [[s0, t0, d0], [s1, t1, d1], ... , [sm, tm, dm]]
  # (si, ti, di): si, ti間に重さdiの辺がある
  dist = [float('inf')]*n 
  dist[s] = 0
  for u in range(n):
    for s, t, d in abc:
      if dist[t] > dist[s] + d:
        dist[t] = dist[s] + d
        if u == n-1 and t == n-1:
          return -1
  return dist

dist = bellman_ford(0)
if dist == -1:
  print('inf')
else:
  print(-1*dist[n-1])



Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666, mo = 1e9+7;
int n,a[N],inv[N];
int main() {
	read(n);rep(i,1,n)read(a[i]);
	inv[1]=1;rep(i,2,n)inv[i]=1LL*(mo-mo/i)*inv[mo%i]%mo;
	ll res=0;rep(i,1,n)inv[i]=(inv[i-1]+inv[i])%mo;
	rep(i,1,n)res+=1LL*a[i]*(inv[i]+inv[n-i+1]-1)%mo;
	ll fac=1;rep(i,1,n)fac=1LL*fac*i%mo;
	cout<<res%mo*fac%mo;return 0;
}


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

#include <algorithm>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    long long n, l, ans = 0;
    cin >> n >> l;
    vector<long long> as(n);
    REP(i, n) { cin >> as[i]; }
    deque<int> dq;
    dq.push_back(0);
    for (int i = 1; i < l; i++) {
        while (as[dq.back()] > as[i]) {
            dq.pop_back();
            if (dq.empty()) {
                break;
            }
        }
        dq.push_back(i);
    }
    cout << as[dq.front()];
    if (n - l != 0){
        cout << " ";
    }
    for (int i = l; i < n; i++) {
        while (as[dq.back()] > as[i]) {
            dq.pop_back();
            if (dq.empty()) {
                break;
            }
        }
        dq.push_back(i);
        if (dq.front() == i - l) {
            dq.pop_front();
        }
        cout << as[dq.front()];
        if (i != n - 1) {
            cout << " ";
        }
    }
    cout << endl;
}


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


long long mod = 1000000000 + 7;

long long modplus(long long a, long long b){
	long long ans = a + b;
	ans %= mod;
	return ans;
}

long long modminus(long long a, long long b){
	long long ans = a - b;
	ans %= mod;
	if(ans < 0) ans += mod;
	return ans;
}

long long modmul(long long a, long long b){
	long long ans = (a % mod) * (b % mod);
	ans = ((ans % mod) + mod) % mod;
	return ans;
}

long long modpow(long long A, long long P){
	long long a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	long long adash = modmul(a,a);
	if(p % 2) return modmul(modpow(adash, p / 2), a);
	else return modpow(adash, p / 2);
}

long long moddiv(long long a, long long b){
	long long divisor = modpow(b, mod - 2);
	return modmul(a,divisor);
}

int main(){
	long long n, a, b;
	cin >> n >> a >> b;
	long long ans = modpow(2, n);
	long long tmpa = 1;
	long long tmpb = 1;
	for(long long i=0;i<a;i++){
		tmpa = modmul(tmpa, n - i);
	}
	for(long long i=0;i<a;i++){
		tmpa = moddiv(tmpa, i + 1);
	}
	for(long long i=0;i<b;i++){
		tmpb = modmul(tmpb, n - i);
	}
	for(long long i=0;i<b;i++){
		tmpb = moddiv(tmpb, i + 1);
	}
	ans = modminus(ans, tmpa);
	ans = modminus(ans, tmpb);
	ans = modminus(ans, 1);
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
typedef int SegT;
const int defvalue=0;
int main(){
	string s;
	cin>>s;
	int c=0;
	rep(i,s.size())if(s[i]=='g')c++;
	else c--;
	cout<<c/2<<endl;
}







Measured memory_bytes: 640
n,k = map(int,input().split())
a = list(map(int,input().split()))
from fractions import gcd
g = a[0]
for i in a[1:]:
    g = gcd(g,i)
if k<=max(a) and k%g==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 14096
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}


void solve(LL r){
    cout << r * r * 3 << endl;
}

int main(){
    LL r;
    scanf("%lld",&r);
    solve(r);
    return 0;
}


Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>

using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//# define m 163577857
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)

const ll mod = 1000000007;
const int K = 2;
//typedef vector<vector<int> > matrix;
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}


signed main()
{
    gok
   //fact0();
  int a,b,n;
  cin>>a>>b>>n;
  int x = min(b-1,n);
  int a1 = (a*x)/b;
  cout<<a1;













    return 0;
    }


Measured memory_bytes: 3612
N = list(map(int,input().split()))
x = N[2] - N[0]
y = N[3] - N[1]
for i in range(0,3,2):
	N[i]-=y
	N[i+1]+=x
print(N[2],end=" ")
print(N[3],end=" ")
print(N[0],end=" ")
print(N[1],end=" ")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
string S;
string T;
int SA[100011];
int SB[100011];
int TA[100011];
int TB[100011];
int q;
int aa[100001];
int bb[100001];
int cc[100001];
int dd[100001];

int main(){
	cin>>S>>T;
	REP(i,100011){
	    SA[i]=0;
	    SB[i]=0;
	    TA[i]=0;
	    TB[i]=0;
	}
	REP(i,S.size()){
	    if(S[i]=='A'){
	       SA[i+1]++;
	    }else{
	       SB[i+1]++;
	    }
	    SA[i+1]+=SA[i];
	    SB[i+1]+=SB[i];
	    
	}
	REP(i,T.size()){
	    if(T[i]=='A'){
	       TA[i+1]++;
	    }else{
	       TB[i+1]++;
	    }
	    TA[i+1]+=TA[i];
	    TB[i+1]+=TB[i];
	}
	cin>>q;
	REP(i,q){
	    cin>>aa[i]>>bb[i]>>cc[i]>>dd[i];
	    aa[i]--;cc[i]--;
	}
	REP(i,q){
	    int a=aa[i],b=bb[i],c=cc[i],d=dd[i];
	    
	    LL temp=(SA[b]-SA[a])-(SB[b]-SB[a])+3*100000000;
	    LL temp2=(TA[d]-TA[c])-(TB[d]-TB[c])+3*100000000;
	    //cout<<"a"<<SA[b]-SA[a]<<"b"<<SB[b]-SB[a]<<endl;
	    //cout<<temp%3<<" "<<temp2%3<<endl;
	    if(temp%3==temp2%3){
	        cout<<"YES"<<endl;
	    }else{
	        cout<<"NO"<<endl;
	    }
	}
	return(0);
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N;
    cin >> N;
/*
    repd(i, 2, N + 1) {
        ll t = N;
        while (t % i == 0) {
            t /= i;
        }
        if (t % i == 1) cout << i << endl;
    }
    */

    ll ans = 0;
    set<ll> st;
    for (ll i = 2; i * i <= N; i++) {
        ll t = N;
        while (t % i == 0) {
            t /= i;
        }
        if (t % i == 1) {
            if (st.count(i) == 0) {
                ans++;
                st.insert(i);
            }
            ll n = N;
            ll t2 = N / i;
            while (n % t2 == 0) {
                n /= t2;
            }
            if (n % t2 == 1 && st.count(t2) == 0) {
                ans++;
                st.insert(t2);
            }
        }
    }

    if (st.count(N) == 0) ans++;
    if (st.count(N - 1) == 0 && N - 1 > 1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 2e5+100;
typedef long long int lld;
typedef long long ll;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}


vector<ll> Ans, Adj[lim];
ll Array[lim], C[lim],dp[600][600];
pair<ll,ll> P[lim];

ll dfs(ll node,ll par) {
    ll countA=1;
    for(auto i: Adj[node]) {
        if(i!=par) {
            ll val = dfs(i,node);
            countA+= val;
            Ans.push_back(val);
        }
    }
    return countA;
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B;
    cin>>n; ans=0;
    maxA=0;
    rep(i,1,n) {
        cin>>x;
        if(x<maxA) ans += maxA-x;
        else maxA=x;
    }
    cout<<ans<<endl;

    return 0;
}
    


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

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int A,B;
  cin >> A >> B;
  if(B+A<24)
  {
    cout << B+A << endl;
  }
  else
  {
    cout << B+A-24 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin >>s>>t;
  int ans;
  if(s[0] == t[0]) ans ++;
  if(s[1] == t[1]) ans ++;
  if(s[2] == t[2]) ans ++;
  cout << ans;
  
  
}


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  for (int i = 0; i < N; i++) cin >> p[i];

  sort(p, p + N);
  
  cout << accumulate(p, p + K, 0) << endl;
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pii pair<int, int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(long long i = l;i<r;i++)

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds;

typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

mt19937 mt('O' + '4' + 'K' + 'O');

void kekek()
{
    
    mt();
    #ifdef EB_UG
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
    #ifndef EB_UG
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #endif
}

int main() {
    kekek();
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << ' ' << b << ' ' << c << endl;
}

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

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

  int N; cin >> N;
  int K; cin >> K;
  vector<pair<ll, int>> dt(N);
  for (int i = 0; i < N; i++) {
    int t; ll d;
    cin >> t >> d;
    t--;
    dt[i] = make_pair(d, t);
  }
  sort(dt.begin(), dt.end());
  reverse(dt.begin(), dt.end());

  ll ans = 0;
  ll x = 0;
  vector<int> cnt(N, 0);
  for (int i = 0; i < K; i++) {
    pair<ll, int> p = dt[i];
    ans += p.first;
    cnt[p.second]++;

    if (cnt[p.second] == 1) {
      x++;
    }
  }
  ans += x * x;

  int l = K, r = K - 1;
  ll temp = ans;
  while (true) {
    pair<ll, int> p;
    while (true) {
      l--;
      if (l < 0) break;
      p = dt[l];
      if (cnt[p.second] > 1) {
        temp -= p.first;
        cnt[p.second]--;
        break;
      }
    }
    while (true) {
      r++;
      if (r >= N) break;
      p = dt[r];
      if (cnt[p.second] == 0) {
        temp += p.first;
        cnt[p.second]++;
        break;
      }
    }

    if (l < 0 || r >= N) break;
    temp -= x * x;
    x++;
    temp += x * x;
    ans = max(ans, temp);
  }
  cout << ans << '\n';
  return 0;
}

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

int main()
{
  i64 N;
  cin >> N;
  vector<i64> A(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];
  i64 ans = 0;
  for (i64 i = 0; i < N; i++)
    ans = A[i] * 2 - ans;
  ans /= 2;
  for (i64 i = 0; i < N; i++)
  {
    cout << ans << " \n"[i + 1 == N];
    ans = A[i] * 2 - ans;
  }
  return 0;
}


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

int main()
{
  char c[2][3];
  cin >> c[0][0] >> c[0][1] >> c[0][2] >> c[1][0] >> c[1][1] >> c[1][2];
  if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int n, a, b;
	vector<int> v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a == 0) {
			cin >> b;
			v.push_back(b);
		}
		else if (a == 1) {
			cin >> b;
			cout << v[b] << endl;
		}
		else {
			v.pop_back();
		}
	}
	return 0;
}


Measured memory_bytes: 3928
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func scanStrings(n int) []string {
	sl := make([]string, n)
	for i := range sl {
		sl[i] = scanString()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	A, P := scanInt(), scanInt()
	fmt.Println((3*A + P) / 2)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  ll a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  if(b <= n) n = n / b * b - 1;
  printf("%lld\n", a * n / b - a * (n / b));
}

Measured memory_bytes: 3704
#lang:reverse.py

result = 0
str = input()
#文字数
str_length = len(str)
rev_str = str[::-1]
count = 0

if str_length % 2 == 1:
    count = (str_length -1)/2
else:
    count = str_length / 2


for i in range(int(count)):
    if str[i] != rev_str[i] :
        result = result + 1

print(result)


Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var N, A, B,  na, nb int
	var S string
	fmt.Scan(&N, &A, &B)
	fmt.Scan(&S)
	s := []byte(S)
	for i := 0; i < N; i++ {
		switch s[i] {
		case 'a':
			if A + B > na + nb {
				fmt.Println("Yes")
			}else{
				fmt.Println("No")
			}
			na++
		case 'b':
			if A + B > na + nb && B > nb{
				fmt.Println("Yes")
				nb++
			}else{
				fmt.Println("No")
			}
		case 'c':
			fmt.Println("No")
		}
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

Measured memory_bytes: 3328