akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;


int main(){
    ll H, W;
    cin >> H >> W;

    vector<ll> R[H];
    vector<ll> C[W];
    string S[H];
    ll P[H][W];
    ll Rcount[H][W];
    ll Ccount[H][W];
    ll count;
    ll max = 0;

    for(ll i = 0; i < H; i++){
        cin >> S[i];
    }

    for(ll i = 0; i < H; i++){
        count = 0;
        for(ll j = 0; j < W; j++){
            if(S[i][j] == '.'){
                count++;
                if(j == W - 1){
                    R[i].push_back(count);
                    count = 0;
                }
            }else{
                R[i].push_back(count);
                count = 0;
            }
        }
    }
    for(ll i = 0; i < W; i++){
        count = 0;
        for(ll j = 0; j < H; j++){
            if(S[j][i] == '.'){
                count++;
                if(j == H - 1){
                    C[i].push_back(count);
                    count = 0;
                }
            }else{
                C[i].push_back(count);
                count = 0;
            }
        }
    }
    for(ll i = 0; i < H; i++){
        for(ll j = 0; j < W; j++){
            if(j == 0){
                if(S[i][j] == '.'){
                    Rcount[i][j] = 0;
                }else{
                    Rcount[i][j] = 1;
                }
            }else{
                if(S[i][j] == '.'){
                    Rcount[i][j] = Rcount[i][j - 1];
                }else{
                    Rcount[i][j] = Rcount[i][j - 1] + 1;
                }
            }
        }
    }
    for(ll i = 0; i < W; i++){
        for(ll j = 0; j < H; j++){
            if(j == 0){
                if(S[j][i] == '.'){
                    Ccount[j][i] = 0;
                }else{
                    Ccount[j][i] = 1;
                }
            }else{
                if(S[j][i] == '.'){
                    Ccount[j][i] = Ccount[j - 1][i];
                }else{
                    Ccount[j][i] = Ccount[j - 1][i] + 1;
                }
            }
        }
    }

    for(ll i = 0; i < H; i++){
        for(ll j = 0; j < W; j++){
            if(S[i][j] == '.' && max < R[i][Rcount[i][j]] + C[j][Ccount[i][j]] - 1){
                max = R[i][Rcount[i][j]] + C[j][Ccount[i][j]] - 1;
            }
        }
    }

    cout << max << endl;

    return 0;
}


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

int main(){
    ll mod = 1e9+7;
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll res = 0;
    rep(d,61){
        ll n0 = 0, n1 = 0;
        rep(i,N){
            if((A[i] >> d) & 1) ++n1;
            else ++n0;
        }
        ll tmp = (1ll << d) % mod;
        ll n = n0 * n1 % mod;
        tmp = tmp * n % mod;
        res = (res + tmp) % mod;
    }
    cout << res << endl;
}

Measured memory_bytes: 2560
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Map as MP
import Data.List
import Data.Tuple
import Data.Char
import Data.IORef
import Control.Monad

toTuple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
    in
        (a, b)

make es = VU.foldl' step MP.empty (VU.map swap es VU.++ es)
    where
        step m (f,t) =
            case MP.lookup f m of
                Just _ -> MP.adjust (t:) f m
                Nothing -> MP.insert f [t] m

del graph (f,t) =
    let
        graph' = MP.adjust (delete f) t graph
        graph'' = MP.adjust (delete t) f graph' 
    in
        graph''

dfs graph table v = do
    r <- VUM.read table (v-1)
    if r 
        then return 0
        else do
            VUM.write table (v-1) True
            table' <- VU.freeze table
            let Just ns = MP.lookup v graph
            let ns' = delete v ns
            if (VU.and table')
                then return 1
                else if (Data.List.null ns')
                    then return 0
                    else do
                        res <- mapM (dfs graph table) ns'
                        return $ Data.List.sum res
                    
main = do
    (n,m) <- toTuple <$> B.getLine
    es <- VU.replicateM m (toTuple <$> B.getLine) 
    let graph = make es
    res <- newIORef (0 :: Int)
    forM_ [0..m-1] $ \i -> do
        tbl <- VUM.replicate n False
        let d = del graph (es VU.! i)
        solve <- dfs d tbl 1
        when (solve == 0) $ modifyIORef' res (+1)
    
    readIORef res >>= print

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

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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; }

ll n,m,k,result;
string s;
int main() {
    INIT();

    cin >> n;
    
    priority_queue<ll> q,memo;
    memo.push(0);
    REP(i,n) {
        ll tmp;
        cin >> tmp;
        q.push(tmp);
    }
    memo.push(q.top());
    q.pop();
    REPS(i,1,n){
        ll top;
        result += memo.top();memo.pop();
        memo.push(q.top());
        memo.push(q.top());
        q.pop();
    }
    cout << result;
}

Measured memory_bytes: 7952
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
const int maxn = 5050, mod = 1e9 + 7;
ll solve(ll n, ll x) {
	if(x == 0 || x == n) return 0;
	ll l = n-x;
	ll cnt = x / l;
	ll ans = 3*l*cnt;
	x %= l;
	if(x) ans += l + 2*x;
	return ans + solve(l, (l-x)%l) - ((l-x)%l);
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	ll n, x;
	cin >> n >> x;
	cout << solve(n, x); 
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll a , b , c;

int main() {
    fast_io;

    cin >> a >> b >> c;
    cout << min({a + b , a + c , b + c}) << endl;

    return 0;
}
/*

*/


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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for(auto &a : A) cin >> a;
    auto f = [&](auto &&f, int i, int h, int64_t cost, int k) -> int64_t {
        if(i == N) return k == K ? cost : 1LL << 60;
        int nh = A[i] > h ? A[i] : h + 1;
        int64_t ncost = A[i] > h ? cost : cost - A[i] + h + 1;
        return min(f(f, i + 1, nh, ncost, k + 1), f(f, i + 1, max(h, A[i]), cost, k));
    };
    cout << f(f, 1, A[0], 0, 1) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, b, t; cin >> a >> b >> t;
    cout << (t / a) * b << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#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 REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

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

int main(){
	int a,b;
	cin>>a>>b;
	if(a<=b){
		cout<<a<<endl;
		return 0;
	}
	else{
		cout<<a-1<<endl;
		return 0;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		int year = 0;
		long mnt = 100;

		while (mnt < X){
			year ++;
			mnt = (long) (mnt * 1.01);
		}

		System.out.println(year);

	}

}


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

int vect[2006];

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

	for(int i = 1; i <= n; i++)
	{
		cin >> vect[i];
	}

	sort(vect+1, vect+n+1);

	int ans = 0;
	for(int i = 1; i <= n-2; i++)
	{
		for(int j = i+1; j <= n-1; j++)
		{
			int st = j+1;
			int dr = n;
			int sol = -1;
			while(st <= dr)
			{
				int mij = (st+dr)/2;
				if(vect[mij] < vect[i]+vect[j])
				{
					sol = mij;
					st = mij+1;
				}
				else
				{
					dr = mij-1;
				}
			}

			if(sol != -1)
			{
				ans = ans + sol - j;
			}
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int kos[n],pe[n];
  for(int i=0;i<n;i++){
    cin>>kos[i]>>pe[i];
  }
  for(int i=0;i<n;i++){
    int timpo=pe[i];
    pe[i]=0;
    while(1){
      pe[i]++;
      kos[i]--;
      if(kos[i]==0){
	break;
      }
      if(pe[i]==timpo){
	pe[i]=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<pe[i]<<endl;
  }
  return(0);
}

Measured memory_bytes: 3100
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
    string s;cin>>s;
    int n = s.length();
    bool palindrome = true;
    for(int i=0;i<n/2;i++)
    {
        if(s[i] != s[n-i-1])
        {
            palindrome = false;
        }
    }
    if(!palindrome)
    {
        //cout<<"1st"<<endl;
        cout<<"No"<<endl;
        return;
    }
    string t;
    for(int i=((n-1)/2)-1;i>=0;i--)
    {
        t += s[i];
    }
    string test = t;
    reverse(t.begin(),t.end());
    if(test!=t)
    {
        cout<<"No";
        return;
    }
    t = "";
    test="";
    for(int i=((n+3)/2)-1;i<n;i++)
    {
        t += s[i];
    }
    test = t;
    reverse(t.begin(),t.end());
    if(test!=t)
    {
        cout<<"No";
        return;
    }
    cout<<"Yes"<<endl;



}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
  int n, a1[101], a2[101], ans = -1, kari = 0;

  if(scanf("%d", &n) == 1);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a1[i]);
  }
  for(int i = 0; i < n; i++) {
    scanf("%d", &a2[i]);
  }

  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= i; j++) {
      kari = kari + a1[j];
    }
    for(int j = i; j < n; j++) {
      kari = kari + a2[j];
    }
    if(ans < kari) {
      ans = kari;
    }
    kari = 0;
  }

  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;



int main(){

    int n;
    cin >> n;

    map<string, int> data;

    for(int i=0; i<n; i++){
        string s;
        cin >> s;

        data[s] += 1;
    }

    int max = 0;
    for(const auto& x :data){
        int num = x.second;
        if(num > max) max = num;
    }

    for(auto it = data.begin(); it != data.end(); it++){
        if(it->second == max){
            cout << it->first << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

  int a=0;
  int b=0;
  int c=0;
  int d=0;
int main(){
  int n;
  cin>>n;
  
  string AC,WA,TLE,RE;
  
  rep(i,n){
    string s;
    cin>>s;
    if(s=="AC"){
      a+=1;
    }
    else if(s=="WA"){
      b+=1;
    }
    else if(s=="TLE"){
      c+=1;
    }
    else if(s=="RE"){
      d+=1;
    }
  }

  cout<<"AC x "<<a<<endl;
  cout<<"WA x "<<b<<endl;
  cout<<"TLE x "<<c<<endl;
  cout<<"RE x "<<d<<endl;
return 0;
}

Measured memory_bytes: 3640
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    ll = rli()
    ans = 0
    for i in range(n):
        li = ll[i]
        for j in range(i+1, n):
            lj = ll[j]
            for k in range(j+1, n):
                lk = ll[k]
                l = [li, lj, lk]
                l.sort()
                if l[0] == l[1] or l[1] == l[2]:
                    continue
                if l[0]+l[1] > l[2]:
                    ans += 1
    print(ans)
        


if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl;


ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}


ll lcm(ll a, ll b) {
    ll gc = gcd(a, b);
    return a*(b / gc); // 割り算を先に行うことでオーバーフローを防ぐ
}                      // ab = gcd(a, b)lcm(a, b)


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

    ll ans = 1LL;

    rep(i, N) {
        ll T;
        cin >> T;
        ans = lcm(ans, T);
    }
    cout << ans << endl;
}

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

int main(void){
  string S;
  cin >> S;
  map<char, int> mp;
  for(int i=0; i<S.size(); i++){
    mp[S[i]]++;
  }
  int nN, nS, nW, nE;
  nN = mp['N'];
  nS = mp['S'];
  nW = mp['W'];
  nE = mp['E'];
  bool tf = true;
  if( (nN > 0 && nS == 0) || (nN == 0 && nS > 0) ) tf = false;
  else if((nW > 0 && nE == 0) || (nW == 0 && nE > 0)) tf = false;
  if(tf) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
using namespace std;
#define N 1000000

int main(){
    int n;
    cin>>n;
    long h[n];
    bool color[n-1];
    for (int i=0; i<n; i++){
        cin>>h[i];
    }
    for (int i=0; i<n-1; i++){
        if (h[i]>=h[i+1]){
            color[i]=true;
        }
        else{
            color[i]=false;
        }
    }
    int count=0;
    int ans[n-1];
    for (int i=0; i<n-1; i++){
        if (color[i]){
            count+=1;
            ans[i]=count;
        }
        else{
            count=0;
            ans[i]=count;
        }
    }
    long maxnum=0;
    for (int i=0; i<n-1; i++){
        if (maxnum<ans[i]){
            maxnum=ans[i];
        }
    }
    cout<<maxnum<<endl;
}

Measured memory_bytes: 1536
from collections import defaultdict, Counter

def main():
    num = int(input())
    hajime = list(input())

    ans = Counter(hajime)

    for i in range(num - 1):
        aaa = Counter(list(input()))
        ans_kari = defaultdict(int)
        for ele in ans.keys():
            if ele in aaa.keys():
                ans_kari[ele] = min(ans[ele], aaa[ele])
        ans = ans_kari

    for i in range(26):
        for j in range(ans[chr(97 + i)]):
            print(chr(97 + i), end='')

    print()



if __name__ == '__main__':
    main()


Measured memory_bytes: 41968
#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 all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int h, w;
	cin >> h >> w;
	V<string> s(h);
	rep(i, h)cin >> s[i];

	int cnt = 0;
	rep(i, h)rep(j, w)if (s[i][j] == '.')cnt++;

	vvi d(h, vi(w, INF));
	d[0][0] = 1;
	queue<P> que;
	que.push(make_pair(0, 0));
	vi dy = { 0,0,1,-1 };
	vi dx = { 1,-1,0,0 };

	while (!que.empty()) {
		int y = que.front().first;
		int x = que.front().second;que.pop();
		rep(i, 4) {
			int ey = y + dy[i];
			int ex = x + dx[i];
			if (ey < 0 || h <= ey || ex < 0 || w <= ex)continue;
			if (s[ey][ex]=='#'||d[ey][ex] != INF)continue;
			d[ey][ex] = d[y][x] + 1;
			que.push(make_pair(ey, ex));
		}
	}

	if (d[h - 1][w - 1] == INF)cout << -1 << endl;
	else cout << cnt - d[h - 1][w - 1] << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);	
	int n;
	cin >> n;
	vector<int> vs(n);
	for(auto &x:vs) cin >> x;
	set<int> st(all(vs));
	if(len(vs)==len(st))
		cout << "YES\n";
	else
		cout << "NO\n";
}


Measured memory_bytes: 10368
n = int(input())
ary = []
for _ in range(n):
  ary.append(int(input()))
 
ary.sort()
last = -1
counter = 0
result = 0
 
for i, el in enumerate(ary):
  if last == el:
    # count the same numbers
    counter += 1

  else:
    # increment
    result += counter%2
    
    # initialize
    counter = 1
    last = el

else:
    if i == n-1:
      result += counter%2
 
print(result)

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    //lol result{0};
    lol a; cin >> a;
    lol b; cin >> b;
    lol c; cin >> c;
    lol k; cin >> k;
    if(k <= a)
    {
        cout << k << endl;
    }
    else if(k <= a + b)
    {
        cout << a << endl;
    }
    else
    {
        cout << a - (k - a - b) << endl;
    }
    

    //int k; cin >> k;
    /*
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */

    //cout << result << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int nax=1e5+5;
vector<ll> bit(nax+1),cnt(nax+1);


ll get_sum(int i)
{
    ll sum=0;
    while(i>=0)
    {
       // cout<<i<<endl;
        sum+=bit[i];
        i=(i&(i+1))-1;

    }
    return sum;
}
void upd(int j,ll x)
{
    while(j<nax)
    {
        bit[j]+=x;
        j=j|(j+1);
    }
}

int main()
{
   int n;
   cin>>n;
   vector<ll> a(n);
   for(int i=0;i<n;i++) {cin>>a[i];cnt[a[i]]++;}
   for(int i=0;i<n;i++)
   {
       upd(a[i],a[i]);
   }
   int q;
   //cout<<get_sum(nax);
   cin>>q;
   while(q--)
   {
       ll x,y;
       cin>>x>>y;
       ll del=x*-1LL*cnt[x];
      // del=-1*del;
       upd(x,del);
       upd(y,(ll)y*1LL*cnt[x]);
       cnt[y]+=cnt[x];
       cnt[x]=0;
       cout<<get_sum(nax)<<endl;;

   }

}

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

using namespace std ;

const int N = 200010 ;

int n ;
int m ;
int top ;
int cnt ;
char s[N] ;
int sz[N] ;
int stk[N] ;

int main(){
    cin >> (s + 1) ;
    n = strlen(s + 1) ;
    if (s[1] == '0') return puts("-1"), 0 ;
    if (s[n] == '1') return puts("-1"), 0 ;
    for (int i = 1 ; i < n ; ++ i)
        if (s[i] != s[n - i]) return puts("-1"), 0 ;
    /*
    for (int i = 1 ; i < n ; ++ i)
        if (s[i] == '1') stk[++ top] = i ;
    stk[++ top] = n ; int k ; cnt = 0 ;
    while (top) sz[++ cnt] = stk[top --] ;
    for (int i = 1 ; i < cnt ; ++ i)
        printf("%d %d\n", i, i + 1), sz[i] -= sz[i + 1] ;
    k = cnt ;
    for (int i = 1 ; i <= cnt ; ++ i)
        for (int j = 1 ; j <= sz[i] ; ++ j)
            printf("%d %d\n", i, ++ cnt) ;
    */
    m = 1 ;
    for (int i = 1 ; i < n ; ++ i){
        cout << i + 1 << " " << m << endl ;
        if (s[i] == '1') m = i + 1 ;
    }
    return 0 ;
}

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

#define int long long

signed main() {
    int N;
    cin >> N;
    int ans = N;
    
    for(int i = 0; i <= N; ++i){
        int cnt = 0;
        int num = i;
        while(num > 0){
            cnt += (num % 6);
            num /= 6;
        }
        int res = N - i;
        while(res > 0){
            cnt += (res % 9);
            res /= 9;
        }
        
        if(cnt < ans){
            ans = cnt;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

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

	string S, S_twice;
	long long K;
	cin >> S >> K;
	S_twice = S + S;
	int N = S.size();
	long long cnt = count(S.begin(), S.end(), S[0]);

	if (cnt == N) cout << N * K / 2 << endl;
	else 
	{
		cnt = 1;
		long long ans_on_S = 0;
		for (int i = 1; i < N; i++)
		{
			if (S[i] == S[i - 1]) cnt++;
			else {
				ans_on_S += cnt / 2;
				cnt = 1;
			}
		}
		ans_on_S += cnt / 2; //残った末尾のカウント
		
		cnt = 1;
		long long ans_on_S_twice = 0;
		for (int i = 1; i < N * 2; i++)
		{
			if (S_twice[i] == S_twice[i - 1]) cnt++;
			else {
				ans_on_S_twice += cnt / 2;
				cnt = 1;
			}
		}
		ans_on_S_twice += cnt / 2;

		long long diff = ans_on_S_twice - ans_on_S;
		long long ans = ans_on_S + (K - 1) * diff; //等差数列の一般項の公式
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 100000

int main(){
    int n, m; cin >> n >> m;
    int MIN = 0, MAX = 1000100;
    rep(i, m){
        int l, r;
        cin >> l >> r;
        MIN = max(MIN, l);
        MAX = min(MAX, r);
    }
    if(MIN <= MAX){
        cout << MAX - MIN + 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 384
import java.lang.Math.*


fun main(args: Array<String>) {
    val (n, d) = readLongList()
    if (n % (2 * d + 1) == 0L) {
        println(n / (2 * d + 1))
    } else {
        println(n / (2 * d + 1) + 1)
    }
}


fun readList() = readLine()!!.split(' ')
fun readIntList() = readList().map(String::toInt)
fun readLongList() = readList().map(String::toLong)
fun readDoubleList() = readList().map(String::toDouble)

fun readPair(): Pair<String, String> {
    val splite = readLine()!!.split(' ')
    return Pair(splite[0], splite[1])
}

fun <T> List<T>.copy() = this.map { it }

// 速度のためforEachは避ける
fun Int.rep(start: Int = 0, body: (Int) -> Unit) {
    for (i in start until this) {
        body(i)
    }
}

fun Long.rep(start: Long = 0, body: (Long) -> Unit) {
    for (i in start until this) {
        body(i)
    }
}

// 約数のList
fun divisor(value: Long): List<Long> {
    val max = sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from: Long, to: Long = from): List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j -> i % j != 0L }
    }
}

// 素因数分解
fun decom(value: Long): List<Long> {
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a: Long, b: Long): Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base: String, a: String, b: String): String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

Measured memory_bytes: 38180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll n,m; cin>>n>>m;
    ll nin=1e9, nax=-1;
    rep(i,m){
        ll l,r; cin>>l>>r;
        chmin(nin, r); chmax(nax, l);
    }
    cout<<max(0ll, nin-nax+1ll)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    int a[100000];
    int res;
    int total;
    cin >> N;
    cin >> a[0];
    total = abs(a[0]);
    for (int i = 1; i < N; i++) {
        cin >> a[i];
        total += abs(a[i] - a[i - 1]);
    }
    total += abs(a[N - 1]);

    res = total - abs(a[0]) - abs(a[1] - a[0]) + abs(a[1]);
    cout << res << endl;
    for (int i = 1; i < N - 1; i++) {
        res = total - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]);
        cout << res << endl;
    }
    res = total - abs(a[N - 1]) - abs(a[N - 1] - a[N - 2]) + abs(a[N - 2]);
    cout << res << endl;
    return 0;
}

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

int main() {

    int N;
    cin >> N;
    int num = 0;
    for(int i = 0; i <= 10; i++) {
        if(N <= 1000 * i) { num = i; break; }
    }

    cout << 1000 * num - N;

 return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n; 
	while (cin >> n, n) {
		vector<char> c(n + 1);
		for (int i = 1; i <= n; ++i) cin >> c[i], c[i] -= 'A';
		int f = 26, s = 26;
		bool flag = false;
		int cnt[27] = {};
		int i;
		for (i = 1; i <= n; ++i) {
			cnt[c[i]]++;
			if (cnt[f] < cnt[c[i]]) s = f, f = c[i];
			else if (c[i] != f && cnt[s] < cnt[c[i]]) s = c[i];
			if (cnt[f] > cnt[s] + n - i) {
				flag = true;
				break;
			}
		}
		if (flag) cout << (char)(f + 'A') << " " << i << endl;
		else cout << "TIE" << endl;
	}

	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
using namespace std;
bool a[5000],d[5000];
int b[10000],c[10000];
int main()
{
    while(1){
        fill(a,a+5000,false);
        fill(b,b+10000,0);
        fill(c,c+10000,0);
        fill(d,d+5000,false);
        int n,m;
        cin>>n>>m;if(!n)return 0;
        for(int i=0;i<m;++i){
            cin>>b[i]>>c[i];
            if(b[i]==1)a[c[i]]=true;
        }
        for(int i=2;i<n+1;++i){
            if(a[i]){
                for(int j=0;j<m;++j){
                    if(b[j]==i)d[c[j]]=true;
                    if(c[j]==i)d[b[j]]=true;
                }
            }
        }
        int ans=0;
        for(int i=2;i<n+1;++i){
            if(a[i])ans++;
            else if(d[i])ans++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1248
n,x = gets.chomp.split.map(&:to_i)
xs = gets.chomp.split.map(&:to_i)
xs << x
xs.sort!
x0 = xs.shift
xs = xs.map{|x| x - x0}
gcd = xs.shift
xs.each do |x|
  gcd = x.gcd(gcd)
end
puts gcd


Measured memory_bytes: 10624
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Data.Monoid
import Control.Monad
import Control.Monad.ST
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.IntMap.Strict as IntMap
import qualified Data.Sequence as Seq

main = do
  [n,q] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM (n-1) $ do
    [a,b,c,d] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a-1,b-1,c,d)
  let edges' :: V.Vector [(Int,Int,Int)]
      edges' = V.create $ do
        vec <- VM.replicate n []
        U.forM_ edges $ \(i,j,c,d) -> do
          VM.modify vec ((j,c,d) :) i
          VM.modify vec ((i,c,d) :) j
        return vec
  let depthMap :: U.Vector Int
      routes :: V.Vector (Seq.Seq Int)
      distances :: U.Vector Int
      distancesMap :: V.Vector (IntMap.IntMap (Sum Int, Sum Int))
      (depthMap, routes, distances, distancesMap) = runST $ do
        depthVec <- UM.new n
        routes <- VM.new n
        distances <- UM.new n
        distancesMap <- VM.new n
        let go !i0 !i !d route !dt dtm = do
              UM.write depthVec i d
              VM.write routes i route
              UM.write distances i dt
              VM.write distancesMap i dtm
              forM_ (edges' V.! i) $ \(j,col,dist) -> do
                when (j /= i0) $ do
                  go i j (d+1) (route Seq.|> j) (dt + dist) (IntMap.insertWith (<>) col (Sum 1, Sum dist) dtm)
        go (-1) 0 0 (Seq.singleton 0) 0 IntMap.empty
        liftM4 (,,,) (U.unsafeFreeze depthVec) (V.unsafeFreeze routes) (U.unsafeFreeze distances) (V.unsafeFreeze distancesMap)
      lowestCommonAncestor :: Int -> Int -> Int
      lowestCommonAncestor !i !j =
        let ri = routes V.! i
            rj = routes V.! j
            search !l !u | l + 1 == u = ri `Seq.index` l
            search !l !u = let d = (l + u) `quot` 2 -- l < d < u
                               pi = ri `Seq.index` d
                               pj = rj `Seq.index` d
                           in if pi == pj
                              then search d u
                              else search l d
        in search 0 (min (Seq.length ri) (Seq.length rj))
  forM_ [0..q-1] $ \_ -> do
    [x,y,up1,vp1] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let u = up1 - 1
        v = vp1 - 1
        w = lowestCommonAncestor u v
        modifiedDistanceFromRoot :: Int -> Int
        modifiedDistanceFromRoot !i = distances U.! i + case IntMap.lookup x (distancesMap V.! i) of
                                                          Just (Sum n, Sum origDist) -> y * n - origDist
                                                          Nothing -> 0
    print $ modifiedDistanceFromRoot u + modifiedDistanceFromRoot v - 2 * modifiedDistanceFromRoot w


Measured memory_bytes: 128252
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,x,y;
int fir[5005],nxt[10005],to[10005],cnt;
int f[5005],size[5005],inv[5005];
int dp[5005][5005],g[5005];

int C(int x){return x*(x-1)/2;}

void dfs(int x,int fa){
	dp[x][0]=1;
	for(int i=fir[x];i;i=nxt[i]){
		if(to[i]==fa) continue;
		dfs(to[i],x);
		memset(g,0,sizeof(g));
		for(int j=0;j<=size[x];j++){
			for(int k=0;k<=size[to[i]];k++){
				(g[j+k]+=1ll*dp[x][j]*dp[to[i]][k]%mod)%=mod;
			}
		}
		size[x]+=size[to[i]];
		for(int j=0;j<=size[x];j++) dp[x][j]=g[j];
	}
	size[x]++;
	for(int i=size[x]-1;i>=0;i--){
		(dp[x][size[x]]+=1ll*(mod-f[size[x]-i])*dp[x][i]%mod)%=mod;
	}
}

int main(){
	scanf("%d",&n);
	inv[1]=1;
	for(int i=2;i<=n;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<n;i++){
		scanf("%d %d",&x,&y);
		to[++cnt]=y,nxt[cnt]=fir[x],fir[x]=cnt;
		to[++cnt]=x,nxt[cnt]=fir[y],fir[y]=cnt;
	}
	for(int i=2;i<=n;i+=2){
		f[i]=1;
		for(int j=1;j<=i/2;j++) f[i]=1ll*f[i]*C(i-2*(j-1))%mod;
		for(int j=1;j<=i/2;j++) f[i]=1ll*f[i]*inv[j]%mod;
	}
	dfs(1,0);
	printf("%d\n",mod-dp[1][n]);
	
	return 0;
}

Measured memory_bytes: 97280
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c, d;std::cin >> a >> b >> c >> d;
  while(true){
    c -= b;
    if(c<=0){
      std::cout << "Yes" << '\n';
      return 0;
    }
    a -= d;
    if(a<=0){
      std::cout << "No" << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3104
mod = 998244353

n,a,b,k = map(int,input().split())

fact = [1]
fact_inv = [1]
for i in range(n+4):
    new_fact = fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod


res = 0

for i in range(n+1):
    if k - a*i < 0:
        continue
    
    if (k-a*i)%b != 0:
        continue

    j = (k-a*i)//b

    if j > n:
        continue

    res = (res + mod_comb_k(n,j,mod)*mod_comb_k(n,i,mod)%mod)%mod

print(res%mod)

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

int main() {
  string S, T;
  cin >> S >> T;
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  if (S < T) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;


int main()
{
    double L;

    cin >> L;

    printf("%.6f\n", pow(L / 3., 3));

    system("pause");

	return 0;
}

Measured memory_bytes: 504
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    int n, k, sum = 0;
    cin >> n >> k;
    int arr[n];
    rep(i, 0, n) cin >> arr[i];
    sort(arr, arr + n);
    rep(i, 0, k) sum += arr[i];
    cout << sum;
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;


int main(){
  string s;
  int K;
  int c[100100];
  cin >> s;
  cin >> K;
  for(int i=0;i<s.size();i++){
    c[i] = 26-(s[i]-'a');
    if(c[i] == 26) c[i] = 0;
  }
  for(int i=0;i<s.size();i++){
    if(K >= c[i] ){
      s[i] = 'a';
      K -= c[i];
    }
    if(i==s.size()-1){
      int l=s.size()-1;
      s[l] = (s[l] + (K%26));
      if(s[l] > 'z') s[l] -= 26;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int add = a + b;
		int minus = a - b;
		int multi = a*b;
		
		int max = Math.max(add, minus);
		max = Math.max(max, multi);
		
		System.out.println(max);
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define MAX 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef long long ll;

int main()
{
    FASTIO
    int n,k;
    cin >> n >> k;
    vector<int> H(n+10, 0);
    for(int i = 0; i < n; i++) cin >> H[i];

      vector<int> ans(n+5, INF);
    ans[0] = 0;
    for(int i = 0; i < n; i++){
      for(int j = 1; j <= k && (i+j) < n; j++){
      ans[i+j] = min(ans[i+j], ans[i] + abs(H[i+j] - H[i]));
    }
  }
    cout << ans[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

vector<int> V[10001];

int A,B;

void func(){

	int ans = BIG_NUM;
	int calc;

	vector<int> TMP;

	for(int i = 0; i < V[A].size(); i++){
		for(int k = 0; k < V[B].size(); k++){
			TMP.push_back(V[A][i]);
			TMP.push_back(A/V[A][i]);
			TMP.push_back(V[B][k]);
			TMP.push_back(B/V[B][k]);
			sort(TMP.begin(),TMP.end());

			calc = 0;
			for(int p = 1; p <= 3; p++){
				calc += (TMP[p]-TMP[p-1])*(TMP[p]-TMP[p-1]);
			}
			ans = min(ans,calc);
			TMP.clear();
		}
	}

	printf("%d\n",ans);
}


int main(){

	for(int i = 1; i <= 10000; i++){
		for(int k = 1; k <= sqrt(i); k++){
			if(i%k == 0){
				V[i].push_back(k);
			}
		}
	}

	while(true){
		scanf("%d %d",&A,&B);
		if(A == 0 && B == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3896
import sys
import collections
sys.setrecursionlimit(4100000)

n,k,q = [int(i) for i in input().split()]
a = [int(input()) for _ in range(q)]
d = collections.defaultdict(int)
for b in a:
    d[b] += 1

for i in range(1,n+1):
    # print(i,d[i]+k-q)
    if d[i]+k-q > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 20092
import numpy as np
n, m = map(int, input().split(" "))
arr = list(map(int, input().split(" ")))
arr = np.array(arr)

s = np.sum(arr)
choosable = len(np.where(4*m*arr >= s)[0])
if m > choosable:
    print('No')
else:
    print('Yes')




Measured memory_bytes: 21264
x = gets.to_i
if x == 1
  puts 1
  exit
end

s = Math.sqrt(x).floor
max = 0

2.upto(s) do |i|
  j = 1
  while x >= i**j
    max = i**j if i**j > max
    j += 1
  end
end
puts max


Measured memory_bytes: 3836
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[10];
int main(){
	int a,x,y,z;
	scanf("%d%d%d%d",&a,&x,&y,&z);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	int ret=mod;
	for(int i=0;i<(1<<(a*2));i++){
		int A=0;
		int B=0;
		int C=0;
		int cur=0;
		for(int j=0;j<a;j++){
			int f=(i>>(j*2))%4;
			if(f==1)A+=p[j];
			if(f==2)B+=p[j];
			if(f==3)C+=p[j];
			if(f!=0)cur+=10;
		}
		cur-=30;
		if(A==0||B==0||C==0)continue;
		cur+=ABS(A-x);
		cur+=ABS(B-y);
		cur+=ABS(C-z);
		ret=min(ret,cur);
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 128
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,b,c = iim()
k = ii()

print(a+c+b+max(a,b,c)*(2**k-1))

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

long long INF=100000000000;

int main(){
  int A,B,Q;
  cin >> A >> B >> Q;
  vector<long long> s(A),t(B);
  for (int i=0;i<A;i++){
    cin >> s[i];
  }
  for (int i=0;i<B;i++){
    cin >> t[i];
  }
  for (int i=0;i<Q;i++){
    long long x;
    cin >> x;
    auto itrs1=lower_bound(s.begin(),s.end(),x),itrt1=lower_bound(t.begin(),t.end(),x);
    auto itrs2=itrs1-1,itrt2=itrt1-1;
    long long a=INF,b=INF,c=INF,d=INF;
    if (itrs1!=s.end()&&itrt1!=t.end()){
      a=max(*itrs1,*itrt1)-x;
    }
    if (itrs1!=s.begin()&&itrt1!=t.begin()){
      b=x-min(*itrs2,*itrt2);
    }
    if (itrs1!=s.end()&&itrt1!=t.begin()){
      c=min(*itrs1-x,x-*itrt2)+*itrs1-*itrt2;
    }
    if (itrs1!=s.begin()&&itrt1!=t.end()){
      d=min(*itrt1-x,x-*itrs2)+*itrt1-*itrs2;
    }
    long long ans=min(min(min(a,b),c),d);
    cout << ans << endl;
  }
}

Measured memory_bytes: 2944
#include<stdio.h>
int main(void){
	long long m,n,a,b,k;
	int c;
	for(;scanf("%lld %lld",&m, &n)&&(m||n);){if(m>n){a=m;b=n;}else {b=m;a=n;}c=0;do{c++;k=a%b;a=b;b=k;}while(k!=0);printf("%lld %d\n",a,c);}}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

using namespace std;

int main(void){
    char a[4];
    for(int i = 0; i < 4; i++)
        cin >> a[i];
    if(a[0] == a[1] && a[1] == a[2]){
            cout << "Yes\n";
    }
    
    else if(a[1] == a[2] && a[2] == a[3]){
            cout << "Yes\n";
    }
    
    else{
        cout << "No\n";
    }
    return 0;
        }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v(n,0);
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int x;
            cin>>x;
            x--;
            v[x]++;
        }
    }
    int cnt = 0;
    rep(i,n){
        if(v[i]==0) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

bool dep(string k){
	string u=k;
	reverse(u.begin(),u.end());
	if(u!=k){
		return false;
	}
	return true;
}
int main() {
	string s;
	cin>>s;
	bool ch=true;
	ch=dep(s);
	string u;
	ll n=s.size();
	for(ll i=0;i<(n-1)/2;i++){
		u.push_back(s[i]);
	}
	if(ch){
	ch=dep(u);
	}
	string t;
	for(ll i=(n+3)/2-1;i<n;i++){
		t.push_back(s[i]);
	}
	if(ch){
	ch=dep(t);
	}
	if(ch){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, m; cin >> n >> m;

    // 何個の玉が入っているか。
    vi ball(n, 1);
    
    // 赤の玉が入っている可能性があるか。
    vector<bool> pos(n, false); pos[0] = true;
    
    rep(i, m){
        // 0-basedで入力
        ll x, y;
        cin >> x >> y;
        x--; y--;

        // ボールの数を増減
        ball[y]++, ball[x]--;

        // もし、移動元に赤の玉がある可能性があるなら
        // 移動先にも赤の玉がある可能性が生じる
        if(pos[x]) pos[y] = true;

        // 移動後、移動元の玉の数が0となったら赤の玉がある可能性は消滅する。
        if(!ball[x]) pos[x] = false;
    }
    // 赤の玉がある可能性のある箱を数え上げる
    ll ans = 0;
    rep(i, n) if(pos[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<pair<int,int>,int>P;

int ans=0;
int mass[3][102];
int n;  

void bfs(int x,int y,int cnt){
    if(x==2 && y == n && ans < cnt) ans = cnt;
    for(int i=0;i<=1;i++){
        for(int j=0;j<=1;j++){
            if(i==0 && j == 0) continue;
            int next_x = x+i, next_y = y+j;
            if(1 <= next_x && next_x <= 2 && 1 <= next_y && next_y <= n){
                bfs(next_x,next_y,cnt + mass[next_x][next_y]);
            }
        }
    }
}

int main(void){
    cin >> n;
    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            cin >> mass[i][j];
        }
    }
    bfs(1,1,mass[1][1]);

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

Measured memory_bytes: 256
#include <stdio.h>

void Check(int *x,int *y){
	int check;
	if(*x>*y){
		check=*x;
		*x=*y;
		*y=check;
	}
}
	
int main(){
	int a,b,c;
	
	scanf("%d%d%d",&a,&b,&c);
	Check(&a,&b);
	Check(&b,&c);
	Check(&a,&b);
	
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}


Measured memory_bytes: 2060