akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
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 n;
  cin >> n;
  vector<ll> s(n-1), c(n-1), f(n-1);
  for(ll i = 0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];

  vector<ll> ans(n-1);
  for(ll i = 0; i < n-1; i++){
    for(ll j = i; j < n-1; j++){
      if(ans[i] < s[j]) ans[i] = s[j];
      ans[i] = (ans[i] + f[j] - 1) / f[j] * f[j] + c[j];
    }
  }

  for(ll i = 0; i < n-1; i++){
    cout << ans[i] << endl;
  }
  cout << 0 << endl;
  return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A+B==3){
    cout << 3 << endl;
  }
  else if(A+B==4){
    cout << 2 << endl;
  }
  else if(A+B==5){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;
	
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 0)
			continue;
		if (i % 5 == 0)
			continue;
		ans += i;

	}
	cout << ans << endl;


	return 0;
}

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

int main() {
	int n;
	cin >> n;
	string ans;
	for (int i = 0; n != 0; i++) {
		if (n % 2 == 0)
			ans += '0';
		else {
			ans += '1';
			n--;
		}
		n /= -2;
	}
	reverse(ans.begin(), ans.end());
	if (ans.empty())
    	ans = "0";
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string S;
    cin>>S;

    int N=S.size();
    int ans=0;
    int cou=0;
    rep(i,N){
        if(S[i]=='B')cou++;
        else ans+=cou;
    }
    cout<<ans<<endl;
    



}


Measured memory_bytes: 3792
from collections import defaultdict, deque

N, u, v  = map(int, input().split())
way = defaultdict(list)
for _ in range(N-1):
    a, b =  map(int, input().split())
    
    way[a].append(b)
    way[b].append(a)
seen1 = [-1]*N
seen2 = [-1]*N
seen1[u-1] = 0
seen2[v-1]= 0

queue = deque([u])
while queue:
    q = queue.popleft()
    for i in way[q]:
        if seen1[i-1]==-1:
            queue.append(i)
            seen1[i-1] = seen1[q-1]+1

queue = deque([v])
while queue:
    q = queue.popleft()
    for i in way[q]:
        if seen2[i-1]==-1:
            queue.append(i)
            seen2[i-1] = seen2[q-1]+1
            
#print(way)
#print(seen1)
#print(seen2)
for i in range(N):
    if seen1[i]>=seen2[i]:
        seen2[i] = -1
print(max(seen2)-1)

Measured memory_bytes: 98536
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve():
    a, b = map(int, input().split())
    if a == b or a % b == 0:
        print(0, 1)
    elif b % a == 0:
        print(1, 0)
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        coe = [[1, 0], [0, 1]]
        while b != 1:
            quo = a // b
            coe_d1 = coe[1]
            coe_d2 = [coe[0][0] - coe[1][0] * quo, coe[0][1] - coe[1][1] * quo]
            coe = [coe_d1, coe_d2]
            a, b = b, a % b
        print(*coe[1])

solve()

Measured memory_bytes: 7824
#define _GLIBCXX_DEBUG
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <random>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <bitset>
#include <sstream>

using namespace std;

#define REP(i, x) for (int i = 0; i < (x); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define MOD 1'000'000'007
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(int argc, const char *argv[])
{
    ll a;
    cin >> a;

    queue<ll> q;
    REP(i, 9)
    {
        q.push(i + 1);
    }

    ll b;
    REP(i, a)
    {
        b = q.front();
        q.pop();
        if (b % 10 == 0)
        {
            q.push(10 * b);
            q.push(10 * b + 1);
        }
        else if (b % 10 == 9)
        {
            q.push(10 * b + 8);
            q.push(10 * b + 9);
        }
        else
        {
            q.push(10 * b + b % 10 - 1);
            q.push(10 * b + b % 10);
            q.push(10 * b + b % 10 + 1);
        }
    }
    cout << b << endl;

    return 0;
}


Measured memory_bytes: 1792
n, m = gets.split.map(&:to_i)
lr = []
m.times do
  lr.push gets.split.map(&:to_i)
end

min = 0
max = 1000000

lr.each do |e|
  l = e.first
  r = e.last
  min = l if min < l
  max = r if max > r
end
puts [max - min + 1, 0].max


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

#define MAX_C_NUM 1000
#define MAX_K_NUM 3000

long long a[MAX_C_NUM], b[MAX_C_NUM], c[MAX_C_NUM];
long long ab[MAX_C_NUM * MAX_C_NUM];
long long abc[MAX_K_NUM * MAX_C_NUM];

int main() {
  int X, Y, Z, K;
  
  cin >> X >> Y >> Z >> K;
 
  for(int i=0; i<X; i++)
    cin >> a[i];
  for(int i=0; i<Y; i++)
    cin >> b[i];
  for(int i=0; i<Z; i++)
    cin >> c[i];
 
  //解法その１
  //まず，aとbの全組み合わせをソート
 
  for(int i=0; i<X; i++) {
    for(int j=0; j<Y; j++) {
      ab[i*Y + j] = a[i] + b[j];
    }
  }
  
  sort(ab, ab + X * Y, greater<long long>());

  //abのk個と，cのZ個の組をソート
  for(int i=0; i<min(X*Y, K); i++) {
    for(int j=0; j<Z; j++) {
      abc[i*Z + j] = ab[i] + c[j];
    }
  }

  sort(abc, abc + min(X*Y, K) * Z, greater<long long>());

  for(int i=0; i<min(X*Y*Z, K); i++) {
    cout << abc[i] << endl;
  }

  return 0;
}


  
  
  
	

Measured memory_bytes: 31488
n, m = (int(i) for i in input().split())
h = [0]
h.extend([int(i) for i in input().split()])
adj = []
for i in range(n+1):
	adj.append([])
for i in range(m):
	a,b = (int(i) for i in input().split())
	adj[a].append(b)
	adj[b].append(a)
	
ans = 0

for i in range(1, n+1):
	if len(adj[i])==0 or h[i] > max([h[y] for y in adj[i]]):
		ans+=1
print(ans)


Measured memory_bytes: 29912
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s, n = 1;
  cin >> s;
  while(s > 4)
  {
    if (s%2==0) s = s/2;
    else s = 3*s+1;
    n += 1;
  }
  if (s == 4) cout << n+3 << endl;
  else if (s == 3) cout << n+8 << endl;
  else if (s == 2) cout << n+3 << endl;
  else if (s == 1) cout << n+3 << endl;
  else if (s == 0) cout << n+1 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		var b=sc.Ia;
		var dp=new long[n+1];
		for(int i = 0;i<=n;i++) {
			for(int j = 0;j<3;j++) {
				if(a[j]<=i&&a[j]<b[j]){dp[i]=Max(dp[i],dp[i-a[j]]+b[j]-a[j]);}
			}
		}
		n+=(int)dp[n];
		dp=new long[n+1];
		for(int i = 0;i<=n;i++) {
			for(int j = 0;j<3;j++) {
				if(b[j]<=i&&b[j]<a[j]){dp[i]=Max(dp[i],dp[i-b[j]]+a[j]-b[j]);}
			}
		}
		Console.WriteLine("{0}",dp[n]+n);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2(int b){return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}
	public int[] Ia3(int a,int b){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(int a,int b,int c,int d){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()+(c!=0?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2(int b){return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}
	public long[] La3(int a,int b){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(int a,int b,int c,int d){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()+(c!=0?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 206304
x,y = map(int, input().split())

if y % 2 != 0:
    print("No")
elif y > 4 * x:
    print("No")
else:
  t_4 = 0
  c_2 = x

  while True:
      if c_2 < 0:
          print("No")
          break
      elif (4 * t_4 + 2 * c_2) == y:
          print("Yes")
          break

      t_4 += 1
      c_2 -= 1

Measured memory_bytes: 61828
/**
 *		author:  zvm
 *		created: 28.09.2020 16:54:32
**/

#include <bits/stdc++.h>

using namespace std ;

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

	int a, b, c, d ;
	cin >> a >> b >> c >> d ;
	cout << ( a+b < c+d ? "Right" : ( a+b > c+d ? "Left" : "Balanced" ) ) << endl ;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	string s; cin>>s;
	char now='-';int am=0,ans=0;
	for(auto x:s){
		if(x!=now) am=1,now=x;
		else am++;
		if(now=='R') ans=max(ans,am);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_134
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = new int[n];
            int[] sorted = new int[n];
            for(int i = 0; i < n; i++)
            {
                array[i] = ReadInt();
                sorted[i] = array[i];
            }
            Array.Sort(sorted);
            int max = sorted[n - 1];
            int max2 = sorted[n - 2];
            for(int i = 0; i < n; i++)
            {
                if (array[i] == max)
                {
                    WriteLine(max2);
                }
                else
                {
                    WriteLine(max);
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 18004
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    a, b = map(int, input().split())
    if a > b:
        print('a > b')
    elif a < b:
        print('a < b')
    else:
        print('a == b')


if __name__ == '__main__':
    main()

Measured memory_bytes: 7748
#define debug 0
#define test 0
#define CPLUS 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#if CPLUS
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <vector>
#include <iterator>
#include <unordered_map>
using namespace std;
#endif

long long fun(int n, int a, int b)
{
	if (n == 1) {
		if (a == b)
			return 1;
		return 0;
	}
	if (a > b)
		return 0;
	else {
		long long mi = (long long)(n - 1)*a + b;
		long long ma = (long long)(n - 1)*b + a;
		return ma - mi + 1;
	}
	//if (n < 1 || a < 1 || b<1 || a>b)
	//	return 0;
	//if (n == 1) {
	//	if (a == b)
	//		return 1;
	//	else
	//		return 0;
	//}
	//if (n == 2)
	//	return 1;
	//long long mi = (n - 1)*a + b;
	//long long ma = (n - 1)*b + a;
	//return ma - mi + 1;
}

int main(void)
{
#if debug
	freopen("in.txt", "r", stdin);
#endif
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	printf("%lld\n", fun(n, a, b));
	return 0;
}

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

#define boost ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)


using namespace std;
using LL = long long;

constexpr int MAXN = 2e5 + 5;

template <typename T>
inline void read(T &x) {
    int f = 1;
    x = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}
LL a, b, n;

int main() {
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    boost;
    cin >> a >> b >> n;
    LL x = min(n, b - 1);
    cout << a * x / b - a * (x / b) << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  int i = a * b;
  
  if (i % 2 == 0) {
    cout << "Even" << endl;
  }
  
  else {
    cout << "Odd" << endl;
  }
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
int main() {
	ll n,m;

	cin>>n>>m;
	if(abs(n-m)>1){
		cout<<0<<endl;
		return 0;
	}
	ll k=1;
	for(ll i=1;i<n+1;++i){
		k*=i;
		k%=1000000007;
	}
	ll h=1;
	for(ll i=1;i<m+1;++i){
		h*=i;
		h%=1000000007;
	}
	if(n==m)k*=2;
	cout<<(k*h)%1000000007<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,m;
    cin >> n >>m;
    vector<int> L(m);
    vector<int> R(m);
    for(int i=0;i<m;i++){
        cin >> L[i] >>R[i];
    }
    int min = 1;
    int max = n;
    for(int i=0;i<m;i++){
        if(L[i]>min){
            min = L[i];
        }
        if(R[i]<max){
            max = R[i];
        }
    }
    if(max-min+1>0){
    cout << max-min+1 <<endl;
    }
    else{
        cout <<0<<endl;
    }

}

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

int main(){
  int a, b, tmp;

  while(true){
    cin >> a >> b;
    if(a == 0 && b ==0)break;
    else{
      if(a>b){
        tmp = a;
        a = b;
        b = tmp;
      }
      cout << a << " " << b << "\n";
    }
  }

  return 0;
}


Measured memory_bytes: 3104
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long n = in.nextLong();
            long k = in.nextLong();
            out.println(k * (long) Math.pow(k - 1, n - 1));
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
//#include <cstdio>
//#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
//#include <set>
#include <queue>
//#include <limits>
#include <sstream>
//#include <functional>
using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define mfill(a, v) fill(a, a + len(a), v)
#define mfill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v, t) sort(v.begin(), v.end(), greater<t>())
#define asort(a) sort(a, a + len(a))
#define rasort(a, t) sort(a, a + len(a), greater<t>())
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
const int weight[] = {0,1,10,100,1000,10000,100000,1000000,10000000};

string remChar(string s, char c){
  s.erase(remove(s.begin(), s.end(), c), s.end());
  return s;
}
int s2i(string Text){
  int Number;
  if ( ! (istringstream(Text) >> Number) ) Number = 0;
  return Number;
}
string replace (string str, const string& from, const string& to) {
  string::size_type pos = 0;
  while(pos = str.find(from, pos), pos != string::npos) {
	str.replace(pos, from.length(), to);
	pos += to.length();
  }
  return str;
}
int exchange(int base, int a, int b){
  int ret = base;
  int na = (base % weight[a+1]) / weight[a];
  int nb = (base % weight[b+1]) / weight[b];
  ret -= na*weight[a] + nb*weight[b];
  ret += na*weight[b] + nb*weight[a];
  return ret;
}
typedef struct P2{
  int num, depth, pos;
} p2;

void doIt(){
  string s;
  map<int, int> m;
  queue<p2> q;
  p2 p;
  int trades[8][3] = {{2, 5, -1},
					  {1, 3, 6},
					  {2, 4, 7},
					  {3, 8, -1},
					  {1, 6, -1},
					  {2, 5, 7},
					  {3, 6, 8},
					  {4, 7, -1}
  };
  p.num = 81234567;
  p.depth = 0;
  p.pos = 8;
  q.push(p);
  m[81234567] = 0;
  while(!q.empty()){
	p2 t = q.front();
	q.pop();
	rep(i, 0, 3){
	  if(trades[t.pos-1][i] != -1){
		int tmp = exchange(t.num, t.pos, trades[t.pos-1][i]);
		if(m.count(tmp) == 0){
		  p2 t1;
		  m[tmp] = t.depth + 1;
		  t1.num = tmp;
		  t1.depth = t.depth + 1;
		  t1.pos = trades[t.pos-1][i];
		  q.push(t1);
		}
	  }
	}
  }
  while(getline(cin, s)){
	int t = s2i(replace(remChar(s, ' '), "0", "8"));
	cout << m[t] << endl;
  }
}

int main() {
  doIt();
  //cout << exchange(12345678, 8, 7) << endl;
  return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int n, k, ans = 0;
  vi a;
  cin >> n >> k;
  REP(i, n) { a.PB(read()); }
  for (int l = 0; l <= k; l++) {
    for (int r = 0; r <= k - l; r++) {
      if (l + r > n) continue;
      int d = k - l - r;
      int now = 0;
      vi s;
      REP(i, l) {
        now += a[i];
        s.PB(a[i]);
      }
      FOR(i, n - r, n) {
        now += a[i];
        s.PB(a[i]);
      }
      sort(ALL(s));
      REP(i, d) {
        if (i >= s.size()) break;
        if (s[i] > 0) break;
        now -= s[i];
      }
      chmax(ans, now);
    }
  }
  print(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

    vector<int> vE(n+1,0),vW(n+1,0);
    REP(i,n+1){
        if(i==0){
            vE[i]=0; 
            vW[n-i]=0;
        }
        else{
            vE[i]=vE[i-1]+((s[i-1]=='W')? 1:0);
            vW[n-i]=vW[n-i+1]+((s[n-i+1]=='E')? 1:0);
        }
    }

    int minv=INF;
    REP(i,n+1){
        minv=min(minv,vE[i]+vW[i]);
    }

    cout<<minv<<endl;

	return 0; 
}

Measured memory_bytes: 3076
N=int(input())
B_list=[int(thing) for thing in input().split(" ")]
a_sum=0
for i in range(N):
    if i==0:
        a_sum=a_sum+B_list[0]
    else:
        if i==N-1:
            a_sum=a_sum+B_list[N-2]
        else:
            a_sum=a_sum+min(B_list[i],B_list[i-1])
print(a_sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

// 4方向（左、右、上、下）（左上を0, 0とした場合）
vector<long long> dx = {-1, 1, 0, 0};
vector<long long> dy = { 0, 0,-1, 1};
map<char, long long> DirectionToInt = {{'L', 0}, {'R', 1}, {'U', 2},{'D', 3}};

int main(){
    Init();
    ll h, w, n, sr, sc;
    cin >> h >> w >> n >> sr >> sc;
    sr--, sc--;
    string s, t;
    cin >> s >> t;

    // // 高橋くんと青木くんはiステップ目には、si, tiの方向に移動させるか何もしないか選択する。
    // // 高橋くんはマス外に移動させたら勝ち、青木くんはnステップまでマス内に残したら勝ち
    // // 高橋くんだけが動かせる場合、そもそも達成可能かどうかをチェック
    // map<ll, ll> cnt;
    // rep(i, n) cnt[DirectionToInt[s[i]]]++;
    // vector<bool> twin(4, false);
    // if(sc - cnt[0] <  0) twin[0] = true;
    // if(sc + cnt[1] >= w) twin[1] = true;
    // if(sr - cnt[2] <  0) twin[2] = true;
    // if(sr + cnt[3] >= h) twin[3] = true;

    // // 青木くんは一切動かさなくても高橋くんが勝てない場合
    // if(!twin[0] && !twin[1] && !twin[2] && !twin[3]){
    //     YES();
    //     return 0;
    // }

    // iステップ目に青木くんがいて大丈夫な範囲を求める
    // LR
    ll l = 0, r = w;
    for(ll i=n-1; i>=0; i--){
        // 青木くんの移動
        if(t[i] == 'R' && l > 0) l--;
        else if(t[i] == 'L' && r < w) r++;

        // 高橋くんの移動
        if(s[i] == 'R') r--;
        else if(s[i] == 'L') l++;

        if(l >= r){
            NO();
            return 0;
        }
    }

    // UD
    ll u = 0, d = h;
    for(ll i=n-1; i>=0; i--){
        // 青木くんの移動
        if(t[i] == 'D' && u > 0) u--;
        else if(t[i] == 'U' && d < h) d++;

        // 高橋くんの移動
        if(s[i] == 'D') d--;
        else if(s[i] == 'U') u++;

        if(u >= d){
            NO();
            return 0;
        }
    }

    (sc < l || sc >= r || sr < u || sr >= d) ? NO() : YES();
}

Measured memory_bytes: 4040
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  bs <- map read . words <$> getLine :: IO [Int]
  print $ solve n bs

solve n bs = a0 + mid + aLast
  where
    a0 = head bs
    aLast = last bs
    mid = sum $ zipWith min bs (tail bs)

Measured memory_bytes: 1020
#!/usr/bin/env python3
# coding=utf-8

import sys

import numpy as np

n, k = map(int, sys.stdin.readline().strip().split(" "))
xyc = [l.strip().split(" ") for l in sys.stdin.readlines()]
xy = [(int(_x) % (2 * k), int(_y) % (2 * k) if _c == "W" else (int(_y) + k) % (2 * k))
      for (_x, _y, _c) in xyc]

# ans = np.zeros((2 * k, 2 * k), dtype=np.int32)
ans = [[0 for j in range(2 * k + 1)] for i in range(2 * k + 1)]
for _x, _y in xy:
    if (_x - k + 0.5) * (_y - k + 0.5) > 0:
        _x %= k
        _y %= k
        ans[_x][_y] += 2
        ans[_x + k][_y] -= 2
        ans[_x][_y + k] -= 2
        ans[_x + k][_y + k] += 2
        ans[_x + k][0] += 1
        ans[0][_y + k] += 1
        ans[0][0] += 1
        ans[_x][0] -= 1
        ans[0][_y] -= 1
    else:
        _x %= k
        _y %= k
        ans[_x][_y] -= 2
        ans[_x + k][_y] += 2
        ans[_x][_y + k] += 2
        ans[_x + k][_y + k] -= 2
        ans[_x + k][0] -= 1
        ans[0][_y + k] -= 1
        ans[_x][0] += 1
        ans[0][_y] += 1
print(np.asarray(ans).cumsum(axis=1).cumsum(axis=0).max())


Measured memory_bytes: 150480
#include <bits/stdc++.h>
using namespace std;
 
// a,b,cの最大値、最小値をそれぞれminimumの参照先、maximumの参照先に代入する

int main() {
    int64_t n8,n10;
    cin >> n8 >> n10;
    int tax8 =round(n8 / 0.08);
    int tax10 =round(n10 / 0.1);
    // cout << tax8 <<":"<<tax10<<endl;
    if(tax8==tax10){
        cout<<tax8<<endl;
        return 0;
    }
    if(tax8>tax10){
        // cout << tax8 << floor( tax8 * 0.1)<<endl;
        int test10 = floor(tax8*0.1);
        if(test10==n10)
        {cout << tax8<<endl;
        return 0;}
    }
    if(tax10>tax8){
        // cout << tax8 << floor( tax8 * 0.1)<<endl;
        int test8 = floor(tax10*0.08);
        if(test8==n8)
        {cout << tax10<<endl;
            return  0;
        }
    }
    cout << -1<< endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

    int D;
    string ans = "Christmas";
    cin>>D;

    for(int i=0;i<(25-D);i++){
        ans+=" Eve";
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
private fun readIntArray(): List<Int> {
    return readLine()!!.split(" ").map{ it.toInt() }
}

private fun readInt(): Int {
    return readLine()!!.toInt()
}

fun main(args: Array<String>) {
    val N = readInt()
    val A1 = readIntArray()
    val A2 = readIntArray()

    var ans = 0
    for (i in 0 until N) {
        val a1sub = A1.subList(0, i + 1)
        val a2sub = A2.subList(i, N)
        ans = listOf(ans, a1sub.sum() + a2sub.sum()).max()!!
    }
    println(ans)
}


Measured memory_bytes: 37820
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#define LL long long
#define mp(x,y) make_pair(x,y)
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
inline void print(int x){write(x);printf(" ");}
char ch[110000];
struct edge{int x,y;}e[110000];int ln;
void ins(int x,int y){ln++;e[ln].x=x;e[ln].y=y;}
int main()
{
	scanf("%s",ch+1);int len=strlen(ch+1);
	int maxpos=len-1;
	bool tf=true;
	for(int i=1;i<maxpos;i++)if(ch[i]!=ch[len-i]){tf=false;break;}
	if(!tf||ch[1]-'0'!=1||ch[len]-'0'!=0){puts("-1");return 0;}
	int tp=2,sum=2;
	ins(1,2);
	for(int i=2;i<=len;i++)
	{
		sum++;ins(tp,sum);
		if(ch[i]-'0'!=0)tp=sum;
	}
	for(int i=1;i<len;i++)printf("%d %d\n",e[i].x,e[i].y);
	return 0;
}

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

int check(int a, int b) {
  int c = a & b;
  return c && ((c & (c - 1)) == 0);
}

int main() {
  int a[3], b[3];
  for (int i = 0; i < 3; ++i)
    cin >> a[i] >> b[i];
  int bits[3];
  for (int i = 0; i < 3; ++i)
    bits[i] = (1 << a[i]) ^ (1 << b[i]);
  int n = check(bits[0], bits[1]) + check(bits[1], bits[2]) + check(bits[2], bits[0]);
  cout << ((n == 2) ? "YES\n" : "NO\n");

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#include <vector>
using namespace std;

int main()
{
	stack<int> nums;
	stack<pair<int, int> > area;
	
	char s[20010]; scanf("%s",s);
	
	int sum = 0;
	for(int i = 0; s[i] != '\0'; ++i) {
		if(s[i] == '\\') {
			nums.push(i);
		} else if(s[i] == '/' && !nums.empty()) {
			int begin = nums.top(); nums.pop();
			int s = i-begin;
			sum += s;
			while(!area.empty() && begin < area.top().first) {
				s += area.top().second;
				area.pop(); 
			}
			area.push(make_pair(begin, s));
		}
	}
	
	vector<int> ans;
	while(!area.empty()) {
		ans.push_back(area.top().second);
		area.pop();
	}
	
	printf("%d\n%d",sum,ans.size());
	for(int i = ans.size()-1; i >= 0; --i) {
		printf(" %d",ans[i]);
	}
	putchar('\n');
	return 0;
}



Measured memory_bytes: 2804
n = int(input())
stones = input()

t = stones.count('R')

num_not_equal = t
red_num_diff = t
red_count = 0

ans = t
for s in stones:
    if s == 'R':
        num_not_equal -= 1
    else:
        num_not_equal += 1

    red_count += 1
    red_num_diff = abs(red_count - t)

    temp = red_num_diff + (num_not_equal - red_num_diff) // 2
    ans = min(ans, temp)

    # print(num_not_equal, red_num_diff)

print(ans)

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

using namespace std;

#define ll long long int

vector<int> temp;

int main(){
  int N,p,q;
  cin >> N;
  vector<int> P,Q,V;
  for(int i=0;i<N;i++){ 
    cin >> p;
    P.push_back(p);
    V.push_back(i+1);
  }
  for(int j=0;j<N;j++){
    cin >> q;
    Q.push_back(q);
  }

  int count_p=0,count_q=0;
  do {
    count_p++;
  } while (next_permutation(P.begin(), P.end()));
  do {
    count_q++;
  } while (next_permutation(Q.begin(), Q.end()));
  cout << abs(count_p-count_q) << endl;
  return 0;
}

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

int main(){
	int a, b, c;
  	cin >> a >> b >> c;
  	
  	int num = 100*a + 10*b + c;
  	if(num%4 == 0){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import collections
import bisect
s = input()
t = input()

dict_pos = collections.defaultdict(list) # dict of index 
for i, ch in enumerate(s, 1): 
    dict_pos[ch].append(i)

count_loop = 0
last_pos = -1
for ch in t:
    list_pos = dict_pos[ch]
    if len(list_pos) == 0:
        print(-1)
        quit()
    if list_pos[-1] <= last_pos:
        last_pos = list_pos[0]
        count_loop += 1
    else:
        last_pos = list_pos[bisect.bisect_right(list_pos, last_pos)]

print(count_loop * len(s) + last_pos)


Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
#define se cout << fixed << setprecision(11)

int main(){
  double a,b,x;
  cin >> a >> b >> x;
  double c=x/a;
  
  double y;
  if(c>a*b/2){
    y=(2*x/(a*a))-b;
    double d=atan((b-y)/a);
    se << d*180/PI <<endl;
  }
  else{
    y=2*x/(b*a);
    double e=atan(b/y);
    se << e*180/PI <<endl;
  }
}

    

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int r, g;
    cin >> r >> g;

    cout << 2*(g-r) + r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[200000];
ll dp[200000];
ll ans;
int n;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     //freopen("output.txt", "w", stdout);
    // #endif

    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    dp[1] = 0;
    dp[0] = 0;
    int i = 3;
    dp[2] = abs(arr[2] - arr[1]);
    while (i <= n)
    {
        dp[i] = min((abs(arr[i] - arr[i - 1]) + dp[i - 1]), abs(arr[i] - arr[i - 2]) + dp[i - 2]);
        i++;
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1792
package main

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

func main() {
	s := readString()
	t := readString()

	for i := 0; i < len(t)-1; i++ {
		if s[i] != t[i] {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}

/*-------------------utilities-------------------*/

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

// 最大公約数
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

// 最小公倍数
func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func comb(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7

	COMB_MAX = 510000
)

var (
	readString func() string
)

var (
	fac  = [COMB_MAX]int{}
	finv = [COMB_MAX]int{}
	inv  = [COMB_MAX]int{}
)

func init() {
	readString = newReadString(os.Stdin)
}

func combInit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < COMB_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
	}
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

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

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

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

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll S;
  IN(S);

  ll X1, Y1, X2, Y2;
  ll k = (ll)sqrt((double)S);
  while(k*k<S) k++;
  X1 = k;
  Y2 = k;

  ll P = X1*Y2 - S;
  ll m = (ll)sqrt(P)+1;

  if(P==0){
    X2 = 0;
    Y1 = 0;
  }else{
    while(P%m!=0) m--;
    X2 = m;
    Y1 = P/m;
  }

  OUT(0, 0, X1, Y1, X2, Y2);

  return 0;
}

Measured memory_bytes: 256
from heapq import heapify, heappush, heappop 

INF = 1001001001

N, Q = map(int, input().split())
STXs = [tuple(map(int, input().split())) for _ in range(N)]
Ds = [int(input()) for _ in range(Q)]

#S-X, T-X, X
future_block = [(S - X, T - X, X) for S, T, X in STXs]
future_block.append((INF, INF, INF)) #sentinel
heapify(future_block)

#T-X, X
current_block = [(INF, INF)] #sentinel
current_min_pair = (INF, INF)

for D in Ds:
    while future_block[0][0] <= D:
        s_x, t_x, x = heappop(future_block)
        if current_min_pair[1] > x:
            current_min_pair = (t_x, x)
        heappush(current_block, (t_x, x))
    
    search_min_flg = False
    while current_block[0][0] <= D:
        if current_min_pair == heappop(current_block):
            search_min_flg = True
    if search_min_flg:
        current_min_pair = min(current_block, key = lambda t: t[1])

    print(-1 if current_min_pair[1] == INF else current_min_pair[1])


Measured memory_bytes: 165908
#include <bits/stdc++.h>
#include <algorithm>
#include <limits>
#include <cmath> 
using namespace std;

int main(){
    int n,ans=0;
    cin>>n;
    for(int i=0;i<=sqrt(n);i++){
        int c=i*i;
        ans=max(ans,c);
    }
    cout<<ans<<endl;
}

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

int main() {
  int H, N; cin >> H >> N;
  vector<int> A(N);
  for (int &i : A) {
    cin >> i;
  }

  int sum = 0;
  for (int i : A) {
    sum += i;
  }
  if (sum >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

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

using namespace std;
using lint=long long;

int main(){
	lint n,x; cin>>n>>x;

	lint ans=x;
	lint a=x,b=n,c=n-x,d=n-x;
	while(1){
		if(a>b) swap(a,b);
		if(c>d) swap(c,d);

		if(b==1){ ans+=c+d-1; break; }
		if(d==1){ ans+=a+b-1; break; }
		if(b==d){ ans+=b; break; }

		if(b>d){ lint m=(b%d==0?b/d-1:b/d); ans+=m*d; b-=m*d; }
		else   { lint m=(d%b==0?d/b-1:d/b); ans+=m*b; d-=m*b; }
	}
	cout<<ans<<endl;

	return 0;
}


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

using namespace std;

int main(){

	ios::sync_with_stdio(false);


	int numero;
	int soma = 0, aux;

	cin >> numero;
	aux = numero;
	
	while(aux > 0){
		int d = aux % 10;
		aux /= 10;

		soma += d;
	}

	cout << (numero % soma == 0 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_140
{
    class F
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] ss = ReadInts();
            Array.Sort(ss);
            Array.Reverse(ss);
            List<int> blocks = new List<int>();
            blocks.Add(1);
            for (int i = 1; i < ss.Length; i++)
            {
                if (ss[i] == ss[i - 1])
                {
                    blocks[blocks.Count - 1]++;
                }
                else
                {
                    blocks.Add(1);
                }
            }
            if (blocks[0] > 1)
            {
                WriteLine("No");
                return;
            }
            int[] cnts = new int[n];
            for (int i = 0; i < n; i++) cnts[i] = 1;
            for (int i = 1; i < blocks.Count; i++)
            {
                int[] next = new int[n];
                int current = 0;
                for (int j = 0; j < blocks[i]; j++)
                {
                    while (cnts[current] == 0)
                    {
                        current++;
                        if (current >= n)
                        {
                            WriteLine("No");
                            return;
                        }
                    }
                    cnts[current]--;
                    for (int k = current + 1; k < n; k++) next[k]++;
                }
                for (int j = 0; j < n; j++) cnts[j] += next[j];
            }
            WriteLine("Yes");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 38824
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a,bbb=b;i<=bbb;++i)
#define repd(i,a,b) for(register int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(register int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
typedef long long ll;
typedef double db;
inline int qi(){
    int f=0,fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ql(){
	ll f=0;int fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
//start!
const int MAX_N=2e5+5;
const int mod=998244353;
struct node{ int l,r; }il[MAX_N];
int dp[MAX_N],sum[MAX_N]; 
int main()
{
	int n=qi(),ans=0;	
	repi(i,1,n-1) ans+=(n-1)/i;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

  int h,w;cin >> h >> w ;
  vector<vector<char>> red(h,vector<char>(w,'.')),
  					   blue(h,vector<char>(w,'.'));
  char s;
  rep(i,h)rep(j,w){
    cin >> s;
    if(s=='#'){
      red[i][j]=s;
      blue[i][j]=s;
      continue;
    }
    if(i+1!=h&&(i==0||j%2==1))red[i][j]='#';
    else blue[i][j]='#';
  }
  rep(i,h)rep(j,w){
    cout << red[i][j];
    if(j+1==w)cout << '\n';
  }
  cout << '\n';
  rep(i,h)rep(j,w){
    cout << blue[i][j];
    if(j+1==w)cout << '\n';
  }
}

Measured memory_bytes: 4040
N = int(input())
  
def digit_sum(N):
  ret = 0
  while N:
    ret += N%10
    N = N//10
  return ret

answer = 1e9
for i in range(1,N):
  answer = min(answer, digit_sum(i)+digit_sum(N-i))
  
print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll h, w, n, m;
  cin >> h >> w >> n >> m;
  cout << h*w - n*w - m*h + n*m << endl;
}

Measured memory_bytes: 256