akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e12; // larger than the longuest distance of s and t.
const ll MOD = 1000000007;  // 1e9 + 7

// Returns the nearest position in left and right.
// The format is (left, right). left < x <= right.
tuple<ll, ll> nearest_pair(vector<ll>& t, ll x) {
  auto it = lower_bound(all(t), x);
  ll left, right;

  if (it == t.end()) {
    right = INF;
    --it;
    left = *it;
  } else if (it == t.begin()) {
    right = *it;
    left = -INF;
  } else {
    right = *it;
    --it;
    left = *it;
  }

  return make_tuple(left, right);
}

ll nearest(vector<ll>& t, ll x) {
  ll left, right;
  tie(left, right) = nearest_pair(t, x);
  if (abs(left - x) < abs(right - x)) {
    return left;
  } else {
    return right;
  }
}

int main(int argc, char** argv) {
  ll A, B, Q;
  cin >> A >> B >> Q;
  vector<ll> s(A);
  vector<ll> t(B);
  rep(i, A) {
    cin >> s[i];
  }
  rep(i, B) {
    cin >> t[i];
  }
  rep(i, Q) {
    ll x;
    cin >> x;

    // Try s->t case.
    ll sl, sr;
    tie(sl, sr) = nearest_pair(s, x);
    ll c1 = abs(x - sl) + abs(sl - nearest(t, sl));
    ll c2 = abs(x - sr) + abs(sr - nearest(t, sr));

    // Try t->s case.
    ll tl, tr;
    tie(tl, tr) = nearest_pair(t, x);
    ll c3 = abs(x - tl) + abs(tl - nearest(s, tl));
    ll c4 = abs(x - tr) + abs(tr - nearest(s, tr));

    cout << min(min(c1, c2), min(c3, c4)) << endl;
  }
}


Measured memory_bytes: 2944
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  board = []
  for _ in range(n):
    board.append(list(input().strip()))
  
  def judge(ia):
    for i in range(n):
      for j in range(i+1, n):
        if board[(i+ia)%n][j] != board[(j+ia)%n][i]:
          return False
    return True
  
  cnt = 0 
  for ia in range(n):
    if judge(ia):
      cnt += 1
  print(n * cnt)
  
if __name__=='__main__':
  main()



Measured memory_bytes: 42608
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

def calc():
    count = 0
    last = 0
    if a[0] > 0:
        return -1
    for v in a:
        if v > last + 1:
            return -1
        if v == last + 1:
            count += 1
        else:
            count += v
        last = v
    return count
print(calc())

Measured memory_bytes: 11048
# 素因数分解

N=int(input())
cand=[]

def check(N0,K0):
    if N0%K0==0:
        return check(int(N0/K0),K0)
    elif N0%K0==1:
        return 1
    else:
        return 0

def check0(N0,K0):
    while N0%K0==0:
        N0=int(N0/K0)
    if N0%K0==1:
        return 1
    else:
        return 0

# N-1の約数の数
for i in range(2,int((N-1)**0.5)+1):#O(N**0.5)
    if (N-1)%i==0:
        cand.append(i)
        if i!=int((N-1)/i):
            cand.append(int((N-1)/i))
if N>2:
    cand.append(N-1)

# Nの約数
for i in range(2,int(N**0.5)+1):#O(N**0.5)
    if N%i==0:
        cand.append(i)
        if i!=int(N/i):
            cand.append(int(N/i))
cand.append(N)

#print(cand)
count=0
for i in range(len(cand)):
    if check(N,cand[i]):
        count+=1

print(count)

Measured memory_bytes: 3188
all = [[[0 for _ in range(10)]for _ in range(3)]for _ in range(4)]

n = int(input())
for i in range(n):
    b,f,r,v = map(int, input().split())
    all[b-1][f-1][r-1] += v
for i in range(4):
  for j in range(3):
    for k in range(10):
      print(" {}".format(all[i][j][k]), end='')
    print()
  if i != 3:
    print("####################")


Measured memory_bytes: 5624
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    S = read_func().strip()
    if S[0] != S[1] and S[1] != S[2] and S[0] != S[2]:
        print 'Yes'
    else:
        print 'No'

if __name__ == '__main__':
    main()

Measured memory_bytes: 2568
def solve():
    n = int(input())
    p = list(map(int, input().split()))

    _min_p = p[0]
    count = 0
    for _p in p:
        if _min_p >= _p:
            count += 1
        _min_p = min(_min_p, _p)

    print(count)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 24872
N=int(input())

M=[[0]*10 for _ in range(10)]

for i in range(1,N+1):
  S=str(i)
  M[int(S[0])][int(S[-1])]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=M[i][j]*M[j][i]
    
print(ans)

Measured memory_bytes: 3064
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
    s = input()
    r = 0
    if 'RRR' in s:
        print(3)
    elif 'RR' in s:
        print(2)
    elif 'R' in s:
        print(1)
    else:
        print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int n; cin >> n;
  vector<int> A(n);
  rep_i(i, n){
    cin >> A[i];
  }
  
  int m; cin >> m;
  vector<int> B(m);
  rep_i(i, m){
    cin >> B[i];
  }

  rep_i(i, B.size()){
    if(!binary_search(A.begin(), A.end(), B[i])){
      say(0);
      return 0;
    }
  }

  say(1);
}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
signed main()
{
    int h, w;
    char a;
    vi cnt(30, 0);
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a;
            cnt[a - 'a']++;
        }
    }
    int g1, g2, g4;
    if (h % 2 == 0 && w % 2 == 1)
        swap(h, w);
    if (h % 2 && w % 2)
    {
        g1 = 1;
        g2 = (h + w) / 2 - 1;
        g4 = (h - 1) * (w - 1) / 4;
    }
    else if (h % 2 && w % 2 == 0)
    {
        g1 = 0;
        g2 = w / 2;
        g4 = (h - 1) * w / 4;
    }
    else
    {
        g1 = 0;
        g2 = 0;
        g4 = (h * w) / 4;
    }
    int flag = 0;
    while (g4)
    {
        int old = g4, latest = g4;
        for (int i = 0; i < 26; i++)
        {
            if (cnt[i] >= 4)
            {
                latest--;
                cnt[i] -= 4;
            }
        }
        if (latest == old)
        {
            flag = 1;
            break;
        }
        else
            g4 = latest;
    }
    while (g2)
    {
        int old = g2, latest = g2;
        for (int i = 0; i < 26; i++)
        {
            if (cnt[i] >= 2)
            {
                latest--;
                cnt[i] -= 2;
            }
        }
        if (latest == old)
        {
            flag = 1;
            break;
        }
        else
            g2 = latest;
    }
    while (g1)
    {
        int old = g1, latest = g1;
        for (int i = 0; i < 26; i++)
        {
            if (cnt[i] >= 1)
            {
                latest--;
                cnt[i]--;
            }
        }
        if (latest == old)
        {
            flag = 1;
            break;
        }
        else
            g1 = latest;
    }
    for (int i = 0; i < 26; i++)
    {
        if (cnt[i])
            flag = 1;
    }
    if (flag)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	string str;
	cin >> str;
	reverse(str.begin(),str.end());
	cout << str << endl;
}

Measured memory_bytes: 1172
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
int main(){
    int a,b; cin >> a >> b;
    if((a+b)%2 == 0) cout << (a+b)/2;
    else cout << "IMPOSSIBLE";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    int N;
    cin >> N;
    vl A(N);
    in(N,A);
    
    vl ans(N);
    ans[0] = 0;
    rep(i,N){
        if(i%2==0) ans[0] += A[i];
        else ans[0] -= A[i];
    }
    reps(i,1,N) ans[i] = A[i-1]*2-ans[i-1];
    
    outve(ans);
    
    
    

    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const ll INF = 1e17;
ll N, M, L, Q;
ll fuel[305][305];
ll dist[305][305];
ll s[105000], t[105000];
ll A[100000], B[100000], C[100000];

void input() {
    cin >> N >> M >> L;
    for(int i = 1; i <= M; i++) cin >> A[i] >> B[i] >> C[i];
    cin >> Q;
    for(int i = 1; i <= Q; i++) cin >> s[i] >> t[i];
}

void solve() {
    input();
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            fuel[i][j] = INF;
            dist[i][j] = INF;
        }
        fuel[i][i] = 0;
        dist[i][i] = 0;
    }
    for(int i = 1; i <= M; i++) {
        chmin(fuel[A[i]][B[i]], C[i]);
        chmin(fuel[B[i]][A[i]], C[i]);
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            for(int k = 1; k <= N; k++) {
                chmin(fuel[j][k], fuel[j][i] + fuel[i][k]);
            }
        }
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            if(i == j) continue;
            if(fuel[i][j] <= L) chmin(dist[i][j], 1LL);
        }
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            for(int k = 1; k <= N; k++) {
                chmin(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    for(int i = 1; i <= Q; i++) {
        if(dist[t[i]][s[i]] < INF) cout << dist[t[i]][s[i]] - 1 << "\n";
        else cout << -1 << "\n";
    }
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 4864
using System;
using System.Collections.Generic;
using System.Linq;

public static class Solution
{
    public static long Solve(long N, long X, long Mod)
    {
        long sum = 0;
        var list = new List<long>();
        var indexes = new Dictionary<long, int>();
        var a = X;
        list.Add(a);
        indexes[a] = 0;
        sum += a;
        var len = long.MaxValue;
        long seqSum = 0;
        long i = 0;
        while (++i < N)
        {
            a = a * a % Mod;
            list.Add(a);
            sum += a;
            if (indexes.ContainsKey(a))
            {
                var l = indexes[a];
                len = i - l;
                seqSum = list.Skip(l + 1).Sum();
                break;
            }
            indexes[a] = (int)i;
        }

        if (N - (i + 1) > len)
        {
            var count = (N - (i + 1)) / len;
            sum += seqSum * count;
            i += len * count;
        }

        while (++i < N)
        {
            a = a * a % Mod;
            sum += a;
        }

        return sum;
    }

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var N = vals[0];
        var X = vals[1];
        var Mod = vals[2];

        Console.WriteLine(Solve(N, X, Mod));
    }
}

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

int main(){
  int n;cin>>n;
  vector<int> arr(n+1);
  for(int i = 1; i <= n; i++){
     int t;cin>>t;
    arr[t] = i;
  }
  for(int i = 1; i <= n; i++) cout<<arr[i]<<" ";
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

inline int suit_to_id(char c) {
  switch (c) {
    case 'S':
      return 0;
    case 'H':
      return 13;
    case 'C':
      return 26;
    case 'D':
      return 39;
  }
  // should not reach here
  return 0;
}

inline char id_to_suit(int i) {
  switch (i) {
    case 0 ... 12:
      return 'S';
    case 13 ... 25:
      return 'H';
    case 26 ... 38:
      return 'C';
    case 39 ... 51:
      return 'D';
  }
  // should not reach here
  return 'S';
}

int main() {
  // 0..12 => S1..S13
  // 13..25 => H1..H13
  // 26..38 => C1..C13
  // 39..51 => D1..D13
  bool bits[52] = {false};

  int n;
  cin >> n;

  char c;
  int x;
  for (int i = 0; i < n; ++i) {
    cin >> c >> x;
    const int offset = suit_to_id(c);
    bits[offset + x - 1] = true;
  }

  for (int i = 0; i < 52; ++i) {
    if (!bits[i]) {
      const char s = id_to_suit(i);
      const int v = i - suit_to_id(s) + 1;
      cout << s << " " << v << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3052
#include <stdio.h>
int main(void)
{
  int a, b, c, x, y, z;
  
  scanf("%d %d %d", &a, &b, &c);

  if(a > b){
    x = a;
    a = b;
    b = x;
  }
  if(b > c){
    y = b;
    b = c;
    c = y;
  }
  if(a > b){
    z = a;
    a = b;
    b = z;
  }

  printf("%d %d %d\n", a, b, c); 
  return 0;
}

Measured memory_bytes: 596
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

hand_table = [[0, 0, P],[R, 0, 0],[0, S, 0]]

T_int = [0 if c == 'r' else 1 if c == 's' else 2 for c in T]

DP = []
for i in range(K):
    innerDP = [[hand_table[T_int[i]][0],hand_table[T_int[i]][1],hand_table[T_int[i]][2]]]
    DP.append(innerDP)

for i in range(K, N):
    offset = i % K
    loopnum = i // K
    DP[offset].append([max(DP[offset][loopnum - 1][1] + hand_table[T_int[i]][0], \
                           DP[offset][loopnum - 1][2] + hand_table[T_int[i]][0]), \
                       max(DP[offset][loopnum - 1][0] + hand_table[T_int[i]][1],DP[offset][loopnum - 1][2] + hand_table[T_int[i]][1]), \
                       max(DP[offset][loopnum - 1][0] + hand_table[T_int[i]][2],DP[offset][loopnum - 1][1] + hand_table[T_int[i]][2])])

ans = 0

for i in range(N - K, N):
    offset = i % K
    loopnum = i // K
    ans += max(DP[offset][loopnum])

print(ans)

Measured memory_bytes: 24176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    if(a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int N;
    cin >> N;
    vector<ll> T(N);
    for(int i=0; i<N; i++) cin >> T[i];

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

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main() {
	char s[110];
	int a,b;
	scanf("%d%d%s",&a,&b,&s);
	if(s[a]!='-') {
		cout<<"No"<<endl;
		return 0;
	} else {
		for(int i=0; i<=a+b; i++)
			if((s[i]<'0'||s[i]>'9')&&i!=a) {
				cout<<"No"<<endl;
				return 0;
			}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(a, b):
    return pow(a, 5) - pow(b, 5)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X = ii()

    for a in range(-120, 120):
        for b in range(-120, 120):
            if f(a, b) == X:
                print(a, b)
                exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9556
#define taskname ""
#include <bits/stdc++.h>

using namespace std;

const int maxN = 2e5 + 2;

int n;
int a[maxN];
int p = 0;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
    cin >> n;
    a[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    a[n + 1] = 0;
    for (int i = 0; i <= n; ++i)
    {
        p += abs(a[i + 1] - a[i]);
    }
    for (int i = 1; i <= n; ++i)
    {
        cout << p - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]) << '\n';
    }
    return 0;
}


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

int main() {
  string cells;
  cin >> cells;
  string cellsArray[3];
  cellsArray[0] = cells.substr(0, 1);
  cellsArray[1] = cells.substr(1, 1);
  cellsArray[2] = cells.substr(2, 1);
  int count = 0;
  for (int i = 0; i < 3; i ++){
  	if(cellsArray[i] == "1"){
    	count++;
    } 
  }
  cout << count << endl;
}


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  string s; cin >> s;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'o') cnt++;
  }

  if(15-(int)s.size() + cnt >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
l=["A",'B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',"A",'B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
n=int(input())
s=input()
ans=""
for i in range(len(s)):
    ans+=l[l.index(s[i])+n]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <math.h>
using namespace std;

int main()
{
	int N;
	std::cin >> N;
	string s;
	vector<string> S;
	for (int i = 0; i < N; i++) {
		std::cin >> s;
		S.push_back(s);
	}

	std::sort(S.begin(), S.end());
	S.erase(std::unique(S.begin(), S.end()), S.end());

	std::cout << S.size() << std::endl;
	
	return 0;
}

	


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

int main(){

	int n, y;

	cin >> n;
	cin >> y;

	for (int i = 0; i <= n; ++i){
		for (int j = 0; j <= n - i; ++j){
			if(10000 * i + 5000 * j + 1000 * (n - i - j) == y){
				cout << i << " " << j << " " << n - i - j << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;

	return 0;

}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    n = len(s)
    l = r = -1
    ans = 0
    for i in range(1, n):
        if s[i] == s[i - 1]:
            if l == -1:
                l = i
            else:
                r = i
        if r != -1:
            ans += r - l
            r = l = -1
    if l != -1:
        ans += n - l
    print(min(ans, n - ans))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 49520
#include <stdio.h>
int main(int argc, const char * argv[])
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a<b && b<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

using namespace std;
using ll = long long;

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

  int n, m;
  cin >> n >> m;
  cout << (n * (n - 1) / 2 + m * (m - 1) / 2) << endl;

  return 0;
}


Measured memory_bytes: 3648
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i64 = input();
    let m: i64 = input();

    if m <= n * 2 {
        println!("{}", m / 2);
    } else if m > n * 2 {
        let m = m - n * 2;
        println!("{}", n + m / 4);
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    //int n=scanner.nextInt();
    //int k=scanner.nextInt();
    String S=scanner.next();
    int flg=0;

    for(int i=0;i<S.length()-1;i++){
      //char str=S.charAt(i);
      if(S.charAt(i)==S.charAt(i+1)){
        flg=1;
        break;
      }
    }

    if(flg==1){
      System.out.println("Bad");
    }
    else{
      System.out.println("Good");
    }



  }
}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    
    cout<<a/b<<endl;
    
    cout<<a-a/b*b<<endl;
    
    double x = a,y = b;
    
    cout<<fixed<<setprecision(9)<<x/y<<endl;
    
    return 0;
}


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

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

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

const int mod = 1000000007;

int main() {
    ll n, a, b; cin >> n >> a >> b;
    ll s = a + b;
    ll r = n / s;
    ll q = n - s * r;
    
    ll ans = r * a;
    ans += min(q,a);
    cout << ans << endl;
    return 0;
}


























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

ll n;

ll ar[10005];

int main(){
	scanf("%lld", &n);
	for(int k = 1; k<= 100; k++){
		for(int s = 1; s<= 100; s++){
			for(int t = 1; t<= 100; t++){
				if(k*k + s*s + t*t + k*s + s*t + t*k <= 10000){
					ar[k*k + s*s + t*t + k*s + s*t + t*k ]++;
				}
			}
		}
	}
	for(int k = 1; k<= n; k++){
		printf("%lld\n", ar[k]);
	}
}

Measured memory_bytes: 3816
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if (s < t) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    double T, X;  cin >> T >> X;

    double ans = T / X;

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

    return 0;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);


    int s, w;
    cin >> s >> w;

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








Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int,int>;
const int INF = 1e18;
const int MOD = 1e9+7;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

signed main(){
    string S;
    cin >> S;
    char last = S[0];

    int ans = 0;
    for(int i=1;i<S.size();i++){
        if(last != S[i]){
            ans++;
            last = S[i];
        }
    }

    put(ans);
    
}


Measured memory_bytes: 512
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;
#define llong long long
int main()
{
   int N;
   cin >> N;
   vector<pair<llong, llong> > j(N);
   for(int i = 0; i < N; i++)
   {
      cin >> j[i].second >> j[i].first;
   }
   sort(j.begin(), j.end());
   bool ans = true;
   llong time = 0;
   for(int i = 0; i < N; i++)
   {
       time += j[i].second;
      if(time > j[i].first)
      {
         ans = false;
      }
   }
   cout << (ans ? "Yes" : "No") << endl;
   return 0;
}


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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    if(n%(a+b)==0)
    {
        cout<<a*(n/(a+b))<<endl;
    }
    else
    {
        ll d=n/(a+b);
        ll m=n-(d*(a+b));
        if(m>a)
        {
            cout<<a*d+a<<endl;
        }
        else
        {
            cout<<a*d+m<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, M, *X = map(int,open(0).read().split())

uf = UnionFind(N + 1)

S = N * (N - 1) // 2
r = [S]

while X:
  b, a = X.pop(), X.pop()
  if not uf.same(a, b):
    S -= uf.size(a) * uf.size(b)
  r.append(S)
  uf.union(a, b)

for a in r[-2::-1]:
  print(a)

Measured memory_bytes: 25076
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P
{
    public static void Main()
    {
        var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var h = hw[0];
        var w = hw[1];
        var map = Enumerable.Repeat(0, h).Select(_ => Console.ReadLine().Select(x => x == '.').ToArray()).ToArray();
        int[][] cost = Enumerable.Range(0, h * w).Select(_ => Enumerable.Repeat(13333, h * w).ToArray()).ToArray();
        for (int i = 0; i < h * w; i++)
            cost[i][i] = 0;
        for (int i = 0; i < h - 1; i++)
            for (int j = 0; j < w; j++)
            { var id = i * w + j; if (map[i][j] && map[i + 1][j]) cost[id][id + w] = (cost[id + w][id] = 1); }
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w - 1; j++)
            { var id = i * w + j; if (map[i][j] && map[i][j + 1]) cost[id][id + 1] = (cost[id + 1][id] = 1); }
        for (int i = 0; i < cost.Length; i++)
            for (int j = 0; j < cost.Length; j++)
                for (int k = 0; k < cost.Length; k++)
                    cost[j][k] = Min(cost[j][k], cost[j][i] + cost[i][k]);
        Console.WriteLine(cost.Max(x => x.Max(y => 13333 == y ? -1 : y)));
    }
}


Measured memory_bytes: 15700
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    n = I()
    aa = [LS() for _ in range(n)]
    a = []
    for i in range(n):
        s,t= aa[i]
        t = int(t)
        a.append((s,-t,i+1))
    a.sort()

    return '\n'.join(map(lambda x: str(x[2]), a))


print(main())



Measured memory_bytes: 7880
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
vector<ll> fac, finv, inv;
void COMinit(const int MAX = 5000000, const ll &MOD = MOD){
  fac.resize(MAX);finv.resize(MAX);inv.resize(MAX);
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  repd(i,2,MAX){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
ll COM(int n, int k){
  if(n < k)return 0;
  if(n < 0 || k < 0)return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int n,a,b;
signed main(){
  cin>>n>>a>>b;
  COMinit();
  int ans = modpow(2, n)-1;
  int sum = 1;
  for(int i = n;i >= n-a+1;i--)sum = (sum*i)%MOD;
  repd(i,1,a+1)sum = (sum * modinv(i))%MOD;
  ans += MOD-sum;ans %= MOD;
  sum = 1;
  for(int i = n;i >= n-b+1;i--)sum = (sum*i)%MOD;
  repd(i,1,b+1)sum = (sum * modinv(i))%MOD;
  ans += MOD - sum;
  ans %= MOD;
  cout << ans << endl;
}


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

ll power(ll x, ll y)
{
	ll m=1;
	for(int i=1;i<=y;i++) m=m*x;
	return m;
}

char crt(int x)
{
	return x+'a'-1;
}

int main()
{
	ll n;
	cin>>n;
	ll x=n,y;
	string s="";
	for(int i=1;x>0;i++)
	{
		y=x%26;
//		cout<<y<<" "<<x<<endl;
		if(y==0) s += crt(26);
		else s += crt(y);
		if(y==0) x = x/26 -1;
		else x /= 26;

	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
using namespace std;
long gcd(long a, long b){
  if(b == 0){
    return a;
  }
  return gcd(b, a % b);
}
int main(){
  long a, b;
  while(cin >> a >> b){
    cout << gcd(a, b) << " ";
    cout << (a * b) / gcd(a, b) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vll vector<ll>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

template<typename T>
void vecin(vector<T>& v, int n = 0){
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n-1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}
void print(string s){
    cout << s << endl;
}

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

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String ss1 = s.substring(0,s.length()/2);
        String ss2 = s.substring(s.length()/2,s.length());
        System.out.println(ss1.equals(ss2)?"Yes":"No");
    }
}

Measured memory_bytes: 21844
import sys
import math
import itertools

n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [True] * n
lis = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    lis[a - 1] = max(lis[a - 1], h[b - 1])
    lis[b - 1] = max(lis[b - 1], h[a - 1])
ans = 0
for i in range(n):
    if lis[i] < h [i]:
        ans += 1
print(ans)


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

int main() {
    int N,K;
    cin >> N >> K;
    int h;
    int count = 0;
    for (int i = 0;i < N;i++){
        cin >> h;
        if (h >= K) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<string> s(n);
   vector<int> t(n);
   f(i,0,n){
      cin >> s[i] >> t[i];
   }
   int in = -1;
   string x;
   cin >> x;
   f(i,0,n){
      if(s[i] == x){
         in = i+1;
         break;
      }
   }
   int ans = 0;
   f(i,in,n){
      ans += t[i];
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int n, k;
    std::cin >> n >> k;

    std::vector<int> v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
    }

    long long ans = 0;
    for (int num_dequeue = 0; num_dequeue <= k; num_dequeue++) {
        for (int right_pop = 0; right_pop <= num_dequeue; right_pop++) {
            std::vector<int> copied_v = v;
            std::priority_queue<int, std::vector<int>, std::greater<int>> q;

            for (int i = 0; i < right_pop && copied_v.size(); i++) {
                q.push(copied_v.back());
                copied_v.pop_back();
            }

            std::reverse(copied_v.begin(), copied_v.end());

            for (int i = 0; i < num_dequeue - right_pop && copied_v.size(); i++) {
                q.push(copied_v.back());
                copied_v.pop_back();
            }

            for (int i = 0; i < k - num_dequeue && q.size() && q.top() < 0; i++) {
                q.pop();
            }

            long long sum = 0;
            while (q.size()) {
                sum += q.top();
                q.pop();
            }

            ans = std::max(ans, sum);
        }
    }

    std::cout << ans << std::endl;
}


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

const int MAX = 100000;
const int64_t INF = 4611686018427387903; // 2^62-1、使わない辺とかに用いる

typedef struct node {
	int myID; // ユニークID, まぁデバッグ用？
	vector<pair<int, int> > edge; // 移動辺
	vector<int64_t> costs; // 確定したコスト
	bool isSearch; // 調べ中か否か
	bool done; // 確定ノードか否か
	int64_t cost; // 現時点のコスト
	
	bool operator<(const node& a) const {
		return cost > a.cost;
	}
} Node;

typedef class dijkstra {
	private:
		int N; // 頂点数
		vector<Node> node;
		void init(int s);
	public:
		dijkstra(int n);
		void addEdge(int n, int m, int cost);
		void calc(int s);
		int64_t getCost(int s, int t);
} Dijkstra;

/**
 * 頂点数を渡してください、初期化します。
 * @param n 頂点の数
 */
dijkstra::dijkstra(int n) {
	N = n;
	node.resize(n);
	for (int i = 0;i < N;i ++) {
		node[i].edge.clear();
		node[i].myID = i;
	}
}

/**
 * 頂点nと頂点mの間にcostの重み付き無向辺を作ります。
 * @param n 行く側の頂点
 * @param m 向かう側の頂点
 * @param cost 移動コスト
 */
void dijkstra::addEdge(int n, int m, int cost) {
	node[n].edge.push_back(make_pair(m, cost));
	node[m].edge.push_back(make_pair(n, cost));
}

void dijkstra::init(int s) {
	for (int i = 0;i < N;i ++) {
		node[i].done = false;
		node[i].isSearch = false;
		node[i].cost = INF;
	}
	node[s].cost = 0;
}
/**
 * ダイクストラ法を実行します。O(VlogE)です。
 */
void dijkstra::calc(int s) {
	init(s);
	priority_queue<Node> que; // コスト、頂点
	que.push(node[s]);
	
	Node check;
	while(!que.empty()) {
		check = que.top();
		que.pop();
		
		check.done = true;
		for (int i = 0;i < check.edge.size();i ++) {
			if (check.cost + check.edge[i].second < node[check.edge[i].first].cost) { // より近い経路発見！
				node[check.edge[i].first].cost = check.cost + check.edge[i].second;
				if (!node[check.edge[i].first].isSearch) {
					que.push(node[check.edge[i].first]);
//					node[check.edge[i].first].isSearch = true;
				}
			}
		}
	}
	node[s].costs.resize(N);
	for (int i = 0;i < N;i ++) node[s].costs[i] = node[i].cost;
}

/**
 * 頂点sから頂点tへ行くまでの最短コストを返します。
 * @param s 始点となる頂点
 * @param t 終点となる頂点
 * @return sからtまでの最短コスト
 */
int64_t dijkstra::getCost(int s, int t) {
	return node[s].costs[t];
}

int main() {
	int n, m, s, t, u, v, a, b;
	cin >> n >> m >> s >> t;
	
	int64_t snuke = 1000000000000000; // 持ち金
	Dijkstra map1(n), map2(n);
	for (int i = 0;i < m;i ++) {
		cin >> u >> v >> a >> b;
		map1.addEdge(u - 1, v - 1, a);
		map2.addEdge(u - 1, v - 1, b);
	}
	map1.calc(s - 1);
	map2.calc(t - 1);
	
	static pair<int64_t, int> cost[MAX];
	for (int i = 0;i < n;i ++) { // iは両替を行う都市
		cost[i] = make_pair(map1.getCost(s - 1, i) + map2.getCost(t - 1, i), i);
	}
	
	sort(cost, cost+n);
	
	int read = 0;
	for (int i = 0;i < n;i ++) {
		while(cost[read].second < i) read ++; // その両替所は存在しない！
		
		cout << snuke - cost[read].first << endl;
	}
	
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

さて、下準備
まず、都市sから他の全ての都市への円を用いた最短経路を出す
次に、その全ての都市から都市tへのスヌークを用いた最短経路を出す 逆に出せば良いのよ、tからね

最後に、どの都市で両替したら良いかを最終スヌークが多い順にソートして持っておこう

さて、この時i年目について高速に求めてみよう
と言っても、答えはソートした奴を上から見て、両替所が存在していればそれが答え

DijkstraでO(nlog(m))、ソートにO(nlog(n))、上から見てくのO(n)だしO(nlog(m))かなぁ(O(max(n,m))=O(m)なので)

ただいまデバッグ中
*/

Measured memory_bytes: 32684
#include <iostream>
#include <string>

using namespace std;
char t[200010],d[200010];
int main(){
	int i,n,q;
	string s;
	cin >> n >> q >> s;
	for(i=0;i<q;i++){
		cin >> t[i] >> d[i];
	}
	int l = -1,r = n;
	for(i=q-1;i>=0;i--){
		if(d[i]=='L'){
			if(l<n-1 && s[l+1]==t[i]) l++;
			if(r<n && s[r]==t[i]) r++;
		}else{
			if(r>0 && s[r-1]==t[i]) r--;
			if(l>=0 && s[l]==t[i]) l--;
		}
	}
	cout << max(0,r - l - 1) << endl;
}

Measured memory_bytes: 900
import java.util.*;

public class Main{

	static int[][] multi;
	static int[] matR;
	static int[] matC;

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		multi = new int[n][n];
		matR = new int[n];
		matC = new int[n];

		for(int i = 0; i < n; i++){
			matR[i] = scan.nextInt();
			matC[i] = scan.nextInt();
		}

		System.out.println(Mat(0, n-1));

		scan.close();
		System.exit(0);
	}

	private static int Mat(int fr, int to){
		if(fr == to)
			return 0;
		if(multi[fr][to] == 0){
			int min = Integer.MAX_VALUE;
			for(int i = fr; i < to; i++){
				int r = Mat(fr, i) + Mat(i+1, to) + (matR[fr] * matC[i] * matC[to]);
				if(r < min)
					min = r;
			}
			multi[fr][to] = min;
		}
		return multi[fr][to];
	}
}

Measured memory_bytes: 27116
import java.util.*;
import java.io.*;
class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int ar[][] = new int[n][3];
		for(int i = 0; i < n; i++) {
			String input[] = (br.readLine()).trim().split("\\s+");
			ar[i][0] = Integer.parseInt(input[0]);
			ar[i][1] = Integer.parseInt(input[1]);
			ar[i][2] = Integer.parseInt(input[2]);                           
		}
		int a = ar[0][0], b = ar[0][1], c = ar[0][2];
		for(int i = 1; i < n; i++) {
			// picking a
			int oldA = a, oldB = b, oldC = c;
			a = ar[i][0] + Math.max(oldB, oldC);
			b = ar[i][1] + Math.max(oldA, oldC);
			c = ar[i][2] + Math.max(oldA, oldB);
		}
		System.out.println(Math.max(a, Math.max(b, c)));
	}
}


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

int main(void)
{
  int n,a,b;
  cin>>n>>a>>b;
  int mx,mi;
  if(a>=b)
    mx=b;
  else
    mx=a;
  if(a+b<=n)
    mi=0;
  else
    mi=a+b-n;
  cout<<mx<<' '<<mi<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, a, b[100005];
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a);
		a++;
		*(lower_bound(b,b+n,a)-1) = a;
	}
	printf("%d\n",n-(lower_bound(b,b+n,1)-b));
}

Measured memory_bytes: 640