akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 1e5 + 5, Mod = 1e9 + 7;
typedef ll arr[Maxn];
ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n, k;
arr fac, inv, invfac;
ll ans;
struct str
{
	int cnt, pos;
	bool operator<(str A) const { return cnt < A.cnt || (cnt == A.cnt && pos < A.pos); }
} a[Maxn];
ll C(int x, int y) { return fac[x] * invfac[y] % Mod * invfac[x - y] % Mod; }
int main()
{
	fac[0] = inv[1] = invfac[0] = 1;
	for (int i = 1; i <= 100000; i++)
	{
		fac[i] = fac[i - 1] * i % Mod;
		if (i > 1)
			inv[i] = (Mod - Mod / i) * inv[Mod % i] % Mod;
		invfac[i] = invfac[i - 1] * inv[i] % Mod;
	}
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		a[i] = {read(), i};
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n - k + 1; i++)
		ans = Add(ans, -(a[i].cnt * C(n - i, k - 1) % Mod));
	for (int i = k; i <= n; i++)
		ans = Add(ans, (a[i].cnt * C(i - 1, k - 1) % Mod));
	cout << ans << '\n';
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

void bubble_sort(vector<string>& v)
{
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    for (int j = n - 1; j > i; --j) {
      if (v[j - 1][1] > v[j][1]) {
        swap(v[j - 1], v[j]);
      }
    }
  }
}

void selection_sort(vector<string>& v)
{
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    int ix = i;
    for (int j = i; j < n; ++j) {
      if (v[j][1] < v[ix][1]) {
        ix = j;
      }
    }
    swap(v[i], v[ix]);
  }
}

bool cmp(const string& s1, const string& s2)
{
  return s1[1] < s2[1];
}

void print(vector<string> v)
{
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    if (i) { fprintf(stdout, " "); }
    fprintf(stdout, "%s", v[i].c_str());
  }
  fprintf(stdout, "\n");
}

int main()
{
  int n = 0;
  cin >> n;
  vector<string> cards(n);
  for (int i = 0; i < n; ++i) {
    cin >> cards[i];
  }
  vector<string> bubble = cards, sel = cards;
  stable_sort(cards.begin(), cards.end(), cmp);
  bubble_sort(bubble);
  selection_sort(sel);
  //print(cards);
  print(bubble);
  fprintf(stdout, "%s\n", cards == bubble ? "Stable" : "Not stable");
  print(sel);
  fprintf(stdout, "%s\n", cards == sel ? "Stable" : "Not stable");
  return 0;
}

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

using namespace std;
const long long MOD = 1e9+7;
const long long MAXN = 1e5+5;
long long arr[MAXN];
long long arr2[MAXN];
long long dp[MAXN];
long long dp2[MAXN];
int main(){
    long long x,y;
    cin>>x>>y;
    if(abs(x-y) <=1){
        cout<<"Brown"<<endl;
    }else{
        cout<<"Alice"<<endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll dp[3001][3001];
int main()
{
	int n;
	cin>>n;
	vector<ll>a(n);
	for(ll&x :a)cin>>x;
	int c = n%2?1:-1;
	for(int i=0;i<n;i++)dp[i][i] = a[i]*c;
	c*=-1;
	for(int j=1;j<n;j++)
	{
		for(int i=0;i+j<n;i++){
			if(c == 1)dp[i][i+j] = max(dp[i+1][i+j]+a[i],dp[i][i+j-1]+a[i+j]);
			else dp[i][i+j] = min(dp[i+1][i+j]-a[i],dp[i][i+j-1]-a[i+j]);
		}
		c*=-1;
	}
	cout<<dp[0][n-1];
}


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

int main(void) {
  int N;
  string S, T;

  cin >> N;
  cin >> S >> T;

  for(int i=0;i<N;i++) {
    cout << S.at(i) << T.at(i);
  }

  cout << endl;

  return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

bool any(const string& s, function<bool(char)> f){
    for(auto c : s) if(f(c)) return true;
    return false;
}
int main(){
    string s;
    cin >> s;
    if(s.size() >= 6 && any(s, [](char c){ return c >= '0' && c <= '9'; }) &&
                        any(s, [](char c){ return c >= 'a' && c <= 'z'; }) &&
                        any(s, [](char c){ return c >= 'A' && c <= 'Z'; })){
        cout << "VALID" << endl;
    }else{
        cout << "INVALID" << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
// Independent set

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
#define mod 1000000007
using namespace std;

ll dfs(ll root,vector< vector<ll> >& adj,vector<ll>& wdp,vector<ll>& bdp,vector<bool>& visited,ll parent)
{
	ll flag=0;
	visited[root]=true;
	for(auto itr:adj[root])
	{
		if(!visited[itr])
		{
			dfs(itr,adj,wdp,bdp,visited,root);
			flag++;
		}
	}
	//do your work
	
	//leaf node
	if(flag==0)
	{
		bdp[root]=1;
		wdp[root]=1;
	}
	else
	{
		//non leafnode
		
		//when root is white
		ll tcomb=1;
		for(auto it:adj[root])
		{
			if(it!=parent)
			tcomb=(tcomb%mod)*((wdp[it]+bdp[it])%mod)%mod;
		}
		wdp[root]=tcomb;
		
		//when root is black	
		ll tcomb2=1;
		for(auto it:adj[root])
		{
			if(it!=parent)
			tcomb2=(tcomb2%mod)*(wdp[it])%mod;
		}
		bdp[root]=tcomb2;
	}
	return bdp[root]+wdp[root];
}

void solve(ll n,vector< vector<ll> >& adj)
{
	ll result=0;
	vector<ll> whitedp(n+1);
	vector<ll> blackdp(n+1);
	vector<bool> visited(n+1,false);
	
	for(ll i=1;i<=n;i++)
	{
		if(!visited[i])
		result=(result+dfs(i,adj,whitedp,blackdp,visited,-1))%mod;
	}
	
	cout<<(result)<<endl;
//	cout<<"white dp"<<endl;
//	for(auto it:whitedp)
//	cout<<it<<" ";
//	
//	cout<<endl;
//	cout<<"Black dp"<<endl;
//	for(auto itr:blackdp)
//	{
//		cout<<itr<<" ";
//	}
}

int main()
{
	ll n,x,y;
	cin>>n;
	vector< vector<ll> > adj(n+1);
	for(ll i=1;i<=n-1;i++)
	{
		cin>>x>>y;
		//directional graph
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	
	solve(n,adj);
	return 0;
}


Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009];
int main()
{
    ll a,b,c,i,j,k,x=0;
    string s[5000],d;
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cin>>s[i]>>ar[i];
        x=x+ar[i];
    }
    cin>>d;
    for(i=1;i<=a;i++)
    {
        x=x-ar[i];
        if(d==s[i])break;
    }
    cout<<x<<endl;
}


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

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> maze(H);
  rep(i,H) cin >> maze[i];

  int mx = 0;

  rep(k,H){
    rep(l,W){
      if(maze[k][l]=='#') continue;
      vector<vector<int> > dist(H, vector<int>(W,-1));
      dist[k][l] = 0;

      queue<pair<int, int> > que;
      que.push(make_pair(k,l));

      while(!que.empty()){
        pair<int, int> current_pos = que.front();
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop();

        rep(d,4){
          int next_x = x + dx[d];
          int next_y = y + dy[d];
          if(next_x < 0 || next_x >= H) continue;
          if(next_y < 0 || next_y >= W) continue;
          if(maze[next_x][next_y]=='#') continue;

          if(dist[next_x][next_y]==-1){
            que.push(make_pair(next_x, next_y));
            dist[next_x][next_y] = dist[x][y] + 1;
          }
        }
      }

      rep(i,H){
        rep(j,W){
          mx = max(mx,dist[i][j]);
        }
      }

    }
  }

  cout << mx << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

N, M = list(map(int, input().split()))
a=[]
for i in range(M):
    a.append(int(input()))

num = [0 for i in range(N)]
for i in range(M):
    num[a[i] - 1] = 1000000008
if num[0] == 0:
    num[0] = 1
if len(num) >= 2 and num[1] == 0:
    num[1] = 1 + min(1000000007, num[0])
    num[1] = num[1] % 1000000007
for i in range(2, N):
    if num[i] < 1000000008:
        num[i] = min(1000000007, num[i - 1]) + min(1000000007, num[i - 2])
        num[i] = num[i] % 1000000007
print(num[N - 1])

Measured memory_bytes: 49116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int ketasuu(int n){
    int ans = 1;
    int a = n;
    while(a > 9){
        ans++;
        a /= 10;
    }
    return ans;
}

int main() {
    int n, ans;
    cin >> n;
    int d = ketasuu(n);
    if(d==6){
        ans = 9 + 900 + 99999 - 10000 + 1;
    } else if(d==5){
        ans = 9 + 900 + n - 10000 + 1;
    } else if(d == 4){
        ans = 9 + 900;
    } else if(d == 3){
        ans = 9 + n - 100 + 1;
    } else if(d == 2){
        ans = 9;
    } else {
        ans = n - 1 + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
//----------------------------------------------------------------

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

  prt3(c, a, b);

}


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

int main()
{
	int n, q;

	cin >> n;
	vector<long long> a(n);

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

	cin >> q;

	for (int i = 0; i < q; i++) {
		long long k;
		cin >> k;

		cout << (lower_bound(a.begin(), a.end(), k) - a.begin()) 
			<< " " << (upper_bound(a.begin(), a.end(), k) - a.begin()) << endl;
	}

	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char s[3][110];
int now[3]={0,0,0};

int rec(int i){
    if(now[i] == strlen(s[i])) return i;
    char next = s[i][now[i]];
    now[i]++;
    return rec(next - 'a');
}

int main(){
    for(int i = 0; i < 3; i++) int ret = scanf("%s", s[i]);
    printf("%c\n", rec(0) + 'A');
    return 0;
}


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

int main() {
  string S; cin >> S;
  int charFreq[26] = {0};
  for (int i = 0; i < S.size(); ++i) {
    charFreq[(int)S[i] - 'a']++;
  }
  int flag = 0;
  for (int i = 0; i < 26; ++i) {
    if (!charFreq[i]) {
      flag = 1;
      cout << (char)('a' + i) << endl;
      break;
    }
  }
  if (!flag) {
    cout << "None" << endl;
  }
}

Measured memory_bytes: 768
#include<algorithm>
#include<iostream>
#include<climits>
#include<cstdio>
#include<cmath>
using namespace std;
//{{{ read()
inline int read(){
	register int x=0,f=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')	f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x*f;
}
//}}}
const long double pi=acos(-1);
const int N=2e5+5;
struct each{
	int x,y;
}a[N];
int n,k,f1,f2,xl,yl,xr,yr,top,f[N];
bool com(each x,each y){
	return x.x<y.x;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	xl=read(),yl=read(),xr=read(),yr=read(),n=read();
	if(xl>xr)	f1=-1;
	else	f1=1;
	if(yl>yr)	f2=-1;
	else	f2=1;
	xl*=f1,xr*=f1,yl*=f2,yr*=f2;
	for(int i=1;i<=n;i++){
		int x=read()*f1,y=read()*f2;
		if(x<xl||x>xr||y<yl||y>yr)	--i,--n;
		else	a[i].x=x,a[i].y=y;
	}
	sort(a+1,a+n+1,com),f[0]=-INT_MAX;
	for(int i=1;i<=n;i++)
		if(a[i].y>f[top])	f[++top]=a[i].y;
		else{
			int l=1,r=top;
			while(l<r){
				int mid=(l+r)>>1;
				if(f[mid]<a[i].y)	l=++mid;
				else	r=mid;
			}
			f[l]=a[i].y;
		}
	long double ans=(long double)((xr-xl)+(yr-yl))*100+top*(5*pi-20);
	if(top==min(xr-xl,yr-yl)+1)	ans+=5*pi;
	printf("%.11Lf\n",ans);
	return 0;
}


Measured memory_bytes: 2560
N = int(input())


def sum(n):
    return n*(n+1)//2


# for i in range(1, N+1):
#     if i % 3 != 0 and i % 5 != 0:
#         ans += i
ans = sum(N)-sum(N//3)*3-sum(N//5)*5+sum(N//15)*15
print(ans)


Measured memory_bytes: 61788
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    if N % 2 == 0:
        print(*A[1::2][::-1], *A[::2])
    else:
        print(*A[::2][::-1], *A[1::2])


if __name__ == '__main__':
    main()


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

int main(void)
{
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> kn(n, 0);

    for(int i = 0; i < n-1; ++i) {
        vector<int> cost(n, n);
        if(i >= x-1) {
            for(int p = 0; p < y-x; ++p) {
                if(y-x-p-(i-x+1) >= 0) cost.at((y-x-p-(i-x+1))) = 1+p+(i-x+1);
            }
        }
        cost.at(0) = 0;
        for(int j = 1; j+i < n; ++j) {
            cost.at(j) = min(cost.at(j-1) + 1, cost.at(j));
            if(j+1 < n) cost.at(j) = min(cost.at(j+1) + 1, cost.at(j));
            if(i+j == x-1) {
                for(int p = 0; p < y-x; ++p) {
                    cost.at(j+(y-x)-p) = min(cost.at(j) + 1 + p, cost.at(j+(y-x)-p));
                }
            }
            ++kn.at(cost.at(j));
        }
    }

    for(int i = 1; i < n; ++i) {
        cout << kn.at(i) << endl;
    }

    return 0;
}



Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {($(read_value!($iter, $t)),*)};
    ($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_|read_value!($iter, $t)).collect::<Vec<_>>()};
    ($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};
    ($iter:expr, usize1) => {read_value!($iter, usize) - 1};
    ($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};
}

fn main() {
    input! {n: u32}
    let v = (1..10).collect::<Vec<u32>>();
    for p in v.iter().rev() {
        if n % *p == 0 {
            if n / *p <= 9 {
                println!("Yes");
                return;
            }
            println!("No");
            return;
        }
    }
}


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

const int INF = 1e9;

int main(){
    int v, e, s, t, d;
    cin >> v >> e;

    int dp[v][1<<v], dist[v][v];
    for(int i = 0; i < v; i++){
        for(int j = 0; j < 1<<v; j++){
            dp[i][j] = INF;
            if(j < v)   dist[i][j] = INF;
        }
    }

    // 巡回路なので始点を0に固定してしまっても問題ない
    dp[0][0] = 0;

    for(int i = 0; i < e; i++){
        cin >> s >> t >> d;
        dist[s][t] = d;
    }

    for(int s = 0; s < 1<<v; s++){
        for(int i = 0; i < v; i++){
            if(dp[i][s] == INF) continue;
            for(int j = 0; j < v; j++){
                if(i == j || dist[i][j] == INF || (s&(1<<j)))   continue;
                dp[j][s|(1<<j)] = min(dp[j][s|(1<<j)], dp[i][s]+dist[i][j]);
            }
        }
    }

    int ans = dp[0][(1<<v)-1];
    if(ans == INF)  ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5012
#include <iostream>

using namespace std;


static const int white = 0;
static const int black = 1;
static const int emp = -1;
static const int inf = 1000000;

int graph[124][124] = {{}};
int d[124] = {};
int n;



void dijkstra(){

  int u,mincost;
  int p[124] = {};
  int color[124] = {};

  for(int i = 0;i < n;i++){
    d[i] = inf;
    color[i] = white;
    p[i] = emp;
  }

  d[0] = 0;

  while(1){

    mincost = inf;
    for(int i = 0;i < n;i++){
      if(color[i] != black && mincost > d[i]){
	mincost = d[i];
	u = i;
      }
    }
    //  cout << "u =  " << u << endl;

    if(mincost == inf) break;
    color[u] = black;

    for(int i = 0;i < n;i++){
      if(color[i] != black && graph[u][i] != emp){
	if(d[u] + graph[u][i] < d[i]){
	  d[i] = d[u] + graph[u][i];
	  p[i] = u;
	}
      }
    }
  }
}


int main(){

  int u,k,ui,c;
  cin >> n;



  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      graph[i][j] = emp;
    }
  }


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

    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> ui >> c;
      graph[u][ui] = c;
    }
  }


  dijkstra();

  for(int i = 0;i < n;i++){
    cout << i << ' ' << d[i] << endl;
  }

}

Measured memory_bytes: 3096
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort 
using namespace std;                      // use as s.f();
using namespace __gnu_pbds;



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		ll a[100001];
		ll dp[100001];
		dp[0]=0;
		ll ans=0;
		for(ll i=1;i<=n;i++)
		{
		cin>>a[i];
		dp[i]=999999999999;
		}
		dp[0]=0;
		dp[1]=0;
		dp[2]=abs(a[1]-a[2]);
		for(ll i=3;i<=n;i++)
		{
		ll m1=999999999999999;
		for(ll j=1;j<=k;j++)
		{
		ll p=i-j;
		if(p>0)
		{
		m1=min(m1,dp[p]+abs(a[i]-a[p]));
		}
		dp[i]=m1;
		}
		
		//dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));							
		}
		ans=dp[n];
		cout<<ans<<endl;
	}
	
return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
	int H,N,A;
	scanf("%d %d",&H,&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A);
		H -= A;
		if( H<=0 ){ printf("Yes"); return 0; }
	}
	printf("No");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
int n,m,A[22][22];
int main() {
	scanf("%d%d",&n,&m);
	For(i,1,n)
		For(j,1,m) scanf("%d",&A[i][j]);
	int ans=0;
	For(i,1,n)
		For(j,i+1,n) {
			int t=0,x;
			For(k,1,m) t+=(A[i][k]-A[j][k])*(A[i][k]-A[j][k]);
			x=sqrt(t);
			if(x*x==t) ++ans;
		}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N, M; cin >> N >> M;
    int a[M], b[M];
    vector<int> imos(N + 1, 0);
    rep(i, M) {
        cin >> a[i] >> b[i];
        imos[a[i] - 1] += 1;
        imos[b[i] - 1] += -1;
    }
    bool ok = true;
    rep(i, N) {
        imos[i + 1] += imos[i];
        if(imos[i + 1] % 2) ok = false;
    }
    if(M == 1) ok = false;
    if(ok) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 1408
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,char> Q;
ll longinf=1ll<<60;
int inf=1<<29;

int main(){
      string s;
      cin>>s;
      int n=s.size();
      bool ok=false;
      rep0(i,n){
            for(int j=i;j<n;j++){
                  string t;
                  for(int k=0;k<i;k++){
                        t+=s[k];
                  }
                  for(int k=j;k<n;k++){
                        t+=s[k];
                  }
                  if(t=="keyence") ok=true;
            }
      }
      if(ok) cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
      return 0;
}

Measured memory_bytes: 256
import bisect

N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()
LC = len(C)
ans = 0
for b in B:
    na = bisect.bisect_left(A, b)
    nc = LC - bisect.bisect_right(C, b)
    ans += na * nc

print(ans)

Measured memory_bytes: 23232
x, n = map(int, input(). split())
p = list()
if n > 0:
  p = list(map(int, input(). split()))
if x not in p:
  print(x)
else:
  d = 1
  while True:
    if x-d not in p:
      print(x-d)
      break
    if x+d not in p:
      print(x+d)
      break
    d += 1

Measured memory_bytes: 61928
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while i < len(s) and s[i] != 'W':
                i += 1
        while j >= 0 and s[j] != 'R':
                j -= 1
        if i < j:
            # s = list(s)
            s[i], s[j] = s[j], s[i]
            # s = "".join(s)
            counter += 1
        i += 1
        j -= 1

    # print(counter)

    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1

    print(counter)

s = list(s)
find_cost(s)

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

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

void Main() {
  // code
  int n;
  long int k;
  cin >> n >> k;
  vector<pair<int, int>> vpii;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    vpii.push_back(make_pair(a, b));
  }
  sort(all(vpii));

  long int s = 0;
  for (auto pii : vpii) {
    if (s < k && k <= s + pii.second) {
      cout << pii.first << endl;
      return;
    } else {
      s += pii.second;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x; cin>>x;
  int a[]={1800, 1600, 1400, 1200, 1000, 800, 600, 400};
  for(int i=0;i<8;i++){
    if(x>=a[i])
      return cout<<i+1<<"\n", 0;
  }
  return 0;
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size()){
        cout<<"GREATER"<<endl;
        return 0;
    }
    else if(a.size()<b.size()){
        cout<<"LESS"<<endl;
        return 0;
    }
    else{
        if(a>b) cout<<"GREATER"<<endl;
        else if(a<b) cout<<"LESS"<<endl;
        else cout<<"EQUAL"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3592
s=input()
a,b,c=0,0,0

for i in range(len(s)):
    if s[i]=='a':
        a+=1
    elif s[i]=='b':
        b+=1
    else :
        c+=1

ans = (abs(a-b) <2) and (abs(c-b)<2) and (abs(c-a)<2)
print( "YES" if ans else "NO") 

Measured memory_bytes: 9124
def main():
    a,b,c,d = map(int, input().split())
    turn = 1
    while True:
        if turn == 1:
            c -= b
        else:
            a -= d
        
        if a <= 0:
            print('No')
            break
        elif c <= 0:
            print('Yes')
            break
        turn *= -1
if __name__ == "__main__":
    main()

Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int a,b;
	while(cin>>a>>b)
	{
		int cnt = 0;
		a += b;
		while(a>0)
		{
			cnt++;
			a /= 10;
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 3064
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    ll r, D, x;
    cin >> r >> D >> x;
    rep(i, 10) {
        x = r * x - D;
        print(x);
    }
    return 0;
}

Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N = gete(int)
    a = [0]*(N+1)
    b, c = a[:], a[:]

    for i in range(N):
        av, bv, cv = geta(int)
        a[i+1] = av + max(b[i], c[i])
        b[i+1] = bv + max(c[i], a[i])
        c[i+1] = cv + max(a[i], b[i])

    print(max(a[-1], b[-1], c[-1]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 50904
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
const ll MOD = 1e9 + 7;

const int MAX = 200001;

// fac[n]: n!
// finv[n]: (n!)^-1
// inv[n]: nの逆元
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
  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] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算 (combination)
// nCk = (n!) * (k!)^-1 * ((n-k)!)^-1 として計算
ll comb(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;
}

ll N, K;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  comb_init();

  ll blue = K;
  ll red = N - K;

  for (ll i = 1; i <= blue; i++) {
    // if (i > red + 1) {
    //   cout << 0 << endl;
    //   continue;
    // }

    // if (i == 1) {
    //   ll ans = comb(red + 1, i);
    //   cout << ans % MOD << endl;
    // } else {
    ll ans = comb(red + 1, i) * comb(blue - 1, i - 1);
    cout << ans % MOD << endl;
    // }
  }
  return 0;
}

Measured memory_bytes: 4992
import sys

def getsum(n):
  if n > 36: return 0
  else:
    i = n if n < 19 else 36-n
    return (i+3)*(i+2)*(i+1)//6 - max(2*(i-9)*(i-8)*(i-7)//3,0)

for i in sys.stdin:
    print(getsum(int(i)))

Measured memory_bytes: 7716
#include <bits/stdc++.h>
#define ll long long
#define maxn 105 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
vi eg[maxn];
int chs[maxn], dep[maxn], fa[maxn], mxs;
void dfs(int a) {
	if (dep[a] > dep[mxs]) mxs = a; 
	int nr = 0;
	for (auto v : eg[a]) {
		if (v == fa[a]) continue;
		nr++;
		dep[v] = dep[a] + 1, fa[v] = a, dfs(v);
	}
	chs[dep[a]] = max(chs[dep[a]], nr);
}
int res; 
ll cal(int a, int b) {
	memset(chs, 0, sizeof(chs));
	if (!b) fa[a] = 0, dep[a] = 1, dfs(a);
	else {
		fa[a] = b, fa[b] = a, dep[a] = dep[b] = 1;
		dfs(a), dfs(b);
	}
	ll ans = 1;
	for (int i = res - 1; i >= 1; i--)
		ans = ans * chs[i];
	if (b != 0) ans *= 2;
	return ans;
}
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		eg[a].pb(b), eg[b].pb(a);
	}
	dep[1] = 1, dfs(1);
	int nrt = mxs;
	fa[nrt] = 0, dep[nrt] = 1;
	mxs = 0, 
	dfs(nrt);
	int npl = mxs;
	ll ans;
	res = (dep[npl] + 1) / 2;
	vi q;
	while (npl)
		q.pb(npl), npl = fa[npl];
	if (q.size() % 2) {
		int x = q[q.size() / 2];
		ans = cal(x, 0);
		for (auto v : eg[x])
			ans = min(ans, cal(x, v));
	}
	else ans = cal(q[q.size() / 2], q[q.size() / 2 - 1]);
	cout << res << ' ' << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=1,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN3(s,a,b);
  n = stoll(s);
  FOR(i,1,n+1){
    x = 0;
    t = to_string(i);
    REP(j,t.size()){
      x += stoll(gCh(t,j));
    }
  	if(MIDe(a,x,b)) z += i;
  }
  OUT(z);
}


Measured memory_bytes: 256
N, X = map(int,input().split())
thk = [1]
p = [1]

for i in range(N-1):
  thk.append(2*thk[-1]+3)
  p.append(2*p[-1]+1)

def burger(N,X):
  if N==0:
    if X<=0:
      return 0
    else:
      return 1
  elif X <= thk[N-1]+1:
    return (burger(N-1,X-1))
  
  else:
    return p[N-1] + 1 + burger(N-1,X-thk[N-1]-2)
  
print(burger(N,X))

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

int main() {
    int H, W;
    cin >> H >> W;
    string s[50];
    rep(i, H) cin >> s[i];
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    rep(i, H) {
        rep(j, W) {
            if (s[i][j] == '.') continue;
            int count = 0;
            for (int k = 0; k < 4; k++) {
                int x = j + dx[k];
                int y = i + dy[k];
                if (x < 0 || W <= x) continue;
                if (y < 0 || H <= y) continue;
                if (s[y][x] == '#') count++;
            }
            if (count == 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
    string s, s1="";
    cin >> s;
    for (int i=0; i<s.size(); i++) {
        if (s[i] == '1' || s[i] == '0')
            s1 += s[i];
        if (s[i] == 'B' && s1.size() > 0)
            s1.pop_back();
    }
    cout << s1;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<new>
#include<vector>

class HeapTree {
private:
	std::vector<int> A_{ 0 };
	void maxHeapify(int i);
	void buildMaxHeap();
public:
	void insert(int);
	void extractMax();
};

void HeapTree::maxHeapify(int i)
{
	int left{ i * 2 }, right{ i * 2 + 1 }, max;
	if (left < A_.size() && A_[left] > A_[i])
		max = left;
	else
		max = i;
	if (right < A_.size() && A_[right] > A_[max])
		max = right;

	if (max != i)
	{
		int tmp = A_[i];
		A_[i] = A_[max];
		A_[max] = tmp;
		this->maxHeapify(max);
	}
}

void HeapTree::buildMaxHeap()
{
	for (int i = A_.size() - 1; i > 0; i /= 2)
		maxHeapify(i);
}

void HeapTree::insert(int key)
{
	A_.push_back(key);
	buildMaxHeap();
}

void HeapTree::extractMax()
{
	printf("%d\n", A_[1]);
	A_[1] = A_[A_.size() - 1];
	A_.pop_back();
	maxHeapify(1);
}

int main()
{
	int key;
	char str[16];
	HeapTree heapTree;

	while (1)
	{
		scanf("%s", str);
		if (str[0] == 'i')
		{
			scanf("%d", &key);
			heapTree.insert(key);
		}
		else if (str[1] == 'x')
			heapTree.extractMax();
		else
			break;
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  for (auto &e : v) cin >> e;
  for (auto &e : c) cin >> e;
  int r = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] > c[i]) r += v[i] - c[i];
  }
  cout << r << endl;
}


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>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n0 = count(s.cbegin(), s.cend(), '0');
    int n1 = count(s.cbegin(), s.cend(), '1');
    cout << min(n0, n1) * 2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,a,b;
  cin >> n>>a>>b;
  ll sum = 0;
  while(n>0){
    if(a+b>n){
      sum += min(a,n);
      break;
    }else{
      ll k = n/(a+b);
      n -= k*(a+b);
      sum += k*a;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

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

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

    ll n, k;
    cin >> n >> k;
    if(2 * k - 1 > n) {
        cout << -1 << endl;
        return 0;
    }
    V<ll> a, b, c;
    for(int i = k; i < k + n; i += 2)
        a.push_back(i);
    for(int i = k + 1; i < k + n; i += 2)
        a.push_back(i);
    FOR(i, k + n, k + n + n)
    b.push_back(i);
    reverse(ALL(b));
    FOR(i, (k * 2 + n * 5) / 2, k + n * 3) c.push_back(i);
    FOR(i, k + n + n, (k * 2 + n * 5) / 2) c.push_back(i);
    rep(i, n) cout << a[i] << " " << b[i] << " " << c[i] << endl;

    return 0;
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;


struct UnionFind{
  vector<int> d;
  UnionFind(int n) : d(n, -1){}
  int find(int x){
    if(d.at(x) < 0) return x;
    return d.at(x) = find(d.at(x));
  }
  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d.at(x) > d.at(y)) swap(x, y);
    d.at(x) += d.at(y);
    d.at(y)= x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d.at(find(x)); }
};

int main(){
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m){
    int x, y, z;
    cin >> x >> y >> z;
    uf.unite(x-1, y-1);
  }
  int ans = 0;
  rep(i, n){
    if(uf.d.at(i) < 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<vector<int>> data(N, vector<int>(3));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> data.at(i).at(j);
    }
  }
  bool can = true;
  for (int i = 0; i < N; i++)
  {
    int t, distance;
    t = data.at(i).at(0);
    distance = data.at(i).at(1) + data.at(i).at(2);
    if (t % 2 != distance % 2)
    {
      can = false;
      break;
    }
  }
  if (data.at(0).at(0) < data.at(0).at(1) + data.at(0).at(2))
    can = false;
  for (int i = 0; i < N - 1; i++)
  {
    int deltat, deltad;
    deltat = data.at(i + 1).at(0) - data.at(i).at(0);
    deltad = abs((data.at(i + 1).at(1) + data.at(i + 1).at(2)) - (data.at(i).at(1) + data.at(i).at(2)));
    if (deltad > deltat)
    {
      can = false;
      break;
    }
  }
  if (can)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	string s,t;
	cin>>s>>t;
	bool B=0;
	for(int i=0;i<2;i++){
		string s_;
		for(int j=i;j<s.size();j+=2) s_+=s[j];
		int I=0,n=s_.size();
		for(int j=0;j<t.size();j++) if(I<=n&&s_[I]==t[j]) I++;
		if(I==n) B=1;
	}
	cout<<(B?"Yes":"No")<<endl;
}


Measured memory_bytes: 3184
<?php
fscanf(STDIN, "%d", $allMoney);
$cards = trim(fgets(STDIN));
$card = explode(" ", $cards);

$alicePoint = 0;
$bobPoint = 0;

while(count($card)!=0){
    $deleteCard = array_splice($card, array_search(max($card), $card), 1);
    $alicePoint += $deleteCard[0];
    
    //aliceがカードをとった時点でカード０枚になった場合、終了する。
    if(count($card) == 0){break;}
    
    $deleteCard = array_splice($card, array_search(max($card), $card), 1);
    $bobPoint += $deleteCard[0];
}

echo $alicePoint - $bobPoint;

Measured memory_bytes: 4728
1.upto(50) { |cnt|
  $aw = gets.to_i
  break if $aw == 0

  $an = gets.to_i
  $v,$w = Array.new($an), Array.new($an)
  0.upto($an - 1) { |i|
    $v[i], $w[i] = gets.split(",").map(&:to_i)
  }

  $dv, $dw = Array.new($an){Array.new($aw + 1)}, Array.new($an){Array.new($aw + 1)}
  def calc(i, j)
    return 0 if i >= $an
    return $dv[i][j], $dw[i][j] if $dv[i][j] != nil && $dw[i][j] != nil

    res = 0
    if j < $w[i]
      res = calc(i + 1, j)
    else
      d1 = calc(i + 1, j)
      d2 = calc(i + 1, j - $w[i])
      if d1[0] >= (d2[0] + $v[i])
        res = d1[0], d1[1]
      else
        res = d2[0] + $v[i], d2[1] + $w[i]
      end
    end
    $dv[i][j], $dw[i][j] = res
    #puts "$dv[#{i}][#{j}], $dw[#{i}][#{j}] = #{res}"
    return res
  end

  puts "Case #{cnt}:"
  ans = calc(0, $aw)
  puts ans[0]
  puts ans[1]
}

Measured memory_bytes: 24924
#include <iostream>

using namespace std;

int main()
{
    int sx, sy, tx, ty; 
    cin >> sx >> sy >> tx >> ty; 

    int difx = tx - sx; 
    int dify = ty - sy; 

    for (int i = 0; i < dify; i++) {
        cout << "U";
    }   
    for (int i = 0; i < difx; i++) {
        cout << "R";
    }   
    for (int i = 0; i < dify; i++) {
        cout << "D";
    }   
    for (int i = 0; i < difx; i++) {
        cout << "L";
    }   
    cout << "L";
    for (int i = 0; i < dify + 1; i++) {
        cout << "U";
    }   
    for (int i = 0; i < difx + 1; i++) {
        cout << "R";
    }   
    cout << "D" << "R";
    for (int i = 0; i < dify + 1; i++) {
        cout << "D";
    }   
    for (int i = 0; i < difx + 1; i++) {
        cout << "L";
    }   
    cout << "U" << endl;
}



                                                                                                                                                                                                                                                                                                                                    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll fun(ll a, ll b, ll n, ll x)
{
	return ((a * x) / b) - a * (x / b);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	fio;
	ll a, b, n;
	cin >> a >> b >> n;
	//set<ll> s;
	//priority_queue<ll> pq;
	/*auto it = s.end();
	it--;
	cout << *it;*/
	/*for (ll x = 0; x <= 20; x++)
		cout << fun(a, b, n, x) << endl;*/
	if (n <= b - 1)
		cout << fun(a, b, n, n) << endl;
	else if (n >= b)
		cout << max(fun(a, b, n, b - 1), fun(a, b, n, b - 2)) << endl;
	return 0;
}


Measured memory_bytes: 3648