akhauriyash/Code-Regression huggingface dataset:
import java.lang.IllegalArgumentException

fun main(args: Array<String>) {
	val (n, m) = readLine()?.split(" ")?.map {it.toInt()} ?: throw IllegalArgumentException()
	
	val friendsUnion = FriendsUnion(n)
	repeat(m) {
		val (a, b) = readLine()?.split(" ")?.map { it.toInt() } ?: throw IllegalArgumentException()
		with(friendsUnion) { addFriends(a, b) }
	}
	println(friendsUnion.maxUnionNumber())
}

class FriendsUnion(private val n: Int, private val rootArray: Array<Int> = Array(n+1) { i -> i }, private val unionNumberArray: Array<Int> = Array(n+1) {1}) {
	fun addFriends(friend1: Int, friend2: Int) {
		//添え字が若い方を親とする
		var (parent, child) = if (friend1 < friend2) Pair(friend1, friend2) else Pair(friend2, friend1)
		//それぞれのrootを探す
		val parentRootIndex = findRoot(parent)
		val childRootIndex = findRoot(child)
		//rootが同じならそのまま
		return if (parentRootIndex == childRootIndex) return else {
			//rootが違うなら子グループを親グループにマージ。
			unionNumberArray[parentRootIndex] += unionNumberArray[childRootIndex]
			unionNumberArray[childRootIndex] = 0
			//子グループのrootの親を、親グループのrootにしておく。
			rootArray[childRootIndex] = parentRootIndex
		}
	}
	
	private fun findRoot(friend: Int): Int {
		//rootが自分だった場合、自分を返す。
		return if (rootArray[friend] == friend) friend else {
			//rootが自分じゃない場合、親がrootか判定した上で、親をrootにする(後々のfindRootを早くするため)。
			rootArray[friend] = findRoot(rootArray[friend])
			rootArray[friend]
		}
	}
	
	fun maxUnionNumber(): Int {
		return unionNumberArray.max() ?: throw IllegalArgumentException()
	}
}

Measured memory_bytes: 72252
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int A, B;
    cin >> A >> B;

    int cnt = 0;
    FOR(x, A, B + 1) {
        int a = x / 1000;
        int b = x % 10 * 10 + x / 10 % 10;

        if (a == b) cnt++;
    }

    print(cnt);
    
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    cout << (((100*r+10*g+b)%4==0)?"YES":"NO") <<endl;
    return 0;
}

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

class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        char[] s = Console.ReadLine().ToCharArray();
        int r = s.Select(p => p == 'R' ? 1 : 0).ToArray().Sum();
        bool f = r > n - r;
        Console.WriteLine(f ? "Yes" : "No");
    }
}

Measured memory_bytes: 13396
m,d = map(int, input().split())
count = 0
for i in range(m):
  i += 1
  for j in range(d):
    j += 1
    j = str(j)
    if len(j) == 2:
      ten = int(j[0])
      one = int(j[1])
      if ten >= 2 and one >= 2 and int(j[0])*int(j[1]) == i:
        count += 1
      
print(count)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;



void solve(){
    int a,b;cin>>a>>b;cout<<a*b;
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main (void) {

   int N;
   
   scanf("%d",&N);

   int A[N];
   
   int minus_num = 0;
   int abs_min = pow(10,9) + 1;
   long sum = 0;
   int i;
   for (i = 0; i < N; i++) {
      scanf("%d",&A[i]);
      if(A[i] < 0) {
         minus_num++;
      }
      if (abs_min > abs(A[i])) {
         abs_min = abs(A[i]);
      }
      sum = sum + abs(A[i]);
   }

   if (minus_num%2 == 0) {
      printf("%ld\n",sum);
   }
   else {
      printf("%ld\n",sum - 2*abs_min);
   }
   
   return 0;
   
}


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

/*

  Points/Vectors - Projection
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A

  ?????????????°???±????±?????????????

 */

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    // a, b ????????´??????????????????p ????????????????°???±?????????????±???????
    static void Calc(Vec2f p, Vec2f a, Vec2f b) {
        var ab = b - a;
        var ap = p - a;

        var d = ab.Normalized().Dot(ap);
        var x = a + ab.Normalized() * d;
        Console.WriteLine("{0} {1}", x.X, x.Y);
    }

    static void Main() {
        var xs = ReadInts();
        var p1 = new Vec2f(xs[0], xs[1]);
        var p2 = new Vec2f(xs[2], xs[3]);

        int q = ReadInt();
        for (int i = 0; i < q; i++) {
            var xy = ReadInts();
            var p = new Vec2f(xy[0], xy[1]);
            Calc(p, p1, p2);
        }
    }
}

struct Vec2f {
    public double X { get; private set; }
    public double Y { get; private set; }

    public Vec2f(double x, double y) : this() {
        X = x;
        Y = y;
    }

    public override string ToString() {
        return string.Format("({0}, {1})", X, Y);
    }

    public static Vec2f operator+(Vec2f a, Vec2f b) {
        return new Vec2f(a.X + b.X, a.Y + b.Y);
    }

    public static Vec2f operator-(Vec2f a, Vec2f b) {
        return new Vec2f(a.X - b.X, a.Y - b.Y);
    }

    public static Vec2f operator*(Vec2f a, double t) {
        return new Vec2f(a.X * t, a.Y * t);
    }

    // a???b = |a||b|cos??
    public double Dot(Vec2f other) {
        return X * other.X + Y * other.Y;
    }

    public double Cross(Vec2f other) {
        return X * other.Y - Y * other.X;
    }

    public Vec2f Normalized() {
        var m = Magnitude();
        if (m != 0 && m != 1) {
            return new Vec2f(X / m, Y / m);
        }
        return this;
    }

    public double Magnitude() {
        return Math.Sqrt(X * X + Y * Y);
    }

    public double SqrMagnitude() {
        return X * X + Y * Y;
    }

    public static double Distance(Vec2f a, Vec2f b) {
        return (a - b).Magnitude();
    }
}

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

const int DIM = 1e5 + 5;

int anc[DIM];

struct str {
    int x, y, z;
} pts[DIM], edg[DIM << 1];

int getroot(int x) {
    return (anc[x] < 0) ? x : getroot(anc[x]);
}

int main(void) {
    ios::sync_with_stdio(false);
    
    int n, m = 0;
    long long ans = 0;
    cin >> n;
    
    for (int i = 1; i <= n; ++i) {
        cin >> pts[i].x >> pts[i].y;
        pts[i].z = i; anc[i] = -1;
    }
    
    sort(pts + 1, pts + n + 1,
         [](str p1, str p2) { return p1.x < p2.x; });
    for (int i = 1; i < n; ++i)
        edg[++m] = {pts[i].z, pts[i + 1].z, pts[i + 1].x - pts[i].x};
    
    sort(pts + 1, pts + n + 1,
         [](str p1, str p2) { return p1.y < p2.y; });
    for (int i = 1; i < n; ++i)
        edg[++m] = {pts[i].z, pts[i + 1].z, pts[i + 1].y - pts[i].y};
    
    sort(edg + 1, edg + m + 1,
         [](str p1, str p2) {return p1.z < p2.z;});
    for (int i = 1; i <= m; ++i) {
        int x = getroot(edg[i].x),
            y = getroot(edg[i].y);
        
        if (x == y)
            continue;
       
        ans += edg[i].z;
        if (anc[x] > anc[y])
            swap(x, y);
        
        anc[x] += anc[y]; anc[y] = x;
    }
    
    cout << ans;
    return 0;
}


Measured memory_bytes: 4224
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
total = sum(a2)+a1[0]
ans = sum(a2)+a1[0]
for i in range(1, n):
    total += a1[i] - a2[i-1]
    if ans < total:
        ans = total
print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int dp[] = new int[100010];
        for(int i = 1;i<=100000;i++){
            dp[i] = Integer.MAX_VALUE;
            int power = 1;
            while(power<= i){
                dp[i] = Math.min(dp[i],dp[i-power]+1);
                power *= 6;
            }
            power = 1;
            while(power<= i){
                dp[i] = Math.min(dp[i],dp[i-power]+1);
                power *= 9;
            }
        }
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(dp[N]);
    }
}

Measured memory_bytes: 21972
#include<stdio.h>
int main(){
  int T[100];
  int n,sum=0,m,p,x,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d",&T[i]);sum+=T[i];}
  scanf("%d",&m);
  for(i=0;i<m;i++){scanf("%d%d",&p,&x);printf("%d\n",sum-T[p-1]+x);}
}

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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int na, nb, nt;
	cin >> na >> nb >> nt;
	vector<int> a(na), b(nb);
	for (int i = 0; i < na; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < nb; i++) {
		cin >> b[i];
	}
	int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
	for (int i = 0; i < nt; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		ans = min(ans, a[x] + b[y] - c);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3948
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int sum = 0;
    int min = -1;
    ArrayList<Integer> a = new ArrayList<Integer>();
    for (int i=0; i<n;i++){
      int b = scan.nextInt();
      int [] g = put(b,min);
      sum += g[0];
      min = g[1];
    }
    System.out.println(sum);
  }

  public static int[] put(int a, int b){
    int [] g = new int[2];
    if (b == -1){
      g[1] = a;
      g[0] = 1;
      return g;
    }

    if (a <= b){
      g[1] = a;
      g[0] = 1;
      return g;
    }

    g[1] = b;
    g[0] = 0;
    return g;
  }
}


Measured memory_bytes: 58572
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    ll n;
    cin >> n;
    vll ls;
    const int MAX = 12;
    ll num = 1;
    rep(i, MAX) {
        ls.push_back(num);
        num *= 26;
    }
    string ans = "";
    rep(i, MAX) {
        if (n/ls[i] == 0) continue;
        int m = (n/ls[i])%26;
        if (m == 0) ans += 'z';
        else ans += (char)(m+'a'-1);
        n -= ls[i];
    }
    reverse(all(ans));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define ll long long int

#define rep(p,q) for(int i = p; i < q;i++)


//11

int main(void) {
	int w, n;
	cin >> w >> n;
	int line[30];
	rep(0, 30) line[i] = i+1;
	rep(0, n) {
		int a, b;
		string comma;
		cin >> a >> comma;
		b = stoi(comma.substr(1));
		int swap = line[a - 1];
		line[a - 1] = line[b - 1];
		line[b - 1] = swap;
	}
	rep(0, w) {
		cout << line[i] << endl;
	}
}



Measured memory_bytes: 3004
/*input
3 3
1
3
1
3
1
3
*/

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

const int MAX_N = 101;
const int MAX_K = 101;

int main() {
    int N, K, d[MAX_K], A[MAX_K][MAX_N];
    cin >> N >> K;
    rep(i, K) {
        cin >> d[i];
        rep(j, d[i]) cin >> A[i][j];
    }

    bool is_none[MAX_N];
    rep(i, N) is_none[i] = true;
    rep(i, K) {
        rep(j, d[i]) {
            is_none[A[i][j]-1] = false;
        }
    }

    int ans = 0;
    rep(i, N) {
        if (is_none[i]) ans++;
        // cout << ans << endl;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var T = F;
		for (int i = 0; i < T; i++)
		{
			var I = GL;
			WriteLine(Check(I[0], I[1], I[2], I[3]) ? "Yes" : "No");
		}
	}
	bool Check(long A, long B, long C, long D)
	{
		if (A < B || D < B) return false;
		if (C >= B) return true;
		var g = GCD(B, D);
		return A % g + B - g <= C;
	}
	public static long GCD(long a, long b)
	{
		var n = (ulong)Math.Abs(a); var m = (ulong)Math.Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Math.Min(zm, zn);
	}
}


Measured memory_bytes: 13268
n=int(input())
X=list(map(int,input().split()))
p=0
s=0
m=0
for i in range(n):
  m += X[i-1]/n
while abs(p-m) > 1/2:
  p += 1
for j in range(n):
  s += (X[j-1]-p)**2
print(s)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int main() {
	const double basis = 3.305785;
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%lf\n", (double)(a*b) / basis);
	return 0;
}

Measured memory_bytes: 632
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  double w, h;
  int x, y;
  cin >> w >> h >> x >> y;
  double res1 = (w * h) / 2;
  int res2 = 0;
  if(w/2 == x && h/2 == y){
    res2 = 1;
  }
  cout << setprecision(9);
  cout << res1 << " " << res2 << "\n";
  return 0;
}


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

using namespace std;

int main(int argc, char* argv[])
{
    bool ans = true;

    int N; cin >> N;
    vector<pair<int, int>> work;
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        work.push_back(make_pair(b, a));
    }
    sort(work.begin(), work.end());

    unsigned long long cur_time = 0;
    for (int i = 0; i < N; i++) {
        cur_time += work[i].second;
        if (cur_time > work[i].first) {
	  ans = false;
	  break;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<set>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(){
	int n;
	string line;
	cin>>n;
	getline(cin,line,'\n');
	for(;n>0;n--){
		getline(cin,line,'\n');
		int alpha[12] = {1,3,5,7,9,11,15,17,19,21,23,25};
		for(int b,i=0;i<12;i++){
			for(b = 0;b<26;b++){
				char chiper[26];
				for(int j=0;j<26;j++)
					chiper[j] = (alpha[i]*j+b)%26 + 97;
				string decode = line;
				for(int j=0;j<line.size();j++){
					if(line[j]>=97&&line[j]<=122)
						decode[j] = chiper[line[j]-97];
					else
						decode[j] = line[j];
				}
				if(decode.find("this") != -1 || decode.find("that") != -1){
					cout<<decode<<endl;
					break;
				}
			}
			if(b!=26)break;
		}
	}
  return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;
public class Main{

    private static void solver(InputReader sc, PrintWriter out) throws Exception {
      int n = sc.nextInt();
      Set<String> hs = new HashSet<>();
      for(int i=0; i<n; i++){
          hs.add(sc.next());
      }
      out.println(hs.size());
    }
    private static int gcd(int a, int b){
        if(b==0)
            return a;
        return gcd(b, a%b);
    }
    public static void main(String[] args) throws Exception {
        // long start =  System.nanoTime();
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();


    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int[] readIntArray(int n){
            int arr[] = new int[n];
            for(int i=0;i<n;i++) arr[i] = nextInt();
            return arr;
        }
    }
}
class Pair  implements  Comparable<Pair>{
    int x;
    int y;
    int z;

    Pair(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

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

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

    @Override
    public int compareTo(Pair o) {
        return this.x-o.x;
    }
}


Measured memory_bytes: 62572
#include <stdio.h>

int main()
{
    int a;
    int b;
    int c;
    int d;
    int i;

    scanf("%d %d", &a, &b);
    c = b - a;

    d = 0;
    for(i = 1; i <= c; i++) {
        d += i;
    }

    printf("%d\n", d - b);

    return 0;
}

Measured memory_bytes: 128
import heapq

n, m = map(int, input().split())
a = []
#a = list(map(int, input().split()))
#a = list(reversed(sorted(a)))
#heapq.heapify(a)
for i in input().split():
    heapq.heappush(a, -int(i))

ans = 0

for i in range(len(a)):
    while True:
        if m <= 0:
            break

        maxV = heapq.heappop(a)
#        print('maxV: ' + str(maxV))
        heapq.heappush(a, -(-maxV // 2))
        m -= 1
        # print('m: ' + str(m))
        # print('a: ' + str(a))
ans = -sum(a)
print(ans)


Measured memory_bytes: 64112
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
 
    char x[4];
 
    int ans = 0;
 
    for(int a = 0; a < 4; a++){
 
         cin >> x[a];
 
         if(x[a] == '+') ans++;
 
         else ans--;

     }
 
     cout << ans << endl;
 
     return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define MOD 1000000007
using namespace std;
typedef long long ll;
int pos[MAXN];
int n,m;
struct node{
	ll x[3][3];	
	void operator *=(const node &a) {
		ll c[3][3]={0};
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					(c[i][j]+=x[i][k]*a.x[k][j])%=MOD;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				x[i][j]=c[i][j];
	}
}e,a,e1,e2;
void fsp(node &x,node y,int t){
	node y1=y;
	while(t){
		if(t&1)
			x*=y1;
		y1*=y1;
		t>>=1;	
	}
}
ll A[3],B[3];
int main(){
	SF("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		SF("%d",&pos[i]);
	e.x[0][0]=e.x[1][1]=e.x[2][2]=e.x[1][2]=e.x[0][2]=1;
	e.x[0][1]=2;
	e2.x[0][0]=e2.x[1][1]=e2.x[2][2]=e2.x[2][0]=1;
	e1=e;
	e1*=e2;
	m++;
	pos[m]=n;
	B[0]=1;
	for(int l=1;l<=m;l++){
		int s=pos[l]-pos[l-1]-1;
		memset(a.x,0,sizeof a.x);
		for(int i=0;i<3;i++)
			a.x[i][i]=1;
		fsp(a,e1,s);
		a*=e;
		for(int i=0;i<3;i++){
			A[i]=0;
			for(int j=0;j<3;j++)
				A[i]=(A[i]+B[j]*a.x[j][i])%MOD;
		}
		for(int i=0;i<3;i++)
			B[i]=A[i];
	}
	PF("%lld",B[2]);
} 

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

typedef long long ll;

int main() {
    string N;
    cin >> N;
    int l = N.size(), ans = 0;
    rep(i, l) {
        ans += N[i] - '0';
    }
    int x = N[0] - '0' - 1;
    x += 9 * (l - 1);
    cout << max(ans, x) << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = 0
    i = 0
    while i < n:
        # 右隣が同じにならないようにする
        while i+1 < n and a[i] == a[i+1]:
            i+=1
        # i は n-1 で抜けてくるので、下には引っかからない
        # 右隣の数の方が大きかったら
        if i+1 < n and a[i] < a[i+1]:
            # 右の方が小さくなるまで、次に進める
            while i+1 < n and a[i] <= a[i+1]:
                i += 1
        # 左隣の数の方が小さかったら
        elif i+1 < n and a[i] > a[i+1]:
            # 右の数が大きくなるまで、次に進める
            while i+1 < n and a[i] >= a[i+1]:
                i += 1
        # a[i]まで切り取る
        ans += 1
        # i をインクリメントして、新しい配列の先頭とする
        i += 1
    print(ans)

if __name__ == '__main__':
    main()


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

four=0
two=0
for i in range(n):
    if a[i]%4==0:
        four+=1
    elif a[i]%2==0:
        two+=1
if two>0:
    ans=four*2+two
else:
    ans=four*2+1

if ans>=n:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62576
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        set <int> s1,s2;
        for(int j=0;j<=i;j++)
            s1.insert(s[j]);
        for(int j=i+1;j<n;j++)
            s2.insert(s[j]);
        int curr=0;
        for(auto it:s1)
        {
            if(s2.find(it)!=s2.end())
                curr++;
        }
        // cout<<curr<<' '<<i<<'\n';
        ans=max(ans,(ll)curr);
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 15532
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;


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

  string res = "";
  while (n) {
    n--;
    res += (char)('a' + (n % 26));
    n /= 26;
  }

  reverse(all(res));
  cout << res << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
long long n,W,k,v[100005],w[100005],j,dp[100005],ans,fix[100005];
int main(){
	cin>>n>>W;
	for(k=1;k<=n;k++){
		cin>>w[k]>>v[k];
	}

	for(k=1;k<=n;k++){
		for(j=W;j>=w[k];j--){
		dp[j]=max(dp[j],dp[j-w[k]]+v[k]);
			//cout<<j-w[k]<<" "<<dp[j-w[k]]+v[k]<<endl;
		}
	}
	for(k=1;k<=W;k++){
		ans=max(ans,dp[k]);
	}
	cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N; ll M;
map<ll, ll> D; 

void solve() {
	cin >> N >> M;
	ll s = 0;
	D[s]++;
	rep(i, 0, N) {
		ll a; cin >> a;
		s = (s + a) % M;
		D[s]++;
	}
	ll res = 0;
	for(auto p: D) {
		res += p.sec * (p.sec - 1) / 2;
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 4224
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        int n=sc.nextInt();
        int a[][] = new int[1<<n][2];
        for(int t=0; t<1<<n; t++) {
            a[t][0] = sc.nextInt();
        }

        for(int t=0,v; t<n; t++) {
            for(int i=0; i<1<<n; i++) {
                if( (i>>t)%2 == 1){
                    v = i^(1<<t);
                    if( a[v][0] > a[i][0]){
                        a[i][1] = a[i][0];
                        a[i][0] = a[v][0];
                        if( a[v][1] > a[i][1])
                            a[i][1] = a[v][1];
                    }
                    else if(a[v][0] > a[i][1])
                                a[i][1] = a[v][0];
                }
            }
        }

        int ans=0;
        for(int t=1; t<1<<n; t++) {
            ans = max(ans, a[t][1]+a[t][0]);
            out.println(ans);
        }
      
        // out.println(ans);
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    

    class P implements Comparable<P>{
        long x;
        double d;
        P(long x, double d) {
            this.x=x;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return (d - p.d)>0?1:-1;//des
        } 
    }
}
class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 76792
/*
*/
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cstring>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define PI 3.141592653589793
#define MOD 1000000007LL
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    // char s[3];

    // cin >> s[0] >> s[1] >> s[2];
    // if(s[0] == )
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB") cout << "No" << endl;
    else  cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int H,A;
  cin>>H>>A;
  
  int ans=0;
  
  if(H%A==0)
    ans=H/A;
  else
    ans=H/A+1;
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#include <bitset>
#define sf scanf
#define pf printf
#define lf double
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define ll long long
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define eps 1e-7
#define zero(x) (((x) > 0? (x):(-x)) < eps)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#include <bitset>

using namespace std;
//https://codeforces.com/contest/1238/problems
//https://codeforces.com/contest/1238/submit
struct A{
    int l,r;
}a[100050];
bool cmp(A a , A b){
    if(a.r < b.r)return true;
    if(a.r == b.r && a.l < b.l)return true;
    return false;
}
int main(){
    int n,m;
    s(n) s(m)
    for(int i = 0; i < m; i ++){
        s(a[i].l) s(a[i].r)
        if(a[i].l > a[i].r){
            swap(a[i].l,a[i].r);
        }
    }
    sort(a,a+m,cmp);
    int x = a[0].r;
    int count0 = 1;
    for(int i = 1; i < m; i ++){
        if(a[i].l <= x-1 && a[i].r >= x){
            continue;
        }else{
            count0 ++;
            x = a[i].r;
        }
    }
    p(count0) pn


    return 0;
}


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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,lessl<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N=2e3+5;
const int M=1e9+7;
void solve()
{
	int n,m;
	cin>>n>>m;
	int s1,s2,e1,e2;
	cin>>s1>>s2>>e1>>e2;
	char a[n+1][m+1];
	bool vis[n+1][m+1];
	memset(vis,false,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		cin>>a[i][j];
	}
	
	deque<pair<int,int>> q;
	q.push_front(mp(s1,s2));
	int ans[n+1][m+1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		ans[i][j]=inf;
	}
	ans[s1][s2]=0;
	
	while(!q.empty())
	{
		pair<int,int> p=q.front();
		int x1=p.ff;
		int y1=p.ss;
		q.pop_front();
		if(vis[x1][y1]) continue;
		vis[x1][y1]=true;
		for(int i=-2;i<=2;i++)
		{
			for(int j=-2;j<=2;j++)
			{
				if(x1+i<=n && x1+i>=1 && y1+j>=1 && y1+j<=m && a[x1+i][y1+j]=='.')
				{
					
					if((i==1 && j==0) || (i==-1 && j==0) || (i==0 && j==-1) || (i==0 && j==1))
					{
						ans[x1+i][y1+j]=min(ans[x1+i][y1+j],ans[x1][y1]);
						q.push_front(mp(x1+i,y1+j));
					}
					else
					{
						q.push_back(mp(x1+i,y1+j));
						ans[x1+i][y1+j]=min(ans[x1+i][y1+j],ans[x1][y1]+1);
					}
					
				}
				
			}
		}
	}
	if(ans[e1][e2]<1000000)
	{
		cout<<ans[e1][e2]<<endl;
	}
	else
	cout<<-1<<endl;
}

signed main()
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 15072
/*......................*/
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double   ld;

//#include <ext/pb_ds/assoc_container.hpp>   
//#include <ext/pb_ds/tree_policy.hpp>  
//#include <functional> 
//using namespace __gnu_pbds;  
//typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> OST;           //unique elements 

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    pf                       push_front
#define    mp                       make_pair
#define    T                        int t; cin >> t; while(t--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    setp(x)                  setprecision(x)
#define    ook(x)                   order_of_key(x)
#define    fbo(x)                   find_by_order(x)

//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

void solve(){
   
}

int main(){                                       //constraints , long long
     speed upp
     int n; cin >> n;
     int ans = 0;
     f(i,1,n){
         int j = i;
         int cnt = 0;
         while(j){
             cnt++;j/=10;
         }
         ans+=(cnt%2);
     }
     cout << ans << '\n';
}








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

int a, b, c, d, e, f;

typedef pair<double, pair<int, int> > P;

bool visited[4000][4000];
P memo[4000][4000];

P dp(int i, int j){

    if(visited[i][j]){
        return memo[i][j];
    }

    P ans = {(double)j/(double)(i+j), {i, j} };


    if(i+j+a <= f){
        ans = max(ans, dp(i+a, j));
    }

    if(i+j+b <= f){
        ans = max(ans, dp(i+b, j));
    }

    if(i+j+c <= f && ((double)(j+c)/(double)(i+j+c)) <= (double)e/(double)(100.0+e)){
        ans = max(ans, dp(i, j+c));
    }

    if(i+j+d <= f && ((double)(j+d)/(double)(i+j+d)) <= (double)e/(double)(100.0+e)){
        ans = max(ans, dp(i, j+d));
    }

    visited[i][j] = 1;

    return memo[i][j] = ans;
}


int main(){
    cin >> a >> b >> c >> d >> e >> f;
    a*=100;
    b*=100;

    //55555Kbyteにしたい
    char kyomu[3000];
    for(int i = 0;i < 3000;i++)
        kyomu[i] = 'Y';

    pair<int, int> ans;
    if(b <= f){
        ans = max(dp(a, 0), dp(b, 0)).second;
    }else{
        ans = dp(a, 0).second;
    }

    cout << (ans.first + ans.second) << " " << (ans.second) << endl;

    return 0;
}


Measured memory_bytes: 55552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,S;
vector<int>vec;
int cnt[405];
set<vector<int> >se;
void verify(vector<int>vi){
	if(vi.size() != n-1) return;
	if(se.find(vi) != se.end()) return;
	vector<int>hoge;
	for(int i=0;i<n-1;i++){
		int sx = 0;
		for(int j=i;j<n-1;j++){
			sx += vi[j];
			if(i!=0 || j!=n-2) hoge.pb(sx);
			else if(sx != S) return;
		}
	}
	sort(hoge.begin(),hoge.end(),greater<int>());
	if(vec == hoge){
		se.insert(vi);
	}
}
void rec(vector<int>L,vector<int>R,int sumL,int sumR){
    //if(S == 9) cout << sumL << " " << sumR <<" " << L.size()+R.size() << " " << n << endl;
	if(L.size()+R.size() == n-2){L.pb(S-sumL-sumR);
		for(int i=R.size();i>=1;i--) L.pb(R[i-1]);
		verify(L); return;
	}
	int mx;
	for(int x=S-min(sumL,sumR);x>=0;x--){
		if(cnt[x]) {mx = x; break;}
	}
	if(mx<S-sumR){
		R.pb(S-sumR-mx);
		int s2 = 0; bool ok = 1;
		for(int i=R.size()-1;i>=0;i--){
			s2 += R[i];
			if(cnt[s2] == 0) ok = 0;
			cnt[s2]--;
		}
		s2 = mx;
		for(int i=0;i<=L.size();i++){
			if(cnt[s2] == 0) ok = 0;
			cnt[s2]--;
			if(i != L.size()) s2 -= L[i];
		}
		if(ok){
			rec(L,R,sumL,S-mx);
		}
		s2 = 0;
		for(int i=R.size()-1;i>=0;i--){
			s2 += R[i];
			cnt[s2]++;
		}
		s2 = mx;
		for(int i=0;i<=L.size();i++){
			cnt[s2]++;
			if(i != L.size()) s2 -= L[i];
		}
		R.pop_back();
	}
	//cout << cnt[2] << " " << cnt[3] << " " << mx << " " << sumL << endl;
	if(mx<S-sumL){
		L.pb(S-sumL-mx);
		int s2 = 0; bool ok = 1;
		for(int i=L.size()-1;i>=0;i--){
			s2 += L[i];
			if(cnt[s2] == 0) ok = 0;
			cnt[s2]--;
		}
		s2 = mx;
		for(int i=0;i<=R.size();i++){
			if(cnt[s2] == 0) ok = 0;
			cnt[s2]--;
			if(i != R.size()) s2 -= R[i];
		}
		if(ok){
			rec(L,R,S-mx,sumR);
		}
		s2 = 0;
		for(int i=L.size()-1;i>=0;i--){
			s2 += L[i];
			cnt[s2]++;
		}
		s2 = mx;
		for(int i=0;i<=R.size();i++){
			cnt[s2]++;
			if(i != R.size()) s2 -= R[i];
		}
		L.pop_back();
	}
}
int main(){
	while(1){
		cin >> n; if(n == 0) return 0; memset(cnt,0,sizeof(cnt)); vec.clear(); se.clear();
		for(int i=0;i<n*(n-1)/2;i++){
			int a; cin >> a;
			if(i==0) S = a;
			else {cnt[a]++;vec.pb(a);}
		}
		rec(vector<int>(0),vector<int>(0),0,0);
		for(set<vector<int> >::iterator it=se.begin();it!=se.end();++it){
		    vector<int>vi = *it;
	        for(int i=0;i<n-1;i++) printf("%d%c",vi[i],i==n-2?'\n':' ');
		}
		puts("-----"); //cout << "J" << endl;
	}
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double eps = 1e-8;
 
#define INF 2147483647
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define FILL(v,n) memset(v,n,sizeof(v))
#define EB emplace_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep1n(i,n)	for(int i=1;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie();cout.tie();
 
#define MXN 1000000 //10^6

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







Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        x:i32,
        n:usize,
        p:[i32;n]
    };

    let mut ans = -200;
    for i in 0..102 {
        if p.contains(&i) {
            continue;
        }
        if (i-x).abs()<(ans-x).abs() {
            ans = i;
        }
    }

    println!("{}",ans);
}


Measured memory_bytes: 2128
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    r = [0] * (N+1)
    rr = [0] * (N+1)

    for i in range(1,N+1):
        r[i] = r[i-1] + A[i-1]
    
    for i in range(N-1, -1, -1):
        rr[i] = rr[i+1] + A[i]

    ans = INF
    for i in range(1,N):
        ans = min(ans, abs(r[i]-rr[i]))

    print(ans)

    
    return



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

if __name__ == '__main__':
    main()


Measured memory_bytes: 46332
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main() {
  int N;
  double AA=1.0,sum=0.0,BB=1.0;
  cin>>N;
  double x[N],y[N];
  for(int i=0;i<N;i++) cin>>x[i]>>y[i];
  for(int i=1;i<=N;i++) AA=AA*i;
  for(int i=1;i<=N-1;i++) BB=BB*i;
  //cout<<AA<<"\n"<<BB<<endl;
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      double a=x[i]-x[j],b=y[i]-y[j];
      double c=pow(a,2.0)+pow(b,2.0);
      //cout<<pow(a,2)<<"\n"<<pow(b,2)<<endl;
      c=pow(c,0.5);
      //cout<<c<<endl;
      sum+=c*(double)BB*2.0;
    }
  }
  
  double ans=sum/AA;
  printf("%.14f\n",ans);
}	


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

int main(void){
    int x, a, b;
    cin >> x >> a >> b;
    if(abs(a-x) > abs(b-x)){
        cout << "B" << endl;
    }else{
        cout << "A" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import *
from itertools import *

N=int(input())
A=list(map(int,input().split()))

s1=[0]+list(accumulate(A))
nums=defaultdict(int)
for i in range(N+1):
  nums[s1[i]]+=1

ans=0
s2=set(s1)
for x in s2:
  ans+=nums[x]*(nums[x]-1)//2

print(ans)


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;

int main(){
    ll n,k;
    cin >> n >> k;
    vl s(n);
    vector<pair<ll,ll>> a(n);
    lrp(i,n){
        cin >> a.at(i).first >> a.at(i).second;
    }
    sort(a);
    s.at(0)=a.at(0).second;
    if(s.at(0)>=k){
        cout << a.at(0).first << endl;
        return 0;
    }
    lrep(i,1,n-1){
        s.at(i)=s.at(i-1)+a.at(i).second;
        if(s.at(i)>=k){
            cout << a.at(i).first << endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 2560