akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
 
struct Node{
  int key;
  struct Node *parent;
  struct Node *left;
  struct Node *right;
};
 
#define NIL NULL
typedef struct Node* NodePointer;
NodePointer root;
 
void inOrder(NodePointer);
void preOrder(NodePointer);
void print(void);
void insert(int);
NodePointer makeNode(int);
int find(int);
NodePointer findNode(int);
NodePointer treeSuccessor(NodePointer);
NodePointer treeMinimum(NodePointer);
NodePointer treeMaximum(NodePointer);
void deleteNode(int);
 
int main(){
  int Q,i,x;
  char order[7];
  scanf("%d",&Q);
  for(i = 0 ; i < Q ; i++){
    scanf("%s",order);
    if(order[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }else if(order[0] == 'f'){
      scanf("%d",&x);
      puts(find(x) ? "yes" : "no");
    }else if(order[0] == 'd'){
      scanf("%d",&x);
      deleteNode(x);
    }else{
      print();
    }
  }
  return 0;
}
 
void inOrder(NodePointer x){
  if(x == NIL){ return; }
  inOrder(x->left);
  printf(" %d",x->key);
  inOrder(x->right);
}
 
void preOrder(NodePointer x){
  if(x == NIL){ return; }
  printf(" %d",x->key);
  preOrder(x->left);
  preOrder(x->right);
}
 
void print(){
  inOrder(root); printf("\n");
  preOrder(root); printf("\n");
}
 
void insert(int key){
  NodePointer x = root,y = NIL;
  NodePointer z = makeNode(key);
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}
 
NodePointer makeNode(int key){
  NodePointer newNode = malloc(sizeof(struct Node));
  newNode->key = key;
  newNode->left = newNode->right = NIL;
  return newNode;
}
 
int find(int key){
  NodePointer x = root;
  while(x != NIL){
    if(key < x->key){
      x = x->left;
    }else if(key > x->key){
      x = x->right;
    }else{
      return 1;
    }
  }
  return 0;
}
 
NodePointer findNode(int key){
 NodePointer x = root;
  while(x != NIL){
    if(key < x->key){
      x = x->left;
    }else if(key > x->key){
      x = x->right;
    }else{
      return x;
    }
  }
  return NIL;
}
 
NodePointer treeSuccessor(NodePointer x){
  NodePointer y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
 
NodePointer treeMinimum(NodePointer x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}
 
NodePointer treeMaximum(NodePointer x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}
 
void deleteNode(int key){
  NodePointer x,y;
  NodePointer z = findNode(key);
  if(z == NIL){ return; }
  if(z->left == NIL || z->right == NIL){
    y = z;
  }else{
    y = treeSuccessor(z);
  }
  if(y->left != NIL){
    x = y->left;
  }else{
    x = y->right;
  }
  if(x != NIL){
    x->parent = y->parent;
  }
  if(y->parent == NIL){
    root = x;
  }else if(y == y->parent->left){
    y->parent->left = x;
  }else{
    y->parent->right = x;
  }
  if(y != z){
    z->key = y->key;
  }
  free(y);
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
#define ld long double
#define int long long
#define fi first
#define se second
using namespace std;
const int N = 20 + 12;
const int inf = 2e9;


string s[N];
int t[N];

void run() {
    int i, j, k, n, need, cnt;
    vector <int> v;
    cin >> n;
    for (i = 0; i < n; ++i) {
        cin>> j;
        v.push_back(j);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    multiset <int> s;
    s.insert(-(v.back()));
    for (int i = (int)(v.size()) - 2; i >= 0; --i) {
        auto p = *s.begin();
        s.erase(s.begin());
        s.insert(-v[i]);
        s.insert(-v[i]);
        ans -= p;

    }
    cout << ans;
}

signed main() {
    #ifdef local
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test;
    run();
}


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

int main() {
   int n;
   cin >> n;
   int S[n];
   for (int i=0; i<n; i++) {
      cin >> S[i];
   }
   int q;
   cin >> q;
   int T[q];
   for (int i=0; i<q; i++) {
      cin >> T[i];
   }
   sort(S,S+n);
   sort(T,T+q);
   int low=0,high=n-1;
   int count=0;
   for (int i=0; i<q; i++) {
      high=n-1;
      while (high-low>1) {
         if (S[(low+high)/2]>T[i]) high=(low+high)/2;
         else low=(low+high)/2;
      }
      if (T[i]==S[low] || T[i]==S[high]) count++;
   }
   cout << count << endl;
}


Measured memory_bytes: 3736
let input f = stdin.ReadLine() |> f
let inputs f = stdin.ReadLine().Split() |> Array.map f

let md = 1000000007L

let [|N; K|] = inputs int

let S l r = r * (r + 1L) / 2L - l * (l - 1L) / 2L


[for i in K..N+1 ->
    let l = S 0L (int64 (i - 1)) in
    let r = S (int64 (N-i+1)) (int64 N) in
    r - l + 1L]
|> List.sum
|> (fun x -> x % md)
|> printfn "%d"


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

int main(){
    int n;
    cin >> n;
    vector<long long>a(n+1);
    vector<long long>b(n);
    for(int i = 0;i < n+1;i++){
        cin >> a[i];
    }
    for(int i = 0;i < n;i++){
        cin >> b[i];
    }
    long long ans = 0;
    for(int i = 0;i < n;i++){
        int pre1 = a[i];
        int pre2 = a[i+1];
        //cout << pre1 << " " << pre2 << endl;
        //a[i] = ((a[i] > b[i]) ? (a[i]-b[i]) : 0);
        //b[i] = ((a[i] > b[i]) ? 0 : (b[i]-a[i]));
        //a[i+1] = (a[i+1] > b[i]) ? (a[i+1] - b[i]) : 0;
        
        if(a[i] > b[i]){
            a[i] = a[i]-b[i];
            b[i] = 0;
            //cout << "1が実行されました！" << endl;
        }else{
            b[i] = b[i]-a[i];
            a[i] = 0;
            //cout << b[i] << endl; 
            //cout << "2が実行されました！" << endl;
        }
        if(a[i+1] > b[i]){
            a[i+1] = a[i+1] - b[i];
            //cout << "3が実行されました！" << endl;
        }else{
            a[i+1] = 0;
            //cout << "4が実行されました！" << endl;
        }
        
        //cout << a[i] << " " << a[i+1] << endl;
      
        ans += (pre1 - a[i]) + (pre2 - a[i+1]);
    }
    cout << ans << endl;
}

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

int main() {
	int a,b,c,d;
  	cin >> a >> b >> c >> d;
  	if((a+b)>(c+d)){
    cout << "Left" << endl;
    }else if((a+b)<(c+d)){
    cout << "Right" << endl;
    }else{
    cout << "Balanced" << endl;
    }
}

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

int main(){
  int a,b;
    cin>>a>>b;
  string s;
   cin >> s;
    for(int i=0;i<a+b+1;i++){
      if( (i == a)&&(s[a] != '-')){
        
          cout << "No" << endl;
          return 0;
      }
       else if((i !=a) && (s[i] < '0' || s[i] >'9')){
          cout << "No" << endl;
          return 0;
        }
    
    }
    
cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <math.h>
int main()
{
    int A,B,S;
    if (1<=A&&A<=100&&1<=B&&B<=100);
    {
        scanf("%d %d",&A,&B);
        S=A+B;
        if (S%3==0||A%3==0||B%3==0) printf("Possible");
        else printf("Impossible");
    }
    return 0;
}


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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////



int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int arr[5];
	FOR(i,3) cin >> arr[i];
	sort(arr,arr+3);
	if(arr[0] + arr[1] == arr[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize, // 4*10^3
      s: chars,
    }
    let mut cnt = vec![0usize; 3];
    for i in 0..n {
        match s[i] {
            'R' => {
                cnt[0] += 1;
            },
            'G' => {
                cnt[1] += 1;
            },
            'B' => {
                cnt[2] += 1;
            },
            _ => panic!()
        }
    }
    let mut ans = cnt[0] * cnt[1] * cnt[2];

    for k in 0..n {
        let c1 = s[k];
        for d in 1..n {
            if k >= 2*d {
                let c2 = s[k-d];
                let c3 = s[k-2*d];
                if c1 != c2 && c2 != c3 && c1 != c3 {
                    ans -= 1;
                }
            }
        }
    }
    puts!("{}\n", ans);
}


Measured memory_bytes: 2200
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int no(){
  cout << "No" << endl;
  return 0;
}

int main(){
  int h, w, c, d; cin >> h >> w >> c >> d;
  if( c > w/2 || d > h/2 ) return no();
  string s, t;
  for( int i = 0; i < w-c; ++i ) s += '1';
  for( int i = 0; i < c; ++i ) s += '0';
  for( int i = 0; i < w-c; ++i ) t += '0';
  for( int i = 0; i < c; ++i ) t += '1';
  for( int i = 0; i < h-d; ++i ) cout << s << endl;
  for( int i = 0; i < d; ++i ) cout << t << endl;
}

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


ll sum(int n,ll arr[],ll v[]){
	if(n==1)return 0;
	if(n<1)return 1000000000;
	if(v[n]<0)
	 v[n]=min(sum(n-1,arr,v)+abs(arr[n]-arr[n-1]),sum(n-2,arr,v)+abs(arr[n]-arr[n-2]));
	return v[n];
}

int main() {

int n;
cin>>n;
ll arr[n+1];
ll v[n+1]={-1};
memset(v,-1,sizeof(v[0])*(n+1));
for (int i = 1; i <=n; ++i)
{
	cin>>arr[i];
}
cout<<sum(n,arr,v);

}


Measured memory_bytes: 9048
#include <iostream>
#include <string>
#include <algorithm>

using ll = long long;

int N;
int cnt;

void dfs(ll n)
{
    if (n > N)return;
    int a = 0, b = 0, c = 0;
    ll num = n;
    while (num > 0)
    {
        int d = num % 10;
        num /= 10;
        if (d == 3)a++;
        else if (d == 5)b++;
        else if (d == 7)c++;
    }
    if (a > 0 && b > 0 && c > 0)
    {
        cnt++;
    }

    dfs(n * 10 + 3);
    dfs(n * 10 + 5);
    dfs(n * 10 + 7);
}

int main()
{
    std::cin >> N;
    cnt = 0;
    dfs(0);
    std::cout << cnt << std::endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
const int MAX_N = 100;

int A[MAX_N+1][MAX_N+1];
int D[MAX_N+1];
int N;

void solve() {
  int d;
  queue<int> Q;

  Q.push(1);
  D[1] = d = 0;

  while (!Q.empty()) {
    int c = Q.front(); Q.pop();

    for (int i = 1; i <= N; i++) {
      if (A[c][i] == 1 && D[i] == -1) {
        D[i] = D[c]+1;
        Q.push(i);
      }
    }
  }
}

int main() {
  cin >> N;

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

  for (int i = 0; i < N; i++) {
    int u, k; cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int t; cin >> t;
      A[u][t] = 1;
    }
  }

  solve();

  for (int i = 1; i <= N; i++) {
    cout << i << ' ' << D[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1240
#include <stdio.h>

int main(void)
{
  int N, M;
  scanf("%d%d", &N, &M);
  int d[100001] = {0};
  int t = 0;
  int f = 0;
  for(int i = 0; i < M; i++){
    int p;
    char S[3];
    scanf("%d %s", &p, S);

    if(S[0] == 'A'){
      if(d[p] != -1){
          f += d[p];
          d[p] = -1;
          t++;
      }
    } else if(d[p] != -1){
      d[p]++;
    }
  }
  printf("%d %d\n", t, f);
  return 0;
}


Measured memory_bytes: 512
s = input()
count = 0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] =="R" or s[i] =="U" or s[i] =="D":
      count += 1
  else:
    if s[i] =="L" or s[i] =="U" or s[i] =="D":
      count += 1

if len(s) == count:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 f(i64 x) {
  i64 y = 0;
  for (; x > 0; x /= 10) ++y;
  return y;
}

int main() {
  i64 n;
  cin >> n;
  i64 ans = 0;
  for (i64 i = 1; i <= n; ++i) {
    if (f(i) % 2 == 1) ++ans;
  }
  cout << ans << endl;
  return 0;
}



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

public class Sus
{
    public List<int> p { get; set; }
    public List<int> c { get; set; }
    public int sno { get; set; }
    public int display { get; set; }
}
public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<int, Sus>();
        var m = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < m; i++)
            d[i + 1] = new Sus { sno = i + 1, p = new List<int>(), c = new List<int>() };
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            if (!d[y].c.Contains(x)) d[y].c.Add(x);
            if (!d[x].p.Contains(y)) d[x].p.Add(y);
        }
        getList(d);
    }
    public static void getList(Dictionary<int, Sus> d)
    {
        while (true)
        {
            var a = d.Where(z => z.Value.c.Count() == 0).Where(z => z.Value.display == 0).Select(z => z.Value);
            if (a.Count() == 0) break;
            foreach (var s in a)
            {
                Console.WriteLine(s.sno);
                s.display = 1;
                removeSus(d, s);
            }
        }
    }
    public static void removeSus(Dictionary<int, Sus> d, Sus s)
    {
        foreach (var x in s.p)
            d[x].c.Remove(s.sno);
    }
}

Measured memory_bytes: 10088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

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

    ll t1 = a * c, t2 = a * d, t3 = b * c, t4 = b * d;
    cout << max(max(t1, t2), max(t3, t4)) << endl;
}

Measured memory_bytes: 3648
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


# 素数pと正の整数eを用いて、z=P**eと表せる
# N%z==0
# z=まだ選んでない素数だけ選ぶ
# N = N/zに置き換える


# n = 24
# 24を素因数分解する
# z=2, 2*1
# n = 24/2

# n = 12
# z=2, 3*1
# n = 24/2


N = int(input())
#cnt = 0
z = []

def solve(N, cnt):
  #print("N:", N)
  f = factorization(N)
  #print(f)

  
  # 素因数分解の要素数分ループ
  for i in range(len(f)):
    # Pが素数かチェック
    p = f[i][0]
    #print("p:", f[i][0])
    if is_prime(p):
      # 指数の数だけループ
      for e in range(1, f[i][1]+1):
        # 未採用のzを見つける. 割り切れる数を見つける
        if (p**e in z) == False and N % (p**e) ==0:
          # 使用済みリストに追加
          z.append(p**e)
          #print("z:", p**e, "p**e:", p,e)
          cnt +=1
          #print("cnt", cnt)
          cnt = solve(N//p**e, cnt)
          return cnt
  return cnt


cnt = solve(N, 0)
print(cnt)

  


Measured memory_bytes: 64104
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = sum(A) - len(A)
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


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

int p[100005];
int r[100005];
int n;
long long m;
int q;

vector<pair<int,int> > edges;

int root(int a){
    return p[a]==a?a:(p[a]=root(p[a]));
}

void un(int a, int b){
    a = root(a);
    b = root(b);
    if (r[a]<r[b]){
        p[a] = b;
    }
    else if (r[b]<r[a]){
        p[b] = a;
    }
    else {
        p[a] = b;
        r[b]++;
    }
}


 main(){
    scanf("%lld%lld%lld",&n,&m,&q);
    for (int x = 0; x<n; x++){
        p[x] = x;
    }
    int components = n;
    for (int x = 0; x<q; x++){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        if (c==0){
            if (root(a)!=root(b)){
                un(a,b);
                components--;
            }

        }
        else{
            edges.push_back({a,b});
        }
    }
    for (auto x : edges){
        if (root(x.first)==root(x.second)){
            printf("No");
            return 0;
        }
    }
    int mn = n-1;
    if (!edges.empty()) mn = n;

    long long mx = components*(components-1)/2 + n-components;

    if (m<mn || m>mx){
        printf("No");
    }
    else{
        printf("Yes");
    }


}


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec.at(i);
    }
    vector<int> vect(n);
    for(int i=0;i<n;i++){
        cin>>vect.at(i);
    }
    vector<int> vectl(n-1);
    for(int i=0;i<n-1;i++){
        cin>>vectl.at(i);
    }
    int Sum=0;
    for(int i=0;i<n;i++){
        Sum+=vect.at(i);
    }
    for(int i=0;i<n-1;i++){
        if(vec.at(i)==vec.at(i+1)-1){
            Sum+=vectl.at(vec.at(i)-1);
        }
    }
    cout<<Sum<<endl;
}

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

using namespace std;

int search(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while (A[i] != key) i++;
    return i != n;
}

int main() {
    int i, n, A[10000+1], q, key , sum = 0;

    scanf("%d", &n);
    for(i=0;i<n;i++)scanf("%d", &A[i]);

    scanf("%d", &q);
    for(i=0;i<q;i++){
        scanf("%d", &key);
        if(search(A, n, key))sum++;
    }
    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 3252
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	int h, w;
	cin >> h >> w;
	while(h--)
	{
		string row;
		cin >> row;
		cout << row << '\n' << row << '\n';
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



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

  int left = 0, right = 0;
  rep(i, m) {
    int a;
    cin >> a;
    if(a < x) {
      left++;
    }
    if(a > x) {
      right++;
    }
  }

  cout << min(left, right) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int i,x[10000],y[10000],a[10000],b[10000];
  for(i=1;i<=10000;i++){
    scanf("%d %d",&x[i],&y[i]);
    if(x[i]==0&&y[i]==0){
    break;
  }
  if(x[i]<=y[i]){
    a[i]=x[i];
    b[i]=y[i];
  }
  else{
    a[i]=y[i];
    b[i]=x[i];
  }
  }
  for(i=1;i<=10000;i++){
    if(x[i]==0&&y[i]==0){
      break;
    }
    printf("%d %d\n",a[i],b[i]);
  }
  return 0;
}



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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
    ll n, k;
    cin>>n>>k;

    ll ans=min(n%k, k-n%k);

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


Measured memory_bytes: 3600
s = [i for i in input()]
result=[0]*len(s)
R=0
L=0
# print(s,len(s))
# print(s[4:0:-1])
for i in range(len(s)):
	if s[i]=="R":
		# index =s[i:].index("L")
		# # sa = i-index
		# if index%2==1:
		# 	result[i+index-1]+=1
		# else:
		# 	result[i+index]+=1
		R=i
	else:
		# print(s[i::-1])
		# index =s[i::-1].index("R")
		if (i-R)%2==1:
			result[R+1]+=1
		else:
			result[R]+=1
for i in range(len(s)-1,-1,-1):
	if s[i]=="R":
		if (L-i)%2==1:
			result[L-1]+=1
		else:
			result[L]+=1

	else:
		L=i
print(" ".join(map(str,result)))
		

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

#define fast ios_base:: sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
int main(){
	fast;
	int n;	cin >> n;
	int a[n+1],p[n+1];
	p[0] = 0;
	
	for(int i=1 ; i<=n ; i++){
		cin >> a[i] ;
		p[i] = p[i-1] + a[i];
	}
	
	int ans = INT_MAX,i;
	for( i=1 ; i<n ; i++){
		ans = min(ans , abs(p[n]- 2*p[i]));
	}
	cout << ans;
}






Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int a[M];
    long long anss[N+1];
    for(int i = 0; i < N+1; i++){
        anss[i] = 1;
    }
    for(int i = 0; i < M; i++){
        cin >> a[i];
        anss[a[i]] = 0;
    }
    anss[0] = 1;
    if(a[0] != 1){
        anss[1] = 1;
    }else{
        anss[1] = 0;
    }
    for(int i = 2; i <= N; i++){
        if(anss[i] != 0){
            if(anss[i-1] == 0 && anss[i-2] == 0){
                cout << "0" << endl;
                return 0;
            }else{
            anss[i] = (anss[i-1] + anss[i-2]) % 1000000007;
            }
        }
    }
    cout << anss[N] << endl;


    return 0;
}

Measured memory_bytes: 1408
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    mod = 10 ** 9 + 7
    print((pow(10, n) % mod - (2 * pow(9, n)) % mod + pow(8, n) % mod) % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10824
#include <iostream>
#include <string.h>
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    if(s[i] != t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
    ll n;
    cin >> n;
    vector<ll> v(n), c(n);
    rep(i, 0, n) cin >> v[i];
    rep(i, 0, n) cin >> c[i];
    ll ans = 0;
    rep(i, 0, n) ans += max(0LL, v[i]-c[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct QU {
  V<> par, rank, _size;

  QU(int n) { 
    par.resize(n);
    iota(par.begin(), par.end(), 0);
    rank.resize(n);
    _size.assign(n, 1);
  }

  int find(int a) {
    if (par[a] == a) return a;
    return par[a] = find(par[a]);
  }

  bool same(int a, int b) { return find(a) == find(b); }

  int size(int a) { return _size[find(a)]; }

  void unite(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (rank[a] < rank[b]) {
      par[a] = b;
      _size[b] += _size[a];
    } else {
      par[b] = a;
      _size[a] += _size[b];
    }
    if (rank[a] == rank[b]) rank[a]++;
  }
};

struct edge { int from, to, w; edge(int a, int b, int w) : from(a), to(b), w(w) {} };

lint kruskal(V<edge>& g, int n) {
  lint res = 0;
  QU qu(n);
  sort(g.begin(), g.end(), [](edge a, edge b) { return a.w < b.w; });
  for (auto&& e : g) {
    if (!qu.same(e.from, e.to)) {
      qu.unite(e.from, e.to);
      res += e.w;
    }
  }
  return res;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  struct town { int id, x, y; };
  V<town> a(n);
  for (int i = 0; i < n; i++) {
    int x, y; cin >> x >> y;
    a[i] = town{i, x, y};
  }
  V<edge> g;
  sort(a.begin(), a.end(), [](town a, town b) { return a.x < b.x; });
  for (int i = 0; i < n - 1; i++) {
    g.emplace_back(a[i].id, a[i + 1].id, min(abs(a[i].x - a[i + 1].x), abs(a[i].y - a[i + 1].y)));
  }
  sort(a.begin(), a.end(), [](town a, town b) { return a.y < b.y; });
  for (int i = 0; i < n - 1; i++) {
    g.emplace_back(a[i].id, a[i + 1].id, min(abs(a[i].x - a[i + 1].x), abs(a[i].y - a[i + 1].y)));
  }
  cout << kruskal(g, n) << '\n';
}

Measured memory_bytes: 6132
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

	if (a + b == 15) cout << '+' << endl;
	else if (a * b == 15) cout << '*' << endl;
	else cout << 'x' << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int n, q;
    cin >> n;
    set<int> S;
    REP(i, n) {
        int s;
        cin >> s;
        S.insert(s);
    }

    cin >> q;
    vector<int> T(q);
    REP(i, q) cin >> T[i];

    int ans = 0;
    REP(i, q) {
        if(S.find(T[i]) != S.end()) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 400;
 
int h, w;
string s;
 
int grid[MX][MX];
ll black[MX*MX], white[MX*MX];
bool used[MX][MX];
ll ans;
 
int curGroup = -1;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
 
void dfs(int x, int y) {
	used[x][y] = true;
	if (grid[x][y]) black[curGroup]++;
	else white[curGroup]++;
	for (int i = 0; i < 4; i++) {
		int a = x + dx[i], b = y + dy[i];
		if (a < 0 || a >= h || b < 0 || b >= w) continue;
		if (grid[a][b] == grid[x][y]) continue;
		if (used[a][b]) continue;
		dfs(a, b);
	}
}
 
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '#') grid[i][j] = 1;
			else grid[i][j] = 0;
		}
	}
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			curGroup++;
			if (!used[i][j]) dfs(i, j);
		}
	}
	
	for (int i = 0; i <= curGroup; i++) {
		ans += white[i] * black[i];
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int n;
	double t,a,h;
	vector<pair<double,int>>v;
	cin>>n;
	cin>>t>>a;
	for(int i=0;i<n;i++)
	{
		cin>>h;
		v.push_back(make_pair(fabs(a-(t-h*0.006)),i+1));
	}
	sort(v.begin(),v.end());
	cout<<v[0].second<<endl;
	return 0;
}
	

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

  int N; cin >> N;
  int a;

  bool ok = true;
  rep(i, 0, N) {
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 == 0 || a % 5 == 0) {
        continue;
      } else {
        ok = false;
      }
    }
  }

  if (ok) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }

  return 0;
};


Measured memory_bytes: 256
n = int(input())
s = list(input())
bi = [0]
wi = [0]
b = 0
w = 0
for i in range(n):
    if s[i] == '#':
        b += 1
    if s[-i-1] == '.':
        w += 1
    bi.append(b)
    wi.append(w)
print(min(bi[i]+wi[-i-1] for i in range(n+1)))

Measured memory_bytes: 14164
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= n - i;
		ans %= mod;
	}
	return ans %= mod;
}

signed main(void) {
	int n, m;
	cin >> n >> m;
	int ans;
	if (n == m)ans = 2;
	else if (n == m - 1 || m == n - 1)ans = 1;
	else {
		println(0);
		return 0;
	}
	ans *= fact(m);
	ans %= mod;
	ans *= fact(n);
	ans %= mod;
	println(ans);
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <math.h>
int main(void){
    int h, w;
    scanf("%d %d", &h, &w);
    if(h==1 || w==1){
        printf("1\n");
    }else{
        int num[2+3];
        num[0]=ceil(w/2.0);
        num[1]=floor(w/2.0);
        
        long int ans=0;
        for(int y=0; y<h; y++){
            ans+=num[y%2];
        }
        printf("%ld\n", ans);
    }
}

Measured memory_bytes: 2240
import math
N,D = map(int,input().split())
Xs = [list(map(int,input().split()))for i in range(N)]
c = 0
for i in range(N-1):
  X1 = Xs[i]
  for j in range(i+1,N):
    X2 = Xs[j]
    su = 0
    for k in range(D):
      su += abs(X1[k]-X2[k]) **2
    distance = math.sqrt(su)
    if distance.is_integer():
      c+=1
print(c)

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

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

//改造
typedef long long int ll;
using namespace std;


//ここから編集する


struct edge {
    int to;
    ll cost;
};
typedef pair<ll, int> P;

int V;
vector<edge> G[100005];
ll INF = 922337203685477580;
ll dd[100005];
void dijkstra(int s) {
    ll dd2[100005];


    priority_queue<P, vector<P>, greater<P>> que;
//    fill(d, d + V, INF);
    for(int i = 0; i <= V; i++){
        dd2[i] = INF;
    }
    dd2[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (dd2[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (dd2[e.to] > dd2[v] + e.cost) {
                dd2[e.to] = dd2[v] + e.cost;
                que.push(P(dd2[e.to], e.to));
            }
        }
    }
    for(int i = 0; i <= V; i++){
        dd[i] = dd2[i];
    }

}

int main() {
    int n;
    cin >> n;
    V = n;
    for (int i = 0; i < n - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        edge e;
        e.to = a;
        e.cost = c;
        G[b].push_back(e);
        e.to = b;
        G[a].push_back(e);
    }
    int q, k;
    cin >> q >> k;
    dijkstra(k);
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        ll ans;
        ans = dd[x] + dd[y];
        cout << ans << endl;
    }
    return 0;
}


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

#define false 0
#define true  1

int isprime(int);

static const int N = 10000;

int main(){
  int n, i, j, count=0;
  int A[N];

  scanf("%d", &n);

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

      if(isprime(A[i])== 1) count++;

  }

  printf("%d\n", count);

  return 0;
}




int isprime(int x){
      
  int i = 3;
      
  if (x == 2)           return true;
  if (x < 2 || x%2 == 0)return false;
      
  while( i <= sqrt(x)) {
    if( x%i == 0) return false;
    i = i + 2;
  }
      
  return true;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
#define MOD 1000000007
using namespace std;
int main(){
    ll n,a,ans=0;
    cin>>n>>a;
    ans=n/a;
    if(ans*a<n)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k,ans;
main () {
	cin>>n>>k;
	
	ans+=(n/k)*(n/k)*(n/k);	
	if (k%2==0) ans+=((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k);	
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import Data.List


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

mdl :: Num a => a
mdl = 10^9 + 7

t a b = a * b `mod` mdl

positivize x = if x < 0 then x + mdl else x

main :: IO ()
main = do
    [n,a,b] <- r' :: IO [Int]
    let al = powMod 2 n - 1
    let na = choose n a
    let nb = choose n b
    print $ positivize $ (al - na - nb) `mod` mdl

powMod :: Int -> Int -> Int
powMod cur 0 = 1
powMod cur n
    | even n = powMod (t cur cur) (div n 2)
    | odd n  = (t cur) $! powMod (t cur cur) (div n 2)

choose :: Int -> Int -> Int
choose n i = t (prod' $ U.generate i (+ (n-i+1)) ) $ modInv (prod' $ U.generate i succ)

prod' :: U.Vector Int -> Int
prod' = U.foldr' t 1

modInv :: Int -> Int
modInv a =  let (x,_,1) = eEA a mdl
            in  positivize x

eEA :: Int -> Int -> (Int, Int, Int)
eEA a 0 = (1, 0, a)
eEA a b =   let (q, r) = a `quotRem` b
                (s, t, g) = eEA b r
            in  (t, s-q*t, g)



Measured memory_bytes: 7164
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    vector<pair<int, int>> a(5);
    for(auto& x : a)
        cin >> x.fi, x.se = (x.fi % 10 ? 10 - x.fi % 10 : 0);
    sort(begin(a), end(a), [] (auto& x, auto& y) {
        if(x.se == y.se)
            return x.fi > y.fi;
        return x.se > y.se;
    });
    int ans = a.front().fi;
    for(int i = 1; i < 5; ++i) {
        ans += ((a[i].fi + 9) / 10) * 10;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  int a, b; cin >> a >> b;
  if(a + b == 15) puts("+");
  else if(a * b == 15) puts("*");
  else puts("x");
  return 0;
}


Measured memory_bytes: 256