akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "../benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int d[222][222];

struct UF{
  vector<int> data;
  UF(int size):data(size,-1){}
  bool unite(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)];}
};


int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int n;
	cin>>n;
	UF uf(2*n);
	rep(i,n){
		string s;
		cin>>s;
		rep(j,n){
			d[i][j]=(s[j]=='1'?1:MOD);
			if(s[j]=='1'){
				uf.unite(i,j+n);
				uf.unite(i+n,j);
			}
		}
	}
	if(uf.size(0)>n){
		cout<<-1<<endl;
		return 0;
	}
	rep(k,n)rep(i,n)rep(j,n) MN(d[i][j],d[i][k]+d[k][j]);
	int re=0;
	rep(i,n)rep(j,i) MX(re,d[i][j]);
	cout<<re+1<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct UF{
	vector<int> par, sz;
	UF(){}
	UF(int n):par(n), sz(n, 1){
		iota(par.begin(), par.end(), 0);
	}
	int find(int x){
		if(x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return;
		if(sz[x] < sz[y]) swap(x, y);
		sz[x] += sz[y];
		par[y] = x;
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
};

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> a(m), b(m);
	UF uf(n);
	vector<int> friends(n);
	REP(i, m){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		uf.unite(a[i], b[i]);
		friends[a[i]]++;
		friends[b[i]]++;
	}
	vector<int> c(k), d(k);
	REP(i, k){
		cin >> c[i] >> d[i];
		c[i]--; d[i]--;
	}
	vector<int> ans(n);
	REP(i, n){
		ans[i] = uf.sz[uf.find(i)] - friends[i] - 1;
	}
	REP(i, k){
		if(uf.same(c[i], d[i])){
			ans[c[i]]--;
			ans[d[i]]--;
		}
	}
	for(int ii = 0; ii < ans.size(); ii++){
			if(ii) cout << ' ';
			cout << ans[ii];
	}
	cout << endl;
}

Measured memory_bytes: 7168
N=int(input())
S=list(input())

L=0
R=0

for i in range(N):
    if(S[i]=="("):
        R+=1
 
    elif(S[i]==")"):
        if(R==0):
            L+=1
        else:
            R-=1

for i in range(R):
        S.append(")")

for i in range(L):
    S.insert(0,"(")
    
print("".join(S))


Measured memory_bytes: 3060
N, P = map(int, input().split())
A = list(map(int, input().split()))
n = 0

for a in A:
    if a % 2 == 0:
        n += 1

if n == N:
    if P == 0:
        ans = 2 ** N
    else:
        ans = 0
else:
    ans = 2 ** (N-1)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define sc second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e6+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
int jc[100005];
int ext_gcd(int a,int b,int &x,int &y){
    if(b==0){x=1;y=0;return a;}
    int q=a/b, g=ext_gcd(b,a-q*b,x,y), z=x-q*y;
    x=y; y=z;
    return g;
}
int inv(int a){
    int x,y;
    ext_gcd(a,mo_num,x,y);
    return (x+mo_num)%mo_num;
}
void init(int *x, int len){
    x[0]=1;
    for(int i=1;i<len;i++)x[i]=(x[i-1]*i)%mo_num;
}

int C(int r,int n){
    if(n<0 or n<r or r<0)return 0;
    return (jc[n]*inv(jc[r])%mo_num)*inv(jc[n-r])%mo_num;
}

int32_t main(){
    int k,n;
    cin>>n>>k;
    init(jc,2001);
    for(int i=1;i<=k;i++){
        out(C(i,n-k+1)*C(i-1,k-1)%mo_num)
    }
    return 0;
}


Measured memory_bytes: 256
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	char a , b , c;
	cin >>a >> b >> c ;
	if(b=='B')cout<<"ARC"<<endl;
	else cout<<"ABC"<<endl;

	return 0;
}

Measured memory_bytes: 3588
import math
a, b, x = map(int, input().split())
maxx = a * a * b
ans_rad = 0
if x + x <= maxx:
    c = 2 * x / (a * b)
    ans_rad = math.atan(b / c)
else:
    y = maxx - x
    c = 2 * y / (a * a)
    ans_rad = math.atan(c / a)

ans = math.degrees(ans_rad)
print(ans)

Measured memory_bytes: 9356
import java.util.*;

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

        String s = scan.next();
        for(int i = 0; i < s.length(); i++) {
            System.out.print("x");
        }
        System.out.println();

        scan.close();
        return;
    }
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 2 * 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int n;
map <string, int> cnt;
string s[N];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    vector <string> ans;
    int ma = 0;
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> s[i];
        cnt[s[i]]++;
        ma = max(ma, cnt[s[i]]);
    }
    FOR(i, 1, n)
    {
        if(cnt[s[i]] == ma)
        {
            ans.pb(s[i]);
            cnt[s[i]] = 0;
        }
    }
    sort(all(ans));
    FOR(i, 0, ans.size() - 1)
    {
        cout << ans[i] << endl;
    }
    return 0;
}


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

void fnInput(vector<int>& rvnBinHeap)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnBinHeap.resize(nMaxSiz + 1);

  for (int i = 1; i < nMaxSiz + 1; ++i)
    cin >> rvnBinHeap[i];
}

void fnBinaryHeaps(const vector<int>& cnrvnBinHeap)
{
  for (int i = 1; i < cnrvnBinHeap.size(); ++i)
  {
  //if (i != 1)  cout << endl;

    cout << "node " << i << ": key = " << cnrvnBinHeap[i] << ", ";
    int nParnt = i / 2;
    int nLeft = i * 2;
    int nRigt = nLeft + 1;
    if (nParnt >= 1)
      cout << "parent key = " << cnrvnBinHeap[nParnt] << ", ";
    if (nLeft < cnrvnBinHeap.size())
      cout << "left key = " << cnrvnBinHeap[nLeft] << ", ";
    if (nRigt < cnrvnBinHeap.size())
      cout << "right key = " << cnrvnBinHeap[nRigt] << ", ";
    cout << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnBinHeap; 

  fnInput(vnBinHeap);
  fnBinaryHeaps(vnBinHeap);
  return 0;
}

Measured memory_bytes: 3228
a=int(input())
AC=[]
WA=[]
TLE=[]
RE=[]
for i in range(a):
  s=(input())
  if s=='AC':
     AC.append(s)
  if s=='TLE':
     TLE.append(s)   
  if s=='WA':
     WA.append(s)
  if s=='RE':
     RE.append(s)
print('AC','x',len(AC))
print('WA','x',len(WA))
print('TLE','x',len(TLE))
print('RE','x',len(RE))
     


Measured memory_bytes: 16436
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define foo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define min3(a,b,c)         min(a,min(b,c))
#define max3(a,b,c)         max(a,max(b,c))
#define min4(a,b,c,d)       min(a,min(b,min(c,d)))
#define max4(a,b,c,d)       max(a,max(b,max(c,d)))
#define max5(a,b,c,d,e)     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)     min(min3(a,b,c),min(d,e))
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
int mpow(int base, ll exp); 
void ipgraph(int m);
void DFS(int n);
bool isprime(ll n);
int gcd(int a,int b);
void rstgraph(int n);

const int mod = pow(10,9)+7;
const int N = 3e5, M = N;

//=======================================================================================
vi g[N];
int vis[N];
int nodes=0;
// ll ans=0;
void iluzn(){
string s;
cin>>s;
int n=s.length();
if(n==1){
  if(s=="s")
    cout<<s+"es";
  else
    cout<<s+"s";
}
else{
  if(s[n-1]=='s'){
    cout<<s+"es";}
    else
      cout<<s+"s";
  
}

}


 
int main() {
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("af.txt","w",stdout);
  #endif
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1,i;
    // cin>>t;
     while(t--) iluzn();
    return 0;
}
int mpow(int base, ll exp) {
  base %=mod ;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
bool isprime(ll n){
    if(n<=1)
        return false;
    if(n==2)
        return true;
    if(n%2==0)
        return false;
    ll rt = sqrt(n);
    for(ll i=3;i<rt;i+=2){
        if(n%i==0)
            return false;
    }
    return true;
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
void ipgraph(int m){
  int u, v;
  while(m--){
    cin>>u>>v;
    g[u].pb(v);
    // g[v].pb(u);
  }
}

void DFS(int n)
{  ++nodes;
    vis[n] = 1;
    for(vector<int>::iterator i = g[n].begin(); i != g[n].end() ; i++)
    {
        if(!vis[*i])
            DFS(*i);
    }
}
void rstgraph(int n){
  int i;
  fo(i,n+1){
    g[i].clear();
    vis[i]=0;
  }
  nodes=0;
}

Measured memory_bytes: 10716
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string N;
    cin >> N;
    
    int sum = 0;
    for(int i = 0; i < N.length();i++){
        sum += stoi(N.substr(i, 1));
    }
    if(sum % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main (){
    int N;
    cin>>N;
    vector<double> vec(N);
    for(int i=0; i<N; i++){
        cin>>vec.at(i);
    }
    sort(vec.begin(), vec.end());
    double Sum=vec.at(0);
    for(int i=1; i<N; i++){
        Sum = (Sum+vec.at(i))/2;
    }
    cout<<Sum<<endl;
}

Measured memory_bytes: 256
object Main extends App {
  @scala.annotation.tailrec
  def loop(l: List[Char], r: Seq[Char], max: Int): Int = r match {
    case Seq() => max
    case y :: ys => loop(y :: l, ys, (y :: l).distinct.count(ys.distinct.contains).max(max))
  }

  val sc = new java.util.Scanner(System.in)
  val _, S = sc.next()
  println(loop(List.empty, S.toCharArray.toList, 0))
}


Measured memory_bytes: 55436
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
counter = Counter(A)
res = sum(A)
for i in range(Q):
    b, c = map(int,input().split())
    res -= counter[b] * b
    res += counter[b] * c
    counter[c] += counter[b]
    counter[b] = 0
    print(res)


Measured memory_bytes: 24108
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import Data.Char
import Data.Int
import Data.List
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import Data.Monoid

exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r

modulo = 10^6+3 :: Int64
addMod, subMod, mulMod, divM :: Int64 -> Int64 -> Int64
addMod !x !y = (x + y) `rem` modulo
subMod !x !y = (x - y) `mod` modulo
mulMod !x !y = (x * y) `rem` modulo
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM !x !y = x `mulMod` recipM y

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  N x + N y = N ((x + y) `rem` modulo)
  N x - N y = N ((x - y) `mod` modulo)
  N x * N y = N ((x * y) `rem` modulo)
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined

instance Fractional N where
  N x / N y = N (divM x y)
  recip (N x) = N (recipM x)
  fromRational = undefined

factL :: [N]
factL = 1 : zipWith (*) factL (map fromInteger [1..])

factFromN :: Int -> Int -> N -> V.Vector N
factFromN n m factN = V.scanl' (\a b -> a * fromIntegral b) factN (V.enumFromN (n+1) (m-1))

factV :: V.Vector N
factV = factFromN 0 200000 1
  <> factFromN 200000 (500000 - 200000) 177247
  <> factFromN 500000 (700000 - 500000) 2
  <> factFromN 700000 (total - 700000) 426941
  where
    total = fromIntegral modulo :: Int

-- factM n == factL !! n == product (map fromInteger [1..n])
-- factM 150000 == 835006
-- factM 300000 == 142803
-- factM 600000 == 715492
-- factM 800000 == 598805
factM :: Int64 -> N
factM n | n < modulo = factV V.! fromIntegral n
        | otherwise = 0

solve :: Int -> Int -> Int -> N
solve x 0 n = (fromIntegral x)^n
solve !x !d !n = let !x' = fromIntegral x :: N
                     !d' = fromIntegral d :: N
                     !xd = unwrapN (x' / d')
                 in if xd + fromIntegral n - 1 >= modulo
                    then 0
                    else d'^n * factM (xd + fromIntegral n - 1) / factM (xd - 1)

main = do
  q :: Int <- readLn
  replicateM_ q $ do
    [x,d,n] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    print (solve x d n)


Measured memory_bytes: 179324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n;
    cin >> n;
    string ans;
    while(n > 0){
        n--;
        ans.push_back('a' + (n%26));
        n /= 26;
    }
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;



signed main(){
    string s;
    cin>>s;
    int x=0,y=0;
    x+=10*(s.at(0)-'0');
    x+=s.at(1)-'0';

    y+=10*(s.at(2)-'0');
    y+=s.at(3)-'0';

    bool flag1=false,flag2=false;
    if(1<=x && x<=12){
        flag1=true;
    }
    if(1<=y && y<=12){
        flag2=true;
    }

    if(flag1 && flag2){
        cout << "AMBIGUOUS" << endl;
    }else if(!flag1 & !flag2){
        cout << "NA" << endl;
    }else if(flag1){
        cout << "MMYY" << endl;
    }else{
        cout << "YYMM" << endl;
    }
}

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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int main(void){
	ll n, k; cin>>n>>k;
	ll ans = 0;

	if(k % 2 == 1) cout<< (n / k)*(n / k)*(n / k) <<endl;
	else {
		ll num = n / (k / 2);
		if(num % 2 == 1) {
			ans = (num/2+1) * (num/2+1) * (num/2+1) + (num/2)*(num/2)*(num/2);
		}
		else {
			ans = (num/2)*(num/2)*(num/2) + (num/2)*(num/2)*(num/2);
		}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

bool prime[int(1e7)+5];

int main() {
    int m = int(1e7);
    vector<ll> p;
    fill(prime,prime+m+1,true);
    prime[0] = false;
    prime[1] = false;
    for(int i=2;i*i<=m;i++){
        if(prime[i]){
            for(int j=i*i;j<=m;j+=i){
                prime[j] = false;
            }
        }
    }
    p.push_back(0);
    for(ll i=2;p.size()<10005;i++){
        if(prime[i]) p.push_back(i);
    }
    for(int i=0;i<p.size();i++){
        p[i+1] += p[i];
    }
    while(1){
        int n;
        cin >> n;
        if(n==0)break;
        cout << p[n] << endl;
    }
    return 0;
}   



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int n, i;
  cin >> n >> i;
  cout << n - i + 1 << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
struct UnionFind {
public:
  int n;
  std::vector<int> par;
  UnionFind(int n): n(n) {
    par.resize(n, -1);
  }
  int root(int x) {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if(rx == ry) return;
    if(par[rx] < par[ry]) {
      std::swap(x, y);
      rx = root(x), ry = root(y);
    }
    par[rx] += par[ry];
    par[ry] = rx;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return -par[root(x)];
  }
};
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, w, h; cin >> n >> w >> h;
  vi tmp = {0, h-1, 0, w-1};
  vi x(n), y(n);
  map<int, vi> mpx, mpy;
  for(int i=0;i<n;++i) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    mpx[x[i]].push_back(i);
    mpy[y[i]].push_back(i);
  }
  UnionFind uf(n);
  for(auto &e: mpx) {
    for(int i=0;i<(int)(e.second.size())-1;++i) {
      uf.unite(e.second[i], e.second[i+1]);
    }
  }
  for(auto &e: mpy) {
    for(int i=0;i<(int)(e.second.size())-1;++i) {
      uf.unite(e.second[i], e.second[i+1]);
    }
  }
  set<int> st;
  for(int i=0;i<n;++i) {
    st.insert(uf.root(i));
  }
  int ans = 0;
  for(auto &e: st) {
    ans += uf.size(e) - 1;
  }
  map<int, vi> mp;
  for(int i=0;i<n;++i) {
    mp[uf.root(i)].push_back(i);
  }
  map<int, int> mp2;
  for(auto &e1: mp) {
    for(int i=0;i<4;++i) {
      int mi = 1;
      for(auto &e2: e1.second) {
        if(i < 2) mi = min(mi, (int)(y[e2] != tmp[i]));
        else mi = min(mi, (int)(x[e2] != tmp[i]));
      }
      mp2[i] += mi;
    }
  }
  int mi = INF;
  for(int i=0;i<4;++i) {
    mi = min(mi, mp2[i]);
  }
  cout << ans + (int)(st.size()) - 1 + ((int)(st.size()) > 1) * mi << endl;
}



Measured memory_bytes: 14632
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 764
W, H, N = map(int, input().split())

minx = 0
maxx = W
miny = 0
maxy = H

for i in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    else:
        maxy = min(maxy, y)

    ans = (maxx - minx) * (maxy - miny)

print(ans if minx < maxx and miny < maxy else 0)

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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    // Fast_IO();
    ll n,k; cin >> n >> k;
    ll a[n]; f(i,0,n-1) cin >> a[i];
    sort(a,a+n);
    ll sum = 0;
    f(i,0,k-1) sum += a[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 3596
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            String st = br.readLine();
            while(st!=null){
            String[] s = st.split(" ",0);
            int valuelength = String.valueOf(Integer.parseInt(s[0])+Integer.parseInt(s[1])).length();
            System.out.println(valuelength);
            st = br.readLine();
            }
        }catch (Exception ex){
            System.exit(0);
        }
    }
}

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

int main() {
  int n;
  bool exist = false;
  cin >> n;

  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i*j == n) {
        exist = true;
        break;
      }
    }
  }

  if (exist == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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


    int N, K; cin >> N >> K;

    double ans = 0;
    int cnt = 0;
    FOR(i,1,N+1) {
        int a = i;
        double p = 1;
        while (a < K) {
            a *= 2;
            p *= 0.5;
        }
        ans += p / N;
    }    

    cout << fixed << setprecision(12) <<  ans << endl;

    return 0;
}

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

#define debug(x) cerr << #x << " = " << x << endl

const int N_MAX = 200003;
int a[N_MAX];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  long long m = 0;
  for (int i = 1; i <= n; ++i)
    cin >> a[i], m += a[i];
  if (m % (1ll * n * (n + 1) / 2) != 0) {
    cout << "NO" << endl;
    return 0;
  }
  m /= 1ll * n * (n + 1) / 2;
  a[0] = a[n];
  for (int i = 1; i <= n; ++i)
    if (m + a[i - 1] - a[i] < 0 || (m + a[i - 1] - a[i]) % n != 0) {
      cout << "NO" << endl;
      return 0;
    }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
int main() {
	string h;
	cin >> h;
	for (int i = 0; i < h.length(); ++i) {
		if (h[i] == '1') { cout << '9'; }
		else { cout << "1"; }
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
 
  int main(){
 lint N,K;
 cin>>N>>K;
 vector<lint>minus;
 vector<lint>plus;
 lint ans=INF;
 rep(i,N){
     lint v;
     cin>>v;
     if(v<0)minus.push_back(v);
     else plus.push_back(v);
 }
 reverse(all(minus));
 rep(i,min(K,(lint)minus.size())){
     lint accum=0;
     accum+=abs(minus[i])*2;
     if(K-i-1<=plus.size()&&i!=(K-1)){
         accum+=plus[K-i-2];
     }else if(i!=(K-1))continue;
     if(i==(K-1))accum-=abs(minus[i]);
        ans=min(ans,accum);
 }

  rep(i,min(K,(lint)plus.size())){
     lint accum1=0;
     accum1+=abs(plus[i])*2;
     if(K-i-1<=minus.size()&&i!=(K-1)){
         accum1-=minus[K-i-2];
     }else if(i!=(K-1)) continue;
          if(i==(K-1))accum1-=abs(plus[i]);
        ans=min(ans,accum1);
 }
    cout<<ans;
}


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

function main()
  N, K = readline() |> split |> parseArray
  S = readline()
  result = S[1:K-1] * lowercase(S[K:K]) * S[K+1:end]
  println(result)
end

main()


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

long long int dp[11][1001];

int main()
{
	dp[0][0] = 1;
	for (int i = 0; i <= 100; i++)
	{
		for (int j = 9; j >= 0; j--)
		{
			for (int k = 0; k + i <= 1000; k++)
			{
				dp[j + 1][k + i] += dp[j][k];
			}
		}
	}

	int n, s;
	while (cin >> n >> s, n + s)
	{
		cout << dp[n][s] << endl;
	}

	return 0;
}

Measured memory_bytes: 3156
//**************************
//*** writer  :  Alan Hu **
//************************
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<cstring>
#include<cmath>

using namespace std;
     
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
     
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(a,max(b,c))-min(a,min(b,c))<<endl;
	return 0;
}

Measured memory_bytes: 256
import static java.lang.System.*;
import java.util.*;

public class Main {
	//初期フィールド・メソッド---------------------------------------------
	static Scanner sc = new Scanner(System.in);
	static int min(int... ar) {Arrays.sort(ar); return ar[0];}
	static int max(int... ar) {Arrays.sort(ar); return ar[ar.length-1];}
	//------------------------------------------------------------


	//フィールド追加場所-----------------------------------------------
	//------------------------------------------------------------


	//メソッド追加場所------------------------------------------------
	//------------------------------------------------------------


	//mainメソッド---------------------------------------------------
	public static void main(String[] args) {
		for (int i=1; i<=9; i++) {
			for (int j=1; j<=9; j++) {
				out.println(i+"x"+j+"="+i*j);
			}
		}
	}
	//------------------------------------------------------------
}


Measured memory_bytes: 26028
#include <bits/stdc++.h>
#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 INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N, M;
  cin >> N >> M;
  if (N == 1 || M == 1) {
    cout << max(max(N - 2, M - 2), (ll)1);
    return 0;
  }

  if (N <= 2 || M <= 2) {
    cout << 0;
    return 0;
  }
  cout << N * M - 2 * (N + M - 2);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			double v = sc.nextDouble();
			double t = v / 9.8;
			double y = 4.9 * t*t;
			double n = (y+5) / 5;
			int N = (int) Math.ceil(n);
			System.out.println(N);
		}
	}

}

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

const int inf = 1e9;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int h, n;
	cin >> h >> n;
	pair<int, int> s[n];
	for (int i = 0; i < n; i++) cin >> s[i].first >> s[i].second;
	sort(s, s + n);
	
	map<int, int> dp;
	for (int i = 1 - s[n - 1].first; i < h; i++) dp[i] = inf;
	dp[h] = 0;
	for (int i = h; i; i--) {
		for (auto spell : s) {
			dp[i - spell.first] = min(dp[i - spell.first], dp[i] + spell.second);
		}
	}
	int ans = inf;
	for (int i = 0; i >= 1 - s[n - 1].first; i--) {
		ans = min(ans, dp[i]);
	}
	cout << ans;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    ll n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
}



Measured memory_bytes: 3568
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]


def dfs(n):
    if n != '':
        if n[0] == '0':
            return 10 ** 7
        elif int(n) >= N:
            return int(n)
    output = 10 ** 7
    for l in L:
        output = min(output, dfs(n + str(l)))
    return output


print(dfs(''))


Measured memory_bytes: 43228
n = int(input())
x, y = [list(map(int, input().split())) for _ in range(2)]

print(sum([abs(x[i] - y[i]) for i in range(n)]))
print(pow(sum([(x[i] - y[i]) ** 2 for i in range(n)]), 1/2))
print(pow(sum([abs(x[i] - y[i]) ** 3 for i in range(n)]), 1/3))
print(max([abs(x[i] - y[i]) for i in range(n)]))


Measured memory_bytes: 5648
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
ll A,B,N;


int main() {
  INCANT;
  cin >> A >> B >> N;
  ll MAX = 0;
  if (B-1>N) {
    cout << (A*N)/B-A*(N/B) << endl;
  } else cout << (A*(B-1))/B-A*((B-1)/B) << endl;
  
  return 0;
}

Measured memory_bytes: 3652
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = i*i+j*j+k*k+i*j+j*k+k*i;
      if v<10050:
        ans[v]+=1
for i in range(n):
    print(ans[i+1])


Measured memory_bytes: 9252
#include <cstdio>
#include <algorithm>

const int MAX_N=1000;

using namespace std;

int a[MAX_N],b[MAX_N],c[MAX_N];

int main(){
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	for (int i=0;i<n;i++){
		if (a[i]<b[i]){
			swap(a[i],b[i]);
		}
		if (a[i]<c[i]){
			swap(a[i],c[i]);
		}
		if (a[i]*a[i]==b[i]*b[i]+c[i]*c[i]){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int,int> pi;
typedef vector<int> vi;
#define ST first
#define ND second
#define PB push_back
#define DET(a,b,c) (LL(b.x-a.x)*LL((c.y-a.y))-LL((c.x-a.x))*LL((b.y-a.y)))

const int MAXN = 100*1000+10;
const LL INF = (LL)1000*1000*1000*1000*1000*1000;
int n,w;
int items[101][2];
LL dp[MAXN];
int ans;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>w;
    for(int i=1; i<=n;i++) cin>>items[i][0]>>items[i][1];
    for(int i=1; i<=1000*100;i++) dp[i] = INF;
    for(int i=1; i<=n;i++) {
        for(int j=1000*100; j>=0;j--) {
            if(j+items[i][1]>1000*100) continue;
            dp[j+items[i][1]]=min(dp[j+items[i][1]],dp[j]+items[i][0]);
            if(dp[j+items[i][1]]<=w) {
                ans=max(ans,j+items[i][1]);
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 1024
## subroutines

def compress(x0, x1, n, w)
  xs = []

  for i in (0...n)
    for d in [-1, 0, 1]
      tx0 = x0[i] + d
      xs << tx0 if tx0 >= 0 && tx0 < w
      tx1 = x1[i] + d
      xs << tx1 if tx1 >= 0 && tx1 < w
    end
  end

  xs.sort!
  xs.uniq!
  w0 = xs.length

  xmap = {}
  for i in (0...w0)
    xmap[xs[i]] = i
  end

  for i in (0...n)
    x0[i] = xmap[x0[i]]
    x1[i] = xmap[x1[i]]
  end

  w0
end

def paint(brd, x0, y0, w, h)
  brd[y0][x0] = 1
  q = [[x0, y0]]

  while ! q.empty?
    x, y = q.shift

    if x > 0 && brd[y][x - 1] == 0
      brd[y][x - 1] = 1
      q << [x - 1, y]
    end
    if x < w - 1 && brd[y][x + 1] == 0
      brd[y][x + 1] = 1
      q << [x + 1, y]
    end
    if y > 0 && brd[y - 1][x] == 0
      brd[y - 1][x] = 1
      q << [x, y - 1]
    end
    if y < h - 1 && brd[y + 1][x] == 0
      brd[y + 1][x] = 1
      q << [x, y + 1]
    end
  end
end

### main

loop do
  w, h = gets.strip.split(' ').map{|s| s.to_i}
  break if (w | h) == 0

  n = gets.strip.to_i

  xs0 = []
  ys0 = []
  xs1 = []
  ys1 = []

  for i in (0...n)
    xs0[i], ys0[i], xs1[i], ys1[i] = gets.strip.split(' ').map{|s| s.to_i}
    xs1[i] -= 1
    ys1[i] -= 1
  end

  w0 = compress(xs0, xs1, n, w)
  h0 = compress(ys0, ys1, n, h)
  #p [xs0, xs1, ys0, ys1]
  #p [w0, h0]

  brd = h0.times.map{w0.times.map{0}}

  for i in (0...n)
    for y in (ys0[i]..ys1[i])
      for x in (xs0[i]..xs1[i])
        brd[y][x] = 1
      end
    end
  end
  #p brd

  cl = 0

  for y in (0...h0)
    for x in (0...w0)
      if brd[y][x] == 0
        cl += 1
        paint(brd, x, y, w0, h0)
      end
    end
  end

  puts cl
end

Measured memory_bytes: 23512
N = int(input())
A = list(map(int, input().split()))

MOD  = 10**9 + 7

l = [0]*(N)
for i in range(N-1):
  l[i+1] += (l[i] +  A[i])%MOD
  
#print(l)

ans = 0
for i in  range(N-1):
  ans += (A[N-1-i] * l[N-1-i])%MOD
  
print(ans%MOD)

Measured memory_bytes: 31552
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    int N; cin>>N;
    ll X; cin>>X;
    vector<ll> x(N+1);

    for (int i = 0; i < N; ++i) {
        cin>>x[i];
    }
    x[N] = X;
    sort(x.begin(), x.end());
    vector<ll> y(N);
    for (int i = 0; i < N; ++i) {
        y[i] = abs(x[i]-x[i+1]);
    }
    ll Gcd = 0;
    for (int i = 0; i < N; ++i) {
        Gcd = __gcd(y[i], Gcd);
    }

    cout<<Gcd<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; cin >> S;
	int C = 114514; int F = -114514; 
	int N = S.size(); 
	for(int i = 0; i < N; i++){
		if(S.at(i) == 'C'){
			C = i; break; 
		}
	}
	for(int i = N-1; i >= 0; i--){
		if(S.at(i) == 'F'){
			F = i; break; 
		}
	}
	if(C < F) cout << "Yes" << endl; 
	else cout << "No" << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long intl;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF = 1e9;
using namespace std;
int main(){
    intl n;
    cin >> n;
    intl a[n];
    bool flag = true;
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        if(!(a[i] % 2)){
            if((a[i] % 3)&& (a[i] % 5))flag = false;
        }
    }
    if(flag)cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)

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

namespace AOJ0519
{
    class Program
    {
        static void Main()
        {
            var teams = int.Parse(Console.ReadLine() ?? "");
            var nodes = Enumerable.Range(1, teams).Select(i => new Node(i)).ToArray();

            var count = int.Parse(Console.ReadLine() ?? "");
            for (var i = 0; i < count; i++)
            {
                var values = (Console.ReadLine() ?? "").Split(' ').Select(int.Parse).ToArray();
                Node.Connect(nodes[values[0] - 1], nodes[values[1] - 1]);
            }

            var noInputs = new Queue<Node>(from node in nodes
                                           where node.Inputs.Count == 0
                                           select node);
            var sorted = new List<Node>();
            var unique = noInputs.Count == 1;

            while (noInputs.Any())
            {
                var node = noInputs.Dequeue();
                sorted.Add(node);
                foreach (var next in new List<Node>(node.Outputs))
                {
                    Node.Disconnect(node, next);
                    if(next.Inputs.Count == 0) noInputs.Enqueue(next);
                    if (unique && noInputs.Count != 1) unique = false;
                }
            }

            foreach (var node in sorted)
            {
                Console.WriteLine(node.Value);
            }

            Console.WriteLine(unique ? 0 : 1);
        }
    }

    public class Node
    {
        public List<Node> Inputs { get; set; }
        public List<Node> Outputs { get; set; }
        public int Value { get; set; }

        public Node(int value)
        {
            Inputs = new List<Node>();
            Outputs = new List<Node>();
            Value = value;
        }

        public static void Connect(Node from, Node to)
        {
            from.Outputs.Add(to);
            to.Inputs.Add(from);
        }

        public static void Disconnect(Node from, Node to)
        {
            from.Outputs.Remove(to);
            to.Inputs.Remove(from);
        }
    }
}

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

#define F                   first
#define S                   second
#define int                 long long int
#define pb                  push_back
#define mp                  make_pair
#define pii                 pair<int,int>
#define vi                  vector<int>
#define mii                 map<int,int>
#define pqb                 priority_queue<int>
#define pqs                 priority_queue<int,vi,greater<int> >
#define mod                 1000000007
#define endl                '\n'
#define rep(i,a,b)            for(int i=a;i<b;i++)
void solve() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) {
        cin >> a[i];
    }
    int ans = 0;
    rep(i, 0, n) {
        rep(j, i + 1, n) {
            rep(k, j + 1, n) {
                if (a[i] == a[j] or a[i] == a[k] or a[j] == a[k]) {
                    continue;
                }
                else {
                    if (a[i] + a[j] > a[k] and a[j] + a[k] > a[i] and a[i] + a[k] > a[j]) {
                        //cout << a[i] << " " << a[j] << " " << a[k] << endl;
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    //c_p_c();
    int t;
    //cin >> t;
    t = 1;
    while (t--) {
        solve();
    }


    return 0;
}

Measured memory_bytes: 3628
#import numpy as np
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
from itertools import permutations as perm


N = int(input())
#H1,M1,H2,M2,K= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())

B = int(input())
C = int(input())
D = int(input())
E = int(input())
m=1000000
l=[N,B,C,D,E]
for v in perm(l,5):
    t=0
    #print(v)
    for i in range(5):
        t+=v[i]

        if v[i] % 10 and i!=4:
            t+=10-v[i]%10
    #print(t)

    m=min(t,m)
print(m)


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

bool prime_test(int n){
  bool is_prime=true;
  if(n==1)is_prime=false;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      is_prime=false;
      break;
    }
  }
  return is_prime;
}

int bi_scale(int a){
  int p;
  for(long long int i=0;i<100;i++){
    if(a>=i*(i+1)/2 && a<(i+2)*(i+1)/2){
      p=i;
      break;
    }
  }
  return p;
}

int main(){

  long long int n;
  cin >> n;

  long long int m=n;
  vector<long long int> f;
  for(long long int i=2;i*i<=n;i++){
    if(m%i==0){
      f.push_back(i);
      m=m/i;
      i--;
    }
    if(m==1)break;
  }
  if(m!=1)f.push_back(m);

  vector<int> a;
  int b[100]={};
  for(int i=0;i<f.size();i++){
    int c=0;
    for(int j=0;j<a.size();j++){
      if(f[i]==a[j]){
        c++;
        b[j]++;
      }
    }
    if(c==0)a.push_back(f[i]);
  }

  int q=0;

  for(int i=0;i<a.size();i++){
    q+=bi_scale(b[i]+1);
  }

  cout << q <<endl;

  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e2+10;
int a[N][N];
int main()
{
    int n,h,w,i,j,l,f,sum=0;
    cin>>h>>w>>n;
    for(i=j=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        sum+=x;
        while(j<sum)
        {
            if((j/w)%2)a[j/w][w-1-j%w]=i+1;
            else a[j/w][j%w]=i+1;
            j++;
        }
    }
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)printf("%d ",a[i][j]);
        printf("\n");
    }
}


Measured memory_bytes: 384