akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define N 500000

void Merge(int A[],int left,int mid,int right);
void MergeSort(int A[],int left,int right);

int A[N],count=0;

int main(){ 
  int n,q,i;
  int mid,left,right;
  
  scanf("%d", &n);
  for( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  
  MergeSort(A,0,n);
  
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]); 
  }
  printf("%d",A[n-1]);
  printf("\n%d\n",count);
  
  return 0;
}

void MergeSort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(A,left,mid);
    MergeSort(A,mid,right);
    Merge(A,left,mid,right);
  }
}

void Merge(int A[],int left,int mid,int right){
  int n1=mid-left,n2=right-mid,i,j,k;
  int L[n1],R[n2];
  for(i=0;i<=n1-1;i++){
    L[i] = A[left + i];
  }
  for(i=0;i<=n2-1;i++){
    R[i] = A[mid + i];
  }
  L[n1] = 1000000000;
  R[n2] = 1000000000;
  i = 0;
  j = 0;
  for(k=left;k<=right-1;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      count++;
      i = i + 1;
    }
    else{
      A[k] = R[j];
      count++;
      j = j + 1;
    }
  }
}

Measured memory_bytes: 4500
#include <stdio.h>

int main()
{
    int a;
    scanf("%d", &a);

    if (81 < 1)
    {
        printf("No\n");
        return 0;
    }
    else
    {
        for (int i = 1; i < 10; i++)
        {
            for (int j = 1; j < 10; j++)
            {
                if (a == i * j)
                {
                    if ((0 < i < 10) && (0 < j < 10))
                    {
                        printf("Yes\n");
                        return 0;
                    }
                }
            }
        }
    }
    printf("No\n");
    return 0;
}

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

#define mod 1'000'000'007
typedef long long ll;

template <typename T>
void deb(initializer_list<T> l)
{
    for (auto &e : l)
        cout << e << ' ';
    cout << '\n';
}

string t = "ACGT";

bool has(char c)
{
    for (auto &e : t)
        if (e == c)
            return 1;
    return 0;
}

void solve()
{
    string s;
    cin >> s;

    int mx = 0;
    int st = 0, e = 0;
    for (int i = 0; i < s.length(); )
    {
        if (!has(s[i]))
        {
            ++i;
            continue;
        }
        st = i;
        e = i;
        while (e < s.length())
        {
            if (!has(s[e]))
                break;
            ++e;
        }
        --e;
        mx = max(mx, e - st + 1);
        i = e + 1;
    }
    cout << mx << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t { 1 };
 //   cin >> t;
    while (t--)
        solve();

    return 0;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
tmp = 0
i = L
for _ in range(N):
    tmp += i
    i += 1
if tmp == 0:
    print(0)
elif tmp > 0:
    if L < 1:
        print(tmp)
    else:
        print(tmp-L)
else:
    if N+L == 0:
        print(tmp+1)
    elif N + L > 0:
        print(tmp)
    else:
        print(tmp - N - L + 1)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int gcd(int p, int q) {
	if (p % q == 0) return q;
	return gcd(q, p % q);
}

int main() {

	int k;
	cin >> k;

	long long ans = 0;
	for (int i = 1;i <= k;i++) {
		for (int j = 1;j <= k;j++) {
			for (int l = 1;l <= k;l++) {
				ans += gcd(gcd(i, j), l);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3668
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const INF = 100001000000

var h []int
var N, A, B int

func main() {
	sc.Split(bufio.ScanWords)

	N, A, B = nextInt(), nextInt(), nextInt()
	h = make([]int, N)
	for i := 0; i < N; i++ {
		h[i] = nextInt()
	}

	lb := 0
	ub := INF

	for ub-lb > 1 {
		mid := (ub + lb) / 2
		if C(mid) {
			ub = mid
		} else {
			lb = mid
		}
	}

	if !C(ub) {
		ub = lb
	}

	fmt.Println(ub)
}

func C(t int) bool {

	cnt := 0

	for _, hh := range h {
		if hh > B*t {
			cnt += (hh - B*t) / (A - B)
			if (hh-B*t)%(A-B) != 0 {
				cnt++
			}
		}
	}

	if t >= cnt {
		return true
	}
	return false

}


Measured memory_bytes: 3072
#include <stdio.h>
 
int main (void)
{
        int n,c,i;
        char s[100];
 
        scanf("%d",&n);
       for(i=0;i<n;i++)
           scanf("%s",s);
 
        if(n%2==1) printf("No");
        else{
        c=0;
        for(i=0;i<n/2;i++)
                if(s[i]==s[i+(n/2)]) c++;
 
        if(c==n/2) printf("Yes");
        else  printf("No");
        }
        return 0;
}

Measured memory_bytes: 128
let rec f () =
  let (a, s, b) = Scanf.scanf "%d %c %d\n" (fun a b c -> a,b,c) in
  match s with
    '+' -> print_int @@ a + b; print_newline (); f ()
  | '-' -> print_int @@ a - b; print_newline (); f ()
  | '*' -> print_int @@ a * b; print_newline (); f ()
  | '/' -> print_int @@ a / b; print_newline (); f ()
  | _ -> ()

let () = f ()

Measured memory_bytes: 2432
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
import std.math;

void main()
{
    auto a = stdin.byLine().map!(to!int).array().until(-1).array().idup;
    auto m = a.reduce!max()+1;
    auto p = new real[][](m,2);
    p[0][]=0.0;
    auto d = PI_2;
    foreach(i;1..m)
    {
        d-=PI_2;
        auto x=p[i][0]=p[i-1][0]+cos(d);
        auto y=p[i][1]=p[i-1][1]+sin(d);
        d=atan2(-y,-x);
    }
    foreach(v;a)
        writefln("%.2f",p[v][0]),
        writefln("%.2f",p[v][1]);
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define inf 1e9
using namespace std;
const int maxn=1e5+10;
vector<int>s[maxn];
vector<int> dis(3*maxn,inf);
int main()
{
    int m,n;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        x--,y--;
        s[x].push_back(y);
    }
    int st,ed;
    cin>>st>>ed;
    st--,ed--;
       dis[st]=0;
   queue<int>que;
    que.push(st);
    while(!que.empty()){
        int x=que.front();
        que.pop();
        int sum=x%n;

        for(int i=0;i<s[sum].size();i++){
           int d=dis[x]+1;
           int y=s[sum][i]+n*(d%3);
           if(dis[y]!=inf)
             continue;
           dis[y]=d;
           que.push(y);

        }
    }
   // for(int i=1;i<=n;i++)
  //      cout<<dis[i]<<endl;
printf("%d\n",dis[ed]==inf? -1:dis[ed]/3);

    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n){
    cin >> h[i];
  }
  vector<vector<int> > to(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  int ans=0;
  rep(i, n){
    int siz=to[i].size();
    bool good=true;
    rep(j, siz){
      if(h[i]<=h[to[i][j]]){
        good=false;
        break;
      }
    }
    if(good){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8756
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ii pair<int,int>
#define iii pair<ii,int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vvi vector<vector<int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define nu 100000
#define mod 1000000007
#define inf pow(10,9)
#define h pow(10,-8)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

int main()
{
	fastio;
	int n;
	ll ans = 0;
	cin >> n;
	
	vi v(n);
	cin >> v[0];
	if(v[0] != 0)
	{
		cout << -1;
		return 0;
	}

	for (int i = 1; i < n; ++i)
	{
		cin >> v[i];
		if(v[i] == v[i-1]+1)
		{
			ans++;
		}	
		else if(v[i] < v[i-1]+1)
		{
			ans += v[i];
		}
		else
		{
			cout << -1;
			return 0;
		}
	}

	cout << ans;
	return 0;
}	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
          using namespace std;
          #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
          #define M_PI 3.14159265358979323846
          #define data data_
          #define ff first
          #define ss second
          int const N = 101;
          long long dp[N][100009];
          long long const inf = 1e15;
          int main()
          {
          // clock_t begin = clock();
          // #ifndef ONLINE_JUDGE
          // freopen("input.txt", "r", stdin);
          // freopen("output.txt", "w", stdout);
          // #endif
          tani_nachi_ke  

          int n;
          long long w;
          cin >> n >> w;
          long long value[n+1],weight[n+1];
          for(int i=1; i<=n; i++)
               cin >> weight[i] >> value[i];
          for(int i=1; i<=n; i++)
          {
               for(int j=1; j<=100000; j++)
                    dp[i][j] = inf;
               dp[i][0] = 0;
          }
          dp[1][value[1]] = weight[1];
          for(int i = 2; i <= n; i++)
          {
               for(int j = 0; j <= 100000; j++)
                    dp[i][j] = dp[i-1][j];
               for(int j = 0; j + value[i] <= 100000; j++)
               {
                    dp[i][j + value[i]] = min(min(inf,dp[i-1][j] + weight[i]), dp[i-1][j + value[i]]);
               }
          }

          int ans = 0;
          for(int i = 0; i <= 100000; i++)
          {
               if(dp[n][i] <= w)
               {
                    ans = i;
               }
          }
          cout << ans << endl;


          




          // #ifndef ONLINE_JUDGE 
          // clock_t end = clock();
          // cout<<endl<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
          // #endif 
          // return 0;
          }

Measured memory_bytes: 78464
#include<bits/stdc++.h>
#define qtr ios::sync_with_stdio(0); cin.tie(0);
#define int long long
using namespace std;

int32_t main(){ qtr
	int n, m;
	cin >> n >> m;
	vector<int> weight(n);
	vector<int> value(n);
	for(int i = 0; i < n; i++){
		cin >> weight[i] >> value[i];
	}
	vector<vector<int>> dp(2, vector<int>(m+1));
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= m; j++){
			if(j < weight[i]) dp[i%2][j] = dp[(i+1)%2][j];
			else dp[i%2][j] = max(dp[(i+1)%2][j], dp[(i+1)%2][j-weight[i]] + value[i]);
		}
	}
	cout << max(dp[0][m], dp[1][m]) << endl;
}

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

int l[4],r[4];

int main(void){
	double x,y;

	while(cin>>x>>y){
		if(x >= 1.1)
			l[0]++;
		else if(x >= 0.6)
			l[1]++;
		else if(x >= 0.2)
			l[2]++;
		else
			l[3]++;

		if(y >= 1.1)
			r[0]++;
		else if(y >= 0.6)
			r[1]++;
		else if(y >= 0.2)
			r[2]++;
		else
			r[3]++;
	}
	for(int i=0;i<4;i++){
		cout<<l[i]<<" "<<r[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
   int N;
   cin>>N;
   int a[N],b[N];
   for(int i=1;i<N;i++)cin>>a[i];
   for(int i=0;i<N;i++)b[i]=0;
   for(int i=1;i<N;i++)b[a[i]-1]++;
   for(int i=0;i<N;i++)cout<<b[i]<<endl;
}

Measured memory_bytes: 5188
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1e9+1
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  long long int n,b,r;
  cin >> n >> b >> r;
  if(b > 0)
  {
    long long int t = n/(b+r);
    long long int rem = n%(b+r);
    cout << t*b+min(rem,b);
  }
  else
    cout << 0;
	return 0;
}	

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0;true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void AnsYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void AnsYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}







//ここまでライブラリ
//ここから本文





int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	for (int i = n - 1; i > 0; i--) {
		if (a.at(i) < a.at(i - 1)) {
			a.at(i - 1)--;
			if (a.at(i) < a.at(i - 1)) {
				AnsYes(false);
				return 0;
			}
		}
	}
	AnsYes(true);

}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"os"
)

func main() {
	var s string
	fp := os.Stdin

	fmt.Fscan(fp, &s)

	max := 0
	temp := 0

	for _, r := range s {
		if r == 'A' || r == 'C' || r == 'G' || r == 'T' {
			temp++
		} else {
			max = maxint(max, temp)
			temp = 0
		}
	}
	max = maxint(max, temp)
	fmt.Println(max)
}
func maxint(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

Measured memory_bytes: 512
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n
f111 f112 ... f151 f152
...
fn11 fn12 ... fn51 fn52
p10 ... p1,10
...
pn0 ... pn,10

n 100
 */

bool f[100][10];
int p[100][11];
int n;
const int INF = pow(10,9);
int main(){
  cin>>n;
  REP(i,n){
    REP(j,10){
      cin>>f[i][j];
    }
  }
  REP(i,n){
    REP(j,11){
      cin>>p[i][j];
    }
  }

  int ans=-INF;
  FOR_IN(b,1,pow(2,10)){
    int s = 0;
    REP(i,n){
      int c=0;
      REP(j,10){
        if(BIT(b,j) && f[i][j])
          c++;
      }
      s+=p[i][c];
    }
    //LOG("b=%d, s=%d\n",b,s);
    ans = max(ans, s);
  }

  cout<<ans<<endl;

  return 0;
}


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



int main()
{
	int n;
	cin >> n;
	const int lim = 100001;
	vector<int> a(lim);
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a[t]++;
	}
	int ans = -1;
	for (int i = 1; i < lim - 1; i++) {
		int temp = a[i - 1] + a[i] + a[i + 1];
		ans = max(temp, ans);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n,a[1<<18],b[1<<18],B[1<<18],ans;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<n;i++)scanf("%d",b+i);
	for(int i=0;i<29;i++)
	{
		long cnt=0;
		int m=1<<(i+1);
		for(int j=0;j<n;j++)B[j]=b[j]&(m-1);
		sort(B,B+n);
		for(int j=0;j<n;j++)
		{
			int A=a[j]&((m>>1)-1);
			cnt+=(a[j]>>i)&1
				?(lower_bound(B,B+n,(m>>1)-A)-B)+(B+n-lower_bound(B,B+n,m-A))
				:lower_bound(B,B+n,m-A)-lower_bound(B,B+n,(m>>1)-A);
		}
		ans|=(cnt&1)<<i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <string>
#include <iostream>
using namespace std;
 
int main(){
  int N;
  long long sum=0;
  cin >> N;
  for (int i =1; i< N+1; i++){
    if (i%3 !=0 && i%5 !=0){
        sum +=i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3156
N = int(input())
m = N % 10

if m == 2 or m == 4 or m == 5 or m == 7 or m == 9:
    print("hon")
elif m == 0 or m == 1 or m == 6 or m == 8:
    print("pon")
else:
    print("bon")


Measured memory_bytes: 61340
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr int MOD = 1'000'000'007;

// 1 <= k <= n <= 10^7
#define CNKMAX 1000001
class CNK1 {
    std::vector<long long> fac, finv, inv;
    int MOD;
public:
    CNK1(int mod = 1000000007): MOD(mod), fac(CNKMAX), finv(CNKMAX), inv(CNKMAX) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < CNKMAX; 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;
        }
    }
    int get(const int &n, const int &k) const {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

void solve() {
    LL n,k;
    cin >> n >> k;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    CNK1 cnk;
    LL ans = 0;
    sort(all(a));
    REP(i,0,n) {
        ans -= cnk.get(n-1-i,k-1) * ((a[i] + MOD) % MOD);
        ans %= MOD;
        if (ans < 0) ans += MOD;
    }
    RREP(i,0,n) {
        ans += cnk.get(i,k-1) * ((a[i] + MOD) % MOD);
        ans %= MOD;
        if (ans < 0) ans += MOD;
    }
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 24448
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N,K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  REP(i,N-K){
    if(A[i]<A[i+K]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,a,b,x[100005],i,ans=0;
    cin>>n>>a>>b;
    for(i=1;i<=n;i++)
        cin>>x[i]; 
    for(i=1;i<n;i++)
        ans+=min(a*(x[i+1]-x[i]),b);
    cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100010
int main(){
    int n,m,h[N],ma[N];
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>h[i];
        ma[i]=0;
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        ma[a]=max(ma[a],h[b]);
        ma[b]=max(ma[b],h[a]);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=ma[i]<h[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4416
#include <cstdio>
typedef long long int64;
static const int MAXN = 1e5 + 3;

int n;
int a[MAXN], b[MAXN], inc[MAXN];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &a[i], &b[i]);
        inc[i] = (a[i] % b[i] == 0 ? 0 : (b[i] - a[i] % b[i]));
    }

    int64 ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        ans += ((inc[i] - ans) % b[i] + b[i]) % b[i];
    }

    printf("%lld\n", ans);
    return 0;
}


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

typedef long long ll;

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

int bfs(const vector<string> &v, int x, int y) {
    int H = v.size(), W = v[0].size();
    vector<vector<int>>dist(H, vector<int>(W, -1));
    queue<pair<int, int>>que;

    int res = 0;
    que.push({x, y});
    dist[x][y] = 0;
    while (!que.empty()) {
        int x = que.front().first, y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();
        for (int dir = 0; dir < 4; ++dir) {
            int nx = x+dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) {
                continue;
            }
            if (v[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }
    return res;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    for (int i = 0; i < H; i++) {
        cin >> v[i];
    }
    int res = 0;
    for (int x = 0; x < H; x++) {
        for (int y = 0; y < W; y++) {
            if (v[x][y] == '#') continue;
            res = max(res, bfs(v, x, y));
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 256
import numpy as np
import scipy.stats as stats
N = int(input())
A = list(map(int,input().split()))
A = np.array(A)
A_plus = A + 1
A_minus = A - 1
A = np.append(A, A_plus)
A = np.append(A, A_minus)
print(stats.mode(A).count[0])

Measured memory_bytes: 69548
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	ll n = 0, a,b,m = 0,counter = 0;
	double kaku,coun=0;
	string in,in2;
	vector<ll>vec;
	cin >> n;
	rep(i, n) {
		cin >> kaku;
		coun += 1 / kaku;
	}
	cout << 1 / coun << endl;
	
}




Measured memory_bytes: 256
s=input()

n=len(s)
dc=dict()
dc['A']=0
dc['B']=1
dc['C']=2
dc['?']=3
dp=[[0 for i in range(4)] for j in range(n+1)]
dp[0][0]=1
mo=10**9+7
for i in range(n):
    for t in range(4):
        ch=s[i]
        m = 1 if dc[ch]==t-1 or dc[ch]==3 else 0
        if t!=0:
            dp[i+1][t]+=(dp[i][t-1]*m)%mo
        dp[i+1][t]+=(dp[i][t]*(3 if dc[ch]==3 else 1))%mo

ans=dp[n][3]
print(ans%mo)


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int  n = 2;
    char c[n];
    rep(i, n) { cin >> c[i]; }

    // 処理
    // 出力
    if (c[0] > c[1]) {
        cout << ">" << endl;
    } else if (c[0] < c[1]) {
        cout << "<" << endl;
    } else {
        cout << "=" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
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; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{
    string s;
    int k;
    cin >> s >> k;
    vector<string> v;
    for (int i=0; i<s.size(); ++i)
    {
        for (int j=1; j<s.size()-i+1; ++j)
        {
            if(s.substr(i,j).size()>k) continue;
            v.push_back(s.substr(i,j));
        }
    }

    sort(v.begin(),v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    
    cout << v[k-1] << endl;

    return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=2e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
vector<int>v[N];
inline int dfs(int k,int fa=0) {
	int ans=0;
	for (int t:v[k])
		if (t!=fa)
			ans^=dfs(t,k)+1;
	return ans;
}
int main()
{
	int n=gi(),a,b;
	while (--n) v[a=gi()].push_back(b=gi()),v[b].push_back(a);
	puts(dfs(1)?"Alice":"Bob");
	return 0;
}


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

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

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

    int m;
    cin >> m;
    int p[m], x[m];
    for (int i = 0; i < m; i++) {
        int pp;
        cin >> pp >> x[i];
        p[i] = --pp;
    }

    for (int i = 0; i < m; i++) {
        cout << total - t[p[i]] + x[i] << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int num = int.Parse(Reader.ReadLine());
        int ans = 0;
        for (int i = 0; i < num; i++) {
            int tmp = 1 << i;
            if(tmp>num) {
                break;
            }
            ans = tmp;
        }
        Console.WriteLine(ans);
        
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"

100


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int K, S;
	cin >> K >> S;
	int ans = 0;
	for (int x = 0; x <= K; x++) {
		for (int y = 0; y <= K; y++) {
			if (S - x - y <= K && S - x - y >= 0) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> l(m),r(m);
    vector<int> idl(n),idr(n);
    rep(i,m){
        cin>>l[i]>>r[i];
        l[i]--;
        r[i]--;
        idl[l[i]]=1;
        idr[r[i]]=1;
    }
    int ansl=0,ansr=n;
    rep(i,n){
        if(idl[i]==1){
            ansl=max(ansl,i);
        }
        if(idr[i]==1){
            ansr=min(ansr,i);
        }
    }
    int ans=ansr-ansl+1;
    ans=(ans>0)?ans:0;
    cout<<ans<<endl;
}

Measured memory_bytes: 4796
// AtCoder Beginner Contest 057
// C - Digits in Multiplication

#include <cstdio>

using namespace std;
typedef long long int ll;


ll N;
int ans;

int main() {

  ll a, b;

  scanf("%lld", &N);
  for (ll i = 1; i * i <= N; i++) {
    if (N % i != 0) {
      continue;
    }
    a = i;
  }
  b = N / a;

  ans = 0;
  while (b > 0) {
    ans++;
    b /= 10;
  }

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

  return 0;

}




Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
const ll INF=(1LL<<62);

bool solve(){
  ll x,k,d;cin>>x>>k>>d;
  x=abs(x);
  d=abs(d);
  k=abs(k);
  
  if(d<pow(10,17)/k and d*k<x){
    cout<<abs(x-d*k)<<endl;
    return false;
  }else{
    ll a=x/d;
    x-=x/d*d;
    k-=a;
    if(k%2==0){
      cout<<abs(x)<<endl;
    }else{
      cout<<abs(d-x)<<endl;
    }
  }



  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  return solve();
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[100100];
long long sum[100100];
long long possum[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
		possum[i]=possum[i-1];
		if(a[i]>0)
			possum[i]+=a[i];
	}
	long long ans=sum[n];
	for(int i=1;i<=n-k+1;i++){
		long long s1=possum[i-1];
		long long s2=possum[n]-possum[i+k-1];
		ans=max(ans,s1+s2);
		ans=max(ans,s1+s2+sum[i+k-1]-sum[i-1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2304
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	bw = bufio.NewWriter(os.Stdout)
)

func init() {}
func ru() (n int) {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}
func ri() (n int) {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	b := sc.Bytes()
	neg := false
	if b[0] == 45 {
		neg = true
	}
	for _, v := range b {
		n = n*10 + int(v-48)
	}
	if neg {
		n = -n
	}
	return
}
func rs() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return sc.Text()
}
func rb() []byte {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return sc.Bytes()
}
func pf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(bw, f, a...); err != nil {
		panic(err)
	}
}
func pln(a ...interface{}) {
	if _, err := fmt.Fprintln(bw, a...); err != nil {
		panic(err)
	}
}
func debug(a ...interface{}) {
	s := fmt.Sprint(a)
	if _, err := fmt.Fprintln(os.Stderr, s[1:len(s)-1]); err != nil {
		panic(err)
	}
}
func pall(a []int) {
	for _, v := range a {
		fmt.Fprintln(bw, v)
	}
}
func pallol(a []int) {
	s := fmt.Sprint(a)
	if _, err := fmt.Fprintln(bw, s[1:len(s)-1]); err != nil {
		panic(err)
	}
}
func isEven(n int) bool {
	return n&1 == 0
}
func isOdd(n int) bool {
	return n&1 == 1
}
func swap(a int, b int) (int, int) {
	return b, a
}
func fill(a []int, val int) {
	for i := 0; i < len(a); i++ {
		a[i] = val
	}
	return
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func largest(a, b, c int) (lgst int) {
	if a > b {
		lgst = a
	} else {
		lgst = b
	}
	if c > lgst {
		lgst = c
	}
	return
}
func smallerst(a, b, c int) (slst int) {
	if a < b {
		slst = a
	} else {
		slst = b
	}
	if c < slst {
		slst = c
	}
	return
}
func max(a []int) (idx, val int) {
	if len(a) == 0 {
		panic("func max requires at least one argument")
	}
	val = a[0]
	for i, aa := range a {
		if aa > val {
			idx, val = i, aa
		}
	}
	return
}
func min(a []int) (idx, val int) {
	if len(a) == 0 {
		panic("func min requires at least one argument")
	}
	val = a[0]
	for i, aa := range a {
		if aa < val {
			idx, val = i, aa
		}
	}
	return
}
func sum(a []int) int {
	res := 0
	for _, v := range a {
		res += v
	}
	return res
}
func powInt(a, b int) int { return int(math.Pow(float64(a), float64(b))) }
func main() {
	sc.Split(bufio.ScanWords)
	solve()
	bw.Flush()
}

const (
	inf = 1 << 60
	mod = 1e9 + 7
)

type pair struct{ a, b int }
type point struct{ x, y int }

func solve() {
	n, q := ri(), ri()
	al := make([][]int, n)
	for i := 1; i <= n-1; i++ {
		a, b := ri()-1, ri()-1
		al[a] = append(al[a], b)
		al[b] = append(al[b], a)
	}
	ps := make([]int, n)
	for i := 1; i <= q; i++ {
		p, x := ri()-1, ri()
		ps[p] += x
	}
	var f func(int, int)
	f = func(o, p int) {
		for _, x := range al[o] {
			if x == p {
				continue
			}
			ps[x] += ps[o]
			f(x, o)
		}
	}
	f(0, -1)
	pallol(ps)
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

    ll n,a[101],ans1=0,ans2,flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8,num=0;
    cin >> n;
    rep(i,n) cin >> a[i];
    flag1=flag2=flag3=flag4=flag5=flag6=flag7=flag8=0;
    rep(i,n){
        if(a[i] < 400){
            if(flag1==0){
                ans1++;
                flag1++;
            }
        }
        else if(a[i] < 800){
            if(flag2==0){
                ans1++;
                flag2++;
            }
        }
        else if(a[i] < 1200){
            if(flag3==0){
                ans1++;
                flag3++;
            }
        }
        else if(a[i] < 1600){
            if(flag4==0){
                ans1++;
                flag4++;
            }
        }
        else if(a[i] < 2000){
            if(flag5==0){
                ans1++;
                flag5++;
            }
        }
        else if(a[i] < 2400){
            if(flag6==0){
                ans1++;
                flag6++;
            }
        }
        else if(a[i] < 2800){
            if(flag7==0){
                ans1++;
                flag7++;
            }
        }
        else if(a[i] < 3200){
            if(flag8==0){
                ans1++;
                flag8++;
            }
        }
        else num++;
    }
    if(ans1==0){
        ans1 = 1;
        ans2 = n;
    }
    else ans2 = ans1 + num;
    cout << ans1 << ' ' << ans2 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long power(long long m, long long n) {
    if(n == 1) return m;
    else if(n%2 == 0) return power(m*m%1000000007, n/2);
    else return power(m*m%1000000007, n/2)*m%1000000007;
}

int main(void){
    long long m, n;
    
    scanf("%lld %lld\n", &m, &n);
    
    printf("%lld\n", power(m,n));
    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll X, N;
    cin >> X >> N;
    vll p(N);
    rep(i, N) cin >> p[i];

    vll cnt(110, 0);
    rep(i, N) cnt[p[i]]++;


    ll ans;
    rep(i, 200) {
        if(cnt[X-i] == 0) {
            ans = X - i;
            break;
        }
        else if(cnt[X+i] == 0) {
            ans = X + i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <array>
#include <numeric>
#include <algorithm>

using namespace std;

int main(){
    int n;
    int count = 1;
    string p, q;
    int Pnum = 0, Qnum = 0;
    int* arr;

    cin >> n;
    arr = new int[n];
    iota(arr, arr+n, 1);

    for(int i = 0; i < n; ++i) {
        char buf;
        cin >> buf;
        p += buf;
    }

    for(int i = 0; i < n; ++i) {
        char buf;
        cin >> buf;
        q += buf;
    }

    do {
        string s;
        for(int i = 0; i < n; ++i) s += to_string(arr[i]);
        if(!Pnum && s == p) Pnum = count;
        if(!Qnum && s == q) Qnum = count;
        if(Pnum && Qnum) break;
        ++count;
    } while(next_permutation(arr, arr+n));

    cout << abs(Pnum - Qnum);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define fir fisrt
#define sec second

int n, k;

struct P{
	int x,y;
}a[105];

int main(){
	scanf(" %d %d", &n, &k);
	int Min = 1e9 + 7;
	for(int i = 1; i <= n; i ++){
		scanf(" %d %d", &a[i].x, &a[i].y);
		if(a[i].y <= k){
			if(a[i].x < Min) Min = a[i].x;
		}
	}
	if(Min == 1e9 + 7) printf("TLE\n");
	else printf("%d\n", Min);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
ll div_num[31];

int main() {
    ll N, num, count = 0;
    cin >> N;
    div_num[0] = 1;
    for (int i = 1; i < 31; i++) div_num[i] = 2;
    for (int i = 1; i < 31; i++) div_num[i] *= div_num[i - 1];
    for (ll i = 0; i < N; i++) {
        cin >> num;
        for (int i = 30; i >= 0; i--) {
            if (num % div_num[i] == 0) {
                count += i;
                break;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
MOD = 1000000007

N = parse(Int, readline())
s1 = readline()
s2 = readline()

curr = 0
prev = 0
ans = 1

i = 1
while i <= N
    curr = s1[i] == s2[i] ? 1 : 2
    if prev == 0
        if curr == 1
            global ans = 3
        else
            global ans = 6
        end
    else
        if prev == 1 && curr == 1
            global ans *= 2
        elseif prev == 1 && curr == 2
            global ans *= 2
        elseif prev == 2 && curr == 1
            global ans *= 1
        elseif prev == 2 && curr == 2
            global ans *= 3
        end
    end

    ans%=MOD

    global i += curr
    global prev = curr
end

println(ans)

Measured memory_bytes: 171808
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)



int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE


ll k,x;
cin>>k>>x;
if(k*500>=x)
	cout<<"Yes";
else cout<<"No";

return 0;
 }


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <numeric>
int main()
{
    long long n;
    std ::vector<long long> a, b;
    std ::cin >> n;
    for (int i = 0; i <= n; i++)
    {
        long long num = 0;
        std ::cin >> num;
        a.push_back(num);
    }

    for (long long i = 0; i < n; i++)
    {
        long long num = 0;
        std ::cin >> num;
        b.push_back(num);
    }

    long temp = 0, sum = 0;
    for (long long i = 0; i < n; i++)
    {
        temp = a[i] - b[i];
        if (temp <= 0)
        {
            if(a[i + 1] >= -temp){
                a[i + 1] += temp;
                sum += b[i];
            }else{
                  sum += a[i] + a[i + 1];
                  a[i + 1] = 0;
            }           
        }
        else{
            sum += b[i];
        }
    }
    std ::cout << sum;
}


Measured memory_bytes: 2548
#include <assert.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <string>
#include <vector>

 
using namespace std;
 
typedef string str;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;




#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define trav(a, x) for (auto &a : x)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define PRINT_ARRAY(a, N)        \
  F0R(z, N) cout << a[z] << " "; \
  cout << "\n"
 
const int MOD = 1000000007;  // 998244353
const ll INF = 1e18;
const ld PI = 4 * atan((ld)1);


ll N, W;
ll w[100005];
ll v[100005];
ll dp[100005];

int main() {
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cout.tie(NULL);
		cin >> N >> W;

		// dp[i] = min weight to get exactly value i.
		ll sum_values = 0;
		F0R(i, N) {
				cin >> w[i] >> v[i];
				sum_values += v[i];
		}

		for (int i = 1; i <= sum_values; i++) {
				dp[i] = INF;
		}

		ll best = -1;
		// dp[i] = mininmum weight required to get value i.
		for (int i = 1; i <= N; i++) {
				int weight = w[i - 1], value = v[i - 1];
				for (int j = sum_values - value; j >= 0; j--) {
						if (dp[j] + weight <= W) {
								dp[j + value] = MIN(dp[j + value], dp[j] + weight);
								best = MAX(best, j + value);
						}
				}
		}

		cout << best << endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int x[100010], y[100010];
signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, n) cin >> x[i];
  REP(i, m) cin >> y[i];

  int xx = 0, yy = 0;
  FOR(i, 1, n+1) (xx += (2*i-n-1)%MOD*x[i-1]) %= MOD;
  FOR(i, 1, m+1) (yy += (2*i-m-1)%MOD*y[i-1]) %= MOD;

  //cout << xx << " " << yy << endl;
  cout << xx*yy%MOD << endl;

  return 0;
}


Measured memory_bytes: 1792
n = int(input())
flag = True
dx, dy, dt = 0, 0, 0

for _ in range(n):
    t, x, y = map(int, input().split())
    dist = abs(dx - x) + abs(dy - y)
    if t - dt < dist or (t - dt - dist) % 2:
        flag = False
    dt, dx, dy = t, x, y

print("Yes" if flag else "No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string.h>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15

 int main(){

 string a,b;
  cin>>a>>b;

  if(a.length() > b.length())
    cout<<"GREATER"<<endl;
  else if(b.length()>a.length())
    cout<<"LESS"<<endl;
else
 if(a>b)
    cout<<"GREATER"<<endl;
 else if(b>a)
    cout<<"LESS"<<endl;
    else if(a == b )
        cout<<"EQUAL"<<endl;


  return 0;
 }

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;
using posteriority_queue = priority_queue<int, vi, greater<int>>;


int main() {
    int N, K; cin >> N >> K;
    int ans = 0;
    posteriority_queue que;
    vi p(N);
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        que.push(tmp);
    }

    for(int i = 0; i < K; i++){
        ans += que.top();
        que.pop();
    }

    cout << ans << endl;

}

Measured memory_bytes: 3632