akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
using cost_t=int;

struct Edge {
    int from, to;
    cost_t cost;
    Edge(int from, int to, cost_t cost) : from(from), to(to), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct LCA{
    static const int LOGN=20;
    array<vector<int>,LOGN+1> par;
    vector<int> dep;
    void dfs(int v,int pre,Graph& g){
        for(auto& e:g[v]){
            if(e.to==pre) continue;
            par[0][e.to]=v;
            dep[e.to]=dep[v]+1;
            dfs(e.to,v,g);
        }
    }

    LCA(Graph& g,int root):dep(g.size()){
        int n=g.size();
        for(int i=0;i<=LOGN;i++) par[i].assign(n,-1);
        dep[root]=0;
        par[0][root]=root;
        dfs(root,-1,g);
        for(int i=0;i<LOGN;i++){
            for(int j=0;j<n;j++){
                par[i+1][j]=par[i][par[i][j]];
            }
        }
    }

    int query(int u,int v){
        if(dep[u]<dep[v]) swap(u,v);
        int d = dep[u]-dep[v];
        for(int i=LOGN;i>=0;i--){
            if((d>>i)&1){
                u = par[i][u];
                d-=(1<<i);
            }
        }
        if(u==v) return u;
        for(int i=LOGN;i>=0;i--){
            if(par[i][u]!=par[i][v]) u=par[i][u],v=par[i][v];
        }
        return par[0][u];
    }
};
int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        while(k--){
            int v; cin>>v;
            g[i].push_back(Edge(i,v,0));
            g[v].push_back(Edge(v,i,0));
        }
    }
    LCA lca(g,0);
    int q;
    cin>>q;
    while(q--){
        int u,v;
        cin>>u>>v;
        cout<<lca.query(u,v)<<endl;
    }
    return 0;
}



Measured memory_bytes: 20084
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 数値n、合計値xの入力準備
		Scanner sc = new Scanner(System.in);
		int n;
		int x;
		// 合計値xの構成要素の3つの数num1、num2、num3を入れる配列をつくる
		ArrayList<Integer> list = new ArrayList<Integer>();

		// 組み合わせの数を入れる答えの配列をつくる
		ArrayList<Integer> anser = new ArrayList<Integer>();

		// num1、num2、num3(1～nの中から重複なし)を配列に入れる
		int min = 1;

		while (true) {
			// 数値n、合計値xを入力
			n = sc.nextInt();
			x = sc.nextInt();

			// 入力終了
			if (n == 0 && x == 0) {
				// 組み合わせの数を表示する
				for (Integer ans : anser) {
					System.out.println(ans);
				}
				break;
			}

			for (int num1 = min; num1 <= n - 2; num1++) {
				for (int num2 = num1 + 1; num2 <= n - 1; num2++) {
					for (int num3 = num2 + 1; num3 <= n; num3++) {
						if (x == num1 + num2 + num3) {
							list.add(num1);
							list.add(num2);
							list.add(num3);
						}
					}
				}
			}

			// 組み合わせの数を答えの配列に入れる
			anser.add((list.size() / 3));

			// 3つの数の配列の中身を削除する
			list.clear();
		}
	}
}


Measured memory_bytes: 27984
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> vec(n);
    rep(i, 0, n) cin >> vec[i].first >> vec[i].second;
    sort(all(vec));
    ll ans = 0;
    ll kosuu = 0;
    rep(i, 0, n)
    {
        ll nanko = min(m - kosuu, vec[i].second);
        kosuu += nanko;
        ans += vec[i].first * nanko;
        if (kosuu >= m)
            break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{

	const int mod = 1000000007;
	static void Main(string[] args)
	{
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		string s = Console.ReadLine();
		List<int> RL = new List<int>();
		List<int> LR = new List<int>();
		LR.Add(-1);

        for(int i = 0; i < s.Length - 1; i++)
		{
			if (s[i] == 'R' && s[i + 1] == 'L')
			{
				RL.Add(i);
			}
			if (s[i] == 'L' && s[i + 1] == 'R')
			{
				LR.Add(i);
			}
		}
		LR.Add(s.Length - 1);

		int[] ans = new int[s.Length];
        for(int i = 0; i < s.Length; i++)
		{
			ans[i] = 0;
		}

		while (RL.Count > 0)
		{
			int R1 = (RL[0] - LR[0] + 1) / 2;
			int L1 = (LR[1] - RL[0]) / 2;
			ans[RL[0]] += L1 + R1;

            int R2= (RL[0] - LR[0]) / 2;
			int L2 = (LR[1] - RL[0] + 1) / 2;
			ans[RL[0] + 1] += L2 + R2 ;

			RL.RemoveAt(0);
			LR.RemoveAt(0);
		}


        for(int i = 0; i < ans.Length; i++)
		{
			Console.Write($"{ans[i]} ");
			
		}
		Console.Out.Flush();
	}
}


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

using namespace std;

int main(void){
  vector<int> vec;
  int i=0,a,b;
  bool judge=true;
  while(true){

      cin>>a>>b;
      if((a==0)&&(b==0)) break;
      i++;
      vec.push_back(a);
      vec.push_back(b);
  }

  for(int j=0;j<i;j++){
      for(int u=0;u<vec.at(j*2);u++){
        if(u%2==0) judge=true;
        else judge=false;
          for(int v=0;v<vec.at(j*2+1);v++){
            if(judge==true){
              cout<<"#";
              judge=false;
            }
            else{
              cout<<".";
              judge=true;
            }
          }
          cout<<endl;
      }
      cout<<endl;
  }

  return 0;
}



Measured memory_bytes: 3124
#include<stdio.h>
int main()
{

  int b1,b2,b3;

  scanf("%d%d%d",&b1,&b2,&b3);

  if(b1==1){
    if(b2==1){
      printf("Open\n");

    }else{
      printf("Close\n");
    }
    
  }else  if(b1==0){
    if(b3==1){
      printf("Open\n");

    }else{
      printf("Close\n");
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 584
#__author__ = "tatuo"
#__date__ = "$Mar 3, 2018 12:34:20 PM$"

import math
import re
import sys


def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result




arr_data = getinputdata()



a = int(arr_data[0][0])
b = int(arr_data[1][0])

if a==b:
    
    print("EQUAL")

elif a>b:
    
    print("GREATER")
    
else:

    print("LESS")

#s3 = arr_data[0][2][0]
#
#
#print(s1.upper() + s2.upper() + s3.upper())

Measured memory_bytes: 3188
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long sx = tmp[0], sy = tmp[1];
    long tx = tmp[2], ty = tmp[3];

    auto s1 = 'U'.repeat(ty-sy);
    auto s2 = 'R'.repeat(tx-sx);
    auto s3 = 'D'.repeat(ty-sy);
    auto s4 = 'L'.repeat(tx-sx);

    auto s5 = 'U'.repeat(ty-sy+1);
    auto s6 = 'R'.repeat(tx-sx+1);
    auto s7 = 'D'.repeat(ty-sy+1);
    auto s8 = 'L'.repeat(tx-sx+1);

    writeln(s1, s2, s3, s4, 'L', s5, s6, 'D', 'R', s7, s8, 'U');
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	LL n,k,q;
	cin >> n >> k >> q;
	VL a(q);
	cin >> a;
	VL p(n,0);
	for (int i = 0; i < q; i++) {
		p[a[i]-1]++;
	}
	for (int i = 0; i < n; i++) {
		if (q - p[i] >= k) {
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	string s;
	cin>>s;
	ll c=s.length();
	int flag=0;
	for(int i=0;i<c-1;i++)
	{
		if(s[i]==s[i+1] ||((s[i]==s[i+2]) && i<c-2))
		{
			if(s[i]==s[i+1])
			{
				cout<<i+1<<" "<<i+2<<endl;
				return(0);
			}
			if(s[i]==s[i+2])
			{
				cout<<i+1<<" "<<i+3<<endl;
				return(0);
			}
		}
	}
	if(flag==0)
	cout<<-1<<" "<<-1<<endl;
}

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

int main()
{

	string s;
	cin >> s;
	if(s=="SUN") printf("7");
	if(s=="MON") printf("6");
	if(s=="TUE") printf("5");
	if(s=="WED") printf("4");
	if(s=="THU") printf("3");
	if(s=="FRI") printf("2");
	if(s=="SAT") printf("1");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
int a,b,c[100],d,e;
scanf("%d",&a);
for(b=0;b<a;b++){
  scanf("%d",&c[b]);
}
for(b=a-1;b>=0;b--){
  if(b>0)
  printf("%d ",c[b]);
  else
  printf("%d",c[b]);
}
printf("\n");
return 0;
}


Measured memory_bytes: 2048
//ΔARC 081D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int mod = 1000000007;
char s1[111],s2[111];
int b[111],f[111];
int main()
{
	int n,i;
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(i=1;i<=n;i=i+1){
		if(s1[i]==s2[i])
			b[i]=0;
		else
			b[i]=1;
	}
	b[0]=1;
	f[0]=1;
	for(i=1;i<=n;i=i+1){
		if(b[i]){
			if(b[i-1])
				f[i+1]=(LL)f[i-1]*3%mod;
			else
				f[i+1]=(LL)f[i-1]*2%mod;
			i++;
		}
		else{
			if(b[i-1])
				f[i]=(LL)f[i-1]*1%mod;
			else
				f[i]=(LL)f[i-1]*2%mod;
		}
	}
	if(!b[1])
		f[n]=(LL)f[n]*3%mod;
	else
		f[n]=(LL)f[n]*2%mod;
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
n = len(str(N))
if n <= 2 :
    print(min(N,9))
elif n == 3 :
    print(9+(N-100+1))
elif n == 4 :
    print(9+900)
else :
    print(min(9+900+(N-10000+1),9+900+90000))

Measured memory_bytes: 9060
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
  int a,b,k,c=0;
  cin>>a>>b>>k;
  for(int i=1000;;i--){
    if(a%i==0&&b%i==0){
      c++;
      if(c==k){
        cout<<i<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <bitset>
#include <functional>
#include <set>
#include <map>
#include <array>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
//#define int long long int
const int MOD = 1000000007;
const int INF = 1001001000;
const double EPS = 0.000000001;

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

bool pairCompare(const PL& pair1, const PL& pair2) {
    return pair1.second > pair2.second;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  vector<ll> a;
  vector<PL> p;
  cin >> n >> m;
  REP(i, n){
    int x;
    cin >> x;
    a.push_back(x);
  }
  REP(i, m){
    int b, c;
    cin >> b >> c;
    p.push_back(P(b,c));
  }
  ll ans = 0;
  sort(ALL(a));
  sort(ALL(p), pairCompare);
  int it = -1;
  REP(i, m){
    int count = p[i].first;
    ll value = p[i].second;

    int k = upper_bound(ALL(a), value) - a.begin() - 1;

    if(k <= it) break;
    else{
      int mult = min(k - it, min(count, (n - it - 1)));
      ans += mult * value;
      it += mult;

    }
    if(it >= n) break;
  }
  for(int i = it+1; i < n; i++){
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3188
#include<cstdio>

int main(void) {
	int a, b, c;
	int x, y;

	x = 0;
	y = 0;
	while(scanf("%d,%d,%d", &a, &b, &c) != EOF) {
		if(c*c == a*a+b*b) {
			x++;
		} else if(a == b) {
			y++;
		}
	}
	printf("%d\n%d\n", x, y);

	return 0;
}

Measured memory_bytes: 0
n,k=map(int,input().split())
a=list(map(int,input().split()))

from itertools import accumulate
l=[]
for i in range(n):
    l+=list(accumulate(a[i:]))

ans=0
for i in range(40,-1,-1):
    j=2**i
    temp=[k for k in l if k&j!=0]
    if len(temp)>=k:
        l=temp
        ans+=j
        
print(ans)

Measured memory_bytes: 27724
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, A: "List[int]"):
    counter = sorted(list(collections.Counter(A).values()),reverse=True)
    c_index = 0
    k=0
    for i in range(1,N+1):
        k+=1
        if len(counter)<i:
            print(0)
            continue
        while counter[c_index]*k > N and c_index<len(counter)-1:
            N-=counter[c_index]
            c_index+=1
            k-=1
        print(N//k)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 56548
#include<stdio.h>

int main(){
        int a[1000001], k;
        scanf("%d", &k);
        a[1]=7%k;
        for(int i=2; i<=k; i++){
                a[i]=(a[i-1]*10+7)%k;
        }
        for(int i=1; i<=k; i++){
                if(a[i]==0){
                        printf("%d", i);
                        return 0;
                }
        }
        printf("-1");
        return 0;
}


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;

    int mx = 1;
    for(int i=1; i*i<=N; i++) {
        if(N%i) continue;
        else mx = i;
    }

    cout << (mx-1) + ((N/mx)-1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
    int a,b,c,d,e,k;
    cin >>a>>b>>c>>d>>e>>k;
    if(k>= e-a){
        cout << "Yay!";
    }else{
        cout << ":(";
    }
    cout << endl;
}

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

//template
#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(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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(a>b){a=b;return 1;}return 0; }
//end

typedef pair<int,int> P;
vector<int> g[201000];
vector<P> h[201000];
int res[201000];
vector<P> done;

int main(){
   int n; scanf("%d",&n);
   rep(i,0,n-1){
      int a,b; scanf("%d%d",&a,&b); a--; b--;
      g[a].push_back(b); g[b].push_back(a);
      h[a].push_back({b,1}); h[b].push_back({a,1});
   }
   int k; scanf("%d",&k);
   rep(i,0,k){
      int v,p; scanf("%d%d",&v,&p); v--;
      done.push_back({v,p});
      h[v].push_back({n,p}); h[n].push_back({v,p});
   }
   priority_queue<P,vector<P>,greater<P>> pq;
   memset(res,0x3f,sizeof(res));
   res[n]=0; pq.push({0,n});
   while(!pq.empty()){
      auto p=pq.top(); pq.pop();
      int d=p.first,v=p.second;
      if(res[v]<d)continue;
      for(auto nxt:h[v])if(chmin(res[nxt.first],res[v]+nxt.second)){
         pq.push({res[nxt.first],nxt.first});
      }
   }
   bool f=0;
   for(auto p:done)if(res[p.first]!=p.second){f=1; break;}
   rep(i,0,n)for(int nxt:g[i])if(abs(res[i]-res[nxt])!=1){f=1; break;}
   if(f){puts("No"); return 0;}
   puts("Yes");
   rep(i,0,n)printf("%d\n",res[i]);
   return 0;
}

Measured memory_bytes: 21992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;

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

  string s;
  cin >> s;

  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i+1]) {
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
    if (i < s.size() - 2 && s[i] == s[i+2]) {
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }

  cout << "-1 -1" << endl;

  return 0;
}


Measured memory_bytes: 512
if __name__ == '__main__':
    a = []
    a.extend(list(map(int, input().split(" "))))
    a.extend(list(map(int, input().split(" "))))
    a.extend(list(map(int, input().split(" "))))
    n = int(input())
    # b = []
    for i in range(n):
        b = int(input())
        for j in range(len(a)):
            if a[j] == b:
                a[j] = 0
                break
        # b.append(int(input()))

    # print(a)
    # print(b)

    if a[0] == 0 and a[1] == 0 and a[2] == 0:
        print("Yes")
    elif a[3] == 0 and a[4] == 0 and a[5] == 0:
        print("Yes")
    elif a[6] == 0 and a[7] == 0 and a[8] == 0:
        print("Yes")
    elif a[0] == 0 and a[3] == 0 and a[6] == 0:
        print("Yes")
    elif a[1] == 0 and a[4] == 0 and a[7] == 0:
        print("Yes")
    elif a[2] == 0 and a[5] == 0 and a[8] == 0:
        print("Yes")
    elif a[0] == 0 and a[4] == 0 and a[8] == 0:
        print("Yes")
    elif a[2] == 0 and a[4] == 0 and a[6] == 0:
        print("Yes")
    else:
        print("No")

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

int main(){
	long long int n,c;
	cin>>n>>c;
	vector<pair<long long int,long long int>> sushi(n);
	for (int i = 0; i < n; i++) {
		cin>>sushi[i].first>>sushi[i].second;
	}
	long long int ans=0;
	//walk_r[i]:時計回りにi個寿司を食べた時の歩行距離
	vector<long long int> walk_r(n+1,0),walk_l(n+1,0);
	//eatcal_r[i]:時計回りにi個食べた時の摂取カロリー
	vector<long long int> eatcal_r(n+1,0),eatcal_l(n+1,0);
	//max_r[i]:時計回りに0~i個食べた時で、カロリー収支が最大のもの
	vector<long long int> max_r(n+1),max_l(n+1);
	//時計回りに回る時の最大値
	for (int i = 0; i < n; i++) {
		eatcal_r[i+1]=eatcal_r[i]+sushi[i].second;
		max_r[i+1]=max(max_r[i],eatcal_r[i+1]-sushi[i].first);
		ans=max(ans,max_r[i+1]);
	}
	//反時計回りに回る時の最大値
	for (int i = 0; i < n; i++) {
		eatcal_l[i+1]=eatcal_l[i]+sushi[n-1-i].second;
		max_l[i+1]=max(max_l[i],eatcal_l[i+1]-(c-sushi[n-1-i].first));
		ans=max(ans,max_l[i+1]);
	}
	//時計回りにi個食べて折り返す時の最大値
	for (int i = 1; i < n; i++) {
		ans=max(ans,eatcal_r[i]-sushi[i-1].first*2+max_l[n-i]);
	}
	//反時計回りにi個食べて折り返す時の最大値
	for (int i = 1; i < n; i++) {
		ans=max(ans,eatcal_l[i]-(c-sushi[n-i].first)*2+max_r[n-i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
typedef long long ll;
int main()
{
   string s;
   cin >> s;
   int n = s.length();
   string tmp = s;
   reverse(all(tmp));
   string a = s.substr(0,(n-1)/2);
   string b = s.substr((n+1)/2, n/2 + 1) ;

 //  cout << a << " " << b << endl;
   string ra = a;
   reverse(a.begin(), a.end());
   string rb = b ;
   reverse(all(b)) ;
   if(tmp == s && a == ra && b==rb)
      cout << "Yes";
   else
      cout << "No" ;
   return 0;


}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int q = sc.nextInt();
			if (n == 0 && q == 0)
				break;
			int[] begin = new int[n];
			int[] end = new int[n];
			String[] era = new String[n];
			for (int i = 0; i < n; i++) {
				era[i] = sc.next();
				int y = sc.nextInt();
				end[i] = sc.nextInt();
				begin[i] = end[i] - y + 1;
			}
			for (int i = 0; i < q; i++) {
				int y = sc.nextInt();
				for (int j = 0; j < n; j++) {
					if (y >= begin[j] && y <= end[j]) {
						System.out.println(era[j] + " " + (y - begin[j] + 1));
						break;
					} else if (j == n - 1)
						System.out.println("Unknown");
				}
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 61576
package main

import "fmt"

func main() {
	var a, b, c int
	var k int
	fmt.Scan(&a, &b, &c)
	fmt.Scan(&k)
	for i := 0; i <= k; i++ {
		x := b
		y := c
		for j := 0; j < i; j++ {
			x *= 2
		}
		for j := 0; j < k-i; j++ {
			y *= 2
		}
		if x > a && y > x {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 1768
#include<bits/stdc++.h>
#define N 10010
#define mo 1000010009
using namespace std;
int n,k,s[N],sm[N],pw[N];
bool eq(int l,int r,int L,int R){
	return 1ll*(sm[R]-sm[L]+mo)*pw[l]%mo==1ll*(sm[r]-sm[l]+mo)*pw[L]%mo;
}
int main(){
	scanf("%d %d\n",&n,&k);
	for(int i=1;i<=n;++i)s[n+n+1-i]=s[i]=getchar()-96;
	pw[0]=1;for(int i=1;i<=n+n;++i)pw[i]=31ll*pw[i-1]%mo;
	for(int i=1;i<=n+n;++i)sm[i]=(sm[i-1]+1ll*pw[i]*s[i])%mo;
	int ps=n;
	for(int i=n+1;i<=n+n;++i){
		int l=0;
		for(int j=12;j+1;--j)if(l+(1<<j)<=n)
			if(eq(ps-l-(1<<j),ps,i-l-(1<<j),i))l+=1<<j;
		if(l<n&&s[i-l]<s[ps-l])ps=i;
	}
	--k;
	while(k--){
		for(int i=1;i<=n;++i)s[i]=s[ps-n+i];
		for(int i=1;i<=n;++i)s[n+n+1-i]=s[i];
		int Q=1;
		for(int i=1;i<n;++i)if(s[i]^s[i+1])Q=0;
		if(Q)break;
		ps=n;while(s[ps+1]==s[ps])++ps;
	}ps=n+1;
	for(int i=1;i<=n+n;++i)sm[i]=(sm[i-1]+1ll*pw[i]*s[i])%mo;
	for(int i=1;i<=n;++i){
		int l=0;
		for(int j=12;j+1;--j)if(l+(1<<j)<=n)
			if(eq(ps+l+(1<<j)-1,ps-1,i+l+(1<<j)-1,i-1))l+=1<<j;
		if(l<n&&s[i+l]<s[ps+l])ps=i;
	}
	for(int i=1;i<=n;++i)putchar(s[ps+i-1]+96);
}

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

int main(){
//srandom((unsigned long)time(NULL));

//  a1+b1  a1+b2 a1+b3
//  a2+b1  a2+b2 a2+b3
//  a3+b1  a3*b2 a3+b3
//a2-a1とかわかる b2-b1も
//これが中央の b2+a2-(b1+b1)と一致するか判断
bool takaRight=true;
int c[3][3];
for(int i=0;i<3;i++){
  for(int j=0;j<3;j++){
    cin>>c[i][j];
  }
}
//c22-c11とc12+c21-2*c11
//つまりc22とc12+c21-c11
for(int i=0;i<2;i++){
  for(int j=0;j<2;j++){
    if(c[i+1][j+1]!=c[i+1][j]+c[i][j+1]-c[i][j]) takaRight=false;
  }
}

if(takaRight) cout<<"Yes"<<endl;
else cout<<"No"<<endl;

return 0;
}



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

int main (void){

	int input[5]={0};
	int x_result=0;
	int y_result=0;
	int i=0;

	for ( i=0; i < 5; i++){
		scanf("%d", &input[i]);
	}
	
	x_result = input[0] * input[4];

	y_result += input[1];

	if ( input[2] < input[4]){
		input[4] -= input[2];
		y_result += input[3] * input[4];
	}

	if( x_result > y_result){
		printf("%d\n",y_result);
	}
	else {
		printf("%d\n",x_result);
		
	}


	return 0;
}

Measured memory_bytes: 596
#include"bits/stdc++.h"
using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n;
	cin >> n;
	int res;
	for (int i = 1; i <= n; i++) {
		if (i*(i + 1) / 2 >= n) {
			res = i;
			break;
		}
	}
	vector<int> ans;
	for (int r = res; r >= 1; r--) {
		if (n >= r) {
			n -= r;
			ans.push_back(r);
		}
	}
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int mod=1e9+7;

int po(int x,int y,int m){
	if (y==0)
		return 1;
	int t=po(x,y/2,m)%m;
	t=(t*t)%m;
	if (y&1)
		return (t*x)%m;
	return t%m;
}

int lb(int a[],int n,int x){
    int l=-1;  //a[l]<x
    int r=n;   //a[r]>=x
    while(r>l+1){
    	int m=l+(r-l)/2;
    	if (a[m]<x)
    		l=m;
    	else
    		r=m;
    }
    return r;
}

int ub(int a[],int n,int x){
    int l=-1;  //a[l]<=x
    int r=n;   //a[r]>x
    while(r>l+1){
    	int m=l+(r-l)/2;
    	if (a[m]>x)
    		r=m;
    	else
    		l=m;
    }
    return l;
}

signed main() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	
   	string s;
   	cin>>s;
   	int ans=0;
   	for (int i=0;i<s.size();++i)
   		ans+=(s[i]-'0');
   	if (ans%3==0)
   		cout<<"Yes"<<endl;
   	else
   		cout<<"No"<<endl;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define endl "\n"
#define unll unsigned long long
#define ll long long
#define INF 1<<31-1
#define mmax(x,y) ((x)<(y)?(x):(y))
#define mmin(x,y) ((x)<(y)?(y):(x))
#define pb push_back
#define ffor(i,a,n) for(ll i = (ll)a; i<(ll)n; i++)
#define iscanf(k) scanf("%d", &k)
#define fscanf(k) scanf("%f", &k)
#define llscanf(k) scanf("%ll", &k)
#define pi pair<int, int>;
#define pii pair<pi, pi>;
using namespace std;


int main() {

    string str;
    cin >> str;

    ffor(i,0,str.size()-1){
        if(str[i] == str[i+1]){
                cout << "Bad\n";
        return 0;
        }
    }
    cout << "Good\n";

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

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

  ll n; cin >> n;
  bitset<60> bs(n);
  vector<vector<ll>> dp(61, vector<ll>(3, 0));
  dp[60][0] = 1;
  for(int i=59; i>=0; i--) {
    if (bs[i]) {
      dp[i][0] = dp[i+1][0];
      dp[i][1] = dp[i+1][0] + dp[i+1][1];
      dp[i][2] = 2*dp[i+1][1] + 3*dp[i+1][2];
    } else {
      dp[i][0] = dp[i+1][0] + dp[i+1][1];
      dp[i][1] = dp[i+1][1];
      dp[i][2] = dp[i+1][1] + 3*dp[i+1][2];
    }
    dp[i][0] %= mod;
    dp[i][1] %= mod;
    dp[i][2] %= mod;
  }
  cout << (dp[0][0] + dp[0][1] + dp[0][2])%mod << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

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

	rep(i, 0, size(n))
	{
		if (n[i] == '1')
			n[i] = '9';
		else if (n[i] == '9')
			n[i] = '1';
	}

	cout << n;
	return 0;
}


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

int main() {
    string a,b;
    int N,t;
    cin >> a >> b;

    a += b;
    N = atoi(a.c_str());

    t = sqrt(N);
    if(t*t == N)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
using namespace std;
 
int main(){
  int N;
  int sensor = 0;
  cin >> N;
  vector<int> A(N);
  int kane = 0;
  for (int i = 0; i < N; i++){
      cin >> A.at(i);
  }
  double L, L1 = 0.0;
  for (int j = 0; j < N; j++){
    L += A.at(j);
  }
  int M;
  double X, Y;
  for(int k = 0; k < N; k++){
    L1 += (double)A.at(k);
    if(L1 == L / 2.0){
      M = k;
      goto END;
    }
    if(L1 > L / 2.0){
      M = k;
      Y = L1 - L / 2.0;
      X = A.at(M) - Y;
      break;
    }    
  }
  kane = (int)min( 2 * X, 2 * Y);
  END :
  cout << kane << endl;
}

Measured memory_bytes: 1024
X = list(map(int, input().split()))
Y = sorted(X)
ans = 0
if Y[0]%2==Y[1]%2 and Y[1]%2 != Y[2]%2:
  ans +=1
  Y = [Y[0]+1,Y[1]+1,Y[2]]
elif Y[1]%2==Y[2]%2 and Y[2]%2 != Y[0]%2:
  ans +=1
  Y = [Y[0], Y[1]+1,Y[2]+1]
elif Y[2]%2==Y[0]%2 and Y[0]%2 != Y[1]%2:
  ans +=1
  Y = [Y[0]+1, Y[1], Y[2]+1]

A = Y[2]-Y[0]
B = Y[2]-Y[1]
C = min(A,B)
D = max(A,B)
ans += C + (D-C)//2
print(ans)

Measured memory_bytes: 9148
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;

int main(void) {
    ll n;
    cin >> n;
    vpll cand;
    for (int i = 1; i <= ll(sqrt(n)) + 1; ++i) {
        if (n % i == 0) cand.emplace_back(i, n / i);
    }
    ll prev = maxLL;
    ll dist = 0;
    for (auto kv: cand) {
        dist = min(prev, kv.first + kv.second - 2);
        prev = dist;
    }
    cout << dist << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;


// 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; }
// ll pow(ll a, ll b) { ll ans = 1; while (b > 0) { if (b % 2 == 1) { ans *= a; ans %= MOD; }b /= 2; a *= a; a %= MOD; }return ans; }
// ll comb(ll n, ll r) { if (n - r < r) { return comb(n, n - r); }static VVL memo = {{1}}; if (memo.size() < n + 1) { memo.reserve(n + 1); FOR(i, memo.size(), n + 1) { memo.emplace_back(i + 1, 0); REP(j, i + 1) { memo[i][j] = 0;	if (j < i) { memo[i][j] += memo[i - 1][j]; }if (j > 0) { memo[i][j] += memo[i - 1][j - 1]; }memo[i][j] %= MOD; } } }return memo[n][r]; }
// ll comb_L(ll a, ll b) { if (a - b < b) { return comb(a, a - b); }static unordered_map<ll, ll> memo; ll c = 1; FOR(i, a - b + 1, a + 1) { c *= i; c %= MOD; }if (memo.find(b) == memo.end()) { ll k = 1; FOR(i, 2, b + 1) { k *= i;	k %= MOD; }memo[b] = pow(k, MOD - 2); }	c *= memo[b]; return c % MOD; }
multiset<ll> prime_decomposition(ll n) { ll i = 2; multiset<ll> table{}; while (i * i <= n) { while (n % i == 0) { n /= i;	table.emplace(i); }++i; }if (n > 1) { table.emplace(n); return table; }return table; }
//-- bit -- REP(i, (1 << n)) {REP(j, n) {cout << (1 & (i >> j));}cout << endl;}

//==============================================================================================

int main() {
	ll n, m;
	cin >> n >> m;

	auto l = prime_decomposition(m);
	map<ll, ll> mp;

	REPC(x, l) {
		mp[x]++;
	}

	ll ans = 1;
	for (auto&& x : mp) {
		while (x.second >= n) {
			ans *= x.first;
			x.second -= n;
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	for (int i = 1; i < 2 * b; i++) {
		if (a * i % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

int bubbleSort(int A[], int N)
{
   int sw = 0;
   bool flag = 1;

   int i, j;
   for(i=0; flag; i++) {
      flag = 0;
      for(j=N-1; j>=i+1; j--) {
         if(A[j]<A[j-1]) {
            swap(A[j], A[j-1]);
            flag = 1;
            sw++;
         }
      }
   }
   return sw;
}

int main()
{
   int A[100], N, sw;
   cin >> N;

   int i;
   for(i=0; i<N; i++)
      cin >> A[i];

   sw = bubbleSort(A, N);

   for(i=0; i<N; i++) {
      if (i) cout << " ";
      cout << A[i];
   }
   cout << endl;
   cout << sw << endl;

   return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x)
{
	x=0;
	static int p;p=1;
	static char c;c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-'0');c=getchar();}
	x*=p;
}
long long n,s;
long long f(long long b,long long j)
{
	if(j<b)return j;
	return f(b,j/b)+j%b;
}
int main()
{
	read(n);read(s);
	if(s==n)return printf("%lld\n",n+1),0;
	long long S=sqrt(n)+1;
	for(int i=2;i<=S;i++)
		if(f(i,n)==s)return printf("%d\n",i),0;
	long long ans=1e11+1;
	for(long long i=1;i*i<=n-s;i++)
		if((n-s)%i==0&&f((n-s)/i+1,n)==s)ans=min(ans,(n-s)/i+1);
	if(ans==1e11+1) puts("-1");
	else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N, ans,d;
  
  scanf("%d", &N);
  for(d=1;;d++){
 
    ans = 1000*d -N;
     if(0<=ans && ans< 1000){
       break;
     }
  }
  
  printf("%d", ans);
	return 0;
}

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

int GCD(long long a, long long b)
{
	if (a == b)
	{
		return a;
	}

	if (a < b)
	{
		swap(a,b);
	}

	if (a % b == 0)
	{
		return b;
	}
	else
	{
		return GCD(b,a%b);
	}
}

int main()
{
	long long A,B,C,D;
	cin >> A >> B >> C >> D;
	long long ans = 0;
	ans += B/C - (A-1)/C;
	ans += B/D - (A-1)/D; 
	long long LCM = C * D / GCD(C,D);
	ans -= B/LCM - (A-1)/LCM;
	cout << (B - A + 1) - ans << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn err() -> ! {
    println!("{}", -1);
    std::process::exit(0);
}

fn main() {
    input!(n: usize, d: [u64; n]);
    let mut ord: Vec<_> = (0..n).collect();
    ord.sort_by_key(|&i| std::cmp::Reverse(d[i]));
    let mut vid = vec![0; n];
    (0..n).for_each(|i| vid[ord[i]] = i);
    let mut d_sorted_reverse = d.clone();
    d_sorted_reverse.sort_by_key(|&x| std::cmp::Reverse(x));

    let mut g = vec![vec![]; n];
    let mut ans = vec![];
    let mut size = vec![1; n];
    for (si, &i) in ord.iter().enumerate().take(n - 1) {
        if n as u64 <= size[i] * 2 {
            err();
        }
        let di = d[i];
        let dj = di - n as u64 + 2 * size[i];
        let sj = d_sorted_reverse
            .binary_search_by_key(&std::cmp::Reverse(dj), |&x| std::cmp::Reverse(x))
            .unwrap_or_else(|_| err());
        assert!(si < sj);
        let j = ord[sj];
        size[j] += size[i];
        ans.push((i, j));
        g[j].push(i);
    }

    let root = ord[n - 1];
    fn dfs(x: usize, g: &Vec<Vec<usize>>, size: &Vec<u64>) -> u64 {
        let mut ans = 0;
        for &y in &g[x] {
            ans += dfs(y, &g, &size) + size[y];
        }
        ans
    }
    if dfs(root, &g, &size) != d[root] {
        err();
    }
    for (u, v) in ans {
        println!("{} {}", u + 1, v + 1);
    }
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

const int N = 1e5+34;
const int K = 1e3+23;

int n, k;
int x[N], y[N];
long long m[4*K][4*K];

int rect(int i, int j, int I, int J) {
	int x = i&&j?m[i-1][j-1]:0,
		y = i?m[i-1][J]:0,
		z = j?m[I][j-1]:0;
	return m[I][J]-z-y+x;
}

void solve() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++i) {
		int x, y; char c; scanf("%d%d %c", &x, &y, &c);
		if (c == 'W') x += k;
		x %= 2*k; y %= 2*k;
		++m[x][y];
		m[x+2*k][y] = m[x][y];
		m[x][y+2*k] = m[x][y];
		m[x+2*k][y+2*k] = m[x][y];
	}
	for (int i = 0; i < 4*k; ++i) {
		for (int j = 0; j < 4*k; ++j) {
			if (i) m[i][j] += m[i-1][j];
			if (j) m[i][j] += m[i][j-1];
			if (i && j) m[i][j] -= m[i-1][j-1];
		}
	}
	int ans = 0;
	for (int i = 0; i < 2*k; ++i) { // offset x
		for (int j = 0; j < 2*k; ++j) { // offset y
			ans = max(ans, rect(i, j, i+k-1, j+k-1) + rect(i+k, j+k, i+2*k-1, j+2*k-1));
		}
	}
	printf("%d", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 129280
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
ll a, b, c, i, j, k,  m, t, p, q, s;
struct node {
	ll x, y;
};
node arr[2505];
string s1,s2,s3;
double n;
int main() {
	cin >> n;
	n = n / 3;
	printf("%.6lf", n * n * n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int S[13], H[13], C[13], D[13];

int main() {

    // 1. input.
    int n;
    cin >> n;
    
    // 2. input check.
    for(int i = 0; i < n; i++){
        char c;
        int n;
        cin >> c >> n;
        // Spade.
        if(c == 'S') S[n - 1] = 1;
        // Heart.
        if(c == 'H') H[n - 1] = 1;
        // Club.
        if(c == 'C') C[n - 1] = 1;
        // Diamond.
        if(c == 'D') D[n - 1] = 1;
    }
    
    // 3. output answer.
    for(int i = 0; i < 13; i++) if(S[i] == 0) cout << "S" << " " << (i + 1) << endl;
    for(int i = 0; i < 13; i++) if(H[i] == 0) cout << "H" << " " << (i + 1) << endl;
    for(int i = 0; i < 13; i++) if(C[i] == 0) cout << "C" << " " << (i + 1) << endl;
    for(int i = 0; i < 13; i++) if(D[i] == 0) cout << "D" << " " << (i + 1) << endl;
    return 0;
    
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;


int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&a!=c)||(b==c&&b!=a)||(a==c&&a!=b)) cout<<"Yes";
	else cout<<"No";
	
	return 0;
 } 

Measured memory_bytes: 256
K = int(input())

list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(list[K-1])

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

int dp_first[10010][110];
int dp[110];

int main(){
    string s;
    cin >> s;
    int D; cin >> D;
    int N = s.size();
    const int MOD = pow(10,9)+7;
    dp_first[0][0]=1;
    for(int i=1; i<=N; i++){
        for(int j=0; j<D; j++){
            for(int k=0; k<=9; k++){
                dp_first[i][(j+k)%D] +=dp_first[i-1][j];
                dp_first[i][(j+k)%D] %=MOD;
            }
        }
    }

    int rui=0;
    for(int i=0; i<N; i++){
        int k=s.at(i)-'0';
        for(int j=0; j<k; j++){
            for(int l=0; l<D; l++){
                dp[(l+j+rui)%D] += dp_first[N-i-1][l];
                dp[(l+j+rui)%D] %= MOD;
            }
        }
        rui +=k;
    }
    if(rui%D==0) dp[0]++;
    dp[0] = (dp[0]+MOD-1)%MOD; //0を除く
/*    int num=0;
    for(int i=0; i<N; i++){
        num = num*10+ s.at(i)-'0';
        num %= D;
    }
    if(num==0) dp[0]++;
*/    cout << dp[0] << endl;
}

Measured memory_bytes: 4608
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

int main(){
  ll A,B,C,M,ans=-1;
  cin>>A>>B>>C;
  M=A+B+C;
  
  if(A%2==1 || B%2==1 || C%2==1){
    co(0);
    return 0;
  }
  
  for(int i=1; i<=100000000; ++i){
    A=(M-A)/2;
    B=(M-B)/2;
    C=(M-C)/2;
    if(A%2==1 || B%2==1 || C%2==1){
      co(i);
      return 0;
    }
  }
  
  co(-1);
  return 0;
}

Measured memory_bytes: 256
import bisect
h,w=map(int,input().split())
g = [['#']*(w+2) for i in range(h+2)]
for i in range(h):
  g[i+1][1:-1] = list(input())
L=[[0]*(w+2) for i in range(h+2)]
R=[[0]*(w+2) for i in range(h+2)]
D=[[0]*(w+2) for i in range(h+2)]
U=[[0]*(w+2) for i in range(h+2)]
for i in range(h+2):
  for j in range(w+2):
    if g[i][j]=="#":
      L[i][j]=0
    else:
      L[i][j]=L[i][j-1]+1
for i in range(h+2):
  for j in range(w+1,-1,-1):
    if g[i][j]=="#":
      R[i][j]=0
    else:
      R[i][j]=R[i][j+1]+1
for i in range(h+2):
  for j in range(w+2):
    if g[i][j]=="#":
      D[i][j]=0
    else:
      D[i][j]=D[i-1][j]+1
for i in range(h+1,-1,-1):
  for j in range(w+2):
    if g[i][j]=="#":
      U[i][j]=0
    else:
      U[i][j]=U[i+1][j]+1
Max=0
for i in range(h+2):
  for j in range(w+2):
    a=0
    a=L[i][j]+R[i][j]+D[i][j]+U[i][j]
    if a>Max:
      Max=a
print(Max-3)

Measured memory_bytes: 310664
n = int(input())
li = []
for i in range(n):
    a = list(map(int,input().split()))
    li.append(a)

li.sort(key = lambda x:x[0])
li2 = []

for i in range(n):
    for j in range(i):
        a = [li[i][0]-li[j][0],li[i][1]-li[j][1]]
        li2.append(a)

for i in li2:
    if i[0] < 0:
        i[0] = -i[0]
        i[1] = -i[1]
    if i[0] == 0 and i[1] < 0:
        i[1] = -i[1]

ans = 0

for i in li2:
    ans = max(ans,li2.count(i))

print(n-ans)


Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

vector<lint> bitall(lint num,lint base,lint keta){
    vector<lint> res;
    while(num>0){
        res.push_back(num%base);
        num/=base;
    }
    while(res.size()<keta) res.push_back(0);
    reverse(res.begin(),res.end());
    return res;
}

int main(void){
    lint N,a,b,c;
    cin >> N >> a >> b >> c;
    lint L[N];
    rep(i,N) cin >> L[i];
    lint rem=N-3;
    lint all=pow(4,rem);
    lint ans=LINF;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) for(int k=j+1;k<N;k++){
        vector<lint> A,B;
        rep(l,N){
            if(l==i || l==j || l==k) A.push_back(L[l]);
            else B.push_back(L[l]);
        }
        rep(l,all){
            lint base[3];
            base[0]=A[0],base[1]=A[1],base[2]=A[2];
            vector<lint> now=bitall(l,4,N-3);
            lint add=0;
            rep(m,N-3){
                if(now[m]==1) base[0]+=B[m],add+=10;
                else if(now[m]==2) base[1]+=B[m],add+=10;
                else if(now[m]==3) base[2]+=B[m],add+=10;
            }
            sort(base,base+3,greater<lint>());
            ans=min(ans,abs(base[0]-a)+abs(base[1]-b)+abs(base[2]-c)+add);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512