akhauriyash/Code-Regression huggingface dataset:
N = int(input())
B = [int(i) for i in input().split()]

A = []
for _ in range(N):
    for i in range(len(B) - 1, -1, -1):
        if i + 1 == B[i]:
            p = B.pop(i)
            A.append(p)
            break
        
A.reverse()
if B != []:
    print(-1)
else:
    for a in A:
        print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,k;
    cin >> a >> b >> k;
    vector<int> ans;
    for(int i=1;i<=max(a,b);i++){
        if(a%i==0 && b%i==0){ans.push_back(i);}
    }
    cout << ans[ans.size()-k] << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
f = [i for i in range(1, m + 1)]
for i in range(n):
  a = list(map(int, input().split()))
  k = a[0]
  a = a[1:]
  f = set(f) & set(a)
f = list(f)
print(len(f))

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
  string A,B;
  cin >> A >> B;
  if(A.size() > B.size())
    cout << "GREATER" << endl;
  if(A.size() < B.size())
    cout << "LESS" << endl;
  if(A.size() == B.size()){
    for(int i=0; i < A.size(); i++){
      if(A[i] > B[i]){
	cout << "GREATER" << endl;
	break;
      }
      else if(A[i] < B[i]){
	cout << "LESS" << endl;
	break;
      }
      if(i == A.size()-1)
	cout << "EQUAL" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vec<int> a(N);
  REP(i, N) cin >> a[i];
  int maxV = *max_element(ALL(a));
  int minV = *min_element(ALL(a));
  // print(N);
  // print(minV);
  int diff = maxV - minV;
  if (diff == 0) {
    if (N >= 2 * minV || N == minV + 1) {
      print("Yes");
    } else {
      print("No");
    }
  } else if (diff == 1) {
    // int c = minV;
    int cnt = count(ALL(a), minV);
    int col = minV + 1 - cnt;
    if (col <= 0) {
      print("No");
      return 0;
    }
    // 2人以上のグループの色数
    if (N - cnt >= 2 * col) {
      print("Yes");
    } else {
      print("No");
    }
  } else {
    print("No");
  }
}

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

using namespace std;

using Image = vector<string>;

Image ReadImage(int size)
{
    Image image(size);
    for (auto &row : image) {
        getline(cin, row);
    }
    return image;
}

bool ContainsAt(const Image &big, int x, int y, const Image &small)
{
    int n = small.size();
    for (int i = 0; i < n; i += 1) {
        for (int j = 0; j < n; j += 1) {
            if (small[i][j] != big[x + i][y + j]) {
                return false;
            }
        }
    }
    return true;
}

bool Contains(const Image &big, const Image &small)
{
    int n = big.size();
    int m = small.size();

    for (int i = 0; i + m <= n; i += 1) {
        for (int j = 0; j + m <= n; j += 1) {
            if (ContainsAt(big, i, j, small)) {
                return true;
            }
        }
    }
    return false;
}

int main()
{
    int n, m;
    cin >> n >> m;
    cin.get();

    auto big = ReadImage(n);
    auto small = ReadImage(m);

    cout << (Contains(big, small) ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double L = sc.nextInt();
		double volume = (L/3)*(L/3)*(L/3);
		System.out.println(volume);
	}
 
 
 
}

Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

bool judge(ll nowK,ll A){
  bool flag=true;
  REP(i,30){
    ll mask=1<<(29-i);
    if((!(mask&nowK)) && (mask&A))flag=false;
  }
  return flag;
}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N,K;
  cin>>N>>K;
  // 真に小さくなる位置
  vector<ll>A(N),B(N);
  REP(i,N)cin>>A[i]>>B[i];

  ll ans=0;
  REP(j,N){
    if(judge(K,A[j]))ans+=B[j];
  }
  REP(i,30){
    ll su=0;
    // 上からi桁目について立ってないときは考えない
    if((1<<(29-i))&K){
      //上からi桁目で0になって、以降すべて1のものの値を求める
      ll nowK=(K-(1<<(29-i)))|((1<<(29-i))-1);
      //nowKに対して使えるかどうか調べていく
      REP(j,N){
        if(judge(nowK,A[j]))su+=B[j];
      }
    }
    chmax(ans,su);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
import itertools

N = int(input().split()[0])
d_list = list(map(int, input().split()))
p_gen = itertools.combinations(d_list, 2)
total = 0
for p in p_gen:
    a, b = p
    total += a * b
ans = total
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[110000];
long long dp[110000];
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int main(){
	scanf("%s",in);
	int n=strlen(in);
	for(int i=1;i<110000;i++){
		dp[i]=(dp[i-1]*3+pw(3,i-1))%mod;
	}
	int LA=0;
	int LH=0;
	int RC=0;
	int RH=0;
	for(int i=0;i<n;i++){
		if(in[i]=='C')RC++;
		if(in[i]=='?')RH++;
	}
	long long ret=0;
	for(int i=0;i<n;i++){
		if(in[i]=='C')RC--;
		if(in[i]=='?')RH--;
		if(in[i]=='B'||in[i]=='?'){
			ret=(ret+(LA*pw(3,LH)%mod+dp[LH])%mod*(RC*pw(3,RH)%mod+dp[RH])%mod)%mod;
	//		printf("%lld\n",ret);
		}
		if(in[i]=='A')LA++;
		if(in[i]=='?')LH++;
	}
	printf("%lld\n",ret);
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int k,s;cin>>k>>s;
    int cnt=0;
    rep(i,k+1){
        rep(j,k+1){
            if((s-i-j)<=k&&(s-i-j)>=0)cnt++;
        }
    }
    cout<<cnt<<endl;
}

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

int main(){

  int N;
  cin >> N;
  std::vector<int> seito(N);
  std::vector<int> junban(N);
  for(int i=0;i<N;++i) cin >> seito[i];

  for(int i=0;i<N;++i){
    junban[seito[i]-1] = i+1;
  }

  for(int i=0;i<N-1;++i){
    cout << junban[i] << " ";
  }
  cout << junban[N-1] << endl;

  return 0;
}


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

int main(){
  string s;
  cin >> s;
  if (s == "RRR") cout << "3" << endl;
  if (s == "SRR") cout << "2" << endl;
  if (s == "RSR") cout << "1" << endl;
  if (s == "RRS") cout << "2" << endl;
  if (s == "SSR") cout << "1" << endl;
  if (s == "SRS") cout << "1" << endl;
  if (s == "RSS") cout << "1" << endl;
  if (s == "SSS") cout << "0" << endl;
  return 0;
}

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

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

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

    int max = 0, ans = 1;

    for (int i = 1; i <= n; i++) {
        int num = 0, a = i;
        while (a % 2 == 0) {
            a /= 2;
            num++;
        }
        if (max < num) {
            ans = i; 
            max = num;
        }
    }

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


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

const int MOD = (int)1e9+7;

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

	if(N<=9)	cout << N << endl;
	else if(N<=99)	cout << 9 << endl;
	else if(N<=999)	cout << 9+N-99 << endl;
	else if(N<=9999)	cout << 9+1000-100 << endl;
	else if(N<=99999)	cout << 9+1000-100+N-9999 << endl;
	else	cout << 90909 << endl;

	return 0;
}


Measured memory_bytes: 768
using System;
class Program
{
    static IO io = new IO();

    static void Main(string[] args)
    {
        io.Read();
        long X = io.Long();

        int i = (int) Math.Ceiling((-1 + Math.Sqrt(1 + 8 * X)) / 2);
        io.Write(i.ToString());

    }
}

class IO
{
    private string[] input;
    private int index;
    public void Read()
    {
        input = new string[1];
        input[0] = Console.ReadLine();
        index = -1;
    }
    public void ReadSplit()
    {
        input = Console.ReadLine().Split(' ');
        index = -1;
    }
    public string String()
    {
        index += 1;
        return input[index];
    }
    public string[] String(int count)
    {
        index += 1;
        string[] rv = new string[count];
        Array.Copy(input, index, rv, 0, count);
        return rv;
    }
    public int Int()
    {
        index += 1;
        return int.Parse(input[index]);
    }
    public int[] Int(int count)
    {
        index += 1;
        int[] rv = new int[count];
        for (int i = 0; i < count; ++i)
        {
            rv[i] = int.Parse(input[index + i]);
        }
        return rv;
    }
    public long Long()
    {
        index += 1;
        return long.Parse(input[index]);
    }
    public long[] Long(int count)
    {
        index += 1;
        long[] rv = new long[count];
        for (int i = 0; i < count; ++i)
        {
            rv[i] = long.Parse(input[index + i]);
        }
        return rv;
    }
    public void Write(string str)
    {
        Console.WriteLine(str);
    }
}

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

using namespace std;

typedef long long ll;
int main()
{
	int n; cin >> n;
	vector<ll> arr(n);
	for(int i = 0; i < n; i++) cin >> arr[i];
	sort(arr.rbegin(), arr.rend());
	ll ans = 0;
	int k = n-2;
	ans += arr[0];
	for(int i = 1; i < n && k; i++){
		if(k == 1){
			ans += arr[i];
			k--;
		}else{
			ans += arr[i]*2;
			k -= 2;
		}
	}
	cout << ans;
}


Measured memory_bytes: 4844
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
LL n, a, b;

int main() {
	scanf("%lld%lld%lld", &n, &a, &b);
	n -= 2;
	if(a > b || (n < 0 && a != b)){
		printf("0\n");
		return 0;
	}
	if(a == b) {
		printf("1\n");
		return 0;
	}
	LL Min = a * n;
	LL Max = b * n;
	printf("%lld\n", Max - Min + 1);
	return 0;
}

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

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

    ll sum = 0;
    for(int i=0;i<n.size();i++){
        if(n[i] == '0') sum += 0;
        if(n[i] == '1') sum += 1;
        if(n[i] == '2') sum += 2;
        if(n[i] == '3') sum += 3;
        if(n[i] == '4') sum += 4;
        if(n[i] == '5') sum += 5;
        if(n[i] == '6') sum += 6;
        if(n[i] == '7') sum += 7;
        if(n[i] == '8') sum += 8;
        if(n[i] == '9') sum += 9;
    }

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


Measured memory_bytes: 3752
#include <iostream>

using namespace std;

int main() {
    int n, ac = 0, wa = 0, tel = 0, re = 0;
    
    cin >> n;
    for(int i = 0; i < n; i++){
        string input;
        cin >> input;
        if("AC" == input) ac++;
        else if("WA" == input) wa++;
        else if("TLE" == input) tel++;
        else if("RE" == input) re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tel << endl;
    cout << "RE x " << re;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
int c[26];
int main(){
    int h,w;
    cin>>h>>w;
    string si;
    rep(i,h){
        cin>>si;
        rep(j,w) ++c[si[j]-'a'];
    }
    if(h%2==0&&w%2==0){
        rep(i,26){
            if(c[i]%4!=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }
    else if(h%2==1&&w%2==1){
        int cnt=0;
        rep(i,26){
            if(c[i]>=4){
                int p=min(cnt+c[i]/4*4,(h-1)/2*(w-1)/2*4);
                c[i]-=p-cnt;
                cnt=p;
            }
            if(cnt==(h-1)/2*(w-1)/2*4) break;
        }
        if(cnt!=(h-1)/2*(w-1)/2*4){
            cout<<"No"<<endl;
            return 0;
        }
        rep(i,26){
            if(c[i]>=2){
                int p=min(cnt+c[i]/2*2,h*w-1);
                c[i]-=p-cnt;
                cnt=p;
            }
            if(cnt==h*w-1) break;
        }
        if(cnt!=h*w-1){
            cout<<"No"<<endl;
            return 0;
        }
        rep(i,26){
            if(c[i]==1){
                ++cnt;break;
            }
        }
        if(cnt==h*w) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else{
        if(h%2==1) swap(h,w);
        int cnt=0;
        rep(i,26){
            if(c[i]>=4){
                int p=min(cnt+c[i]/4*4,(w-1)/2*h/2*4);
                c[i]-=p-cnt;
                cnt=p;
            }
            if(cnt==(w-1)/2*h/2*4) break;
        }
        if(cnt!=(w-1)/2*h/2*4){
            cout<<"No"<<endl;
            return 0;
        }
        rep(i,26){
            if(c[i]>=2){
                int p=min(cnt+c[i]/2*2,h*w);
                c[i]-=p-cnt;
                cnt=p;
            }
            if(cnt==h*w) break;
        }
        if(cnt==h*w) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  int h, w, d; cin>>h>>w>>d;
  map<int, pair<int, int>> a;
  rep(i, h) rep(j, w) {
    int t; cin>>t;
    a[t] = make_pair(i, j);
  }

  vector<int> b(90010, 0);
  REP(i, 1, d+1) {
    int x = a[i].second, y = a[i].first;
    for (int j = i+d; j < h*w+1; j += d) {
      int nx = a[j].second, ny = a[j].first;
      b[j] = b[j-d] + abs(x-nx) + abs(y-ny);
      x = nx; y = ny;
    }
  }
  int q; cin>>q;
  rep(i, q) {
    int l, r; cin>>l>>r;
    print(b[r]-b[l]);
  }

  return 0;
}

Measured memory_bytes: 7040
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_diff = 10 ** 10
near_index = -1
for i, h in enumerate(H):
    t = T - h * 0.006
    if abs(t - A) < min_diff:
        min_diff = abs(t - A)
        near_index = i + 1

print(near_index)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}







int main() {
  int N,K;
  cin>>N>>K;
  int x[N];
  for(int i=0;i<N;i++){
    cin>>x[i];
  }
  int sum=0;
  for(int i=0;i<N;i++){
    int a=abs(x[i]);
    int b=abs(K-x[i]);
    sum+=min(a,b)*2;
  }
  cout<<sum<<endl;


  




  
  
}

  


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    vi r(n);
    rep(i, n) r[i] = i + 1;
    int now = 1, a, b;
    do {
        if (r == p) a = now;
        if (r == q) b = now;
        ++now;
    } while (next_permutation(all(r)));
    cout << abs(a-b) << endl;
    return 0;
}



Measured memory_bytes: 256
n=gets.to_i
s=gets.chomp.split('')
ans = 0
(0...n-1).each do |i|
  a = 0
  [*?a..?z].each do |l|
    a+=1 if s[0..i].include?(l) && s[i+1...n].include?(l)
  end
  ans=[ans,a].max
end
p ans


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

using namespace std;
typedef long long int ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const ll mod = 1e9 + 7;

struct StronglyConnectedComponents {
  int V;
  std::vector<std::vector<int>> G, rG;
  std::vector<int> vs, cmp;
  std::vector<bool> used;

  StronglyConnectedComponents(const int V)
      : V(V), G(V), rG(V), cmp(V), used(V) {}

  void add_edge(const int from, const int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void dfs(const int v) {
    used[v] = true;
    for (int c : G[v])
      if (not used[c]) dfs(c);
    vs.push_back(v);
  }

  void rdfs(const int v, const int k) {
    used[v] = true;
    cmp[v] = k;
    for (int c : rG[v])
      if (not used[c]) rdfs(c, k);
  }

  int run() {
    std::fill(used.begin(), used.end(), false);
    vs.clear();
    for (int v = 0; v < V; v++)
      if (!used[v]) dfs(v);
    std::fill(used.begin(), used.end(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--)
      if (!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }

  std::vector<int> create_order() {
    std::vector<int> order(V);
    for (std::size_t i = 0; i < cmp.size(); i++) {
      order[cmp[i]] = i;
    }
    return order;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; std::cin >> N;
  map<std::pair<int, int>, int> dict;
  int cnt = 0;
  REP(i, N) FOR(j, i+1, N) {
    dict[make_pair(i, j)] = dict[make_pair(j, i)] = cnt++;
  }
  StronglyConnectedComponents scc(cnt);
  REP(i, N) {
    vector<int> orders(N-1);
    REP(j, N-1) cin >> orders[j], orders[j]--;
    REP(j, N-2) {
      int match1 = dict[make_pair(i, orders[j])], match2 = dict[make_pair(i, orders[j+1])];
      scc.add_edge(match1, match2);
    }
  }
  int n_cc = scc.run();
  if (n_cc != cnt) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> orders = scc.create_order();
  vector<int> dp(cnt, 1);
  for (int v : orders) {
    for (int c : scc.G[v]) {
      dp[c] = max(dp[c], dp[v] + 1);
    }
  }

  cout << *max_element(ALL(dp)) << endl;

  return 0;
}


Measured memory_bytes: 128312
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int m;
    ll k;
    cin >> m >> k;
    ll n = 1<<m;

    if (m == 0){
        if (k == 0) cout << 0 << " " << 0 << endl;
        else cout << -1 << endl;
    }
    else if (m == 1){
        if (k == 0) cout << 0 << " " << 1 << " " << 1 << " " << 0 << endl;
        else cout << -1 << endl;
    }
    else{
        if (k >= n) {
            cout << -1 << endl;
            return 0;
        }
        vector<ll> a;
        rep(i, n) if (i != k) a.push_back(i);
        rrep (i, a.size()) cout << a[i] << " ";
        cout << k << " ";
        rep (i, a.size()) cout << a[i] << " ";
        cout << k << endl;
    }

    return 0;
}

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

using namespace std;

class UnionFind {
public:
  UnionFind(int n) : _parent(n, -1) {
  }

  int findRoot(int x) {
    if (_parent[x] < 0) {
      return x;
    }
    _parent[x] = findRoot(_parent[x]);
    return _parent[x];
  }

  void unite(int x, int y) {
    x = findRoot(x);
    y = findRoot(y);

    if (x == y) {
      return;
    }

    if (getSize(x) > getSize(y)) {
      swap(x, y);
    }

    _parent[x] += _parent[y];
    _parent[y] = x;
  }

  bool isSame(int x, int y) {
    return findRoot(x) == findRoot(y);
  }

  int getSize(int x) {
    return -_parent[findRoot(x)];
  }

  int getGroupNum() {
    int res = 0;
    for (size_t i = 1; i < _parent.size(); ++i) {
      if (_parent.at(i) < 0) {
        ++res;
      }
    }
    return res;
  }

private:
  vector<int> _parent;
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n+1);

  vector<int> a(m, 0), b(m, 0);
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
  }

  vector<uint64_t> ans(m, 0);
  ans[m-1] = (uint64_t)n * (n - 1) / 2;
  for (int i = m - 1; i >= 1; --i) {
    if (!uf.isSame(a[i], b[i])) {
      ans[i-1] = ans[i] - (uint64_t)uf.getSize(a[i]) * uf.getSize(b[i]);
      uf.unite(a[i], b[i]);
    } else {
      ans[i-1] = ans[i];
    }
  }
  for (auto &e : ans) {
    cout << e << endl;
  }
  return 0;
}

Measured memory_bytes: 6044
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      String s;
      s=sc.next();
      int ans=1000;

      for(int i=2; i<s.length(); i++){
        if(Math.abs(Integer.parseInt(s.substring(i-2, i+1))-753)<ans){
          ans=Math.abs(Integer.parseInt(s.substring(i-2, i+1))-753);
        }
      }
      
      System.out.println(ans);
      
      }catch (Exception e) {
      System.out.println("out");
    }
  }
}


Measured memory_bytes: 22996
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

int n, a[N];

void solve() {
	cin >> n;
	int x = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		x ^= a[i];
	}
	for (int i = 0; i < n; i++)
		cout << (x ^ a[i]) << ' ';
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif
		
	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 4380
#pragma comment(linker, "/STACK:10240000")
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 550;

struct tnode
{
    int x, y;
}a[MAXN];

int b[MAXN];

int finds (int k)
{
    if (b[k] != k)
    {
        b[k] = finds (b[k]);
    }
    return b[k];
}

int main ()
{
    int n, m;
    scanf ("%d%d", &n, &m);
    for (int i = 1; i <= m; i ++)
    {
        scanf ("%d%d", &a[i].x, &a[i].y);
    }
    int ans = 0;
    for (int i = 1; i <= m; i ++)
    {
        for (int j = 1; j <= n; j ++)
        {
            b[j] = j;
        }
        for (int j = 1; j <= m; j ++)
        {
            if (j == i)
            {
                continue;
            }
            int s = finds (a[j].x);
            int t = finds (a[j].y);
            if (s != t)
            {
                b[s] = t;
            }
        }
        int now = finds (1);
        bool flag = false;
        for (int j = 2; j <= n; j ++)
        {
            if (finds (j) != now)
            {
                flag = true;
                break;
            }
        }
        if (flag)
        {
            ans ++;
        }
    }
    printf ("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int n;
    cin>>n;
    string s1;
    cin>>s1;
    map<string,int> m1;
    int m = s1.size();
    char c = s1[m-1];
    m1[s1]++;
    bool chk = true;
    loop(i,1,n)
    {
        cin>>s1;
        m = s1.size();
        m1[s1]++;
        //cout<<m1[s1]<<" "<<s1[0]<<" "<<c<<endl;
         if(m1[s1]>1 || s1[0]!=c)
         {
             chk = false;
             //cout<<s1<<endl;
         }
         c = s1[m-1];

    }
    if(chk)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}



Measured memory_bytes: 3672
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<string.h>
using namespace std;
string s;
string t;
int e;

int main()
{
    cin>>s;
    cin>>t;
    e =s.length();
    // cout<<s.substr(0, e);
    if(s == t.substr(0, e)){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;

  int ans = 0;
  rep(i, 50000) {
    if (floor(i * 1.08f) == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

//a,b x
int main(){
	ll N,K; cin>>N>>K;
    vector<P> p(N);
    rep(i,N){
        ll x,y; cin>>x>>y;
        p[i]=mp(x,y);
    }	
	sort(p.bg,p.ed);
    ll i=0,tmp=0;
    while(tmp<K){
        tmp+=p[i++].b;
    }
    cout<<p[i-1].a;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int n, v; cin >> n >> v;
   V<int> a(n), b(n), c(n), d(n);
   REP(i, n) cin >> a[i];
   REP(i, n) cin >> b[i];
   REP(i, n) cin >> c[i];
   REP(i, n) cin >> d[i];

   V<int> ab(n * n);
   REP(i, n) REP(j, n) {
      ab[i * n + j] = a[i] + b[j];
   }
   SORT(ab);

   int ans = 0;
   REP(i, n) REP(j, n) {
      ans += COUNT(ab, v - (c[i] + d[j]));
   }
   cout << ans << endl;

   return 0;
}



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

using namespace std;

vector<pair<int, int> >v;

int main()
{
  for(int i=0;i<2;i++){
    int n;
    scanf("%d", &n);
    for(int j=0;j<n;j++){
      int h, m;
      scanf("%d%d", &h, &m);
      v.push_back(make_pair(h, m));
    }
  }

  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  for(int i=0;i<v.size();i++)
    printf(i==v.size()-1?"%d:%02d\n":"%d:%02d ", v[i].first, v[i].second);
  return 0;
}

Measured memory_bytes: 1052
using System;
using System.Collections.Generic;
class Program
{

    static void Main()
    {
        string S = Console.ReadLine();
        int i = S.Length;
        string s = S.Substring(i-1);

        if (s=="s")
        {
            Console.WriteLine("{0}es",S);
        }
        else
        {
            Console.WriteLine("{0}s",S);
        }

    }

}


Measured memory_bytes: 25956
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	char arr[100];

	scanf("%s", arr);

	int count = 15;

	for (int i = 0; i < strlen(arr); i++)
		if (arr[i] == 'x')
			count--;

	if (count >= 8)
		printf("YES");
	else
		printf("NO");

	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, eq=0;
    lint ans=0, mb = (int)2e9;
    cin>>N;
    for(int i=0;i<N;i++){
        lint a, b;
        cin>>a>>b;
        ans += a;
        if(a>b) mb = min(mb, b);
        if(a==b) eq++;
    }
    if(eq==N) cout<<0<<endl;
    else cout<<ans - mb<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
input = sys.stdin.readline

times = []
for _ in range(5):
    x = int(input())
    times.append([x, ((x + 9) // 10 * 10) - x])

times.sort(key=lambda x : x[1])

ans = 0
for i in range(4):
    ans += times[i][0] + times[i][1]

ans += times[-1][0]

print(ans)



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

int main() {
  int K;
  cin >> K ;
  vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << vec.at(K-1) << endl;
  return 0;
}


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

typedef long long ll;

const int maxn=2e5+100;

int n;
ll a[maxn];
map <ll,int> cnt;
int ans=0;

ll get(ll x){
	ll ret=1;
	while(ret<=x) ret*=2;
	return ret;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	sort(a,a+n);
	for(int i=0;i<n;i++) cnt[a[i]]++;
	for(int i=n-1;i>=0;i--){
		ll x=get(a[i]);
		if(cnt[a[i]]==0) continue;	
		cnt[a[i]]--;
		if(cnt.find(x-a[i])!=cnt.end()){
			if(cnt[x-a[i]]>0){
				ans++;
				cnt[x-a[i]]--;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }

int main(){
    int n; cin>>n;
    vector<int> time(24);
    time[0]++;
    rep(i,n){int d; cin>>d; time[d]++;}
    int ans=-100, tmp=100;
    rep(i,(1<<12)){
        vector<int> time_=time;
        rep(j,12){
            if(i&(1<<j) && time_[j+1]>=1){
                time_[j+1]--;
                time_[23-j]++;
            }
        }
        rep(x,24){
            rep(y,24){
                if(x>=y)continue;
                if(max(time_[x],time_[y])>=2){tmp=0;break;}
                if(min(time_[x],time_[y])>0){chmin(tmp,min(y-x,24+x-y));}
            }
        }
        chmax(ans,tmp);
        tmp=100;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
S = input()

former = defaultdict(lambda: 0)
latter = defaultdict(lambda: 0)

def power(n):
  return chain(*(combinations(range(n), r) for r in range(n+1)))

def solve(N, S):
  for p in power(N):
    bs1 = []; rs1 = []; bs2 = []; rs2 = []
    for i in range(N):
      if i in p:
        rs1.append(S[i])
        rs2.append(S[-1-i])
      else:
        bs1.append(S[i])
        bs2.append(S[-1-i])
    former["".join(rs1), "".join(bs1)] += 1
    latter["".join(bs2), "".join(rs2)] += 1

  ans = 0
  for k, v in former.items():
    if k in latter:
      ans += v * latter[k]

  return ans

print(solve(N, S))

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

int main(){
  int x, n;
  cin >> x >> n;
  vector<int> vec(n);
  
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
  }
  
  int ans;
  for(int i= 0; i < n + 2; i++){
    int num = x;
    bool isSame = false;
    if(i % 2 == 0){
      num -= (i/2);
    }
    else{
      num += (i/2);
    }
    
    for(int j = 0; j < n; j++){
      if(vec.at(j) == num){
        isSame = true;
        break;
      }
    }
    
    if(isSame){
      continue;
    }
    else{
      ans = num;
      break;
    }
  }
  
  
  cout << ans << endl;
}


Measured memory_bytes: 3616
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int x,k,d; 
    cin>>x>>k>>d; 
    int n=x;
    x = abs(x);
    int c = x/d;
    if (c>=k){
        cout << (x-(k*d)) << endl;
        return;
    } 
    x -= (c*d); 
    k -= c; 
    int ans1=x,ans2=x;
    if (k>0) {
        int h=k-1;
        ans2 = (ans2-d); 
        if (h&1) ans2 += d;
    }
    if (k%2) ans1 -= d;
    cout << min(abs(ans2),abs(ans1)) << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3524
#include <stdio.h>
int main (void)
{
  int x,y,z,box;

  scanf ("%d %d %d\n",&x,&y,&z);

  do
  {
    if (x>y)
    {
      box=x;
      x=y;
      y=box;
    }
    else
    if (y>z)
    {
      box=y;
      y=z;
      z=box;
    }
  } while(x>y || y>z);

  box=0;

  box=z-x;

  printf ("%d\n",box);

  return 0;
}


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

int len(char s[]){
	int l = 0;
	for(;'a'<=s[l]&&s[l]<='z';l++);
	for(;'A'<=s[l]&&s[l]<='Z';l++);
	return l;
}

int min(int a, int b, int c){
	if(a<=b&&a<=c) return a;
	if(b<=a&&b<=c) return b;
	return c;
}

int levenshtein(char s1[], char s2[]){
	int n = len(s1);
	int m = len(s2);
	int dp[n+1][m+1]={};

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

	for(int j=0; j<m+1; j++){
		dp[0][j] = j;
	}

	for(int i=1; i<n+1; i++){
		for(int j=1; j<m+1; j++){
			if(s1[i-1] == s2[j-1]){
				dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]);
			}else{
				dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+1);
			}
		}
	}

	return dp[n][m];
}

int main(){
	char s1[1000], s2[1000];

	cin >> s1 >> s2;
	cout << levenshtein(s1, s2) << endl;

	return 0;
}


Measured memory_bytes: 7004
#include<stdio.h>
int main()
{
	int n,i,a=0,m=0;
	int s[100001]={0},t[100001]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&s[i]);
	}
	for(i=0;i<n;i++)
	{
		t[s[i]]++;
		t[s[i]+1]++;
		t[s[i]-1]++;
	}
	for(i=0;i<n;i++)
	{
		if(a<t[i])a=t[i];
	}
	if(a==0)printf("1\n");
	else printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>

typedef long long ll;
using namespace std;


void paint(int cell[10][10],int x, int y, int size,int *maxC){
	if(size == 3){
		for(int i=x-2;i<=x+2;i++){
			for(int j=y-2;j<=y+2;j++){
				if(sqrt(pow((double)i-(double)x,2.0) + pow((double)j-(double)y,2.0)) <= 2.0){
					if(i >=0 && i< 10 && j>= 0&& j<10){
						cell[j][i]++;
						*maxC = max(cell[j][i],*maxC);
					}
				}
			}
		}
	}

	if(size == 2){
		for(int i=x-1;i<=x+1;i++){
			for(int j=y-1;j<=y+1;j++){
				if(i >=0 && i< 10 && j>= 0&& j<10){
					cell[j][i]++;
					*maxC = max(cell[j][i],*maxC);
				}
			}
		}
	}

	if(size == 1){
		int tx[5] = {-1,0,1,0,0};
		int ty[5] = {0,1,0,-1,0};
		for(int i=0;i<5;i++){
			cell[y+ty[i]][x+tx[i]]++;
			*maxC = max(cell[y+ty[i]][x+tx[i]],*maxC);
		}
	}
}

int main()
{
	int cell[10][10];
	fill((int*)cell,(int*)cell+10*10,0);
	string str;
	int maxC=0;
	int count=0;
	while(getline(cin,str,',')){
		string str2;

		getline(cin,str2,',');
		string str3;

		getline(cin,str3);		
		paint(cell,str[0]-'0',str2[0]-'0',str3[0]-'0',&maxC);
		
	}
	for(int i=0;i<10;i++) for(int j=0;j<10;j++) count += cell[i][j] == 0 ? 1 : 0;

	cout << count << endl;
	cout << maxC << endl;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>

FILE *fp;
int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a + b >= 10) {
		printf("error\n");
	}
	else {
		printf("%d\n", a + b);
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n;cin>>n;
    int arr[n];
    int ans=0;
    for(int i = 0;i<n;i++)
    {
        cin>>arr[i];
        if(i%2==0 && arr[i] %2!=0){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  int N,M;
  cin>>N>>M;
  ll A[N];
  int B[N];
  pair<int,int> p[N];
  rep(i,N){
    cin>>A[i]>>B[i];
    p[i]=make_pair(A[i],B[i]);
  }
  sort(p,p+N);
  ll ans=0;
  int hoge=0,i=0,h=0,k=0;
  while(hoge<M){
    hoge++;
    p[i].second--;
    ans+=p[i].first;
    if(p[i].second==0)
      i++;
  }

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


Measured memory_bytes: 2176