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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;

using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

using Tree = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

int main(){
    int n;
    cin >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = INF;
    rep(mask, 1<<n) {
        dumpL(bitset<4>(mask));
        ll tmp = 0;
        deque<pii> odd;
        deque<pii> even;
        rep(i, n) {
            int x = a[i];
            int y = b[i];
            // if((mask&1)^(i&1)) even.emplace_back(x, i);
            // else odd.emplace_back(y, i);
            if(mask&(1<<i)) {
                if(i&1) odd.emplace_back(x, i);
                else even.emplace_back(x, i);
            }
            else {
                if(i&1) even.emplace_back(y, i);
                else odd.emplace_back(y, i);
            }
        }
        sort(all(even));
        sort(all(odd));
        dumpVL(even);
        dumpVL(odd);
        Tree t;
        rep(i, n) t.insert(i);
        auto& cur = even;
        auto& nxt = odd;
        ll prev = -INF;
        while(!cur.empty()) {
            auto p = cur.front();
            cur.pop_front();
            if(p.fi < prev) {
                nxt.emplace_back(-1,-1);
                break;
            }
            prev = p.fi;
            tmp += t.order_of_key(p.se);
            t.erase(p.se);
            swap(cur, nxt);
        }
        if(nxt.empty()) {
            chmin(ans, tmp);
            dumpL(tmp);
        }
        LINEL;
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    System.out.println(Math.max(Math.max(a, b) - Math.min(a, b) - w, 0));

  }
}

Measured memory_bytes: 35700
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;

  deque<int> a(N);
  F0R(i, N) {
    cin >> a[i];
  }

  // dp[i][j] ... 先頭からi個, 末尾からj個取り除いたときの最適行動時 X-Y
  vector<vector<i64>> dp(N, vector<i64>(N));

  F0R(i, N) {
    dp[i][N - i - 1] = a[i];
  }

  FOR(i, 1, N) {
    int jm = N - i - 1;
    F0R(j, N - i) {
      dp[j][jm - j] = max(
        a[N - jm + j - 1] - dp[j][jm - j + 1],
        a[j] - dp[j + 1][jm - j]
      );
    }
  }
  cout << dp[0][0];
}
#endif


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

int main(void) 
{
   int s,w;
   cin >> s >> w;

   if(s <= w) cout << "unsafe"<< endl;
   else cout << "safe" << endl;
}

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

int main(){
    int N;
    cin>>N;
    vector<string> s(N);
    for(int i = 0;i < N;i++){
        cin>>s.at(i);
    }
    int i = 0;//ac
    int j = 0;//wa
    int k = 0;//tle
    int l = 0;//re
    for(int g = 0;g < N;g++){
        if(s.at(g) == "AC"){
            i++;
        }
        if(s.at(g) == "WA"){
            j++;
        }
        if(s.at(g) == "TLE"){
            k++;
        }
        if(s.at(g) == "RE"){
            l++;
        }
    }//ループ終わり
    cout<<"AC"<<" "<<"x"<<" "<<i<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<j<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<k<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<l<<endl;
}


Measured memory_bytes: 6424
#include <stdio.h>


 
int main(){
  int i,j,n,R[200000];
  int dai,syo;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }
 //?????????
    syo = R[0];
    dai = R[1]-R[0];

    for(i=1;i<n;i++){
      if(R[i]-syo > dai) dai = R[i]-syo;
      if(R[i] < syo) syo = R[i];
    }
 
  printf("%d\n",dai);
  return 0;
}

Measured memory_bytes: 1376
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(void) {
	string s;
	cin >> s;
	
	char exs = s[0];
	if (s[0] == '0') exs = '1';
	else exs = '0';
	bool flag = false;
	int c = 0;

	for (const auto &i : s) {
		
		if (flag ^ (exs == i)) c++;
		if (exs == i) flag = !flag;

		exs = i;
	}

	if (c > s.size() - c) c = s.size() - c;

	cout << c;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  vector<char> alp;
  string S;
  cin >> S;
  rep(i, 3) alp.push_back(S[i]);
  sort(all(alp));
  cout << (alp[0]=='a' && alp[1]=='b' && alp[2]=='c' ? "Yes" : "No") << newl;
  return 0;
}

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

int count(int n, int x){
    int cnt=0;
    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)cnt++;
            }
        }
    }
    return cnt;
}

int main(){
    int n,x;
    
    while(1){
        cin>>n>>x;
        if(n==0&&x==0)break;
        cout<<count(n,x)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>

using namespace std;

int main() {
    int a;
    
    cin >> a;
    
    if (a == 111) {
        cout << 3 << endl;
    }
    
    else if ( (a==110) || (a==101) || (a==11)){
        cout << 2 << endl;
    }
    
    else if(a==0){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <tuple>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

void solve()
{
    ll N,K;
    ll ans = 0;
    cin >> N >> K;

    set<ll> setT;
    map<ll, vector<ll>> t1;

    for1(i,N) {
        ll t,d;
        cin >> t >> d;
        setT.insert(t);
        t1[t].push_back(d);
    }
    vector<pair<ll,ll>> t2;
    vector<pair<ll,ll>> t3;
    for(ll t: setT) {
        sort(t1[t].begin(), t1[t].end(), greater<ll>());
    }
    for(ll t: setT) {
        bool first = true;
        for(ll tt: t1[t]) {
            if (first) {
                first = false;
                t2.push_back(make_pair(tt,t));
            } else {
                t3.push_back(make_pair(tt,t));
            }
        }
    }
    sort(t2.begin(), t2.end(), greater<pair<ll,ll>>());
    if (t2.size() > K) {
        ll cnt = t2.size() - K;
        for1(i,cnt) {
            auto b = t2.back();
            t2.pop_back();
            t3.push_back(b);
        }
    }
    sort(t3.begin(), t3.end(), less<pair<ll,ll>>());;
    ll cntT = t2.size();
    ll sc = cntT * cntT;
    if (t2.size() < K) {
        ll cnt = K - t2.size();
        for1(i,cnt) {
            auto b = t3.back();
            t3.pop_back();
            t2.push_back(b);
        }
        sort(t2.begin(), t2.end(), greater<pair<ll,ll>>());
    }
    for (auto t: t2) {
        sc += t.first;
    }
    ans = sc;

    map<ll,ll> counter;
    for (auto t: t2) {
        counter[t.second]++;
    }

    for1(i,min(N-K,K)) {
        auto b = t2.back();
        t2.pop_back();
        counter[b.second]--;
        if (counter[b.second] == 0) {
            sc -= cntT * cntT;
            --cntT;
            sc += cntT * cntT;
        }
        sc -= b.first;

        b = t3.back();
        t3.pop_back();
        counter[b.second]++;
        if (counter[b.second] == 1) {
            sc -= cntT * cntT;
            ++cntT;
            sc += cntT * cntT;
        }
        sc += b.first;
        ans = max(ans, sc);
    }

    cout << ans << endl;
}

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

    do {
        solve();
    } while (DEBUG);
}


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

#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfl2(x, y) scanf("%I64d%I64d" , &x,&y)
#define sfl(x) scanf("%I64d" , &x)
#define sfl3(x, y, z) scanf("%I64d%I64d%I64d", &x, &y, &z)
#define sfd(x) scanf("%lf", &x)
#define sfd2(x, y) scanf("%lf", &x, &y)
#define sfs(x) scanf("%s", &x)
#define testv(x) cerr << x << ' '
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define test cerr << "here"
#define fst(x) cout << fixed << setprecision(x)
#define mod 1000000007
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;

int par[200005], rnk[200005];

int findp(int x)
{
    if (par[x] == x)
        return x;
    return par[x] = findp(par[x]);
}

bool iscon(int x, int y)
{
    if (findp(x) == findp(y))
        return true;
    return false;
}

void con(int x, int y)
{
    int px = findp(x), py = findp(y);
    if (rnk[px] > rnk[py])
        par[py] = px;
    else if (rnk[px] < rnk[py])
        par[px] = py;
    else
        par[px] = py, rnk[px]++;
}


    pair<pair<ll, ll>, int> a[100005], b[100005];
int main()
{
    ENGZ
    int n;
    ll ans = 0;
    for (int i = 0; i < 100005; i++)
        par[i] = i;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].first.first >> a[i].first.second;
        b[i].first.first = a[i].first.second;
        b[i].first.second = a[i].first.first;
        a[i].second = b[i].second = i;
    }
    sort(a, a + n);
    sort(b, b + n);
    map<ll, vector<pair<int, int>>> mp;
    for (int i = 0; i < n - 1; i++)
    {
        mp[abs(a[i].first.first - a[i + 1].first.first)].push_back({a[i].second, a[i + 1].second});
        mp[abs(b[i].first.first - b[i + 1].first.first)].push_back({b[i].second, b[i + 1].second});
    }
    for (auto it: mp)
    {
        for (auto i: it.second)
        {
            if (!iscon(i.first, i.second))
                con(i.first, i.second), ans += it.first;
        }
    }
    cout << ans;
    return 0;
}

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

int N;
string s;
vector<int> a;

void solve(vector<int> &x)
{
    for (int i=2; i<N; i++)
    {
        x[i] = (x[i-2] + x[i-1] + a[i-1]) % 2;
    }
}

bool check(vector<int> &x)
{
    if ((x[N-1] + x[1]) % 2 == (x[0] + a[0]) % 2 && (x[N-2] + x[0]) % 2 == (x[N-1] + a[N-1]) % 2)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void output(vector<int> &x)
{
    for (auto v : x)
    {
        if (v == 0) cout << 'S';
        else cout <<'W';
    }
    cout << endl;
}

int main()
{
    cin >> N >> s;
    a.resize(N, 0);
    for (int i=0; i<N; i++) if (s[i] == 'x') a[i] = 1;

    vector<int> x(N);
    x[0] = x[1] = 0;
    solve(x);
    if (check(x))
    {
        output(x);
        return 0;
    }
    x[0] = x[1] = 1;
    solve(x);
    if (check(x))
    {
        output(x);
        return 0;
    }
    x[0] = 1; x[1] = 0;
    solve(x);
    if (check(x))
    {
        output(x);
        return 0;
    }
    
    x[0] = 0; x[1] = 1;
    solve(x);
    if (check(x))
    {
        output(x);
        return 0;
    }

    cout << -1 << endl;

}


Measured memory_bytes: 1408
n, m = map(int, input().split())
a = list(map(int, input().split()))
matchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
numberlist = []
for i in range(m):
    numberlist.append(matchlist[a[i]])
numberlist = set(numberlist)
#dp[i]:i本でのmax桁
dp = [-10000000]*(n+1)
dp[0] = 0
for i in range(n):
    for j in numberlist:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1)


ans = []
d = dp[n]
a.sort(reverse = True)
for i in range(d):
    for j in a:
        if n - matchlist[j] >= 0:
            if dp[n] == dp[n-matchlist[j]] + 1:
                n -= matchlist[j]
                ans.append(j)
                break
print("".join(map(str,ans)))


Measured memory_bytes: 3696
main::IO()
main = do
  [x,k,d] <- map (read::String->Int) . words <$> getLine
  print $ if (div (abs x) d)>=k
    then (abs x)-k*d
    else f (mod (abs x) d) (k-div (abs x) d) d
  
f x k d = if k==0
  then abs x
  else if abs(x) >= abs(x-d)
    then f (x-d) (k-1) d
    else if even k
      then abs x
      else min (abs (x-d)) (abs (x+d))

Measured memory_bytes: 3944
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define debug(x) if(MODE==x)
#define MODE 0
using namespace std;

int h[100007];

int main()
{
    int i,j;
    int N;

    scanf("%d",&N);
    for( i=0; i<N; i++)
    {
        scanf("%d",&h[i]);
    }

    int maxi = 0;
    int cnt = 0;
    for( i=1; i<N; i++)
    {
        if(h[i] <= h[i-1])
            cnt++;
        else
        {
            maxi = max(maxi,cnt);
            cnt = 0;
        }
    }
    maxi = max(maxi,cnt);
    printf("%d\n",maxi);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int k;
    cin >> k;
    if(k%2 == 0) cout << k*k/4 << endl;
    else{
        int n = k/2;
        cout << n*(n+1) << endl;
    }
    return 0;
}

Measured memory_bytes: 3512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m;
    cin>>n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    cin>>m;
    rep(i,m){
        string s;
        cin>>s;
        mp[s]--;
    }
    int ans=0;
    for(auto itr:mp) chmax(ans,itr.se);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
        String[] directions = new String[n];
        for (int i = 0; i < n; i++) {
            directions[i] = String.valueOf(str.charAt(i));
        }
        
        int[] WCount = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            if (directions[i - 1].equals("W")) {
                WCount[i] += WCount[i - 1] + 1;
            } else {
                WCount[i] += WCount[i - 1];
            }
        }
        
        int minCount = n + 1;
        for (int i = 1; i <= n; i++) {
            int leftWCount = WCount[i - 1];
            int rightECount = n - i - (WCount[n] - WCount[i]);
            int count = leftWCount + rightECount;
            minCount = Math.min(minCount, count);
        }
        
        System.out.println(minCount);
    }
}


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

using namespace std;

int main() {
    
    int t;
    t=1;
    // cin >> t;
    while(t--){
        int n,k;
        cin >> n >> k;
        
        int arr[n];
        long long int dp[n];
        for(int i=0;i<n;i++){
            cin >> arr[i];
            dp[i] = LONG_MAX;
        }
        dp[0] = 0;
        dp[1] = abs(arr[1]-arr[0]);
        for(int i=2;i<n;i++){
            for(int j = i-1;j>=i-k&&j>=0;j--){
                dp[i] = min(dp[j]+abs(arr[i]-arr[j]),dp[i]);
            }
        }
        
        cout << dp[n-1] << endl;
    }
    return 0;

}

Measured memory_bytes: 1408
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.math;
import std.range;

void main()
{
    while(1)
    {
        auto mfr = readln.chomp.split.map!(to!int).array;
        if(mfr == [-1, -1, -1]) return;

        if(mfr[0 .. 2].count(-1)) writeln("F");
        else{
            int smf = reduce!"a+b"(0, mfr[0 .. 2]);
            if(smf >= 80) writeln("A");
            else if(smf >= 65 && smf < 80) writeln("B");
            else if(smf >= 50 && smf < 65) writeln("C");
            else if(smf >= 30 && smf < 50) writeln(mfr[2] >= 50 ? "C" : "D");
            else writeln("F");
        }
    }
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e-a <= k) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

int main()
{
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N, M; cin >> N >> M;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<P> CB(M);
    for (int i = 0; i < M; ++i){
        ll b, c; cin >> b >> c;
        CB[i] = {c, b};
    }
    sort(CB.begin(), CB.end(), greater<P>());

    ll sum = 0, K = 0;
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < CB[i].second; ++j) {
            if (K >= N){
                break;
            }
            sum += max(A[K++], CB[i].first);
        }
    }

    for (int i = K; i < N; ++i){
        sum += A[i];
    }
    
    cout << sum << endl;
    return 0;
}


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

int main()
{
	const int MaxVal = 2000000;
	int n = 0;
	int A[MaxVal] = { 0 };
	cin >> n;
	int maxTemp =0;
	int nextTemp = 0;
	int topIndex = 0;
	for (int i =0; i < n; ++i) {
		cin >> A[i];
		if (maxTemp < A[i]) {
			nextTemp = maxTemp;
			maxTemp = A[i];
			topIndex = i;
		} else {
			if (nextTemp < A[i]) {
				nextTemp = A[i];
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (i == topIndex) {
			cout << nextTemp << endl;
		} else {
			cout << maxTemp << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  long long N;
  long long M;
  cin >> N >> M;
  
  if(M == 0LL){
    cout << '0' << " " << '0' << endl;
  }
  else{
    vector<long long> s(M);
    vector<string> t(M);
    
    for(long long i = 0LL;i < M;++i){
      cin >> s[i] >> t[i];
    }
    
    vector<long long> a(N);
    vector<long long> b(N);
    
    for(long long i = 0LL;i < N;++i){
      a[i] = 0LL;
      b[i] = 0LL;
    }
   
    
    
    for(long long i = 0LL;i < M;++i){
      long long num = s[i] - 1LL;
      
      if(t[i][0] == 'A'){
        if(a[num] == 0LL){
          a[num] = 1LL;
        }
      }
      else{
        if(a[num] == 0LL){
          b[num] = b[num] + 1LL;
        }
      }
    }
    
    for(long long i = 0;i < N;++i){
      if(a[i] == 0){
        b[i] = 0;
      }
    }
    
    long long num3 = 0LL;
    
    long long num4 = 0LL;
    
    for(long long i = 0LL;i < N;++i){
      num3 = a[i] + num3;
      num4 = b[i] + num4;
    }
    
    cout << num3 << " " << num4 << endl;
    
  }
   
}





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

int main() {
  
  string S, T;
  cin >> S >> T;
  
  bool ans = false;
  for(int i=0; i<S.size(); i++){
    if(S==T){ ans = true; break; }
    S = S.back() + S.substr(0, S.size()-1);
  }
  if(ans){ cout << "Yes" << endl; }
  else{ cout << "No" << endl; }

}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007


int main()
{
	int n, x;
	cin >> n >> x;
	int a[101];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a + n);
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(x < a[i]) break;
		ans++;
		x -= a[i];
		if(i == n - 1 && x > 0) ans--;
	}
	cout << ans << endl;
}

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

int main(void){

  char input[] = "";

  scanf("%s\n", input);

  if (strcmp("Sunny",input)==0) {
    printf("Cloudy\n");
  }
  if (strcmp("Cloudy",input)==0) {
    printf("Rainy\n");
  }
  if (strcmp("Rainy",input)==0) {
      printf("Sunny\n");
  }
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

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

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

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

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

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve(){
    COMinit();

    ll N, K;
    cin >> N >> K;

    for (int i = 1; i <= K; i++) {
        cout << (COM(N-K+1, i) % MOD) * (COM(K-1, i-1) % MOD) % MOD << endl;
    }

    return;
}

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


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

string divi[4] = {"maerd", "remaerd", "esare", "resare"};

int main() {
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    int i = 0;
    bool ng;
    while (i < S.size()) {
        ng = true;
        rep(j, 4) {
            string d = divi[j];
            if (S.substr(i, d.size()) == d) {
                ng = false;
                i += d.size();
            }
        }
        if (ng) break;
    }
    cout << (ng ? "NO" : "YES") << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
  int A, B, T;
  scanf("%d %d %d", &A, &B, &T);
  int X = 0;
  for(int i = T; i >= 0; i -= A) {
    if(i >= A)
      X += B;
  }
  printf("%d\n", X);
  return 0;
}


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

using namespace std;

typedef pair<int, int> Pi;
typedef pair<int, Pi> Pii;

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

vector< vector<edge> > G(110);
int pbit[1<<8], pass[1<<8];

int N, M, H, K, S, T, P;

const int inf = (1 << 25);

int dijkstra(int bit)
{
  int minCost[110][25];
  fill(minCost[0], minCost[110], inf);
  priority_queue<Pii, vector<Pii>, greater<Pii> > que;
  que.push(Pii(0, Pi(S, 0)));
  minCost[S][0] = 0;
  while(!que.empty()){
    Pii p = que.top(); que.pop();
    int now = p.second.first, cost = p.first, hour = p.second.second;
    if(now == T) return cost;
    if(minCost[now][hour] < cost) continue;
    for(int i = 0; i < G[now].size(); i++){
      edge e = G[now][i];
      if(hour + e.hour > H) continue;
      if(((bit >> e.comp) & 1) && minCost[e.to][hour + e.hour] > cost){
	que.push(Pii(cost, Pi(e.to, hour + e.hour)));
	minCost[e.to][hour + e.hour] = cost;
      }
      if(minCost[e.to][hour + e.hour] > cost + e.cost){
	que.push(Pii(cost + e.cost, Pi(e.to, hour + e.hour)));
	minCost[e.to][hour + e.hour] = cost + e.cost;
      }
    }
  }
  return inf;
}

int main()
{
  while(cin >> N >> M >> H >> K, N || M || H || K){
    G.clear(); G.resize(N);
    for(int i = 0; i < M; i++){
      int a, b, c, h, r;
      cin >> a >> b >> c >> h >> r;
      --a, --b, --r;
      G[a].push_back(edge(b, c, h, r));
      G[b].push_back(edge(a, c, h, r));
    }
    cin >> S >> T;
    --S, --T;
    cin >> P;
    int dp[1<<8];
    fill(dp, dp + (1<<8), inf);
    memset(pbit, 0, sizeof(pbit));
    fill(pass, pass + (1<<8), inf);
    dp[0] = 0;
    for(int i = 0; i < P; i++){
      int l, d;
      cin >> l >> d;
      int bit = 0;
      for(int j = 0; j < l; j++){
	int k;
	cin >> k;
	--k;
	bit |= (1 << k);
      }
      pass[bit] = d;
      pbit[i] = bit;
    }
    for(int i = 0; i < (1<<K); i++){
      if(dp[i] == inf) continue;
      for(int j = 0; j < P; j++){
	if(pass[pbit[j]] == inf) continue;
	dp[i | pbit[j]] = min(dp[i | pbit[j]], dp[i] + pass[pbit[j]]);
      }
    }

    int ans = inf;
    for(int i = 0; i < (1<<K); i++){
      if(dp[i] == inf) continue;
      ans = min(ans, dp[i] + dijkstra(i));
    }
    cout << (ans >= inf ? -1 : ans) << endl;
  }
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  string a, b, c;
  a = "Sunny";
  b = "Cloudy";
  c = "Rainy";
  if(S == a){
    cout << b <<endl;
  }else if(S == b){
    cout << c <<endl;
  }else{
    cout << a << endl;
  }
  return 0;
}

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

const int N = 1 << 12;
int d[2 * N];
string r[N];

int mx(int a, int b) {
	a += N;
	b += N;

	int mx = 0;
	while (a <= b) {
		if (a % 2 == 1) mx = max(mx, d[a++]);
		if (b % 2 == 0) mx = max(mx, d[b--]);
		a /= 2;
		b /= 2;
	}
	if (mx == 0) return -1;
	if (mx == 1 && d[N] == 1) return 0;
	a = 1;
	while (1) {
		if (a-N >= 0) return a-N;
		if (d[a*2] >= mx) a *= 2;
		else a = a * 2 + 1;
	}
}

void change(int x, int k) {
	x += N;
	if (d[x] >= k) return;
	d[x] = k;
	for (x /= 2; x >= 1; x /= 2) d[x] = max(d[x*2], d[x*2+1]);
}

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

	string a, b;
	cin >> a >> b;

	int n = a.length(), m = b.length();

	set<pair<char, int>> inx;
	for (int i = 0; i < m; ++i) inx.insert({b[i], -i});

	for (int i = 0; i < n; ++i) {
		char c = a[i];
		for (auto it = inx.lower_bound({c, -1e9}); it != inx.end(); ++it) {
			if (it -> first != c) break;
			int x = -it -> second;

			if (r[x].length() == 0) r[x] = c;
			int z = mx(0, x-1);
			if (z > -1 && r[x].length() < r[z].length() + 1) r[x] = r[z] + c;
			change(x, r[x].length());
		}
	}
	string rs = "";
	for (int i = 0; i < N; ++i) {
		if (r[i].length() > rs.length()) rs = r[i];
	}
	cout << rs << '\n';
}


Measured memory_bytes: 14720
#include "bits/stdc++.h"
//#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

signed main(){
	int n, m;
	cin >> n >> m;
	int v[n], w[n];
	rep(i, n)cin >> v[i] >> w[i];

	int va[m + 1];
	memset(va, -1, sizeof(va));
	va[0] = 0;

	rep(i, n){
		for(int j = m; j >= 0; j--){
			if(va[j] == -1)continue;
			if(j + w[i] > m)continue;
			va[j + w[i]] = max(va[j + w[i]], va[j] + v[i]);
		}
	}

	int ans = -INF;
	rep(i, m + 1)ans = max(ans, va[i]);

	cout << ans << endl;
}

Measured memory_bytes: 3132
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int q(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int main(void) {
  int n;
  scanf("%d",&n);
  PRN(n*32);
  return 0;
}


Measured memory_bytes: 2140
# -*- coding: utf-8 -*-
"""
C - Modulo Summation
https://beta.atcoder.jp/contests/abc103/tasks/abc103_c

"""
import sys
from sys import stdin
input = stdin.readline


from fractions import gcd

def solve(arr):
    def calc_sum(m, arr):
        return sum([m%a for a in arr])

    def calc_lcm(arr):
        t = arr[0]
        for a in arr[1:]:
            t = t * a // gcd(t, a)
        return t

    lcm = calc_lcm(arr)
    return calc_sum(lcm-1, arr)


def main(args):
    N = int(input())
    arr = [int(a) for a in input().split()]
    ans = solve(arr)
    print(ans)


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


Measured memory_bytes: 5716
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

bool ok(const vecint& a, const int th, vecint& v) {
  ll n = a.size();
  v.assign(n*3, 0);
  int offset = n*1.5;
  ll cnt = 0;
  ll sum = 0;
  REP(i,n) {
    v[offset] += 1;
    if (a[i] >= th) {
      offset -= 1;
      sum -= v[offset];
    } else {
      sum += v[offset];
      offset += 1;
    }
    cnt += sum;
  }
  ll m = n * (n+1) / 2;
  ll mid = m/2 + 1;
  return cnt >= mid;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vecint a(n);
  string line;
  getline(cin, line);
  getline(cin, line);
  int i = 0;
  int num = 0;
  for (char c : line) {
    if ('0' <= c && c <= '9') {
      num *= 10;
      num += c - '0';
    } else {
      a[i] = num;
      ++i;
      num = 0;
    }
  }
  a[i] = num;
  vecint b = a;
  b.push_back(0);
  b.push_back(1000000007);
  sort(ALL(b));
  b.erase(unique(ALL(b)), end(b));
  int hi = b.size() - 1;
  int lo = 0;
  vecint v(n*4);
  while ((hi - lo) > 1) {
    int mid = (hi + lo) / 2;
    if (ok(a, b[mid], v)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout<<b[lo]<<endl;
  return 0;
}


Measured memory_bytes: 4124
#include<stdio.h>
int main(){
	int i;
	int pl[5];
	int aiko[3];
	for(;;){
		scanf("%d",&pl[0]);
		if(pl[0]==0)break;
		if(pl[0]==1)aiko[0]=1;
		if(pl[0]==2)aiko[1]=1;
		if(pl[0]==3)aiko[2]=1;
		for(i=1;i<5;i++){
			scanf("%d",&pl[i]);
			if(pl[i]==1)aiko[0]=1;
			if(pl[i]==2)aiko[1]=1;
			if(pl[i]==3)aiko[2]=1;
		}
		if(pl[0]==pl[1] &&  pl[1]==pl[2] &&  pl[2]==pl[3] &&  pl[3]==pl[4]){
			for(i=0;i<5;i++){
				pl[i]=3;
			}
		}
		else if(aiko[0]==1 && aiko[1]==1 && aiko[2]==1){
			for(i=0;i<5;i++){
				pl[i]=3;
			}
		}
		
		else if(aiko[0]==1 && aiko[1]==1 && aiko[2]==0){
			for(i=0;i<5;i++){
				if(pl[i]==1)pl[i]=1;
				if(pl[i]==2)pl[i]=2;
			}
		}
		else if(aiko[0]==0 && aiko[1]==1 && aiko[2]==1){
			for(i=0;i<5;i++){
				if(pl[i]==2)pl[i]=1;
				if(pl[i]==3)pl[i]=2;
			}
		}
		else if(aiko[0]==1 && aiko[1]==0 && aiko[2]==1){
			for(i=0;i<5;i++){
				if(pl[i]==1)pl[i]=2;
				if(pl[i]==3)pl[i]=1;
			}
		}
		for(i=0;i<5;i++){
			printf("%d\n",pl[i]);
		}
		for(i=0;i<3;i++)aiko[i]=0;
	}
	return 0;
}

Measured memory_bytes: 0
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
D=[[A[i]-B[i],i] for i in range(N)]
D.sort()
s=0
for i in range(N):
  if D[i][0]<0:
    s+=D[i][0]
    D[i][0]=0
  elif D[i][0]>=0:
    break
for i in range(N)[::-1]:
  if s+D[i][0]<0:
    s+=D[i][0]
    D[i][0]=0
  else:
    D[i][0]+=s
    s=0
    break
if s!=0:
  print(-1)
  exit()
C=[""]*N
ans=0
for i in range(N):
  C[D[i][1]]=D[i][0]+B[D[i][1]]
  if C[D[i][1]]!=A[D[i][1]]:
    ans+=1
print(ans)

  


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

typedef long long LL;

const int N = 5005;
const LL INF = 0x3f3f3f3f3f3f3f3f;

int n, k, p[N];
LL cost[N], ans = -INF;
bool vis[N];

vector <LL> S;

void dfs(int pos, LL sum){
    if (vis[pos]) return;

    vis[pos] = true;
    sum += cost[pos];
    S.push_back(sum);

    dfs(p[pos], sum);
}

int main(){
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &p[i]), p[i]--;
    for (int i = 0; i < n; i++) scanf("%lld", &cost[i]);

    for (int i = 0; i < n; i++){
        S.clear();
        memset(vis, false, sizeof(vis));
        dfs(i, 0);

        if (S.back() > 0 && k >= S.size()){
            int q = k / S.size();

            if (q >= 1){             // q - 1
                LL mx = -INF;
                if (q - 1 > 0) mx = 0;
                
                for (int i = 0; i < S.size(); i++) mx = max(mx, S[i]);
                ans = max(ans, (q - 1) * S.back() + mx);
            }

            LL mx = 0;
            for (int i = 0; i < k % S.size(); i++) mx = max(mx, S[i]);
            ans = max(ans, q * S.back() + mx);
        } else for (int i = 0; i < min(k, (int)S.size()); i++) ans = max(ans, S[i]);
    }

    printf("%lld\n", ans);
    
    return 0;
}

Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> L;
  int l;
  for (int i = 0; i < N; i++){
    cin >> l;
    L.push_back(l);
  }
  L.push_back(10000);
  sort(L.begin(),L.end());
  int count = 0;
  for (int i = 0; i < N; i++){
    for (int j = i+1; j < N; j++){
      int minlen = L[j]-L[i];
      int maxlen = L[j]+L[i];
      //Binary search 1
      int A = 0;
      int B = N+1;
      while (B-A>1){
        if (L[(A+B)/2]>minlen){
          B=(A+B)/2;
        } else {
          A=(A+B)/2;
        }
      }
      int min = max(B,j);
      //Binary search 2
      int C = 0;
      int D = N+1;
      while (D-C>1){
        if (L[(C+D)/2]<maxlen){
          C=(C+D)/2;
        } else {
          D=(C+D)/2;
        }
      }
      int max = C;
      count += (max-min);
    }
  }
  cout << count;
}

Measured memory_bytes: 256
#include<list>
#include<string>
#include<iostream>

using namespace std;

int main()
{
	list<int> lst;
	double obj;
	
	int n;
	string command;
	cin >> n;
	while(n--)
	{
		cin >> command;
		if(command[0] == 'i')
		{
			cin >> obj;	
			lst.push_front(obj);
		}
		else if(command[0] == 'd')
			{
				if(command[6]=='F')
					lst.pop_front();
				else if(command[6]=='L')
					lst.pop_back();
				else
				{
					cin >> obj;
					for(list<int>::iterator i = lst.begin(); i!=lst.end(); i++)
					{
						if(obj == *i)
							{lst.erase(i);break;}				
					}
				}			
			}


	}
	int sk = 0;
	for(list<int>::const_iterator i = lst.begin(); i!=lst.end(); i++)
	{
	if(sk++) 
			cout << " ";
	cout <<	*i;	
	}
	cout << endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L, R;
  
  L = A + B;
  R = C + D;
  
  if (L > R) {
    cout << "Left" << endl;
  } else if (L == R) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  string S;
  string R = "test";
  for (int i = 0; i < N; i++) {
    cin >> S;
    R+=S;
  }
  if (R.find("P") == string::npos || R.find("W") == string::npos || R.find("G") == string::npos || R.find("Y") == string::npos) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
n=int(input())
a=sorted(list(map(int,input().split())))
i=a[1]
while i > 0:
  flg=0
  for j in a:
    if j%i!=0:
      flg+=1
      if flg>1:
        break
  if flg<=1:
    print(i)
    break
  else:
    i-=1

Measured memory_bytes: 14584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();
            int c = Integer.parseInt(Integer.toString(a).concat(Integer.toString(b)));
            int root = (int) Math.sqrt((double) c);
            out.println(root * root == c ? "Yes" : "No");
        }

    }
}



Measured memory_bytes: 20948
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int

struct edge
{
  int to, cost;
};
typedef std::vector<std::vector<edge>> graph;
const ll MOD = 1000000007;
using namespace std;

int main()
{
  int n;
  cin >> n;
  int a[100];
  REP(i, n)
  {
    cin >> a[i];
  }
  int al = 0, bo = 0;
  sort(a, a + n, greater<int>());

  REP(i, n)
  {
    if (i % 2 == 0)
    {
      al += a[i];
    }
    else
    {
      bo += a[i];
    }
  }

  cout << al - bo << endl;
}


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

using namespace std;
const int MAXHW = 2001;

int memo[MAXHW][MAXHW][4];
char matrix[MAXHW][MAXHW];
// 0 dx 1 sx 2 down 3 up
int moves[][2] = {{0,1}, {0,-1}, {1,0},{-1,0}};
int H,W;

int dp(int r,int c, int dir){
	if(r < 0 || r >= H)return 0;
	if(c < 0 || c >= W)return 0;
	if(memo[r][c][dir] != -1)return memo[r][c][dir];
	if(matrix[r][c] == '#')return 0;
	return memo[r][c][dir] = 1 + dp(r + moves[dir][0], c + moves[dir][1],dir);  
}

int main(){
	#ifdef EVAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> matrix[i][j];
		}
	}
	memset(memo,-1,sizeof(memo));
	int ans = 0;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(matrix[i][j] == '#')continue;
			ans = max(ans,dp(i,j,0) + dp(i,j,1) + dp(i,j,2) + dp(i,j,3));
		}
	}
	cout << ans - 3;
	return 0;
}

Measured memory_bytes: 66688
import sys
from math import ceil
input=sys.stdin.readline
_lii=lambda :list(map(int, input().strip('\n').split()))
_i=lambda :input().strip('\n')
res=[]
#for _ in range(int(input())):
n=int(input())
print(int(ceil(n/1000))*1000-n)
	#res.append(ans)
#print('\n'.join(map(str, res)))

Measured memory_bytes: 9000
#include <bits/stdc++.h>
#define fin freopen("input", "r", stdin);
#define fout freopen("output", "w", stdout);
#define wt(x) cerr << #x << ": " << x << " ";
#define whatis(x) {cerr << #x << ": " << x << endl;}
#define whatis2(x, y) {wt(x); wt(y); cerr << endl;}
#define whatis3(x, y, z) {wt(x); wt(y); wt(z); cerr << endl;}
#define whatis4(x, y, z, a) {wt(x); wt(y); wt(z); wt(a); cerr << endl;}
using namespace std;

typedef long long ll; typedef unsigned long long ull; typedef long double ld;
const ll MOD = 1000000007; const ld PI = acos(-1.0);

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

    
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;


    return 0;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int sum(0);
  for(int i1 = 0; i1 <= 9; i1++)
  {
    for(int i2 = 0; i2 <= 9; i2++)
    {
      for(int i3 = 0; i3 <= 9; i3++)
      {
        for(int i4 = 0; i4 <= 9; i4++)
        {
          const int sumd = i1 + i2 + i3 + i4;
          if( A <=sumd && sumd <= B && sumd != 0)
          {
            const int num = 1000 * i1 + 100 * i2 + 10 * i3 + i4;
            if( num <= N )
            {
              sum += num;
            }
          }
        } 
      } 
    }
  }
  if( A <= 1 && 1 <= B && 10000 <= N ) sum += 10000;
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int prime(int);
void bubbleSort(int *,int);

int main(){
  int i,j,k,l,m,n;
  int N,P;
  int count=0;
  int ans[200000];
  int res[101000];
  
  while(1){
    i=1;
    j=0;
    count=0;
  
    scanf("%d %d",&N,&P);
    if(N==-1&&P==-1) break;

    while(1){
      if(j>=P) break;
      if(prime(N+i)==1){
	ans[j]=N+i;
	j++;
      }
      i++;
    }
    
    for(k=0;k<j;k++){
      for(l=k;l<j;l++){
	res[count]=ans[k]+ans[l];
	count++;
      }
    }
    
    bubbleSort(res,count);
    // for(i=0;i<count;i++)printf("%d\n",res[i]);
    printf("%d\n",res[P-1]);
  } 
  
  return 0;
}

int prime(int x){
  int i=3;

  if(x==2) return 1;

  if(x%2==0||x<2) return 0;

  while(i<=sqrt(x)){
    if(x%i==0) return 0;
    i+=2;
  }

  return 1;
}

void bubbleSort(int A[],int N){
  int i=0,j;
  int sw;
  int flag=1;

  while(flag){
    flag=0;
    for(j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	sw=A[j];
	A[j]=A[j-1];
	A[j-1]=sw;
	flag=1;
      }
    }
  }
}

Measured memory_bytes: 628
s = input()

left_days_next_sunday = {
    'SUN': 7,
    'MON': 6,
    'TUE': 5,
    'WED': 4,
    'THU': 3,
    'FRI': 2,
    'SAT': 1,
}

print(left_days_next_sunday[s])

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

int main()
{
	int N, Q, l, r;
	int ans = 0;
	cin >> N >> Q;

	char str[100000 + 3] = {};
	int dp[100000 + 1] = {};
	for (int i = 0; i < N; i++) {
		if (i > 0 && dp[i - 1] != 0)dp[i] = dp[i - 1];
		cin >> str[i];
		if (str[i] == 'C'&&str[i - 1] == 'A')dp[i] = dp[i] + 1;
	}
	str[N + 1] = '\0';

	for (int i = 0; i < Q; i++) {
		ans = 0;
		cin >> l >> r;
		
		ans = dp[(r - 1)] - dp[(l - 1)];
		cout << ans << endl;

	}
	
	return 0;
}

Measured memory_bytes: 1280