akhauriyash/Code-Regression huggingface dataset:
def main():
    cards = [input() for _ in range(3)]
    next_turn = {"a": 0, "b": 1, "c": 2}
    answer = {}
    for person, index in next_turn.items():
        answer[index] = person.upper()
    now_turn = 0
    while True:
        if cards[now_turn] == "":
            print(answer[now_turn])
            break
        else:
            next = cards[now_turn][0]
            cards[now_turn] = cards[now_turn][1:]
            now_turn = next_turn[next]


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,m,k,fav,ans=0; cin>>n>>m;
    vector<int> food(m);
    rep(i,m) food[i]=0;
    rep(i,n){
        cin>>k;
        rep(j,k){
            cin>>fav;
            food[fav-1]++;
        }
    }
    rep(i,m){
        if(food[i]==n) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
    for(int i = k; i < n; i++){
      if(a[i] > a[i - k]){
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 60328
use std::io;
use std::io::BufRead;

fn main() {
	let stdin = io::stdin();
	for line in stdin.lock().lines() {
		let v: Vec<usize> = line.unwrap().split_whitespace()
			.map(|s| s.parse().unwrap()).collect();
		let (h, w) = (v[0], v[1]);
		let s = "#".repeat(w) + "\n";
		let rect = match (h, w) {
			(0, 0) => break,
			(x, y) if x < 3 || y < 3 => s.repeat(h),
			(_, _) => s + &("#".to_string() + &(".".repeat(w-2)) + "#\n").repeat(h-2) + &("#".repeat(w)) + "\n",
		};
		println!("{}", rect);
	}
}


Measured memory_bytes: 5036
#include<iostream>
using namespace std;
#define MAX 2000005

int A[MAX];
int H;

void buildMaxHeap(int i) {
    int l,r,largest;
    l = 2*i;
    r = 2*i + 1;
    if ( l <= H && A[l] > A[i] ) largest = l;
    else largest = i;
    if ( r <= H && A[r] > A[largest] ) largest = r;

    swap(A[i], A[largest]);

    if ( largest != i ) buildMaxHeap( largest );
}

int main() {
    cin >> H;
    int i;
    for ( i = 1; i <= H; i++ ) cin >> A[i];
    for ( i = H/2; i >= 1; i-- ) buildMaxHeap(i);
    for ( i = 1; i <= H; i++ ) cout <<' ' << A[i];
    cout << endl;

    return 0;
}



Measured memory_bytes: 5016
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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


  cin >> n;
  MAP mp;
  vll v;
  rep(i, n) {
    cin >> tmp;
    mp[tmp]++;
    v.pb(tmp);
  }

  bool ok = true;
  sort(all(v));
  if (mp.size() > 3) ok = false;
  rep(i, n / 3) {
    if ((v[i] ^ v[i + n / 3] ^ v[i + (n / 3 * 2)]) != 0) ok = false;
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;



  return 0;
}


Measured memory_bytes: 5748
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
 
#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
 
#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)
 
typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)
 
#define S_RTN(S)  s_cout(S);return 0
 
 
#define _itoa(A,N) sprintf(A, "%d", N);
 
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
 
int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
 
 
int s_asorts(const void* a, const void* b);
 
//昇順
int s_asorts(const void* a, const void* b) {
    return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
    return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
    return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
    int i;
    rept(i, 0, n) {
        l_cin2(*(a + i), *(b + i));
    }
    return 0;
}
int i_cins(int n, int* a) {
    int i;
    for (i = 0; i < n; i++) {
        i_cin(*(a + i));
    }
 
    return 0;
}
int _gcd(int a, int b) {
    int r, tmp;
    if (a < b) { tmp = a; a = b; b = tmp; }
    r = a % b;
    while (r) {
        if (!r) break;
        a = b; b = r;
        r = a % b;
    }
    return(b);
}
 
long _max(long a, long b) {
    return a > b ? a : b;
}
long _min(long a, long b) {
    return a < b ? a : b;
}
int _swp(int* a, int* b)
{
    int tmp;
    tmp = *b; *b = *a; *a = tmp;
    return 0;
}

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


int main(){
    int a,b,c,k;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    if(k<=a){
        printf("%d",k);
        return 0;
    }else if(k<=(a+b)){
        printf("%d",a);
    }else if(k<=(a+b+c)){
        printf("%d",a-(k-(a+b)));
        return 0;
    }else{
        printf("%d",a-c);
    }
}

 
 


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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int>h(n);
  for(int i=0;i<n;i++) cin>>h[i];
  vector<int>answer(n);
  for(int i=0;i<n;i++) answer[i]=1;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    if(h[a-1]>h[b-1]) answer[b-1]=0;
    else if(h[a-1]<h[b-1]) answer[a-1]=0;
    else{
      answer[a-1]=0;
      answer[b-1]=0;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++) ans+=answer[i];
  cout<<ans<<endl;
}

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

int main()
{
  string s; cin >> s;
  int k; cin >> k;
  for (int i = 0; i < k; i++)
  {
    char c = s[i];
    if (c != '1')
    {
      cout << c << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n , k , q;
    cin >> n >> k >> q;
    vector<int>p(n);
    for(int i = 0; i < n; i ++){
        p[i] = 0;
    }
    int a;
    for(int i= 0;i < q;i++){
        cin >> a;
        p[a - 1] ++;
        
    }
    for(int i = 0;i < n;i++){
        //cout << k - q + p[i];
        if(k - q + p[i] > 0){
            cout << "Yes" <<endl;
        }
        else{
            cout << "No" <<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,m;
	cin>>n>>m;
	ll fl[n+1]={0},cnt[n+1]={0};
	string s;
	ll a=0,b=0;
	for(i=1;i<=m;i++){
		cin>>k>>s;
		if(s=="AC"){
			if(fl[k]==0){
				fl[k]=1;
				a++;
				b+=cnt[k];
			}
		}
		else{
			if(fl[k]==0){
				cnt[k]++;
			}
		}
	}
	cout<<a<<" "<<b;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
typedef long long int ll;
#define rep(i,m,n) for(ll i=m; i<n; i++)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a;
    ll l=a.length();
    rep(i,0,l){
    	cout<<"x";
    }
    cout<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char str1[4],str2[4];
    int count=0;
    cin>>str1;

    cin>>str2;
    for (int i=0;i<3;i++){
        if (str1[i]==str2[i]){
            count++;
        }
    }

    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

total = 0
for i in range(N):
    j = N-i-1
    a = A[j] + total
    total += -a % B[j]

print(total)


Measured memory_bytes: 58968
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=100005;
int n;
int h[N],tot;
struct Edge{
	int v,next;
}e[N];
int f[N];
inline int max(int x,int y){
	return x>y?x:y;
}
inline void addEdge(int u,int v){
	e[++tot]=(Edge){v,h[u]}; h[u]=tot;
}
void readData(){
	scanf("%d",&n);
	int x;
	for(int i=2;i<=n;i++){
		scanf("%d",&x);
		addEdge(x,i);
	}
}
bool cmpGiant(const int &x,const int &y){
	return x>y;
}
void solve(int u){
	f[u]=0;
	for(int i=h[u];i;i=e[i].next)
		solve(e[i].v);
	static int a[N],cnt;
	cnt=0;
	for(int i=h[u];i;i=e[i].next)
		a[++cnt]=f[e[i].v];
	sort(a+1,a+1+cnt,cmpGiant);
	for(int i=1;i<=cnt;i++)
		f[u]=max(f[u],i+a[i]);
}
int main(){
	readData();
	solve(1);
	printf("%d\n",f[1]);
	return 0;
}

Measured memory_bytes: 6400
use proconio::{fastout, input};
use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: i32,
    }

    let mut map = BTreeMap::new();

    for x in 1..=100 {
        for y in 1..=100 {
            for z in 1..=100 {
                let tmp = x * x + y * y + z * z + x * y + y * z + z * x;
                map.entry(tmp).and_modify(|e| *e += 1).or_insert(1);
            }
        }
    }

    for i in 1..=n {
        println!("{}", map.get(&i).unwrap_or(&0));
    }
}


Measured memory_bytes: 2744
N, M = map(int, input().split())
l, r = map(int, input().split())
cnt = 0
num = 0
if (l == r):
  cnt += 1
  num = l
for i in range(M-1):
  L, R = map(int, input().split())
  if (cnt == 1 and L == R and num == L):
    num = L
  elif (cnt == 1 and L == R and num != L):
    cnt += 1
    print(0)
    break
  elif (cnt == 0 and L == R):
    cnt += 1
    num = L
  elif ((cnt == 0 or cnt == 1) and L != R):
    if (L >= l):
      l = L
    if (R <= r):
      r = R
      
if (l > r and (cnt == 0 or cnt == 1)):
  print(0)
elif(l <= r and (cnt == 0 or cnt == 1)):
  if (num != 0 and cnt == 1):
    if (num >= l and num <= r):
      print(1)
    else:
      print(0)
  elif(cnt == 0 or cnt == 1):
    print(r - l + 1)

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

int main(void) {
    int K,N; cin >> K >> N;
    vector<int> A;
    for(int i=0; i<N; i++) {
        int x; cin >> x;
        A.push_back(x); 
    }
    int max_dis=A[0]+K-A[N-1];
    for(int i=1; i<N; i++) {
        int dis = A[i] - A[i-1];
        if(max_dis<dis) max_dis=dis;
    }
    cout << K-max_dis << endl;
    return 0;
}

Measured memory_bytes: 4296
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

ll mod = 1e9 + 7;

ll fact(ll n)
{
    ll res = 1;
    for(ll i = 1; i <=n; ++i)
        res = res * i % mod;
    return res % mod;
}

int main()
{
    // cout << fact(3) << endl;
    // cout << fact(100000) << endl;
    // return 0;
    ll n, m;
    cin >> n >> m;
    if (abs(n - m) >= 2)
        cout << 0;
    else if (n == m)
    {
        // cout << fact(n) << endl;
        cout << fact(n) * fact(m) * 2 % mod;

    }
    else 
        cout << fact(n) * fact(m) % mod;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> g(n);
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        a[i]--;
        g[i].emplace_back(a[i]);
        g[a[i]].emplace_back(i);
    }
    vector<int> ans(n);
    function<void(int, int)> dfs = [&](int v, int p) {
        vector<int> ch;
        for (int to : g[v]) {
            if (to == p) {
                continue;
            }
            dfs(to, v);
            ch.emplace_back(ans[to]);
        }
        sort(ch.rbegin(), ch.rend());
        for (int i = 0; i < ch.size(); i++) {
            ans[v] = max(ans[v], i + 1 + ch[i]);
        }
    };
    dfs(0, -1);
    cout << ans[0] << '\n';
    return 0;
}

Measured memory_bytes: 22144
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] l = new long[87];
		Arrays.fill(l, -1);

		l[0] = 2;
		l[1] = 1;
		for (int i = 2; i <= n; i++) {
			l[i] = l[i-1] + l[i-2];
		}
		System.out.println(l[n]);

	}

}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();

    int[] list = new int[n];

    for (int i = 0; i < k; i++) {
      int d = sc.nextInt();
      for (int j = 0; j < d; j++) {
        int ad = sc.nextInt();
        list[ad - 1]++;
      }
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
      if (list[i] <= 0) {
        count++;
      }
    }
    System.out.println(count);

    sc.close();

  }
}

Measured memory_bytes: 46320
main = do
  [n, m] <- map read . words <$> getLine
  print $ f n m 

q = 1000000007
 
f n m
  | abs (n - m) > 1 = 0
  | abs (n - m) == 1 = mod ((fact n) * (fact m)) q
  | otherwise = mod (2 * (fact n) * (fact m)) q

fact n
  | n == 0 = 1
  | otherwise =  mod (n * fact (n-1)) q

Measured memory_bytes: 7804
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int MAX_R=10,MAX_C=10000;

bool osenbei[MAX_R][MAX_C];	//true=1,false=0
bool table[MAX_R][MAX_C];
int R,C;

int solve();

int main(){
	vector<int> res;
	do{
		cin>>R>>C;
		if (R!=0 || C!=0){
			for (int i=0;i<R;i++){
				for (int j=0;j<C;j++){
					int a;
					cin>>a;
					osenbei[i][j]=(a ? true:false);
				}
			}
			res.push_back(solve());
		}
	}while (R!=0 || C!=0);
	for (vector<int>::iterator ite=res.begin();ite!=res.end();ite++){
		cout<<*ite<<endl;
	}
	return 0;
}

int solve(){
	int res=0;
	for (int i=0;i<1<<R;i++){
		for (int j=0;j<R;j++){
			for (int k=0;k<C;k++){
				table[j][k]=osenbei[j][k];	//?????????
			}
		}
		for (int j=0;1<<j<=i;j++){
			if (i&(1<<j)){
				//j??????????£???????
				for (int k=0;k<C;k++){
					table[j][k]=!table[j][k];
				}
			}
		}
		int r=0;	//false????????§?????°
		for (int j=0;j<C;j++){
			int f=0;	//false????????°
			for (int k=0;k<R;k++){
				if (!table[k][j]){
					f++;
				}
			}
			f=max(f,R-f);
			r+=f;
		}
		res=max(res,r);
	}
	return res;
}

Measured memory_bytes: 1412
n = int(input())
a = list(map(int,input().split()))
t = abs(a[0])
dis = []
for i in range(1,n):

    t += abs(a[i] - a[i-1])


t += abs(a[-1])


before = 0
for i,now in enumerate(a):

    if i == n-1:
        after = 0
    else:
        after = a[i+1]


    if before <= now <= after or after <= now <= before:
        dis.append(0)
    elif before <= after <= now or now <= after <= before:
        dis.append(2 * abs(now - after))
    else:
        dis.append(2 * abs(now - before))
    before = now

for i, d in enumerate(dis):
    print(t-d)


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

#define rep(i, N) for(int i = 0; i < N; i++)

using namespace std;
using ll = long long;

const int INF = INT_MAX;

struct LazySegmentTree{
private:
    int n;
    vector<int> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(){}
    LazySegmentTree(vector<int> v){
        int sz = v.size();
        int height = ceil(log2(sz));
        n = pow(2, height);
        node.resize(2*n-1, 0);
        lazy.resize(2*n-1, INF);
        lazyFlag.resize(2*n-1, false);
        rep(i, sz) node[i+(n-1)] = v[i];
        for(int i = n-2; i >= 0; i--) node[i] = min(node[(i<<1)+1], node[(i<<1)+2]);
    }

    void lazyEval(int k, int l, int r){
        if(lazyFlag[k]){
            node[k] = lazy[k];
            if(r-l > 1){
                lazy[(k<<1) + 1] = lazy[k]; lazyFlag[(k<<1) + 1] = true;
                lazy[(k<<1) + 2] = lazy[k]; lazyFlag[(k<<1) + 2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    int getmin(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;

        lazyEval(k, l, r);
        if(b <= l || r <= a) return INF;
        else if(a <= l && r <= b) return node[k];
        else{
            int vl = getmin(a, b, (k<<1)+1, l, (l+r)/2);
            int vr = getmin(a, b, (k<<1)+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }

    void update(int a, int b, int x, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;

        lazyEval(k, l, r);
        if(b <= l || r <= a) return;
        else if(a <= l && r <= b){
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEval(k, l, r);
        }
        else{
            update(a, b, x, (k<<1)+1, l, (l+r)/2);
            update(a, b, x, (k<<1)+2, (l+r)/2, r);
            node[k] = min(node[(k<<1)+1], node[(k<<1)+2]);
        }
    }
};

int main(void){
    int n, q; cin >> n >> q;
    vector<int> A(n, INF);
    LazySegmentTree lst(A);
    rep(i, q){
        int cmd; cin >> cmd;
        if(cmd){
            int s, t; cin >> s >> t;
            cout << lst.getmin(s, t+1) << endl;
        }
        else{
            int s, t, x; cin >> s >> t >> x;
            lst.update(s, t+1, x);
        }
    }
}


Measured memory_bytes: 6044
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
total = 0
for Ai in A:
    total += Ai
    a.append(total)
total = 0
for Bi in B:
    total += Bi
    b.append(total)

j = len(b) - 1
ans = 0
for i in range(len(a)):
    if a[i] > k:
        continue
    while a[i] + b[j] > k:
        j -= 1
        if j < 0:
            break
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 47380
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    for i in range(len(S)):
        if i%2==0 and S[i]=='L':
            print(NO)
            return
        if i%2==1 and S[i]=='R':
            print(NO)
            return 
    print(YES)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			boolean flag = false;
			int ans = 0;
			for(int i=0;i<n;i++) {
				int k = sc.nextInt();
				ans += Math.min(k, 1);
				if (k >= 2) {
					flag = true;
				}
			}
			if (!flag) {
				System.out.println("NA");
			}else{
				System.out.println(ans+1);
			}
		}
	}

}

Measured memory_bytes: 158304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
using ll = long long;

int main() {
    vector<int> num(3);
    rep(i, 0, 3) cin >> num[i]; 
    sort(num.begin(), num.end());
    int count = 0;
    if((num[1] - num[0])%2 == 1){
        num[2]++;num[1]++;
        count += (num[1] - num[0]) / 2;
        count += num[2] - num[1] + 1;
    }else{
        count += (num[1] - num[0]) / 2;
        count += num[2] - num[1];
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 5e3 + 11;
int ans, n;
LL tong[N], base[N];
char s[N];
int read(){
    int x = 0;
    char ch = getchar();
    while(ch > '9' || ch < '0')ch = getchar();
    while(ch >= '0' && ch <= '9')x = 10 * x + ch - 48, ch = getchar();
    return x;
}
LL get(int l, int r){
    return tong[r] - tong[l] * (base[r-l]);
}
bool check(int x){
    for(int l = 1;l <= n - x * 2 + 1; l++){
        int r = l + x - 1;
        for(int ll = r + 1;ll <= n - x + 1; ll++){
            int rr = ll + x - 1;
            if(get(ll - 1, rr) == get(l - 1, r))return 1;
        }
    }
    return 0;
}
int main(){
    n = read();
    scanf("%s", s + 1);
    base[0] = 1;
    for(int i = 1;i <= n; i++){
        s[i] -= 'a' - 1;
        base[i] = base[i-1] * 127;
        tong[i] = tong[i-1] * base[1] + s[i];
    }
    int l = 1, r = n;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(check(mid)){
            ans = max(ans, mid);
            l = mid + 1;
        }
        else r = mid - 1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def bfs01(g, s):
    d = {}
    for v in g.keys():
        d[v] = sys.maxsize
    d[s] = 0

    if s not in d:
        return d
    q = deque()
    q.append((d[s], s))

    NM = 1 << 30
    while q:
        _, u = q.popleft()
        for v in g[u]:
            if v > NM:
                c = 0
            else:
                c = 1
            alt = c + d[u]
            if d[v] > alt:
                d[v] = alt
                if c == 0:
                    q.appendleft((d[v], v))
                else:
                    q.append((d[v], v))
    return d


@mt
def slv(N, M):

    g = defaultdict(list)
    NM = 30
    for _ in range(M):
        p, q, c = input().split()
        p = int(p)
        q = int(q)
        c = int(c)

        cp = (c << NM) + p
        cq = (c << NM) + q
        g[cp].append(cq)
        g[cq].append(cp)
        g[cp].append(p)
        g[cq].append(q)
        g[p].append((cp))
        g[q].append((cq))

    d = bfs01(g, 1)
    return -1 if N not in d or d[N] == sys.maxsize else d[N]


def main():
    N, M = read_int_n()

    print(slv(N, M))


if __name__ == '__main__':
    main()


Measured memory_bytes: 163776
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
const int N=310;
int n,K,mo,C[N][N],f[N][N],sum[N][N];
int main()
{
	scanf("%d%d%d",&n,&K,&mo);
	C[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
	}
	for (int i=0;i<=K;i++) f[1][i]=1,sum[1][i]=i+1;
	for (int i=2;i<=n+1;i++)
		for (int j=0;j<=K;j++)
		{
			for (int k=1;k<=i-1;k++)
				f[i][j]=(f[i][j]+(ll)f[i-k][j]*C[i-2][k-1]%mo*(sum[k][K]-sum[k][j])%mo)%mo;
			sum[i][j]=(sum[i][j-1]+f[i][j])%mo;
		}
	printf("%d\n",(f[n+1][0]+mo)%mo);
	return 0;
}


Measured memory_bytes: 1408
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,x,y,a[200040];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>x>>y;
	for(;i++<n;)
	{
		for(j=i;j++<n;)
		{
			a[min(j-i,abs(i-x)+abs(j-y)+1)]++;
		}
	}
	for(i=0;++i<n;)cout<<a[i]<<endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)


def solve():
    n, *a = map(int, read().split())
    a = tuple(a)
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            L = a[i] - dp[i + 1][j]
            R = a[j] - dp[i][j - 1]
            if L > R:
                dp[i][j] = L
            else:
                dp[i][j] = R
    return dp[0][n - 1]


print(solve())


Measured memory_bytes: 234288
#include<iostream>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    for (ll n = 1; n <= 3500; n++) {
        for (ll w = 1; w <= 3500; w++) {
            ll c1 = 4 * n * w;
            ll c2 = N * (w + n);
            ll c3 = N * n * w;
            if (c1 == c2) continue;
            if (c3 % (c1 - c2) == 0 && c3 / (c1 - c2) > 0) {
                cout << n << ' ' << w << ' ' << c3 / (c1 - c2) << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1000000007LL;
const int Maxn = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

pll a[Maxn];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, k, s;
	cin >> n >> k >> s;
	for(int i = 0; i < k; i++) cout << s << ' ';
	int t = 1;
	if(s <= n) t = 1000000000ll;
	for(int i = 0; i < n-k; i++) cout << t << ' ';
	return 0;
}



Measured memory_bytes: 1280
import java.util.*;

public class Main{
	static boolean[] list;
	static HashMap<String,Integer> daylist;
	static ArrayList<String> name;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			int s = sc.nextInt();
			int n = sc.nextInt();
			int t = sc.nextInt();
			String week = sc.next();
			String time = sc.next();
			int p = sc.nextInt();
			int m = sc.nextInt();

			list=new boolean[7*24*60+1];
			
			for(int e=0;e<list.length;e++)list[e]=false;
			
			daylist=new HashMap<String,Integer>();
			name=new ArrayList<String>();
			name.add("Sun");
			daylist.put(name.get(0), 0);
			
			name.add("Mon");
			daylist.put(name.get(1), 1*24*60);
			
			name.add("Tue");
			daylist.put(name.get(2), 2*24*60);
		
			name.add("Wed");
			daylist.put(name.get(3), 3*24*60);
			
			name.add("Thu");
			daylist.put(name.get(4), 4*24*60);
			
			name.add("Fri");
			daylist.put(name.get(5), 5*24*60);
			
			name.add("Sat");
			daylist.put(name.get(6), 6*24*60);		
			
			if (s == 0 && n == 0 && t == 0 && p == 0 && m == 0 && week.equals("None") && time.equals("None"))break;		
					
			if(week.equals("All"))set(time);
			else set(week,time);
			
			if(list[0]||list[10080]){
				list[0]=true;
				list[10080]=true;
			}
			int aroundable=0;
			
			int ii=0;
			while(true){
				int count=0;	
				int here=ii;

				

				for(int j=0;j<m;j++){
					int sub=here+s;
					if(list[here]&&check(here,sub))count++;
					here+=t;
					if(here>=10080)here-=10080;
				}		
					aroundable=Math.max(aroundable, count);
			
				ii++;
				if(ii==7*24*60)break;
			}

	
			double result=1.0-(1.0/p);
			result=result==0?result=1:result;
			result=1-Math.pow(result,aroundable*n);
			result=result==0&&!(time.equals("Night")&&s>=360)?result=1:result;
	
			System.out.printf("%.10f\n",result);
	
		}
	}
	
	public static void set(String str){
		if(str.equals("Day")){
			for(int i=0;i<daylist.size();i++)setset(daylist.get(name.get(i)),6,18);
		}
		else if(str.equals("Night")){
			for(int i=0;i<daylist.size();i++){
				setset(daylist.get(name.get(i)),0,6);
				setset(daylist.get(name.get(i)),18,24);
			}
		}else for(int i=0;i<daylist.size();i++)setset(daylist.get(name.get(i)),0,24);
		
	}
	public static void set(String strw,String strt){
		if(strt.equals("Day"))setset(daylist.get(strw),6,18);
		else if(strt.equals("Night")){

			setset(daylist.get(strw),0,6);
			setset(daylist.get(strw),18,24);
		}else setset(daylist.get(strw),0,24);
	}
	public static void setset(int num,int start,int end){
		
		if(start==0&&end==24){
			start=num;
			end=start+1440;
		}else if(start==0&&end==6){
			start=num;
			end=start+360;
		}else if(start==18&&end==24){
			start=num+1080;
			end=start+360;
		}else if(start==6&&end==18){
			start=num+360;
			end=start+720;
		}
		
		for(int i=start;i<end;i++)list[i]=true;			
	
	}
	public static boolean check(int start,int end){
	
		
		if(end<=10080){
			for(int i=start;i<=end;i++){
				if(!list[i])return false;
			}
	
		}else {
			end-=10080;
			for(int i=start;i<=10080;i++){
				if(!list[i])return false;
			}for(int i=0;i<=end;i++){
				if(!list[i])return false;
			}
	
		}
		
		return true;
	}
}

Measured memory_bytes: 33464
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    K = int(input())
    A,B = map(int, input().split())
    if A%K == 0 or A%K + (B-A) >= K:
        print('OK')
    else:
        print('NG')    

main()


Measured memory_bytes: 9160
import itertools

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a, b, c, d, e]

min_m = 999 * 5
for abcde in itertools.permutations(l, 5):
    # print(abcde)
    end = 0
    for v in abcde:
        mod = end % 10
        if mod != 0:
            end += 10 - mod
        end += v
        # print(end)
    if end < min_m:
        min_m = end
print(min_m)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication15
{
    class Program
    {
        static void Main(string[] args)
        {
            // 文字列入力
            string strMojiData = Console.ReadLine();

            // 試行回数入力
            int intInputTryNum = int.Parse(Console.ReadLine());

            for (int num = 0; num < intInputTryNum; num++)
            {
                // 命令入力
                string[] strInputOrderArray = Console.ReadLine().Split(' ');

                string strTargetData = strMojiData.Substring(int.Parse(strInputOrderArray[1]), int.Parse(strInputOrderArray[2]) - int.Parse(strInputOrderArray[1]) + 1);
                string strLeftData = strMojiData.Substring(0, int.Parse(strInputOrderArray[1]));
                string strRightData = strMojiData.Substring(int.Parse(strInputOrderArray[2]) + 1);

                switch (strInputOrderArray[0])
                {
                    case "print":
                        Console.WriteLine(strTargetData);
                        break;
                    case "reverse":
                        strMojiData = strLeftData + new string(strTargetData.Reverse().ToArray())+ strRightData;
                        break;
                    case "replace":
                        strMojiData = strLeftData + strInputOrderArray[3] + strRightData;
                        break;
                    default:
                        break;
                }
            }
        }
    }
}



Measured memory_bytes: 20376
#include <stdio.h>
int main (void){
  int a, b;
  scanf("%d %d", &a, &b);
  if(a>b) printf("a > b\n");
  else if(a<b) printf("a < b\n");
  else if(a==b) printf("a == b\n");

  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string S; cin >> S;
    cout << (S == "ARC" ? "ABC" : "ARC") << "\n";
}

Measured memory_bytes: 3620
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;

  auto it = S.begin();
  char S_i;
  if (it == S.end()) goto FAILED;
  S_i = *(it++);
  if (S_i == 'A') {
    if (it == S.end()) goto FAILED;
    S_i = *(it++);
    if (S_i == 'A') goto FAILED;
  }
  if (S_i != 'K') goto FAILED;
  if (it == S.end()) goto FAILED;
  S_i = *(it++);
  if (S_i != 'I') goto FAILED;
  if (it == S.end()) goto FAILED;
  S_i = *(it++);
  if (S_i != 'H') goto FAILED;
  if (it == S.end()) goto FAILED;
  S_i = *(it++);
  if (S_i == 'A') {
    if (it == S.end()) goto FAILED;
    S_i = *(it++);
    if (S_i == 'A') goto FAILED;
  }
  if (S_i != 'B') goto FAILED;
  if (it == S.end()) goto FAILED;
  S_i = *(it++);
  if (S_i == 'A') {
    if (it == S.end()) goto FAILED;
    S_i = *(it++);
    if (S_i == 'A') goto FAILED;
  }
  if (S_i != 'R') goto FAILED;
  if (it != S.end()) {
    S_i = *(it++);
    if (S_i != 'A') goto FAILED;
    if (it != S.end()) goto FAILED;
  }

  std::cout << "YES" << std::endl;
  return 0;

FAILED:
  std::cout << "NO" << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

vector<int> cap[26];
int G[200010][26];
int rev[200010];

int arr[200010];

int main() {
	for (int i = 0;i < 200010;i++)rev[i] = -1;
	string A;
	cin >> A;
	int N = A.size();
	for (int i = 0;i < N;i++) {
		cap[A[i] - 97].push_back(i);
	}

	for (int i = 0;i < N;i++) {
		for (int j = 0;j < 26;j++) {
			auto it = upper_bound(all(cap[j]), i);
			if (it == cap[j].end()) {
				G[i][j] = 200005;
			}
			else {
				G[i][j] = *it;
			}
		}
	}

	int a, b, c, ord = 0;
	char key;
	string ans = "";
	priority_queue<tuple<int, int, int, char>> Q;//ターン(文字数のマイナス)、行きがけ順(辞書順走査)、位置、最後の文字
	//各頂点にはターンを記録(行きがけ順はやればその通りになるから)
	//更新された時点でそこが最短経路となる
	for (int i = 0;i < 26;i++) {
		if (cap[i].size() == 0) {
			cout << (char)(i + 97) << endl;
			return 0;
		}
		Q.push(make_tuple(0, ord, cap[i][0], i + 97));
		ord--;
		rev[cap[i][0]] = 200006;
	}
	while (!Q.empty()) {
		tie(a, b, c, key) = Q.top();
		Q.pop();
		if (c == 200005) {
			ans += key;
			break;
		}
		for (int i = 0;i < 26;i++) {
			if (rev[G[c][i]] < 0) {
				rev[G[c][i]] = c;
				Q.push(make_tuple(a - 1, ord, G[c][i], i + 97));
				ord--;
			}
		}
	}

	while (rev[c] != 200006) {
		c = rev[c];
		ans += A[c];
	}
	reverse(all(ans));
	cout << ans << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 1050000000;
constexpr auto MOD = 1000000007;

ll fac[100020],invfac[100020];

ll lpow(ll p, ll q) {
	ll ans = 1;
	ll pp = p;
	while (q) {
		if (q % 2) {
			ans *= pp;
			ans %= MOD;
		}
		q /= 2;
		pp *= pp;
		pp %= MOD;
	}
	return ans;
}

ll com(ll n, ll r) {
	if (n < r || n < 0 || r < 0)	return 0;
	ll ans = 1;
	ll k = n - r;

	ans *= fac[n] * invfac[r];
	ans %= MOD;
	ans *= invfac[k];
	ans %= MOD;

	return ans;
}


int main() {
	int n, k;
	cin >> n >> k;
	vi a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));

	rep(i, n+1) {
		if(i==0)fac[i] = 1;
		else fac[i] = (fac[i - 1] * i) % MOD;
		invfac[i] = lpow(fac[i], MOD - 2);
	}

	ll ans = 0;

	rep(i, n) {
		ans+=com(i, k - 1)* a[i];
		ans %= MOD;
	}

	rep(i, n) {
		ll hoge = com(n - 1 - i, k - 1) * a[i];
		hoge %= MOD;
		ans += MOD - hoge;
		ans %= MOD;
	}
	cout << ans << endl;
}

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

#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define fori(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(n) fori(somethingStupid,1,(n))


using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

bool tests = false;

void solve(){
    int a; cin >> a;
    cout << a + a*a+a*a*a << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
    if (tests){
        cin >> t;
    }
    rep(t) solve();
    return 0;
}


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

int a[109];

int main()
{
    int n;
    std::cin>>n;
    for(int i=1;i<=n;i++){
        std::cin>>a[i];
    }
    std::sort(a+1,a+1+n);
    int ans=0,temp=0;
    for(int i=a[1];i<=a[n];i++){
        temp=0;
        for(int j=1;j<=n;j++){
            temp+=(a[j]-i)*(a[j]-i);
        }
        if(i==a[1]) ans=temp;
        else{
            if(temp<ans) ans=temp;
        }
    }
    std::cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
import collections
while True:
    W, H = map(int, input().split())
    if (W, H) == (0, 0): break
    cdoor, rdoor = [], []
    cdoor.append(list(map(int, input().split())))
    for _ in range(H-1):
        rdoor.append(list(map(int, input().split())))
        cdoor.append(list(map(int, input().split())))
    
    maze = [[-1 for _ in range(W)] for _ in range(H)]
    maze[0][0] = 1
    que = collections.deque()
    que.append((0, 0))
    drc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    while maze[H-1][W-1] == -1 and len(que) > 0:
        r, c = que.popleft()
        for dr, dc in drc:
            nr, nc = r+dr, c+dc
            if 0 <= nr < H and 0 <= nc < W and ((dc == 0 and rdoor[min(nr, nr-dr)][c] == 0) or (dr == 0 and cdoor[r][min(nc, nc-dc)] == 0)) and maze[nr][nc] == -1:
                maze[nr][nc] = maze[r][c] + 1
                que.append((nr, nc))
    print(maze[H-1][W-1] if maze[H-1][W-1] != -1 else 0)

Measured memory_bytes: 6788
T=int(input())
from functools import lru_cache

for _ in range(T):
    N,A,B,C,D=map(int,input().split())
    @lru_cache(maxsize=None)  
    def solve(N):
        if N==0:
            return 0
        if N==1:
            return D
        tmp=N*D    
        if N%2==0:
            tmp=min(tmp,solve(N//2)+A)
        else:
            tmp=min(tmp,solve((N-1)//2)+A+D,solve((N+1)//2)+A+D)
        if N%3==0:
            tmp=min(tmp,solve(N//3)+B)
        else:
            b=N%3 
            tmp=min(tmp,solve((N+(3-b))//3)+B+(3-b)*D,solve((N-b)//3)+B+b*D)
        if N%5==0:
            tmp=min(tmp,solve(N//5)+C)
        else:
            c=N%5
            tmp=min(tmp,solve((N-c)//5)+C+D*c,solve((N+(5-c))//5)+C+D*(5-c))
        return tmp

    print(solve(N))


Measured memory_bytes: 11524
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(){
    int x,y;
    char s[100];
    int stack[100];
    int num=0;
 
    while (scanf("%s", s) != EOF){
        if (s[0] == '+'){
            x = stack[--num];
            y = stack[--num];
            stack[num] = x + y;
            num++;
        }
        else if (s[0] == '-'){
            x = stack[--num];
            y = stack[--num];
            stack[num] = -x + y;
            num++;
 
        }
        else if (s[0] == '*'){
            x = stack[--num];
            y = stack[--num];
            stack[num] = x * y;
            num++;
 
        }
        else {
            x = atoi(s);
            stack[num] = x;
            num++;
        }
    }
    printf("%d\n",stack[--num]);
    return 0;
}

Measured memory_bytes: 548
#include<iostream>
#include<stdio.h>
#include<cctype>
using namespace std;

int main(){
	char ch;
	int counter[26];

	for (int i = 0; i < 26; i++){
		counter[i] = 0;
	}

	while (cin >> ch){
		if (islower(ch)){
			counter[ch - 'a']++;
		}
		else if (isupper(ch)){
			counter[ch - 'A']++;
		}
	}

	for (int i = 0; i < 26; i++){
		printf("%c : %d\n", i + 'a', counter[i]);
	}

	return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define INF 1000000000;
using namespace std;

int turn(vector<int> p, int c){
    int tmp = 0;
    int s = p.size()- 1;
    vector<int> ans;
    p.pb(0);
      p[0] -= c;
      tmp += c;
      int f = 0;
      REP(i, s){
          while(f < 3){
            if(p[i] <= 0)break;
            p[i]--;
            p[i+1]--;
            tmp+= 2;
            f++;
          } 
          f = 0;
        }
        while(f < 3){
          if(p[s] <= 0)break;
          p[s]--;
          tmp++;
          f++;
        }
    return tmp;
  }

int main(){
 int n;
 cin >> n;
 vector<int> ans;
 vector<int> p(n);
 REP(i, n){
  cin >> p[i];
   }  
  ans.pb(turn(p, 0));
  ans.pb(turn(p, 1));
  ans.pb(turn(p, 2));
  ans.pb(turn(p, 3));

  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
  
 return 0;
}



Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int r,D,x,ANS;
	cin >> r >> D >> x;
	ANS = x;

	for(int i=0;i<10;i++)
	{
		ANS = r*ANS - D;
		cout << ANS << endl;
	}

}

Measured memory_bytes: 256
#3
#入力
s=input()

#処理
X={}

for i in range(len(s)):
    if s[i] in X:
        X[s[i]]+=1
    else:
        X[s[i]]=1
    
Y=[kv[0] for kv in X.items()]
z=float('inf')

for i in Y:
    x=0
    t=s
    while t!=i*len(t):
        l=""
        for j in range(len(t)-1):
            if t[j]==i or t[j+1]==i:
                l=l+i
            else:
                l=l+t[j]
        x+=1
        t=l
    
    if z>x:
        z=x
print(z)

Measured memory_bytes: 3064
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

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

        System.out.println((10+x-a)/10*10);
    }
}

class io{
    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }
}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}



Measured memory_bytes: 21844