akhauriyash/Code-Regression huggingface dataset:
import heapq

N, M, S = map(int, input().split())
Cost = [[] for _ in range(N)]
Change = [[0]*2 for _ in range(N)]
A_m = 0
for i in range(M):
    u, v, a, b = map(int, input().split())
    A_m = max(A_m, a)
    Cost[u-1].append([v-1, a, b])
    Cost[v-1].append([u-1, a, b])
for i in range(N):
    c, d = map(int, input().split())
    Change[i][0] = c
    Change[i][1] = d
if S > A_m*N:
    S = A_m*N

def dijkstra(N, start, Cost, Change):
    rich = [[] for _ in range(N+1)]
    Ans = [10**18]*N
    Ans[0] = 0
    minHeap = []
    used = [[10**18]*(A_m*N + 1) for _ in range(N)]
    used[start][S] = 0
    heapq.heappush(minHeap, (0, S, start))
    while minHeap:
        (c, hold, current) = heapq.heappop(minHeap)
        if rich[current] and rich[current][-1] >= hold:
            continue
        rich[current].append(hold)
        j = 1
        for i in range(N):
            if Ans[i] > c:
                j = 0
                break
        if j == 1:
            break
        for P in Cost[current]:
            road, a, b = P
            if hold >= a:
                if used[road][hold - a] > c + b:
                    used[road][hold - a] = c + b
                    heapq.heappush(minHeap, (c + b, hold - a, road))
                if Ans[road] > c + b:
                    Ans[road] = c + b
        if hold + Change[current][0] <= A_m*N:
            if used[current][hold + Change[current][0]] > c + Change[current][1]:
                heapq.heappush(minHeap, (c + Change[current][1], hold + Change[current][0], current))
    return Ans

T = dijkstra(N, 0, Cost, Change)
for i in T[1:]:
    print(i)

Measured memory_bytes: 77624
def binom(n,r):
    if n<r or n<0:
        return 0

    result=1
    for i in range(r):
        result*=(n-i)
        result//=(i+1)
    return result

n=int(input())
an=[int(c) for c in input().split()]

count=[0 for _ in range(n)]
for i in range(n):
    count[an[i]-1]+=1

sum_=0
minus=[0 for _ in range(n)]
for i in range(n):
    sum_+=binom(count[i],2)
    minus[i]=binom(count[i]-1,1)

for i in range(n):
    print(sum_-minus[an[i]-1])


Measured memory_bytes: 26140
#include <iostream>
#include <math.h>

using namespace std;

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

	int preTime = 0;
	int preX = 0, preY = 0;
	for (int i = 0; i < n;i++) {
		int t, x, y;
		cin >> t >> x >> y;

		int dt = t - preTime;
		int dist = abs(x - preX) + abs(y - preY);
		
		if (!(dt % 2 == dist % 2 && dt >= dist)) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

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

int main() {
	int n, l[11];
	cin >> n;
	int all = 0;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
		all += l[i];
	}
	for (int i = 0; i < n; i++) {
		if (l[i] >= (all - l[i])) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

if N < 1000:
    print(1000-N)

elif N == 1000:
    print(0)

elif 1000<N<2000:
    print(2000-N)

elif N == 2000:
    print(0)


elif 2000<N<3000:
    print(3000-N)

elif N == 3000:
    print(0)

elif 3000<N<4000:
    print(4000-N)

elif N == 4000:
    print(0)

elif 4000<N<5000:
    print(5000-N)

elif N == 5000:
    print(0)

elif 5000<N<6000:
    print(6000-N)

elif N == 6000:
    print(0)

elif 6000<N<7000:
    print(7000-N)

elif N == 7000:
    print(0)

elif 7000<N<8000:
    print(8000-N)

elif N == 8000:
    print(0)

elif 8000 < N < 9000:
    print(9000-N)

elif N == 9000:
    print(0)

elif 9000<N<10000:
    print(10000-N)

elif N == 10000:
    print(0)

Measured memory_bytes: 9196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e12)
#define PI (acos(-1))

// #define amari(x) ((x) % 1000000007)
#define amari(x) ((x) % 998244353)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(int i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll f(ll a, ll b) {
  ll c = a%b;
  if (c) {
    return f(b, c);
  } else {
    return b;
  }
}

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

  int t;
  cin >> t;

  vector<ll> a(t);
  vector<ll> b(t);
  vector<ll> c(t);
  vector<ll> d(t);

  for (int i = 0; i < (t); i++) scanf("%lld %lld %lld %lld", &a[i], &b[i], &c[i], &d[i]);

  rep(i, t) {
    if (a[i] < b[i] || d[i] < b[i] || c[i] + f(d[i], b[i]) < b[i] || a[i] % b[i] > c[i]) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		double r = s.nextDouble();
		double a = r*r*Math.PI;
		String c = String.format("%.6f",a);
		double b = r*2*Math.PI;
		String d = String.format("%.6f",b);
		
		System.out.println(c+" "+d);
	}
}

Measured memory_bytes: 28160
#include <bits/stdc++.h>
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const long long INF = 9e9;

using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N],B[N],C[N];
  rep0(i,N){
    cin >> A[i] >> B[i] >> C[i];
  }
  long long dpA[N],dpB[N],dpC[N];
  rep0(i,N){
    dpA[i] = INF;
    dpB[i] = INF;
    dpC[i] = INF;
  }
  dpA[0]=A[0];
  dpB[0]=B[0];
  dpC[0]=C[0];

  rep1(i,N-1){
    dpA[i] = A[i] + max(dpB[i-1],dpC[i-1]);
    dpB[i] = B[i] + max(dpC[i-1],dpA[i-1]);
    dpC[i] = C[i] + max(dpA[i-1],dpB[i-1]);
  }
  
  cout << max(dpA[N-1], max(dpB[N-1],dpC[N-1])) << endl;
}

Measured memory_bytes: 3712
#include<cstdio>
#define ll long long
using namespace std;
int main() {
	ll n, m;
	scanf("%lld %lld", &n, &m);
	if (n == m) {
		puts("0");
		return 0;
	}
	if (m == 0) {
		if (n < 0)
			printf("%lld", -n);
		else
			printf("%lld", n + 1);
      return 0;
	}
	if (n >= 0)
	{
		if (m >= 0) {
			if (n > m)
				printf("%lld", n - m + 2);
			else
				printf("%lld", m - n);
		}
		else
		{
			m = -m;
			if (n < m) {
				printf("%lld", m - n + 1);
			}
			else
			{
				printf("%lld", n - m + 1);
			}
		}
	}
	else
	{
		n =- n;
		if (m >= 0)
		{
			if (n > m)
				printf("%lld", n - m + 1);
			else
				printf("%lld", m - n+1);
		}
		else
		{
			m = -m;
			if (n < m)
				printf("%lld", m - n + 2);
			else
				printf("%lld", n - m);
		}
	}
}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  ll n;
  cin >> n;
  vector<ll> x(n), s(n);
  rep(i, n) {
    cin >> x[i];
    s[i] = x[i];
  }
  sort(all(s));
  ll ans1 = s[n/2], ans2 = s[n/2 - 1];
  rep(i, n) {
    if(x[i] < ans1) cout << ans1 << endl;
    else cout << ans2 << endl;
  }
  return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s, t;
    cin >> s >> t;
    int n = s.size();

    if (s == t.substr(0, n)) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}



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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.rbegin(), A.rend());
  long long ans = 0;
  int t = N - 1;

  for (int i = 0; i < N; i++) {
    int lim = 2;
    if (i == 0) lim = 1;
    for (int j = 0; j < lim; j++) {
      if (t > 0) ans += A.at(i);
      t--;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4056
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>

#define FORN(n) for(int i=0;i<n;i++)
#define PINT(d) printf("%d\n", d);
#define PDOUBLE(lf) printf("%lf\n", lf);
#define PSTR(s) printf("%s\n", s);
#define INF 2147483647

using namespace std;
     
main(){
    string str;
    char his[3] = {"\0"};
    int i = 0, l = -1, r = -1;
    
    cin >> str;
    
    while(i < str.length()){
        his[0] = str[i];
        i++;
        if(his[0] == his[1]){
            l = i-1;
            r = i;
            break;
        }else if(his[0] == his[2]){
            l = i-2;
            r = i;
            break;
        }
        his[2] = his[1];
        his[1] = his[0];
    }
    printf("%d %d", l, r);
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  char s[4];
  int count_plus=0;
  scanf("%s", s);

  for(int i=0;i<4;i++){
    if(s[i]=='+'){
      count_plus++;
    }
  }
  printf("%d\n", 2*count_plus - 4);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
using namespace std;
const int N=2e5+100,mod=1e9+7;
int32_t main(){
    string s,t;
    cin >> s >> t;
    string y=t+s;
    cout << y << endl;
}


Measured memory_bytes: 256
import bisect

N, M = map(int, input().split())
table = []
for _ in range(M):
    p, y = map(int, input().split())
    table.append((p, y))

vals = [[] for i in range(N)]

for i in range(M):
    p, y = table[i]
    vals[p-1].append(y)

for i in range(N):
    vals[i].sort()

for i in range(M):
    p, y = table[i]
    s = bisect.bisect_left(vals[p-1], y)+1
    print('%06d'%p + '%06d'%s)


Measured memory_bytes: 29624
# include <bits/stdc++.h>
 
/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}
 
const int xn = 1e5 + 10;
const int xm = - 20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int mod = 1e9 + 7;
const int TM = 3;
const int base = 257;

ll n, sz[xn], D[xn], ord[xn], cnt, H[xn], sum;
vector <pii> ans;
unordered_map <ll, int> mp;
vector <int> adj[xn];
bool mark[xn];

bool cmp(int i, int j){ return D[i] > D[j];}
void DFS(int v){
	mark[v] = true;
	++ cnt;
	sum += H[v];
	for (int u : adj[v]){
		if (mark[u]) continue;
		H[u] = H[v] + 1;
		DFS(u);
	}
}

int main(){
    InTheNameOfGod;
    
	cin >> n;
	for (int i = 1; i <= n; ++ i){
		cin >> D[i];
		ord[i] = i;
		sz[i] = 1;
		mp[D[i]] = i;
	}
	sort(ord + 1, ord + n + 1, cmp);
	for (int i = 1; i < n; ++ i){
		int v = ord[i];
		int par = mp[D[v] - n + sz[v] + sz[v]];
		if (!par) kill(- 1);
		ans.push_back({v, par});
		adj[par].push_back(v);
		adj[v].push_back(par);
		sz[par] += sz[v];
	}
	DFS(1);
	if (cnt < n || sum != D[1]) kill(- 1);
	for (pii e : ans) cout << e.A << sep << e.B << endl;
 
    return 0;
}


Measured memory_bytes: 21440
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public int minJumps(int[] heights) {
        int n = heights.length;
        int[] memo = new int[n];
        Arrays.fill(memo, -1);
		return dfs(heights, 0, memo);
	}
	private int dfs(int[] heights, int currPos, int[] memo) {
		int n = heights.length;
		if (currPos + 1 >= n) {
			return 0;
		}
        if (memo[currPos] != -1) {
            return memo[currPos];
        }
		int oneJump = Math.abs(heights[currPos] - heights[currPos + 1]) + dfs(heights, currPos + 1, memo);
		int twoJumps = Integer.MAX_VALUE;
		if (currPos + 2 < n) {
			twoJumps = Math.abs(heights[currPos] - heights[currPos + 2]) + dfs(heights, currPos + 2, memo);
		}
		return memo[currPos] = Math.min(oneJump, twoJumps);
	}

    public static void main(String[] args)  {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(br.readLine());
            String heightsStr = br.readLine();
            String[] split = heightsStr.split(" ");
          	int[] heights = new int[n];
            for (int i = 0; i < n; i++) {
              	heights[i] = Integer.parseInt(split[i]);
            }
          	Main app = new Main();
            int result = app.minJumps(heights);
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 50208
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a1,a2,a3;
  cin>>a1>>a2>>a3;
  if(a1>a2&&a2>a3)cout<<a1-a3<<endl;
  else if(a1>a3&&a3>a2)cout<<a1-a2<<endl;
  else if(a2>a1&&a1>a3)cout<<a2-a3<<endl;
  else if(a2>a3&&a3>a1)cout<<a2-a1<<endl;
  else if(a3>a1&&a1>a2)cout<<a3-a2<<endl;
  else if(a3>a2&&a2>a1)cout<<a3-a1<<endl;
  else if(a1==a2&&a1<a3)cout<<a3-a1<<endl;
  else if(a1==a2&&a1>a3)cout<<a1-a3<<endl;
  else if(a1==a3&&a1<a2)cout<<a2-a1<<endl;
  else if(a1==a3&&a1>a2)cout<<a1-a2<<endl;
  else if(a2==a3&&a2<a1)cout<<a1-a2<<endl;
  else if(a2==a3&&a2>a1)cout<<a2-a1<<endl;
  else cout<<0<<endl;
  return 0;
}


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

min = n

def digits_sum(x):
    _x = 0
    while x > 0:
        _x += x % 10
        x //= 10
    
    return _x


for i in range(2, n):
    a = i
    b = n - i
    if digits_sum(a) + digits_sum(b) < min:
        min = digits_sum(a) + digits_sum(b)

print(min)

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

int main() {
  int n, q, p, x;
  cin >> n >> q;
  vector<int> a(n - 1), b(n - 1), c(n);
  vector<vector<int>> r(n, vector<int>());
  for(int i = 0; i < n - 1; i++) {
    cin >> a.at(i) >> b.at(i);
    r.at(--a.at(i)).push_back(--b.at(i));
    r.at(b.at(i)).push_back(a.at(i));
  }
  for(int i = 0; i < q; i++) {
    cin >> p >> x;
    c.at(--p) += x;
  }
  queue<pair<int, int>> que;
  pair<int, int> t;
  for(int i = 0; i < r.at(0).size(); i++) {
    c.at(r.at(0).at(i)) += c.at(0);
    que.push({r.at(0).at(i), 0});
  }
  while(que.size()) {
    t = que.front();
    que.pop();
    for(int i = 0; i < r.at(t.first).size(); i++) {
      if(r.at(t.first).at(i) != t.second) {
        c.at(r.at(t.first).at(i)) += c.at(t.first);
        que.push({r.at(t.first).at(i), t.first});
      }
    }
  }
  for(int i = 0; i < n; i++)
    printf("%d ", c.at(i));
  printf("\n");
}

Measured memory_bytes: 17908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int n, m;
vector<string> a;
vector<string> b;

bool check(int y, int x){
    for(auto s: b){
        if(s != a[y].substr(x, m))
            return false;
        y++;
    }
    return true;
}

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

    for(int i = 0; i < n; i++){
        string s; cin >> s;
        a.emplace_back(s);
    }
    for(int i = 0; i < m; i++){
        string s; cin >> s;
        b.emplace_back(s);
    }

    string key = b[0];
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= n-m; j++){
            if(n-i >= m && key == a[i].substr(j, m)){
                if(check(i, j)){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}


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

const int INF = 100000000;

template <typename T>
struct Edge
{
    int to;
    T cap;
    int rev;
    int id;
};

template <typename T>
struct Flow
{
    int n, c;
    vector<vector<Edge<T>>> g;
    vector<int> ch;
    
    Flow(){}
    
    Flow(int n) : n(n), c(1){
        g.resize(n);
        ch.resize(n);
    }
    
    void add_edge(int from, int to, T cap, int id = -1){
        g[from].push_back((Edge<T>){to, cap, (int)g[to].size(), id});
        g[to].push_back((Edge<T>){from, 0, (int)g[from].size() - 1, -1});
    }
    
    T dfs(int u, T f, int t){
        if(u == t) return f;
        ch[u] = c;
        for(int i = 0; i < (int)g[u].size(); i++){
            Edge<T> &e = g[u][i];
            int v = e.to;
            if(e.cap > 0 && ch[v] != c){
                T fl = dfs(v, min(f, e.cap), t);
                if(fl > 0){
                    e.cap -= fl;
                    g[v][e.rev].cap += fl;
                    return fl;
                }
            }
        }
        return 0;
    }
    
    T max_flow(int s, int t){
        T res = 0;
        for(T f; (f = dfs(s, INF, t)) > 0; c++) res += f;
        return res;
    }
};

struct Bipartite_Matching
{
    int n;
    int m;
    Flow<int> g;
    vector<int> match;
    
    Bipartite_Matching(int n, int m) : n(n), m(m){
        g.n = n + m + 2;
        g.c = 1;
        g.ch.resize(g.n);
        g.g.resize(g.n);
        for(int i = 0; i < n; i++) g.add_edge(n + m, i, 1);
        for(int i = n; i < n + m; i++) g.add_edge(i, n + m + 1, 1);
    }
    
    void add_edge(int i, int j, int id = -1){
        g.add_edge(i, j + n, 1, id);
    }
    
    int max_matching(){
        g.max_flow(n + m, n + m + 1);
        for(int i = 0; i < n; i++){
            for(int j = 1; j < (int)g.g[i].size(); j++){
                if(g.g[i][j].cap == 0) match.push_back(g.g[i][j].id);
            }
        }
        return (int)match.size();
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    int a[102][102];
    int d[10005];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            a[i][j]--;
            d[a[i][j]] = i;
        }
    }
    int b[10005];
    for(int i = 0; i < n * m; i++) b[i] = -1;
    for(int k = 0; k < m; k++){
        Bipartite_Matching g(n, n);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(b[a[i][j]] == -1) g.add_edge(i, a[i][j] / m, a[i][j]);
            }
        }
        g.max_matching();
        for(int id : g.match) b[id] = k;
    }
    int c[105][105];
    for(int i = 0; i < n * m; i++){
        c[d[i]][b[i]] = i;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cout << c[i][j] + 1 << " ";
        cout << endl;
    }
    for(int i = 0; i < n * m; i++){
        c[i / m][b[i]] = i;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cout << c[i][j] + 1 << " ";
        cout << endl;
    }
}


Measured memory_bytes: 4132
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt;ll ans;
int a[200010];
map<int,int>s;
int main(){
	n=r;
	for(rt i=1;i<=n;i++)a[i]=r,s[a[i]]++;
	sort(a+1,a+n+1,greater<int>());
	int lim=1<<30;
	for(rt i=1;i<=n;i++)if(s[a[i]]){
		while(a[i]+a[i]<lim)lim>>=1;
		if(a[i]+a[i]==lim){
			if(s[a[i]]>=2)ans++,s[a[i]]-=2;
		}
		else {
			if(s[lim-a[i]])ans++,s[lim-a[i]]--;
			s[a[i]]--;			
		}

	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 19712
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        a[i]=x-y,b[i]=x+y;
    }
    sort(a,a+n);
    sort(b,b+n);
    cout<<max(a[n-1]-a[0],b[n-1]-b[0])<<endl;
    return 0;
}

Measured memory_bytes: 5192
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

class UnionFind {
  vector<int> p;
public:
  UnionFind (int n) : p(n, -1) {}
  int root(int x) {
    return p[x] < 0 ? x : p[x] = root(p[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) swap(x, y);
    if (p[x] == p[y]) --p[x];
    p[y] = x;
    return true;
  }
};

void solve(ll N, vector<ll> x, vector<ll> y) {
  vector<pair<int,int>> ex, ey;
  REP(i,N) ex.emplace_back(x[i], i);
  REP(i,N) ey.emplace_back(y[i], i);
  sort(ALL(ex)); sort(ALL(ey));
  vector<tuple<int,int,int>> es;
  REP(i,N-1) es.emplace_back(ex[i+1].first - ex[i].first, ex[i].second, ex[i+1].second);
  REP(i,N-1) es.emplace_back(ey[i+1].first - ey[i].first, ey[i].second, ey[i+1].second);
  sort(ALL(es));
  UnionFind uf(N);
  ll res = 0;
  for (auto t: es) {
    int c, a, b;
    tie(c, a, b) = t;
    if (!uf.same(a, b)) {
      res += c;
      uf.unite(a, b);
    }
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> x(N-1+1);
	vector<ll> y(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &x[i]);
	  scanf("%lld", &y[i]);
	}
	solve(N, x, y);
	return 0;
}


Measured memory_bytes: 10092
#include<iostream> 
#include<cstring>
using namespace std;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
int main()
{
	int a[maxn]; 
	int dp[maxn];
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	 cin>>a[i];
	memset(dp,0x3f,sizeof(dp));
	dp[1]=0;
	for(int i=2;i<=n;i++)
		for(int j=1;j<=k;j++)
		{
			if(i-j<1)
				break;
			dp[i]=min(dp[i],dp[i-j]+(abs(a[i]-a[i-j])));
		}			
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 4360
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;


int main() {
    ll N,M;
    cin>>N>>M;
    int mx =max(N,M);
    int mn =min(N,M);
    if(mn==1){
        if(mx==1)cout<<1<<endl;
        else cout<<mx-2<<endl;
    }
    else cout <<(ll)(N-2)*(M-2)<<endl;
}

Measured memory_bytes: 256
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
K = int(input())
cnt = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            cnt += gcd(a,gcd(b,c))
print(cnt)

Measured memory_bytes: 68772
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int N; cin >> N;
    vector<string> vs(N);
    for(auto& s : vs) cin >> s;
    int res = 0;
    for(int i=0;i<N;i++){
        bool ok = true;
        for(int j=0;j<N;j++){
            for(int k=j+1;k<N;k++){
                int b = (k+i)%N;
                if(vs[j][(k+i)%N] != vs[k][(j+i)%N]) ok = false;
            }
        }
        if(ok) res += N;
    }
    cout << res << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
	int seisu1,seisu2,seisu3;//??\?????¨?????°
	scanf("%d%d%d",&seisu1,&seisu2,&seisu3);//??\?????????
	if(seisu1<seisu2){
		if(seisu2<seisu3){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=2e5+5;
int n,mx[N],foo[N],bar[N],ans[N];vector<int>E[N];
void dfs(int u,int f,int val,int fg){
	foo[u]=1;bar[u]=fg;
	for(int v:E[u])
		if(v!=f&&mx[v]==mx[u])
			dfs(v,u,val,fg&(v<val)),foo[u]+=foo[v],bar[u]+=bar[v];
}
void dfs1(int u,int f){
	mx[u]=max(mx[f],u);
	for(int v:E[u])if(v!=f)dfs1(v,u);
	if(mx[u]==u)dfs(u,f,mx[f],1);
}
void dfs2(int u,int f){
	if(mx[u]==u)ans[u]=bar[u];
	else if(mx[f]==f)ans[u]=foo[u]-bar[u];
	ans[u]+=ans[f];
	for(int v:E[u])if(v!=f)dfs2(v,u);
}
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		E[x].push_back(y);E[y].push_back(x);
	}
	dfs1(1,0);dfs2(1,0);
	for(int i=2;i<=n;++i)printf("%d ",ans[i]-1);
	puts("");return 0;
}


Measured memory_bytes: 31232
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
const int mod=1e9+7;
int POW(int x,int y){
	if(!y)RE 1;
	int t=POW(x,y/2);
	t=t*t%mod;
	if(y&1)RE t*x%mod;
	else RE t;
}
int dp[100005];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k,ans=0;
	cin>>n>>k;
	for(int i=k;i>=1;i--){
		dp[i]=POW(k/i,n);
		for(int j=i+i;j<=k;j+=i)dp[i]=(dp[i]-dp[j])%mod;
		dp[i]=(dp[i]+mod)%mod;
		ans=(ans+dp[i]*i)%mod; 
	}
	cout<<ans<<'\n';
	RE 0;
}




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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arrll(a,n);

  ll x=0, y=f_sumll(a);
  ll ans=1e17;
  rep(i,n-1){
    x += a[i];
    y -= a[i];
    chmin(ans, abs(x-y));
  }

  prt(ans);

}


Measured memory_bytes: 1792
import java.util.*;

//文字操作
class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		int num=0;
		while(sc.hasNext()){
			String str=sc.nextLine();
			int val=0;
			for(int i=0,s=str.length();i<s;i++){
				if('0'<=str.charAt(i)&& str.charAt(i)<='9'){
					val=val*10+str.charAt(i)-'0';
				}else{
					num+=val;
					val=0;
				}
			}
			num+=val;
		}
		ln(num);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
N = int(input())
P = [0]
P.extend(map(float, input().split()))

dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = 1

for i in range(1, N+1):
    for j in range(1, N+1):
        dp[i][j] = dp[i-1][j-1] * P[i] + dp[i-1][j] * (1-P[i])

print(dp[-1][N//2+1])


Measured memory_bytes: 256008
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair




int main(){
    ll n;
    cin>>n;
    vector<ll> a;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        a.push_back(b);
    }
    for(int i=1;i<n;i++){
        a[i]+=a[i-1];
    }
    ll ans=E;
    ll b=0,d=-1;
    for(int i=2;i<n-2;i++){
        if(abs(a[n-1]-a[i]-(a[i]-a[1]))<abs(a[n-1]-a[i+1]-(a[i+1]-a[1]))){d=i; break;}
    }
    if(d==-1){d=n-2;}
    for(int c=1;c<n-2;c++){
        while(b<c-1 && abs(a[c]-a[b]-a[b])>abs(a[c]-a[b+1]-a[b+1])){b++;}
        if(c==d){d++;}
        while(d<n-2 && abs(a[n-1]-a[d]-(a[d]-a[c]))>abs(a[n-1]-a[d+1]-(a[d+1]-a[c]))){d++;}
        ll mx=max(max(a[b],a[c]-a[b]),max(a[d]-a[c],a[n-1]-a[d]));
        ll mi=min(min(a[b],a[c]-a[b]),min(a[d]-a[c],a[n-1]-a[d]));
        ans=min(ans,mx-mi);
    }
    cout<<ans<<endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    cout << (N+1)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

bool check(int[] a,int[] b){
    if(a.length == b.length){
	for(int i=0;i<a.length;i++){
	    if(a[i] != b[i]) return false;
	}
    }else return false;

    return true;
}

void main(){

    while(true){
	int n = readln().chomp().to!int;
	if(n == 0) break;
	int[] a,b;
	a = new int[n];
	b = new int[n];
	a = readln().split().to!(int[]);
	int ans;
	while(true){
	    for(int i=0;i<n;i++){
		int count = 0;
		for(int j=0;j<n;j++){
		    if(a[i] == a[j]) count++;
		}
		b[i] = count;
	    }
	    if(check(a,b)){
		writeln(ans);
		auto res = a.to!(string[]);
		res.join(" ").writeln();
		break;
	    }
	    swap(a,b);
	    ans++;
	}
    }
}

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

bool card[4][13];

int main(){
	int n, x, y;
	char s[2];
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%s%d", s, &x);
		switch(s[0]) {
		case 'S': y = 0; break;
		case 'H': y = 1; break;
		case 'C': y = 2; break;
		case 'D': y = 3; break;
		}
		card[y][x-1] = true;
	}
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 13; j++) {
			if(card[i][j]) continue;
			switch(i) {
			case 0: s[0] = 'S'; break;
			case 1: s[0] = 'H'; break;
			case 2: s[0] = 'C'; break;
			case 3: s[0] = 'D'; break;
			}
			printf("%c %d\n", s[0], j+1);
		}
	}
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,x,y;
  cin>>n>>x>>y;
  x--;
  y--;
  vvll t(n,vll(0));
  rep(i,n-1){
    t[i].pb(i+1);
    t[i+1].pb(i);
  }
  t[x].pb(y);
  t[y].pb(x);
  vll ans(n);
  rep(i,n){
    vb ch(n,false);
    vll kk(n);
    queue<ll> p;
    ch[i]=true;
    p.pu(i);
    while(sz(p)){
      ll s=p.front();
      p.pop();
      for(auto pp:t[s]){
        if(ch[pp]) continue;
        ch[pp]=true;
        kk[pp]=kk[s]+1;
        if(pp>i){
          ans[kk[pp]]++;
        }
        p.pu(pp);
      }
    }
  }
  rep(i,n){
    if(i==0) continue;
    COUT(ans[i]);
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

struct Point {
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) {}
    Point operator+(const Point &p) { return Point{x + p.x, y + p.y}; }
    Point operator-(const Point &p) { return Point{x - p.x, y - p.y}; }
    Point operator*(const double k) { return Point{x * k, y * k}; }

    double norm() { return x * x + y * y; }
    double abs() { return sqrt(norm()); }
};

typedef Point Vector;
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }

struct Segment {
    Point p1, p2;
};

typedef Segment Line;
bool isOrthogonal(Line l1, Line l2) {
    return dot(l1.p2 - l1.p1, l2.p2 - l2.p1) == 0;
}
bool isParallel(Line l1, Line l2) {
    return cross(l1.p2 - l1.p1, l2.p2 - l2.p1) == 0;
}
Point project(Line l, Point p) {
    Vector base = l.p2 - l.p1;
    double r = dot(p - l.p1, base) / base.norm();
    return l.p1 + base * r;
}

struct Circle {
    Point c;
    double r;
    Circle(Point c = Point(), double r = 0) : c(c), r(r) {}
};

typedef vector<Point> Polygon;

int main() {
    Line l;
    cin >> l.p1.x >> l.p1.y >> l.p2.x >> l.p2.y;
    int n;
    cin >> n;
    while(n--) {
        Point p;
        cin >> p.x >> p.y;
        Point ret = project(l, p);
        printf("%.10f %.10f\n", ret.x, ret.y);
    }
}


Measured memory_bytes: 3292
#include<stdio.h>
int main()
{
    int i,a,n,K,X,j=0;
    scanf("%d%d",&K,&X);

    i=X;
    n=2*K-1;
    while(j<n)
    {
        a=X-K+1;
        K--;
        j++;
        printf("%d ",a);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var tempArray = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        var N = tempArray[0];
        var K = tempArray[1];
        var Q = tempArray[2];

        var memberPoints = Enumerable.Repeat(K - Q, N).ToList();

        for (var i = 0; i < Q; i++)
        {
            var A = int.Parse(Console.ReadLine());

            memberPoints[A - 1]++;
        }

        for (var i = 0; i < N; i++)
        {
            if (memberPoints[i] > 0)
            {
                Console.WriteLine("Yes");
            }
            else if (memberPoints[i] <= 0)
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 18652
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	struct P
	{
		public long r, count;
	}

	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var h = read();
		long n = h[0], d = h[1], a = h[2];
		var ms = new int[n].Select(_ => read()).OrderBy(x => x[0]).ToArray();

		long sc = 0, tc = 0;
		var q = new Queue<P>();
		foreach (var m in ms)
		{
			P p;
			while (q.Any() && (p = q.Peek()).r < m[0])
			{
				tc -= p.count;
				q.Dequeue();
			}

			var c = (m[1] - 1) / a + 1 - tc;
			if (c <= 0) continue;
			sc += c;
			tc += c;
			q.Enqueue(new P { r = m[0] + 2 * d, count = c });
		}
		Console.WriteLine(sc);
	}
}


Measured memory_bytes: 39140
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int n, k;
	int x, y, z;
	scanf("%d%d%d", &x,&y,&z);
	n = max(max(x, y), z);
	k = min(min(x, y), z);
	printf("%d\n", n - k);


	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string.h>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <sstream>
#include <stack>
#include <iomanip>
#include <climits>
#include <complex>
#include <cmath>
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ii, int> iii;

const int maxN = 5e5 + 9, maxV = 5e5, MOD = 1e9 + 7 , lg = 20, LIM = 100;

int n, h, w;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> h >> w;
    
    cout << (n - h + 1) * (n - w + 1) << '\n';
    
    
}

/*
 4
 7 2 3 4
 1
 1 4
 */


Measured memory_bytes: 256
import math
A,B,H,M =map(int,input().split())
ans = 0
kaku = 30 * H -5.5 * M
if abs(kaku) > 180:
    kaku = 360-abs(kaku)
ans = math.sqrt(A**2 + B**2 -2*A*B*math.cos(math.radians(abs(kaku))))
print(ans)         

Measured memory_bytes: 9480
#include <iostream>
using namespace std;
int main(){
  long a, b, k, count = 0;
  cin >> a >> b >> k;
  
  if(a+b<=k){
    cout << 0 << " " << 0 << endl;
  	return 0;
  }else{
    if(a-k>=0){
      cout << a-k << " " << b << endl;
    }else{
      cout << 0 << " " << b-(k-a) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>v;
    cout.precision(30);
    long double res=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        res+=1/double(a);
    }
    res=1/res;
    cout<<res<<endl;
    return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#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++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n;
	cin >> n;
	str s;
	cin >> s;
	map<char, int> y;
	rep(i, s.size())
	{
		y[s[i]]++;
	}
	map<char, int> x;
	ll ans = 0;
	rep(i, s.size())
	{
		x[s[i]]++;
		y[s[i]]--;
		ll tmp_ans = 0;
		for (auto xxx : x)
		{
			if (y[xxx.first] > 0)
			{
				tmp_ans++;
			}
		}
		ans = max(tmp_ans, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

a,b=get_i
def extra_gcd(a,b,x,y)
    if b.zero?
        x=1
        y=0
        return a,x,y
    end
    d,y,x=extra_gcd(b,a%b,y,x)
    y-=a/b*x
    return d,x,y
end
x,y=nil,nil
_,x,y=extra_gcd(a,b,x,y)
puts [x,y].join(" ")


Measured memory_bytes: 6884
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
#define   psi  pair<string,pii> 
using namespace std;

bool cmp(psi a,psi b){
    if (a.ff==b.ff) return a.ss.ff >= b.ss.ff;
    return a.ff <= b.ff;
}

inline void solve(){
    int n,score; cin>>n;
    vector<psi> v; 
    for (int i=1;i<=n;i++){
        string  s; 
        cin >> s >> score ; 
        v.emplace_back(s,make_pair(score,i));
    }
    sort(v.begin(), v.end(),cmp); 
    for (auto &it: v) cout << it.ss.ss << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3604
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static ArrayList<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] p = new int[n];
		for(i=0;i<n;i++) {
			p[i] = parseInt(sc.next());
		}
		sc.close();
		int cnt=0;
		int mn=200001;
		for (i = 0; i < n; i++) {
			if(p[i]<=mn) {
				cnt++;
				mn=p[i];
			}
		}
		out.println(cnt);
	}
}


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

int main() {
    ios_base::sync_with_stdio(false);
    char a,b;
    cin >> a >> b;
    if(a == b){cout << "=" << endl;}
    else if(a < b){cout << "<" << endl;}
    else if(a > b){cout << ">" << endl;}

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 1e+8;

typedef long long ll;


// http://stackoverflow.com/questions/1838368/calculating-the-amount-of-combinations
unsigned long long choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}


int main() {
  ios::sync_with_stdio(false);

  int N, A, B;
  cin >> N >> A >> B;

  vector<ll> v(N);
  for(int i = 0; i < N; i++) { cin >> v[i]; }

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  ll min_num = v[A-1];
  int mins_used = 0;

  ll sum = 0;
  for(int i = 0; i < A; i++) {
    sum += v[i];
    if( min_num == v[i] ) {
      mins_used++;
    }
  }
  double max_avr = (double)sum / A;

  int mins = 0;
  for( int i = 0; i < N; i++ ) {
    if( v[i] < min_num ) break;
    if( min_num == v[i] ) mins++;
  }

  // debug(min_num);
  // debug(mins);
  // debug(mins_used);

  cout << fixed;
  cout << max_avr << "\n";

  if(min_num == max_avr) {
    cout << fixed;
    ll ans = 0;
    for(int i = A; i <= B; i++) {
      ans += choose(mins, i);
    }
    cout << ans << "\n";
  } else {
    cout << choose(mins, mins_used) << "\n";
  }


  return 0;
}


Measured memory_bytes: 256