akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<Int, Int>;
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Sun Dec  1 21:00:11 JST 2019
 **/

signed main() {
    Int n = in();
    REPI (x, 1, n + 1) {
        if ((x * 108) / 100 == n) {
            cout << x << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}


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

int main(){
    string s;
    int n,flag=0;
    cin>>n>>s;
    
    if(n%2==1){
        flag=1;
    }
    else{
        for(int i=0;i<n/2;i++){
            if(s[i]!=s[i+n/2]){
                flag=1;
            }
        }
    }
    if(flag!=1){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
   return 0;
}

Measured memory_bytes: 256
import sys
#for line in sys.stdin:
def cross(ax,ay,bx,by):
	return ax*by-ay*bx

def check(ax,ay,bx,by,cx,cy,dx,dy):
	a=cross(dx-ax,dy-ay,bx-ax,by-ay)
	b=cross(ax-bx,ay-by,cx-bx,cy-by)
	c=cross(bx-cx,by-cy,dx-cx,dy-cy)
	d=cross(cx-dx,cy-dy,ax-dx,ay-dy)
	if a*b<0 or a*c<0 or a*d<0:
		return False
	else:
		return True

if __name__=="__main__":
	"""while True:
		line=raw_input()
	"""
	for line in sys.stdin:
		a=map(float,line.split(","))
		if check(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]):
			print "YES"
		else:
			print "NO"

Measured memory_bytes: 6320
#include<stdio.h>

int main(void) {
    
    int n;
    int a[10000] = {};
    int i;
    int max, min;
    long long int sum;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    
    max = a[0];
    for(i = 1; i < n; i++) {
        if(max < a[i]) {
            max = a[i];
        }
    }
    
    min = a[0];
    for(i = 1; i < n; i++) {
        if(min > a[i]) {
            min = a[i];
        }
    }
    
    sum = a[0];
    for(i = 1; i < n; i++) {
        sum += a[i];
    }
    
    printf("%d %d %lld\n",min, max, sum);
    
    return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>
int main(){

  int x,y,r,temp;

  scanf("%d%d",&x, &y);
  
  if(x<y){
    temp=x;
    x=y;
    y=temp;
  }
  
  while (y>0){
    r = x % y;
    x = y;
    y = r;
	  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<queue>
#include<set>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

class state{
public:
  int now,n,cnt;
  vector<int> data;
  bool operator<(const state & a)const{
    rep(i,n)if ( data[i] !=a.data[i])return data[i] < a.data[i];
    return false;
  }

  void test_print(){
    cout <<"DEBUG START"<<endl;
    cout <<"count "  <<  cnt << endl;
    cout << "state " ;
    rep(i,n){
      cout << data[i];
    }
    cout <<endl<< "DEBUG END" << endl;
  }
  bool solved(vector<int> &tar){
    rep(i,tar.size()){
      if ( data[i] != tar[i])return false;
    }

    return true;
  }
  
  bool move(set<state>&S,queue<state> &Q,vector<int> &tar){
    while(now < n && data[now] == tar[now])now++;
    if ( now == n){
      if(  solved(tar))return true;
      else return false;
    }
    int move=tar[now]-data[now];
    data[now]=(10+data[now]+move)%10;
    cnt++;
    if ( S.find(*this)== S.end())S.insert(*this),Q.push(*this);
    for(int i=now+1;i<n;i++){
      data[i]=(10+data[i]+move)%10;
      if ( S.find(*this)==S.end())S.insert(*this),Q.push(*this);
    }

    return false;
  }

};

int solve(state & ini,vector<int> tar){
  set<state> S;
  queue<state> Q;
  Q.push(ini);
  S.insert(ini);
  while(!Q.empty()){
    state now = Q.front();
    
    Q.pop();
    if ( now.solved(tar) )return now.cnt;
    //  cout << "now " <<now.now <<  endl;
    //now.test_print();
    if ( now.move(S,Q,tar))return now.cnt;
  }
  return -1;
}

main(){
  int n;
  string a;
  while(cin>>n && n){
    state ini;
    ini.cnt=0;ini.n=n;ini.now=0;
    vector<int> tar;
    cin>>a;
    rep(i,n)ini.data.push_back(a[i]-'0');
    cin>>a;
    rep(i,n)tar.push_back(a[i]-'0');

    while(ini.now < ini.n && ini.data[ini.now]==tar[ini.now])ini.now++;

    cout << solve(ini,tar)<<endl;
  }
}

Measured memory_bytes: 2260
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define tp(A, B, C) tuple<A, B, C>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define si set<int>
#define msi map<string, int>
#define rsz(a) resize(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b){return a.se < b.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define pt(a, b, c) emplace_back(make_tuple(a, b, c))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; ++i)
#define foris(i, a, b) for(ll i = a; i < b; ++i)
#define forise(i, a, b) for(ll i = a; i <= b; ++i)
#define ford(i, n) for(ll i = n; i >= 0; --i)
#define fords(i, a, b) for(ll i = a; i >= b; --i)
#define fordse(i, a, b) for(ll i = a; i > b; --i)
#define fora(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define umap unordered_map
#define uset unordered_set
#define pq(T) priority_queue<T>
#define rpq(T) priority_queue<T, vector<T>, greater<T> >
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;
int digits(int n) {
  n = abs(n);
  if(n < 10) return 1;
  elif(n < 100) return 2;
  elif(n < 1000) return 3;
  elif(n < 10000) return 4;
  elif(n < 100000) return 5;
  elif(n < 1000000) return 6;
  elif(n < 10000000) return 7;
  elif(n < 100000000) return 8;
  elif(n < 1000000000) return 9;
  else return 10;
}


int main() {
  io();
  
  ull n;
  cin >> n;
  ull total = 0;
  foris(i, 1, n) {
    total += i;
  }
  cout << total;
  
  return 0;
}

Measured memory_bytes: 256
use std::io;
fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> u32 {
    return s.trim().parse()
        .expect("Please type a number!");
}
fn main() {

    let line = read_line();
    let ab: Vec<&str> = line.split(' ').collect();

    let a: u32 = to_i(ab[0]);
    let b: u32 = to_i(ab[1]);
    let mut s = "Yes";
    if a %2 ==0 || b%2==0{
        s = "No";
    } 
    print!("{}", s);
}   

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String res = "";
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'B') {
                if (res.equals("")) {
                    continue;
                }
                res = res.substring(0, res.length() - 1);
            } else {
                res += String.valueOf(s.charAt(i));
            }
        }
        System.out.println(res);
        sc.close();
    }
}

Measured memory_bytes: 39468
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF=2e18;
ll n;
ll k[101];
string s;

int main(){
    while(cin>>n,n!=0){
        for(int i=0;i<n;i++){
            cin>>k[i];
        }
        cin>>s;
        string ans="";
        for(int i=0;i<s.length();i++){
            ans+=s[i];
            int K=k[i%n];
            if(K==52){
                K=0;
            }
            if(K>=26){
                K-=26;
                if(islower(ans[i]))ans[i]=toupper(ans[i]);
                else if(isupper(ans[i]))ans[i]=tolower(ans[i]);
            }
            if(islower(ans[i])){
                if(ans[i]-'a'<K){
                    ans[i]='Z'+1-(K-(ans[i]-'a'));
                }else{
                    ans[i]=ans[i]-K;
                }
            }
            else if(isupper(ans[i])){
                if(ans[i]-'A'<K){
                    ans[i]='z'+1-(K-(ans[i]-'A'));
                }else{
                    ans[i]=ans[i]-K;
                }
            }
        }
        cout<<ans<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

string replace(string s,char table[])
{
	rep(i,s.size())
		if(islower(s[i]))
			s[i]=table[s[i]-'a'];
	return s;
}

int main()
{
	for(string s;getline(cin,s);){
		char table[]="abcdefghijklmnopqrstuvwxyz";
		rep(i,26){
			string s2=" "+s+" ";
			rep(i,s2.size())
				if(s2[i]=='.' || s2[i]=='\n')
					s2[i]=' ';
			s2=replace(s2,table);
			if(s2.find(" the ")!=string::npos || s2.find(" this ")!=string::npos ||s2.find(" that ")!=string::npos){
				cout<<replace(s,table)<<endl;
				break;
			}
			rotate(table,table+1,table+26);
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;
	private int n;

	private void mainrun() {
		scan = new Scanner(System.in);

		for(;;) {
			n = scan.nextInt();

			if(n == 0) {
				break;
			}

			looprun();
		}

		scan.close();
	}

	private Integer[][] Matrix;
	private Integer[] sumr;

	private void looprun() {
		Matrix = new Integer[n + 1][n + 1];
		sumr = new Integer[n];

		Arrays.fill(sumr,0);

		for(int i = 0;i < n;i++) {
			int sumc = 0;
			Arrays.fill(Matrix[i], 0);

			for(int j = 0;j < n;j++) {
				Matrix[i][j] = scan.nextInt();

				sumc += Matrix[i][j];
				sumr[j] += Matrix[i][j];

				if(j == n-1) {
					Matrix[i][n] = sumc;
				}
			}
		}

		int sum = 0;

		for(int i = 0;i < n;i++) {
			Matrix[n][i] = sumr[i];
			sum += sumr[i];
		}

		Matrix[n][n] = sum;
		Arrays.asList(Matrix).forEach(e -> {
			Arrays.asList(e).forEach(f -> System.out.printf("%5d",f));
			System.out.println();
		});
	}
}


Measured memory_bytes: 35076
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

int main(void){
    string S,T;
    cin >> S >> T;
    int N=S.length(),M=T.length();
    vector<string> ans;
    for(int i=0;i<N-M+1;i++){
        string s=S;
        bool chk=true;
        for(int j=i;j<i+M;j++){
            if(s[j]!='?' && s[j]!=T[j-i]) chk=false;
            if(s[j]=='?') s[j]=T[j-i];
        }
        rep(j,N) if(s[j]=='?') s[j]='a';
        if(chk) ans.push_back(s);
    }
    sort(ans.begin(),ans.end());
    if(ans.empty()) cout << "UNRESTORABLE"  << endl;
    else cout << ans[0] << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=10000+10;
int main()
{
    int a,b;
    while(~scanf("%d%d",&a,&b)){
        string str;
        cin>>str;
        if(a+b+1!=str.size()){
            printf("No\n");
        }
        else {
            bool flag=1;
            for(int i=0;i<a;i++){
                if(!isdigit(str[i])) {flag=0;goto end;}
            }
            if(str[a]!='-') {flag=0;goto end;}
            for(int i=a+1;i<str.size();i++){
                if(!isdigit(str[i])) {flag=0;goto end;}
            }
            end : {
                if(flag) printf("Yes\n");
                else printf("No\n");
            }
        }

    }


    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

from sys import stdin, stdout
 
def input():
    return stdin.readline().strip()
    
input()
A = input().split(' ')
A = list(map(int, A))
Q = int(input())

curr_sum = sum(A)
curr_freqs = dict()

for a in A:
    if a not in curr_freqs: curr_freqs[a] = 0
    curr_freqs[a] += 1

for _ in range(Q):
    B, C = input().split(' ')
    B = int(B)
    C = int(C)

    if B not in curr_freqs:
        print(curr_sum)
        continue

    if C not in curr_freqs: curr_freqs[C] = 0

    curr_sum += (C - B)*curr_freqs[B]

    curr_freqs[C] += curr_freqs[B]
    curr_freqs[B] = 0


    print(curr_sum)


Measured memory_bytes: 85204
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = I()
s = input()
c = Counter(s)
ans = 0
for i in range(n):
    for k in range(i+1,n):
        if (i+k)%2 == 0:
            j = (i+k)//2
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans+=1
ans_2 = c["R"]*c["G"]*c["B"]
print(ans_2-ans)

Measured memory_bytes: 9972
#include <iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  a = a+b;
  c = c+d;
  if(a>c){
    cout<<"Left"<<endl;
    return 0;
  }else if(a<c){
    cout<<"Right"<<endl;
    return 0;
  }else{
    cout<<"Balanced"<<endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int ans = 1e9;
	for (int k = -100; k <= 100; k++){
		int cost = 0;
		for (int j = 0; j < n; j++){
			cost += (a[j]-k)*(a[j]-k);
		}
		ans = min(ans, cost);
	}
	cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

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

    vector<int> dp(n + 1, 1000000000);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j *= 6) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
        for (int j = 1; j <= i; j *= 9) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 640
def sosu(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

n = int(input())
prime = [int(input()) for i in range(n)]
cnt = 0
for i in prime:
    if sosu(i):
        cnt += 1
print(cnt)



Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
int h, w;
int n;
int dp[maxn][5];
int sx, sy;
string s1, s2;
char p[] = "LUDR";
int main() {
    cin >> h >> w >> n;
    cin >> sx>>sy;
    cin >> s1>>s2;
    dp[0][0] = dp[0][3] = sy;
    dp[0][1] = dp[0][2] = sx;
    int flag = 1;
    for (int i = 0; i<n; ++i) {
        if (i)
        for (int j = 0; j <4;++j) dp[i][j] = dp[i - 1][j];
        for (int j = 0;  j <4;++j) {
            if (s1[i] == p[j]) {
                /*if (j == 0 || j == 1) dp[i][j] = max(dp[i][j] - 1, 1);
                else dp[i][j] = min(dp[i][j] + 1, j == 0 ? w :h);*/
                if (j == 0 || j == 1) dp[i][j] --;
                else dp[i][j] ++;
                if (dp[i][j] <= 0 || ((j == 0 || j == 3) ? dp[i][j] > w : dp[i][j] > h)) {
                    flag = 0;
                    break;
                }
            }
        }
        for (int j = 0; j < 4; ++j) {
            if (s2[i]==p[3-j]) {
                if (j == 3 || j == 2) dp[i][j] = max(dp[i][j] - 1, 1);
                else dp[i][j] = min(dp[i][j] + 1, j == 0 ? w :h);
            }
        }
        //for (int j = 0; j < 4; ++j)
        //cerr << dp[i][j] << ",";
        //cerr <<endl;
    }
    /*
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            cerr << c[i][j] << ",";
        }
        cerr << endl;
        for (int j = 0; j < 4; ++j) {
            cerr << c2[i][j] << ",";
        }
        cerr << endl;
        if ( - c[i][0] + c2[i][0] + sy <= 0) flag = 0;
        if ( - c[i][1] + c2[i][1] + sx <= 0) flag = 0;
        if ( c[i][2] - c2[i][2] + sx > h) flag = 0;
        if (c[i][3] - c2[i][3] + sy > w) flag = 0;
        if (flag == 0) break;
    }*/
    cout << (flag ? "YES" :"NO") << endl;
    return 0;
}


Measured memory_bytes: 4616
#include<stdio.h>
#include<map> 
using namespace std;
map<int,int> times;


int main(){
	int N;
	scanf("%d",&N);
	long long ans=0;
	int temp=0;
	for(int i=1;i<=N;++i){
		scanf("%d",&temp);
		ans+=times[i-temp];
		times[i+temp]++;
	}
	printf("%lld ",ans);
}

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

#define  SZ(items) (int)items.size()
template <class T> inline T gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }

int ar[50];

int main()
{
	//ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); cout.tie(nullptr); cin.tie(nullptr);
	ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr);

	
	long long N;
	cin >> N;

	long long last;
	cin >> last;

	long long res = 0;

	for (int i = 2; i <= N; i++)
	{
		long long it;
		cin >> it;

		if (i == 2)
		{
			res = gcd(it, last);
		}
		else
		{
			res = gcd(res, it);
		}
	}

	cout << res << endl;



	return 0;
}

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

int main()
{
  int m, n;
  int num, ans = 0;;
  bool f = true;
  cin >> n >> m;
  num = ans = m;
  for(int i = 0; i < n; i++)
  {
    int a, b;
    cin >> a >> b;
    num += a - b;
    ans = max(ans, num);
    f &= num >= 0;
  }
  if(!f)
    ans = 0;
  cout << ans << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define int long long
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

const double pi=acos(-1);

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

    double a,b,x; cin>>a>>b>>x;
    double ans;
    if(x>=a*a*b/2){
        ans=2*(a*a*b-x)/(a*a*a);
        ans=atan(ans)*180/pi;
    }else{
        ans=a*b*b/(2*x);
        ans=atan(ans)*180/pi;
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    for ai in a:
        while True:
            if ai % 2 == 0:
                ai = ai / 2
                count += 1
            else:
                break

    print(count)

Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(),(x).end()
#define lowbit(x) x&-x
#define pb push_back
#define ls (id<<1)
#define rs (id<<1|1)
#define Rint register int
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(ull &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MAXN=2e6+10,MAXM=4e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int MOD=1e9+7,mod=998244353;
const int inv2=5e8+4;
const int Lim=1<<20;

int z[15];
ll cnt=0;
int n,m,q,ans;
int a[MAXN],b[MAXN],c[MAXN],d[MAXN];

void dfs(int u)
{
    if(u==n+1)
    {
        int res=0;
        for(int i=1;i<=q;i++)
        {
            if(z[a[i]]+c[i]==z[b[i]])res+=d[i];
        }
        ans=max(ans,res);
        return;
    }
    for(int i=z[u-1];i<=m;i++)
    {
        z[u]=i;
        dfs(u+1);
    }
}

void solve()
{
    z[0]=1;
    R(n,m,q);
    for(int i=1;i<=q;i++)R(a[i],b[i],c[i],d[i]);
    dfs(1);
    W(ans);
}

int main()
{
    //freopen("in.txt","r",stdin);
    int t=1;
    //R(t);
    while(t--)solve();
    return 0;
}


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

int main() {
    int n,k,count=0;

    cin >> n >> k;

    while (n > 0) {
        n /= k;
        count++;
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j;
    cin>>n;
    vector<pair<string,int>>v;
    string s,s1;
    int x;
    while(n-->0)
    {
      cin>>s1>>x;
      v.push_back({s1,x});
    }
    cin>>s;
    int c=0,sum=0;
    for(auto &it : v)
    {
        //cout<<it.first<<" "<<it.second<<"\n";
       
        if(c==1)
        sum+=it.second;
        
        if(it.first==s)
        c=1;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 8

int a[N][N];

void output(int row[]){
  int i, j;
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(a[i][j] == 1){
	if(row[i] != j) return;
      }
    }
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(row[i] != j){
	printf(".");
      }else{
	printf("Q");
      }
    }
    printf("\n");
  }
}

void putQueen(int i, int row[], int col[], int dpos[], int dneg[]){
  int j, k;
  if(i == N){
    output(row);
    return;
  }
  for(j = 0; j < 8; j++){
    if(col[j] == 1 || dpos[i+j] == 1 || dneg[i-j+7] == 1){
      continue;
    }
    row[i] = j;
    col[j] = 1;
    dpos[i+j] = 1;
    dneg[i-j+7] = 1;
    putQueen(i+1, row, col, dpos, dneg);
    col[j] = 0;
    dpos[i+j] = 0;
    dneg[i-j+7] = 0;
  }
}

int main(){
  int i, j, k;
  int r, c;
  int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];

  for(i = 0; i < N; i++){
    row[i] = 0;
    col[i] = 0;
  }
  for(i = 0; i < 2 * N - 1; i++){
    dpos[i] = 0;
    dneg[i] = 0;
  }
  
  scanf("%d", &k);

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      a[i][j] = 0;
    }
  }
  
  for(i = 0; i < k; i++){
    scanf("%d%d", &r, &c);
    a[r][c] = 1;
  }
  
  putQueen(0, row, col, dpos, dneg);

  return 0;
}



Measured memory_bytes: 2112
import bisect
a = [True] * 100001
a[0] = False
a[1] = False
p = []
for i in range(2, 100001):
    if a[i]:
        for j in range(i * 2, 100001, i):
            if a[j]:
                a[j] = False
        if i % 2 != 0 and a[(i + 1) // 2]:
            p.append(i)
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(bisect.bisect_right(p, r) - bisect.bisect_left(p, l))


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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

int main()
{
    ll h;
    int n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll sum=0;
    rep(i,n){
        sum+=a[i];
    }
    if(sum>=h){
        Yes;
    }else{
        No;
    }
}

Measured memory_bytes: 3772
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    pattern = 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:
                    pattern += 1
    print(pattern)
main()

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

int main(){
    int n; cin >> n;
    vector<long long int> a(n), b(n);
    vector<pair<pair<int,int>, int> > c(n);
    for(int i=0;i<n;i++) {
        cin >> a[i] >> b[i];
        c[i].first.first = -(a[i] + b[i]);
        c[i].first.second = a[i];
        c[i].second = i;
    }
    sort(c.begin(),c.end());
    long long int tk=0,ao=0;
    for(int i=0;i < n; i++){
        if(i % 2 == 0) tk += a[c[i].second]; 
        else ao += b[c[i].second];
    }
    cout << tk - ao << endl;
    return 0;
}

Measured memory_bytes: 2944
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int a, b, c, d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
        if(abs(a - c)<=d){
            printf("Yes\n");
        }
        else if(abs(a-b)<=d&&abs(b -c)<=d){
            printf("Yes\n");
        }
        else printf("No\n");
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

int D; 
int c[27];
int s[366][27];
int t[366];


ll cal_score(){
    int last[27] = {0};
    ll score = 0;
    for(int d=1;d<=D;++d){
        int i = t[d];
        score += s[d][i];
        last[i] = d;
        for(int j=1;j<=26;++j){
            score -= c[j]*(d-last[j]);
        }
        //cout << score << "\n";
    }
    return score;
}

int main(){
    cin>>D;
    for(int i=1;i<=26;++i){ cin >> c[i]; }
    for(int d=1;d<=D;++d){ for(int i=1;i<=26;++i){ cin >> s[d][i]; } }
    
    default_random_engine e1(29876239);
    uniform_int_distribution<int> uniform_dist(1, 26);   
    
    for(int d=1;d<=D;++d){
        int t = uniform_dist(e1);;
        for(int i=1;i<=26;++i){
            if((double)s[d][i]>(double)s[d][t]*1.3){
                t = i;
            }
        }
        cout << t << "\n";
    }
    
    
}

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

typedef long long ll;

using namespace std;

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

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;

int main(){
    char c;
    cin >> c;
    cout << (char)((int)c+1) << endl;
    return  0;
}




Measured memory_bytes: 256
program main
	implicit none
	integer a,b
	character x,y
	read(*,*)x,y
	select case(x)
		case('A')
			a=1
		case('B')
			a=2
		case('C')
			a=3
		case('D')
			a=4
		case('E')
			a=5
		case('F')
			a=6
	end select
	select case(y)
		case('A')
			b=1
		case('B')
			b=2
		case('C')
			b=3
		case('D')
			b=4
		case('E')
			b=5
		case('F')
			b=6
	end select
	if(a<b)then
		write(*,*)"<"
	else if(a==b)then
		write(*,*)"="
	else
		write(*,*)">"
	endif
end program main


Measured memory_bytes: 512
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
A = [INT() for _ in range(N)]

A.sort()

if N%2 == 0:
	a = A[:N//2]
	b = A[N//2:]

	print((2*sum(b)-b[0]) - (2*sum(a)-a[-1]))

else:
	a1 = A[:N//2]
	b1 = A[N//2:]

	ans1 = (2*sum(b1)-b1[0]-b1[1]) - 2*sum(a1)

	a2 = A[:-(-N//2)]
	b2 = A[-(-N//2):]

	ans2 = (2*sum(b2)) - (2*sum(a2)-a2[-1]-a2[-2])

	print(max(ans1, ans2))



Measured memory_bytes: 15920
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;

int main(){
 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
ll n;
cin>>n;
ll cnt=0;
rep(i,0,n)
{
	ll x;
	cin>>x;
	if(x%2!=0)
	cnt++;
}
if(!(cnt%2))

	cout<<"YES\n";
	else
	cout<<"NO\n";


}





Measured memory_bytes: 256
// java
import java.util.Scanner;
import java.io.FileReader;
public class Main {
    public static void main(String[] args) {
        Scanner in = null;

        // read from local file for testing
        try {
            in = new Scanner(new FileReader("in.txt"));
        } catch (Exception e) { }

        // when submit your code, use this instead  
        in = new Scanner(System.in);

        int result = in.nextInt() * in.nextInt();
        if(result%2 == 0){
          System.out.println("Even");
        }
        else{
          System.out.println("Odd");
        }
        
    }
}

Measured memory_bytes: 22736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(e,array) for(const auto& e : array)
#define lower_index(v,a) (int)distance(v.begin(), lower_bound((v).begin(),(v).end(),a))
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
typedef long long ll;
const int inf = 1<<28;
const ll INF = 1LL<<57;
const ll MOD = 1e9+7;

int main(){ 
    ll N; cin >> N;
    rep(_,N){
        string x,y;cin >> x >> y;
        ll X = x.size();
        ll Y = y.size();
        vector<vector<ll>> dp(X+1,vector<ll>(Y+1,0));
        rep(i,X)rep(j,Y){
            if (x[i]==y[j]) chmax(dp[i+1][j+1],dp[i][j]+1);
            else chmax(dp[i+1][j+1],max(dp[i+1][j],dp[i][j+1]));
        }
        cout << dp[X][Y] << endl;
    }

}


Measured memory_bytes: 10768
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int H, W, N, X[201010], Y[201010];
vector<int> rows[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W >> N;
    swap(H, W);
    rep(i, 0, N) cin >> X[i] >> Y[i];
    rep(i, 0, N) rows[Y[i]].push_back(X[i]);
    rep(y, 0, H + 1) sort(all(rows[y]));

    int ans = W;
    int cx = 1;
    rep(cy, 1, H + 1) {
        int mi = W;
        fore(x, rows[cy]) if (cx < x) chmin(mi, x - 1);
        chmin(ans, mi);
        
        cx++;
        fore(x, rows[cy + 1]) {
            if (x < cx) continue;
            else if (x == cx) cx++;
            else if (cx < x) break;
        }
    }
    cout << ans << endl;
}

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s, t;
	cin >> s >> t;
	t.pop_back();
	if (s == t) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    multiset<int> st = {-1,-1,n,n};
    vector<int> a(n);
    ll ans = 0;
    for (int i = 0;i < n;++i) {
        int p;
        cin >> p;
        a[p-1] = i;
    }
    for (ll i = n-1;i >= 0;--i) {
        auto it = st.upper_bound(a[i]);
        int w = *prev(it,2);
        int x = *prev(it);
        int y = *it;
        int z = *next(it);
        ans += (i+1)*(x-w)*(y-a[i])+(i+1)*(a[i]-x)*(z-y);
        st.insert(a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5376
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
output = 0

for i in range(N):
    if A[i] + A[i +1] - B[i] <= 0:
        output += A[i] + A[i + 1]
        A[i], A[i + 1] = 0, 0

    elif A[i] - B[i] <= 0:
        output += B[i]
        A[i], A[i + 1] = 0, A[i + 1] - (B[i] - A[i])

    else:
        output += B[i]
        A[i] -= B[i]

print(output)

Measured memory_bytes: 18624
n=int(input())
h=list(map(int,input().split()))

cost=[0]*n

cost[0] = 0
cost[1] = abs(h[1]-h[0])
for i in range(2,n):
    cost[i] = min(abs(h[i]-h[i-1])+cost[i-1],abs(h[i]-h[i-2])+cost[i-2])
print(cost[n-1])

Measured memory_bytes: 13980
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String, Integer> hs = new HashMap<>();
        hs.put("SUN", 7);
        hs.put("MON", 6);
        hs.put("TUE", 5);
        hs.put("WED", 4);
        hs.put("THU", 3);
        hs.put("FRI", 2);
        hs.put("SAT", 1);
        String s = sc.next();
        System.out.println(hs.get(s));
        sc.close();
    }
}


Measured memory_bytes: 35544
N,M=map(int,input().split())
A=[0]*(N+1)
for i in range(M):
  a=int(input())
  A[a]=1
mod=10**9+7
dp=[0]*(N+1)
dp[0]=1
for i in range(N):
  dp[i+1]=dp[i]
  if i>=1:
    dp[i+1]+=dp[i-1]
  if A[i+1]==1:
    dp[i+1]=0
  dp[i+1]%=mod
print(dp[N])

Measured memory_bytes: 46936
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);

const int INF = 2e9;
const int MAXN = 1e5 + 5;

int n, h[MAXN], dp[MAXN];

int main() {
    IOS

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

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

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= 2 && i + j <= n; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[n] << '\n';
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll n, a, b; cin >> n >> a >> b;
    if(n == 1){
        if(a == b){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }else if(n == 2){
        if(a >= b){
            cout << 0 << endl;
        }else{
            cout << 1 << endl;
        }
        return 0;
    }else{
        if(a < b){
        cout << (n - 2) * (b - a) + 1 << endl;
        }else if(a == b){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
}

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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n,k;
	cin >> n >> k;
	ll arr[n+1];
	for(ll i=1;i<=n;i++)
		cin >> arr[i];
	ll val=1;
	ll i=1;
	ll j=k+1;
	while(j<=n)
	{
		if(arr[i]>=arr[j])
			cout << "No" << endl;
		else 
			cout << "Yes" << endl;
		i++;
		j++;
	}
	return 0;	
}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) for(int i = 0; i < n; ++i)
#define _ << " " <<
typedef double lf;
typedef long long ll;
typedef pair<int, int> point;

const int mod = 1e9 + 7;
int add(int x, int y) {
	x += y;
	if(x >= mod) return x - mod;
	return x;
}
int sub(int x, int y) {
	x -= y;
	if(x < 0) return x + mod;
	return x;
}
int mul(int x, int y) {
	return (ll) x * y % mod;
}

const int MAXN = 1e5 + 5;

vector<int> path, e[MAXN];

bool bio[MAXN];

void dfs(int x, int tip) {
   if(tip) path.push_back(x);
   bio[x] = true;
   for(auto y: e[x]) {
      if(!bio[y]) {
         dfs(y, tip);
         break;
      }
   }
   if(!tip) path.push_back(x);
}

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

	int n, m; cin >> n >> m;

	REP(i, m) {
      int x, y; cin >> x >> y;
      e[x].push_back(y);
      e[y].push_back(x);
	}

	dfs(1, 0);

	for(auto y: e[1]) {
      if(!bio[y]) {
         dfs(y, 1);
         break;
      }
	}

   cout << path.size() << endl;

	REP(i, path.size()) {
      cout << path[i] << " ";
	}
}


Measured memory_bytes: 9720
cat, doccat, cat_much = input().split(" ")

if int(cat) > int(cat_much):
    answer = "NO"
elif int(cat) == int(cat_much):
    answer = "YES"
else:
    if int(cat) + int(doccat) >= int(cat_much):
        answer = "YES"
    else:
        answer = "NO"

print(answer)

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  VI xs(N);
  cin >> xs;
  SORT(xs);

  cout << accumulate(ALL(xs), 0) - xs.back() / 2 << endl;

  return 0;
}


Measured memory_bytes: 256