akhauriyash/Code-Regression huggingface dataset:
# frozen_string_literal: true

# ABC 088 B - Card Game for Two

STDIN.gets
cards = STDIN.gets.split.map(&:to_i).sort { |a, b| b <=> a }

alice_cards = cards.select.with_index do |_, idx|
  idx.even?
end
bob_cards = cards.select.with_index do |_, idx|
  idx.odd?
end

puts alice_cards.inject(:+) - bob_cards.inject(:+)


Measured memory_bytes: 1788
def solve():
  ans = 0
  x = int(input())
  b = x // 500
  ans += 1000 * b
  x -= 500 * b
  b += x // 5
  ans += (x // 5) * 5
  print(ans)
  return 0
 
if __name__ == "__main__":
  solve()

Measured memory_bytes: 3060
/*input
0 2 3 4 5
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  for (int i = 1; i <= 5; ++i) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  const int N=3;
  bool isCorrect = true;
  vector<vector<int> > v(N,vector<int>(N));
  rep(i,N) rep(j,N) cin >> v[i][j];
  int c[N-1];
  rep(j,N-1) c[j] = v[0][j+1] - v[0][j];
  repp(i,1,N) rep(j,N-1){
    if(v[i][j+1] - v[i][j] != c[j]) isCorrect=false;
  }
  rep(i,N-1) c[i] = v[i+1][0] - v[i][0];
  repp(j,1,N) rep(i,N-1){
    if(v[i+1][j] - v[i][j] != c[i]) isCorrect=false;
  }
  YesNo(isCorrect);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;
void File(){
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
}
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
#define MREP(i,x) for(register int i=beg[x];i;i=E[i].last)
#define ll long long
#define inf INT_MAX
const int maxn=5000+10;
map<string,bool>mp;
char s[maxn];
string a[maxn*50];
int n,k,cnt;
int main(){
	//File();
	scanf("%s",s+1);
	n=strlen(s+1);
	scanf("%d",&k);
	REP(i,1,min(5,n)){
		REP(j,1,n){
			if(i+j-1>n)continue;
			int l=j,r=min(l+i-1,n);
			string aa;
			REP(f,0,r-l)aa=aa+s[l+f];
			a[++cnt]=(aa);
		}
	}
	sort(a+1,a+cnt+1);
	REP(i,1,cnt)if(a[i]==a[i-1])
		a[i-1].clear();
	sort(a+1,a+cnt+1);
	int p=1;
	while(a[p].empty())++p;
	cout<<a[p+k-1]<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> adj[100005];
const int mod=1000000007;
bool vis[100005];
int h,w;
int dp[1005][1005];
char a[1005][1005];
int f(int x,int y){
    if(x>=h || y>=w) return 0;
    if(x==h-1 && y==w-1) return 1;
    int &ans=dp[x][y];
    if(ans!=-1){
        return ans;
    }
    ans=0;
    if(a[x][y]=='.'){
        ans=(f(x+1,y)+f(x,y+1))%mod;
    }
    else{
        return 0;
    }
    return ans%mod;
}

int32_t main() {
    memset(dp,-1,sizeof(dp));
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char x;
            cin>>x;
            a[i][j]=x;
        }
    }
    int ans=f(0,0);
    cout<<ans<<endl;
}


Measured memory_bytes: 14884
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1e9+7
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int k, x;
    cin >> k >> x;
    if (500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3564
package main

import "fmt"

func main() {
    var n int
    var s string
    var m []int64 = make([]int64, 5)
    var ans int64

    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&s)
        switch s[0:1] {
            case "M": m[0]++
            case "A": m[1]++
            case "R": m[2]++
            case "C": m[3]++
            case "H": m[4]++
        }
    }
    ans = 0
    for i := 0; i < 5; i++ {
        for j := i+1; j < 5; j++ {
            for k := j+1; k < 5; k++ {
                ans += m[i]*m[j]*m[k]
            }
        }
    }
    fmt.Println(ans)
}

Measured memory_bytes: 5504
#include <iostream>
#include <string>

using namespace std;

int main() {
    string a;
    string b = "CODEFESTIVAL2016";
    int cnt;
    cin >> a;

    for (int i = 0; i < 16; i++) {
        if (a[i] != b[i])
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
    int a,b=0,c;
    scanf("%d",&a);c=a;
    while(c){
        b+=(c%10);
        c=c/10;
    }
    b=a%b;
    if(b==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
from operator import itemgetter
n,m = map(int,input().split())
t = [list(map(int,input().split())) for _ in range(m)]
t.sort(key=itemgetter(0))
c = [i[1] for i in t ]
s = [i[0] for i in t]
# print(c)
x = 0

ans = "a"*n
ans = list(ans)
for i in range(n):
    for j in range(len(s)):
        if i==s[j]-1 :
            if str(c[j])!=ans[i] and ans[i]=="a":
                ans[i]=str(c[j])
            elif  str(c[j])!=ans[i] and ans[i]!="a":
                x =1
# print(ans)

if ans[0]=="0" and n!=1:
    x=1
for i in range(len(ans)):
    if ans[i]=="a":
        ans[i]="0"
# print(ans)
if ans[0]=="0"and n!=1:
    ans[0]="1"
if x==0:
    print(int("".join(ans)))
else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define num(a) a-'0'
#define maxself(a,b) if(b>a)a=b
#define minself(a,b) if(b<a)a=b;
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"	
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n;
	cin>>n;
	vi d(n);
	rep(i,0,n){
		cin>>d[i];
	}
	sort(all(d));
	int mid=n/2;
	cout<<d[mid]-d[mid-1];
}

int main(){
	boost_io;
	solve();
	return 0;
}

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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=200*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
//int a[N+2];
int pref[N+2]={0};
int32_t  main(){
	IOS;
  int ans=0;
  int n;cin>>n;

  string s;cin>>s;
  if(n==1){cout<<"0\n";return 0;}
  memset(pref,0,sizeof(pref));
  if(s[0]=='.')pref[0]=1;
  else pref[0]=0;

  for(int i=1;i<n;++i){
    if(s[i]=='.')pref[i]=1+pref[i-1];
    else pref[i]=pref[i-1];
  }
  ans=pref[n-1];//all black cost 
  for(int i=0;i<n;++i){
    //uptil ith pos white remaining black 
    ans=min(ans,i+1-pref[i]+(pref[n-1]-pref[i]));
  }
  cout<<ans<<endl;

  return 0;
}



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

int main() { 
  int N;
  cin >> N;
 /* vector<vector<int>> a(2,vector<int>(N));
  for(int i = 0;i < 2; i++){
    for(int j = 0; j < N ; j++){
      cin >> a.at(i).at(j);
    }
  }
  int c;
  int b;
  int sum = 0;
  
  //なんでこれ通らない（-公- 怒）
  for(int i = 0;i < 2;i++){
    for(int j = 0; j < N;j++){    
     // if(a.at(i).at(j) > a.at(i + 1).at(j)){
     //   sum += (a.at(i).at(j) - a.at(i + 1).at(j));        
     // }  
      cout << a.at(i+1).at(j) <<endl;
    }
  } */
  vector<int> a(N);
  for(int i = 0;i < N; i++){
    cin >> a.at(i);
  }
  
  vector<int> b(N);
  for(int i = 0;i < N; i++){
    cin >> b.at(i);
  }
  
  int sum = 0;
  for(int i = 0; i < N;i++){
    if(a.at(i) > b.at(i)){
      sum += a.at(i) - b.at(i);
    }
  }
  cout << sum << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++)
    cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  cout << vec.at(N - 1) - vec.at(0) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long long MOD = pow(10, 9) + 7;

typedef long long ll;

int main() {
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << endl;

	return 0;
}



Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};


int main(void){
  int N, A, B, C, D;
  string S;
  cin >> N >> A >> B >> C >> D;
  A--, B--, C--, D--;
  cin >> S;
  if(A < C && C < B && B < D){
    bool l = 1;
    for(int i = A; i < C; i++){
      if(S[i] == '#' && S[i+1] == '#') l = 0;
    }
    for(int i = B; i < D; i++){
      if(S[i] == '#' && S[i+1] == '#') l = 0;
    }
    if(l){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  if(A < B && B < C && C < D){
    bool l = 1;
    for(int i = A; i < C; i++){
      if(S[i] == '#' && S[i+1] == '#') l = 0;
    }
    for(int i = B; i < D; i++){
      if(S[i] == '#' && S[i+1] == '#') l = 0;
    }
    if(l){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  if(A < B && B < D && D < C){
    bool l = 1;
    for(int i = A; i < C; i++){
      if(S[i] == '#' && S[i+1] == '#') l = 0;
    }
    for(int i = B; i < D; i++){
      if(S[i] == '#' && S[i+1] == '#') l = 0;
    }
    bool x = 0;
    for(int i = B-1; i <= D-1; i++){
      if(i+2 >= N) continue;
      if(S[i] == '.' && S[i+1] == '.' && S[i+2] == '.'){
        x = 1;
      }
    }
    if(x == 0){
      l = 0;
    }
    if(l){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }










}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    
    int ans = 0;
    rep(i, N) {
        while (h[i] > 0) {
            int cnt = i;
            while (cnt < N) {
                if (h[cnt] == 0) break;
                --h[cnt];
                ++cnt;
            }
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int temp=a;
    a=b;
    b=temp;
    temp=a;
    a=c;
    c=temp;
    System.out.println(a+" "+b+" "+c);
  }
}

Measured memory_bytes: 20820
#include <iostream>

using namespace std;

const int N = 100010;

int n, i, v[N], d[N];

inline int abs(int x) {
    return (x >= 0 ? x : (-x));
}

inline int minim(int x, int y) {
    return (x < y ? x : y);
}

int main(){
    cin >> n;
    for (i = 1; i <= n; ++i) {
        cin >> v[i];
    }
    d[1] = 0;
    d[2] = abs(v[2] - v[1]);
    for (i = 3; i <= n; ++i) {
        d[i] = minim(d[i - 1] + abs(v[i] - v[i - 1]), d[i - 2] + abs(v[i] - v[i - 2]));
    }
    cout << d[n] << "\n";
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long a = 100l;
        for (int i = 0 ; i < 100000 ; i++) {
            a *= 1.01;
            if (a >= x) {
                System.out.println(i + 1);
                return;
            }
        }
    }

}

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

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    int s = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s += a[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (s <= a[i] * 4 * m) cnt++;
    }
    if (m <= cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
uint64_t gcd(uint64_t a, uint64_t b);
uint64_t lcm(uint64_t a, uint64_t b);

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  uint64_t N;
  cin >> N;
  vector<pair<string, uint32_t>> Music(N);
  for (uint32_t i = 0; i < N; ++i) {
    cin >> Music[i].first >> Music[i].second;
  }
  string X;
  cin >> X;

  uint64_t res = 0;
  uint64_t num = 0;
  while (X != Music[num].first) {
    ++num;
  }
  ++num;
  while (num < N) {
    res += Music[num].second;
    ++num;
  }
  cout << res << endl;
  return 0;
}

uint64_t gcd(uint64_t a, uint64_t b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

uint64_t lcm(uint64_t a, uint64_t b) { return a * b / gcd(a, b); }

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int n; 
    cin >> n;

    vector<int>ans(10001);
    for(int i=0; i<10001; i++) ans[i]=0;

    int a, b, c;
    long long w=0;

    for(a=1; a<101; a++){
        for(b=a; b<101; b++){
            for(c=b; c<101; c++){
                w = a*a + b*b + c*c + a*b + b*c + c*a;
                    if(w>n){
                        break;
                    } else {
                        if(a==b && b==c) ans[w] += 1;
                        else if(a==b || b==c) ans[w] += 3;
                        else ans[w] += 6;
                }
            }
        }
    }

    for(int i=1; i<=n; i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    unordered_map<int,int> mp;
    vec<ll> a2;
    vec<ll> a4;
    rep(i, N){
        int a;cin >> a;
        ++mp[a];
        if(mp[a] == 2) a2.push_back(a);
        if(mp[a] == 4) a4.push_back(a);
    }
    sort(a2.rbegin(),a2.rend());
    sort(a4.rbegin(),a4.rend());
    ll ans = 0;
    if(a2.size()>=2) ans = a2[0]*a2[1];
    if(a4.size()>=1) ans = max(ans,a4[0]*a4[0]);
    cout << ans << endl;
}


Measured memory_bytes: 7140
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll either = 0;
  ll sum = 0;
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
    if (i > 1) {
      either ^= A.at(i);
    }
    else {
      sum += A.at(i);
    }
  }
  ll both = sum - either;
  if (both % 2 == 1 || both >= A.at(0) * 2 + 1) {
    cout << -1 << "\n";
    return 0;
  }
  both /= 2;
  if (either & both) {
    cout << -1 << "\n";
    return 0;
  }
  bitset<40> bs1(either);
  ll ans_small = 0;
  for (ll i = 39; i >= 0; --i) {
    if (bs1[i] == 1) {
      if (ans_small + pow(2, i) + both <= A.at(0)) {
        ans_small += pow(2, i);
      }
    }
  }
  if (both + ans_small == 0) {
    cout << -1 << "\n";
    return 0;
  }
  ll ans = A.at(0) - (both + ans_small);
  cout << ans << "\n";
}


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int p, q;

// 素因数分解 O(√N)
map<ll, int> pf(ll n) {
	map<ll, int> res;
	for (ll i = 2; i*i <= n; i++) {
		while (n%i==0) {
			++res[i];
			n /= i;
		}
	}
	if (n!=1) res[n]++;
	return res;
}

signed main() {
	cin >> p >> q;
	ll g = __gcd(p,q);
	p /= g, q /= g;
	map<ll,int> m = pf(q);
	ll res = 1;
	each(i,m) if (__gcd((ll)p,i.fi)==1) res *= i.fi;
	cout << res << ln;
}


Measured memory_bytes: 3216
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#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,accumulate
#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;

// clang++ main.cc -std=c++11 -stdlib=libc++

/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/

signed main(){
  int res = 0;
  int A, B;
  cin >> A >> B;

  int sum = 1;
  while (sum < B) {
    sum += (A - 1);
    res++;
  }

  cout << res << endl;

  return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979323846

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;

//==============================================
#define NIL -2000000050

struct node {
	int key;
	int parent = NIL;
	int left = NIL;
	int right = NIL;
};

node T[500050];

void insert(int z) {
	int y = NIL;
	int x = 0;

	if (z == 0) return;

	while (x != NIL) {
		y = x;
		if (T[z].key < T[x].key) {
			x = T[x].left;
		} else {
			x = T[x].right;
		}
	}

	T[z].parent = y;
	if (T[z].key < T[y].key) {
		T[y].left = z;
	} else {
		T[y].right = z;
	}
}

int find(int x, int k) {
	while (x != NIL && k != T[x].key) {
		if (k < T[x].key) {
			x = T[x].left;
		} else {
			x = T[x].right;
		}
	}

	return x;
}

int getMinimum(int x) {
	while (T[x].left != NIL) {
		x = T[x].left;
	}
	return x;
}

int getSuccessur(int x) {
	if (T[x].left != NIL) {
		return getMinimum(T[x].right);
	}

	int y = T[x].parent;
	while (y != NIL && x == T[y].right) {
		x = y;
		y = T[y].parent;
	}
	return y;
}

void deleteNode(int z) {
	int y;
	int x;

	z = find(0, z);
	if (T[z].left == NIL || T[z].right == NIL) {
		y = z;
	} else {
		y = getSuccessur(z);
	}

	if (T[y].left != NIL) {
		x = T[y].left;
	} else {
		x = T[y].right;
	}

	if (x != NIL) {
		T[x].parent = T[y].parent;
	}

	if (y == T[T[y].parent].left) {
		T[T[y].parent].left = x;
	} else {
		T[T[y].parent].right = x;
	}

	if (y != z) {
		T[z].key = T[y].key;
	}
}

void inorder(int x) {
	if (x == NIL) return;
	inorder(T[x].left);
	cout << " " << T[x].key;
	inorder(T[x].right);
}

void preorder(int x) {
	if (x == NIL) return;
	cout << " " << T[x].key;
	preorder(T[x].left);
	preorder(T[x].right);
}


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

	int n;
	cin >> n;

	string s;
	int v;
	REP(i, n) {
		cin >> s;

		if (s == "insert") {
			cin >> v;
			T[i].key = v;
			insert(i);
		} else if (s == "find") {
			cin >> v;
			if (find(0, v) != NIL) {
				cout << "yes" << "\n";
			} else {
				cout << "no" << "\n";
			}
		} else if(s == "delete") { 
			cin >> v;
			deleteNode(v);
		} else {
			inorder(0);
			cout << "\n";
			preorder(0);
			cout << "\n";
		}
	}
	return 0;
}

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

int main()
{
    long long a, b, k;
    cin >> a >> b >> k;

    if (k > 0)
    {
        if (a >= k)
        {
            a -= k;
            cout << a << " " << b << endl;
        }
        else
        {
            k -= a;
            a = 0;

            if (b >= k)
            {
                b -= k;
                cout << a << " " << b << endl;
            }
            else
            {
                cout << "0 0" << endl;
            }
        }
    }
    else
    {
        cout << a << " " << b << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n,maxi=0;
   scanf("%lld",&n);
   long long ba[n+1];
   for(int i=0;i<n;i++)scanf("%lld",&ba[i]);
   for(int i=0;i<n;i++)
   {
       maxi=__gcd(ba[i],maxi);
   }
   cout<<maxi<<endl;

}



Measured memory_bytes: 1152
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(ll i = z; i < n; i++)
//const int INF = 1<<29;
//const ll MOD = 1000000007;
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, 0, N) cin >> A.at(i);
    sort(all(A));
    
    int start = 0, end = A.at(N - 1);
    
    while(start != end){
        int mid = (start + end) / 2;
        if(mid == 0){
            start = 1;
            break;
        }
        int sum = 0;
        rep(i, 0, N){
            sum += ((A.at(i) - 1) / mid);
        }
        if(sum > K){
            start = mid + 1;
        }
        else{
            end = mid;
        }
    }
    cout << start << endl;
}


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

int n,m,tmp;
int maxv = 0;

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++){
    int sum = 0;
    for(int j=0;j<m;j++)cin >> tmp, sum += tmp;
    maxv = max(maxv,sum);
  }
  cout << maxv << endl;
}

Measured memory_bytes: 1164
{-
問の数が多すぎるため、次の問題を回答できる配列を用意しておく。
１～ｒ文字目までに、ACは何回現れるか。これをA_rとする。ただし、以下の計算の都合上A_0=0とする。
l,rのクエリに対して、だいたいで
A_r-A_(l-1)で近似できる。
これは正しいだろうか？
1~l-1について、l-1、lがACであったとき、これをA_(l-1)はカウントしないが、
A_rはカウントする。しかしこのACはl~rに含まれていないので、カウントしてはならない。

これを除去するために、次の動作をする。
クエリl,rに対して、l-1,lがACであるかどうかを見る。ACでないときは、
これを考える必要はないので、A_r-A_(l-1)で計算してよい。
これは、A_l A_l-1をみて、ふえているかどうかで判定できる。


もしACになっているときは、カウントが+1されているので、A_r-A_(l-1)-1で計算する

A_lをどのように計算すればよいだろうか？
先頭をはずしたものとzipする。これに2..をzipして、
0から末尾引数を回す。

これをアレイに格納する。
-}

import Data.Array
import Control.Monad

counter::String->[Int]
counter str = let doubled = map (\ (x,y) -> (x:y:[]) ) (zip str (tail str)) in
              (0:0:(eater 0 doubled))
            where eater _ []     = []
                  eater i (x:xs) = if x == "AC" then ((i+1):(eater (i+1) xs)) else i:(eater i xs)

gen_ar::String->Array Int Int
gen_ar str = let n = length str in listArray (0,n) (counter str)


solver::Array Int Int->Int->Int->Int
solver ar l r = (ar!r - ar!(l-1)) - (if ar!l - ar!(l-1) == 0 then 0 else 1)


main::IO()
main=do
  nq<-return.map read.words=<<getLine
  let n:q:[]= nq :: [Int]
  str<-getLine
  let ar = gen_ar str
  forM_ [1..q] (\_->print.(\ (l:r:_) -> solver ar l r ).map read.words=<<getLine)

Measured memory_bytes: 9628
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
bool scan(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef vo

typedef complex<double> P;

double cross(P a, P b) {
    return a.real() * b.imag() - a.imag() * b.real();
}

bool convex(vector<P> &v) {
	vector<bool> res(4);
	for (int i = 0; i < 4; i++)
		res[i] = cross(v[i] - v[(i + 1) % 4], v[(i + 1) % 4] - v[(i + 2) % 4]) <= 0;
	for (int i = 0; i < 3; i++)
		if (res[i] != res[i + 1])
			return false;
	return true;
}

int main() {
	int i = 0;
	vector<P> vp(4);
	for (double x, y; scanf("%lf,%lf,", &x, &y) != EOF;) {
		vp[i++] = P(x, y);
		if (i == 4){
			out(convex(vp) ? "YES" : "NO", '\n');
			i = 0;
		}
	}
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll dp[100010][3];

void show_table(ll I, ll J) {
  for (ll i = 0; i <= I; i++) {
    for (ll j = 0; j <= J; j++) {
      cout << dp[i][j] << " ";
    }
    cout << "" << endl;
  }
  cout << "" << endl;
}

int main() {
  fill(dp[0], dp[100005], -INF);
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;

  ll N;
  scanf("%lld", &N);

  vector<tuple<ll, ll, ll>> list;
  for (ll i = 0; i < N; i++) {
    ll a, b, c;
    scanf("%lld %lld %lld", &a, &b, &c);
    list.emplace_back(make_tuple(a, b, c));
    // cout << get<0>(list[i]) << endl;
  }

  for (ll n = 0; n < N; n++) {
    for (ll type = 0; type <= 2; type++) {
      ll vals[3];
      vals[0] = get<0>(list[n]);
      vals[1] = get<1>(list[n]);
      vals[2] = get<2>(list[n]);
      for (ll next_type = 0; next_type <= 2; next_type++) {
        if (type == next_type && n > 0) {
          continue;
        }

        ll plus = vals[next_type];
        dp[n + 1][next_type] = max(dp[n + 1][next_type], dp[n][type] + plus);
      }
    }
  }

  ll a = max(max(dp[N][0], dp[N][1]), dp[N][2]);
  cout << (a) << endl;
}


Measured memory_bytes: 8760
N = int(input())
S = input()
E = S.count('E')
W = 0
Min = N
for i in range(N):
  if S[i]=='E':
    E -= 1
  if i>0 and S[i-1]=='W':
    W += 1
  Min = min(Min,E+W)
print(Min)    
    
    

Measured memory_bytes: 42584
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long double a,b,c;
    cin>>a>>b>>c;
	long double eps=1.0E-14;
    if (sqrt(a)+sqrt(b)+eps<sqrt(c)) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  
  vector<tuple<string, int, int>> restaurants;
  
  for (int i = 0; i < N; i++) {
    string s;
    int p;
    
    cin >> s >> p;
    restaurants.push_back(make_tuple(s, (-1)*p, i+1));
  }
  
  sort(restaurants.begin(), restaurants.end());
  
  for (int i = 0; i < N; i++) {
    cout << get<2>(restaurants.at(i)) << endl;
  }
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define INF 3000000000000000000
#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;

int main(){
	int l,a,b,c,d,j=0,m=0,ans=0;
	scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
	j=a/c;
	if(a%c)j++;
	m+=b/d;
	if(b%d)m++;
	printf("%d\n",l-max(j,m));
	return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

int nums[2010];

int main() {
    int N, Z, W;
    cin >> N >> Z >> W;
    
    rep1(i,N) cin >> nums[i];
    
    int maxv = abs(nums[N]-W);
    if( N>1 && abs(nums[N-1]-nums[N])>maxv ) maxv = abs(nums[N-1]-nums[N]);
    
    cout << maxv << endl;
}

Measured memory_bytes: 256
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;

const int N = 6e5 + 5;
int t;
int c[15];
int a[15][15];
int now[15];
int main()
{
	int n, m, x;
	scanf("%d%d%d", &n, &m, &x);

	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &c[i]);
		for (int j = 1; j <= m; ++j)
			scanf("%d", &a[i][j]);
	}


	int res = 2e9;
	for (int i = 0; i < (1 << n); ++i)
	{
		int tres = 0;
		memset(now, 0, sizeof now);
		for (int j = 0; j < n; ++j)
		{
			if (i >> j & 1)
			{
				tres += c[j + 1];
				for (int k = 1; k <= m; ++k)
					now[k] += a[j + 1][k];
			}
		}

		bool flag = true;
		for (int j = 1; j <= m; ++j)
		{
			if (now[j] < x)
				flag = false;
		}

		if (flag)
			res = min(res, tres);
	}

	if (res == 2e9)
		printf("%d\n", -1);
	else
		printf("%d\n", res);

	return 0;
}





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

int H, W, D, Q;
int A_inv[90000];
long long dist_memo[90000];

int dist(int p, int q){
    int dx = (A_inv[p]/W) - (A_inv[q]/W);
    int dy = (A_inv[p]%W) - (A_inv[q]%W);
    return max(dx, -dx) + max(dy, -dy);
}


int main(){
    cin >> H >> W >> D;
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            int A;
            cin >> A;
            A--;
            A_inv[A] = h*W + w;
        }
    }

    int jump_cnt = (H*W-1)/D;

    for(int start = 0; start < D; start++){
        dist_memo[start * (jump_cnt+1)] = 0;
        for(int jc = 1; jc <= jump_cnt && (start + jc*D) < H*W; jc++){
            dist_memo[start * (jump_cnt+1) + jc] = dist_memo[start * (jump_cnt + 1) + jc - 1] + dist(start + D * jc, start + D * (jc-1));
        }
    }


    /*for(int start = 0; start < D; start++){
        for(int jc = 0; jc <= jump_cnt; jc++){
            cout << dist_memo[start*(jump_cnt+1) + jc] << " ";
        }
        cout << endl;
        }*/

    cin >> Q;
    for(int q = 0; q < Q; q++){
        int L, R;
        cin >> L >> R;
        L--;
        R--;
        cout << dist_memo[(L%D)*(jump_cnt + 1) + (R - (L%D))/D] - dist_memo[(L%D)*(jump_cnt+1) + (L - (L%D))/D]<< endl;
    }
}



                

Measured memory_bytes: 2176
n = int(input())
s = input()

w = {-1: 'W', 1: 'S'}
p = {1:'o', -1:'x'}
lst = [[1, 1], [-1, -1], [1, -1], [-1, 1]]

tmp = [0 for i in range(n+1)]
for a in lst:
    tmp[0] = a[0]
    tmp[1] = a[1]
    for i in range(1,n):
        tmp[i+1] = tmp[i-1] if s[i] == p[tmp[i]] else (tmp[i-1] * -1)
    if tmp[0] == tmp[-1]:
        flag = 1 if s[0] == p[tmp[0]] else -1
        if tmp[-2] == tmp[1] * flag:
            tmp.pop()
            print(''.join(map(w.get, tmp)))
            break
else:
    print(-1)


Measured memory_bytes: 4860
n, c, k = map(int, input().split())
t_list = list()
for t in range(n):
    t_list.append(int(input()))

t_list.sort()

ans = 1
c_limit = 1
t_limit = t_list[0] + k

for i in range(1, n):
    t = t_list[i]
    # 乗客が前の客の時間制限より大きいか、すでにバスが定員以上なら
    if t > t_limit or c_limit >= c:
        ans += 1
        c_limit = 1
        t_limit = t + k
    else:
        c_limit += 1

print(ans)


Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = 998244353;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

ll gcd(ll p, ll q){
    if(q==0) return p;
    else return gcd(q, p%q);
}

int main() {
    ll n, a[MAX_N], memo[2][MAX_N]{}, g = 0, ans = 0;
    cin >> n;
    REP(i,n) cin >> a[i];
    REP(i,n){
        g = gcd(a[i],g);
        memo[0][i+1] = g;
    }
    g = 0;
    REPR(i,n-1){
        g = gcd(a[i],g);
        memo[1][i] = g;
    }
    REP(i,n){
        ans = max(ans, gcd(memo[0][i],memo[1][i+1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll              long long int
#define vi              vector< int >
#define vll             vector< ll >
#define vc              vector< char >
#define vs              vector< string >
#define pb              push_back
#define all(v)          v.begin(), v.end()
#define PI              acos(-1.0)  // 3.1415926535897932
#define yes             cout << "yes" << endl
#define no              cout << "no" << endl
#define YES             cout << "YES" << endl
#define NO              cout << "NO" << endl

int main()
{
    ll x=100, y, m=0;
    cin >> y;
    while(1)
    {
        x+=(x/100);
        m++;
        if(x>=y)
        {
            break;
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int M, D;
	cin >> M >> D;

	int ans = 0;
	for (int m = 1; m <= M; ++m) {
		for (int d = 1; d <= D; ++d) {
			int dd = d;
			int d1 = dd % 10;
			dd /= 10;
			int d2 = dd % 10;

			if (d1 >= 2 && d2 >= 2 && d1 * d2 == m) {
				++ans;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

int main() 
{
	fast;
	ll x,a,b;
	cin>>x>>a>>b;
	ll t = x-a;
	t += b;
	if(t <= x)
		cout << "delicious";
	else if(t > x && t-x <= x )
		cout << "safe";
	else
		cout << "dangerous";
 	return 0;	
}

Measured memory_bytes: 256
import bisect

A, B, Q = map(int,input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
x = [int(input()) for i in range(Q)]

for e in x:
    b, d = bisect.bisect_right(s,e), bisect.bisect_right(t,e)
    a, c = b-1, d-1
    ans = INF
    for S in [s[a],s[b]]:
        for T in [t[c],t[d]]:
            d1, d2 = abs(S-e) + abs(T-S), abs(T-e) + abs(S-T)
            ans = min(ans, d1, d2)
    print(ans)

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


int main()
{
	int n,m,a[105],sum=0;
	cin>>n>>m;
	for(int i=1;i<=n;++i) {
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+1,a+n+1);
	for(int i=n;i>=n-m+1;--i) {
		if(a[i]*4*m<sum) {
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){ll ans=1;rrp(i,n-r+1,n+1){ans*=i;ans%=mod;}return ans/=fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n,k;
 cin>>n>>k;
  
 ll bef=n+1;
 ans=0;
 if(n%k==0){
  puts("0");return 0;
 }
 ans=n;
 ans=min(abs(n-(n/k)*k),abs(n-(n/k+1)*k));
 pr(ans);  
return 0;}


Measured memory_bytes: 3600