akhauriyash/Code-Regression huggingface dataset:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    for _ in range(K):
        new = [0] * N
        imos = [0] * N
        for i, a in enumerate(A):
            imos[max(0, i-a)] += 1
            if i+a+1 <= N-1:
                imos[i+a+1] -= 1
        for i in range(N):
            new[i] = new[i-1] + imos[i]
        A = new
        if sum(A) == N * N:
            break
    print(*A)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long LL;

const int N = 100010;

int n, a[N], k;

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

    int res = 0;
    for(int i = 0; i < k; i++)
        res += a[n - 1 - i];

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))
count = len(list(filter(lambda A: A < 0, As)))
As2 = list(map(abs, As))
As2.sort()
#print(count, As2)
if count%2 == 0:
  r = sum(As2)
else:
  r = sum(As2)-2*As2[0]
print(r)


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

using namespace std;

typedef long long ll;

int h, w, inittial_black_sqs = 0, k;
int matrix[8][8];
int erased_bs = 0;

int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    char scanner;
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> scanner;
            if (scanner == '#')
            {
                inittial_black_sqs++;
                matrix[i][j] = 1;
            }
                
        }
    }

    int ans = 0;
    for (int u = 0; u < ( 1 << h); u++){
        for (int v = 0; v < ( 1 << w); v++){
            erased_bs = 0;
            for (int i = 0; i < h; i++){
                for (int j = 0; j < w; j++){
                    if (((1 << i) & u) || ((1 << j) & v)){
                        erased_bs += matrix[i][j];
                        
                    }
                }
            }
            if (inittial_black_sqs - erased_bs == k)
                ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  vector<int> v(3) ;
  rep(i,3) cin >> v.at(i) ;
  sort(all(v)) ;
  int ans = 0 ;
  
  while(v.at(2) - v.at(0) >1){
    v.at(0) += 2 ;
    ans ++;
  }
  
   while(v.at(2) - v.at(1) >1){
    v.at(1) += 2 ;
    ans ++;
  }
  sort(all(v)) ;
  
  if(v.at(0) == v.at(1)){
    if(v.at(1) != v.at(2)) ans ++ ;
  }
  
  if(v.at(0) != v.at(1)) ans += 2 ;
  
  cout <<ans ;
    
  
      
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#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)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  M color;
  REP(i,n){
    IN(x);
    color[x/400]++;
  }
  for(auto p: color){
    if(p.first < 8) y++;
    else z += p.second;
  }
  if(y>=1) cout << y << " " << y + z << endl;
  else cout << 1 << " " << z << endl;
}

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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  vector<ll> a(n + 1);
  vector<ll> b(n);
  rep(i, n + 1) {
    cin >> a[i];
  }
  rep(i, n) {
    cin >> b[i];
  }
  rep(i ,n) {
    ll min1 = min(a[i], b[i]);
    a[i] -= min1;
    b[i] -= min1;
    ans += min1;

    ll min2 = min(a[i + 1], b[i]);
    a[i + 1] -= min2;
    b[i] -= min2;
    ans += min2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include <complex>
#include <iomanip>
using namespace std;

int main()
{
	double x[3], y[3];
	complex<double> a, b, c;
	double angle;
	double r, i;

	cout<<setprecision(6);
	cout<<setiosflags(ios::fixed);
	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2]) != EOF) {
		a = complex<double>(x[0], y[0]);
		b = complex<double>(x[1], y[1]);
		c = complex<double>(x[2], y[2]);

		c -= a;
		angle = arg(b-a)*2.0;
		r = cos(angle)*c.real()+sin(angle)*c.imag();
		i = sin(angle)*c.real()-cos(angle)*c.imag();
		cout<<r+a.real()<<" "<<i+a.imag()<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>                                                        
int main(){                                                                     
  long l, r;                                                                    
  std::cin >> l >> r;                                                           
                                                                                
  if (r > l + 2018) r = l + 2018;                                               
  long ans = 2019;                                                              
  for (long i = l; i <= r - 1; ++i) {                                           
    for (long j = i + 1; j <= r; ++j) {                                         
      long x = ((i%2019)*(j%2019))%2019;                                        
      if (x < ans) ans = x;                                                     
    }                                                                           
  }                                                                             
  std::cout << ans;                                                             
  return 0;                                                                     
}

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

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    int A[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> A[i][j];
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int b;
            cin >> b;
            A[i][j] -= b;
        }
    }

    bool dp[H][W][80*(H+W)+1];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            for(int v = 0; v < 80*(H+W)+1; v++){
                dp[i][j][v] = false;
            }
        }
    }
    dp[0][0][abs(A[0][0])] = true;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            for(int v = 0; v < 80*(H+W)+1; v++){
                if(i-1 >= 0){
                    dp[i][j][v] = dp[i-1][j][abs(v - A[i][j])] | dp[i-1][j][abs(v + A[i][j])];
                }
                if(j-1 >= 0){
                    dp[i][j][v] = dp[i][j][v] | dp[i][j-1][abs(v - A[i][j])] | dp[i][j-1][abs(v + A[i][j])];
                }
            }
        }
    }

    for(int i=0; i<80*H*W+1; i++){
        if(dp[H-1][W-1][i]){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, p;
  cin >> n >> p;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  ll even = 0, odd = 0;
  for (ll i = 0; i < n; i++) {
    if (a[i] % 2 == 0) even++;
    else odd++;
  }
  if (p == 0) {
    ll ans = 0;
    ll subans = 1;
    ans += subans;
    for (ll i = 2; i <= odd; i += 2) {
      subans *= (odd - i + 2) * (odd - i + 1);
      subans /= i * (i - 1);
      ans += subans;
    }
    ans *= pow(2, even);
    cout << ans << endl;
  }
  else {
    ll ans = 0;
    ll subans = odd;
    ans += subans;
    for (ll i = 3; i <= odd; i += 2) {
      subans *= (odd - (i - 2)) * (odd - (i - 1));
      subans /= i * (i - 1);
      ans += subans;
      //cout << subans << endl;
    }
    ans *= pow(2, even);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
// AOJ 2656 Taps
// 2018.4.6 bal4u

#include <stdio.h>
#include <string.h>
#include <math.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define EPS 1e-6
#define EQ(a,b)  (fabs((a)-(b))<EPS)

int T, D, ta, tb, da, db;

int ok(int a, int b)
{
	int t = a*da + b*db;
	return t >= 1 && t <= D;
}

double calc2()
{
	int a, b;
	double s, t, ans;

	s = (double)(ta-tb)/(ta-T) * db;
	ans = 100;
	for (b = 1; ; b++) {
		t = b*s;
		if (!EQ(t, 1) && t <= 1) continue;
		if (!EQ(t, D) && t >= D) break;
		t = (double)(T-tb)*db*b / ((ta-T)*da);
		a = (int)t;
		if (a < 0) continue;
		if (!ok(a, b)) continue;
		t = ta*a*da + tb*b*db, t /= a*da+b*db, t = fabs(T-t);
		if (t < ans) ans = t;
		if (!ok(++a, b)) continue;
		t = ta*a*da + tb*b*db, t /= a*da+b*db, t = fabs(T-t);
		if (t < ans) ans = t;
	}
	return ans;
}

double calc()
{
	int x;
	double t, ans;

	if (ta == tb) return fabs(T-ta);
	if (ta == T || tb == T) return 0;
	t = ta; if (t < tb) t = tb;
	if (T > t) return T-t;
	t = ta; if (t > tb) t = tb;
	if (T < t) return t-T;
	ans = fabs(T-ta), t = fabs(T-tb);
	if (t < ans) ans = t;

	t = calc2();
	if (t < ans) ans = t;
	x = ta, ta = tb, tb = x;
	x = da, da = db, db = x;
	t = calc2();
	if (t < ans) ans = t;
	return ans;
}

int main()
{
	T = in(), D = in();
	ta = in(), tb = in();
	da = in(), db = in();
	printf("%.10lf\n", calc());
	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define msg(x) debug() << x
#define int long long
#define LL __int128_t
const int xx = 2e5;
const int MOD = 1e9 + 7;

int first(int n){
  int fst;
  while(n){
    fst = n;
    n/=10;
  }
  return fst;
}
int last(int n){
  return n % 10;
}
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);
  int n;
  cin >> n;
  map<pair<int,int> , int>cnt;
  for(int i=1;i<=n;i++){
    int f = first(i); int l = last(i);
    cnt[{f,l}]++;
  }

  int ans = 0;

    for(int i=1;i<=n;i++){
    int f = first(i); int l = last(i);
     ans += cnt[{l,f}];
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int n;
  cin >> n;
  ll left = 1,right = 1;
  rep(i,n){
    ll a,b;
    ll key = 0;
    cin >> a >> b;
    if(left % a == 0 && right % b == 0){
      //cout << "a" << endl;
      key = max(left/a,right/b);
    }
    else if(left % a == 0){
      //cout << "b" << endl;
      key = max(left/a,right/b+1);
    }
    else if(right % b == 0){
      //cout << "c" << endl;
      key = max(left/a+1,right/b);
    }
    else{
      //cout << "d" << endl;
      key = max(left/a+1,right/b+1);
    }
    left = a*key;
    right = b*key;
    //cout << key << endl;
    //cout << left << " " << right << endl;
  }
  cout << left + right << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  int n;
  cin >>n;
  int g=n/2;
  cout << g*(n-g) << endl;

}

Measured memory_bytes: 3636
N,Q=map(int, input().split())
A=[input().split() for _ in range(N)]
time=0
while True:
    a=A.pop(0)
    n=a[0]
    v=int(a[1])-Q
    if v <= 0:
        time+=Q+v
        print(f'{n} {time}')
    else:
        A.append([n, v])
        time+=Q
    if len(A) <= 0: break


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

int main() {
  int n, y; cin >> n >> y;
  rep(i,n+1) {
    rep(j,n+1-i) {
      int k = (y - (10000*i + 5000*j)) / 1000;
      if (k >= 0 && k == n-(i+j)) {
        cout << i << " ";
        cout << j << " ";
        cout << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 3636
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N, K = map(int, readline().split())
    d = []
    A = []
    for _ in range(K):
        d.append(int(readline()))
        A.append(readline().decode().split())
    ans = 0
    for n in range(1,N+1):
        cnt = 0
        for i in range(len(A)):
            cnt += A[i].count(str(n))
        if cnt == 0:
            ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()


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

int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<int>a(n);
    rep(i,n){
        if(s[i]=='R')a[i]=0;
        if(s[i]=='G')a[i]=1;
        if(s[i]=='B')a[i]=2;
    }
    vector<ll>cnt(3);
    rep(i,n)cnt[a[i]]++;
    ll ans=1;
    rep(i,3)ans*=cnt[i];
    rep(j,n)rep(i,j){
        int k=j+(j-i);
        if(k<n){
            if(a[i]==a[j])continue;
            if(a[i]==a[k])continue;
            if(a[k]==a[j])continue;
            ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>

int main() {
	int  a, b;
	double c, d;
	std::cin >> a >> b;
	c = a; d = b;
	std::cout << a/b  << " " << a%b << " " << std::fixed << std::setprecision(8) << c/d << std::endl;

}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int k,x; cin >> k >> x;
    if(x > 500*k) No;
    else Yes;
    

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split());
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
ab.append([0, 1])
i = 0
ans = 0
while m - ab[i][1] >= 0:
  ans += ab[i][0] * ab[i][1]
  m -= ab[i][1]
  i += 1
print(ans + ab[i][0] * m)

Measured memory_bytes: 29024
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int cnt;
int main()
{
int a;
int b;
cin>>a>>b;
if(b==100)a*=1000;
if(b/10>=1 and b/10<10)a*=100;
if(b/10==0)a*=10;
int c=a+b;
for(int i=1;i<=c;i++)
{
if(i*i==c)cnt++;}
if(cnt>=1)cout<<"Yes";
else cout<<"No";
system("pause");
return 0;
}

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

int main() {
  int n, m, c; cin >> n >> m >> c;
  vector<int> B(m);
  int ans = 0;
  rep(i,m) cin >> B[i];
  rep(i,n) {
    int sum = c;
    rep(j,m) {
      int aj; cin >> aj;
      sum += aj*B[j];
    }
    if (sum > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int N, M, X; cin >> N >> M >> X;
    vector<int> v(M);
    for (int i = 0; i < M; i++) cin >> v[i]; 
    auto iter = lower_bound(v.begin(),v.end(),X);
    long cost1 = 0;    
    for (auto i = iter; i != v.end(); i++) cost1 ++;
    long cost2 = 0;
    for (auto i = v.begin(); i != iter; i++) cost2++;
    cout << min(cost1, cost2) << endl;
    
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;

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

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

/*bool subseq(string s,string t){
    ll y=0;
    for(ll i=0;y<s.size()&& i<t.size();i++){
        if(s[y]==t[i]){
            y++;
        }
    }
        if(y==s.size())
            return true;
        else  return false;
}*/
/*ll x=1000000001;
vector<bool>p(x,false);
void prime(){
    p[2]=true;
    for(ll i=3;i<x;i=i+2)
        p[i]=true;
    for(ll i=0;i<x;i=i+2){
        if(p[i]){
            for(ll j=i*i;j<x;j=j+i)
                p[j]=false;
        }
    }
}*/
/*vector<ll> divisor(ll n){
    vector<ll> d;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
        d.push_back(i);
        d.push_back(n/i);
        }
    }
    sort(d.begin(),d.end(),greater<ll>());
    return d;
}*/
/*bool bs(ll n,string s){
    ll a[4]={0};
    for(ll i=0;i<n-1;i++){
        a[s[i]-'0']++;
    }
    for(ll i=n-1;i<s.size();i++){
        a[s[i]-'0']++;
        if(a[1]>0 && a[2]>0 && a[3]>0)
        return true;
        a[s[i-n+1]-'0']--;
    }
    return false;
}*/


/*ll binarySearch(ll n,ll a[],ll x){
    ll low=0,high=n-1,mid,ans=-1;
    while(low<=high){
        mid=low+(high-low)/2;
        if(a[mid]>=x){

            high=mid-1;
        }
        else{
                ans=mid;
            low=mid+1;
        }
    }
    return a[ans];
}*/




/*bool subseq(string s,string t){
    ll y=0;
    for(ll i=0;y<s.size()&& i<t.size();i++){
        if(s[y]==t[i]){
            y++;
        }
    }
        if(y==s.size())
            return true;
        else  return false;
}*/
/*ll x=1000000001;
vector<bool>p(x,false);
void prime(){
    p[2]=true;
    for(ll i=3;i<x;i=i+2)
        p[i]=true;
    for(ll i=0;i<x;i=i+2){
        if(p[i]){
            for(ll j=i*i;j<x;j=j+i)
                p[j]=false;
        }
    }
}*/
/*vector<ll> divisor(ll n){
    vector<ll> d;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
        d.push_back(i);
        d.push_back(n/i);
        }
    }
    sort(d.begin(),d.end(),greater<ll>());
    return d;
}*/
/*bool bs(ll n,string s){
    ll a[4]={0};
    for(ll i=0;i<n-1;i++){
        a[s[i]-'0']++;
    }
    for(ll i=n-1;i<s.size();i++){
        a[s[i]-'0']++;
        if(a[1]>0 && a[2]>0 && a[3]>0)
        return true;
        a[s[i-n+1]-'0']--;
    }
    return false;
}*/


/*ll binarySearch(ll n,ll a[],ll x){
    ll low=0,high=n-1,mid,ans=-1;
    while(low<=high){
        mid=low+(high-low)/2;
        if(a[mid]>=x){

            high=mid-1;
        }
        else{
                ans=mid;
            low=mid+1;
        }
    }
    return a[ans];
}*/

string solve(ll n){


}

int main() {
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    ll s=0;
    for(ll i=0;i<k;i++){
        s=s+a[i];
    }
    cout<<s;
}


Measured memory_bytes: 3620
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let nt : Vec<i32> = get_vec();
    let xs : Vec<i32> = get_vec();
    let n = nt[0] as usize;
    let t = nt[1];
    let mut ans = 0;

    for i in 1..n {
        if xs[i] < xs[i-1] + t {
            ans += xs[i] - xs[i-1];
        }
        else {
            ans += t;
        }
    }
    ans += t;
    println!("{}", ans);
}


Measured memory_bytes: 8444
import math

inputa = input().split()

# inputb = input()


a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# inputList = list(inputb)
#
# inputList[b-1] = inputList[b-1].lower()
#
# ans = "".join(inputList)
ans = 0

for i in range(2):
    if a > b:
        ans += a
        a -= 1
    else:
        ans += b
        b -= 1


print(ans)

# inputList.sort()
#
# list = [a+b, b+c ,c+a]
#
# ans = min(list)
# print(ans)



# flg = 1
# for i in range(0, len(inputList)-1):
#     if inputList[i] == inputList[i + 1]:
#         flg = 0
#         break
#
# if flg == 0:
#     print("Bad")
# else:
#     print("Good")


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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, K; cin >> N >> K;
	
	vector<ll> x(N, 0LL), y(N, 0LL);
	vector<ll> xary, yary;
	rep (i, N){
		cin >> x[i] >> y[i];
		xary.push_back(x[i]);
		yary.push_back(y[i]);
	} // end rep

	sort(ALL(xary));
	sort(ALL(yary));

	ll ans = (xary[N-1] - xary[0]) * (yary[N-1] - yary[0]);

	for (int xi = 0; xi < N; ++xi){
		for (int xj = xi + 1; xj < N; ++xj){
			for (int yi = 0; yi < N; ++yi){
				for (int yj = yi + 1; yj < N; ++yj){
					int num = 0;
					ll lx = xary[xi], rx = xary[xj];
					ll by = yary[yi], uy = yary[yj];
					rep (i, N){
						if (lx <= x[i] && x[i] <= rx && by <= y[i] && y[i] <= uy){
							++num;
						} // end if
					} // end rep
					if (num >= K){
						ans = min(ans, (rx - lx) * (uy - by));
					} // end if
				} // end for
			} // end for
		} // end for
	} // end for

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
S = input()
x, y = map(int, input().split())

x_axis = 1 << 8000
y_axis = 1 << 8000
first = True
axis = 0  # 0 = x, 1 = y
count = 0

for s in S:
    if s == 'T':
        if axis == 0:
            if first:
                x_axis = x_axis << count
            else:
                x_axis = (x_axis << count) | (x_axis >> count)
        else:
            y_axis = (y_axis << count) | (y_axis >> count)

        axis = 1 - axis  # 軸が変わる
        first = False
        count = 0

    else:
        count += 1

if count:
    if axis == 0:
        if first:
            x_axis = x_axis << count
        else:
            x_axis = (x_axis << count) | (x_axis >> count)
    else:
        y_axis = (y_axis << count) | (y_axis >> count)


if (x_axis >> (8000+x)) & 1 and (y_axis >> (8000+y)) & 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
using vint = vector<int>;
using vvint = vector<vint>;
using vchar = vector<int>;
using vvchar = vector<vchar>;
constexpr double pi = 3.1415926535897932384626433832795028L;

int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int sigma_2(int n) {
  if (n == 0) {
    return 0;
  }
  return n + sigma_2(n - 1);
}
int sum_range(int a, int b) {
  if (a == b) {
    return a;
  }
  return sum_range(a, b - 1) + b;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}

int array_sum_from_i(vint &data, int i) {
  if (i == data.size()) {
    return 0;
  }
  int s = array_sum_from_i(data, i + 1);
  return data[i] + s;
}
int array_sum(vint &data) {
  return array_sum_from_i(data, 0);
}
bool has_divisor(int N, int i) {
  if (i == N) {
    return false;
  }
  if (N % i == 0) {
    return true;
  }
  return has_divisor(N, i + 1);
}

bool is_prime(int N) {
  if (N == 1) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else {
    return !has_divisor(N, 2);
  }
}
bool is_even(int);
bool is_odd(int);

bool is_even(int n) {
  if (n == 0) {
    return true;
  }
  return is_odd(n - 1);
}

bool is_odd(int n) {
  if (n == 0) {
    return false;
  }
  return is_even(n - 1);
}








signed main() {
    string S;
    cin >> S;
    int N = S.length();
    for(int i=1;i<N;i++){
        if(S[i-1]!=S[i]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;

}


Measured memory_bytes: 256
x=int(input())
j=0
while True:
  j+=1
  for i in range(j+1):
    a=j
    b=j-i
    if pow(a,5)-pow(b,5)==x:
      print(a,b)
      exit(0)
    b*=-1
    if pow(a,5)-pow(b,5)==x:
      print(a,b)
      exit(0)
    b*=-1
    a*=-1
    if pow(a,5)-pow(b,5)==x:
      print(a,b)
      exit(0)





Measured memory_bytes: 9180
#include <cstdio>
int n, m, x, y, s, a[100005], v[100005]={0,1};
int main() {
  int i;
  scanf("%d%d", &n, &m);
  for(i=n; i; i--) a[i] = 1;
  while(m--) {
    scanf("%d%d", &x, &y);
    if(v[x]) v[y] = 1;
    a[x]--, a[y]++;
    if(!a[x]) v[x] = 0;
  }
  for(i=n; i; i--) s += v[i];
  printf("%d", s);
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int a,sum=0,maxl=0;

	for (size_t i = 0; i < N; ++i) {
		cin >> a;
		sum += a;
		maxl = max(a, maxl);
	}
	sum -= maxl;
	if(sum>maxl) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  int n, m;
  cin >> n >> m;
  
  vector <P> v;

  REP(i, m){
    int x, y;
    cin >> x >> y;
    if(x > y) swap(x, y);
    v.push_back(make_pair(x, y));
  }

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

  int l = v[0].first;
  int r = v[0].second;
  int ans = 1;

  FOR(i, 1, m){    
    if(v[i].first >= r){
      ans++;
      l = v[i].first;
      r = v[i].second;
    }
    else{
      l = max(l, v[i].first);
      r = min(r, v[i].second);
    }
  }

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


Measured memory_bytes: 1400
a, b, c, x, y = list(map(int, input().split()))

l = a * x + b * y
m = c * max(x, y) * 2

if x >= y :
    n = c * y * 2 +  a * (x - y)
else:
    n = c * x * 2 + b * (y - x)

ans = min(l, min(m, n))
print(ans)



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

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  for(int i=A;i<=B;i++){
    if(i%K==0){
      cout << "OK" << endl;
      return 0;
    }
  }
  
  cout << "NG" << endl;
}

Measured memory_bytes: 3632
use proconio::input;

fn main() {
    input! {
        mut a: usize,
        mut b: usize,
    }

    if a == 1 {
        a += 13
    }
    if b == 1 {
        b += 13
    }

    if a < b {
        println!("Bob");
    } else if a == b {
        println!("Draw");
    } else {
        println!("Alice");
    }
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
 
//Prints the Longest common subsequence
void printLCS( string s1, string s2, int m, int n )
{
   int L[m+1][n+1];
 
   //Building L[m][n] as in algorithm
   for (int i=0; i<=m; i++)
   {
     for (int j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
       else if (s1[i-1] == s2[j-1])
         L[i][j] = L[i-1][j-1] + 1;
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }
 
   //To print LCS
   int index = L[m][n];
   //charcater array to store LCS
   char LCS[index+1];
   LCS[index] = '\0'; // Set the terminating character
   
   //Stroing characters in LCS
   //Start from the right bottom corner character
   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      //if current character in s1 and s2 are same, then include this character in LCS[]
      if (s1[i-1] == s2[j-1])
      {
          LCS[index-1] = s1[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }
      // compare values of L[i-1][j] and L[i][j-1] and go in direction of greater value.
      else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
   }
 
   // Print the LCS
   cout<< LCS<<endl;
}
 
/* Driver program to test above function */
int main()
{
string s1,s2;
cin>>s1>>s2;
  printLCS(s1, s2, s1.length(), s2.length());
  return 0;
}

Measured memory_bytes: 35456
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

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

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    string s,t;
    cin >> s;
    cin >> t;

    ll n = s.size();

    s += s;

    vector<vector<ll>> next(n*2,vector<ll>(26,-1));

    next[n*2-1][(int)(s.back() - 'a')] = n*2 - 1;

    for(int i = n*2-2; i >= 0; i--){
        for(int j = 0; j < 26; j++){
            if(j == (int)(s[i] - 'a')){
                next[i][j] = i;
            }else{
                next[i][j] = next[i+1][j];
            }
        }
    }

    ll pos = 0;

    ll ans = 0;

    for(int i = 0; i < t.size(); i++){
        int idx =(int)(t[i] - 'a');
        if(next[pos][idx] < 0){
            cout << -1 << endl;
            return 0;
        }else{
            ans += next[pos][idx] - pos + 1;
            pos = next[pos][idx] + 1;
            pos %= n;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 49004
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  double a, b;
  cin >> a >> b;
  if (a > b) cout << "GREATER" << endl;
  else if (a < b) cout << "LESS" << endl;
  else cout << "EQUAL" << endl;
  return 0;
}

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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 2e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);


string s;

void solve(){

    cin >> s;

    sort(s.begin() , s.end());
    if( (s[0] == s[1]) && (s[2] == s[3]) && (s[1] != s[2]) ){
        printf("Yes\n");
    }
    else
        printf("No");


}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
const double pi=acos(-1.0);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int main(void){
    float d,t,s,ans;
    cin>> d>>t>>s ;
    ans=d/s;
    if(t>=ans){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    
    //cout<<  ;<<endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

void solve()
{
    int X, t; cin >> X >> t;
    cout << max(X-t, 0) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();

    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;

class Solve
{
    static void Main(string[] args) {
        var S = Console.ReadLine();
        var answer = 0;
        if (S == "RRR") answer = 3;
        else if (S.StartsWith("RR") || S.EndsWith("RR")) answer = 2;
        else if (S.Contains('R')) answer = 1;
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 26180
#define    ll           long long
#define    dn           double
#define    mp           make_pair
#define    pb           push_back
#define    se           second
#define    fi           first
#define    mod          1000000007
#define    sob(v)       v.begin(),v.end()
#define    sobr(v)      v.rbegin(),v.rend()
#define    fr(i,a,b)    for(int i=a;i<=b;++i)
#define    frr(i,a,b)   for(int i=a;i>=b;--i)
#define    pi           acos(-1.00)
#define    check        cout<<"*"<<endl
#define    ffix(x)      cout<<fixed<<setprecision(x)
#define    fast         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#include<bits/stdc++.h>
#include<string.h>
using namespace std;


typedef vector<int> vi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<int,vi> pp;

int dr[8]= {0,0,-1,1,-1,-1,+1,+1};
int dc[8]= {-1,1,0,0,-1,+1,-1,+1};

const int N=2000000;

int main()
{
    int n,ans;
    cin>>n;
    if(n>=400 && n<=599)
        ans=8;
    else if(n>=600 && n<=799)
        ans=7;
    else if(n>=800 && n<=999)
        ans=6;
    else if(n>=1000 && n<=1199)
        ans=5;
    else if(n>=1200 && n<=1399)
        ans=4;
    else if(n>=1400 && n<=1599)
        ans=3;
    else if(n>=1600 && n<=1799)
        ans=2;
    else if(n>=1800 && n<=1999)
        ans=1;
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
n = int(input())
mod = 10**9 + 7
# ans = 1
# for i in range(n - 2):
#     ans *= 10
#     ans %= mod
# print((ans * n * (n - 1)) % mod)

# print((n * (n - 1) * 10**(n - 2 ) % mod))
print((10**n - 9**n - 9**n + 8**n) % mod)


Measured memory_bytes: 11164
main :: IO ()
main = do
  s <- getLine
  solver' s

solver :: String -> IO ()
solver s
  = print $ if s !! 1 /= 'S'
      then length $ filter (=='R') s
      else if 'R' `elem` s then 1 else 0

solver' :: String -> IO ()
solver' s
  | s == "SSS" = print 0
  | s == "RSS"
  || s== "RSR"
  || s== "SRS"
  || s== "SSR" = print 1
  | s == "RRS"
  || s== "SRR" = print 2
  | otherwise = print 3

Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int A[10][10];
int N, b[150];

int C[10][10];

int main(void) {

	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> A[i][j];
		}
	}

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> b[i];
		for (int u = 1; u <= 3; u++) {
			for (int v = 1; v <= 3; v++) {
				if (A[u][v] == b[i]) { C[u][v] = 1; }
			}
		}
	}

	int sign = 0;

	for (int i = 1; i <= 3; i++) {
		if (C[i][1] == 1 && C[i][2] == 1 && C[i][3] == 1) { sign = 1; }
	}

	for (int j = 1; j <= 3; j++) {
		if (C[1][j] == 1 && C[2][j] == 1 && C[3][j] == 1) { sign = 1; }
	}

	if (C[1][1] == 1 && C[2][2] == 1 && C[3][3] == 1) { sign = 1; }

	if (C[1][3] == 1 && C[2][2] == 1 && C[3][1] == 1) { sign = 1; }

	if (sign == 1) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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



int main(){
  string s; cin >> s; vector<char> ans;
  
  rep(i,s.size()){
    
    if(s[i] == 'B' && ans.size() != 0){
      ans.pop_back();
    }
    
    else if(s[i] == '1'){
      ans.push_back('1');
    }
    else if(s[i] == '0'){
      ans.push_back('0');
    }
    
  }
  
  for(char x : ans){
    cout << x;
  }
  
  cout << endl;
}

Measured memory_bytes: 256
N,C=map(int,input().split())
x=[];v=[]
for i in range(N):
    xi,vi=map(int,input().split())
    x.append(xi);v.append(vi)

# 時計回りにj番目までの寿司を（全部）食べて初期位置まで戻った場合の差し引き摂取カロリー
rc=[v[0]-2*x[0]]
for j in range(1,N):
    rc.append(rc[-1]+v[j]-2*(x[j]-x[j-1]))
# print(f'rc:{rc}') #DB
# 時計回りにj番目までの寿司を（必ずしも最後までではなく）食べて初期位置まで戻った場合の差し引き摂取カロリーの最大値
mrc=[rc[0]]
for j in range(1,N):
    mrc.append(max(mrc[-1],rc[j]))
# print(f'mrc:{mrc}')
# 反時計回りにN-1-i番目までの寿司を（全部）食べて退店した場合の差し引き摂取カロリー
ca=[v[N-1]-(C-x[N-1])]
for i in range(1,N):
    ca.append(ca[-1]+v[N-1-i]-(x[N-i]-x[N-1-i]))
# print(f'ca:{ca}')
# 反時計回りにN-1-i番目までの寿司を（必ずしも最後までではなく）食べて退店した場合の差し引き摂取カロリーの最大値
mca=[ca[0]]
for i in range(1,N):
    mca.append(max(mca[-1],ca[i]))
# print(f'mca:{mca}')


# 反時計回りにN-1-j番目までの寿司を食べて初期位置まで戻った場合の差し引き摂取カロリー
ra=[v[N-1]-2*(C-x[N-1])]
for j in range(1,N):
    ra.append(ra[-1]+v[N-1-j]-2*(x[N-j]-x[N-1-j]))
# print(f'ra:{ra}')
mra=[ra[0]]
for j in range(1,N):
    mra.append(max(mra[-1],ra[j]))
# print(f'mra:{mra}')

# 時計回りにi番目までの寿司を食べて退店した場合の差し引き摂取カロリー
cc=[v[0]-x[0]]
for i in range(1,N):
    cc.append(cc[-1]+v[i]-(x[i]-x[i-1]))
# print(f'cc:{cc}')
mcc=[cc[0]]
for i in range(1,N):
    mcc.append(max(mcc[-1],cc[i]))
# print(f'mcc:{mcc}')

ans=0
if N==1:
    ans=max(ans,v[0]-x[0],v[0]-(C-x[0]))
else:
    # まず時計回りに進み，初期位置まで戻って反時計回りに進む場合
    for i in range(N-1):
        ans=max(ans,mrc[i]+mca[N-2-i])
    # 時計回りに全部食べてから初期位置に戻る(i=N-1)場合は考慮する必要がない。
    # そのような食べ方は，反時計回りに進まず，時計回りに全部食べてそのまま退店する場合よりも常に差し引き摂取カロリーが少ない。

    # 時計回りに進み，そのまま退店する場合
    for i in range(N):
        ans=max(ans,mcc[i])

    # まず反時計回りに進み，初期位置まで戻って時計回りに進む場合
    for i in range(N-1):
        ans=max(ans,mra[i],mra[i]+mcc[N-2-i])
    
    # 反時計回りに進み，そのまま退店する場合
    for i in range(N):
        ans=max(ans,mca[i])

print(ans)

Measured memory_bytes: 77272
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] c = new int[m];
		int[] dp = new int[n+1];
		Arrays.fill(dp, 50000);
		for(int i=0;i<m;i++){
			c[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
			if(n<c[i]){
				continue;
			}
			dp[c[i]] = 1;
			for(int j=0;j<n;j++){
				if(j+c[i]>n){
					break;
				}
				if(dp[j]!=0){
					dp[c[i]+j] = Math.min(dp[c[i]+j], dp[j]+1);
				}
			}
		}

		System.out.println(dp[n]);

	}
}




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

int main(void)
{
    int n;
    cin >> n;
    int a[n];
    for ( int i = 0; i < n; i++ )
        cin >> a[i];
    
    // vectorと配列は別モンなんだね
    // sort(a.begin(), a.end(), greater<int>());
    
    sort(a, a + n, greater<int>());
    
    int alice = 0,bob = 0;
    for ( int i = 0; i < n; i++ )
    {
        if ( i % 2 == 0 )
            alice += a[i];
        else
            bob += a[i];
    }
    
    int ans = alice - bob;
    
    cout << ans << endl;
}


Measured memory_bytes: 3640
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
x,y=map(int,input().split())
tate,yoko=[],[]
kaisi=0
tmp=0
flag=1
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    elif s[i]=="T":
        if kaisi==0:
            kaisi=1
            x-=tmp
        elif flag==0:
            flag=1
            yoko.append(tmp)
        else:
            flag=0
            tate.append(tmp)
        tmp=0


if kaisi==0:
    kaisi=1
    x-=tmp
elif flag==0:
    flag=1
    yoko.append(tmp)
else:
    flag=0
    tate.append(tmp)

# if sum(yoko)==0 and sum(tate)==0:
#     if x==0 and y==0:
#         print("Yes")
#     else:
#         print("No")
#     quit()
# # print(yoko,tate)

if abs(x)>sum(yoko) or abs(y)>sum(tate):
    print("No")
    quit()
yokolst=[[0]*(sum(yoko)*2+1) for i in range(len(yoko)+1)]
tatelst=[[0]*(sum(tate)*2+1) for i in range(len(tate)+1)]
yokolst[0][sum(yoko)]=1
tatelst[0][sum(tate)]=1
# print(yokolst)
# print(tatelst)
for i in range(len(tate)):
    for j in range(len(tatelst[0])):
        if tatelst[i][j]==1:
            tatelst[i+1][j+tate[i]]=1
            tatelst[i+1][j-tate[i]]=1


for i in range(len(yoko)):
    for j in range(len(yokolst[0])):
        if yokolst[i][j]==1:
            yokolst[i+1][j+yoko[i]]=1
            yokolst[i+1][j-yoko[i]]=1


# print(yokolst)
# print(tatelst)

if tatelst[-1][sum(tate)+y]==1 and yokolst[-1][sum(yoko)+x]==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 167260