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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  ll l, r;
  cin >> l >> r;
  int ans = 2020;
  r = min(r, l+2500);
  FOR(i, l, r+1){
    FOR(j, i+1, r+1){
      int now = ((i % 2019) * (j % 2019)) % 2019;
      ans = min(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3664
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int main(){
	double n,x,t,h;
	while(cin>>x){
		t=x/9.8;
		h=4.9*x*x/(9.8*9.8);
		n=h/5;
		if(h-(int)h!=0) cout<<(int)n+2<<endl;
		else cout<<(int)n+1<<endl;
	}
}

Measured memory_bytes: 1224
l, r = map(int, input().split())

li=[]
cnt=0
for i in range(l, r+1):
  li.append(i%2019)
  if i%2019==0:
    print(0)
    break
else:
  ans=2019
  for index, i in enumerate(li):
    for j in li[index+1:]:
      ans = min(ans, (i*j)%2019)
  print(ans)

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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,t;
    cin>>n>>t;
    ll sum=0;
    while(t--)
    {
        ll a;
        cin>>a;
        sum+=a;
    }
    ll ans=(sum<=n)?(n-sum):-1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
// In the Name of Allah. Ya Ali!
#include<bits/stdc++.h>
#define bp __builtin_popcount
typedef long long ll;
const ll MAX_N = 2e5+100;
const ll MOD = 1e9+7;
using namespace std;

int h[MAX_N];
int a[MAX_N];
ll fen[MAX_N];
int n;

void add(int x,ll d)
{
    for(;x<=n;x += (x&-x))
        fen[x] = max(fen[x],d);
}

ll ask(int x)
{
    ll ans = 0;
    for(;x;x&=x-1)
        ans = max(ans,fen[x]);
    return ans;
}

int main()
{
    cin >> n;
    for(int i = 1;i<=n;++i)
        scanf("%d",&h[i]);
    for(int i = 1;i<=n;++i)
        scanf("%d",&a[i]);
    for(int i = 1;i<=n;++i)
        add(h[i],ask(h[i])+a[i]);
    cout << ask(n);
    return 0;
}


Measured memory_bytes: 3328
s = list(input())

x = [s[0]]
cnt1 = 0
cnt2 = 0

for i in s:
    if x[0] != i:
        if i not in x:
            x.append(i)

if len(x) == 2:
    cnt1 = s.count(x[0])
    cnt2 = s.count(x[1])

if cnt1 == 2 and cnt2 == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
using System;

public class Problem_C
{
  public static void Main()
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int A = inputs[0], B = inputs[1], C = inputs[2], D = inputs[3], E = inputs[4], F = inputs[5];

    var total = 0;
    var sugarTotal = 0;
    double maxDens = 0;
    for (var i = 0; 100 * A * i <= F; i++)
    {
      for (var j = 0; (100 * A * i) + (100 * B * j) <= F; j++)
      {
        if (i == 0 && j == 0) continue;
        var waterSum = (100 * A * i) + (100 * B * j);
        for (var k = 0; waterSum + (C * k) <= F; k++)
        {
          for (var l = 0; waterSum + (C * k) + (D * l) <= F; l++)
          {
            var sugarSum = (C * k) + (D * l);
            if (sugarSum > waterSum) continue;
            double dens = ((double) sugarSum / waterSum);
            if (dens <= E / 100d && dens >= maxDens)
            {
              maxDens = dens;
              total = waterSum + sugarSum;
              sugarTotal = sugarSum;
            }
          }
        }
      }
    }
    Console.WriteLine($"{total} {sugarTotal}");
  }
}


Measured memory_bytes: 13140
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

P = [[0 for j in range(3)] for i in range(3)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if B[i] == A[j][k]:
                P[j][k] = 1

if P[0][0]+P[0][1]+P[0][2] == 3 or P[1][0]+P[1][1]+P[1][2] == 3 or P[2][0]+P[2][1]+P[2][2] == 3 or P[0][0]+P[1][0]+P[2][0] == 3 or P[0][1]+P[1][1]+P[2][1] == 3 or P[0][2]+P[1][2]+P[2][2] == 3 or P[0][0]+P[1][1]+P[2][2] == 3 or P[2][0]+P[1][1]+P[0][2] == 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38480
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	if a == 7 {
		a, c = c, a
	}
	if b == 7 {
		b, c = c, b
	}
	if a == 5 && b == 5 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


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

int main(){
  string N;
  int count;
  count = 0;
  cin >> N;
  for (int i = 0; i < 3; i++){
    if (N.at(i) == '1'){
      count++;
    }
  }
  cout << count << endl;
}

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

public class Main {
  private static boolean solve(int n, int[] as) {
    Set<Integer> set = new HashSet<>();
    for (int a : as) {
      set.add(a);
    }
    return set.size() == n;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] as = reader.nextInt(n);
    out.println(solve(n, as) ? "YES" : "NO");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 53832
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, W;
  string DE[4] = {"maerd","esare","remaerd","resare"};
  int L, N;
  cin >> S;
  L = S.size();
  N = L;
  bool H = true;
  reverse(S.begin(), S.end());
  while(H){
     W = "";
     if(N < 5){
     H = false;
     continue;
     }
     else if(S.at(L - N) == 'm' || S.at(L - N) == 'e'){
        for(int i = 0;i < 5;i++){
        W = W + S.at(L - N + i);
        }
        if(W == DE[0] || W == DE[1]){
        N = N - 5;
        }
        else{
        H = false;
        }
     }
     else if(S.at(L - N) == 'r'){
        if(S.at(L - N + 2) == 'm'){
           for(int i = 0;i < 7;i++){
           W = W + S.at(L - N + i);
           }
           if(W == DE[2]){
           N = N - 7;
           }
           else{
           H = false;
           }    
        }
        else if(S.at(L - N + 2) == 's'){
           for(int i = 0;i < 6;i++){
           W = W + S.at(L - N + i);
           }
           if(W == DE[3]){
           N = N - 6;
           }
           else{
           H = false;
           }    
        }
        else{
        H = false;
        }    
     }
    
     else{
     H = false;
     }
     if(N == 0){
     break;
     }
  }

  if(H){
  cout << "YES" << endl;
  }
  else{
  cout << "NO" << endl;
  }
}

Measured memory_bytes: 512
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,A,B;
  cin>>N>>A>>B;
  if(A*N>=B)
    cout<<B<<endl;
  else
    cout<<N*A<<endl;

}
    
  
  



Measured memory_bytes: 256
n,m = map(int, input().split())
py = []
for i in range(m):
    city = list(map(int, input().split()))
    city.append(i)
    py.append(city)
py.sort()
for i in range(m):
    if py[i][0]==py[i-1][0] and i!=0:
        py[i][1]=py[i-1][1]+1
    else:
        py[i][1]=1 

py.sort(key=lambda x: x[2])

for i in range(m):
    
    py[i][0] = str(py[i][0])
    py[i][1]=str(py[i][1])
    while len(py[i][1])<6:
        py[i][1]="0"+py[i][1]
        
    while len(py[i][0])<6:
        py[i][0]="0"+py[i][0]
    print(py[i][0]+py[i][1])

Measured memory_bytes: 43296
n,h = map(int,input().split())
al,bl = [],[]
for i in range(n):
  a,b = map(int,input().split())
  al.append(a)
  bl.append(b)
ma = max(al)
bl.sort()
s = 0
c = 0
for i in bl[::-1]:
  if ma >= i:
    break
  else:
    s += i
    c += 1
    if s >= h:
      break
if h > s:
  c += (h-s-1)//ma+1
print(c)

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

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pll;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fir first
#define sec second

#define fo0(i,a,b) for(int i=(a);i<(b);i++)
#define fo1(i,a,b) for(int i=(a);i<=(b);i++)
#define fd0(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define fd1(i,a,b) for(int i=(a);i>=(b);i--)
#define mset(a,b) memset(a,(b),sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

template<typename T> inline void in(T &x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9')
{if(ch=='-')fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;}
template<typename T> void out(T x){if(x<0){putchar('-');x=-x;}if(x/10)out(x/10);putchar(x%10+'0');}
template<typename T> inline void outln(T x){out(x);putchar(10);}
template<typename T> inline void outsp(T x){out(x);putchar(' ');}
template<typename T> inline T gcd(T a, T b){T t;if(a>b){while(b){
t=b;b=a%b;a=t;}return a;}else{while(a){t=a;a=b%a;b=t;}return b;}}
template<typename T> inline T lcm(T a, T b){return a/gcd(a,b)*b;}

const int N = 100005;

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

bool cmp(int x, int y){
	return x > y;
}

LL work(int k){
	LL ans = 0;
	if(k == 1)	sort(a+1, a+n+1);
	else	sort(a+1, a+n+1, cmp);
	int l = 1, r = n;
	c[0] = 0;
	while(l <= r){
		c[++c[0]] = a[l++];
		if(l <= r)
			c[++c[0]] = a[r--];
	}
	fo0(i, 1, c[0])	ans += abs(c[i] - c[i+1]);
	ans += abs(c[1] - c[c[0]]);
	LL mn = 1e15;
	fo1(i, 2, n)	mn = min(mn, 1ll * abs(c[i] - c[i-1]));
	mn = min(mn, 1ll * abs(c[1] - c[n]));
	ans -= mn;
	return ans;
}

int main(){
	in(n);
	fo1(i, 1, n)	in(a[i]);
	outln(max(work(1), work(0)));
	return 0;
}

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

int main() {
   int x, a, b;
   cin >> x >> a >> b;

   if (a >= b) {
       cout << "delicious" << endl;
   } else if ((a + x) >= b){
       cout << "safe" << endl;
   } else {
       cout << "dangerous" << endl;
   }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>

using namespace std;
int N;
vector<int> v;

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

    vector<int> m(N);
    int min_v = INT32_MAX;
    for (int i = 0; i < N; i++) {
        min_v = min(min_v, v[i]);
        m[i] = min_v;
    }
    int ans = INT32_MIN;
    for (int i = 1; i < N; i++) {
        ans = max(ans, v[i] - m[i - 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4344
#include<iostream>
using namespace std;
int parent(int i){ return i/2; }
int left(int i){ return i*2; }
int right(int i){ return i*2+1; }
int main(){
  int h,tree[100001];
  cin>>h;
  for(int i=1;i<=h;++i) cin>>tree[i];
  for(int i=1;i<=h;++i){
    cout<<"node "<<i<<": key = "<<tree[i]<<", ";
    if(parent(i)>=1) cout<<"parent key = "<<tree[parent(i)]<<", ";
    if(left(i)<=h) cout<<"left key = "<<tree[left(i)]<<", ";
    if(right(i)<=h) cout<<"right key = "<<tree[right(i)]<<", ";
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


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

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

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

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

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

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


/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/


const int MAX = 1000005;
//const int mod = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    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 COM(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(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll H, W, A, B;
    cin >> H >> W >> A >> B;

    COMinit();

    ll ans = 0;
    for(int i=B+1; i<=W; ++i) {
        ans += COM(H-A-1 + i-1, i-1) * COM(A-1 + W-i, W-i);
        chmod(ans);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
LL A,B,N;
V<LL> vec;
bool calc(LL i){
    LL ans = 0;
    REP(a,N){
        LL ins = vec.at(a)-i*B;
        if(ins >= 0){
            ans += ins/(A-B);
            if(ins%(A-B)!=0)ans++;
        }
    }
    return ans <= i;
}
int main(){
    cin >> N >> A >> B;
    REP(a,N){
        LCIN(b);
        vec.pb(b);
    }
    LL mi = 0;
    LL ma = INF;
    while(true){
        if(ma-mi<=1){
            break;
        }
       // COUT((ma-mi)/2+mi);
        if(!calc((ma-mi)/2+mi)){
            mi = (ma-mi)/2+mi;
        }else{
            ma = (ma-mi)/2+mi;
        }
    }
    if(calc(mi)){
        COUT(mi);
        return 0;
    }
    if(calc(ma)){
        COUT(ma);
        return 0;
    }
    return 0;
}


Measured memory_bytes: 1400
program two_contests
  implicit none
  integer :: n, a(0:100001,2) = 0, pre(0:100001) = 0, suf(0:100001) = 0, i, x = 0
  read(*,*) n
  do i = 1, n
    read(*,*) a(i,1:2)
  end do
  call merge_sort(a(1:n,1:2))
  pre(0) = 1e9
  suf(n+1) = 1e9
  do i = 1, n
    pre(i) = min(pre(i-1),a(i,2))
  end do
  do i = n, 1, -1
    suf(i) = min(suf(i+1),a(i,2))
  end do
  do i = 1, n-1
    x = max(x,max(calc(a(i,1),pre(i))+calc(a(n,1),suf(i+1)),calc(a(i,1),a(i,2))+calc(a(n,1),min(pre(i-1),suf(i+1)))))
  end do
  write(*,'(i0)') x
contains
  integer function calc(l,r)
    integer, intent(in) :: l, r
    calc = r-l+1
    if (l > r) calc = 0
  end
  subroutine merge_sort(a)
    integer, intent(inout) :: a(:,:)
    integer :: n, m, l, i, u
    n = size(a,1)
    m = n
    l = 1
    do while (m > 1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(a(2*(i-1)*l+1:(2*i-1)*l,:),a((2*i-1)*l+1:u,:))
      end do
      l = 2*l
      m = (m+1)/2
    end do
  end
  subroutine merger(a1,a2)
    integer, intent(inout) :: a1(:,:), a2(:,:)
    integer :: a(size(a1,1)+size(a2,1),size(a1,2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(a1,1)
    n2 = size(a2,1)
    do while (i1 <= n1 .and. i2 <= n2)
      if (a1(i1,1) < a2(i2,1) .or. &
      & (a1(i1,1) == a2(i2,1) .and. a1(i1,2) <= a2(i2,2))) then
        a(i1+i2-1,:) = a1(i1,:)
        i1 = i1+1
      else
        a(i1+i2-1,:) = a2(i2,:)
        i2 = i2+1
       end if
    end do
    if (i1 <= n1) then
      a(i1+i2-1:n1+n2,:) = a1(i1:n1,:)
    else
      a(i1+i2-1:n1+n2,:) = a2(i2:n2,:)
    end if
    a1 = a(1:n1,:)
    a2 = a(n1+1:n1+n2,:)
  end
end program two_contests

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

int yakusu(int a){
  int k=1;
  for(int i=2;i<=a;i++){
    int c=1;
    while(a%i==0){
      a/=i;
      c++;
    }
    k*=c;
  }
  return(k);
}

int main(){
  int n;
  cin >> n;
  int ans=0;
  
  for(int i=3;i<=n;i+=2){
    if(yakusu(i)==8) ans++;
  }
  
  cout << ans << endl;
  
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<ll> A(N);
  vector<bool> buy(N, true);
  buy[N-1] = false;
  ll ans = 1000;
  ll res = 0;
  REP(i, N){
    cin >> A[i];
  }
  for(int i = N-1; i > 0; i--){
    if(A[i] < A[i-1]){
      buy[i-1] = false;
    }
  }
  REP(i, N){
    if(buy[i]){
      if(ans >= A[i]){
        ll tmp = ans/A[i];
        res += tmp;
        ans -= tmp*A[i];
      }
    }else{
      if(res > 0){
        ans += res*A[i];
        res = 0;
      }
    }
  }    
  cout << ans << endl;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s[]={"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  int n; cin>>n;
  while(n--){
    string t,ans;
    cin >> t;
    int cnt=-1,num=0;
    for(int i=0;i<t.size();++i){
      if(t[i]=='0'){
        if(cnt!=-1){
          ans+=s[num][cnt%s[num].size()];
          cnt=-1;
        }
      }else{
        num=t[i]-'0';
        cnt++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(void)
{
    int serve_time[5];
    int total_time = 0;
    for (int i = 0; i < 5; i++)
    {
        cin >> serve_time[i];
        total_time += serve_time[i];
    }

    int dead_time[5] ;

    for (int i = 0; i < 5; i++)
    {
        if ((serve_time[i] % 10) != 0)
        {dead_time[i] = 10 - (serve_time[i] % 10);
        }else{
            dead_time[i] = 0;
        }
        total_time+=dead_time[i];
    }
    
    int max_deadtime = 0;
    for (int i = 0; i < 5; i++)
    {
        if (max_deadtime < dead_time[i])
        {
            max_deadtime = dead_time[i];
        }
    }

    //cout << max_deadtime;
    total_time -= max_deadtime;

    cout << total_time << endl;

    return 0;
}

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

using namespace std;

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

int main(){
 long a,b;
  cin >> a >> b;
  
  long res=0;
  
  if((a-1)%2) res^=(a/2)%2;
  else res^=(((a-1)/2)%2)^(a-1);
  
  if(b%2) res^=((b+1)/2)%2;
  else res^=((b/2)%2)^b;
  
  cout << res << 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 h,w;
    cin>>h>>w;
    int cnt=0;
    rep(i,h){
        string s; cin>>s;
        rep(j,w){
            if(s[j]=='#')cnt++;
        }
    }
    if(cnt==h+w-1)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
s=list(input())
ans=[]
num=0
for i in range(len(s)):
    if s[i]=="1":
        ans.append("1")
        num+=1
    elif s[i]=="0":
        ans.append("0")
        num+=1
    else:
        if num!=0:
            del ans[-1]
            num-=1
print("".join(ans))

Measured memory_bytes: 3060
#include<iostream>
#include<climits>

using namespace std;


typedef struct ball_T
{
        long x;
        long y;
        ball_T* p;
        ball_T* c;
}ball_t;

int search_pos(long x, long y, ball_t* bs, int n);
int search(int i, int j, ball_t* bs, int n);

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

        ball_t* bs = new ball_t[n];
        long x,y;
        for(long i=0;i<n;i++){
                cin >> x >> y;
                bs[i].x = x;
                bs[i].y = y;
        }

        long ans = n;
        for(long i=0;i<n;i++){
                for(long j=0;j<n;j++){
                        if(i == j )
                                continue;

                        long ret = search(i,j,bs,n);
                        if(ret < ans){
                                ans = ret;
                        }
                }
        }

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

int search(int i, int j, ball_t* bs, int n)
{
        ball_t diff = {  bs[j].x - bs[i].x, bs[j].y - bs[i].y };

        if(diff.x == 0 && diff.y == 0){
                return INT_MAX;
        }
        //cout << "search for (" << diff.x << "," << diff.y << ")" << endl;
        for(long i=0;i<n;i++){
                bs[i].p = bs[i].c = NULL;
        }
        int cost = n;
        for(int i=0;i<n;i++){
                int ret = search_pos(bs[i].x - diff.x, bs[i].y - diff.y, bs, n);

                if(ret >= 0){
                        bs[i].p = &bs[ret];
                        bs[ret].c = &bs[i];
                        cost--;
                }
        }

        //cout << cost << endl;

        return cost;
}


int search_pos(long x, long y, ball_t* bs, int n)
{

        for(int i=0;i<n;i++){
                if(bs[i].x == x && bs[i].y == y && bs[i].c == NULL){
                        return i;
                }
        }

        return -1;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import deque

def solve():
    n = II()
    D = deque(sorted(LI()))

    for i in range(n):
        l = D.popleft()
        # print('l', l)
        if len(D) == 0:
            print(1)
            break
        else:
            r = D.pop()
            # print('r', r)
            if len(D) == 0:
                print(r - l)
                break
            else:
                continue




if __name__ == '__main__':
    solve()


Measured memory_bytes: 14812
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 

int main() {
   
   ll n;
   cin>>n;
   
   
   ll ans=0;
   for(ll i=1;i<=n;i++)
   {
       if((ll)floor(log10(i)+1)&1)
       {
       ans++;//cout<<i<<" ";
       }
   }
   cout<<ans;
}

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

int main(){
    int N;
    cin>>N;
    if(N%111==0){
        cout<<N<<endl;
    }else if(N<(N/100)*111){
        cout<<(N/100)*111<<endl;
    }else if(N>(N/100)*111){
        cout<<((1+(N/100))*111)<<endl;
    }
}


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

//template
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define repr(i,n) for(ll i=n;i>0;i--)
#define all(v) v.begin(),v.end()
#define in cin>>
#define out cout<<
#define en <<endl
const ll INF = 10000000000000;

int main()
{
	ll n,k;
	in n >> k;
	vector<ll> A(n);
	rep(i, n)
	{
		in A.at(i);
	}
	if (n <= k)
		out 0 en;
	else
	{
		ll ans = 0;
		sort(all(A));
		rep(i, n - k)
		{
			ans += A.at(i);
		}
		out ans en;
	}
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

vector<string> field;
int color[303][303];
int pre_color[303];
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    field.resize(H);
    rep(i,H) cin >> field[i];
    
    vector<int> cnt(H);
    rep(i,H) {
        rep(j,W) {
            if (field[i][j]=='#') ++cnt[i];
        }
    }
    int now_color = 1;
    bool is_first = true;
    int tmp;
    rep(i,H) {
        tmp = cnt[i];
        if (tmp != 0) {
            rep(j,W) {
                color[i][j] = now_color;
                if (tmp>1 && field[i][j]=='#') {
                    ++now_color;
                    --tmp;
                }
            }
            ++now_color;
            if (is_first) {
                rep(j,W) pre_color[j] = color[i][j];
                is_first = false;
            }
        }
    }

    rep(i,H) {
        int tmp = cnt[i];
        if (tmp == 0) rep(j,W) color[i][j] = pre_color[j];
        else rep(j,W) pre_color[j] = color[i][j];
    }   

    rep(i,H) {
        rep(j,W) {
            if (j < W-1) cout << color[i][j] << ' ';
            else cout << color[i][j] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define inf 1e18
#define sqr(x) ((x)*(x))
using namespace std;
const int N=200005;
vector<int> e[N];
int n,T,dfn[N],ed[N];
int fa[N],ans[N],vis[N];
set<pii> S;
void dfs(int x){
	dfn[x]=++T;
	for (auto i:e[x])
		if (i!=fa[x])
			fa[i]=x,dfs(i);
	ed[x]=T;
}
set<pii> t[N*4];
void insert(int k,int l,int r,int p,int v){
	t[k].insert(pii(v,p));
	if (l==r) return;
	int mid=(l+r)/2;
	if (p<=mid) insert(k*2,l,mid,p,v);
	else insert(k*2+1,mid+1,r,p,v);
}
void workdown(int k,int l,int r,int x,int y,int v){
	if (l==x&&r==y){
		for (;t[k].begin()!=t[k].end()&&t[k].begin()->fi<v;){
			if (!vis[t[k].begin()->fi]){
				S.insert(pii(t[k].begin()->se,t[k].begin()->fi));
				vis[t[k].begin()->fi]=1;
			}
			t[k].erase(t[k].begin());
		}
		return;
	}
	int mid=(l+r)/2;
	if (y<=mid) workdown(k*2,l,mid,x,y,v);
	else if (x>mid) workdown(k*2+1,mid+1,r,x,y,v);
	else{
		workdown(k*2,l,mid,x,mid,v);
		workdown(k*2+1,mid+1,r,mid+1,y,v);
	}
}
void dfs2(int x,int res,int pmx){
	workdown(1,1,n,dfn[x],ed[x],pmx);
	auto it=S.lower_bound(pii(dfn[x],0));
	if (it!=S.end()&&it->se!=x&&vis[x]==1){
		S.insert(pii(dfn[x],x));
		it=S.lower_bound(pii(dfn[x],0));
	}
	for (;it!=S.end()&&it->fi<=ed[x];){
		int id=it->se; res++; vis[id]=2;
		for (auto i:e[id])
			if (i!=fa[id]){
				if (i<pmx){
					S.insert(pii(dfn[i],i));
					vis[i]=1;
				}
				else{
					insert(1,1,n,dfn[i],i);
				}
			}
		S.erase(it);
		it=S.lower_bound(pii(dfn[x],0));
	}
	ans[x]=res;
	for (auto i:e[x])
		if (i!=fa[x]){
			if (!vis[i])
				S.insert(pii(dfn[i],i)),vis[i]=1;
			dfs2(i,res,max(pmx,x));
		}
}
int main(){
	scanf("%d",&n);
	For(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].PB(y); e[y].PB(x);
	}
	dfs(1);
	dfs2(1,0,0);
	for (int i=2;i<=n;i++)
		printf("%d ",ans[i]);
}

Measured memory_bytes: 228980
n = int(input())

a = list(map(int,input().split()))

su = 0

co = 0

for i in range(max(a)):
    for j in range(n):
        if a[j] > 0 and co == 0:
            co += 1
            su += 1
        if co  >=  1:
            if a[j] == 0:
                co = 0
            else:
                a[j] -= 1
    co = 0

print(su)



Measured memory_bytes: 39664
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e5+10;
const int N = 1e5+10;
const int E = 1e6+10; 
int n;
int a[maxn];
int main(){
	cin>>n;
	F(i,1,n) cin>>a[i];
	bool flg = 1;
	F(i,1,n){
		if(a[i]%2==0){
			if(a[i]%3!=0&&a[i]%5!=0){
				flg = 0;
			}
		}
		if(!flg) break;
	}
	
	if(flg) printf("APPROVED\n");
	else printf("DENIED\n");
}

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


int main() {
  int n;
  cin>>n;
  vector<vector<int>> G(n);
  vector<vector<int>> b(n); 
  for(int i=0;i<n-1;i++){
    int a,s,w;
    cin>>a>>s>>w;
    a--;
    s--;
    G[a].push_back(s);
    G[s].push_back(a);
    b[a].push_back(w);
    b[s].push_back(w);
  }
  vector<int> co(n,-1);
  co[0]=0;
  queue<int> que;
  que.push(0);
  int j=0;
  while(!que.empty()){
    int v=que.front();
    que.pop();
    for(int nv=0;nv<G[v].size();nv++){
      int u=G[v][nv];
      int w=b[v][nv];
      if(co[u]!= -1) continue;
      co[u]=(co[v]+w)%2;
      que.push(u);
    }
  }
  for(int i=0;i<n;i++){
    cout<<co[i]<<endl;
  }
}
  


Measured memory_bytes: 11904
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    K, S = read_ints()
    # X+Y+Z = S
    # 0 <= X,Y,Z <= K
    total = 0
    for X in range(K+1):
        if S-X < 0:
            break
        # Y+Z=S-X
        Y_min = max(S-X-K, 0)
        Y_max = min(S-X, K)
        if Y_min <= Y_max:
            total += Y_max-Y_min+1
    return total


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 63924
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

bool valid(int X, int Y, int Z, int x, int y)
{
    if (X <= Z && Z <= Y && x < Z && y >= Z) {
        return true;
    }

    return false;
}

int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N);
    vector<int> y(M);

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

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

    for (int z = 0; z <= 100; ++z) {
        if (X >= z || z > Y) {
            continue;
        }

        bool x_ok = all_of(begin(x), end(x), [z](int xi) {
            return xi < z;
        });

        if (!x_ok) {
            continue;
        }

        bool y_ok = all_of(begin(y), end(y), [z](int yi) {
            return yi >= z;
        });

        if (!y_ok) {
            continue;
        }

        cout << "No War" << endl;
        return 0;
    }

    cout << "War" << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!{
        n: i64,
        x: i64,
        mut a: [i64; n],
    }

    let mut x = x;
    let mut ans = 0;

    a.sort();

    for i in 0..n as usize {
        x -= a[i];
        ans += 1;

        if x <= 0 {
            break;
        }
    }

    if x != 0 {
        ans -= 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2160
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var Ai = Sarray();
            var ans = 0L;
            for (var i = 0; i < N; ++i)
            {
                //くり返し部分
                var rep = 0L;
                for(var j=i+1;j<i+N;++j)
                    if (Ai[i] > Ai[j % N]) ++rep;
                //しっぽの部分
                var zan = 0L;
                for (var j = i + 1; j < N; ++j)
                    if (Ai[i] > Ai[j % N]) ++zan;
                ans = (ans + (zan * K) % Mod) % Mod;
                ans = (ans + (rep * ((K * (K - 1) / 2) % Mod)) % Mod) % Mod;
            }
            WriteLine(ans % Mod);
            //Out.Flush();
        }
    }
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

typedef pair<int,int> pii;

int n,m,c[21][21],d[21][21],hi[]={0,0,1,-1},hj[]={1,-1,0,0};

void nhap()
{
    scanf("%d %d",&n,&m);
    for (int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            char x;
            cin>>x;
            c[i][j]=(x=='.');
        }
    }
}

int bfs(pii s,pii t)
{
    for (int i=1;i<=n;++i)
    {
        for (int j=1;j<=m;++j)
        {
            d[i][j]=0;
        }
    }
    queue<pii> q;
    q.push(s);
    while (!q.empty())
    {
        pii u=q.front();
        q.pop();
        for (int i=0;i<4;++i)
        {
            int x=hi[i]+u.first,y=hj[i]+u.second;
            if (x>0 && y>0 && x<=n && y<=m && c[x][y] && !d[x][y] && s!=make_pair(x,y))
            {
                d[x][y]=d[u.first][u.second]+1;
                q.push({x,y});
            }
        }
    }
    return d[t.first][t.second];
}

void process()
{
    int ma=0;
    for (int x=1;x<=n;++x)
    {
        for (int y=1;y<=m;++y)
        {
            if (!c[x][y]) continue;
            for (int x1=1;x1<=n;++x1)
            {
                for (int y1=1;y1<=m;++y1)
                {
                    if (!c[x1][y1]) continue;
                        ma=max(ma,bfs({x,y},{x1,y1}));
                }
            }
        }
    }
    cout<<ma;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize);
    let mut count = 0;
    for i in 0..n {
        if i % 2 == 0 {
            count += 1;
        }
    }

    println!("{}", count as f64 / n as f64);
}


Measured memory_bytes: 2204
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=998244353;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;
    int n,val;
    cin>>n;

    vi v;
    rep(i,n)
    {
        cin>>val;
        v.pb(val);
    }

    sort(all(v));

    reverse(all(v));

    int l=1,ans=v[0],cnt=0;
    repa(i,2,n-1)
    {
        cnt++;
        ans+=v[l];

        if(cnt==2)
        {
            cnt=0;
            l++;
        }
    }

    cout<<ans<<endl;
}   


Measured memory_bytes: 5328
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
using namespace std;


int n, m;
int matchsticks[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int a[100];
string dp[10003];
int main(){
	scanf("%d %d", &n, &m);
	for(int i=0;i<m;i++){
		scanf("%d", &a[i]);
	}
	sort(a, a+m);
	reverse(a, a+m);
	dp[0] = "";
	for (int i=1;i<=n;i++){
		dp[i] = "#";
	}
	for (int i=0;i<m;i++){
		for (int j=matchsticks[a[i]];j<=n;j++){
			if (dp[j-matchsticks[a[i]]] != "#"){
				string temp = dp[j-matchsticks[a[i]]];
				temp += (a[i] + 48);
				if (dp[j].length() < temp.length()){
					dp[j] = temp;	
				}
				else if (dp[j].length() == temp.length()){
					if (dp[j] < temp){
						dp[j] = temp;
					}
				}
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 43136
def comp(a,b):
    if a[1] > b[1]:
        return True
    else:
        return False

def bubble_sort(a):
    for i in range(n):
        for j in reversed(range(i+1,n)):
            if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
    return a

def selection_sort(a):
    for i in range(n):
        mini = i
        for j in range(i,n):
            if comp(a[mini],a[j]):
                mini=j
        a[mini],a[i]=a[i],a[mini]
    return a

def stable(original_a,sorted_a):
    for num in range(1,10):
        suite_ord = []
        for v in original_a:
            if v[1] == str(num):
                suite_ord.append(v[0])
        for v in sorted_a:
            if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
    return "Stable"


n = int(raw_input())
cards = raw_input().split(' ')

sorted_cards = bubble_sort(cards[:])
print ' '.join(sorted_cards)
print stable(cards,sorted_cards)
sorted_cards = selection_sort(cards[:])
print ' '.join(sorted_cards)
print stable(cards,sorted_cards)

Measured memory_bytes: 6432