akhauriyash/Code-Regression huggingface dataset:
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         Thing[] arr = new Thing[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = new Thing(i,Integer.parseInt(st.nextToken()));
         //dp(a,b) = best answer when a have been pushed front, b pushed back
         dp = new long[N+1][N+1];
         for(int i=0; i <= N; i++)
            Arrays.fill(dp[i], -1);
         Arrays.sort(arr);
         System.out.println(dfs(0,0,arr));
      }
      static long[][] dp;
      public static long dfs(int a, int b, Thing[] arr)
      {
         if(dp[a][b] != -1)
            return dp[a][b];
         int N = dp.length-1;
         if(a+b == N)
            return 0L;
         Thing curr = arr[a+b];
         long res = (long)curr.val*Math.abs(curr.index-a)+dfs(a+1,b,arr);
         res = Math.max(res, (long)curr.val*Math.abs(curr.index-(N-1-b))+dfs(a,b+1,arr));
         return dp[a][b] = res;
      }
   }
   class Thing implements Comparable<Thing>
   {
      public int index;
      public int val;
      
      public Thing(int a, int b)
      {
         index = a;
         val = b;
      }
      public int compareTo(Thing oth)
      {
         return oth.val-val;
      }
   }

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

void cxxio() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}

int main() {
    cxxio();
    ll I, O, J, L, _;
    cin>>I>>O>>_>>J>>L;
    ll ans=O;
    if (I&&J&&L&&I%2+J%2+L%2>=2)
        ans+=3, I--, J--, L--;
    ans+=I/2*2;
    ans+=J/2*2;
    ans+=L/2*2;
    cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <set>

using namespace std;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  multiset<int> s;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    s.insert(-x);
  }
  for (int i = 0; i < m; ++i) {
    int x = *s.begin();
    s.erase(s.begin());
    s.insert(x / 2);
  }
  long long ans = 0;
  for (int e : s) {
    ans -= e;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 4864
//
//  main.cpp
//  ABC165
//
//  Created by 安藤光希 on 2020/05/02.
//  Copyright © 2020 安藤光希. All rights reserved.
//

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


int main() {
    int K, A,B;
    cin >> K;
    cin >> A >> B;
    string result;
    result = "NG";
    
    for (int i = A; i < B+1; i++){
        //cout << i << endl;
        if (i % K == 0) {
            result = "OK";
            break;
        } else {
            continue;
        }
    }
    
    cout << result << endl;
    
}


Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
#include<queue>

using namespace std;

int n, m;
int a[51][51] = { 0 };
int b[51][51] = { 0 };
char buf[51];


bool search(int x, int y)
{
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (a[x + i][y + j] != b[i][j]) {
				return false;
			}
		}
	}
	return true;
}

int main()
{

	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> buf;
		for (int j = 0; j < n; j++) {
			a[i][j] = buf[j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> buf;
		for (int j = 0; j < m; j++) {
			b[i][j] = buf[j];
		}
	}

	bool flag = false;
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m; j++) {
			if (search(i, j) == true) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int n, m;
    cin >> n >> m;
    vector<modint> x(n), y(m);
    for(int i = 0; i < n; ++i)  cin >> x[i];
    for(int i = 0; i < m; ++i)  cin >> y[i];
    modint X = 0, Y = 0;
    for(int i = 1; i < n; ++i){
        X += modint(i) * x[i];
        X -= modint(i) * x[n - i - 1];
    }
    for(int i = 1; i < m; ++i){
        Y += modint(i) * y[i];
        Y -= modint(i) * y[m - i - 1];
    }
    modint ans = X * Y;
    cout << ans << endl;
}

Measured memory_bytes: 1024
x, y, *_ = gets.split.map(&:to_i)
la = gets.split.map(&:to_i).sort.last(x)
lb = gets.split.map(&:to_i).sort.last(y)
lc = gets.split.map(&:to_i)
puts (la + lb + lc).sort.last(x+y).inject(:+)

Measured memory_bytes: 30860
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  ll a,b=0;
  ll ans=0;
  for(ll i=0;i<n;i++){
    cin >> a;
    if(a>=b){
      b=a;
    }
    else{
      ans+=b-a;
    }
  }
  cout << ans << endl;


}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int b = a.size();
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  if(b==a.size()){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
  
}


Measured memory_bytes: 1024
n = int(input())
*A, = map(int, input().split())
# n = 6
# A = [8, 6, 9, 1, 2, 1]
# n = 4
# A = [1, 3, 4, 2]
A = [(a, i) for i, a in enumerate(A)]
A.sort(reverse=True)
DP = [[0 for r in range(n+1)] for l in range(n+1)]
for l in range(n):
    for r in range(n-l):
        a, i = A[l+r]
        DP[l+1][r] = max(DP[l+1][r], DP[l][r]+a*abs(i-l))
        DP[l][r+1] = max(DP[l][r+1], DP[l][r]+a*abs(i-(n-1-r)))
print(max([DP[l][n-l] for l in range(n)]))


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

namespace B___Some_Sums
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var n = int.Parse(input[0]);
            var a = int.Parse(input[1]);
            var b = int.Parse(input[2]);
            var c = new List<string>();
            var ans = new List<int>();

            for (var i = 1; i <= n; i++)
            {
                c.Add(i.ToString());
            }
            for (var i = 0; i < n; i++)
            {
                var d = 0;
                for (var j = 0; j < c[i].Length; j++)
                {
                    d += int.Parse(c[i][j].ToString());
                }
                if (d >= a && d <= b)
                {
                    ans.Add(int.Parse(c[i]));
                }
            }
            Console.WriteLine(ans.Sum());
        }
    }
}

Measured memory_bytes: 13408
#include <cstdint>
#include <string>

using namespace std;

struct process_t {
  string name;
  uint32_t time;
  bool operator==(const process_t &p1) const
  {
    return (p1.name == this->name) && (p1.time == this->time);
  }
};

#define ARRAY_SIZE 100000
process_t processes[ARRAY_SIZE];
uint32_t head, tail;

bool queue_dequeue(process_t &process)
{
  if (head == tail) return false;
  process = processes[head];
  head++;
  head %= ARRAY_SIZE;
  return true;
}

void queue_enqueue(process_t process)
{
  processes[tail] = process;
  tail++;
  tail %= ARRAY_SIZE;
}

bool queue_empty()
{
  if (head == tail)
    return true;
  else
    return false;
}

#if !defined(TEST)
#include <iostream>

int32_t main()
{
  uint32_t num, quantum;
  cin >> num >> quantum;

  for (uint32_t i = 0; i < num; i++) {
    string name;
    uint32_t time;
    cin >> name >> time;
    process_t process = {.name = name, .time = time};
    queue_enqueue(process);
  }

  uint32_t time = 0;
  while (!queue_empty()) {
    process_t process;
    queue_dequeue(process);
    uint32_t process_time = min(process.time, quantum);
    process.time -= process_time;
    time += process_time;
    if (process.time) {
      queue_enqueue(process);
    } else {
      cout << process.name << ' ' << time << endl;
    }
  }

  return 0;
}
#endif

Measured memory_bytes: 7080
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

total = 0
for i in range(N + 1):
    total += abs(A[i + 1] - A[i])
for i in range(N):
    print(total + abs(A[i + 2] - A[i]) - (abs(A[i + 1] - A[i] ) + abs(A[i + 2] - A[i + 1])))


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}


int mood[101010];
map<int,int> moodset[101010];

int mm,nn,aa;

int main(){
    int i,j,k;
    int x,y;
    int u,s;
    
    cin >> nn >> mm;
    
    for (i=1;i<=nn;i++){
        scanf("%d",&x);
        mood[x%mm]++;
        moodset[x%mm][x]++;
    }
    //debuga(mood,mm)
    int result = 0;
    for (i=1;i<(mm+1)/2;i++){
        j = mm-i;
        k = min(mood[i],mood[j]);
        //printf("%d  %d %d %d  %d\n",i,mood[j],mood[i],k,result);
        result += k;
        
        u = mood[i] > mood[j] ? i : j;
        s = 0;
        for (auto p : moodset[u]){
            s+=p.second/2;
        }
        result+=min((mood[u]-k)/2,s);
        
        // mood[i]-=k;
        // mood[j]-=k;
        // result+=mood[i]/2 + mood[j]/2;
    }
    
    if (mm%2==0){
        result+=mood[mm/2]/2;
    }
    result+=mood[0]/2;
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 10112
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int A[100010]={};
int P[100010]={};
int main(){
    int N,K,Q;
    cin >> N >> K >> Q;
    //for(int i = 1;i<N+1;i++){
    //    P[i] = K;
    //}
    for(int i = 1;i<Q+1;i++){
        cin >> A[i];
        P[A[i]]++;
    }
    for(int i = 1; i<N+1; i++){
        P[i] += K - Q;
    }
    for(int i = 1; i<N+1; i++){
        if(P[i] <= 0){
            cout << "No"<<endl;
        }else{
            cout << "Yes"<< endl;
        }
    }
}


Measured memory_bytes: 1408
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt();
            int aLast = 0, bLast = 0, cLast = 0;
            for (int i = 0; i < n; i++) {
                int a = inp.nextInt(), b = inp.nextInt(), c = inp.nextInt();
                int aLast2 = aLast, bLast2 = bLast, cLast2 = cLast;
                aLast = Math.max(bLast2, cLast2) + a;
                bLast = Math.max(aLast2, cLast2) + b;
                cLast = Math.max(aLast2, bLast2) + c;
            }
            out.print(Math.max(Math.max(aLast, bLast), cLast));
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    int n,maxa=0,mina=0;
    cin>>n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        
        if(a[i]>a[maxa]) maxa=i;
        if(a[i]<a[mina]) mina=i;
    }
    
    cout<<2*n-1<<endl;
    if(abs(a[maxa])>=abs(a[mina]))
    {
        for(int i = 0; i < n; i++)
        {
            cout<<maxa+1<<" "<<i+1<<endl;
        }
        
        for(int i = 0; i < n-1; i++)
        {
            cout<<i+1<<" "<<i+2<<endl;
        }
        cout<<endl;        
    }
    else
    {
        for(int i = 0; i < n; i++)
        {
            cout<<mina+1<<" "<<i+1<<endl;
        }
        
        for(int i = n-1; i > 0; i--)
        {
            cout<<i+1<<" "<<i<<endl;
        }
        cout<<endl;  
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cerr << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> PII;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}


ll N, M, Q;
ll a[51][4];

ll score(ll A[]) {
    ll ans = 0;
    for (int i = 0; i <= Q; i++) {
      if (A[a[i][1]] - A[a[i][0]] == a[i][2]) {
        ans += a[i][3];
      }
    }
    return ans;
}


int dfs(int count, int put, ll A[]) {
  A[count] = put;
  count++;
  if (count == N) {
    //debug(score(A));
    return score(A);
  }

  ll score = 0;
  for (int i = put; i <= M; i++) {
    ll t = dfs(count, i, A);
    score = MAX(score, t);
  }
  return score;
}

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

    cin >> N >> M >> Q;

    REP(i, Q) {
      cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
      REP(j, 2) {
        a[i][j]--;
      }
    }
    
    ll A[N];
    ll ans = 0;
    REP(i, N) {
      A[i] = 0;
    }

    for (int i = 1; i <= M; i++) {
      ll t = dfs(0, i, A);
      ans = MAX(t, ans);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <vector>
using namespace std;
struct segK{//非再帰
    int n;
    long long MIN;
    int size;
    vector<long long> dat;
    segK(int n_){
        n = 1;
        MIN = 0;
        size = n_;
        while(n < n_) n *= 2;
        dat.resize(2 * n);
        for(int i = 1; i < 2 * n; i++) dat[i] = MIN;
    }
    void update(int k, long long a){
        k += n;
        dat[k] = a;
        while(k > 0){
            k >>= 1;
            dat[k] = max(dat[k << 1 | 0], dat[k << 1 | 1]);
        }
    }
    long long query(int l, int r){
        long long res = 0;
        l += n;
        r += n;
        while(r > l){
            if(l & 1) res = res + dat[l++];
            if(r & 1) res = res + dat[--r];
            l >>= 1;
            r >>= 1;
        }
        return res;
    }
    int right_bin(int l, long long v) {
        if(l == size) return l;
        l += n;
        do {
            while (l % 2 == 0) l >>= 1;
            if (dat[l] >= v) {
                while (l < n) {
                    l = (2 * l);
                    if (dat[l] < v) {
                        l++;
                    }
                }
                return l - n;
            }
            l++;
        } while ((l & -l) != l);
        return size - 1;
    }
    int left_bin(int r, long long v) {
        if(r == 0) return r;
        r += n;
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (dat[r] <= v) {
                while (r < n) {
                    r = (2 * r + 1);
                    if (dat[r] > v) {
                        r--;
                    }
                }
                return r - n;
            }
        } while ((r & -r) != r);
        return size - 1;
    }
};

int main(){
    long long N, Q;
    cin >> N >> Q;
    segK segtate(N), segyoko(N);
    long long sum = (N - 2) * (N - 2);
    segtate.update(N - 1, N - 1);
    segyoko.update(N - 1, N - 1);
    for(int i = 0; i < Q; i++){
        int t, x;
        cin >> t >> x;
        x--;
        if(t == 1){
            long long ind = segtate.right_bin(0, x);
            sum -= ind - 1;
            segyoko.update(x, ind);
        }
        else {
            long long ind = segyoko.right_bin(0, x);
            sum -= ind - 1;
            segtate.update(x, ind);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 11456
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  cin>>s;
  int cnt=0;
  REP(i,s.size()){
    
    if(i==0){
      if(s[i]=='A'){
        continue;
      }else{
        cout<<"WA"<<endl;
        return 0;
      }
    }
    
    if(s[i]=='C' && i>=2 && i<=s.size()-2){
      cnt++;
      continue;
      }else{
      if(s[i]-'a'<26 && s[i]-'a'>=0){
        continue;
      }else{
        cout<<"WA"<<endl;
        return 0;
      }
    }
  }
  
  if(cnt!=1){
    cout<<"WA"<<endl;
  }else{
    cout<<"AC"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import math
N, M = map(int, input().split())
sqrt = int(math.sqrt(M)) + 1
ans = 0
for i in range(1, sqrt):
    if M % i == 0:
        if ans < i <= M//N:
            ans = i
        if ans < M//i <= M//N:
            ans = M//i
print(ans)


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

int p[MAXN];

int sz[MAXN];

vi g[MAXN];

int gr[MAXN], gr1[MAXN];

int used[MAXN];

set<pii> st;

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, n){
		scanf("%d", &p[i]);
		sz[p[i]]++;
		g[p[i]].pb(i);
	}
	REPN(i, 1, n){
		st.insert(mp(sz[i], i));
		gr[i] = -1;
	}
	while(st.begin()->_1 == 0){
		int s = st.begin()->_2;
		st.erase(st.begin());
		st.erase(mp(sz[p[s]], p[s]));
		sz[p[s]]--;
		st.insert(mp(sz[p[s]], p[s]));
		
		REP(i, 0, SZ(g[s])){
			int to = g[s][i];
			used[gr[to]] = s;
		}
		for(gr[s] = 0; used[gr[s]] == s; gr[s]++);
	}

	int mn = n + 5, mx = 0;
	FA(it, st){
		int s = it->_2;
		REP(i, 0, SZ(g[s])){
			int to = g[s][i];
			if (st.find(mp(sz[to], to)) == st.end()){
				used[gr[to]] = s;
			}
		}
		for(gr[s] = 0; used[gr[s]] == s; gr[s]++);
		for(gr1[s] = gr[s] + 1; used[gr1[s]] == s; gr1[s]++);
		mn = min(mn, gr[s]);
		mx = max(mx, gr[s]);
	}
	
	/*REPN(i, 1, n){
		printf("%d %d\n", gr[i], gr1[i]);
	}*/
	
	if (mn == mx && SZ(st) % 2 == 1){
		printf("IMPOSSIBLE\n");
	} else {
		printf("POSSIBLE\n");
	}
	
	
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 22528
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}



ll sz[52],patty[52];

ll cnt;


ll call(ll n)
{
    if(cnt<=0)return 0;

      if(sz[n]<=cnt)
      {
          cnt-=sz[n];

          return patty[n];
      }

      cnt--;

      ll ans=0;


      if(cnt)ans+=call(n-1);

      if(cnt)
      {
          ans++;
          cnt--;
      }

      if(cnt)ans+=call(n-1);

      return ans;
}
int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,q,l,r,ans=0;

      bool flag=false;

      cin>>n>>cnt;


      sz[0]=1;

      patty[0]=1;

      for(i=1; i<=50; i++)
      {
         sz[i]=3+(sz[i-1]*2);

         patty[i]=1+(2*patty[i-1]);
      }

      cnt--;

      if(cnt)
       ans+=call(n-1);

       if(cnt)cnt--,ans++;


       if(cnt)
      ans+=call(n-1);

      cout<<ans<<endl;





}



Measured memory_bytes: 3608
MOD=10**9+7
N=int(input())

mp=['A','C','G','T']
out=['AGC','ACG','GAC']

dp = [[[[0 for i in range(4)] for j in range(4)] for k in range(4)] for l in range(N)]
for i in range(4):
    for j in range(4):
        for k in range(4):
            if mp[k]+mp[j]+mp[i] in out:continue
            dp[2][i][j][k]=1

for k in range(3,N):
    for x in range(4):
        for y in range(4):
            for i in range(4):
                for j in range(4):
                    if mp[i]+mp[y]+mp[x] in out:continue
                    if mp[j]+mp[y]+mp[x] == 'AGC': continue
                    if mp[j]+mp[i]+mp[x] == 'AGC': continue
                    #print(mp[j]+mp[i]+mp[y]+mp[x])
                    dp[k][x][y][i] = (dp[k][x][y][i] + dp[k-1][y][i][j])%MOD
#for d in dp:
#    print(d)
res=0
for d in dp[-1]:
    for row in d:
        res=(res+sum(row))%MOD
print(res)

"""
print('------------')
cnt=0
for a in range(4):
    for b in range(4):
        for c in range(4):
            for d in range(4):
                if (mp[a]+mp[b]+mp[c] in out) or (mp[b]+mp[c]+mp[d] in out): continue
                print(mp[a]+mp[b]+mp[c]+mp[d])
                cnt+=1
print(cnt)
"""


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int a=0,b=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C')a=1;
    if(a==1&&s[i]=='F')b++;
  }
  if(a>0&&b>0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int A, B;
	cin >> A >> B;

	int ans = -1;
	for (int i = 0; i < 1000000; i++) {
		int a = 8 * i / 100;
		int b = 10 * i / 100;

		if (a == A && b == B) {
			ans = i;
			break;
		}

	}

	cout << ans << "\n";

	return 0;
}



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

int main(){
	string str;
	cin >> str;
	int n;
	int numa=0;
	int numb=0;
	int ans=0;
	n=str.size();
	for (int i=0; i<n; i++){
		numa++;
		if(str.at(i)=='A') break;
	}
	reverse(str.begin(), str.end());
	for (int i=0; i<n; i++){
		numb++;
		if(str.at(i)=='Z') break;
	}
	ans = n-numa-numb+2;
	cout << ans << endl;
}


Measured memory_bytes: 3680
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
#define ull_cin(X) scanf("%llu", &X)
#define lf_cin(X) scanf("%lf", &X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)

#define  ll_cout(X) printf("%lld\n",X)
#define  ull_cout(X) printf("%llu\n",X)



typedef long long  ll;
typedef unsigned long long  ull;

#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion

static char a[101], b[101];
int main(void) {
	int rc,la,lb;
	
	scanf("%s",a); la = strlen(a);
	scanf("%s",b); lb = strlen(b);

	if(la<lb) { S_RTN("LESS"); }
	if(la>lb) { S_RTN("GREATER");}

	rc = memcmp(a, b, la);
	if (rc ==0) { S_RTN("EQUAL"); }
    if (rc > 0){ S_RTN("GREATER"); }
    S_RTN("LESS");
}



//#define _N 1000000000

//int main(void)
//{
//
//	int  n,i;
//	ull   tmp=1;
//
//	i_cin(n);
//
//	for (i = 1; i <= n; i++) {
//		if (!(tmp % ((ull)_N + 7)))
//			tmp = 1;
//		tmp *= (ull)i;
//	}
//	tmp %= ((ull)_N + 7);
//		
//	ull_cout(tmp);
//	return 0;
//}



Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n, k; cin >> n >> k;
    vector<double> p(n), s(n);
    rep(i,n) cin >> p[i];
    rep(i,n) {
        s[i] = (1+p[i])/2.0;
    }
    vector<double> sum(n+1);
    sum[0] = 0;
    rep(i,n) {
        sum[i+1] += sum[i]+s[i];
    }
    double ans = 0;
    repf(i,k,n+1) {
        chmax(ans ,sum[i]-sum[i-k]);
    }
    printf("%.10lf\n", ans);
    return 0;
}

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

using namespace std;

#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP(x)	make_pair(x)

#define debug(_x)		cerr << #_x << '=' << _x << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << _x << ' ' << #_y << '=' << _y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << _x << ' '; cerr << endl;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX >> 1;
const int NINF = LONG_LONG_MIN;
const int mmod = 100000000000ll;

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	int a[n];
	for (int& x: a) cin >> x;
	
	map<int, int> m;
	
	bool ok = true;
	for (int i = 0; i < n; i++) {
		if  (m[a[i]] == 0) {
			m[a[i]]++;
		} else {
			ok = false;
		}
	}
	
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined 


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

int n, m;
map<string, bool> u;
string s;
bool flag;

int main()
{
  cin >> n;
  while(n--){
    cin >> s;
    u[s] = true;
  }

  cin >> m;
  while(m--){
    cin >> s;
    if(u[s]){
      cout << (flag ? "Closed" : "Opened") << " by " << s << endl;
      flag = !flag;
    }
    else{
      cout << "Unknown " << s << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// 出力は.xで！！！！

int main(){
  int n,k; cin >> n >> k;
  ll ans=0;
  vector<ll> sums(n+2);
  sums[0]=sums[1]=0;
  rep(i,n){
    sums[i+2]=sums[i+1]+i+1;
    sums[i+2]%=MOD;
  }
  for(int i=n+1; i>=k; i--){
    ans+=sums[n+1]-sums[n+1-i]-sums[i]+1;
    while(ans<0) ans+=MOD;
    ans%=MOD;
  }
  cout << ans << endl;
return 0;
}

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


int main() {
	int N;
	cin >> N;
	int A = N / 1000;

	if (N % 1000 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << (A + 1) * 1000 - N << endl;
	}
	}

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

int main(){
    ll n, t;
    cin >> n >> t;
    ll ans=0;
    ll pre=0;
    ll push=0;
    cin >> pre;
    for(int i=0; i<n-1; i++){
        pre = push;
        cin >> push;
        if(push-pre < t) ans += push-pre;
        else ans += t;
    }
    ans += t; //最後の一回
    cout << ans << endl;
}

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

int main() {
    int N;
    long long x;
    cin >> N >> x;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    long long res = 0;
    for (int i = 0; i < N; ++i) {
        if (a[i] > x) {
            res += a[i] - x;
            a[i] = x;
        }
    }
    for (int i = 0; i+1 < N; ++i) {
        if (a[i] + a[i+1] > x) {
            res += a[i] + a[i+1] - x;
            a[i+1] = x - a[i];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  int n = in();
  vi b(n - 1);
  cin >> b;
  ll ans = b[0] + b[n - 2];
  rep(i, n - 2) ans += b[(b[i] < b[i + 1]) ? i : (i + 1)];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const double PI = 3.14159265358979323846;
int main() {
	
	double a, b, x;
	cin >> a >> b >> x;
	
	double ans;
	if(x / a > a * b / 2) ans = 360 / (2 * PI) * atan(2 / (a * a * a) * (a * a * b - x));
	else ans = 360 / (2 * PI) * atan(a * b * b / (2 * x));
	printf("%.10f\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//size_t f = string::npos
//make pair, tuple

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std ;
#define ld long double
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define inp(a) for(auto& i : a) cin >> i;
#define out(a) for(auto i : a){cout << i << ' ';}cout << endl;
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define LOCAL
const int N = 2e5+7 ;
const int INF = 1e9 ;
const long long MOD = INF + 7 ;
string s ;
#define int long long

int32_t main(){_
	int n,m ;
	cin >> n >> m ;
	vi a(n) , b(m) ;
	inp(a) ;
	inp(b) ;
	vector<vector<int>> dp(n+1, vector<int>(m+1,0)) ;
	for(int i = 0 ; i <= n ; i++){
		dp[i][0] = 1 ;
		}
	for(int i = 0 ; i <= m ; i++){
		dp[0][i] = 1 ;
		}
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= m ; j++){
			dp[i][j] = dp[i-1][j] + dp[i][j-1] ;
			if(a[i-1] != b[j-1])
					dp[i][j] -= dp[i-1][j-1] ;
			dp[i][j] = (dp[i][j] + 10 * MOD) % MOD;
		}
	}
	cout << dp[n][m] << endl ;
}



Measured memory_bytes: 31616
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};

struct edge {
    int t;
    int c;
    edge(int a, int b) {
        t = a;
        c = b;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, u, k, v, c;
    cin >> n;
    vector<edge> E[n];
    rep(i, n) {
        cin >> u >> k;
        rep(j, k) {
            cin >> v >> c;
            edge tmp(v, c);
            E[u].push_back(tmp);
        }
    }

    priority_queue<pair<int, int>, vector<pair<int, int>>,
                   greater<pair<int, int>>>
        Q; // cost,V

    int d[n];
    fill(d, d + n, INFINT);
    Q.push(make_pair(0, 0));

    int fix = 0;
    while(fix < n && !Q.empty()) {
        pair<int, int> v = Q.top();
        Q.pop();
        if(d[v.second] != INFINT) continue;
        d[v.second] = v.first;
        fix++;
        for(auto e : E[v.second]) {
            if(d[e.t] == INFINT) {
                Q.push(make_pair(v.first + e.c, e.t));
            }
        }
    }

    rep(i, n) cout << i << " " << d[i] << "\n";
}



Measured memory_bytes: 9520
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i;
    cin>>n;
    vector<long long int> h(n),mi(n);
    for(i=0;i<n;i++)
    cin>>h[i];
    mi[n-1]=0;
    mi[n-2]=abs(h[n-1]-h[n-2]);
    for(i=n-3;i>=0;i--)
    {
        mi[i]=min(mi[i+1]+abs(h[i+1]-h[i]),mi[i+2]+abs(h[i+2]-h[i]));
    }
    cout<<mi[0];
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int calc(string num){
    int res=atoi(num.c_str());
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    int N;
    cin>>s;
    N=s.size();
    
    int mn=INF;
    for(int i=0;i+3<=N;i++){
        int x=calc(s.substr(i,3));
        if(abs(753-x)<mn) mn=abs(753-x);
    }
    cout1(mn)
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N=0;
  long int a=2;
  long int b=1;
  long int c=0;
  cin >> N;
  if(N==1){
    cout << 1 << endl;
  }
  else{
    for(int i=0;i<N-1;i++){
      c = b + a;
      a = b;
      b = c;
    }
    cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 256