akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
//r-石头
//s-剪刀
//p-布
int main()
{
    ll n,k,r,s,p;
    while(cin>>n>>k)
    {
        cin>>r>>s>>p;
        string t;cin>>t;
        ll ans=0;
        for(int i=0;i<t.size();i++)
        {
            if(t[i]=='r'&&i<k)
            {
                t[i]='p';
                ans+=p;
            }
            else if(t[i]=='s'&&i<k)
            {
                t[i]='r';
                ans+=r;
            }
            else if(t[i]=='p'&&i<k)
            {
                t[i]='s';
                ans+=s;
            }
            else if(i>=k)
            {
                if(t[i]=='r'&&(t[i-k]!='p'||t[i-k]=='1'))
                {
                    t[i]='p';
                    ans+=p;
                }
                else if(t[i]=='p'&&(t[i-k]!='s'||t[i-k]=='1'))
                {
                    t[i]='s';
                    ans+=s;
                }
                else if(t[i]=='s'&&(t[i-k]!='r'||t[i-k]=='1'))
                {
                    t[i]='r';
                    ans+=r;
                }
                else t[i]='1';
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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 dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint a(n); rep(i,n) cin>>a[i];

    ll ans =0;
    rep(i,n){
        if((i+1)%2==1 and a[i]%2==1) ans++;
    }
    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
using namespace std;
int main(){
	string S;cin>>S;bool OK=false;
	for(int i=0;i<(int)S.size()-1;i++)if(S[i]==S[i+1]){cout<<i+1<<' '<<i+2<<endl;return 0;}
	for(int i=0;i<(int)S.size()-2;i++)if(S[i]==S[i+2]){cout<<i+1<<' '<<i+3<<endl;return 0;}
	cout<<"-1 -1"<<endl;
}

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


int main(){
  int n;
  cin >> n;
  vector<int>l(n);
  rep(i,n) cin >> l.at(i);
  sort(l.begin(),l.end());
  
  int ans = 0;
  rep(i,n-2){
    for(int j = i+1; j < n-1; j++){
    int L = j; int R = n;
    while(R-L>1){
      int mid = (L+R)/2;
      if(l.at(mid) < l.at(i)+l.at(j)) L = mid;
      else R = mid;
    }
    ans += L-j;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [input() for _ in range(H)]
ans = [[-1]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    cnt = 0
    if S[i][j] == "#":
      ans[i][j] = "#"
      continue
    for n in range(-1, 2):
      for m in range(-1, 2):
        if i+n < 0 or i+n > H-1: 
          continue
        if j+m < 0 or j+m > W-1:
          continue
        if S[i+n][j+m] == "#":
          cnt += 1
    ans[i][j] = cnt
for i in range(H):
  print(*ans[i], sep="")

Measured memory_bytes: 3444
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

bool cmp(char a,char b)
{
	if(a>b) return true;
	return false;
}
	
int main()
{
	char a[105],b[105];
	scanf("%s %s",&a,&b);
	sort(a,a+strlen(a));
	sort(b,b+strlen(b),cmp);
	if(strcmp(a,b)<0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
    char S[1001];
    int w, i;
    scanf("%s",   S);
    scanf("%d",  &w);
    for (i=0;i<strlen(S);i=i+w) {
        printf("%c", S[i]);
    }
    return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())
k=min(k,n)
a=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
for i in range(1,k):
    for j in range(0,i):
        dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]))
for i in range(k,len(a)):
    for j in range(i-k,i):
        dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]))
print(dp[-1])

Measured memory_bytes: 55136
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	int n;
	bool b[10]={};
	
	for(int i=0;i<4;i++)
	{
		cin >> n;
		b[n]=true;
	}
	
	if(b[1] && b[9] && b[7] && b[4])cout << "YES";
	else cout << "NO";
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String sep = System.getProperty("line.separator");
		sc.useDelimiter(sep+sep);
		String s = sc.next();
		char characters[] = s.toCharArray();
		int count[] = new int[26];
		for (int i = 0; i < characters.length; i++) {
			for (int j = 0; j < 26; j++) {
				if (characters[i] == (char) (j + 97) || characters[i] == (char) (j + 65)) {
					count[j]++;
				}
			}

		}

		for (int i = 0; i < 26; i++) {
			char c = (char) (i + 97);

			System.out.println(c + " : " + count[i]);
		}

	}

}

Measured memory_bytes: 26200
#include <bits/stdc++.h>
#include <unordered_map>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
using namespace std;
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
ll max(ll a, ll b)
{
    if(a>b) return a;
    return b;
}

#define MAXN 10000001 
  
// stores smallest prime factor for every number 
int spf[MAXN]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
vector<int> getFactorization(int x) 
{ 
    vector<int> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 
  

void solve()
{
    ll n;
    cin>>n;

    ll ans = 0;

    for(int i = 1; i <= n; i++)
    {
        vi p = getFactorization(i);

        int cnt = 1;

        ll prod = 1;

        for(int j = 1; j < p.size(); j++)
        {
            if(p[j] == p[j-1]) cnt++;
            else
            {
                prod = prod*(cnt + 1);
                cnt = 1;
            }
        }


        prod = prod*(cnt + 1);

        ans += i*prod;
    }

    cout<<ans-1<<endl;



}

int main()
{
    sieve(); 

    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 54620
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> H;
	int i, j;
	for (i = 0; i < N; i++) {
		int h;
		cin >> h;
		H.push_back(h);
	}
	int ans = 0;
	for (i = 0; i < N; i++) {
		bool b = true;
		for (j = 0; j < i; j++) {
			if (H.at(i) < H.at(j)) {
				b = false;
				break;
			}
		}
		if (b == true) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
def combinationWithRepetitionListRecursive(data, r):
  if r <= 0:
    return []

  result = []
  _combinationWithRepetitionListRecursive(data, r, 0, [], result)
  return result

def _combinationWithRepetitionListRecursive(data, r, start, progress, result):
  if r == 0:
    result.append(progress)
    return

  for i in range(start, len(data)):
    _combinationWithRepetitionListRecursive(data, r - 1, i, progress + [data[i]], result)


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

L = [[0] * 4 for _ in range(Q)]

for i in range(Q):
    a, b, c, d = map(int, input().split())
    L[i][0] = a
    L[i][1] = b
    L[i][2] = c
    L[i][3] = d

#print(L)

allnum = []

for i in range(1, M+1):
    allnum.append(i)

allseq = combinationWithRepetitionListRecursive(allnum, N)
#print(allseq)

MAX = 0

for j in range(len(allseq)):
    point = 0
    for k in range(Q):
        if allseq[j][L[k][1]-1] - allseq[j][L[k][0]-1] == L[k][2]:
            point += L[k][3]
    MAX = max(MAX, point)

print(MAX)

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

int pow(int n, int i){
	int ans = 1;
	for(int j = 0; j < i; j++){
		ans *= n; 
	}
	return ans;
}

int main(){
	/*input*/
	char n[4];	cin >> n;
	/*calculation*/
	int ans = 0;
	for(int i = 0; i < 3; i++){
		ans += pow(10, 2 - i)*((n[i] == '1')?9:1);
	}
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_N = 260;
const int MOD = 256;
const double EPS = 1e-8;

int N;

int init(vector<int> &R, int &s, int &a, int &c, int n){
  if(n <= 0) return R[0] = s;
  return R[n] = (a * init(R, s, a, c, n - 1) + c) % MOD;
}

double check(vector<int> &O){
  double res = 0.0;
  map<int, int> M;
  REP(i, N) M[O[i]] += 1;
  for(pair<const int, int> p : M) res -= (double)p.second / N * log((double)p.second / N);
  return res;
}

int main() {
  while(cin >>N && N){
    vector<int> I(N); REP(i, N) cin >>I[i];
    int S = 0, A = 0, C = 0;
    double H = 1e9;
    REP(s, 16){
      REP(a, 16){
        REP(c, 16){
          vector<int> R(N + 10), O(N);
          init(R, s, a, c, N);
          REP(i, N) O[i] = (I[i] + R[i + 1]) % MOD;
          double h = check(O);
          if(h + EPS < H) { S = s; A = a; C = c; H = h; }
        }
      }
    }
    cout <<S <<" " <<A <<" " <<C <<endl;
  }
  return 0;
}

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < ((int)n); ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int> > A(n, vector<int>(m));
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> A[i][j];
    }

    llong ans = 10000000000;
    for (int bit = 0; bit < (1 << n); ++bit) {
        llong cost = 0;
        vector<llong> und(m, 0);
        rep(i, n) {
            if ((1 << i) & bit) {
                cost += c[i];
                rep(j, m) und[j] += A[i][j];
            }
        }
        bool flag = true;
        rep(i, m) {
            if (und[i] < x) {
                flag = false;
                break;
            } 
        }
        if (flag) ans = min(ans, cost);
    }

    if (ans == 10000000000LL) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3664
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
	"math"
)

var INF int32 = math.MaxInt32
var INF64 int64 = math.MaxInt64

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineNum64s(bf *bufio.Reader) []int64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int64{}
	for _, field := range fields {
		num, _ := strconv.ParseInt(field, 10, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

func main() {
	bf := bufio.NewReader(os.Stdin)
	N := readLineNums(bf)[0]
	A := make([][]int, N)
	for i := range A {
		A[i] = readLineNums(bf)
	}

	bitCnt := func(mask int) int {
		cnt := 0
		for i:=0; i<N; i++ {
			if mask & (1<<uint(i)) != 0 {
				cnt++
			}
		}
		return cnt
	}

	dp := make([]int, 1<<uint(N)) // 2^n
	dp[0] = 1 // 无人匹配
	for mask:=0; mask<len(dp)-1; mask++ {
		a := bitCnt(mask)
		for b:=0; b<N; b++ {
			if A[a][b] == 0 {
				continue
			}
			if mask & (1<<uint(b)) != 0 {
				continue
			}
			nmask := mask | (1<<uint(b))
			dp[nmask] += dp[mask]
			if dp[nmask] > 1e9+7 {
				dp[nmask] -= 1e9+7
			}
		}
	}

	fmt.Println(dp[(1<<uint(N))-1])
}


Measured memory_bytes: 17536
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
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;

const int mod = 1000000007;

//power_mod
inline int Pow_mod(int x, int pow){
    if(pow==0) return 1;
    int a=Pow_mod(x, pow/2);
    a=a*a%mod;
    if(pow%2==1) a*=x;
    return a%mod;
}

int n;
string s;
int dp[5010][5010];

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

    cin>>n>>s;
    dp[0][0]=1;
    rep(i,n){
        rep(j,n+1){
            (dp[i+1][j+1]+=dp[i][j]*2%mod)%mod;
            (dp[i+1][max<int>(0,j-1)]+=dp[i][j])%=mod;
        }
    }

    cout<<dp[n][s.size()]*Pow_mod(Pow_mod(2,s.size()),mod-2)%mod<<endl;
    return 0;

}

Measured memory_bytes: 195968
function Main(input) {
  input=input.split("\n");
  var N=input[0].split(' ')[0]-0;
  var M=input[0].split(' ')[1]-0;
  console.log((N*(N-1)+M*(M-1))/2);
  
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


Measured memory_bytes: 29492
package main

import (
	"fmt"
	"sort"
)

func chatInACircle(a []int) int {
	sort.Slice(a, func(i, j int) bool {
		return a[i] > a[j]
	})
	if len(a) <= 1 {
		return 0
	}
	if len(a) == 2 {
		return a[0]
	}

	m := a[0]
	a = a[1:]

	lim := len(a) - 1
	numLim := 2
	for i := 0; i < len(a); i++ {
		for j := 0; j < numLim; j++ {
			if lim > 0 {
				m += a[i]
				lim--
			}
			
		}
	}

	return m
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	ans := chatInACircle(a)
	fmt.Println(ans)
}


Measured memory_bytes: 6512
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout<<#x<<'='<<x<<endl
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
#define INF 0x3f3f3f3f
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int maxn = 101010;
const int MOD = 1e9 + 7;

vector<ll> X;
vector<ll> Y[55];
vector<ll> V;
ll a[55] , b[55];
int get(ll x)
{
    return (lower_bound(X.begin(),X.end(),x)-X.begin())+1;
}

int main()
{
    int n,num;
    scanf("%d%d",&n,&num);
    rep(i,1,n+1) scanf("%lld%lld",&a[i],&b[i]);
    rep(i,1,n+1) X.push_back(a[i]);
    sort(X.begin() , X.end());
    X.end() = unique(X.begin(),X.end());

    for(int i=1;i<=n;i++){
        Y[get(a[i])].push_back(b[i]);
    }

    for(int i=1;i<=n;i++) sort(Y[i].begin(),Y[i].end());
    //for(int i=1;i<=n;i++) printf("%d%c",Y[i].size(),i==n?'\n':' ');

    ll tmp;
    ll minn = 4999999996000000001;
    ll y_max,y_min;
    int cnt;

    for(int i=1;i<=n;i++){
        if(Y[i].size()>num){
            rep(j,0,Y[i].size()){
                if(j+num>Y[i].size()) break;
                ll len = Y[i][j+num-1]-Y[i][j];
                tmp = len;
                //puts("");de(Y[i].size());de(i);de(tmp);
                minn = min(minn,tmp);

            }
        }
        cnt = 0;
        for(int j=i+1;j<=n;j++){
            V.clear();
            for(int k=i;k<=j;k++){
                for(int l=0;l<Y[k].size();l++){
                    V.push_back(Y[k][l]);
                }
            }
            //puts("");de(i);de(j);
            sort(V.begin() , V.end());
            rep(k,0,V.size()){
                if(k+num>V.size()) break;
                tmp = X[j-1]-X[i-1];
                ll len = V[k+num-1]-V[k];
                if(len==0) len=1;
                tmp*=len;
                //de(k);de(tmp);
                minn = min(minn,tmp);
            }
        }
    }
    cout<<minn<<endl;
}


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

int main(){
    map<string, int>Map;
    int N, M;
    cin >> N;
    for(int i=0; i<N; i++){
        string str;
        cin >> str;
        decltype(Map)::iterator it=Map.find(str);
        if(it==Map.end())Map.insert(make_pair(str, 1));
        else Map[str]++;
    }
    cin >> M;
    for(int i=0; i<M; i++){
        string str;
        cin >> str;
        decltype(Map)::iterator it=Map.find(str);
        if(it==Map.end())Map.insert(make_pair(str, -1));
        else Map[str]--;
    }
    int mx=-1000;
    for(pair<string, int>p:Map){
        mx = max(p.second, mx);
    }
    cout << max(0, mx);
    return 0;
}

Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    p = list(IL())
    q = sorted(p)
    flag = 3
    for i in range(n):
        if p[i] != q[i]:
            flag -= 1
        if not flag:
            print("NO")
            exit()
    print("YES")
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 9144
#include <iostream>
using namespace std;
int main(){
	int n, x, ans, i, j;
	while(1){
		cin >> n >> x;
		if(n == 0 && x == 0){
			break;
		}else{
			ans = 0;
			for(i = 2; i <= n; i++){
				for(j = 1; j < i; j++){
					if(x-i-j > 0 && x-i-j <= n && x-j-i != i && x-j-i != j){
						ans += 1;
					}else if(i+j >= x){
						break;
					}
				}
			}
			cout << ans/3 << endl;
		}
	}
	return 0;
}

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

int c_1( char *, int );
int c_2( char *, int );
int c_3( char *, int );

int main(){
    char s[100] = {0};
    int n = 0;

    cin >> s;

    int i;
    for( i = 0; s[i] != 0; i++ ){
        n++;
    }

    if( ( c_1(s,n) == 0 ) &&
        ( c_2(s,n) == 0 ) &&
        ( c_3(s,n) == 0 ) ){
        cout << "Yes" << "\n";
    }
    else{
        cout << "No" << "\n";
    }

}

int c_1( char *s, int n ){
    int i;
    for( i = 0; i < ( n / 2 ); i++ ){
        if( s[i] != s[n-i-1] )break;
    }

    return (n/2)-i;
}

int c_2( char *s, int n ){
    int i;

    n = ( n - 1)/2;

    for( i = 0; i < ( n / 2 ); i++ ){
        if( s[i] != s[n-i-1] )break;
    }

    return (n/2)-i;
}

int c_3( char *s, int n ){
    int i;
    char t[99] = {0};

    // 文字列を反転させる
    for( i = 0; i < n; i++ ){
        t[i] = s[n-i-1];
    }
//    cout << "inv:" << t << "\n";

    n = ( n - 1)/2;

    for( i = 0; i < ( n / 2 ); i++ ){
        if( t[i] != t[n-i-1] )break;
    }

    return (n/2)-i;
}

Measured memory_bytes: 256
/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long 
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e18
# define mx2 1000005
# define mx 100005
# define endl "\n"
int main()
{
	IOS;
	ll n,a,b;
	cin>>n>>a>>b;
	if((b-a)%2==1LL){
		ll temp1=a;
		ll ans1=temp1+(b-a-1)/2;
		ll temp2=n-b+1;
		ll ans2=temp2+(b-a-1)/2;
		cout<<min(ans1,ans2)<<endl;
	}
	else
		cout<<(b-a)/2<<endl;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
LL fact[N];
LL rfact[N];
int a[N];
int pre[N];
void init()
{
	fact[0] = fact[1] = 1;
	for (int i = 1; i < N; i++) fact[i] = i * fact[i - 1] % INF;
	rfact[0] = rfact[1] = 1;
	for (int i = 2; i < N; i++) rfact[i] = (INF - INF / i) * rfact[INF % i] % INF;
	for (int i = 2; i < N; i++) rfact[i] = rfact[i] * rfact[i - 1] % INF;
}
LL C(int n, int m)
{
	if (n < m) return 0;
	return fact[n] * rfact[m] % INF * rfact[n - m] % INF;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	init();
	int n;
	cin >> n;
	int lsum = 0, rsum = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		int x;
		cin >> x;
		if (pre[x] != 0)
		{
			lsum = pre[x] - 1;
			rsum = n + 1 - i;
		}
		pre[x] = i;
	}
	for (int i = 1; i <= n + 1; i++)
	{
		LL ans = C(n + 1, i);
		ans -= C(lsum + rsum, i - 1);
		if (ans < 0) ans += INF;
		printf("%lld\n", ans);
	}
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int A[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>A[i][j];
        }
    }
    int dp[n+1][3];
    for(int i=0;i<=n;i++){
        for(int j=0;j<3;j++){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = A[0][0];
    dp[0][1]= A[0][1];
    dp[0][2] = A[0][2];
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            dp[i][j] = A[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
        }
    }
            int ans = INT_MIN;
    for(int i=0;i<3;i++){
        ans = max(ans,dp[n-1][i]);
    }
     cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
package main

import "fmt"

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var (
		n int
		s string
	)
	fmt.Scan(&n)
	count, bxa, bx, xa := 0, 0, 0, 0
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		for j := 0; j < len(s)-1; j++ {
			if s[j] == 'A' && s[j+1] == 'B' {
				count++
			}
		}
		if s[0] == 'B' && s[len(s)-1] == 'A' {
			bxa++
		} else if s[0] == 'B' {
			bx++
		} else if s[len(s)-1] == 'A' {
			xa++
		}
	}

	if bxa == 0 {
		count += min(bx, xa)
	} else if bx == 0 && xa == 0 {
		count += bxa - 1
	} else {
		count += bxa + min(bx, xa)
	}
	fmt.Println(count)
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
  string s,t;
  map<string,int>m;
  for(;cin>>s;)m[s]++;
  s=t=(*m.begin()).first;
  int M=(*m.begin()).second,l=s.length();
  for(map<string,int>::iterator it=m.begin();it!=m.end();it++){
    if(M<(*it).second)M=(*it).second,s=(*it).first;
    if(l<(*it).first.length())l=(*it).first.length(),t=(*it).first;
  }
  cout<<s<<' '<<t<<endl;
}

Measured memory_bytes: 1192
#include<stdio.h>

int main(){
  int n;
  char p, dummy;
  int input;
  int arr[4][13];
  int i, j;
  
  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      arr[i][j] = 0;
    }
  }


  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%c", &dummy);
    scanf("%c %d", &p, &input);
    switch(p){
      case 'S':
	arr[0][input - 1] = 1;
	break;
      case 'H':
	arr[1][input - 1] = 1;
	break;
      case 'C':
	arr[2][input - 1] = 1;
	break;
      case 'D':
	arr[3][input - 1] = 1;
	break;
    }
  }


  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      if(arr[i][j] == 0){
        switch(i){
          case 0:
            printf("S %d\n", j + 1);
            break;
          case 1:
            printf("H %d\n", j + 1);
            break;
          case 2:
            printf("C %d\n", j + 1);
            break;
          case 3:
            printf("D %d\n", j + 1);
            break;
        }
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 2112
public class Main {
  private static void solve() {
    int n = ni();
    if (n % 10 == 0) {
      System.out.println(10);
    } else {
      int x = 0;
      while (n > 0) {
        x += n % 10;
        n /= 10;
      }
      System.out.println(x);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 22612
input = $stdin.read.split("\n")
s = input[0]
k = input[1].to_i
 
s.chars.each_with_index do |c, i|
    next if (c == "a")
    diff = ("z".ord - c.ord + 1)%26
    if (diff <= k)
        s[i] = "a"
        k = k - diff
    end
end
 
if k > 0
    last = s.length-1
    char = (s[last].ord + (k%26)).chr
    char = (char.ord - 26).chr if char.ord > "z".ord
    s[last] = char
end
 
puts s

Measured memory_bytes: 9724
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.parseLong;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		boolean[] f = new boolean[n];
		int cnt=0;
		i=0;
		while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		}
		out.println(i==1?cnt:-1);
	}
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	int x = n + m;
	int y = n - m;
	int z = n * m;
	int mx = max(x, max(y, z));
	cout << mx << endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define INF ((1ll<<60)-233)
#define sqr(x) ((x)*(x))
#define debug puts("wzpkking")
using namespace std;
const int N=4005,mo=998244353;
int C[N][N],P[N],k,n;
int solve(int x,int y,int z){
	int ans=0;
	For(i,0,min(z,x))
		if (y+i>0) ans=(ans+1ll*P[i]*C[x][i]%mo*C[z+y-1][y+i-1])%mo;
	return ans;
}
int main(){
	For(i,0,N-1){
		C[i][0]=1;
		For(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
	}
	P[0]=1;
	For(i,1,N-1) P[i]=P[i-1]*2%mo;
	scanf("%d%d",&k,&n);
	For(i,2,2*k){
		int cnt=min(i-1,k)-max(0,i-k-1);
		int ans=solve(cnt/2,k-cnt,n);
		if (!(i&1)) ans=(ans+solve(cnt/2,k-cnt,n-1))%mo;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 61440
fun main(args: Array<String>) {
    val (n, k, q) = readLine()!!.split(" ").map { it.toInt() }
    val arr = IntArray(n)
    repeat(q) {
        val a = readLine()!!.toInt()
        arr[a - 1]++
    }
    arr.map { it + k - q }
        .map { it > 0 }
        .forEach {
            println(if (it) "Yes" else "No")
        }
}

Measured memory_bytes: 45632
/*
{

AuThOr Gwj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MAXN=1000+1;
int n,m;
char maze[MAXN][MAXN];
int dp[MAXN][MAXN];
int dire[4][2]={
{1,0},
{-1,0},{0,1},{0,-1}
};
int main(){
	fastio;
	memset(dp,63,sizeof(dp));
	cin>>n>>m;
	int s1,s2;
	R2(s1,s2);
	int t1,t2;
	R2(t1,t2);
	rb(i,1,n)
		rb(j,1,m)
			R(maze[i][j]);
	deque<pair<int,mp > > qq;
	dp[s1][s2]=0;
	qq.PB(II(0,II(s1,s2)));
	while(!qq.empty()){
		int val,i,j;
		val=qq.front().FIR;
		i=qq.front().SEC.FIR;
		j=qq.front().SEC.SEC;
//		cout<<i<<"
		qq.pop_front();
		if(dp[i][j]!=val) continue;
//		cout<<i<<" "<<j<<" "<<val<<endl; 
		rep(k,4){
			int ni,nj;
			ni=i+dire[k][0];
			nj=j+dire[k][1];
			if(ni<=n&&nj<=m&&ni>=1&&nj>=1&&maze[ni][nj]=='.'){
				if(val<dp[ni][nj]){
					dp[ni][nj]=val;
					qq.push_front(II(val,II(ni,nj)));
				} 
			}
		}
		rb(k,-2,2)
			rb(k2,-2,2){
			int ni,nj;
			ni=i+k;
			nj=j+k2;
			if(ni<=n&&nj<=m&&ni>=1&&nj>=1&&maze[ni][nj]=='.'){
				if(val+1<dp[ni][nj]){
					dp[ni][nj]=val+1;
					qq.push_back(II(val+1,II(ni,nj)));
				} 
			}
			}		
	}
	if(dp[t1][t2]==INF) dp[t1][t2]=-1;
	cout<<dp[t1][t2]<<endl; 
	return 0;
}



Measured memory_bytes: 8548
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
    
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// struct chash { int operator()(int x) const { return x ^ RANDOM; }};
// cc_hash_table<int, int, hash<int>> cnt;

int x[6];

void solve(){
    FOR(i,1,5) cin>>x[i];

    FOR(i,1,5){
        if(x[i] == 0){
            cout<<i<<endl;
            return;
        }
    }
}
    
signed main(){
    
    FastRead;     

    
    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}
    




Measured memory_bytes: 3640
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        int[] a= new int[26];
        int sum=0;
        for(int i=0; i<s.length(); i++) {
        	a[s.charAt(i)-'a']++;
        }
        for(int i=0; i<26; i++) {
        	sum+=a[i]%2;
        }
        System.out.println(sum/2);
	}
}


Measured memory_bytes: 26244
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String S = scan.next();
        if(S.equals("AAA")||S.equals("BBB")){
            System.out.println("No");
        }
        else{
            System.out.println("Yes");
        }
    }
}


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

using namespace std;

int main() {
 int x,y;
  cin>>x>>y;
  int rew=0;
  if (x<4) rew+=(4-x)*100000;
  if (y<4) rew+=(4-y)*100000;
  if (x==1 && y==1) rew+=400000;
  cout<<rew;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
long long ans=1,n;
int main(){
    scanf("%lld",&n);
    for(long long i=1;i<=n;i++) ans=ans*i%1000000007;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		int ans = 0;
		for(int i=0; i<S.length; i++)
			if(S[i]!=T[i])
				ans++;
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 32900
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sz[100009],mn[100009],mq[100009],h[100009],f[100009];
vector<ll> v[100009];
ll K;
string s;
ll n;
ll ans = 1e18;
void dfs(ll x, ll d){
        f[x] = 1;
    vector<pair<ll,ll> > u;
    mq[x] = 0;
    mn[x] = 0;
    if(s[x-1] == '1') sz[x] = 1, K+= d;
    for(auto y:v[x]){
        if(f[y]) continue;
        dfs(y,d+1);
        sz[x] += sz[y];

        mq[x] += mq[y] + sz[y];
        u.push_back({mq[y]+ sz[y], mn[y]+ sz[y]});

    }
    sort(u.begin(), u.end());
    if(u.size() == 0){
        mn[x] = 0;

  //  cout<<x<<" "<<mn[x]<<" "<<mq[x]<<endl;
        return;
    }
    if(u.size() == 1){
        mn[x] = u[0].second;

  //  cout<<x<<" "<<mn[x]<<" "<<mq[x]<<endl;
        return;
    }
    for(ll i = 0; i < u.size()-1; i++)
        mn[x] -= u[i].first;
    mn[x] += u.back().second;
    if(mn[x] < 0) mn[x] = mq[x]%2;
   // cout<<x<<" "<<mn[x]<<" "<<mq[x]<<endl;
}
void ch(ll x){
    for(ll i = 1; i<= n; i++)
        f[i] = 0,sz[i] = 0;
    K = 0;
    dfs(x,0);
    if(mn[x] == 0) {
        ans = min(ans, K/2);
    }
}
main(){
    cin >> n>>s;
    for(ll i = 1;i <= n-1; i++){
        ll a,b;cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(ll i = 1; i <= n; i++)
        ch(i);
    if(ans == 1e18) cout<<-1;
    else cout<<ans<<endl;
    //sum(r[i1]) * X
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
using namespace std;
int main()
{
    ll x;
    cin>>x;
    ll ans = 0;
    ll temp = x;
    while(temp>=500)
    {
        ans++;
        temp = temp - 500;
    }
    // cout<<ans<<'\n';
    ans = 1000*ans;
    x = x%500;
    // cout<<x<<'\n';
    ll a =0;
    while(x>=5)
    {
        a++;
        x = x-5;
    }
    ans += 5*a;
    cout<<ans<<'\n';
}

Measured memory_bytes: 3584
N,M=map(int,input().split())
A,B=[sorted(map(int,input().split())) for i in range(2)]
from collections import defaultdict
d=defaultdict(int)
for a in A:
    d[a]+=1
for b in B:
    d[b]+=1001
if d[N*M]!=1002:
    print(0)
    exit()
x,y,s,r=1,1,0,1
m=10**9+7
for i in range(N*M-1,0,-1):
    if d[i]==1002:
        s+=x+y
        x+=1
        y+=1
    elif d[i]==1001:
        r=(r*x)%m
        s+=x-1
        y+=1
    elif d[i]==1:
        r=(r*y)%m
        s+=y-1
        x+=1
    elif d[i]==0 and s>0:
        r=(r*s)%m
        s-=1
    else:
        r=0
        break
print(r)

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

int main() {
    int N, A; cin >> N >> A;
    int nN = N / 500;
    nN = N - nN * 500;
    if (nN <= A)  {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>

#define SENTINEL 1100000000000000000

int count = 0;
void merge(long long int A[], int left, int mid, int right);

void mergeSort(long long int A[], int left, int right) {
	int i, mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}



void merge(long long int A[], int left, int mid, int right) {
	int n1, n2, i, j, k;
	long long int *L, *R;
	n1 = mid - left;
	n2 = right - mid;
	L = (long long int *)malloc(sizeof(long long int)*(n1 + 1));
	R = (long long int *)malloc(sizeof(long long int)*(n2 + 1));
	for (i = 0; i <= n1 - 1; i++) {
		L[i] = A[left + i];
	}
	for (j = 0; j <= n2 - 1; j++) {
		R[j] = A[mid + j];
	}
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	i = 0;
	j = 0;
	for (k = left; k <= right - 1; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
			count++;
		}
		else {
			A[k] = R[j];
			j++;
			count++;
		}
	}
	free(L);
	free(R);
}



int main() {
	long long int result = 0, n, memo = 1, m, a[200005] = {}, sum[200005] = {};
	scanf("%lld%lld", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		sum[i] = sum[i - 1] + a[i];
		sum[i] %= m;
	}
	mergeSort(sum, 1, n + 1);
	for (int i = 1; i <= n; i++) {
      	
		if (sum[i] == sum[i - 1]) { memo++; }
		else {
			result += memo * (memo - 1) / 2;
          	memo=1;
		}
	}
  	result += memo * (memo - 1) / 2;
	printf("%lld", result);
}

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

int s, n, t, m, p;

bool minutes[7 * 24 * 60];

int wbits, tbits;

double ck(int start){
  int cnt = 0;
  for(int i = 0; i < m; i++, start += t){
    bool flag = true;
    for(int j = 0; j <= s; j++){
      if(!minutes[(start + j) % (7 * 24 * 60)]){
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return( 1.0 - pow( 1.0 - 1.0/p, (double)cnt * n));
}


inline int todays(int i){
  return(i / (24 * 60));
}
inline bool totime(int i){
  int tm = i % (24 * 60) / 24;
  return(tm >= 18 || tm < 6);
}

int main(){
  string weekday, time ;
  while( cin >> s >> n >> t >> weekday >> time >> p >> m, m){
    if(weekday == "All") wbits = (1 << 7) - 1;
    else wbits = 1 ;
    if(time == "Night") tbits = 1;
    else if(time == "Day") tbits = 2;
    else tbits = 3; 

    double ans = 0.0;
    for(int i = 7 * 24 * 60 - 1; i >= 0; i--){
      minutes[i] = 
        wbits >> todays(i) & 1 && (tbits >>(i/360+1)%4/2) & 1;
    }

    for(int i = 24 * 60 - 1; i >= 0; i--){
      ans = max( ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}

Measured memory_bytes: 1340
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    int n;
    cin >> n;
    vi data;
    F(i, 0, n){
        int l;
        cin >> l;
        data.pb(l);
    }
    printV(data);
    F(i, 1, data.size()){
        int key = data[i];
        // insert data[i] into the sorted sequence A[0,....j-1]
        int j = i-1;
        while(j >= 0 && data[j] > key){
            data[j+1] = data[j];
            j--;
        }
        data[j+1] = key;
        printV(data);
    }
}



Measured memory_bytes: 3168
#include <iostream>

using namespace std;

int main(){
  int A[3][3];
  bool bA[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      bA[i][j]=false;
    }
  }
  int N;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> A[i][j];
    }
  }
  cin >> N;
  for(int n=0;n<N;n++){
    int b;
    cin >> b;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(b==A[i][j]) bA[i][j]=true;
      }
    }
  }
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    }
  }
  //check bingo
  bool bingo=false;
  //horizontal & vertical
  for(int i=0;i<3;i++){
    if(bA[i][0] && bA[i][1] && bA[i][2]) bingo=true; 
    if(bA[0][i] && bA[1][i] && bA[2][i]) bingo=true;
  }
  //diagonal
  if(bA[0][0] && bA[1][1] && bA[2][2]) bingo=true;
  if(bA[0][2] && bA[1][1] && bA[2][0]) bingo=true;
  if(bingo) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main (){


    int a,b,c;
    cin >> a >> b >> c;

    if(c <= a - b){
        cout << 0 << endl;
    }else{
        cout << c -(a - b) << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f first
#define s second
#define mod 1000000007

ll power(ll x, ll y){
	if(y==0)return 1;
	ll ps = power(x, y/2)%mod;
	ll ss = (ps%mod*ps%mod)%mod;
	if(y&1)ss = (x%mod*ss%mod)%mod;
	return ss%mod;
}

int main(){
	
	ll n;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)cin>>arr[i];
	ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			ans += arr[i]*arr[j];
		}
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=ss()
wcnt,ecnt=0,0
ans=10**100
wsum=arr.count("W")
esum=n-wsum

for i in range(n):
    if arr[i]=="W":
        ans=min(wcnt+esum-ecnt,ans)
        #print(wcnt+esum-ecnt)

        wcnt+=1
    else:
        ecnt+=1
        ans=min(wcnt+esum-ecnt,ans)
        #(wcnt+esum-ecnt)
print(ans)



Measured memory_bytes: 67028