akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> ps(n), qs(n);
    for(int i=0; i<n; ++i){
        cin >> ps[i];
        qs[i]=ps[i];
    }
    sort(ps.begin(), ps.end());
    int cnt=0;
    for(int i=0; i<n; ++i){
        cnt+=ps[i]!=qs[i];
    }
    cout << (cnt <= 2 ? "YES" : "NO") << endl;
    return 0;
}



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

int main(){
    char s[1000], t[1000];
    scanf("%s", s);
    scanf("%s", t);
    int s_size = strlen(s);
    int t_size = strlen(t);
    int ans = t_size;

    for(int start = 0; start <= s_size - t_size ; start++){
        int diff = 0;
        for(int i = 0; i < t_size; i++){
            if(t[i] != s[start + i]){
                diff++;
            }     
        }
        if(ans>diff){
            ans = diff;
        }
    }
    
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1724
#include <stdio.h>
int main()
{
	int i, data[5], sum = 0, average;
	for(i=0; i<5; i++){
		scanf("%d",&data[i]);
		if(data[i] < 40){
			data[i] = 40;
		}else{
			data[i] = data[i];
		}
		sum += data[i]; 
	}
	average = sum /5;
	printf("%d\n",average);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;



signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,ans = 0;
    cin>>n;
    vector<int>a(n),b(60,0);
    rep(i,0,n){
        cin>>a[i];
    }
    rep(i,0,n){
        rep(j,0,60){
            if(a[i] & (1LL<<j)){
                b[j]++;
            }
        }
    }
    rep(i,0,60){
        ans+=((1LL<<i)%MOD)*(((n-b[i])*b[i])%MOD)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

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

int main()
{
	int n;
	while(cin >>n){
		if(n==0)
			break;
		for(int i=0;i<n;i++){
			int a,b,c,d,e,f,g,h;
			cin >> a >> b >> c >> d >> e >> f >> g >> h;
			cout << a*e-b*f-c*g-d*h << " " << a*f+b*e+c*h-d*g << " " << a*g-b*h+c*e+d*f << " " << a*h+b*g-c*f+d*e << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;


int main(){
int k,x; cin>>k>>x;
for(int i=x - k + 1; i<=x + k - 1;i++){
    if(i == x + k - 1) {cout<<i<<endl;break;}
    cout<<i<<' ';
}

    return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back

int main()
{
  ll k,a[32]={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};
  cin>>k;
  cout<<a[k-1]<<endl;




 return 0;
  }





Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
//#include<>
using namespace std;

typedef long long int64;
typedef int int32;
typedef char int8;


#define rep(i,j) for(i=0;i<j;i++)
#define all(v) (v).begin(),(v).end()

const int INF=1<<30;//=10E10

typedef struct Point
{
  int x;
  int y;
  int d;
  Point(int x_,int y_,int d_):x(x_),y(y_),d(d_){};
}Point ;

 

int solve(bool bd[60][60],int w,int h)
{
  queue<Point> bf;
  int ans=INF;
  bf.push(Point(0,0,1));
  while(!bf.empty())
    {
      Point now=bf.front();bf.pop();
      if(bd[now.y][now.x])continue;
      else
	bd[now.y][now.x]=true;


      if(now.x==2*w-2 && now.y==2*h-2){//ゴール
	ans=now.d;
	break;
      }
      else{
	if(now.x<2*w-2&&!bd[now.y][now.x+1])bf.push(Point(now.x+2,now.y,now.d+1));
	if(now.y<2*h-2&&!bd[now.y+1][now.x] )bf.push(Point(now.x,now.y+2,now.d+1));
	if(now.x>0&& !bd[now.y][now.x-1])bf.push(Point(now.x-2,now.y,now.d+1));
	if(now.y>0&&!bd[now.y-1][now.x])bf.push(Point(now.x,now.y-2,now.d+1));
      }
      /*
      //探索の視覚化
      int i,j;
      rep(i,2*h-1)
	{
	  if(i%2==0){
	  rep(j,2*w-1)
	    if(j%2==0)cout<< (bd[i][j] ? "O" : " ");
	  cout<<endl;
	  }
	}
	  cout<<endl;
      */
    }
  if(ans==INF)ans=0;
  cout<<ans<<endl;
}

int main()
{
  while(true){
    bool bd[60][60]={};//[2h-1][2w-1]
    int w,h;
    cin>>w>>h;
    if(!w && !h)break;
    string hline,wline;
    int i,j;
    getline(cin,hline);//読み捨て
    rep(i,h-1)
      {
	getline(cin,hline);
	getline(cin,wline);
	rep(j,hline.size())
	  bd[i*2][j]= (hline[j]=='1' ? true:false);
	rep(j,wline.size())
	  bd[i*2+1][j]= (wline[j]=='1' ? true:false);
	//      cout<<"hline : "<<hline<<endl;
	//      cout<<"wline : "<<wline<<endl;
      }
    i=h-1;
    getline(cin,hline);
    rep(j,hline.size())
      bd[i*2][j]= (hline[j]=='1' ? true:false);
    
    /*
    rep(i,2*h-1)
      {
	rep(j,2*w-1)
	  cout<<bd[i][j]<<" ";
	cout<<endl;
      }
    */
 
    //探索
    solve(bd,w,h);
  }
    return 0;
    
}

Measured memory_bytes: 1236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

ll n;

vector<ll> fvalues;
vector<ll> fvalues2;
ll f(ll x) {
  return x * (x + 1) * (x + 2) / 6;
}

vector<ll> table;
ll dfs(ll x) {
  if (table[x] != -1) return table[x];
  if (x == 0) return 0;

  ll minv = numeric_limits<ll>::max() / 2;

  for (ll i = fvalues.size() - 1; i >= 0; i -= 1) {
    ll value = fvalues[i];
    if (x - value >= 0) {
      minv = min(minv, dfs(x - value) + 1);
    }
  }
  return table[x] = minv;
}

vector<ll> table2;
ll dfs2(ll x) {
  if (table2[x] != -1) return table2[x];
  if (x == 0) return 0;

  ll minv = numeric_limits<ll>::max() / 2;

  for (ll i = fvalues2.size() - 1; i >= 0; i -= 1) {
    ll value = fvalues2[i];
    if (x - value >= 0) {
      minv = min(minv, dfs2(x - value) + 1);
    }
  }
  return table2[x] = minv;
}

bool solve() {
  cin >> n;
  if (n == 0) return false;

  cout << dfs(n) << " " << dfs2(n) << endl;

  return true;
}

int main() {
  ll M = 1000000;
  for (ll i = 1;; i++) {
    ll value = f(i);
    fvalues.push_back(value);
    if (value % 2 == 1) fvalues2.push_back(value);
    if (value > M) break;
  }

  table = vector<ll>(M + 1, -1);
  table2 = vector<ll>(M + 1, -1);
  while (solve());
}



Measured memory_bytes: 18240
n, m, x, y = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
X.sort()
Y.sort()
if x <= X[-1] and X[-1] < Y[0] and Y[0] <= y:
  print("No War")
else:
  print("War")


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

using namespace std;

int main(void) {
	int x, n;
	int a[100];

	scanf("%d%d", &x, &n);
	for(int i=0; i<n; i++) {
		scanf("%d", &a[i]);
	}
	int flag = 1;
	int flag2 = 0;
	int target = x;
	int cnt1 = 0;
	int cnt2 = 0;
	int clk = 0;
	while(flag) {
		clk = !clk;
		flag2 = 0;
//		printf("target:%d\n", target);
		for(int i=0; i<n; i++) {
			if(a[i] == target) {
				flag2 = 1;
				if(clk) {
					target = x - cnt1;
					cnt1++;
					break;
				} else {
					target = x + cnt2;
					cnt2++;
					break;
				}
			}
		}
		if(!flag2) flag = 0;
	}
	printf("%d\n", target);
	return 0;
}

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


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

    int s=0;

    if(b==1)
    {
        cout<<0<<endl;
        return 0;
    }

    for(int i=1 ;  ; i++){
        s=s+a;
        if(s>=b){
            cout<<i<<endl;
            break;
        }


        s--;

    }


}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const int N = 1010;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int n, m;
struct node{
    int x, y;
    node(){}
    node(int x, int y):x(x),y(y){}
}s, t;
char str[N][N];
int a[N][N], tot, dep[N*N];
queue<node> q;
vector<node> g[N*N];
void expend(int x, int y){
    tot++;
    a[x][y] = tot; g[tot].push_back(node(x, y));
    q.push(node(x, y));
    while (!q.empty()){
        node u = q.front(); q.pop();
        for (int i = 0; i < 4; ++i){
            int tx = u.x+dx[i], ty = u.y+dy[i];
            if (tx < 1 || tx > n || ty < 1 || ty > m || str[tx][ty] != '.' || a[tx][ty]) continue;
            a[tx][ty] = tot; g[tot].push_back(node(tx, ty));
            q.push(node(tx, ty));
        }
    }
}
int bfs(void){
    queue<int> q;
    vector<int> v;
    q.push(a[s.x][s.y]);
    dep[a[s.x][s.y]] = 0;
    while (!q.empty()){
        int u = q.front(); q.pop();
        if (a[t.x][t.y] == u){
            return dep[a[t.x][t.y]];
        }
        v.clear();
        for (node& nd : g[u]){
            for (int dx = -2; dx <= 2; ++dx){
                for (int dy = -2; dy <= 2; ++dy) if (dx||dy){
                    int tx = nd.x+dx, ty = nd.y+dy;
                    if (tx < 1 || tx > n || ty < 1 || ty > m || str[tx][ty] != '.' || a[tx][ty] == u) continue;
                    v.push_back(a[tx][ty]);
                }
            }
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        for (int& k : v) if (!dep[k]){
            dep[k] = dep[u]+1;
            q.push(k);
        }
    }
    return -1;
}
int main(void){
    IOS;
    cin >> n >> m;
    cin >> s.x >> s.y >> t.x >> t.y;
    for (int i = 1; i <= n; ++i){
        cin >> (str[i]+1);
    }
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= m; ++j) if (str[i][j] == '.' && !a[i][j]){
            expend(i, j);
        }
    }
    /*for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= m; ++j){
            printf("%d ", a[i][j]);
        }
        printf("\n");
    }*/
    cout << bfs() << endl;
    return 0;
}

Measured memory_bytes: 39328
#include <bits/stdc++.h>
using namespace std;
long long go[500000];
bool been[500000];
vector<int> roop;
#define per(k,x,y) for(long long k=x;k<=y;k++)
int main(){
    long long n,k;
    scanf("%lld%lld",&n,&k);
    per(i,1,n)
        scanf("%lld",&go[i]);
    long long at=1,c=0;
    while(!been[at]&&k){
        been[at]=1;
        at=go[at];
        k--;
    }
    if(!k)
        printf("%lld",at);
    else {
        long long w = go[at];
        long long cnt = 1;
        roop.push_back(at);
        while (w != at) {
            cnt++;
            roop.push_back(w);
            w = go[w];
        }        
        printf("%lld\n",roop[(k)%cnt]);
    }

}//
// 6 1
//6 5 2 5 3 2

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

int main() {
  string s,t;
  int N;
  cin>>N;
  int j=0;
  std::vector<int> v(N),a(N);
  for(int i=0;i<N;i++){
    cin>>v[i];
    j+=v[i];
    if(v[i]%10!=0)a[i]=v[i];
    else a[i]=1000;
  }
  sort(a.begin(),a.end());
  if(j%10==0){
    if(a[0]==1000)cout<<0<<endl;
    else cout<<j-a[0]<<endl;
  }
  else cout<<j<<endl;
}


Measured memory_bytes: 256
/*
*/

//#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 300031;

int ar[1000];

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	string st;
	cin>>st;
	for (int i=0;i<4;i++){
		ar[i]=st[i]-48;
	}

	for (int mask=0;mask<(1<<3);mask++){
		int res=ar[0];
		for (int i=0;i<3;i++){
			if (mask&(1<<i))
				res-=ar[i+1];
			else
				res+=ar[i+1];
		}
		if (res==7)
		{
			cout<<ar[0];
			for (int i=0;i<3;i++){
				if (mask&(1<<i))
					cout<<"-";
				else
					cout<<"+";
				cout<<ar[i+1];
			}
			cout<<"=7"<<endl;
			return 0;
		}
	}

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int henkan(char pattern)
{	
	if(pattern == 'S'){
		return 0;
	}
	else if(pattern == 'H'){
		return 1;
	}
	else if(pattern == 'C'){
		return 2;
	}
	else{
		return 3;
	}
}

char moji(int i)
{
	if(i == 0){
		return 'S';
	}
	else if(i == 1){
		return 'H';
	}
	else if(i == 2){
		return 'C';
	}
	else{
		return 'D';
	}
}

int main(void)
{
	int n;	//??????????????£??????????????????????????°
	
	scanf("%d", &n);
	char dummy;
	
	bool checksheet[4][13];	//????????¨????????????????????????????¬??????????
	char pattern;		//???????????¨?????????
	int num;			//?????????????????????
	
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			checksheet[i][j] = false;
		}
	}
	
	//n??????????????????????????????
	for(int i = 0; i < n; i++){
		scanf("%c", &dummy);
		scanf("%c %d", &pattern, &num);
		
		checksheet[henkan(pattern)][num - 1] = true; 
		
	}
	
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			if(checksheet[i][j] != true){
			
				char a = moji(i);
				
				printf("%c %d\n", a, j + 1);
			} 
		
		}
	}
	
	return 0;
}

Measured memory_bytes: 2624
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    char[] c = s.toCharArray();
    
    int cnt = 0;
    if(c[0] == '1') cnt++;
    if(c[1] == '1') cnt++;
    if(c[2] == '1') cnt++;
    
    System.out.println(cnt);
  }
}


Measured memory_bytes: 21972
import collections

n,m,k = map(int,raw_input().split(' '))

friendships = [map(int, raw_input().split(' ')) for _ in range(m)]
disses = [map(int, raw_input().split(' ')) for _ in range(k)]

parent = [i for i in range(0, n+1)]
sizes = [1 for i in range(0, n+1)]
hd = [1 for i in range(0, n + 1)]


def f(parent, u):
	if parent[u] != u:  parent[u] = f(parent, parent[u])
	return parent[u]

for a,b in friendships:

	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in disses:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - hd[u])  for u in range(1, n+1)])

Measured memory_bytes: 58268
$N = gets.chomp.to_i

s = []
$N.times do
  s << gets.chomp.to_i
end

def max(a, b)
  a < b ? b : a
end

# s = s.sort
sum = s.reduce(:+)

$table = Array.new(sum + 1, 0)

def point(n)
  n % 10 == 0 ? 0 : n
end

def max_a(arr)
  res = -10_000_000_000_000_000_000
  arr.each do |i|
    res = i < res ? res : i
  end
  res
end

$N.times do |i|
  (0...sum).each do |j|
    current = sum - j
    $table[current] = if s[i] <= current
                        max($table[current], $table[current - s[i]] + s[i])
                      else
                        $table[current]
                      end
  end
end
puts max_a($table.map { |t| point(t) })


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    //w   e
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    int ans=0;
    for(int i=0; i<n; i++){
        bool flag=false;
        for(int j=0; j<i; j++){
            if(a[j] > a[i]) flag = true;
        }
        ans+=(flag? 0 : 1);
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
#define ll long long
typedef pair<int, int> P;

bool prime[1000005];

void solve()
{
	REP(i, 1000005)prime[i] = true;
	prime[0] = prime[1] = false;
	for (int i = 2; i*i <= 1000000;i++)
	{
		if (prime[i] == true)
		{
			for (int j = 2; j*i <= 1000000; j++){
				if (prime[i*j] == true)prime[i*j] = false;
			}
		}
	}
}

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

		int ans = 0;

		solve();
		REP(i, n + 1){
			if (prime[i] == true){
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2136
// https://atcoder.jp/contests/abc129/tasks/abc129_c

package main

import "fmt"
import "bufio"
import "os"
import "strconv"

var _sw = bufio.NewScanner(os.Stdin)

const mod = 1000000007

func main() {
	N := NextInt()
	M := NextInt()
	broken := make([]bool, N+1)
	for i := 0; i < M; i++ {
		a := NextInt()
		broken[a] = true
	}

	// i 段目まで行く方法
	counts := make([]int, N+1)
	counts[0] = 1

	for i := 1; i < len(counts); i++ {
		if broken[i] {
			counts[i] = 0
			continue
		}

		if i == 1 {
			counts[i] = counts[i-1]
		} else {
			counts[i] = (counts[i-1] + counts[i-2]) % mod
		}
	}

	fmt.Println(counts[N] % mod)
}

func init() {
	_sw.Split(bufio.ScanWords)
}

func NextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func NextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}


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

#define ipair pair<int,int>
#define rep(I,N) for(int I=0; I<N; I++)
#define repj(i,j,n) for(int i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;

int graph[50][50];

bool dfs(int v1, int v2, int N, bool visited[10])
{
  bool is_all_visited = true;
  if (v1 == v2) {
    return true;
  }
  rep(i, N) {
    if (visited[i] == false) {
      is_all_visited = false;
      break;
    }
  }

  if (is_all_visited) return false;

  bool ret = false;
  rep(i, N) {
    if (graph[v1][i] && visited[i] == false) {
      visited[i] = true;
      ret = dfs(i, v2, N, visited);
      if (ret) {
        return true;
      }
      visited[i] = false;
    }
  }
  return ret;
}

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

  rep(i, 50) {
    rep(j, 50) {
      graph[i][j] = 0;
    }
  }

  rep(i, M) {
    int j, k;
    cin >> j >> k;
    j--;
    k--;
    graph[j][k] = graph[k][j] = 1;
  }

  int bridge = 0;
  rep (i, N) {
    int edge = 0;
    // repj (j, i+1, N) {
    //   edge += graph[i][j];
    // }
    // if (edge == 1) {
    //   bridge++;
    //   continue;
    // }
    repj (j, i, N) {
      if (graph[i][j] ) {
        graph[i][j] = 0;

        bool visited[50] = {false};
        visited[i] = true;

        bool is_reach = dfs(i, j, N, visited);
        bridge += !is_reach;
        // printf("bridge from %d to %d = %d\n", i, j, is_reach);

        graph[i][j] = true;
        visited[i] = false;
      }
    }
  }
  printf("%d\n", bridge);

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, k;
  string s;
  cin >> n >> k >> s;

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

  vll a(0);
  ll cnt = 1;
  for (ll i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      a.push_back(cnt);
      cnt = 1;
    }
    else cnt++;
  }
  a.push_back(cnt);
  for (ll i = 1; i < a.size(); i++) a[i] += a[i - 1];

  ll ans = 0;
  if (s[0] == '1') {
    if (k >= a.size() / 2) ans = n;
    else {
      ans = a[min((ll)a.size() - 1, 2 * k)];
      for (ll i = 2; i < a.size(); i += 2) ans = max(ans, a[min((ll)a.size() - 1, i + 2 * k)] - a[i - 1]);
    }
  }
  else {
    if (a.size() % 2 == 1) {
      if (k >= a.size() / 2 + 1) ans = n;
      else {
        ans = a[min((ll)a.size() - 1, 2 * k - 1)];
        for (ll i = 1; i < a.size(); i += 2) ans = max(ans, a[min((ll)a.size() - 1, i + 2 * k)] - a[i - 1]);
      }
    }
    else {
      if (k >= a.size() / 2) ans = n;
      else {
        ans = a[min((ll)a.size() - 1, 2 * k - 1)];
        for (ll i = 1; i < a.size(); i += 2) ans = max(ans, a[min((ll)a.size() - 1, i + 2 * k)] - a[i - 1]);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1528
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
    String judge=Math.abs(x-a)>Math.abs(x-b)?"B":"A";
    System.out.println(judge);
  }
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int A=in(),B=in(),K=in();
	int N = B-A+1;
	vector<int> T;
	for(int i=A;i<A+min(N,K);i++) T.push_back(i);
	for(int i=B;i>B-min(N,K);i--) T.push_back(i);
	sort(ALL(T));
	T.erase(unique(ALL(T)),T.end());
	int M=T.size();
	REP(i,M){
		out(T[i]);
	}

	return 0;
}


Measured memory_bytes: 256
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
19：25〜
着席位置は{中央x中央}
*/
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

#define INF 999999999;
#define MOD 1000000007

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int V, E, r;
//vector< vector < pair<int, int> > > graph;
struct {
    int s;
    int t;
    unsigned long long int d;
} Cost[500005];
unsigned long long int d[100005];

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

    cin >> V >> E >> r;;
    for(int i = 0; i < V; i++){
        d[i] = 99999999999;
    }
    d[r] = 0;
    for(int i = 0; i < E; i++){
        cin >> Cost[i].s >> Cost[i].t >> Cost[i].d;
        
    }

    bool f = true;
    while(f){
        f = false;
        for(int i = 0; i < E; i++){
            if(d[ Cost[i].t ] > d[ Cost[i].s ] + Cost[i].d){
                d[ Cost[i].t ] = d[ Cost[i].s ] + Cost[i].d;
                f = true;
            }
        }
    }

    for(int i = 0; i < V; i++){
        if(d[i] == 99999999999) cout << "INF\n";
        else cout << d[i] << "\n";
    }

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  bool flag = true;
  for(int i = 0; i < s.size(); i += 2){
    if(s.at(i) == 'L') flag = false;
  }
  for(int i = 1; i < s.size(); i += 2){
    if(s.at(i) == 'R') flag = false;
  }

  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if(a==b && d==c || a==c && b==d || a==d && b==c){
    printf("yes\n");
  }
  
  else{
    printf("no\n");
  }
	      

  return 0;
}

Measured memory_bytes: 580
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N, x = getInput()
a_i = getInput()
a_i.sort()
child = 0
for i in range(N):
    a = a_i.pop(0)
    if x >= a:
        x = x - a
        if x > 0 and not a_i:
            break
        child += 1
    if x == 0:
        break

print(child)

Measured memory_bytes: 3060
#include <stdio.h>

int main() {
	int prime[60000] = {1, 1};
	int prime_num[10000] = {0};
	int num;
	int i, j;
	int n;
	int ans;
	int temp;

	for(i = 2; i < 60000; i++)
		if(!prime[i])
			for(j = 2; i * j < 60000; j++)
				prime[i * j] = 1;

	for(i = 0, num = 0; i < 60000; i++) {
		if(!prime[i]) {
			prime_num[num] = i;
			num++;
		}
	}

	while(1) {
		ans = 0;
		scanf("%d", &n);
		if(n == 0)
			break;
		
		if(n % 2 == 1) {
			if(!prime[n - 2])
				ans++;
		}

		else {
			for(i = 0; prime_num[i] * 2 <= n; i++) {
				if(!prime[n - prime_num[i]])
					ans++;
				
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 880
class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end


n = gets.strip.to_i
xy = readlines.map {|line| line.strip.split.map(&:to_i) }
xy=xy.uniq

nodes = {}
xy.each_with_index do|(x, y), i|
  nodes[[x, y].to_s] = i+1
end

edges = []
x_order = xy.dup.sort_by(&:first)
x_order.each_cons(2) do |from, to|
  x1, y1 = from
  x2, y2 = to
  from_node = nodes[from.to_s]
  to_node = nodes[to.to_s]
  cost = [(x1-x2).abs, (y1-y2).abs].min

  edges << [from_node, to_node, cost]
end

y_order = xy.dup.sort_by(&:last)
y_order.each_cons(2) do |from, to|
  x1, y1 = from
  x2, y2 = to
  from_node = nodes[from.to_s]
  to_node = nodes[to.to_s]
  cost = [(x1-x2).abs, (y1-y2).abs].min
  
  edges << [from_node, to_node, cost]
end

edges = edges.sort_by(&:last)
uf = UnionFind.new(n+1)
result=0
edges.each do |from, to, cost|
  next if uf.same_parent?(from, to)

  uf.unite(from, to)
  result+=cost
end

#p x_order
#p y_order

p result






Measured memory_bytes: 51380
#include <stdio.h>
#include <iostream>

#define ll long long int

int main() {
  int l, r;
  int modi, modj;
  int min=2019, ans;
  std::cin >> l >> r;

  for(int i = l; i < r && i < (l+2019); i++) {
      for(int j = i+1; j <= r && j < (i+2020); j++) {
      ans = ((i%2019) * (j%2019)) % 2019;
      if(ans < min) min = ans;
    }
  }
  std::cout << min << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, k;
bool used[100009];

bool compare(vector<ll> a, vector<ll> b){return a[0] > b[0];}

int main() {
	cin >> n >> k;
	vector<vector<ll>> t(n+1, vector<ll>(2));
	for(ll i = 1; i <= n; i++){cin >> t[i][1] >> t[i][0]; used[i] = false;}
	sort(t.begin()+1, t.end(), compare);
	
	ll score = 0;
	ll color = 0;
	priority_queue<ll, vector<ll>, greater<ll>> q;
	for(ll i = 1; i <= k; i++){
		score += t[i][0];
		if(used[t[i][1]]){q.push(t[i][0]);}
		else{
			used[t[i][1]] = true;
			color++;
		}
	}
	score += color*color;
	
	ll bufscore = score;
	for(ll i = k+1; i <= n; i++){
		if(!q.empty() && !used[t[i][1]]){
			used[t[i][1]] = true;
			ll min = q.top(); q.pop();
			bufscore += t[i][0]-min+2*color+1;
			if(bufscore > score){score = bufscore;}
			color++;
			//cout << bufscore << color << endl;
		}
	}
	
	cout << score << endl;
	//for(ll i = 1; i <= n; i ++){cout << i << " " << t[i][0] <<  " " << t[i][1] << endl;}
	//for(ll i = 1; i <= n; i++){cout << used[i] << endl;}
	return 0;
}

Measured memory_bytes: 6396
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll

int32_t main(){ _
    char c;
    cin >> c;
    cout << char (c + 1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
const ll inf = 1e18+5;
int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	ll ans = -inf;
	for(int v: {a,b}) {
		for(int u: {c,d}) {
			ans = std::max(ans, ((long long int)u*v));
		}
	}	
	cout<<ans;
}


Measured memory_bytes: 3580
fn main() {
    proconio::input! {
        n: usize,
        k: usize,
    }
    let mut count = 0usize;
    let mut v = vec![0; k];
    for i in 1..=n {
        v[i % k] += 1;
    }
    for amk in 0..k {
        let bmk = (k - amk) % k;
        let cmk = (k - amk) % k;
        if (bmk + cmk) % k != 0 {
            continue;
        }
        count += v[amk] * v[bmk] * v[cmk];
    }
    println!("{}", count);
}


Measured memory_bytes: 2752
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sstream>

using namespace std;

int main(){
    unsigned long N, sum;
    cin >> N; sum = 0;

    vector<unsigned long> A(N+1), B(N);
    for(unsigned long i = 0; i < N + 1; ++i) cin >> A[i];
    for(unsigned long i = 0; i < N;     ++i) cin >> B[i];

    for(unsigned long i = 0; i < N; ++i){
        if(A[i] >= B[i]){
            sum += B[i];
            A[i] -= B[i];
            B[i] = 0;
        }else{
            sum += A[i];
            B[i] -= A[i];
            A[i] = 0;
            if(A[i+1] >= B[i]){
                sum += B[i];
                A[i+1] -= B[i];
                B[i] = 0;
            }else{
                sum += A[i+1];
                B[i] -= A[i+1];
                A[i+1] = 0;
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>

#define REP(i, n) for(int i; i<n; i++)

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int sec;
    if(b<=c || d<=a){
        sec = 0;
    } else {
        sec = min(b, d)- max(a, c);
    }

    cout << sec << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
//#include "../cxx-prettyprint/prettyprint.hpp"

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

    std::vector<int> A(N + 2, 0);
    for (int i = 1; i <= N; i ++) {
        std::cin >> A[i];
    }

    int full_cost = 0;
    for (int i = 1; i <= N + 1; i ++) {
        full_cost += std::abs(A[i] - A[i - 1]);
    }

    for (int i = 1; i <= N; i ++) {
        std::cout << full_cost
                     - std::abs(A[i] - A[i - 1])
                     - std::abs(A[i + 1] - A[i])
                     + std::abs(A[i + 1] - A[i - 1]);
        std::cout << std::endl;
    }
}


Measured memory_bytes: 1664
#include <stdio.h>
int main()
{
    int a,b,c,i,ans=0;
    scanf("%d %d %d",&a,&b,&c);
    int s[a];
    for(i=0;i<a;i++)
    {
        scanf("%d",&s[i]);
        if(s[i]<b||s[i]>=c)
            ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,ans=1,i;
	string s;
	cin >> n;
	cin >> s;
	for(i=1; i<n; ++i){
		if(s[i]!=s[i-1]){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
N,M=map(int,input().split())
AB=[[] for _ in range(N)]
for i in  range(N):
    a,b=map(int,input().split())
    AB[i]=[a,b]

AB.sort()

ans=0
cnt=0
for i in range(N):
    if cnt+AB[i][1]<M:
        cnt+=AB[i][1]
        ans+=AB[i][0]*AB[i][1]
    else:
        ans+=(M-cnt)*AB[i][0]
        break
        
print(ans)

Measured memory_bytes: 20064
l = [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]
i = int(input())
print(l[i-1])


Measured memory_bytes: 2940
#include<stdio.h>
int check(void);
int check_2(void);
char step[200002];
int n,a,b,a_end,b_end;
int main(void){
    int i,flg,flg_2;
    for(i=0;i<200002;i++){
        step[i]=0;
    }
    scanf("%d %d %d %d %d",&n,&a,&b,&a_end,&b_end);
    scanf("%s",step);
    a--;
    b--;
    a_end--;
    b_end--;
    flg=0;
    flg_2=0;
    if(a_end==b_end){
        printf("No\n");
        return 0;
    }else if(b_end<a_end){
        flg=check();
        flg_2=check_2();
    }else{
        flg=check();
    }
    if(flg==0 && flg_2==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}
int check(void){
    int i,ren;
    ren=0;
    if(b_end>a_end){
        for(i=a;i<b_end;i++){
            if(step[i]=='#'){
                ren++;
            }else{
                ren=0;
            }
            if(ren==2){
                return 1;
            }
        }
    }else{
        for(i=a;i<a_end;i++){
            if(step[i]=='#'){
                ren++;
            }else{
                ren=0;
            }
            if(ren==2){
                return 1;
            }
        }
    }
    return 0;
}
int check_2(void){
    int i,ret=1;
    for(i=b;i<=b_end;i++){
        if(step[i-1]=='.' && step[i]=='.' && step[i+1]=='.'){
            ret=0;
        }
    }
    return ret;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/2
Solved on 2019/3/
@author: shinjisu
"""


# Educational Dynamic Programming
# import math
import numpy as np


def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**12


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def prob_A():  # Frog 1
    N = getInt()
    H = getIntList()
    dmp((N, H), 'N, H')
    c = zeros(N)
    c[1] = abs(H[1]-H[0])
    for i in range(2, N):
        c[i] = min(c[i-1] + abs(H[i]-H[i-1]),
                   c[i-2] + abs(H[i]-H[i-2]))
    dmp(c, 'c')
    return c[N-1]


def prob_B_TLE():  # Frog 2 3/16 TLE
    N, K = getIntList()
    H = getIntList()
    dmp((N, K, H), 'N, K, H')
    c = np.zeros(N)
    c[0] = 0
    for i in range(1, N):
        #c[i] = INF
        for j in range(max(0, i-K), i):
            c[i] = min(c[i], c[j] + abs(H[i]-H[j]))
    dmp(c, 'c')
    return c[N-1]


def prob_B():  # Frog 2 3/16 TLE
    N, K = getIntList()
    H = np.array(input().split(), dtype='int')
    dmp((N, K, H), 'N, K, H')
    c = np.zeros(N, dtype='int')
    c[0] = 0
    for i in range(1, N):
        c[i] = np.min(c[max(0, i-K):i] + np.abs(H[max(0, i-K):i] - H[i]))
    dmp(c, 'c')
    return c[N-1]


debug = False  # True False
ans = prob_B()
print(ans)
#for row in ans:
#    print(row)


Measured memory_bytes: 21960
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;
typedef string tring;

lint N, M;
string s;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> M;
	cin >> s;
	vector<lint> ans;
	IREP(i, N + 1) {
		if (i == 0) break;
		lint mv = M;
		while (s[max(0ll,  i - mv)] == '1') {
			mv--;
		}
		ans.push_back(min(i, mv));
		if (mv == 0) {
			cout << -1 << endl;
			return 0;
		}
		i -= mv;
		i++;
	}

	IREP(i, SZ(ans)) {
		cout << ans[i] << " ";
	}
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> A_sum(N + 1, 0);
    REP(i, N) A_sum[i + 1] = A_sum[i] + A[i];

    ll result = LLONG_MAX;
    FOR(i, 1, N) {
        PRINT(i);
        PRINT(A_sum[i]);
        PRINT(A_sum[N] - A_sum[i]);
        amin(result, abs(A_sum[i] - (A_sum[N] - A_sum[i])));
    }
    cout << result << endl;


    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define INF INT_MAX
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
   cin.tie(0);  
   ios::sync_with_stdio(false);
   char a[5];
   int f=0;
   cin>>a;
   //sort(a,a+4);
   FOR(i,3){
    if(a[i]==a[i+1]){
      f=1;
      break;
    }
   }
   if(f) cout<<"Bad"<<endl;
   else cout<<"Good"<<endl;
   return 0;
}



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

using namespace std;

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<int> L(M);
	vector<int> R(M);
	vector<int> p(Q);
	vector<int> q(Q);
	for (int i = 0; i < M; i++) cin >> L[i] >> R[i];
	for (int i = 0; i < Q; i++) cin >> p[i] >> q[i];

	vector<vector<int>> field(N, vector<int>(N, 0));

	for (int i = 0; i < M; i++) {
		field[L[i] - 1][R[i] - 1]++;
	}

	vector<vector<int>> s(N + 1, vector<int>(N + 1, 0));

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + field[i][j];
		}
	}

	for (int i = 0; i < Q; i++) {
		int num = s[q[i]][q[i]] - s[p[i] - 1][q[i]] - s[q[i]][p[i] - 1] + s[p[i] - 1][p[i] - 1];
		cout << num << endl;
	}


	return 0;
}


Measured memory_bytes: 7436
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>

using namespace std;

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

   string B,C;
   cin>>B>>C;
   cout<<endl;
   for(int i=0;i<A;i++){

       cout<<B[i];
       cout<<C[i];
   }

   return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    private static int INF = 300005;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[A];
        int[] b = new int[B];
        int minA = INF;
        for (int i = 0; i < A; i++) {
            a[i] = sc.nextInt();
            minA = Math.min(minA, a[i]);
        }
        int minB = INF;
        for (int i = 0; i < B; i++) {
            b[i] = sc.nextInt();
            minB = Math.min(minB, b[i]);
        }
        int ans = minA+minB;
        for (int i = 0; i < M; i++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            int c = sc.nextInt();
            ans = Math.min(ans, a[x]+b[y]-c);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 152588
#include <iostream>
#include <cstdint>

static int64_t solve(int64_t m, int64_t n, int64_t mod);
static int64_t mod_comb(int64_t n, int64_t k, int64_t mod);
static int64_t mod_inv(int64_t a, int64_t m);
static int64_t mod_mul(int64_t a, int64_t b, int64_t m);

int main()
{
    int64_t m, n;
    std::cin >> n >> m;
    std::cout << solve(m, n, 1000000007) << std::endl;

    return 0;
}

static int64_t solve(int64_t m, int64_t n, int64_t mod)
{
    int64_t i = 2;
    int64_t x = m;
    int64_t r = 1;

    while (i * i <= x) {
        int64_t c = 0;
        while (x % i == 0) {
            c++;
            x /= i;
        }

        if (c != 0) {
            r = mod_mul(r, mod_comb(c + n - 1, c, mod), mod);
        }

        i++;
    }

    if (x != 1) {
        r = mod_mul(r, n, mod);
    }

    return r;
}

static int64_t mod_comb(int64_t n, int64_t k, int64_t mod)
{
    int64_t r = 1;

    for (int64_t i = 1; i <= k; i++) {
        r = mod_mul(r, n - k + i, mod);
        r = mod_mul(r, mod_inv(i, mod), mod);
    }

    return r;
}

static int64_t mod_inv(int64_t a, int64_t m)
{
    int64_t p = a, q = m;
    int64_t x = 1, y = 0, u = 0, v = 1;

    while (q != 0) {
        int64_t k = p / q;
        int64_t np = q;
        int64_t nq = p % q;
        int64_t nx = u;
        int64_t ny = v;
        int64_t nu = x - k * u;
        int64_t nv = y - k * v;

        p = np;
        q = nq;
        x = nx;
        y = ny;
        u = nu;
        v = nv;
    }

    return mod_mul(x, 1, m);
}

static int64_t mod_mul(int64_t a, int64_t b, int64_t mod)
{
    int64_t r = a * b % mod;
    if (r < 0) {
        r += mod;
    }

    return r;
}


Measured memory_bytes: 888