akhauriyash/Code-Regression huggingface dataset:
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Segment Tree
template <typename Operator>
struct SegmentTree {
    Operator OP;
    using NodeType = decltype(OP.NodeE);
    int length;
    vector<NodeType> node;
    SegmentTree (int N) {
        length = 1;
        while (length < N) length <<= 1;
        node.assign(length << 1, OP.NodeE);
    }
    SegmentTree (vector<NodeType> &vec) {
        length = 1;
        while (length < vec.size()) length <<= 1;
        node.assign(2 * length, OP.NodeE);
        rep(i, vec.size()) node[i + length] = vec[i];
        for (int i = length - 1; i > 0; --i) node[i] = OP.func(node[(i << 1) + 0], node[(i << 1) + 1]);
    }
    void update(int idx, NodeType val) {
        idx += length;
        node[idx] = OP.change(node[idx], val);
        while (idx >>= 1) node[idx] = OP.func(node[(idx << 1) + 0], node[(idx << 1) + 1]);
    }
    NodeType get(int l, int r) {
        l += length;
        r += length;
        NodeType vl = OP.NodeE, vr = OP.NodeE;
        while (r > l) {
            if (l & 1) vl = OP.func(vl, node[l++]);
            if (r & 1) vr = OP.func(node[--r], vr);
            l >>= 1;
            r >>= 1;
        }
        return OP.func(vl, vr);
    }
};
struct RMQ {
    using NodeType = int;
    NodeType NodeE = 0;
    NodeType change(NodeType x, NodeType y) {return y;}
    NodeType func(NodeType x, NodeType y) {return max(x, y);}
};

// Main
int main() {
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> x(m), y(m);
    rep(i, m) {
        cin >> x[i] >> y[i];
        --x[i]; --y[i];
    }
    
    vector<vector<int>> g(w);
    rep(i, m) g[y[i]].push_back(x[i]);
    vector<int> cnt1(h, 0), cnt2(w, 0);
    rep(i, m) {
        ++cnt1[x[i]];
        ++cnt2[y[i]];
    }
    SegmentTree<RMQ> st(cnt1);
    int ans = 0;
    rep(i, w) {
        for (int n: g[i]) st.update(n, cnt1[n] - 1);
        int mx = st.get(0, h);
        chmax(ans, mx + cnt2[i]);
        for (int n: g[i]) st.update(n, cnt1[n]);
    }
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 28524
def main45():
    data = input().split()
    nm = []
    for i in range(2):
        nm.append(int(data[i]))
    ab = []
    for i in range(nm[0]):
        karid = input().split()
        karin = []
        for j in range(2):
            karin.append(int(karid[j]))
        ab.append(karin)
    ab.sort()
    result = 0
    kazu = 0
    while(nm[1]>0):
        if nm[1] <= ab[kazu][1]:
            result = result + nm[1] * ab[kazu][0]
            nm[1] = 0
        else:
            result = result + ab[kazu][1] * ab[kazu][0]
            nm[1] = nm[1] - ab[kazu][1]
            kazu = kazu + 1
    print(result)

if __name__ == "__main__":
    main45()

Measured memory_bytes: 21544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

class UnionFind {
public:
    vector<int> par;

    UnionFind(int n) : par(n, -1) {};

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int size(int x) {
        return -par[root(x)];
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    rep(i, 0, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    ll ans[m] = {};
    ans[m - 1] = (ll)n * (n - 1) / 2;

    UnionFind uf(n);

    for (int i = m - 1; i >= 1; i--) {
        if (uf.same(a[i], b[i])) ans[i - 1] = ans[i];
        else {
            ans[i - 1] = ans[i] - (ll)uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
    }

    rep(i, 0, m) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll MOD = 1000000007;
  ll n;
  cin >> n;
  vl a(n+1);
  a[0] = 1;
  for(int i=1; i<=n; i++){
    if(i >= 3) {
      a[i] = a[i-1] + a[i-3];
      a[i] %= MOD;
    }
  }
  cout << a[n] << endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<set>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
int n;
ll a[200001];
multiset<ll>s;
ll inv(ll x)
{
    ll t=1;
    while(t<=x) t<<=1;
    return t-x;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        const auto& f=s.find(a[i]);
        if(f!=s.end()) ans++,s.erase(f);
        else s.insert(inv(a[i]));
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 11136
#include<iostream>
#include<algorithm>
#include <string>
#include<vector>

using namespace std;
int d[200][2];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d[i][0] >> d[i][1];
	}
	for (int i = 0; i < n - 2; i++) {
		if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] && d[i + 2][0] == d[i + 2][1]) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

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

int main()
{
    int x, y;

    while (true) {
        cin >> x >> y;

        if (x == 0 && y == 0) {
            return 0;
        }

        if (x > y) {
            int temp = x;
            x = y;
            y = temp;
        }

        cout << x << " " << y << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr<<#x<<": "<<(x)<<'\n'
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll nax = 0;

int main(){
  IOS
  ll k, ans=0;
  cin >> k;
  for(int i=1;i<=k;++i){
    ans=ans*10+7;
    ans%=k;
    if(ans==0){
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    ll n;
    cin >> n;
    vector<ll> vec(0);
    vec.push_back(2);
    vec.push_back(1);
    rep(i,n-1){
        vec.push_back(vec.at(i)+vec.at(i+1));
    }
    cout << vec.at(n) << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
XYH = [list(map(int,input().split())) for _ in range(N)]

Cxy = defaultdict(int)

#-1 NG
# 0 default
#1+ ok
verify =[]
XYH.sort(key=lambda x:-x[2])

for x,y,h in XYH:
    for cx in range(101):
        for cy in range(101):
            val = Cxy[(cx,cy)]
            if val<0:
                continue
            tmp_H = abs(x-cx)+abs(y-cy)+h
            if h==0:
                if tmp_H < Cxy[(cx,cy)]:
                    Cxy[((cx, cy))]=-1
                continue

            if val==0:
                Cxy[(cx,cy)] = tmp_H
            elif val != tmp_H:
                Cxy[(cx, cy)] =-1

def find(d):
    for key in d.keys():
        if d[key] >0:

            return key,d[key]

(X,Y),H = find(Cxy)
print(X,Y,H)

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


vector<int> scc(vector<vector<int>>& edges){
    int n = edges.size();
    vector<vector<int>> rev(n);

    for(int i = 0; i < n; ++i)
        for(auto& x : edges[i])
            rev[x].emplace_back(i);

    vector<i64> dfs_num(n, -1);
    vector<i64> flag(n, 0);
    int num = 0;
    function<void(int)> dfs = [&](int pos){
        flag[pos] = 1;
        for(auto& xx : edges[pos])
            if(!flag[xx]){
                dfs(xx);
        }
        dfs_num[pos] = num++;
    };

    for(int i = 0; i < n; ++i)
        if(!flag[i])
            dfs(i);

    vector<int> dfs_inv(n);
    for(int i = 0; i < n; ++i)
        dfs_inv[n - 1 - dfs_num[i]] = i;

    num = 0;

    vector<int> scc_vec(n, -1);

    function<void(int)> rdfs = [&](int pos){
        scc_vec[pos] = num;
        for(auto t : rev[pos])
            if(scc_vec[t] == -1)
                rdfs(t);
    };

    for(int i = 0; i < n; ++i)
        if(scc_vec[dfs_inv[i]] == -1){
            rdfs(dfs_inv[i]);
            ++num;
        }

    return scc_vec;
}


signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i];
        edges[--a[i]].emplace_back(--b[i]);
    }

    auto ret = scc(edges);
    for(int i = 0; i < n; ++i){
        bool fl = false;
        for(int j = 0; j < n; ++j)
            if(ret[i] == ret[j]){
                if(fl)
                    cout << " ";
                cout << j + 1;
                fl = true;
            }
        cout << endl;
    }
}



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

int main(){
  string S;
  char a[2];
  cin>>S;
  int i=0;
  int cou=0;
  int b[2];
  int Flag=0;


  while(S[i]!='\0'){
    if(isupper(S[i])&&Flag!=1){
      a[cou] = S[i];
      b[cou] = i;
      cou++;
      if(cou > 2){
        Flag=1;
      }
    }
    i++;
  }

  if(Flag==1){
    cout<<"WA"<<endl;
  }
  else{
    if(a[0] == 'A' && b[0]==0){
      if(a[1]=='C' && 1<b[1] && b[1]<i-1){
        cout<<"AC"<<endl;
      }
      else{
        cout<<"WA"<<endl;
      }
    }
    else cout<<"WA"<<endl;
  }

}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = scanner.nextInt();
        int[] p = new int[n];

        for (int i = 0 ; i < n ; i++) {
            p[i] = scanner.nextInt();
        }

        int count = 0;
        for (int i = 0 ; i < n - 2 ; i++) {
            if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2])
                || (p[i + 2] < p[i + 1] && p[i + 1] < p[i])) {
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 35684
#include<bits/stdc++.h>
#define MAXN 100000
#define MAXP 670000
#define MAXA 10000000
#define pii pair<int,int>
#define MP(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))


using namespace std;
void get(int &v)
{
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return ;
}
int get()
{
	int v;
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return v;
}
int a[180][180];
int s[10080];
int color()
{
	if(s[s[0]]==0)
		s[0]--;
	s[s[0]]--;
	return s[0];
}
int main()
{
	int h,w,i,j;
	get(h);
	get(w);
	get(s[0]);
	for(i=1;i<=s[0];i++)
		get(s[i]);
	for(i=1;i<=h;i++)
	{
		if(i&1)
		{
			for(j=1;j<=w;j++)
				a[i][j]=color();
		}
		else
		{
			for(j=w;j;j--)
				a[i][j]=color();
		}
	}
	for(i=1;i<=h;i++)
	{
		for(j=1;j<w;j++)
			printf("%d ",a[i][j]);
		printf("%d\n",a[i][j]);
	}
	return 0;
}
//g++ -g c.cpp -o c

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = 1000000007;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n;
    cin>>n;
    if(n % 7 == 0 || n % 4 == 0)
    {
        cout<<"Yes\n";
        return 0;
    }
    f(i, 26)
    {
        f(j, 26)
        {
            if(4 * i + 7 * j == n)
            {
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tlll tuple<ll, ll, ll>

int main() {
    ll n, x[100010], l[100010];
    cin >> n;
    vector<Pll> v;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> l[i];
        v.emplace_back(x[i] + l[i], l[i]);
    }

    sort(all(v));

    int ans = 0, at = -2e9;
    for (int i = 0; i < n; i++) {
        if (at <= v[i].first - 2 * v[i].second) {
            ans++;
            at = v[i].first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3444
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int>::reverse_iterator rit; for(rit=s.rbegin();rit!=s.rend();rit++)
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e5+5;
using namespace std;

ll t,n,m,x,y,ans;

int main(){
	scanf("%lld%lld",&n,&m);
	if(m-n>=2019) printf("0\n");
	else{
		ll minn=inf;
		for(ll i=n;i<m;i++){
			for(ll j=i+1;j<=m;j++){
				minn=min(minn,((i%2019)*(j%2019))%2019);
			}
		}
		printf("%lld\n",minn);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using Int = long long;
int main(void){
    
    Int N, M;
    cin >> N >> M;
    vector<Int> used(N,0);
    int count_AC = 0, count_WA = 0;
    

    
    for(int i = 0; i < M; i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(used[p] < 0) continue;
        
        if(s == "AC"){
            count_AC++;
            count_WA += used[p];
            used[p] = -1;
        }
        else used[p]++;
    }
    
    cout << count_AC << " " << count_WA << endl;
    
    
    
}


Measured memory_bytes: 1152
#!/usr/bin/env python3

N, T = list(map(int, input().split()))
ct_list = []

for _ in range(N):
    c, t = list(map(int, input().split()))
    ct_list.append((c, t))

min_c = float("inf")

for ct in ct_list:
    c, t = ct
    if t <= T:
        min_c = min(c, min_c)

ans = min_c if min_c != float("inf") else "TLE"
print(ans)


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

int main(){
    int k,s;
    cin >> k >> s;
    int x,y,z;
    int ans = 0;
    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            z = s-x-y;
            if(z>=0 && z<=k) ans++;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void func(int nn);
int box[31];
int a[6][2]={{1,9},{10,12},{13,15},{16,18},{19,21},{22,30}};
int ans;
int main(void){
	int n;
	int i,j;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=1;j<=30;j++)	cin>>box[j];
		ans=10;
		func(0);
		cout<<ans<<endl;
	}
	return 0;
}
void func(int nn){
	int i,j;
	int x,y;
	int flg;
	int aa[4][5]={{ 1, 4, 7,10,16},{ 3, 6, 9,12,13},{ 1, 2, 3,15,19},{ 7, 8, 9,13,10}};
	int bb[4][5]={{24,27,30,21,18},{22,25,28,19,15},{28,29,30,16,21},{22,23,24,18,12}};
	
	if(nn<=8){
		flg=0;
		for(i=0;i<6;i++){
			x=a[i][0];
			y=a[i][1];
			for(j=x;j<y;j++){
				if(box[j]!=box[j+1]){
					flg=1;
					break;
				}
			}
			if(flg==1)	break;
		}
		if(flg==0){
			ans=min(ans,nn);
		}
		else{
			for(i=0;i<4;i++){
				for(j=0;j<5;j++){
					x=aa[i][j];
					y=bb[i][j];
					swap(box[x],box[y]);
				}
				func(nn+1);
				for(j=0;j<5;j++){
					x=aa[i][j];
					y=bb[i][j];
					swap(box[x],box[y]);
				}
			}
		}
	}
}
			
			


Measured memory_bytes: 3100
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $H, $W);
echo str_repeat("#", $W + 2) . PHP_EOL;
for ($i = 0; $i < $H; $i++) {
    fscanf(STDIN, "%s", $s);
    echo "#{$s}#\n";
}
echo str_repeat("#", $W + 2) . PHP_EOL;


Measured memory_bytes: 4728
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
   ll dp[n];
   dp[0]=0;
   for(int i=1;i<n;i++)
     dp[i]=1e9;
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        if(j<n)
          dp[j]=min(dp[j],abs(a[i]-a[j])+dp[i]);
          else break;
    }
    cout<<dp[n-1];
    return 0;
}


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

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

    vector<vector<int> > v(n,vector<int>(d));

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < d; ++j){
            cin >> v[i][j];
        }
    }

    int ans = 0;

    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            double l = 0;
            for(int k = 0; k < d; ++k){
                l += pow(abs(v[i][k] - v[j][k]),2);
            }
            if((int)sqrt(l) == sqrt(l)) ans ++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
  int n;
  int val;
   cin>>n;
  
  vector<int> a;
  vector<int> b;
  
 
  for(int i=0;i<n;i++)
  {
    cin>>val;
    a.push_back(val);
    b.push_back(0);
  }
  
  b[1]=abs(abs(a[1]-a[0]));
  for(int i=2;i<n;i++)
  {
      b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
      
	}
    
    cout<<b[n-1]<<endl;           
	return 0;
}

Measured memory_bytes: 1276
#include<stdio.h>
int main(void){
  int i, j, n, r, p, c;

  while(1){
    scanf("%d%d", &n, &r);
    if(n==0 && r==0){
      break;
    }
    int yama[n];
    for(i=0;i<n;i++){
      yama[i]=n-i;
    }
    for(i=0;i<r;i++){
      scanf("%d%d", &p, &c);
      int down[p-1], cut[c];
      for(j=0;j<p-1;j++){
        down[j]=yama[j];
      }
      for(j=0;p-1+j<p-1+c;j++){
        cut[j]=yama[p-1+j];
      }
      for(j=0;j<c;j++){
        yama[j]=cut[j];
      }
      for(j=0;j<p-1;j++){
        yama[c+j]=down[j];
      }
    }
    printf("%d\n", yama[0]);
  }
  return 0;
}

Measured memory_bytes: 600
H,W = gets.split.map(&:to_i)
M = 160 * 80
A = H.times.map { gets.split.map(&:to_i) }
B = H.times.map { gets.split.map(&:to_i) }

dp = Array.new(H){ Array.new(W, 0)}
d0 = (A[0][0] - B[0][0]).abs
dp[0][0] = (1 << (M - d0) | 1 << (M + d0))

W.times do |x|
  H.times do |y|
    d = (A[y][x] - B[y][x]).abs
    dp[y][x] |= (dp[y][x - 1] << d | dp[y][x - 1] >> d)  if x > 0
    dp[y][x] |= (dp[y - 1][x] << d | dp[y - 1][x] >> d)  if y > 0
  end
end

G = dp[H - 1][W - 1]
puts M.times.find{|i| G[M - i] > 0 || G[M + i] > 0 }


Measured memory_bytes: 36220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, m,n) for (int i = m; i < (int)(n); i++)
int main(){
int N;
  cin>>N; int a=0;
  a+=1000*(N/500);
  a+=((N%500)/5)*5;
  cout<<a<<endl;
}

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

using namespace std;

const int maxn = 100010;
int cost[maxn];
int N;
int h[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> h[i];
	}
	cost[0] = 1000000000;

	for (int i = 2; i <= N; i++) {
		cost[i] = min(cost[i-1] + abs(h[i] - h[i-1]),
			cost[i-2] + abs(h[i]-h[i-2]));
	}

	cout << cost[N] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){

int N,D,X;
int ans=0,j=1;
scanf("%d",&N);
scanf("%d%d",&D,&X);
int A[N];
for (int i = 0; i < N; i++)
{
  scanf("%d",&A[i]);
}

for (int i = 0; i < N; i++)
{
  while (j*A[i]+1<=D)
  {
    ans++;
    j++;
  }
  j=1;
}

printf("%d",ans+X+N);

return 0;

}


Measured memory_bytes: 1720
from collections import Counter
N = int(input())
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
factors2 = []
for i in range(N):
    factors2.extend(prime_factors(i+1))
cc = Counter(factors2)
ans = 1
inf = 10 ** 9 + 7 
for c in cc.items():
    ans *= c[1]+1
if N == 1:
    print(1)
else:
    print(ans % inf)

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

int main(){
    int a, b, c;
    int count = 0;

    cin >> a >> b >> c;

    for(int i = a; i <= b; i++){
        // cout << i << endl;
        if(0 == c % i){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3100
import math
a, b = map(int,input().split())
ans = []

for x in range(1,1009):
    if math.floor(x * 0.08 )== a and math.floor(x * 0.1) == b:
        ans.append(x)

if len(ans) == 0:
    print("-1")
else:
    print(min(ans))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N = 1e5;
    vector<bool> p(N+1, true);
    p[1] = false;
    rep(i, 2, N+1){
        for(ll j = 2; i * j <= N; j++){
            p[i*j] = false;
        }
    }
    vector<ll> acc(N+1, 0);
    rep(i, 1, N+1){
        acc[i] = acc[i-1];
        if(i % 2 == 0) continue;
        if(p[i] && p[(i+1)/2]) acc[i]++;
    }
    ll Q;
    cin >> Q;
    rep(q, 0, Q){
        ll l, r;
        cin >> l >> r;
        cout << acc[r] - acc[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
for _ in range(50):
    m, f, r = map(int, input().split())
    total = m + f
    if m == -1 and  f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    elif total >=80:
        print('A')
    elif total >= 65:
        print('B')
    elif total >= 50:
        print('C')
    elif total >= 30 and r >= 50:
        print('C')
    elif total >= 30:
        print('D')
    else:
        print('F')



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

const int MAX_TOWN = 10;
const int INF = 1000000;

int dist[MAX_TOWN][MAX_TOWN];

void minify() {
  for (int k = 0; k < 10; k++)
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int sum_of_dist(int t) {
  int sum = 0;
  for (int i = 0; i < 10; i++)
    sum += (dist[t][i] == INF)? 0:dist[t][i];

  return (sum == 0)? INF:sum;
}

int main() {
  int n;
  while (cin >> n and n != 0) {
    int a, b, c;

    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        dist[i][j] = (i == j)? 0:INF;

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      dist[a][b] = dist[b][a] = c;
    }

    minify();

    int min_dist = INF, min_town = 0;
    for (int t = 0; t < 10; t++) {
      if (min_dist > sum_of_dist(t)) {
        min_town = t;
        min_dist = sum_of_dist(t);
      } 
    }

    cout << min_town << " " << min_dist << endl;
  }
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) {

		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";

		try {
			str=bfr.readLine();
			long res=0;
			long han=0;
			long ni_beki=1;
			int ruijyo=0;

			if(str=="") {
				System.exit(0);
			}

			else {
				res=Long.parseLong(str);

				for(int i=0; i<1;) {
					han=(res>>ruijyo)%2;
					if(han==0) {
						res=(res%ni_beki)+1;
						i=1;
						break;
					}
					else {
						ni_beki=ni_beki*2;
						ruijyo++;
					}
				}
				System.out.println(res);
			}
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

	}

}


Measured memory_bytes: 24220
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] x = new int[4];
        int[] y = new int[4];
        for (int i = 0; i < 2; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        int movex = x[1] - x[0];
        int movey = y[1] - y[0];
        x[2] = x[1] - movey;
        y[2] = y[1] + movex;
        x[3] = x[0] - movey;
        y[3] = y[0] + movex;
        for (int i = 2; i < y.length; i++) {
            System.out.print(x[i] + " " + y[i] + " ");
        }
        System.out.println();
        sc.close();
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int e_mx,e_mx_index,e_mx2,o_mx,o_mx_index,o_mx2;
vector<int> ecnt(100010),ocnt(100010);
int main() {
    int n;
    cin >> n;
    ll ans = 0;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ans += (a[i]-1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,n) for(int i=1;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll h,w;
ll dx[8]={1,0,-1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1};
char Maze[55][55];
ll ans;
void solve_Maze(){
  repn(i,h){
    repn(j,w){
      if(Maze[i][j]!='#'){
        ans=0;
        rep(k,8){
          if(Maze[i+dx[k]][j+dy[k]]=='#'){
            ans++;
          }
        }
        Maze[i][j]=to_string(ans)[0];
      }
    }
  }
}

int main(){
  cin>>h>>w;
  repn(i,h){
    repn(j,w){
      cin>>Maze[i][j];
    }
  }

  solve_Maze();
  repn(i,h){
    repn(j,w){
      cout<<Maze[i][j];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    cout << (n + 1) / 2 * (n / 2) << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=1e7+5;
int n,x,ans,t[N+5],p[1000005],b[205][205],d1[205],d2[205],s[205];
bool bz[N+5],v[205];
bool dg(int x)
{
	for (int i=1;i<=d2[0];i++)
	if (b[x][i] && !v[i])
	{
		v[i]=1;
		if (!s[i] || dg(s[i]))
		{
			s[i]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&x),bz[x]=1;
	for (int i=1;i<=N;i++) 
	if (bz[i]^bz[i-1]) 
	{
		if (i&1) d1[++d1[0]]=i; 
			else d2[++d2[0]]=i;
	}
	memset(bz,0,sizeof(bz));
	bz[1]=1;
	for (int i=2;i<=N;i++)
	{
		if (!bz[i]) p[++p[0]]=i;
		for (int j=1;j<=p[0] && i*p[j]<=N;j++)
		{
			bz[i*p[j]]=1;
			if (i%p[j]==0) break;
		}
	}
	bz[2]=1;
	for (int i=1;i<=d1[0];i++)
		for (int j=1;j<=d2[0];j++)
		if (!bz[abs(d1[i]-d2[j])]) b[i][j]=1;
	for (int i=1;i<=d1[0];i++)
	{
		memset(v,0,sizeof(v));
		if (dg(i)) ans++;
	}
	d1[0]-=ans,d2[0]-=ans;
	ans+=d1[0]/2*2+d2[0]/2*2+d1[0]%2*3;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 14720
#include <stdio.h>
#include <iostream>
#include <tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
typedef long long Int;

int N, S, W, Q, a[200000];

Int solve() {
    if(Q==2 || Q==5) {
        Int ans=0, c=0;
        rep(i, N) {
            if(a[i]!=0) c += 1;
            if(a[i]%Q==0) ans += c;
        }
        return ans;
    }
    else {
        Int ans=0, cur=0, p=1;
        unordered_map<int, int> cnt;
        cnt[0] = 1;
        for(int i=N-1; i>=0; i--) {
            cur = (cur+a[i]*p) % Q;
            p = p*10 % Q;
            if(a[i]!=0) ans += cnt[cur];
            cnt[cur] += 1;
        }
        return ans;
    }
}

int main() {
    for(;;) {
        scanf("%d%d%d%d", &N, &S, &W, &Q);
        if(N==0) return 0;
        int g = S;
        rep(i, N) {
            a[i] = (g/7) % 10;
            if(g%2==0) g = g/2;
            else g = (g/2) ^ W;
        }
        cout << solve() << endl;
    }
}

Measured memory_bytes: 3224
a,b = map(int, input().split())

if a > b:
    if a % b == 0:
        print(0)
        exit()
    else:
        print(min(a%b, b-(a%b)))
        exit()

while True:
    x = abs(a-b)
    if x < a:
        a = x
    else:
        print(a)
        break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,i,ta,a[1010],hs;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>ta;
		a[ta]++;
		if(a[ta]==1)
			hs++;
	}
	cout<<hs<<"\n";
}

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

using namespace std;

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

    int n1 = stoi(s.substr(0, 2));
    int n2 = stoi(s.substr(2, 4));

    bool yymm = false, mmyy = false;
    if (n2 > 0 && n2 <= 12)
        yymm = true;
    if (n1 > 0 && n1 <= 12)
        mmyy = true;

    if (yymm && mmyy)
        cout << "AMBIGUOUS\n";
    else if (yymm)
        cout << "YYMM\n";
    else if (mmyy)
        cout << "MMYY\n";
    else
        cout << "NA\n";
}


Measured memory_bytes: 256
/// Author : Nhat Huy
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define task "miniziation"
#define opfin(task) freopen( task".inp", "r", stdin )
#define opfout(task) freopen(task".out", "w", stdout)
#define ms(a) memset(a, 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef vector<int> vi;
typedef vector <ii> vii;
typedef pair <int, double> id;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    clock_t begin = clock();
    //opfin(task);
    //opfout(task);
    //Code here !
    int n, k;
    cin >> n >> k;
    REP(i,n) {
        int x;
        cin >> x;
    }
    int res = 0;
    while (n > 1) {
        res++;
        n -= (k - 1);
    }
    cout << res << endl;
    clock_t end = clock();
    //cerr <<"Time run: "<<(float)(end-begin)/CLOCKS_PER_SEC<<" s"<<endl;
    return 0;
}










Measured memory_bytes: 256
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

n = int(input())
b = {}
vals = list(map(int, input().split()))
for i in range(n-1):
    if(vals[i] in b):
        b[vals[i]]+=1
    else:
        b[vals[i]] = 1
for i in range(1, n+1):
    if(i in b):
        print(b[i])
    else:
        print(0)


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

#define ll long long

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

    int n;
    cin >> n;
    string s;
    int cnt =0;
    unordered_map<string, int> u;
    for (int i=0;i<n;i++) {
        cin >> s;
        if (s == "AC" || s == "WA" || s == "TLE" || s == "RE")
            u[s]++;
    }
    cout << "AC x " << u["AC"] << "\n";
    cout << "WA x " << u["WA"] << "\n";
    cout << "TLE x " << u["TLE"] << "\n";
    cout << "RE x " << u["RE"] << "\n";
}


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

using namespace std;

#define rg register
#define In inline
#define ll long long

const int N = 128;
const int M = 62;

namespace IO{
	In int read(){
		int s = 0,ww = 1;
		char ch = getchar();
		while(ch < '0' || ch > '9'){if(ch == '-')ww = -1;ch = getchar();}
		while('0' <= ch && ch <= '9'){s = 10 * s + ch - '0';ch = getchar();}
		return s * ww;
	}
	In void write(int x){
		if(x < 0)putchar('-'),x = -x;
		if(x > 9)write(x / 10);
		putchar('0' + x % 10);
	}
};
using namespace IO;

int f[62+5],len;
char c[62+5];
typedef vector<char> str;

void print(str s){
	for(rg int i = 0;i < s.size();i++)printf("%c",s[i]),fflush(stdout);
	printf("\n"),fflush(stdout);
}

int query(str s){
	printf("? "),fflush(stdout);
	print(s);
	int ret;
	scanf("%d",&ret);
	return ret;
}

str InsertFromEnd(str s,int pos,char c){
	str ret = s;
	ret.resize(s.size() - pos);
	ret.push_back(c);
	for(rg int i = s.size() - pos;i < s.size();i++)ret.push_back(s[i]);
	return ret;
}

str solve(int l,int r){
	if(l == r)return str(f[l],c[l]);
	int m = (l + r) >> 1;
//cout<<"solve: l="<<l<<" r="<<r<<endl;
	str A = solve(l,m),B = solve(m + 1,r);
//cout<<"A=";print(A);
//cout<<"B=";print(B);
	str C = A;
	int p = -1,curans = len - A.size();
	for(rg int i = 0;i < A.size();i++){
		while(p + 1 < B.size() && query(InsertFromEnd(C,A.size()-i,B[p+1])) == curans - 1){
			curans--;
			C = InsertFromEnd(C,A.size()-i,B[p+1]);
			p++;
		}
	}
	for(p++;p < B.size();p++)C.push_back(B[p]);
	return C;
} 

void report(str ans){
	printf("! "),fflush(stdout);
	print(ans);
}

int main(){
//	freopen("AGC044D.in","r",stdin);
//	freopen("AGC044D.out","w",stdout);
	
	for(rg int i = 1;i <= 26;i++)c[i] = i - 1 + 'A';
	for(rg int i = 1;i <= 26;i++)c[i+26] = i - 1 + 'a';
	for(rg int i = 1;i <= 10;i++)c[i+52] = i - 1 + '0';
	
	for(rg int i = 1;i <= M;i++)f[i] = 128 - query(str(128,c[i]));		
	for(rg int i = 1;i <= M;i++)len += f[i];
//for(rg int i = 1;i <= M;i++)cout<<f[i]<<" ";cout<<endl;
//cout<<len<<endl;
	
	report(solve(1,M));
	
	return 0;
}

Measured memory_bytes: 3812
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    static long[][] comb = new long[51][51];
    public static void combTable() {
        for (int i = 0; i <= 50; ++i) {
            for (int j = 0; j <= i; ++j) {
                if (j == 0 || j == i) {
                    comb[i][j] = 1;
                } else {
                    comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
                }
            }
        }
    }

    public static void main(String[] args) {
        combTable();
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt();
        Long[] V = new Long[N];
        for (int i = 0; i < N; ++i) {
            V[i] = sc.nextLong();
        }
        Arrays.sort(V, Collections.reverseOrder());
        int maxvLastIdx = 0;
        int aValNum = 0, aValPos = 0;
        for (int i = 0; i < N; ++i) {
            if (V[i] == V[A-1]) {
                ++aValNum;
                if (i < A) {
                    ++aValPos;
                }
            }
        }
        double avg = 0.0;
        for (int i = 0; i < A; ++i) {
            avg += V[i];
        }
        avg /= A;
        long ret = 0;
        int count = 0, other = 0;
        for (int i = 0; i < N; ++i) {
            if (V[A-1].equals(V[i])) {
                ++count;
            }
            if (V[A-1] < V[i]) {
                ++other;
            }
        }
        if (other == 0) {
            for (int i = A; i <= B; ++i) {
                if (count >= i) {
                    ret += comb[count][i];
                }
            }
        } else {
            ret += comb[count][A - other];
        }
        System.out.printf("%.6f\n", avg);
        System.out.println(ret);
    }
}


Measured memory_bytes: 23508
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI p(n), q(n);
    REP(i,n) p[i] = in() - 1;
    REP(i,n) q[i] = in() - 1;
    VI d(n);
    REP(i,n) d[i] = i;
    int i = 0, a = -1, b = -1;
    do {
        if (d == p) a = i;
        if (d == q) b = i;
        i++;
    }while (next_permutation(ALL(d)));
    cout << abs(a - b) << endl;
    return 0;
}


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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
    os << "[";
    for (auto x : V) os << x << ", ";
    return os << "]";
}
//--------------------------------------------------//

int main() {
    use_cio();
    int cnt[5] = {0};
    rep(i, 3) {
        int a, b;
        cin >> a >> b;
        cnt[a]++, cnt[b]++;
    }
    rep(i, 5) if (cnt[i] >= 3) return !(cout << "NO\n");
    cout << "YES\n";
}


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

int main(void) {
  char s[15], t;
  long long i, j, k, n;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    long long min, max;
    scanf("%s", s);
    for(j = 0; j < 8; ++j) for(k = j + 1; k < 8; ++k) if(s[j] > s[k]) t = s[j], s[j] = s[k], s[k] = t;
    min = atoll(s);
    for(j = 0; j < 8; ++j) for(k = j + 1; k < 8; ++k) if(s[j] < s[k]) t = s[j], s[j] = s[k], s[k] = t;
     max = atoll(s);
     printf("%lld\n", max - min);
  }
}


Measured memory_bytes: 2580
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN (200000 + 5)
#define INF (0x7fffffff)
#define LL long long
using namespace std;
int n, a[MAXN];
LL ans;
LL solve()
{
	LL sum = 0, xsum = 0;
	int he = 1, ta = 0, lastt = 0;
	while (true)
	{
		sum += a[++ta];
		xsum ^= a[ta];
		if (xsum != sum)
		{
			LL dqn = ta - he, emm = max(0, (lastt - he + 1));
			ans += (dqn * (dqn + 1)) >> 1;
			ans -= (emm * (emm + 1)) >> 1;
			lastt = ta - 1;
			while (xsum != sum)
			{
				sum -= a[he];
				xsum ^= a[he++];
			}
			if (ta == n)
			{
				dqn = n - he + 1, emm = max(0, (lastt - he + 1));
				ans += (dqn * (dqn + 1)) >> 1;
				ans -= (emm * (emm + 1)) >> 1;
				break;
			}
		}
		else if (ta == n)
		{
			LL dqn = ta - he + 1, emm = max(0, (lastt - he + 1));
			ans += (dqn * (dqn + 1)) >> 1;
			ans -= (emm * (emm + 1)) >> 1;
			break;
		}
	}
	return ans;
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	printf("%lld\n", solve());
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <forward_list>
#include <queue>

using namespace std;

int cnt = 0;
int cntp = 0;

queue<int> source;
vector<int> pre;
vector<int> in;

class Edge{
public:
  int v;
  int w;
  Edge(int vi,int wi):v(vi),w(wi){;}
};

class Graph{
public:
    int V;
    int E;
    vector<forward_list<int>> adj_list;
    Graph(int v,int e):V(v),E(e){
        adj_list.resize(V);
        pre.resize(V);
        in.resize(V);
        for(int i = 0; i < V;i++) {pre[i] = -1;in[i] = 0;}
    }
    void addEdge(int v,int w){
        adj_list[v].push_front(w);
    }
};

int main(){
    int V,E,v,w;
    scanf("%d %d",&V,&E);
    Graph G(V,E);
    for(int i = 0; i < E;i++){
        scanf("%d %d",&v,&w);
        G.addEdge(v,w);
        in[w]++;
    }

    for(int i = 0; i < V;i++){
        if(!in[i]) source.push(i);
    }
    while(!source.empty()){
        int j = source.front();
        pre[j] = 0;
        printf("%d\n",j);
        source.pop();
        for(auto a = G.adj_list[j].begin();a!=G.adj_list[j].end();++a){
            int v = *a;
            if(pre[v] == -1){
               if(--in[v] == 0)
                    source.push(v);
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3904
import sys
C =[0 for _ in range(3)]
for i in range(3):
    C[i] = list(map(int,input().split()))

for i in range(2):
    for j in range(2):
        if C[i][j] - C[i][j+1] == C[i+1][j] - C[i+1][j+1] and\
           C[j][i] - C[j+1][i] == C[j][i+1] - C[j+1][i+1]:
            continue
        else:
            print("No")
            sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  ll b;
  cin>>b;
  if(a%b==0){
    cout<<0<<endl;
    return 0;
  }
  cout<<1<<endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(), A.end());
    auto f = [&](ll tar, ll a) -> ll{
        ll l = -1, r = N;
        while(r - l > 1){
            ll m = (l + r) >> 1;
            if(a * A[m] <= tar){
                if(a < 0) r = m;
                else l = m;
            }
            else{
                if(a < 0) l = m;
                else r = m;
            }
        }
        if(a < 0) return N - r;
        else return r;
    };

    ll l = -LINF, r = LINF;
    while(r - l > 1){
        ll m = (r + l) >> 1;
        ll cnt = 0;
        REP(i,N){
            cnt += f(m, A[i]);
            if(A[i] * A[i] <= m) cnt--;
        }
        if(cnt / 2 >= K) r = m;
        else l = m;
    }
    cout << r << endl;
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		
		Scanner sc = new Scanner(System.in);
		
		String x = sc.next();
		
		String a;
		String ans = "";
		
		for(int i=0; i<x.length(); i++){
			if((a = x.substring(i, i+1)).equals("B")){
				if(ans.length() == 0)continue;
				ans = ans.substring(0, ans.length()-1);
			}else{
				ans = ans + a;
			}
		}
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 9684
#include <stdio.h>

const long long mod = 1000000007;
long long inv[500500] = { 0, 1 }, fact[500500] = { 1, 1 }, ifact[500500] = { 1, 1 };
int n, m;

int main()
{
	for (int i = 2; i < 500500; i++){
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		fact[i] = fact[i - 1] * i % mod;
		ifact[i] = ifact[i - 1] * inv[i] % mod;
	}

	long long a = 0;
	scanf ("%d %d", &n, &m);
	for (int k = 0; k <= n; k++){
		long long g = fact[n] * ifact[k] % mod * ifact[n - k] % mod;
		long long s = fact[m] * ifact[m - k] % mod;
		long long p = fact[m - k] * ifact[m - n] % mod;
		long long c = g * s % mod * p % mod * p % mod;
		if (k % 2) a = (a + mod - c) % mod;
		else a = (a + c) % mod;
	}

	printf ("%lld\n", a);
	return 0;

}

Measured memory_bytes: 14928