akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
const ll M=505;
ll n;
ll a[M][M];
bool viz[M][M];
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
void dfs(ll x,ll y){
	ll val=a[x][y]+viz[x][y];
	for(ll i=0;i<4;i++){
		ll x1=x+dx[i],y1=y+dy[i];
		if(a[x1][y1]>val){
			a[x1][y1]=val;
			dfs(x1,y1);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			a[i][j] = min(min(i,n+1-i),min(j,n+1-j))-1;
			viz[i][j]=true;
		}
	}
	ll ans=0;
	for(ll i=0;i<n*n;i++){
		ll p;
		cin>>p;
		ll x,y;
		x= ceil(p/(n*1.0));
		y = p%n;
		if(y==0) y=n;
		viz[x][y]=false;
		ans+=a[x][y];
		dfs(x,y);
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 21188
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W=map(int,input().split())
cx,cy=map(lambda x: int(x)+1,input().split())
dx,dy=map(lambda x: int(x)+1,input().split())
S=["#"*(W+4)]*2+["##"+input()+"##" for i in range(H)]+["#"*(W+4)]*2
l=[[-2]*(W+4) for i in range(H+4)]
for i in range(2,H+2):
    for j in range(2,W+2):
        if S[i][j]==".":
            l[i][j]=-1
l[cx][cy]=0
b=[(cx,cy)]
bb=[(cx,cy)]
t=0
while bb:
    while b:
        a=[]
        for i in b:
            if l[i[0]+1][i[1]]==-1:
                l[i[0]+1][i[1]]=t
                a.append((i[0]+1,i[1]))
            if l[i[0]-1][i[1]]==-1:
                l[i[0]-1][i[1]]=t
                a.append((i[0]-1,i[1]))
            if l[i[0]][i[1]+1]==-1:
                l[i[0]][i[1]+1]=t
                a.append((i[0],i[1]+1))
            if l[i[0]][i[1]-1]==-1:
                l[i[0]][i[1]-1]=t
                a.append((i[0],i[1]-1))
        bb+=a
        b=a
    aa=[]
    t+=1
    b=[]
    for i in bb:
        for j in range(-2,3):
            for k in range(-2,3):
                if l[i[0]+j][i[1]+k]==-1:
                    l[i[0]+j][i[1]+k]=t
                    aa.append((i[0]+j,i[1]+k))
                    b.append((i[0]+j,i[1]+k))
    if l[dx][dy]>=0:
        break
    bb=aa
print(l[dx][dy])

Measured memory_bytes: 90032
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner cin = new Scanner(System.in);
        int w = cin.nextInt();
        int h = cin.nextInt();
        int x = cin.nextInt();
        int y = cin.nextInt();
        int r = cin.nextInt();
        
        System.out.println((x-r>=0 && y-r>=0 && x+r<=w && y+r<=h)?"Yes":"No");
    }
}


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


int main()
{

    int n=0; string s;
    cin>>s;
    for(int i=0, j=s.size()-1; i<j; i++, j--)
    {
        if(s[i]==s[j]) continue;
        n++;
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Monad                                                                                                       
main :: IO ()                                                                                                              
main = do                                                                                                                  
  n <- readLn                                                                                                              
  [d,x] <- map read . words <$> getLine                                                                                    
  print =<< (+x) . sum . map ((+1) . div (d-1) . read) <$> replicateM n getLine

Measured memory_bytes: 1020
#include <stdio.h>

int main(void)
{
	char str[10000];
	int temp;
	int sum;
	int i;
	
	scanf("%[^ ]", str);
	
	i = sum = 0;
	while (str[i] != '\0'){
		temp = 0;
		while ('0' <= str[i] && str[i] <= '9'){
			temp = temp * 10 + str[i] - '0';
			i++;
		}
		sum += temp;
		i++;
	}
	
	printf("%d\n", sum);
	
	return (0);
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApplication2
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs = ReadLine().Split(' ').Select(r => Convert.ToInt32(r)).ToList();

			if (inputs[0] <= inputs[2] && inputs[2] <= inputs[1])
			{
				WriteLine("Yes");
			}
			else
			{
				WriteLine("No");
			}
		}
	}
}


Measured memory_bytes: 11348
def just_fit(xyh, x, y, h):
    for p in xyh:
        if max(h - abs(p[0] - x) - abs(p[1] - y), 0) == p[2]:
            pass
        else:
            return False
    return True

N = int(input())

xyh = []
highest_h = 0
for i in range(N):
    tmp = list(map(int, input().split()))
    xyh.append(tmp)
    if tmp[2] > highest_h:
        highest_h = tmp[2]

ans_x, ans_y, ans_z = -1, -1, -1
flug = 0
for highPlus in range(101):
    for x in range(101):
        for y in range(101):
            if just_fit(xyh, x, y, highest_h + highPlus):
                ans_x, ans_y, ans_z = x, y, highest_h + highPlus
                flug = 1
                break
        if flug == 1:
            break
    if flug == 1:
        break

print(ans_x, ans_y, ans_z)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  if(n%k==0) cout << 0 << endl;
  else cout << 1 << endl;
}


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

int main(){
	string s;
	cin >> s;
	map<char, bool> dict;

	for(char c: s) dict[c] = true;
	rep(i, 26){
		char c = 'a' + i;
		if(!dict.count(c)){
			cout << c << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && B == C){
        out("No");
    }
    else if (A != B && B != C && C != A){
        out("No");
    } else out("Yes");

}


Measured memory_bytes: 256
from sys import stdin
from collections import Counter
H,W = [int(x) for x in stdin.readline().rstrip().split()]
c = Counter()

for i in range(H):
    c += Counter(list(input()))

rem0 = 0
rem2 = 0

for i in c.values():
    if i % 4 == 0:
        rem0 += 1
    elif i % 4 == 2:
        rem2 += 1

num_v = len(c.values())

f = True
if H % 2 == 0 and W % 2 == 0:
    if rem0 != num_v:
        f = False

elif H % 2 != 0 and W % 2 != 0:
    
    if len([i for i in c.values() if i % 2 != 0]) != 1:
        f = False
        
    if rem2 > (H-1)/2 + (W-1)/2:
        f = False
    
    if num_v-1 != rem0 + rem2:
        f = False
    
else:
    if H % 2 == 0:
        if rem2 > H/2:
            f = False
        if rem2 + rem0 != num_v:
            f = False
            
    if W % 2 == 0:
        if rem2 > W/2:
            f = False
        if rem2 + rem0 != num_v:
            f = False
    
if f:
    print("Yes")
else:
    print("No")

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

int main(){
	int n, l, c, t, cost = 1001;
	cin >> n >> l;
	for(int i=0; i<n; i++){
		cin >> c >> t;
		if(t<=l) cost = min(cost,c);
	}
	if(cost == 1001) cout << "TLE" << endl;
	else cout << cost << endl;
}

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

int main(){
  long int n, h;
  cin >> n >> h;
  vector <pair<long int, long int>> ab(n), ba(n);
  for(int i = 0; i < n; i++){
    long int a, b;
    cin >> a >> b;
    ab.at(i) = make_pair(a, b);
    ba.at(i) = make_pair(b, a);
  }
  sort(ab.rbegin(), ab.rend());
  long int a_base = ab.at(0).first;  
  sort(ba.rbegin(), ba.rend());
  int count = 0;
  for(long int i = 0; i < n; i++){
    if(ba.at(i).first < a_base) break;
    h -= ba.at(i).first;
    count++;
    if(h <= 0) break;
  }
  if(h > 0){
    count += h / a_base;
    if(h % a_base != 0){
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x,y;
	cin>>x>>y;
	if(x%y==0)cout<<-1<<endl;
	else{
		cout<<x<<x<<endl;
	}
	return 0; 
} 

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

#define N 100000

typedef struct que{
  char name[10];
  int num;
}que;

int main(void){
  int i,n,q,sum=0,head,tail;
  que Q[N];

  scanf("%d %d",&n,&q);
  if(n>N||n<=0) exit(1);

    

  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].num);
  }

  head=1;
  tail=n+1;

  while(head!=tail){
    if(Q[head].num<=q && Q[head].num!=0){
      sum+=Q[head].num;
      printf("%s ",Q[head].name);
      printf("%d\n",sum);
      if(head==N-1) head=0;
      head++;
      
    }
    else {
      Q[head].num-=q;
      sum+=q;
      Q[tail]=Q[head];
      if(head==N-1) head=0;
      if(tail==N-1) tail=0;
      tail++;
      head++;
        }
  }

  
  return 0;
}

Measured memory_bytes: 2160
#include <iostream>
using namespace std;
int n,m,x,y;
int f[100005];
long long answer[100005],Size[100005];
struct Edge
{
	int u,v;
}e[100005];
int find_set(int x)
{
	if(x!=f[x]) f[x]=find_set(f[x]);
	return f[x];
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) f[i]=i,Size[i]=1;
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y;
		e[i].u=x;
		e[i].v=y;
	}
	answer[m]=(long long)n*(n-1)/2;
	for(int i=m;i>=1;i--)
	{
		if(find_set(e[i].u)==find_set(e[i].v))
		    answer[i-1]=answer[i];
	    else
	    {
	    	answer[i-1]=answer[i]-Size[find_set(e[i].u)]*Size[find_set(e[i].v)];
			Size[find_set(e[i].v)]+=Size[find_set(e[i].u)];
			f[find_set(e[i].u)]=find_set(e[i].v);
		}
	}
	for(int i=1;i<=m;i++) cout<<answer[i]<<endl;
	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define gcd __gcd
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000003
#define MOD 1000000007
#define N 105
using namespace std;

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;

//All indexing is 0-based
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
       tree_order_statistics_node_update> ordered_set;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar.

//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c;}
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c;}
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p;}

main()
{ 
  #ifdef CP
    freopen("/home/tarun/Desktop/input.txt", "r", stdin);
//    freopen("/home/tarun/Desktop/output.txt", "w", stdout);
  #endif
  //cerr << fixed << setprecision(18);
  sync;
  clock_t clk = clock();
  cerr << "I will return...\n";
  
  int n; cin >> n;
  int x; cin >> x;
  int a[n];
  for(int&i : a) cin >> i;
  sort(a, a + n);
  int cnt = 0;
  int i = 0;
  while(i < n && x > 0) {
    x -= a[i];
    i++;
    cnt++;
  }
  //db(x);
  if(x) cout << cnt - 1 << '\n';
  else cout << cnt << '\n';


  cerr << "...don't you ever hang your head.\n";
  cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}

//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment







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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  string S; cin >> S;
  ll cnt = 0;
  ll i = 0;
  ll j = N-1;
  while (true) {
    while (i < j && S.at(i) == 'R') i++;
    while (i < j && S.at(j) == 'W') j--;
    if (i >= j) break;
    cnt++;
    i++;
    j--;
  }
  cout << cnt << endl;


  return 0;
}



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

struct dice{
    int l[6];
    void roll(int a, int b, int c, int d){
        int t = l[a];
        l[a] = l[b];
        l[b] = l[c];
        l[c] = l[d];
        l[d] = t;}
    void roll_x() {roll(0, 2, 5, 3);}
    void roll_y() {roll(0, 1, 5, 4);}
    void roll_z() {roll(1, 2, 4, 3);}
    bool find_l3(dice a){
        REP(i, 4) {
            roll_x();
            REP(j, 4) {
                roll_y();
                REP(k, 4) {
                    roll_z();
                    int n = 0;
                    REP(m, 6) {
                        if (l[m] != a.l[m]) break;
                        else n++;}
                    if (n == 6) return 1;}}}
        return 0;
    }
};

int main(){
    int n; cin >> n;
    vector<dice> d(n);
    REP(i, n) REP(j, 6) cin >> d[i].l[j];
    REP(i, n)
        FOR(j, i+1, n)
            if (d[i].find_l3(d[j])) {cout << "No" << endl; return 0;}
    cout << "Yes" << endl;
}

Measured memory_bytes: 3068
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

const int N = 105;

int D[N];

void die() {
    printf("Impossible\n");
    exit(0);
}

int main() {
    int n;
    scanf("%d", &n);
    int mx = 0;
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        D[x]++;
        mx = max(mx, x);
    }
    for (int c = mx; c >= mx / 2 + 1; c--) {
        D[c] -= 2;
        if (D[c] < 0)
            die();
    }
    if (mx % 2 == 0) {
        D[mx / 2]--;
        if (D[mx / 2] < 0)
            die();
    }
    for (int c = 1; c <= mx; c++) {
        if (D[c] != 0) {
            if (c < ((mx + 1) / 2 + 1))
                die();
        }
    }
    printf("Possible\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

// O(√n)
map<int64_t, int64_t> prime_factor(int64_t n) {
    map<int64_t, int64_t> res;
    for(int64_t i=2; i*i<=n; i++) {
        while(n%i == 0)  res[i]++, n/=i;
    }
    if(n != 1)  res[n] = 1;
    return res;
}

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

    auto pf = prime_factor(N);

    lint ans = 0;
    for(auto [prime, exp] : pf) {
        for(lint i=1; i<=exp; i++) {
            ans++;
            exp -= i;
        }
    }
    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n; cin >> n;
  map<ll, int> div;
  ll lim = sqrt(n);
  for(ll i = 2; i <= lim; ++i) {
    while(n % i == 0) {
      if(div.find(i) == div.end()) div[i] = 0;
      ++div[i];
      n /= i;
    }
  }
  if(n != 1) div[n] = 1;
  vector<ll> num(1001, 0);
  for(int i = 1; i <= 1000; ++i) num[i] = i*(i+1)/2;
  ll ans = 0;
  for(auto x : div) {
    if(binary_search(ALL(num), x.second)) ans += distance(num.begin(), lower_bound(ALL(num), x.second));
    else {
      auto it = lower_bound(ALL(num), x.second);
      --it;
      ans += distance(num.begin(), it);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3736
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let s: Vec<char> = it.next().unwrap().chars().collect();
    let mut map = std::collections::HashMap::new();
    for i in 0..(1 << n) {
        let mut a = String::new();
        let mut b = String::new();
        for j in (0..n).rev() {
            if (i >> j) & 1 == 1 {
                a.push(s[n + j]);
            } else {
                b.push(s[n + j]);
            }
        }
        let po = map.entry((a, b)).or_insert(0);
        *po += 1;
    }
    let mut ans = 0u64;
    for i in 0..(1 << n) {
        let mut a = String::new();
        let mut b = String::new();
        for j in 0..n {
            if (i >> j) & 1 == 1 {
                a.push(s[j]);
            } else {
                b.push(s[j]);
            }
        }
        if let Some(&v) = map.get(&(a, b)) {
            ans += v;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 59628
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 62)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll sz = 2e5 + 10, mod = 1e9 + 7;
ll ara[sz];

int main()
{
    ll n, k;
    cin >> n >> k;
    for1(i, n) sl(ara[i]);

    sort(ara+1, ara+n+1);

    if(ara[n] == 0 && k % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }

    if(ara[n] < 0 && k % 2 != 0) {
        ll mul = 1;
        for(ll i = n, j = 1; i >= 1 && j <= k; i--, j++) mul = (mul * ara[i]) % mod;

        mul += mod;
        cout << mul << endl;
        return 0;
    }

    ll ptr1 = 1, ptr2 = n, done = 0, mul = 1;
    if(k & 1) {
        mul = (mul * ara[ptr2]) % mod;
        ptr2--, done++;
    }

    while(done < k) {
        ll mul1 = ara[ptr1] * ara[ptr1 + 1], mul2 = ara[ptr2] * ara[ptr2-1];

        if(mul2 >= mul1) {
            mul2 %= mod;
            mul = (mul * mul2) % mod;
            done += 2, ptr2 -= 2;
        }
        else {
            mul1 %= mod;
            mul = (mul * mul1) % mod;
            done += 2, ptr1 += 2;
        }
    }

    if(mul < 0) mul += mod;
    cout << mul << endl;

    return 0;
}


Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
# define int long long
int knapsack(int n,int w,int wt[],int v[])
{
    int dp[n+1][w+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(wt[i]<=j)
            {
                dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-wt[i]]);
            }
            else
                dp[i][j]=dp[i-1][j];
        }
    }
  return dp[n][w];
}
int32_t main()
{
    int t,w;
    cin>>t>>w;
    int wt[t+1],v[t+1];
    for(int i=1;i<=t;i++)
    {
        cin>>wt[i]>>v[i];
    }
    cout<<knapsack(t,w,wt,v);
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int* s = new int[n];
	for(int i = 0; i < n;i++){
		cin >> s[i];
	}

	int q;
	cin >> q;
	int* t = new int[q];
	for(int i = 0;i < q;i++){
		cin >> t[i];
	}

	int count = 0;
	for(int i = 0;i < q;i++){
		for(int j = 0;j < n;j++){
			if(t[i] == s[j]){
				s[j] = -1;
				t[i] = -1;
				count++;
				break;
			}
		}
	}
	cout << count << endl;
}



Measured memory_bytes: 3064
cards = []
for a in range(1,14):
    cards += ["S "+str(a), "H "+str(a), "C "+str(a), "D "+str(a)]
n = int(input())
for a in range(n):
    cards.remove(input())
order = ["S","H","C","D"]
cards.sort(key = lambda x: order.index(x[0]))
if len(cards) != 0:
    print("\n".join(cards))


Measured memory_bytes: 5604
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  vector<pair<ll, int> > all;
  for(int i = 0; i < a; i++) cin >> p[i], all.push_back({p[i], 0});
  for(int i = 0; i < b; i++) cin >> q[i], all.push_back({q[i], 1});
  for(int i = 0; i < c; i++) cin >> r[i], all.push_back({r[i], 2});
  sort(all.begin(), all.end(), greater<pair<ll, int>>());

  int ux = 0, uy = 0, uz = 0;
  ll ans = 0;
  for(int i = 0; i < all.size(); i++){
    ll nowf = all[i].first;
    int nows = all[i].second;
    if(nows == 0 && ux < x){
      ux++;
      ans += nowf;
    }
    else if(nows == 1 && uy < y){
      uy++;
      ans += nowf;
    }
    else if(nows == 2){
      uz++;
      ans += nowf;
    }
    if(ux+uy+uz == x+y) break;
  }
  cout << ans << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 12908
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
typedef struct {
    ll u;
    ll v;
    ll cost;
} edge;

typedef struct {
    ll x;
    ll y;
    ll idx;
} edge2;

bool compx(edge2 l1, edge2 l2){
    return l1.x < l2.x;
}

bool compy(edge2 l1, edge2 l2){
    return l1.y < l2.y;
}

bool comp(edge l1, edge l2){
    return l1.cost < l2.cost;
}

ll parent[200010];

ll root(ll x){
    if(x == parent[x]) return x;
    else return parent[x] = root(parent[x]);
}

void unite(ll a, ll b){
    a = root(a); b = root(b);
    if(a == b) return;
    parent[a] = b;
}

bool same(ll a, ll b){
    return root(a) == root(b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll x[100010], y[100010];
    cin >> N;
    rep(i,0,N) cin >> x[i] >> y[i];
    if(N == 2){
        print(min(abs(x[0]-x[1]), abs(y[0]-y[1])));
        return 0;
    }
    vector<edge2> lp;
    rep(i,0,N){
        edge2 e = {x[i], y[i], i};
        lp.push_back(e);
    }
    sort(lp.begin(), lp.end(), compx);
    vector<edge> ee;
    rep(i,1,N-1){
        edge tt = {lp[i-1].idx, lp[i].idx, abs(lp[i-1].x - lp[i].x)};
        ee.push_back(tt);
        edge tt2 = {lp[i+1].idx, lp[i].idx, abs(lp[i+1].x - lp[i].x)};
        ee.push_back(tt2);
    }
    sort(lp.begin(), lp.end(), compy);
    rep(i,1,N-1){
        edge tt = {lp[i-1].idx, lp[i].idx, abs(lp[i-1].y - lp[i].y)};
        ee.push_back(tt);
        edge tt2 = {lp[i+1].idx, lp[i].idx, abs(lp[i+1].y - lp[i].y)};
        ee.push_back(tt2);
    }
    sort(ee.begin(), ee.end(), comp);
    rep(i,0,N) parent[i] = i;
    ll ans = 0;
    for(auto &e: ee){
        ll u = e.u;
        ll v = e.v;
        ll cost = e.cost;
        if(same(u,v)) continue;
        unite(u,v);
        ans += cost;
    }
    print(ans);
    
    
    
}


Measured memory_bytes: 18924
#include<stdio.h>

int main(void){
    long int i, j, n, k, ans = 0;
    
    scanf("%ld %ld", &n, &k);
    
    n -= 2;
    if(n < 0) n = 0;
    
    ans = 5 * (n / 11);
    n %= 11;
    
    
    for(i = 1; i <= n; i++){
        for(j = 1; j <= 5; j++) if((9 * (7 * i + j + 1)) % 11 == k) ans++;
    }
    printf("%ld\n", ans);
    
    return 0;
}

Measured memory_bytes: 128
h, w = list(map(int, input().split()))
li = []
for _ in range(h):
    li.append(input())

# construct graph
from collections import defaultdict
edges = defaultdict(list)
for i in range(h):
    for j in range(w):
        idx = i * w + j
        if li[i][j] == '.':
            if i + 1 < h and li[i + 1][j] == '.':
                edges[idx].append(idx + w)
                edges[idx + w].append(idx)
            if j + 1 < w and li[i][j + 1] == '.':
                edges[idx].append(idx + 1)
                edges[idx + 1].append(idx)
goal = h * w - 1
# root search
from collections import deque
Q = deque()
Q.append(0)
reach = False
visited = {0}
pre = {0: None}
while len(Q) > 0:
    u = Q.popleft()
    if u == goal:
        reach = True
        break
    for v in edges[u]:
        if v not in visited:
            pre[v] = u
            visited |= {v}
            Q.append(v)

ans = -1
if reach:
    white = sum(a.count('.') for a in li)
    path = [goal]
    while True:
        path.append(pre[path[-1]])
        if pre[path[-1]] is None:
            break
    ans = white - len(path)

print(ans)

Measured memory_bytes: 4212
"use strict";

const permutateWithRepetitions = (
  permutationOptions,
  permutationLength
) => {
  if (permutationLength === 1) {
    return permutationOptions.map(permutationOption => [permutationOption]);
  }

  const permutations = [];

  const smallerPermutations = permutateWithRepetitions(
    permutationOptions,
    permutationLength - 1
  );

  permutationOptions.forEach((currentOption) => {
    smallerPermutations.forEach((smallerPermutation) => {
      permutations.push([currentOption].concat(smallerPermutation));
    });
  });

  return permutations;
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const S = arg[1].split("").map(n=>parseInt(n));

    // 最大で1000通りしかありえないので全探索する
    const digits = [0,1,2,3,4,5,6,7,8,9];
    
    const combos = permutateWithRepetitions(digits, 3);
    
    let cnt = 0;
    
    for(let i=0; i<1000; i++) {
        let digit1 = combos[i][0];
        let digit2 = combos[i][1];
        let digit3 = combos[i][2];
        
        let flag1 = false;
        let flag2 = false;
        let flag3 = false;

        for(let j=0; j<S.length; j++) {
            if(S[j] === digit1 && flag1 !== true) {
                flag1 = true;
            } else if(S[j] === digit2 && flag1 && flag2 !== true) {
                flag2 = true;
            } else if(S[j] === digit3 && flag1 && flag2) {
                flag3 = true;
            }
        }
        
        
        if(flag1 && flag2 && flag3) {
            cnt++;
        }
    }
    
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

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

typedef long long ll;

const ll MOD = 1e9 + 7;

using namespace std;

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

    int S;
    cin >> S;

    vector<ll> dp(S + 1, 0);

    dp[0] = 1;

    for (int i = 3; i <= S; ++i) {
        for (int j = 0; j <= i - 3; ++j) {
            dp[i] += dp[j];
            dp[i] %= MOD;
        }
    }

    cout << dp[S] << endl;
}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:268435456")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifndef _MSC_VER
#pragma GCC target ("sse4.2")
#endif
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <random>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;




int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for (int i = 0; a > 0 && c > 0; i++)
	{
		if (i % 2 == 1)
			a -= d;
		else
			c -= b;
	}
	cout << (a > 0 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;
 
 int main(){
   int l,r,d;
   cin >> l >> r >> d;
   int ans = r/d - l/d;
   if(l%d==0) ans++;
   cout << ans << endl;
   return 0;
 }

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

typedef long long ll;
using namespace std;

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

	int a[12];

	for (int i = 0;i < 12;i++){
		cin >> a[i];
	}

	sort(a,a+12);

	for (int i = 0;i < 3;i++){
		for (int j = 0;j < 3;j++){
			if(a[i*4+j] != a[i*4+j+1]){
				cout << "no" << endl;
				return 0;
			}
		}
	}

	cout << "yes" << endl;

	return 0;

}


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

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int m;
    
    scanf("%d", &m);
    
    printf("%d", 24+24-m);
    
    return 0;
}



Measured memory_bytes: 1700
N, A, B = map(int, input().split())
S = input()

n_p = n_f = 0

for s in S:
  if s == "a" and n_p < A + B:
    n_p += 1
    print("Yes")
    continue

  if s == "b" and n_p < A + B and n_f < B:
    n_p += 1
    n_f += 1
    print("Yes")
    continue

  print("No")


Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
/*
signed main(){
  int a,b;
  cin>>a>>b;
  if(a<=5) cout<<0<<endl;
  else if(a<=12) cout<<b/2<<endl;
  else cout<<b<<endl;
  return 0;
}
*/
/*
signed main(){
  int r,d,x;
  cin>>r>>d>>x;
  lp(i,10){
    x=r*x-d;
    cout<<x<<endl;
  }
  return 0;
}
*/
signed main(){
  int n,m;
  cin>>n>>m;
  vector<int> v;
  lp(i,n){
    int a;
    cin>>a;
    v.push_back(a);
  }
  vector<pair<int,int>> l;
  lp(i,m){
    int a,b;
    cin>>a>>b;
    l.push_back({b,a});
  }
  l.push_back({-1,INF});
  sort(v.begin(),v.end());
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  int lit=0;
  int ans=0;
  lp(i,v.size()){
    v[i]=max(l[lit].first,v[i]);
    l[lit].second--;
    if(l[lit].second==0){
      lit++;
    }
    ans+=v[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3316
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

int main() {
    ll N,K;
    cin >> N >> K;

    // if(K == 1){
    //     cout << 0 << endl;
    //     return 0;
    // }else if(K == 2 && N%2 == 0){
    //     cout << 0 << endl;
    //     return 0;
    // }

    ll result = N % K;

    result = min(result,abs(result-K));

    cout << result << endl;
}


Measured memory_bytes: 3600
n = int(input().strip())
lower=[0]*n
upper=[0]*n
for i in range(n):
    A, B = map(int, input().strip().split())
    lower[i]=A
    upper[i]=B
lower.sort()
upper.sort()

if n%2:
    ans=upper[n//2]-lower[n//2]+1
else:
    ans=upper[n//2]+upper[n//2-1]-(lower[n//2]+lower[n//2-1])+1
print(ans)

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

#define MAX 200

unsigned n, A[MAX], q, m[MAX];

void bubbleSort(unsigned a[], unsigned n) {
  int flag = 1;
  int done = 0;
  while (flag) {
    flag = 0;
    int j;
    for (j = n - 1; j > done; j--) {
      if (a[j] < a[j - 1]) {
        unsigned temp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = temp;
        flag = 1;
      }
    }
    done++;
  }
}

unsigned rsolve(unsigned mi, unsigned p)
{
//  cout << mi << "," << p << endl;
  unsigned ret;
  if (p >= n || mi < A[p]) ret = 0;
  else if (mi == A[p]) ret = 1;
  else {
    ret = rsolve(mi, p + 1) || rsolve(mi - A[p], p + 1);
  }
  return ret;
}

void solve()
{
  for (unsigned i = 0; i < q; i++)
    cout << (rsolve(m[i], 0) ? "yes" : "no") << endl;
}

int main()
{
  cin >> n;
  for (unsigned i = 0; i < n; i++) cin >> A[i];
  bubbleSort(A, n);
  cin >> q;
  for (unsigned i = 0; i < q; i++) cin >> m[i];
  solve();
  return 0;
}

Measured memory_bytes: 3092
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
for i in range(N):
    if B[i] >= A[i]:
        B[i] -= A[i]
        count += A[i]
        if B[i] >= A[i+1]:
            count +=A[i+1]
            A[i+1] = 0
        else:
            A[i+1] -= B[i]
            count += B[i]
    else:
        count +=B[i] 
print(count)

Measured memory_bytes: 82020
#include<bits/stdc++.h>
typedef long long ll;
#define F(i,L,R) for (ll i = L; i < R; i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define re(x) scanf("%lld",&x)
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, a,sum = 0,maxh = 0;
  cin>>n;
  F(i,0,n) cin>>a, maxh = max(maxh,a), sum += maxh-a;

  cout<<sum;

  return 0;
}

Measured memory_bytes: 3616
use proconio::input;
use std::collections::HashSet;

fn main() {

    input! {
    n: i32,
    m: i32,
    }

    let mut set = HashSet::new();

    for _i in 0..m {
        input! {t: i32}
        for _j in 0..t {
            input! {s: i32}
            set.insert(s);
        }
    }

    let size = set.len() as i32;

    let ans = n - size;

    println!("{}", ans);
}


Measured memory_bytes: 2168
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c,d,ans=0;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=0;i<=d;++i){
		if(i*a>d) break;
		for(int j=0;j<=d;++j){
			if(i*a+j*b>d) break;
			if((d-i*a-j*b)%c==0) ans++;
		}
	}
	printf("%d",ans);
	return 0;
}

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

typedef unsigned long long ull;

int ind(char ch)
{
    switch (ch) {
    case 'R':
        return 0;
    case 'G':
        return 1;
    case 'B':
        return 2;
    default:
        return 3;
    }
}

bool f(const string &s, int a, int b, int c)
{
    int t[3] = {0,0,0};
    t[ind(s[a])] = 1;
    t[ind(s[b])] = 1;
    t[ind(s[c])] = 1;
    return t[0] == 1 && t[1] == 1 && t[2] == 1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;

    vector<int> v[3];
    for (int i = 0; i < N; ++i) {
        v[ind(S[i])].push_back(i);
    }

    if (v[0].size() == 0 ||
        v[1].size() == 0 ||
        v[2].size() == 0) {
        cout << 0 << endl;
        return 0;
    }

    unsigned long long cnt = 0;

    for (int dist = 1; dist < N; ++dist) {
        for (int i = 0; i + (2*dist) < N; ++i) {
            if (f(S, i, i+dist, i+(2*dist))) {
                ++cnt;
            }
        }
    }

    unsigned long long total = v[0].size() * v[1].size() * v[2].size();

    cout << total - cnt << endl;

}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b)
    {
        cout << c;
    }
    else if (a == c)
    {
        cout << b;
    }
    else
    {
        cout << a;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll N;
map<ll,string> m;

ll comb(ll a, ll b) {
    ll ret = 1;
    F0R(i,b) {
        ret *= a-b+1+i;
        ret /= i+1;
    }
    return ret;
}

ll getLen(ll i) {
    return (ll)pow((ld)2,i-1)-1;
}

void solve(ll N) {
    int nex = 1;
    vi ans;
    while (N) {
        auto it = prev(m.ub(N));
        N -= it->f;
        for (char c: it->s) {
            if (c == 'a') ans.pb(nex);
            else ans.pb(nex+1);
        }
        // cout << N << " " << sz(ans) << "\n";
        nex += 2;
    }
    cout << sz(ans) << "\n";
    //if (sz(ans) > 200) {
        for (int i: ans) cout << i << " ";
        cout << "\n";
    //}
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    FOR(a,1,14) FOR(b,1,14) FOR(c,1,14) FOR(d,1,14) {
        string s; 
        F0R(A,a) s += 'a';
        F0R(B,b) s += 'b';
        F0R(C,c) s += 'a';
        F0R(D,d) s += 'b';
        
        ll res = getLen(a+c)+getLen(b+d);
        FOR(i,1,min(a,c)+1) FOR(j,1,min(b,d)+1) res += comb(a,i)*comb(c,i)*comb(b,j)*comb(d,j);
        m[res] = s;
    }
    FOR(i,2,42) {
        string s; F0R(j,i) s += 'a';
        m[getLen(i)] = s;
        // cout << s << " " << (ll)pow((ld)2,i-1)-1 << "\n";
    }
    for (auto it = m.begin(); it != m.end(); ) {
        if (it != m.begin() && sz(prev(it)->s) < sz(it->s) && 0.99*it->f < prev(it)->f) {
            it = next(it);
            m.erase(prev(it));
        } else if (it != m.begin() && prev(it) != m.begin() && sz(prev(it)->s) > sz(it->s) && 0.99*it->f < prev(prev(it))->f) {
            m.erase(prev(it));
        } else {
            it = next(it);
        }
    }
    // for (auto& a: m) cout << a.f << " " << sz(a.s) << "\n";
    cin >> N; solve(N); 
    /*F0R(i,100) {
        solve(rand()+1000LL*rand());
    }*/
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int odd,even;
double ans;
int main(){
	cin>>n;	odd=even=n/2;even++;
	if(n&1)odd+=1;
	ans=(double)(odd)/(double)(n);
	printf("%.7lf",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {  // 発見できたとき
    return 1;
  } else {  // 発見できなかったとき
    return 0;
  }
}
unsigned GetDigit(unsigned num) { return log10(num) + 1; }
int main() {
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll sum = 0, num = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      num = a[i] - a[i + 1];
      sum = sum + num;
      a[i + 1] = a[i + 1] + num;
    }
  }
  cout << sum;
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

bool isp(int x){
  if(x <= 2) return x == 2;
  for(int i=2;i*i<=x;++i)
	if(x % i == 0)
	  return false;
  return true;
}

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

  int N = 1407;
  int K = 38;

  cout << N << " " << K << endl;
  REP(k,K){
	cout << 1;
	REP(d,K-1)
	  cout << " " << 2 + k * (K-1) + d;
	cout << endl;
  }

  for(int x=2;x<=K;++x){
	int cyc = x - 2;
	REP(j,K-1){
	  cout << x << " " << K+1+j;
	  for(int col=2;col<K;++col){
		int b = 2 + col * (K-1);
		cout << " " << b + (j + cyc * (col-1))
		  % (K-1);
	  }
	  cout << endl;
	}
  }

  return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
const ll INF = LLONG_MAX / 2;

signed main() {
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
    return 0;
}


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

using ll = long long;
using ld = long double;

const int M = 10;

bool lol[M];

bool dislike(int x) {
  bool ret = false;
  while(x > 0) {
    int cur = x % 10;
    ret |= lol[cur];
    x /= 10;
  }
  return ret;
}

void solve() {
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < k; i++) {
    int d;
    cin >> d;
    lol[d] = true;
  }
  int ans = n;
  while(dislike(ans)) ans++;
  cout << ans << '\n';
}

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

  int TC = 1;
  // cin >> TC;
  for(int i = 1; i <= TC; i++) {
    // cout << "Case #" << i << ": ";
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 3600