akhauriyash/Code-Regression huggingface dataset:
import heapq
H = []
V, E = map(int, input().split())
#G = [[] for _ in range(V)]
for _ in range(E):
    s, t, w = map(int, input().split())
    #G[s].append((t, w))
    heapq.heappush(H, (w, s, t))


class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n

    def root(self, a):
        if self.parent[a] < 0:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]

    def size(self, a):
        return - self.parent[self.root(a)]

    def connect(self, a, b) -> bool:
        a = self.root(a)
        b = self.root(b)

        if a == b:
            return False

        if self.size(a) < self.size(b):
            a, b = b, a

        self.parent[a] += self.parent[b]
        self.parent[b] = a
        return True


unif = UnionFind(V)
ans = 0
while len(H) > 0:
    w, s, t = heapq.heappop(H)
    if unif.root(s) == unif.root(t):
        continue

    unif.connect(s, t)
    ans += w

print(ans)



Measured memory_bytes: 22864
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll Pow_mod(ll a, ll b, ll p){
    ll ans = 1;
    a %= p;
    while (b){
        if (b & 1) ans = (ans * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return (ans % p);
}

int n;

int main(){
    scanf("%d", &n);
    if (n & 1)
        printf("%.6lf\n", (n / 2 + 1.0) / n);
    else
        printf("%.6lf\n", 0.5);
    return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int K = input(), N = input();
    vector< int > A(N);
    cin >> A;
    A.push_back(K + A[0]);
    
    int ans = inf;
    range(i, 1, A.size()) {
        chmin(ans, K - (A[i] - A[i - 1]));
    }
    
    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 1920
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {
        var AKB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var K = AKB[0];
        var A = AKB[1];
        var B = AKB[2];
        var ans = K+1;
        if(A < B)
        {
            ans = Math.Max(ans,A+(B-A)*((K - A + 1)/2) + (K - A + 1) % 2);
        }

        Console.WriteLine(ans);
    }
        

    
}


Measured memory_bytes: 28052
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// DAME:
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    s += s;
    map<char, vector<int>> sm;
    rep(i, s.size()) sm[s[i]].push_back(i);
    ll ans = 0;
    int index = -1;
    rep(i, t.size()){
        auto itr = lower_bound(sm[t[i]].begin(), sm[t[i]].end(), index+1);
        if (itr == sm[t[i]].end()){
            ans += s.size() - index;
            if (sm[t[i]].size() == 0){
                cout << -1 << endl;
                return 0;
            }
            index = sm[t[i]][0];
            ans += index;
        }else{
            ans += *itr - index;
            index = *itr;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1896
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		
		int i = 0;
		int arr[];
		while( sc.hasNext() ){
			arr = new int[2];
			
    		String line[] = sc.nextLine().split(" ");
			arr[0] = Integer.parseInt(line[0]);
			arr[1] = Integer.parseInt(line[1]);
			
    		System.out.println(String.valueOf(arr[0]+arr[1]).length());
		}
	}
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

# define fr(a,b) for(int i = a; i < b; i++)
# define rep(i,a,b) for(int i = a; i < b; i++)

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;


void solve(){

    string s;
    cin >> s;
    int sum = 0;
    rep(i,0,s.size()) sum+=(s[i]-'0');
    string ans = sum%9 ? "No" : "Yes";
    cout << ans;line
    return;

}

int main(){
    fast
    int t=1;
    //cin >> t;
    while(t--){
             solve();
    }

    R 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

ll mod = 1e9+7;

const int N = 4000004;
ll f[N], inv_f[N];

inline ll mod_pow(ll x, ll n)
{
    ll r = 1;
    while(n)
    {
        if(n&1) (r*=x)%=mod;
        (x*=x)%=mod;
        n>>=1;
    }
    return r;
}

inline ll mod_inv(ll x)
{
    return mod_pow(x,mod-2);
}


inline ll C(int n, int r)
{
    if(n<0 || r<0 || n-r<0) return 0;
    ll ret = f[n];
    (ret*=inv_f[r])%=mod;
    (ret*=inv_f[n-r])%=mod;
    return ret;
}

inline ll H(int n, int r)
{
    if(n==0 && r==0) return 1;
    return C(n+r-1,r);
}

int main()
{
    f[0]=1;
    for(int i=1; i<N; ++i) f[i]=(f[i-1]*i)%mod;

    inv_f[N-1] = mod_inv(f[N-1]);
    for(int i=N-2; i>=0; --i) inv_f[i] = (inv_f[i+1]*(i+1))%mod;

    int a,b,c,sx,sy;
    while(cin >>a >>b >>c >>sx >>sy)
    {
        if(a+b+c+sx+sy==0) break;
        ll ans = 0;
        rep(i,sx+1)
        {
            ll add = 1;
            int j = sy-sx+i;
            (add*=H(a,i-a))%=mod;
            (add*=H(b,j-b))%=mod;
            (add*=H(a+b+c,sx-i))%=mod;

            (ans += add)%=mod;
        }
        (ans*=C(a+b+c,a))%=mod;
        (ans*=C(b+c,b))%=mod;
        printf("%lld\n", ans);
    }
    return 0;
}

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

#define int ll

#define pb push_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int32_t main() {
	int n, k;
	cin >> n >> k;
	vector<bool> b(n);
	for(int i = 0; i < k; i++) {
		int d;
		cin >> d;
		for(int j = 0; j < d; j++) {
			int p;
			cin >> p;
			p--;
			b[p] = 1;
		}
	}
	int cnt = 0;
	for(int i = 0; i < n; i++)
		cnt += 1 - b[i];
	cout << cnt;
}


Measured memory_bytes: 3632
import math
n = int(input())

alist = []
for i in range(n):
    alist.append(int(round(float(input())*10**9)))

def two_five_power(n):
    a = 0
    b = 0
    while n % 2 == 0:
        n /=2
        a += 1
    while n % 5 == 0:
        n /= 5
        b += 1
    return (a,b)

ab_dict = dict()
for i in range(n):
    ab = two_five_power(alist[i])
    if ab in ab_dict:  
        ab_dict[ab] += 1
    else:
        ab_dict[ab] = 1

prev = 0
count = 0
for one in ab_dict:
    for two in ab_dict:
        if one[0] + two[0] >= 18 and one[1] + two[1] >= 18:    
            if one < two:
                count += ab_dict[one] * ab_dict[two]
            else: 
                if one == two:
                    count += ab_dict[one] * (ab_dict[two]-1) // 2

print(count)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

// ############################################################################################

#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define FORE(i, a, n) for (i = (a); i < (int)(n); ++i)
#define Size(n) ((int)(n).size())
#define all(n) (n).begin(), (n).end()

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair

#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>

#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>

#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)

#define mod 1000000007
#define inf 1e18

#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// ############################################################################################

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2) res = (res * base) % mod;
        base = (base * base) % mod;
        exp /= 2;
    }
    return res % mod;
}

void a_k_s() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
}

ll n, w, wt, val;
vector<pll> v;

ll solve(ll n, ll W) {
    ll maxVal = n * 1000;
    ll dp[n + 1][maxVal + 1];

    FOR(i, 0, maxVal + 1) {
        dp[1][i] = inf;
    }
    dp[1][0] = 0;
    dp[1][v[1].ss] = v[1].ff;

    FOR(i, 2, n + 1) {
        FOR(val, 0, maxVal + 1) {
            dp[i][val] = dp[i - 1][val];
            if (v[i].ss <= val) {
                dp[i][val] = min(dp[i][val], dp[i - 1][val - v[i].ss] + v[i].ff);
            }
        }
    }

    ll ans = 0;

    FOR(x, 0, maxVal + 1) {
        if (dp[n][x] <= W) {
            ans = x;
        }
    }

    return ans;
}

int main() {
    a_k_s();

    cin >> n >> w;

    v.resize(n + 1);

    FOR(i, 1, n + 1) {
        cin >> wt >> val;
        v[i] = {wt, val};
    }

    cout << solve(n, w) << endl;

    return 0;
}

Measured memory_bytes: 81736
#include <bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;

const int MAXN = 200000;
int n;
struct node{
  int x, y, id;
  node() {}
  node(int _x, int _y, int _id) {
    x = _x, y = _y, id = _id;
  }
} arr[MAXN+1];
int dsu[MAXN+1];
int sze[MAXN+1];
pii tmp;
stack <int> stk;

int fnd(int a) {
  return a == dsu[a] ? a : dsu[a] = fnd(dsu[a]);
}

void Union(int a, int b) {
  if (fnd(a) == fnd(b)) return;
  sze[fnd(b)] += sze[fnd(a)];
  dsu[fnd(a)] = fnd(b);
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i].x >> arr[i].y, arr[i].id = dsu[i] = i, sze[i] = 1;
  sort(arr+1, arr+1+n, [](const node a, const node b) {
      return a.x < b.x;
      });
  for (int i = 1; i <= n; i++) {
    tmp = pii(arr[i].y, i);
    while (stk.size() && arr[i].y > arr[stk.top()].y) {
      Union(arr[i].id, arr[stk.top()].id);
      tmp = min(tmp, pii(arr[stk.top()].y, stk.top()));
      stk.pop();
    }
    stk.push(tmp.ss);
  }
  while (stk.size()) stk.pop();
  for (int i = n; i >= 1; i--) {
    tmp = pii(arr[i].y, i);
    while (stk.size() && arr[i].y < arr[stk.top()].y) {
      Union(arr[i].id, arr[stk.top()].id);
      tmp = max(tmp, pii(arr[stk.top()].y, stk.top()));
      stk.pop();
    }
    stk.push(tmp.ss);
  }
  for (int i = 1; i <= n; i++)
    cout << sze[fnd(i)] << "\n";
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define INF 1e9
#define st string
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test(x) int t; cin >> t; while(t--) x();

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

vector<int>adj[20005];
map<int, int>ans;
bool vist[20005];
int dist[20005];
int n;

void bfs(int start){
    queue<int>q;;
    q.push(start);
    vist[start] = true;
    dist[start] = 0;
    while(!q.empty()){
        int x = q.front(); q.pop();
        for(auto neigh : adj[x]){
            if(!vist[neigh]){
                vist[neigh] = true;
                dist[neigh] = dist[x] + 1;
                q.push(neigh);
            }
        }
    }
    for(int i = 0; i < n; i++){
        ans[dist[i]]++;
    }
    for(int i = 0; i < n; i++) {
        dist[i] = 0;
        vist[i] = false;
    }
}

void solve(){
    int x, y; cin >> n >> x >> y;
    for(int i = 1; i < n; i++){
        adj[i - 1].pb(i);
        adj[i].pb(i - 1);
    }
    adj[x-1].pb(y-1);
    adj[y-1].pb(x-1);

    for(int i = 0; i < n; i++) {
        bfs(i);
    }
    for(int i = 1; i < n; i++){
        cout << ans[i] / 2 << endl;
    }
}

int main(){
    fastio
    solve();
    return 0;
}



Measured memory_bytes: 4284
#include<algorithm>
#include<stdio.h>
#define min(i, j) (i) < (j) ? (i) : (j)
int main() {
    int n, k, h[100010], i, minn = 1000000010;
    scanf("%d%d", &n, &k);
    for(i = 1; i <= n; ++i) scanf("%d", &h[i]);
    std::sort(h + 1, h + 1 + n);
    for(i = 1; i <= n - k + 1; ++i) minn = min(minn, h[i + k - 1] - h[i]);
    printf("%d\n", minn);
    return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)

	r := nextInt()
	fmt.Println(r * r)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		log.Fatal(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var inf = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

using namespace std;

#define LIMIT 100
typedef pair<int64_t, int64_t> ii;

//  ***** MAIN *****
int main(){

  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  int a;
  cin >> n >> a;
  n %= 500;
  if (n > a){
    std::cout << "No" << std::endl;
  }
  else{
    std::cout << "Yes" << std::endl;
  }

  return 0;
}



Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, D): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let X: Vec<Vec<i64>> = {
        let mut X = vec![];
        for _ in 0..N {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            X.push(
                line.split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect()
            );
        }
        X
    };

    let sq = (0..1000)
        .map(|i| i * i)
        .collect::<std::collections::HashSet<i64>>();
    let ans = (0..(N - 1))
        .map(|i| ((i + 1)..N)
            .map(|j| (0..D)
                .map(|k| (X[i][k] - X[j][k]).pow(2))
                .sum::<i64>())
            .filter(|&d| sq.contains(&d))
            .count())
        .sum::<usize>();

    println!("{}", ans);
}


Measured memory_bytes: 4352
while True:
    table = input().split()
    
    a = int(table[0])
    op = table[1]
    b = int(table[2])
    
    if op == "?":
        break
    elif op == "+":
        print("%d" %(a+b))
    elif op == "-":
        print("%d" %(a-b))
    elif op == "*":
        print("%d" %(a*b))
    elif op == "/":
        print("%d" %(a/b))


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

const int maxn= 40000, mod = 1e9 + 7;
const double eps = 1e-6;
long long s[maxn], b[maxn], presums[maxn], presumb[maxn];

int main() {
  #ifdef LOCAL
  //freopen("input.txt", "r", stdin);
  #endif
  ios::sync_with_stdio(false);
  int n, k, tot;
  cin >> n >> k;
  for (tot = 1; tot * tot <= n; ++tot); --tot;
  for (int i = 1; i <= tot; ++i) {
    s[i] = 1;
    b[i] = n / i - max(n / (i + 1), (int)(sqrt(n) + eps));
  }
  for (int i = 1; i <= tot; ++i) {
    presums[i] = presums[i - 1] + s[i];
    presums[i] %= mod;
    presumb[i] = presumb[i - 1] + b[i];
    presumb[i] %= mod;
  }

  for (int i = 2; i <= k; ++i) {
    for (int j = 1; j <= tot; ++j) {
      s[j] = presums[tot] + presumb[tot] - presumb[j - 1];
      s[j] %= mod;
      if (s[j] < 0) s[j] += mod;

      b[j] = (n / j - max(n / (j + 1), (int)(sqrt(n) + eps))) * presums[j];
      b[j] %= mod;
    }
    for (int j = 1; j <= tot; ++j) {
      presums[j] = presums[j - 1] + s[j];
      presums[j] %= mod;
      presumb[j] = presumb[j - 1] + b[j];
      presumb[j] %= mod;
    }
  }
  cout << (presumb[tot] + presums[tot]) % mod << endl;
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
int main(){

  long long int a,b,c,d;
  ld t;
  cin>>a>>b>>c>>d>>t;

  if(a>c){
    ll e=a-c;
    ll f=b-d;
    ld ans=(ld)e/(ld)f;
    if(ans>=0&&ans<=t){
        cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }else{
    ll e=a-c;
    ll f=d-b;
     ld ans=(ld)e/(ld)f;
    if(ans>=0&&ans<=t){
        cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }

  }
}


Measured memory_bytes: 3728
#include<cstdio>
#include<cstring>
char c[100005],s[100005];
int main(){
	bool flag=0;
	scanf("%s",c+1);
	strcpy(s,c+1);
	int n=strlen(c+1);
	for(int i=1;i*2<=n;++i){
		if(c[i]!=c[strlen(c)-i+1]){flag=1;break;}
	}
	if(flag==0){printf("Yes\n");return 0;}
	flag=0;
	for(int i=1;i<=n;++i){
		if(c[i]=='b')c[i]='d';
		else if(c[i]=='d')c[i]='b';
		else if(c[i]=='p')c[i]='q';
		else c[i]='p';
	}
	if(strcmp(c+1,s)==0){printf("Yes\n");return 0;}
	for(int i=1;i*2<=n;++i){
		char w=c[i];
		c[i]=c[n-i+1];
		c[n-i+1]=w;
	}
	if(strcmp(c+1,s)==0){printf("Yes\n");}
	else printf("No\n");
    return 0;
}


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

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

    int output = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i]) {
            output++;
        }
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3856
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;

const LL INF=1<<30;
const LL MOD=1000000007;






int main(){
    LL n;
    cin>>n;
    for(LL i=n;i>=1;--i){
        LL j=sqrt(i);
        if(j*j==i){
            cout<<i<<endl;
            return 0;
        }
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]||s[0]==s[2]&&s[1]==s[3]&&s[1]!=s[2]||s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[2]) cout<<"Yes"; 
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
import bisect

a = int(input())
b = list(map(int, input().split()))
b.sort()
c = list(map(int, input().split()))
d = list(map(int, input().split()))
d.sort()
e = 0
for i in c:
    e += bisect.bisect_left(b, i) * (a - bisect.bisect_right(d, i))
print(e)


Measured memory_bytes: 23360
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
  int n;
  string s; cin>>n>>s;
  string tmp="No";
  int k=n/2;
  if(n%2==0 && s.substr(0,k)==s.substr(k,n)) tmp="Yes";
  //cout<<s.substr(0,k)<<endl;
  //cout<<s.substr(k,n)<<endl;
  cout<<tmp<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

char buf[100005];
int amt[100005];

int main() {
  int k;
  scanf("%s%d", buf, &k);
  int n = strlen(buf);
  for(int i = 0; i < n; i++) {
    amt[i] = buf[i] - 'a';
  }
  for(int i = 0; i < n; i++) {
    int need = (26-amt[i])%26;
    if(need <= k) {
      k -= need;
      amt[i] = 0;
    }
  }
  amt[n-1] += k;
  amt[n-1] %= 26;
  for(int i = 0; i < n; i++) {
    printf("%c", 'a' + amt[i]);
  }
  printf("\n");
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  char A,B;
  A=S.at(0);
  for(int i=1;i<S.size();i++){
    if(S.at(i)!=A){
      B=S.at(i);
      break;
      }
    }
  int countA=1,countB=0;
  bool flag=true;
  for(int i=1;i<S.size();i++){
    if(S.at(i)==A)
      countA++;
    else if(S.at(i)==B)
      countB++;
    else{
      flag=false;
      break;
      }
    }
  //cout<<countA<<endl<<countB<<endl;
  if(flag==true&&countA==2&&countB==2)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  int n;
  cin>>n;
  vector<long> vec(n);
  rep(i,n) cin>>vec[i];
  sort(all(vec));

  int ans=0;
  long acc=0;
  rep(i,n-1){
    if(2 * (acc + vec[i]) < vec[i+1]){
      ans = 0;
    } else {
      ans++;
    }
    acc += vec[i];
  }
  if(2*acc < vec[n-1]) ans=1;
  else ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
def calc_sum_energy(p, x_list) -> int:
    return sum([(p - x) ** 2 for x in x_list])


def main(n, x_list):
    print(min([calc_sum_energy(p, x_list) for p in range(1, 101)]))


if __name__ == "__main__":
    n = int(input())
    x_list = [int(i) for i in input().split()]

    main(n, x_list)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    Scanner in = new Scanner(System.in);

    long f(long n, long[] costs, long d, Map<Long, Long> memo) {
        if (n == 0) return 0;
        if (n == 1) return d;
        if (memo.containsKey(n)) return memo.get(n);

        int[] div = new int[]{2,3,5};
        long ret = Long.MAX_VALUE;
        if (ret / d >= n) ret = n * d;
        for (int i=0;i<3;i++) {
            int di = div[i];
            long c = costs[i];
            if (n % di == 0) {
                ret = Math.min(ret, f(n/di, costs, d, memo) + c);
            } else {
                ret = Math.min(ret, c + f(n / di, costs, d, memo) + d * (n % di));
                ret = Math.min(ret, c + f(n / di + 1, costs, d, memo) + d * (di - n % di));
            }
        }

        memo.put(n, ret);
        return ret;
    }

    long solve() {
        long n = in.nextLong(), a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        return f(n, new long[]{a, b, c}, d, new HashMap<>());
    }

    void run() {
        int T = in.nextInt();
        while (T-- > 0) {
            System.out.println(solve());
        }
    }

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


Measured memory_bytes: 63364
#include<cstdio>

using namespace std;

int b[100010];
bool r[100010];

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++){
		b[i] = 1;
	}
	r[0] = true;
	for(int i = 0; i < m; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		x--; y--;
		if(r[x]){
			r[y] = true;
		}
		b[x]--; b[y]++;
		if(b[x] == 0){
			r[x] = false;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(r[i]){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

public class Main {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line = br.readLine();
            String[] strArray = new String[1];
            double[] doubleArray = new double[1];
            DecimalFormat df = new DecimalFormat("0.000000");
            
            strArray = line.split("\\s");
            
            for (int i = 0; i < strArray.length; i++) {
				doubleArray[i] = Double.parseDouble(strArray[i]);
			} 
            System.out.println(df.format(doubleArray[0]*doubleArray[0]*Math.PI)+" "+df.format(doubleArray[0]*2*Math.PI));
            br.close();
        } catch (IOException e) {
            System.err.println(e);
        }
    }
}

Measured memory_bytes: 17124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
  int res = 1;
  x = x % p;
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  tc = 1;
  //cin>>tc;
  while (tc--)
  {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, g = 0, b = 0, ans = 0;
    for (int i = 0; i < n; i++)
    {
      if (s[i] == 'R')
      {
        r++;
      }
      if (s[i] == 'G')
      {
        g++;
      }
      if (s[i] == 'B')
      {
        b++;
      }
    }
    for (int i = 0; i < n; i++)
    {
      if (s[i] == 'R')
      {
        for (int j = 0; j < n; j++)
        {
          if (s[j] == 'G')
          {
            int cc = b;
            if (j < i)
            {
              if ((j - (i - j) >= 0 && s[j - (i - j)] == 'B'))
              {
                cc--;
              }
              if (i + i - j < n && s[i + i - j] == 'B')
                cc--;
              if((i-j)%2==0&&s[j+(i-j)/2]=='B')
                cc--;
              ans += cc;
            }
            else
            {
              if ((j + j - i < n && s[j + j - i] == 'B') )
                {
                  cc--;
                }
              if ((i - (j - i) >= 0 && s[i - (j - i)] == 'B'))
              {
                cc--;
              }
              if((j-i)%2==0&&s[i+(j-i)/2]=='B'){
                cc--;
              }

              ans += cc;
            }
          }
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
#define min 105
long long a[min];
long long gcd(long long a,long long b)
{
	return a%b==0?b:gcd(b,a%b);
}
int main()
{
	int n,i,j;
	long long max=0;
	long long sum,flag;
	scanf("%d",&n);
	scanf("%lld",&a[0]);
	sum=flag=a[0];
	for(i=1;i<n;i++)
	{
		scanf("%lld",&a[i]);
		flag=gcd(sum,a[i]);
		sum=sum/flag*a[i];
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <algorithm>
#include<math.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

#define pb(a) push_back(a)
#define mp(a , b) make_pair((a) , (b))
#define fore(i,a,b) for(int  i = (int)(a) ; i < (int)(b) ; ++i)
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){
	FIN;
	int n,d,cnt=0 ;
	cin>>n>>d;
	int x[n][d];
	for(int i=0;i<n;i++){
		fore(j,0,d){
			cin>>x[i][j];
		}
	}

	//double dist = 0;
	fore(i,0,n){
		fore(j,i,n){
			if(j == i)
				continue;
			else{
				double dist = 0;
				fore(k,0,d){
					dist +=  pow((x[i][k] - x[j][k]),2);
				}
				float d = sqrt(dist);
				int c = sqrt(dist);
				//if(floor(sqrt(dist)) == sqrt(dist) )
				if(c == d)
					cnt++;
			}
		}
	}

	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String dishNumStr = sc.nextLine();
		String eatOrderStr = sc.nextLine();
		String[] eatOrderArray = eatOrderStr.split(" ");
		String firstSatisfactionStr = sc.nextLine();
		String[] firstSatisfactionArray = firstSatisfactionStr.split(" ");
		String secondSatisfactionStr = sc.nextLine();
		String[] secondSatisfactionArray = secondSatisfactionStr.split(" ");
		
		int result = 0;
		for(int i = 0; i < Integer.parseInt(dishNumStr); i++) {
			int eatNum = Integer.parseInt(eatOrderArray[i]);
			result += Integer.parseInt(firstSatisfactionArray[eatNum-1]);
			
			if(i != Integer.parseInt(dishNumStr)-1) {
				int eatNumNext = Integer.parseInt(eatOrderArray[i+1]);
				if(eatNum+1 == eatNumNext) {
					result += Integer.parseInt(secondSatisfactionArray[eatNum-1]);
				}	
			}
		}
		
		System.out.println(result);
	}
}


Measured memory_bytes: 23252
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn primes(mut n: usize) -> std::collections::HashMap<usize, usize> {
    let mut ret = std::collections::HashMap::new();
    let n0 = n;
    let mut cur = 2;
    while cur * cur <= n0 {
        if n % cur != 0 {
            cur += 1;
            continue;
        }
        let mut count = 0;
        while n % cur == 0 {
            n /= cur;
            count += 1;
        }
        ret.insert(cur, count);
        cur += 1;
    }
    if n > 1 {
        ret.insert(n, 1);
    }
    ret
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    let ps = primes(n);
    let mut ret = 0;
    for (p, m) in ps {
        let mut k = 1;
        while m >= (k + 1) * (k + 2) / 2 {
            k += 1;
        }
        ret += k;
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll A, B, C, K; cin >> A >> B >> C >> K;
  ll ans = 0;
  ll tmp = K;
  if(A < tmp && tmp > 0) {
    tmp = tmp - A;
    ans += A;
  } else {
    ans += tmp;
    tmp = 0;
  }

  if(B < tmp && tmp > 0) {
    tmp = tmp - B;
  } else {
    tmp = 0;
  }

  if(C < tmp && tmp > 0) {
    tmp = tmp - C;
    ans -= C;
  } else {
    ans -= tmp;
    tmp = 0;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, x;
    cin >> n >> x;
    vi a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n) {
        if (i == 0) {
            ans += max(0, a[i] - x);
            a[i] = min(x, a[i]);
        } else {
            ans += max(0, (a[i-1] + a[i]) - x);
            a[i] = min(a[i], x - a[i-1]);
        }
    }
    cout << ans << endl;
}

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

int main() {
	int N,M,Q;
	cin >> N >> M >> Q;
	vector<vector<int>> data(N + 1, vector<int>(N + 1));
	vector<vector<int>> sum(N + 1, vector<int>(N + 1));
	for (int i = 0;i<M;++i) {
		int L, R;
		cin >> L >> R;
		data[L][R]++;
	}
	for (int i = 0;i<N;++i) {
		for (int j = 0;j<N;++j) {
			sum[i + 1][j + 1] = sum[i + 1][j]+sum[i][j+1]-sum[i][j]+data[i + 1][j + 1];
		}
	}
	for (int i = 0;i < Q;++i) {
		int p, q;
		cin >> p >> q;
		cout << sum[q][q]+sum[p -1 ][p - 1]-sum[p - 1][q]-sum[q][p - 1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5572
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const int MAX_L = 16016;
const int MAX_SZ = 4000;

int main() {
    string S;
    int x, y;
    cin >> S >> x >> y;
    vector<int> M;
    int cnt = 0;
    S = S + 'T';
    for (int i = 0; i < (int)S.length(); i++) {
        if (S[i] == 'F') cnt++;
        else { M.emplace_back(cnt); cnt = 0; }
    }
    
    vector<int> X, Y;
    for (int i = 1; i < (int)M.size(); i++) {
        if (i&1) Y.emplace_back(M[i]);
        else X.emplace_back(M[i]);
    }
    
    int lx = X.size(), ly = Y.size();
    const int geta = 8008;
    
    bool dp[MAX_SZ][MAX_L] = {0};
    dp[0][M[0]+geta] = true;
    for (int i = 0; i < lx; i++) {
        for (int j = 0; j < MAX_L; j++) if (dp[i][j]) {
            if (j + X[i] < MAX_L) dp[i+1][j+X[i]] = true;
            if (0 <= j - X[i]) dp[i+1][j-X[i]] = true;
        }
    }
    
    bool dpp[MAX_SZ][MAX_L] = {0};
    dpp[0][geta] = true;
    for (int i = 0; i < ly; i++) {
        for (int j = 0; j < MAX_L; j++) if (dpp[i][j]) {
            if (j + Y[i] < MAX_L) dpp[i+1][j+Y[i]] = true;
            if (0 <= j - Y[i]) dpp[i+1][j-Y[i]] = true;
        }
    }
    
    cout << ((dp[lx][geta+x] && dpp[ly][geta+y]) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 125568
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;

int main(void) {
	int x; cin >> x;
	if (x % 2 == 0)cout << 0.5 << endl;
	else {
		int a = x / 2 + 1;
		cout << (double)a / x << endl;
		
	}



	return 0;
}

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

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

typedef pair<int, int> P;

#define MAX_N 100003
bool is_prime[MAX_N + 1];

void sieve(int n)
{
    int p = 0;
    for (int i = 0; i <= n; i++)
        is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            for (int j = 2 * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
}

int main()
{
    int X;
    cin >> X;
    sieve(MAX_N);
    for (int i = X; i <= MAX_N; i++) {
        if (is_prime[i]) {
            cout << i << endl;
            return 0;
        }
    }
}

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

using namespace std;

//typedef pair<int,int> P;
typedef long long ll; 

#define int ll

main(){
	int A,B,M;
	cin >> A >> B >> M;
	vector<int> a(A),b(B);
	for(int i=0;i<A;i++) cin >> a[i];
	for(int i=0;i<B;i++) cin >> b[i];

	int ans = 1e18;
	for(int i=0;i<M;i++){
		int x,y,c;
		cin >> x >> y >> c;
		ans = min(ans,a[x-1]+b[y-1]-c);
	}

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

	ans = min(ans, a[0]+b[0]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4756
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
//const int MAX=;
const int MOD=1e9+7;

int main(){
	int N;
	cin>>N;
	string S;
	cin>>S;
	
	int a=0;
	int mn=0;
	rep(i,N){
		if(S[i]=='(')a++;
		else a--;
		mn=min(a,mn);
	}
	if(mn==0){
		rep(i,N)cout<<S[i];
		rep(i,a)cout<<")";
	}
	else {
		int x=(-1)*mn;
		a+=x;
		rep(i,x)cout<<"(";
		rep(i,N)cout<<S[i];
		rep(i,a)cout<<")";
	}
}

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


def trial_division(n):
    factor = []
    for num in range(2, int(n**0.5)+1):
        while n % num == 0:
            n //= num
            factor.append(num)
    if not factor or n != 1:
        factor.append(n)
    return factor


d = {}
for i in range(2, N+1):
    divisors = trial_division(i)
    for divisor in divisors:
        d[divisor] = d.get(divisor, 0) + 1

ans = 1
for v in d.values():
    ans = ans * (v + 1) % (10**9+7)
print(ans)


Measured memory_bytes: 3188
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------

		int x = Integer.parseInt(sc.next());

		int ret = 0;

		ret += (x / 500) * 1000;
		x %= 500;
		ret += (x / 5) * 5;

		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
}

Measured memory_bytes: 27040
#include <bits/stdc++.h>
using namespace std;
int main()
{
      int a[3], ans;
      for(int i = 0; i<3; i++){
        cin >> a[i];
      }
      sort(a, a+3, greater<int>());

      ans = a[0]*10 + a[1] + a[2];
      cout << ans << endl;
}


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

int main(){
  int n,p[55]={};
  int  flag=0;

  cin>>n;

  for(int i=1;i<=n;i++){
    cin>>p[i];
  }


  for(int i=1;i<=n;i++){
    if(p[i]!=i) {
      flag++;
    }   
  }

  if(flag==0 || flag==2) cout<<"YES"<<endl;
  else cout<< "NO"<<endl;
  return 0;
}
      


Measured memory_bytes: 256