akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/
struct Timer {
    int64_t start;
    const int64_t CYCLES_PER_SEC = 2800000000;
    Timer() { reset(); }
    void reset() { start = getCycle(); }
    inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
    inline int64_t getCycle() {
        uint32_t low, high;
        __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
        return ((int64_t)low) | ((int64_t)high << 32);
    }
};

Timer timer;

bool multicase = false;

ll n, m, k, w, num, a, b, c, d, e, h, q, ans, sum;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

ll x[500005], y[500005], z[500005];

void solve() {
    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> x[i];
        if (x[i] % 2 == 1 && i % 2 == 0) ans ++;
    }
    p(ans);
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
typedef unsigned long long uint64;
using namespace std;
int main(){
 int k;
 string s;
 cin >> k;
 cin >> s;
 if(s.length()>k){
    for(int i= 0;i<k;i++){
        cout << s[i] ;
    }
    cout << "..." << endl;
    return 0;
 }
 cout << s << endl;
return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

def func():
    N = int(input())

    A = list(map(int, input().split()))
    P = [[(A[0], 0), (0, 0)] for i in range(2 ** N)]

    for i in range(1, 2 ** N):
        Ai = A[i]
        Pi = P[i]
        if (Ai, i) > Pi[0]:
            Pi[1] = Pi[0]
            Pi[0] = (Ai, i)
        elif (Ai, i) > Pi[1]:
            Pi[1] = (Ai, i)
        for j in range(N):
            if (i & (1 << j)) == 0:
                Pindex = P[i + (1 << j)]
                for k in range(2):
                    if Pi[k] > Pindex[0]:
                        Pindex[1] = Pindex[0]
                        Pindex[0] = Pi[k]
                    elif Pi[k] > Pindex[1] and Pi[k] != Pindex[0]:
                        Pindex[1] = Pi[k]
    ans = 0
    for i in range(1, 2 ** N):
        ans = max(ans, P[i][0][0] + P[i][1][0])
        print(ans)
    #print(P)

func()

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

int main()
{
    ll k;
    cin>>k;

    ll x= 7;
    int cnt= 1;

    while(x<k)
        x*= 10, x+= 7, cnt++;

    map<ll,bool>mp;

    while(x%k!=0)
    {
        if( mp[x%k] )
            return cout<<"-1", 0;

        mp[x%k]= 1;
        x%= k;
        x*= 10;
        x+= 7;
        cnt++;
    }

    cout<<cnt<<endl;
}


Measured memory_bytes: 65980
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
    int N, M;
    cin >> N >> M;
    
    int cities[N];
    for (int i = 0 ; i < N; i++) cities[i] = 0;
    
    for (int i = 0; i < M; i++) {
        int city1, city2;
        cin >> city1 >> city2;
        cities[city1 - 1]++;
        cities[city2 - 1]++;
    }
    
    for (int i = 0 ; i < N; i++)
        cout << cities[i] << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <complex>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;
typedef long long ll;
typedef map<ll,ll> mi;
typedef vector<ll> vi;
mi open[3],closed[3];
ll fish[50][2][3];
bool search(int x,int y,int z,int l){
	int num[3]={x,y,z};
	num[0]=x;
	num[1]=y;
	num[2]=z;
	REP(i,3){
		if(fish[l][0][i]<=num[i] && fish[l][1][i]>=num[i]+1)
		continue;
		return false;
	}
	return true;
}
int main() {
	ll N,K;
	vi points[3];
	cin >> N >> K;
	REP(i,N)
		REP(j,2)
			REP(k,3){
				cin >> fish[i][j][k];
				points[k].push_back(fish[i][j][k]);
			}
	REP(i,3){
	points[i].push_back(0);
	sort(points[i].begin(),points[i].end());
	int count =0;
	REP(j,(int)points[i].size())
		if(j==1 || points[i][j]!=points[i][j-1]){
			open[i].insert(mi::value_type(count,points[i][j]));
			closed[i].insert(mi::value_type(points[i][j],count));
			count++;
		}
	}
	REP(i,N)
		REP(j,2)
			REP(k,3){
				fish[i][j][k]=closed[k][fish[i][j][k]];
				
		}
	ll sum=0;
	REP(i,open[0].size()-1)
		REP(j,open[1].size()-1)
			REP(k,open[2].size()-1){
				int count=0;
				REP(l,N)
				count+=search(i,j,k,l);
				if(count>=K)
				sum+=(open[0][i+1]-open[0][i])*(open[1][j+1]-open[1][j])*(open[2][k+1]-open[2][k]);
			}
	cout << sum << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1260
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	h := nextInt()
	d := math.Floor(math.Log2(float64(h))) + 1
	l := int(math.Pow(2, d)) - 1
	fmt.Printf("%d", l)
}


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

int main()
{
	int a;
	vector<int>v;
	for (int i = 1; i <= 10; i++)
	{
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for (int i = 0; i < 3; i++)cout << v[i] << endl;
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> HB(300010, 0), WB(300010, 0);
  map<pair<ll,ll>, ll> A;
  rep(i, M){
    ll h, w;
    cin >> h >> w;
    A[{h, w}]++;
    HB[h]++;
    WB[w]++;
  }
  ll htmp=0, wtmp=0, ans=0;
  rep(i, 300001){
    chmax(htmp, HB[i]);
    chmax(wtmp, WB[i]);
  }
  ans = htmp + wtmp;
  vector<ll> hkeep, wkeep;
  rep(i, 300001){
    if (HB[i] == htmp)
      hkeep.emplace_back(i);
    if (WB[i] == wtmp)
      wkeep.emplace_back(i);
  }
  for(auto vh: hkeep){
    for(auto vw: wkeep){
      if (A[{vh, vw}] == 0){
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;  
}


Measured memory_bytes: 33020
import math

a,b,h,m=map(int,input().split())
seconds=h*60+m
kaku=seconds*5.5
k_kaku=kaku%360
if k_kaku>180:
  g_kaku=360-k_kaku
else :
  g_kaku=k_kaku
p_kaku=math.radians(g_kaku)
cos=math.cos(p_kaku)
l=a**2+b**2-2*a*b*cos
len=math.sqrt(l)
print(len)


Measured memory_bytes: 9508
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int N, M, P, X[105];

int main() {
  while(1){
      cin>>N>>M>>P;
      if(N==0 && M==0 && P==0) break;
      int sum=0;
      map<int,int> m;
      REP(i,0,N){
        cin>>X[i];
        m[i] = X[i];
        sum += X[i]*100;
      }
      if(m[M-1] != 0) cout<<sum*(100-P)/100/m[M-1]<<endl;
      else cout<<0<<endl;
  }


  return 0;
}

Measured memory_bytes: 3100
#![allow(dead_code)]
#![allow(unused)]
use proconio::input;

mod union_find {
    pub struct UnionFind { pub(self) list: Vec<i32> }
    impl UnionFind {
        pub fn new(size: usize) -> UnionFind { UnionFind{ list: vec![-1; size] } }
        pub fn root(&self, n: usize) -> usize { if self.list[n] < 0 { n } else { self.root(self.list[n] as usize) } }
        pub fn size_at(&self, n: usize) -> i32 { std::cmp::max(0, -self.list[n]) }
        pub fn unite(&mut self, x: usize, y: usize) {
             let (mut x_root, mut y_root) = (self.root(x), self.root(y));
              if(x_root == y_root) { return; } 
              if(self.list[x_root] > self.list[y_root]) { std::mem::swap(&mut x_root, &mut y_root); } 
              self.list[x_root] += self.list[y_root]; 
              self.list[y_root] = x_root as i32; }
        pub fn are_in_same_tree(self, x: usize, y: usize) -> bool { self.root(x) == self.root(y) }  
    }
}

fn main() {
    input!{n: usize, m: usize}
    let mut uf = union_find::UnionFind::new(n);
    for _ in 0..m {
        input!{a: usize, b: usize}
        uf.unite(a - 1, b - 1);
    }
    let mut max = 0;
    for i in 0..n {
        max = std::cmp::max(max, uf.size_at(i));
    }
    println!("{}", max);
}

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

int main(){
  while(true){
    int x,y,s;
    int mx = 0;
    cin>>x>>y>>s;
    if(x==0&&y==0&&s==0) break;
    for(int t=1;t<s;t++){
      for(int u=1;u<s;u++){
        if((t*(100+x)/100+u*(100+x)/100)==s){
          mx = max(mx,(t*(100+y)/100+u*(100+y)/100));
        }
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}



Measured memory_bytes: 3056
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int h, w;
	cin >> h >> w;
	vector<vi> c(10, vi(10));
	rep(i, 10) rep(j, 10) cin >> c[i][j];
	vector<vi> a(h, vi(w));
	rep(i, h) rep(j, w) cin >> a[i][j];

	rep(k, 10) rep(i, 10) rep(j, 10) chmin(c[i][j], c[i][k] + c[k][j]);
	int ans = 0;
	rep(i, h) rep(j, w) if(a[i][j] != -1) ans += c[a[i][j]][1];
	cout << ans << endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	int r;
	while(cin>>r)
	{
		if(r<1200)
			cout<<"ABC"<<endl;
		else if(r<2800)
			cout<<"ARC"<<endl;
		else
			cout<<"AGC"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100


void trace(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}



int main(){
  int n,i,j,flag=1,k=0,kaunt=0;//k=hozon
  int A[N];

  scanf("%d",&n);
  for(i =0;i<n;i++)scanf("%d",&A[i]);

  while(flag){
    flag = 0;
    for(j=n-1;j>=1;j--){
      if(A[j]<A[j-1]){
	k=A[j];
	A[j]=A[j-1];
	A[j-1]=k;
	flag = 1;
	kaunt++;	
      }
    }
  }

  

  trace(A,n);
  printf("%d\n",kaunt);
  
  return 0;
}

Measured memory_bytes: 2744
N = int(input())
C = []

for i in range(N):
  x, y, z = map(int, input().split())
  C.append((x, y, z))

for X in range(101):
  for Y in range(101):

    for i in range(N):
      x, y, h = map(int, C[i])
      if h > 0:
        htop = abs(x-X) + abs(y-Y) + h
    
    for i in range(N):
      x, y, h = map(int, C[i])
      if h == 0:
        if htop - (abs(x-X) + abs(y-Y)) > 0:
          break
      if h > 0:
        if htop - (abs(x-X) + abs(y-Y)) != h:
          break
    else:
      print(X, Y, htop)
      exit()

Measured memory_bytes: 3064
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int cnt=0;
  string s;
  cin >> s;
  if(s.size()%2) {
    cout << "No" << endl;
  }
  else {
    for(int i=0; i<s.size(); i++) {
      if(s[i]=='h'&&s[i+1]=='i') {
        cnt++;
        i++;
      }
    }
    if(cnt*2==s.size()) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

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

#define rep(i, n) for(int i = 0; i < n;i++)

int main()
{
    int W, H, N;
    int W0 = 0, H0 = 0;
    cin >> W >> H >> N;
    vector<int> x(N), y(N), a(N);
    rep(i, N){
        cin >> x.at(i) >> y.at(i) >> a.at(i);
    }
    rep(i, N){
        if(a.at(i) == 1){
            W0 = max(W0, x.at(i));
        }else if(a.at(i) == 2){
            W = min(W, x.at(i));
        }else if(a.at(i) == 3){
            H0 = max(H0, y.at(i));
        }else if(a.at(i) == 4){
            H = min(H, y.at(i));
        }
    }

    if(W0 >= W || H0 >= H){
        cout << 0 << endl;
    }else{
        cout << (W - W0) * (H - H0) << endl;
    }
}



Measured memory_bytes: 256
def main():
    n,k,q = list(input().split())
    answer = [0]*int(n)
    for i in range(int(q)):
        num = int(input())
        answer[num-1] += 1

    diff = int(q) - int(k)

    for i in answer:
        if i > diff:
            print("Yes")
        else:
            print("No")


if __name__ =="__main__":
    main()


Measured memory_bytes: 4680
#include<stdio.h>
#define N 8
 
int a[N][N]={0};
 
 
 
void printboard(){
    int i,j;
     
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(a[i][j]==1)printf("Q");
            else printf(".");
        }
        printf("\n");
    }
 
    return; 
}
 
 
int check(int y,int x){
    int i,j;
     
    /*横*/
    for(i=0;i<N;i++){
        if(i!=x && a[y][i]==1)return 0;
    }
    /*縦*/
    for(i=0;i<N;i++){
        if(i!=y && a[i][x]==1)return 0;
    }
    /*右上*/
    i=y-1; j=x+1;
    while(i>=0 && j<N){
        if(a[i--][j++]==1)return 0;
    }
    /*左上*/
    i=y-1; j=x-1;
    while(i>=0 && j>=0){
        if(a[i--][j--]==1)return 0;
    }
    /*左下*/
    i=y+1; j=x-1;
    while(i<N && j>=0){
        if(a[i++][j--]==1)return 0;
    }
    /*右下*/
    i=y+1; j=x+1;
    while(i<N && j<N){
        if(a[i++][j++]==1)return 0;
    }
     
    return 1;
     
}
 
 
int Get_Solution(int d){
    int i;
     
    for(i=0;i<N;i++){
        if(a[d][i]==1){
            if(!Get_Solution(d+1))return 0;
        }
    }
     
 
    if(d==N){
        printboard();
        return 1;
    }
     
    else {
        for(i=0;i<N;i++){
            if(a[d][i]==0 && check(d,i)){
                a[d][i]=1;
                if(!Get_Solution(d+1)){
                    a[d][i]=0;
                }
            }
        }
    }
     
     
    return 0;
 
}
 
int main(){
    int n,i,j;
    int x,y;
    int d=0;
     
    scanf("%d",&n);
     
    for(i=0;i<n;i++){
        scanf("%d %d",&y,&x);
        a[y][x]=1;
    /*  update(y,x);*/
    }
     
    i=Get_Solution(d);
 
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X;
  int a = 1;
  cin>>X;
  vector<int> vec(X);
  for(int i=0;i<X;i++)
    cin>>vec.at(i);
  sort(vec.begin(),vec.end());
  for(int i=0;i<X-1;i++){
    if(vec.at(i) < vec.at(i+1))
      a++;
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222



ll dp[111][MAX], sum[MAX];



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


  cin >> n >> m;
  dp[0][0] = 1;
  rep(i, n) {
    cin >> tmp;
    rep(j, m + 1) sum[j] = 0;
    rep(j, m + 1) {
      (sum[j] = sum[max(0LL, j - 1)] + dp[i][j]) %= mod;
      dp[i + 1][j] = sum[j];
      if (j - tmp - 1 >= 0) (dp[i + 1][j] += mod - sum[j - tmp - 1]) %= mod;
    }
  }
  cout << dp[n][m] << endl;



  return 0;
}

Measured memory_bytes: 177152
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
string t = "hi";

int main(){
	string s;
	cin >> s;
	if(s.size() % 2 == 1){
		cout <<"No" << endl;
		return 0;
	}
	rep(i, s.size()){
		if(s[i] != t[i%2]){
			cout << "No" << endl; 
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;

int32_t main()
{
  uint32_t A, B;
  cin >> A >> B;

  if (A == B) {
    cout << "Draw";
  } else if (A == 1) {
    cout << "Alice";
  } else if (B == 1) {
    cout << "Bob";
  } else if (A < B) {
    cout << "Bob";
  } else {
    cout << "Alice";
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int numA = scanner.nextInt();
        int numB = scanner.nextInt();
        int numC = scanner.nextInt();
        int ans = 0;
        
        for (int val = numA;val <= numB;val++){
        	if(numC % val == 0) ans++;
        }	
        System.out.println(ans);	
	}	
}

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

using namespace std;

int main (void) {
    int x;

    for ( int i = 1; i <= 5; i++ ) {
        cin >> x;
        if ( x == 0 ) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>

using namespace std;

int n, cnt;
int a[25], b[25], c[25];

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
    for(int i = 1; i <= n - 1; i++) scanf("%d", &c[i]);
    for(int i = 1; i <= n; i++)
    {
        cnt += b[a[i]];
        if(i != 0 && a[i] - 1 == a[i - 1]) cnt += c[a[i] - 1];
    }
    printf("%d", cnt);
    return 0;
}


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

using namespace std;

int main() {
	
	double r, S, L;
	const double PI = 3.14159265358979;
	cin >> r;

	S = r * r*PI;
	L = 2 * r*PI;

	cout << fixed << setprecision(6) << S << " " << L << endl;


}


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

long N, S;
vector<long> A(100000);

int main(void) {

    cin >> N;
    for (long i = 0; i < N; i++) {
        long a; cin >> a;
        A[a]++;
        S += a;
    }
    long Q; cin >> Q;
    for (long i = 0; i < Q; i++) {
        long b, c;
        cin >> b >> c;
        S -= b * A[b];
        S += c * A[b];
        A[c] += A[b];
        A[b] = 0;
        cout << S << endl;
    }


    return 0;
}

Measured memory_bytes: 3816
#include<stdio.h>

int main(){
  int num1,num2,temp,rem;
  
  scanf("%d%d",&num1,&num2);
  
  if(num1<num2){
    temp=num1;
    num1=num2;
    num2=temp;
  }

  rem=num1%num2;

  
  while(1){
    if(rem==0)break;
    
    else{
      num1=num2;
      num2=rem;
      rem=num1%num2;
    }
  }

  printf("%d\n",num2);
  return 0;
}



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

int H, W;
int c[10][10], d[10][10];
int A[210][210];

void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       
    for (int i = 0; i < n; i++) {    
      for (int j = 0; j < n; j++) {  
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
            d[i][j] = c[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }

    warshall_floyd(10);

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] != -1) {
                ans += d[A[i][j]][1];
            }
        }
    }

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


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

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll a = X, cnt = 0;
  while (a <= Y) {
    cnt++;
    a *= 2;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

int n,k;
long long x[100005];

long long calc(int st){
        int ed = st+k-1;

        return min(abs(x[st]),abs(x[ed]))+abs(x[ed]-x[st]);

}

int main(){

        cin>>n>>k;
        for(int i=0;i<n;i++)cin>>x[i];

        long long ans = 5*100000000;
        for(int i=0;i<n-k+1;i++){
                ans = min(ans,calc(i));
        }
        cout<<ans<<endl;

        return 0;

}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

void DispArr(int32_t arr[], int32_t len) {
	printf("%d", arr[0]);
	for (int32_t i = 1; i < len; i++) {
		printf(" %d", arr[i]);
	}
	putchar('\n');
}

void InsertionSort(int32_t arr[], int32_t len) {
	DispArr(arr, len);
	for (int32_t i = 1; i < len; i++) {
		int32_t target = arr[i];
		int32_t j = i - 1;
		for (; j >= 0 && arr[j] > target; j--) {
			arr[j+1] = arr[j];
		}
		arr[j+1] = target;
		DispArr(arr, len);
	}
}

int main() {
	int32_t dataNum;
	scanf("%d", &dataNum);

	int32_t *data = (int32_t *)calloc(dataNum, sizeof(int32_t));
	if (!data) return 1;

	for (int32_t i = 0; i < dataNum; i++) {
		scanf("%d", &data[i]);
	}
	
	InsertionSort(data, dataNum);
	return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)
    // {
       
    // }
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    for(ll i=0;i<m;i++)
    {
        ll x;
        cin>>x;
        sum+=x;
    }
    if(n>=sum)
    cout<<n-sum;
    else
    cout<<-1;
    
}


Measured memory_bytes: 3656
#include<iostream>

using namespace std;


int main(){

	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;

	if(((x-r >= 0) && (x+r <= W))&&((y-r >=0) && (y+r <=H))) cout << "Yes\n";
	else cout << "No\n";


	return 0;
}




Measured memory_bytes: 3076
import static java.lang.System.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int a=sc.nextInt(), b=sc.nextInt(), c=sc.nextInt(), d=sc.nextInt();
		int difAB = (int)Math.abs(a-b);
		int difBC = (int)Math.abs(b-c);
		int difAC = (int)Math.abs(a-c);
		if (difAB<=d && difBC<=d) {
			out.println("Yes");
		}
		else if (difAC <= d) out.println("Yes");
		else out.println("No");
	}
}

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

using namespace std;

class Dice{
private:
  int tmp;
public:
  int d[6];

  void rollN(){
    tmp = d[0];
    d[0] = d[1];
    d[1] = d[5];
    d[5] = d[4];
    d[4] = tmp;
  }
  void rollE(){
    tmp = d[0];
    d[0] = d[3];
    d[3] = d[5];
    d[5] = d[2];
    d[2] = tmp;
  }
  void rotation(){
    tmp = d[1];
    d[1] = d[3];
    d[3] = d[4];
    d[4] = d[2];
    d[2] = tmp;
  }
  bool operator < (const Dice &die)const{
    for(int i = 0 ; i < 6 ; i++){
      if(d[i] != die.d[i]) return d[i] < die.d[i];
    }
    return false;
  }
};

int N,ans,p[4];
map<string,int> mp;
vector<Dice> dice[4];

int getCost(){
  int res = 0;
  for(int i = 0 ; i < 6 ; i++){
    int cnt[25] = {0}, max = 0;
    for(int j = 0 ; j < N ; j++){
      cnt[dice[j][p[j]].d[i]]++;
      max = std::max(max,cnt[dice[j][p[j]].d[i]]);
    }
    res += N-max;
  }
  return res;
}

void solve(int x){
  if(x == N){
    ans = min(ans,getCost());
    return;
  }
  for(int i = 0 ; i < (int)dice[x].size() ; i++){
    p[x] = i;
    solve(x+1);
  }
}

vector<Dice> make(Dice die){
  vector<Dice> res;
  set<Dice> visited;
  for(int i = 0 ; i < 4 ; i++){
    for(int j = 0 ; j < 4 ; j++){
      if(!visited.count(die)){
        visited.insert(die);
        res.push_back(die);
      }
      die.rollN();
    }
    for(int j = 0 ; j < 4 ; j++){
      if(!visited.count(die)){
        visited.insert(die);
        res.push_back(die);
      }
      die.rollE();
    }
    die.rotation();
  }
  return res;
}

int main(){
  Dice in;
  while(cin >> N, N){
    int n = 0;
    mp.clear();
    for(int i = 0 ; i < N ; i++){
      p[i] = -1;
      for(int j = 0 ; j < 6 ; j++){
        string s;
        cin >> s;
        if(mp.find(s) != mp.end()){
          in.d[j] = mp[s];
        }else{
          mp[s] = n++;
          in.d[j] = mp[s];
        }
      }
      dice[i] = make(in);
    }
    ans = 1e9;
    solve(0);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1248
n = int(input())
data = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for _ in range(n):
    data[input()] += 1
print("AC x {}".format(data["AC"]))
print("WA x {}".format(data["WA"]))
print("TLE x {}".format(data["TLE"]))
print("RE x {}".format(data["RE"]))

Measured memory_bytes: 8964
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    reverse(A,A+N);
    if(A[0]!=2){
        cout << -1 << endl;
        return 0;
    }
    int ma=3,mi=2;
    rep(i,N-1){
        if(ma/A[i+1]-mi/A[i+1]<=0 && mi%A[i+1]!=0){
            cout << -1 << endl;
            return 0;
        } else {
            ma=ma/A[i+1]*A[i+1]+A[i+1]-1;
            mi=(mi+A[i+1]-1)/A[i+1]*A[i+1];
        }
    }
    cout << mi << " " << ma << endl;
}


Measured memory_bytes: 1024
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0;
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL k ;
    cin>>n>>k; 
    string s ; 
    cin>>s ; 
    vector <pair<LL,LL> > V ; 
    if(s[0]=='0')
    V.pb({0,-1}) ; 
    LL cnt = 0 ;
    for(int i=0;i<sz(s);i++)
    {  if(s[i]=='1') cnt++ ;
       else
       {   if(cnt)
           V.pb({cnt,i-cnt}),ans = max(ans,cnt) ; 
          cnt = 0 ;  
       }
    }
    if(cnt) V.pb({cnt,sz(s)-cnt}) ; 
    else V.pb({1,sz(s)}) ; 
    if(k>sz(V)-2) ret cout<<sz(s),0 ; 
    int l =  k ;
    for(int i=0;i<sz(V)-l;i++)
    {  if(V[i].S==-1) V[i].S = 0 ; 
        if(V[k].S==sz(s)) V[k].S = sz(s) -1 ; 
       ans = max(ans,V[k].S - V[i].S + 1 + V[k].F - 1) ; 
       k++ ; 

    }
    cout<<ans<<endl; 
}
//Check for 0,1 and other corner cases.

Measured memory_bytes: 1528
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr = (input.trim()).split("\n");

const binarySearch = (key, arr, N) => {
  let mid;
  let left = 0;
  let right = N;
  while (left < right) {
    mid = Math.floor((left + right) / 2);
    if (key < arr[mid]) right = mid;
    else if (key > arr[mid]) left = mid + 1;
    else return 1;
  }
  return 0;
}


(function() {
  const N1 = Number(Arr[0]);
  const arr1 = Arr[1].split(" ").map(Number);
  // const N2 = Number(Arr[2]);
  const arr2 = Arr[3].split(" ").map(Number);
  console.log(arr2.map(e => binarySearch(e, arr1, N1)).reduce((a, b) => a + b, 0));
})();



Measured memory_bytes: 34896
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
using namespace std;
int main()
{
    ///MUST READ THE POINTS BELOW BEFORE SUBMIT

    ll n;
    cin >> n;
    if(n >= 400 and n <= 599) cout << 8 << endl;
    if(n >= 600 and n <= 799) cout << 7 << endl;
    if(n >= 800 and n <= 999) cout << 6 << endl;
    if(n >= 1000 and n <= 1199) cout << 5 << endl;
    if(n >= 1200 and n <= 1399) cout << 4 << endl;
    if(n >= 1400 and n <= 1599) cout << 3 << endl;
    if(n >= 1600 and n <= 1799) cout << 2 << endl;
    if(n >= 1800 and n <= 1999) cout << 1 << endl;

    return 0;
    ///MUST READ THE POINTS BELOW BEFORE SUBMIT
}
/**
    1. LOOK SPECIAL CASE N = 1.
    2. LOOK FOR OVERFLOW.
    3. LOOK FOR OUT OF BOUNDS.
**/


Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1e9
#define PI acos(-1)
typedef long long ll;


int main() {
	
	string str, t;
	bool flag = false;
	cin >> str >> t;
	
	int n = t.size(); 

	for (int i = str.size() - n; i >= 0; i--) {
		if (flag)break;
		if (str[i] == t[0] || str[i] == '?') {
			bool check = true;
			string tmp = str.substr(i, n);

			for (int j = 0; j < n; j++) {
				if (tmp[j] != t[j] && tmp[j] != '?') {
					check = false;
					break;
				}
			}

			if (check) {
				for (int k = i; k < i + n; k++) {
					str[k] = t[k - i];
				}
				flag = true;
			}
		}
	}

	for (int i = 0; i < str.size(); i++) {
		if (str[i] == '?')str[i] = 'a';
	}
	
	cout << ((flag) ? str : "UNRESTORABLE") << endl;
	
	return 0;
}

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

int main() {
    int N,L;
    cin >> N >> L;
    int aji=0;
    vector<int> V(N),Z(N);
    for (int i=0 ; i<N ; i++)
        V.at(i)=(L+i);
    Z=V;
    for (int i=0 ; i<N ; i++)
        Z.at(i)=abs(Z.at(i));
    sort(Z.begin(),Z.end());
    for (int i=0 ; i<N ; i++)
        aji+=V.at(i);
    if (L<0)
        cout << aji+Z.at(0) << endl;
    else if (L>=0)
        cout << aji-Z.at(0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int inf=1000000007;
int rest=1000000007;
long long modinv(long long a, long long m) {
  m=rest;
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int conb(int i,int k,vector<int> const& kaijo){
  int res=kaijo[i];
  res*=modinv(kaijo[k],rest);
  res%=rest;
  res*=modinv(kaijo[i-k],rest);
  res%=rest;
  return res;
}
signed main(){
  int n,k;cin>>n>>k;
  vector<int> a(n);
  vector<int> kaijo(n,1);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  rep1(i,n-1){
    kaijo[i]=kaijo[i-1]*i;
    kaijo[i]%=rest;
  }
  vector<int> smax(n,0);
  vector<int> smin(n,0);
  for(int i=n-1;i>=0;i--){
    if(i>=k-1)
    smax[i]=conb(i,k-1,kaijo);
  }
  rep(i,n){
    if(n-1-i>=k-1)
    smin[i]=conb(n-1-i,k-1,kaijo);
  }
  int ans=0;
  rep(i,n){
    ans+=a[i]*smax[i]-a[i]*smin[i]+rest;
    ans%=rest;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
//#include <algorithm>
//#include <iostream>
//#include <cstring>
//#include <cstdlib>
//#include <cstdio>
//#include <cmath>
//#include <queue>
//#include <set>
//#include <map>
//#define N 1005

#include <bits/stdc++.h>

using namespace std;

int num[100005];

bool comp(int a, int b)
{
    return a > b;
}
int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n ; i++)
    {
        scanf("%d", &num[i]);
    }

    sort(num, num + n, comp);

    int a = 0, b = 0, a1 = 0, b1 = 0;

    for(int i = 1; i < n; i++)
    {
        if(num[i] == num[i - 1] && a1 == 0)
        {
            a1 = 1;
            a = num[i];
            i++;
        }
        else if(a1 == 1 && num[i] == num[i - 1] && b1 == 0)
        {
            b = num[i];
            b1 = 1;
            i++;
        }
        else if(a1 == 1 && b1 == 1)
        {
            break;
        }
    }
    cout <<(long long ) a * b << endl;
    return 0;
}


Measured memory_bytes: 640
def factor(n):
    r = set()
    if n % 2 == 0:
        while n % 2 == 0:
            n //= 2
        r.add(2)
    i = 3
    while i * i <= n:
        if n % i == 0:
            while n % i == 0:
                n //= i
            r.add(i)
        i += 2
    if n > 1:
        r.add(n)
    return r

def main():
    N = int(input())
    A = list(map(int, input().split()))
    pairwise = True
    onef = factor(A[0])
    allf = onef.copy()
    
    for a in A[1:]:
        fa = factor(a)
        if pairwise:
            for f in fa:
                if f in onef:
                    pairwise = False
                    break
                onef.add(f)
        allf &= fa
        if not pairwise and not allf:
            return 'setwise coprime'
    if pairwise:
        return 'pairwise coprime'
    if len(allf) == 0:
        return 'setwise coprime'
    return 'not coprime'

print(main())


Measured memory_bytes: 205040
import java.util.*

data class Rail(val to: Int, val cost: Long)
data class Station(val id:Int) {
    private val mRails: MutableCollection<Rail> = Stack()
    val rails: Iterable<Rail>
        get() = mRails
    fun addRail(to: Int, cost:Int): Unit {
        mRails.add(Rail(to, cost.toLong()))
    }
}
fun calMinCostFrom(from: Int, stations: Array<Station>): LongArray {
    val res = LongArray(stations.size){ Long.MAX_VALUE}.apply { this[from] = 0L }
    val queue = PriorityQueue<Pair<Int, Long>>(compareBy(Pair<Int, Long>::second)).apply { add(from to 0L) }
    while (queue.isNotEmpty()) {
        if (res[queue.peek().first] == queue.peek().second) {
            val (to, current) = queue.poll()
            for ((next, cost) in stations[to].rails) {
                if (res[next] > current + cost) {
                    res[next] = current + cost
                    queue.add(next to res[next])
                }
            }
        }else queue.poll()
    }
    return res
}
class MutablePair<A, B>(var first:A, var second:B)
fun calMinPath(t:Int, minFromS: LongArray, minFromU: LongArray, minFromV: LongArray, stations: Array<Station>): Long {
    val memo = Array(stations.size){ MutablePair(minFromU[it], minFromV[it])}
    val isSearching = BooleanArray(stations.size){false}.apply{this[t] = true}
    val queue = PriorityQueue<Pair<Int, Long>>(compareByDescending(Pair<Int, Long>::second)).apply { add(t to minFromS[t]) }
    while (queue.isNotEmpty()){
        val (to, current) = queue.poll()
        for ((next, cost) in stations[to].rails) {
            if (minFromS[next] == current - cost) {
                if (memo[next].first > memo[to].first) memo[next].first = memo[to].first
                if (memo[next].second > memo[to].second) memo[next].second = memo[to].second
                if (!isSearching[next]){
                    isSearching[next] = true
                    queue.add(next to minFromS[next])
                }
            }
        }
    }
    return minOf(minFromU.withIndex().map{(i, l) -> l + memo[i].second}.min()!!, minFromV.withIndex().map{(i, l) -> l + memo[i].first}.min()!!)
}
fun main(args:Array<String>): Unit {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val (s, t) = readLine()!!.trim().split(' ').map(String::toInt)
    val (u, v) = readLine()!!.trim().split(' ').map(String::toInt)
    val stations = Array(n){Station(it)}
    repeat(m){
        val (a, b, c) = readLine()!!.trim().split(' ').map(String::toInt)
        stations[a - 1].addRail(b - 1, c)
        stations[b - 1].addRail(a - 1, c)
    }
    val minCostFromS = calMinCostFrom(s - 1, stations)
    val minCostFromU = calMinCostFrom(u - 1, stations)
    val minCostFromV = calMinCostFrom(v - 1, stations)
    println(calMinPath(t - 1, minCostFromS, minCostFromU, minCostFromV, stations))
}


Measured memory_bytes: 143604
ii=lambda:map(int,raw_input().split())
n,k=ii()
T,F=True,False
e=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=ii()
    e[a-1]+=[b-1];e[b-1]+=[a-1]
cost=[0]*n
ans=10**5
def dfs(x,f):
    if f>=0:vis[f]=T
    q=[(x,0)]
    while len(q):
        v,c=q.pop(0)
        if c>k/2:break
        cost[v]=c;vis[v]=T
        for w in e[v]:
            if not vis[w]:q+=[(w,c+1)]
    return n-vis.count(T)
if k%2:
    for i in range(n):
        for j in e[i]:
            if i<j:vis=[F]*n;dfs(i,j);ans=min(ans,dfs(j,i))
else:
    for i in range(n):vis=[F]*n;ans=min(ans,dfs(i,-1))
print ans


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

int main()
{
    double x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    cout<<fixed<<setprecision(6)<<sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))<<endl;
}




Measured memory_bytes: 3284
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)


import sys
import numpy as np

def z_algo(S):  # [z_algo, "i8[:](i8[:])"],
    # Z-algoirhm  O(n)
    # Z[i] := S と S[i:] で prefix が何文字一致しているか
    # 検証1: https://atcoder.jp/contests/abc150/submissions/15829530
    # 検証2: https://atcoder.jp/contests/abc141/submissions/15855247
    i, j, n = 1, 0, len(S)
    Z = np.zeros(S.shape, dtype=np.int64)
    Z[0] = n
    while i < n:
        while i+j < n and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        Z[i] = j
        d = 1
        while i+d < n and d+Z[d] < j:
            Z[i+d] = Z[d]
            d += 1
        i += d
        j -= d
    return Z

def solve(s, t):
    ns = len(s)
    nt = len(t)
    n = max(ns, nt) * 2
    ts = np.empty(n*4, dtype=np.int64)
    ts[:n*2] = t[np.arange(2*n, dtype=np.int64) % nt]
    ts[n*2:] = s[np.arange(2*n, dtype=np.int64) % ns]
    Z = z_algo(ts)
    ma = Z[n*2:].max()
    if ma > n:
        return -1
    else:
        return ma // nt

numba_compile([
    [z_algo, "i8[:](i8[:])"],
    [solve, "i8(i1[:],i1[:])"],
])

def main():
    s = np.frombuffer(sys.stdin.buffer.readline()[:-1], dtype=np.int8).copy()
    t = np.frombuffer(sys.stdin.buffer.readline()[:-1], dtype=np.int8).copy()
    ans = solve(s, t)
    print(ans)

main()


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

int main()
{
	int i, j, n, count=0;
	cin >> n;
	vector <int> v1, v2;
	for(i=0; i<n; i+=1)
	{
		string s;
		cin >> s;
		int l=s.length();
		if(s[0]=='B')
			v1.push_back(i);
		if(s[l-1]=='A')
			v2.push_back(i);
		for(j=0; j<l-1; j+=1)
		{
			if(s[j]=='A' && s[j+1]=='B')
				count+=1;
		}
	}
	int x=v1.size(), y=v2.size(), flag=0;
	if(x!=y)
		count+=min(x,y);
	else
	{
		sort(v1.begin(),v1.end());
		sort(v2.begin(),v2.end());
		for(i=0; i<x; i+=1)
		{
			if(v1[i]!=v2[i])
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		{
			if(x!=0)
				count+=x-1;
		}
		else
			count+=x;
	}
	cout << count << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define M 100000
int main(){
  vector<bool>prime(M+1,true);
  vector<bool>prime2(M+1,false);
  vector<int>cumsum(M+1,0);
  for(int i=0;i<M+1;i++){
    if(i<2)prime[i]=false;
    else if(prime[i])for(int j=2;i*j<M+1;j++)prime[j*i]=false;
  }
  for(int i=0;i<(M+1)/2+1;i++)if(prime[i])prime2[i*2-1]=true;
  for(int i=1;i<M+1;i++)cumsum[i]=cumsum[i-1]+(prime[i]&&prime2[i]);

  int Q;cin>>Q;
  for(int i=0;i<Q;i++){
    int l,r;cin>>l>>r;
    cout<<cumsum[r]-cumsum[l-1]<<endl;
  }
  
}

Measured memory_bytes: 1024
import java.util.Scanner;

/**
 * C2
 */
public class Main {

    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int len = Integer.parseInt(sc.nextLine());
        final String[] line = sc.nextLine().split(" ");
        sc.close();
        final Card[] cardsForBubble = new Card[len];
        final Card[] cardsForSelect = new Card[len];
        for(int i=0; i<len; i++){
            cardsForBubble[i] = new Card(line[i]);
            cardsForSelect[i] = new Card(line[i]);
        }
        
        bubbleSort(cardsForBubble, len);
        selectionSort(cardsForSelect, len);
        StringBuilder val = new StringBuilder();

        for(int i=0; i<len; i++){
            val.append(cardsForBubble[i].card + " ");
        }
        System.out.println(val.toString().trim());
        System.out.println("Stable");

        val = new StringBuilder();
        Boolean isStable = true;
        for(int i=0; i<len; i++){
            if(cardsForBubble[i].card != cardsForSelect[i].card) isStable = false;
            val.append(cardsForSelect[i].card + " ");
        }
        System.out.println(val.toString().trim());
        if(isStable) System.out.println("Stable");
        else System.out.println("Not stable");
    }

    private static void bubbleSort(final Card[] arr, final int len){
        for(int i=0; i<len; i++){
            for(int j=len-1; j>i; j--){
                if(arr[j].number < arr[j-1].number){
                    final Card tmp = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = tmp;
                }
            }
        }
    }

    private static void selectionSort(final Card[] arr, final int len){
        for(int i=0; i<len; i++){
            int minj = i;
            for(int j=i; j<len; j++){
                if(arr[j].number < arr[minj].number){
                    minj = j;
                }
            }
            final Card tmp = arr[minj];
            arr[minj] = arr[i];
            arr[i] = tmp;
        }
    }
}

class Card{   
    public char mark;
    public int number;
    public String card;
    public Card(final String card){
        this.card = card;
        this.mark = card.charAt(0);
        this.number = Integer.parseInt(card.substring(1, 2));
    }
}


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

void solve()
{
	int N;
	cin >> N;
	set<string> ID;
	while(N--)
	{
		string str;
		cin >> str;
		ID.insert(str);
	}
	int M;
	cin >> M;
	bool flag = false;
	while(M--)
	{
		string str;
		cin >> str;
		if(ID.find(str) == ID.end())
		{
			cout << "Unknown " << str << endl;
		}
		else
		{
			if(!flag)
			{
				cout << "Opened by " << str << endl;
			}
			else
			{
				cout << "Closed by " << str << endl;
			}
			flag = !flag;
		}
	}
}

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

Measured memory_bytes: 1232