akhauriyash/Code-Regression huggingface dataset:
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int C = in.nextInt();
		int[][] D = new int[C][C];
		long[][] d = new long[3][C];
		
		for(int i = 0; i < C; i++){
			for(int j = 0; j < C; j++) D[i][j] = in.nextInt();
		}
		
		int[][] c = new int[N][N];
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				c[i][j] = in.nextInt();
				for(int k = 1; k <= C; k++){
					d[((i + j) % 3)][k-1] += D[c[i][j]-1][k-1];
				}
			}
		}
		
		long min = Long.MAX_VALUE;
		for(int i = 1; i <= C; i++){
			for(int j = 1; j <= C; j++){
				if(i == j) continue;
				for(int k = 1; k <= C; k++){
					if(i == k || j == k) continue;
					long cost = 0;
					cost += d[0][i-1];
					cost += d[1][j-1];
					cost += d[2][k-1];
					min = Math.min(min, cost);
				}
			}
		}
		
		System.out.println(min);
	}
}

Measured memory_bytes: 94588
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
    int K,N;
    cin >> K >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int dist = 0;
    int ans;
    for(int i = 0 ;i < N - 1; i++)
    {
        if(abs(A[i] - A[i+1]) >= dist)
        {
            dist = abs(A[i] - A[i+1]);
        }
    }
    if(K - A[N -1] + A[0] >= dist)
    {
        dist = K - A[N -1] + A[0];
    }
    cout << K - dist << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
  int N,j,count=0;
  int H[100];

  scanf("%d",&N);
  for ( int i = 0; i < N; i++ ) {
    scanf("%d",&H[i]);
  }
  count = 1;
  for ( int i = 1; i < N; i++ ) {
    for ( j = 0; j < i; j++) {
      if( H[j] > H[i])  break;
    }
    if ( i == j ) count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

int prim(){
  int i, v, u, minv;
  int d[MAX], p[MAX], color[MAX];

  for(i = 0; i < n; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  int sum = 0;
  for(i = 0; i < n; i++) if(p[i] != -1) sum += M[i][p[i]];

  return sum;
}

int main(){
  int i, j, e;
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &e);
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

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

  return 0;
}

Measured memory_bytes: 636
import itertools

N = int(input())
S = input()

candi = list(itertools.product(range(10),repeat=3))

cnt = 0

for i in candi:
    if str(i[0]) in S:
        T = S[S.find(str(i[0]))+1:]
        if str(i[1]) in T:
            U = T[T.find(str(i[1]))+1:]
            if str(i[2]) in U:
                cnt += 1

print(cnt)

Measured memory_bytes: 3188
// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint X, Y; std::cin >> X >> Y;
  int ans = 1;
  while (true) {
    if (Y / 2 < X) break;
    X *= 2;
    ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 20
using namespace std;
string s[MAXN];
int h,w;
vector<pii> fans;
bool ans=false;
inline bool check()
{
	multiset<string> my_set;
	if(fans[0].first==fans[0].second)
	{
		int val=fans[0].first;
		fans.erase(fans.begin());
		fans.pb(mk(val,val));
	}
	for(int i=0;i<h;i++)
	{
		string temp;
		for(int j=0;j<fans.size();j++)
		{
			temp.insert(temp.end(),s[i][fans[j].first]);
		}
		for(int j=fans.size()-1;j>=0;j--)
		{
			if(fans[j].first!=fans[j].second)
			{
				temp.insert(temp.end(),s[i][fans[j].second]);
			}
		}
		int sz=temp.size();
		assert(sz==w);
		if(!my_set.empty())
		{
			string rev_temp=temp;
			reverse(rev_temp.begin(),rev_temp.end());
			auto it=my_set.find(rev_temp);
			if(it!=my_set.end())
			{
				my_set.erase(it);
			}
			else
			{
				my_set.insert(temp);
			}
		}
		else
		{
			my_set.insert(temp);
		}
	}
	if(fans.back().first==fans.back().second)
	{
		int val=fans.back().first;
		fans.pop_back();
		fans.insert(fans.begin(),mk(val,val));
	}
	if(h%2)
	{
		int sz=my_set.size();
		if(sz==1)
		{
			string temp=(*my_set.begin());
			string rev_temp=temp;
			reverse(rev_temp.begin(),rev_temp.end());
			if(temp==rev_temp)
			{
				return true;
			}
		}
		return false;
	}
	else
	{
		if(my_set.empty())
		{
			return true;
		}
		return false;
	}
}
void recurse(vector<int> v)
{
	if(v.empty())
	{
		if(check())
		{
			ans=true;
		}
		return;
	}
	int first_num=v[0];
	v.erase(v.begin());
	for(int i=0;i<v.size();i++)
	{
		vector<int> temp=v;
		int second_num=v[i];
		temp.erase(temp.begin()+i);
		fans.pb(mk(first_num,second_num));
		recurse(temp);
		fans.pop_back();
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>h>>w;
	for(int i=0;i<h;i++)
	{
		cin>>s[i];
	}
	vector<int> v;
	for(int i=0;i<w;i++)
	{
		v.pb(i);
	}
	if(w%2)
	{
		for(int i=0;i<w;i++)
		{
			vector<int> temp=v;
			fans.pb(mk(i,i));
			temp.erase(temp.begin()+i);
			recurse(temp);
			fans.pop_back();
		}
	}
	else
	{
		recurse(v);
	}
	if(ans)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
k,n = map(int,input().split())
a = list(map(int,input().split()))

long = a[0] + (k - a[n-1])

for i in range(n-1):
    long_ = a[i+1] - a[i]
    if long_ >= long:
        long = long_
        
print(k - long) 

Measured memory_bytes: 26444
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<long long, int> > a(n);
	for(auto& e: a)
		cin >> e.first >> e.second;
	sort(a.begin(), a.end());
	long long num=0, price=0;
	for(int i=0; i<n; i++){
		if(num==m)
			break;
		if(num+a[i].second<=m){
			price+=a[i].first*a[i].second;
			num+=a[i].second;
		}else{
			price+=a[i].first*(m-num);
			num=m;
		}
	}
	cout << price << endl;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
P = list(map(int, input().split()))

A = [(i * 20000) for i in range(1, N+1)]
B = [(i * 20000) for i in range(N, 0, -1)]

AB = []
for p in P:
    add = A[p-1] + B[p-1]
    AB.append([p, add])
    
for i in range(N-1):
    if AB[i][1] >= AB[i+1][1]:
        diff = AB[i][1] - AB[i+1][1]
        AB[i+1][1] += diff+1
        A[AB[i+1][0]-1] += diff+1

A = list(map(str, A))
B = list(map(str, B))
print(" ".join(A))
print(" ".join(B))

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

int p, q;
string P[10], Q[10];
int num[10];
vector<int> v[10];

bool check(int r, int c, int s) {
  int sr = 0, sc = 0, ss = 0;
  for (int i = 0; i < p; i++) {
    if (num[i] != r * sr + c * sc + s * ss) return false;
    for (int j = 0; j < (int)P[i].size(); j++) {
      sr += P[i][j] == '(';
      sr -= P[i][j] == ')';
      sc += P[i][j] == '{';
      sc -= P[i][j] == '}';
      ss += P[i][j] == '[';
      ss -= P[i][j] == ']';
    }
  }
  return true;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> p >> q, p) {
    for (int i = 0; i < 10; i++) {
      v[i].clear();
    }
    for (int i = 0; i < p; i++) {
      cin >> P[i];
      for (int j = 0; j < (int)P[i].size(); j++) {
        if (P[i][j] == '.') continue;
        num[i] = j;
        break;
      }
    }
    for (int i = 0; i < q; i++) {
      cin >> Q[i];
    }

    for (int r = 1; r <= 20; r++) {
      for (int c = 1; c <= 20; c++) {
        for (int s = 1; s <= 20; s++) {
          if (!check(r, c, s)) continue;
          int sr = 0, sc = 0, ss = 0;
          for (int i = 0; i < q; i++) {
            v[i].emplace_back(r * sr + c * sc + s * ss);
            for (int j = 0; j < (int)Q[i].size(); j++) {
              sr += Q[i][j] == '(';
              sr -= Q[i][j] == ')';
              sc += Q[i][j] == '{';
              sc -= Q[i][j] == '}';
              ss += Q[i][j] == '[';
              ss -= Q[i][j] == ']';
            }
          }
        }
      }
    }
    for (int i = 0; i < q; i++) {
      sort(v[i].begin(), v[i].end());
      v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
      cout << (v[i].size() == 1 ? v[i][0] : -1) << " \n"[i + 1 == q];
    }
  }

  return 0;
}


Measured memory_bytes: 3396
import java.util.Scanner;

public class Main {
	
	static int pos=0;
	static int c=0;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k;
		int[] pre = new int[n];
		int[] in = new int[n];
		int[] post = new int[n];
		
		
		for (int i=0; i<n; i++){
			pre[i] = sc.nextInt();
		}
		
		for (int i=0; i<n; i++){
			in[i] = sc.nextInt();
		}
		solve(n, pre, in, post);
	}
	
	static void rec(int n, int l, int r, int[] pre, int[] in, int[] post) {
		if (l >= r) return;
		int cnt=n;
		int root = pre[pos];
		pos++;
		for(int i=0; i<n; i++){
			if(in[i]==root) cnt=i;
		}
		rec(n, l, cnt, pre, in, post);
		rec(n, cnt + 1, r, pre, in, post);
		post[c] = root;
		c++;
		
		
	}
	
	static void solve(int n, int[] pre, int[] in, int[] post){
		pos = 0;
		rec(n, 0, n, pre, in, post);
		for (int i=0; i<n-1; i++){
			System.out.print(post[i] + " ");
		}
		System.out.println(post[n-1]);
		
		
	}
}


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

using namespace std;

#define ll long long 

ll v[105],weight[105],dp[105][100005],n,CAP;

ll KnapSack(int i, ll w)
{
	if(i == n)
	{
		return 0;
	}
	if(dp[i][w] != -1) return dp[i][w];
	ll ans1 = 0, ans2 = 0;
	if(w+weight[i] <= CAP)
	{
	    ans1 = KnapSack(i+1, w+weight[i]) + v[i];
	}
	ans2 = KnapSack(i+1, w);
	
	return dp[i][w] = max(ans1,ans2);
}

int main()
{
	memset(dp, -1, sizeof(dp));
	cin >> n >> CAP;
	
	for(int i = 0; i < n; i++) cin >> weight[i] >> v[i];
	
	ll ans = KnapSack(0,0);
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 82304
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d.at(i);
    }

    sort(begin(d), end(d));
    int cnt = 1;
    for (int i = 0; i < n-1; i++) {
        if (d.at(i) != d.at(i+1)) cnt++;
    }

    cout << cnt << endl;
}


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

int main()
{
	int N,M;
	scanf("%d %d",&N,&M);

	int *counter,K,tmp;
	counter = (int *)calloc(M,sizeof(int));
	for ( int i = 0; i < N; i++ ) {
		scanf("%d",&K);
		for ( int j = 0; j < K; j++ ) {
			scanf("%d",&tmp);
			counter[tmp-1]++;
		}
	}

	int ans = 0;
	for ( int i = 0; i < M; i++ ) {
		if ( counter[i] == N ) ans++;
	}

	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        System.out.println( (n-1) % (k-1) == 0 ? (n-1)/(k-1) : (n-1)/(k-1)+1);
    }
}


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

int n, A[44];

void fibo(){
    A[0] = 1;
    A[1] = 1;
    for (int i = 2; i <= n; i++) A[i] = A[i -1] + A[i -2];
}

int main(){
    cin >> n;
    fibo();
    cout << A[n] << endl;
    return 0;
}


Measured memory_bytes: 3064
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let nn = n as i64;
    let a: Vec<i64> = (0..n).map(|_| sc.ne()).collect();
    let sum: i64 = a.iter().fold(0, |acc, &x| acc + x);
    let sumn: i64 = (1..nn + 1).fold(0, |acc, x| acc + x);
    let mut ok = true;
    if sum % sumn != 0 {
        ok = false;
    }
    let key = sum / sumn;
    let mut cntd = 0;
    for i in 0..n {
        let j = (i + 1) % n;
        let x = a[j] - a[i];
        match x {
            val if val == key => {}
            val if val > 0 => ok = false,
            _ => {
                let d = key - x;
                if d % nn != 0 {
                    ok = false;
                } else {
                    cntd += d / nn;
                }
            }
        }
    }
    if cntd != key {
        ok = false;
    }
    println!("{}",
             match ok {
                 true => "YES",
                 _ => "NO",
             });
}
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}

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

int main(){int a,m=0,ans=0,b;cin>>a;
           for(int i=0;i<a;i++){
             cin>>b;ans+=b;
             if(b>m){
               m=b;
             }
           }
           ans-=m/2;
           cout<<ans;
          }

Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.readline()[:-1]

n, m = map(int, input().split())
def calc(x, y):
	return x * (x-1) // 2 + y * (y-1) // 2

adj = [[True for _ in range(n)] for _ in range(n)]
for _ in range(m):
	a, b = map(int, input().split())
	adj[a-1][b-1] = False
	adj[b-1][a-1] = False
for i in range(n):
	adj[i][i] = False

parity = [-1 for _ in range(n)]
nibus = []

def dfs(x):
	global bip
	bip[parity[x]] += 1
	for i in range(n):
		if adj[x][i] == True:
			if parity[i] < 0:
				parity[i] = 1^parity[x]
				dfs(i)
			elif parity[i] == parity[x]:
				print(-1)
				sys.exit()
	return bip

for i in range(n):
	if parity[i] < 0:
		parity[i] = 0
		bip = [0, 0]
		nibus.append(dfs(i))

cand = {0}
for p, q in nibus:
	p_set, q_set = set(), set()
	for s in cand:
		p_set.add(s+p)
		q_set.add(s+q)
	cand = p_set|q_set

ans = n**2
for c in cand:
	ans = min(ans, calc(c, n-c))
print(ans)

Measured memory_bytes: 9336
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(void) {
	int d;
	cin >> d;
	if (d == 25)cout << "Christmas";
	if (d == 24)cout << "Christmas Eve";
	if (d == 23)cout << "Christmas Eve Eve";
	if(d==22) cout<< "Christmas Eve Eve Eve";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define inf 100000007
int abs(int x){
	if(x<0) x=-x;
	return x;
}
int main(){
	int n,x[105],max=-1;
	long long ans=inf;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
	scanf("%d",&x[i]);
	if(x[i]>max) max=x[i];}
	for(int i=0;i<=max;i++){
		long long t=0;
		for(int j=1;j<=n;j++){
			long long y=(long long)abs(i-x[j]);
			t+=y*y;
		}
		if(t<ans) ans=t;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int n,a[2010],f[2010][2],z,w;
int main()
{
	scanf("%d %d %d",&n,&z,&w);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	a[0]=w;
	for(int i=n;i>=1;i--)
	{
		f[i][0]=abs(a[i-1]-a[n]);
		f[i][1]=abs(a[i-1]-a[n]);
		for(int j=i+1;j<=n;j++)
		{
			f[i][0]=min(f[i][0],f[j][1]);
			f[i][1]=max(f[i][1],f[j][0]);
		}
	}
	printf("%d",f[1][1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++){cout<<a[i]<<" ";cout<<endl;}}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1LL; while (b > 0) {if (b & 1LL) {c = a * c%mod;}a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

bool solve() {
	int n; cin >> n;
	vp A(n);
	REP (i,n) {
		int x; cin >> x; A.pb({x,1});
	}
	REP (i,n) {
		int x; cin >> x; A.pb({x,-1});
	}
	sort(ALL(A));
	int ans = 1;
	int cnt = 0;
	for (auto a : A) {
		int delta = a.second;
		if (cnt != 0 && cnt * a.second < 0) {
			ans *= abs(cnt); ans %= mod;
		}
		cnt += delta;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 7908
#include<stdio.h>
#include<math.h>
int main(){
  int w,h;
  char a;
  char c[25][25];

  scanf("%d %d %c",&h,&w,&a);
  for(int i=0; i<w; i++){
    for(int j=0; j<h; j++){
      if(i==0 || i==w-1){
        if(j==0 || j==h-1) c[i][j] = '+';
        else c[i][j] = '-';
      }
      else{
        if(j==0 || j==h-1) c[i][j] = '|';
        else c[i][j] = '.';
      }
    }
  }
  c[w/2][h/2] = a;
  for(int i=0; i<w; i++){
    for(int j=0; j<h; j++){
      printf("%c",c[i][j]);
    }
    printf("\n");
  }
	return 0;
}



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

int n,k;
vector<int> h;
vector<int> DP;

int main()
{
	cin >> n>>k;
	h.resize(n + 1);
	for (int i = 1; i < n + 1; i++)
		cin >> h[i];

	DP.resize(n + 1);

	// can reach n, n+1; DP[n] = 0
	DP[n] = 0;
	for (int i = n - 1; i >= 1; i--)
	{
		int mc = 1000000007; 
		for (int j = 1; j < k + 1; j++)
		{
			//find the min cost for different jumps
			if (i + j > n)
				break;
			mc = min(mc, DP[i + j] + abs(h[i + j] - h[i]));
		}
		DP[i] = mc;
	}
	cout << DP[1] << endl;
}

Measured memory_bytes: 4008
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [a,b,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ max 0 (c-a+b)


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

int main(){
int W,H, x,y,r;
cin>>W>>H>>x>>y>>r;
if(x-r>=0 && y-r>=0 && x+r<=W && y+r<=H){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return 0;
}


Measured memory_bytes: 3112
import sys
input=sys.stdin.readline
import string
import bisect

def main():

    S = input().strip()
    T = input().strip()
    if any(S.find(c) < 0 for c in T):
        print(-1)
        return

    dS = {c:[] for c in string.ascii_lowercase}
    for i, s in enumerate(S):
        dS[s].append(i)
    
    ans = 0
    pos = 0
    ls = len(S)
    for c in T:
        if dS[c][-1] < pos:
            pos = 0
            ans += ls
        bi = bisect.bisect_left(dS[c], pos)
        pos = dS[c][bi] + 1

    print(ans + pos)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8184
#include <iostream>
using namespace std;
int main(void){
    char val;
    // Your code here!
    scanf("%c", &val);
    
    if(val == 'A') {
        std::cout << "T";
    }
    if(val == 'T') {
        std::cout << "A";
    }
    if(val == 'G') {
        std::cout << "C";
    }
    if(val == 'C') {
        std::cout << "G";
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
	"strings"
)

var ans int

func dfs(step, n int, s string) {
	num, _ := strconv.Atoi(s)
	if num > n {
		return
	} else if strings.Count(s, "3") > 0 && strings.Count(s, "5") > 0 && strings.Count(s, "7") > 0 {
		// fmt.Println(num)
		ans++
	}
	for i := 0; i < len("357"); i++ {
		dfs(step+1, n, s+string("357"[i]))
	}
}

func main() {
	var N int
	fmt.Scan(&N)
	dfs(0, N, "")
	fmt.Println(ans)
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int s,d;
	int score[][7]={{0,300,500,600,700,1350,1650},
					{0,0,350,450,600,1150,1500},
					{0,0,0,250,400,1000,1350},
					{0,0,0,0,250,850,1300},
					{0,0,0,0,0,600,1150},
					{0,0,0,0,0,0,500}};
	int dist[][7]={{0,6,13,18,23,43,58},
					{0,0,7,12,17,37,52},
				 	{0,0,0,5,10,30,45},
					{0,0,0,0,5,25,40},
				 	{0,0,0,0,0,20,35},
					{0,0,0,0,0,0,15}};
	while(scanf("%d",&s),s){
		int hs,ms;
		scanf("%d%d",&hs,&ms);

		int hd,md;
		scanf("%d",&d);
		scanf("%d%d",&hd,&md);

		s--;d--;
		if(s>d)swap(s,d);

		if(1050 <= hs*60+ms && hs*60+ms <= 1170){
			if(dist[s][d]<=40){
				int ret = score[s][d];
				ret /= 2;
				if(ret%10){
					ret+=25;
				}
				printf("%d\n",ret);
			}
			else{
				printf("%d\n",score[s][d]);
			}
		}
		else if(1050 <= hd*60+md && hd*60+md <= 1170){
			if(dist[s][d]<=40){
				int ret = score[s][d];
				ret /= 2;
				if(ret%10){
					ret+=25;
				}
				printf("%d\n",ret);
			}
			else{
				printf("%d\n",score[s][d]);	
			}
		}
		else{
			printf("%d\n",score[s][d]);
		}
	}
    return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main()
{
    int n, m;
    cin >> n >> m;
    if (n == m) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define NDEBUG

#include <cstdio>

#include <vector>
#include <queue>
#include <cstdint>
#include <cassert>
#include <tuple>

template<typename t> t inf() { assert(0); return t(); }
template<> double inf() { return (1LL << 50); }
template<> long inf() { return (1LL << 50); }
template<> int inf() { return (1LL << 31)-1; }

namespace Graph {
  template<typename tEdge>
  struct Graph {
    Graph() : v(0) {}
    std::vector<tEdge> edges;
    uint32_t v;
  };
  template<typename tEdge>
  void addEdge(Graph<tEdge>& graph, tEdge edge) {
    assert( edge.from < graph.v );
    assert( edge.to   < graph.v );
    graph.edges.push_back(edge);
  }
  template<typename tEdge>
  void setV(Graph<tEdge>& graph, uint32_t v) {
    graph.v = v;
  }
};

namespace Graph {
  namespace Dijkstra {
    template<typename tEdge>
    struct DijkstraInfo {
      std::vector<typename tEdge::wType> dists;
    };
    template<typename tEdge>
    static DijkstraInfo<tEdge> dijkstra(const Graph<tEdge>& graph, uint32_t start) {
      std::vector< std::pair<uint32_t, typename tEdge::wType> > *adj = new std::vector< std::pair<uint32_t, typename tEdge::wType> >[graph.v];
      int n = graph.edges.size();
      for(int i = 0; i < n; ++i) {
        adj[graph.edges[i].from].push_back(std::make_pair(graph.edges[i].to, graph.edges[i].w));
      }
      DijkstraInfo<tEdge> info;
      info.dists.resize(graph.v);
      for(auto &x : info.dists) x = inf<typename tEdge::wType>();
      info.dists[start] = 0;
      std::priority_queue< std::pair<typename tEdge::wType, uint32_t> > q;
      q.push(std::make_pair(0, start));
      while( not q.empty() ) {
        typename tEdge::wType w;
        uint32_t id;
        std::tie(w, id) = q.top(); q.pop(); w = -w;
        for(auto I : adj[id]) {
          uint32_t next;
          typename tEdge::wType nw;
          std::tie(next, nw) = I; nw += w;
          if( info.dists[next] <= nw ) continue;
          info.dists[next] = nw;
          q.push(std::make_pair(-nw, next));
        }
      }
      delete [] adj;
      return info;
    }
  };
};


struct Edge {
  uint32_t from;
  uint32_t to;
  typedef int wType;
  wType w;
};

int main() {
  Graph::Graph<Edge> graph;
  int v, e, r;
  scanf("%d %d %d", &v, &e, &r);
  setV(graph, v);
  for(int i = 0; i < e; ++i) {
    Edge edge;
    scanf("%u %u %d", &edge.from, &edge.to, &edge.w);
    addEdge(graph, edge);
  }
  auto res = Graph::Dijkstra::dijkstra(graph, r);
  int n = res.dists.size();
  for(int i = 0; i < n; ++i) {
    printf("%s\n", res.dists[i] == inf<int>() ? "INF" : std::to_string(res.dists[i]).c_str());
  }
  
  return 0;
}

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

int n, b;
int a[200000];

int main()
{
	cin >> n;

	for (int i = 2; i <= n; i++) {
		cin >> b;
		a[b - 1]++;
	}

	for (int i = 0; i < n; i++)
		cout << a[i] << endl;
}


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

int main() {
  long long n;
  cin>>n;
  long long num=26;
  long long size=1;
  while(num<n){
    n-=num;
    num*=26;
    size++;
  }
  vector<char>ans(size);
  for(int i=0;i<size;i++) ans[i]='a';
  long long mod=26;
  n--;
  for(int i=0;i<size;i++){
    long long l=n%mod;
    char c='a'+l;
    ans[i]=c;
    n/=26; 
  }
  for(int i=size-1;i>=0;i--){
    cout<<ans[i];
  }
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	int dp[2][n], val[2][n];
	for (int i=0; i<2; i++)
		for (int j=0; j<n; j++)
			cin>>val[i][j];
	dp[0][0]=val[0][0];
	for (int i=1; i<2; i++)
		dp[i][0]=dp[i-1][0]+val[i][0];
	for (int j=1; j<n; j++)
		dp[0][j]=dp[0][j-1]+val[0][j];
	for (int i=1; i<2; i++)
		for (int j=1; j<n; j++)
			dp[i][j]=max(dp[i-1][j],dp[i][j-1])+val[i][j];
	cout<<dp[1][n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL n,r=2,t1=10,num1=1,pre[15],ans=0;
LL t2=10,num2=1,cnt=1;
LL pow(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;b>>=1;
	}
	return ans;
}
void check(LL len)
{
	if(len<num1) return;
	LL num=n/len,tot=9*pow(10,len-1)%mod;
	(ans+=(tot-num+1)%mod)%=mod;
	//printf("%lld %lld %lld\n",len,tot,num);
}
LL down(LL a,LL b) {return a%b==0?a/b-1:a/b;}
LL up(LL a,LL b) {return a/b+1;}
int main()
{
	scanf("%lld",&n);
	pre[0]=1;for(LL i=1;i<=8;i++) pre[i]=pre[i-1]*10;
	if(n>9)
	{
		for(LL i=1;;i++)
		{
			if(i==t1)
			{
				t1*=10,num1++;
				if(num1*pre[num1-1]*9>=n) break;
			}
			while(cnt<n)
			{
				if(cnt+num2>n) break;
				cnt+=num2;
				r++;if(r==t2) t2*=10,num2++;
			}
			if(cnt==n) (ans+=1)%=mod;
			cnt-=num1;
			//printf("%lld %lld %lld %lld\n",i,r,cnt,ans);
		}
	}
	//printf("1:%lld %lld %lld\n",t1,num1,ans);
	for(LL i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			check(i);
			if(i*i!=n) check(n/i);
		}
	}
	//printf("2:%lld\n",ans);
	for(LL i=num1;i<=n/2;i++)
	{
		LL R=down(n,i),L=up(n,i+1);
		if(L<=R) (ans+=(R-L+1))%=mod;
		//printf("%lld %lld\n",i,ans);
	}
	printf("%lld",(ans+mod)%mod);
}

Measured memory_bytes: 3800
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll maxn = 5020;
ll n,k,a[maxn],ans,sum;
bool f[maxn];

int main()
{
    scanf("%lld%lld",&n,&k);
    for (ll i = 0; i < n; i++)
    {
        scanf("%lld",&a[i]);
        sum += min(a[i],k);
        a[i] = min(a[i],k);
    }
    sort(a,a + 1 + n);
    f[0] = 1;
    for (ll i = n; i >= 0; i--)
    {
        bool flag = true;
        for (ll j = k - 1; j >= max(0LL,k - sum); j--)
            if (f[j])
            {
                flag = false;
                break;
            }
        if (flag)
        {
            ans = i;
            break;
        }
        for (ll j = k; j >= a[i]; j--)
            if (f[j - a[i]])
                f[j] = 1;
        sum -= a[i];
    }
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 256
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 105, K = (int)1e5 + 10;
bool dp[K];
int n, k, mn_a, ar[N];

void solve () {
   for (int i = 0; i <= k; ++i) dp[i] = false;
   for (int i = 1; i <= n; ++i) dp[ar[i]] = true;

   for (int i = 0; i <= k; ++i) {
      for (int j = 1; j <= n; ++j) {
         if (i + ar[j] <= k) dp[i+ar[j]] |= (!dp[i]);
      }
   }

   // for (int i = 0; i <= k; ++i) debug(i, dp[i]);
   cout << (dp[k] ? "First\n" : "Second\n");
}

signed main() {
   IOS; PREC;
   cin >> n >> k;

   mn_a = 0;
   for (int i = 1; i <= n; ++i) cin >> ar[i], mn_a = min(mn_a, ar[i]);
   solve();

   return EXIT_SUCCESS;
}


Measured memory_bytes: 384
import string
n = int(input())
S = [sorted(list(input())) for _ in range(n)]

ans = ""
ref = 'abcdefghijklmnopqrstuvwxyz'
lst = [51]*26

for i in range(26):
    for j in range(n):
        lst[i] = min(lst[i], S[j].count(ref[i]))
    if 0 < lst[i] < 51:
        ans = ans + ref[i]*lst[i]

print(ans)


Measured memory_bytes: 9772
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int a[12][12];
int main(){
  string a,b;cin>>a>>b;
  rep(i,a.size()){
    char c=a[a.size()-1];
    a.insert(a.begin(),c);
    a.pop_back();
    if(a==b){
      cout<<"Yes";
      return 0;
  }
  }
  cout<<"No";
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=500005,inf=1e9;
typedef long long ll;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct Edg{
	int nxt,poi;
}e[N<<1];
int fa[N],a[N],b[N],first[N],l=0,c[N];
ll f[N],g[N];
bool vis[N];
bool cmp(int x,int y){
	return a[x]<a[y];
}
void addedge(int u,int v){
	l++;
	e[l].nxt=first[u];
	e[l].poi=v;
	first[u]=l;
}
int find(int x){
	return (fa[x]==x)?x:fa[x]=find(fa[x]);
}
int main(){
	int n=read(),m=read();
	for (int i=1;i<=n;i++){
		a[i]=read(),b[i]=read(); a[i]=max(0,a[i]-b[i]);
	}
	for (int i=1;i<=m;i++){
		int u=read(),v=read();
		addedge(u,v); addedge(v,u);
	}
	for (int i=1;i<=n;i++){
		fa[i]=i; c[i]=i; f[i]=a[i]; g[i]=b[i];
	}
	sort(c+1,c+1+n,cmp);
	for (int i=1;i<=n;i++){
		int u=c[i]; vis[u]=1;
		for (int p=first[u];p;p=e[p].nxt){
			int v=e[p].poi;
			if (!vis[v]) continue;
			int x=find(u),y=find(v);
			if (x==y) continue;
			g[x]+=g[y]; fa[y]=x;
			f[x]=min(f[x],f[y]+max(0ll,a[u]-f[y]-g[y]));
		}
	}
	printf("%lld\n",f[c[n]]+g[c[n]]);
	return 0;
}

Measured memory_bytes: 15488
#include <iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<tuple>
#include<algorithm>
#include<cmath>

#define rep(i,n) for (int i =0; i<(n); ++i)
using namespace std;

int main() {
	int P, Q, R;
	cin >> P >> Q >> R;
	int pq = P + Q;
	int pr = P + R;
	int qr = Q + R;

	cout << min({ pq, pr, qr });

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char aa,bb,cc,dd;
  cin>>aa>>bb>>cc>>dd;
  int a=aa-'0',b=bb-'0',c=cc-'0',d=dd-'0';
  if(a+b+c+d==7)
    cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7";
  else if(a+b+c-d==7)
    cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7";
  else if(a+b-c+d==7)
    cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7";
  else if(a-b+c+d==7)
    cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7";
  else if(a+b-c-d==7)
    cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7";
  else if(a-b+c-d==7)
    cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7";
  else if(a-b-c+d==7)
    cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7";
  else
    cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mo 998244353
#define N 410
using namespace std;
string s;
ll dp[N][N][N],ans,d[N][N][2];
int k,n,ma,a[N],na,m;
void add(ll &x,ll y){x=(x+y)%mo;}
int main(){
	cin>>s>>k;n=s.length();k=min(k,n);
	for (int i=1,la=0;i<=n;i++){if (s[i-1]=='0'){a[++na]=i-la-1;la=i;}if (i==n)a[++na]=i-la;}
	n=na;for (int i=1;i<=na;i++)m+=a[i];
	dp[0][0][0]=1;
	for (int i=0,s=0;i<na;i++,s+=a[i]){
		for (int j=s;j<=m;j++){
			for (int l=0;l<=k;l++){
				add(d[j][l][0],dp[i][j][l]);
				if (j+a[i+1]<=m){
					add(d[min(m+1,j+a[i+1])][l][0],mo-dp[i][j][l]);
					add(d[j+a[i+1]][l][1],dp[i][j][l]);
				}
			}
		}
		for (int j=0;j<=m;j++){
			for (int l=0;l<=k;l++){
				add(d[j+1][l][0],d[j][l][0]),add(d[j+1][l+1][1],d[j][l][1]);
				add(dp[i+1][j][l],d[j][l][0]+d[j][l][1]);d[j][l][0]=d[j][l][1]=0;
			}
		}
	}
	for (int i=0;i<=k;i++)add(ans,dp[n][m][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 77716
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		
		int cost_0_X = 0;
		int cost_X_N = 0;
		
		int[] A = new int[ M ];
		for(int i = 0; i < M ; i ++){
			A[ i ] = sc.nextInt();
			if(A[ i ] <= X ){
				cost_0_X ++ ;
			} else{
				cost_X_N ++;
			}
		}
		System.out.println(Math.min(cost_0_X , cost_X_N ));

	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, DP[4001][4001], R[2001], B[2001];
string S;


int main() {
	cin >> S;
	N = S.size();
	for (int i = 1; i <= N; ++i) {
		switch (S[i - 1]) {
		case '0':
			R[i] = 2;
			break;
		case '1':
			R[i] = B[i] = 1;
			break;
		case '2':
			B[i] = 2;
			break;
		}
		R[i] += R[i - 1];
		B[i] += B[i - 1];
	}
	DP[0][0] = 1;
	for (int i = 0; i < N * 2; ++i) {
		for (int j = max(0, i - B[min(i, N)]); j <= R[min(i, N)] && j <= i; ++j) {
			if (j + 1 <= R[min(i + 1, N)]) {
				DP[j + 1][i - j] = (DP[j + 1][i - j] + DP[j][i - j]) % 998244353;
			}
			if (i - j + 1 <= B[min(i + 1, N)]) {
				DP[j][i - j + 1] = (DP[j][i - j + 1] + DP[j][i - j]) % 998244353;
			}
		}
	}
	cout << DP[R[N]][B[N]] << endl;
	return 0;
}

Measured memory_bytes: 60416
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a+b){
    vector<int>in(a+b);
    rep(i,a)cin>>in[i];
    loop(i,a,a+b)cin>>in[i];
    sort(all(in));
    int maxx=in[0];
    rep(i,a+b-1)maxx=max(maxx,in[i+1]-in[i]);
    cout<<maxx<<endl;
  }
}

Measured memory_bytes: 1292
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define Point pair<double, double>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

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

  int a, b; cin >> a >> b;
  cout << a*b/2 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<set>
using namespace std;
int D;
int c[26];
int S[365][26];
int t[365];
set<int>id[26];
main()
{
	scanf("%d",&D);
	for(int i=0;i<26;i++)
	{
		scanf("%d",&c[i]);
		id[i].insert(-1);
	}
	for(int i=0;i<D;i++)for(int j=0;j<26;j++)scanf("%d",&S[i][j]);
	int ans=0;
	for(int i=0;i<D;i++)
	{
		scanf("%d",&t[i]);
		t[i]--;
		ans+=S[i][t[i]];
		id[t[i]].insert(i);
		for(int j=0;j<26;j++)ans-=c[j]*(i-*id[j].rbegin());
	}
	for(int i=0;i<26;i++)id[i].insert(D);
	int M;scanf("%d",&M);
	for(;M--;)
	{
		int d,q;scanf("%d%d",&d,&q);d--,q--;
		ans-=S[d][t[d]];
		ans+=S[d][q];
		set<int>::iterator it=id[t[d]].lower_bound(d);
		it=id[t[d]].erase(it);
		{
			int r=*it;
			int l=*--it;
			ans-=c[t[d]]*(r-d)*(d-l);
		}
		it=id[q].lower_bound(d);
		{
			int r=*it;
			int l=*--it;
			ans+=c[q]*(r-d)*(d-l);
		}
		it++;
		id[q].insert(it,d);
		t[d]=q;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
typedef pair<int64_t, int64_t> P;
vector<P> to[MAXN];
vector<int64_t> d(MAXN, -1);

void dfs(int v)
{
  for (auto u : to[v])
  {
    if (d.at(u.first) == -1)
    {
      d.at(u.first) = d.at(v) + u.second;
      dfs(u.first);
    }
  }
}

int main()
{
  int64_t N, a, b, c;
  cin >> N;
  for (int i = 0; i < N - 1; i++)
  {
    cin >> a >> b >> c;
    a--, b--;
    to[a].emplace_back(b, c);
    to[b].emplace_back(a, c);
  }
  int Q, K, x, y;
  cin >> Q >> K;
  K--;
  d[K] = 0;
  dfs(K);
  for (int i = 0; i < Q; i++)
  {
    cin >> x >> y;
    x--, y--;
    cout << d[x] + d[y] << endl;
  }
}

Measured memory_bytes: 15600
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll A, B, M;
  cin >> A >> B >> M;
  vll a(A);
  rep(i, A){
    cin >> a[i];
  }
  vll b(B);
  rep(i, B){
    cin >> b[i];
  }
  vll x(M), y(M), c(M);
  rep(i, M){
    cin >> x[i] >> y[i] >> c[i];
    x[i]--;
    y[i]--;
  }
  ll ans = *min_element(ALL(a))+*min_element(ALL(b));
  rep(i, M){
    chmin(ans, a[x[i]]+b[y[i]]-c[i]);
  }
  print(ans);
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456, mod = 1000000007;
int f[4][maxn];
int main(){
	string s; cin >> s;
	int ans = 0;
	f[0][0] = 1;
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j < 4; j++){
			f[j][i + 1] += f[j][i];
			if(f[j][i + 1] >= mod) f[j][i + 1] -= mod;
		}
		if(s[i] == 'A') (f[1][i + 1] += f[0][i]) %= mod;
		else if(s[i] == 'B') (f[2][i + 1] += f[1][i]) %= mod;
		else if(s[i] == 'C') (f[3][i + 1] += f[2][i]) %= mod;
		else {
			for(int j = 0; j < 4; j++){
				int add = f[j][i] + f[j][i]; if(add >= mod) add -= mod;
				f[j][i + 1] += add;
				if(f[j][i + 1] >= mod) f[j][i + 1] -= mod;
			}
			(f[1][i + 1] += f[0][i]) %= mod;
			(f[2][i + 1] += f[1][i]) %= mod;
			(f[3][i + 1] += f[2][i]) %= mod;
		}
	}
	cout << f[3][s.size()] << endl;
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main()
{
        int N;
        cin >> N;
        int *B = new int[N];
        for (int i = 0; i < N; i++)
                B[i] = 0;

        for (int i = 0; i < N - 1; i++) {
                int A;
                cin >> A;
                B[A - 1]++;
        }

        for (int i = 0; i < N; i++)
                cout << B[i] << endl;

        delete B;
        return 0;
}

Measured memory_bytes: 4032
let rec max_divisor acc i n =
  if n < i * i then acc
  else max_divisor (if n mod i = 0 then i else acc) (i + 1) n

let () = Scanf.scanf "%d" @@ fun n ->
  let i = max_divisor 1 1 n in
  Printf.printf "%d\n" @@ i + n / i - 2



Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

int N;
int main() {
	vector<int> evenNotDivBy3;
	vector<int> evenDivBy3;
	vector<int> oddMultOf3;
	for (int i = 2; i <= 30000; i++) {
		if (i % 2 == 0) {
			if (i % 3 != 0) {
				evenNotDivBy3.push_back(i);
			} else {
				evenDivBy3.push_back(i);
			}
		} else {
			if (i % 3 == 0) {
				oddMultOf3.push_back(i);
			}
		}
	}
	scanf("%d", &N);
	if (N  == 3) {
		printf("%d %d %d", 2, 5, 63);
	} else if (N == 4) { 
		printf("%d %d %d %d", 2, 5, 20, 63);
	}	else if (N <= 15000) {
		for (int i = 0; i < 2; i++) {
			printf("%d %d ", evenNotDivBy3[i], oddMultOf3[i]);
		}
		int cnt = N - 4;
		for (int i = 2; i < evenNotDivBy3.size() && cnt > 1; i += 2) {
			printf("%d %d ", evenNotDivBy3[i], evenNotDivBy3[i + 1]);
			cnt -= 2;
		}
		for (int i = 2; i < oddMultOf3.size() && cnt > 1; i += 2) {
			printf("%d %d ", oddMultOf3[i], oddMultOf3[i + 1]);
			cnt -= 2;
		}
		if (N % 2) {
			printf("%d ", evenDivBy3[0]);		
		}
	} else {
		int cnt = N;
		for (int n : evenNotDivBy3) {
			printf("%d ", n);
			cnt--;
		}
		for (int n : oddMultOf3) {
			printf("%d ", n);
			cnt--;
		}
		for (int i = 0; i < cnt; i++) {
			printf("%d ", evenDivBy3[i]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 512