akhauriyash/Code-Regression huggingface dataset:
var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

rl.on('line', function (line) {
    let sum = 0;
    for(let i=0; i < line.length; i++) {
        sum += Number(line[i]);
    }
    if(sum % 9 === 0) {
        console.log("Yes");
    } else {
        console.log("No");
    }
})

Measured memory_bytes: 33212
from heapq import heappush,heappop,heapify
from math import ceil
def main():
    N, M = (int(i) for i in input().split())
    A = [-int(i) for i in input().split()]
    heapify(A)
    for divcnt in range(M):
        tmp = ceil(heappop(A)/2)
        heappush(A,tmp)
    print(-sum(A))
if __name__ == "__main__":
    main()


Measured memory_bytes: 96920
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

double dp[3005][3005];

int main(int argc, char *argv[])
{
	int N;
	double p[3005];

	cin >> N;

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

	dp[0][0] = 0;
	dp[1][0] = 1.0 - p[0];
	dp[1][1] = p[0];

	for (int i = 2; i <= N; i++) {
		for (int j = 0; j <= i; j++) {
			if (j == 0) {
				dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1]);
			} else {
				dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1];
			}
		}
	}

	double ans = 0.0;
	for (int i = N / 2 + 1; i <= N; i++) {
		ans += dp[N][i];
	}

	printf("%.9lf\n", ans);

	return 0;
}

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

class Solution {
public:
  void run() {
    int N, A, B; cin >> N >> A >> B;
    cout << min(A, B) << ' ' << max(0, A + B - N) << '\n';
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  Solution().run();
}


Measured memory_bytes: 256
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abc = br.readLine().split(" ");
        int a = Integer.parseInt(abc[0]);
        int b = Integer.parseInt(abc[1]);
        int c = Integer.parseInt(abc[2]);
        int ans = 0;
        
        if (a >= c-1) {
            ans = b+c;
        }
        else {
            ans += (a+1);
            c -= (a+1);
            if (b >= c) {
                ans += (b+c);
            }
            else {
                ans += b*2;
            }
        }
        
        System.out.println(ans);
        
    }
}

class Box {
    int w;
    int h;
    public Box(int w, int h) {
        this.w = w;
        this.h = h;
    }
}

class BoxComparator1 implements Comparator<Box>{
	public int compare(Box b1, Box b2) {
		return b1.w - b2.w;
	}
}

class BoxComparator2 implements Comparator<Box> {
    public int compare(Box b1, Box b2) {
        return b1.h - b2.h;
    }
}


Measured memory_bytes: 23124
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 998244353ll;

ll power(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll calcAll(int N) {
  ll res = power(3, N);
  res = (res - power(2, N) * 3 % MOD + MOD) % MOD;
  res = (res + 3) % MOD;
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (int& x : A) cin >> x;
    int tot = accumulate(A.begin(), A.end(), 0);
    vec<ll, 2> dp = make_v(tot + 1, 4, 0ll);
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
      int x = A[i];
      vec<ll, 2> ndp = make_v(tot + 1, 4, 0ll);
      for (int s = 0; s <= tot; s++) {
        for (int m = 0; m < 4; m++) {
          (ndp[s][m | (1 << 0)] += dp[s][m]) %= MOD;
          (ndp[s][m | (1 << 1)] += dp[s][m]) %= MOD;
          if (s + x <= tot) {
            (ndp[s + x][m] += dp[s][m]) %= MOD;
          }
        }
      }
      dp = ndp;
    }
    ll all = calcAll(N);
    ll sub = 0;
    for (int s = 1; s <= tot; s++) {
      if (s * 2 >= tot) {
        (sub += dp[s][3]) %= MOD;
      }
    }
    sub = sub * 3 % MOD;
    ll res = (all - sub + MOD) % MOD;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 14832
import java.util.Scanner;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt(), d = sc.nextInt(), x = sc.nextInt();
        int a[] = new int[n];
        long count = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            for (int j = 1, k = 0; j <= d; j++) {
                if (j == k * a[i] + 1) {
                    count++;
                    k++;
                }
            }
        }
        System.out.println(count + x);
    }
}

Measured memory_bytes: 22228
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    double r;cin>>r;
    printf("%.7f\n",2*r*M_PI);
}


Measured memory_bytes: 3808
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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


int main() {

  string S;

  std::cin >> S;
  S.erase(4,1);
  S.erase(6,1);
  
  if(stoi(S)<=20190430){
    cout <<"Heisei" <<endl;
  }else{
    cout <<"TBD" <<endl;
  }
  return 0;
   
}


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


int main(void){
    int N,i; cin>>N;
    int dp[100010];
    dp[0]=0;
    
    for(i=1;i<=N;i++){
        int c=1;
        while(c<=i){
            dp[i]=1+dp[i-c];
            c*=6;
        }
        c=9;
        while(c<=i){
            dp[i]=min(dp[i],1+dp[i-c]);
            c*=9;
       }
    }
    cout<<dp[N];
}

Measured memory_bytes: 640
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n=int(input())
print(lcm_list([int(input()) for _ in range(n)]))

Measured memory_bytes: 63980
# include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;

int n, ans = 0, state = 0;
int a[MAXN], sum[MAXN], cnt[MAXN], f[MAXN];

int main()
{
    scanf("%d", &n);
    int u, v, w;
    for(int i = 1; i < n; i++) {
        scanf("%d%d%d", &u, &v, &w);
        a[u] ^= w, a[v] ^= w;
    }
    for (int i = 0; i < n; i++) ++cnt[a[i]];
    for (int i = 1; i <= 15; i++) ans += (cnt[i] >> 1), state |= ((cnt[i] & 1) << (i - 1));
    int sta_max = (1 << 15) - 1;
    for (int sta = 1; sta <= sta_max; sta++) f[sta] = f[sta & (sta - 1)] + 1;
    for (int sta = 1; sta <= sta_max; sta++) --f[sta];
    for (int sta = 1; sta <= sta_max; sta++)
        for (int i = 1; i <= 15; i++)
            if((sta >> (i - 1)) & 1) sum[sta] ^= i;
    for (int sta = 1; sta <= sta_max; sta++) {
        if(sum[sta]) continue;
        for (int i = (sta & (sta - 1)); i; i = ((i - 1) & sta))
            if (!sum[i]) f[sta] = min(f[sta], f[i] + f[sta ^ i]);
    }
    printf("%d\n", ans + f[state]);
    return 0;
}

Measured memory_bytes: 896
dice = list(input().split(' '))
a = list('NNNNWNNNWNNNENNNENNNWNNN')
for _ in range(int(input())):
    aa,bb  = input().split(' ')
    for i in a:
        if i == 'W':
            dice = [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]]
        elif i == 'S':
            dice = [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]]
        elif i == 'N':
            dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
        elif i == 'E':
            dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
        if dice[0] == aa and dice[1] == bb:
            print(dice[2])
            


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) {
		if (b == c)cout << '1' << endl;
		else cout << '2' << endl;
		return 0;
	}
	else if (b == c) {
		if (a == c)cout << '1' << endl;
		else cout << '2' << endl;
		return 0;
	}
	else if (a == c) {
		if (b == c)cout << '1' << endl;
		else cout << '2' << endl;
		return 0;
	}
	else cout << '3' << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  int n; cin >> n;
  vector<int>x(n),y(n);
  rep(i,n) cin >> x[i] >> y[i];

  auto dist = [&](int i, int j){
    double dx = x[i]-x[j];
    double dy = y[i]-y[j];
    return sqrt(dx*dx+dy*dy);
  };
  vector<int>p(n);
  rep(i,n) p[i] = i;
  double len = 0;
  int cnt =0;
  do{
    rep(i,n-1){
      len += dist(p[i],p[i+1]);
    }
    cnt ++;
  }while(next_permutation(p.begin(),p.end()));
  double ans = len /cnt;
  printf("%.10f\n",ans);
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


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

int last[26];
int c[26];
int s[365][26];
int a[365];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int d; cin >> d;
    for(int i=0;i<26;i++){
    	cin >> c[i];
    }
    for(int i=0;i<d;i++){
    	for(int j=0;j<26;j++){
    		cin >> s[i][j];
    	}
    }
    for(int i=0;i<d;i++){
    	int mx=0;
    	int id=0;
    	for(int j=0;j<26;j++){
    		if(mx<(i+1-last[j])*c[j]){
    			mx=(i+1-last[j])*c[j];
    			id=j;
    		}
    	}
    	a[i]=id+1;
    }
    for(int i=0;i<26;i++){
    	last[i]=0;
    }
    int res=0;
    for(int i=0;i<d;i++){
    	res+=s[i][a[i]-1];
    	last[a[i]-1]=i+1;
    	for(int j=0;j<26;j++){
    		res-=c[j]*(i+1-last[j]);
    	}
    }
    for(int i=0;i<1e6;i++){
    	int day,qq;
    	day=myRand(d)+1;
    	qq=myRand(26)+1;
    	int resres=res;
    	int qqq=a[day-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres+=c[qq-1]*(i+1-last[qq-1]);
            resres+=c[qqq-1]*(i+1-last[qqq-1]);
        }
        a[day-1]=qq;
        resres-=s[day-1][qqq-1];
        resres+=s[day-1][qq-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres-=c[qq-1]*(i+1-last[qq-1]);
            resres-=c[qqq-1]*(i+1-last[qqq-1]);
		}
		if(resres>=res){

		}
		else{
			a[day-1]=qqq;
		}
    }
    for(int i=0;i<d;i++){
    	printf("%d\n",a[i]);
    }
}



Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {

    public Main() {
    }

    private static Scanner sc;

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        new Main().run();
    }

    private void run() {
        int N = sc.nextInt();
        int M = sc.nextInt();
        char[][] A = new char[N][N];
        char[][] B = new char[M][M];

        for (int i = 0; i < N; i++) {
            String line = sc.next();
            for (int j = 0; j < N; j++) {
                A[i][j] = line.charAt(j);
            }
        }

        for (int i = 0; i < M; i++) {
            String line = sc.next();
            for (int j = 0; j < M; j++) {
                B[i][j] = line.charAt(j);
            }
        }

        int pos = 0;
        boolean found = false;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (A[i][j] == B[0][0]) {
                    if (N < i + M || N < j + M) {
                        continue;
                    }
                    boolean unmatch = false;
                    for (int j2 = 0; j2 < M; j2++) {
                        if (unmatch) {
                            break;
                        }
                        for (int k = 0; k < M; k++) {
                            int ax = i + j2;
                            int ay = j + k;

                            if (A[ay][ax] != B[j2][k]) {
                                unmatch = true;
                                break;
                            }
                        }
                        if (j2 == M - 1) {
                            if (!unmatch) {
                                found = true;
                            }
                        }
                    }
                }
            }
        }

        if (found) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m;
vector<int> d;

int main() {
	cin >> n >> m;
	
	inc1(i, m) {
		if(i  > m / i) { break; }
		if(m % i != 0) { continue; }
		d.PB(i);
		if(i == m / i) { break; }
		d.PB(m / i);
	}
	sort(ALL(d));
	
	int ans = 0;
	inc(i, d.size()) {
		if(m / d[i] >= n) { setmax(ans, d[i]); }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int a,b,c; cin >> a>>b>>c;
    int sum = a+b; ll ans = 0;
    for(int i = 0;10000;i++){
        ans=i*60+c;
        if(ans % (a+b)<=a){cout << ans << endl; break;}
        if(((a+b == 60) && c > a )|| i>5000){cout << -1 << endl; break;}
    }
     
}

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


int main() {
	long double x[N];
	long double y[N];
	bool v;
	int n;
	long double ans = 10000000.0;
	long double x1, x2, x3, y1, y2, y3;
	long double xx, yy, r2, z, zz;
	scanf("%d", &n);
	f(i, n)scanf("%Lf %Lf", &x[i], &y[i]);
	f(i, n) {
		f(j, i) {
			xx = (x[i] + x[j]) / 2;
			yy = (y[i] + y[j]) / 2;
			r2 = ((xx - x[i])*(xx - x[i])) + ((yy - y[i])*(yy - y[i]));
			v = true;
			f(ii, n) {
			z= ((xx - x[ii])*(xx - x[ii])) + ((yy - y[ii])*(yy - y[ii]));
			if (z > (r2 + q))v = false;
			}
			if (v)ans = min(ans, sqrt(r2));
		}
	}
	f(i, n) {
		f(j, i) {
			f(jj, j) {
				x1 = x[i];
				x2 = x[j];
				x3 = x[jj];
				y1 = y[i];
				y2 = y[j];
				y3 = y[jj];
				z = (2 * (y1 - y3)*(x1 - x2) - 2 * (y1 - y2)*(x1 - x3));
				if (abs(z) > 1.0) {
					xx = (y1 - y3)*((y1*y1) - (y2*y2) + (x1*x1) - (x2*x2)) - (y1 - y2)*((y1*y1) - (y3*y3) + (x1*x1) - (x3*x3));
					xx = xx / z;
					yy = (x1 - x3)*((y1*y1) - (y2*y2) + (x1*x1) - (x2*x2)) - (x1 - x2)*((y1*y1) - (y3*y3) + (x1*x1) - (x3*x3));
					yy = -yy / z;
					r2 = ((xx - x[i])*(xx - x[i])) + ((yy - y[i])*(yy - y[i]));
					v = true;
					f(ii, n) {
						z = ((xx - x[ii])*(xx - x[ii])) + ((yy - y[ii])*(yy - y[ii]));
						if (z > (r2 + q))v = false;
					}
					if (v)ans = min(ans, sqrt(r2));
				}
			}
		}
	}
	printf("%.09Lf", ans);
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <cctype>
#include <queue>
#define il inline
#define vd void
#define rg register
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
int n,m,p,u,v,w,cnt,h[2505],dis[2505],in[2505],vis[2505];
struct E{int to,nxt,w;}e[5005];
queue <int> q;
il vd Add(int u,int v,int w){e[++cnt]=(E){v,h[u],w},h[u]=cnt;}
il int Spfa(){
	while(!q.empty()){
		u=q.front(),q.pop(),in[u]=0;
		for(rg int i=h[u];i;i=e[i].nxt){int v=e[i].to;
			if(dis[u]+e[i].w>dis[v]){
				dis[v]=dis[u]+e[i].w;
				if(!in[v]){
					if((vis[v]=vis[u]+1)>n&&v==n) return -1;
					q.push(v),in[v]=1;
				}
			}
		}
	}
	return Max(dis[n],0);
}
int main(){
	n=rd(),m=rd(),p=rd();
	while(m--) u=rd(),v=rd(),w=rd()-p,Add(u,v,w);
	rep(i,1,n) dis[i]=-1e9;
	dis[1]=0,q.push(1),rt(Spfa());
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
const int mxn = 2e5;
int n;
ll ans;
vi adj[mxn];

void dfs(int u = 0, int p = -1)
{
	for (int v : adj[u])
		if (v ^ p)
			dfs(v, u);
	if (u)
	{
		if (p < u)
			ans += (ll)(u - p) * (n - u);
		else
			ans += (ll)(u + 1) * (p - u);
	}
	else
		ans += n;
}

int main()
{
	fast;
	cin >> n;
	FOR(n - 1)
	{
		int u, v;
		cin >> u >> v, --u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs();
	cout << ans;
}

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

int main() {
  int n,d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0;i < n;i++){
    for (int j = 0;j < d;j++){
      cin >> x[i][j];
    }
  }
  int ans = 0;
  
  for (int i = 0;i < n-1;i++){
    for (int j = i+1;j < n;j++){
      int t = 0;
      for (int k = 0;k < d;k++){
        t += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
      }
      for (int k = 1;k*k <= t;k++){
        if (k*k == t){
          ans++;
        }
      }
    }
  }
      
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int t = a%b;

    if(t==0) {
        if(c==0) cout << "YES" << endl;
        else cout << "NO" <<  endl;
        return 0;
    }
    int sum = t;
    bool res = false;
    while(sum < 10050) {
        if(sum%b ==c) {
            res = true;
        }
        sum += t;
    }

    if(res) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
w = []
for i in range(n):
    item = str(input())
    if i == 0:
        w.append(item)
    elif i!=0:
        if w[i-1][-1]==item[0]:
            w.append(item)
        elif w[i-1][-1]!=item[0]:
            print("No")
            exit()
l = set(w)
if len(l)==len(w):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
// AOJ 1608: Selection of Participants of an Experime...
// 2017.10.6 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

int a[1002];

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int n, i, ans;

	while (scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++) scanf("%d", a+i);
		qsort(a, n, sizeof(int), cmp);
		ans = a[1] - a[0];
		for (i = 2; i < n; i++) if (a[i] - a[i-1] < ans) ans = a[i] - a[i-1];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1772
import sys
input = sys.stdin.readline
from collections import deque
def dfs(B,si,sj, H, W):
    R = [-1]*(H*W)
    R[si*W+sj] = 0
    d = deque([si*W+sj])
    while d:
        p = d.popleft()
        x = p//W
        y = p%W
        t = R[x*W+y]

        if x > 0:
            if B[(x-1)*W+y] == 0:
                if R[(x-1)*W+y] == -1:
                    R[(x-1)*W+y] = t+1
                    d.append((x-1)*W+y)

        if x < H-1:
            if B[(x+1)*W+y] == 0:
                if R[(x+1)*W+y] == -1:
                    R[(x+1)*W+y] = t+1
                    d.append((x+1)*W+y)
        if y > 0:
            if B[x*W+y-1] == 0:
                if R[x*W+y-1] == -1:
                    R[x*W+y-1] = t+1
                    d.append(x*W+y-1)
        if y < W-1:
            if B[x*W+y+1] == 0:
                if R[x*W+y+1] == -1:
                    R[x*W+y+1] = t+1
                    d.append(x*W+y+1)

    return max(R)
    

def main():
    H, W = map( int, input().split())
    S = [ list( input()) for _ in range(H)]
    B = [0]*(H*W)
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                B[i*W+j] = 1
    ans = 0
#    print(dfs(B,i,j,H,W))

    for i in range(H):
        for j in range(W):
            if B[i*W+j] == 1:
                continue
            t = dfs(B, i, j, H, W)
            if t > ans:
                ans = t
    print(ans)
            
if __name__ == '__main__':
    main()


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

int main()
{
  vector<int> v(3);
  for(int i=0;i<3;i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  cout<<v.at(0)+v.at(1)<<endl;
  return 0;
}


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

int main(){
 	char c1, c2, c3;
	cin >> c1 >> c2 >> c3;
 	cout << 700 + (c1 == 'o')*100 + (c2 == 'o')*100 + (c3 == 'o')*100;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define INF INT_MAX/3

int main() {
  cin.sync_with_stdio(false);
  ll n, c;
  cin >> n >> c;
  ll x[n + 2], v[n + 2];
  x[0] = v[0] = v[n + 1] = 0;
  x[n + 1] = c;
  repl(i, 1, n + 1) cin >> x[i] >> v[i];
  P r[n + 2], l[n + 2];
  r[0] = l[n + 1] = P(0, 0);
  repl(i, 1, n + 2) {
    r[i].fi = r[i - 1].fi + v[i] - (x[i] - x[i - 1]);
    l[n + 1 - i].fi = l[n + 2 - i].fi + v[n + 1 - i] - (x[n + 2 - i] - x[n + 1 - i]);
    r[i].se = l[i].se = i;
  }
  repl(i, 1, n + 2) {
    if (r[i].fi < r[i - 1].fi) {
      r[i] = r[i - 1];
    }
    if (l[n + 1 - i].fi < l[n + 2 - i].fi) {
      l[n + 1 - i] = l[n + 2 - i];
    }
  }
  ll ans = 0;
  rep(i, n + 1) {
    maxch(ans, r[i].fi + l[i + 1].fi - min(x[r[i].se], c - x[l[i + 1].se]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
ui = input()
uis = ui.split(" ")
N = int(uis[0])
A = int(uis[1])
B = int(uis[2])
if abs(A-B) % 2 == 0:
    print(abs(A-B) // 2)
elif A == B:
    print(0)
else:
    if B > A:
        temp = B
        B = A
        A = temp
    BDistance = B - 1
    ADistance = N - A
    if BDistance > ADistance:
        steps = ADistance + 1
        B = B + ADistance + 1
        A = N
        Distance = (N-B) // 2
        steps = steps + Distance
    else:
        steps = BDistance + 1
        B = 1
        A = A - BDistance - 1
        Distance = (A-1) // 2
        steps = steps + Distance
    print(steps)
    
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl a(n), b(n);
	REP(i, n)
	{
		cin >> a[i] >> b[i];
	}

	ll diff = 0;
	for (ll i = n - 1; i >= 0; i--) {
		diff += (b[i] - (a[i] + diff) % b[i]) % b[i];
	}
	cout << diff << endl;

	return 0;
}

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

int main(){
  int a, b, c, ans = 0;
  cin >> a >> b >> c;
  if(a % 2 != b % 2){
    if(a % 2 != c % 2){
      b++;
      c++;
      ans++;
    } else {
      a++;
      c++;
      ans++;
    }
  } else {
    if(a % 2 != c % 2){
      a++;
      b++;
      ans++;
    }
  }
  vector<int> arr = {a, b, c};
  sort(arr.rbegin(), arr.rend());
  cout << (arr[0] * 2 - arr[1] - arr[2]) / 2 + ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int c[3][3];
  FOR(i,0,3) FOR(j,0,3) cin >> c[i][j];
  bool ok = true;
  if(c[0][0]-c[1][0] != c[0][1] - c[1][1]) ok = false;
  if(c[0][2]-c[1][2] != c[0][1] - c[1][1]) ok = false;
  if(c[1][0]-c[2][0] != c[1][1] - c[2][1]) ok = false;
  if(c[1][1]-c[2][1] != c[1][2] - c[2][2]) ok = false;
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
*G=gets;
puts [
  *$<.map{|l|eval"X="+l.split*?,;X.each{|a|G[a]=*G[a],*X}},
  *1..$.
].map{|w|
  d=0;
  w=*w;
  f=w.size;
  (
    z=*z,*u=w;
    w=[];
    f*=[1,
      *u.map{|v|w=*w,*b=G[v]-z;b.size}
    ].max;
    d+=1;
  )while w[0];
  [d,f]
}.min

################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################
################################################################################

Measured memory_bytes: 4092
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

for A_num in range(A+1):
    for B_num in range(B+1):
        for C_num in range(C+1):
            if A_num * 500 + B_num * 100 + C_num * 50 == X:
                count += 1
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#define int long long
using namespace std;

int a[100001];
signed main() {
	int b; scanf("%lld", &b);
	for (int c = 0; c < b; c++)scanf("%lld", &a[c]);
	int ans = 0;
	for (int c = 0; c <= b; c++) {
		int sum = 0;
		for (int i = c;; i++) {
			if (a[i] == 0)break;
			sum += a[i];
			a[i] = 0;
		}
		ans += sum / 2;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        
        if(a > b){
            System.out.println("a > b");
        }else if(a == b){
            System.out.println("a == b");
        }else{
            System.out.println("a < b");
        }
        scanner.close();
    }
}


Measured memory_bytes: 26260
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    if (i+1)%2 != 0 and A[i]%2 != 0:
        count += 1
print(count)

Measured memory_bytes: 9528
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())

mod = 10**9 + 7


class CombMod:

    def __init__(self, N, MOD=10**9 + 7):

        N = N + 1
        inv = [0] * N
        fact = [0] * N
        fact_inv = [0] * N

        inv[0] = 0
        inv[1] = 1
        for n in range(2, N):
            q, r = divmod(MOD, n)
            inv[n] = inv[r] * (-q) % MOD

        fact[0] = 1
        for n in range(1, N):
            fact[n] = n * fact[n - 1] % MOD

        fact_inv[0] = 1
        for n in range(1, N):
            fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD

        self.fact = fact
        self.fact_inv = fact_inv
        self.inv = inv

    def comb(self, n, r, mod=10**9 + 7):
        return self.fact[n] * self.fact_inv[r] % mod * self.fact_inv[n - r] % mod

    def perm(self, n, r, mod=10**9 + 7):
        return self.fact[n] * self.fact_inv[n - r] % mod


def main():

    S = in_n()
    if S < 3:
        print(0)
        exit()

    mod = 10**9 + 7
    div = S // 3

    ans = 0
    comb = CombMod(2 * S)
    for k in range(1, div + 1):
        ans += comb.comb(S - 3 * k + k - 1, S - 3 * k)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define MOD ll(1000000007)

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

	ll i, n, j, t, m, x, y, z, k;

	ll ans=0;

	vl v;
	cin>>n;
	v.reserve(n);

	for(i=0; i<n; i++)
	{
		cin>>x;
		v.pb(x);
	}

	/*
	auto w = vector<int>(unordered_set<int>(v));

	sort(w.begin(), w.end());
*/

	for(i=0; i<n-2; i++)
	{
		for(j=i+1; j<n-1;j++)
		{
			for(k=j+1; k<n;k++)
			{
				if(v[i]!=v[j] && v[j]!=v[k] && v[i]!=v[k] && v[i]+v[j]>v[k] && v[i]+v[k]>v[j] && v[j]+v[k]>v[i]) 
					ans++;			
			}
		}
	}

	cout<<ans;
	cout<<"\n";

	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<bitset>
#include<cstring>
#include<algorithm>
using namespace std;

int len[2010], n, k, cnt, ncnt;
char s[2010][10010], ans[1000010];
bitset<10010> can[2010];
pair<int, int> vis[2][10010];

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%s", s[i]), len[i] = strlen(s[i]);
	can[n + 1][0] = 1;
	for (int i = n; i >= 1; i--) can[i] = can[i + 1] | (can[i + 1] << len[i]);
	for (int i = 1; i <= n; i++) if (can[i + 1][k - len[i]]) vis[0][++cnt] = make_pair(i, 0);
	int ii = 0;
	for (int i = 0; i < k; i++)
	{
		char minc = 'z';
		for (int j = 1; j <= cnt; j++) minc = min(minc, s[vis[ii][j].first][vis[ii][j].second]);
		ans[i] = minc;
		int minid = n + 1;
		ncnt = 0;
		for (int j = 1; j <= cnt; j++)
		{
			int nid = vis[ii][j].first, nlen = vis[ii][j].second;
			if (s[nid][nlen] != minc)
				continue;
			if (nlen + 1 == len[nid])
				minid = min(minid, nid);
			else
				vis[ii ^ 1][++ncnt] = make_pair(nid, nlen + 1);
		}
		for (int j = minid + 1; j <= n; j++)
			if (k - len[j] - i - 1 >= 0 && can[j + 1][k - len[j] - i - 1])
				vis[ii ^ 1][++ncnt] = make_pair(j, 0);
		ii ^= 1;
		cnt = ncnt;
	}
	printf("%s", ans);
}

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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

int main(){
	ll n, k;
	scanf("%lld%lld", &n, &k);
	ll t1 = n / k, t2 = k & 1 ? n / k : n * 2 / k;
	t2 -= t1;
	printf("%lld\n", t1 * t1 * t1 + t2 * t2 * t2);
	return 0;
}


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

using namespace std;

int main()
{
    double l1_distance = 0.0, l2_distance = 0.0, l_3_distance = 0.0, diff, l_infty = -99999;
    double x[100], y[100];
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> x[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> y[i];
    }

    for (int i = 0; i < n; ++i)
    {
        diff = fabs(y[i] - x[i]);
        l1_distance += diff;
        l2_distance += diff * diff;
        l_3_distance += diff * diff * diff;
        l_infty = max(l_infty, diff);
    }
    l2_distance = sqrt(l2_distance);
    l_3_distance = pow(l_3_distance, 1.0 / 3.0);
    printf("%10.8f\n", l1_distance);
    printf("%10.8f\n", l2_distance);
    printf("%10.8f\n", l_3_distance);
    printf("%10.8f\n", l_infty);
}


Measured memory_bytes: 3396
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	
	int A,B;
	cin >> A >> B;
	cout << (A + B) % 24 << endl;
	return 0;
}


Measured memory_bytes: 256
N, X, Y = map(int, input().split())
f = [0] * N
for i in range(1, N):
    for j in range(i + 1, N + 1):
        d = min(j - i, abs(i - X) + abs(j - Y) + 1)
        f[d] += 1
for i in range(1, N):
    print(f[i])

Measured memory_bytes: 46300
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    if k%2 == 1:
        print((n//k)**3)
    else:
        print(((n-k//2)//k+1)**3 + (n//k)**3)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

int main() {
    int H, W, D; cin >> H >> W >> D;
    vector<vi> a(H, vi(W));
    rep(i, H)rep(j, W) {
        int x; cin >> x; --x;
        a[i][j] = x;
    }

    map<int, pii> mp;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            mp[a[i][j]] = { i,j };
        }
    }
    int E = (H * W + D - 1) / D;
    vector<vector<int>> preAcc(E, vi(D));

    for (int i = 1; i < E; i++) {
        for (int j = 0; j < D; j++) {
            int num = i * D + j;
            if (num > H * W) break;
            preAcc[i][j] = preAcc[i - 1][j] + abs(mp[num].first - mp[num - D].first) + abs(mp[num].second - mp[num - D].second);
        }
    }

    int Q; cin >> Q;
    for (int q = 0; q < Q; q++) {
        int L, R; cin >> L >> R;
        --L; --R;
        int cost = 0;
        cost = preAcc[R / D][R % D] - preAcc[L / D][L % D];
        cout << cost << endl;
    }
    sysp;
}

Measured memory_bytes: 14388