akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

struct Item
{
  int w;
  int v;
};

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N, W;
  cin >> N >> W;
  vector<Item> items(N);
  for(auto& item : items)
  {
    cin >> item.w >> item.v;
  }
  
  vector<vector<int64_t> > dp(N + 1, vector<int64_t>(W + 1));
  
  for(int i = 0; i <= N; ++i)
  {
    dp[i][0] = 0;
  }
  
  for(int i = 0; i <= W; ++i)
  {
    dp[0][i] = 0;
  }
  
  for(int i = 1; i <= N; ++i)
  {
    for(int j = 1; j <= W; ++j)
    {
      int id = j - items[i - 1].w;
      dp[i][j] = dp[i - 1][j];
      if(id >= 0)
      {
        dp[i][j] = max(dp[i][j], dp[i - 1][id] + items[i - 1].v);
      }
    }
  }
  
  cout << dp[N][W] << "\n";
  
  return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    string s;cin>>s;
    ll now=0;
    string a[4]={"dream","dreamer","erase","eraser"};
    queue<ll> q;
    q.push(0);
    while(q.size()>0){
        ll x=q.front();q.pop();
        //cout<<x<<endl;
        if(x==s.size()){
            cout<<"YES"<<endl;
            return 0;
        }
        rep(i,0,3){
            if(x+(ll)a[i].size()-1>s.size()-1){
                continue;
            }else{
                bool bol=true;
                rep(j,x,x+(ll)a[i].size()-1){
                    if(s[j]!=a[i][j-x]){
                        bol=false;
                    }
                }
                if(bol){
                    q.push(x+(ll)a[i].size());
                }
            }
        }
    }
    cout<<"NO"<<endl;
    
    return 0;
}




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

int c[4][4];
int main(){
    for(int i=1; i<=3; ++i)
        for(int j=1; j<=3; ++j)
            cin >> c[i][j];
    int b[4], a[4];
    b[3] = c[2][3]+c[3][1]-c[2][1]-c[3][2];
    b[2] = c[2][2]+c[3][1]-c[2][1]-c[3][2];
    b[1] = c[3][1]-c[3][2];
    a[3] = c[3][2]-b[2];
    a[2] = c[2][1]-b[1];
    a[1] = c[1][1]-b[1];
    
    //cout << a[1] << " " << a[2] << " " << a[3] << " " << b[1] << " " << b[2] << " " << b[3] << endl;
    bool ans = true;
    for(int i=1; i<=3; ++i){
        for(int j=1; j<=3; ++j){
            if(c[i][j]!=a[i]+b[j])
                ans = false;
        }
    }
    if(ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}  


Measured memory_bytes: 256
import collections

N ,K = map(int, input().split())
A = list(map(int, input().split()))

cnt_list = []

c = collections.Counter(A)
values, counts = zip(*c.most_common())
counts = list(counts)
counts.reverse()

answer=0

if len(counts) > K:
    for i in range(len(counts)-K):
        answer += counts[i]
        
print(answer)


Measured memory_bytes: 53680
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int L = scan.nextInt();

    int sum1 = 0;
    int min = 299;
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = L + i - 1;
      int tmp2 = tmp;
      if (tmp2 < 0) {
        tmp2 = -1 * tmp2;
      }
      if (tmp2 < min) {
        min = tmp2;
        count = i;
      }
      sum1 += tmp;
    }
    System.out.println(sum1 - (L + count  - 1));
  }
}


Measured memory_bytes: 23380
n=int(input())
s=[]
for i in range(n):
    S=list(input().split())
    s.append([S[0],int(S[1]),i+1])
s.sort(key=lambda x: x[1],reverse=True)
s.sort(key=lambda x: x[0])
for i in range(n):
    print(s[i][2])

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string s;
    cin >> s;
    if (s == "A") cout << "T";
    if (s == "T") cout << "A";
    if (s == "C") cout << "G";
    if (s == "G") cout << "C";
    cout << endl;

}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

using namespace std;
int main(){
    int n,l;
    cin>>n>>l;
    // string str[n];
    vector<string> strlist;
    for(int i=0;i<n;i++){
        // cin>>str[i];
        string str;
        cin>>str;
        strlist.push_back(str);
    }
    sort(strlist.begin(),strlist.end());
    string ans="";
    for(int i=0;i<strlist.size();i++){
        // cout<<strlist[i]<<endl;
        ans+=strlist[i];
    }
    cout<<ans<<endl;
}

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

int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    c *= 2;
    vector<ll> pizza = {x, y, 0};
    ll ans = 1001001001001001001;
    for (int i = 0; i < max(x, y) + 1; ++i) {
        ans = min(ans, a * pizza[0] + b * pizza[1] + c * pizza[2]);
        if (pizza[0] != 0) pizza[0]--;
        if (pizza[1] != 0) pizza[1]--;
        pizza[2]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
#define ll  long long
#define ld  long double
 
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN=1e5 + 5;
int main() {
    string h;
    cin>>h;
    set<char> s;
    for(int i=0;i<(int)h.size();i++)
    {
        s.insert(h[i]);
    }
    s.size()==h.size()?cout<<"yes":cout<<"no";
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

from pprint import pprint
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline


def adj(i, j):
    up, down = [i - 1, j], [i + 1, j]
    left, right = [i, j - 1], [i, j + 1]
    res = []
    for i_next, j_next in up, down, left, right:
        if 0 <= i_next < height and 0 <= j_next < width:
            if [i_next, j_next] == left:
                if walls[i * 2][j - 1] == 0:
                    res.append([i_next, j_next])
            elif [i_next, j_next] == right:
                if walls[i * 2][j] == 0:
                    res.append([i_next, j_next])
            elif [i_next, j_next] == up:
                if walls[2 * i - 1][j] == 0:
                    res.append([i_next, j_next])
            else:
                if walls[2 * i + 1][j] == 0:
                    res.append([i_next, j_next])
    return res


def bfs(que, dist):
    while len(que) > 0:
        i, j = que.popleft()
        for i_next, j_next in adj(i, j):
            if dist[i_next][j_next] == -1:
                dist[i_next][j_next] = dist[i][j] + 1
                que.append([i_next, j_next])
    return dist


while True:
    width, height = map(int, input().split())
    if width == 0 and height == 0:
        break
    walls = []
    for _ in range(2 * height - 1):
        line = list(map(int, input().split()))
        walls.append(line)
    # pprint(walls)

    maze = [[-1 for j in range(width)] for i in range(height)]
    que = deque()
    dist = [[-1 for j in range(width)] for i in range(height)]

    start = [0, 0]
    que.append(start)
    dist[0][0] = 0

    dist = bfs(que, dist)
    print(dist[height - 1][width - 1] + 1)



Measured memory_bytes: 6624
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m; vector<int> a, r; vector<vector<int> > x;
int rec(int depth) {
	if (depth == m) {
		bool ok = true;
		for (int i = 0; i < m && ok; i++) {
			for (int j = 0; j < x[i].size(); j++) {
				for (int k = j + 1; k < x[i].size(); k++) {
					int diff = x[i][j] - x[i][k];
					if (-1 <= diff && diff <= 1) {
						ok = false;
					}
				}
			}
		}
		if (!ok) return m;
		vector<int> t(n);
		for (int i = 0; i < n; i++) t[i] = i;
		for (int i = 0; i < m; i++) {
			for (int j : x[i]) swap(t[j], t[j + 1]);
		}
		if (r != t) return m;
		for (int i = m - 1; i >= 0; i--) {
			if (x[i].size()) return i + 1;
		}
	}
	int ret = m;
	for (int i = 0; i < m - 1; i++) {
		x[i].push_back(a[depth]);
		ret = min(ret, rec(depth + 1));
		x[i].pop_back();
	}
	return ret;
}
int main() {
	cin >> n >> m; r.resize(n);
	for (int i = 0; i < n; i++) r[i] = i;
	a.resize(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i]; a[i]--;
		swap(r[a[i]], r[a[i] + 1]);
	}
	x.resize(m);
	cout << rec(0) << endl;
	return 0;
}

Measured memory_bytes: 3176
n = input()
inp = input()

sum = 0
order = 0

for c in inp:
  if ord(c) == ord('A'):
    order = 1
  elif ord(c) == ord('A') + order:
    order += 1
    if order == 3:
      order = 0
      sum += 1
  else:
    order = 0
print(sum)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
	int n=0, min, max,A=0,B=0;
	long int sum = 0;
	cin >> n;
	int a[10000] = { 0 };
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum = sum + a[i];
	}
	min = a[0];
	max = a[0];
	for (int i = 0; i < n; i++){
		if (min >= a[i]){
			B = min;
			min = a[i];
			a[i] = B;
		}
	}
	for (int i = 0; i < n; i++){
		if (max <= a[i]){
			A = max;
			max = a[i];
			a[i] = A;
		}
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

void solve(int n) {
    map<string, int> mp;
    rep(i, n) {
        string s, t;
        cin >> s >> t;
        mp[s]++;
        mp[t]--;
    }
    auto itr = mp.begin();
    int mx = itr->second;
    for (; next(itr) != mp.end(); itr++) {
        next(itr)->second += itr->second;
        mx = max(mx, next(itr)->second);
    }
    cout << mx << endl;
}

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

    int n;
    while (cin >> n, n) {
        solve(n);
    }

}

Measured memory_bytes: 5136
import scala.collection.mutable.ListBuffer

object Main extends App {

  private val buf = new Array[Byte](1024)
  private val input = ListBuffer.empty[Array[Int]]

  def isChar(c: Int) = 32 <= c && c <= 126
  
  @inline def reads() = {
    var sb = new StringBuilder
    var insize = System.in.read(buf)
    var i = 0
    while(i < insize){
      val c = buf(i)
      if(isChar(c)) {
        sb.append(c.toChar.toString)
        if(i + 1 == insize) {
          input += sb.toString().split(' ').map(_.toInt)
          sb.clear()
        }
      } else { // break
        input += sb.toString().split(' ').map(_.toInt)
        sb.clear()
      }
      i += 1
    }
  }
  
  reads()
  
  val buff = input.toVector
  val n = buff(0)(0)
  val a = buff(1)
  val q = buff(2)(0)
  val m = buff(3)

  def solve(i: Int, m: Int): Boolean = if(m == 0) true
  else if(i >= n) false
  else solve(i+1, m) || solve(i+1, m - a(i))

  val result = m.map(p => if(solve(0, p)) "yes" else "no")

  print(result.mkString(f"%n") + f"%n")

}


Measured memory_bytes: 44168
import heapq

N, M = list(map(int, input().split()))
price = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(price)

for i in range(M):
    max_price = -(heapq.heappop(price))
    new_price = max_price // 2
    heapq.heappush(price, -(max_price // 2))

print(-(sum(price)))

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

int get(int n, int k) {
	while (n % k) {
		int d = n / k;
		n -= ((n - k * d - 1) / (d + 1) + 1) * (d + 1);
	}
	return n / k;
}

int main() {
	int n, a, b, sg = 0;
	for (cin >> n; n--;) {
		cin >> a >> b;
		sg ^= get(a, b);
	}
	puts(sg ? "Takahashi" : "Aoki");
	return 0;
}


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

vector<bool> Eratosthenes(int n){
    vector<bool> prime(n+1, true);
    if(n >= 0) prime[0] = false;
    if(n >= 1) prime[1] = false;
    for(int i = 2; i * i <= n; i++){
        if(prime[i]){
            for(int j = i + i; j <= n; j += i) prime[j] = false;
        }
    }
    return prime;
}

int main(){
    auto prime = Eratosthenes(1e6);
    int x; cin >> x;
    for (int i = x; i < 1e6; i++) {
        if (prime[i]) {
            cout << i << "\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int main(){
	string s;
	cin>>s;
	int i=s.size(),ans=0;
	int a=-1,z=-1;
	for(i=0;i<s.size();i++){
		if(s[i]==65&&a==-1){
			a=i;
		}
		if(s[i]==90){
			z=i;
		}
	}
	cout<<z-a+1;
	return 0;
}


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

int N, M;
int A[100000];

void solve() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    map<int, int> sofar;
    sofar[0] = 1;
    LL S = 0;
    LL ans = 0;
    for (int i = 0; i < N; i++) {
        S += A[i];
        ans += sofar[S % M];
        sofar[S % M] += 1;        
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(){
  int n;
  int max=0;
  int a[111]={0};
  while(cin>>n){
    a[n]=a[n]+1;
    if(a[n]>max) max=a[n];
  }
  for(int i=1;i<101;i++){
    if(max==a[i]) cout<<i<<endl;
  }
}
 

Measured memory_bytes: 1160
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        int j = 1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == j) {
                j++;
            }
        }
        if (j == 1) {
            out.println(-1);
        } else {
            out.println(n - j + 1);
        }
    }

    public static void main(String[]$) {
        try {
            new Main().solve();
            out.flush();
        } catch (Throwable t) {
            out.flush();
            t.printStackTrace();
        }
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

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

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 46136
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, count = 0; cin >> N >> M;
  vector<int> p(M);
  vector<vector<int>> s(M, vector<int> (0));
  for(int i = 0; i < M; i++) {
    int k; cin >> k;
    for(int j = 0; j < k; j++) {
      int x; cin >> x; x--;
      s.at(i).push_back(x);
    }
  }
  for(int i = 0; i < M; i++) {
    cin >> p.at(i);
  }
  for(int i = 0; i < (1 << N); i++) {
    bitset<10> board(i);
    bool judge = false;
    for(int m = 0; m < M; m++) {
      int t = 0;
      for(int l = 0; l < s.at(m).size(); l++) {
        if(board.test(s.at(m).at(l))) t++;
      }
      if(t % 2 != p.at(m)) judge = true;
      if(judge) break;
    }
    if(judge) continue;
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
X = int(input())
f = False
i = 0
while i < 3000:
    if f:
        break
    j = i-1
    while True:
        if X < (i**5-j**5):
            break
        if X == (i**5-j**5):
            print(i, j)
            f = True
            break
        j -= 1
    i += 1


Measured memory_bytes: 9184
#include <stdio.h>
int main(void)
{
  char name[5];
  int i=0;
  scanf("%s",name);
  if(name[0]=='+'){
    i++;
  }else{
    i--;
  }
  if(name[1]=='+'){
    i++;
  }else{
    i--;
  }
  if(name[2]=='+'){
    i++;
  }else{
    i--;
  }
  if(name[3]=='+'){
    i++;
  }else{
    i--;
  }
  printf("%d",i);

  return 0;
}


Measured memory_bytes: 128
n,m=map(int,input().split())
class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum(1 for i in  self._parents if i<0)
lanper=[-1]*m
uf=UnionFind(n)
for i in range(n):
    for j in list(map(int,input().split()))[1:]:
        if lanper[j-1]==-1:lanper[j-1]=i
        else:uf.unite(lanper[j-1],i)
print("YES") if uf.group_count()==1 else print("NO")


Measured memory_bytes: 62936
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);

const int MAX=200010;


ll fac[MAX], finv[MAX], inv[MAX];

void cmbInit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}


ll cmb(int n, int k){
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


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

    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    cmbInit();
    ll ans=0;
    rep(i,n-k+1) ans=(ans-(a[i]*cmb(n-1-i,k-1))%MOD+MOD)%MOD;
    rep(i,n-k+1) ans=(ans+(a[n-1-i]*cmb(n-1-i,k-1))%MOD+MOD)%MOD;
    ans=(ans+MOD)%MOD;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 8784
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
k = a.max
c = [0] * (k + 1)

a.each do |ai|
  c[ai] += 1
end
ans = []
c.each.with_index do |ci, i|
  ci.times do
    ans << i
  end
end
puts ans.map(&:to_s).join(' ')



Measured memory_bytes: 174468
var
        a,b:byte;
begin
        readln(a,b);
        if (a=1) and (b=2) or (a=2) and (b=1) then write(3)
        else if (a=2) and(b=3) or (a=3) and (b=2) then write(1)
        else if (a=1) and (b=3) or (a=3) and (b=1) then write(2);
        readln;
end.

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

int main()
{
	int n;
	cin >> n;
	int t[ n ];
	for( int i = 0; i < n; i++ ) {
		cin >> t[ i ];
	}

	int m;
	cin >> m;
	pair< int, int > p[ m ];
	for( int i = 0; i < m; i++ ) {
		cin >> p[ i ].first >> p[ i ].second;
	}

	
	for( int i = 0; i < m; i++ ) {
		int s = 0;
		for( int j = 0; j < n; j++ ) {
			if( j + 1 == p[ i ].first ) {
				s += p[ i ].second;
			}
			else {
				s += t[ j ];
			}
		}
		cout << s << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;


int main(void){
    int N;
    cin >> N;
    printf("%d\n", N*(N-1)/2 - N/2);
    if(N % 2 == 0){
        for(int i = 1; i < N; i++){
            for(int j = i + 1; j <= N; j++){
                if(i + j != N+1) printf("%d %d\n", i, j);
            }
        }
    }
    else{
        for(int i = 1; i < N; i++){
            for(int j = i + 1; j <= N; j++){
                if(i + j != N) printf("%d %d\n", i, j);
            }
        }
    }    
    
    
}


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

#define int long long int
#define f(i,l,n) for(int i=l;i<n;i++)
#define E "\n"
#define float long double
#define M 1000000007
int32_t main()
{
	int n;
	cin >> n;
	
	map<string,int> mp;
	
	int m=0;
	f(i,0,n)
	{
		string s;
		cin >> s;
		mp[s]++;
		m=max(m,mp[s]);
	}
	
	vector<string> v;
	
	for(auto x:mp)
	{
		if(x.second==m) v.push_back(x.first);
	}
	
	sort(v.begin(),v.end());
	
	for(auto x:v) cout<<x<<E;
	
}


Measured memory_bytes: 26868
import java.io.*;
import java.util.*;
public class Main
{
  public static void main(String[] ar)throws Exception
  {
    Scanner p= new Scanner(System.in) ;
    long n= p.nextLong();
    long m= p.nextLong();
    if(n==m && n*m!=0)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}

Measured memory_bytes: 23252
using System;
public class Hello{
    public static void Main(){
        
        string str=Console.ReadLine();
        int len=str.Length;
        int count=0;
        //if(len%2==0){
            for(int i=0;i<len/2;i++){
                if(str.Substring(i,1)!=str.Substring(len-i-1,1)){
                    count++;
                    
                }
            }
        //}
        System.Console.WriteLine(count);
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    for(int i=0;i<s.length();i++) if(s[i]=='C') for(int j=i+1;j<s.length();j++) if(s[j]=='F') {cout<<"Yes"; return 0;}
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
func readIntPair() -> (Int, Int) {
    let line = readLine()!.split(separator: " ").map({Int($0)!})
    return (line[0], line[1])
}

let (X, Y) = readIntPair()
if (Y - 2 * X >= 0 && Y % 2 == 0) {
    let t = (Y - 2 * X) / 2
    print(X - t >= 0 ? "Yes" : "No")
} else {
    print("No")
}


Measured memory_bytes: 8308
s = input()
t = input()
dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
for i in range(1, len(s) + 1):
  for j in range(1, len(t) + 1):
    if s[i - 1] == t[j - 1]:
      dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1] + 1)
    else:
      dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])
u = []
while True:
  if dp[i][j] == 0:
    break
  elif dp[i - 1][j] == dp[i][j]:
    i -= 1
  elif dp[i][j - 1] == dp[i][j]:
    j -= 1
  else:
    u.append(s[i - 1])
    i -= 1
    j -= 1
print(''.join(u[::-1]))


Measured memory_bytes: 113884
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int anser = -1;

		int n = scan.nextInt();
		int m = scan.nextInt();

		int[] s = new int[m];
		int[] c = new int[m];

		for (int i = 0; i < m; i++) {
			s[i] = scan.nextInt();
			c[i] = scan.nextInt();
		}

		if(m == 0) {
			if(n == 1) {
				anser = 0;
			}
			if(n == 2) {
				anser = 10;
			}
			if(n == 3) {
				anser = 100;
			}
		}

		if (n == 1) {
			out_of_loop: for (int i = 0; i <= 9; i++) {
				for (int j = 0; j < m; j++) {
					if (i != c[j]) {
						break;
					}
					if (j == m - 1) {
						anser = i;
						break out_of_loop;
					}
				}
			}
		}

		if (n == 2) {
			out_of_loop: for (int i = 10; i <= 99; i++) {
				for (int j = 0; j < m; j++) {
					if (s[j] == 1) {
						if (i / 10 != c[j]||c[j] == 0) {
							break;
						}
					}
					if (s[j] == 2) {
						if (i % 10 != c[j]) {
							break;
						}
					}
					if (j == m - 1) {
						anser = i;
						break out_of_loop;
					}

				}
			}
		}

		if (n == 3) {
			out_of_loop: for (int i = 100; i <= 999; i++) {
				for (int j = 0; j < m; j++) {
					if (s[j] == 1) {
						if (i / 100 != c[j] || c[j] == 0) {
							break;
						}
					}
					if (s[j] == 2) {
						if (i / 10 % 10 != c[j]) {
							break;
						}
					}

					if (s[j] == 3) {
						if (i % 10 != c[j]) {
							break;
						}
					}
					if (j == m - 1) {
						anser = i;
						break out_of_loop;
					}

				}
			}
		}

		System.out.println(anser);
	}

}


Measured memory_bytes: 22868
def max(a, b)
  (a > b) ? a : b
end
def min(a,b)
  (a<b)? a : b
end

s=gets.chomp
mini=s.size
(s.size-1).times do |i|
  if s[i]!=s[i+1]
    mini=min(mini,max(s.size-1-i,i+1))
  end
end
puts mini


Measured memory_bytes: 1916
using System;
class abc146_b{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    String str = Console.ReadLine();
    for(int i=0; i<str.Length; i++){
      int temp = (int)str[i] + n;
      if(temp > (int)'Z'){
        temp = temp - (int)'Z' + (int)'A' - 1;
      }
      Console.Write((char)temp);
    }
    Console.WriteLine();
  }
}


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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/*template*/
template<class T>constexpr bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>constexpr bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
constexpr int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
constexpr int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
constexpr int32_t LCM(int32_t a, int32_t b){return a / GCD(a, b) * b;}
constexpr int64_t LCM(int64_t a, int64_t b){return a / GCD(a, b) * b;}

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7;
constexpr int32_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

//#define int int64_t

/*global*/



signed main()
{
	int n; cin >> n;
	vector<vector<int>> a(n, vector<int>(n-1));

	for(int i{}; i < n; ++i)
	{
		for (int j = 0; j < n-1; ++j)
		{
			cin >> a[i][j];
			a[i][j]--;
		}
		reverse(a[i].begin(), a[i].end());
	}

	using pi = pair<int, int>;
	vector<pi> v;

	auto make = [&](int i)
	{
		if(a[i].size() == 0) return;
		int m = a[i].back();
		if(a[m].back() == i)
		{
			pi p(i,m);
			if(p.second < p.first) swap(p.first, p.second);
			v.emplace_back(p);
		}
	};

	for(int i = 0; i < n; ++i)
	{
		make(i);
	}

	int day{};
	while(v.size() > 0)
	{
		day++;

		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());

		vector<pi> prev;
		swap(prev, v);

		for(pi p: prev)
		{
			int i = p.first; int j = p.second;
			a[i].pop_back();
			a[j].pop_back();
		}

		for(pi p: prev)
		{
			int i = p.first; int j = p.second;
			make(i);
			make(j);
		}
	}

	for(int i = 0; i < n; ++i)
	{
		if(a[i].size() != 0)
		{
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << day << '\n';
}


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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int n;
vector <int> graph[ N ];
int degree[ N ];
int mx;
bool vis[ N ];
map <int,int> ans[ N ];

int getnext( int id ) {
        return id + 1 > mx ? 1 : id + 1;
}
int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> n;
        vector <pii> edge;
        for( int i = 1; i <= n - 1; i++ ) {
                int u , v;
                cin >> u >> v;
                graph[u].push_back( v );
                graph[v].push_back( u );
                degree[u]++;
                degree[v]++;
                edge.push_back( {min( u , v ) , max( u , v )} );
                mx = max( mx , max( degree[u] , degree[v] ) );
        }
        cout << mx << endl;
        queue <pii> Q;
        Q.push( {1,0} );
        vis[1] = true;
        while( !Q.empty() ) {
                pii f = Q.front(); Q.pop();
                int cur = f.second;
                for( auto x : graph[f.first] ) {
                        if( vis[x] ) continue;
                        vis[x] = true;
                        int c = getnext( cur );
                        cur = c;
                        //trace( f.first , x , c );
                        ans[min(f.first,x)][max(f.first,x)] = c;
                        Q.push( {x,c} );
                }
        }
        for( auto x : edge ) cout << ans[x.first][x.second] << endl;
        return 0;
}










Measured memory_bytes: 16760
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
	string S;
	cin >> S;
	
	int ans = 0, i = 0;
	char c = '0';
	while(i < S.size()){
		if(c == S[i]) {
			c = '0', i++;
			if(i == S.size()) ans--;
		}
		else c = S[i];
		i++, ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
/*int main()
{
	int n; cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
//	for(int i=0;i<n;i++) cout<<a[i];
	int sum=0;
	for(int i=n-1;i>1;i--)
	{
		for(int j=i-1;j>0;j--)
		{
			if(a[i]==a[j]) continue;
			for(int k=j-1;k>=0;k--)
			{
				if(a[k]!=a[i] and a[k]!=a[j] and a[i] < (a[k] + a[j])) 
				{
					sum++;
				}
				
				if(a[k]!=a[i] and a[k]!=a[j] and a[i] >= (a[k] + a[j])) 
				{
					break;
				}
				
			}
		}
	}
	
	cout<<sum;
}

int main()
{
	int n,d,ans=0;
	cin>>n>>d;
	while(n--)
	{
		int a,b; cin>>a>>b;
		long long int fl=a*a + b*b;
		float sum=sqrt(fl);
		if(sum<=d) ans++;
		
	}
	cout<<ans;
}
int main()
{
	int n,k; cin>>n>>k;
	int a[n],sum=0;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++) sum+=a[i];
	cout<<sum; 
}

int main()
{
	int n,k; cin>>n>>k;
	k%2==0 and k>=2*n and k<=4*n ? cout<<"Yes" : cout<<"No";
}

int main()
{
	int n; cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	unsigned long long ans=1,ANS;
	vector<int>v;
	for(int i=0;i<n;i++)
	{
		ans*=a[i];
		ANS=ans;
		while(ANS)
		{
			v.push_back(ANS%10);
			ANS/=10;
		}
		if(v.size()>1000000000000000000)
		{
			cout<<"HRE";
			cout<<"-1";
			return 0;
		}
		v.clear();
	}
	cout<<ans;
}

int main()
{
	int n; cin>>n;
	string s; cin>>s;
	if(s.size()<=n) cout<<s;
	else {
		
	for(int i=0;i<n;i++) cout<<s[i];
	cout<<"...";
}}

int main()
{
	long long int a,b,c,d; cin>>a>>b>>c>>d;
	long long int sum=0,count=0;
	if(a<=d)
	{
		sum+=a;
		d-=a;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<d;
		return 0;
	}
	
		if(b<=d)
	{
		
		d-=b;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<d;
		return 0;
	}
	
		if(c<=d)
	{
		sum-=c;
		d-=c;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<sum-d;
		return 0;
	}
	
	
}
*/

int main()
{
	int n,k; cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) a[i]=0;
	while(k--)
	{
		int d; cin>>d;
		for(int i=0;i<d;i++) 
		{
			int x; cin>>x;
			a[x-1]++;
		}
	}
	//cout<<a[2];
	int ans=0;
	for(int i=0;i<n;i++) if(a[i]==0) ans++; cout<<ans;
}


Measured memory_bytes: 3184
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

struct DATA{
  string name;
  double efficient;
};

bool Compare(const DATA&, const DATA&);

int main(){
  int i, j, n;
  int t1, t2, t3, t4, t5, piece, prime, oneprime, m;
  int income, time;
  string name;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> name >> prime >> t1 >> t2 >> t3 >> t4 >> t5 >> piece >> oneprime >> m;
      income = piece * oneprime * m - prime;
      for(j=0, time=t1+t2+t3; j<m; ++j)
	time += (t4+t5);

      _data.name = name;
      _data.efficient = (double)income / time;
      data.push_back(_data);
    }

    sort(data.begin(), data.end(), Compare);

    for(i=0; i<data.size(); ++i)
      cout << data[i].name << endl;
    cout << "#" << endl;

    data.clear();
  }
  return 0;
}

bool Compare(const DATA& x, const DATA& y){
  if(x.efficient == y.efficient)
    return x.name < y.name;
  else
    return x.efficient > y.efficient;
}

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

int main() {
  int N,A,B;
  cin >> N;
  A = 0;
  B = 0;
  vector<int> h(N,0);
  for(int i=0;i<N;i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  reverse(h.begin(),h.end());
  for(int j=0;j<N;j++){
    if(j%2 == 0){
      A += h.at(j);
    }
    else if(j%2 == 1){
      B += h.at(j);
    }
  }
  cout << A-B << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vb=vector<bool>;
using pii=pair<int,int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int V,E;
    cin>>V>>E;
    vector<vll> Dist(V,vll(V,INF));
    rep(i,0,V)Dist[i][i]=0;
    rep(i,0,E){
        int f,t;
        cin>>f>>t;
        int d;
        cin>>d;
        Dist[f][t]=d;
    }
    rep(i,0,V){
        rep(j,0,V){
            if(Dist[j][i]==INF)continue;
            rep(k,0,V){
                if(Dist[i][k]==INF)continue;
                chmin(Dist[j][k],Dist[j][i]+Dist[i][k]);
            }
        }
    }
    bool check=false;
    rep(i,0,V)if(Dist[i][i]<0)check=true;
    if(check){cout<<"NEGATIVE CYCLE"<<endl;return 0;}

    rep(i,0,V){
        rep(j,0,V){
            if(j>=1&&j<=V-1)cout<<" ";
            if(Dist[i][j]==INF)cout<<"INF";
            else{
                cout<<Dist[i][j];
            }
        }
        cout<<endl;
    }
    return 0;
}





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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	ll x, y;
	cin >> x >> y;
	ll cp = x;
	if(x % y == 0){
		cout << -1 << endl;
		return 0;
	}
	while(x <= 1e18){
		if(x % y != 0){
			cout << x << endl;
			return 0;
		} else {
			x += cp;
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 3644
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = format(A[i], "041b")
one_count = [0 for i in range(41)]
for i in range(N):
    for j in range(41):
        if A[i][j] == "1":
            one_count[j] += 1
halfsize = (len(A)+1)//2
Xint = 0
X = ""
for i in range(41):
    if one_count[i] < halfsize and Xint + 2 ** (40-i) <= K:
        Xint += 2 ** (40-i)
        X += "1"
    else:
        X += "0"

ans = 0
for i in range(41):
    if int(X[i]) == 1:
        ans += 2**(40-i) * (N - one_count[i])
    else:
        ans += 2**(40-i) * one_count[i]

print(ans)


Measured memory_bytes: 16556
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

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

    int max=0;
    int num=0;
    for(int i=0 ; i<s.size() ; i++){
        string tmp = s.substr(i,1);
        if(tmp=="I") num++;
        else if(tmp=="D") num--;

        max=std::max(max,num);
    }
    p(max)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }

const ll INF=(1LL<<60);
const int mod=1000000007;

int main(){
    int N,k; cin >> N >> k;
    vector<int> h(N);
    for(int i=0; i<N; i++) cin >> h[i];

    int ans=1000000000;
    sort(h.begin(), h.end());
    for(int i=0; i<N-k+1; i++){
        chmin(ans, h[i+k-1]-h[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto a=new int[](n);
  foreach(i; 0..n) rd(a[i]), a[i]--;

  int cur=0, cnt=0;
  foreach(_; 0..n+1){
    cur=a[cur];
    cnt++;
    if(cur==1){
      writeln(cnt);
      return;
    }
  }
  writeln(-1);

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;

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

const int maxn = 1e5 + 5;

vector<int> adj[maxn];
int DFS(int u , int par){
    int cnt = 0 , res = 0;
    for(int c : adj[u]){
        if(c == par)continue;
        res ^= (DFS(c , u) + 1);
    }
    return res;
}
int n;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1; i < n ; ++i){
        int u,v;cin >> u >> v;
        adj[u].pb(v);adj[v].pb(u);
    }
    puts(DFS(1,0) ? "Alice" : "Bob");
}


Measured memory_bytes: 10368
#include <stdio.h>

int main(void){
    int h,w,i,o;
    for(;scanf("%d %d",&h,&w),h+w;puts(""))
        for(i=0;i<h;i++,puts("")){
            if(i==0 || i==h-1)
                for(o=0;o<w;o++)
                    printf("#");
            else{
                for(printf("#"),o=0;o<w-2;o++)
                    printf(".");
                printf("#");
            }
        }
    return 0;
}

Measured memory_bytes: 584
n,m,k=map(int,input().split())
n,m=min(n,m),max(n,m)
for i in range(n//2+n%2):
  num,dem=k-i*m,n-2*i
  if num%dem or not(0<=num//dem<=m):continue
  print("Yes");exit()
print("No")

Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
struct UnionFind {
  vector<ll> data;
  ll num;
  UnionFind(ll size) : data(size, -1) ,num(size){ }
  bool unite(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
	  num--;
    }
    return x != y;
  }
  bool find(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,q;cin>>n>>q;
  UnionFind uf(n);
  while(q--){
    ll t,u,v;cin>>t>>u>>v;
    if(t==0)uf.unite(u,v);
    else cout<<uf.find(u,v)<<endl;
  }
  return 0;
}

Measured memory_bytes: 4676
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}



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;}

const ll INF=1e15;

const ll mod=1e9+7;
class DisjointSet{
    public:
    vector<ll> rank,p,sz;
    DisjointSet(){}
    DisjointSet(ll size){ //作られうる木の頂点数の最大値を入れる。
        rank.resize(size,0);
        p.resize(size,0);
        sz.resize(size,1);
        rep(i,size) makeSet(i);
    }
    void makeSet(ll x){ //xだけが属する木を作る。
        p[x]=x;
        rank[x]=0;
    }
    bool same(ll x,ll y){ //xとyが同じ木に属するかどうか
        return findSet(x)==findSet(y);
    }
    void unite(ll x, ll y){
        link(findSet(x),findSet(y));
    }
    void link(ll x, ll y){ //rankが大きい方の根に小さい方の根をつける。
        if(rank[x]>rank[y]){
            p[y]=x;
        }
        else{
            p[x]=y;
            if(rank[x]==rank[y]){
                rank[y]++; //xとyの木のrankが同じであれば、統合するとrankが1増える。
            }
        }
        sz[x]+=sz[y];
        sz[y]=sz[x];
    }
    ll findSet(ll x){ //xが属する木の根の番号を返す
        if(x!=p[x]){
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
   ll n,m;
   cin >> n >> m;
   vector<ll> a(m),b(m);
   DisjointSet ds=DisjointSet(n+1);
   rep(i,m){
       cin >> a[i] >> b[i];
       a[i]--;
       b[i]--;
       if(!ds.same(a[i],b[i])){
           ds.unite(a[i],b[i]);
       }
   }
   ll ans=0;
   rep(i,n){
       ans=max(ans,ds.sz[ds.findSet(i)]);
   }
   cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11184