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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	priority_queue<int> pq;
	while (n--) {
		int a;
		cin >> a;
		pq.push(a);
	}
	
	for (int i = 0; i < m; i++) {
		int val = pq.top();
		pq.pop();
		pq.push(val / 2);
	}
	long long ans = 0;
	while (!pq.empty()) {
		ans += pq.top();pq.pop();
	}
	cout << ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 892
//
//AtCoder Beginner Contest 087
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

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

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<vector<int>> a(2, vector<int>(n));;
    REP(i,2)REP(j,n) cin >> a[i][j];

    int ans=0;
    REP(i,n){
        int sum=0;
        int ud=0;
        REP(j,n){
            sum+=a[ud][j];
            if (i==j){
                sum+=a[1][j];
                ud=1;
            }
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> l(n);
	
	for(int i = 0; i < n; i++){
		cin >> l.at(i);
	}
	
	sort(l.begin(), l.end());
	
	bool ans_flg = true;
	
	int others = 0;
	for(int i = 0; i < n-1; i++){
		others += l.at(i);
	}
	ans_flg = (l.at(n-1) < others) ? true : false;
	
	string ans = ans_flg ? "Yes" : "No";
	
	cout << ans << endl;
	
}

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

using namespace std;
using ll = long long;

const int N = 200005;

int st[4*N];

void upd(int p, int L, int R, int i, int val) {
	if(i > R or i < L) return;
	if(L == R) {
		st[p] = val;
		return;
	}
	int mid = (L + R) / 2;
	upd(2 * p, L, mid, i, val);
	upd(2 * p + 1, mid + 1, R, i, val);
	st[p] = max(st[2 * p], st[2 * p + 1]);
}

int query(int p, int L, int R, int i, int j) {
	if(i > R or j < L) return 0;
	if(L >= i and R <= j) return st[p];
	int mid = (L + R) / 2;
	return max(query(2 * p, L, mid, i, j),
			   query(2 * p + 1, mid + 1, R, i, j));
}

int n;
int a[N];
vector<int> g[N];

int ans[N];

void dfs(int u, int p) {
	int old = query(1, 1, n, a[u], a[u]);
	int tmp = query(1, 1, n, 1, a[u] - 1) + 1;
	upd(1, 1, n, a[u], max(old, tmp));

	ans[u] = st[1];

	for(int v : g[u]) if(v != p) {
		dfs(v, u);
	}

	upd(1, 1, n, a[u], old);
}

int main() {

	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i);

	{
		set<int> s(a + 1, a + n + 1);
		map<int, int> go;
		int p = 1;
		for(int x : s) go[x] = p++;
		for(int i = 1; i <= n; i++) a[i] = go[ a[i] ];
	}

	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}

	dfs(1, 1);

	for(int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
}


Measured memory_bytes: 38524
n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|u|u.to_i}
if(n == 1 and a[0] == 0)
  puts 1
  exit
end
if(a.count(0) > 1) 
  puts 0
  exit
elsif(n % 2 == 0 and a.count {|item| item % 2 == 0 } > 0)
  puts 0
  exit
elsif(n % 2 == 1 and a.count {|item| item % 2 == 1 } > 0)
  puts 0
  exit
elsif(n % 2 == 1 and a.count {|item| item % 2 == 1 } > 0)
  puts 0
  exit
else
  a.sort!
  i = 0
  while(i < n)
    i += 1 if(a[i] == 0)
    if(i+2 < n)
      if(a[i] != a[i+2] - 2)
        puts 0
        exit
      end
      unless(a[i] == a[i+1])
        puts 0
        exit
      end
    elsif(i+1 < n)
      unless(a[i] == a[i+1])
        puts 0
        exit
      end
    else
        puts 0
        exit
    end
    i += 2
  end
  puts 2**(n/2) % (10**9+7)
end


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

int	main() {
	int N;
	cin >>N;
	vector<int> b(N);
	vector<int> c(0);
	for (int i=0; i<N; i++)
		cin >>b.at(i);
	while (b.size()>0) {
		int i;
		for (i=b.size()-1; i>=0; i--) {
			if (i+1==b.at(i)) {
				b.erase(b.begin()+i);
				c.push_back(i+1);
				break;
			}
		}
		if (-1==i) {
			cout <<-1 <<endl;
			return 0;
		}
	}
	for (int i=c.size()-1; i>=0; i--)
		cout <<c.at(i) <<endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    
    for i in range(1,10):
        for j in range(1,10):
            ans = i*j
            if ans == N:
                print("Yes")
                sys.exit()
                
    print("No")
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 38768
///BISMILLAH'IR  RO'HMANIR  ROH'IM
///RIFAT SHARIAR SAKIL
///SOFTWARE ENGINEERING(SUST)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ///BISMILLAH'IR  RO'HMANIR  ROH'IM


#include<stdio.h>
#include<string.h>
int main()
{
    char S[100],l,m,p;
    int i;
    gets(S);
      l=strlen(S);
    for(i=0;i<l;i++)
    {

        if((i+1)%2==1){
         m=1;
        if( S[i]!='R' && S[i]!='U' && S[i]!='D'  )
        {

       printf("No");
       return 0;
        }
        else m=0;
        }
    if((i+1)%2==0){ p=1;
        if( S[i]!='L' && S[i]!='U' && S[i]!='D'  )
        {
         printf("No");
       return 0;
        }
        else p=0;
        }


}
if(m==0 && p==0) printf("Yes");
        return 0;


}


Measured memory_bytes: 128
area :: (Num a) => a -> a -> a
area = \x y -> x * y

perimeter :: (Num a) => a -> a -> a
perimeter = \x y -> 2 * x + 2 * y

printf :: (Show a) => [a] -> IO ()
printf xs = putStrLn $ unwords $ map show xs   

main = do
  hoge <- getLine
  let  a = head $ words hoge
       b = last $ words hoge
       ar = area (read a) (read b)
       per = perimeter (read a) (read b)
  printf [ar, per]


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
#define pi 3.141592653589
using namespace std;
ll cnt[26];
signed main() {
	string s;
	cin >> s;
	ll size = s.size(), ans = 0;
	ll memo = size * (size - 1) / 2 + 1;
	rep(i, size)cnt[s[i] - 'a']++;
	rep(i, 26)ans += cnt[i] * (cnt[i] - 1) / 2;
	cout << memo - ans << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        int max = N;
        int min = Integer.MIN_VALUE;

        for(int i=0; i<M; i++){
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }

        if(max < min){
            System.out.println(0);
        }else {
            System.out.println(max-min+1);
        }

    }
}


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

MOD = 10 ** 9 + 7

dp = [[0 for _ in range(13)] for _ in range(len(s)+1)]

k = 1

dp[0][0] = 1

for i, x in enumerate(reversed(s)):
    #print(i, x)
    if x == '?':
        temp = 0
        for _ in range(10):
            for j in range(13):
                m = (j+temp) % 13
                dp[i+1][m] = (dp[i+1][m] + dp[i][j]) % MOD
            temp = (temp + k) % 13
    else:
        y = int(x)
        temp = (y * k) % 13
        #print(temp)
        for j in range(13):
            m = (j + temp) % 13
            dp[i + 1][m] = (dp[i + 1][m] + dp[i][j]) % MOD
    k = (k * 10) % 13
    #print(i, x, k, dp[i+1])
    #input()

print(dp[len(s)][5])

Measured memory_bytes: 69896
H, W, K = map(int, input().split())

c = [input() for _ in range(H)]

ans = 0
for h in range(2**H):
    h = "{:06b}".format(h)[-H:]
    for w in range(2**W):
        w = "{:06b}".format(w)[-W:]

        cnt = 0
        for i in range(len(h)):
            for j in range(len(w)):
                if h[i] == "0" and w[j] == "0":
                    if c[i][j] == "#":
                        cnt += 1
        
        if cnt == K:
            ans += 1

print(ans)

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

void Answer(int x){
	print(x);
	exit(0);
}

signed main(){
	int n=read(),m=read();
	if(n>m)swap(n,m);
	if(n==1){
		if(m==1){
			Answer(1);
		}else{
			Answer(m-2);
		}
	}else if(n==2){
		Answer(0);
	}else{
		Answer((n-2)*(m-2));
	}
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int32 q;
    cin >> q;
    int32 revcnt = 0;
    deque<char> frontstr;
    deque<char> backstr;
    REP(_,q){
        int32 t;
        cin >> t;
        if(t == 1){
            revcnt++;
        }else{
            int32 f;
            char c;
            cin >> f >> c;
            if(f == 1){
                if(revcnt % 2 == 0){
                    // s = c + s;
                    frontstr.push_front(c);
                }else{
                    backstr.push_back(c);
                }
            }else{
                if(revcnt % 2 == 0){
                    // s = s + c;
                    backstr.push_back(c);
                }else{
                    // s = c + s;
                    frontstr.push_front(c);
                }
            }
        }
    }
    if(revcnt % 2 == 0){
        while(!frontstr.empty()){
            cout << frontstr.front();
            frontstr.pop_front();
        }
        cout << s;
        while(!backstr.empty()){
            cout << backstr.front();
            backstr.pop_front();
        }
        cout << endl;
    }else{
        while(!backstr.empty()){
            cout << backstr.back();
            backstr.pop_back();
        }
        FORR(i,(signed)s.size()-1,0)cout << s[i];
        while(!frontstr.empty()){
            cout << frontstr.back();
            frontstr.pop_back();
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


const int INF = 1<<29;        // 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策
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; }

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    ll sum = 0;
    REP(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    sort(a.rbegin(), a.rend());
    double min = (double)sum / (4.0 * (double)m);
    // cout << min ;

    vector<int> r(m);
    REP(i, m) {
        if((double)a[i] < min) {
            cout << "No" << endl;
            return 0;
        }
        r[i] = a[i];
    }

    cout << "Yes" << endl;
}   

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

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

  ll money = 100;
  int ans = 0;
  while (money < x) {
    money *= 1.01;
    ans++;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll n, d, x, a;
	cin >> n >> d >> x;
	REP(i, n) {
		cin >> a;
		x += (d-1) / a + 1;
	}
	cout << x << endl;
	return 0;
}
 

Measured memory_bytes: 256
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cctype>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

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

  cout << N*N-A << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  string S;
  cin>>S;
  vector<char> a(S.length());
  vector<char> b(S.length());
  int ans1=0;
  int ans2=0;
  for(int i=0;i<S.length();i+=2) a[i]='0';
  for(int i=1;i<S.length();i+=2) a[i]='1';
  for(int i=0;i<S.length();i+=2) b[i]='1';
  for(int i=1;i<S.length();i+=2) b[i]='0';
  rep(i,S.length()) if(S[i]!=a[i]) ans1++;
  rep(i,S.length()) if(S[i]!=b[i]) ans2++;
  ans1=min(ans1,ans2);
  cout<<ans1<<endl;
}   

Measured memory_bytes: 3800
n = int(input())
lst = [input() for i in range(n)]
lst.sort()
lst.append("END")

maxi = 0
ans = []
count = 1

for i in range(n):
  if lst[i] == lst[i+1]:
    count += 1
  else:
    if count > maxi:
      ans = [lst[i]]
      maxi = count
    elif count == maxi:
      ans.append(lst[i])
    count = 1
    
for i in range(len(ans)):
  print(ans[i])

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

int cal(string s){
  int res=0;
  for(int i=0;i<s.size();i++) res+=s[i]-'0';
  return res;
}

int main(){
  
  string s;
  cin>>s;

  int ans=cal(s);
  
  ans=max(ans, int(s[0]-'0'-1)+((int)s.size()-1)*9);

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


Measured memory_bytes: 256
#include <stdio.h>
int d[100000][2][2],now=1,s[100000];
int max(int a,int b){
    if(a>b)return a;
    return b;
}
int dp(int n,int m,int p){
    if(n==now)return 0;
    if(n==now-1){
        if(p==0)return d[n][m][p]=0;
        return d[n][m][p]=s[n]-m;
    }
    if(s[n]-m==0)return dp(n+1,0,0);
    if(d[n][m][p]!=0)return d[n][m][p];
    if(p==0){
        return d[n][m][p]=max(dp(n+1,1,0)+s[n]-m,dp(n+1,0,1));
    }
    return d[n][m][p]=max(dp(n+1,0,1)+s[n]-1-m,dp(n+1,0,0)+s[n]-m);
}
int main(){
    int n,t=0,ans=0;
    scanf("%d",&n);
    char a,temp='\0';
    d[1][0][0]=d[1][1][1]=d[1][0][1]=d[1][1][0]=0;
    for(int i=0;i<n;i++){
        scanf("%c",&a);
        if(a!='0'&&a!='1')i--;
        else if(a=='0'){
            if(temp==a){
                ans+=dp(1,0,0);
                now=1;
            }
            else if(t>0){
                s[now]=t;
                d[now][0][0]=d[now][1][0]=d[now][0][1]=d[now][1][1]=0;
                t=0;
                now++;
            }
        }
        else{
            t++;
        }
        temp=a;
    }
    if(t>0){
    s[now]=t;
        now++;
    }
    if(now>2)ans+=dp(1,0,0);
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int main()
{

    int a, b, c;
    map<int,int> mp;
    mp.clear();
    int i;cin >> a >> b >> c;
    i = a;
    while(1)
    {
        mp[i % b]++;
        if(i % b == c % b)
        {
            printf("YES\n");
            break;
        }
        else
        {
            i += a;
        }
        if(mp[i % b])
        {
            printf("NO\n");
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<pair <int,int> >p(n);
    REP(i,n){
        int a;
        cin >> a;
        p[i].first = a;
        p[i].second = i+1;
    }
    sort(p.begin(),p.end());
    REP(i,n){
        cout << p[i].second << " ";
    }
    cout << endl;
    return 0;
}

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

int main(){
    int x,y,ans=MOD; cin >> x >> y;
    if(-x<=y) ans=min(ans,y-(-x)+1);
    if(x<=y) ans=min(ans,y-x);
    if(x<=-y) ans=min(ans,-y-x+1);
    if(-x<=-y) ans=min(ans,-y+x+2);
    cout << ans << endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                {
                    let mut out = Vec::<u8>::new();
                    solve($input,&mut out);
                    let out_str =str::from_utf8(&out).unwrap();
                    assert_eq!(&out_str, &$output);
                }
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
#[allow(unused_mut)]
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, isize1) => {
        read_value!($iter, isize) - 1
    };
    ($iter:expr,str) => {
        $iter.next().unwrap()
    };

    ($iter:expr, $t:tt) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

#[allow(dead_code)]
fn to_yesno(yesno: bool) -> &'static str {
    if yesno {
        "Yes"
    } else {
        "No"
    }
}

fn main() {
    let mut out = std::io::stdout();

    solve(&stdin!(), &mut out);
}

#[allow(unused_mut)]
fn solve<W: std::io::Write>(src: &str, out: &mut W) {
    #[allow(unused_macros)]
    macro_rules! out {
        ($arg:expr) => {{
            let _ = out.write_fmt(format_args!("{}",$arg));
        }};
        ($fmt:expr, $($args:tt)*) => {{
            let _ = out.write_fmt(format_args!($fmt, $($args)*));
        }};
    }
    #[allow(unused_macros)]
    macro_rules! outln {
        ($arg:expr) => {{
            out!("{}\n",$arg);
        }};
        ($fmt:expr, $($args:tt)*) => {{
            out!(concat!($fmt, "\n"), $($args)*);
        }};
    }

    input! {
        source = src,
        d:usize,
        t:usize,
        s:usize,
    }
    out!(to_yesno(d <= t * s));
}
test! {}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,q;
  string s;
  cin >> n >> q >> s;
  vector<int> l(q);
  vector<int> r(q);
  vector<int> result;
  for(int i=0;i<q;i++){
    cin >> l[i] >> r[i];
  }
  int count = 0;
  for(int j = 0;j<n-1;j++){
    if(s[j]=='A'&&s[j+1]=='C'){
      result.push_back(++count);
    }else{
      result.push_back(count);
    }
  }
  result.push_back(0);
  for(int k=0;k<q;k++){
    count = result[r[k]-2]-result[l[k]-2];
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 2296
def typical_stairs(n, memo)
  return 0 if n < 0
  return memo[n] if memo[n]

  1.upto(n) do |i|
    memo[i] = memo[i - 1] + memo[i - 2] unless memo[i]
  end
  memo[n] % 1000000007
end

n, m = gets.split.map(&:to_i)
memo = { -1 => 0, 0 => 1 }
m.times { memo[gets.chomp.to_i] = 0 }

puts typical_stairs(n, memo)

Measured memory_bytes: 438524
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int x,a,b;
    cin>>x>>a>>b;
    if(b-a<1){
        cout<<"delicious";
    }else if(b-a<=x){
        cout<<"safe";
    }else{
        cout<<"dangerous";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define out(x) cerr << #x << " = " << x << "\n"
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
	x = 0;char c = getchar();bool f = 0;
	for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
	for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
	if(f) x = -x;
}
const int N = 310, mo = 1e9  + 7;

struct P {
	int l, r, x;
	inline void in() {
		read(l), read(r), read(x);
	}
};
vector<P> vec[N];
int f[N][N][N];
int n, m, ans = 0;

inline int C(int r, int g, int b) {
	int p = max(r, max(g, b));
	for(vector<P> :: iterator u = vec[p].begin(); u != vec[p].end(); ++ u) {
		int cnt = 0;
		if(r >= u -> l) cnt ++;
		if(g >= u -> l) cnt ++;
		if(b >= u -> l) cnt ++;
		if(cnt != u -> x) return 0;
	}
	return 1;
}
inline void U(int &a, int b) {
	for(a += b; a >= mo; a -= mo);
}
main() {
	read(n);read(m);
	for(int i = 1; i <= m; i ++) {
		int l, r, x;
		read(l);
		read(r);
		read(x);
		vec[r].push_back(P{l, r, x});
	}
	f[0][0][0] = 1;
	for(int r = 0; r <= n; r ++) {
		for(int g = 0; g <= n; g ++) {
			for(int b = 0; b <= n; b ++) {
				int &v = f[r][g][b];
				if(v == 0) continue;
				if(!C(r, g, b)) {
					v = 0;
					continue;
				}
				int p = max(r, max(g, b)) + 1;
				U(f[p][g][b], v);
				U(f[r][p][b], v);
				U(f[r][g][p], v);
			}
		}
	}
	for(int r = 0; r <= n; r ++) {
		for(int g = 0; g <= n; g ++) {
				U(ans ,f[r][g][n]);
		}
	}
	for(int r = 0; r <= n; r ++) {
		for(int g = 0; g <= n; g ++) {
				U(ans ,f[r][n][g]);
		}
	}
	for(int r = 0; r <= n; r ++) {
		for(int g = 0; g <= n; g ++) {
				U(ans ,f[n][r][g]);
		}
	}
	cout << ans << "\n";
	return 0;
}
/*
when its hard to define the f- 
so think how to use the condition
Notes the color is only 3
so we only need to sign the pos for each color appreared latest
*/

Measured memory_bytes: 227584
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
A, B = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    #if arr==[]:
    #    arr.append([n, 1])
    return arr
    
facts_A = factorization(A)

cnt = 0
for l in facts_A:
    if B % l[0] == 0:
        cnt += 1
print(cnt + 1)

Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << 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; }

int main(){
  string s,t;
  cin >> s >> t;
  bool ans = false;
  rep(i,sz(s)){
    char a = s[sz(s) - 1];
    s = s.erase(sz(s) - 1);
    s = a + s;
    if (s == t){
      ans = true;
    }
  }
  if(ans){
    print("Yes");
  }
  else{
    print("No");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int cnt[1010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(i, 2, N) {
        int num = i;
        int j = 2;
        while(num > 1) {
            while(num % j == 0) {
                num /= j;
                cnt[j]++;
            }
            j++;
        }
    }
    int ans = 1;
    rep(i, 1010) {
        ans = (ans * (cnt[i] + 1)) % mod;
    }
    cout << ans << endl;


    return 0;
}


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

int A[3][3];
int N;

int main() {
    for(int i = 0; i < 3; i++) {
        for(int j =0; j< 3; j++) {
            cin >> A[i][j];
        }
    }
    cin >> N;
    for(int i =0; i< N; i++) {
        int a;
        cin >> a;
        for(int i =0; i < 3; i++) {
            for(int j=0;j<3;j++){
                if(A[i][j] == a) {
                    A[i][j] = -1;
                }
            }
        }
    }

    for(int i = 0;i < 3; i++) {
        int counter = 0;
        for(int j = 0; j< 3; j++) {
           if(A[i][j] == -1) {
               counter++;
           } 
        }
        if(counter == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }


    for(int i = 0;i < 3; i++) {
        int counter = 0;
        for(int j = 0; j< 3; j++) {
           if(A[j][i] == -1) {
               counter++;
           } 
        }
        if(counter == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    int counter = 0;
    int counter2 = 0;
    for(int i =0; i < 3; i++) {
        if(A[i][i] == -1) counter++;
        if(A[2 - i][i] == -1) counter2++;
    }
    if(counter == 3 || counter2 == 3) {
        cout << "Yes" <<endl;
        return 0;
    }

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

Measured memory_bytes: 256
#include <deque>
#include <utility>
#include <iostream>
using namespace std;
#define F first
#define S second
#define PB push_back
template <class T> struct chain{
    deque<pair<T,chain*>> v;
    chain(void){}
    void push(T n){
        if(v.empty()||n<=v.back().F)v.PB({n,nullptr});
        else if(n>v.front().F)v.push_front({n,nullptr});
        else{
            int l=0,r=static_cast<int>(v.size()),mid;
            while(r-l>1){
                mid=(r+l)>>1;
                if(v[mid].F<n)r=mid;
                else l=mid;
            }
            if(!v[l].S)v[l].S=new chain<T>();
            v[l].S->push(n);
        }
        return ;
    }
    void pop(){
        if(v.size()>1){
            if(v[0].S){
                v[0].F=v[0].S->v[0].F;
                if(v[0].S->v.size()>1)v[0].S->pop();
                else v[0].S=nullptr;
            }
            else v.pop_front();
        }
        return ;
    }
    T top(){return v[0].F;}
    void print(){
        for(int i=0;i<v.size();i++){
            printf("%d ",v[i].F);
            if(v[i].S){
                printf("to: ");
                v[i].S->print();
            }
        }
        printf(":end ");
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    chain<int>*root=new chain<int>();
    string s;
    int temp;
    while(true){
        cin>>s;
        if(s.size()<5)return 0;
        else if(s[0]=='i'){
            cin>>temp;
            root->push(temp);
        }
        else{
            cout<<root->top()<<endl;
            if(root->v.size()==1)root->v.pop_front();
            else root->pop();
        }
        //root->print();
        //printf("\n\n");
    }
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int n;
    cin >> n;
    int h[n + 1];
    for (int i = 0; i < n; i++)
        cin >> h[i];
    int dp[n + 1];

    rep(i, n) dp[i] = 1e9;

    dp[0] = 0;

    for (int i = 1; i < n; i++)
    {
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1)
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    OP(dp[n - 1]);

    return 0;
}

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



int main(){
    int N,K,res=0;
    cin>>N>>K;
    vector<bool> have(N,false);
    for(int i=0;i<K;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int A;
            cin>>A;
            have.at(A-1)=true;
        }
    }
    for(int i=0;i<N;i++){
        if(!have.at(i)){
            res++;
        }
    }
    cout<<res<<endl;

}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

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


#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

int main() {
	int N;
	cin >> N;
	vector<double> v(N, 0);
	rep(i, N) {
		cin >> v[i];
	}
	sort(ALL(v));

	double sum = 0;
	int power = 0;
	rep(i, N) {
		if (i == 0) {
			power = N - 1;
		}
		else {
			power = N - i;
		}
		sum += v[i] / pow(2, power);
	}
	cout << sum << endl;
	return 0;
}

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

int main()
{
    int n , s[255];
    while(scanf("%d",&n)==1) {
        for(int i=1;i<=n;i++) scanf("%d",&s[i]);
        for(int i=1;i<=n;i++) {
            printf("node %d: key = %d, ",i,s[i]);
            if(i/2) printf("parent key = %d, ",s[i/2]);
            if(i*2<=n) printf("left key = %d, ",s[i*2]);
            if(i*2+1<=n) printf("right key = %d, ",s[i*2+1]);
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 3204
N=gets.to_i
ans = N;

for i in 0..N
  cc=0
  t=i
  u=N-i
  while t>0
    cc+=t%6
    t/=6
  end
  while u>0
    cc+=u%9
    u/=9
  end
  if ans>cc
    ans=cc
  end
end

puts ans 

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define x first
#define y second

using namespace std;

int N;
char sir[100009];
bool dp[100009];
string s[] = {"dream", "dreamer", "erase", "eraser"};

bool mtch (int pos, int id)
{
    for (int i=0; i<s[id].length (); i++)
        if (s[id][i] != sir[pos + i]) return 0;
    return 1;
}

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

scanf ("%s", sir+1), N = strlen (sir + 1);
dp[0] = 1;
for (int i=1; i<=N; i++)
    for (int j=0; j<4; j++)
        if (mtch (i - s[j].length () + 1, j))
            dp[i] |= dp[i - s[j].length ()];
if (dp[N]) printf ("YES\n");
else printf ("NO\n");
return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
long long a,b,ans=999999999;
int main(){
    cin>>a>>b;
        if(a/2019!=b/2019)cout<<0<<endl;
        else{
            for(long long i=a;i<=b;i++){
                for(long long j=i+1;j<=b;j++){
                    ans=min(i*j%2019,ans);
                }
            }
            cout<<ans<<endl;
        }
    return 0;
}

Measured memory_bytes: 256
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define End return 0

int main ()
{
    ll a,b;
    cin>>a>>b;
    if(a==b)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    End;
}
/* pray for me
All is well
*/


Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

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

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

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define SCIN(x) string x;cin>>x;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

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

#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end());

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(n);CIN(a);CIN(b);
    int win=0;
    bool turn=true;//t alice
    while(win==0){
        if(turn){
            if(a!=b-1)a++;
            else win=2;
        }
        else{
            if(b!=a+1)b--;
            else win=1;
        }
        turn = !turn;

    }
    SANKOU(win==1,"Alice","Borys");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	int a,b,c;
	int min;

	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	
	if(a>b && a>c){
		min = b+c;
	}
	else if(b>a && b>c){
		min = a+c;
	}
	else if(c>a && c>b){
		min = a+b;
	}
	else if(a==b && b==c){
		min = a+b;
	}
	
	printf("%d\n",min);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
typedef long long ll;
using namespace std;
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;
    ll e=gcd(c,d);
    e=c*d/e;
    ll cnt= b-a-(b/c+b/d-b/e-a/c-a/d+a/e);
    cout <<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
b = list(d.values())
b.sort(reverse=True)
print(n-sum(b[:min(len(b), k)]))


Measured memory_bytes: 34616
n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
  graph[b].append(a)
ans = 0
for i in range(1,n+1):
  highest = 0
  for y in graph[i]:
    highest = max(highest,h[y-1])
  if h[i-1] > highest:
    ans += 1
print(ans)

Measured memory_bytes: 106392
#include<bits/stdc++.h>
#define N 1000005
#define Mod 1000000007
using namespace std;
char s[N];int sum[N],last[N],dp[N],nxt[N][3];
inline int gt(char ch){if(ch=='a')return 1;return 2;}
int main(){
	scanf("%s",s+1);int n=strlen(s+1);
	bool flag=1;
	for (int i=1;i<=n;i++){
		if (s[i]==s[i-1]) flag=0;
		sum[i]=sum[i-1]+gt(s[i]);
		sum[i]%=3;
	}
	if (flag) return puts("1"),0;
	for (int i=0;i<3;i++) last[i]=n+1;
	for (int i=n;~i;i--){
		for (int j=0;j<3;j++) nxt[i][j]=last[j];
		last[sum[i]]=i;
	}
	int ans=0;dp[0]=1;
	for (int i=0;i<=n;i++){
		for (int j=1;j<=2;j++)
			if (nxt[i][(sum[i]+j)%3]<=n) dp[nxt[i][(sum[i]+j)%3]]=1ll*(dp[nxt[i][(sum[i]+j)%3]]+dp[i])%Mod;
		if (i&&sum[i]==sum[n]) ans=1ll*(ans+dp[i])%Mod;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  int N,M; cin >> N >> M;
  
  vector<int> hona(M); vector<int> honb(M);
  vector<int> eve(N);
  for(int i=0;i<N;i++){
    eve.at(i)=0;
  }
  for(int i=0;i<M;i++){
    cin >> hona.at(i);
    cin >> honb.at(i);
  }
  for(int i=0;i<M;i++){
    for(int p=0;p<N;p++){
      if(hona.at(i)==p+1 || honb.at(i)==p+1){
        eve.at(p)++;
      }
    }
  }
  for(int p=0;p<N;p++){
    cout << eve.at(p) << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/arc073/editorial.pdf
　　　https://ei1333.hateblo.jp/entry/2017/05/01/004235
　　　https://atcoder.jp/contests/abc060/submissions/3782609
・公式解
・累積和あり
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import defaultdict

N, W = map(int, input().split())
wN = [0] * N
vN = [[] for i in range(4)]
for i in range(N):
    w, v = map(int, input().split())
    if i == 0:
        offset = w
    vN[w-offset].append(v)

# 重さ毎のリストを降順ソート
for i in range(4):
    # 空リストのままだとこの後ループを回ってくれないので、[0]を追加する
    vN[i] = [0] + sorted(vN[i], reverse=True)

# 累積和
for i in range(4):
    for j in range(1, len(vN[i])):
        vN[i][j] = vN[i][j-1] + vN[i][j]

ans = 0
for i in range(len(vN[0])):
    for j in range(len(vN[1])):
        for k in range(len(vN[2])):
            for l in range(len(vN[3])):
                # 重さリミットを超えるパターンは対象外
                if offset * i + (offset+1) * j + (offset+2) * k + (offset+3) * l > W:
                    continue
                ans = max(vN[0][i] + vN[1][j] + vN[2][k] + vN[3][l], ans)
print(ans)


Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>

using namespace std;
int main()
{
    int sum = 0;
    char c;
    while(scanf("%c",&c) && c!='\n' )
    {
        if(c == 'o')
        sum++;
    }
    cout<<700+sum*100<<endl;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define db double
#define ld long double
#define pp printf
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
using namespace std;

const int N = 2e5 + 5;

const int mo = 1e9 + 7;

int n, c[N];
ll f[N], s[N];

int main() {
//	freopen("a.in", "r", stdin);
	scanf("%d", &n);
	fo(i, 1, n) scanf("%d", &c[i]);
	c[n + 1] = -1;
	int la = 0; f[0] = 1;
	fo(i, 1, n + 1) if(c[i] != c[i + 1]) {
		f[i] = (s[c[i]] + f[la]) % mo;
		s[c[i]] = f[i];
		la = i;
	}
	pp("%lld", f[n]);
}

Measured memory_bytes: 4096
N, K = list(map(lambda x: int(x), input().split(' ')))

H = [0 for _ in range(N)]
for i in range(N):
    H[i] = int(input())

H.sort()
ans = max(H)
for i in range(N-K+1):
    ans = min(ans, H[i+K-1] - H[i])
    # print(H[i+K-1], H[i])

print(ans)


Measured memory_bytes: 46472
function MainB(input) {
	input = input.split("\n");

	var n = parseInt(input[0], 10);
	var s = input[1].split("");
	var k = parseInt(input[2], 10);

  var sampleChar = s[k - 1];
  for(var i = 0; i < n; i++){
    if(s[i] !== sampleChar){
      s[i] = "*";
    }
  }
	//出力
	console.log('%s',s.join(""));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
MainB(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){

    int n = 5;
    vector<int> a(5);
    for(int i = 0; i < 5; i++) cin >> a[i];
    
    int ans = INF;
    for(int i = 0; i < n; i++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
            if(i == j || a[j] % 10 == 0) tmp += a[j];
            else tmp += a[j] + (10 - a[j] % 10);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin>>N;
    string S;
    cin>>S;
    if(S.size()<=N){
    for(int i=0;i<S.size();i++){
    cout<<S.at(i);}}
    else{
    for(int i=0;i<N;i++){
    cout<<S.at(i);}
    cout<<"..."<<endl;}}
    

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using namespace std;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c,ans=0; cin >> a >> b >> c;
    ans=min(c,b/a);
    cout << ans << endl;
    
 }    


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

using namespace std;

string S;
int solve(void) {
    int left = 0;
    int right = S.length() - 1;
    int counter = 0;
    while (left <= right) {
        if (S[left] != S[right]) {
            counter++;
        }
        left++;
        right--;
    }
    return counter;
}

int main(void) {
    cin >> S;
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int MOD=MOD2;



int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
            int a,b,n,m;
            cin>>a>>b>>n>>m;
            ld ang1=(30.000*n+0.5*m);
            ld ang2=(6.000*m);
            ld diff=abs(ang1-ang2);
            if(diff>180)diff=360-diff;
            diff=(diff*PI)/180.000;
            ld ans=a*a+b*b-2*a*b*cos(diff);
            ans=sqrt(ans);
            precise(20)<<ans<<endl;
      } 
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 4100