akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = double;
constexpr ll mod = 1e9 + 7;
constexpr ld inf = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

using Graph = vector<vector<int>>;

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

  int n, m;
  cin >> n >> m;
  vector<int> s(m), t(m);
  Graph g0(n);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> t[i];
    s[i]--;
    t[i]--;
    // s->t
    g0[s[i]].push_back(t[i]);
  }
  vector<ld> dist(n, inf);
  auto calc = [&](const Graph &g) {
    for (int i = 0; i < n; i++) dist[i] = inf;
    dist[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--) {
      int sz = g[i].size();
      if (sz == 0) continue;
      ld sum = 0;
      for (auto nxt : g[i]) {
        sum += dist[nxt];
        if (dist[nxt] == inf) return inf;
      }
      dist[i] = 1 + sum / sz;
    }
    return dist[0];
  };
  ld ret = calc(g0);
  for (int i = n - 2; i >= 0; i--) {
    if (g0[i].size() == 1) continue;
    calc(g0);
    ld ma = 0, sum = 0;
    for (auto nxt : g0[i]) {
      sum += dist[nxt];
      ma = max(ma, dist[nxt]);
    }
    sum -= ma;
    dist[i] = 1 + sum / (g0[i].size() - 1);
    bool f = true;
    for (int j = i - 1; j >= 0; j--) {
      int sz = g0[j].size();
      assert(sz);
      ld stmp = 0;
      for (auto nxt : g0[j]) {
        stmp += dist[nxt];
        assert(dist[nxt] != inf);
      }
      dist[j] = 1 + stmp / sz;
    }
    if (!f) continue;
    ret = min(ret, dist[0]);
  }
  cout << fixed << setprecision(10) << ret << endl;
}


Measured memory_bytes: 2816
import bisect
N=int(input())
L=sorted(map(int,input().split()))
cnt=0
for i in range(N):
    for j in range(i):
        a=L[i]
        b=L[j]
        right=a+b
        left=abs(a-b)
        rind=bisect.bisect_left(L,right)
        lind=bisect.bisect_right(L,left)
        res=rind-lind
        if(left<a<right):
            res-=1
        if(left<b<right):
            res-=1
        cnt+=res
print(cnt//3)

Measured memory_bytes: 47192
import numpy as np
n = int(input())
h = list(map(int, input().split()))

h = np.array(h)


def calc(h, s):
#     print(h, s)
    a = np.min(h)
    s += a
    h = h - a
    ind = np.where(h == 0)[0][0]
    h1 = h[:ind]
    h2 = h[ind+1:]
    if len(h1) != 0:
        s = calc(h1, s)
    if len(h2) != 0:
        s = calc(h2, s)
    return s

print(calc(h, 0))

Measured memory_bytes: 21516
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
LL N, M, S, A[50];
inline LL ceil(LL d, LL n) {return (d+n-1)/n;}
inline bool ok(LL x) {
  if(M < S-x) return false;
  LL s = 0;
  for(auto i=0; i<N; ++i) s += ceil(A[i]+x+1-N, N+1);
  return s <= x;
}
int main() {
  scanf("%lld", &N);
  M=N*(N-1);
  for(auto i=0; i<N; ++i) scanf("%lld", A+i), S+=A[i];
  LL l = -1, h = 1e18;
  while(l+1 < h) {
    LL m = (l+h)>>1;
    if(ok(m)) h = m;
    else      l = m;
  }
  for(auto x=max(0ll,h-M); x<=h; ++x) if(ok(x)) {
    printf("%lld\n",x);
    break;
  }
}


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

long long int n;


int main(){
	scanf("%lld", &n);
	long long int x;
	scanf("%lld", &x);
	long long int A = n-x;
	long long int B = x;
	long long int ans = n;
	if (A < B)swap(A, B);
	while (B){
		if (A%B){
			ans += (A / B)*B*2LL;
			A %= B;
			swap(A, B);
		}
		else{
			ans += (A / B)*B * 2LL;
			ans -= B;
			break;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
AB.sort(key=lambda x: x[1])

count = 0
c = 0
for (a, b) in AB:
    if a >= c:
        count += 1
        c = b

print(count)

Measured memory_bytes: 18248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  char a,b;cin>>a>>b;
  string ans;
  if(a<b){
    ans=string(b-'0',a);
  }else{
    ans=string(a-'0',b);
  }
  cout<<ans<<endl;
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    cout << (all_of(A.begin(), A.end(), [](ll x) { return x % 2 == 0; }) ? "second" : "first") << endl;
    return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;

cc N, K, i, j, k, A[500000], sub = 0, n = 0;
cc judge = 0, Ans, J[500000];

string S;


int main() {
	
	cin >> N;
	vector<pair<int, int>>pairs(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
		J[i] = i;
		pairs[i] = make_pair(A[i], J[i]);
	}
	sort(pairs.begin(), pairs.end());

	for (i = 0; i < N; i++) {
		if (pairs[i].second != i)
			sub += 1;
	}
	if (sub > 2)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;

		return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n;
    string s1, s2;
    cin >> n >> s1 >> s2;

    int i;
    ll ans;
    bool tate;
    if (s1[0] == s2[0]) {
        i = 1;
        ans = 3;
        tate = true;
    } else {
        i = 2;
        ans = 6;
        tate = false;
    }
    while (i < n) {
        if (s1[i] == s2[i]) {
            if (tate) {
                ans *= 2;
                ans %= MOD;
            }
            tate = true;
            i++;
        } else {
            if (tate) {
                ans *= 2;
                ans %= MOD;
            } else {
                ans *= 3;
                ans %= MOD;
            }
            tate = false;
            i += 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	double x[4];
	double y[4];

	while (true)
	{
		for (int i = 0; i < 4; i++)
		{
			if (!(cin >> x[i] >> y[i])) return 0;
		}

		if (x[0] > x[3]) cout << "NO" << endl;
		else if (x[1] < x[2]) cout << "NO" << endl;
		else if (y[0] > y[3]) cout << "NO" << endl;
		else if (y[1] < y[2]) cout << "NO" << endl;
		else cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
using namespace std;
typedef long long ll;
int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  int ans = 0;
  repi(i,1,3){
  int n = a[i]-a[i-1];
  ans += n;
  }
  cout << ans << endl;
  
  return 0;
}
    

Measured memory_bytes: 256
# ball and boxes2
from math import factorial
def P(n,r):
    return factorial(n)//factorial(n-r)
def C(n,r):
    return P(n,r)//factorial(r)

n, k = map(int, input().split())
print(P(k,n)%(pow(10,9)+7) if k >= n else 0)


Measured memory_bytes: 5664
/* {{{ Definitions */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ios>
#include <utility>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
/* }}}------------------------------------------- */
int n, a[20], b[20], c[20];
int ans;
void solve(){
	rep(i, n - 1){
		if(a[i] == a[i + 1] - 1){
			ans += c[a[i] - 1];
		}
	}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i, n){
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
		ans += b[i];
	}
	rep(i, n - 1) {
		cin >> c[i];
	}
		solve();
	return 0;
}


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

const int INF = (int)1e8;

struct Edge {
  // type = 0 -> land
  // type = 1 -> sea
  int from, to, cost, type;
  Edge(int from_, int to_, int cost_, int type_) : from(from_), to(to_), cost(cost_), type(type_) { }
};

int main() {
  while(true) {
    int N, M; cin >> N >> M;
    if(N == 0 && M == 0) break;
    vector<Edge> G;
    for(int i = 0; i < M; ++i) {
      int x,y,t;
      char sl;
      cin >> x >> y >> t >> sl;
      --x; --y;
      G.emplace_back(x,y,t,sl=='S');
    }
    int R; cin >> R;
    vector<int> Z;
    for(int i = 0; i < R; ++i) {
      int z; cin >> z;
      --z;
      Z.push_back(z);
    }
    int dl[N][N];
    int ds[N][N];
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
        dl[i][j] = INF;
        ds[i][j] = INF;
      }
      dl[i][i] = 0;
      ds[i][i] = 0;
    }
    for(int i = 0; i < M; ++i) {
      if(G[i].type == 0) {
        dl[G[i].from][G[i].to] = min(dl[G[i].from][G[i].to], G[i].cost);
        dl[G[i].to][G[i].from] = min(dl[G[i].to][G[i].from], G[i].cost);
      }
      else {
        ds[G[i].from][G[i].to] = min(ds[G[i].from][G[i].to], G[i].cost);
        ds[G[i].to][G[i].from] = min(ds[G[i].to][G[i].from], G[i].cost);
      }
    }
    for(int k = 0; k < N; ++k) {
      for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
          dl[i][j] = min(dl[i][j], dl[i][k] + dl[k][j]);
          ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
        }
      }
    }
    int d[R][N];
    for(int i = 0; i < R; ++i)
      for(int j = 0; j < N; ++j)
        d[i][j] = INF;
    d[0][Z[0]] = 0;
    for(int r = 0; r < R - 1; ++r) {
      for(int i = 0; i < N; ++i) {
        d[r+1][i] = min(d[r+1][i], d[r][i] + dl[Z[r]][Z[r+1]]);
        for(int j = 0; j < N; ++j) {
          d[r+1][j] = min(d[r+1][j], d[r][i] + dl[Z[r]][i] + ds[i][j] + dl[j][Z[r+1]]);
        }
      }
    }
    int ans = INF;
    for(int i = 0; i < N; ++i) {
      ans = min(ans, d[R-1][i]);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2692
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    char b;
    cin >> b;
    if (b == 'A') b = 'T';
    else if (b == 'T') b = 'A';
    else if (b == 'C') b = 'G';
    else b = 'C';
    cout << b << endl;
}

Measured memory_bytes: 256
from fractions import gcd
k = int(input())
check = [[1 for _ in range(k+3)] for i in range(k+3)]
for i in range(1, k+2):
    for j in range(1, k+2):
        check[i][j] = gcd(i, j)

result = 0
for s in range(1, k+1):
    for t in range(s, k+1):
        x = check[s][t]
        for u in range(t+1, k+1): 
            result += check[x][u]
result *= 6
result += k*(k+1)//2
print(result)

Measured memory_bytes: 76204
function main(input){
  const N=input.split('\n')[0];
  const grams = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));

  
  var sa=[];

  for(var T=1; T<N; T++){
    var group1=0;
  	var group2=0;
    for(var j=0; j<T; j++){
      group1+=grams[j]
    }
    for(var k=T; k<N; k++){
      group2+=grams[k]
    }
    sa.push(Math.abs(group1-group2))
  }

  console.log(Math.min.apply(null,sa));
}

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

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

class Program
{
    static void Main(string[] args)
    {
        int[] input = GetInputsInt();

        int[] hit = new int[input[0]];

        for (int i = 0; i < input[2]; i++)
        {
            hit[GetInputInt()-1]++;
        }

        int sum = hit.Sum();

        for (int i = 0; i < hit.Length; i++)
        {
            if(hit[i] + input[1] - sum > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }


        Console.ReadKey();
    }



    public static int GetInputInt()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] GetInputsInt()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static List<int> GetInputsIntList()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
    }
    public static List<float> GetInputsFloatList()
    {
        return Console.ReadLine().Split(' ').Select(float.Parse).ToList();
    }

    public static char[] GetInputChar()
    {
        return Console.ReadLine().ToCharArray();
    }

    public static long GetInputLong()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] GetInputsLong()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

}


Measured memory_bytes: 18012
import math
 
A, B = map(int, input().split())
ans = -1
 
for i in range(int(min(A/0.08, B/0.1)), 10001):
  if math.floor(i * 0.08) == A and math.floor(i * 0.10) == B:
    ans = i
    break
    
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}


int main(){
    string s;
    cin >> s;
    bool flag = true;
    int n = s.size();
    rep(i, n) {
        if (i >= n - i - 1) {
            break;
        }
        if (s[i] != s[n-i-1]) {
            flag = false;
        }
    }

    rep(i, (n - 1)/2) {
        if (i >= (n-1)/2 - 1 - i) {
            break;
        }
        if (s[i] != s[(n-1)/2 - 1 - i]) {
            flag = false;
        }
    }

    int ind = 0;
    REP(i, (n+3)/2-1, n) {
        if (i >= n-ind-1) {
            break;
        }
        if (s[i] != s[n-ind-1]) {
            flag = false;
        }
        ind+= 1;
    }

    yesno(flag);


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
int a,b,c,d,e,k;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b>>c>>d>>e>>k;
	bool f=false;
	if (b-a>k) f=true;
	if (c-a>k) f=true;
	if (d-a>k) f=true;
	if (e-a>k) f=true;
	if (c-b>k) f=true;
	if (d-b>k) f=true;
	if (e-a>k) f=true;
	if (d-c>k) f=true;
	if (e-c>k) f=true;
	if (e-d>k) f=true;
	if (f) cout<<":(";
	else cout<<"Yay!";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[5000001], invf[5000001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
ll invs[200020];
int n;
vector<int> g[200020];
int cnt[200020];
ll dp[200020];
void dfs(int x, int p){
	cnt[x]=1, dp[x]=1;
	for(auto y:g[x]){
		if(y==p) continue;
		dfs(y, x);
		cnt[x]+=cnt[y];
		(dp[x]*=dp[y])%=MOD;
	}
	(dp[x]*=invs[cnt[x]])%=MOD;
}
ll dp2[200020], ans[200020];
void dfs2(int x, int p){
	ans[x]=dp2[x]*f[n-1]%MOD*invf[n-cnt[x]]%MOD;
	for(auto y:g[x]){
		if(y==p) continue;
		dp2[y]=dp2[x]*dp[x]%MOD*inv(dp[y])%MOD*f[cnt[y]]%MOD*invf[cnt[x]-1]%MOD*invf[n-cnt[x]]%MOD*f[n-cnt[y]-1]%MOD;
		dfs2(y, x);
		ans[x]=ans[x]*dp[y]%MOD*invf[cnt[y]]%MOD;
	}
}
int main()
{
	cin>>n;
	for(int i=0; i<n-1; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fac(n);
	for(int i=1; i<=n; i++) invs[i]=inv(i);
	dfs(0, -1);
	for(int i=0; i<n; i++) (dp[i]*=f[cnt[i]])%=MOD;
	dp2[0]=1;
	dfs2(0, -1);
	for(int i=0; i<n; i++) cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 27636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int main() {
	int cnt[10] = {};
	for(int i=1;i<=3;i++) {
		int x, y; scanf("%d%d", &x, &y);
		cnt[x]++; cnt[y]++;
	}
	int mx = *max_element(cnt, cnt + 10);
	if(mx == 3) puts("NO");
	else puts("YES");
	return 0;
}


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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

long long dp[1000005][2];

void solve() {
    string s; cin >> s;
    s = '0' + s;

    dp[0][1] = 1;

    for (int i = 1; i < s.size(); i++) {

        int d = s[i] - '0';

        // 下の桁へおつりなし
        // min(上の桁からおつりなし, 上の桁からおつりあり)
        dp[i][0] = min(dp[i-1][0] + d, dp[i-1][1] + (10 - d));

        // 下の桁へおつりあり
        // min(上の桁からおつりなし, 上の桁からおつりあり)
        dp[i][1] = min(dp[i-1][0] + (d + 1), dp[i-1][1] + (10 - d - 1));

    }

    cout << dp[s.size()-1][0] << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 20052
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool solve(int *A, int n, int pos, int target)
{
	if (0 == target) return true;
	if (pos >= n) return false;
	return solve(A, n, pos + 1, target) || solve(A, n, pos + 1, target - A[pos]);
}

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

	int A[20];
	int i = 0;
	while (i < n) cin >> A[i++];

	int target, q;
	cin >> q;

	while (cin >> target)
	{
		cout << (solve(A, n, 0, target) ? "yes" : "no") << endl;
	}

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  string ans = "";
  while (N != 0) {
    if (N % 2 != 0) {
      N --;
      ans = "1" + ans;
    }
    else ans = "0" + ans;
    N /= -2;
  }
  
  if (ans  == "") ans ="0";
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> v(h);
	for (int i = 0; i < h; i++) {
		cin >> v[i];
	}

	for (int i = 0; i < w + 2; i++) {
		cout << "#";
	}
	cout << endl;
	for (int i = 0; i < h; i++) {
		cout << "#";
		for (int j = 0; j < w; j++) {
			cout << v[i][j];
		}
		cout << "#" << endl;
	}
	for (int i = 0; i < w + 2; i++) {
		cout << "#";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

int main(void) {
    std::priority_queue<u_int> heights;
    
    for (u_int h, i = 0; i < 10; ++i) {
        std::cin >> h;
        heights.push(h);
    }
	
    for (u_int i = 0; i < 3; ++i) {
        std::cout << heights.top() << std::endl;
        heights.pop();
    }
    return 0;
}

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

count = 0

max = A[-1]
if max == 0:
	print(0)
	exit()

import math
V = [0]*(math.floor(math.log(max, 2))+1)

for i in range (0, N):
	B = A[i]
	vount = 0
	while B > 0:
		if B%2 == 0:
			B = B//2
			vount+=1			
		else:
			B = (B-1)//2
			V[vount]+=1
			vount+=1

for i in range (0, len(V)):
	count+=((V[i]*(N-V[i]))*(2**i))

print(count%(10**9+7))

Measured memory_bytes: 126920
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {

	in(ll, N, M);
	map<ll, ll> pref;
	vector<pair<ll, ll>> city;
	city.reserve(N);

	map<pair<ll, ll>, string> ans;

	loop(i, M) {
		in(ll, P, Y);
		city.push_back({ Y, P });
	}

	auto city_b = city;

	sort_v(city);

	for (auto ci : city) {
		auto Y = ci.first;
		auto P = ci.second;
		auto a = P * 1000000 + ++pref[P];
		auto as = to_string(a);
		string tmp;
		tmp.reserve(N);
		for (int t = 12 - as.size(); t--;)
			tmp += "0";
		ans[{Y, P}] = tmp + as;
	}

	for (auto c : city_b)
		out(ans[c]);

	return 0;
}


Measured memory_bytes: 21760
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a,b;
    cin>>a>>b;
    if (a==b)
        cout<<2*a<<endl;
    else
        cout<<2*max(a,b)-1<<endl;
}

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

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main(){
  int n;
  cin>>n;
  ll vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  if(n==1){
    cout<<vec[0]<<endl;
    return 0;
  }
  if(n<=100){
    ll ans=0;
    for(int i=0;i<n;i++){
      ll x=vec[(i+1)%n];
      for(int j=0;j<n;j++){
        if(i!=j){
          x=gcd(x,vec[j]);
        }
      }
      ans=max(ans,x);
    }
    cout<<ans<<endl;
    return 0;
  }      
  ll vecgcd[n];
  ll vecgcdb[n];
  vecgcd[0]=vec[0];
  for(int i=1;i<n;i++){
    vecgcd[i]=gcd(vecgcd[i-1],vec[i]);
  }
  vecgcdb[n-1]=vec[n-1];
  for(int i=n-2;i>=0;i--){
    vecgcdb[i]=gcd(vecgcdb[i+1],vec[i]);
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    if(i==0){
      ans=max(ans,vecgcdb[1]);
      continue;
    }
    if(i==n-1){
      ans=max(ans,vecgcd[n-1]);
      continue;
    }
    ans=max(ans,gcd(vecgcd[i-1],vecgcdb[i+1]));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5908
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,ten=100000,ten2;
  cin>>n;
  rep(i,n){
    ten+=ten/20;
    ten2=ten/1000*1000;
    if(ten!=ten2){
      ten2+=1000;
      ten=ten2;
    }
  }
  cout<<ten<<endl;
}

Measured memory_bytes: 3036
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define ins insert
#define nl cout<<"\n"
#define P 1000000007
#define N 100005
#define MOD(x) ((x%P)+P)%P
#define show(x) cout<<x<<" "
#define vec(v) loop(i,0,v.size()) show(v[i]); nl

int main()
{
	fastio();

	int n;
	cin>>n;

	double dp[n+1][2*n+1] = {};
	dp[0][n] = 1;

	double pr[n+1];
	loop(i,1,n+1)
		cin>>pr[i];

	loop(i,1,n+1)
	{
		loop(j,0,2*n+1)
		{
			double p = pr[i];
			double q = 1-p; 
			if(j)
				dp[i][j] += (p*dp[i-1][j-1]);
			if(2*n-j)
				dp[i][j] += (q*dp[i-1][j+1]);
		}
	}

	double ans = 0;
	loop(i,n+1,2*n+1)
		ans += dp[n][i];
	
	cout<<fixed<<setprecision(10);
	cout<<ans,nl;

	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 140928
import numpy as np

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = A[0]
    if 0 in A:
        ans = 0
    else:
        for i in A[1:]:
            ans *= i
            if ans > 1000000000000000000:
                ans = -1
                break
    print(ans)


Measured memory_bytes: 40008
#include<iostream> 
#include<utility>
#include<cmath>
#include<map>
#include<vector>

using namespace std;

map<int, int> enumpr(int n) {
    map<int, int> V;
    for (int i = 2; 1LL * i*i <= n; i++) while (n%i == 0) V[i]++, n /= i;
    if (n > 1) V[n]++;
    return V;
}

long long d756(int n) {
  if(n==1)
    return 0;
  map<int, int> prims;

  for(int i=1; i<=n;i++) {
    auto ep = enumpr(i);
    for(auto iter= ep.begin();iter != ep.end();iter++) {
      prims[iter->first] += iter->second;
    }
  }
  long long counter = 0;
  /*
  for(auto iter = prims.begin();iter != prims.end();iter++) {
    cout << iter->first << " -> " << iter->second << endl;
  }
  */

  for(int i=2;i<=n;i++) {
    if(74 <= prims[i])
      counter++;
  }

  for(int i=2;i<=n;i++) {
    for(int j=2;j<=n;j++) {
      if(i != j && 14 <= prims[i] && 4 <= prims[j])
	counter++;
    }
  }
  for(int i=2;i<=n;i++) {
    for(int j=2;j<=n;j++) {
      if(i != j && 24 <= prims[i] && 2 <= prims[j])
	counter++;
    }
  }
  for(int i=2;i<=n;i++) {
    for(int j=2;j<=n;j++) {
      for(int k=j+1;k<=n;k++) {
	if (i != j && i != k && 2 <= prims[i] && 4 <= prims[j] && 4 <= prims[k])
	  counter++;
      }
    }
  }
  return counter;
}

int main() {
  int n;
  cin >> n; 
  cout << d756(n);
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC143B()
{
	int N;
	cin >> N;
	vi d(N);
	for(auto& x : d)
		cin >> x;

	ll sum = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			sum += d[i] * d[j];
		}
	}
	cout << sum << endl;
}

int main()
{
	ABC143B();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstdio>
using ll = long long;
using namespace std;
int main(){
    string str;
    int flag=0;
    cin >> str;
    for(int i=0;i<str.size();i++){
        if(i==0){
            if(str[i]!='A'){
                cout << "WA\n";
                return 0;
            }
        }
        else if(i>=2&&i<=int(str.size())-2){
            if(str[i]=='C') flag++;
            else if(str[i]<'a'||str[i]>'z') {
                cout << "WA\n";
                return 0;
               }
        }
        else{
            if(str[i]<'a'||str[i]>'z') {
                cout << "WA\n";
                return 0;
            }
        }
    }
    if(flag==1){
        cout << "AC\n";
    }
    else{
        cout << "WA\n";
    }
    return 0;
}


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

int main()
{
	long long n, k;
	cin >> n >> k;

	if (k == 1) {
		long long ret = LLONG_MAX;
		for (long long i = 0; i < n; ++i) {
			long long temp;
			cin >> temp;
			ret = min(ret,abs(temp));
		}
		cout << ret << endl;
		return 0;
	}

	long long zpos = -1;
	vector<long long> v(n);
	for (long long i = 0; i < n; ++i) {
		cin >> v[i];
		if (0 < i && v[i-1] <= 0 && 0 < v[i]) {
			zpos = i - 1;
		}
	}

	if (0 <= v[0]) {
		zpos = 0;
	}
	else if (v[n - 1] <= 0) {
		zpos = n-1;
	}

	long long ml = zpos - k + 1;
	long long mr = zpos;
	if (ml < 0) {
		mr += -ml;
		ml = 0;
	}

	long long ret = 0;
	if (v[ml] < 0 && v[mr] <= 0) {
		ret = - v[ml];
	}
	else if (0 <= v[ml] && 0 < v[mr]) {
		ret = v[mr];
	}
	else {
		ret = min(- v[ml] * 2 + v[mr], - v[ml] + v[mr] * 2);
	}

	++ml;
	++mr;
	while (v[ml] <= 0 && mr < n) {
		ret = min(ret, - v[ml] * 2 + v[mr]);
		ret = min(ret, - v[ml] + v[mr] * 2);
		++ml;
		++mr;
	}
	if (0 < v[ml] && mr < n) {
		ret = min(ret, v[mr]);
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+6;
const ll MOD=1e9+7;
const int Seed=1e7+7;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
string s[2000];
map<string,int> mp;
int main(){
    int n;
    sf(n);
    for(int i=1;i<=n;i++){
        cin >> s[i];
        if(mp[s[i]]){
            cout <<"No"<<endl;
            return 0;
        }
        mp[s[i]]++;
    }
    for(int i=2;i<=n;i++){
        if(s[i][0]!=s[i-1][(int)s[i-1].size()-1]){
            cout <<"No"<<endl;
            return 0;
        }
    }
    cout <<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int l, n;
    cin >> l >> n;
    int tmp = 0;
    rep(i, 0, n){
        int x, w;
        cin >> x >> w;
        tmp += x * w;
    }
    if(tmp == 0) cout << 0 << endl;
    else cout << 1 << endl << (tmp > 0 ? -1 : 1) << " " << abs(tmp) << endl;
}

Measured memory_bytes: 3104
// B. Backfront

#include <sstream>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	int n, mx = 0;
	cin >> n;
	vector<int> cnt(n + 1);
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		cnt[a] = cnt[a - 1] + 1;
		mx = max(mx, cnt[a]);
	}
	int ans = n - mx;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>

typedef long long ll;

int main() {
  int R, G, B, N, ans = 0;
  cin >> R >> G >> B >> N;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      int rmd = N - (R * i + G * j);
      if (rmd >= 0 && rmd % B == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M+1];
        int[] R = new int[M+1];
        int[] countID = new int[N+1];
        int under = 0;
        int upper = N;

        for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        }
        sc.close();

        // for(int i=1; i<=M; i++){
        //     for(int j=L[i]; j <= R[i]; j++){
        //         countID[j]++;
        //     }
        // }

        int ans = upper - under + 1;
        if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        }
        // for(int i=1; i<=N; i++){
        //     if(countID[i] == M){
        //         ans++;
        //     }
        // }
    }
}

Measured memory_bytes: 65012
#include <iostream>
using namespace std;
void sol(int N) {
	for (int i=1; i<=9; i++) {
		for (int j=1; j<=9; j++) {
			if (i*j==N) {
				cout << "Yes" << endl;
				return;
			}
		}
	}
	cout << "No" << endl;
	return;
}
int main () {
	int N;
	cin >> N;
	sol(N);
}

Measured memory_bytes: 3632
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    s = in_s()

    if s[-1] == "s":
        s += "es"
    else:
        s += "s"

    print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61872
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
inline int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int a, b, c, d;
int main() {
	cin >> a >> b >> c >> d;
	a = abs(a - c);
	b = abs(b - d);
	int g = gcd(a, b);
	cout << a + b - g << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<typename T>
struct SegmentTree{
private:
    int N;
    vector<T> node;
    function<T(T, T)> F;
    T E;
public:
    void init(int n, function<T(T, T)> f, T e, T def){
        F = f;
        E = e;
        N = 1;
        while(N < n) N = (N<<1);
        node.assign(2*N-1, e);
        for(int i=0; i<n; i++) node[N-1+i] = def;
        for(int i=N-2; i>=0; i--) node[i] = F(node[(i<<1)+1], node[(i<<1)+2]);
    }
    T& operator [](int a){
        return node[N-1+a];
    }
    void update(int a, T x){
        a += N-1;
        node[a] = x;
        while(a > 0){
            a = (a-1)>>1;
            node[a] = F(node[(a<<1)+1], node[(a<<1)+2]);
        }
    }
    T query(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1) r = N;
        if(b <= l || r <= a) return E;
        if(a <= l && r <= b) return node[k];
        return F(query(a, b, (k<<1)+1, l, (l+r)>>1), query(a, b, (k<<1)+2, (l+r)>>1, r));
    }
};

string S;
deque<int> que[26];
SegmentTree<int> st;

signed main(){
    cin >> S;
    rep(i, S.size()){
        que[S[i]-'a'].pb(i);
    }

    int cnt = 0;
    rep(i, 26){
        cnt += que[i].size()%2;
    }
    if(cnt != S.size()%2){
        cout << -1 << endl;
        return 0;
    }

    st.init(S.size(), [](int a, int b){ return a+b; }, 0, 0);

    ll ans = 0;
    rep(i, S.size()/2){
        int idx = -1;
        int c = 1e9;
        rep(j, 26){
            if(que[j].size() < 2) continue;
            int a = que[j].front();
            int b = que[j].back();
            if(c > a-st.query(0, a) + S.size()-1-b-st.query(b+1, S.size())){
                c = a-st.query(0, a) + S.size()-1-b-st.query(b+1, S.size());
                idx = j;
            }
        }
        ans += c;
        st.update(que[idx].front(), 1);
        que[idx].pop_front();
        st.update(que[idx].back(), 1);
        que[idx].pop_back();
    }
    cout << ans << endl;
}

Measured memory_bytes: 6532
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        string karifie[8];
        int fie[8][8];
        for(int i=0;i<8;i++){
            if(!(cin>>karifie[i]))goto exit;
        }
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++)fie[i][j]=karifie[i][j]-'0';
        }
        char ans;
        for(int i=0;i<7;i++){
            for(int j=0;j<7;j++)if(fie[i][j]&fie[i+1][j]&fie[i][j+1]&fie[i+1][j+1])ans='A';
        }
        for(int i=0;i<5;i++){
            for(int j=0;j<8;j++)if(fie[i][j]&fie[i+1][j]&fie[i+2][j]&fie[i+3][j])ans='B';
        }
        for(int i=0;i<8;i++){
            for(int j=0;j<5;j++)if(fie[i][j]&fie[i][j+1]&fie[i][j+2]&fie[i][j+3])ans='C';
        }
        for(int i=0;i<6;i++){
            for(int j=0;j<7;j++)if(fie[i+2][j]&fie[i+1][j]&fie[i][j+1]&fie[i+1][j+1])ans='D';
        }
        for(int i=0;i<7;i++){
            for(int j=0;j<6;j++)if(fie[i][j]&fie[i+1][j+2]&fie[i][j+1]&fie[i+1][j+1])ans='E';
        }
        for(int i=0;i<6;i++){
            for(int j=0;j<7;j++)if(fie[i][j]&fie[i+1][j]&fie[i+2][j+1]&fie[i+1][j+1])ans='F';
        }
        for(int i=0;i<7;i++){
            for(int j=0;j<6;j++)if(fie[i][j+2]&fie[i+1][j]&fie[i][j+1]&fie[i+1][j+1])ans='G';
        }
        cout<<ans<<endl;
    }
exit:
    return 0;
}

Measured memory_bytes: 1180
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    long long n, m, a[100], b[100], c[100], d[100], x[100];
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    for(int j = 0; j < m; j++)
    {
        cin >> c[j] >> d[j];
    }
 
    for(int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            x[j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        }
 
        int min = x[0];
        int k = 1; 
        for(int j = 0; j < m; j++)
        {
            if(min > x[j])
            {
                k = j + 1;
                min = x[j];
            }
        }
        cout << k << "\n";
    }
}

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

using namespace std;
using VI = vector<int>;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	int n;
	cin >> n;
	vector<double> v(n);
	IN(n, v);

	double ans = 0;
	SORT(v);

	FOR(0, n - 1)
	{
		v[i + 1] = ((v[i] + v[i + 1]) / 2);
	}

	cout << v[n - 1] << endl;
}

Measured memory_bytes: 256
tile_list = list(map(str, input()))

odd_diff_count = 0
even_diff_count = 0

for i in range(len(tile_list)):
    
    if i % 2 == 0:
        if tile_list[i] != "0":
            odd_diff_count += 1
        else:
            even_diff_count += 1
    else:
        if tile_list[i] != "1":
            odd_diff_count += 1
        else:
            even_diff_count += 1

if odd_diff_count >= even_diff_count:
    print(even_diff_count)
else:
    print(odd_diff_count)

Measured memory_bytes: 3956
N = int(input())
dp = [0] * (1 << N)
dp[0] = 1
MOD = 10 ** 9 + 7
now = {0}
for _ in range(N):
    mat = [1<<i for i, v in enumerate(input().split()) if v == '1']
    nxt = set()
    for k in now:
        p = dp[k] % MOD
        for m in mat:
            if k & m: # 1101 & 0100 3番目の人はすでにペアになっているためはじく
                continue
            dp[k | m] += p # 1001 | 0010 = 1011
            nxt.add(k | m)
    now = nxt
print(dp[-1] % MOD) #dp[11...11]が答えになる

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

int n;
int a[200000];

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	for (i = 0; i < n - 1; i++) if (a[i] == a[i + 1]) { cout << "NO" << endl; return 0; }
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
int deg[405],n,h;
bool e[405][405],u[405],ans=1,flag;
void dfs(int x){
	if (!u[x] || !ans) return;
	u[x]=0;
	if (x>h && deg[x]<0) ans=0;
	if (x<=h && deg[x]>0) ans=0;
	if (deg[x]) flag=1;
	for (int i=1;i<=h*2;i++)
		if (e[x][i]) dfs(i);
}
int main(){
	scanf("%d%d",&n,&h);
	for (int i=1;i<=n;i++){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a=c?-c+h+1:a+h;b=d?d+h:-b+h+1;
		deg[a]++;deg[b]--;
		e[a][b]=e[b][a]=u[a]=u[b]=1;
	}
	for (int i=1;i<=h*2 && ans;i++)
	if (u[i]){
		flag=0;dfs(i);
		if (!flag) ans=0;
	}
	if (ans) printf("YES\n");
		else printf("NO\n");
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
  -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

  int N;
  std::cin >> N;
  string C;
  std::cin >> C;

  int ans = 0;
  int i_back = N;
  REP(i, N) {
    if(C[i] == 'W') {
      while(i < i_back) {
        if(C[i_back] == 'R') {
          C[i_back] = 'W';
          ans++;
          break;
        }
        i_back--;
      }
    }
    if(i == i_back) break;
  }
  for(int i = i_back; i < N; i++) {
    if(C[i] == 'R') {
      ans++;
    }
  }
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 3776
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'

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

  int x, y, z, k; cin >> x >> y >> z >> k;
  vector<int64> a(x), b(y), c(z);
  rep(i, x) cin >> a[i]; rep(i, y) cin >> b[i]; rep(i, z) cin >> c[i];

  sort(rall(a)); sort(rall(b)); sort(rall(c));
  vector<int64> ans;

  vector<int64> ab;
  rep(i, x){
    rep(j, y) ab.push_back(a[i] + b[j]);
  }

  sort(rall(ab)); ab.resize(k);

  rep(i, k){
    rep(j, z) ans.push_back(ab[i] + c[j]);
  }


  sort(rall(ans));
  rep(i, k) print(ans[i]);

  return 0;
}

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

int main(){

    cout<<setprecision(9)<<fixed;

    int n,k; cin>>n>>k;

    double ans =0;

    for(int i=1; i<=n; i++){

        int count = 0;

        int com = i; 

        while( k > com ){
            count++;
            com *= 2;
        }

        ans += (1)/(double)n * pow((double)1/2,count);

    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())
import math
g = 1
if N ==1:
    print(P)
else:
    for i in range(1,int((P+1)**(1/N))+1):
        X = i**N
        if X > P:
            break
        else:
            if P % X == 0:
                g = i
    print(g)

Measured memory_bytes: 3060