akhauriyash/Code-Regression huggingface dataset:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    penalty = dict()
    penalty_cnt = 0
    ans = set()
    for _ in range(m):
        num, result = input().split()
        if result == 'AC':
            ans.add(num)
            if num not in penalty:
                penalty[num] = 0
        elif num not in ans:
            if num not in penalty:
                penalty[num] = 1
            else:
                penalty[num] += 1
    ans = list(ans)
    for i in range(len(ans)):
        penalty_cnt += penalty[ans[i]]
    print(len(ans), penalty_cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21280
n = gets.chomp.to_i

a = [1]

x = 6
while x <= 100000 do
  a.push(x)
  x *= 6
end

x = 9
while x <= 100000 do
  a.push(x)
  x *= 9
end

a = a.select{|x| x <= n}.sort

dp = [1e+9+7] * (n + 1)
dp[0] = 0

n.times do |x|
  a.each do |v|
    if x + v <= n then
      dp[x + v] = [dp[x + v], dp[x] + 1].min
    end
  end
end

puts dp[n].to_s

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b&&b==c)cout << 1 << endl;
  else if (a==b||b==c||a==c) cout << 2 << endl;
  else cout << 3 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def main():
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
    input = sys.stdin.readline
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(lambda x:int(x) - 1, input().split())
        uf.union(a, b)
    
    ans = max([-i for i in uf.parents])
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 91980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;


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

    vector<int> pos(N);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        pos[a - 1] = i;
    }

    int ans = N - 1;
    int prev_start = 0;
    for(int i=1;i<N;i++){
        if(pos[i - 1] < pos[i]){
            ans = min(ans, N - (i - prev_start + 1));
        }else{
            prev_start = i;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
    vector<long long> n(3);
    cin >> n[0] >> n[1] >> n[2];
    sort(n.begin(), n.end());
    bool exist_e = false;
    for (int i=0; i<3; ++i) {
        if (n[i]%2 == 0) exist_e = true;
    }
    long long ans = 0;
    if (!exist_e) ans = n[1] * n[0];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<int> a(n), ra(n), ans1(n), ans2(n);
    rep(i, n)cin >> a[i];
    sort(all(a));
    ra = a;
    reverse(all(ra));
    vector<P> x, y;
    rep(i, n){
        if(i % 2 == 0){
            if(i == 0 || i == n-1)x.push_back(make_pair(1, i));
            else x.push_back(make_pair(2, i));
        }
        else{
            if(i == 0 || i == n-1)y.push_back(make_pair(1, i));
            else y.push_back(make_pair(2, i));
        }
    }
    sort(rall(x)); sort(rall(y));
    rep(i, x.size()){
        ans1[x[i].second] = a[i];
        ans2[x[i].second] = ra[i];
    }
    rep(i, y.size()){
        ans1[y[i].second] = ra[i];
        ans2[y[i].second] = a[i];
    }
    ll c = 0, d = 0;
    rep(i, n-1){
        c += abs(ans1[i] - ans1[i+1]);
        d += abs(ans2[i] - ans2[i+1]);
    }
    cout << max(c, d) << endl;
}


Measured memory_bytes: 2812
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll num;
    cin>>num;
    string s;
    cin>>s;
    ll i;
    for(i=0; i<s.length(); i++) {
    	ll cur = s[i] - 'A';
    	cur = (cur + num)%26;
    	s[i] = cur + 'A';
    }
    cout<<s<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    long k;
    cin >> n >> k;
    vector<int> a(n + 1);
    unordered_map<int, bool> visited;
    for (int i = 1; i <= n; i++) cin >> a[i];

    int now = 1;
    visited[now] = true;

    while (k--) {
        now = a[now];
        if (visited[now]) break;
        visited[now] = true;
    }

    int t = 0;
    int tmp = now;

    if (k > 0) {
        while (k--) {
            now = a[now];
            t += 1;
            if (now == tmp) break;
        }
    }

    if (k > 0) {
        k %= t;
        while (k--) now = a[now];
    }

    cout << now << endl;
}


Measured memory_bytes: 11108
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    ll x, y;
    cin >> x >> y;
    int ok = 0;
    for (int i = 0; i < 101; i++)
    {
        for (int j = 0; j < 101; j++)
        {
            if (i + j == x)
            {
                if (i * 2 + 4 * j == y)
                    ok = 1;
            }
        }
    }
    cout << (ok ? "Yes" : "No");
}

Measured memory_bytes: 3652
def main(str)
  n = str.to_f
  x = n * 1/3
  x * x * x
end

unless ENV["TEST"]
  puts(main($stdin.read.chomp))
  exit(0)
end

require 'minitest/autorun'

class TestA < Minitest::Test
  def test_main
    assert_equal(1.0000000, main("3"))
    assert_equal(36926037.000000000000, main("999"))
  end
end




Measured memory_bytes: 14260
n,q=map(int,input().split())
Q=[list(map(int,input().split())) for i in range(q)]

#Segment tree（区間の和を求めるバージョン）
for i in range(30):#要素数以上の2のベキを見つける
    if n<1<<i:
        seg_el=1<<i#Segment treeの台の要素数
        break

SEG=[0]*(2*seg_el-1)#Segment treeを一次元リストとして作る

def update(n,x,seg_el):#A[n]+=x
    i=n+seg_el-1
    SEG[i]+=x
    i=(i-1)//2
    
    while i>=0:
        SEG[i]+=x
        i=(i-1)//2
        
def getvalues(a,b,k,l,r):#区間[a,b)での,SEG[k],つまり区間[l,r)に関する和を調べる
    if r<=a or b<=l:#区間[a,b)が対象区間の外にあれば,0を出力
        return 0
    if a<=l and r<=b:#区間[a,b)が対象区間の中にあればSEG[k]を出力
        return SEG[k]
    vl=getvalues(a,b,k*2+1,l,(l+r)//2)#それ以外のときは,SEG[k*2+1]とSEG[k*2+2]で場合分け（木の子ノード二つを見る）
    vr=getvalues(a,b,k*2+2,(l+r)//2,r)
    return vl+vr

for com,x,y in Q:
    if com==0:
        update(x,y,seg_el)
    else:
        print(getvalues(x,y+1,0,0,seg_el))


Measured memory_bytes: 28884
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ll mod=1e9+7;
const ld PI = 2 * acos(0.0);
ll m(ll a){ return (a+mod)%mod;}
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int solve(){}
void fun(vv &gr,v &dist,int root)
{
    // int root=0;
    // v dist(n,0);
    queue<int>que;
    que.push(root);
    int n=sz(dist);
    vector<bool>vst(n,false);
    vst[root]=true;
    dist[root]=0;
    while(!que.empty())
    {
        int u=que.front();
        // u--;
        que.pop();
        for(auto it:gr[u])
        {
            if(!vst[it])
            {
                vst[it]=true;
                que.push(it);
                dist[it]=dist[u]+1;
            }
        }
    }
}
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n,x,y;cin>>n>>x>>y;
    v ans(n+1,0);
    vv gr(n);
    for(int i=0;i<n-1;i++)
    {
        gr[i].pb(i+1);
        gr[i+1].pb(i);
    }
    x--;
    y--;
    gr[x].pb(y);
    gr[y].pb(x);
    v dist(n,0);
    for(int i=0;i<n;i++)
    {
        fun(gr,dist,i);
        for(int j=i+1;j<n;j++)
            ans[dist[j]]++;
    }
    // f(i,n)
    // {
    //     for(int j=i+1;j<n;j++)
    //         ans[dist[i]]++;
    // }
    for(int i=1;i<n;i++)cout<<ans[i]<<"\n";
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String line[] = line = bf.readLine().split("\\s");;
        int n = Integer.parseInt(line[0]);
        int w = Integer.parseInt(line[1]);
        int wt [] =  new int[n];
        int val [] =  new int[n];

        for(int i=0;i<n;++i) {
            line = bf.readLine().split("\\s");
            wt[i] = Integer.parseInt(line[0]);
            val[i] = Integer.parseInt(line[1]);
        }
        long [][] dp = new long[n+1][w+1];

        for(int i=1;i<=n;i++) {
            for(int j=0;j<=w;j++) {

                if(wt[i-1] <= j) {
                    dp[i][j] = Math.max(dp[i-1][j] ,  dp[i-1][j-wt[i-1]] + val[i-1]);
                } else {
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
        System.out.println(dp[n][w]);



    }
}


Measured memory_bytes: 129108
n=int(input())

l=[]
for i in range(n):
 s,p=input().split()
 p=int(p)
 l.append([s,p,i])
l.sort()
l.append(['',0,0])

b_name=l[0][0]
t_list=[]

for name, point, inx in l:
 if name==b_name:
  t_list.append([int(point),inx])
 else:
  t_list.sort(reverse=True)
  for i,j in t_list:
   print(j+1)
  t_list=[]
  t_list.append([int(point),inx])
  b_name=name

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110];
int main(){
    ll n,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0,a8=0;
    ll ans=0;
    cin>>n;
    rep(i,0,n)cin>>a[i];
    ll x=0;
    rep(i,0,n){
        if(a[i]>=3200)a1++;
        else if(a[i]>=2800)x++;
        else if(a[i]>=2400)a2++;
        else if(a[i]>=2000)a3++;
        else if(a[i]>=1600)a4++;
        else if(a[i]>=1200)a5++;
        else if(a[i]>=800)a6++;
        else if(a[i]>=400)a7++;
        else a8++;
    }
    if(a2>0)ans++;
    if(a3>0)ans++;
    if(a4>0)ans++;
    if(a5>0)ans++;
    if(a6>0)ans++;
    if(a7>0)ans++;
    if(a8>0)ans++;
    if(x>0)ans++;

    if(ans==0)cout<<"1"<<" ";
    else cout<<ans<<" ";
    cout<<ans+a1;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a,b;
    char op;
    
    while(true){
    cin>>a>>op>>b;
    if(op == '?') break;
    switch(op){
    case '+':
    	cout<<a+b<<endl;
    	break;
    case '-':
    	cout<<a-b<<endl;
    	break;
    case '*':
    	cout<<a*b<<endl;
    	break;
    case '/':
    	cout<<a/b<<endl;
    	break;
    }
    }
    
    }


Measured memory_bytes: 3084
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val v = readLine()!!.split(" ").map { it.toInt() }
    val c = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    for (i in 0 until n) {
        if (v[i] > c[i]) ans += v[i] - c[i]
    }
    println(ans)
}

Measured memory_bytes: 37856
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N, M;
  cin >> N >> M;
  
  vector<int> s(M);
  vector<int> c(M);
  
  for (int i=0; i<M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  
  int error = 0;
  int a100 = 0;
  int a10 =0;
  int a1 = 0;
  int c100 = 0;
  int c10 = 0;
  int c1 = 0;
  
  if (N==3) {
  
      for (int i=0; i<M; i++) {
          if ( s.at(i) > N) {
              error = 1;
              break;
          }
          if ( s.at(i) == 1) {
              if (c.at(i) == 0) {
                  error = 1;
              } else if (c100 == 0 || a100 == c.at(i)) {
                  a100 = c.at(i);
                  c100++;
              } else {
                  error = 1;
              }
          }
          
          if ( s.at(i) == 2) {
              if ( c10 == 0 || a10 == c.at(i)) {
                  a10 = c.at(i);
                  c10++;
              } else {
                  error = 1;
              }
          }
          
          if ( s.at(i) == 3) {
              if ( c1 == 0 || a1 == c.at(i)) {
                  a1 = c.at(i);
                  c1++;
              } else {
                  error = 1;
              }
          }
      }
  }
  
  if (N==2) {
  
      for (int i=0; i<M; i++) {
          if ( s.at(i) > N) {
              error = 1;
              break;
          }
          if ( s.at(i) == 1) {
              if (c.at(i) == 0) {
                  error = 1;
              } else if (c10 == 0 || a10 == c.at(i)) {
                  a10 = c.at(i);
                  c10++;
              } else {
                  error = 1;
              }
          }
          
          if ( s.at(i) == 2) {
              if ( c1 == 0 || a1 == c.at(i)) {
                  a1 = c.at(i);
                  c1++;
              } else {
                  error = 1;
              }
          }
      }
  }
  
  if (N==1) {
  
      for (int i=0; i<M; i++) {
          if ( s.at(i) > N) {
              error = 1;
              break;
          }
          if ( s.at(i) == 1) {
              if (c1 == 0 || a1 == c.at(i)) {
                  a1 = c.at(i);
                  c1++;
              } else {
                  error = 1;
              }
          }
      }
  }
      
      if (error == 1) {
          cout << "-1" << endl;
      } else {
          if( N == 3 && a100 == 0) {
              a100 = 1;
          } else if ( N == 2 && a10 == 0) {
              a10 = 1;
          } 
          int ans = 100 * a100 + 10 * a10 + a1;
          cout << ans << endl;
      }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    double tmp[20][2];
    int cnt=0;
    double ans=0.0;
    while (scanf("%lf,%lf",&tmp[cnt][0],&tmp[cnt][1])!=EOF) {
        cnt++;
    }
    for (int i=0;i<cnt;++i) {
        ans+=(tmp[i][0]-tmp[(i+1)%cnt][0])*(tmp[i][1]+tmp[(i+1)%cnt][1]);
    }
    ans=abs(ans);
    printf("%lf\n",ans/2.0);
    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s,t;
    cin>>s>>t;
    int l1 = s.size(), l2 = t.size();
    int a[l1+1][l2+1];
    for(int i = 0; i <= l1; i++) {
        for(int j = 0; j <= l2; j++) {
            if(i == 0 || j == 0)
                a[i][j] = 0;
            else if(s[i-1] == t[j-1])
                a[i][j] = a[i-1][j-1] + 1;
            else 
                a[i][j] = max(a[i-1][j],a[i][j-1]);
        }
    }
    int len = a[l1][l2];
    int i = l1, j = l2,k = len-1;
    char str[len+1];
    str[len] = '\0';
    while(i > 0 && j > 0) {
        if(s[i-1] == t[j-1]) {
            str[k] = s[i-1];
            k--;
            i--;
            j--;
        } else if(a[i-1][j] >= a[i][j-1])
            i--;
        else 
            j--;
    }
    cout<<str<<endl;
} 

Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	ll a,p,ans;
	cin>>a>>p;
	ans= 3*a+p;
	ans/=2;
	cout<<ans;
    return 0;
}























Measured memory_bytes: 256
n,d = map(int,input().split())

x = [list(map(int,input().split())) for _ in range(n)]

ans = 0

for i in range(n-1):
    for j in range(i+1,n):
        sub = 0
        for k in range(d) :
            sub += abs(x[i][k]-x[j][k])**2
        sub = sub**0.5
        if sub.is_integer() :
            ans += 1

print(ans)


Measured memory_bytes: 9348
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[110][100010];
int main(){
int n,W;
cin>>n>>W;
vector<ll> w(n),v(n);
ll ma=0;
for(int i=0;i<n;i++){
    cin>>w.at(i)>>v.at(i);
    ma+=v.at(i);
}
for(int i=1;i<=ma;i++)dp[0][i]=inf;

for(int i=0;i<n;i++){
    for(int j=0;j<=ma;j++){
      if(j>=v.at(i))dp[i+1][j]=min(dp[i][j],dp[i][j-v.at(i)]+w.at(i));
      else  dp[i+1][j]=dp[i][j];    
    }
}
int ans=0;
for(int i=0;i<=ma;i++)if(dp[n][i]<=W)ans=i;
cout<<ans<<endl;
}


Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
int main(){

  int n;
  int k;
  cin >>n >> k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int dp[n];
  dp[0] = 0;
  for(int i=1;i<n;i++){
    dp[i] =INT_MAX;
    for(int j = 1;j<=k && i-j>=0;j++){
      dp[i] = min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
    }
  }
  cout<<dp[n-1];
  
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define int ll
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=800010,Mod=924844033,G=5;
int n,front[N],cnt,k,ans,siz[N],fac[N],fai[N],inv[N],f[N],g[N],limit,r[N];
struct node{int to,nxt;}e[N<<1];
void Add(int u,int v){e[++cnt]=(node){v,front[u]};front[u]=cnt;}
void dfs(int u,int ff)
{
	siz[u]=1;
	for(int i=front[u];i;i=e[i].nxt)
	{
		int v=e[i].to;if(v==ff)continue;
		dfs(v,u);siz[u]+=siz[v];f[siz[v]]++;
	}
	f[n-siz[u]]++;
}
int qpow(int a,int b)
{
	int ret=1;
	while(b){if(b&1)ret=1ll*ret*a%Mod;b>>=1;a=1ll*a*a%Mod;}
	return ret;
}
void NTT(int *a,int opt)
{
	for(int i=0;i<limit;i++)if(i>r[i])swap(a[i],a[r[i]]);
	for(int i=1;i<limit;i<<=1)
	{
		int Root=qpow(G,(Mod-1)/(i<<1));
		for(int j=0,R=i<<1;j<limit;j+=R)
		{
			int W=1;
			for(int k=0;k<i;k++,W=1ll*W*Root%Mod)
			{
				int X=a[j+k],Y=1ll*a[i+j+k]*W%Mod;
				a[j+k]=(X+Y)%Mod;a[i+j+k]=(X-Y+Mod)%Mod;
			}
		}
	}
	if(opt==-1)
	{
		reverse(a+1,a+limit);int Inv=qpow(limit,Mod-2);
		for(int i=0;i<limit;i++)a[i]=1ll*a[i]*Inv%Mod;
	}
}
int C(int n,int m){if(n<m||n<0||m<0)return 0;return 1ll*fac[n]*fai[m]%Mod*fai[n-m]%Mod;}
signed main()
{
	n=gi();
	for(int i=1;i<n;i++){int u=gi(),v=gi();Add(u,v);Add(v,u);}
	fac[0]=fai[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%Mod;
	for(int i=2;i<=n;i++)inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for(int i=1;i<=n;i++)fai[i]=1ll*fai[i-1]*inv[i]%Mod;
	dfs(1,1);
	for(int i=0;i<=n;i++)f[i]=1ll*f[i]*fac[i]%Mod;
	for(int i=0;i<=n;i++)g[i]=fai[n-i];
	limit=1;int l=0;while(limit<(n+n))limit<<=1,l++;
	for(int i=0;i<limit;i++)r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
	NTT(f,1);NTT(g,1);
	for(int i=0;i<limit;i++)f[i]=1ll*f[i]*g[i]%Mod;
	NTT(f,-1);
	for(int i=1;i<=n;i++)f[i]=1ll*f[i+n]*fai[i]%Mod;
	for(int i=1;i<=n;i++)printf("%lld\n",(1ll*n*C(n,i)%Mod-f[i]+Mod)%Mod);
	return 0;
}


Measured memory_bytes: 57216
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define int long long
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define All(x) x.begin() , x.end()
#define de(x,y) cout<<#x<<" "<<x<<y;
#define pray(a,i,n_thing) for(int x=i;x<=(i+n_thing);x++) cout<<#a<<"["<<x<<"] :"<<a[x]<<endl;
#define mem(aa,x) memset(aa,x,sizeof aa)
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
const int maxn=4e5+5;
int arr[maxn];

int f(int x){
	if(x<10) return x;
	return f(x/10)+x%10;
}

main(){
    int N,A,B,sum=0;
    cin>>N>>A>>B;
    rep(i,1,N){
    	if(A<=f(i)&&f(i)<=B)
		    sum+=i;
	}
	cout<<sum<<"\n";
}



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

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n, m;
  cin >> n >> m;
  int ans = (n-1) * (m-1);
  cout << ans << endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long N, std::string S){
  int ans=1;
  for (int i = 0; i < S.length()-1; i++) {
    if(S[i] != S[i+1])ans++;
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  string s;
  int k;
  cin >> s >> k;

  map<char, vector<int> > mp;
  rep(i, 0, s.length()) {
    mp[s[i]].pb(i);
  }

  map<string, int> ans;
  for(auto it = mp.begin(); it != mp.end(); it++) {
    rep(i, 0, it->second.size()) {
      string ss = "";
      rep(j, it->second[i], min((int)s.length(), it->second[i] + 5)) {
        ss += s[j];
        ans[ss] = 1;
      }
    }
    if(ans.size() >= k) break;
  }
  int id = 0;
  for(auto it = ans.begin(); it != ans.end(); it++) {
    id++;
    if(id >= k) {
      cout << it->first << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint a, v;
    cin >> a >> v;
    lint b, w;
    cin >> b >> w;
    lint t;
    cin >> t;
    lint dist = abs(a - b);
    lint sp   = v - w;
    if (dist == 0) {
        cout << "YES"
             << "\n";
        return 0;
    }
    if (sp <= 0) {
        cout << "NO"
             << "\n";
        return 0;
    }
    if ((dist + sp - 1) / sp <= t) {
        cout << "YES"
             << "\n";
    } else {
        cout << "NO"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 3640
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;

int main()
{
    optimiza_io
    string s;
    cin >> s;
    cout << ( s[1] == 'R' ? "ABC" : "ARC" );
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n == 1) {
		cout << 1 << endl;
	}
	else if (n < 4) {
		cout << 2 << endl;
	}
	else if (n < 8) {
		cout << 4 << endl;
	}
	else if (n < 16) {
		cout << 8 << endl;
	}
	else if (n < 32) {
		cout << 16 << endl;
	}
	else if (n < 64) {
		cout << 32 << endl;
	}
	else if (n < 128) {
		cout << 64 << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt(),x=sc.nextInt();//,k=sc.nextInt();
		int sum=0,count=0,flag=0,max=-999999,min=99999;
		int[] array=new int[101];
		//String[] array = new String[n];
		//String s=sc.next();//,t=sc.next();
		for(int i=0;i<m;i++) {
			array[sc.nextInt()]++;
		}
		for(int i=0;i<=x;i++) {
			sum+=array[i];
		}
		for(int i=x;i<n;i++) {
			count+=array[i];
		}

		System.out.println(Math.min(count, sum));
	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 23760
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;	}


//Variables Declaration
int N ;
vector<vector<ll>> vect;
ll dp[3][MAXN];

ll solve(int n, int t) {
	if (n >= N) return 0;
	if (dp[t][n] >= 0) return dp[t][n];
	ll sol = 0;

	for (int k = 0 ; k < 3 ; ++k) {
		if (k != t) {
			sol = max ( sol, solve(n + 1 , k ) + vect[t][n] );
		}
	}
	return dp[t][n] = sol ;

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


	memset(dp, -1, sizeof(dp));

	cin >> N;
	vect.resize(3, vector< ll>(N));
	for (int i = 0 ; i < N ; ++i) {
		for (int j = 0 ; j < 3 ; ++j) {
			cin >> vect[j][i];
		}
	}

	ll ans = 0;

	dp[0][0] = vect[0][0] ;
	dp[1][0] = vect[1][0] ;
	dp[2][0] = vect[2][0] ;
	for (int i = 1 ; i < N ; ++i) {
		dp[0][i] = max(dp[1][i - 1] , dp[2][i - 1] ) + vect[0][i];
		dp[1][i] = max(dp[0][i - 1] , dp[2][i - 1] ) + vect[1][i] ;
		dp[2][i] = max(dp[0][i - 1] , dp[1][i - 1] ) + vect[2][i] ;
	
	}
	ans = max(dp[0][N-1], dp[1][N-1]);
	ans = max(ans		, dp[2][N-1]);
	/*
	ans = max( solve(start, 0) , solve(start, 1));
	ans = max( ans 			  , solve(start, 2));*/
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5760
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a,b,c = gi

puts c >= a && c<=b ? 'Yes' : 'No'



Measured memory_bytes: 2300
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int X,K,D;cin>>X>>K>>D;X=abs(X);
	if(X/D>=K){
		cout<<X-D*K<<endl;
	}else {
		int num=X/D;
		K-=num;
		X-=D*num;
		if(K%2)cout<<abs(X-D)<<endl;
		else cout<<X<<endl;
	}
}

Measured memory_bytes: 3596
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a = list(input())


k = [[0 for i in range(len(a)+1)] for j in range(3)]

for j in range(len(a)):
    if a[j] == "<":
        k[0][j+1] = 1
    elif a[j] == ">":
        k[1][j] = 1

for i in range(len(a)):
    if k[0][i+1] > 0 and k[0][i] > 0:
        k[0][i+1] += k[0][i]
for i in range(len(a)):
    if k[1][-(i+1)] > 0 and k[1][-(i+2)] > 0:
        k[1][-(i+2)] += k[1][-(i+1)] 
for i in range(len(a)+1):
    if k[1][i] >= k[0][i]:
        k[2][i] = k[1][i]
    else:
        k[2][i] = k[0][i]


print(sum(k[2]))

Measured memory_bytes: 122792
def point(arr):
    res=0
    for i in range(1,N):
        res+=abs(arr[i]-arr[i-1])
    return res
def merge(li_1,li_2):
    arr=[]
    for i in range(N):
        if not i%2:
            arr.append(li_2[i//2])
        else:
            arr.append(li_1[i//2])
    return arr

N=int(input())
A=[int(input()) for i in range(N)]
A.sort()
if not N%2:
    ans=0
    l,r=A[:N//2],A[N//2:]
    print(point(merge(l,r)))
else:
    ans=-1
    li=[]
    l,r=A[:N//2],A[N//2:]
    r[1],r[-1]=r[-1],r[1]
    ans=max(ans,point(merge(l,r)))
    li=[]
    l,r=A[:N//2+1],A[N//2+1:]
    l[0],l[-2]=l[-2],l[0]
    ans=max(ans,point(merge(r,l)))
    print(ans)

Measured memory_bytes: 60888
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include<queue>
#include<cmath>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
#define INF 1000000000
using namespace std;
using ll = long long;
using IR = pair<int, int>;

int N, M;

int main() {
	S2(N, M);
	if (M == 0) {
		if (N == 1) {
			P(0);
			return 0;
		}
		else if (N == 2) {
			P(10);
			return 0;
		}
		else if (N == 3) {
			P(100);
			return 0;
		}
	}
	vector<bool> dec(N);
	vector<int> integer;
	R(i, N)integer.push_back(0);
	if (N >= 2) {
		integer[0] = 1;
	}
	R(i, M) {
		int s, c;
		S2(s, c);
		if (N >= 2 && s == 1 && c == 0) {
			P(-1);
			return 0;
		}
		if (dec[s - 1] && integer[s - 1] != c) {
			P(-1);
			return 0;
		}
		dec[s - 1] = true;
		integer[s - 1] = c;
	}
	R(i, N) {
		P(integer[i]);
	}
}

Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>

using namespace std;

int h,n;
int dp[16][10001]={};
int d[10001]={};

int calc(int i,int m){
	if(dp[i][m]>=0)return dp[i][m];
	dp[i][m]=0;
	for(int j=0;j<16;++j)dp[i][m]=max(dp[i][m],calc(j,m-1));
	if(((3+d[m])==i)&&((3&d[m-1])==0)){
		dp[i][m]=max(dp[i][m],1+calc(0,m-1));
		dp[i][m]=max(dp[i][m],1+calc(4,m-1));
		dp[i][m]=max(dp[i][m],1+calc(8,m-1));
		dp[i][m]=max(dp[i][m],1+calc(12,m-1));
	}
	if(((6+d[m])==i)&&((6&d[m-1])==0)){
		dp[i][m]=max(dp[i][m],1+calc(0,m-1));
		dp[i][m]=max(dp[i][m],1+calc(1,m-1));
		dp[i][m]=max(dp[i][m],1+calc(8,m-1));
		dp[i][m]=max(dp[i][m],1+calc(9,m-1));
	}
	if(((12+d[m])==i)&&((12&d[m-1])==0)){
		dp[i][m]=max(dp[i][m],1+calc(0,m-1));
		dp[i][m]=max(dp[i][m],1+calc(1,m-1));
		dp[i][m]=max(dp[i][m],1+calc(2,m-1));
		dp[i][m]=max(dp[i][m],1+calc(3,m-1));
	}
	if(((15+d[m])==i)&&((15&d[m-1])==0)){
		dp[i][m]=max(dp[i][m],2+calc(0,m-1));
	}
	return dp[i][m];
}
int main() {
	cin>>h>>n;

	for(int i=0;i<10001;++i){
		for(int j=0;j<16;++j){
			dp[j][i]=-1;
		}
	}
	int x,y;
	for(int i=0;i<n;++i){
		cin>>x>>y;
		x=(1<<x);
		for(int j=0;j<16;++j){
			if((j&x)==0)dp[j][y]=0;
		}
		d[y]+=x;
	}

	for(int j=0;j<16;++j)dp[j][0]=0;


	int total=0;
	for(int i=0;i<16;++i)total=max(total,calc(i,h-1));
	cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 4392
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int N;
string S;

inline vector<int> Z_algorithm(string S) {
	vector<int> A(S.size());
	A[0] = S.size();
	int i = 1, j = 0;
	while(i < S.size()){
		while(i + j < S.size() && S[j] == S[i + j]) j++;
		A[i] = j;

		if(j == 0){
			i++;
			continue;
		}
		int k = 1;
		while(i + k < S.size() && k + A[k] < j){
			A[i + k] = A[k];
			k++;
		}
		i += k;
		j -= k;
	}
	return A;
}

signed main() {
	cin >> N >> S;
	ll ans = 0;
	rep(i, N) {
		string T = S.substr(i, N - i);
		vector<int> v = Z_algorithm(T);
		for (int j = 1; j < v.size(); j++) {
			if(v[j] <= j) ans = max(ans, (ll)v[j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
N = int(input())
nums =[]
count = 0
switch = False
for i in range(N):
    nums.append([int(x) for x in input().split()])

for j in nums:
    if j[0] == j[1]:
        count += 1
    elif j[0] != j[1]:
        count = 0
    if count == 3:
        switch = True
if switch == True:
    print("Yes")
elif switch == False:
    print("No")


Measured memory_bytes: 9176
L,R = map( int, input().split() )

Min = 2019
N = R - L

if N > 2019:
    Min = 0
else:
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            if Min > i*j%2019:
                Min = i*j%2019
        

print(Min)

Measured memory_bytes: 41196
from heapq import heappush, heappop
def main():
    X, Y, Z, K = map(int, input().split())
    a_cake = [int(x) for x in input().split()]
    b_cake = [int(x) for x in input().split()]
    c_cake = [int(x) for x in input().split()]

    a_cake.sort(reverse = True)
    b_cake.sort(reverse = True)
    c_cake.sort(reverse = True)

    heap_queue = []
    arg_hash = {}
    score_taste = a_cake[0] + b_cake[0] + c_cake[0]
    heappush(heap_queue, (-score_taste, 0, 0, 0))

    for i in range(K):
        score, a_candle, b_candle, c_candle = heappop(heap_queue)
        print(-score)

        arg_a = (a_candle+1, b_candle, c_candle)
        arg_b = (a_candle, b_candle+1, c_candle)
        arg_c = (a_candle, b_candle, c_candle+1)

        if a_candle < X-1 and arg_a not in arg_hash:
            arg_hash[arg_a] = 1
            heappush(heap_queue, (-(a_cake[a_candle+1] + b_cake[b_candle] + c_cake[c_candle]),) + arg_a)
        if b_candle < Y -1 and arg_b not in arg_hash:
            arg_hash[arg_b] = 1
            heappush(heap_queue, (-(a_cake[a_candle] + b_cake[b_candle+1] + c_cake[c_candle]),) + arg_b)
        if c_candle < Z -1 and arg_c not in arg_hash:
            arg_hash[arg_c] = 1
            heappush(heap_queue, (-(a_cake[a_candle] + b_cake[b_candle] + c_cake[c_candle+1]),) + arg_c)

if __name__ == "__main__":
    main()

Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

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

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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


int main() {

	ll N,A,B;
	cin >> N >> A >> B;

	ll ans = 0;

	repn(i, N) {
		ll wa = 0;

		for (int j = i; j > 0; j /= 10) {
			wa += j % 10;
		}

		if (wa >= A && wa <= B) { ans+=i; }

	}

	cout << ans;


	system("PAUSE");

	

}


Measured memory_bytes: 504
import java.util.Scanner;

  
public class Main {
	
	
  public static void main(String[] args) {
	  Scanner sc=new Scanner(System.in);
	  
	  int n=Integer.MAX_VALUE;
	  
	  for(int i=0;i<n;i++){
		  int x=Integer.parseInt(sc.next());
		  int y=Integer.parseInt(sc.next());
		  if(x==0&&y==0){
			  break;
		  }
		  else if(x>y){
		  System.out.println(y +" "+ x);
		  }
		  else if(x<y){
			  System.out.println(x +" "+ y);
		  }
		  else if(x==y){
			  System.out.println(x +" "+ y);
		  }
	  }
    
  }
}

Measured memory_bytes: 25164
import java.util.Scanner;

class Main{
  public static int temp = 0;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int X = sc.nextInt();
    int L[] = new int[N];
    for(int i = 0; i < N;i++){
     L[i] = sc.nextInt();
    }
    N = N + 1;
    
    int ans = 0;
    if(0 <= X){
      ans = ans + 1;
     }
    for(int i = 2; i <= N;i++){
     temp = method(i,L[i-2]);
     if(temp <= X){
      ans = ans + 1;
     }
    }
    System.out.println(ans);

  }
  static int method(int Ni,int Li){
    return (temp + Li);
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    for (auto &e: b) cin >> e;

    vector<int> ans;

    while (!b.empty()) {
        int i;
        for (i = b.size()-1; i >= 0; --i) {
            if (i+1 == b[i]) break;
        }
        if (i == -1) {
            cout << -1 << endl;
            return 0;
        }
        b.erase(b.begin() + i);
        ans.push_back(i+1);
    }

    reverse(ans.begin(), ans.end());
    for (auto &e: ans) cout << e << endl;
}


Measured memory_bytes: 256