akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    //データ定義
    string str;
    
    //データ入力
    cin >> str;

    //各桁の和を計算する
    while(str[0] != '0'){
        int i, sum = 0;
        for(i = 0; i < str.size(); i++){
            sum += str[i] - '0';
        }
        cout << sum << endl;
        cin >> str;
    }

    return 0;
}


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

int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll dif=b-a;
	ll ans;
	if(dif%2==0)
		ans=dif/2;
	else 
	{
		ans=min(a+(b-a-1)/2,n-b+1+(b-a-1)/2);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 768
from itertools import combinations
n, *S = open(0).read().split()
# 頭文字だけ抜き出す.
cap = [s[0] for s in S]
# M,A,R,C,H,それぞれ頭文字の中にある数をカウント.
cnt = [cap.count(i) for i in "MARCH"]
# 組み合わせの合計を取る.
ans = sum(x*y*z for x, y, z in combinations(cnt, 3))
print(ans)

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

int main(){
    int n;cin>>n;
    vector<int> a(n);
    for(int i = 0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int an = n/2;
    cout << a[an]-a[an-1] << endl;
}

Measured memory_bytes: 640
n = gets.to_i

ab = []
n.times do
  ab << gets.split.map(&:to_i)
end
ab.sort!{|a, b| a[0] <=> b[0] }

count  = 0
if ab.size == 1
  a, b = ab[0]
  if a == 1
    count = b + 1
  else
    count = b + a
  end
else
  top    = 0
  lowest = ab.max[0]
  ab.each do |a, b|
    if a == 1
      count += 1
    elsif top == 0 and a == 2
      count += 2
    elsif a == lowest
      count += b + (a - top)
    elsif a - top == 1
      count += 1
    else
      count += a - top
    end
    top = a
  end
end
puts count


Measured memory_bytes: 12536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const double pi = acos(-1);
const int mod = 998244353;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
int a[maxn];

int main(){
	int k,n;
	scanf("%d %d",&k,&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
	}
	int ma = 0;
	for(int i = 2;i <= n;i++){
		if(a[i] - a[i-1] > ma) ma = a[i] - a[i-1];
	}
	ma = max(ma,k-a[n]+a[1]);
	cout << k - ma << endl;
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,ppos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n;
      ll dp[n+1];
      rep(i,n+1){
        dp[i]=LINF;
      }
      dp[0]=0;
      rrep(i,1,n+1){
        if(i<6){
          dp[i]=min(dp[i-1]+1,dp[i]);
        }
        else if(i<9){
          pos=6;
          while(1){
            dp[i]=min({dp[i-1]+1,dp[i-pos]+1,dp[i]});
            pos*=6;
            if(pos>i)break;
          }
        }
        else{
          pos=6;
          ppos=9;
          while(1){
            if(ppos>i){
              dp[i]=min({dp[i-1]+1,dp[i-pos]+1,dp[i]});
               pos*=6;
            }
            else dp[i]=min({dp[i-1]+1,dp[i-pos]+1,dp[i-ppos]+1,dp[i]}),pos*=6,ppos*=9;
            if(pos>i)break;
          }
        }
      }
      Cout(dp[n]);
    
       
return 0;
}


Measured memory_bytes: 1024
import copy


def main():
    H, W = map(int, input().split())
    b = [
        list(input())
        for _ in range(H)
    ]

    ans = copy.deepcopy(b)

    for h in range(H):
        for w, s in enumerate(b[h]):
            if s == "#":
                continue

            w_left = max(w - 1, 0)
            h_top = max(h - 1, 0)
            h_bottom = min(h + 2, H)
            n = 0
            for _h in range(h_top, h_bottom):
                n += b[_h][w_left:w + 2].count("#")

            ans[h][w] = str(n)

    for a in ans:
        print("".join(a))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3688
#include <bits/stdc++.h>
		using namespace std;
		
		typedef long long ll;
		#define pi 3.14159265 
		#define EPS 1e-8
		
		#define mod 998244353
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define endl "\n"

		const ll INF=(ll)2e18;
	
		
		int main()
		{
			 ios_base::sync_with_stdio(false);
			 cin.tie(NULL);
			
			ll n,x;
			cin>>n>>x;
			if(x==1 || x==(2*n-1))
			{
				cout<<"No";
				exit(0);
			}
			vector<ll> v(2*n,0);
			v[n]=x;
			v[n+1]=x+1;
			v[n-1]=x-1;
			vector<ll> vis(2*n,0);
			vis[x]=vis[x+1]=vis[x-1]=1;
			if(x+2<=(2*n-1))
			{
				v[n-2]=x+2;
				vis[x+2]=1;
			}
			if((x-2)>=1)
			{
				v[n+2]=x-2;
				vis[x-2]=1;
			
			}
			ll j=1;
			for(ll i=1;i<2*n;i++)
			{
				if(v[i])
					continue;
				while(vis[j])
				{
					j++;
				}
				vis[j]=1;
				v[i]=j;
			}
			cout<<"Yes\n";
			for(ll i=1;i<2*n;i++)
			{
				cout<<v[i]<<endl;
			}
		}
						
					 
				 


Measured memory_bytes: 4608
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

/*全てのライブラリをインクルード*/
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    string s;
    cin>>s;
    rep(i,19){
        if(i==5||i==13){
            cout<<" ";
        }
        else cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3628
nums = gets.split(" ").map{|x| x.to_i}
until nums[0]== 0 && nums[1] ==0
iti,go,sen =0,0,0 
turi = nums[1] - nums[0]
sen = turi/1000
turi %= 1000
go = turi/500
turi %= 500
iti = turi/100
nums = gets.split(" ").map{|x| x.to_i}
printf("%d %d %d\n",iti,go,sen)
end

Measured memory_bytes: 6124
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int A = 0, T = 1, C = 2, G = 3;

int n;
ll mod = INF;
ll ans = 0;
ll dp[101][4][4][4];


int main() {
	
	cin >> n;

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				if (i == A && j == G && k == C)dp[3][i][j][k] = 0;
				else if (i == A && j == C && k == G)dp[3][i][j][k] = 0;
				else if (i == G && j == A && k == C)dp[3][i][j][k] = 0;
				else dp[3][i][j][k] = 1;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				for (int l = 0; l < 4; l++) {
					for (int m = 0; m < 4; m++) {
						if (k == A && l == G && m == C)continue;
						if (k == A && l == C && m == G)continue;
						if (k == G && l == A && m == C)continue;
						if (j == A && l == G && m == C)continue;
						if (j == A && k == G && m == C)continue;
						dp[i + 1][k][l][m] += dp[i][j][k][l] % mod;
					}
				}
			}
		}
	}
	
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				ans += dp[n][i][j][k] % mod;
			}
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int MAX = 1e5 + 5;
priority_queue <int> q;
vector <int> v[MAX];
int main()
{
	boost;
	int n, m, i, a, b;
	cin >> n >> m;
	fo(i, 0, n){
		cin >> a >> b;
		v[a].pb(b);
	}
	int ans = 0;
	for(i = m - 1; i >= 0; i--){    // Start from the last day i.e. m - 1 th day 
		for(auto x : v[m - i])
		q.push(x);
		if(!q.empty()){
			ans += q.top();
			q.pop();
		}
	}
	cout << ans;
}


Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int c11=sc.nextInt();
        int c12=sc.nextInt();
        int c13=sc.nextInt();
        int c21=sc.nextInt();
        int c22=sc.nextInt();
        int c23=sc.nextInt();
        int c31=sc.nextInt();
        int c32=sc.nextInt();
        int c33=sc.nextInt();
        int a=c11-c21;
        int b=c12-c22;
        int d=c13-c23;
        int e=c21-c31;
        int f=c22-c32;
        int g=c23-c33;
        if(a==b&b==d&e==f&f==g) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
            

    }

}

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

int main() {
	string x,y;
	cin>>x>>y;
	if(x>y){
	    cout<<'>'<<'\n';
	}
	if(x<y){
	    cout<<'<'<<'\n';
	}
	if(x==y){
	    cout<<'='<<'\n';
	}
	return(0);
}


Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
	static ArrayList<Integer> listX = new ArrayList<Integer>();
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		makePrimeList(104730);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			
			System.out.println(listX.get(n-1));
		}
	}
	public static void makePrimeList(int n) {
		boolean[] isntPrime = new boolean[n];
		isntPrime[0] = isntPrime[1] = true;
		int sum = 2;
		listX.add(2);
		for(int i = 3; i < n; i+= 2) {
			if(!isntPrime[i]) {
				sum += i;
				listX.add(sum);
				for(int j = i + i; j < n; j+= i) {
					isntPrime[j] = true;
				}
			}
		}
	}

	
	
}

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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b, c, k;
    
    cin >> a >> b >> c >> k;

    int sum = 0;

    if (k <= a){
        cout << k;
    }
    else if (k <= a + b){
        cout << (k -  b); 
    }
    else {
        cout << a - (k - a - b);
    }
}




Measured memory_bytes: 3600
from collections import deque

def bfs(H, W, S):
    visited = [[False]*(W+2) for _ in range(H+2)]
    visited[1][1] = True
    unvisited = deque([(1,1)])
    dist = 1
    while unvisited:
        dist += 1
        un = deque()
        for x, y in unvisited:
            for t1, t2 in zip([-1,+1,0,0],[0,0,-1,1]):
                dx = x + t1
                dy = y + t2
                if S[dy][dx] != '#' and not visited[dy][dx]:
                    if dy == H and dx == W:
                        return dist
                    un.append((dx,dy))
                    visited[dy][dx] = True
        unvisited = un

    return -1

def main():
    H, W = map(int, input().split())
    S = ['#'+input()+'#' for _ in range(H)]
    S.insert(0,'#'*(W+2))
    S.append('#'*(W+2))
    step = bfs(H,W,S)
    white = sum([n.count('.') for n in S])
    if step == -1:
        print(step)
    else:
        print(white - step)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
bitset<4000010> dp;
int main() {
	int n, sum = 0; scanf("%d", &n), dp[0] = 1;
	for (int i = 1, a;i <= n;i++) scanf("%d", &a), dp |= dp << a, sum += a;
	for (int i = (sum + 1) / 2;i <= sum;i++) if (dp[i]) return printf("%d\n", i), 0;
}

Measured memory_bytes: 1792
#include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<utility>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
/*
(char)'1' - (int)48 = (int)1;


*/


int main()
{
	int n, a, b, c, x;
	cin >> n >> a >> b >> c >> x;
	while (n!=0)
	{
		int y[120];
		for (int i = 0; i < n; i++)cin >> y[i];
		int ans = 0;
		int maxx = 20000;
		for (int i = 0; i < n; i++)
		{
			while (maxx>0)
			{
				if (x == y[i])
				{
					x = (a*x + b) % c;
					if (i != n - 1)ans++;
					break;
				}
				ans++;
				x = (a*x + b) % c;
				maxx--;

			}

		}
		if (ans > 10000)cout << -1 << endl;
		else cout << ans << endl;
		cin >> n >> a >> b >> c >> x;
	}
	
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int x, n;
    cin >> x >> n;
    int dis, min = 150, idx = 1;
    vector<int> p(n);
    rep(i, n)
    {
        cin >> p[i];
    }
    bool flg;
    for (int i = 0; i <= 101; i++)
    {
        flg = true;
        rep(j, n)
        {
            if (p[j] == i)
            {
                flg = false;
            }
        }
        if (flg)
        {
            dis = abs(i - x);
            if (dis < min)
            {
                min = dis;
                idx = i;
            }
        }
    }
    cout << idx << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

VI adj[512345];
int N;
int indeg[512345] = {};
int id[1000][1000];
int toID(int i, int j){
    if(i > j) swap(i,j);
    return id[i][j];
}

int DAG_check(int indeg[]){
    stack<int> st;
    REP(i,N*(N-1)/2){
        if(indeg[i] == 0) st.push(i);
    }
    VI ans;

    while(!st.empty()){
        int i = st.top(); st.pop();
        ans.eb(i);
        for(auto j : adj[i]){
            indeg[j]--;
            if(indeg[j] == 0) st.push(j);
        }
    }

    if(SZ(ans) == N*(N-1)/2) return 1;
    else return 0;
}

int visited[512345]={};
int dp[512345]={};

int dfs(int i){
    if(visited[i]) return dp[i];

    visited[i] = 1;
    dp[i] = 1;
    for(int j : adj[i]){
        int res = dfs(j);
        dp[i] = max(dp[i],res+1);
    }

    return dp[i];
}



signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    vector<VI> A(N,VI(N-1));
    REP(i,N){
        REP(j,N-1) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    int V = 0;
    REP(i,N) REP(j,N){
        if(i < j) id[i][j] = V++;
    }
    dump(V)
    REP(i,N){
        REP(j,N-1){
            A[i][j] = toID(i,A[i][j]);
        }
        REP(j,N-2){
            adj[A[i][j]].eb(A[i][j+1]);
            indeg[A[i][j+1]]++;
        }
    }

    int ans = 0;
    if(DAG_check(indeg)){
        REP(i,N*(N-1)/2){
            ans = max(dfs(i),ans);
        }
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }




}


Measured memory_bytes: 41848
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll c=0,n;
    string s;
    cin>>n>>s;
    if(n<3)
    cout<<0;
    else{
    for(int i=0;i<n-2;i++)
    {
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
        c++;
    }
    cout<<c;}}

Measured memory_bytes: 3624
from collections import Counter
def main():
    N = int(input())

    c = Counter()
    M = 0
    for i in range(N):
        s = input()
        n = c[s] + 1
        c[s] = n
        M = max(M, n)

    for s in sorted((s for s, c in c.items() if c == M)):
        print(s)
main()

Measured memory_bytes: 32448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    ll n,k,ans=pow(10,9);
    cin >> n >> k;
    vector<ll> v(n);
    for(ll i=0;i < n;i++)
    {
        cin >> v.at(i);
    }
    sort(v.begin(),v.end());
    
    for(ll i=0;i+k-1 <(ll)v.size();i++)
    {
        ans = min(ans,-v.at(i)+v.at(i+k-1));
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 1e5 + 100,mod = 1e9 + 7;
int n,sum; char s[N];
int nex[N][2],f[N];
int main()
{
	scanf("%s",s + 1); n = strlen(s + 1);
	int flag = 1; for(int i = 1;i < n;i ++) if(s[i] == s[i + 1]) flag = 0;
	if(flag) {puts("1"); return 0;}
	sum = 0; f[n + 1] = 1; nex[n + 1][0] = nex[n + 1][1] = nex[n + 2][0] = nex[n + 2][1] = n + 2;
	for(int i = n;i >= 1;i --)  
	{
		sum = (sum + s[i] - 'a' + 1) % 3;
		nex[i][0] = s[i] == 'a' ? i + 1 : s[i + 1] == 'b' ? i + 2 : nex[i + 2][0];
		nex[i][1] = s[i] == 'b' ? i + 1 : s[i + 1] == 'a' ? i + 2 : nex[i + 2][1];
		f[i] = ((sum == 0) + f[nex[i][0]] + f[nex[i][1]] ) % mod;
 	}
 	cout << (f[1] - (sum == 0) + mod) % mod;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n; cin>>n;
    int ans=0;
    string s;
    for(int i=1;i<=n;i++){
        if(to_string(i).length()%2!=0) ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s []byte
	fmt.Scan(&s)
	var c0, c1 int
	for i := range s {
		if s[i] == '0' {
			c0++
		} else {
			c1++
		}
	}
	fmt.Println(min(c0, c1) * 2)
}

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

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

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


Measured memory_bytes: 2592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A*B*C == 175 && A+B+C == 17 && A*B+B*C+C*A == 95){
    cout << "YES" << endl;
  }
  
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
n = gets.to_s.to_i
s = gets.to_s.chomp.chars

ans = s.count('R') * s.count('G') * s.count('B')
for i in 0..n
  t = 1
  while i + 2 * t < n
    j = i + t
    k = j + t
    ans -= 1 if s[i] != s[j] && s[j] != s[k] && s[i] != s[k]
    t += 1
  end
end

puts ans

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;


signed main(){
  string s;
  cin>>s;
  rep(i,s.size()-1){
    if(s[i]==s[i+1]){
      cout<<i+1<<' '<<i+2<<endl;
      return 0;
    }
  }
  rep(i,s.size()-2){
    if(s[i]==s[i+2]){
      cout<<i+1<<' '<<i+3<<endl;
      return 0;
    }
  }
  cout<<-1<<' '<<-1<<endl;

  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 2, 0);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    long long sum = 0;
    for (int i = 1; i <= N + 1; i++)
        sum += abs(A[i] - A[i - 1]);

    for (int i = 1; i <= N; i++) {
        cout << sum + abs(A[i + 1] - A[i - 1]) - (abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1])) << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>

int main(void)
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b==c+d)puts("Balanced");
    else if(a+b>c+d)puts("Left");
    else puts("Right");
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int sum;
	sum = 0;
	for (int i=0; i < N; i++ ){
		int l;
		int r;
		cin >> l >> r;
		int x = r - l + 1;
		sum += x;
	}
	cout << sum << endl;
}


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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a + b >= 10) {
			pr.println("error");
		} else {
			pr.println(a + b);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


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

int main()
{
    ull N, M, sum = 0;
    cin >> N >> M;
    priority_queue<int> q;
    rep(i, N){
        int a;
        cin >> a;
        q.push(a);
    }
    rep(i, M){
        int a = q.top(); q.pop();
        q.push(a/2);
    }
    rep(i, N){
        sum += q.top(); q.pop();
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 892
def solve():
    s = int(input())
    
    ans, an = 1, s
    while 1:
        if an == 4 or an == 2 or an == 1:
            ans += 3
            break
        if an % 2 == 0:
            an //= 2
        else:
            an = 3 * an + 1
        ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int H[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	int ma=0,ret=0;
	FOR(i,N) {
		cin>>H[i];
		if(ma<=H[i]) ret++;
		ma=max(ma,H[i]);
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
s = input()
left = s[:2]
right = s[2:]

if (0 < int(left) < 13) and (0 < int(right) < 13):
  print("AMBIGUOUS")
elif (0 < int(left) < 13) and ((int(right) >= 13) or (int(right) == 0)):
  print("MMYY")
elif ((int(left) >= 13) or (int(left) == 0)) and (0 < int(right) < 13):
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 38256
import random
d=int(input())
c=list(map(int,input().split()))
num=[0]*26
ans=[]
numans=0
s=[]
for i in range(1,d+1):
    num1=1
    num2=-(10**100)
    num3=[0]*26
    for j in range(26):
        num3[j]=-1*((i-num[j])*c[j])
    s.append(list(map(int,input().split())))
    for j in range(26):
        num5=s[i-1][j]-num3[j]
        if num5>num2:
            num1=j+1
            num2=num5
    ans.append(num1)
    numans+=num2+s[i-1][num1-1]
    num[num1-1]=i
def sco(n1,n2,n3):
    n0=0
    n01=[0]*26
    old=ans[n1]
    ans[n1]=n2
    for k in range(n3):
        n0+=s[k][ans[k]-1]
        n01[ans[k]-1]=k+1
        for l in range(26):
            n0-=(k+1-n01[l])*c[l]
    return n0
for i in range(1545):
    num6=random.randint(1,26)
    num7=random.randint(2,364)
    num100=sco(num7-1,num6,d)
    if num100>numans:
        ans[num7-1]=num6
for i in range(d):
    print(ans[i])


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

int main(){
  int N; cin >> N;
  vector<int> A(N), B(N), C(N);
  rep(i, 0, N) cin >> A[i];
  rep(i, 0, N) cin >> B[i];
  rep(i, 0, N) cin >> C[i];
  sort(A.begin(),A.end());
  sort(C.begin(),C.end());
  ll ans = 0;
  rep(i, 0, N) {
    ll a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    ll c = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    ans += a * c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main() {
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);
  if((A==5 && B==5 && C==7) || (A==5 && B==7 && C==5) || (A==7 && B==5 && C==5)){
    printf("YES\n");}
  else
    printf("NO\n");
  return 0;
}

Measured memory_bytes: 128
import bisect
m, n = map(int, input().split())
w = [tuple(map(int, input().split())) for _ in range(m)]
w, t = map(list,zip(*w))
for i in range(1, m):
    w[i] += w[i - 1]
    t[i] += t[i - 1]
c = [tuple(map(int, input().split())) for _ in range(n)]
c, b = map(list,zip(*c))
a = {}
a[tuple(range(n))] = -1
for _ in range(n):
    an = [(k,a[k]) for k in a]
    a = {}
    for x in an:
        for p in x[0]:
            if x[1] != -1:i = min(bisect.bisect_right(w, c[p] + w[x[1]], x[1]), bisect.bisect_right(t, b[p] + t[x[1]], x[1])) - 1
            else:i = min(bisect.bisect_right(w, c[p]), bisect.bisect_right(t, b[p])) - 1
            y = list(x[0])
            y.remove(p)
            y = tuple(y)
            if y in a:a[y] = max(a[y], i)
            else:a[y] = i
print(max([a[i] for i in a]) + 1)


Measured memory_bytes: 37144
n=int(input())
a=list(map(int,input().split()))
x=[0]*(10**5+1)
ans=0
for i in range(n):
    if a[i]>10**5:
        ans+=1
    else:
        x[a[i]]+=1
for i in range(1,10**5+1):
    if x[i]<i:
        ans+=x[i]
    else:
        ans+=x[i]-i
print(ans)


Measured memory_bytes: 85340
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M;
    cin >> N >> M;
    vector<int> h(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }
    vector<vector<int>> g(N + 1);
    vector<int> r(N + 1, 1);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (h[u] <= h[v]) {
            r[u] = 0;
        }
        if (h[u] >= h[v]) {
            r[v] = 0; 
        }
    }
    int res = 0;
    for (int i = 1; i <= N; i++) {
        if (r[i]) res++;
    }
    cout << res <<endl;
    
    return 0;
}

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

#define MAX_LINE 256

int main(void);

int main(void)
{
  int n;
  int i;
  int a[4];
  char buf[MAX_LINE];
  
  fgets(buf, MAX_LINE, stdin);
  n = atoi(buf);
  
  for(i = 1; i <= 4; i++){
  	a[i] = n % 10;
  	n /= 10;
  }
  
  if(a[1] == a[2] && a[2] == a[3]){
    printf("Yes");
  }
  else if(a[2] == a[3] && a[3] == a[4]){
  	printf("Yes");
  }
  else{
  	printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
import bisect
h,w,m=map(int,input().split())
xnum=[[0,i] for i in range(h)]
ynum=[[0,i] for i in range(w)]
hw=[]
xmax=[]
ymax=[]
for i in range(m):
  s,t=map(int,input().split())
  xnum[s-1][0]+=1
  ynum[t-1][0]+=1
  hw.append([s-1,t-1])
hw.sort()
xnum.sort()
ynum.sort()
xmax.append(xnum[-1][1])
ymax.append(ynum[-1][1])
for i in range(2,len(xnum)+1):
  if xnum[-1*i][0]==xnum[-1][0]:
    xmax.append(xnum[-1*i][1])
  else:
    break
for i in range(2,len(ynum)+1):
  if ynum[-1*i][0]==ynum[-1][0]:
    ymax.append(ynum[-1*i][1])
  else:
    break
flag=True
for i in xmax:
  for j in ymax:
    l=bisect.bisect_left(hw,[i,j])
    r=bisect.bisect_right(hw,[i,j])
    if [i,j] in hw[l:r]:
      continue
    else:
      flag=False
      break

if flag:
  ans=xnum[-1][0]+ynum[-1][0]-1
else:
  ans=xnum[-1][0]+ynum[-1][0]
print(ans)

Measured memory_bytes: 131844
function Main(input) {
  var list = input.split("\n");
  var a = parseInt(list[0], 10);
  var e = parseInt(list[4], 10);
  var k = parseInt(list[5], 10);
  
  if (e-a>k) console.log(":(");
  else console.log("Yay!");
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string s; cin >> s;
    int n = (int)s.size();
    bool ok = 1;
    if(s[0] != 'A') ok = 0;
    int cnt = 0;
    for(int i = 2; i < n - 1; ++ i) {
        if(s[i] == 'C') ++ cnt;
    }
    if(cnt != 1) ok = 0;
    rep(i, n) {
        if('A' <= s[i] && s[i] <= 'Z' && s[i] != 'A' && s[i] != 'C') {
            ok = 0;
        }
    }
    cout << (ok ? "AC" : "WA") << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

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

    ll ans=0;
    rep1(i,n){
        if(n%i==0){
            ans+=(n/i-1);
        }
        else ans+=n/i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
iterate = 0
n = int(input())
num_list = input().split()
flag = 0
while True:
  i = 0
  while i <= n-1:
    if int(num_list[i])%2 == 1:
      flag = 1
      break
    num_list[i] = int(num_list[i])/2
    i += 1
  if flag == 1:
    break
  iterate += 1

print(iterate)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________


	int n, m;
	cin >> n >> m;
	int a[n];
	zip(i, 0, n)
	{
		cin >> a[i];
		//a[i] /= 2;
	}
	int ans = a[0];
	zip(i, 1, n)
	{
		ans = (a[i] * ans) / (__gcd(a[i], ans));
		if(ans>=2*m)
		{
             cout<<0<<en;
             return 0;
		}
	}
	//ans = ans / 2;
	vi v;
	map<int, int>mt;

	zip(i, 0, n)
	{
		int x = a[i];
		int cnt = 0;
		while (x % 2 == 0)
		{
			x /= 2;
			cnt++;
		}

		if (mt[2] == 0 && cnt != 0)
		{
			mt[2] = cnt;
		}
		else if (mt[2] != cnt)
		{
			cout << 0 << en;
			return 0;
		}
	}
	if (ans % 2==1)
	{
		cout << 0 << en;
		return 0;
	}
	int res = (2 * m) / ans;
	cout << (res + 1) / 2 << en;
	/*int cnt = 0;

	//cnt += (m /   (2 * ans - 1));

	int x = log2(m - ans);
	//cnt -= x;
	for (int i = ans; i <= m; i += 2)
	{
		if (i % ans == 0)
		{
			cnt++;
		}
	}
	cout << cnt  << en;*/

	return 0;
}



Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int K = scn.nextInt();

    ArrayList<Integer> h = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      h.add(scn.nextInt());
    }

    Collections.sort(h, new Comparator<Integer>() {
      public int compare(Integer d1, Integer d2) {
        return (d1 - d2 < 0) ? 1 : -1;
      }
    });

    int minDiff = Integer.MAX_VALUE;
    for (int i = 0; i < N - K + 1; i++) {
      minDiff = Math.min(minDiff, h.get(i) - h.get(i + K - 1));

    }

    System.out.println(minDiff);

  }

}


Measured memory_bytes: 58532
def stepUp(val_list):
    temp = 0
    counter = 0

    for i in range(len(val_list) - 1):
        current = val_list[i]
        up = val_list[i + 1]

        if (current > up):
            counter += current - up
            temp += current - up
            val_list[i + 1] = current
          
        temp = 0

    if (val_list[len(val_list) - 2] > val_list[len(val_list) -1]):
        counter += val_list[len(val_list) - 2] - val_list[len(val_list) -1]

    return counter

def userInput():
    a_count = int(input())
    a = list(map(int, input().rstrip().split()))
    
    return stepUp(a)
  
print(userInput())

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
map<ll, ll> sum;

map<ll, ll> primefact(ll n) {
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

ll modmul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }

signed main() {
    cin >> N;
    FOR(i, 1, N + 1) {
        auto pr = primefact(i);
        FOREACH(x, pr)(sum[x.first] += x.second) %= MOD;
    }
    ll ans = 1;
    FOREACH(s, sum) { ans = modmul(ans, s.second + 1); }
    cout << ans << "\n";
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

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

  int h, count = 0;
  for(int i = 0; i < N; i++) {
    cin >> h;
    if(h >= K) {
      count++;
    }
  }

  cout << count;

  return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

const int MAXN = 16;
int a[MAXN + 5][MAXN + 5];
ll v[1 << MAXN];
ll dp[1 << MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  rep(i, 0, n) rep(j, 0, n)
    cin >> a[i][j];
  rep(bm, 0, 1 << n) {
    rep(i, 0, n) {
      rep(j, 0, n) {
	if ((1 << i) & bm and (1 << j) & bm)
	  v[bm] += a[i][j];
      }
    }
    v[bm] /= 2;
  }
  rep(bm, 0, 1 << n) {
    dp[bm] = v[bm];
    for (int sm = bm; sm; sm = (sm - 1) & bm) {
      dp[bm] = max(dp[bm], dp[bm - sm] + v[sm]);
    }
  }
  cout << dp[(1 << n) - 1] << '\n';
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define int ll
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,m,v,p,ans;
int a[100005];
inline int check(int x)
{
    /*
    reg int y,t=0,i;
    y=v-(n-x+1);
    for(i=1;i<x;++i)
        if(a[i]>a[x]+m)++t;
    if(t>=p)return 0;
    y-=t;if(y<=0)return 1;
    reg ll s=1ll*m*y;
    for(i=t+1;i<x;++i)
        s-=1ll*(a[x]+m-a[i]);
    if(s<=0)return 1;
    for(i=t+1;i<x;++i)
    {
        s-=min(s,1ll*(a[i]-a[x]));++t;
        if(s==0)return t<p;
    }if(s==0)return t<p;
    */
    ll s=1ll*(v-(n-x+1)-p+1)*m,M=a[x]+m;
    for(reg int i=x-1;i>=p;--i)
    {
        if(a[i]>M)return 0;
        s-=M-a[i];
    }
    if(s<=0)return 1;
    return 0;
}
signed main()
{
    n=read(),m=read(),v=read(),p=read();
    reg int i,l,r,mid;
    for(i=1;i<=n;++i)a[i]=read();
    sort(a+1,a+1+n);reverse(a+1,a+1+n);
    l=1;r=n+1;
    while(l<r-1)
    {
        mid=(l+r)>>1;
        if(check(mid))l=mid;
        else r=mid;
    }cout<<r-1<<"\n";
	return 0;
}


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

#include <iostream>
using namespace std;

int main(int argc, char* argv[]){
        int N=0;
        int *A=NULL, *C=NULL;

        cin >> N;

        A = (int*)calloc(N+1, sizeof(int));
        C = (int*)calloc(N+2, sizeof(int));
        for(int i=0; i<N+1; i++){ C[i]=0; }

        for(int i=0; i<N; i++){
                cin >> A[i];
                C[A[i]]++;
        }
        long long total=0;
        for(int i=1; i<N+1; i++){
                long long a = (long long)C[i];
                total += a*(a-1)/2;
        }
        for(int i=0; i<N; i++){
                long long v = (long long)C[A[i]];
                long long d = 0;
                if(v>1) { d = v -1; }
                long long ans = total - d;
                printf("%lld\n", ans);
        }
        return 0;
}

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

int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) {
        cout << "No" << endl;
    } else if (s[0] == s[1] && s[2] == s[3]) {
        cout << "Yes" << endl;
    } else if (s[0] == s[2] && s[1] == s[3]) {
        cout << "Yes" << endl;
    } else if (s[1] == s[2] && s[0] == s[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define CON 1000000000000
#define SIX 1000000
using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << a*b/2 << endl;
  return 0;
}


Measured memory_bytes: 256
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p = sorted(p,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)

lis = p[:x]
lis.extend(q[:y])

lis = sorted(lis)

#print(lis)
ans = []
lr = len(r)
for i in range(len(lis)):
    if i<lr:
        ans.append(max(lis[i],r[i]))
    else:
        ans.append(lis[i])

print(sum(ans))


Measured memory_bytes: 113772
z;main(a){float b,c,d,e,f;for(;z=~scanf("%d%f%f%f%f%f",&a,&b,&c,&d,&e,&f);printf("%.3f %.3f\n",(c-b*f)/a,f/=a*e-b*d))f=a*f-d*c;}

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

ans = 0

sum_tmp = A[0]
xor_tmp = A[0]
l = 0
r = 1
while True:
        if r == N:
                ans += (r - l) * (r - l + 1) // 2
                break

        if sum_tmp + A[r] == xor_tmp ^ A[r]:
                sum_tmp += A[r]
                xor_tmp ^= A[r]
                r += 1
                continue

        ans += (r - l)

        if l+1 == r:
                l += 1
                r += 1
                sum_tmp = A[l]
                xor_tmp = A[l]
                continue

        sum_tmp -= A[l]
        xor_tmp ^= A[l]
        l += 1

print(ans)

Measured memory_bytes: 24584