akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    List<Integer> list = Arrays.asList(A + B, A - B, A * B);
    Collections.sort(list, Collections.reverseOrder());
    System.out.println(list.get(0));
  }
}


Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
	int ans=0,n;
	cin>>n;
	if(n%10==0){
		ans=10;
	}else{
		while(n!=0){
			ans+=n%10;
			n/=10;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;
constexpr int d = 13;

int main() {
  string s;
  cin >> s;
  vector<int> r(d);
  r[0] = 1;
  for (auto e : s) {
    vector<int> t(d);
    for (int j = 0; j < 10; j++) {
      if (e != '?' && e != '0' + j) continue;
      for (int k = 0; k < d; k++) {
        (t[(10 * k + j) % 13] += r[k]) %= mod;
      }
    }
    r = t;
  }
  cout << r[5] << endl;
}


Measured memory_bytes: 512
#include <cstdio>
using namespace std;

int mdb(int a, int b) {
	int c = a ^ b;
	if(c == 0) return 32;
	int ans = 0;
	for(; !(c & 1); ans++) {
		c /= 2;
	}
	return ans;
}

int main() {
	int N;
	scanf("%d%*c", &N);
	for(int i = 0; i < N - 1; i++) {
		for(int j = i + 1; j < N; j++) {
			printf("%d", mdb(i, j) + 1);
			if(j < N - 1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    long x;
    scanf("%ld",&x);
  long long i,j;
    for( i=-120;i<121;i++){
        for( j=-120;j<121;j++){
            if(i*i*i*i*i-j*j*j*j*j==x){
              printf("%lld %lld",i,j);
               return 0;}
        }
    }
   
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;


void solve()
{ 
    int n;
    cin>>n;
    if(n>=400&&n<600)cout<<8<<endl;
        else if(n>=600&&n<800)cout<<7<<endl;
        else if(n>=800&&n<1000)cout<<6<<endl;
        else if(n>=1000&&n<1200)cout<<5<<endl;
        else if(n>=1200&&n<1400)cout<<4<<endl;
        else if(n>=1400&&n<1600)cout<<3<<endl;
        else if(n>=1600&&n<1800)cout<<2<<endl;
        else if(n>=1800&&n<2000)cout<<1<<endl;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 3652
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
k=len(set(A))
if k==1:
  if A[0]==n-1 or 2*A[0]<=n:
    print("Yes")
  else:
    print("No")
elif k>2:
  print("No")
else:
  ma=min(A)
  Ma=max(A)
  if Ma-ma>1:
    print("No")
  else:
    ct=0
    for a in A:
      if a==ma:
        ct+=1
    if ma+1>ct and (ma+1-ct)*2<=n-ct:
      print("Yes")
    else:
      print("No")

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

const int md = 1e9 + 7;
int p[200001];

int pw(int x, int p) {
	if (!p)return 1;
	int t = pw(x, p >> 1);
	t = (ll)t*t%md;
	if (p & 1)t = (ll)t*x%md;
	return t;
}

int ch(int n, int r) { return (ll)p[n] * pw(p[n - r], md - 2) % md*pw(p[r], md - 2) % md; }

int main() {
	p[0] = p[1] = 1;
	f(i, 2, 200001)p[i] = (ll)p[i - 1] * i%md;
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	int an = 0;
	int x = h - a, y = w - b;
	f(i, 0, y) {
		an += (ll)ch(b + i + x - 1, x - 1)*ch(a + y - i - 2, y - i - 1) % md;
		if (an >= md)an -= md;
	}
	printf("%d\n", an);
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int n, k, ans;
int main()
{
    cin >> n >> k;
    ans = k;
    for(int i = 0; i < n-1; i++ ){
//        ans =  (k-1) * ans;
        ans *= k - 1;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
#define pld pair<pll,ll>
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
	return (x>=0 and y>=0 and x<n and y<m);
}
bool isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
	mem(isprime,true);
	for(ll p=2;p*p<=n;p++)
	{
		if(isprime[p]==true)
		{
			for(ll i=p*p;i<=n;i+=p)
				isprime[i]=false;
		}
	}
}
ll cnt(ll a[],ll n)
{
	vector<ll> v;
	rep(i,0,n)
		v.pb(a[i]);
	sort(a,a+n);
	ll cnt2=0,cnt=0;
	do
	{
		cnt2++;
		cnt=0;
		for(ll i=0;i<n;i++)
		{
			if(a[i]==v[i])
				cnt++;
		}
		
		if(cnt==n)
			return cnt2;
	}while(next_permutation(a,a+n));
}
void solve()
{	
	ll n;
	cin>>n;
	ll a[n],b[n];
	rep(i,0,n)
	{
		cin>>a[i];
	}

	rep(i,0,n)
	{
		cin>>b[i];
	}
	ll x=cnt(a,n);
	ll y=cnt(b,n);
	cout<<abs(x-y);
}	
int main()
{
	IOS
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> 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]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    vi v(5);
    for (int i = 0; i < 5; i++) {
        cin >> v[i];
    }
    int k;
    cin >> k;

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            if (i != j) {
                if ( abs(v[i] - v[j]) > k){
                    cout << ":(" << endl;
                    return;
                }
            }
        }
    }

    cout << "Yay!" << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	cin>>n;
	ll a[n];
	rep(i,0,n) cin>>a[i];
	partial_sum(a,a+n,a);
	ans=LLONG_MAX;
	rep(i,0,n){
		ans=min(ans,abs(a[n-1]-a[i]-a[i]));
	}
	ret(ans)
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
l = sorted(list(map(int,input().split())))
d = Counter(l)
ans = 0
for i in range(n-1,-1,-1):
    if d[l[i]] == 0:
        continue
    d[l[i]] -= 1
    x = 2**(l[i].bit_length())
    y = x-l[i]
    if d[y] > 0:
        d[y] -= 1
        ans += 1
            
print(ans)

Measured memory_bytes: 37676
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	int N = in.nextInt();
        	int K = in.nextInt();
        	int[] h = new int[N];
        	for(int i = 0; i < N; i++) {
        		h[i] = in.nextInt();
        	}
        	Arrays.sort(h);
        	int dif = 2000000000;
        	int ans = 2000000000;
        	for(int i = 0; i < N - K + 1; i++) {
        		dif = h[i + K - 1] - h[i]; 
        		ans = Math.min(ans, dif);
        	}
        	out.println(ans);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 36744
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


ll gcd(ll a, ll b) { // a >= b;
	if (b == 0) return a;
	else return gcd(b, a%b);
}

int A[100001];
ll cnt[100001]; // cnt[i] : 1～i番目までの最大公約数
ll cnt2[100001]; // cnt2[i] : i～N番目までの最大公約数

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

	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	cnt[1] = A[1];
	for (int i = 2; i <= N; i++) cnt[i] = gcd(cnt[i - 1], A[i]);
	cnt2[N] = A[N];
	for (int i = N - 1; i >= 1; i--) cnt2[i] = gcd(cnt2[i + 1], A[i]);

	ll ans = 0;
	for (int i = 2; i < N; i++) {
		ans = max(ans, gcd(cnt[i - 1], cnt2[i + 1]));
	}
	ans = max(ans,cnt[N - 1]);
	ans = max(ans, cnt2[2]);


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2176
m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
if d2==1 and m2==m1+1:
    print(1)
    exit()
elif d2==1 and d1==12 and d1==1:
    print(1)
    exit()
else:
    print(0)
    exit()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;cin>>n>>m;
    string s;
    cin>>s;
    vector<int> v;
    set<int> st;
    rep(i,0,n+1){
        if(s[i]=='0')st.insert(i);
    }
    int now=n;
    for(;;){
        int r=now-m;
        auto itr=st.lower_bound(r);
        int ne=*itr;
        if(ne==now){
            cout<<-1<<endl;
            return 0;
        }
        v.push_back(now-ne);
        now=ne;
        if(now==0)break;
    }
    //cout<<v.size()<<endl;
    rrep(i,v.size()-1,0){
        cout<<v[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 5832
a = int(input())
b = int(input())
c = int(input())
x = int(input())

l = []
for i in range(0,a+1):
    for j in range(0,b+1):
        for k in range(0,c+1):
            l.append(500*i + 100*j + 50*k)

print(l.count(x))

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

int main()
{
    int x, y;
    cin >> x >> y;
    rep(i, 0, x+1){
        if(2*i + 4*(x - i) == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>

#define NORTH "North"
#define EAST  "East"
#define WEST  "West"
#define SOUTH "South"
#define RIGHT "Right"
#define LEFT  "Left"
struct DiceState {
  int up;
  int down;
  int north;
  int east;
  int west;
  int south;
  void Reset() {
    up = 1; down = 6; north = 5; east = 3; west = 4; south = 2;
  }
  DiceState() {
    Reset();
  }
};

class Dice {
public:
  Dice();
  ~Dice();
  void Move(int n);
  int GetUpSum() const;
  void ResetState();
private:
  void rotate(int* pa, int* pb, int* pc, int* pd);

  DiceState m_state;
  int m_up_sum;
};

Dice::Dice() : m_up_sum(m_state.up)
{
  ;
}

Dice::~Dice()
{
  ;
}

void Dice::Move(int n)
{
  m_up_sum = m_state.up;

  for (int i = 0; i < n; i++) {
    std::string cmd;
    std::cin >> cmd;
    if (cmd == NORTH) rotate(&m_state.north, &m_state.up, &m_state.south, &m_state.down);
    if (cmd == EAST) rotate(&m_state.east, &m_state.up, &m_state.west, &m_state.down);
    if (cmd == WEST) rotate(&m_state.west, &m_state.up, &m_state.east, &m_state.down);
    if (cmd == SOUTH) rotate(&m_state.south, &m_state.up, &m_state.north, &m_state.down);
    if (cmd == RIGHT) rotate(&m_state.north, &m_state.west, &m_state.south, &m_state.east);
    if (cmd == LEFT) rotate(&m_state.north, &m_state.east, &m_state.south, &m_state.west);

    m_up_sum += m_state.up;
  }
}

int Dice::GetUpSum() const
{
  return m_up_sum;
}

void Dice::ResetState()
{
  m_state.Reset();
}

void Dice::rotate(int* pa, int* pb, int* pc, int* pd)
{
  *pa = *pb;
  *pb = *pc;
  *pc = *pd;
  *pd = 7 - *pb;
}

int main(void)
{
  int n;
  while (true) {
    std::cin >> n;
    if (n == 0) break;
    Dice dc;
    dc.ResetState();
    dc.Move(n);
    std::cout << dc.GetUpSum() << std::endl;
  }

  return 0;
}

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

struct node{
 unsigned int key;
 struct node *next;
 struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
NodePointer i;
 for(i=nil->next; i!=nil ;i=i->next) {
if(i->key == key) return i;
}
return nil;
}

void init(){
 nil = malloc(sizeof(struct node));
 nil->next = nil;
 nil->prev = nil;
}

void printList(){
 NodePointer cur = nil->next;
 int isf = 1;
 while(1){
   if ( cur == nil ) break;
   if ( isf == 0)  printf(" ");
   printf("%d", cur->key);
   cur = cur->next;
   isf = 0;
 }
 printf("\n");
}

void deleteNode(NodePointer t){
t->prev->next=t->next;
t->next->prev=t->prev;
free(t);
}

void deleteFirst(){
 NodePointer t = nil->next;
 if ( t == nil ) return;
 deleteNode(t);
}

void deleteLast(){
NodePointer t=nil->prev;
 if ( t == nil ) return;
 deleteNode(t);
}

void delete(int key){
NodePointer delete;
delete = listSearch(key);
if (delete == nil) return;
deleteNode(delete);
}


void insert(int key){
 NodePointer x;
 x = malloc(sizeof(struct node));
 x->key = key;
x->next=nil->next;
nil->next->prev=x;
nil->next=x;
x->prev=nil;
if(nil->prev==nil) nil->prev=x;
}

int main(){
 int key, n, i;
 int size = 0;
 char com[20];
 int np = 0, nd = 0;
 scanf("%d", &n);
 init();
 for ( i = 0; i < n; i++ ){
   scanf("%s%d", com, &key);
   if ( com[0] == 'i' ) {insert(key); np++; size++;}
   else if ( com[0] == 'd' ) {
     if (strlen(com) > 6){
if ( com[6] == 'F' ) deleteFirst();
else if ( com[6] == 'L' ) deleteLast();
     } else {
delete(key); nd++; 
     }
     size--;
   }
 }

 printList();
 return 0;
}

Measured memory_bytes: 31788
#include <algorithm>
#include <iostream>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

using Int = long long;
using Event = tuple<Int, Int, Int>;

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

    vector<Event> E;
    for (int i = 0; i < N; i++) {
        Int s, t, x;
        cin >> s >> t >> x;

        E.push_back(make_tuple(s - x, -1, x));
        E.push_back(make_tuple(t - x, 0, x));
    }
    for (int i = 0; i < Q; i++) {
        Int d;
        cin >> d;

        E.push_back(make_tuple(d, 1, i));
    }
    sort(E.begin(), E.end());

    vector<Int> res(Q);
    multiset<Int> S;
    for (auto e : E) {
        Int x, t, v;
        tie(x, t, v) = e;

        switch (t) {
        case -1:
            S.insert(v);
            break;
        case 0:
            S.erase(S.lower_bound(v));
            break;
        case 1:
            res[v] = (S.empty() ? -1 : *(S.begin()));
            break;

        default:
            break;
        }
    }

    for (auto r : res) {
        cout << r << '\n';
    }
}


Measured memory_bytes: 27364
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
s = 0
for i in range(n):
    s += b[a[i]-1]
    if i > 0 and a[i] == a[i-1] + 1:
        s += c[a[i-1]-1]
print(s)


Measured memory_bytes: 3064
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll n;
    std::cin >> n;
    map<string,ll> m;
    for (int i = 0; i < n; i++) {
        string s;
        std::cin >> s;
        m[s]++;
    }
    std::cout << "AC x "<<m["AC"] << std::endl;
    std::cout << "WA x "<<m["WA"] << std::endl;
    std::cout << "TLE x "<<m["TLE"] << std::endl;
    std::cout << "RE x "<<m["RE"] << std::endl;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
"""
C - Boxes and Candies
https://atcoder.jp/contests/abc048/tasks/arc064_a

"""
import sys


def solve(N, x, candies):
    i = 1
    ans = 0
    while i < N:
        gap = candies[i - 1] + candies[i] - x
        if gap > 0:
            if gap <= candies[i]:
                candies[i] -= gap
                ans += gap
            else:
                ans += gap
                candies[i] = 0
        i += 1
    return ans


def main(args):
    N, x = map(int, input().split())
    candies = [int(x) for x in input().split()]
    ans = solve(N, x, candies)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 14060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int i=n-1;i>0;i--)
    {
        cout<<arr[i]<<" ";
    }
cout<<arr[0]<<endl;
    return 0;
}



Measured memory_bytes: 3084
n, m = map(int, input().split())
a = [0] * (n + 1)
for _ in range(m):
    a[int(input())] = True
MOD = 10 ** 9 + 7

dp = [0] * (n + 1)
dp[0] = 1
if not a[1]:
    dp[1] = 1

for i in range(2, n + 1):
    if not a[i]:
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[-1])

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

int main() {
  int n;	cin >> n;
  string s;	cin >> s;
  if(s.size()%2!=0){
    cout << "No";
    return 0;
  }
  string t=s.substr(0,n/2);
  if(t==s.substr(n/2,n/2))	cout << "Yes";
  else	cout << "No";
}

Measured memory_bytes: 3620
num = int(input())
time = list(map(int, input().split()))
drink = int(input())
eff = [list(map(int, input().split())) for i in range(drink)]

baseT = sum(time)
for i in range(drink):
    print(baseT - time[eff[i][0]-1] + eff[i][1])

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		StringTokenizer st;
		int n, a, b, suma, sumb;
		n = a = b = suma = sumb = 0;

		while (!(line = br.readLine()).equals("0")) {
			st = new StringTokenizer(line);
			if (st.countTokens() == 1) {
				n = Integer.parseInt(st.nextToken());
				suma = sumb = 0;
			} else {
				a = Integer.parseInt(st.nextToken());
				b = Integer.parseInt(st.nextToken());
				if (a > b) {
					suma += (a + b);
				} else if (a == b) {
					suma += a;
					sumb += b;
				} else {
					sumb += (a + b);
				}
				n--;
				if (n == 0)
					System.out.println(suma + " " + sumb);
			}
		}
	}
}

Measured memory_bytes: 24764
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
 
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main() {
  int N, ga, sa, ba, gb, sb, bb;
  cin >> N;
	cin >> ga >> sa >> ba >> gb >> sb >> bb;
  vector<long long> dp1, dp2;
 
	
	dp1.push_back(0); 
	for(int i=1; i<N+1; i++) {
		long long dg=0, ds=0, db=0;
		if(i>=ga) dg = dp1[i-ga] + gb;
		if(i>=sa) ds = dp1[i-sa] + sb;
		if(i>=ba) db = dp1[i-ba] + bb;
		long long dd = dp1[i-1] + 1;
		dp1.push_back(max(max(dd, dg), max(ds, db)));
	}

	dp2.push_back(0); 
	for(int i=1; i<dp1[N]+1; i++) {
		long long dg=0, ds=0, db=0; 
		if(i>=gb) dg = dp2[i-gb] + ga;
		if(i>=sb) ds = dp2[i-sb] + sa;
		if(i>=bb) db = dp2[i-bb] + ba;
		long long dd = dp2[i-1] + 1;
		dp2.push_back(max(max(dd, dg), max(ds, db)));
	}
 
	cout << dp2[dp1[N]] << endl;
 
  return 0;
}

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

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

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

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

ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

int main() {
    fastio();

    ll a, b;
    cin >> a >> b;
    cout << a * b / gcd(a, b) << endl;

    return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  ll n,m; cin>>n>>m;
  //ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  //cout<<<<endl;
  
  vector<ll> a(n),b(m),c(m);
  map<ll,ll,greater<ll>> p;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<m;i++){
    cin>>b[i]>>c[i];
    if(p.find(c[i])==p.end()){
      p.insert(MP(c[i],b[i]));
    }
    else {
      p[c[i]]+=b[i];
    }  
  }
  sort(ALL(a));
  i=0;
  for(auto itr = p.begin();itr!=p.end()&&judge;itr++){
    for(j=0;j<itr->second;i++,j++){
      if(itr->first<=a[i]||i>=n){
        judge=false;
        break;
      }
      else{
        a[i]=itr->first;
      }
    }
  }

  for(i=0;i<n;i++){
    result+=a[i];
  }
  cout<<result<<endl;



  

  return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

#define PI 3.14159265358979
#define degtorad(a) (a / 180.0 * PI)

int main() {
	long long a, b, h, m;

	std::cin >> a >> b >> h >> m;

	long double rad = PI * 2 * (
		(long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long
			double)m / 60.0);
	
	long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
			b) * cosl(rad);

	printf("%20.20Lf\n", sqrtl(rsq));


	return 0;
}


Measured memory_bytes: 4144
import java.util.*;
class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[] = new int[n];
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int res[] =new int[n];
        Arrays.fill(res,Integer.MAX_VALUE);
        res[0]=0;
        for(int i=1;i<n;i++)
        {
            // int one =Integer.MAX_VALUE;
            // int two =Integer.MAX_VALUE;
            if(i-1>=0)
            {
                res[i] = Math.min(Math.abs(arr[i]-arr[i-1])+res[i-1],res[i]);
            }
            if(i-2>=0)
            {
                res[i] = Math.min(Math.abs(arr[i]-arr[i-2])+res[i-2],res[i]);
            }
        }
        System.out.println(res[n-1]);
    }
}

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

using namespace std;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n;
   cin >> n;
   long long sum = 0LL;
   int tot = 0 , mini = 1e9;
   for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      sum += abs(x);
      tot += (x < 0);
      mini = min(mini , abs(x));
   }
   if (tot % 2 == 0) {
      cout << sum << '\n';
   } else {
      cout << sum - 2 * mini << '\n';
   }
   return 0;
}


Measured memory_bytes: 256
def dp(x, N):
  if x > N:
    return 0
  ans = 1 if len(set(str(x))) > 2 else 0
  for n in (3, 5, 7):
  	ans += dp(x*10+n, N)
  return ans

N = long(raw_input())
print dp(3, N)+dp(5, N)+dp(7, N)



Measured memory_bytes: 2568
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

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


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();



int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c >= 22)cout << "bust";
  else cout << "win";


  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
num = float("inf")
for i in range(0, 2 * 10 ** 5 + 3, 2):
    num = min(num, A * max(0, X - i // 2) + B * max(0, Y - i // 2) + C * i)
print(num)

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

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

    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];

    int q;
    cin >> q;

    int com, b, e;
    for(int i = 0; i < q; i++){
        cin >> com >> b >> e;
        int res;
        if(com == 0){
            res = INT_MAX;
            for(int i = b; i < e; i++)  res = min(res, a[i]);
        }else if(com == 1){
            res = INT_MIN;
            for(int i = b; i < e; i++)  res = max(res, a[i]);
        }
        cout << res << endl;
    }

    return 0;
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int n;

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

map<string, int> mp;

bool in(int x, int y) {
  return 0 <= x && x < n && 0 <= y && y < n;
}

bool isinfe(int x, int y, string s) {
  int cnt = 0;
  rep(i, 8) {
    int nx = x + dx[i], ny = y + dy[i];
    if(!in(nx, ny)) continue;
    if(s[nx+ny*n] == '#') cnt++;
    else if(s[nx+ny*n] == '@') cnt++;
  }
  //cout<<x<<" "<<y<< " "<<cnt<<endl;
  if(s[x+y*n] == '.') return cnt == 3;
  else if(s[x+y*n] == '#') return cnt == 2 || cnt == 3;
  assert(false);
}

string infect(string s) {
  string t = "";
  rep(i, s.size()) {
    if(s[i] == '@') t += '@';
    else if(isinfe(i%n, i/n, s)) t += '#';
    else t += '.';
  }
  return t;
}

bool check(string s) {
  //cout<<s<<endl;
  rep(i, s.size()) if(s[i] == '#') return false;
  return true;
}

int findvehi(string s) {
  rep(i, s.size()) if(s[i] == '@') return i;
  assert(false);
}

int bfs(string s) {
  mp.clear();
  queue<string> que;
  mp[s] = 0;
  que.push(s);
  while(!que.empty()) {
    string t = que.front(); que.pop();
    if(check(t)) return mp[t];
    int idx = findvehi(t);
    int x = idx%n, y = idx/n;
    rep(i, 8) {
      string u = t;
      int nx = x + dx[i], ny = y + dy[i];
      int ni = nx+ny*n;
      if(!in(nx, ny)) continue;
      if(u[ni] != '.') continue;
      u[idx] = '.';
      u[ni] = '@';
      u = infect(u);
      if(mp.count(u)) continue;
      mp[u] = mp[t] + 1;
      que.push(u);
    }
  }
  return -1;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> n, n) {
    string s = "";
    rep(i, n) {
      string t;
      cin >> t;
      s += t;
    }
    cout << bfs(s) << endl;
  }

  return 0;
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N = 1e6 + 69, mod = 1e9 + 7, INF = 1e9;

const ll INFLL = 1e18;

ll n, k, x, m, answer;
ll path[55][65][55];
bool is_edge[55][55];


int main(){

        cin >> n >> k;

        for(int i = 1; i <= n; i++) {
                for(int j = 1 ; j <= n; j++){
                        cin >> is_edge[i][j] ;
                        if(is_edge[i][j]) path[i][0][j] ++;
                }

        }


        for(int i = 1; i <= 62; i++){
                for(int x = 1; x <= n; x++){
                        for(int y = 1; y <= n; y++){
                                for(int z = 1; z <= n; z++){
                                        path[x][i][z] += path[x][i-1][y] * path[y][i-1][z];
                                        path[x][i][z] %= mod;
                                        //if(path[x][i][z])
                                        //cout << x << " " << i << " " << z << " " << path[x][i][z] << endl;
                                }
                        }
                }
        }



        for(int i = 1; i <= n; i++){

                vector< ll > cur(n+1,0);

                cur[i] = 1;

                ll y = k;

                for(ll bit = 62; bit >= 0; bit--){
                        if(k < (1ll << bit)) continue;
                        k -= (1LL << bit);
                        vector< ll > v(n+1,0);
                        for(int x = 1; x <= n; x++){
                                if(!cur[x])continue;
                                for(int y = 1; y <= n; y++){
                                        if(path[x][bit][y]){
                                                v[y] += cur[x] * path[x][bit][y];
                                                v[y] %= mod;
                                        }
                                }
                        }

                        cur = v;
                }
                for(int j = 1; j <= n; j++) answer += cur[j], answer %= mod;
                k = y;
        }

        cout << answer << endl;

}


Measured memory_bytes: 1664
#include <iostream>
 
using namespace std;
 
int main()
{
	int total,books;
	while(true){
		cin>>total;
		if(total==0){
			break;
		}
	for(int i=1;i<=9;i++){
	cin>>books;
	total-=books;
	}
	cout<<total<<"\n";
	}

    return 0;
}

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

using namespace std;

int main() {
    const string error = "UNRESTORABLE";
    string s, t;
    cin >> s >> t;
    if (s.length() < t.length()) {
        cout << error << endl;
        return 0;
    }
    int start_index = -1;
    for (int start = s.length() - t.length() + 1; start >= 0; start--) {
        bool found = true;
        for (int i = 0; i < t.length(); i++) {
            if (s[i + start] != '?' && s[i + start] != t[i]) {
                found = false;
                break;
            }
        }
        if (found) {
            start_index = start;
            break;
        }
    }
    if (start_index == -1) {
        cout << error << endl;
        return 0;
    }
    string true_s(s);
    int i = 0;
    while(i < start_index) {
        if (true_s[i] == '?') true_s[i] = 'a';
        i++;
    }
    while(i < start_index + t.length()) {
        true_s[i] = t[i - start_index];
        i++;
    }
    while(i < s.length()) {
        if (true_s[i] == '?') true_s[i] = 'a';
        i++;
    }
    cout << true_s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <random>
using namespace std;

int main()
{
	int n, x, t;
	cin >> n >> x >> t;
	int ret = 0, now = 0;
	while (now < n)
	{
		now += x;
		ret += t;
	}
	cout << ret;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <cstdio>

#define LL long long
#define Maxn 200010
#define Maxk 8010

using namespace std;

const LL INF = 1e9, D = 2001, MOD = 1e9 + 7;

inline int read() {
	int x = 0, f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while('0' <= c && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}

int n, a[Maxn], b[Maxn];
LL f[Maxk][Maxk], fac[Maxk], facinv[Maxk], ans;

LL Pow(LL a, LL b) {
	LL ans = 1, base = a;
	while(b) {
		if(b & 1) ans = ans * base % MOD;
		base = base * base % MOD;
		b >>= 1;
	}
	return ans;
}

void pre() {
	fac[0] = facinv[0] = 1;
	for(int i = 1; i < Maxk; ++i) fac[i] = fac[i - 1] * i % MOD;
	facinv[Maxk - 1] = Pow(fac[Maxk - 1], MOD - 2);
	for(int i = Maxk - 2; i; --i) facinv[i] = facinv[i + 1] * (i + 1) % MOD;
}

LL C(LL a, LL b) {
	return fac[a] * facinv[b] % MOD * facinv[a - b] % MOD;
}

int main() {
	n = read();
	pre(); 
	for(int i = 1; i <= n; ++i) {
		a[i] = read(); b[i] = read();
		++f[D - a[i]][D - b[i]];
	}
	for(int i = 1; i <= 4003; ++i)
		for(int j = 1; j <= 4003; ++j)
			f[i][j] += f[i - 1][j] + f[i][j - 1], f[i][j] %= MOD;
	for(int i = 1; i <= n; ++i) ans = (ans + f[a[i] + D][b[i] + D]) % MOD;
	for(int i = 1; i <= n; ++i) ans -= C(a[i] * 2 + b[i] * 2, a[i] * 2), ans %= MOD;
	ans *= Pow(2, MOD - 2);
	cout << (ans % MOD + MOD) % MOD << endl;
	return 0;
}

Measured memory_bytes: 146456
import heapq
class Dijkstra:
    INF = 10**18
    threshold = 10**9

    def __init__(self, N):
        self.MAX_V = N + 1
        self.dist = [self.INF] * self.MAX_V
        self.G = [[] for _ in range(self.MAX_V)]

    def insert(self, X, Y, cost): self.G[X].append(cost * self.threshold + Y)

    def dijkstra(self, st):
        q = []
        heapq.heappush(q, st)
        self.dist[st] = 0

        while len(q):
            p = heapq.heappop(q)
            cost = p // self.threshold
            node = p - cost * self.threshold
            if cost > self.dist[node]: continue
            for to in self.G[node]:
                to_cost = to // self.threshold
                to_node = to - to_cost * self.threshold
                to_cost += self.dist[node]
                if self.dist[to_node] > to_cost:
                    self.dist[to_node] = to_cost
                    heapq.heappush(q, to_cost * self.threshold + to_node)

def main():
    h, w = map(int, input().split())
    sh, sw = map(int, input().split())
    eh, ew = map(int, input().split())

    sh -= 1
    sw -= 1
    eh -= 1
    ew -= 1

    S = [input() for _ in range(h)]

    di = Dijkstra(h*w)
    for x in range(h):
        for y in range(w):
            if S[x][y] == '#': continue
            for i in range(-2, 3):
                for j in range(-2, 3):
                    X = x + i
                    Y = y + j
                    if X < 0 or Y < 0 or X >= h or Y >= w or S[X][Y] == '#': continue
                    D = abs(i) + abs(j)

                    if D == 1: di.insert(x * w + y, X * w + Y, 0)
                    if D >= 2: di.insert(x * w + y, X * w + Y, 1)

    di.dijkstra(sh * w + sw)
    ans = di.dist[eh * w + ew]
    if ans == 10**18: print(-1)
    else: print(ans)

main()

Measured memory_bytes: 207516
C = []
for i in range(3):
	C.append(list(map(int, input().split())))

c1 = C[0][0] + C[1][1] + C[2][2]
c2 = C[0][1] + C[1][2] + C[2][0]
c3 = C[0][2] + C[1][0] + C[2][1]
if c1 == c2 and c2 == c3:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

import heapq
N,M = map(int,input().split())
LRC = [tuple(map(int,input().split())) for i in range(M)]

es = [[] for i in range(N)]
for l,r,c in LRC:
    l,r = l-1,r-1
    es[l].append((r,c))
for i in range(N-1):
    es[i+1].append((i,0))

INF = float("inf")
dist = [INF]*N
dist[0] = 0
hq = [(0,0)]
heapq.heapify(hq)

while(hq):
    d,v = heapq.heappop(hq)
    if v==N-1:
        print(d)
        exit()
    for to,c in es[v]:
        if d+c >= dist[to]: continue
        dist[to] = d+c
        heapq.heappush(hq, (d+c, to))
print(-1)

Measured memory_bytes: 57476
#include <bits/stdc++.h>
using namespace std;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
typedef long long ll;
 
void solve(long long L)
{
    double len = L / 3.0;
    printf("%8.12lf\n", len * len * len);
}
 
int main()
{
    long long L;
    scanf("%lld", &L);
    solve(L);
    return 0;
}

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

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    map<ll, ll> start;
    rep(i, n){
        if(i - a[i] >= 0) ++start[i - a[i] + 1];
    }
    // rep(i, n) cout << start[i] << " ";
    // cout << endl;

    vector<ll> dp(n);
    for(ll i = 0; i < n; ++i){
        dp[i] = i + a[i] + 1;
    }

    // rep(i, n) cout << dp[i] << " ";
    // cout << endl;

    ll res = 0;
    rep(i, n){
        res += start[dp[i]];
    }

    cout << res << endl;

    return 0;
}

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

using namespace std;

const short Nmax = 1005;

char a[Nmax][Nmax];


int n , m , dist[Nmax][Nmax];

queue < pair < int , int > > Q;

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

int main()
{
    int mx = 0;
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)
        cin >> (a[i] + 1);
    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= m ; j++)
            dist[i][j] = 1e9;
    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= m ; j++)
            if(a[i][j] == '#')
                    dist[i][j] = 0 , Q.push({i , j});

    while(!Q.empty())
    {
        int x = Q.front().first;
        int y = Q.front().second;
        Q.pop();
        for(int k = 0 ; k < 4 ; k++)
        {
            int xx = x + dx[k];
            int yy = y + dy[k];
            if(!(1 <= xx && xx <= n && 1 <= yy && yy <= m))
                    continue;
            if(dist[xx][yy] > dist[x][y] + 1)
            {
                dist[xx][yy] = dist[x][y] + 1;
                Q.push({xx , yy});
            }
        }
    }
    for(int i = 1; i <= n ; i++)
        for(int j = 1 ; j <= m ; j++)
            mx = max(mx , dist[i][j]);
    cout << mx << "\n";
}


Measured memory_bytes: 13328
N, M = map(int,input().split())
results = [0 for _ in range(N+1)]
wa_list = [0 for __ in range(N+1)]
ac_cnt = 0
wa_cnt = 0
for _ in range(M):
  problem, result = input().split()
  if results[int(problem)] == 0 and result == 'AC':
    ac_cnt += 1
    results[int(problem)] = 1
  elif results[int(problem)] == 0 and result == 'WA':
    wa_list[int(problem)] += 1
for i in range(1, N+1):
  if results[i] == 1:
    wa_cnt += wa_list[i]
print(ac_cnt, wa_cnt)


Measured memory_bytes: 85656
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>

#define INF 1001

using namespace std;

struct point{
	int x,y,z;
	point():x(0),y(0),z(0){}
	bool operator <(const point &t)const{
		if( x < t.x ){
			return true;
		}else if( x == t.x ){
			if( y < t.y ){
				return true;
			}else if( y == t.y ){
				if( z < t.z ){
					return true;
				}
			}
		}
		return false;
	}
	void rot90arndX(){ int tz = z; z = -y; y = tz; }
	void rot90arndY(){ int tz = z; z = x; x = -tz; }
	void rot90arndZ(){ int tx = x; x = y; y = -tx; }
};

struct strange_key{
	vector<point> vp;

	void rot90arndX(){
		for(unsigned int i = 0; i < vp.size(); ++i){
			vp[i].rot90arndX();
		}
	}
	void rot90arndY(){
		for(unsigned int i = 0; i < vp.size(); ++i){
			vp[i].rot90arndY();
		}
	}
	void rot90arndZ(){
		for(unsigned int i = 0; i < vp.size(); ++i){
			vp[i].rot90arndZ();
		}
	}

	bool Same(strange_key &t){
		if( vp.size() != t.vp.size() )
			return false;

		for(int a = 0; a < 4; ++a){
			for(int b = 0; b < 4; ++b){
				for(int c = 0; c < 4; ++c){
					bool bSame = true;
					sort( vp.begin(), vp.end() );
					sort( t.vp.begin(), t.vp.end() );
					
					int dx = vp[0].x - t.vp[0].x;
					int dy = vp[0].y - t.vp[0].y;
					int dz = vp[0].z - t.vp[0].z;
					
					for(unsigned int l = 1; l < vp.size() && bSame; ++l){
						if( dx != vp[l].x - t.vp[l].x )
							bSame = false;
						if( dy != vp[l].y - t.vp[l].y )
							bSame = false;
						if( dz != vp[l].z - t.vp[l].z )
							bSame = false;
					}
					if( bSame )
						return true;

					rot90arndX();
				}
				rot90arndY();
			}
			rot90arndZ();
		}
		return false;
	}
};

void input_strange_key( istream &is, int n, strange_key &in ){
	if( is ){
		point now;
		bool val[51]={false,};
		vector<point> pos_mem(51);
		
		val[0]=true;
		for(int i = 0; i < n; ++i){
			string s;
			
			cin >> s;
			if( s[0] != '+' && s[0] != '-' ){
				int mem = atoi( s.c_str() );
				if( val[ mem ] ){
					now = pos_mem[ mem ];
				}else{
					pos_mem[ mem ] = now;
					val[ mem ] = true;
				}
			}else{
				int progress = ( s[0] == '+' ? 2 : -2 );
				point next = now;
				switch( s[1] ){
					case 'x':
						now.x += progress / 2;
						in.vp.push_back( now );
						now.x += progress / 2;
						break;
					case 'y':
						now.y += progress / 2;
						in.vp.push_back( now );
						now.y += progress / 2;
						break;
					case 'z':
						now.z += progress / 2;
						in.vp.push_back( now );
						now.z += progress / 2;
						break;
				}
			}
		}
	}
}

int main(){
	while( true ){
		int n1,n2;
		strange_key a, b;

		cin>>n1;
		if( n1 == 0 )
			break;
		input_strange_key( cin, n1, a );
		cin>>n2;
		input_strange_key( cin, n2, b );

		if( a.Same( b ) )
			cout << "SAME\n";
		else
			cout << "DIFFERENT\n";

	}
	return 0;
}

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

int main() {
  int city_num, road_num;
  cin >> city_num >> road_num;
  vector<int> cnt(city_num);

  for(int i=0; i < road_num; i ++) {
    int a, b;
    cin >> a >> b;
    cnt.push_back(a);
    cnt.push_back(b);
  }

  for(int i=1; i <= city_num; i++) {
    cout << count(cnt.begin(),cnt.end(), i) << endl;
  }
}

Measured memory_bytes: 3628
program bm
    implicit none
    integer::N,M
    integer,allocatable,dimension(:)::A
    integer::SUMA,CNT=0
    integer::i
    read*,N,M
    allocate(A(N))
    read*,A
    SUMA=sum(A)
    do i=1,N
        if(A(I)*4*M>=SUMA)cnt=cnt+1
    end do
    print"(A)",trim(merge("Yes","No ",CNT>=M))
end program bm

Measured memory_bytes: 768