akhauriyash/Code-Regression huggingface dataset:
N, L = gets.strip.split.map(&:to_i)

sum = 0
N.times do |i|
  sum += L + i
end

res = 10 ** 6
sum2 = 0
N.times do |i|
  sv = L + i
  if sv.abs < res
    sum2 = sum - sv
    res = sv.abs
  end
end

p sum2


Measured memory_bytes: 1788
#include <stdio.h>
#include <math.h>
#define rep(i,a,n) for(int i=a;i<n;i++)

int main(){
	int n,m,l,a[100][100]={0},b[100][100]={0};
	long long c[100][100]={0};

	scanf("%d %d %d",&n,&m,&l);
	rep(i,0,n){
		rep(j,0,m){
			scanf("%d",&a[i][j]);
		}
	}
	rep(i,0,m){
		rep(j,0,l){
			scanf("%d",&b[i][j]);
		}
	}
	rep(i,0,n){
		rep(j,0,l){
			rep(k,0,m){
				c[i][j]+=a[i][k]*b[k][j];
			}
			printf("%lld",c[i][j]);
			if(j!=l-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1196
// Aizu 1131: Unit Fraction Partition
// 2017.10.24 bal4u@uu

#include <stdio.h>
#include <math.h>

#define M 100000000
#define EPS 1e-9
#define HASHSIZ 19997
typedef struct { int b; double v; } HASH;
HASH hash[HASHSIZ + 2], *hashend = hash + HASHSIZ;

int lookup(double v)
{
	int k = (int)(v * M);
	HASH *hp = hash + k % HASHSIZ;
	while (hp->b) {
		if (fabs(hp->v - v) <= EPS) return hp->b;
		if (++hp == hashend) hp = hash;
	}
	return -1;
}

void insert(double v, int b)
{
	int k = (int)(v * M);
	HASH *hp = hash + k % HASHSIZ;
	while (hp->b) {
		if (fabs(hp->v - v) <= EPS) return;
		if (++hp == hashend) hp = hash;
	}
	hp->v = v, hp->b = b;
}

double tbl[12005];

int bsch(double v)
{
	int m, l = 0, r = 12001;

	while (l < r) {
		m = (l + r) >> 1;
		if (fabs(tbl[m] - v) <= EPS) return m;
		if (tbl[m] > v) l = m + 1; else r = m;
	}
	if (l <= 0) l = 1;
	return l;
}

int ans, a;

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

void rec(double v, int k, int n, int aa)
{
	int i, l, r;

	if (n < 0 || aa > a) return;
	if (fabs(v) <= EPS) { ans++; return; }
	if (n == 0) return;

	l = bsch(v), r = bsch(v / n);
	if (k > l) l = k;
	for (i = l; i <= r; i++) rec(v - 1.0 / i, i, n - 1, aa*i);
}

int main()
{
	int p, q, n, i, l, r;
	double v;

	for (i = 1; i <= 12002; i++) {
		v = 1.0 / i;
		insert(v, i), tbl[i] = v;
	}

	while (scanf("%d%d%d%d", &p, &q, &a, &n) && n > 0) {
		i = gcd(p, q); p /= i, q /= i;
		v = (double)p / q;
//		if (fabs(v-n) <= EPS) { puts("1"); continue; }
		if (v > n) { puts("0"); continue; }
		l = bsch(v), r = bsch(v / n);
		for (ans = 0, i = l; i <= r; i++) {
			rec(v - 1.0 / i, i, n - 1, i);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2100
#include<stdio.h>
int main(){
int n,m,l;
long long a[100][100],b[100][100],c[100][100]={0};
scanf("%d %d %d", &n,&m,&l);
for (int i = 0; i < n; i++)
{
    for (int j = 0; j < m; j++)
    {
        scanf("%lld", &a[i][j]);
    }
    
}
for (int i = 0; i <m; i++)
{
    for (int j = 0; j < l; j++)
    {
        scanf("%lld", &b[i][j]);
    }
    
}
for (int i = 0; i < n; i++)
{
    for (int j = 0; j < l; j++)
    {
        c[i][j]=0;
        for (int k = 0; k < m; k++)
        {
            c[i][j] = c[i][j] + a[i][k]*b[k][j];
        }
        
    }
    
}


for (int i = 0; i < n; i++)
{
    for (int j = 0; j < l; j++)
    {
        if (j == 0)
        {
            printf("%lld",c[i][j]);
        }
        else
        {
        printf(" %lld", c[i][j]);
        }
        
    }
    printf("\n");
}

return 0;
}



Measured memory_bytes: 2872
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=desc gsmi

sum=a.shift
sum += sum(a[0,(n-2)/2])*2

if n.odd?
  sum+=a[(n-2)/2]
end

puts sum

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

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

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

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

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll a;
    ll b;
    cin >> a >> b;
    ll ans=0;
    for(ll i= a; i<=b; i++){
        ll a_div=0;
        ll b_div=0;
        ll c_div=0;
        ll d_div=0;
        ll e_div=0;
        a_div = i %10;
        b_div = (i %100 -     a_div);
        c_div = (i %1000 -   (a_div+b_div));
        d_div = (i %10000 - (b_div+a_div+c_div)) ;
        e_div = (i- (b_div+a_div+c_div+d_div)) ;

       //cout << a_div << " " << b_div << " "  << c_div<<" "<< d_div << " " << e_div << endl;
        if(a_div == (e_div/10000)&& b_div == (d_div/100)){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3220
#include "bits/stdc++.h"
#define YES "YES"
#define Yes "Yes"
#define NO "NO"
#define No "No"
#define YESNO OUT(three(solve(),YES,NO))
#define YesNo OUT(three(solve(),Yes,No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef long double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,1,1,-1,-1,0 }, dy[] = { 1,0,-1,0,1,-1,1,-1,0 };
const int SIZE1 = 2e6 + 1000;
const int SIZE2 = 1010;
const int SIZE3 = 188;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1 << 20;
const long double EPS = 1e-7;
ut N, M, K, L, H, W, Q, D, T;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
Vpr edges[SIZE];
int maps[SIZE2][SIZE2];
LL solve() {
	LL R, G, B, N;
	cin >> R >> G >> B >> N;
	LL ans = 0;
	REP(i, 3001) REP(j,3001) {
		LL c = R * i + G * j;
		if (N - c >= 0 and (N - c) % B == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	solve();
	//	cin >> N;
	return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
	}
  s << "]";
	return s;
}

struct Node {
  Node* c0 = nullptr;
  Node* c1 = nullptr;
  void Add(const string& s, int cur) {
    if (cur >= s.length()) return;

    if (s[cur] == '0') {
      if (c0 == nullptr) {
        c0 = new Node();
      }
      c0->Add(s, cur + 1);
    } else if (s[cur] == '1') {
      if (c1 == nullptr) {
        c1 = new Node();
      }
      c1->Add(s, cur + 1);
    }
  }
};

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

  int n;
  int64 l;
  cin >> n >> l;

  Node trie;

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    trie.Add(s, 0);
  }

  vector<int64> ds;
  function<void(Node*, int)> dfs_fn = [&](Node* node, int d) {
    if (node->c0 == nullptr && node->c1 == nullptr) {
      // Leaf.
    } else if (node->c0 == nullptr) {
      ds.push_back(l - d);
      dfs_fn(node->c1, d + 1);
    } else if (node->c1 == nullptr) {
      ds.push_back(l - d);
      dfs_fn(node->c0, d + 1);
    } else {
      dfs_fn(node->c0, d + 1);
      dfs_fn(node->c1, d + 1);
    }
  };
  dfs_fn(&trie, 0);

  if (DEBUG) cout << "ds: " << ds << endl;

  auto g_fn = [](int64 x) -> int64 {
    int64 v = 1;
    while (x % 2 == 0) {
      x /= 2;
      v *= 2;
    }
    return v;
  };

  int64 xor_value = 0;
  for (int64 d: ds) {
    xor_value ^= g_fn(d);
  }
  if (xor_value == 0) {
    cout << "Bob" << endl;
  } else {
    cout << "Alice" << endl;
  }
}

Measured memory_bytes: 12132
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N  = scanner.nextInt();
        int K  = scanner.nextInt();
        ArrayList<Integer> l = new ArrayList<>();
        for(int i=0; i<N; i++){
            l.add(scanner.nextInt());
        }
        Collections.sort(l, Comparator.reverseOrder());
        int len = 0;
        for(int i=0; i<K; i++){
            len += l.get(i);
        }
        System.out.println(len);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int r=0;
    for(char c:s){
        if(c=='R')r++;
    }
    int res=min(r,n-r);
    vector<int> sum(n+1,0);
    for(int i=0;i<n;i++){
        sum[i+1]=sum[i]+(s[i]=='W');
    }
    int w=n-r;
    for(int i=0;i<=n;i++){
        int cost=abs(i-r);
        if(i==r){
            cost+=sum[i];
        }
        else if(i<r){
            cost+=sum[i];
        }
        else{
            cost+=max(0,sum[i]-(i-r));
        }
        res=min(res,cost);
        //cout << abs(i-r) << " "<< cost << endl;
    }
    cout << res << endl;
}

/*

WWWRRRR

RRRRWWW

*/


Measured memory_bytes: 4448
#include"bits/stdc++.h"
#include<numeric>
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#define rep(i,n) for (int i = 0; i < (n);i++)
typedef long long ll;
using namespace std;
/*#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;*/
ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

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

void Main()
{
	ll a,b,c,d; cin >> a>>b>>c>>d;
	ll C = (b/c) - (a/c);
	ll D = (b/d) - (a/d);
	ll e = lcm(c,d);
	ll E = b/e - a/e;
	if(a%c==0||a%d==0)
		cout<< b-a -C -D + E << endl;
	else
		cout<< b-a+1 -C -D +E <<endl;
	
}


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

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

int main(void) {
    int n ;
    int *d ;
    cin >> n ;

    d = new int[n] ;
    for (int i = 0; i < n; i++)
        cin >> d[i] ;

    sort(d, d+n) ;

    int dif = d[n/2] - d[n/2-1] ;
    cout << dif << endl ;

    delete[] d ;

    return 0 ;
}

Measured memory_bytes: 640
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(x[0] - X)

for i in range(len(x)):
    ans = gcd(ans, abs(x[i] - X))

print(ans)

Measured memory_bytes: 14252
#include <stdio.h>
 
int main(void)
{
 long a,b,x;
 int c=0;
 
 scanf("%ld%ld%ld",&a,&b,&x);
 if(a%x==0)
  c=1;
 printf("%ld\n",(b/x)-(a/x)+c);
  return 0;
}

Measured memory_bytes: 128
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 
 
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

 
int main() {
    #ifdef sharma
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);      
    #endif
    fastio;
    int n;
    string s;
    cin >> n >> s;
    if(n < 3200)
        cout << "red";
    else
        cout << s;
    



    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000
#define MOD 1000000007

void solve() {
    ll n;
    cin >> n;
    bool flag = false;
    for(ll i = 2; i*i <= n; ++i) {
        if (!(n%i)) {
            flag = 1;
            break;
        }
    }
    if (!flag && n^1) {
        cout << 1 << "\n";
        return;
    }
    unordered_map<ll, int> div;
    int ans = 0;
    while (!(n%2)) {
        n /= 2;
        div[2]++;
    }
    for (ll i = 3; i*i <= n; i += 2) {
        while (!(n%i)){
            ++div[i];
            n /= i;
        }
    }
    if (n > 1) div[n]++;
    for (auto& i: div) {
        int k = 1;
        while (i.se >= k) {
            ++ans;
            i.se -= k;
            ++k;
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}



Measured memory_bytes: 3596
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        N: usize,
    }

    let mut ans = 0;
    let mut i = 2;
    let mut n = N;
    while i * i <= N {
        let mut cnt = 0;
        while n % i == 0 {
            n /= i;
            cnt += 1;
        }

        let mut ind = 1;
        loop {
            if ind > cnt {
                break;
            }

            ans += 1;
            cnt -= ind;
            ind += 1;
        }

        i += 1;
    }

    if n >= 2 {
        ans += 1;
    }
    println!("{}", ans);
}


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

#define hi(x) ((x)>>16)
#define lo(x) ((x)&0xffff)

struct comp{
    bool operator()(const unsigned a, const unsigned b){return hi(a)*lo(a) < hi(b)*lo(b);}
};

int main(){
	int n,w,d;
	for(;scanf("%d%d%d",&n,&w,&d),w;){
	vector<unsigned> v;
	v.push_back((w<<16)+d);
	for(;n--;){
		int p, s, state=0;
		scanf("%d%d", &p, &s);
		p--;
		s%=hi(v[p])+lo(v[p]);
		
		unsigned x=hi(v[p]), y=lo(v[p]), _x=0, _y=0;
		for(;s--;){
			switch(state){
				case 0:{
					_x++;
					if(_x==x)state=1;
					break;
				}
				case 1:{
					_y++;
					break;
				}
			}
		}
		unsigned x1, x2, y1, y2;
		switch(state){
			case 0:{
				x1=_x;x2=x-_x;
				y1=y2=y;
				break;
			}
			case 1:{
				x1=x2=x;
				y1=_y;y2=y-_y;
				break;
			}
		}
		
		v.erase(v.begin()+p);
		if(x1*y1>x2*y2){
			v.push_back((x2<<16)+y2);
			v.push_back((x1<<16)+y1);
		}else{
			v.push_back((x1<<16)+y1);
			v.push_back((x2<<16)+y2);
		}
	}
	
	sort(v.begin(), v.end(), comp());
	for(;v.size();){
		printf("%d", hi(v[0])*lo(v[0]));
		v.erase(v.begin());
		if(v.size())printf(" ");
	}
	printf("\n");
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

ll n,x,ans;


inline ll rd(){
	ll ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

int main(){
	n=rd(); x=rd(); ans=n;
	ll q=n-x; if(x > n-x) swap(x,q);
	while(x != 0){
		if(q%x == 0) ans+=(q/x)*x*2-x;
		else ans+=(q/x)*x*2;
		ll t=q;
		q=x; x=t%x;
	}
	printf("%lld",ans);
	return 0;
}//Faze


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;	
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

const ll INF = 1e15;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> hs(n);
	rep(i, n) cin >> hs[i];
	vector<vector<ll>> graph(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	ll sum = 0;
	rep(i, n) {
		ll h = hs[i];
		bool ok = true;
		for(auto  p :  graph[i]) {
			if (h <= hs[p]){
				ok = false;
				break;
			}
		}
		if (ok) sum++;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 9860
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n,m;
    scanf("%d%d", &n, &m);

    vector<pair<int,int> > z(n);
    int i;
    for(i=0; i<n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        z[i]=make_pair(a,b);
    }
    sort(z.begin(), z.end());
    int curr=0;

    ll sum=0;
    set<pair<int,int> > zz;   //b, id
    for(i=1; i<=m; i++) {
        while(curr<n) {
            if(z[curr].first<=i) {
                zz.insert(make_pair(z[curr].second, curr));
                curr++;
            }
            else {
                break;
            }
        }
        if(!zz.empty()) {
            auto it=zz.rbegin();
            sum += it->first;
            zz.erase(*it);
        }
    }
    printf("%lld\n", sum);

    return 0;
}

Measured memory_bytes: 5632
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

#define lim 2000005

ll a[lim],b[lim],cnt[lim];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n;
    sfl(n);
    FOR(i,n){
        sfl(a[i]);
        cnt[a[i]]++;
    }
    sort(a+1,a+n+1);
    ll ans=0;
    for(ll i=1;i<=n;i++){
        if(a[i]==a[i-1]) continue;
        if(!b[a[i]] and cnt[a[i]]==1){
            ans++;
        }
        for(ll j=a[i];j<=1e6;j+=a[i]){
            b[j]=1;
        }
    }

    pfl(ans);
    return 0;
}


Measured memory_bytes: 20916
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;
int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    int ret=INT_MAX;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> s(m,0);
        int cost=0;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                for(int j=0;j<m;j++){
                    s[j]+=a[i][j];
                }
                cost+=c[i];
            }
        }
        bool ok=true;
        for(int i=0;i<m;i++){
            if(s[i]<x)ok=false;
        }
        if(ok)ret=min(ret,cost);
    }
    if(ret==INT_MAX)cout<<-1<<endl;
    else cout<<ret<<endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	int K;
	cin >> K;
	Rep(i, K) cout << "ACL";
	cout << endl;
	return 0;
}

Measured memory_bytes: 3620
ss=gets.chomp.chars
ts=gets.chomp.chars
ns=[]
a=ts.size
0.upto(ss.size-a) do |i|
  ns << ss.slice(i..i+a-1)
end
c=Array.new(ns.size,0)
ns.each_with_index do |n,f|
  0.upto(ts.size) do |i|
    c[f] += 1 unless n[i]==ts[i]
  end
end
p c.min

Measured memory_bytes: 14156
n = int(input())
taro = 0
hanako = 0
for i in range(n):
    A, B = (x for x in input().split())
    if(A < B): hanako += 3
    elif(A > B): taro += 3
    else:
      taro += 1
      hanako += 1
print(taro, hanako)


Measured memory_bytes: 5600
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val aa = listOfInt().sorted()

    var lastPos = 0
    var dist = 0
    aa.forEach {
        dist += it - lastPos
        lastPos = it
    }

    println(dist - aa[0])
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

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

int main() {
  int N;
  while(cin >> N && N) {
    int h[N+1];
    for(int i=0; i<N+1; i++) {
      cin >> h[i];
    }
  
    for(int i=0; i<N+1; i++) {
      vector<int> h2;
      for(int j=0; j<N+1; j++) {
        if(i == j) {}
        else h2.push_back(h[j]);
      }
    
      bool ok = true;
      const int diff = h2[1]-h2[0];
      for(int j=0; j<N-1; j++) {
        if(h2[j+1]-h2[j] == diff) {}
        else {
          ok = false;
        }
      }
      if(ok) {
        cout << h[i] << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1216
import bisect

n = int(input())
s = input()

idx = [[] for i in range(10)]

for i in range(n):
  idx[ord(s[i]) - ord('0')].append(i)

ans = 0
for i in range(1000):
  flag = True
  i_str = format(i, "03d")
  _idx = -1
  for j in range(3):
    if not flag or len(idx[ord(i_str[j]) - ord('0')]) == 0:
      flag = False
      break
    __idx = bisect.bisect_left(idx[ord(i_str[j]) - ord('0')], _idx + 1)
    if __idx == len(idx[ord(i_str[j]) - ord('0')]):
      flag = False
      break
    else:
      _idx = idx[ord(i_str[j]) - ord('0')][__idx]
  if flag:
    ans += 1
print(ans)

Measured memory_bytes: 4468
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first 
#define ss second
#define mod 1000000007
#define lim 100005
#define nfs_mw ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int dp[1<<18][2];
void merge(int big[2], int small[2])
{
	for(int i=0; i<2; i++){
		if(small[i]>big[1]) big[1] = small[i];
		if(big[0]<big[1]) swap(big[0], big[1]);
	}
}


int main()
{
	nfs_mw;
	int i,j,n,mask,out = 0;
	cin>>n;
	for(i=0; i<(1<<n); i++) cin>>dp[i][0];

	for(i=0; i<n; i++)
		for(mask=0; mask<(1<<n); mask++) if(mask&(1<<i))
			merge(dp[mask], dp[mask^(1<<i)]);

	for(i=1; i<(1<<n); i++) cout<<(out = max(out, dp[i][0] + dp[i][1]))<<"\n";

	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "Yes";
const string NO  = "No";

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

    string s;

    cin >> s;

    if (s.substr(0, 4) == "YAKI") {
        cout << YES;
    } else {
        cout << NO;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll ans=0;
ll suma[200001],dif1[200001],dif2[200001],n;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        suma[i]=x+y;
        dif1[i]=x-y;
        dif2[i]=y-x;
    }
    sort(suma+1,suma+n+1);
    sort(dif1+1,dif1+n+1);
    sort(dif2+1,dif2+n+1);
    ans=max(ans,suma[n]-suma[1]);
    ans=max(ans,dif1[n]+dif2[n]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 8328
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 200000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}

int vis[4];

int main() {
    int a, b;
    cin >> a >> b;
    vis[a] = vis[b] = true;
    for (int i = 1; i <= 3; i++) {
        if (!vis[i]) printf("%d\n", i);
    }
    return 0;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
*x, = map(int, input().split())
y = [abs(X-x_i) for x_i in x]
def gcd(a,b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a
ans = y[0]
for i in range(1,N):
    ans = gcd(ans, y[i])
print(ans)


Measured memory_bytes: 15020
#include<cstdio>
#include<algorithm>
int n,m,x[100010],y[100010],list[100010],fa[100010];
bool cmpx(int i,int j){return x[i]<x[j];}
bool cmpy(int i,int j){return y[i]<y[j];}
int find(int i){return fa[i]==i?i:fa[i]=find(fa[i]);}
struct edge{int u,v,w;bool operator<(const edge&e)const{return w<e.w;}}E[200010];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d",x+i,y+i),fa[i]=list[i]=i;
	std::sort(list,list+n,cmpx);
	for(int*i=list;i<list+n-1;i++)E[m++]=(edge){*i,i[1],x[i[1]]-x[*i]};
	std::sort(list,list+n,cmpy);
	for(int*i=list;i<list+n-1;i++)E[m++]=(edge){*i,i[1],y[i[1]]-y[*i]};
	std::sort(E,E+m);
	int s=0,b=n;
	for(edge*e=E;b>1;e++)find(e->u)!=find(e->v)?s+=e->w,b--,fa[find(e->u)]=find(e->v):1;
	printf("%d\n",s);
}

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

long long MOD = 1000000007;

int main() {
    
    string S;
    cin >> S;
    int zero = 0, one = 0;
    int ans = INT_MAX;
    int n = S.length();
    for ( int i = 0; i < n-1; i++ ) {
        if ( S[i] != S[i+1] ) { ans = min( ans, max( i+1, n - (i+1) ) ); }
    }
    if ( ans == INT_MAX ) { ans = n; }
    
    cout << ans << endl;
    
    return 0;
}

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

int main()
{
	long long n;
	cin>>n;
	
	long long ans = 0;
	for (int i=1;i<=n;++i)
		ans=ans+(i+(n/i)*i)*(n/i)/2;
	cout<<ans<<endl;
	return 0;
}

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


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

    int time = 0;
    while (b <= a) {
        b *= 2;
        time++;
    }
    while (c <= b) {
        c *= 2;
        time++;
    }
            
    if (time <= k) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
     
    using namespace std;
    const int maxn=1000005;
    int n,m,dp[maxn],best,path[maxn],root;
    vector<pair<int,int>> g[maxn];
     
    int dfs_With_dp(int u)
    {
        if(dp[u]) return dp[u];
        dp[u]=1;
        for(auto v:g[u]) {
            int c=v.first;
            if(dp[u]<dfs_With_dp(c)+1) {
                dp[u]=dp[c]+1;
                path[u+1]=c+1;
            }
        }
        return dp[u];
    }
     
    int main()
    {
        int x,y;
        scanf("%d%d",&n,&m);
        for(int i=0;i<m;i++) {
            scanf("%d%d",&x,&y);
            x-=1;
            y-=1;
            g[x].push_back(make_pair(y,i+1));
        }
        for(int i=0;i<n;i++) {
            int path_len=dfs_With_dp(i);
            if(best<path_len) {
                root=i;
                best=path_len;
            }
        }
        cout<<best-1;
       
        return 0;
    }

Measured memory_bytes: 32000
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

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

  ll n, k; cin >> n >> k;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];

  int ans = 1e9;
  for(int i = 0; i < n-(k-1); ++i) {
    ll l = i, r = i+(k-1);
    int  tmp  = min(abs(x[l])+x[r]-x[l], abs(x[r])+x[r]-x[l]);
    ans = min(ans, tmp);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n;
	cin >> n;
	vector<string> w(n);
	rep(i, 0, n) cin >> w[i];

	string ans = "Yes";
	// その単語の先頭の文字は直前に発言した単語の末尾の文字と一致する
	rep(i, 0, n - 1) if (w[i].at(w[i].size() - 1) != w[i + 1].at(0)) ans = "No";
	// その単語はまだ発言していない単語である
	SORT(w);
	rep(i, 0, n - 1) if (w[i] == w[i + 1]) ans = "No";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char X[1001];
char Y[1001];
int LCS(int r,int s);
int main(){
  int q, i, out;
  int l1,l2;
  scanf("%d", &q);
  for(i = 0;i < q;i++){
    scanf("%s", X);
    scanf("%s", Y);
    l1 = strlen(X);
    l2 = strlen(Y);
    out = LCS(l1, l2);
    printf("%d\n", out);
}
return 0; }
int LCS(int r, int s){
  int i, j;
  int t[1001][1001];
  for(i = 0;i <= r;i++){
    t[i][0] = 0;
  }
  for(i = 0;i <= s;i++){
t[0][j] = 0; }
  for(i = 1;i <= r;i++){
    for(j = 1;j <= s;j++){
      if(X[i-1] == Y[j-1]){
        t[i][j] = t[i-1][j-1]+1;
      }else if(t[i-1][j-1] >= t[i][j-1]){
        t[i][j] = t[i-1][j];
      }else{
        t[i][j] = t[i][j-1];
} }
}
  if(i == 0 || j == 0){
    return 0;
  }else if(i > 0 && j > 0 && r == s){
    return t[i-1][j-1];
  }else if(i > 0 && j > 0 && r != s){
    return t[r][s];
}
return 0; }


Measured memory_bytes: 5632
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

const int inf = pow(2, 31) - 1;

void update(int i, int x, vector<int> &data, int n) {
  i += n - 1;
  data[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    data[i] = min(data[2 * i + 1], data[2 * i + 2]);
  }
}

int find(int a, int b, int k, int l, int r, vector<int> &data) {
  if (r <= a or b <= l) {
    return inf;
  } else if (a <= l and r <= b) {
    return data[k];
  } else {
    int vl = find(a, b, 2 * k + 1, l, (l + r) / 2, data);
    int vr = find(a, b, 2 * k + 2, (l + r) / 2, r, data);
    return min(vl, vr);
  }
}

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

  int n, q;
  cin >> n >> q;
  const int N = pow(2, 17);
  vector<int> data(N * 2, inf);
  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      update(x, y, data, N);
    } else if (com == 1) {
      cout << find(x, y + 1, 0, 0, N, data) << '\n';
    }
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
const int N=1e5+9;
int n;
int a[N];
int dp[N];
int main(){

    while(~scanf("%d",&n)){
        memset(dp,0x3f,sizeof dp);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        dp[1]=0;
        for(int i=2;i<=n;i++){
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        }
        cout<<dp[n]<<"\n";
    }

    return  0;
}





Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;

llint n;
llint a[200005],cnt[200005];

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		cnt[a[i]]++;
	}
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		ans += cnt[i]*(cnt[i]-1)/2;
	}
	for(int i = 1; i <= n; i++){
		llint tmp = ans - cnt[a[i]]*(cnt[a[i]]-1)/2;
		tmp += (cnt[a[i]]-2)*(cnt[a[i]]-1)/2;
		cout <<tmp << endl;
	}

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 4736
n, m = map(int, input().split())
a = set(map(int, [input() for _ in range(m)]))

dp = [0] * (n+1)
# 0段目と1段目は1通り（但し、１段目が壊れていない場合）（0 段目は「なにもしない」という から1 通り）
dp[:2] = 1, 1 if 1 not in a else 0 

for i in range(2, n+1):
    if i not in a:
        dp[i] = ((dp[i-1] + dp[i-2]) % (10**9+7))

print(dp[-1])


Measured memory_bytes: 18336
n = gets.to_i
d = Array.new
f = Array.new
ans = "Yes"
for i in 0 .. n-1 do
    d = gets.split(" ").map(&:to_i)
    f[i] = d
end

for i in 0 .. n-1 do
if f[i][0] % 2 == 1
    if (f[i][1].abs + f[i][2].abs) % 2 == 0 ||f[i][1].abs + f[i][2].abs > f[i][0]
        ans = "No"
        break
    end
    elsif
    if (f[i][1].abs + f[i][2].abs) % 2 == 1 ||f[i][1].abs + f[i][2].abs > f[i][0]
        ans = "No"
        
    end
end
end
 
puts ans

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    ll X;
    cin >> X;

    ll ans = 0;
    ans += X/500*1000;
    ans += X%500/5*5;
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Point{
	double x,y;
};

int N,X,Y,pre_time[1000];
Point customer,point[1000];
bool near_customer[1000];
bool check[1000];
vector<int> NEAR[1000];


double calc_dist(Point a,Point b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void func(){

	scanf("%d %d %d",&N,&X,&Y);

	for(int i = 0; i < N; i++)NEAR[i].clear();

	scanf("%lf %lf",&customer.x,&customer.y);

	for(int i = 0; i < N; i++){
		scanf("%lf %lf",&point[i].x,&point[i].y);
		near_customer[i] = (calc_dist(point[i],customer) <= 10.0);
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){
			if(calc_dist(point[i],point[k]) <= 50.0){
				if(i != k)NEAR[i].push_back(k);
			}
		}
	}

	int ans;
	vector<int> V,NEXT;

	for(int i = 0; i < N; i++){
		if(near_customer[i]){
			pre_time[i] = X;
			V.push_back(i);
		}else{
			pre_time[i] = -1;
		}
	}

	if(V.size() == 0){
		printf("0\n");
		return;
	}

	ans = X;

	while(true){

		for(int i = 0; i < N; i++)check[i] = false;
		for(int i = 0; i < V.size(); i++){
			for(int k = 0; k < NEAR[V[i]].size(); k++){
				check[NEAR[V[i]][k]] = true;
			}
		}
		for(int i = 0; i < N; i++){
			if(check[i]){
				if(pre_time[i] == -1){
					pre_time[i] = ans+X;
					NEXT.push_back(i);
				}else if(pre_time[i] != -1 && ans-pre_time[i] > Y){
					printf("You're always welcome!\n");
					return;
				}
			}
		}
		if(NEXT.size() == 0)break;
		V.clear();
		for(int i = 0; i < NEXT.size(); i++)V.push_back(NEXT[i]);
		NEXT.clear();
		ans += X;
	}

	printf("%d\n",ans);
}

int main(){

	int case_num;
	scanf("%d",&case_num);

	for(int i = 0; i < case_num; i++)func();

	return 0;
}

Measured memory_bytes: 7076
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EGetEverything solver = new EGetEverything();
        solver.solve(1, in, out);
        out.close();
    }

    static class EGetEverything {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = new int[m];
            int[] c = new int[m];

            for (int i = 0; i < m; i++) {
                a[i] = in.nextInt();
                int b = in.nextInt();
                for (int j = 0; j < b; j++) {
                    int k = in.nextInt() - 1;
                    c[i] |= (1 << k);
                }
            }

            int target = (1 << n) - 1;
            int[][] dp = new int[m + 1][target + 1];
            for (int i = 0; i <= m; i++) {
                Arrays.fill(dp[i], Integer.MAX_VALUE);
            }

            dp[0][0] = 0;

            for (int i = 0; i < m; i++) {
                for (int state = 0; state <= target; state++) {
                    if (dp[i][state] == Integer.MAX_VALUE)
                        continue;

                    dp[i + 1][state | c[i]] = Math.min(dp[i + 1][state | c[i]], dp[i][state] + a[i]);
                    dp[i + 1][state] = Math.min(dp[i + 1][state], dp[i][state]);
                }
            }

            int answer = dp[m][target];
            if (answer == Integer.MAX_VALUE)
                answer = -1;
            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 51912