akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val (s,t) = readLine()!!.split(" ")
    val (a,b) = readLine()!!.split(" ").map{it.toInt()}
    val u = readLine()!!
    if(u == s){
        println((a - 1).toString() + " " + b)
    }
    else{
        println(a.toString() + " " + (b - 1))
    }
}

Measured memory_bytes: 36004
H, W = map(int, input().split())
C = []
N = 10
for i in range(N):
    c = list(map(int, input().split()))
    C.append(c)

def w_f(C):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                C[i][j] = min(C[i][j], C[i][k]+C[k][j])
    return C

C = w_f(C)

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

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] != -1:
            ans += C[A[h][w]][1]
            
print(ans)

Measured memory_bytes: 9588
/*It’s going to be hard,
but hard does not mean impossible.*/

#include <bits/stdc++.h>

// definitions
#define __Imperial_Lord__ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define acc(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"
#define p2(a, b) cout << a << " " << b << "\n"
#define p3(a, b, c) cout << a << " " << b << " " << c <<"\n"
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d <<"\n"
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<"\n"
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<long double> vld;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1e18;

template <class ...Args>
istream &read_args(Args &...args) {return (cin >> ... >> args);}
#define read(...)   __VA_ARGS__; read_args(__VA_ARGS__)

// cin and cout overloaded for vectors
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v)
        is >> i;
    return is;
}
template<typename T>    ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v)
        os << i << ' ';
    return os;
}

// code beigns in main
int main()
{
    __Imperial_Lord__
    ll t = 1;
    // cin >> t;
    
    while (t--)
    {
        ll read(a,b,c);
        ll read(k);
        ll cnt=0;
        while(b<=a)
        {
            b*=2; cnt++;
        }
        while(c<=b)
        {
            c*=2;
            cnt++;
        }    

        if(cnt<=k) p1("Yes");
        else p1("No");
    }   
    exec;
}





Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;

const int inf = 1e17 + 7;
const int MOD = 1e7 + 9;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s;
	cin>>s;
	if(s[3]==s[2] && s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
# AOJ ITP1_11_A

# サイコロ。

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

class dice:
    def __init__(self):
        self.data = [0 for i in range(8)]
        a = intinput()
        for i in range(1, 7): self.data[i] = a[i - 1]  # 1, 2, 3, 4, 5, 6.
        for i in range(6): self.data[0] += a[i]  # 各位の和を0に。
        self.data[7] = a[0] * a[5] + a[1] * a[4] + a[2] * a[3]  # 対面同士の積の和。
        # dataの1, 2, 3, 4, 5, 6というindexが位置を示す。
        # 回転するとそれらの位置にある数が変化するイメージ。

    def d_read(self, a):
        # aはたとえば5, 1, 2, 6のような配列
        b = []
        for i in range(len(a)): b.append(self.data[a[i]])
        return b

    def d_write(self, b, c):
        # cはたとえば1, 2 ,6, 5のような配列で、そこにbの中身を落とす。
        if len(b) != len(c): return     # 要求と異なる。
        for i in range(len(b)): self.data[c[i]] = b[i]

    def roll(self, direction):
        # directionが'S', 'E', 'W', 'N'.
        # 'S', 'N'では3と4が不変。 'E'と'W'では2と5が不変。
        if direction == 'S':
            self.d_write(self.d_read([5, 1, 2, 6]), [1, 2, 6, 5])
            
        elif direction == 'N':
            self.d_write(self.d_read([2, 6, 5, 1]), [1, 2, 6, 5])
            
        elif direction == 'W':
            self.d_write(self.d_read([3, 6, 4, 1]), [1, 3, 6, 4])
            
        elif direction == 'E':
            self.d_write(self.d_read([4, 1, 3, 6]), [1, 3, 6, 4])

    def get_upper(self):
        return self.data[1]

def main():
    d = dice()
    command = input()
    for i in range(len(command)):
        d.roll(command[i])
    print(d.get_upper())

if __name__ == "__main__":
    main()


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

int main(){
    int n,k; cin >> n >> k;
    map<int,int> mp;
    rep(i,k){
        int d; cin >> d;
        rep(j,d){
            int a; cin >> a;
            mp[a]++;
        }
    }
    int ans = n-mp.size();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
/*
AizuOnline A1111
Title Cyber Guardian
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int n,m;
struct rule_st
{
        char permission;  //permit or deny
        char src[8];
        char dst[8];
} rule[1024];
struct packet_st
{
        char src[8];
        char dst[8];
        int  flag;
        char msg[51];
} packet[1024];

//
int strcmp_wild8(char * s1,char * s2)  //match -1 no 0 s1 pattern s2 packet
{
        int i;
#ifdef DEBUG
        printf("cmp %.8s %.8s\n",s1,s2);
#endif

        for(i=0;i<8;i++)
                if(!((s1[i]=='?' && isdigit(s2[i]))||(s1[i]==s2[i])))
                        return(0);
        return(-1);
}
int is_permit(struct packet_st * pp)
{
        int i;
        for(i=n-1;i>=0;i--)
                if(strcmp_wild8(rule[i].src,pp->src) &&
                   strcmp_wild8(rule[i].dst,pp->dst))
                {
#ifdef DEBUG
                        printf("MATCH %d %c\n",i,rule[i].permission);
#endif
                        if(rule[i].permission=='P')
                                return(-1);
                        else
                                return(0);
                }
        return(0);
}
void print_packet(struct packet_st * pp)
{
        printf("%.8s %.8s %s\n",pp->src,pp->dst,pp->msg);
}
main()
{
        int i;
        char op[10];
        int cnt;
        
        while(EOF!=scanf("%d %d",&n,&m) && (n||m))
        {
                for(i=0;i<n;i++)
                {
                        scanf("%s ",op);

                        if(op[0]=='p')
                                rule[i].permission='P';
                        else
                                rule[i].permission='D';

                        scanf("%s ",rule[i].src);
                        scanf("%s",rule[i].dst);
                }
                for(i=0;i<m;i++)
                {
                        scanf("%s ",packet[i].src);
                        scanf("%s ",packet[i].dst);
                        scanf("%s",packet[i].msg);
                }
                //print();
                cnt=0;
                for(i=0;i<m;i++)
                        if(is_permit(&packet[i]))
                        {
                                cnt++;
                                packet[i].flag=-1;
                        }       
                        else
                                packet[i].flag=0;
                printf("%d\n",cnt);
                for(i=0;i<m;i++)
                        if(packet[i].flag)
                                print_packet(&packet[i]);
        }
return(0);
}

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

using namespace std;

int main()
{
    string S, T;
    int flag = 1;
    cin >> S >> T;

    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == T[i])
        {
        }

        if (S[i] != T[i])
        {
            flag = 2;
        }
    }

    if (flag == 1)
    {
        cout << "Yes";
    }

    if (flag == 2)
    {
        cout << "No";
    }
}

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

typedef pair<int64_t,int64_t> ii;
ii a[55];
int64_t n,k,res=4e18;

bool Check(int64_t u1,int64_t v1,int64_t u2,int64_t v2)
{
    int64_t rs=0;
    for(int64_t i=1;i<=n;i++)
        if(u1<=a[i].first&&a[i].first<=u2&&v1<=a[i].second&&a[i].second<=v2)
        {
            rs++;
            if(rs==k)
                return true;
        }
    return false;
}

int main()
{
    cin>>n>>k;
    for(int64_t i=1;i<=n;i++)
        cin>>a[i].first>>a[i].second;
    for(int64_t i=1;i<=n;i++)
        for(int64_t j=1;j<=n;j++)
            for(int64_t ii=1;ii<=n;ii++)
                for(int64_t jj=1;jj<=n;jj++)
                {
                    int64_t u1=a[i].first;
                    int64_t v1=a[j].second;
                    int64_t u2=a[ii].first;
                    int64_t v2=a[jj].second;
                    if(u1>u2)
                        swap(u1,u2);
                    if(v1>v2)
                        swap(v1,v2);
                    if(res>(u2-u1)*(v2-v1)&&Check(u1,v1,u2,v2)==true)
                        res=(u2-u1)*(v2-v1);
                }
    cout<<res;
}


Measured memory_bytes: 256
n = int(input())
ans = [0 for _ in range(n + 1)]

for x in range(1, 100 + 1):
    if x ** 2 > n - 2 * x - 2:
        break
    for y in range(1, 100 + 1):
        if x**2 + y ** 2 > n - x - y - x * y:
            break
        for z in range(1, 100 + 1):
            f = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if f > n:
                break
            ans[f] += 1


for i in range(1, n + 1):
    print(ans[i])


Measured memory_bytes: 9404
#include<stdio.h>

int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b)
	{
		printf("a > b\n");
	}
	else if(a < b)
	{
		printf("a < b\n");
	}
	else
	{
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2080
#include <iostream>

int main() {

    int a, b, c;
    std::cin >> a >> b >> c;

    if ( a > b ) std::swap(a, b);
    if ( b > c ) std::swap(b, c);
    if ( a > b ) std::swap(a, b);

    std::cout << a << " " << b << " " << c << std::endl;

    return 0;
}



Measured memory_bytes: 3104
package main

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

func main() {
	var N, M int
	var Tstr string

	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	Nstr := sc.Text()
	N, _ = strconv.Atoi(Nstr)
	sc.Scan()
	Tstr = sc.Text()
	T := make([]int, N)
	Tlist := strings.Split(Tstr, " ")
	for i := 0; i < N; i++ {
		T[i], _ = strconv.Atoi(Tlist[i])
	}

	sc.Scan()
	Mstr := sc.Text()
	M, _ = strconv.Atoi(Mstr)
	P := make([]int, M)
	X := make([]int, M)
	for i := 0; i < M; i++ {
		sc.Scan()
		str := sc.Text()
		strlist := strings.Split(str, " ")
		P[i], _ = strconv.Atoi(strlist[0])
		X[i], _ = strconv.Atoi(strlist[1])
	}

	total := 0
	for _, val := range T {
		total += val
	}

	for idx, val := range P {
		no := val - 1
		time := X[idx]
		fmt.Printf("%d\n", total-T[no]+time)
	}
}


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

#define mod 1000000007LL
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res + m) * ( a + m) % m;
        a = a * a % m;
        b >>= 1;
    }
    return (res + m) % m;
}

long long mul(long long a, long long b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return ((a + mod) * (b + mod))%mod;
}
long long add(long long a, long long b){
    a += mod;
    b += mod;
    return (a + b)%mod;
}
ll inv(ll x){
    return binpow(x, mod - 2, mod);
}
bool val(ll a, ll b, ll c) {
    if(a == b || a == c || b == c)
        return 0;
    if(a + b > c && b + c > a && c + a > b)
        return 1;
    return 0;
}
int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll y = x / d;
    if(y >= k)
    {
        cout << abs(x - k * d);
        return 0;
    }
    ll pos = x - y * d;
    ll pos2 = x - (y + 1) * d;
    ll step = k - y;
    // you are at pos
    if(step % 2 == 0)
    {
        cout << abs(pos);
    }else
    {
        cout << abs(pos2);
    }
}

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

using namespace std;
#include <cstdlib>
int main (){
  long long int n,k;
  cin >> n >> k;
  if (n>k){
      cout << min (n%k,abs(n%k-k)) << endl;

  }else{
      cout << min(n,k-n) << endl;
  }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, w;
    pair <int, long long> item[201];
    scanf("%d%d", &n, &w);
    for (int i = 0; i < n; i++)
        scanf("%d%lld", &item[i].first, &item[i].second);
    long long dp[200001];
    for (int i = 0; i < n; i++)
        for (int j = w; j >= item[i].first; j--)
            dp[j] = max(dp[j], dp[j - item[i].first] + item[i].second);
    printf("%lld\n", dp[w]);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 2005
using namespace std;
int F[N][N],G[N][N],sumF[N][N],sumG[N][N],a[N];
int n,A,B,i,l,j,k;
int main(){
	scanf("%d%d%d",&n,&A,&B);
	for (i=2;i<=n+1;i++)
	  scanf("%d",&a[i]);
	a[1]=A;a[n+2]=B;n+=2;
	for (l=2;l<=n;l++)
	  for (i=1;i<=n-l+1;i++){
	  	j=i+l-1;
	  	if (l==2){
	  		F[i][j]=G[i][j]=abs(a[i]-a[j]);
	  		sumF[i][j]=sumG[i][j]=F[i][j];
	  		continue;
	  	}
	  	F[i][j]=abs(a[j-1]-a[j]);
	  	if (i+1<j-1)
	  		F[i][j]=max(F[i][j],sumG[i+1][j]);
	  	
	  	//for (k=i+1;k<j-1;k++) F[i][j]=max(F[i][j],G[k][j]);
	  	
	  	G[i][j]=abs(a[i+1]-a[i]);
	  	if (i+2<j)
	  	  G[i][j]=min(G[i][j],sumF[i][j-1]);
	  	
	  	sumG[i][j]=max(G[i][j],sumG[i+1][j]);
	  	sumF[i][j]=min(sumF[i][j],F[i][j+1]);
	  	//for (k=i+2;k<j;k++) G[i][j]=min(G[i][j],F[i][k]);
	  }
	printf("%d\n",F[1][n]);
}

Measured memory_bytes: 62464
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define debug(x) std::cout << #x << ": " << x << endl
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

const int INF = 1e9;
const int maxN = 6003;
int dp[maxN];
pii d[maxN];

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif

    int n, T;
    cin >> n >> T;
    for (int i = 0; i < n; ++i)
    {
        cin >> d[i].fi >> d[i].se;
    }
    sort(d, d + n, [&](pii p, pii q) -> bool
    {
        return p.fi < q.fi;
    }); 
    fill(dp + 1, dp + maxN, -INF);
    for (int i = 0; i < n; ++i)
    {
        for (int s = T + d[i].fi - 1; s >= d[i].fi; --s)
        {
            chkmax(dp[s], dp[s - d[i].fi] + d[i].se);
        }
    }
    cout << *max_element(dp, dp + maxN);

    return 0;
}





Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1 3");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("7 4");
            //6
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5 5");
            //5
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        int wkSum = wkArr.Sum();

        if (wkSum % 2 == 0) {
            Console.WriteLine(wkSum / 2);
        }
        else {
            Console.WriteLine(wkSum / 2 + 1);
        }
    }
}


Measured memory_bytes: 13396
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>

using namespace std;

bool func(const pair<pair<string, int>, int> &a, const pair<pair<string, int>, int> &b)
{
	return a.first.first < b.first.first || a.first.first == b.first.first&&a.first.second > b.first.second;
}

int main()
{
	vector<pair<pair<string, int>,int>> list;
	char input[20];
	int input2;
	string str;
	int n;
	int i;

	//freopen("input.txt", "r", stdin);

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%s %d", input, &input2);

		str = input;

		list.push_back(pair<pair<string, int>, int>(pair<string, int>(str, input2), i + 1));
	}

	sort(list.begin(), list.end(), func);

	for (i = 0; i < n; i++)
	{
		printf("%d\n", list[i].second);
	}

	return 0;
}

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

int main(){
  ll n;
  cin >> n;
  vector<ll> c(100002);
  rep(i,n){
    ll a;
    cin >> a;
    c.at(a+1)++;
    c.at(a)++;
    c.at(a+2)++;
  }
  sort(c.begin(),c.end());
  cout << c.back() << endl;
  
  
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
double dp[305][305][305];
int main()
{
	int n;cin>>n;
	int n1=0,n2=0,n3=0;
	for(int i=1;i<=n;i++)
	{
		int x;cin>>x;
		if(x==1)n1++;
		else if(x==2)n2++;
		else n3++;
	}
	for(int k=0;k<=n3;k++)
		for(int j=0;j<=n3+n2;j++)
			for(int i=0;i<=n3+n2+n1;i++)
			{
				if(i==0&&j==0&&k==0){dp[i][j][k]=0;continue;}
				dp[i][j][k]=1.0*(n)/(i+j+k);
    			if(i)dp[i][j][k]+=(1.0*i/(i+j+k))*dp[i-1][j][k];
    			if(j)dp[i][j][k]+=(1.0*j/(i+j+k))*dp[i+1][j-1][k];
    			if(k)dp[i][j][k]+=(1.0*k/(i+j+k))*dp[i][j+1][k-1];
			}
	printf("%.10lf",dp[n1][n2][n3]);
	return 0;
}

Measured memory_bytes: 220656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int d,t,s; cin >> d >> t >> s;
    if((d+s-1)/s<=t) cout << "Yes" << endl;
    else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100
using namespace std;

int n;
int d[3][MAXN+5];

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
            scanf("%d",&d[i][j]);
    for(int i=1;i<=n;i++)
        d[1][i]+=d[1][i-1];
    for(int i=1;i<=n;i++)
        d[2][i]+=max(d[2][i-1],d[1][i]);
    printf("%d",d[2][n]);
}


Measured memory_bytes: 128
from operator import itemgetter
from collections import deque


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

    def root(self, x):
        """頂点xの根を求める"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        """頂点xを含む集合と頂点y含む集合を結合する"""
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.parent[x] > self.parent[y]:
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x
            self.cnt -= 1

    def is_same(self, x, y):
        """頂点xと頂点yが同じ集合に属するかどうかを返す"""
        return self.root(x) == self.root(y)

    def get_size(self, x):
        return -self.parent[self.root(x)]


n, m = map(int, input().split())
x = list(map(int, input().split()))
info = [list(map(int, input().split())) + [i] for i in range(m)]

graph = [[] for i in range(n)]
for i in range(m):
    a, b, cost, j = info[i]
    a -= 1
    b -= 1
    graph[a].append((b, cost, j))
    graph[b].append((a, cost, j))

uf = UnionFind(n)
for i in range(n):
    uf.parent[i] = -x[i]

candidate = set([])
info = sorted(info, key = itemgetter(2))
for i in range(m):
    a, b, cost, j = info[i]
    a -= 1
    b -= 1
    if not uf.is_same(a, b):
        uf.merge(a, b)
    if uf.get_size(a) >= cost:
        candidate.add(j)

ans = 0
used = [False] * m
info = sorted(info, key = itemgetter(2), reverse = True)
for i in range(m):
    a, b, cost, j = info[i]
    a -= 1
    b -= 1
    if used[j]:
        continue
    if j in candidate:
        used[j] = True
        q = deque([a, b])
        while q:
            pos = q.pop()
            for next_pos, tmp_cost, k in graph[pos]:
                if not used[k] and tmp_cost <= cost:
                    used[k] = True
                    q.append(next_pos)
    else:
        ans += 1

print(ans)


Measured memory_bytes: 134360
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <deque>
using namespace std;

deque<char> d[2];
bool query() {
	string s1, s2;
	int n = d[0].size();
	for(int i = 0; i < n; i++) {
		s1 += d[0][i] == 0 ? '.' : '#';
		s2 += d[1][i] == 0 ? '.' : '#';
	}
	cout << s1 << endl << s2 << endl;
	cout.flush();
	char c;
	cin >> c;
	return c == 'T';
}

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

	int N;
	cin >> N;

	bool right = true;
	while(d[0].size() < N) {
		//cout << "right " << right << endl;
		int idx = -1;
		if(right) {
			d[0].push_back(0);
			d[1].push_back(0);
			idx = d[0].size() - 1;
		}
		else {
			d[0].push_front(0);
			d[1].push_front(0);
			idx = 0;
		}
		bool flag = false;
		for(int j = 0; j < 4; j++) {
			d[0][idx] = j & 1;
			d[1][idx] = j & 2;
			if(query()) {
				flag = true;
				break;
			}
		}
		if(!flag) {
			right = false;
			d[0].pop_back();
			d[1].pop_back();
		}
	}

	assert(query());
}

Measured memory_bytes: 596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int min(int x, int y){return x<y?x:y;}
int main(void){
	char S[101];
	scanf("%s",S);
	char s,U[101];
	int ans=101,l,ok;
	for(int i=0;i<26;i++){
		strcpy(U,S);
		l=strlen(S);
		s = 'a'+i;
		int c=0;
		ok=1;
		for(int j=0;j<l;j++){
			if(U[j]!=s)ok=0;
		}
		while(ok!=1){
			ok=1;
			for(int k=0;k<l-1;k++){
				if(U[k]==s || U[k+1]==s){
					U[k] = s;
				}else{
					ok=0;
				}
			}
			l--;
			c++;
		}
		ans = min(c,ans);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();

		int t[] = new int[n];

		for(int i = 0; i < n; i++){
			t[i] = sc.nextInt();
		}
		Arrays.sort(t);

		int arrive = t[0] + k;
		int ride = 0;
		int num = 1;

		for(int i = 0; i < n; i++){
			if(arrive >= t[i] && t[i] + k >= arrive && ride < c){
				ride++;
			}
			else{
				num++;
				ride = 1;
				arrive = t[i] + k;
			}

//			System.out.println("i = "+i+" num "+num);
		}
		System.out.println(num);
	}
}


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

const int MOD = 1000000007;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void prime_fact(int n, unordered_map<int, int>& out1, unordered_map<int, int>& out2) {
    int i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            out1[i]++;
            n /= i;
        }
        else {
            i++;
        }
    }
    if (n != 1) out1[n]++;

    for (const auto& it : out1) {
        out2[it.first] = max(out2[it.first], it.second);
    }
}

int main() {
    int N;
    cin >> N;
    vector<lint> A(N);
    rep(i, N) cin >> A[i];
    vector<lint> B(N);

    unordered_map<int, int> lc;
    vector<unordered_map<int, int>> A_P(N);

    for (int i = 0; i < N; i++) {
        prime_fact(A[i], A_P[i], lc);
    }

    lint l = 1;
    for (const auto& it : lc) {
        l *= modpow(it.first, it.second);
        l %= MOD;
    }

    lint res = 0;

    rep(i, N) {
        lint t = l;
        t *= modpow(A[i], MOD-2);
        t %= MOD;
        res += t;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <stdio.h>
#include<stdlib.h>
#define N 10000

int main(){
  unsigned short *A, *B;

  int C[N];
  int n, i, j;
  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i = 0;i < N;i++ ){
    C[i] = 0;
  }
  for (i = 0;i < n; i++ ){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  for (i = 1;i < N+1;i++ ){
    C[i] = C[i] + C[i-1];
  }
  for (j = 1;j < n+1;j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for (i = 1;i < n+1;i++ ){
    if ( i < n){ 
    printf("%d ",B[i]);
    }
    else if(i == n){
      printf("%d\n",B[i]);
    }
  }
 
  return 0;
}

Measured memory_bytes: 8460
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
            double dx = arr[2] - arr[0];
            double dy = arr[3] - arr[1];
            Console.WriteLine($"{Math.Sqrt(dx * dx + dy * dy):0.000000000}");
        }
    }
}


Measured memory_bytes: 18364
#include <iostream>
#include <algorithm>
using namespace std;
//_____
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
typedef const int let;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3fLL
#define NIL -1
//_______

int N;
ll dp[102][102];

void floyd()
{
   rep(k,N) {
      rep(i,N) {
         if (dp[i][k] == LINF)continue;
         rep(j,N) {
            if (dp[k][j] == LINF) continue;
            chmin( dp[i][j], dp[i][k] + dp[k][j] );
         }
      }
   }
   return;
}

signed main()
{
   FAST();
   int E, s, t, c;
   cin >> N >> E;

   rep(i,N)rep(j,N)
      dp[i][j] = (i == j) ? 0 : LINF;

   while (E--) {
      cin >> s >> t >> c;
      dp[s][t] = c;
   }

   floyd();

   rep(i, N) if(dp[i][i] < 0) {
      outl("NEGATIVE CYCLE");
      return (0);
   }
   rep(i, N) {
      rep(j, N) {
         if(dp[i][j] == LINF)cout << "INF";
         else cout << dp[i][j];
         cout << (j+1 < N ? ' ' : '\n');
      }
   }
}




Measured memory_bytes: 3276
e_r, e_g, n_r, n_g, n_n = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
none = list(map(int, input().split()))
 
red.sort(reverse=True)
green.sort(reverse=True)
none.sort(reverse=True)

eat_r = red[0:e_r]
eat_g = green[0:e_g]

eat = eat_r + eat_g
eat.sort()

for i in range(len(eat)):
  if len(none) > 0 and eat[i] < none[0]:  
    eat[i] = none.pop(0)

print(sum(eat))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int main(){
  int n,m; cin >> n >> m;
  vector<vector<int>> s(m);
  for(int i = 0; i < m; i++){
    int k; cin >> k;
    for(int j = 0; j < k; j++){
      int a; cin >> a; a--;
      s[i].push_back(a);
    }
  }
  vector<int> p(m);
  for(int i = 0; i < m; i++) cin >> p[i];
  ll ans = 0;
  for(int bit = 0; bit < (1<<n); bit++){
    bool flg = true;
    for(int i = 0; i < m; i++){
      int cnt = 0;
      for(int j: s[i]){
        if(bit & (1<<j)) cnt++;
      }
      if(cnt % 2 != p[i]) flg = false;
    }
    if(flg) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;
const int maxn = 4e6 + 4;
const int inf = (int)1e9;

int main() {
	ios::sync_with_stdio(false);
	ll x, y;
	cin >> x >> y;
	if (x == y)
		return cout << 0 << endl, 0;

	if (abs(x) <= abs(y)) {
		cout << abs(y) - abs(x) + (x < 0) + (y < 0) << '\n';
	}
	else {
		cout << abs(x) - abs(y) + (x > 0) + (y > 0) << '\n';
	}
}


Measured memory_bytes: 256
import java.util.Scanner
import java.util.ArrayList

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val D = sc.nextInt()
    var arraylist = ArrayList<ArrayList<Int>>()
    for(i in 0 until N){
        arraylist.add(ArrayList<Int>())
        for(j in 0 until D){
            arraylist.elementAt(i).add(sc.nextInt())
        }
    }
    var counter = 0
    for(i in 0 until N - 1){
        for(j in i + 1 until N){
           var sum = 0
            for(k in 0 until D) {
                val point_i = arraylist.elementAt(i).elementAt(k)
                val point_j = arraylist.elementAt(j).elementAt(k)
                sum += (point_i - point_j) * (point_i - point_j)
            }
            var element = 1
            while(element * element <= sum){
                if(element * element == sum){
                    counter++
                    break
                }
                element++
            }
        }
    }
    println(counter)


}

Measured memory_bytes: 29468
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N,Q = map(int,input().split())
    AB = [list(map(int,input().split())) for _ in range(N-1)]
    PX = [list(map(int,input().split())) for _ in range(Q)]

    # queryを一個づつ処理すると間に合わない。
    # pxをまとめ上げ、かつ隣接nodeに逐次加算していけばよい
    from collections import deque

    tree = [[] for i in range(N)]
    for a,b in AB:
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    
    score = [0]*N
    for p,x in PX:
        score[p-1]+=x

    queue = deque([0])
    visited = [False]*N
    visited[0] = True

    while queue:
        x = queue.pop()

        for i in tree[x]:
            if not visited[i]:
                queue.append(i)
                score[i]+=score[x]
                visited[i]=True

    print(*score)

if __name__=='__main__':
    main()

Measured memory_bytes: 128084
n,m,*a=map(int,open(0).read().split());c,d=[0,2,5,5,4,5,6,3,7,6],[0]+[-1]*n*9
for i in range(n):
 for j in a:
  if d[i]>=0:d[i+c[j]]=max(d[i+c[j]],d[i]*10+j)
print(d[n])

Measured memory_bytes: 15284
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;

ll dp[111][111111];

int main(){
  ll n,k,a[111];
  cin>>n>>k;
  for(int i=0;i<n;i++)cin>>a[i];
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    ll sum=0;
    for(int j=0;j<=k;j++){
	 sum+=dp[i][j];
	 sum%=p;
	 if(j-a[i]>0){
	   sum=(p+sum-dp[i][j-a[i]-1])%p;
	 }
	 dp[i+1][j]+=sum;
	 dp[i+1][j]%=p;
    }
  }
  cout<<dp[n][k]<<endl;
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<k;j++){
	 cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }
  */
  return 0;
}


Measured memory_bytes: 87296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define EACH(e,v) for(auto& e:v)
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(),(v).rend())
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
#define UNIQUE(v) SORT(v);(v).erase(unique(ALL(v)),(v).end())
template<typename A,typename B> inline bool chmax(A &a,const B &b){if(a<b){a=b;return 1;}return 0;}
template<typename A,typename B> inline bool chmin(A &a,const B &b){if(a>b){a=b;return 1;}return 0;}

int N, M;
vector<int> job[100100];

signed main() {

    cin >> N >> M;

    // job.resize(N);
    REP(i, N) {
        int A, B;
        cin >> A >> B;
        job[A].emplace_back(B);
    }

    REP(i, 100100) RSORT(job[i]);

    ll res = 0;

    priority_queue<int> pq;
    FOR(i, 1, M + 1) {
        EACH(e, job[i]) pq.push(e);
        if (pq.size() == 0) continue;
        res += pq.top();
        pq.pop();
    }

    cout << res << endl;

}


Measured memory_bytes: 5632
h,w=map(int,input().split())
s = [[0]*(w+2)]
for i in range(h):
    s.append([0]+list(input())+[0])
s.append([0]*(w+2))

c = 0
b = 0

def sirabe(t,i,j):
    if t[i-1][j] != "#" and t[i][j-1] != "#" and t[i+1][j] != "#" and t[i][j+1] != "#":
        return False
    else:
        return True


for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if sirabe(s,i,j):
                continue
            else:
                c = 1
                break
    if c == 1:
        break


if c == 0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let (n, k) = {
    let tmp: Vec<u64> = read_vec();
    (tmp[0], tmp[1])
  };
  let mut h: Vec<u64> = read_vec();

  let mut ans = 0;
  for i in h {
    if i >= k { ans+=1; }
  }

  println!("{}", ans);

}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=int(a);i<=int(b);i++)
#define ROF(i,a,b) for(int i=int(b);i>=int(a);i--)
#define pb push_back
#define pq priority_queue
#define ps push
#define x first
#define y second
using namespace std;
int n;
string in;
int main(){
    cin>>n>>in;
    if(n<3200) cout<<"red";
    else cout<<in;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d\n", &N)

	F := [100][10]int{}
	for i := 0; i < N; i++ {
		for j := 0; j < 10; j++ {
			var f int
			fmt.Scan(&f)
			F[i][j] = f
		}
	}
	P := [100][11]int{}
	for i := 0; i < N; i++ {
		for j := 0; j < 11; j++ {
			var f int
			fmt.Scan(&f)
			P[i][j] = f
		}
	}
	max := int(-1e10)
	for i := 1; i < 1<<10; i++ {
		sum := 0
		for j := 0; j < N; j++ {
			cnt := 0
			for k := uint(0); k < 10; k++ {
				fl := (i >> k) & 1
				if fl == 0 {
					continue
				}
				fi := F[j][k]
				if fi == 1 {
					cnt++
				}
			}
			p := P[j][cnt]
			sum += p
		}
		if sum > max {
			max = sum
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string str;
bool check(string t){
	for(int i=0;i<t.size();i++)
	if(t[i]!=t[t.size()-i-1])return false;
	return true;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>str;
	int len=str.size();
	if(check(str)&&check(str.substr(0,(len-1)/2))&&check(str.substr((len+1)/2,(len-1)/2)))cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G();
		int A = I[0] - 1, B = I[1] - 1;
		var map = new bool[100, 100];
		for (var i = 0; i < 100; i++) for (var j = 50; j < 100; j++) map[i, j] = true;
		for (var j = 0; B > 0 && j <= 48; j += 2) for (var i = 1; B > 0 && i <= 99; i += 2) { map[i, j] = true; B--; }
		for (var j = 99; A > 0 && j >= 51; j -= 2) for (var i = 1; A > 0 && i <= 99; i += 2) { map[i, j] = false; A--; }
		WriteLine("100 100");
		for (var i = 0; i < 100; i++)
		{
			for (var j = 0; j < 100; j++) Write(map[i, j] ? '#' : '.');
			WriteLine();
		}
	}
}


Measured memory_bytes: 13376
def main():
  N, *A = map(int, open(0).read().split())
  A.sort()

  if N % 2:
    array1 = [-2] * (N // 2) + [1] * 2 + [2] * (N // 2 - 1)
    array2 = [-2] * (N // 2 - 1) + [-1] * 2 + [2] * (N // 2)
  
    ret1 = 0
    ret2 = 0
    for i, j, k in zip(A, array1, array2):
      ret1 += i * j
      ret2 += i * k
    ret = max(ret1, ret2)

  else:
    array1 = [-2] * (N // 2 - 1) + [-1] + [1] + [2] * (N // 2 - 1)
  
    ret = 0
    for i, j in zip(A, array1):
      ret += i * j
  
  print(ret)

  
if __name__=="__main__":
  main()


Measured memory_bytes: 14452
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N=100005;
const int MOD=1e9+7;
 

// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
 
int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
*/

int n;
cin>>n;
for(int i=-1000;i<=1000;i++)
{
	for(int j=-1000;j<=1000;j++)
	{
		if(i*i*i*i*i-j*j*j*j*j==n)
		{
		cout<<i<<" "<<j;
		return 0;
	    }
	}
}






}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main(){
  int n;
  cin >>n;
  int dp[100010];
  rep(i,100010)dp[i]=i;
  
  for(int i=1;i<=100000;i++){
    int p=1;
    while(p<=i){
      chmin(dp[i],dp[i-p]+1);
      p*=6;
    }
    int g=1;
    while(g<=i){
      chmin(dp[i],dp[i-g]+1);
      g*=9;
    }
  }

  cout << dp[n] << endl;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, k;
    cin >> n >> k;

    vector a(n, 0L);
    for (auto&& aa : a) {
        cin >> aa;
        --aa;
    }

    vector b{0L};
    unordered_map<int64_t, int64_t> um{{0L, 0L}};
    for (int64_t i = 0, c = 0;; ++i) {
        c = a[c];

        if (i + 1 == k) {
            cout << c + 1 << endl;
            return 0;
        }

        if (um.count(c)) {
            auto p = i + 1 - um[c];
            k = (k - um[c]) % p + um[c];
            cout << b[k] + 1 << endl;
            return 0;
        }

        b.push_back(c);
        um[c] = i + 1;
    }
}

Measured memory_bytes: 13088
//高知能系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 INTINF 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 tmp;
	bool ch = false;
	string s;
  	cin >> s;
  	int n = s.size();
  	REP(i, n-1){
      if(s[i]==s[i+1]){
        ch = true;
        cout << i+1 << " " << i+1+1 << endl;
        break;
      }
    }
  	if(!ch){
      REP(i,n-2){
        if(s[i]==s[i+2]){
          ch = true;
          cout << i+1 << " " << i+2+1 << endl;
          break;
        }
      }
    }
  	if(!ch) cout << "-1 -1" << endl;
}


Measured memory_bytes: 3684
#include<cstdio>
#include<queue>
using namespace std;

const int INF = 10000;
const int MAX_H = 50;
const int MAX_W = 50;

typedef pair<int, int> P;

char maze[MAX_H][MAX_W + 1];
int H, W;

int d[MAX_H][MAX_W];

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

int bfs(){
	queue<P> que;
	for (int i = 0; i < H; ++i){
		for (int j = 0; j < W; ++j) d[i][j] = INF;
	}
	que.push(P(0,0));
	d[0][0] = 0;

	while(que.size()){
		P p = que.front();
		que.pop();
		if(p.first == H - 1 && p.second == W - 1) break;
		for (int i = 0; i < 4; ++i)	{
			int nx = p.first + dx[i], ny = p.second + dy[i];

			if(0 <= nx && nx < H && 0 <= ny && ny < W && maze[nx][ny] != '#' && d[nx][ny] == INF){
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[H - 1][W - 1];
}

int main(){
	scanf("%d %d", &H, &W);
	int white = 0;
	for (int i = 0; i < H; ++i)	{
		for (int j = 0; j < W; ++j)	{
			if(j == 0)
				scanf("\n");
			scanf("%c", &maze[i][j]);
			if(maze[i][j] == '.')
				white += 1;
		}
	}
	int distance = bfs();
	if(distance == INF)
		printf("-1\n");
	else
		printf("%d\n", white - distance - 1);
	return 0;
}

Measured memory_bytes: 256
(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
    b.append(int(input()))

for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 P = pair<int,int>;
//Write From this Line

int main()
{
	int n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
const int MAXN=105;
int a[MAXN]; 
int main () {
    int n;
    scanf ("%d",&n);
    for (int i=0;i<n;i++) {
    	scanf ("%d",&a[i]);
	}
	printf ("%d",a[0]);
	for (int i=1;i<n;i++) {
		printf (" %d",a[i]);
	}
	printf ("\n");
	for (int i=1;i<n;i++) {
		int v=a[i];
		int j=i-1;
		while (j>=0&&a[j]>v) {
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		printf ("%d",a[0]);
		for (int k=1;k<n;k++) {
			printf (" %d",a[k]);
		}
		printf ("\n");
	}
    return 0;
}


Measured memory_bytes: 2716
import scala.io.Source.stdin

object Main {
  def main(args: Array[String]) = {
    val list = stdin.getLines().map { _.toInt }.buffered
    val n = list.next()
    val r0 = list.next()
    val r1 = list.next()
    var max = r1 - r0
    var min = if(r0 > r1) r1 else r0
    for( m <- list ) {
      if( max < m - min) {
        max = m - min
        if( min -m > 0 )
          min = m
      }
      else if( min - m > 0 ) {
        min = m
      }
    }
    println(max)
  }
}

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

using namespace std;
typedef long long int lli;

lli solve(lli a, lli b) {
    lli multi = a*b;
    if (a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

    lli surplus = a%b;
    while (surplus != 0) {
        a = b;
        b = surplus;
        surplus = a % b;
    }
    return multi/b;
}

int main() {
    lli a,b;
    cin >> a >> b;
    cout << solve(a,b);
}


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

using namespace std;

int N, Q;
vector< int > g[100000];
vector< int > query[100001];
int sz[100000];

int lca[100000];
bool buf[100000];

int sub(int idx)
{
  sz[idx] = query[idx].size();
  for(auto &to : g[idx]) sz[idx] += sub(to);
  return (sz[idx]);
}

void dfs(int idx, bool keep)
{
  if(g[idx].empty()) {
    if(keep) for(int &v : query[idx]) buf[v] = true;
    return;
  }

  int heavy = g[idx][0];
  for(auto &to : g[idx]) if(sz[to] > sz[heavy]) heavy = to;
  if(sz[heavy] <= query[idx].size()) heavy = idx;
  for(auto &to : g[idx]) if(heavy != to) dfs(to, false);

  if(idx != heavy) {
    dfs(heavy, true);
    query[idx].swap(query[heavy]);
  } else {
    for(int &v : query[idx]) buf[v] = true;
  }

  for(auto &to : g[idx]) {
    for(int &v : query[to]) {
      if(buf[v]) lca[v] = idx;
    }
    for(int &v : query[to]) {
      if(~lca[v]) continue;
      buf[v] = true;
      query[idx].push_back(v);
    }
  }

  if(!keep) {
    for(auto &v : query[idx]) buf[v] = false;
  }
}

int main()
{
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    int K;
    scanf("%d", &K);
    while(K--) {
      int U;
      scanf("%d", &U);
      g[i].push_back(U);
    }
  }
  scanf("%d", &Q);

  memset(lca, -1, sizeof(lca));

  for(int i = 0; i < Q; i++) {
    int U, V;
    scanf("%d %d", &U, &V);
    if(U == V) {
      lca[i] = V;
    } else {
      query[U].push_back(i);
      query[V].push_back(i);
    }
  }

  sub(0);
  dfs(0, false);
  for(int i = 0; i < Q; i++) {
    printf("%d\n", lca[i]);
  }
}

Measured memory_bytes: 22836