akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <limits>

using namespace std;
using ll = long long;

int main(){

	// 入力 int N = N, vector a = {a_1, a_2, ... a_N*3} 
	int N;
	cin >> N;
	int N3 = N * 3;

	vector<ll> a(N3);

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

	// 優先度つきキューの作成
	// pq_front: 前から N+k 個の要素で常に最大のN要素をもつキュー（降順に取り出す）
	// pq_back: 後ろから N+k　個の要素で常に最小のN要素をもつキュー（昇順に取り出す）
	priority_queue<ll, vector<ll>, greater<ll>> pq_front;
	priority_queue<ll> pq_back;

	// sum_front[k]: あるkに対するpq_front の総和
	// sum_front[k]: あるkに対するpq_back の総和
	vector<ll> sum_front(N+1, 0), sum_back(N+1, 0);

	// pq_front(back)に前から（後ろから）N要素を追加、sum_front(back)を計算
	for (int i=0; i<N; ++i){
		pq_front.push(a[i]);
		pq_back.push(a[N3 - i - 1]);
		sum_front[0] += a[i];
		sum_back[N] += a[N3 - i - 1];
	}

	// k = 0, 1, ... , N-1 に対してsum_front(back)を計算
	for (int k=0; k<N; ++k){
		// a_k+N を pq_front に追加、最小要素をpopして総和を更新。
		pq_front.push(a[N+k]);
		pq_back.push(a[N*2-k-1]);

		sum_front[k+1] = sum_front[k] + a[N+k] - pq_front.top();
		sum_back[N-k-1] = sum_back[N-k] + a[N*2-k-1] - pq_back.top();

		pq_front.pop();
		pq_back.pop();

	}

	// sum_front[k] - sum_back[k] の最大値を計算
	ll max_score = 0x8000000000000000;
	for (int k=0; k<=N; ++k){
		ll score = sum_front[k] - sum_back[k];
		if (max_score < score){
			max_score = score;
		}

	}

	// 出力
	cout << max_score << endl;
}

Measured memory_bytes: 5996
import           Control.Monad (forM, replicateM)
import           Data.List     (groupBy, sort)

main :: IO ()
main = do
    n <- readLn :: IO Int
    ss <- replicateM n getLine
    let ss' = process ss
    print $ solve ss'

process = map length .
          groupBy (\(a:_) (b:_) ->  a == b) .
          sort . filter (\(s:_) -> s `elem` "MARCH")

solve ls = let n = length ls
               bs = map (map fst . filter snd . zip [0..])
                   $ filter (\ss -> 3 == length (filter id ss))
                   $ replicateM n [True, False]
           in
               sum $ map (product . map (ls !!)) bs



Measured memory_bytes: 79228
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int n,a[100];
string s[100],x;
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>s[i]>>a[i];
    cin>>x;
    int i=0,ans=0;
    for(;i<n;i++)
    {
        if(s[i]==x)break;
    }
    ++i;
    for(;i<n;i++)
        ans+=a[i];
    cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("XORQUERY.inp","r",stdin);
    //freopen("XORQUERY.out","w",stdout);
    //int test;cin>>test;while(test--)
    solve();
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix_2
# CreatedDate:  2020-08-29 22:01:34 +0900
# LastModified: 2020-08-29 22:07:06 +0900
#


import os
import sys
import numpy as np
# import pandas as pd


def main():
    n = int(input())
    A = list(map(int, input().split()))
    amari = 1000000007
    ans = ((sum(A))*(sum(A)) - sum(a**2 for a in A))
    print(ans//2%amari)


if __name__ == "__main__":
    main()


Measured memory_bytes: 49580
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		long k, n_ken;

		k = scan.nextLong();
		n_ken = scan.nextLong();

		long[] distanceFromN = new long[(int) (n_ken) + 1];

		for (int i = 1; i <= n_ken; i++) {
			distanceFromN[i] = scan.nextLong();
		}

		long max = 0;

		//一番遠い家の距離を求める
		for (int i = 1; i <= n_ken; i++) {

			long distance = distanceFromN[i] - distanceFromN[i - 1];

			if (max < distance) {
				max = distance;
			}

			if (i == 1) {
				//初めの家は後ろ向きでも考える
				long firstDistance = distanceFromN[i] + (k - distanceFromN[(int) n_ken]);

				if (max < firstDistance) {
					max = firstDistance;
				}
			}
		}

		System.out.println(k - max);
	}

	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


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

const long long INF = 1000000000000000;

int main() {
	int a, b, q; cin >> a >> b >> q;
	long long s[100010], t[100010];
	for (int i = 0; i < a; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> t[i];
	}
	long long ans[100010];
	for (int i = 0; i < q; i++) {
		ans[i] = INF;
	}
	for (int i = 0; i < q; i++) {
		long long x; cin >> x;
		int sh = lower_bound(s, s + a, x) - s;
		int tem = lower_bound(t, t + b, x) - t;
		if (sh > 0) {
			if (tem > 0) ans[i] = min(ans[i], max(x - s[sh - 1], x - t[tem - 1]));
			if (tem < b) {
				long long d = min(x - s[sh - 1], t[tem] - x);
				ans[i] = min(ans[i], d + abs(s[sh - 1] - t[tem]));
			}
		}
		if (sh < a) {
			if (tem < b) ans[i] = min(ans[i], max(s[sh] - x, t[tem] - x));
			if (tem > 0) {
				long long d = min(s[sh] - x, x - t[tem - 1]);
				ans[i] = min(ans[i], d + abs(s[sh] - t[tem - 1]));
			}
		}
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3712
from collections import Counter


class UnionFind:
    from collections import deque

    def __init__(self, v):
        self.v = v
        self._tree = list(range(v + 1))

    def _root(self, a):
        queue = self.deque()
        while self._tree[a] != a:
            queue.append(a)
            a = self._tree[a]
        while queue:
            index = queue.popleft()
            self._tree[index] = a
        return a

    def union(self, a, b):
        root_a = self._root(a)
        root_b = self._root(b)
        self._tree[root_b] = root_a

    def find(self, a, b):
        return self._root(a) == self._root(b)


N, M, K = map(int, input().split(' '))

n_friends = Counter()
n_groups = Counter()
uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    uf.union(a, b)
    n_friends[a] -= 1
    n_friends[b] -= 1

for _ in range(K):
    c, d = map(int, input().split(' '))
    c -= 1
    d -= 1
    if uf.find(c, d):
        n_friends[c] -= 1
        n_friends[d] -= 1

for n in range(N):
    n_groups[uf._root(n)] += 1

print(*[n_friends[n] + n_groups[uf._root(n)] - 1 for n in range(N)])


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

int main() {
  string S,T;
  cin>>S>>T;
  int count;
  int A=S.size();
  for(int i=0; i<A; i++) {
    if (S.at(i)==T.at(i)) {
      count++;
    }
  }
  cout << A-count << endl;
}

Measured memory_bytes: 3776
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define loop(i,s,e) for(ll i=s; i<e; i++)
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX
#define minusinf INT_MIN

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

void alpha(){

	ll n, m;
	cin>>n>>m;

	ll correct = 0, penalty = 0;
	pair<ll, string> arr[m];

	map<ll, ll> mp;
	ll wrong[100001]={0};

	loop(i,0,m) cin>>arr[i].ff>>arr[i].ss;

	loop(i,0,m){
		if(arr[i].ss=="WA" and mp.count(arr[i].ff)==0) wrong[arr[i].ff]++;
		
		else if(arr[i].ss=="AC" and mp.count(arr[i].ff)==0) {
			correct++;
			penalty+=wrong[arr[i].ff];
			mp[arr[i].ff]=1;
		}
	}


	cout<<correct<<" "<<penalty<<endl;
	
	return;

}

int main(){

	ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    ll t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}

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


int main() {
	int buff = 0;
	cin >> buff;

	if (buff == 1) {
		cout << "Hello World";
	} else if (buff == 2) {
		int a, b;
		cin >> a >> b;
		cout << (a+b);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long h,w,cnt=0;
  char c;
  cin >> h >> w;
  for (int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c;
      if(c=='#'){
        cnt++;
      }
    }
  }
  if(cnt==h+w-1){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

#ifndef MDEBUG
#define NDEBUG
#endif

#define x first
#define y second
#define ll long long
#define d double
#define ld long double
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define psi pair<string,int>
#define pis pair<int,string>
#define psl pair<string,ll>
#define pls pair<ll,string>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
// auto fraclt = [](auto&a,auto&b) { return (ll)a.x * b.y < (ll)b.x * a.y; };
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }
template<typename T> void fracn(pair<T,T>&a) {auto g=gcd(a.x,a.y);a.x/=g;a.y/=g;}
template<typename T> struct Index { int operator[](const T&t){auto i=m.find(t);return i!=m.end()?i->y:m[t]=m.size();}int s(){return m.size();} unordered_map<T,int> m; };

int main(int,char**) {
    ios_base::sync_with_stdio(false);

    ri(N); ri(K);
    vector<bool> D(10, true);
    for (int i = 0; i < K; i++) {
        ri(w); D[w] = false;
    }

    int i = N;
    while (true) {
        int w = i; bool ok = true;
        while (w>0) {
            ok &= D[w%10];
            w /= 10;
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
        ++i;
    }
    
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

res10000 = -1
res5000 = -1
res1000 = -1

for ai in range(N+1):
    for bi in range(0, N-ai+1):
        ci = N - ai - bi
        total = 10000*ai + 5000*bi + 1000*ci
        if total == Y:
            res10000 = ai
            res5000 = bi
            res1000 = ci
            break

print(str(res10000) + " " + str(res5000) + " " + str(res1000))

Measured memory_bytes: 3064
n = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
    if P[i - 1] < P[i] < P[i + 1] or P[i + 1] < P[i] < P[i - 1]:
        ans += 1
print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<string,string>ma;
set<int > s;
multiset<string> :: iterator it;

deque <char> q ;
ll ar [55100];
int main()
{
    fast;
     string s[3];
    string ans = "";
  for ( int i=0;i<3;i++)
{
   cin >> s[i];
  ans+=s[i][0];

}
cout << ans <<endl;
}




Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  if(N % 2 == 1) {
    puts("No");
    return 0;
  }
  for(int i=0; i<N/2; i++) {
    if(S[i] != S[i+N/2]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

u64 n;
s64 *R;
s64 *A;
s64 *B;

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

    cin >> n;

    R = new s64[n];
    A = new s64[n];
    B = new s64[n];

    s64 r;
    s64 m = 1e9 + 1;
    rep (i, n)
    {
        cin >> r;
        R[i] = r;
        m = MIN(m, r);
        A[i] = m;
    }

    m = 0;
    for (int i = n - 1; i >= 0; --i)
    {
        m = MAX(m, R[i]);
        B[i] = m;
    }

    m = -1e9;
    rep (i, n - 1)
    {
        m = MAX(m, B[i + 1] - A[i]);
    }

    cout << m << "\n";

    return 0;
}



Measured memory_bytes: 7932
import bisect
from collections import defaultdict

N = int(input())
# 書き換える時に文字列だと不便なのでリスト化しておく
S = list(input())
Q = int(input())

dict = defaultdict(list)
for i in range(N):
    dict[S[i]].append(i)
# print(dict)

ans = []

for _ in range(Q):
    a, b, c = input().split()
    a = int(a)

    if a == 1:
        b = int(b) - 1
        if S[b] == c:
            continue
        else:
            dict[S[b]].remove(b)
            idx = bisect.bisect_left(dict[c], b)
            dict[c].insert(idx, b)
            S[b] = c

    elif a == 2:
        b = int(b) - 1
        c = int(c) - 1
        char_n = 0
        for key, value in dict.items():
            x1 = bisect.bisect_left(value, b)
            x2 = bisect.bisect_right(value, c)
            if x2 - x1 > 0:
                char_n += 1
        ans.append(char_n)

for i in ans:
    print(i)


Measured memory_bytes: 126660
//BISMILLAHIR RAHMANIR RAHIM
//RABBI ZIDNI ILMA
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define endl "\n"
#define inf (1LL<<61)
#define pi acos(-1)
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(0);cout<< fixed<< setprecision(10);
#define debug(x) cout<<"["<<#x<<": "<<x<<"]\n"
#define debug2(x, y) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]\n"
#define debug3(x, y, z) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]"<<"  ["<<#z<<": "<<z<<"]\n"
#define debug4(x, y, z, k) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]"<<"  ["<<#z<<": "<<z<<"]"<<"  ["<<#k<<": "<<k<<"]\n"

const ll N = 1e5 + 9;

void genPrime(vector<ll>& prime, ll upto)
{
    prime.push_back(2);
    vector<bool> yes(upto+1, 1);
    for(ll i=3; i*i<=upto; i+=2){
        if(yes[i] == 1){
            for(ll j=i*i; j<=upto; j+=2*i) yes[j] = 0;
        }
    }
    for(ll i=3; i<=upto; i+=2){
        if(yes[i]) prime.push_back(i);
    }
}

int main()
{
    fastio
    vector<ll> primes;
    genPrime(primes, 1010);

    ll n;
    cin>> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>> a[i];
    vector<bool> yes((int)(1e6+9));
    bool pairwise = 1;
    vector<ll> copy_a = a;
    for(int i=0; i<n; i++){
        for(ll p: primes){
            if(a[i] % p == 0){
                while(a[i] % p == 0){
                    a[i] /= p;
                }
                if(yes[p]) pairwise = 0;
                yes[p] = 1;
            }
        }
        if(a[i] > 1){
            if(yes[a[i]]) pairwise = 0;
            yes[a[i]] = 1;
        }
    }
    if(pairwise){
        cout<< "pairwise coprime";
        return 0;
    }
    a = copy_a;
    bool setwise = 1;
    ll gcd = a[0];
    for(int i=1; i<n; i++){
        gcd = __gcd(gcd, a[i]);
        //debug(gcd);
    }
    if(gcd > 1) setwise = 0;
    if(setwise){
        cout<< "setwise coprime";
        return 0;
    }
    cout<< "not coprime";
}



Measured memory_bytes: 19088
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <array>
#include <map>
#include <set>
using namespace std;

#define IS_POWER_TWO(x) (!(x & (x-1))) 
struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

typedef pair<int, int> pii;
const pii Dir_eight[8]{
	{0,-1},{-1,0},{1,0},{0,1},{-1,-1},{1,1},{-1,1},{1,-1}
};

int main()
{
	int w, h;

	while (scanf("%d %d", &w, &h)) {
		if (w == 0)
			return 0;
		array<array<int, 52>, 52> map = {};
		UnionFind uf(2501);

		for (int i = 0; h > i; i++) {
			for (int j = 0; w > j; j++) {
				int a;
				scanf("%d", &a);

				map[j + 1][i + 1] = a;
				if (!a)uf.unionSet(i*w + j, h*w);
			}
		}

		for (int i = 1; h >= i; i++) {
			for (int j = 1; w >= j; j++) {
				if (map[j][i]) {
					for (int k = 0; 8 > k; k++) {
						if (map[j + Dir_eight[k].first][i + Dir_eight[k].second]) {
							uf.unionSet(j + Dir_eight[k].first + (i + Dir_eight[k].second-1)*w-1, (i-1)*w + j-1);
						}
					}
				}
			}
		}

		set<int> ver;

		for (int i = 0; h*w+1 > i; i++) {
			ver.insert(uf.root(i));
		}
		
		printf("%d\n", ver.size() - 1);
	}
	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

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

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (int)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n, k;
  cin >> n >> k;

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  // sortAl(a);

  ll min_step = INF;

  rep(i, n - k + 1) {
    // a
    ll step = abs(a[i] - a[i + k - 1]) + std::min(abs(a[i]), abs(a[i + k - 1]));
    chmin(min_step, step);
  }

  cout << min_step << endl;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int n=s.size();
    rep(i,n){
        if (i%2==0 && s[i]=='L'){
            cout<<"No\n";
            return 0;
        }
        if (i%2==1 && s[i]=='R'){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np 

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, m = I[:2]
a = I[2:]
a.sort()
ma = a[-1]
cnt = np.bincount(a, minlength=ma+2)
cnt_not_less_than = np.cumsum(cnt[::-1])[::-1]

right = a[:, None]
def possible(border):
    left = border - right
    left = np.maximum(left, 0)
    left = np.minimum(left, ma+1)
    pair_cnt = np.sum(cnt_not_less_than[left])
    return pair_cnt >= m

def main():
    lo = 1; hi = ma * 2 + 1
    while lo + 1 < hi:
        border = (lo + hi) // 2
        if possible(border):
            lo = border
        else:
            hi = border

    res = lo
    left = res - right
    left = np.maximum(left, 0)
    left = np.minimum(left, ma+1)
    c = cnt_not_less_than[left[left != ma+1]]
    pair_cnt = np.sum(c)
    minimum = np.amin(right[left != ma + 1] + a[-c])

    s = np.cumsum(a[::-1])
    ans = np.sum(s[c-1] + right[left != ma+1] * c) - minimum * (pair_cnt - m)
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main() {
	int v[4] = {0,0,0,0};
	for(int i=0;i<3;++i){
		int a,b;cin>>a>>b;
		++v[a-1];
		++v[b-1];
	}
	int cnt1 = 2;
	int cnt2 = 2;
	for(int i=0;i<4;++i){
		if(v[i]==1) --cnt1;
		if(v[i]==2) --cnt2;
	}
	if(cnt1==0&&cnt2==0){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int x = scanner.nextInt();
        int gohyaku = (x/500) * 1000;
        int go = ((x%500) / 5) * 5;

        System.out.println(gohyaku + go);
    }
}

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

int main() {
    string s;
    int size;
    string t;
    
    cin >> s;

    size = s.size() - 2;
    t = s[0] + to_string(size) + s[s.size()-1];
    
    cout << t << endl;

    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
arr = gets.split.map(&:to_i)
dp = N.times.map{[0]*(N)}
N.times.each do |i|
  dp[i][i] = arr[i]
end

(1..(N-1)).each do |length|
  (0..(N-1-length)).each do |left|
    right = left + length
    left_score = arr[left] - dp[left + 1][right]
    right_score = arr[right] - dp[left][right - 1]

    dp[left][right] = left_score > right_score ? left_score : right_score
  end
end
puts dp.first.last

Measured memory_bytes: 74364
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	private StringTokenizer st;
	private BufferedReader bf;
	private int w;
	
	Main() {
		readData();
		

	}	

	private void readData() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());

			int n = nextInt();
			while (n != 0) {
				int rA = 0;
				int rB = 0;
				for (int i = 0; i < n; i++) {
					int a = nextInt();
					int b = nextInt();
					if (a > b) {
						rA += a + b;
					} else if (a < b) {
						rB += a + b;
					} else {
						rA += a;
						rB += b;
					}
	//				BigDecimal bd = new BigDecimal(m);
	//				BigDecimal bd3 = bd.setScale(-3, BigDecimal.ROUND_UP);
	//				m = bd3.intValue();
	//				System.out.println((int)m);
				}
				System.out.println(rA+" "+rB);
				
				n = nextInt();
			}
//			DecimalFormat df = new DecimalFormat("0");
//			System.out.println(df.format(m));
			
		} catch (Exception e) {
			System.out.println("dacat");
			e.printStackTrace();
		}
	}
	
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	
	private String next() throws IOException {
		try {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		} catch (Exception e) {
			System.out.println("dacat");
		}
		return st.nextToken();
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Main m = new Main();
	}

}

Measured memory_bytes: 24488
#include <stdio.h>

int main(void)
{
	int hit, blow, a[4], b[4], i, j;
	
	while (scanf("%d %d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &b[0], &b[1], &b[2], &b[3]) != EOF){
		blow = hit = 0;
		for (i = 0; i < 4; i++){
			if (a[i] == b[i]) blow++;
		}
		for (i = 0; i < 4; i++){
			for(j = 0; j < 4; j++){
				if (a[i] == b[j])  hit++;
			}
		}
		printf("%d %d\n", blow, hit - blow);
	}
	return (0);
}

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

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		int t;cin>>t;
		a.push_back(t);
	}
	sort(a.begin(), a.end());
	int l=a[a.size()-1], r = l;
	int i=0,j=a.size()-2;
	ll sum=0;
	while(i<j){
			int li=abs(l-a[i]),ri=abs(r-a[i]);
			int lj=abs(l-a[j]),rj=abs(r-a[j]);
			if(li>ri||lj>rj){
					if(li>lj){
							sum+=li;
							l=a[i++];
					}else{
							sum+=lj;
							l=a[j--];
					}
			}else{
					if(ri>rj){
							sum+=ri;
							r=a[i++];
					}else{
							sum+=rj;
							r=a[j--];
					}
			}
	}
	sum+=max(abs(l-a[i]),abs(r-a[i]));
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 892
mod=10**9+7
N,M=map(int,input().split())
d=abs(N-M)
if d>1:
	print(0)
else:
	ans=1
	for i in range(1,N+1):
		ans=(ans*i)%mod
	for i in range(1,M+1):
		ans=(ans*i)%mod	
	print((ans*(2-d))%mod)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	const string VERIFY_WORDS = "ABC";
	int N;
  string S;
	int result = 0;

  // 入力
  cin >> N;
	cin >> S;

	// ループで文字列を検索
	for (int i = 0; i < N; i++) {
		string _part_str = S.substr(i, VERIFY_WORDS.length());
		if (_part_str == VERIFY_WORDS) { result++; }
	}
  // 出力
  cout << result << endl;
}


Measured memory_bytes: 256
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    n, x, t = mi()
    tmp = 0
    ans = 0
    for i in range(10000):
        ans += t
        tmp += x
        if n <= tmp:
            break
    print(ans)


main()


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 998244353
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string s;	cin>>s;
	int ans=INT_MAX;
  	for(int i=0;i<s.length()-2;i++){
      int num= (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
      ans=min(ans,abs(num-753));
    }
	cout<<ans<<'\n';
  
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;
typedef long long ll;

int main() {
    ll n, k;    cin >> n >> k;
    ll *x = new ll[n];
    for (int i = 0; i < n; i++)
        cin >> x[i];
    
    ll ans = LLONG_MAX;
    for (int i = 0; i+k-1 < n; i++) {
        ll tmp = min((abs(x[i])+abs(x[i]-x[i+k-1])), (abs(x[i+k-1])+abs(x[i]-x[i+k-1])));
        ans = min(tmp, ans);
    }

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

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int f(int a){
  if(a<0)return -a;
  return a;
}

int main(void){
  int i,j,k,N,x[100],y[100],h[100],H;
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d%d%d",&x[i],&y[i],&h[i]);
  for(i=0;i<=100;i++)
    for(j=0;j<=100;j++)
      for(k=0;;){
        int s,t,flg=1;
        for(s=k;s<N&&!h[s];s++);
        for(t=s+1;t<N&&!h[t];t++);
        k=t;
        if(t>=N){
          int l;
          for(l=0;!h[l];l++);
          H=h[l]+f(x[l]-i)+f(y[l]-j);
          for(s=0;s<N;s++)
            if(h[s]==0&&H-f(x[s]-i)-f(y[s]-j)>0){
              flg=0;break;
            }
          if(flg==1)printf("%d %d %d\n",i,j,H);
          if(flg==0)break;
          return 0;
        }
        if(h[s]-h[t]!=-f(x[s]-i)-f(y[s]-j)+f(x[t]-i)+f(y[t]-j))break;
      }
}


Measured memory_bytes: 128
import sys

D = int(input())
C = list(map(int, sys.stdin.readline().rsplit()))
S = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(D)]

d = [0] * 26
res = 0
for i in range(1, D + 1):
    t = int(input()) - 1
    res += S[i - 1][t]
    d[t] = i
    for j, dd in enumerate(d):
        res -= C[j] * (i - dd)
    print(res)


Measured memory_bytes: 9316
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long LL;
int main()
{
    int h,w,n;
    scanf("%d%d%d",&h,&w,&n);
    h=max(h,w);
    printf("%d",(int)ceil(n*1.0/h));
    return 0;
}


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

using namespace std;

typedef long long ll;
#define INF 100000000
#define MOD 1000000007

int main()
{
	int a, b, c;
	bool flag = false;
	
	cin >> a >> b >> c;

	for (int i = 0; i <= 1000; i++) {
		int n_a;
		n_a = b * i + c;
		if (n_a % a == 0) {
			flag = true;
			break;
		}
	}
	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;

	return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1E5+5,P=1E9+7;
int n,a[N],b[N],x,y,fac[N],inv[N],f[N];
int C(int a,int b){return a<0||b<0||a<b?0:1LL*fac[a]*inv[b]%P*inv[a-b]%P;}
signed main() {
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<N;++i)fac[i]=1LL*fac[i-1]*i%P;
	for(int i=2;i<N;++i)inv[i]=1LL*inv[P%i]*(P-P/i)%P;
	for(int i=2;i<N;++i)inv[i]=1LL*inv[i-1]*inv[i]%P;
	cin>>n;++n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(!b[a[i]])b[a[i]]=i;
		else x=b[a[i]],y=i;
	}
	for(int i=1;i<=n;++i)f[i]=C(n,i);
	int sum=(x-1)+(n-y);--f[1];
	for(int i=2;i<=n;++i)f[i]=(f[i]+P-C(sum,i-1))%P;
	for(int i=1;i<=n;++i)cout<<f[i]<<endl;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> P(n), Q(n);
   rep(i, 0, n) cin >> P[i];
   rep(i, 0, n) cin >> Q[i];
   vector<int> p(n);
   rep(i, 0, n) p[i] = i + 1;

   int cnt = 1;
   map<vector<int>, int> mp;
   do {
      mp[p] = mp.size();
   } while (next_permutation(p.begin(), p.end()));
   int ans = abs(mp[Q] - mp[P]);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,m,d;
    cin >> n >> m >> d;
    long k;
    if(d==0) k = n;
    else k = 2*(n-d);
    cout << fixed << setprecision(10) << double(k*(m-1))/double(n*n) << endl;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

template<class T> inline bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

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

int main() {
  int H, W; cin >> H >> W;
  vector<string> s(H);
  rep(i, H) cin >> s[i];
  rep(i, H) rep(j, W) {
    if (s[i][j] == '.') continue;
    bool ok = 0;
    rep(k, 4) {
      int ni = i + dy[k];
      int nj = j + dx[k];
      if (!in_range(ni, nj, H, W)) continue;
      if (s[i][j] == '#' && s[ni][nj] == '#') {
        ok = 1;
      }
    }
    if (!ok) {
      cout << "No\n";
      exit(0);
    }
  }
  cout << "Yes\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const long long mod = 1e9 + 7;
 
long long binpow (long long a, long long b) {
	if (b == 0) 
		return 1;
 	long long t = binpow(a, b / 2);
 	if (b & 1)
		return t * t % mod * a % mod;
 	else 
		return t * t % mod;
}
 
signed main () {
	long long n, k;
	cin >> n >> k;
	vector < long long > d(k + 1, 0);
	for (long long i = 1; i <= k; ++i)
		d[i] = binpow(k / i, n);
	for (long long i = k; i >= 1; --i) {
		for (long long j = 2 * i; j <= k; j += i) 
			((d[i] -= d[j]) += mod) %= mod;
	}
	long long ans = 0;
	for (long long i = 1; i <= k; ++i)
		(ans += ((i * d[i]) % mod)) %= mod;
	cout << ans << '\n';
}


Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,max,i,j,s=0;
	cin>>n;
	int p[n];
	for(i=0;i<n;i++)cin>>p[i];
	max=n+1;
	
	for(i=0;i<n;i++){
		if(p[i]<max){s++;max=p[i];
		}
		
	}

	cout<<s;
	return 0;
}



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

int main(void){
    long long int a, b;
    long long int waru;
    long long int count = 0;
    long long int ans;
    cin >> a >> b >> waru;
    if(a % waru != 0)
        a = (a+waru)/waru*waru;
    if(b % waru != 0)
        b = b/waru*waru;
    ans = (b-a)/waru+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void mod_inverse(int n, vector<long long>& inv, int mod)
{
    inv.assign(n+1, -1);
    inv[1] = 1;
    for(int i=2; i<=n; ++i)
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
}

class FactorialCalculation
{
private:
    const int mod;
    vector<long long> factorial;
    vector<long long> invFactorial;
public:
    FactorialCalculation(int n, int mod) : mod(mod)
    {
        factorial.resize(n+1, 1);
        invFactorial.resize(n+1, 1);
        vector<long long> inv;
        mod_inverse(n, inv, mod);
        for(int i=1; i<=n; ++i){
            factorial[i] = factorial[i-1] * i % mod;
            invFactorial[i] = invFactorial[i-1] * inv[i] % mod;
        }
    }
    long long getFactorial(int n){
        return factorial[n];
    }
    long long getInvFactorial(int n){
        return invFactorial[n];
    }
    long long getPermutation(int n, int r){
        if(n < r)
            return 0;
        return factorial[n] * invFactorial[n-r] % mod;
    }
    long long getCombination(int n, int r){
        if(n < r)
            return 0;
        return getPermutation(n, r) * invFactorial[r] % mod;
    }
    long long getHomogeneous(int n, int r){
        return getCombination(n+r-1, r);
    }
};

const int MOD = 1000000007;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<vector<int> > edges(n);
    for(int i=0; i<n-1; ++i){
        int a, b;
        cin >> a >> b;
        -- a;
        -- b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    FactorialCalculation fc(k, MOD);
    long long ans = fc.getPermutation(k, edges[0].size()+1);
    for(int i=1; i<n; ++i){
        ans *= fc.getPermutation(k-2, edges[i].size()-1);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8568
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>

#define N_size 100000000000

using namespace std;

int main(){
    int r,wa=1;
    cin >> r;

    wa = 3 * r * r;

    cout << wa << endl;

}

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

int main() {

	int a,b;
	cin>>a>>b;
	if(b<10){a=a*10+b;}
  else if(b<100){a=a*100+b;}
  else{a=a*1000+b;}
  if(fmod(sqrt(a),1)==0){cout<<"Yes"<<endl;}
	else{cout<<"No"<<endl;}
}


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

using namespace std;

typedef long long lint;

const int maxn = 1e5+5, inf = 0x3f3f3f3f;

int n, i, j;
lint k, x;
int one[100], zero[100];

lint ans;
lint v[maxn];
int main()
{
    //freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);

    scanf("%d%lld", &n, &k);

    for(i = 1; i <= n; i ++) {
        scanf("%lld", &x); v[i] = x;
        for(j = 0; j <= 50; j ++) {
            if((x & (1LL << j)) != 0) {
                one[j] ++;
            } else {
                zero[j] ++;
            }
        }
    }

    lint x = 0;
    for(i = 50; i >= 0; i --) {
        lint u = 1LL << i;
        if(x + u <= k && zero[i] > one[i]) {
            x += u;
        }
    }

    for(i = 1; i <= n; i ++) {
        ans += (x ^ v[i]);
    }
    printf("%lld", ans);

    return 0;
}


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

using namespace std;
using ll = long long;

string S;
int N;

int distance(char c) {
    int Max = 0, d = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] == c) {
            Max = max(Max, d);
            d = 0;
        } else {
            ++d;
        }
    }
    return max(Max, d);
}

int main() {
    cin >> S;
    N = S.length();
    set<char> se;
    for (auto c : S)
        se.insert(c);

    int ans = INT_MAX;
    for (auto c : se) {
        ans = min(ans, distance(c));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(void){
    Cins(int, 3, a);
    sort(Range(a));
    Cout(a[1] + a[0]);
}

Measured memory_bytes: 256
def step():
    onestep_points = set()
    twostep_points = set()
    threestep_points = set()
    for p in current_points:
        if(routes[p] == 0):
            continue
        for s in routes[p]:
            onestep_points.add(s)
    for p in onestep_points:
        if(routes[p] == 0):
            continue
        for s in routes[p]:
            twostep_points.add(s)
    for p in twostep_points:
        if(routes[p] == 0):
            continue
        for s in routes[p]:
            threestep_points.add(s)
    next_stop = set()
    for p in threestep_points:
        if(p not in stopped_points):
            stopped_points.add(p)
            next_stop.add(p)
    return next_stop
  
import collections
routes = collections.Counter()

N, M = list(map(int, input().split()))
for m in range(M):
    routes[m+1] = []

for m in range(M):
    u, v = list(map(int, input().split()))
    routes[u].append(v)

S, T = list(map(int, input().split()))

loop = 0
current_points = set()
stopped_points = set()
current_points.add(S)

ans = -1
while(True):
    loop += 1
    current_points = step()
    if(T in current_points):
        ans = loop
        break
    if(len(current_points) == 0):
        break
print(ans)  
  


Measured memory_bytes: 39904
N = gets.to_i

div1 = []
div2 = []
for i in 1..(N ** 0.5 + 1) do
  if N % i == 0 then
    div1.push(i)
    div2.push(N/i)
  end
end
  
min = 10 ** 13
for i in 1..div1.length do
  s = div1[i-1] + div2[i-1] - 2
  if s < min then
    min = s
  end
end
  
print min

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

int main(){
  ll r,d;
  vector<ll> x(20);
  cin >> r >> d >> x[0];
  rep(i,10){
    x[i+1] = r*x[i] - d;
  }
  for(int i = 1;i < 11;++i){
    cout << x[i] << endl;
  }
  return 0;
}


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

#define ll long long int
#define vl vector<pair<ll, ll>>

int main() {

    ll N;
    cin >> N;

    ll ans = 0;
    vl R;
    ll x, l;
    ll right;

    for (int i = 0; i < N; i++) {
        cin >> x >> l;
        R.push_back(make_pair(x, l));
    }

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

    ll X, L;
    for (int i = 0; i < N; i++) {
        X = R[i].first;
        L = R[i].second;
        if (right <= X - L || i == 0) {
            ans++;
            right = X + L;
        }
        else {
            right = min(right, X + L);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
// Bismillaahirrahmaanirrahiim
/* Author	: Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define jehian using
#define mau namespace
#define libur std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

jehian mau libur;
/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n");
#define sp printf(" ");

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) memset((x), (y), sizeof(x))

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)

string S, tmp, hehe;
vll idx;
int main(){
	cin >> S;
	for (ll i = 0; i < S.size(); ++i){
		if (S[i] != 'x'){
			tmp.pb(S[i]);
			idx.pb(i);
		}
	}
	hehe = tmp;
	if (tmp.size() > 0){
		reverse(hehe.begin(),hehe.end());
	} else {
		cout << 0 << endl;
		return 0;
	}
	if (hehe != tmp){
		cout << -1 << endl;
	} else {
		ll cnt = 0;
		if (idx.size() > 1){
			ll le, ri;
			if (idx.size() % 2){
				le = idx.size()/2;
				ri = le;
			} else {
				le = idx.size()/2-1;
				ri = le+1;
			}
			ll ujung = (ll) idx.size() - (ll) 1;
			for (; le >= 1 && ri < ujung; --le, ++ri){
				cnt += abs((idx[le]-idx[le-1])-(idx[ri+1]-idx[ri]));
			}
			cnt += abs((idx[le])-((ll) S.size()-1-idx[ri]));
		} else {
			cnt += abs(idx[0]-((ll) S.size()-1-idx.front()));
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1656
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    string o, b; cin >> o >> b;
    string ans;
    rep(i, o.size()) {
        ans += o[i];
        if (i < b.size()) ans += b[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
LL Q, A, B, C, D;
LL _max(LL x, LL y) { return x > y ? x : y; }
LL _min(LL x, LL y) { return x < y ? x : y; }
int main() {
	LL i, j, k;
	scanf("%lld", &Q);
	while(Q--){
		scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
		LL L = 0, R = A+B, ret = 0;
		k = (_max(A, B)-1)/(_min(A, B)+1)+1;
		while(L <= R){
			LL mid = L+R>>1;
			LL sa = A-mid/(k+1)*k-mid%(k+1), sb = B-mid/(k+1);
			if(sa*k >= sb){ ret = mid+1; L = mid+1; }
			else R = mid-1;
		}
		A -= ret/(k+1)*k+ret%(k+1); B -= ret/(k+1);
		LL l = ret, r = ret+B-A*k+1;
		for(i = C; i <= _min(D, l); i++) printf("%c", i%(k+1) ? 'A' : 'B');
		for(i = _max(C, l+1); i <= D; i++) printf("%c", (i-r)%(k+1) ? 'B' : 'A');
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256