akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String ans = "bon";
        switch (N % 10) {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                ans = "hon";
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                ans = "pon";
                break;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35760
// Try Educational DP Contest
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
	std::io::Read::read_to_string(
		&mut std::io::stdin(),
		&mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
	let mut get = || stdin.next().unwrap();
	macro_rules! get {
		($t:ty) => (get().parse::<$t>().unwrap());
		() => (get!(i64));
	}
	
	let n = get!(usize);
	let mut last_a = 0;
	let mut last_b = 0;
	let mut last_c = 0;
	use std::cmp::max;
	for _ in 0..n {
		let a = get!();
		let b = get!();
		let c = get!();
		let new_last_a = max(last_a,
			max(last_b, last_c) + a);
		let new_last_b = max(last_b,
			max(last_a, last_c) + b);
		let new_last_c = max(last_c,
			max(last_a, last_b) + c);
		last_a = new_last_a;
		last_b = new_last_b;
		last_c = new_last_c;
	}
	let ans = max(last_a, max(last_b, last_c));
	println!("{}", ans);
}

Measured memory_bytes: 6396
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $ans=0;
  for($i=1;$i<=$n;$i++){
    $div=intdiv($n,$i);
    if($n%$i==0){
      $div--;
    }
    $ans+=$div;
  }

  echo $ans;

Measured memory_bytes: 16276
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  char n[4];
  int count=0;
  cin>>n;
  if(n[0]=='2')
    count++;
  if(n[1]=='2')
    count++;
  if(n[2]=='2')
    count++;
  if(n[3]=='2'){
    count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    double sum=0;
    int i;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        sum+=(double)1/tmp;
    }
    printf("%.10lf\n", 1/sum);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll x,k,d;
  cin >> x >> k >> d;
  ll cnt = min(k, abs(x)/d);
  k -= cnt;
  if(x>0) x -= cnt*d;
  else x += cnt*d;
  ll ans = abs(x);
  if(k&1){
    if(x>0) ans = abs(x-d);
    else ans = abs(x+d);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main{
	public static void main(String[] args){
		String input = new Scanner(System.in).nextLine();
		String[] num = input.split("\\s");
		int a = Integer.parseInt(num[0]);
		int b = Integer.parseInt(num[1]);
		if( a < b){
			System.out.println("a < b");
		} else if( a > b){
			System.out.println("a > b");
		} else{
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26096
n, m = map(int, input().split())
lis = list(map(int, input().split()))
su = []

for i in range(n):
    su.append(lis[i] - lis[0])

res = 10**9
for i in range(n - m + 1):
    res = min(res, su[i + m - 1] - su[i] + min(abs(lis[i]), abs(lis[i + m - 1])))
print(res)


Measured memory_bytes: 14252
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 2 == 1) {
                cnt++;
            }
        }
        double ans = (double)cnt / (double)n;
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	private static String YES = "YES";
	private static String NO_ = "NO";

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int[] isides = new int[3];
		String[] ssides = new String[3];

		while ((line = br.readLine()) != null) {
			try {
				ssides = line.split(" ");
				isides[0] = Integer.parseInt(ssides[0]);
				isides[1] = Integer.parseInt(ssides[1]);
				isides[2] = Integer.parseInt(ssides[2]);
				Arrays.sort(isides);
				if (Math.pow(isides[2], 2) == (Math.pow(isides[0], 2) + (Math
						.pow(isides[1], 2)))) {
					System.out.println(YES);
				} else {
					System.out.println(NO_);
				}
			} catch (ArrayIndexOutOfBoundsException e) {
				continue;
			}
		}
	}
}

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

int main()
{
    int n, a, b, single_class, good_class;
    good_class = 0;
    cin >> n >> a >> b;
    for (int index = 0; index < n; index += 1)
    {
        cin >> single_class;
        if (single_class < a || single_class >= b)
        {
            good_class +=1;
        }
    }
    cout << good_class<<endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define ZERO(a) memset(a,0,sizeof(a))

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ld dp[310][310][310];
ll n;

ld rec(ll i, ll j, ll k){
  if(i<0 || j<0 || k<0)
    return 0;
  if(i>n || j>n || k>n)
    return 0;

  if(dp[i][j][k]!=-1)
    return dp[i][j][k];
  if(i==0 && j==0 && k==0)
    return dp[i][j][k]=0;

  ld res = 1*(n/ld(i+j+k));
  res += rec(i-1,j,k)*i/ld(i+j+k);
  res += rec(i+1,j-1,k)*j/ld(i+j+k);
  res += rec(i,j+1,k-1)*k/ld(i+j+k);

  return dp[i][j][k] = res;
}


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

  cin>>n;
  ll a;
  vll v(3);
  REP(i,n){
    cin>>a;
    a--;
    v[a]++;
  }
  REP(i,310)REP(j,310)REP(k,310)dp[i][j][k]=-1;

  ld ans = rec(v[0],v[1],v[2]);
  cout<<Decimal;
  cout<<ans<<endl;

}




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

resident = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for i in range(n):
    lst = list(map(int, input().split()))
    resident[lst[0] - 1][lst[1] - 1][lst[2] - 1] += lst[3]

for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" {}".format(resident[i][j][k]), end="")
        print()
    if i < 3:
        print("####################")



Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int A[100001], B[100001], C[100001];
  cin >> A[0] >> B[0] >> C[0];
  int64_t ans = 0;
  for(int i=0;i<100000;i++){
    if(A[i] % 2 == 1 || B[i] % 2 == 1 || C[i] % 2 == 1){
      break;
    } 
    else{
      A[i+1] = B[i]/2 + C[i]/2;
      B[i+1] = C[i]/2 + A[i]/2;
      C[i+1] = A[i]/2 + B[i]/2;
      ans++;
    }
  }
  if(ans == 100000) ans = -1;
  cout << ans << endl;
}



Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;


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


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

int main() {
  ll N, K;
  cin >> N >> K;

  struct Sushi {
    ll t, d;
  };
  vector<Sushi> sushis(N);
  for (ll i = 0; i < N; i++) {
    cin >> sushis[i].t >> sushis[i].d;
    sushis[i].t--;
  }

  sort(sushis.begin(), sushis.end(),
       [&](Sushi& lhs, Sushi& rhs) { return lhs.d > rhs.d; });

  vector<bool> appear(N, false);
  priority_queue<ll, vector<ll>, greater<ll>> pq;
  ll base = 0;
  ll type_num = 0;
  for (ll i = 0; i < K; i++) {
    base += sushis[i].d;
    if (appear[sushis[i].t]) {
      pq.push(sushis[i].d);
    } else {
      appear[sushis[i].t] = true;
      type_num++;
    }
  }
  ll ans = base + type_num * type_num;

  for (ll i = K; i < N && !pq.empty(); i++) {
    if (appear[sushis[i].t]) {
      continue;
    }

    ll t = pq.top();
    pq.pop();
    base += sushis[i].d - t;
    type_num++;
    ans = max(ans, base + type_num * type_num);
    appear[sushis[i].t] = true;
  }

  cout << ans << endl;
}


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

typedef pair<int, int> pint;

int N;
vector<vector<pint> > g;

vector<bool> used;
vector<int> pos;
bool dfs(const int cur) {
  for(int i = 0; i < g[cur].size(); i++) {
    int nxt = g[cur][i].first;
    int npos = (int)(g[cur][i].second) + pos[cur];
    if(used[nxt]) {
      if(pos[nxt] != npos) return false;
    } else {
      used[nxt] = true;
      pos[nxt] = npos;
      dfs(nxt);
    }
  }
  return true;
}

bool solve() {
  int M; cin>>N>>M;
  g = vector<vector<pint> > (N);
  vector<int>l(M), r(M), d(M);
  for(int i = 0; i < M; i++) {
    int L, R, D; cin>>L>>R>>D;
    L--; R--;
    g[L].push_back(make_pair(R, D));
    g[R].push_back(make_pair(L, -D));
    l[i] = L; r[i] = R;	d[i] = D;
  }
  used = vector<bool>(N, false);
  pos = vector<int>(N, 0);
  for(int i = 0; i < N; i++) {
    if(used[i] == false) {
      used[i] = true;
      bool tmp = dfs(i);
      if(tmp == false) return false;
    }
  }
  for(int i = 0; i < M;	i++) {
    if(d[i] != pos[r[i]] - pos[l[i]]) return false;
  }
  return true;
}

int main() {
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 14336
#include<stdio.h>
int main(){
  int a[100],b[101],r[102],c[101],t,i,j,n,m;
  for(i=0;scanf("%d,%d",&n,&m),n||m;i++){
    r[i]=i;
    a[i]=n;
    b[i]=m;
    for(j=i;j;j--){
      if(b[r[j-1]]<b[r[j]]){
	t=r[j-1];
	r[j-1]=r[j];
	r[j]=t;
      }
    }
  }
  c[r[0]]=t=1;
  for(j=1;j<i;j++){
    if(b[r[j-1]]-b[r[j]])t++;
    c[r[j]]=t;
  }
  while(scanf("%d",&n)!=EOF){
    for(j=0;a[j]-n;j++);
    printf("%d\n",c[j]);
    }//*/
  return 0;
}
    

Measured memory_bytes: 600
import sys
a, b = map(int, input().split())
paint = []
paint.append("".join(["."]*(b+2)))
for _ in range(a):
    t = input()
    s = "".join([".", t, "."])
    paint.append(s)
paint.append("".join(["."]*(b+2)))
for i in range(a):
    for j in range(b):
       if paint[i][j] == "#":
           if paint[i+1][j] == "." and paint[i-1][j] == "." and paint[i][j+1] == "." and paint[i][j-1] == ".":
                print("No")
                sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  long long ans = 0;
  long long current = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (current > v[i]) {
      cout << -1 << endl;
      return 0;
    }
    if (current != v[i]) {
      if (v[i] > i) {
        cout << -1 << endl;
        return 0;
      }
      ans += v[i];
      current = v[i];
    }
    if (current > 0)
      current--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 100100
using namespace std;
int n,m,pos=1;
struct QAQ{
    int l,r,sum,add;
}t[N<<2];
struct QWQ{
	int l,r;
}a[N*3];
inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch>'9'||ch<'0'){
        if(ch=='-') w=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0'){
        s=(s<<3)+(s<<1)+(ch^48);
        ch=getchar();
    }
    return s*w;
}
inline int ls(int p){return p<<1;}
inline int rs(int p){return p<<1|1;}
inline void push_up(int p){t[p].sum=t[ls(p)].sum+t[rs(p)].sum;}
inline void spread(int p){
    if(t[p].add){
        t[ls(p)].sum+=t[p].add*(t[ls(p)].r-t[ls(p)].l+1);
        t[rs(p)].sum+=t[p].add*(t[rs(p)].r-t[rs(p)].l+1);
        t[ls(p)].add+=t[p].add;
        t[rs(p)].add+=t[p].add;
        t[p].add=0;
    }
}
void build(int p,int l,int r){
    t[p].l=l;t[p].r=r;
    if(l==r) return;
    int mid=(t[p].l+t[p].r)>>1;
    build(ls(p),l,mid);
    build(rs(p),mid+1,r);
}
void change(int p,int l,int r,int x){
    if(l<=t[p].l&&t[p].r<=r){
        t[p].add+=x;
        t[p].sum+=(t[p].r-t[p].l+1)*x;
        return;
    }
    spread(p);
    int mid=(t[p].l+t[p].r)>>1;
    if(l<=mid)change(ls(p),l,r,x);
    if(r>mid) change(rs(p),l,r,x);
    push_up(p);
}
int ask(int p,int l,int r){
    if(l<=t[p].l&&t[p].r<=r){
        return t[p].sum;
    }
    spread(p);
    int mid=(t[p].l+t[p].r)>>1,ans=0;
    if(l<=mid)ans+=ask(ls(p),l,r);
    if(r>mid) ans+=ask(rs(p),l,r);
    return ans;
}
inline bool cmp(QWQ x,QWQ y){
	return x.r-x.l<y.r-y.l;
}
int main(){
    n=read();m=read();
    build(1,1,m);
	for(register int i=1;i<=n;i++){
		a[i].l=read();
		a[i].r=read();
	}
	sort(a+1,a+n+1,cmp);
	for(register int i=1;i<=m;i++){
		while(a[pos].r-a[pos].l<i&&pos<=n){
			change(1,a[pos].l,a[pos].r,1);
			pos++;
		}
		int ans=n-pos+1;
		for(int j=i;j<=m;j+=i){
			ans+=ask(1,j,j);
		}
		printf("%d\n",ans);
	}
    return 0;
}


Measured memory_bytes: 9088
# 6**6 < 10**5 < 6**7
# 9**5 < 10**5 < 9**6

def solve(n):
    if n < 6:
        return n
    elif n < 9:
        return n - 5
    else:
        now_6 = 6
        while now_6 * 6 <= n:
            now_6 *= 6

        now_9 = 9
        while now_9 * 9 <= n:
            now_9 *= 9
        
        ans = float('inf')
        for i in range(n // now_6 + 1):
            cnt = i + (n - now_6*i) // now_9 + solve((n - now_6*i) % now_9)
            if cnt < ans:
                ans = cnt
        
        return ans

print(solve(int(input())))

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

ans=10**10
for i in range(1,n):
    a=str(i)
    b=str(n-i)
    temp=0
    for j in a:
        temp+=int(j)
    for j in b:
        temp+=int(j)
    ans=min(ans,temp)
print(ans)

        

Measured memory_bytes: 3060
from itertools import permutations

import numpy as np

N = int(input())

xys = []
for _ in range(N):
    xys.append(list(map(int, input().split())))

combs = np.array(list(permutations(xys, N)))
ret = np.array(
    [np.linalg.norm(combs[:, i] - combs[:, i + 1], axis=1) for i in range(N - 1)]
).sum() / len(combs)

print("{:.10f}".format(ret))


Measured memory_bytes: 24036
// 難さんすう すーぱーさんすうと呼ぼう
// Mを素因数分解しといて例えばM=12としてM=(2^2) * (3^1)なるが、それぞれの因数をそれぞれの乗数ぶん振り分ける感じにした組み合わせが答え
// N = 3なら [1, 1, 1]の3つのどれかに振り分ける つまり以下
// 因数2を2つ,因数3を1つ を振り分けて、
//			[2^1, 2^1, 2^0], [3^1, 3^0, 3^0]
// 				-> [1*(2^1 * 3^1)] * [1*(2^1 * 3^0)] * [1*(2^0 * 3^0)] = 6*2*1 = 12
// あるいは
//			[2^2, 2^0, 2^0], [3^0, 3^0, 3^1] ならば
//				-> [1*(2^2 * 3^0)] * [1*(2^0 * 3^0)] * [1*(2^0 * 3^1)] = 4*1*3 = 12
// あるいは
//			[2^1, 2^1, 2^0], [3^0, 3^0, 3^1] ならば
//				-> [1*(2^1 * 3^0)] * [1*(2^1 * 3^0)] * [1*(2^0 * 3^1)] = 2*2*3 = 12
//
// 解説の""計算量はNに依らない""が意味不明だけど、説明してくれないので無視
// すーぱーさんすうの世界ではこれを重複組合せと呼ばうらしい 漢字だね 画数が多い
// n種類のものから重複を許してr個選ぶ場合の数 = nHr = (n+r-1)Cr に帰着できるらしい

// nCr mod Pなので気をつける
package main

import (
	"fmt"
	"math"
)

var MOD int

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	arr := factorization(M)
	ans := 1
	MOD = int(math.Pow10(9)) + 7
	for _, v := range arr {
		// ans *= ncrMod(v+N-1, v, MOD)
		// ans *= comb(v+N-1, v, MOD)
		ans = ans * comb(v+N-1, v, MOD) % MOD
	}
	fmt.Println(ans % MOD)
}

func factorization(n int) map[int]int {
	a := make(map[int]int)
	for i := 2; i*i <= n; {
		if n%i == 0 {
			a[i]++
			n /= i
		} else {
			i++
		}
	}
	if n > 1 {
		a[n]++
	}
	return a
}

func primeFactorization(x int) map[int]int {
	ret := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			x /= i
			if _, ok := ret[i]; ok {
				ret[i] += 1
			} else {
				ret[i] = 1
			}
		}
	}
	if x > 1 {
		ret[x] = 1
	}
	return ret
}

func ncrMod(n, r, mod int) int {
	// 呼び出すたびにテーブルを作るのは愚
	_n := 1000000
	g1 := make([]int, _n+1)
	g1[0], g1[1] = 1, 1
	g2 := make([]int, _n+1)
	g2[0], g2[1] = 1, 1
	inverse := make([]int, _n+1)
	inverse[0], inverse[1] = 0, 1
	for i := 2; i <= _n; i++ {
		g1[i] = (g1[i-1] * i) % mod
		inverse[i] = mod - inverse[mod%i]*(mod/i)%mod
		g2[i] = (g2[i-1] * inverse[i]) % mod
	}

	return g1[n] * (g2[r] * g2[n-r] % mod) % mod
}

func comb(n, m, MOD int) int {
	return factorial(n, n-m+1, MOD) * pow(factorial(m, 2, MOD), MOD-2, MOD) % MOD
}

func pow(x, n, MOD int) int {
	r := 1
	for ; n > 0; n /= 2 {
		if n%2 == 1 {
			r = r * x % MOD
		}
		x = x * x % MOD
	}
	return r
}

func factorial(n, m, MOD int) int {
	r := 1
	for i := m; i <= n; i++ {
		r = r * i % MOD
	}
	return r
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>

const long long INF = 1LL << 60;
const int MAX_NUM = 100010;

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

int main()
{
  int N, K;
  std::cin >> N >> K;
  std::vector<int> h(N);
  for ( int i = 0; i < N; i++ ) std::cin >> h[i];
  std::vector<long long> dp(MAX_NUM, INF);
  dp[0] = 0;
  for ( int now = 0; now < N; now++ ) {
    for ( int next = now + 1; next <= std::min(N, now + K); next++ ) {
      chmin(dp[next], dp[now] + std::abs(h[now] - h[next]));
    }
  }
  std::cout << dp[N-1] << std::endl;
  return 0;
}



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


using namespace std;


# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }



//const float INF = std::numeric_limits<float>::infinity();
//const int MAX_N = 1e6;

int main() {
  int N;
  cin >> N;
  int i = 0;
  int j = 0;
  int k = 0;

  vector<vector<int64_t>> dp(N+1, vector<int64_t>(3));
  vector<vector<int>> h(N, vector<int>(3));
  rep(i, N) {
    cin >> h.at(i).at(0) >> h.at(i).at(1) >> h.at(i).at(2);
  }
  
  rep(i, N) {
    rep(j, 3) {
      rep(k, 3) {
        if (j == k) continue;
        chmax(dp.at(i+1).at(k), dp.at(i).at(j)+h.at(i).at(k));
      }
    }
  }

  int64_t res = 0;
  rep(i ,3) {
    res = max(res, dp.at(N).at(i));
  }
  cout << res << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    string s; cin >> s;
    int num_1=0, num_0=0;
    for(char c : s){
        if(c=='1') ++num_1;
        else ++num_0;
    }
    cout << min(num_1, num_0)*2 << endl;
    return 0;
}


Measured memory_bytes: 512
import sys
readline = sys.stdin.buffer.readline

w,h,n = map(int,readline().split())

lst1 = [0,w,0,h] #←x,x→,y↓,y↑
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: #max
        if a==1: #x
            lst1[a-1] = max(lst1[a-1],x)
        else: #y
            lst1[a-1] = max(lst1[a-1],y)
    
    else:
        if a==2: #x
            lst1[a-1] = min(lst1[a-1],x)
        else: #y
            lst1[a-1] = min(lst1[a-1],y)

class Square_area():
    """
    about:
    四角形の縁からx,yだけ塗りつぶした時の、塗りつぶした面積を出力する。
    require:
    w,h,x1,x2,y1,y2
    w:幅
    h:高さ
    四角形の左下の座標を(0,0)とした時、
    x1:その左側を塗りつぶす
    x2:その右〃
    y1:その下〃
    y2:その上〃
    x1とx2の領域が重なる(x2<x1)の場合は、全て塗りつぶすという扱いになる。yについても同様。
    """
    def __init__(self,w,h,x1=0,x2=w,y1=0,y2=h):
        self.w = w
        self.h = h
        self.area = w*h
        self.x1 = x1
        if x2 < x1:
            self.x2 = w-x1
        else:
            self.x2 = w-x2
        self.y1 = y1
        if y2 < y1:
            self.y2 = h-y1
        else:
            self.y2 = h-y2
    
    def get_outer(self): #指定した座標の外側の面積
        return (self.x1+self.x2)*h +(self.y1+self.y2)*w - self.dublication()

    def get_inner(self): #指定した座標の内側の面積
        return self.area - self.get_outer()

    def dublication(self): #重複部分の面積。x同士、y同士の重複はinitで処理してしまっているので注意
        return self.x1*(self.y1+self.y2)+self.x2*(self.y1+self.y2)

req = Square_area(w,h,lst1[0],lst1[1],lst1[2],lst1[3])

print(req.get_inner())

Measured memory_bytes: 38384
#include<iostream>

using namespace std;

int abs(int x){

   return max(x, -x);
}

int main(){

   int N, T;
   cin>> N>> T;
   int a[N];
   for(int i=0; i<N; i++) cin>> a[i];

   int b[N]={0};
   for(int i=N-1; i>0; i--){
      b[i-1]=max(b[i], a[i]);
   }

   int ma=0;
   for(int i=0; i<N; i++){
      ma=max(ma, max(b[i]-a[i], 0));
   }
   int cnt=0;
   for(int i=0; i<N; i++){
      cnt+=(ma==max(b[i]-a[i], 0));
   }

   cout<< cnt<< endl;

   return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define N 110000
int n,num;
int a[N];
int main()
{
	scanf("%d",&n);
	if(n==1)return puts("Second"),0;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	while(1)
	{
		int odd=0,even=0,pos;
		for(int i=1;i<=n;i++)
		{
			if(a[i]&1)odd++,pos=i;
			else even++;
		}
		if(even&1)break;
		if(odd>=2){num++;break;}
		if(a[pos]==1){num++;break;}
		a[pos]--;int t=a[1];
		for(int i=2;i<=n;i++)t=__gcd(t,a[i]);
		for(int i=1;i<=n;i++)a[i]/=t;
		num++;
	}
	puts(num&1 ? "Second" : "First");
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[200];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>m;
	a=0;
	for(i=0;i<n;i++){
		cin>>t[i];
		a+=t[i];
	}
	b=0;
	for(i=0;i<n;i++){
		if(t[i]*4*m>=a)b++;
	}
	if(b>=m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] s = new int[4];
		for(int i=0; i < 4;i++) {
			s[i] = n % 10;
			n /= 10;
		}

		String msg = "Good";
		for(int i = 0; i < 3; i++)
			if(s[i] == s[i+1])
				msg = "Bad";


		System.out.println(msg);
	}

}


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

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

Measured memory_bytes: 3760
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
vector<pairs> p;


ll gcd(ll A,ll B){
    if (A%B==0)return(B);
    else return(gcd(B,A%B));
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;
    string ans = "NO";
    for(ll i=0;i<s.size();++i){
        for(ll j=0;j<s.size();++j){
            string x = s.substr(0, i);
            string y = s.substr(j);
            if(x+y == "keyence"){
                ans = "YES";
                break;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
/*input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
*/
 

//this ufds implementation is for this problem: https://atcoder.jp/contests/abc177/tasks/abc177_d
#include <unordered_map>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<long long, long long> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 
int link[200020];
int siz[200020];


int find(int x){
	while(x!=link[x]) x = link[x];
	return x;
}

bool same(int a, int b){
	return find(a)==find(b);
}

void unite(int a, int b){
	a = find(a);
	b = find(b);
	if(siz[a]<siz[b]){
		swap(a,b);
	}
	siz[a]+=siz[b];
	link[b]=a;
}





 
int main() {
	int n;
	int m;

	memset(link,0,sizeof(link));
	memset(siz,0,sizeof(siz));
	cin>>n>>m;

	for(int i = 1; i<=n;i++){
		link[i] = i;
	}
	for(int i = 1; i<=n; i++){
		siz[i] = 1;
	}
	rep(i,m){
		int a;
		int b;
		cin>>a>>b;
		if(!same(a,b)){
			unite(a,b);
		}
		
	}

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

		mi = max(mi,siz[i]);
	}
	cout<<mi<<endl;;





}

Measured memory_bytes: 5216
#include<iostream>
using namespace std;
int main()
{
    int a[4],c=0,d=0,e=0,f=0;
    cin>>a[0];
    cin>>a[1];
    cin>>a[2];
    cin>>a[3];
    for(int i=0;i<4;++i)
    {
        if(a[i]==1)
            c++;
        else if(a[i]==9)
            d++;
        else if(a[i]==7)
            e++;
        else if(a[i]==4)
            f++;
    }
    if(c==1 && d==1 && e==1 && f==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
a,b = gets.split(" ").map(&:to_i)
sum = 0
min = 101
(0+b..a+b-1).each do |n|
    
   if  min > n.abs
        min = n.abs
   end
    sum += n
end
if sum >= 0
    puts sum-min
else
    puts sum+min
end


Measured memory_bytes: 1788
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <chrono>
#include <vector>

using namespace std;

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

    int w_cnt = 0;
    int b_cnt = 0;

    for (int i = 0; i < N; i++)
    {
        if (S[i] == '.')
        {
            w_cnt += 1;
        }
    }
    int ans = w_cnt;

    for (int i = 0; i < N; i++)
    {
        if (S[i] == '#')
        {
            b_cnt += 1;
        }
        else
        {
            w_cnt -= 1;
        }
        ans = min(ans, w_cnt + b_cnt);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n, d;

int main()
{
	IOS;
	cin >> d >> n;
	if (n == 100) n = 101;
	if (d == 0) cout << n << endl;
	if (d == 1) cout << n * 100 << endl;
	if (d == 2) cout << n * 10000 << endl;
	return 0;
}



Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
    n, u, v = map(int,input().split())
    if u == v:
        print(0)
        sys.exit()

    graph = [[] for _ in range(n)]
    depth_u = [-1] * (n) #頂点iのuから見た深さ
    depth_v = [-1] * (n) #頂点iのvから見た深さ
    u -= 1 #高橋
    v -= 1 #青木
    for i in range(n-1):
        a, b = map(int,input().split())
        graph[a - 1].append(b - 1)
        graph[b - 1].append(a - 1)
    
    # bfsで高橋から見た各頂点の深さをメモる。
    queue = deque([u])
    visited = [False]*n
    visited[u] = True
    depth_u[u] = 0
    while queue:
        node = queue.popleft()
        for xnode in graph[node]:
            if not visited[xnode]:
                visited[xnode] = True
                depth_u[xnode] = depth_u[node] + 1
                queue.append(xnode)
    # bfsで青木から見た各頂点の深さをメモる。
    queue = deque([v])
    visited = [False]*n
    visited[v] = True
    depth_v[v] = 0
    while queue:
        node = queue.popleft()
        for xnode in graph[node]:
            if not visited[xnode]:
                visited[xnode] = True
                depth_v[xnode] = depth_v[node] + 1
                queue.append(xnode)
    ans = 0
    max_d_v = 0
    for i in range(n):
        if depth_u[i] < depth_v[i]:
            max_d_v = max(max_d_v, depth_v[i])
    print(max_d_v - 1)



if __name__=='__main__':
    main()

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

void dfs(int& x,vector<vector<int>>& adj,vector<bool>& vis,vector<int>& dp)
{
	if(!vis[x])
	{
		vis[x]=true;
		for(int i=0;i<adj[x].size();i++)
		{
			dfs(adj[x][i],adj,vis,dp);
			dp[x]=max(dp[x],1+dp[adj[x][i]]);
		}
	}
}


int main()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int>>adj(n+1);
	vector<bool>vis(n+1,false);
	vector<int>dp(n+1,0);
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
	}

	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i,adj,vis,dp);

	cout<<*max_element(dp.begin(),dp.end());

}

Measured memory_bytes: 10992
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int main() {
	string h;
	while (getline(cin, h)) {
		if (h == "END OF INPUT") { break; }
		int mon = 0, cou;
		while (mon < h.length()) {
			cou = 0;
			while (mon < h.length() && h[mon] != ' ') {
				++mon;
				++cou;
			}
			cout << cou;
			++mon;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3160
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int n,a[100010],count=0;
	vector<int> v;
	cin>>n;
	int max=n-1;
	REP(i,n){
		cin>>a[i];
		if(i+1==a[i]){
			v.push_back(i);
		}
	}
	REP(i,v.size()){ARDEB(i,v)END}
	REP(i,v.size()){
		if(i!=v.size()-1&&v[i]+1==v[i+1]){
			count++;
			i++;
		}
		else{
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    int l=0,r=0;
    ll sum=0,ans=0;
    while(l<n){
        while(r<n&&(sum^v[r])==(sum+v[r])) sum+=v[r++];
        ans+=r-l;
        if(r==l) r++;
        else sum-=v[l];
        l++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 3005;
const int inf = N*N;

vector<pii> g[N*N];
int dis[N*N];
int c[2],d[2];
string s[N];
int n,m; 

int go(int i,int j)
{
  return i*m + j;   
}

void solve()
{
   cin >> n >> m;  
    
   f(i,2) cin >> c[i];
   f(i,2) cin >> d[i];
    
   f(i,2)  c[i]--;
   f(i,2) d[i]--;
    
    
   f(i,n) cin >> s[i];
    
    
    
   f(i,n) f(j,m) 
   {
      //add all edges from S(i,j)
      if(s[i][j] == '#') continue;
      
      int id = go(i,j);
     
       for(int k=i-2;k<=i+2;k++)
           for(int l=j-2;l<=j+2;l++)
       {
           if(k == i && l == j) continue;
           if(k < 0 || l < 0) continue;
           if(k >= n || l >= m) continue;
           
           if(s[k][l] == '#') continue;
           
           int wt = 1;
           
           if(abs(k-i) + abs(l-j) == 1) wt = 0;
           
           g[id].push_back({go(k,l),wt});
       }
   }
   
   f(i,n) f(j,m) dis[go(i,j)] = inf; 
    
   priority_queue<pii,vector<pii>,greater<pii> > pq; 
   pq.push({0,go(c[0],c[1])}); 
   dis[go(c[0],c[1])] = 0;
    
   while(!pq.empty())
   {
       auto x = pq.top(); pq.pop();
       
       if(dis[x.S] != x.F) continue;
       
       for(auto v : g[x.S])
       {
           if(dis[v.F] > v.S + x.F)
           {
               dis[v.F] = v.S + x.F;
               pq.push({dis[v.F],v.F});
           }
       }
       
   }
    
  
   int des = go(d[0],d[1]);
    
   if(dis[des] == inf) cout<< -1;
    else cout << dis[des];
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 355980
from collections import deque
N = int(input())
g = {i: deque() for i in range(1,N+1)} #1-index
for i in range(1, N+1):
    u, k, *v = map(int, input().split())
    for j in v:
        g[u].append(j)
        
seen = [0]*(N+1) #1-index
que = deque([])
dist = [-1]*(N+1) #1-index

seen[1] = 1
que.append(1)
dist[1] = 0

while que: #queが空になるまで
    q_no = que.popleft()
    if not g[q_no]: continue #点q-noから他の点に伸びていない
    
    for next_v in g[q_no]:
        if seen[next_v] == 1: continue #訪問済
        
        seen[next_v] = 1 #訪問済にする
        dist[next_v] = dist[q_no] + 1 #距離情報を格納
        que.append(next_v) #queに追加

for i in range(1, N+1):
    print(i, dist[i])


Measured memory_bytes: 6064
a,b,c,d = map(int,input().split())

#print(a,b,c,d)
isWin = True

while(True):
    c -= b
    if(c <= 0):
        break
    a -= d
    if(a <= 0):
        isWin = False
        break
    

if(isWin):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int n,m;cin >> n >> m;
    vector<P> ng;
    vector<int> to[n+1];
    for(int i=0; i<m; i++){
        int a,b;cin >> a >> b;
        ng.push_back({a,b});
        to[a].push_back(b);
        to[b].push_back(a);
    }
    int ans=0;
    for(auto p: ng){
        queue<int> q;
        q.push(1);
        vector<bool> used(n+1,false);
        used[1]=true;
        while(!q.empty()){
            int now=q.front();q.pop();
            for(auto next: to[now]){
                if((now==p.first&&next==p.second)||(now==p.second&&next==p.first)){
                    continue;
                }
                if(used[next]) continue;
                used[next]=true;
                q.push(next);
            }
        }
        bool ok=true;
        for(int i=1; i<=n; i++){
            if(!used[i]) ok=false;
        }
        if(!ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 18
#define ll long long
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<'\n';
#define trace(a) cout<<#a<<": "<<a<<"\n"
int a[(1<<N)];
multiset<int> fr[(1<<N)];
multiset<int> dp[(1<<N)][N+1];
int main() {
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	int i,j,k,l,m,n,t;
	cin >> n;
	for(i = 0;i < (1<<n);i++) {
		cin >> a[i];
		// dp[i][-1]
		fr[i].insert(-a[i]);
	}
	for(i = 0;i < (1<<n);i++) {
		for(j = 0;j <= n;j++) {
			if((i>>j)&1) {
				if(j == 0) {
					dp[i][j].insert(fr[i].begin(),fr[i].end());
					dp[i][j].insert(fr[i^(1<<j)].begin(),fr[i^(1<<j)].end());
					while(dp[i][j].size() > 2) {
						dp[i][j].erase(--dp[i][j].end());
					}
				}
				else {
					// dp[i][j] = dp[i][j-1] + dp[i^(1<<j)][j-1];
					dp[i][j].insert(dp[i][j-1].begin(),dp[i][j-1].end());
					dp[i][j].insert(dp[i^(1<<j)][j-1].begin(),dp[i^(1<<j)][j-1].end());
					while(dp[i][j].size() > 2) {
						dp[i][j].erase(--dp[i][j].end());
					}
				}
			}
			else {
				if(j == 0) {
					dp[i][j] = fr[i];
					// dp[i][j].insert(fr[i].begin(),fr[i].end());
					// while(dp[i][j].size() > 2) {
					// 	dp[i][j].erase(--dp[i][j].end());
					// }
				}
				else {
					dp[i][j] = dp[i][j-1];
					// dp[i][j].insert(dp[i][j-1].begin(),dp[i][j-1].end());
					// while(dp[i][j].size() > 2) {
					// 	dp[i][j].erase(--dp[i][j].end());
					// }
				}
			}
		}
	}
	int an = 0;
	for(i = 1;i < (1<<n);i++) {
		int can =  -(*dp[i][n].begin() + *dp[i][n].rbegin());
		an = max(an,can);
		cout << an << endl;
	}
}

Measured memory_bytes: 716800
($A,$B,$C,$X,$Y)=glob<>;
$\=1e15;
for(0..($X>$Y?2*$X:2*$Y)){
	if($_%2==0){
		$\-=$-=$\-($C*$_+$A*($-=$X-$_/2)+$B*($-=$Y-$_/2))
	}
}
print


Measured memory_bytes: 768
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int

using namespace std;

ll H,W;
char masume[2005][2005];
ll tate[2005][2005];
ll yoko[2005][2005];





int main(){
  cin>>H>>W;
  for(int i = 0;i<2005;i++){
    for(int j=0;j<2005;j++){
      masume[i][j] = '#';
      tate[i][j] = 0;
      yoko[i][j] = 0;
    }
  }

  for(int h = 1;h<=H;h++){
    string s; cin>>s;
    for(int w = 1;w<=W;w++){
      if(s[w-1] == '.') masume[h][w] = '.';
    }
  }

  for(int h = 1;h<=H;h++){
    int renzoku = 0;

    yoko[h][0] = -1;

    for(int w = 1;w<=W;w++){
      if(masume[h][w] == '#') {renzoku=0;yoko[h][w] = -1;continue;}
      renzoku++;
      yoko[h][w] = renzoku;
    }

    for(int w = W-1; w>=1;w--){
      if(yoko[h][w] == -1) continue;
      if(yoko[h][w] < yoko[h][w+1]) yoko[h][w] = yoko[h][w+1];
    }


  }
  


  for(int w = 1;w<=W;w++){
    int renzoku = 0;

    tate[0][w] = -1;

    for(int h = 1;h<=H;h++){
      if(masume[h][w] == '#') {renzoku=0;tate[h][w] = -1;continue;}
      renzoku++;
      tate[h][w] = renzoku;
    }

    for(int h = H-1; h>=1;h--){
      if(tate[h][w] == -1) continue;
      if(tate[h][w] < tate[h+1][w]) tate[h][w] = tate[h+1][w];
    }


  }

  ll ans = -1000;

  for(int h=1;h<=H;h++){
    for(int w = 1;w<=W;w++){
      ans = max(ans, yoko[h][w] + tate[h][w] -1);
      //cout<<h<<"  "<<w<<endl;
    }
  }

  //cout<<yoko[1][1]<<"  "<<yoko[3][2]<<endl<<endl;


  
  cout<<ans<<endl;




  return 0;

}

Measured memory_bytes: 66944
#include <iostream>
#include<vector>

using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<long> A(N + 1);
	vector<long> B(N);
	vector<long> C(N);

	for (int i = 0; i < N + 1; i++)
	{
		cin >> A[i];
	}
	for (int j = 0; j < N; j++)
	{
		cin >> B[j];
	}

	long ans = 0;
	for (int k = 0; k < N; k++)
	{
		if (B[k] >= A[k]) { // Bが大きいとき
			C[k] = A[k];
			B[k] -= A[k];
		}
		else
		{
			C[k] = B[k]; // Bが小さいとき
			B[k] = 0;
		}
		if (B[k]>=A[k+1]) //まだBが余っていてA[k+1]より大きいなら
		{
			C[k] += A[k + 1]; //A[k+1]のモンスター全てを退治する
			A[k + 1] = 0;
		}
		else
		{
			C[k] += B[k]; //まだBが余っていてA[k+1]よりは小さいとき
			A[k + 1] -= B[k]; // B分だけモンスターを退治する
		}
		ans += C[k];
	}
		cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<math.h>
#include<limits.h>
#define ll long long
using namespace std;
int main(){
  ll L,R;
  ll m=LLONG_MAX;
  cin >> L >> R;
  for(ll i=L;i<R;i++){
    for(ll j=i+1;j<=R;j++){
      ll tmp=(i*j)%2019;
      m=min(m,tmp);
      if(m==0){
        cout << m << endl;
        return 0;
      }
    }
  }
  cout << m << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  int N = s.size();
  for(int i = 0; i < N; i++){
    string c = s.substr(0, N - 1);
    char c2 = s[N - 1];
    s = c2 + c;
    if(s == t){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#ABC132B
n= int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
    if min(P[i-1], P[i], P[i+1]) != P[i] and max(P[i-1], P[i], P[i+1]) != P[i]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
n = int(input())
s = str(input())
mod = 10**9+7
d = {}
for i in range(n):
    if s[i] not in d:
        d[s[i]] = 1
    else:
        d[s[i]] += 1
ans = 1
for v in d.values():
    ans *= (v+1)%mod
ans -= 1
print(ans%mod)

Measured memory_bytes: 3188
N,W = map(int,input().split())
vw = [ list(map(int,input().split())) for _ in range(N) ]

# dp[i]: 重さがiとなるように選んだ時の合計価値の最大値
dp = [0]*(W+1)

dp[0] = 0

for i in range(W+1):
    for j in range(N):
        v = vw[j][0]
        w = vw[j][1]
        if i<w:
            dp[i] = dp[i]
        else:
            dp[i] = max( dp[i], dp[i-w]+v )
# print(dp)
print(dp[W])


Measured memory_bytes: 5920
#include<stdio.h>
#include<string.h>
int main()
{
    char s[20];
    int l,i;
    gets(s);
    l=strlen(s);
    if(l==19&&s[i]>=97&&s[i]<=122&&s[5]&&s[13])
    {

       for(i=0; i<=l; i++){

        if(i==5||i==13)
        {
            printf(" ");
        }
        else if(s[i]>=97&&s[i]<=122)
        {
            printf("%c",s[i]);
        }

    }}return 0;
}


Measured memory_bytes: 128
N,Y = map(int, raw_input().split())
for x in range(N+1):
  y = ((Y-10000*x)-1000*(N-x))/4000
  z = N-y-x
  if 0<=y and 0<=z and 10000*x+5000*y+1000*z==Y:
    print x, y, z
    exit(0)
print -1, -1, -1


Measured memory_bytes: 2696
require 'pp'

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end

N, h_list = gets_n_and_i_list

list = [h_list]
count = 0
while true
  break if list.empty?
  target = list.pop
  if target.include?(0)
    index = target.index(0)
    left  = target[0,index]
    right = target[index+1, target.size]
    list.push(left)  unless left.empty?
    list.push(right) unless right.empty?
  else
    list.push(target.map{|i|i-1})
    count += 1
  end
end

puts count


Measured memory_bytes: 2300
a,b,c=map(int,input().split())
l=set()
for i in range(a,a+c):
    if i!=b:l.add(i)
    else:break
for i in range(max(b-c+1,a),b+1):
        l.add(i)
print("\n".join(map(str,sorted(list(l)))))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { std::cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    map<string,int> data;
    rep(i,n){
        string s;
        cin >> s;
        data[s]++;
    }
    cout << data.size() << endl;
}

Measured memory_bytes: 19220