akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def main():
    N = int(input())

    # print(math.floor(N * 1.08))

    for i in range(100000):
        if N == int(i * 1.08):
            print(i)
            return

    print(':(')


if __name__ == '__main__':
    main()


Measured memory_bytes: 66156
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = test2()

fun test2() = FastIO.exec {
    val k = int()
    val n = int()
    val aList = LongArray(n) { long() }

    val diff = LongArray(n)
    diff[0] = k - aList.last() + aList.first()

    for (i in 0 until n - 1) {
        diff[i + 1] = aList[i + 1] - aList[i]
    }

    val answer = diff.sum() - diff.max()!!

    println(answer)
}

// region

@Suppress("unused")
object FastIO {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    private var st = StringTokenizer("")
    val pw = PrintWriter(System.out)

    fun string(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
        return st.nextToken()
    }

    fun int() = Integer.parseInt(string())
    fun long() = java.lang.Long.parseLong(string())
    fun double() = java.lang.Double.parseDouble(string())
    fun nextLine() = br.readLine()!!
    fun println() = pw.println()
    fun <T> print(o: T) = pw.print(o)
    fun <T> println(o: T) = pw.println(o)

    inline fun exec(code: FastIO.() -> Unit) {
        code()
        pw.flush()
    }
}
// endregion


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

int main(){
int a[30];
for(int i = 0;i <= 29;i++){
a[i] = 0;
}
for(int ii = 1;ii <= 28;ii++){
int n;
cin >> n;
a[n - 1] = 1;
}
for(int p = 0;p <= 29;p++){
if(a[p] == 0){
cout << p + 1 << endl;
}
}
    return 0;
}

Measured memory_bytes: 1160
# include <bits/stdc++.h>
using namespace std;
const int maxn = 303;
int dp[maxn][maxn][maxn];
char s[maxn];
int main()
{
    int a;
    scanf("%s%d",s+1,&a);
    int len = strlen(s+1);
    for(int i=1; i<=len; ++i)
        for(int j=0; j<=a; ++j) dp[i][i][j] = 1;
    for(int j=1; j<=len; ++j)
    {
        for(int i=j-1; i>=1; --i)
        {
            for(int k=0; k<=a; ++k)
            {
                dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k]);//not change borders
                if(s[i]==s[j]) dp[i][j][k] = max(dp[i][j][k], dp[i+1][j-1][k]+2);//not change borders
                if(k) dp[i][j][k] = max(dp[i][j][k], max(dp[i][j][k], dp[i+1][j-1][k-1]+2));//change one border
            }
        }
    }
    printf("%d\n",dp[1][len][a]);
    return 0;
}


Measured memory_bytes: 108416
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il int max(int x,int y){return x>y?x:y;}
il int min(int x,int y){return x<y?x:y;}
il int abs(int x){return x>0?x:-x;}
il void swap(int &x,int &y){int t=x;x=y;y=t;}
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 100010
string s1,s2;
int main(){
	cin>>s1;s1=s1+s1;
	cin>>s2;
	int pos=s1.find(s2),l=s2.size();
	for(int i=pos;i<pos+l;i++)if(s1[i]!=s2[i-pos])return puts("No"),0;
	puts("Yes");return 0;
}

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

typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;

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

int rev(int n) {
    return n == 1 ? 2 : 1;
}

bool inFloor(int x, int y) {
    if (0 <= x && x < 8 && 0 <= y && y < 8) return true;
    return false;
}

int main() {
    mat d(8, vec(8));

    for (auto &i : d) {
        for (auto &j : i) {
            char c; cin >> c;
            if (c == 'o') j = 1;
            if (c == 'x') j = 2;
        }
    }

    int turn = 1;
    int pass = 0;
    while (1) {
        int tx(-1), ty(-1);
        int count = 1;
        for (int i = 0; i < 8; i++) {
            for (int j = 0 ; j < 8; j++) {
                if (d[i][j] == 0) {
                    int count_ = 0;
                    for (int k = 0; k < 8; k++) {
                        int x = i + dx[k];
                        int y = j + dy[k];
                        int tmp = 0;
                        while (inFloor(x, y) && d[x][y] == rev(turn)) {
                            x += dx[k], y += dy[k];
                            tmp++;
                        }
                        if (inFloor(x,y) && d[x][y] == turn) count_ += tmp;
                    }

                    if (count < count_ || (count_ > 0 && tx < 0)) {
                        tx = i; ty = j; count = count_;
                    } else if (count == count_) {
                        if (turn == 1) {
                            if (tx > i) tx = i, ty = j;
                            else if (tx == i && ty > j) ty = j;
                        } else {
                            if (tx < i) tx = i, ty = j;
                            else if (tx == i && ty < j) ty = j;
                        }
                    }
                }
            }
        }

        if (tx > -1) {
            d[tx][ty] = turn;
            for (int i = 0; i < 8; i++) {
                int x = tx + dx[i];
                int y = ty + dy[i];
                while (inFloor(x, y) && d[x][y] == rev(turn)) {
                    x += dx[i], y += dy[i];
                }
                if (inFloor(x, y) && d[x][y] == turn)
                    while (inFloor(x, y) && d[(x+=dx[(i+4)%8])][(y+=dy[(i+4)%8])] == rev(turn))
                        d[x][y] = turn;
            }
            pass = 0;
        } else pass++;
        if (pass == 2) break;

        turn = rev(turn);
    }

    for (auto i : d) {
        for (auto j : i) {
            if (j == 1) cout << 'o';
            else if (j == 2) cout << 'x';
            else cout << '.';
        }
        cout << endl;
    }

    return 0;
}

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

struct Process{
    string name;
    int ttime;
    Process(string name_, int tt): name(name_), ttime(tt){}
};

int main(){
    queue<Process> qu;
    int n,q;
    string name;
    int qt;
    cin>>n>>q;
    int tt=0;
    while(n--){
        cin>>name>>qt;
        qu.push(Process(name, qt));
    }
    while(!qu.empty()){
        Process p = qu.front();
        qu.pop();
        if(p.ttime <= q){
            cout<<p.name<<" "<<tt+p.ttime<<endl;
            tt += p.ttime;
            p.ttime = 0;
        }
        else{
            p.ttime -= q;
            qu.push(p);
            tt += q;
        }
    }
    return 0;
}


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

using namespace std;

int a, b;

int main() {

	cin >> a >> b;
	
	if (a >= 13) cout << b << "\n";
	else if (a >= 6) cout << b / 2 << "\n";
	else cout << "0\n";

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

int main(){
    int x;
    cin >> x;
    int a = x / 500;
    x = x % 500;
    int b = x / 5;
    long long ans = 1LL * a * 1000 + b * 5LL;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#coding:utf-8

if __name__ == "__main__":

    i = int(input())

    money = 0

    for j in range(i):

        j,k = map(str,input().split())

        kane = 0

        if k == 'JPY':
            kane = int(j)
        else:
            kane = float(j) * 380000.0

        money += kane

    print(money)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e16;
#define int long long

const int MAX_N = 1010;

bool ok[10];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int cnt = 0;
	rep(i, n) {
		int a; cin >> a;
		if (3200 <= a) {
			cnt++;
		}
		else {
			ok[a / 400] = true;
		}
	}
	if (n == 1) {
		cout << 1 << " " << 1 << endl; return 0;
	}
	int ans = 0;
	rep(i, 10) {
		if (ok[i])ans++;
	}
	if (ans == 0) {
		cout << 1 << " " << ans + cnt << endl; return 0;
	}
	cout << ans << " " << ans+cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG true
#define coutd if(DEBUG) cout
#define ff first
#define ss second
#define len(x) int(x.size())
using ll = long long;
using ii = pair<int, int>;

struct res{
	int i;
	string name;
	int pt;
	
	bool operator < (res other) const {
		return name==other.name ? pt>other.pt : name<other.name; 
	}
};
int main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<res> vs(n);
	for(int i=0; i<n; i++){
		vs[i].i=i+1;
		cin >> vs[i].name >> vs[i].pt;
	}
	sort(vs.begin(), vs.end());
	for(auto i:vs)
		cout << i.i<< endl;

}



Measured memory_bytes: 256
N = int(input())
C = list(input())
c = 0
top = 0
back = N-1
while top < back:
  if(C[top]=="W" and C[back]=="R"):
    c += 1
    C[top] = "R"
    C[back] = "W"
    top += 1
    back -= 1
  elif(C[top]=="W" and C[back]=="W"):
    back -= 1
  elif(C[top]=="R" and C[back]=="W"):
    top += 1
    back -= 1
  elif(C[top]=="R" and C[back]=="R"):
    top += 1
    
print(c)
    
  
  




Measured memory_bytes: 76148
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    string S;
    cin >> S;
    int N = S.size();
    for(int del = 1; del <= N - 2; del++){
        int n = N - del;
        if(n % 2) continue;

        if(S.substr(0, n / 2) == S.substr(n/2, n/2)){
            cout << n << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3568
#include "stdio.h"
#include <iostream>
using namespace std;

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

}

Measured memory_bytes: 1156
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int a, b, c, d;
    cin >> a >>b >> c >> d;
    cout << max(a*b, c*d) << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
#define int ll
using namespace std;

inline int read(){
	int sum=0,f=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
	while(c<='9'&&c>='0'){sum=sum*10+c-'0';c=getchar();}
	return f*sum;
}

const int N=55;
const int M=N*N*N;
struct edge{int to,next;}e[N];
struct node{int v,w,id;}a[N];
int n,m,D;
int head[N],cnt;
int dp[M];

inline void add(int x,int y){
	e[++cnt]=(edge){head[x],y};head[x]=cnt;
}

inline bool cmp(node a,node b){return a.v*b.w>b.v*a.w;}

inline void dfs(int x){
	a[x].v=1;
	for(int i=head[x];i;i=e[i].to){
		int k=e[i].next;dfs(k);
		a[x].v+=a[k].v;a[x].w+=a[k].w;
	}
}

signed main(){
	n=read();m=read();D=read();
	int X=min(D,n),d=n*n*n;
	a[1].w=read();
	for(int i=2;i<=n;i++){
		a[i].w=read();int x=read();add(x,i);
	}
	for(int i=1;i<=n;i++) a[i].id=i;
	dfs(1);
	memset(dp,0x3f,sizeof(dp));	dp[0]=0;
	for(int i=1;i<=n;i++){
		int x=X;
		for(int j=0;(1<<j)<=x;j++){
			int v=a[i].v*(1<<j),w=a[i].w*(1<<j);
			for(int k=d;k>=v;k--) dp[k]=min(dp[k],dp[k-v]+w);
			x-=(1<<j);
		}
		if(x){
			int v=a[i].v*x,w=a[i].w*x;
			for(int k=d;k>=v;k--) dp[k]=min(dp[k],dp[k-v]+w);
		}
	}
	sort(a+1,a+n+1,cmp);
	while(a[n].id!=1) n--;
	int ans=0;
	for(int i=0;i<=d;i++){
		if(dp[i]>m) continue;
		int v=i,w=dp[i];
		for(int j=1;j<=n;j++){
			int c=min(j==n? 0x3f3f3f3f:D-X,(m-w)/a[j].w);
			v+=c*a[j].v,w+=c*a[j].w;
		}
		ans=max(ans,v);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1536
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

type node struct {
	no      int
	cnt     int
	visited bool
	next    []int
}

type graph []node

func dfs(G *graph, x int) {
	(*G)[x].visited = true
	for _, i := range (*G)[x].next {
		if !(*G)[i].visited {
			(*G)[i].cnt += (*G)[x].cnt
			dfs(G, i)
		}
	}

}

func main() {
	sc.Split(bufio.ScanWords)
	N, Q := scanInt(), scanInt()

	G := make(graph, N)
	for i := 0; i < N; i++ {
		G[i].no = i
		G[i].next = make([]int, 0)
	}

	for i := 0; i < N-1; i++ {
		a, b := scanInt(), scanInt()
		G[a-1].next = append(G[a-1].next, b-1)
		G[b-1].next = append(G[b-1].next, a-1)
	}

	for i := 0; i < Q; i++ {
		p, x := scanInt(), scanInt()
		G[p-1].cnt += x
	}
	dfs(&G, 0)

	for _, node := range G {
		fmt.Printf("%d ", node.cnt)
	}
	fmt.Printf("\n")
}


Measured memory_bytes: 73216
#include <iostream>
    using namespace std;
     
    int main(){
        string S1, S2;
        cin >> S1 >> S2;
        if(S1[0] == S2[2] && S1[2] == S2[0] && S1[1] == S2[1]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> v(100005);
    while (n--) {
        int x;
        cin >> x;
        ++v[x];
    }

    int ans = 0;
    for (int i = 1; i <= 100000; ++i) {
        ans = max(ans, v[i-1] + v[i] + v[i+1]);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back

int main() 
{ 
    int n;
    cin>>n;
    vector<int> a(n);
    int i,j,ans = 0;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=1;i<=n;i++)
    {
        if(i%2!=0 && a[i-1]%2!=0)
            ans++;
    } 
    cout<<ans;
    return 0; 
} 

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
 
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e4 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(h, w);
	char ch[h + 1][w + 1] = {};
	FOR (i, 1, h)
	    FOR (j, 1, w)
	        cin >> ch[i][j];
    
    vvi dp(h + 1, vi(w + 1, 0));
    FOR (i, 1, h)
    {
        int j = 1;
        if (ch[i][j] == '#' && ch[i - 1][j] != '#') dp[i][j] = dp[i - 1][j] + 1;
	        else dp[i][j] = dp[i - 1][j];
    }
    
    FOR (j, 1, w)
    {
        int i = 1;
        if (ch[i][j] == '#' && ch[i][j - 1] != '#') dp[i][j] = dp[i][j - 1] + 1;
	        else dp[i][j] = dp[i][j - 1];
    }
    
    FOR (i, 2, h)
	    FOR (j, 2, w)
	    {
	        if (ch[i][j] == '#' && ch[i - 1][j] != '#') dp[i][j] = dp[i - 1][j] + 1;
	        else dp[i][j] = dp[i - 1][j];
	        
	        if (ch[i][j] == '#' && ch[i][j - 1] != '#') dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
	        else dp[i][j] = min(dp[i][j], dp[i][j - 1]);
	    }
    cout << dp[h][w];
}







Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

void query(int u, int v)
{
    cout << "? " << u << " " << v << endl;
}

int main()
{
    int n, st, gt;
    cin>>n>>st>>gt;
    assert(n!=1);
    vector<vector<int>> dist(n+1,vector<int>(n+1,INF));
    for(int i=1;i<=n;i++) dist[i][i] = 0;
    if(n==2)
    {
        cout << "! " << st << " " << gt << endl;
        return 0;
    }
    query(st, gt);
    int d; cin>>d;
    dist[st][gt] = dist[gt][st] = d;
    // (dist, index)
    vector<P> cand;
    for(int i=1;i<=n;i++)
    {
        if(i==st || i==gt) continue;
        query(st, i);
        cin >> d;
        dist[st][i] = dist[i][st] = d;
        query(i, gt);
        cin>>d;
        dist[i][gt] = dist[gt][i] = d;
        if(dist[st][gt] == dist[st][i] + dist[i][gt])
        {
            cand.push_back(P(dist[st][i], i));
        }
    }
    sort(cand.begin(),cand.end());
    vector<int> ret;
    ret.push_back(st);
    if(cand.size())
    {
        int index = 0, cur=cand[index].second;
        ret.push_back(cur);
        for(int i=1;i<(int)cand.size();i++)
        {
            query(cur, cand[i].second);
            cin >> d;
            if(dist[st][cur] + d + dist[cand[i].second][gt] != dist[st][gt]) continue;
            index = i;
            cur = cand[index].second;
            ret.push_back(cur);
        }
    }
    ret.push_back(gt);
    cout << "!";
    for(auto v:ret)
    {
        cout << " " << v;
    }
    cout << endl;
}



Measured memory_bytes: 4652
import math
import fractions
import collections
import itertools
from collections import deque
N=int(input())
S=input()
leftRGB=[[0,0,0] for _ in range(N)]
rightRGB=[[0,0,0] for _ in range(N)]
cnt=0
buf=0
ch=""
R=0
G=0
B=0
for i in range(N):
    if S[i]=="R":
        R=R+1
    elif S[i]=="G":
        G=G+1
    else:
        B=B+1
    leftRGB[i][0]=R
    leftRGB[i][1] = G
    leftRGB[i][2] = B
R=0
G=0
B=0
for i in range(N):
    if S[N-1-i]=="R":
        R=R+1
    elif S[N-1-i]=="G":
        G=G+1
    else:
        B=B+1
    rightRGB[N-1-i][0]=R
    rightRGB[N-1-i][1] = G
    rightRGB[N-1-i][2] = B
#print(leftRGB)
#print(rightRGB)
for i in range(N):
    if (i!=0)and(i!=N-1):
        ch=S[i]
        if S[i]=="R":
            cnt=cnt+(leftRGB[i-1][1]*rightRGB[i+1][2])+(leftRGB[i-1][2]*rightRGB[i+1][1])
            for j in range(min(i,N-1-i)):
                if (S[i-j-1]=="G")and(S[i+j+1]=="B"):
                    cnt=cnt-1
                if (S[i-j-1]=="B")and(S[i+j+1]=="G"):
                    cnt=cnt-1
        elif S[i]=="G":
            cnt = cnt + (leftRGB[i - 1][0] * rightRGB[i + 1][2])+(leftRGB[i - 1][2] * rightRGB[i + 1][0])
            for j in range(min(i,N-1-i)):
                if (S[i-j-1]=="R")and(S[i+j+1]=="B"):
                    cnt=cnt-1
                if (S[i-j-1]=="B")and(S[i+j+1]=="R"):
                    cnt=cnt-1
        else:
            cnt = cnt + (leftRGB[i - 1][0] * rightRGB[i + 1][1])+(leftRGB[i - 1][1] * rightRGB[i + 1][0])
            for j in range(min(i,N-1-i)):
                if (S[i-j-1]=="R")and(S[i+j+1]=="G"):
                    cnt=cnt-1
                if (S[i-j-1]=="G")and(S[i+j+1]=="R"):
                    cnt=cnt-1
        #print(leftRGB[i - 1],rightRGB[i + 1],S[i],cnt)
        #input()
print(cnt)




Measured memory_bytes: 74856
#require 'pp'

n = gets.chomp!.to_i
a_n = gets.split.map(&:to_i)

digit_max = 61
memo = Array.new(digit_max)
digit_max.times do |i|
    memo[i] = [0, n]
end

digit_max.times do |d|
    memo[d][0] = a_n.count {|a| a[d] == 1 }
    memo[d][1] = n - memo[d][0]
end

MOD = (10 ** 9) + 7
sum = 0
count = Array.new(digit_max, 0)
digit_max.times do |dig|
    s = (2 ** dig) * (memo[dig][0] * memo[dig][1])
    sum = (sum + s) % MOD
end
    
puts sum


Measured memory_bytes: 34828
n = int(input())
h = [int(i) for i in input().split()]
ans = []
i = 0
if n ==1:
    ans.append(0)
else:
    while i < n-1:
        count_min = 0
        while i<n-1 and h[i]<h[i+1]:
            i += 1
        while i<n-1 and h[i]>=h[i+1]:
            count_min += 1
            i += 1 
        ans.append(count_min)
print(max(ans))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;

using namespace std;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie();
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    for (int i = 0; i < m; i++)
        cin >> s[i] >> c[i];
    for (int i = (n == 1 ? 0 : pow(10, n-1)); i < pow(10, n); i++){
        string x = to_string(i);
        bool ok = true;
        for (int j = 0; j < m; j++){
            if (x[s[j] - 1] != '0' + c[j]){
                ok = false;
                break;
            }
        }
        if (ok){
            cout << x;
            return 0;
        }
    }
    cout << "-1";
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int x, y;

signed main() {
	cin >> x >> y;
	cout << x + y/2 << endl;
}


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

int main() {
  /*
  int a, b, na, nb;
  int a1, a2, a3, a4, a5, b1, b2, b3, b4, b5;
  std::cin >> a >> b;
  
  b1 = b % 10;
  b2 = (b / 10) % 10;
  b3 = (b / 100) % 10;
  b4 = (b / 1000) % 10;
  b5 = (b / 10000) % 10;
  
  nb = 0
    + b5 * 10 * 10
    + b4 * 10
    + b3
    + (b4 >= b2 && b5 >= b1) ? 1 : 0;


  34243;
    
  2-*-2 )	-, *
  1-*-1 ) 	3 * 10 * 10
  0-*-0 )
  3			
   3*33 )
   2*23 )	4 * 10
   1*13 )
   0*03 )
   4
    143 )	2
    043 )
    2
  
  a--;
  a1 = a % 10;
  a2 = (a / 10) % 10;
  a3 = (a / 100) % 10;
  a4 = (a / 1000) % 10;
  a5 = (a / 10000) % 10;

  na = 0
    + a5 * 10 * 10
    + a4 * 10
    + a3
    + (a4 >= a2 && a5 >= a1) ? 1 : 0;
  
  std::cout << nb << std::endl;
  std::cout << na << std::endl;
  std::cout << nb - na << std::endl;
  */
  int sum = 0;
  int a, b;
  std::cin >> a >> b;
  for (int i = a; i <= b; i++) {
    int i1, i2, i3, i4, i5;
    i1 = i % 10;
    i2 = (i / 10) % 10;
    i3 = (i / 100) % 10;
    i4 = (i / 1000) % 10;
    i5 = (i / 10000) % 10;
    if (i1 == i5 && i2 == i4) {
      sum++;
    }
  }
  std::cout << sum << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n;
    double t, a;
    cin >> n >> t >> a;
    int result = 0;
    double minDiff = 1000.0;
    for (int i=1; i<=n; i++) {
        int h;
        cin >> h;
        if (minDiff > abs(t-h*0.006-a)) {
            minDiff = abs(t-h*0.006-a);
            result = i;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int k, a, b, c, d;
unordered_map<int, int> cache;

int work(int n)
{
	if(n == 0)
		return 0;
	if(n == 1)
		return d;
	if(cache.count(n))
		return cache[n];
	int &ans = cache[n];
	ans = 4e18;
	if(n <= 4e9)
	    ans = min(ans, n * d);
	for(int i = -12; i <= 12; i++)
	{
		int nxtN = n + i;
		if(nxtN < 0)
			continue;
		if(nxtN % 2 == 0 && nxtN / 2 < n)
			ans = min(ans, d * abs(i) + a + work(nxtN / 2));
		if(nxtN % 3 == 0 && nxtN / 3 < n)
			ans = min(ans, d * abs(i) + b + work(nxtN / 3));
		if(nxtN % 5 == 0 && nxtN / 5 < n)
			ans = min(ans, d * abs(i) + c + work(nxtN / 5));
		if(nxtN % 6 == 0 && nxtN / 6 < n)
			ans = min(ans, d * abs(i) + a + b + work(nxtN / 6));
		if(nxtN % 15 == 0 && nxtN / 15 < n)
			ans = min(ans, d * abs(i) + b + c + work(nxtN / 15));
		if(nxtN % 10 == 0 && nxtN / 10 < n)
			ans = min(ans, d * abs(i) + a + c + work(nxtN / 10));
	}	
	return ans;
}

int32_t main()
{
	IOS;
	int t;
	cin >> t;
	while(t--)
	{
		cache.clear();
		cin >> k >> a >> b >> c >> d;
		int ans = work(k);
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
	string a;
	cin >> a;
	string b = "No";
	if (a[0] == a[1] && a[1] == a[2]) {
		b = "Yes";
	}
	if (a[1] == a[2] && a[2] == a[3]) {
		b = "Yes";
	}
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(){
	string s="101";
  	cin >> s;
  	int sum = 0;
  	for(int i=0;i<3;i++){
  	if (s[i] == '1') sum=sum+1;
    }
    cout << sum << endl;
}

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

using namespace std;

int main()
{
    int n,k,p;
    vector <int> v;

    cin>>n>>k;

    while(n--){

        cin>>p;
        v.push_back(p);

    }

    int sum=0;

    sort(v.begin(),v.end());
    for(int i=0;i<k;i++){
       sum+=v[i];
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();

    if (Pattern.matches("[a-z]", a)) {
      System.out.println("a");
    } else {
      System.out.println("A");
    }
  }
}


Measured memory_bytes: 26996
//This is the Property of Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e9+7;
ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll temp=power(a,b/2)%mod;
    if(b%2==0){
        return (temp*temp)%mod;
    }
    else{
        return ((a*temp)%mod*temp)%mod;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        a[0]=0;
        for(ll x=0; x<n; x++){
            cin>>a[x];
        }
        ll dp[n];
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        for(ll x=2; x<n; x++){
            dp[x]=min(dp[x-1]+abs(a[x]-a[x-1]),dp[x-2]+abs(a[x]-a[x-2]));
        }
        cout<<dp[n-1]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }

    int cnt = 0;
    auto insertionSort = [&](int g) {
        for(int i = g; i < n; ++i) {
            int v = a[i];
            int j = i-g;
            while(j >= 0 and a[j] > v) {
                a[j+g] = a[j];
                j = j-g;
                cnt++;
            }
            a[j+g] = v;
        }
    };

    int m = 0;
    ll now = 1;
    ll x = 1;
    vi G;
    while(now <= n) {
        G.push_back(now);
        x *= 3;
        now += x;
        m++;
    }

    rep(i, m) {
        insertionSort(G[m-1-i]);
    }

    cout << m << '\n';
    rep(i, m) {
        cout << G[m-1-i] << (i == m-1?'\n':' ');
    }
    cout << cnt << endl;

    rep(i, n) {
        cout << a[i] << '\n';
    }
}


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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	char c = s.at(0);
	ll ans = 1;
	for (int i = 0; i < n; i++) {
		if (c != s.at(i)) {
			ans++;
			c = s.at(i);
		}
	}
	cout << ans << endl;
}

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

using namespace std;

struct UnionFind {  // The range of node number is from 0 to n-1
	//'rank[x]' is a rank of the union find tree the root of which is x.
	//'parents[x]' is the parent of x
	vector<int> rank, size, parents;

	// constructor
	UnionFind() {}
	UnionFind(int n) {  // make n trees.
		size.resize(n, 0);
		rank.resize(n, 0);
		parents.resize(n, 0);
		for (int i = 0; i < n; i++) {
			makeTree(i);
		}
	}
	// make a union find tree
	void makeTree(int x) {
		parents[x] = x;  // the parent of x is x
		rank[x] = 0;
		size[x] = 1;
	}

	// check whether the root of x is the same as that of y
	bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }

	//uniteはどちらかを選ぶこと！！！！！

	// unite two tree (ランク（木の高さ）が低くなるように繋げる場合）
	bool unite(int x, int y) {
		x = findRoot(x);
		y = findRoot(y);
		if (x == y) return false;
		if (rank[x] > rank[y]) {
			parents[y] = x;
		}
		else {
			parents[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
		return true;
	}

	// unite two tree (サイズ（頂点の数）が大きい方に小さい方を繋げる場合）
	//bool unite(int x, int y) {
	//	x = findRoot(x);
	//	y = findRoot(y);
	//	if (x == y) return false;
	//	if (size[x] > size[y]) {
	//		parents[y] = x;
	//		size[x] += size[y];
	//	}
	//	else {
	//		parents[x] = y;
	//		size[y] += size[x];
	//	}
	//	return true;
	//}

	//// 経路圧縮（全て根につなげる）する場合の根探しtravel the parents of tree recursivily to find root
	int findRoot(int x) {
		if (x != parents[x]) {
			parents[x] = findRoot(parents[x]);  // change the x's parent to the root of tree.
		}
		return parents[x];
	}
	//経路圧縮しない場合
	//int findRoot(int x) {
	//	if (x == parents[x])
	//		return x;
	//	return findRoot(parents[x]);
	//}

	int treeSize(int x) { return size[findRoot(x)]; }
};

int main() {

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(m);

	int in1, in2;
	for (int i = 0; i < m; i++) {
		cin >> in1 >> in2;
		a[i] = make_pair(in1-1, in2-1);
	}

	int res = 0;
	for (int i = 0; i < m; i++) {

		UnionFind tree(n);

		for (int j = 0; j < m; j++) {

			if (i == j) { continue; }

			tree.unite(a[j].first, a[j].second);
		}

		bool brkflg = false;
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (tree.findRoot(j) != tree.findRoot(k)) {
					res++;
					brkflg = true;
					break;
				}
			}
			if (brkflg) { break; }
		}
	}

	cout << res << endl;

	return 0;
}

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

using namespace std;

int main()
{
  int N, W, H;
  cin >> N >> W >> H;
  int wifi[2][100002] = {{0}};
  for(int i = 0; i < N; i++){
    int x, y, w;
    cin >> x >> y >> w;
    wifi[0][max(0, x-w)]++, wifi[1][max(0, y-w)]++;
    wifi[0][min(x+w, W)]--, wifi[1][min(y+w, H)]--;
  }
  partial_sum(wifi[0], wifi[0] + W, wifi[0]);
  partial_sum(wifi[1], wifi[1] + H, wifi[1]);
  if(*min_element(wifi[0], wifi[0] + W) <= 0 &&
     *min_element(wifi[1], wifi[1] + H) <= 0){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 1944
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
const int N=1e3+5,inf=0x7f7f7f7f;
int n,a,b;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	printf("%d %d",min(a,b),min(n,max(0,a+b-n)));
	return 0; 
}

Measured memory_bytes: 256
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

#　素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# ここから書き始める
n = int(input())
a = list(map(int, input().split()))
x = a[0]
y = sum(a[1:])
a = a[1:-1]
ans = abs(x - y)
# print("x =", x)
# print(a)
for i in range(n - 2):
    x += a[i]
    y -= a[i]
    ans = min(ans, abs(x - y))
print(ans)

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

double dis(pair<long, long> a, pair<long, long> b){
  return abs(a.first - b.first) + abs(a.second - b.second);
}

int main() {
  int N, K;
  cin >> N >> K;
  long ans = K*pow(K-1, N-1);
  cout << ans << endl;
}



Measured memory_bytes: 384
X, Y, A, B, C = (int(x) for x in input().split())
R = [int(i) for i in input().split()]
G = [int(i) for i in input().split()]
M = [int(i) for i in input().split()]

R.sort(reverse=True)
G.sort(reverse=True)

for i in range(X):
  M.append(R[i])

for i in range(Y):
  M.append(G[i])

M.sort(reverse=True)

ans = 0
for i in range(X + Y):
  ans = M[i] + ans

print(ans)


Measured memory_bytes: 23340
a,b = gets.chomp.split(' ').map(&:to_i)
x = 0
y = 0
z = 0
xyz = []

switch = false

while x < a + 1
  break if switch
  y = 0
  while y < a + 1
    z = a-(x+y)
    # p "#{x}:#{y}:#{z}"
    if x + y + z < a + 1 && b == (10000 * x) + (5000 * y) + (1000 * z) && z >= 0
      xyz << [x,y,z]
      # p "#{x}:#{y}:#{z}"
      switch = true
      break
    end
    y += 1
  end
  x += 1
end

if !xyz.empty?
  puts "#{xyz[0][0]} #{xyz[0][1]} #{xyz[0][2]}"
else
  puts "-1 -1 -1"
end

Measured memory_bytes: 3836
#include<stdio.h>
#include<stdlib.h>

int max1(int a,int b){
	if(a<b)
	return b;
	else 
	return a;
}
int max2(int a,int b,int c){
	int m;
	m=max1(max1(a,b),c);
	return m;
}
int main()
{
	int a,b,c,max;
	scanf("%d %d %d",&a,&b,&c);
	max=max2(a,b,c);
	
	if(max==a)
	{
		if(b<c)
		printf("%d %d %d\n",b,c,a);
		else 
		printf("%d %d %d\n",c,b,a);
	}
	else if(max==b){
		if(a<c)
		printf("%d %d %d\n",a,c,b);
		else 
		printf("%d %d %d\n",c,a,b);
	}
	else if(max==c){
		if(a<b)
		printf("%d %d %d\n",a,b,c);
		else
		printf("%d %d %d\n",b,a,c);
	}
	

	return 0;
}


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

int N;

void dfs(string s, char mx){
    if(s.length() == N){
        printf("%s\n", s.c_str());
    }
    else {
        for(char c='a';c<=mx;c++){
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
        }
    }
}

int main(void){
    cin >> N;
    dfs("",'a');
    return 0;
}


Measured memory_bytes: 1536
N, K= [int(i) for i in input().split()]
An = [int(i) for i in input().split()]

i = 0
checked = [0 for _ in range(N)]
c = 0
while checked[i] == 0:
  c += 1
  checked[i] = c
  i = An[i] - 1
if checked[i] >= K:
  i = 0
  for k in range(K):
    i = An[i] - 1
  print(i + 1)
else:
  period = c - checked[i] + 1
  diff = K - checked[i] + 1
  mod_diff = diff % period
  for k in range(mod_diff):
    i = An[i] - 1
  print(i + 1)
  

Measured memory_bytes: 32196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        if (a == b && b == c) {
            cout << -1 << endl;
            return 0;
        }
        ll x = (b + c) / 2;
        ll y = (a + c) / 2;
        ll z = (a + b) / 2;
        a = x;
        b = y;
        c = z;
        cnt++;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.nio.file.FileSystemLoopException;
import java.text.DecimalFormat;
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static class P {
        int x;
        int y;

        public P(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            P p = (P) o;
            return x == p.x &&
                    y == p.y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int T = Integer.parseInt(scanner.next());
        int[][] CT = new int[N][2];
        for (int i = 0; i < N; i++) {
            CT[i][0] = Integer.parseInt(scanner.next());
            CT[i][1] = Integer.parseInt(scanner.next());
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            if (CT[i][1] <= T) {
                ans = Math.min(ans, CT[i][0]);
            }
        }

        System.out.println(ans == Integer.MAX_VALUE ? "TLE" : ans);
    }

}


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

int main() {
    int n;
    string s;
    cin>>n>>s;
    int l[n]{},r[n]{};
    for (int i=0;i+1<n;i++)
        l[i+1]=l[i]+(s[i]=='W');
    for (int i=n-1;i>0;i--)
        r[i-1]=r[i]+(s[i]=='E');
    int mn=1e9;
    for (int i=0;i<n;i++)
        mn=min(mn,l[i]+r[i]);
    cout<<mn<<endl;
    return 0;
}

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

using namespace std;

int main() {
	string S;
	cin >> S;
	int first  = stoi(S.substr(0, 2));
	int second = stoi(S.substr(2, 2));

	if ((first >= 13 || first == 0) && second >= 1 && second <= 12) {
		cout << "YYMM" << endl;
	} else if ((second >= 13 || second == 0) && first >= 1 && first <= 12) {
		cout << "MMYY" << endl;
	} else if (!(first == 0 && second == 0) && first <= 12 && second <= 12) {
		cout << "AMBIGUOUS" << endl;
	} else {
		cout << "NA" << endl;
	}
}


Measured memory_bytes: 256
import bisect
import sys

def input():
    return sys.stdin.readline()

A, B, Q = map(int, input().split())

shrines = []
for i in range(A):
    shrines.append(int(input()))

temples = []
for i in range(B):
    temples.append(int(input()))

shortest_s_to_t = {}
for shrine in shrines:
    index = bisect.bisect_left(temples, shrine)
    if index == 0:
        distance = abs(shrine - temples[index])
        shortest_s_to_t[shrine] = distance
    elif index == B:
        distance = abs(shrine - temples[index - 1])
        shortest_s_to_t[shrine] = distance
    else:
        distance_left = abs(shrine - temples[index - 1])
        distance_right = abs(shrine - temples[index])
        shortest_s_to_t[shrine] = min(distance_left, distance_right)

shortest_t_to_s = {}
for temple in temples:
    index = bisect.bisect_left(shrines, temple)
    if index == 0:
        distance = abs(temple - shrines[index])
        shortest_t_to_s[temple] = distance
    elif index == A:
        distance = abs(temple - shrines[index - 1])
        shortest_t_to_s[temple] = distance
    else:
        distance_left = abs(temple - shrines[index - 1])
        distance_right = abs(temple - shrines[index])
        shortest_t_to_s[temple] = min(distance_left, distance_right)

for i in range(Q):
    x = int(input())

    # shrine to temple
    index = bisect.bisect_left(shrines, x)
    ans = 10**11
    if index > 0:
        left_shrine = shrines[index - 1]
        candidate = abs(x - left_shrine) + shortest_s_to_t[left_shrine]
        ans = min(ans, candidate)
    if index < A:
        right_shrine = shrines[index]
        candidate = abs(x - right_shrine) + shortest_s_to_t[right_shrine]
        ans = min(ans, candidate)

    # temple to shrine
    index = bisect.bisect_left(temples, x)
    if index > 0:
        left_temple = temples[index - 1]
        candidate = abs(x - left_temple) + shortest_t_to_s[left_temple]
        ans = min(ans, candidate)
    if index < B:
        right_temple = temples[index]
        candidate = abs(x - right_temple) + shortest_t_to_s[right_temple]
        ans = min(ans, candidate)

    print(ans)

Measured memory_bytes: 115676