akhauriyash/Code-Regression huggingface dataset:
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntSet as IntSet
import Data.Foldable
import Control.Monad.ST

main = do
  [n,m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [u,v] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (u-1,v-1)
  [s,t] <- map (subtract 1) . unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let graph :: V.Vector IntSet.IntSet
      graph = V.create $ do
        vec <- VM.replicate (3 * n) IntSet.empty
        U.forM_ edges $ \(u,v) -> do
          modify' vec (IntSet.insert (3 * v + 1)) (3 * u)
          modify' vec (IntSet.insert (3 * v + 2)) (3 * u + 1)
          modify' vec (IntSet.insert (3 * v)) (3 * u + 2)
        return vec
      result = runST $ do
        visited <- UM.replicate (3 * n) False
        let !target = 3 * t
        -- bfs :: Int -> [Int] -> ST s (Maybe Int)
        let bfs !depth ss = do
              forM_ ss $ \u ->
                UM.write visited u True
              let ts = foldMap (graph V.!) ss
              if target `IntSet.member` ts
                then return $ Just (depth `quot` 3)
                else do ts' <- filterM (\v -> not <$> UM.read visited v) (IntSet.toList ts)
                        if null ts'
                          then return Nothing
                          else bfs (depth+1) ts'
        bfs 1 [3 * s]
  case result of
    Nothing -> putStrLn "-1"
    Just d -> print d

modify' :: VM.MVector s a -> (a -> a) -> Int -> ST s ()
modify' vec f !i = do x <- VM.read vec i
                      VM.write vec i $! f x

foldMap_IntSet :: (Monoid n) => (Int -> n) -> IntSet.IntSet -> n
foldMap_IntSet f set = go set
  where
    go set = case IntSet.splitRoot set of
               [] -> mempty
               [x] -> foldMap f (IntSet.toList x)
               xs -> foldMap go xs

forM_IntSet :: Monad m => IntSet.IntSet -> (Int -> m ()) -> m ()
forM_IntSet set f = go set
  where
    go set = case IntSet.splitRoot set of
               [] -> return ()
               [x] -> forM_ (IntSet.toList x) f
               xs -> forM_ xs go

foldMapM_IntSet :: (Monoid n, Monad m) => (Int -> m n) -> IntSet.IntSet -> m n
foldMapM_IntSet f set = go set
  where
    go set = case IntSet.splitRoot set of
               [] -> return mempty
               [x] -> foldlM (\x v -> mappend x <$> f v) mempty (IntSet.toList x)
               xs -> foldlM (\x set' -> mappend x <$> go set') mempty xs


Measured memory_bytes: 37244
from math import sin, cos, pi

def koch_curve(d, p1, p2):
    if d == 0:
        return

    s = [None, None]
    u = [None, None]
    t = [None, None]
    
    s[0] = (2*p1[0] + p2[0])/3
    s[1] = (2*p1[1] + p2[1])/3
    t[0] = (p1[0] + 2*p2[0])/3
    t[1] = (p1[1] + 2*p2[1])/3
    u[0] = (t[0] - s[0])*cos(1/3*pi) - (t[1] - s[1])*sin(1/3*pi) + s[0]
    u[1] = (t[0] - s[0])*sin(1/3*pi) + (t[1] - s[1])*cos(1/3*pi) + s[1]

    koch_curve(d-1, p1, s)
    print(s[0], s[1])
    koch_curve(d-1, s, u)
    print(u[0], u[1])
    koch_curve(d-1, u, t)
    print(t[0],t[1])
    koch_curve(d-1, t, p2)

num = int(input())
print(0.0, 0.0)
koch_curve(num, [0.0, 0.0], [100.0, 0.0])
print(100.0, 0.0)


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

using namespace std;

int main()
{ 
	int N;
	cin >> N;

	unsigned long long ans = 0;
	for (int i = 1; i <= N; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			ans += i;
		}
	}

	cout << ans;
}

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

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<string> s(n);
    vector<vector<int>> cnt(n, vector<int>(26));
    map<vector<int>, ll> M;
    rep(i, n){
        cin >> s[i];
    }
    rep(i, n){
        for(auto &x : s[i]){
            ++cnt[i][(int)(x - 'a')];
        }
        ++M[cnt[i]];
    }

    ll ans = 0;
    for(auto it = M.begin(), end = M.end(); it != end; ++it){
        ans += it->se * (it->se - 1) / 2;
    }

    cout << ans << endl;

return 0;
}

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

string s = "?',.!";
int main() {
	string a;
	while (cin >> a) {
		a += "#";
		for (int b = 0; b<a.length() - 1; b++) {
			for (int c = b; c<a.length(); c++) {
				if (a[b] != a[c + 1]) {
					int k = c - b + 1;
					switch (a[b]) {
					case '0':for (int i = 1; i<k; i++)cout << " "; break;
					case '1':k %= 5; cout << s[k]; break;
					case '7':k %= 8;
						switch (k) {
						case 0:cout << 'S'; break;
						case 1:cout << 'p'; break;
						case 2:cout << 'q'; break;
						case 3:cout << 'r'; break;
						case 4:cout << 's'; break;
						case 5:cout << 'P'; break;
						case 6:cout << 'Q'; break;
						case 7:cout << 'R'; break;
						}break;
					case '8':k %= 6;
						switch (k) {
						case 0:cout << 'V'; break;
						case 1:cout << 't'; break;
						case 2:cout << 'u'; break;
						case 3:cout << 'v'; break;
						case 4:cout << 'T'; break;
						case 5:cout << 'U'; break;
						}break;
					case '9':k %= 8;
						switch (k) {
						case 0:cout << 'Z'; break;
						case 1:cout << 'w'; break;
						case 2:cout << 'x'; break;
						case 3:cout << 'y'; break;
						case 4:cout << 'z'; break;
						case 5:cout << 'W'; break;
						case 6:cout << 'X'; break;
						case 7:cout << 'Y'; break;
						}break;
					default:k %= 6;
						switch (k) {
						case 0:cout << char((a[b] - '2') * 3 + 'C'); break;
						case 1:cout << char((a[b] - '2') * 3 + 'a'); break;
						case 2:cout << char((a[b] - '2') * 3 + 'b'); break;
						case 3:cout << char((a[b] - '2') * 3 + 'c'); break;
						case 4:cout << char((a[b] - '2') * 3 + 'A'); break;
						case 5:cout << char((a[b] - '2') * 3 + 'B'); break;
						}
					}
					b = c; break;
				}
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 2960
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<double, int>;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n; cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int sum = accumulate(a.begin(), a.end(), 0);

    double ave = sum / (double)n;

    P ans(101, 101);
    REP(i, n) {
        double diff = abs((double)a[i] - ave);
        ans = min(ans, P(diff, i));
    }

    cout << ans.second << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

int main(){
    ll i,n,a[300002],j,ans=0,x,temp;
    scanf("%lld",&n);
    for (i=0; i<n; i++) scanf("%lld",&a[i]);
    for (i=0; i<60; i++) {
        x=0;
        for (j=0; j<n; j++) if (a[j]>>i&1) x++;
        temp=(x*(n-x))%MOD;
        for (j=0; j<i; j++) temp=(temp*2)%MOD;
        ans+=temp%MOD;
        ans%=MOD;
    }
    printf("%lld",ans%MOD);
    return 0;
}



Measured memory_bytes: 2560
using System;
using System.IO;

namespace Contest
{
    class Program
    {
        public void Solve()
        {
            var sc = new Scanner();

            int a = sc.NextInt();
            for (int i = 0; i < 3; i++)
            {
                sc.Next();
            }

            int e = sc.NextInt();
            int k = sc.NextInt();
            if (e - a > k)
            {
                Console.WriteLine(":(");
            }
            else
            {
                Console.WriteLine("Yay!");
            }

        }


        static void Main(string[] args) => new Program().Solve();
    }

    class Scanner
    {
        private char _separator = ' ';
        private StreamReader _stream = new StreamReader(Console.OpenStandardInput());
        private int _pos = 0;
        private string[] _line = new string[0];
        public string Next()
        {
            if (_pos >= _line.Length)
            {
                _line = _stream.ReadLine().Split(_separator);
                _pos = 0;
            }
            return _line[_pos++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public string[] Array()
        {
            if (_pos >= _line.Length)
                _line = _stream.ReadLine().Split(_separator);
            _pos = _line.Length;
            return _line;
        }
        public int[] IntArray()
        {
            var arr = Array();
            var res = new int[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = int.Parse(arr[i]);
            }
            return res;
        }
        public long[] LongArray()
        {
            var arr = Array();
            var res = new long[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = long.Parse(arr[i]);
            }
            return res;
        }
        public double[] DoubleArray()
        {
            var arr = Array();
            var res = new double[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = double.Parse(arr[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;
const int MAX = 1e5+10;
const double exps = 1e-8;

inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }

int main () {
    ll n,m;
    cin >> n >> m;
    if(n==1||m==1) {
        cout<<1;return 0;
    }
    ll t1=(m%2==0)?m/2:m/2+1;
    ll t2=m/2+t1;
    ll s1=n/2*t2;
    if(n&1) s1+=t1;
    cout<<s1;
}

Measured memory_bytes: 764
import collections
nmax = 10**6+1
mod = 10**9+7

fac = [1]*nmax
finv = [1]*nmax
inv = [1]*nmax
def ncr_pre():
    for i in range(2,nmax):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i] %mod

def factorize(n):
    b = 2
    fct = [(1,1)]
    while b * b <= n:
        cnt =0
        while n % b == 0:
            n //= b
            cnt +=1
        if cnt >=1:
            fct.append((b,cnt))
        b = b + 1
    if n > 1:
        fct.append((n,1))
    return fct

ncr_pre()

n = int(input())
a = list(map(int,input().split()))
co = collections.Counter()
for i in range(n):
    for num,cnt in factorize(a[i]):
        co[num] = max(co[num],cnt)

lcm= 1
for num,cnt in co.items():
    lcm *= num**cnt
    lcm%=mod

ans = 0
for i in range(n):
    ans += lcm*inv[a[i]]
    ans %=mod
print(ans)


Measured memory_bytes: 69340
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int N=1e5+5;
const int inf=0x3f3f3f3f;
ll dp[3][N]={inf},v[3][N],k,n;

ll check(int index);


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
ll i,j,m;
memset(dp,-1,sizeof(dp));

    cin>>n;
    for(i=0;i<n;i++)
        cin>>v[0][i]>>v[1][i]>>v[2][i];
    for(auto it:{0,1,2})
        dp[it][0]=v[it][0];
    for(i=1;i<n;i++){
        for(auto it:{0,1,2}){
            for(auto iit:{0,1,2}){
                if(it!=iit)
                    dp[it][i]=max(dp[it][i],v[it][i]+dp[iit][i-1]);
            }
        }
    }
    cout<<max({dp[0][n-1],dp[1][n-1],dp[2][n-1]})<<"\n";
    // for(auto it:{0,1,2})
    //     for(i=0;i<n;i++)
    //         cout<<dp[it][i]<<" \n"[i==n-1];
    return 0;
}



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

int main() {

    int n;
    cin >> n;

    bool check = false;
    string result = "DENIED";
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        result = "APPROVED";
        if(a[i] % 2 == 0) {
            if(a[i] % 3 != 0 && a[i] % 5 != 0) {
                check = true;
            }
        }
    }

    if(check) {
        cout << "DENIED" << '\n';
    } else {
        cout << result << '\n';
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
const ll mod = 1e9+7;
const ll inf = 1e10;
const double pi = 3.141592;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}

template<class T>
bool contain(const string& s, const T& v){
  return s.find(v) != std::string::npos;
}

ll f(int a, int b){
  if(a == b || a == 0 || b == 0) return 1;
  else return f(a-1, b-1)%mod+f(a-1, b)%mod;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, h;
  cin >> n >> h;
  int amax = 0;
  priority_queue<int> b;
  rep(i, n){
    int ta, tb;
    cin >> ta >> tb;
    amax = max(amax, ta);
    b.push(tb);
  }
  int ans = 0;
  while(h > 0 && amax < b.top() && !b.empty()){
    h -= b.top();
    b.pop();
    ++ans;
  }
  while(h > 0){
    h -= amax;
    ++ans;
  }
  cout << ans << "\n";
  return 0;
}

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

const int mod = 998244353;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
    return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0;i <= 999;i++){
        string d = "";
        d.push_back('0' + i/100);
        d.push_back('0' + (i%100)/10);
        d.push_back('0' + (i%10));
        int dig = 0;
        int j = 0;
        while(dig < 3){
            if(j == n) break;
            if(s[j] == d[dig]){
                //cout << d << " "<< dig<<endl;
                dig++;
            }
            j++;
        }
        if(dig==3) ans++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3656
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

N = int(input())

primes = []
mod = 1
count = 0
for i in range(2,55555+1):
    if i%5 == mod and is_prime(i):
        primes.append(i)
        count += 1
    if count == N:
        break

print(*primes)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;

void solve(){
	set<string> g[100],ans;
	vector<string> s;
	set<string>::iterator ite;
	rep(i,n){
		string str;
		cin >> str;
		int st;
		rep(j,str.size()){
			if(str[j] == ':'){
				s.pb(str.substr(0,j));
				st = j;
				break;
			}
		}
		for(int j = st+1; j < str.size(); j++){
			if(str[j] == ','){
				g[i].insert(str.substr(st+1,j-st-1));
				st = j;
			}
			if(str[j] == '.'){
				g[i].insert(str.substr(st+1,j-st-1));
				break;
			}
		}
	}
	queue<string> que;
	set<string> used;
	for(ite = g[0].begin(); ite != g[0].end(); ite++){
		que.push(*ite);
		used.insert(*ite);
	}
	while(true){
	if(que.size() == 0) break;
		string str = que.front(); que.pop();
		bool check = false;
		for(int i = 1; i < n; i++){
			if(str == s[i]){
				check = true;
				for(ite = g[i].begin(); ite != g[i].end(); ite++){
					if(used.find(*ite) == used.end()){
						que.push(*ite);
						used.insert(*ite);
					}
				}
				break;
			}
		}
		if(!check) ans.insert(str);
	}
	cout << ans.size() << endl;
	/*
	for(ite = ans.begin(); ite != ans.end(); ite++){
		cout << *ite << " ";
	}
	cout << endl;
	*/
}

int main(){
	while(scanf("%d", &n),n) solve();
}

Measured memory_bytes: 1420
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0

for a in range(A + 1) :
    for b in range(B + 1) :
        for c in range(C + 1) :
            if 500 * a + 100 * b + 50 * c == X :
                cnt += 1

print(cnt)

Measured memory_bytes: 3188
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int R = sc.nextInt();
		
		System.out.println(N>=10 ? R : R + (100*(10-N)));
		
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
int main()
{
	int a,b,c,ans;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b) {
		printf("%d\n",c);
	}
	else if(a==c) {
		printf("%d\n",b);
	}else{
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

int Gauss2(double x)
{
	int p=x;

	if(x==(double)p || x>0)
	{
		return p;
	}
	else
	{
		return p-1;
	}

}

int main()
{
	const double g = 9.8, HiPerStair = 5.0;

	double v;

	while(std::cin >> v)
	{
		std::cout << Gauss2(v*v/g/HiPerStair/2.0+1.0)+1 << '\n';
		//vが崩壊速度なので v^2 < 2*9.8*y　で壊れる nは階数として　y=HiPerStair*(n-1)　ｎを直接求める式
	}
}

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

int main() {
  ll N, M;
  cin >> N >> M;

  priority_queue<double> pq;

  for (ll i = 0; i < N; i++) {
    double tmp;
    cin >> tmp;
    pq.push(tmp);
  }

  //top が最大値
  for (ll i = 0; i < M; i++) {
    double top = pq.top(); pq.pop();
    pq.push(top/2);
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ans += (ll) pq.top();
    pq.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    char str0[105]={0};
    scanf("%s", str0);

    char str[105]={0};
    strcpy( str, str0);
    
    long i;

    while(1) {
        bool modify=false;
        for(i=0; i<n-1; i++) {
            if(str[i]=='(' && str[i+1]==')') {
                long k;
                for(k=i; k<n; k++) {
                    str[k] = str[k+2];
                }
                modify=true;
                break;
            }
        }
        if(modify) continue;
        else break;
    }

    long len=strlen(str);
    for(i=0; i<len; i++) {
        if(str[i]==')') {
            printf("(");
        }
        else {
            break;
        }
    }
    printf("%s", str0);
    
    for(i=len-1; i>=0; i--) {
        if(str[i]=='(') {
            printf(")");
        }
        else {
            break;
        }
    }

    printf("\n");
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


vector<vector<vector<int> > > dp(2020, vector<vector<int> >(2020, vector<int>(2, -1)));
int n, m;
string s1, s2;

int dfs(int s, int t, int odd){
  if(dp[s][t][odd]!=-1) return dp[s][t][odd];
  
  int ret=0;
  if(odd){
    if(s<m && s1[s]=='O') ret=max(ret, dfs(s+1, t, odd^1)+1);
    if(t<n && s2[t]=='O') ret=max(ret, dfs(s, t+1, odd^1)+1);
  }
  else{
    if(s<m && s1[s]=='I') ret=max(ret, dfs(s+1, t, odd^1)+1);
    if(t<n && s2[t]=='I') ret=max(ret, dfs(s, t+1, odd^1)+1);
  }

  return dp[s][t][odd]=ret;
}

int main(){
  cin >> m >> n;
  cin >> s1 >> s2;

  int ans=0;
  REP(i, m+1){
    REP(j, n+1){
      ans=max(ans, dfs(i, j, 0));
    }
  }

  if(ans==0) printf("0\n");
  else if(ans%2==0) printf("%d\n", ans-1);
  else printf("%d\n", ans);
}

Measured memory_bytes: 224880
import math

n = int(input())

a = [int(i) for i in input().split(" ")]
ar = a[::-1]
a = [0] + a
ar = [0] + ar
s = [0] * (n + 1)
sr = [0] * (n + 1)
li = 0
ri = n

for i in range(1, n + 1):
    s[i] = a[i] + s[i - 1]
    sr[i] = ar[i] + sr[i - 1]
    
def f(a):
    return max(a) - min(a)

def fs(rr):
    global li
    while abs(s[rr] - 2 * s[li]) > abs(s[rr] - 2 * s[li + 1]):
        li += 1
        
def fsr(rr):
    global ri
    while abs(sr[rr] - 2 * sr[ri]) > abs(sr[rr] - 2 * sr[ri - 1]):
        ri -= 1

m_min = 2 * 10**14
for i in range(2, n - 1):
    fs(i)
    fsr(n - i)
    m = f([s[li], s[i] - s[li], sr[ri], sr[n - i] - sr[ri]])
    if m < m_min:
        m_min = m
        
print(m_min)

Measured memory_bytes: 32008
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] sw = new int[m][];
		for (int i = 0; i < m; i++) {
			sw[i] = new int[sc.nextInt()];
			for (int j = 0; j < sw[i].length; j++) {
				sw[i][j] = sc.nextInt();
			}
		}
		int[] arr = new int[m];
		for (int i = 0; i < m; i++) {
			arr[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 0; i < Math.pow(2, n); i++) {
			boolean[] on = new boolean[n];
			int x = i;
			for (int j = 0; j < n; j++) {
				on[j] = (x % 2 == 1);
				x /= 2;
			}
			boolean flag = true;
			for (int j = 0; j < m; j++) {
				int ps = 0;
				for (int k = 0; k < sw[j].length; k++) {
					if (on[sw[j][k] - 1]) {
						ps++;
					}
				}
				if (ps % 2 != arr[j]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				count++;
			}
		}
		System.out.print(count);
	}
}


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

int main(void)
{
  int N, A, B;
  string str;
  cin >> N >> A >> B;
  cin >> str;
  int a_qualify = 0, b_qualify = 0;
  auto sum_qualify = [&a_qualify, &b_qualify](){
  	return a_qualify + b_qualify;
  };
  for(char c: str){
    bool is_qualify = false;
    switch(c)
    {
      case 'a':
        if ( sum_qualify() < A + B )
        {
          is_qualify = true;
          a_qualify++;
        }
        break;
      case 'b':
        if ( sum_qualify() < A + B && b_qualify < B )
        {
          is_qualify = true;
          b_qualify++;
        }
        break;
      default:
        break;
    }
    cout << (is_qualify ? "Yes" : "No") << endl;
  }
}

Measured memory_bytes: 896
#include<iostream>
#include<queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s)
{
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while (!q.empty())
    {
        u = q.front();
        q.pop();
        for (int v = 0; v < n; v++)
        {
            if (M[u][v] == 0) continue;
            if (d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << i + 1 << " " << ( (d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}

int main()
{
    int u, k, v;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);
    
    return 0;
}


Measured memory_bytes: 3116
S = input()

n = len(S)-1
ans = 0

for i in range(2**(n)):
    locs = []
    for j in range(n):
        if (i>>j) & 1:
            # 右からj番目にフラグが立っている
            locs.append(j+1)
    S2 = S
    for j in reversed(locs):
        S2 = S2[:j] + "+" + S2[j:]
    ans += eval(S2)
print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
	
const int maxN = 1 << 19, mod = 998244353;

template <class T1, class T2> inline void addMod(T1& a, T2 b)	{   a = (a + b) % mod;  }
template <class T1, class T2> inline void multMod(T1& a, T2 b)	{   a = a * b % mod;    }

long long qpow(long long a, long long b)
{
    long long ret = 1;
    for (; b!=0; b>>=1)
    {
        if (b & 1)  multMod(ret, a);
        multMod(a, a);
    }
    return ret;
}

map <pair <int, int>, int> M;

long long pref10[maxN], res;
int n;

void modf(int i, int j, int d)
{
	int pi = n-i, pj = n-j;
	long long dx = pref10[pi];
	if (pj != 0)
		addMod(dx, mod - pref10[pj-1]);
	multMod(dx, d);
	addMod(res, dx);
}

void dod(int i, int j, int d)
{
	M[{i, j}] = d;
	modf(i, j, d);
}

void usu(auto it)
{
	modf(it->ft.ft, it->ft.sd, mod - it->sd);
	M.erase(it);
}

void solve()
{	
	int q;
	scanf ("%d%d", &n, &q);
	pref10[0] = 1ll;
	FOR(i, 1, n+3)
		pref10[i] = (pref10[i-1] * 10 + 1ll) % mod;
	dod(1, n, 1);	
	while (q--)
	{
		int i, j, d;
		scanf ("%d%d%d", &i, &j, &d);
		auto it = prev(M.upper_bound(make_pair(i, n+1)));
		int a = it->ft.ft, b = it->ft.sd, t = it->sd;
		
		if (a != i)
			dod(a, i-1, t);
			
		while (it != M.end() and it->ft.sd <= j)
			usu(it++);
			
		if (it != M.end())
		{
			b = it->ft.sd, t = it->sd;
			usu(it);
			dod(j+1, b, t);
		}	
		
		dod(i, j, d);
		printf("%lld\n", res);
	}
}

 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}





Measured memory_bytes: 17876
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let mut x: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    x.sort();

    let mut memo: Vec<Vec<usize>> = vec![Vec::new(); 100010];
    let mut ans = 0;
    for i in 0..n {
        memo[x[i] % m].push(x[i]);
    }
    for i in 0..m / 2 + 1 {
        if i == 0 || (m % 2 == 0 && i == m / 2) {
            ans += memo[i].len() / 2;
        } else {
            let mut a = memo[i].clone();
            let mut b = memo[m - i].clone();
            if a.len() < b.len() {
                std::mem::swap(&mut a, &mut b);
            }
            let mut same = 0;
            let mut idx = 0;
            while idx < a.len() {
                while idx < a.len() - 1 && a[idx] == a[idx + 1] {
                    idx += 2;
                    same += 1;
                }
                idx += 1;
            }
            ans += b.len() + std::cmp::min((a.len() - b.len()) / 2, same);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,a;
    cin>>n>>a;
    vec A(n);
    rep(i,n) cin>>A[i];
    rep(i,n) A[i]-=a;
    ll dp[100][5001]={0};
    dp[0][2500]=1;
    rep(i,n)rep(j,5001){
        dp[i+1][j]=dp[i][j];
        if(j+A[i]>=0) dp[i+1][j]+=dp[i][j+A[i]];
    }
    cout<<dp[n][2500]-1;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int n, a;
    cin>>n;
    vector<int> as;
    rep(i, n) {
        cin>>a;
        as.push_back(a);
    }
    rep(i, n-1) {
        cout<<as.back()<<" ";
        as.pop_back();
    }
    cout<<as.back()<<endl;
}


Measured memory_bytes: 3140
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
vector<int> a(100100);

int main() {
    int n, q; cin >> n >> q;
    long long sum[n+1] = {}, sum2[n+1] = {};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
        if (i >= 2) sum2[i] = sum2[i-2] + a[i];
        else sum2[i] = a[i];
    }
    a.resize(n);

    while (q--) {
        int x; cin >> x;
        if (x >= a[n-2]) { cout << sum2[n-1] << endl; continue; }
        int lb = 0, ub = 1<<30;
        while (ub - lb > 1) {
            int mid = (lb + ub) / 2;
            int right = upper_bound(a.begin(), a.end(), x + mid) - a.begin() - 1,
                left = lower_bound(a.begin(), a.end(), x - mid) - a.begin();
            if (n - (right - left + 1) > right) lb = mid;
            else ub = mid;
        }
        int right = upper_bound(a.begin(), a.end(), x + lb) - a.begin() - 1,
            left = lower_bound(a.begin(), a.end(), x - lb) - a.begin(),
            t = n - (right - left + 1);
        long long ans = 0;
        ans += sum[n] - sum[t];
        bool turn_T = true;
        while (t - right > 1) {
            if (turn_T) ans += a[--t];
            else if (left > 0 && x - a[left-1] <= a[right+1] - x) left--;
            else right++;
            turn_T = !turn_T;
        }
        if (turn_T && left > 0) ans += sum2[left-1];
        else if (left > 1) ans += sum2[left-2];
        cout << ans << endl;
    }
}


Measured memory_bytes: 3712
//In the Name of Allah Most Gracious, Most Merciful//
/*If you want something you've never had, you have  to do something you never did.*/

#include<bits/stdc++.h>
using namespace std;


#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define M 100007
#define INF 1e9
#define INFL 1e18
#define PI acos(-1)
#define mp make_pair

//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
int n;
int dp[100100];
int arr[100100];



int mydp(int i)
{
    if(i>=n)
    {
        return 0;
    }
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    int ret1=INF,ret2=INF;
    if(i+2<=n)
    {
        ret1=abs(arr[i+2]-arr[i])+mydp(i+2);
    }
    if(i+1<=n)
    {
        ret2=abs(arr[i+1]-arr[i])+mydp(i+1);
    }
    dp[i]=min(ret1,ret2);
    return dp[i];
}
int main()
{

   //  #ifndef ONLINE_JUDGE
   //    freopen("input.txt","r",stdin);
   //    freopen("output.txt","w",stdout);
  //   #endif
  int k;
  cin>>n>>k;
  for(int i=1;i<=n;i++)
  {
      cin>>arr[i];
  }
  for(int i=0;i<=100000;i++)
  {
      dp[i]=INF;
  }
  dp[0]=dp[1]=0;
  for(int i=2;i<=n;i++)
  {
      for(int j=i-1;j>=max(1,i-k);j--)
      {

          dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
         // cout<<i<<" "<<j<<" "<<dp[i]<<endl;
      }
  }
  cout<<dp[n]<<endl;

}



Measured memory_bytes: 4412
// https://abc085.contest.atcoder.jp/tasks/abc085_c

package main
 
import "fmt"
 
func main() {
	var n, y int
	fmt.Scan(&n, &y)
	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			if i*10000+j*5000+(n-i-j)*1000 == y {
				fmt.Println(i, j, n-i-j)
				return
			}
		}
	}
	fmt.Println("-1 -1 -1")
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n;
    cin >> n;
    vector<int> a(n),b(n);
    ll sum=0;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) sum+=b[i]-a[i];
    // cout << sum << endl;

    bool ans=true;
    rep(i,n){
        if(a[i]<b[i]){
            sum-=(b[i]-a[i]+1)/2;
        }
        if(sum<0) ans=false;
        if(!ans) break;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3716
// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <assert.h>
#include <complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 200005, M = 505;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;
const double PI = acos(-1.0);

int n, cnt, cmp, idx[N], low[N], comp[N], val[N], compH[N];
bool inStack[N];
stack<int> stk;
vector<vector<int> > g;

inline int Not(int u) {
	return u >= n ? u - n : u + n;
}

inline void add(int a, int b) {
	g[Not(a)].push_back(b);
	g[Not(b)].push_back(a);
}

void dfs(int u) {
	idx[u] = low[u] = ++cnt;
	inStack[u] = 1;
	stk.push(u);
	for (int i = 0; i < g[u].size(); i++) {
		int v = g[u][i];
		if (!idx[v])
			dfs(v);
		if (inStack[v])
			low[u] = min(low[u], low[v]);
	}
	if (idx[u] == low[u]) {
		while (1) {
			int v = stk.top();
			stk.pop();
			inStack[v] = 0;
			comp[v] = cmp;
			if (v == u) break;
		}
		compH[cmp++] = u;
	}
}

int main() {
	scanf("%d", &n);
	g.resize(2 * n);
	for (int i = 1, a, b, c; i < n; i++) {
		scanf("%d%d%d", &a, &b, &c);
		a--, b--;
		if (c & 1) {
			add(Not(a), Not(b));
			add(a, b);
		}
		else {
			add(Not(a), b);
			add(a, Not(b));
		}
	}
	for (int i = 0; i < 2 * n; i++)
		if (!idx[i])
			dfs(i);
	bool ok = 1;
	for (int i = 0; i < n; i++) {
		if (comp[i] == comp[Not(i)]) {
			ok = 0;
			break;
		}
		val[comp[i]] = 0;
		val[comp[Not(i)]] = 1;
	}
	for (int i = 0; i < n; i++)
		printf("%d\n", val[comp[i]]);
	return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int N, M, Q, ans;
vector<int> a, b, c, d, A;

void dfs(int length, int pre){
	if(length==N){
		int sum=0;
		rep(i,Q){
			if(A[b[i]-1]-A[a[i]-1]==c[i]) sum+=d[i];
		}
		ans=max(ans,sum);
		return;
	}
	for(int i=pre; i<=M; i++){
		A[length]=i;
		dfs(length+1, i);
	}
}

int main(){
	cin >> N >> M >> Q;
	a = b = c = d = vector<int>(Q,0);
	A = vector<int>(N,0);
	rep(i,Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
	ans=0;
	dfs(0,1);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3588
N = int(input())
C = input()

left = 0
right = N -1

ans = 0
while left < right:
    if C[left] == 'W' and C[right] == 'R':
        left += 1
        right -= 1
        ans += 1
    elif C[left] == 'W':
        right -= 1
    elif C[left] == 'R':
        left += 1
print(ans)

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

pair<int, int> dfs(vector<vector<int>> &g, int v, vector<int> &bs, int b, int &f){
	pair<int, int> ans(0, 0);
	if(bs[v] != -1){
		if(bs[v] != b){
			f = 1;
		}
	}
	else{
		bs[v] = b;
		if(b == 0){
			ans.first++;
		}
		else{
			ans.second++;
		}
		for(int i = 0; i < g[v].size(); i++){
			pair<int, int> res = dfs(g, g[v][i], bs, 1 - b, f);
			ans.first += res.first;
			ans.second += res.second;
		}
	}
	return ans;
}

signed main(){
	int N, M, a, b, i;
	scanf("%lld%lld", &N, &M);
	vector<vector<int>> g(N, vector<int>(0));
	for(i = 0; i < M; i++){
		scanf("%lld%lld", &a, &b);
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<int> bs(N, -1);
	vector<pair<int, int>> ps(0);
	int f = 0;
	for(i = 0; i < N; i++){
		if(bs[i] == -1){
			ps.push_back(dfs(g, i, bs, 0, f));
			if(f == 1){
				printf("-1\n");
				return 0;
			}
		}
	}
/*	for(i = 0; i < ps.size(); i++){
		printf("(%lld, %lld)\n", ps[i].first, ps[i].second);
	}
*/	bitset<50001> dp(1);
	for(i = 0; i < ps.size(); i++){
		dp = ((dp << ps[i].first) | (dp << ps[i].second));
	}
	int near_half = 0;
	for(i = 0; i <= N / 2; i++){
		if(dp[i] == 1){
			near_half = max(near_half, i);
		}
	}
	printf("%lld\n", near_half * (N - near_half) - M);
	return 0;
}


Measured memory_bytes: 10244
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll x, a, b;
  cin >> x >> a >> b;

  if(abs(x - a) < abs(x - b)) cout << 'A' << endl;
  else cout << 'B' << endl;
  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main {
  def fib(a:Int, b:Int, c:Int, n:Int):Int = {
    if (n ==  0)
      a
    else
      fib(a+b, a, b, n-1)
  }

  def main(args: Array[String]) = {
    val n = readInt()
    println(fib(1, 0, 0, n))
  }
}

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

const int n = 753;

int main() {
	string s; cin >> s;
	int ans = 1000;
	int l = s.size();
	for (int i = 0; i < l-2; i++) {
		string t = s.substr(i, 3);
		ans = min(ans, abs(n - stoi(t)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
typedef long long ll;
int main(){
    ll k,a,b;
    cin>>k>>a>>b;
 
    if(b<=a+1)
        cout<<k+1<<endl;
    else{
      ll cnt = a;
      k -= (a - 1);
      cnt = cnt + (b - a) * (k / 2);
      k %= 2;
      cnt += k;
      cout << cnt << endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

if b >= a:
    print("{}".format(a))
else:
    print("{}".format(a - 1))


Measured memory_bytes: 3060
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		StringBuilder sb = new StringBuilder();
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int ans;
		if (k % 2 == 0) {
			ans = k / 2 * k / 2;
		} else {
			ans = k / 2 * (k + 1) / 2;
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 21844
// Copyright 2020 yaito3014
#include "bits/stdc++.h"
using namespace std;

int main() {
  cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int R, S, P;
  cin >> R >> S >> P;
  string T;
  cin >> T;
  const array<int, 3> scores = { R,S,P };
  auto cnv = [](char c) -> int {
    switch (c) {
    case 'r': return 0;
    case 's': return 1;
    case 'p': return 2;
    default: return -1;
    }
  };
  int ans = 0;
  vector<int> memo(N, 0);
  for (int i = 0; i < N; ++i) {
    int t = (cnv(T[i]) + 2) % 3;
    int score = scores[t];
    if (i >= K && memo[i - K] == t) {
      t = -1;
      score = 0;
    }
    memo[i] = t;
    ans += score;
  }
  cout << ans << endl;
}


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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long
typedef pair<int, int> P;

int main(){
  int n, now;
  cin >> n;
  now = n;
  while (true) {
    if (now % n == 0 && now % 2 == 0) {
      cout << now << endl;
      exit(0);
    }else{
      now += n;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	deque<int> v(n - 1);
	for (int &i : v)
		cin >> i;

	long long ans = v.front() + v.back();
	/*v.pop_back();
	 v.pop_front();*/
	for (int i = 0; i + 1 < v.size(); i++) {
		ans += min(v[i], v[i + 1]);
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
const int N = 100050;
typedef long long LL;
int fa[N], siz[N], dep[N];
int find(int x) {
  return fa[x] ? fa[x] = find(fa[x]) : x;
}
void Union(int x, int y) {
  if ((x = find(x)) != (y = find(y))) {
    if (dep[x] > dep[y]) std::swap(x, y);
    dep[y] += 1;
    siz[y] += siz[x];
    fa[x] = y;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) siz[i] = 1;
  int a, b;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    Union(a, b);
  }
  LL t = std::min(siz[find(1)], siz[find(2)]);
  LL t2 = n - t;
  printf("%lld\n", t * (t - 1) / 2 + t2 * (t2 - 1) / 2 - m);
  return 0;
}


Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main(){
  int n,i;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  int maxi=0,u=0;
  i=0;
  while(i<n-1){
    if(a[i]>=a[i+1])
      u++;
    else
      u=0;
    maxi=max(maxi,u);
    i++;
  }
  cout<<maxi;
    
  return 0;
}

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

class UnionFind {
public:
  vector<ll> parent, gap, up;

  UnionFind(ll n): parent(n), gap(n), up(n) {
    REP(i, 0, n) parent[i] = i;
  }

  ll find(ll i) {
    if(parent[i] == i) return i;
    ll p = parent[i];
    ll t = find(p);
    gap[i] += gap[p];
    return parent[i] = t;
  }

  void unite(ll a, ll b, ll c) {
    ll pa = find(a), pb = find(b);
    if(pa != pb) {
      ll w = height(a) - height(b) + c;
      gap[pa] = -w;
      parent[pa] = find(pb);
    }
    up[a] += c;
    up[b] += c;
  }

  ll height(ll i) {
    return gap[i] + up[i];
  }
};

int main(void) {
  ll N, Q;
  cin >> N >> Q;
  vector<ll> T(Q), A(Q), B(Q), C(Q);
  REP(i, 0, Q) {
    string type;
    cin >> type >> A[i] >> B[i]; A[i]--; B[i]--;
    if(type == "IN") {
      T[i] = 0;
      cin >> C[i];
    }
    if(type == "COMPARE") T[i] = 1;
  }

  UnionFind uf(N);
  REP(i, 0, Q) {
    if(T[i] == 0) {
      uf.unite(A[i], B[i], C[i]);
    } else {
      if(uf.find(A[i]) != uf.find(B[i])) {
        cout << "WARNING" << endl;
      } else {
        cout << uf.height(B[i]) - uf.height(A[i]) << endl;
      }
    }
  }
}


Measured memory_bytes: 8468
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int n,m;//線路の情報の数,駅の数
int dpc[101][101];
int dpt[101][101];
const int INF = 100000000;


void WarshallFloyd(){
  for(int i = 1;i <= m;i++){
    for(int j = 1;j <=m;j++){
      for(int k = 1;k <=m;k++){
      dpc[j][k] =min(dpc[j][k],dpc[j][i]+dpc[i][k]);
      dpt[j][k] =min(dpt[j][k],dpt[j][i]+dpt[i][k]);
      }
    }
  }
  return;
}

int main()
{
  while(cin >>n>>m){
    if(n ==0&&m ==0){
      break;
    }
   
    for(int i = 1;i <=m ;i++){
      for(int j = i+1;j <=m;j++){
	dpc[i][j] =INF;
	dpc[j][i] =INF;
	dpt[i][j] =INF;
	dpt[j][i] =INF;
      }
    }
    for(int i = 1;i <= m;i++){
      dpc[i][i] = 0;
      dpt[i][i] = 0;
    }
    for(int i = 0;i < n;i++){
      int from,to,cost,time;
      cin >>from>>to>>cost>>time;
      dpc[from][to] =cost;
      dpt[from][to] =time;
      dpc[to][from] =cost;
      dpt[to][from] =time;
    }
    /* for(int i = 1;i <=m;i++){
      for(int j = 1;j <=m;j++){
	cout <<"dpc["<<i<<"]["<<j<<"]"<<dpc[i][j] <<endl;
	cout <<"dpt["<<i<<"]["<<j<<"]"<<dpt[i][j] <<endl;
      }
      }*/
    WarshallFloyd();
    int k;//問い合わせの数
    cin >>k;
    for(int i = 0;i <k;i++){
      int s;
      int f;
      int r;
      cin >>s>>f>>r;
      if(r)
	cout<<dpt[s][f]<<endl;
      else
	cout<<dpc[s][f]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1240