akhauriyash/Code-Regression huggingface dataset:
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


constexpr int32_t MAX_N = 200000;//頂点数
constexpr int32_t MAX_LOGN = 30;//log2頂点数
std::vector<int32_t> graph[MAX_N];//木
std::set<int32_t> graph_in[MAX_N];//木
int32_t N,M;
void input_tree()
{
	in >> N>>M;
	for (int32_t i = 0; i < N - 1 + M; ++i)
	{
		int a, b;
		in >> a >> b; --a; --b;
		graph[a].push_back(b);
		graph_in[b].insert(a);
	}
}
int32_t result[MAX_N];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	input_tree();

	std::vector<int> ok_list;
	for (size_t i = 0; i < N; i++)
	{
		if (graph_in[i].empty()) {
			ok_list.push_back(i);
			result[i] = -1;
			break;
		}
	}
	while (!ok_list.empty())
	{
		auto v = ok_list.back(); ok_list.pop_back();

		for (auto& n : graph[v])
		{
			graph_in[n].erase(v);
			if (graph_in[n].empty()) {
				ok_list.push_back(n);
				result[n] = v;
			}
		}
	}/*

	for (size_t i = 0; i < N; i++)
	{
		if (graph_in[i].empty()) {
			out << "0\n";
			continue;
		}
		auto tmp_parent = graph_in[i][0];
		for (size_t j = 1; j < graph_in[i].size(); j++)
		{
			auto next_p = graph_in[i][j];
			auto not_parent = nLCA::glca(tmp_parent, next_p);
			if (tmp_parent == not_parent) {
				tmp_parent = next_p;
			}
		}
		out << tmp_parent+1 << "\n";
	}*/

	for (size_t i = 0; i < N; i++)
	{
		out << result[i]+1 << "\n";
	}

	return 0;
}
#endif


Measured memory_bytes: 23168
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int d4x[4] = {0,1,0,-1};
int d4y[4] = {1,0,-1,0};

int main(){
	char nap[55][55];
	int ans[55][55];
	int H,W;
	cin>>H>>W;
	int cnt_blk = 0;
	REP(i,H)REP(j,W){
		cin>>nap[i][j];
		ans[i][j] = inf;
		if(nap[i][j] == '#')cnt_blk++;
	}
	queue<ip> Q;
	ans[1][1] = 0;
	Q.push(make_pair(1, 1));
	while(!Q.empty()){
		int y = Q.front().first, x = Q.front().second;
		Q.pop();
		rep(i,4){
			int dy = y + d4y[i], dx = x + d4x[i];
			if(nap[dy][dx] == '.' && ans[dy][dx] == inf){
				ans[dy][dx] = ans[y][x] + 1;
				Q.push(make_pair(dy, dx));
			}
		}
	}
	if(ans[H][W]== inf)cout<<-1<<endl;
	else cout<<H*W-1-cnt_blk-ans[H][W]<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
A = np.array(list(map(float, input().split())))
x1, y1 = A[0]*np.sin((A[2]+(A[3]/60))/6*np.pi), A[0]*np.cos((A[2]+(A[3]/60))/6*np.pi)
x2, y2 = A[1]*np.sin(A[3]/30*np.pi), A[1]*np.cos(A[3]/30*np.pi)
print(((x1-x2)**2+(y1-y2)**2)**0.5)

Measured memory_bytes: 27156
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
 
ll roc = 0;
string s;
ll i;
ll t;
bool found = false;
char ans = '#';
 
string genome() {
    string res = "";
    if(s[roc] == '(') {
        ++roc;
        while(s[roc] != ')' && !found) {
            if(s[roc] >= 'A' && s[roc] <= 'Z') {
                res += s[roc];
                ++t;
                if(t == i && ans == '#') {
                    ans = s[roc];
                    found = true;
                    ++roc;
                    t = INF;
                    break;
                }
                ++roc;
            } else {
                ll roc_buf = roc;
                while(s[roc] >= '0' && s[roc] <= '9') ++roc;
                int roop = stoi(s.substr(roc_buf, roc - roc_buf));
                string rooped = genome();
                if(!found) {
                    REP(j, roop - 1) {
                        if(t + rooped.size() < i) {
                            t += rooped.size();
                            res += rooped;
                        } else {
                            if(ans == '#') {
                                ans = rooped[(i - t) - 1];
                                found = true;
                                t = INF;
                            }
                            break;
                        }
                    }
                    res += rooped;
                }
            }
        }
        ++roc;
        return res;
    } else {
        res += s[roc];
        ++t;
        if(t == i) {
            ans = s[roc];
            found = true;
        }
        ++roc;
        return res;
    }
}
 
int main(void) {
    while(true) {
        cin>>s>>i;
        if(s == "0" && i == 0) break;
        roc = 0;
        t = -1;
        found = false;
        ans = '#';
        s = "(" + s;
        s += ")";
        genome();
        if(ans == '#') cout<<0<<endl;
        else cout<<ans<<endl;
    }
}


Measured memory_bytes: 5816
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;

//const int MOD=998244353;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    
    int n,m;
    cin>>n>>m;
    vector<int> v(2*n);
    for(int&i:v)cin>>i;
    
    sort(v.begin(),v.end());
    
    int ans=0, l=0, r=n+1;
    while(l<r){
        int mid=(l+r)/2;
        bool works=1;
        /*
        for(int i=0; i<2*mid; i++){
            if(v[i]+v[2*mid-1-i]>=m) works=0;
        }
        */
        for(int i=2*mid; i<2*n; i++){
            if(v[i]+v[2*n-1-i+2*mid]<m) works=0;
        }
        if(!works) l=mid+1;
        else r=mid;
    }
    for(int i=0; i<2*l; i++){
        ans=max(ans,(v[i]+v[2*l-1-i])%m);
    }
    for(int i=2*l; i<2*n; i++){
        ans=max(ans,(v[i]+v[2*n-1-i+2*l])%m);
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"errors"
	"fmt"
	"log"
	"os"
	"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()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// キュー
type queue struct {
	wpos, rpos int
	len        int
	maxlen     int
	val        []interface{}
}

func (q *queue) init(v int) {
	q.maxlen = v
	q.len = 0
	q.wpos = 0
	q.rpos = 0
	q.val = make([]interface{}, v)
}

func (q *queue) push(v interface{}) {
	out(v)
	if q.len == q.maxlen {
		log.Fatal("queue is overflow")
	}
	q.val[q.wpos] = v
	q.wpos++
	q.len++
	if q.wpos == q.maxlen {
		q.wpos = 0
	}
}

func (q *queue) pop() (interface{}, error) {
	if q.len == 0 {
		return nil, errors.New("empty")
	}
	ret := q.val[q.rpos]
	q.len--
	q.rpos++
	if q.rpos == q.maxlen {
		q.rpos = 0
	}
	return ret, nil
}

func (q *queue) empty() bool {
	if q.len == 0 {
		return true
	}
	return false
}

func (q *queue) full() bool {
	if q.len == q.maxlen {
		return true
	}
	return false
}

func next(s []int) []int {
	n := len(s)
	if n == 1 {
		if s[0] == 9 {
			s = []int{0, 1}
		} else {
			s[0]++
		}
		return s
	}

	for i := 0; i < n-1; i++ {
		if s[i]+1 <= 9 && s[i+1] >= s[i] {
			s[i]++
			v := s[i]
			for j := i - 1; j >= 0; j-- {
				s[j] = max(v-1, 0)
				v--
			}
			return s
		}
	}

	v := s[n-1] + 1
	if v == 10 {
		s = make([]int, n+1)
		s[n] = 1
		return s
	}
	for i := n - 1; i >= 0; i-- {
		s[i] = v
		v = max(v-1, 0)
	}

	return s
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	K := getInt()

	s := []int{1}
	for i := 1; i < K; i++ {
		s = next(s)
		// out(s)
	}

	for i := len(s) - 1; i >= 0; i-- {
		fmt.Printf("%d", s[i])
	}
	out()
}


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

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

int main(void){

    string a, b;
    cin >> a >> b;

    int sum=0;
    rep(i, a.size()){
        if(a.at(i) != b.at(i)) sum++;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3932
from sys import stdin

if __name__ == '__main__':
    N = int( stdin.readline().rstrip() )
    H = [ ( i, int(x) ) for i, x in enumerate(stdin.readline().rstrip().split()) ]
    H = dict(H)
    isOK = True
    for i in range( N - 1 ):
        if H[i] < H[i + 1]:
            H[i + 1] = H[i + 1] - 1
        elif H[i] == H[i + 1]:
            pass
        else:
            isOK = False
            break
    if isOK:
        print( 'Yes' )
    else:
        print( 'No' )

Measured memory_bytes: 27820
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int a,b,c,d;
    int x,y,n;
    int p,q;
    string s;

    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    ll res = H2*60+M2 - (H1*60+M1);

    cout << res - K << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>


int main(void){
  int a,b,c,d;
  scanf("%d %d %d %d",&a, &b,&c,&d);

  int left = a + b;
  int right = c + d;

  if(left == right){
  printf("Balanced\n");
  }else if (left > right){
  printf("Left\n");
  }else {
   printf("Right\n");
  }
  
  

 
  return 0;
}

Measured memory_bytes: 128
A, B, C, D, E, F = map(int, input().split())
conc = -1
ans = (0, 0)
for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        w = a + b
        if w == 0:
            continue
        for c in range(0, min(w * E // 100, F - w) + 1, C):
            d = min(w * E // 100 - c, F - w - c) // D * D
            s = c + d
            if conc < s / (w + s):
                conc = s / (w + s)
                ans = (w + s, s)
print(*ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int n, ans = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        long long int a;
        cin >> a;

        while (a % 2 == 0) {
            a /= 2;
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
sarr = input()
kisuu = ['R', 'U', 'D']
gusuu = ['L', 'U', 'D']

is_fumiyasui = True
for i, s in enumerate(sarr):
  if (i+1) % 2 == 0:
    if s not in gusuu:
      is_fumiyasui = False
      break
  else:
    if s not in kisuu:
      is_fumiyasui = False
      break


print('Yes' if is_fumiyasui else 'No')

Measured memory_bytes: 3064
def solve(x, y):
    if y < 0 and x < 0:
        if abs(x) <= abs(y):
            return 1 + abs(y) - abs(x) + 1
        if abs(x) > abs(y):
            return abs(x) - abs(y)
    elif x >= 0 and y >= 0:
        if abs(x) <= abs(y):
            return abs(y) - abs(x)
        if abs(x) > abs(y):
            if y != 0:
                return 1 + abs(x) - abs(y) + 1
            else:
                return 1 + abs(x) - abs(y)
    elif x < 0 and y >= 0:
        if y != 0:
            return abs(abs(x) - abs(y)) + 1
        else:
            return abs(abs(x) - abs(y))
    elif x >= 0 and y < 0:
        if y != 0:
            return abs(abs(x) - abs(y)) + 1
        else:
            return abs(abs(x) - abs(y))


if __name__ == "__main__":
    x, y = tuple(map(int, input().split(" ")))
    print(solve(x, y))


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

int main(){
  ll a,v,b,w,t,x,y;
  cin >> a >> v >> b >> w >> t;
  x=abs(a-b);
  y=(v-w)*t;
  if(y>=x){
    cout << "YES";
  }
  else{
    cout <<"NO";
  }
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

ll f(ll n) {
  if (n <= 0) return 0ll;
  int b = 0;
  while ((1ll << b) <= n) ++b;
  --b;
  ll res = 0;
  for (; b >= 0; b--) {
    ll tot = 0;
    tot += (n >> (b + 1)) * (1ll << b);
    if ((n >> b) & 1) {
      tot += (n & ((1ll << b) - 1)) + 1;
    }
    if (tot & 1) {
      res ^= 1ll << b;
    }
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  ll A, B;
  while (cin >> A >> B) {
    ll res = f(B) ^ f(A - 1);
    cout << res << endl;
  }
  return 0;
}


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

total = 0

for i in range(N - 1):
    xi = p[i][0]
    yi = p[i][1]
    for j in range(i + 1, N):
        xj = p[j][0]
        yj = p[j][1]
        total += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5

ans = total * 2 / N

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;

int main() {
	string s;
	cin >> s;
	if (s == "SUN")cout << "7" << endl;
	else if (s == "MON")cout << "6" << endl;
	else if (s == "TUE")cout << "5" << endl;
	else if (s == "WED")cout << "4" << endl;
	else if (s == "THU")cout << "3" << endl;
	else if (s == "FRI")cout << "2" << endl;
	else if (s == "SAT")cout << "1" << endl;
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int p[n];
  rep(i, n) cin >> p[i];
  sort(p, p+n);
  int sum = 0;
  rep(i, k) sum += p[i];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
long n,x[1000],y[1000];
vector<long>d;
main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		if(abs(x[i])+abs(y[i])&1^abs(x[0])+abs(y[0])&1){
			cout<<-1;
			return 0;
		}
	}
	for(int i=31;i--;)d.push_back(1<<i);
	d.push_back(1);
	d.push_back(1);
	if(abs(x[0])+abs(y[0])&1^1)d.push_back(1);
	cout<<d.size()<<" ";
	for(int i=0;i<d.size();i++)cout<<d[i]<<" ";
	for(int i=0;i<n;i++){
		long X=x[i],Y=y[i];
		string s=" ";
		for(int j=0;j<d.size();j++)s+=abs(X)>abs(Y)?X>0?X-=d[j],"R":(X+=d[j],"L"):Y>0?Y-=d[j],"U":(Y+=d[j],"D");
		cout<<s;
	}
}

Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  t,i,x,j,k,n,a,b,c,d,cnt=0;
    string s;
    cin>>a>>b>>c>>d;
    for(i=a;i<=b;i++)
    if(i>=c&&i<=d) cnt++;
        cout<<max(0LL,cnt-1)<<endl;

    return 0;
}





Measured memory_bytes: 3600
#include <stdio.h>

int main(){
  int i,n,l[11],sum=0,max=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
    sum+=l[i];
    if(l[i]>max){
      max=l[i];
    }
  }

  if(2*max<sum){
    printf("Yes");
  }else{
    printf("No");
  }
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   vector<int> v(n);
   rep(i, 0, n) cin >> v[i];
   sort(v.begin(), v.end());
   double ans = v[0];
   rep(i, 1, n) ans = (ans + v[i]) / 2;
   printf("%0.10f\n", ans);
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int n,i,m,not=0;
    double a[100000],b=0;

    scanf("%d %d", &n, &m);
    if(n >= m){
        for(i=0;i<n;i++){
            scanf("%lf", &a[i]);
            b += a[i];
        }

        for(i=0;i<n;i++){
            if(a[i] < (b/(4*m))){
                not++;
            }
        }
        if(n-not < m){
            printf("No\n");
        }
        else{
            printf("Yes\n");
        }
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
void printRectangle( int h, int w );

int main( void )
{
    while ( true )
    {
        int h, w;
        std::cin >> h >> w;
        if ( ( h == 0 ) && ( w == 0 ) ) break;
        printRectangle( h, w );
    }
    return 0;
}

void printRectangle( int h, int w )
{
    for ( int i = 0; i < h; i++ )
    {
        for ( int j = 0; j < w; j++ )
        {
            std::cout << "#";
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
}

Measured memory_bytes: 3044
using namespace std;
#include<string.h>
#include <sstream>
typedef long long int ll;
typedef long double ld;
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <map>
//#define N 4
#include <stack>
#include <unordered_set>
#include <math.h>
#include <cstring>
#include <bitset>
#include <numeric>
#include <set>
#include <sstream>
#include <list>
#include <queue>
#define PI 3.14159265358979323846264338327950
#define mp make_pair
#define inf 1e9
//#define M 1000000007
#define M 1000000007
#define N 200005

ll a[N + 5], v[N + 5], r[N + 5];
int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);

	ll n, k;
	cin >> n >> k;

	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
	}

	ll p = 1;
	ll c = 0;
	ll t = 0, len = 0;

	while (true) {

		if (v[a[p]] != 0) {
			t = v[a[p]];
			len = c - t + 1;
			break;
		}

		c++;
		r[c] = a[p];
		v[a[p]] = c;
		p = a[p];
	}

	if (k <= t) {
		cout << r[k];
	} else {
		ll s = (k - t) % len;
		cout << r[t + s];
	}
}


Measured memory_bytes: 8316
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
const double EPS = 1e-8;
#define Scan(a) int a;scanf("%d", &a);
#define ScanS(a) char a[500];scanf("%s", a);
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
class Graph {
public:
	int vn;
	int sumcost = 0;
	vector<vector<pii>> g;

	Graph(int n) {
		vn = n;
		g.resize(n);
	}
	virtual void con(int a, int b, int w) = 0;
	int getWeight(int f, int t) {
		auto itr = lower_bound(ALL(g[f]), make_pair(t, INT_MIN));
		if (itr != g[f].end())
			return itr->second;
		return INT_MIN;
	}
	int Costsum() {
		return sumcost;
	}
	void scan(int edcount, bool oindexed, bool w) {
		REP(i, edcount) {
			int a, b, c = 1;
			scanf("%d %d", &a, &b);
			if (w)scanf("%d", &c);
			con(a - oindexed, b - oindexed, c);
		}
	}
};
class BiDGraph : public Graph {//無向
public:
	BiDGraph(int n) : Graph(n) {}

	void con(int a, int b, int w = 1) {
		g[a].push_back({ b,w });
		g[b].push_back({ a, w });
		sumcost++;
	}
};
int factorial(int n) {//階乗
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
signed main() {
	int n, m,cr; 
	cin >> n >> m >> cr;
	vector<vector<int>> dist(n, vector<int>(n, 30000000));
	vector<int> r(cr);
	REP(i, cr) {
		scanf("%d", &r[i]);
		r[i]--;
	}
	REP(i, m) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		a--, b--;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	REP(i, n)
		dist[i][i] = 0;

	REP(k, n)
	REP(i, n)
		REP(j, n)
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

	int l = factorial(r.size());
	int Min = 300000000;
	REP(i, l) {
		int cur = 0;
		rep(i, 1, cr)
			cur += dist[r[i]][r[i-1]];
		Min = min(Min, cur);
		next_permutation(ALL(r));
	}
	cout << Min;
	return 0;
}

Measured memory_bytes: 384
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let a: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let mut acc = vec![0; N];
    acc[0] = a[0];
    for i in 1..N {
        acc[i] = acc[i - 1] + a[i];
    }

    let ans = (1..N).map(|i| (acc[i - 1] - (acc[N - 1] - acc[i - 1])).abs()).min().unwrap();

    println!("{}", ans);
}


Measured memory_bytes: 10492
gets
number_list = gets.split(" ").map{|a| a.to_i}
calc_number = 0
loop{
  all_even = true
  number_list.each{|a|
    if 0 != (a%2)
      all_even = false
      break
    end
  }
  if all_even == true
    number_list.map!{|a| a/2}
    calc_number += 1
  else
    break
  end
}
print calc_number


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#define lli long long int
#define INF 1e9+5
using namespace std;
int absdiff(int a, int b){
	if(a>b)
	return a-b;
	else return b-a;
}
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> h;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		h.push_back(x);
	
	}
	//dp[i] minimum cost to reach this step
	vector<int> dp(n,INF);
	dp[0]=0;
	for(int i=0;i<n;i++)
		for(int j=1;j<=k;j++)
		{if(i+j<n)
		dp[i+j]=min(dp[i+j],dp[i]+absdiff(h[i+j], h[i]))	;
		}
		
	
	cout<<dp[n-1]<<endl;
}

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

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

    long long x, y, a = 1, b = 1, c, ans;
    REP(i, n){
        cin >> x >> y;
        c = max((a + x - 1) / x, (b + y - 1) / y); 
        if(c == 0) c = 1;
        a = x * c;
        b = y * c;
    }
    ans = a + b;
    cout << ans << endl;
    


    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = [0]*M
for i in range(M):
    a[i] = int(input())

now = 0
ans = 1
j = 0
for i in range(M):
    if now == a[i] - 1:
       now = a[i] + 1 
    elif now == a[i]:
        ans = 0
        break
    else:
        j = (a[i] - 1) - now
        k1 = 0
        k2 = 1
        k3 = 1
        for n in range(j):
            k3 = k2
            k2 += k1
            k1 = k3
        ans *= k2
        now = a[i] + 1
if ans > 0:
  j = N - now
  k1 = 0
  k2 = 1
  k3 = 1
  for n in range(j):
      k3 = k2
      k2 += k1
      k1 = k3
  ans *= k2
print(ans % 1000000007)

Measured memory_bytes: 6900
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.close();

        int ans = 0 ;

        if(A>B){
            ans += A;
            A -= 1;
        }else{
            ans += B;
            B -= 1;
        }

        if(A>B){
            ans += A;
        }else{
            ans += B;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
import math

n = int(input())
end = math.ceil((-1 + (1 + 8 * n)**(0.5)) / 2)

ans = [j for j in range(1, end+1)]

sum_to_end = ( end ** 2 + end ) // 2

if sum_to_end != n:
    ans.remove(sum_to_end - n)

print('\n'.join(map(str, ans)))

Measured memory_bytes: 9568
N,W = map(int,input().split())
dp = [0]*(W+1)
for i in range(N):
    w,v = map(int,input().split())
    for j in range(W-w+1)[::-1]:
        dp[j+w] = max(dp[j+w],dp[j] + v)
print(max(dp))


Measured memory_bytes: 41580
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds;

typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> start_time(n); // Начинает ездить с такого времени
    vector<int> time_to_go(n); // едет столько времени
    vector<int> delta_time(n); // ездит через каждые столько секунд
    for (int i = 0; i < n; i++) {
        cin >> time_to_go[i] >> start_time[i]  >> delta_time[i];
    }
    vector<int> ans;
    for (int i = 0; i < n; i++){
        int cur_time = 0;
        int cur_st = i;
        while (cur_st != n - 1) {
            if (cur_time <= start_time[cur_st]) {
                cur_time = start_time[cur_st];
            }
            else {
                if ((cur_time - start_time[cur_st]) % delta_time[cur_st] != 0) {
                    cur_time += delta_time[cur_st] - (cur_time - start_time[cur_st]) % delta_time[cur_st];
                }
            }
            cur_time+=time_to_go[cur_st];
            cur_st++;
        }
        ans.push_back(cur_time);
    }
    for (auto cp: ans) {
        cout << cp << endl;
    }
}

Measured memory_bytes: 256
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

const ll modd=1e9+7;
const ll inf=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*    
         -> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
         -> cout<<"Case #"<<casee<<": "<<ans<<endl; // for google kickstart

*/

/*-----------------------------------------------------------------------------------------------*/

int main(){
   fastt;

   ll n,k;
   cin>>n>>k;

   ld prob=0;

   for(ll i=1;i<=n;i++){
      if(i<=k-1){
        ll cnt=0;
        ll copy=i;
        while(copy<=k-1){
           copy*=2;
           cnt++;
        }
        prob+=1.00/(1LL<<cnt);
      }
      else
        prob+=1.00;
   }

   prob=prob/n;

   cout<<fixed<<setprecision(10);

   cout<<prob<<endl;
 
   return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toLong() ?: return
    val aList = readLine()?.split(" ")?.map { it.toLong() } ?: return

    val distList = aList.mapIndexed { index, l -> index - l + 1 }
    val median = distList.sorted()[((n - 1) / 2).toInt()]
    val result = distList.map { Math.abs(it - median) }.sum()

    println(result)
}

Measured memory_bytes: 83036
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans, mn=inf;
int A[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	while (n--){
		cin>>x;
		if (x<mn){
			ans++;
			mn=x;
		}
	}
	kill(ans)
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i < t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

const int MAX_N = 200010;

int par[MAX_N];
int Rank[MAX_N];
int size;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
    size = n;
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size--;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}
bool same(int x, int y) {
    return find(x) == find(y);
}

const int MAX_E = 400020;

struct edge { int u, v, cost; };

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;                   // 頂点数と辺数

int kruskal() {
    sort(es, es + E, comp); // edge.costが小さい順にソートする
    init(V);                // Union-Findの初期化
    int res = 0;
    rep(i, E) {
        edge e = es[i];
        //cout << e.u << " " << e.v << " " << e.cost << endl;
        if (!same(e.u, e.v)) {
            unite(e.u, e.v);
            res += e.cost;
            //cout << "*" <<e.u << " " << e.v << " " << e.cost << endl;
        }
    }
    return res;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    V = N; E = (N-1)*2;
    vector<pair<int, int> > pairx(N);
    vector<pair<int, int> > pairy(N);
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        pairx[i] = make_pair(x, i);
        pairy[i] = make_pair(y, i);
    }
    sort(pairx.begin(), pairx.end());
    sort(pairy.begin(), pairy.end());
    rep(i, N-1)  {
        es[i*2] = {pairx[i+1].second, pairx[i].second, pairx[i+1].first - pairx[i].first};
        es[i*2+1] = {pairy[i+1].second, pairy[i].second, pairy[i+1].first - pairy[i].first};
    }
    cout << kruskal() << endl;


    return 0;
}


Measured memory_bytes: 7936
#include<iostream>
using namespace std;
int main(){
    int N,i,j,e,d;
    cin>>N;
    int p[N],h[N];
    for(i=0;i<N;i++){
        cin>>p[i];
        h[i]=p[i];
    }
    for(i=0;i<N;i++){
        for(j=i+1;j<N;j++){
            if(p[i]>p[j]){
                d=p[i];
                p[i]=p[j];
                p[j]=d;
            }
        }
    }
    e=0;
    for(i=0;i<N;i++){
        if(p[i]!=h[i])
            e=e+1;
    }
    if(e>2)
        cout<<"NO";
    else
        cout<<"YES";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N;
    vector<ull> A(100010,0ULL);
    cin >> N;
    for (int i=0;i<N;i++) cin >> A[i];

    // 興味深くないビットを無視
    ull all = 0ULL;
    for (int i=0;i<N;i++) all ^= A[i];
    for (int i=0;i<N;i++) A[i] &= ~all;
    // 行標準形を求める
    ull rank = 0;
    for (int i=59;i>=0;i--) {
        int j;
        for (j=rank;j<N;j++) if (A[j] & (1LL << i)) break;
        if (j == N) continue; // ビットが立っていない
        if (j > rank) A[rank] ^= A[j]; // 下でビットが立っているので上に移す
        for (j = rank+1;j<N;j++) A[j] = min(A[j],A[j] ^ A[rank]);
        rank++;
    }
    ull ans = 0;
    for (int i=0;i<N;i++) ans = max(ans,ans ^ A[i]);
    cout << (ans << 1) + all << endl;

    return 0;
}


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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

const int MAX = 1 << 17;

int a[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	FOR(i, 1, n + 1)
		cin >> a[i];
	int tot = 0;
	FOR(i, 0, n + 1)
		tot += abs(a[i + 1] - a[i]);
	FOR(i, 1, n + 1)
		cout << tot - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i - 1]) << "\n";
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll X;
        cin >> X;
        ll ans = inf;
        rep(i, 1, 1000000) {
                ll a = i * (i+1) / 2;
                if (a >= X) {
                        ans = i;
                        break;
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
box = [[0, 1] for _ in range(n+1)]
box[0][1] = 0
box[1][0] = 1
for i in range(m):
  x, y = map(int, input().split())
  if box[x][0]:
    box[y][0] = 1
  box[x][1] -= 1
  box[y][1] += 1
  if box[x][1] == 0:
    box[x][0] = 0
print(sum(box[x][0] for x in range(1,n+1)))

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

int sent(int num){
string s = to_string(num);
  return s[0] - '0';
}

int back(int num){
string s = to_string(num);
  return s[s.size() - 1] - '0';
}

int main (){

  int n; cin >> n;
  int data[9][9] = {{}};
  for(int i = 1; i <= n; i++){
    if(i % 10 == 0){continue;}
     data[sent(i) - 1][back(i) - 1]++;  
  }
  
  int ans = 0;
  for(int i = 0; i < 9; i++){
     for(int  j = i; j < 9; j++){
       if(i == j){ans += data[i][j] * data[j][i];}
       else{ans += (data[i][j] * data[j][i]) * 2;} 
     }
  }
  cout << ans << endl;
  
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#include <chrono>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cstring>
#include <cassert>
#include <math.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;


int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        int n; scanf("%d", &n);
        map<int, int> ev;
        map<int, int> l, r;
        for(int i = 0; i < n; i++) {
            int a, b; scanf("%d%d", &a, &b);
            ev[a], ev[b];
            l[a]++;
            r[b]++;
        }
        if(n % 2) {
            int mid = 0;
            int le = 0;
            int mn = 1e9, mx = -1;
            for(auto it : ev) {
                int v = it.first;
                mid += l[v];
                int ri = n - le - mid;
                if(le <= n / 2 && ri <= n / 2) mn = min(mn, v), mx = max(mx, v);
                mid -= r[v];
                le += r[v];
            }
            printf("%d\n", max(0, mx - mn + 1));
        }
        else {
            int mid = 0;
            int le = 0;
            int mn1 = 1e9, mx1 = -1;
            int mn2 = 1e9, mx2 = -1;
            for(auto it : ev) {
                int v = it.first;
                mid += l[v];
                int ri = n - le - mid;
                if(le <= (n / 2) - 1 && ri <= n / 2) mn1 = min(mn1, v), mx1 = max(mx1, v);
                if(le <= (n / 2) && ri <= (n / 2) - 1) mn2 = min(mn2, v), mx2 = max(mx2, v);
                mid -= r[v];
                le += r[v];
            }
            printf("%d\n", (mx1 + mx2) - (mn1 + mn2) + 1);
        }
    }
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 1e3 + 5;

char g[MAXN][MAXN];

string s4[4] = {
	"aabc",
	"ddbc",
	"bcaa",
	"bcdd"
};

string s5[5] = {
	"abbcc",
	"a..de",
	"b..de",
	"bff.g",
	"hhiig"
};

string s6[6] = {
	"aa.aab",
	"..bc.b",
	"..bcdd",
	"eefee.",
	"g.f..f",
	"ghh..f"
};

string s7[7] = {
	"a...hff",
	"a...h.e",
	"b...dde",
	"bhff...",
	"ch.e...",
	"cdde...",
	".ccbbaa",
};

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		REP(j, 0, n) {
			g[i][j] = '.';
		}
	}
	if (n == 2) {
		printf("-1\n");
		return;
	}
	if (n == 3) {
		g[0][1] = g[0][2] = 'a';
		g[1][0] = g[2][0] = 'b';
	} else {
		int r = 4 + n % 4;
		if (r == 4) {
			REP(i, 0, 4) {
				REP(j, 0, 4) {
					g[i][j] = s4[i][j];
				}
			}
		} else if (r == 5) {
			REP(i, 0, 5) {
				REP(j, 0, 5) {
					g[i][j] = s5[i][j];
				}
			}
		} else if (r == 6) {
			REP(i, 0, 6) {
				REP(j, 0, 6) {
					g[i][j] = s6[i][j];
				}
			}
		} else if (r == 7) {
			REP(i, 0, 7) {
				REP(j, 0, 7) {
					g[i][j] = s7[i][j];
				}
			}
		}
		for(int k = r; k < n; k += 4) {
			REP(i, 0, 4) {
				REP(j, 0, 4) {
					g[k + i][k + j] = s4[i][j];
				}
			}
		}
	}
	REP(i, 0, n) {
		printf("%s\n", g[i]);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 2176
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

var m = make(map[string]string)

func main() {
	n := readInt()
	s := readString()

	bitPlusCnt := strings.Count(s, "1") + 1
	bitMinusCnt := bitPlusCnt - 2
	if bitMinusCnt == 0 {
		bitMinusCnt = -1
	}
	// fmt.Println(bitCnt, bitMinusCnt, bitPlusCnt)

	plusR := make([]int, n)
	minusR := make([]int, n)
	plusR[n-1] = 1 % bitPlusCnt
	minusR[n-1] = 1 % bitMinusCnt
	for i := n - 2; i >= 0; i-- {
		plusR[i] = plusR[i+1] * 2 % bitPlusCnt
		minusR[i] = minusR[i+1] * 2 % bitMinusCnt
	}
	// fmt.Println(plusR)
	// fmt.Println(minusR)

	rPlus := 0
	rMinus := 0
	for i := n - 1; i >= 0; i-- {
		if s[i] == '1' {
			rPlus = (rPlus + plusR[i]) % bitPlusCnt
			rMinus = (rMinus + minusR[i]) % bitMinusCnt
		}
	}

	for i := 0; i < n; i++ {
		ans := 1
		r := 0
		if s[i] == '1' {
			if bitMinusCnt == -1 {
				fmt.Println(0)
				continue
			}
			r = ((rMinus-minusR[i])%bitMinusCnt + bitMinusCnt) % bitMinusCnt
		} else {
			r = (rPlus + plusR[i]) % bitPlusCnt
		}

		for r != 0 {
			bcnt := strings.Count(fmt.Sprintf("%b", r), "1")
			r = r % bcnt
			ans++
		}

		fmt.Println(ans)
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 9480
#include <bits/stdc++.h>
#define ll long long

using namespace std;


int main() {
    
     ll n,w;
     cin>>n>>w;
     ll we[n+1],pro[n+1];
     for(ll i=1;i<=n;i++){cin>>we[i];cin>>pro[i];}
     
     ll m[n+1][w+1];
    for(ll i=0;i<=w;i++)m[0][i]=0;
    for(ll i=1;i<=n;i++)
    {
        m[i][0]=0;
        for(ll j=1;j<=w;j++)
        {
            if(j>=we[i])
            {
                m[i][j]=max(m[i-1][j-we[i]]+pro[i],m[i-1][j]);
            }
            else
            m[i][j]=m[i-1][j];
        }
        
    }
    cout<<m[n][w]<<endl;
   /*
    for(ll  i=0;i<=n;i++)
    {    for(ll j=0;j<=w;j++)
            cout<<m[i][j]<<" ";
        cout<<endl;
    }
    */

     
    
     
     
}

Measured memory_bytes: 79104