akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] V = new long[N];
		for(int i=0; i<N; i++)
			V[i] = sc.nextLong() | (sc.nextLong()<<30);
		
		Arrays.sort(V);
		
		boolean ok = true;
		long now = 0;
		for(int i=0; i<N; i++) {
			long A = V[i] & ((1<<30)-1);
			long B = V[i]>>30;
			now += A;
			if(now>B) {
				ok = false;
				break;
			}
		}
		
		System.out.println(ok ? "Yes" : "No");
		sc.close();
	}
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    string s;
    cin1(s);
    lli c_0 = 0;
    lli c_1 = 0;
    REP(i, 0, s.length()) {
        if (s[i] == '0')
            c_0++;
        else
            c_1++;
    }
    lli x = min(c_0, c_1);
    cout << x * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL n;
VEC<int> box = {3, 5, 7};
int keta;
int siz = 3;
VEC<LL> cand(15, 0);
int cnt = 0;
void dfs(int th) {
  if (th == 0) {
    LL sum = 0;
    VEC<bool> f(10, 0);

    REP(i, 0, cand.size()) {

      sum += (LL)pow(10, i) * cand[i];
      f[(int)cand[i]] = 1;
    }
    if (f[3] && f[5] && f[7] && sum <= n) {
      ++cnt;
    }
    return;
  } else {
    REP(i, 0, siz) {
      LL tmp = cand[th - 1];
      cand[th - 1] = box[i];
      dfs(th - 1);
      cand[th - 1] = tmp;
    }
  }
}

int main() {
  cin >> n;
  keta = log10(n) + 1;
  //DUMP(keta);
  REP(i, 3, keta + 1) {
    cand = VEC<LL>(i, 0);
    dfs(i);
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const double PI = acos(-1);

void solve(){
    //3
    ll n,k;
    cin>>n>>k;
    n%=k;
    cout<<min(n,k-n)<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    int n,m;
    cin>>n>>m;
    int w[n+1];
    int a[n+1];
    MEM(w,0);
    MEM(a,0);
    while(m--)
    {
        int id;
        string s;
        cin>>id>>s;
        if(s=="AC")
            a[id]=1;
        else if(a[id]==0 and s=="WA")
            w[id]++;
    }
    int cnt=0,pt=0;
    for(int i=0;i<=n;i++)
    {
        if(a[i])
        {
            cnt++;
            pt+=w[i];
        }
    }
    cout<<cnt<<" "<<pt;

}


Measured memory_bytes: 4380
(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))

count = max(0, a[0] - x)
a[0] = min(a[0], x)
for i in range(1, n):
    sub = max(0, a[i - 1] + a[i] - x)
    count += sub
    a[i] -= sub

print(count)

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

typedef long long ll;

ll n, m;

int main()
{
	cin >> n >> m;
	if (n > m) swap(n, m);
	if (n == 1 && m == 1) cout << 1 << endl;
	else if (n == 1) cout << m-2 << endl;
	else cout << (n-2)*(m-2) << endl;
	return 0;
}


Measured memory_bytes: 768
object Main extends App {

  def findHollow(shapes: List[Char]): List[Char] = {

    def find(shapes: List[Char], flood: List[Char], depth: Int): List[Char] = {
      if (shapes.isEmpty)
        List()
      else shapes.head match {
        case '\\' => find(shapes.tail, '\\'::flood, depth + 1)
        case '_'  => find(shapes.tail, '_'::flood,  depth)
        case '/'  =>
          if (depth == 1) ('/'::flood).reverse
          else find(shapes.tail, '/'::flood, depth - 1)
      }
    }

    if (shapes.nonEmpty && shapes.head == '\\')
      find(shapes, List(), 0)
    else
      List()
  }

  def findAllFloods(diagram: String): List[String] = {

    def findAll(shapes: List[Char], floods: List[String]): List[String] = {
      if (shapes.isEmpty)
        floods.reverse
      else shapes.head match {
        case '\\' => {
          val hollow = findHollow(shapes)
          if (hollow.isEmpty)
            findAll(shapes.tail, floods)
          else
            findAll(shapes drop hollow.length, hollow.mkString::floods)
        }
        case _ => findAll(shapes.tail, floods)
      }
    }

    findAll(diagram.toList, List())
  }

  def calcAmountOfWater(pool: String): Int = {

    def calc(shapes: Seq[Char], amount: Double, depth: Int): Double = {
      if (shapes.isEmpty)
        amount
      else shapes.head match {
        case '\\' => calc(shapes.tail, amount + depth + 0.5, depth + 1)
        case '_'  => calc(shapes.tail, amount + depth,       depth)
        case '/'  => calc(shapes.tail, amount + depth - 0.5, depth - 1)
      }
    }

    calc(pool, 0.0, 0).toInt
  }

  val in = Console.in.readLine()

  val floods = findAllFloods(in)
  val amounts = floods map calcAmountOfWater

  println(amounts.sum)
  println((amounts.length::amounts) mkString " ")
}



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

typedef int64_t i64;
typedef uint64_t ui64;

const int inf=1073741823;
const i64 llinf=4611686018427387903LL;

class rmtree{
public:
    int nd;
    int wdt;
    i64 *node;
	int *ind;
    void make(int n){
        int k=1;
        while(k<n) k*=2;
        wdt=k;
        nd=wdt*2-1;
        node=new i64[nd]{};
		ind=new int[nd]{};
        for(int i=0;i<nd;i++){
            node[i]=llinf;
            ind[i]=-1;
        }
    }
    void add(int k,i64 x){
        k+=wdt-1;
        node[k]=x;
        ind[k]=k;
    }
    void calc(void){
        func_calc(0);
    }
    void func_calc(int k){
        int k1=k*2+1;
        int k2=k*2+2;
        if(k1>=nd || k2>=nd) return;
        if(node[k1]==-1) func_calc(k1);
        if(node[k2]==-1) func_calc(k2);
        if(node[k1]<node[k2]) node[k]=node[k1];
        else node[k]=node[k2];
        if(node[k1]<node[k2]) ind[k]=ind[k1];
        else ind[k]=ind[k2];
    }
    void update(int k,i64 x){
        k+=wdt-1;
        node[k]=x;
        ind[k]=k;
        while(k>0){
            k=(k-1)/2;
            if(node[k*2+1]<node[k*2+2]) node[k]=node[k*2+1];
            else node[k]=node[k*2+2];
			if(node[k*2+1]<node[k*2+2]) ind[k]=ind[k*2+1];
			else ind[k]=ind[k*2+2];
        }
    }
    i64 query(int a,int b){
        return func_query(a,b,0,0,wdt);
    }
    i64 func_query(int a,int b,int k,int l,int r){
        if(r<=a || b<=l) return llinf;
        if(a<=l && r<=b) return node[k];
        else{
            i64 vl=func_query(a,b,k*2+1,l,(l+r)/2);
            i64 vr=func_query(a,b,k*2+2,(l+r)/2,r);
            return min(vl,vr);
        }
    }
    int indery(int a,int b){
        return func_indery(a,b,0,0,wdt);
    }
    int func_indery(int a,int b,int k,int l,int r){
        if(r<=a || b<=l) return -1;
        if(a<=l && r<=b) return ind[k];
        else{
            int li=func_indery(a,b,k*2+1,l,(l+r)/2);
            int ri=func_indery(a,b,k*2+2,(l+r)/2,r);
			if(li==-1){
				if(ri==-1) return -1;
				else return ind[ri];
			}
			else if(ri==-1) return ind[li];
			else{
				if(node[ind[li]]<node[ind[ri]]) return ind[li];
				else return ind[ri];
			}
        }
    }
    void refr(void){
        delete[] node;
        delete[] ind;
    }
};

int main(void){
    int n;
    scanf("%i",&n);
    rmtree a;
    a.make(n);
    int q;
    scanf("%i",&q);
    int c;
    int p,s,t;
    i64 x;
    for(int i=0;i<q;i++){
        scanf("%i",&c);
        if(c==0){
            scanf("%i%lli",&p,&x);
            a.update(p,x);
        }
        if(c==1){
            scanf("%i%i",&s,&t);
            i64 f=a.query(s,t+1);
            printf("%lli\n",min(f,(i64)(1LL<<31)-1));
        }
    }
    return 0;
}



Measured memory_bytes: 6284
/*
 * Matheus Oliveira
 * 08:58:00 26/04/2020
 * a.cpp
*/

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

#define EPS
#define INF
#define MAXN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define sc(x) scanf("%d", &x);
#define sc2(x, y) scanf("%d %d", &x, &y);
#define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, bg, ed) printf("%s: ", #x); for(int i = bg; i < ed; i++) printf("%d%c", x[i], (i == ed-1) ? '\n' : ' ');

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int main() {
	int s, w;
	scanf("%d %d", &s, &w);
	
	if(w >= s) printf("unsafe\n");
	else printf("safe\n");

	return 0;
}

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

using namespace std;

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

  if (S.size() < 5){
    printf("NO\n");
  }else{
    int p = S.size() - 1;
    while (p >= 4){
      if (S.substr(p - 4, 5) == "dream" || S.substr(p - 4, 5) == "erase"){
        p -= 5;
      }else if (S.substr(p - 5, 6) == "eraser"){
        p -= 6;
      }else if (S.substr(p - 6, 7) == "dreamer"){
        p -= 7;
      }else{
        break;
      }
    }

    if (p==-1){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
    
    
  }
  
}


Measured memory_bytes: 3696
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

typedef struct node {
  i32 number;
  i32 len;
} node;

int can (const i32 m, const i32 *a, const i32 n) {
  static node *stack = NULL;
  if (stack == NULL) {
    stack = (node *) calloc (n, sizeof (node));
  }
  stack[0] = (node) {1, a[0]};
  i32 top = 1;
  i32 sum = a[0];
  for (i32 i = 1; i < n; ++i) {
    if (a[i] > sum) {
      stack[top++] = (node) {1, a[i] - sum};
      sum = a[i];
      continue;
    }
    node t = stack[--top];
    sum -= t.len;
    while (sum >= a[i]) {
      t = stack[--top];
      sum -= t.len;
    }
    while (top > 0 && t.number == m) {
      t = stack[--top];
      sum -= t.len;
    }
    if (t.number == m) return 0;
    if (sum + t.len > a[i]) {
      t.len = a[i] - sum;
    }
    t.len--;
    if (t.len > 0) {
      stack[top++] = t;
      sum += t.len;
    }
    stack[top++] = (node) {t.number + 1, 1};
    sum++;
    if (a[i] > sum) {
      stack[top++] = (node) {1, a[i] - sum};
      sum = a[i];
    }
  }
  return 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  i32 l = 0;
  i32 r = n;
  while (r - l > 1) {
    i32 m = (l + r) / 2;
    if (can (m, a, n)) {
      r = m;
    } else {
      l = m;
    }
  }
  printf ("%" PRIi32 "\n", r);
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 2560
S = str(input())
l = [str(x) for x in list(str(S))]
for i in range(int(len(l)/2)):
    l.pop(-1)
    l.pop(-1)
    tmp = "".join(l)
    if tmp[:int(len(l)/2)] == tmp[int(len(l)/2):]:
        print(len(l))
        break
    else:
        continue

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var scan *bufio.Scanner
var writer io.Writer

func init() {
	scan = bufio.NewScanner(os.Stdin)
	writer = os.Stdout
	scan.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	n := nextInt()
	res := n * (n - 1) / 2
	fmt.Fprint(writer, res)
}

func nextWord() string {
	scan.Scan()
	str := scan.Text()
	return str
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
function main(input) {
    input = input.trim().split("\n");
    var a = input[1].split(" ").map(x => Number(x)).filter(isEven);
    for (var i = 0; i < a.length; i++) {
        if (a[i] % 3 != 0 && a[i] % 5 != 0) {
            return console.log("DENIED");
        } 
    }
    console.log("APPROVED");

}
function isEven(num) {
    return num % 2 === 0;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int g[15][15];

int main(){
    int n;
    cin >> n;
    rep(i, n)rep(j, n) g[i][j] = -1;
    rep(i, n){
        int a;
        cin >> a;
        rep(j, a){
            int x, y;
            cin >> x >> y;
            x--;
            g[i][x] = y;
        }
    } 

    int ans = 0;

    rep(i, 1<<n){
        vi d(n);
        rep(j, n){
            d[j] = ((i>>j)&1);
        }

        bool ok = true;
        rep(j, n){
            if(d[j]==0) continue;
            rep(k, n){
                if(g[j][k] == -1) continue;
                if(g[j][k] != d[k]) ok = false;
            }
        }
        if(ok) ans = max(ans, __builtin_popcount(i));
    }

    cout << ans << endl;
}





/*
int g[15][15];

int main(){
    //読み込み
    int n;
    cin >> n;
    rep(i, n)rep(j, n) g[i][j] = -1;
    rep(i, n){
        int m;
        cin >> m;
        rep(j, m){
            int a, x;
            cin >> a >> x;
            --a;
            g[i][a] = x;
        }
    }

    //答えの変数用意
    int ans = 0;

    //処理 大きなループとして2のn乗
    rep(i, 1<<n){
        //まずは参照しやすいように各0,1をベクタに入れる
        vi d(n);
        rep(j, n) if(i>>j & 1){
            d[j] = 1;
        }
        //今回のパターンで成功するかどうかを表す変数
        bool ok = true;

        //正直者の発言だけを見てあげる        
        rep(j, n){
            if(d[j]){
                //ある人に対して発言してなければcontinue
                //発言していればそれと実際があっているか確かめる
                rep(k, n){
                    if(g[j][k] == -1) continue;
                    if(g[j][k] != d[k]) ok = false;
                }
            }
        }
        //間違いがなければ正直者の人数を数えてmax
        if(ok) ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << endl;
    return 0;
}

*/

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

int dp[20][2][10][10][10];

string num;

int Stoll(string s){
  
  int res = 0;
  
  for(int i=0;i<s.size();i++) res = res * 10 + s[i] - '0';

  return res;
}

int dfs(int x, int y, int p3, int p2, int p1 ){
  
  if( num.size() <= x ) return 0;
  
  if( dp[x][y][p3][p2][p1] != -1 ) return dp[x][y][p3][p2][p1];
  
  int res = 0;
  
  if( y == 0 ){
    
    int p = num[x] - '0';
    
    if( p3 == 5 && p2 == 1 && p == 3 ){
      if( x != (int)num.size() - 1 ) res += Stoll(num.substr(x+1));
      res++;
    }
    else res += dfs( x+1, 0, p2, p1, p );
    
    for(int i=0;i<num[x]-'0';i++){
      
      if( p3 == 5 && p2 == 1 && i == 3 ){
	
	int X = 1;
	
       	for(int j=0;j<(int)num.size()-x-1;j++) X *= 10;
	
	res += X;
	
      }
      else res += dfs( x+1, 1, p2, p1, i );
      
    }
    
  }
  
  if( y == 1 ){
    
    for(int i=0;i<10;i++){
      
      if( p3 == 5 && p2 == 1 && i == 3 ){
	
	int X = 1;
	
	for(int j=0;j<(int)num.size()-x-1;j++) X *= 10;
	
	res += X;
	
      }
      else res += dfs( x+1, 1, p2, p1, i );
      
    }
    
  }

  return dp[x][y][p3][p2][p1] = res;
}

signed main(){
  
  cin>>num;
  
  memset( dp, -1, sizeof(dp) );
  
  cout<<dfs(0,0,0,0,0)<<endl;
  
  return 0;
}



Measured memory_bytes: 3536
#include<stdio.h>
#include<math.h>

unsigned int Abs(int i) {
	if (i >= 0)return i;
	else return -i;
}

int main() {
	int n;
	int x[100], y[100];
	double D[4];
	unsigned long long ut;

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &x[i]);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &y[i]);
	}

	//infinite(D[0])
	ut = Abs(x[0] - y[0]);
	for (int i = 0; i < n; i++) {
		if (Abs(x[i] - y[i]) > ut)ut = Abs(x[i] - y[i]);
	}
	D[0] = (double)ut;

	//p=1
	ut = 0;
	for (int i = 0; i < n; i++) {
		ut += Abs(x[i] - y[i]);
	}
	D[1] = (double)ut;

	//p=2
	ut = 0;
	for (int i = 0; i < n; i++) {
		ut += (x[i] - y[i])*(x[i] - y[i]);
	}
	D[2] = sqrt((double)ut);

	//p=3
	ut = 0;
	for (int i = 0; i < n; i++) {
		ut += Abs(x[i] - y[i])*Abs(x[i] - y[i])*Abs(x[i] - y[i]);
	}
	D[3] = cbrt((double)ut);

	printf("%lf\n%lf\n%lf\n%lf\n", D[1], D[2], D[3], D[0]);

	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int y1, m1, d1, y2, m2, d2;
    while ( cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2 && y1 != -1 ) {
        int res = 0;
        const int days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        for ( int y = y1; y <= y2; ++ y ) {
            int ms = 1;
            int me = 12;
            if ( y == y1 ) ms = m1;
            if ( y == y2 ) me = m2;
            for ( int m = ms; m <= me; ++ m ) {
                int ds = 1;
                int de = days[m];
                if ( m == 2 && y % 4 == 0 ) {
                    if ( y % 100 != 0 || y % 400 == 0 ) {
                        de ++;
                    }
                }
                if ( y == y1 && m == m1 ) ds = d1;
                if ( y == y2 && m == m2 ) de = d2;
                for ( int d = ds; d <= de; ++ d ) {
                    // cout << y << "/" << m << "/" << d << endl;
                    res ++;
                }
            }
        }
        cout << res - 1 << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int a,b;
    char c;
    cin>>a>>c>>b;
    if(c=='+'){
        cout<<a+b<<endl;
    }else{
        cout<<a-b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from operator import itemgetter

def read():
    return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, read().split())
    a = sorted(int(i) for i in read().split())
    bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=itemgetter(1), reverse=True)
    d = []
    for b, c in bc:
        if len(d) < n:
            d += [c] * b
    for i in range(min(n, len(d))):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
    print(sum(a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 27852
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	long long n,k;
	cin >> n >> k;
	long long modn = n % k;
	long long abn = abs(modn - k);
	if (abn < modn)cout << abn;
	else cout << modn;
	
}

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

int V, E;
vector<unordered_set<int>> redge;
// bool redge[10000][10000];

// bool memo[10000];
unordered_set<int> memo;
void topological_sort(int u) {
//   if(memo[u]) return;
//   memo[u] = true;
//   for(int v = 0; v < V; ++v) if(redge[u][v]) topological_sort(v);
  if(memo.count(u)) return;
  memo.insert(u);
  for(int v: redge[u]) topological_sort(v);
  cout << u << endl;
}

int main() {
  cin >> V >> E;
  redge.resize(V);
  for(int i = 0; i < E; ++i) {
    int u, v;
    cin >> u >> v;
    redge[v].insert(u);
//     redge[v][u] = true;
  }
  for(int i = 0; i < V; ++i) topological_sort(i);
}

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

ll solve() {
    string S;
    cin >> S;
    ll N = S.size();
    ll M = 2019;
    vector<ll> dp(M+1), dpp(M);
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        swap(dp, dpp);
        dp.assign(M, 0);
        int a = S[i] - '0';
        for ( int j = 0; j < M; j++ ) {
            dp[(10*j+a)%M] += dpp[j];
        }
        dp[a] += 1;
        ans += dp[0];
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3724
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        List<Integer> list = new ArrayList<Integer>();

        for(int i = 0; i < S.length(); i++){
            list.add(Character.getNumericValue(S.charAt(i)));
        }


        int index = 0;
        int ans = 0;
        while(index < list.size() - 1){
            int num = list.get(index);
            int nextNum = list.get(index+1);
            if(num + nextNum == 1){   //01, 10の時
                ans += 2;
                list.remove(index);
                list.remove(index);  //連続で削除する
                index--;
                if(index < 0){ index = 0; }
            } else {
                index++;
            }
        }

        out.println(ans);
    }
}


Measured memory_bytes: 26376
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<30)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  ll N=S.size();
  ll cnt1=0;
  ll cnt2=0;
  for(int i=0;i<N;i++){
    if(i%2==0 && S[i]!='0'){
      cnt1++;
    }else if(i%2==1 && S[i]!='1'){
      cnt1++;
    }
  }
  
  for(int i=0;i<N;i++){
    if(i%2==0 && S[i]!='1'){
      cnt2++;
    }else if(i%2==1 && S[i]!='0'){
      cnt2++;
    }
  }

  cout << min(cnt1,cnt2) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

__int128 abbs(__int128 n){
	if(n < 0)
		n *= -1;
	return n;
}

int main(){
	ll nn, kk, dd;
	cin >> nn >> kk >> dd;
	
	__int128 n = nn, k = kk, d = dd;
	
	
	n = abbs(n);
	
	if(k * d <=	(__int128)n)
		return cout << (ll)(n - (k * d)) << endl, 0;
		
	__int128 diff = n / d;
	
	k -= diff;
	n -= d * diff;
	
	if(k > 0 && abbs(n - d) < n){
		k -= 1;
		n -= d;
	}
	
	if(k % 2 == 0)
		cout << (ll)abbs(n) << endl;
	else
		cout << (ll)min(abbs(n-d), abbs(n+d)) << endl;
	
	return 0;
}


Measured memory_bytes: 3628
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int[] count = new int[n+1];
		Arrays.fill(count, 0);

		for(int i = 0; i < m*2; i++){
			int j = scanner.nextInt();
			count[j] += 1;
		}
		for(int i = 1; i < n+1; i++){
			System.out.println(count[i]);
		}
	}
}

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

long cal(long n) {
	long sum = 0;
	while (n) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main() {
	long N;
	cin >> N;
	long div = cal(N);
	if (N % div) 
		cout << "No\n";
	else
		cout << "Yes\n";
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end



int main(){
   int n; cin>>n;
   printf("%d\n",(n/500)*1000+(n%500)/5*5);
   return 0;
}

Measured memory_bytes: 256
program sample
    implicit none
    character(len=100000)::s
    integer(8) :: i,j,m,n,a,b,c,x(3)
    integer(8),allocatable :: y(:)
  
    read(*,*) s
    x(:)=0
    n=len_trim(s)
    do i=1,n
        if (s(i:i) .eq. 'a')then
            x(1)=x(1)+1
        else if (s(i:i) .eq. 'b')then
            x(2)=x(2)+1
        else
            x(3)=x(3)+1
        end if
    end do
    
    if (abs(x(1)-x(2))<2 .and. abs(x(2)-x(3))<2 .and. abs(x(1)-x(3))<2 )then
     write(*,*) 'YES'
    else
        write(*,*)'NO'
    end if
  
    stop
end program sample
  



Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main()
{
	int a, b, x;
	cin >> a >> b >> x;

	if (a + b >= x && a <= x) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repe(i,n) for (int i = 0; i <= (n); ++i)

using namespace std;
typedef long long int ll;
int INF = 100100101;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int cnt=0;
  repe(i,a){
   	repe(j,b){
      repe(k,c){
       	int tmp = i*500+j*100+k*50;
        if(tmp == x) cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

typedef long long ll;

struct Edge {
    ll s,t;
    ll w;
    bool operator < (const Edge& tgt) const {
	return w > tgt.w;
    }
    void dump(){
	cout << s << " --> " << t << " : " << w << endl; 
    }
};

ll Prim(vector<vector<Edge>>& G) {
    const ll V = G.size();
    priority_queue<Edge> edges;
    
    vector<int> used(V,0);
    edges.push( Edge{-1,0,0} );
    ll ans = 0;
    while( edges.size() ) {
	Edge e = edges.top(); edges.pop();

//	assert(used[e.s] == 1);
	if( used[e.t] == 1 ) continue;
	used[e.t] = 1;
//	e.dump();
	ans += e.w;

	for(auto& nxt : G[e.t]) {
	    if( used[nxt.t] == 1 ) continue;
	    edges.push(nxt);
	}
    }
    for(auto& e : used) assert(e == 1);

    return ans;
}


int main () {

    ll V;
    cin >> V;
    vector<vector<Edge>> G(V);

    for(int i=0; i<V; i++) {
	for(int j=0; j<V; j++) {
	    ll w; cin >> w;
	    if( w != -1 ) {
		G[i].push_back( Edge{i,j,w} );
//		G[j].push_back( Edge{j,i,w} );
//		cout << i << " <--> " << j << " : " << w << endl; 
	    }
	}
    }

    ll ans = Prim(G);
    cout << ans << endl;
        
    return 0;
}

Measured memory_bytes: 3320
#include<bits/stdc++.h>
#include <unordered_map>
#define int long long
//#define double long double
#define endl "\n"
#define PI 3.1415926535897932384626433
#define sp(x)   setprecision(x)
#define ceil(a,b)   (a+(b-1))/b
#define LCM(a,b)    (a*b)/__gcd(a,b)
#define all(v)  v.begin(),v.end()
#define alls(s,v)  s.begin(),s.end(),v
#define gena(arr,n,nxt)  generate(arr,arr+n, nxt)
#define genv(v,nxt)  generate(v.begin(),v.end(), nxt)
#define base ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define exit return 0;
#define is(x) cout << #x << " = " << x << endl;
using namespace std;
const int N=500000;
int nxt(){int x;cin >> x;return x;}
double dtan(double x){
return tan((x)*PI/180.0);
}
int32_t main(){
    base
    string s;
    cin>>s;
    int i=s.size()-1;
    if(s[i]=='3') cout<<"bon";
    else if(s[i]=='0'||s[i]=='1'||s[i]=='6'||s[i]=='8')cout<<"pon";
    else cout<<"hon";
    exit
}


Measured memory_bytes: 3672
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

constexpr int N=1e5+10;
constexpr ll INF=1e9+7;
ll a[N*16];
ll sum[11];
main(){
    int h,w,n;scanf("%d%d%d",&h,&w,&n);
    int x,y;
    int cnt=0;
    ll m=(ll)(h-2)*(w-2);
    rep(iii,n){
        scanf("%d%d",&x,&y);
        rep(i,3)rep(j,3)if( x-i>=1 && x-i<=h-2 && y-j>=1 && y-j<=w-2){
            a[cnt++]=INF*(x-i)+(y-j);
        }
    }
    sort(a,a+cnt);
    ll t=1;
    rep(i,cnt){
        if(a[i]==a[i+1])t++;
        else sum[t]++,t=1,m--;
    }
    cout<<m<<endl;
    rep2(i,1,9)cout<<sum[i]<<endl;
}



Measured memory_bytes: 8448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES": "NO");

		static void Main(string[] args)
		{
			var a = RIs;
			var k = RI;
			var li = new List<int>(a);
			li.Sort();
			Out(li[0] + li[1] + li[2] * (int)Math.Pow(2, k));
		}
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;

int main(){
int n;
  scanf("%d",&n);
  vector<int> h(n);
  for(int& x : h){
  	scanf("%d",&x);
  }
  vector<int> ans(n,INF);
  ans[0]=0;
  for(int i=0;i<n;i++){
  	if(i+1<n) ans[i+1]=min(ans[i+1],ans[i]+abs(h[i]-h[i+1]));
    if(i+2<n) ans[i+2]=min(ans[i+2],ans[i]+abs(h[i]-h[i+2]));
  }
  printf("%d",ans[n-1]);
}


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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c== 'e' || c=='i' || c=='u' || c=='o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int na, nb, nc, x, num;
const int a=500, b=100, c=50;
int main()
{
	int sum=0;
	scanf("%d%d%d%d", &na, &nb, &nc, &x);
	for(int ia=0; ia<=na; ia++)
		for(int ib=0; ib<=nb; ib++)
			for(int ic=0; ic<=nc; ic++)
			{
				sum = ia*a+ib*b+ic*c;
				if(sum == x)
					num++;
			}
	printf("%d", num);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define REP(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    vector<pll> rec(N);
    REP(i, N){
        rec[i].first = A[i]+B[i];
        rec[i].second = A[i];
    }
    sort(rec.begin(), rec.end());
    reverse(rec.begin(), rec.end());
    ll res = 0;
    REP(i, N){
        if(i % 2 == 0){ //* Takahashi
            res += rec[i].second;
        }
        else{ //* Aoki
            res -= (rec[i].first - rec[i].second);
        }
    }
    cout << res << endl;
}

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: 3456
#include <bits/stdc++.h>
using namespace std;

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    int K, X;
    cin >> K >> X;
    for (int i = X - K + 1; i < X + K; i++)
        cout << i << " ";
}

Measured memory_bytes: 256
//QWsin
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100+10;
typedef unsigned long long ll;
const double eps=1e-9;

ll f[maxn][maxn],a[maxn],dp[maxn][maxn];

inline int dcmp(long double x){
	return fabs(x) < eps ? 0:(x<0?-1:1);	
}

int main()
{
	int n,l,r;cin>>n>>l>>r;
	
	for(int i=0;i<maxn;++i)	
		for(int j=0;j<maxn;++j)
			dp[i][j]=(ll)-1e17;
	
	dp[0][0]=0;f[0][0]=1;
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=1;i<=n;++i)
	{
		dp[i][0]=0;f[i][0]=1;
		for(int j=1;j<=i&&j<=r;++j)
		{
			ll t1=dp[i-1][j];
			ll t2=dp[i-1][j-1]+a[i];
			
			if(t1==t2) dp[i][j]=t1,f[i][j]=f[i-1][j]+f[i-1][j-1];
			else if(t1>t2) dp[i][j]=t1,f[i][j]=f[i-1][j];
			else dp[i][j]=t2,f[i][j]=f[i-1][j-1];
		}
	}
	
	int pos=0;ll cnt=0;
	for(int i=l;i<=r&&i<=n;++i)
		if(pos==0||dp[n][i]*pos > dp[n][pos]*i) pos=i,cnt=f[n][i];
		else if(dp[n][i]*pos==dp[n][pos]*i) cnt+=f[n][i];
	
	printf("%.6f\n%lld\n",(double)dp[n][pos]/pos,cnt);
	return 0;
}


Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<int>dis(N + 1, INT_MAX);
	vector<vector<pair<int, int>>>edge(N + 1);
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> K;
		edge[L].push_back({ R,K });
		edge[R].push_back({ L, -K });
	}
	vector<bool>flag(N + 1, true);
	for (int i = 1; i <= N; i++) {
		if (!flag[i]) {
			continue;
		}
		queue<int>Q;
		Q.push(i);
		while (!Q.empty()) {
			int cn = Q.front();
			Q.pop();
			if (!flag[cn]) {
				continue;
			}
			flag[cn] = false;
			int c = dis[cn];
			for (auto j : edge[cn]) {
				int nx = j.first;
				int nc = c + j.second;
				if (dis[nx] == INT_MAX || dis[nx] == nc) {
					dis[nx] = nc;
					if (flag[nx]) {
						Q.push(nx);
					}
				}
				else {
					cout << "No\n";
					return 0;
				}
			}
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 9600
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int K[n];
	if(n == 1)
	{
		printf("1\n");
		}
	if(n >= 2)
	{
	for(int i = 2; i <= n; i++)
	{
		K[0] = 2;
		K[1] = 1;
        K[i] = K[i - 1] + K[i - 2];
		}
		printf("%lld\n", K[n]);
	}
}

Measured memory_bytes: 128
N, Ma, Mb = map(int, input().split())
L = []
sum_a = 0
sum_b = 0
for _ in range(N):
    a, b, c = map(int, input().split())
    sum_a += a
    sum_b += b
    L.append((a, b, c))

inf = 10 ** 9 + 7
dp = [[[inf] * (sum_b + 1) for _ in range(sum_a + 1)] for _ in range(N + 1)]

dp[0][0][0] = 0
for i in range(N):
    for a in range(sum_a + 1):
        for b in range(sum_b + 1):
            if 0 <= a - L[i][0] and 0 <= b - L[i][1]:
                # print(a, b, L[i])
                dp[i + 1][a][b] = min(dp[i][a - L[i][0]]
                                      [b - L[i][1]] + L[i][2], dp[i][a][b])
            else:
                dp[i + 1][a][b] = dp[i][a][b]

min_cost = inf
for a in range(sum_a + 1):
    for b in range(sum_b + 1):
        if a * Mb == b * Ma and dp[N][a][b] != 0:
            # print(a, b, dp[N][a][b])
            min_cost = min(dp[N][a][b], min_cost)

print(min_cost if min_cost != inf else -1)


Measured memory_bytes: 93420
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#include <tuple>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000000; //10^18
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

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



int main(void) {

  int n;
  string c;
  cin >> n;
  cin >> c;

  int nw[200100], nr[200100];
  nw[0] = 0; nr[n] = 0;

  rep(i, n) {
    if (c[i] == 'W') nw[i+1] = nw[i] + 1;
    else nw[i+1] = nw[i];

    if (c[n-1-i] == 'R') nr[n-i-1] = nr[n-i] + 1;
    else nr[n-i-1] = nr[n-i];
  }

  int ans = INT_MAX;


  rep(i, n+1) {
    ans = min(ans, max(nr[i], nw[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 5288
N = int(input())
A = list(map(int, input().split()))

cnt = 0
money = 1000
stock = 0
for i in range(N-1):
    if A[i] == A[i+1]:
        pass
    elif A[i] < A[i+1]:
        tmp = money // A[i]
        stock += tmp
        money -= tmp * A[i]
    else:
        money += stock * A[i]
        stock = 0

money += stock * A[-1]

print(money)


Measured memory_bytes: 61920
#include <stdio.h>

int main(void)
{
	int n;
	int i, j;
	int ice[10001];
	int c[10];
	
	while (1) {
		for (i = 0; i < 10; i++) {
			c[i] = 0;
		}
		scanf("%d", &n);
		if (n == 0) {
			break;
		}
		for (i = 0; i < n; i++) {
			scanf("%d", &ice[i]);
			c[ice[i]]++;
		}
		for (i = 0; i < 10; i++) {
			if (c[i] == 0) {
				puts("-");
				continue;
			}
			for (j = 0; j < c[i]; j++) {
				printf("*");
			}
			puts("");
		}
	}
	return (0);
}

Measured memory_bytes: 624