akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> P;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct Edge{
  int to,d,e;
  Edge(int to,int d,int e):to(to),d(d),e(e){}
};

int N,M,L;
vector<Edge>G[128];
int dist[128][128];

void dijkstra(){
  rep(i,128) fill(dist[i], dist[i]+N, INF);
  dist[L][0] = 0;
  priority_queue<P, vector<P>, greater<P> >q;
  q.push(P(L, 0));

  while(!q.empty()){
    P p = q.top(); q.pop();
    int v = p.second, m = p.first;
    rep(i,G[v].size()){
      Edge e = G[v][i];
      if(e.d <= m){
	if(dist[m-e.d][e.to] > dist[m][v]){
	  dist[m-e.d][e.to] = dist[m][v];
	  q.push(P(m-e.d, e.to));
	}
      }
      if(dist[m][e.to] > dist[m][v] + e.e){
	dist[m][e.to] = dist[m][v] + e.e;
	q.push(P(m, e.to));
      }
    }
  }
}

int main(){
  while(scanf("%d%d%d", &N,&M,&L) && N+M+L){
    rep(i,128) G[i].clear();
    rep(i,M){
      int a,b,d,e;
      scanf("%d%d%d%d",&a,&b,&d,&e); a--; b--;
      G[a].push_back(Edge(b,d,e));
      G[b].push_back(Edge(a,d,e));
    }

    dijkstra();
    int res = INF;
    rep(i,L+1){
      //      cout << dist[i][N-1] <<endl;;
      //      rep(j,N) cout << dist[i][j] << " "; cout << endl;
    }
    rep(i,L+1) res = min(res, dist[i][N-1]);
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1424
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

/// ..), 0-origin
struct BITree(alias _fun, alias E, T)
if (is(typeof(E) : T))
{
    import std.functional : binaryFun;
    alias OP = binaryFun!_fun;

    ///
    this(size_t n, T[] ts) {
        this.n = n;
        this.tree.length = n+1;
        foreach (ref e; this.tree) e = E;
        foreach (i, t; ts) this.update(i, t);
    }

    /// This method does not replace the element but applies old one and new one to the `OP`.
    void update(size_t i, T e) {
        i += 1;
        while (i <= this.n) {
            this.tree[i] = OP(this.tree[i], e);
            i += i & -i;
        }
    }

    ///
    T query(size_t i) {
        auto r = E;
        while (i > 0) {
            r = OP(r, this.tree[i]);
            i -= i & -i;
        }
        return r;
    }

private:
    size_t n;
    T[] tree;
}

auto bitree(alias fun, alias init, T)(size_t n, T[] ts = [])
{
    return BITree!(fun, init, T)(n, ts);
}

///
auto bitree(alias fun, alias init, T)(T[] ts)
{
    return BITree!(fun, init, T)(ts.length, ts);
}

auto sum_bitree(T)(size_t n, T[] ts = [])
{
    return bitree!("a + b", 0L, T)(n, ts);
}

auto sum_bitree(T)(T[] ts)
{
    return sum_bitree!T(ts.length, ts);
}

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    long K = nk[1];
    long[] AS;
    foreach (_; 0..N) AS ~= readln.chomp.to!long;
    foreach (i; 1..N) AS[i] += AS[i-1];
    long[] BS = [0];
    foreach (i; 0..N) {
        AS[i] -= (i+1).to!long * K;
        BS ~= AS[i];
    }
    sort(BS);
    BS = BS.uniq.array;

    size_t[long] CS;
    foreach (i, b; BS) CS[b] = i;

    auto bit = sum_bitree!long(BS.length);
    bit.update(CS[0], 1);
    long r;
    foreach (a; AS) {
        auto c = CS[a];
        r += bit.query(c+1);
        bit.update(c, 1);
    }
    writeln(r);
}

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

int main(){
    ll n; cin >> n;
    string s; cin >> s;
    vector<int> a(2 * n);
    rep(i, 2 * n) a[i] = (int)(s[i] - 'a') + 1;
    vector<int> check(26,0);
    rep(i, 2 * n) {
        if (i < n) check[a[i]-1]++;
        else check[a[i]-1]--;
    }
    rep(i, 26) if (check[i]) { cout << 0 << "\n"; return 0; }

    map<pair<ll,ll>,ll> mp;
    rep(i, 1ll<<n) {
        ll c1 = 0, c2 = 0;
        rep(j, n) {
            if (i & 1ll<<j) { c1 *= 10007; c1 += a[j]; }
            else { c2 *= 10007; c2 += a[j]; }
        }
        mp[make_pair(c1,c2)]++;
    }

    ll ans = 0;
    rep(i, 1ll<<n) {
        ll c1 = 0, c2 = 0;
        rep(j, n) {
            if (i & 1ll<<j) { c1 *= 10007; c1 += a[n+n-1-j]; }
            else { c2 *= 10007; c2 += a[n+n-1-j]; }
        }
        ans += mp[make_pair(c1,c2)];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 36208
#include<bits/stdc++.h>
#define ll long long
#define debug(a) cout<<a<<endl
#define pii pair<int,int>
#define maxn 100009
#define inf (int) 1e9+7
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    ll r,d,x;
    cin>>r>>d>>x;
    ll ant=x;
    for(int i=1;i<=10;i++){
        ant=ant*r-d;
        cout<<ant<<endl;
    }
    return 0;
}
///usar double sempre ou long double
///pensar em casos que coisas dao negativas
///N esquecer de limpar as coisas em quest de varios testes
///OLHAR A COMPLEXIDADE PRA VER SE N PASSA POR BRUTE FORCE OU BRUTE FORCE COM ALGUMAS OTIMIZACOES

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int A,B;
    cin >>A>>B;
    if(A*B%2==0){
        cout<<"Even"<<endl;
    }
    else{
        cout<<"Odd"<<endl;
    }
}

Measured memory_bytes: 256
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
//void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 998244353;
const ll maxn = 1000005;
const ll mm = 1e+18;
void solve()
{
    int s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe";
    else cout<<"safe";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
	//freopen("sp.txt","r",stdin);
    //srand(time(0));
    //cin>>t;
    for(int _i=1;_i<=t;_i++){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 3640
type t = {
  id : int;
  ch : char;
  num : int;
}

let rec partitoin a r = function
  | (i, j) when j = r ->
    let tmp = a.(i) in
    a.(i) <- a.(j);
    a.(j) <- tmp;
    i
  | (i, j) when a.(j).num <= a.(r).num ->
    let tmp = a.(i) in
    a.(i) <- a.(j);
    a.(j) <- tmp;
    partitoin a r (i + 1, j + 1)
  | (i, j) ->
    partitoin a r (i, j + 1)

let rec quick_sort a p r =
  if p < r then begin
    let q = partitoin a r (p, p) in
    quick_sort a p (q - 1);
    quick_sort a q r
  end

let rec stable_str a n i =
  if i = n then "Stable"
  else if a.(i-1).num = a.(i).num && a.(i-1).id > a.(i).id then "Not stable"
  else stable_str a n (i + 1)

let rec split str delim acc =
  let open String in
  match
    try Some (rindex str delim) with _ -> None
  with
  | None -> str :: acc
  | Some i -> split (sub str 0 i) delim (sub str (i + 1) (length str - i - 1) :: acc)

let () =
  let n = read_int () in
  let a = Array.init n (fun i ->
    match split (read_line ()) ' ' [] with
    | [c; d] -> { id = i; ch = c.[0]; num = int_of_string d }
    | _ -> exit 1) in
  quick_sort a 0 (n - 1);
  print_endline (stable_str a n 1);
  Array.iter (fun x -> Printf.printf "%c %d\n" x.ch x.num) a

Measured memory_bytes: 9136
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
  cin>>a>>b>>c;
  if(max({a,b,c})==a)cout<<a*10+b+c<<endl;
  else if(max({a,b,c})==b)cout<<b*10+a+c<<endl;
  else cout<<c*10+b+a<<endl;
  return 0;
}


Measured memory_bytes: 256
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var a = new int[n];
            for (int i = 0; i < m; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                for (int j = 0; j < n; j++) a[j] += int.Parse(line[j]);
            }
            Console.WriteLine(a.Max());
        }
    }
}



Measured memory_bytes: 25140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
struct edge {
    ll from;
    ll to;
    ll cost;
};
int main(void){
    ll n,m,p;
    ll d[2500];
    vector<edge> edges;
    cin>>n>>m>>p;
    for(int i=0;i<m;i++){
        struct edge add;
        cin>>add.from>>add.to>>add.cost;
        add.from--,add.to--;
        add.cost-=p;
        edges.push_back(add);
    }
    fill(d,d+n,-INF);
    d[0]=0;
    for(int i=0;i<2*n;i++){
        for(auto e:edges){
            if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=min(d[e.from]+e.cost,INF);
                if(i>=n-1){
                    d[e.to]=INF;
                }
            }
        }
    }
    for(auto e:edges){
        if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
            d[e.to]=min(d[e.from]+e.cost,INF);
        }
    }
    if(d[n-1]==INF) cout<<-1<<endl;
    else cout<<max(ll(0),d[n-1])<<endl;
}


Measured memory_bytes: 576
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_N = 40;
static const int MAX_A = 10;
static const int MAX_B = 10;
static const int MAX_C = 100;
static const int INF = 1000000;

int N, Ma, Mb;
int a[MAX_N], b[MAX_N], c[MAX_N];
int memo[MAX_N + 1][MAX_A * MAX_C + 1][MAX_B * MAX_C + 1];

int main(){
	cin >> N >> Ma >> Mb;
	for(int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= 1000; j++){
			for(int k = 0; k <= 1000; k++){
				memo[i][j][k] = INF;
			}
		}
	}
	memo[0][0][0] = 0;
	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= 1000; j++){
			for(int k = 0; k <= 1000; k++){
				memo[i][j][k] = min(memo[i][j][k], memo[i - 1][j][k]);
				if(j - a[i - 1] < 0 || k - b[i - 1] < 0) continue;
				memo[i][j][k] = min(memo[i][j][k], memo[i - 1][j - a[i - 1]][k - b[i - 1]] + c[i - 1]);
			}
		}
	}
	int ans = INF;
	for(int i = 1; i <= N; i++){
		for(int j = 1; Ma * j <= 1000 && Mb * j <= 1000; j++){
			ans = min(ans, memo[i][Ma * j][Mb * j]);
		}
	}
	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

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

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int H,W;
  cin >> H >> W;
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  vector<vector<int>> G(H,vector<int> (W));
  int k=0;
  while(!a[k]){
    k++;
  }
  for(int i=0; i<H; i++){
    if(i%2){
      for(int j=W-1; j>=0; j--){
        G[i][j] = k;
        a[k]--;
        while(!a[k]){
          k++;
        }
      }
    }else{
      for(int j=0; j<W; j++){
        G[i][j] = k;
        a[k]--;
        while(!a[k]){
          k++;
        }
      }
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cout << G[i][j]+1;
      if(j != W-1){
        cout << " ";
      }else{
        cout << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 384
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;

void dikj(vector<vector<Pll>> &da, vector<ll> &p, int s){
    MinHeap<Pll> pq;
    pq.push({0, s});
    while(!pq.empty()){
        auto now = pq.top();pq.pop();
        if(p[now.second] != -1) continue;
        p[now.second] = now.first;
        rip(i,da[now.second].size(),0){
            pq.push({now.first + da[now.second][i].first, da[now.second][i].second});
        }
    }
    return;
}

int main(){
    int n,m,s,t; cin >> n >> m >> s >> t;
    --s;--t;
    vector<vector<Pll>> da1(n, vector<Pll>(0));
    vector<vector<Pll>> da2(n, vector<Pll>(0));
    rip(i,m,0){
        ll u,v,a,b; cin >> u >> v >> a >> b;
        --u;--v;
        da1[u].push_back({a,v});
        da1[v].push_back({a,u});
        da2[u].push_back({b,v});
        da2[v].push_back({b,u});
    }
    vector<ll> to(n, -1), ot(n, -1),ans(n);
    dikj(da1, to, s);
    dikj(da2, ot, t);
    ans[n-1] = to[n-1] + ot[n-1];
    for(int i = n-2;i>-1;--i){
        ans[i] = min(ans[i+1], to[i] + ot[i]);
    }
    rip(i,n,0) ans[i] = 1000000000000000-ans[i];
    rip(i,n,0) printf("%lld\n", ans[i]);
}


Measured memory_bytes: 19340
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String line1=s.nextLine();
        String line2=s.nextLine();
        String[] SNum1=line1.split(" ");
        String[] SNum2=line2.split(" ");
        int town=Integer.parseInt(SNum1[0]);
        long step=Long.valueOf(SNum1[1]);
        int[] A=new int[town];
        for(int i=0;i<town;i++){
            A[i]=Integer.parseInt(SNum2[i]);
        }

        int[] B=new int[town];
        int[] C=new int[town];

        int counter=0;
        int currentTown=0;
        int loopNum=0;
        int startTown;
        while (true){
            B[currentTown]++;
            if(B[currentTown]==2){
                startTown=currentTown;
                loopNum=counter-C[currentTown];
                break;
            }
            C[currentTown]=counter;
            counter++;
            currentTown=A[currentTown]-1;
        }

        if(step>counter){
            step=(step-counter)%loopNum;
            currentTown=startTown;
        }else if(step>C[currentTown]){
            step=step-C[currentTown];
            currentTown=startTown;
        }else{
            currentTown=0;
        }

        for(int i=0;i<step;i++){
            currentTown=A[currentTown]-1;
        }
        System.out.println(currentTown+1);

    }
}


Measured memory_bytes: 71932
h, w = map(int, input().split())
s = [ [0] + [0 if a=='.' else 1 for a in input()] + [0] for _ in range(h)]
s = [[0 for _ in range(w+2)]] + s + [[0 for _ in range(w+2)]]

for j in range(1,h+1):
  ans = []
  for i in range(1,w+1):
    if s[j][i] == 0:
      ans.append(str(sum(s[j-1][i-1:i+2])+sum(s[j][i-1:i+2])+sum(s[j+1][i-1:i+2])))
    else:
      ans.append('#')
  print(''.join(ans))

Measured memory_bytes: 3064
v = 0
t = 0
n = int(input())
T = [0] + list(map(int, input().split())) + [0]
V = [0] + list(map(int, input().split())) + [0]
cumT = [0] * (len(T) + 1)
for i in range(len(T)):
    cumT[i + 1] = cumT[i] + T[i]
imos = [1000] * (sum(T) + 1)

for i in range(len(T)):
    for j in range(T[i]):
        imos[cumT[i] + j] = V[i]
horizon = imos.copy()
for i in range(len(T)):
    for j in range(len(imos) - cumT[i + 1]):
        imos[cumT[i + 1] + j] = min([imos[cumT[i + 1] + j], V[i] + j])
    for j in range(cumT[i + 1]):
        imos[cumT[i] - j] = min([imos[cumT[i] - j], V[i] + j])

ret = 0.0
for i in range(len(imos) - 1):
    ret += (imos[i] + imos[i + 1] + 0.5 if imos[i] == imos[i + 1] and imos[i] < horizon[i] else imos[i] + imos[i + 1]) / 2
print(ret)


Measured memory_bytes: 3444
#include <stdio.h>
#include <algorithm>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
	
struct Node{
	Node *l,*r,*p;
	int s,v,m;
	Node():l(NULL),r(NULL),p(NULL){}
	static int Size(Node* x){
		return x?x->s:0;
	}
	static int Mini(Node* x){
		return x?x->m:1145141919;
	}
	Node* Update(){
		s=1+Size(l)+Size(r);
		m=min({v,Mini(l),Mini(r)});
		return this;
	}
	int Pos(){
		if(p&&p->l==this) return -1;
		if(p&&p->r==this) return 1;
		return 0;
	}
	void Rotate(){
		Node *q=p,*c;
		if(Pos()==1){
			c=l;
			l=p;
			p->r=c;
		}else{
			c=r;
			r=p;
			p->l=c;
		}
		if(c) c->p=p;
		p=p->p;
		q->p=this;
		if(p&&p->l==q) p->l=this;
		if(p&&p->r==q) p->r=this;
		q->Update();
	}
	Node* Splay(){
		while(p){
			int a=Pos(),b=p->Pos();
			if(b&&a==b) p->Rotate();
			if(b&&a!=b) Rotate();
			Rotate();
		}
		return Update();
	}
	Node* Idx(int i){
		if(i<Size(l)) return l->Idx(i);
		else if(i>Size(l)) return r->Idx(i-Size(l)-1);
		return Splay();
	}
} d[200000];

pair<Node*,Node*> Split(Node* x,int i){
	if(i<0) return MP((Node*)NULL,x);
	x=x->Idx(i);
	Node* c=x->r;
	if(c) c->p=NULL;
	x->r=NULL;
	return MP(x->Update(),c);
}

Node* Merge(Node* a,Node* b){
	if(!a||!b) return a?a:b;
	while(a->r) a=a->r;
	b->p=a->Splay();
	a->r=b;
	return a->Update();
}

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	Node* w=NULL;
	REP(i,n){
		scanf("%d",&d[i].v);
		w=Merge(w,d[i].Update());
	}
	REP(_,q){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		if(x==0){
			auto r=Split(w,z);
			auto q=Split(r.first,z-1);
			auto p=Split(q.first,y-1);
			w=Merge(Merge(p.first,q.second),Merge(p.second,r.second));
		}else if(x==1){
			auto q=Split(w,z);
			auto p=Split(q.first,y-1);
			printf("%d\n",p.second->m);
			w=Merge(Merge(p.first,p.second),q.second);
		}else{
			w=w->Idx(y);
			w->v=z;
			w->Update();
		}
	}
}

Measured memory_bytes: 10560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main() {
  string n;
  cin >> n;
  int size=n.size();
  int sum=0;
  for(int i=0;i<size;i++){
    sum+=ctoi(n.at(i));
  }
  if(sum%9==0)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}



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

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

        bool ok = true;
        for (int i = 0; i < N; ++i) {

                if (A[i] % 2 == 0) {
                        if (A[i] % 3 == 0 || A[i] % 5 == 0) {

                        }
                        else {
                                ok = false;
                                break;
                        }
                }

        }
        if (ok) {
                cout << "APPROVED" << endl;
        }
        else {
                cout << "DENIED" << endl;
        }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int a[3];

	cin >> a[0] >> a[1] >> a[2];

	sort(a, a + 3);

	Out((a[1] - a[0]) + (a[2] - a[1]));
	
	return 0;
}


Measured memory_bytes: 256
A = []
q = gets.chomp.to_i
q.times{
    input = gets.chomp
    query = input.split(" ")
    case query[0]
    when "0"
        A.push(query[1])
    when "1"
        puts A[query[1].to_i]
    when "2"
        A.pop()
    else
    end
}


Measured memory_bytes: 21172
#include "bits/stdc++.h"
using namespace std;

int main(){
int n;
cin >>n;
vector<int> t(n);
int nobuff =0;
for(int i=0;i<n;i++){
    cin >> t.at(i);
    nobuff+=t.at(i);
}
int che = nobuff;
int m;
cin >>m;
vector<int> p(m),x(m);
for(int i=0;i<m;i++){
    nobuff = che;
    cin >> p.at(i)>>x.at(i);
    for(int j=0;j<n;j++){
        if(p.at(i)==j+1){
            nobuff-=t.at(j)-x.at(i);
            cout << nobuff << endl;
        }
    }
}
}

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

#define SZ(v) ((int)(v).size())
using ll = long long;

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

	int nb_enfants;
	cin >> nb_enfants;
	vector<pair<ll, int> > val(nb_enfants);
	for (int i = 0; i < nb_enfants; ++i)
	{
		cin >> val[i].first;
		val[i].second = i;
	}
	sort(val.rbegin(), val.rend());

	vector<vector<ll> > dp(nb_enfants);
	for (int i(0); i < nb_enfants; ++i)
		dp[i].resize(nb_enfants+1);

	for (int i = 0; i < nb_enfants; ++i)
		for (int gauche(0); gauche <= i; ++gauche)
		{
			dp[i][gauche+1] = val[i].first * (val[i].second - gauche) + (i ? dp[i-1][gauche]:0);
			dp[i][gauche] = max(dp[i][gauche], val[i].first * (nb_enfants - (i - gauche) - 1 - val[i].second) + (i?dp[i-1][gauche]:0));
		}
	ll ans(0);
	for (int i(0); i <= nb_enfants; ++i)
		ans = max(dp[nb_enfants-1][i], ans);
	cout << ans << endl;
}


Measured memory_bytes: 34608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;++i)
#define Sort(a) sort(a.begin(),a.end())
const int INF = 1e9+7;

int main(){
  string s;
  int cnt = 0;
  cin >> s;
  rep(i,s.size()){
    if(s.at(i)=='A'){
      int t = 0;
      for(int j=i;j<s.size();++j){
        if(s.at(j)=='Z'){
          ++t;
          cnt = max(cnt,t);
        }else{
          ++t;
        }
      }
      if(cnt){
        break;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
void main() {
    int n = readln.chomp.to!int;
    int[] tmp = readln.split.to!(int[]);
    int d = tmp[0], x = tmp[1];
    foreach (i; 0 .. n) {
        int a = readln.chomp.to!int;
        int day = 1;
        while (day <= d) {
            ++x;
            day += a;
        }
    }
    x.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=1e6+6;
const int mod=1e9+7;
ll fact[N],inv[N];

ll fp(ll b,ll p){
	if(p==0) return 1;
	if(p&1) return (b*fp(b,p-1))%mod;
	return fp((b*b)%mod,p/2);
}

ll nCk(ll n,ll k){
   return ((fact[n]*inv[k])%mod*inv[n-k])%mod;
}

int main()
{

  /* #ifndef ONLINE_JUDGE
   freopen("test.txt", "r", stdin);
   #endif*/
   ios_base::sync_with_stdio(0);
   cin.tie(0);
    fact[0]=1;
   inv[0]=fp(fact[0],mod-2);
   for(int i=1;i<=1000000;i++){
       fact[i]=fact[i-1]*i%mod;
       inv[i]=fp(fact[i],mod-2);
   }
   ll x,y,ans=0;
   cin>>x>>y;
   if((x+y)%3!=0)return cout<<0,0;
   ll n=2*y-x;
   n=n/3;
   ll m=y-2*n;
   if(m<0||n<0)return cout<<0,0;
   cout<<nCk(n+m,m)<<'\n';



    return 0;
}


Measured memory_bytes: 15872
#include<stdio.h>

int main(){
	
	int h,m,s,S;
	
	h=m=s=0;
	
	scanf("%d",&S);
	
	h = S/3600;
	m = (S / 60) % 60;
	s = S % 60;
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
	
}

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

int main() {
    string s,res,ans;
    cin>>s;
    int n=s.size();
    int small=0,c=0;
    rep(i,n) {
        if (s[i]>='a'&&s[i]<='z') small++;
    }
    if (s[0]=='A'&&small==n-2) {
        res=s.substr(2,(n-3));
        rep(i,res.size()) {
            if (res[i]=='C') c++;
        }
        if (c==1) ans="AC";
        else ans="WA";
    } else {
        ans="WA";
    }
    cout<<ans<<endl;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> cnt(3,0);
    rep(i,n){
        if(a[i] % 4 == 0)cnt[2]++;
        else if(a[i] % 2 == 0)cnt[1]++;
        else cnt[0]++;
    }
    bool ok = true;
    if(cnt[2] >= cnt[0])ok = true;
    else if(cnt[2] == cnt[0]-1 && cnt[1] == 0)ok = true;
    else ok = false;

    cout << (ok ? "Yes" : "No") << endl;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a));

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const long double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;


const int MAX = 100005;
string a;
int x[MAX];
int n;
int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(0);cin.tie(0);

	cin>>n>>a;

	FOR(i,0,2)
	FOR(j,0,2)
	{
		FILL(x,-1);
		x[0]=i;
		x[1]=j;

		FOR(k,1,n)
		{
			int nxt = (k+1)%n;
			int w;
			if(x[k] == 0 && a[k]=='o')
			{
				w = x[k-1];
			}
			if(x[k] == 0 && a[k]=='x')
			{
				w = x[k-1]^1;
			}
			if(x[k] == 1 && a[k]=='o')
			{
				w = x[k-1]^1;
			}
			if(x[k] == 1 && a[k]=='x')
			{
				w = x[k-1];
			}

			if(nxt == 0 && x[0]==w)
			{
				if(x[0] == 0 && a[0]=='o' && (x[n-1]!=x[1]))continue;
				if(x[0] == 0 && a[0]=='x' && (x[n-1]==x[1]))continue;
				if(x[0] == 1 && a[0]=='o' && (x[n-1]==x[1]))continue;
				if(x[0] == 1 && a[0]=='x' && (x[n-1]!=x[1]))continue;
				FOR(l,0,n)
				{
					if(x[l]==0)cout<<'S';
					else cout<<'W';
				}

				return 0;
			}
			x[nxt]=w;
		}
	}

	cout<<-1;

}



Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Dictionary<int, int> dic = new Dictionary<int, int>();
            int rmCount = 0;
            for (int i = 0; i < N; i++)
            {
                if (dic.ContainsKey(r[i]))
                {
                    if (dic[r[i]] >= r[i])
                    {
                        rmCount++;
                        continue;
                    }
                    dic[r[i]]++;
                }
                else
                {
                    dic.Add(r[i], 1);
                }
            }

            foreach (var item in dic)
            {
                if (item.Key > item.Value)
                {
                    rmCount += item.Value;
                }
            }
            Console.WriteLine(rmCount);
        }
    }
}

Measured memory_bytes: 27360
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	ll a, v;
	cin >> a >> v;
	ll b, w;
	cin >> b >> w;
	ll t;
	cin >> t;
	ll dist = abs(a - b);
	ll sp = v - w;
	sp *= t;
	if (dist <= sp) puts("YES");
	else puts("NO");
	return 0;
}

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

using namespace std;

int main()
{
    int n, k, ans; cin >> n >> k;
    
    int a[55];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    sort(a, a + n, greater<int>());

    for(int i = 0;i < k;i++){
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	bool sign=false;
	while(n>=0)
	{
		if(n%4==0){
			sign=true;
			break;
		}
		n-=7;
	}
	if(sign)
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int l = stoi(s.substr(2,2));
    int f = stoi(s.substr(0,2));
    if(l>=1 && l<=12 && (f<1 || f>12)){
        cout << "YYMM" << endl;
    }
    else if(f>=1 && f<=12 && (l<1 || l>12)){
        cout << "MMYY" << endl;
    }
    else if(f>=1 && f<=12 && l>=1 && l<=12){
        cout << "AMBIGUOUS" << endl;
    }
    else{
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int gcd(int x, int y){
  if(x==0) return y;
  else return gcd(y%x, x);
}

int main(){
  int N, X;
  cin >> N >> X;
  int distance[N];
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    distance[i] = abs(x-X);
  }

  int ans = distance[0];
  for(int i=1;i<N;i++){
    ans = gcd(ans, distance[i]);
  }
  cout << ans <<endl;

  return 0;
}




Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int b1, b2, b3;
	
	scanf("%d %d %d", &b1, &b2, &b3);
	
	if ((b1 == 1 && b2 == 1) || (b3 == 1)) {
		printf("Open\n");
	}
	else {
		printf("Close\n");
	}
	
 	return (0);
}

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

int main(){
    string s,r;
    int q;
    int t,f;
    cin >> s >> q;
    char c;
    rep(i,q){
        cin >> t;
        if(t == 2){
           cin >> f;
           cin >> c;
           if(f == 1){
               r += c;               
           }
           else{
               s += c;
           }
        }
        else{
            swap(s,r);
        }
    }
    reverse(r.begin(),r.end());
    r += s;
    cout << r << endl;
    return 0;
}

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

int main() {
	int a;
  string s;
	cin >> a >> s;
  if(a>=3200){
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

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

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    string c; cin >> c;
    int pf = 0;
    int pl = c.size()-1;
    int ans = 0;
    while(pf < pl) {
        //cout << pf << " " << pl << endl;
        if (c[pf]=='W' & c[pl]=='R') {
            ++ans;
            ++pf; --pl;
        }
        else {
            if (c[pf]=='R') ++pf;
            if (c[pl]=='W') --pl;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3748
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n = readline() |> parseInt
    a,b = readline() |> split |> parseMap
    p = readline() |> split |> parseMap
    ca = 0
    cb = 0
    for i in 1:n
        if p[i] <= a
            ca += 1
        elseif p[i] <= b
            cb += 1
        end
    end
    println(min(ca,cb,n-ca-cb))
end

main()


Measured memory_bytes: 111160
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  cin>>n;

  vector<int> p(n);
  int ans=0;
  rep(i,n){
    cin>>p[i];
    if(i%2==0 && p[i]%2==1) ans++;
  }


  cout << ans << endl;

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    ll x;
    cin >> x;

    ll ans = x / 11 * 2;
    if (x % 11 != 0) ans++;
    if (x - x / 11 * 11 > 6) ans++;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
inf=10**9
n,A,B,C=map(int,input().split())
l=[int(input())  for i in range(n)]
def dfs(s,a,b,c):
    if n==s:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) >0 else inf
    ret0=dfs(s+1,a,b,c)
    ret1=dfs(s+1,a+l[s],b,c)+10
    ret2=dfs(s+1,a,b+l[s],c)+10
    ret3=dfs(s+1,a,b,c+l[s])+10
    return min((ret0,ret1,ret2,ret3))
print(dfs(0,0,0,0))

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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;
  vll d(n);
  REP(i, n)
    cin >> d[i];
  ll m;
  cin >> m;
  vll t(m);
  REP(i, n)
    cin >> t[i];

  map<ll, ll> mn,mm;
  REP(i, n)
    mn[d[i]] += 1;
  REP(i, m)
    mm[t[i]] += 1;

  SORT_UNIQUE(t);
  ll ans = true;
  REP(i, t.size()){
    if(mn[t[i]] < mm[t[i]])
      ans = false;
  }

  if(ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {
  ll n, x, m;
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    cin >> x;
    n -= x;
  }
  if(n < 0)n = -1;
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 3684
#include<stdio.h>
#include<math.h>
#define N 10000
#define MAX 100000000
#define MIN 2
int main(){
  int i,n,j,num[N],count=0;
  scanf("%d",&n);
  if(n>N) return 0;
  for(i=n;i>0;i--){
    scanf("%d",&num[i]);
    if(num[i]>=MIN&&num[i]<=MAX){
      if(num[i]!=2&&num[i]%2==0) count++;
      else{
	for(j=3;j<=sqrt(num[i]);j+=2){
	  if(num[i]%j==0){
	    count++;
	    break;
	  }
	}
      }
    }
    else break;
  }
  printf("%d\n",n-count);
  return 0;
}



Measured memory_bytes: 2140
#include<iostream>
#include<algorithm>

using namespace std;

#define rep(i, a, b) for(int i=a;i<b;++i)
////////////////

int const N = 1e5 + 41;

int ans, w[N], cnt[N];
int n, m;

void solve(){
	cin >> n >> m;
	ans = 1;
	w[0] = 1;
	rep(i, 0, n) cnt[i] = 1;
	rep(i, 0, m){
		int xi, yi;
		cin >> xi >> yi;
		--xi;--yi;
		if(w[xi]){
			if(!w[yi]){ 
				w[yi] = 1;
				++ans;
			}
		}
		++cnt[yi];
		--cnt[xi];
		if(cnt[xi] == 0 && w[xi]) w[xi] = 0, --ans;
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

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

const int NUM = 100;

int main(){
  int x[NUM], y[NUM];

  int num = 0;
  while(true){
    cin >> y[num] >> x[num];

    if(x[num] == 0 && y[num] == 0){
      break;
    }

    ++num;
  }

  for(int i=0;i<num;++i){
    for(int k=0;k<y[i];++k){
      for(int l=0;l<x[i];++l){
	if(k == 0 || k == y[i] - 1){
	  cout << "#";
	}else if(l == 0 || l == x[i] - 1){
	  cout << "#";
	}else{
	  cout << ".";
	}
      }

      cout << endl;
    }

    cout  << endl;
  }
  
}




Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())
#define inf          1<<25

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int main() {
    int n;
    cin >> n;
    
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    
    int c = 0;
    while (true) {
        bool flg = false;
        rep(i, n) if (v[i] % 2 != 0) flg = true;
        if (flg) break;
        
        rep(i, n) v[i] /= 2;
        c++;
    }
    cout << c << endl;
    
    return 0;
}

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

struct point {
    int x;
    int y;
};

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    int x[N], y[N], a[N];
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> a[i];
    }
    point p1 = {0, H};
    point p2 = {W, H};
    point p3 = {0, 0};
    point p4 = {W, 0};
    
    for(int i = 0; i < N; i++) {
        if(a[i] == 1) {
            p1.x = max(p1.x, x[i]);
            p3.x = max(p3.x, x[i]);
        }
        if(a[i] == 2) {
            p2.x = min(p2.x, x[i]);
            p4.x = min(p2.x, x[i]);
        }
        if(a[i] == 3) {
            p3.y = max(p3.y, y[i]);
            p4.y = max(p3.y, y[i]);
        }
        if(a[i] == 4) {
            p1.y = min(p1.y, y[i]);
            p2.y = min(p2.y, y[i]);
        }
    }
    int w = p2.x - p1.x;
    int h = p1.y - p3.y;
    if(w < 0 || h < 0) {
        cout << "0" << endl;    
    } else {
        cout << (p2.x - p1.x) * (p1.y - p3.y) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
count=0

n=int(input())

p=list(map(int,input().split()))

for i in range(n):
    if i ==0:
        continue

    if i==n-1:
        break


    if max(p[i-1],p[i+1])>p[i] and min(p[i-1],p[i+1])<p[i]:
        count+=1




print(count)


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

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

#define d2r(deg) deg*(M_PI/180.0)

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

int main(){

    ll a, b, h, m; cin >> a >> b >> h >> m;

    long double mth, hth;
    mth = m*6;
    hth = (60*h + m)/2.0;

    long double mx, my, hx, hy;
    mx = b*sin(d2r(mth));
    my = b*cos(d2r(mth));

    hx = a*sin(d2r(hth));
    hy = a*cos(d2r(hth));

    long double ans = sqrt(pow(mx-hx, 2)+pow(my-hy, 2));

    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}

Measured memory_bytes: 4164