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

int main() {
  int n;
  cin >> n;
  int r = n % 1000;
  if(r == 0){
    cout << 0 << endl;
    return 0;
  }else{
    cout << 1000 - r << endl;
    return 0;
  }
}

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

int maxProfit(vector<int>& A, int N){
  int maxProfit = -2000000000;
  int minR = A[0];
  for (int i=1;i<N;i++){
      maxProfit = max(maxProfit, A[i] - minR);
      minR = min(minR, A[i]);
  }
  return maxProfit;
}

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

 int sw = maxProfit(A,N);
 cout<<sw<<endl;
}


Measured memory_bytes: 3620
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;


void solve()
{
    ll n,m,s=0,p=0,q;
    cin >> n >> m;
    vector<bool> a(n+5,false);
    vll b(n+5,0);

    bool is;
    string str;

    f(i,1,m)
    {
        cin >> q >> str;
        is = str=="AC";
        if(!a[q])
        {
            if(is)
            {
                a[q]=true;
            }
            else
            {
                b[q]++;
            }
        }
    }

    f(i,1,n)
    {
        if(a[i])
        {
            s++;
            p+=b[i];
        }
    }
    cout << s << " " << p;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

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

ll mod = 1e9+7;
//a+2b=X,2a+b=Y => b=(X-a)/2 and Y-2a  

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    ll X,Y; cin>>X>>Y;
    ll N = max(X,Y/2);
    ll a,b=-1;
    rep(i,N+1){
        if((X-i)/2.0 == Y-2*i){
            a=i;
            b=Y-2*i;
        }
    }
    if(b==-1){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    rep(i,a){
        ans*=(a+b-i);
        ans%=mod;
    } 
    ll c=1;
    rep(i,a){
        c*=(a-i);
        c%=mod;
    }
    cout<<(ans*modinv(c,mod))%mod<<endl;
    return 0;
}

Measured memory_bytes: 3636
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> Int -> Int -> Int
solve k a b
  | k == 1     = 2
  | b <= a + 2 = k + 1
--  | a == 1     = b + (b-a) * q + r
  | a + 1 > k  = k + 1
  | otherwise = b + (b-a) * q + r
  where (q,r) = divMod (k - (a+1)) 2

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_k,bs_a,bs_b]:remLines1 = remLines0
      k = readBInt bs_k
      a = readBInt bs_a
      b = readBInt bs_b
  in solve k a b

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "4 2 6\n"
inp2 = "7 3 4\n"
inp3 = "314159265 35897932 384626433\n"
inp4 = "2 1 10\n"
inp5 = "4 1 10\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
tv4 = tmain $ B.pack inp4
tv5 = tmain $ B.pack inp5
test1 = tv1 == 7
test2 = tv2 == 8
test3 = tv3 == 48518828981938099
test4 = tv4 == 10
test5 = tv5 == 19
alltest = test1 && test2 && test3 && test4 && test5



Measured memory_bytes: 380
#include<stdio.h>
int main(){
	int n, i, k, one=0;
	const int max=100000;
	int sosu[max+1];
	for(i=2;i<=max;i++){
		sosu[i]=1;
	}
	for(i=2;i*i<=max;i++){
		if(sosu[i]){
			for(k=2*i;k<=max;k+=i){
				sosu[k]=0;	
			}
		}
	}	
//	printf("%d",sosu[7]);	
//	printf("%d",sosu[8]);
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=n;one==0;i--){
			if(sosu[i]==1 && sosu[i-2]== 1){
				printf("%d %d\n",i-2,i);
				one=1;
			}
		}
		one=0;
	}	
	return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	int minusNum = 0;
	int plusNum = 0;

	//true = 1, false = 0
	//boolはint型の足し算ができる
	bool containsZero = false;
	int zeroPoint;

	vector<long long int> x;

	rep(i, n){
		long long int a;
		cin >> a;
		x.push_back(a);

		if(a == 0){
			containsZero = true;
			zeroPoint = i;
		}
		else if(a < 0){
			minusNum++;
		}
		else{
			plusNum++;
		}
	}

	//真の答え
	long long int ans = __LONG_LONG_MAX__;

	//正の方向にいけるだけ進み、負に引き返す　条件：正の要素が存在する
	rep(i, k){
		if(i >= plusNum + containsZero) break;

		int node = minusNum + i;
		if(node - k + 1 < 0) continue;

		long long int total;
		if(x[node - k + 1] < 0) total = 2 * abs(x[node]) + abs(x[node - k + 1]);
		else total = abs(x[node]);

		if(total < ans) ans = total;
	}

	//負の方向にいけるだけ進み、正に引き返す　条件：負の要素が存在する
	rep(i, k){
		if(minusNum + containsZero - i - 1 < 0) break;

		int node = minusNum + containsZero - i - 1;
		if(n <= node + k - 1) continue;

		long long int total;
		if(0 < x[node + k - 1]) total = 2 * abs(x[node]) + abs(x[node + k - 1]);
		else total = abs(x[node]);

		if(total < ans) ans = total;
	}

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

Measured memory_bytes: 1400
#!/usr/bin/env python3
n,m = map(int,input().split())
a = list(map(int,input().split()))
lim = sum(a)/(4*m)
a.sort()
for i in range(m):
    if a[-1-i] >= lim:
        continue
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 38256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	string s;
	while(cin >> s && s != "0"){
		int ans = 0;
		for(auto i:s)ans += (i - '0');
		cout << ans << '\n';
	}
	return 0;
}



Measured memory_bytes: 3148
using System;

class A{
  public static void Main(){
    int n,count = 0;
    n = int.Parse(Console.ReadLine());
    int[] array = new int[n];

    string[] str = Console.ReadLine().Split(' ');
    for(int i = 0;i < n;i++){
      array[i] = int.Parse(str[i]);
    }

    for(int i = 0;i < n - 1;i++){
      for(int j = n - 1;j > i;j--){
        if(array[j].CompareTo(array[j-1]) < 0){
          Swap(ref array[j],ref array[j-1]);
          count++;
        }
      }
    }

    for(int i = 0;i < n - 1;i++){
    Console.Write(array[i] + " ");
    }
    Console.Write(array[n - 1]);
    Console.WriteLine("");

    Console.WriteLine(count);
    }

    static void Swap(ref int x,ref int y){
      int temp;
      temp = x;
      x = y;
      y = temp;
    }
}


Measured memory_bytes: 9144
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    char start = *(a[0].end() - 1);
    REP(i, 1, n)
    {
        if (a[i][0] == start)
        {
            start = *(a[i].end() - 1);
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }
    set<string> b(a.begin(), a.end());
    if (b.size() == a.size())
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int judge(int num[],int n)
{
  int i,j,count=0,d[101]={0};
  for(i=0; i<n; i++)
    d[num[i]]++;
  for(i=0; i<=100; i++)
    if(d[i]>0)
      count++;
  return count;
}
int main()
{
  int i,n;
  scanf("%d",&n);
  int num[n];
  for(i=0; i<n; i++)
    scanf("%d",&num[i]);
  printf("%d\n",judge(num,n));
  return 0;
}

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

int main(void)
{
    char s[100], t[100], u[100];

    scanf("%s", s);
    scanf("%s", t);
    scanf("%s", u);

    printf("A%cC", t[0]);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){

int n;
  cin >> n;
  
long dp[n+1][2];
  long a[n];
  
  dp[0][0]=0;
  dp[0][1]=-10000000000;
  
  for(int i=0;i<n;i++){
   cin >> a[i];
    
    dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]);
    dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]);
  }
    

 cout << dp[n][0] << endl;


}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int count[26] = {};
    string s;
    while(true)
    {
        cin >> s;
        if(cin.eof())
        {
            break;
        }
        for(int i = 0;i < s.size();i++)
        {
            if(s[i] >= 'a' && s[i] <= 'z')
            {
                count[s[i] - 'a']++;
            }
            else if(s[i] >= 'A' && s[i] <= 'Z')
            {
                count[s[i] - 'A']++;
            }
        }
    }
    for(int i = 0;i < 26;i++)
    {
        cout << (char)('a' + i) << " : " << count[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/math/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  boost::for_each(vc, [&os, &vc](T value) {
    os << value;
    if (value != vc.back())
      os << ' ';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream&
operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  //using std::string;
  //string S{}; std::cin >> S;
  //ui N{}; std::cin >> N;

  ull A{}, B{}, C{}, D{};
  std::cin >> A >> B >> C >> D;

  auto culc = [](ull a, ull b, ull mod) {
    return b / mod - (a - 1) / mod;
  };

  ull modC = culc(A, B, C);
  ull modD = culc(A, B, D);
  ull CD = boost::math::lcm(C, D);
  ull modCD = culc(A, B, CD);

  auto ans = (B - A + 1) - (modC + modD) + modCD;

  std::cout << ans << '\n';

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];

        for(int i=0;i<N;i++){
            x[i] = sc.nextInt();
        }
        int ans = (int) 2e9;

        for(int i=0;i<=N-K;i++){
            ans = Math.min(ans, dist(x[i], x[i+K-1]));
        }

        System.out.println(ans);
    }

    public static int dist(int A, int B){
        return Math.min(Math.abs(A)+Math.abs(A-B), Math.abs(B) + Math.abs(A-B));
    }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    ll N,A,B; cin >> N >> A >> B;
    vector<ll> X(N);
    REP(i,N){
        cin >> X[i];
    }
    vector<ll> d(N-1);
    ll ans = 0;
    REP(i,N-1){
        ans += min((X[i+1] - X[i])*A, B);
    }
    cout << ans << endl;
    return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, t;
  std::cin >> n >> t;
  std::vector<int64_t> a(n);
  std::cin >> a;

  int64_t val = -1, count = 0, max = a.back();

  for (auto i = a.crbegin(); i != a.crend(); i++) {
    max = std::max(*i, max);
    const auto dif = max - *i;
    if (val < dif) {
      val = dif;
      count = 1;
    } else if (val == dif) {
      count++;
    }
  }
  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 1024
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    int H,W;
    cin >> H >>W;
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i,N) cin>>a[i];
    vector<vector<int>> G(H+2,vector<int>(W+2,-1));

    vector<pair<int,int>> mode={{0,1},{1,0},{0,-1},{-1,0}};
    REP(i,H+2){
        REP(j,W+2){
            if(i==0||i==H+1||j==0||j==W+1) G[i][j]=0;
        }
    }
    int cnt=0;
    int num=0;
    int cnt2=0;
    int i_mode=0;
    int x,y;
    x=1;
    y=1;
    while(cnt<H*W){
        G[x][y]=num+1;
        cnt2++;
        if(cnt2==a[num]){
            cnt2=0;
            num++;
        }
        if(G[x+mode[i_mode].first][y+mode[i_mode].second]!=-1){
            i_mode++;
            i_mode%=4;
        }
        x=x+mode[i_mode].first;
        y=y+mode[i_mode].second;
        cnt++;
        
    }

    REP2(i,1,H+1){
        REP2(j,1,W+1){
            cout << G[i][j];
            if(j!=W) cout << " ";
        }
        cout << endl;
    }
    

    
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in(), k = in();
    vll h = in(n);
    sort(ALL(h));
    ll ans = 0;
    rep(i, max(n - k, (ll)0))
    {
        ans += h[i];
    }
    cout << ans << endl;
}

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const int MAX_N = 100100;
const int MOD = 1e9+7;
const int A = 0, G = 1, C = 2, T = 3;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e%2 == 0) { p = (p*p)%mod; e /= 2; }
            else { a = (a*p)%mod; e--; }
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

int main() {
    int n;
    cin >> n;
    ModInt<MOD> dp[110][4][4][4];
    dp[0][T][T][T] = 1;
    for (int i = 0; i < n; i++) {
        rep(j, 4) rep(k, 4) rep(l, 4) rep(m, 4) {
            if (k == A && l == G && m == C) continue;
            if (j == A && l == G && m == C) continue;
            if (j == A && k == G && m == C) continue;
            if (k == G && l == A && m == C) continue;
            if (k == A && l == C && m == G) continue;
            dp[i+1][k][l][m] += dp[i][j][k][l];
        }
    }
    
    ModInt<MOD> ans = 0;
    rep(i, 4) rep(j, 4) rep(k, 4) ans += dp[n][i][j][k];
    cout << ans << endl;
    return 0;
}
    

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

int power(int m, int n) {
	long long res = 1, mm = m;
	while (n) {
		if (n & 1) res = (res * mm) % MOD;
		mm = (mm * mm) % MOD;
		n >>= 1;
	}
	return (int)res;
}

int main()
{
	int m, n;
	cin >> m >> n;
	cout << power(m, n) << endl;
	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int flag=0,len;
	cin>>s;
	len=s.length();
	for(int i=0;i<len;i++){
		if(s[i]=='C') flag=1;
		if(flag&&s[i]=='F'){
			cout<<"Yes";
			return 0;
		} 
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String line = br.readLine();
			if ("0".equals(line))
				break;
			int n = Integer.parseInt(line);

			line = br.readLine();
			String[] scores = line.split(" ");
			double sum = 0;
			for (String score : scores) {
				sum += Integer.parseInt(score);
			}
			double avg = sum / n;

			sum = 0;
			for (String score : scores) {
				sum += Math.pow(Integer.parseInt(score) - avg, 2);
			}
			double a2 = sum / n;

			System.out.printf("%.5f%n", Math.sqrt(a2));
		}

		if (br != null) {
			br.close();
			br = null;
		}
	}
}

Measured memory_bytes: 19784
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(W: int, H: int, x: int, y: int):
    area = W*H/2.0
    if x == W/2 and y == H/2:
        print(area, 1)
    else:
        print(area, 0)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(W, H, x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<long long, long long>;
const int INF = 1001001007;
const int mod = 1000000007;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    if (n == 1 || n == 2) cout << 0 << endl;
    else{
        ll b = 0;
        ll g = 0;
        ll r = 0;
        rep(i,n){
            if (s[i] == 'R') r++;
            else if (s[i] == 'G') g++;
            else b++;
        }
        ll ans = b * g * r;
        ll mi = 0;
        repp(i,n-1,1){
            repp(j,min(i,n-1-i)+1,1){
                if (s[i] != s[i+j] && s[i] != s[i-j] && s[i+j] != s[i-j]) mi++;
            }
        }
        cout << ans - mi << endl;
    }
}

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

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

	vector<long long> ans(10000);
	long long caln;
	for(long long i=1;i<=99;i++){
		for(long long j=1;j<=99;j++){
			for(long long k=1;k<=99;k++){
				caln = i*i+j*j+k*k+i*j+j*k+k*i;
				if(caln <=10000){
					ans.at(caln - 1)++;
				}
			}
		}
	}

	for(int i=0;i<N;i++){
		cout << ans.at(i) << endl;
	}

}


Measured memory_bytes: 3696
#include <iostream>
using namespace std;
int main(){
    long long n,ans=1000000000000000LL;
    cin>>n;
    for(long long i=1LL;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,i+(n/i)-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))

    mt = 0
    for i in range(n):
        zs = s[i:]
        zln = len(zs)
        zl = [0] * zln
        zi = 1
        zj = 0
        while zi < zln:
            while zi + zj < zln and zs[zj] == zs[zi+zj]:
                zj += 1
            zl[zi] = zj
            if zj == 0:
                zi += 1
                continue
            zk = 1
            while zi + zk < zln and zk + zl[zk] < zj:
                zl[zi+zk] = zl[zk]
                zk += 1
            zi += zk
            zj -= zk

        for j in range(len(zl)):
            if zl[j] <= j:
                mt = max(mt, zl[j])
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 47708
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD ((ll)(1e+9)+7)

ll pow2(int n){
  ll ret = 1;
  for(int i = 0; i < n; i++){
    ret = (ret*2) % MOD;
  }
  return ret;
}


int main(){
  int n;
  int a[100001] = {};
  int cnt[100001] = {};
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  if(n%2 == 1) cnt[0]++;
  for(int i = 0; i < n; i++){
    if(++cnt[a[i]] > 2){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i = 0; i < n; i++){
    if(cnt[a[i]] == 1){
      cout << 0 << endl;
      return 0;
    }
  }
  cout << pow2(n/2) << endl;
}

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

struct Dice{
    int one, two;
};

int main(){
    int N;
    cin >> N;
    Dice dice[N];

    for (int i = 0; i < N; ++i){
        cin >> dice[i].one >> dice[i].two;
    }

    int cnt = 0;
    for (int i = 0; i < N; ++i){
        if (dice[i].one == dice[i].two){
            cnt += 1;
        } else{
            cnt = 0;
        }
        if (cnt == 3){
            cout << "Yes" << endl;
            exit(0);
        }
    }
    cout << "No" << endl;
}

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

#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i,n)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx= 0;
    for(auto p: mp)mx = max(mx, p.second);
    for(auto p : mp)
    {
        if(p.second == mx) cout << p.first << endl;
    } 
    return 0;
}

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

int main(){
    int x,hantei;
    cin>>x;
    vector<int>P(x);
    int ans=1;
    for(int i=0;i<x;i++){
        cin>>P.at(i);
    }
    hantei=P.at(0);
    for(int i=1; i<x;i++){
        if(P.at(i)<hantei){
            ans++;
            hantei=P.at(i);
        }
    }
    cout<<ans<<endl;

}

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

int main() {
  int N;
  
  cin >> N;
  vector<double> v(N);
  for(int i = 0; i < N;i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  double amount = (v.at(0)+v.at(1))/std::pow(2,N-1);
  for(int i = 2; i < N;i++) {
    amount = amount + v.at(i)/std::pow(2,N-i);	
  }
  cout << amount << endl;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	for(int i=K; i<N; i++){
		if(A[i]>A[i-K]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    //100A + 100B + C + D <= 3000
    //maximize 100(C+D)/(100A + 100B + C + D)
    //s1/w1 <= s2/w2 <=> s1*w2 <= s2*w1
    //100A+100Bの水に対し(A+B)*Eの砂糖を溶かせる
    int A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F;
    int mx_water = 100*A;
    int mx_sugar = 0;
    int op_A = 100*A;
    int op_B = 100*B;
    int op_C = C;
    int op_D = D;
    for(int i = 0; i <= 30; i++){
        for(int j = 0; j <= 30; j++){
            int water = op_A * i + op_B * j;
            int sugar_lim = min((A*i+B*j)*E, F-water);
            for(int k = 0; k <= sugar_lim; k+=op_C){
                for(int l = 0; k+l <= sugar_lim; l+=op_D){
                    if((k+l)*mx_water >= mx_sugar*water){
                        mx_water = water;
                        mx_sugar = k+l;
                    }
                }
            }
        }
    }
    cout << mx_water+mx_sugar << " " << mx_sugar << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
int main()
{
  int m[MAX][MAX],i,n,pri[MAX],l,q,j,k,p;
  while(1)
    {
      scanf("%d",&p);
      if(p>=1&&p<=100)
	break;
    }
  for(i=1;i<=p;i++)
    {
      scanf("%d%d",&pri[i-1],&pri[i]);
      if((pri[i-1]<1 && pri[i-1]>MAX) || (pri[i]<1 && pri[i]>MAX))
	i--;
    }
  for(i=1;i<=p;i++)
    m[i][i]=0;
  for(l=2;l<=p;l++)
    {
      for(i=1;i<=p-l+1;i++)
	{
	  j=i+l-1;
	  m[i][j]=100000000;
	  for(k=i;k<=j-1;k++)
	    {
	      q=m[i][k]+m[k+1][j]+pri[i-1]*pri[k]*pri[j];
	      if(q<m[i][j])
		m[i][j]=q;
	    }
	}
    }
  printf("%d\n",m[1][p]);
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;

ll n,a[200007],sum,res;

int main() {
    scanf("%lld",&n);res=n-1;
    for (int i=1;i<=n;++i) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    sum=a[n],res--;
    for (int i=n-1;i;--i){
        if (res) sum+=a[i],--res;
        if (res) sum+=a[i],--res;
        if (!res) break;
    }
    printf("%lld\n",sum);
    return 0;
}


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

int main() {
    int n, k;
    string s;
    cin >> n >> s >> k;

    char target = s[k-1];
    for (int i=0; i<s.size(); i++) {
        if (s[i] != target) s[i] = '*';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: usize, k: usize, q: usize, a: [u32; n]);

    let cal = |y: u32| {
        let mut r = 0;
        let mut cand: Vec<u32> = vec![];
        while r < n {
            let mut l = r;
            while l < n && a[l] < y {
                l += 1;
            }
            r = l;
            while r < n && y <= a[r] {
                r += 1;
            }
            if k <= r - l {
                let mut alr = a[l..r].to_vec();
                alr.sort();
                cand.extend(&alr[0..=r - l - k]);
            }
        }
        cand.sort();
        if q <= cand.len() {
            Some(cand[q - 1])
        } else {
            None
        }
    };

    let mut ans = std::u32::MAX;
    for &y in &a {
        if let Some(x) = cal(y) {
            if x - y < ans {
                ans = x - y;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2260
#include<iostream>
using namespace std;
int main(){
	long long a,b,x;
	cin >> a >> b >> x;
	long long aa,ans=0;
	aa=(a/x+(a%x==0?0:1))*x;
	ans=(b-aa)/x+(aa>b?0:1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair <int,int>
#define ull unsigned long long
#define mp make_pair
#define s second
#define f first                                          
#define _ ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

const int maxn = (int)(1e5)+2;
const int mod = (int)(1e9)+7;

int n;
map <int,int> cnt;
vector <int> a;

int main() {
	_
	cin >> n;
	for (int i = 1; i <= n; i++) {
	 	int x;
	 	cin >> x;
	 	cnt[x]++;
	 	if (cnt[x]==2) a.pb(x);
	}
	sort(a.begin(),a.end());

	if (a.size()>=1 && cnt[a.back()]>=4) {
	 	cout << a.back()*1ll* a.back();
	}
	else if (a.size()>=2){
		cout << a[a.size()-1] * 1ll * a[a.size()-2];
	}
	else
		cout<<0;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
#define INT_MAX 1<<30
const ll mod = 1e9+7;

map<ll,ll> prime_factor(ll n){
	map<ll,ll> mp;
	for(ll i=2; i*i<=n; i++){
		while(n % i == 0){
			mp[i]++;
			n /= i;
		}
	}
	if(n != 1) mp[n] = 1;
	return mp;
}

int main(){
	ll n,p; cin >> n >> p;
	auto mp = prime_factor(p);
	ll ans = 1;
	for(auto i : mp){
		ans *= pow(i.first,i.second/n);
	}
	cout << ans << endl;
}


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

LL A, B, C, D;
map<LL, LL> memo;
LL solve(LL N) {
    if (N == 0) return 0;
    if (N == 1) return D;
    if (memo.count(N)) return memo[N];
    LL l2 = (N/2)*2;
    LL r2 = ((N+1)/2)*2;
    LL l3 = (N/3)*3;
    LL r3 = ((N+2)/3)*3;
    LL l5 = (N/5)*5;
    LL r5 = ((N+4)/5)*5;

    LL res = 1e18;
    if (N < res/D) res = N*D;
    res = min(res, llabs(l2-N)*D + A + solve(l2/2));
    res = min(res, llabs(r2-N)*D + A + solve(r2/2));

    res = min(res, llabs(l3-N)*D + B + solve(l3/3));
    res = min(res, llabs(r3-N)*D + B + solve(r3/3));

    res = min(res, llabs(l5-N)*D + C + solve(l5/5));
    res = min(res, llabs(r5-N)*D + C + solve(r5/5));

    memo[N] = res;

    return res;
}

int main() {
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        memo.clear();
        LL N;
        cin >> N;
        cin >> A >> B >> C >> D;
        cout << solve(N) << "\n";
    }
}


Measured memory_bytes: 4336
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    int n,m;
    string s[120],t[120];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>t[i];
    }
    
    int count[120];
    for(int i=0;i<n;i++){
        count[i]=0;
    }
    
    
    for(int i=0;i<120;i++){
        for(int j=0;j<120;j++){
            if(s[i]==s[j]){
                count[i]+=1;
            }
            if(s[i]==t[j]){
                count[i]-=1;
            }
            
        }
    }
    
    sort(count,count+n);
    if(count[n-1]<=0){
        cout<<"0"<<endl;
    }else{
    cout<<count[n-1]<<endl;
    }
    
    
    return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main (void){
    int n, m;
    cin >> n >> m;
    int sum = 0;
    rep(i, m) {
        int in;
        cin >> in;
        sum += in;
    }
    if (n - sum < 0) cout << -1 << endl;
    else cout << n - sum  << endl;
}


Measured memory_bytes: 3572
#include<cstdio>

using namespace std;

int main(){
	int k, s; scanf("%d %d", &k, &s);
	int res = 0;
	for(int x = 0; x <= k; x++) for(int y = 0; y <= k; y++){
		int z = s - x - y;
		if(0 <= z && z <= k) res++;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    char s[100001];
    scanf("%s",s);
    long int a=0;
    long int ans=0;
    while(s[a]!=NULL)
      a++;
    char ss[100001] = {};
    long int b=-1;
    for(long int p=0;p<a;p++)
    {
        if(s[p]!=0x78)
        {
            b++;
            ss[b]=s[p];
        }
    }
    if(ss[0]==0)
    {
        printf("0");
        return 0;
    }
    char sss[a];
    for(long int q=0;q<b+1;q++)
      sss[q]=ss[b-q];
    long int min=0;
    long int max=a-1;
    long int mincount=0;
    long int maxcount=0;
    long int check=8;
    long int t[a];
    long int aans=0;
    //printf("%s\n%s\n%s\n",s,ss,sss);
    for(long int u=0;u<b+1;u++)
    {
        if(ss[u]==sss[u])
          aans++;
    }
    if(aans!=b+1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        for(long int r=0;r<a;r++)
        {
            if(s[r]==0x78)
              t[r]=0;
            else
              t[r]=1;
        }
        //for(int w=0;w<a;w++)printf("%d",t[w]);
        while(check!=0 && min<max)
        {
            check=0;
            while(t[min]!=1)
            {
                min++;
                mincount++;
            }
            while(t[max]!=1)
            {
                max--;
                maxcount++;
            }
            if(mincount>=maxcount)ans+=mincount-maxcount;
            else ans+=maxcount-mincount;
            mincount=0;
            maxcount=0;
            min++;
            max--;
            for(int y=min;y<max+1;y++)
            {
                check+=t[y];
            }
        }
    }
    printf("%ld",ans);
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <string.h>

int main(void){
   int n,i,alp[26];
   char str[101];

   scanf("%s",str);
   n=strlen(str);

   for(i=0;i<26;i++)
      alp[i]=0;

   for(i=0;i<n;i++)
      alp[str[i]-'a']++;

   for(i=0;i<26;i++)
      if(alp[i]%2!=0){printf("No\n");return 0;}
   printf("Yes\n");
   return 0;
}

Measured memory_bytes: 1632
void main() {
	auto ip = readAs!(int[]), N = ip[0], u = ip[1], v = ip[2];
	auto tree = new Edge[][](N,0);
	foreach(i; 0..N-1)
	{
		auto ip2 = readAs!(int[]), A = ip2[0], B = ip2[1];
		A--; B--;
		tree[A] ~= Edge(B, 1);
		tree[B] ~= Edge(A, 1);
	}
	auto distv = dijkstra(tree, v-1);
	auto distu = dijkstra(tree, u-1);

	ulong res = 0;
	foreach(i; 0..N) {
		if(distu[i] < distv[i]) {
			res = max(res, distv[i]);
		}
	}
	writeln(res - 1);
}

const inf = (1<<30);

alias Edge = Tuple!(int,"to", int ,"cost");
alias tie = Tuple;

int[] dijkstra(in Edge[][] tree, int start) {
    import std.container;
    import std.algorithm;
    alias PriorityQueue = BinaryHeap;

    ulong V = tree.length;
    auto dist = new int[V];
    fill(dist, inf);

    // priority_queue
    auto queue = new PriorityQueue!(Array!Edge, "a.cost>=b.cost")();

    dist[start] = 0;
    queue.insert(Edge(start,0));
    while (!queue.empty())
    {
        int v;
        int cost;
        auto aaaa = queue.front();
        v = aaaa[0], cost = aaaa[1];
        queue.popFront();

        // another shorter path was already found, skip
        if (dist[v] < cost)
            continue;
        foreach(const ref Edge e; tree[v])
        {
            if (dist[v] + e.cost < dist[e.to])
            {
                dist[e.to] = dist[v] + e.cost;
                // found new shorter path,
                // push to queue for re-calculate path
                queue.insert(Edge(e.to, dist[e.to]));
            }
        }
    }
    return dist;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 19708
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

struct edge{
	int to,cost;
	edge(int to,int cost):to(to),cost(cost){}
};

int N,M,K;
vector<edge> G[3010];
int dist[3010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>M>>K;
	int a,b,l;
	rep(i,M){
		cin>>a>>b>>l;
		a--,b--;
		G[a].pb(edge(b,l));
		G[b].pb(edge(a,l));
	}
	int s;
	rep(i,K){
		cin>>s;
		s--;
		G[N].pb(edge(s,0));
	}
	fill(dist,dist+N+1,INF);
	dist[N]=0;
	priority_queue<pi,vector<pi>,greater<pi> > Q;
	Q.push(pi(0,N));
	while(sz(Q)){
		pi p=Q.top();
		Q.pop();
		int v=p.sec;
		if(dist[v] < p.fir)continue;
		rep(i,sz(G[v])){
			int nd=dist[v]+G[v][i].cost;
			if(nd < dist[G[v][i].to]){
				dist[G[v][i].to]=nd;
				Q.push(pi(nd,G[v][i].to));
			}
		}
	}
	int ans=*max_element(dist,dist+N+1);
	rep(i,N+1)rep(j,sz(G[i])){
		if(dist[i] <= dist[G[i][j].to]){
			ans=max(ans,
			dist[G[i][j].to] + (G[i][j].cost-(dist[G[i][j].to]-dist[i])+1)/2);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4212
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e+5;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

void solve() {
    int n;
    cin >> n;
    ll a[N];
    rep(i, n) {
        cin >> a[i];
    }
    vector<ll> v(a, a+n);
    sort(ALL(v));
    v.push_back(0);

    int ans = 0;
    int c = 0;
    rep(i, n) {
        ++c;
        if (v[i] != v[i+1]) {
            if (c >= v[i]) {
                ans += c - v[i];
            }
            else {
                ans += c;
            }
            c = 0;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int h[n];
	for(int i=0; i<n; ++i){
		cin>>h[i];
	}
	
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[0]-h[1]);
	for(int i=2; i<n; ++i){
		dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
S = input()

N = len(S)
N1 = (N-1)//2
N2 = (N+3)//2
#print(N1,N2)
flag = 0

for i in range(N//2):
    #print(S[i], S[-(i+1)])
    if S[i] != S[-(i+1)]:
        flag = 1

for i in range(N1//2):
    #print(S[i], S[-(i+1+N1+1)])
    if S[i] != S[-(i+1+N1+1)]:
        flag = 1

for i in range(N1//2):
    #print(S[i+N2-1], S[-(i+1)])
    if S[i+N2-1] != S[-(i+1)]:
        flag = 1

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

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std;
int main() {
string s;
cin>>s;
if(s=="Sunny"){
    cout<<"Cloudy"<<endl;
}
if(s=="Rainy"){
    cout<<"Sunny"<<endl;
}
if(s=="Cloudy"){
    cout<<"Rainy"<<endl;
}

return 0;
}

Measured memory_bytes: 256
line = [int(s) for s in input().split()]
A = line[0]
B = line[1]
C = line[2]
D = line[3]

while A > 0:
    C = C - B
    if not(C > 0):
        print('Yes')
        break
    A = A - D

if not(A > 0):
    print('No')

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

using ll = long long;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> K(Q); cin >> K;

    vector<int> sumd(N), summ(N), ic;
    vector<ll> sumdm(N);
    for (int i = 0; i < N; i++) {
        sumd[i] = (i == 0 ? 0 : sumd[i-1]) + (S[i] == 'D' ? 1 : 0);
        summ[i] = (i == 0 ? 0 : summ[i-1]) + (S[i] == 'M' ? 1 : 0);
        sumdm[i] = (i == 0 ? 0LL : sumdm[i-1]) + (S[i] == 'M' ? sumd[i] : 0);
        if (S[i] == 'C') ic.push_back(i);
    }

    for (int k : K) {
        ll ans = 0;
        for (const int& i : ic) {
            ll dm = 0;
            if (i - 1  >= 0) {
                dm = sumdm[i-1];
                if (i - k >= 0) {
                    dm -= sumdm[i-k];
                    dm -= (ll)sumd[i-k] * (summ[i-1] - summ[i-k]);
                }
            }
            ans += dm;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 23960
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	int A, B;
	cin >> A >> B;
	if (A == 1) A = 14;
	if (B == 1) B = 14;

	string ans;
	if (A > B) ans = "Alice";
	else if (A < B) ans = "Bob";
	else ans = "Draw";

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


Measured memory_bytes: 256