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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.next();
        long cnt1 = 0;
        long cnt2 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0') {
                cnt1++;
            }
            if (s.charAt(i) == '1') {
                cnt2++;
            }
        }
        long ans = 2 * Math.min(cnt1, cnt2);
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

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

signed main(){
	string s,t;
	cin>>s>>t;
	int d[26][26]={},p[26][26]={};
	r(i,s.size()){
		d[s[i]-'a'][t[i]-'a']=1;
		p[t[i]-'a'][s[i]-'a']=1;
	}
	r(i,26){
		int c=0,e=0;
		r(j,26){
			if(d[i][j])c++;
			if(p[i][j])e++;
		}
		if(c>=2||e>=2){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;

ll N;
ll L[100000 + 10], R[100000 + 10];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> L[i] >> R[i];
	
	L[N] = 0, R[N] = 0;
	N++;

	sort(L, L + N, greater<ll>());
	sort(R, R + N);

	ll ans = 0;
	ll rside = 0, lside = 0;
	for (int i = 0; i < N; i++) {
		rside += L[i];
		lside += R[i];
		ans = max(ans, rside - lside);
	}
	cout << 2LL * ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    int ans = (x-a)/b;
    cout<<x-a-(ans*b)<<endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int sp[100010][33];


void mainmain(){
	int n;
	cin>>n;
	vint v(n);
	rep(i,n) cin>>v[i];
	ll L;
	cin>>L;
	rep(i,n){
		rep(j,33){
			sp[i][j] = -1;
		}
	}
	rep(i,n) sp[i][0] = i;
	queue<int> q;
	int p = 0;
	rep(i,n){
		while(v[i]-v[p]>L){
			sp[p][1] = i-1;
			p++;
		}
	}
	rep(i,p,n) sp[i][1] = n-1;
	rep(i,2,33){
		rep(j,n){
			sp[j][i] = sp[sp[j][i-1]][i-1];
		}
	}
	int Q;
	cin>>Q;
	rep(_, Q){
		int a,b;
		cin>>a>>b;
		a--,b--;
		if(a>b) swap(a,b);
		ll ans = 0;
		for(int i=32; i>=1; i--){
			if(sp[a][i]>=b) continue;
			ans += (1<<(i-1));
			a = sp[a][i];
		}
		if(a<b) ans++;
		cout<<ans<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

typedef long long ll;

int ct=0;

int gcd(int a,int b){
	if(b==0)return a;
	ct++;
	return gcd(b,a%b);
}

int main(){
	int x,y;
	while(1){
		scanf("%d%d",&x,&y);
		if(x==0 && y==0)break;
		if(x<=y){
			int tmp=x;
			x=y;
			y=tmp;
		}
		ct=0;
		int ans=gcd(x,y);
		cout<<ans<<" "<<ct<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
s=gets.chomp.split("").map(&:to_s)
v=gets.chomp.split("").map(&:to_s)

count=Array.new(v.length){0}
for i in 0..(s.length-v.length)
    vv=s[i..i+v.length-1]

    check=0
    for j in 0..vv.length-1
        if vv[j]==v[j]
            check+=1
        end
        
    end
    count[i]=check
  
end
p v.length-count.max

Measured memory_bytes: 14416
#include "bits/stdc++.h"
using namespace std;
const int N = 1e4 + 4;
int n , m;
char str[N];
int main(){
	scanf("%d %d" , &n , &m);
	scanf("%s" , str + 1);
	for(int i = 1 ; i <= n ; ++i){
		if(!isdigit(str[i])){
			printf("No\n");
			return 0;
		}
	}
	if(str[n + 1] != '-'){
		printf("No\n");
		return 0;
	}
	for(int i = n + 2 ; i <= n + m + 1 ; ++i){
		if(!isdigit(str[i])){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll X, Y, A, B, C;

int main()
{
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C), sum(X + Y + C);
    rep(0, i, A)
    {
        cin >> p.at(i);
    }
    rep(0, i, B)
    {
        cin >> q.at(i);
    }
    rep(0, i, C)
    {
        cin >> r.at(i);
    }
    sort(all(p));
    reverse(all(p));
    sort(all(q));
    reverse(all(q));
    sort(all(r));
    reverse(all(r));
    rep(0, i, X)
    {
        sum.at(i) = p.at(i);
    }
    rep(0, i, Y)
    {
        sum.at(i + X) = q.at(i);
    }
    rep(0, i, C)
    {
        sum.at(i + X + Y) = r.at(i);
    }
    sort(all(sum));
    reverse(all(sum));
    ll ans = 0;
    rep(0, i, X + Y)
    {
        ans += sum.at(i);
    }
    cout << ans << endl;
}

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

const int maxn = 2e6 + 3,
          mod = 1e9 + 7;
ll f[maxn];

ll iv(ll a, ll b = mod) {
    return a > 1 ? b - iv(b % a, a) * b / a : 1;
}

ll modExp(ll b, int e) {
    ll r = 1;
    for (; e; e >>= 1, b = b * b % mod) {
        if (e & 1) r = r * b % mod;
    }
    return r;
}

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

    f[0] = 1;
    for (int i = 1; i < maxn; i++) {
        f[i] = f[i - 1] * i % mod;
    }

    int k;
    string s;
    cin >> k >> s;

    ll ans = 0;
    for (int i = 0; i <= k; i++) {
        ans = (ans +
            f[sz(s) + i - 1] *
            iv(f[sz(s) - 1]) % mod *
            iv(f[i]) % mod *
            modExp(25, i) % mod *
            modExp(26, k - i)
        ) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 19860
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int tc,ac,K;


int main()
{
	scanf("%d %d %d", &tc, &ac, &K);
	for (int i = 0; i < K; i++)
	{
		if (i % 2 == 0)
		{
			if (tc % 2 == 0)
			{
				tc = tc / 2;
				ac = tc + ac;
			}
			else
			{
				tc = (tc - 1) / 2;
				ac = tc + ac;
			}
		}
		else if (i % 2 == 1)
		{
			if (ac % 2 == 0)
			{
				ac = ac / 2;
				tc = tc + ac;
			}
			else
			{
				ac = (ac - 1) / 2;
				tc = ac + tc;
			}
		}
	}
	printf("%d %d", tc, ac);

}

Measured memory_bytes: 256
import sys

k=int(input())

k7=7%k
if k7==0:
    print(1)
    sys.exit()

fi=k7
for i in range(1,k):
    fi=(fi+7*pow(10,i,k))%k
    if fi==0:
        print(i+1)
        sys.exit()
print(-1)


Measured memory_bytes: 63436
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int x = Integer.parseInt(scanner.nextLine());
    int a = Integer.parseInt(scanner.nextLine());
    int b = Integer.parseInt(scanner.nextLine());
    System.out.println((x-a)%b);
  }
}

Measured memory_bytes: 23124
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int N = sc.nextInt();
    int[] h = new int[N];

    int max = 0;
    for (int i=0; i<N; i++) {
      h[i] = sc.nextInt();
      if (h[i] > max) max = h[i];
    }

    int count = 0;
    for (int t=0; t<max; t++) {
      if (h[0] > 0) count++;
      for (int i = 1; i < N; i++) {
        if (h[i-1] <= 0 && h[i] > 0) {
          count++;
        }
      }
      for (int i=0; i<N; i++) {
        h[i]--;
      }
    }

    System.out.println(count);

  }
}

Measured memory_bytes: 23252
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main() {
    ll n;
    cin >> n;
    ll a[3*n];
    rep(i,3*n) cin >> a[i];
    sort(a,a+3*n);
    ll ans=0;
    for(ll i=n;i<3*n-1;i+=2) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 2560
import sys

def main():
  s = input()
  n = len(s)
  x, y = map(int, input().split())
  
  move = [0]
  for i in range(n):
    if s[i] == "F":
      move[-1] += 1
    else:
      move.append(0)
  
  move_x = move[2::2]
  move_y = move[1::2]
  move_a = move[0]
  
  for start, lis in zip([x-move_a, y], [move_x, move_y]):
    move_range = sum(lis)
    if abs(start) > move_range:
      print("No")
      sys.exit()
    
    dp = 2**move_range
    for value in lis:
      dp = (dp >> value)|(dp << value)
    if not (dp>>(move_range+start))&1:
      print("No")
      sys.exit()
  
  print("Yes")
  
  
if __name__ == "__main__":
  main()

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

//Compiler version g++ 6.3.0

int main()
{
    int n,x;
    cin >> x >> n;
    int arr[n];
    map <int,bool> mp;
    int great = 0,tmp,mini = 1000001,ans = x;
    for(int i = 0; i < n; i++){
      cin >> arr[i];
      great = max(great,arr[i]);
      mp[arr[i]] = true;
    }
    if(n == 0)great = -2;
    for(int i = 0; i <= great + 1; i++){
      if(mp[i]) continue;
      
      int tmp = abs(i - x);
      
      if(tmp < mini){
        mini = tmp;
        ans = i;
      }
      if(tmp == mini){
        if(i < ans)ans = i;
      }
    }
    /*if(mp[great]){
      int t = great + 1;
      if(abs(t - x) < mini)ans = t;
    }*/
    cout << ans;
    
    return 0;
    
}

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

bool check(int i, vector<int> &s, vector<int> &c){
    bool ans = true;
    string S;
    S = to_string(i);
    for(int j=0; j<s.size(); j++){
        if(S.at(s.at(j))-'0' != c.at(j)){
            ans = false;
            break;
        }
    }
    return ans;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> s(m),c(m);
    for(int i=0; i<m; i++){
        cin >> s.at(i) >> c.at(i);
        s.at(i)--;
    }
    int start,end;
    if(n==1) start=0;
    else start = pow(10,n-1);
    end = pow(10,n)-1;
    for(int i=start; i<=end; i++){
        if(check(i, s, c)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 4096
def main():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())
    charge = 0
    charge1 = 0
    charge2 = 0
    charge3 = 0
    if K <= N:
        charge1 += K*X
        charge2 += (N-K)*Y
        charge = charge1 + charge2
    else:
        charge3 += N*X
        charge = charge3
    print(charge)
main()


Measured memory_bytes: 3060
#coding:utf-8


class Point
	def initialize(args)
		@x,@y = args[0],args[1]
	end

	def x
		@x
	end

	def y
		@y
	end
end

class Vector
	def initialize(x,y)
		@x,@y = x,y
	end
	def x
		@x
	end
	def y
		@y
	end
end

#外積を求める
def cross(a,b)
	a.x*b.y - a.y*b.x
end


while (line=gets) != nil do
	data = line.chomp.split(',').map(&:to_f)
	a = Point.new(data[0,2])
	b = Point.new(data[2,2])
	c = Point.new(data[4,2])
	d = Point.new(data[6,2])
	#p data

	ab = Vector.new(b.x-a.x, b.y-a.y)
	bc = Vector.new(c.x-b.x, c.y-b.y)
	cd = Vector.new(d.x-c.x, d.y-c.y)
	da = Vector.new(a.x-d.x, a.y-d.y)
	
	ans =  cross(ab,bc)* cross(bc,cd)*cross(cd,da)*cross(da,ab)
	if ans>0 then
		puts "YES"
	elsif ans<=0 then
		puts "NO"
	end

end

Measured memory_bytes: 6148
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format, std.numeric;

void main(string[] args)
{
    long h, n;
    readf("%d %d\n", &h, &n);
    long as = readln.strip.split.to!(long[]).sum;
    if (h <= as)
    {
        writeln("Yes");
    }
    else
    {
        writeln("No");
    }
}


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const N=2e5+50;
ll INF=0x3f3f3f3f;
ll n,k,x,cnt1=0,cnt2=0,cnt3=0;
ll a[N],b[N];
bool cmp(ll a,ll b) {  return a>b;  }
ll check1(ll m)
{
    ll p=1,ans=0;
    for(int i=1;i<=cnt2;i++)
    {
        while( a[p]*b[i] > m&&p<=cnt1 )
            p++;
        ans+=(cnt1-p+1);
    }
   // cout<<ans<<endl;
    return ans;
}
ll check(ll m)
{
    ll p=cnt1,ans=0,ans1=0;
    for(int i=1;i<=cnt1;i++)
    {
        while(a[i]*a[p]>m&&p>=1)
            p--;
        ans+=(p);
        if(p>=i)
            ans--;
     //   cout<<i<<" "<<p<<endl;
    }
    p=cnt2;
    for(int i=1;i<=cnt2;i++)
    {
        while(b[i]*b[p]>m&&p>=1)
            p--;
        ans1+=(p);
        if(p>=i)
            ans1--;
       // cout<<i<<" "<<p<<endl;
    }
    ans=ans/2+ans1/2;
   // cout<<ans<<endl;
    return ans;
}
int main()
{
    //cout<<(-11)/2<<endl;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x>0)
            a[++cnt1]=x;
        else
            if(x<0)
                b[++cnt2]=x;
            else
                ++cnt3;
    }
  //  cout<<cnt1<<" "<<cnt2<<" "<<cnt3<<endl;
    ll l,r,mid;
    if(cnt1*cnt2>=k)///负数区
    {
        sort(a+1,a+1+cnt1);
        sort(b+1,b+1+cnt2);
        l=-1e18+5,r=-1;
        while(l < r )
        {
            mid=(l+r-1)/2;
            if( check1(mid) >= k)
                r=mid;
            else
                l=mid+1;
          //  cout<<l<<" "<<r<<" "<<mid<<endl;
        }
        cout<<l<<endl;
    }
    else
    {
        k-=cnt1*cnt2;
        if( k <= ((n-cnt3)+(n-1))*cnt3/2 ) ///0
        {
            cout<<"0"<<endl;
            return 0;
        }
        else///正数
        {
            k-=((n-cnt3)+(n-1))*cnt3/2;
         //   cout<<k<<endl;
            for(int i=1;i<=cnt2;i++)
                b[i]*=-1;
            sort(b+1,b+1+cnt2);
            sort(a+1,a+1+cnt1);
            // cout<<"**"<<check(ll(448283280358331062))<<endl;
           // cout<<"**"<<check(ll(448283280358331064))<<endl;
           // cout<<"**"<<check(ll(448283280358331066))<<endl;
            l=1,r=1e18+5;
            while(l<r)
            {
                mid=(l+r)/2;
                if( check(mid)>=k )
                {
                    r=mid-1;
                }
                else
                    l=mid+1;
               // cout<<l<<" "<<r<<" "<<mid<<endl;
            }
            ll i;
            for(i=l+10;;i--)
            {
                if(check(i)<k)
                    break;
            }
            cout<<i+1<<endl;

        }
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep( i, n ) for( int ( i ) = 0; ( i ) < ( n ); ( i )++ )
#define repr( i, n ) for( int ( i ) = ( n ); ( i ) >= 0; ( i )-- )
#define FOR( i, m, n ) for( int ( i ) = ( m ); ( i ) < ( n ); ( i )++ )
#define all( x ) ( x ).begin(), ( x ).end()
typedef long long lint;
using namespace std;

int main( void ){
	
	int a;
	int b;
	bool f = false;
	
	cin >> a >> b;
	
	rep( i, 2){
		if ( ( i + 1 ) * a * b % 2 ){
			f = true;
		}
	}
	if( f == true){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    long long x;

    cin >> x;

    long long ans = 100;

    for(int i = 1;; i++){
        ans += floor((long double)0.01 * ans);

        if(ans >= x){
            cout << i << "\n";
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3624
//package Contest090;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int first = sc.nextInt(),last = sc.nextInt();
        int cnt =0;
        for(int i = first;i<=last;i++)
        {
            String str1 = String.valueOf(i);
            StringBuilder sb = new StringBuilder(str1);
            sb = sb.reverse();
            String temp = sb.toString();
            //out.println(str1+" "+temp);
            if(str1.equals(temp))
                cnt++;

        }
        out.println(cnt);

        out.flush();
    }

}


Measured memory_bytes: 38356
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<deque>
using namespace std;
typedef long long int ll;

#define MAX_A 1000000

int main(){

    int n;
    cin >> n;
    vector<int> a(MAX_A,0);
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }

    int button = 1;
    for(int i = 1;i <= n;i++){

        if(button == 2){
            cout << i-1 << endl;
            return 0;
        }
        button = a[button];

    }

    cout << "-1" << endl;



    return 0;

}

Measured memory_bytes: 4096
# AGC033A - Darker and Darker
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.distance_transform_cdt.html
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        1 1 1    2 1 2
        1 0 1 -> 1 0 1
        1 1 1    2 1 2
    """
    _, _, *A = open(0).read().split()
    B = tuple(tuple(1 if i == "." else 0 for i in a) for a in A)
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Measured memory_bytes: 46848
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	printf("%d\n", std::min(n*a, b));
	return 0;	
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    long long int sum=0,i,n,T,t[200001]={};
    
    scanf("%lld %lld",&n,&T);
    
    for( i = 0; i < n; i++){
        scanf("%lld",&t[i]);
        
        if( t[i] <= T ){
            sum = t[i];
        }
        if( t[i] > T ){
            if(t[i]-t[i-1]<T){
                sum = sum + (t[i]-t[i-1]);
            }
            else sum += T;
        }
    }
    
    printf("%lld\n",sum+T);
    
    return 0;
}

Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;


import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			for(int i = 0; i < 5; i++) {
				final int x = sc.nextInt();
				
				if(x == 0) {
					System.out.println((i + 1));
					return; 
				}
			}
			
			
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32556
#abc127 c
n,m=map(int,input().split())
l_max=0
r_mini=n
for i in range(m):
    l,r=map(int,input().split())
    l_max=max(l_max,l)
    r_mini=min(r_mini,r)
ans=r_mini-l_max+1
if ans<0:
    ans=0
print(ans)

Measured memory_bytes: 3060
function main(inp) {
  var inps = inp.split(" ");
  var a = parseInt(inps[0]);
  var b = parseInt(inps[1]);
  
  if (( a * b ) % 2 === 1) {
      console.log("Odd");
  }else{
    console.log("Even");
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
a=input()
n=len(a)

for i in range(1<<n):
    sum=0
    st=''
    for j in range(n):

        if i & (1 <<j):sum +=int(a[j]); st+= '+' + a[j] 
        else: sum -=int(a[j]); st+= '-' + a[j]

    if sum==7:break

print(st[1:] + '=7')

Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    k=II()
    run=list(range(1,10))
    cur=list(range(1,10))
    while len(run)<k:
        nxt=[]
        for r in cur:
            e=r%10
            nxt.append(r*10+e)
            run.append(r*10+e)
            if e!=0:
                nxt.append(r*10+e-1)
                run.append(r*10+e-1)
            if e!=9:
                nxt.append(r*10+e+1)
                run.append(r*10+e+1)
        cur=nxt
    run.sort()
    print(run[k-1])

main()

Measured memory_bytes: 19484
#include<bits/stdc++.h>
#define fr(i,n) for(ll i=0;i<n;i++)
#define ll long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=0;i<n-1;i++)
	cin>>a[i];
	map<int,int>m;
	for(int i=0;i<n-1;i++)
	{
		m[a[i]]++;
	} 
	for(int i=1;i<=n;i++)
	cout<<m[i]<<endl;
}


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

long long gcd(long long A,long long B) {
  if (A>B) {
    swap(A,B);
  }
  if (B % A == 0) {
    return A;
  }
  return gcd(A,B%A);
}

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

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

int main() {
	int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;

	int mixedAns = 0, sugarAns = 0; double cnc = -1.0;
	for (int ai = 0; ai <= f; ai += 100 * a) {
		for (int bi = 0; ai + bi <= f; bi += 100 * b) {
			int water = ai + bi; if (water == 0)continue;
			for (int ci = 0; water + ci <= f; ci += c) {				
				for (int di = 0; water + ci + di <= f; di += d) {
					int sugar = ci + di;
					double nowCnc = 100.0 * sugar / (water + sugar);
					int limitSugar = water / 100 * e;
					if (sugar <= limitSugar && nowCnc > cnc) {
						cnc = nowCnc; mixedAns = water + sugar; sugarAns = sugar;
					}
				}
			}
		}
	}
	cout << mixedAns << ' ' << sugarAns << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  long long X, Y;
  cin >> X >> Y;
  int ret = 0;
  long long num = X;
  while(num <= Y){
    num *= 2;
    ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin>>n;
   int A[100000],B[100000],C[100000];
   for(int i=0;i<n;i++){
      cin>>A[i];
   }
   for(int i=0;i<n;i++){
     cin>>B[i];
   }
   for(int i=0;i<n-1;i++){
     cin>>C[i];
   }
   int sum=0;
   for(int i=0;i<n;i++){
      int l=A[i];
      int l1=A[i+1];
      if(l1-l==1){
         sum=sum+B[l-1]+C[l-1];
      }
      else{
        sum=sum+B[l-1];
      }
   }
   cout<<sum<<endl;
}

Measured memory_bytes: 256
using System;

namespace ABC073_D___joisino_s_travel
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = read[0];
            var M = read[1];
            var R = read[2];

            var ri = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var distance = new long[N + 1, N + 1];
            for (int i = 0; i < N + 1; i++) for (int j = 0; j < N + 1; j++) distance[i, j] = long.MaxValue;
            for (int i = 0; i < N + 1; i++) distance[i, i] = 0;

            for (int i = 0; i < M; i++)
            {
                read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                distance[read[0], read[1]] = read[2];
                distance[read[1], read[0]] = read[2];
            }

            for (int via = 1; via < N + 1; via++)
                for (int to = 1; to < N + 1; to++)
                    for (int from = 1; from < N + 1; from++)
                    {
                        if (distance[to, via] == long.MaxValue || distance[via, from] == long.MaxValue) continue;
                        distance[from, to] = Math.Min(distance[from, to], distance[from, via] + distance[via, to]);
                    }

            var distanceR = new long[R, R];
            for (int i = 0; i < R; i++) for (int j = 0; j < R; j++) distanceR[i, j] = distance[ri[i], ri[j]];

            var dp = new long[1 << R, R];
            for (int i = 0; i < (1 << R); i++) for (int j = 0; j < R; j++) dp[i, j] = long.MaxValue;
            for (int i = 0; i < R; i++) dp[1 << i, i] = 0;

            for (int bit = 1; bit < (1 << R); bit++)
                for (int last = 0; last < R; last++)
                {
                    if ((bit & (1 << last)) == 0) continue;
                    for (int prev = 0; prev < R; prev++)
                        if (((1 << prev) & (bit - (1 << last))) > 0) dp[bit, last] = Math.Min(dp[bit, last], dp[bit - (1 << last), prev] + distanceR[last, prev]);
                }

            long result = long.MaxValue;
            for (int i = 0; i < R;i++)result = Math.Min(result, dp[(1 << R) - 1, i]);
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 15328
#include<bits/stdc++.h>
#include<cstdio>
#include<numeric>
#include<iostream>
using namespace std;

 long long Gcd(long long m,long long n)
{
	long long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

 long long Lcm(long long m,long long n)
{
	return m * n / Gcd(m,n); 
}

int main(void)
{
    long long a,b,c,d;
    long long i,j,k=0;
    long long bad=0;

    cin >> a >> b >> c >> d;
    a--;

    long long f=Lcm(c,d);
    long long ans=(b/c + b/d - b/f)-(a/c + a/d - a/f);

    a++;
    cout << (b-a+1)-ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    set<int> from, to;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        if(a == 1) from.insert(b);
        if(b == n) to.insert(a);
    }

    for(int x : from){
        if(to.find(x) != to.end()){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 9600
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, std::vector<long long> a){

    i64 ans = -INF;
    vector<vector<i64>> dp(n, vector<i64>(10, -INF));
    dp[0][0] = a[0];
    dp[1][0] = a[1];
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 10; ++j){
            int perf = (i / 2) + 1;
            int cnt = perf - j;
            if(cnt == 0)
                chmax(dp[i][j], 0LL);
            if(cnt == 1)
                chmax(dp[i][j], a[i]);
            if(cnt == n / 2)
                chmax(ans, dp[i][j]);
            for(int nex = 2; nex < 10 && i + nex < n; ++nex){
                int nex_idx = i + nex;
                int nex_perf = (i + nex) / 2 + 1;
                int diff = nex_perf - (cnt + 1);
                if(diff >= 10)
                    continue;
                chmax(dp[nex_idx][diff], dp[i][j] + a[nex_idx]);
            }
        }
    }
    cout << ans << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 28312
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
using namespace std;
int dp[101][10001], w[101], v[101], n;
int main() {
	int W;
	cin >> n;
	cin >> W;
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = n; i >= 0; i--) dp[i][W] = 0;
	for (int j = W; j >= 0; j--) dp[n][j] = 0;
	for (int i = n - 1; i >= 0; i--)
		for (int j = W; j >= 0; j--) {
			if (w[i] > j) dp[i][j] = dp[i + 1][j];
			else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
		}
	cout << dp[0][W] << endl;
	return 0;
}

Measured memory_bytes: 7048
N, X = map(int, input().split())
x = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return abs(a)
    return gcd(b, a % b)

new_x = []
for i in x:
    new_x.append(abs(i - X))

if len(x) == 1:
    print(new_x[0])
    exit()
else:
    for i, j in enumerate(new_x):
        if i == 0:
            res = gcd(new_x[0], new_x[1])
        else:
            res = gcd(res, new_x[i])

print(res)

Measured memory_bytes: 14224
x1, y1, x2, y2 = map(int, input().split())

def found_coordinate(x0, y0, x1, y1):
  x = x1 + y0 - y1
  y = y1 + x1 - x0
  return(x, y)

ans1 = found_coordinate(x1, y1, x2, y2)
ans2 = found_coordinate(x2, y2, ans1[0], ans1[1])
print(ans1[0], ans1[1], ans2[0], ans2[1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int L, R; cin >> L >> R;

    if (R - L >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 2018;
    for (int i = L; i <= R; i++) {
        for (int j = i + 1; j <= R; j++) {
            ans = min(ans, (int)((ll)i * j % 2019));
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<cctype>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N;
    ll i;
    cin >> N;
    ll A,B;
    cin >> A >> B;
    string S;
    cin >> S;
    ll a=0,b=0;
    for(i=0;i<N;i++){
        if(S[i]=='a'&&a+b<A+B){cout <<"Yes"<<endl;a++;}
        else if(S[i]=='b'&&a+b<A+B&&b<B){cout << "Yes" <<endl;b++;}
        else cout <<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=501010;
char s[N];
struct Bigint
{
    int a[N],n;
    int& operator [] (const int &x){return a[x];}
    Bigint(){memset(a,0,sizeof(a));n=0;}
    Bigint(char *s){n=strlen(s);for(int i=0;i<n;i++)a[i]=s[n-i-1]-'0';}
    void carry()
    {
        for(int i=0;i<n;i++)
        {
            if(a[i]<=9) continue;
            a[i+1]+=a[i]/10;
            a[i]%=10;
            if(i==n-1) n++;
        }
    }
    Bigint& operator *= (int x){for(int i=0;i<n;i++)a[i]*=x;carry();return *this;}
    int get(){int res=0;for(int i=0;i<n;i++)res+=a[i];return res;}
    void gao(int &sum)
    {
        a[0]+=9;sum+=9;
        for(int i=0;a[i]>9;i++)
        {
            sum-=a[i];sum-=a[i+1];
            a[i+1]+=a[i]/10;a[i]%=10;
            sum+=a[i];sum+=a[i+1];
            if(i==n-1) n++;
        }
    }
} A;
int main()
{
    scanf("%s",s);
    A=s;A*=9;
    int sum=A.get(),k;
    for(k=1;true;k++)
    {
        A.gao(sum);
        if(sum<=9*k&&sum%9==0) break;
    }
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

string s, t;
int dp[3010][3010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s >> t;
  REP(i,SZ(s)) REP(j,SZ(t)) {
    if (s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
    else chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
  }
  int y = SZ(s), x = SZ(t);
  string ans;
  while (!(y==0 && x==0)) {
    if (y>0&&x>0&&dp[y][x]!=dp[y-1][x]&&dp[y][x]!=dp[y][x-1]) {
      ans = string(1, s[y-1]) + ans;
      y--; x--;
    } else {
      if (y==0) x--;
      else if (x == 0) y--;
      else if (dp[y-1][x] < dp[y][x-1]) x--;
      else y--;
    }
  }
  cout << ans << endl;

  return 0;
}

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

class Dice {
  private:
    int *numbers;
  public:
    Dice(int *numbers) {
      this->numbers = numbers;
    }

    int getTop() {
      return numbers[0];
    }
    int getFront() {
      return numbers[1];
    }
    int getRight() {
      return numbers[2];
    }
    int getLeft() {
      return numbers[3];
    }
    int getBack() {
      return numbers[4];
    }
    int getBottom() {
      return numbers[5];
    }

    void roll(char direction) {
      switch (direction) {
        case 'N':
          rollToNorth();
          break;
        case 'S':
          rollToSouth();
          break;
        case 'E':
          rollToEast();
          break;
        case 'W':
          rollToWest();
          break;
      }
    }

    void rollToNorth() {
      swap(numbers[0], numbers[1]);
      swap(numbers[1], numbers[5]);
      swap(numbers[5], numbers[4]);
    }

    void rollToSouth() {
      swap(numbers[0], numbers[4]);
      swap(numbers[4], numbers[5]);
      swap(numbers[5], numbers[1]);
    }

    void rollToEast() {
      swap(numbers[0], numbers[3]);
      swap(numbers[3], numbers[5]);
      swap(numbers[5], numbers[2]);
    }

    void rollToWest() {
      swap(numbers[0], numbers[2]);
      swap(numbers[2], numbers[5]);
      swap(numbers[5], numbers[3]);
    }

    void turnRight() {
      swap(numbers[1], numbers[2]);
      swap(numbers[2], numbers[4]);
      swap(numbers[4], numbers[3]);
    }

    bool equals(Dice other) {
      return getTop() == other.getTop()
        && getFront() == other.getFront()
        && getRight() == other.getRight()
        && getLeft() == other.getLeft()
        && getBack() == other.getBack()
        && getBottom() == other.getBottom();
    }
};

int main() {
  int numbers1[6], numbers2[6];

  for (int i = 0; i < 6; i++) {
    cin >> numbers1[i];
  }
  for (int i = 0; i < 6; i++) {
    cin >> numbers2[i];
  }

  Dice dice1(numbers1);
  Dice dice2(numbers2);

  for (int i = 0; i < 6; i++) {
    if (dice1.equals(dice2)) {
      cout << "Yes" << endl;
      return 0;
    }
    if(i % 2 == 0) {
      dice1.rollToNorth();
    } else {
      dice1.rollToEast();
    }
    for (int i = 0; i < 4; i++) {
      if (dice1.equals(dice2)) {
        cout << "Yes" << endl;
        return 0;
      }
      dice1.turnRight();
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
int main()
{
	int a,b;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		if(a<=8&&b<=8)printf("Yay!\n");
		else printf(":(\n");
	}
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
a1=min(h*(w%3!=0),w*(h%3!=0))
a2=10**6
a3=10**6
for i in range(1,h):
  mx=max(w*i,(w//2)*(h-i),((w+1)//2)*(h-i))
  mn=min(w*i,(w//2)*(h-i),((w+1)//2)*(h-i))
  a2=min(a2,mx-mn)
for i in range(1,w):
  mx=max(h*i,(h//2)*(w-i),((h+1)//2)*(w-i))
  mn=min(h*i,(h//2)*(w-i),((h+1)//2)*(w-i))
  a3=min(a3,mx-mn)
print(min(a1,a2,a3))

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

int main()
{ 
  int a, b, c ;
  cin >> a >> b >> c ;
  if(a + b >= c)
  {
    cout << b + c << endl ;
  }
  else
  {
    cout << b + b + a + 1 << endl ;
  }
  
}

Measured memory_bytes: 256
// 138_D_Ki.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> edge;

void createTree(int targetNode, int parentNode, vector<int> *edges, int* parents, vector<int>* children)
{
	parents[targetNode] = parentNode;

	//枝を探索して、対象ノードに接続しているノードを子に追加（ただし、親は除く）。
	//枝が(親, 子)か(子, 親)かわからないため、両方確認する。
	vector<int> targetChildren;
	for(int child : edges[targetNode])
	{
		if(child != parentNode)	targetChildren.push_back(child);
	}

	children[targetNode] = targetChildren;

	//子に対して再帰
	for (int child : children[targetNode])
	{
		createTree(child, targetNode, edges, parents, children);
	}
}

void addNodesToQueue(int targetNode, queue<int> &nodes, vector<int>* children)
{
	for (int child : children[targetNode])
	{
		nodes.push(child);
	}

	//再帰
	for (int child : children[targetNode])
	{
		addNodesToQueue(child, nodes, children);
	}
}

int main()
{
	//n:ノードの個数
	//q:操作の回数
	int n, q = 0;
	cin >> n >> q;

	//枝
	//a, bどちらが親かわからないため、双方向で保存
	//あとで正確に木を組み立てる
	vector<int> *edges = new vector<int>[n+1];
	for (int i = 1; i < n; i++)
	{
		int a, b = 0;
		cin >> a >> b;

		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	//操作
	//各ノードに直接行う操作を集計しておく
	int* actions = new int[n + 1]();

	for (int i = 0; i < q; i++)
	{
		int p, x = 0;
		cin >> p >> x;

		actions[p] += x;
	}

	//木の組み立て
	int* parents = new int[n + 1]();
	vector<int>* children = new vector<int>[n + 1];
	createTree(1, 0, edges, parents, children);

	//ノードの計算順序決定
	//FIFOでルート（1）から順番に子を追加
	queue<int> nodes;
	nodes.push(1);
	addNodesToQueue(1, nodes, children);

	//カウントを集計
	//部分木をすべて再計算すると計算量がO(nq)となり、時間超過する。
	//直接の親のカウントがわかれば計算できる。
	int* counts = new int[n + 1]();
	while (!nodes.empty())
	{
		int targetNode = nodes.front();
		nodes.pop();

		//自身に対する直接の操作をカウントアップ
		counts[targetNode] += actions[targetNode];

		//直接の親に対するカウントアップを加算
		if (parents[targetNode] > 0)
		{
			counts[targetNode] += counts[parents[targetNode]];
		}
	}

	//答えを表示
	for (int i = 1; i <= n; i++)
	{
		cout << counts[i] << " ";
	}

	return 0;
}


Measured memory_bytes: 58752
import sys
sys.setrecursionlimit(10**7)

n = int(input())
l = [[] for _ in range(n)]
for _ in range(n-1):
  a, b, c = map(int, input().split())
  l[a-1].append((b-1, c))
  l[b-1].append((a-1, c))
q, k = map(int, input().split())
dist = [-1]*n
dist[k-1] = 0
def dfs(v):
  for nv, c in l[v]:
    if dist[nv] == -1:
      dist[nv] = dist[v]+c
      dfs(nv)
dfs(k-1)
for _ in range(q):
  x, y = map(int, input().split())
  print(dist[x-1] + dist[y-1])


Measured memory_bytes: 131632
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int>v(N);
	for (auto&i : v)cin >> i;
	sort(v.begin(), v.end());
	int sum = 0;
	for (int i = 0; i < K; i++)
		sum += v[i];
	cout << sum;
}

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

void BubbleSort( int a[], int N )
{
	int time = 0;
	for( int i = 0 ; i < N ; i++ )
	{
		for( int j = N-1 ; j >= i+1 ; j-- )
		{
			if( a[j] < a[j-1])
			{
			   swap( a[j] , a[j-1] );
			   time++;
			}
			   
		}
	}
	for( int i = 0 ; i < N-1 ; i++ )
	    cout << a[i] << " ";
	cout << a[N-1] << endl;
	cout << time << endl;
}

int main()
{
	int N;
	cin >> N;
	int *A = new int [N];
	for( int i =0; i < N; i++ )
	{
		cin >> A[i];
	}
	BubbleSort( A , N );
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979323846;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> V;
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    V.push_back({a, 1});
  }
  for (int i=0; i<M; i++) {
    int b, c;
    cin >> b >> c;
    V.push_back({c, b});
  }
  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());
  ll num = 0, res = 0;
  for (auto p: V) {
    if (num+p.second<=N) {
      res += p.first*p.second;
      num += p.second;
    }
    else {
      res += p.first*(N-num);
      num = N;
      break;
    }
  }
  cout << res << endl;
  return 0;
}

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


int main(void){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    bool flag = 0;
    for(int i=1;i<=3;i++){
        ans = a*b*i;
        if(ans%2==1){
            flag = 1;
            break;
        }
    }
    if(flag)cout << "Yes" <<endl;
    else cout <<"No" <<endl;
    
    
    return 0;
}













































Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll n, k;
vector<ll> vec;
vector<ll> steps;
vector<bool> visited;

int rec(int i, ll nx) {
  if (k == i) return nx + 1;
  if (visited[nx]) {
    int r = (k - steps[nx]) % (i - steps[nx]);
    int ans = nx;
    rep(i, r) {
      ans = vec[ans];
    }
    ans++;
    return ans;
  } else {
    visited[nx] = true;
    steps[nx] = i;
    return rec(i+1, vec[nx]);
  }
}

int main()
{
  cin >> n >> k;
  vec.resize(n);
  steps.resize(n);
  visited.resize(n);
  rep(i,n) {
    cin >> vec[i];
    vec[i]--;
  }
  cout << rec(0, 0) << endl;
  
  return 0;
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char c[200000];
	cin>>c;
	int s=0;
	for(int i=0;i<strlen(c);i++)
	{
		if(c[i]==c[i+1])
		{
		c[i+1]='1'-c[i+1]+'0';
		s++;
		}
	}
	cout<<s;
}

Measured memory_bytes: 384