akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <class T>
class cumulativeSum
{
private:
    int ny, nx;
    vector<vector<T> > sum;
public:
    cumulativeSum(const vector<vector<T> >& a)
    {
        ny = a.size();
        nx = a[0].size();
        sum.assign(ny+1, vector<T>(nx+1, 0));
        for(int i=0; i<ny; ++i){
            for(int j=0; j<nx; ++j){
                sum[i+1][j+1] = a[i][j] + sum[i][j+1] + sum[i+1][j] - sum[i][j];
            }
        }
    }
    T getSum(int y1, int x1, int y2, int x2)
    {
        y1 = max(y1, 0);
        x1 = max(x1, 0);
        y2 = min(y2, ny-1);
        x2 = min(x2, nx-1);
        if(y1 > y2 || x1 > x2)
            return 0;
        return sum[y2+1][x2+1] - sum[y1][x2+1] - sum[y2+1][x1] + sum[y1][x1];
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<vector<vector<int>>> v(2, vector<vector<int>>(k*2, vector<int>(k*2, 0)));
    for(int i=0; i<n; ++i){
        int x, y;
        char c;
        cin >> x >> y >> c;
        y %= k * 2;
        x %= k * 2;
        int a = (c == 'B') ? 0 : 1;
        ++ v[a][y][x];
    }

    int ans = 0;
    vector<cumulativeSum<int>> cs = {v[0], v[1]};
    for(int y=0; y<2*k; ++y){
        for(int x=0; x<2*k; ++x){
            int sum = 0;
            for(int i=0; i<4; ++i){
                for(int j=0; j<4; ++j){
                    int a = (i + j) % 2;
                    int y2 = y + (i - 2) * k;
                    int x2 = x + (j - 2) * k;
                    sum += cs[a].getSum(y2, x2, y2+k-1, x2+k-1);
                }
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 94592
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)
for i in range(N - 1):
    if A[i + 1] == A[i] + 1:
        ans += C[A[i] - 1]
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  
  int array[50];
  int i=0;
  for(int j=1;j<10;j++){
    for(int k=j;k<10;k++){
      array[i]=j*k;
      i++;}}

  for(int j=0;j<i;j++){
    if(n==array[j]){
      printf("Yes\n");
      return 0;}}
  printf("No\n");
  return 0;
}
  


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int N;
    string s;
    cin >> N;
    cin >> s;
    int r=0,b=0;
    for(auto c: s) {
        if(c=='R') r++;
        if(c=='B') b++;
    }
    cout << ((r>b)? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

void warshall_floyd(vector<vector<int>> &_Date){
    for(int k = 0; k < _Date.size(); k++){        //経由頂点
        for(int i = 0; i < _Date.size(); i++){    //始点
            for(int j = 0; j < _Date.size(); j++){//終点
                _Date[i][j] = min(_Date[i][j], _Date[i][k] + _Date[k][j]);
            }
        }
    }
}

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> cost(10, vector<int>(10, INF));
    vector<vector<int>> ch(H, vector<int>(W));
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cin >> cost[i][j];
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> ch[i][j];
        }
    }
    
    warshall_floyd(cost);
    int sum = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(ch[i][j] == -1)continue;
            sum += cost[ch[i][j]][1];
        }
    }
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll N, ans = 1;
    double T, A, H[1010];
    cin >> N >> T >> A;
    for(ll i = 1; i <= N; i++)cin >> H[i];
    for(ll i = 2; i <= N; i++){
        if(abs(A - (T - H[ans] * 0.006)) > abs(A - (T - H[i] * 0.006))){
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};


/** Problem0096 : Sum of 4 Integers II **/
int main()
{
	int num;
	
	int count1[4001]={0};
	for (int a=0; a<=1000; a++) {
		for (int b=0; b<=1000; b++) {
			count1[a+b]++;
		}
	}
	
	while (cin>>num) {
		int ans=0;
		for (int ab=0; ab<=2000; ab++) {
			if (num-ab<=2000 && num-ab>=0)
				ans += count1[ab] * count1[num-ab];
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 1184
package main

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

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

// 期待値の2倍を返す
func expected(p int64) int64 {
	return 1 + p
}

func solve(n int, k int, ps []int64) int64 {
	cur := int64(0)
	i := 0
	for ; i < k; i++ {
		cur += expected(ps[i])
	}
	ret := cur
	for ; i < n; i++ {
		cur -= expected(ps[i - k])
		cur += expected(ps[i])
		if cur > ret {
			ret = cur
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := nextInt()
	k := nextInt()
	ps := nextInts(n)
	res := solve(int(n), int(k), ps)
	fmt.Fprintln(out, float64(res) * 0.5)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define ll long long
using namespace std;
ll bsum[214514];
priority_queue<ll, vector<ll>, greater<ll> > lar;
priority_queue<ll> sma;
ll lsum,ssum;
void addnum(ll x){
	ll lsz = lar.size();
	ll ssz = sma.size();
	ll ltp = lar.top();
	ll stp = sma.top();
	if( lsz == ssz ){
		if(ltp >= x){
			sma.push(x);
			ssum += x;
		}
		else{
			sma.push(ltp);
			ssum += ltp;
			lar.pop();
			lsum -= ltp;
			lar.push(x);
			lsum += x;
		}
	}
	else{
		if(stp<=x){
			lar.push(x);
			lsum += x;
		}
		else{
			lar.push(stp);
			lsum +=stp;
			sma.pop();
			ssum -= stp;
			sma.push(x);
			ssum += x;
		}
	}
}
ll getmid(){
	return sma.top();
}
ll getval(){
	ll lsz = lar.size()-1;
	ll ssz = sma.size()-1;
	ll md = getmid();
	return (lsum-md*lsz) + (md*ssz-ssum);
}
signed main(){
	ll n;
	cin>>n;
	lar.push(10000000000000009LL);
	sma.push(-10000000000000009LL);
	for(int i=1;i<=n;i++){
		int tp;
		cin>>tp;
		if(tp == 1){
			ll ta,tb;
			cin>>ta>>tb;
			addnum(ta);
			bsum[i]=bsum[i-1]+tb;
		}
		if(tp == 2){
			bsum[i]= bsum[i-1];
			cout<<getmid()<<" "<<getval()+bsum[i]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5364
#include <stdio.h>



int main()
{
	int S;
	int h,m,s;
	scanf("%d",&S);
	h=S/3600;
	m=(S-(h*3600))/60;
	s=S-(h*3600+m*60);

	printf("%d:%d:%d\n",h,m,s);




	return 0;
}

Measured memory_bytes: 592
#include <stdio.h>
#include <ctype.h>

#define N 128
#define ADD -1
#define SUB -2
#define MUL -3
#define DIV -4
#define ESC -5
#define LPR -6
#define RPR -7

static
int * e;

static
int eval_1st ( void ),
    eval_2nd ( void ),
    eval_3rd ( void );

static
int eval_1st (
  void
  )
{
  if ( *e == LPR )
  {
    int res;

    ++e;
    res = eval_3rd ( );
    ++e;
    return ( res );
  }
  else
  {
    return ( *( e++ ) );
  }
}

static
int eval_2nd (
  void
  )
{
  int left = eval_1st ( );

  while ( *e == MUL || *e == DIV )
  {
    ++e;
    if ( e[ -1 ] == MUL ) left *= eval_1st ( );
    else                  left /= eval_1st ( );
  }

  return ( left );
}

static
int eval_3rd (
  void
  )
{
  int left = eval_2nd ( );

  while ( *e == ADD || *e == SUB )
  {
    ++e;
    if ( e[ -1 ] == ADD ) left += eval_2nd ( );
    else                  left -= eval_2nd ( );
  }

  return ( left );
}

static
int eval (
  void
  )
{
  return ( eval_3rd ( ) );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;

  scanf ( "%d ", &n );
  while ( n-- )
  {
    int   expr[ N ] = { 0 };
    int * p = expr;

    for ( ; ; )
    {
      int ch = ' ';

      while ( isspace ( ch ) )  ch = getchar ( );

      switch ( ch )
      {
        case '+':   ++p; *( p++ ) = ADD; break;
        case '-':   ++p; *( p++ ) = SUB; break;
        case '*':   ++p; *( p++ ) = MUL; break;
        case '/':   ++p; *( p++ ) = DIV; break;
        case '=':   ++p; *( p++ ) = ESC; goto BREAKK;
        case '(':        *( p++ ) = LPR; break;
        case ')':   ++p; *( p   ) = RPR; break;
        default:
          *p = *p * 10 + ( ch - '0' );
          break;
      }
    }
BREAKK:
    e = expr;
    printf ( "%d\n", eval ( ) );
  }

  return ( 0 );
}

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

int main() {
  string s;
  cin >> s;
  if (s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi") cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,ans;
int main()
{
	cin>>n>>m>>k;
	if(n<=m)
	{
		cout<<"1\n";
		return 0;
	}
	if(m<=k)
	{
		cout<<"-1\n";
		return 0;
	}
	cout<<((n-m)%(m-k)==0?(n-m)/(m-k):(n-m)/(m-k)+1)*2+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s;
bool x[5];
int main(void){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='N'){
            x[0]=true;
        }else if(s[i]=='S'){
            x[1]=true;
        }else if(s[i]=='W'){
            x[2]=true;
        }else{
            x[3]=true;
        }
    }
    if(x[0]==x[1]&&x[2]==x[3]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}



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

const int N = 2e5+69;
int arr[N];

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

 int n;
 cin >> n;
 for(int i=1; i<=n; i++){
 	cin >> arr[i];
 }

 map<int,int> mp;
 mp[arr[n]-n]++;
 long long ans = 0;

 for(int i=n-1; i>=1; i--){
 	ans += 1ll*mp[-i-arr[i]];
 	mp[arr[i]-i]++;
 }

 cout << ans << "\n";

}


Measured memory_bytes: 21416
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define fast            ios_base::sync_with_stdio(false)
#define mems(x, y)      memset(x, y, sizeof x)
#define pii             pair < int, int >
#define prec(x)         << fixed << setprecision(x)
#define itf             it->first
#define its             it->second
#define it(x)           it = x.begin(); it != x.end(); it++
#define pq_max(x)       priority_queue < x >
#define pq_min(x)       priority_queue < x, vector < x >, greater < x > >
#define ll              long long
#define nl              << "\n"
#define spc             << " "
#define pb              push_back
#define inf             0x3f3f3f3f
#define PI              3.14159265358979323846
#define E               2.71828182845904523536
#define gamma           0.5772156649
#define EPS             1e-9
#define toint(st, x)    stringstream ss(st); ss >> x
// =======Debug========//
#define watch(x)        cout << (#x) spc << x nl
//int fx[] = {1, -1, 0, 0};
//int fy[] = {0, 0, 1, -1};
const int mod=1e9+7;
const ll mxn=2e5+9;
int cases = 1;
//ll BigMod(ll n,ll power) {ll ans=1;assert(power>=0);n%=mod;while(power>0){if(power&1) ans=(ans*n)%mod;n=(n*n)%mod;power>>=1;}return ans%mod;}
//ll ModInverse(int n)  { return BigMod(n, mod - 2); }
int main()
{
    //    freopen("input.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
    int n;
    double d;
    cin >> n >> d;
    ll x[n], y[n];
    for(int i = 0; i < n; i++)      cin >> x[i] >> y[i];
    int cnt = 0;
    for(int i = 0; i < n; i++ ) {
        double dist = sqrt((x[i]*x[i]) + (y[i]*y[i]));
        if(dist <= d)   cnt++;
    }
    cout << cnt nl;
    return 0;
}


Measured memory_bytes: 6856
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>

int main(){
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for(int i=0; i<n; i++){
		std::cin >> a[i];
	}
	double ave = (double)std::accumulate(a.begin(), a.end(), 0) / a.size();
	int min_index = 0;
	double min_value = 10000;
	for(int i=0; i<n; i++){
		double value = std::abs(a[i] - ave);
		if(std::abs(value - min_value) < 0.0000001) continue;
		if(value < min_value){
			min_index = i;
			min_value = value;
		}
	}

	std::cout << min_index << "\n";
	return 0;
}


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

int N;
vector<int> A;

bool check1() {
    bool res = false;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 0) continue;
        if ((N - 1 & i) == i) res = !res;
    }
    return res;
}

bool check0() {
    for (int i = 0; i < N; i++)
        if (A[i] == 1) return true;
    return false;
}

int main() {
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        A[i] = c - '1';
    }
    if (check1())
        cout << 1 << endl;
    else if (check0())
        cout << 0 << endl;
    else {
        for (int i = 0; i < N; i++) A[i] /= 2;
        cout << (check1() ? 2 : 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <cstdio>

#define abs(a) (a < 0 ? -(a) : (a))

int main()
{
  int n;
  int acc[101] = {0};
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; ++i)
  {
    int w;
    scanf("%d", &w);
    acc[i] = acc[i - 1] + w;
    sum += w;
  }
  int ans = 1e10;
  for (int i = 1; i < n; ++i)
  {
    if (ans > abs(sum - 2 * acc[i])) ans = abs(sum - 2 * acc[i]);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
def gcd(x, y)
  if y == 0
    return x
  else
    gcd(y, x % y)
  end
end

def main
  n, m = gets.chomp.split.map(&:to_i)
  a = gets.chomp.split.map(&:to_i)
  
  #aを2で割る
  a = a.map {|v| v / 2}

  #aを２で割り切れるだけ割る
  isSame = true
  while a[0] % 2 == 0 do
    n.times do |i|
      if a[i] % 2 == 0
        a[i] /= 2
      else
        isSame = false
      end 
    end
    m /= 2
  end

  return 0 if isSame == false
  a.each do |v|
    return 0 if v % 2 == 0
  end

  #aの最小公倍数を求める
  lcm = 1
  n.times do |i|
    g = gcd(lcm, a[i])
    lcm = (lcm / g) * a[i] 
    return 0 if lcm > m
  end

  #m以下の中でlcmの奇数倍の総和を求める
  return (m / lcm + 1) / 2
end

puts main

Measured memory_bytes: 10508
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,k,i,ans;
ll a[5001],sum;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>k;
    for(i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(i=n;i>=1;i--)
     if(sum+a[i]<k)sum+=a[i],ans++;
     else ans=0;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
int h;
int a[55];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=k;i++)
		h+=a[i];
	cout<<h<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
const int MOD = 1e9+7;
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
signed main()
{
    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    int T=1;
   // cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        int n=s.size();
        vi v(n,0);
        if(s[n-1]=='W')v[n-1]=1;
        for(int i=n-2;i>=0;i--)
        {
            if(s[i]=='W')
            {
                v[i]=v[i+1]+1;
            }
            else
            {
                v[i]=v[i+1];
            }
        }
        int ans=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='B')
            {
                ans+=v[i];
            }
        }
        cout<<ans<<"\n";

    }

}


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

const int N = 2e6 + 100, M = 6, MOD = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {a += b;return (a < 0? a + MOD: a >= MOD? a - MOD: a);}
void _sum(int &a, int b) {a = sum(a, b);}
int mul(int a, int b) {return 1LL * a * b % MOD;}
void _mul(int &a, int b) {a = mul(a, b);}

int power(int a, int b) {
	int res = 1;
	while(b) {
		if(b & 1)
			_mul(res, a);
		_mul(a, a);
		b >>= 1;
	}
	return res;
}

int n, ans, X[M], Y[M], fac[N], pow_fac[N];

int choose(int a, int b) {
	return a > b? 0: mul(fac[b], mul(pow_fac[a], pow_fac[b - a]));
}

void pre_pro() {
	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = mul(fac[i - 1], i);
	for (int i = 0; i < N; i++)
		pow_fac[i] = power(fac[i], MOD - 2);
}

int g(int x, int y, int X, int Y) {
	return sum(sum(choose(y + Y + 1, x + X + y + Y + 2), -choose(y + Y + 1, x + 1 + y + Y)), sum(-choose(y, x + X + y + 1), choose(y, x + y)));
}

int f(int x, int y, int xx, int yy) {
	return mul(g(x - X[1], y - Y[1], X[1] - X[0], Y[1] - Y[0]), g(X[4] - xx, Y[4] - yy, X[5] - X[4], Y[5] - Y[4]));
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	pre_pro();
	for (int i = 0; i < M; i++)
		cin >> X[i];
	for (int i = 0; i < M; i++)
		cin >> Y[i];
	
	for (int x = X[2]; x <= X[3]; x++)
		_sum(ans, mul(f(x, Y[2] - 1, x, Y[2]), -(x + Y[2] - 1)));
	for (int y = Y[2]; y <= Y[3]; y++)
		_sum(ans, mul(f(X[2] - 1, y, X[2], y), -(X[2] - 1 + y)));
	
	for (int x = X[2]; x <= X[3]; x++)
		_sum(ans, mul(f(x, Y[3], x, Y[3] + 1), x + Y[3]));
	for (int y = Y[2]; y <= Y[3]; y++)
		_sum(ans, mul(f(X[3], y, X[3] + 1, y), X[3] + y));
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 16000
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        int N = sc.nextInt();
        int A[] = new int[N];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
        }
        
        int kyori_a = A[N-1]-A[0];
        int Aminus[] = new int[N];
        for (int i = 0; i < A.length; i++) {
            Aminus[i] = K-A[i];
        }
        int kyori_b = K;
        for (int i = 0; i < Aminus.length-1; i++) {
            kyori_b = Aminus[i+1] +A[i];
            if (kyori_a > kyori_b) {
                kyori_a = kyori_b;
            }
        }
        System.out.println(kyori_a);
      	sc.close();
    }
		

}

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int members;
  cin >> members;
  int arr[members+1];
  memset(arr, 0, sizeof(arr));
  int get;
  for(int i = 0; i < members - 1; i++){
    cin >> get;
    arr[get]++;
  }
  for(int i = 1; i <= members; i++){
    cout << arr[i] << '\n';
  }
  return 0;
}

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

int main(){
  std::string vec = "abcdefghijklmnopqrstuvwxyz";
  std::string C;
  std::cin >> C;
  std::string::size_type pos = vec.find(C);
  std::cout << vec[pos + 1] << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<=(n); i++)
typedef long long ll;
using namespace std;
 
int main(){
    int N; cin >> N;
    int count=0;
    rep(i,14){
        rep(j,25){
            count=7*i+4*j;
            if(count==N){
                cout << "Yes";
                return 0;
            }
            count=0;
        }
    }
    cout << "No";
}

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

using namespace std;
typedef long long ll;

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

  for (int i = 0; i <= N; i++) {
    for (int j = 0; (i + j) <= N; j++) {
      int k = ((N - (i + j)) < 0) ? 0 : N - (i + j);
     if (Y == (10000 * i + 5000 * j + 1000 * k)) {
       cout << i << " " << j << " " << k << endl;
       return 0;
     }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl
 
#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n,m;
int a,b;
P edge[10000];
int aa,bb;
int ahai[55];
int ans;
//int bhai[55];
vector<int> G[55];
bool same_pair(int a,int b,int c,int d)
{
    if(a==c&&b==d)return true;
    if(a==d&&b==c)return true;
    return false;
}
void asearch(int now)
{
    rep(i,G[now].size())
    {
        if(same_pair(aa,bb,now,G[now][i]))continue;
        if(ahai[G[now][i]]==0)
        {
            ahai[G[now][i]]=1;
            asearch(G[now][i]);
        }
    }
}
int main()
{
    cin>>n>>m;
    rep(i,m)
    {
        cin>>a>>b;
        a--;b--;
        edge[i]=P(a,b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,m)
    {
        aa=edge[i].first;
        bb=edge[i].second;
        rep(i,55)
        {
            ahai[i]=0;//bhai[i]=0;
        }
        ahai[aa]=1;
        asearch(aa);
        if(ahai[bb]==0)
        {
            ans++;
        }
        //bsearch(bb);

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

Measured memory_bytes: 256
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, M, K = [int(x) for x in input().strip().split()]
    MOD = 998244353
    if M == 1:
        if N == 1:
            print(1)
            exit()
    
    fact = [1] * (N+1)
    inv_fact = [1] * (N+1)
    for i in range(1, N+1):
        fact[i] = ((i) * fact[i-1]) % MOD
    
    inv_fact[-1] = pow(fact[-1], MOD-2, MOD)
    for i in range(N-1):
        inv_fact[N-i-1] = (inv_fact[N-i] * (N - i)) % MOD

    def nCr(n, r):
        if r == 0 or r == n:
            return 1
        r = min(r, n - r)
        return (fact[n] * inv_fact[n-r] * inv_fact[r]) % MOD

    ans = (M * pow(M-1, N-1, MOD)) % MOD
    for k in range(K):
        ans = (ans + (M * pow(M-1, N-1-(k+1), MOD)) * nCr(N-1, k+1)) % MOD

    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> g(n);
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }
  int ans = 0;
  for (int st = 0; st < n; st++) {
    vector<int> dist(n, -1);
    vector<int> que(1, st);
    dist[st] = 0;
    for (int b = 0; b < (int) que.size(); b++) {
      for (int i = 0; i < n; i++) {
        if (g[que[b]][i] == '1' && dist[i] == -1) {
          que.push_back(i);
          dist[i] = dist[que[b]] + 1;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (g[i][j] == '1' && dist[i] == dist[j]) {
          cout << -1 << '\n';
          return 0;
        }
      }
    }
    int mx = *max_element(dist.begin(), dist.end());
    ans = max(ans, mx);
  }
  cout << ans + 1 << '\n';
  return 0;
}

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

int main()
{
	string s;
	while (cin >> s) {
		if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
			cout << "Bad\n";
		else cout << "Good\n";
	}
}

Measured memory_bytes: 3132
n, k = [int(i) for i in input().split()]
s = input()

l_r = 0
r_l = 0
prev_s = s[0]
ans = 0
for cur_s in s[1:]:
    if prev_s == cur_s:
        ans += 1
    elif cur_s == 'L':
        r_l += 1
    else:
        l_r += 1
    prev_s = cur_s

if min(l_r, r_l) >= k:
    ans += 2 * k
else:
    ans += 2 * min(l_r, r_l)
    if max(l_r, r_l) >= k:
        ans += k - min(l_r, r_l)
    else:
        ans += max(l_r, r_l) - min(l_r, r_l)

print(ans)


Measured memory_bytes: 3316
class Card
  include Comparable

  attr_reader :design
  attr_reader :number
  def initialize(design, number)
    @design = design
    @number = number
  end

  def <=>(other)
    @number <=> other.number
  end

  def to_s
    "#{@design} #{@number}"
  end
end

def partition(a, p, r)
  x = a[r]
  i = p - 1
  p.upto(r - 1) do |j|
    if a[j] <= x
      i += 1
      a[i], a[j] = a[j], a[i]
    end
  end
  a[i+1], a[r] = a[r], a[i+1]
  i+1
end

def quicksort(a, p, r)
  if p < r
    q = partition(a, p, r)
    quicksort(a, p, q-1)
    quicksort(a, q+1, r)
  end
end

def stable?(orig_order, after_order)
  orig_order.all?{|e| e[1].join == after_order[e[0]].join }
end

n = gets.to_i
cards = n.times.map{ d, n = gets.split; Card.new(d, n.to_i) }

orig_order = Hash.new{|h, k| h[k] = []}
cards.each{|c| orig_order[c.number] << c.design }

quicksort(cards, 0, cards.size-1)


after_order = Hash.new{|h, k| h[k] = []}
cards.each{|c| after_order[c.number] << c.design }

puts stable?(orig_order, after_order) ? 'Stable' : 'Not stable'
puts cards

Measured memory_bytes: 42916
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

vector<LL> dp, subtree;
vector<vector<LL>> adj;
vector<bool> visited;
const LL M=2*100000+1;

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
            ans%=MOD;
        }
        base = base * base;
        base%=MOD;
        y = y >> 1;
    }
    return ans;
}

LL dfs(LL s)
{
    if (!visited[s])
    {
        visited[s] = true;
        LL cnt = 1;
        for (auto &x : adj[s])
        {
            cnt += dfs(x);
        }
        subtree[s] = cnt;
        return cnt;
    }
    else
        return 0;
}
void dfs2(LL s, LL par, LL sub_s, LL sub_par)
{
    if (!visited[s])
    {
        visited[s] = true;
        LL x = sub_par - sub_s;
        LL y = sub_s;
        //subtree[s] += x ;
        //subtree[par] -= y;
        dp[s] = (((dp[par] *y)%MOD)*POW(x,MOD-2))%MOD;

        for (auto &t : adj[s])
        {
            dfs2(t, s, subtree[t], sub_s + x);
        }
    }
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp;
    cin >> n;
    adj.resize(n + 1);
    visited.resize(n + 1);
    subtree.resize(n + 1);
    dp.resize(n + 1);

    dp[1]=1;
    for(i=1;i<=n;i++)
    {
        dp[1]=(dp[1]*i)%MOD;
    }

    for (i = 1; i <= n; i++)
    {
        visited[i] = false;
    }
    for (i = 1; i <= n - 1; i++)
    {
        cin >> j >> k;
        adj[j].pb(k);
        adj[k].pb(j);
    }

    dfs(1);
    for (i = 1; i <= n; i++)
    {
        visited[i] = false;
        dp[1] = (dp[1]*POW(subtree[i],MOD-2))%MOD;
    }
    visited[1]=true;
   // debug(dp[1]);

    for (auto &x : adj[1])
    {
        dfs2(x, 1, subtree[x], subtree[1]);
    }
    for(i=1;i<=n;i++)
    {
        cout<<dp[i]<<endl;
    }

    return 0;
}


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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        char c[100];
        for(int i=0; i<n; i++){
            cin >> c[i];
        }

        int cnt[26] = {0};
        for(int i=0; i<n; i++){
            cnt[(int)(c[i]-'A')]++;
            int max1 = -1;
            int max2 = -1;
            for(int j=0; j<26; j++){
                if(cnt[j]>max1){
                    max2 = max1;
                    max1 = cnt[j];
                }
                else if(cnt[j]>max2){
                    max2 = cnt[j];
                }
            }

            if(max1-max2>n-(i+1)){
                for(int j=0; j<26; j++){
                    if(cnt[j]==max1){
                        cout << (char)(j+'A') << ' ';
                        break;
                    }
                }
                cout << (i+1) <<endl;
                break;
            }
            if(i==n-1){
                cout<<"TIE"<<endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double

int ans=0;
int32_t main()
{
	IOS
	int a,b;cin>>a>>b;
	if(a&1)
	{
		if(b&1)
		{
			if( ((b-a)/2)&1 )
			{
				ans=a^1;
			}
			else
			{
				ans=a;
			}
		}
		else
		{
			if( ((b-a-1)/2)&1 )
			{
				ans=a^b^1;
			}
			else
			{
				ans=a^b;
			}
			
		}
	}
	else
	{
		if(b&1)
		{
			if( ((b-a+1)/2)&1 )
			{
				ans=1;
			}
			else
			{
				ans=0;
			}
		}
		else
		{
			if( ((b-a)/2)&1 )
			{
				ans=b^1;
			}
			else
			{
				ans=b;
			}
		}
	}
	cout<<ans<<endl;
}
			
	
	
	
	
	

	

	

	
		


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

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

    string a;
    cin >> a;
    int n = a.size();
    vector<int> x;
    int tmp = 0;
    for (int i = n - 1; i >= 0; i--) {
        tmp |= 1 << (a[i] - 'a');
        if (tmp == (1 << 26) - 1) {
            tmp = 0;
            x.emplace_back(i);
        }
    }
    tmp = 0;
    int cnt = 0;
    string ans;
    while (!x.empty()) {
        tmp = 0;
        int z = *x.rbegin();
        x.pop_back();
        for (; cnt < z; cnt++) {
            tmp |= 1 << (a[cnt] - 'a');
        }
        rep(i, 0, 26) {
            if (!((tmp >> i) & 1)) {
                ans.push_back('a' + i);
                break;
            }
        }
        while (a[cnt] != *ans.rbegin()) cnt++;
        cnt++;
    }
    tmp = 0;
    for (; cnt < n; cnt++) {
        tmp |= 1 << (a[cnt] - 'a');
    }
    rep(i, 0, 26) {
        if (!((tmp >> i) & 1)) {
            ans.push_back('a' + i);
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

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

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

int n;
ll ans = 0;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                ans += gcd(gcd(i,j),k);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
using namespace std;
int main() {
	int N, M;
	cin >> N;
	vector<string> s(N);
	

	for (int i = 0; i < N; i++) {
		cin >> s[i];
		
	}
		
	cin >> M;
	vector<string> t(M);
	for (int i = 0; i < M; i++)
		cin >> t[i];

	int mx = 0;
	for (int i = 0; i < N; i++) {
		int scount = 0;
		int tcount = 0;
		for (int j = 0; j < N; j++) {
			if (s[i] == s[j])
				scount++;
		}
		for (int j = 0; j < M; j++) {
			if (s[i] == t[j])
				tcount++;
		}
		mx = max(mx, scount - tcount);
	}
	cout << mx << endl;
	//cin >> N;
	return 0;
}

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

using namespace std;

int M, N;
vector<int> Players;
string Expected, Words;


void getExpectedAnswer(int data) {
	stringstream ss;

	if (data % 3 == 0 && data % 5 == 0) {
		Expected = "FizzBuzz";
		return;
	}

	if (data % 3 == 0) {
		Expected = "Fizz";
		return;
	}

	if (data % 5 == 0) {
		Expected = "Buzz";
		return;
	}

	ss << data;
	ss >> Expected;
	//Expected = data + '0';
}

void show() {
	int size;

	size = Players.size();
	for (int i = 0; i < size; ++i) {
		cout << Players[i];
		if (i != size-1) {
			cout << " ";
		}
	}
	cout << endl;
}

int main() {
	vector<int>::iterator iter;

	while (cin >> M >> N, M) {
		Players.clear();
		for (int i = 0; i < M; ++i) {
			Players.push_back(i+1);
		}
		iter = Players.begin();

		for (int cnt = 0; cnt < N; ++cnt) {
			cin >> Words;
			if (Players.size() == 1) {
				continue;
			}
			getExpectedAnswer(cnt+1);
			//cout << "expected:" << Expected << endl;
			if (Words != Expected) {
				iter = Players.erase(iter);
			}
			else {
				++iter;
			}
			if (iter == Players.end()) {
				iter = Players.begin();
			}
		}
		show();
	}

	return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans,a,b;
	cin>>n;
	if(n==1)
	{
		cout<<"Hello World";
	}
	else
	{
		cin>>a>>b;
		cout<<a+b;
	}
	return 0;
}

Measured memory_bytes: 256
#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 ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, k, arr[300005];
ll pos[300005];
pi brr[300005];
pi cr[300005]; //counter arr

struct node{
	ll s, e, m, total;
	node *l, *r;
	node (ll _s, ll _e): s(_s), e(_e), m((_s + _e)/2), total(0){
		if (s != e){
			l = new node(s, m);
			r = new node(m + 1, e);
		}
	}
	
	//point update
	void update(ll x, ll nv){
		
		if (s == e){
			total = nv;
			return;
		}
		if (x > m) r -> update(x, nv);
		if (x <= m) l -> update(x, nv);

		total = max(l -> total, r -> total);
	}
	
	ll range_max(ll x, ll y){
		if (s == x && e == y) return total;
		if (x > m) return r -> range_max(x, y);
		if (y <= m) return l -> range_max(x, y);
		return max(l -> range_max(x, m), r -> range_max(m + 1, y));		
	}
} *root;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	REP(i, 0, n) cin >> arr[i];
	REP(i, 0, n) brr[i] = MP(arr[i], i);
	sort(brr, brr + n);
	REP(i, 0, n) pos[brr[i].second] = i;
	
	ll lc = 0, rc = 0;
	REP(i, 0, n){
		while (llabs(brr[lc].first - brr[i].first) > k) lc++;
		while (rc+1 < n && llabs(brr[rc+1].first - brr[i].first) <= k) rc++;
		cr[i] = MP(lc, rc);
	}
	
	//REP(i, 0, n){
	//	cout << i << " " << cr[i].first << " " << cr[i].second << endl;
	//}
	
	root = new node(0, n - 1);
	ll ans = 0;
	REP(i, 0, n){
		ll curans = root -> range_max(cr[pos[i]].first, cr[pos[i]].second) + 1;
		ans = max(curans, ans);
		root -> update(pos[i], curans);
	}
	cout << ans << endl;
	
	
	
	
}

//cout.flush()
//cout << fixed << setprecision(9) << x << endl;

Measured memory_bytes: 55192
#include<iostream>
using namespace std;
int main(){
  int t[5],n[5];
  for(int i=0;i<4;i++){
    cin>>t[i]>>n[i];
    if(t[i]==1)t[i]=n[i]*6000;
    else if(t[i]==2)t[i]=n[i]*4000;
    else if(t[i]==3)t[i]=n[i]*3000;
    else t[i]=n[i]*2000;
  }
  for(int i=0;i<4;i++){
    cout<<t[i]<<"\n";
  }
  return 0;
}
  



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

#define ll long long
#define ar array

const int mxH=10, mxW=1e3;
int h, w, k, ans=1e9;
string g[mxH];
vector<int> v[mxW];

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

	cin >> h >> w >> k;
	for(int i=0; i<h; ++i)
		cin >> g[i];
	for(int i=0; i<1<<h-1; ++i) {
		int ca=__builtin_popcount(i);
		bool flag = false;
		for(int j=0; j<w; ++j) {
			int s=0;
			for(int k=0; k<h; ++k) {
				s+=g[k][j]&1;
				if(i>>k&1) {
					v[j].push_back(s);
					s=0;
				}
			}
			v[j].push_back(s);
			for(int vi : v[j])
				if(vi>k) {
						ca=1e9;
						flag = true;
						break;
				}
		}
		vector<int> u(v[0].size());
		for(int j=0; j<w; ++j) {
			bool split=0;
			for(int l=0; l<u.size(); ++l)
				split|=u[l]+v[j][l]>k;
			if(split) {
				++ca;
				u=vector<int>(u.size());
			}
			for(int l=0; l<u.size(); ++l)
				u[l]+=v[j][l];
			v[j].clear();
		}
		//cout << i << " " << ca << endl;
		ans=min(ca, ans);
	}
	cout << ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MAX 100005

using namespace std;

int h[MAX];
int minimum[MAX];

int n;

int main(){
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>h[i];
    memset(minimum, -1, sizeof(minimum));
    minimum[0]=0;
    for(int i=0; i<n-1; i++){
        //if(i<n-1)cout<<minimum[i]<<" "<<minimum[i+1]<<" "<<minimum[i+2]<<"\n";
        if(minimum[i+1]<0) minimum[i+1] = minimum[i]+abs(h[i]-h[i+1]);
        minimum[i+1] = min(minimum[i+1], minimum[i]+abs(h[i]-h[i+1]));
        if(i<n-2) {
                if(minimum[i+2]<0) minimum[i+2] = minimum[i]+abs(h[i]-h[i+2]);
                minimum[i+2] = min(minimum[i+2], minimum[i]+abs(h[i]-h[i+2]));
        }
    }
    cout<<minimum[n-1]<<"\n";
    return 0;
}
/*
4
10 30 40 20
0  20 30 30

4
10 50 10 10
*/


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void p(){ cout << "pairwise coprime" << endl;}
void s(){ cout << "setwise coprime" << endl;}
void no(){ cout << "not coprime" << endl;}

//-----------------------------------------
//-----------------------------------------

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

  ll n;
  cin >> n;
  vll a(n);
  REP(i,n) cin >> a[i];
  ll tmp = gcd(a[0], a[1]);
  for(ll i = 2; i < n; i++){
    tmp = gcd(tmp, a[i]);
  }
  if(tmp != 1){
    no();
    return 0;
  }

  vector<bool> flag(1000000 + 10, false);

  for(ll i = 0; i < n; i++){
    if(flag[a[i]]){
      s();
      return 0;
    }
    for(ll j = 2; j * j <= a[i]; j++){
      if(a[i] % j == 0){
        if(flag[j] || flag[a[i]/ j]){
          s();
          return 0;
        }
        flag[j] = true;
        flag[a[i] / j] = true;
      }
    }
    if(a[i] != 1) flag[a[i]] = true;
  }

  p();
    
  return 0;
}



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

ll dp[2001][2001];
inline void chmax(ll& a, ll b) {
	a = max(a,b);
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	dp[0][0] = 0;
	vector<P> p;
	rep(i,n) p.emplace_back(a[i],i);
	sort(p.rbegin(), p.rend());
	rep(i,n) {
		int pi = p[i].second;
		rep(l,i+1) {
			int r = i-l;
			chmax(dp[i+1][l+1], dp[i][l]+ll(pi-l)*a[pi]);
			chmax(dp[i+1][l], dp[i][l]+ll((n-r-1)-pi)*a[pi]);
		}
	}
	ll ans = 0;
	rep(i,n+1) chmax(ans, dp[n][i]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 26208
#pragma optimization_level 3
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  1e+9 + 7;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ll n,a[N];
string s;

void MAIN(int tc){
	cin >> s;
    if(s[s.size() - 1] == 's') cout<<s +"es";
    else cout<<s+"s";
}

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

    int test_cases = 1;
    //cin>>test_cases;
    for(int i = 1; i <= test_cases; i++){
        MAIN(i);
    }
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

	vector<long long> a(n);
	cin >> a[0];
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		a[i] += a[i - 1];
	}

	long long mn = 101010101010101010;
	for (int i = 0; i < n - 1; i++) {
		mn = min(mn, abs(a[n - 1] - a[i] - a[i]));
	}
	cout << mn << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int main()
{     int n,m=1,i,j,k;
      cin>>n>>k;
      for(i=1;i<=n;i++)
        m=min(m*2,m+k);
      cout<<m<<endl;
	  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define f first 
# define s second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
# define debug cerr<<"ERROR"<<endl
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;

const int dx[]={1,0,-1,0,-1,-1,1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1}; 
const int inf=1e9,mod=1e9+7,N=2e5+5;



void solve(){
	int n;
	cin>>n;
	vector<int>v;
	int ans=0;
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		if(x&1){
			v.pb(x);
		}
		else{
			int cnt=0;
			while(x%2==0){
				x/=2;
				cnt++;
			}
			ans+=cnt;
		}
	}
	sort(all(v));
	int res=0;
	while(sz(v)>0){
		ll y=v.back()*1LL;
		v.pop_back();
		while(y*3<=1e9){
			res++;
			y*=3;
		}
	}
	cout<<ans;
}

int main(){
 	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)solve();
}


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

#define _LL long long
_LL* mallocint(_LL si)
{
    return (_LL*) malloc(si * sizeof(_LL));
}

_LL* inputint(_LL n)
{
    _LL *ans = mallocint(n);
    for( _LL i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}


int main()
{
    _LL n, m , v, p;
    cin >> n >> m >> v >> p;
    vector<_LL> a;
    for( _LL i = 0; i < n; i++ ) 
    {
        _LL tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());

    if( v < p )
    {
        _LL border = a[n - 1 - (p - 1)];
        for( _LL i = 0; i < n; i++ ) 
        {
            if( a[i] + m >= border )
            {
                cout << n - i;
                return 0;
            }
        }
    }
    else
    {
        _LL allsum = 0;
        for( _LL i = 0; i < n - p + 1; i++ )
        {
            allsum += a[i];
        }
        allsum += m * (v - p + 1);
        for( _LL i = 0; i < n - p + 1; i++ ) 
        {
            _LL border = a[n - 1 - (p - 1)];
            _LL border2 = (allsum - 1) / (n - p + 1 - i) + 1;
//            cout << "i = " << i << " allsum = " << allsum << " border = " << border << endl; 
            if( a[i] + m >= border && a[i] + m >= border2 )
            {
                cout << n - i;
                return 0;
            }
            allsum -= m + a[i];
        }
    }
    cout << p;    

    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    int ans; cin >> ans;
    for (int i = 1; i < N; i++) {
        int a; cin >> a;
        ans = __gcd(ans, a);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256