akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll solve(int cost[],int n,int k)
{
	ll dp[n];
	for(int i=0 ; i<n ; i++)
		dp[i]=INT_MAX;
	dp[0]=0;
	for(int i=0 ; i<n ; i++)
	{
		for(int j=1 ; j<=k ; j++)
		if(i+j<n)
			dp[i+j]=min(dp[i+j],dp[i]+abs(cost[i+j]-cost[i]));
	}
	return dp[n-1];
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	int cost[n];
	for(int i=0 ; i<n ; i++)
		cin>>cost[i];
	long long int ans=solve(cost,n,k);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[100010];
    rep(i,0,N) cin >> A[i];
    ll ans = 0;
    multiset<ll> mt;
    rep(i,0,N){
        auto iter = mt.lower_bound(A[i]);
        if(iter == mt.begin()){
            ans++;
            mt.insert(A[i]);
        }else{
            iter--;
            mt.erase(iter);
            mt.insert(A[i]);
        }
    }
    print(ans);
}

Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		long N=sc.nextLong();
		long[] t=new long[5];
		int soe=0;
		long min=Long.MAX_VALUE;
		for(int i=0; i<5; i++) {
			t[i]=sc.nextLong();
			if(min>t[i]) {
				soe=i;
			}
			min=Math.min(min, t[i]);
		}
		pl((N+min-1)/min+4);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 21972
#include<stdio.h>

int main()
{
	int a=1,b=2,c;
	
	while(true)
	{
	    scanf("%d %d", &a, &b);
	    if(a == 0 && b == 0)
	    {
	    	break;
		}
	    if(a>b)
		{
			c = b;
			b = a;
			a = c;
		}
		printf("%d %d\n" , a , b);
	}
	
	
	return 0;
}


Measured memory_bytes: 2728
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class RangeSpannedGraph(object):
    def __init__(self, n):
        self.n = n
        self.N = N = 1 << (n - 1).bit_length()
        N2, N3 = N * 2, N * 3
        ref = self._reflect
        E = [[] for _ in range(N3)]
        for i in range(N - 1, 0, -1):
            cl, cr = i << 1, i << 1 | 1
            E[i].append((cl, 0))
            E[i].append((cr, 0))
            E[ref(cl + N2)].append((ref(i + N2), 0))
            E[ref(cr + N2)].append((ref(i + N2), 0))
        self.E = E

    def _reflect(self, v):
        return v if v < 3 * self.N else v - 2 * self.N

    def add_range_edge(self, l0, r0, l1, r1, w):
        N, E = self.N, self.E
        E.append([])
        v = len(E) - 1
        self._add_range_edge(l0 + N, r0 + N, v, w, to = True)
        self._add_range_edge(l1 + N, r1 + N, v, 0, to = False)

    def _add_range_edge(self, l, r, v, w, to):
        E, ref, N2 = self.E, self._reflect, self.N * 2
        while l < r:
            if l & 1:
                E[ref(l + N2)].append((v, w)) if to else E[v].append((l, 0))
                l += 1
            if r & 1:
                r -= 1
                E[ref(r + N2)].append((v, w)) if to else E[v].append((r, 0))
            l >>= 1
            r >>= 1

    def to_index(self, v):
        return v + self.N

from heapq import heappop, heappush
def resolve():
    n, m = map(int, input().split())
    rsg = RangeSpannedGraph(n)
    for _ in range(m):
        u, v, w = map(int, input().split())
        u -= 1
        rsg.add_range_edge(u, v, u, v, w)

    # Dijkstra
    E = rsg.E
    dist = [INF] * len(E)
    dist[rsg.to_index(0)] = 0
    heap = [(0, rsg.to_index(0))]
    while heap:
        d, v = heappop(heap)
        if dist[v] != d:
            continue
        for nv, w in E[v]:
            if dist[nv] > d + w:
                dist[nv] = d + w
                heappush(heap, (d + w, nv))

    ans = dist[rsg.to_index(n - 1)]
    if ans == INF:
        ans = -1
    print(ans)
resolve()

Measured memory_bytes: 261828
x,y,a,b,c=map(int,input().split())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
r=[int(i) for i in input().split()]
p.append(-1)
q.append(-1)
r.append(-1)
ps=sorted(p)
qs=sorted(q)
rs=sorted(r)
d=0
e=0
f=0
ans=0
def me1():
    global ans
    
    if max(ps[-1],qs[-1],rs[-1])==ps[-1]:
        ans+=ps[-1]
        ps.pop(-1)
        global d
        d+=1
    elif max(ps[-1],qs[-1],rs[-1])==qs[-1]:
        ans+=qs[-1]
        qs.pop(-1)
        global e
        e+=1
    else:
        ans+=rs[-1]
        rs.pop(-1)
        global f
        f+=1
def me2():
    global ans
    if max(ps[-1],rs[-1])==ps[-1]:
        ans+=ps[-1]
        ps.pop(-1)
        global d
        d+=1
    else:
        ans+=rs[-1]
        rs.pop(-1)
        global f
        f+=1
def me3():
    global ans
    if max(qs[-1],rs[-1])==qs[-1]:
        ans+=qs[-1]
        qs.pop(-1)
        global e
        e+=1
    else:
        ans+=rs[-1]
        rs.pop(-1)
        global f
        f+=1
for i in range(x+y):
    #print(ans)
    #print(i)
    
    if d>=x:
        #print('x')
        me3()
    elif e>=y:
        #print('y')
        me2()
    else:
        #print('z')
        me1()
print(ans)
    

Measured memory_bytes: 107116
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int a[] = new int[3];
		for(int n=0;n<3;n++){
			a[n] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println((a[1]-a[0])+(a[2]-a[1]));

	}
}

Measured memory_bytes: 24020
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
//---------------------------------------------
 
int main(void)
{


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

ll modn = n%k;

ll abb = modn-k;

cout<<min(modn,abs(abb))<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mes(a, b)  memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e5 + 20;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;
int has[maxn];
int main(){
	int n;
	cin >> n;
	for(int i = 1;i < n;i++){
		int v;cin >> v;
		has[v]++;
	}
	for(int i = 1;i <= n;i++) printf("%d\n",has[i]);
}

Measured memory_bytes: 4424
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

    String nyuA=sc.nextLine();
 
      String[] t=sc.nextLine().split(" ");
 int[] numt=new int[t.length];
for(int i=0;i<t.length;i++){
numt[i]=Integer.parseInt(t[i]);
}
   String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

int N=Integer.parseInt(nyuA);
int M=Integer.parseInt(nyuB);
int[][] num=new int[M][2];
for(int i=0;i<M;i++){
String[] temp=sc.nextLine().split(" ");
num[i][0]=Integer.parseInt(temp[0]);
num[i][1]=Integer.parseInt(temp[1]);
}

//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);

//boolean[][] data=new boolean[H][W];

int data[]=new int[M];

int result=0;
for(int i=0;i<M;i++){
result=0;
for(int j=0;j<N;j++){
if(j+1==num[i][0])result+=num[i][1];
else result+=numt[j];
}

System.out.println(result);
}

//System.out.println();

	}
}

Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> v;
  v.resize(N,0);
  for(int i=0;i<N-1;i++){
    int c,s,f;
    cin >> c >> s >> f;
    v[i] = s+c;
    for(int j=0;j<i;j++){
      if(v[j]<=s){
        v[j] = s+c;
      }else{
        if((v[j]-s)%f!=0){
        	v[j] = s+((v[j]-s)/f+1)*f+c;
        }else{
          	v[j] += c;
        }
      }
    }
  }
  for(int i=0;i<N;i++){
    cout << v[i] << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
S = input()
count = 0

RGBlist = [[S.count('R')],[S.count('G')],[S.count('B')]]


for i in range(1,N):
    RGBlist[0].append(RGBlist[0][-1] - (S[i-1] == 'R'))
    RGBlist[1].append(RGBlist[1][-1] - (S[i-1] == 'G'))
    RGBlist[2].append(RGBlist[2][-1] - (S[i-1] == 'B'))

for i in range(N-2):
    si = S[i]
    
    for j in range(i+1,N-1):
        sj = S[j]
        if si==sj:
            continue
        else:
            RGB = set(['R','G','B'])
            RGB -= set([si,sj])
            k=j+1
            kji=j-i
            if RGB == {'R'}:
                rgb = 0
            elif RGB =={'G'}:
                rgb = 1
            else:
                rgb = 2
            if k+kji-1 < len(S):
                count += RGBlist[rgb][k] - ({S[k+kji-1]} == RGB)
            else:
                count += RGBlist[rgb][k]
            
print(count)


Measured memory_bytes: 75236
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}




int dis[10][10];





int main()
{

	int n;
	cin >> n;

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

	sort(a.begin(), a.end(), greater<int>());

	vector<int> hen;

	for (int i = 0; i < a.size() - 1; i++) {
		if (a[i] == a[i + 1]) {
			hen.push_back(a[i]);
			i++;
		}

		if (hen.size() == 2)break;

	}



	long long int ans;
	ans = (long long int)hen[0] * (long long int)hen[1];
	if (hen.size() == 2) {
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;

}



Measured memory_bytes: 640
N,H=map(int,input().split())
L=[list(map(int,input().split()))for _ in[0]*N]
A=max(a[0]for a in L)
B=sorted(b for _,b in L if b>A)
c=0
while B and H>0:
    H-=B.pop()
    c+=1
print(c-(-max(0,H)//A))

Measured memory_bytes: 28456
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int q,m,r;};
struct Node T[MAX];
int n;

void pre(int u){
  if( u == NIL) return;
  printf(" %d", u);
  pre(T[u].m);
  pre(T[u].r);
}

void in(int u){
  if(u == NIL) return;
  in(T[u].m);
  printf(" %d", u);
  in(T[u].r);
}

void post(int u){
  if(u == NIL) return;
  post(T[u].m);
  post(T[u].r);
  printf(" %d", u);
}

int main(){
  int i,v,m,r,root;

  scanf("%d",&n);
  for( i = 0; i < n; i++){
    T[i].q = NIL;
  }

  for( i = 0; i <n; i++){
    scanf("%d %d %d",&v, &m , &r);
    T[v].m = m;
    T[v].r = r;
    if(m != NIL) T[m].q = v;
    if(r != NIL) T[r].q = v;
  }

  for( i = 0; i < n ; i++) if( T[i].q == NIL) root = i;

  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}



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

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

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    double a, b, x;
    cin >> a >> b >> x;

    double ans = 0.0;
    if(x <= a*a*b/2){
        ans = atan(a*b*b/(2*x));
    }else{
        ans = atan(2*(a*a*b - x)/(a*a*a));
    }

    cout << fixed << setprecision(10) << ans * 360 / (2 * M_PI) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
using namespace std;
int n;
int LG[600];
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	int it=1;
	for(int i=1;i<=512;i*=2){
		LG[i]=it;
		it++;
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			cout<<LG[lowbit((i^j))]<<' ';
		}
		cout<<endl;
	} 
	return 0;
}


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

void _157() {
    string s;
    cin >> s;

    if ((s == "AAA") || (s == "BBB"))
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}

void _156() {
    int n, r;
    cin >> n >> r;

    if (n >= 10)
        cout << r << endl;
    else
        cout << r + 100 * (10 - n) << endl;
}

void _155() {
    int a, b, c;
    cin >> a >> b >> c;

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

void _154() {
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if (s ==u)
        cout << a - 1 << " " << b << endl;
    else
        cout << a << " " << b - 1 << endl;
}

void _153() {
    int h, a;
    cin >> h >> a;

    // int times = h / a;
    // if (times % a == 0)
    //     cout << times << endl;
    // else
    //     cout << times + 1 << endl;
    cout << (h + a - 1) / a << endl;
}

void _152() {
    int n, m;
    cin >> n >> m;

    if (m == n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void _151() {
    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
}

void _150() {
    int k;
    long long x;
    cin >> k >> x;
    if (500 * k >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main()
{
    _150();
    
    return 0;
}



Measured memory_bytes: 256
package main

import (
        "fmt"
)

func solution(a, b, c, x, y int) int {
        out := max(x, y) * c * 2

        out = min(out, a*x+b*y)

        tmp := c * 2 * min(x, y)
        t := min(x, y)
        x -= t
        y -= t

        tmp += a*x + b*y

        return min(out, tmp)
}

func min(x, y int) int {
        if x < y {
                return x
        }
        return y
}
func max(x, y int) int {
        if x > y {
                return x
        }
        return y
}

func main() {
        var a, b, c, x, y int
        fmt.Scan(&a, &b, &c, &x, &y)
        fmt.Println(solution(a, b, c, x, y))
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
void pairsort(vector<int>&arr,vector<int>&answer,int n)
{
	pair<int,int>p[n];
	for(int i=0; i<n; i++)
	{
		p[i].first=arr[i];
		p[i].second=answer[i];
	}
	sort(p,p+n);
	for(int i=0; i<n; i++)
	{
		arr[i] = p[i].first;
		answer[i] = p[i].second;
	}
}
int main()
{
	int n;
	cin >> n;
	vector<int>arr(n),answer(n);

	for(int i=0; i<n; i++)
	{
		cin >> arr[i];
		answer[i] = i;
	}
	pairsort(arr,answer,n);

	for(int i=0; i<n; i++)
		cout << answer[i]+1 << " ";
 	return 0; 	
}

Measured memory_bytes: 2432
MOD = 10**9 +7
INF = 10**9

def main():
    n = int(input())
    R = [tuple(map(int,input().split())) for _ in range(n)]
    B = [tuple(map(int,input().split())) for _ in range(n)]
    
    B.sort(key = lambda x:x[0])
    R.sort(key = lambda x:x[1],reverse=True)
    done = [1] * n
    
    cnt = 0
    for i in range(n):
        bx,by = B[i]
        for j in range(n):
            if done[j] and R[j][0] < bx and R[j][1] < by:
                cnt += 1
                done[j] = 0
                break
    
    print(cnt)
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
def debug(k,v) puts "#{k}: #{v}" end
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
a,b,c = gsmi
k = gi

k.times do
  if (a>=b)
    b*=2
  elsif b>=c
    c*=2
  end
end

puts (a<b&&b<c) ? 'Yes' : 'No'


Measured memory_bytes: 14396
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
ll MOD = 1000000007;

template <typename T>
class BIT {
private:
  vector<T> bit;
  int neutral = 0;
  // 更新クエリ, 区間クエリ
  function<T(T,T)> f = [](const T l, const T r) -> T { return max(l, r); },
                   g = [](const T l, const T r) -> T { return max(l, r); };
public:
  BIT(int n_ = 1e5) { init(n_); }
  void init(int n_ = 1e5) { bit.assign(n_+1, neutral); }
  void update(int i, T w) {
    for(int x = i+1; x < bit.size(); x += x&-x) bit[x] = f(bit[x], w);
  }
  // [0,i]
  T query(int i) {
    T ret = neutral;
    for(int x = i+1; x > 0; x -= x & -x) ret = g(ret, bit[x]);
    return ret;
  }
};

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

  while(1) {
    ll n;
    cin >> n;
    if(!n) break;
    vector<PII> v(n);
    REP(i, n) cin >> v[i].first >> v[i].second;
    ll m;
    cin >> m;
    REP(i, m) {
      ll h, r;
      cin >> h >> r;
      v.push_back({h, r});
    }

    sort(ALL(v), [](PII l, PII r){
      if(l.first != r.first) return l.first < r.first;
      return l.second > r.second;
    });

    ll ret = 0;
    BIT<ll> bit;
    REP(i, n+m) {
      ll tmp = bit.query(v[i].second-1) + 1;
      bit.update(v[i].second, tmp);
      chmax(ret, tmp);
    }
    cout << ret << endl;
  }

  return 0;
}



Measured memory_bytes: 3896
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	Tuple[] points;
	boolean enable = true;

	static class Tuple {
		int t, x, y;

		Tuple(int t, int x, int y) {
			this.t = t;
			this.x = x;
			this.y = y;
		}
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		points = new Tuple[N + 1];
		points[0] = new Tuple(0, 0, 0);
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.readLine().split(" ");
			int t = Integer.parseInt(tokens[0]);
			int x = Integer.parseInt(tokens[1]);
			int y = Integer.parseInt(tokens[2]);
			points[i + 1] = new Tuple(t, x, y);
		}
	}

	void calc() {
		for (int i = 0; i < N; ++i) {
			Tuple prev = points[i];
			Tuple next = points[i + 1];
			if (next.t - prev.t < Math.abs(next.x - prev.x) + Math.abs(next.y - prev.y)) {
				enable = false;
				return;
			} else if ((Math.abs(next.x - prev.x) + Math.abs(next.y - prev.y) - next.t - prev.t) % 2 != 0) {
				enable = false;
				return;
			}
		}
	}

	void showResult() {
		System.out.println((enable ? "Yes" : "No"));
	}
}

Measured memory_bytes: 47108
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <typeinfo>
using namespace std;


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    int Digit(int N); //桁和
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }

    int Digit(int N){
        if(N<10){
            return N;
        }
        int r = 0;
        while (N>=10)
        {
            r += (N%10);
            N /= 10;
        }
        r += N;
        return r;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define strcin(s) string (s); cin >> (s);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    using intv = vector<int>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    incin(n);
    intv d(n);
    input(n,d);
    int sum = 0;
    for (int i = 0; i < n-1; i++)
    {
        for(int j=i+1; j<n; j++){
            sum += d[i]*d[j];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
 
#define fr first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forln(i, l, n) for (int i = l; i < n; ++i)

// #define LOCAL

using namespace std;

#ifdef LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n';
#else 
	#define dbg(x)
#endif

//tg: @galebickosikasa
 
const int maxn = (int) 3e5;
const ll inf = (ll) 2e9;
const ld pi = 3.14159265358979323846264;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

random_device rd;
mt19937 SuperRandom(rd());

ll BS_neg (vector<ll>& goo, ll x, ll m) {
	ll l = -1, r = sz (goo);
	while (r - l > 1) {
		ll mid = (r + l) / 2;
		ll t = x * goo[mid];
		if (t > m) l = mid;
		else r = mid;
	}
	dbg (x);
	dbg (m);
	if (x * x <= m) ++r;
	dbg (sz (goo) - r);
	return sz (goo) - r;
}

ll BS_pos (vector<ll>& goo, ll x, ll m) {
	ll l = -1, r = sz (goo);
	while (r - l > 1) {
		ll mid = (r + l) / 2;
		ll t = x * goo[mid];
		if (t > m) r = mid;
		else l = mid;
	}
	dbg (x);
	dbg (m);
	if (x * x <= m) --l;
	dbg (l + 1);
	return l + 1;
}

ll kek (vector<ll>& goo, ll m) {
	ll ans = 0;
	for (auto& x: goo) {
		if (x >= 0) ans += BS_pos (goo, x, m);
		else ans += BS_neg (goo, x, m);
	}
	ans /= 2;
	dbg (ans);
	return ans;
}

ll BinSearch (vector<ll>& goo, ll k) {
	ll l = -4e18, r = 4e18;
	// ll l = -10, r = 10;
	while (r - l > 1) {
		ll m = (r + l) / 2;
		dbg (m);
		if (kek (goo, m) >= k) r = m;
		else l = m;
	}
	return r;
}


int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll n, k;
	cin >> n >> k;
	vector<ll> goo (n);
	cinv (goo);
	sort (all (goo));
	ll ans = BinSearch (goo, k);
	cout << ans;





}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

using namespace std;

int d[110];

int main() {
   map<string,int> mp;
   int n,m;
   cin >> n;

   rep(i,n){
      string s;
      cin >> s;
      mp[s]++;
   }

   cin >> m;
   rep(i,m){
      string s;
      cin >> s;
      mp[s]--;
   }
   
   int ans=0;
   for(auto p : mp)
   ans = max(ans,p.second);

   cout << ans << endl;
}

Measured memory_bytes: 256
def half(x): return x/100*50+[0,50][x%100>0]
def In(): return map(int, raw_input().split())
def t(h,m): return 1050<=h*60+m<=1170

toll = {}
P=[6,10,12,14,27,33,7,9,12,23,30,5,8,20,27,5,17,26,12,23,10]
c=0
for i in range(0,6):
  for j in range(i+1,7):
    toll[(i,j)] = toll[(j,i)] =P[c]*50
    c += 1
D=[0, 6, 13, 18, 23, 43, 58]

while 1:
  i1 = input()-1
  if i1<0: break
  h1, m1 = In()
  i2 = input()-1
  h2, m2 = In()
  cost = toll[(i1,i2)]
  if (t(h1, m1) or t(h2,m2)) and abs(D[i1]-D[i2])<=40: cost = half(cost)
  print cost

Measured memory_bytes: 4284
package main

import "fmt"

var S [100000]int
var n, q int

func main() {
	var m int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&S[i])
	}
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&m)
		if solve(0, m) == true {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}
func solve(i, m int) bool {
	if m == 0 {
		return true
	}
	if i >= n {
		return false
	}
	if solve(i+1, m) == true {
		res := solve(i+1, m)
		return res
	} else if solve(i+1, m-S[i]) == true {
		res := solve(i+1, m-S[i])
		return res
	}
	return false
}



Measured memory_bytes: 1112
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int MAX = 0;
    rep(i, 0, n){
        cin >> a[i];
        MAX = max(MAX, a[i]);
    }
    int cnt = 0;
    bool f = true;
    rep(i, 0, n){
        if(a[i] == MAX - 1){
            cnt++;
        }
        if(a[i] < MAX - 1){
            f = false;
        }
    }
    if(cnt == 0){
        if(!(MAX == n - 1 || 2 * MAX <= n)) f = false;
    }else{
        int a = cnt;
        int b = n - cnt;
        if(!(a + 1 <= MAX && MAX <= a + b / 2)) f = false;
    }
    cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
fn main() {
  input! {
    r: f64,
  }

  println!("{:.15}", r * 2.0 * std::f64::consts::PI);
}


Measured memory_bytes: 2172
'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date:2nd june 2020
'''

def Solve():
    n=int(input())
    ar=[int(x) for x in input().split()]
    if 0 in ar:
        print(0)
        exit()
    ans=1
    for x in ar:
        ans=ans*x
        if ans>10**18:
            print("-1")
            return
    print(ans)
Solve()

Measured memory_bytes: 21668
#include <stdio.h>

long GCD(long a, long b){
  long dividend, divisor;
  if (a >= b) {
    dividend = a;
    divisor = b;
  } else {
    dividend = b;
    divisor = a;
  }
  long remainder;
  while (1) {
    if (divisor == 1) {
      return 1;
    }
    remainder = dividend % divisor;
    if (remainder == 0) {
      break;
    } else {
      dividend = divisor;
      divisor = remainder;
    }
  }
  return divisor;
}

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long max = a[0];
  long gcd_all = a[0];
  for (long i = 1; i < n; i++) {
    if (a[i] > max) {
      max = a[i];
    }
    gcd_all = GCD(gcd_all,a[i]);
  }
  if (k <= max && k%gcd_all == 0) {
    printf("POSSIBLE\n");
  } else {
    printf("IMPOSSIBLE\n");
  }

  return 0;
}

Measured memory_bytes: 896
/*input
9
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())     
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define N 998244353
#define PI acos(-1.0)
//if (s.find('R') != std::string::npos)
//s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;
bool comp(pair<string,ll>a,pair<string,ll>b){
  if(a.first==b.first) return a.second>b.second;
  return a.first<b.first;
}
int main()
{
  // added the two lines below 
  ios_base::sync_with_stdio (false); 
  cin.tie(NULL);
  cout.tie(0);
  
  ll a,b,c;
  cin>>a>>b>>c;
 cout<<(c/a)*b;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF 1LL<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    ll n; cin >> n;
    vvl G(n);
    rep(i,n-1){
        ll a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<ll> q;
    q.push(0);
    vl d(n,INF);
    d[0] = 0;
    ll mx = 0;
    while(!q.empty()){
        ll u = q.front(); q.pop();
        for(auto v : G[u]){
            if(d[v] != INF) continue;
            d[v] = d[u] + 1;
            q.push(v);
            mx = max(d[v],mx);
        }
    }
    ll start;
    rep(i,n) if(d[i]==mx) start = i;
    q.push(start);
    mx = 0;
    rep(i,n) d[i] = INF;
    d[start] = 0;
    while(!q.empty()){
        ll u = q.front(); q.pop();
        for(auto v : G[u]){
            if(d[v] != INF) continue;
            d[v] = d[u] + 1;
            q.push(v);
            mx = max(d[v],mx);
        }
    }
    if(mx%3==1) puts("Second");
    else puts("First");
    //cout << mx << endl;
}

Measured memory_bytes: 15984
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

ll C[60][60];

void PascalTriangle() {

    rep(i, 60) {
        C[i][0] = C[i][i] = 1;
    }

    for(int i = 2; i < 60; i++) {
        for(int j = 1; j < i; j++) {
            C[i][j] = C[i-1][j] + C[i-1][j-1];
        }
    }
}


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

    vector<ll> v(n);
    rep(i, n) {
        cin >> v[i];
    } 
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    ll sum = 0;
    rep(i, a) {
        sum += v[i];
    }
    double avg = (double)sum/a;
    printf("%.7f\n", avg);

    PascalTriangle();

    ll ans = 0;
    if(v[0] != v[a-1]) {

        int x = 0, y = 0;
        rep(i, n) {
            if(v[i] == v[a-1]) {
                x++;
            }
        }
        rep(i, a) {
            if(v[i] == v[a-1]) {
                y++;
            }
        }

        ans = C[x][y];
    }
    else if(v[0] == v[a-1]) {

        int x = 0;
        rep(i, n) {
            if(v[i] == v[0]) {
                x++;
            }
        }

        for(int i = a; i <= min(b, x); i++) {
            ans += C[x][i];
        }
    }

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

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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i=0;i<n;++i) cin >> h[i];
  
  int cnt = 0;
  int ans = 0;
  for (int i=0;i<n-1;++i){
      if (h[i]>=h[i+1]) cnt++;
      else cnt = 0;//カウンター0からやり直し
      ans = max(ans,cnt);
  }
  cout << ans << endl;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> c(h, vector<char>(w));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> c.at(i).at(j);
        }
    }
    for(int i = 0; i < h*2; i++){
        for(int j = 0; j < w; j++){
            int id = i/2;
            if(j+1 == w){
                cout << c.at(id).at(j) << endl;
            } else {
                cout << c.at(id).at(j);
            }
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner kb=new Scanner(System.in);
		int s=kb.nextInt();
		int h=s/3600;
		int m=(s-(h*3600))/60;
		int sec=(s-(h*3600))%60;
		
		System.out.printf("%d:%d:%d\n",h,m,sec);
		kb.close();
	}

}

Measured memory_bytes: 26400
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ret = 0;
  for (int i=3; i<=N; i+=2) {
    int c = 2;
    for (int j=2; j*j<=i; j++) {
      if (i % j == 0) {
        if (j * j == i) c += 1;
        else c += 2;
      }
    }
    if (c == 8) ret++;
  }
  cout << ret << endl;
}

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

using namespace std;

int main()
{
    string CODE="XYZABCDEFGHIJKLMNOPQRSTUVW";
    string instr;

    cin >> instr;

    for(int i=0; i<(int)instr.size(); ++i) {
        cout << CODE[instr[i]-'A'];
    }
    cout << endl;
    return 0;
}

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

int main() {
  ll n, m, r = 0, g = 0, b = 0;
  string s;
  cin >> n >> s;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'R')
      r++;
    else if (s[i] == 'G')
      g++;
    else
      b++;
  }
  m = r * g * b;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int k = j + j - i;
      if (k < n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
        m--;
        continue;
      }
    }
  }
  cout << m << endl;
}


Measured memory_bytes: 3644
#include<stdio.h>

int main(){

  int i,j,k;
  for(i=1;;i++){
    scanf("%d %d",&j,&k);
    if(j==0 && k==0) break ;


  if(j>k){
    printf("%d %d\n",k,j);
  }
  else{
    printf("%d %d\n",j,k);
  }
  }

  return 0;
}

Measured memory_bytes: 600
n = int(input())
b_list = [int(i) for i in input().split()]
a_list = [0] * n
before_val = 0
for i in range(n-1):
    target = b_list[i]
    if i == 0:
        a_list[i], a_list[i+1] = target, target
    elif before_val >= target:
        a_list[i], a_list[i+1] = target, target
    else:
        a_list[i], a_list[i+1] = before_val, target
    before_val = target
print(sum(a_list))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	
	
	int n, m;
	cin >> n >> m;
	bool f[15][15] = {};
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int t;
			cin >> t;
			t--;
			f[i][t] = 1;
		}
	}
	vector<int>p;
	for (int i = 0; i < m; i++) {
		int b;
		cin >> b;
		p.push_back(b);
	}

	int ans = 0;


	for (int i = 0; i < 1 << n; i++) {
	//	if(i&1)cout << i << endl;
	
		int t = 0;
		for (int j = 0; j < m; j++) {
			int c = 0;
			for (int k = 0; k < n; k++) {
				if (i&(1 << k)&&f[j][k])c++;
			}

			c = c % 2;
			if (c == p[j])t++;
		
		}
		if (t == m)ans++;
		

	}
	
	cout << ans << endl;


	return 0;



}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	unsigned long long a,b,x,m;
	scanf("%lld %lld %lld",&a,&b,&x);
	if(a%x==0)
	{
		m=b/x-a/x+1;
	}
	else
	{
		m=b/x-a/x;
	}
	printf("%lld\n",m);
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i=0;i<n;i++)
	{
		cin >> h[i];
	}
	vector<int> dp(n);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i=2;i<n;i++)
	{
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1024
# Aizu Problem ITP_1_11_D: Dice IV
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")



a = [0,2,5,3]
b = [0,1,5,4]
c = [1,2,4,3]

def sortdice(dice1,dice2,p,q,r):
    for i in range(4):
        dice1[p[0]],dice1[p[1]],dice1[p[2]],dice1[p[3]]=dice1[p[1]],dice1[p[2]],dice1[p[3]],dice1[p[0]]
        for j in range(4):
            dice1[q[0]],dice1[q[1]],dice1[q[2]],dice1[q[3]]=dice1[q[1]],dice1[q[2]],dice1[q[3]],dice1[q[0]]
            for k in range(4):
                dice1[r[0]],dice1[r[1]],dice1[r[2]],dice1[r[3]]=dice1[r[1]],dice1[r[2]],dice1[r[3]],dice1[r[0]]
                if dice1==dice2:
                    return True
    return False

def all_different(N, dices):
    for i in range(N - 1):
        dice1 = dices[i]
        for j in range(i + 1, N):
            dice2 = dices[j]
            if sortdice(dice1, dice2, a, b, c):
                return False
    return True

    
N = int(input())
dices = []
for _ in range(N):
    dices.append(list(map(int,input().split())))
print("Yes" if all_different(N, dices) else "No")

Measured memory_bytes: 7912
using System;
using System.Linq;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(input);
            Console.WriteLine(input[0] + input[1]);
        }
    }
}

Measured memory_bytes: 11348
n,m,s = map(int,input().split())
import collections
g = [[] for _ in range(n+1)]
dic = {}
for _ in range(m):
    u,v,a,b = map(int,input().split())
    g[u].append(v)
    g[v].append(u)
    dic[(u,v)]=(a,b)
    dic[(v,u)]=(a,b)
arr = [[0,0]]+[list(map(int,input().split())) for _ in range(n)]
cost =[[float('inf')]*2501 for _ in range(n+1)]
for i in range(min(2500,s)+1):
    cost[1][i] = 0
q=collections.deque()
q.append(1)
while q:
    v = q.popleft()
    c,d = arr[v]
    for i in range(c,2501):
        cost[v][i] = min(cost[v][i],cost[v][i-c]+d)
    for u in g[v]:
        a,b = dic[(v,u)]
        flag = False
        for i in range(a,2501):
            if cost[u][i-a]>cost[v][i]+b:
                cost[u][i-a]=cost[v][i]+b
                flag = True
        if flag==True:
            q.append(u)
for i in range(2,n+1):
    print(min(cost[i]))

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		// temp += n % 10;
		n = n / 10;
		temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}
bool ispalin(int n) {


	string  str = to_string(n);
	// cout<<str<<endl;


	for (int i = 0; i < str.size() / 2; ++i)
	{
		/* code */
		// watch2(str[i],str[str.size()-i-1]);
		if (str[i] != str[str.size() - i - 1]) {
			return false;
		}
	}


	return true;


}

int main() {
	int i,  n, m, k;
	int sum = 0;
	c_p_c();
	string s;
	cin>>s;
	for (int i = 0; i < s.size(); ++i)
	{
		/* code */
		cout<<'x';
	}
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main(){
	string s;
	cin>>s;
	set<char> st;
	rep(i,s.size()){
		if(!st.insert(s[i]).se){
			cout<<"no"<<endl;
			return 0;
		}
	}
	cout<<"yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int k, x;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> k >> x;
  erep(i, max(-1000000LL, x-k+1), min(1000000LL, x+k-1)) {
    cout << i << (i == min(1000000LL, x+k-1) ? "\n" : " ");
  }
  return 0;
}




Measured memory_bytes: 256