akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
int main() {
	std::string string;
	while (std::getline(std::cin, string)) {
		std::stack<long double> stack;
		std::stringstream stringstream;
		if (string.empty() == true) {
			break;
		}
		else {
			stringstream << string;
		}
		while (stringstream >> string) {
			if (isdigit(*string.rbegin())) {
				stack.push(atof(string.c_str()));
			}
			else {
				double a, b;
				if (stack.empty() == true) {
					break;
				}
				else {
					b = stack.top();
					stack.pop();
				}
				if (stack.empty() == true) {
					break;
				}
				else {
					a = stack.top();
					stack.pop();
				}
				switch (string.front()) {
				case '+':
					stack.push(a + b);
					break;
				case '-':
					stack.push(a - b);
					break;
				case '*':
					stack.push(a * b);
					break;
				case '/':
					if (b == 0) {
						while (stack.empty() == false) {
							stack.pop();
						}
						break;
					}
					stack.push(a / b);
					break;
				}
			}
		}
		if (stack.empty() == true) {
			std::cout << "ERROR" << std::endl;
		}
		else {
			std::cout << std::fixed << std::setprecision(6) << stack.top() << std::endl;
		}
	}
	return EXIT_SUCCESS;
}

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

const int maxn=25;
const int mod=1e9+7;
const int sz=21;
int T,n;
int binom[maxn][maxn],G[maxn];

class Matrix{
public:
	int m[maxn][maxn];
	Matrix(){memset(m,0,sizeof(m));}
	Matrix operator*(const Matrix &o)const{
		Matrix res;
		for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)
			for(int k=0;k<sz;k++)res.m[i][j]=(res.m[i][j]+1LL*m[i][k]*o.m[k][j])%mod;
		return res;
	}
}trans;
Matrix power(Matrix x,int pow){
	Matrix res;
	for(int i=0;i<sz;i++)res.m[i][i]=1;
	for(;pow;pow>>=1){
		if(pow&1)res=res*x;
		x=x*x;
	}
	return res;
}

int main(){
	binom[0][0]=1;
	for(int i=1;i<sz;i++){
		binom[i][0]=binom[i][i]=1;
		for(int j=1;j<i;j++)binom[i][j]=(binom[i-1][j-1]+binom[i-1][j]);
	}
	for(int i=0;i<=11;i++)for(int j=0;j<=5;j++)
		G[i+2*j]=(G[i+2*j]+1LL*(i&1?mod-binom[11][i]:binom[11][i])*(j&1?mod-binom[5][j]:binom[5][j]))%mod;
	for(int i=0;i<=20;i++){
		if(i)trans.m[i][i-1]=1;
		trans.m[i][20]=(mod-G[21-i])%mod;
	}
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		if(n<=4)puts("0");
		else{
			Matrix cur=power(trans,n-5);
			printf("%d\n",cur.m[20][20]);
		}
	}
	return 0;
}

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

using namespace std;


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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, double>  iidb;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define offset 
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 209999
int go(int x0,int y0,int xf,int yf,int t)
{
	int res=abs(x0-xf)+abs(y0-yf);
	if (res%2==t%2 && res<=t)
		return 1;
	return 0;
}
int main()
{
	int n;
	cin>>n;
	int x0,y0,xf,yf,t,t0;
	t0=x0=y0=0;
	bool valid=1;
	forr(i,0,n)
	{
		cin>>t;
		//cout<<t<<" ";
		
		cin>>xf>>yf;
		valid&=go(x0,y0,xf,yf,t-t0);
		x0=xf,y0=yf;
		t0=t;
		//cout<<valid<<endl;
	}
	if (valid)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}				

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


int main(){
	LL A, B;cin >> A >> B;
	LL K;cin >> K;
	LL m, M;
	m = min(A + K, B);
	M = max (B - K + 1, A);
	if(m>M) M = m;
	for(LL i = A;i < m ; i++){
		cout << i << endl;
	}

	for(LL i = M; i <= B; i++){
		cout << i << endl;
	}
	return 0;

}












Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define pb push_back
#define mp make_pair
const ll mod=1e9+7;

ll func(ll A[], ll n, ll k)
{
    sort(A, A + n);
    ll product = 1;
    if (A[n - 1] == 0 && (k & 1))
        return 0;
    if (A[n - 1] <= 0 && (k & 1)) {
        for (int i = n - 1; i >= n - k; i--)
            product=((product%mod)*(A[i]%mod))%mod;
        return (product+mod)%mod;
    }
    ll i = 0;
    ll j = n - 1;
  if (k & 1) {
        product *= A[j];
        j--;
        k--;
    }
        k >>= 1;
    for (int itr = 0; itr < k; itr++) {
        ll left_product = A[i] * A[i + 1];
        ll right_product = A[j] * A[j - 1];
        if (left_product > right_product) {
            product=((product%mod)*(left_product%mod))%mod;
            i += 2;
        }
        else {
            product=((product%mod)*(right_product%mod))%mod;
            j -= 2;
        }
    }
    return (product+mod)%mod;
}

void solve()
{
  ll n,k;
  cin>>n>>k;
  ll V[n];
  for(int i=0;i<n;i++)
  cin>>V[i];
  cout<<(func(V,n,k)+mod)%mod;
}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 5172
def prime(K):
    for i in range(2,K):
        if K%i == 0:
            return 0
    return 1
N = int( input())
ANS = []
K = 0
for i in range(11, 55555):
    if i%5 == 1:
        if prime(i) == 1:
            ANS.append(i)
            K += 1
    if K == N:
        break
for i in range(N-1):
    print(ANS[i], end = ' ')
print(ANS[N-1])

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

int main() {
  string s; cin >> s;
  while(s.size() < 15) s += 'o';
  int win = 0;
  rep(i,15) {
    if(s[i]=='o') win++;
  }
  if(win>=8) puts ("YES");
  else puts ("NO");

  return 0;
}


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

using namespace std;

using lli = long long int;
using ulli = unsigned long long int;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

lli N;
lli aA[200010];
ulli MIN = 137438953472;

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

	cin >> N;
	aA[0] = 0;
	for(lli i = 1; i <= N; i++){
		cin >> aA[i];
		aA[i] += aA[i-1];
	}
	for(lli i = 1; i < N; i++){
		MIN = min(MIN, (ulli)abs(aA[i]*2 - aA[N]));
	}
	cout << MIN;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
  int R,G,B,N;
  cin>>R>>G>>B>>N;
  unsigned ans=0;
  for(int b=0 ; b<=N ; b++){
    for(int g=0 ; g<=N ; g++){
      int B_G = b*B+g*G ;
      if( N>=B_G && (N-B_G)%R==0 ){
        ans++;
      }
    }
  }

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




Measured memory_bytes: 256
import java.util.*;

public class Main {

   public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       
       while(true){
           int n = sc.nextInt();
           int m = sc.nextInt();
       
           if(n== 0 && m == 0){
               break;
           }
           
           int []taro = new int[n];
           int []hanako = new int[m];
           int sumT = 0;
           int sumH = 0;
           for(int i = 0;i < n;i++){
              taro[i] += sc.nextInt();
              sumT += taro[i];
           }
           for(int i = 0;i < m;i++){
               hanako[i] = sc.nextInt();
               sumH += hanako[i];
           }
           
           int minSumI = -1;
           int minSumJ = -1;
           int minSum = Integer.MAX_VALUE;
           
           for(int i = 0;i < n;i++){
               for(int j =0;j < m;j++){
                    if(sumT - taro[i] + hanako[j] == sumH - hanako[j] + taro[i] && sumT - taro[i]  + hanako[j] < minSum){
                       minSum = sumT - taro[i] + hanako[j];
                       minSumI = i;
                       minSumJ = j;
                    }                  
               }               
           }
           
           if(minSumI >= 0 && minSumJ >= 0){
               System.out.println(taro[minSumI] + " " + hanako[minSumJ]);
           }else{
               System.out.println(-1);
           }           
           
       }
   }

}
        
        

Measured memory_bytes: 29428
S = input()
T = input()

flg_possible = False 

for i in range(len(S)) :
    s1 = S[0:i]
    s2 = S[i:len(S)]
    
    if s2 + s1 == T :
        flg_possible = True
        break
        
if flg_possible == True :
    print("Yes")
else :
    print("No")

Measured memory_bytes: 3060
# AtCoder Regular Contest 065
# D - 連結 / Connectivity
# https://atcoder.jp/contests/arc065/tasks/arc065_b
import sys
from collections import defaultdict

class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
    def find(self, x):
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        self.parent[x] = y

def main():
    N, *KL = map(int, input().split())
    uf = [UnionFind(N) for _ in range(2)]
    for i in range(2):
        for j in range(KL[i]):
            p, q = map(int, input().split())
            uf[i].union(p-1, q-1)

    d = defaultdict(int)
    for i in range(N):
        d[(uf[0].find(i), uf[1].find(i))] += 1

    for i in range(N):
        print(d[(uf[0].find(i), uf[1].find(i))], end = " ")
    print("")

if __name__ == "__main__":
    sys.setrecursionlimit(10**6)
    main()


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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int a, b;
  cin >> a >> b;

  int small = min({a,b});
  int large = max({a,b});

  REP(i, large) {
    cout << small;
  }
  cout << endl;

  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *a, int *b);

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b>c && a<c) swap(&b,&c);
		if(b>c && a>c){
			swap(&b,&c);
			swap(&a,&b);
		}
		if(a==c && b>=c) swap(&b,&c);
	}else{
		if(a>c && b>=c){
			swap(&a,&c);
		}else if(a>c && b<=c){
			swap(&a,&b);
			swap(&b,&c);
		}else if(a<c && b<c){
			swap(&a,&b);
		}
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

void swap(int *a, int *b){
	int c;
	c=*a;
	*a=*b;
	*b=c;
}

Measured memory_bytes: 596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int d; cin>>d;
    cout<<"Christmas ";
    rep(i,25-d) cout<<"Eve ";
    cout<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin >> n;

    vector<vector<vector<vector<int>>>> dp(n + 1, vector<vector<vector<int>>>(4,vector<vector<int>>(4,vector<int>(4,0))));
    dp[0][3][3][3] = 1;

    REP(i,n){
        REP(j,4){
            REP(k,4){
                REP(l,4){
                    if(dp[i][j][k][l]==0){
                        continue;
                    }

                    
                    REP(m,4){

                        if((k==0&&l==2&&m==1)||(k==2&&l==0&&m==1)||(k==0&&l==1&&m==2)||(j==0&&l==2&&m==1)||(j==0&&k==2&&m==1)){
                            continue;
                        }else{
                            dp[i + 1][k][l][m] += dp[i][j][k][l];
                            dp[i + 1][k][l][m] %= mod;
                        }

                    }
                }
            }
        }
    }

    long long int result = 0;

    REP(i,4){
        REP(j,4){
            REP(k,4){

                result += dp[n][i][j][k];
                result %= mod;
            }
        }
    }


    cout << result << endl;

    return 0;
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli n,m;

int main(){
  cin >> n >> m;
  if(n == 1 && m == 1){
    cout << 1 << endl;
    return 0;
  }
  if(n == 1 || m == 1){
    cout << n*m-2 << endl;
    return 0;
  }
  cout << n*m-n-n-m-m+4 << endl;
  return 0;
}


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

static const int MAX=100000;

vector<int>G[MAX];
list<int>out;
bool V[MAX];
int N,M;

void dfs(int u)
{
	V[u]=true;
	
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(!V[v])dfs(v);
	}
	out.push_front(u);
} 

int main()
{
	int s,t,w;
	
	cin>>N>>M;
	
	for(int i=0;i<N;i++)
	V[i]=false;
	
	for(int i=0;i<M;i++)
	{
	cin>>s>>t;
	G[s].push_back(t);
	}
	
	for(int i=0;i<N;i++)
	{
		if(!V[i])dfs(i);
	}
	
	for(list<int>::iterator it=out.begin();it!=out.end();it++)
	{
		cout << *it << endl;
	}
}


Measured memory_bytes: 6224
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;
    long long int min = 2e9;

    cin >> n;

    for (int i = 1; i < n; i++) {
        int sum = 0;
        string s = to_string(i);
        for (int j = 0; j < (int)s.size(); j++) {
            sum += s[j] - '0';
        }
        s = to_string(n-i);
        for (int j = 0; j < (int)s.size(); j++) {
            sum += s[j] - '0';
        }
        if (sum < min) {
            min = sum;
        }
    }

    cout << min << endl;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  val Array(n, k) = StdIn.readLine.split(" ").map(_.toInt)
  val seq = StdIn.readLine.split(" ").map(_.toInt).par
    .groupBy(m => m).map(_._2.size).toArray.sorted
  val g = math.max(seq.size - k, 0)
  val ans = seq.take(g).sum
  
  println(ans)
}

Measured memory_bytes: 171308
#include <cstdio>
     
    long long gcd(long long a, long long b) {
        if (b > a) {
            long long tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0)
            return a;
        else
            return gcd(b, a%b);
    }
     
    int main() {
        int n; 
        long long t[100] = {0};
        long long val;
        scanf("%d", &n);
        scanf(" %lld", &val);
        for (int i=1; i<n; i++) {
            long long tmp;
            scanf(" %lld", &tmp);
            long long r = gcd(val, tmp);
            val = val / r * tmp;
        }
        printf("%lld\n", val);
        return 0;
    }

Measured memory_bytes: 128
function Main(input) {
	input = input.split("\n");
	var s = input[1];
	var n = parseInt(input[0], 10);
    var toTest = [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']];
    for (var t = 0; t < 4; t++) {
        var arr = toTest[t];
        for (var i = 1; i < n-1; i++) {
            if (s[i] == 'o') {
                if (arr[i] == 'S') {
                    if (arr[i-1] == 'S') {
                        arr.push('S');
                    } else {
                        arr.push('W');
                    }
                } else {
                    if (arr[i-1] == 'S') {
                        arr.push('W');
                    } else {
                        arr.push('S');
                    }
                }
            } else {
                if (arr[i] == 'S') {
                    if (arr[i-1] == 'S') {
                        arr.push('W');
                    } else {
                        arr.push('S');
                    }
                } else {
                    if (arr[i-1] == 'S') {
                        arr.push('S')
                    } else {
                        arr.push('W');
                    }
                }
            }
        }
    }
    var failCount = 0;
    for (var t = 0; t < 4; t++) {
        var fail = false;
        var arr = toTest[t];
        for (var i = 0; i < n; i++) {
            var prev = i - 1;
            var next = i + 1;
            if (i == 0) {
                prev = n - 1;
            }
            if (i == n - 1) {
                next = 0;
            }
            if (arr[i] == 'S') {
                if (s[i] == 'o' && arr[prev] != arr[next]) {
                    fail = true;
                    break;
                } else if (s[i] == 'x' && arr[prev] == arr[next]) {
                    fail = true;
                    break;
                }
            } else {
                if (s[i] == 'o' && arr[prev] == arr[next]) {
                    fail = true;
                    break;
                } else if (s[i] == 'x' && arr[prev] != arr[next]) {
                    fail = true;
                    break;
                }
            }
        }
        if (!fail) {
            console.log(arr.join(""));
            break;
        }
        failCount++;
    }
    if (failCount >= 4) console.log(-1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 24396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Class34
    {
        static void Main()
        {
            long H = long.Parse(Console.ReadLine());
            long count = 1;
            while (H > 1)
            {
                H /= 2;
                count = count * 2 + 1;
            }
            Console.WriteLine(count);
        }
    }
}


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

int main(){
    int n;
    while(cin>>n,n){
        int S=500;
        vector<vector<int>> field(S,vector<int>(S,-1));
        field[250][250]=0;
        for(int k=0;k<n-1;k++){
            int v,d;
            cin>>v>>d;
            int dx[]={0,1,0,-1};
            int dy[]={-1,0,1,0};
            for(int i=0;i<S;i++){
                for(int j=0;j<S;j++){
                    if(field[i][j]==v){
                        field[i+dx[d]][j+dy[d]]=k+1;

                    }
                }
            
            }
        }
        int top=500;
        int bot=0;
        int lef=500;
        int rig=0;
        for(int i=0;i<S;i++){
            for(int j=0;j<S;j++){
                if(field[i][j]!=-1){
                    top=min(top,i);
                    bot=max(bot,i);
                    lef=min(lef,j);
                    rig=max(rig,j);
                }
            }
        }
        cout<<rig-lef+1<<" "<<bot-top+1<<endl;

    }   

    return 0;
}

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

const unsigned long int INFTY = 1000000001;
int C;

void Merge(int A[],int left,int mid,int right){
    int n1 = mid-left;
    int n2 = right-mid;
    int* L = new int[n1+1];
    int* R = new int[n2+1];

    for(int i=0;i<n1;i++){
        L[i] = A[left+i];
    }
    for(int i=0;i<n2;i++){
        R[i] = A[mid+i];
    }
    L[n1] = INFTY;
    R[n2] = INFTY;

    for(int i=0,j=0,k=left;k<right;k++){
        if(C++, L[i]<=R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
    delete[] L;
    delete[] R;
}

void mergeSort(int A[],int left,int right){
    if(left+1>=right){
        return;
    }
    int mid = (left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    Merge(A,left,mid,right);
}

int main(){
    unsigned n;
    cin>>n;
    int s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    mergeSort(s,0,n);
    for(int i=0;i<n;i++){
        cout<<s[i];
        if(i<n-1){cout<<' ';}
    }
    cout<<endl;
    cout<<C<<endl;
}


Measured memory_bytes: 6768
function main(input) {
    var args = input.trim().split("\n");
    var N = parseInt(args[0]);
    var S = args[1];

    var dp = [];

    for(var i = 0; S.length > i; i++) {
        for(var j = 0; S.length > j; j++) {
            if (typeof dp[i] === "undefined") dp[i] = [];
            if (S[i] === S[j]) {
                var value = i === 0 || j === 0 ? 0 : dp[i - 1][j - 1];
                dp[i].push(value + 1);
            } else {
                dp[i].push(0)
            }
        }
    }

    var result = 0;
    for (var k = 0; S.length > k; k++) {
        for(var l = k; S.length > l; l++) {
            if (k >= l) continue;
            var now = Math.min(dp[k][l], l - k);
            result = Math.max(result, now);
        }
    }

    console.log(result);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


int main(){
    ll N;
    cin >> N;
    for(ll h = 1; h <= 3500; ++h){
        for(ll n = 1; n <= 3500; ++n){
            const ll x = N * h * n;
            const ll y = 4 * h * n - N * (n + h);
            if(y <= 0){ continue; }
            if(x % y != 0){ continue; }
            const ll w = x / y;
            cout << h << ' ' << n << ' ' << w << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	while (N != 0) {
		vi A(N);
		REP(i, N) {
			cin >> A[i];
		}
		so(A);
		int ans = INF;
		REP(i, N - 1) {
			chmin(ans, A[i + 1] - A[i]);
		}
		cout << ans << endl;
		cin >> N;
	}
	return 0;
}



Measured memory_bytes: 3172
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int N;
int A[2][100];

int main() {
    cin >> N;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    vector<int> left(N,0), right(N,0);
    left[0] = A[0][0];
    right[N-1] = A[1][N-1];
    for (int i = 1; i < N; i++) {
        left[i] = left[i-1] + A[0][i];
        right[N-i-1] = right[N-i] + A[1][N-i-1];
    }
    int res = -1;
    for (int i = 0; i < N; i++) {
        chmax(res, left[i]+right[i]);
    }
    cout << res << endl;

}


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

using namespace std;

int main() {
    int x, h;
    while (scanf("%d%d", &x, &h), (x || h)) {
        double S = x * sqrt(x * x + 4 * h * h) + x * x;
        printf("%.10f\n", S);
    }

    return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll hb(ll x){
  if(x==0) return -1;
  int l=0,r=64,m;
  while(r-l>1){
    m=(l+r)/2;
    if(x<(1ll<<m)) r=m;
    else l=m;
  }
  return l;
}

int main(){
  ll n,k,a,s[1010]={},m=0,cnt=0,tmp,ans=0,q,r,t;
  vector<ll> v[50][50];
  cin>>n>>k;
  Fr(i,n){cin>>a;s[i]=s[i-1]+a;}
  Fr(i,n){
    fr(j,i){
      t=hb(s[i]-s[j]);
      if(t>=0) v[0][t].pb(s[i]-s[j]);
    }
  }
  ifr(i,50){
    q=v[cnt][i].size();tmp=cnt;r=1ll<<i;
    if(q>=k){
      ans+=r;
      cnt++;
    }
    fr(j,q){
      t=hb(v[tmp][i][j]-r);
      if(t>=0) v[cnt][t].pb(v[tmp][i][j]-r);
    }
  }
  cout<<ans<<endl;
}

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

int main(void) {
	int n,m;
	int a[51][3];
	int p[51] = {};
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i][1] >> a[i][2];
	}
	for (int i = 1; i <= m; i++) {
		for (int t = 1; t <= n; t++) {
			if ((a[i][1] == t)||(a[i][2] == t)) {
				p[t]++;
			}
		}
	}
	for (int t = 1; t <= n; t++) {
		cout << p[t] << endl;
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int maxCount = 200;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    int count = 0;
    while ( a % 2 == 0) {
      a = a / 2;
      count++;
    }
    if (maxCount > count) maxCount = count;
  }
  cout << maxCount << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
using namespace std;
typedef pair<int,int>P;
const int MAXN=100010;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
P p[MAXN];
double Dis(P &a, P &b){
	return sqrt((a.fi - b.fi) * (a.fi - b.fi) + (a.se - b.se) * (a.se - b.se));
}
struct node{
	int u,v;
	double w;
	node(int _u = 0, int _v = 0, double _w = 0) : u(_u), v(_v), w(_w){}
	bool operator < (node a) const{
		return w > a.w;
	}
}mp[MAXN];
int f[MAXN];
int getf(int k){
	return k == f[k] ? k : f[k] = getf(f[k]);
}
double kruskal(int n, int m){
	int i = 0, cnt = 1;
	double sum = 0;
	while(i < m && cnt < n){
		int u = getf(mp[i].u);
		int v = getf(mp[i].v);
		if(u != v){
			f[u] = v;
			cnt++;
			sum += mp[i].w;
		}
		i++;
	}
	return sum;
}
int main(){
	int n, m, u, v;
	cin >> n >> m;
	for(int i = 1; i <= n; ++i){
		scanf("%d %d", &p[i].fi, &p[i].se);
		f[i] = i;
	}
	double sum = 0;
	for(int i = 0; i < m; i++){
		scanf("%d %d", &u, &v);
		mp[i] = node(u, v, Dis(p[u], p[v]));
		sum += Dis(p[u], p[v]);
	}
	sort(mp, mp + m);
	cout << fixed << setprecision(3) << sum - kruskal(n, m) << endl;
 	return 0;
}


Measured memory_bytes: 5712
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    vector<int> L(n);
    rep(i,n) cin >> L[i];
    sort(L.begin(),L.end());
    int ans = 0;
    for(int i = 0;i<n;i++) {
        for(int j = i+1;j<n;j++) {
            int sum = L[i]+L[j];
            int left = j+1;
            int right = lower_bound(L.begin(),L.end(),sum)-L.begin();
            ans += right-left;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int H,W;
char S[2010][2010];
int x[2010];
int ans;

int main(){
	scanf("%d%d" , &H , &W);
	repp(i,0,H){
		scanf(" %s" , S[i]);
	}
	ans = max(W,H);
	repp(i,1,H){
		stack<P2> v;
		v.push(MP(0,0));
		repp(j,1,W){
			if(1 ^ (S[i-1][j] == S[i][j]) ^ (S[i-1][j-1] == S[i][j-1])){
				++x[j];
			} else {
				x[j] = 0;
			}
			int p = v.top().first;
			int q = v.top().second;
			int r = 0;
			while(p > x[j]){
				r += q;
				ans = max(ans , (p+1) * (r+1));
				v.pop();
				p = v.top().first;
				q = v.top().second;
			}
			if(p < x[j]){
				v.push(MP(x[j],1+r));
			} else {
				v.top().second += 1+r;
			}
		}
		int r = 0;
		while(!v.empty()){
			int p = v.top().first;
			int q = v.top().second;
			r += q;
			ans = max(ans , (p+1) * (r+1));
			v.pop();
		}
	}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 4224
import sys
from operator import itemgetter, attrgetter
from itertools import starmap
import cmath
from math import isinf, sqrt, acos, atan2
readline = sys.stdin.readline
EPS = 1e-9
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2
class Circle(object):
    __slots__ = ('c', 'r')
    def __init__(self, c, r):
        self.c = c
        self.r = r
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
Line = Segment
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
def getCrossPoint(s1, s2):
	base = s2.se - s2.fi
	d1 = abs(cross(base, s1.fi - s2.fi))
	d2 = abs(cross(base, s1.se - s2.fi))
	t = d1 / (d1 + d2)
	return s1.fi + (s1.se - s1.fi) * t
def getCrossPointsCL(c, l):
    pr = project(l, c.c)
    e = (l.se - l.fi) / abs(l.se - l.fi)
    base = sqrt(c.r * c.r - norm(pr - c.c))
    return Segment(*sorted((pr + e * base, pr - e * base)), key=attrgetter('real', 'imag'))
def getCrossPointsCC(c1, c2):
    d = abs(c1.c - c2.c)
    a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2.0 * c1.r * d))
    t = cmath.phase(c2.c - c1.c)
    return Segment(*sorted((c1.c + cmath.rect(c1.r, t + a), c1.c + cmath.rect(c1.r, t - a)), key=attrgetter('real', 'imag')))
def contains(g, p):
    n = len(g)
    x = False
    for i in range(n):
        a = g[i] - p
        b = g[(i + 1) % n] - p
        if abs(cross(a, b)) < EPS and dot(a, b) < EPS: return 1
        if a.imag > b.imag: a, b = b, a
        if a.imag < EPS and EPS < b.imag and cross(a, b) > EPS: x = not x
    return 2 if x else 0
n = int(readline())
pg = tuple(complex(*map(int, readline().split())) for _ in [0] * n)
q = int(readline())
for _ in [0] * q:
    print(contains(pg, complex(*map(float, readline().split()))))

Measured memory_bytes: 8256
using System;
using System.Linq;

namespace B___Two_Colors_Card_Game
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Si = Enumerable.Range(1, N).Select(_ => Console.ReadLine()).ToArray();
            var M = int.Parse(Console.ReadLine());
            var Ti = Enumerable.Range(1, M).Select(_ => Console.ReadLine()).ToArray();

            var array = Si.Union(Ti).Distinct().ToArray();
            var SiGroup = Si.GroupBy(x => x).ToArray();
            var TiGroup = Ti.GroupBy(x => x).ToArray();
            int res = 0;

            foreach (var e in array)
            {
                var plus = SiGroup.Any(g => g.Key == e) ? SiGroup.Single(g => g.Key == e).Count() : 0;
                var minus = TiGroup.Any(g => g.Key == e) ? TiGroup.Single(g => g.Key == e).Count() : 0;
                res = Math.Max(res, plus - minus);
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 11616
from collections import defaultdict
n,k = map(int,input().split())
a = list(map(int,input().split()))
ruisekiwa = [0 for _ in range(n+1)]
for i in range(n):
	ruisekiwa[i+1] = (ruisekiwa[i] + a[i] - 1) % k
dp = defaultdict(lambda: 0)
ans = 0
tmp = 0
for i in range(n+1):
	tmp += 1
	if tmp > k:
		dp[ruisekiwa[i-k]] -= 1
	ans += dp[ruisekiwa[i]]
	dp[ruisekiwa[i]] += 1
print(ans)

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

const unsigned int B = 9973;

typedef struct node {
  struct node *next;
  char key[21]; //  char *key;
  int value;
} Node;

unsigned int compute_hash(char *a)
{
  unsigned int hash = 0;
  int len = strlen(a);
  for (int i=0; i<len; i++) hash = hash * B + a[i];
  return hash;
}

int main(){
  int n, i, x, q, hash;
  char buf[256];
  char key[21];
  char *p1, *p2;
  fgets(buf, 256, stdin);
  n = atoi(buf);
  Node **a = (Node**)malloc(sizeof(Node*)*n/2);
  for (i = 0; i < n/2; i++)  a[i] = NULL;
  for (i = 0; i < n; i++) {
    fgets(buf, 256, stdin);
    q = atoi(buf);
    p1 = index(buf, ' ') + 1;
    if (q==0) { // insert
      p2 = index(p1, ' ');
      strncpy(key, p1, p2-p1);
      key[p2-p1] = '\0';
      hash = compute_hash(key)%(n/2);
      x = atoi(p2);
      if (a[hash]==NULL) {
	a[hash] = (Node*)malloc(sizeof(Node));
	a[hash]->next = NULL;
	//	a[hash]->key = (char*)malloc(strlen(buf)+1);
	strcpy(a[hash]->key, key);
	a[hash]->value = x;
	continue;
      }
      
      Node *ptr = a[hash];
      Node *prev = ptr;
      while (ptr) {
	if (strcmp(ptr->key, key)==0) {
	  ptr->value = x;
	  break;
	}
	prev = ptr;
	ptr = ptr->next;
      }
      if (ptr==NULL) {
	ptr = (Node*)malloc(sizeof(Node));
	ptr->next = NULL;
	//	ptr->key = (char*)malloc(strlen(buf)+1);
	strcpy(ptr->key, key);
	ptr->value = x;
	prev->next = ptr;
      }
      
    } else if (q==1) { // find
      p2 = index(p1, '\n');
      strncpy(key, p1, p2-p1+1);
      key[p2-p1] = '\0';
      hash = compute_hash(key)%(n/2);
      Node *ptr = a[hash];
      while (ptr) {
	if (strcmp(ptr->key,key)==0) {
	  int b = ptr->value;
	  int j;
	  for (j=1; j*10<=b; j*=10);
	  for (; j>0; j/=10) {
	    putc_unlocked('0'+b/j, stdout);
	    b %= j;
	  }
	  putc_unlocked('\n', stdout);
	  break;
	}
	ptr = ptr->next;
      }
      if (ptr==NULL) {
	putc_unlocked('0', stdout);
	putc_unlocked('\n', stdout);
      }
    } else { // delete
      p2 = index(p1, '\n');
      strncpy(key, p1, p2-p1);
      key[p2-p1] = '\0';
      hash = compute_hash(key)%(n/2);
      if (a[hash]==NULL) continue;
      if (strcmp(a[hash]->key, key)==0) {
	a[hash] = a[hash]->next;
	continue;
      }
      Node *ptr = a[hash];
      Node *prev = ptr;
      while (ptr) {
	if (strcmp(ptr->key, key)==0) {
	  prev->next = ptr->next;
	  break;
	}
	prev = ptr;
	ptr = ptr->next;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 11780
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
count = Counter(A)
S = sum(A)

for _ in range(int(input())):
    b, c = map(int, input().split())
    k = count[b]
    count[b] = 0
    count[c] += k
    S += (c - b) * k
    print(S)

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


int main()
{
    int a,b;
    cin>>a>>b;

    string s ="";
    string str = "";

    for(int i=0;i<b;i++)
    {
        s = s + to_string(a);
    }

     for(int i=0;i<a;i++)
    {
        str = str + to_string(b);
    }
   
    if(s<=str)
    cout<<s<<endl;

    else 
    cout<<str<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main(){
    priority_queue<int> edge;
    int n,a,b,c;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a>>b>>c;
        edge.push(a);
        edge.push(b);
        edge.push(c);
        a=edge.top();
        edge.pop();
        b=edge.top();
        edge.pop();
        c=edge.top();
        edge.pop();
        if(a*a==(b*b+c*c)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
#include<string.h>
#define MAXN 105

int main(){
//	freopen("in.txt", "r", stdin);
	char str1[MAXN], str2[MAXN];
	int len1, len2;
	scanf("%s%s",str1, str2);
	
	len1 = strlen(str1);
	len2 = strlen(str2);
//	printf("%d", strlen(str1));
//	printf("%d", strlen(str2));
	if(len1 != len2){
		printf("No\n");
		return 0;
	}else{
		for(int i=0; i<len1; i++){
			int k;
			for(int j=0, index = 0; j<len1; j++, index++){
				k = j+i;
				k>=len1?k=k-len1:k=k;
				if(str1[index] != str2[k]){
					break;
				}else if(str1[index] == str2[k] && index == len1-1){
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String m = sc.next();
		String l = sc.next();
		System.out.println("" + s.charAt(0) + m.charAt(1) + l.charAt(2));
	}
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
vl dp(2e5+1,1);
vl rf(2e5+1,-1);
ll MOD = 1e9+7;
int main() {
  ll n;
  cin >> n;
  REP(i,n){
    ll c;
    cin >> c;
    if(i!=0) dp[i] = dp[i-1];
    if(rf[c]>=0 && rf[c]<i-1){
      dp[i] += dp[rf[c]];
    }
    dp[i] %= MOD;
    rf[c] = i;
  }

  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
int main(){
    int n,k;
    double sum=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        double p=1;
        int tmp=i;
        while(tmp<k){
            p/=2;
            tmp*=2;
        }
        sum+=p;
    }
    printf("%.12lf\n",sum/n);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}

int main()
{
	int n;
	scanf("%d/n",&n);
	int a[n],i;
	long long int ans=0,median;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i] += -i;
	}
	qsort(a,n,sizeof(int),compare_int);
	median = a[n/2];
	for(i=0;i<n;i++){
		ans += abs(a[i]-median);
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    ll A,B,K;
    cin >> A >> B >> K;
    if (A>=K) {
        cout << A-K << " " << B << endl;
        return 0;
    }
    K = K-A;
    cout << 0 << " " << max(ll(0),B-K) << endl;



    return 0;
}


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

using namespace std;

int main (){
  int N;
  int tmp;
  vector<int> arr;
  int A=0;
  int B=0;

  cin >> N;
  for(int i;i<N;i++){
    cin >> tmp;
    arr.push_back(tmp);
  }
  sort(arr.begin(),arr.end(),greater<int>());

  for(int i; i<N;i++){
    if(i%2 == 0){
      A += arr[i];
    }
    if(i%2 == 1){
      B += arr[i];
    }
  }
  cout << A - B << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    int N,x;
    cin>>N>>x;
    long long a[N];
    for(int i=0;i<N;i++) cin>>a[i];
    
    long long count=0;
    
    if(a[0]>x){
        count+=a[0]-x;
        a[0]=x;
    }
    
    for(int i=1;i<N;i++){
        long long tmp=(a[i]+a[i-1])-x;
        if(tmp>0){
            a[i]-=tmp;
            count+=tmp;
        }
    }
    
    cout<<count<<endl;
}

Measured memory_bytes: 1152
while True:
    n = int(input())
    if n == 0:
        break
    
    data = [0 for i in range(10)]
    for i in range(n):
        data[int(input())] += 1
        
    for i in range(10):
        if data[i] == 0:
            print("-")
        else:
            print("*" * data[i])


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ull> vull;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;


#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORDOWN(i, a, b) for(int i = a; i >= b; --i)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
//mt19937 rnd(150);



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

    //  freopen("goat5.in", "r", stdin);
    //  freopen("goat5.out","w", stdout);

    string s;
    cin >> s;

    int sum = 0;

    for (int i = 0; i < s.size(); ++i) {
        sum += s[i] - '0';
    }

    if (sum % 9 == 0)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 3732
#include <stdio.h>
int main()
{
    long long int a,b,x;
    scanf("%lld %lld %lld",&x,&a,&b);
    {
        if( b <= a )
        {
            printf("delicious");
        }
        else if ( b > a + x )
        {
            printf("dangerous");
        }
        else
        {
            printf("safe");
        }
    }
return 0;
}

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

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> x(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> x[i];
    x[i] = fabs(x[i] - s);
  }
  sort(x.begin(), x.end());
  int result = x[x.size() - 1];
  for (i = 0; i < n; i++) {
    while (x[i] != 0) {
      if (result < x[i]) {
        swap(x[i], result);
      }
      result %= x[i];
      swap(result, x[i]);
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 640