akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    int n, a, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        while (a > 0) {
            if (a % 2 == 0) {
                ans++;
                a /= 2;
            }
            else break;
        }
    }
    cout << ans << endl;
}
    

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
        # undirected graph
        init_adj_table[v_to].append(v_from)
    return init_adj_table


def graph_dfs(current, prev):
    global timer
    pre_v[current] = lowest_v[current] = timer
    timer += 1

    color[current] = VISITED_IN_STACK
    for adj in adj_table[current]:
        if color[adj] is UNVISITED:
            parent_v[adj] = current
            # recursive dfs
            graph_dfs(adj, current)
            lowest_v[current] = min(lowest_v[current], lowest_v[adj])
        elif adj is not prev:
            lowest_v[current] = min(lowest_v[current], pre_v[adj])

    return None


def art_points():
    graph_dfs(dfs_root, -1)

    np = 0
    for v in range(1, vertices):
        parent = parent_v[v]
        if parent is dfs_root:
            np += 1
        elif pre_v[parent] <= lowest_v[v]:
            art_set.add(parent)

    if np > 1:
        art_set.add(dfs_root)

    return art_set


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])
    pre_v, parent_v, lowest_v = ([float('inf')] * vertices for _ in range(3))
    init_adj_table = tuple([] for _ in range(vertices))

    timer = 1
    # root
    dfs_root = 0

    art_set = set()
    color = [UNVISITED] * vertices

    adj_table = generate_adj_table(v_info)

    res = art_points()
    # print('parent', parent_v, 'preorder', pre_v, 'postorder', lowest_v)
    if not res:
        pass
    else:
        print(*sorted(res), sep='\n')

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


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);

 
    int a,b;
    cin>>a>>b;
    for(int i=0;i<=a;i++)
    {
      int left=a-i;
      if(b==(left*2+i*4))
      {
        cout<<"Yes"<<endl;
        return 0;
      }
    }

    cout<<"No"<<endl;
  return 0;

}

Measured memory_bytes: 3652
#include<stdio.h>

int main(){
  char num[1000];
  int sum,i,j;

  while(1){
  for(i = 0; ;i++){
    scanf("%c",&num[i]);
    if(num[i]=='\n')break;
  }
  sum = 0;
  for(j = 0; j < i; j++){
    sum += num[j] - '0';
  }
  if(sum==0)break;
  printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 536
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = S()
    sa = []
    for c in s:
        if c == 'D':
            sa.append(1)
        elif c == 'M':
            sa.append(2)
        elif c == 'C':
            sa.append(3)
        else:
            sa.append(None)
    q = I()
    kk = LI()
    rr = []
    for k in kk:
        a = 0
        b = 0
        t = 0
        r = 0
        for j in range(k):
            if sa[j] is None:
                continue
            if sa[j] == 3:
                r += t
            elif sa[j] == 2:
                t += a
                b += 1
            else:
                a += 1
        for j in range(k,n):
            if sa[j-k] == 1:
                t -= b
                a -= 1
            elif sa[j-k] == 2:
                b -= 1

            if sa[j] is None:
                continue
            if sa[j] == 3:
                r += t
            elif sa[j] == 2:
                t += a
                b += 1
            else:
                a += 1

        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())


Measured memory_bytes: 117896
#include <bits/stdc++.h>
using namespace std;
int N;
int Cnt[100000 + 100];
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i)
	{
		int x;
		scanf("%d", &x);
		++ Cnt[x-1];
		++ Cnt[x];
		++ Cnt[x+1];
	}
	int Ans = 0;
	for (int i = 1; i <= 100000; ++i)
		Ans = max(Ans, Cnt[i]);
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static Scanner scan;

    private static void start() {
        scan = new Scanner(java.lang.System.in);
    }

    private static void finish() {
    }

    static class T {
        long x;
        long s;

        public T(long x, long s) {
            this.x = x;
            this.s = s;
        }
    }

    public static void main(String[] args) {
        start();

        int n = scan.nextInt();
        List<T> li = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            li.add(new T(scan.nextLong(), scan.nextLong()));
        }
        li.sort((o1, o2) -> {
            if (o1.x == o2.x) return 0;
            return (o1.x < o2.x) ? -1 : 1;
        });

        long maxProfit = 0;
        long currProfit = 0;
        long l = 0;
        for (int i = 0; i < n; i++) {
            if (currProfit + li.get(i).s - (li.get(i).x - l) < li.get(i).s) {
                l = li.get(i).x;
                currProfit = li.get(i).s;
            } else {
                currProfit = currProfit + li.get(i).s - (li.get(i).x - l);
                l = li.get(i).x;
            }
//            System.out.println(currProfit + " *");
            maxProfit = Math.max(maxProfit, currProfit);
        }
        System.out.println(maxProfit);
        finish();
    }
}


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

int mod = pow(10,9) + 7;


int inv(int n){
	int e= pow(10,9) + 5;
  	int64_t p=n;
  	int64_t ans=1;
  
  	while(e>0){
    	if(e%2==0){
        	p*=p;
          	p%=mod;
          	e/=2;
        }
      	else{
        	ans*=p;
          	ans%=mod;
          	e--;
        }
    }
  	return ans%mod;
}

int main(){
	int H,W,A,B;
  	cin >> H >> W >> A >> B;
  	vector<int64_t> fact(H+W-1);
  	fact.at(0) =1;
  	fact.at(1) = 1;
  	for(int i=2; i<=H+W-2; i++){
    	fact.at(i) = (i * fact.at(i-1))%mod;
    }
  	vector<int64_t> invfact(H+W-1);
  	invfact.at(0) = 1;
  	invfact.at(1) =1;
  	for(int i=2; i<=H+W-2;i++){
    	invfact.at(i) = inv(fact.at(i));
    }
  	

	  	
  	int64_t ans=0;
  	for(int i=0;i<W-B ;i++ ){
      	int64_t ret=1LL;
    	
        
        ret*=fact.at(H-A+B+i-1);
      	
        ret*=invfact.at(H-A-1);
      	ret%=mod;
      	ret*=invfact.at(B+i);
      	ret%=mod;
      	ret*=fact.at(A-B+W-2-i);
      	ret%=mod;
      	ret*=invfact.at(A-1);
      	ret%=mod;
      	ret*=invfact.at(W-B-i-1);
      	ret%=mod;
      	ans+=ret;
      	ans%=mod;
        
         
    }
  	cout << ans << endl;
  
}


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

typedef pair<ll, ll> P;
P p[200000];

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

	int N;
	cin >> N;

	multiset<ll> B, R;
	for(int i = 0; i < N; i++) {
		ll X, Y;
		cin >> X >> Y;
		if(X > Y) swap(X, Y);
		p[i] = { X, Y };
		B.insert(X);
		R.insert(Y);
	}
	sort(p, p + N);

	ll Rmax = *R.rbegin(), Rmin = *R.begin(), Bmax = *B.rbegin(), Bmin = *B.begin();
	ll ans = (Rmax - Rmin) * (Bmax - Bmin);

	for(int i = 0; i < N - 1; i++) {
		ll X = p[i].first, Y = p[i].second;
		B.erase(B.find(X));
		B.insert(Y);
		R.erase(R.find(Y));
		R.insert(X);
		Rmax = *R.rbegin(), Rmin = *R.begin(), Bmax = *B.rbegin(), Bmin = *B.begin();

		ans = min(ans, (Rmax - Rmin) * (Bmax - Bmin));
	}

	cout << ans << endl;
}

Measured memory_bytes: 24192
#include <iostream>
#include <cstdio>

using namespace std;

#define LL unsigned long long
#define RI register int
#define pr(x) cout<<#x<<" = "<<x<<endl;
#define p(x) cout<<x<<endl;
#define SP <<"   "<<

int n,m;

int main()
{
	string s;
	cin>>s;
	int l=s.length() ;
	bool c=0;
	for(RI i=0;i<l;i++)
	{
		if(s[i]=='C')	c=1;
		if(s[i]=='F'&&c)	
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) {
  for (auto &e : vec) cout << e << " \n"[&e==&vec.back()];
}

template <class T>
void OUTS(vector<vector<T>> &df) {
  for (auto &vec : df) OUTS(vec);
}

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) {
  for (auto &e : vec) cout << e << "\n";
}

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  VAR(int, R);
  if (R < 1200) OUTL("ABC");
  else if (R < 2800) OUTL("ARC");
  else OUTL("AGC");
  return 0;
}


Measured memory_bytes: 256
// x < y
//   x < 0 && y < 0 || x > 0 && y > 0 : y-x
//   x < 0 && y > 0
//      |x| < |y| : y+x+1
//      |y| < |x| : -y-x+1
// y < x
//   y < 0 && x < 0 : +2
//   y > 0 && x > 0 : +2
//   y < 0 && x > 0
//      |x| < |y| : +1
//      |y| < |x| : +1

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int A = Math.abs(Math.abs(x)-Math.abs(y));
    int B = 0;
    if (x <= y) {
      B = (long)x*y >= 0 ? 0 : 1;
    } else {
      B = (long)x*y > 0 ? 2 : 1;
    }
    System.out.println(A+B);
  }
}

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

using namespace std;

int main() {
	int n, r;
	cin >> n >> r;
	if (n <= 10) {
		cout << r + (10 - n) * 100 << endl;
	}
	else {
		cout << r << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll l;
    cin>>l;
    ll n = 0;
    while(pow(2,n)<=l){
        n++;
    }
    n--;
    ll m = 0;
    vector<vector<Pi>> g(n);
    rep(i,n){
        g[i].emplace_back(i+1,0);
        g[i].emplace_back(i+1,1<<i);
        m += 2;
    }
    int cur = 1<<(n);
    per(i,n-1){
        if(l & 1<<i){
            g[i].emplace_back(n,cur);
            cur += 1<<i;
            m++;
        }
    }

    cout<<n+1<<" "<<m<<endl;
    rep(i,g.size()){
        Each(elm,g[i]){
            cout<<i+1<<" "<<elm.fi+1<<" "<<elm.se<<endl;
        }
    }
    return  0;
}


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

int A,B,C,X;
int res = 0;

int main() {

  cin >> A >> B >> C >> X;

  for(int a = 0; a <= A; ++a) {
    for(int b = 0; b <= B; ++b) {
      for(int c = 0; c <= C; ++c) {
        if(500*a + 100*b + 50*c == X) ++res;
      }
    }
  }
  cout << res << endl;
}


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

data = {}

for i in range(N):
    inputs = input().split()
    data[int(inputs[0])] = int(inputs[1])

sort_key = sorted(data)
ans = 0

for i in range(len(sort_key)):
    if i == 0 and sort_key[0] != 1:
        ans += sort_key[0] - 1
    if i < len(sort_key) - 1:
        ans += min(sort_key[i + 1] - sort_key[i] - 1, data[sort_key[i]] - data[sort_key[i + 1]] - 1)
    if i == len(sort_key) - 1 and data[sort_key[i]] != 0:
        ans += data[sort_key[i]]


print(ans + len(sort_key))

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

int main(){
  int N; cin >> N;
  int pos = 1;
  int cnt = 0;
  bool flag = false;
  for(int i = 0; i < N; i++){ 
    int a; cin >> a;
    if( a == pos ){ pos++; cnt++; flag = true;}
  }
if(flag){
  cout << N-cnt << endl;
  
}
  else{
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main() {
    int n, m;
    cin >> n >> m;

    UnionFind tree(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree.merge(a, b);
    }
    ll ans = 0;
    rep(i, n) ans = max(ans, tree.size(i));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6352
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M;cin>>N>>M;
  vector<string> A(N);
  repeat(i,N)cin>>A[i];
  vector<string> B(M);
  repeat(i,M)cin>>B[i];
  bool contain=false;
  repeat(i,N-M+1){
    repeat(j,N-M+1){
      bool isok=true;
      repeat(ii,M){
        repeat(jj,M){
          isok &= B[ii][jj]==A[i+ii][j+jj];
        }
      }
      contain |= isok;
    }
  }
  cout<<(contain? "Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N;
    static int M;
    static Edge[] edges;
    static long[] d;
    static long INF = Long.MAX_VALUE;
    static boolean[] negative;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        M = scanner.nextInt();

        negative = new boolean[N];
        Arrays.fill(negative, false);

        edges = new Edge[M];
        for(int i = 0; i < M; i++) {
            int from = scanner.nextInt() - 1;
            int to = scanner.nextInt() - 1;
            long cost = -scanner.nextLong();
            Edge e = new Edge(from, to, cost);
            edges[i] = e;
        }

        d = new long[N];
        Arrays.fill(d, INF);

        scanner.close();
    }

    private static void bellmanFord(int s) {
        d[s] = 0;
        for(int i = 0; i < N; i++) {
            boolean update = false;
            for(int j = 0; j < M; j++) {
                Edge e = edges[j];
                if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]) {
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                }

            }
            if(!update) break;
        }

        for(int i = 0; i < N; i++) {
            boolean update = false;
            for(int j = 0; j < M; j++) {
                Edge e = edges[j];
                if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]) {
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                    negative[e.to] = true;
                }
                if(negative[e.from]) {
                    negative[e.to] = true;
                }
            }
            if(!update) break;
        }
    }

    public static void main(String args[]) {
        init();
        bellmanFord(0);
        long ans = -d[N - 1];

        if(!negative[N - 1]) {
            System.out.println(ans);
        } else {
            System.out.println("inf");
        }
    }
}

class Edge {
    int from;
    int to;
    long cost;

    public Edge(int from, int to, long cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }
}

Measured memory_bytes: 30124
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(void){
    double x1,x2,y1,y2;
    cin>>x1>>x2>>y1>>y2;
    
    //cout<<sqrt(pow(x1-y1,2)+pow(x2-y2,2))<<endl;
    printf("%.7lf",sqrt(pow(x1-y1,2)+pow(x2-y2,2)));

    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;

int main(){
    int N, M;
    cin >> N >> M;
    VVI s(M);
    REP(i,M){
        int ktemp;
        cin >> ktemp;
        VI stemp(ktemp);
        REP(j,ktemp){
            cin >> stemp[j];
            stemp[j]--;
        }
        s[i] = stemp;
    }
    VI p(M);
    REP(i,M){
        cin >> p[i];
    }
    int cnt = 0;
    bool chk;
    REP(bit, (1<<N)){
        chk = true;
        REP(i, M){
            int temp = 0;
            int sz = s[i].size();
            REP(j, sz){
                if (bit & (1<<s[i][j])) temp++;
            }
            if (temp % 2 != p[i]){
                chk = false;
                break;
            }
        }
        if (chk) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

bool cmp(pair<ll,ll> a,pair<ll,ll> b){
    return a.first+a.second<b.first+b.second;
}

// dp:index iまででj枚つむ最小の高さ
ll dp[5010][5010];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    rep(i,5010)rep(j,5010) dp[i][j]=LINF;

    int n;cin>>n;
    vector<pair<ll,ll>> v(n+1);
    rep(i,n){
        ll h,p;cin>>h>>p;
        v[i+1]=make_pair(h,p);
    }
    sort(ALL(v),cmp);

    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        dp[i][0]=0;
        for(int j=1;j<=n;j++){
            dp[i][j]=dp[i-1][j];
            if(dp[i-1][j-1]<=v[i].first) chmin(dp[i][j],dp[i-1][j-1]+v[i].second);
        }
    }
    // rep(i,n+1){
    //     rep(j,n+1){
    //         if(dp[i][j]>=LINF) cout<<"inf ";
    //         else cout<<dp[i][j]<<"   ";
    //     }
    //     cout<<endl;
    // }

    for(int i=n;i>=0;i--){
        if(dp[n][i]<LINF){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 196480
#include <iostream>
#include <algorithm>
#include <numeric>
#define ll long long
#define println(S) (cout << S << endl)
using namespace std;

ll gcd(ll x, ll y)
{
    ll r;

    // ユーグリッドの互除法
    while((r = x % y) != 0)  // yで割り切れるまでループ
    {
        x = y;
        y = r;
    }
    return y;
}

int main() {
	ll N;
	cin >> N;
	int x[N+1];
	for (int i = 0; i <= N; ++i) {
		cin >> x[i];
	}
	sort(x,x+N+1);
	ll g,df;
	g = x[1]-x[0];
	for (int i = 0; i < N; ++i) {
		df = x[i+1]-x[i];
		if(df==0) continue;
		g = gcd(df,g);
	}
	println(g);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<string> sv;
    rep(i,n) {
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        sv.push_back(s);
    }
    sort(sv.begin(),sv.end());
    ll ans = 0;
    int se = 1;
    
    rep(i,n){
        if(!i) continue;
        if(sv[i]==sv[i-1]) se++;
        if(sv[i]!=sv[i-1]||i==n-1){
            ans += (ll)se*(se-1)/2;
            se = 1;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int ll
#define endl "\n"
#define all( x ) x.begin(), x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef unsigned long long ull;

const int inf = 1e9 + 5;
const long double PI = 3.141592653589793;

string alphabet = "abcdefghijklmnopqrstuvwxyz";

void solve(){
  int n, x;
  cin >> n;
  //vector<int> a(n);
  map<int, int> mp;
  int sum = 0;
  for(int  i = 0; i<n; ++i){
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while(q--){
    int b, c;
    cin >> b >> c;
    if(mp.count(b) == 1){
      sum = sum + (c - b) * mp[b];
      mp[c] += mp[b];
      mp.erase(b);
    }
    cout << sum <<endl;
  }
}  
signed main(){
  fast;
  int t;
  t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 7556
#include <stdio.h>
#include <cassert>
#include <algorithm>

typedef long long int LL;

int main() {
  LL n;
  scanf("%lld", &n);

  // 街のモンスター数
  LL *a = new LL[n+1];
  for(LL i=0; i<n+1; i++){
    scanf("%lld", &a[i]);
  }

  // 倒せる数
  LL *b = new LL[n];
  for(LL i=0; i<n; i++){
    scanf("%lld", &b[i]);
  }

  LL count = 0;

  for(LL i=0; i<n; i++){
    if(b[i] <= a[i]) {
      count += b[i];
      a[i] -= b[i];
      b[i] = 0;
    } else {
      count += a[i];
      b[i] -= a[i];
      a[i] = 0;

      if(b[i] <= a[i+1]) {
        count += b[i];
        a[i+1] -= b[i];
        b[i] = 0;
      } else {
        count += a[i+1];
        b[i] -= a[i+1];
        a[i+1] = 0;
      }
    }
  }

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

  delete [] a;
  delete [] b;

  return 0;
}

Measured memory_bytes: 1792
import java.util.*;

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

        String[] s = sc.next().split("");
        String[] t = sc.next().split("");

        int count = 0;

        for (int i = 0; i < 3; i++) {
            if (s[i].equals(t[i])) {
                count++;
            }
        }

        System.out.println(count);
    }
}

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

int main(){
  int N; cin >> N;
  int H,W; cin >> H >> W;
  int count=0;
  int A,B;
  for(int i=0; i<N; i++){
    cin >> A >> B;
    if(A>=H&&B>=W) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    int div2min = 0;
    for (int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        for (int j = 0; ; j++) {
            if (ai % 2 == 0) {
                ai /= 2;
            } else if (i == 0) {
                div2min = j;
                break;
            } else {
                div2min = min(div2min, j);
                break;
            }
        }
    }

    cout << div2min << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static int sumUp(int[] a ){
		int sum = 0;
		for(int i = 0; i < a.length; i++){
			sum += a[i];
		}
		return sum;
	}
	
	public static int max(int a, int b){
		return ( a > b ) ? a : b;
	}
	
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int[] a = new int[4];
		int[] b = new int[4];
		
		for(int i = 0; i < 4; i++){
			a[i] = stdIn.nextInt();
		}
		for(int i = 0; i < 4; i++){
			b[i] = stdIn.nextInt();
		}
		
		System.out.println(max(sumUp(a), sumUp(b)));
	}
}

Measured memory_bytes: 11000
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int a, b, ans;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b;
    ans = max(ans, a + a - 1);
    ans = max(ans, b + b - 1);
    ans = max(ans, a + b);
    cout << ans << "\n";
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a==b)
{
  cout<<"a == b"<<endl;
}
else if(a<b)
{
  cout<<"a < b"<<endl;
}else{
  cout<<"a > b"<<endl;
}
return 0;
}



Measured memory_bytes: 3088
$line = <STDIN>;
chomp $line;
$N=scalar($line);
$line = <STDIN>;
chomp $line;
$S=$line;

$mm=0;$mi=-1;$m=0;

for($i=0;$i<$N;$i++){
	$k=substr($S,$i,1);
	$ri=rindex($S,$k,$i-1);
	$li=index($S,$k,$i+1);
	if ($li>=0) {
		if($ri>=0) {
			#no change
		} else {
			$m+=1;
			if($mm<$m) {
				$mm=$m;
				$mi=$i;
			}
		}
	} else {
		if($ri>=0) {
			$m-=1;
		} else {
			#no change
		}
	}
}

print "$mm\n";


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

int main(){
  int a,b,i,j,c=0;
  string s,k;
  cin>>s>>k;
  sort(s.begin(),s.end());
  sort(k.begin(),k.end());
  reverse(k.begin(),k.end());
  if(s<k){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{input, marker::Chars};

fn main() {
    input! {
        n: usize,
        a: isize,
        b: isize,
        c: isize,
        ss: [String; n],
    }

    let mut pattern = vec![];

    let mut abc = vec![a, b, c];
    let sum = a + b + c;

    if sum == 0 {
        println!("No");
        return;
    }

    fn run(large: usize, small: usize, abc: &mut Vec<isize>, pattern: &mut Vec<String>) {
        abc[large] -= 1;
        abc[small] += 1;
        let st = match small {
            0 => "A",
            1 => "B",
            _ => "C",
        };
        pattern.push(st.to_string());
    }

    fn phase(
        pattern: &mut Vec<String>,
        abc: &mut Vec<isize>,
        ope: &str,
        next_ope: Option<&String>,
    ) {
        let (one, another, _theother) = match ope {
            "AB" => (0, 1, 2),
            "BC" => (1, 2, 0),
            _ => (2, 0, 1), // "AC"
        };

        if abc[one] == 0 || abc[another] == 0 {
            if abc[one] > abc[another] {
                run(one, another, abc, pattern);
            } else {
                run(another, one, abc, pattern);
            }
            return;
        }

        if let Some(n) = next_ope {
            // 先読み
            if n == "AB" {
                if one == 1 {
                    // 今が BC で次が AB なら B に 1 足す
                    run(another, one, abc, pattern);
                } else {
                    // 今が AC, AB で次が AB なら A に 1 足す
                    run(one, another, abc, pattern);
                }
            } else if n == "BC" {
                if one == 2 {
                    run(another, one, abc, pattern);
                } else {
                    run(one, another, abc, pattern);
                }
            } else {
                // "AC"
                if one == 0 {
                    run(another, one, abc, pattern);
                } else {
                    run(one, another, abc, pattern);
                }
            }

            return;
        }

        // どちらでも同じ
        run(one, another, abc, pattern);
    }

    for i in 0..n {
        phase(&mut pattern, &mut abc, &ss[i], ss.get(i + 1));

        if abc[0] < 0 || abc[1] < 0 || abc[2] < 0 {
            println!("No");
            return;
        }
    }

    println!("Yes");
    for e in &pattern {
        println!("{}", e);
    }
}


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

L = list(map(int, input().split()))

s=0
for i in range(0,N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i] and L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[j]+L[i]:
                s+=1

print(s)























Measured memory_bytes: 9192
N = int(input())
A, S = [0] * (N+1), [0] * (N+1)
a = list(map(int, input().split()))
for i in range(N):
    A[i+1] = A[i] ^ a[i]
    S[i+1] = S[i] + a[i]
ans = 0
l = 1
for r in range(1, N+1):
    while (S[r]-S[l-1]) != (A[r]^A[l-1]):
        l += 1
    ans += r-l+1
print(ans)



Measured memory_bytes: 28392
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P deque(){
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b){return a < b? a:b;}

int main(){
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);

	for (i = 1; i <= n; i++){
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1; tail = n + 1;

	while (head != tail ) {
		u = deque();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if (u.t > 0) enqueue(u);
		else{
			printf("%s %d\n", u.name, elaps);
		}
	}
	return 0;

}

Measured memory_bytes: 12740
#include<stdio.h>
int main()
{
    int a,b,c;
    char s[101];
    // 整数の入力
    scanf("%d", &a);
    
    if(a == 25) {
        printf("Christmas\n");
    }else if(a==24) {
        printf("Christmas  Eve\n");

    }else if(a==23) {
        printf("Christmas  Eve  Eve\n");    
    
    } else {
        printf("Christmas  Eve  Eve Eve\n");    
    
    }


    // 出力
    //printf("%d %s\n",a+b+c,s);
    return 0;
}

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

  ll a,b,x;
  cin >> a >> b >> x ;
  ll l = a/x;
  ll r = b/x ;

   if (a % x == 0)
     cout << ((b / x) - (a / x) + 1) << endl;

    else
    cout << ( (b / x) - (a / x) ) << endl ;





  }


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
main(){
    fastio;
	int n;
	cin >> n;
	vector<pii> v(n);
	for(int i=0;i<n;i++) cin >> v[i].ss >> v[i].ff;
	sort(td(v));
	int t = 0;
	for(int i=0;i<n;i++){
		t += v[i].ss;
		if(t > v[i].ff){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main (){
    int d,n;
    cin>>d>>n;
    if(d==0){
		if(n!=100){
			cout<<n<<endl;
		}
		else{
			cout<<"101"<<endl;
		}
	}
	else if(d==1){
		if(n!=100){
			cout<<n*100<<endl;
		}
		else{
			cout<<"10100"<<endl;
		}
	}
	else{
		if(n!=100){
			cout<<n*10000<<endl;
		}
		else{
			cout<<"1010000"<<endl;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int n;
char c[200][200];
const int dy[16] = { 0,-1, 0, 1, 1,-1, 1,-1, 0,-2, 0, 2};
const int dx[16] = { 1, 0,-1, 0, 1, 1,-1,-1, 2, 0,-2, 0};

void dfs(int x, int y){
	if(c[y][x] == 'o'){
		c[y][x] = 'x';
		rep(i,4){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(ny < 0 || ny >= n || nx < 0 || nx >= n) continue;
			dfs(nx, ny);
		}
	}
}

int main(){
	cin >> n;

	rep(i,n){
		rep(j,n){
			cin >> c[i][j];
		}
	}

	int cnt = 0;
	rep(i,n){
		rep(j,n){
			if(c[i][j] == 'o'){
				cnt++;
				dfs(j, i);
			}
		}
	}
	//show(cnt)
	cout << cnt / 3 << endl;
}

Measured memory_bytes: 3120
n = int(input())
a = list(map(int, input().split()))
a.sort()

i = 0
while True:
    x = a[i+1] % a[i]
    if x < a[i]:
        a[i+1] = a[i]
        a[i] = x
        if a[i] == 0:
            i += 1
            if i == n-1:
                break
    else:
        break
print(a[i])


Measured memory_bytes: 20132
n, m = input().split()
a = input().split()
vote = 0
cnt = 0

for i in range( len(a) ):
    vote += int( a[i] )

for i in range( len(a) ):
    if int( a[i] ) >= vote / ( 4 * int( m ) ):
        cnt += 1

if cnt >= int( m ):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;

#define _CRT_SECURE_NO_WARNINGS
int N;
int c[4][4];
int main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3;j++) {
			scanf("%d", &c[i][j]);
		}
	}
	bool f = true;
	for (int i = 0; i < 3;i++) {
		for (int j = 0; j < 2;j++) {
			for (int k = i + 1; k < 3; k++) {
				if (c[i][j + 1] - c[i][j] != c[k][j + 1] - c[k][j]) {
					f = false;
				}
			}
		}
	}

		if (f) {
			printf("Yes");
		}
		else {
			printf("No");
		}
	
	return 0;
}

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


int main(){
    long long N, K, min, temp;
    
    cin >> N >> K;

    if(N == 0){
        cout << 0;
        return 0;
    }

    if( N >= K)
    {
        min = N % K;
        min = ( K-min < min)?K-min:min;
    }else{
        min = ( K-N < N)?K-N:N;
    }

    cout << min << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long

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

Measured memory_bytes: 256
S = input().strip()
mod = 10**9 + 7
d = {i:i*10%13 for i in range(13)}
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1
for i, c in enumerate(S, 1):
    if c != '?':
        c = int(c)
        for j in range(13):
            dp[i][(d[j] + c) % 13] = dp[i-1][j] % mod
    else:
        for c in range(10):
            for j in range(13):
                k = (d[j] + c) % 13
                dp[i][k] = (dp[i][k] + dp[i-1][j]) % mod
print(dp[-1][5])

Measured memory_bytes: 61916
n,m=map(int,input().split())
li=[]
for i in range(m):
    a=list(map(int,input().split()))
    li.append(a)
l=0
r=n
for i in range(m):
    if li[i][0]>l:
        l=li[i][0]
    if li[i][1]<r:
        r=li[i][1]
print(max(0,r-l+1))
    

Measured memory_bytes: 27340
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 55, INF = 1e9;
const ll M = 5005, Mod = 1e9 + 7;

/*******************************************************************************
 *
 * 把每个数的贡献独立出来
 *
 * 对于一个数i，我们可以把他放在第i位前，中，后，
 * 而放在前面会造成 i + i （放在第i位的数比他小），或者是 i - i
 *              （放在第i位的数比他大）的贡献
 * 放在中没有贡献
 * 放在后面会造成 -i + i （放在第i位的数比他小），或者是 - i - i
 *              （放在第i位的比他大）的贡献
 *
 ******************************************************************************/

int n, m;
ll f[N][N][M];

int main() {
    n = read<int>(), m = read<int>();
    f[0][0][2500] = 1;
    rep (i, 0, n - 1) {
        rep (j, 0, i) rep (k, 0, 5000) {
            // 1 选一个空位放并且选一个数放自己这
            if (j > 0 && k + 2 * i <= 5000)
                (f[i + 1][j - 1][k + 2 * i] += f[i][j][k] * j * j) %= Mod;
            // 2 选一个空位放i，然后自己空出来
            (f[i + 1][j][k] += f[i][j][k] * j) %= Mod;
            // 3 放自己
            (f[i + 1][j][k] += f[i][j][k]) %= Mod;
            // 4 选一个放自己这，然后空位不变
            (f[i + 1][j][k] += f[i][j][k] * j) %= Mod;
            // 5 自己空出来
            if (k - 2 * i >= 0)
                (f[i + 1][j + 1][k - 2 * i] += f[i][j][k]) %= Mod;
        }
    }

    // 每个数都放了
    cout << f[n][0][2500 + m] << endl;
    return 0;
}



Measured memory_bytes: 108800
import java.util.*;

public class Main {
    static boolean isPrime(int x){
        if(x==2) return true;
        if(x<2 || x%2==0) return false;
        int i = 3;
        while(i<=Math.sqrt(x)){
            if(x%i == 0) return false;
            i += 2;
        }
        return true;
    }
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for(int i=0;i<n;i++){
            int x = sc.nextInt();
            if(isPrime(x)) count++;
        }
        System.out.println(count);
    }
}



Measured memory_bytes: 42192
n=int(input())
a=list(map(int,input().split()))
maxi=-1
dic={}
for i in a:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
for i in range(max(a)+1):
    maxi=max(maxi,(dic[i-1] if i-1 in dic else 0)+(dic[i] if i in dic else 0)+(dic[i+1] if i+1 in dic else 0))
print(maxi)

Measured memory_bytes: 20936
str = gets.split
N,K = str[0].to_i, str[1].to_i
a = Array.new(N)
str = gets.split
a[0] = str[0].to_i
for i in 1...N do
    a[i] = a[i-1] + str[i].to_i
end
answer = K * 0.5

max = a[K-1]
for i in K...N do
    n = a[i] - a[i-K]
    max = max < n ? n : max
end
answer += max * 0.5
puts answer

Measured memory_bytes: 14988
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int mod = 998244353;
        int N = in.i();
        int K = in.i();

        int[] LR = new int[K * 2];
        for (int i = 0; i < LR.length; ) {
            LR[i++] = in.i();
            LR[i++] = in.i();
        }

        long[] sum = new long[N + 2];
        sum[2] = 1;

        for (int i = 2; i <= N; i++) {
            long dp = 0;
            for (int j = 0; j < LR.length; ) {
                int r = i - LR[j++];
                int l = i - LR[j++];
                if (r < 1) continue;
                if (l < 1) l = 1;
                dp = (dp + sum[r + 1] - sum[l]) % mod;
            }
            sum[i + 1] = (sum[i] + dp) % mod;
        }

        out.println((sum[N + 1] - sum[N] + mod) % mod);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


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

int main(void){
    long n,ans=0;
    cin >> n;
    int a[n],b[n],c[n];
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    rep(i,n){
        long d,e;
        int ng=-1,ok=n;
        while(ok-ng>1){
            int mid = ok-(ok-ng)/2;
            if(b[i]<c[mid]) ok = mid;
            else ng = mid;
        }
        d = n-ok;
        ng = n;
        ok = -1;
        while(ng-ok>1){
            int mid = ng - (ng-ok)/2;
            if(a[mid]<b[i]) ok = mid;
            else ng = mid;
        }
        e = ok+1;
        ans += d*e;
    }
    cout << ans << endl;
}

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

using namespace std; 
 
#define int long long
#define M 1000000007 
 
signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin >> n;
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=((n-1)/i);
	}
	cout << ans << endl;
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (x / d <= k) {
        if ((k - x / d) % 2 == 0) {
            print(x % d);
        } else {
            x = (x % d) - d;
            x = abs(x);
            print(x);
        }
    } else {
        print(x - k * d);
    }
    return 0;
}


Measured memory_bytes: 3632