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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
//setprecision(10);
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
        return b != 0 ? gcd(b, a % b) : a;
    }


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    pair<llong ,llong> Q[n];
    llong vv=0;
    int cnt=0;
    REP(i,n)
    {
        llong a,b; cin>>a>>b;
        Q[i].first=a;
        Q[i].second=b;
        if(vv<a)
        {
            vv=a;
            cnt=i;
        }
    }

    cout<<Q[cnt].first+Q[cnt].second<<endl;
    return  0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ASC(v) sort(v.begin(), v.end());
#define DESC(v) sort(v.begin(), v.end(), greater<int>());
#define REVERSE(v) reverse(v.begin(), v.end());
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	bool can = true;

	REP(i, N) {
		if (A[i]%2==0){
			if (A[i]%3!=0 && A[i]%5!=0) can = false;
		}
	}

	if (can) cout << "APPROVED" << "\n";
	else cout << "DENIED" << "\n";
}


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

int main() {
    int n, a, b, cnt = 0;
    vector<long long> v;
    vector< vector<long long> > c;
    long long sum = 0, num = 0;
    cin >> n >> a >> b;
    v.assign(n, 0);
    for(int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(), v.end(), greater<long long>());
    for(int i=0;i<a;i++) sum += v[i];
    for(int i=0;i<n;i++){
        if(v[i] == v[a-1]) cnt++;
    }
    c.assign(cnt+1, vector<long long>());
    for(int i=1;i<=cnt;i++){
        c[i].assign(i+1, 1);
        for(int j=1;j<i;j++){
            c[i][j] = c[i-1][j] + c[i-1][j-1];
        }
    }
    int d = 0;
    for(int i=0;i<b;i++){
        if(v[i] == v[a-1]) d++;
        if(i >= a && v[i] != v[0]) break;
        if(i >= a-1) num += c[cnt][d];
    }
    cout << fixed << setprecision(8) << (double) sum / a << endl;
    cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] ary = new int[k];
		for( int i = 0; i < k; i++ ) ary[i] = in.nextInt();
		Arrays.sort(ary);
		int ans = 0;
		if( k != 1 ) {
			int[] diffs = new int[k-1];
			for( int i = 0; i < k-1; i++ ) diffs[i] = ary[i+1] - ary[i];
			Arrays.sort(diffs);
			//System.out.println(Arrays.toString(diffs));
			for( int i = 0; i < k-n; i++ ) ans += diffs[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 52896
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int D = scanner.nextInt();
    int[][] x = new int[N][D];
    for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) x[i][j] = scanner.nextInt();

    int count = 0;
    for (int i = 0; i < N - 1; i++) {
      for (int j = i + 1; j < N; j++) {
        long d = 0;
        for (int k = 0; k < D; k++) {
          d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int dd = (int) Math.sqrt(d);
        if (dd * dd == d) count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back

template<typename T> void out(vector<T> v) {rep(i, v.size()) cout << v[i] << " "; cout << endl;}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, k; string s; cin >> n >> k >> s;
    vector<int> Nums;
    int now = 1; //今見ているかず
    int cnt = 0; //nowがいくつ並んでいるか
    for (int i = 0; i < n; ++i) {
        if (s[i] == (char)('0' + now)) cnt++;
        else {
            Nums.eb(cnt);
            now = 1 - now; //0, 1 切り替え
            cnt = 1; //新しいのをカウントし始める
        }
    }
    if (cnt != 0) Nums.push_back(cnt);
    //1 - 0 - 1 - 0 - 1
    //0で終わってたら
    if(Nums.size() % 2 == 0) Nums.eb(0);
    int Add = 2 * k + 1;
    int ans = 0;
    //累積和を作る
    
    vector<int> sum(Nums.size() + 1);
    for (int i = 0; i < Nums.size(); ++i) {
        sum[i + 1] = sum[i] + Nums[i];
    }
    //1 - 0 - 1...の1から始めるので偶数番目だけ見る
    for (int i = 0; i < Nums.size(); i += 2) {
        //次のleft, rightを計算する[left, right)
        int left = i;
        int right = min(i + Add, (int)Nums.size());
        int tmp = sum[right] - sum[left];
        chmax(ans, tmp);
    }
    cout << ans << endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  for(int i = 0; i < (1 << 3); i++) {
    string ans = "";
    ans.push_back(s[0]);
    int sum = s[0] - '0';
    // jがopにたいおう
    for(int j = 0; j < 3; j++) {
      if(i & (1 << j)) {
        sum += s[j + 1] - '0';
        ans.push_back('+');
        ans.push_back(s[j + 1]);
      } else {
        sum -= s[j + 1] - '0';
        ans.push_back('-');
        ans.push_back(s[j + 1]);
      }
    }
    // cout << sum << ' ' << ans << endl;
    if(sum == 7) {
      ans += "=7";
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for a in range(A+1) :
    for b in range(B+1) :
        for c in range(C+1) :
            if 500*a + 100 * b + 50 * c == X :
                ans += 1

print(ans)

Measured memory_bytes: 9044
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		String str = (n == 0) ? "0" : "";
		while (n != 0) {
			if(n % 2 != 0) {
				n--;
				str = "1" + str;
			}else {
				str = "0" + str;
			}
			n /= -2;
		}
		System.out.println(str);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll MAX=51000;
const ll MOD=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];
ll extGCD(ll a,ll b,ll &x,ll &y){
  if(b==0){
    x=1;
    y=0;
    return a;
  }
  ll d=extGCD(a,b%a,y,x);
  y-=(a/b)*x;
  return d;
}
void COMtable(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[n-k]*finv[k]%MOD)%MOD;
}
int main(){
  ll N,K;
  cin >> N >> K;
  ll a[K]={0};
  ll amari=N-K;
  COMtable();
  for(ll i=0;i<K;i++){
    a[i]=COM(amari+1,i+1)*COM(K-1,i)%MOD;
  }
  for(ll i=0;i<K;i++) cout << a[i] << endl;
}


Measured memory_bytes: 1408
import java.math.BigDecimal;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int count = scanner.nextInt();
			scanner.nextLine();
			BigDecimal rate = new BigDecimal("380000.0");
			System.out.println(IntStream.range(0, count).mapToObj(i -> {
				String amount = scanner.next();
				String currency = scanner.next();
				scanner.nextLine();
				if ("JPY".equals(currency)) {
					return new BigDecimal(amount);
				} else {
					return (new BigDecimal(amount)).multiply(rate);
				}
			}).reduce(BigDecimal.ZERO, BigDecimal::add));
		}
	}
}

Measured memory_bytes: 28752
d=gets.to_i
c=gets.split.map(&:to_i)
s=[]
d.times do
  s << gets.split.map(&:to_i)
end
l=[0]*26
(d-1).times do |i|
  m=0
  mi=0
  26.times do |j|
    l[j]+=1
  end
  26.times do |j|
    cs1=c[j]*(2*l[j]-1)+s[i][j]
    26.times do |k|
      cs2=c[k]*l[k]+s[i+1][k]
      if cs1+cs2>m
        m=cs1+cs2
        mi=j
      end
    end
  end
  puts mi+1
  l[mi]=0
end
m=0
mi=0
26.times do |j|
  l[j]+=1
end
26.times do |j|
  cs=c[j]*l[j]+s[d-1][j]
  if cs>m
    m=cs
    mi=j
  end
end
puts mi+1


Measured memory_bytes: 14384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;


const int MOD = 998244353;

inline int add(int x, int y){
	int res = x + y;	
	while(res >= MOD)res-=MOD;
	return res;
}

inline int mul(int x,int y){
	return (1LL * x * y) % MOD;
}

int modpow(int x,int p){
	int res = 1;
	while(p){
		if(p&1)gmul(res,x);
		gmul(x,x);
		p/=2;
	}
	return res;
}

inline int invert(int x){
	return modpow(x,MOD - 2);
}

const int N = 3000 + 5;

int dp[N];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,s;
	cin >> n >> s;
	dp[0] = modpow(2,n);
	int inv = invert(2);
	rep(i,0,n){
		int x;
		cin >> x; 
		for(int i = N-1-x; i >= 0; --i){
			gadd(dp[i+x],mul(dp[i],inv));
		}
	}
	cout << dp[s] << '\n';
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
vector <char> v;
vector<int>ansl;
string s;

int main(){
  int N;

  cin >>N;

  while (N != 0)  {
    int ans = 0;

    for(int j = N-1;j>0;j--){
      int ruiseki = 0;

      for(int k = 1;k<=j;k++){
        ruiseki += k;
      }
      for(int k = 1;k<=j;k++){
        if(ruiseki == N){
          ans++;
        }
        ruiseki -= k;
      }
    }
    ansl.push_back(ans);
    cin >>N;
  }


  for (int i = 0;i<(int)ansl.size();i++){
    cout <<ansl[i]<<endl;
  }

  return 0;
}



Measured memory_bytes: 3124
#include"bits/stdc++.h"
 
using namespace std;
 
int main() {
	string s;
	cin >> s;
	string ans = "AC";
 
	if (s[0] != 'A') {
		ans = "WA";
	}
	int C = 0;
	for (int i = 2; i < s.length() - 1; i++) {
		if (s[i] == 'C') {
			C++;
		}
	}
	if (C != 1) {
		ans = "WA";
	}
 
 
	int cnt = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] >= 'A' && s[i] <= 'Z') {
			cnt++;
		}
	}
	if (cnt != 2) {
		ans = "WA";
	}
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())

ans = [0] * n
for v in itertools.product(list(range(1,101)), repeat=3):
    x,y,z = v[0], v[1], v[2]
    a = x*x + y*y + z*z + x*y + y*z + z*x
    if a <= n:ans[a-1] += 1
    else: continue
for i in ans: print(i)

Measured memory_bytes: 9196
#include<stdio.h>
#define N 100
#define White 0
#define Black 2
#define Gray 1


int GX[N][N],x,color[N],time,d[N],f[N];

void visit(int u){
  int v;
  color[u]=Gray;
  d[u]=++time;
  for(v=0;v<x;v++){
    if(GX[u][v]==0) continue;
    if(color[v]==White) visit(v);
  }
  color[u]=Black;
  f[u]=++time;
}

void dfs(){
  int u;
  for(u=0;u<x;u++) color[u]=White;
  time=0;
  for(u=0;u<x;u++){
    if(color[u]==White) visit(u);
  }
  for(u=0;u<x;u++) printf("%d %d %d\n",u+1,d[u],f[u]);
}

int main(){

  int i,j,a,b,c,v,g;

  scanf("%d",&x);

  for(i=0;i<x;i++){
    for(j=0;j<x;j++){
      GX[i][j]=0;
    }
  }

  for(i=0;i<x;i++){
    scanf("%d",&v);
    scanf("%d",&g);
    for(j=0;j<g;j++){
      scanf("%d",&a);
      GX[v-1][a-1]=1;
    }
  }

  dfs();
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin>>a;
    cin>>b;
    cin>>c;
    if(a == b)
    {
        cout<<c;
    }
    else if(a == c)
    {
        cout<<b;
    }
    else
    {
        cout<<a;
    }
    return 0;
}


Measured memory_bytes: 256
# amidaをbitで管理
MOD = 10**9+7
H,W,K = map(int,input().split())
K -= 1
dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        for bit in range(1<<(W-1)):
            ok = True
            for k in range(W-2):
                if bit & (1 << k) and bit & (1 << (k+1)):
                    ok = False
            if not ok:
                continue
            nj = j
            if bit & (1<<j):
                nj = j+1
            elif j>0 and bit & (1<<(j-1)):
                nj = j-1
            dp[i+1][nj] += dp[i][j]
            dp[i+1][nj] %= MOD

print(dp[H][K]%MOD)

Measured memory_bytes: 44268
#include<stdio.h>
int main()
{
   int W,H,i=0,j=0;
   while(1){
       scanf("%d %d",&H,&W);
       if (H==0 && W==0)  break;

       for (i=0;i<H;i++){
           for (j=0;j<W;j++){
               printf("#");
           }
           printf("\n");
       }
       printf("\n");

   }
      return 0;
}


Measured memory_bytes: 2588
#include <iostream>
#include <string>


using namespace std;


int main()
{
    string s;
    cin >> s;
    
    
    auto c = s.find("C");
    auto f = s.find("F", c);
    
    if( f != string::npos ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < n; i++){
			int money0 = Integer.parseInt(br.readLine());
			int year = Integer.parseInt(br.readLine());
			int numOfMethod = Integer.parseInt(br.readLine());
			
			int maxResult = -1;
			for(int j = 0; j < numOfMethod; j++){
				String[] tmpStr = br.readLine().split(" ");
				
				int method = Integer.parseInt(tmpStr[0]);
				double ratio = Double.parseDouble(tmpStr[1]);
				int fee = Integer.parseInt(tmpStr[2]);
				int result = 0;
				
				if(method == 0){
					result = calcTanri(money0, year, ratio, fee);
				}
				else if (method == 1){
					result = calcFukuri(money0, year, ratio, fee);
				}
				
				//System.out.println(result);
				if(result > maxResult){
					maxResult = result;
				}
			}
			
			System.out.println(maxResult);
		}
	}

	private static int calcFukuri(int money0, int year, double ratio, int fee) {
		// TODO ?????????????????????????????????????????????
		for(int i = 0; i < year ; i++){
			money0 *= (1 + ratio);
			money0 -= fee;
		}
		return money0;
	}

	private static int calcTanri(int money0, int year, double ratio, int fee) {
		// TODO ?????????????????????????????????????????????
		int rishiSum = 0;
		
		for(int i = 0; i < year ; i++){
			rishiSum += money0*ratio;
			money0 -= fee;
		}
		
		return money0 + rishiSum;
	}
	
	
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;


// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
vll a;
// <------------- Implement Functions Here ----------> //

ll dp[200][300];

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> x;
	ll ans = 0;
	dp[0][0] = 1;
	for(ll i=0;i<n;i++) {
		cin >> y;
		for(ll j=i;j>=0;j--) 
			for(ll k=0;k<256;k++) {
				dp[j+1][k^y] += dp[j][k]*(j+1);
				dp[j+1][k^y]%=MOD;
			}
	}

	for(ll i=0;i<=n;i++) 
		ans += dp[i][x];
	cout<<ans%MOD;newl;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main()
{
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        char c;
        cin >> c;
        if (c == 'Y')
        {
            cout << "Four";
            return 0;
        }
    }
    cout << "Three";
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int m,f,r,sum;
	char score;

	while(1){
		scanf("%d %d %d",&m,&f,&r);
		sum=m+f;
		if(m==-1 && f==-1 && r==-1) break;
		else if(m==-1 || f==-1) score='F';
		else if(sum<30) score='F';
		else if(sum<50){
			if(r<50) score='D';
			else score='C';
		}
		else if(sum<65) score='C';
		else if(sum<80) score='B';
		else score='A';
		printf("%c\n",score);
	}
	
	return 0;	
}	

Measured memory_bytes: 600
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

#define debugone(x) cerr << #x << " " << x << endl;
#define debugtwo(x) cerr << #x << "-------------" << endl;for(auto &it: x) cerr << it << " ";cerr << endl;
#define debugthree(x, i, j) cerr << #x << "------------" << endl;cerr << "from " << i << " to " << j << endl;for(int k=i; k<=j; k++) cerr << x[k] << " ";cout << endl;

const int mod = (int)1e9 + 7;


int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int a, b;
	cin >> a >> b;
	if(a <= 5){
		cout << 0 << endl;
	}
	else if(a >= 13){
		cout << b << endl;
	}
	else cout << b/2 << endl;
	
}	

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

static const size_t x_max = 100, n_max = 9, s_max = 1000;
static unsigned long long dp[2][n_max+1][s_max+1];

int main() {
  for (;;) {
    size_t n, s;
    scanf("%zu%zu", &n, &s);
    if (!n && !s)
      return 0;
    for (size_t i = 0; i <= n; i++)
      for (size_t j = 0; j <= s; j++)
        dp[0][i][j] = 0;
    dp[0][0][0] = 1;
    size_t l = std::min(s, x_max);
    for (size_t x = 1; x <= l; x++)
      for (size_t i = 0; i <= n; i++)
        for (size_t j = 0; j <= s; j++) {
          dp[x%2][i][j] = dp[(x-1)%2][i][j];
          if (i && x <= j)
            dp[x%2][i][j] += dp[(x-1)%2][i-1][j-x];
        }
    printf("%llu\n", dp[l%2][n][s] + dp[l%2][n-1][s]);
  }
}

Measured memory_bytes: 2800
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 200010
ll f[M],iv[M];
ll ex(ll a,ll b){
	ll ans=1;a%=md;
	while(b){
		if(b&1)ans=(ans*a)%md;
		a=(a*a)%md;b/=2;
	}
	return ans;
}
ll C(ll n,ll r){
	if(n<r)return 0;
	ll ans=(f[n]*iv[r])%md;
	ans=(ans*iv[n-r])%md;
	return ans;
}
ll g(ll n,ll k){
	ll ans=1;
	rep(i,0,k)ans=(ans*(n-i))%md;
	ans=(ans*iv[k])%md;
	return ans;
}
int main(){
	IOS;
	tihs;
	
	f[0]=1,iv[0]=1;
	rep(i,1,M)f[i]=(i*f[i-1])%md;
	iv[M-1]=ex(f[M-1],md-2);
	for(ll i=M-2;i>=0;--i)iv[i]=(iv[i+1]*(i+1))%md;

	ll n,a,b;cin>>n>>a>>b;
	ll ans = ex(2,n)-1+md;
	ans%=md;
	(ans-=g(n,a))%=md;
	(ans-=g(n,b))%=md;
	cout<<(ans+md)%md;
		

	return 0;
}

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

int main()
{
    int H, W, A, B;
    cin >> H >> W >> A >> B;


    rep (h, 0, B)
    {
        rep (w, 0, W)
        {
            if (w < A)
                printf("1");
            else
                printf("0");
        }
        printf("\n");
    }
    rep (h, B, H)
    {
        rep (w, 0, W)
        {
            if (w < A)
                printf("0");
            else
                printf("1");
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

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

int main()
{
	string S;
	cin >> S;
	string ss = "";
	for(int i = S.size() - 1; i >= 0; i--)
	{
		ss += S[i];
		if(ss == "maerd") ss = "";
		if(ss == "remaerd") ss = "";
		if(ss == "esare") ss = "";
		if(ss == "resare") ss = "";
	}
	if(ss == "") cout << "YES" << endl;
	else cout <<  "NO" << endl;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	map<int,int> rank; rank.clear();

	for (int i = 0, j = 1; i < 13; ++i, j = (j + 1) % 13){
//		cerr << "i: " << i << " j': " << j + 1 << endl;
		rank[j+1] = i;
	} // end for
 
	int A, B; cin >> A >> B;
	if (rank[A] < rank[B]){
		cout << "Bob" << endl;
	}else
	if (rank[A] > rank[B]){
		cout << "Alice" << endl;
	}else{
		cout << "Draw" << endl;
	} // end if

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(x - r < 0 || y - r < 0 || x + r > W || y + r > H){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define rep(i,x,n) for(ll i=x; i<n; ++i)
#define INF LLONG_MAX
using ll = long long;
using ull = unsigned long long;
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) { a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) { a=b; return true;} return false;}
ll dp[3][100000];
ll act[3][100000];
int main() {
  ll N; cin >> N;
  rep(i,0,N) cin >> act[0][i] >> act[1][i] >> act[2][i];

  dp[0][0] = act[0][0];
  dp[1][0] = act[1][0];
  dp[2][0] = act[2][0];
  rep(i,1,N) {
    rep(j,0,3) {
      rep(k,0,3) {
        if(j!=k) {
          chmax(dp[j][i], dp[k][i-1]+act[j][i]);
        }
      }
    }
  }
  ll ans = 0;
  rep(i,0,3) chmax(ans, dp[i][N-1]);
  cout << ans << endl;
}


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

int main()
{
    int a,b;
    cin>>a;
    cin>>b;

    if(a!=1 && b!=1){
        cout<<1<<endl;
    }
    else if(a!=2 && b!=2){
        cout<<2<<endl;
    }
    else if(a!=3 && b!=3){
        cout<<3<<endl;
    }
}

Measured memory_bytes: 3556
// AOJ 2015: Square Route
// 2017.11.04 bal4u@uu

#include <stdio.h>
#include <string.h>
#define TM 0
#if TM
#include <time.h>
#endif

int h[1502], w[1502];
int f[1500001];
char buf[20], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, v, sh, sw, s, ans;
#if TM
	clock_t start, end;
	start = clock();
#endif
	while (fgets(p=buf, 20, stdin) && *buf != '0') {
		n = getint(), p++, m = getint();
		for (sh = 0, i = 0; i < n; i++)	{
			fgets(p=buf, 10, stdin), v = getint();
			h[i] = v, sh += v;
		}
		for (sw = 0, i = 0; i < m; i++) {
			fgets(p=buf, 10, stdin), v = getint();
			w[i] = v, sw += v;
		}
		if (sh > sw) sh = sw;

		memset(f, 0, sizeof(f));
		for (i = 0; i < n; i++) {
			for (s = 0, j = i; s <= sh && j < n; j++) s += h[j], f[s]++;
		}
		ans = 0;
		for (i = 0; i < m; i++) {
			for (s = 0, j = i; s <= sh && j < m; j++) s += w[j], ans += f[s];
		}
		printf("%d\n", ans);
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

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

int main()
{
	int x, t;
	cin >> x >> t;
	if (x < t) {
		cout << 0 << endl;
	}
	else {
		cout << x - t << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int N;
string S;
using ull = unsigned long long;
ull csum[5010];
ull pow3[5010];

bool can(int i, int j, int x) {
  if (j + x >= S.size()) {
    return false;
  }

  if (i + x >= j) {
    return false;
  }

  ull h1 = csum[i + x + 1] - csum[i];
  ull h2 = csum[j + x + 1] - csum[j];
  return h1 * pow3[j - i] == h2;
}

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

  pow3[0] = 1;
  rep(i, 1, 5010) { pow3[i] = pow3[i - 1] * MOD; }

  rep(i, 0, N) { csum[i + 1] = csum[i] + S[i] * pow3[i]; }

  int ans = 0;
  rep(i, 0, N) {
    rep(j, i + 1, N) {
      if (S[i] != S[j]) continue;

      int low = 0;
      int high = S.size() - j;
      while (high - low > 1) {
        int mid = (low + high) / 2;
        if (can(i, j, mid)) {
          low = mid;
        } else {
          high = mid;
        }
      }
      chmax(ans, low + 1);
    }
  }

  cout << ans;
}


Measured memory_bytes: 3732
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
#include<tuple>
#include<stack>

#define _USE_MATH_DEFINES
#include<math.h>


using namespace std;
typedef long long ll;

typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef tuple<int, int, int> ti3;

const ll MOD_CONST = 1000000007;
//const ll MOD_CONST = 998244353;


const int BIG_NUM = 1000000005;
const ll INF = 1000000000000000000;

//const vector<vector<int>> DIR{ {1,0},{0,1},{-1,0},{0,-1} };

//const double EPS = 1e-10;


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

	vector<ll> sum;
	for (int i = 0; i < n; i++) {
		ll s = a[i];
		sum.emplace_back(s);
		for (int j = i + 1; j < n; j++) {
			s += a[j];
			sum.emplace_back(s);
		}
	}

	sort(sum.begin(), sum.end());

	vector<ll> v;
	for (int i = 63; i >= 0; i--) {
		if (v.size() == k) {
			break;
		}
		if (v.size() <=0) {
			for (int j = 0; j < sum.size(); j++) {
				if ((sum[j] >> i) & 1) {
					v.emplace_back(sum[j]);
				}
			}

			/*
			for (int vi : v) {
				cout << vi << " ";
			}
			cout << endl;
			*/
			if (v.size() < k) {
				v = vector<ll>();
			}
			continue;
		}

		vector<ll> newV;
		for (auto it = v.begin(); it != v.end(); it++) {
			if ((*it >> i) & 1) {
				newV.emplace_back(*it);
			}
		}
		if (newV.size() >= k) {
			v = newV;
		}
		
	}

	ll ans = 0;
	if (v.size() >= k) {
		ans = v[0];
		for (int i = 0; i < k; i++) {
			ans = (ans & v[i]);
		}
	}
	cout << ans << endl;


}



Measured memory_bytes: 6388
import bisect

n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))

ans = 0

for i in range(n):
    ans += bisect.bisect_left(a,b[i]) *(n- bisect.bisect_right(c,b[i]))

print(ans)

Measured memory_bytes: 23160
#coding: utf-8
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = 1000000000
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    tmp = min(abs(l) + abs(r - l), abs(r) + abs(r - l))
    ans = min(ans, tmp)
print(ans)

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

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

    vector<long> h(n);
    for (long i = 0; i < n; i++) cin >> h[i];

    vector<long> d(n, LONG_MAX);
    d[0] = 0;
    for (long i = 1; i < n; i++) {
        for (long j = 0; j < k; j++) {
            if (i > j) d[i] = min(d[i], d[i - j - 1] + abs(h[i] - h[i - j - 1]));
        }
    }

    cout << d[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

int main()
{
  int a, b, c;
  double S, L, h;

  scanf("%d %d %d", &a, &b, &c);

  h = (double)b * sin((double)c * M_PI / 180);
  S = a * h / 2;
  L = a + b + sqrt((double)a * a + (double)b * b -
           2 * (double)a * b * cos((double)c * M_PI / 180));

  printf("%.8f\n", S);
  printf("%.8f\n", L);
  printf("%.8f\n", h);

  return 0;
}



Measured memory_bytes: 2088
#include<iostream>
#include<string>
#include<cstdio>

using namespace std;

int main(){

	string str;
	cin >> str;
	bool alp[26];
	for(int i=0;i<26;i++){
		alp[i]=false;
	}
	for(int i=0;i<str.size();i++){
		alp[str[i]-'a']=true;
	}
	for(int i=0;i<26;i++){
		if(!alp[i]){
			cout << (char)('a'+i) << endl;
			return 0;
		}
	}
cout << "None" << endl;
return 0;

}

Measured memory_bytes: 512
///"Bismillahir Rahmanir Raheem"///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;
const int LOGN = 20;
int main(){
    int x,n;
    cin>>x>>n;
    if(x<n) cout<<"0"<<endl;
    else cout<<10<<endl;
return 0;
}


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


int main() {
    ll n,m,l;
    cin >> n >> m >> l;
    vector< vector<ll>> a(n,vector<ll>(m,0));
    rep(i,n)rep(j,m)cin >> a.at(i).at(j);
    vector< vector<ll>> b(m,vector<ll>(l,0));
    rep(i,m)rep(j,l)cin >> b.at(i).at(j);
    vector< vector<ll>> c(n,vector<ll>(l,0));

    rep(i,n)rep(j,l){
        ll sum = 0;
        rep(k,m){
            sum += a[i][k] * b[k][j];
        }
        c[i][j] = sum;
    }
    rep(i,n){
        rep(j,l){
            cout << c.at(i).at(j);
            if(j != l-1)cout << " ";
        }
        cout << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


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

int main() {
	int len1, len2, cross, ctr1 = 0, ctr2 = 0;
	char a, b;
	vector<int> LEN1, LEN2, CROSS;

	while (cin >> len1 >> a >> len2 >> b >> cross) {
		LEN1.push_back(len1);
		LEN2.push_back(len2);
		CROSS.push_back(cross);
	}
	
	for (int i = 0; i < LEN1.size(); i++) {
		if (pow(CROSS[i], 2) == pow(LEN1[i], 2) + pow(LEN2[i], 2))ctr1++;
		else if (LEN1[i]==LEN2[i])ctr2++;
	}

	cout << ctr1 << endl << ctr2 << endl;
	return 0;
}

Measured memory_bytes: 3104
#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;

int main()
{
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == ',')
      s[i] = ' ';
  cout << s << endl;
  return 0;
}

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

int n;
int k;
int id[100010];
int num[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> n;
  bool can = false;
  for (k = 1; k*(k-1) <= 2 * n; k++) {
    if (k*(k-1) == 2 * n) {
      can = true;
      break;
    }
  }
  if (n == 2 || !can) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if (n == 1) {
    cout << 2 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  }
  cout << k << endl;
  int sz = 2 * n / k;
  cout << sz;
  for (int i = 1; i <= n; i++) {
    id[i] = -i;
  }
  for (int j = 0; j < sz; j++) {
    cout << " " << j+1;
    id[j+1] = 1;
    num[j+1] = 1;
  }
  cout << endl;
  int st = 1;
  for (int i = 0; i < k-1; i++) {
    cout << sz;
    int tmp = 0, p = st;
    vector<int> v;
    // cout << i << " " << p << endl;
    for (int j = 0; j < sz; j++) {
      while (p <= n && (id[p] == tmp || num[p] == 2)) p++;
    //   cout << " " << j << " " << tmp << " " << p << " " << id[p] << endl;
      cout << " " << p;
      tmp = id[p];
      num[p]++;
      v.emplace_back(p);
    }
    cout << endl;
    if (num[st] == 2) st++;
    for (int j = 0; j < v.size(); j++) {
      id[v[j]] = i+2;
    }
  }

  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9+7;
const ll mod= 1e9 + 7;

vector<ll> k(100001);
vector<ll> f(100001);

ll mod_pow(ll x, ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}

void kai(void) {
	ll cur = 1;
	k[0] =f[0]= 1;
	FOR(i, 1, 100000) {
		cur = (cur * i)%mod;
		k[i] = cur;
		f[i] = mod_pow(cur, mod - 2);
	}
}


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

	ll N, K; cin >> N >> K;
	K--;
	ll ans = 0;

	vector<ll> A(N);
	FOR(i, 0, N)cin >> A[i];
	sort(A.begin(), A.end());
	
	vector<ll> C(N + 1, 0);
	kai();
	FOR(i, K, N) {
		C[i] = ((k[i] * f[i - K])%mod * f[K])%mod;
	}
	


	if (K == 0)cout << 0 << endl;
	else {
		FOR(i,0,N)if(i>=K)ans = (ans + (A[i] * C[i])%mod)%mod;
		FOR(i, 0, N)if (N - i - 1 >= K)ans = (ans - (A[i] * C[N - i - 1])%mod) % mod;
		cout << (ans+2*mod)%mod << endl;
	}
	

	return 0;
}

Measured memory_bytes: 3456
n=int(input())
A=list(map(int,input().split()))
import numpy as np
nwa=n*(n+1)//2
if sum(A)%nwa!=0 : print("NO");exit()
k= sum(A)//nwa 


D=[0]*n
D[0]=A[0]-A[-1]
for i in range(n-1):
    D[i+1]= A[i+1]-A[i]

# print(D)
D=[i-k for i in D]
for i in D:
    if i>0:print("NO");exit()
    if i==0:continue
    if abs(i)%n!=0: print("NO");exit()
else:
    print("YES")


Measured memory_bytes: 36160
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	ll ans = b / c;
	if(a == 0){
		ans++;
	}else{
		ans -= (a - 1) / c;
	}

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

Measured memory_bytes: 256
R,G,B,N=map(int,input().split())

ans=0
i=0
while i<=3000:
    j=0
    while j<=3000 and N-(i*R+j*G)>=0:
        if (N-(i*R+j*G))%B==0:
            ans+=1
        j+=1
    i+=1

print(ans)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

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

void assign(vvi &g, vi &group, int n = 0) {
  rep(i, g.size()) {
    if (group[i] != -1) continue;
    group[i] = i;
    
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int f = q.front(); q.pop();
      for (auto v: g[f]) {
        if (group[v] == -1) {
          group[v] = i;
          q.push(v);
        }
      }
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  
  vvi g(n);
  rep(i, m) {
    int s, t;
    cin >> s >> t;
    
    g[s].push_back(t);
    g[t].push_back(s);
  }

  vi group(n, -1);
  assign(g, group);
  
  int q;
  cin >> q;

  rep(i, q) {
    int s, t;
    cin >> s >> t;

    cout << (group[s] == group[t] ? "yes" : "no") << endl;
  }
}



Measured memory_bytes: 8572
from collections import deque

H, W = map(int, input().split())

m = [['X'] * (W+2)]
for i in range(H):
  row = [c for c in input()]
  row.insert(0, 'X')
  row.append('X')
  m.append(row)
m.append(['X'] * (W+2))

q = deque([deque([(i, j) for j in range(1, 1+W) for i in range(1, 1+H) if m[i][j] == '#'])])

cnt = 0
while(True):
  if not q:
    break
  tt = q.popleft()
  nn = deque([])
  for t in tt:
    # left, right, up, down
    for n in ((t[0]-1, t[1]), (t[0]+1, t[1]), (t[0], t[1]-1), (t[0], t[1]+1)):
      if m[n[0]][n[1]] == '.':
        nn.append(n)
        m[n[0]][n[1]] = '#'
  if nn:
    q.append(nn)
  cnt += 1

print(cnt-1)

Measured memory_bytes: 135768
s=input()
s=set(s)
l = list(s)
l.sort()
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']
for i in range(len(l)):
    if(l[i]!=al[i]):
        print(al[i])
        break
lenl=len(l)
lenl1=lenl-1
if((lenl<=25)&(l[lenl1]==al[lenl1])):
    print(al[len(l)])
if (l==al):
    print('None')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll int,ll int>
#define pb push_back
#define sbit __builtin_popcount
#define vec vector <int>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define bg begin()
#define en end()
#define endl "\n"
#define ff first
#define ss second
#define all(x) x.bg,x.en
#define sz(a) (int)a.size()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sp(x) setprecision(x)
#define fill(a,b) memset(a,b,sizeof(a))
#define fr(i,n) for(int i=0;i<n;i++)
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rr(i,a,b) for(int i=a;i>=b;i--)
#define ft(it,x) for(auto it : x)
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define mapi map<int,int>
#define mapl map<ll int,ll int>
#define val_at(x) find_by_order(x)
#define idx_of(x) order_of_key(x)
#define scni(x) scanf("%d",&x)
#define prt(x) printf("%d\n",x)
#define test(t) int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> myset;
const int mod=1e9+7;
const int mex=1e6+1;
inline ll power(ll a,ll b)
{
    ll ans=1,temp=a;
    while(b!=0)
    {
        if(b&1)
        ans=ans*temp;
        ans=ans%mod;
        temp=temp*temp;
        temp=temp%mod;
        b/=2;
    }
    return ans;
}
int pr[mex];
vec prime;
inline void seive()
{
    rp(i,2,mex) pr[i]=1;
    for(int i=2;i*i<mex;i++)
    {
        if(pr[i])
        for(int j=i*i;j<mex;j+=i)
        pr[j]=0;
    }
    vec prime;
    rp(i,2,mex)
    {
        if(pr[i]) prime.pb(i);
    }
}
ll int xx,xy,d1;
void exeu(ll int a1,ll int b1)
{
    if(b1==0)
    {
        xx=1;
        xy=0;
        d1=a1;
    }
    else
    {
        exeu(b1,a1%b1);
        ll int temp=xx;
        xx=xy;
        xy=temp-(a1/b1)*xy;
    }
}
ll int modinv(ll int A,ll int M)
{
    exeu(A,M);
    return (xx%M+M)%M;
}
int main()
{
    fast
    char c;
    cin>>c;
    c++;
    cout<<c<<endl;
    
    return 0;
}

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

int main(){


	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);

   	string s;
   	cin>>s;
   	int n=s.length();

   	int i=0;
   	string ministring;
   	string prevstring;
   	int ans=0;
   	while(i<n){
   		ministring+=s[i];
   		if(ministring!=prevstring){
   			prevstring=ministring;
	   		ministring="";
   			ans++;
   		}
   		i++;
   	}

   	cout<<ans<<endl;
}


Measured memory_bytes: 720
def GSB(n):
	ans = -1
	for i in range(30):
		if n&(1<<i):
			ans = i
	return ans
def ans(a,b,c,d,M):
	other = [x for x in range(1<<M) if x not in [a,b,c,d]]
	print(*([a,b]+other+[c,d]+other[::-1]+[b,a,d,c]))

def solve(M,K):
	if K==0:
		arr = list(range(1<<M))
		print(*(arr+arr[::-1]))
	elif K==1:
		if M < 2:
			print(-1)
		else:
			ans(0,1,2,3,M)
	else:
		if M > GSB(K):
			a = 1<<GSB(K)
			b = K^a
			c = a+1
			d = K^c
			ans(a,b,c,d,M)
		else:
			print(-1)


solve(*map(int,input().split()))

Measured memory_bytes: 100496
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<vector>

#define NIL -1
int color[100000];
std::vector<int>V[100005];

void dfs(int i,int id){
    std::stack<int>S;
    S.push(i);
    color[i]=id;
    int j;
    while(!S.empty()){
        int top=S.top();
        S.pop();
        for(j=0;j<V[top].size();j++){
            if(color[V[top][j]]==NIL){
                color[V[top][j]]=id;
                S.push(V[top][j]);
            }
        }
    }
}
int main(){
    int n,m,i;
    scanf("%d %d",&n,&m);
    
    for(i=1;i<=m;i++){
        int s,t;
        scanf("%d %d",&s,&t);
        V[s].push_back(t);
        V[t].push_back(s);
    }
    for(i=0;i<=n-1;i++)color[i]=NIL;
    int id=1;
    for(i=0;i<=n-1;i++){
        if(color[i]==NIL){
            id++;
            dfs(i,id);
        }
    }
    
    int q;
    scanf("%d",&q);
    for(i=1;i<=q;i++){
        int s,t;
        scanf("%d %d",&s,&t);
        if(color[s]==color[t])printf("yes");
        else printf("no");
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 8584
#include <stdio.h>

int main(void)
{
    int A, B, C, D;
    scanf("%d %d %d %d", &A, &B, &C, &D);
    while (1)
    {
        C -= B;
        if (C <= 0)
        {
            printf("Yes");
            break;
        }
        A -= D;
        if (A <= 0)
        {
            printf("No");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1724
x1, y1, x2, y2 = map(int, input().split())
x3 = x2-(y2-y1)
y3 = y2+(x2-x1)
x4 = x1-(y2-y1)
y4 = y1+(x2-x1)
print (x3,y3,x4,y4)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
   int n=kbd.nextInt();
   int x=0;
   String a="";
   int[] A= new int[4];
   for(int i=0;i<n;i++){
     a=kbd.next();
     if(a.equals("AC")){
       x=0;
     }
     if(a.equals("WA")){
       x=1;
     }
     if(a.equals("TLE")){
       x=2;
     }
     if(a.equals("RE")){
       x=3;
     }
     A[x]++;
   }
   System.out.println("AC x "+A[0]);
   System.out.println("WA x "+A[1]);
   System.out.println("TLE x "+A[2]);
   System.out.println("RE x "+A[3]);
}
}

Measured memory_bytes: 57876
n,k = map(int,input().split())
a = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[1] = abs(a[1] - a[0])
for i in range(2, n):
    dp[i]=dp[i-1]+abs(a[i]-a[i-1])
    for j in range(2,k+1):
        if j>i:
            break
        else:
            dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]))
print(dp[-1])

Measured memory_bytes: 56800