akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static int mod = (int)Math.Pow(10, 9) + 7;
        static void Main(string[] args)
        {
            //[summary]C - Reconciled?
            var line = ReadLine();
            int n = line[0];
            int m = line[1];

            long perms = CountPermutations(n, m);

            Console.WriteLine(perms);
        }

        static long CountPermutations(int n, int m)
        {
            if (Math.Abs(n - m) > 1)
            {
                return 0;
            }
            else
            {
                long dogs = GetFactorial(n);
                long monkeys = GetFactorial(m);

                if (n == m)
                {
                    return dogs * monkeys * 2 % mod;
                }
                else
                {
                    return dogs * monkeys % mod;
                }
            }
        }

        static long GetFactorial(int n)
        {
            long ans = 1;
            
            for(int i = 2; i <= n; i++)
            {
                ans = ans * i % mod;
            }

            return ans;
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}


Measured memory_bytes: 11348
#![allow(non_snake_case, unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! read_single_value {
	($t:ty) => {
        impl InputValue for $t {
            fn parse(s: &str) -> $t { s.parse().unwrap() }
        }
	}
}
read_single_value!(i32);
read_single_value!(i64);
read_single_value!(f32);
read_single_value!(f64);
read_single_value!(usize);
read_single_value!(String);

macro_rules! read_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
read_tuple!(A, B);
read_tuple!(A, B, C);

// ===

fn main() {
    let (a, b): (i32, i32) = read();
    println!("{}", max(0, a-b));
}


Measured memory_bytes: 4352
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	ll a, b, k;
	cin >> a >> b >> k;
	
	cout << max((ll)0, a-k) << " " << max((ll)0, b-max((ll)0,k-a)) << endl;
}

Measured memory_bytes: 256
def solve():
    n = int(input())
    a = tuple(int(x) for x in input().split())

    memo = tuple([None] * n for _ in range(n))
    for i, aa in enumerate(a):
        memo[i][i] = aa

    for l in range(n - 2, -1, -1):
        for r in range(l + 1, n):
            memo[l][r] = max(a[r] - memo[l][r - 1], a[l] - memo[l + 1][r])

    print(memo[0][n - 1])


if __name__ == '__main__':
    solve()

# [l,r]を
# l:=配列aの右端から左にシフト
# r:=lと一致する位置からn-1まで右にシフト
# と考えると、l==rは既にメモ化済みなので、l=n-2以前、r=l+1以降を調べればよい
# 漸化式で使う値は、
# lがより右にいるときの計算結果（前のループで計算済み）と
# rがより左にいるときの計算結果（一番左でもl==rなので計算済み）
# なので、参照する値がNoneになることはなく、Noneのチェックは不要になる


Measured memory_bytes: 179804
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#define inf 1000000000

using namespace std;
typedef pair<int, int> P;

struct edge{
	int to, cost;
	edge(int a, int b){
		to = a, cost = b;
	}
};

int N, M, cap;
int S, T;
int station[305];
map<string, int> name;
string src, dest;
vector<edge> G[6005], stG[305];

int V;
int get(string str)
{
	map<string, int>::iterator p;
	p = name.find(str);
	if(p == name.end()){
		V++;
		name[str] = V;
		return V;
	}
	else{
		return p->second;
	}
}

int d[6005];
bool used[6005];

void dijkstra(vector<edge> G[], int s)
{
	priority_queue<P, vector<P>, greater<P> > Q;
	
	for(int i = 0; i <= V; i++){
		d[i] = inf;
		used[i] = false;
	}
	d[s] = 0;
	Q.push( make_pair(0, s) );
	
	P p; int v;
	while(Q.size()){
		p = Q.top(); Q.pop();
		v = p.second;
		used[v] = true;
		if(p.first > d[v]) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(used[G[v][i].to]) continue;
			if(d[G[v][i].to] > d[v] + G[v][i].cost){
				d[G[v][i].to] = d[v] + G[v][i].cost;
				Q.push( make_pair(d[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

int main(void)
{
	while(1){
		cin >> N >> M >> cap;
		if(N == 0 && M == 0 && cap == 0) break;
		
		cin >> src >> dest;
		V = 0;
		name.clear();
		
		string s, t; int di;
		for(int i = 0; i < N; i++){
			cin >> s >> t >> di;
			G[get(s)].push_back( edge(get(t), di ) );
			G[get(t)].push_back( edge(get(s), di ) );
		}
		S = get(src), T = get(dest);
		
		station[0] = S;
		for(int i = 1; i <= M; i++){
			cin >> s;
			station[i] = get(s);
		}
		station[M+1] = T;
		
		for(int i = 0; i <= M+1; i++){
			dijkstra(G, station[i]);
			for(int j = 0; j <= M+1; j++){
				if(d[station[j]] <= cap * 10) stG[i].push_back( edge(j, d[station[j]]) );
			}
		}
		
		/*dijkstra(G, S);
		for(int i = 1; i <= V; i++) cout << d[i] << " ";
		cout << endl;*/
		
		dijkstra(stG, 0);
		if(d[M+1] == inf) d[M+1] = -1;
		cout << d[M+1] << endl;
		
		for(int i = 1; i <= V; i++) G[i].clear();
		for(int i = 0; i <= M+1; i++) stG[i].clear();
	}
	
	return 0;
}

Measured memory_bytes: 5392
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 2000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,L,q;
int jump[21][100001];
int x[100001];

int func(int l,int r){
	if(l==r)return 0;
	int res=0;
	for(int k=20;k>=0;k--){
		if(jump[k][l]<r){
			res+=1<<k;
			l=jump[k][l];
		}
	}
	return res+1;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	scanf("%d",&L);
	scanf("%d",&q);
	for(int i=0;i<n;i++){
		jump[0][i]=upper_bound(x,x+n,x[i]+L)-x-1;
	}
	for(int i=0;i<20;i++){
		for(int j=0;j<n;j++){
			jump[i+1][j]=jump[i][jump[i][j]];
		}
	}
	for(int i=0;i<q;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		int l=min(a,b);
		int r=max(a,b);
		printf("%d\n",func(l,r));
	}
	return 0;
}

Measured memory_bytes: 9472
//In the name of God

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int N = 2e5 + 5;
ll n, k;
vector<ll> a(N);

bool chk(ll length) {
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cnt += (a[i] - 1)/length;	
	}
	return cnt <= k;
}

void solve() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans;
	ll lo = 1, hi = 1e12;
	while (hi >= lo) {
		ll m = (lo + hi)/2;
		if (chk(m)) {
			hi = m - 1;
			ans = m;
		} else {
			lo = m + 1;
		}
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false);	
    cin.tie(NULL);
	int tt = 1;
	// cin >> tt;
	for (int tc = 1; tc <= tt; tc++) {
		// cout << "Case " <<;
		solve();
		// cout << chk(2);
	}
}

Measured memory_bytes: 4692
import Control.Applicative
import Control.Monad
import Data.List (foldl')
import qualified Data.Vector as V
import qualified Data.Map as M


type Node      = Int
type Adjacency = [Int]
type AdjList   = V.Vector [Int]
type Query     = [Int]
type GID       = Int
type GIDs      = M.Map Int Int


main :: IO ()
main = do
    [n, c]  <- map read . words <$> getLine                 :: IO [Int]
    adjs    <- replicateM c $ map read . words <$> getLine  :: IO [Adjacency]
    q       <- readLn                                       :: IO Int
    queries <- replicateM q $ map read . words <$> getLine  :: IO [Query]
    mapM_ putStrLn $ answers n adjs queries


answers:: Int -> [Adjacency] -> [Query] -> [String]
answers n adjs queries = map ans queries
  where
    ans :: Query -> String
    ans [f, t]
        | groups M.! f == groups M.! t = "yes"
        | otherwise                    = "no"

    groups :: GIDs
    groups = snd $ foldl' assign (1, M.empty) [0..n-1]

    adjList :: AdjList
    adjList =
        V.accum (flip (:)) (V.replicate n [])
            $ foldr (\[x, y] accum -> [(x, y), (y, x)] ++ accum) [] adjs

    assign :: (GID, GIDs) -> Node -> (GID, GIDs)
    assign (gid, gids) x
        | M.member x gids = (gid, gids)
        | otherwise       = (gid + 1, dfs gids x)
      where
        dfs :: GIDs -> Node -> GIDs
        dfs gids n
            | M.member n gids = gids
            | otherwise       = foldl' dfs (M.insert n gid gids) (adjList V.! n)


Measured memory_bytes: 95180
n, m = map(int, input().split())

ps = []
for i in range(m):
    ps.append(list(input().split()))
    ps[i][0] = int(ps[i][0])

cnt_correct = 0
cnt_penalty = 0
cnt_penalty_buf = 0

juge = [1]*n
buf = [0]*n

for i in range(m):
    if ps[i][1] == "AC" and juge[ps[i][0] - 1] == 1 :
        cnt_correct += 1
        cnt_penalty += buf[ps[i][0] - 1]
        juge[ps[i][0] - 1] = 0
        cnt_penalty_buf = 0

    if ps[i][1] == "WA" and juge[ps[i][0] - 1] == 1:
        buf[ps[i][0] - 1] += 1

print(cnt_correct, cnt_penalty)

Measured memory_bytes: 27104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

typedef struct{
    long long a;
    long long b;
} pair;

int pairsort(const void *A, const void *B){
    long long P=((pair*)A)->a-((pair*)B)->a;
    long long Q=((pair*)A)->b-((pair*)B)->b;
    if (P!=0){
        return P;
    } else if (Q!=0){
        return Q;
    } else {
        return 0;
    }
}

int main(void){
    long long n,m,ans=0,count=0;
    scanf("%lld%lld\n",&n,&m);
    pair drink[n];
    for (int i=0; i<n; i++){
        scanf("%lld%lld",&drink[i].a,&drink[i].b);
    }
    qsort (drink,n,sizeof(pair),pairsort);
    while(m>0){
        if (drink[count].b>m){
            ans+=drink[count].a*m;
        } else {
            ans+=drink[count].a*drink[count].b;
        }
        m-=drink[count].b;
        count++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3324
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            int a = int.Parse(In[0]);
            int b = int.Parse(In[1]);
            int add = a + b;
            int sub = a - b;
            int mul = a * b;
            int temp = (int)Math.Max(add, sub);
            Console.WriteLine((int)Math.Max(temp, mul));
        }
    }
}


Measured memory_bytes: 27436
//2019.12.16
//s1270188 momooka murakami
//alds_04c Dictionary
//use template


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

#define M 3333337/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M;/* your task */; }
int h2(int key){ return 1+key%(M-1);/* your task */; }

int find(char str[]){

    /* your task */
  int i=0, j;
  long long key;

  key=getKey(str);
  
  while(1){
    j=(h1(key)+i*h2(key))%M;
    if(strcmp(H[j],str)==0) return j;
    else if(H[j][0]=='\0' || i>3) return 0;
    else i++;
  }
  
}

int insert(char str[]){
    /* your task */
  int i=0, j;
  long long key;
  
  key=getKey(str);

  if(find(str)!=0) return 0;
  
  while(1){
    j=(h1(key)+i*h2(key))%M;

    if(H[j][0]=='\0'){
      strcpy(H[j],str);
      return j;
    }
    else i++;
  }
  
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 47364
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	string s;
	ll T1=0,T3=0;
	cin>>s;
	for(ll i=0;i<s.size();i++){
		T1=T1+(int)s[i]-48;
	}
	for(ll i=0;i<s.size();i++){
		if(i==0){
			T3=T3+(int)s[i]-49;
		}
		else T3=T3+9;
	}
	cout<<max(T1,T3)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(h,w);
    vector2d(int,table,h,w);
    vector<tuple<int,int,int,int>> ope;
    in(table);
    rep(y,h){
        rep(x,w){
            table[y][x]%=2;
            if(y<h-1&&table[y][x]==1){
                table[y+1][x]++;
                ope.push_back(make_tuple(y+1,x+1,y+2,x+1));
            }
            if(y==h-1&&x+1<w&&table[y][x]==1){
                table[y][x+1]++;
                ope.push_back(make_tuple(y+1,x+1,y+1,x+2));
            }
        }
    }
    out(ope.size());
    rep(i,ope.size())out(get<0>(ope[i]),get<1>(ope[i]),get<2>(ope[i]),get<3>(ope[i]));
}


Measured memory_bytes: 6356
#include<stdio.h>
#define MAX 500000
int A[MAX + 1],n;

void Max(int i);

void build();

int main(){
  
  int i;
  
  scanf("%d",&n);
  
  for(i = 1;i <= n; i++){
    
    scanf("%d",&A[i]);
    
  }
  
  build();
  
  for(i = 1;i <= n; i++){
    
    printf(" %d",A[i]);
    
  }
  
  printf("\n");
 
  return 0;
}



void Max(int i){
  int max, t, right , left;
  
  left =2 * i;
  right = 2 * i + 1;
  if(left <= n && A[left] > A[i]){
    max = left;
  }
  else {
    max = i;
  }
  if(right <= n && A[right]>A[max]){
    max = right;
  }
  if(max != i){
    t=A[i];
    A[i]=A[max];
    A[max]=t;
    return Max(max);
 
  }
}


void build(){
  int i;
  for(i = n / 2 ; i >= 1 ;i--){
    Max(i);
  }
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int Maxn=1e5+5;
int hap[Maxn][3],dp[Maxn][3];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		rep(j,3){
			cin>>hap[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		rep(j,3){
			rep(k,3){
				if(j!=k){
					chkmax(dp[i][j],dp[i-1][k]+hap[i][j]);
				}
			}
		}
	}
	cout<<*max_element(dp[n],dp[n]+3)<<endl;
	return 0;
}

Measured memory_bytes: 5968
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            direction = []
            if i > 0:
                direction.append((-1, 0))
            if i < H-1:
                direction.append((1, 0))
            if j > 0:
                direction.append((0, -1))               
            if j < W-1:
                direction.append((0, 1))
            for d in direction:
                if s[i+d[0]][j+d[1]] != '.':
                    break
            else:
                print('No')
                exit()
else:
    print('Yes')



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

using i64 = int64_t;

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> l;
    for(int i=0;i<c;++i){
        int tmp;
        cin >> tmp;
        l.push_back(tmp);
    }
    vector<pair<i64, i64>> v;
    for(int i=0;i<n;++i){
        i64 ci, wi;
        cin >> ci >> wi;
        v.emplace_back(wi, ci);
    }
    sort(v.rbegin(), v.rend());
    vector<int> cnt(c+1);
    i64 ans = 0, num = 0;
    for(int i=0;i<n;++i){
        if(cnt[v[i].second] >= l[v[i].second-1])continue;
        if(num >= m)break;
        ans += v[i].first;
        cnt[v[i].second]++;
        num++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 5308
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,M=map(int,input().split())

def COMinit(n,MOD):
    fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,(n+1)):
        fac[i]=fac[i-1]*i%MOD
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i]=finv[i-1]*inv[i]%MOD
    return fac,finv,inv

fac,finv,inv=COMinit(M,MOD)

def COM(n, k, MOD=MOD):
    if n<k or n<0 or k<0:
        return 0
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

def PER(n, k, MOD=MOD):
    if n<k or n<0 or k<0:
        return 0
    return fac[n]*finv[n-k]%MOD

ans=0
k=1

for i in range(N+1):
    ans+=k*COM(N,i)*PER(M,i)*(PER(M-i,N-i)**2)
    ans%=MOD
    k*=-1
print(ans)

Measured memory_bytes: 99436
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<ll> enum_div(ll n) {
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N;
    cin >> N;
    vector<int> P(N);
    cin >> P;

    int ans = 0;
    REP(i, N) {
        if (P[i] == i + 1) {
            if (i + 1 == N) {
                swap(P[i - 1], P[i]);
            } else {
                swap(P[i + 1], P[i]);
            }
            ans++;
        }
    }

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

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

#define SZ(v) ((int)(v).size())
using ll = long long;

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

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


Measured memory_bytes: 3640
n, m = [int(x) for x in input().split()]
s, t = [input() for _ in range(2)]

def gcd(a, b):
    while b!=0:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a // gcd(a, b) * b

l = lcm(n, m)
nn, mm = l//m, l//n

for k in range(l//(nn*mm)):
    if s[k*nn] != t[k*mm]:
        print(-1)
        break
else:
    print(l)


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

int main(){
    ll n;
    cin >> n;
    ll sum = 0;
    vector<ll> ans(n, 0);
    for(int x=1; x<=n; x++){
        for(int y=1; y<=n; y++){
            for(int z=1; z<=n; z++){
                sum = (x+y+z)*(x+y+z)-(x*y+y*z+z*x);
                if(sum > n) break;
                ans[sum-1]++;
            }
        }
    }
    rep(i, n){
        cout << ans[i] << endl;

    }
    return 0;
}

Measured memory_bytes: 3620
a,b=map(int,input().split())
def xorsum(x):
  if x % 4 == 1:
    return 1
  elif x % 4 == 2:
    return x+1
  elif x % 4 == 3:
    return 0
  elif x % 4 == 0:
    return x
print(xorsum(b)^xorsum(a-1))


Measured memory_bytes: 61648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n,m;
vector<int> g[100100];
bool used[100100];
deque<int> ans;

void dfs1(int x){
    used[x]=true;
    ans.push_back(x);
    rep(i,g[x].size()){
        if(!used[g[x].at(i)]){
            dfs1(g[x].at(i));
            return;
        }
    }
}

void dfs2(int x){
    used[x]=true;
    ans.push_front(x);
    rep(i,g[x].size()){
        if(!used[g[x].at(i)]){
            dfs2(g[x].at(i));
            return;
        }
    }
}

void dfs(int x){
    ans.push_back(x);
    used[x]=true;
    dfs1(g[x].at(0));
    rep(i,g[x].size()){
        if(!used[g[x].at(i)]){
            dfs2(g[x].at(i));
            return;
        }
    }
}

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

    cin>>n>>m;
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dfs(0);
    cout<<ans.size()<<endl;
    rep(i,ans.size()-1)cout<<ans.at(i)+1<<' ';
    cout<<ans.back()+1<<endl;
    
}

Measured memory_bytes: 10112
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    auto compute = [&](ll n) -> ll {
        if (n == -1) return 0;
        return 1 + n/x;
    };
    cout << compute(b) - compute(a-1) << endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int a = Integer.parseInt(br.readLine());

		System.out.println(a+a*a+a*a*a);
	}
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101010];
P c[2][101010];
void solve(){
	cin >> n;
	for(int i = 0; i < 101010; i++){
		c[0][i].second = i;
		c[1][i].second = i;
	}
	for(int i = 0; i < n; i++){
		cin >> a[i];
		c[i&1][a[i]].first++;
	}
	sort(c[0],c[0]+101010,greater<P>());
	sort(c[1],c[1]+101010,greater<P>());
	
	if(c[0][0].second == c[1][0].second){
		i64 ma = 0;
		chmax(ma, c[0][0].first+c[1][1].first);
		chmax(ma, c[0][1].first+c[1][0].first);
		cout << n-ma << endl;
	}
	else{
		cout << n-c[0][0].first-c[1][0].first << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3840
N, M = tuple([int(x) for x in input().split(' ')])
A = [int(x) for x in input().split(' ')]
minA = min(A)

BC = []
for i in range(M):
    BC.append(tuple([int(x) for x in input().split(' ')]))

BC.sort(key=lambda x:x[1], reverse=True)

sumB = 0
for B, C in BC:
    if C <= minA:
        break
    sumB += B
    A.extend([C]*B)
    if sumB >= N:
        break

A.sort(reverse=True)
print(sum(A[:N]))

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

// main.cpp

class edge {
public:
  std::int_fast64_t from;
  std::int_fast64_t to;
  std::int_fast64_t distance;
  edge(const std::int_fast64_t from, const std::int_fast64_t to, const std::int_fast64_t distance) :
    from(from),
    to(to),
    distance(distance) {
  }
};

class bfs_queue {
private:
  std::vector<std::int_fast64_t> vector;
  std::unordered_set<std::int_fast64_t> set;

public:
  std::int_fast64_t size() const {
    return this->vector.size();
  }

  std::int_fast64_t operator[](const std::int_fast64_t i) const {
    return this->vector[i];
  }

  void insert(const std::int_fast64_t x) {
    if (this->set.insert(x).second) {
      this->vector.push_back(x);
    }
  }

  bool contains(const std::int_fast64_t x) const {
    return this->set.find(x) != this->set.end();
  }
};

int main() {
  std::int_fast64_t n, m;
  std::cin >> n >> m;

  std::unordered_map<std::int_fast64_t, std::vector<edge>> graph;
  std::unordered_set<std::int_fast64_t> unvisited_nodes;
  for (std::int_fast64_t i = 0; i < m; ++i) {
    std::int_fast64_t l_i, r_i, d_i;
    std::cin >> l_i >> r_i >> d_i;
    graph.insert(std::make_pair(l_i, std::vector<edge>()));
    graph[l_i].emplace_back(l_i, r_i, d_i);
    unvisited_nodes.insert(l_i);
    graph.insert(std::make_pair(r_i, std::vector<edge>()));
    graph[r_i].emplace_back(r_i, l_i, -d_i);
    unvisited_nodes.insert(r_i);
  }

  while (!unvisited_nodes.empty()) {
    std::unordered_map<std::int_fast64_t, std::int_fast64_t> line;
    bfs_queue bfs;
    bfs.insert(*unvisited_nodes.begin());
    line.insert(std::make_pair(bfs[0], 0));

    for (std::int_fast64_t i = 0; i < bfs.size(); ++i) {
      for (const edge& edge : graph[bfs[i]]) {
        if (line.find(edge.to) != line.end()) {
          if (line[edge.from] + edge.distance != line[edge.to]) goto FAILED;
        } else {
          line.insert(std::make_pair(edge.to, line[edge.from] + edge.distance));
        }
        bfs.insert(edge.to);
      }
      unvisited_nodes.erase(bfs[i]);
    }
  }

  std::cout << "Yes" << std::endl;
  return 0;

FAILED:
  std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 31992
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int gcd(int x, int y) {
	int r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}

int main()
{
	int n, i;
	scanf("%d", &n);
	int a[100000];
	lop(i, n){ scanf("%ld", &a[i]); }
	
	int ans=a[0];
	lop(i, n){
		ans=gcd(ans, a[i]);
	}
	
	printf("%d", ans);
	
return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
long long n,a[20][20],dp[1<<17],sum[1<<17];
int main()
{
	cin >> n;
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin >> a[i][j];
	for(int i=0; i<(1<<n); i++) for(int j=0; j<n; j++) for(int k=j+1; k<n; k++)
		if((i&(1<<j)) && (i&(1<<k))) sum[i]+=a[j][k];
	for(int i=0; i<(1<<n); i++)
	{
		vector<int> pos;
		for(int j=0; j<n; j++) if(i&(1<<j)) pos.push_back(1<<j);
		int m=pos.size();
		for(int j=0; j<(1<<m); j++)
		{
			int c=0;
			for(int k=0; k<m; k++) if(j&(1<<k)) c+=pos[k];
			dp[i]=max(dp[i],dp[i-c]+sum[c]);
		}
	}
	long long ans=0;
	for(int i=0; i<(1<<n); i++) ans=max(ans,dp[i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 4620
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

string x,y;
int main(){
	while(cin >> x >> y){
		int L[x.size()+1][y.size()+1] = {{0}};
		for(int i=0;i<x.size()+1;i++){
			for(int j=0;j<y.size()+1;j++){
				if(i==0){
					L[i][j] = j;
				}else if(j==0){
					L[i][j] = i;
				}else{
					int alpha = 0;
					if(x[i-1]!=y[j-1]) alpha = 1;
					L[i][j] = min(alpha+L[i-1][j-1],min(1+L[i][j-1],1+L[i-1][j]));
				}
			}
		}
		cout << L[x.size()][y.size()] << endl;
	}
}

#if 0
所要時間は40分程度。これも河村先生の講義で扱ったが，アルゴリズムを忘れていたので勉強しなおしだった。
#endif


Measured memory_bytes: 7004
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

typedef struct {
    int ipt; int num;
} tpl;

int asc(const void *a, const void *b) {
    return ((*(tpl *)a)).ipt - ((*(tpl *)b)).ipt;
}

int main(void){
    int N;
    scanf("%d", &N);
    int a[100000 + 10];
    tpl array[100000 + 10];
    for (int i = 0; i < N; i++) {
        scanf("%d", &array[i].ipt);
        array[i].num = i + 1;
    }
    qsort(array,N,sizeof (tpl), asc);
    for (int i = 0; i < N; i++) {
        printf("%d ",array[i].num);
    }

}


Measured memory_bytes: 1788
N, K = map(int,input().split())

m = 60

A = list(map(int,input().split()))
A = [A[i]-1 for i in range(N)]

D = [A]
for i in range(m):
  temp = []
  for j in range(N):
    temp.append(D[i][D[i][j]])
  D.append(temp)

now = 0
for i in range(m):
  if K >> i&1 == 1:
    now = D[i][now]
print(now+1)

Measured memory_bytes: 217252
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


q, h, s, d = MI()
n = II()
print((n // 2) * min(8 * q, 4 * h, 2 * s, d) + (n % 2) * min(4 * q, 2 * h, s))


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

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];
    int cnt = 1;
    for (int i = 1; i < n; i++)
    {
        bool flag = true;
        for (int j = 0; j < i; j++)
        {
            if (h[i] < h[j])
                flag = false;
        }
        if (flag)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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


ll knap(ll wg,int n,ll v[],ll w[])
{
 
   ll dp[n+1][wg+1];
   for(ll i=0;i<=n;i++)
   {

   	for(ll j=0;j<=wg;j++)
   		dp[i][j]=0;
   }

   for(ll i=0;i<=n;i++)
   {
   	for(ll j=0;j<=wg;j++)
   	{
        
        if(i==0 || j==0)
        {
        	dp[i][j]=0;
        	
        }

        else if(w[i-1]<=j)
        {

        	 dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
        }
        else
        	dp[i][j]=dp[i-1][j];

        // cout<<dp[i][j]<<" ";

   	}
   	// cout<<endl;
   }
    // cout<<endl;

   return dp[n][wg];
	
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    

 int n;
 ll wg;
 cin>>n>>wg;


 ll v[n],w[n];

 for(ll i=0;i<n;i++)
 {
 cin>>w[i]>>v[i];

 }

cout<<knap(wg,n,v,w);



    }

Measured memory_bytes: 79104
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N;
string ans = "";

int main() {

	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	ll cur = 26,cnt=1;

	while (N > cur) {
		N -= cur;
		cur *= 26;
		
		cnt++;
	}

	N--;
	FOR(i, 0, cnt) {
		ans += char('a' + N % 26);
		N /= 26;
	}


	reverse(ans.begin(), ans.end());
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 2, 0);
    rep(i, n) cin >> a[i + 1];
    int sum = 0;
    rep(i, n + 1){
        sum += abs(a[i] - a[i + 1]);
    }

    int ans = sum;
    for(int i = 1; i <= n ; i++){
        int cost = sum;
        cost -= abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1]);
        cost += abs(a[i - 1] - a[i + 1]);
        cout << cost << endl;
    }
}

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

int main(){
  long long n,k,ans=0;
  cin>>n>>k;
  
  if(k%2==0){
    ans+=((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k);
  }
  ans+=(n/k)*(n/k)*(n/k);
 
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long LL;
#define INF 1145141919

#define MAX_N 100005
#define mod 1000000007

int N;
int A[MAX_N];

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

int main()
{
  input();

  sort(A, A+N);

  int startNum = 0;
  int cnt = 1;
  if(N % 2 == 0){
    startNum = 1;
    cnt = 0;
  }

  for (int i = 0; i < N; i++) {
    if(A[i] != startNum){
      cout << 0 << endl;
      return 0;
    }
    cnt++;
    if(cnt == 2){
      cnt = 0;
      startNum += 2;
    }
  }
  startNum -= 2;

  LL ans = 1;
  while(startNum > 0){
    ans *= 2;
    ans %= mod;
    startNum -= 2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll gcd(ll x, ll y){
	return (y?gcd(y,x%y):x);
}

ll a[100100];
int b[100100];

int main(void){
	int n,i;
	ll m,g,uni=1ll;
	cin >> n >> m;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(i=0; i<n; ++i){
		while(!(a[i]%2)){
			a[i] /= 2;
			++b[i];
		}
		if(b[i] != b[0]){
			cout << 0 << endl;
			return 0;
		}
		g = gcd(uni,a[i]);
		uni *= a[i]/g;
		if(uni>m){
			cout << 0 << endl;
			return 0;
		}
	}
	for(i=1; i<b[0]; ++i){
		uni *= 2;
		if(uni > m){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (m/uni-m/(uni*2)) << endl;
	return 0;
}


Measured memory_bytes: 1408
n = int(input())
hs = [int(i) for i in input().split()]
flag = -1
count = 0

while max(hs) > 0:
    flag = -1
    for i in range(n):
        if hs[i] > 0:
            if flag == 1:
                hs[i] -= 1
            else:
                count += 1
                flag = 1
                hs[i] -= 1
        else:
            if flag == 1: 
                flag = -1
print(count)

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long y,const mint& m){ return m+y; }
mint operator*(long long y,const mint& m){ return m*y; }

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<pair<int,int>> Ev[301];
	rep(i,m){
		int l,r,c; scanf("%d%d%d",&l,&r,&c); l--;
		Ev[r].emplace_back(l,c);
	}

	// dp[i][j][k] = (最も右にある赤, 緑, 青マスがそれぞれ i, j, k マス目 (1-indexed) であるような塗り方の数)
	static mint dp[301][301][301];
	dp[0][0][0]=1;
	rep(i,n) rep(j,n) rep(k,n) {
		int next=max({i,j,k})+1;
		dp[next][j][k]+=dp[i][j][k];
		dp[i][next][k]+=dp[i][j][k];
		dp[i][j][next]+=dp[i][j][k];

		for(auto p:Ev[next]){
			int l,c; tie(l,c)=p;
			int cnt;
			cnt=1;
			if(j>=l+1) cnt++;
			if(k>=l+1) cnt++;
			if(cnt!=c) dp[next][j][k]=0;
			cnt=1;
			if(i>=l+1) cnt++;
			if(k>=l+1) cnt++;
			if(cnt!=c) dp[i][next][k]=0;
			cnt=1;
			if(i>=l+1) cnt++;
			if(j>=l+1) cnt++;
			if(cnt!=c) dp[i][j][next]=0;
		}
	}

	mint ans=0;
	rep(j,n) rep(k,n) ans+=dp[n][j][k];
	rep(i,n) rep(k,n) ans+=dp[i][n][k];
	rep(i,n) rep(j,n) ans+=dp[i][j][n];
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 106752
N = int(input())
A = [int(i) for i in input().split()]

x = A[-1]
i = -1
for j in range(0, len(A) - 1):
    if x >= A[j]:
        i += 1
        A[i], A[j] = A[j], A[i]
A[i+1], A[-1] = A[-1], A[i+1]
q = i + 1

return_str = str(A[0])
for i, k in enumerate(A):
    if i != 0:
        if i == q:
            return_str += " [" + str(k) + "]"
        else:
            return_str += ' ' + str(k)

print(return_str)


Measured memory_bytes: 16372
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, K, p[201010];
double e[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> p[i];

	rep(i, 0, N) e[i] = 1.0 * (1 + p[i]) / 2;

	double tot = 0;
	rep(i, 0, K) tot += e[i];

	double ans = tot;
	rep(i, K, N) {
		tot = tot + e[i] - e[i - K];
		chmax(ans, tot);
	}
	printf("%.10f\n", ans);
}







Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
const ll mod = 1000000007;
const ll M = 1000000000000000000ll;
#define fi first
#define se second
#define pb push_back
inline ll add(ll a,ll b){return ((a%mod+b%mod)%mod);}
inline ll sub(ll a,ll b){return ((a%mod-b%mod+mod)%mod);}
inline ll mult(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
inline ll power(ll n,ll x){ll p=1;while(x!=0){if(x%2==0){n=mult(n,n);x=x/2;}p=mult(p,n);x--;}return p;}
inline ll recurmult(ll a,ll b){ll r = 0;while (b){if (b & 1)r = add(r, a);a = mult(2,a);b >>= 1;}return r%mod;}

int main()
{
    ios::sync_with_stdio(0);   
    cin.tie(0);   
    #ifndef ONLINE_JUDGE   
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif  
    ll n,r;
    cin>>n>>r;
    vector<ll>adj[200005];
    map<ll,ll>mp;
    map<ll,ll>ans;
    for(ll i=1;i<=n;i++)
    {
        ans[i]=1;
        cin>>mp[i];
    }

    for(ll i=1;i<=r;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(mp[x]<=mp[y])
            ans[x]=ans[x]&0;
        if(mp[x]>=mp[y])
            ans[y]=ans[y]&0;
    }
    ll z=0;
    for(auto it:ans)
        z+=it.second;
    cout<<z<<"\n";
}

Measured memory_bytes: 20832
#include<iostream>
using namespace std;
int main() {
	int N;
	int t[110000], x[110000], y[110000];
	cin >> N;
	t[0] = x[0] = y[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> t[i + 1] >> x[i + 1] >> y[i + 1];

	}
	bool can = true;
	for (int i = 0; i < N; i++) {
		int dt = t[i + 1] - t[i];
		int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		if (dist <= dt) {
			if ((dist % 2) != (dt % 2)) {
				can = false;
				break;
			}
		}
		else {
			can = false;
			break;

		}

	}
	if (can) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int x, y;
    cin >> x >> y;
    rep(i, 100)rep(j, 100){
        if(i + j == x && 2 * i + 4 * j == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3632
use std::io;

macro_rules! parse_line {
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
                a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

fn main() {
    let (n,) = parse_line!(u32);
    println!(
        "AB{}",
        if n < 1000 {
            "C"
        } else {
            "D"
        });
}

Measured memory_bytes: 4352
#include<stdio.h>
long long int abs(long long int n)
{
	if (n < 0)
		n *= -1;
	return n;
}

int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	int x[200005], y[200005];
	for (i = 0; i < n; i++)
		scanf("%d %d", &x[i], &y[i]);
	int ans = 0;
	j = 0;
	for (i = 0; i < n; i++)
		if (x[i] < x[j])
			j = i;
	for (i = 0; i < n; i++)
		if (ans < abs(x[i] - x[j]) + abs(y[i] - y[j]))
			ans = abs(x[i] - x[j]) + abs(y[i] - y[j]);
	j = 0;
	for (i = 0; i < n; i++)
		if (y[i] < y[j])
			j = i;
	for (i = 0; i < n; i++)
		if (ans < abs(x[i] - x[j]) + abs(y[i] - y[j]))
			ans = abs(x[i] - x[j]) + abs(y[i] - y[j]);
	j = 0;
	for (i = 0; i < n; i++)
	{
		if (x[i] <= x[j] && y[i] <= y[j])
		{
			j = i;
			continue;
		}
		if (x[i] >= x[j] && y[i] >= y[j])
			continue;
		if (x[i] < x[j])
		{
			if (x[j] - x[i] > y[i] - y[j])
				j = i;
		}
		else
		{
			if (y[j] - y[i] > x[i] - x[j])
				j = i;
		}
	}
	for (i = 0; i < n; i++)
		if (ans < abs(x[i] - x[j]) + abs(y[i] - y[j]))
			ans = abs(x[i] - x[j]) + abs(y[i] - y[j]);
	j = 0;
	for (i = 0; i < n; i++)
	{
		if (x[i] <= x[j] && y[i] >= y[j])
		{
			j = i;
			continue;
		}
		if (x[i] >= x[j] && y[i] <= y[j])
			continue;
		if (x[i] < x[j])
		{
			if (x[j] - x[i] > y[j] - y[i])
				j = i;
		}
		else
		{
			if (y[i] - y[j] > x[i] - x[j])
				j = i;
		}
	}
	for (i = 0; i < n; i++)
		if (ans < abs(x[i] - x[j]) + abs(y[i] - y[j]))
			ans = abs(x[i] - x[j]) + abs(y[i] - y[j]);
	printf("%d\n", ans);
}

Measured memory_bytes: 3292