akhauriyash/Code-Regression huggingface dataset:
s = input()

ans = True

if len(s) == 3 :
    if s[0] == s[2] :
        print('Yes')
        exit()
    else :
        print('No')
        exit()

firstS = s[0:len(s)//2]
secondS = s[len(s)//2+1:len(s)]

#print(firstS, secondS)

for i in range(len(firstS)) :
    if firstS[i] != firstS[len(firstS)-1-i] :
        ans = False

#print(ans)

for i in range(len(secondS)) :
    if secondS[i] != secondS[len(secondS)-1-i] :
        ans = False
    #print(s[i], s[len(secondS)-1-i])
    if firstS[i] != secondS[i] :
        ans = False

if ans :
    print('Yes')
else :
    print('No')

'''
if len(s) == 3 :
    if s[0] == s[2] :
        print('Yes')
        exit()
    else :
        print('No')
        exit()

for i in range(len(s) // 2) :
    #print(i, len(s) // 2 -1 - i, s[i], s[len(s) // 2 -1 - i])
    if s[i] != s[len(s) // 2 -1 - i] :
        ans = False

#print(ans)

for i in range(len(s) // 2 + 1, len(s)) :
    #print(i, len(s) - i + len(s) // 2 + 1)
    if s[i] != s[len(s) - 1 - i + len(s) // 2 + 1] :
        ans = False

if ans :
    print('Yes')
else :
    print('No')
'''


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

int main() {
    ll n;
    cin >> n;
    for (ll h = 1; h <= 3500; h++) {
        for (ll w = 1; w <= 3500; w++) {
            ll numerator = n * h * w;
            ll denominator = 4 * h * w - n * w - n * h;
            if (denominator > 0 && numerator % denominator == 0) {
                ll ans = numerator / denominator;
                cout << h << " ";
                cout << ans << " ";
                cout << w << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl

int main() {
    int N,M,A,B,h;
    cin >> N >> M;
    vector<int> H(N);
    vector<bool> ii(N,true);

    rep(i,N){
        cin >> h;
        H.at(i) = h;
    }
    rep(i,M){
        cin >> A >> B;
        if(H.at(A-1) == H.at(B-1)){
            ii.at(A-1) = false;
            ii.at(B-1) = false;
        }else{
            if(H.at(A-1) > H.at(B-1)){
                ii.at(B-1) = false;
            }else{
                ii.at(A-1) = false;
            }
        }
    }
    int cnt =0;
    rep(i,N){
        if(ii.at(i)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3788
import math
 
c60 = math.cos(math.radians(60))
s60 = math.sin(math.radians(60))
 
def koch(d, p1, p2):
    """ Print the coordinates of the vertices of Koch Curve.
    d is the depth of recursion.
    p1, p2 are coordinates of end point of the initial state.
    """
    if d == 0:
        return
 
    sx = (2 * p1[0] + p2[0]) / 3
    sy = (2 * p1[1] + p2[1]) / 3
 
    tx = (p1[0] + 2 * p2[0]) / 3
    ty = (p1[1] + 2 * p2[1]) / 3
 
    dx = tx - sx
    dy = ty - sy
 
    ux = dx * c60 - dy * s60 + sx
    uy = dx * s60 + dy * c60 + sy
 
    koch(d - 1, p1, (sx, sy))
    print("{0:.8f} {1:.8f}".format(sx, sy))
 
    koch(d - 1, (sx, sy), (ux, uy))
    print("{0:.8f} {1:.8f}".format(ux, uy))
 
    koch(d - 1, (ux, uy), (tx, ty))
    print("{0:.8f} {1:.8f}".format(tx, ty))
 
    koch(d - 1, (tx, ty), p2)
 
 
n = int(input())
 
ax = 0
ay = 0
 
bx = 100
by = 0
 
print("{0:.8f} {1:.8f}".format(ax, ay))
koch(n, (ax, ay), (bx, by))
print("{0:.8f} {1:.8f}".format(bx, by))

Measured memory_bytes: 8032
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stdbool.h>
#include <bitset>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using namespace std;


int main(void) {
    char c;
    cin >> c;
    switch (c) {
        case 'A':
            cout << "T" << endl;
            break;
        case 'C':
            cout << "G" << endl;
            break;
        case 'G':
            cout << "C" << endl;
            break;
        case 'T':
            cout << "A" << endl;
            break;
    }
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a,vector<vector<ll>> b,int n){
	int i,j,k,t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k]*b[k][j] % M)%M;
			c[i].push_back(t);
		}
	}
	return c;
}
int main() {
	int n, x, i,count, ans[333333],p[555],t,r[555];
	cin >> n;
	vector<pair<int, int>> v;
	for (i = 1; i <= n * n; i++)
		ans[i] = 0;
	for (i = 1; i <= n; i++) {
		cin >> x;
		v.push_back(make_pair(x, i));
		p[i] = n-1;
	}
	sort(v.begin(), v.end());
	t = 1;
	for (auto& e : v) {
		ans[e.first] = e.second;
		count = e.second - 1;
		r[e.second] = e.first;
		for (; t < e.first&&count>0; t++) {
			if (ans[t] == 0) {
				ans[t] = e.second;
				count--;
				p[e.second]--;
			}
		}
		if (count > 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	for (auto& e : v) {
		while (ans[t] != 0)
			t++;
		if (t < e.first) {
			cout << "No" << endl;
			return 0;
		}
		for(;p[e.second]>0;t++){
			if (ans[t] == 0) {
				ans[t] = e.second;
				p[e.second]--;
			}
		}
	}
	cout << "Yes" << endl;
	for (i = 1; i <= n * n; i++)
		cout << ans[i] << " ";
}

Measured memory_bytes: 6784
object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._
    val inputs = readLine().split(" ").map(_.toLong)
    val N = inputs(0).toInt
    val K = inputs(1)
    val arr = new Array[Long](100001)

    (0 until N).map(_ => {
      val Array(a, b) = readLine().split(" ").map(_.toInt)
      (a, b)
    }).foreach { case (a, b) =>
      arr(a) += b
    }

    var c = 0L
    (1 to 100000).foreach { i =>
      c += arr(i)
      if (c >= K) {
        println(i)
        return
      }
    }

  }

}


Measured memory_bytes: 57784
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int n,k,s,i;
	cin>>n>>k>>s;
	for(i=0;i<k;++i)	cout<<s<<" ";
	for(i=k;i<n;++i)
	{
		if(s != 1)	cout<<s-1<<" ";
		else	cout<<s+1<<" ";
	}
	return 0;
}


Measured memory_bytes: 1280
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime
a = primes(100000)
resemble = []
for i in range(len(a)):
    if a[i]:
        if a[(i+1)//2]:
            resemble.append(i)
n = int(input())
ans = [0]*100000
q =[]
for i in range(1,100001):
    if i in resemble:
        ans[i-1] = ans[i-2] + 1
    elif i>1:
        ans[i-1] = ans[i-2]
for i in range(n):
    l,r = map(int,input().split())
    if l>1:
        q.append(ans[r-1]-ans[l-2])
    elif r>1:
        q.append(ans[r-1])
    else:
        q.append(0)
for i in range(n):
    print(q[i])

Measured memory_bytes: 9404
a,b,c = [int(x) for x in input().split()]

m = max([a,b,c])
if m % 2 == sum([a,b,c]) % 2:
    print(((3 * m) - sum([a,b,c])) // 2)
else:
    print((((m+1) - a) + ((m+1)-b) + ((m+1)-c)) // 2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll sum=0;
    ll sumr=0,sumb=0,sumg=0;
    ll cntr[n]={},cntg[n]={},cntb[n]={};
    for(int i=0; i<n; i++){
        if(s[i]=='R')sumr++;
        if(s[i]=='G')sumg++;
        if(s[i]=='B')sumb++;
        cntr[i]=sumr;
        cntg[i]=sumg;
        cntb[i]=sumb;
        //cout << sumr << " " << cntr[i] << endl;
    }
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            int tmp=0;
            if(s[i]=='R'&&s[j]=='G'){
                tmp=sumb-cntb[j];
                //cout <<"!" <<tmp << endl;
                if(2*j-i<=n-1){
                    if(s[2*j-i]=='B')tmp--;
                }
                
            }
            else if(s[i]=='G'&&s[j]=='R'){
                tmp=sumb-cntb[j];
                if(2*j-i<=n-1){
                    if(s[2*j-i]=='B')tmp--;
                }
                
            }
            else if(s[i]=='R'&&s[j]=='B'){
                tmp=sumg-cntg[j];
                if(2*j-i<=n-1){
                    if(s[2*j-i]=='G')tmp--;
                }
            }
            else if(s[i]=='B'&&s[j]=='R'){
                tmp=sumg-cntg[j];
                if(2*j-i<=n-1){
                    if(s[2*j-i]=='G')tmp--;
                }
 
            }
            else if(s[i]=='G'&&s[j]=='B'){
                tmp=sumr-cntr[j];
                if(2*j-i<=n-1){
                    if(s[2*j-i]=='R')tmp--;
                }
                
            }
            else if(s[i]=='B'&&s[j]=='G'){
                tmp=sumr-cntr[j];
                if(2*j-i<=n-1){
                    if(s[2*j-i]=='R')tmp--;
                }
                
            }
            sum+=tmp;
            //cout << sum << endl;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3720
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var Li_2 = 2L;
            var Li_1= 1L;
            var Li = 1L;
            for (var i = 2; i <= N; ++i)
            {
                Li = Li_1 + Li_2;
                Li_2 = Li_1;
                Li_1 = Li;
            }
            WriteLine(Li);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28164
#include<bits/stdc++.h>
#include<string>
#include<cctype> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
  int N,i;
  int max=0;
  int min=1000;
  cin >> N;
  int a[N];
  rep(i,N){
    cin >> a[i];
  } 
  rep(i,N){
    if(a[i]<min){
      min=a[i];
    }
    if(a[i]>max){
      max=a[i];
    }
  }
  cout << max-min << endl;  


  return 0;
} 



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int k;
    ll ans = 0;

    cin >> k;

    for (int a = 1; a <= k; a++)
    {
        for (int b = 1; b <= k; b++)
        {
            for (int c = 1; c <= k; c++)
            {
                int res = gcd(a, b);
                res = gcd(res, c);

                ans += res;
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  int pos[N];
  for(int i=0; i<N; i++) cin >> pos[i];
  
  int min = INT_MAX;
  int loss;
  
  for(int i=1; i<=100; i++) {
    loss = 0;
    for(int j=0; j<N; j++) {
      loss += (pos[j]-i)*(pos[j]-i);
    }
    if(loss<min) min = loss;
  }
    
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int NIL = -1;
const int MAX = 100000;
vector<int> SNS[MAX];
int color[MAX];

void dfs(int v, int colorIdx) {

	stack<int> S;
	S.push(v);
	color[v] = colorIdx;

	while (!S.empty()) {
		int s = S.top();
		S.pop();
		for (int i = 0; i < (int) SNS[s].size(); ++i) {
			int r = SNS[s][i];
			if (color[r] == NIL) {
				S.push(r);
				color[r] = colorIdx;
			}
		}
	}
}

void makeColor(int color[], int n) {
	int colorIdx = 0;
	for (int i = 0; i < n; ++i) {
		if (color[i] == NIL)
			dfs(i, colorIdx++);
	}
}

int main() {

	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 0; i < m; ++i) {
		int s, t;
		scanf("%d %d", &s, &t);
		SNS[s].push_back(t);
		SNS[t].push_back(s);
	}

	for (int i = 0; i < n; ++i)
		color[i] = NIL;

	makeColor(color, n);

	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int s, t;
		scanf("%d %d", &s, &t);
		if (color[s] == color[t])
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}

	return 0;
}

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

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define FR(i, a, b) for(int i = a; i <= b; i++)
#define gcd __gcd 
#define FR(i, l, r) for(int i = (l); i <= (r); i++)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
	
	
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <pll> vll;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }


/*********** TEMPLATE ENDS HERE *************/

#define int long long

const int N = 507;

int a[N][N];
int b[N][N];

main()
{
	int n, m, q;
	cin >> n >> m >> q;
	  
	while(m--)
	{
		int x, y;
		cin >> x >> y;
		a[x][y]++;
	}
	
	for(int i = 1; i <= n; i++)
		for(int j = i; j <= n; j++)
		{
			b[i][j] = b[i][j - 1];
			for(int k = i; k <= j; k++)
				b[i][j] += a[k][j];
		}
	
	int ans = 0;
	
	while(q--)
	{   
		int P, Q;
		cin >> P >> Q;
		cout << b[P][Q] << endl;
	}
}


Measured memory_bytes: 4864
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int N, M, K;
int A[20000];
long long dp[20001];

int main() {
  scanf("%d %d %d", &N, &M, &K);
  for (int i=0; i<N; i++) {
    scanf("%d", &A[i]);
  }
  dp[0] = 0LL;
  for (int i=0; i<N; i++) {
    int a = A[i], b = A[i];
    long long m = (1LL<<60);
    for (int j=0; j<M; j++) {
      if (i-j < 0) break;
      a = max(a, A[i-j]);
      b = min(b, A[i-j]);
      m = min(m, dp[i-j] + K + (long long)(j+1)*(a - b));
    }
    dp[i+1] = m;
  }
  printf("%lld\n", dp[N]);
  return 0;
}

Measured memory_bytes: 2984
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
 
const static int tx[] = {+0,+1,+0,-1};
const static int ty[] = {-1,+0,+1,+0};
 
static const double EPS = 1e-12;

class MagicalCircle{
public:
  int pos;
  int dist;
  int time;
  MagicalCircle(int _p,int _d,int _t) : pos(_p),dist(_d),time(_t){}
  bool operator<(const MagicalCircle& m) const{
    return pos < m.pos;
  }
  bool operator>(const MagicalCircle& m) const{
    return pos > m.pos;
  }
  bool operator<(const int num) const{
    return pos < num;
  }
  bool operator>(const int num) const{
    return pos > num;
  }
};

class State{
public:
  int pos;
  int time;
  State(int _p,int _t) : pos(_p),time(_t){}
  bool operator<(const State& s) const{
    return time < s.time;
  }
  bool operator>(const State& s) const{
    return time > s.time;
  }
};

int main(){
  int distance;
  int total_magical_circles;
  while(~scanf("%d %d",&distance,&total_magical_circles)){

    vector<MagicalCircle> magical_circles;
    for(int circle_idx=0;circle_idx<total_magical_circles;circle_idx++){
      int pos;
      int dist;
      int time;
      scanf("%d %d %d",&pos,&dist,&time);
      magical_circles.push_back(MagicalCircle(pos,dist,time));
    }

    magical_circles.push_back(MagicalCircle(distance,0,0));
    sort(magical_circles.begin(),magical_circles.end());

    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(0,0));

    map<int,int> dp;
    while(!que.empty()){
      State s = que.top();
      que.pop();

      if(dp.find(s.pos) != dp.end()) continue;
      dp[s.pos] = s.time;

      int idx = lower_bound(magical_circles.begin(),magical_circles.end(),s.pos) - magical_circles.begin();

      if(magical_circles[idx].pos == s.pos){
	//use
	int next_time = s.time + magical_circles[idx].time;
	int next_pos = s.pos + magical_circles[idx].dist;
	que.push(State(next_pos,next_time));

	//un-use
	int next_time2 = s.time + 1;
	int next_pos2 = s.pos + 1;
	que.push(State(next_pos2,next_time2));
      }
      else{
	//just move
	int next_time = s.time + (magical_circles[idx].pos - s.pos);
	int next_pos = magical_circles[idx].pos;
	que.push(State(next_pos,next_time));
      }
    }

    printf("%d\n",dp[distance]);
  }
}


Measured memory_bytes: 1352
import Data.Traversable
import Data.List

main = do
  n:m:xs <- map read . words <$> getLine
  ps <- for [1..n] $ \x -> do
    sort . tail . map read . words <$> getLine
  putStrLn . show $ solve'' 1 m ps

solve'' :: Int -> Int -> [[Int]] -> Int
solve'' k m ps
  | k > m = 0
  | otherwise =
      let (res, next) = oneStep k ps
      in (if (and res) then 1 else 0) + solve'' (k+1) m next

oneStep k ps =
  unzip $ map (\p -> if (if null p then False else head p == k) then 
                       (True, if null p then [] else tail p)
                     else (False, p)) ps


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

int main() {
  int64_t H;
  cin >> H;
  
  int64_t ans = 1LL;
  int64_t n = 1LL; 
  

  while(H > 1){
    H = H/2;
    n = 2*n;
    ans += n;
    
  }
  
    cout << ans << endl;
  
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  long unsigned N, M;
  cin >> N >> M;
  vector<long long> takasa(N);
  for(long unsigned i = 0; i < N; i++){
    cin >> takasa[i];
  }
  vector<vector<long unsigned>> hashi(N);
  for(long unsigned i = 0; i < M; i++){
    long unsigned a, b;
    cin >> a >> b;
    a--; b--;
    hashi[a].push_back(b);
    hashi[b].push_back(a);
  }

  long unsigned count = 0;
  for(long unsigned i = 0; i < N; i++){
    for(long unsigned j = 0; j < hashi[i].size(); j++){
      if(takasa[hashi[i][j]] >= takasa[i]){
        break;
      }
      if(j == hashi[i].size()-1){
        count++;
      }
    }
    if(hashi[i].size() == 0){
      count++;
    }
  }
  cout << count <<endl;
}


Measured memory_bytes: 9800
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define inf 10e8
using namespace std;



int main(){
    string s;
    cin >> s;
    int n=s.size();
    bool ans=0;
    for(int i=0;i<n;i++){
        if(i%2==0){//奇数
            if(s.at(i)=='L') ans=1;
        }
        else {
            if(s.at(i)=='R') ans=1;
        }
    }
    if(ans) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
bool cmp(pint a, pint b) {return a.second < b.second;}

const ll MOD = 1e9 + 7;

ll f(ll x) {
    if(x == 1) return 1;
    ll a = f(x/2);
    return a*2 + 1;
}

int main() {
    ll h;
    cin >> h;
    cout << f(h) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll      int
#define ld      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     1000000007
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     10000000000000007
const int N=304;
ll ans[N][N];
ll vis[N];
vector<pair<ll,ll> >adj[N];
priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>,ll> >,greater<pair<pair<ll,ll>,ll> > >pq;
void run(){
    ll n,m,k,u,v,w,i,q;
    cin>>n>>m>>k;
    while(m--)
    {
        cin>>u>>v>>w;
        adj[u].pb(MP(v,w));
        adj[v].pb(MP(u,w));
    }

    memset(ans,-1,sizeof ans);    
    for(i=1;i<=n;i++)
    {
        memset(vis,0,sizeof vis);
        pq.push(MP(MP(0,-k),i));
        while(!pq.empty())
        {
            pair<pair<ll,ll>,ll>p=pq.top();
            u=p.S;
            pq.pop();
            if(vis[u]) continue;
            vis[u]=1;
            ans[i][u]=p.F.F;
            for(auto it:adj[u])
            {
                v=it.F;
                w=it.S;
                if(vis[v]) continue;
                if(w<=-p.F.S)
                    pq.push(MP(MP(p.F.F,-(-p.F.S-w)),v));
                else if(w<=k)
                    pq.push(MP(MP(p.F.F+1,-(k-w)),v));
            }
        }
    }
    cin>>q;
    while(q--)
    {
        cin>>u>>v;
        cout<<ans[u][v]<<"\n";
    }

}
 
 
void setup(){
    ios;
    //cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}

Measured memory_bytes: 2816
from collections import defaultdict
import math


N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

nums = make_divisors(N)
# print(nums)
ans = 0
for num in nums:
    if num != 1:
        if N % (num -1) == N // (num -1):
            ans += num -1
print(ans)
# for m in range(1,N + 1):
#     ans = 0
#     if N//m == N % m:
#         print("SAME")
#         print(f"{m}: 商:{N//m} 余り:{N % m}")
#         print("SAME")

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll k,a,b;

int main(void){
    scanf("%lld%lld%lld",&k,&a,&b);
    ll ans=1;
    if(a>k+1){
        ans=k+1;
        printf("%lld\n",ans);
        return 0;
    }
    ans=a;
    k-=(a-1LL);
    if(b-a>=3){
        ll ca=k/2LL;
        ans+=ca*(b-a);
        ans+=k%2LL;
        printf("%lld\n",ans);
    }else{
        ans+=k;
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <numeric>
#include <algorithm>
using namespace std;

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

	if (A >= 3200) cout << S << endl;
	else cout << "red" << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int mex[500][500];

int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    int X,Y;
    scanf("%d %d",&X,&Y);
    X--,Y--;
    if(mex[X][X]||mex[Y][Y]||mex[X][Y]){
      mex[X][X]=1;
      mex[Y][Y]=1;
    }else{
      for(int j=0;j<N;j++){
	if(mex[X][j]||mex[Y][j]){
	  mex[X][j]=mex[j][X]=mex[Y][j]=mex[j][Y]=1;
	}
      }
      mex[X][Y]=mex[Y][X]=1;
    }
  }
  for(int i=0;i<N;i++){
    if(mex[i][i]){
      for(int j=0;j<N;j++){
	mex[i][j]=mex[j][i]=1;
      }
    }
  }
  /*
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      printf("%d",mex[i][j]);
    }
    printf("\n");
  }
  */
  int cnt=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<i;j++){
      if(mex[i][j]==0) cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 896
N, M = [int(i) for i in input().split()]

AB = []

for _ in range(N):
    AB.append([int(i) for i in input().split()])

AB = sorted(AB)

money = 0

for i in AB:
    a = M - i[1]
    if a > 0:
        M = a
        money += i[1]*i[0]
    else:
        money += M*i[0]
        break
print(money)

Measured memory_bytes: 22384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
 
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
 
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
 
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
 
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
 
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  int a,b;
  cin >> a >> b;
  int ans = 1;
  if(b == 1){
    cout << 0 << endl;
    return 0;
  }
  else {
    cout << 1+(b-2)/(a-1) << endl;
  }
}



Measured memory_bytes: 256
#include <stdio.h>
#define NIL 2000000001
#define NUM 10000000

int heap[NUM];

void output(int num){
    printf("node %d: key = %d, ", num, heap[num]);
    if(num != 1){
        printf("parent key = %d, ", heap[num / 2]);
    }
    if(heap[num * 2] != NIL){
        printf("left key = %d, ", heap[num * 2]);
    }
    if(heap[num * 2 + 1] != NIL){
        printf("right key = %d, ", heap[num * 2 + 1]);
    }
    printf("\n");
}

int main(void){
    for(int i = 0; i < NUM; i++){
        heap[i] = NIL;
    }

    int H;
    scanf("%d", &H);

    int index = 1;

    for(int i = 0; i < H; i++){
        scanf("%d", &heap[i + 1]);
    }

    for(int i = 0; i < H; i++){
        output(i + 1);
    }

}



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

static const int MAX = 50;
static const int INF = 1e9;

// 隣接行列を用いた幅優先探索 O(|V|^2)
int n, M[MAX][MAX];
vector<int> d(MAX, INF); // 始点sから頂点iまでの最短距離をd[i]に記録
// main関数からこれらを削除すること

void bfs(int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int v = 0; v < n; v++){
      if(M[u][v] == 0) continue;
      if(d[v] != INF) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
}

int main() {
// 無向(有向)グラフの隣接行列
  int m, u, v;
  cin >> n >> m;
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      M[i][j] = 0;
    }
  }
  
  for(int i = 0; i < m; i++){
    cin >> u >> v;
    u--;
    v--;
    M[u][v] = 1;
    M[v][u] = 1; // 有向グラフではこの行をコメントアウト
  }
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(M[i][j] == 1){
        M[i][j] = M[j][i] = 0;
        for(int k = 0; k < n; k++){
          d[k] = INF;
        }
        bfs(0);
        for(int k = 0; k < n; k++){
          if(d[k] == INF){
            ans++;
            break;
          }
        }
        M[i][j] = M[j][i] = 1;
      }
    }
  }
  
  cout << ans / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>

using namespace std;

const int mod = 1000000007;

int main(){
    int n;
    while(cin>>n,n){
        int a=0,b=0;
        n/=4;
        while(n--){
            cin>>a;
            b+=a;
        }
        cout<<b<<endl;
        
    }
}

Measured memory_bytes: 1160
let solve n a =
	let rec loop checked lost sum lst =
		match lst with
		| [] -> lost
		| x :: xs ->
			if x <= sum * 2 then
				loop (checked + 1) lost (sum + x) xs
			else
				loop (checked + 1) checked (sum + x) xs
	in
	n - loop 0 0 0 (List.sort compare a)

let () =
	let n = read_int () in
	let a =
		read_line ()
		|> Str.split (Str.regexp " ")
		|> List.map int_of_string
	in
	solve n a
	|> print_int
	|> print_newline


Measured memory_bytes: 16768
import java.util.*;
import java.lang.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b=new int[5];
		int c=10;
		int d=0;
		for(int i=0;i<4;i++) {
			b[i]=a%c;
			//System.out.println(b[i]);
			a/=10;
		}
		for(int i=0;i<3;i++) {
			if(b[i]==b[i+1]) {
				if(b[i]==b[i+2])
				d++;
				break;
			}
		}
		if(d>=1)System.out.println("Yes");
		else System.out.println("No");
		//System.out.println(d);
	}
}

Measured memory_bytes: 23764
{-
A_i周期で食べる人がN日目までに消費する個数：
(div (N-1) A_i)+1
-}

solver::[Int]->Int->Int->Int
solver peris rest day = rest + (sum (map (person_eat day) peris))
            where person_eat::Int->Int->Int
                  person_eat d period = (div (d-1) period)+1

main::IO()
main=do
  nc<-getLine
  let n = read nc
  dxc<-getLine
  let d:x:[]=map read (words dxc)
  peris<-n_get n
  print (solver peris x d)

n_get::Int->IO [Int]
n_get 0 = return []
n_get n = do
  d<-getLine
  let i = read d
  rest<-n_get (n-1)
  return (i:rest)

Measured memory_bytes: 892
from collections import deque


def init_tree(x, par):
    for i in range(x + 1):
        par[i] = i


def find(x, par):
    q = deque()
    q.append(x)
    while len(q) > 0:
        v = q.pop()
        if v == par[v]:
            return v
        q.append(par[v])


def union(x, y, par, rank):
    px, py = find(x, par), find(y, par)
    if px == py:
        return
    if rank[px] < rank[py]:
        par[px] = py
        return
    elif rank[px] == rank[py]:
        rank[px] += 1
    par[py] = px


n, m, k = map(int, input().split())
par = [0] * (n + 1)
rank = [0] * (n + 1)
init_tree(n, par)
eg = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    union(a, b, par, rank)
    eg[a].append(b)
    eg[b].append(a)
for _ in range(k):
    a, b = map(int, input().split())
    eg[a].append(b)
    eg[b].append(a)

xs = [0] * (n + 1)
ys = [0] * (n + 1)
for i in range(1, n + 1):
    p = find(i, par)
    xs[p] += 1
    for v in eg[i]:
        if p == find(v, par):
            ys[i] += 1

ans = [-1] * (n + 1)
for i in range(1, n + 1):
    ans[i] += xs[find(i, par)] - ys[i]
print(*ans[1:])


Measured memory_bytes: 116360
#include<iostream>
#define int long long
using namespace std;

signed main(){
    const int bunkatsu_max=50000;
    int b;
    while(true){
        cin>>b;
        if(b==0){
            return 0;
        }
        for(int i=bunkatsu_max;i>0;--i){
            if(i%2==1){
                if(b%i==0&&b>=(i+1)*i/2){
                    cout<<b/i-(i+1)/2+1<<" "<<i<<endl;
                    break;
                }
            }
            else{
                if(b%i==i/2&&b>=i*(i+1)/2){
                    cout<<b/i-i/2+1<<" "<<i<<endl;
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 3108
/*
 * src.cpp
 *
 *  Created on: 2016/07/27
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=10;

int N;

struct team{
	int w,l,index;
	char name;
	bool operator < (const team &a)const{
		if (w!=a.w){
			return w<a.w;
		}
		if (l!=a.l){
			return l>a.l;
		}
		return index>a.index;
	}
};

team t[MAX_N];

int main(){
	do{
		cin>>N;
		if (N){
			cin.ignore();
			REP(i,N){
				string s;
				getline(cin,s);
				t[i].w=t[i].l=0;
				t[i].index=i;
				t[i].name=s[0];
				REP(j,N-1){
					char r=s[j*2+2];
					if (r=='0'){
						t[i].w++;
					}else if (r=='1'){
						t[i].l++;
					}
				}
			}
			sort(t,t+N);
			REP(i,N){
				cout<<t[N-i-1].name<<endl;
			}
		}
	}while (N);
	return 0;
}

Measured memory_bytes: 1216
#include<iostream>
using namespace std;
int main(void){
	int array[4]={1,9,7,4};
	int i,n,j,co=0;
	for(i=0;i<4;i++){
		cin>>n;
		if(n!=1&&n!=7&&n!=9&&n!=4){
			co=0;
			break;
		}
		for(j=0;j<4;j++){
			if(array[j]==n){
				array[j]=0;
//				cout<<array[0]<<array[1]<<array[2]<<array[3]<<endl;
				co++;
				break;
			}
		}
	}
	if(array[0]+array[3]+array[2]+array[1]==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb push_back
const int N=1e5+5;
// const ll M = 998244353;
const ll M=1e9+7;
const ll inf=1e18;

ll dp[101][N];

int main()
{
	var(n);var(k);
	rep(i,0,n)
	{
		var(x);
		if(i)
		{
			for(int j=0;j<N;j++)
			{
				if(j<=x)
					dp[i][j]=dp[i-1][j];
				else
				{
					dp[i][j]=(dp[i-1][j]-dp[i-1][j-x-1]+M)%M;
				}
			
			}
		}
		else
		{
			for(int j=0;j<=x;j++)
				dp[i][j]=1;
		}
		if(i<n-1)
		{
			for(int j=1;j<N;j++)
			{
				dp[i][j]+=dp[i][j-1];
				dp[i][j]%=M;
			}
		}
	}
	lpri(dp[n-1][k]);

}

Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int a[200];

void init() {
	for (int i = 1; i <= 199; ++i) {
		a[i] = i * i;
	}
}

int dp[36700];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	init();
	while (cin >> n) {
		if (n == 0) break;

		int ans = 0;
		for (int i = 1; i <= 185; ++i) {
			
			if (a[i] > n) break;
			if (a[i] == n) {
				ans++;
				break;
			}
			for (int j = i; j <= 185; ++j) {
				if (a[i] + a[j] > n) break;
				if (a[i] + a[j] == n) {
					ans++;
					break;
				}

				for (int k = j; k <= 185; ++k) {
					if (a[i] + a[j] + a[k]> n) break;
					if (a[i] + a[j] + a[k] == n) {
						ans++;
						break;
					}

					for (int l = k; l <= 185; ++l) {
						if (a[i] + a[j] + a[k] + a[l] > n) break;
						if (a[i] + a[j] + a[k] + a[l] == n) {
							ans++;
							break;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}

	int c; cin >> c;
	return 0;

}


Measured memory_bytes: 3132
#include <stdio.h>


int main(){

	int n, m, l;
	int x, y, k;
	long sum;
	int a[100][100], b[100][100];


	scanf( "%d %d %d", &n, &m, &l );

	for( y=0; y<n; y++ ){
	for( x=0; x<m; x++ ){
		scanf( "%d", &a[x][y] );
	}}

	for( y=0; y<m; y++ ){
	for( x=0; x<l; x++ ){
		scanf( "%d", &b[x][y] );
	}}




	for( y=0; y<n; y++ ){
	for( x=0; x<l; x++ ){
		sum=0;
		for( k=0; k<m; k++ ){
			sum += a[k][y]*b[x][k];
		}
		printf( "%ld", sum );
		if( x != (l-1) ) printf( " " ); 
	
	}printf( "\n" );}







	return 0;

}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

#define MAX 100000

struct union_find {
    int rnk[MAX], par[MAX];

    union_find(int n) { for(int i = 0; i < n; i++) rnk[i] = 1, par[i] = i; }

    int find(int x) {
        if(x == par[x]) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;
        if(rnk[x] > rnk[y]) par[y] = x;
        else{
            par[x] = y;
            if(rnk[x] == rnk[y]) rnk[y]++;
        }
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

struct edge {
    int from, to, cst;
    edge(){}
    edge(int from, int to, int cst) : from(from), to(to), cst(cst) {}
    bool operator<(const edge &e) const { return cst < e.cst; }
};

int n;

// Eが連結ならTに最小全域木が入る
int kruskal(vector<edge> &E, vector<edge> &T) {
    sort(E.begin(), E.end());
    T.clear();
    union_find uf(n) ;
    int w = 0;
    for(int i = 0; i < E.size(); i++){
        edge &e = E[i];
        if(uf.same(e.from, e.to)) continue;
        uf.unite(e.from, e.to);
        w += e.cst;
        T.push_back(e);
    }
    return w;
}

int main(){
  cin >> n;
  vector<pii> x(n),y(n);
  rep(i,n){
    cin >> x[i].fst >> y[i].fst;
    x[i].snd = y[i].snd = i;
  }
  
  sort(all(x)); sort(all(y));
  vector<edge> e,t;
  rep(i,n-1){
    e.pb((edge){x[i].snd,x[i+1].snd,abs(x[i].fst-x[i+1].fst)});
    e.pb((edge){y[i].snd,y[i+1].snd,abs(y[i].fst-y[i+1].fst)});
  }
  cout << kruskal(e,t) << endl;
}

Measured memory_bytes: 8304
#include<iostream>
using namespace std;
int main(){
    while(true){
       int i,j,k,n,x,tem=0;
       cin >> n >> x;
       if(n == 0 && x == 0)break;
       for(i=1;i<=n-2;i++){
           for(j=i+1;j<=n-1;j++){
               for(k=j+1;k<=n;k++){
                   if((i+j+k == x) && (i!=j || j!=k ||i!=k))tem = tem+1;
               }
           }
       }
       cout << tem << endl;
    }
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#define PI acos(-1)
#define fs first
#define sc second
#define debug freopen("1.in","r",stdin),freopen("1.out","w",stdout);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll maxn = 1e6 + 10;
int arr[5], n, m, c, tmp;

int main() {
    ios;
    cin >> n >> m;
     if(n == 1 && m == 0) {
        cout << 0;
        return 0;
    }
    memset(arr,-1,sizeof arr);
    for(int i = 0;i < m; ++i) {
        cin >> c >> tmp;
        if(arr[c] == -1) arr[c] = tmp;
        else if(arr[c] != tmp) {
            cout << "-1";
            return 0;
        }
    }
    if(arr[1] == -1)
		arr[1] = 1;
    if(arr[1] == 0 && n > 1) {
        cout << -1;
        return 0;
    }
    for(int i = 1;i <= n; ++i) {
        if(arr[i] == -1) cout << 0;
        else cout << arr[i]; 
    }
    return 0;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, x=1e9 + 7, c=1;
  string s;
  cin >> n >> s;
  vecll a(26, 0);
  forll(i, 0, n)
	a[s[i] - 'a']++;
  forll(i, 0, 26)
	c = c * (a[i] + 1) % x;
  cout << c - 1 << endl;
}


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

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

int main(){

  while(true){
    int r, n; cin>> r>> n;
    if(n==0 && r==0) break;

    vector<int> xl(n), xr(n), h(n);
    rep(i, n) cin>> xl[i]>> xr[i]>> h[i];
    map<int, int> mh;
    rep(i, n){
      for(int x=xl[i]; x<xr[i]; x++){
        mh[x]=max(mh[x], h[i]);
      }
    }

    double t=1e9;
    for(int x=-r+1; x<r; x++){
      t=min(t, r-sqrt(r*r-x*x)+min(mh[x-1], mh[x]));
    }

    printf("%.18f\n", t);
  }

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool a = (s[2] == s[3]);
  bool b = (s[4] == s[5]);
  if(a & b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

template <class T>
T mygcd(T x, T y) {
  if (y == T(0))
    return x;
  else
    return mygcd(y, x % y);
}

void solve() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x[i];
  int g = 0;
  for (int i = 0; i < N; i++) g = mygcd(g, abs(X - x[i]));
  cout << g << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// list up all factors
template <typename T>
set<T> factors(T a) {
    set<T> facs;
    for (T i = 1; i * i <= a; ++i) {
        if (a % i == 0) {
            facs.insert(i);
            facs.insert(a / i);
        }
    }
    return facs;
}

int main() {
    int n, k;
    cin >> n >> k;
    vl a(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    // vl summa(n);
    // ll minsuma = INF;
    // for (int i = 0; i < n; ++i) {
    //     summa[i] = sum - a[i];
    //     chmin(minsuma, summa[i]);
    // }
    // if (minsuma <= k) {
    //     cout << sum << "\n";
    //     return 0;
    // }

    set<ll> facs = factors(sum);
    ll ret = 1;
    for (auto &f : facs) {
        vl diff(n, 0);
        vl diffabs(n, 0);
        ll sum = 0;
        ll sumabs = 0;
        for (int i = 0; i < n; ++i) {
            int d = a[i] % f;
            if (abs(d - f) < abs(d))
                diff[i] = d - f;
            else
                diff[i] = d;
            diffabs[i] = abs(diff[i]);
            sum += diff[i];
            sumabs += diffabs[i];
        }
        if (sum % f != 0)
            continue;
        if (sum < 0) {
            ll num = abs(sum / f);
            priority_queue<ll, vl, greater<ll>> pq;
            for (int i = 0; i < n; ++i) {
                pq.push(diff[i]);
            }
            for (int i = 0; i < num; ++i) {
                ll mini = pq.top();
                pq.pop();
                sumabs -= abs(mini);
                mini += f;
                sumabs += abs(mini);
                pq.push(mini);
            }
        } else {
            ll num = abs(sum / f);
            priority_queue<ll> pq;
            for (int i = 0; i < n; ++i) {
                pq.push(diff[i]);
            }
            for (int i = 0; i < num; ++i) {
                ll mini = pq.top();
                pq.pop();
                sumabs -= abs(mini);
                mini -= f;
                sumabs += abs(mini);
                pq.push(mini);
            }
        }
        if (sumabs / 2 <= k) {
            chmax(ret, f);
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;



int main(){
	int d,arr[100000],count,ch;
	arr[0]=2;
	count =0;
	for(int i=3;i<=50100;i++){
		ch=0;
		for(int j=0;j<=count;j++){
			if(i%arr[j] == 0)ch=1;
		}
		if(ch == 0){
			count++;
			arr[count]=i;
		}
	}
	while(scanf("%d",&d) != EOF){
		for(int i=0;;i++){
			if(arr[i]==d){
				printf("%d %d\n",arr[i-1],arr[i+1]);
				break;
			}
			if(arr[i]>d){
				printf("%d %d\n",arr[i-1],arr[i]);
				break;
			}
		}
	}
		
	
	return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k; cin>>n>>k;
    long long ans=1;
    for(int i=0;i<n;i++){
        if(i==0) ans*=k;
        else ans*=(k-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256