akhauriyash/Code-Regression huggingface dataset:
import java.awt.geom.Point2D;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

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

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

	public Main() {
		new AOJ().doIt();
	}
	class AOJ{
		void doIt(){
			int DP[][] = new int[4][4001];
			for(int i = 0;i < 1001;i++)DP[0][i] = 1;
			for(int i = 1;i < 4;i++){
				for(int j = 0;j <= 3000;j++){
					for(int k = 0;k < 1001;k++){
						DP[i][j+k] = DP[i][j+k] + DP[i-1][j];
					}
				}
			}
			while(sc.hasNext()){
				int n = sc.nextInt();
				System.out.println(DP[3][n]);
			}
		}
	}
}

Measured memory_bytes: 27296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N;
    cin >> N;
    vi a(N);
    in(N,a);
    a.pb(10000000);
    int ans = 0;
    rep(i,N+1){
        if(a[i] == a[i+1]){
            ans++;
            i++;
        }
    }
    
    cout << ans << endl;

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(int argc, char const *argv[]){
	long a,b,c,ans=0,sum;
	scanf("%ld %ld %ld",&a,&b,&c);
	if(a%2==0 && b%2==0 && c%2==0){
		if(a==b && b==c) ans=-1;
		else{
			sum=a+b+c;
			c=c-b;
			b=b-a;
			while(c%2==0 && b%2==0 && a%2==0){
				ans++;
				a=(sum-a)/2;
				b/=2;
				c/=2;
			}
		}
	}
	printf("%ld\n",ans);
	return 0;
}

Measured memory_bytes: 128
def dfs(i,f,sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        dfs(i+1, f + "-" + s[i+1], sum - int(s[i+1]))
        dfs(i+1, f + "+" + s[i+1], sum + int(s[i+1]))
s = input()
dfs(0,s[0],int(s[0]))
       

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

vector<bitset<5100> > dp[2];
vector<int> a;
int N, K;

int main() {
	cin >> N >> K;
	a.resize(N);
	rep(i,N) cin >> a[i];
	rep(i_, 2) {
		dp[i_].resize(N+1);
		dp[i_][0][0] = true;
		rep(i,N) {
			dp[i_][i+1] = dp[i_][i];
			rep(j,K+1) {
				if(dp[i_][i][j]) {
					dp[i_][i+1][min(j+a[i],(ll)K)] = true;
				}
			}
		}
		reverse(all(a));
	}

	int res = 0;
	rep(i,N) {
		int b, c;
		b = 0;
		c = K;
		bool needs = false;
		while(c >= 0) {
			while(c >= 0 && !dp[1][N-(i+1)][c]) c--;
			while(b <= K && (!dp[0][i][b] || b+c < K-a[i])) b++;
//			if(dp[0][i][b] && dp[1][N-(i+1)][c]) cout << i << " " << b << " " << c << endl;
			if(dp[0][i][b] && dp[1][N-(i+1)][c] && (b+c) < K)
				needs = true;
			c--;
		}
		if(!needs) {
			res++;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 6528
#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int N;
	while(cin >> N, N){
		int A[100], Target;
		for(int i = 0; i < N; i++) cin >> A[i];
		cin >> Target;

		int l = 0, r = N - 1, piv;
		int cnt = 0;
		while(r - l >= 0){
			cnt++;
			int mid = (l + r)/2;
			if(A[mid] > Target) r = mid - 1;
			else if(A[mid] < Target) l = mid + 1;
			else break;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 1140
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class LazySegTree {
	int n;
	vector<ll> node, lazy;
public:
	LazySegTree(const vector<ll> &v) {
		int N = v.size();
		n = 1;
		while (n < N) n <<= 1;
		node.resize(2 * n);
		lazy = node;
		REP(i, N) node[i + n] = v[i];
		FORR(i, N, 1) node[i] = max(node[2 * i], node[2 * i + 1]);
	}
	void eval(int k, int l, int r) {
		if (lazy[k]) {
			node[k] += lazy[k];
			if (r - l > 1) {
				lazy[2 * k] += lazy[k];
				lazy[2 * k + 1] += lazy[k];
			}
			lazy[k] = 0;
		}
	}
	void add(int a, int b, ll x, int k = 1, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] += x;
			eval(k, l, r);
			return;
		}
		add(a, b, x, 2 * k, l, (l + r) / 2);
		add(a, b, x, 2 * k + 1, (l + r) / 2, r);
		node[k] = max(node[2 * k], node[2 * k + 1]);
	}
	ll get_max(int a, int b, int k = 1, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		if (b <= l || r <= a) return 0;
		if (a <= l && r <= b) return node[k];
		return max(get_max(a, b, 2 * k, l, (l + r) / 2), get_max(a, b, 2 * k + 1, (l + r) / 2, r));
	}

};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	ll D, A;

	cin >> N >> D >> A;
	
	vector<pair<ll, ll>> XH(N);

	REP(i, N) {
		cin >> XH[i].first >> XH[i].second;
	}

	SORT(XH);

	vector<ll> X(N), H(N);
	REP(i, N) tie(X[i], H[i]) = XH[i];

	LazySegTree seg(H);
	
	int l = 0, r = 1;
	ll res = 0;
	while (l < N) {
		while (l < N && seg.get_max(l, l + 1) <= 0) ++l;
		if (l == N) break;
		if (r <= l) r = l + 1;
		while (r < N && X[r] - X[l] <= 2 * D) ++r;
		ll h = seg.get_max(l, l + 1);
		ll num = (h + A - 1) / A;
		res += num;
		seg.add(l, r, -num * A);
		++l;
	}
	cout << res << endl;
	return 0;
}

										

Measured memory_bytes: 14720
#include<stdio.h>

int main(void)

{

    int i;

    int n;

    int max;

    int min;

    long int sum = 0;

    int a[10000];

    scanf("%d", &n);

    for(i = 0; i < n; i++){

         scanf("%d", &a[i]);

    }

    max = min = a[0];

    for(i = 0; i < n; i++){

        if(a[i] > max){

            max = a[i];

        }

        else if(a[i] < min){

            min = a[i];

        }

        sum += a[i];

    }

    printf("%d %d %ld\n", min, max, sum);

    return 0;

} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define fi first
#define se second
const int LEN = 2e5+5;
const int LEN5 = 1e5+5;
const int MOD = 1e9+7;
typedef long long ll;
int n,m;
int dp[LEN5];
vector<int> adj[LEN5];
void sol(int x) {
   if(dp[x] != -1) return;
   dp[x] = 0;
   for(auto v : adj[x]) {
      sol(v);
      dp[x] = max(dp[x],1+dp[v]);
   }
}
int main() {

   // freopen ("myfile.txt","r",stdin);
   // freopen ("myfile.txt","w",stdout);

   // ios_base::sync_with_stdio(0); cin.tie(NULL);
   cin>>n>>m;
   int x,y;
   for(int i =0;i<m;i++) {
      scanf("%d%d",&x,&y);
      adj[x].push_back(y);
   }   
   for(int i =0;i<LEN5;i++) dp[i] = -1;
   int ans = 0;
   for(int i =1;i<=n;i++) {
      if(dp[i] == -1) {
         sol(i);
      }
      ans = max(ans,dp[i]);
   }
   cout<<ans<<endl;

}   

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

int main(){
  int A[5][4][11], n;
  for ( int i = 1; i <= 4; i++ )
     for ( int j = 1; j <= 3; j++ )
       for ( int k = 1; k <= 10; k++ ) A[i][j][k] = 0;
      
   cin >> n;
      for ( int i = 0; i < n; i++ ){
        int b, f, r, v;
      cin >> b >> f >> r >> v;
      A[b][f][r] += v;
  }
    
    for ( int f = 1; f <= 4; f++ ){
      if ( f > 1 ) cout << "####################\n";
        for ( int b = 1; b <= 3; b++ ){
            for ( int r = 1; r <= 10; r++ ){
            cout << " " << A[f][b][r];
        }
        cout << endl;
    }
}
        

  return 0;
}    

Measured memory_bytes: 1164
n,m = map(int,input().split())

A_list = []
B_list = []

for i in range(n):
    A = list(map(int,input().split()))
    A_list.append(A)

for j in range(m):
    B = int(input())
    B_list.append(B)

for l in range(n):
    answer = 0
    for k in range(m):
        answer += (A_list[l][k] * B_list[k])
    print(answer)


Measured memory_bytes: 6008
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define init(arr, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
const int inf = pow(10,9);
const int nil = -1;
int i, n, m, k, ans, a;

int main() {
    scanf(" %d %d", &n, &m);
    rep(0,m) {
        scanf(" %d", &a);
        n -= a;
    }
    n = n >= 0 ? n : -1;

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

Measured memory_bytes: 3828
N = int(input())
a = list(map(int,input().split()))

b = [0 for i in range(N)]

def check(i):
    cnt = 0
    n = i
    while n <= N:
        cnt += b[n-1]
        n += i
    return cnt

for i in range(N-1,-1,-1):
    if (a[i] + check(i+1))%2 == 1:
        b[i] = 1

ans = []
cnt = 0
for i in range(N):
    if b[i] == 1:
        cnt += 1
        ans.append(i+1)

print(cnt)
L = [str(int(i)) for i in ans]
print(' '.join(L))

Measured memory_bytes: 22324
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int main() {
    ll n, ans = 0, div = 1;
    cin >> n;
    if (!(n & 1)) {
        while (div <= n) {
            div *= 5;
            ans += n / div / 2;
        }
        printf("%lld\n", ans);
    } else {
        puts("0");
    }
    return 0;
}

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

#define INF 1<<20


int main(){
    string s, t;
    cin >> s>>t;
    if (s.size()+1==t.size() && t.substr(0, t.size()-1)==s) cout <<"Yes"<< endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        System.out.println((b-a==c-b ? "YES": "NO"));
      
    }
}


Measured memory_bytes: 21844
#include<cstdio>

#define ran 2022

struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	int add(int x,int y){return (x+=y)<mod?x:x-mod;}
	int sub(int x,int y){return (x-=y)>=0?x:x+mod;}
};
modular_arithmetic ma;

int n, m;
int a[ran], b[ran];
int s[ran][ran];

int main() {
	scanf("%d%d", &n, &m);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]);
	for(int i=1;i<=m;i++) scanf("%d", &b[i]);
	
	for(int i=0;i<=m;i++) s[0][i] = 1;
	for(int i=1;i<=n;i++) {
		s[i][0] = 1;
		for(int j=1;j<=m;j++) {
			s[i][j] = ma.add(s[i-1][j], s[i][j-1]);
			s[i][j] = ma.sub(s[i][j], s[i-1][j-1]);
			
			if (a[i] == b[j])
				s[i][j] = ma.add(s[i][j], s[i-1][j-1]);
		}
	}
	printf("%d\n", s[n][m]);
	
	return 0;
}

Measured memory_bytes: 16000
n,k = map(int,input().split())
h = sorted(list(map(int,input().split())))

if k > h[n-1]:
    print(0)

else:

    low = 0
    high = n-1
       
    while low < high:
           
        mid = (low + high)//2
           
        if k > h[mid]:
               
            low = mid +1
           
        else:    
               
            high = mid 

    else:
           
        print(n - low)

Measured memory_bytes: 51440
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  if (b % a == 0) cout << b + a << '\n';
  else cout << b - a << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node T[25];
int n;

void maigoCenter(void);
int findSibling(int);
int countDegree(int);
int findDepth(int);
int findHeight(int);
void printType(int);

int main(){
  int i, id;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d", &id);
    scanf("%d%d", &T[id].left, &T[id].right);
    T[id].parent = -1;
  }

  maigoCenter();

  for(i=0; i<n; i++){
    printf("node %d: parent = %d, sibling = %d, ", i, T[i].parent, findSibling(i));
    printf("degree = %d, ", countDegree(i));
    printf("depth = %d, ", findDepth(i));
    printf("height = %d, ", findHeight(i));
    printType(i);
  }


  return 0;
}

void maigoCenter(void){
  int i;

  for(i=0; i<n; i++){
    if(T[i].left != -1){
      T[T[i].left].parent = i;
    }
    if(T[i].right != -1){
      T[T[i].right].parent = i;
    }
  }

} 

int findSibling(int n){
  if(T[n].parent != -1){
    if(T[T[n].parent].left == n){
      return T[T[n].parent].right;
    }else {
      return T[T[n].parent].left;
    }
  }
    return -1;
}

int countDegree(int n){
  int count = 0 ;

  if(T[n].left != -1) count++;
  if(T[n].right != -1) count++;

  return count;
}

int findDepth(int n){ 
  int depth, parent;

  if(T[n].parent == -1) return 0;

  parent = T[n].parent;

  for( depth = 1; T[parent].parent != -1; depth++){
    parent = T[parent].parent;
  }

  return depth;
}

int findHeight(int n){
  int left=0, right=0;

  if(T[n].right != -1){
    right = findHeight(T[n].right) + 1;
  }  
  if(T[n].left != -1){
    left = findHeight(T[n].left) + 1;
  }
  
  return (left>right)? left : right;

}

void printType(int n){
  if(T[n].parent == -1) printf("root\n");
  else if(T[n].left == -1 && T[n].right == -1) printf("leaf\n");
  else printf("internal node\n");
}

Measured memory_bytes: 612
#include <stdio.h>
#include <string.h>
int main() {
	char str[300],str1[101], str2[101];
	scanf("%s", str1);
	scanf("%s", str2);
	strcpy(str, str1);
	strcat(str, str1);
	if (strstr(str, str2)==NULL)
		printf("No\n");
	else
		printf("Yes\n");
}


Measured memory_bytes: 2104
n, m = gets.chomp.split.map(&:to_i)
edges = []
$graph = Array.new(n).map{Array.new()}

m.times {
  a, b = gets.chomp.split.map(&:to_i)
  a -= 1; b-= 1;
  edges.push( [a, b] )
  $graph[a].push(b)
  $graph[b].push(a)
}

def dfs(cur, u, v, n)
  $is_visited[cur] = true
  for adj in $graph[cur] do
    if $is_visited[adj] == true ||
       cur == u && adj == v ||
       cur == v && adj == u then
       next
    end
    dfs(adj, u, v, n)
  end
end

ans = 0
m.times { |i|
  $is_visited = [ false ]*n
  u = edges[i][0]
  v = edges[i][1]
  dfs(0, u, v, n)
  if not $is_visited.all?
    ans += 1
  end
}

p ans


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

		 int main() {
			 double sum = 0;
			 int n;
			 cin >> n;
			 vector<double> v1;
			 vector<string> s1;
		
			 for (int i = 0; i < n; i++) {

				 v1.push_back(0); s1.push_back("a");
				cin >> v1[i]; cin >> s1[i];
				 if (s1[i] == "JPY") {
					 sum = sum + v1[i];
				 }
				 else {
					 sum = sum + 380000.0*v1[i];
				 }
			 }
			 cout << sum;
			 return 0;
		 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, 0, n) {
    int a;
    cin >> a;
    mp[a]++;
  }

  int ans = 0;
  for (auto m : mp) {
    if (m.second - m.first < 0)
      ans += m.second;
    else
      ans += min(m.second, m.second - m.first);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4736
'use strict';

const main = (args) => {
    const input = args.trim().split('\n');
    const K = parseInt(input[0], 10);
    const S = String(input[1]);

    if(S.length > K) {
        let s = S.slice(0, K);
        console.log("%s...", s);
    } else {
        console.log(S);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 29560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

// 最小公約数
long lcm(long a, long b) {
	return a / gcd(a, b) * b;
}*/

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

	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];

	sort(allof(h));

	ll ans = inf;

	Rep(i, k - 1, n) {
		ans = min(ans, h[i] - h[i - k + 1]);
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  int x, y;
  cin >> x >> y;

  int count_A   = y - x;
  int count_AB  = -y - x + 1;
  int count_BA  = y + x + 1;
  int count_BAB = -y + x + 2;

  vector<int> ans = {count_A, count_AB, count_BA, count_BAB};
  sort(ans.begin(), ans.end());
  for (int i = 0; i < 4; i ++) {
    if (ans.at(i) > 0) {
      cout << ans.at(i) << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;

int compare_ll(const void *a, const void *b){
    return *(ll*)a - *(ll*)b;
}

int main(){
	ll  n, h, a, amax=0, cnt=0, d=0;
    ll  b[100000+1]={0};

	scanf("%lld %lld", &n, &h);

	for(int i=0; i<n; i++){
		scanf("%lld %lld", &a, &b[i]);
		if( a > amax ){ amax = a; }
	}
    qsort( b, n, sizeof(ll), compare_ll );
	
    int j=n-1;

    while(h > 0){

        if( j >= 0 && b[j] >= amax ){
            h -= b[j];
            cnt++;
            j--;

        }else{
            h -= amax;
            cnt++;
        }
    }
    printf("%lld\n", cnt);
	
	return 0;
}

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

class MaxFlow {
public:
  struct edge { ll to, cap, rev; };

  const ll INF = 1LL << 60;
  ll N;
  vector< vector<edge> > E;
  vector<bool> used;

  MaxFlow(ll n): N(n), E(n), used(n) {};

  void add_directed_edge(ll from, ll to, ll cap) {
    E[from].push_back((edge) { to, cap, (ll) E[to].size() });
    E[to].push_back((edge) { from, 0, (ll) E[from].size() - 1 });
  }

  ll dfs(ll v, ll t, ll f) {
    if(v == t) return f;
    used[v] = true;
    REP(i, 0, E[v].size()) {
      edge &e = E[v][i];
      if(!used[e.to] && e.cap > 0) {
        ll d = dfs(e.to, t, min(f, e.cap));
        if(d > 0) {
          e.cap -= d;
          E[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  ll max_flow(ll s, ll t) {
    ll flow = 0;
    while(1) {
      REP(i, 0, N) used[i] = false;
      ll f = dfs(s, t, INF);
      if(f == 0 || f == INF) break;
      flow += f;
    }
    return flow;
  }
};

int main(void) {
  ll N;
  cin >> N;
  vector<string> S(N);
  REP(i, 0, N) cin >> S[i];

  vector<bool> last(256, false);
  REP(i, 0, N) last[S[i].back()] = true;

  for (char c = 'a'; c <= 'z'; c++) if (last[c]) {
    MaxFlow mf(28);
    ll s = 26, t = 27;
    ll cnt = 0;
    REP(i, 0, N) {
      char f = S[i].front(), b = S[i].back();
      ll u = f == c ? s : f - 'a';
      ll v = b == c ? t : b - 'a';
      mf.add_directed_edge(u, v, 1);
      if (u == s) cnt++;
    }
    ll flow = mf.max_flow(s, t);
    if (cnt == flow) cout << c << endl;
  }
}


Measured memory_bytes: 5560
// D - Practical Skill Test

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

using POS = pair<int, int>;

int A[300][300];
unordered_map<int, POS> n_to_pos;
int cum_pow[300 * 300 + 1];

int main() {
	int H, W, D;
	cin >> H >> W >> D;

	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			cin >> A[i][j];
			n_to_pos[A[i][j]] = make_pair(i, j);
		}
	}

	// 事前計算
	for (int i=0; i<D; i++) {
		for (int l=i; l+D<=H*W; l+=D) {
			int r = l + D;

			POS l_pos = n_to_pos[l];
			POS r_pos = n_to_pos[r];

			int pow = abs(l_pos.first - r_pos.first) + abs(l_pos.second - r_pos.second);
			cum_pow[r] = cum_pow[l] + pow;
		}
	}

	int Q;
	cin >> Q;

	vector<int> ans;

	for (int i=0; i<Q; i++) {
		int L, R;
		cin >> L >> R;
		ans.push_back(cum_pow[R] - cum_pow[L]);
	}

	for (int a : ans) {
		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 8588
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, A, B;
  cin >> N >> A >> B;
  string S;
  cin >> S;
  const char* s = S.c_str();

  ll border = (A + B) - 1;
  ll count_a = 0;
  ll count_b = 0;

  REP(i, 0, N) {
    switch (s[i]) {
      case 'a': {
        if (count_a + count_b <= border) {
          cout << "Yes" << endl;
          count_a++;
        } else {
          cout << "No" << endl;
        }
        break;
      }
      case 'b': {
        if (count_a + count_b <= border && count_b <= (B - 1)) {
          cout << "Yes" << endl;
          count_b++;
        } else {
          cout << "No" << endl;
        }
        break;
      }
      default: {
        cout << "No" << endl;
        break;
      }
    }
  }

  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  string s; cin >> s;
  int sz = SZ(s);

  vector<vector<ll>> dp(n+1, vector<ll>(n+1));
  dp[0][0] = 1;
    
  for(int i=0;i<n;++i) {
    for(int j=0;j<n+1;++j) {
      if(j == 0) {
        dp[i+1][j] += dp[i][j];
        dp[i+1][j+1] += 2*dp[i][j];
        dp[i+1][j+1] %= MOD;
      } else {
        if(j-1 >= 0) {
          dp[i+1][j-1] += dp[i][j];
          dp[i+1][j-1] %= MOD;
        }
        if(j+1 <= n) {
          dp[i+1][j+1] += 2*dp[i][j];
          dp[i+1][j+1] %= MOD;
        }
      }
    }
  }
  const ll inv2 = 500000004;
  for(int i=0;i<sz;++i) {
    dp[n][sz] *= inv2;
    dp[n][sz] %= MOD;
  }
  cout << dp[n][sz] << endl;
}

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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18

/*int power(int a,int b){
  int res=1;
  while(b>0){
    if(b&1)(res*=a)%=mod;
    (a*=a)%=mod;
    b>>=1;
  }
  return res;
}*/

void solve(){
  int n,w;cin>>n>>w;
  vi wt(n),v(n);
  int val=0;
  for(int i=0;i<n;i++)
  cin>>wt[i]>>v[i],val+=v[i];
  vi dp(val+1,0);
  for(int i=1;i<=val;i++)dp[i]=INF64;
  for(int i=0;i<n;i++)
    for(int j=val;j>=v[i];j--)
      dp[j]=min(dp[j],dp[j-v[i]]+wt[i]);
  int ans=-1;
  for(int i=val;i>=0;i--)
    if(dp[i]<=w){
      ans=i;break;
    }
  cout<<ans;
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

Measured memory_bytes: 3988
package main

import (
	"fmt"
	"sort"
)

type Poi []rune

func (p Poi) Len() int           { return len(p) }
func (p Poi) Less(i, j int) bool { return p[i] < p[j] }
func (p Poi) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

func solve() {
	var ss, ts string
	fmt.Scan(&ss, &ts)
	s := Poi(ss)
	t := Poi(ts)

	sort.Sort(s)
	sort.Sort(sort.Reverse(t))

	if check(s, t) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func check(a, b []rune) bool {
	for i, as := range a {
		bs := b[i]
		if as < bs {
			return true
		} else if as > bs {
			return false
		}
		if len(b)-1 == i {
			break
		}
	}
	if len(a) < len(b) {
		return true
	}
	return false
}

func main() {
	solve()
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,q,a,b,de[200010]={},d=1,i,j;
  vector<int> l[200010];
  cin >> n >> q;
  for (i=0;i<n-1;i++){
    cin >> a >> b;
    l[a].push_back(b);
    l[b].push_back(a);
  }
  int qs,h;
  queue<int> que;
  que.push(1);
  while (que.size()){
    qs=que.size();
    for (i=0;i<qs;i++){
      h=que.front();
      que.pop();
      de[h]=d;
      for (j=0;j<l[h].size();j++) if (de[l[h][j]]==0) que.push(l[h][j]);
    }
    d++;
  }
  int p,x,ans[200010]={};
  for (i=0;i<q;i++){
    cin >> p >> x;
    ans[p]+=x;
  }
  int t;
  queue<int> y;
  y.push(1);
  while (y.size()){
    t=y.front();
    y.pop();
    for (i=0;i<l[t].size();i++) if (de[l[t][i]]>de[t]){
      ans[l[t][i]]+=ans[t];
      y.push(l[t][i]);
    }
  }
  for (i=1;i<=n;i++) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}

Measured memory_bytes: 16372
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    ll k;
    cin >> s >> k;

    rep(i, min((ll)s.size(), k)) {
        if(s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }

    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define maxn 100005
#define ll long long 
using namespace std;
ll n,q,a[maxn],sum;
int tm[maxn];
int main(void)
{
    while(~scanf("%lld",&n))
    {
        sum=0;
        for(int i=0;i<n;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];//求和
            tm[a[i]]++;//a[i]出现的次数自增
        }
        scanf("%lld",&q);
        ll b,c;
        for(int i=0;i<q;++i)
        {
            scanf("%lld %lld",&b,&c);
            sum+=(c-b)*tm[b];
            tm[c]+=tm[b];//更新tm[c]
            tm[b]=0;//更新tm[b]
            printf("%lld\n",sum);
        }
    }
    return 0;
}


Measured memory_bytes: 4980
require "set"
q = gets.chomp.to_i
lr_arr = q.times.map{gets.chomp.split(" ").map(&:to_i)}

MAX = 10 ** 5
set = Set.new((2..MAX))

# 10 ** 5までの素数を求める
2.upto(Math.sqrt(MAX)).each do |i|
  tmp = i
  while tmp <= MAX do
    tmp += i
    set.delete(tmp)
  end
end

# 累積
arr = [0]
1.upto(MAX) do |i|
  if set.include?(i) && set.include?((i+1)/2)
    arr[i] = arr[i-1] + 1
  else
    arr[i] = arr[i-1] 
  end
end

lr_arr.each do |(l, r)|
  puts arr[r] - arr[l-1]
end


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

using namespace std;
#define N 100100
#define SIGMA 26

string s;
int t[128];
long long j, jj, i, n, ans, k;
int verif (){
    int it = 0;
    while (it< s.size() && s[it] - '0' == t[it])
        ++it;
    if (it == s.size())
        return 1;
    if (s[it] - '0' < t[it])
        return 0;
    return 1;
}
int main()
{
    cin >> s;
    cin >> k;
    if (k == 1){
        n = s.size();
        if (n > 1)
            ans = 9 * (n - 1);
        else
            ans = 0;
        ans += s[0] - '0';
    }
    if (k == 2){
        n = s.size();
        if (n > 2)
            ans = 81 * (n - 1) * (n - 2) / 2;
        else
            ans = 0;
        for (i = 1; i < s[0] - '0' + 1; ++i){
            t[0] = i;
            for (j = 1; j < s.size(); ++j){
                for (t[j] = 1; t[j] < 10; ++t[j])
                    ans += verif();
                t[j] = 0;
            }
        }
        if (n < 2)
            ans = 0;
    }
    if (k == 3){
        n = s.size();
        if (n > 3)
            ans = 729 * (n - 1) * (n - 2) * (n - 3) / 6;
        else
            ans = 0;
        for (i = 1; i < s[0] - '0' + 1; ++i){
            t[0] = i;
            for (j = 1; j < s.size(); ++j){
                for (t[j] = 1; t[j] < 10; ++t[j]){
                    for (jj = j + 1; jj < s.size(); ++jj){
                        for (t[jj] = 1; t[jj] < 10; ++t[jj])
                            ans += verif ();
                        t[jj] = 0;
                    }
                }
                t[j] = 0;
            }
        }
        if (n < 3)
            ans = 0;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int node[5];

int main(){
    for (int i = 0; i < 3; i++){
        int a, b; cin >> a >> b;
        node[a]++;
        node[b]++;
    }
    int a[5] = {1, 1, 2, 2};
    sort(node+1, node+5);
    for (int i = 1; i <= 4; i++){
        if (node[i] != a[i-1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    

}


Measured memory_bytes: 256
fun main(args: Array<String>) = IO().exec {
    val n = int()
    val s = Array(n){string()}
    val t = string()
    var p = 0
    var q = 0
    for (u in s) {
        val u1 = u.replace('?', 'a')
        val u2 = u.replace('?', 'z')
        if (t < u1) continue
        else if (u2 < t) p++
        else q++
    }
    println((p..p+q).map { it+1 }.joinToString(" "))
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 34168
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  vector<long long> H(N);
  for (int i = 0; i < N; i++){
    cin >> H[i];
  }
  long long sum = 0;
  sort(H.begin(),H.end());
  for (int i = 0; i < N - K; i++){
    sum += H[i];
  }
  cout << sum;
}

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

int main()
{
    int n;
    cin >> n;
    int x;
    int maxn = -1;
    int minn = 1000000010;
    rep(i, n) {
        cin >> x;
        maxn = max(maxn, x);
        minn = min(minn, x);
    }

    cout << maxn - minn << endl;



    return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long an = 1;

		int i = 1;

		for (i = 1; i <= n; i++) {

			an = (an * i) % 1000000007;
		}

		System.out.println(an);

	}

}


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

vector<long> prime(long N){
    vector<long> ans;
    if(N % 2 == 0){
        long a = 0;
        while(N % 2 == 0){
            N /= 2;
            a++;
        }
        ans.push_back(a);
    }
    long M = N;
    for(long i = 3; i * i <= N; i += 2){
        if(M % i == 0){
            long a = 0;
            while(M % i == 0){
                M /= i;
                a++;
            }
            ans.push_back(a);
        }
    }
    if(M != 1) ans.push_back(1);
    return ans;
}

int main(){
    long N;
    cin >> N;
    vector<long> A = prime(N);
    long ans = 0;
    for(int i = 0; i < A.size(); i++){
        long a = 0;
        while(((a * (a + 1)) / 2) <= A[i]) a++;
        ans += (a - 1);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n,total=0;
    cin >>n;
    int a[n],b[n],c[n-1];
    for(int ia=0;ia<n;ia++){
        cin >> a[ia];
    }
    for(int ib=0;ib<n;ib++){
        cin >> b[ib];
        total = total+ b[ib];
    }
    for(int ic=0;ic<n-1;ic++){
        cin >> c[ic];
    }
    for(int prob=0;prob<n-1;prob++){
        if(a[prob]+1==a[prob+1]){
            total = total+ c[a[prob]-1];
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())

nkai = 1
nkaid = 1
mkai = 1
mkaid = 1
for i in range(n):
  nkai *= (n-i)
for i in range(n-2):
  nkaid *= (n-2-i)
for i in range(m):
  mkai *= (m-i)
for i in range(m-2):
  mkaid *= (m-2-i)

if n == 1:
  nans= 0
else:
  nans= int(nkai/(nkaid*2))
if m == 1:
  mans= 0
else:
  mans= int(mkai/(mkaid*2))


print(nans + mans)


Measured memory_bytes: 3064
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
    long[][] nums = new long[2*n][];//座標と種類
    long memo = 0;
    long multiplyMemo = 1;
    long answer = 1;
    long mod = 1000000007;
    for(long i = 0; i < n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = 0;
    }
    for(long i = n; i < 2*n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = 1;
    }
    Array.Sort(nums, (a, b) => a[0].CompareTo(b[0]));
    for(long i = 0; i < 2*n; i++)
    {
      if(nums[i][1] == 0)
      {
        memo++;
        if(memo > 1) answer *= Math.Abs(memo);
        answer %= mod;
      }
      else
      {
        memo--;
        if(memo < -1) answer *= Math.Abs(memo);
        answer %= mod;
      }
      //Console.WriteLine(answer);
    }
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
  
}


Measured memory_bytes: 29520
#include <iostream>

using namespace std;
 
int main(){
  int n;
  int p[21];
  int cnt = 0;
  cin >> n;
  
  for(int i = 0;i < n;i++){
    cin >> p[i];
  }
  
  for(int i = 0;i < n - 2;i++){
    
    if( (p[i+1] < p[i]) && (p[i+1] > p[i+2]) || (p[i+1] < p[i+2]) && (p[i+1] > p[i])){
      cnt++;
    }
  }
  
  cout << cnt;
  
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int n = Integer.parseInt(bf.readLine());
 		String x = bf.readLine().trim();
 		int onecount = 0;
 		int index = 0;
 		for(int i = 0;i<x.length();i++){
 			if (x.charAt(i) == '1'){
 				onecount++;
 				index = i;
 			}
 		}
 	
 		if (onecount == 1){
 	 		long sumonep1 = 0;
 	 		for(int i = x.length()-1;i>=0;i--){
 	 			if (x.charAt(i) == '1'){
 		 			sumonep1+= power(2, x.length()-1-i, onecount+1);
 		 			sumonep1%= (onecount+1);
 	 			}
 	 		}
 	 		
 	 		for(int i = 0;i<x.length();i++){
 	 			
 	 			long sum = 0;
 	 			if (x.charAt(i) == '1'){
 	 				out.println(0);
 	 			}
 	 			else{
 	 				sum = sumonep1;
 	 				sum+= power(2, x.length()-1-i, onecount+1);
 	 				sum%= (onecount+1);
 	 				sum+= (onecount+1);
 	 				sum%= (onecount+1);
 	 				int count = 1;
 	 				while(sum!= 0){
 	 					String a = Long.toBinaryString(sum);
 	 					long counta = 0;
 	 					for(int j=0;j<a.length();j++){
 	 						if (a.charAt(j) == '1')
 	 							counta++;
 	 					}
 	 					sum = sum%counta;
 	 					count++;
 	 				}
 	 				out.println(count);
 	 			}
 	 		}
 		}
 		else{
 		long sumonem1 = 0;
 		long sumonep1 = 0;
 		for(int i = x.length()-1;i>=0;i--){
 			if (x.charAt(i) == '1'){
	 			sumonem1+= power(2, x.length()-1-i, onecount-1);
	 			sumonem1%= (onecount-1);
	 			sumonep1+= power(2, x.length()-1-i, onecount+1);
	 			sumonep1%= (onecount+1);
 			}
 		}
 		
 		for(int i = 0;i<x.length();i++){
 			
 			long sum = 0;
 			if (x.charAt(i) == '1'){
 				sum = sumonem1;
 				sum -= power(2, x.length()-1-i, onecount-1);
 				sum%= (onecount-1);
 				sum+= (onecount-1);
 				sum%= (onecount-1);
 				int count = 1;
 				while(sum!= 0){
 					String a = Long.toBinaryString(sum);
 					long counta = 0;
 					for(int j=0;j<a.length();j++){
 						if (a.charAt(j) == '1')
 							counta++;
 					}
 					sum = sum%counta;
 					count++;
 				}
 				out.println(count);
 			}
 			else{
 				sum = sumonep1;
 				sum+= power(2, x.length()-1-i, onecount+1);
 				sum%= (onecount+1);
 				sum+= (onecount+1);
 				sum%= (onecount+1);
 				int count = 1;
 				while(sum!= 0){
 					String a = Long.toBinaryString(sum);
 					long counta = 0;
 					for(int j=0;j<a.length();j++){
 						if (a.charAt(j) == '1')
 							counta++;
 					}
 					sum = sum%counta;
 					count++;
 				}
 				out.println(count);
 			}
 		}
 		}
 		
 		
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
	public static int power(long x, long y, long mod){
		long ans = 1;
		while(y>0){
			if (y%2==1)
				ans = (ans*x)%mod;
			x = (x*x)%mod;
			y/=2;
		}
		return (int)(ans);
	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 51080
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
//constexpr ll mod = 1000000007;


ll n, p, s[300000], e10[300000];
ll t[300000];
ll c[200000];
string ss;

int main() {
    cin >> n >> p >> ss;
    if (p == 2 || p == 5) {
        ll v = 0;
        for (int i = 0; i < n; i++) {
            if ((ss[i] - '0') % p == 0) {
                v += i + 1;
            }
        }
        cout << v << endl;
        return 0;
    }
    e10[0] = 1;
    for (ll i = 1; i < 300000; i++) e10[i] = ((e10[i - 1] * 10) % p);
    for (ll i = 0; i < n; i++) {
        s[i] = ss[(n - i) - 1] - '0';
    }
    for (ll i = 0; i < n; i++) {
        t[i + 1] = (t[i] + (s[i] * e10[i])) % p;
    }
    for (ll i = 0; i <= n; i++) {
        c[t[i]]++;
    }
    ll r = 0;
    for (ll i = 0; i < p; i++) {
        r += (c[i] * (c[i] - 1)) / 2;
    }
    cout << r << endl;
}

Measured memory_bytes: 7300
// knap1.cpp
#include<iostream>
#include<cstring>
#include<climits>
using namespace std;
typedef long long int ll;

int main(){
ll n,k;
cin >> n >> k;
ll val[n], wt[n];
for(ll i=0;i<n;i++){
	cin >> wt[i] >> val[i] ;
}

ll dp[n+1][k+1];
memset(dp,0,sizeof(dp));

for(ll i=0;i<=n;i++){
	for(ll j = 0;j<=k;j++){
		if(i==0|| j==0) dp[i][j] = 0;

		else if(i-1 >= 0 && j-wt[i-1] >=0){
		dp[i][j] = max(dp[i-1][j], dp[i-1][j-wt[i-1]] + val[i-1]);
		}else{
			dp[i][j] = dp[i-1][j];
		}
	}
}

cout << dp[n][k]<<endl;

return 0;
}

Measured memory_bytes: 82432
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#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 ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;

int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	
	int x = 800 * n;
	int y = (n/15) * 200;
	cout << x-y << endl;
	return 0;
}

Measured memory_bytes: 764