akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int h, w, d;
    cin >> h >> w >> d;

    int x[90001], y[90001], sum[90001] = {};
    int in;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> in;
            x[in] = i, y[in] = j;
        }
    }

    for(int i = d+1; i <= h*w; i++){
        sum[i] = sum[i-d] + abs(x[i]-x[i-d]) + abs(y[i]-y[i-d]);
    }

    int q;
    cin >> q;

    int l, r;
    for(int i = 0; i < q; i++){
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(void)
{
	for (int u = 0; u, 50; u++)
	{
		long long n;

		cin >> n;
		if (n == 0)
		{
			return 0;
		}

		for (long long i = 0; i < 100000; i++)
		{
			if (n == 1)
			{
				cout << i << endl;
				break;
			}
			else if (n % 2 == 0)
			{
				n = n / 2;
			}
			else
			{
				n = (n * 3) + 1;
			}
		}
	}
}




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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
int a[N];
set<int> S;

int main()
{
	scanf("%d%d", &n, &m);
	
	int mina = 0x3f3f3f3f, maxd = 0;
	for (int i = 0; i < n; i ++ )
	{
		scanf("%d", &a[i]);
		mina = min(mina, a[i]);
		maxd = max(maxd, a[i] - mina);
	}

	int res = 0;
	for (int i = 0; i < n; i ++ )
	{
		if (S.count(a[i] - maxd)) res ++ ;
		S.insert(a[i]);
	}
	
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 5376
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int ta[100010],to[100010],co[100010],nt[100010],it[100010],l[100010];
void mklsb(int v,int e,int *a,int *b,int *c){
  int i;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];      
    co[ta[b[i]]=i+e]=0;
  }
}
int MF(int e,int s,int t,int min){
  if(s==t||min==0)return min;
  int i,r;
  for(;it[s]+1;it[s]=nt[it[s]]){
    if(l[s]>=l[to[it[s]]])continue;
    r=MF(e,to[it[s]],t,MIN(min,co[it[s]]));
    co[it[s]]-=r;
    co[(it[s]+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
int maxf(int v,int e,int s,int g){
  int i,a=0,q[100010],t,r,c=3;
  while(1){
    q[0]=s;
    for(i=t=0;i<v;i++)l[i]=-1;
    l[q[0]]=0;
    for(r=1;r-t;t++){
      for(i=ta[q[t]];i+1;i=nt[i]){
	if(co[i]==0||l[to[i]]+1)continue;
	l[to[i]]=l[q[t]]+1;
	q[r++]=to[i];
      }
    }
    if(l[g]<0)return a;
    for(i=0;i<v;i++)it[i]=ta[i];
    for(;(r=MF(e,s,g,1e9))>0;a+=r);
  }
  return a;
}
int main(){
  int n,m,i,a[100010],b[100010],c[1000010],m1,m2;
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  mklsb(n,m,a,b,c);//prls(n);
  m1=maxf (n,m,0,n-1);
  printf("%d\n",m1);
  return 0;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 1e4 + 10;
ll a[N], b[N];

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  ll sa = 0;
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    a[i] = x;
    sa += x;
  }
  ll sb = 0;
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    b[i] = x;
    sb += x;
  }
  if (sa > sb) {
    cout << "No\n";
    return 0;
  }

  ll moves_a = sb - sa;
  ll moves_b = sb - sa;
  for (int _: {0,1}) {
    for (int i = 0; i < n; i++) {
      if (a[i] < b[i]) {
        ll cur = (b[i] - a[i] + 1) / 2;
        a[i] += 2 * cur;
        moves_a -= cur;
      } else if (b[i] < a[i]) {
        ll cur = a[i] - b[i];
        b[i] += cur;
        moves_b -= cur;
      }
    }
  }

  if (moves_a < 0 || moves_b < 0 || moves_a * 2 != moves_b) {
    cout << "No\n";
    return 0;
  }

  cout << "Yes\n";

  return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

int main(void){
    int N;
    cin>>N;
    double ans=0.0;
    for(int i=0;i<N;i++){
        double A;
        cin>>A;
        ans+=1/A;
    }
    ans=1/ans;
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int H,W,N; cin>>H>>W>>N;
	vector<int> a;
	rep(i,N){
		int t; cin>>t;
		rep(j,t){
			a.push_back(i+1);
		}
	}
	vector<vector<int>> ans(H,vector<int> (W));
	rep(i,H){
		vector<int> e_ans(W);
		rep(j,W)e_ans[j] = a[i*W+j];
		if(i%2==1)reverse(all(e_ans));
		ans[i] = e_ans;
	}
	rep(i,H){show(ans[i]);}
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    
    vector<vector<int>> v(3, vector<int>(3));
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> v[i][j];
        }
    }
    int N; cin >> N;
    for (int i = 0; i < N; ++i) {
        int num; cin >> num;
        for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) if (v[i][j] == num) v[i][j] = -1;
    }
    
    bool ans = (v[0][0] == -1 && v[0][1] == -1 && v[0][2] == -1) ||
               (v[1][0] == -1 && v[1][1] == -1 && v[1][2] == -1) ||
               (v[2][0] == -1 && v[2][1] == -1 && v[2][2] == -1) ||
               (v[0][0] == -1 && v[1][0] == -1 && v[2][0] == -1) ||
               (v[0][1] == -1 && v[1][1] == -1 && v[2][1] == -1) ||
               (v[0][2] == -1 && v[1][2] == -1 && v[2][2] == -1) ||
               (v[0][0] == -1 && v[1][1] == -1 && v[2][2] == -1) ||
               (v[0][2] == -1 && v[1][2] == -1 && v[2][2] == -1) ||
               (v[0][2] == -1 && v[1][1] == -1 && v[2][0] == -1);
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

long long *fact, *inv;

template <typename T, typename U, typename V>
auto pow(T x_, U n_, V mod_) {
    using R = std::common_type_t<T, U, V>;
    R ret = 1, x = x_, n = n_, mod = mod_;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <typename T, typename U>
auto inverse(T x, U p) { return pow(x, p - 2, p); }

void init_factorial(int n, long long mod) {
    fact = new long long[n + 1];
    inv = new long long[n + 1];
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
    constexpr i64 mod = 998244353;
    int n, m;
    std::cin >> n >> m;
    init_factorial(n + 3 * m, mod);

    i64 ret = 0;
    for (int i = 0; i <= std::min(n, m); i++) {
        int r = 3 * m - i;
        if (r & 1) continue;
        r >>= 1;
        i64 t = fact[r + n - 1] * inv[n - 1] % mod * inv[r] % mod;
        ret = (ret + t * fact[n] % mod * inv[i] % mod * inv[n - i] % mod) % mod;
    }

    for (int i = 0; i <= std::min(n, m); i++) {
        int r = m - i;
        if (r & 1) continue;
        r >>= 1;
        i64 t = fact[r + n - 1] * inv[n - 1] % mod * inv[r] % mod;
        ret = (ret + mod - t * fact[n] % mod * inv[i] % mod * inv[n - i] % mod * n % mod) % mod;
    }

    for (int i = 0; i <= std::min(n - 1, m); i++) {
        int r = m - i;
        if (r & 1) continue;
        r >>= 1;
        i64 t = fact[r + n - 2] * inv[n - 2] % mod * inv[r] % mod;
        ret = (ret + t * fact[n - 1] % mod * inv[i] % mod * inv[n - i - 1] % mod * n % mod) % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 39296
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var b = ReadLine()[0];
            var dct = new Dictionary<char, char>(){ {'A','T' },{'T','A' },{ 'C','G' },{ 'G','C'} };
            WriteLine(dct[b]);
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

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

constexpr int inf = 1e9;

vector<int> g[1005];
int val[1005], dp[1005], tmp[2][5005];

bool foo(int c) {
  if(g[c].empty()) {
    dp[c] = 0;
    return true;
  }
  for(int i : g[c]) {
    if(!foo(i))
      return false;
  }
  for(int i=0;i<=5000;i++) tmp[0][i] = tmp[1][i] = inf;
  tmp[0][0] = 0;
  for(int z : g[c]) {
    int a = val[z], b = dp[z];
    for(int i=0;i<=val[c];i++) {
      if(tmp[0][i] == inf) continue;
      if(i+a <= val[c])
        tmp[1][i+a] = min(tmp[1][i+a], tmp[0][i] + b);
      if(i+b <= val[c])
        tmp[1][i+b] = min(tmp[1][i+b], tmp[0][i] + a);
    }
    for(int i=0;i<=val[c];i++) {
      tmp[0][i] = tmp[1][i];
      tmp[1][i] = inf;
    }
  }
  dp[c] = inf;
  for(int i=0;i<=val[c];i++) {
    if(tmp[0][i] < dp[c]) dp[c] = tmp[0][i];
  }
  if(dp[c] == inf) return false;
  return true;
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=2;i<=n;i++) {
    int x;
    scanf("%d",&x);
    g[x].push_back(i);
  }
  for(int i=1;i<=n;i++) scanf("%d",val+i);
  if(foo(1)) puts("POSSIBLE");
  else puts("IMPOSSIBLE");
}


Measured memory_bytes: 384
// AOJ 0508: String With Rings
// 2017.12.3 bal4u@uu

#include <stdio.h>
#include <string.h>

int to[102][102], sz[102];
char mk[102];
int ans;

void dfs(int x, int len)
{
	int i;

	if (len > ans) ans = len;
    mk[x] = 1;
	for (i = 0; i < sz[x]; i++) {
		if (!mk[to[x][i]]) dfs(to[x][i], len+1);
    }
	mk[x] = 0;
}
 
int main()
{
    int n, m, i, a, b, min;

    while (scanf("%d", &n) && n > 0) {
		memset(sz, 0, sizeof(sz));
	    for (m = 0, i = 0; i < n; i++) {
			scanf("%d%d", &a, &b);
			if (a > m) m = a;
			if (b > m) m = b;
			a--, b--;
			to[a][sz[a]++] = b, to[b][sz[b]++] = a;
	    }
		min = 1000;
		for (i = 0; i < m; i++) if (sz[i] > 0 && sz[i] < min) min = sz[i];

		ans = 0;
		memset(mk, 0, m);
		for (i = 0; i < m; i++) if (sz[i] == min) dfs(i, 1);
		printf("%d\n", ans);
    }
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string S; cin >> S;
	if (S <= "2019/04/30") {
		cout << "Heisei" << '\n';
	} else {
		cout << "TBD" << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

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

	static class TaskD {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			List<Integer>[] adj = new List[n];
			for (int i = 0; i < n; i++) {
				adj[i] = new ArrayList<>();
			}
			for (int i = 0; i < n - 1; i++) {
				int a = in.nextInt() - 1;
				int b = in.nextInt() - 1;
				adj[a].add(b);
				adj[b].add(a);
			}
			int m = dfs(0, -1, adj);
			int ans = 31 - Integer.numberOfLeadingZeros(m);
			out.println(ans);
		}

		private int dfs(int root, int parent, List<Integer>[] adj) {
			int setBits = 0;
			int atLeastTwice = 0;
			for (int ch : adj[root]) {
				if (ch == parent) {
					continue;
				}
				int mask = dfs(ch, root, adj);
				atLeastTwice |= (setBits & mask);
				setBits |= mask;
			}
			// weight(mask) = sum(M^i) for all set bits i in mask and
			// a large number M. Find the smallest mask such that
			// weight(rootmask) > sum of weights of children's masks.
			int mask = setBits;
			if (atLeastTwice > 0) {
				mask |= (Integer.highestOneBit(atLeastTwice) << 1) - 1;
			}
			++mask;
			return mask;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



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

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

    std::vector<int> A(N+10);
    std::vector<int> B(N+10);
    for (int i = 0; i < N+1; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> B[i];

    long attackedMonster = 0;
    for (int i = 0; i < N; ++i){
        //A[i]
        attackedMonster += min(A[i], B[i]);
        //A[i+1]
        attackedMonster += min(A[i+1] , max((B[i] - A[i]),0));
        A[i+1] -= min(A[i+1] , max((B[i] - A[i]),0));
    }
    cout << attackedMonster << endl;
    return 0;
}

Measured memory_bytes: 1024
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char

main :: IO ()
main = do
  n <- readLn
  vs <- readInts
  print $ solve n vs

readInts :: IO [Int]
readInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

solve :: Int -> [Int] -> Int
solve n vs = go n (count as) (count bs)
  where (as, bs) = deal vs

count :: [Int] -> [(Int, Int)]
count = sortOn (negate . snd) . map ((,) <$> head <*> length) . group . sort

deal :: [Int] -> ([Int], [Int])
deal [] = ([], [])
deal (x:y:zs) = (x:xs, y:ys)
  where (xs, ys) = deal zs

go :: Int -> [(Int, Int)] -> [(Int, Int)] -> Int
go n [(ka0, va0)] [(kb0, vb0)]
  | ka0 == kb0 = n - va0
  | otherwise = n - va0 - vb0
go n [(ka0, va0)] ((kb0, vb0):(kb1, vb1):_)
  | ka0 == kb0 = n - va0 - vb1
  | otherwise = n - va0 - vb0
go n ((ka0, va0):(ka1, va1):_) [(kb0, vb0)]
  | ka0 == kb0 = n - va1 - vb0
  | otherwise = n - va0 - vb0
go n ((ka0, va0):(ka1, va1):_) ((kb0, vb0):(kb1, vb1):_)
  | ka0 /= kb0 = n - va0 - vb0
  | va0 + vb1 > va1 + vb0 = n - va0 - vb1
  | otherwise = n - va1 - vb0

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

#define int long long

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

const int N = 2005;

int dp[N][N];

inline void upd(int &x, int y) {
    x = max(x, y);
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x;
        a[i].y = i;
    }
    sort(all(a));
    reverse(all(a));
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < n - i; j++) {
            upd(dp[i + 1][j], dp[i][j] + a[i + j].x * abs(a[i + j].y - i));
            upd(dp[i][j + 1], dp[i][j] + a[i + j].x * abs(a[i + j].y - (n - j - 1)));
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) upd(ans, dp[i][n - i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 26328
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        int i = 1;
        int j = 0;
        while(i != 0){
            j++;
            i =  sc.nextInt();
        }
        sc.close();
        System.out.println(j);
    }
}


Measured memory_bytes: 35764
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n);
    cins(all(h));
    SORT(h);
    ll ans = INF;
    rep(i,n-k+1){
        chmin(ans,h[i+k-1]-h[i]);
    }
    PRINT(ans);
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
const long mod=1e9+7;
using namespace std;
ll dp[1<<17];
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int main()
{
	ll n,k;
	while(cin>>n>>k){
        ll rslt=0;
        for(ll i=k;i>=1;i--){
            dp[i]=power(k/i,n);
            for(ll j=i+i;j<=k;j+=i)
                dp[i]-=dp[j];
            rslt+=i*dp[i]%mod;
        }
        cout<<rslt%mod<<endl;
	}
  return 0;
}


Measured memory_bytes: 4416
#include<stdio.h>
//#include<algorithm>
//#include<math.h>
//#include<stack>
//#include<queue>
//using namespace std;

int a[100005]={0};

int main(){
	int n,i,num,p;
	while(scanf("%d",&n)==1){
		num=0;
	       for(i=0;i<n;i++){
	       	scanf("%d",&a[i]);
		   }
		   
		   if(n%2==1) p=(n-1)/2;
		   else p=n/2;
		   
		   for(i=0;i<n;i++){
		   	if(a[i]%4==0) num=num+2;
		   	else if(a[i]%2==0) num++;
		   }
		   
		   p=p*2;
		   if(num>=p) printf("Yes\n");
		   else printf("No\n");
	}
	return 0;
} 

Measured memory_bytes: 512
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){ 
	int n,k;
	cin>>n>>k; 
	string s;
	cin>>s;
	int same=0,diff=0;
	rep(i,1,sz(s)){
		if(s[i]==s[i-1]) ++same;
		else ++diff;
	}  
	cout<<same+min(2*k,diff)<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d;
    long long mp;
    cin>>a>>b>>c>>d;
    vector<long long>v;
    v.push_back(a*c);
    v.push_back(a*d);
    v.push_back(b*c);
    v.push_back(b*d);
    sort(v.begin(),v.end());
    cout<<v[3];


}


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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

struct era{
  string name;
  int fr, to;
  bool operator<(const era &x)const{
    if(fr < x.fr) return true;
    return false;
  }
  era(string name, int fr, int to) : name(name), fr(fr), to(to) {}
};

int main(){
  int n, q;
  while(cin >> n >> q and n + q){
    vector<era> eras;
    REP(i, n){
      string name; int eby, wy;
      cin >> name >> eby >> wy;
      eras.emplace_back(name, wy-eby+1, wy);
    }
    sort(ALL(eras));
    REP(i, q){
      int query; cin >> query;
      int target = -1;
      REP(j, eras.size()-1) if(eras[j+1].fr > query){ target = j; break; }
      if(target == -1){
        if(eras[eras.size()-1].to < query or query < eras[eras.size()-1].fr) cout << "Unknown" << endl;
        else cout << eras[eras.size()-1].name << " " << query - eras[eras.size()-1].fr + 1 << endl;
        continue;
      }
      if(eras[target].to < query or query < eras[target].fr) cout << "Unknown" << endl;
      else cout << eras[target].name << " " << query - eras[target].fr + 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3080
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
x=0
for i in range(N):
  if A[i]+A[i+1]<=B[i]:
    x+=A[i]+A[i+1]
    A[i+1]=0
  elif A[i]>=B[i]:
    x+=B[i]
  elif A[i]<B[i]:
    x+=B[i]
    A[i+1]=A[i+1]-(B[i]-A[i])
print(x)

Measured memory_bytes: 18476
#include<stdio.h>
int main()
{
    int a[100],i,j,n,b[100];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(j=0,i=n-1;j<n,i>=0;j++,i--)
    {
        b[j]=a[i];
    }

    for(j=0;j<n;j++)
    {   if(j==(n-1))
        {
            printf("%d",b[j]);
        }
        else
        printf("%d ",b[j]);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    int n, p;
    while(cin >> n >> p, n) {
        const int total_p = p;
        int current_player = 0;
        vector<int> v(n);
        int winner = 0;
        while(true) {
            if(p > 0) {
                ++v[current_player];
                --p;
                current_player = (current_player+1)%n;
            } else if(p == 0) {
                if(v[current_player] == total_p) {
                    winner = current_player;
                    break;
                } else {
                    p += v[current_player];
                    v[current_player] = 0;
                    current_player = (current_player+1)%n;
                }
            }
        }
        cout << winner << endl;
    }
}


Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
int N, M, K;
cin >> N >> M >> K;

for( int yoko = 0; yoko <= N; yoko++ ){
for( int tate = 0; tate <= M; tate++ ){
if( yoko*(M-tate) + tate*(N-yoko) == K ){
cout << "Yes" << endl;
return 0;
}
}
}

cout << "No" << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>

int main(){
    char L;
    while(1){
        scanf("%c" , &L);
        if ( L == '\n') break;
        else{
            if (islower(L)) {
                printf("%c" ,char(toupper(L)));
            }
            else if (isupper(L)) {
                printf("%c" , char(tolower(L)));
            }
            else {
                printf("%c",L);
            }
        }
    }
    printf("%c",'\n');
    return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>

int A[1<<19];

int main()
{
	int N,Z;
	scanf ("%d",&N); Z = 1 << N;
	for (int i=0;i<Z;i++) scanf ("%d",&A[i+Z]);
	for (int i=Z-1;i>=1;i--){
		int p = A[i*2], q = A[i*2+1];
		if (p > q) A[i] = p - q;
		else if (p == q) A[i] = p;
		else A[i] = q - p;
	}
	printf ("%d\n",A[1]);

	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long LL;

const int MOD = 1e9+7;
void solve(){
    int h,a;
    cin>>h>>a;
    int ans = h/a;
    if(h%a) ans++;
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep_bit(n) for (int bit = 0; bit < (1 << n); ++bit)
using namespace std;
typedef long long ll;
typedef string str;
const ll INF = 1e18;
const int MX = 2005;
const double pi = 3.141592653589793238;

int main() {

  int n, x;
  
  while(true){
  cin >> n >> x;
  if(n==0&x==0) break;
  int cnt = 0;
  for(int i = 1; i<= n-2; ++i){
    for(int j = i+1; j<=n-1; ++j){
      for(int k = j+1; k<=n; ++k){
        if(i+j+k==x) cnt += 1;
      }
    }
  }
  cout << cnt << endl;
  }

}


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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int a[N];
long long dp[N][5];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    return true;
}

long long calc(int i, int f) {
    if (f == 0 || f == 4)
        return a[i];

    if (f == 2)
        return 1 ^ (a[i] & 1);

    return a[i] == 0 ? 2 : (a[i] & 1);
}

void solve() {
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 5; ++j) {
            dp[i][j] = static_cast<long long>(MOD) * MOD;

            for (int k = 0; k <= j; ++k)
                dp[i][j] = min(dp[i][j], dp[i - 1][k] + calc(i, j));
        }
    }

    auto ans = dp[n][0];

    for (int i = 1; i < 5; ++i)
        ans = min(ans, dp[n][i]);

    cout << ans << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 8832
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c;
float avrg;
float result;
scanf("%f %f",&a,&b);
c=a+b;
avrg=c/2;
result=ceil(avrg);
printf("%.0f\n",result);
return 0;
}


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

int main() {
    long long n, k;
    cin >> n >> k;

    long long min;
    if (n % k == 0) {
        cout << 0 << endl;
        return 0;
    }
    min = n % k;
    if (k - min < min) {
        min = k - min;
    }

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int d;
    cin>>d;
    vector<ll> c(26),t(d);
    vector<vector<int>> s(d,vector<int>(26));
    for(int i=0;i<26;i++){
        cin>>c[i];
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            cin>>s[i][j];
        }
    }
    for(int i=0;i<d;i++){
        int a;
        cin>>a;
        a--;
        t[i]=a;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        int a,b,ans=0;
        vector<int> last(26,-1);
        cin>>a>>b;
        a--;
        b--;
        t[a]=b;
        for(int j=0;j<d;j++){
            last[t[j]]=j;
            ans+=s[j][t[j]];
            for(int k=0;k<26;k++) ans-=c[k]*(j-last[k]);
        }
        cout<<ans<<endl;
    }
}

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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n; cin>>n;
        cout<<(n+1)/2;


		
		cout<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
f(x){scanf("%d",x);}a[100],l,r,p;main(c){for(;f(&r),l=r;printf("%d\n",c)){for(;c=l;)f(a+--l);for(f(a);l<r&&!++c|a[p=l+r>>1]-*a;)a[p]<*a?r=p:(l=p+1);}exit(0);}

Measured memory_bytes: 0
n=int(input())
while(n!=0):
    list={}
    sum=""
    for i in range(n):
        a,b=input().split()
        list[a]=b.rstrip()
    n=int(input())
    for i in range(n):
        s=input().rstrip()
        if s in list:
            sum+=list[s]
        else:
            sum+=s
    print(sum)
    n=int(input())

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

using namespace std;

int main()
{
    int N;
    while (cin >> N, N) {
        int a, res = -1;
        map<int, int> cnt;
        for (int i = 0; i < N; i++) {
            cin >> a;
            cnt[a]++;
            if (cnt[a] > N/2) {
                res = a;
            }               
        }
        if (res == -1) {
            cout << "NO COLOR" << endl;
        } else {
            cout << res << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4536
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>

struct Node {
  int key;
  Node *prev;
  Node *next;
};

Node *nil;

void insert(int key){
  Node *x = (Node*)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  x->prev = nil;
  nil->next = x;
}

Node* listSearch(int key){
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void deleteNode(Node *t){
  if (t == nil) {
    return ;
  }

  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void init(){
  nil = (Node*)malloc(sizeof(Node));
  nil->prev = nil;
  nil->next = nil;
}

void printList(){
  Node* cur = nil->next;
  int isf = 0;
  while (1) {
    if (cur == nil) {
      break;
    }

    if (isf++ > 0) {
      printf(" ");
    }

    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}



int main(int argc, char const *argv[]) {
  int key, n;
  int size = 0;

  char com[20];

  int np = 0;
  int nd = 0;

  scanf("%d", &n);

  init();

  for(int i = 0; i < n; i++){
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    }else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') {
          deleteFirst();
        }else if (com[6] == 'L') {
          deleteLast();
        }
      }else{
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}

Measured memory_bytes: 34396
#include<bits/stdc++.h>
using namespace std;
int cntA,cntB,cntAB;
char s[15];
signed main(){
	int n,len,ans=0;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>(s+1);len=strlen(s+1);
		for(int j=1;j<len;++j)
			ans+=(s[j]=='A' && s[j+1]=='B');
		if(s[1]=='B' && s[len]=='A') ++cntAB;
		else if(s[1]=='B') ++cntB;
		else if(s[len]=='A') ++cntA;
	}
	if(cntAB){
		ans+=cntAB-1+(cntA>0)+(cntB>0);
		if(cntA>0) --cntA;
		if(cntB>0) --cntB;		
	} 
	ans+=min(cntA,cntB);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n,k,q;	cin >> n >> k >> q;
    vector<int>a(q);
    rep(i, q)	cin >> a[i];
    //solve
    vector<int>count(n);    //正解した回数
    rep(i, q)	 count[a[i]-1]++;
    rep(i, n){
	if(k-q+count[i] > 0){
	    cout << "Yes" << endl;
	}else{
	    cout << "No" << endl;
	}
    }
}


Measured memory_bytes: 1408
//https://atcoder.jp/contests/agc047/submissions/15789685
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

struct Node{
    bool isend;
    unordered_map<char, Node*> m;
    Node(): isend(false){}
};

class Trie{
    public:
        Node* root;
        Trie(): root(new Node()){
            ;
        }
        void insert(string word){
            Node *node = root;
            rep(i,word.size()){
                char c = word[i];
                if(node->m.count(c) == 0) node->m[c] = new Node();
                node = node->m[c];
            }
            node->isend = true;
        }
        bool search(string word){
            Node *node = root;
            for(char c : word){
                if(node->m.count(c) == 0) return false;
                node = node->m[c];
            }
            return node->isend;
        }
        bool startsWith(string prefix){
            Node *node = root;
            for(char c : prefix){
                if(node->m.count(c) == 0) return false;
                node = node->m[c];
            }
            return true;
        }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> ss(n);
    rep(i,n) cin >> ss[i];
    vector<vector<int>> ds(n);
    rep(i,n){
        int p = 0;
        rep(j,ss[i].size()){
            p |= (1<<(ss[i][j] - 'a'));
            ds[i].emplace_back(p);
        }
        reverse(ds[i].begin(), ds[i].end());
    }
    rep(i,n) reverse(ss[i].begin(), ss[i].end());
    Trie t;
    rep(i,n) t.insert(ss[i]);
    ll ans = 0;
    rep(i,n){
        Node *node = t.root;
        rep(j,ss[i].size()-1){
            char c = ss[i][j];
            rep(k,26){
                char d = char('a'+k);
                if(d == c) continue;
                if(!(ds[i][j] & (1<<k))) continue;
                if(node->m.count(d) == 0) continue;
                if(!node->m[d]->isend) continue;
                ++ans;
            }
            if(node->m.count(c) == 0) break;
            node = node->m[c];
            if(node->isend) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

int main(void)
{
    unsigned int N; // the number of monsters
    unsigned int K; // the number of special move
    unsigned int H[200000]; // life point of monsters
    unsigned int i;
    long int attack = 0;
    scanf("%d %d", &N, &K);
    for (i = 0; i < N; i++)
    {
        scanf("%d", &H[i]);
    }
    // Sorting array by ascending order by quick sort library
    qsort(H, N, sizeof(int), compare_int);
    // for (i = 0; i < N; i++)
    //     {
    //         printf("%d ", H[i]);
    //     }
    for (i = K; i < N; i++)
    {
        // printf("H[%d] = %d\n", i, H[i]);
        attack = attack + H[i];
    }
    printf("%ld", attack);
    return (0);
}

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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18;


int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  

    int n, m;
    cin >> n >> m;
    int k;
    cin >> k;
    int a[k + 1];
    FOR(i,1,k) {
        cin >> a[i];
    }
    bool dir = 1;
    std::vector<pair<int,int>> path;
    FOR(i,1,n){
        if(dir){
            for(int j = 1; j <= m; j++){
                path.push_back({i,j});
            }
        }else{
            for(int j = m; j >= 1; j--){
                path.push_back({i,j});
            }
        }
        dir ^= 1;
    }

    int which = 1;
    int ans[n + 1][m + 1];

    for(auto [x,y] : path){
        while(a[which] == 0)
            ++which;
        ans[x][y] = which;
        --a[which];
    }
    FOR(i,1,n) FOR(j,1,m) cout << ans[i][j] << " \n"[j == m];
}


Measured memory_bytes: 3868
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

const uint64_t MOD = 1e+9 + 7;

class ModuloOps
{
private:
  std::vector<uint64_t> _fact, _fact_inv;

  void _calc_fact(uint64_t n)
  {
    for (uint64_t i = 2; i <= n; ++i) {
      _fact[i] = (_fact[i - 1] * i) % MOD;
      _fact_inv[i] = inv(_fact[i]);
    }
  }

public:
  ModuloOps(uint64_t n)
  {
    _fact = std::vector<uint64_t>(n + 1);
    _fact_inv = std::vector<uint64_t>(n + 1);

    _fact[0] = 1;
    _fact[1] = 1;
    _fact_inv[0] = 1;
    _fact_inv[1] = 1;

    _calc_fact(n);
  }

  uint64_t power(uint64_t x, uint64_t y) const
  {
    if (y <= 1) {
      return (y == 0) ? 1 : (x % MOD);
    }

    uint64_t w = power(x, y >> 1);
    uint64_t z = (w * w) % MOD;

    if (y % 2 == 1) {
      z = (x * z) % MOD;
    }

    return z;
  }

  uint64_t inv(uint64_t n) const { return power(n, MOD - 2); } 

  uint64_t fact(uint64_t n) const { return _fact[n]; }
  uint64_t fact_inv(uint64_t n) const { return _fact_inv[n]; }

  uint64_t perm(uint64_t n, uint64_t k) const {
    return (_fact[n] * _fact_inv[n - k]) % MOD;
  }

  uint64_t comb(uint64_t n, uint64_t k) const {
    return (perm(n, k) * _fact_inv[k]) % MOD;
  }

  uint64_t prem_rep(uint64_t k, uint64_t l) const
  {
    uint64_t x = _fact[k + l];
    x = (x * _fact_inv[k]) % MOD;
    x = (x * _fact_inv[l]) % MOD;
    return x;
  }

  uint64_t prem_rep(const std::vector<uint64_t> &a) const
  {
    uint64_t n = std::accumulate(a.begin(), a.end(), 0);
    uint64_t x = _fact[n];
    for (uint64_t y : a) {
      x = (x * _fact_inv[y]) % MOD;
    }
    return x;
  }

  uint64_t comb_rep(uint64_t n, uint64_t k) const {
    return comb(n + k - 1, k);
  }
};

int main(int argc, char **argv)
{
  uint64_t N, M, K;
  std::cin >> N >> M >> K;
  
  ModuloOps mod_ops(4 * 1e+5);
  
  uint64_t S = 0;
  
  N_TIMES(p, M) {
    uint64_t Nsq = (N * N) % MOD;
    uint64_t x = ((M - p) * Nsq) % MOD;
    S = (S + ((x * p) % MOD)) % MOD;
  }
  
  N_TIMES(q, N) {
    uint64_t Msq = (M * M) % MOD;
    uint64_t y = ((N - q) * Msq) % MOD;
    S = (S + ((y * q) % MOD)) % MOD;
  }
  
  std::cout << ((S * mod_ops.comb(N * M - 2, K - 2)) % MOD) << std::endl;
  
  return 0;
}

Measured memory_bytes: 6528
fun main(args: Array<String>) {
    val (h,w) = readLine()!!.split(" ").map(String::toInt)
    var p : MutableList<String> = mutableListOf()
    repeat(h) {p.add(readLine()!!)}
    p.forEach {
        println(it)
        println(it)
    }

}

Measured memory_bytes: 35988
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main
{
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		int N = Integer.parseInt(st.nextToken()); int K = Integer.parseInt(st.nextToken());
		
		int[] a = new int[N];
		st = new StringTokenizer(br.readLine());
		for(int i=0; i<N; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		
		boolean[] dp = new boolean[K+1]; //true if next turn wins
		dp[0] = false;
		for(int i=1; i<=K; i++) {
			if(i>=a[0]) {
				for(int x: a) {
					if(i-x<0) break;
					if(!dp[i-x]) {
						dp[i] = true;
						break;
					}
				}
			}else {
				dp[i] = false;
			}
		}

		if(dp[K]) {
			System.out.println("First");
		}else {
			System.out.println("Second");
		}
		
	}
}


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

static const int MAX = 5001;
std::vector<int> Graph[MAX];
std::stack<int> outs;
bool visited[MAX];
std::deque<std::pair<int,int> > ids;
int indegree[MAX];
int V;
bool isMulti;

bool compare(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    return a.second < b.second;
}

void dfs(int current) {
    visited[current] = true;
    int cnt = 0;
    for (unsigned long i = 0; i < Graph[current].size(); i++) {
        if(--indegree[Graph[current][i]] == 0) cnt++;
    }
    if (cnt > 1) isMulti = true;

    for (unsigned long i = 0; i < Graph[current].size(); i++) {
        int next = Graph[current][i];
        if (!visited[next]) {
            dfs(next);
        }
    }
    outs.push(current);
}


int main()
{
    int won, lost, M;
    std::scanf("%d", &V);
    ids.resize(V+1);
    std::scanf("%d", &M);
    ids[0] = std::make_pair(0, -1);
    for (int i = 1; i <= V; i++) {
        indegree[i] = 0;
        visited[i] = false;
        ids[i] =std::make_pair(i, 0);
    }

    for (int i = 0; i < M; i++) {
        std::scanf("%d %d", &won, &lost);
        Graph[won].push_back(lost);
        indegree[lost]++;
        ids[lost].second++;
    }

    std::sort(ids.begin(), ids.end(), compare);

    isMulti = false;
    for (int i = 1; i <= V; i++) {
        if (!visited[ids[i].first]) {
            dfs(ids[i].first);
        }
    }


    while (!outs.empty()) {
        std::cout << outs.top() << std::endl;
        outs.pop();
    }
    std::cout << isMulti << std::endl;

    return 0;
}



Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int l=1;
  int r=1e9+1;
  /*rep(i,0,n){
    r=min(r,a[i]);
  }
  r++;*/
  while(l<r){
    int x=(l+r)/2;
    ll cur=0;
    //bool p=true;
    rep(i,0,n){
      /*if(a[i]<x){
        p=false;
        break;
      }*/
      if(a[i]>x){
        cur+=(a[i]-1)/x;
      }
    }
    if(cur>k){
      l=x+1;
    }
    else{
      r=x;
    }
  }
  cout<<l<<endl;
}

Measured memory_bytes: 4212
n = int(input())
public_hall = [[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]]
input_info = []

for b in range(4):
    for f in range(3):
        for r in range(10):
            public_hall[b][f].append(0)

for i in range(n):
    input_info.append(input().split())
    input_info[i] = list(map(int, input_info[i]))

for j in range(n):
    public_hall[input_info[j][0] - 1][input_info[j][1] - 1][input_info[j][2] - 1] += input_info[j][3]

for k in range(4):
    for l in range(3):
        for m in range(10):
            print('', public_hall[k][l][m],end='')
        print()
    if k != 3:
        print('#' * 20)

Measured memory_bytes: 7688
#include<stdio.h>
int main()
{
    int x,y,a,b,r;
    scanf("%d%d%d%d%d",&x,&y,&a,&b,&r);
    if (a>0 && b>0 && r>0 && a<100 && b<=100 && r<=100  && x>=-100 && x<=100 && y>=-100 && y<=100){


    if(a+r<=x && b+r<=y){
        printf("Yes\n");}

        else {
            printf("No\n");
        }
        }
        else printf("No\n");

}



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

int a[20],b[20];
int main(){
	int n;cin>>n;
	rep(i,n)scanf("%d",&a[i]);
	rep(i,n)scanf("%d",&b[i]);
	vector<int>v;
	rep(i,n)v.push_back(i);
	int Min=INT_MAX;
	do{
		int cnt=0;
		rep(i,n){
			int j=v[i],k;
			if(a[v[i]]==0){
				k=v[(i+1)%n];
			}
			else{
				k=v[(i+n-1)%n];
			}
			if(a[j]!=a[k])cnt+=b[j];
		}
		Min=min(Min,cnt);
	}while(next_permutation(v.begin(),v.end()));
	cout<<Min<<endl;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  
  vector<pair<int,int>> data(N);
  for(int i=0;i<N;i++) cin >> data[i].first >> data[i].second;
  
  sort(data.begin(),data.end());
  
  long yen;
  int count;
  int i=0;
  while(count<M) {
    for(int j=0; j<data[i].second; j++) {
      if(count==M) break;
      yen+=data[i].first;
      count++;
    }
    if(count==M) break;
    i++;
  }
  
  cout << yen << endl;
 }

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

const int N = 500054;

int n, q, D;
int f[N], d[N];
bool ans[N];

int main() {
	int i;
	scanf("%d%d", &n, &D), f[n] = 1;
	for (i = 1; i <= n; ++i) scanf("%d", d + i);
	for (i = n; i > 1; --i) f[i - 1] = (d[i] < 2 * f[i] ? d[i] : 0) + f[i];
	for (i = 1; i <= n; ++i) ans[i] = f[i] <= D, d[i] < 2 * D && (D = abs(D - d[i]));
	for (scanf("%d", &q); q; --q) scanf("%d", &i), puts(ans[i] ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define int long long
using namespace std;

double solve(int x) {
	int res = 0, k = x;
	while (k) {
		res += k % 10;
		k /= 10;
	}
	return (x * 1.0) / (res * 1.0);
}

signed main() {
	int n, ans = 0, base = 1;
	scanf("%lld", &n);
	while (n--) {
		while (solve(ans + base) > solve(ans + base * 10)) {
			base *= 10;
		}
		ans += base;
		printf("%lld\n", ans);
	}
	return 0;
}

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

#define NL '\n'
#define C char
#define D double
#define F float
#define S string
#define sz(x) x.size()
#define INF LONG_LONG_MAX
#define PI (2.0*acos(0.0))
#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

/*LL gcd(LL a,LL b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}*/


int main()
{
    S s;
    cin>>s;
    int x = sz(s);
    for(int i=0; i<x; i++)
        cout<<"x";
}


Measured memory_bytes: 256