akhauriyash/Code-Regression huggingface dataset:
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main()
{
	string C1 = "";
	string C2 = "";
	string ret = "YES";

	cin >> C1 >> C2;
	ll len = C1.length();

	Rep( i, len) {
		if ( C1[i] != C2[len - i - 1] ) {
			ret = "NO";
			break;
		}
	}

	cout << ret << endl;


	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  char a,b;
  cin>>a>>b;
  if(a=='H'&&b=='H')
  cout<<'H'<<endl;
  else if(a=='D'&&b=='D')
  cout<<'H'<<endl;
  else{
     cout<<'D'<<endl;
}
}

   
  
   
 


   
  
   
 

Measured memory_bytes: 256
from collections import defaultdict
MOD=10**9+7
def swaps(s):
    for i in xrange(1, len(s)):
        yield s[:i-1]+s[i]+s[i-1]+s[i+1:]

n=int(raw_input())
cur={'':1}
for i in xrange(1, n+1):
    new = defaultdict(int)
    for k, v in cur.iteritems():
        for c in 'ACGT':
            k_ = (k+c)[-5:]
            if 'AGC' in k_ or any('AGC' in s for s in swaps(k_)): continue
            new[k_] = (new[k_]+v)%MOD
    #print(new)
    cur = new

total=0
for v in cur.itervalues():
    total = (total+v)%MOD
print(total)


Measured memory_bytes: 3064
import java.util.Scanner;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D&lang=ja
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r[] = new int[n];

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

		int maxv = r[1] - r[0];
		int minv = r[0];

		for (int i = 1; i < n; i++) {
			maxv = Math.max(maxv, r[i] - minv);
			minv = Math.min(minv, r[i]);
		}

		System.out.println(maxv);

		sc.close();
	}

}



Measured memory_bytes: 100660
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val nums = inputs.head.split(" ").map(_.toInt)
  val a = nums(0)
  val b = nums(1)
  val c = nums(2)

  println(solve(a, b, c))

  private def solve(a: Int, b: Int, c: Int): String = {
    if (a <= c && c <= b) {
      "Yes"
    } else {
      "No"
    }
  }
}

Measured memory_bytes: 54792
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

vector<int> G[100010];

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    vector<int> par(n+1);
    vector<int> in(n+1, 0);
    REP(i,n-1+m) {
        int a, b;
        cin >> a >> b;
        in[b]++;
        G[a].push_back(b);
    }
    int root;
    REP(i,n+1) if (in[i] == 0) root = i;
    queue<int> q;
    q.push(root);
    while(!q.empty()){
        int u = q.front(); q.pop();
        for (auto &v: G[u]) {
            in[v]--;
            if (in[v] == 0) {
                par[v] = u;
                q.push(v);
            }
        }
    }
    for (int i = 1; i <= n; ++i) cout << par[i] << endl;
    return 0;
}

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

 int main() {
   int N, H, amax;
   cin >> N >> H;

   vector<int> a(N), b(N);
   rep(i, 0, N) cin >> a.at(i) >> b.at(i);

   sort(a.begin(), a.end());
   amax = a.at(N - 1);

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

   auto itr = lower_bound(b.begin(), b.end(), amax);
   int d = distance(b.begin(), itr);

   int ans = 0;
   for (int i = N - 1; i >= d; i--) {
     ans++;
     H -= b.at(i);
     if (H <= 0) break;
   }
   if (H > 0) ans += ceil(H * 1.0 / amax);

   cout << ans << endl;
 }


Measured memory_bytes: 1024
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long

int main(){
    ll n,k;
    ll ans=0;
    cin >> n >> k;
    if(k==0){
        ans=n*n;
        cout << ans << endl;
        return 0;
    }
    for(ll i=k;i<n;i++){
        ans+=n-i;
    }
    for(ll i=k+1;i<=n-k;i++){
        ll p=(n-i)%i;
        ans+=(n-i)/i*(i-k);
        if(p>=k) ans+=p-k+1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def solve():
    from sys import stdin
    f_i = stdin
    
    n = int(f_i.readline())
    A = list(map(int, f_i.readline().split()))
    A.append(1000000001)
    
    q = int(f_i.readline())
    
    from bisect import bisect_left
    ans = []
    for i in range(q):
        k = int(f_i.readline())
        if k == A[bisect_left(A, k)]:
            ans.append('1')
        else:
            ans.append('0')
    
    print('\n'.join(ans))

solve()


Measured memory_bytes: 16852
#include<stdio.h>

int main(void)
{
	int n;
	int d;
	int s;
	
	while (scanf("%d", &d) != EOF) {
		s = 0;
		
		for (n = 1; n < 600 / d; n++) {
			s += d * d * d * n * n;
		}
		
		printf("%d\n", s);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<pair<int,int>, ll> PP;
const int MAX=1e5+10;

template <typename T,typename E>
struct SegmentTree{
	using F = function<T(T,T)>;
	using G = function<T(T,E)>;
	using H = function<E(E,E)>;
	int n,height;
	F f;
	G g;
	H h;
	T ti;
	E ei;
	vector<T> dat;
	vector<E> laz;
	  SegmentTree(F f,G g,H h,T ti,E ei):
	    f(f),g(g),h(h),ti(ti),ei(ei){}
  
	void init(int n_){
		n=1;height=0;
		while(n<n_) n<<=1,height++;
		dat.assign(2*n,ti);
		laz.assign(2*n,ei);
	}
	void build(const vector<T> &v){
		int n_=v.size();
		init(n_);
		for(int i=0;i<n_;i++) dat[n+i]=v[i];
		for(int i=n-1;i;i--)dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
	}
	inline T reflect(int k){
		return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
	}
	inline void eval(int k){
		if(laz[k]==ei) return;
		laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
		laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
		dat[k]=reflect(k);
		laz[k]=ei;
	}
	inline void thrust(int k){
		for(int i=height;i;i--) eval(k>>i);
	}
	inline void recalc(int k){    
		while(k>>=1)dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
	}
	void update(int a,int b,E x){
		thrust(a+=n);
		thrust(b+=n-1);
		for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
			if(l&1) laz[l]=h(laz[l],x),l++;
			if(r&1) --r,laz[r]=h(laz[r],x);
		}
		recalc(a);
		recalc(b);
	}
	void set_val(int a,T x){
		thrust(a+=n);
		dat[a]=x;laz[a]=ei;
		recalc(a);
	}
	T query(int a,int b){
		thrust(a+=n);
		thrust(b+=n-1);
		T vl=ti,vr=ti;
		for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
			if(l&1) vl=f(vl,reflect(l++));
			if(r&1) vr=f(reflect(--r),vr);
		}
		return f(vl,vr);
	}
};

int N,M;
int L[MAX], R[MAX];
ll C[MAX];
void input(){
    cin>>N>>M;
    multiset<PP> st;
    rep(_,M){
        int l,r;
        ll c;
        cin>>l>>r>>c;
        l--;
        r--;
        PP pp=make_pair(make_pair(l,r),c);
        st.insert(pp);
    }
    int ind=0;
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        PP pp=*itr;
        P p=pp.first;
        L[ind]=p.first;
        R[ind]=p.second;
        C[ind]=pp.second;
        ind++;
    }
//    rep(i,M){
//        cout<<L[i]<<" "<<R[i]<<" "<<C[i]<<endl;
//    }
}  

void solve(){
    auto f=[](ll a, ll  b){return min(a,b);};
    ll INF=1e18;
    SegmentTree<ll,ll> seg(f,f,f,INF,INF);
    seg.init(N);
    seg.set_val(0,0);
    rep(i,M){
        ll tmp=seg.query(L[i], R[i]);
        tmp+=C[i];
        seg.update(L[i]+1, R[i]+1, tmp);
    }
    
    ll ans=seg.query(N-1, N);
    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;
}

void output(){
  
}

int main(){
    input();
    solve();
    output();
}

Measured memory_bytes: 8064
#include <iostream>
#include<vector>
using namespace std;
int main() {
	vector<char> a(3), b(3), c(3);
	for (int i = 0; i < 3; i++){
		cin >> a.at(i);
		cin >> b.at(i);
		cin >> c.at(i);
	}
	cout << a.at(0) << b.at(1) << c.at(2); 
}

Measured memory_bytes: 256
//Meet Arora 2016055

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*;
import java.awt.Point;

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}

public class Main {
	public static void main(String[] args) throws IOException {
		Reader.init(System.in);
		int n=Reader.nextInt();
		int[] a=new int[n];
		PriorityQueue<Integer> pq = new PriorityQueue<>(n);
		HashMap<Integer, Integer> hm = new HashMap<>();

		for (int i = 0; i < n; i++) {
			a[i] = Reader.nextInt();
			pq.add(a[i]);
			hm.put(a[i], i);
		}

		int count = 0;
		int inc = 0, max_inc = -1;
		int min = pq.remove();
		int min_index = hm.get(min);
		for (int i = 1; i < n; i++) {
			int next = pq.remove();
			int index = hm.get(next);
			if (min_index<index) {
				inc++;
				if (inc > max_inc)
					max_inc = inc;
			}
			else {
				inc = 0;
			}
			min = next;
			min_index = index;
		}

		if (max_inc==-1) {
			max_inc=0;
		}
		count = n-1-max_inc;
		System.out.println(count);
	}
}


Measured memory_bytes: 58740
import sys, math



if(__name__ == "__main__"):

    """
    26^2 = 676 -> 676+26 = 702: 2文字の最大値
    3文字の番号は26**3種類
    1文字のものが26 * 1, 2文字が26* (1+26), 3文字の最大値は26**3 + 27 * 26 = 26 * (27 + 26**2) = 36 * 703
    4文字の最大値は26 * 703 + 26**4 = 26 * (26**0 + 26**1 + 26**2 + 26**3) = 475254


    """

    N= int( input().strip() )

    Max_bef = 0
    Max = 1
    N_26 = N/26
    str_len = 1
    while(N_26 > Max):
        Max_bef = Max
        Max += 26**str_len
        str_len += 1
    Max_beforestr= Max_bef*26
    hash = N-Max_beforestr
    # hash = N
    namelist = ["z"]*str_len

    num = str_len-1
    num2alpha = lambda c: chr(c+64)
    """
    d = num2alpha(25)
    print( d )
    aa -> 1
    ab -> 2
    az -> 26

    aaa -> 1
    aaz -> 26
    aba -> 27
    """

    while( num >= 0):
        remainder = hash%26
        if(remainder==0):
            remainder = 26
        d = num2alpha(remainder).lower()
        namelist[num]= d
        hash = math.ceil(hash/26)

        num -= 1

    Str = ""
    for i in range(str_len):
        Str += namelist[i]
    print(Str)
    #print(N, str_len, hash, namelist)


Measured memory_bytes: 9132
"use strict"
function Main(input) {
  input = input.trim().split('\n');
  const N = input[0].trim().split(' ').map(Number)[0];
  const M = input[0].trim().split(' ').map(Number)[1];
  const AB = input.slice(-M);
  const T = Array(N).fill(0);

  for(let i=0; i<M; i++){
    let A = AB[i].trim().split(' ').map(Number)[0];
    let B = AB[i].trim().split(' ').map(Number)[1];
    T[A-1] = T[A-1] + 1;
    T[B-1] = T[B-1] + 1;
  }
  console.log(T.join('\n'));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 400;
int n, ma, mb, a, b, c;
int dp[N + 1][N + 1];

int main() {
    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = 0;
    cin >> n >> ma >> mb;
    int ans = 0x3f3f3f3f;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b >> c;
        for (int ka = N; ka >= 0; --ka) {
            for (int kb = N; kb >= 0; --kb) {
                if (ka >= a && kb >= b && dp[ka - a][kb - b] != 0x3f3f3f3f) {
                    dp[ka][kb] = min(dp[ka][kb], dp[ka - a][kb - b] + c);
                    int g = __gcd(ka, kb);
                    if (ka / g == ma && kb / g == mb) {
                        ans = min(ans, dp[ka][kb]);
                    }
                }
            }
        }
    }
    cout << (ans == 0x3f3f3f3f ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 4248
m, d = map(int, input().split(' '))
ans = 0

for i in range(1, m+1):
    for j in range(1, d+1):
        j = str(j).zfill(2)
        if int(j[0]) >= 2 and int(j[1]) >= 2:
            if int(j[0]) * int(j[1]) == i:
                ans += 1
            
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int A, B, a[100010], b[100010], i, amin, bmin, sum;
	int M, x[100010], y[100010], c[100010];

	scanf("%d%d%d", &A, &B, &M);

	for(i = 1; i <= A; i++) 
		scanf("%d", &a[i]);
	for(i = 1; i <= B; i++)
		scanf("%d", &b[i]);
	for(i = 1; i <= M; i++) {
		scanf("%d", &x[i]);
		scanf("%d", &y[i]);
		scanf("%d", &c[i]);
	}

	amin = a[1];
	bmin = b[1];

	for(i = 2; i <= A; i++)
		if (amin > a[i])
			amin = a[i];
	for(i = 2; i <= B; i++)
		if (bmin > b[i])
			bmin = b[i];
	sum = amin + bmin;

	for(i = 1; i <= M; i++) {
		if (sum > a[x[i]] + b[y[i]] - c[i])
			sum = a[x[i]] + b[y[i]] - c[i];
	}

	printf("%d", sum);
	
	return 0;
}

Measured memory_bytes: 2176
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define DEBUG
#undef DEBUG

int N, W;
int VS[101];
int WS[101];

void solve()
{
    // i???????????§??????????????????j?????\????????¨???????????§??????
    int dp[101][10001];

    // ???????????\???????????´??????????????????????????????0
    FOR(j, 0, W+1) {
        dp[0][j] = 0;
    }

    // DP
    // i????????????????????\????????????????????§??´?????????
    // ????????? j < WS[i] ????????\???????????????
    //   ??\???????????´??????dp[i-1][j] ????????§??????
    //   ??\????????´??????VS[i] + dp[i-1][j-WS[i]] ????????§??????

    FOR(i, 1, N+1) {
        FOR(j, 0, W+1) {
            if(j < WS[i]) {
                dp[i][j] = dp[i-1][j];
            }
            else {
                dp[i][j] = max(dp[i-1][j], VS[i] + dp[i-1][j-WS[i]]);
            }
        }
    }

#ifdef DEBUG
    FOR(i, 0, N+1) {
        FOR(j, 0, W+1) {
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }
#endif

    cout << dp[N][W] << "\n";
}

int main()
{
    cin >> N >> W;
    REP(i, N) {
        cin >> VS[i+1] >> WS[i+1];
    }

    solve();

    return 0;
}

Measured memory_bytes: 7044
c=console.log
l=require('fs').readFileSync(0,'utf8').split('\n')
n=l[0].split(' ').map(Number)
h=n[0]
w=n[1]
d='#'.repeat(w+2)
c(d)
for(i=1;i<=h;){c(`#${l[i++]}#`)}
c(d)

Measured memory_bytes: 7500
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
stack=[0]
ans=0
while stack:
    q=stack.pop()
    if q<=n:
        if len(set(str(q)))==3:
            ans+=1
        stack.append(q*10+3)
        stack.append(q*10+5)
        stack.append(q*10+7)
print(ans)

Measured memory_bytes: 66664
VAR
 I,X,Y,A:LONGINT;
BEGIN
 FOR I:=1 TO 3 DO BEGIN READ(A);IF A=5 THEN INC(X);IF A=7 THEN INC(Y);END;
 IF (X=2) AND (Y=1) THEN WRITELN('YES')
                    ELSE WRITELN('NO');
END.

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

using namespace std;

int main(){
	
    while(true){
        int a,b;
        cin>>a>>b;
        if(a==0&&b==0)break;
        if(a>=b){
            cout<<b<<' '<<a<<endl;
        }else{
            cout<<a<<' '<<b<<endl;
            
        }
    }

}


Measured memory_bytes: 3012
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.next());
    }

    int cnt1 = 0;
    int cnt2 = 0;
    int cnt4 = 0;

    for (int i = 0; i < n; i++) {
      if (a[i] % 4 == 0) {
        cnt4++;
      } else {
        if (a[i] % 2 == 0) {
          cnt2++;
        } else {
          cnt1++;
        }
      }
    }

    if (cnt2 == 0) {
      if (cnt4 + 1 >= cnt1) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    } else {
      if (cnt4 >= cnt1) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
    sc.close();
  }

}

Measured memory_bytes: 47912
#include <iostream>
#include <queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];

void bfs(int s){
    queue<int> q;
    q.push(s);
    for (int i=0; i<n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while( !q.empty() ){
        u = q.front(); q.pop();
        for (int v=0; v<n; v++){
            if (M[u][v] == 0) continue;
            if (d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i=0; i<n; i++){
        cout << i+1 << " " << ( (d[i]==INFTY) ? (-1) : d[i]) << endl;
    }
}

int main(){
    int u, k, v;

    cin >> n;
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            M[i][j] = 0;
        }
    }

    for (int i=0; i<n; i++){
        cin >> u >> k;
        u--;
        for (int j=0; j<k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);

    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}

long long qpow(long long a, long long b, int MOD) {
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

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

    int n, p;
    string s;
    cin >> n >> p >> s;
    if (p == 2 || p == 5) {
        vector<int> pre(p, 0);
        LL ans = 0;
        for (int i = 0; i < n; i++) {
            int num = s[i] - '0';
            vector<int> cur(p, 0);
            for (int j = 0; j < p; j++) {
                int jj = (j * 10 + num) % p;
                cur[jj] += pre[j];
            }
            cur[num % p]++;
            ans += cur[0];
            pre = cur;
            // cout << pre << endl;
        }
        cout << ans << '\n';
    } else {
        LL cur = 0;
        int lookup[10000] = {0};
        lookup[0]++;
        LL ans = 0;
        for (int i = n - 1, idx = 0; i >= 0; i--, idx++) {
            int num = s[i] - '0';
            cur = (qpow(10, idx, p) * num + cur) % p;
            ans += lookup[cur];
            lookup[cur]++;
        }
        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 720
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

a = [1]*(10**5+1)
a[0] = a[1] = a[2] = 0

for i in range(2, ceil(sqrt(10**5)+1)):
    for j in range(i*2, len(a), i):
        a[j] = 0
        if j*2 - 1 < len(a):
            a[j*2-1] = 0

q = INT()
p = [LIST() for i in range(q)]
s = list(accumulate(a))

for i in range(q):
    print(s[p[i][1]]-s[p[i][0]-1])

Measured memory_bytes: 96756
a,b,k=map(int,input().split())
ans = []
ans.append(a)

for i in range(min(k,b-a)):
    ans.append(a+i)
for j in range(min(k,b-a)):
    ans.append(b-j)
    ans.append(b)
for k in range(len(set(ans))):
    print(sorted(set(ans))[k])

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

using namespace std;

int main(){
  
  string s, t;
  int ans = 0;

  cin >> s >> t;

  for(int i = 0; i < 3; i++){
	if(s[i] == t[i]){
	  ans++;
	}
  }

  cout << ans << endl;
 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int n,k,min=1000000000;
	cin >> n >> k;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	
	sort(h.begin(),h.end());
	
	for(int j=0;j<n-k+1;j++){
		if(h[j+k-1]-h[j] < min){
			min = h[j+k-1] - h[j];
		}
	}
	
	cout << min <<endl;

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

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

int n;
ll k;
int a[SIZE];
int b[SIZE];
vector<int> v;

int main(){
  cin >> n >> k;
  rep(i,1,n+1) cin >> a[i];
  v.push_back(1);
  b[1] = 1;
  int t=1;
  for(;;){
    t = a[t];
    if(b[t] == 1)break;
    b[t]=1;
    v.push_back(t);
  }
  int m;
  rep(i,0,v.size()){
    if(v[i] == t)m=i;
  }
  if(k < (ll)m){
    cout << v[k] << endl;
  }else{
    cout << v[m + (k-(ll)m)%((ll)(v.size()-m))] << endl;
  }


  return 0;
}


Measured memory_bytes: 5816
import java.util.*;

public class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        boolean b = n % 2 == 0;
        if (b) {
            int next = 0;
            for (int i = 0; i < n; i++) {
                if (i < n / 2) {
                    ans[i] = array[n - 1 - i * 2];
                } else {
                    ans[i] = array[next];
                    next += 2;
                }
            }
        } else {
            int next = 1;
            for (int i = 0; i < n; i++) {
                if (i < n / 2) {
                    ans[i] = array[n - 1 - i * 2];
                } else if (i == n / 2 ){
                    ans[i] = array[0];
                } else {
                    ans[i] = array[next];
                    next += 2;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (i == n - 1) {
                System.out.println(ans[i]);
            } else {
                System.out.print(ans[i] + " ");
            }
        }
    }
}


Measured memory_bytes: 97224
//##MohK
//10/2/2020.... 10,00
#include <bits/stdc++.h>
using namespace std ;
using ll = long long ;
using ld = long double;
int main(){
    string s;
    cin>>s;
    ll x=s.size();
    for(ll i=0;i<s.size();i+=2){
        cout<<s[i];
    }
    
 return 0 ;
}




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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){

	int n;cin >> n;
	vector<ll> v(n);
	ll sum = 0;
	REP(i,n){
		cin >> v[i];
		sum += v[i];
	}

	ll mi = LLINF;
	ll ret;

	REP(i,n){
		if(mi > abs(sum - v[i]*n)){
			mi = abs(sum - v[i]*n);
			ret = i;
		}
	}

	cout << ret << endl;

	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a;
    cin >> n >> a;
    if(a>=n%500) cout << "Yes" << "\n";
    else cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 3556
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
A1 -= B1
A2 -= B2
if A1 < 0:
    A1 *= -1
    A2 *= -1

if A1*T1 > -A2*T2:
    print(0)
elif A1*T1 == -A2*T2:
    print("infinity")
else:
    dx = -A2*T2 -A1*T1
    ans = (A1*T1)//dx *2 +1
    if (A1*T1)%dx == 0:
        ans -= 1
    print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
int N,i,J;
char S[100];
J=0;
scanf("%d", &N);
if(N%2==0){
	for(i=0;i<=N;i++)
		scanf("%s",S);
	for(i=0;i<=N/2;i++){
		if(S[i]==S[i+N/2])
			J++;
	}
  	if(J==N/2){
		puts("Yes");
		return 0;
    }
}
puts("No");
}

Measured memory_bytes: 128
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while q:
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)


Measured memory_bytes: 66112
A, B, K = map(int, input().split())
answer = set([])
for i in range(A, min(A+K, B+1)):
    answer.add(i)
    # print(i)
for i in range(max(A, B-K+1), B+1):
    answer.add(i)
    # print(i)
# print(answer)
ordered_answer = sorted(answer)
# print(ordered_answer)
for i in ordered_answer:
    print(i)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(x+r <= W && y+r <= H && x-r >= 0 && y-r >= 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>                                                
#include <vector>  
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#define endl "\n"

using ll = long long;
using namespace std;

int main() {
    string S;
    cin >> S;
    if (S.back() == 's') {
        cout << S + "es" << endl;
    }
    else {
        cout << S + 's' << endl;
    }
        
    
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int prim(void);

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int A[MAX][MAX];
int n;

int main(){
  int i,j,e;
  int u;
  cin >> n;
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      cin >> e;
      A[i][j] = (e == -1) ? INFINITY : e;
    }
  }
  cout << prim() << endl;
  return 0;
}

int prim(){
  int sum = 0;
  int i,j,minV;
  int d[MAX],p[MAX],color[MAX];
  int u,v; 
  for(i = 0; i < n; i++){
    d[i] = INFINITY;
    p[i] = -1;
    color[i] = WHITE;
  }
  d[0] = 0;
  while(1){
    minV = INFINITY;
    u = -1;
    for(i = 0; i < n; i++){
      if(minV > d[i] && color[i] != BLACK){
        u = i;
        minV = d[i];
      }
    }
    if(u == -1){
      break;
    }
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if(color[v] != BLACK && A[u][v] != INFINITY){
        if(d[v] > A[u][v]){
          d[v] = A[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
  //sum = 0;
  for(i = 0; i < n; i++){
    if(p[i] != -1){
      sum += A[i][p[i]];
    }
  }
  return sum;
}

Measured memory_bytes: 3088
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

c = str(input())
mother = list("aiueo")

if c in mother:
    print("vowel")
else:
    print("consonant")


Measured memory_bytes: 6732
#include <stdio.h>
char s[5];
int is;
int main(void) {
    scanf("%s", s);
    if (s[0] == s[1]) {
        if (s[0] == s[2]) {
            is = 1;
        }
    } else {
        if (s[1] == s[2]) {
            if (s[1] == s[3]) {
                is = 1;
            }
        }
    }
    puts(is ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	long long x;
	cin>>x;
	
	double one_percent = 0;
	long long deposit = 100;
	int years = 0;
	
	while(deposit < x){
		years++;
		one_percent = 	(long long)deposit*0.01;
		deposit += one_percent;
	}
	
	cout<<years<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int n,mx,mn,p;
	
	mx=1;
	mn=1000000000;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&p);
		if (p>mx) mx=p;
		if (p<mn) mn=p;
	}
	p=mx-mn;
	printf("%d",p);
	
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  
  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(N-1-i)){
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < (N-1)/2; i++) {
    if (S.at(i) != S.at((N-1)/2 -1-i)){
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = (N+3)/2; i < N; i++) {
    if (S.at(i) != S.at(N-1-i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}



Measured memory_bytes: 3540
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 100000000000000000
#define ninf -100000000000000000
#define label -1000000000000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
const ll N = 2e5+5;
ll n;
ll a[N], dp[N][5];
ll compute(ll i, ll ex)
{
    if( i >= n) 
    {
        if(ex == 2) return ninf;
        return 0;
    }
    if(dp[i][ex] != label) return dp[i][ex];
    ll ans = ninf;
    // take
    ans = MAX2(ans, a[i] + compute(i+2, ex));
    // leave
    if(ex > 0)
        ans = MAX2(ans, compute(i+1, ex-1));
    return dp[i][ex] = ans;
}
int main()
{
    she_told_me_dont_worry
    cin>>n;
    ll i;
    FOR0(i, n) cin>>a[i];
    ll j;
    FOR0(i, n+3) FOR0(j, 4) dp[i][j] = label;
    ll dif = 1;
    if(n%2) dif = 2;
    ll ans = 0;
    ans = compute(0, dif);
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 17852
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        int x,t=1;
        Scanner sc = new Scanner(System.in);
        while(true){
            x=sc.nextInt();
            if(x == 0) break;
            System.out.println("Case "+ t++ +": "+x);
        }
    }
}



Measured memory_bytes: 41216
#include<iostream>
#include<math.h>
#include<cstring>
#include<vector>
#include<map>

typedef long long ll;
//sort(rt,rt+sizeof(rt)/sizeof(rt[0]),greater<>());
using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
int main(){
    char n[1001];
    cin>>n;
    int a;
    a=(int)strlen(n);
    if(n[a-1]=='s'){
        cout<<n<<"es";
        return 0;
    }else if(n[a-1]!='s'){
        cout<<n<<'s';
        return 0;
    }
}


Measured memory_bytes: 3592
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;


public class AtCoder
{
    static string w;
    static void Main() {
        w = Console.ReadLine();
        for(int i = 0; i < 26; i++) {
            if (w.Length == 0) {
                break;
            }
            string ss = w.Replace(w[0].ToString(), "");
            if ((w.Length - ss.Length) % 2 != 0) {
                Console.WriteLine("No");
                return;
            }
            w = ss;
        }
        Console.WriteLine("Yes");
            
           
    }
}



Measured memory_bytes: 2648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std; 

string list = "0123456789";

int MCXItoINT(string s)
{
	int l=s.length(), n=0, b=1;
	string t;

	for(int i=0; i<l; i++){
		t = s.substr(i,1);
		if(t=="m"){n += (b*1000); b=1;}
		else if(t=="c"){n += (b*100); b=1;}
		else if(t=="x"){n += (b*10); b=1;}
		else if(t=="i"){n += b; b=1;}
		else{b=atoi(t.c_str());}
	}

	return n;
}

void INTtoMCXI(int z)
{
	string s="";
	int m,c,x,i;

	m=z/1000;
	c=(z%1000)/100;
	x=(z%100)/10;
	i= z%10;

	if(m==1){s = s+"m";}
	else if(m!=0){s = s + list.substr(m,1)+"m";}

	if(c==1){s = s+"c";}
	else if(c!=0){s = s + list.substr(c,1)+"c";}

	if(x==1){s = s+"x";}
	else if(x!=0){s = s + list.substr(x,1)+"x";}

	if(i==1){s = s+"i";}
	else if(i!=0){s = s + list.substr(i,1)+"i";}

	cout << s << endl;

}

int main()
{
	int n;
	string a, b;

	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a >> b;
		INTtoMCXI( MCXItoINT(a) + MCXItoINT(b) );
	}

	return 0;
}

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

int main() {
	int  ans=0,i,min;
	bool mi=false;
	vector<int> a(5),b(5);
	cin >> a[0] >> a[1] >>a[2]  >>a[3]>> a[4];
	min = a[0];
	for (i = 0; i < a.size(); i++) {
		if (a[i] % 10 < min%10&&a[i] % 10 != 0) {
			min = a[i];
		}
	}
	for (i = 0; i<a.size(); i++) {
		if (a[i] != min||mi) {
			ans += a[i];
			if (ans % 10 != 0 ) {
				ans = (ans / 10 + 1) * 10;

			}
		}
		else {
			mi = true;
		}
	}
	ans += min;
	cout << ans << endl;
}

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

int main(){
    int  n,t;

    cin >>n>>t;
    vector<int> C(n);
    vector<int> T(n);

    for (int i = 0; i < n;i++){
        cin >> C[i] >> T[i];
    }
    int min = 999999;

    for(int i = 0; i < n; i++){
        if(T[i]<=t){
            if(C[i]<=min){
                min = C[i];
            }
        }
    }
    if(min == 999999){
        cout << "TLE" <<endl;

    }else{
    cout << min <<endl;

    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;cin>>n>>k;vector<int> vec(n+1);vec[0]=0;
	for(int i=1;i<=n;i++) cin>>vec[i],vec[i]=vec[i]+vec[i-1];
	int pos=upper_bound(vec.begin(),vec.end(),k)-vec.begin(); 
	cout<<pos<<endl;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  vector<int> H(200000);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  vector<int> dp(200000,1000000000);
  dp.at(0)=0;
  for(int i=0;i<N;i++){
    for(int j=1;j<K+1;j++){
      dp.at(i+j)=min(dp.at(i+j),dp.at(i)+abs(H.at(i+j)-H.at(i)));
    }
  }
  cout << dp.at(N-1) << endl;
} 

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

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef long long ll;
typedef pair<int, int> pll;
typedef vector<int> vll;
typedef vector<pll> vpll;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

int h[N];
int dp[N];
int n;

int32_t main() {
  FAST_IO;
  cin >> n;
  rep1(i, n)
    cin >> h[i];
  h[0] = INF;
  loop(i, 2, n + 1) {
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n] << '\n';
  rtn 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
   string s;
   cin >> s;
   string ans;
   if(s == "Sunny") ans = "Cloudy";
   else if(s == "Cloudy") ans = "Rainy";
   else ans = "Sunny";
   cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3424
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string s;
  cin >> s;
  ll k;
  cin >> k;
  int n=s.size();
  vector<char> v;
  for(int i=0;i<n;i++){
    if(s[i]!='a' && ('z'-s[i])+1<=k){
      k-='z'-s[i]+1;
      v.push_back('a');
    }else{
      v.push_back(s[i]);
    }
  }
  ll x=k%(26LL);
  rep(i,x){
    if(v[n-1]=='z'){
      v[n-1]='a';
    }else v[n-1]++;
  }
  rep(i,n)cout << v[i];
  cout << endl;
return 0;}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef pair<int,ii> iii;
const int N = 2e5+1,L = 19;
int f[L][N],a[N],pos[N];
priority_queue<iii,vector<iii>,greater<iii>>pq;
int find(int l,int r)
{
	int sz = log2((r-l)/2+1);
	return min(f[sz][l],f[sz][r-((1<<sz)-1)*2]);
}
void add(int l,int r)
{
	if(l<=r)
	{
		int mn = find(l,r-1);
		pq.push(iii(mn,ii(l,r)));
	}
}
int main()
{
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)	
	{
		scanf("%d",&a[i]);
		pos[a[i]] = i;
	}
	for(i=0;i<n;i++)	f[0][i]=a[i];
	for(i=1;i<L;i++)
	{
		for(j=0;j<n;j++)
		{
			f[i][j] = f[i-1][j];
			if(j+(1<<i)<n)	f[i][j]=min(f[i][j],f[i-1][j+(1<<i)]);
		}
	}
	add(0,n-1);
	for(i=0;i<n;i+=2)
	{
		iii p = pq.top();pq.pop();
		int l=p.second.first;
		int r=p.second.second;
		int min1 = find(l,r-1);
		int p1=pos[min1];
		int min2 = find(p1+1,r);
		int p2=pos[min2];
		printf("%d %d ",min1,min2);
		add(l,p1-1);add(p1+1,p2-1);add(p2+1,r);
	}
}


Measured memory_bytes: 20900
#include "bits/stdc++.h"
using namespace std;
int main(){
  string s,t;
  char c;
  int n,i;
  cin >> s >> t;
  n = s.size();
  for(i=0;i<n;i++){
    c=s.at(0);
    s.erase(s.begin(),s.begin()+1);
    s += c;
    if(s==t){
      cout << "Yes"<<endl;
      return 0;
    }
  }
  cout << "No"<<endl;
  return 0;
}

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

int S[1000];
int top;

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main()
{
  int a, b;
  top = 0;
  char s[100];

  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }
    else{
      push(atoi(s));
    }
  }

  printf("%d\n", pop());

  return 0;
}



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

vector<int> G[200001];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int i: G[1]) {
        for (int j: G[i]) {
            if (j == n) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 12016
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <tuple>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#include <cmath>

using namespace std;
using lint = long long int;


int main() {
	string predict, actual;
	cin >> predict >> actual;

	int count = 0;
	for (int i = 0; i < predict.length(); i++)
		if (predict[i] == actual[i])
			count++;
	cout << count;

	return 0;
}




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


int main()
{
  int N;
  string str;
  str = "Three";
  cin >> N;
  char S[N];
  for(int i = 0 ; i < N ; i++){
  cin >> S[i];
  if(S[i] == 'Y'){
      str = "Four";
      break;
    }
  }
    cout << str;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,g;
    g = 0;
    scanf("%d %d",&a,&b);
    while(a != 0 && b != 0){
        for(int c = 0; a-1 >= c; c ++){
            for(int d = 0; b-1 >= d ; d++){
                if(c==0 || c+1==a || d == 0 || d+1==b){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d",&a,&b);
    }
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define emp emplace
#define fi first
#define se second
#define INF 0x3f3f3f3f
typedef long long ll;
typedef pair<int, int> ii;

int g[3][3];

int main(void) {
	ios_base::sync_with_stdio(false);

	int ans =0;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> g[i][j];
			ans += g[i][j];
		}
	}

	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			for (int k = 0; k <= 100; k++) {
				int b1 = g[0][0]-i, b2 = g[0][1]-i, b3 = g[0][2]-i;
				int cand = 1;

				if (g[1][0] != j+b1 or g[1][1] != j+b2 or g[1][2] != j+b3) {
					cand = 0;
				}
				if (g[2][0] != k+b1 or g[2][1] != k+b2 or g[2][2] != k+b3) {
					cand = 0;
				}

				if (cand) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long

ll MIN(ll num1,ll num2){
    return num1<num2?num1:num2;
}

int main(){

    int H,W,cnt=0;
    cin>>H>>W;
    for(int i=0;i<H;i++){
        string S;
        cin>>S;
        for(int i=0;i<W;i++){
            if(S[i]=='#')cnt++;
        }
    }
    if(cnt==H+W-1)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;

    return 0;
}

Measured memory_bytes: 256