akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<assert.h>
using namespace std;

int main(){

    unsigned long long int n, k;
    cin >> n >> k;
    vector<int> a(n + 1, -1);

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

    int now = 1;
    //naive
    if (k <= 200000)
    {
        //assert(now > 0);
        for (int i = 0; i < k; ++i)
        {
           // cout << now << " " << a[now] << endl;
            now = a[now];
        }
    }
    else{

        vector<int> isVisited(n + 1, false);
        queue<int> q;
        int roop_point = 0;
        long long int roop_size = 0;

        while(1){
            if(!isVisited[now])
            {
                q.push(now);
                isVisited[now] = true;
                now = a[now];
            }
            else{
                roop_point = now;
                break;
            }
        }

        while(1){
            int tmp = q.front();
            if(tmp!=roop_point){
                --k;
                q.pop();
            }
            else{
                roop_size = (long long int)q.size();
                break;
            }
        }

        long long int remnant = 0;
        if (roop_size != 0)
        {
            remnant = k % roop_size;
        }

        for (long long int i = 0; i < remnant;++i){
            now = a[now];
        }
    }

    cout << now << endl;

    return 0;
}

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

const int N = 11;

string n;
int val[N], l;

long long computed_val(int x) {
  long long sum = 0;
  int tmp = l-1;
  int prev = l; // chars remaining
//   cout << "call" << endl;
  while(tmp) {
    if (x&1) {
        // cout << tmp << ' ' <<  prev << endl;
        // cout << n.substr(tmp,prev-tmp) << endl;
      sum += stoll(n.substr(tmp,prev-tmp));
      prev = tmp;
    }
    tmp--;
    x >>= 1;
  }
//   cout << "tmp: " << tmp << endl;
//   cout << n.substr(0,prev) << endl;
  sum += stoll(n.substr(0,prev));
  return sum;
}

int main() {
  cin >> n;
  l = n.size();
  for (int i = 0; i < l; i++) val[i] = (int)(n[i]-'0');
  long long sum = 0;
  for (int x = 0; x < (1<<(l-1)); x++) sum += computed_val(x);
  cout << sum << endl;
  
  return 0; 
}

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

//#define FILE
//#define int long long
//#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fst first
#define scd second
#define inv(x) ksm((x),mod - 2)
#define lowbit(x) ((x) & (-(x)))

const int MAXN = 2e5 + 10;
const int INF = 2e9;
const double PI = acos(-1);
const double eps = 1e-6;
//const int mod = 1e9 + 7;
//const int mod = 998244353;
//const int G = 3;

int n,cnt,L,R,v,pos;
int a[MAXN],b[MAXN];

template<typename T> inline void read(T &a) {
	a = 0; char c = getchar(); int f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') {a = a * 10 + (c ^ 48); c = getchar();}
	a *= f;
}

signed main () {
#ifdef FILE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	read(n);
	for(int i = 1;i <= n; ++i) read(a[i]);
	for(int i = 1;i <= n; ++i) {
		read(b[i]);
		b[i] *= -1;
	}
	sort(b + 1,b + n + 1);
	for(int i = 1;i <= n; ++i) b[i] *= -1;
	for(int i = 1;i <= n; ++i) {
		if(a[i] == b[i]) {
			if(!L) L = i;
			R = i;
			cnt++;
		}
	}
	if(!cnt) {
		puts("Yes");
		for(int i = 1;i <= n; ++i)
			printf("%d ",b[i]);
		return 0;
	}
	assert(b[L] == b[R]);
	int ban = b[L]; pos = L;
	for(int i = 1;i < L; ++i) {
		if(b[i] == ban || a[i] == ban) continue;
		if(pos > R) break;
		swap(b[i],b[pos++]);
		if(pos > R) break;
	}
	for(int i = R + 1;i <= n; ++i) {
		if(b[i] == ban || a[i] == ban) continue;
		if(pos > R) break;
		swap(b[i],b[pos++]);
		if(pos > R) break;
	}
	bool flag = true;
	for(int i = 1;i <= n; ++i)
		if(a[i] == b[i]) {
			flag = false;
			break;
		}
	if(flag) {
		puts("Yes");
		for(int i = 1;i <= n; ++i)
			printf("%d ",b[i]);
		return 0;
	}
	puts("No");
	return 0;
}



Measured memory_bytes: 5320
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  int N;
  cin>>N;
  N%=10;
  
  if(N==2 || N==4 || N==5 || N==7 || N==9) cout<<"hon"<<endl;
  if(N==0 || N==1 || N==6 || N==8) cout<<"pon"<<endl;
  if(N==3) cout<<"bon"<<endl;
}

Measured memory_bytes: 3636
L,R = map(int, input().split())
l = L//2019
r = R//2019
m = L%2019
n = R%2019

ans = 2018
if l != r:
  print(0)
  exit()
else:
  for i in range(m,n):
    for j in range(i+1,n+1):
      ans = min((i*j) % 2019, ans)
      if ans == 0:
        print(ans)
        exit()
      
print(ans)

Measured memory_bytes: 3064
//Keep Working Hard
  // I__Like__Food
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 405
  #define INF 1e16
  const double PI = acos(-1);



int32_t main()
{
       


    int n;
    cin >> n;

    int dp[n+1][n+1];

    //dp[i][j] denotes the minimum cost to combine slimes from i to j

    for(int i = 0; i <= n; i++)
      {
        for(int j = 0; j <= n; j++)dp[i][j] = INF;
      }

    vector<int> arr(n+1),pre(n+1,0);

    for(int i = 1; i <=n; i++)
    {
      cin >> arr[i];
      pre[i] = pre[i-1] + arr[i];
      dp[i][i] = 0;
    }



    for(int i = 2; i <= n; i++)
    {
      //  here outer loop i represents the length of the interval being considered 
      for(int j = 1; j + i - 1<=n; j++)
      {
        int l = j;
        int r = j + i - 1;
        
           for(int k = l; k < r; k++)
          {
              int leftcost = pre[k]-pre[l-1];
              int rightcost = pre[r] - pre[k];

              dp[l][r] = min(dp[l][r],dp[l][k] + dp[k+1][r] + leftcost + rightcost);
          }
      }
    }

 
    cout << dp[1][n];



  return 0;
} 

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int a, b, t;
  cin >> a >> b >> t;
  
  int ans = (t/a) * b;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        var dp = new double[N + 1];
        dp[0] = 1;
        for (int j = 0; j < N; j++)
        {
            var p = cin.nextdouble;
            for (int i = N; i >= 0; i--)
            {
                dp[i] = dp[i] * (1 - p) + (i > 0 ? dp[i - 1] * p : 0);
            }
            //cin.join(dp);
        }


        WriteLine(dp.Skip((N + 1) / 2).Sum().ToString("F10"));
    }

}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public void join<T>(IEnumerable<T> values) { WriteLine(string.Join(" ", values)); }
}

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

typedef long long ll;

int main(void){
    int a,b,c,d;scanf("%d %d %d %d",&a,&b,&c,&d);
    printf("%d\n", min(a,b) + min(c,d));
}

Measured memory_bytes: 256
object Main extends App {
  val N = io.StdIn.readLine.toInt

  val xu: Seq[Array[String]] = for (i <- 1 to N) yield io.StdIn.readLine.split(' ')

  val out = xu.map {
    case Array(n,"JPY") => n.toInt
    case Array(n,"BTC") => 380000 * n.toDouble
  }.sum

  println(out)
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double d = 1000 * 1510;
  ll n,m,k;
  double w,b;
  while(cin >> n >> m,n +m){
    vector<ll> x(n+1),y(m+1);
    k = 0;
    rep(i,n){
      cin >> w;
      k += w;
      x[i+1] = k;
    }
    k = 0;
    rep(i,m){
      cin >> w;
      k += w;
      y[i+1] = k;
    }
    map<int,int> ans;
    rep(i,n+1){
      rep(j,m+1){
        ans[int(y[j]-x[i])]++;
      }
    }
    ll cnt = 0;
    for(auto p:ans){
      int o = p.se;
      cnt += o * (o-1)/2;
    }
    cout << cnt << endl;
  }
  return 0;
}

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

#define max(a, b) ((a) < (b) ? (b) : (a))
#define min(a, b) ((a) < (b) ? (a) : (b))

using namespace std;

int main(){
  int N, K;
  scanf("%d %d ", &N, &K);
  int white[2 * K + 1][2 * K + 1];
  int black[2 * K + 1][2 * K + 1];
  for(int x = 0; x <= 2 * K; x++){
    for(int y = 0; y <= 2 * K; y++){
      white[x][y] = 0;
      black[x][y] = 0;
    }
  }
  
  for(int i = 0; i < N; i++){
    int x, y;
    char c;
    scanf("%d %d %c ", &x, &y, &c);
    if(c == 'W') white[x % (2 * K) + 1][y % (2 * K) + 1]++;
    else black[x % (2 * K) + 1][y % (2 * K) + 1]++;
  }
  
  for(int y = 0; y <= 2 * K; y++){
    for(int x = 1; x <= 2 * K; x++){
      white[x][y] += white[x - 1][y];
      black[x][y] += black[x - 1][y];
    }
  }
  
  for(int x = 0; x <= 2 * K; x++){
    for(int y = 1; y <= 2 * K; y++){
      white[x][y] += white[x][y - 1];
      black[x][y] += black[x][y - 1];
    }
  }
  
  int count = 0;
  for(int x = 0; x <= 2 * K; x++){
    for(int y = 0; y <= 2 * K; y++){
      int cnt = 0;
      int w[4][4];
      int b[4][4];
      
      for(int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
          int xi = min(max(x - K + i * K, 0), 2 * K);
          int yj = min(max(y - K + j * K, 0), 2 * K);
          w[i][j] = white[xi][yj];
          b[i][j] = black[xi][yj];
        }
      }
      
      for(int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
          if((i + j) & 1){
            if(i < 3 && j < 3)
              cnt += 2 * w[i][j] - 2 * b[i][j];
            else
              cnt += w[i][j] - b[i][j];
          }else{
            if(i < 3 && j < 3)
              cnt += - 2 * w[i][j] + 2 * b[i][j];
            else if(i == 3 && j == 3)
              cnt += b[i][j];
            else
              cnt += -w[i][j] + b[i][j];
          }
        }
      }
      count = max(cnt, count);
    }
  }
  
  printf("%d\n", count);
  
  return 0;
}

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

struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INf = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define int ll

int findSquare(int n){
    int mux;
    for(int i=0;i*i<=n;i++){
        mux = i;
    }
    return mux*mux;
}

signed main(){
    int n;
    scanf("%lld",&n);
    printf("%lld\n",findSquare(n));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

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

int main()
{
	ll N,K;
	cin >> N >> K;
	ll cnt=0;
	if(K%2!=0){
		for(ll n=1; n<=N; n++){
			if(n*2%K==0) cnt++;
		}
		ll ans=cnt+3*cnt*(cnt-1)+cnt*(cnt-1)*(cnt-2);
		cout << ans << endl;
	}else{
		ll k=K/2;
		ll cnt=N/k;
		ll even=cnt/2;
		ll ans=even+3*even*(even-1)+even*(even-1)*(even-2);
		ll odd=cnt/2+cnt%2;
		cout << ans+odd+3*odd*(odd-1)+odd*(odd-1)*(odd-2) << endl;
	}


	

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  static int count5 = 0;
  static int count7 = 0;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    func(sc.nextInt());
    func(sc.nextInt());
    func(sc.nextInt());
    if (count5 == 2 && count7 == 1) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
    sc.close();
  }
  static void func(int target){
    if (target == 5) {
      count5++;
    } else if (target == 7) {
      count7++;
    }
  }
}

Measured memory_bytes: 23636
from collections import defaultdict
from collections import OrderedDict

N = int(input())

words = dict()
wordsFromValue = defaultdict(list)

for idx in range(N) :
  word = str(input())
  
  if word in words :
    words[word] += 1
  else :
    words[word] = 1
  
for key, value in sorted(words.items()) :
  wordsFromValue[value].append(key)
  

for val in wordsFromValue[max(wordsFromValue)] : 
  print(val)
  

Measured memory_bytes: 45268
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846264338;
const int MOD=1000000007;
vector<int>arr[100001];
vector<int>arr2[100001];
queue<int>que;
int cost;
int arr3[100001];
const int ad='A'-'a';

int main() {
	int n,m;
	cin>>n>>m;
	cost=0;
	for(int i=1;i<=m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		
		arr[a].push_back(b);
		arr[b].push_back(a);
	}

	for(int i=1;i<=n;i++){
		if(!arr3[i]){
			arr3[i]=1;
			cost++;
			//cout<<i<<endl;
		}
		else continue;
		que.push(i);
		while(!que.empty()){
			int cur=que.front();
			que.pop();
			//cout<<cur<<" "<<i<<endl;
			for(auto c:arr[cur]){
				if(arr3[c])continue;
				arr3[c]=1;
				
				que.push(c);
			}
		}
	}
	
	cout<<cost<<endl;
  return 0;
}




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

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            MergeSort(arr, 0, arr.Length);
            Console.WriteLine(string.Join(" ", arr));
            Console.WriteLine(Count);
        }

        private static int Count { set; get; } = 0;

        public static void Merge(int[] array, int left, int mid, int right)
        {
            var nl = mid - left;
            var nr = right - mid;
            var lefts = new int[nl + 1];
            var rights = new int[nr + 1];
            Array.Copy(array, left, lefts, 0, nl);
            Array.Copy(array, mid, rights, 0, nr);
            lefts[nl] = int.MaxValue;
            rights[nr] = int.MaxValue;
            var i = 0; var k = 0; 
            for(var m = left; m < right; ++m)
            {
                Count++;
                if(lefts[i] <= rights[k])
                {
                    array[m] = lefts[i];
                    ++i;
                }
                else
                {
                    array[m] = rights[k];
                    ++k;
                }
            }
        }

        public static void MergeSort(int[] array, int left, int right)
        {
            if (left + 1 < right)
            {
                var mid = (left + right) / 2;
                MergeSort(array, left, mid);
                MergeSort(array, mid, right);
                Merge(array, left, mid, right);
            }
        }
    }
}



Measured memory_bytes: 82740
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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




Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int n=nxt();
    n=n%10;
    if(n==2||n==4||n==5|n==7||n==9){
        printf("hon");
    } else if(n==0||n==1||n==6|n==8){
        printf("pon");
    } else if(n==3){
        printf("bon");
    }
    return 0;
}



Measured memory_bytes: 3820
#include <stdio.h>

int main(void)
{
    char s[9];
    int c = 0, i = 0;
    scanf("%s", s);

    for(; i<3; ++i) {
      if(s[i] == '1') ++c;
    }

    printf("%d\n", c);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
	char s[100001], t[100001];
	scanf("%s", s);
	scanf("%s", t);
	
	int i, n, p[26] = {}, pos[26][100001] = {}, count[26] = {};
	for (n = 0; s[n] != 0; n++) pos[s[n] - 'a'][p[s[n] - 'a']++] = n;
	for (i = 0; t[i] != 0; i++) count[t[i] - 'a']++;
	for (i = 0; i < 26; i++) if (p[i] == 0 && count[i] > 0) break;
	if (i < 26) {
		printf("-1\n");
		fflush(stdout);
		return 0;
	}
	
	int j, k, m, l, u;
	long long ans = 0;
	for (i = 0, j = 0; t[i] != 0; i++) {
		k = t[i] - 'a';
		l = 0;
		u = p[k] - 1;
		if (pos[k][u] < j) {
			ans += n;
			j = 0;
			u = 0;
		}
		while (l < u) {
			if (pos[k][(l+u)/2] < j) l = (l + u) / 2 + 1;
			else u = (l + u) / 2;
		}
		j = pos[k][l] + 1;
	}
	
	printf("%lld\n", ans + j);
	fflush(stdout);
	return 0;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    lli n;
    cin >> n;
    vector<lli> a(n);
    for(auto &i : a) cin >> i;
    unordered_map<lli, lli> m;
    for(auto i : a){
        m[i]++;
    }
    for(auto i : m){
        if(i.second > 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


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

int a, b;
int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
  cin >> a >> b;
  a += b;
  if(a&1) cout << "IMPOSSIBLE\n";
  else cout << a / 2 << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

public class Main {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int w = Integer.parseInt(br.readLine());

		int n = Integer.parseInt(br.readLine());

		int[] ans = new int[w + 1];

		List<points> line = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			String[] s_points = br.readLine().split(",");

			line.add(new points(Integer.parseInt(s_points[0]), Integer.parseInt(s_points[1])));
		}

		Deque<points> d = new ArrayDeque<>();

		for (int i = 1; i <= w; i++) {
			int target = i;
			d.addAll(line);
			while (!(d.isEmpty())) {
				points p = d.poll();

				if (target == p.point_a) {
					target = p.point_b;
				} else if (target == p.point_b) {
					target = p.point_a;
				}
				/* System.out.println(p.point_a+" "+p.point_b); */
			}
			ans[target] = i;
		}
		for (int i = 1; i <= w; i++) {
			System.out.println(ans[i]);
		}
	}

	static class points {
		int point_a;
		int point_b;

		public points(int a, int b) {
			this.point_a = a;
			this.point_b = b;
		}
	}

}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


const int MOD = 1e+9 + 7;

template <typename T>
T pow_mod( T n, T p, T m )
{
    if( p == 0 ) return 1;
    if( p%2 == 1 ) return pow_mod(n, p-1, m) * n % m;
    else{
        T tmp = pow_mod(n, p/2, m) % m;
        return tmp * tmp % m;
    }
}

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

    long long ans = 0;
    vector<long long> num_cases(K+1);
    // gcd が i になるものの個数を求める
    for(int i = K; i >= 1; --i){
        num_cases[i] = pow_mod<long long>(K/i, N, MOD);
        int j = 2;
        while(i*j <= K) num_cases[i] -= num_cases[i*j++];
        ans += (i * num_cases[i]) % MOD;
    }
    cout << ans % MOD << endl;

    return 0;
}

Measured memory_bytes: 3892
using System;

public class Program
{
	public static void Main(string[] args)
	{
		//var ss = new StreamScanner();
		//---------------------------------
		//????????????int, double, string?????????????????£????????????
		while (true)
		{
			string number = Console.ReadLine();
			if (number == "0")
			{
				break;
			}
			char[] charArray = new char[number.Length];

			charArray = number.ToCharArray();
			int sum = 0;
			for (int i = 0; i < number.Length; i++)
			{
				sum+=int.Parse(charArray[i].ToString());
			}
			Console.WriteLine(sum);
			//int x = ss.Next<int>();
			//double d = ss.Next<double>();
			//string s = ss.Next<string>();

			//?????°???????????????????????¨?????????????????????????????????????????????????´???????
			//int[] array = ss.Next<int>(10);
			//---------------------------------
		}
	}
}
public class StreamScanner
{
	private readonly char[] _c = { ' ' };
	private int _index = -1;
	private string[] _input = new string[0];
	private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

	public T Next<T>()
	{
		if (_index == _input.Length - 1)
		{
			_index = -1;
			while (true)
			{
				string rl = _sr.ReadLine();
				if (rl == null)
				{
					if (typeof(T).IsClass) return default(T);
					return (T)typeof(T).GetField("MinValue").GetValue(null);
				}
				if (rl != "")
				{
					_input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
					break;
				}
			}
		}
		return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
	}

	public T[] Next<T>(int x)
	{
		var ret = new T[x];
		for (var i = 0; i < x; ++i) ret[i] = Next<T>();
		return ret;
	}

	public T[][] Next<T>(int x, int y)
	{
		var ret = new T[y][];
		for (var i = 0; i < y; ++i) ret[i] = Next<T>(x);
		return ret;
	}
}

Measured memory_bytes: 9160
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<int,int>mp;
set<int> s;

int main()
{
    fast;
    ll n,m,s=0;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        ll x;
        cin>>x;
        s+=x;
    }
    if(n-s>=0)
        cout<<n-s<<endl;
    else
        cout<<-1<<endl;
}



Measured memory_bytes: 3656
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k == x:
        ans+=1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    int ma = -inf, mi = inf;
    rep(i, N){
        ma = max(ma, A[i]);
        mi = min(mi, A[i]);
    }
    
    if(ma > mi + 1){
        output("No");
    }
    else if(ma > mi){
        int mi_cnt = 0, ma_cnt = 0;
        rep(i, N){
            if(A[i] == mi) mi_cnt++;
            else ma_cnt++;
        }
        if(mi_cnt <= mi && ma_cnt >= (ma - mi_cnt) * 2){
            output("Yes");
        }
        else{
            output("No");
        }
    }
    else{
        if(N == ma + 1 || N >= ma * 2){
            output("Yes");
        }
        else{
            output("No");
        }
    }
    
    return 0;
}

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

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  vec x(n);
  for(ll i=0;i<n;i++)cin >> x[i];
  ll l;
  cin >> l;

  mat dp(n+1,vec(21,0));
  for(ll i=0;i<n;i++){
    dp[i][0]=prev(upper_bound(x.begin(),x.end(),x[i]+l))-x.begin();
  }

  //cout << 5 << endl;

  for(ll i=0;i<20;i++){
    for(ll j=0;j<n;j++){
      dp[j][i+1]=dp[dp[j][i]][i];
    }
  }

  //cout << 5 << endl;

  ll q;
  cin >> q;

  vec ans;

  for(ll i=0;i<q;i++){
    ll a,b,c;
    cin >> a >> b;
    if(b<a)swap(a,b);
    a--;
    b--;

    ll r,l,h;
    r=100000;
    l=0;
    while(abs(r-l)>1){
      h=(r+l)/2;
      c=a;
      for(ll j=20;j>=0;j--){
        if((1<<j)&h){
          c=dp[c][j];
        }
      }
      if(c>=b){
        r=h;
      }
      else{
        l=h;
      }
    }
    ans.push_back(r);
  }

  for(ll i=0;i<q;i++)cout << ans[i] << endl;


}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

vector<lint> a;

lint cost(int i, int k){
    if(k == 0 || k == 4){
        return a[i];
    }else if(k == 1 || k == 3){
        if(a[i] == 0){
            return 2LL;
        }else if(a[i] % 2 == 0){
            return 0LL;
        }else{
            return 1LL;
        }
    }else{
        if(a[i] % 2 == 0){
            return 1LL;
        }else{
            return 0LL;
        }
    }
}

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

    lint l;
    cin >> l;

    a.resize(l);
    rep(i, l){
        cin >> a[i];
    }

    lint dp[200010][5];
    fill(dp[0], dp[l + 1], LLINF);
    dp[0][0] = 0;

    rep(i, l){
        rep(j, 5){
            REP(k, j, 5){
                dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cost(i, k));
            }
        }
    }

    lint ans = LLINF;
    rep(i, 5){
        ans = min(ans, dp[l][i]);
    }

    cout << ans << endl;

    return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

template <typename T>
bool Setmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  in(int, D);
  vector<int> c(26);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  rep(i, D) rep(j, 26) cin >> s[i][j];

  int score = 0;
  vector<int> last(26);
  rep(i, D) {
    int maxi = numeric_limits<int>::min();
    int chosen;
    rep(j, 26) {
      int score_change = s[i][j];
      rep(k, 26) {
        int last_day = k == j ? i + 1 : last[k];
        score_change -= c[k] * (i + 1 - last_day);
      }
      if (Setmax(maxi, score_change)) {
        chosen = j;
      }
    }
    score += maxi;
    dbg(score, maxi, chosen);
    out(chosen + 1);
  }
}


Measured memory_bytes: 3680
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL ec = 0,nxt[4005],to[4005],hed[2005] = {0};
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL n,k;
LL siz[2005],dep[2005],del;
void dfs(LL u,LL f){
	dep[u] = dep[f] + 1;
	if(dep[u] > k) del ++;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL ans = 0x3f3f3f3f3f3f3f3f;
	LL u[2005],v[2005];
	cin >> n >> k;
	for(LL i = 1;i < n;i ++){
		cin >> u[i] >> v[i];
		add_edge(u[i],v[i]);
		add_edge(v[i],u[i]);
	}
	if(k & 1){
		k >>= 1;
		for(LL i = 1;i < n;i ++){
			del = 0;
			dep[v[i]] = -1; dfs(u[i],v[i]);
			dep[u[i]] = -1; dfs(v[i],u[i]);
			ans = min(ans,del);
		}
	}
	else{
		k >>= 1; dep[0] = -1;
		for(LL i = 1;i <= n;i ++){
			del = 0; dfs(i,0);
			ans = min(ans,del);
		}
	}
	cout << ans << endl;
	return 0;
}
//

Measured memory_bytes: 512
#include<iostream>
 
using namespace std;
 
#define INF 1000000000
 
int ll(int a){return (a<0)?-a:a;}
 
int main(){
 
	int n;
	int x[4],y[4]; /*0,1,2,3 -> a,b,c,d*/
	int abcd[4];
	int dis,min=INF;
 
	cin>>n;
	 
	for(int i=0;i<4;i++) cin>>abcd[i];
 
	for(int i=n;i>=1;i--){ /*横max*/
		for(int j=1;j<=n;j++){ /*番目*/
			for(int k=0;k<4;k++){ /*abcd*/
				if(abcd[k]==j){
					x[k]=(j-1)%i;
					y[k]=(j-1)/i;
				}
			}
		}
		dis=ll(x[0]-x[1])+ll(y[0]-y[1])+ll(x[2]-x[3])+ll(y[2]-y[3]);
		/*cout<<i<<","<<dis<<","<<min<<endl;*/
		if(dis<min) min=dis;
	}
 
	cout<<min<<endl;
 
	return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    string S, T;
    std::cin >> S >> T;

    int L = S.size();
    for(int i=0;i<L;++i){
        bool ok = true;
        
        for(int j=0;j<L;++j){
            if(S[j] != T[(i + j) % L]){
                ok = false;
                break;
            }
        }

        if(ok){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }

    std::cout << "No" << std::endl;
}


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

long long calcGcm(long long n1, long long n2) {
  long long a = n1, b = n2;
  if (n1 < n2) {
    long long tmp = n1;
    n1 = n2;
    n2 = tmp;
  }

  long long r = n1 % n2;
  while (r != 0) {
    n1 = n2;
    n2 = r;
    r = n1 % n2;
  }

  long long gcm = a / n2 * b;
  return gcm;
}

int main() {
  int n;
  cin >> n;
  vector<long long> t;
  for (int i=0; i<n; i++) {
    long long tmp;
    cin >> tmp;
    t.push_back(tmp);
  }

  long long gcm = t[0];
  for (int i=1; i<n; i++) {
    gcm = calcGcm(gcm, t[i]);
  }
  cout << gcm << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793


int main(){
  string S, T;
  cin >> S >> T;
  int dp[3010][3010]= {};
  int a = S.size();
  int b = T.size();
  rep(i, a){
    rep(j, b){
      if(S[i]==T[j]) dp[i+1][j+1]=dp[i][j]+1;
      else dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j]);
    }
  }
  string ans = "";
  int i=a, j=b;
  while(i>0&&j>0){
    if(dp[i][j]==dp[i-1][j]) i--;
    else if(dp[i][j]==dp[i][j-1]) j--;
    else {ans+=S[i-1]; i--; j--; }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 35712
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

int main() {
	string s, ss = "";
	string a = "AKIHABARA";
	cin >> s;
	int i, j;
	i = j = 0;
	bool flg = true;
	while(i < s.size() && j < a.size()) {
		if(s[i] == a[j]) {
			i++; j++;
		}
		else if(a[j] == 'A') {
			j++;
		}
		else {
			flg = false;
			break;
		}
	}
	if(i < s.size() || (i == s.size() && j < a.size()-1)) {
		flg = false;
	}
	if(flg) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
N, L = gets.split(' ').map(&:to_i)

apples = (L..(L + N - 1)).to_a

min_abs = apples.map(&:abs).min
min_abs_idx = apples.map(&:abs).index(min_abs)

sum=0
apples.each do |x|
  sum+=x
end
print (sum - apples[min_abs_idx])


Measured memory_bytes: 1788
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void enqueue(P);
P dequeue(void);
int isEmpty(void);
int isFull(void);

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){/*Q[tail]???n?????£??\???tail??????????¢???????*/
  if(isFull() == 0){
    Q[tail] = x;
  }

  if((tail + 1) == LEN){
    tail = 0;
  }

  else{
    tail++;
  }

}

P dequeue(){/*Q[head]??????????????????head??????????¢???????*/
  P x;
  if(isEmpty() == 0){
    x = Q[head];
  }

  if((head + 1) == LEN){
    head = 0;
  }

  else{
    head++;
  }

  return x;

}

int isEmpty(){
  if(head == tail) return 1;
  else return 0;
}

int isFull(){
  if(head == (tail  + 1) % LEN) return 1;
  else return 0;
}

int main(){
  int elaps = 0, c=0;
  int i, q, a, b;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = n + 1;

  while(1){
    if(head == tail) break;

    a = isEmpty();
    b = isFull();
    u = dequeue();

    if(q >= u.t){
      c += u.t;
      printf("%s %d\n", u.name, c);
    }

    else{
      c += q;
      u.t = u.t - q;
      enqueue(u);
    }
  
  }

  return 0;
}

Measured memory_bytes: 10756
def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())
    if V <= W:
        return False
    if abs(B-A)/(V-W) <= T:
        return True
    return False
if main():
    print('YES')
else:
    print('NO')



Measured memory_bytes: 9172
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define ll long long

int main() {

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	// int a,b;
	// cin>>a>>b;

	// cout << a << " " << b << "\n";
	// cout << "Aryan" << "\n";
	// cerr << "Aryan " << a;

	// while(1){
	// 	cout<<"Aryan"<<"\n";
	// }

	ll n;
	cin >> n;

	ll v = n % 10;
	if (v == 2 || v == 4 || v == 5 || v == 7 || v == 9) {
		cout << "hon" << "\n";
	} else if (v == 0 || v == 1 || v == 6 || v == 8) {
		cout << "pon" << "\n";
	} else if (v == 3) {
		cout << "bon" << "\n";
	}


	return 0;
}


Measured memory_bytes: 3652
use std::io;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;

fn main() {

	let mut line = String::new();

	io::stdin().read_line(&mut line).expect("Failed to read line.");
	let mut tmp : Vec<i64> = line.trim().split(" ").map(|val| val.parse().unwrap()).collect();
	let (h, w) = (tmp[0],tmp[1]);


	// 現在行で、ある場所からスタートする時の、前行まででの初期位置？を格納？
	// 不要なスタート地点は都度抜いていくが、
	// 最初は全ての場所(W個)をスタート地点にEntry
	let mut map_start_and_init = BTreeMap::new();
	// let mut set_answers = BTreeSet::new();
	// let mut map_answers = BTreeMap::new();
	let mut answers = BTreeSet::new();	
	for w_ in 0..w {
		map_start_and_init.insert(w_,w_);
		answers.insert((0,w_));	// 欲しいのはfirstだけだが、multiset的な使い方をするために、secondに開始位置格納。。。
	}


	for h_ in 0..h {
		// 行ごとに答えを更新していくスタイル
		line = "".to_string();
		io::stdin().read_line(&mut line).expect("Failed to read line.");
		tmp = line.trim().split(" ").map(|val| val.parse().unwrap()).collect();
		let (wall_left, wall_right_plus_one) = (tmp[0]-1,tmp[1]);
		// 前の行の壁内Entryで一番右まで行ってた位置
		let mut max_init_pos : i64 = -1;
		// println!("{}: {}", wall_left, wall_right_plus_one);

		// 壁startから、壁END[+1]の場所まで更新する
		let mut tmp : Vec<(i64,i64)> = Vec::new();
		for (&start_pos,&init_pos) in map_start_and_init.range(wall_left..wall_right_plus_one+1) {
			tmp.push( (start_pos,init_pos) );
		}
		for &( start_pos, init_pos ) in tmp.iter() {
			// 壁のある地点Entryを全部削除
			// 壁内の答えもセットで削除
			answers.remove( &(start_pos - init_pos, start_pos) );
			map_start_and_init.remove( &start_pos );
			// 前の行までに作った、行の壁内のEntry中で一番右の場所を取得
			max_init_pos = cmp::max( max_init_pos, init_pos );
			// println!("{}行目 {}: {}", h_+1, start_pos, init_pos);
		}

		if max_init_pos != -1 && wall_right_plus_one < w {
			// 壁内のEntryが更新された場合
			// 壁START〜壁END+1までのEntryは全て削除ずみ
			// それを壁END+1スタートのEntry１つにまとめて再登録する
			// (壁が右まで行っちゃってたら再登録しないので壁内のEntryは全消滅)
			// max_init_posには、壁内にあったEntryの中で(前の行で)一番右まで行ってたやつが入っているはず
			// この行では、前の行で、なるべく右まで行っていたものとみなす方が得なので、それを使用。
			answers.insert( (wall_right_plus_one - max_init_pos, wall_right_plus_one ) );//wall_right_plus_one - max_init_pos );
			map_start_and_init.insert(wall_right_plus_one, max_init_pos);
			// println!("wall_right_plus_one={}: max_init_pos={}", wall_right_plus_one, max_init_pos);
		}

		let mut ans = -1;
		if false == answers.is_empty() {
			// 答えは、消えてないEntry内で右移動した量の最小値
			let min_right_move = answers.iter().next().unwrap().0;
			// let first = set_answers.iter().next();
			ans = min_right_move + (h_+1);
		}

		println!("{}", ans);
	}
}

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

using namespace std;
constexpr int NMAX = 1000010;
int vp2(int x) {
	if (x % 2 == 1) return 0;
	else return 1 + vp2(x / 2);
}
int vp2fac[NMAX];
int vp2binom(int n, int r) {
	return vp2fac[n] - vp2fac[r] - vp2fac[n - r];
}
char initRow[NMAX];
int simula[NMAX];
int main() {
	vp2fac[0] = 0;
	for (int i = 1; i < NMAX; ++i) vp2fac[i] = vp2fac[i - 1] + vp2(i);
	int n; scanf("%d", &n);
	scanf("%s", initRow);
	bool hasOne = false; // this refers to the shifted-down version
	for (int i = 0; i < n; ++i) if (initRow[i] == '2') hasOne = true;
	if (!hasOne) for (int i = 0; i < n; ++i) simula[i] = (initRow[i] - '1') / 2;
	else for (int i = 0; i < n; ++i) simula[i] = 1 - abs(initRow[i] - '2');
	int tans = 0;
	for (int i = 0; i < n; ++i) tans = (tans + (vp2binom(n - 1, i) ? 0 : 1) * simula[i]) % 2;
	if (hasOne) printf("%d\n", tans == 0 ? 0 : 1);
	else printf("%d\n", tans == 0 ? 0 : 2);
	return 0;
}


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

int main(void){
long long int n;scanf("%lld",&n);

long long int uresisa=0;

uresisa=uresisa+n/500*1000;
n=n%500;
uresisa=uresisa+n/5*5;
printf("%lld\n",uresisa);

}

Measured memory_bytes: 128
#include<iostream>
using namespace  std;
int main()
{
	int heap[600];
	int h;
	cin >> h;
	for (int i = 0; i < 600; i++)heap[i] = 2000000009;
	for (int i = 1; i <= h; i++)
	{
		cin >> heap[i];
	}

	for (int i = 1; i <= h; i++)
	{
		cout << "node " << i << ": key = " << heap[i] << ", ";
		if (i != 1)
		{
			cout << "parent key = " << heap[i / 2] << ", ";
		}
		if (heap[i * 2] != 2000000009)
		{
			cout << "left key = " << heap[i * 2] << ", ";
		}

		if (heap[i * 2 + 1] != 2000000009)
		{
			cout << "right key = " << heap[i * 2 + 1] << ", ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1160