akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>

struct Edge {
  size_t src, dst;
  double cost;
  Edge(size_t src, size_t dst, double cost): src(src), dst(dst), cost(cost) {};
  bool operator <(const Edge &e) const {
    return cost < e.cost;
  }
};

class UnionFind {
  size_t n;
  std::vector<int> size;

public:
  UnionFind(size_t n): n(n), size(n, -1) {}

  bool unite(size_t u, size_t v) {
    u = find_root(u);
    v = find_root(v);
    if (u == v) return false;

    if (-size[u] < -size[v])
      std::swap(u, v);

    // u >= v
    size[u] += size[v];
    size[v] = u;

    return true;
  }

  size_t find_root(size_t u) {
    if (size[u] < 0) return u;
    return (u = find_root(size[u]));
  }

  bool is_connected(size_t u, size_t v) {
    return find_root(u) == find_root(v);
  }
};

double kruskal(std::vector<std::vector<Edge>> &g) {
  size_t v=g.size();
  std::vector<Edge> es;
  for (size_t i=0; i<v; ++i) {
    for (size_t j=0; j<g[i].size(); ++j) {
      es.emplace_back(g[i][j]);
    }
  }

  size_t e=es.size();
  std::sort(es.begin(), es.end());
  UnionFind uf(v);
  double res=0;
  for (size_t i=0; i<e; ++i) {
    Edge e=es[i];
    if (!uf.is_connected(e.src, e.dst)) {
      uf.unite(e.src, e.dst);
      res += e.cost;
    }
  }

  return res;
}

double hypot3d(double x, double y, double z) {
  return sqrt(x*x+y*y+z*z);
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);

  if (n == 0)
    return 1;

  std::vector<double> x(n), y(n), z(n), r(n);
  for (size_t i=0; i<n; ++i) {
    scanf("%lf %lf %lf %lf", &x[i], &y[i], &z[i], &r[i]);
  }

  std::vector<std::vector<Edge>> d(n, std::vector<Edge>(n, Edge(0, 0, 0)));
  for (size_t i=0; i<n; ++i) {
    for (size_t j=i+1; j<n; ++j) {
      double dist=hypot3d(x[i]-x[j], y[i]-y[j], z[i]-z[j]);
      if (dist <= r[i] + r[j]) {
	d[i][j] = Edge(i, j, 0);
	d[i][j] = Edge(j, i, 0);
      } else {
	d[i][j] = Edge(i, j, dist - (r[i]+r[j]));
	d[j][i] = Edge(j, i, dist - (r[i]+r[j]));
      }
    }
  }

  printf("%.3f\n", kruskal(d));
  return 0;
}

int main() {
  while (!testcase_ends()) {}

  return 0;
}

Measured memory_bytes: 3180
import java.util.*;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int data[] = new int[3];
    int max = -1000;

    for (int i = 0 ; i < 3 ; i++ ) {
      if (i == 0) {
        data[i] = a+b ;
      }
      if (i == 1) {
        data[i] = a-b ;
      }
      if (i == 2) {
        data[i] = a*b ;
      }
    }

    for (int i = 0 ; i < 3 ; i++ ) {
      max = Math.max(data[i], max);
    }
    System.out.println(max);
  }
}


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

int main(){
  string s; cin>>s;
  int len=s.length();
  int l,r;
  for(int i=0;i<len;i++){
    if(s[i]=='A'){
      l=i+1;
      break;
    }
  }
  for(int i=len-1;i>=0;i--){
    if(s[i]=='Z'){
      r=i+1;
      break;
    }
  }
  cout<<r-l+1<<endl;
}

Measured memory_bytes: 640
Z = 998244353
N = int(input())
D = list(map(int,input().split()))
if D[0]>0:
    ans = 0
elif N==1:
    ans = 1
else:
    D.sort()
    if D[1]==0:
        ans = 0
    else:
        D.append(-1)
        ans = 1
        cur = 0
        n1 = 1
        n2 = 1
        for d in D[1::]:
            if d == cur:
                n2 += 1
            else:
                if d == cur+1 or d == -1:
                    nn = pow(n1,n2,Z)
                    ans *= nn
                    n1 = n2
                    n2 = 1
                    cur = d
                else:
                    ans = 0
                    break
        ans%=Z
print(ans)

Measured memory_bytes: 14020
#include <stdio.h>

int main(void)
{
    int N;
    long long int A[100000];
    long long int B[100000];
    long long int sum = 0, p;

    scanf("%d", &N);

    for (int i = 0; i < N; i++) {
        scanf("%lld%lld", &A[i], &B[i]);
    }

    for (int i = N-1; i >= 0; i--) {
        if ((sum+A[i])%B[i] == 0) {
            continue;
        } else {
            sum += B[i] - (sum + A[i]) % B[i];
        }
    }
    printf("%lld\n", sum);
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
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;}
const int MOD = 1000000007;

void solve() {
  string s;
  cin >> s;
  int x = stoi(s.substr(0, 2));
  int y = stoi(s.substr(2, 2));
  if ((x == 0 || x > 12) && (y == 0 || y > 12)) {
    cout << "NA" << endl;
  } else if ((x != 0 && x <= 12) && (y != 0 && y <= 12)) {
    cout << "AMBIGUOUS" << endl;
  } else {
    if ((x == 0 || x > 12)) cout << "YYMM";
    else cout << "MMYY";
  }
}

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

Measured memory_bytes: 3624
from collections import deque #両端から取り出すのが速い
N,K = map(int,input().split())
A = list(map(int,input().split()))
pos = []
neg = []
for a in A:
    if a >= 0:
        pos.append(a)
    else:
        neg.append(-a)
pos = deque(sorted(pos))
neg = deque(sorted(neg))
mod = 10**9+7
ans = 1
sign = 1
if K%2 == 1: #Kが奇数の時pos（ある場合）から必ず１つ取る
    if len(pos) > 0:
        ans = ans*pos.pop() % mod
    else:
        ans = ans*neg.popleft() % mod
        sign *= -1
    K -= 1
while K > 0: #偶数の場合と奇数の残りの処理
    if len(pos) == 1 and len(neg) == 1:
        ans = ans*-neg.pop()*pos.pop() % mod
    elif sign == 1:#通常バージョン
        if len(pos) < 2 or (len(neg) >= 2 and pos[-2]*pos[-1] < neg[-2]*neg[-1]):
            ans = ans*neg.pop()*neg.pop() % mod
        else:
            ans = ans*pos.pop()*pos.pop() % mod
    else:#奇数の前処理で負になっている場合(最終結果も負になるので小さくしたい)
        if len(pos) < 2 or (len(neg) >= 2 and pos[-2]*pos[-1] < neg[-2]*neg[-1]):
            ans = ans*neg.popleft()*neg.popleft() % mod
        else:
            ans = ans*pos.popleft()*pos.popleft() % mod
    K -= 2
ans = ans*sign % mod
print(ans)



Measured memory_bytes: 110488
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    double f[n][2];
    double d[n][n];
    for(int i = 0; i < n; i++){
        cin >> f[i][0] >> f[i][1];
    }
    double ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            d[i][j] = sqrt((f[i][0] - f[j][0])*(f[i][0] - f[j][0]) + (f[i][1] - f[j][1])*(f[i][1] - f[j][1]));
            ans += d[i][j];
        }
    }
    cout << setprecision(12) << 2*ans / n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using std::cout;
using std::cin;
using std::endl;

bool check1(int n) {
    if (n % 3 == 0) {
        return true; 
    }
    return false;
}
bool check2(int n) {
    if (n % 10 == 3 ){
        return true; 
    }
    return false;
}

bool check(int n) {
    if (check1(n) == true || check2(n) == true) {
        return true;
    } else {
        n /= 10;
        while (n != 0) {
            if (check2(n) == true) {
                return true;
            }
            n /= 10;
        }
    }
    return false;
}

void call(int n) {
    for (int i = 1; i <= n; i++) {
        if (check(i) == true) {
            cout << " " << i;
        }
    }
    cout << endl;
    return;
}

int main(void) {
    int n;
    cin >> n;
    call(n);
}

Measured memory_bytes: 3096
#include <iostream>
#include <queue>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[100][100];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];
    struct Edge {
        int from, to, weight;
        Edge(int from, int to, int weight) : from(from), to(to), weight(weight) {}
        bool operator < (const Edge& e) const {
            return weight > e.weight;
        }
    };
    int sm = 0;
    priority_queue<Edge> q;
    q.push(Edge(-1, 0, 0));
    bool visited[100]{};
    while (q.size()) {
        auto e = q.top();
        q.pop();
        if (visited[e.to]) continue;
        visited[e.to] = true;
        sm += e.weight;
        for (int i = 0; i < n; ++i) {
            if (a[e.to][i] >= 0 && !visited[i])
                q.push(Edge(e.to, i, a[e.to][i]));
        }
    }
    cout << sm << endl;
    return 0;
}

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

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    int count = 0;
    while(true) {
        B += A / 2;
        A /= 2;
        count++;
        if(count == K) break;
        A += B / 2;
        B /= 2;
        count++;
        if(count == K) break;
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
from itertools import *

n = int(input())
xyh = []
for i in range(n):
    xyh += [list(map(int, input().split()))]
xyh.sort(reverse=True, key=lambda x: x[2])
[x0, y0, h0] = xyh[0]
for x, y in product(range(0, 101), range(0, 101)):
    h = h0 + abs(x - x0) + abs(y - y0)
    for k in xyh[1:]:
        if k[2] != max(h - abs(x - k[0]) - abs(y - k[1]), 0):
            break
    else:
        break
print(x, y, h)


Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

typedef long long ll;
#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

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

	int pre_a = 0, pre_b = 1;
	bool flag = true;
	for(int i = 2; i <= 999; ++i){
		if(pre_a - a == pre_b - b){
			break;
		} else{
			pre_a = pre_b;
			pre_b += i;
		}
	}
	cout << abs(pre_b - b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while(1){
        cin >> a >> op >> b;
        if(op=='?')break;
        else if(op=='+'){
            cout << a+b << endl;
        } else if(op=='-'){
            cout << a-b << endl;
        } else if(op=='*'){
            cout << a*b << endl;
        } else if(op=='/'){
            cout << a/b << endl;
        }
    }return 0;
}


Measured memory_bytes: 3120
#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 << "Balanced" << endl;
  else if(A + B > C + D)
    cout << "Left" << endl;
  else
    cout << "Right" << endl;
  
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,k; cin>>a>>b>>k;
	ll cnt=0;
	for(ll i=min(a, b);i>=1;i--){
		if (a%i==0 && b%i==0){
			cnt++;
			if (cnt==k){
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    flag=-1
    for i in range(n):
        if s[i]=='W':
            flag=i
        else:
            break
    cunt_b=0
    cunt_w=0
    ans=0
    for i in range(n):
        if s[i]=='B':
            cunt_b+=1
        elif cunt_b>0:
            ans+=i-flag-1-cunt_w
            cunt_w+=1
    print(ans)



if __name__=='__main__':
    main()

Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <iomanip>
#include <cmath>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef tuple<double,int,int> T;

class UnionFind {
public:
    vector<int> par;
    int size;
    UnionFind(int n) {
        size = n;
        par.resize(n);
        REP (i, 0, n) par[i] = i;
    }
    int find(int n) {
        return (n == par[n] ? n : par[n] = find(par[n]));
    }
    bool unite(int a, int b) {
        a = find(a);
        b = find(b);
        if (a == b) return false;
        par[a] = b;
        size--;
        return true;
    }
    bool same(int a, int b) {
        return find(a) == find(b);
    }
};

int main() {
    int n;
    while (cin >> n, n) {
        vector<double> x(n), y(n), z(n), r(n);
        REP (i, 0, n) cin >> x[i] >> y[i] >> z[i] >> r[i];
        UnionFind uf(n);
        vector<T> v;
        v.reserve(n * n);
        REP (i, 0, n) REP (j, i + 1, n) {
            double dis = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j]));
            v.push_back(make_tuple(max(0.0, dis - r[i] - r[j]), i, j));
        }
        sort(begin(v), end(v));
        double ans = 0;
        REP (i, 0, v.size()) {
            T tp = v[i];
            if (uf.unite(get<1>(tp), get<2>(tp))) {
                ans += get<0>(tp);
            }
        }
        cout << fixed << setprecision(3) << ans << endl;
    }

    return 0;
}


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

// UnionFindの実装
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }

    // 集合をマージする
    // すでに同じ集合ならfalseが返る
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) return false;
        //要素数の少ない方を多い方に繋げる
        if(data.at(y) < data.at(x)) swap(x, y);
        data.at(x) += data.at(y);
        data.at(y) = x;
        return true;
    }

    // ある要素がどの集合に属しているかを答える
    int root(int x) {
        // 根に直接つなぎ直す
        return data.at(x) < 0 ? x : (data.at(x) = root(data.at(x)));
    }

    // ある集合の大きさを答える
    int size(int x) {
        return -data.at(root(x));
    }

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

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    map<pair<int, int>, int> num;
    UnionFind car(n);
    vector<int> p(k, 0);
    vector<int> q(k, 0);
    for(int i = 0; i < k; ++i) {
        cin >> p.at(i) >> q.at(i);
        p.at(i)--; q.at(i)--;
        car.merge(p.at(i), q.at(i));
    }

    UnionFind train(n);
    vector<int> r(l, 0);
    vector<int> s(l, 0);
    for(int i = 0; i < l; ++i) {
        cin >> r.at(i) >> s.at(i);
        r.at(i)--; s.at(i)--;
        train.merge(r.at(i), s.at(i));
    }
    for(int i = 0; i < n; ++i) {
        int inp = car.root(i);
        int inq = train.root(i);
        num[pair<int, int>(inp, inq)]++;
    }

    for(int i = 0; i < n; ++i) {
        int inp = car.root(i);
        int inq = train.root(i);
        cout << num[pair<int, int>(inp, inq)] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long long LINF=1e18;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
int ans[305][305];

signed main(){
  int h,w,k;cin>>h>>w>>k;
  vector<string> s(h);
  for(int i=0;i<h;i++)cin>>s[i];
  int now=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='.')continue;
      now++;
      int y=j;
      while(ans[i][y]==0){
        ans[i][y]=now;
        y--;
        if(y==-1)break;
      }
      y=j+1;
      if(y<h){
        while(ans[i][y]==0){
          if(s[i][y]=='#')break;
          ans[i][y]=now;
          y++;
          if(y==h)break;
        }
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=1;j<w;j++){
      if(ans[i][j]==0&&ans[i][j-1]){
        ans[i][j]=ans[i][j-1];
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=w-2;j>=0;j--){
      if(ans[i][j]==0&&ans[i][j+1]){
        ans[i][j]=ans[i][j+1];
      }
    }
  }
  for(int j=0;j<w;j++){
    for(int i=1;i<h;i++){
      if(ans[i][j]==0&&ans[i-1][j]){
        ans[i][j]=ans[i-1][j];
      }
    }
  }
  for(int j=0;j<w;j++){
    for(int i=h-2;i>=0;i--){
      if(ans[i][j]==0&&ans[i+1][j]){
        ans[i][j]=ans[i+1][j];
      }
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cout<<ans[i][j]<<" ";cout<<endl;
  }
}


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

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

template<class S, class T> inline void chmin(S &a, T b){if(a>b)a=b;}

int N, A[2000], B[2000], X;

int main(){
  int i, j, k;
  ll res, tmp;

  reader(&N,&X);
  rep(i,N) reader(A+i);

  res = accumulate(A, A+N, 0LL);
  rep(i,N) B[i] = A[i];
  REP(k,1,N){
    rep(i,N) B[i] = min(B[i], A[(i-k+N)%N]);
    tmp = accumulate(B, B+N, (ll)k*X);
    res = min(res, tmp);
  }

  writerLn(res);

  return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int n, p[100007], vis[100007], can[100007], d[100007]; vector<int> v;
void rec(int pos, int cur) {
	vis[pos] = cur;
	while (true) {
		if (p[pos] == 0) break;
		v.push_back(pos);
		pos += p[pos];
		if (vis[pos] == cur || !can[pos]) {
			for (int i = 0; i < v.size(); i++) can[v[i]] = 0;
			break;
		}
		vis[pos] = cur;
	}
	v.clear();
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> p[i], can[i] = 1;
	for (int i = 0; i < n; i++) {
		if (!vis[i] && p[i]) rec(i, i + 1);
	}
	fill(d + 1, d + n, -1);
	queue<int> que; que.push(0);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i = 1; i <= 6 && u + i < n; i++) {
			int cur = u + i;
			if (can[cur] && d[cur] == -1) {
				while (p[cur]) cur += p[cur];
				if(d[cur] == -1) d[cur] = d[u] + 1, que.push(cur);
			}
		}
	}
	cout << d[n - 1] << endl;
	return 0;
}

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

vector<int> res;

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long int> l, r;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    l.push_back(a);
    r.push_back(b);
  }
  
  long long int left = *max_element(l.begin(), l.end());
  long long int right = *min_element(r.begin(), r.end());
  long long temp = right - left + 1;

  long long int res;
  if (temp <= 0) {
    res = 0;
  } else if (n <= temp) {
    res = n;
  } else {
    res = temp;
  }
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2036
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author myob-_-
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
        double a = in.nextDouble();
        double b = in.nextDouble();
        double H = in.nextDouble();
        double M = in.nextDouble();
        double HH = H*30+ M/2;
        double MM = M*6;
        double ang = Math.abs(HH-MM);
        ang = Math.min(360-ang, ang);
        double result = Math.sqrt((a*a)+(b*b)-(2*a*b*Math.cos(Math.toRadians(ang))));
        out.println(String.format("%.10f", result));
    }

    }
}



Measured memory_bytes: 37412
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long int n,m,ans=0,c=0;
    cin>>n>>m;
    int k[n+5];
    int a[n+5][m+5];
    for(int h=0;h<n;h++){
        cin>>k[h];
        for(int g=0;g<k[h];g++){
            cin>>a[h][g];
        }
    }
    for(int i=1;i<m+1;i++){
        for(int j=0;j<n;j++){
            for(int l=0;l<k[j];l++){
                if(a[j][l]==i){
                    c++;
                }
            }
        }
        if(c==n){
           ans++;
        }
        c=0;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  int h;
  vector<int> hs;

  for (int i = 0; i < n; i++)
  {
    cin >> h;
    hs.push_back(h);
  }

  int res = 0;
  for (int i = 0; i < n; i++)
  {
    bool suc = true;
    for (int j = 0; j < i; j++)
    {
      if (hs[i] < hs[j])
      {
        suc = false;
        break;
      }
    }
    if (suc)
    {
      res++;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
signed main() {
	int r;
	cin >> r;
	double pi = 3.1415926;
	cout << 2 * r * pi << endl;
	ggr
}


Measured memory_bytes: 3788
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int a[4];
	for (int i = 0;i < 4;i++) {
		cin >> a[i];
	}
	sort(a, a + 4);
	if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
from collections import deque

divide = ["dream", "dreamer", "erase", "eraser"];

s = input()
que = deque()

can = "NO"

que.append(0)

while(len(que) > 0):
  t = que.pop()
  if (t == len(s)):
    can = "YES"
    break
  for e in divide:
    if s[t:t+len(e)] == e:
      que.append(t+len(e))
print(can)

Measured memory_bytes: 3820
n = int(input())
words = []
for i in range(n):
	a = int(input())
	w = []
	for _ in range(a):
		x, y = map(int, input().split())
		w.append([x-1, y])
	words.append(w)


ans = 0
for bit in range(1<<n):
  #2のn乗まで捜査
	ok = True
	is_honest = [(bit>>i) & 1 for i in range(n)]
	#bitをiずらして末尾が1のひとは正直
	for i in range(n):
		if not is_honest[i]:
			continue
		for x, y in words[i]:
			if is_honest[x] != y:
				ok = False
	if ok:
		ans = max(ans, sum(is_honest))
print(ans)



Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
    int a,b,d,r;


    scanf("%d%d",&a,&b);

    d=b*2+1;
    r=a/d;
    a=a%d;
    if(a!=0)
        printf("%d",r+1);
    else
        printf("%d",r);



}




Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
//#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
char s[4010];
std::vector<int> rs;
std::vector<int> gs;
std::set<int> bs;

int main()
{
	scanf("%d\n", &n);
	scanf("%s\n", &s);
	
	for (int i = 0 ; i < n ; i++) {
		if (s[i] == 'R') {
			rs.push_back(i);
		} else if (s[i] == 'G') {
			gs.push_back(i);
		} else if (s[i] == 'B') {
			bs.insert(i);
		}
	}
	
	long long total;
	total = rs.size();
	total = total * gs.size();
	total = total * bs.size();
	for (int i = 0 ; i < rs.size() ; i++) {
		for (int j = 0 ; j < gs.size() ; j++) {
			int a = rs[i];
			int b = gs[j];
			if (a > b) {
				int temp = a;
				a = b;
				b = temp;
			}
			
			int c;
			//左侧的 
			c = a - (b - a);
			if (bs.find(c) != bs.end()) {
				total--;
//				printf("%d %d %d\n", a, b, c);
			}
			
			//右侧的 
			c = b + (b - a);
			if (bs.find(c) != bs.end()) {
				total--;
//				printf("%d %d %d\n", a, b, c);
			}
			
			int dist = b - a;
			if (dist % 2 == 0) {
				c = a + dist / 2;
				if (bs.find(c) != bs.end()) {
					total--;
//					printf("%d %d %d\n", a, b, c);
				}
			}
			
		}
	}
	
	
	printf("%lld\n", total);
	
	return 0;
}

Measured memory_bytes: 3344
#include<iostream>
using namespace std;
typedef long long ll;
ll n,m,a,s,t,u;
int main(){
  cin >> n >> m;s=n^m,t=s&1,u=(s&2)>>1;a=((n&1)*n)^(((m&1)^1)*m)^t^u;
  cout << a << endl;
}

Measured memory_bytes: 256
def base10to(n, b):
    if(int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)
def main():
    n = int(input())
    result = 0
    for i in range(1, 3*10**5):
        temp = base10to(i, 4)
        if '0' not in temp and '1' in temp and '2' in temp and '3' in temp:
            temp = temp.replace('3', '7')
            temp = temp.replace('1', '3')
            temp = temp.replace('2', '5')
            if int(temp) <= n:
                #print(temp)
                result += 1
            else:
                break
    print(result)
main()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
	int a;
	cin >> a;
	if (a == 22)
	{
		cout << "Christmas Eve Eve Eve" << endl;
	}
	if (a == 23)
	{
		cout << "Christmas Eve Eve" << endl;
	}
	if (a == 24)
	{
		cout << "Christmas Eve" << endl;
	}
	if (a == 25)
	{
		cout << "Christmas" << endl;
	}
	return 0;
}

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

namespace AOJ0021
{
    class Program
    {
        private const double Epsilon = 0.00000001;

        static void Main()
        {
            var dataCount = int.Parse(Console.ReadLine() ?? "");
            for (var i = 0; i < dataCount; i++)
            {
                var data = (Console.ReadLine() ?? "").Split(' ').Select(double.Parse).ToArray();
                var pA = new Point(data[0], data[1]);
                var pB = new Point(data[2], data[3]);
                var pC = new Point(data[4], data[5]);
                var pD = new Point(data[6], data[7]);
// ReSharper disable InconsistentNaming
                var vAB = new Vector(pA, pB);
                var vCD = new Vector(pC, pD);
// ReSharper restore InconsistentNaming
                Console.WriteLine(Math.Abs(vAB.Cross(vCD).Z) < Epsilon ? "YES" : "NO");
            }
        }
    }

    public class Point
    {
        public double X { get; set; }
        public double Y { get; set; }
        public double Z { get; set; }

        public Point(double x = 0, double y = 0, double z = 0)
        {
            X = x;
            Y = y;
            Z = z;
        }
    }

    public class Vector
    {
        public double X { get; set; }
        public double Y { get; set; }
        public double Z { get; set; }

        public Vector(double x = 0, double y = 0, double z = 0)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public Vector(Point p1, Point p2)
            : this(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z)
        {
        }

        public Vector Cross(Vector other)
        {
            var x = Y * other.Z - Z * other.Y;
            var y = Z * other.X - X * other.Z;
            var z = X * other.Y - Y * other.X;

            return new Vector(x, y, z);
        }
    }
}

Measured memory_bytes: 6004
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

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

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

	map<char, int> dir;
	dir.insert(make_pair('N', 0));
	dir.insert(make_pair('S', 1));
	dir.insert(make_pair('E', 2));
	dir.insert(make_pair('W', 3));

	for(int n; cin >> n, n;) {
		vector<vector<bool> > field(21, vector<bool>(21, false));
		for(int i = 0; i < n; ++i) {
			int x, y;
			cin >> x >> y;
			field[y][x] = true;
		}

		int m;
		cin >> m;

		int cnt = 0;
		int x = 10, y = 10;
		for(int i = 0; i < m; ++i) {
			char d;
			int l;
			cin >> d >> l;

			for(int j = 0; j < l; ++j) {
				x += dx[dir[d]];
				y += dy[dir[d]];

				cnt += field[y][x];
				field[y][x] = false;
			}
		}

		cout << (cnt == n ? "Yes" : "No") << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int a[n];
    int cnt[100001],cnt2[100001];
    fill(cnt,cnt+100001,0);
    fill(cnt2,cnt2+100001,0);
    rep(i,0,n){
        cin>>a[i];
        if(i%2==0)cnt[a[i]]++;
        else cnt2[a[i]]++;
    }
    vector<pii> v1,v2;
    rep(i,1,100001){
        v1.push_back({cnt[i],i});
        v2.push_back({cnt2[i],i});
    }
    sort(v1.begin(),v1.end(),greater<pii>());
    sort(v2.begin(),v2.end(),greater<pii>());
    if(v1[0].second!=v2[0].second){
        cout<<n-v1[0].first-v2[0].first<<endl;
    }
    else{
        cout<<min(n-v1[0].first-v2[1].first,n-v1[1].first-v2[0].first)<<endl;
    }
}










Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,ii> iii;
typedef pair<int, iii> iiii;
typedef pair<double, ii> dii;
typedef long long ll;
typedef pair<ll, ii> lii;
const int INF = 1000000000;
const double EPS = 1e-9;
#define LSOne(S) (S & (-S))
int mods(int a, int b) { return (b + (a%b)) % b; }

int n, h[100005], dp[100005];

int solve(int pos) {
    if (pos == n-1) return 0;
    if (dp[pos] != -1) return dp[pos];

    int a = INF, b = INF;
    if (pos + 1 < n) a = solve(pos+1);
    if (pos + 2 < n) b = solve(pos+2);
    return dp[pos] = min(abs(h[pos] - h[pos+1]) + a, abs(h[pos] - h[pos+2]) + b);
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> h[i];

    memset(dp, -1, sizeof(dp));

    cout << solve(0) << '\n';
 
    return 0;
}

Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();
        long answer = 0;
        for (int i = 1; i <= N; i++) {
            String x = Integer.toString(i);
            int t = 0;
            for (char c : x.toCharArray()) {
                t += c - '0';
            }
            if (A <= t && t <= B) {
                answer += i;
            }
        }
        System.out.println(answer);
    }
}


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

ifstream in("test.in");
ofstream out("test.out");

int cnt[26];

int main(void) {
    ios :: sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n, m;
    cin >> n >> m;
    
    for (int i = 1; i <= n; ++i) {
        string str;
        cin >> str;
        
        for (char ch : str)
            cnt[ch - 'a']++;
    }
    
    int nr1 = (n / 2) * (m / 2),
        nr2 = (m / 2) * (n & 1) + (n / 2) * (m & 1),
        nr3 = (n & 1) and (m & 1);
    
    for (int i = 0; i < 26; ++i) {
        while (cnt[i] >= 4 and nr1)
            cnt[i] -= 4, --nr1;
        while (cnt[i] >= 2 and nr2)
            cnt[i] -= 2, --nr2;
        while (cnt[i] >= 1 and nr3)
            cnt[i] -= 1, --nr3;
    }
    
    cout << ((!nr1 and !nr2 and !nr3) ? "Yes" : "No");
    
    return 0;
}

Measured memory_bytes: 256
function main()
  
  (A,B) = map(x -> parse(Int,x), split(readline()))
  
  if A == 1
    A = 14
  end
  if B == 1
    B = 14
  end
  
  if A == B
    println("Draw")
  elseif A > B
    println("Alice")
  else
    println("Bob")
  end
  
end
 
main()

Measured memory_bytes: 109636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<string>A(N);
  vector<string>B(M);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<M;i++){
    cin>>B.at(i);
  }
  bool flag2=true;
  for(int i=0;i<N-M+1;i++){
    if(flag2==false){
      break;
    }
    for(int j=0;j<N-M+1;j++){
      bool flag=true;
      for(int k=0;k<M;k++){
        for(int l=0;l<M;l++){
          if(B.at(k).at(l)!=A.at(i+k).at(j+l)){
            flag=false;
          }
        }
      }
      if(flag){
        cout<<"Yes"<<endl;
        flag2=false;
        break;
      }
    }
  }
  if(flag2==true){
    cout<<"No"<<endl;
  }
}

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

public class Main {
	public static void main(String args[]) throws IOException {
		// 2020/2/3 No.149
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		System.out.println(str[1] + str[0]);
	}
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
const int MOD = 1000000007;
const int BUF = 2000005;


int factorial[BUF];

int add(int a, int b) {
    return (1LL * a + b) % MOD;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int modpow(int p, int n) {
    if (n == 0) return 1;
    int t = modpow(p, n / 2);
    return n & 1 ? mul(t, mul(t, p)) : mul(t, t);
}

int inv(int v) {
    return modpow(v, MOD - 2);
}

int nCk(int n, int k) {
    return mul(factorial[n], mul(inv(factorial[k]), inv(factorial[n - k])));
}

int nHk(int n, int k) {
    return nCk(n + k - 1, k);
}


int K;
int sLeng;

void read() {
    string dummy;
    cin >> K >> dummy;
    sLeng = dummy.size();
}


void work() {
    int ans = 0;
    for (int i = 0; i <= K; ++i) {
        ans = add(ans, mul(nHk(sLeng, i), mul(modpow(25, i), modpow(26, K - i))));
    }
    cout << ans << endl;
}


int main() {
    factorial[0] = 1;
    for (int i = 1; i < BUF; ++i) {
        factorial[i] = mul(i, factorial[i - 1]);
    }
    
    read();
    work();
    
    return 0;
}


Measured memory_bytes: 13136
S = list(input())
N = len(S)

K = N // 2

if N % 2 == 0:
    if S[K - 1] == S[K]:
        tmp = S[K - 1]
    else:
        print (K)
        exit()
    i = 0
    while i < K and S[K - 1 - i] == S[K + i] == tmp:
        i += 1
    print (K + i)
else:
    tmp = S[K]
    i = 1
    while i <= K and S[K - i] == S[K + i] == tmp:
        i += 1
    print (K + i)

Measured memory_bytes: 3956
#include<iostream>
using namespace std;
int main() {
    int n, ac=0, wa=0, tle=0, re=0;
    string str;
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> str;
        if (str == "AC") ac += 1;
        else if (str == "WA") wa += 1;
        else if (str == "TLE") tle += 1;
        else if (str == "RE") re += 1;
    }
    cout << "AC x " << ac << endl << "WA x " << wa << endl << "TLE x " << tle << endl << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
const int mod=998244353;
int fac[8010],ifac[1<<14],f[1<<14],g[8010];
int pw(int a,int n=mod-2){int b=1;for(;n;n>>=1)n&1?b=1ll*b*a%mod:1,a=1ll*a*a%mod;return b;}
int C(int n,int m){return m<0||m>n?0:1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
int ws[1<<14];
void dft(int*a,int n,bool r=0){
	int*w=ws+n/2;
	*w=1;w[1]=pw(3,(mod-1)/n);
	if(r)w[1]=pw(w[1]);
	for(int i=2;i<n/2;i++)w[i]=1ll*w[i-1]*w[1]%mod;
	for(int i=n/2;--i;)ws[i]=ws[i*2];
	w=ws+1;
	for(int i=0,j=0,t;i<n;i++){
		if(i<j)t=a[i],a[i]=a[j],a[j]=t;
		for(t=n/2;(j^=t)<t;t/=2);
	}
	for(int i=1;i<n;w+=i,i*=2){
		for(int j=0;j<n;j+=i*2){
			for(int k=0,t;k<i;k++){
				t=1ll*a[i+j+k]*w[k]%mod;
				a[i+j+k]=(a[j+k]+mod-t)%mod;
				a[j+k]=(a[j+k]+t)%mod;
			}
		}
	}
	if(r){
		long long I=pw(n);
		for(int i=0;i<n;i++)a[i]=a[i]*I%mod;
	}
}
int main(){
	int N,M;scanf("%d%d",&N,&M);
	for(int i=*fac=1;i<=N+2;i++)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[N]=pw(fac[N+2]);
	for(int i=N;i>1;i--)ifac[i-1]=ifac[i]*(i+2ll)%mod;
	int n=1;while(n<=N*2)n*=2;
	dft(ifac,n);
	*f=1;
	for(int i=0;i<M;i++){
		for(int j=0;j<=N;j++)g[j]=f[j]*(j*(j+1)/2+1ll)%mod;
		dft(f,n);
		for(int j=0;j<n;j++)f[j]=1ll*f[j]*ifac[j]%mod;
		dft(f,n,1);
		for(int j=0;j<n;j++)f[j]=j>N?0:(f[j]*((j+2)*(j+1ll))+g[j])%mod;
	}
	int s=0;
	for(int i=0,w=1;i<=N;i++,w=w*(N-i+1ll)%mod)s=(s+1ll*w*f[i])%mod;
	printf("%d\n",s);
}

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

int main() {
  uint64_t n, k;
  std::cin >> n >> k;

  std::vector<uint64_t> h(n);
  for (auto &i : h) {
    std::cin >> i;
  }
  std::sort(h.begin(), h.end());

  uint64_t dif = 1e10;
  for (uint64_t i = 0; i + k - 1 < n; i++) {
    dif = std::min(dif, h[i + k - 1] - h[i]);
  }
  std::cout << dif << std::endl;
  return 0;
}


Measured memory_bytes: 1024
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll MOD=1e9+7;

int main(){
  int n;
  cin>>n;
  
  vector<int> A(n);
  rep(i,n) cin>>A[i];
  
  int x=0,y=0,z=0;
  
  ll ans=1;
  rep(i,n){
    if(A[i]==x && A[i]==y && A[i]==z){
      ans=ans*3%MOD;
      x++;
    }
    else if(A[i]==x && A[i]==y){
      ans=ans*2%MOD;
      x++;
    }
    else if(A[i]==x && A[i]==z){
      ans=ans*2%MOD;
      x++;
    }
    else if(A[i]==y && A[i]==z){
      ans=ans*2%MOD;
      y++;
    }
    else if(A[i]==x) x++;
    else if(A[i]==y) y++;
    else if(A[i]==z) z++;
    else{
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3768
package main

import (
	"fmt"
	"sort"
)

func getReverse(s string) (t string) {
	for _, r := range s {
		t = string(r) + t
	}
	return t
}

func getSorted(s string) (t string) {
	ss := make([]string, len(s))
	for i, r := range s {
		ss[i] = string(r)
	}
	sort.Strings(ss)
	for i := 0; i < len(s); i++ {
		t += ss[i]
	}
	return
}

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	if getSorted(s) < getReverse(getSorted(t)) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

D = []

for i in range(N):
   D.append(input().split())

def judge(L):
   if L[0] == L[1]:
      return True
   else:
      return False

for i in range(N - 2):
   if judge(D[i]) and judge(D[i+1]) and judge(D[i+2]):
      print('Yes')
      exit()

print('No')

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
    int n,m,all=0;
    cin >> n >> m;
    vector <int> v(n);
    rep(i,n) {
        cin >> v[i];
        all+=v[i];
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int count=0;
    rep(i,n){
        if(4*m*v[i]<all){
            break;
        }
        count++;
    }
    if(count>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   runtime_error.c                                    :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: mkosaka <42tokyo_jan2020_pisciner>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/05 14:22:59 by mkosaka           #+#    #+#             */
/*   Updated: 2020/02/05 14:22:59 by mkosaka          ###   ########.jp       */
/*                                                                            */
/* ************************************************************************** */

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

void init_chars(char *chars, int size)
{
	int i;

	i = 0;
	while (i < size)
	{
		chars[i] = '\0';
		i++;
	}
}

char grade_tests(int *scores)
{
	if (scores[0] == -1 || scores[1] == -1 || scores[0] + scores[1] < 30)
		return ('F');
	else if (scores[0] + scores[1] >= 80)
		return ('A');
	else if (scores[0] + scores[1] >= 65)
		return ('B');
	else if (scores[0] + scores[1] >= 50)
		return ('C');
	else if ((scores[0] + scores[1] >= 30) && (scores[2] >= 50))
		return ('C');
	return ('D');
}

int  main(void)
{
	int scores[3];
	char data_set[51];
	int i;

	init_chars(data_set, 51);
	scores[0] = 0;
	scores[1] = 0;
	scores[2] = 0;
	i = 0;
	while (i < 50)
	{
		scanf("%d %d %d", &scores[0], &scores[1], &scores[2]);
		if (scores[0] == -1 && scores[1] == -1 && scores[2] == -1)
			break;
		data_set[i] = grade_tests(scores);
		i++;
	}
	i = 0;
	while (data_set[i])
		printf("%c\n", data_set[i++]);
	return (0);
}



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

using namespace std;

struct node {
    int a, b, c;
    void read() {
        scanf("%d%d%d", &a, &b, &c);
    }
    bool operator < (const node &rhs) const {
        return a - b < rhs.a - rhs.b;
    }
} p[100005];

long long lv[100005], rv[100005];

priority_queue <int, vector <int>, greater <int> > Q;

int main() {
    int X, Y, Z;
    scanf("%d%d%d", &X, &Y, &Z);
    int n = X + Y + Z;
    for (int i = 0; i < n; ++i)
        p[i].read();
    sort(p, p + n);
    int L = Y - 1, R = n - X;
    long long s1 = 0, s2 = 0;
    for (int i = 0; i <= L; ++i) {
        s1 += p[i].c;
        s2 += p[i].b - p[i].c;
        Q.push(p[i].b - p[i].c);
    }
    lv[L] = s1 + s2;
    for (int i = L + 1; i < R; ++i) {
        s1 += p[i].c;
        s2 += p[i].b - p[i].c;
        Q.push(p[i].b - p[i].c);
        s2 -= Q.top();
        Q.pop();
        lv[i] = s1 + s2;
    }
    s1 = s2 = 0;
    while (Q.size())
        Q.pop();
    for (int i = n - 1; i >= R; --i) {
        s1 += p[i].c;
        s2 += p[i].a - p[i].c;
        Q.push(p[i].a - p[i].c);
    }
    rv[R] = s1 + s2;
    for (int i = R - 1; i > L; --i) {
        s1 += p[i].c;
        s2 += p[i].a - p[i].c;
        Q.push(p[i].a - p[i].c);
        s2 -= Q.top();
        Q.pop();
        rv[i] = s1 + s2;
    }
    long long ans = 0;
    for (int i = L; i < R; ++i)
        ans = max(ans, lv[i] + rv[i + 1]);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2688
import java.util.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);

        int cnt = 0;


        String s1 = sc.next();
        String str = s1.replaceAll(",", " ");

        System.out.print(str);
        System.out.println();
    }

}

Measured memory_bytes: 10196