akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int[] div_n = new int[4];

            for (int i = 0; i < 3; i++)
            {
                div_n[cin.ReadInt - 1]++;
                div_n[cin.ReadInt - 1]++;
            }

            int even = 0;

            for (int i = 0; i < 4; i++)
            {
                if (div_n[i] == 0)
                {
                    Console.WriteLine("NO");
                    return;
                }
                else if (div_n[i] % 2 == 0)
                {
                    even++;
                }
            }

            if (even == 2 || even == 4)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 13268
import java.util.*;

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

    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double h = sc.nextDouble();
    double m = sc.nextDouble();
    double ans = 0;

    double hAng = (60 * h + m) / 2;
    double mAng = m * 6;
    double diff = Math.abs(hAng - mAng);

    ans = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.toRadians(diff)));

    System.out.println(ans);
  }
}


Measured memory_bytes: 37452
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;

ll a[200005];
ll help[1000005];
int main(){
	ll n;
    sc(n);
    
    
    for(ll i=1;i<=n;i++)sc(a[i]),help[a[i]]++;
    ll ans=0;
    for(ll i=1;i<=n;i++){
    	ll f=1;
    	help[a[i]]--;
    	if(help[a[i]]>0)f=0;
    	else{
    	for(ll j=1;j*j<=a[i];j++){
    		if(a[i]%j==0){
    			if(help[j] or help[a[i]/j]) {f=0;break;}
    		}
		}
	    }
		help[a[i]]++;
		ans+=f;
	}
	pr(ans);
    
	
	
	
	
    
}


Measured memory_bytes: 13088
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }




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

    vl a(3);
    for (ll i = 0; i < 3; ++i) {
        cin >> a[i];
    }
    sort(all(a));
    cout << (a == vl({5, 5, 7}) ? "YES" : "NO") << endl;

    print_time();
    return 0;
}


Measured memory_bytes: 256
import math

n = int(input())

def f(a, b):
    x = int(max(a, b))
    return len(str(x))

results = []

# itr_end = int(n ** 0.5) + 1
itr_end = int(math.sqrt(n)) + 1

for i in range(1, itr_end):
    if n % i == 0:
        a = i
        b = n / i
    result = f(a, b)
    results.append(result)

print(min(results))



Measured memory_bytes: 9788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

using ll = long long;

const int INF = 1001001001;
int n, a, b;
vector<int> h(100005);

// 二分探索用判定関数
bool C(int num)
{
    vector<int> temp(h.begin(), h.begin() + n);

    ll res = 0;
    ll subtraction = b * num;
    for (int i = 0; i < n; ++i)
    {
        if (h[i] > subtraction)
        {
            res += ceil((double)(h[i] - subtraction) / (a - b));
        }
    }

    return res <= num;
}

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

    cin >> n >> a >> b;
    for (int i = 0; i < n; ++i)
    {
        cin >> h[i];
    }

    int lb = 0, ub = ceil((double)*max_element(h.begin(), h.begin() + n) / b);
    while (ub - lb > 1)
    {
        int mid = (lb + ub) / 2;
        if (C(mid))
            ub = mid;
        else
            lb = mid;
    }

    cout << ub << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
ll N, A, B;
vector<ll> h;

bool enough(ll t){
	ll curr = 0LL;
	rep (i, N){
		if (h[i] > B * t){
			curr += (ll)ceil((double)(h[i] - B * t) / (double)(A - B));
		} // end if
	} // end rep

	return curr <= t;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> A >> B;
	h.clear(); h.resize(N, 0LL);
	rep (i, N){
		cin >> h[i];
	} // end rep

	ll ok = (ll)1e9;
	ll ng = 0LL;

	while(abs(ok - ng) > 1LL){
		ll mid = (ok + ng) / 2LL;
		if (enough(mid)){
			ok = mid;
		}else{
			ng = mid;
		} // end if
	} // end while

	cout << ok << endl;

	return 0;
}

Measured memory_bytes: 1024
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,a,b = readline() |> split |> parseMap
	h = zeros(Int,n)
	for i in 1:n
		h[i] = readline() |> parseInt
	end
	h = sort(h)
	l = 0
	r = 1
	for i in 1:n
		r += cld(h[i],a)
	end
	while r-l>1
		m = (l+r)>>1
		z = 0
		for i in 1:n
			z += h[i]-m*b>0?cld(h[i]-m*b,a-b):0
		end
		if z>m
			l=m
		else
			r=m
		end
	end
	println(r)
end

main()

Measured memory_bytes: 129156
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


#define INF (1e+9)
int main(void) {
    int num, cap, limit;
    cin >> num >> cap >> limit;
    vector<pii> ranges(num);
    for(int i = 0; i < num; i++) {
        int time;
        cin >> time;
        ranges[i] = make_pair(time, time+limit+1);
    }
    auto comp = [](pii a, pii b) {
        return a.second < b.second;
    };
    sort(ranges.begin(), ranges.end(), comp);

    int ans = 0;
    int time = 0;
    int ps = 0;
    for(int i = 0; i < num; i++) {
        pii r = ranges[i];
        if(ps == cap) {
            time = 0;
        }
        if(r.first < time) {
            ps++;
        // too early for r
        } else {
            ans++;
            time = r.second;
            ps = 1;
        }
        debug("[time: %d] %d\n", time, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int dx = x2 - x1;
	int dy = y2 - y1;
	cout << x2 - dy << ' ' << y2 + dx << ' ' << x2 - dy - dx << ' ' << y2 + dx - dy << endl;
}

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

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

  vector<int> L(n);
  rep(i, n) cin >> L[i];

  sort(L.begin(), L.end(), greater<int>());

  int ans = 0;
  rep(i, k) ans += L[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
long long int a[300000];

int main()
{
    long long int sum=0;
    long long int k=0;
    long long int n;
    cin>>n;
    for(long long int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]>i)
        {
            k=1;
        }
    }
    if(k==1)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(long long int i=1; i<n; i++)
    {
        if(a[i]>a[i-1]+1)
        {
            cout<<-1<<endl;
            return 0;
        }
        if(a[i]==a[i-1]+1)
        {
            sum++;
        }
        if(a[i]<a[i-1]+1)
        {
            sum+=a[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {

  long long int x, h;

  while( true ) {

    cin >> x >> h;

    if ( x == 0 ) break;

    cout << fixed << setprecision(7) << sqrt( 0.25 * x * x + h * h ) * x * 2 + x * x << endl;

  }

  return 0;

}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef pair<int, int> P;
int main()
{
    ll N, K;
    cin >> N >> K;

    ll ans = 0;

    vector<ll> sum(N + 1, 0);
    rep(i, N) {
        sum[i + 1] = i + 1;
    }
    rep(i, N) sum[i + 1] += sum[i];
    repd(i, K, N + 1) {
        ans += (sum[N] - sum[N - i]) - sum[i - 1] + 1;
        ans %= MOD;
    }

    cout << (ans + 1) % MOD << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#define ll long long
#define re register
#define rint register int
#define isdight(c) (c<='9'&&c>='0')
using namespace std;
inline int read()
{
	int x=0;register char c=getchar();int f=1;
	for(;!isdight(c);c=getchar()) if(c=='-') f=-1;
	for(;isdight(c);c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
template <typename ty> inline void write(ty x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+48);
}
const int N = 1e5+5;
int n;
string s[N];
string key[N];
map <string,ll> ma;
map <string,int> :: iterator it;
int main()
{
	n = read();
	for(int i=1;i<=n;i++) cin >> s[i];
	for(int i=1;i<=n;i++)
	{
		key[i].resize(50);
		for(int j=0;j<10;j++)
		{
			key[i][s[i][j]-'a']++;
		}
		ma[key[i]]++;
	}
	ll sum = 0;
	for(int i=1;i<=n;i++)
	{
		ll t = ma[key[i]];
		if(t)
		{
			sum += t*(t-1)/2;
			ma[key[i]]=0;
		}
	}
	cout << sum;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int W, a, b;

    cin >> W >> a >> b;
    if (a <= b){
      if (b - (a + W) <= 0){
        cout << 0 << endl;
      } else {
        cout << b - (a + W) << endl;
      }
    } else {
      if (a - (b + W) <= 0){
        cout << 0 << endl;
      } else {
        cout << a - (b + W) << endl;
      }
    }
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;
    string t = "";
    rep(i, s.size()) t += 'x';
    OP(t);
    return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
keta = ["-1"] * n
if n == 1:
  ans = -1
  for s,c in sc:
    if ans == -1 or ans == c:
      ans = c
    else:
      print(-1)
      exit()
  if ans == -1:
    print(0)
  else:
    print(ans)
else:
  for s,c in sc:
    s-=1
    if keta[s] == "-1" or keta[s] == str(c):
      keta[s] = str(c)
    else:
      print(-1)
      exit()
  ans = ""
  for k,i in enumerate(keta):
    if i == "-1":
      if k == 0:
        ans += "1"
      else:
        ans += "0"
    else:
      ans += i   
  if ans[0] == "0":
    print(-1)
    exit()
  else:
    print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll x,cost;
};
int main() {

	int n;
	cin>>n;
	cout<<n/2+n%2<<endl;
	return 0;
}


Measured memory_bytes: 764
import Control.Applicative ((<$>))
import Control.Monad (replicateM, forM_, when)
import Data.Vector (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed.Mutable (IOVector)
import qualified Data.Vector.Unboxed.Mutable as VM

main :: IO ()
main = do
  [m, n] <- map read <$> words <$> getLine
  k <- readLn
  solve m n k

solve :: Int -> Int -> Int -> IO ()
solve m n k = do
  dpj <- VM.replicate ((m+1) * (n+1)) 0 :: IO (IOVector Int)
  dpo <- VM.replicate ((m+1) * (n+1)) 0 :: IO (IOVector Int)
  dpi <- VM.replicate ((m+1) * (n+1)) 0 :: IO (IOVector Int)
  forM_ [1..m] $ \i -> do
    s <- getLine
    forM_ (zip [1..n] s) $ \(j, c) -> do
      lj <- VM.read dpj ((n+1)*i+j-1)
      uj <- VM.read dpj ((n+1)*i+j-n-1)
      ulj <- VM.read dpj ((n+1)*i+j-n-2)
      VM.write dpj ((n+1)*i+j) (uj + lj - ulj)
      lo <- VM.read dpo ((n+1)*i+j-1)
      uo <- VM.read dpo ((n+1)*i+j-n-1)
      ulo <- VM.read dpo ((n+1)*i+j-n-2)
      VM.write dpo ((n+1)*i+j) (uo + lo - ulo)
      li <- VM.read dpi ((n+1)*i+j-1)
      ui <- VM.read dpi ((n+1)*i+j-n-1)
      uli <- VM.read dpi ((n+1)*i+j-n-2)
      VM.write dpi ((n+1)*i+j) (ui + li - uli)
      when (c == 'J') $ do
        modify dpj (+1) ((n+1)*i+j) 
      when (c == 'O') $ do
        modify dpo (+1) ((n+1)*i+j)
      when (c == 'I') $ do
        modify dpi (+1) ((n+1)*i+j)
  forM_ [1..k] $ \_ -> do
    [a, b, c, d] <- map read <$> words <$> getLine
    lj <- VM.read dpj (c*(n+1)+(b-1))
    uj <- VM.read dpj ((a-1)*(n+1)+d)
    ulj <- VM.read dpj ((a-1)*(n+1)+(b-1))
    ctj <- VM.read dpj (c*(n+1)+d)
    lo <- VM.read dpo (c*(n+1)+(b-1))
    uo <- VM.read dpo ((a-1)*(n+1)+d)
    ulo <- VM.read dpo ((a-1)*(n+1)+(b-1))
    cto <- VM.read dpo (c*(n+1)+d)
    li <- VM.read dpi (c*(n+1)+(b-1))
    ui <- VM.read dpi ((a-1)*(n+1)+d)
    uli <- VM.read dpi ((a-1)*(n+1)+(b-1))
    cti <- VM.read dpi (c*(n+1)+d)
    putStrLn . unwords . map show $ [ctj - lj - uj + ulj, cto - lo - uo + ulo, cti - li - ui + uli]

modify :: IOVector Int -> (Int -> Int) -> Int -> IO ()
modify v f i = do
  x <- VM.read v i
  VM.write v i (f x)



Measured memory_bytes: 52608
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

ll MOD = 2019;

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

    ll L, R;
    cin >> L >> R;

    ll ans = 5000;
    for (ll i = L; i <= R && i <= L + MOD; i++) {
        for (ll j = i+1; j <= R && j <= L + 1 + MOD; j++) {
            ans = min (ans, (i*j) % MOD);
        }
    }

    cout << ans << "\n";

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int X;
  cin >> X;

  cout << 8-(X-400)/200 << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int maxn = 8;
int m,n;
char a[maxn+1][maxn+1];
bool visit[maxn+1][maxn+1];
void dfs(int x,int y)
{
	visit[x][y]=true;
	if (x<m and !visit[x+1][y] and a[x+1][y]=='#') dfs(x+1,y);
	else
	if (y<n and !visit[x][y+1] and a[x][y+1]=='#') dfs(x,y+1);
}
int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> m >> n;
	for (int i=1; i<=m; i++)
	for (int j=1; j<=n; j++)
	cin >> a[i][j];
	memset(visit,false,sizeof(visit));
	dfs(1,1);
	/*for (int i=1; i<=m; i++)
	{
		for (int j=1; j<=n; j++)
		cout << visit[i][j];
		cout << '\n';
	}
	for (int i=1; i<=m; i++)
	{
		for (int j=1; j<=n; j++)
		cout << a[i][j];
		cout << '\n';
	}*/
	for (int i=1; i<=m; i++)
	for (int j=1; j<=n; j++)
	if (a[i][j]=='#' and !visit[i][j])
	{
		cout << "Impossible";
		return 0;
	}
	cout << "Possible";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n;
ll ans;
map<int, int> m;    
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) {
        int x; cin >> x;
        m[x]++;
    }
    for (auto itr = m.begin(); itr != m.end(); itr++) {
        if (itr->first < itr->second) ans += (itr->second - itr->first);
        else if (itr->second < itr->first) ans += itr->second;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>
#include<string.h>
int main(void)
{
	int x, y, kotae;
	char mozi[10];
	scanf("%d%s%d", &x, &mozi, &y);
	if (strcmp(mozi, "+") == 0)
		kotae = x + y;
	else
		kotae = x - y;
	printf("%d", kotae);
   return 0;
}


Measured memory_bytes: 128
#include <iostream>

int next_x(int r, int d, int x)
{
        return (r * x) - d;
}

int main(int argc, char **argv)
{
        int r, d, x;
        std::cin >> r >> d >> x;

        for(int i = 0;i < 10;i++){
                x = next_x(r, d, x);
                printf("%d\n", x);
        }

        return 0;
}


Measured memory_bytes: 256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;

void solve(){
    string s,t;
    cin >> s >> t;
    int N= s.size(), M=t.size();
    vector<vector<int>> dp(N+1,vector<int>(M+1));
    REP(i,N){
        REP(j,M){
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
            if(s[i]==t[j]){
                chmax(dp[i+1][j+1],dp[i][j]+1);
            }
        }
    }
    cout << dp[N][M]<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    REP(i,N) solve();
}


Measured memory_bytes: 6912
n,m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = "No"
for i in range(n-m+1):
  for j in range(n-m+1):
    for k in range(m):
      if b[k] != a[k+i][j:j+m]:
        break
    else:
      ans = "Yes"
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long a, b, c, d, x, y;
    cin >> a >> b >> c >> d;
    long long ara[5];
    ara[0] = a*c, ara[1] = a*d, ara[2] = b*c, ara[3] = b*d;
    long long maxi = ara[0];
    for(int i=0; i<4 ; i++){
        if(maxi < ara[i]) maxi = ara[i];
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 3660
import collections
import itertools
n=int(input())
l,s=[],[]
for i in range(n):
    a=input()
    if a[0]=="M" or a[0]=="A" or a[0]=="R" or a[0]=="C" or a[0]=="H":
        l.append(a[0])
        if s.count(a[0])==0:
            s.append(a[0])
l=collections.Counter(l)
ans=0
for j in itertools.combinations(s,3):
    ans+=(l[j[0]]*l[j[1]]*l[j[2]])
print(ans)


Measured memory_bytes: 9904
/*
    B - Mix Juice 
    https://atcoder.jp/contests/abc171/tasks/abc171_b
*/

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define ll long long // 10 ^ 18
#define forn(i, s, n) for (int i = s; i < n; i++)
#define whilen(val, n) while(n-- && cin >> val)
#define r_1(v) cin >> v
#define r_2(v1, v2) cin >> v1 >> v2

int main() {
    int n, k, p;
    int min_sum = 0;
    vector<int> ns;
    r_2(n, k);

    forn(i, 0, n) {
        r_1(p);
        ns.push_back(p);
    }

    sort(ns.begin(), ns.end());

    forn(i, 0, k) min_sum += ns[i];

    cout << min_sum << '\n';
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int H; cin >> H;
	int N; cin >> N;

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

	vector<int>dp(10000 + 1,INF);
	dp[0] = 0;
	rep(i, 0, N) {
		rep(j, A[i], 10000 + 1) {
			chmin(dp[j], dp[j - A[i]] + B[i]);
		}
	}

	int ans = INF;
	rep(j, H, dp.size()) {
		chmin(ans, dp[j]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string bouzu;
	int i,j,n;
	int p;
	while(1){
		int player[11]={0};
		int ba=0;
		cin>>n;
		if(n==0)break;
		cin>>bouzu;
		for(i=0;i<100;i++){
			p=i%n;
			//cout<<p<<endl;;
			if(bouzu[i]=='S'){//??????
				ba+=player[p]+1;
				player[p]=0;
			}
			else if(bouzu[i]=='L'){//?§?
				player[p]+=ba+1;
				ba=0;
			}
			else{//???
				player[p]++;
			}
		}
		sort(player,player+n);
		for(i=0;i<n;i++){
			if(i!=0){
				cout<<" ";
			}
			cout<<player[i];
		}
		cout<<" "<<ba<<endl;
	}
	return 0;
}

Measured memory_bytes: 3196
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int attend[n];
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		attend[t-1] = i+1;
	}

	for (int i = 0; i < n; i++) cout << attend[i] << " ";
	cout << endl;
    return 0;
}


Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            ReadInt(out a, out b);

            int ans;
            if (a <= 5)
            {
                ans = 0;
            }
            else if (a <= 12)
            {
                ans = b / 2;
            }
            else
            {
                ans = b;
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 11348
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>

constexpr int di[]={-1, -1, -1, 0, 0, 1, 1, 1};
constexpr int dj[]={-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
  intmax_t H, W, N;
  scanf("%jd %jd %jd", &H, &W, &N);

  std::set<std::pair<int, int>> s;
  for (int i=0; i<N; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);

    s.emplace(a, b);
  }

  std::map<std::pair<int, int>, int> m;
  for (const auto &p: s) {
    int i=p.first, j=p.second;
    ++m[p];
    for (int k=0; k<8; ++k)
      ++m[std::pair<int, int>(i+di[k], j+dj[k])];
  }

  intmax_t res[10]={(H-2)*(W-2)};
  for (const auto &p: m) {
    int i=p.first.first, j=p.first.second;
    if (!(1 < i && i < H && 1 < j && j < W)) continue;
    if (p.second == 0) continue;
    fprintf(stderr, "(%d, %d) -> %d\n", i, j, p.second);
    ++res[p.second];
    --res[0];
  }

  for (int i=0; i<=9; ++i)
    printf("%zd\n", res[i]);
}


Measured memory_bytes: 61184
#include<cstdio>

using namespace std;

int main(){
	int n; scanf("%d", &n);
	int res = 0;
	for(int i = 1; i <= n; i += 2){
		int c = 0;
		for(int j = 1; j <= i; j++) if(i % j == 0) c++;
		if(c == 8) res++;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+7; char s[N];
int n,ans,len[N],sum[N],dep[N],siz[N],maxn[N],minn[N]; bool fl[N]; vector<int>v[N];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline void find(int u){
	fl[u]=1; int pot=0;
	for(int x=0;x<len[u];x++){
		if(fl[v[u][x]]) continue;
		dep[v[u][x]]=dep[u]+1,find(v[u][x]),siz[u]+=siz[v[u][x]];
		maxn[u]+=maxn[v[u][x]]; if(maxn[v[u][x]]-siz[v[u][x]]*dep[u]>maxn[pot]-siz[pot]*dep[u]) pot=v[u][x];
	}
	int t=maxn[u]-siz[u]*dep[u],c=maxn[pot]-siz[pot]*dep[u],q=minn[pot]-siz[pot]*dep[u];
	if(q<=t-c) minn[u]=siz[u]*dep[u]+(t&1);
	else minn[u]=c+q-t+siz[u]*dep[u];
	if(s[u]=='1') maxn[u]+=dep[u],minn[u]+=dep[u],siz[u]++;
}
int main(){
	n=read(),scanf("%s",s+1); int u,t; ans=1e9;
	for(int i=1;i<n;i++) u=read(),t=read(),v[u].push_back(t),v[t].push_back(u),len[u]++,len[t]++;
    for(int i=1;i<=n;i++){
    	memset(fl,0,sizeof(fl)),memset(maxn,0,sizeof(maxn)),memset(minn,0,sizeof(minn)),memset(siz,0,sizeof(siz));
    	dep[i]=0,find(i); if(!minn[i]) ans=min(ans,maxn[i]/2);
	}
	if(ans==1e9) cout<<-1<<endl; else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdint>
using namespace std;
const int MOD = 50;
const int ADD = MOD - 1;
int main() {
	int64_t K, use, loop;
	cin >> K;
	loop = K % MOD;
	use = K / MOD + (49 - loop);
	if (loop) use ++;
	else {
		loop = ADD;
		use -= ADD;
	}
	cout << MOD << endl;
	for (int i = 0;i < loop;i ++) cout << use + ADD << " ";
	for (int i = loop;i < ADD;i ++) cout << use - 1 << " ";
	if (K % MOD) cout << use - 1;
	else cout << use + ADD;
	return 0;
}

/*
初期値を50、数列を全てaとすれば50回でa-1になる数列を作れる。


5
10 10 10 10 10
11 11 11 11 5
12 12 12 6 6
13 13 7 7 7
14 8 8 8 8
9 9 9 9 9

5
10 10 10 10 5
11 11 11 6 5
12 12 7 6 6
13 8 7 7 7
9 8 8 8 8
9 9 9 9 4
10 10 10 5 4
11 11 6 5 5
12 7 6 6 6
8 7 7 7 7

5
10 10 10 5 5
11 11 6 6 5
12 7 7 6 6
8 8 7 7 7
9 8 8 8 3
9 9 9 4 4
10 10 5 5 4
11 6 6 5 5
7 7 6 6 6

5
10 10 5 5 5
11 6 6 6 5
7 7 7 6 6
8 8 7 7 2
9 8 8 3 3
9 9 4 4 4
10 5 5 5 4
6 6 6 5 5

5
10 5 5 5 5
6 6 6 6 5
7 7 7 6 1
8 8 7 2 2
9 8 3 3 3
9 4 4 4 4
5 5 5 5 4
……

これより、Kを50で割り(少数以下切り上げ)、出た値に(49-Kを50で割った余り個)を足した値をKを50で割った余り個だけ並べる
ただし、Kが50で割り切れるなら50個とも出た値に49を足したものを並べる
次に、まだ並べていないものを全てKを50で割り(小数以下切り上げ)、出た値から1引いたものにする
*/

Measured memory_bytes: 256
#include <iostream>
#define MAX 100005
#define NIL -1

struct Node{int p,l,r;};

Node T[MAX];
int n,D[MAX];

void print(int u){
  int c;
  std::cout << "node " << u << ": ";
  std::cout << "parent = " << T[u].p << ", ";
  std::cout << "depth = " << D[u] << ", " ;
  
  if(T[u].p == NIL)std::cout << "root, ";
  else if(T[u].l == NIL) std::cout << "leaf, ";
  else std::cout << "internal node, ";
  
  std::cout << "[";
  
  for(int i = 0,c=T[u].l;c!=NIL;++i,c=T[c].r){
    if(i)std::cout<<", ";
    std::cout << c;
  }
  
  std::cout  << "]" <<std::endl;
}

int rec(int u,int p){
  D[u] = p;
  if(T[u].r != NIL)rec(T[u].r,p);
  if(T[u].l != NIL)rec(T[u].l,p + 1);
}

int main(){
  int v,d,c,l,r;
  std::cin >> n;
  for(int i=0;i<n;++i){
    T[i].p = T[i].l = T[i].r = NIL;
  }
  
  for(int i=0;i<n;++i){
    std::cin >> v >> d;
    for(int j=0;j<d;++j){
      std::cin >> c;
      if(j==0)T[v].l = c;
      else T[l].r =c;
      l=c;
      T[c].p = v;
    }
  }
  
  for(int i=0;i<n;++i){
    if(T[i].p == NIL) r=i;
  }
  
  rec(r,0);
  
  for(int i=0;i<n;++i){
    print(i);
  }
  
  return 0;
  
}

Measured memory_bytes: 7760
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n,a = 0,b = 0,c,d;
    cin >> n;
    cin >> c;
    d = c;
    for (int i = 1; i < n; i++){
        int x;
        cin >> x;
        a = min(a+abs(x-c), b + abs(x - d));
        swap(a,b);
        c = d;
        d = x;
    }
    cout << b;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
//#define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)

std::string highlight(std::string s) {
#ifdef _MSC_VER
    return s;
#else
    return "\033[33m" + s + "\033[0m";
#endif
}

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        print_to(os, ", ", "\n", __VA_ARGS__);            \
        std::cerr << highlight(os.str());                 \
    } while (0)
#define dump_(a)                                          \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #a << " = [";          \
        print_to_(os, ", ", "]\n", all(a));               \
        std::cerr << highlight(os.str());                 \
    } while (0)
#else
#define dump(...)
#define dump_(...)
#endif

template <typename T>
void print_to(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) {
    os << fst << del;
    print_to(os, del, tail, rst...);
}
template <typename Iter>
void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) {
    for (Iter it = bgn; it != end;) {
        os << *it;
        if (++it != end) {
            os << del;
        } else {
            os << tail;
        }
    }
}
template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, " ", "\n", fst, rst...);
}
template <typename Iter>
void println_(Iter bgn, Iter end) {
    print_to_(std::cout, "\n", "\n", bgn, end);
}
template <typename Iter>
void print_(Iter bgn, Iter end) {
    print_to_(std::cout, " ", "\n", bgn, end);
}

// const int MOD = 1000000007;
namespace trush {
    int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
             std::ios::sync_with_stdio(0), 0);
}

using namespace std;

int main() {
    int a, b, c, d;
    while (cin >> a >> b >> c >> d) {
        int A = a + b;
        int B = c + d;
        string ans = "Balanced";
        if (A > B) {
            ans = "Left";
        } else if (A < B) {
            ans = "Right";
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val datS = readLine.split("").filterNot(_.isEmpty).map(_.toInt).reverse

    import math.pow
    val combNum = pow(2, (datS.length - 1)).toInt

    var sum: Long = datS(0) * combNum
    for (i <- 1 until datS.length) {
      for (j <- 1 to (i + 1)) {
        val sum_ = datS(i) * pow(10, j - 1).toLong * (combNum >> j)
        if ((combNum >> j) == 0) sum += datS(i) * pow(10, j - 1).toLong
        if (j == (i + 1)) sum += sum_ * 2
        else sum += sum_
        //println("i=" + i + " j=" + j + " S=" + datS(i) + " sum_=" + sum_)
      }
    }

    val ans = sum
    println(ans)
  }
}


Measured memory_bytes: 27316
import java.util.*;
public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a=new int[m];
        int[] b=new int[m];
        long[] ans=new long[m];
        Unionfind uf = new Unionfind(n);
        
        for(int i=0; i<m; i++){
            a[i] = sc.nextInt()-1;
            b[i] = sc.nextInt()-1;
        }
        
        ans[0] = n*(long)(n-1)/2;

        for (int i=1; i<m; i++) {
            if(uf.same(a[m-i],b[m-i])){
                ans[i] = ans[i-1];
            }else{
                ans[i] = ans[i-1] - uf.getSize(a[m-i])*(long)uf.getSize(b[m-i]);
            }
            uf.union(a[m-i],b[m-i]);
        }

        for(int i=0; i<m; i++){
            System.out.println(ans[m-1-i]);
        }
    }

	static class Unionfind {
		 
			private int[] data;
			private int []size;
			
			public Unionfind(int size) {
				this.data = new int [size];
				this.size = new int [size];
				for(int i = 0 ;i < size ;i++) {
					initnode(i);
				}
				clear();
			}
			
			public void initnode(int i) {
				size[i] = 1;
			}
			
			public void clear() {
				Arrays.fill(data, -1);
			}
			
			public void union(int x , int y ) {
				if((x = root(x)) != (y = root(y))) {
					if(data[y] < data[x]) {
						final int t = x;
						x = y;
						y = t;
					}
					data[x] += data[y];
					size[root(x)] += size[root(y)];
					data[y] = x;
				}
			}
			
			public int getSize(int i) {
				return size[root(i)];
			}
			
			public int root(int x) {
				if(data[x] < 0) {
					return x;
				}
				else {
					return data[x] = root(data[x]);
				}
			}
			
			public boolean same(int x, int y) {
				return root(x) == root(y);
			}
			
		}

}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    int A[3][3];

    cin >> A[0][0] >> A[0][1] >> A[0][2];
    cin >> A[1][0] >> A[1][1] >> A[1][2];
    cin >> A[2][0] >> A[2][1] >> A[2][2];

    bool B[3][3];

    REP(i,3){
        REP(j,3){
            B[i][j] = false;
        }
    }

    int N;
    cin >> N;
    vector<int> b(N);
    REP(i, N){
        cin >> b[i];
        REP(j,3){
            REP(k,3){
                if(A[j][k] == b[i]){
                    B[j][k] = true;
                }
            }
        }
    }
    REP(i,3){
        if(B[i][0] == true){
            if(B[i][1] == true){
                if(B[i][2] == true){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    REP(i,3){
        if(B[0][i] == true){
            if(B[1][i] == true){
                if(B[2][i] == true){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    if(B[0][0] == true){
        if(B[1][1] == true){
            if(B[2][2] == true){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    if(B[0][2] == true){
        if(B[1][1] == true){
            if(B[2][0] == true){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    
    
    int i, ii, iii;
    int N, K;
    int tmp;
    int d;
    int c[100] = {};
    int a =0 ;
    scanf("%d %d", &N, &K);
    for (i = 0; i < K; i++)
    {
        scanf("%d", &d);
        for (ii = 0; ii < d; ii++)
        {
            scanf("%d ", &tmp);
            c[tmp - 1] = 1;
                }
            
    }
    for (i = 0; i < N; i++)
    {
        if (c[i] == 0)
            a++;
    }
    printf("%d", a);
    return (0);
}


Measured memory_bytes: 1724
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main d = new Main();
        d.solve();
    }


    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int m = scan.nextInt();
        UnionTree edges = new UnionTree(n);
        int[] data = new int[n];
        for (int i = 0; i < n; i++) {
            data[i] = scan.nextInt() - 1;
        }
        for (int i = 0; i < m; i++) {
            int x = scan.nextInt() - 1;
            int y = scan.nextInt() - 1;
            edges.unite(x, y);
        }
        System.out.println(solve(n, data, edges));
    }

    public static int solve(int n, int[] data, UnionTree edges) {
        int[] check = new int[n];
        for(int i = 0; i < n; i++) {
            check[data[i]] = i;
        }
        int count = 0;
        for(int i = 0; i < n; i++) {
            if (i == data[i]) {
                count++;
                continue;
            }
            if (edges.same(i, check[i])) {
                count++;
            }
        }
        return count;
    }

    class UnionTree {
        private int[] parents;
        public UnionTree(int n) {
            this.parents = new int[n];
            Arrays.fill(parents, -1);
        }
        public boolean same(int x, int y) {
            return this.root(x) == this.root(y);
        }

        public void unite(int x, int y) {
            int parent_x = root(x);
            int parent_y = root(y);
            if (parent_x == parent_y) {
                return;
            }
            if (this.parents[parent_x] < this.parents[parent_y]) {
                this.parents[parent_x] += this.parents[parent_y];
                this.parents[parent_y] = parent_x;
            } else {
                this.parents[parent_y] += this.parents[parent_x];
                this.parents[parent_x] = parent_y;
            }
        }

        public int root(int x) {
            if (this.parents[x] < 0) {
                return x;
            }
            return this.root(this.parents[x]);
        }
    }
}


Measured memory_bytes: 90312