akhauriyash/Code-Regression huggingface dataset:
n,c = map(int,input().split())
X = []
V = []
for i in range(n):
  x,v = map(int,input().split())
  X.append(x)
  V.append(v)
right = []
right2 = []
left = []
count = 0
left2 = []
for i in range(n):
  if i == 0:
    count += (V[i] - X[i])
    right.append(count)
    right2.append(count)
  else:
    count += (V[i] - (X[i] - X[i - 1]))
    right.append(count)
    right2.append(max(right2[-1],count))

count = 0
for i in range(n):
  if i == 0:
    count += (V[(i + 1) * (-1)] - (c - X[(i + 1) * (-1)]))
    left.append(count)
    left2.append(count)
  else:
    count += (V[(i + 1) * (-1)] - ((X[i * (-1)] - X[((i + 1) * (-1))])))
    left.append(count)
    left2.append(max(left2[-1],count))
ans = max(0,max(right),max(left))
for i in range(n - 1):
  ans = max(ans, right[i] - X[i] + left2[n-i-2])
for i in range(n - 1):
  ans = max(ans, left[i] - (c - X[(i + 1) * (-1)]) + right2[n-i-2])
print(ans)

Measured memory_bytes: 22028
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());
        int[] li = new int[N];
        for(int i =0; i < N;i++){
            li[i] = K-Q;
        }
        for(int j =0; j < Q;j++){
            int correct = Integer.parseInt(sc.next())-1;
            li[correct]++;
        }
        for(int i =0 ; i < N ;i++){
            if(li[i] <= 0){
                System.out.println("No");
            }else{
                System.out.println("Yes");
            }
        }
    }
}

Measured memory_bytes: 52372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll inf = 1e18;
ll mod = 1e9+7;

int a[200010];

int main(){
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int x;
        cin >> x;
        a[x]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4348
#include <bits/stdc++.h>
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)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,k,a[110],dp[110][110000];
signed main(){
  cin>>n>>k;rep(i,n)cin>>a[i];
  rep(i,n)dp[i][0] = 1;
  repd(i,1,k+1)dp[0][i] = (i <= a[0] ? i+1 : a[0]+1);
  repd(i,1,n){
    repd(j,1,k+1){
      dp[i][j] = ((dp[i][j-1] + dp[i-1][j])%MOD + MOD - (j-a[i]-1 >= 0 ? dp[i-1][j-a[i]-1] : 0))%MOD;
    }
  }
  cout << (dp[n-1][k] + MOD - dp[n-1][k-1])%MOD << endl;
}


Measured memory_bytes: 86144
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn readu32(&mut self) -> u32 {
        self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0, |acc, x| acc*10 + (x as u8 - b'0') as u32)
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn insertion_sort(a: &mut Vec<u32>, g: usize) -> usize {
    let mut cnt = 0;
    let n = a.len();
    for i in g..n {
        let v = a[i];
        let mut j = i;
        while j >= g && a[j-g] > v {
            a[j] = a[j-g];
            cnt += 1;
            j -= g;
        }
        a[j] = v;
    }
    cnt
}

fn shell_sort(a: &mut Vec<u32>, g: &[usize]) -> usize {
    let mut cnt = 0;
    for &i in g.iter() {
        cnt += insertion_sort(a, i);
    }
    cnt
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n = sc.read();
    let mut a: Vec<_> = (0..n).map(|_| sc.readu32()).collect();

    let g = {
        let mut g = vec![];
        let mut x = 1 as usize;
        while x <= n {
            g.push(x);
            x = x*3 + 1;
        }
        g.reverse();
        g
    };
    let cnt = shell_sort(&mut a, &g[..]);
    println!("{}", g.len());
    println!("{}", g.iter().join(" "));
    println!("{}", cnt);
    println!("{}", a.iter().join("\n"));
}



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

using namespace std;

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int count = 0;
	for (int i = 0;i <= a;i++) {
		for (int j = 0;j <= b;j++) {
			for (int k = 0;k <= c;k++) {
				int sum = 500 * i + 100 * j + 50 * k;
				if (sum==x) {
					count++;
					break;
				}
				else if (sum > x) {
					break;
				}
			}
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int s[505][3];
int f[505][505];
int n;
int main()
{
    cin>>n;
    for (int i=1; i<=n-1; ++i)
        cin>>s[i][0]>>s[i][1]>>s[i][2];

    for (int i=1; i<=n-1; ++i)
        f[i][i+1]=s[i][0]+s[i][1];

    for (int i=1; i<=n-1; ++i)
        for (int j=i+2; j<=n; ++j)
        {
            if (f[i][j-1]<=s[j-1][1])
                f[i][j]=s[j-1][0]+s[j-1][1];
            else
            {
                f[i][j]=f[i][j-1]-1;
                f[i][j]/=s[j-1][2];
                f[i][j]++;
                f[i][j]*=s[j-1][2];
                f[i][j]+=s[j-1][0];
            }
        }

    for (int i=1; i<=n; ++i)
        cout<<f[i][n]<<endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {
    
    int a,b,c;
    cin>>a>>b>>c;

    if(a==b&&b==c)  cout<<"No"<<endl;
    else if(a!=b&&b!=c&&a!=c)   cout<<"No"<<endl;
    else    cout<<"Yes"<<endl;

 
 return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 150007;
const int MOD = 1000000007;

void solve() {
    int x;
    cin >> x;
    if (x >= 30) {cout << "Yes";}
    else {cout << "No";}
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("rental.in", "r", stdin); freopen("rental.out", "w", stdout);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}


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

// 月:01 ~ 12
// 年:00 ~ 99

int main(void){
    char str[4];
    cin >> str;
    int upper = (str[0]-'0') * 10 + (str[1]-'0');
    int lower = (str[2]-'0') * 10 + (str[3]-'0');
    // cout << upper << ' ' << lower;

    int mmyy = 0, yymm = 0;
    if(0 < upper && upper < 13) mmyy = 1;
    if(0 < lower && lower < 13) yymm = 1;
    if(mmyy & yymm) cout << "AMBIGUOUS";
    else if(mmyy) cout << "MMYY";
    else if(yymm) cout << "YYMM";
    else cout << "NA";
    return 0;
}

Measured memory_bytes: 256
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int n,p[200010],invp[200010];

int main(){
    I(n);
    REP(i,n){
        I(p[i]);
        invp[p[i]-1] = i;
    }
    int ret = 0;
    int tmp = 1;
    REP(i,n-1){
        if (invp[i] < invp[i+1]){
            tmp++;
        } else {
            ret = max(ret,tmp);
            tmp = 1;
        }
    }
    cout << n-max(ret,tmp) << endl;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;

    unordered_map<char, vec> mp;
    rep (i, s.size())
        mp[s[i]].pb(i);

    int total = 0, ind = -1;
    rep (i, t.size()) {
        char c = t[i];
        if (mp[c].size() == 0) {
            print(-1);
            return 0;
        }
        while (true) {
            auto loc = upper_bound(all(mp[c]), ind);
            if (loc == mp[c].end()) {
                ind = -1;
                total += s.size();
            } else {
                ind = *loc;
                break;
            }
        }
    }
    total += ind + 1;
    print(total);

    return 0;
}


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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string a, b, c;
	string *turn;
	char card;
	
	cin >> a; cin >> b; cin >> c;
	
	turn = &a;

	while (true) {
	    card = (*turn)[0];
	    
	    turn->erase(turn->begin());
	    
	    if (card == 'a') {
	        turn = &a;
	        
	        if (a.size() == 0) {
	            cout << "A" << endl;
	            break;
	        }
	    } else if (card == 'b') {
	        turn = &b;
	        
	        if (b.size() == 0) {
	            cout << "B" << endl;
	            break;
	        }
	    } else if (card == 'c') {
	        turn = &c;
	        
	        if (c.size() == 0) {
	            cout << "C" << endl;
	            break;
	        }
	    }
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
using lli = long long int;

void swap(int *x, int *y) {
    int tmp = *x;
    *x = *y;
    *y = tmp;
}

lli median(lli x, lli y, lli z) {
    if (x < y) {
        if (y < z) { return y; }
        else if (z < x) { return x; }
        else { return z; }
    } else {
        if (z < y) { return y; }
        else if (x < z) { return x; }
        else { return z; }
    }
}

void quicksort(lli *a, lli left, lli right) {
    if (left < right) {
        lli i = left;
        lli j = right;
        lli pivot = median(a[i], a[i + (j - i) / 2], a[j]);

        while (1) {
            while (a[i] < pivot) { i++; }
            while (pivot < a[j]) { j--; }
            if (i >= j) { break; }
            swap(a[i], a[j]);
            i++;
            j--;
        }
        quicksort(a, left, i - 1);
        quicksort(a, j + 1, right);
    }

}

int main() {

    lli n;
    cin >> n;

    lli a[n];
    for(auto i = 0; i < n; i++){
        cin >> a[i];
    }

    quicksort(a, 0, n - 1);

    lli tmp_left = a[0], tmp_right = a[n - 1];

    lli ans = n;

    lli i = 0, j = n - 1;

    bool is_left = false;
    while (1) {
        if (i >= j) { break; }
        i++;
        if(a[i] == tmp_left){
            is_left = true;
        } else {
            tmp_left = a[i];
        }

        while (is_left) {
            j--;
            if (a[j] == tmp_right) {
                ans -= 2;
                is_left = false;
            } else {
                tmp_right = a[j];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef pair<double, ll> pdl;

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready, resolve
    int N;
    cin >> N;
    vector<double> vList;
    vList.resize(N);
    for (int i=0; i<N; i++) cin >> vList.at(i);
    sort(vList.begin(), vList.end());
    double lastGuzai = vList[0];
    for (int i=1; i<N; i++) {
        lastGuzai = (lastGuzai + vList[i]) /2;
    }

    cout << lastGuzai << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      string s,s1;
      cin>>s>>s1;
      ll ans=s.length();
      for(int i=0;i<s.length()-s1.length()+1;i++){
        ll tans=0;
        for(int j=i;j<i+s1.length();j++){
          if(s[j]!=s1[j-i]) tans++;
        }
        ans=min(ans,tans);
      }
      cout<<ans;
}

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

int main(){
  long long x,y;
  long long c = 0;
  long long s = 0;
  cin >> x >> y;
  for(long long i=0; i<x; ++i){
    int tmp;
    cin >> tmp;
    c += tmp;
  }

  for(long long i=0; i<y; ++i){
    int tmp;
    cin >> tmp;
    s += tmp;
  }
  cout << c*s << endl;
}



Measured memory_bytes: 3100
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7 ;
const ll N = 1e5 + 10 ;

int main(){
    fastio
int d;
cin>>d;
if(d==22)
cout<<"Christmas Eve Eve Eve"<<endl;
 else if(d==23)
cout<<"Christmas Eve Eve"<<endl;
 else if(d==24)
cout<<"Christmas Eve"<<endl;
 else if(d==25)
cout<<"Christmas"<<endl;

    return 0 ;
}

Measured memory_bytes: 256
N, H = map(int, input().split())
A, B = zip(*[tuple(map(int, input().split())) for _ in range(N)])
a = max(A)
B = sorted((b for b in B if b > a), reverse=True)
for i, b in enumerate(B, 1):
    H -= b
    if H <= 0:
        ans = i
        break
else:
    ans = len(B) + (H + a - 1) // a
print(ans)

Measured memory_bytes: 24380
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    
    rep(i, N){
        ll inp; cin >> inp;
        if(inp % 2 == 0){
            if((inp % 3) == 0 or (inp % 5) == 0){
                continue;
            }else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll MOD=1e9+7;
#define endl '\n'
#define F first
#define S second
#define pb push_back
const double PI = 3.141592653589793238460;
  void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
    #endif
}
ll dp[100005];ll a[100005];
ll frog(int i,int n)
{
  if(i==n)
    return 0;
  if(dp[i]!=-1)
    return dp[i];
  ll cost=abs(a[i]-a[i+1])+frog(i+1,n);
  if(i+2<=n)
    cost=min(cost,abs(a[i]-a[i+2])+frog(i+2,n));
  return dp[i]=cost;



}
 

int  main()
{
  c_p_c();
 ll n;cin>>n;
 memset(dp,-1,sizeof(dp));

 for(int i=1;i<=n;i++)cin>>a[i];

  cout<<frog(1,n);

 

  return 0;

}

Measured memory_bytes: 11364
n = int(input())
s = [int(input()) for i in range(n)]
s.sort()
s = list(filter(lambda x: x % 10 != 0,s)) + list(filter(lambda x: x % 10 == 0,s))
ans = sum(s)
i = 0
while ans % 10 == 0 and n > i:
    ans -= s[i]
    i += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll n , k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n){
        cin >> a.at(i);
        a.at(i)--;
    }

    vector<ll> visited(n,-1);
    ll now = 0;
    ll cnt = 0;
    visited.at(0) = cnt;

    ll loopbegin,loopend;

    while(true){
        now = a.at(now);
        cnt++;
        if(visited.at(now)==-1){
            visited.at(now) = cnt;
        }else{
            loopbegin = visited.at(now);
            loopend = cnt;
            break;
        }
    }

    //prvec(visited);

    ll loopcycle = loopend - loopbegin;

    if(k<loopend){
        rep(i,n){
            if(visited.at(i)==k){
                cout << i + 1 << endl;
                return 0;
            }
        }
    }else{
        ll x = (k-loopbegin)%loopcycle;
        x = x + loopbegin;
        rep(i,n){
            if(visited.at(i)==x){
                cout << i + 1 << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 6428
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <bitset>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

using bit = std::bitset<50>;

int main()
{
    using namespace std;

    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c && c == a)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
from sys import stdin
from itertools import repeat
def main():
    L, n = map(int, stdin.readline().split())
    a = map(int, stdin.read().split(), repeat(10, n))
    sr = [0] * (n + 1)
    sl = [0] * (n + 1)
    for i in xrange(n):
        sl[i+1] = sl[i] + a[i]
    for i in xrange(n - 1, 0, -1):
        sr[i-1] = sr[i] + L - a[i]
    ans = 0
    for i in xrange(n):
        l = i
        r = n - 1 - i
        if l < r:
            r = l + 1
        else:
            l = r
        t = (sr[i] - sr[i+r] + sl[i] - sl[i-l]) * 2 + a[i]
        if ans < t:
            ans = t
    for i in xrange(n - 1, -1, -1):
        l = i
        r = n - 1 - i
        if l > r:
            l = r + 1
        else:
            r = l
        t = (sr[i] - sr[i+r] + sl[i] - sl[i-l]) * 2 + L - a[i]
        if ans < t:
            ans = t
    print ans
main()


Measured memory_bytes: 22088
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long a, b, c;
  Solver() {
    S002 reader;
    reader >= a >= b >= c;
  }
  void solve() {
    puts(b - a == c - b ? "YES" : "NO");
  }
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
//#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, P> PP;
typedef pair<P,int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

//// UnionFind
struct UnionFind{
	vector<int> v;
	UnionFind(int n) : v(n, -1) {}

	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
		return true;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int n;
vector<PP> edge;
vector<P> point;
int dd[]={-1,0,1,0,-1};

int idlast;
map<P,int> mp;
int id(P p){
	if(mp.count(p))return mp[p];
	mp[p]=idlast++;
	return mp[p];
}

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		UnionFind uf(4*n+100);
		idlast=0;
		edge.clear(); point.clear(); mp.clear();
		rep(i,n){
			ll a,b; char c;
			cin>>a>>b>>c;
			if(c=='x'){
				edge.pb(PP(P(a,b),P(a+1,b)));
				uf.unite(id(P(a,b))+2*n,id(P(a+1,b)));
				uf.unite(id(P(a,b)),id(P(a+1,b))+2*n);
				point.pb(P(a,b)); point.pb(P(a+1,b));
			}else{
				edge.pb(PP(P(a,b),P(a,b+1)));
				uf.unite(id(P(a,b))+2*n,id(P(a,b+1)));
				uf.unite(id(P(a,b)),id(P(a,b+1))+2*n);
				point.pb(P(a,b)); point.pb(P(a,b+1));
			}
		}
		rep(i,point.size()){
			P p=point[i];
			rep(j,4){
				ll nx=p.fi+dd[j], ny=p.se+dd[j+1];
				if(!mp.count(P(nx,ny))||P(nx,ny)==point[i+(i%2?-1:1)])continue;
				uf.unite(id(p),id(P(nx,ny)));
				uf.unite(id(p)+2*n,id(P(nx,ny))+2*n);
			}
		}
		bool ok=true;
		rep(i,edge.size()){
			if(uf.same(id(edge[i].fi),id(edge[i].se))||
				uf.same(id(edge[i].fi)+2*n,id(edge[i].se)+2*n))ok=false;
		}
		if(ok)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 7096
#include <bits/stdc++.h>
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)}; 


////////////////////////////////////////////////////////////////////
template<typename T>
struct edge {
  int to, from;T cost;
  edge(int to) : from(-1), to(to), cost(-1) {}
  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template<typename T>
using edges = vector<edge<T>>;
template<typename T>
using graph = vector<edges<T>>;
template<typename T>
using matrix = vector<vector<T>>;

template<typename T>
bool compByCost(const edge<T>& left, const edge<T>& right){
  return left.cost < right.cost; 
}

template<typename T>
vector<vector<T>> warshall(matrix<T> &g){
  vector<vector<T>> dist(g.size());
  rep(i,g.size()){
    dist[i].resize(g.size());
    rep(j,g.size())dist[i][j] = (i == j ? 0 : g[i][j]);
  }
  rep(k,g.size()){
    rep(i,g.size()){
      rep(j,g.size()){
        if(dist[i][k] == INF || dist[k][j] == INF)continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return dist;
}

#define warshall warshall<int>// matの初期化でINFを詰めておく



////////////////////////////////////////////////////////////////////

signed main(){
  string s,t;cin>>s;
  rep(i,s.length()-8)t += s[i];
  cout << t << endl;
}


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


int main() {

	
	 ll aa, bb, cc, kk;
     cin >> aa >> bb >> cc >> kk;
     ll ans = 0;
     ans += min(aa, kk);
     kk -= min(aa, kk);
     kk = max(0ll, kk);
     //ans += min(bb, kk);
     kk -= min(bb, kk);
     kk = max(0ll, kk);
     ans -= min(cc, kk);
     cout << ans;

}


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

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

  int H,W,D;
  cin >> H >> W >> D;

  vector<pair<int,int>> Cood(H * W + 1);
  rep(h, H) {
    rep(w, W) {
      int A; cin >> A;
      Cood[A] = make_pair(h, w);
    }
  }

  vector<int> Cost(H * W + 1);

  // D = 2
  // d = 1
  rep1(d, D) {
    Cost[d] = 0; // Cost[1] = 1にいくまでのコスト
    for(int i = d + D; i <= (H * W); i += D) {
      pair<int,int> pre = Cood[i - D]; // 1の座標
      pair<int,int> nex = Cood[i]; // 3の座標
      Cost[i] = Cost[i - D] + abs(nex.first - pre.first) + abs(nex.second - pre.second);
    }
  }

  int Q; cin >> Q;
  rep(q, Q) {
    int l,r; cin >> l >> r;
    cout << Cost[r] - Cost[l] << endl;
  }
}


Measured memory_bytes: 2176
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class CUnification {
public:
    void solve(std::istream &in, std::ostream &out) {
        string str;
        in >> str;
        stack<char> S;
        trav(c, str) {
            if (not S.empty() and S.top() != c) {
                S.pop();
            } else {
                S.push(c);
            }
        }
        int res = sz(str) - sz(S);
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    CUnification solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 512
#editorial参照
#そもそもの漸化式
#2次元累積和
#dp累積和のdpを含む漸化式 & dp消せる
n,m = map(int, input().split( ))

s = list(map(int, input().split( )))
t = list(map(int, input().split( )))

mod = 10**9 + 7

dp_sum = [[0]*(m+1) for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] + 1
            dp_sum[i][j] %= mod
        else:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] - dp_sum[i-1][j-1]
            dp_sum[i][j] %= mod
#print(dp_sum)
print(dp_sum[n-1][m-1]+1)#空集合で+1



Measured memory_bytes: 72924
#include <stdio.h>
int nums1[105][105];
int nums2[105][105];
long long nums3[105][105];

int main() {
#ifdef TEST
    freopen("input", "r", stdin);
#endif

    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    for (int i = 0; i < a; ++i) {
        for (int j = 0; j < b; ++j) {
            scanf("%d", &nums1[i][j]);
        }
    }

    for (int i = 0; i < b; ++i) {
        for (int j = 0; j < c; ++j) {
            scanf("%d", &nums2[i][j]);
        }
    }

    for (int i = 0; i < a; ++i) {
        for (int j = 0; j < c; ++j) {
            for (int k = 0; k < b; ++k) {
                nums3[i][j] += nums1[i][k] * nums2[k][j];
            }
        }
    }

    for (int l = 0; l < a; ++l) {
        for (int i = 0; i < c - 1; ++i) {
            printf("%lld ", nums3[l][i]);
        }
        printf("%lld\n", nums3[l][c - 1]);
    }
    return 0;
}



Measured memory_bytes: 2132
#include<stdio.h>
#include<string.h>
char str1[100],str2[100],temp[100];
int main()
{
    int i,j=0,t;
    scanf("%s[^\n]",str1);
    scanf("%s[^\n]",str2);
    i=strlen(str1);
    t=i-1;
    if(strlen(str1)!=strlen(str2))
    {
        printf("NO\n");
    }
    else
    {
        while(str1[j]!='\0')
        {
            temp[j]=str1[t];
            j++;
            t--;
        }
        t=0;
        i=0;
        while(temp[i]!='\0')
        {
            if(temp[i]==str2[i])
            {
                t++;
            }
            i++;
        }
        if(strlen(str2)==t)
        {
            printf("YES\n");
        }
        else if(strlen(str2)!=t)
        {
            printf("NO\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define LOG 19
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 500005

char s[maxn] ;
int a[maxn] ;

int main()
{
    int n ;

    scanf("%s",s) ;

    n = strlen(s) + 1 ;

    for(int i=n-1 ; i>0 ; i--) s[i] = s[i-1] ;

    for(int i= 1 ; i<= n-1 ; i++)
    {
        int l = i , r= i ;
        while( r+1 <= n-1 && s[r]==s[r+1] ) r++ ;

        if( s[r]=='<' ) for(int j=l-1 , k=0 ; j<=r ; j++,k++) a[j] = max( a[j],k ) ;
        else    for(int j=r , k=0 ; j>=(l-1) ; j--,k++) a[j] = max( a[j] , k  ) ;
        i = r ;
    }

//    for(int i=0 ; i<n ; i++) printf("%d ",a[i]) ;
//    printf("\n") ;

    long long ans = 0 ;

    for(int i=0 ; i<n ; i++) ans += a[i] ;

    cout<<ans<<endl ;


    return 0 ;
}


Measured memory_bytes: 2688
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

####

def solve(N, M, A, graph):
    ans = 0
    for u in xrange(N):
        au = A[u]
        for v in graph[u]:
            if au <= A[v]:
                break
        else:
            ans += 1
    return ans

N,M = rrm()
A = rrm()
graph = [[] for _ in xrange(N)]
for _ in xrange(M):
    u,v = rrm()
    u -=1;v-=1
    graph[u].append(v)
    graph[v].append(u)

print solve(N, M, A, graph)


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

int main () {
	int a, b, c;
	cin >> a >> b >> c;
	for (int i = 1; i <= b; i++) {
		if (a * i % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <complex>
#include <iomanip>
#include <cassert>
 
using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  ll l = 2, r = 2;
  for (int i = n - 1; i >= 0; --i) {
    ll x = r - (r % a[i]);
    if (x < l) {
      cout << "-1\n";
      return 0;
    }
    ll mx = r - (r % a[i]);
    ll mn = l + ((a[i] - (l % a[i])) % a[i]);
    l = mn;
    r = mx + a[i] - 1;
  }
  cout << l << ' ' << r << '\n';
} 


Measured memory_bytes: 1024
def b():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    satisfaction, pre_a = 0, -1
    for i in range(N):
        a = A[i] - 1
        satisfaction += B[a]
        if pre_a != -1 and pre_a + 1 == a:
            satisfaction += C[pre_a]

        pre_a = a

    print(satisfaction)


if __name__ == '__main__':
    b()

Measured memory_bytes: 38256
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
#include <cmath>

int main(int argc, char *argv[])
{
	int n;
	cin>>n;
	set<int> a;

	for (int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		if (a.count(t))
		{
			cout<<"NO"<<endl;
			return 0;
		}
		a.insert(t);
	}
	
	cout<<"YES"<<endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int alice = 0, bob = 0;
    
    sort(a.begin(), a.end(), greater<int>());
    
    rep(i, n) {
        if ((i % 2) == 0) {
            alice += a[i];
        }
        else {
            bob += a[i];
        }
    }
    
    cout << (alice - bob) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
s = [""] * N
t = [0] * N
for i in range(N):
    S,T = map(str,input().split())
    s[i] = S
    t[i] = int(T)
X = input().rstrip("\n")

for i in range(1,N):
    t[i] += t[i-1]

index = s.index(X)

answer = t[-1] - t[index]
print(answer)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[26];
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
            int[] b = new int[26];
            for (int j = 0; j < s[i].length(); j++) {
                char c = s[i].charAt(j);
                if(i == 0) {
                    a[c - 'a']++;
                } else {
                    b[c - 'a']++;
                }
            }
            if(i != 0) {
                for (int j = 0; j < 26; j++) {
                    a[j] = Math.min(a[j], b[j]);
                }
            }
        }
        for (int i = 0; i < 26; i++) {
            int c = a[i];
            if(c != 0) {
                for (int j = 0; j < c; j++) {
                    System.out.print(Character.valueOf((char) ('a' + i)));
                }
            }
        }
    }
}

Measured memory_bytes: 35604
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
count = 0
for i in 0..a do
  x1 = x - (500 * i)
  if x1 < 0
    break
  end

  for j in 0..b do
    x2 = x1 - (100 * j)
    if x2 < 0
      break
    end

    if (x2 / 50) <= c
      count += 1
    end
  end
end

p count


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B,a,b,c,d,e,aa,bb,cc,dd;
  cin >> A >> B;
 
  // ここにプログラムを追記
  int count = 0;
  for(int i=A; i<=B; i++){
    a=i/10000;
    aa = a*10000;
    b=(i-aa)/1000;
    bb=b*1000+aa;
    c=(i-bb)/100;
    cc=c*100+bb;
    d=(i-cc)/10;
    dd=d*10+cc;
    e=(i-dd);
    if(a==e && b==d)
      count++;
  }
  cout << count << endl;
}

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

int main() {
  int A,B,M; cin>>A>>B>>M;
  vector<int> a(A),b(B),x(M),y(M),c(M);
  rep(i, A) cin>>a[i];
  rep(i, B) cin>>b[i];
  rep(i, M) cin>>x[i]>>y[i]>>c[i];

  ll res=0;
  vector<int> ans(M+1);
  rep(i, M) {
    ans[i]=a[x[i]-1]+b[y[i]-1]-c[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ans[M]=a[0]+b[0];
  sort(ans.begin(), ans.end());
  cout<<ans[0]<<endl;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;

//---main---------------------------------------------
int main(){
    //main
    int N;
    cin >> N;

    if(N==0) cout << 1 << endl;
    else cout << 0 << endl; 

    return 0;
}

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

int main() {
  std::string str;
  std::cin >> str;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == ',') {
      str[i] = ' ';
    }
  }
  std::cout << str << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
char c[110],s[110];
int main(){
	n=read();
	scanf("%s%s",c+1,s+1);
	for(register int i=1;i<=n;i++){
		printf("%c%c",c[i],s[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
#define rep(i,s,t) for(ll i=s ; i<t ; i++)
typedef pair<int,int> P;
typedef pair<int,P> pp;
const int INF = 1e5;
string s[20];
int h,w;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const ll mod = 1e9+7;
int func(int sx,int sy){
  int d[h][w];
  rep(i,0,h)rep(j,0,w){
    d[i][j] = INF;
  }
  int ma = 0;
  queue<P> que;
  d[sx][sy] = 0;
  que.push(P(sx,sy));
  while(que.size()){
    P p = que.front();  que.pop();
    int x = p.fi, y = p.se;
    //cout << x << " " << y << endl;
    rep(i,0,4){
      int nx = x+dx[i], ny = y+dy[i];
      if(nx>=0 && ny>=0 && nx<h && ny<w && d[nx][ny]==INF && s[nx][ny]=='.'){
        d[nx][ny] = d[x][y] + 1;
        ma = max(d[nx][ny], ma);
        que.push(P(nx,ny));
      }
    }
  }
  return ma;
}
int main(){
  cin >> h >> w;
  rep(i,0,h){
      cin >> s[i];
  }
  int ans = 0;
  rep(i,0,h)rep(j,0,w){
    if(s[i][j]!='#')
      ans = max(ans, func(i,j));
  }
  cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>

int count[7];
int main(){
	int n;
	while(true){
		std::cin>>n;
		if(!n){
			break;
		}
		for(int i =0; i < 7;i++){
			count[i]=0;
		}
		for(int i=0; i< n ;i++){
			int now;
			std::cin >> now;
			now = now /10;
			if(now > 6) now = 6;
			count[now]++;
		}
		for(int i = 0; i < 7 ;i++){
			std::cout << count[i] << std::endl;
		}
	}
}

Measured memory_bytes: 864