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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0)  )
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}




int main() {
    READ(0);
    int n;
    ll d,a;
    cin>>n>>d>>a;
    vector<ii> x(n);
    FOR(i,n) cin>>x[i].first>>x[i].second;
    sort(x.begin(),x.end());
    int idx=0;
    ll bombs=0;
    set<pair<ll,ll>,greater<pair<ll,ll>>> hh;
    ll acum=0;
    while(idx<n){
        while (!hh.empty() && hh.rbegin()->first<x[idx].first){
            acum -= hh.rbegin()->second;
            hh.erase(--hh.end());
        }
        if (acum>=x[idx].second){++idx;continue;}
        int b = (x[idx].second-acum)/a + ((x[idx].second-acum)%a != 0);
        bombs += b;
        ll pos = (ll)x[idx].first+d*2;
        if (pos<x[n-1].first)
            hh.emplace(pos,a*b);
        acum += a*b;
        ++idx;
    }
    cout << bombs;


}



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

int main() {
  int N, l, r, a = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
	a += r - l + 1;
  }
  cout << a << endl;
}


Measured memory_bytes: 3576
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for l in range(A + 1):
    for m in range(B + 1):
        for n in range(C + 1):
            if 500 * l + 100 * m + 50 * n == X:
                count += 1
print(count) 

Measured memory_bytes: 3188
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

X = ri()
print(1 if X >= 1800 else 2 if X >= 1600 else 3 if X >= 1400 else 4 if X >= 1200 else 5 if X >= 1000 else 6 if X >= 800 else 7 if X >= 600 else 8)

Measured memory_bytes: 9184
#include<iostream>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int L, R; std::cin >> L >> R;
  if(R - L >= 2018) fin(0);
  int ans = 2019;
  for(int i = L; i < R; ++i) for(int j = i+1; j <= R; ++j) {
    ans = std::min(ans, ((i%2019)*(j%2019))%2019);
  }
  fin(ans);
  return 0;
}


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

#define ll long long int

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int n=s1.size();
    int m=s2.size();
    
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    string ans="";
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s1[i-1]==s2[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=n,j=m;
    if(dp[n][m]==0)
    {
        cout<<ans<<endl;
        return 0;
    }
    while(i>0 && j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
            ans=s1[i-1]+ans;
            i--; j--;
        }
        else
        {
            if(dp[i][j-1]>=dp[i-1][j])
                j--;
            else
                i--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 38956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

int main()
{	
    int x, n;
    cin >> x >> n;
    set<int> s;
    REP(i, n){
        int a;
        cin >> a;
        s.insert(a);
    }
    set<int> notp;
    REP(i, 103) notp.insert(i-1);
    REP(i, n) {
        notp.erase(*begin(s));
        s.erase(*begin(s));
    }

    int sub = INF;
    int tmp = x;
    int size = notp.size();
    REP(i, size){
        if(sub > abs(x-*begin(notp))){
            sub = abs(x-*begin(notp));
            tmp = *begin(notp);
        }
        notp.erase(*begin(notp));
    }
    cout << tmp << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int n, A[2][MX];
int son[2][MX];
int rt[2];
int ans[MX];
vector<int> G[2][MX], H[MX];

void NOPE(){
    cout<<"IMPOSSIBLE";
    exit(0);
}

void add_edge(int x, int y){
    H[x].push_back(y);
    H[y].push_back(x);
}

int dfs1(int t, int v){
    int now = (son[t][v]%2!=0 ? -1 : v);
    for(int x:G[t][v]){
        int y=dfs1(t,x);
        if(y>0){
            if(now>0) add_edge(now, y), now=-1;
            else now=y;
        }
    }
    return now;
}

void dfs2(int v, int c=1){
    ans[v]=c;
    for(int x:H[v])
        if(ans[x]==0) dfs2(x,-c);
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int j=0; j<2; j++)
        for(int i=1; i<=n; i++){
            cin>>A[j][i];
            if(A[j][i]<0) rt[j]=i;
            else G[j][A[j][i]].push_back(i), son[j][A[j][i]]++;
        }
    for(int i=1; i<=n; i++){
        if(son[0][i]%2!=son[1][i]%2) NOPE();
    }
    dfs1(0, rt[0]);
    dfs1(1, rt[1]);

    for(int i=1; i<=n; i++)
        if(ans[i]==0 && son[0][i]%2==0) dfs2(i,1);
    
    cout<<"POSSIBLE\n";
    for(int i=1; i<=n; i++) cout<<ans[i]<<' ';
    cout<<'\n';

    return 0;
}

Measured memory_bytes: 16896
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Solve{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var P = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var Q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int a = 1, b = 1;
        var set = new HashSet<int>();
        for (int i = 0; i < N; i++){
            var pi = P[i];
            int count = 0;
            if(set.Any())
                foreach (var s in set){
                    if (s < pi) count++;}
            var x = pi - count;
            a += (x - 1) * Factorial(N - 1 - i);
            set.Add(pi);}
        set.Clear();
        for (int i = 0; i < N; i++){
            var qi = Q[i];
            int count = 0;
            if (set.Any())
                foreach (var s in set){
                    if (s < qi) count++;}
            var x = qi - count;
            b += (x - 1) * Factorial(N - 1 - i);
            set.Add(qi);}
        var answer = Math.Abs(a - b);
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}

    public static int Factorial(int n){
        int result = 1;
        for (int i = n; i > 1; i--){
            result *= i;}
        return result;}}

Measured memory_bytes: 28236
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
vector<int> x = {1,-1,0,0};
vector<int> y = {0,0,-1,1};
int main(){
    string s;
    cin >> s;
    string head,tail;
    string ans = "keyence";
    head = s.substr(0,7);
    tail = s.substr(s.size()-7);
    string a,b,c,d,e,f;
    a = s.substr(0,1)+s.substr(s.size()-6);
    b = s.substr(0,2)+s.substr(s.size()-5);
    c = s.substr(0,3)+s.substr(s.size()-4);
    d = s.substr(0,4)+s.substr(s.size()-3);
    e = s.substr(0,5)+s.substr(s.size()-2);
    f = s.substr(0,6)+s.substr(s.size()-1);
    if(a==ans||b==ans||c==ans||d==ans||e==ans||f==ans||head==ans||tail==ans){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    

  return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, C; cin >> N >> C;

    //入力
    vector<pi > input;

    for(ll i = 0; i < N; i++){
        ll x, v; cin >> x >> v;
        input.push_back(make_pair(x, v));
    } 

    //時計回り累積和と最大値
    //コストの累積ワと距離を記憶
    vector<pi > sum(N + 1);
    vector<ll > mx(N + 1, 0);

    ll tmp = -INF;
    //現在地
    sum[0].first = 0; sum[0].second = 0;
    mx[0] = 0; 
    for(ll i = 1; i <= N; i++){
        ll x = input[i - 1].first;
        ll v = input[i - 1].second;
        if(i == 1){
            sum[i].first = v - x;
            sum[i].second = x;
        }else{
            //進んだ距離(x - sum[i-1].second)
            sum[i].first = sum[i-1].first + (v - (x - sum[i-1].second));
            sum[i].second = x;
        }
        
        ll m = max(sum[i].first, tmp);
        mx[i] = m;
        tmp = m;

    }

    //反時計回り累積和と最大値
    vector<pi > r_sum(N+1);
    vector<ll > r_mx(N+1, 0);

    ll idx = 1;
    tmp = -INF;
    //現在地
    r_sum[0].first = 0; r_sum[0].second = 0;
    r_mx[0] = 0; 
    for(ll i = N - 1; i >= 0; i--){
        ll x = C - input[i].first;
        ll v = input[i].second;
        if(i == N - 1){
            r_sum[idx].first = v - x;
            r_sum[idx].second = x;
        }else{
            //(x-r_sum[idx-1].second)進んだ距離
            r_sum[idx].first = r_sum[idx-1].first + (v - (x-r_sum[idx-1].second));
            r_sum[idx].second = x;
        }
        
        ll m = max(r_sum[idx].first, tmp);
        r_mx[idx] = m;
        tmp = m;
        idx++;
    }

    //確認
    
    /*
    for(ll i = 0; i <= N; i++){
        cout << sum[i].first << " " << sum[i].second << " " << mx[i] << endl;
    } 
    */ 
    /*
    for(ll i = 0; i <= N; i++){
        cout << r_sum[i].first << " " << r_sum[i].second << " " << r_mx[i] << endl;
    }
    */
    

    //時計回りで全探査
    //あるところで折り返して反対時計回りに寿司をとっていった時どこが最大か
    //折り返さなくて最大のときもある

    ll ans = -INF;

    for(ll i = 0; i <= N; i++){
        //寿司を時計回りに食べるだけ食べて折り返さずに退店するとき
        ll not_turn = sum[i].first;

        //cout << not_turn << endl;

        //折り返して反対側へ寿司を食べに行く時
        //コスト-折返し距離
        ll turn = sum[i].first - sum[i].second;
        ll idx = N - i;
        //cout << r_mx[idx] << endl;
        turn += r_mx[idx];
        
        ans = max(ans, turn);
        ans = max(ans, not_turn);
    }

    //反時計回りで全探査
    for(ll i = 0; i <= N; i++){
        //寿司を反時計回りに食べるだけ食べて折り返さずに退店するとき
        ll not_turn = r_sum[i].first;

        //cout << not_turn << endl;

        //折り返して反対側へ寿司を食べに行く時
        //コスト-折返し距離
        ll turn = r_sum[i].first - r_sum[i].second;
        ll idx = N - i;
        //cout << mx[idx] << endl;
        turn += mx[idx];
        
        ans = max(ans, turn);
        ans = max(ans, not_turn);
    }

    cout << ans << endl;

}

Measured memory_bytes: 6512
/*
[abc136] E - Max GCD
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 500;

int N, K;
int A[MAX_N];

bool can(int m) {
    int r[MAX_N];
    for (int i = 0; i < N; i++) {
        r[i] = A[i] % m;
    }
    sort(r, r + N);

    int rs[MAX_N + 1];
    rs[0] = 0;
    for (int i = 0; i < N; i++) {
        rs[i + 1] = rs[i] + r[i];
    }

    for (int i = 0; i <= N; i++) {
        if (max((ll)rs[i], (ll)m * (N - i) - (rs[N] - rs[i])) <= K) {
            return true;
        }
    }
    return false;
}

ll solve() {
    int s = 0;
    for (int i = 0; i < N; i++) {
        s += A[i];
    }

    int ans = 1;
    for (int i = 1; i * i <= s; i++) {
        if (s % i == 0) {
            if (can(i)) {
                ans = max(ans, i);
            }
            if (can(s / i)) {
                ans = max(ans, s / i);
            }
        }
    }

    return ans;
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
 
namespace Sample
{
  static class Sample
  {
    static void Main()
    {
            int a = int.Parse(Console.ReadLine());
            if(a == 0){
              Console.WriteLine(1);
            }else{
              Console.WriteLine(0);
            }
            
    }
  }
}

Measured memory_bytes: 27380
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        ArrayList<Integer> al = new ArrayList<>();
        ArrayList<Integer> bl = new ArrayList<>();
        ArrayList<Integer> cl = new ArrayList<>();
        for(int i = 0; i < a; i++){
            al.add(sc.nextInt());
        }
        Collections.sort(al, Comparator.reverseOrder());
        for(int i = 0; i < b; i++){
            bl.add(sc.nextInt());
        }
        Collections.sort(bl, Comparator.reverseOrder());
        for(int i = 0; i < c; i++){
            cl.add(sc.nextInt());
        }
        List<Integer> sub = al.subList(0,x);
        List<Integer> sub2 = bl.subList(0,y);
        sub.addAll(sub2);
        sub.addAll(cl);
        Collections.sort(sub, Comparator.reverseOrder());
        long ans = 0;
        int maxi = x+y;
        for(int i = 0; i < maxi; i++){
            ans += sub.get(i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 100004
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int A,B;
	cin>>A>>B;
	if(A<=8&&B<=8)cout<<"Yay!";
	else cout<<":(";
}

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


long rec(long h){
    if(h==1){
        return 1;
    }
    if(h%2==1){
        return rec((h-1)/2)*2+1;
    }else{
        return rec(h/2)*2+1;
    }
}

int main(){
    // あとで消す
    //std::ifstream in("din3.txt");
    //std::cin.rdbuf(in.rdbuf());

    long H;
    cin >> H;

    cout << rec(H) <<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  string c;
  cin >> a >> b;
  string heightLine = "";
  
  for (int i = 0; i < b + 2 ; i++) {
    heightLine.push_back('#');
  }
  cout << heightLine << endl;
  for (int i = 0; i < a; i++) {
      cin >> c;
      cout << '#' + c + '#' << endl;
  }
  cout << heightLine << endl;
}

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b == c + d)
		cout << "Balanced" << endl;
	else if (a + b < c + d)
		cout << "Right" << endl;
	else
		cout << "Left" << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    if(a[0]+a[1]+a[2]>=22)cout<<"bust\n";
    else cout<<"win\n";
}

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

int A, B, C, X;

int main(){
  cin >> A >> B >> C >> X;
 
  int res = 0;
  
  for(int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
      for(int k = 0; k <= C; k++){
        if(X == 500 * i + 100 * j + 50 * k){
          res ++;
        }
      }
    }
  }
  
  cout << res << endl;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int x, a, b;
    cin >> x >> a >> b;
    
    if(a-b >= 0) {
        cout << "delicious";
    } else {
        if(b-a <= x) {
            cout << "safe";
        } else {
            cout << "dangerous";
        }
    }

    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

char plus_one(char c, int r,int lim){
  if(r==lim)return c;
  if(c=='Z'){
    return plus_one('A',r+1,lim);
  }else{
    return plus_one(c+1,r+1,lim);
  }
}

int main() {
  int n;
  string s;
  string::iterator it;
  cin >>n>>s;
  for(it=s.begin();it!=s.end();it++){
    *it=plus_one(*it,0,n);
  }
  cout<<s<<endl;
}


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

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

    string S;
    int Q;
    cin >> S >> Q;

    vector<char> V(700000);
    int l = 300000;
    int r = l + S.size() - 1;
    for (int i = 0; i < S.size(); ++i) {
        V.at(l + i) = S.at(i);
    }
    int fr = 1;

    while (Q--) {
        int T;
        cin >> T;
        if (T == 1) {
            fr ^= 1;
        } else {
            int F;
            char C;
            cin >> F >> C;
            if (F == 1) {
                V.at((fr) ? --l : ++r) = C;
            } else {
                V.at((fr) ? ++r : --l) = C;
            }
        }
    }

    if (fr) {
        for (int i = l; i <= r; ++i) {
            cout << V.at(i);
        }
    } else {
        for (int i = r; i >= l; --i) {
            cout << V.at(i);
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1488
S = input()
Q = int(input())
top = ''
end = ''
reverse_flag = 1
for _ in range(Q):
    query = input()
    if query == '1':
        reverse_flag *= -1
    else:
        _, F, C = query.split()
        if (int(F)-1.5) * reverse_flag > 0:
            end += C
        else:
            top += C
ans = top[::-1] + S + end
if reverse_flag == 1:
    print(ans)
else:
    print(ans[::-1])

Measured memory_bytes: 4596
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int x, y, z; cin >> x >> y >> z;
  x -= z;
  outl(x / (y + z));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 760
#include<bits/stdc++.h> 
int main(){
    int D,G,i,j,t,score,slvs,ans=1000000000;
    scanf("%d%d",&D,&G);
    int p[D],c[D];
    for(i=0;i<D;i++)scanf("%d%d",&p[i],&c[i]);
    for(i=0;i<(1<<D);i++){
        score=0,slvs=0;
        for(j=0;j<D;j++)
            if(i&(1<<j))score+=100*(j+1)*p[j]+c[j],slvs+=p[j];
            else t=j;
        for(j=0;j<p[t]&&score<G;j++,score+=100*(t+1),slvs++);
        if(score>=G)ans=std::min(ans,slvs);
    }
    printf("%d\n",ans);
}  

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii tms;
int dp[2][MAX_N + 1];

/* subroutines */

/* main */

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

  tms.clear();
  
  for (int i = 0; i < n; i++) {
    int ai, bi;
    cin >> ai >> bi;
    if (ai <= bi) tms.push_back(pii(bi, ai));
  }
  sort(tms.begin(), tms.end());
  n = tms.size();
  //cout << tms.size() << endl;

  int cur = 0, nxt = 1;
  for (int i = 0; i <= n; i++) dp[cur][i] = INF;
  dp[cur][0] = 0;

  for (int i = 0; i < n; i++) {
    int& ai = tms[i].second;
    int& bi = tms[i].first;

    memcpy(dp[nxt], dp[cur], sizeof(int) * (n + 1));

    for (int j = 0; j <= i; j++)
      if (dp[cur][j] < INF) {
	int d = dp[cur][j] + ai;
	if (d <= bi && dp[nxt][j + 1] > d) dp[nxt][j + 1] = d;
      }

    cur ^= 1, nxt ^= 1;
  }

  int maxi = 0;
  for (int i = 0; i <= n; i++)
    if (dp[cur][i] < INF) maxi = i;

  cout << maxi << endl;
  
  return 0;
}

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

int main()
{
	string s;
	cin >> s;
	string t = s;
	int n = s.size();
	if(s.size()==26)
	{
		if(next_permutation(s.begin(),s.end()))
		{
			for(int i = 0;i<n;i++)
			{
				if(s[i]==t[i])cout<<t[i];
				else
				{
					cout<<s[i];
					cout<<endl;
					return 0;
				}
			}
		}
		else
		{
			cout<<-1<<endl;
		}
	}
	else
	{
		vector<bool> v(26);
		for(auto c:s)v[c-'a']=true;
		cout<<s;
		for(int i = 0;i<26;i++)
		{
			if(v[i]==false)
			{
				cout<<(char)('a'+i)<<endl;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int P[214514];
int app[214514];
LL dp[214514];

int main() {
  scanf("%d", &N);

  fill(app, app+214000, -1);
  rep(i, N) {
    int c;
    scanf("%d", &c);
    P[i] = app[c];
    app[c] = i;
  }

  dp[0] = 1;
  rep(i, N) {
    dp[i] += dp[i-1];
    if (P[i] != -1 && P[i]+1 != i) {
      dp[i] += dp[P[i]];
    }
    dp[i] %= MOD;
  }
  printf("%lld\n", dp[N-1]);
}


Measured memory_bytes: 3456
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  s <- C.getLine
  let r = C.reverse s
  if isIn' r
    then putStrLn "YES"
    else putStrLn "NO"

rDream, rDreamer, rErase, rEraser :: C.ByteString
rDream   = C.reverse . C.pack $ "dream"
rDreamer = C.reverse . C.pack $ "dreamer"
rErase   = C.reverse . C.pack $ "erase"
rEraser  = C.reverse . C.pack $ "eraser"

isIn' :: C.ByteString -> Bool
isIn' s
  | C.null s = True
  | rDreamer `C.isPrefixOf` s = helper rDreamer s
  | rDream   `C.isPrefixOf` s = helper rDream   s
  | rEraser  `C.isPrefixOf` s = helper rEraser  s
  | rErase   `C.isPrefixOf` s = helper rErase   s
  | otherwise = False
  where
    helper rS = isIn' . C.drop (C.length rS) 

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
LL facctorialMethod(int k);
int main(){
    LL n, m, sum=0, cnt=0, ans;
    cin >> n >> m;
    vector<LL> a(m);

    for(int i = 0; i < m; i++) {
        cin >> a[i];
        sum += a[i];
        cnt++;
    }
    if(n >= sum) {
        ans = n-sum;
        cout << ans << endl;
    }else{
        cout << "-1" << endl;
    }

    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


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

#define eb emplace_back
#define pb push_back
#define INF LLONG_MAX
#define FLT_INF pow(10.0, 16)


using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<ll, ll>;
using int3 = tuple<ll, ll, ll>;

template <typename A> string to_string(const A& v);
string to_string(const string& s) { return '"'+ s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(const pair<A, B>& p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C> string to_string(const tuple<A, B, C>& p) {
  return "(" + to_string(std::get<0>(p)) + ", " + to_string(std::get<1>(p)) +  ", " + to_string(std::get<2>(p)) + ")";
}

template <typename A> string to_string(const A& v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T>
void sort(vector<T>& val) {
  sort(val.begin(), val.end());
}

template <typename T>
void reverse(vector<T>& val) {
  reverse(val.begin(), val.end());
}

template <typename T>
void sort_b(vector<T>& val) {
  sort(val.begin(), val.end(), greater<T>());
}

template <typename T>
T pair_sum(pair<T, T>& val) {
  return val.first + val.second;
}


template <typename T>
T min(T a, T b, T c) {
  return min(min(a, b), c);
}

template <typename T>
T max(T a, T b, T c) {
  return max(max(a, b), c);
}


template <typename T>
T mul_mod(T a, T b, T mod) {
  T res = 0;
  a %= mod;
  while (b) {
    if (b & 1) {
      res = (res + a) % mod;
    }
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...);
#endif

#define COMMON_MOD pow(10, 9) + 7
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;
/* printf("%lld %lld \n", cur_n, m / 2 + 1);
*/

class mytask {
public:

  mytask() { }


  int solve() {
    ll a, b, c;
    cin >> a >> b >> c;
    set<ll> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if (s.size() == 2) {
      cout << "Yes";
    } else {
      cout << "No";
    }


    return 0;
  }




};


int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  auto task = mytask();
  task.solve();


  cout << endl;

  return 0;
}


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

#define swap(type, x, y)  do {type t = x; x = y; y = t;} while (0)

void quick(int a[], int left, int right)
{
    int pl = left;
    int pr = right;
    int x = a[(pl + pr) / 2];
    do {
        while (a[pl] < x) ++pl;
        while (a[pr] > x) --pr;
        if (pl <= pr) {
            swap(int, a[pl], a[pr]);
            ++pl;
            --pr;
        }
    } while (pl <= pr);
    if (left < pr) quick(a, left, pr);
    if (pl < right) quick(a, pl, right);
}

int main(void)
{
    char a[5];
    scanf("%s", a);

    int sum = a[0] + a[1] + a[2];
    if (sum == 294) printf("%s\n", "Yes");
    else printf("%s\n", "No");
    return 0;
}

Measured memory_bytes: 128
import collections
n=int(input())
arr=list(map(int,input().split()))
q=int(input())
arr2=list(map(int,input().split()))
dic=collections.defaultdict(int)
for i in range(2**n):
  tmp=0
  pos=0
  while i!=0:
    if i%2==1:
      i-=1
      tmp+=arr[pos]
    i=i//2
    pos+=1
  dic[tmp]+=1
for i in range(q):
  if dic[arr2[i]]!=0:
    print('yes')
  else:
    print('no')


Measured memory_bytes: 6100
import sys

lst=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
pos = input()
print(lst[int(pos)-1])

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

int main()
{
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif*/
	
	int x;
	cin >> x;
	if (x>=400 && x<=599){
		cout<<8<<endl;
	}else if(x>=600 && x<=799){
		cout<<7<<endl;
	}else if(x>=800 && x<=999){
		cout<<6<<endl;
	}else if(x>=1000 && x<=1199){
		cout<<5<<endl;
	}else if(x>=1200 && x<=1399){
		cout<<4<<endl;
	}else if(x>=1400 && x<=1599){
		cout<<3<<endl;
	}else if(x>=1600 && x<=1799){
		cout<<2<<endl;
	}else if(x>=1800 && x<=1999){
		cout<<1<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3632
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto rd = readln.split.map!(to!int);
  auto a = rd[0], b = rd[1];
  writeln(a == b ? "a == b" : (a < b ? "a < b" : "a > b"));
}

Measured memory_bytes: 2516
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long min = (long) 1e18;
		long tot = A.Sum();
		long sum = 0;
		for(int i=0;i<N-1;i++){
			sum += A[i];
			min = Math.Min(min, Math.Abs(tot - sum - sum));
		}
		Console.WriteLine(min);
		
	}
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 31964
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define arr array

using namespace std;

const int e = 2e6 + 69;
const ll mod = 1e9 + 7;

ll a[e];

//beginner 1999 129

int h, w;

string s[e];

ll row[3000][3000], col[3000][3000], another_col[3000][3000], another_row[3000][3000];

int main()
{
    cin >> h >> w;
    for(int i=1; i<=h; i++){
        cin >> s[i];
        s[i] = ' ' + s[i];
        for(int j=1; j<=w; j++){
            row[i][j] = row[i][j-1];
            if(s[i][j] == '#'){
                row[i][j] = 0;
            }
            else{
                row[i][j] ++;
            }
        }
        for(int j=w; j>=1; j--){
            another_row[i][j] = another_row[i][j+1];
            if(s[i][j] == '#'){
                another_row[i][j] = 0;
            }
            else{
                another_row[i][j] ++;
            }
        }
    }
    for(int j=1; j<=w; j++){
        for(int i=1; i<=h; i++){
            col[i][j] = col[i-1][j];
            if(s[i][j] == '#'){
                col[i][j] = 0;
            }
            else{
                col[i][j] ++;
            }
        }
        for(int i=h; i>=1; i--){
            another_col[i][j] = another_col[i+1][j];
            if(s[i][j] == '#'){
                another_col[i][j] = 0;
            }
            else{
                another_col[i][j] ++;
            }
        }
    }
    ll maxx = 0;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(s[i][j] == '#') continue;
            if(row[i][j] + col[i-1][j] + another_col[i+1][j] + another_row[i][j+1] > maxx){
                maxx = row[i][j] + col[i-1][j] + another_col[i+1][j] + another_row[i][j+1];
                //cout << i <<" "<<j<<"\n";
            }
        }
    }
    cout << maxx;
}


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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int32_t main()
{
	IOS;
	int n, k;
	cin >> n >> k;
	vi a(n);
	rep(i, 0, n)
	{
		cin >> a[i];
	}
	vector<bool> dp(k + 1, false);
	rep(i, 1, k + 1)
	{
		trav(it, a)
		{
			if ((i - it) >= 0)
			{
				if (dp[i - it] == false)
					dp[i] = true;
			}
		}
	}
	if (dp[k])
	{
		cout << "First\n";
	}
	else
	{
		cout << "Second\n";
	}
	return 0;
}

Measured memory_bytes: 256
# UnionFind
import sys
sys.setrecursionlimit(10**9)
class UnionFind:
  def __init__(self, n):
    self.n = [-1]*n
    self.r = [0]*n
    self.siz = n

  def find_root(self, x):
    if self.n[x] < 0:
      return x
    else:
      self.n[x] = self.find_root(self.n[x])
      return self.n[x]

  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.r[x] > self.r[y]:
      self.n[x] += self.n[y]
      self.n[y] = x
    else:
      self.n[y] += self.n[x]
      self.n[x] = y
      if self.r[x] == self.r[y]:
        self.r[y] += 1
    self.siz -= 1

  def root_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def count(self, x):
    return -self.n[self.find_root(x)]

  def size(self):
    return self.siz

n,q=map(int,input().split())
uf=UnionFind(n)
for _ in range(q):
  t,u,v=map(int,input().split())
  if t==0:
    uf.unite(u,v)
  else:
    print(uf.root_same(u,v)+0)

Measured memory_bytes: 13044
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ini(N);
  vector<vector<ll>> v(N,vl(N)); in(v);
  vl dp(1<<N , 0);
  dp[0] = 0;
  rep(T , 1<<N){
    rep(i,N) rep(j,i){
      if((T&(1<<i)) && (T&(1<<j))) dp[T] += v[i][j];
    }
    for(int U=(1<<N)-1; U>0; U--){
      U &= T;
      dp[T]= max(dp[T] , dp[U] + dp[T ^ U]);
    }
  }
  out(dp[(1<<N) - 1]);

}

Measured memory_bytes: 768
// #include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;

typedef long long ll;
typedef pair<ll ,ll> pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll mod = 1000000009;
const ll INF = 1e18;//1*10^18

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

int ReturnDigit(ll num)
{
  string number=to_string(num);
  return number.length();
}

int main() {
  ll i,j,k,l;
  ll ans=0,n;
  cin >>n; 
  
  for(i=1; i<=n; i++)
  {
    if(i%3!=0 && i%5!=0)
    {
      ans+=i;
    }
  }
  cout<< ans <<endl;
}

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

int main() {

  int H, N;
  cin >> H >> N;

  vector<int> c(N);
  rep(i, N) { cin >> c[i]; }

  ll max = accumulate(c.begin(), c.end(), 0);

  string ret = H > max ? "No" : "Yes";

  cout << ret << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,d[N],book[N];
signed main()
{
    n=read();
    int res=0;
    for(ri int i=1;i<=n;i++)
    {
        d[i]=read();
        if(!book[d[i]]) res++, book[d[i]]=1;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 3612
main = do
  (a:b:xs) <- map read . words <$> getLine
  s <- getLine
  putStrLn $ if solve a b s then "Yes" else "No"

solve a b s = length s == a+b+1 && and (map isNum (take a s)) && (head $ drop a s) == '-' && and (map isNum ((drop (a+1) s)))

isNum c = c `elem` ['0'..'9']



Measured memory_bytes: 508
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] d = new int[N];
		for(int i=0;i<N;i++) {
			d[i] = sc.nextInt();
		}
		int ans = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				ans += d[i]*d[j];
			}
		}
		System.out.println(ans);
	}
}

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

struct status{
  vector<int> ans;
  vector<long long> last;
};

bool operator< (pair<long long, status> l, pair<long long, status> r){
  if(l.first != r.first) return l.first < r.first;
  return l.first < r.first;
}

int main() {
  int d;
  cin >> d;
  vector<long long> c(26);
  for(int i = 0; i < 26; i++) cin >> c.at(i);
  vector<vector<long long>> s(d, vector<long long> (26));
  for(int i = 0; i < d; i++){
    for(int j = 0; j < 26; j++) cin >> s.at(i).at(j);
  }
  
  priority_queue<pair<long long, status>> beam;
  vector<int> an(0);
  vector<long long> la(26, 0);
  status sta = {an, la};
  beam.push({(long long)0, sta});
  for(int day = 0; day < d; day++){
    priority_queue<pair<long long, status>> now;
    
    while(beam.size() > 0){
      long long score = beam.top().first;
      auto state = beam.top().second;
      beam.pop();
      state.ans.push_back(0);
      
      for(int i = 0; i < 26; i++){
        long long sum = score;
        auto n = state;
        n.last.at(i) = day;
        n.ans.at(day) = i + 1;
        
        sum += s.at(day).at(i);
        for(int j = 0; j < 26; j++){
          sum -= c.at(j) * (day - n.last.at(j));
        }
        
        now.push({sum, n});
      }
    }
    for(int i = 0; i < 50; i++){
      if(now.size() <= 0) break;
      beam.push(now.top());
      now.pop();
    }
  }
  
  auto res = beam.top().second.ans;
  for(auto now : res) cout << now << endl;
}


Measured memory_bytes: 6252
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    int n;
    cin >> n;
    vector<ll> data;
    F(i, 0, n){
        int l;
        cin >> l;
        data.pb(l);
    }
    int upper = n-1;
    ll upper_max = data[n-1];
    ll diff = data[n-1]-data[n-2];
    while(upper > 0){
        int lower = 0;
        while(upper_max > data[upper] && upper > 0)upper--;
        upper_max = data[upper];
        while(upper > lower){
            while(data[lower] >= data[lower+1] && lower+1 < upper)lower++;
            ll tmp = data[upper] - data[lower];
            if(diff < tmp){
                diff = tmp;
            }
            lower++;
        }
        upper--;
    }
    cout << diff << endl;
}



Measured memory_bytes: 4968