akhauriyash/Code-Regression huggingface dataset:
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)

const int M=1000000007;
const int MM=998244353;


 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;




int main()
{ 

IOS;


ll n,k;cin>>n>>k;

if(!k){
  cout<<n*n;
  return 0;
}

ll tot=0;

for(int i=k+1;i<=n;i++){
  ll e=min((n/i)*i+i-1,n);
  ll r=(n/i)*(i)+k;
tot+=(n/i)*(i-k)+max(0ll,e-r+1);
}

cout<<tot<<endl;


return 0;
 
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define ll long long int
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

ll n, s;
priority_queue<ll, vector<ll>, greater<ll> > q;

ll res(ll nn, ll a){
	if(nn!=0){
		return res(nn/a, a) + nn % a;  
	}else{
		return (ll)0;
	}
}

int main(){
	cin >> n >> s;
	if(n==s){
		cout << n+1 << endl;
		return 0;
	}
	for(int i=1;i<=sqrt(n-s);i++){
		if((n-s)%i==0){
			q.push(i+1);
			q.push((n-s)/i+1);
		}
	}
	while(!q.empty()){
		if(res(n, q.top())==s){
			cout << q.top() << endl;
			return 0;
		}else{
			q.pop();
		}
	}
	cout << 0-1 << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n;
  ll num = -1;
  
  rep(i,1e5){
    if(n == i*(i-1)/2) num = i;
  }
  
  if(num == -1){
    cout << "No" << endl;
    return 0;
  }
  
  vector<vector<ll>> table(num,vl(0));
  
  ll now = 1;
  
  for(ll i=0; i < num-1; i++){
    ll cnt = table[i].size();
    
    for(ll j=0; j < num - cnt-1; j++){
      table[i+j+1].push_back(now+j);
      table[i].push_back(now+j);
    }
    
    now += num-cnt-1;
  }
  

  cout << "Yes" << endl << num << endl;
  
  rep(i,num){
    cout << num-1 << ' ' ;
  
    for(auto array : table[i]){
      cout << array << ' ';
    }
    
    cout << endl;
  }
  
  
}

Measured memory_bytes: 5068
#include<vector>
#include<algorithm>
#include <iostream>
using namespace std;
int main(void){
    //
    int N;
    
    cin>>N;
    
    vector<int> a(N);
    
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    
    int Alice=0,Bob=0;
    
    sort(a.begin(),a.end(),greater<int>());
    
    for(int i=0;i<N;i++){
        if(i%2==0){
            Alice=Alice+a[i];
        }
        else{
            Bob=Bob+a[i];
        }
    }
    
    
    
    
cout<<Alice-Bob<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(long long*)a > *(long long*)b){
        return -1;
    }else if (*(long long*)a == *(long long*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]);
        }
    }
}*/

char c[105][105];

int main(void){
    int h, w;
    scanf("%d %d", &h, &w);
    for (int i = 0 ; i < h; i++){
        scanf(" %s", c[i]);
    }
    for (int i = 0 ; i < h; i++){
        printf("%s\n%s\n", c[i], c[i]);
    }

    return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {            
            string[] S = Console.ReadLine().Split(' ');

            Console.WriteLine(Lcm(long.Parse(S[0]),long.Parse(S[1])));
        }

        // 最小公倍数
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}

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

const int MAXN = 1e5 + 10;
int a[MAXN], n, ans;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		if (a[i] == i + 1)
			ans++, i++;
	cout << ans;
}

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

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine();
        

        System.Console.WriteLine(vars == "AAA" || vars == "BBB" ? "No" : "Yes");

    }

}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

int euclid(int a, int b)
{
    if (a < b)
        euclid(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int a, b;
    cin >> a >> b;

    if ((a * b) % 2 == 0)
        cout << "Even" << endl;
    else
        cout << "Odd" << endl;
}


Measured memory_bytes: 256
# coding:utf-8

def printline(data):
    l=""
    for i,s in enumerate(data):
        l = l + str(s)
        if i+1 != len(data):
            l = l+" "
    print(l)


length = int(input())
data = list(map(int,input().split()))
printline(data)
for i in range(1,len(data)):
    tmp = data[i]
    i2 = i - 1
    while i2 >=0 and data[i2] > tmp:
        data[i2+1] = data[i2]
        i2 -= 1

    data[i2+1] = tmp
    printline(data)


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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, less<int>, null_type, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 1e5 + 667;

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

    int n;
    cin >> n;
    int ans = n / 2;
    if(n % 2 == 1) ans++;
    cout << ans;
    return 0;
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

template<class T, class Q> inline bool chmin(T& a, Q b) {
    if (a > b) { 
        a = b;
        return true; 
    }
    return false;
}

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) { 
        a = b; 
        return true; 
    }
    return false;
}

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //

void operator*(vli& vec, lint k) {
    rep(i, (int)vec.size()) {
        vec[i] = ((vec[i] % mod) * (k % mod)) % mod;
    }
    return;
}


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    int N, K;
    cin >> N >> K;
    vli A(N);
    map<lint, lint> appear;
    
    rep(i, N) {
        lint k;
        cin >> k;
        A[i] = k;
        if (appear.count(k)) {
            appear[k]++;
        }
        else {
            appear[k] = 1;
        }
    }
    vli aftsmal(N, 0);
    rep(i, N - 1) {
        for (int j = i + 1; j < N; j++) {
            if (A[i] > A[j]) {
                aftsmal[i]++;
            }
        }
    }
    vli smaller(N, 0);
    rep(i, N) {
        for (auto x : appear) {
            if (x.first == A[i]) break;
            smaller[i] += x.second;
        }
    }

    smaller * (K * (K - 1LL) / 2LL);
    aftsmal * K;
    
    lint tori = 0;
    rep(i, N) {
        tori = (tori + smaller[i]) % mod;
        tori = (tori + aftsmal[i]) % mod;
    }

    cou(tori);
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var p = Enumerable.Range(0, N).Select(i => int.Parse(ReadLine())).OrderByDescending(x => x).ToArray();

        var ans = p[0] / 2 + p[1..].Sum();

        WriteLine(ans);
    }
}


Measured memory_bytes: 28476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-3;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

int main(){
   string S;
   cin >> S;
   if(S == "RRR") cout << 3 << endl;
   if(S == "RRS" || S == "SRR") cout << 2 << endl;
   if(S == "RSS" || S == "SSR" || S == "SRS" || S == "RSR") cout << 1 << endl;
   if(S == "SSS") cout << 0 << endl;
}


Measured memory_bytes: 3616
def gcd(a, b) :
    while True :
        if a < b :
            a, b = b, a
        amari = a % b
        if amari == 0 :
            break
        else :
            a, b = b, amari
    return(b)

n = int(input())
c = list(map(int, input().split()))
for i in range(n-1, 0, -1) :
    c[i-1] = int(c[i] * c[i-1] / gcd(c[i], c[i-1]))
print(c[0])


Measured memory_bytes: 5600
from heapq import heappop,heappush
# from line_profiler import LineProfiler
def main():
    while(True):
        W, H = map(int,input().split())
        if not W: break
        B = float('inf')
        Bi = -1
        consequNodes = []
        monsterNodes = [[] for _ in range(5)]
        idx = 0
        for i in range(H):
            for j,a in enumerate(input()):
                if a == ".":
                    continue
                elif a == "S": 
                    consequNodes.append([i,j,idx,5])
                    startNode = [i,j,idx,5]
                    idx+=1
                elif a == "G":
                    consequNodes.append([i,j,idx,6])
                    goalNode = [i,j,idx,6]
                    idx+=1
                elif a != ".":
                    consequNodes.append([i,j,idx,int(a)-1])
                    monsterNodes[int(a)-1].append([i,j,idx])
                    idx+=1
        for z in range(5):
            consequNodes[startNode[2]][3] = z
            dist = [[float('inf')]*idx for _ in range(6)]
            dist[1][startNode[2]] = 0
            que = [(0,1,startNode[2],0)]
            reached = False
            while que:
                cst,numrep,nid,huristicCost = heappop(que)
                cst = int(cst)-int(huristicCost)
                if numrep == 5:
                    reached = True
                    cst += abs(consequNodes[nid][0]-goalNode[0]) + abs(consequNodes[nid][1]-goalNode[1])
                    break
                nxtmonster = (consequNodes[nid][3]+1)%5
                for nxty,nxtx,nxtid in monsterNodes[nxtmonster]:
                    tmpCost = dist[numrep][nid] + abs(nxty-consequNodes[nid][0]) + abs(nxtx-consequNodes[nid][1])
                    if tmpCost < dist[numrep+1][nxtid]:
                        dist[numrep+1][nxtid] = tmpCost
                        h = abs(nxty-goalNode[0]) + abs(nxtx-goalNode[1])
                        h *= 0.99
                        heappush(que,(tmpCost+h,numrep+1,nxtid,h))
            if reached and cst < B:
                B = cst
                Bi = z+1
        if Bi == -1:
            print("NA")
        else:
            print(Bi,B)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

  ll N, K;
  ll mod = 1000000007;

  cin >> N >> K;

  vl a(N, 0);
  vvl dp(N+1, vl(3*(K+1), 0));
  vl acc(N, 0);

  FOR(i, 0, N) cin >> a[i];

  dp[0][K] = 1;
  FORD(k, 0, K+1)FOR(c, 0, N+1){
    if(c > 0){
      dp[c][k] = acc[c-1];
    }
    if(c == N) continue;
    acc[c] = (acc[c]+dp[c][k])%mod;
    acc[c] = (acc[c]+mod-dp[c][k+a[c]+1])%mod;
  }
  /*
  FOR(c, 0, N+1){
      FOR(k, 0, K+1){
        cout << dp[c][k] << ' ';
      }
      cout << endl;
  }
  */
  cout << dp[N][0] << endl;



}


Measured memory_bytes: 239360
class Program
{
    public static void Main()
    {
        int t = int.Parse(System.Console.ReadLine());
        int h = t/3600;
        int m = (t-3600*h)/60;
        int s = (t-3600*h-60*m);
        System.Console.WriteLine("{0}:{1}:{2}",h,m,s);
        
    }
    
}


Measured memory_bytes: 17928
fun main(args: Array<String>) {
    val A = readLine()!!.toInt()
    val B = readLine()!!.toInt()
    if(A == 1 && B == 2) {
        println(3)
    } else if(A == 1 && B == 2) {
        println(3)
    } else if(A == 2 && B == 1) {
        println(3)
    } else if(A == 2 && B == 1) {
        println(3)
    } else if(A == 3 && B == 1) {
        println(2)
    } else if(A == 1 && B == 3) {
        println(2)
    } else if(A == 2 && B ==3) {
        println(1)
    } else if(A == 3 && B == 2) {
        println(1)
    }

}

Measured memory_bytes: 29820
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

string S;
int K;
int dp[305][305][305];
bool b[305][305][305];
int f(int l,int r,int k){
	if(b[l][r][k])return dp[l][r][k];
	b[l][r][k]=1;
	if(r-l==1)return dp[l][r][k]=1;
	if(r-l==2){
		if(S[l]==S[l+1])return dp[l][r][k]=2;
		return dp[l][r][k]=k?2:1;
	}
	dp[l][r][k]=1;
	chmax(dp[l][r][k],f(l,r-1,k));
	chmax(dp[l][r][k],f(l+1,r,k));
	if(S[l]==S[r-1])chmax(dp[l][r][k],f(l+1,r-1,k)+2);
	else if(k)chmax(dp[l][r][k],f(l+1,r-1,k-1)+2);
	return dp[l][r][k];
}
signed main(){
	cin>>S>>K;
	cout<<f(0,len(S),K)<<endl;
}


Measured memory_bytes: 246016
// ALDS1_5_B
#include <iostream>
#include <vector>
using namespace std;

void merge(vector<int> &A, int left, int mid, int right, int &count){
	int n1 = mid - left, n2 = right - mid;
	vector<int> L(n1), R(n2);

	for(int i=0;i<n1;i++)
		L[i] = A[left+i];
	for(int i=0;i<n2;i++)
		R[i] = A[mid+i];

	int i=0, j=0;
	for(int k=left;k<right;k++){
		count++;

		if(i >= n1){
			A[k] = R[j];
			j++;
			continue;
		}

		if(j >= n2){
			A[k] = L[i];
			i++;
			continue;
		}

		if(L[i] <= R[j]){
			A[k] = L[i];
			i++;
		}else{
			A[k] = R[j];
			j++;
		}
	}
}

void mergeSort(vector<int> &A, int left, int right, int &count){
	if(left+1 < right){
		int mid = (left + right) / 2;
		mergeSort(A, left, mid, count);
		mergeSort(A, mid,right, count);
		merge(A, left, mid, right, count);
	}
}

int main(){
	int n, num, count=0;
	vector<int> S;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>num;
		S.push_back(num);
	}

	mergeSort(S, 0, n, count);

	for(int i=0;i<n;i++){
		if(i != 0)
			cout<<" ";
		cout<<S[i];
	}
	cout<<endl<<count<<endl;

	return 0;
}

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

using namespace std;

#define rg register
#define In inline
#define ll long long

const ll inf = 0x3f3f3f3f3f3f3f3f;

namespace IO{
	In ll read(){
		ll s = 0,ww = 1;
		char ch = getchar();
		while(ch < '0' || ch > '9'){if(ch == '-')ww = -1;ch = getchar();}
		while('0' <= ch && ch <='9'){s = 10 * s + ch - '0';ch = getchar();}
		return s * ww;
	}
	In void write(ll x){
		if(x < 0)putchar('-'),x = -x;
		if(x > 9)write(x / 10);
		putchar('0' + x % 10);
	}
}
using namespace IO;

ll N,A,B,C,D;
//vector<ll>v;
//ll fac[4] = {0,2,3,5};
/*
void dfs(ll cur,ll n){
//cout<<"dfs: cur="<<cur<<" n="<<n<<endl;
	if(cur == 4){
		v.push_back(n);
		return;
	}
	for(rg ll m = n;m <= N;m = m * fac[cur])dfs(cur + 1,m);
}*/

In void checkmin(ll &a,ll b){
	if(b < a)a = b;
}

map<ll,ll>f;
ll sp[10];
ll w[6];

ll dfs(ll N);

In void check(ll &ans,ll N,ll M,ll fac){
	ll cur = abs(N - fac * M) * D + dfs(M) + w[fac];
	if(cur < ans)ans = cur;
}

ll dfs(ll N){
//cout<<"dfs:N="<<N<<" f="<<f.count(N)<<endl;
	if(N <= 1)return sp[N];
	if(f.count(N))return f[N];
	ll ans = inf;
	if(inf / N >= D)ans = N * D;
	if(N % 2 == 0)checkmin(ans,dfs(N/2) + A);
	else{
		check(ans,N,N / 2,2);
		check(ans,N,(N+1) / 2,2);
	}
	if(N % 3 == 0)checkmin(ans,dfs(N/3) + B);
	else{
		check(ans,N,N / 3,3);
		check(ans,N,(N+2) / 3,3);	
	}
	if(N % 5 == 0)checkmin(ans,dfs(N/5) + C);
	else{
		check(ans,N,N / 5,5);
		check(ans,N,(N+4) / 5,5);
	}
//cout<<"N="<<N<<" ans="<<ans<<endl;
	return f[N] = ans;
}

int main(){
//	freopen("A.in","r",stdin);
//	freopen("A.out","w",stdout);
	ll T = read();
	while(T--){
//		v.resize(0);
		f.clear();
		N = read(),A = read(),B = read(),C = read(),D = read();
		w[2] = A;
		w[3] = B;
		w[5] = C;
		sp[0] = 0;
		sp[1] = D;
		sp[2] = min(min(2*D,D+A),min(2*D+B,4*D+C));
		
//dfs(1,1);	
//cout << v.size() << endl;
//sort(v.begin(),v.end());
//for(rg int i = 0;i < v.size();i++)cout<<"v="<<v[i]<<" dv="<<v[i] - v[i-1] << endl;
		cout << dfs(N) << endl;
	}
	return 0;
}

Measured memory_bytes: 4428
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vi d(N); REP(i, N) cin >> d[i];

    set<int> st;
    REP(i, N) st.insert(d[i]);

    int ans = (int)st.size();
    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
static const int N=100;
int min(int a, int b){ return a < b ? a : b; }
int main(){
  int i, j, r, l, y;
  int n, q[N+1], e[N+1][N+1];
  scanf("%d", &n);
  for (i=1;i<=n;i++)
    scanf("%d %d", &q[i-1], &q[i]);
  

  for(i=1;i<=n;i++)
    e[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=0;i<=n-l+1;i++){
      j=i+l-1;
      e[i][j] = (1<<21);
      for(r=i;r<=j-1;r++){
        e[i][j]=min(e[i][j],e[i][r]+e[r+1][j]+q[i-1]*q[r]*q[j]);
        y=e[i][r]+e[r+1][j]+q[i-1]*q[r]*q[j];

      }
    }
  }



  printf("%d\n", e[1][n]);

  return 0;
}



Measured memory_bytes: 2044
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	if (b < n * a)
		cout << b << endl;
	else
		cout << n * a << endl;
}


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

using namespace std;

typedef long long ll;

class Prime {
// n以下の素数を列挙する
public:
  const int n;
  vector<bool> is_prime;
  vector<int> primes;
  Prime(int size) : n(size), is_prime(n+1, true) {
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
      if (!is_prime[i]) continue;
      primes.push_back(i);
      int tmp = 2*i;
      while (tmp <= n) {
        is_prime[tmp] = false;
        tmp += i;
      }
    }
  }

  bool check(int x) { return is_prime[x]; }
};

struct PrimeFactorization {
  // n*n以下の数についての素因数分解
  const int n;
  Prime p;
  PrimeFactorization(int n) : n(n), p(n) {}

  map<ll, int> calc(ll a) {
    map<ll, int> ret;
    ll tmp = a;
    for (int i: p.primes) {
      if (i > tmp) break;
      int count = 0;
      while (tmp % i == 0) { 
        ++count;
        tmp /= i;
      }
      if (count > 0) ret[i] = count;
    }
    if (tmp > 1) ret[tmp] = 1;
    return ret;
  }
};


int main() {
  PrimeFactorization pf(1000000);
  map<ll, int> factors;
  ll a, b;
  cin >> a >> b;
  map<ll, int> fa = pf.calc(a);
  map<ll, int> fb = pf.calc(b);
  int ans = 1;
  for (auto it: fa) { 
    if (fb.find(it.first) == fb.end()) continue;
    ++ans;
  }
  cout << ans << endl;
}



Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int d=max({a,b,c});
	int e=min({a,b,c});
	int f=a+b+c-d-e;
	cout<<d-f+f-e<<endl;
}


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

int main(){
    int N,M,X;
    cin>>N>>M>>X;
    vector<int>A(110);
    
    for(int i=0;i<M;++i){
    cin>>A[i];
    }
   

    int ans=0;
    for(int i=X;i<N;++i){
        for(int j=0;j<M;++j){
            if(i==A[j]){
                ans++;
            }
        }
    }

    int sum=0;

        for(int i=X;i>0;--i){
        for(int j=0;j<M;++j){
            if(i==A[j]){
                sum++;

            }
            
        }
    }
    cout<<min(ans,sum)<<endl;
}


Measured memory_bytes: 256
// atcoder/abc123/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int x, y, z;
  lli k;
  while (cin >> x >> y >> z >> k) {
    vector<lli> a(x);
    vector<lli> b(y);
    vector<lli> c(z);
    cin >> a >> b >> c;

    vector<lli> d;
    each (i, a) each (j, b) d.push_back(i + j);
    sort(begin(d), end(d));
    reverse(begin(d), end(d));
    while (k < d.size()) d.pop_back();

    vector<lli> e;
    each (i, d) each (j, c) e.push_back(i + j);
    sort(begin(e), end(e));
    reverse(begin(e), end(e));
    while (k < e.size()) e.pop_back();

    each (i, e) cout << i << endl;
  }

  return 0;
}


Measured memory_bytes: 43240
#include <bits/stdc++.h>
 
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define int long long
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
const int N = 10010, D = 100;
const int MOD = 1000000007;
const int LOG = 20;
 
int d;
string n;
ll dp[N][D];
 
int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> d;
	dp[0][0] = 1;
	for (int i = 1; i < n.size(); i++){
		for (int j = 0; j < d; j++){
			for (int k = 0; k < 10; k++){
				int num = (j - k) % d;
				num += d;
				num %= d;
				dp[i][j] += dp[i - 1][num];
				dp[i][j] %= MOD;
			}
			//cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
		}
	}
	ll sum = 0;
	ll ans = 0;
	for (int i = 0; i < n.size(); i++){
		for (int j = 0; j < n[i] - '0'; j++){
			ll nw = sum + j;
			nw %= d;
			nw = d - nw;
			nw %= d;
			ans += dp[n.size() - i - 1][nw];
			ans %= MOD;
			//cout << n.size() - i - 1 << ' ' << nw << ' ' << dp[n.size() - i - 1][nw] << '\n';
		}
		sum += n[i] - '0';
		sum %= d;
	}
	ans --;
	ans %= MOD;
	ans += MOD;
	ans %= MOD;
	if (sum % d == 0) ans ++;
	cout << ans % MOD;
 
 
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
typedef long long ll; 
 
using namespace std;
using P = pair<ll, ll>;

vector<P> prime_factorize(ll n) {
	vector<P> res;

	for (ll p = 2; p * p <= n; p++) {
		if (n % p != 0) continue;

		int num = 0;
		while (n % p ==0) {
			num++;
			n /= p;
		}
		res.push_back(P(p, num));
	}
	if (n != 1) res.push_back(P(n, 1));

	return res;
}

int main() {
	ll N, p;
	cin >> N >> p;
	vector<P> v = prime_factorize(p);
	ll res = 1;
	for (ll i = 0; i < v.size(); ++i) {
		ll vf = v[i].first;
		ll vs = v[i].second;
		while (vs >= N) {
			res *= vf;
			vs -= N;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
//#include <atcoder/all>
//using namespace atcoder;
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;

//using mint = modint998244353;
//These are for segment tree
/*int op(int a, int b){return max(a, b);}
int e(){return -1;}
bool f(int v){ return v < target;}
*/

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

template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

/*--------------------------------------------------------------------------------------------------------------------------------*/

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	bool ok = false;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		if(a == b) cnt++;
		else cnt = 0;
		if(cnt == 3) ok = true;
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
	
} 


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
//  int a, b,c,d;
  cin >> s;
  if (((s[0]==s[1])&&(s[1]==s[2]))||((s[1]==s[2])&&(s[2]==s[3])))
  cout << "Yes"<<endl;
  else
  cout << "No"<<endl;    
}

Measured memory_bytes: 256
A,B,C=map(int,input().split())
a=A
b=B
c=C
cnt=0
if a%2 == b%2:
  if b%2 != c%2:
    a+=1
    b+=1
    cnt+=1
else:
  if b%2 == c%2:
    b+=1
    c+=1
    cnt+=1
  else:
    a+=1
    c+=1
    cnt+=1
numlist=[a,b,c]
numlist.sort()
cnt+=(numlist[2]-numlist[0])/2
cnt+=(numlist[2]-numlist[1])/2
print(int(cnt))

Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

typedef long long ll;

const int N = 500;
const int inf = 1000000000;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

class st{
public:
  int y,x,cost;
  bool operator<(const st & a)const{
    return cost > a.cost;
  }
};


/*
  e®É½Çè­½ßÉKvÈÅ¬ÌFØxðßéB
  »ÌÊÉîÃ¢ÄAx±Ì®ðKêé½ßÉKvÈÅ¬ÌxðvZ·é
*/
int cost[N][N];
int m[N][N];
vector<ll> dijkstra(int r,int c,int sy,int sx){
  rep(i,r)rep(j,c)cost[i][j] = inf;
  priority_queue<st> Q;
  cost[sy][sx] = 1;
  Q.push((st){sy,sx,1});
  while(!Q.empty()){
    st now = Q.top();Q.pop();
    int y = now.y,x = now.x;
    if (cost[y][x] != now.cost)continue;
    rep(i,4){
      int nex = x+dx[i],ney = y+dy[i];
      if (nex == -1 || ney == -1 || nex == c || ney == r)continue;
      int nec = max(now.cost,m[ney][nex]);
      if (cost[ney][nex] > nec){
	//cout << y <<" "<< x <<" to " << ney <<" "<< nex <<" "<< now.cost <<" " << m[ney][nex] << endl;
	cost[ney][nex] = nec;
	Q.push((st){ney,nex,nec});
      }
    }
  }
  vector<ll> ret;
  ret.push_back(0);/*0±Ì®ðKêéÉÍx0Å¢¢B*/
  rep(i,r)rep(j,c)ret.push_back(cost[i][j]);
  sort(ret.begin(),ret.end());
  return ret;
}


vector<ll> compute(){
  int r,c,sy,sx;
  cin>>c>>r>>sx>>sy;
  sy--;sx--;
  rep(i,r)rep(j,c)cin>>m[i][j];
  return dijkstra(r,c,sy,sx);
}

main(){
  int R;
  while(cin>>R && R){
    vector<ll> a=compute();
    vector<ll> b = compute();
    //rep(i,a.size())cout << a[i] <<" " ;cout << endl;
    //rep(i,b.size())cout << b[i] <<" " ;cout << endl;
    ll ans = inf;
    rep(i,R+1){
      int j = R-i;
      if (i >= a.size() || j >= b.size())continue;
      ans = min(ans,a[i]+b[j]);
    }
    cout << ans << endl;
  }
  
}

Measured memory_bytes: 5164
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

s = list(input())
n1 = int(str(s[0])+str(s[1]))
n2 = int(str(s[2])+str(s[3]))
f_yymm = False
f_mmyy = False

if n2 > 0 and n2 < 13:
    f_yymm = True

if n1 > 0 and n1 < 13:
    f_mmyy = True


if f_yymm and f_mmyy:
    print("AMBIGUOUS")
elif f_mmyy:
    print("MMYY")
elif f_yymm:
    print("YYMM")
else:
    print("NA")






Measured memory_bytes: 3064
#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 count = 0;
  for( int i = 0 ; i < 3; i++){
    if(s.at(i) == 'o') count++;
  } 
  cout << count * 100 + 700;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
#include<climits>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<(n);i++)
#define end(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
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 long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){
    
    int i,n;
    cin>>n;
    char c;
    int s[n];
    rep(i,n){
    	cin>>c;
		if(c=='W')s[i]=-1;
		else s[i]=1;
	}
    int t=0,maxt=-INT_MAX,maxi=0;
	rep(i,n){
		t+=s[i];
		if(t>maxt){
			maxt=t;
			maxi=i;
		}
		else if(t==maxt){
			if(abs(n/2-maxi)>abs(n/2-i)) maxi=i;
		}
	}
	int ans=0;
    for(i=0;i<maxi;i++)if(s[i]==-1)ans++;
    for(i=maxi+1;i<n;i++)if(s[i]==1)ans++;
    
//    cout<<maxi<<" "<<maxt<<endl;
	end(ans);
    
	return 0;
}


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

int main(){
	int N; cin >> N;
	vector<int> A(N+2);
	for(int i=1; i<=N; i++)
		cin >> A[i];

	int sum = 0;
	for(int i=0; i<=N; i++)
		sum += abs(A[i+1]-A[i]);

	for(int i=1; i<=N; i++){
		if((A[i]-A[i-1])*(A[i]-A[i+1])<=0)
			cout << sum << endl;
		else
			cout << sum-2*(min(abs(A[i]-A[i-1]), abs(A[i]-A[i+1]))) << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
use std::vec::Vec;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn abs(x: &i64) -> i64 {
    let y: i64 = *x;
    if y < 0 {
        return -y;
    } else {
        return y;
    }
}

fn main() {
    let n: usize = read();
    let h: Vec<i64> = read_vec();
    let mut c: Vec<i64> = Vec::new();
    c.push(0);
    c.push(abs(&(h[0]-h[1])));

    let mut temp: i64 = 0;

    for i in 2..n {
        temp = cmp::min(c[i-1] + abs(&(h[i] - h[i-1])),
                        c[i-2] + abs(&(h[i] - h[i-2])));
        c.push(temp);
    }
    println!("{}", c[n-1]);


}


Measured memory_bytes: 6396
#include<cstdio>
#include<vector>
#include<deque>
using namespace std;
int main(){
    int n,m,a,b,flag=0,used[100001]={};
    vector<int> g[100001];
    deque<int> ans;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d %d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ans.push_back(1);
    ans.push_back(g[1][0]);
    used[1]=used[g[1][0]]=1;
    while(!flag){
        flag=1;
        for(int i=0;i<g[ans.front()].size();i++){
            if(used[g[ans.front()][i]]==0){
                ans.push_front(g[ans.front()][i]);
                used[ans.front()]=1;
                break;
            }
        }
        for(int i=0;i<g[ans.back()].size();i++){
            if(used[g[ans.back()][i]]==0){
                ans.push_back(g[ans.back()][i]);
                used[ans.back()]=1;
                break;
            }
        }
        for(int i=0;i<g[ans.front()].size();i++){
            flag*=used[g[ans.front()][i]];
        }
        for(int i=0;i<g[ans.back()].size();i++){
            flag*=used[g[ans.back()][i]];
        }
    }
    printf("%ld\n",ans.size());
    for(int i=0;i<ans.size();i++){
        printf("%d ",ans[i]);
    }
    printf("\n");
}

Measured memory_bytes: 7040
import java.util.*;

public class Main {
    private static Scanner scanner;

    public static int[] inputIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = scanner.nextInt();
        }

        return res;
    }

    // public static String[] <T> ToStringArray(T[] arr) {
    // String[] res = new String[arr.length];
    // for(int i = 0; i < arr.length; ++i) {
    // res[i] = String.valueOf(arr[i]);
    // }

    // return res;
    // }

    private static List<Integer> asIntergerList(int[] arr) {
        List<Integer> intList = new ArrayList<Integer>();
        for (int i = 0; i < arr.length; i++) {
            intList.add(arr[i]);
        }

        return intList;
    }

    private static int[][] deepCopy(int[][] arr) {
        int[][] res = new int[arr.length][];
        for (int i = 0; i < arr.length; ++i) {
            res[i] = arr[i].clone();
        }

        return res;
    }

    private static String asString(int[][] arr) {
        String str = new String();

        for (int i = 0; i < 2; ++i) {
            str += "" + arr[i][0] + arr[i][1] + arr[i][2] + arr[i][3];
        }

        return str;
    }

    private static int dfs(int y, int x, int[][] arr) {
        int[] dy = { -1, 1, 0, 0, 1, 1, -1, -1 };
        int[] dx = { 0, 0, 1, -1, 1, -1, 1, -1 };

        if (arr[y][x] == 0) {
            return 0;
        }

        arr[y][x] = 0;
        for (int i = 0; i < 8; ++i) {
            int py = y + dy[i], px = x + dx[i];

            if (py < 0 || py >= arr.length || px < 0 || px >= arr[0].length) {
                continue;
            }

            if (arr[py][px] == 1) {
                dfs(py, px, arr);
            }
        }
        return 1;
    }

    public static void main(String[] args) {
        scanner = new Scanner(System.in);

        while (true) {
            int w = scanner.nextInt();
            int h = scanner.nextInt();

            if (w == 0 && h == 0) {
                return;
            }
            int[][] arr = new int[h][w];

            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    arr[i][j] = scanner.nextInt();
                }
            }

            int counter = 0;

            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    counter += dfs(i, j, arr);
                }
            }
            System.out.println(counter);
        }

    }

}



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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll x;
    cin >> x;
    for(ll i=-1000;i<1001;i++){
        for(ll j=-1000;j<1001;j++){
            if(i*i*i*i*i-j*j*j*j*j==x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}











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

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    A -= K;
    if (A < 0)
    {
        B += A;
    }

    cout << max(ll(0), A) << " " << max(ll(0), B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, a, b, res = 0;
    stack<int> q;
    cin>>n;
    rep(i, n - 1){
        cin>>a;
        q.push(a);
    }
    a = INF;
    while(!q.empty()){
        b = q.top(); q.pop();
        res += min(a, b);
        a = b;
    }
    res += a;
    cout<<res<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# import math

# スペース区切りの整数の入力
l,r = map(int, input().split())

tmp_ans = 0
ans = -1

for i in range(r-l):
    for j in range(r-l):
        tmp_ans = ((l+i) * (l+j+1)) % 2019
        # print("({} = ({}+{}) * ({}+{}+1)) % 2019".format(tmp_ans,l,i,l,j))
        if tmp_ans == 0:
            ans = 0
            break
        if tmp_ans < ans:
            ans = tmp_ans
        elif ans == -1:
            ans = tmp_ans
    if ans == 0:
        break

# 出力
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] p = new int[n];
    int ans = 0;

    for(int i=0; i<n; ++i)
      p[i] = sc.nextInt();

    for(int i=2; i<n; ++i) {
      if( p[i-1] < p[i-2] & p[i-1] < p[i]
         || p[i-1] > p[i-2] & p[i-1] > p[i]) {
        continue;
      }
      ++ans;
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>

using ll = long long;

using namespace std;
int gccd(int a, int b) {
	if (a < b) {
		int t = a;
		a = b;
		b = t;
	}

	while (b != 0) {
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}
int main()
{/*8日目*/
//少数も使いたい割り算はしない方がいい
// 数値の大きさ
//for文で0代入する場所はforの一文下
//オーバーフローする一手手前を分解して作る・ 割り算で減らしていく
//for文いつも間違える/ i<nなら最後はa[n-1]
	int k;cin >> k;
	int sum = 0;
	for (int i = 1;i <= k;i++) {
		for (int j = 1;j <= k;j++) {
			for (int h = 1;h <= k;h++) {
				sum += gccd(i,gccd(j,h));
			}
		}
	}cout << sum;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>#De
#define DIM 3007
#define INF 1000000000000000007LL
using namespace std;

long long n,a[DIM],d[DIM][DIM];

long long F(int l,int r)
{
    if(d[l][r]!=INF) return d[l][r];
    if(l==r) d[l][r] = a[l];
    else
    {
        d[l][r] = max(a[l]-F(l+1,r),a[r]-F(l,r-1));
    }
    return d[l][r];
}
int main()
{
    cin>>n;
    for(int i = 1; i <= n; ++i)
        cin>>a[i];
    for(int i = 1; i <= n; ++i)
        for(int j = i; j <= n; ++j)
        d[i][j] = INF;
    cout<<F(1,n);
    return 0;
}


Measured memory_bytes: 70272
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 1e5;
int n, k;
int X[MAXN+10];
int main(){
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++) scanf("%d", &X[i]);
	int ans = INT_MAX;
	for(int i = 0; i <= n - k; i++){
		if(X[i] <= 0 && X[i+k-1] <= 0) ans = min(ans, abs(X[i]));
		else if(X[i] >= 0 && X[i+k-1] >= 0) ans = min(ans, X[i+k-1]);
		else ans = min(ans,
			min(2*abs(X[i]) + abs(X[i+k-1]),
				2*abs(X[i+k-1]) + abs(X[i])));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640