akhauriyash/Code-Regression huggingface dataset:
input = str(input()).split(" ")
input = [int(x) for x in input]

a=input[0]
b=input[1]
x=input[2]

import math

##check situation
height = x/a/a
if height <= b/2:
    teihen_height = 2*x/a/b
    print(math.degrees(math.atan(b/teihen_height)))
elif height == b:
    print(0)
else:
    nokori_height = b - height
    print(90-math.degrees(math.atan(0.5*a/nokori_height)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long A, long long B, long long C)
{
    set<tuple<ll, ll, ll>> s;
    int ans = 0;
    vector<ll> tmp(3);
    tmp[0] = A;
    tmp[1] = B;
    tmp[2] = C;
    SORT(tmp);
    s.insert(make_tuple(tmp[0], tmp[1], tmp[2]));
    while (1)
    {
        if (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
        {
            ll tmpA = B / 2 + C / 2, tmpB = A / 2 + C / 2, tmpC = B / 2 + A / 2;
            A = tmpA;
            B = tmpB;
            C = tmpC;
            ans++;
            tmp[0] = A;
            tmp[1] = B;
            tmp[2] = C;
            SORT(tmp);
            if (s.find(make_tuple(tmp[0], tmp[1], tmp[2])) != s.end())
            {
                cout << -1 << endl;
                return;
            }
            else
            {
                s.insert(make_tuple(tmp[0], tmp[1], tmp[2]));
            }
        }
        else
        {
            cout << ans << endl;
            return;
        }
    }
}

int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());
        var input = ReadLine().Split();
        int m = 0;
        foreach (int i in EnumerableCommon.Range(n))
        {
            m += int.Parse(input[i]) - 1;
        }
        WriteLine(m);
        ReadLine();
    }


    public static partial class EnumerableCommon
    {
        public static IEnumerable<int> Range(int count)
        {
            return Enumerable.Range(0, count);
        }
    }
}

Measured memory_bytes: 13212
import java.util.Scanner;

object Main extends App {

  val sc = new Scanner(System.in);

  val n = sc.nextInt();
  val as = Array.fill(n)(sc.nextInt());

  val max = as.max;

  val ar = new Array[Boolean](max + 1);
  val at = new Array[Int](max + 1);

  (0 until n).foreach { i =>
    val a = as(i);
    (2 to (max / a)).foreach { j =>
      ar(j * a) = true;
    }
    at(a) = at(a) + 1;
  }

  val answer = (0 until n).count { i =>
    val a = as(i);
    !ar(a) && at(a) == 1;
  }

  println(answer);
}

Measured memory_bytes: 64796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

ll x;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>x;
	ll k=x/500;
	ll res=k*1000+(x-k*500)/5*5;
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  int ans = 0;
  int cnt = 1;
  while(cnt < B){
    cnt += A - 1;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   vector<int> v(n);
   rep(i, 0, n) cin >> v[i];
   sort(v.begin(), v.end());
   double ans = (v[0] + v[1]) / 2.0;
   rep(i, 2, n) ans = (ans + v[i]) / 2;
   printf("%0.6f\n", ans);
   return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  int Max=0;
  int Sum=0;
  for(int i=0; i<N; i++){
    cin >> P.at(i);
    Max=max(P.at(i), Max);
    Sum+=P.at(i);
  }
  cout << Sum-Max/2 << endl;
}
  

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

int main() {
  int L, R, A, B, C, D;
  
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> D;
  
  L = A + B;
  R = C + D;
  
  if (L > R){
    cout << "Left" <<endl;
  } else if (L == R){
    cout << "Balanced" <<endl;
  } else if (L < R){
    cout << "Right" <<endl;
  }
}

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

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);
  rep(i,N){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  vector<ll> F(N-K+1);
  rep(i,N-K+1){
    F.at(i)=A.at(K+i-1)-A.at(N-K-i);
  }//max-min,適切な係数をかける
  vector<ll> P(N-K+1);
  
  ll MAX=100000+10;
  vector<ll> fac(MAX), finv(MAX), inv(MAX);
  
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
  
  rep(j,N-K+1){
    P.at(j)=fac.at(K+j-1)*finv.at(K-1)%MOD;
    P.at(j)*=finv.at(j);
    P.at(j)%=MOD;
  }
  ll ans=0;
  rep(j,N-K+1){
    ans+=F.at(j)*P.at(j)%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
}





Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
using namespace std;
int main()
{
	long long INF = 10e15+7;
	long long N, W;
	cin >> N >> W;
	vector<pair<long long,long long>> coins(N);
	vector<long long> dp(100002,INF);
	for (long long i = 0; i < N; i++) {
		long long w, v;
		cin >> w >> v;
		coins[i] = { w,v };	
	
	}
	dp[0] = 0;
	for (auto coin : coins) {
		long long weight = coin.first;
		long long value = coin.second;
		for (int i = 100001; i >= 0; i--) {
			
			if (i >= value) {
				if (dp[i - value] != INF) {
					if (dp[i - value] == INF) {
						dp[i] = min(weight, dp[i]);
					}
					else dp[i] = min(dp[i - value] + weight, dp[i]);
				}
			}
		}
	}
	long long ans = 0;
	//for (int e : dp) { cout << e <<" "; ans++; }
	for (int i = 1; i <= 100001; i++) {
		if (dp[i] <= W) ans = i;
	}
	cout << ans;
 
	
}

Measured memory_bytes: 3672
N = gets.chomp.to_i
L = gets.chomp.split(' ').map(&:to_i).sort!

c = 0

N.times do |i|
  ((i+1)..(N-1)).each do |j|
    ((j+1)..(N-1)).each do |k|
      c += 1 if L[i] != L[j] && L[i] != L[k] && L[j] != L[k] && (L[i] + L[j]) > L[k]
    end
  end
end

puts c


Measured memory_bytes: 14316
encode = {
" ":"101",
"'":"000000",
",":"000011",
"-":"10010001",
".":"010001",
"?":"000001",
"A":"100101",
"B":"10011010",
"C":"0101",
"D":"0001",
"E":"110",
"F":"01001",
"G":"10011011",
"H":"010000",
"I":"0111",
"J":"10011000",
"K":"0110",
"L":"00100",
"M":"10011001",
"N":"10011110",
"O":"00101",
"P":"111",
"Q":"10011111",
"R":"1000",
"S":"00110",
"T":"00111",
"U":"10011100",
"V":"10011101",
"W":"000010",
"X":"10010010",
"Y":"10010011",
"Z":"10010000"
}
decode = {
"00000":"A",
"00001":"B",
"00010":"C",
"00011":"D",
"00100":"E",
"00101":"F",
"00110":"G",
"00111":"H",
"01000":"I",
"01001":"J",
"01010":"K",
"01011":"L",
"01100":"M",
"01101":"N",
"01110":"O",
"01111":"P",
"10000":"Q",
"10001":"R",
"10010":"S",
"10011":"T",
"10100":"U",
"10101":"V",
"10110":"W",
"10111":"X",
"11000":"Y",
"11001":"Z",
"11010":" ",
"11011":".",
"11100":",",
"11101":"-",
"11110":"'",
"11111":"?"
}
while True:
	try:
		list = raw_input()
	except EOFError:
		break
	code = ""
	for var in list:
		code += encode[var]
	
	if len(code) % 5 != 0:
		code += "0" * (5 - len(code) % 5)
	
	list = ""
	for i in range(0, len(code), 5):
		list += decode[code[i:i+5]]
	
	print list

Measured memory_bytes: 6316
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll x;
	cin>>x;
	ll ans=0;
	ans+=(x/500)*1000;
	x%=500;
	ans+=(x/5)*5;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 23680
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define MAX_N 200020
struct segtree {

	int n, dat[2 * MAX_N - 1];

	segtree(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		for (int i = 0; i < 2 * n - 1; i++) dat[i] = INF;
	}

	//k番目の値(0-indexed)をaに変更
	void update(int k, int a) {
		//葉の節点
		k += n - 1;
		dat[k] = a;
		//登りながら更新
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	//[a,b)の最小値を求める
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return dat[k];
		else {
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}
};
struct segtree_max {

	int n, dat[2 * MAX_N - 1];

	segtree_max(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		for (int i = 0; i < 2 * n - 1; i++) dat[i] = -INF;
	}

	//k番目の値(0-indexed)をaに変更
	void update(int k, int a) {
		//葉の節点
		k += n - 1;
		dat[k] = a;
		//登りながら更新
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	//[a,b)の最小値を求める
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return dat[k];
		else {
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return max(vl, vr);
		}
	}
};

int main(void) {
	int h,w,a,b;cin>>h>>w>>a>>b;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if(i < b == j < a)printf("0");else printf("1");
		}
		printf("\n");
	}
}

Measured memory_bytes: 1280
n = int(input())
l = list(map(int, input().split()))
b_count = 0
s_count = 1

for i in range(n):
  # l[1, 2, 3, ...] のうち l[0] == 0+1
  if l[i] == s_count:
    s_count += 1
  else:
    b_count += 1

if b_count == n:
  print(-1)
else:
  print(b_count)


Measured memory_bytes: 77516
#include<stdio.h>

int main(void){
   long int N,A,B,a,b;

   scanf("%ld%ld%ld",&N,&A,&B);
   a=N/(A+B)*A;
   b=N%(A+B);
   if(b>A)
     printf("%ld",a+A);
   else
     printf("%ld",a+b);
   return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e6+5;
ll n,m,p;
int main()
{
    scanf("%lld%lld",&n,&m);
    if(n*500>=m) printf("Yes\n");
    else printf("No\n");
    return 0;
}





Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int n;
	int cnt = 0;
	int x, y, z;
	scanf("%d", &n);

	for(int i = 1; i <= n; i++){
		for(x = 1; ; x++){
			if(x*x + 1 + 1 + x + 1 + x > i){
				break;
			}
				for(y = 1; ; y++){
					if(x*x + y*y + 1 + x*y + y + x > i){
						break;
					}
					for(z = 1; ; z++){
						if(x*x + y*y + z*z + x*y + y*z + x*z == i){
							cnt++;
						}else if(x*x + y*y + z*z + x*y + y*z + x*z > i){
							break;
						}
					}
				}
			}
		printf("%d\n", cnt);
		cnt = 0;
	}
}


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

int main(){
  cin.tie(0);
 	ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int b[k];
  for(int i = 0; i < k; i++){
    cin >> b[i];
  }
  for(int i = 0; i < (1 << k); i++){
    bitset<28> a(i);

    bitset<28> t(0);
    bool flag = true;
    for(int j = 0; j < 28; j++){
      if(flag){
        if(a[j]){
          t = (1 << b[j]);
          flag = false;
        }
      }else{
        if(a[j]){
          t |= (1 << b[j]);
        }
      }
    }
    cout << t.to_ulong() << ":";
    for(int j = 0; j < 28; j++){
      if(a[j]){
        cout << " " << b[j];
      }
    }
    cout << "\n";
  }
  return 0;
}



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

#define N 1000000

static int h[N + 1];

int main(void) {
  int p;
  
  for (;;) {
    int n, a, b;
    int res;
    
    scanf("%d%d%d", &n, &a, &b);
    if (n == 0 && a == 0 && b == 0) break ;
    memset(h, 0, sizeof(h));

    res = 0;    
    h[0] = 1;
    for (p = 0; p <= n; ++p) {
      if (h[p] == 0) {
        ++res;
        continue ;
      }
      if (p + a <= n)
        h[p + a] = 1;
      if (p + b <= n)
        h[p + b] = 1;
    }
    
    printf("%d\n", res);
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 4512
#include <iostream>
#include <math.h>
#include <stdio.h>

typedef long long ll;

using namespace std;

int main() {
  ll N;
  cin >> N;
  ll n = (ll)ceil((-1 + sqrt(1 + 8 * N)) / 2);
  ll d = n * (n + 1) / 2 - N;
  for (int i = 1; i <= n; ++i) {
    if (i != d) {
      printf("%d\n", i);
    }
  }
}


Measured memory_bytes: 3184
from sys import stdin
from itertools import combinations_with_replacement

def input():
    return stdin.readline().strip()


def main():
    N, M, Q = map(int, input().split())
    a, b, c, d = [0] * Q, [0]* Q, [0]* Q, [0]* Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
        a[i] -= 1
        b[i] -= 1

    ans = 0
    for seq in combinations_with_replacement(range(1, M + 1), N):
        score = 0
        for i in range(Q):
            if seq[b[i]] - seq[a[i]] == c[i]:
                score += d[i]

        ans = max(ans, score)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
int main(){
  int n; cin >> n;
  ll ans = 0;
  vector<ll> v(n+1);
  for(int i = 1; i <= n; i++){
    cin >> v[i];
  }
  for(int i = 1; i <=n; i++){
    ans += v[i]/2 * 2;
    v[i] = v[i]%2;
    if(i < n){
    if(v[i] != 0 && v[i+1] != 0){
      v[i]--,v[i+1]--;
      ans += 2;
    }
    }
  }
  cout << ans/2 << endl;
}

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

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    for(ll i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    ll ans=abs(v[0]-v[k-1]);
    for(ll i=1;i<=n-k;i++){
        ll tmp=abs(v[i]-v[i+k-1]);
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}
    

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin >>n;
  ll p=(ll)sqrt(n);
  ll ans=1000000007;
  for(ll i=1;i<=p;i++){
     if(n%i!=0) continue;
     ll k=n/i,sum=0;
     k=max(k,i);
      while(1){
        if(k==0) break;
        sum++;
        k/=10;
      }
      ans=min(sum,ans);
  }
  cout <<ans<<endl;

}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr ll MOD = 1000000007;

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll dp[100010][13];

int main(int argc, char* argv[]) {
  std::string s;
  std::cin >> s;
  dp[0][0] = 1;

  rep(i, 0, sz(s)) rep(m, 0, 13) {
    int first = (s[i] == '?' ? 0 : s[i] - '0');
    int last = (s[i] == '?' ? 10 : first + 1);
    rep(j, first, last) {
      int next_m = ((m * 10) + j) % 13;
      dp[i + 1][next_m] = (dp[i + 1][next_m] + dp[i][m]) % MOD;
    }
  }

  cout << dp[sz(s)][5] << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 10624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		scan.close();
		int g[]= {4,6,9,11};
		if(x==2||y==2)System.out.println("No");
		else {
			int cnt=0;
			for(int i=0;i<g.length;i++) {
				if(g[i]==x)cnt++;
				if(g[i]==y)cnt++;
			}
			if(cnt==2 || cnt==0)System.out.println("Yes");
			else if(cnt==1)System.out.println("No");
		}
	}
}

Measured memory_bytes: 22740
n, m = map(int, input().split())
a = list(map(int, input().split()))

needs = [10,2,5,5,4,5,6,3,7,6]
table = [-1] * (n + 10)
table[0] = 0

for i in range(n):
    if table[i] != -1:
        for number in sorted(a, reverse = True):
            matchs = needs[number]
            if table[i+matchs] == 0:
                table[i+matchs] = table[i] * 10 + number
            else:
                table[i+matchs] = max(table[i+matchs], table[i] * 10 + number)

print(table[n])

Measured memory_bytes: 14836
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long

using namespace std;

int f[1<<15][15],in[1<<15],e[15][15],n,m,all;

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
  return q*x;
}

int main(){
  n=gi(),m=gi(),all=1<<n;
  while (m--){
    RG int u=gi()-1,v=gi()-1,w=gi();
    e[u][v]=e[v][u]=w,in[(1<<u)|(1<<v)]+=w;
  }
  for (RG int i=1;i<all;i<<=1)
    for (RG int j=0;j<all;++j) if (j&i) in[j]+=in[j^i];
  memset(f,-0x3f,sizeof(f)),f[1][0]=0;
  for (RG int S=1;S<all;S+=2)
    for (RG int i=0;i<n;++i){
      if (f[S][i]<0) continue;
      for (RG int o=(all-1)^S,sub=o;sub;(--sub)&=o)
	f[S|sub][i]=max(f[S|sub][i],f[S][i]+in[sub|(1<<i)]);
      for (RG int k=0;k<n;++k)
	if (!(S>>k&1) && e[i][k]) f[S|(1<<k)][k]=max(f[S|(1<<k)][k],f[S][i]+e[i][k]);
    }
  cout<<in[all-1]-f[all-1][n-1]; return 0;
}


Measured memory_bytes: 2304
A, B, C = map(int, input().split())
a = A + B + C
ans = 0

if A == B == C and A % 2 == 0:
    print(-1)
else:
    while A % 2 == B % 2 == C % 2 == 0:
        A, B, C = (B + C) // 2, (A + C) // 2, (A + B) // 2
        ans += 1
    print(ans)

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

int main() {
  long long int n, sum = 0; cin >> n;
  long long int a[n*3];
  for (long long int i = 0; i < n*3; i++) cin >> a[i];
  sort(a, a+3*n);
  for (long long int i = n; i < n*3; i+=2) 
    sum += a[i];
  cout << sum << endl;
  return 0;
}
    

Measured memory_bytes: 2560
import java.util.*;

public class Main {

    /* チェックリスト
     * intの範囲を超えていないか
     * TLEしそうな処理の有無
     */
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] in = sc.nextLine().split(" ");
        List<Integer> ints = new ArrayList<Integer>();
        for(String str : in){
            ints.add(Integer.parseInt(str));
        }
        Collections.sort(ints);
        long r = 0;
        for(int ia = 0;ia < n;ia++){
            int a = ints.get(ia);
            for(int ib = ia + 1;ib < n;ib++) {
                int b = ints.get(ib);
                //検索開始位置
                int start = ib;
                //検索終了位置
                int end = ints.size();
                //目的の値 (これより小さい値を探す)
                int val = a + b ;
                while (end - start > 1) {
                    int mid = start + (end - start) / 2;
                    if (ints.get(mid) < val) {
                        start = mid;
                    } else {
                        end = mid;
                    }
                }
                int add = (end-1) -ib;
                r += add;
            }
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 23124
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Array.Sort(A);
		Array.Sort(B);
		
		for(int z = A[N-1] + 1; z <= B[0];z++){
			if(X < z && z <= Y){
				Console.WriteLine("No War");
				return;
			}
		}
		Console.WriteLine("War");
	}
	int N,M,X,Y;
	int[] A,B;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1]; X = d[2]; Y = d[3];
		A = ria();
		B = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,q,i,x,y,j,dp[3005][3005],p2[3005],ans=0,st[3005][3005],a[3005],u,v;
const ll mod=1e9+7;
int main()
{
	p2[0]=1;for(i=1;i<=3000;i++)p2[i]=p2[i-1]*2%mod;
	scanf("%lld%lld",&n,&q);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(a[i]==a[j])continue;
			if(a[i]>a[j])dp[j][i]++;
			else dp[i][j]++;
		}
	}
	for(i=1;i<=q;i++)
	{
		scanf("%lld%lld",&x,&y);
		for(j=1;j<=n;j++)
		{
			if(j==x||j==y)continue;
			u=dp[x][j]=dp[x][j]*p2[i-1-st[x][j]]%mod;st[x][j]=i;
			v=dp[y][j]=dp[y][j]*p2[i-1-st[y][j]]%mod;st[y][j]=i;
			dp[x][j]=(dp[x][j]+v)%mod;
			dp[y][j]=(dp[y][j]+u)%mod;
			u=dp[j][x]=dp[j][x]*p2[i-1-st[j][x]]%mod;st[j][x]=i;
			v=dp[j][y]=dp[j][y]*p2[i-1-st[j][y]]%mod;st[j][y]=i;
			dp[j][x]=(dp[j][x]+v)%mod;
			dp[j][y]=(dp[j][y]+u)%mod;
		}
		u=dp[x][y]=dp[x][y]*p2[i-1-st[x][y]]%mod;st[x][y]=i;
		v=dp[y][x]=dp[y][x]*p2[i-1-st[y][x]]%mod;st[y][x]=i;
		dp[x][y]=(dp[x][y]+v)%mod;
		dp[y][x]=(dp[y][x]+u)%mod;
	}
	for(i=1;i<=n;i++)for(j=1;j<i;j++)ans=(ans+dp[i][j]*p2[q-st[i][j]])%mod;
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 141184
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
using namespace std;
const int inf=1e9;

int tmp[100010];
int main() {
	int W, a[100010], ans=0;
	cin>>W;
	REP(i, 0, W) cin>>a[i];

	int t=0;
	REP(i,0,W){
		if(a[i]==0) t=inf;
		else if(a[i]<0) t=min(t,-a[i]);
		else tmp[i]=t;
		t--;
	}
	t=0;
	for(int i=W-1;i>=0;i--){
		if(a[i]==0) t=inf;
		else if(a[i]<0) t=min(t,-a[i]);
		else ans+=max(0,min(a[i],max(tmp[i],t)));
		t--;
	}

	p(ans);

	return 0;
}

Measured memory_bytes: 3844
def Input():
    data = list(map(int,input().split()))
    return data

def gcd(x, y):
    if x < y:
        temp = x
        x = y
        y = temp
    z = x % y
    if z == 0:
        return y
    return gcd(y, z)

data = Input()
print(gcd(data[0], data[1]))


Measured memory_bytes: 5600
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#define MAXN 2010
int n, m, head[MAXN], to[MAXN << 1], next[MAXN << 1], tot = 0;
inline void $(int u, int v) {
    next[tot] = head[u], to[tot] = v, head[u] = tot++;
    next[tot] = head[v], to[tot] = u, head[v] = tot++;
}
std::pair<int, int> path[MAXN];
std::vector<int> paths[MAXN], edges[MAXN];
bool dfs(int x, int y, int fa, int id) {
    if (x == y) return 1;
    for (int i = head[x]; ~i; i = next[i]) {
        if (to[i] == fa) continue;
        if (dfs(to[i], y, x, id)) {
            paths[i >> 1].push_back(id);
            edges[id].push_back(i);
            return 1;
        }
    }
    return 0;
}
int cnt[MAXN], vis[MAXN], have[MAXN << 1];
int main(int argc, char const *argv[]) {
    scanf("%d%d", &n, &m);
    memset(head, -1, sizeof(head));
    for (int i = 1, u, v; i < n; i++) scanf("%d%d", &u, &v), $(u, v);
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &path[i].first, &path[i].second);
        dfs(path[i].first, path[i].second, 0, i);
    }

    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        cnt[i] = paths[i].size();
        ans += std::min(2, cnt[i]);
    }
    for (int p, rev;;) {
        for (p = 0; p < n - 1; p++)
            if (cnt[p] == 1 && (have[p << 1] ^ have[p << 1 | 1])) break;
        if (p == n - 1) {
            for (p = 0; p < n - 1; p++)
                if (cnt[p]) break;
            if (p == n - 1) break;
        }
        while (vis[paths[p].back()]) paths[p].pop_back();
        int x = paths[p].back();
        rev = 0;
        for (auto y : edges[x]) {
            if ((y >> 1) == p) {
                if (have[y]) {
                    rev = 1;
                    std::swap(path[x].first, path[x].second);
                }
            }
        }
        for (auto y : edges[x]) {
            have[y ^ rev] = 1;
            cnt[y >> 1]--;
        }
        vis[x] = 1;
    }
    printf("%d\n", ans);
    for (int i = 1; i <= m; i++) printf("%d %d\n", path[i].first, path[i].second);
    return 0;
}


Measured memory_bytes: 13824
#include <stdio.h>
#include <stdlib.h>

int main(){
	int N;
	char S[10];
	scanf("%d", &N);
	printf("0\n");
	fflush(stdout);
	scanf("%s", S);
	if(S[0] == 'V'){
		return 0;
	}
	char l = S[0], r = S[0], h;
	int lnum = 0, rnum = N, hnum;
	for(;;){
		hnum = (lnum + rnum) / 2;
		printf("%d\n", hnum);
		fflush(stdout);
		scanf("%s", S);
		if(S[0] == 'V'){
			return 0;
		}
		h = S[0];
		if((((hnum - lnum) % 2) == 0 && h != l) || ((hnum - lnum) % 2 == 1) && h == l){
			r = h;
			rnum = hnum;
		}
		else{
			l = h;
			lnum = hnum;
		}
	}
}

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

int main(){
   string s , s1="" , s2="";
   cin >> s;
   int ans1 = 0 , ans2 = 0;
   int size = s.size();
   s1+='0'; s2+='1';
   for(int i = 1; i < size; i++){
      if(s1[i-1]=='0'){
         s1+='1';
      }
      else{
         s1+='0';
      }
      if(s2[i-1]=='0'){
         s2+='1';
      }
      else{
         s2+='0';
      }
   }
   for(int i = 0; i < size; i++){
      if(s[i] != s1[i]){
        ans1++;
      }
      if(s2[i]!=s[i]){
        ans2++;
      }
   }
   //cout << s1 << " " << s2 << endl;
   ans1 = min(ans1 , ans2);
   cout << ans1 << endl;
}

Measured memory_bytes: 768
def main():
    N = int(input())
    # N=1: {1}, {1} (1*2)
    # N=3: {1, 2}, {1, 3}, {2, 3} (2*3)
    # N=6: {1, 2, 3}, {1, 4, 5}, {2, 4, 6}, {3, 5, 6} (3*4)
    # N=10:{1, 2, 3, 4}, {1, 5, 6, 7}, {2, 5, 8, 9}, {3, 6, 9, 10}, {4, 7, 8, 10} (4*5)
    # N=n(n+1)/2のケース(n=1,2,...)で構成可能
    # 集合の数はn+1で要素数はn
    n = 1
    while n * (n + 1) < 2 * N:
        n += 1
    if n * (n + 1) != 2 * N:
        print('No')
        return
    ans = [list() for _ in range(n + 1)]
    num = 0
    for left in range(n):
        for right in range(left + 1, n + 1):
            num += 1
            ans[left].append(num)
            ans[right].append(num)
    print('Yes')
    print(len(ans))
    for li in ans:
        print('{} {}'.format(len(li), ' '.join(map(str, li))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 13920
import sys
def euler(a):
    i = 2
    res = a
    #standard = a
    while i * i <= a:
        if a % i == 0:
            res = res - res//i
            while a % i == 0:
                a //= i

        i += 1
    if a != 1:
        res = res - res//a

    return res


x = int(input())


print(euler(x))

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

using namespace std;

int main() {
int n;
cin>>n;
set<char> s;
for(int i=0;i<n;i++)
{
    char x;
    cin>>x;
    s.insert(x);
}
if(s.size()==1)
cout<<"One";
else if(s.size()==2)
cout<<"Two";
else if(s.size()==3)
cout<<"Three";
else cout<<"Four";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<int>>jobs(m);
    rep(i,n) {
        int a,b;
        cin>>a>>b;
        if(a>m) continue;
        jobs[m-a].push_back(b);
    }
    priority_queue<int> q;
    
    ll ans = 0;
    for(int i = m-1; i >=0; i--) {
        for(int b : jobs[i]) {
            q.push(b);
        }
        if(!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 8504
n=int(input())
a=list(map(int,input().split()))
m=max(a)
a.sort()
dp=[True]*(m+1)
h=dict()
for i in a:
    if i not in h:
        h[i]=1
    else:
        h[i]+=1
    j=2
    while j*i<=m:
        dp[i*j]=False
        j+=1
ans=0
for i in a:
    if dp[i]==True and h[i]==1:
        ans+=1
print(ans)
    

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int h,w,k; cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];

    int ans = 0;
    rep(s, 1<<h) rep(t, 1<<w){
        int count = 0;
        rep(i, h) rep(j, w){
            if(s & (1<<i) || t & (1<<j) || c[i][j] == '.') continue;
            count++;
        }
        if(count == k) ans++;
    }
    out(ans);
}

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void) {
  int n;
  double xa, ya, ra, xb, yb, rb, d;
  cin >> n;

  while (n--) {
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    d = sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));
    if (d > (ra + rb)) cout << "0";
    else if (d < (rb - ra)) cout << "-2";
    else if (d < (ra - rb)) cout << "2";
    else cout << "1";
    cout << endl;
  }

  return 0;
}

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

using namespace std;

int main(){
	int H, N, count;
  	cin >> H >> N;
  	vector<int> A(N);
  	for(int i = 0; i < N; i++)
      cin >> A[i];
  	sort(A.begin(), A.end());
  	while(count < N){
    	H -= A.at(count);
      	if(H <= 0){
        	cout << "Yes" << endl;
          	return 0;
        }
      	count++;
    }
  	cout << "No" << endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] data = new int[n];
    long sum = 0;

    for(int i = 0;i < n;i++) {
      data[i] = sc.nextInt();
    }

    for(int i = 0;i < n;i++) {
      for(int j = i+1;j < n;j++) {
        sum += data[i] * data[j];
      }
    }

    System.out.println(sum);

  }

}


Measured memory_bytes: 25044
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0); 
  double d;
  cin >> d;
  cout << setprecision(20) << fixed << max(d * sqrt(2), floor(d) + 1) << endl;
  return 0;
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;
	cin >> s;
	int a,b,c,d;
	char op[2];
	op[0] = '+';
	op[1] = '-';

	a = s[0] - '0';
	b = s[1] - '0';
	c = s[2] - '0';
	d = s[3] - '0';
	int q1,q2,q3,ans;
	for (int i = 0;i <= 1;i++){
		if (i == 0){
			q1 = a+b;
		}
		else{
			q1 = a - b;
		}
		for(int j = 0 ;j <= 1;j++){
			if (j == 0){
				q2 = q1+c;
			}
			else{
				q2 = q1 - c;
			}
			for(int k = 0;k <= 1;k++){
				if (k == 0){
					q3 = q2+d;
				}
				else{
					q3 = q2 - d;
				}
				if (q3 == 7){
					cout << a << op[i] << b <<op[j] << c << op[k] << d << "=7" << endl;
					exit(0);
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll n,m;
ll d[MAXn];
int main(){
  IOS();
  cin >> n >> m;
  REP (i,m) cin >> d[i];
  sort(d,d+m);
  pary(d,d+m);

  vector<ll> diff;
  REP (i,m-1) diff.eb(d[i+1]-d[i]);
  sort(ALL(diff));

  ll tmp = max(0LL,m-n);

  ll ans = 0;
  REP (i,tmp) ans += diff[i];
  cout << ans << endl;
}


Measured memory_bytes: 2168
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

const int max_n = 200010;

int main()
{
  cin.tie(0);
  ll n;
  cin >> n;
  ll a[max_n];
  ll sum[max_n];
  ll sumxor[max_n];
  sum[0] = 0;
  sumxor[0] = 0;
  for (ll i = 0; i < n; i++)
  {
    cin >> a[i];
    sum[i + 1] = sum[i] + a[i];
    sumxor[i + 1] = sumxor[i] ^ a[i];
  }
  ll ans = 0;
  ll i = 0;
  ll j = 1;
  while (i < n)
  {
    if (i != j && sum[j] - sum[i] == (sumxor[j] ^ sumxor[i]))
    {
      ans++;
      j++;
      if (j > n)
      {
        ans += (j - i - 1) * (j - i - 2) / 2;
        break;
      }
    }
    else
    {
      i++;
      ans += j - i - 1;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    ll n;
    cin >> n;
    string s;
    cin >> s;

    vector<ll> red;
    vector<ll> green;
    vector<ll> blue;

    for (ll i=0;i<=n-1;i++)
    {
        if (s[i]=='R')
        {
            red.push_back(i+1);
        }
        else if (s[i]=='G')
        {
            green.push_back(i+1);
        }
        else if (s[i]=='B')
        {
            blue.push_back(i+1);
        }
    }


    ll ans=0;
    sort(blue.begin(),blue.end());
    for (auto it=red.begin();it!=red.end();it++)
    {
        for (auto it2=green.begin();it2!=green.end();it2++)
        {
            ll a=*it;
            ll b=*it2;

            ll val=0;
            if ((binary_search(blue.begin(),blue.end(),(a+b)/2))&&((a+b)%2==0))
            {
                val++;
            }
            if (binary_search(blue.begin(),blue.end(),(2*a)-b))
            {
                val++;
            }
            if (binary_search(blue.begin(),blue.end(),(2*b)-a))
            {
                val++;
            }

            ll local=blue.size()-val;
            ans=ans+local;
        }
    }

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


Measured memory_bytes: 3636
#define u for(j=0;j<n;++j)
a[5][1<<18],b[2],x,y,j,n;main(i){scanf("%d",&n);for(;++i<5;)u{scanf("%d",&a[i][j]);--a[i][j];}u{if(a[2][j]%3)++b[1-j%2];if(a[2][j]/3-a[3][j]/3||a[3][j]/3-a[4][j]/3||a[4][j]/3-a[2][j]/3||a[3][j]%3-1||a[3][j]/3-j&1){b[0]=1;break;}x=y=a[3][j]/3+1;for(;x;x-=x&-x)b[j&1]-=a[j&1][x]%2;b[j&1]+=j/2;for(;y<2e5;y+=y&-y)++a[j&1][y];}puts(b[0]&1|b[1]&1?"No":"Yes");}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

signed main(){
	int k;
	cin>>k;
	int a[100010];
	rep(i,k)cin>>a[i];
	P b[100010];
	b[k]=P(2,2);
	bool ok=true;
	for(int i=k-1;i>=0;i--){
		if(b[i+1].second-b[i+1].first>=a[i]||b[i+1].first%a[i]==0||b[i+1].second%a[i]==0||b[i+1].first%a[i]>b[i+1].second%a[i]){
			b[i].first=(b[i+1].first+a[i]-1)/a[i]*a[i];
			b[i].second=(b[i+1].second)/a[i]*a[i]+a[i]-1;
			//cout<<b[i].first<<" "<<b[i].second<<endl;
		}else{
			ok=false;
			break;
		}
	}
	if(ok)cout<<b[0].first<<" "<<b[0].second<<endl;
	else cout<<-1<<endl;
}



Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int A[1000000], n;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}

	int q, k, sum = 0;
	cin >> q;
	for (int i= 0; i < q; i++) {
		scanf("%d", &k);

		if (*lower_bound(A, A + n, k) == k)sum++;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3424