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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
const int MAX = 1e5 + 5;
ll m = 1e9 + 7;
ll A[MAX];
ll mul(ll a, ll b, ll m) {
    return (ll)((__uint128_t)a * b % m);
}

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    ll n;
    cin >> n;
    map<ll, ll> mp;
    forn(i, n) cin >> A[i], mp[A[i]]++;
    bool ok = 1;
    ll ans = 1;
    for (auto x : mp) {
        if ((x.S > 2) || (x.F == 0 && x.S >= 2)) {
            ok = 0;
            break;
        }
        ans = mul(ans, x.S, m);
    }
    if (!ok)
        cout << 0 << endl;
    else
        cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main() {
    int W,H,N;
    int count=0;
    int x[110],y[110],a[110];
    int SQ[110][110]={0};
    cin>>W>>H>>N;
    for(int i=0;i<N;++i){
        cin>>x[i]>>y[i]>>a[i];
    }
    for(int i=0;i<N;++i){
        switch (a[i]){
        case 1:
        for(int j=0;j<x[i];++j){
            for(int k=0;k<H;++k){
                SQ[j][k]=1;
            }
        }
            break;
        case 2:
        for(int j=x[i];j<W;++j){
            for(int k=0;k<H;++k){
                SQ[j][k]=1;
            }
        }
            break;
        case 3:
        for(int j=0;j<W;++j){
            for(int k=0;k<y[i];++k){
                SQ[j][k]=1;
            }
        }
            break;
        case 4:
        for(int j=0;j<W;++j){
            for(int k=y[i];k<H;++k){
                SQ[j][k]=1;
            }
        }
            break;
        }
    }
    for(int i=0;i<W;++i){
        for(int j=0;j<H;++j){
            if(SQ[i][j]==0){
                count++;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
	int a[3],min,max;
	min = 0;
	max = 0;
	a[0] = 0;
	a[1] = 0;
	a[2] = 0;

	cin >> a[0] >> a[1] >> a[2];

	
	sort(a, a + 3, less<int>());

	min = abs(a[1] - a[0]) + abs(a[2] - a[1]);

	sort(a, a + 3, greater<int>());

	max = abs(a[1] - a[0]) + abs(a[2] - a[1]);

	if (min < max) {
		cout << min << endl;
	}
	else {
		cout << max << endl;
	}

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    int x, ans = 0;

    cin >> x;
    rep(i, 1, sqrt(x) + 1)
    {
        rep(j, 1, sqrt(x) + 1)
        {
            if (pow(j, i) <= x)
                ans = max(ans, (int)pow(j, i));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int i=0;
	char data[100000]={'\0'},al[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	int k[27]={0};
	scanf("%s",data);
	while(data[i]!='\0'){
		k[data[i]-'a']=1;
		i++;	
	}
	i=0;
	while(k[i]==1){
		i++;	
	}
	if(i==26){
		printf("None\n");
	}else{
		printf("%c\n",al[i]);
	}
return 0;
}

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

int main(){
    int a,b,c;cin >> a >> b >> c;
    int ab = a*10 + b;
    int bc = b*10 + c;
    int ac = c*10 + a;

    cout << max(ab+c, max(a+bc, ac+b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    long long i,j,k,num,d,range,ans;

    cin >> num >>  d;
    range = 2 * d +1;
    ans = num / range;
    if(num%range) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
 
  class Main {
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
         int n = scan.nextInt();
        
        long[] arr = new long[n+1];
        long[] arr2 = new long[n];
        
        for(int i = 0 ; i<n+1 ; i++){
            arr[i] = scan.nextInt();
        }
        for(int i = 0 ; i < n ;i++){
            arr2[i] = scan.nextInt();
        }
        long count = 0 ;
        for(int i = 0 ; i< n ;i++){
            long a = Math.min(arr[i],arr2[i]);
            if(a == arr[i]){
                count +=a ;
                long b = Math.max(arr[i],arr2[i]) - Math.min(arr[i],arr2[i]);
                if(arr[i+1] > b){
                    count+=b;
                    arr[i+1] = arr[i+1] - b ;
                }else{
                    count+=arr[i+1]; 
                    arr[i+1] = 0 ;
                }
            }else{
                count +=a ;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 64948
#include "bits/stdc++.h"
using namespace std;

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

    int ans = 0;
    while (1) {
        bool flag = false;
        for (int i = 0; i < N; i++) {
            if (H[i] != 0) flag = true;
        }
        if (!flag) break;

        int cnt = 1;
        if (H[0] == 0) cnt--;
        int Hmin = 100;
        for (int i = 0; i < N - 1; i++) {
            if (H[i] == 0 && H[i + 1] != 0) cnt++;
            if (H[i] > 0) Hmin = min(Hmin, H[i]);
        }
        if (H[N - 1] > 0) Hmin = min(Hmin, H[N - 1]);

        for (int i = 0; i < N; i++) {
            if (H[i] > 0) H[i] -= Hmin;
        }
        ans += Hmin * cnt;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n;
	vvp g;
	public:
	int DIJ(int s,int t){
		priority_queue<P> q;
		vi d(n,inf);
		d[s]=0;
		q.push({0,s});
		while(!q.empty()){
			P p=q.top();
			q.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i:g[v]){
				int u=i.first,D=d[v]+i.second;
				if(d[u]>D){
					d[u]=D;
					q.push({-D,u});
				}
			}
		}
		return d[t];
	}
	Graph(int v){
		n=v;
		g=vvp(v);
	}
	void add_edge(int s,int t,int c){
		g[s].push_back({t,c});
	}
};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	vi b(n,-2);
	for(int i=0;i<n;i++) if(b[i]==-2){
		set<int> st;
		if(a[i]==0){
			b[i]=i;
			continue;
		}
		int x=i;
		do{
			if(st.find(x)!=st.end()){
				x=i;
				break;
			}
			st.insert(x);
			x+=a[x];
		}while(x!=i&&a[x]!=0&&b[x]==-2);
		int type=b[x];
		if(type==-2) type=-1;
		if(a[x]==0) type=x;
		x=i;
		do{
			b[x]=type;
			x+=a[x];
		}while(x!=i&&a[x]!=0&&b[x]!=-1);
	}
	Graph g(n);
	for(int i=0;i<n;i++) if(a[i]==0){
		for(int j=1;j<=6;j++){
			int x=min(i+j,n-1);
			if(b[x]!=-1) g.add_edge(i,b[x],1);
		}
	}
	cout<<g.DIJ(0,n-1)<<endl;
}


Measured memory_bytes: 8916
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n,p;
  while(1){
   cin>>n>>p;
   if(n==0||p==0)return 0;
   int sum=p;
   V<int> a(n,0);
   int i=0;
   while(1){
       if(a[i]==sum){
           cout<<i<<endl;
           break;
       }
       if(p==0){
           p+=a[i];
           a[i]=0;
       }
       else {
           a[i]++;
           p--;
       }
       i++;
       i%=n;
   }
  }
}


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

struct node{
  int key;
  struct node *right, *left, *parent;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treemin(Node x)
{
  while ( x->left != NIL)
    x = x->left;
  return x;
}

Node find(Node u, int k)
{
  while (u != NIL && k != u->key){
    if (k < u->key)
      u = u->left;
    else
      u = u->right;
  }
  return u;
}

Node treesuccessor(Node x)
{
  Node y;
  
  if (x->right != NIL)
    return treemin(x->right);
  y = x->parent;
  while (y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treedelete(Node z)
{
  Node y, x;

  if (z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treesuccessor(z);
  if (y->left != NIL)
    x = y->left;
  else
    x = y->right;
  if (x != NIL)
    x->parent = y->parent;
  if (y->parent == NIL)
    root = x;
  else{
    if (y == y->parent->left)
      y->parent->left = x;
    else
      y->parent->right = x;
  }
  if (y != z)
    z->key = y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while (x != NIL){
    y = x;
    if (z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
    z->parent = y;
    if (y == NIL)
      root = z;
    else if (z->key < y->key)
      y->left = z;
    else
      y->right = z;
}

void inorder(Node u){
  if (u == NIL)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if (u == NIL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main()
{
  int n, i, x;
  char c[8];
  Node t;

  scanf("%d",&n);
  for (i = 0; i < n; i++){
    scanf("%s",c);
    if (c[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if (c[0] == 'f'){
      scanf("%d",&x);
      t = find(root,x);
      if (t != NIL)
	printf("yes\n");
      else
	printf("no\n");
    }
    else if (c[0] == 'd'){
      scanf("%d",&x);
      treedelete(find(root,x));
    }
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
}



Measured memory_bytes: 20452
// https://atcoder.jp/contests/abc085/tasks/abc085_c
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

// N: お札の枚数, Y: 合計金額
int N, Y;

void solve();

int main() {
  cin >> N >> Y;
  solve();
}

void solve() {
  vector<int> papers{10000, 5000, 1000};
  vector<int> ans(3, -1);
  // i: 1万円札
  for (int i = 0; i <= N; i++) {
    int total = 0;
    // j: 五千円札
    for (int j = 0; i + j <= N; j++) {
      // k: 千円札
      int k = N - i - j;
      total = i * 10000 + j * 5000 + k * 1000;
      if (total == Y) {
        ans[0] = i;
        ans[1] = j;
        ans[2] = k;
        break;
      }
    }
    if (total == Y) {
      break;
    }
  }
  cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
}


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

int main(void){
    int N,M,X,Y,Z;
    cin>>N>>M>>X>>Y;
    Z=X+1;
      
    for(int i=1;i<=N;i++){
        int x;
        cin>>x;
        if(x>Z){
            Z=x+1;
        }
    }


    if(Z>Y){
        cout<<"War"<<endl;
        return 0;
    }


    for(int i=1;i<=M;i++){
        int Y;
        cin>>Y;
        if(Z>Y){
            cout<<"War"<<endl;
            return 0;
        }
    }

    cout<<"No War"<<endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int A[3];
    rep(i,3) cin >> A[i];
    if(A[0]+A[1]+A[2]>=22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 892
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll a;
string b;
cin >> a >> b;
string s;
for(int i = 0; i < b.size(); i++){
    if(b[i] != '.')
        s = s + b[i];
}
cout << (ll)((a * atoi(s.c_str())) / 100) << endl;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            System.out.println(isPalindrome("" + N) ? "Yes" : "No");
        }
    }

    private static boolean isPalindrome(String s) {
        for (int l = 0, r = s.length() - 1; l < r; l++, r--) {
            if (s.charAt(l) != s.charAt(r)) {
                return false;
            }
        }
        return true;
    }
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{
    lint n;
    cin >> n;
    lint ans, tmp;

    vector<lint> d(n);
    REP(i, n) { cin >> d[i]; }

    sort(ALL(d));
    lint l, r;
    l = d[SZ(d) / 2 - 1];
    r = d[SZ(d) / 2];
    ans = r - l;

    cout << ans <<"\n";

    return 0;
}

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

int main()
{  
  int n,c;
  int ans=0;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;++i){
    cin >> v.at(i);
  }
  for(int i=0;i<n;++i){
    cin >> c;
    if(v.at(i)>c){
      ans+=v.at(i)-c;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
	int m,d,d1,d10;
    int ans=0;
    cin >> m >> d;
    for(int i=1;i<=m;i++){
        for(int j=21;j<=d;j++){
            d1=j%10;
            d10=j/10;
            if(d1*d10 == i&&d1>=2){
                ans++;
            }

        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <set>          
#include <map>           
#include <list>
#include <ctime>
#include <deque>         
#include <bitset>        
#include <vector>
#include <list>
#include <stack>
#include <random>		 
#include <string>       
#include <numeric>      //  needed for  accumulate
#include <utility>      // needed for std:: move
#include <iterator> 
#include <iostream>   
#include <algorithm> 
#include <functional>    
#include <cmath>         
#pragma warning(disable:4996) // ignore this
#define ve vector
#define pb push_back
#define mp make_pair                     
#define srt(x) sort(x.begin(),x.end())         
#define mod static_cast<long long> (1e9+7)     
#define sumx(x) accumulate(x.begin(),x.end(),0LL)
#define pi 3.14159265358979323846
using namespace std;
template<typename T>
istream& operator >> (istream& in, ve<T> &v)
{
	for (auto &x : v)
		in >> x;
	return in;
}
template<typename T>
ostream& operator<<(ostream& in, ve<T> &v)
{
	for (auto &x : v)
		in << x << " ";
	return in;
}
class solve
{
	long long n;
public:
	solve()
	{
		int p,p2[2]={0,0};
		cin >> n >> p ;
		for(int i=0;i<n;i++)
		{
			int x;
			cin >>x;
			p2[x%2]++;
		}
		if(p%2)
		{
			if(p2[1]==0)
			{
				cout << 0;
				return;
			}
		}
		else
		{
			if(p2[0]==0 && p2[1]<2)
			{
				cout << 0 << endl;
				return;
			}
		}
		long long ans=1;
		for(int i=0;i<p2[0];i++)
		{
			ans*=2;
		}
		for(int i=0;i<p2[1]-1;i++)
		{
			ans*=2;
		}
		cout << ans <<endl;
	}
};
 
int main()
{
	int t = 1, i = 1;
	//scanf("%d", &t);
 
	while (t--)
	{
		new solve;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <algorithm>
using namespace std;

int main()
{
    int n = 0;
    cin >> n;

    int A[100]={};
    for(size_t i = 0; i < n; i++)
    {
        cin >> A[i];
    }

    int m=0;
    int buf=0;
    
    
    for(size_t i = 0; i < n; i++)
    {
        for(size_t j = 0; j < n-i; j++)
        {
            buf = abs(A[i] - A[i+j]);
            m = max(m, buf);
        }
        
    }
    
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

int* table;

void func(int X,int Y){

	int current = X%Y,ans_left,ans_right;

	table[current] = 0;

	for(int i = 1;i < 1000000; i++){
		current = (10*current)%Y;

		if(current == 0){ //?????????????????´???
			ans_left = i;
			ans_right = 0;
			break;
		}else{
			if(table[current] != -1){
				ans_left = table[current];
				ans_right = i - table[current];
				break;
			}else{
				table[current] = i;
			}
		}
	}
	printf("%d %d\n",ans_left,ans_right);
}


int main(){

	int X,Y;

	table = new int[1000010];

	while(true){
		scanf("%d %d",&X,&Y);
		if(X == 0 && Y == 0)break;

		for(int i = 0; i < Y; i++)table[i] = -1;

		func(X,Y);
	}

    return 0;
}

Measured memory_bytes: 6660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
#define mod(x) x % MOD
#define INF 0x3f3f3f3f

vector<int> G[maxn];
int deg[maxn];
ll dp[maxn][2];
void dfs(int s, int f){
    if(deg[s] == 1 && f != 0){
        dp[s][0] = 1;
        dp[s][1] = 1;
        return ;
    }
    ll res1 = 1, res2 = 1;
    for(int i = 0;i < G[s].size();i++){
        if(G[s][i] == f) continue;
        dfs(G[s][i], s);
        res1 = res1 * (dp[G[s][i]][0] + dp[G[s][i]][1]) % MOD;
        res2 = res2 * (dp[G[s][i]][0]) % MOD;
       // if(s == 2) cout<<"res1 : "<<res1<<" res2: "<<res2<<endl;
        //ans += dp[G[s][i]][0];
    }
    dp[s][1] = res2;
    dp[s][0] = res1;
}

int main(){
    int n = 0;
    while(~scanf("%d", &n)){
        for(int i = 1;i < n ;i++){
            int x, y;
            scanf("%d %d", &x, &y);
            G[x].push_back(y);
            G[y].push_back(x);
            deg[x]++, deg[y]++;
        }
        dfs(1, 0);
        // for(int i = 1;i <= n;i++){
        //     cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl;
        // }
        printf("%lld\n", (dp[1][0] + dp[1][1]) % MOD );
    }
    return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) // cout << #x << " = " << (x) << endl;

const double EPS = 1e-6;

struct point{
  double x, y;
  point() {}
  point(double X, double Y) : x(X), y(Y) {}
  point operator -(const point &o){
    point p(x - o.x, y - o.y);
    return p;
  }
  bool operator <(const point &p) const{
    return x < p.x || (x == p.x && y < p.y);
  }
  bool operator ==(const point &o){
    if(fabs(x - o.x) <= EPS && fabs(y - o.y) < EPS)
      return true;
    return false;
  }
  double dist(point &o){
    double d = (x - o.x)*(x - o.x);
    d += (y - o.y)*(y - o.y);
    d = sqrt(d);
    return d;
  }
  double cross_product(const point &a, const point &b) {
    return (a.x - x) * (b.y - y) - (a.y - y) * (b.x - x);
  }
  double point_product(const point &a, const point &b) {
    return (a.x - x) * (b.x - x) + (a.y - y) * (b.y - y);
  }
  double norm() {
    return sqrt(x * x + y * y);
  }
  friend ostream& operator <<(ostream& stream, point &p){
    stream << "(" << p.x << "," << p.y << ")";
    return stream;
  }
};

vector<point> convex_hull(vector<point> P){
  int n = P.size(), k = 0;
  vector<point> H(2 * n);
  sort(P.begin(), P.end());

  for(int i = 0; i < n; ++i){
    while(k >= 2 and H[k-2].cross_product(H[k-1], P[i]) < 0) k--;
    H[k] = P[i];
    k++;
  }

  for(int i = n - 2, t = k + 1; i >= 0; --i){
    while(k >= t and H[k-2].cross_product(H[k-1], P[i]) < 0) k--;
    H[k] = P[i];
    k++;
  }
  H.resize(k);
  
  return H;
}


int main() { IO;
  int n;
  cin >> n;

  vector<point> P(n);
  for (auto &p : P) {
    cin >> p.x >> p.y;
  }

  // if (n == 2) {
  //   cout << 0.5 << endl;
  //   cout << 0.5 << endl;

  //   return 0;
  // }
  
  vector<point> H = convex_hull(P);
  H.pop_back();
  int sz = H.size();

  for (auto p : H) D(p);
  
  double total_len = 0;
  for (int i = 0; i < sz; ++i) {
    int j = (i + 1) % sz;
    double d = H[i].dist(H[j]);
    total_len += d;
    D(d);
  }
  D(total_len);

  vector<double> prob;
  for (int i = 0; i < sz; ++i) {
    int j = (i - 1 + sz) % sz;
    int k = (i + 1) % sz;

    // double d = H[i].dist(H[j]) + H[i].dist(H[k]);
    // d /= 2;
    // D(d);

    // prob.push_back(d / total_len);

    double angle = H[i].point_product(H[j], H[k]);
    angle /= (H[j] - H[i]).norm();
    angle /= (H[k] - H[i]).norm();

    angle = M_PI - acos(angle);
    double p = angle / (2 * M_PI);

    D(angle); D(p);
    prob.push_back(p);
  }

  vector<double> ans;
  for (int i = 0; i < n; ++i) {
    double p = 0;
    for (int j = 0; j < sz; ++j) {
      if (P[i] == H[j]) {
        p = prob[j];
        break;
      }
    }

    ans.push_back(p);
  }

  for (auto d : ans) {
    cout << setprecision(9) << fixed << d << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; cin >> n;
    vector<ll> a(n), bit(30, 0);
    ll b = 0;
    rep(i, n){
        cin >> a[i];
        b += a[i];
        rep(j, 30) if(a[i] & (1LL << j)) bit[j]++;
    }
    if(n%3 != 0 && b != 0){
        cout << "No" << endl;
        return 0;
    }
    rep(i, 30){
        if(bit[i] != 0 && bit[i] != 2*(n/3)){
            cout << "No" << endl;
            return 0;
        }
    }
    //for(auto i : bit) cout << i << " "; cout << endl;
    cout << "Yes" << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl
#define PI 3.14159265358979323846

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a;
	cin>>a;
	cout<<(a>=30?"Yes":"No")<<Endl;
	return 0;
}

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

int main(){
    int N; cin >> N;
    vector<int>W(N);
    for(int i=0; i<N; i++){
        cin >> W[i];
    }
    int mn = 99999; 
    for(int T=1; T<N-1; T++){
        int S1 = accumulate(W.begin(), W.begin()+T+1, 0);
        
        int S2 = accumulate(W.begin()+T+1, W.end() , 0);
        
        int ABS = abs(S1-S2);
        mn = min(mn, ABS);
    }

    cout << mn << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define all(obj) obj.begin(), obj.end()
#define debug(x) cerr << #x << ":" << x << " "
#define debugl(x) cerr << #x << ":" << x << "\n"
#define vdebug(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

// prime factorization
vector<pii> pf(int N) {
	vector<pii> res;
	for (int p = 2; p * p <= N; p++) {
		if (N % p == 0) {
			int k = 0;
			while (N % p == 0) {
				N /= p; k++;
			}
			pii pk(p, k);
			res.push_back(pk);
		}
	}
	if (N > 1) {
		pii pk(N, 1);
		res.push_back(pk);
	}
	return res;
}

// number of positive divisors
int nod(int N) {
	int res = 1;
	for (auto pk : pf(N)) {
		res *= pk.second + 1;
	}
	return res;
}
int main () {
	int N; cin >> N;
	int ans = 0;
	rep2(i, 1, N + 1) {
		if (i % 2 == 0) continue;
		if (nod(i) == 8) {
			// debugl(i);
			ans++;
		}
	}
	cout << ans << endl;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  mod 1000000007

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

inline void normal(ll &a)
{
    a %= mod;
    (a < 0) && (a += mod);
}
inline ll modMul(ll a, ll b)
{
    a %= mod, b %= mod;
    normal(a), normal(b);
    return (a * b) % mod;
}
inline ll modAdd(ll a, ll b)
{
    a %= mod, b %= mod;
    normal(a), normal(b);
    return (a + b) % mod;
}
inline ll modSub(ll a, ll b)
{
    a %= mod, b %= mod;
    normal(a), normal(b);
    a -= b;
    normal(a);
    return a;
}
inline ll modPow(ll b, ll p)
{
    ll r = 1;
    while (p)
    {
        if (p & 1) r = modMul(r, b);
        b = modMul(b, b);
        p >>= 1;
    }
    return r;
}
inline ll modInverse(ll a)
{
    return power(a, mod - 2);
}
inline ll modDiv(ll a, ll b)
{
    return modMul(a, modInverse(b));
}

ll pre[2000009];

void cal()
{
    pre[0] = 1;

    for(ll i=1; i<=2000000; i++)
    {
        pre[i] = (i*pre[i-1])%mod;
    }
}

ll ncr(ll n,ll r)
{
    return  modMul(pre[n],modMul(modInverse(pre[r]),modInverse(pre[n-r])));
}
int main()
{

    ll tst;

   ll a,b,c,d;
    ll i,j,k,l,m,n,x,y;

    cin  >> a >> b >> c >> d;

    cout << max({a*c,b*d,a*d,b*c}) << endl;



    ll ans = 0;



//    ll mn = -1,mx= -1,lmx=-1,lmn=-1;
//
//    vl v1,v2;
//    for(i=0; i<n; i++)
//    {
//        cin  >> x >> y;
//
//        if(mn == -1)mn = x+y;
//        else mn = min(mn,x+y);
//
//        if(mx == -1)mx = x+y;
//        else mx = max(mx,x+y);
//
//        v1.pb(x-y);
//        v2.pb(y-x);
//    }
//
//    ll ans = mx-mn;
//
//
//    sort(all(v1));
//    sort(all(v2));
//    reverse(all(v1));
//    reverse(all(v2));
//
//    ans = max(ans,v1[0]+v2[0]);
//
//    cout << ans << endl;



}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)

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

  set<int> set;
  set.insert(s);
  int cnt = 1;
  int a;

  while(true){
    if (cnt == 1) a = s;
    if (a % 2 == 0){
      a /= 2;
    }
    else
    {
      a = 3 * a + 1;
    }
    cnt += 1;
    if (set.count(a)) break;
    set.insert(a);
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 3608
N=int(input())
L=list(map(int,input().split()))
A=1
if 0 in L:
  print(0)
  exit()
for i in range(N):
  A=A*L[i]
  if 10**18<A:
    print(-1)
    exit()
if 10**18<A:
  print(-1)
else:
  print(A)

Measured memory_bytes: 21648
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  string s,t;
  cin>>s>>t;
  int ans=INT_MAX;
  rep(i,s.length()-t.length()+1){
      int c=0;
      rep(j,t.length()){
          if(t[j]!=s[i+j]) c++;
      }
      ans=min(ans,c);
  }
  cout<<ans<<endl;
  return 0;
}

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

long long int table[1001][1001];

int main(){

    int n,m;

    cin >> n >> m;

    int dir[n],weather[m];

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

    for(int i=0;i<m;i++){
      cin >> weather[i];
    }

    n++;m++;

    for(int i=0;i<n;i++){
      table[0][i] = 10000000000;
    }

    for(int i=0;i<m;i++){
      table[i][0] = 0;
    }

    for(int i=1;i<m;i++){
      for(int j=1;j<n;j++){
        if(m-n+1 < i  && (m-i+j<n) ){
          table[i][j] = 10000000000;
          continue;
        }
        table[i][j] = min(table[i-1][j],table[i-1][j-1]+dir[j-1]*weather[i-1]);
      }
    }

    cout << table[m-1][n-1] << endl;


    return 0;
}

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

int chmin(int a,int b){
    if(a > b) return b;
    else return a;
}

int main(){
    int N,K;
    cin >> K >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    int min=-1;
    int minidx;

    for(int i=0;i<N-1;i++){
        if(min < A[i+1]-A[i]) {min=A[i+1]-A[i]; minidx=i;}
    }
    if(min < (K-A[N-1]+A[0])) minidx=N;

    int ans = K;
    if(minidx==N) ans-=(K-A[N-1]+A[0]);
    else ans-=A[minidx+1]-A[minidx];

    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int[] point = new int[n];

        for(int i = 0;i < q;i++){
            point[sc.nextInt()-1]++;
        }
        
        for(int i = 0;i < n;i++){
            if(k-q+point[i] > 0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 67500
#include<iostream>
using namespace std;
int dx[]={0,1,0,-1,1,1,-1,-1},dy[]={1,0,-1,0,1,-1,1,-1};
struct E{
	int w,h;
	int ma[50][50],color[50][50];
	bool used[50][50];
	int col;
	int init(int _w,int _h)
	{
		w=_w,h=_h;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				cin>>ma[i][j];
				used[i][j]=color[i][j]=0;
			}
		}
	}
	void dfs(int x,int y)
	{
		used[x][y]=1;
		color[x][y]=col;
		for(int r=0;r<8;r++)
		{
			int tx=x+dx[r],ty=y+dy[r];
			if(tx<0||ty<0||tx>=h||ty>=w||ma[tx][ty]==0||used[tx][ty])continue;
			dfs(tx,ty);
		}
	}
	void solve()
	{
		col=0;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(used[i][j]||ma[i][j]==0)continue;
				col++;
				dfs(i,j);
			}
		}
		cout<<col<<endl;
	}
};
main()
{
	int a,b;
	while(cin>>a>>b,a)
	{
		E s;s.init(a,b);s.solve();
	}
}



Measured memory_bytes: 3164
import math


class RMQ:
    def __init__(self, n):
        k = 1
        while k < n:
            k *= 2
        self.N = k
        self.node = [float("inf")] * (2 * self.N - 1)

    def update(self, i, x):
        i += self.N - 1
        self.node[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = min(self.node[2 * i + 1], self.node[2 * i + 2])

    def _find(self, a, b, i, l, r):
        if r <= a or b <= l:
            return float("inf")
        elif a <= l and r <= b:
            return self.node[i]

        else:
            mid = (l + r) // 2
            return min(self._find(a, b, 2 * i + 1, l, mid), self._find(a, b, 2 * i + 2, mid, r))

    def find(self, a, b):
        return self._find(a, b, 0, 0, self.N)


n, q = map(int, input().split())
rmq = RMQ(n)
inf = 2147483647
for j in range(q):
    c, x, y = map(int, input().split())
    if c == 0:
        rmq.update(x, y)
    else:
        m = rmq.find(x, y + 1)
        if m == float("inf"):
            print(inf)
        else:
            print(m)


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

#ifdef LOCAL
  #include <contest/local.hpp>
#else
  #define LOG(...) do {} while (false)
#endif

#define REP(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)

using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  unsigned n;
  cin >> n;

  vector <int> a;
  vector <int> b;

  REP (i, n + 1)
  {
    int x;
    cin >> x;
    a.push_back (move (x));
  }
  REP (i, n)
  {
    int x;
    cin >> x;
    b.push_back (move (x));
  }

  int64_t ans = 0;
  REP (i, n)
  {
    if (a [i] <= b [i])
    {
      auto t = a [i];
      ans += t;
      a [i] -= t;
      b [i] -= t;
    }
    else
    {
      auto t = b [i];
      ans += t;
      a [i] -= t;
      b [i] -= t;
    }

    auto j = i + 1;
    if (a [j] <= b [i])
    {
      auto t = a [j];
      ans += t;
      a [j] -= t;
      b [i] -= t;
    }
    else
    {
      auto t = b [i];
      ans += t;
      a [j] -= t;
      b [i] -= t;
    }
  }

  cout << ans << endl;
}



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

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

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

  int m;
  cin >> m;

  int p, x;
  for(int i = 0; i < m; i++){
    cin >> p >> x;
    cout << sum + x - t[p-1] << endl;
  }

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (e);(i) --> (s);)
#define all(x) x.begin(),x.end()

int main() {
  i64 N;
  cin >> N;
  vector<i64> s(N);
  rep(i,0,N) cin >> s[i];

  i64 ans = s[0] + s[N - 1];

  rep(C,1,N) {
    if((N - 1) % C == 0) {
      i64 now = 0;
      i64 i = 0;
      i64 j = N - 1;
      while(i < j) {
        now += s[i] + s[j];
        i += C;
        j -= C;
        ans = max(ans, now);
      }
    }
    else {
      i64 now = 0 ;
      i64 i = 0;
      i64 j = N - 1;
      while(i < N - 1 && C < j) {
        now += s[i] + s[j];
        i += C;
        j -= C;
        ans = max(ans, now);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

nums = gc
puts nums.include?('9') ? 'Yes' : 'No'


Measured memory_bytes: 2428
import math
A, B, H, M = map(int, input().split())

H_deg = H*30 + M*0.5
M_deg = M*6
if M_deg <= H_deg:
    degree = H_deg - M_deg
else:
    degree = M_deg - H_deg

if degree == 180:
    print(A+B)
elif degree < 180:
    c = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(degree)))
    print(c)
else:
    c = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(360-degree)))
    print(c)

Measured memory_bytes: 9528
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};
const int NMAX=100010;
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;	
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n,k;
	cin>>n>>k;
	vector<int> a(n);
	rep(i,0,n)cin>>a[i];
	sort(a.begin(),a.end());
	
	Make_Fact();
    Make_InvFact();
   
    mint ans;
	
	rep(i,0,n-k+1){
		ans += (mint)(-a[i])*Comb(n-i-1,k-1);
	}
	for(ll i=k-1;i<n;++i){
		ans += (mint)a[i]*Comb(i,k-1);
	}
	cout<<ans.x<<endl;
  	return 0;
}


Measured memory_bytes: 2176
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n, k = MI()
v = LI()
m = min(n, k)
ans = -INF
for a in range(m+1):
    for b in range(0, m+1-a):
        tmp_l = []
        for i in range(a):
            tmp_l.append(v[i])
        for j in range(b):
            tmp_l.append(v[-(j+1)])
        index = 0
        negative_sum = 0
        tmp_l.sort()
        while index < len(tmp_l) and index < k-(a+b):
            if tmp_l[index] < 0:
                negative_sum -= tmp_l[index]
            index += 1
        ans = max(ans, negative_sum + sum(tmp_l))
print(ans)

        


Measured memory_bytes: 69720
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;


int main(){
    long long int n, k;
    cin >> n >> k;
    vector<long long int> a(2*n);
    for(long long int i=0;i<n;i++) cin >> a[i];
    for(long long int i=n;i<2*n;i++) a[i] = a[i-n];

    long long int res = 0;

    // aの中にある転倒数
    for(long long int i=0;i<n-1;i++){
        for(long long int j=i+1;j<n;j++){
            if(a[i] > a[j]) {
                res++;
            }
        }
    }

    //aを跨いで存在する転倒数
    long long int res1 = 0;
    for(long long int i=0;i<n;i++){
        for(long long int j=n;j<2*n;j++){
            if(a[i] > a[j]){
                res1++;
            }
        }
    }
    long long int ans = k*res%1000000007;
    ans += res1 * (((k-1)*k)/2 % 1000000007)%1000000007;
    ans %= 1000000007;

    cout << ans << endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i, s.size()){
    if(s[i] != t[i])ans++;
  }
  cout << ans << endl;
}

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

using namespace std;
int main() {
    int n;
    int q;
    int cnt = 0;

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

    cin >> q;
    vector<int> T(q);
    for (int i = 0; i < q; i++) {
        cin >> T[i];
    }

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (T[i] == S[j]) {
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 3116
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
# from copy import deepcopy, copy

import queue
from collections import deque



def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]
    for i in range(high):
        for j in range(width):
            if data[i][j] == '.':
                data[i][j] = 10 ** 5
            else:
                data[i][j] = 0

    for i in range(high):
        for j in range(1, width):
            data[i][j] = min(data[i][j], data[i][j - 1] + 1)

    for i in range(high):
        for j in range(width - 1)[::-1]:
            data[i][j] = min(data[i][j], data[i][j + 1] + 1)

    for j in range(width):
        for i in range(1, high):
            data[i][j] = min(data[i][j], data[i - 1][j] + 1)

    for j in range(width):
        for i in range(high - 1)[::-1]:
            data[i][j] = min(data[i][j], data[i + 1][j] + 1)


    ans = 0
    for i in range(high):
        ans = max(ans, max(data[i]))

    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 139096
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    YES(a.back() == b.front() && b.back() == c.front());
}


Measured memory_bytes: 256
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = map(int, read().split())
l = M
checked = [False] * (N + 10)

if N % 2 == 1:
    for i in range(1, M + 1):
        r = l + 2 * i - 1
        print(l, r)
        l -= 1

else:
    p = (M + 1) // 2
    for i in range(1, p + 1):
        r = l + 2 * i - 1
        print(l, r)
        l -= 1
    for i in range(p + 1, M + 1):
        r = l + 2 * i - 1 + 1
        print(l, r)
        l -= 1


Measured memory_bytes: 10208
def calc(b,A):
  ret=0
  for i,num in enumerate(A):
    ret += abs( num-(b+i+1) )
  return ret    
##########################

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

L=-1*10**9
R=10**9
i=(L+R)//2

while True:
  s=calc(i-1,A)
  t=calc(i,A)
  u=calc(i+1,A)
  if s<t<u:
    R=i
    i=(L+R)//2
  elif s>t>u:
    L=i
    i=(L+R)//2
  else:
    print(t)
    break

Measured memory_bytes: 86868