akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr int kMaxH = 1e4 + 1;
int dp[kMaxH];

int main() {
  int H, N; std::cin >> H >> N;
  std::vector<std::pair<int, int>> P(N);
  std::pair<int, int> max_pair = {0, 0};
  for (int i = 0; i < N; ++i) {
    int A, B; std::cin >> A >> B;
    P[i] = {A, B};
    if (A > max_pair.first) max_pair = P[i];
  }

  dp[0] = 0;
  // Init.
  for (int i = 1; i <= max_pair.first; ++i) {
    dp[i] = max_pair.second;
  }

  for (int i = 1; i <= H; ++i) {
    int n = std::max(0, i-P[0].first);
    dp[i] = dp[n] + P[0].second;
    for (int j = 1; j < P.size(); ++j) {
      int n = std::max(0, i-P[j].first);
      dp[i] = std::min(dp[i], dp[n] + P[j].second);
    }
  }

  std::cout << dp[H] << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    string a;
    int cnt = 0;
    //int a, b, c;
    cin >> a ;
    //*/
    
    if(a.at(0)== 'o'){
        cnt++;
    }
    
    if(a.at(1)== 'o'){
        cnt++;
    }
    
    if(a.at(2)== 'o'){
        cnt++;
    }
    
    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    /*
    if(b >= c - a && c - a >= 0 ){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    */
    
    cout << 700 + 100 * cnt << endl;

    return 0; 
}


Measured memory_bytes: 3504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
bool visited[100005];
const int max_N=1e5+10;
string s;
int buckets[26];
int main(void)
{
  memset(buckets,0,sizeof(buckets));
  cin >> s;
  for(int i=0;i<4;i++)
  {
    buckets[int(s[i]-'A')]++;
  }
  for(int i=0;i<26;i++)
  {
    for(int j=i+1;j<26;j++)
    {
      if(buckets[i]==2 && buckets[j]==2)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL X;
 
LL ans = 0;

void solve(){
    ans += (X/500LL)*1000LL;
    ans += ((X%500)/5LL)*5LL;

}
 
int main(){
    cin >> X;
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 10007;
const ld PI = acosl(-1);

template <typename T>
struct BIT {
    int siz;
    vector<T> bit;

    BIT(int N) : siz(N + 1), bit(siz) {}

    void add(int k, T x) {
        for (int i = k; i < siz; i += (i & -i))
            bit[i] += x;
    }

    T sum(int k) {
        T res(0);
        for (int i = k; i > 0; i -= (i & -i))
            res += bit[i];
        return res;
    }
};

struct dat {
    int l, r, idx;
};

bool operator<(dat &a, dat &b) {
    return a.r < b.r;
}

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

    int N, Q;
    cin >> N >> Q;
    vector<int> c(N);
    for (int i = 0; i < N; ++i) {
        cin >> c[i];
        c[i]--;
    }

    vector<dat> lr(Q);
    vector<int> ans(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lr[i].l >> lr[i].r;
        lr[i].idx = i;
    }
    sort(lr.begin(), lr.end());

    BIT<int> bit(N);

    int idx = 0;
    vector<int> prev(500005, -1);
    for (int i = 0; i < N; ++i) {
        if (~prev[c[i]])
            bit.add(prev[c[i]] + 1, -1);
        bit.add(i + 1, 1);
        prev[c[i]] = i;

        while (idx < Q && lr[idx].r <= i + 1) {
            ans[lr[idx].idx] = bit.sum(lr[idx].r) - bit.sum(lr[idx].l - 1);
            idx++;
        }
    }

    for (auto i : ans)
        cout << i << '\n';

    return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll MOD = 1000000007;

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

    if ( !(n & 1) ) {
        cout << ( n - n / 2 ) * ( n - n / 2 ) << endl;
    }
    else {
        cout << ( n - n / 2 - 1 ) * ( n - n / 2 ) << endl;
    }

    return 0;
}

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++)
typedef long long ll;
typedef pair<int,int> pii;

int V[55];
int main(){
    int n,k;
    cin>>n>>k;

    REP(i,n) cin>>V[i];
    int ans=0;
    int r=min(n,k);

    rep(i,n+1){
        for(int j=0;i+j<=r;j++){
            vector<int> v;
            REP(x,i) v.push_back(V[x]);
            rep(x,j) v.push_back(V[n-x]);
            sort(v.rbegin(),v.rend());
            int k2 = k-i-j;
            while(k2>0 && !v.empty() && v.back()<0){
                v.pop_back();
                k2--;
            }
            int sum=0;
            for (int x:v) sum+=x;
            ans = max(ans,sum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

int main(){
  int A,B,X;
  cin >> A >> B >> X;
  if(X>=A && (A+B)>=X){
    cout << "YES" <<endl;
  }
  else{
    cout << "NO" <<endl;
  }
}


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

int main(void)
{
	int i, j;
	for (i = 1; i <= 9; i++)
		for (j = 1; j <= 9; j++)
			printf("%dx%d=%d\n", i, j, i*j);
	return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 998244353;
const int N = 1e6 + 5;
const int M = 1e3 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, k;

int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) puts("Yes");
    else puts("No");
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


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

int main(int argc, char* argv[])
{
  std::string str;
  std::string::iterator it;
  std::cin >> str;

  int cnt = 0;
  for (it = str.begin(); it != str.end(); it++) {
    if (*it == 'o') {
      cnt++;
    }
  }

  std::cout << 700 + 100 * cnt << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int A = scan.nextInt();
		int B = scan.nextInt();
		System.out.println(N * A < B ? (N * A) : B);
		scan.close();

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


  

int main(){
    ll x;
    cin>>x;
    ll count = 0;
    if(x%500 == 0){
        cout<<(x/500)*1000<<endl;
        return 0;
    }
    ll t = x/500;
    ll leftover = x -= t*500;
    ll wtf = leftover/5;
    cout<<t*1000 + wtf*5<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,w;
int arr[100][2];
long long dp[105][100010];
long long inf;
long long go(int i , int sum){

    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= w ; j++){
            if(arr[i-1][0] <= j)
            dp[i][j] = max(arr[i-1][1] + dp[i-1][j - arr[i-1][0]] , dp[i-1][j]);
            else
            dp[i][j] = dp[i-1][j];
        }
    }
    return dp[n][w];
}
int main(){
    cin >> n >> w;
    inf = 5 * 100000000000000;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < 2 ; j++)
            cin >> arr[i][j];
    long long res = go(0,0);
    if(res > 0)
        cout<<res;
    else
        cout<<0;
}


Measured memory_bytes: 79360
var
	n,k,ans:int64;
	b,next,prev,i,start,goal:Longint;
begin
	read(n,k);
	i:=1;
	prev:=n;
	while(i*i<=n)and(prev>k)do begin
		next:=n div(i+1);
		goal:=(n-k+1)div i;
		if goal>prev then goal:=prev;
		if next<k then next:=k-1;
		start:=next+1;
		if goal>=start then begin
			inc(ans,(n-k+1-start*i)*(goal-start+1));
			dec(ans,(goal-start)*(goal-start+1)div 2*i);
		end;
		inc(ans,(prev-next)*(prev-next+1)div 2*i+next*(prev-next)*i-(prev-next)*k*i);
		prev:=next;
		inc(i);
	end;
	for b:=k+1 to prev do begin
		inc(ans,n div b*(b-k));
		if n mod b>=k then inc(ans,n mod b-k+1);
	end;
	if k=0 then dec(ans,n);
	writeln(ans);
end.

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

#define ll long long int
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define nl '\n'
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[N][4];

void solve()
{
	ll n,p,q,r;
	cin>>n;
	cin>>a[1][1]>>a[1][2]>>a[1][3];
	rep(i,2,n)
	{
		cin>>p>>q>>r;
		a[i][1] = p + max(a[i-1][2],a[i-1][3]) ;
		a[i][2] = q + max(a[i-1][1],a[i-1][3]) ;
		a[i][3] = r + max(a[i-1][2],a[i-1][1]) ; 
	}
	cout<< max(a[n][1], max(a[n][2],a[n][3]));
}



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    //if(t^1)exit(0);
    while(t--)
       solve();
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, a, b;
  cin >> n >> a >> b;
  n %= 12;
  for (int i = 0; i < n; ++i) {
    if (i & 1) {
      b = a + b;
    } else {
      a = a - b;
    }
  }
  cout << a << ' ' << b << '\n';
}



Measured memory_bytes: 3212
import sys
from collections import deque

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

B = deque([])

# print(A, B)

for i in range(N):
	if i%2:
		B.append(A[i])
	else:
		B.appendleft(A[i])
	# print(B)

if not N % 2: B = reversed(B)
print(' '.join(map(str, B)))

Measured memory_bytes: 121172
#include <bits/stdc++.h>
#define M 1000000007
#define U 998244353
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define N 1000005
#define U 998244353
#define bs binary_search
#define endl '\n'
#define FILEIO     freopen("input.txt","r",stdin); freopen("output.txt","w", stdout);
#define PI 3.1415926535
#define INF LLONG_MAX-5
using namespace std;
int po(int n, int exp){
    int prod=1;
    rep(i,0,exp)
        prod*=n;
    return prod;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n;
        cin>>n;
        int x=0;
        rep(i,0,n){
            int t;
            cin>>t;
            x^=t;
        }
        if(x==0){
            cout<<"Yes";
        }
        else cout<<"No";
    }   
}   

Measured memory_bytes: 256
#include <iostream>                                                      
#include <cstdio>                                                        
#include <vector>                                                        
#include <algorithm>                                                     
using namespace std;                                                     
                                                                         
int main() {                                                             
  int n;                                                                 
  cin >> n;                                                              
  vector<int> a;                                                         
  while (n--) {                                                          
    int x;                                                               
    cin >> x;                                                            
    a.push_back(x);                                                      
  }                                                                      
  reverse(a.begin(),a.end());                                            
  for (int i=0; i<a.size(); i++) {                                       
    cout << (i==0?"":" ") << a[i] << flush;                              
  }                                                                      
  printf("\n");                                                          
  return 0;                                                              
}                                                                        
                       

Measured memory_bytes: 3060
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b, c, d = M()
if a+b > c+d:
    print('Left')
elif a+b == c+d:
    print('Balanced')
else:
    print('Right')

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

int main(void) {
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  cout << ((count(v.begin(), v.end(), 5) == 2 &&
            count(v.begin(), v.end(), 7) == 1)
               ? "YES"
               : "NO")
       << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String tmp="";
    for(int i=1;i<S.length();i++){
      tmp=S.substring(0,S.length()-2*i);
      if(isEvenstr(tmp)){
        System.out.println(tmp.length());
        return;
      }
    }
    
  }
  public static boolean isEvenstr(String tmp){
    if(tmp.substring(0,tmp.length()/2).equals(tmp.substring(tmp.length()/2,tmp.length()))){
      return true;
    }
    return false;
  }
       
                                              
  

  
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	while(1)
	{
		cin >> a >> b;
		if ( a == b && a == 0 )break;
		else if ( a <= b ) cout << a << " " << b << endl;
		else if ( a >= b ) cout << b << " " << a << endl;
	} 
	return 0;
}

Measured memory_bytes: 1160
$n=<>;$_=<>;<>;chomp;$m=1e9+7;
s/(.)\1/1/g;
s/[a-zA-Z]/0/g;
@s=split//,$_;
$p=shift(@s);
$i=$p?6:3;
for(@s){
    my$k=1;
    if($p<1){   
        $k=2
    }elsif($_){
        $k=3   
    }
    $i=($i*$k)%$m;
    $p=$_;
}
print$i

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

main() {
    string S,T; cin >> S >> T;
    if(S.size()>T.size())
    cout << "GREATER" << endl;
    else if(S.size()<T.size())
    cout << "LESS" << endl;
    else if(S>T)
    cout << "GREATER" << endl;
    else if(T>S)
    cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
     

    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int to;
	T cost;
	Edge() {}
	Edge(int to, T cost = 1) : to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<vector<Edge<int>>> edges(N);
	for (int i = 0; i < N - 1; i++) {
		int u, v, len;
		cin >> u >> v >> len;
		u--, v--;
		edges[u].emplace_back(v, len);
		edges[v].emplace_back(u, len);
	}

	vector<int> used(N), ans(N);
	auto dfs = [&](auto && f, int d) -> void {
		
		for (const auto &e : edges[d]) {
			if (!used[e.to]) {
				ans[e.to] = ans[d] ^ (e.cost & 1);
				used[e.to] = 1;
				f(f, e.to);
			}
		}

	};

	dfs(dfs, 0);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
#define int long long
using namespace std;


int n,p[100],cnt,ans=1ll<<60;


int exgcd(int a,int b,int &x,int &y)
{
	if(!b)	{x=1;y=10;return a;}
	int d=exgcd(b,a%b,x,y);
	int z=y;y=x-a/b*y;x=z;
	return d;
}

void dfs(int pos,int k1,int k2)
{
	if(pos==cnt+1)
	{
		int x,y;
		exgcd(k1,k2,x,y);
//		cout<<x*k1<<' '<<y*k2<<endl;
//		cout<<x<<' '<<y<<' '<<k1<<' '<<k2<<endl;
//		if(x<0)	return;
		x=(x%k2+k2)%k2;
//		cout<<x<<endl;
		if(x==0)	x=k2;
		if(x==1&&k1==1)	return; 
		ans=min(ans,x*k1-1);
		return;
	}
	dfs(pos+1,k1*p[pos],k2);
	dfs(pos+1,k1,k2*p[pos]);
}


signed main()
{
	cin>>n;
	int u=n*2;
	for(int i=2;i<=min(n,40000000ll);i++)
	{
		int now=1;
		while(u%i==0)
		{
			now*=i;
			u/=i;
		}
		if(now!=1)	p[++cnt]=now;	
	}
	if(u!=1)	p[++cnt]=u;
	dfs(1,1,1);		//µ±Ç°µÄµÚÒ»¸öÖÊÊý  µ±Ç°µÄµÚ¶þ¸öÖÊÊý 
	cout<<ans<<endl;
} 

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int sum=0;
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++){
    sum+=(s[i]-'0');
  }
  if(sum%9==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3732
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int a,b,c;
char s[2333];
int main()
{
	scanf("%d%d",&a,&b);
	printf("%d\n",(a-1)*(b-1));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	bool single = true; 
	bool different = false; 
	string S; long long int K; 
	cin >> S >> K; 
	int L = S.size(); 
	if(S.at(0) != S.at(L - 1)){
		different = true;
	}
	for(int i = 0; i < L - 1; i++){
		if(S.at(i) != S.at(i+1)) single = false; 
	}
	if(single){
		long long int total = K * L; 
		cout << total / 2 << endl; return 0; 
	}
	vector<int> divide = {}; 
	int current = 1;
	for(int i = 0; i < L-1; i++){
		if(S.at(i) == S.at(i+1)) current ++; 
		else{
			divide.push_back(current); current = 1; 
		}
	}
	divide.push_back(current); 
	if(different){
		int tmp = 0; 
		for(int i = 0; i < divide.size(); i++){
			tmp += divide.at(i) / 2; 
		}
		cout << K * tmp << endl; 
	}
	else{
		long long int cut = 0; 
		long long int others = 0; 
		cut += (long long) divide.at(0) / 2 + divide.at(divide.size()-1)/2;
		cut += (divide.at(0) + divide.at(divide.size()-1)) / 2 * (K - 1); 
		for(int i = 1; i < divide.size() - 1; i++){
			others += (long long) divide.at(i) / 2; 
		}
		others *= K;  
		cout << cut + others << endl; 
	}
}

Measured memory_bytes: 256
N,M=map(int,input().split())
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switches in enumerate(L):
    cnt=0
    for s in switches:
      if i>>(s-1)&1:cnt+=1
    if cnt%2==P[j]:lit[j]=1
  if all(lit):ans+=1 
print(ans)

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

// {
#define debug(var)  do{ std::cout << #var << " : "; view(var); }while(0)
using ll = long long;
using ld = long double;
inline int num (const std::string& S, int idx) noexcept { return S.at(idx) - '0'; }
inline int ctoi(char c) noexcept { return c - '0'; }
inline bool isNumber(char c) noexcept { return ('0'<c && c<'9'? true : false); }
inline int safeCtoi(char c) { if(isNumber(c)) { return ctoi(c); } else { throw 1; } }
inline char itoc(int i) noexcept { return i + '0'; }
inline unsigned int bitMask(int i) noexcept { return (1 << i); }
inline bool isTrue(unsigned int bit, int i) noexcept { return bit & bitMask(i); }
inline bool isEven(int num) noexcept { return !num%2; }
inline bool isOdd(int num) noexcept { return num%2; }
template<typename T> inline short sgn(T num) noexcept { return (num==0? 0 : (num>0? 1 : -1) ); }
template<typename T> inline bool isZero(T num) noexcept { return (num==0? true : false); }
template<typename T> inline bool isPositive(T num) noexcept { return (num>0? true : false); }
template<typename T> inline bool isNegative(T num) noexcept { return (num<0? true : false); }
template<typename T> void view(T e) noexcept { cout << e; }
template<typename T> void view(std::vector<T> v) noexcept { for(const auto& e : v) cout << e << " "; }
template<typename T> void view(std::vector<std::vector<T>> vv) noexcept { for(const auto& v : vv) view(v); }
//}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;
	cin >> str;
	cout << str.substr(0,3) << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <unordered_map>

int main(){
	int t;
	std::cin >> t;
	std::unordered_map<std::string, int> map;
	map["AC"] = 0;
	map["WA"] = 0;
	map["TLE"] = 0;
	map["RE"] = 0;
	for(int _i = 0; _i < t; ++_i){
		std::string s;
		std::cin >> s;

		map[s] += 1;
	}

	std::cout << "AC x " << map["AC"] << "\n";
	std::cout << "WA x " << map["WA"] << "\n";
	std::cout << "TLE x " << map["TLE"] << "\n";
	std::cout << "RE x " << map["RE"] << "\n";
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair



int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int n, m, d;
	scanf("%d%d%d", &n, &m, &d);
	double ans = (double)(m - 1) / n / n;
	if (d == 0)
		ans *= n;
	else
		ans *= 2 * (n - d);
	printf("%.15lf\n", ans);

	return 0;
}


Measured memory_bytes: 256
/*
高速フーリエ変換(を使った多項式演算)
c_i=sum_{j=0}^{i} a_j*b_{i-j} mod 998244353を計算する。
これはf(x)=sum_i^N a_i*x^iとg(x)=sum_j^M b_j*x^jの積の係数にあたる
本来はO(N^2)かかるが、FFTを経由することでO(NlogM)に抑えられる
畳み込みでは998244353がmodとしてよく使われるらしい
*/

#pragma region Template

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(vec) (vec).begin(), (vec).end()
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define SZ(x) ((int)(x).size())
#define m0(x) memset(x, 0, sizeof(x))
#define m1(x) memset(x, 0xff, sizeof(x)) // init by -1
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, begin, end) for (int i = begin; i < end; i++)
#define endl '\n'
#define debug(x) cout << "debug: " << x << endl
#define MOD 1e9 + 7
#define INF 1e9
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
void inpl(const int n, vl &A)
{
    rep(i, n)
    {
        cin >> A[i];
    }
}
void inpl2(const int n, vvl &A)
{
    rep(i, n)
    {
        ll tmp;
        while (cin >> tmp)
        {
            A[i].push_back(tmp);
        }
    }
}
void printvec(const int n, vl &a, string sep = "\n")
{
    rep(i, n)
    {
        cout << a[i] << sep;
    }
}
#pragma endregion

void solve()
{
    ll n, m;
    cin >> n >> m;
    vl av, bv;
    rep(i, n)
    {
        ll a;
        cin >> a;
        av.push_back(a);
    }
    rep(i, m)
    {
        ll b;
        cin >> b;
        bv.push_back(b);
    }
    vl ans = convolution(av, bv);
    printvec(ans.size(), ans, " ");
    cout << endl;
}

signed main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


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

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

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  if(a % MOD < 0) return MOD + (a % MOD);
  return a % MOD;
}

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


int main(){
  string s,t; cin >> s >> t;
  reverse(all(s));
  
  if(s == t) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
}

Measured memory_bytes: 3560
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;

int main() {
  INCANT;
  cin >> N;
  ll sm=0;
  rep(i, N) {
    if ((i+1)%3!=0 && (i+1)%5!=0) sm+=i+1;
  }
  cout << sm << "\n";
  return 0;
}


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

int n;
vector<vector<int>> g;
vector<double> ev, ev2;

double dfs(int i)
{
  if (ev[i] != -1)
    return ev[i];
  double s = g[i].size();
  for (int nxt : g[i])
    s += dfs(nxt);
  ev[i] = s / g[i].size();
  return ev[i];
}

double dfs2(int i, int cls)
{
  if (ev2[i] != -1)
    return ev2[i];
  if (i == cls)
  {
    int c;
    double emx = -1;
    for (int nxt : g[i])
      if (ev[nxt] > emx)
      {
        emx = ev[nxt];
        c = nxt;
      }
    double s = g[i].size() - 1;
    for (int nxt : g[i])
      if (nxt != c)
        s += ev[nxt];
    ev2[i] = s / (g[i].size() - 1);
    return ev2[i];
  }
  double s = g[i].size();
  for (int nxt : g[i])
    s += dfs2(nxt, cls);
  ev2[i] = s / g[i].size();
  return ev2[i];
}

int main()
{
  int m;
  cin >> n >> m;
  g.resize(n - 1);
  rep(i, m)
  {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    g[s].push_back(t);
  }
  ev.resize(n);
  fill(ev.begin(), ev.end(), -1);
  ev[n-1] = 0;
  double ans = dfs(0);
  ev2.resize(n);
  rep(i, n - 1)
  {
    if (g[i].size() == 1)
      continue;
    fill(ev2.begin(), ev2.end(), -1);
    ev2[n-1] = 0;
    ans = min(ans, dfs2(0, i));
  }
  printf("%.7lf\n", ans);
  return 0;
}

Measured memory_bytes: 1408
import sys;input=sys.stdin.readline
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
def div(a, b):
    return mul(a, modinv(b))
def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
NNN = (2*10**5)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, = map(int, input().split())
d = [list() for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

vs = set([1])
stack = [1]
vs_bfs = list()
parents = [0] * (N+1)
while stack:
    v = stack.pop()
    vs_bfs.append(v)
    for u in d[v]:
        if u in vs:
            continue
        parents[u] = v
        vs.add(u)
        stack.append(u)

dp1 = [0 for _ in range(N+1)]
sss = [0 for _ in range(N+1)]
for v in vs_bfs[::-1]:
    t = 1
    ts = []
    for u in d[v]:
        if u == parents[v]:
            continue
        t = mul(dp1[u], t)
        ts.append(sss[u])
    st = sum(ts)
    sss[v] = st + 1
    for tt in ts:
        t = mul(cmb(st, tt, mod), t)
        st -= tt
    dp1[v] = t

for v in vs_bfs:
    if v == 1:
        continue
    p = parents[v]
    dp1[v] = mul(
            div(dp1[p], cmb(N-1, sss[v], mod)),
            cmb(N-1, N-sss[v], mod)
            )

for x in dp1[1:]:
    print(x)


Measured memory_bytes: 124036
#include<bits/stdc++.h>
using namespace std;
const int N=101;
struct S
{
	int x,i;
	string s;
};
bool C(S x,S y)
{
	if(x.s!=y.s)
		return x.s<y.s;
	if(x.x!=y.x)
		return x.x>y.x;
	return x.i<y.i;
}
int n;
S w[N];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>w[i].s>>w[i].x,w[i].i=i;
	sort(w+1,w+n+1,C);
	for(int i=1;i<=n;i++)
		cout<<w[i].i<<'\n'; 
	return 0;
}

Measured memory_bytes: 256
k=int(input())
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[k-1])

Measured memory_bytes: 9140
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, M;
int like[30];

void init()
{
}

void solve()
{
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    REP(i, N){
        int k;
        cin >> k;
        REP(j, k){
            int v;
            cin >> v;
            like[--v]++;
        }
    }
    int ans = 0;
    REP(i, M){
        if(like[i] == N) ans++;
    }
    cout << ans << endl;
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int count=0;
	int n, x;
	while (1)
	{
		 count =0 ;
		cin >> n >> x;
		if (n == 0 && x == 0){ break; }
		for (int i = 1; i <= n - 2; i++)
		{

			for (int j = i + 1; j <= n - 1; j++)
			{
				for (int k = j + 1; k <= n; k++)
				{

					if (i + j + k == x)count++;


					
				}
			}
		}
		cout << count << endl;
	}

	
	return 0;
}


Measured memory_bytes: 3076
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n%2==1)
		cout<<n/2*(n/2+1);
	else
		cout<<n*n/4;
	return 0;
}

Measured memory_bytes: 764
s=input()
if s=='SUN':
    ans = 7
elif s =='MON':
    ans = 6
elif s =='TUE':
    ans = 5
elif s =='WED':
    ans = 4
elif s =='THU':
    ans = 3
elif s =='FRI':
    ans = 2
elif s =='SAT':
    ans = 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long n,a[222222];
vector<long long> v;
map<int,int> mp;
long long maxn=0;
int powerup(int n)
{
	int s=1;
	while(true)
	{
		s*=2;
		if(s>n)
		  break;
	}
	return s;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
		if(a[i]>maxn)
		  maxn=a[i];
    }
    long long s=1,ans=0;
	sort(a,a+n);
	for(int i=n-1;i>=0;i--)
	{
		if(mp[a[i]]<=0)continue;
		int x=a[i];
		int y=powerup(x)-x;
		if(mp[y])
		{
			mp[x]--;
			mp[y]--;
			if(mp[y]>=0)
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 20608
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] p = new int[n];

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

		int si = 0 ;
		for ( int i=0; i<k; i++ ) {
			si = si + p[i] ;
		}
		int u = si ;

		for ( int i=0; i<n-k; i++ ) {
			int t = u - p[i] + p[i+k] ;
			si = Math.max(si,t) ;
			u = t;
		}
		float s = (float)si/2f ;
		System.out.println(s);
	}
}

Measured memory_bytes: 83872
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<char> v;
    int index = 0;
    if(n == 0){
        cout << '0' << endl;
        return 0;
    }
    if (n == 1){
        cout << '1' << endl;
        return 0;
    }
    while(true){
        int mod = n%-2;
        int ss = n/-2;
        if(mod != 1 && mod != 0){
            ss++;
            mod = -mod;
        }
        // cout << ss << " " << mod << endl;
        v.push_back(mod==1?'1':'0');
        index++;
        n = ss;
        if (ss == 1){
            v.push_back('1');
            break;
        }
    }
    // cout << index << endl;
    for(int i = index; i >= 0; i--){
        cout << v[i];
    }
    cout << endl;
    return 0;
}


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


#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
#define MOD 1000000007
int N;
int T[101010], A[101010];
pair<int, int> TT[101010];
pair<int, int> AA[101010];
//-----------------------------------------------------------------
ll solve() {
	int m = 0;
	rep(i, 0, N) {
		if (T[i] < m) return 0;
		else if (T[i] == m) {
			TT[i].first = 1;
			TT[i].second = m;
		} else {
			TT[i].first = T[i];
			TT[i].second = T[i];
		}
		m = T[i];
	}

	m = 0;
	rrep(i, N - 1, 0) {
		if (A[i] < m) return 0;
		else if (A[i] == m) {
			AA[i].first = 1;
			AA[i].second = m;
		}
		else {
			AA[i].first = A[i];
			AA[i].second = A[i];
		}
		m = A[i];
	}

	ll ans = 1;
	rep(i, 0, N) {
		int l = max(TT[i].first, AA[i].first);
		int r = min(TT[i].second, AA[i].second);
		if (r < l) return 0;
		ans = (ans * (r - l + 1)) % MOD;
	}
	return ans;
}
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d", &T[i]);
	rep(i, 0, N) scanf("%d", &A[i]);

	cout << solve() << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k,c=0;
  cin >> n >> k;
  
  for(int i=0;i<n;i++){
    int x;
    cin >>x;
    if(x>=k) c++;
  }
  
  cout << c << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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;
}

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

    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    REP(i, n) { cin >> h.at(i); }

    ll dp[100010];
    memset(dp, INF, sizeof(dp));
    dp[0] = 0LL;
    FOR(i, 1, n) {
        FOR(j, 1, k + 1) {
            if (i - j >= 0) {
                chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            } else {
                break;
            }
        }
    }

    cout << dp[n - 1] << endl;

    return 0;
}


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

struct po{
  int t,s,d;
};
 
int main() {

  while(1) {
    int n,m;
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    po ls[20000];
    for(int i=0;i<m;i++) {
      cin >> ls[i].t >> ls[i].s >> ls[i].d;
    }

    bool sta[20001] = {};
    sta[1] = 1;
    
    for(int i=0;i<m;i++) 
      for(int j=m-1;j>i;j--) 
	if(ls[j].t < ls[j-1].t){
	  po tmp = ls[j];
	  ls[j] = ls[j-1];
	  ls[j-1] = tmp;
	}

     
    for(int i=0;i<m;i++){
      if(sta[ls[i].s] == 1) {
	sta[ls[i].d] = 1;
      }
    }
    int ans = 0;
    for(int i=1;i<=n;i++) 
      if(sta[i] == 1) ans++;

    cout << ans <<endl;
  }
    
}

Measured memory_bytes: 1420
import sys
input = sys.stdin.readline

n,k=map(int,input().split())
d=list(input().split())
for _ in range(n,100000):
    string=str(_)
    check=0
    for i in string:
        if i in d:
            check=1
    if check==0:
        print(_)
        break
    

Measured memory_bytes: 2940
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

lis = [0]*N
for a in As:
    lis[a-1]+= 1

for l in lis:
    print(l)

Measured memory_bytes: 99224
// 2011/07/18 Tazoe

#include <iostream>
#include <string>
using namespace std;

bool DFS(int G[26][26], int n, int cnt, int ini)
{
	if(cnt==n)
		return true;

	for(int j=0; j<26; j++)
		if(G[ini][j]!=0){
			G[ini][j]--;
			if(DFS(G, n, cnt+1, j))
				return true;
			G[ini][j]++;
		}

	return false;
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int G[26][26];
		for(int i=0; i<26; i++)
			for(int j=0; j<26; j++)
				G[i][j] = 0;

		for(int i=0; i<n; i++){
			string str;
			cin >> str;
			G[str[0]-'a'][str[str.size()-1]-'a']++;
		}

		bool flg = true;
		for(int i=0; i<26; i++){
			int bgn = 0;
			int end = 0;
			for(int j=0; j<26; j++){
				bgn += G[i][j];
				end += G[j][i];
			}
			if(bgn!=end){
				flg = false;
				break;
			}
		}
		if(!flg){
			cout << "NG" << endl;
			continue;
		}

		int ini = 0;
		flg = false;
		for(; ini<26; ini++){
			for(int j=0; j<26; j++){
				if(G[ini][j]!=0){
					flg = true;
					break;
				}
			}
			if(flg)
				break;
		}

		if(DFS(G, n, 0, ini))
			cout << "OK" << endl;
		else
			cout << "NG" << endl;
	}

	return 0;
}

Measured memory_bytes: 916
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b = I()
for i in range(2):
    if a >= b:
        ans += a
        a -= 1
    else:
        ans += b
        b -= 1
print(ans)


Measured memory_bytes: 10148
#include <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+ (pll a, pll b){ return {a.x + b.x, a.y + b.y}; }

ll rand0m() {
    return (ull(rand()) << 15ull | ull(rand()));
}                   //[0 ... n)
ll rand0m(ll x) {
    return rand0m() % x;
}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {
    return rand0m(maxx - minn + 1) + minn;
}   //[minn ... maxx]

const ll MAXN = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 2e9 + 1000;

ll n, m;
ll d[MAXN];
ll need[MAXN];
vector<ll> g[MAXN];

void solve(){
    cin >> n >> m;
    fori(i, m){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        ++need[b];
    }
    //forI(i, n) d[i] = 1;
    set<pll> need_queue;
    forI(i, n) need_queue.insert({need[i], i});
    while(!need_queue.empty()){
        ll v = need_queue.begin()->ss;
        need_queue.erase(need_queue.begin());
        for(ll to: g[v]){
            need_queue.erase({need[to], to});
            need_queue.insert({--need[to], to});
            d[to] = max(d[to], d[v] + 1);
        }
    }
    ll c = 0;
    forI(i, n) c = max(c, d[i]);
    cout << c;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //stress();
    solve();
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
  
int main(){
	long A,B,K;
  	scanf("%ld %ld %ld",&A,&B,&K);
  	printf("%ld %ld\n",max((long)0,A-K),max((long)0,B-max((long)0,K-A)));
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000
int main(){
 unsigned short *A,*B;
 int C[VMAX+1];
 int n,i,j;
 scanf("%d",&n);
 A=malloc(sizeof(short)*n+1);
 B=malloc(sizeof(short)*n+1);
 for(i=0;i<=VMAX;i++)C[i]=0;
 for(i=0;i<n;i++){
  scanf("%hu",&A[i+1]);
  C[A[i+1]]++;
 }
 for(i=1;i<=VMAX;i++)C[i]=C[i]+C[i-1];
 for(j=1;j<=n;j++){
  B[C[A[j]]]=A[j];
  C[A[j]]--;
 }
 for(i=1;i<=n;i++){
  if(i>1)printf(" ");
  printf("%d",B[i]);
 }
 printf("\n");
 return 0;
}


Measured memory_bytes: 9608
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>

using namespace std;

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

  string S;
  cin >> S;

  if (S.size() <= K) {
    cout << S << endl;
  } else {
    cout << S.substr(0,K) << "..." << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
N, M = gets.split(' ').map(&:to_i)
require 'pp'
def debug obj
  PP.pp obj, STDERR
end

debug [N,M]
@nodes = {} # key node番号, value keyのnodeから生えてるedgeの向き先配列
@result = 0
@visits = {}
@ords = []
@lows = []
@step = 0

M.times do
  a, b = gets.split(' ').map(&:to_i)
  @nodes[a] ||= []
  @nodes[b] ||= []
  @nodes[a].push(b)
  @nodes[b].push(a) 
end

def dfs node,parent=-1
debug @lows
  @visits[node] = true
  @ords[node] = @step
  @lows[node] = @step
  @nodes[node].each do |target|
    if target == parent
      next
    end
    if @visits[target]
      if @ords[target] < @lows[node]
        @lows[node] = @ords[target]
      end
    else
      @step += 1
      dfs(target, node)
      if @lows[target] < @lows[node]
        @lows[node] = @lows[target]
      end
      if @ords[node] < @lows[target]
        @result += 1
      end
    end
  end
end

dfs(1)
debug @nodes
debug @ords
debug @lows
puts @result

Measured memory_bytes: 2556