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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(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 VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
// inline void CIN() {}
// template <class Head, class... Tail>
// inline void CIN(Head &&head, Tail &&... tail) {
//     cin >> head;
//     CIN(move(tail)...);
// }
// CIN(__VA_ARGS__)
// CIN(__VA_ARGS__)
// CIN(__VA_ARGS__)
// #define Yes(a) cout << (a ? "Yes" : "No") << "\n"
// #define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
// typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int q;
V A;

int main() {
    cin >> q;
    REP(i, q) {
        switch(IN()) {
        case 0:
            A.push_back(IN());
            break;
        case 1:
            cout << A[IN()]<<"\n";
            break;
        case 2:
            A.pop_back();
            break;
        default:
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3852
import math._
import collection.mutable.{Map => MTMap}

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val c = Vector.fill(n)((sc.nextLong, sc.nextLong))

  val mod = 1000000007

  def plus(a: Long, b: Long): Long = (a + b) % mod
  def minus(a: Long, b: Long): Long = (a - b + mod) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  def pow(a: Long, n: Long, res: Long = 1): Long = {
    if (n == 0) {
      res
    } else if ((n&1) == 0) {
      pow(times(a,a), n >> 1, res)
    } else {
      pow(times(a,a), n >> 1, times(a,res))
    }
  }

  def gcd(a: Long, b: Long): Long = {
    if (b == 0) a else gcd(b, a % b)
  }

  val m = MTMap[(Long,Long), Long]()
  var z = 0

  for ((a,b) <- c) {
    if (a == 0 && b == 0) {
      z += 1
    } else {
      val d = gcd(a.abs, b.abs)
      if (b == 0) {
        m((1, 0)) = m.getOrElse((1, 0), 0L) + 1
      } else if (b > 0) {
        m((a / d, b / d)) = m.getOrElse((a / d, b / d), 0L) + 1
      } else {
        m((-a / d, -b / d)) = m.getOrElse((-a / d, -b / d), 0L) + 1
      }
    }
  }

  val bads = m.toList.collect{
    case ((a, b), l) if a > 0 && m.isDefinedAt((-b, a)) => (l, m((-b, a)))
  }

  val ans = minus(plus(times(
    pow(2, n - z - bads.map{case (x,y) => x+y}.sum),
    bads.map{case (x,y) => minus(plus(pow(2,x), pow(2,y)), 1)}.foldLeft(1L)(times(_,_))
  ), z), 1)

  println(ans)
}

Measured memory_bytes: 99584
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
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 = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(){
    fastcin();

    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " <<b << " " << c << endl;
}

Measured memory_bytes: 256
#include "stdio.h"

int main(void){

	int n;
	scanf("%d",&n);

	char S[n + 1];
	char T[n + 1];

	scanf("%s %s",S,T);

	char new[n * 2 + 1];
	int j = 0;

	for (int i = 0; i < n; ++i){
		new[j++] = S[i];
		new[j++] = T[i];
	}
	new[j] = '\0';

	printf("%s\n",new);

	return 0;
}

Measured memory_bytes: 128
import Data.Bits (xor)

f0 x
  | x`mod`4==0 = x
  | x`mod`4==1 = 1
  | x`mod`4==2 = x `xor` 1
  | x`mod`4==3 = 0

main = do
  [a,b] <- map read . words <$> getLine :: IO [Int]
  print $ f0 (a-1) `xor` f0 b


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int cnt=0,cnt2=0,i;
    string x;
    cin>>x;
    for(i=0;i<x.size();i++)
    {
        if(x[i]!='T')
            break;
    }
    int ck=0,ans=0;
    for(;i<x.size();i++)
    {
        if(x[i]=='S'&&ck==1)
        {
            int l=min(cnt,cnt2);
         ans+=l;
         cnt=cnt-l;
         cnt2=0;
         ck=0;
        }
        if(x[i]=='S'&&ck==0)
            {
                cnt++;
            }
        else if(x[i]=='T')
        {
            cnt2++;
            ck=1;
        }
        //cout<<cnt<<" "<<cnt2<<" "<<ans<<endl;
    }
    if(ck)
    {
        ans+=min(cnt,cnt2);
    }
    printf("%d\n",x.size()-(ans*2));
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while( 1 ){
		c -= b;
		if( c <= 0 ){
			puts("Yes");break;
		}
		a -= d;
		if( a <= 0 ){
			puts("No");break;
		}
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    long long int cnt=0;
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            for(int k=1; k<=n; k++) {
                cnt=cnt+gcd(i, gcd(j, k));
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 3636
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
dist=[]
for i in range(m-1):
  dist.append(a[i+1]-a[i])
ans=sum(dist)
dist=sorted(dist,reverse=True)
ans-=sum(dist[0:n-1])
print(ans)

Measured memory_bytes: 13968
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


int n;
int a[100005];

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

	int ans = 1;

	if (n < 3) {
		cout << ans << endl;
		return 0;
	}

	int flag = 0;
	for (int i = 1;i < n;i++) {
		if (a[i - 1] == a[i]) {
			continue;
		}
		else if (a[i - 1] < a[i]) {
			if (flag == 0) {
				flag = 1;
			}
			else if (flag == 1) {
				flag = 1;
			}
			else {
				flag = 0;
				ans++;
			}
		}
		else {
			if (flag == 0) {
				flag = -1;
			}
			if (flag == 1) {
				flag = 0;
				ans++;
			}
			else {
				flag = -1;
			}
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 640
n=int(input())
s_list=[list(map(int,input().split())) for i in range(n)]
cnt = 0
ans = "No"
for i in s_list:
  if i[0] == i[1]:
    cnt = cnt + 1
  else:
    cnt = 0
  if cnt == 3:
    ans = "Yes"
print(ans)

Measured memory_bytes: 9176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch)
{
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
}

long long getKey(char str[])
{
	long long sum = 0, p = 1, i;
	for (i=0; i<strlen(str); i++)
	{
		sum += p * (getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key)
{
	return key % M;
}

int h2(int key)
{
	return 1 + (key % (M - 1));
}

int find(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for (i=0; ; i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0) return 0;
	}
	return 0;
}

int insert(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for (i=0; ; i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0)
		{
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}


int main()
{
	int i, n, h;
	char str[L], com[9];
	for (i=0; i<M; i++) H[i][0] = '\0';
	scanf("%d", &n);
	for (i=0; i<n; i++)
	{
		scanf("%s %s", com, str);
		
		if (com[0] == 'i')
		{
			insert(str);
		} else {
			if (find(str))
			{
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 15500
n, k = map(int, input().split())
arr = list(map(int, input().split()))

inf = float('inf')
min_cost = inf
for amount in range(n, 100000):
    for i, e in enumerate(arr):
        if str(e) in str(amount):
            break
        if i == len(arr)-1:
            min_cost = min(min_cost, amount)

print(min_cost)

Measured memory_bytes: 9192
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::vector;
using std::string;

int main(){
    long sum=0;
    string n;
    cin >> n;
    for(int i=0;i<n.length();i++){
        sum = (sum + int(n[i]) - 48) % 9;
    }
    if(sum == 0) cout << "Yes";
    else cout << "No";
}

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  
  int count = 0;
  if(A == 7)count ++;
  if(B == 7)count ++;
  if(C == 7)count ++;
  
  if(count == 1)cout << "YES" << endl;
  else cout << "NO" << 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 all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  int n,m,l;
  cin >> n >> m >>l;
  if(n==m)
    cout << l << endl;
  else if(n==l)
    cout << m << endl;
  else
    cout << n << endl;
}

Measured memory_bytes: 256
S = input()
l = len(S)
ans = True
if l % 2 != 0:
  ans = False
else:
  for i in range(l):
    if i % 2 == 0 and S[i] == "h": 
      ans = True
    elif i % 2 == 1 and S[i] == "i":
      ans = True
    else:
      ans = False
      break
if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#define FI first
#define SE second
#define PB push_back
#define PA pair<int,int>
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const int vmax=100001;

vector<PA> g[vmax];
long int dist[vmax]={};
bool gb[vmax]={};
stack<int> s;
void dfs(int k);

int main(){
    int n; cin>>n;
    FOR(i,0,n-1){
        int a,b,c;
        cin>>a>>b>>c;
        g[a].PB(PA(b,c));
        g[b].PB(PA(a,c));
    }
    int q,k; cin>>q>>k;
    dfs(k);
    FOR(i,0,q){
        int x,y; cin>>x>>y;
        cout<<dist[x]+dist[y]<<endl;
    }
}

void dfs(int k){
    s.push(k);
    gb[k]=true;
    while(!s.empty()){
        int t=s.top(); s.pop();
        FOR(i,0,g[t].size()){
            if(!gb[g[t][i].FI]){
                s.push(g[t][i].FI);
                dist[g[t][i].FI]=dist[t]+g[t][i].SE;
            }
        }
        gb[t]=true;
    }
}

Measured memory_bytes: 8820
n,x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort

sum = a.inject(:+)

if sum==x
  p n
elsif sum<x
  p n-1
else
  ans = 0
  a.each{|t|
    ans += 1 if x>=t
    x-=t
  }
  p ans
end



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t ;
  cin >> s >> t ;
  cout << t << s <<endl ;
  
  
  
  return 0 ;
}




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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    ll a, b, n;

    cin>> a>> b>> n;

    cout<< ((n>=b)? (a* (b-1))/ b: (a* n)/b);
    nl;

    return 0;
}




Measured memory_bytes: 3548
#include <iostream>

using ll = long long;

int main()
{
    ll a, b, c, k;
    std::cin >> a >> b >> c >> k;
    if (std::abs(a - b) > 10e18) {
        std::cout << "Unfair" << std::endl;
        return 0;
    }
    if (k % 2 == 0) {
        std::cout << a - b << std::endl;
    } else {
        std::cout << b - a << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
Anki:未済
作成日:
*/

#include <stdio.h>

int main()
{
    int n, k, x, y, cost;
    scanf( "%d\n%d\n%d\n%d", &n, &k, &x, &y );

    if( n < k+1 )
    {
        cost = x * n;

    }
    else
    {
        cost = x * k + y * ( n-k );
    }
    printf( "%d\n", cost );
    
    return 0;
}

Measured memory_bytes: 128
import sys
import math
K, A, B = list(map(int, input().split()))
 
if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = p//d
if ((p % d) != 0):
    q += 1
print(int(2*q + 1))

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,c; cin>>a>>b>>c;
	int ans=0;
	for(int i=a;i<=b;++i){
		if(c%i==0)++ans;
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3212
N, W = map(int, input().split())

maxv = 10 ** 3 * N + 1
t = [-1] * maxv
t[0] = W
cmaxv = 0
for _ in range(N):
    nw, nv = map(int, input().split())
    for i in range(cmaxv, -1, -1):
        ti = t[i]
        if ti == -1:
            continue
        if t[i + nv] < ti - nw:
            t[i + nv] = ti - nw
            if cmaxv < i + nv:
                cmaxv = i + nv
print(cmaxv)


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

const int N = 2e3 + 5;

int n, x, a[N], f[N][N];
LL ans = 1e18;

LL calc(int c) {
	LL r = 0;
	for(int i = 1; i <= n; ++i) {
		int mi;
		if(i - c > 0) {
			mi = f[i - c][i];
		} else {
			mi = min(f[1][i], f[n - (c + 1 - i) + 1][n]);
		}
		r += mi;
	}
	return r;
}
int main() {
	scanf("%d%d", &n, &x);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	for(int i = 1; i <= n; ++i) {
		f[i][i] = a[i];
		for(int j = i + 1; j <= n; ++j)
			f[i][j] = min(f[i][j - 1], a[j]);
	}
	for(int i = 0; i <= n; ++i)
		ans = min(ans, (LL) i * x + calc(i));
	printf("%lld\n", ans);
	return 0;
}	


Measured memory_bytes: 15360
#include <stdio.h>

using namespace std;

int main(){
	int a,b,c,count = 0;
	scanf("%d %d %d",&a,&b,&c);
	for(int i = a; i <= b; i++){
		if(c%i == 0) count++;
	}
	printf("%d\n",count);
}



Measured memory_bytes: 2736
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define SZ(a) int(a.size())
#define ALL(x) (x).begin(),(x).end()
#define trav(a,x) for (auto& a: x)
#define LOG(FMT...) fprintf(stderr, FMT)
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int INF = 0x3f3f3f3f;
constexpr int mod = 1e9+7;
constexpr int Erica = 998244353;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr ull base=2333, P_1=19260811, P_2=999998639;
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
template<class T>inline void umin(T &x, T y) {x = x > y ? y : x;}
template<class T>inline void umax(T &x, T y) {x = x < y ? y : x;}
template<class T>inline void dec(T &x, T y) {x -= y; if(x < 0) x += mod;}
template<class T>inline void add(T &x, T y) {x += y; if(x >= mod) x -= mod;}
int n , a[maxn];
int main()
{
    close;
    cin >> n;
    int ans = 0;
    vi prime(maxn, 1);
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i < maxn; i++){
        if(a[i] == 0) continue;
        if(a[i] == 1 && prime[i])ans++;
        for(int j = 2; j * i < maxn; j++){
            prime[j*i] = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 11168
from itertools import accumulate

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

cumA = list(accumulate(A))

l_index = 0
r_index = 2
cumA_max = cumA[-1]

diff = cumA_max

for i in range(1, len(A)-2):
  while abs(cumA[i] - cumA[l_index] - cumA[l_index]) > abs(cumA[i] - cumA[l_index + 1] - cumA[l_index + 1]):
    l_index += 1

  while abs(cumA_max - cumA[r_index] - (cumA[r_index] - cumA[i])) > abs(cumA_max - cumA[r_index + 1] - (cumA[r_index + 1] - cumA[i])):
    r_index += 1
        
  left = cumA[l_index]
  center = cumA[i] - cumA[l_index]
  right = cumA[r_index] - cumA[i]
  last = cumA_max - cumA[r_index]

  diff = min(diff, max(left, center, right, last) - min(left, center, right, last))

print(diff)

Measured memory_bytes: 24176
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=2e5+5;

int n;
int a[N], b[N];

int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int p=n/2, q=n/2 + 1;
	for(int i=1;i<=n;i++)
	{
		if(i%2)
			b[q++]=a[i];
		else
			b[p--]=a[i];
	}
	if(n%2)
		reverse(b+1, b+n+1);
	for(int i=1;i<=n;i++)
		cout<<b[i]<<" ";
	return 0;
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	REP(i, q) {
		int n;
		cin >> n;
		int cnt = 0;
		while (n>=10) {
			ll cmax = -1, res = 1;
			int a=n;
			while (a > 0) {
				res *= 10;
				a /= 10;
			}
			res /= 10;


			REP(j, log10(n)-1) {
				cmax = max(cmax, (n / res)*(n%res));
				res /= 10;
			}
			cnt++;

			if (cmax == n) {
				cnt = -1;
				break;
			}
			n = cmax;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */



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

    int n; cin >> n;
    vector<double> p(n);
    rep(i, n) cin >> p[i];

    vector<vector<double>> dp(n+5, vector<double>(n+5, 0));
    dp[0][0]=1;

    rep(i, n) rep(j, n+1){
        dp[i+1][j] = dp[i][j]*(1-p[i]) + (j==0? 0:dp[i][j-1]*p[i]);
    }

    double ans=0;
    repr(j, n/2+1, n+1) ans += dp[n][j];
    cout << setprecision(10) << ans << endl;

    return 0;
}


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

vector<int> z_algorithm(const string& s) {
    int sz = s.size();
    vector<int> prefix(sz, 0);
    int c = 0;
    for (int i=1; i<sz; ++i) {
        if (i+prefix[i-c] < c+prefix[c]) {
            prefix[i] = prefix[i-c];
        }
        else {
            int j = max(0, c+prefix[c]-i);
            while (i+j < sz and s[j] == s[i+j]) j++;
            prefix[i] = j;
            c = i;
        }
    }
    prefix[0] = sz;
    return prefix;
}

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

    int ans = 0;
    for (int i=0; i<S.size(); ++i) {
        string T = S.substr(i, S.size()-i);
        vector<int> prefix = z_algorithm(T);
        for (int j=1; j<T.size(); ++j) {
            ans = max(ans, min(prefix[j], j));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int a[60], n, sum;
int main(){
	cin >> n;
	for(int i=1; i<=n; i++)
		cin >> a[i];
	for(int i=1; i<n; i++)
		for(int j=i+1; j<=n; j++)
			sum += a[i]*a[j];
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

constexpr int C = 1000000007;

vector<vector<int>> dp;
vector<vector<char>> arr;

size_t count(unsigned i, unsigned j)
{
  if (i+1 == arr.size() && j+1 == arr[0].size())
  {
    return 1;
  }
  if (arr[i][j] == '.')
  {
    if (i+1 < arr.size() && j+1 < arr[0].size())
    { 
      if (dp[i][j] == -1)
        dp[i][j] = (count(i+1, j) + count(i, j+1)) % C;
    }
    else if (i + 1 < arr.size())
    { 
      if (dp[i][j] == -1)
        dp[i][j] = count(i+1, j);
    }
    else if (j+1 < arr[0].size())
    { 
      if (dp[i][j] == -1)
        dp[i][j] = count(i, j+1);
    }
    return dp[i][j];
  }
  return 0;
}

int main()
{ 
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  
  unsigned H, W;
  std::cin >> H >> W;
  arr = vector<vector<char>>(H, vector<char>(W));
  dp = vector<vector<int>>(H, vector<int>(W, -1));
  
  for (auto& h : arr)
  { 
    for (auto& w : h)
    { 
      std::cin >> w;
    }
  }
  
  std::cout << count(0, 0);
  
  return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll N,A,B;

vector<ll> h;

bool ch(ll x) {

	vector<ll> t(N + 1);

	repn(i, N) t[i] = max(0, h[i] - B * x);

	ll k = 0;
	repn(i, N) {
		if (t[i] > 0) { k += (t[i] - 1) / (A - B) + 1; }
	}

	if (k > x) { return 0; }
	else { return 1; }
}




int main() {

	cin >> N >> A >> B;
	h.resize(N + 1);
	repn(i, N) cin >> h[i];

	ll l = 0;
	ll r = 1e9;

	while (r - l > 1) {
		ll m = (r + l) / 2;
		if (ch(m)) { r = m; }
		else { l = m; }
		//cout << m << ch(m)<<endl;
	}
	
	cout << r << endl;


	system("PAUSE");
}


Measured memory_bytes: 2024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


int factorial(int n){
  if(n == 0) return 1;
  return n*factorial(n-1);
}

int divisor(int a){
  int cnt = 0;
  for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
  return cnt;
}

int comb(int n, int k){
  return factorial(n) / (factorial(n-k)*factorial(k));
}

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






int main(){
  priority_queue<int> q;
  rep(i,3){
    int a;
    cin >> a;
    q.push(a);
  }
  int k;
  cin >> k;
  rep(i,k){
    int a = q.top()*2;
    q.pop();
    q.push(a);
  }
  int ans = 0;
  rep(i,3){
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  
  return 0;
}









Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define INF 2147483647
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
int main(){
	
	string s[3];
	cin>>s[0]>>s[1]>>s[2];
	int i[3]={0};
	int l=0,m=0;
	char ans;
	bool flag=true;
	while(flag){
		i[l]++;
		if(s[l][m]=='a')l=0;
		else if(s[l][m]=='b')l=1;
		else if(s[l][m]=='c')l=2;
		m=i[l];
		if(m==s[l].size()){
			flag=false;
			cout<<(char)('A'+l)<<endl;
		}
		
		
	}
	
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)


int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> memoa(n+1);
	vector<ll> memob(m+1);
	
	ll a, b;
	FOR(i, 1, n) {
		cin >> a;
		memoa[i] = memoa[i - 1] + a;
	}

	
	FOR(i, 1, m) {
		cin >> b;
		memob[i] = memob[i - 1] + b;
	}

	ll res = 0;
	FOR(i, 0, n) {
		if (memoa[i] > k)break;
		else {
			ll tmp = i;
			ll tmp2 = upper_bound(ALL(memob), k - memoa[i])-memob.begin()-1;
			//dump(tmp);
			//dump(tmp2);
			res = max(res, tmp + tmp2);
		}
	}
	pv(res)
	return 0;
}

Measured memory_bytes: 6412
#include <stdio.h>

int main(){
  int i,N,ans,coin[6] = {500,100,50,10,5,1};
  while(1){
    ans = 0;
    scanf("%d",&N);
    if(N == 0){ break; }
    N = 1000-N;
    for(i = 0 ; i < 6 ; i++){
      if(N >= coin[i]){
        ans += N/coin[i];
        N %= coin[i];
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll a, b, c;
  scanf("%lld%lld%lld", &a, &b, &c);
  if(c > a + b && 4 * a * b < (a + b - c) * (a + b - c)) printf("Yes");
  else printf("No");
  return 0;
}

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

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [map(int, input().split()) for i in range(Q)]

D = {}
for i in range(1, 10**5+1):
    D[i] = 0

for a in A:
    D[a] += 1

ret = sum(A)

for b, c in BC:
    sa = c - b
    #minus = b * D[b]
    #cnt = D[b]
    plus = sa * D[b]
    D[c] += D[b]
    D[b] = 0
    ret += plus
    print(ret)

Measured memory_bytes: 118984
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double l; cin >> l;
    cout << fixed << setprecision(12) << l / 3 * l / 3 * l / 3 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)


const int N = 200005, mo = 1000000007;
long long fac[N], inv[N];

//繰り返し2乗法
int ksm(int x, int y) {
	int i = 1;
	for (; y; y >>= 1, x = 1ll * x*x%mo)
		if (y & 1) i = 1ll * i*x%mo;
	return i;
}

//組合せテーブルの構築
void Pre(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i%mo;
	inv[n] = ksm(fac[n], mo - 2);
	for (int i = n; i >= 1; i--) inv[i - 1] = inv[i] * i%mo;
}

//組み合わせの計算
long long C(int n, int m) {
	return fac[n] * inv[m] % mo*inv[n - m] % mo;
}


int main() {

	int h, w, a, b, ans = 0;
	cin >> h >> w >> a >> b;

	Pre(h + w);


	for (int i = 1; i <= h - a; i++) {
		ans = (ans + C(i + b - 2, i - 1)*C(h + w - i - b - 1, h - i)) % mo;
	}

	
	printf("%d\n", ans);
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<int> vec;
#define LL long long
int main()
{
  LL n,k,h[200005]={};
  LL sum=0;
  cin>>n>>k;

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

  sort(h,h+n,greater<LL>());

  for(int i=0; i<k; i++){
    h[i]=0;
  }

  sort(h,h+n,greater<LL>());

  for(int i=0; i<n-k; i++){
    sum+=h[i];
  }

  cout<<sum<<'\n';
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
int a,b,i,x,y;
while(cin>>a>>b){
int max=0,min;
i=1;
x=a;
y=b;
while(i!=0){
i=x%y;
x=y;
y=i;
}
max=x;
min=(a/max)*b;
cout<<max<<" "<<min<<endl;
}
return 0;
}

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

const int mod = 1000000007;
struct mint {
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

void Main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    mint smax = 0;
    mint smin = 0;
    combination C(n);

    for (int i = k-1; i < n; i++)
    {
        smax += C(i, k-1) * a[i];
    }
    for (int i = 0; i < n-k+1; i++)
    {
        smin += C(n-1-i, k-1) * a[i];
    }
    
    cout << smax-smin << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 5280
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var x = long.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        Console.WriteLine(getAns (a,x));
    }
    public static long getAns (long[] a , long x)
    {
        var aL = a.Length;
        var ret = 0L;
        for (int i = 0; i < aL-1; i++)
        {
            var w = a[i] + a[i + 1];
            if (w > x && w - x <= a[i + 1]) { ret += w - x; a[i + 1] -= w - x; }
            else if (w > x && w - x > a[i + 1]) { ret += w - x; a[i + 1]  = 0; }
        }
        return ret;
    }
}

Measured memory_bytes: 25436
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
 
using namespace std;
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
 

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=b))
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;   
}
 
 

Measured memory_bytes: 256
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
def output_S(S, K):
    if len(S)<=K: return S
    else: return S[0:K] + "..."

def main():
    K = int(input())
    S = input()
    print(output_S(S, K))

if __name__ == "__main__":
    main()


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define all(a) (a).begin(), (a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

const ll MOD = 998244353;

template <long long MOD>
long long mod_pow(long long a, long long b)
{
  if (b == 0) return 1;
  long long ret = mod_pow<MOD>(a, b/2);
  ret = ret * ret % MOD;
  if (b % 2 == 1) ret = a * ret % MOD;
  return ret;
}


int main()
{
  fastio();

  int n; cin >> n;
  ll maxa = 0;
  map<ll,ll> cnt;
  forn(i,n) {
    ll a; cin >> a;
    if (i == 0) {
      if (a != 0) {
        cout << 0 << endl;
        return 0;
      }
    }
    cnt[a]++;
    chmax(maxa,a);
  }

  ll ans;
  if (cnt[0] == 1) {
    ans = 1;
  } else {
    ans = 0;
  }

  ll prev = 1;
  for (int i = 1; i <= maxa; i++) {
    if (cnt[i])
      ans = (ans * mod_pow<MOD>(prev, cnt[i])) % MOD;
    else
      ans = 0;

    prev = cnt[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#include <regex>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N,M,A[100000];
  cin>>N>>M;
  priority_queue<int> q;
  for (int i(0);i<N;i++) {
    cin>>A[i];
    q.push(A[i]);
  }
  for (int i(0);i<M;i++){
    int a=q.top();
    q.pop();
    q.push(a/2);
  }
  ll sum(0);
  for (int i(0);i<N;i++){
    sum+=q.top();
    q.pop();
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1148
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#define M_PI 3.1415926535897932384626433832795

int main() {
	int n;
	cin >> n;
	vector<P>a(n);
	rep(i, n) {
		cin >> a[i].first;
		a[i].second = i + 1;
	}
	sort(a.begin(), a.end());
	rep(i, n) {
		cout << a[i].second << " ";
	}
	return 0;
}

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

using namespace std;

int main() {
	int size;
	string str;
	
	cin >> str;
	size = str.size();
	for (int i = 0; i < size; ++i) {
		str[i] = (str[i] - 'A' + 23) % 26 + 'A';
	}
	cout << str << endl;

	return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <fstream>

using namespace std;

[[gnu::hot]]inline unsigned countTwo(int n)
{
    unsigned count = 0;
    for (; n % 2 == 0; n /= 2, ++count);
    return count > 2 ? 2 : count;
}

int main()
{
    int n, count = 0;
    cin >> n;
    for (int x, i = 0; i < n; ++i) {
        cin >> x;
        count += countTwo(x);
    }

    if (n%2 && count >= n - 1)
        cout << "Yes";
    else if (n%2 == 0 && count >= n)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
A,B = map(int,input().split())
 
def kaibun(m, n):
    key = 0
    for i in range(m,n+1):
        s = i//10000  
        t = i%10
        u = i//1000 % 10
        v = i//10 % 10
        if (s==t)&(u==v):
            key += 1
    return key
 
print(kaibun(A,B))

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

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;
static const bool DEBUG = false;

signed main() {
	for (int H, W, N; cin >> H >> W >> N;) {
		vector<pii> a;//塗りつぶされた
		vector<pii> b;//中心
		rep(i, 0, N) {
			int y, x; cin >> y >> x; --y, --x;
			a.emplace_back(y, x);
			rep(dy, -1, 2) rep(dx, -1, 2) {
				int yy = y + dy, xx = x + dx;
				if (1 <= yy && yy <= H - 2 && 1 <= xx && xx <= W - 2)
					b.emplace_back(yy, xx);
			}
		}
		sort(all(a));
		sort(all(b));
		b.erase(unique(all(b)), b.end());
		int ans[10] = {};
		for (auto p : b) {
			int j = 0;
			rep(dy, -1, 2) rep(dx, -1, 2) {
				pii q{ p.first + dy, p.second + dx };
				j += binary_search(all(a), q);
			}
			++ans[j];
		}
		ans[0] += (H - 2) * (W - 2) - b.size();
		rep(i, 0, 10) cout << ans[i] << endl;;
	}
	return 0;
}

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


int main(){

    string S, T;
    cin >> S >> T;
    int cnt=0;
    for(int i=0;i<3;i++){
        if(S[i]==T[i]){
            cnt+=1;
        }
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
N, W = map( int, input().split())
dp = [10**9+1]*(10**5+2)
dp[0] = 0
for _ in range(N):
    w, v = map( int, input().split())
    #iを実現しうる最小のwを更新すればよいのでは
    for i in range(10**5,0,-1):
        if i <= v:
            dp[i] = min( dp[i], w)
        else:
            if dp[i-v] + w <= W:
                dp[i] = min( dp[i-v] + w, dp[i])
print( dp.index(10**9+1)-1)


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 n, m;
    cin >> n >> m;
    vector<i32> v(n), u(n);
    v[0] = 1;
    for (i32 i = 0; i < m; i++) {
        i32 s, c;
        cin >> s >> c, s--;
        if (u[s] && v[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        u[s] = 1;
        v[s] = c;
    }

    if (n != 1 && v[0] == 0) {
        cout << -1 << endl;
        return 0;
    }

    if (n == 1 && u[0] == 0) {
        v[0] = 0;
    }
    for (auto& e : v) cout << e;
    cout << endl;
}


Measured memory_bytes: 256
s=input()
K=int(input())

dic={}
for i in range(len(s)):
    dic[s[i:]]=1
arr=sorted(dic)
dic={}

for x in arr:
    for i in range(0,len(x)):
        tmp = x[:i+1]
        if dic.get(tmp,0)==0:
            K-=1
            dic[tmp]=1
        else:
            continue
        if K==0:
            print(x[:i+1])
            break
    if K<0:
        break

Measured memory_bytes: 18224