akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n, k;
    cin >> n >> k;
    int m = n - k;
    vector<ll> h(n + 1, 0);
    rep(i, n) cin >> h[i + 1];

    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 1e18));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            ll now = 1e18;
            for (int x = 0; x < i; x++) {
                now = min(now, dp[x][j] + max(0LL, h[i] - h[x]));
            }
            dp[i][j + 1] = now;
        }
    }
    ll ans = 1e18;
    rep(i, n + 1) {
        ans = min(ans, dp[i][m]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def main():
    a, b, c, d = get_ints()

    print(max(a*c, a*d, b*c, b*d))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int ok=15-(int)s.size();
    for ( char c:s ) {
        if ( c=='o' ) ok++;
        else ok--;
    }   
    if ( ok>0 ) cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,A,B;
    cin>>N>>A>>B;
    int cnt=0;
    rep(i,N){
        int t;
        cin>>t;
        if(t<A||t>=B)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int i,flag=0;
	string str;
	cin >> str;
	if(str == "RRR")
		cout <<"3\n";
	else if(str == "RRS" or str=="SRR")
		cout <<"2\n";
	else
	{
		for(i=0;i<3;i++)
		{
			if(str[i]== 'R')
				flag =1;
		}
		if(flag==1)
			cout <<"1\n";
		else
			cout << "0\n";
	}
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
}

Measured memory_bytes: 3652
import math

def main():
    H,N=map(int,input().split())

    inf=float('inf')
    dp=[0]+[inf]*H

    for i in range(N):
        A,B=map(int,input().split())
        if A>=H:
            #dp[-1]=min(B,dp[-1])
            if B < dp[-1]:
                dp[-1]=B
        else:
            for j in range(A,H+1):
                #dp[j]=min(dp[j-A]+B,dp[j])
                if dp[j-A]+B<dp[j]:
                    dp[j]=dp[j-A]+B

                if j > H-A:
                    #dp[-1]=min(dp[-1],dp[j]+B)
                    if dp[j]+B < dp[-1]:
                        dp[-1]=dp[j]+B

    print(dp[-1])

main()

Measured memory_bytes: 3440
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n, x;
    cin>>n>>x;
    vi l(n);
    lli d=0;
    lli ans=1;
    rep(i,n){
        cin>>l[i];
    }
    rep(i,n){
        d+=l[i];
        if(d<=x){ 
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3568
/* Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define debug(x) cout << #x << " " << x <<endl;
#define set_bits __builtin_popcount
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod)
{ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
/*--------------------------------------------------------------------------------------------------------------------------*/
int main()
{
	fastio();
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif
	int l, r, d;
	cin >> l >> r >> d;
	cout << r / d - (l - 1) / d << endl;
	return 0;
}


Measured memory_bytes: 3580
n=int(input())
a=list(map(int, input().split()))
q=int(input())
num=[0]*(10**5)
tot=0
for i in range(n):
    num[a[i]-1]+=1
    tot+=a[i]

for _ in range(q):
    b,c=map(int, input().split())
    tot+=(num[b-1]*(c-b))
    num[c-1]+=num[b-1]
    num[b-1]=0
    print(tot)

Measured memory_bytes: 20880
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

std::string solve(int n, int a, int b){
    const std::string BORYS = "Borys";
    const std::string ALICE = "Alice";
    std::string ret = (abs(b - a) % 2 == 1) ? BORYS : ALICE;
    return ret;
}

int main()
{
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    int n, a, b;
    std::cin >> n >> a >> b;
    std::string ans;
    ans = solve(n, a, b);
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int x;
    cin >> x;
    int f = (x - 400) / 200;
    cout << 8 - f << endl;
}


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

int main(){
  string s,x="";
  cin>>s;
  int l=s.length();
  int i=0,c=INT_MAX,d,t;
  while(i<l-2)
  {
     x=s.substr(i,3);
     t=stoi(x);
     d=abs(t-753);
     if(d<c)
       c=d;
       i++;
      x="";
  }
  cout<<c<<endl;
  return 0;
}
     

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define upb upper_bound
#define lwb lower_bound
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

map<ll ,ll> mpa, mpb;

struct comp {
    bool operator()(ll& a, ll& b)
    {
    	return rng()%2;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

	ll n;
	cin>>n;
	ll a[n], b[n];
	map<ll, ll> rand, org;
	priority_queue<ll, vi, comp> pq, pqorg;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mpa[a[i]]++;
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
		mpb[b[i]]++;
	}
	
	for(int i=0;i<n;i++){
		if(rand[b[i]]==0)
			pq.push(b[i]);
		rand[b[i]]++;
	}
	pqorg = pq;
	org = mpb;
	
	int flag=0;
	vi v(n, 0);
	for(int i=0;i<n;i++){
		if(pq.top()==a[i]){
			ll op = pq.top();
			pq.pop();
			if(pq.empty()) {
				flag=1;
				break;
			}
			else{
				ll op1 = pq.top();
				pq.pop();
				mpb[op1]--;
				if(mpb[op1]) pq.push(op1);
				v[i] = op1;
			}
			pq.push(op);
		}
		else{
			ll op = pq.top();
			pq.pop();
			mpb[op]--;
			if(mpb[op]) pq.push(op);
			v[i] = op;
		}
	}
	if(flag){
		
		for(int it=0;it<=30;it++){
			pq = pqorg;
			mpb = org;
			int flag=0;
			vi v(n, 0);
			for(int i=0;i<n;i++){
				if(pq.top()==a[i]){
					ll op = pq.top();
					pq.pop();
					if(pq.empty()) {
						flag=1;
						break;
					}
					else{
						ll op1 = pq.top();
						pq.pop();
						mpb[op1]--;
						if(mpb[op1]) pq.push(op1);
						v[i] = op1;
					}
					pq.push(op);
				}
				else{
					ll op = pq.top();
					pq.pop();
					mpb[op]--;
					if(mpb[op]) pq.push(op);
					v[i] = op;
				}
			}
			if(flag==0){
				cout<<"Yes\n";
				for(int i=0;i<n;i++){
					cout<<v[i]<<" ";
				}
				return 0;
			}
		}
		
	}
	else{
		cout<<"Yes\n";
		for(int i=0;i<n;i++){
			cout<<v[i]<<" ";
		}
		return 0;
	}
	cout<<"No";
	
    return 0;
}


Measured memory_bytes: 60904
#include <iostream>
using namespace std;
int main()
{
	int S;
	int temp;
	bool flag1 = false, flag2 = false;

	cin >> S;
	temp = S % 100;
	if (temp <= 12 && temp >= 1) {
		flag1 = true;
	}
	temp = S / 100;
	if (temp <= 12 && temp >= 1) {
		flag2 = true;
	}

	if (flag1 == true && flag2 == true) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (flag1 == true) {
		cout << "YYMM" << endl;
	}
	else if (flag2 == true) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import math
import copy

# inputa = input().split()
# inputb = input().split()
# inputc = input().split()

# a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# a = inputa[0]
# inputList = list(a)

# x = int(inputb[0])
# y = int(inputb[1])

a = 5
inputList=[]
for i in range(a):
    inputNum = input()
    inputList.append(inputNum)

inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

itemInfo = []
tmp = []

for i in range(a):
    tmp.append(int(math.floor(inputList[i]/10))*10)
    tmp.append(int(math.ceil(inputList[i]/10))*10)
    tmp.append(inputList[i]%10)
    itemInfo.append(copy.deepcopy(tmp))
    tmp.clear()

tmpList = sorted(itemInfo, key = lambda x:x[2])

flg = False
sum = 0
for i in range(len(tmpList)):
    if flg == False and tmpList[i][2] != 0:
        flg = True
        sum += tmpList[i][0] + tmpList[i][2]
    else:
        sum += tmpList[i][1]

print(sum)






Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 355001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;

map<ll,int> mp;
ll n , a[N], pref[N];

signed main(){
    ll ans = 0 ;
    mp[0]++;
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
        scanf("%lld",&a[i]);
        pref[i]=pref[i-1]+a[i];
        ans+=mp[pref[i]];
        mp[pref[i]]++;
    }
    cout <<ans << endl;

}

Measured memory_bytes: 16640
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

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

int count(int N)
{
        int cnt = 0;
        while (N)
        {
                cnt += N % 10;
                N /= 10;
        }
        return cnt;
}

int main()
{
        int N, A, B;
        cin >> N >> A >> B;

        int ans = 0;
        for (int i = 1; i < N + 1; i++)
        {
                int cnt = count(i);
                if (A <= cnt && cnt <= B)
                        ans += i;
        }
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,n;cin >> a >> b >> n;
    ll t=min(b-1,n);
    cout << a*t/b-t/b*a << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;

    int pos[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    if(pos[x] == pos[y])
    	cout << "Yes" << endl;
    else
    	cout << "No" << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans = 0;
    if(k <= a)ans+=k,k=0;
    else ans+=a,k-=a;

    if(k<=b)k=0;
    else k-=b;

    ans-=k;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>

using namespace std;

int main(){
  int b[]={1<<0|1<<1,1<<0,1<<0|1<<2,1<<1,0,1<<2,1<<1|1<<3,1<<3,1<<2|1<<3};
  for(int i=0;i<1000;i++){
    char p[11];
    cin>>p;
    bool f=false;
    for(int j=1;p[j];j++){
      int c=b[p[j-1]-'A']^b[p[j]-'A'];
      f|=!c||c&c-1;
    }
    if(!f){
      cout<<p<<endl;
    }
  }
}

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

main() {
  int H, W;
  cin >> H >> W;

  vector<string> grid(H);
  int white = 0;
  for (auto& row : grid) {
    cin >> row;
    for (auto cell : row) {
      white += cell == '.';
    }
  }
 
  queue<pair<int, int>> q;
  q.emplace(0, 0);
 
  vector<vector<int>> dist(H, vector<int>(W, -1));
  dist[0][0] = 0;
  
  int dy[] = { 0, 1, 0, -1 };
  int dx[] = { 1, 0, -1, 0 };
 
  while (!q.empty()) {
    auto y = q.front().first;
    auto x = q.front().second;
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int y_ = y + dy[i];
      int x_ = x + dx[i];
      if (y_ < 0 || H <= y_ || x_ < 0 || W <= x_) continue;
      if (grid[y_][x_] == '#') continue;
      if (dist[y_][x_] != -1) continue;
      dist[y_][x_] = dist[y][x] + 1;
      q.emplace(y_, x_);
    }
  }
 
  if (dist[H - 1][W - 1] == -1) {
    cout << -1 << endl;
  } else {
    cout << white - dist[H - 1][W - 1] - 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
ll mod=1e9+7;
int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
         
    // }
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll pref[n];
    pref[0]=0;
    for(int i=1;i<n;i++)
    {
        pref[i]=(pref[i-1]%mod+a[i-1]%mod)%mod;
    }
    ll ans=0;
    for(int i=1;i<n;i++)
    {
        ll temp=(a[i]%mod*pref[i]%mod)%mod;
        ans=(ans%mod+temp%mod)%mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6704
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        h: usize,
        mut katanas: [(usize, usize); n],
    }

    let amax = katanas.iter().map(|v| v.0).max().unwrap();
    katanas.sort_by_key(|v| -(v.1 as i64));
    let mut damage = 0;
    let mut cnt = 0;
    for &(_, p) in &katanas {
        if p >= amax {
            damage += p;
            cnt += 1;
        }
        if damage >= h {
            break;
        }
    }
    katanas.sort_by_key(|v| -(v.0 as i64));
    if h > damage {
        let d = katanas[0].0;
        cnt += (h - damage + d - 1) / d;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    string a,b;
    cin >> a >> b;
    if (a.length()>b.length()){
        cout << "GREATER" << endl;
        return 0;
    }
    if (a.length()<b.length()){
        cout << "LESS" << endl;
        return 0;
    }
    for (int i=0;i<a.length();i++){
        if (a[i]==b[i]) continue;
        else if (a[i]>b[i]){
            cout << "GREATER" << endl;
            return 0;
        }
        else {
            cout << "LESS" << endl;
            return 0;
        }
    }
    cout << "EQUAL" << endl;
    
}

Measured memory_bytes: 256
###############################################################################

import sys
from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = input()

    for i in n:
        if i == '1':
            sys.stdout.write('9')
        if i == '9':
            sys.stdout.write('1')
    print()


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fe(i,a,b) for(int i=(a);i<=(b);i++)
#define fne(i,a,b) for(int i=(a);i<(b);i++)
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%lld",&x)
#define mst(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(),x.end()
#define pb push_back
#define lowbit(x) x&-x
#define lc rt<<1
#define rc rt<<1|1
#define ls lc,l,m
#define rs rc,m+1,r
#define dbg(x) cout<<' '<<#x<<" = "<<x<<endl;
#define dbg2(x,y) cout<<' '<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<endl;
#define dbg3(x,y,z) cout<<' '<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<endl;
const int INF =0x3f3f3f3f;
const int mod = 1e9+7;
const double eps=1e-8;
const int N = 2e5+5;
int dir[4][2]={0,1,0,-1,1,0,-1,0};
int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int c[N],w[N];
ll dp[N];
int main(){
//	freopen("BZW.txt","r",stdin);
	//freopen("BZW.txt","r",stdin);
	//freopen("BZW.txt","r",stdin);
	int n,W;
	read2(n,W);
	int totv = 0;
    fe(i,1,n)read2(c[i],w[i]),totv+=w[i];
    mst(dp,0x3f);
    dp[0] = 0;
    fe(i,1,n){
    	for(int j=totv;j>=w[i];j--){
				//value =j ,use min cost
			dp[j] = min(dp[j],dp[j-w[i]]+c[i]);
    	}
    }
    int res;
    for(int i=totv;i>=0;i--){
        if(dp[i] <= W){
			res = i;
			break;
        }
    }
    cout<<res<<endl;




	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

int64_t sub(int64_t n) {
	int64_t retval = 1;

	for (int64_t i = n; i > 0; i--) {
		retval = retval % MOD * i % MOD;
	}

	return retval;
}

int main() {
	int64_t N, M;
	cin >> N >> M;

	int64_t d = abs(N - M);
	int64_t ans = 0;

	int64_t n, m;
	n = sub(N);
	m = sub(M);
	if (d <= 1) ans = n * m % MOD;
	if (!d) ans = ans % MOD * 2 % MOD;
	
	cout << ans << endl;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>

int main(){

  int i,n,a[250];


  scanf("%d",&n);

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

    scanf("%d",&a[i]);
  }

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

    printf("node %d: key = %d, ",i,a[i]);

    if(i/2 <= n && i/2 > 0) printf("parent key = %d, ", a[i/2]);

    if(i*2 <= n) printf("left key = %d, ",a[i*2]);

    if(i*2+1 <= n) printf("right key = %d, ",a[i*2+1]);

    printf("\n");
  }


  return 0;
}

      
      



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int t[N+1], x[N+1], y[N+1];
  t[0]=0;x[0]=0;y[0]=0;
  for(int i=1;i<=N;i++){
    cin >> t[i] >> x[i] >> y[i];
  }

  int flag = 0;
  int dist, time;
  for(int i=1;i<=N;i++){
    dist = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
    time = t[i] - t[i-1];
    if(time<dist||abs(time - dist)%2!=0){
      flag = 1;
      break;
    }
  }

  if (flag==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = a[0]
    for i in range(1, N, 1):
        b = b ^ a[i]
    if b == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 14116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N, A;
    cin >> N >> A;
    cout << N*N-A<<endl;
}

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

int main(){
  int N;
  cin >> N;
  
  int all = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
    all = all ^ A.at(i);
  }
  
  vector<int> ans(N);
  for (int i = 0; i < N; i++){
    ans.at(i) = all ^ A.at(i);
  }
  
  for (int i = 0; i < N; i++){
    cout << ans.at(i) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <tuple>
#include <vector>
#include <map>
#include <iterator>

using namespace std;
using lint = long long int;

int main() {
	int a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;

	cout << max(c - (a - b), 0);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int b[210000];
int c[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",b+i);
		c[i]=b[i];
	}
	std::sort(c,c+a);
	for(int i=0;i<a;i++){
		if(c[a-1]==b[i]){
			printf("%d\n",c[a-2]);
		}else printf("%d\n",c[a-1]);
	}
}

Measured memory_bytes: 3072
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int d=a*100+b*10+c;
	if((d%4)==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int  X, x[100010],z[100010],ans;
	int N;
	cin >> N>>X;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		z[i] = abs(x[i] - X);
	}
	sort(z, z+N);
	ans = z[N - 1];
	for (int i = 0; i < N;i++) {
		while (z[i] != 0) {
			if (ans < z[i]) {
				swap(z[i], ans);
			}
			ans %= z[i];
			swap(ans, z[i]);
		}
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<int> dp(n+1,-1);
  dp[n]=0;
  queue<int> q;
  q.push(0);
  drep(i,n){
    while(1){
      if(q.empty()){
        cout << -1 << endl;
        return 0;
      }
      if(q.front()!=-1&&q.size()<=m)break;
      q.pop();
    }
    if(s[i]=='0')dp[i]=q.front()+1;
    q.push(dp[i]);
  }
  //rep(i,n+1)cout << dp[i] << endl;
  int c = dp[0];
  vector<int> mn(c+1,INF);
  rep(i,n+1){
    if(dp[i]==-1)continue;
    chmin(mn[dp[i]],i);
  }
  drep(i,c){
    cout << mn[i]-mn[i+1] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1472
#include <iostream>

using namespace std;

int main(void)
{
    int n, dr, ir;
    scanf("%d%d", &n, &dr);
    if (n >= 10)
        ir = dr;
    else
        ir = dr + 100 * (10 - n);
    printf("%d\n", ir);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define RG register
using namespace std;
const int N=1e5+10;
struct node{
	int a,b;
}num[N];
int n;
inline bool cmp(node a,node b){return a.a<b.a;}
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)
	{
		num[i]=(node){read(),read()};
	}
	sort(num+1,num+1+n,cmp);
	printf("%d\n",num[n].a+num[n].b);
	//fclose(stdin); fclose(stdout);
	return 0;
}


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(auto& x : a)
        cin >> x;
    for(auto& x : b)
        cin >> x;

    vector<pair<int,int>> v;
    for(int i = 0; i < n; ++i)
        v.emplace_back(b[i], a[i]);
    sort(v.begin(), v.end());

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(int i = 0; i < n; ++i){
        if(a[i] > b[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i = 0; i < n; ++i){
        if(i && a[i] <= b[i - 1]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    auto as = a;
    auto bs = b;
    for(int i = 0; i < n; ++i){
        a[i] = distance(as.begin(), lower_bound(as.begin(), as.end(), v[i].second));
        b[i] = distance(bs.begin(), lower_bound(bs.begin(), bs.end(), v[i].first));
    }
    vector<int> inv(n);
    for(int i = 0; i < n; ++i)
        inv[a[i]] = i;
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(a[i] != b[i]){
            int j = inv[i];
            swap(a[i], a[j]);
            inv[a[i]] = i;
            inv[a[j]] = j;
            ++cnt;
        }
    }
    if(cnt > n - 2 || a != b){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 2932
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    for i = 0 to n - 1 do
        let f = i < (n + 1) / 2 in
        let idx = if f then n - 1 - i * 2 else (i - (n + 1) / 2) * 2 + (n mod 2) in
        Printf.printf "%d " a.(idx)
    done;
    print_newline ()
)

Measured memory_bytes: 7556
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define INF (int)(1e9)
#define minimize(a, b) a = min(a, b)

int dp[10010];

int main() {
    int h, n;
    cin >> h >> n;
    int a[n], b[n];
    for (int i=0; i<n; i++) {
        cin >> a[i] >> b[i];
    }
    fill(dp, dp+h+1, INF);
    dp[0] = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<h; j++) {
            minimize(dp[min(j+a[i], h)], dp[j] + b[i]);
        }
    }
    cout << dp[h] << '\n';
    return 0;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> datos(n);
    for (int &i : datos) cin >> i;
    sort(datos.begin(), datos.end());
    int suma = 0;
    for (int i = 0; i < m; i++) suma += datos[i];
    cout << suma << "\n";
    return 0;
}

Measured memory_bytes: 3628
import sys
from collections import defaultdict, deque
n = int(sys.stdin.readline().split()[0])
A = defaultdict(deque)
ans = []
for query in sys.stdin:
    if query[0] == '0':
        t, x = query[2:].split()
        A[t].append(x)
    elif query[0] == '1':
        if A[query[2:-1]]:
            ans.append(A[query[2:-1]][0] + '\n')
    else:
        if A[query[2:-1]]:
            A[query[2:-1]].popleft()
sys.stdout.writelines(ans)



Measured memory_bytes: 20136
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
 int X,A,B;cin>>X>>A>>B;if(B-A<=0)cout<<"delicious"<<endl;
  else if(B-A<=X)cout<<"safe"<<endl;
  else cout<<"dangerous"<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
    int h,w;
    cin>>h>>w;
    vvi f(h+2,vi(w+2,1));
    vvi walk(h+2,vi(w+2,0));
    int gy,gx,y=0,x=0,v=0;
    range(i,1,h+1)range(j,1,w+1){
        char c;
        cin>>c;
        switch(c){
            case 'G': gy=i,gx=j,f[i][j]=0; break;
            case '.': f[i][j]=0;break;
            case '#': break;
            case '^': y=i,x=j,v=0,f[i][j]=0; break;
            case '>': y=i,x=j,v=1,f[i][j]=0; break;
            case 'v': y=i,x=j,v=2,f[i][j]=0; break;
            case '<': y=i,x=j,v=3,f[i][j]=0; break;
        }
    }
    walk[y][x]=1;
    rep(loop,9000000){//2646
        vvi vec={{-1,0},{0,1},{1,0},{0,-1}};
        if(f[y+vec[(v+1)%4][0]][x+vec[(v+1)%4][1]]==0){
            v=(v+1)%4;
            y+=vec[v][0], x+=vec[v][1];
            walk[y][x]=1;
        }else if(f[y+vec[v][0]][x+vec[v][1]]==1){
            v=(v+3)%4;
        }else{
            y+=vec[v][0],x+=vec[v][1];
            walk[y][x]=1;
        }
        if(y==gy&&x==gx){
            break;
        }
    }
    if(y==gy&&x==gx){
        int ans=0;
        rep(i,h+2)rep(j,w+2)ans+=walk[i][j];
        cout<<ans<<endl;
    }else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3192
#include <algorithm>
#include <cstdio>
const int MAXN = 3005;
int A[MAXN];
int B[MAXN];
int dp[MAXN][MAXN];
int pd[MAXN][MAXN];
int N, T;

void prefix() {
    for (int j = 0; j <= T; ++j) {
        dp[0][j] = 0;
    }
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= T; ++j) {
            dp[i][j] = dp[i-1][j];
            if (j >= 1)     dp[i][j] = std::max(dp[i][j-1], dp[i][j]);
            if (j >= A[i])  dp[i][j] = std::max(dp[i-1][j - A[i]] + B[i], dp[i][j]);
        }
    }
}

void suffix() {
    for (int j = 0; j <= T; ++j) {
        pd[N+1][j] = 0;
    }
    for (int i = N; i >= 1; --i) {
        for (int j = 0; j <= T; ++j) {
            pd[i][j] = pd[i+1][j];
            if (j >= 1)     pd[i][j] = std::max(pd[i][j-1], pd[i][j]);
            if (j >= A[i])  pd[i][j] = std::max(pd[i+1][j - A[i]] + B[i], pd[i][j]);
        }
    }
}

int solve() {
    prefix();
    suffix();
    // No final dish
    int ret = dp[N][T];
    // Fix final dish
    for (int i = 1; i <= N; ++i) {
        int cur = 0;
        for (int j = 0; j < T; ++j) {
            cur = std::max(dp[i-1][j] + pd[i+1][T-j-1], cur);
        }
        cur += B[i];
        ret = std::max(cur, ret);
    }
    return ret;
}

int main() {
    scanf(" %d%d", &N, &T);
    for (int i = 1; i <= N; ++i) {
        scanf(" %d%d", &A[i], &B[i]);
    }
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
using std::vector;
using std::pair;
using std::cin;
using std::cout;
typedef long long LONG;
typedef int INT;
LONG n, m;
int main( )
{
 std::ios::sync_with_stdio( false );
 cin >> n >> m;
 long long ans = 0;
 ans = std::min( n, m / 2 );
 m -= ans * 2;
 ans += m / 4;
 cout << ans;
 return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}

//int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}

int32_t main(void){
	IOS;
	
	in2(a, b);
	cout<<a*b<<endl;
	
}

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

using namespace std;
typedef long long int ll;
int main() {
    
    ll n, k, a, b, i;
    string s;
    cin>>s;
    for(i=0;i<=2;i++)
    printf("%c", s[i]);
    
    
    
    return 0;
}

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

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

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

  //double x = cbrt(L);
  double x = L/3.0;
  
  double ans = x * x * x ;
  cout << fixed << setprecision(10);
  cout << ans;

  
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[n],b[n];
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[a[i]]=i;
    }
    for (int j=1;j<=n;j++){
        printf("%d ",b[j]);
    }
    return 0;
}

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

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

    int n,k,ans=0;
	string s;
	//cin >> n;
	cin >> s;

	if(s[0]=='S'){
		cout << "Cloudy" << endl;
	}
	else if(s[0]=='C'){
		cout << "Rainy" << endl;
	}
	else{
		cout << "Sunny" << endl;
	}
}

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

using namespace std;

int main() {
    deque<int64_t> lucas;
    lucas.push_back(2LL);
    lucas.push_back(1LL);
    int n;
    cin >> n;
    for (int64_t i = 2LL; i <= n; ++i) {
        int64_t m;
        m = lucas.at(i - 1LL) + lucas.at(i - 2LL);
        lucas.push_back(m);
    }
    cout << lucas.back();
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,k;
  int n=1;
  int m=1;
  cin >> a >> b >> k;
  for(int i=1;i<=a;i++){
    if(a%i==0&&b%i==0){
      n=n+1;
    }
  }
  for(int l=1;l<=a;l++){
    if(a%l==0&&b%l==0){
      if(n-k==m){
        cout << l << endl;
      }
      m=m+1;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,K,H,ans=0; cin>>N>>K;
  vector<ll> Z(N);
  for(int i=0; i<N; i++){
    cin>>H; Z[i]=H; ans+=H;
  }
  sort(Z.begin(), Z.end());
  for(int i=0; i<min(K,N); i++){
    ans-=Z[N-1-i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[210];
int main()
{
	cin>>n;
	for(int i=1;i<=2*n;++i){
		scanf("%d",a+i);
	}
	sort(a+1,a+2*n+1);
	int ans=0;
	for(int i=1;i<=2*n;i+=2){
		ans+=a[i];
	}
	cout<<ans<<endl;
}

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

int main() {
    int n, a;
    cin >> n;
    set<int> s;
    for(int i=0; i<n; i++) {
        cin >> a;
        if(s.count(a)) s.erase(a);
        else s.insert(a);
    }
    cout << s.size();
}


Measured memory_bytes: 4864
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n,x,count;
	while(true){
	cin>>n>>x;
	count=0;
	if(n==0&&x==0)
		break;
	for(int i=1;i<=n-2;i++){
		for(int j=i+1;j<=n-1;j++){
			for(int k=j+1;k<=n;k++){
				if(i+j+k==x)
					count++;
			}
		}
	}
	cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160