akhauriyash/Code-Regression huggingface dataset:
import heapq
if __name__ == "__main__":
    n,k = map(int,input().split())
    lst = [list(map(int,input().split())) for i in range(n)]
    selected = [False] * (n+1)
    pq = []
    lst.sort(key=lambda x:x[1], reverse=True)
    f = [0] * (n+1)
    cnt = 0
    res = 0
    for i in range(k):
        res += lst[i][1]
        if selected[lst[i][0]]:
            heapq.heappush(pq, lst[i][1])
        else:
            selected[lst[i][0]]=True
            cnt += 1
    f[cnt] = res
    now = k
    while len(pq)!=0 and now<n:
        diff=0
        while now < n and selected[lst[now][0]]:
            now +=1
        if now >= n:
            break
        diff -= heapq.heappop(pq)
        diff += lst[now][1]
        selected[lst[now][0]] = True
        cnt += 1
        f[cnt]=f[cnt-1]+diff
    res = 0 
    for i in range(n+1):
        if f[i]!=0 and f[i]+i**2>res:
            res=f[i]+i**2
    print("{}".format(res))
        



Measured memory_bytes: 29964
sx,sy,tx,ty=gets.split.map(&:to_i)
lr=Hash.new()
ud=Hash.new()
lr[1] = "R"
lr[-1] = "L"
ud[1] = "U"
ud[-1] = "D"

dx, dy = (sx-tx).abs, (sy-ty).abs
xx, yy = 1, 1

xx *=-1 if sx > tx
yy *=-1 if sy > ty

ans = ud[yy]*dy + lr[xx]*dx
ans += ud[-yy]*dy + lr[-xx]*dx

ans += lr[-xx] + ud[yy]*(dy+1) + lr[xx]*(dx+1) + ud[-yy]
ans += lr[xx] + ud[-yy]*(dy+1) + lr[-xx]*(dx+1) + ud[yy]

puts ans


Measured memory_bytes: 1916
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}
	}
}


Measured memory_bytes: 21076
import java.util.*;
public class Main{
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int a = sc.nextInt();
	  int b = sc.nextInt();
	  if(a<b*2)System.out.println(0);
	  else System.out.println(a-b*2);
	}
}

Measured memory_bytes: 21716
// Example program
#include<iostream>
using namespace std;
 
int main (){
  int  a;
  int  b;
  char op;
  while (true){
  
    cin >> a >> op >> b;
  
    if (op=='+'){
        cout << a+b << endl;
    }else if  (op=='-'){
        cout << a-b << endl;
    }else if  (op=='*'){
        cout << a*b << endl;
    }else if  (op=='/'){
        cout << a/b << endl;
    }else if  (op=='?'){
        return 0;
    }
  }
 
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
int n,m,q;
int a[55],b[55],c[55],d[55];
long long mx=0;
void dfs(vector<int> v){
	if(v.size()==n+1){
		long long cnt=0;
		for(int i=0;i<q;i++){
			if(v[b[i]]-v[a[i]]==c[i]){
				cnt+=d[i];
			}
		}
		mx=max(mx,cnt);
		return ;
	}
	for(int i=v[v.size()-1];i<=m;i++){
		v.push_back(i);
		dfs(v);
		v.erase(v.begin()+v.size()-1);
	}
}
int main(){
	cin>>n>>m>>q;
	vector<int> v;
	for(int i=0;i<q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	vector<int> vvvvv;
	vvvvv.push_back(1);
	dfs(vvvvv);
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 3632
defmodule MemoZ do
  def init(f) do
    fn x ->
      {:ok, pid} = Agent.start_link &Map.new/0
      try do
        fix(pid, f).(x)
      after
        Agent.stop pid
      end
    end
  end

  defp fix(pid, f) do
    fn x ->
      x.(x)
    end.(
      fn x ->
        f.(&(get_or_else_update(pid, &1, fn -> x.(x).(&1) end)))
      end
    )
  end

  defp get_or_else_update(pid, k, f) do
    case Agent.get(pid, &Map.get(&1, k)) do
      nil ->
        v = f.()
        Agent.update(pid, &Map.put(&1, k, v))
        v
      v -> v
    end    
  end
end
defmodule Main do
  def main do
    memofib = MemoZ.init(fn f ->
  fn 
    0 -> 2
    1 -> 1
    x -> f.(x-1) + f.(x-2)
  end
end)
    n =
      IO.read(:line)
      |> String.trim |> String.to_integer
    ans = memofib.(n)
    IO.puts(ans)
  end
end

Measured memory_bytes: 30808
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

#define N 101
const double eps = 1e-8;
//n matrix size  a00+x0+...=c0
//k current step
//mat Matrix
bool select_pivot(int n,int k,double mat[N][N]){
  int s=k;//selected pivot
  double val=fabs(mat[k][k]);
  REP(i,k+1,n)if (fabs(mat[i][k]) >val)val=fabs(mat[i][k]),s=i;
  
  if ( val<eps)return false;//cannot solve this linear equations.
  REP(i,k,n+1)swap(mat[k][i],mat[s][i]);
  return true;//no problem for this pivot;
}

//n matrix size  x0,x1,...xn-1 =constant
//row n,column n+1
bool gauss(int n,double mat[N][N]){
  //step1
  rep(k,n){
    if ( select_pivot(n,k,mat)==false)return false;
    REP(i,k+1,n+1)mat[k][i]/=mat[k][k];//devided by m[k][k];
    mat[k][k]=1;//for looking the equation
    REP(i,k+1,n){//ツ妥」ツ禿シ
      REP(j,k+1,n+1)mat[i][j]+=-mat[i][k]*mat[k][j];
      mat[i][k]=0;//For looking the equation
    }
  }
  
  //step2 
  for(int i=n-1;i>=0;i--){//solve ith row
    REP(j,i+1,n){
      mat[i][n]-=mat[i][j]*mat[j][n];
    }
  }

  return true;
}

#define INF ( 1 << 25)

main(){
  int n,s,d;
  int adj[N][N];
  int cost[N][N];
  bool sign[N];
  double mat[N][N];
  while(cin>>n>>s>>d && n){
    s--;d--;
    rep(i,n)cin>>sign[i];
    rep(i,n){
      rep(j,n){
	cin>>adj[i][j];
	cost[i][j]=adj[i][j]==0?INF:adj[i][j];
	mat[i][j]=0;
      }
      mat[i][n]=0;
      cost[i][i]=0;
    }
    
    rep(k,n)rep(i,n)rep(j,n)cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);

    rep(i,n){
      int cnt=0;
      if ( i == d){mat[i][i]=1;mat[i][n]=0;continue;}
      if (sign[i]==true){
	
	rep(j,n)
	  if ( adj[i][j] !=0 && cost[i][d]==adj[i][j]+cost[j][d])
	    mat[i][n]+=adj[i][j],mat[i][j]=-1,cnt++;
	

	/*
	int mincost=INF;
	rep(j,n)if (adj[i][j]!=0 )mincost=min(mincost,cost[j][d]);
	rep(j,n)
	  if ( adj[i][j] !=0 && mincost==cost[j][d])
	    mat[i][n]+=adj[i][j],mat[i][j]=-1,cnt++;
	*/

	//	rep(j,n)
	//  if ( adj[i][j] !=0 && cost[s][d]==cost[s][j]+cost[j][d])
	//    mat[i][n]+=adj[i][j],mat[i][j]=-1,cnt++;
	

      }else {
	rep(j,n)
	  if (adj[i][j] != 0 )mat[i][n]+=adj[i][j],mat[i][j]=-1,cnt++;
      }
      mat[i][i]=cnt;
    }
        
    if (false == gauss(n,mat)){puts("No Solution");return true;continue;}
        
    printf("%.14lf\n",mat[s][n]);

  }

  return false;
}


/*main for verify
main(){
  srand(time(NULL));
  int n =100;
  double ans[n];
  double mat[N][N];
  rep(i,n)ans[i]=(double)(RAND_MAX-rand())/(double)RAND_MAX;
  
  rep(i,n){
    double sum =0;
    rep(j,n){
      double tmp =(double)(RAND_MAX- rand())/(double)RAND_MAX;
      mat[i][j]=tmp;
      sum+=tmp*ans[j];
    }
    mat[i][n]=sum;
  }

  if (  gauss(n, mat) == false){puts("Cannot solve");return false;}
  
  int cnt=0;
  rep(i,n){
    cout <<i << " " << ans[i] << " " << mat[i][n]<<" " 
	 << fabs(ans[i]-mat[i][n]) << endl;
    if ( fabs(ans[i]-mat[i][n])>eps)cnt++;
  }
  cout << "number of WA is " << cnt << endl;
}
*/

Measured memory_bytes: 1064
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 987654319 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	int a, b;
	cin >> a >> b;
	if(a <= 9 && b <= 9)
		cout << a * b;
	else
		cout << -1;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (long int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long long A,B,V,W,T;
    cin>>A>>V>>B>>W>>T;
    if (V<=W) cout<<"NO"<<endl;
    else{
        if (abs(A-B)<=T*abs(V-W)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>

using namespace std;

class Node
{  
public:
    int p;
    vector<int> vec;
};

int dp[100005];
Node node[100005];

int rec(int v)
{
    if(node[v].vec.size() == 0)
    {
        return 0;
    }

    if(dp[v] != -1)
    {
        return dp[v];
    }

    vector<int> vec;
    for (int i = 0; i < node[v].vec.size();i++)
    {
        vec.push_back(rec(node[v].vec[i]));
    }
    sort(vec.begin(), vec.end(), greater<int>());
    int ret = -1;
    for (int i = 1; i <= node[v].vec.size(); i++)
    {
        ret = max(ret, i + vec[i - 1]);
    }
    return dp[v] = ret;
}

int main()
{
    long long N;
    long long a[100005];

    cin >> N;

    for (int i = 1; i <= N;i++)
    {
        dp[i] = -1;
    }

    node[1].p = 1;
    for (int i = 2; i <= N; i++)
    {
        int a;
        cin >> a;
        node[i].p = a;
        node[a].vec.push_back(i);
    }

    cout << rec(1) << endl;
    return 0;
}


Measured memory_bytes: 19456
def main():
    from builtins import int, map, list, print, min
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    A,B,C,K = input_number_list()
    ans = min(A,K)
    K -= A+B
    if K>0:
        ans -= min(C,K)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	string s;
	cin >> s;
	for(char c:s) if(c == '7') {
		cout << "Yes" << endl;
		return 0;
	}	
	cout << "No" << endl;	
}





Measured memory_bytes: 3584
#include<iostream>

using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if(a < b)
    if(b < c)
      cout << a+b;
    else
      cout << a+c;
  else
    if(a < c)
      cout << a+b;
    else
      cout << b+c;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[8];
signed main(){
	ic(n)
	c(n*n)
}	
	

Measured memory_bytes: 256
#include<cstdio>

int main(){
    unsigned N;
    scanf("%u\n", &N);
    bool X[N];
    unsigned ones = 0;
    char tmp;
    for (unsigned i = 0; i < N; i++){
        scanf("%c", &tmp);
        if(X[i] = tmp == '1') ones++;
    }
    if(ones == 1){
        for (unsigned i = 0; i < N; i++){
            if(X[i]) printf("0\n");
            else if(X[N-1] ^ (bool)(i == N - 1)) printf("2\n");
            else printf("1\n");
        }
        return 0;
    }
    unsigned plus[N], minus[N];
    plus[0] = 1;minus[0] = 1 % (ones - 1);
    for (unsigned i = 1; i < N; i++){
        plus[i] = (plus[i-1]<<1) % (ones+1);
        minus[i] = (minus[i-1]<<1) % (ones-1);
    }
    unsigned f[ones+1];
    f[0] = 0;
    for (unsigned i = 1; i <= ones; i++){
        unsigned _i = i, pop = 0;
        while(_i){
            if(_i&1) pop++;
            _i >>= 1;
        }
        f[i] = 1 + f[i % pop];
    }
    unsigned modplus = 0, modminus = 0;
    for (unsigned i = 0; i < N; i++){
        if(X[i]){
            modplus = (modplus + plus[N-1-i]) % (ones+1);
            modminus = (modminus + minus[N-1-i]) % (ones-1);
        }
    }
    for (unsigned i = 0; i < N; i++){
        printf("%u\n", 1 + (X[i] ? f[(modminus + ones - 1 - minus[N-1-i])%(ones-1)] : f[(modplus + plus[N-1-i])%(ones+1)]));
    }
	return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
ll mod = 1000000007;
ll modpow(ll a, int p) {
    if (p == 0)
        return 1;
    if (p & 1) {
        return a * modpow(a, p - 1) % mod;
    }
    ll half = modpow(a, p / 2);
    return half * half % mod;
}
ll calcComb(int a, int b) {
	if (b > a - b)
		return calcComb(a, a - b);
	ll ansMul = 1, ansDiv = 1;
	rep(i, 0, b) {
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= mod;
		ansDiv %= mod;
	}
	ll ans = ansMul * modpow(ansDiv, mod - 2) % mod;
	return ans;
}
void solve() {
	var(int, n, m);
	int MNokori = m;
	ll ans = 1;
	for (int i = 2; i * i <= MNokori; ++i) {
		if (MNokori % i == 0) {
			int cnt= 0;
			while (MNokori % i == 0) {
				++cnt;
				MNokori /= i;
			}
			ans *= calcComb(n + cnt - 1, n - 1);
			ans %= mod;
		}
	}
	if (MNokori != 1) {
		ans *= calcComb(n, n - 1);
		ans %= mod;
	}
	print(ans);
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;
int tosi = 2019;

int main()
{
	cin >> n >> k;
	vector<int>h(n); rep(i, n)cin >> h[i];
	sort(all(h));
	ans = INFINITY;
	rep(i, n - k+1 ) {
		if (ans > h[i + k - 1] - h[i])
			ans = h[i + k - 1] - h[i];
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
long long N,T,ans;
  cin>>N>>T;
  ans=T;
  vector<long long>t(N),sa(N-1);
  for(int i=0;i<N;i++){
    cin>>t[i];
  }
    for(int i=0;i<N-1;i++){
    sa[i]=t[i+1]-t[i];
        ans+=min(T,sa[i]);
      }
      cout<<ans<<endl;
        
  }


Measured memory_bytes: 3328
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;


int main() {
	string S, T;
	cin >> S >> T;
	ll cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i])cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

type pair struct {
	f, s int
}

// P :
type P []pair

func (p P) Len() int {
	return len(p)
}

func (p P) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p P) Less(i, j int) bool {
	if p[i].f == p[j].f {
		return p[i].s < p[j].s
	}
	return p[i].f < p[j].f
}

func lower_bound(a P, x pair) int {
	l := 0
	r := len(a)
	for l <= r {
		m := (l + r) / 2
		if len(a) == m {
			break
		}
		if a[m].f >= x.f || (a[m].f == x.f && a[m].s >= x.s) {
			r = m - 1
		} else {
			l = m + 1
		}
	}
	return l
}

func upper_bound(a P, x pair) int {
	l := 0
	r := len(a)
	for l <= r {
		m := (l + r) / 2
		if len(a) == m {
			break
		}
		if a[m].f <= x.f || (a[m].f == x.f && a[m].s <= x.s) {
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return l
}

type G struct {
	to []pair
}

// MX :
const MX = 100005

var x [MX]int
var used [MX]bool
var g [MX]G

var ans []int

func dfs(v int) int {
	used[v] = true
	res := x[v]
	for _, e := range g[v].to {
		if used[e.f] {
			continue
		}
		r := dfs(e.f)
		if r == 1 {
			ans = append(ans, e.s)
		}
		res ^= r
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)

	n, m := getInt(), getInt()
	a := make(P, n)
	// 爆弾の座標
	for i := 0; i < n; i++ {
		a[i] = pair{getInt(), getInt()}
	}
	sort.Sort(a)
	x[0] = a[0].s
	for i := 0; i < n-1; i++ {
		x[i+1] = a[i].s ^ a[i+1].s
	}
	x[n] = a[n-1].s

	for i := 0; i < m; i++ {
		l, r := getInt(), getInt()
		l = lower_bound(a, pair{l, 0})
		r = upper_bound(a, pair{r, 1})
		g[l].to = append(g[l].to, pair{r, i + 1})
		g[r].to = append(g[r].to, pair{l, i + 1})
	}

	for i := 0; i <= n; i++ {
		if used[i] {
			continue
		}
		if dfs(i) == 1 {
			out(-1)
			return
		}
	}

	out(len(ans))
	sort.Ints(ans)
	for _, v := range ans {
		fmt.Print(v, " ")
	}
	out("")
}


Measured memory_bytes: 50560
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> std::vector<T> vec(int l,T e){return std::vector<T>(l,e);}
template<typename T> using MaxHeap=std::priority_queue<T>;
template<typename T> using MinHeap=std::priority_queue<T,std::vector<T>,std::greater<T> >;

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vvll cnt(10, vll(10, 0));
  FOR (i, 1, n+1) {
    string s = to_string(i);
    cnt[s[0] - '0'][i % 10] += 1;
  }
  ll ans = 0;
  FOR (i, 1, 10) {
    FOR (j, 1, 10) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
      ll n;
      cin>>n;
       ll cnt=0;
        ll ans=0;
      for(int i=1;i<=n;i++)
         for(int j=1;j<=n;j++)
           {
               if(i*j<n)
                  cnt++;
               else
                break;
           }
        cout<<cnt<<endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> v(n+1,0);
  for(int i=0;i<n-1;i++)
  {
    int x;
    cin>>x;
    v[x]++;
  }
  for(int i=1;i<=n;i++)
    cout<<v[i]<<endl;
  return 0;
}

Measured memory_bytes: 4012
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    string o,b;
    cin >> o >> b  ;
    string ans;
    int i;
    rep(i,o.size()){
        ans += o[i];
        if (i<b.size())ans += b[i];
    }
    pri(ans);

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int N;
	cin >> N;

	ll a[N];
	rep(i,N) cin >> a[i];

	int ans = 1;
	int d = 0; // 1:up,0:neutral,-1:down

	rep(i,N-1){
		if(a[i] > a[i+1] && d == 0){
			d = -1;
		}else if(a[i] > a[i+1] && d == 1){
			ans++;
			d = 0;
		}else if(a[i] < a[i+1] && d == 0){
			d = 1;
		}else if(a[i] < a[i+1] && d == -1){
			ans++;
			d = 0;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 4056343
using namespace std;
int main()
{
	int k;
	cin>>k;
	int now=7,ans=0;
	bool f=0;
	for(fint i=1;i<=k;i++)
	{
		if(now%k!=0)
		now=now*10+7,now%=k,ans++;
		else
		{
			f=1;
			break;
		}
	}
	if(f)
	cout<<ans+1;
	else
	cout<<-1;
	return 0;
}

Measured memory_bytes: 3592
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  list.sort(function(a,b){
    return a - b;
  });
  var check = [];
  check.push(list[list.length - 1]);
  list[list.length - 1] = -1;
  for(var i = 0; i < N; i++){
    var check2 = makeClone(check);
    check2.sort(function(a,b){
      return a - b;
    });
    var index = (1 << N) - 1;
    while(check2.length > 0 && index >= 0){
      if(list[index] == -1){
        index--;
        continue;
      }
      if(list[index] < check2[check2.length - 1]){
        check.push(list[index]);
        check2.pop();
        list[index] = -1;
      }
      index--;
    }
    if(check2.length > 0){
      myout("No");
      return;
    }
  }
  //myerr(check);
  myout("Yes");
}





Measured memory_bytes: 73436
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

const int N=2e5+10;
char s[N];
int n; 
double x,y,d;

int main(){
	int ans=0;
	cin>>n>>d;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		double temp=sqrt(pow(x,2)+pow(y,2));
		if(temp<=d){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long A,B,C,X;
    cin>>A>>B;

    X=A*B;
    
    C=abs(A%B);
    while(C!=0){
        A=B;
        B=C;
        C=A%B;
    }

    cout<<X/B<<endl;

    
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
##print(S)
tmp=0
T=0
for i in range(N-1):
  T=T+A[i]
  ##print(T)
  ##print(A[i])
  tmp=(A[i]*(S-T)+tmp)
tmp=tmp%(10**9+7)
print(tmp)

Measured memory_bytes: 104956
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
const int N =1e4+5;
int n,k,x,y;
int main(){
     scanf("%d %d %d %d",&n,&k,&x,&y);
     ll ans=0;
     for(ll i=0;i<n;i++)
     {
          if(k>0)
          {
               ans+=x;
               k-=1;
          }
          else 
               ans+=y;     
     }
     printf("%lld\n",ans);
}


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

using namespace std;

int z;

int main() {
    while(~scanf("%d", &z)) {
        if(z == 0) break;
        int i, j;
        int mx = 0;
        for(i = 1; i <= 1111; i++) {
            for(j = 1; j <= 1111; j++) {
                if((i*i*i) + (j*j*j) <= z*z*z) {
                    mx = max(mx, ((i*i*i) + (j*j*j)));
                }
            }
        }
        printf("%d\n", ((z*z*z) - mx));
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef set<int> si;
typedef set<ll, ll> sll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<int, int> mii;
typedef map<int, ll> mil;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;

#define FOR(i, a, b) for(int i = (a), loop_end_##i=(b); i < (loop_end_##i); i++)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort((c).begin(),(c).end())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define PB push_back

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

#define rep(v,n) for(int v=0;v<n;v++)
#define input(t,v) t v;cin>>v;
#define input2(t,v1,v2) t v1,v2;cin>>v1>>v2;
#define input3(t,v1,v2,v3) t v1,v2,v3;cin>>v1>>v2>>v3;

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

int main(){
	while(true){
		input(int,n);
		if(n==0)return 0;
		if(n%1111==0){cout<<"NA"<<endl;continue;}
		int ret=0;
		while(n!=6174){
			int ds[4],tmp;
			tmp=n;
			rep(i,4){
				ds[i]=tmp%10;
				tmp/=10;
			}
			sort(begin(ds),end(ds));
			
			int S=ds[0]*1000+ds[1]*100+ds[2]*10+ds[3];
			int L=ds[3]*1000+ds[2]*100+ds[1]*10+ds[0];
			n=L-S;
			ret++;
		}
		cout<<ret<<endl;
	}
	
}

Measured memory_bytes: 1172
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 1005;

int i,j,h,w,ch,cw,dh,dw,dist[N][N];
char s[N][N];

void solve()
{
    cin>>h>>w>>ch>>cw>>dh>>dw;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            cin>>s[i][j];
            dist[i][j]=INF;
        }
    }
    dist[ch][cw]=0;
    deque<pii> q;
    q.pf({ch,cw});
    while(!q.empty())
    {
        pii p=q.front();
        q.pop_front();
        int x=p.f,y=p.s;
        for(int dx=-2;dx<=2;dx++)
        {
            for(int dy=-2;dy<=2;dy++)
            {
                int nx=x+dx,ny=y+dy;
                if(nx>=1 && nx<=h && ny>=1 && ny<=w && s[nx][ny]=='.')
                {
                    if(abs(dx)+abs(dy)==1 && dist[x][y]<dist[nx][ny])
                    {
                        dist[nx][ny]=dist[x][y];
                        q.pf({nx,ny});
                    }
                    else if(dist[x][y]+1<dist[nx][ny])
                    {
                        dist[nx][ny]=dist[x][y]+1;
                        q.pb({nx,ny});
                    }
                }
            }
        }
    }
    if(dist[dh][dw]==INF)
        dist[dh][dw]=-1;
    cout<<dist[dh][dw];
}

signed main()
{
    fastio;
    int tt;
    //cin>>tt;
    tt=1;
    while(tt--)
    {
        solve();
    }
    return 0;
}

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

int main(){
    int A, B, C, D;
    std::cin >> A >> B >> C >> D;

    while(1){
        C -= B;
        if(C <= 0){
            std::cout << "Yes" << std::endl;
            break;
        }

        A -= D;
        if(A <= 0){
            std::cout << "No" << std::endl;
            break;
        }
    }

    return 0;
}


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

double a, b, x;
double theta;
#define D 180 / M_PI
/*図形問題*/

int main(){
  cin >> a >> b >> x;
  double S = x / a;                //水と側面の接触面積
  if(S >= a * b / 2) theta = atan((2 * b - 2 * x / a / a) / a) * D;    //傾けたとき側面が台形
  else theta = atan(b*b/S/2) *  D;  // 側面が底面の辺を用いて構成される三角形<-2倍
  printf("%.8f\n", theta);
  return 0;

  
}


Measured memory_bytes: 4068
//#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
//#include<unordered_map>
using namespace std;

typedef long long ll;
typedef long double ld;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define of(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof a)
#define uint unsigned int

const  int N = 4e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;




int main()
{
	/*ios::sync_with_stdio(false);*/
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; s[i]; i++)
	{
		if (s[i] != s[i + 1])
		{
			ans++;
		}
		else
		{
			if (s[i + 2])
				ans+=2, i += 2;
			else if (s[i + 1])
				ans++, i++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
A = []
XY = []
for i in range(N):
    a = int(input())
    A.append(a)
    xy = [list(map(int,input().split())) for j in range(a)]
    XY.append(xy)
ans = 0
for i in range(2**N):
    b = [i>>j&1 for j in range(N)]
    f = 0
    for j in range(N):
        if b[j] == 1:
            for k in range(A[j]):
                x = XY[j][k][0] -1
                y = XY[j][k][1]
                if b[x] != y:
                    f = 1
                    break
        if f:
            break
    else:
        ans = max(ans,b.count(1))
print(ans)

Measured memory_bytes: 9140
fn read<T: ::std::str::FromStr>() -> T {
    let mut s = String::new();
    ::std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: ::std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    ::std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

pub fn main() {
    let N: usize = read();
    let S: String = read();
    let K: usize = read();
    let target_char = S.chars().nth(K - 1).unwrap();
    let mut ans = String::with_capacity(N);
    for c in S.chars() {
        ans.push(if c == target_char { c } else { '*' });
    }
    println!("{}", ans);
}

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

int main(){
    string s;
    ll k;
    cin>>s>>k;
    if(s.size()==1){
        cout<<k/2<<endl;
        return 0;
    }
    char prev=s[0];
    ll cnt=1;
    vector<ll> n;
    for(ll i=1;i<s.size();i++){
        if(s[i]==prev){
            cnt++;
            if(i==s.size()-1)n.push_back(cnt);
        }else{
            n.push_back(cnt);
            cnt=1;
            if(i==s.size()-1)n.push_back(cnt);
        }
        prev=s[i];
    }
    bool c=(s[0]==s[s.size()-1]);
    ll ans=0;
    if(c){
        if(n.size()==1){
            cout<<n[0]*k/2<<endl;
        }else{
            ll aida=n[0]+n[n.size()-1];
            ans+=(aida/2)*(k-1);
            ans+=n[0]/2;
            ans+=n[n.size()-1]/2;
            for(ll i=1;i<n.size()-1;i++){
                ans+=(n[i]/2)*k;
            }
            cout<<ans<<endl;
        }
    }else{
        rep(i,n.size()){
            ans+=n[i]/2;
        }
        cout<<ans*k<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  long long int ans=max(a*b,c*d);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a,b,ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
    	scanf("%d%d",&a,&b);
    	ans+=b-a+1;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n =gets.to_i
a =gets.split.map(&:to_i)

for i in 1...n
  puts a.join(" ")
  v = a[i]  # 2[1]
  j = i - 1 # 0
  while j>=0 && a[j]> v # 5[0]>1[1]
    a[j+1]=a[j] # 2[1]=0[0]
    j -= 1      # 0
    a[j+1] = v  # a[1]=2[1]
  end
end

puts a.join(" ")


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

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * (ll)i % mod;
        inv[i] = mod - inv[mod%i] * (mod/(ll)i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


int main(){
    COMinit();
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    ll ans = 0;
    for(int i = 0; i < h - a; i++) ans = (ans + COM(b+i-1,i)*COM(h+w-b-2-i,h-1-i)) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int n,k,h[100005],f[100005];
int main()
{
    cin>>n>>k;
    for (int i=1;i<=n;++i)
    {
        cin>>h[i];
    }
    f[1]=0;
    f[0]=0;
    for (int i=2;i<=n;++i)
    {
        f[i]=1e9;
        int l=i-k;
        l=max(l,1);
        for (int j=i-1;j>=l;--j)
        {
            f[i]=min(f[i],f[j]+abs(h[i]-h[j]));
        }
    }
    cout<<f[n];
    return 0;
}

Measured memory_bytes: 4296
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;
    
    int depth = 0;
    for( int i = 0; i < n; ++i ) {
        if( s[i] == ')' ) {
            --depth;
            if( depth < 0 ) {
                cout << '(';
                ++depth;
            }

        } else ++depth;


    }
    cout << s;
    depth = 0;
    for( int i = s.size() - 1; i >= 0; --i ) {
        if( s[i] == ')' ) {
            --depth;

        } else {
            ++depth;
            if( depth > 0 ) {
                cout << ')';
                --depth;

            }

        }
    }
    cout << endl;
    return 0;
}


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

sm = abs(x)//d+1

if abs(x)-sm*d>0 :
    ans = abs(x)-sm*d 
elif abs(x)-d*k>0:
    ans = abs(x)-d*k
elif (k-sm)%2==0:
    ans = min(abs(x)-sm*d,abs(abs(x)-sm*d-2*d))
else:
    ans = min(abs(abs(x)-sm*d-d),abs(abs(x)-sm*d+d))

print(abs(ans))
    


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

const int INF = 2e9;

//sortの比較関数: first昇順、second降順
bool comp(pair<int, string> a, pair<int, string> b){
    /* if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    } */
    return a.second > b.second;
} 

int main(){
    //入力
    int N, M; cin >> N >> M;
    vector<int> A(M);
    for(int i = 0; i < M; i++) cin >> A[i];

    map<int,int> F; // F[i] := 数字iを作るのに使うマッチ数
    F[1] = 2, F[2] = 5, F[3] = 5,F[4] = 4, F[5] = 5,
    F[6] = 6, F[7] = 3, F[8] = 7, F[9] = 6;

    vector<int> dp(N+1, -INF); // dp[i] := マッチ棒をi本使って作れる数の最大の桁数
    string ans = "";

    //dpテーブルを埋めていく
    dp[0] = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < M; j++){
            if(i - F[A[j]] >= 0) dp[i] = max(dp[i], dp[i-F[A[j]]] + 1);
        }
    }

    /* for(int i = 0; i <= N; i++){
        cout << i << " " << dp[i] << endl;
    }  */

    //前処理
    vector<pair<int,string>> P(M); // firstがマッチの本数、secondが数字
    for(int i = 0; i < M; i++){
        string tmp = {(char)('0' +A[i])};
        P[i] = {F[A[i]], tmp};
    }
    sort(P.begin(), P.end(), comp);

    //for(int i = 0 ; i < M; i++) cout << P[i].first << "  " << P[i].second << endl;

    // dpテーブルが動いた時に数字は追加されているのでそれを逆に辿る
    int remain = dp[N]; // 残り桁数
    int match = N;      // 残りマッチ数
    while(match > 0){
        for(int i = 0; i < M; i++){
            if( match - P[i].first >= 0 && dp[match - P[i].first] == remain - 1){
                ans += P[i].second;
                match -= P[i].first;
                remain--;
                break;
            }
        }
    }

    //　最大桁数の中で辞書順最大なものを出力したい
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
using namespace std;

int main() {
	int N;
	int ans = 1;
	string S;
	cin >> N;
	cin >> S;
	string formerC, nowC;
	formerC = S[0];
	for (int i = 1;i < N;i++) {
		nowC = S[i];
		if (formerC != nowC) {
			ans++;
			formerC = nowC;
		}
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 512
fn main() {
    let n = read::<usize>();
    let mut v = read_vec::<u32>();
    v.sort();

    if n % 2 != 0 {
        for i in 0..n {
            //println!("{} {} {}", i, v[i], (i as u32 + 1) / 2 * 2);
            if (i as u32 + 1) / 2 * 2 != v[i] {
                println!("0");
                return;
            }
        }
    } else {
        for i in 0..n {
            //println!("{} {} {}", i, v[i], (i as u32 + 2) / 2 * 2);
            if (i as u32 + 2) / 2 * 2 - 1 != v[i] {
                println!("0");
                return;
            }
        }
    }
    let e = n / 2;
    let mut ans = 1;
    for _ in 0..e {
        ans *= 2;
        ans %= 1000000007;
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
while True:
    try:
        n = int(input())
        if not n : break
        town = 0
        dis = [[float('inf') for j in range(10)] for i in range(10)]
        for i in range(n):
            a,b,c = map(int , input().split())
            dis[a][b] = c
            dis[b][a] = c
            town = max(town,a)
            town = max(town,b)
        for i in range(town+1):
            dis[i][i] = 0
        mindis = dis

        for i in range(town+1):
            for j in range(town+1):
                for k in range(town+1):
                    if (mindis[j][k] > mindis[j][i]+mindis[i][k]):
                        mindis[j][k] = mindis[j][i]+mindis[i][k]
        

        mintown = 0
        ans = float('inf')

        for i in range(town+1):
            sum = 0
            for j in range(town+1):
                sum += mindis[i][j]
            if (ans > sum) :
                ans = sum
                mintown = i

        print(mintown , ans)

    except:
        break


Measured memory_bytes: 5624
#include<stdio.h>

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

void insertionSort(int A[],int N){
    int j,i,v;
    for(i = 1; i < N; i++){
        v = A[i];
        j = i-1;
        while( j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A,N);
    }
}

int main(){
    int N,i,j;
    int A[100];

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

    trace(A,N);
    insertionSort(A,N);

    return 0;
}


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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

/*const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

ll mul(ll a, ll b) {
    return (((a % mod) * (b % mod)) % mod);
}*/

/*vector<int> find_dividers(int x) {
    vector<int> dividers;

    for (int i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

void solve() {
    int n;
    ll d;
    cin >> n >> d;
    d *= d;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        if (x*x + y*y <= d) cnt++;
    }
    cout << cnt;
}

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

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

    return 0;
}


Measured memory_bytes: 3604