akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
int L = 1000000007;
using namespace std;
string s[60] = {};
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long sum = 0;
	long long cnt1 = 0, cnt2 = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (i % 2 == 0 && sum <= 0) {
			cnt1 += 1 - sum;
			sum = 1;
		}
		else if (i % 2 == 1 && sum >= 0) {
			cnt1 += 1 + sum;
			sum = -1;
		}
	}
	sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (i % 2 == 1 && sum <= 0) {
			cnt2 += 1 - sum;
			sum = 1;
		}
		else if (i % 2 == 0 && sum >= 0) {
			cnt2 += 1 + sum;
			sum = -1;
		}
	}
	cout << min(cnt1, cnt2) << endl;
	return 0;
}

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int N;
  cin >> N;
  vector<long int> a(N);
  long int sum = 0;
  bool even = true;
  for(int i = 0;i < N;i++){
    cin >> a.at(i);
    if(a.at(i) % 2 != 0) even = false;
  }
  if(even == false) cout << "first" << endl;
  else cout << "second" << endl;
}
 

Measured memory_bytes: 1024
#include <cstdio>
int x, y;
char s[105];
int main() {
	scanf("%*d%s", s);
	for(int i=0; s[i]; i++) {
		if(s[i]=='(') x++;
		else {
			if(x>0) x--;
			else y++, x=0;
		}
	}
	while(y--) putchar('(');
	printf("%s", s);
	while(x--) putchar(')');
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 10000
#define Q 500

int main() {

    int i, j, n, q, cnt=0;
    int x[N], y[Q];

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

	for(j=0; j<n; j++) {
            if(y[i] == x[j]) {
                cnt++;
                break;
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 2128
#include <stdio.h>
int main (void){
  int n, max, min, tmp = 0, a[100] = {};

  scanf("%d", &n);

  for(int i = 0; i < n; i++){
  scanf("%d", &a[i]);
  }

  for(int j = 0; j < n; j++){
    for(int i = 0; i < n; i++){
      if(a[i] < a[i+1]){//max
	tmp = a[i];
	a[i] = a[i+1];
	a[i+1] = tmp;
      }
    }
  }

  printf("%d\n", a[0]-a[n-1]);
  

  return 0;
}


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

typedef long long ll;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(0, min(B, D) - max(A, C)) << "\n";
}

Measured memory_bytes: 3636
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn main() {
    let n = read::<u32>();
    yn(n == 3 || n == 5 || n == 7);
}


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

#define ll long long
ll pattyCount(ll n, ll x) {
	if (n==0) {
		if (x>0) return 1;
		return 0;
	}

	ll l=1, r=1, m;
	for (int i=0; i<n; i++) r = r*2 + 3;
	m=(l+r)/2;
	
	if (x>m) {
		ll add=1;
		for (int i=0; i<n-1; i++) add = add*2 + 1;
		return add+1 + pattyCount(n-1, x-m);
	}
	else if (x<m)
		return pattyCount(n-1,x-1);
	else {
		ll add=1;
		for (int i=0; i<n-1; i++) add = add*2 + 1;
		return add+1;
	}

}
int main() {
	ll n, x; cin>>n>>x;
	cout << pattyCount(n,x) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String args[])
{
  Scanner sp=new Scanner(System.in);
   int a=sp.nextInt();
    int b=sp.nextInt();
    int l=0;
     int n=0;
    if(a<b)
    {
        l=b;
    }
    else
    {
        l=a;
    }
   for(int k=0;k<l;k++)
   {
      if(Math.abs(a-k)==Math.abs(b-k))
       {
           n=k;
       }
      
   }
   if(!(n==0))
   {
       System.out.println(n);
   }
   else{
       System.out.println("IMPOSSIBLE");
   }
   
   

}
}


Measured memory_bytes: 21716
import math
N, D = map(int, input().split())
X = []
res = 0
for _ in range(N):
  X.append(list(map(int, input().split())))

for i in range(N - 1):
  for j in range(i + 1, N):
    temp = 0
    for k in range(D):
      temp += (X[i][k] - X[j][k]) ** 2
      
    temp = math.sqrt(temp)
    if temp.is_integer() == True:
      res += 1
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <cctype>
#include <ctype.h>
#define ll long long
char toupper(char c);
char toupper(char c)
{
    return (c - 0x20);
}

using namespace std;
int main()
{
    int a, b, c;
  cin >> a>>b>>c;
    if(a+b+c<=21){
        cout << "win" << endl;
    }
    else{
        cout << "bust" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
def main():
  ans = [[0]*W for _ in range(H)]
  color = 0
  num = 0
  for i in range(H):
    if i % 2 == 0:
      for j in range(W):
        ans[i][j] = color+1
        num += 1
        if num == a[color]:
          color += 1
          num = 0
    else:
      for j in range(W-1, -1, -1):
        ans[i][j] = color+1
        num += 1
        if num == a[color]:
          color += 1
          num = 0
  for i in range(H):
    print(*ans[i])
  
if __name__ == "__main__":
  main()        

Measured memory_bytes: 3920
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
using LP = pair<ll,ll>;
using P = pair<ll,int>;
int n;
ll inf = 1e18;
vector<ll> solve(int n, vector<int> x, vector<int> y, vector<int> p){
    //道路を選んだ集落に関してコストの前計算
    vector<vector<ll>> xcost(1<<n, vector<ll>(n)), ycost(1<<n, vector<ll>(n));
    rep(i, 1<<n){
        rep(j, n){
            xcost[i][j] = abs(x[j]);
            ycost[i][j] = abs(y[j]);
            rep(k, n){
                if ((i>>k) &1){
                   xcost[i][j] = min(xcost[i][j], (ll)abs(x[j]-x[k]));
                   ycost[i][j] = min(ycost[i][j], (ll)abs(y[j]-y[k]));
                }
            }
        }
    }
    rep(i, 1<<n) rep(j, n) {
        xcost[i][j] *= p[j];
        ycost[i][j] *= p[j];
    }

    //各状態に関するmin
    vector<ll> ans(n+1, inf);
    rep(i, 1<<n){
        int cnt = 0;
        rep(j, n){
            if (i>>j &1) ++cnt;
        }
        //iの部分集合に関するmin
        repd(j, i+1){
            j &= i;
            ll cost = 0;
            rep(k, n){
                if (!((i>>k) & 1)){
                    cost += min(xcost[j][k], ycost[i-j][k]);
                }
            }
            ans[cnt] = min(ans[cnt], cost);
        }
    }
    return ans;
}

int main()
{
    cin >> n;
    vector<int> x(n), y(n), p(n);
    rep(i, n) cin >> x[i] >> y[i] >> p[i];
    vector<ll> ans = solve(n, x, y, p);
    rep(i, n+1) cout << ans[i] << endl;
}

Measured memory_bytes: 12984
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int n;
double w, h;

int main() {
    while ( scanf("%d,%lf,%lf", &n, &w, &h) != EOF ) {
        double bmi = w / (h * h);
        if (bmi >= 25.0) cout << n << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int n;
    cin >> n;
    vector<vector<ll>> a(n, vector<ll>(n));
    rep(i, n){
        rep(j, n) cin >> a[i][j];
    }

    //存在判定
    auto d = a;
    rep(k, n){
        rep(i, n){
            rep(j, n){//最短路の更新があったら条件に反する
                if(chmin(d[i][j], d[i][k] + d[k][j])){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }


    ll ans = 0;
    rep(i, n){
        rep(j, n){
            bool ok = true;
            rep(k, n){
                if(k == i || k == j) continue;
                if(a[i][j] >= a[i][k]+a[k][j]) ok = false;
            }
            if(ok){
                ans += a[i][j];
            } 
        }
    }

    cout << ans/2 << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
        int n;
        cin>>n;
        int arr[n][3];
        for(int i=0; i<n; i++)
        {
                for(int j=0; j<3; j++)
                        cin>>arr[i][j];
        }
        int dp[n][3];
        for(int i=0; i<3; i++) dp[0][i]=arr[0][i];
        for(int i=1; i<n; i++)
        {
                for(int j=0; j<3; j++)
                {
                        dp[i][j] = 0;
                        for(int k=0; k<3; k++)
                        {
                                if(k!=j)
                                {
                                        dp[i][j] = max(dp[i-1][k] + arr[i][j], dp[i][j]);
                                }
                        }
                }
        }
        cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
        return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n] , b[n] , c[n];
    for( int i = 0 ; i < n ; i++ ) cin >> a[i];
    for( int i = 0 ; i < n ; i++ ) cin >> b[i];
    for( int i = 0 ; i < n ; i++ ) cin >> c[i];
    sort( a , a + n );
    sort( b , b + n );
    sort( c , c + n );
    ll x = 0 , d = 0 , e = 0;
    for( int i = 0 ; i < n ; i++ ) {
        d = 1ll * ( lower_bound( a , a + n , b[i] ) - a );
        e = 1ll * ( n - (upper_bound( c , c + n , b[i] ) - c ) );
        x += d * e;
    }
    cout << x;
}



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

#define llint long long int

using namespace std;

int main(){
  string s;
  cin >> s;
  int sum = 0;
  int len = s.length();
  for(int i = 0; i < len; i++)sum+=(s[i]-'0');
  llint n = 0, j = 0;
  for(int i = len-1; i >=0; i--){
  	n +=(s[i]-'0')*pow(10, j);
    j++;
  }
  if(n%sum)
    cout << "No";
  else
    cout << "Yes";
  return 0;
}

Measured memory_bytes: 384
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <bitset>
#include <cmath>
#include <tuple>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 型
#define ll long long

// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// for文
#define forn(i, size) for (long long(i) = 0; (i) < (size); (i)++)
#define for0(size) for (long(i) = 0; (i) < (size); (i)++)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length, type_name) sort(array, array + length, std::greater<type_name>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#define println(str) cout << str << endl;

#pragma endregion

#pragma region Utility
#pragma region 最大公約数
ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}
#pragma endregion

#pragma region 最小公倍数
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
#pragma endregion

#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion

#pragma region 連想配列のkeyが存在するか
template <typename T>
bool containsKey(map<string, T> map, string key)
{
    if (map.count(key) == 0)
    {
        return false;
    }
    return true;
}
#pragma endregion

#pragma region 素数判定
bool isPrime(ll num)
{
    if (num <= 1)
    {
        return false;
    }
    for (int i = 2; i < num / 2 + 1; i++)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    int A, B, C;
    cin >> A >> B >> C;

    if (A + B + C >= 22)
    {
        println("bust");
    }
    else
    {
        println("win");
    }
}


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

int N, M, L;
vector<double> P, T, V;
double F[51];
double C[51][51];

int main(){
    cout.precision(16);
    cout.setf(ios::fixed);
    
    F[0] = 1;
    for(int i=1; i<51; i++)
        F[i] = F[i-1] * i;
    for(int i=0; i<51; i++)
        for(int j=0; j<=i; j++)
            C[i][j] = F[i] / F[i-j] / F[j];
    
    cin >> N >> M >> L;
    P.resize(N); T.resize(N); V.resize(N);
    for(int i=0; i<N; i++)
        cin >> P[i] >> T[i] >> V[i];
    
    for(int i=0; i<N; i++){
        double ans = 0;
        for(int k=0; k<=M; k++){ //????????????i????????????????????????
            double ti = L / V[i] + T[i]*k;
            double ttans = 1;
            for(int j=0; j<N; j++) if(i != j){
                double tans = 0;
                for(int l=0; l<=M; l++){ //????????????j????????????????????????
                    double tj = L / V[j] + T[j]*l;
                    if(ti < tj){
                        tans += pow(P[j]/100, l) * pow(1-P[j]/100, M-l) * C[M][l];
                    }
                }
                ttans *= tans;
            }
            ans += ttans * pow(P[i]/100, k) * pow(1-P[i]/100, M-k) * C[M][k];
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}


std::vector<int> V;
int main() {
    ////////////input//////////////////
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int a; cin >> a;
        V.push_back(a);
    }
    ////////////compute////////////////
    int ans = 0;
    

    ////////////操作Aと操作Bのすべての組み合わせを試す//////////////
    for (int i = 0; i <= min(k, n); i++) {
        for (int j = 0; i + j <= min(k, n); j++) {
    //////////////////////////////////////////////////////////        
            
            vector<int> v;///////ansを計算するための配列////////


            for (int x = 0; x < i; x++) v.push_back(V[x]);
            for (int x = 1; x <= j; x++)  v.push_back(V[n - x]);
            
            sort(v.rbegin(), v.rend());
            
            int k2 = k - i - j;
            while (k2 > 0 && !v.empty() && v.back() < 0) {
                v.pop_back();
                k2--;
            }
            
            int sum = 0;
            for (int x : v) sum += x;
            
            ans = max(ans, sum);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
#define INF (1 << 30)
#define INFL (1ll << 60ll);
#define mod 1000000007

int a, b;

signed main()
{
    cin >> a >> b;
    if(a == b){
        cout << a << endl;
        return 0;
    }
    if(a == 0){
        if(b % 2 == 0)b = ((b / 2) % 2) ^ b;
        else b = ((b + 1) / 2) % 2;
        cout << b << endl;
        return 0;
    }
    if((a - 1) % 2 == 0)a = (((a - 1) / 2) % 2) ^ (a - 1);
    else a = (a / 2) % 2;
    if(b % 2 == 0)b = ((b / 2) % 2) ^ b;
    else b = ((b + 1) / 2) % 2;
    cout << (a ^ b) << endl;


    return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    if(a == 3 || a == 5 || a == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scan = FastScanner()
    val x = scan.next()
    val que = ArrayDeque<Char>()
    for (i in x.indices) {
        val head = que.peek()
        if (head == null) {
            que.push(x[i])
        } else {
            if (head == 'S' && x[i] == 'T') {
                que.pop()
            } else {
                que.push(x[i])
            }
        }
    }
    println(que.size)
}

class FastScanner {
    private val printable = 33..126
    val `in` = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = `in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun nextInt(): Int {
        val nl = nextLong()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun nextDouble(): Double {
        return next().toDouble()
    }
}

Measured memory_bytes: 35436
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
using namespace std;

#define llong long long

int x;

int main(){
  cin >> x;
  llong a[35 * 9];
  int k = 0;
  for (int i = 1; i <= 35; i++){
    for (int j = 2; j <= 10; j++){
      a[k] = pow(i, j);
      k++;
    }
  }

  sort(a, a + 35 * 9);

  llong ans;

  for (int i = 35 * 9 - 1; i >= 0; i--){
    if (x >= a[i]){
      ans = a[i];
      break;
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    ll h, w, n;
    cin >> h >> w >> n;
    ll M = max(h, w);
    ll o = M, cnt = 1;
    while(1){
        if(o >= n) break;
        o += M;
        cnt++;
    }
    cout << cnt << "\n";
}

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

    solve();
    return 0;
}
 


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

using namespace std ;
typedef long long ll;
int main(){

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

if(k>=n)
    cout<<0<<endl;

    else{
        sort(h.begin(),h.end());
        ll sum=0;
        for(ll i=0;i<n-k;i++)
        sum+=h[i];

        cout<<sum<<endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;
 
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');
 
const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;
 
struct mat {
    ll h, w;
    vvll d;
    mat() {}
    mat(ll h, ll w, ll v=0): h(h), w(w), d(h, vll(w, v)){}
    vll& operator[] (ll i) {return d[i];}
    const vll& operator[] (int i) const { return d[i];}
    void fil(ll v=0) { REP(i,h)REP(j,w) d[i][j] = v;}
    void unit() { REP(i,h)REP(j,w) d[i][j] = (i==j);}
    mat operator+(const mat& a) const { // same size
        mat res(h,w);
        REP(i,h)REP(j,w) {
            res[i][j] = d[i][j]+a[i][j];
            if (res[i][j]>=MOD) res[i][j] -= MOD;
        }
        return res;
    }
    mat operator-(const mat& a) const { // same size
        mat res(h,w);
        REP(i,h)REP(j,w) {
            res[i][j] = d[i][j]-a[i][j];
            if (res[i][j]<0) res[i][j] += MOD;
        }
        return res;
    }
    mat operator*(const mat& a) const { // w = a.h
        mat res(h,a.w);
        REP(i,h)REP(k,w)REP(j,a.w) {
            res[i][j] += d[i][k]*a[k][j]%MOD;
            if (res[i][j]>=MOD) res[i][j] -= MOD;
        }
        return res;
    }
    mat power(ll a) { // h = w
        if (a == 0) {
            mat res(h,w); res.unit();
            return res;
        }
        mat res = power(a/2);
        res = res*res;
        if (a&1) res = res*(*this);
        return res;
    }
};
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    mat a(n,n);
    REP(i, n) REP(j, n) cin >> a[i][j];
    a = a.power(k);
    ll ans = 0;
    REP(i, n) REP(j, n) {
        ans += a[i][j];
        if (ans >= MOD) ans -= MOD;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
bitset<201000>a,b;
int n,m,u,v;
int main(){
	cin>>n>>m;
	for (int i=0;i<m;i++){
		cin>>u>>v;
		if (u==1){
			a[v]=1;
		}
		if (v==n){
			b[u]=1;
		}
	}
	a&=b;
	if (a.count()){
		printf("POSSIBLE");
	}else{
		printf("IMPOSSIBLE");
	}
}

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

string S[100000];
set<string> ng;

bool dfs(int i, int n, string& p) {
	if(i == n) {
		return ng.count(p) == 0;
	}
	for(int c = 0; c < 26; c++) {
		p.push_back('a' + c);
		if(dfs(i + 1, n, p)) return true;
		p.pop_back();
	}
	return false;
}

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

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

	for(int i = 1; ; i++) {
		ng.clear();
		for(int j = 0; j < N; j++) {
			for(int k = 0; k + i <= S[j].size(); k++) {
				ng.insert(S[j].substr(k, i));
			}
		}
		string ans;
		if(dfs(0, i, ans)) {
			cout << ans << endl;
			break;
		}
	}
}

Measured memory_bytes: 41472
X, K, D = map(int, input().split())
ref = abs(X) // D
cnt = K - ref
if abs(X) > K*D:
    print(abs(abs(X)-K*D))
elif cnt % 2 == 0:
    print(abs(abs(X)-D*ref))
else:
    print(abs(abs(X)-D*(ref+1)))

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    char prev = s[0];
    int count = 0;
    rep(i, n){
        if(i==0) continue;
        if(s[i]!=prev){
            count++;
            prev = s[i];
        }
    }

    cout << count  << endl;
    return 0;
}

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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int arr[n];
	bool dp[k + 1];
	for(int i = 0; i < n; i++) cin >> arr[i];
	memset(dp, 0, sizeof(dp));
	for(int i = 0; i <= k; i++){
		for(int j = 0; j < n; j++){
			if(i - arr[j] >= 0 && dp[i - arr[j]] == 0){
				dp[i] = 1;
				break;
			} 
		}
	}
	if(dp[k]) cout << "First" << endl;
	else cout << "Second" << endl;
}

Measured memory_bytes: 384
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: String,
    }
    let mut alpha = [0; 26];

    for c in s.bytes() {
        alpha[(c - b'a') as usize] += 1;
    }

    for (i, c) in alpha.iter().enumerate() {
        if *c == 0 {
            println!("{}", (i as u8 + b'a') as char);
            return;
        }
    }
    println!("None");
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;
typedef long long ll;
ll a,b,c,i,j,k,n,m,t;

int main(){
	scanf("%lld%lld%lld",&a,&b,&k);
	c=k;
	k=k-a;
	a=a-c;
	if(a<=0){
		a=0;
		b=b-k;
        if(b<0)
            b=0;
	}
	printf("%lld %lld",a,b);
	return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

class RMQ {
    int n;
    vector<int> dat;
    
public:
    RMQ(int _n) {init(_n);}
    RMQ(){}
    
    void init(int _n) {
        n=1;
        while (n<_n) n*=2;
        dat.resize(2*n-1, INT_MAX);
    }
    
    void update(int k, int a) {
        k += n-1;
        dat[k] = a;
        while (k>0) {
            k = (k-1)/2;
            dat[k] = min(dat[k*2+1], dat[k*2+2]);
        }
    }
    
    int size() {
        return n;
    }
    
    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return INT_MAX;
        if (a <= l && r <= b) return dat[k];
        else {
            int vl = query(a, b, k*2+1, l, (l+r)/2);
            int vr = query(a, b, k*2+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }

    int query(int l, int r)
    {
        return query(l, r, 0, 0, n);
    }
};
RMQ R;

int main()
{
    int N, Q;
    cin >> N >> Q;
    R.init(N);
    while (Q--) {
        int C, X, Y;
        cin >> C >> X >> Y;

        if (C == 0) {
            R.update(X, Y);
        } else {
            cout << R.query(X, Y+1) << endl;
        }
    }
}

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

int main() {
  int N; cin >> N;
  int s[N]; rep(i,0,N) cin >> s[i];
  bool dp[10001]; rep(i,0,10001) dp[i] =false;
  int ans =0;
  
  dp[0] = true;
  rep(i,0,N) {
    vector<int> tmp;
    rep(j,0,10001) if (dp[j]) tmp.push_back(j);
    for (auto a: tmp) dp[a+s[i]] = true;
  }
  
  for (int i =10000; i>0; i--) {
    if (dp[i] && i % 10 != 0) {
      ans = i; break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <stdlib.h>
using namespace std;

int main(){
	int H, W;
	cin >> H >> W;
	char masu[H][W];
	string line;
	int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			char in;
			cin >> in;
			masu[i][j] = in;
		}
	}

	/*
	   cout << "-------------" << endl;
	   for(int i = 0; i < H; i++){
	   for(int j = 0; j < W; j++){
	   cout << masu[i][j];
	   }
	   cout << endl;
	   }
	   */

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(masu[i][j] == '#'){
				int count = 0;
				for(int k = 0; k < 4; k++){
					int nx = j + dx[k];
					int ny = i + dy[k];
					if(0 <= nx && nx < W && 0 <= ny && ny < H){
						if(masu[ny][nx] == '.'){
							count++;
						}
					}
				}
				if(count == 4){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  long long A[N];
  long long tmp = 0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    if(i%2 == 0){
      tmp += A[i];
    }else{
      tmp -= A[i];
    }
  }
  long long x1 = tmp / 2;
  cout << x1 * 2;
  long long x = x1;
  for(int i=0; i<N-1; i++){
    cout << ' ' << (A[i] - x) * 2;
    x = A[i] - x;
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 2048
#include<stdio.h>
#define N 256

int main(){
  int i=0,j,k=0,m,n;
  int H[N],W[N];
  while(1){
    scanf("%d %d",&H[i],&W[i]);
    if(H[i]==0 && W[i]==0){
      break;
    }
    i++;
  }
  for(m=0;m<i;m++){
    for(j=0;j<H[m];j++){
      for(n=0;n<W[m];n++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1000
#include <atcoder/all>
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
using namespace atcoder;

int main(void) {
  lld n, m;
  cin >> n >> m;
  dsu d(n);
  for (lld i = 0; i < m; i++) {
    lld a, b;
    cin >> a >> b;
    d.merge(a - 1, b - 1);
  }

  set<lld> s;
  for (lld i = 0; i < n; i++) {
    s.insert(d.leader(i));
  }

  cout << s.size() - 1 << "\n";
}

Measured memory_bytes: 7624
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=998244353;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2LL*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
string s1, s2, s3;

int main(void)
{
	cin>>s1>>s2>>s3;
	cout<<s1[0]<<s2[0]<<s3[0];
	return 0;
}
// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

			String str = reader.readLine();
			String[] arr = str.split(" ");
			int a = Integer.parseInt(arr[0]);
			int b = Integer.parseInt(arr[1]);
			int c = Integer.parseInt(arr[2]);
			int cnt = 0;
			
			for (int i = a; i <= b; i++) {
				if (c % i == 0) {
					cnt++;
				}
			}
			System.out.println(cnt);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Measured memory_bytes: 24428
#include<bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
const int N = 3000010;
inline int read()
{
	register char cc = getchar(); register int cn(0), flus(1);
	while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus;
}
set<int> s;
signed main()
{
	int n = read();
	bool ans(1);
	while(n --)
	{
		int tmp = read();
		if(s.find(tmp) != s.end())
		{
			ans = 0;
			break; 
		} 
		s.insert(tmp);
	}
	if(ans) printf("YES\n");
	else printf("NO\n");
	return 0;
}

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


void solve(std::string S){
    ll ans = 0;
    if (S == "SUN") ans = 7;
    if (S == "MON") ans = 6;
    if (S == "TUE") ans = 5;
    if (S == "WED") ans = 4;
    if (S == "THU") ans = 3;
    if (S == "FRI") ans = 2;
    if (S == "SAT") ans = 1;
    
    cout << ans << endl;
    
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main() {
  string s; cin >> s;
  if(s[s.size()-1] == 's') cout << s << "es" << endl;
  else cout << s << "s" << endl;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------
const int MAX = 1000000 ;
long long fac[MAX], finv[MAX], inv[MAX] ;

void pre(){
    fac[0] = fac[1] = 1 ;
    finv[0] = finv[1] = 1 ;
    inv[1] = 1 ;
    for(int i=2;i<MAX;i++){
        fac[i] = fac[i-1]*i%MOD ;
        inv[i] = MOD - inv[MOD%i]*(MOD/i) %MOD ;
        finv[i] = finv[i-1]*inv[i]%MOD ;
    }
}

long long nCk(int n, int k){
    if(n<k){
        return 0 ;
    }
    if(n<0 || k<0){
        return 0 ;
    }
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD ;
}
//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();


    ll n, k ;
    cin >> n >> k ;
    pre() ; 
    vll a(n) ;
    REP(i,n){
        cin >> a[i] ;
    }
    sort(ALL(a)) ;
    ll ans = 0 ;
    for(ll i=n-1;i>=k-1;i--){
        ans += nCk(i,k-1)*(a[i]-a[n-1-i])%MOD ;
        ans += MOD ;
        ans %= MOD ;
    }
    cout << ans <<endl;






    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    string s = to_string(N);
    int n=0;
    rep(i, s.size()){
        n += s[i] - '0';
    }

    if(N % n){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
s1=input()
s2=input()
n=len(s1)
m=len(s2)
# import numpy as np
dp=[[0 for i in range(m+1)]for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        if s1[i-1]==s2[j-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
# print(np.array(dp))
ans=""
# print(dp[-1][-1])
i=n
j=m
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans=s1[i-1]+ans
        i-=1
        j-=1
print(ans)

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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    	ll x, n;
	cin >> x >> n;
	map<int, int> seen;
	for(int i = 0, a; i < n; i++) {
		cin >> a;
		seen[a] = 1;
	}
	ll lo = 1e9, ans;
	for(int i = -2; i <= 102; i++) {
		if(!seen[i] && lo > abs(x - i)) {
			lo = abs(x-i);
			ans = i;
		}
	}
	cout << ans << "\n";
    return 0;
}

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

const int N = 100010;

int n, m, deg[N], q[N], f[N];
int cnt, head[N];
struct edge { int to, nxt; } e[N];

void ins(int u, int v) {
	e[++cnt] = (edge) { v, head[u] };
	head[u] = cnt;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1, u, v; i <= m; ++i) {
		scanf("%d%d", &u, &v);
		ins(u, v); deg[v]++;
	}
	int l = 1, r = 1;
	for(int i = 1; i <= n; ++i) {
		if(!deg[i]) q[r++] = i;
	}
	while(l < r) {
		int u = q[l++];
		for(int i = head[u]; i; i = e[i].nxt) {
			int v = e[i].to;
			f[v] = max(f[v], f[u] + 1);
			deg[v]--;
			if(!deg[v]) q[r++] = v;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n ;++i) ans = max(ans, f[i]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2560