akhauriyash/Code-Regression huggingface dataset:
import scala.io.Source.stdin
import scala.collection.mutable.Queue
import scala.collection.mutable.{ Set => mSet }

object Main {
  val rgb = "rgb".toCharArray

  def main(argv: Array[String]): Unit = {
    stdin.getLines.foreach { l =>
      if (l == "0") sys.exit()

      val q = new Queue[(String, Int)]()
      q.enqueue((l, 0))
      val rgbSet = mSet(Array.fill(l.length)("r").mkString,
        Array.fill(l.length)("g").mkString,
        Array.fill(l.length)("b").mkString)

      val done = mSet[String]()
      var continue = true

      while (continue && q.length > 0) {
        val (buf, time) = q.dequeue
        // 終了判定
        if (rgbSet.contains(buf) && continue) {
          println(time)
          continue = false
        }

        val pairs = (buf.drop(1) zip buf.take(buf.length-1)).map{ case (a, b) => Array(a, b) }.zipWithIndex
        pairs.foreach { case (arr, i) =>
          if (arr(0) != arr(1)) {
            val res = buf.take(i) + convert(arr).mkString + buf.drop(i + 2)
            if (!done.contains(res)) {
              q.enqueue(res -> (time+1))
              done += res
            }
          }
        }

        if (continue && q.length == 0) {
          println("NA")
        }
      }
    }
  }

  def convert(st: Array[Char]): Array[Char] = {
    val c = rgb.filterNot(c => st.contains(c))(0)
    Array(c, c)
  }
}



Measured memory_bytes: 456396
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,k;
	while(cin >> N,N){
		int cnt= 0;int flag = 0;
		for(int i=0;i<N;i++){
		cin >> k;
		if(k>=1) cnt++;
		if(k>=2) flag = 1;
		}
		if(cnt == 0 || flag == 0) cout << "NA" << endl;
		else cout << cnt+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n,m = map(int,input().split())
st = []
co = []
for i in range(n):
  a,b = map(int,input().split())
  st.append([a,b])
for i in range(m):
  c,d = map(int,input().split())
  co.append([c,d])
for a,b in st:
  tmp = 10**9
  output = 0
  for i in range(m):
    if tmp > (new:=abs(a-co[i][0])+abs(b-co[i][1])):
      output = i+1
      tmp = new
  print(output)  

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

class DisjointSet {
   private:
    vector<int> rank, parent;

   public:
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        parent.resize(size, 0);
        rep(i, size) { makeSet(i); }
    }

    void makeSet(int x) {
        parent[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y) { return findSet(x) == findSet(y); }

    void unite(int x, int y) { link(findSet(x), findSet(y)); }

    void link(int x, int y) {
        if (x == y) {
            return;
        }
        if (rank[x] > rank[y]) {
            parent[y] = x;
        } else {
            parent[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }
    int findSet(int x) {
        if (x != parent[x]) {
            parent[x] = findSet(parent[x]);
        }
        return parent[x];
    }
};
int n;

int main() {
    cin >> n;
    DisjointSet ds(n);
    vector<pair<int, int>> vx, vy;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        vx.push_back(make_pair(x, i));
        vy.push_back(make_pair(y, i));
    }
    sort(all(vx));
    sort(all(vy));
    vector<pair<int, pair<int, int>>> edge;
    reps(i, n - 1) {
        edge.push_back(make_pair(vx[i].first - vx[i - 1].first, make_pair(vx[i].second, vx[i - 1].second)));
        edge.push_back(make_pair(vy[i].first - vy[i - 1].first, make_pair(vy[i].second, vy[i - 1].second)));
    }
    ll ans = 0;
    int cnt = 0;
    sort(all(edge));
    for (auto &e : edge) {
        if (!ds.same(e.second.first, e.second.second)) {
            ds.unite(e.second.first, e.second.second);
            ans += e.first;
            cnt++;
            if (cnt == n - 1)
                break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9400
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a;
    cin >> a;
    // スペース区切りの整数の入力
    int b,c;
    cin >> b >> c;

	int d;
	d = b%a;

	if(b%a == 0 || c%a == 0) {
		cout << "OK" << endl;
	} else if((b - d + a) <= c) {
		cout << "OK" << endl;
	} else {
		cout << "NG" <<endl;
	}

    return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 2020;
const int inf = 1e7;


int n;
int a[maxn*2][2];
int mp[2][maxn];
int dp[maxn][maxn];

int cntW[maxn*2][maxn];
int cntB[maxn*2][maxn];

int solve(int w, int b) {
    if (w==0 && b==0) return 0;

    int &res = dp[w][b];
    if (~res) return res;

    res = inf;
    int idx = w+b;

    
    if (w>0) {
	int at = mp[0][w];
	int dist = at-idx;


	// Elems to left of `at` that have already moved to their positions
	// will move our actual index to the left.
	
	dist -= cntW[at-1][w+1];
	dist -= cntB[at-1][b+1];
	
	dist = abs(dist);
	res = min(res, solve(w-1,b) + dist);
    }

    
    if (b>0) {
	int at = mp[1][b];
	int dist = at-idx;

	dist -= cntW[at-1][w+1];
	dist -= cntB[at-1][b+1];

	
	dist = abs(dist);
	res = min(res, solve(w,b-1) + dist);
    }


    return res;
}


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

    cin>>n;
    for (int i=1; i<=n*2; i++) {
	char c; cin>>c;
	a[i][0] = (c=='B');
	cin>>a[i][1];
	mp[a[i][0]][a[i][1]] = i;
    }



    // cntW[i][j]: # of white elems in 1..i that are >= j.
    // White
    for (int i=1; i<=2*n; i++) {
	if (a[i][0] == 0) {
	    for (int j=i; j<=2*n; j++) {
		cntW[j][a[i][1]]++;
	    }
	}
	for (int j=n; j>=0; j--) {
	    cntW[i][j] += cntW[i][j+1];
	}
    }


    // Black
    for (int i=1; i<=2*n; i++) {
	if (a[i][0] == 1) {
	    for (int j=i; j<=2*n; j++) {
		cntB[j][a[i][1]]++;
	    }
	}

	for (int j=n; j>=0; j--) {
	    cntB[i][j] += cntB[i][j+1];
	}
    }
    
    mp[0][0]=mp[1][0]=inf;

    memset(dp,-1,sizeof(dp));
    cout<<solve(n,n)<<endl;

    return 0;
}


Measured memory_bytes: 83128
#include <bits/stdc++.h>
#define MAX 1000001
#define M 1000000009
#define ll long long
#define ld long double
using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((a-b)%2==0) cout << "Alice";
	else cout << "Borys";
	return 0;
}

Measured memory_bytes: 256
package main
import (
    "fmt"
    "bufio"
    "os"
    "strings"
    "strconv"
)

var stdin = bufio.NewScanner(os.Stdin)

func sI() string {
	stdin.Scan()
	return stdin.Text()
}

func main() {
    kx := strings.Split(sI(), " ");
    k,_ := strconv.Atoi(kx[0])
    x,_ := strconv.Atoi(kx[1])
    if(k*500 >= x) {
        fmt.Println("Yes")
    }else{
        fmt.Println("No")
    }
}


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

int main() {
  int D, T, S;
  cin >> D >> T >> S;

  if (T * S >= D)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

long long h, w, n;
map<pair<ll, ll>, ll> mp;
map<pair<ll, ll>, ll> ch;
ll ans[10] = {0};

void solve();

int main() {
  cin >> h >> w >> n;
  for(ll i = 0; i < n; ++i) {
    ll x, y;
    cin >> x >> y;
    --x;
    --y;
    ++mp[make_pair(x, y)];
  }
  solve();
  for(int i = 0; i < 10; ++i) cout << ans[i] << endl;
  return 0;
}

void solve() {
  ll sum = 0, cnt = 0;
  ans[0] = (h - 2) * (w - 2);
  for(auto it = mp.begin(); it != mp.end(); ++it) {
    pair<ll, ll> now = it->first;
    for(ll i = now.fi - 2; i <= now.fi; ++i)
      for(ll j = now.se - 2; j <= now.se; ++j) {
        if(i < 0 || j < 0 || i + 2 >= h || j + 2 >= w)
          continue;
        if(ch[make_pair(i, j)] != 0) continue;
        cnt = 0;
        for(ll k = 0; k < 3; ++k)
          for(ll l = 0; l < 3; ++l)
            if(mp.find(make_pair(i + k, j + l)) != mp.end())
              ++cnt;
        ++ans[cnt];
        ++ch[make_pair(i, j)];
      }
  }
  for(int i = 1; i < 10; ++i) sum += ans[i];
  ans[0] -= sum;
}

Measured memory_bytes: 64768
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int dx[2] = {-1, 1};

int h, w, k;

char c[300][300];
int ans[300][300];
int cnt;

void dfs(int y, int x) {
  ans[y][x] = cnt;
  REP(d, 2) {
    int ny = y;
    int nx = x + dx[d];
    if (nx < 0 || w <= nx) continue;
    if (c[ny][nx] == '.' && ans[ny][nx] == -1) {
      dfs(ny, nx);
    }
  }
}

int main() {
  cin >> h >> w >> k;
  REP(i, h) REP(j, w) cin >> c[i][j];
  REP(i, h) REP(j, w) ans[i][j] = -1;
  cnt = 0;
  REP(i, h) REP(j, w) {
    if (c[i][j] == '#') {
      dfs(i, j);
      cnt++;
    }
  }
  int k = -1;
  REP(i, h) REP(j, w) {
    if (ans[i][j] != -1) {
      k = i;
      break;
    }
  }
  for (int i = k - 1; i >= 0; --i) {
    REP(j, w) {
      if (ans[i][j] == -1) {
        ans[i][j] = ans[i + 1][j];
      }
    }
  }
  for (int i = k + 1; i < h; ++i) {
    REP(j, w) {
      if (ans[i][j] == -1) {
        ans[i][j] = ans[i - 1][j];
      }
    }
  }
  REP(i, h) {
    REP(j, w) { cout << ans[i][j] + 1 << " "; }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;


int main()
{
    int a, b, k;
    cin >> k >> a >> b;
    for (int i = a; i <= b; ++i)
        if (i % k == 0)
            return cout << "OK", 0;
    cout << "NG";
}


Measured memory_bytes: 3620
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);   t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}
     
void solve(){
	ll h,n,w;cin>>h>>w>>n;
	ll ans = 1e9;
	forn(i, h+1)
	{
		forn(j, w+1)
		{
			if(i*w+j*h-i*j >= n)
			{
				ans = min(ans, i+j);
			}
		}
	}
	cout<<ans<<ln;
}
 
int main()
{
	fast_cin();
    ll t=1;
    //cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,k,i,j;
    cin>>n>>k;
    string str;
    cin>>str;
    str[k-1]+=32;
    cout<<str<<endl;
return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<bool> vb;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

class Graph{
	private:
	int GV,GE;
	vvi List;
	public:
	vb ap;
	Graph(int v,int e){
		GV=v;
		GE=e;
		List=vvi(v);
	}
	void add_edge(int x,int y){
		List[x].push_back(y);
		List[y].push_back(x);
	}
	void APfunc(int x,vb& used,vi& disc,vi& low,vi& par){
		static int time=0;
		int ch=0;
		used[x]=1;
		disc[x]=low[x]=++time;
		for(int i=0;i<List[x].size();i++){
			int v=List[x][i];
			if(!used[v]){
				ch++;
				par[v]=x;
				APfunc(v,used,disc,low,par);
				low[x]=min(low[x],low[v]);
				if(par[x]==-1&&ch>1) ap[x]=1;
				if(par[x]!=-1&&low[v]>=disc[x]) ap[x]=1;
			}
			else if(v!=par[x]) low[x]=min(low[x],disc[v]);
		}
	}
	void AP(){
		ap=vb(GV);
		vb used(GV);
		vi disc(GV),low(GV),par(GV,-1);
		for(int i=0;i<GV;i++){
			if(!used[i]) APfunc(i,used,disc,low,par);
		}
	}
};

int V,E;

int main(){
	cin>>V>>E;
	Graph gra(V,E);
	int s,t;
	for(int i=0;i<E;i++){
		cin>>s>>t;
		gra.add_edge(s,t);
	}
	gra.AP();
	for(int i=0;i<V;i++){
		if(gra.ap[i]) cout<<i<<endl;
	}
}

Measured memory_bytes: 2936
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  cout<<m*2-n<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
  int x, y;
  scanf("%d %d", &x, &y);

  for (int i = 0; i <= x; i++) {
    int j = x - i;
    if (i * 2 + j * 4 == y) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");

  return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<typename U, typename V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}
 
int main() {
    FAST_IO();
    ll N, A, B; cin >> N >> A >> B;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    ll S = 0, lo = 0, hi = 1e9;
    while(lo <= hi) {
        ll mid = (lo + hi) >> 1;
        ll sum = 0;
        rep(i, N) {
            sum += max(0LL, (H[i] - B * mid + A - B - 1) / (A - B));
        }
        if(sum <= mid) {
            S = mid;
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << S << "\n";
}

Measured memory_bytes: 640
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1167

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int MAX = 1000100;

vector<int> list;
vector<int> odd;

void init()
{
	for(int i=1;;i++)
	{
		int num = i*(i+1)*(i+2)/6;
		if(num > MAX){ break; }
		list.push_back(num);
		if(num % 2){ odd.push_back(num); }
	}

	return;
}

int main()
{
	init();
	
	vector<int> dp(MAX,MAX);
	vector<int> odd_dp(MAX,MAX);
	
	dp[0] = 0;
	odd_dp[0] = 0;

	rep(i,list.size()){
		REP(j,list[i],MAX){
			dp[j] = min(dp[j], dp[j - list[i]] + 1);	
		}
	}

	rep(i,odd.size()){
		REP(j,odd[i],MAX){
			odd_dp[j] = min(odd_dp[j], odd_dp[j - odd[i]] + 1);	
		}
	}
	
	int N;
	while(cin >> N && N){
		cout << dp[N] << " " << odd_dp[N] << endl;	
	}

	return 0;
}

Measured memory_bytes: 8852
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    string S;
    int w;
    cin >> S;
    cin >>w;
    for(int i = 0; i < S.length(); i += w){
        cout << S.at(i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long H,A;
  cin >> H;
  cin >> A;
  cout << (H-H%A)/A+(H%A>0) << endl;
  //vector<long long> vec(N);
  //for (i=0;i<N;i++) {
   //cin >> vec.at(i);
  //}  
}

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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(N);
    }
}

class Solver {
    public void solve(long N) {
        System.out.println((int) (N / 2.0 + 0.6));
    }
}



Measured memory_bytes: 21844
#!/usr/bin/env ruby

loop do
  x = gets.chomp!.to_f
  h = gets.chomp!.to_f

  break if x.zero? && h.zero?

  hh = (x / 2 * x / 2 + h * h) ** 0.5
  puts format '%.6f', x * x + x * hh * 2

end

Measured memory_bytes: 6936
/*
Reference : https://www.geeksforgeeks.org/maximum-product-subsequence-size-k/
 
 
*/
#include <bits/stdc++.h> 
using namespace std; 
 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
bool sortbysecdesc(const pair<int,int> &a, 
                   const pair<int,int> &b) 
{ 
       return a.second>b.second; 
} 
 
/*
Mistakes
 
- while using pairs make sure you comparator datatype it's int by default change it as per the need
- Modify comparator if you want to
*/
#define f first
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll64 int64_t
#define pb push_back
#define pll pair<long long int,long long int>
#define pi pair<int,int>
#define mi map<int,int>
#define ll long long int
#define mll map<long long int,long long int>
#define umi unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<long long int,long long int>>
#define mod 1000000007
#define fp(i,x,n) for(int i=x;i<n;i++)
#define fn(i,x,n) for(int i=x;i>n;i--)
#define fpm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define asort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysec)
#define asort_vp_first(vect) sort(vect.begin(), vect.end())
#define dsort_vp_first(vect) sort(vect.begin(), vect.end(), sortinrev) 
#define dsort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysecdesc)
#define vi vector<int>
#define vll vector<long long int>
#define c(x) cout<<x<<endl;
#define M 1000000007
using namespace std; 
#define int long long int
 
signed main()
{
    FIO;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)));
   
}

Measured memory_bytes: 3644
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn combination_two(n: usize) -> usize {
    if n == 2 {
        return 1;
    }
    if n < 2 {
        return 0;
    }
    n * (n - 1) / 2
}

fn main() {
    input! {
        n: usize,
        a: [usize;n],
    }
    let mut mem: std::vec::Vec<usize> = vec![0; n + 1];
    let mut map: std::collections::HashMap<usize, usize> = std::collections::HashMap::new();
    for &i in a.iter() {
        let default = 0;
        let &v = map.get(&i).unwrap_or(&default);
        map.insert(i, v + 1);
    }
    let mut sum = 0;
    for (i, v) in map {
        mem[i] = combination_two(v) - combination_two(v - 1);
        sum = sum + combination_two(v);
    }
    // println!("{:?}", mem);
    for k in 0..n {
        println!("{}", sum - mem[a[k]]);
    }
}

Measured memory_bytes: 19220
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	int a[m];
	memset(a, 0, sizeof(a));
	rep(i, n){
		int k;
		cin >> k;
		rep(j, k){
			int x;
			cin >> x;
			x--;
			a[x]++;
		}
	}
	int ans = 0;
	rep(i, m) if(a[i] == n) ans++;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
n,k = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n-1)]
mod = 10**9+7

E = [[] for i in range(n+1)]
for i in range(n-1):
    E[A[i][0]].append(A[i][1])
    E[A[i][1]].append(A[i][0])
    #print(E)

B = [0 for i in range(n+1)]
H = [0 for i in range(n+1)]

def tuke(x,y,z):
    H[x] = 1
    B[x] = y
    y = max(k-z-1, k-2)
    for i in E[x]:
        if H[i] == 0:
            LI.append([i,y,z+1])
            y -= 1

LI = [[1,k,0]]

kk = 0
while kk < len(LI):
    tuke(LI[kk][0],LI[kk][1],LI[kk][2])
    kk += 1

ans = 1
for i in range(1,len(B)):
    ans = (ans * B[i]) % mod

#print(B)
print(ans)

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

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

  ll L[3*N] = {};
  ll R[3*N] = {};
  rep(i, N){
    if(A[i] >= N) continue;
    L[A[i]+i]++;
    R[-A[i]+i]++;
  }
  ll ans = 0;
  rep(i, N){
    ans += L[i] * R[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14808
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d=0;
  cin>>a>>b>>c;
  if(a!=b){
    d++;
  }
  if(b!=c){
    d++;
  }
  if(a!=c){
    d++;
  }
  if(d==0){
    d++;
  }
  cout<<d<<"\n";
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;
import java.lang.*; 
import java.util.regex.Pattern;
import java.text.DecimalFormat;
import java.util.stream.IntStream;
public class Main{    
public static void main(String[] args)
{     
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int count;
int c=1;
int[] a=new int[n];
for(int i=0;i<n;i++)
{
   a[i]=scanner.nextInt();
}
for(int i=1;i<n;i++)
{ count=0;
  for(int j=0;j<i;j++)
   if(a[i]>=a[j])count++;else break;
 if(count==i)c++;
}
System.out.println(c);
}
}






Measured memory_bytes: 21844
N = int(input())
X = list(map(int, input().split()))
Xc = X.copy()
Xc.sort()

Xcmed = Xc[N//2]

for i in range(N):
    if X[i] < Xcmed:
        print(Xc[N // 2])
    else:
        print(Xc[N // 2 - 1])


Measured memory_bytes: 25224
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    int n; cin >> n;
    VI a(n);
    REP(i, n)  a[i] = i + 1;
    do{
        REP(i, n){
            if(i) cout << " ";
            cout << a[i];
        }
        cout << "\n";
    }while(next_permutation(ALL(a)));
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define endl "\n"
    #define space " "
    #define ll long long int
    #define vl vector<ll>
    #define vvl vector < vll >
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define vpl vector < pll >
    #define mod 1000000007
    #define pi 3.1415926535897932384626433
    #define inf 1000000000000000001;
    #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y) 
    #define mem(a,val) memset(a,val,sizeof(a))
    #define pb push_back
    #define f first
    #define s second
    
    void solve()
    {
        string s,t;
        cin>>s>>t;
        ll p=0;
        for (int i = 0; i < s.length(); ++i)
        {
            /* code */
            if(s[i]!=t[i]) p++;
        }
        cout<<p;
    }

    signed main()
    {

    fast;
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif

    ll T=1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
    }


Measured memory_bytes: 3880
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        String s = obj.next();
        int n = s.charAt(s.length()-1)-'0';
        if(n==2 || n==4 || n==5 || n==7 || n==9)
            System.out.println("hon");
        else if(n==3) System.out.println("bon");
        else if(n==0 || n==1 || n==6 || n==8) System.out.println("pon");
    }
}


Measured memory_bytes: 32504
from collections import deque
N=int(input())
A=map(int,input().split())
# Aから要素を削除していくと[1,2,3,...]になるかどうかを判定する．砕く個数が最小のときは最後に残る要素が最大になる
D=deque(A)
count = 1
for i in range(N):
    d = D.popleft()
    if d == count:
        count+=1
if count == 1:
    print(-1)
else:
    print(N-(count-1))


Measured memory_bytes: 25244
program main
 implicit none
 integer*8 N,M,i,j,d,k
 integer*8, allocatable::a(:),b(:)
 read(*,*) N
 allocate(a(1:N),b(1:N))
 read(*,*) a
 
 M=0
 do i=N/2+1,N
  b(i) = a(i)
  if(a(i) == 1) M = M+1
 end do
 
 do i=N/2,1,-1
  d = N/i
  k=0
  do j=2,d
   k = mod(k + b(i*j),2)
  end do
  b(i) = mod(a(i) + k,2)
  if(b(i) == 1) M = M+1
 end do
 write(*,*) M
! write(*,*) b
 do i=1,N
  if(b(i) == 1) write(*, '(i11)', advance="NO") i
 end do
end program main

Measured memory_bytes: 4864
n=int(input())
b=list(map(int,input().split()))
k=b[n-2]
if n>2:
    for i in range(0,n-2):
        if b[n-i-3]<b[n-i-2]:
            k+=b[n-i-3]
        else:
            k+=b[n-i-2]
k+=b[0]
print(k)

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a*b%2==0)
    cout<<"Even"<<endl;
  else
  {
    cout<<"Odd"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, string) {
	n := scanInt(sc)
	str := scanString(sc)
	return n, str
}

const modulo = 1e9 + 7

func resolve(n int, str string) int {
	nums := map[byte]int{}
	for i := 0; i < len(str); i++ {
		nums[str[i]]++
	}
	num := 1
	for _, v := range nums {
		num = (num * (v + 1)) % modulo
	}
	return (num - 1) % modulo
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
using namespace std;

string s;
int main() {
	cin>>s;
	ll c=0;
	for(char x : s){
		c += x-'0';
	}
	string ans;
	if(c%9==0) ans ="Yes";
	else ans = "No";
	cout << ans << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++) cin >> h[i];
    int dp[n];
    for(int i=0;i<n;i++) dp[i]=1e9;
    dp[0]=0;
    for(int i=0;i<n;i++){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
n = int(input())
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]

maxSum = 0
for i in range(n):
    sum = 0
    for j in range(i+1):
        sum += a1[j]
    for j in range(i, n):
        sum += a2[j]
    maxSum = max(maxSum, sum)
print(maxSum)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#define INF 1<<28
using namespace std;
 
int p[222];
int memo[1000001];
int memo2[1000001];
 
int solve(int n){

  if(!n) return 0;
  if(memo[n]) return memo[n];
   
  int ans = INF;
  for(int i=1;p[i]<=n; i++) ans = min(ans, solve(n-p[i])+1);
   
  return memo[n] = ans;
}
 
int solve2(int n){
   
  if(!n) return 0;
  if(memo2[n]) return memo2[n];
   
  int ans = INF;
  for(int i=1;p[i]<=n;i++){
    if(p[i]&1) ans = min(ans, solve2(n-p[i])+1);
  }
   
  return memo2[n] = ans;
}
 
int main(){
   
  int n;
   
  for(int i=0;i<=181;i++) p[i] = i*(i+1)*(i+2)/6;
  for(int i=1;i<=1000000;i+=1000) solve(i), solve2(i);
   
  while(cin >> n, n) cout << solve(n) << " " << solve2(n) << endl;
}

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

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

    vector<vector<int>> yakusuu(200);
    rep(i, 200) {
        yakusuu[i].push_back(1);
        int n = i+1;
        for (int j = 2; j <= n; j++) {
            if (n % j == 0) yakusuu[i].push_back(j);
        }
    }

    int cnt = 0;
    rep(i, k) rep(j, k) rep(l, k) {
        bool c = false;
        for (int m = yakusuu[i].size()-1; m >= 0; m--) {
            bool d = false;
            if (c) break;
            for (int n = yakusuu[j].size()-1; n >= 0; n--) {
                bool e = false;
                if (c || d) break;
                if (yakusuu[i][m] > yakusuu[j][n]) d = true;
                for (int o = yakusuu[l].size()-1; o >= 0; o--) {
                    if (c || d || e) break;
                    if (yakusuu[i][m] > yakusuu[l][o] || yakusuu[j][n] > yakusuu[l][o]) e = true;
                    if (yakusuu[i][m] == yakusuu[j][n] && yakusuu[j][n] == yakusuu[l][o]) {
                        cnt += yakusuu[i][m];
                        c = true;
                    }
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,Q = map(int,input().split())
to = [[] for _ in range(N+1)]
ans = [0 for _ in range(N+1)]

for _ in range(N-1):
    a,b=map(int,input().split())
    to[a].append(b)
    to[b].append(a)
for _ in range(Q):
    p,x = map(int,input().split())
    ans[p] += x

def dfs(v, p):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
dfs(1, -1)
print(*ans[1:])


Measured memory_bytes: 230936
import Data.List
import Data.List.Split

plus :: Int -> [Int] -> [Int] -> [Int] -> [Int]
plus (-1) _ _ zs = zs
plus n xs ys zs
  | elem n xs = plus (n-1) xs ys (((ys !! n) + 1):zs)
  | otherwise = plus (n-1) xs ys ((ys !! n):zs)

small :: Int -> Int -> [[Int]] -> [[Int]]
small x y xs = (take (y-1) xs) ++ (a:b:c:(drop (y+2) xs))
  where a = plus 13 [x] (xs !! (y-1)) []
        b = plus 13 [x-1,x,x+1] (xs !! y) []
        c = plus 13 [x] (xs !! (y+1)) []

regular :: Int -> Int -> [[Int]] -> [[Int]]
regular x y xs = (take (y-1) xs) ++ (a:b:c:(drop (y+2) xs))
  where a = plus 13 [x-1,x,x+1] (xs !! (y-1)) []
        b = plus 13 [x-1,x,x+1] (xs !! y) []
	c = plus 13 [x-1,x,x+1] (xs !! (y+1)) []

large :: Int -> Int -> [[Int]] -> [[Int]]
large x y xs = (take (y-2) xs) ++ (a:b:c:d:e:(drop (y+3) xs))
  where a = plus 13 [x] (xs !! (y-2)) []
	b = plus 13 [x-1,x,x+1] (xs !! (y-1)) []
	c = plus 13 [x-2,x-1,x,x+1,x+2] (xs !! y) []
	d = plus 13 [x-1,x,x+1] (xs !! (y+1)) []
	e = plus 13 [x] (xs !! (y+2)) []

solve :: [[Int]] -> [[Int]] -> [[Int]]
solve m [] = m
solve m ([x,y,z]:xs)
  | z == 3 = solve (small x y m) xs
  | z == 4 = solve (regular x y m) xs
  | z == 5 = solve (large x y m) xs

mkMap :: [[Int]]
mkMap = replicate 14 $ replicate 14 0

countZero :: [[Int]] ->	Int
countZero [] = 0
countZero (x:xs) = (length $ elemIndices 0 x) + countZero xs

mold :: [[Int]] -> [[Int]]
mold xs = mold' $ take 10 $ drop 2 xs
  where mold' [] = []
        mold' (x:xs) = (take 10 $ drop 2 x) : mold' xs

printAns :: [[Int]] -> IO ()
printAns xs = do
  print $ countZero xs
  print $ maximum $ map maximum xs

main = getContents >>= printAns . mold . solve mkMap . map (map ((+) 2 . read) . splitOn ",") . lines


Measured memory_bytes: 4052
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <limits.h>
#include <map>
#define MAXN 200000
#define Amari 1000000007
#define p pair <int,int>
using namespace std;
multimap <int, int> ship;
int n,m,cnt=0;
bool clear = false; 
int main(int argc,char const* argv[])
{
  cin >> n;
  vector<long long> a(n,0);
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
    }
  sort(a.begin(),a.end());
  vector <long long> v;
  for(int i=n-1;i>0;i--)
    {
      if(a[i]==a[i-1])
	{
	  v.push_back(a[i]);
	  i--;
	}
    }
  v.push_back(0);
  v.push_back(0);
  cout << v[0]*v[1] << endl;
  return 0;
}


Measured memory_bytes: 1660
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
/////////////////// 
//

#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n,h,w;
  cin >> n >> h >> w;
  pri((n-h+1)*(n-w+1));
  return 0;
}







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

#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 310;

long double dp[N][N][N];

long long int a1, a2, a3;

int main () {
    cout << setprecision(12) << fixed;
    long long int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++ ) {
        int x;
        cin >> x;
        if(x==1)a1++;
        if(x==2)a2++;
        if(x==3)a3++;
    }
    dp[0][0][0]=0;
    for(int k = 0 ; k <= n ; k++ ) {
        for(int j = 0 ; j <= n ; j++ ) {
            for(int i = 0 ; i <= n ; i++ ) {
                if(i+j+k>n||i+j+k==0)continue;
                long double ii = i, jj = j, kk = k;
                if(i!=0)dp[i][j][k]+=ii*(dp[i-1][j][k]+1);
                if(j!=0)dp[i][j][k]+=jj*(dp[i+1][j-1][k]+1);
                if(k!=0)dp[i][j][k]+=kk*(dp[i][j+1][k-1]+1);
                dp[i][j][k]+=n-ii-jj-kk;
                dp[i][j][k]/=i+j+k;
            }
        }
    }
    cout << dp[a1][a2][a3] << '\n';
}


Measured memory_bytes: 450688
import sys
input = sys.stdin.readline

n, k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]

dp = [float('inf')] * (n + 1)
dp[1] = 0

for i in range(1, n + 1):
    for j in range(1, k + 1):
        if i + j <= n:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i - 1] - h[i + j - 1]))

print(dp[-1])


Measured memory_bytes: 55260
#include <stdio.h>

int
main(void)
{
	int i;
	int x;
	int y;
	int idx = 0;
	int input_num[5000];

	while (1) {
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0) break;
		input_num[idx] = x;
		input_num[idx+1] = y;
		idx += 2;
	}

	for (i = 0; i < idx; i += 2) {
		if (input_num[i] < input_num[i+1])
			printf("%d %d\n", input_num[i], input_num[i+1]);
		else
			printf("%d %d\n", input_num[i+1], input_num[i]);
	}

	return 0;
}


Measured memory_bytes: 1916
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16036
#include<cstdio>
#include<iostream>
#include<map>
#include<cmath>
#include<algorithm>

#include<cstdlib>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
int a[100],b[100],c[100],d[100];
int Min,ans;
int main(){
	int n,m;
	cin >> n >> m;
	for(int i = 1;i <= n;i++){
			scanf("%d %d",&a[i],&b[i]);
		}
	for(int j = 1;j <= m;j++){
			scanf("%d %d",&c[j],&d[j]);
		}
	for(int i = 1;i <= n;i++){
			Min = 999999999;
		for(int j = 1;j <= m;j++){
			if(Min>(abs(a[i]-c[j])+abs(b[i]-d[j]))){
				Min =  abs(a[i]-c[j])+abs(b[i]-d[j]);
				ans = j;
				}
			}
			printf("%d\n",ans);
		}
	return 0;
	}
//a

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

int main() {
	string S;
	cin >> S;

	const int length = S.length();
	int res = 0;
	for (int i = 0; i < length / 2; ++i) {
		if (S[i] != S[length - 1 - i]) {
			res++;
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        if(A > T){
            System.out.println(0);
        }else{
            int result = T / A * B;
            System.out.println(result);
        }
    }
}


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

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

    string s;
    cin >> s;

    string ans;
    for(size_t i = 0; i < s.size(); ++i){
        if(s[i] == '0'){
            ans += "0";
        }
        if(s[i] == '1'){
            ans += "1";
        }
        if(s[i] == 'B' && ans.size() != 0){
            ans = ans.substr(0, ans.size() - 1);
        }
       //cout << ans << endl;    
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256