akhauriyash/Code-Regression huggingface dataset:
X = [i for i in range(1, 10)]
prev = X[:]
for i in range(9):
    ne = []
    for x in prev:
        s = x % 10
        ne.append(x * 10 + s)
        if s: ne.append(x * 10 + s - 1)
        if s < 9: ne.append(x * 10 + s + 1)
    X += ne
    prev = ne
X = sorted(X)
print(X[int(input()) - 1])

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

int main(){
    int n,k;
    cin>>n>>k;
    int a=(n-1)*(n-2)/2;
    if(k>a) cout<<-1<<endl;
    else{
        int lim=a-k;
        cout<<lim+n-1<<endl;
        for(int i=2;i<=n;i++) cout<<1<<" "<<i<<endl;
        for(int i=2;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(lim>0){
                    cout<<i<<" "<<j<<endl;
                    lim--;
                }
                else{
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define mod 1000000007
#define pb push_back  
#define endl "\n"
#define fi first
#define se second 
#define ll long long
#define inf 9000000000000000000
#define PI 3.14159265359

int power(int a,int b,int m=mod)
{
     if(b==0)	return 1;
     if(b==1)	return a;
	 int res=power(a,b/2,m);
	 res=(res*res)%m;
     if(b&1)	res=(res*a)%m;
     return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}


int32_t main()
{
   IOS
    
   int n,i;
   cin>>n;
   vector<int>v1,v2;
   for(i=0;i<n;i++)
   {
   	int x,y;
   	cin>>x>>y;
   	
   	v1.push_back(x-y);
   	v2.push_back(x+y);
   }
  
   sort(v1.begin(),v1.end());
   sort(v2.begin(),v2.end());
   
   cout<<max(abs(v1[v1.size()-1] - v1[0]),abs(v2[v2.size()-1] - v2[0]))<<endl;
}

Measured memory_bytes: 6692
N = int(input())
D = list(map(int, input().split()))
D.sort()

def minGap(hour):
    ret = float('inf')
    for i in range(len(hour)):
        for j in range(len(hour)):
            if i == j:
                continue
            h1 = hour[i]
            h2 = hour[j]
            gap = max(h1, h2) - min(h1, h2)
            ret = min(ret, gap, 24 - gap)
    return ret

hour = [0]
for d in D:
    back = minGap(hour + [d])
    front = minGap(hour + [24 - d])
    if back > front:
        hour += [d]
    else:
        hour += [24 - d]
ans = minGap(hour)

print(ans)



Measured memory_bytes: 3064
#!ruby -nl
s = $_.dup
gsub ?x,''
if $_ != $_.reverse
  p -1
  exit
end

l = 0
r = s.size-1
count = 0
while l < r
  if s[l] != s[r]
    if s[l] == ?x
      l += 1
    else
      r -= 1
    end
    count += 1
  else
    l += 1
    r -= 1
  end
end
p count


Measured memory_bytes: 2044
use std::cmp::{max, min};

const BASE: i32 = 30000;

fn find_set(a: &Vec<char>, b: &Vec<char>) -> Vec<bool> {
    let mut vv = Vec::new();
    vv.resize((BASE*2) as usize, true);
    let a_len = a.len() as i32;
    let b_len = b.len() as i32;
    for i in (-b_len+1)..a_len {
        let mut ok = true;
        for j in max(0, i)..min(a_len, i + b_len) {
            if a[j as usize] != '?' && b[(j - i) as usize] != '?' && a[j as usize] != b[(j - i) as usize] {
                ok = false;
                break;
            }
        }
        if !ok {
            vv[(BASE + i) as usize] = false;
        } else {
            //println!("{}", i);
        }
    }
    vv
}

fn solve(a: String, b: String, c: String) -> i32 {
    let a = a.chars().collect::<Vec<_>>();
    let b = b.chars().collect::<Vec<_>>();
    let c = c.chars().collect::<Vec<_>>();
    let a_len = a.len() as i32;
    let b_len = b.len() as i32;
    let c_len = c.len() as i32;
    let set_ab = find_set(&a, &b);
    let set_bc = find_set(&b, &c);
    let set_ac = find_set(&a, &c);
    let mut ans = 1<<29;
    for i in (-b_len-c_len)..(a_len+c_len+1) {
        // i: a to b position
        if !set_ab[(BASE + i) as usize] {
            continue;
        }
        for j in (min(0, i)-c_len)..(max(a_len, i+b_len)+1) {
            // j: a to c position
            if set_ac[(BASE + j) as usize] && set_bc[(BASE + j - i) as usize] {
                ans = min(ans, max(max(a_len, i+b_len), j+c_len) - min(min(0, i), j));
            }
        }
    }
    ans
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let a = line.trim().to_string();
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let b = line.trim().to_string();
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let c = line.trim().to_string();
    let r = solve(a, b, c);
    println!("{}", r);
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"
vector<int> g[100005],a;

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	return (a+b)%m;}
int sub(int a,int b,int m=mod){	return (a-b+m)%m;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}

void solve()
{
	int n,m;
	cin>>n>>m;
	int a[n+1],i,ans=0;
	memset(a,0,sizeof(a));
	for(i=0;i<m;i++)
	{
		int x;
		cin>>x;
		for(int j=0;j<x;j++)
		{
			int y;
			cin>>y;
			a[y]++;
		}
	}
	for(i=1;i<=n;i++)
		if(a[i]==0)
			ans++;
	cout<<ans<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	while(t--)	solve();
	return 0;
}

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

using namespace std;

bool prime(int x)
{
	if(x==2) return true;
	if(x<2 || x%2==0)
	return false;
	int root=sqrt(x);
	for(int i=3;i<=root;i+=2)
	{
		if(x%i==0)
		return false;
	}
	return true;
}
int main()
{
     int x;
     cin>>x;
     while(1)
     {
        bool res = prime(x);
     	if(res)
     	{
     		cout<<x;
     		return 0;
		}
		x++;
	 }   
}

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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define pf push_front
#define pii pair <int ,int>
#define all(s) s.begin (), s.end ()
#define int long long

using namespace std;

const int N = 1e5 + 5, mod = 1e9 + 7;

int n, a, b, dp[2][N], l = 1, ar[N], L[N];

main()
{
    cin >> n >> a >> b;

    if (a > b) swap(a, b);

    dp[0][1] = dp[1][1] = 1;

    for (int i = 1; i <= n; i++)
        scanf("%lld", &ar[i]);

    L[1] = 1;

    for (int i = 2; i <= n; i++)
    {
        if ( ar[i] - ar[i - 1] >= a )
            L[i] = L[i - 1];
        else
            L[i] = i;
    }
    ar[0] = -1e18;

    for (int i = 2; i <= n; i++)
    {
        if (ar[i] - ar[i - 1] >= a)
            dp[0][i] = (dp[0][i - 1] + dp[1][i - 1]) % mod;

        else if (ar[i] - ar[i - 2] >= a)
            dp[0][i] = dp[1][i - 1];

        else if (i > 2)
        {
            puts("0");
            return 0;
        }

        while (ar[i] - ar[l] >= b) l++;

        if (l == i)
            dp[1][i] = (dp[0][i - 1] + dp[1][i - 1]) % mod;

        else if ( L[i - 1] <= l)
            dp[1][i] = dp[0][l];
    }
    cout << ( dp[1][n] + dp[0][n] ) % mod;
}


Measured memory_bytes: 3456
import sys
import collections
import copy


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    c = collections.Counter(list(s))
    left = collections.defaultdict(int)
    cnt = 0
    for i in range(n - 2):
        left[s[i]] += 1
        mid = copy.deepcopy(left)
        for j in range(i + 1, n - 1):
            mid[s[j]] += 1
            if s[i] != s[j]:
                if [s[i], s[j]].count("R") == 0:
                    cnt += c["R"] - mid["R"]
                    if j + j - i < n:
                        if s[j+j-i] == "R":
                            cnt -= 1
                elif [s[i], s[j]].count("G") == 0:
                    cnt += c["G"] - mid["G"]
                    if j + j - i < n:
                        if s[j+j-i] == "G":
                            cnt -= 1
                elif [s[i], s[j]].count("B") == 0:
                    cnt += c["B"] - mid["B"]
                    if j + j - i < n:
                        if s[j+j-i] == "B":
                            cnt -= 1
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 71564
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<ll> v(n);
    for(auto& i : v) cin >> i;

    vector<ll> gl(n), gr(n);
    REP(i, n){
        if(i == 0) gl[i] = v[i];
        else gl[i] = __gcd(gl[i-1], v[i]);
    }
    RREP(i, n){
        if(i == n-1) gr[i] = v[i];
        else gr[i] = __gcd(gr[i+1], v[i]);
    }

    ll ans = max(gl[n-2], gr[1]);
    FOR(i, 1, n-1){
        chmax(ans, __gcd(gl[i-1], gr[i+1]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-

def main():
    
    A, B = map(int, input().split())

    if A == 1 and B != 1:
        ans = 'Alice'
    
    elif A != 1 and B == 1:
        ans = 'Bob'
    
    elif A == 1 and B == 1:
        ans = 'Draw'

    elif A > B:
        ans = 'Alice'

    elif A < B:
        ans = 'Bob'
    
    elif A == B:
        ans = 'Draw'

    print(ans)


if __name__ == "__main__":
    main()

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

int main() { 
  string s;
  cin>>s;
  int n;
  cin>>n;
  ////
  int iti=0;
 
  rep(i,s.size()){
    if(s[i]=='1'){
     iti++; 
    }
    else{
     break;
    }
  }
  /////////
  if(n<=iti){
    cout<<1<<endl;
  }
  else cout<<s[iti]<<endl;
  
  
  
  
    
  
}

Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_3_C
# 本の説明を図に書き出してみるとよく理解できる。
from math import sqrt


class Vector:
    def __init__(self, ls):
        '''
        ls ... list
        '''
        self.vec = ls

    def __len__(self):
        return len(self.vec)

    def __getitem__(self, idx):
        return self.vec[idx]

    def __repr__(self):
        return f'Vector({self.vec})'

    def add(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a + b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def sub(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a - b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def mul(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a * b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def norm(self):
        tmp = sum([x * x for x in self.vec])
        return sqrt(tmp)


def norm(vec):
    '''
    vec ... Vector class
    '''
    return vec.norm()


def cross(a, b):
    '''
    Outer product for 2d
    a,b ... Vector class
    '''
    assert len(a) == 2 and len(b) == 2
    first = a[0] * b[1]
    second = a[1] * b[0]
    return first - second


def dot(a, b):
    return sum(a.mul(b))


EPS = 1e-10


def contains(G, p):
    '''
    Gは多角形を表すリストで、今回ならばvectorが中に並んでいることとする
    pは内容しているか判別したい点で、Vectorで表す

    pが多角形Gの辺上にあれば1
    pが多角形Gに内包されていれば2
    それ以外は0をreturnする
    '''
    is_contain = False  # 内包してるか
    for i in range(len(G)):
        a = G[i].sub(p)
        b = G[(i + 1) % len(G)].sub(p)  # i+1が0に戻るようにこのような形式にしている。
        # もしpがG[i]とG[i+1]の線分上にある場合は即座に1をreturnします
        if abs(cross(a, b)) < EPS and dot(a, b) < EPS:
            # 外積が0→a,bが同一直線上
            # かつ 内積が負→a,bは逆を向いている
            # ならばpは線分上に存在する
            return 1
        # 内包を判定する。前処理として、yの座標によってa,bを入れ替える
        if a[1] > b[1]:  # aの方のy座標を小さくしたい
            a, b = b, a
        if a[1] < EPS and b[1] > EPS and cross(a, b) > EPS:  # 実際に判別する
            is_contain = (not is_contain)
    return (0, 2)[is_contain]


# load data
N = int(input())
G = []
for _ in range(N):
    g = Vector(list(map(int, input().split())))
    G.append(g)

# answer query
Q = int(input())
for _ in range(Q):
    p = Vector(list(map(int, input().split())))
    print(contains(G, p))



Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register
#define maxn 1200
#define inf 0x7f7f7f7f
#define mod (ll)(1e9+7)
#pragma GCC optimize(3)
#pragma -fcrossjumping
#pragma -fdefer-pop
#pragma -fmerge-constans
#pragma -fthread-jumps
#pragma -floop-optimize
#pragma -fif-conversion
#pragma -fif-conversion2
#pragma -fdelayed-branch
#pragma -fguess-branch-probability
#pragma -fcprop-registers
#pragma -fforce-mem
#pragma -foptimize-sibling-calls
#pragma -fstrength-reduce
#pragma -fgcse
#pragma -fcse-follow-jumps
#pragma -frerun-cse-after-loop
#pragma -fdelete-null-pointer-checks
#pragma -fextensive-optimizations
#pragma -fregmove
#pragma -fschedule-insns
#pragma -fsched-interblock
#pragma -fcaller-saves
#pragma -fpeephole2
#pragma -freorder-blocks
#pragma -fstrict-aliasing
#pragma -funit-at-a-time
#pragma -falign-functions
#pragma -fcrossjumping
#pragma -finline-functions
#pragma -fweb
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
inline ll print(ll x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>=10)
    {
        print(x/10);
    }
    putchar(x%10+'0');
}
int n;
int tot1,tot2;
int main()
{
	n=read();
	for(rg int i=1;i<=n;++i)
	{
		if(i%2==0) tot2++;
		else tot1++; 
	}
	cout<<tot1*1.0/(1.0*(tot1+tot2));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll l = a*c;
  ll m = a*d;
  ll n = b*c;
  ll o = b*d;
  ll ans = max(max(l,m),max(n,o));
  cout<<ans<<endl;
}



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

#define ll long long int

bool KD[40];
ll C[40], P2[40], dp[40][2];
// dp[i][0] : maximum use of last i digits of X by keeping them less or equal than i last digits of K
// dp[i][1] : maximum use of last i digits of X without limitation

ll max(ll a, ll b)
{
    if (a >= b) return(a);
    return(b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        ll a;
        cin >> a;
        for (int j = 0; j < 40; j++)
        {
            if (a % 2) C[j]++;
            a /= 2;
        }
    }
    for (int i = 0; i < 40; i++)
    {
        if (K % 2) KD[i] = true;
        K /= 2;
    }
    P2[0] = 1;
    for (int i = 1; i < 40; i++) P2[i] = 2 * P2[i - 1];
    dp[0][1] = max(C[0], N - C[0]);
    for (int i = 1; i < 40; i++) dp[i][1] = dp[i - 1][1] + max(C[i], N - C[i]) * P2[i];
    if (KD[0]) dp[0][0] = dp[0][1];
    else dp[0][0] = C[0];
    for (int i = 1; i < 40; i++)
    {
        if (KD[i]) dp[i][0] = max(C[i] * P2[i] + dp[i - 1][1], (N - C[i]) * P2[i] + dp[i - 1][0]);
        else dp[i][0] = C[i] * P2[i] + dp[i - 1][0];
    }
    cout << dp[39][0] << '\n';
    return(0);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>

using namespace std;

int main(){
    int a,b;
    int turi;
    int hyaku,gohyaku,sen;

    cin >> a >> b;

    while((a!=0)&&(b!=0)){
    
      turi=b-a;

      sen=turi/1000;
      turi=turi-sen*1000;

      gohyaku=turi/500;
      turi=turi-gohyaku*500;

      hyaku=turi/100;
      turi=turi-hyaku*100;

      cout << hyaku << " ";
      cout << gohyaku << " ";
      cout << sen << endl;

      cin >> a >> b;
    }
    return 0;
}

Measured memory_bytes: 0
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Roadwork
 */

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

/* constant */

const int MAX_N = 200000;
const int MAX_M = MAX_N * 2;
const int MAX_E2 = 1 << 20; // = 1048576

typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

template <typename T, const int MAX_E2>
struct SegTree {
  int n, e2;
  T nodes[MAX_E2];
  SegTree() {}

  void init(int _n) {
    n = _n;
    for (e2 = 1; e2 < n; e2 <<= 1);
    memset(nodes, -1, sizeof(nodes));
  }

  T &get(int i) { return nodes[e2 - 1 + i]; }

  void eval_all() {
    for (int j = 0; j < e2 - 1; j++)
      if (nodes[j] >= 0) {
	nodes[j * 2 + 1] = nodes[j * 2 + 2] = nodes[j];
	nodes[j] = -1;
      }
  }

  void set_range(int r0, int r1, T v, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k] = v;
      return;
    }

    int k0 = k * 2 + 1, k1 = k0 + 1;
    if (nodes[k] >= 0) {
      nodes[k0] = nodes[k1] = nodes[k];
      nodes[k] = -1;
    }
    
    int im = (i0 + i1) / 2;
    set_range(r0, r1, v, k0, i0, im);
    set_range(r0, r1, v, k1, im, i1);
  }
  void set_range(int r0, int r1, T v) { set_range(r0, r1, v, 0, 0, e2); }
};

struct RW {
  int s, t, x;
  RW() {}
  RW(int _s, int _t, int _x): s(_s), t(_t), x(_x) {}
  bool operator<(const RW &r) const { return x < r.x; }
  void print() { printf("(%d,%d,%d)\n", s, t, x); }
};

/* global variables */

SegTree<int,MAX_E2> st;
RW rws[MAX_N];
int tms[MAX_M];

/* subroutines */

/* main */

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

  int m = 0;
  for (int i = 0; i < n; i++) {
    int s, t, x;
    scanf("%d%d%d", &s, &t, &x);
    rws[i] = RW(s - x, t - x, x);
    tms[m++] = s - x;
    tms[m++] = t - x;
  }
  sort(rws, rws + n);
  sort(tms, tms + m);
  m = unique(tms, tms + m) - tms;

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

  st.init(m);

  for (int i = n - 1; i >= 0; i--) {
    int r0 = lower_bound(tms, tms + m, rws[i].s) - tms;
    int r1 = lower_bound(tms, tms + m, rws[i].t) - tms;
    st.set_range(r0, r1, rws[i].x);
  }

  st.eval_all();
  //for (int i = 0; i < m; i++) printf("%d ", st.get(i)); putchar('\n');

  while (q--) {
    int d;
    scanf("%d", &d);

    int k = upper_bound(tms, tms + m, d) - tms - 1;
    printf("%d\n", (k < 0) ? -1 : st.get(k));
  }
  return 0;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main(){
    int N; cin >> N;
    vi vec(N);
    for(int i=0; i<N; i++){
        cin >> vec[i];
    }
    vi v = vec;
    int num = v.size();
    sort(v.begin(), v.end());
    bool r = true;
    if(v[N-1] == v[N-2]){
        r = false;
    }
    vi res(0);
    res.push_back(v[0]);
    for(int i=1; i<num; i++){
        if(v[i] != v[i-1]){
            res.push_back(v[i]);
        }
    }
    ll k = v[N-1];
    ll g = res.size();
    if(r == true){
    for(auto x: vec){
        if(x == k){
            cout << res[g-2] << endl;
        }
        else{
            cout << res[g-1] << endl;
        }
    }
    }
    else{
        for(auto x: vec){
        cout << res[g-1] << endl;
    }
    }
}

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


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

  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> s_i(n,0);

  rep(i,n) cin >> s[i];

  sort(s.begin(), s.end());

  int s_cnt = 0;
  rep(i,n){
    int cnt = 1;
    for(int j=i+1; j<n; j++){
      if(s[i] != s[j]) {
        break;
      }
      else{
        i++;
        cnt++;
      }
    }
    s_i[s_cnt] = cnt;
    s_cnt++;
  }

  decltype(s)::iterator result = unique(s.begin(), s.end());
  s.erase(result, s.end());
  size_t s_size = s.size();
  decltype(s_i)::iterator mx = max_element(s_i.begin(), s_i.end());
  vector<int> ans;

  rep(i,s_size){
    if(*mx == s_i[i]){
      ans.push_back(i);
    }
  }

  size_t ans_size = ans.size();

  rep(i,ans_size){
    int num = ans[i];
    cout << s[num] << '\n';
  }

  return 0;
  
}

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

int main(){
  vector<char> S(3);
  for(int i=0;i<3;i++)
    cin >>S.at(i);
  int t=0;
  for(int i=0;i<3;i++){
    if(S.at(i)=='o')
      t+=100;
  }
  cout <<700+t <<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    int min_val = 0, max_diff = -1000000000;
    int diff = 0;
    bool first = true;
    cin >> N;
    while (N--) {
        int r;
        cin >> r;
        if (!first) {
            diff = r - min_val;
            if (diff > max_diff) max_diff = diff;
        }
        if (first) { min_val = r; first = false; }
        else if (r < min_val) min_val = r;
    }
    cout << max_diff << endl;

    return 0;
}

Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char p;
    for(;;){
    cin>>a>>p>>b;
    if(p=='+')cout<<a+b<<endl;
    if(p=='-')cout<<a-b<<endl;
    if(p=='*')cout<<a*b<<endl;
    if(p=='/')cout<<a/b<<endl;
    if(p=='?')exit(0);
    }
    return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
 string s;
  
  cin >> s;
  int n = s.length();
  string a = s;
  reverse(a.begin(),a.end());
    if(a!=s){cout<<"No";return 0;}
  string b = s.substr(0,(n-1)/2);
  string  c= b;
  reverse(c.begin(),c.end());
  string d = s.substr((n+3)/2 - 1);
  string l = d;
  reverse(l.begin(),l.end());
  if(c==b && l==d) cout << "Yes";
  else cout <<"No";
}

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

int main(void){
  int n; cin >> n;
  vector<int> p(n),q(n);
  rep(i,n) cin >> p.at(i);
  rep(i,n) cin >> q.at(i);
  vector<int> a(n);
  rep(i,n) a[i] = i + 1;
  map<vector<int>, int> mp;
  do{
    mp[a] = mp.size();
  } while(next_permutation(a.begin(),a.end()));

  int ans = abs(mp[p] - mp[q]);
  cout << ans << endl;
  return 0;

}


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


#define INF 1000000000000
  signed main(){
    int n;
    cin>>n;
    if(n%2==0){cout<<n;}
    else{cout<<2*n;}
 }


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

int main(){
  int N;
  cin >> N;
  
  vector<int> L(N);
  for (int i = 0; i < N; i++){
    cin >> L.at(i);
  }

  sort(L.begin(), L.end());
  
  long long int ans = 0;
  for (int i = 0; i < N - 2; i++){
    for (int j = i + 1; j < N - 1; j++){
      for (int k = j + 1; k < N; k++){
        vector<long long int> l(3);
        l.at(0) = L.at(i);
        l.at(1) = L.at(j);
        l.at(2) = L.at(k);
        sort(l.begin(), l.end());
        
        if (l.at(0) == l.at(1) || l.at(1) == l.at(2)){
          continue;
        }
        else if(l.at(2) < l.at(0) + l.at(1)){
          ans++;
        }
        else{
          break;
        }
      }
    }
  }
  
  cout << ans << endl;
}

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

int main(){
  int n,y;
  cin >> n  >> y;
  bool X = false;
  for(int i=0 ;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      int k;
      k = (y-10000*i-5000*j)/1000;
      if(i+j+k==n && k>=0){
        cout << i << " " << j << " " <<k << endl;
        X = true;
      }
      if(X) break;
    }
    if(X) break;
  }
  if(!X) cout << "-1 -1 -1" << endl;
        
 

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <random>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    int n,k; cin >> n >> k;
    k--;
    string s; cin >> s;
    s[k] += 0x20;
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define W first
#define L second
#define F 5000
using namespace std;
pair<int,int> c[F*20];
int n,m,g[F];
int q[F],l[F],head,tail;
void BFS(int x,int len){
	cout<<x+1<<endl;
	int left=0,right=m,mids,mide;
	while(true){
		if(left>=right-1)break;
		mids=(left+right)/2;
		if(c[mids].W<x)left=mids;
		else right=mids;
	}
	left=0,right=m;
	while(true){
		if(left>=right-1)break;
		mide=(left+right)/2;
		if(c[mide].W<=x)left=mide;
		else right=mide;
	}
	mids-=2,mide+=2;
	for(int i=max(0,mids);i<(m,mide);i++){
		if(c[i].W==x){
			g[c[i].L]--;
			if(!g[c[i].L])q[tail]=c[i].L,l[tail]=len+1,tail++;
		}
	}
	return;
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)g[i]=0;
	for(int i=0;i<m;i++){
		cin>>c[i].W>>c[i].L;
		c[i].W--,c[i].L--;
		g[c[i].L]++;
	}
	sort(c,c+m);
	head=0,tail=0;
	int bef=F;
	bool twin=false;
	for(int i=0;i<n;i++)if(!g[i])q[tail]=i,l[tail]=0,tail++;
	while(true){
		BFS(q[head],l[head]);
		if(l[head]==bef)twin=true;
		bef=l[head];
		head++;
		if(head==tail)break;
	}
	cout<<twin<<endl;
	return 0;
}

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

vector<long long> divisors(const long long& x){
  vector<long long> ret;
  for(long long i = 1; i * i <= x; i++){
    if(x % i == 0){
      ret.push_back(i);
      if(x / i != i){
        ret.push_back(x / i);
      }
    }
  }
  return ret;
}

int main(){
  long long N;
  cin >> N;

  long long ans = 0;
  auto divisors_N = divisors(N);
  for(auto& div: divisors_N){
    if(div == 1){
      continue;
    }
    long long n = N;
    while(n % div == 0){
      n /= div;
    }
    if(n % div == 1){
      ans++;
    }
  }

  auto divisors_N1 = divisors(N - 1);
  for(auto& div: divisors_N1){
    if(div == 1){
      continue;
    }
    if(N % div == 1){
      ans++;
    }
  }
  cout << ans << endl;
}



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

const string Yes = "Yes";
const string No = "No";
string to_min(string S)
{
    string result;
    map<char,char> g;
    char now = 'a';
    for(char ch:S)
    {
        if(g.count(ch))
        {
            result += g[ch];
        }else
        {
            g[ch] = now++;
            result += g[ch];
        }
    }
    return result;
}
void solve(string S, string T)
{
    if(to_min(S) == to_min(T))
    {
        cout<<Yes<<endl;
    }else
    {
        cout<<No<<endl;
    }
}


int main()
{
    string S;
    cin >> S;
    string T;
    cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 1552
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, k, ans = 0;
    cin >> n >> k;
    rep(i, n){
        int x;
        cin >> x;
        ans += min(2 * x, 2 * abs(x-k));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
    int N, ans = 0, pre = -1;
    cin >> N;
    int A[N+1], B[N+1], C[N];
    REP(i, N){
        cin >> A[i+1];
    }
    REP(i, N){
        cin >> B[i+1];
    }
    REP(i, N-1){
        cin >> C[i+1];
    }

    ans = B[A[1]];
    pre = A[1];
    REP(i, N-1){
        ans += B[A[i+2]];
        if(pre+1 == A[i+2]){
            ans += C[pre];
        }
        pre = A[i+2];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	a := readInt()
	b := readInt()
	c := readInt()

	if a+b == c || b+c == a || c+a == b {
		println("Yes")
	} else {
		println("No")
	}

}


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

int yu(int a, int b) {
  while(1) {
    int temp=a%b;
    if(temp==0) {
      return b;
    }
    else {
      a=b;
      b=temp;
    }
  }
}

int main () {
  int a,b,c;
  cin >> a >> b >> c;
  if (c%yu(a,b)==0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
int main()
{
    int n, m;
    cin >> n >> m;
    string ans = "0";
    if(n==3) ans = "100";
    if(n==2) ans = "10";
    int s;
    char c;
    vector<char> cnt(n, 'F');
    rep(i, m){
        cin >> s  >> c;
        s--;
        if(cnt[s] != c && cnt[s]!='F') {ans = "-1"; break;}
        else{cnt[s] = c;}
        if(s==0 && n>=2 && c=='0') {ans = "-1"; break;}
        ans[s] = c;
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    ll N;
    vector<ll> a;
    vector<ll> good;
    vector<ll> balls;
    cin >> N;
    a.resize(N);
    balls.resize(N, 0);
    for(ll i = 0;i < N;i++) cin >> a[i];
    for(ll i = N;i >= 1;i--) {
        ll count = 0;
        for(ll j = 1;j <= N / i;j++) {
            /*if(i * j <= N)*/ count += balls[i * j - 1];
        }
        if(count % 2 != a[i - 1]) {
            balls[i - 1] = 1;
            good.push_back(i);
        }
    }
    cout << good.size() << endl;
    for(auto &i: good) cout << i << ' ';
    return 0;
}


Measured memory_bytes: 4980
from heapq import heapify, heappush, heappop
N = int(input())
V = list(map(int, input().split()))

heapify(V)

now_value = 0
while len(V) > 1:
    x = heappop(V)
    y = heappop(V)
    heappush(V, (x+y)/2)

print(heappop(V))

Measured memory_bytes: 3060
#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 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 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> > //第二成分の大きさが関係ない
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;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll ans = 0 ;
    string S;
    cin >> S;
    
    ll cnt = 0;
    rep(i, S.size()){
        if(S[i] == 'A'||S[i] == 'C'||S[i] == 'G'||S[i] == 'T'){
            cnt ++;
        }
        else{
            ans = max(ans, cnt);
            cnt = 0 ;
        }
    }
    
    ans = max(ans, cnt);
    
    cout << ans << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
k = 10**6

for i in range(a[0],a[-1]+1):
  total = 0
  for s in a:
    total +=(i-s)**2
  #print(total)
  k = min(k,total)
print(k)  

Measured memory_bytes: 63648
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
ll com[51][51];
void comb_table(int N){
    com[0][0] = 1;
    for(int i = 1; i <= N; ++i){
        for(int j = 0; j <= i; ++j){
            com[i][j] += com[i-1][j];
            if(j>0) com[i][j] += com[i-1][j-1];
        }
    }
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  REP(i, N){
    cin >> v[i];
  }
  comb_table(N);

  sort(v.begin(), v.end(), greater<ll>());
  ll sum = 0;
  REP(i, A){
    sum+=v[i];
  }
  ll comb = 0;
  int n, r;
  if(v[0] == v[A-1]){
    int cnt = A;
    for(int i = A; i < N; i++){
      if(v[i] != v[A-1]){
        break;
      }
      cnt++;
    }
    for(int i = A; i <= min(cnt, B); i++){
      comb += com[cnt][i];
    }
  }
  else{
    int b, e;
    b = e = -1;
    for(int i = 0; i < N; i++){
      if(v[i] == v[A-1] && b == -1){
        b = i;
      }
      else if(b != -1 && v[i] != v[A-1]){
        e = i;
        break;
      }
    }
    if(e == -1){
      e = N;
    }
    comb = com[e-b][A-b];
  }
  double ave = (double) sum/ A;
  printf("%.6f\n", ave);
  cout << comb << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#define llong long long
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  int ans = 0;
  For(i, A, B+1){
    if (i/10000 == i%10 && (i/1000 - (i/10000) * 10 ) == (i%100 - i%10)/10) {
      ans ++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
long mod=1e9+7,dp[3333][3333];
c,i,j;
main(n)
{
	scanf("%d\n",&n);
	dp[0][0]=1;
	for(;++i<n;)
	{
		c=getchar();
		for(j=0;j<=i;j++)
		{
			dp[i][j]=c=='<'?(*dp[i-1]-dp[i-1][j]+mod)%mod:dp[i-1][j];
		}
		for(;j--;)dp[i][j]=(dp[i][j]+dp[i][j+1])%mod;
	}
	printf("%d",*dp[n-1]);
}

Measured memory_bytes: 78336
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> n = new ArrayList<Integer>();

		while(sc.hasNextInt()){
			int value = sc.nextInt();
			if(value != 0){
				n.add(value);
			}
			else{
				break;
			}
		}

		for(int i = 0; i < n.size(); i++){
			System.out.println("Case " + (i + 1) + ": " + n.get(i));
		}
	}
}



Measured memory_bytes: 44964
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    if (v[0] != 1) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> index(n);
    for (int i = 0; i < n; i++) {
        index[i] = i+1;
    }
    deque<int> ans;
    while (ans.size() < n) {
        int q = -1;
        for (int i = 0; i < n; i++) {
            if (index[i] == v[i]) q = v[i];
        }
        if (q == -1) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_front(q);
        for (int i = 0; i < n; i++) {
            if (index[i] == q) index[i] = -1;
            if (index[i] > q) index[i]--;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{

	public static void main(String[] args) throws IOException{
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		if(s.equals("ABC"))
		{
			System.out.println("ARC");
		}
		else
		{
			System.out.println("ABC");
		}

	}

}


Measured memory_bytes: 32528
#include <iostream>
using namespace std;
int tab[(int)1e5+4], dp[(int)1e5+4];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; ++i){
        cin>>tab[i];
    }

    for(int i=2; i<=n; ++i){
        if(i>2) dp[i]=min(dp[i-1]+abs(tab[i]-tab[i-1]), dp[i-2]+abs(tab[i]-tab[i-2]));
        else dp[i]=dp[i-1]+abs(tab[i]-tab[i-1]);
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#define FAST ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

priority_queue <ll, vector<ll>, greater<ll> > q1;//小的在前
priority_queue <ll> q2;//大的在前

ll a[maxn * 3];
ll l[maxn * 3], r[maxn * 3];//维护l最大,r最小

int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i <= 3 * n; i++){
		scanf("%lld", &a[i]);
	}
	ll sum = 0;
	for(int i = 1; i <= 3 * n; i++){
		q1.push(a[i]);
		sum += a[i], l[i] = sum;
		if(q1.size() == n + 1){
			sum -= q1.top();
			q1.pop();
			l[i] = sum;
		}
	}
//---------------------------------------
	sum = 0;
	for(int i = 3 * n; i >= 1; i--){
		q2.push(a[i]);
		sum += a[i], r[i] = sum;
		if(q2.size() == n + 1){
			sum -= q2.top();
			q2.pop();
			r[i] = sum;
		}
	}
	ll ans = -1e15;
	for(int i = n; i <= 2 * n; i++){
		ans = max(ans, l[i] - r[i+1]);//left - right
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    int n;
    int sum = 0;
    cin >> n;
    vector<int> t(n);
    rep(i, n) {
        cin >> t.at(i);
        sum += t.at(i);
    }
    int m;
    cin >> m;
    vector<int> p(m);
    vector<int> q(m);
    rep(i, m) cin >> p.at(i) >> q.at(i);
    rep(i, m) {
        int ans;
        ans = sum - t.at(p.at(i) - 1) + q.at(i);
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
list = input().split(" ")
N = int(list[0])
A = int(list[1])
B = int(list[2])

num1 = N // (A + B)
num2 = N % (A + B)
if num2 <= A:
    print(num1 * A + num2)
else:
    print(num1 * A + A)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	balls := make(Balls, n)

	for i := 0; i < n; i++ {
		balls[i].x = getNextInt(scanner)
		balls[i].y = getNextInt(scanner)
	}
	sort.Sort(balls)
	dd := make(IntMapMap, 0)
	for i := 0; i < n; i++ {
		for ii := i + 1; ii < n; ii++ {
			dx := balls[ii].x - balls[i].x
			dy := balls[ii].y - balls[i].y
			dd[dx] = dd.getMap(dx)
			dd[dx][dy] = dd.get(dx, dy)
			dd[dx][dy]++
		}
	}
	max := 0
	for _, mm := range dd {
		for _, m := range mm {
			if max < m {
				max = m
			}
		}
	}
	fmt.Fprintln(writer, n-max)

	writer.Flush()
}

type Ball struct {
	x int
	y int
}

type Balls []Ball

func (a Balls) Len() int      { return len(a) }
func (a Balls) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Balls) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y < a[j].y
	}
	return a[i].x < a[j].x
}
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if v, ok := m[key]; ok {
		return v
	}
	return 0
}

type IntMapMap map[int]IntMap

func (m IntMapMap) getMap(key1 int) IntMap {
	if v, ok := m[key1]; ok {
		return v
	}
	return make(IntMap, 0)
}

func (m IntMapMap) get(key1, key2 int) int {
	return m[key1].get(key2)
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,K;
  cin >> N >> K;
  vector<int> h(N),dp(N,0);
  REP(i,N) cin >> h[i];
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  REP2(i,2,N){
    int tmp=dp[i-1]+abs(h[i]-h[i-1]);
    REP2(j,i-K,i){
      if(j<0) continue;
      tmp = min(tmp, dp[j] + abs(h[i]-h[j]));
    }
    dp[i] = tmp;
  }
  cout << dp[N-1];
  return 0;
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

int main() {
  string s;
  int K;
  cin >> s >> K;

  rep0(i, s.size()) {
    if (s[i] == 'a') continue;
    if ('z' - s[i] + 1 <= K) {
      K -= ('z' - s[i] + 1);
      s[i] = 'a';
    }
  }

  if (K > 0) {
    s[s.size() - 1] = ((s[s.size() - 1] - 'a' + K) % 26) + 'a';
  }

  cout << s << BR;
  return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  priority_queue<ll>p;
  rep(i,0,n)p.push(a[i]);
  rep(i,0,m){
    ll x=p.top();
    x/=2;
    p.pop();
    p.push(x);
  }
  rep(i,0,n){
    res+=p.top();
    p.pop();
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 2168