akhauriyash/Code-Regression huggingface dataset:
// Created by martinezdiego on 27/5/19

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  int a, p;
  cin >> a >> p;
  int pieces = p + a*3, count = 0;
  while (pieces >= 2) count ++, pieces -= 2;
  cout << count << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        int n = Integer.parseInt(sc.nextLine());
        int[] targetArray = new int[n + 1];
        String[] input = sc.nextLine().split(" ");
        for(int i = 0; i < n; i++) targetArray[i] = Integer.parseInt(input[i]);

        // 空読み
        sc.nextLine();
        int[] searchNums = Arrays.stream(sc.nextLine().split(" "))
                                               .mapToInt(s -> Integer.parseInt(s))
                                               .toArray();

        System.out.println(linearSearch(targetArray, searchNums));

    }

    private static int linearSearch(int[] targetArray, int[] searchNums) {

        int targetEnd = targetArray.length - 1;
        int cnt = 0;

        for(int num: searchNums) {

            int i = 0;
            targetArray[targetEnd] = num;
            while(targetArray[i] != num) {
                i++;
            }
            if(i != targetEnd) {
                cnt++;
            }

        }

        return cnt;
    }

}



Measured memory_bytes: 33888
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
//4 -8 -1 -2  s = 4+8+1+2  - 2*minval--> 4+8-1+2

void solve(){
	int n; cin >> n;
	ll a[n], neg = 0, s = 0, m = infll;
	FOR(n){
		cin >> a[i];
		s += abs(a[i]);
		if(a[i] < 0) ++neg;
		m = min(m,abs(a[i]));
	}
	if(neg&1){
		s -= 2*m;
	}
	cout << s;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 4428
a = list(map(int,input().split()))
h = a[0]
w = a[1]
li=[input() for i in range(h)]

ans = 0
minans = 0
flag = 0
row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            row[i]=True
            col[j]= True
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(li[i][j],end ="")
                
        print()

Measured memory_bytes: 4468
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int year,month,day;
	while(cin>>year>>month>>day){
		if(year<1868||year==1868&&month<9||year==1868&&month==9&&day<8){
			cout<<"pre-meiji\n";
		}else if(year<1912||year==1912&&month<7||year==1912&&month==7&&day<30){
			cout<<"meiji "<<year-1867<<" "<<month<<" "<<day<<endl;
		}else if(year<1926||year==1926&&month<12||year==1926&&month==12&&day<25){
			cout<<"taisho "<<year-1911<<" "<<month<<" "<<day<<endl;
		}else if(year<1989||year==1989&&month<1||year==1989&&month==1&&day<8){
			cout<<"showa "<<year-1925<<" "<<month<<" "<<day<<endl;
		}else{
			cout<<"heisei "<<year-1988<<" "<<month<<" "<<day<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, k;
  cin >> n >> k;
  vi ok(n + 1, false);
  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      ok[a] = true;
    }
  }
  int ans = 0;
  rep2(i, 1, n + 1) if(ok[i] == false) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <utility>
#include <numeric>
#include <iomanip>
#include <locale>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <cmath>

using namespace std;

vector<int> read();
int think(vector<int> *);
void write(int);

int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  auto input = read();
  auto output = think(&input);
  write(output);

  return 0;
}

vector<int> read() {
  int n, length;
  auto listOfLength = vector<int>();

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &length);
    listOfLength.push_back(length);
  }
  return listOfLength;
}

int think(vector<int> *input) {
  int n = input->size();
  bool debug = false;

  sort(input->begin(), input->end());

  if (debug) {
    for (auto e : *input) {
      cout << e << " ";
    }
    cout << endl;
  }

  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      auto sumOfAandB = input->at(i) + input->at(j);
      auto itr = lower_bound(input->begin() + j + 1, input->end(), sumOfAandB);
      auto d = distance(input->begin() + j + 1, itr);
      if (d > 0) {
        count += d;
      }
      if (debug) {
        cout << i << " " << j << " " << distance(input->begin() + j + 1, itr) << endl;
      }
    }
  }

  return count;
}

void write(int output) {
  printf("%d\n", output);
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}


int main(){
  ld X; cin >> X;
  ld now = 100; int ans = 0;

  while (now < X){
    now = now / 100 * 101;
    now = ll(now);
    ans++;
  }
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 3732
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#define _GLIBCXX_DEBUG
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int main() {
    int X,A,B;cin >> X >> A >> B;
    X -= A;
    cout << X%B << endl;


    

    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
using namespace std;


int main (void)
{
    int h, w;
    int i, j;
    
    while (scanf("%d %d", &h, &w) != EOF && h != 0 || w != 0){
        for (i=1; i<=h; i++){
            for (j=1; j<=w; j++){
                if (i%2 == 0){
                    if (j%2 != 0)
                        printf(".");
                    else
                        printf("#");
                }
                else{
                    if (j%2 != 0)
                        printf("#");
                    else
                        printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 1000
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

ll dp[100005];
int main()
{
    ll t,x,n,i,j,k,l,mn=0, mx=0, m;
    cin>>n>>x>>m;
    ll ans=0;
    dp[1]=x;
    ans+=x;

    for(int i=2; i<=min(n,m); i++)
        dp[i]=(dp[i-1]*dp[i-1])%m, ans+=dp[i];


    if(n>m)
    {
        ll r=(dp[m]*dp[m])%m;
        int in=0;
        for(int i=1; i<=m; i++)
            if(dp[i]==r)
            {
                in=i;
                break;
            }

        ans=0;
        ll sum=0;
        for(int i=1; i<in; i++)
         ans+=dp[i];

        int cy=m-in+1;
        int koybar= (n-in+1)/cy;
        int rem=(n-in+1)%cy;
        for(int i=in; i<=m; i++)
            sum+=dp[i];
        ans+= sum*koybar;

        for(int i=in; i<in+rem; i++)
            ans+=dp[i];

    }
    cout<<ans;
}



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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i, k , n) for(int i = k; i <= n; i++)
typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


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

   int n, m, x; cin >> n >> m >> x;
   bool a[200] = {};
   rep(i,m)
   {
      int k; cin >> k;
      a[k] = true;
   }
   int sum1= 0, sum2 = 0;
   for(int i = x; i <= n; i++)
   {
      if(a[i])
         sum1++;
   }
   for(int i = 0; i <= x; i++)
   {
      if(a[i])
         sum2++;
   }
   cout << min(sum1, sum2) << nl;


   return 0;
}


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

template <ll Mod>
struct modint {
  ll n;

  modint(const ll x = 0) : n(x) {
    while (n < 0) n += Mod;
    n %= Mod;
  }
  modint operator+(const modint r) const { return modint(*this) += r; }
  modint operator-(const modint r) const { return modint(*this) -= r; }
  modint operator*(const modint r) const { return modint(*this) *= r; }
  modint operator/(const modint r) const { return modint(*this) /= r; }
  modint &operator+=(const modint r) {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  modint &operator-=(const modint r) {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  modint &operator*=(const modint r) {
    n = n * r.n % Mod;
    return *this;
  }
  modint &operator/=(const modint r) { return *this *= r.inv(); }
  modint pow(ll x) const {
    modint<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  modint inv() const { return pow(Mod-2); }
  friend ostream& operator<<(ostream& os, const modint& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, modint& obj) { 
    ll t;
    is >> t;
    obj = modint(t);
    return is;
  }
};
constexpr ll mod = 1000000007;
using mint = modint<mod>;

// T modint
template<class T>
struct Combination {
  vector<T> fact, inv_fact;
  Combination(ll n) : fact(n+1), inv_fact(n+1) {
    fact[0] = T(1);
    for (ll i = 1; i <= n; i++) fact[i] = fact[i-1] * static_cast<T>(i);
    inv_fact[n] = fact[n].inv();
    for (ll i = n; i > 0; i--) inv_fact[i-1] = inv_fact[i] * static_cast<T>(i);
  }

  T P(ll n, ll k) const {
    return fact[n] * inv_fact[n-k];
  }

  T C(ll n, ll k) const {
    if(n < k or k < 0) return T(0);
    return fact[n] * inv_fact[n-k] * inv_fact[k];
  }

  T H(ll n, ll k) const {
    return C(n+k-1, n-1);
  }
};

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

  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  Combination<mint> comb(n);
  mint ans(0);
  rep(i, n) {
    ans += mint(a[i]) * comb.C(i, k-1);
    ans -= mint(a[i]) * comb.C(n-1-i, k-1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
import sys

n, m, q = map(int, input().split())
dp1 = [[0] * (m + 1) for _ in range(n + 1)]
dpv = [[0] * (m + 1) for _ in range(n + 1)]
dph = [[0] * (m + 1) for _ in range(n + 1)]

prev_s = '0' * m

for i in range(n):
    s = input()
    for j in range(m):
        is1 = s[j] == '1'
        additional = 0

        if is1:
            dp1[i + 1][j + 1] = 1

            if i > 0 and prev_s[j] == '1':
                dpv[i + 1][j + 1] = 1
            if j > 0 and s[j - 1] == '1':
                dph[i + 1][j + 1] = 1
    prev_s = s

for i in range(1, n + 1):
    for j in range(1, m + 1):
        dp1[i][j] += dp1[i][j - 1]
        dpv[i][j] += dpv[i][j - 1]
        dph[i][j] += dph[i][j - 1]

for j in range(1, m + 1):
    for i in range(1, n + 1):
        dp1[i][j] += dp1[i - 1][j]
        dpv[i][j] += dpv[i - 1][j]
        dph[i][j] += dph[i - 1][j]

mp = map(int, sys.stdin.read().split())
buf = []
for x1, y1, x2, y2 in zip(mp, mp, mp, mp):
    cnt1 = dp1[x2][y2] - dp1[x1 - 1][y2] - dp1[x2][y1 - 1] + dp1[x1 - 1][y1 - 1]
    ver1 = dpv[x2][y2] - dpv[x1][y2] - dpv[x2][y1 - 1] + dpv[x1][y1 - 1]
    hor1 = dph[x2][y2] - dph[x1 - 1][y2] - dph[x2][y1] + dph[x1 - 1][y1]

    buf.append(cnt1 - ver1 - hor1)

print('\n'.join(map(str, buf)))


Measured memory_bytes: 249992
#include <stdio.h>

int main(void)
{
  int k,x;
  scanf("%d %d", &k, &x);

  int c = x-k+1;
  int d = x+k-1;
  if(c < -1000000)c = -1000000;
  if(d >  1000000)d = 1000000;

  for(;c<=d;c++)printf("%d ", c);
  
  return 0;
}


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

int main(){
  int N,i,ans;
  string S;
  cin>>N;
  cin>>S;
  
  ans=0;
  
  for(i=2;i<N;i++){
    if(S.at(i-2)=='A'&&S.at(i-1)=='B')
    {
      if(S.at(i)=='C') ans++;
    }
  }
  cout<<ans;  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int a;
int main()
{
    scanf("%d",&a);
    if(a<1200)printf("ABC");
    else
    if(a<2800)printf("ARC");
    else
    printf("AGC");
    return 0;
}

Measured memory_bytes: 256
k = int(input())

num = 7 % k
ans = 1
mod = [0 for _ in range(k)]
mod[num] = 1
while(num):
    num = (num * 10 + 7) % k
    if mod[num] > 0:
        ans = -1
        break
    ans += 1
    mod[num] += 1

print(ans)


Measured memory_bytes: 17012
package main
 
import (
	"fmt"
  "bufio"
  "os"
	"strings"
  "strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
func main() {

  var n int
  fmt.Scanf("%d", &n)

  var ws []string
  if sc.Scan() {
    wss := sc.Text()
    ws = strings.Split(wss, " ")
  }

  var sum float64
  sumSeq := [] float64{}
  for i:=0; i<n; i++ {
    welem, _ := strconv.ParseFloat(ws[i],64)
    sum = sum + welem
    sumSeq = append(sumSeq, sum)
  }
  sum_half := sum/2

  // fmt.Println(sumSeq)
  var diff_prev float64
  var diff float64
  var result float64
  for i:=0; i<n; i++ {
    diff = sum_half - sumSeq[i]
    // fmt.Println("sum_half",sum_half)
    // fmt.Println("diff_prev",diff_prev)
    // fmt.Println("diff",diff)
    if diff < 0 {
      if (i == 0) {
        result = -diff
      } else {
        if (-diff < diff_prev) {
          result = -diff
        } else {
          result = diff_prev
        }
      }
      break
    }
    diff_prev = diff
  }
  fmt.Println(result*2)
}




Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef std::vector<ll> lls;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 998244353L;
template<class T> inline void chmin(T& a, T b) { if (a > b) a = b; }
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> inline T MaxE(vector<T>& v, ll S, ll E) { T m = v[S]; for (ll i = S; i <= E; i++)chmax(m, v[i]); return m; }//v[S]～v[E]の最大値
template<class T> inline T MinE(vector<T>& v, ll S, ll E) { T m = v[S]; for (ll i = S; i <= E; i++)chmin(m, v[i]); return m; }
template<class T> inline T MaxE(vector<T>& v, ll N) { return MaxE(v, 0, N - 1); } //先頭N個中の最大値
template<class T> inline T MinE(vector<T>& v, ll N) { return MinE(v, 0, N - 1); } //先頭N個中の最小値
template<class T> inline T MaxE(vector<T>& v) { T m = v[0]; for (T e : v)chmax(m, e); return m; }
template<class T> inline T MinE(vector<T>& v) { T m = v[0]; for (T e : v)chmin(m, e); return m; }


void cinv(lls& llVec, ll n, bool to_0_origin = false) {
	ll val;
	llVec.reserve((size_t)(n));
	for (ll i = 0; i < n; i++) {
		cin >> val;
		if (to_0_origin) val--;
		llVec.push_back(val);
	}
}

int main()
{
	ll N, W;
	cin >> N >> W;
	lls w(N), v(N);
	for (ll i = 0; i < N; i++) {
		ll ww, vv;
		cin >> ww >> vv;
		w[i] = ww;
		v[i] = vv;
	}

	//テーブル初期化
	std::vector<lls> tblAll(N, lls(W + 1, -INF));
	tblAll[0][0] = 0;
	tblAll[0][w[0]] = v[0];

	//貰うDPで計算
	for (ll i = 1; i < N; i++) {
		for (ll ww = 0; ww <= W; ww++) {
			chmax(tblAll[i][ww], tblAll[i - 1][ww]);
			if (ww - w[i] >= 0) {
				chmax(tblAll[i][ww], tblAll[i - 1][ww - w[i]] + v[i]);
			}
		}
	}

	cout << MaxE(tblAll[N - 1]) << '\n';

	return 0;
}


Measured memory_bytes: 79360
#include <stdio.h>
typedef struct _point{
	int i;
	int j;
}POINT;

POINT DEC(int i);
int ENC(int i,int j);

int MAP[92][92];
int m,n;

int main(){
	int i,j,k;
	int len_max,len;
	int route[90*90];
	
	while(1){
		scanf("%d\n",&m);
		scanf("%d\n",&n);
		if(!m&&!n)break;

		for(i=0;i<92;i++)for(j=0;j<92;j++)MAP[i][j]=0;

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

		len_max=0;
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				if(MAP[i][j]){
					for(k=0;k<90*90;k++)route[k]=0;
					route[0]=ENC(i,j);
					len=DFS(route);
					if(len>len_max)len_max=len;
				}
			}
		}

		printf("%d\n",len_max);
	}
	return 0;
}


POINT DEC(int i){
	POINT P;
	P.i=i/92;
	P.j=i%92;
	return P;
}
int ENC(int i,int j){
	return i*92+j;
}


int DFS(int route[]){

	static int L;
	int route0[90*90];
	int i,j,now;
	int k;
	for(now=0;route[now]!=0;now++)route0[now]=route[now];
	if(now==1)L=1;
	now--;

	int u,d,l,r;
	u=d=l=r=1;
	if(MAP[DEC(route0[now]).i-1][DEC(route0[now]).j  ]==0)u=0;
	for(k=0;k<=now;k++)if(route0[k]==route0[now]-92)u=0;
	if(MAP[DEC(route0[now]).i+1][DEC(route0[now]).j  ]==0)d=0;
	for(k=0;k<=now;k++)if(route0[k]==route0[now]+92)d=0;
	if(MAP[DEC(route0[now]).i  ][DEC(route0[now]).j-1]==0)l=0;
	for(k=0;k<=now;k++)if(route0[k]==route0[now]-1)l=0;
	if(MAP[DEC(route0[now]).i  ][DEC(route0[now]).j+1]==0)r=0;
	for(k=0;k<=now;k++)if(route0[k]==route0[now]+1)r=0;

	if(!u&&!d&&!l&&!r){
		if(now+1>=L)L=now+1;
		return L;
	}

	if(u){
		route0[now+1]=route0[now]-92;
		DFS(route0);
	}
	if(d){
		route0[now+1]=route0[now]+92;
		DFS(route0);
	}
	if(l){
		route0[now+1]=route0[now]-1;
		DFS(route0);
	}
	if(r){
		route0[now+1]=route0[now]+1;
		DFS(route0);
	}

	return L;
}

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

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

    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());

    int ans = 1;

    if (n%2) {
        if (a.at(0) == 0) {
            for (int i=1; i<n; i++) {
                if (a.at(i) == ((i+1)/2)*2) {
                    if (i%2 == 0) ans = ans * 2 % 1000000007;
                } else {
                    ans = 0;
                    break;
                }
            }
        } else {
            ans = 0;
        }
    } else {
        for (int i=0; i<n; i++) {
            if (a.at(i) == (i/2)*2 + 1) {
                if (i%2) ans = ans * 2 % 1000000007;
            } else {
                ans = 0;
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm> 
#include <iostream>
#include <cstdio>

using namespace std;

int n,m,ans; 
struct node
{
	int x;
	bool b;
}a[200010];

int cmp(node a,node b)
{
	return a.x>b.x;
}

int main() {
    /*int a,b;
    cin >> a >> b;
    cout << a+b;*/
    scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i+n].x),
		a[i+n].b=1;
	sort(a+1,a+1+n*2,cmp);
	for(int i=1;i<=n*2;i++)
	{
		if(a[i].b)
		{
			m-=a[i].x;
			ans++;
		}
		else
		{
			ans+=m/a[i].x;
			if(m%a[i].x!=0)ans++;
			m=0;
		}
		if(m<=0)
		{
			printf("%d\n",ans);
			return 0;
		}
	}
    return 0;
}


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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 100100;

bool vis[N][2];
ll n,mem[N][2],mod=1e9+7;
vector <int> adj[N];

ll dp(int i,int color,int v)
{
    ll &ret = mem[i][color];
    if( vis[i][color] )
        return ret;
    vis[i][color] = 1;

    ret = 1;

    for(auto &x:adj[i])
    {
        if( x == v )
            continue;

        if( color )
            ret = ret*dp(x,0,i)%mod;
        else
            ret = ret*(dp(x,0,i)+dp(x,1,i))%mod;
    }

    return ret;
}

int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n-1;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    printf("%lld\n",(dp(1,0,1)+dp(1,1,1))%mod);
}


Measured memory_bytes: 20732
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int m=101,M=0;
    Rep(i,0,100){
        if(i>=a&&i<=b&&i>=c&&i<=d){
            M=max(M,i);
            m=min(m,i);
        }
    }
    if(m==101||M==0) cout<<0<<"\n";
    else cout<<M-m<<"\n";
}

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

using namespace std;

const int M = 1046527;
const int L = 14;

char H[M][L];

int getChar(char ch)
{
    if( ch == 'A' ) return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

int getKey(char str[])
{
    int sum = 0, p = 1, i;
    for( i = 0; i < strlen(str); i++ ){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int main(){
    int n;
    scanf("%d", &n);
    
    for(int i = 0; i < M; i++){
        H[i][0] = '\0';
    }

    for(int i = 0; i < n; i++){
        char com[7];
        scanf("%s", com);
        char item[L];
        scanf("%s", item);
        int key = getKey(item);
        if(com[0] == 'i'){
            for(int j = 0; j < M; j++){
                int hash = ((key % M) + j * (1 + (key % (M - 1)))) % M;
                if(H[hash][0] == '\0'){
                    strcpy(H[hash], item);
                    break;
                }
                else if(strcmp(H[hash], item) == 0){
                    break;
                }
            }
        }
        else{
            for(int j = 0; j < M; j++){
                int hash = ((key % M) + j * (1 + (key % (M - 1)))) % M;
                if(H[hash][0] == '\0'){
                    printf("no\n");
                    break;
                }
                else if(strcmp(item, H[hash]) == 0){
                    printf("yes\n");
                    break;
                }
            }
        }
    }
}


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

int main(){
	int N,K;
  cin>>N>>K;
  vector<int> length(N);
  for(int i=0;i<N;i++)
    cin>>length.at(i);
  sort(length.begin(),length.end());
  reverse(length.begin(),length.end());
  int sum=0;
  for(int i=0;i<K;i++)
    sum+=length.at(i);
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>=b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<=b){
        a=b;
        return true;
    }
    return false;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(1<<N);
    rep(i,1<<N) cin >> A[i];
    vector<vector<ll>> dp1(1<<N,vector<ll>(N+1)),dp2(1<<N,vector<ll>(N+1));
    rep(i,1<<N) dp1[i][0]=A[i],dp2[i][0]=0;
    rep(j,N){
        rep(i,1<<N){
            dp1[i][j+1]=dp1[i][j],dp2[i][j+1]=dp2[i][j];
            if (i&(1<<j)){
                if (chmax(dp1[i][j+1],dp1[i&~(1<<j)][j])){
                    dp2[i][j+1]=dp1[i][j];
                    chmax(dp2[i][j+1],dp2[i&~(1<<j)][j]);
                }
                else{
                    chmax(dp2[i][j+1],dp1[i&~(1<<j)][j]);
                }
            }
        }
    }
    ll now=0;
    rep2(i,1,1<<N){
        chmax(now,dp1[i][N]+dp2[i][N]);
        cout << now << endl;
    }
}

Measured memory_bytes: 99328
#include <stdio.h>
#include <algorithm>

using namespace std;

int N;
int A[200000];
int dp0[200001];
int dpL[200001];
int dpM[200001];
int dpR[200001];
int dp1[200001];

void to(int *x, int y) {
    *x = min(*x, y);
}

int g(int x) {
    if (x == 0) return 2;
    return x % 2;
}

int h(int x) {
    return (x + 1) % 2;
}

int f() {
    for (int i = 0; i <= N; i++) {
        dpL[i] = 1e9;
        dpM[i] = 1e9;
        dpR[i] = 1e9;
        dp0[i] = 1e9;
        dp1[i] = 1e9;
    }
    dp0[0] = 0;
    dpL[0] = 0;
    dpM[0] = 0;
    dpR[0] = 0;
    dp1[0] = 0;
    for (int i = 0; i < N; i++) {
        to(&dp0[i + 1], dp0[i] + A[i]);
        to(&dpL[i + 1], dp0[i] + A[i]);
        to(&dpM[i + 1], dp0[i] + A[i]);
        to(&dpR[i + 1], dp0[i] + A[i]);
        to(&dp1[i + 1], dp0[i] + A[i]);

        to(&dpL[i + 1], dpL[i] + g(A[i]));
        to(&dpM[i + 1], dpL[i] + g(A[i]));
        to(&dpR[i + 1], dpL[i] + g(A[i]));
        to(&dp1[i + 1], dpL[i] + g(A[i]));

        to(&dpM[i + 1], dpM[i] + h(A[i]));
        to(&dpR[i + 1], dpM[i] + h(A[i]));
        to(&dp1[i + 1], dpM[i] + h(A[i]));

        to(&dpR[i + 1], dpR[i] + g(A[i]));
        to(&dp1[i + 1], dpR[i] + g(A[i]));

        to(&dp1[i + 1], dp1[i] + A[i]);
    }
    return dp1[N];
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    int ans = 1e9;
    ans = min(ans, f());
    reverse(A, A + N);
    ans = min(ans, f());
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 4864
N = int(input())

if N%4 == 0:
    print(*[(3*N)//4]*3)
else:
    for w in range(1, 3501):
        for n in range(w+1, 3501):
            if 4*n*w - w*N - n*N <= 0:
                continue
            elif (n*w*N) % (4*n*w - w*N - n*N) == 0:
                h = (n*w*N) // (4*n*w - w*N - n*N)
                print(h, n, w)
                exit()

Measured memory_bytes: 40556
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

double sq(double x) {return x*x;}

void solve()
{
	double x1,y1,x2,y2,x3,y3;
	cin>>x1>>y1>>x2>>y2>>x3>>y3;
	double a,b,c,d,e,f;
	a = x2-x1; b = y2- y1;
	a*=2; b*= 2;
	c = sq(x2)-sq(x1)+sq(y2)-sq(y1);
	d = x3-x1; e = y3- y1;
	d *=2; e *= 2;
	f = sq(x3)-sq(x1)+sq(y3)-sq(y1);
    double det = a*e - b * d;
    double x = 1 / det * (c * e - b * f);
    double y = 1 / det * (f * a - c * d);
    if(x < 1e-5 && -1e-5 < x) x = 0.0;
    if(y < 1e-5 && -1e-5 < y) y = 0.0;
	double r = sqrt(sq(x - x1) + sq(y - y1));

	printf("%.3lf %.3lf %.3lf\n",x,y,r);
}

int main(){

	int t;
	cin >> t;
    while(t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 400
#define mod 1000000007
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
using namespace std;
vector<ll> get_factors(ll n)
{
    ll i,j;
    vector<ll>ret;
    for(i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            ret.push_back(i);
        }
    }
    return ret;
}
void solve()
{
    ll n,i,j,ans=LONG_MAX;
    in(n);
    vector<ll>divs=get_factors(n);
    for(auto it:divs)
    {
        ans=min(ans,it+n/it-2);
    }
    cout<<ans<<'\n';
}
int main()
{

    gear_change;
    ll test=1;
    // in(test);
    while(test--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 384
n = int(input())
divs = [1]*(n + 1)
for i in range(3, n + 1, 2):
    for j in range(3, n + 1, 2):
        if i % j == 0:
            divs[i] = divs[i] + 1

print(len([x for x in range(len(divs)) if divs[x] == 8]))


Measured memory_bytes: 3060
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=True)

def check(s):
  ret=0
  for i,j in zip(a,f):
    ret+=max(0,i-s//j)
  return ret<=k

ok=10**12+1
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if check(mid):
    ok=mid
  else:
    ng=mid
print(ok)

Measured memory_bytes: 113648
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#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;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 9000000000000000000 //9e18:極めて大きい値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define LOGMAXR 18 // floor(log2(10^5)) + 1: 配列の最大のrangeのlog
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

int main(){
  string S, T;
  cin >> S >> T;
  if(T.substr(0, S.size()) == S){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())
 
int main() {
    string t;
    cin>>t;
    rep(i,t.size()) {
        if(t[i] == '?') {
            if(i == 0) {
                if(t[i+1] == 'D') t[i] = 'P';
                else t[i] = 'D';
            } else {
                t[i] = 'D';
            }
        }
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>

using namespace std;

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

    if(n ==1) cout << "Hello World" << endl;
    else{
        int a, b;
        cin >> a; cin >> b;
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct T {
    double a;
    int i;
}ar[10001];
bool cmp(T a, T b) {
    return a.a < b.a;
}
int main() {
    int n, t, a;
    cin >> n >> t >> a;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        ar[i].a = t - h * 0.006;
        ar[i].a = abs(ar[i].a - a);
        ar[i].i = i+1;
    }
    sort(ar, ar+n, cmp);
    cout << ar[0].i << "\n";

    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 N = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[M];
    int[] b = new int[M];
    int[] c = new int[M];
    for(int i = 0; i < M; i++) {
      a[i] = sc.nextInt() - 1;
      b[i] = sc.nextInt() - 1;
      c[i] = sc.nextInt();
    }
    int[][] dp = new int[N][N];
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        if(i != j) {
          dp[i][j] = 1000000;
        } else {
          dp[i][j] = 0;
        }
      }
    }
    for(int i = 0; i < M; i++) {
      dp[a[i]][b[i]] = Math.min(dp[a[i]][b[i]], c[i]);
      dp[b[i]][a[i]] = Math.min(dp[b[i]][a[i]], c[i]);
    }
    for(int k = 1; k <= N; k++) {
      for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
          dp[i][j] = Math.min(dp[i][j], dp[i][k - 1] + dp[k - 1][j]);
        }
      }
    }
    int ans = 0;
    for(int i = 0; i < M; i++) {
      if(dp[a[i]][b[i]] < c[i]) ans++;
    }
    System.out.println(ans);
  }
}

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

int main() {
	unsigned int k;
	char s[100];
	cin >> k;
	cin >> s;
	if (strlen(s) > k) {
		for (unsigned int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "...";
	}
	else cout << s;
}

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

vector<vector<int>> V;
vector<int> Map;
int ans=0, inf=1<<30;

void dfs (int prev, int now, int cnt) {
  Map[now]=cnt;
  for (auto i: V[now]) {
    if(Map[i]!=inf) continue;
    else {
      dfs(now, i, cnt);
    }
  }
}

int main() {
  int N, M; cin >> N >> M;
  V = vector<vector<int>>(N, vector<int>(0));
  Map = vector<int>(N, inf);
  for (int i=0;i<M;i++) {
    int x, y, z; cin >> x >> y >> z;
    V[x-1].push_back(y-1);
    V[y-1].push_back(x-1);
  }
  
  ans=0;
  for(int i=0; i<N; i++) {
    if(Map[i]==inf) {dfs(-1,i,ans);ans++;}
  }
  cout << ans << "\n";
}

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

using namespace std;

typedef long long ll;

const int N = 200010;


deque<char> q;

int n,seen = 0;
string s;

int main() {
	//freopen("input.txt", "r", stdin);
	cin >> n >> s;
	for (int i = 0; i < s.size(); ++i){
		if(s[i] == ')'){
			if(seen){
				seen--;
			}else{
				q.push_front('(');
			}
		}else{
			seen++;
		}
		q.push_back(s[i]);
	}
	while(seen--){
		q.push_back(')');
	}
	while(q.size()){
		printf("%c", q.front());
		q.pop_front();
	}
	puts("");
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define INF 10000000

int main(){
  int n,p[101],m[101][101];
  int i,j,k,l,q;

  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d%d",&p[i-1],&p[i]);

  for(i=1;i<=n;i++) m[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<j;k++){
	q = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j] = (m[i][j]>q) ? q : m[i][j];
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}



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

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    vector<ll> AB(N,0);
    for (int i=0;i<N;i++){
        AB[i]  = A[i] + B[i];
    }
    sort(AB.begin(),AB.end());
    ll res = 0;
    for (int i=0;i<N;i++){
        res -= B[i];
    }
    for (int i=N-1;i>=0;i-=2){
        res += AB[i];
    }

    printf("%lld\n",res);

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long N , M; cin >> N >> M;
	long res;

	res = (N - 2) * (M - 2);

	if (N != 1 && M == 1) res = N - 2;
	if (N == 1 && M != 1) res = M - 2;
	if (N == 1 && M == 1) res = 1;

	cout << res << endl;

}

Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new File("c:\\0509-input.txt"));

		while (true) {
			int n = scan.nextInt();
			if (n == 0)
				break;
			run(n, n, "");
		}

		scan.close();
		System.exit(0);
	}

	private static void run(int n, int max, String s) {
		// System.out.println(n + " " + max + " " + s);
		if (n == 0) {
			System.out.println(s);
			return;
		}
		for (int i = Math.min(n, max); i > 0; i--) {
			if (s.length() == 0) {
				String ss = s.concat(String.valueOf(i));
				run(n - i, i, ss);
			} else {
				String ss = s.concat(" ").concat(String.valueOf(i));
				run(n - i, i, ss);
			}
		}
	}
}

Measured memory_bytes: 47016
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pair = Tuple!(long, "cost", long, "num");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto l = aryread();
    l.sort();
    long ans;
    foreach (i; iota(n))
    {
        foreach (j; iota(i + 1, n))
        {
            auto minidx = max(l.upper_bound(l[j] - l[i]), j);
            auto maxidx = l.lower_bound(l[j] + l[i]);
            if(maxidx != j)
                ans += maxidx - minidx;
    }
}
ans.writeln();
}

// limitより小さい限界のインデックス
auto lower_bound(T)(T[] ary, T limit)
{
    long ok = -1, ng = ary.length;
    while (abs(ng - ok) > 1)
    {
        auto mid = (ok + ng) / 2;
        if (ary[mid] >= limit)
            ng = mid;
        else
            ok = mid;
    }
    return ok;
}

// limitより大きい最小のインデックス
auto upper_bound(T)(T[] ary, T limit)
{
    long ok = ary.length, ng = -1;
    while (abs(ok - ng) > 1)
    {
        auto mid = (ok + ng) / 2;
        if (ary[mid] > limit)
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2428
from collections import defaultdict as dd
from sys import exit
from operator import mul
from functools import reduce


x = int(input())
X = x

if x == 1:
    print(0, -1)
    exit()

dic = dd(int)
for i in range(2, int(x**0.5) + 3):
    while x % i == 0:
        x //= i
        dic[i] += 1
if x != 1:
    dic[x] = 1

#print(dic)

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def serch(dif):
    target = X // dif
    for b in range(-1000, 1000):
        if 5 * b**4 + 10 * dif * b**3 + 10 * dif**2 * b**2 + 5 * dif**3 * b + dif**4 == target:
            print(-(b), -b-dif)
            exit()
    return None

pattern = [1]
for key in dic.keys():
    temp = []
    for num in range(dic[key] + 1):
        for i in pattern:
            temp.append(i * key**num)
    pattern = temp
#print(pattern)

for num in pattern:
    serch(num)



"""
b = -1
dif = 3
print(5 * b**4 + 10 * dif * b**3 + 10 * dif**2 * b**2 + 5 * dif**3 * b + dif**4)
"""

Measured memory_bytes: 68708
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i <= (n); i++)
using namespace std;
typedef pair<int, int> PII;

int M, T, P, R, m, t, p, j, q[51][11];
PII s[51];

int main(void) {
  while(cin >> M >> T >> P >> R, M || T || P || R) {
    REP(i, 1, T) {
      s[i] = PII(P, 0);
      REP(j, 1, P) q[i][j] = 0;
    }

    REP(i, 1, R) {
      cin >> m >> t >> p >> j;
      if(j == 0) {
        if(q[t][p] >= 0) {
          s[t].first--;
          s[t].second += q[t][p] * 20 + m;
        }
      } else {
        q[t][p]++;
      }
    }

    REP(i, 1, T) {
      s[i].first = s[i].first * 100000000 + s[i].second;
      s[i].second = T - i;
    }
    sort(s + 1, s + T + 1);
    REP(i, 1, T) {
      cout << (T - s[i].second);
      if(i < T) cout << (s[i].first == s[i + 1].first ? '=' : ',');
    }
    cout << endl;
  }
}

Measured memory_bytes: 3080
function main(input) {
  const formatted_input = input.split('\n')[0].split(' ').map( x => parseInt(x, 10) );

  const A = formatted_input[0];
  const B = formatted_input[1];
  const C = formatted_input[2];

  if( (A<C && C<B) || (A>C && C>B) ){
    console.log('Yes');
  }else{
    console.log('No');
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
// 01:34:40 > 




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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, H; cin >> N >> H;
    vector<ll> a(N), b(N);
    rep(i, N){cin >> a.at(i) >> b.at(i);}
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());

    ll amax = a.at(0);
    ll ind = 0;
    ll cost = 0;
    while (true){
        if (cost < H && ind < b.size() && b.at(ind) > a.at(0)){
            cost += b.at(ind);
            ind++;
        } else {
            break;
        }
    }
    if (cost >= H){
        cout << ind << endl;
    } else {
        cout << ind + (ll)(ceil((H - cost) / (double)(a.at(0)))) << endl;
    }
    // 先にどの刀まで投げるか確定させる
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

import sys
from copy import deepcopy

def input(): return sys.stdin.readline().strip()
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W,K=MAP()
orgn=[[0]*W for i in range(H)]
for i in range(H):
    nums=input()
    for j in range(W):
        orgn[i][j]=int(nums[j])

# ブロックが落ちる動き
def drop():
    for i in range(H-1, 0, -1):
        for j in range(W):
            if grid[i][j]==0 and grid[i-1][j]!=0:
                k=i
                while k<H and grid[k][j]==0:     
                    grid[k][j]=grid[k-1][j]
                    grid[k-1][j]=0
                    k+=1

# 揃ったところを消して合計を計算
def check(times):
    sm=0
    for i in range(H):
        st=0
        cnt=1
        for j in range(1, W):
            if grid[i][j-1]==grid[i][j]:
                cnt+=1
            else:
                if cnt>=K:
                    sm+=grid[i][j-1]*cnt
                    for k in range(st, j):
                        grid[i][k]=0
                cnt=1
                st=j
        else:
            if cnt>=K:
                sm+=grid[i][j]*cnt
                for k in range(st, j+1):
                    grid[i][k]=0
    return 2**times*sm

ans=0
for i in range(H):
    for j in range(W):
        # 元の状態は保持しておいて、全部試す
        grid=deepcopy(orgn)
        grid[i][j]=0    
        res=1
        score=times=0
        # 消えるところがある限りループ
        while res:
            drop()
            res=check(times)
            score+=res
            times+=1
        ans=max(ans, score)

print(ans)


Measured memory_bytes: 57948
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define sort(n) sort(n.begin(), n.end());
#define Ivec vector<int>
#define Svec vector<string> 
#define Out(S) cout << S << endl;
int main() {
  lli A,B,C,X,D=0;
  cin >> A >> B >> C >> X;
  rep(i,A+1) rep(j,B+1) rep(k,C+1){
    if(500*i+100*j+50*k==X)D++;
  }
  Out(D);
}



Measured memory_bytes: 256