akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = INT_MAX;
/************************  DEFINE  ****************************/
const int MAX_N = 100000;
/************************ FUNCTION ****************************/

/************************   MAIN   ****************************/
int main(void){
    string S; cin >> S;
    int N = S.size();
    if(S[0] == '0' || S[N-1] == '1'){
        cout << -1 << endl;
        return 0;
    }
    for(int i=1;i<N-1;i++){
        if(S[i]!=S[N-(i+1)-1]){
            cout << -1 << endl;
            return 0;
        }
    }
    S[N-1] = '1';
    int par[MAX_N];
    int p=N-1;par[N-2]=p;
    for(int i = N-3;i >= 0;i--){
        if(S[i+1] == '1'){
            p=i+1,par[i]=p;
        }else{
            par[i]=p;
        }
    }
    for(int i=0;i<N-1;i++){
        printf("%d %d\n",i+1,par[i]+1);
    }
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>

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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int n;

int mul(int a, int b){
  return ll(a) * b % mod;
}

int main(){
  cin >> n;
  int p = 1;
  for(int i = 1; i <= n; ++i){
    p = mul(p, i);
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>

char s[200001];

int main()
{
	int i,j;long long c=0;
	scanf("%s",s);
	for(i=j=0;s[i];i++)
		if(s[i]=='W')
			c+=i-j,j++;
	printf("%lld\n",c);
}

Measured memory_bytes: 384
//<--sbhmsh-- Shubham Jaiswal>//

#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lli long long int
#define endl '\n'
#define deb cout<<"sab_badhiya"<<endl;
// const long long INF = 1000 * 1000 * 1000 * 1ll * 1000 * 1000 * 1000;
const long INF = 1000 * 1000 * 1000;
const long long int mod = 1000000007;

int main(){
  FASTIO
  int n;
  cin >> n;
  for(int i=1; i < sqrt(n) +1 ; i++){
    if(n%i==0){
      if( i <10 && n/i <10){
        cout << "Yes" << endl;
				exit(0);
      }
    }
  }
  cout << "No"<< endl;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())
ans = [0] + [x for x in range(n-1, 0, -1)]

# print(ans)

byd = y - x

# i < x and y < j
for i in range(1, x+1):
    for j in range(y, n+1):
        altd = j - i
        d = j - i - byd + 1
        ans[altd] -= 1
        ans[d] += 1

ld = byd + 1

# x < i, j < y
for i in range(x, y):
    for j in range(x+1, y+1):
        if i == x and j == y:
            break

        altd = j - i
        d = ld - (j - i)
        if altd > d:
            ans[altd] -= 1
            ans[d] += 1

# i < x, x < j < y
for i in range(1, x):
    for j in range(x+1, y):
        altd = j - i
        d = ld - (j - x) + (x-i)
        if altd > d:
            ans[altd] -= 1
            ans[d] += 1

# i < x < j, y < j
for i in range(x+1, y):
    for j in range(y+1, n+1):
        altd = j - i
        d = ld - (y - i) + (j - y)
        if altd > d:
            ans[altd] -= 1
            ans[d] += 1

for k in range(1, n):
    print(ans[k])


Measured memory_bytes: 3444
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate
import sys
import bisect
import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))

# ----------

N, M = mii()
A = lmii()

total = sum(A)

enjoy = N - total

if enjoy < 0:
    print(-1)
else:
    print(enjoy)



Measured memory_bytes: 27844
class Dice
  attr :top, :front, :right, :left, :back, :bottom
  def initialize a,b,c,d,e,f
    @top = a; @front = b; @right = c; @left = d; @back = e; @bottom = f
  end
  def == other
    other.top == @top && other.front == @front && other.right == @right \
    && other.left == @left && other.back == @back && other.bottom == @bottom
  end
  def rotN
    t = @top; @top = @front; @front = @bottom; @bottom = @back; @back = t; self
  end
  def rotE
    t = @top; @top = @left; @left = @bottom; @bottom = @right; @right = t; self
  end
  def rotW
    t = @top; @top = @right; @right = @bottom; @bottom = @left; @left = t; self
  end
  def rotS
    t = @top; @top = @back; @back = @bottom; @bottom = @front; @front = t; self
  end
  def rotV
    t = @front; @front = @left; @left = @back; @back = @right; @right = t; self
  end
  def show
#    printf("%d %d %d %d %d %d\n",@top,@front,@right,@left,@back,@bottom)
  end
  def isSame die
    ret = false
    for i in 1..4
      die.rotV
      die.show
      ret = true if die == self
    end
    die.rotE
    for i in 1..4
      die.rotV
      die.show
      ret = true if die == self
    end
    die.rotE
    for i in 1..4
      die.rotV
      die.show
      ret = true if die == self
    end
    die.rotE
    for i in 1..4
      die.rotV
      die.show
      ret = true if die == self
    end
    die.rotE.rotN
    for i in 1..4
      die.rotV
      die.show
      ret = true if die == self
    end
    die.rotS.rotS
    for i in 1..4
      die.rotV
      die.show
      ret = true if die == self
    end
    ret
  end
end

n = gets.to_i
ary = Array.new(n)
for i in 1..n
  a,b,c,d,e,f = gets.split.map {|s| s.to_i}
  d = Dice.new(a,b,c,d,e,f)
  ary[i-1] = d
end
ret = true
for i in 1..n-1
  for j in i+1..n
    ret = false if ary[i-1].isSame(ary[j-1])
  end
end
if ret
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 6132
//
// Created by 李青坪 on 2018/10/12.
//

#include "cstdio"

using namespace std;

int a[2000001];
int b[2000001];
int c[10001];
int MAXK = 10001;

void countingSort(int n){
    for (int i = 0; i < MAXK; ++i) {
        c[i] = 0;
    }
    for (int j = 1; j <= n; ++j) {
        ++c[a[j]];
    }
    for (int k = 1; k < MAXK; ++k) {
        c[k] = c[k] + c[k-1];
    }
    for (int l = n; l > 0; --l) {
        int index = c[a[l]];
        b[index] = a[l];
        --c[a[l]];
    }
}

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    countingSort(n);
    for (int j = 1; j <= n; ++j) {
        if (j-1) printf(" ");
        printf("%d", b[j]);
    }
    printf("\n");
}


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

int main() {
  int a,b;
  cin >> a >> b;
  if(a+ b >= a-b && a+b >= a*b){
    cout << a+b << endl;
  }
  else if(a-b >= a+b && a-b >= a*b){
    cout << a-b << endl;
  }
  else{
    cout << a*b << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    /*
     #.#.#.
     ......
     #.#.#.
     ......
     ######
     .#.#.#
     ######
     .#.#.#
     */
    int a, b;
    cin >> a >> b;
    string s[102] = {};
    for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 100; j++) s[i] += '.';
    }
    for (int i = 50; i < 100; i++) {
        for (int j = 0; j < 100; j++) s[i] += '#';
    }
    b--;
    for (int i = 0; i < 50; i += 2) {
        for (int j = 0; j < 100; j += 2) {
            if (b == 0) break;
            s[i][j] = '#';
            b--;
        }
        if (b == 0) break;
    }
    a--;
    for (int i = 52; i < 100; i += 2) {
        for (int j = 0; j < 100; j += 2) {
            if (a == 0) break;
            s[i][j] = '.';
            a--;
        }
        if (a == 0) break;
    }
    cout << 100 << ' ' << 100 << '\n';
    for (int i = 0; i < 100; i++) cout << s[i] << '\n';
}


Measured memory_bytes: 3604
x=list(input())
num=[]
s="S"
cnt=len(x)
for i in range(len(x)):
    if x[i]==s:
        cnt=i
        break
cnt2=0
for i in range(cnt,len(x)):
    if x[i]!=s:
        if s=="T":
            s="S"
        else:
            s="T"
        num.append(cnt2)
        cnt2=1
    else:
        cnt2+=1
num.append(cnt2)
ans=0
num3=0
if len(num)%2==1:
    del(num[-1])
for i in range(len(num)//2):
    if num[-2*(i+1)]>=num[(-2*i)-1]+num3:
        ans+=num[(-2*i)-1]+num3
        num3=0
    else:
        ans+=num[-2*(i+1)]
        num3=num[(-2*i)-1]+num3-num[-2*(i+1)]
print(len(x)-(ans*2))


Measured memory_bytes: 11528
#include<stdio.h>
#define N 200000
int main()
{
  int x[N];
  int i;
  int max = -1000000000;
  int sa;
  int min;

  for(i = 0 ; i < N ; i++){
    scanf("%d", &x[i]);
  }

  min = x[1];

  for(i = 2 ; i < x[0] + 1 ; i++){
    sa = x[i] - min;
    if(max < sa){
      max = sa;
    }
    if(min > x[i]){
      min = x[i];
    }
  }

  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 1376
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <iterator>
#include <limits>
#include <numeric>
#include <type_traits>
#include <cmath>
#include <cstdlib>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

#define ALL(v) (v).begin(), (v).end()
#define endl "\n"
typedef long long int ll;

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

int SumDigitValues(int x)
{
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x = x / 10;
	}

	return sum;
}

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

int factorial(int n)
{
	if (n > 1)
	{
		return n * factorial(n - 1);
	}
	else
	{
		return 1;
	}
}

int gcd(int x, int y)
{
	if (y == 0)
		return x;
	else 
		return gcd(y, x % y);
}

vector<int> Divisors(int x)
{
	vector<int> divisors;
	divisors.push_back(1);
	for (int a = 2; a <= x; a++)
	{
		if (x % a == 0) divisors.push_back(a);
	}
	return divisors;
}

vector<int> CommonDivisors(int a, int b)
{
	vector<int> divisorsA = Divisors(a);
	vector<int> divisorsB = Divisors(b);
	vector<int> commonDivisors;
	set_intersection(divisorsA.begin(), divisorsA.end(), divisorsB.begin(), divisorsB.end(), std::back_inserter(commonDivisors));
	return commonDivisors;
}

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

	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> ans(n);
	rep(i, n)ans[a[i] - 1] = i + 1;
	rep(i, n) cout << ans[i] << endl;
}

Measured memory_bytes: 1664
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int q;cin>>q;
    set<int> st;
    rep(i,0,q){
        int a,b;cin>>a>>b;
        if(a==0){
            st.insert(b);
            cout<<st.size()<<endl;
        }else {
            cout<<st.count(b)<<endl;
        }
    }
    
    
}



/*

*/



Measured memory_bytes: 12444
N=int(input())
S=[input() for _ in range(N)]

MARCH=[0]*5
for i in range(N):
  if S[i][0]=="M":
    MARCH[0]+=1
  elif S[i][0]=="A":
    MARCH[1]+=1
  elif S[i][0]=="R":
    MARCH[2]+=1
  elif S[i][0]=="C":
    MARCH[3]+=1
  elif S[i][0]=="H":
    MARCH[4]+=1

ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=MARCH[i]*MARCH[j]*MARCH[k]
print(ans)


Measured memory_bytes: 9772
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,h[200000];
signed main(){
    cin>>n;
    rep(i,n)cin>>h[i];
    int cnt=0,ans=0;
    for(int i=1;i<n;i++){
        if(h[i]<=h[i-1])cnt++;
        else cnt=0;
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    
    let mut iter = buf.split_whitespace();
    
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    
    let max = min(a, b);
    let mut count = 0;
    
    for i in (1..max+1).rev() {
        if a % i == 0 && b % i == 0 {
            count += 1;
            if count == k {
                println!("{}", i);
                break;
            }
        }
    }
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner cin = new Scanner(System.in)) {
			if ((cin.nextInt() * 100 + cin.nextInt() * 10 + cin.nextInt()) % 4 == 0) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		} finally {
		}
	}

}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define Sort(vec) sort(vec.begin(),vec.end())
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define all(st) st.begin(),st.end()
#define vpll vector<pair<lli,lli>>
#define vpii vector<pair<int,int>>
#define al vector<list<int>>
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<lli>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ulli unsigned long long int
#define pb push_back
#define lli long long int
#define inf INT_MAX
#define minf INT_MIN
#define f first
#define se second
#define mod 1000000007
#define mx 200001
using namespace std;
void add_me(lli &a,lli b){
    a+=b;
    if(a>=mod) a-=mod;
}   
void sub_me(lli &a,lli b){
    a-=b;
    if(a<0) a+=mod;
}
struct disjointset{
    int parent[mx];
   	disjointset(){
        for(int i=1;i<mx;i++) parent[i]=i;
    }
    int find(int x){
      	int par=parent[x];
        if(par==x) return x;
        return find(parent[x]);
    }
    void union_(int x,int y){
   	    int par1=find(x);
     	int par2=find(y);
       	if(par1==par2) return;
       	parent[par2]=par1;
    }
};
lli mi(lli n,lli m){
	lli pw=n;
	lli ex=m-2;
	lli ans=1;
	while(ex){
		if(ex&1) ans = ans*pw%m;
		pw = pw*pw%m;
		ex>>=1;
	}
	return ans;
}
int main(){
	FIO;
	string s,t;cin>>s>>t;
	t+=s;
	cout<<t<<endl;
	
	
	
	
	
	
}

Measured memory_bytes: 256
<?php

$input = fgets(STDIN);
$array = explode(' ', $input);

$a = (int)$array[0];
$b = (int)$array[1];
$c = (int)$array[2];

$message = 'No';

if ($a === $b && $a !== $c) {
    $message = 'Yes';
} elseif($a === $c && $a !== $b) {
    $message = 'Yes';
} elseif($b === $c && $b !== $a) {
    $message = 'Yes';
}

echo $message;

Measured memory_bytes: 16124
#include<bits/stdc++.h>
using namespace std;
int n,x[200001],k;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>x[i];
	if(x[0]>=0)cout<<x[k-1]<<endl;
	else if(x[n-1]<=0)cout<<-x[n-k]<<endl;
	else
	{
		int ans=1<<30;
		for(int i=0,j=i+k-1;j<n;i++,j++)
			if(x[i]<=0&&x[j]>=0)ans=min(ans,min(-2*x[i]+x[j],2*x[j]-x[i]));
			else if(x[i]>=0)ans=min(ans,x[j]);
			else ans=min(ans,-x[i]);
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 640
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.IntMap as IMap
import qualified Data.Vector as V
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt

sqleft :: Seq a -> a
sqleft q = sqleft_(Sq.viewl q)
sqleft_ :: ViewL a -> a
sqleft_ (x :< xs) = x
sqright :: Seq a -> a
sqright q = sqright_(Sq.viewr q)
sqright_ :: ViewR a -> a
sqright_ (xs :> x) = x
-------------------------------------------------------------

main = do
    a <- readLn :: IO Int
    b <- readLn :: IO Int
    c <- readLn :: IO Int
    d <- readLn :: IO Int
    print $ (min a b) + (min c d)

Measured memory_bytes: 508
N,L=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
possible=0
for i in range(N-1):
    if(a[i]+a[i+1] >= L):
        print("Possible")
        possible=i+1
        break
if(possible):
    for i in range(1,possible):
        print(i)
    for i in range(N-possible-1):
        print(N-i-1)
    print(possible)
else:
    print("Impossible")


Measured memory_bytes: 14152
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-19 07:29:14
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;

  const int inf = 1e9;
  vector<int> can(26, inf);
  for (int i = 0; i < n; ++i) {
    string s; cin >> s;
    vector<int> cnt(26, 0);
    for (char c : s) ++cnt[c - 'a'];
    for (int j = 0; j < 26; ++j) {
      can[j] = min(can[j], cnt[j]);
    }
  }

  string ans = "";
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < can[i]; ++j) {
      ans += (char)('a' + i);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    string s;
    cin >> s;
    int(k);
    rep(i, s.size()){
      int a = 26 - (s[i] - 'a');
      if(a <= k && s[i] != 'a'){
        s[i] = 'a';
        k -= a;
      }
    }
    if(k > 0){
      k %= 26;
      s[s.size() - 1] += k;
    }

    pri(s);


/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 512
from collections import deque
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
cnt = [0] * n
already = [False] * n

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(q):
    p,x = map(int,input().split())
    cnt[p-1] += x
wait_q = deque()
wait_q.append(0)

while len(wait_q) > 0:
    parent = wait_q.popleft()
    for child in graph[parent]:
        if child == 0:continue
        if already[child] == True:continue
        already[child] = True
        cnt[child] += cnt[parent]
        wait_q.append(child)
print(*cnt)


Measured memory_bytes: 56168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long x = long.Parse(Console.ReadLine());
            long a = long.Parse(Console.ReadLine());
            long b = long.Parse(Console.ReadLine());
            x = x - a;
            x = x % b;
            Console.WriteLine(x);
        }
    }
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int n, m;
    cin >> n >> m;

    int x;
    priority_queue<int> pq;
    long long result = 0;

    REPI(i, n){
        cin >> x;
        pq.push(x);
        result += x;
    }

    while(m--){
        int top = pq.top();
        pq.pop();
        int after = top / 2;
        result -= (top - after);
        pq.push(after);
    }
    cout << result;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;


int main()
{
	int n , w;
	scanf("%d%d", &n, &w);
	ll dp[w + 5] = {0};
	for (int i = 0; i < n; i++) {
		ll wi, vi;
		scanf("%lld%lld", &wi, &vi);
		for (int j = w; j >= 0; j--) {
			if (j >= wi)dp[j] = max(dp[j], dp[j - wi] + vi);
		}

	}
	printf("%lld\n", dp[w]);

	return 0;
}


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

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define forn(i, n) for (int i = 0; i < n; i++)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rforn(i, n) for (int i = n; i >= 0; i--)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int A;
    int B;
    cin >> A >> B;
    if (A <= 9 && B <= 9)
        printf("%d\n", A * B);
    else
        printf("-1\n");
    // bool f = true;
    // forn(i, 10)
    // {
    //     if (i == 0)
    //         continue;
    //     forn(j, 10)
    //     {
    //         if (i * j == A * B && f)
    //         {
    //             if (j == 0)
    //                 continue;
    //             f = false;
    //             cout << i * j << "\n";
    //         }
    //     }
    // }
    // if (f)
    // {
    //     cout << -1 << "\n";
    // }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

#define ARRAY_MAX 10001


vector<int> par(ARRAY_MAX);//親
vector<int> rank(ARRAY_MAX);//木の深さ

//n要素で初期化
void init(int n){
    for(int i = 0;i < n;i++){
        par[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
        rank[i] = 0;/*各ノード自体の高さは0*/
    }
}

//木の根を求める
int find(int x){
    if(par[x] == x){
        return x;/*根ならそのノードの番号を返す*/
    }else{
        return par[x] = find(par[x]);/*根でないならさらにノードの根を探す*/
    }
}

//xとyの属する集合を併合する
void unite(int x,int y){
    x = find(x);//xの根の番号を探す
    y = find(y);//yの根の番号を探す
    if(x == y){//一致すればつながっている
        return;
    }
    if(rank[x] < rank[y]){//xの高さが低いなら高いほうにつなぐ、そして高さは大きい方(y)になる
        par[x] = y;
    }else{
        par[y] = x;//yの高さが低いなら高いほうにつなぐ、そして高さは大きいほう(x)になる
        if(rank[x] == rank[y]){//高さが一致しているなら併合の高さは1増える
            rank[x]++;
        }
    }
}

//xとyが同じ集合に属するか判定
bool same(int x,int y){
    return find(x) == find(y);//同じ集合なら1、違うなら0が返る
}


int main(){


    int n,q,com,x,y;
    cin >> n >> q;
    init(n);

    REP(i,q){

        cin >> com >> x >> y;
        if(com == 0){
            unite(x,y);
        }else{

            if(same(x,y)){
                cout << "1" << endl;
            }else{
                cout << "0" << endl;
            }

        }
    }
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  char c; cin >> c;
  c++;
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<vector<int>> mat(n, vector<int>(n, 1));
	if (n % 2 == 1) {
		for (int i = 1; i <= n / 2; ++i) {
			mat[i - 1][n - i - 1] = 0;
			mat[n-i-1][i-1] = 0;
		}
	}
	else {
		for (int i = 1; i <= n / 2; ++i) {
			mat[i - 1][n - i] = 0;
			mat[n-1][i-1] = 0;
		}
	}

	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (mat[i][j] == 1) cnt++;
		}
	}
	cout << cnt << endl;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (mat[i][j] == 1) {
				cout << i+1 << " " << j+1 << endl;
			}
		}
	}
}

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

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

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

    // 累積 GCD (左と右両方)
    vector<int> left(N+1, 0), right(N+1, 0);
    for (int i = 0; i < N; ++i) left[i+1] = GCD(left[i], a[i]);
    for (int i = N-1; i >= 0; --i) right[i] = GCD(right[i+1], a[i]);
    
    // 集計
    int res = 0;
    for (int i = 0; i < N; ++i) {
        // 左側
        int l = left[i];

        // 右側
        int r = right[i+1];

        // 更新
        chmax(res, GCD(l, r));
    }
    cout << res << endl;
}


Measured memory_bytes: 1408
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

import itertools

# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))
    stemp = input()
    s = "R"
    s += stemp
    s += "L"

    unhappy_edge = 0

    if s[1] == "L":
        unhappy_edge += 1
    if s[-2] == "R":
        unhappy_edge += 1

    unhappy_pair = 0
    prev = s[1]
    for i in range(2, n + 1):
        current = s[i]
        if prev == "R" and current == "L":
            unhappy_pair += 1
        prev = current

    temp = min(k, unhappy_pair)
    unhappy_pair -= temp
    k -= temp

    if k > 0:
        unhappy_edge = 1

    print(n - unhappy_pair * 2 - unhappy_edge)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"

	"strconv"
)

func parseInt(s string) int64 {
	i, _ := strconv.ParseInt(s, 0, 64)
	return i
}

func Run(in io.Reader, out io.Writer) error {
	sc := bufio.NewScanner(in)
	sc.Scan()
	n := parseInt(sc.Text())

	d := make(map[string]bool, n)
	for sc.Scan() {
		d[sc.Text()] = true
	}

	fmt.Fprintf(out, "%d\n", len(d))

	return nil
}

func main() {
	err := Run(os.Stdin, os.Stdout)

	if err != nil {
		log.Fatal(err)
	}
}


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

int main() {
  string s;
  cin >> s;
  int cntc = 0, ans = 0;
  rep(i, s.size()) {
    if ((s[i] == 'A') || (s[i] == 'G') || (s[i] == 'C') || (s[i] == 'T')) {
      cntc++;
      ans = max(ans, cntc);
    } else {
      cntc = 0;
    }
  }
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int ncnt[100007];

int main() {
  ll K,N,x=0;
  ll sum=0;
  priority_queue<ll> PQ;
  pair<ll,ll> dt[100007];   // first taste , second diffference
  cin >> N >> K;
  rep(i,N){
    cin >> dt[i].second >> dt[i].first;
  }
  sort(dt,dt+N);
  reverse(dt,dt+N);
  rep(i,K){    //うまい順に取っていく
    if(ncnt[dt[i].second]>0){
      PQ.push(-dt[i].first);
    }
    else{
      x++;
    }
    ncnt[dt[i].second]++;
    sum+=dt[i].first;
  }
  ll ma=sum+x*x;
  ll now=K;
  while(now<N){   //N個すべて検討するまで種類を増やしていく
    if(PQ.empty()){
      break;
    }
    sum -= -PQ.top();
    PQ.pop();
    Rep(i,now,N){
      if(ncnt[dt[i].second]==0){
        ncnt[dt[i].second]++;
        sum+=dt[i].first;
        x++;
        ma=max(ma,sum+x*x);
        now=i+1;
        break;
      }
    }
  }
  cout << ma << endl;
}

Measured memory_bytes: 2812
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll D[MAX_N];
vi sig[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> D[i];
	ll res = 0;
	rep(k, 1, N - 1) {
		if((N - 1) % k == 0) {
			ll tmp = 0;
			for(int i = 0; i < N - 1 - i; i += k) {
				tmp += D[i]; tmp += D[N - 1 - i];
				// debug(k, i, "omo", res, tmp);
				MAX(res, tmp);
			}
		}
		else {
			ll tmp = 0;
			for(int i = k; i < N - 1 - k; i += k) {
				tmp += D[i]; tmp += D[N - 1 - i];
				MAX(res, tmp);
			}
		}
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 14592
#include<bits/stdc++.h>
#define int long long
using namespace std;
const long long mod=1e9+7;
int n,k;
long long a[100003],jie[100003],ans,mi,ma;
long long poww(int x,int p)
{
	if(p==0)
		return 1;
	int tmp=poww(x,p/2);
	tmp=(tmp*tmp)%mod;
	if(p%2==1)
		tmp=(tmp*x)%mod;
	return tmp;
}
long long cc(int nn,int mm)
{
	return jie[nn]*poww(jie[nn-mm],mod-2)%mod*poww(jie[mm],mod-2)%mod;
}
signed main()
{
	scanf("%lld%lld",&n,&k);
	if(k==1)
	{
		cout<<0;
		return 0;
	}
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	jie[0]=1,jie[1]=1,k--;
	for(int i=2;i<=100000;i++)
		jie[i]=(jie[i-1]*i)%mod;
	for(int i=1;i<=n;i++)
	{
		if(i-1>=k)
			ma+=cc(i-1,k)%mod*a[i]%mod,ma%=mod;
		if(n-i>=k)
			mi+=cc(n-i,k)%mod*a[i]%mod,mi%=mod;
	}
	cout<<(ma-mi+mod)%mod;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
	string s; int c = 0, n;
	cin >>n>> s;
	for (int i = 0; i < s.length()-2; i++)
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			c++;
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

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

vector<PII> a;
LL dp[2005][2005];
int n;

LL solve(int l, int r){
	if (l > r) return 0;
	if (dp[l][r]) return dp[l][r];
	int i = n - (r - l + 1);
	return dp[l][r] = max(solve(l, r - 1) + a[i].first * (r - a[i].second), solve(l + 1, r) + a[i].first * (a[i].second - l));
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		a.push_back({x, i});
	}
	sort(a.rbegin(), a.rend());
	solve(0, n - 1);
	printf("%lld\n", dp[0][n - 1]);
	return 0;
}


Measured memory_bytes: 26012
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] t = new int[10];
		
		for(int i = 0; i < 10; i++){
			t[i] = sc.nextInt();
		}
		
		Arrays.sort(t);
		
		for(int i = 9; i >= 7; i--){
			System.out.println(t[i]);
		}
	}
}

Measured memory_bytes: 17168
import java.util.Scanner;
public class Main{
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		int ans = (a + b) * h / 2;
		System.out.println(ans);
	}
}

Measured memory_bytes: 35820
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;





void Main(){

  int N; cin>>N;

  vector<int> a;

  rep(i,N){
    int aa; cin>>aa;
    a.emplace_back(aa);
  }
  sort(ALL(a),greater<int>());
  int ans=0;
  rep(i,N){
    if(i%2==0)ans+=a[i];
    else ans-=a[i];
  }
  cout<< ans<<"\n";
}


//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

using namespace std;

using ll = long long;
using ld = long double;

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

ll sx, sy, tx, ty;

int main() {
  cin >> sx >> sy >> tx >> ty;
  REP(i, tx - sx) {
    cout << "R";
  }
  REP(i, ty - sy) {
    cout << "U";
  }
  REP(i, tx - sx) {
    cout << "L";
  }
  REP(i, ty - sy) {
    cout << "D";
  }
  cout << "D";
  REP(i, tx - sx + 1) {
    cout << "R";
  }
  REP(i, ty - sy + 1) {
    cout << "U";
  }
  cout << "L";
  cout << "U";
  REP(i, tx - sx + 1) {
    cout << "L";
  }
  REP(i, ty - sy + 1) {
    cout << "D";
  }

  // for (int i = 0; i < (tx - sx); i++) {
  //   cout << "R";
  // }
  // for (int i = 0; i < (ty - sy); i++) {
  //   cout << "U";
  // }
  // for (int i = 0; i < (tx - sx); i++) {
  //   cout << "L";
  // }
  // for (int i = 0; i < (ty - sy); i++) {
  //   cout << "D";
  // }
  // cout << "D";
  // for (int i = 0; i < (tx - sx) + 1; i++) {
  //   cout << "R";
  // }
  // for (int i = 0; i < (ty - sy) + 1; i++) {
  //   cout << "U";
  // }
  // cout << "L";
  // cout << "U";
  // for (int i = 0; i < (tx - sx) + 1; i++) {
  //   cout << "L";
  // }
  // for (int i = 0; i < (ty - sy) + 1; i++) {
  //   cout << "D";
  // }
  cout << "R" << endl;
}

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

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

  rep(i, n) {
    int tmp = i + 1;
    if (to_string(tmp).size() % 2 == 1) {
      ans++;
    }
  }

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

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
vector<string> arr;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    F0R(i, n)
    {
        string s;
        cin >> s;
        arr.pb(s);
    }
    vector<ll> sB, eA;
    vector<ll> bth;
    F0R(i, n)
    {
        if(arr[i][0] == 'B')
        {
            if(arr[i][arr[i].sz() - 1] == 'A')
            {
                bth.pb(i);
            }
            else sB.pb(i);
        }
        else
        {
            if(arr[i][arr[i].sz() - 1] == 'A') eA.pb(i);
        }
    }
    ll res = 0;
    if(bth.sz() == 0) res += min(eA.sz(), sB.sz());
    else
    {
        ll e = eA.sz();
        ll s = sB.sz();
        res += bth.sz() - 1;
        if(e > 0)
        {
            res++;
            e--;
        }
        if(s > 0)
        {
            res++;
            s--;
        }
        res += min(e, s);
    }
    F0R(i, n)
    {
        F0R(j, arr[i].sz() - 1)
        {
            if(arr[i][j] == 'A' && arr[i][j + 1] == 'B') res++;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
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)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N,M; cin >> N >> M;

    vector< pair<int,int> > ba(M);
    for(int i=0; i<M; ++i) cin >> ba[i].second >> ba[i].first;
    sort(ba.begin(), ba.end());

    int ans = 0;
    int pos = 0;
    while(pos < M){
        int nowb = ba[pos].first-1;
        while(pos<M && ba[pos].second <= nowb) ++pos;
        ++ans;
    }

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024