akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <climits>


typedef long long ll;
const int MOD = pow(10,9)+7;
const int MAX = 100001;

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}


int main() {

    int n = in();
    
    deque<int> dq;
    
    for(auto i = 0; i< n; i++){
        
        if (i%2 ==0){
            dq.push_back(in());
        }else{
            dq.push_front(in());
        }
    }
    
    if(dq.size() == 1){
        cout << dq.front() << endl;
        return 0;
    }
    
    if (n%2 == 0){
        
        for(auto a = dq.begin(); a != --dq.end(); a++){
            cout << *a << " ";
        }
        cout<< *(--dq.end()) << endl;
    }else{
        
        for(auto a = --dq.end(); a != dq.begin(); a--){
            cout << *a << " ";
        }
        cout<< *(dq.begin()) << endl;
        
    }
    
    return 0;
    
    
}








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

const int c[] = {500, 100, 50, 10, 5, 1};

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    n = 1000 - n;
    int ans = 0;
    for (int i = 0; i < 6; ++i) {
      ans += n / c[i];
      n %= c[i];
    }

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

Measured memory_bytes: 0
#include <cstdio>
#include <set>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include<numeric>
#include <list>
#define fo(a, b, c) for (register int a = b; a <= c; ++a)
 
namespace IO
{
    inline char gc()
    {
        static char s[1<<20|1]={0},*p1=s,*p2=s;
        return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
    }
//	inline char gc() { return getchar(); }
	inline long long read()
	{
		long long ret=0;bool flag=0;char c=gc();
		while ((c<'0')|(c>'9')) flag ^= !(c^'-'),c=gc();
		while ((c>='0')&(c<='9')) ret=(ret<<1)+(ret<<3)+(c^'0'),c=gc();
		return flag?-ret:ret;
 	}
 	char OutputAns[1<<20|1],*OutputCur = OutputAns;
 	inline void output()
 	{
 		OutputCur -= fwrite(OutputAns,1,OutputCur - OutputAns,stdout);
	}
	inline void print(long long ans)
	{
		char s[20]={0};
		if (OutputCur - OutputAns + sprintf(s,"I64d",ans) >> 20) output();
		OutputCur += sprintf(OutputCur,"%I64d",ans);
	}
	inline void printc(char c)
	{
		if (OutputCur - OutputAns + 1 >> 20) output();
		*(OutputCur++) = c;
	}
}
 
using IO::read;
using IO::print;
using IO::printc;
using IO::output;
 
using namespace std;
 
typedef long long int64;
 
const int M = 2e3 + 11;
 
int lim, n, q, ans = 2e9;

int A[M], R[M], Ok[M], C[M];

inline void Input()
{
	n = read(), lim = read(), q = read();
	for (int i = 1;i <= n; ++i)
		A[i] = R[i] = read();
	std::sort(R + 1, R + 1 + n);
}

inline void Solve(int Min)
{
	Ok[0] = 0;
	int l = 1, r = 1;
	while (l <= n)
	{
		C[0] = 0;
		while (A[l] < Min && l <= n) ++l;
		r = l;
		while (A[r] >= Min && r <= n) ++r;
		if (r - l < lim) goto end;
		for (int i = l;i < r; ++i)
			C[++C[0]] = A[i];
		std::sort(C + 1, C + 1 + C[0]);
		for (int i = 1;i <= C[0] - lim + 1; ++i)
			Ok[++Ok[0]] = C[i];
		end:; l = r;
	}
	if (Ok[0] < q) return ;
	std::sort(Ok + 1, Ok + 1 + Ok[0]);
	ans = std::min(ans, Ok[q] - Ok[1]);
}

int main(void)
{
	Input();
	for (int i = 1;i <= n - lim + 1; ++i)
		Solve(R[i]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int n, m; cin >> n >> m;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	vector<pair<int, int>> ab(m);
	rep(i, m) cin >> ab[i].first >> ab[i].second;

	int ans = 0;
	map<int, int> mp;
	rep(i, n) mp[i + 1] = 0;

	rep(i, m) {
		if (h[ab[i].first - 1] < h[ab[i].second - 1]) mp[ab[i].first]--;
		else if (h[ab[i].first - 1] > h[ab[i].second - 1]) mp[ab[i].second]--;
		else {
			mp[ab[i].first]--;
			mp[ab[i].second]--;
		}
	}

	bool c = true;
	rep(i, n) {
		if (mp[i + 1] == 0) ans++;
		else c = false;
	}
	if (c) ans = 0;

	dunk(ans);
	return 0;
}


Measured memory_bytes: 9064
"use strict"

function main(input) {
  input = input.split(/\n/).map(v => ~~v)
  //
  const ans = input[0] + (input[1] - input[0]) * 2
  // avg * 2 = ( a +b )
  //2017  = 2002 + 2032  / 2
  // 4034 -x  = 2002

  console.log(ans)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 20808
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, M;
	cin >> N;
	vector<string> s(N);
	for (int i = 0; i < N; i++)
		cin >> s.at(i);
	cin >> M;
	vector<string> t(M);
	for (int i = 0; i < M; i++)
		cin >> t.at(i);

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int sum = 1;
		for (int j = i + 1; j < N; j++)
			if (s.at(i) == s.at(j))
				sum++;
		for (int j = 0; j < M; j++)
			if (s.at(i) == t.at(j))
				sum--;
		if (ans < sum)
			ans = sum;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long findlcm(long long c,long long d)
{
  long long lcm=c*d;
  if(c<d)
  {
    c=c+d;
    d=c-d;
    c=c-d;
  }
  long long temp;
  while(c%d!=0)
  {
    temp=d;
    d=c%d;
    c=temp;
  }
  return(lcm/d);
}

long long multiples(long long a,long long b, long long c)
{
  long long answer = b/c-a/c;
  if(a%c==0)
    answer++;
  return answer;
}

int main()
{
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long answer =b-a+1;
  long long lcm;
  lcm = findlcm(c,d);
  long long cmul=multiples(a,b,c);
  long long dmul=multiples(a,b,d);
  long long lcmmul=multiples(a,b,lcm);
  answer=answer-cmul-dmul+lcmmul;
  cout<<answer;
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>

typedef int type;
using namespace std;
const bool isDebug = true;

typedef pair<string, int> p;
queue<p> pque;

int n, q;

void input(){
    cin >> n >> q;
    for(int i=0; i<n; i++){
        string tmpName;
        int tmpTime;
        cin >> tmpName;
        cin >> tmpTime;
        
        pque.push(p(tmpName, tmpTime));     
    }
}

void solve(){
    int elapsedTime = 0;
    while(!pque.empty()){
        p currentP = pque.front();
        pque.pop();

        int deltaTime = min(currentP.second, q);
        currentP.second -= deltaTime;
        elapsedTime += deltaTime;

        if(isDebug){
            
            //printf("%s %d\n", currentP.first.c_str(), elapsedTime);
        }

        if(currentP.second  == 0){
            printf("%s %d\n", currentP.first.c_str(), elapsedTime);
        }else{
            pque.push(currentP);
        }
    }
}

int main(){
    input();
    solve();
    return 0;
}

Measured memory_bytes: 6256
def main():
  S = map(int,list(input()))
  K = int(input())
  for i,n in enumerate(S):
    if n == 1:
      K -= n
      continue
    if K>0:
      return n
    else:
      return 1
  return 1

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


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

int main() {
	int N, K, C;
	cin >> N >> K >> C;
	string S;
	cin >> S;
	vector<int> Left, Right;
	int i = 0;
	int num = 0;
	while (i<N) {
		if (S[i] == 'o') {
			Left.push_back(i);
			i += C + 1;
			num++;
		}
		else i++;
		if (num == K) break;
	}
	i = N - 1;
	num = 0;
	while (i >= 0) {
		if (S[i] == 'o') {
			Right.push_back(i);
			i -= (C + 1);
			num++;
		}
		else i--;
		if (num == K) break;
	}
	for (int i = 0; i < K; i++) {
		if (Left[i] == Right[K-i-1] ) cout << Left[i] + 1 << endl;
	}
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li a,b;
    cin>>a>>b;
    if(a<6){
        puts("0");
    }else if(a<13){
        cout<<b/2<<endl;
    }else{
        cout<<b<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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 pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
bool dfs(ll k, ll type, VV &vec, V &reg)
{
    reg[k] = type;
    rep(i, vec[k].size())
    {
        if (reg[vec[k][i]] == -1)
        {
            if (!dfs(vec[k][i], 1 - type, vec, reg))
            {
                return false;
            }
        }
        else
        {
            if (reg[vec[k][i]] == type)
            {
                return false;
            }
        }
    }
    return true;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    VV vec(n, V(n));
    rep(i, n)
    {
        string s;
        cin >> s;
        rep(j, n)
        {
            vec[i][j] = s[j] - '0';
        }
    }
    VV vec2(n);
    rep(i, n)
    {
        rep(j, n)
        {
            if (vec[i][j])
            {
                vec2[i].push_back(j);
            }
            else
            {
                if (i != j)
                {
                    vec[i][j] = 1e18;
                }
            }
        }
    }
    //  cout<<vec2[1].size()<<endl;
    V reg(n, -1);
    if (!dfs(0, 0, vec2, reg))
    {
        cout << -1 << endl;
        return 0;
    }
    rep(k, n)
    {
        rep(i, n)
        {
            rep(j, n)
            {
                chmin(vec[i][j], vec[i][k] + vec[k][j]);
            }
        }
    }
    ll res = 0;
    rep(i, n)
    {
        rep(j, n)
        {
            chmax(res, vec[i][j]);
        }
    }
    cout << res+1 << endl;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    --k;
    lint dp[105][10] = {0};
    dp[0][0] = 1;
    rep(y, h){
        rep(i, 1 << (w - 1)){
            bool flag = false;
            rep(j, w - 1){
                if((i >> j) % 4 == 3){
                    flag = true;
                    break;
                }
            }
            if(flag){
                continue;
            }
            vector<int> pos(w);
            rep(j, w){
                pos[j] = j;
            }
            rep(j, w - 1){
                if(i >> j & 1){
                    swap(pos[j], pos[j + 1]);
                }
            }
            rep(j, w){
                dp[y + 1][pos[j]] += dp[y][j];
                dp[y + 1][pos[j]] %= MOD;
            }
        }
    }
    cout << dp[h][k] << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))

ma = []
for i in a:
    ma.append(-i)

heapq.heapify(ma)
for i in range(m):
    b = (-heapq.heappop(ma) // 2)
    heapq.heappush(ma, -b)

ans = 0
for i in ma:
    ans -= i

print(ans)

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

using namespace std;
using ll = long long;

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

    string s;
    cin >> s;

    vector<int> down;
    vector<pair<int, int>> area_left;
    int x = 0, area;
    for(char c: s) {
        if(c == '\\') {
            down.emplace_back(x);
        } else if(c == '/' && !down.empty()) {
            area = x - down.back();
            while(!area_left.empty() && down.back() < area_left.back().second) {
                area += area_left.back().first;
                area_left.pop_back();
            }
            area_left.emplace_back(make_pair(area, down.back()));
            down.pop_back();
        }
        x++;
    }

    int sum = 0;
    for(pair<int, int> p: area_left) sum += p.first;
    printf("%d\n", sum);
    printf("%d", area_left.size());
    for(pair<int, int> p: area_left) printf(" %d", p.first);
    printf("\n");

    return 0;
}


Measured memory_bytes: 3380
import math
N,D = map(int,input().split())
x =[]
y=[]
for i in range(N):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)
  
count = 0
for i in range(N):
  if math.sqrt(x[i]**2+y[i]**2)<=D:
    count+=1
print(count)

Measured memory_bytes: 96820
#include <iostream>
#include <set>
using namespace std;
int main() {
    int n, x;
    cin >> n;
    set<int> a;
    for (int i = 0; i < n; i++) {
        cin >> x;
        a.insert(x);
    }
    cout << (a.size() == n ? "YES" : "NO") << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define pb push_back
using namespace std;
int main(){
  ll n;
  cin>>n;
  vector<pair<int,int> > v;
  ll maxff=INT_MIN,maxsf=INT_MIN,minfs=INT_MAX,minss=INT_MAX;
  for(ll i=0;i<n;i++){
  	ll x,y;cin>>x>>y;
    maxff=max(maxff,x+y);
    minfs=min(minfs,x+y);
    maxsf=max(maxsf,x-y);
    minss=min(minss,x-y);
  }
  ll ans=max(abs(maxff-minfs),abs(maxsf-minss));
  cout<<ans;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<pll,ll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define piii pair<pii, int>
#define sort(p) sort(p.begin(),p.end())
#define rsort(p) sort(p.rbegin(),p.rend())
#define pb push_back
const ll llinf = 2e18 + 7;
const int inf = 2e9 + 7;
const ll mod = 998244353;
const ll N = 1e5 + 7;
const ld pi = 3.14159265358979; 

void solve() {
    int n,k;
    cin>>n>>k;
    vector<int> arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr);
    int sum = 0;
    for(int i=0;i<k;i++ ) sum+=arr[i];
    cout<<sum;}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        // cout<<"\n";
    }
    return 0; 

}


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

typedef long long LL;

const int N = 100005;
const LL inf = (LL)1e18;;

int n;
LL a[N], ans;

LL dfs(int d, LL v)
{
	v = min(v, inf);
	if (v < a[d]) return -1;
	if (d == n) return ans += a[d], a[d];
	LL w = dfs(d + 1, (v - a[d]) * 2);
	if (w == -1) return -1;
	ans += min(w, v - a[d]) + a[d];
	return a[d] + min(w, v - a[d]);
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i <= n; i++) scanf("%lld", &a[i]);
	if (dfs(0, 1) == -1) puts("-1");
	else printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  cout << arr[arr.size() - 1] - arr[0] << endl;
}


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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  long long ans = 0;
  for ( int i = 0; i < s.size(); i++ ) {
    if ( s[i] != t[i] ) { ans++; }
  }  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3912
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int main(){
	int w, h, n;
	cin >> w >> h >> n;
	int x;
	int y;
	int a;

	int min_x = 0;
	int max_x = w;
	int min_y = 0;
	int max_y = h;


	for(int i = 0; i < n; ++i){
		cin >> x >> y >> a;
		switch(a){
		case 1:
			if (min_x < x){
				min_x = x;
			}
			break;
		case 2:
			if (max_x > x){
				max_x = x;
			}
			break;
		case 3:
			if (min_y < y){
				min_y = y;
			}
			break;
		default:
			if (max_y > y){
				max_y = y;
			}
			break;
		}
	}
	x = (max_x - min_x);
	y = (max_y - min_y);
	if ((x > 0) && (y > 0)){
		cout << x*y << endl;
	}
	else{
		cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include  <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
#define endl '\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> index_set;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ii = pair<int,int>;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define mod 1000000007

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

 int n;
 cin >> n;int a[n];
 sort(a, a+n);
 int ans = 0;
 for(int i = 0; i<n; i++)cin >> a[i];
 for(int i = 0; i<n; i++)
   for(int j = i+1; j<n; j++)
     for(int k = j+1; k<n; k++){
     	if(a[i] == a[j] || a[j] == a[k] || a[i] == a[k])
				continue;
     	if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[k] + a[j] > a[i])
          ans+=1;
     }
  cout << ans <<endl;
		
 return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////
 
int main(){fastio
    
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=1;
    ll c[3];memset(c,0,sizeof(c));
    rep(i,0,n-1){
        ll k=0;
        rep(j,0,2){
            if(a[i]==c[j])k++;
        }
        if(k==0){
            cout<<0;return 0;
        }
        ans=mod(ans*k);
        rep(j,0,2){
            if(a[i]==c[j]){
                c[j]++;break;
            }
        }
        
    }
    
    cout<<mod(ans)<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 100000000
using namespace std;

int N;
string S[14];
int d[14][14], b[14], dp[1 << 14][14];

int overlap(int a, int b) {
  int ret = 0, na = S[a].length(), nb = S[b].length();
  REP(i, 1, na + 1) {
    if(S[a].substr(na - i, na) == S[b].substr(0, i)) ret = i;
  }
  return ret;
}

bool include(int a, int b) {
  int na = S[a].length(), nb = S[b].length();
  if(na < nb) return false;
  REP(i, 0, na) if(S[a].substr(i, nb) == S[b]) return true;
  return false;
}

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) cin >> S[i];
    REP(i, 0, N) REP(j, 0, N) d[i][j] = overlap(i, j);
    REP(i, 0, N) b[i] = 0;
    REP(i, 0, N) REP(j, 0, N) b[i] |= include(j, i) << j;

    REP(i, 0, 1 << N) REP(j, 0, N) dp[i][j] = INF;
    REP(i, 0, N) dp[1 << i][i] = S[i].length();

    REP(i, 0, 1 << N) REP(j, 0, N) if(dp[i][j] != -1) {
      REP(k, 0, N) if((i & (1 << k)) == 0) {
        if((i & b[k]) == 0) {
          int len = S[k].length();
          dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + len - d[j][k]);
        } else {
          dp[i | (1 << k)][j] = min(dp[i | (1 << k)][j], dp[i][j]);
        }
      }
    }

    int ans = INF;
    REP(i, 0, N) ans = min(ans, dp[(1 << N) - 1][i]);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3884
// ACM-ICPCアジア地区予選2014 H. Cornering at Poles

#include <iostream>
#include <map>

using namespace std;

const long long INF = 1LL<<50;

int N;
map<long long, int> mem[2][150];
int r[150];
int s[150];
int lest[151];

int solve(int turn, int idx, long long diff);

int search(int turn, int idx, long long diff){
	if(idx == N) return 0;
	if(mem[turn][idx].empty()){
		int cur = solve(turn, idx, -INF/2);
		mem[turn][idx][-INF] = cur;
		long long key = -INF;
		while(true){
			long long L = key, R = INF/2;
			while(R-L>1){
				long long mid = (L+R)/2;
				if(solve(turn, idx, mid) == cur){
					L = mid;
				} else {
					R = mid;
				}
			}
			int next = solve(turn, idx, R);
			if(cur == next) break;
			mem[turn][idx][R] = next;
			cur = next;
			key = R;
		}
	}
	return (--mem[turn][idx].upper_bound(diff))->second;
}

int solve(int turn, int idx, long long diff){
	if(idx == N) return 0;
	int res = s[idx] + lest[idx+1] - search(!turn, idx+1, -(diff+r[idx]));
	if(diff > 0){
		res = max(res, search(turn, idx+1, diff-r[idx]-1));
	}
	return res;
}

int main(){
	int A, B;
	while(cin >> N >> A >> B){
		for(int i=0;i<N;i++) cin >> r[i] >> s[i];
		lest[N] = 0;
		for(int i=N-1;i>=0;i--) lest[i] = lest[i+1]+s[i];
		for(int i=0;i<N;i++){
			mem[0][i].clear();
			mem[1][i].clear();
		}
		int res = search(0, 0, A-B);
		cout << res << " " << lest[0]-res << endl;
	}
}

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

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

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

const int mod = 1e9 + 7;


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

	double a, b, x;
	cin >> a >> b >> x;

	double ans = b - x/(a*a);
	if(x/(a*a) >= b/2.0){
		a /= 2.0;
		ans = atan(ans/a);
	}else{
		x = x/a * 2.0;
		x /= b;
		ans = atan(b/x);
	}

	cout << fixed << setprecision(8) << ans * 180.0 / M_PI << endl;
    return 0;
}



Measured memory_bytes: 256
/**
 * C - Build Stairs
 * https://atcoder.jp/contests/abc136/tasks/abc136_c
 **/
#include<iostream>

using namespace std;

const int MAX_N = 100000;
const int MAX_H = 1000000000;

int N;
int H[MAX_N+1]; 

bool hoge(int i, int j) {
    if(i < 0) {
        return true;
    }
    bool res;
    if(H[i] - j <= 0) {
        res = hoge(i-1, H[i]);
    } else if (H[i] - j == 1) {
        res = hoge(i-1, H[i] - 1);
    } else {
        res = false;
    }
    return res;
}

void solve() {
    if(hoge(N-1, MAX_H+1)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    solve();
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    cin >> N;
    V<pii> vl, vr;

    rep(i, N) {
        string s;
        cin >> s;
        int h = 0;
        int mi = 0;
        for (auto c : s) {
            if (c == '(') {
                ++h;
            } else {
                --h;
            }
            chmin(mi, h);
        }
        if (h >= 0) {
            vl.eb(mi, h);
        } else {
            vr.eb(mi - h, -h);
        }
    }
    debug(vl, vr);
    sort(ALL(vl));
    sort(ALL(vr));
    reverse(ALL(vl));
    reverse(ALL(vr));
    int lh = 0;
    for (auto p : vl) {
        if (lh + p.fi < 0) {
            puts("No");
            return 0;
        }
        lh += p.se;
    }
    int rh = 0;
    for (auto p : vr) {
        if (rh + p.fi < 0) {
            puts("No");
            return 0;
        }
        rh += p.se;
    }
    puts(lh == rh ? "Yes" : "No");
    return 0;
}

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

int with_tax(int value, int tax) {
  return value * (100 + tax) / 100;
}

int without_tax(int value, int tax) {
  for (int i = 1; i <= value; i++) {
    if (with_tax(i, tax) == value) {
      return i;
    }
  }
  return -1e5;
}

int solve(int x, int y, int s) {
  int ans = 0;
  for (int pencil = 1; pencil < s; pencil++) {
    int eraser = s - pencil;
    int pencil_without_tax = without_tax(pencil, x),
        eraser_without_tax = without_tax(eraser, x);
    ans = max(ans, 
        with_tax(pencil_without_tax, y) 
        + with_tax(eraser_without_tax, y));
  }
  return ans;
}

int main() {
  int x, y, s;
  while (cin >> x >> y >> s and x) {
    cout << solve(x, y, s) << endl;
  }
}

Measured memory_bytes: 1160
a2z = "abcdefghijklmnopqrstuvwxyz"
s_org = input()
ret = len(s_org)
for c in a2z:
    if(s_org.count(c) == 0):
        continue
    s = s_org
    steps = 0
    while s.count(c) != len(s):
        s_prime = ""
        for i in range(len(s)-1):
            if(s[i] == c or s[i+1] == c):
                s_prime += c
            else:
                s_prime += s[i]
        s = s_prime
        steps += 1
    ret = min([steps, ret])
print(ret)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int N, M, Q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
  if (A.size() == N+1) {
    int now = 0;
    rep(i,Q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.emplace_back(A.back());
  while (A.back() <= M) {
    dfs(A);
    A.back()++;
  }
} 

int main() {
  cin >> N >> M >> Q;
  a = b = c = d = vector<int>(Q);
  rep(i,Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int MAX_N = 1e5;
vector<vector<int> > tree(MAX_N + 1);
vector<int> cost1(MAX_N + 1);
vector<int> cost2(MAX_N + 1);

vector<bool> searched1(MAX_N, false);
vector<bool> searched2(MAX_N, false);
vector<bool> searched3(MAX_N, false);

void dfs1(int p, int c) {
    for(int to: tree[p]) {
        if (!searched1[to]) {
            searched1[to] = true;
            cost1[to] = c;
            dfs1(to, c + 1);
        }
    }
}
void dfs2(int p, int c) {
    for(int to: tree[p]) {
        if (!searched2[to]) {
            searched2[to] = true;
            cost2[to] = c;
            dfs2(to, c + 1);
        }
    }
}

int main() {
    int N, u, v;
    cin >> N >> u >> v;
    
    for (int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    searched1[v] = true;
    cost2[v] = 0;
    dfs1(v, 1);
    searched2[u] = true;
    cost2[u] = 0;
    dfs2(u, 1);

    int ans = 0;
    queue<int> q;
    q.push(u);
    while (!q.empty()) {
        int t = q.front();
        q.pop();
        for(int tar: tree[t]) {
            if (!searched3[tar] && cost1[tar] > cost2[tar]) {
                searched3[tar] = true;
                q.push(tar);
            }
            if (cost1[tar] > cost2[tar]) {
                ans = max(cost1[tar] - 1, ans);
            }
            if (cost1[tar] == cost2[tar]) {
                ans = max(cost1[tar], ans);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10368
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[2100];
bitset<4010000>dp;
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	dp[0]=1;
	int tot=0;
	for(int i=0;i<a;i++){
		tot+=p[i];
		dp|=(dp<<p[i]);
	}
	int ret=0;
	for(int i=(tot+1)/2;i<=tot;i++){
		if(dp[i]){
			ret=i;break;
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
int MIN(int x, int y){return x<y?x:y;}
int main(void){
	int n;
	scanf("%d",&n);
	char s[n+1];
	scanf("%s",s);
	int ans=n;
	int w[n+1],b[n+1];
	for(int i=0;i<=n;i++){w[i]=b[i]=0;}
	for(int i=0;i<n;i++){
		if(s[i]=='.'){
			w[i+1]=w[i]+1;
			b[i+1]=b[i];
		}else{
			w[i+1]=w[i];
			b[i+1]=b[i]+1;
		}
	}
	/*
	for(int i=0;i<=n;i++){printf("%2d",i);}
	printf("\n");
	for(int i=0;i<=n;i++){printf("%2d",w[i]);}
	printf("\n");
	for(int i=0;i<=n;i++){printf("%2d",b[i]);}
	printf("\n");
	*/
	for(int i=0;i<=n;i++){
		ans=MIN(ans,w[n]-w[i]+b[i]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1920
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
	static class P implements Comparable<P>{
		int id;
		int order;
		@Override
		public int compareTo(P o) {
			return this.order - o.order;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<P> lst = new ArrayList<P>();
		for(int i = 0 ; i< N ; ++i){
			int ai = sc.nextInt();
			P p = new P();
			p.id = i + 1;
			p.order = ai;
			lst.add(p);			
		}
		Collections.sort(lst);
		StringBuilder ret = new StringBuilder();
		for(P p : lst){
			if(ret.length() > 0){
				ret.append(' ');
			}
			ret.append(p.id);
		}
		System.out.println(ret);	
	}
}


Measured memory_bytes: 61684
N,K=map(int,input().split())
if K>((N-2)*(N-1)//2):
    print(-1)
else:
    print(N-1+(N-1)*(N-2)//2-K)
    cnt=0
    for i in range(1,N+1):
        
        for j in range(i+1,N+1):
            if cnt==N-1+((N-1)*(N-2)//2-K):
                exit()
            print(i,j)
            cnt+=1

Measured memory_bytes: 42864
main(){
	int id,bac[4]={0};
	char bt[3];
	for(;~scanf("%d,%s",&id,bt);){
		if(bt[1]=='B')		bac[2]++;
		else if(bt[0]=='A')	bac[0]++;
		else if(bt[0]=='B')	bac[1]++;
		else				bac[3]++;
	}
	for(id=0;id<4;id++)	printf("%d\n",bac[id]);
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    vector<int> dx({0,1,0,-1});
    vector<int> dy({-1,0,1,0});
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];

    auto bfs = [&](const int &x,const int &y){
        int ret = 0;
        set<pii> st;
        st.insert({x,y});
        vector<vector<bool>> visit(h,vector<bool>(w));
        
        while(!st.empty()) {
            set<pii> tmp;
            swap(st,tmp);

            for(auto xy:tmp) {
                //cerr << xy.second << " " << xy.first << endl;
                visit[xy.second][xy.first] = true;
                REP(i,dx.size()) {
                    int nx = xy.first + dx[i];
                    int ny = xy.second + dy[i];
                    if (nx >= w || nx < 0) continue;
                    if (ny >= h || ny < 0) continue;
                    //cerr << i << " " << ny << " " << nx << endl;
                    if (!visit[ny][nx] && s[ny][nx] == '.') st.insert(make_pair(nx,ny));
                }
            }
            if (!st.empty()) ret++;
            //cerr << "r:" << ret << endl;
        }

        return ret;
    };

    int ans = 0;
    REP(y,h) REP(x,w) {
        //cerr << "yx:"<< y << " " << x << endl;
        if (s[y][x] == '.') ans = max(ans,bfs(x,y));
    }


    cout << ans << '\n';

    return 0;
}

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

result=""
for ss in s:
    if ss=="a":
        result+="a"
    else:
        if k>= 123 - ord(ss):
            k-=123-ord(ss)
            result+="a"
        else:
            result+=ss


if k>0:
    k=k%(123-97)
    temp=chr((((ord(result[-1])-97)+k)%(123-97))+97)
    print(result[:-1]+temp)
else:
    print(result)

#print(ord("a")):97
#print(ord("b")):98
#print(ord("z")):122
#97ならそのまま
#aにするには123-ord()をすればいい

Measured memory_bytes: 3572
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(!n && !m)break;
		int mass[n];
		rep(i,n)cin>>mass[i];
		int saikoro[m];
		rep(i,m)cin>>saikoro[i];
		int position=0;
		int cnt=0;
		rep(i,m){
			position+=saikoro[i];
			position+=mass[position];
			if(position>=n-1){
				cnt=i;
				break;
			}
		}
		cnt++;
		cout<<cnt<<endl;
	}
	return 0;
}

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

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    
    int *A = new int[N];
    int *B = new int[N-1];
    for (int i = 0; i < N-1; i++) {
        cin >> B[i];
    }
    
    // init
    A[0] = A[1] = B[0];
    
    for (int i = 1; i < N-1; i++) {
        A[i+1] = B[i];
        if (A[i] > B[i]) {
            A[i] = B[i];
        }
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += A[i];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __DJKIM613
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

ll N;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    cin >> N;

    ll ans = N - 1;
    for(ll i = 1 ; i * i <= N ; i++) if(N % i == 0) ans = min(ans, i + N / i - 2);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n;
  cin >> n;
  vector<vector<i_i> > v(n);
  rep(i,n){
    int a; cin >> a;
    rep(j,a){
      int x,y; cin >> x >> y; x--;
      v[i].push_back(i_i(x,y));
    }
  }
  int ans=0;
  rep(i,(1<<n)){
    bool f=1;
    rep(j,n){
      if(i&(1<<j)){
        rep(k,v[j].size()){
          if(((i>>v[j][k].first)&1)!=v[j][k].second) f=0;
        }
      }
    }
    if(f){
      //cout << i << endl;
      int cnt=0;
      rep(j,n) if(i&(1<<j)) cnt++;
      chmax(ans,cnt);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(void){
    int n,k;
    scanf("%d %d",&n,&k);
    int r,s,p;
    scanf("%d %d %d",&r,&s,&p);
    char str[n + 1];
    scanf("%s",str);

    int dp[n];
    for(int i = 0;i < n;i++){
        dp[i] = 0;
    }

    for(int i = 0;i < n;i++){
        if(i > 0){
            dp[i] += dp[i - 1];
        }
            if(str[i] == 'r'){
            //パー->P
            if(i - k/*kを気にするな*/ < 0){
                //printf("hoge_r\n");
                dp[i] += p;
            }else{
                    if(str[i - k] != 'r'){
                        dp[i] += p;
                    }else if(dp[i - k - 1] == dp[i - k]){
                        dp[i] += p;
                    }
            }

            }else if(str[i] == 's'){

            if(i - k /*kを気にするな*/< 0){
                //printf("hoge_s\n");
                dp[i] += r;
            }else{
                     if(str[i - k] != 's'){
                    dp[i] += r;
                    }else if(dp[i - k - 1] == dp[i - k]){
                        dp[i] += r;
                    }
            }
            }
            else if(str[i] == 'p'){
            if(i - k/*kを気にするな*/ < 0){
                //printf("hoge_p\n");
                dp[i] += s;
            }else{
                    if(str[i - k] != 'p'){
                        dp[i] += s;
                }else if(dp[i - k - 1] == dp[i - k]){
                        dp[i] += s;
                    }
            }

        }
        //printf("%d\n",dp[i]);
    }
    printf("%d",dp[n - 1]);

    return 0;
}

Measured memory_bytes: 640
n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

comb = factorization(n)
lst = []
for i in comb:
    for j in range(i[1]):
        lst.append(i[0]**(j+1))

lst.sort()
ans = 0
for i in lst:
    if n == 1:
        break
    elif n > 1:
        if n%i == 0:
            n = n/i
            ans += 1
print(ans)


Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int mod = 1000000007;
const int N = 10005;
const int D = 111;

string k;
int d;

int dp[N][D][2];
int dfs(int x, int r, int s){
    if(x==N) return !r;
    if(dp[x][r][s]>=0) return dp[x][r][s];

    int ret = 0;
    int lim = s==0?k[x]-'0':9;
    rep(i,lim+1) (ret += dfs(x+1, (r+i)%d, s|(i<lim))) %= mod;
    return dp[x][r][s] = ret;
}

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

    reverse(all(k));
    while(k.size()<N) k += "0";
    reverse(all(k));

    memset(dp,-1,sizeof(dp));
    cout << (dfs(0,0,0)+mod-1)%mod << "\n";
    return 0;
}


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


using namespace std;

int main(){
	long long int n,k,q;
	cin>>n>>k>>q;
	vector<long long int>v(100000);
	
	for(long long int i=1;i<=n;i++){
		
		v[i]=0;
	}
	for(long long int i=1;i<=q;i++){
		int x;
		cin>>x;
		v[x]++;
	} 
    
    for(long long int i=1;i<=n;i++){
		
		v[i]+=(k-q);
	} 
	
	for(long long int i=1;i<=n;i++){
		if(v[i]>0)
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	
		return 0;
}



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

int main(){
  long long n,a,xsum=0,ans; cin >> n;
  vector<long long> vec;
  while(cin >> a){
    vec.push_back(a);
    xsum ^= a;
  }
  
  for(long long i = 0 ; i<n ; i++){
    ans = xsum^vec[i];
    cout<<ans<<" ";
  }
}


Measured memory_bytes: 5304
s=input()
if s[0]!="A":
  print("WA")
  exit()
s=s[1:]
count_C=0
for i in range(len(s)-2):
  if s[i+1]=="C":
    count_C+=1
if count_C!=1:
  print("WA")
  exit()
s=s.replace("C","")
if not s.islower():
  print("WA")
  exit()
print("AC")

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

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

#define INF 1000000000

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

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a*b/gcd(a, b);
}

void bubble_sort(int* p, int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[j], &p[j + 1]);
		}
	}
}

int array_max(int* p, int n)
{
	int max = 0;
	for (int i = 0; i < n; i++)
	{
		if (p[i] > max)
			max = p[i];
	}
	return max;
}

int binary_search(int* p, int key, int n)
{
	int low = 0, high = n - 1;
	int middle;

	while (low <= high)
	{
		middle = (low + high) / 2;

		//printf("low %d  middle %d  high %d\n", low, middle, high);

		//for (int i = 0; i < n; i++)
		//{
		//	if (i == middle)
		//		printf(" ^ ");
		//	else if (i == low)
		//		printf(" [ ");
		//	else if (i == high)
		//		printf(" ] ");
		//	else if (i == middle)
		//		printf(" ^ ");
		//	else
		//		printf("   ");
		//}
		//printf("\n");

		if (key == p[middle])
			return key;
		else if (key < p[middle])
			high = middle - 1;
		else if (key > p[middle])
			low = middle + 1;
	}

	//printf("low %d  middle %d  high %d\n", low, middle, high);
	return -1;
}

int main()
{
	int N;
	char S[100000];
	int count = 0;
	int count2 = 0;

	scanf("%s", S);

	for (int i = 0; S[i]!=NULL; i++)
	{
		if (S[i] == '0')
			count++;
		count2++;
	}

	printf("%d\n", MIN(count,count2-count)*2);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

map<char, int> m;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for (char c : s)
        m[c] = 1;
    if (m['S'] != m['N'] || m['E'] != m['W'])
        cout << "No";
    else
        cout << "Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    char dif = 'A' - 'a';
    printf("%c%c%c\n", s1[0] + dif, s2[0] + dif, s3[0] + dif);
    return 0;
}

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

int main(void)
{
	string fin,model;
	int n,ans=0;

	cin >> fin;
	cin >> n;

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

		if(strstr(model.c_str(), fin.c_str()))
			ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1216